@rocapine/react-native-onboarding 1.75.0 → 1.76.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 (87) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +16 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/onboarding-example.d.ts +140 -0
  6. package/dist/onboarding-example.d.ts.map +1 -1
  7. package/dist/onboarding-example.js +41 -1
  8. package/dist/onboarding-example.js.map +1 -1
  9. package/dist/paywalls/PaywallProvider.d.ts +71 -5
  10. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  11. package/dist/paywalls/PaywallProvider.js +237 -57
  12. package/dist/paywalls/PaywallProvider.js.map +1 -1
  13. package/dist/paywalls/customScreens.d.ts +31 -0
  14. package/dist/paywalls/customScreens.d.ts.map +1 -1
  15. package/dist/paywalls/observer.d.ts +129 -0
  16. package/dist/paywalls/observer.d.ts.map +1 -0
  17. package/dist/paywalls/observer.js +211 -0
  18. package/dist/paywalls/observer.js.map +1 -0
  19. package/dist/paywalls/present.d.ts +19 -15
  20. package/dist/paywalls/present.d.ts.map +1 -1
  21. package/dist/paywalls/present.js +21 -17
  22. package/dist/paywalls/present.js.map +1 -1
  23. package/dist/paywalls/types.d.ts +3 -1
  24. package/dist/paywalls/types.d.ts.map +1 -1
  25. package/dist/products/adapters/expoIap.d.ts +38 -1
  26. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  27. package/dist/products/adapters/expoIap.js +509 -75
  28. package/dist/products/adapters/expoIap.js.map +1 -1
  29. package/dist/products/index.d.ts +1 -0
  30. package/dist/products/index.d.ts.map +1 -1
  31. package/dist/products/index.js.map +1 -1
  32. package/dist/products/types.d.ts +13 -0
  33. package/dist/products/types.d.ts.map +1 -1
  34. package/dist/screens/completingActions.d.ts +55 -3
  35. package/dist/screens/completingActions.d.ts.map +1 -1
  36. package/dist/screens/completingActions.js +209 -15
  37. package/dist/screens/completingActions.js.map +1 -1
  38. package/dist/screens/elementTypeRegistry.d.ts +14 -0
  39. package/dist/screens/elementTypeRegistry.d.ts.map +1 -1
  40. package/dist/screens/elementTypeRegistry.js +38 -1
  41. package/dist/screens/elementTypeRegistry.js.map +1 -1
  42. package/dist/screens/elements/ButtonElement.d.ts +3 -2
  43. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  44. package/dist/screens/elements/ButtonElement.js +5 -1
  45. package/dist/screens/elements/ButtonElement.js.map +1 -1
  46. package/dist/screens/types.d.ts +2 -2
  47. package/dist/screens/types.d.ts.map +1 -1
  48. package/dist/screens/types.js +5 -1
  49. package/dist/screens/types.js.map +1 -1
  50. package/dist/screens/unknownKeys.d.ts +25 -4
  51. package/dist/screens/unknownKeys.d.ts.map +1 -1
  52. package/dist/screens/unknownKeys.js +81 -2
  53. package/dist/screens/unknownKeys.js.map +1 -1
  54. package/dist/steps/common.types.d.ts +178 -6
  55. package/dist/steps/common.types.d.ts.map +1 -1
  56. package/dist/steps/common.types.js +64 -3
  57. package/dist/steps/common.types.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/__tests__/authoringDocEscapes.test.ts +59 -0
  60. package/src/__tests__/completingActions.test.ts +371 -1
  61. package/src/__tests__/customActionHooks.test.ts +224 -0
  62. package/src/__tests__/onboardingExampleElements.test.ts +47 -0
  63. package/src/__tests__/requestPermissionAction.test.ts +138 -0
  64. package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
  65. package/src/__tests__/unknownKeys.test.ts +110 -0
  66. package/src/index.ts +33 -1
  67. package/src/onboarding-example.ts +41 -1
  68. package/src/paywalls/PaywallProvider.tsx +370 -66
  69. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
  70. package/src/paywalls/__tests__/observer.test.ts +401 -0
  71. package/src/paywalls/__tests__/present.test.ts +0 -18
  72. package/src/paywalls/customScreens.ts +34 -1
  73. package/src/paywalls/observer.ts +308 -0
  74. package/src/paywalls/present.ts +24 -18
  75. package/src/paywalls/types.ts +3 -1
  76. package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
  77. package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
  78. package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
  79. package/src/products/adapters/expoIap.ts +609 -78
  80. package/src/products/index.ts +1 -0
  81. package/src/products/types.ts +13 -0
  82. package/src/screens/completingActions.ts +223 -15
  83. package/src/screens/elementTypeRegistry.ts +34 -0
  84. package/src/screens/elements/ButtonElement.ts +9 -1
  85. package/src/screens/types.ts +2 -2
  86. package/src/screens/unknownKeys.ts +113 -7
  87. package/src/steps/common.types.ts +213 -6
@@ -20,5 +20,6 @@ export { ProductRuntimeContext, useProductRuntime } from "./ProductRuntimeContex
20
20
  export { stubProductProvider } from "./adapters/stub";
21
21
  export { revenueCatProductProvider } from "./adapters/revenueCat";
22
22
  export { expoIapProductProvider } from "./adapters/expoIap";
23
+ export type { ExpoIapProviderOptions, ExpoIapProvider } from "./adapters/expoIap";
23
24
  export { stripeLinkProductProvider } from "./adapters/stripeLink";
24
25
  export type { StripeLinkProviderConfig } from "./adapters/stripeLink";
@@ -122,4 +122,17 @@ export type ProductRuntime = {
122
122
  purchasing: boolean;
123
123
  purchase: (key: string) => Promise<PurchaseResult>;
124
124
  restore: () => Promise<RestoreResult>;
125
+ /**
126
+ * `true` once the paywall presentation this runtime was published for has
127
+ * left the screen. Only `PaywallProvider` sets it, on the runtime it
128
+ * publishes while a `present()` paywall is showing; absent everywhere else,
129
+ * which means "never ended".
130
+ *
131
+ * A `purchase` through an ended runtime is refused: the store is not opened
132
+ * and it resolves `{ status: "cancelled" }`. The action engine checks this
133
+ * BEFORE calling `purchase` and ends the whole action chain instead, so a
134
+ * paywall's stale chain runs none of `onSuccess`/`onCancel`/`onError`/
135
+ * `onPending` and no action after it.
136
+ */
137
+ presentationEnded?: () => boolean;
125
138
  };
@@ -19,9 +19,13 @@
19
19
  *
20
20
  * WHAT COUNTS. `runActions` calls `onContinue` for exactly two actions —
21
21
  * `"continue"` and `{type:"dismiss"}` — so those two, wherever a press can
22
- * reach them, are the whole definition. Everything else (`setVariable`,
23
- * `presentPaywall`, `custom`) leaves the user on the screen as far as this SDK
24
- * can tell, and is not counted.
22
+ * reach them, are the whole definition. Two exceptions to "wherever":
23
+ * `requestPermission` and `custom` are read with AND across their outcome hooks
24
+ * rather than OR (see `permissionAskCompletes` and `customActionEscapes`),
25
+ * because neither a grant nor a backend's answer is the user's to give — a
26
+ * `"continue"` sitting only in `onGranted`/`onResolve` strands everyone on the
27
+ * other branch. Everything else (`setVariable`, `presentPaywall`) leaves the
28
+ * user on the screen as far as this SDK can tell, and is not counted.
25
29
  *
26
30
  * The walk deliberately errs toward "no": an unrecognised action shape, or a
27
31
  * `continue` somewhere the runtime would not actually run it, reads as no way
@@ -58,21 +62,172 @@ const PRESS_HANDLED_TYPES: ReadonlySet<string> = new Set([
58
62
  ]);
59
63
 
60
64
  /**
61
- * One action, or any action nested in one of its branch lists
62
- * (`purchase.onSuccess`, `restore.onNothingToRestore`, …), completes the screen.
65
+ * WHICH completing action a press can reach, not just whether it can reach one.
66
+ *
67
+ * `runActions` needs the kind, not the boolean: when it stands in for an ask
68
+ * whose module is missing it has to call `complete` the way the AUTHOR'S OWN
69
+ * escape would have (review round 2, finding 1 — a bare `onContinue()` walked
70
+ * the user through a hard paywall gate that the authored `{dismiss}` would have
71
+ * held shut). One walk answers both questions, so the two cannot disagree.
72
+ */
73
+ export type EscapeAction = "continue" | "dismiss";
74
+
75
+ const union = (...sets: ReadonlySet<EscapeAction>[]): Set<EscapeAction> => {
76
+ const out = new Set<EscapeAction>();
77
+ for (const s of sets) for (const v of s) out.add(v);
78
+ return out;
79
+ };
80
+
81
+ /**
82
+ * Every completing action reachable through one list — directly, or nested in
83
+ * one of an action's branch lists (`purchase.onSuccess`,
84
+ * `restore.onNothingToRestore`, …).
63
85
  *
64
86
  * Branch lists are found by shape rather than by name, so a branch added to
65
87
  * `purchase`/`restore` later is covered without a change here.
66
88
  */
67
- const isCompletingAction = (action: unknown): boolean => {
89
+ const listEscapes = (value: unknown): Set<EscapeAction> => {
90
+ if (!Array.isArray(value)) return new Set<EscapeAction>();
91
+ const before = new Set<EscapeAction>();
92
+ for (let i = 0; i < value.length; i++) {
93
+ const action = value[i];
94
+ // `custom` is a BARRIER, not just another item: it is the one action whose
95
+ // OWN escape has to be read with AND (see `customActionEscapes`), and the
96
+ // actions after it are reachable on each of its paths, so they belong to
97
+ // both terms of that conjunction rather than being counted on their own.
98
+ // They are handed on as `rest`.
99
+ //
100
+ // Everything BEFORE the barrier keeps the plain OR reading, for a different
101
+ // reason: a completing action there returns from `runActions` before the
102
+ // handler is ever called, so it does not depend on the handler's outcome.
103
+ if (isRecord(action) && action.type === "custom") {
104
+ return union(before, customActionEscapes(action, value.slice(i + 1)));
105
+ }
106
+ for (const escape of actionEscapes(action)) before.add(escape);
107
+ }
108
+ return before;
109
+ };
110
+
111
+ const listCompletes = (value: unknown): boolean => listEscapes(value).size > 0;
112
+
113
+ /**
114
+ * `requestPermission` is the one action read with AND rather than OR, because
115
+ * its outcome is not the user's to choose.
116
+ *
117
+ * `runActions` has exactly three paths: a grant runs `onGranted`, a refusal
118
+ * runs `onDenied`, and "this build cannot ask" runs `onUnavailable` when
119
+ * declared. All of them have to reach a `"continue"` / `{dismiss}` for the ask
120
+ * to be a way OFF the screen — a CTA whose only `"continue"` sits in
121
+ * `onGranted` strands everyone who refuses.
122
+ *
123
+ * The third path is the one the runtime rescues by itself: with no
124
+ * `onUnavailable` declared it completes the screen rather than running
125
+ * `onDenied` (review round 1 of #196 — the old fallback recorded a refusal the
126
+ * user was never asked for, and rescued nobody when `onDenied` was absent too).
127
+ * So a declared-but-dead `onUnavailable` still reads as a trap here, while its
128
+ * ABSENCE no longer does.
129
+ *
130
+ * `purchase` / `restore` keep the generic OR reading on purpose: a cancelled
131
+ * purchase leaves the user free to press again, whereas a standing OS denial is
132
+ * final for the life of the install. Not symmetric, so not shared.
133
+ *
134
+ * Mirrors the runtime's own shape (`runActions.ts` — `onUnavailable` present but
135
+ * empty runs nothing, exactly as an empty array does here).
136
+ */
137
+ const permissionAskEscapes = (
138
+ action: Record<string, unknown>
139
+ ): Set<EscapeAction> => {
140
+ const onGranted = listEscapes(action.onGranted);
141
+ const onDenied = listEscapes(action.onDenied);
142
+ // Absent `onUnavailable`: the runtime completes the screen itself iff the
143
+ // author put a completing action somewhere in the ask — the same
144
+ // `actionsCanComplete(onGranted) || actionsCanComplete(onDenied)` test
145
+ // `runActions` runs. Written out rather than folded into the conjunction
146
+ // below, so this stays readable as the runtime's three paths.
147
+ const onUnavailable = action.onUnavailable
148
+ ? listEscapes(action.onUnavailable)
149
+ : union(onGranted, onDenied);
150
+ if (!onGranted.size || !onDenied.size || !onUnavailable.size)
151
+ return new Set<EscapeAction>();
152
+ return union(onGranted, onDenied, onUnavailable);
153
+ };
154
+
155
+ const permissionAskCompletes = (action: Record<string, unknown>): boolean =>
156
+ permissionAskEscapes(action).size > 0;
157
+
158
+ /**
159
+ * `custom` is the second AND-read action, for the same reason (#191, review
160
+ * round 1, finding 6): its outcome is the service's, not the user's.
161
+ *
162
+ * RE-DERIVED from the semantics decision of 2026-09-11 (recorded on #191, and
163
+ * the subject of #266), which removed the abort a thrown handler used to
164
+ * perform. `runActions` now has exactly TWO paths, and `rest` — whatever
165
+ * follows the action in the same list — is reachable from both:
166
+ *
167
+ * - the handler RESOLVES: `onResolve` runs, then `rest`;
168
+ * - the handler FAILS: `onError` runs, then `rest`. One rule for every way of
169
+ * failing — a throw with every retry spent, an attempt that never settled
170
+ * (`retry.timeoutMs`), and a `function` name the host never registered.
171
+ *
172
+ * So the escape set is `onResolve ∪ rest` AND `onError ∪ rest`, both non-empty.
173
+ *
174
+ * THE CONJUNCTION IS NOW COMPLETE, and that is the whole change here. The same
175
+ * two terms used to be a JUDGEMENT: there was a third path (throw → `onError`
176
+ * → abort, `rest` unreachable) that was deliberately left out of the
177
+ * conjunction, on the argument that a throw is the one outcome a user can talk
178
+ * out of by pressing again — the reading `purchase`/`restore` get. That
179
+ * argument was load-bearing and is now moot: the third path does not exist, so
180
+ * nothing is being excluded and no retryability argument is needed to justify
181
+ * the answer.
182
+ *
183
+ * WHAT THAT RESCUES. `[{custom}, "continue"]` — the shape an author writes when
184
+ * the CTA fires a handler and then moves on, and the ONLY `custom` shape Studio
185
+ * can author until `rocapine/onboarding-studio#288` lands — is a way off the
186
+ * screen on EVERY path, not on two of three. Round 2 of this PR required
187
+ * `onError` there and so read every such payload in the field as a trap,
188
+ * bolting a duplicate escape CTA onto any screen that had also been stripped
189
+ * (#209) plus a `console.error` naming a trap that was not one. Pinned by
190
+ * `onboarding-ui/src/UI/Runtime/__tests__/mergeBaseEscapeParity.test.ts`, which
191
+ * runs verbatim against this PR's merge base, and by
192
+ * `onboarding-ui/src/UI/Runtime/__tests__/customActionEscapeCoherence.test.ts`,
193
+ * which runs this walk and `runActions` against the same payloads and requires
194
+ * them to agree — the check that was missing while the two disagreed.
195
+ *
196
+ * What round 1, finding 6 established SURVIVES, and the decision does not touch
197
+ * it: a `"continue"` in `onResolve` alone is still not a way off the screen,
198
+ * because the failure path is then empty — and `customActions: {}` is
199
+ * `ScreenHost`'s own default, so that is not a hypothetical host. (#266 costed
200
+ * this decision as "reverts to the generic OR walk"; it does not. OR would
201
+ * credit that `onResolve` and re-open finding 6. What the decision removes is
202
+ * the third term, which was never in the code.)
203
+ *
204
+ * WHY `rest` STILL GOES THROUGH BOTH TERMS rather than being OR-ed on its own:
205
+ * the two readings agree on the boolean, but not on WHICH escape is reachable,
206
+ * and `completingActionKind` spends that answer. With `onResolve: [{dismiss}]`,
207
+ * no `onError` and a trailing `"continue"`, OR-ing `rest` separately loses the
208
+ * reachable `{dismiss}` and the runtime would substitute the more permissive
209
+ * advance — the review-round-2 finding-1 bug, one level down.
210
+ */
211
+ const customActionEscapes = (
212
+ action: Record<string, unknown>,
213
+ rest: readonly unknown[] = []
214
+ ): Set<EscapeAction> => {
215
+ const afterwards = listEscapes(rest);
216
+ const resolved = union(listEscapes(action.onResolve), afterwards);
217
+ const failed = union(listEscapes(action.onError), afterwards);
218
+ if (!resolved.size || !failed.size) return new Set<EscapeAction>();
219
+ return union(resolved, failed);
220
+ };
221
+
222
+ const actionEscapes = (action: unknown): Set<EscapeAction> => {
68
223
  // `ButtonActionSchema` declares continue as the string literal, not an
69
224
  // object: `{type:"continue"}` is not an action the runtime runs.
70
- if (action === "continue") return true;
71
- if (!isRecord(action)) return false;
72
- if (action.type === "dismiss") return true;
73
- return Object.values(action).some(
74
- (value) => Array.isArray(value) && value.some(isCompletingAction)
75
- );
225
+ if (action === "continue") return new Set<EscapeAction>(["continue"]);
226
+ if (!isRecord(action)) return new Set<EscapeAction>();
227
+ if (action.type === "dismiss") return new Set<EscapeAction>(["dismiss"]);
228
+ if (action.type === "requestPermission") return permissionAskEscapes(action);
229
+ if (action.type === "custom") return customActionEscapes(action);
230
+ return union(...Object.values(action).map(listEscapes));
76
231
  };
77
232
 
78
233
  const nodeCanComplete = (node: unknown): boolean => {
@@ -82,14 +237,20 @@ const nodeCanComplete = (node: unknown): boolean => {
82
237
  if (props.actions != null) {
83
238
  // `Button` reads `actions ?? (action === "continue" ? …)`, so a present
84
239
  // `actions` shadows the deprecated shorthand — even when it is empty.
85
- if (Array.isArray(props.actions) && props.actions.some(isCompletingAction)) return true;
240
+ //
241
+ // Read as ONE list, not action-by-action: order matters, because an
242
+ // action BEFORE a `custom` runs whatever the handler does, while one
243
+ // AFTER it has to satisfy both terms of that action's conjunction.
244
+ // `.some(isCompletingAction)` could express neither, and credited a
245
+ // `"continue"` inside an `onResolve` hook it never looked at the
246
+ // reachability of at all.
247
+ if (listCompletes(props.actions)) return true;
86
248
  } else if (props.action === "continue") {
87
249
  return true;
88
250
  }
89
251
  if (
90
- Array.isArray(props.onPress) &&
91
252
  !PRESS_HANDLED_TYPES.has(String(node.type)) &&
92
- props.onPress.some(isCompletingAction)
253
+ listCompletes(props.onPress)
93
254
  ) {
94
255
  return true;
95
256
  }
@@ -106,3 +267,50 @@ const nodeCanComplete = (node: unknown): boolean => {
106
267
  */
107
268
  export const hasCompletingAction = (elements: unknown): boolean =>
108
269
  Array.isArray(elements) && elements.some(nodeCanComplete);
270
+
271
+ /**
272
+ * The same walk over ONE action list rather than a whole element tree.
273
+ *
274
+ * Exists for the runtime, which needs the question answered at press time and
275
+ * had been deciding it by hand: `runActions` reaches "the build cannot ask for
276
+ * this permission and the author declared no `onUnavailable`" and has to choose
277
+ * between logging and moving on, and stranding the user. Whether the press was
278
+ * the screen's only way forward is exactly what this module already knows, so
279
+ * the runtime consults it instead of re-deriving it (review round 1, finding 1).
280
+ *
281
+ * OR across the list — "did the author intend this press to move the user on" —
282
+ * not `permissionAskCompletes`' AND across one ask's outcomes, which answers the
283
+ * stricter "does EVERY outcome move them on". Total on junk for the same reason
284
+ * `hasCompletingAction` is.
285
+ */
286
+ export const actionsCanComplete = (actions: unknown): boolean => listCompletes(actions);
287
+
288
+ /**
289
+ * WHICH completing action stands in for a press list — the kind, where
290
+ * `actionsCanComplete` gives only the yes/no.
291
+ *
292
+ * `"dismiss"` wins when the list can reach both, and that preference is the
293
+ * whole reason this exists (review round 2, finding 1). The runtime calls it
294
+ * for one case: a `requestPermission` on a build that cannot ask, with no
295
+ * `onUnavailable` declared. Nobody was asked anything, so the SDK must not
296
+ * claim the more permissive of the two answers the author authored — and the
297
+ * two are not equivalent downstream. `complete()` with no outcome is what
298
+ * `Pages/Paywall/Renderer`'s hard gate reads as "advance"
299
+ * (`shouldAdvanceOnComplete(undefined) === true`), so substituting it for an
300
+ * authored `{dismiss}` handed out paid content to a user who never purchased.
301
+ * `{status:"dismissed"}` is ignored by an onboarding step (it still advances)
302
+ * and resolves a `present()`ed paywall, so preferring it costs nothing on the
303
+ * surfaces where both outcomes mean the same thing, and holds the gate on the
304
+ * one where they do not.
305
+ *
306
+ * `undefined` = this list was never a way off the screen; the runtime then
307
+ * leaves the user where they are rather than inventing an exit.
308
+ */
309
+ export const completingActionKind = (
310
+ actions: unknown
311
+ ): EscapeAction | undefined => {
312
+ const escapes = listEscapes(actions);
313
+ if (escapes.has("dismiss")) return "dismiss";
314
+ if (escapes.has("continue")) return "continue";
315
+ return undefined;
316
+ };
@@ -62,6 +62,40 @@ const buildElementRegistry = (schema: unknown): Map<string, ElementKeySets> => {
62
62
  return built;
63
63
  };
64
64
 
65
+ /**
66
+ * The same union reading, one level shallower: a `type`-discriminated union's
67
+ * variant name → the key set that variant declares.
68
+ *
69
+ * Serves the `ButtonAction` union (`unknownKeys.ts`, so a misspelled
70
+ * `purchase.onSucces` / `requestPermission.onDeneid` can be reported rather
71
+ * than silently stripped). It lives beside the element derivation because this
72
+ * file is the one place that knows how to read zod's internals — duplicating
73
+ * `zdef` would give us two things to fix the next time they move.
74
+ *
75
+ * EMPTY means "could not tell", and every caller must read it that way: this
76
+ * only ever feeds diagnostics, never a reject.
77
+ */
78
+ export const deriveVariantKeySets = (schema: unknown): Map<string, ReadonlySet<string>> => {
79
+ const built = new Map<string, ReadonlySet<string>>();
80
+ try {
81
+ const lazyDef = zdef(schema);
82
+ const union = typeof lazyDef?.getter === "function" ? lazyDef.getter() : schema;
83
+ for (const option of zdef(union)?.options ?? []) {
84
+ const optionDef = zdef(option);
85
+ // A union member may itself be lazy (the recursive action variants are).
86
+ const resolved =
87
+ typeof optionDef?.getter === "function" ? optionDef.getter() : option;
88
+ const shape = zdef(resolved)?.shape;
89
+ if (!shape) continue;
90
+ const keys = new Set(Object.keys(shape));
91
+ for (const name of literalsOf(shape.type)) built.set(name, keys);
92
+ }
93
+ } catch {
94
+ // fall through to whatever was built before the failure
95
+ }
96
+ return built;
97
+ };
98
+
65
99
  /**
66
100
  * Every element `type` a given element union declares. EMPTY means "could not
67
101
  * tell" — zod internals moved, or this is not an element union — and every
@@ -16,8 +16,15 @@ import {
16
16
  export {
17
17
  type CustomButtonAction,
18
18
  CustomButtonActionSchema,
19
+ type CustomActionRetry,
20
+ CustomActionRetrySchema,
19
21
  type SetVariableButtonAction,
20
22
  SetVariableButtonActionSchema,
23
+ type RequestPermissionButtonAction,
24
+ RequestPermissionButtonActionSchema,
25
+ type PermissionKind,
26
+ PermissionKindSchema,
27
+ PERMISSION_KINDS,
21
28
  } from "../../steps/common.types";
22
29
  export type { ButtonAction };
23
30
  export { ButtonActionSchema };
@@ -40,7 +47,8 @@ export type ButtonElementProps = BaseBoxProps & {
40
47
  label: string;
41
48
  /**
42
49
  * Ordered list of actions to run on press. Sequential, await async handlers,
43
- * abort on error, `"continue"` is terminal.
50
+ * `"continue"` is terminal. A failing action runs its own `onError` hook and
51
+ * the list carries on.
44
52
  */
45
53
  actions?: ButtonAction[];
46
54
  /**
@@ -72,8 +72,8 @@ export type { RiveElementProps } from "./elements/RiveElement";
72
72
  export type { IconElementProps } from "./elements/IconElement";
73
73
  export type { VideoElementProps } from "./elements/VideoElement";
74
74
  export type { InputElementProps } from "./elements/InputElement";
75
- export type { ButtonElementProps, ButtonAction, CustomButtonAction, SetVariableButtonAction } from "./elements/ButtonElement";
76
- export { ButtonActionSchema, CustomButtonActionSchema, SetVariableButtonActionSchema } from "./elements/ButtonElement";
75
+ export type { ButtonElementProps, ButtonAction, CustomButtonAction, CustomActionRetry, SetVariableButtonAction, RequestPermissionButtonAction, PermissionKind } from "./elements/ButtonElement";
76
+ export { ButtonActionSchema, CustomButtonActionSchema, CustomActionRetrySchema, SetVariableButtonActionSchema, RequestPermissionButtonActionSchema, PermissionKindSchema, PERMISSION_KINDS } from "./elements/ButtonElement";
77
77
  export type { RadioGroupElementProps } from "./elements/RadioGroupElement";
78
78
  export type { CheckboxGroupElementProps } from "./elements/CheckboxGroupElement";
79
79
  export type { DatePickerElementProps } from "./elements/DatePickerElement";
@@ -1,8 +1,9 @@
1
- import { getElementRegistry } from "./elementTypeRegistry";
1
+ import { deriveVariantKeySets, getElementRegistry } from "./elementTypeRegistry";
2
+ import { ButtonActionSchema } from "../steps/common.types";
2
3
 
3
4
  /**
4
- * Detection for keys placed at an element's TOP LEVEL that the schema doesn't
5
- * know about.
5
+ * Detection for keys the schema doesn't know about — at an element's TOP LEVEL,
6
+ * and on any `ButtonAction` inside `props.actions` / `props.onPress`.
6
7
  *
7
8
  * Zod strips unrecognized keys instead of rejecting them, which makes a
8
9
  * misplaced prop completely silent: the element still parses, still renders, and
@@ -16,8 +17,14 @@ import { getElementRegistry } from "./elementTypeRegistry";
16
17
  * key into a hard parse failure, taking down whole screens to report a no-op —
17
18
  * strictly worse than the bug. So this reports; it never rejects.
18
19
  *
19
- * The allowed key sets are derived from `UIElementSchema` itself at runtime
20
- * rather than hardcoded, so they cannot drift as elements gain props.
20
+ * The allowed key sets are derived from `UIElementSchema` / `ButtonActionSchema`
21
+ * themselves at runtime rather than hardcoded, so they cannot drift as elements
22
+ * gain props or actions gain outcome hooks.
23
+ *
24
+ * The ACTION case (#196) has the same silence and a sharper edge: a misspelled
25
+ * `requestPermission.onDeneid` or `purchase.onSucces` parses clean and leaves an
26
+ * outcome hook that never runs — on a permission screen, a CTA the refusing user
27
+ * cannot get past. Same treatment: report, never reject.
21
28
  */
22
29
  export type UnknownElementKey = {
23
30
  /** Location in the tree, e.g. `elements[0].children[2]`. */
@@ -49,6 +56,21 @@ export type UnknownElementKey = {
49
56
  * disagree are a trap, and only the disagreement is worth alarming about.
50
57
  */
51
58
  conflicts?: boolean;
59
+ /**
60
+ * Where the key was found. `"element"` (the default) is a key on the element
61
+ * node itself; `"action"` is a key on a `ButtonAction` inside `props.actions`
62
+ * or `props.onPress`, whose `path` points at that action.
63
+ *
64
+ * Actions get their own scope because the two mistakes need different advice:
65
+ * a stray key on an element is usually a prop written one level too high,
66
+ * while a stray key on an action is a misspelled OUTCOME HOOK — a branch of
67
+ * the flow that will never run. `requestPermission.onDeneid` (#196) is the
68
+ * costly one: the payload validates, and the user who refuses the permission
69
+ * has no way off the screen.
70
+ */
71
+ scope?: "element" | "action";
72
+ /** `scope: "action"` only — the action's `type`, e.g. `"requestPermission"`. */
73
+ actionType?: string;
52
74
  };
53
75
 
54
76
  const isRecord = (v: unknown): v is Record<string, unknown> =>
@@ -67,6 +89,64 @@ const valuesDiffer = (a: unknown, b: unknown): boolean => {
67
89
  }
68
90
  };
69
91
 
92
+ /**
93
+ * Variant name → declared key set for the `ButtonAction` union, read off
94
+ * `ButtonActionSchema` itself so a hook added to an action later is covered
95
+ * without touching this file. Built once; EMPTY means "could not tell" and
96
+ * reports nothing, the same degradation the element registry makes.
97
+ */
98
+ let actionRegistry: Map<string, ReadonlySet<string>> | null = null;
99
+ const getActionRegistry = (): Map<string, ReadonlySet<string>> => {
100
+ if (!actionRegistry) actionRegistry = deriveVariantKeySets(ButtonActionSchema);
101
+ return actionRegistry;
102
+ };
103
+
104
+ /**
105
+ * Report unrecognized keys on every action in one list, recursing into the
106
+ * nested `ButtonAction[]` an outcome hook holds (`purchase.onSuccess`,
107
+ * `requestPermission.onGranted`, …) so a typo two levels down is still found.
108
+ *
109
+ * `"continue"` is a bare string, not an object, and an action whose `type` this
110
+ * build does not know is skipped — guessing its key set would be noise, exactly
111
+ * as for an unknown element type.
112
+ */
113
+ const visitActions = (
114
+ actions: unknown,
115
+ path: string,
116
+ element: Record<string, unknown>,
117
+ found: UnknownElementKey[]
118
+ ): void => {
119
+ if (!Array.isArray(actions)) return;
120
+ const known = getActionRegistry();
121
+ if (known.size === 0) return;
122
+
123
+ actions.forEach((action, index) => {
124
+ if (!isRecord(action)) return;
125
+ const actionPath = `${path}[${index}]`;
126
+ const allowed = typeof action.type === "string" ? known.get(action.type) : undefined;
127
+ if (allowed) {
128
+ for (const key of Object.keys(action)) {
129
+ if (allowed.has(key)) continue;
130
+ found.push({
131
+ path: actionPath,
132
+ elementId: typeof element.id === "string" ? element.id : "(no id)",
133
+ elementType: typeof element.type === "string" ? element.type : "(no type)",
134
+ key,
135
+ kind: "unknown",
136
+ scope: "action",
137
+ actionType: action.type as string,
138
+ });
139
+ }
140
+ }
141
+ // Recurse into every nested action list, found by SHAPE rather than by hook
142
+ // name — the same choice `completingActions.ts` makes, so a branch added to
143
+ // an action later needs no change here.
144
+ for (const [key, value] of Object.entries(action)) {
145
+ if (Array.isArray(value)) visitActions(value, `${actionPath}.${key}`, element, found);
146
+ }
147
+ });
148
+ };
149
+
70
150
  /**
71
151
  * Walk an element tree and report unrecognized top-level keys.
72
152
  *
@@ -111,6 +191,17 @@ export const collectUnknownElementKeys = (
111
191
  }
112
192
  }
113
193
 
194
+ // Action lists, on both the `Button`-specific `actions` and the generic
195
+ // `onPress` every element accepts. Walked even on an element type this build
196
+ // does not know: the ACTION union is this package's own, so its key sets are
197
+ // trustworthy regardless of what the element around them is.
198
+ const propsRecord = isRecord(node.props) ? node.props : undefined;
199
+ if (propsRecord) {
200
+ for (const listName of ["actions", "onPress"] as const) {
201
+ visitActions(propsRecord[listName], `${path}.props.${listName}`, node, found);
202
+ }
203
+ }
204
+
114
205
  // Recurse regardless of whether this node was recognized, so a stray key
115
206
  // nested under an unknown-typed parent is still found.
116
207
  if (Array.isArray(node.children)) {
@@ -154,14 +245,29 @@ export const formatUnknownElementKeys = (found: UnknownElementKey[]): string =>
154
245
  : ` • ${where}: "${f.key}" is ignored — ${f.suggestion} is already set to the ` +
155
246
  `same value and is the one taking effect. Delete this top-level copy.`;
156
247
  }
248
+ if (f.scope === "action") {
249
+ // No "did you mean" — the useful fact is that this names a BRANCH of the
250
+ // flow that the parse dropped, so it can never run.
251
+ return (
252
+ ` • ${f.path} (${f.actionType} action on ${f.elementType} "${f.elementId}"): ` +
253
+ `unrecognized key "${f.key}" — dropped when the payload is parsed, so if ` +
254
+ `this was meant to be an outcome hook, that branch never runs.`
255
+ );
256
+ }
157
257
  if (f.kind === "misplaced") {
158
258
  return ` • ${where}: "${f.key}" is not a top-level key — did you mean ${f.suggestion}?`;
159
259
  }
160
260
  return ` • ${where}: unrecognized top-level key "${f.key}"`;
161
261
  });
262
+ const scopeLabel =
263
+ found.every((f) => f.scope === "action")
264
+ ? "on button actions"
265
+ : found.some((f) => f.scope === "action")
266
+ ? "on elements and their actions"
267
+ : "on elements";
162
268
  return (
163
- `[onboarding] ${found.length} unrecognized top-level ` +
164
- `${found.length === 1 ? "key" : "keys"} on elements. These are silently ` +
269
+ `[onboarding] ${found.length} unrecognized ` +
270
+ `${found.length === 1 ? "key" : "keys"} ${scopeLabel}. These are silently ` +
165
271
  `dropped when the payload is parsed, so they have no effect:\n` +
166
272
  lines.join("\n")
167
273
  );