@rocapine/react-native-onboarding 1.69.0 → 1.71.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/paywalls/PaywallProvider.d.ts +24 -7
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +80 -42
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/present.d.ts +60 -14
- package/dist/paywalls/present.d.ts.map +1 -1
- package/dist/paywalls/present.js +67 -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 +5 -5
- package/dist/paywalls/usePaywall.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.js +118 -11
- package/dist/products/adapters/expoIap.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/dist/steps/common.types.d.ts +2 -0
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +1 -0
- package/dist/steps/common.types.js.map +1 -1
- package/package.json +1 -1
- package/src/OnboardingStudioClient.ts +7 -7
- package/src/paywalls/PaywallProvider.tsx +109 -46
- package/src/paywalls/__tests__/getPaywalls.test.ts +15 -12
- package/src/paywalls/__tests__/present.test.ts +149 -28
- package/src/paywalls/present.ts +74 -21
- package/src/paywalls/types.ts +49 -23
- package/src/paywalls/usePaywall.ts +5 -5
- package/src/products/__tests__/refIdentity.test.ts +44 -0
- package/src/products/adapters/__tests__/expoIap.test.ts +210 -0
- package/src/products/adapters/__tests__/stripeLink.test.ts +179 -0
- package/src/products/adapters/expoIap.ts +121 -5
- 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
- package/src/steps/common.types.ts +3 -0
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
computeCatalogStatus,
|
|
11
11
|
type CatalogStatus,
|
|
12
12
|
resolvePresentDecision,
|
|
13
|
+
selectActiveProductRuntime,
|
|
13
14
|
shouldBreakPresentationWedge,
|
|
14
15
|
resolvePresentedOutcome,
|
|
15
16
|
shouldRecordPurchaseOutcome,
|
|
@@ -50,13 +51,13 @@ const EMPTY_CUSTOM_ACTIONS: CustomActions = Object.freeze({});
|
|
|
50
51
|
* `infra/hooks/` slicing `OnboardingProgressContext`.
|
|
51
52
|
*/
|
|
52
53
|
export type PaywallContextValue = {
|
|
53
|
-
present: (
|
|
54
|
+
present: (moment: string) => Promise<PresentResult>;
|
|
54
55
|
isReady: boolean;
|
|
55
56
|
catalog: PaywallCatalog | null;
|
|
56
57
|
/**
|
|
57
58
|
* What the catalog is doing — the states `isReady` collapses into one
|
|
58
59
|
* boolean. See `CatalogStatus`; `"revalidating"` in particular means the
|
|
59
|
-
* catalog on hand may be superseded within moments, so a missing
|
|
60
|
+
* catalog on hand may be superseded within moments, so a missing moment
|
|
60
61
|
* does not yet mean an absent one.
|
|
61
62
|
*/
|
|
62
63
|
catalogStatus: CatalogStatus;
|
|
@@ -69,7 +70,7 @@ export type PaywallContextValue = {
|
|
|
69
70
|
/** The paywall currently being presented, or null. Read by `usePaywallHost()` — not by `usePaywall()`. */
|
|
70
71
|
activePaywall: Paywall | null;
|
|
71
72
|
/**
|
|
72
|
-
* Resolve the pending `present()` call and clear the active
|
|
73
|
+
* Resolve the pending `present()` call and clear the active moment.
|
|
73
74
|
* Call this from the presented paywall's `ScreenHost.complete` (Task 7's
|
|
74
75
|
* `PaywallHost`) — never from an ordinary consumer.
|
|
75
76
|
*/
|
|
@@ -90,7 +91,7 @@ export type PaywallContextValue = {
|
|
|
90
91
|
const EMPTY_PAYWALL_CONTEXT: PaywallContextValue = {
|
|
91
92
|
// No provider above: there is no catalog at all, which is the same answer
|
|
92
93
|
// `resolvePresentDecision` gives for an unresolved one.
|
|
93
|
-
present: async () => ({ status: "error", reason: "unknown-
|
|
94
|
+
present: async () => ({ status: "error", reason: "unknown-moment" }),
|
|
94
95
|
isReady: false,
|
|
95
96
|
catalog: null,
|
|
96
97
|
// No provider above: nothing is loading and nothing will arrive.
|
|
@@ -134,13 +135,30 @@ interface PaywallProviderProps {
|
|
|
134
135
|
locale?: string;
|
|
135
136
|
customAudienceParams?: Record<string, any>;
|
|
136
137
|
/**
|
|
137
|
-
* Billing adapter
|
|
138
|
-
*
|
|
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
|
|
139
148
|
* `ProductRuntimeContext` — an `OnboardingProvider` mounted anywhere inside
|
|
140
|
-
* this tree picks up
|
|
149
|
+
* this tree picks up that SAME runtime instead of resolving its own, so
|
|
141
150
|
* there is one store round-trip and one `purchasing` flag for both.
|
|
142
151
|
*/
|
|
143
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;
|
|
144
162
|
/** Handlers for `{ type: "custom" }` ButtonActions inside a paywall's elements. */
|
|
145
163
|
customActions?: CustomActions;
|
|
146
164
|
/**
|
|
@@ -161,6 +179,7 @@ interface PaywallProviderInnerProps {
|
|
|
161
179
|
locale: string;
|
|
162
180
|
customAudienceParams: Record<string, any>;
|
|
163
181
|
productProvider?: ProductProvider;
|
|
182
|
+
stripeProductProvider?: ProductProvider;
|
|
164
183
|
customActions: CustomActions;
|
|
165
184
|
presentAckTimeoutMs: number | null;
|
|
166
185
|
}
|
|
@@ -171,6 +190,7 @@ const PaywallProviderInner = ({
|
|
|
171
190
|
locale,
|
|
172
191
|
customAudienceParams,
|
|
173
192
|
productProvider,
|
|
193
|
+
stripeProductProvider,
|
|
174
194
|
customActions,
|
|
175
195
|
presentAckTimeoutMs,
|
|
176
196
|
}: PaywallProviderInnerProps) => {
|
|
@@ -198,17 +218,68 @@ const PaywallProviderInner = ({
|
|
|
198
218
|
// but `PaywallProvider` wraps the WHOLE app (spec §7:
|
|
199
219
|
// `<PaywallProvider><App/><PaywallHost/></PaywallProvider>`), so throwing
|
|
200
220
|
// here would crash every screen over a paywall-catalog failure alone.
|
|
201
|
-
// Instead: `catalog` simply stays null, `present()` on any
|
|
221
|
+
// Instead: `catalog` simply stays null, `present()` on any moment
|
|
202
222
|
// resolves "error" (see `resolvePresentDecision` — an unresolved catalog
|
|
203
|
-
// looks identical to an unknown
|
|
223
|
+
// looks identical to an unknown moment), and `isReady` stays false.
|
|
204
224
|
console.warn("[paywalls] Failed to load paywall catalog:", error);
|
|
205
225
|
}, [error]);
|
|
206
226
|
|
|
207
|
-
//
|
|
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
|
|
208
248
|
// re-keyed per presented paywall. See `present.ts`'s `collectProductRefs`
|
|
209
249
|
// doc for why (spec §6.1's "render instantly on tap" requirement).
|
|
210
250
|
const productRefs = useMemo(() => collectProductRefs(catalog), [catalog]);
|
|
211
|
-
|
|
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]);
|
|
212
283
|
|
|
213
284
|
// Tracks what a purchase attempt resolved to during the CURRENT
|
|
214
285
|
// presentation — read by `complete()` to upgrade a generic "dismissed"
|
|
@@ -252,7 +323,8 @@ const PaywallProviderInner = ({
|
|
|
252
323
|
[productRuntime, purchase]
|
|
253
324
|
);
|
|
254
325
|
|
|
255
|
-
|
|
326
|
+
// `activeMoment`'s `useState` was hoisted above `productRefs` — see the
|
|
327
|
+
// comment there. Only `hostAcknowledged` is declared here.
|
|
256
328
|
// Whether the host has confirmed THIS presentation is on screen. State, not
|
|
257
329
|
// a ref, because the timeout effect below must re-run (and cancel) the moment
|
|
258
330
|
// it flips.
|
|
@@ -262,7 +334,7 @@ const PaywallProviderInner = ({
|
|
|
262
334
|
// `purchase`/`restore` callbacks.
|
|
263
335
|
const catalogRef = useRef(catalog);
|
|
264
336
|
catalogRef.current = catalog;
|
|
265
|
-
// `
|
|
337
|
+
// `activeMomentRef` is made AUTHORITATIVE below — assigned inside
|
|
266
338
|
// `present()`'s start branch and inside `complete()`, not just here. Finding
|
|
267
339
|
// 4, 2026-08-17 final review: this line alone only resyncs the ref from
|
|
268
340
|
// state AFTER React commits, so between a `present()` call and the next
|
|
@@ -274,17 +346,17 @@ const PaywallProviderInner = ({
|
|
|
274
346
|
// orphaning this whole ref/resolver scheme exists to prevent. Assigning
|
|
275
347
|
// synchronously inside `present`/`complete` closes that window; this
|
|
276
348
|
// render-body line stays only as a resync for the (rare) case something
|
|
277
|
-
// external changes `
|
|
349
|
+
// external changes `activeMoment` state without going through either
|
|
278
350
|
// callback.
|
|
279
|
-
const
|
|
280
|
-
|
|
351
|
+
const activeMomentRef = useRef(activeMoment);
|
|
352
|
+
activeMomentRef.current = activeMoment;
|
|
281
353
|
const pendingResolveRef = useRef<((result: PresentResult) => void) | null>(null);
|
|
282
354
|
|
|
283
355
|
// present() must not fetch anything — the catalog and products are already
|
|
284
356
|
// resolved (or resolving) from mount. It only decides, synchronously,
|
|
285
357
|
// whether to show the Modal.
|
|
286
|
-
const present = useCallback((
|
|
287
|
-
const decision = resolvePresentDecision(catalogRef.current,
|
|
358
|
+
const present = useCallback((moment: string): Promise<PresentResult> => {
|
|
359
|
+
const decision = resolvePresentDecision(catalogRef.current, activeMomentRef.current, moment);
|
|
288
360
|
if (decision.type === "immediate") {
|
|
289
361
|
return Promise.resolve(decision.result);
|
|
290
362
|
}
|
|
@@ -296,20 +368,20 @@ const PaywallProviderInner = ({
|
|
|
296
368
|
// Authoritative NOW, synchronously — see the ref's doc above. A second
|
|
297
369
|
// `present()` call before React commits reads this value, not the stale
|
|
298
370
|
// pre-commit state, and correctly takes the "already showing" branch.
|
|
299
|
-
|
|
371
|
+
activeMomentRef.current = moment;
|
|
300
372
|
return new Promise<PresentResult>((resolve) => {
|
|
301
373
|
pendingResolveRef.current = resolve;
|
|
302
374
|
// A new presentation is unacknowledged until the host says otherwise —
|
|
303
375
|
// reset before it starts, or the previous presentation's confirmation
|
|
304
376
|
// would vouch for this one and disable the recovery.
|
|
305
377
|
setHostAcknowledged(false);
|
|
306
|
-
|
|
378
|
+
setActiveMoment(moment);
|
|
307
379
|
});
|
|
308
380
|
}, []);
|
|
309
381
|
|
|
310
382
|
// Called by PaywallHost (Task 7) from the presented paywall's
|
|
311
383
|
// `ScreenHost.complete`. Resolves whatever `present()` call is pending and
|
|
312
|
-
// clears the active
|
|
384
|
+
// clears the active moment, hiding the Modal and allowing a new
|
|
313
385
|
// `present()` to start. Safe to call with nothing pending (no-ops).
|
|
314
386
|
//
|
|
315
387
|
// `resolvePresentedOutcome` upgrades a bare "dismissed" to "purchased" (or
|
|
@@ -325,8 +397,8 @@ const PaywallProviderInner = ({
|
|
|
325
397
|
// opening from the previous paywall's resolution is a canonical pattern,
|
|
326
398
|
// spec §4.5) must see "nothing showing" immediately, not wait for the
|
|
327
399
|
// next commit.
|
|
328
|
-
|
|
329
|
-
|
|
400
|
+
activeMomentRef.current = null;
|
|
401
|
+
setActiveMoment(null);
|
|
330
402
|
setHostAcknowledged(false);
|
|
331
403
|
resolve?.(resolvePresentedOutcome(result, lastPurchaseOutcomeRef.current));
|
|
332
404
|
}, []);
|
|
@@ -337,31 +409,20 @@ const PaywallProviderInner = ({
|
|
|
337
409
|
setHostAcknowledged(true);
|
|
338
410
|
}, []);
|
|
339
411
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
//
|
|
343
|
-
// catalog revalidation (see `getPaywalls.query.ts`) can push a fresh catalog
|
|
344
|
-
// that no longer contains the placement currently on screen (a studio
|
|
345
|
-
// publish renamed or removed it mid-session) — OR the query KEY itself can
|
|
346
|
-
// change while a paywall is showing (`locale`/`customAudienceParams`
|
|
347
|
-
// changed as a prop), which makes react-query report `data: undefined`
|
|
348
|
-
// while the new key is fetching (Finding 1's fix reads `catalog` straight
|
|
349
|
-
// from that `data`). Both collapse `activePaywall` to null the same way, so
|
|
350
|
-
// guarding on THAT — not on `catalog` being non-null — catches both: the
|
|
351
|
-
// original guard (`!catalog` check) missed the query-key case entirely,
|
|
352
|
-
// because a null `catalog` made it bail out before ever checking whether
|
|
353
|
-
// 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.
|
|
354
415
|
//
|
|
355
416
|
// Either way, the Modal closes itself WITHOUT going through `complete()`,
|
|
356
417
|
// so the pending `present()` promise would never settle and
|
|
357
|
-
// `
|
|
418
|
+
// `activeMoment` would stay set forever, silently failing every later
|
|
358
419
|
// `present()` call with `"error"` for the rest of the app's life.
|
|
359
|
-
// `complete()` always clears `
|
|
420
|
+
// `complete()` always clears `activeMoment` together with resolving the
|
|
360
421
|
// pending promise, so it cannot race with or double-resolve this branch.
|
|
361
422
|
useEffect(() => {
|
|
362
|
-
if (!
|
|
423
|
+
if (!activeMoment || activePaywall) return;
|
|
363
424
|
complete({ status: "error", reason: "paywall-disappeared" });
|
|
364
|
-
}, [
|
|
425
|
+
}, [activeMoment, activePaywall, complete]);
|
|
365
426
|
|
|
366
427
|
// The OTHER way a presentation never completes, and the one the guard above
|
|
367
428
|
// structurally cannot catch: `activePaywall` is perfectly non-null — the
|
|
@@ -370,8 +431,8 @@ const PaywallProviderInner = ({
|
|
|
370
431
|
// already-presenting view controller: another Modal, a
|
|
371
432
|
// `presentation: "modal"` route, a StoreKit alert). Nothing calls
|
|
372
433
|
// `complete()`, so without this the pending promise never settles,
|
|
373
|
-
// `
|
|
374
|
-
// `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
|
|
375
436
|
// error and no log. Confirmed in production on a monetisation surface, which
|
|
376
437
|
// is why this recovers rather than merely reports.
|
|
377
438
|
//
|
|
@@ -379,10 +440,10 @@ const PaywallProviderInner = ({
|
|
|
379
440
|
// reading is never torn down; see `shouldBreakPresentationWedge`.
|
|
380
441
|
useEffect(() => {
|
|
381
442
|
if (presentAckTimeoutMs === null) return;
|
|
382
|
-
if (!shouldBreakPresentationWedge(
|
|
443
|
+
if (!shouldBreakPresentationWedge(activeMoment, hostAcknowledged, true)) return;
|
|
383
444
|
const timer = setTimeout(() => {
|
|
384
445
|
console.warn(
|
|
385
|
-
`[paywalls] "${
|
|
446
|
+
`[paywalls] "${activeMoment}" was never confirmed on screen within ` +
|
|
386
447
|
`${presentAckTimeoutMs}ms and has been abandoned, so later present() calls keep working. ` +
|
|
387
448
|
"The platform most likely refused to present it — on iOS, something else was already " +
|
|
388
449
|
"presenting (another Modal, a `presentation: \"modal\"` route, or a StoreKit alert).",
|
|
@@ -390,7 +451,7 @@ const PaywallProviderInner = ({
|
|
|
390
451
|
complete({ status: "error", reason: "host-never-presented" });
|
|
391
452
|
}, presentAckTimeoutMs);
|
|
392
453
|
return () => clearTimeout(timer);
|
|
393
|
-
}, [
|
|
454
|
+
}, [activeMoment, hostAcknowledged, presentAckTimeoutMs, complete]);
|
|
394
455
|
|
|
395
456
|
const isReady = useMemo(
|
|
396
457
|
() => computeIsReady(catalog, productRefs, productRuntime.status),
|
|
@@ -447,6 +508,7 @@ export const PaywallProvider = ({
|
|
|
447
508
|
locale = "en",
|
|
448
509
|
customAudienceParams = {},
|
|
449
510
|
productProvider,
|
|
511
|
+
stripeProductProvider,
|
|
450
512
|
customActions = EMPTY_CUSTOM_ACTIONS,
|
|
451
513
|
presentAckTimeoutMs = DEFAULT_PRESENT_ACK_TIMEOUT_MS,
|
|
452
514
|
}: PaywallProviderProps) => {
|
|
@@ -457,6 +519,7 @@ export const PaywallProvider = ({
|
|
|
457
519
|
locale={locale}
|
|
458
520
|
customAudienceParams={customAudienceParams}
|
|
459
521
|
productProvider={productProvider}
|
|
522
|
+
stripeProductProvider={stripeProductProvider}
|
|
460
523
|
customActions={customActions}
|
|
461
524
|
presentAckTimeoutMs={presentAckTimeoutMs}
|
|
462
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
|
});
|