@rocapine/react-native-onboarding 1.74.1 → 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 (105) hide show
  1. package/dist/evaluateCondition.d.ts.map +1 -1
  2. package/dist/evaluateCondition.js +103 -4
  3. package/dist/evaluateCondition.js.map +1 -1
  4. package/dist/index.d.ts +10 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +39 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/onboarding-example.d.ts +375 -99
  9. package/dist/onboarding-example.d.ts.map +1 -1
  10. package/dist/onboarding-example.js +118 -1
  11. package/dist/onboarding-example.js.map +1 -1
  12. package/dist/paywalls/PaywallProvider.d.ts +71 -5
  13. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  14. package/dist/paywalls/PaywallProvider.js +237 -57
  15. package/dist/paywalls/PaywallProvider.js.map +1 -1
  16. package/dist/paywalls/customScreens.d.ts +31 -0
  17. package/dist/paywalls/customScreens.d.ts.map +1 -1
  18. package/dist/paywalls/observer.d.ts +129 -0
  19. package/dist/paywalls/observer.d.ts.map +1 -0
  20. package/dist/paywalls/observer.js +211 -0
  21. package/dist/paywalls/observer.js.map +1 -0
  22. package/dist/paywalls/present.d.ts +19 -15
  23. package/dist/paywalls/present.d.ts.map +1 -1
  24. package/dist/paywalls/present.js +21 -17
  25. package/dist/paywalls/present.js.map +1 -1
  26. package/dist/paywalls/types.d.ts +3 -1
  27. package/dist/paywalls/types.d.ts.map +1 -1
  28. package/dist/products/adapters/expoIap.d.ts +38 -1
  29. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  30. package/dist/products/adapters/expoIap.js +509 -75
  31. package/dist/products/adapters/expoIap.js.map +1 -1
  32. package/dist/products/index.d.ts +1 -0
  33. package/dist/products/index.d.ts.map +1 -1
  34. package/dist/products/index.js.map +1 -1
  35. package/dist/products/types.d.ts +13 -0
  36. package/dist/products/types.d.ts.map +1 -1
  37. package/dist/screens/completingActions.d.ts +95 -0
  38. package/dist/screens/completingActions.d.ts.map +1 -0
  39. package/dist/screens/completingActions.js +302 -0
  40. package/dist/screens/completingActions.js.map +1 -0
  41. package/dist/screens/elementTypeRegistry.d.ts +45 -0
  42. package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
  43. package/dist/screens/elementTypeRegistry.js +119 -0
  44. package/dist/screens/elementTypeRegistry.js.map +1 -0
  45. package/dist/screens/elements/ButtonElement.d.ts +3 -2
  46. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  47. package/dist/screens/elements/ButtonElement.js +5 -1
  48. package/dist/screens/elements/ButtonElement.js.map +1 -1
  49. package/dist/screens/resolveRenderableStep.d.ts +42 -0
  50. package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
  51. package/dist/screens/resolveRenderableStep.js +28 -0
  52. package/dist/screens/resolveRenderableStep.js.map +1 -0
  53. package/dist/screens/types.d.ts +2 -2
  54. package/dist/screens/types.d.ts.map +1 -1
  55. package/dist/screens/types.js +5 -1
  56. package/dist/screens/types.js.map +1 -1
  57. package/dist/screens/unknownElementTypes.d.ts +94 -0
  58. package/dist/screens/unknownElementTypes.d.ts.map +1 -0
  59. package/dist/screens/unknownElementTypes.js +141 -0
  60. package/dist/screens/unknownElementTypes.js.map +1 -0
  61. package/dist/screens/unknownKeys.d.ts +30 -6
  62. package/dist/screens/unknownKeys.d.ts.map +1 -1
  63. package/dist/screens/unknownKeys.js +88 -54
  64. package/dist/screens/unknownKeys.js.map +1 -1
  65. package/dist/steps/common.types.d.ts +262 -9
  66. package/dist/steps/common.types.d.ts.map +1 -1
  67. package/dist/steps/common.types.js +64 -3
  68. package/dist/steps/common.types.js.map +1 -1
  69. package/package.json +1 -1
  70. package/src/__tests__/authoringDocEscapes.test.ts +59 -0
  71. package/src/__tests__/completingActions.test.ts +509 -0
  72. package/src/__tests__/customActionHooks.test.ts +224 -0
  73. package/src/__tests__/elementTypeRegistry.test.ts +48 -0
  74. package/src/__tests__/evaluateCondition.test.ts +228 -3
  75. package/src/__tests__/onboardingExampleElements.test.ts +74 -0
  76. package/src/__tests__/requestPermissionAction.test.ts +138 -0
  77. package/src/__tests__/resolveRenderableStep.test.ts +117 -0
  78. package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
  79. package/src/__tests__/unknownElementTypes.test.ts +240 -0
  80. package/src/__tests__/unknownKeys.test.ts +110 -0
  81. package/src/evaluateCondition.ts +107 -4
  82. package/src/index.ts +55 -0
  83. package/src/onboarding-example.ts +119 -1
  84. package/src/paywalls/PaywallProvider.tsx +370 -66
  85. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
  86. package/src/paywalls/__tests__/observer.test.ts +401 -0
  87. package/src/paywalls/__tests__/present.test.ts +0 -18
  88. package/src/paywalls/customScreens.ts +34 -1
  89. package/src/paywalls/observer.ts +308 -0
  90. package/src/paywalls/present.ts +24 -18
  91. package/src/paywalls/types.ts +3 -1
  92. package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
  93. package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
  94. package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
  95. package/src/products/adapters/expoIap.ts +609 -78
  96. package/src/products/index.ts +1 -0
  97. package/src/products/types.ts +13 -0
  98. package/src/screens/completingActions.ts +316 -0
  99. package/src/screens/elementTypeRegistry.ts +122 -0
  100. package/src/screens/elements/ButtonElement.ts +9 -1
  101. package/src/screens/resolveRenderableStep.ts +59 -0
  102. package/src/screens/types.ts +2 -2
  103. package/src/screens/unknownElementTypes.ts +204 -0
  104. package/src/screens/unknownKeys.ts +119 -56
  105. package/src/steps/common.types.ts +297 -9
@@ -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,117 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { resolveRenderableStep } from "../screens/resolveRenderableStep";
3
+ import { ComposableScreenStepTypeSchema } from "../steps/ComposableScreen/types";
4
+
5
+ /**
6
+ * The whole render-boundary decision for #209, in one pure function, so the
7
+ * ComposableScreen renderer holds no logic that this package's tests cannot
8
+ * reach (the UI package's vitest runs in plain Node and cannot import
9
+ * `react-native`, so anything decided there is only assertable at source level).
10
+ *
11
+ * Two questions, answered together because the second only has meaning after
12
+ * the first: what should be parsed, and can the user still leave the screen?
13
+ */
14
+
15
+ const text = (id: string, content: string) => ({ id, type: "Text", props: { content } });
16
+ const cta = (id: string) => ({
17
+ id,
18
+ type: "Button",
19
+ props: { label: "Continue", actions: ["continue"] },
20
+ });
21
+
22
+ const step = (elements: unknown[]) => ({
23
+ id: "s",
24
+ name: "Step one",
25
+ type: "ComposableScreen",
26
+ displayProgressHeader: false,
27
+ payload: { elements },
28
+ });
29
+
30
+ describe("resolveRenderableStep", () => {
31
+ it("hands back the same step reference when every element type is known", () => {
32
+ const clean = step([text("t", "hi"), cta("go")]);
33
+ const resolved = resolveRenderableStep(clean);
34
+ expect(resolved.step).toBe(clean);
35
+ expect(resolved.omitted).toEqual([]);
36
+ expect(resolved.needsEscape).toBe(false);
37
+ });
38
+
39
+ it("asks for an escape when the strip takes the screen's only way forward", () => {
40
+ // The reviewer's reproduction, and the shape the shipped example payload
41
+ // itself uses: ONE root container holding everything, including the CTA. If
42
+ // that container is a type this build does not know, the strip empties the
43
+ // screen — `[]` parses cleanly, so nothing throws and nothing renders.
44
+ const trapped = step([
45
+ { id: "root", type: "HolographicCard", props: {}, children: [text("t", "hi"), cta("go")] },
46
+ ]);
47
+ const resolved = resolveRenderableStep(trapped);
48
+
49
+ const parsed = ComposableScreenStepTypeSchema.parse(resolved.step);
50
+ expect(parsed.payload.elements).toEqual([]);
51
+ expect(resolved.needsEscape).toBe(true);
52
+ expect(resolved.omitted.map((o) => o.elementType)).toEqual(["HolographicCard"]);
53
+ });
54
+
55
+ it("needs no escape when a CTA survives the strip", () => {
56
+ const resolved = resolveRenderableStep(
57
+ step([{ id: "x", type: "HolographicCard", props: {} }, cta("go")])
58
+ );
59
+ expect(resolved.needsEscape).toBe(false);
60
+ expect(resolved.omitted).toHaveLength(1);
61
+ });
62
+
63
+ it("needs an escape when the surviving tree has content but nothing pressable", () => {
64
+ const resolved = resolveRenderableStep(
65
+ step([text("t", "hi"), { id: "x", type: "TimeOfDayPicker", props: {}, children: [cta("go")] }])
66
+ );
67
+ expect(resolved.needsEscape).toBe(true);
68
+ });
69
+
70
+ it("leaves an authored screen with no CTA alone — nothing was stripped, so nothing is ours to fix", () => {
71
+ // A screen the author gave no way forward is an authoring bug, and the host
72
+ // may well advance it some other way (a custom action that navigates, a
73
+ // timer). Injecting a CTA there would change shipped screens that have
74
+ // nothing to do with an unknown element type.
75
+ const authored = step([text("t", "hi")]);
76
+ const resolved = resolveRenderableStep(authored);
77
+ expect(resolved.step).toBe(authored);
78
+ expect(resolved.needsEscape).toBe(false);
79
+ });
80
+
81
+ it("passes a step with no element payload straight through", () => {
82
+ const ratings = { id: "r", type: "Ratings", payload: { title: "x" } };
83
+ const resolved = resolveRenderableStep(ratings);
84
+ expect(resolved.step).toBe(ratings);
85
+ expect(resolved.needsEscape).toBe(false);
86
+ });
87
+
88
+ it("strips nothing and asks for nothing when it cannot tell which types are known", () => {
89
+ // An empty capability set means the derivation failed, which must read as
90
+ // "learn nothing" — never as "reject everything", which would blank every
91
+ // screen in every app and then cover each one with a fallback CTA.
92
+ const trapped = step([
93
+ { id: "root", type: "HolographicCard", props: {}, children: [cta("go")] },
94
+ ]);
95
+ const resolved = resolveRenderableStep(trapped, new Set<string>());
96
+ expect(resolved.step).toBe(trapped);
97
+ expect(resolved.omitted).toEqual([]);
98
+ expect(resolved.needsEscape).toBe(false);
99
+ });
100
+
101
+ it("keys off the capability set it is given, not the schema it was built from", () => {
102
+ // What renders is the onboarding-ui package's own re-declared union, whose
103
+ // installed version can differ from this one's. The caller supplies the set;
104
+ // here `Button` is deliberately absent from it and must be stripped.
105
+ const resolved = resolveRenderableStep(step([text("t", "hi"), cta("go")]), new Set(["Text"]));
106
+ const parsed = ComposableScreenStepTypeSchema.parse(resolved.step);
107
+ expect(parsed.payload.elements.map((e) => e.id)).toEqual(["t"]);
108
+ expect(resolved.needsEscape).toBe(true);
109
+ });
110
+
111
+ it("does not mutate the step it was given", () => {
112
+ const trapped = step([{ id: "x", type: "HolographicCard", props: {} }, cta("go")]);
113
+ const before = JSON.stringify(trapped);
114
+ resolveRenderableStep(trapped);
115
+ expect(JSON.stringify(trapped)).toBe(before);
116
+ });
117
+ });
@@ -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
+ });
@@ -0,0 +1,240 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ KNOWN_ELEMENT_TYPES,
4
+ collectUnknownElementTypes,
5
+ collectUnknownElementTypesInSteps,
6
+ dropUnknownElementTypes,
7
+ dropUnknownElementTypesInStep,
8
+ formatUnknownElementTypes,
9
+ } from "../screens/unknownElementTypes";
10
+ import { ScreenElementsSchema } from "../screens/types";
11
+ import { ComposableScreenStepTypeSchema } from "../steps/ComposableScreen/types";
12
+
13
+ /**
14
+ * Forward compatibility for element TYPES (#209).
15
+ *
16
+ * `UIElementSchema` is a discriminated union of the types this SDK build knows.
17
+ * Before this, one element type published after an app shipped made the WHOLE
18
+ * screen fail to parse — and the ComposableScreen renderer's `.parse` threw
19
+ * inside its error boundary, whose fallback has no interactive control, so on a
20
+ * step with `displayProgressHeader: false` the user had no way forward OR back.
21
+ *
22
+ * The contract asserted here: an unrecognized element type is OMITTED (matching
23
+ * `renderElement`'s terminal `return null` and `buildAnimation`'s unknown-preset
24
+ * no-op), the rest of the screen renders, and a genuine data error on a KNOWN
25
+ * type still fails loudly.
26
+ */
27
+
28
+ const text = (id: string, content: string) => ({ id, type: "Text", props: { content } });
29
+ const stack = (id: string, children: unknown[]) => ({ id, type: "YStack", props: {}, children });
30
+ const unknown = (id: string, type = "HolographicCard") => ({ id, type, props: { magic: true } });
31
+
32
+ const step = (elements: unknown[]) => ({
33
+ id: "step-1",
34
+ name: "Step one",
35
+ type: "ComposableScreen",
36
+ displayProgressHeader: false,
37
+ payload: { elements },
38
+ });
39
+
40
+ describe("dropUnknownElementTypes", () => {
41
+ it("keeps the rest of the screen when a top-level element type is unknown", () => {
42
+ const parsed = ScreenElementsSchema.safeParse(
43
+ dropUnknownElementTypes([text("a", "before"), unknown("x"), text("b", "after")])
44
+ );
45
+ expect(parsed.success).toBe(true);
46
+ if (!parsed.success) return;
47
+ expect(parsed.data.map((e) => e.id)).toEqual(["a", "b"]);
48
+ });
49
+
50
+ it("keeps a container's known children when one child type is unknown", () => {
51
+ const parsed = ScreenElementsSchema.safeParse(
52
+ dropUnknownElementTypes([stack("root", [text("a", "hi"), unknown("x")])])
53
+ );
54
+ expect(parsed.success).toBe(true);
55
+ if (!parsed.success) return;
56
+ const [root] = parsed.data;
57
+ expect(root.type).toBe("YStack");
58
+ expect("children" in root ? root.children.map((c) => c.id) : []).toEqual(["a"]);
59
+ });
60
+
61
+ it("drops the whole subtree of an unknown element, never hoisting its children", () => {
62
+ // Matches the render half: `renderElement` returns null for an unrecognized
63
+ // type, so its children never render either. Hoisting them would invent a
64
+ // layout the author never wrote.
65
+ const parsed = ScreenElementsSchema.safeParse(
66
+ dropUnknownElementTypes([{ ...unknown("x"), children: [text("inner", "hidden")] }])
67
+ );
68
+ expect(parsed.success).toBe(true);
69
+ if (!parsed.success) return;
70
+ expect(parsed.data).toEqual([]);
71
+ });
72
+
73
+ it("drops an unknown type nested in a RichText's Text-only children", () => {
74
+ const parsed = ScreenElementsSchema.safeParse(
75
+ dropUnknownElementTypes([
76
+ { id: "rt", type: "RichText", props: {}, children: [text("w", "word"), unknown("x")] },
77
+ ])
78
+ );
79
+ expect(parsed.success).toBe(true);
80
+ });
81
+
82
+ it("still fails loudly on a bad prop of a KNOWN element type", () => {
83
+ // The forward-compat escape must not become a silence-everything escape:
84
+ // `variant: "plain"` is a CMS data bug the author has to fix.
85
+ const bad = { id: "b", type: "Button", props: { label: "Go", variant: "plain" } };
86
+ const parsed = ScreenElementsSchema.safeParse(dropUnknownElementTypes([bad]));
87
+ expect(parsed.success).toBe(false);
88
+ if (parsed.success) return;
89
+ expect(parsed.error.issues.some((i) => i.path.join(".").endsWith("props.variant"))).toBe(true);
90
+ });
91
+
92
+ it("still fails loudly on a KNOWN element type missing its `id`", () => {
93
+ const parsed = ScreenElementsSchema.safeParse(
94
+ dropUnknownElementTypes([{ type: "Text", props: { content: "x" } }])
95
+ );
96
+ expect(parsed.success).toBe(false);
97
+ });
98
+
99
+ it("leaves an element with no `type` for the parser to report", () => {
100
+ // A missing/non-string discriminator is a malformed payload, not a newer
101
+ // element — dropping it would hide the real error.
102
+ const parsed = ScreenElementsSchema.safeParse(dropUnknownElementTypes([{ id: "a", props: {} }]));
103
+ expect(parsed.success).toBe(false);
104
+ });
105
+
106
+ it("returns the input unchanged when it is not an array", () => {
107
+ expect(dropUnknownElementTypes(undefined)).toBeUndefined();
108
+ expect(dropUnknownElementTypes("nope")).toBe("nope");
109
+ });
110
+
111
+ it("does not mutate the payload it was given", () => {
112
+ const elements = [stack("root", [text("a", "hi"), unknown("x")])];
113
+ const before = JSON.stringify(elements);
114
+ dropUnknownElementTypes(elements);
115
+ expect(JSON.stringify(elements)).toBe(before);
116
+ });
117
+
118
+ it("keeps every element when the type registry cannot be built", () => {
119
+ // The registry is derived from zod's internals, so a future zod release can
120
+ // break it. It must degrade to "everything is known" (parse as today), never
121
+ // to "nothing is known" — which would blank every screen in every app.
122
+ const elements = [text("a", "hi"), unknown("x")];
123
+ expect(dropUnknownElementTypes(elements, new Set<string>())).toBe(elements);
124
+ });
125
+
126
+ it("returns the same array reference when nothing is unknown", () => {
127
+ // Structural sharing: the strip runs on every screen render, so a clean
128
+ // payload must not be cloned (and must stay `useMemo`-stable).
129
+ const elements = [stack("root", [text("a", "hi")])];
130
+ expect(dropUnknownElementTypes(elements)).toBe(elements);
131
+ });
132
+ });
133
+
134
+ describe("dropUnknownElementTypesInStep", () => {
135
+ it("makes the ComposableScreen step parse instead of throwing", () => {
136
+ // The exact call at ComposableScreen/Renderer.tsx: `.parse(step)`.
137
+ expect(() => ComposableScreenStepTypeSchema.parse(step([unknown("x")]))).toThrow();
138
+ const parsed = ComposableScreenStepTypeSchema.parse(
139
+ dropUnknownElementTypesInStep(step([text("a", "hi"), unknown("x")]))
140
+ );
141
+ expect(parsed.payload.elements.map((e) => e.id)).toEqual(["a"]);
142
+ });
143
+
144
+ it("passes a step through untouched when it carries no element payload", () => {
145
+ const ratings = { id: "r", type: "Ratings", payload: { title: "x" } };
146
+ expect(dropUnknownElementTypesInStep(ratings)).toBe(ratings);
147
+ });
148
+
149
+ it("returns the same step reference when every element type is known", () => {
150
+ const clean = step([text("a", "hi")]);
151
+ expect(dropUnknownElementTypesInStep(clean)).toBe(clean);
152
+ });
153
+ });
154
+
155
+ describe("collectUnknownElementTypes", () => {
156
+ it("reports the path, id and type of each unknown element", () => {
157
+ const found = collectUnknownElementTypes([
158
+ text("a", "hi"),
159
+ unknown("x", "HolographicCard"),
160
+ stack("root", [unknown("y", "TimeOfDayPicker")]),
161
+ ]);
162
+ expect(found).toEqual([
163
+ { path: "elements[1]", elementId: "x", elementType: "HolographicCard" },
164
+ { path: "elements[2].children[0]", elementId: "y", elementType: "TimeOfDayPicker" },
165
+ ]);
166
+ });
167
+
168
+ it("reports an unknown parent once, not its dropped descendants", () => {
169
+ const found = collectUnknownElementTypes([
170
+ { ...unknown("x"), children: [unknown("y", "AlsoUnknown")] },
171
+ ]);
172
+ expect(found).toHaveLength(1);
173
+ expect(found[0].elementId).toBe("x");
174
+ });
175
+
176
+ it("says nothing about a tree of known types", () => {
177
+ expect(collectUnknownElementTypes([stack("root", [text("a", "hi")])])).toEqual([]);
178
+ });
179
+
180
+ it("walks every step carrying an element payload", () => {
181
+ const found = collectUnknownElementTypesInSteps([
182
+ { id: "s1", type: "Ratings", payload: {} },
183
+ step([unknown("x")]),
184
+ ]);
185
+ expect(found).toHaveLength(1);
186
+ expect(found[0].path).toContain("step-1");
187
+ });
188
+ });
189
+
190
+ describe("formatUnknownElementTypes", () => {
191
+ it("says nothing when there is nothing to say", () => {
192
+ expect(formatUnknownElementTypes([])).toBe("");
193
+ });
194
+
195
+ it("names the type, the path and the omit contract", () => {
196
+ const report = formatUnknownElementTypes(
197
+ collectUnknownElementTypes([unknown("x", "HolographicCard")])
198
+ );
199
+ expect(report).toContain("HolographicCard");
200
+ expect(report).toContain("elements[0]");
201
+ expect(report).toMatch(/omitted/i);
202
+ expect(report).toMatch(/upgrade|newer|version/i);
203
+ });
204
+ });
205
+
206
+ describe("KNOWN_ELEMENT_TYPES", () => {
207
+ it("is derived from the schema, so it cannot drift as elements are added", () => {
208
+ // Every variant of the discriminated union, and nothing else.
209
+ expect(KNOWN_ELEMENT_TYPES).toContain("YStack");
210
+ expect(KNOWN_ELEMENT_TYPES).toContain("Slider");
211
+ expect(KNOWN_ELEMENT_TYPES).not.toContain("HolographicCard");
212
+ // No known type may be rejected on its own discriminator. Other issues are
213
+ // expected and fine: `props: {}` is incomplete for most variants.
214
+ const rejectedOnDiscriminator = KNOWN_ELEMENT_TYPES.filter((type) => {
215
+ const parsed = ScreenElementsSchema.safeParse([{ id: "a", type, props: {} }]);
216
+ return (
217
+ !parsed.success && parsed.error.issues.some((i) => i.path.join(".") === "0.type")
218
+ );
219
+ });
220
+ expect(rejectedOnDiscriminator).toEqual([]);
221
+ });
222
+
223
+ it("is sorted and free of duplicates, so it is usable as a capability list", () => {
224
+ expect([...KNOWN_ELEMENT_TYPES]).toEqual([...new Set(KNOWN_ELEMENT_TYPES)].sort());
225
+ });
226
+ });
227
+
228
+ describe("no backtracking is reintroduced", () => {
229
+ it("strips a deep tree and still fails fast on a pathological payload", () => {
230
+ // Canary for the discriminated union (screens/types.ts:296-348): a plain
231
+ // union of these recursive variants exhausted a 512 MB heap on a real
232
+ // 52-node paywall. The strip must stay a linear walk in front of it.
233
+ const nest = (depth: number, leaf: unknown): unknown =>
234
+ depth === 0 ? leaf : { name: "c", type: "YStack", props: {}, children: [nest(depth - 1, leaf)] };
235
+ const started = Date.now();
236
+ const parsed = ScreenElementsSchema.safeParse(dropUnknownElementTypes([nest(10, text("l", "x"))]));
237
+ expect(parsed.success).toBe(false);
238
+ expect(Date.now() - started).toBeLessThan(2000);
239
+ });
240
+ });
@@ -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
+ });