diff --git a/PUBLISHING.md b/PUBLISHING.md index e872b3c..2570cb0 100644 --- a/PUBLISHING.md +++ b/PUBLISHING.md @@ -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. diff --git a/README.md b/README.md index 8be7ba8..a6eee1d 100644 --- a/README.md +++ b/README.md @@ -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. @@ -59,24 +59,33 @@ 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 { - 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 | 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): RedeemUi => { + const offerLine = offerLineFrom(result); if (result.alreadyAttributed === true) { return { title: "You're all set", @@ -84,13 +93,20 @@ async function redeemForUi(code: string): Promise { 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": @@ -114,11 +130,7 @@ async function redeemForUi(code: string): Promise { 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", { @@ -126,14 +138,30 @@ async function redeemForUi(code: string): Promise { 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); } } ```