@rocapine/react-native-onboarding 1.61.0 → 1.63.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 (173) hide show
  1. package/dist/OnboardingStudioClient.d.ts +23 -5
  2. package/dist/OnboardingStudioClient.d.ts.map +1 -1
  3. package/dist/OnboardingStudioClient.js +82 -6
  4. package/dist/OnboardingStudioClient.js.map +1 -1
  5. package/dist/index.d.ts +7 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +12 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/infra/hooks/index.d.ts +1 -0
  10. package/dist/infra/hooks/index.d.ts.map +1 -1
  11. package/dist/infra/hooks/index.js +3 -1
  12. package/dist/infra/hooks/index.js.map +1 -1
  13. package/dist/infra/hooks/useProgressHeaderConfig.d.ts +14 -0
  14. package/dist/infra/hooks/useProgressHeaderConfig.d.ts.map +1 -0
  15. package/dist/infra/hooks/useProgressHeaderConfig.js +24 -0
  16. package/dist/infra/hooks/useProgressHeaderConfig.js.map +1 -0
  17. package/dist/infra/preload/extractAssetUrls.d.ts.map +1 -1
  18. package/dist/infra/preload/extractAssetUrls.js +67 -0
  19. package/dist/infra/preload/extractAssetUrls.js.map +1 -1
  20. package/dist/infra/provider/OnboardingProvider.d.ts +25 -0
  21. package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
  22. package/dist/infra/provider/OnboardingProvider.js +74 -3
  23. package/dist/infra/provider/OnboardingProvider.js.map +1 -1
  24. package/dist/infra/queries/cacheKey.d.ts +22 -4
  25. package/dist/infra/queries/cacheKey.d.ts.map +1 -1
  26. package/dist/infra/queries/cacheKey.js +26 -5
  27. package/dist/infra/queries/cacheKey.js.map +1 -1
  28. package/dist/onboarding-example.d.ts +1063 -60
  29. package/dist/onboarding-example.d.ts.map +1 -1
  30. package/dist/onboarding-example.js +140 -0
  31. package/dist/onboarding-example.js.map +1 -1
  32. package/dist/paywalls/PaywallProvider.d.ts +66 -0
  33. package/dist/paywalls/PaywallProvider.d.ts.map +1 -0
  34. package/dist/paywalls/PaywallProvider.js +227 -0
  35. package/dist/paywalls/PaywallProvider.js.map +1 -0
  36. package/dist/paywalls/getPaywalls.query.d.ts +37 -0
  37. package/dist/paywalls/getPaywalls.query.d.ts.map +1 -0
  38. package/dist/paywalls/getPaywalls.query.js +114 -0
  39. package/dist/paywalls/getPaywalls.query.js.map +1 -0
  40. package/dist/paywalls/present.d.ts +100 -0
  41. package/dist/paywalls/present.d.ts.map +1 -0
  42. package/dist/paywalls/present.js +113 -0
  43. package/dist/paywalls/present.js.map +1 -0
  44. package/dist/paywalls/types.d.ts +95 -0
  45. package/dist/paywalls/types.d.ts.map +1 -0
  46. package/dist/paywalls/types.js +10 -0
  47. package/dist/paywalls/types.js.map +1 -0
  48. package/dist/paywalls/usePaywall.d.ts +29 -0
  49. package/dist/paywalls/usePaywall.d.ts.map +1 -0
  50. package/dist/paywalls/usePaywall.js +17 -0
  51. package/dist/paywalls/usePaywall.js.map +1 -0
  52. package/dist/products/ProductRuntimeContext.d.ts +15 -0
  53. package/dist/products/ProductRuntimeContext.d.ts.map +1 -0
  54. package/dist/products/ProductRuntimeContext.js +19 -0
  55. package/dist/products/ProductRuntimeContext.js.map +1 -0
  56. package/dist/products/index.d.ts +1 -0
  57. package/dist/products/index.d.ts.map +1 -1
  58. package/dist/products/index.js +4 -1
  59. package/dist/products/index.js.map +1 -1
  60. package/dist/products/mergeProductRuntimes.d.ts +55 -0
  61. package/dist/products/mergeProductRuntimes.d.ts.map +1 -0
  62. package/dist/products/mergeProductRuntimes.js +79 -0
  63. package/dist/products/mergeProductRuntimes.js.map +1 -0
  64. package/dist/screens/elements/AnimatedTextElement.d.ts +7 -0
  65. package/dist/screens/elements/AnimatedTextElement.d.ts.map +1 -1
  66. package/dist/screens/elements/BaseBoxProps.d.ts +39 -0
  67. package/dist/screens/elements/BaseBoxProps.d.ts.map +1 -1
  68. package/dist/screens/elements/BaseBoxProps.js +9 -0
  69. package/dist/screens/elements/BaseBoxProps.js.map +1 -1
  70. package/dist/screens/elements/ButtonElement.d.ts +28 -0
  71. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  72. package/dist/screens/elements/CarouselElement.d.ts +38 -0
  73. package/dist/screens/elements/CarouselElement.d.ts.map +1 -1
  74. package/dist/screens/elements/CarouselElement.js +1 -0
  75. package/dist/screens/elements/CarouselElement.js.map +1 -1
  76. package/dist/screens/elements/CheckboxGroupElement.d.ts +7 -0
  77. package/dist/screens/elements/CheckboxGroupElement.d.ts.map +1 -1
  78. package/dist/screens/elements/DatePickerElement.d.ts +7 -0
  79. package/dist/screens/elements/DatePickerElement.d.ts.map +1 -1
  80. package/dist/screens/elements/DrawingPadElement.d.ts +7 -0
  81. package/dist/screens/elements/DrawingPadElement.d.ts.map +1 -1
  82. package/dist/screens/elements/IconElement.d.ts +7 -0
  83. package/dist/screens/elements/IconElement.d.ts.map +1 -1
  84. package/dist/screens/elements/ImageElement.d.ts +26 -0
  85. package/dist/screens/elements/ImageElement.d.ts.map +1 -1
  86. package/dist/screens/elements/ImageElement.js +1 -0
  87. package/dist/screens/elements/ImageElement.js.map +1 -1
  88. package/dist/screens/elements/InputElement.d.ts +7 -0
  89. package/dist/screens/elements/InputElement.d.ts.map +1 -1
  90. package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts +7 -0
  91. package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts.map +1 -1
  92. package/dist/screens/elements/LottieElement.d.ts +7 -0
  93. package/dist/screens/elements/LottieElement.d.ts.map +1 -1
  94. package/dist/screens/elements/ProgressIndicatorElement.d.ts +7 -0
  95. package/dist/screens/elements/ProgressIndicatorElement.d.ts.map +1 -1
  96. package/dist/screens/elements/ProgressiveBlurImageElement.d.ts +7 -0
  97. package/dist/screens/elements/ProgressiveBlurImageElement.d.ts.map +1 -1
  98. package/dist/screens/elements/RadioGroupElement.d.ts +7 -0
  99. package/dist/screens/elements/RadioGroupElement.d.ts.map +1 -1
  100. package/dist/screens/elements/RepeatElement.d.ts +79 -0
  101. package/dist/screens/elements/RepeatElement.d.ts.map +1 -0
  102. package/dist/screens/elements/RepeatElement.js +10 -0
  103. package/dist/screens/elements/RepeatElement.js.map +1 -0
  104. package/dist/screens/elements/RichTextElement.d.ts +7 -0
  105. package/dist/screens/elements/RichTextElement.d.ts.map +1 -1
  106. package/dist/screens/elements/RiveElement.d.ts +7 -0
  107. package/dist/screens/elements/RiveElement.d.ts.map +1 -1
  108. package/dist/screens/elements/SafeAreaViewElement.d.ts +7 -0
  109. package/dist/screens/elements/SafeAreaViewElement.d.ts.map +1 -1
  110. package/dist/screens/elements/ScrollViewElement.d.ts +7 -0
  111. package/dist/screens/elements/ScrollViewElement.d.ts.map +1 -1
  112. package/dist/screens/elements/SliderElement.d.ts +7 -0
  113. package/dist/screens/elements/SliderElement.d.ts.map +1 -1
  114. package/dist/screens/elements/StackElement.d.ts +7 -0
  115. package/dist/screens/elements/StackElement.d.ts.map +1 -1
  116. package/dist/screens/elements/TextElement.d.ts +7 -0
  117. package/dist/screens/elements/TextElement.d.ts.map +1 -1
  118. package/dist/screens/elements/TypewriterTextElement.d.ts +26 -0
  119. package/dist/screens/elements/TypewriterTextElement.d.ts.map +1 -1
  120. package/dist/screens/elements/TypewriterTextElement.js +1 -0
  121. package/dist/screens/elements/TypewriterTextElement.js.map +1 -1
  122. package/dist/screens/elements/VideoElement.d.ts +7 -0
  123. package/dist/screens/elements/VideoElement.d.ts.map +1 -1
  124. package/dist/screens/elements/WheelPickerElement.d.ts +7 -0
  125. package/dist/screens/elements/WheelPickerElement.d.ts.map +1 -1
  126. package/dist/screens/elements/ZStackElement.d.ts +7 -0
  127. package/dist/screens/elements/ZStackElement.d.ts.map +1 -1
  128. package/dist/screens/types.d.ts +9 -0
  129. package/dist/screens/types.d.ts.map +1 -1
  130. package/dist/screens/types.js +9 -0
  131. package/dist/screens/types.js.map +1 -1
  132. package/dist/screens/unknownKeys.d.ts +67 -0
  133. package/dist/screens/unknownKeys.d.ts.map +1 -0
  134. package/dist/screens/unknownKeys.js +160 -0
  135. package/dist/screens/unknownKeys.js.map +1 -0
  136. package/dist/steps/common.types.d.ts +22 -1
  137. package/dist/steps/common.types.d.ts.map +1 -1
  138. package/dist/steps/common.types.js +10 -1
  139. package/dist/steps/common.types.js.map +1 -1
  140. package/dist/types.d.ts +73 -0
  141. package/dist/types.d.ts.map +1 -1
  142. package/package.json +1 -1
  143. package/src/OnboardingStudioClient.ts +110 -7
  144. package/src/__tests__/extractAssetUrls.test.ts +104 -0
  145. package/src/__tests__/mergeProductRuntimes.test.ts +172 -0
  146. package/src/__tests__/resolveLocalProductArgs.test.ts +41 -0
  147. package/src/__tests__/unknownKeys.test.ts +234 -0
  148. package/src/index.ts +20 -0
  149. package/src/infra/hooks/index.ts +1 -0
  150. package/src/infra/hooks/useProgressHeaderConfig.ts +21 -0
  151. package/src/infra/preload/extractAssetUrls.ts +72 -0
  152. package/src/infra/provider/OnboardingProvider.tsx +87 -3
  153. package/src/infra/queries/cacheKey.ts +27 -4
  154. package/src/onboarding-example.ts +140 -0
  155. package/src/paywalls/PaywallProvider.tsx +342 -0
  156. package/src/paywalls/__tests__/getPaywalls.test.ts +334 -0
  157. package/src/paywalls/__tests__/present.test.ts +190 -0
  158. package/src/paywalls/getPaywalls.query.ts +123 -0
  159. package/src/paywalls/present.ts +141 -0
  160. package/src/paywalls/types.ts +99 -0
  161. package/src/paywalls/usePaywall.ts +35 -0
  162. package/src/products/ProductRuntimeContext.tsx +17 -0
  163. package/src/products/index.ts +1 -0
  164. package/src/products/mergeProductRuntimes.ts +78 -0
  165. package/src/screens/elements/BaseBoxProps.ts +56 -0
  166. package/src/screens/elements/CarouselElement.ts +31 -0
  167. package/src/screens/elements/ImageElement.ts +16 -0
  168. package/src/screens/elements/RepeatElement.ts +80 -0
  169. package/src/screens/elements/TypewriterTextElement.ts +19 -0
  170. package/src/screens/types.ts +18 -0
  171. package/src/screens/unknownKeys.ts +211 -0
  172. package/src/steps/common.types.ts +34 -1
  173. package/src/types.ts +86 -0
@@ -0,0 +1,141 @@
1
+ import type { Paywall, PaywallCatalog, PresentResult } from "./types";
2
+ import type { ProductRef, ProductStatus, PurchaseResult } from "../products/types";
3
+
4
+ /**
5
+ * Union of every `paywall.products[]` across the WHOLE catalog, deduplicated
6
+ * 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.
10
+ *
11
+ * Resolving the whole catalog's union ONCE at load — rather than re-keying
12
+ * `useProducts` per presented paywall — is the deliberate design decision:
13
+ * a paywall must render the instant the user taps upgrade (spec §6.1), and a
14
+ * store round-trip at that moment is exactly the latency this avoids. Cost
15
+ * accepted: an app resolves products for paywalls it may never show.
16
+ */
17
+ export const collectProductRefs = (catalog: PaywallCatalog | null): ProductRef[] => {
18
+ if (!catalog) return [];
19
+ const seen = new Set<string>();
20
+ const refs: ProductRef[] = [];
21
+ for (const paywall of Object.values(catalog.paywalls)) {
22
+ for (const ref of paywall.products) {
23
+ const identity = `${ref.key}|${ref.ios ?? ""}|${ref.android ?? ""}|${ref.compareTo ?? ""}`;
24
+ if (seen.has(identity)) continue;
25
+ seen.add(identity);
26
+ refs.push(ref);
27
+ }
28
+ }
29
+ return refs;
30
+ };
31
+
32
+ /** What `present()` should do, decided as a pure function of current state. */
33
+ export type PresentDecision =
34
+ | { type: "start"; paywall: Paywall }
35
+ | { type: "immediate"; result: PresentResult };
36
+
37
+ /**
38
+ * `present(placement)`'s edge-case decision, extracted so both documented
39
+ * edge cases are covered by an importable test rather than only inspection:
40
+ *
41
+ * - **Unknown placement** (absent from the catalog, or the catalog hasn't
42
+ * resolved yet — both look identical here: `catalog?.paywalls[placement]`
43
+ * is `undefined` either way) → resolves `"error"`, never throws. A missing
44
+ * placement must not crash a host app mid-flow.
45
+ * - **`present()` called while another paywall is already showing** → also
46
+ * resolves `"error"` immediately, leaving the in-progress presentation
47
+ * untouched. This SDK shows one paywall at a time. Silently replacing the
48
+ * active paywall would orphan its pending `present()` promise (never
49
+ * resolved — that caller hangs forever); queueing the new request would
50
+ * need its own cancellation/timeout story that nothing here asks for.
51
+ * Resolving the new call immediately applies the same "resolve, don't
52
+ * throw" contract as the unknown-placement case, consistently.
53
+ */
54
+ export const resolvePresentDecision = (
55
+ catalog: PaywallCatalog | null,
56
+ activePlacement: string | null,
57
+ placement: string
58
+ ): PresentDecision => {
59
+ if (activePlacement !== null) {
60
+ return { type: "immediate", result: { status: "error" } };
61
+ }
62
+ const paywall = catalog?.paywalls[placement];
63
+ if (!paywall) {
64
+ return { type: "immediate", result: { status: "error" } };
65
+ }
66
+ return { type: "start", paywall };
67
+ };
68
+
69
+ /**
70
+ * `isReady` = catalog resolved AND products resolved — the one flag a caller
71
+ * needs to know "presenting now will not show a spinner".
72
+ *
73
+ * The `productRefs.length === 0` branch handles a real edge case:
74
+ * `useProducts` never leaves status `"idle"` when its ref set is empty
75
+ * (`products/useProducts.ts:49-54` bails out before ever calling the
76
+ * provider) — a catalog whose paywalls declare no products at all would
77
+ * otherwise report `isReady: false` forever, with nothing to actually wait
78
+ * for.
79
+ */
80
+ export const computeIsReady = (
81
+ catalog: PaywallCatalog | null,
82
+ productRefs: ProductRef[],
83
+ productsStatus: ProductStatus
84
+ ): boolean => catalog !== null && (productRefs.length === 0 || productsStatus === "ready");
85
+
86
+ /**
87
+ * What a purchase attempt resolved to during the current presentation, or
88
+ * `null` if none did. Only the two `PurchaseResult` statuses that describe a
89
+ * completed store interaction are tracked — `"pending"` (e.g. Ask-to-Buy) and
90
+ * `"error"` are not: they don't describe what happened to the STORE PURCHASE
91
+ * in a way that should override how the paywall itself reports closing (an
92
+ * `"error"` here would collide with `PresentResult`'s existing `"error"`,
93
+ * which means something structurally different — an unknown placement or a
94
+ * mistimed `present()` call, not a failed purchase attempt).
95
+ */
96
+ export type PurchaseOutcomeDuringPresentation = "purchased" | "cancelled" | null;
97
+
98
+ /** Narrows a `PurchaseResult` to the subset `PurchaseOutcomeDuringPresentation` tracks. */
99
+ export const purchaseOutcomeFromResult = (result: PurchaseResult): PurchaseOutcomeDuringPresentation =>
100
+ result.status === "purchased" || result.status === "cancelled" ? result.status : null;
101
+
102
+ /**
103
+ * Reconciles what the closing action REPORTED with what actually happened at
104
+ * the store during this presentation. `dismiss` (spec §4.5) always reports
105
+ * `{status:"dismissed"}` — it is the generic "this screen is done" signal and
106
+ * knows nothing about purchases, which is exactly the gap spec §4.6's own
107
+ * canonical authoring shape falls into: `{type:"purchase", onSuccess:
108
+ * [{type:"dismiss"}]}` closes a successful purchase through the SAME generic
109
+ * signal a user backing out would produce. So a bare `"dismissed"` is treated
110
+ * as "the caller didn't have anything more specific to say" and gets upgraded
111
+ * to whatever the store actually did (if anything). Any other reported
112
+ * status is assumed to mean something deliberate and passes through
113
+ * unchanged — this only fills in the generic default, never overrides a
114
+ * caller that already said something more specific.
115
+ */
116
+ export const resolvePresentedOutcome = (
117
+ reported: PresentResult,
118
+ purchaseOutcome: PurchaseOutcomeDuringPresentation
119
+ ): PresentResult =>
120
+ reported.status === "dismissed" && purchaseOutcome ? { status: purchaseOutcome } : reported;
121
+
122
+ /**
123
+ * Guards the purchase-outcome WRITE against a race that resetting the ref at
124
+ * `present()`'s start does not, by itself, prevent: paywall A is showing,
125
+ * `purchase()` is in flight; the user dismisses A (nothing tracked yet, so A
126
+ * correctly resolves `"dismissed"`); paywall B is presented, resetting the
127
+ * tracked outcome; THEN A's stale promise finally settles and would write
128
+ * `"purchased"` into what is now B's tracker — B later reports a purchase
129
+ * the user never made on it. `purchase()` must capture the current
130
+ * generation BEFORE awaiting the store and compare it against the current
131
+ * generation again after — only an unchanged generation means the write is
132
+ * still for the presentation that started it.
133
+ *
134
+ * A monotonic counter, not the placement string: the same placement can
135
+ * legitimately be presented twice in a row, and a string comparison would
136
+ * let a stale write from the FIRST of those two land in the second.
137
+ */
138
+ export const shouldRecordPurchaseOutcome = (
139
+ startedInGeneration: number,
140
+ currentGeneration: number
141
+ ): boolean => startedInGeneration === currentGeneration;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Response types for `OnboardingStudioClient.getPaywalls()` (spec §6.1). The
3
+ * endpoint returns every placement for the project/audience/locale in one
4
+ * payload — a paywall must render the instant the user taps upgrade, and a
5
+ * 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
+ */
8
+
9
+ /** A single studio-authored paywall, keyed by `placement` in `PaywallCatalog.paywalls`. */
10
+ export type Paywall = {
11
+ id: string;
12
+ name: string;
13
+ placement: string;
14
+ /** UIElement[] — parsed by the UI adapter (Task 7's `ScreenElementsSchema`), not here. */
15
+ elements: unknown[];
16
+ products: Array<{
17
+ key: string;
18
+ ios?: string;
19
+ android?: string;
20
+ compareTo?: string;
21
+ }>;
22
+ configuration: Record<string, unknown> | null;
23
+ };
24
+
25
+ /** Full response body of `GET get-paywalls`. */
26
+ export type PaywallCatalog = {
27
+ metadata: {
28
+ audienceId: number | null;
29
+ audienceName: string | null;
30
+ locale: string | null;
31
+ draft: boolean;
32
+ };
33
+ /** Keyed by placement, not by paywall id. */
34
+ paywalls: Record<string, Paywall>;
35
+ fonts: Record<string, unknown> | null;
36
+ };
37
+
38
+ /**
39
+ * Options for `OnboardingStudioClient.getPaywalls()`.
40
+ *
41
+ * `placement` narrows the response to a single paywall — the exception, not
42
+ * the default. Omit it to get every placement in one round-trip, which is
43
+ * what lets a paywall render instantly at buy-tap time (see the module doc
44
+ * above).
45
+ */
46
+ export type PaywallOptions = {
47
+ locale?: string;
48
+ placement?: string;
49
+ };
50
+
51
+ /**
52
+ * Response headers for `get-paywalls`. Deliberately **not** the onboarding
53
+ * trio (`ONBS-Onboarding-Id` / `ONBS-Audience-Id` / `ONBS-Onboarding-Name`) —
54
+ * the paywall endpoint has no single onboarding/audience-name concept and
55
+ * instead reports which paywall ids came back.
56
+ */
57
+ export interface GetPaywallsResponseHeaders {
58
+ "ONBS-Audience-Id": string | null;
59
+ "ONBS-Paywall-Ids": string | null;
60
+ }
61
+
62
+ /**
63
+ * Resolved outcome of a `usePaywall().present(placement)` call (spec §7).
64
+ * Closed union, not the open-ended `ScreenHost.CompleteOutcome` — a
65
+ * presentation ends in exactly one of these four ways, and `present()`'s
66
+ * caller (typically an `await`) should be able to switch over it exhaustively.
67
+ *
68
+ * `"error"` covers both: (a) `placement` is absent from the catalog (or the
69
+ * catalog hasn't resolved yet), and (b) `present()` was called while another
70
+ * paywall is already being presented. Both resolve rather than throw — a
71
+ * missing placement or a mistimed call must not crash a host app mid-flow.
72
+ * See `resolvePresentDecision` in `present.ts` for the exact decision logic.
73
+ *
74
+ * `"purchased"` / `"cancelled"` are NOT produced by any ButtonAction directly
75
+ * — `dismiss` (the only in-content closing action) always reports
76
+ * `{status:"dismissed"}`, on purpose, since it doesn't know anything about
77
+ * purchase state. `PaywallProvider` instead tracks what the store actually
78
+ * did during the active presentation (`purchaseOutcomeFromResult` in
79
+ * `present.ts`) and `resolvePresentedOutcome` upgrades a bare `"dismissed"`
80
+ * to whichever of these occurred, if any — so spec §4.6's canonical authoring
81
+ * shape (`{type:"purchase", onSuccess:[{type:"dismiss"}]}`) resolves
82
+ * `"purchased"` even though `dismiss` itself never says so.
83
+ */
84
+ /**
85
+ * How a presentation ENDED — not what the user is entitled to.
86
+ *
87
+ * `"purchased"` means a purchase succeeded while this paywall was showing, and
88
+ * is the honest report in the common case. But it is deliberately not an
89
+ * entitlement signal: a purchase followed by a render crash resolves `"error"`
90
+ * (the boundary settles the promise so the user is not trapped), so a host that
91
+ * keys entitlement off `status === "purchased"` would under-grant a user who
92
+ * genuinely paid.
93
+ *
94
+ * Entitlement belongs to the store — read it from the `ProductProvider` /
95
+ * billing SDK, and use this only to decide what the UI does next.
96
+ */
97
+ export type PresentResult = {
98
+ status: "purchased" | "dismissed" | "cancelled" | "error";
99
+ };
@@ -0,0 +1,35 @@
1
+ import { useContext } from "react";
2
+ import { PaywallContext } from "./PaywallProvider";
3
+ import { PaywallCatalog, PresentResult } from "./types";
4
+
5
+ export type UsePaywallResult = {
6
+ /**
7
+ * Present a paywall by placement. Never fetches — the catalog and its
8
+ * products are already resolved (or resolving) from `PaywallProvider`
9
+ * mount, which is the whole point: a paywall must render the instant the
10
+ * user taps upgrade.
11
+ *
12
+ * Resolves `{ status: "error" }` — never throws — when `placement` is
13
+ * absent from the catalog, or when another paywall is already being
14
+ * presented. See `resolvePresentDecision` in `present.ts`.
15
+ */
16
+ present: (placement: string) => Promise<PresentResult>;
17
+ /**
18
+ * `true` once BOTH the catalog and its products have resolved — the one
19
+ * flag meaning "calling `present()` now will not show a spinner".
20
+ */
21
+ isReady: boolean;
22
+ /** The full resolved catalog (every placement), or `null` before it loads. */
23
+ catalog: PaywallCatalog | null;
24
+ };
25
+
26
+ /**
27
+ * Read the paywall runtime published by an ancestor `PaywallProvider`.
28
+ * Outside one, returns inert defaults (`present` resolves `"error"`,
29
+ * `isReady: false`, `catalog: null`) rather than throwing — mirrors how
30
+ * `useProductRuntime()` degrades to `null` with no ancestor.
31
+ */
32
+ export const usePaywall = (): UsePaywallResult => {
33
+ const { present, isReady, catalog } = useContext(PaywallContext);
34
+ return { present, isReady, catalog };
35
+ };
@@ -0,0 +1,17 @@
1
+ import { createContext, useContext } from "react";
2
+ import type { ProductRuntime } from "./types";
3
+
4
+ /**
5
+ * Publishes one `ProductRuntime` above both `PaywallProvider` and
6
+ * `OnboardingProvider`, so a `PaywallProvider` mounted around an
7
+ * `OnboardingProvider` (Phase 5's `presentPaywall` arrangement) gives them one
8
+ * shared product catalog instead of each mounting its own `useProducts` — one
9
+ * store round-trip, one `purchasing` flag, for both.
10
+ *
11
+ * `null` by default: nothing above publishes a runtime, which is the normal
12
+ * case for an app that mounts only `OnboardingProvider`.
13
+ */
14
+ export const ProductRuntimeContext = createContext<ProductRuntime | null>(null);
15
+
16
+ /** The ancestor `ProductRuntime`, or `null` when no provider publishes one. */
17
+ export const useProductRuntime = (): ProductRuntime | null => useContext(ProductRuntimeContext);
@@ -14,6 +14,7 @@ export { parseIsoDuration } from "./duration";
14
14
  export { formatCurrency, deriveProductFields, deriveAll } from "./derive";
15
15
  export { productVariables } from "./toVariables";
16
16
  export { useProducts } from "./useProducts";
17
+ export { ProductRuntimeContext, useProductRuntime } from "./ProductRuntimeContext";
17
18
  export { stubProductProvider } from "./adapters/stub";
18
19
  export { revenueCatProductProvider } from "./adapters/revenueCat";
19
20
  export { expoIapProductProvider } from "./adapters/expoIap";
@@ -0,0 +1,78 @@
1
+ import type { ProductRuntime, ProductStatus } from "./types";
2
+
3
+ const mergeStatus = (a: ProductStatus, b: ProductStatus): ProductStatus => {
4
+ if (a === "error" || b === "error") return "error";
5
+ if (a === "ready" && b === "ready") return "ready";
6
+ if (a === "loading" || b === "loading") return "loading";
7
+ return "idle";
8
+ };
9
+
10
+ /**
11
+ * Publishes ONE `ProductRuntime` out of the shared context runtime (a
12
+ * `PaywallProvider` ancestor's catalog union) and this `OnboardingProvider`'s
13
+ * own local resolution of its `productRefs` prop.
14
+ *
15
+ * Finding 5, 2026-08-17 final review: `OnboardingProvider` used to zero the
16
+ * local ref set out entirely whenever a context runtime existed, on the
17
+ * assumption that the paywall catalog's product union is always a superset of
18
+ * whatever `productRefs` the host declares — an assumption about a
19
+ * host-supplied prop, not a property of the code. That silently broke a
20
+ * documented Phase 3 prop the moment a host added a `PaywallProvider` above
21
+ * an existing `OnboardingProvider`: `productRefs` keys absent from the
22
+ * catalog union resolved to nothing, with no error and nothing that
23
+ * type-checks. `productRefs` is therefore ALWAYS resolved locally now,
24
+ * regardless of whether a context runtime exists (see
25
+ * `resolveLocalProductArgs`) — this function unions the result back into the
26
+ * one `ProductRuntime` the rest of the app reads.
27
+ *
28
+ * **Callers MUST memoize this** (`OnboardingProvider.tsx` wraps it in
29
+ * `useMemo`, keyed on the four arguments) — round 2 of the final review (N1)
30
+ * found the object literal below allocated fresh, plus a fresh `purchase`
31
+ * closure, on every call, which breaks `ScreenHost.products`'s "referentially
32
+ * stable across variable writes" contract when called inline in a render
33
+ * body.
34
+ *
35
+ * Returns `contextRuntime` UNCHANGED when there is nothing local to add
36
+ * (`hasLocalRefs` false — the common case: no host-declared `productRefs`),
37
+ * so the well-established "one shared runtime, no local round trip" identity
38
+ * and behavior is untouched for every app that doesn't use this prop.
39
+ *
40
+ * `purchase` routes by key: a key resolved by the LOCAL runtime purchases
41
+ * through the local provider (it is the only one that resolved it); anything
42
+ * else — including an unknown key — goes through the context runtime, which
43
+ * already reports "No resolved product for key" for that case (`useProducts.
44
+ * purchase`), so no separate handling is needed here. `restore` delegates to
45
+ * the context runtime only: restoring is a whole store-account operation, not
46
+ * scoped to individual refs, so one call through the shared adapter is
47
+ * correct even with a local ref set also present — the same billing adapter
48
+ * type is the expected real-world setup for both `productProvider` props.
49
+ *
50
+ * `hasLocalProvider` (N3, round 2): a host can declare `productRefs` with NO
51
+ * local `productProvider` — nothing unusual, since the shared context runtime
52
+ * is normally expected to cover everything. `useProducts` then never leaves
53
+ * `"idle"` for the local runtime (it bails before ever calling a provider it
54
+ * doesn't have — `useProducts.ts`), and a naive `mergeStatus` would drag the
55
+ * context runtime's `"ready"` down to `"idle"` FOREVER, closing every
56
+ * `renderWhen: {"products.loaded": {eq:"true"}}` gate for good — the same
57
+ * "idle blocks readiness when there's nothing to actually wait for" trap
58
+ * `computeIsReady` (`present.ts`) already special-cases for an empty ref set.
59
+ * When there is no local provider, the local runtime has nothing pending, so
60
+ * the merged status is just the context runtime's.
61
+ */
62
+ export const mergeProductRuntimes = (
63
+ contextRuntime: ProductRuntime,
64
+ localRuntime: ProductRuntime,
65
+ hasLocalRefs: boolean,
66
+ hasLocalProvider: boolean
67
+ ): ProductRuntime => {
68
+ if (!hasLocalRefs) return contextRuntime;
69
+ return {
70
+ products: { ...contextRuntime.products, ...localRuntime.products },
71
+ status: hasLocalProvider ? mergeStatus(contextRuntime.status, localRuntime.status) : contextRuntime.status,
72
+ error: contextRuntime.error ?? localRuntime.error,
73
+ purchasing: contextRuntime.purchasing || localRuntime.purchasing,
74
+ purchase: (key: string) =>
75
+ key in localRuntime.products ? localRuntime.purchase(key) : contextRuntime.purchase(key),
76
+ restore: contextRuntime.restore,
77
+ };
78
+ };
@@ -244,6 +244,26 @@ export type ElementAnimation = {
244
244
  exiting?: ExitingAnimation;
245
245
  layout?: LayoutAnimation;
246
246
  effect?: ElementEffect;
247
+ /**
248
+ * Replay `entering` whenever the named variable's VALUE changes.
249
+ *
250
+ * Reanimated fires an `entering` builder on mount and never again, so without
251
+ * this the only way to re-run an entrance is to unmount and remount the
252
+ * element — which today means toggling `renderWhen`, i.e. you cannot replay
253
+ * without also changing visibility. This covers the case where the element
254
+ * stays on screen and should re-animate because something it depends on
255
+ * changed (a recalculated total, the answer to the question above it).
256
+ *
257
+ * Mechanism, because it has a visible consequence: the element's subtree is
258
+ * remounted (its React key is derived from the variable's value). Any
259
+ * transient state inside it resets — an `Input`'s uncommitted text, a
260
+ * `Carousel`'s scroll position — and a continuous `animation.effect` restarts.
261
+ * Use it on presentational subtrees; avoid wrapping inputs in one.
262
+ *
263
+ * The first render is not a replay: the key only changes on a subsequent
264
+ * write, so `entering` still fires exactly once on mount.
265
+ */
266
+ replayWhen?: string;
247
267
  };
248
268
 
249
269
  const ElementAnimationSchema = z.object({
@@ -251,6 +271,35 @@ const ElementAnimationSchema = z.object({
251
271
  exiting: ExitingAnimationSchema.optional(),
252
272
  layout: LayoutAnimationSchema.optional(),
253
273
  effect: EffectSchema.optional(),
274
+ replayWhen: z.string().min(1).optional(),
275
+ });
276
+
277
+ // Declarative absolute placement for a ZStack child. Numbers are density-
278
+ // independent pixels; strings are percentages of the stack ("62.1%") — the same
279
+ // number|string convention `width`/`height` already use via `dim()`.
280
+ //
281
+ // ONLY honoured on a direct child of a `ZStack`, because that is the only
282
+ // container that absolutely-positions its children; elsewhere it is inert.
283
+ //
284
+ // A side you omit is NOT treated as 0 — it falls back to the ZStack's shared
285
+ // anchor for that axis, so partial placement works (`{ top: 40 }` pins vertically
286
+ // while still honouring the anchor horizontally). Supplying exactly one side per
287
+ // axis (`top` + `left`) leaves the child content-sized and pinned by that corner,
288
+ // which is what a drag-to-place gesture means; supplying BOTH sides of an axis
289
+ // resolves to a width/height instead, which stretches the child.
290
+ export type ElementInset = {
291
+ top?: number | string;
292
+ left?: number | string;
293
+ right?: number | string;
294
+ bottom?: number | string;
295
+ };
296
+
297
+ const InsetSide = z.union([z.number(), z.string()]);
298
+ const InsetSchema = z.object({
299
+ top: InsetSide.optional(),
300
+ left: InsetSide.optional(),
301
+ right: InsetSide.optional(),
302
+ bottom: InsetSide.optional(),
254
303
  });
255
304
 
256
305
  // Static transform surface — also what `effect` animates at runtime.
@@ -303,6 +352,12 @@ export type BaseBoxProps = {
303
352
  shadowOpacity?: number;
304
353
  shadowRadius?: number;
305
354
  elevation?: number;
355
+ /**
356
+ * Declarative absolute placement inside a `ZStack` (ignored elsewhere).
357
+ * Replaces doing the arithmetic by hand with `transform.translateX/Y`;
358
+ * composes with `transform` rather than replacing it.
359
+ */
360
+ inset?: ElementInset;
306
361
  transform?: ElementTransform;
307
362
  animation?: ElementAnimation;
308
363
  /**
@@ -344,6 +399,7 @@ export const BaseBoxPropsSchema = z.object({
344
399
  shadowOpacity: z.number().min(0).max(1).optional(),
345
400
  shadowRadius: z.number().min(0).optional(),
346
401
  elevation: z.number().min(0).optional(),
402
+ inset: InsetSchema.optional(),
347
403
  transform: TransformSchema.optional(),
348
404
  animation: ElementAnimationSchema.optional(),
349
405
  onPress: z.array(ButtonActionSchema).optional(),
@@ -19,6 +19,36 @@ export type CarouselElementProps = BaseBoxProps & {
19
19
  dotsMarginBottom?: number;
20
20
  defaultIndex?: number | null;
21
21
  variableName?: string;
22
+ /**
23
+ * Publishes the carousel's *continuous* swipe position as a screen-scoped
24
+ * animated variable, so sibling elements can gate `renderWhen` on the finger
25
+ * rather than on the settled slide.
26
+ *
27
+ * `variableName` is written only on snap, so it steps 0 → 1 → 2. This tracks
28
+ * the drag: 0 → 0.37 → 0.81 → 1, updating every frame.
29
+ *
30
+ * Value semantics — ALWAYS normalized to `[0, childCount)`:
31
+ * • the underlying `absoluteProgress` from react-native-reanimated-carousel
32
+ * is clamped to `[0, n-1]` when `loop: false`, but is UNBOUNDED when
33
+ * `loop: true` (the library never wraps its internal offset — on the
34
+ * second lap slide 1 reports 4, not 1, and it keeps climbing).
35
+ * • `loop` defaults to TRUE here, so publishing the raw value would silently
36
+ * break any `eq`/`lt`/`gte` gate after the first lap. We therefore publish
37
+ * `((raw % n) + n) % n`, which is a no-op for `loop: false` and makes every
38
+ * lap read identically.
39
+ * • consequence: under `loop: true` the value is discontinuous at the wrap
40
+ * seam, jumping from just under `n` back to 0. That is the same seam the
41
+ * dots cross, so it matches what the user sees.
42
+ *
43
+ * Consumed on the UI thread — see `AnimatedVariablesContext` / `GatedElement`.
44
+ * Note `eq` compares the ROUNDED value, so `eq 1` flips once the swipe passes
45
+ * halfway to slide 1 (that is the intended "fade in during the gesture" feel).
46
+ *
47
+ * Safe to set to the same string as `variableName`: the store then holds the
48
+ * snapped integer for branching/analytics while gates on this screen read the
49
+ * live value, since an animated variable takes precedence in `GatedElement`.
50
+ */
51
+ progressVariableName?: string;
22
52
  };
23
53
 
24
54
  export const CarouselElementPropsSchema = BaseBoxPropsSchema.extend({
@@ -39,4 +69,5 @@ export const CarouselElementPropsSchema = BaseBoxPropsSchema.extend({
39
69
  dotsMarginBottom: z.number().optional().default(0),
40
70
  defaultIndex: z.number().int().nonnegative().nullable().optional(),
41
71
  variableName: z.string().min(1).optional(),
72
+ progressVariableName: z.string().min(1).optional(),
42
73
  });
@@ -3,6 +3,21 @@ import { BaseBoxProps, BaseBoxPropsSchema } from "./BaseBoxProps";
3
3
 
4
4
  export type ImageElementProps = BaseBoxProps & {
5
5
  url: string;
6
+ /**
7
+ * `expression` enables `{{variable}}` interpolation in `url`, so ONE Image can
8
+ * serve a data-driven set instead of one duplicated subtree per case — e.g.
9
+ * `https://cdn.example.com/zodiac/{{zodiacSign}}.png` replaces 13 gated Images.
10
+ *
11
+ * References resolve to the variable's `value`, NOT its `label` (the inverse of
12
+ * `Text`, which is display copy). A URL segment is a machine identifier: for a
13
+ * variable carrying `{ value: "aries", label: "Aries" }` the URL needs `aries`.
14
+ * An unknown variable interpolates to the empty string, so authors should keep
15
+ * a fallback path segment or a `renderWhen` guard around the element.
16
+ *
17
+ * Defaults to `"plain"` — no interpolation, and the element stays fully static
18
+ * (it does not subscribe to variable writes).
19
+ */
20
+ mode?: "plain" | "expression";
6
21
  aspectRatio?: number;
7
22
  resizeMode?: "cover" | "contain" | "stretch" | "center";
8
23
  /** Uniform Gaussian blur radius (px). 0/undefined = sharp. Ignored for SVGs. */
@@ -11,6 +26,7 @@ export type ImageElementProps = BaseBoxProps & {
11
26
 
12
27
  export const ImageElementPropsSchema = BaseBoxPropsSchema.extend({
13
28
  url: z.string().min(1, "url must not be empty"),
29
+ mode: z.enum(["plain", "expression"]).optional(),
14
30
  aspectRatio: z.number().optional(),
15
31
  resizeMode: z.enum(["cover", "contain", "stretch", "center"]).optional(),
16
32
  blurRadius: z.number().min(0).optional(),
@@ -0,0 +1,80 @@
1
+ import { z } from "zod";
2
+
3
+ /**
4
+ * Materializes its `children` (the template) once per row of `data`.
5
+ *
6
+ * Solves the duplicated-subtree problem: a screen with one card design and six
7
+ * cards, or one reveal design and thirteen zodiac signs, otherwise needs the
8
+ * subtree copy-pasted N times, and every copy or style change becomes an N-fold
9
+ * edit. That duplication has already produced real drift in shipped screens.
10
+ *
11
+ * **Repeat plus a per-row gate is a switch**, so there is no separate `Match`
12
+ * element: give the template's root a `renderWhen` of
13
+ * `{ variable: "item.sign", operator: "eq", value: "{{zodiacSign}}" }`-style
14
+ * shape and exactly one row renders. Iterate-and-show-all and
15
+ * iterate-and-show-one are the same primitive.
16
+ *
17
+ * ## Scope
18
+ *
19
+ * Each row's fields are exposed to that row's subtree under the `as` prefix
20
+ * (default `item`), so `{{item.title}}` interpolates and
21
+ * `{ variable: "item.sign", ... }` gates. `item.index` is always present.
22
+ *
23
+ * The scope reaches BOTH render-time reads (`{{var}}` interpolation,
24
+ * `renderWhen`) and press-time reads (a `setVariable` action with
25
+ * `valueMode: "expression"` referencing `{{item.id}}`), which is what lets a
26
+ * repeated card write its own row's value when tapped. Without the press-time
27
+ * half a repeated grid could be drawn but not answered.
28
+ *
29
+ * Scoped values are READ-ONLY. Nothing writes back into a row; an interactive
30
+ * child still writes to the ordinary variable store, and because the template is
31
+ * shared, every row's child writes the SAME variable name. That is usually what
32
+ * you want for single-select (the row distinguishes itself through the *value*
33
+ * it writes, not the variable it writes to).
34
+ *
35
+ * ## Data lives in the payload
36
+ *
37
+ * `data` is authored in the step, not sourced from a variable holding JSON. That
38
+ * is deliberate: it keeps copy and asset URLs in the studio where designers and
39
+ * the translation pipeline are. Rows sourced from the app would move product copy
40
+ * into the binary, where a typo fix needs a store release and i18n never sees it.
41
+ *
42
+ * For the same reason, a translatable string in a row carries its own literal
43
+ * i18n key (`{ sign: "aries", titleKey: "zodiac_aries_title" }`) rather than a
44
+ * derived one. Key coverage is computed by scanning payloads for *literal* key
45
+ * strings, so a computed key (`"zodiac_{{item.sign}}_title"`) would make the
46
+ * scanner find nothing, report the screen fully translated, and ship untranslated
47
+ * rows. Literal keys per row keep that machinery working untouched.
48
+ *
49
+ * ## Layout
50
+ *
51
+ * Repeat renders no view of its own — the materialized rows become direct
52
+ * children of whatever contains the Repeat, so the parent's `gap`, direction and
53
+ * alignment apply per row exactly as if the rows had been hand-written. Put a
54
+ * Repeat inside a `YStack`/`XStack`/`ZStack` and lay the rows out there.
55
+ *
56
+ * This is why the props below do NOT extend `BaseBoxProps`: with no view to style,
57
+ * box props would silently do nothing.
58
+ */
59
+ export type RepeatElementProps = {
60
+ /**
61
+ * One record per materialization. Flat scalars only — nested objects are not
62
+ * addressable by `{{item.x}}` and are rejected.
63
+ */
64
+ data: Array<Record<string, string | number | boolean>>;
65
+ /** Prefix the row's fields are exposed under. Default `"item"`. */
66
+ as?: string;
67
+ /**
68
+ * Row field used to build each materialized element's id suffix and React key
69
+ * (`card` → `card__aries`). Falls back to the row index when unset or missing.
70
+ * Prefer setting it: ids stay meaningful in diagnostics, and identity survives
71
+ * a reordering of `data`.
72
+ */
73
+ keyField?: string;
74
+ };
75
+
76
+ export const RepeatElementPropsSchema = z.object({
77
+ data: z.array(z.record(z.string(), z.union([z.string(), z.number(), z.boolean()]))),
78
+ as: z.string().min(1).optional(),
79
+ keyField: z.string().min(1).optional(),
80
+ });
@@ -56,6 +56,24 @@ export type TypewriterTextElementProps = BaseBoxProps & {
56
56
  cursor?: boolean;
57
57
  /** Caret glyph when `cursor` is on. Default "|". */
58
58
  cursorChar?: string;
59
+ /**
60
+ * Reserve the fully-revealed text's layout box up front, so the element never
61
+ * grows as it reveals and never pushes its siblings down.
62
+ *
63
+ * Only meaningful with `cursor: true`. Without a cursor every character is
64
+ * already mounted from frame 0 and only its opacity/transform animates, so the
65
+ * box is stable and this is a no-op. With `cursor` the characters mount
66
+ * progressively, so an unreserved block grows 1 → 2 → 3 lines mid-reveal and
67
+ * shoves everything below it down the screen.
68
+ *
69
+ * Implemented by laying out the fully resolved string invisibly to establish the
70
+ * box, then overlaying the animating characters on top of it. Because the
71
+ * reservation measures the REAL resolved string, it stays correct per locale —
72
+ * a hardcoded wrapper height is what breaks when e.g. `fr` runs 15-20% longer.
73
+ *
74
+ * Default false (unchanged behaviour).
75
+ */
76
+ reserveSpace?: boolean;
59
77
  fontSize?: number;
60
78
  fontWeight?: string;
61
79
  /**
@@ -83,6 +101,7 @@ export const TypewriterTextElementPropsSchema = BaseBoxPropsSchema.extend({
83
101
  loopDelay: z.number().min(0).optional(),
84
102
  cursor: z.boolean().optional(),
85
103
  cursorChar: z.string().optional(),
104
+ reserveSpace: z.boolean().optional(),
86
105
  fontSize: z.number().optional(),
87
106
  fontWeight: z.string().optional(),
88
107
  fontFamily: z.string().optional(),