Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ No repo secret is required for Option A. The release workflow already sets `perm
3. Tag that commit and push:

```bash
git tag v0.2.1
git push origin v0.2.1
git tag v0.3.2
git push origin v0.3.2
```

Do not retag an old commit with a new version name. The publish job checks that `v*` equals `package.json` version on the tagged commit.
76 changes: 52 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Works in Expo **dev clients and production builds**. Expo Go cannot load the And

## Install

Install the SDK and AsyncStorage together. AsyncStorage is required so install state survives cold launches; without it each launch can post a new install.
Install **0.3.2 or later** of the SDK, together with AsyncStorage. AsyncStorage is required so install state survives cold launches; without it each launch can post a new install.

**Expo**

```bash
npx expo install @tapapplink/react-native @react-native-async-storage/async-storage
npx expo install @tapapplink/react-native@0.3.2 @react-native-async-storage/async-storage
```

**Bare React Native**

```bash
npm install @tapapplink/react-native @react-native-async-storage/async-storage
# or: yarn add @tapapplink/react-native @react-native-async-storage/async-storage
npm install @tapapplink/react-native@0.3.2 @react-native-async-storage/async-storage
# or: yarn add @tapapplink/react-native@0.3.2 @react-native-async-storage/async-storage
```

Bare React Native iOS apps should run `cd ios && pod install` after installing.
Expand Down Expand Up @@ -59,38 +59,54 @@ Purchases are attributed with billing **webhooks**, not a client `trackPurchase`

Show success only when `applyCode` resolves. Map each result to UI state as below. Customers must never see the word "environment".

On a `network` (or timeout) error only, retry `applyCode` once with the same code. Do not auto-retry `unknownCode`, `inactiveCode`, or `wrongEnvironment`. If that retry also fails, show N6 ("We couldn't check your code. Check your connection and try again.") with a **Try again** button. From 0.3.2, that automatic retry is safe because the SDK reuses its request ID, so the server will not count the install twice.

```ts
type RedeemUi = {
title: string;
detail?: string;
hint?: string;
showCode: boolean;
/** When true, show a Try again button (N6 after a failed network retry). */
tryAgain?: boolean;
};

async function redeemForUi(code: string): Promise<RedeemUi> {
try {
const result = await TapAppLink.applyCode(code);
const offerLine =
typeof result.offer === "object" &&
result.offer &&
typeof (result.offer as { creatorName?: string }).creatorName === "string"
? `Offer from ${(result.offer as { creatorName: string }).creatorName}`
: undefined;
const offerLineFrom = (result: Record<string, unknown>): string | undefined => {
const offer = result.offer;
if (
offer &&
typeof offer === "object" &&
typeof (offer as { creatorName?: string }).creatorName === "string"
) {
return `Offer from ${(offer as { creatorName: string }).creatorName}`;
}
return undefined;
};

const mapSuccess = (result: Record<string, unknown>): RedeemUi => {
const offerLine = offerLineFrom(result);
if (result.alreadyAttributed === true) {
return {
title: "You're all set",
detail: offerLine,
showCode: false,
};
}

return {
title: "Code applied",
detail: offerLine,
showCode: true,
};
} catch (error) {
};

const networkFailureUi = (): RedeemUi => ({
title: "We couldn't check your code. Check your connection and try again.",
showCode: true,
tryAgain: true,
});

const mapError = (error: unknown): RedeemUi => {
if (error instanceof TapAppLinkRedeemError) {
switch (error.code) {
case "unknownCode":
Expand All @@ -114,26 +130,38 @@ async function redeemForUi(code: string): Promise<RedeemUi> {
showCode: true,
};
case "network":
return {
title:
"We couldn't check your code. Check your connection and try again.",
showCode: true,
};
return networkFailureUi();
case "other":
default:
console.warn("TapAppLink applyCode failed", {
code: error.code,
status: error.status,
message: error.message,
});
return {
title:
"We couldn't check your code. Check your connection and try again.",
showCode: true,
};
return networkFailureUi();
}
}
throw error;
};

try {
return mapSuccess(await TapAppLink.applyCode(code));
} catch (error) {
// Auto-retry once for network/timeout only. Never for unknown/inactive/wrongEnvironment.
if (error instanceof TapAppLinkRedeemError && error.code === "network") {
try {
return mapSuccess(await TapAppLink.applyCode(code));
} catch (retryError) {
if (
retryError instanceof TapAppLinkRedeemError &&
retryError.code === "network"
) {
return networkFailureUi();
}
return mapError(retryError);
}
}
return mapError(error);
}
}
```
Expand Down
Loading