@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
@@ -0,0 +1,224 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { ButtonActionSchema, CustomButtonActionSchema } from "../steps/common.types";
3
+ import { hasCompletingAction } from "../screens/completingActions";
4
+
5
+ // RNO#191 — the declarative half of an async gate. `custom` gains the same
6
+ // nested-`ButtonAction[]` outcome hooks `purchase`/`restore` already carry,
7
+ // plus a bounded retry. These assert the HEADLESS schema (the one that
8
+ // validates the payload); the UI mirror is asserted in
9
+ // `packages/onboarding-ui/src/UI/Runtime/__tests__/runActions.test.ts`.
10
+
11
+ describe("CustomButtonAction schema — outcome hooks", () => {
12
+ // Asserting the PARSED OUTPUT, not just `success`: Zod strips unrecognized
13
+ // keys, so an unimplemented hook parses "successfully" and silently vanishes
14
+ // before it ever reaches `runActions`.
15
+ it("accepts onResolve and onError action lists and keeps them", () => {
16
+ const parsed = CustomButtonActionSchema.safeParse({
17
+ type: "custom",
18
+ function: "generatePlan",
19
+ variables: ["goal"],
20
+ onResolve: ["continue"],
21
+ onError: [{ type: "setVariable", name: "planError", value: "true" }],
22
+ });
23
+ expect(parsed.success).toBe(true);
24
+ expect((parsed as any).data.onResolve).toEqual(["continue"]);
25
+ expect((parsed as any).data.onError).toEqual([
26
+ { type: "setVariable", name: "planError", value: "true" },
27
+ ]);
28
+ });
29
+
30
+ it("accepts a nested custom action inside onError (recursion)", () => {
31
+ const parsed = CustomButtonActionSchema.safeParse({
32
+ type: "custom",
33
+ function: "generatePlan",
34
+ onError: [{ type: "custom", function: "reportFailure" }],
35
+ });
36
+ expect(parsed.success).toBe(true);
37
+ expect((parsed as any).data.onError[0].function).toBe("reportFailure");
38
+ });
39
+
40
+ it("still accepts the pre-#191 three-field shape", () => {
41
+ const parsed = CustomButtonActionSchema.safeParse({
42
+ type: "custom",
43
+ function: "generatePlan",
44
+ variables: ["goal"],
45
+ });
46
+ expect(parsed.success).toBe(true);
47
+ });
48
+
49
+ it("is reachable through the ButtonAction union with its hooks", () => {
50
+ const parsed = ButtonActionSchema.safeParse({
51
+ type: "custom",
52
+ function: "generatePlan",
53
+ onResolve: ["continue"],
54
+ });
55
+ expect(parsed.success).toBe(true);
56
+ expect((parsed as any).data.onResolve).toEqual(["continue"]);
57
+ });
58
+ });
59
+
60
+ describe("CustomButtonAction schema — bounded retry", () => {
61
+ it("accepts an explicit attempt cap", () => {
62
+ const parsed = CustomButtonActionSchema.safeParse({
63
+ type: "custom",
64
+ function: "generatePlan",
65
+ retry: { maxAttempts: 3, delayMs: 500 },
66
+ });
67
+ expect(parsed.success).toBe(true);
68
+ expect((parsed as any).data.retry).toEqual({ maxAttempts: 3, delayMs: 500 });
69
+ });
70
+
71
+ // The cap is what makes the retry BOUNDED — a payload that forgets it, or
72
+ // asks for an unbounded/absurd number of attempts, must fail at parse time
73
+ // rather than hang a screen behind a dead service.
74
+ it("rejects a retry with no attempt cap", () => {
75
+ const parsed = CustomButtonActionSchema.safeParse({
76
+ type: "custom",
77
+ function: "generatePlan",
78
+ retry: { delayMs: 500 },
79
+ });
80
+ expect(parsed.success).toBe(false);
81
+ });
82
+
83
+ it("rejects fewer than one attempt", () => {
84
+ const parsed = CustomButtonActionSchema.safeParse({
85
+ type: "custom",
86
+ function: "generatePlan",
87
+ retry: { maxAttempts: 0 },
88
+ });
89
+ expect(parsed.success).toBe(false);
90
+ });
91
+
92
+ it("rejects more attempts than the runtime will make", () => {
93
+ const parsed = CustomButtonActionSchema.safeParse({
94
+ type: "custom",
95
+ function: "generatePlan",
96
+ retry: { maxAttempts: 11 },
97
+ });
98
+ expect(parsed.success).toBe(false);
99
+ });
100
+
101
+ it("rejects a fractional attempt cap", () => {
102
+ const parsed = CustomButtonActionSchema.safeParse({
103
+ type: "custom",
104
+ function: "generatePlan",
105
+ retry: { maxAttempts: 2.5 },
106
+ });
107
+ expect(parsed.success).toBe(false);
108
+ });
109
+ });
110
+
111
+ // RNO#264 — `maxAttempts` bounds the NUMBER of attempts; nothing bounded ONE
112
+ // attempt's duration, so a handler whose promise never settles held the
113
+ // single-flight claim for the life of the screen and the documented
114
+ // `disabledWhen: actions.pending.<id>` payload greyed the CTA out permanently.
115
+ describe("CustomActionRetry schema — per-attempt timeoutMs (#264)", () => {
116
+ const retry = (retry: Record<string, unknown>) =>
117
+ CustomButtonActionSchema.safeParse({
118
+ type: "custom",
119
+ function: "generatePlan",
120
+ retry,
121
+ });
122
+
123
+ it("accepts a per-attempt timeout and keeps it", () => {
124
+ const parsed = retry({ maxAttempts: 3, delayMs: 400, timeoutMs: 15000 });
125
+ expect(parsed.success).toBe(true);
126
+ expect((parsed as any).data.retry).toEqual({
127
+ maxAttempts: 3,
128
+ delayMs: 400,
129
+ timeoutMs: 15000,
130
+ });
131
+ });
132
+
133
+ // A timeout without retries is the #264 repro itself — one attempt that never
134
+ // answers — so it must be authorable without pretending to want retries.
135
+ it("accepts a timeout on a single-attempt policy", () => {
136
+ const parsed = retry({ maxAttempts: 1, timeoutMs: 30000 });
137
+ expect(parsed.success).toBe(true);
138
+ expect((parsed as any).data.retry.timeoutMs).toBe(30000);
139
+ });
140
+
141
+ it("is optional — an absent timeout means unbounded, as before", () => {
142
+ const parsed = retry({ maxAttempts: 2 });
143
+ expect(parsed.success).toBe(true);
144
+ expect((parsed as any).data.retry.timeoutMs).toBeUndefined();
145
+ });
146
+
147
+ // A sub-second timeout cannot be met by any real network call, so it is a
148
+ // typo (milliseconds meant as seconds), not a policy.
149
+ it("rejects a timeout too short for any real handler", () => {
150
+ expect(retry({ maxAttempts: 1, timeoutMs: 0 }).success).toBe(false);
151
+ expect(retry({ maxAttempts: 1, timeoutMs: 250 }).success).toBe(false);
152
+ });
153
+
154
+ // Generous on purpose: a legitimate LLM call can take 60s+, and cutting one
155
+ // off would be a worse bug than the hang. Five minutes is the ceiling.
156
+ it("accepts a generous timeout and rejects one past the ceiling", () => {
157
+ expect(retry({ maxAttempts: 1, timeoutMs: 300000 }).success).toBe(true);
158
+ expect(retry({ maxAttempts: 1, timeoutMs: 300001 }).success).toBe(false);
159
+ });
160
+
161
+ it("rejects a non-numeric timeout", () => {
162
+ expect(retry({ maxAttempts: 1, timeoutMs: "5000" }).success).toBe(false);
163
+ });
164
+ });
165
+
166
+ describe("hasCompletingAction and a custom action's hooks (#209 guard)", () => {
167
+ // Round 1 asserted the opposite of this — that `onResolve: ["continue"]` alone
168
+ // makes the screen completable — and review round 1, finding 6 refuted it.
169
+ // The resolve path is not the user's to reach: `ScreenHost`'s default is
170
+ // `customActions: {}`, and an unregistered name runs `onError` and whatever
171
+ // follows the action, never `onResolve`. So a `"continue"` in `onResolve`
172
+ // alone is not a way off the screen. Read with AND across the outcomes, like
173
+ // `requestPermission` (`completingActions.ts` — `customActionEscapes`), over
174
+ // the action's two paths: the handler resolved, and the handler failed.
175
+ const cta = (actions: unknown[]) => [
176
+ { type: "Button", id: "cta", props: { label: "Generate", actions } },
177
+ ];
178
+
179
+ it("does not count a continue reachable only on the resolve path", () => {
180
+ expect(
181
+ hasCompletingAction(
182
+ cta([{ type: "custom", function: "generatePlan", onResolve: ["continue"] }])
183
+ )
184
+ ).toBe(false);
185
+ });
186
+
187
+ it("counts it when the error path also reaches a way off the screen", () => {
188
+ expect(
189
+ hasCompletingAction(
190
+ cta([
191
+ {
192
+ type: "custom",
193
+ function: "generatePlan",
194
+ onResolve: ["continue"],
195
+ onError: ["continue"],
196
+ },
197
+ ])
198
+ )
199
+ ).toBe(true);
200
+ });
201
+
202
+ it("counts a sibling continue after the custom action", () => {
203
+ // The trailing `"continue"` runs on both of the action's paths — handler
204
+ // resolved, and handler failed however it failed — so it IS the screen's
205
+ // way forward. It used to be reachable on only two of three paths, the
206
+ // throw path having aborted the list; the semantics decision of 2026-09-11
207
+ // removed that path, so this row no longer rests on a retryability
208
+ // argument.
209
+ //
210
+ // Round 2 of this PR required `onError` here, which read every
211
+ // `[{custom}, "continue"]` payload in the field as a trap: Studio's action
212
+ // editor cannot author `onResolve`/`onError` until
213
+ // `rocapine/onboarding-studio#288` lands, so the prescribed fix was not
214
+ // available to anyone the verdict applied to.
215
+ expect(
216
+ hasCompletingAction(cta([{ type: "custom", function: "generatePlan" }, "continue"]))
217
+ ).toBe(true);
218
+ expect(
219
+ hasCompletingAction(
220
+ cta([{ type: "custom", function: "generatePlan", onError: ["continue"] }, "continue"])
221
+ )
222
+ ).toBe(true);
223
+ });
224
+ });
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect } from "vitest";
2
2
  import { ScreenElementsSchema } from "../screens/types";
3
+ import { actionsCanComplete, hasCompletingAction } from "../screens/completingActions";
3
4
  import { onboardingExample } from "../onboarding-example";
4
5
 
5
6
  // The default onboarding is the payload every example app and the studio's
@@ -25,3 +26,49 @@ describe("onboarding-example ComposableScreen payloads", () => {
25
26
  });
26
27
  }
27
28
  });
29
+
30
+ /**
31
+ * The exported payload is also the documented `fallbackOnboarding`
32
+ * (`getting-started.mdx`), rendered by apps that pass no `customActions` at all
33
+ * — `ScreenHost`'s default is `{}`. So no step in it may depend on a registered
34
+ * handler for its way forward (review round 1, findings 1 and 7).
35
+ *
36
+ * Round 1 of #191 moved the hero button's only `"continue"` into the
37
+ * `onResolve` of a `{type:"custom", function:"trackCta"}` action. `trackCta` is
38
+ * registered nowhere in the SDK, so on the fallback path the primary CTA logged
39
+ * one line and did nothing: a step with no way off it.
40
+ */
41
+ describe("onboarding-example ComposableScreen steps stay navigable", () => {
42
+ const composableSteps = onboardingExample.steps.filter(
43
+ (s) => s.type === "ComposableScreen"
44
+ );
45
+
46
+ for (const step of composableSteps) {
47
+ it(`step "${step.name}" can be completed with no customActions registered`, () => {
48
+ expect(hasCompletingAction(step.payload?.elements)).toBe(true);
49
+ });
50
+ }
51
+
52
+ // Tree-wide is not enough for the PRIMARY CTA: the screen keeping SOME way
53
+ // forward elsewhere in the tree does not make a dead "Get Started" button
54
+ // acceptable. This asserts the button itself.
55
+ const findById = (nodes: unknown, id: string): any => {
56
+ if (!Array.isArray(nodes)) return undefined;
57
+ for (const node of nodes) {
58
+ if (node && typeof node === "object") {
59
+ const n = node as any;
60
+ if (n.id === id) return n;
61
+ const inner = findById(n.children, id);
62
+ if (inner) return inner;
63
+ }
64
+ }
65
+ return undefined;
66
+ };
67
+
68
+ it("the hero CTA advances on a host with no customActions", () => {
69
+ const step = composableSteps[0];
70
+ const hero = findById(step.payload?.elements, "hero-button");
71
+ expect(hero, "hero-button not found in the example payload").toBeTruthy();
72
+ expect(actionsCanComplete(hero.props.actions)).toBe(true);
73
+ });
74
+ });
@@ -0,0 +1,138 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ ButtonActionSchema,
4
+ PERMISSION_KINDS,
5
+ PermissionKindSchema,
6
+ } from "../steps/common.types";
7
+ import { UIElementSchema } from "../screens/types";
8
+
9
+ /**
10
+ * The headless half of the `requestPermission` ButtonAction (#196).
11
+ *
12
+ * The headless schema is what validates a published payload, so a variant that
13
+ * exists only in the UI mirror still throws `invalid_union` on parse — the
14
+ * failure mode CLAUDE.md's step 3 warns about. These tests pin the headless
15
+ * side: the eighth union member, its closed `kind` enum, and the fact that its
16
+ * three outcome hooks recurse through `ButtonActionSchema` the way
17
+ * `purchase`/`restore` do.
18
+ */
19
+
20
+ describe("PermissionKind", () => {
21
+ // Deliberately narrow: every kind here must be reachable through an
22
+ // optionally-installed Expo module the SDK can dynamic-`require` at press
23
+ // time. HealthKit and Screen Time / Family Controls need app-owned
24
+ // entitlements and a config plugin neither package ships, so they are NOT
25
+ // members — they arrive later behind the host `requestPermission` resolver.
26
+ it("is exactly the six kinds an Expo module can request", () => {
27
+ expect([...PERMISSION_KINDS]).toEqual([
28
+ "notifications",
29
+ "appTrackingTransparency",
30
+ "locationWhenInUse",
31
+ "camera",
32
+ "microphone",
33
+ "photoLibrary",
34
+ ]);
35
+ });
36
+
37
+ it("rejects a kind outside the enum", () => {
38
+ expect(PermissionKindSchema.safeParse("healthkit").success).toBe(false);
39
+ expect(PermissionKindSchema.safeParse("notification").success).toBe(false);
40
+ });
41
+ });
42
+
43
+ describe("ButtonActionSchema — requestPermission", () => {
44
+ it("accepts the minimal action (kind only)", () => {
45
+ const parsed = ButtonActionSchema.safeParse({
46
+ type: "requestPermission",
47
+ kind: "notifications",
48
+ });
49
+ expect(parsed.success).toBe(true);
50
+ });
51
+
52
+ it("accepts all three outcome hooks as nested ButtonAction lists", () => {
53
+ const parsed = ButtonActionSchema.safeParse({
54
+ type: "requestPermission",
55
+ kind: "notifications",
56
+ onGranted: [{ type: "setVariable", name: "push", value: "on" }, "continue"],
57
+ onDenied: ["continue"],
58
+ onUnavailable: [{ type: "dismiss" }],
59
+ });
60
+ expect(parsed.success).toBe(true);
61
+ });
62
+
63
+ it("accepts a requestPermission nested inside another action's hook", () => {
64
+ // Recursion through the same union is what makes ask-then-ask possible, and
65
+ // is the property `purchase.onSuccess` already relies on.
66
+ const parsed = ButtonActionSchema.safeParse({
67
+ type: "purchase",
68
+ product: "yearly",
69
+ onSuccess: [{ type: "requestPermission", kind: "notifications", onGranted: ["continue"] }],
70
+ });
71
+ expect(parsed.success).toBe(true);
72
+ });
73
+
74
+ it("rejects a missing kind", () => {
75
+ expect(
76
+ ButtonActionSchema.safeParse({ type: "requestPermission" }).success
77
+ ).toBe(false);
78
+ });
79
+
80
+ it("rejects an unknown kind", () => {
81
+ expect(
82
+ ButtonActionSchema.safeParse({ type: "requestPermission", kind: "healthkit" }).success
83
+ ).toBe(false);
84
+ });
85
+
86
+ it("rejects a non-array outcome hook", () => {
87
+ expect(
88
+ ButtonActionSchema.safeParse({
89
+ type: "requestPermission",
90
+ kind: "camera",
91
+ onGranted: "continue",
92
+ }).success
93
+ ).toBe(false);
94
+ });
95
+
96
+ it("rejects a garbage action inside an outcome hook", () => {
97
+ expect(
98
+ ButtonActionSchema.safeParse({
99
+ type: "requestPermission",
100
+ kind: "camera",
101
+ onGranted: [{ type: "notAnAction" }],
102
+ }).success
103
+ ).toBe(false);
104
+ });
105
+ });
106
+
107
+ describe("UIElement round-trip", () => {
108
+ it("parses a Button whose actions request a permission", () => {
109
+ const parsed = UIElementSchema.safeParse({
110
+ id: "cta",
111
+ type: "Button",
112
+ props: {
113
+ label: "Enable notifications",
114
+ actions: [
115
+ {
116
+ type: "requestPermission",
117
+ kind: "notifications",
118
+ onGranted: ["continue"],
119
+ onDenied: ["continue"],
120
+ },
121
+ ],
122
+ },
123
+ });
124
+ expect(parsed.success).toBe(true);
125
+ });
126
+
127
+ it("parses a generic onPress that requests a permission", () => {
128
+ const parsed = UIElementSchema.safeParse({
129
+ id: "card",
130
+ type: "YStack",
131
+ props: {
132
+ onPress: [{ type: "requestPermission", kind: "photoLibrary", onGranted: ["continue"] }],
133
+ },
134
+ children: [],
135
+ });
136
+ expect(parsed.success).toBe(true);
137
+ });
138
+ });
@@ -0,0 +1,57 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+
5
+ /**
6
+ * `retry` re-invokes the SAME host handler with the same press-time variables,
7
+ * up to ten times, and a timed-out attempt is an ordinary failed attempt — so a
8
+ * handler that POSTs is asked to POST again, including after an attempt that
9
+ * reached the server and lost only the ANSWER to the clock. Neither the schema,
10
+ * the runtime nor the console can tell a safe handler from an unsafe one, which
11
+ * leaves the prose as the only place the hazard can be stated — and until this
12
+ * test, `grep -i idempoten` over the retry docs returned nothing (review round 2
13
+ * of !263, finding 5).
14
+ *
15
+ * Declared rather than discovered, like `SURFACES` in
16
+ * `scripts/check-element-docs.mjs`: the `maxAttempts` assertion fails if a file
17
+ * stops teaching retry, so the list cannot quietly go stale in either
18
+ * direction. Deliberately NOT here: `Runtime/elements/runActions.ts` (the
19
+ * implementation, not an authoring surface) and the example payloads.
20
+ */
21
+ const RETRY_SURFACES = [
22
+ "packages/onboarding/src/steps/common.types.ts",
23
+ "packages/onboarding-ui/src/UI/Runtime/elements/actions.ts",
24
+ "website/docs/customization/custom-actions.mdx",
25
+ "website/docs/page-types.mdx",
26
+ "claude-plugin/skills/validate-step-json/SKILL.md",
27
+ "claude-plugin/skills/compose-screen-builder/SKILL.md",
28
+ "claude-plugin/agents/step-json-reviewer.md",
29
+ ];
30
+
31
+ const ROOT = join(__dirname, "../../../..");
32
+
33
+ /**
34
+ * The warning has to sit WITH the retry teaching, not merely somewhere in the
35
+ * file: `common.types.ts` already says "idempotent" ~280 lines away, about
36
+ * `requestPermission` and the OS's prompt, and a whole-file check passed on that
37
+ * sentence while the retry doc itself said nothing. So the region checked is the
38
+ * span of the file's `maxAttempts` mentions, widened by this much either side.
39
+ */
40
+ const REGION_MARGIN = 1500;
41
+
42
+ describe("retry docs — every surface that teaches `retry` warns it re-runs the handler", () => {
43
+ it.each(RETRY_SURFACES)("%s", (rel) => {
44
+ const src = readFileSync(join(ROOT, rel), "utf8");
45
+ const first = src.indexOf("maxAttempts");
46
+ expect(first, `${rel} no longer teaches retry — drop it from RETRY_SURFACES`).toBeGreaterThan(
47
+ -1
48
+ );
49
+ const region = src
50
+ .slice(Math.max(0, first - REGION_MARGIN), src.lastIndexOf("maxAttempts") + REGION_MARGIN)
51
+ .toLowerCase();
52
+ expect(
53
+ region,
54
+ `${rel} teaches retry without saying the handler must be idempotent`
55
+ ).toContain("idempot");
56
+ });
57
+ });
@@ -232,3 +232,113 @@ describe("formatUnknownElementKeys", () => {
232
232
  expect(msg).toContain("silently dropped");
233
233
  });
234
234
  });
235
+
236
+ /**
237
+ * Keys on an ACTION object, not on the element (#196, review round 1).
238
+ *
239
+ * `ButtonActionSchema` is a plain non-strict `z.object` union — deliberately, for
240
+ * the same reason the element schemas are (`unknownKeys.ts`'s header:
241
+ * `.strict()` would turn a published payload carrying a stray key into a dead
242
+ * screen). The price is that a misspelled outcome hook is completely silent:
243
+ * `{"type":"requestPermission","onGranted":["continue"],"onDeneid":["continue"]}`
244
+ * validates clean, the key is stripped, and the denial branch is dead — on a
245
+ * permission screen that is a CTA the refusing user cannot get past.
246
+ *
247
+ * So it is reported the same non-fatal way a misplaced `animation` is, through
248
+ * the `__DEV__` check `OnboardingProvider` already runs on every fetched
249
+ * payload. Key sets are derived from `ButtonActionSchema` itself, so they cover
250
+ * `purchase.onSucces` and every action added later with no change here.
251
+ */
252
+ describe("collectUnknownElementKeys — action keys", () => {
253
+ const withActions = (actions: unknown) => [
254
+ { id: "cta", type: "Button", props: { label: "Go", actions } },
255
+ ];
256
+
257
+ it("reports a misspelled requestPermission outcome hook", () => {
258
+ const found = collectUnknownElementKeys(
259
+ withActions([
260
+ { type: "requestPermission", kind: "notifications", onGranted: ["continue"], onDeneid: ["continue"] },
261
+ ])
262
+ );
263
+ expect(found).toHaveLength(1);
264
+ expect(found[0].key).toBe("onDeneid");
265
+ expect(found[0].scope).toBe("action");
266
+ expect(found[0].actionType).toBe("requestPermission");
267
+ expect(found[0].path).toBe("elements[0].props.actions[0]");
268
+ expect(found[0].elementId).toBe("cta");
269
+ });
270
+
271
+ it("reports a misspelled purchase hook — the derivation is not permission-specific", () => {
272
+ const found = collectUnknownElementKeys(
273
+ withActions([{ type: "purchase", product: "yearly", onSucces: ["continue"] }])
274
+ );
275
+ expect(found.map((f) => f.key)).toEqual(["onSucces"]);
276
+ });
277
+
278
+ it("says nothing about a correctly spelled action", () => {
279
+ expect(
280
+ collectUnknownElementKeys(
281
+ withActions([
282
+ "continue",
283
+ { type: "requestPermission", kind: "camera", onGranted: ["continue"], onDenied: ["continue"], onUnavailable: ["continue"] },
284
+ { type: "setVariable", name: "a", value: "b", valueMode: "expression", kind: "int", arrayOp: "toggle", label: "A" },
285
+ { type: "purchase", product: "yearly", onSuccess: ["continue"], onCancel: [], onError: [], onPending: [] },
286
+ { type: "restore", onSuccess: ["continue"], onNothingToRestore: [], onError: [] },
287
+ { type: "dismiss" },
288
+ { type: "presentPaywall", placement: "x" },
289
+ { type: "custom", function: "f", variables: ["a"] },
290
+ ])
291
+ )
292
+ ).toEqual([]);
293
+ });
294
+
295
+ it("walks into an outcome hook's own actions", () => {
296
+ const found = collectUnknownElementKeys(
297
+ withActions([
298
+ {
299
+ type: "requestPermission",
300
+ kind: "notifications",
301
+ onGranted: [{ type: "purchase", product: "yearly", onErrr: ["continue"] }],
302
+ onDenied: ["continue"],
303
+ },
304
+ ])
305
+ );
306
+ expect(found).toHaveLength(1);
307
+ expect(found[0].key).toBe("onErrr");
308
+ expect(found[0].path).toBe("elements[0].props.actions[0].onGranted[0]");
309
+ });
310
+
311
+ it("covers the generic onPress list too", () => {
312
+ const found = collectUnknownElementKeys([
313
+ { id: "card", type: "YStack", props: { onPress: [{ type: "dismiss", statuss: "x" }] }, children: [] },
314
+ ]);
315
+ expect(found.map((f) => f.key)).toEqual(["statuss"]);
316
+ expect(found[0].path).toBe("elements[0].props.onPress[0]");
317
+ });
318
+
319
+ // An action type this build does not know is a parse failure, not a stray
320
+ // key — guessing its key set would be noise, exactly as for an unknown
321
+ // element type.
322
+ it("skips an action type it does not know", () => {
323
+ expect(
324
+ collectUnknownElementKeys(withActions([{ type: "requestBiometrics", onGranted: ["continue"] }]))
325
+ ).toEqual([]);
326
+ });
327
+
328
+ it("tolerates malformed action lists", () => {
329
+ expect(collectUnknownElementKeys(withActions("continue"))).toEqual([]);
330
+ expect(collectUnknownElementKeys(withActions([null, 42, "continue"]))).toEqual([]);
331
+ expect(collectUnknownElementKeys(withActions([{}]))).toEqual([]);
332
+ });
333
+
334
+ it("formats an action finding as a dropped key on that action", () => {
335
+ const msg = formatUnknownElementKeys(
336
+ collectUnknownElementKeys(
337
+ withActions([{ type: "requestPermission", kind: "notifications", onDeneid: ["continue"] }])
338
+ )
339
+ );
340
+ expect(msg).toContain("onDeneid");
341
+ expect(msg).toContain("requestPermission");
342
+ expect(msg).toContain("elements[0].props.actions[0]");
343
+ });
344
+ });
package/src/index.ts CHANGED
@@ -11,7 +11,10 @@ export {
11
11
  export type {
12
12
  ButtonAction,
13
13
  CustomButtonAction,
14
+ CustomActionRetry,
14
15
  SetVariableButtonAction,
16
+ RequestPermissionButtonAction,
17
+ PermissionKind,
15
18
  ComposableVariableEntry,
16
19
  ComposableVariableKind,
17
20
  WheelPickerElementProps,
@@ -42,7 +45,11 @@ export type {
42
45
  export {
43
46
  ButtonActionSchema,
44
47
  CustomButtonActionSchema,
48
+ CustomActionRetrySchema,
45
49
  SetVariableButtonActionSchema,
50
+ RequestPermissionButtonActionSchema,
51
+ PermissionKindSchema,
52
+ PERMISSION_KINDS,
46
53
  WheelPickerElementPropsSchema,
47
54
  generateWheelPickerRangeItems,
48
55
  resolveWheelPickerItems,
@@ -123,7 +130,20 @@ export type { UnknownElementType } from "./screens/unknownElementTypes";
123
130
  // versions can differ.
124
131
  export { resolveRenderableStep } from "./screens/resolveRenderableStep";
125
132
  export type { RenderableStep } from "./screens/resolveRenderableStep";
126
- export { hasCompletingAction } from "./screens/completingActions";
133
+ // `hasCompletingAction` answers it for a whole element tree (what the strip
134
+ // needs); `actionsCanComplete` answers it for one action list, which is what the
135
+ // UI runtime consults at press time before deciding whether a permission ask it
136
+ // could not perform has left the user with no way off the screen.
137
+ // `completingActionKind` answers WHICH of the two completing actions that list
138
+ // reaches — the runtime has to stand in for the author's escape with the same
139
+ // outcome the author authored, since `complete()` and `complete({status:
140
+ // "dismissed"})` are not interchangeable at a paywall's hard gate.
141
+ export {
142
+ hasCompletingAction,
143
+ actionsCanComplete,
144
+ completingActionKind,
145
+ } from "./screens/completingActions";
146
+ export type { EscapeAction } from "./screens/completingActions";
127
147
  export { deriveElementTypeNames } from "./screens/elementTypeRegistry";
128
148
  // Hooks and providers
129
149
  export * from "./infra";
@@ -177,6 +197,18 @@ export { PaywallProvider, usePaywallHost } from "./paywalls/PaywallProvider";
177
197
  // live in the headless package. onboarding-ui re-exports both names.
178
198
  export type { CustomPaywallScreenProps, CustomPaywallScreens } from "./paywalls/customScreens";
179
199
  export type { PaywallContextValue } from "./paywalls/PaywallProvider";
200
+ // `PaywallProvider`'s `observer` prop: the host's own analytics hook into every
201
+ // presentation. Names match rocalytics-sdk's `PaywallObserver` verbatim.
202
+ export type {
203
+ PaywallObserver,
204
+ PaywallPresentationInfo,
205
+ PaywallPresentationHandle,
206
+ PaywallPresentationEnd,
207
+ PaywallTransactionInfo,
208
+ PaywallSurface,
209
+ PaywallPresentation,
210
+ PaywallPresentationSource,
211
+ } from "./paywalls/observer";
180
212
  export { usePaywall } from "./paywalls/usePaywall";
181
213
  // Exported so a host can switch exhaustively on what the catalog is doing
182
214
  // rather than inferring it from `isReady` plus a non-null check.