@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.
Files changed (54) hide show
  1. package/dist/OnboardingStudioClient.d.ts +4 -4
  2. package/dist/OnboardingStudioClient.js +7 -7
  3. package/dist/OnboardingStudioClient.js.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/paywalls/PaywallProvider.d.ts +38 -7
  7. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  8. package/dist/paywalls/PaywallProvider.js +101 -44
  9. package/dist/paywalls/PaywallProvider.js.map +1 -1
  10. package/dist/paywalls/present.d.ts +91 -12
  11. package/dist/paywalls/present.d.ts.map +1 -1
  12. package/dist/paywalls/present.js +75 -18
  13. package/dist/paywalls/present.js.map +1 -1
  14. package/dist/paywalls/types.d.ts +48 -23
  15. package/dist/paywalls/types.d.ts.map +1 -1
  16. package/dist/paywalls/types.js +0 -7
  17. package/dist/paywalls/types.js.map +1 -1
  18. package/dist/paywalls/usePaywall.d.ts +19 -4
  19. package/dist/paywalls/usePaywall.d.ts.map +1 -1
  20. package/dist/paywalls/usePaywall.js +2 -2
  21. package/dist/paywalls/usePaywall.js.map +1 -1
  22. package/dist/products/adapters/stripeLink.d.ts +57 -0
  23. package/dist/products/adapters/stripeLink.d.ts.map +1 -0
  24. package/dist/products/adapters/stripeLink.js +158 -0
  25. package/dist/products/adapters/stripeLink.js.map +1 -0
  26. package/dist/products/index.d.ts +4 -1
  27. package/dist/products/index.d.ts.map +1 -1
  28. package/dist/products/index.js +5 -1
  29. package/dist/products/index.js.map +1 -1
  30. package/dist/products/refIdentity.d.ts +3 -0
  31. package/dist/products/refIdentity.d.ts.map +1 -0
  32. package/dist/products/refIdentity.js +37 -0
  33. package/dist/products/refIdentity.js.map +1 -0
  34. package/dist/products/types.d.ts +29 -1
  35. package/dist/products/types.d.ts.map +1 -1
  36. package/dist/products/useProducts.d.ts.map +1 -1
  37. package/dist/products/useProducts.js +7 -1
  38. package/dist/products/useProducts.js.map +1 -1
  39. package/package.json +1 -1
  40. package/src/OnboardingStudioClient.ts +7 -7
  41. package/src/index.ts +3 -0
  42. package/src/paywalls/PaywallProvider.tsx +145 -48
  43. package/src/paywalls/__tests__/getPaywalls.test.ts +15 -12
  44. package/src/paywalls/__tests__/present.test.ts +192 -26
  45. package/src/paywalls/present.ts +115 -19
  46. package/src/paywalls/types.ts +49 -23
  47. package/src/paywalls/usePaywall.ts +22 -6
  48. package/src/products/__tests__/refIdentity.test.ts +44 -0
  49. package/src/products/adapters/__tests__/stripeLink.test.ts +179 -0
  50. package/src/products/adapters/stripeLink.ts +245 -0
  51. package/src/products/index.ts +4 -0
  52. package/src/products/refIdentity.ts +33 -0
  53. package/src/products/types.ts +30 -1
  54. package/src/products/useProducts.ts +7 -4
@@ -1,11 +1,11 @@
1
1
  import type { Paywall, PaywallCatalog, PresentResult } from "./types";
2
- import type { ProductRef, ProductStatus, PurchaseResult } from "../products/types";
2
+ import type { ProductRef, ProductRuntime, ProductStatus, PurchaseResult } from "../products/types";
3
3
  /**
4
4
  * Union of every `paywall.products[]` across the WHOLE catalog, deduplicated
5
5
  * by content — the same identity notion `useProducts`' `refsKey` uses
6
- * (`products/useProducts.ts:41-45`: keyed on ref CONTENT, not array
7
- * identity), so this array is exactly as cheap to pass as a hand-written one:
8
- * `useProducts` resolves it once and does not refetch on every render.
6
+ * (`products/refIdentity.ts`: keyed on ref CONTENT, not array identity), so
7
+ * this array is exactly as cheap to pass as a hand-written one: `useProducts`
8
+ * resolves it once and does not refetch on every render.
9
9
  *
10
10
  * Resolving the whole catalog's union ONCE at load — rather than re-keying
11
11
  * `useProducts` per presented paywall — is the deliberate design decision:
@@ -23,13 +23,13 @@ export type PresentDecision = {
23
23
  result: PresentResult;
24
24
  };
25
25
  /**
26
- * `present(placement)`'s edge-case decision, extracted so both documented
26
+ * `present(moment)`'s edge-case decision, extracted so both documented
27
27
  * edge cases are covered by an importable test rather than only inspection:
28
28
  *
29
- * - **Unknown placement** (absent from the catalog, or the catalog hasn't
30
- * resolved yet — both look identical here: `catalog?.paywalls[placement]`
29
+ * - **Unknown moment** (absent from the catalog, or the catalog hasn't
30
+ * resolved yet — both look identical here: `catalog?.paywalls[moment]`
31
31
  * is `undefined` either way) → resolves `"error"`, never throws. A missing
32
- * placement must not crash a host app mid-flow.
32
+ * moment must not crash a host app mid-flow.
33
33
  * - **`present()` called while another paywall is already showing** → also
34
34
  * resolves `"error"` immediately, leaving the in-progress presentation
35
35
  * untouched. This SDK shows one paywall at a time. Silently replacing the
@@ -37,9 +37,9 @@ export type PresentDecision = {
37
37
  * resolved — that caller hangs forever); queueing the new request would
38
38
  * need its own cancellation/timeout story that nothing here asks for.
39
39
  * Resolving the new call immediately applies the same "resolve, don't
40
- * throw" contract as the unknown-placement case, consistently.
40
+ * throw" contract as the unknown-moment case, consistently.
41
41
  */
42
- export declare const resolvePresentDecision: (catalog: PaywallCatalog | null, activePlacement: string | null, placement: string) => PresentDecision;
42
+ export declare const resolvePresentDecision: (catalog: PaywallCatalog | null, activeMoment: string | null, moment: string) => PresentDecision;
43
43
  /**
44
44
  * Whether an in-progress presentation should be abandoned because the host
45
45
  * never confirmed it appeared.
@@ -64,6 +64,39 @@ export declare const resolvePresentDecision: (catalog: PaywallCatalog | null, ac
64
64
  * unacknowledged presentation is ever torn down.
65
65
  */
66
66
  export declare const shouldBreakPresentationWedge: (activePlacement: string | null, hostAcknowledged: boolean, timedOut: boolean) => boolean;
67
+ /**
68
+ * What the catalog is doing right now — the states `isReady` collapses.
69
+ *
70
+ * `isReady` is a single boolean over at least three distinct situations (no
71
+ * catalog yet, a catalog whose products are still resolving, and a failed query
72
+ * — which also presents as `catalog === null`). A host deciding "wait for the
73
+ * catalog" versus "fall back to another paywall engine" cannot tell those apart
74
+ * from one boolean, and every host that needs the distinction ends up building
75
+ * its own multi-input gate.
76
+ *
77
+ * `"revalidating"` is the state that motivated this, and it is not cosmetic.
78
+ * In production the catalog is served CACHE-FIRST from AsyncStorage under a key
79
+ * that is NOT scoped by `customAudienceParams` (`getPaywalls.query.ts` — the
80
+ * react-query key is param-scoped, the disk key is a bare constant). So a host
81
+ * sending volatile params gets an instantly-available catalog that was resolved
82
+ * under DIFFERENT params, with a fresh fetch in flight behind it. That catalog
83
+ * is present and non-null, so it reads as ready — and a host gating on
84
+ * `catalog.paywalls[moment]` can conclude the moment does not exist and
85
+ * route away, milliseconds before the correct catalog arrives.
86
+ *
87
+ * Observed consequence, reported from a production pilot: for an audience gated
88
+ * on a threshold (`hoursSinceOnboardingPaywall >= 44`), the launch where a user
89
+ * first becomes eligible is served the PRE-threshold catalog, so the arm under
90
+ * test loses exactly the launch that matters. `"revalidating"` is how a host
91
+ * distinguishes "this catalog is final" from "this catalog may be superseded in
92
+ * a moment", and therefore whether a missing moment means absent or not-yet.
93
+ *
94
+ * A present catalog outranks an error deliberately: if a background
95
+ * revalidation fails, react-query keeps the cached `data` AND sets `error`, and
96
+ * a usable catalog should not be reported as a failure.
97
+ */
98
+ export type CatalogStatus = "loading" | "ready" | "revalidating" | "error";
99
+ export declare const computeCatalogStatus: (catalog: PaywallCatalog | null, error: unknown, isFetching: boolean) => CatalogStatus;
67
100
  /**
68
101
  * `isReady` = catalog resolved AND products resolved — the one flag a caller
69
102
  * needs to know "presenting now will not show a spinner".
@@ -83,7 +116,7 @@ export declare const computeIsReady: (catalog: PaywallCatalog | null, productRef
83
116
  * `"error"` are not: they don't describe what happened to the STORE PURCHASE
84
117
  * in a way that should override how the paywall itself reports closing (an
85
118
  * `"error"` here would collide with `PresentResult`'s existing `"error"`,
86
- * which means something structurally different — an unknown placement or a
119
+ * which means something structurally different — an unknown moment or a
87
120
  * mistimed `present()` call, not a failed purchase attempt).
88
121
  */
89
122
  export type PurchaseOutcomeDuringPresentation = "purchased" | "cancelled" | null;
@@ -116,9 +149,55 @@ export declare const resolvePresentedOutcome: (reported: PresentResult, purchase
116
149
  * generation again after — only an unchanged generation means the write is
117
150
  * still for the presentation that started it.
118
151
  *
119
- * A monotonic counter, not the placement string: the same placement can
152
+ * A monotonic counter, not the moment string: the same moment can
120
153
  * legitimately be presented twice in a row, and a string comparison would
121
154
  * let a stale write from the FIRST of those two land in the second.
122
155
  */
123
156
  export declare const shouldRecordPurchaseOutcome: (startedInGeneration: number, currentGeneration: number) => boolean;
157
+ /**
158
+ * Which of the two resolved product runtimes to publish.
159
+ *
160
+ * `PaywallProvider` resolves the catalog's product union TWICE — once through
161
+ * the host's store adapter, once through its Stripe adapter — because the
162
+ * runtime is published as one map keyed by product key, and a `store` paywall
163
+ * and a `stripe` paywall declaring the same key would otherwise fight over
164
+ * `product.<key>.price`. Only one paywall is ever presented at a time
165
+ * (`activeMoment`), so "the active one" is unambiguous.
166
+ *
167
+ * This is cheap rather than wasteful because the Stripe pass performs no
168
+ * network call (`stripeLinkProductProvider`) and each provider silently drops
169
+ * refs it cannot resolve, so neither pass does work for the other's paywalls.
170
+ *
171
+ * The statuses are deliberately NOT merged. Merging is the trap
172
+ * `mergeProductRuntimes` documents from the other direction: an `"idle"`
173
+ * runtime with nothing to wait for drags a `"ready"` one down and closes every
174
+ * `products.loaded` gate for the life of the process.
175
+ *
176
+ * `hasStripeProvider` is the guard for a misconfigured host: a `stripe`
177
+ * paywall with no `stripeProductProvider` passed leaves `useProducts` at
178
+ * `"idle"` forever (it bails before calling a provider it does not have), so
179
+ * `computeIsReady` would never turn true and paywalls would stop appearing
180
+ * with no error. Falling back to the store runtime keeps the app alive; the
181
+ * caller warns.
182
+ *
183
+ * `billing` is `undefined` whenever no paywall is active (`activePaywall` is
184
+ * null before the first `present()`, and after every `complete()`) — there is
185
+ * no `.billing` to read yet. That USED to fall through to the store runtime
186
+ * unconditionally, which meant a host that passes ONLY
187
+ * `stripeProductProvider` (no `productProvider` at all) sat on an `"idle"`
188
+ * `storeRuntime` — forever, for every screen before a paywall first presents,
189
+ * since nothing ever calls a `present()` to select the stripe runtime instead
190
+ * — so `products.loaded` read `"false"` everywhere and `isReady` never turned
191
+ * true. `hasStoreProvider` closes that gap: with no active paywall, prefer
192
+ * whichever provider was actually SUPPLIED. When both or neither exist there
193
+ * is no asymmetry to correct, so this keeps the pre-existing store-first
194
+ * default — unchanged for every host that already worked.
195
+ */
196
+ export declare const selectActiveProductRuntime: (args: {
197
+ storeRuntime: ProductRuntime;
198
+ stripeRuntime: ProductRuntime;
199
+ billing: "store" | "stripe" | undefined;
200
+ hasStripeProvider: boolean;
201
+ hasStoreProvider: boolean;
202
+ }) => ProductRuntime;
124
203
  //# sourceMappingURL=present.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"present.d.ts","sourceRoot":"","sources":["../../src/paywalls/present.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,cAAc,GAAG,IAAI,KAAG,UAAU,EAa7E,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,cAAc,GAAG,IAAI,EAC9B,iBAAiB,MAAM,GAAG,IAAI,EAC9B,WAAW,MAAM,KAChB,eAaF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,4BAA4B,GACvC,iBAAiB,MAAM,GAAG,IAAI,EAC9B,kBAAkB,OAAO,EACzB,UAAU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EAAE,OAAO,CAAC;CAC3B,KAAG,cAKH,CAAC"}
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldRecordPurchaseOutcome = exports.resolvePresentedOutcome = exports.purchaseOutcomeFromResult = exports.computeIsReady = exports.shouldBreakPresentationWedge = exports.resolvePresentDecision = exports.collectProductRefs = void 0;
3
+ exports.selectActiveProductRuntime = exports.shouldRecordPurchaseOutcome = exports.resolvePresentedOutcome = exports.purchaseOutcomeFromResult = exports.computeIsReady = exports.computeCatalogStatus = exports.shouldBreakPresentationWedge = exports.resolvePresentDecision = exports.collectProductRefs = void 0;
4
+ const refIdentity_1 = require("../products/refIdentity");
4
5
  /**
5
6
  * Union of every `paywall.products[]` across the WHOLE catalog, deduplicated
6
7
  * by content — the same identity notion `useProducts`' `refsKey` uses
7
- * (`products/useProducts.ts:41-45`: keyed on ref CONTENT, not array
8
- * identity), so this array is exactly as cheap to pass as a hand-written one:
9
- * `useProducts` resolves it once and does not refetch on every render.
8
+ * (`products/refIdentity.ts`: keyed on ref CONTENT, not array identity), so
9
+ * this array is exactly as cheap to pass as a hand-written one: `useProducts`
10
+ * resolves it once and does not refetch on every render.
10
11
  *
11
12
  * Resolving the whole catalog's union ONCE at load — rather than re-keying
12
13
  * `useProducts` per presented paywall — is the deliberate design decision:
@@ -15,14 +16,13 @@ exports.shouldRecordPurchaseOutcome = exports.resolvePresentedOutcome = exports.
15
16
  * accepted: an app resolves products for paywalls it may never show.
16
17
  */
17
18
  const collectProductRefs = (catalog) => {
18
- var _a, _b, _c;
19
19
  if (!catalog)
20
20
  return [];
21
21
  const seen = new Set();
22
22
  const refs = [];
23
23
  for (const paywall of Object.values(catalog.paywalls)) {
24
24
  for (const ref of paywall.products) {
25
- const identity = `${ref.key}|${(_a = ref.ios) !== null && _a !== void 0 ? _a : ""}|${(_b = ref.android) !== null && _b !== void 0 ? _b : ""}|${(_c = ref.compareTo) !== null && _c !== void 0 ? _c : ""}`;
25
+ const identity = (0, refIdentity_1.productRefIdentity)(ref);
26
26
  if (seen.has(identity))
27
27
  continue;
28
28
  seen.add(identity);
@@ -33,13 +33,13 @@ const collectProductRefs = (catalog) => {
33
33
  };
34
34
  exports.collectProductRefs = collectProductRefs;
35
35
  /**
36
- * `present(placement)`'s edge-case decision, extracted so both documented
36
+ * `present(moment)`'s edge-case decision, extracted so both documented
37
37
  * edge cases are covered by an importable test rather than only inspection:
38
38
  *
39
- * - **Unknown placement** (absent from the catalog, or the catalog hasn't
40
- * resolved yet — both look identical here: `catalog?.paywalls[placement]`
39
+ * - **Unknown moment** (absent from the catalog, or the catalog hasn't
40
+ * resolved yet — both look identical here: `catalog?.paywalls[moment]`
41
41
  * is `undefined` either way) → resolves `"error"`, never throws. A missing
42
- * placement must not crash a host app mid-flow.
42
+ * moment must not crash a host app mid-flow.
43
43
  * - **`present()` called while another paywall is already showing** → also
44
44
  * resolves `"error"` immediately, leaving the in-progress presentation
45
45
  * untouched. This SDK shows one paywall at a time. Silently replacing the
@@ -47,19 +47,19 @@ exports.collectProductRefs = collectProductRefs;
47
47
  * resolved — that caller hangs forever); queueing the new request would
48
48
  * need its own cancellation/timeout story that nothing here asks for.
49
49
  * Resolving the new call immediately applies the same "resolve, don't
50
- * throw" contract as the unknown-placement case, consistently.
50
+ * throw" contract as the unknown-moment case, consistently.
51
51
  */
52
- const resolvePresentDecision = (catalog, activePlacement, placement) => {
53
- if (activePlacement !== null) {
54
- // `activePlacement` is echoed back deliberately — see PresentErrorReason.
52
+ const resolvePresentDecision = (catalog, activeMoment, moment) => {
53
+ if (activeMoment !== null) {
54
+ // `activeMoment` is echoed back deliberately — see PresentErrorReason.
55
55
  return {
56
56
  type: "immediate",
57
- result: { status: "error", reason: "already-presenting", activePlacement },
57
+ result: { status: "error", reason: "already-presenting", activeMoment },
58
58
  };
59
59
  }
60
- const paywall = catalog === null || catalog === void 0 ? void 0 : catalog.paywalls[placement];
60
+ const paywall = catalog === null || catalog === void 0 ? void 0 : catalog.paywalls[moment];
61
61
  if (!paywall) {
62
- return { type: "immediate", result: { status: "error", reason: "unknown-placement" } };
62
+ return { type: "immediate", result: { status: "error", reason: "unknown-moment" } };
63
63
  }
64
64
  return { type: "start", paywall };
65
65
  };
@@ -89,6 +89,14 @@ exports.resolvePresentDecision = resolvePresentDecision;
89
89
  */
90
90
  const shouldBreakPresentationWedge = (activePlacement, hostAcknowledged, timedOut) => activePlacement !== null && !hostAcknowledged && timedOut;
91
91
  exports.shouldBreakPresentationWedge = shouldBreakPresentationWedge;
92
+ const computeCatalogStatus = (catalog, error, isFetching) => {
93
+ if (catalog !== null)
94
+ return isFetching ? "revalidating" : "ready";
95
+ if (error)
96
+ return "error";
97
+ return "loading";
98
+ };
99
+ exports.computeCatalogStatus = computeCatalogStatus;
92
100
  /**
93
101
  * `isReady` = catalog resolved AND products resolved — the one flag a caller
94
102
  * needs to know "presenting now will not show a spinner".
@@ -133,10 +141,59 @@ exports.resolvePresentedOutcome = resolvePresentedOutcome;
133
141
  * generation again after — only an unchanged generation means the write is
134
142
  * still for the presentation that started it.
135
143
  *
136
- * A monotonic counter, not the placement string: the same placement can
144
+ * A monotonic counter, not the moment string: the same moment can
137
145
  * legitimately be presented twice in a row, and a string comparison would
138
146
  * let a stale write from the FIRST of those two land in the second.
139
147
  */
140
148
  const shouldRecordPurchaseOutcome = (startedInGeneration, currentGeneration) => startedInGeneration === currentGeneration;
141
149
  exports.shouldRecordPurchaseOutcome = shouldRecordPurchaseOutcome;
150
+ /**
151
+ * Which of the two resolved product runtimes to publish.
152
+ *
153
+ * `PaywallProvider` resolves the catalog's product union TWICE — once through
154
+ * the host's store adapter, once through its Stripe adapter — because the
155
+ * runtime is published as one map keyed by product key, and a `store` paywall
156
+ * and a `stripe` paywall declaring the same key would otherwise fight over
157
+ * `product.<key>.price`. Only one paywall is ever presented at a time
158
+ * (`activeMoment`), so "the active one" is unambiguous.
159
+ *
160
+ * This is cheap rather than wasteful because the Stripe pass performs no
161
+ * network call (`stripeLinkProductProvider`) and each provider silently drops
162
+ * refs it cannot resolve, so neither pass does work for the other's paywalls.
163
+ *
164
+ * The statuses are deliberately NOT merged. Merging is the trap
165
+ * `mergeProductRuntimes` documents from the other direction: an `"idle"`
166
+ * runtime with nothing to wait for drags a `"ready"` one down and closes every
167
+ * `products.loaded` gate for the life of the process.
168
+ *
169
+ * `hasStripeProvider` is the guard for a misconfigured host: a `stripe`
170
+ * paywall with no `stripeProductProvider` passed leaves `useProducts` at
171
+ * `"idle"` forever (it bails before calling a provider it does not have), so
172
+ * `computeIsReady` would never turn true and paywalls would stop appearing
173
+ * with no error. Falling back to the store runtime keeps the app alive; the
174
+ * caller warns.
175
+ *
176
+ * `billing` is `undefined` whenever no paywall is active (`activePaywall` is
177
+ * null before the first `present()`, and after every `complete()`) — there is
178
+ * no `.billing` to read yet. That USED to fall through to the store runtime
179
+ * unconditionally, which meant a host that passes ONLY
180
+ * `stripeProductProvider` (no `productProvider` at all) sat on an `"idle"`
181
+ * `storeRuntime` — forever, for every screen before a paywall first presents,
182
+ * since nothing ever calls a `present()` to select the stripe runtime instead
183
+ * — so `products.loaded` read `"false"` everywhere and `isReady` never turned
184
+ * true. `hasStoreProvider` closes that gap: with no active paywall, prefer
185
+ * whichever provider was actually SUPPLIED. When both or neither exist there
186
+ * is no asymmetry to correct, so this keeps the pre-existing store-first
187
+ * default — unchanged for every host that already worked.
188
+ */
189
+ const selectActiveProductRuntime = (args) => {
190
+ if (args.billing === "stripe" && args.hasStripeProvider)
191
+ return args.stripeRuntime;
192
+ if (args.billing !== undefined)
193
+ return args.storeRuntime;
194
+ if (args.hasStripeProvider && !args.hasStoreProvider)
195
+ return args.stripeRuntime;
196
+ return args.storeRuntime;
197
+ };
198
+ exports.selectActiveProductRuntime = selectActiveProductRuntime;
142
199
  //# sourceMappingURL=present.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"present.js","sourceRoot":"","sources":["../../src/paywalls/present.ts"],"names":[],"mappings":";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,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAD3E,QAAA,yBAAyB,6BACkD;AAExF;;;;;;;;;;;;;GAaG;AACI,MAAM,uBAAuB,GAAG,CACrC,QAAuB,EACvB,eAAkD,EACnC,EAAE,CACjB,QAAQ,CAAC,MAAM,KAAK,WAAW,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AAJjF,QAAA,uBAAuB,2BAI0D;AAE9F;;;;;;;;;;;;;;;GAeG;AACI,MAAM,2BAA2B,GAAG,CACzC,mBAA2B,EAC3B,iBAAyB,EAChB,EAAE,CAAC,mBAAmB,KAAK,iBAAiB,CAAC;AAH3C,QAAA,2BAA2B,+BAGgB;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACI,MAAM,0BAA0B,GAAG,CAAC,IAM1C,EAAkB,EAAE;IACnB,IAAI,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,iBAAiB;QAAE,OAAO,IAAI,CAAC,aAAa,CAAC;IACnF,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,YAAY,CAAC;IACzD,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,gBAAgB;QAAE,OAAO,IAAI,CAAC,aAAa,CAAC;IAChF,OAAO,IAAI,CAAC,YAAY,CAAC;AAC3B,CAAC,CAAC;AAXW,QAAA,0BAA0B,8BAWrC"}
@@ -1,69 +1,94 @@
1
+ import type { StripeProductRef } from "../products/types";
1
2
  /**
2
3
  * Response types for `OnboardingStudioClient.getPaywalls()` (spec §6.1). The
3
- * endpoint returns every placement for the project/audience/locale in one
4
+ * endpoint returns every moment for the project/audience/locale in one
4
5
  * payload — a paywall must render the instant the user taps upgrade, and a
5
6
  * network round-trip at that moment is a conversion bug, so there is no
6
- * per-placement fetch in the common path (see `PaywallOptions.placement`).
7
+ * per-moment fetch in the common path (see `PaywallOptions.moment`).
8
+ */
9
+ /**
10
+ * A single studio-authored paywall, keyed by `moment` in `PaywallCatalog.paywalls`.
11
+ *
12
+ * `audienceId`/`audienceName` are resolved PER MOMENT, not once for the whole
13
+ * catalog: each moment (an onboarding-end upsell, a settings-screen upgrade,
14
+ * …) runs its own independent audience waterfall, so two entries in the same
15
+ * catalog can legitimately have matched different audiences. That is why
16
+ * these fields live here and not on `PaywallCatalog.metadata`.
7
17
  */
8
- /** A single studio-authored paywall, keyed by `placement` in `PaywallCatalog.paywalls`. */
9
18
  export type Paywall = {
10
19
  id: string;
11
20
  name: string;
12
- placement: string;
21
+ moment: string;
22
+ audienceId: number | null;
23
+ audienceName: string | null;
13
24
  /** UIElement[] — parsed by the UI adapter (Task 7's `ScreenElementsSchema`), not here. */
14
25
  elements: unknown[];
26
+ /**
27
+ * Which billing path this paywall's buy actions take. `"store"` uses the
28
+ * host's store adapter (`PaywallProvider`'s `productProvider`); `"stripe"`
29
+ * uses `PaywallProvider`'s `stripeProductProvider` and opens a Payment Link.
30
+ *
31
+ * A property of the PAYWALL, not the moment or the project, so one moment
32
+ * audience can weight a `store` variant against a `stripe` variant and ramp
33
+ * the billing change as an A/B test.
34
+ */
35
+ billing: "store" | "stripe";
15
36
  products: Array<{
16
37
  key: string;
17
38
  ios?: string;
18
39
  android?: string;
19
40
  compareTo?: string;
41
+ stripe?: StripeProductRef;
20
42
  }>;
21
43
  configuration: Record<string, unknown> | null;
22
44
  };
23
45
  /** Full response body of `GET get-paywalls`. */
24
46
  export type PaywallCatalog = {
25
47
  metadata: {
26
- audienceId: number | null;
27
- audienceName: string | null;
28
48
  locale: string | null;
29
49
  draft: boolean;
30
50
  };
31
- /** Keyed by placement, not by paywall id. */
51
+ /** Keyed by moment, not by paywall id. */
32
52
  paywalls: Record<string, Paywall>;
33
53
  fonts: Record<string, unknown> | null;
34
54
  };
35
55
  /**
36
56
  * Options for `OnboardingStudioClient.getPaywalls()`.
37
57
  *
38
- * `placement` narrows the response to a single paywall — the exception, not
39
- * the default. Omit it to get every placement in one round-trip, which is
58
+ * `moment` narrows the response to a single paywall — the exception, not
59
+ * the default. Omit it to get every moment in one round-trip, which is
40
60
  * what lets a paywall render instantly at buy-tap time (see the module doc
41
61
  * above).
42
62
  */
43
63
  export type PaywallOptions = {
44
64
  locale?: string;
45
- placement?: string;
65
+ moment?: string;
46
66
  };
47
67
  /**
48
68
  * Response headers for `get-paywalls`. Deliberately **not** the onboarding
49
69
  * trio (`ONBS-Onboarding-Id` / `ONBS-Audience-Id` / `ONBS-Onboarding-Name`) —
50
70
  * the paywall endpoint has no single onboarding/audience-name concept and
51
71
  * instead reports which paywall ids came back.
72
+ *
73
+ * `ONBS-Audience-Ids` is plural (comma-separated) and parallel in order to
74
+ * `ONBS-Paywall-Ids`: each moment resolves its own audience waterfall (see
75
+ * `Paywall.audienceId`), so there is no single catalog-level audience left
76
+ * to report under a singular header.
52
77
  */
53
78
  export interface GetPaywallsResponseHeaders {
54
- "ONBS-Audience-Id": string | null;
79
+ "ONBS-Audience-Ids": string | null;
55
80
  "ONBS-Paywall-Ids": string | null;
56
81
  }
57
82
  /**
58
- * Resolved outcome of a `usePaywall().present(placement)` call (spec §7).
83
+ * Resolved outcome of a `usePaywall().present(moment)` call (spec §7).
59
84
  * Closed union, not the open-ended `ScreenHost.CompleteOutcome` — a
60
85
  * presentation ends in exactly one of these four ways, and `present()`'s
61
86
  * caller (typically an `await`) should be able to switch over it exhaustively.
62
87
  *
63
- * `"error"` covers both: (a) `placement` is absent from the catalog (or the
88
+ * `"error"` covers both: (a) `moment` is absent from the catalog (or the
64
89
  * catalog hasn't resolved yet), and (b) `present()` was called while another
65
90
  * paywall is already being presented. Both resolve rather than throw — a
66
- * missing placement or a mistimed call must not crash a host app mid-flow.
91
+ * missing moment or a mistimed call must not crash a host app mid-flow.
67
92
  * See `resolvePresentDecision` in `present.ts` for the exact decision logic.
68
93
  *
69
94
  * `"purchased"` / `"cancelled"` are NOT produced by any ButtonAction directly
@@ -94,18 +119,18 @@ export interface GetPaywallsResponseHeaders {
94
119
  * absent on every other status.
95
120
  *
96
121
  * This exists because `"error"` alone conflates conditions whose correct
97
- * recovery is OPPOSITE. `"unknown-placement"` means the catalog may simply not
122
+ * recovery is OPPOSITE. `"unknown-moment"` means the catalog may simply not
98
123
  * have arrived yet, so retrying later is right. `"already-presenting"` means a
99
124
  * presentation is in progress, so retrying is wrong and something may be
100
125
  * stuck. A caller given only the status can act correctly on neither, and two
101
126
  * separate multi-hour production investigations were spent reconstructing by
102
127
  * elimination what the SDK already knew here.
103
128
  *
104
- * - `unknown-placement` — absent from the catalog, or the catalog has not
129
+ * - `unknown-moment` — absent from the catalog, or the catalog has not
105
130
  * resolved yet. The two are indistinguishable at this layer, and both are
106
131
  * worth retrying once `usePaywall().isReady` is true.
107
- * - `already-presenting` — one paywall shows at a time. `activePlacement` on
108
- * the result names the one that IS showing: the same placement means the
132
+ * - `already-presenting` — one paywall shows at a time. `activeMoment` on
133
+ * the result names the one that IS showing: the same moment means the
109
134
  * caller double-called and wants its own in-flight guard, a different one
110
135
  * means something else holds the surface.
111
136
  * - `parse-error` — `elements` failed the UI schema, so the Modal was never
@@ -120,19 +145,19 @@ export interface GetPaywallsResponseHeaders {
120
145
  * keep the surface usable. In practice the platform refused to present
121
146
  * (iOS will not present over an already-presenting view controller — another
122
147
  * Modal, a `presentation: "modal"` route, a StoreKit alert).
123
- * - `paywall-disappeared` — the placement vanished from the catalog while it
148
+ * - `paywall-disappeared` — the moment vanished from the catalog while it
124
149
  * was on screen (a studio publish, or a query-key change mid-presentation).
125
150
  */
126
- export type PresentErrorReason = "unknown-placement" | "already-presenting" | "parse-error" | "render-error" | "host-never-presented" | "paywall-disappeared";
151
+ export type PresentErrorReason = "unknown-moment" | "already-presenting" | "parse-error" | "render-error" | "host-never-presented" | "paywall-disappeared";
127
152
  export type PresentResult = {
128
153
  status: "purchased" | "dismissed" | "cancelled" | "error";
129
154
  /** Why it failed. Set on `"error"` only — see `PresentErrorReason`. */
130
155
  reason?: PresentErrorReason;
131
156
  /**
132
- * The placement currently being presented. Set only alongside
133
- * `reason: "already-presenting"`, where knowing WHICH placement holds the
157
+ * The moment currently being presented. Set only alongside
158
+ * `reason: "already-presenting"`, where knowing WHICH moment holds the
134
159
  * surface is what distinguishes a caller double-call from an unrelated stall.
135
160
  */
136
- activePlacement?: string;
161
+ activeMoment?: string;
137
162
  };
138
163
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/paywalls/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,2FAA2F;AAC3F,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,0FAA0F;IAC1F,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;IACH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC/C,CAAC;AAEF,gDAAgD;AAChD,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE;QACR,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC;IACF,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,EAAE,MAAM,C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,OAAO,CAAC;IAC1D,uEAAuE;IACvE,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC"}
@@ -1,10 +1,3 @@
1
1
  "use strict";
2
- /**
3
- * Response types for `OnboardingStudioClient.getPaywalls()` (spec §6.1). The
4
- * endpoint returns every placement for the project/audience/locale in one
5
- * payload — a paywall must render the instant the user taps upgrade, and a
6
- * network round-trip at that moment is a conversion bug, so there is no
7
- * per-placement fetch in the common path (see `PaywallOptions.placement`).
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/paywalls/types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/paywalls/types.ts"],"names":[],"mappings":""}
@@ -1,23 +1,38 @@
1
1
  import { PaywallCatalog, PresentResult } from "./types";
2
+ import type { CatalogStatus } from "./present";
3
+ import type { ProductStatus } from "../products/types";
2
4
  export type UsePaywallResult = {
3
5
  /**
4
- * Present a paywall by placement. Never fetches — the catalog and its
6
+ * Present a paywall by moment. Never fetches — the catalog and its
5
7
  * products are already resolved (or resolving) from `PaywallProvider`
6
8
  * mount, which is the whole point: a paywall must render the instant the
7
9
  * user taps upgrade.
8
10
  *
9
- * Resolves `{ status: "error" }` — never throws — when `placement` is
11
+ * Resolves `{ status: "error" }` — never throws — when `moment` is
10
12
  * absent from the catalog, or when another paywall is already being
11
13
  * presented. See `resolvePresentDecision` in `present.ts`.
12
14
  */
13
- present: (placement: string) => Promise<PresentResult>;
15
+ present: (moment: string) => Promise<PresentResult>;
14
16
  /**
15
17
  * `true` once BOTH the catalog and its products have resolved — the one
16
18
  * flag meaning "calling `present()` now will not show a spinner".
17
19
  */
18
20
  isReady: boolean;
19
- /** The full resolved catalog (every placement), or `null` before it loads. */
21
+ /** The full resolved catalog (every moment), or `null` before it loads. */
20
22
  catalog: PaywallCatalog | null;
23
+ /**
24
+ * What the catalog is doing, for hosts that need more than `isReady`'s one
25
+ * bit. `"revalidating"` is the important one: the catalog on hand was served
26
+ * from disk and a fresh fetch is in flight, so a moment missing from it may
27
+ * simply not have arrived yet. Gate "fall back to another engine" on
28
+ * `"ready"`, not merely on a non-null catalog.
29
+ */
30
+ catalogStatus: CatalogStatus;
31
+ /**
32
+ * What the store products are doing — the other half of `isReady`. Lets a
33
+ * host tell "still waiting on the store" from "still waiting on us".
34
+ */
35
+ productsStatus: ProductStatus;
21
36
  };
22
37
  /**
23
38
  * Read the paywall runtime published by an ancestor `PaywallProvider`.
@@ -1 +1 @@
1
- {"version":3,"file":"usePaywall.d.ts","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExD,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;;;;;;OASG;IACH,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACvD;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,8EAA8E;IAC9E,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAO,gBAG7B,CAAC"}
1
+ {"version":3,"file":"usePaywall.d.ts","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;;;;;;OASG;IACH,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACpD;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,2EAA2E;IAC3E,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/B;;;;;;OAMG;IACH,aAAa,EAAE,aAAa,CAAC;IAC7B;;;OAGG;IACH,cAAc,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAO,gBAI7B,CAAC"}
@@ -10,8 +10,8 @@ const PaywallProvider_1 = require("./PaywallProvider");
10
10
  * `useProductRuntime()` degrades to `null` with no ancestor.
11
11
  */
12
12
  const usePaywall = () => {
13
- const { present, isReady, catalog } = (0, react_1.useContext)(PaywallProvider_1.PaywallContext);
14
- return { present, isReady, catalog };
13
+ const { present, isReady, catalog, catalogStatus, productsStatus } = (0, react_1.useContext)(PaywallProvider_1.PaywallContext);
14
+ return { present, isReady, catalog, catalogStatus, productsStatus };
15
15
  };
16
16
  exports.usePaywall = usePaywall;
17
17
  //# sourceMappingURL=usePaywall.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePaywall.js","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,uDAAmD;AAwBnD;;;;;GAKG;AACI,MAAM,UAAU,GAAG,GAAqB,EAAE;IAC/C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAA,kBAAU,EAAC,gCAAc,CAAC,CAAC;IACjE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACvC,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB"}
1
+ {"version":3,"file":"usePaywall.js","sourceRoot":"","sources":["../../src/paywalls/usePaywall.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,uDAAmD;AAuCnD;;;;;GAKG;AACI,MAAM,UAAU,GAAG,GAAqB,EAAE;IAC/C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAChE,IAAA,kBAAU,EAAC,gCAAc,CAAC,CAAC;IAC7B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AACtE,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB"}