@rocapine/react-native-onboarding 1.74.1 → 1.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/evaluateCondition.d.ts.map +1 -1
- package/dist/evaluateCondition.js +103 -4
- package/dist/evaluateCondition.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/onboarding-example.d.ts +375 -99
- package/dist/onboarding-example.d.ts.map +1 -1
- package/dist/onboarding-example.js +118 -1
- package/dist/onboarding-example.js.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +71 -5
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +237 -57
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/customScreens.d.ts +31 -0
- package/dist/paywalls/customScreens.d.ts.map +1 -1
- package/dist/paywalls/observer.d.ts +129 -0
- package/dist/paywalls/observer.d.ts.map +1 -0
- package/dist/paywalls/observer.js +211 -0
- package/dist/paywalls/observer.js.map +1 -0
- package/dist/paywalls/present.d.ts +19 -15
- package/dist/paywalls/present.d.ts.map +1 -1
- package/dist/paywalls/present.js +21 -17
- package/dist/paywalls/present.js.map +1 -1
- package/dist/paywalls/types.d.ts +3 -1
- package/dist/paywalls/types.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.d.ts +38 -1
- package/dist/products/adapters/expoIap.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.js +509 -75
- package/dist/products/adapters/expoIap.js.map +1 -1
- package/dist/products/index.d.ts +1 -0
- package/dist/products/index.d.ts.map +1 -1
- package/dist/products/index.js.map +1 -1
- package/dist/products/types.d.ts +13 -0
- package/dist/products/types.d.ts.map +1 -1
- package/dist/screens/completingActions.d.ts +95 -0
- package/dist/screens/completingActions.d.ts.map +1 -0
- package/dist/screens/completingActions.js +302 -0
- package/dist/screens/completingActions.js.map +1 -0
- package/dist/screens/elementTypeRegistry.d.ts +45 -0
- package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
- package/dist/screens/elementTypeRegistry.js +119 -0
- package/dist/screens/elementTypeRegistry.js.map +1 -0
- package/dist/screens/elements/ButtonElement.d.ts +3 -2
- package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
- package/dist/screens/elements/ButtonElement.js +5 -1
- package/dist/screens/elements/ButtonElement.js.map +1 -1
- package/dist/screens/resolveRenderableStep.d.ts +42 -0
- package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
- package/dist/screens/resolveRenderableStep.js +28 -0
- package/dist/screens/resolveRenderableStep.js.map +1 -0
- package/dist/screens/types.d.ts +2 -2
- package/dist/screens/types.d.ts.map +1 -1
- package/dist/screens/types.js +5 -1
- package/dist/screens/types.js.map +1 -1
- package/dist/screens/unknownElementTypes.d.ts +94 -0
- package/dist/screens/unknownElementTypes.d.ts.map +1 -0
- package/dist/screens/unknownElementTypes.js +141 -0
- package/dist/screens/unknownElementTypes.js.map +1 -0
- package/dist/screens/unknownKeys.d.ts +30 -6
- package/dist/screens/unknownKeys.d.ts.map +1 -1
- package/dist/screens/unknownKeys.js +88 -54
- package/dist/screens/unknownKeys.js.map +1 -1
- package/dist/steps/common.types.d.ts +262 -9
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +64 -3
- package/dist/steps/common.types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/authoringDocEscapes.test.ts +59 -0
- package/src/__tests__/completingActions.test.ts +509 -0
- package/src/__tests__/customActionHooks.test.ts +224 -0
- package/src/__tests__/elementTypeRegistry.test.ts +48 -0
- package/src/__tests__/evaluateCondition.test.ts +228 -3
- package/src/__tests__/onboardingExampleElements.test.ts +74 -0
- package/src/__tests__/requestPermissionAction.test.ts +138 -0
- package/src/__tests__/resolveRenderableStep.test.ts +117 -0
- package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
- package/src/__tests__/unknownElementTypes.test.ts +240 -0
- package/src/__tests__/unknownKeys.test.ts +110 -0
- package/src/evaluateCondition.ts +107 -4
- package/src/index.ts +55 -0
- package/src/onboarding-example.ts +119 -1
- package/src/paywalls/PaywallProvider.tsx +370 -66
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
- package/src/paywalls/__tests__/observer.test.ts +401 -0
- package/src/paywalls/__tests__/present.test.ts +0 -18
- package/src/paywalls/customScreens.ts +34 -1
- package/src/paywalls/observer.ts +308 -0
- package/src/paywalls/present.ts +24 -18
- package/src/paywalls/types.ts +3 -1
- package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
- package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
- package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
- package/src/products/adapters/expoIap.ts +609 -78
- package/src/products/index.ts +1 -0
- package/src/products/types.ts +13 -0
- package/src/screens/completingActions.ts +316 -0
- package/src/screens/elementTypeRegistry.ts +122 -0
- package/src/screens/elements/ButtonElement.ts +9 -1
- package/src/screens/resolveRenderableStep.ts +59 -0
- package/src/screens/types.ts +2 -2
- package/src/screens/unknownElementTypes.ts +204 -0
- package/src/screens/unknownKeys.ts +119 -56
- package/src/steps/common.types.ts +297 -9
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import type { PresentResult } from "./types";
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// The observer contract. Copied VERBATIM from rocalytics-sdk
|
|
5
|
+
// `src/paywall/observer.ts` (Rocapine/rocalytics-sdk#14): that package's
|
|
6
|
+
// `createPaywallTracker()` satisfies `PaywallObserver` STRUCTURALLY and imports
|
|
7
|
+
// nothing from here, so any drift in a name or a field type breaks the only
|
|
8
|
+
// consumer without a compile error on either side. Change it there first.
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
export type PaywallSurface = "present" | "paywall_step";
|
|
12
|
+
|
|
13
|
+
export interface PaywallPresentationInfo {
|
|
14
|
+
moment: string;
|
|
15
|
+
paywallId: string;
|
|
16
|
+
audienceId: string | null;
|
|
17
|
+
renderMode: "elements" | "custom";
|
|
18
|
+
billing: "store" | "stripe";
|
|
19
|
+
surface: PaywallSurface;
|
|
20
|
+
variantKey?: string;
|
|
21
|
+
deploymentId?: string;
|
|
22
|
+
onboardingRun?: { runId: string; stepKey: string };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PaywallTransactionInfo {
|
|
26
|
+
/** The exact value the app passes to Rocalytics' `purchase` call: iOS StoreKit original transaction id (iOS join key); Android Play order id (GPA.…). */
|
|
27
|
+
originalTransactionIdentifier?: string;
|
|
28
|
+
/** Android only: the Play purchase token (RevenueCat `transaction.purchaseToken`). Android join key. */
|
|
29
|
+
purchaseToken?: string;
|
|
30
|
+
productId?: string;
|
|
31
|
+
/** True when the purchase only restored existing access. Not a conversion. */
|
|
32
|
+
restored?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PaywallPresentationEnd {
|
|
36
|
+
status: "purchased" | "dismissed" | "cancelled" | "error";
|
|
37
|
+
/** The host SDK's error reason; accepted as any string. */
|
|
38
|
+
reason?: string;
|
|
39
|
+
transaction?: PaywallTransactionInfo;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface PaywallPresentationHandle {
|
|
43
|
+
shown(): void;
|
|
44
|
+
end(outcome: PaywallPresentationEnd): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PaywallObserver {
|
|
48
|
+
start(info: PaywallPresentationInfo): PaywallPresentationHandle | void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// This SDK's side: one guarded presentation, shared by `present()` and the
|
|
53
|
+
// inline `Paywall` step so both enforce the same rules in one place.
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The fields of a catalog `Paywall` a presentation report needs. Structural
|
|
58
|
+
* and lenient (`billing`/`products` optional, `renderMode` nullable) because
|
|
59
|
+
* the inline step reads the catalog as open wire data.
|
|
60
|
+
*/
|
|
61
|
+
export type PaywallPresentationSource = {
|
|
62
|
+
id: string;
|
|
63
|
+
moment: string;
|
|
64
|
+
audienceId?: number | null;
|
|
65
|
+
billing?: "store" | "stripe";
|
|
66
|
+
renderMode?: "elements" | "custom" | null;
|
|
67
|
+
products?: ReadonlyArray<{ key: string; ios?: string; android?: string }>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* What a surface holds for one presentation. Never throws, whatever the
|
|
72
|
+
* observer does: `shown()` reaches the observer at most once and never after
|
|
73
|
+
* `end()`; `end()` reaches it exactly once.
|
|
74
|
+
*
|
|
75
|
+
* `end` takes the SDK's own `PresentResult` plus the product key a purchase
|
|
76
|
+
* went through, and builds the observer's `PaywallPresentationEnd` itself — so
|
|
77
|
+
* the transaction rules (only with `purchased`, `productId` from the slot for
|
|
78
|
+
* the running platform) live here and not in each surface.
|
|
79
|
+
*
|
|
80
|
+
* `purchasedFrom` is the paywall the purchase was made ON, when that is not the
|
|
81
|
+
* one the presentation started with: a variant swap keeps one presentation open
|
|
82
|
+
* (credited to the variant shown first), but the bought slot's store id is the
|
|
83
|
+
* swapped-in variant's, and that id is what joins to revenue. Omitted, the
|
|
84
|
+
* started paywall is used.
|
|
85
|
+
*
|
|
86
|
+
* `reportedTransaction` is the `transaction` a custom paywall screen passed to
|
|
87
|
+
* `complete()` (#287). Typed `unknown` because it arrives from host code and is
|
|
88
|
+
* sanitized here (`sanitizePaywallTransaction`), the one place both surfaces
|
|
89
|
+
* share. The caller passes it only when the screen itself reported
|
|
90
|
+
* `purchased`; `buildPresentationEnd` documents how it meets a recorded
|
|
91
|
+
* purchase.
|
|
92
|
+
*/
|
|
93
|
+
export type PaywallPresentation = {
|
|
94
|
+
shown(): void;
|
|
95
|
+
end(
|
|
96
|
+
result: Pick<PresentResult, "status" | "reason">,
|
|
97
|
+
purchasedProductKey?: string | null,
|
|
98
|
+
purchasedFrom?: PaywallPresentationSource | null,
|
|
99
|
+
reportedTransaction?: unknown
|
|
100
|
+
): void;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const NOOP_PAYWALL_PRESENTATION: PaywallPresentation = Object.freeze({
|
|
104
|
+
shown: () => {},
|
|
105
|
+
end: () => {},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const warn = (what: string, error: unknown) =>
|
|
109
|
+
console.warn(`[paywalls] PaywallObserver.${what} threw; ignored so the paywall is unaffected:`, error);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Calls `fn`, swallowing a synchronous throw AND a rejected promise. An
|
|
113
|
+
* observer typed `void` can still be `async`, and its rejection would otherwise
|
|
114
|
+
* surface as an unhandled rejection in the host app.
|
|
115
|
+
*/
|
|
116
|
+
const guarded = (what: string, fn: () => unknown): unknown => {
|
|
117
|
+
try {
|
|
118
|
+
const value = fn();
|
|
119
|
+
if (value && typeof (value as PromiseLike<unknown>).then === "function") {
|
|
120
|
+
Promise.resolve(value).catch((error) => warn(what, error));
|
|
121
|
+
}
|
|
122
|
+
return value;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
warn(what, error);
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const isHandle = (value: unknown): value is PaywallPresentationHandle =>
|
|
130
|
+
typeof value === "object" &&
|
|
131
|
+
value !== null &&
|
|
132
|
+
typeof (value as PaywallPresentationHandle).shown === "function" &&
|
|
133
|
+
typeof (value as PaywallPresentationHandle).end === "function";
|
|
134
|
+
|
|
135
|
+
export const buildPresentationInfo = (
|
|
136
|
+
paywall: PaywallPresentationSource,
|
|
137
|
+
surface: PaywallSurface
|
|
138
|
+
): PaywallPresentationInfo => ({
|
|
139
|
+
moment: paywall.moment,
|
|
140
|
+
paywallId: paywall.id,
|
|
141
|
+
// The catalog carries a numeric id; the contract is a string.
|
|
142
|
+
audienceId: paywall.audienceId == null ? null : String(paywall.audienceId),
|
|
143
|
+
// Absent means "elements" — see `Paywall.renderMode`.
|
|
144
|
+
renderMode: paywall.renderMode === "custom" ? "custom" : "elements",
|
|
145
|
+
billing: paywall.billing === "stripe" ? "stripe" : "store",
|
|
146
|
+
surface,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* `productId` is the store id of the purchased slot on the RUNNING platform.
|
|
151
|
+
* Undefined when nothing resolves (unknown key, a slot with no id for this
|
|
152
|
+
* platform, web), in which case the caller sends no `transaction` at all.
|
|
153
|
+
*/
|
|
154
|
+
const resolveProductId = (
|
|
155
|
+
paywall: PaywallPresentationSource,
|
|
156
|
+
key: string | null | undefined,
|
|
157
|
+
platform: string
|
|
158
|
+
): string | undefined => {
|
|
159
|
+
if (!key) return undefined;
|
|
160
|
+
const slot = paywall.products?.find((p) => p.key === key);
|
|
161
|
+
if (!slot) return undefined;
|
|
162
|
+
if (platform === "ios") return slot.ios || undefined;
|
|
163
|
+
if (platform === "android") return slot.android || undefined;
|
|
164
|
+
return undefined;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const nonEmptyString = (value: unknown): value is string => typeof value === "string" && value.length > 0;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* A custom screen's `complete({ transaction })`, reduced to the contract: the
|
|
171
|
+
* three ids only when they are non-empty strings, `restored` only when it is
|
|
172
|
+
* exactly `true`, every other field dropped. `undefined` when the input is not
|
|
173
|
+
* a plain object or nothing survives, so the end carries no `transaction` at
|
|
174
|
+
* all, exactly as when none was passed.
|
|
175
|
+
*
|
|
176
|
+
* Never throws: the value is host data, and a throwing getter or a revoked
|
|
177
|
+
* `Proxy` (on which even `Array.isArray` throws) must cost only the
|
|
178
|
+
* transaction, never the end of the presentation it rides on.
|
|
179
|
+
*/
|
|
180
|
+
export const sanitizePaywallTransaction = (value: unknown): PaywallTransactionInfo | undefined => {
|
|
181
|
+
try {
|
|
182
|
+
return readTransaction(value);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.warn("[paywalls] complete()'s transaction could not be read; it was dropped:", error);
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const readTransaction = (value: unknown): PaywallTransactionInfo | undefined => {
|
|
190
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined;
|
|
191
|
+
const raw = value as Record<string, unknown>;
|
|
192
|
+
const out: PaywallTransactionInfo = {};
|
|
193
|
+
if (nonEmptyString(raw.originalTransactionIdentifier)) {
|
|
194
|
+
out.originalTransactionIdentifier = raw.originalTransactionIdentifier;
|
|
195
|
+
}
|
|
196
|
+
if (nonEmptyString(raw.purchaseToken)) out.purchaseToken = raw.purchaseToken;
|
|
197
|
+
if (nonEmptyString(raw.productId)) out.productId = raw.productId;
|
|
198
|
+
if (raw.restored === true) out.restored = true;
|
|
199
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The end the observer receives.
|
|
204
|
+
*
|
|
205
|
+
* A transaction only ever accompanies a `purchased` end (contract rule P8).
|
|
206
|
+
* Its sources:
|
|
207
|
+
* - a purchase the SDK recorded (`purchasedProductKey`): `productId` from that
|
|
208
|
+
* slot for the running platform;
|
|
209
|
+
* - a custom screen's reported transaction (#287), sanitized.
|
|
210
|
+
*
|
|
211
|
+
* With no recorded purchase, the reported transaction is sent as it is.
|
|
212
|
+
*
|
|
213
|
+
* When a purchase IS recorded, the recorded purchase wins: the "first settled
|
|
214
|
+
* purchase sticks" rule `resolveEndedOutcome` applies to the outcome. The
|
|
215
|
+
* reported ids are added to it only when they provably describe it, i.e. the
|
|
216
|
+
* reported `productId` is present and equals the recorded slot's store id for
|
|
217
|
+
* this platform. `restored` is never added: the SDK's own purchase is a
|
|
218
|
+
* purchase, and a screen's flag must not relabel it. In every other case (an
|
|
219
|
+
* absent or different reported `productId`, or a recorded slot with no store
|
|
220
|
+
* id on this platform) the reported ids are dropped with a warning, and the
|
|
221
|
+
* end carries the recorded purchase's transaction alone (`{ productId }`, or
|
|
222
|
+
* none when its slot names nothing here). Pairing one purchase's transaction
|
|
223
|
+
* id with another's `productId` would corrupt the revenue join.
|
|
224
|
+
*/
|
|
225
|
+
export const buildPresentationEnd = (
|
|
226
|
+
paywall: PaywallPresentationSource,
|
|
227
|
+
result: Pick<PresentResult, "status" | "reason">,
|
|
228
|
+
purchasedProductKey: string | null | undefined,
|
|
229
|
+
platform: string,
|
|
230
|
+
reportedTransaction?: unknown
|
|
231
|
+
): PaywallPresentationEnd => {
|
|
232
|
+
const end: PaywallPresentationEnd = { status: result.status };
|
|
233
|
+
if (result.reason !== undefined) end.reason = result.reason;
|
|
234
|
+
if (result.status !== "purchased") return end;
|
|
235
|
+
const productId = resolveProductId(paywall, purchasedProductKey, platform);
|
|
236
|
+
const reported = sanitizePaywallTransaction(reportedTransaction);
|
|
237
|
+
if (reported && !purchasedProductKey) {
|
|
238
|
+
end.transaction = reported;
|
|
239
|
+
return end;
|
|
240
|
+
}
|
|
241
|
+
if (reported && productId && reported.productId === productId) {
|
|
242
|
+
const { restored, ...ids } = reported;
|
|
243
|
+
if (restored) {
|
|
244
|
+
console.warn(
|
|
245
|
+
"[paywalls] complete() reported `restored: true` for a purchase this presentation already " +
|
|
246
|
+
"recorded through the SDK; the flag was dropped and the purchase is reported as one."
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
end.transaction = ids;
|
|
250
|
+
return end;
|
|
251
|
+
}
|
|
252
|
+
if (reported) {
|
|
253
|
+
console.warn(
|
|
254
|
+
`[paywalls] complete() reported a transaction for ${JSON.stringify(reported.productId ?? null)}, ` +
|
|
255
|
+
`but this presentation already recorded a purchase of ${JSON.stringify(productId ?? null)}; ` +
|
|
256
|
+
"the recorded purchase is reported and the screen's transaction ids are dropped."
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (productId) end.transaction = { productId };
|
|
260
|
+
return end;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Opens one observed presentation: calls `observer.start` now and returns the
|
|
265
|
+
* guarded handle. With no observer (or a malformed one) every call is a no-op.
|
|
266
|
+
*
|
|
267
|
+
* `platform` is `Platform.OS`, passed in rather than imported so this module
|
|
268
|
+
* stays testable without a react-native stub.
|
|
269
|
+
*/
|
|
270
|
+
export const openPaywallPresentation = (
|
|
271
|
+
observer: PaywallObserver | undefined | null,
|
|
272
|
+
paywall: PaywallPresentationSource,
|
|
273
|
+
surface: PaywallSurface,
|
|
274
|
+
platform: string
|
|
275
|
+
): PaywallPresentation => {
|
|
276
|
+
if (!observer || typeof (observer as PaywallObserver).start !== "function") {
|
|
277
|
+
return NOOP_PAYWALL_PRESENTATION;
|
|
278
|
+
}
|
|
279
|
+
const returned = guarded("start", () => observer.start(buildPresentationInfo(paywall, surface)));
|
|
280
|
+
// `start()` may legitimately return void; anything that is not a handle is
|
|
281
|
+
// treated the same way.
|
|
282
|
+
const handle = isHandle(returned) ? returned : null;
|
|
283
|
+
let shown = false;
|
|
284
|
+
let ended = false;
|
|
285
|
+
return {
|
|
286
|
+
shown: () => {
|
|
287
|
+
if (shown || ended) return;
|
|
288
|
+
shown = true;
|
|
289
|
+
if (handle) guarded("shown", () => handle.shown());
|
|
290
|
+
},
|
|
291
|
+
end: (result, purchasedProductKey, purchasedFrom, reportedTransaction) => {
|
|
292
|
+
if (ended) return;
|
|
293
|
+
ended = true;
|
|
294
|
+
if (!handle) return;
|
|
295
|
+
const source = purchasedFrom ?? paywall;
|
|
296
|
+
// The sanitizer never throws, but the end must reach the observer
|
|
297
|
+
// whatever the reported transaction does: fall back to the end without it.
|
|
298
|
+
let outcome: PaywallPresentationEnd;
|
|
299
|
+
try {
|
|
300
|
+
outcome = buildPresentationEnd(source, result, purchasedProductKey, platform, reportedTransaction);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
warn("end (its transaction)", error);
|
|
303
|
+
outcome = buildPresentationEnd(source, result, purchasedProductKey, platform);
|
|
304
|
+
}
|
|
305
|
+
guarded("end", () => handle.end(outcome));
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
};
|
package/src/paywalls/present.ts
CHANGED
|
@@ -197,25 +197,31 @@ export const resolvePresentedOutcome = (
|
|
|
197
197
|
reported.status === "dismissed" && purchaseOutcome ? { status: purchaseOutcome } : reported;
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* `
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* `
|
|
206
|
-
* the
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
200
|
+
* What a presentation ENDS with. A purchase that settled `purchased` during it
|
|
201
|
+
* sticks (owner ruling on #286): no later report overturns it — a dismissal,
|
|
202
|
+
* a host's `error` (`render-error`, `paywall-disappeared`), a custom screen's
|
|
203
|
+
* `cancelled`. The user paid, and `register()` must not deny them. Otherwise
|
|
204
|
+
* `resolvePresentedOutcome`'s rule. Recording keeps the same rule: once
|
|
205
|
+
* `purchased`, a later store result (`cancelled`, or a second `purchased`) is
|
|
206
|
+
* not recorded, so the end keeps the FIRST purchase's key and paywall.
|
|
207
|
+
*/
|
|
208
|
+
export const resolveEndedOutcome = (
|
|
209
|
+
reported: PresentResult,
|
|
210
|
+
purchaseOutcome: PurchaseOutcomeDuringPresentation
|
|
211
|
+
): PresentResult =>
|
|
212
|
+
purchaseOutcome === "purchased" ? { status: "purchased" } : resolvePresentedOutcome(reported, purchaseOutcome);
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* How long a presentation whose paywall left the catalog with a purchase in
|
|
216
|
+
* flight waits for that purchase before ending `dismissed`. Mirrors
|
|
217
|
+
* `DEFAULT_PURCHASE_TIMEOUT_MS` in `../products/adapters/expoIap.ts` (not
|
|
218
|
+
* imported: that module pulls in the adapter's own imports), which answers
|
|
219
|
+
* `pending` after the same wait counted from the purchase START, so it settles
|
|
220
|
+
* first and this only fires for a provider with no bound of its own. The UI's
|
|
221
|
+
* inline step has the same constant (`usePaywallStepObservation.ts`), held
|
|
222
|
+
* equal by its test.
|
|
214
223
|
*/
|
|
215
|
-
export const
|
|
216
|
-
startedInGeneration: number,
|
|
217
|
-
currentGeneration: number
|
|
218
|
-
): boolean => startedInGeneration === currentGeneration;
|
|
224
|
+
export const LATE_PURCHASE_TIMEOUT_MS = 180_000;
|
|
219
225
|
|
|
220
226
|
/**
|
|
221
227
|
* Which of the two resolved product runtimes to publish.
|
package/src/paywalls/types.ts
CHANGED
|
@@ -205,7 +205,9 @@ export interface GetPaywallsResponseHeaders {
|
|
|
205
205
|
* (iOS will not present over an already-presenting view controller — another
|
|
206
206
|
* Modal, a `presentation: "modal"` route, a StoreKit alert).
|
|
207
207
|
* - `paywall-disappeared` — the moment vanished from the catalog while it
|
|
208
|
-
* was on screen (a studio publish, or a query-key change mid-presentation)
|
|
208
|
+
* was on screen (a studio publish, or a query-key change mid-presentation)
|
|
209
|
+
* and no purchase was made on it. A purchase wins: one that settled
|
|
210
|
+
* `purchased` resolves `purchased`, and one still in flight is waited for.
|
|
209
211
|
* - `unknown-custom-screen` — the paywall is `renderMode: "custom"` and names
|
|
210
212
|
* a `customScreenId` this host did not register (or names none at all), so
|
|
211
213
|
* there was nothing to render and the Modal was never opened. Deliberately
|