@rocapine/react-native-onboarding 1.68.2 → 1.70.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/OnboardingStudioClient.d.ts +4 -4
- package/dist/OnboardingStudioClient.js +7 -7
- package/dist/OnboardingStudioClient.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +38 -7
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +101 -44
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/present.d.ts +91 -12
- package/dist/paywalls/present.d.ts.map +1 -1
- package/dist/paywalls/present.js +75 -18
- package/dist/paywalls/present.js.map +1 -1
- package/dist/paywalls/types.d.ts +48 -23
- package/dist/paywalls/types.d.ts.map +1 -1
- package/dist/paywalls/types.js +0 -7
- package/dist/paywalls/types.js.map +1 -1
- package/dist/paywalls/usePaywall.d.ts +19 -4
- package/dist/paywalls/usePaywall.d.ts.map +1 -1
- package/dist/paywalls/usePaywall.js +2 -2
- package/dist/paywalls/usePaywall.js.map +1 -1
- package/dist/products/adapters/stripeLink.d.ts +57 -0
- package/dist/products/adapters/stripeLink.d.ts.map +1 -0
- package/dist/products/adapters/stripeLink.js +158 -0
- package/dist/products/adapters/stripeLink.js.map +1 -0
- package/dist/products/index.d.ts +4 -1
- package/dist/products/index.d.ts.map +1 -1
- package/dist/products/index.js +5 -1
- package/dist/products/index.js.map +1 -1
- package/dist/products/refIdentity.d.ts +3 -0
- package/dist/products/refIdentity.d.ts.map +1 -0
- package/dist/products/refIdentity.js +37 -0
- package/dist/products/refIdentity.js.map +1 -0
- package/dist/products/types.d.ts +29 -1
- package/dist/products/types.d.ts.map +1 -1
- package/dist/products/useProducts.d.ts.map +1 -1
- package/dist/products/useProducts.js +7 -1
- package/dist/products/useProducts.js.map +1 -1
- package/package.json +1 -1
- package/src/OnboardingStudioClient.ts +7 -7
- package/src/index.ts +3 -0
- package/src/paywalls/PaywallProvider.tsx +145 -48
- package/src/paywalls/__tests__/getPaywalls.test.ts +15 -12
- package/src/paywalls/__tests__/present.test.ts +192 -26
- package/src/paywalls/present.ts +115 -19
- package/src/paywalls/types.ts +49 -23
- package/src/paywalls/usePaywall.ts +22 -6
- package/src/products/__tests__/refIdentity.test.ts +44 -0
- package/src/products/adapters/__tests__/stripeLink.test.ts +179 -0
- package/src/products/adapters/stripeLink.ts +245 -0
- package/src/products/index.ts +4 -0
- package/src/products/refIdentity.ts +33 -0
- package/src/products/types.ts +30 -1
- package/src/products/useProducts.ts +7 -4
|
@@ -7,14 +7,17 @@ import {
|
|
|
7
7
|
collectProductRefs,
|
|
8
8
|
computeIsReady,
|
|
9
9
|
purchaseOutcomeFromResult,
|
|
10
|
+
computeCatalogStatus,
|
|
11
|
+
type CatalogStatus,
|
|
10
12
|
resolvePresentDecision,
|
|
13
|
+
selectActiveProductRuntime,
|
|
11
14
|
shouldBreakPresentationWedge,
|
|
12
15
|
resolvePresentedOutcome,
|
|
13
16
|
shouldRecordPurchaseOutcome,
|
|
14
17
|
type PurchaseOutcomeDuringPresentation,
|
|
15
18
|
} from "./present";
|
|
16
19
|
import { useProducts } from "../products/useProducts";
|
|
17
|
-
import { ProductProvider } from "../products/types";
|
|
20
|
+
import { ProductProvider, ProductStatus } from "../products/types";
|
|
18
21
|
import { ProductRuntimeContext } from "../products/ProductRuntimeContext";
|
|
19
22
|
import type { CustomActions } from "../infra/provider/OnboardingProvider";
|
|
20
23
|
|
|
@@ -48,13 +51,26 @@ const EMPTY_CUSTOM_ACTIONS: CustomActions = Object.freeze({});
|
|
|
48
51
|
* `infra/hooks/` slicing `OnboardingProgressContext`.
|
|
49
52
|
*/
|
|
50
53
|
export type PaywallContextValue = {
|
|
51
|
-
present: (
|
|
54
|
+
present: (moment: string) => Promise<PresentResult>;
|
|
52
55
|
isReady: boolean;
|
|
53
56
|
catalog: PaywallCatalog | null;
|
|
57
|
+
/**
|
|
58
|
+
* What the catalog is doing — the states `isReady` collapses into one
|
|
59
|
+
* boolean. See `CatalogStatus`; `"revalidating"` in particular means the
|
|
60
|
+
* catalog on hand may be superseded within moments, so a missing moment
|
|
61
|
+
* does not yet mean an absent one.
|
|
62
|
+
*/
|
|
63
|
+
catalogStatus: CatalogStatus;
|
|
64
|
+
/**
|
|
65
|
+
* What the store products are doing. The other half of `isReady`: a host that
|
|
66
|
+
* sees `catalogStatus: "ready"` but `isReady: false` can tell it is waiting on
|
|
67
|
+
* the store rather than on us.
|
|
68
|
+
*/
|
|
69
|
+
productsStatus: ProductStatus;
|
|
54
70
|
/** The paywall currently being presented, or null. Read by `usePaywallHost()` — not by `usePaywall()`. */
|
|
55
71
|
activePaywall: Paywall | null;
|
|
56
72
|
/**
|
|
57
|
-
* Resolve the pending `present()` call and clear the active
|
|
73
|
+
* Resolve the pending `present()` call and clear the active moment.
|
|
58
74
|
* Call this from the presented paywall's `ScreenHost.complete` (Task 7's
|
|
59
75
|
* `PaywallHost`) — never from an ordinary consumer.
|
|
60
76
|
*/
|
|
@@ -75,9 +91,12 @@ export type PaywallContextValue = {
|
|
|
75
91
|
const EMPTY_PAYWALL_CONTEXT: PaywallContextValue = {
|
|
76
92
|
// No provider above: there is no catalog at all, which is the same answer
|
|
77
93
|
// `resolvePresentDecision` gives for an unresolved one.
|
|
78
|
-
present: async () => ({ status: "error", reason: "unknown-
|
|
94
|
+
present: async () => ({ status: "error", reason: "unknown-moment" }),
|
|
79
95
|
isReady: false,
|
|
80
96
|
catalog: null,
|
|
97
|
+
// No provider above: nothing is loading and nothing will arrive.
|
|
98
|
+
catalogStatus: "loading",
|
|
99
|
+
productsStatus: "idle",
|
|
81
100
|
activePaywall: null,
|
|
82
101
|
complete: () => {},
|
|
83
102
|
acknowledgePresentation: () => {},
|
|
@@ -116,13 +135,30 @@ interface PaywallProviderProps {
|
|
|
116
135
|
locale?: string;
|
|
117
136
|
customAudienceParams?: Record<string, any>;
|
|
118
137
|
/**
|
|
119
|
-
* Billing adapter
|
|
120
|
-
*
|
|
138
|
+
* Billing adapter for `billing: "store"` paywalls — also the default while
|
|
139
|
+
* no paywall is active, and the fallback for `"stripe"` when
|
|
140
|
+
* `stripeProductProvider` (see that prop) was not passed. Resolved once,
|
|
141
|
+
* over the union of every `paywall.products[]` in the catalog
|
|
142
|
+
* (deduplicated).
|
|
143
|
+
*
|
|
144
|
+
* This adapter's result is NOT unconditionally what gets published: which
|
|
145
|
+
* of `productProvider`'s and `stripeProductProvider`'s resolution reaches
|
|
146
|
+
* `ProductRuntimeContext` depends on the active paywall's `billing` (see
|
|
147
|
+
* `selectActiveProductRuntime`). Whichever one is live, it is published via
|
|
121
148
|
* `ProductRuntimeContext` — an `OnboardingProvider` mounted anywhere inside
|
|
122
|
-
* this tree picks up
|
|
149
|
+
* this tree picks up that SAME runtime instead of resolving its own, so
|
|
123
150
|
* there is one store round-trip and one `purchasing` flag for both.
|
|
124
151
|
*/
|
|
125
152
|
productProvider?: ProductProvider;
|
|
153
|
+
/**
|
|
154
|
+
* Billing adapter for `billing: "stripe"` paywalls — normally
|
|
155
|
+
* `stripeLinkProductProvider`. The catalog's product union is resolved
|
|
156
|
+
* through BOTH this and `productProvider`, and the runtime published is the
|
|
157
|
+
* one matching the presented paywall's `billing` (see
|
|
158
|
+
* `selectActiveProductRuntime`). Omit it and every paywall uses
|
|
159
|
+
* `productProvider`, exactly as before this prop existed.
|
|
160
|
+
*/
|
|
161
|
+
stripeProductProvider?: ProductProvider;
|
|
126
162
|
/** Handlers for `{ type: "custom" }` ButtonActions inside a paywall's elements. */
|
|
127
163
|
customActions?: CustomActions;
|
|
128
164
|
/**
|
|
@@ -143,6 +179,7 @@ interface PaywallProviderInnerProps {
|
|
|
143
179
|
locale: string;
|
|
144
180
|
customAudienceParams: Record<string, any>;
|
|
145
181
|
productProvider?: ProductProvider;
|
|
182
|
+
stripeProductProvider?: ProductProvider;
|
|
146
183
|
customActions: CustomActions;
|
|
147
184
|
presentAckTimeoutMs: number | null;
|
|
148
185
|
}
|
|
@@ -153,6 +190,7 @@ const PaywallProviderInner = ({
|
|
|
153
190
|
locale,
|
|
154
191
|
customAudienceParams,
|
|
155
192
|
productProvider,
|
|
193
|
+
stripeProductProvider,
|
|
156
194
|
customActions,
|
|
157
195
|
presentAckTimeoutMs,
|
|
158
196
|
}: PaywallProviderInnerProps) => {
|
|
@@ -164,10 +202,14 @@ const PaywallProviderInner = ({
|
|
|
164
202
|
// for why the query still needs `paywallQueryClient` for the ONE case
|
|
165
203
|
// `data` alone can't cover: a background revalidation pushing a fresh
|
|
166
204
|
// payload while this query call already resolved with the cached one.
|
|
167
|
-
const { data, error } = useQuery<PaywallCatalog>(
|
|
205
|
+
const { data, error, isFetching } = useQuery<PaywallCatalog>(
|
|
168
206
|
getPaywallsQuery(client, locale, customAudienceParams, paywallQueryClient)
|
|
169
207
|
);
|
|
170
208
|
const catalog = data ?? null;
|
|
209
|
+
// `isFetching` (not `isLoading`) on purpose: it is also true for a BACKGROUND
|
|
210
|
+
// revalidation behind an already-served cached catalog, which is precisely the
|
|
211
|
+
// case a host needs to see — see `CatalogStatus`.
|
|
212
|
+
const catalogStatus = computeCatalogStatus(catalog, error, isFetching);
|
|
171
213
|
|
|
172
214
|
useEffect(() => {
|
|
173
215
|
if (!error) return;
|
|
@@ -176,17 +218,68 @@ const PaywallProviderInner = ({
|
|
|
176
218
|
// but `PaywallProvider` wraps the WHOLE app (spec §7:
|
|
177
219
|
// `<PaywallProvider><App/><PaywallHost/></PaywallProvider>`), so throwing
|
|
178
220
|
// here would crash every screen over a paywall-catalog failure alone.
|
|
179
|
-
// Instead: `catalog` simply stays null, `present()` on any
|
|
221
|
+
// Instead: `catalog` simply stays null, `present()` on any moment
|
|
180
222
|
// resolves "error" (see `resolvePresentDecision` — an unresolved catalog
|
|
181
|
-
// looks identical to an unknown
|
|
223
|
+
// looks identical to an unknown moment), and `isReady` stays false.
|
|
182
224
|
console.warn("[paywalls] Failed to load paywall catalog:", error);
|
|
183
225
|
}, [error]);
|
|
184
226
|
|
|
185
|
-
//
|
|
227
|
+
// Hoisted above `productRefs`/the product runtimes below: `activeMoment`
|
|
228
|
+
// (state) and `activePaywall` (derived from it) are read by the runtime
|
|
229
|
+
// selection that follows. Bare `useState(null)` with no dependencies, so
|
|
230
|
+
// hoisting past the effects and refs below it changes nothing about hook
|
|
231
|
+
// order.
|
|
232
|
+
const [activeMoment, setActiveMoment] = useState<string | null>(null);
|
|
233
|
+
// Finding 6, 2026-08-17 final review, widened by N2 (round 2): a background
|
|
234
|
+
// catalog revalidation (see `getPaywalls.query.ts`) can push a fresh catalog
|
|
235
|
+
// that no longer contains the moment currently on screen (a studio
|
|
236
|
+
// publish renamed or removed it mid-session) — OR the query KEY itself can
|
|
237
|
+
// change while a paywall is showing (`locale`/`customAudienceParams`
|
|
238
|
+
// changed as a prop), which makes react-query report `data: undefined`
|
|
239
|
+
// while the new key is fetching (Finding 1's fix reads `catalog` straight
|
|
240
|
+
// from that `data`). Both collapse `activePaywall` to null the same way, so
|
|
241
|
+
// guarding on THAT — not on `catalog` being non-null — catches both: the
|
|
242
|
+
// original guard (`!catalog` check) missed the query-key case entirely,
|
|
243
|
+
// because a null `catalog` made it bail out before ever checking whether
|
|
244
|
+
// the moment was still present.
|
|
245
|
+
const activePaywall = activeMoment ? catalog?.paywalls[activeMoment] ?? null : null;
|
|
246
|
+
|
|
247
|
+
// Union of every moment's products, deduplicated, resolved ONCE — never
|
|
186
248
|
// re-keyed per presented paywall. See `present.ts`'s `collectProductRefs`
|
|
187
249
|
// doc for why (spec §6.1's "render instantly on tap" requirement).
|
|
188
250
|
const productRefs = useMemo(() => collectProductRefs(catalog), [catalog]);
|
|
189
|
-
|
|
251
|
+
// Resolved TWICE — once per billing adapter — because the runtime is
|
|
252
|
+
// published as one map keyed by product key, and a `store` paywall and a
|
|
253
|
+
// `stripe` paywall declaring the same key would otherwise fight over
|
|
254
|
+
// `product.<key>.price`. See `selectActiveProductRuntime`'s doc for why
|
|
255
|
+
// this is cheap rather than wasteful, and why the statuses must not merge.
|
|
256
|
+
const storeRuntime = useProducts(productRefs, productProvider, locale);
|
|
257
|
+
// Free in practice: `stripeLinkProductProvider.getProducts` makes no network
|
|
258
|
+
// call, and refs without a `stripe` block are dropped.
|
|
259
|
+
const stripeRuntime = useProducts(productRefs, stripeProductProvider, locale);
|
|
260
|
+
const productRuntime = selectActiveProductRuntime({
|
|
261
|
+
storeRuntime,
|
|
262
|
+
stripeRuntime,
|
|
263
|
+
billing: activePaywall?.billing,
|
|
264
|
+
hasStripeProvider: stripeProductProvider !== undefined,
|
|
265
|
+
// Lets `selectActiveProductRuntime` prefer the stripe runtime while no
|
|
266
|
+
// paywall is active yet, for a host that passed ONLY
|
|
267
|
+
// `stripeProductProvider` — see that function's doc.
|
|
268
|
+
hasStoreProvider: productProvider !== undefined,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// A studio author can set `billing: "stripe"` on a paywall before the host
|
|
272
|
+
// ships the adapter. Loud, because the symptom otherwise is a paywall that
|
|
273
|
+
// charges through the store while the dashboard says Stripe.
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
if (activePaywall?.billing === "stripe" && !stripeProductProvider) {
|
|
276
|
+
console.warn(
|
|
277
|
+
`[paywalls] "${activePaywall.name}" is set to Stripe billing, but no ` +
|
|
278
|
+
"`stripeProductProvider` was passed to PaywallProvider — falling back to the store " +
|
|
279
|
+
"adapter. Pass `stripeLinkProductProvider({ clientReferenceId })` to honour it.",
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}, [activePaywall, stripeProductProvider]);
|
|
190
283
|
|
|
191
284
|
// Tracks what a purchase attempt resolved to during the CURRENT
|
|
192
285
|
// presentation — read by `complete()` to upgrade a generic "dismissed"
|
|
@@ -230,7 +323,8 @@ const PaywallProviderInner = ({
|
|
|
230
323
|
[productRuntime, purchase]
|
|
231
324
|
);
|
|
232
325
|
|
|
233
|
-
|
|
326
|
+
// `activeMoment`'s `useState` was hoisted above `productRefs` — see the
|
|
327
|
+
// comment there. Only `hostAcknowledged` is declared here.
|
|
234
328
|
// Whether the host has confirmed THIS presentation is on screen. State, not
|
|
235
329
|
// a ref, because the timeout effect below must re-run (and cancel) the moment
|
|
236
330
|
// it flips.
|
|
@@ -240,7 +334,7 @@ const PaywallProviderInner = ({
|
|
|
240
334
|
// `purchase`/`restore` callbacks.
|
|
241
335
|
const catalogRef = useRef(catalog);
|
|
242
336
|
catalogRef.current = catalog;
|
|
243
|
-
// `
|
|
337
|
+
// `activeMomentRef` is made AUTHORITATIVE below — assigned inside
|
|
244
338
|
// `present()`'s start branch and inside `complete()`, not just here. Finding
|
|
245
339
|
// 4, 2026-08-17 final review: this line alone only resyncs the ref from
|
|
246
340
|
// state AFTER React commits, so between a `present()` call and the next
|
|
@@ -252,17 +346,17 @@ const PaywallProviderInner = ({
|
|
|
252
346
|
// orphaning this whole ref/resolver scheme exists to prevent. Assigning
|
|
253
347
|
// synchronously inside `present`/`complete` closes that window; this
|
|
254
348
|
// render-body line stays only as a resync for the (rare) case something
|
|
255
|
-
// external changes `
|
|
349
|
+
// external changes `activeMoment` state without going through either
|
|
256
350
|
// callback.
|
|
257
|
-
const
|
|
258
|
-
|
|
351
|
+
const activeMomentRef = useRef(activeMoment);
|
|
352
|
+
activeMomentRef.current = activeMoment;
|
|
259
353
|
const pendingResolveRef = useRef<((result: PresentResult) => void) | null>(null);
|
|
260
354
|
|
|
261
355
|
// present() must not fetch anything — the catalog and products are already
|
|
262
356
|
// resolved (or resolving) from mount. It only decides, synchronously,
|
|
263
357
|
// whether to show the Modal.
|
|
264
|
-
const present = useCallback((
|
|
265
|
-
const decision = resolvePresentDecision(catalogRef.current,
|
|
358
|
+
const present = useCallback((moment: string): Promise<PresentResult> => {
|
|
359
|
+
const decision = resolvePresentDecision(catalogRef.current, activeMomentRef.current, moment);
|
|
266
360
|
if (decision.type === "immediate") {
|
|
267
361
|
return Promise.resolve(decision.result);
|
|
268
362
|
}
|
|
@@ -274,20 +368,20 @@ const PaywallProviderInner = ({
|
|
|
274
368
|
// Authoritative NOW, synchronously — see the ref's doc above. A second
|
|
275
369
|
// `present()` call before React commits reads this value, not the stale
|
|
276
370
|
// pre-commit state, and correctly takes the "already showing" branch.
|
|
277
|
-
|
|
371
|
+
activeMomentRef.current = moment;
|
|
278
372
|
return new Promise<PresentResult>((resolve) => {
|
|
279
373
|
pendingResolveRef.current = resolve;
|
|
280
374
|
// A new presentation is unacknowledged until the host says otherwise —
|
|
281
375
|
// reset before it starts, or the previous presentation's confirmation
|
|
282
376
|
// would vouch for this one and disable the recovery.
|
|
283
377
|
setHostAcknowledged(false);
|
|
284
|
-
|
|
378
|
+
setActiveMoment(moment);
|
|
285
379
|
});
|
|
286
380
|
}, []);
|
|
287
381
|
|
|
288
382
|
// Called by PaywallHost (Task 7) from the presented paywall's
|
|
289
383
|
// `ScreenHost.complete`. Resolves whatever `present()` call is pending and
|
|
290
|
-
// clears the active
|
|
384
|
+
// clears the active moment, hiding the Modal and allowing a new
|
|
291
385
|
// `present()` to start. Safe to call with nothing pending (no-ops).
|
|
292
386
|
//
|
|
293
387
|
// `resolvePresentedOutcome` upgrades a bare "dismissed" to "purchased" (or
|
|
@@ -303,8 +397,8 @@ const PaywallProviderInner = ({
|
|
|
303
397
|
// opening from the previous paywall's resolution is a canonical pattern,
|
|
304
398
|
// spec §4.5) must see "nothing showing" immediately, not wait for the
|
|
305
399
|
// next commit.
|
|
306
|
-
|
|
307
|
-
|
|
400
|
+
activeMomentRef.current = null;
|
|
401
|
+
setActiveMoment(null);
|
|
308
402
|
setHostAcknowledged(false);
|
|
309
403
|
resolve?.(resolvePresentedOutcome(result, lastPurchaseOutcomeRef.current));
|
|
310
404
|
}, []);
|
|
@@ -315,31 +409,20 @@ const PaywallProviderInner = ({
|
|
|
315
409
|
setHostAcknowledged(true);
|
|
316
410
|
}, []);
|
|
317
411
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
//
|
|
321
|
-
// catalog revalidation (see `getPaywalls.query.ts`) can push a fresh catalog
|
|
322
|
-
// that no longer contains the placement currently on screen (a studio
|
|
323
|
-
// publish renamed or removed it mid-session) — OR the query KEY itself can
|
|
324
|
-
// change while a paywall is showing (`locale`/`customAudienceParams`
|
|
325
|
-
// changed as a prop), which makes react-query report `data: undefined`
|
|
326
|
-
// while the new key is fetching (Finding 1's fix reads `catalog` straight
|
|
327
|
-
// from that `data`). Both collapse `activePaywall` to null the same way, so
|
|
328
|
-
// guarding on THAT — not on `catalog` being non-null — catches both: the
|
|
329
|
-
// original guard (`!catalog` check) missed the query-key case entirely,
|
|
330
|
-
// because a null `catalog` made it bail out before ever checking whether
|
|
331
|
-
// the placement was still present.
|
|
412
|
+
// `activePaywall` was hoisted above `productRefs` — see the comment there
|
|
413
|
+
// (Finding 6, 2026-08-17 final review) for why it is derived from
|
|
414
|
+
// `activeMoment` rather than guarded on `catalog` alone.
|
|
332
415
|
//
|
|
333
416
|
// Either way, the Modal closes itself WITHOUT going through `complete()`,
|
|
334
417
|
// so the pending `present()` promise would never settle and
|
|
335
|
-
// `
|
|
418
|
+
// `activeMoment` would stay set forever, silently failing every later
|
|
336
419
|
// `present()` call with `"error"` for the rest of the app's life.
|
|
337
|
-
// `complete()` always clears `
|
|
420
|
+
// `complete()` always clears `activeMoment` together with resolving the
|
|
338
421
|
// pending promise, so it cannot race with or double-resolve this branch.
|
|
339
422
|
useEffect(() => {
|
|
340
|
-
if (!
|
|
423
|
+
if (!activeMoment || activePaywall) return;
|
|
341
424
|
complete({ status: "error", reason: "paywall-disappeared" });
|
|
342
|
-
}, [
|
|
425
|
+
}, [activeMoment, activePaywall, complete]);
|
|
343
426
|
|
|
344
427
|
// The OTHER way a presentation never completes, and the one the guard above
|
|
345
428
|
// structurally cannot catch: `activePaywall` is perfectly non-null — the
|
|
@@ -348,8 +431,8 @@ const PaywallProviderInner = ({
|
|
|
348
431
|
// already-presenting view controller: another Modal, a
|
|
349
432
|
// `presentation: "modal"` route, a StoreKit alert). Nothing calls
|
|
350
433
|
// `complete()`, so without this the pending promise never settles,
|
|
351
|
-
// `
|
|
352
|
-
// `present()` — for any
|
|
434
|
+
// `activeMoment` stays set for the life of the process, and every later
|
|
435
|
+
// `present()` — for any moment — resolves "already-presenting" with no
|
|
353
436
|
// error and no log. Confirmed in production on a monetisation surface, which
|
|
354
437
|
// is why this recovers rather than merely reports.
|
|
355
438
|
//
|
|
@@ -357,10 +440,10 @@ const PaywallProviderInner = ({
|
|
|
357
440
|
// reading is never torn down; see `shouldBreakPresentationWedge`.
|
|
358
441
|
useEffect(() => {
|
|
359
442
|
if (presentAckTimeoutMs === null) return;
|
|
360
|
-
if (!shouldBreakPresentationWedge(
|
|
443
|
+
if (!shouldBreakPresentationWedge(activeMoment, hostAcknowledged, true)) return;
|
|
361
444
|
const timer = setTimeout(() => {
|
|
362
445
|
console.warn(
|
|
363
|
-
`[paywalls] "${
|
|
446
|
+
`[paywalls] "${activeMoment}" was never confirmed on screen within ` +
|
|
364
447
|
`${presentAckTimeoutMs}ms and has been abandoned, so later present() calls keep working. ` +
|
|
365
448
|
"The platform most likely refused to present it — on iOS, something else was already " +
|
|
366
449
|
"presenting (another Modal, a `presentation: \"modal\"` route, or a StoreKit alert).",
|
|
@@ -368,7 +451,7 @@ const PaywallProviderInner = ({
|
|
|
368
451
|
complete({ status: "error", reason: "host-never-presented" });
|
|
369
452
|
}, presentAckTimeoutMs);
|
|
370
453
|
return () => clearTimeout(timer);
|
|
371
|
-
}, [
|
|
454
|
+
}, [activeMoment, hostAcknowledged, presentAckTimeoutMs, complete]);
|
|
372
455
|
|
|
373
456
|
const isReady = useMemo(
|
|
374
457
|
() => computeIsReady(catalog, productRefs, productRuntime.status),
|
|
@@ -380,12 +463,24 @@ const PaywallProviderInner = ({
|
|
|
380
463
|
present,
|
|
381
464
|
isReady,
|
|
382
465
|
catalog,
|
|
466
|
+
catalogStatus,
|
|
467
|
+
productsStatus: productRuntime.status,
|
|
383
468
|
activePaywall,
|
|
384
469
|
complete,
|
|
385
470
|
acknowledgePresentation,
|
|
386
471
|
customActions,
|
|
387
472
|
}),
|
|
388
|
-
[
|
|
473
|
+
[
|
|
474
|
+
present,
|
|
475
|
+
isReady,
|
|
476
|
+
catalog,
|
|
477
|
+
catalogStatus,
|
|
478
|
+
productRuntime.status,
|
|
479
|
+
activePaywall,
|
|
480
|
+
complete,
|
|
481
|
+
acknowledgePresentation,
|
|
482
|
+
customActions,
|
|
483
|
+
]
|
|
389
484
|
);
|
|
390
485
|
|
|
391
486
|
return (
|
|
@@ -413,6 +508,7 @@ export const PaywallProvider = ({
|
|
|
413
508
|
locale = "en",
|
|
414
509
|
customAudienceParams = {},
|
|
415
510
|
productProvider,
|
|
511
|
+
stripeProductProvider,
|
|
416
512
|
customActions = EMPTY_CUSTOM_ACTIONS,
|
|
417
513
|
presentAckTimeoutMs = DEFAULT_PRESENT_ACK_TIMEOUT_MS,
|
|
418
514
|
}: PaywallProviderProps) => {
|
|
@@ -423,6 +519,7 @@ export const PaywallProvider = ({
|
|
|
423
519
|
locale={locale}
|
|
424
520
|
customAudienceParams={customAudienceParams}
|
|
425
521
|
productProvider={productProvider}
|
|
522
|
+
stripeProductProvider={stripeProductProvider}
|
|
426
523
|
customActions={customActions}
|
|
427
524
|
presentAckTimeoutMs={presentAckTimeoutMs}
|
|
428
525
|
>
|
|
@@ -29,13 +29,16 @@ const CUSTOM_KEY = "v2";
|
|
|
29
29
|
const CUSTOM_CACHE_KEY = "rocapine-paywalls-sdk-v2";
|
|
30
30
|
|
|
31
31
|
const catalog: PaywallCatalog = {
|
|
32
|
-
metadata: {
|
|
32
|
+
metadata: { locale: "en", draft: false },
|
|
33
33
|
paywalls: {
|
|
34
34
|
onboarding_end: {
|
|
35
35
|
id: "pw1",
|
|
36
36
|
name: "End paywall",
|
|
37
|
-
|
|
37
|
+
moment: "onboarding_end",
|
|
38
|
+
audienceId: 1,
|
|
39
|
+
audienceName: "default",
|
|
38
40
|
elements: [],
|
|
41
|
+
billing: "store",
|
|
39
42
|
products: [{ key: "monthly", ios: "com.app.monthly" }],
|
|
40
43
|
configuration: null,
|
|
41
44
|
},
|
|
@@ -70,10 +73,10 @@ describe("OnboardingStudioClient.getPaywalls", () => {
|
|
|
70
73
|
vi.unstubAllGlobals();
|
|
71
74
|
});
|
|
72
75
|
|
|
73
|
-
it("builds the URL against get-paywalls with projectId/platform/appVersion/locale, and omits
|
|
76
|
+
it("builds the URL against get-paywalls with projectId/platform/appVersion/locale, and omits moment by default", async () => {
|
|
74
77
|
fetchMock.mockResolvedValue(
|
|
75
78
|
fakeResponse(catalog, {
|
|
76
|
-
headers: { "ONBS-Audience-
|
|
79
|
+
headers: { "ONBS-Audience-Ids": "42", "ONBS-Paywall-Ids": "pw1" },
|
|
77
80
|
})
|
|
78
81
|
);
|
|
79
82
|
const client = new OnboardingStudioClient("proj-1", { appVersion: "1.2.3" });
|
|
@@ -87,18 +90,18 @@ describe("OnboardingStudioClient.getPaywalls", () => {
|
|
|
87
90
|
expect(requestedUrl.searchParams.get("platform")).toBe("ios");
|
|
88
91
|
expect(requestedUrl.searchParams.get("appVersion")).toBe("1.2.3");
|
|
89
92
|
expect(requestedUrl.searchParams.get("locale")).toBe("fr");
|
|
90
|
-
expect(requestedUrl.searchParams.has("
|
|
93
|
+
expect(requestedUrl.searchParams.has("moment")).toBe(false);
|
|
91
94
|
expect(requestedUrl.searchParams.has("draft")).toBe(false);
|
|
92
95
|
});
|
|
93
96
|
|
|
94
|
-
it("includes
|
|
97
|
+
it("includes moment only when explicitly requested (the exception, not the default)", async () => {
|
|
95
98
|
fetchMock.mockResolvedValue(fakeResponse(catalog));
|
|
96
99
|
const client = new OnboardingStudioClient("proj-1", {});
|
|
97
100
|
|
|
98
|
-
await client.getPaywalls({ locale: "en",
|
|
101
|
+
await client.getPaywalls({ locale: "en", moment: "onboarding_end" });
|
|
99
102
|
|
|
100
103
|
const requestedUrl = new URL(fetchMock.mock.calls[0][0] as string);
|
|
101
|
-
expect(requestedUrl.searchParams.get("
|
|
104
|
+
expect(requestedUrl.searchParams.get("moment")).toBe("onboarding_end");
|
|
102
105
|
});
|
|
103
106
|
|
|
104
107
|
it("appends draft=true in sandbox mode, same as getSteps", async () => {
|
|
@@ -121,10 +124,10 @@ describe("OnboardingStudioClient.getPaywalls", () => {
|
|
|
121
124
|
expect(requestedUrl.searchParams.get("experimentGroup")).toBe("b");
|
|
122
125
|
});
|
|
123
126
|
|
|
124
|
-
it("extracts ONBS-Audience-
|
|
127
|
+
it("extracts ONBS-Audience-Ids and ONBS-Paywall-Ids — not the onboarding header trio", async () => {
|
|
125
128
|
fetchMock.mockResolvedValue(
|
|
126
129
|
fakeResponse(catalog, {
|
|
127
|
-
headers: { "ONBS-Audience-
|
|
130
|
+
headers: { "ONBS-Audience-Ids": "7", "ONBS-Paywall-Ids": "pw1,pw2" },
|
|
128
131
|
})
|
|
129
132
|
);
|
|
130
133
|
const client = new OnboardingStudioClient("proj-1", {});
|
|
@@ -133,7 +136,7 @@ describe("OnboardingStudioClient.getPaywalls", () => {
|
|
|
133
136
|
|
|
134
137
|
expect(data).toEqual(catalog);
|
|
135
138
|
expect(headers).toEqual({
|
|
136
|
-
"ONBS-Audience-
|
|
139
|
+
"ONBS-Audience-Ids": "7",
|
|
137
140
|
"ONBS-Paywall-Ids": "pw1,pw2",
|
|
138
141
|
});
|
|
139
142
|
expect(headers).not.toHaveProperty("ONBS-Onboarding-Id");
|
|
@@ -182,7 +185,7 @@ const makeClient = (
|
|
|
182
185
|
const getPaywalls = vi.fn().mockResolvedValue({
|
|
183
186
|
data,
|
|
184
187
|
headers: {
|
|
185
|
-
"ONBS-Audience-
|
|
188
|
+
"ONBS-Audience-Ids": "1",
|
|
186
189
|
"ONBS-Paywall-Ids": Object.keys(data.paywalls).join(","),
|
|
187
190
|
},
|
|
188
191
|
});
|