@rocapine/react-native-onboarding 1.69.0 → 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 (49) 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/paywalls/PaywallProvider.d.ts +24 -7
  5. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  6. package/dist/paywalls/PaywallProvider.js +80 -42
  7. package/dist/paywalls/PaywallProvider.js.map +1 -1
  8. package/dist/paywalls/present.d.ts +60 -14
  9. package/dist/paywalls/present.d.ts.map +1 -1
  10. package/dist/paywalls/present.js +67 -18
  11. package/dist/paywalls/present.js.map +1 -1
  12. package/dist/paywalls/types.d.ts +48 -23
  13. package/dist/paywalls/types.d.ts.map +1 -1
  14. package/dist/paywalls/types.js +0 -7
  15. package/dist/paywalls/types.js.map +1 -1
  16. package/dist/paywalls/usePaywall.d.ts +5 -5
  17. package/dist/paywalls/usePaywall.d.ts.map +1 -1
  18. package/dist/products/adapters/stripeLink.d.ts +57 -0
  19. package/dist/products/adapters/stripeLink.d.ts.map +1 -0
  20. package/dist/products/adapters/stripeLink.js +158 -0
  21. package/dist/products/adapters/stripeLink.js.map +1 -0
  22. package/dist/products/index.d.ts +4 -1
  23. package/dist/products/index.d.ts.map +1 -1
  24. package/dist/products/index.js +5 -1
  25. package/dist/products/index.js.map +1 -1
  26. package/dist/products/refIdentity.d.ts +3 -0
  27. package/dist/products/refIdentity.d.ts.map +1 -0
  28. package/dist/products/refIdentity.js +37 -0
  29. package/dist/products/refIdentity.js.map +1 -0
  30. package/dist/products/types.d.ts +29 -1
  31. package/dist/products/types.d.ts.map +1 -1
  32. package/dist/products/useProducts.d.ts.map +1 -1
  33. package/dist/products/useProducts.js +7 -1
  34. package/dist/products/useProducts.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/OnboardingStudioClient.ts +7 -7
  37. package/src/paywalls/PaywallProvider.tsx +109 -46
  38. package/src/paywalls/__tests__/getPaywalls.test.ts +15 -12
  39. package/src/paywalls/__tests__/present.test.ts +149 -28
  40. package/src/paywalls/present.ts +74 -21
  41. package/src/paywalls/types.ts +49 -23
  42. package/src/paywalls/usePaywall.ts +5 -5
  43. package/src/products/__tests__/refIdentity.test.ts +44 -0
  44. package/src/products/adapters/__tests__/stripeLink.test.ts +179 -0
  45. package/src/products/adapters/stripeLink.ts +245 -0
  46. package/src/products/index.ts +4 -0
  47. package/src/products/refIdentity.ts +33 -0
  48. package/src/products/types.ts +30 -1
  49. package/src/products/useProducts.ts +7 -4
@@ -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.computeCatalogStatus = 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
  };
@@ -141,10 +141,59 @@ exports.resolvePresentedOutcome = resolvePresentedOutcome;
141
141
  * generation again after — only an unchanged generation means the write is
142
142
  * still for the presentation that started it.
143
143
  *
144
- * A monotonic counter, not the placement string: the same placement can
144
+ * A monotonic counter, not the moment string: the same moment can
145
145
  * legitimately be presented twice in a row, and a string comparison would
146
146
  * let a stale write from the FIRST of those two land in the second.
147
147
  */
148
148
  const shouldRecordPurchaseOutcome = (startedInGeneration, currentGeneration) => startedInGeneration === currentGeneration;
149
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;
150
199
  //# sourceMappingURL=present.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"present.js","sourceRoot":"","sources":["../../src/paywalls/present.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;GAYG;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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;QAC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;;;;;;;;;;;;GAYG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,MAAM,kBAAkB,GAC1B,gBAAgB,GAChB,oBAAoB,GACpB,aAAa,GACb,cAAc,GACd,sBAAsB,GACtB,qBAAqB,CAAC;AAE1B,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,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":""}
@@ -3,27 +3,27 @@ import type { CatalogStatus } from "./present";
3
3
  import type { ProductStatus } from "../products/types";
4
4
  export type UsePaywallResult = {
5
5
  /**
6
- * Present a paywall by placement. Never fetches — the catalog and its
6
+ * Present a paywall by moment. Never fetches — the catalog and its
7
7
  * products are already resolved (or resolving) from `PaywallProvider`
8
8
  * mount, which is the whole point: a paywall must render the instant the
9
9
  * user taps upgrade.
10
10
  *
11
- * Resolves `{ status: "error" }` — never throws — when `placement` is
11
+ * Resolves `{ status: "error" }` — never throws — when `moment` is
12
12
  * absent from the catalog, or when another paywall is already being
13
13
  * presented. See `resolvePresentDecision` in `present.ts`.
14
14
  */
15
- present: (placement: string) => Promise<PresentResult>;
15
+ present: (moment: string) => Promise<PresentResult>;
16
16
  /**
17
17
  * `true` once BOTH the catalog and its products have resolved — the one
18
18
  * flag meaning "calling `present()` now will not show a spinner".
19
19
  */
20
20
  isReady: boolean;
21
- /** The full resolved catalog (every placement), or `null` before it loads. */
21
+ /** The full resolved catalog (every moment), or `null` before it loads. */
22
22
  catalog: PaywallCatalog | null;
23
23
  /**
24
24
  * What the catalog is doing, for hosts that need more than `isReady`'s one
25
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 placement missing from it may
26
+ * from disk and a fresh fetch is in flight, so a moment missing from it may
27
27
  * simply not have arrived yet. Gate "fall back to another engine" on
28
28
  * `"ready"`, not merely on a non-null catalog.
29
29
  */
@@ -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;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,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;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"}
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"}
@@ -0,0 +1,57 @@
1
+ import type { ProductProvider } from "../types";
2
+ /**
3
+ * Stripe Payment Link provider.
4
+ *
5
+ * Deliberately NOT a store adapter. It makes no network call and holds no
6
+ * Stripe key: the price is authored in Onboarding Studio and travels inline on
7
+ * the `ProductRef` (`ProductRef.stripe`), so `getProducts` is a synchronous
8
+ * synthesis and `purchase` is a link-out.
9
+ *
10
+ * What it does NOT do, on purpose:
11
+ * - grant or verify anything. `purchase()` resolves `{ status: "pending" }`
12
+ * because the browser leaves the app — on web the JS context is destroyed.
13
+ * The entitlement arrives later through RevenueCat's Stripe integration,
14
+ * which is why `clientReferenceId` MUST return the RevenueCat App User ID:
15
+ * it is the key RevenueCat's webhook matches on, and the only thing tying
16
+ * the payment to the user. Return the wrong id and the money is taken with
17
+ * no entitlement granted. An ABSENT id (null/undefined/empty) is handled
18
+ * differently: `purchase()` refuses before opening anything, unless
19
+ * `allowAnonymous` opts in — see `StripeLinkProviderConfig.allowAnonymous`.
20
+ * - import `react-native` at module scope, so this file is safe to load on
21
+ * web. URL opening is injected (`openUrl`) for the same reason, and so the
22
+ * provider is testable under Node.
23
+ */
24
+ export type StripeLinkProviderConfig = {
25
+ /**
26
+ * The RevenueCat App User ID, as a getter — it changes on login/logout, and
27
+ * a value captured at provider construction would go stale.
28
+ */
29
+ clientReferenceId: () => string | null | undefined;
30
+ /** Optional email prefill for the Checkout page. */
31
+ prefilledEmail?: () => string | null | undefined;
32
+ /**
33
+ * How to leave the app. Defaults to `react-native`'s `Linking.openURL`,
34
+ * required lazily so this module stays importable where react-native is not.
35
+ */
36
+ openUrl?: (url: string) => void | Promise<void>;
37
+ /**
38
+ * Restoring is a store-account operation Stripe links cannot perform. Supply
39
+ * the host's real implementation (usually the RevenueCat adapter's
40
+ * `restore`) to make a Restore button work on a Stripe paywall.
41
+ */
42
+ restore?: ProductProvider["restore"];
43
+ /** Passed to `Intl.NumberFormat` when formatting the authored price. */
44
+ locale?: string;
45
+ /**
46
+ * Opt-in for checkout with no `clientReferenceId()`. Default `false`:
47
+ * `purchase()` refuses (fails closed) rather than open a Payment Link it
48
+ * cannot attribute to a RevenueCat user, because a payment that opens
49
+ * anyway is taken with NO way to grant the entitlement afterwards — see
50
+ * `purchase()` below. Set `true` only if you genuinely want anonymous
51
+ * checkout; entitlements from those purchases cannot be attributed
52
+ * automatically and must be reconciled out of band.
53
+ */
54
+ allowAnonymous?: boolean;
55
+ };
56
+ export declare const stripeLinkProductProvider: (config: StripeLinkProviderConfig) => ProductProvider;
57
+ //# sourceMappingURL=stripeLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripeLink.d.ts","sourceRoot":"","sources":["../../../src/products/adapters/stripeLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,eAAe,EAIhB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,iBAAiB,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACjD;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD;;;;OAIG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACrC,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAiDF,eAAO,MAAM,yBAAyB,GAAI,QAAQ,wBAAwB,KAAG,eAqI5E,CAAC"}
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripeLinkProductProvider = void 0;
4
+ const derive_1 = require("../derive");
5
+ const PERIOD_FROM_UNIT = {
6
+ D: "week",
7
+ W: "week",
8
+ M: "month",
9
+ Y: "year",
10
+ };
11
+ /** Same shape the store adapters parse, for one consistent notion of period. */
12
+ const toPeriod = (iso) => {
13
+ var _a;
14
+ if (!iso)
15
+ return { period: null, count: 0 };
16
+ const m = /^P(\d+)([DWMY])$/.exec(iso);
17
+ if (!m)
18
+ return { period: null, count: 0 };
19
+ return { period: (_a = PERIOD_FROM_UNIT[m[2]]) !== null && _a !== void 0 ? _a : null, count: Number(m[1]) };
20
+ };
21
+ const lazyLinking = (url) => {
22
+ // Required lazily and defensively: this provider's whole point is running on
23
+ // web, where react-native may be absent entirely.
24
+ try {
25
+ const RN = require("react-native");
26
+ return RN.Linking.openURL(url);
27
+ }
28
+ catch (_a) {
29
+ if (typeof globalThis !== "undefined" && globalThis.location) {
30
+ globalThis.location.assign(url);
31
+ return;
32
+ }
33
+ throw new Error("stripeLinkProductProvider: no way to open a URL. Pass `openUrl` in the provider config.");
34
+ }
35
+ };
36
+ const withParams = (link, params) => {
37
+ // Parsed rather than string-concatenated so a link that already carries
38
+ // query parameters (`?locale=fr`) keeps them and does not gain a second `?`.
39
+ const url = new URL(link);
40
+ for (const [name, value] of Object.entries(params)) {
41
+ // Omit rather than emit — Stripe would receive the literal string "null".
42
+ if (value === null || value === undefined || value === "")
43
+ continue;
44
+ url.searchParams.set(name, value);
45
+ }
46
+ return url.toString();
47
+ };
48
+ const stripeLinkProductProvider = (config) => {
49
+ const { clientReferenceId, prefilledEmail, openUrl = lazyLinking, restore, locale, allowAnonymous = false } = config;
50
+ // `ResolvedProduct` has no field for the payment link and widening it would
51
+ // put a Stripe concern on every store product, so the link is remembered
52
+ // here, populated by `getProducts` — the same call that produced the
53
+ // `ResolvedProduct` `purchase` is later handed.
54
+ const linkByKey = new Map();
55
+ return {
56
+ async getProducts(refs) {
57
+ var _a, _b, _c;
58
+ // Cleared, not merged: this call's `refs` is the full current catalog, so
59
+ // it defines the resolvable set on its own. A key that carried a stripe
60
+ // block last call but not this one (re-authored off Stripe billing) must
61
+ // stop resolving — an accumulating map would keep `purchase()` opening
62
+ // that stale link indefinitely instead of taking the "no link" error path.
63
+ linkByKey.clear();
64
+ const out = [];
65
+ for (const ref of refs) {
66
+ const s = ref.stripe;
67
+ // A ref with no stripe block is not an error — the catalog union spans
68
+ // every paywall, including `billing: "store"` ones. Dropping it is the
69
+ // same contract the store adapters have for a missing platform id.
70
+ if (!s || !s.paymentLink)
71
+ continue;
72
+ linkByKey.set(ref.key, s.paymentLink);
73
+ const { period, count } = toPeriod(s.periodIso);
74
+ const trialDays = (_a = s.trialDays) !== null && _a !== void 0 ? _a : 0;
75
+ out.push(Object.assign({ key: ref.key, productId: (_b = s.priceId) !== null && _b !== void 0 ? _b : s.paymentLink, store: "stripe", title: "", description: "", price: (0, derive_1.formatCurrency)(s.amount, s.currency, locale), priceAmount: s.amount, currencyCode: s.currency, period, periodCount: count, periodIso: (_c = s.periodIso) !== null && _c !== void 0 ? _c : null }, (trialDays > 0
76
+ ? {
77
+ trial: {
78
+ period: "week",
79
+ periodCount: Math.max(1, Math.round(trialDays / 7)),
80
+ days: trialDays,
81
+ },
82
+ }
83
+ : {})));
84
+ }
85
+ return out;
86
+ },
87
+ async purchase(product) {
88
+ const link = linkByKey.get(product.key);
89
+ if (!link) {
90
+ return {
91
+ status: "error",
92
+ error: new Error(`stripeLinkProductProvider: no payment link for "${product.key}". ` +
93
+ "getProducts() never resolved this key, so the ref carries no `stripe.paymentLink`."),
94
+ };
95
+ }
96
+ // Resolved and checked BEFORE the link opens — once it opens, the
97
+ // browser has left the app and the payment cannot be stopped. A
98
+ // null/undefined/empty id is not exotic: a getter wired to
99
+ // RevenueCat's `appUserID` before `Purchases.configure()` resolves, or
100
+ // read while the user is logged out, returns null. Without this check
101
+ // the link would still open, `purchase()` would still resolve
102
+ // "pending", the user would pay, and RevenueCat would have nothing to
103
+ // match the payment to — nothing fails loudly at any layer. See this
104
+ // file's top comment: "Return the wrong id and the money is taken with
105
+ // no entitlement granted" — this is that, for the ABSENT case.
106
+ const refId = clientReferenceId();
107
+ const hasRefId = refId !== null && refId !== undefined && refId !== "";
108
+ if (!hasRefId && !allowAnonymous) {
109
+ return {
110
+ status: "error",
111
+ error: new Error("stripeLinkProductProvider: clientReferenceId() returned no id — refusing to open the " +
112
+ "Payment Link. Opening it anyway would take payment with no way to attribute the " +
113
+ "entitlement RevenueCat grants afterwards. Wire `clientReferenceId` to the RevenueCat App " +
114
+ "User ID and make sure it resolves AFTER `Purchases.configure()` completes (reading it " +
115
+ "before configure() finishes, or while the user is logged out, is what returns null). " +
116
+ "Pass `allowAnonymous: true` in the provider config if anonymous checkout — with no " +
117
+ "automatic entitlement attribution — is genuinely what you want."),
118
+ };
119
+ }
120
+ // `withParams` throws synchronously on a malformed link (`new URL`) —
121
+ // a plausible failure mode for an author-pasted Stripe URL. That throw
122
+ // happens before any `await`, so left unguarded it would make
123
+ // `purchase()` return a REJECTED promise instead of the resolved
124
+ // `{ status: "error", error }` every other failure path in this file
125
+ // uses. Callers awaiting `purchase()` should only ever see it resolve.
126
+ try {
127
+ await openUrl(withParams(link, {
128
+ client_reference_id: refId,
129
+ prefilled_email: prefilledEmail === null || prefilledEmail === void 0 ? void 0 : prefilledEmail(),
130
+ }));
131
+ }
132
+ catch (e) {
133
+ // Always renamed to name the offending link — a bare `Invalid URL`
134
+ // (what `new URL` throws) gives an author nothing to act on.
135
+ const reason = e instanceof Error ? e.message : String(e);
136
+ return {
137
+ status: "error",
138
+ error: new Error(`stripeLinkProductProvider: failed to open payment link "${link}": ${reason}`),
139
+ };
140
+ }
141
+ // Never "purchased": the browser has taken over and, on web, this JS
142
+ // context is about to be destroyed. RevenueCat reports the entitlement.
143
+ return { status: "pending" };
144
+ },
145
+ async restore() {
146
+ if (restore)
147
+ return restore();
148
+ return {
149
+ status: "error",
150
+ error: new Error("stripeLinkProductProvider: restore is not configured. A Stripe Payment Link cannot " +
151
+ "enumerate past purchases; pass `restore` (usually your RevenueCat adapter's) in the " +
152
+ "provider config so a Restore button does something."),
153
+ };
154
+ },
155
+ };
156
+ };
157
+ exports.stripeLinkProductProvider = stripeLinkProductProvider;
158
+ //# sourceMappingURL=stripeLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripeLink.js","sourceRoot":"","sources":["../../../src/products/adapters/stripeLink.ts"],"names":[],"mappings":";;;AAAA,sCAA2C;AAgE3C,MAAM,gBAAgB,GAAkC;IACtD,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,MAAM;CACV,CAAC;AAEF,gFAAgF;AAChF,MAAM,QAAQ,GAAG,CAAC,GAA8B,EAAmD,EAAE;;IACnG,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC5C,MAAM,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC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ACf,KAAK,EAAE,IAAI,KAAK,CACd,uFAAuF;wBACrF,kFAAkF;wBAClF,2FAA2F;wBAC3F,wFAAwF;wBACxF,uFAAuF;wBACvF,qFAAqF;wBACrF,iEAAiE,CACpE;iBACF,CAAC;YACJ,CAAC;YACD,sEAAsE;YACtE,uEAAuE;YACvE,8DAA8D;YAC9D,iEAAiE;YACjE,qEAAqE;YACrE,uEAAuE;YACvE,IAAI,CAAC;gBACH,MAAM,OAAO,CACX,UAAU,CAAC,IAAI,EAAE;oBACf,mBAAmB,EAAE,KAAK;oBAC1B,eAAe,EAAE,cAAc,aAAd,cAAc,uBAAd,cAAc,EAAI;iBACpC,CAAC,CACH,CAAC;YACJ,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,mEAAmE;gBACnE,6DAA6D;gBAC7D,MAAM,MAAM,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC1D,OAAO;oBACL,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,IAAI,KAAK,CAAC,2DAA2D,IAAI,MAAM,MAAM,EAAE,CAAC;iBAChG,CAAC;YACJ,CAAC;YACD,qEAAqE;YACrE,wEAAwE;YACxE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/B,CAAC;QAED,KAAK,CAAC,OAAO;YACX,IAAI,OAAO;gBAAE,OAAO,OAAO,EAAE,CAAC;YAC9B,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,IAAI,KAAK,CACd,qFAAqF;oBACnF,sFAAsF;oBACtF,qDAAqD,CACxD;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AArIW,QAAA,yBAAyB,6BAqIpC"}
@@ -1,10 +1,13 @@
1
- export type { ProductRef, ProductPeriod, ResolvedProduct, DerivedProductFields, ProductWithDerived, PurchaseResult, RestoreResult, ProductProvider, ProductStatus, ProductRuntime, } from "./types";
1
+ export type { ProductRef, StripeProductRef, ProductPeriod, ResolvedProduct, DerivedProductFields, ProductWithDerived, PurchaseResult, RestoreResult, ProductProvider, ProductStatus, ProductRuntime, } from "./types";
2
2
  export { parseIsoDuration } from "./duration";
3
3
  export { formatCurrency, deriveProductFields, deriveAll } from "./derive";
4
4
  export { productVariables } from "./toVariables";
5
+ export { productRefIdentity } from "./refIdentity";
5
6
  export { useProducts } from "./useProducts";
6
7
  export { ProductRuntimeContext, useProductRuntime } from "./ProductRuntimeContext";
7
8
  export { stubProductProvider } from "./adapters/stub";
8
9
  export { revenueCatProductProvider } from "./adapters/revenueCat";
9
10
  export { expoIapProductProvider } from "./adapters/expoIap";
11
+ export { stripeLinkProductProvider } from "./adapters/stripeLink";
12
+ export type { StripeLinkProviderConfig } from "./adapters/stripeLink";
10
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/products/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oB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