@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.
- package/dist/evaluateCondition.d.ts.map +1 -1
- package/dist/evaluateCondition.js +103 -4
- package/dist/evaluateCondition.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/onboarding-example.d.ts +375 -99
- package/dist/onboarding-example.d.ts.map +1 -1
- package/dist/onboarding-example.js +118 -1
- package/dist/onboarding-example.js.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +71 -5
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
- package/dist/paywalls/PaywallProvider.js +237 -57
- package/dist/paywalls/PaywallProvider.js.map +1 -1
- package/dist/paywalls/customScreens.d.ts +31 -0
- package/dist/paywalls/customScreens.d.ts.map +1 -1
- package/dist/paywalls/observer.d.ts +129 -0
- package/dist/paywalls/observer.d.ts.map +1 -0
- package/dist/paywalls/observer.js +211 -0
- package/dist/paywalls/observer.js.map +1 -0
- package/dist/paywalls/present.d.ts +19 -15
- package/dist/paywalls/present.d.ts.map +1 -1
- package/dist/paywalls/present.js +21 -17
- package/dist/paywalls/present.js.map +1 -1
- package/dist/paywalls/types.d.ts +3 -1
- package/dist/paywalls/types.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.d.ts +38 -1
- package/dist/products/adapters/expoIap.d.ts.map +1 -1
- package/dist/products/adapters/expoIap.js +509 -75
- package/dist/products/adapters/expoIap.js.map +1 -1
- package/dist/products/index.d.ts +1 -0
- package/dist/products/index.d.ts.map +1 -1
- package/dist/products/index.js.map +1 -1
- package/dist/products/types.d.ts +13 -0
- package/dist/products/types.d.ts.map +1 -1
- package/dist/screens/completingActions.d.ts +95 -0
- package/dist/screens/completingActions.d.ts.map +1 -0
- package/dist/screens/completingActions.js +302 -0
- package/dist/screens/completingActions.js.map +1 -0
- package/dist/screens/elementTypeRegistry.d.ts +45 -0
- package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
- package/dist/screens/elementTypeRegistry.js +119 -0
- package/dist/screens/elementTypeRegistry.js.map +1 -0
- package/dist/screens/elements/ButtonElement.d.ts +3 -2
- package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
- package/dist/screens/elements/ButtonElement.js +5 -1
- package/dist/screens/elements/ButtonElement.js.map +1 -1
- package/dist/screens/resolveRenderableStep.d.ts +42 -0
- package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
- package/dist/screens/resolveRenderableStep.js +28 -0
- package/dist/screens/resolveRenderableStep.js.map +1 -0
- package/dist/screens/types.d.ts +2 -2
- package/dist/screens/types.d.ts.map +1 -1
- package/dist/screens/types.js +5 -1
- package/dist/screens/types.js.map +1 -1
- package/dist/screens/unknownElementTypes.d.ts +94 -0
- package/dist/screens/unknownElementTypes.d.ts.map +1 -0
- package/dist/screens/unknownElementTypes.js +141 -0
- package/dist/screens/unknownElementTypes.js.map +1 -0
- package/dist/screens/unknownKeys.d.ts +30 -6
- package/dist/screens/unknownKeys.d.ts.map +1 -1
- package/dist/screens/unknownKeys.js +88 -54
- package/dist/screens/unknownKeys.js.map +1 -1
- package/dist/steps/common.types.d.ts +262 -9
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +64 -3
- package/dist/steps/common.types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/authoringDocEscapes.test.ts +59 -0
- package/src/__tests__/completingActions.test.ts +509 -0
- package/src/__tests__/customActionHooks.test.ts +224 -0
- package/src/__tests__/elementTypeRegistry.test.ts +48 -0
- package/src/__tests__/evaluateCondition.test.ts +228 -3
- package/src/__tests__/onboardingExampleElements.test.ts +74 -0
- package/src/__tests__/requestPermissionAction.test.ts +138 -0
- package/src/__tests__/resolveRenderableStep.test.ts +117 -0
- package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
- package/src/__tests__/unknownElementTypes.test.ts +240 -0
- package/src/__tests__/unknownKeys.test.ts +110 -0
- package/src/evaluateCondition.ts +107 -4
- package/src/index.ts +55 -0
- package/src/onboarding-example.ts +119 -1
- package/src/paywalls/PaywallProvider.tsx +370 -66
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
- package/src/paywalls/__tests__/observer.test.ts +401 -0
- package/src/paywalls/__tests__/present.test.ts +0 -18
- package/src/paywalls/customScreens.ts +34 -1
- package/src/paywalls/observer.ts +308 -0
- package/src/paywalls/present.ts +24 -18
- package/src/paywalls/types.ts +3 -1
- package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
- package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
- package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
- package/src/products/adapters/expoIap.ts +609 -78
- package/src/products/index.ts +1 -0
- package/src/products/types.ts +13 -0
- package/src/screens/completingActions.ts +316 -0
- package/src/screens/elementTypeRegistry.ts +122 -0
- package/src/screens/elements/ButtonElement.ts +9 -1
- package/src/screens/resolveRenderableStep.ts +59 -0
- package/src/screens/types.ts +2 -2
- package/src/screens/unknownElementTypes.ts +204 -0
- package/src/screens/unknownKeys.ts +119 -56
- package/src/steps/common.types.ts +297 -9
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { getKnownElementTypes } from "./elementTypeRegistry";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* FORWARD COMPATIBILITY FOR ELEMENT TYPES (issue #209).
|
|
5
|
+
*
|
|
6
|
+
* `UIElementSchema` is a `z.discriminatedUnion("type", …)` over the element
|
|
7
|
+
* types *this build* knows. An element type published after an app shipped
|
|
8
|
+
* therefore missed every branch, and the whole `elements` array failed to
|
|
9
|
+
* parse — one new element type took down the entire screen, in every installed
|
|
10
|
+
* app pinned to an older SDK.
|
|
11
|
+
*
|
|
12
|
+
* That is worse than a blank screen. The ComposableScreen renderer parses with
|
|
13
|
+
* a throwing `.parse` inside `withErrorBoundary`, and that fallback has no
|
|
14
|
+
* interactive control; the host's back chevron lives inside `<ProgressBar>`,
|
|
15
|
+
* gated on the step's `displayProgressHeader`. On a header-off step there is no
|
|
16
|
+
* exit in either direction, because `onContinue` died with the subtree. Real
|
|
17
|
+
* flows have four such steps, including the entry screen and both steps before
|
|
18
|
+
* the paywall.
|
|
19
|
+
*
|
|
20
|
+
* The fix is a linear walk in FRONT of the schema, not a change to it:
|
|
21
|
+
*
|
|
22
|
+
* • Unknown element `type` → the element is OMITTED, with its subtree, before
|
|
23
|
+
* the payload is parsed. The rest of the screen renders.
|
|
24
|
+
* • Anything else → untouched, so a genuine data bug (a `Button` `variant`
|
|
25
|
+
* outside the enum, a missing `id`) still fails loudly with its exact path.
|
|
26
|
+
*
|
|
27
|
+
* OMIT is the contract, chosen to match what the codebase already does rather
|
|
28
|
+
* than as a new invention: `renderElement` falls through to `return null` for an
|
|
29
|
+
* unrecognized type, `buildAnimation` no-ops an unknown `animation.preset`, and
|
|
30
|
+
* an unknown *step* type already skips with a reason code
|
|
31
|
+
* (`OnboardingPage` → `onContinue("onboarding_screen_not_implemented")`). No
|
|
32
|
+
* placeholder is rendered: a box reading "unsupported" in the middle of an
|
|
33
|
+
* authored layout is worse than the gap it advertises, and the author cannot see
|
|
34
|
+
* it from Studio anyway.
|
|
35
|
+
*
|
|
36
|
+
* WHY NOT WIDEN THE SCHEMA. A non-discriminated union, or a catch-all branch
|
|
37
|
+
* reachable on any miss, is not an option: the discriminator is a deliberate fix
|
|
38
|
+
* for three data-reachable CRASHES (a 512 MB heap OOM on a real 52-node paywall,
|
|
39
|
+
* a `RangeError` thrown from inside zod's own error constructor, and unreadable
|
|
40
|
+
* `invalid_union` output) — see the comment above `UIElementSchema` in
|
|
41
|
+
* `./types.ts` and `__tests__/elementUnionDiscriminator.test.ts`. A fallback
|
|
42
|
+
* branch would also swallow real errors on KNOWN types, turning every CMS data
|
|
43
|
+
* bug into a silently missing element. Stripping first keeps both properties.
|
|
44
|
+
*
|
|
45
|
+
* `ScreenElementsSchema` itself stays STRICT on purpose: authoring- and
|
|
46
|
+
* publish-time validation (Studio, `validate-step-json`, the CLAUDE.md
|
|
47
|
+
* `safeParse` recipe) should keep reporting a typo'd element type as an error.
|
|
48
|
+
* Only the render boundaries strip.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/** One element omitted because this build cannot render its `type`. */
|
|
52
|
+
export type UnknownElementType = {
|
|
53
|
+
/** Location in the tree, e.g. `elements[0].children[2]`. */
|
|
54
|
+
path: string;
|
|
55
|
+
elementId: string;
|
|
56
|
+
/** The `type` value no variant of `UIElementSchema` declares. */
|
|
57
|
+
elementType: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Every element `type` this SDK build can parse and render, sorted.
|
|
62
|
+
*
|
|
63
|
+
* The capability list a publish-time gate needs (#209's "capability floor"):
|
|
64
|
+
* derived from `UIElementSchema`, so it is exactly what the installed build
|
|
65
|
+
* supports and cannot be forgotten when an element is added.
|
|
66
|
+
*/
|
|
67
|
+
export const KNOWN_ELEMENT_TYPES: readonly string[] = [...getKnownElementTypes()].sort();
|
|
68
|
+
|
|
69
|
+
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
70
|
+
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* An empty registry means the derivation failed (zod internals moved), not that
|
|
74
|
+
* no element type exists. Read as "learn nothing": every element is kept and the
|
|
75
|
+
* schema decides, exactly as it did before this file existed. The inverse
|
|
76
|
+
* reading would blank every screen in every app.
|
|
77
|
+
*/
|
|
78
|
+
const resolveKnown = (known?: ReadonlySet<string>): ReadonlySet<string> | null => {
|
|
79
|
+
const set = known ?? getKnownElementTypes();
|
|
80
|
+
return set.size === 0 ? null : set;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const isUnknownElement = (node: unknown, known: ReadonlySet<string>): boolean =>
|
|
84
|
+
isRecord(node) && typeof node.type === "string" && !known.has(node.type);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Strip every element whose `type` this build does not know from an `elements`
|
|
88
|
+
* array (recursively, through `children`).
|
|
89
|
+
*
|
|
90
|
+
* Pure, and structurally sharing: a payload with nothing unknown comes back as
|
|
91
|
+
* the SAME array reference, so this is free on the overwhelmingly common path
|
|
92
|
+
* and stays stable inside a `useMemo`. Non-array input is returned unchanged for
|
|
93
|
+
* the schema to reject.
|
|
94
|
+
*
|
|
95
|
+
* A node with no `type`, or a non-string one, is KEPT: that is a malformed
|
|
96
|
+
* payload rather than a newer element, and dropping it would hide the real error.
|
|
97
|
+
*/
|
|
98
|
+
export const dropUnknownElementTypes = <T>(elements: T, known?: ReadonlySet<string>): T => {
|
|
99
|
+
const knownTypes = resolveKnown(known);
|
|
100
|
+
if (knownTypes === null || !Array.isArray(elements)) return elements;
|
|
101
|
+
return dropInArray(elements, knownTypes) as T;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const dropInArray = (elements: unknown[], known: ReadonlySet<string>): unknown[] => {
|
|
105
|
+
let changed = false;
|
|
106
|
+
const kept: unknown[] = [];
|
|
107
|
+
for (const node of elements) {
|
|
108
|
+
if (isUnknownElement(node, known)) {
|
|
109
|
+
// The whole subtree goes with it: `renderElement` returns null for an
|
|
110
|
+
// unknown type, so its children never render either.
|
|
111
|
+
changed = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const next = dropInNode(node, known);
|
|
115
|
+
if (next !== node) changed = true;
|
|
116
|
+
kept.push(next);
|
|
117
|
+
}
|
|
118
|
+
return changed ? kept : elements;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const dropInNode = (node: unknown, known: ReadonlySet<string>): unknown => {
|
|
122
|
+
if (!isRecord(node) || !Array.isArray(node.children)) return node;
|
|
123
|
+
const children = dropInArray(node.children, known);
|
|
124
|
+
return children === node.children ? node : { ...node, children };
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The same strip for a whole step, for callers holding one (the ComposableScreen
|
|
129
|
+
* renderer parses the step, not the array). Steps without `payload.elements` —
|
|
130
|
+
* every non-composable step type — are returned untouched.
|
|
131
|
+
*/
|
|
132
|
+
export const dropUnknownElementTypesInStep = <T>(step: T, known?: ReadonlySet<string>): T => {
|
|
133
|
+
if (!isRecord(step)) return step;
|
|
134
|
+
const payload = step.payload;
|
|
135
|
+
if (!isRecord(payload) || !Array.isArray(payload.elements)) return step;
|
|
136
|
+
const elements = dropUnknownElementTypes(payload.elements, known);
|
|
137
|
+
if (elements === payload.elements) return step;
|
|
138
|
+
return { ...step, payload: { ...payload, elements } } as T;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Report — rather than strip — the elements this build cannot render, so a host
|
|
143
|
+
* (and the dev-time payload diagnostic in `OnboardingProvider`) can say what
|
|
144
|
+
* went missing. An unknown parent is reported ONCE: its descendants go with it,
|
|
145
|
+
* and listing them would bury the one fact that matters.
|
|
146
|
+
*/
|
|
147
|
+
export const collectUnknownElementTypes = (
|
|
148
|
+
elements: unknown,
|
|
149
|
+
basePath = "elements",
|
|
150
|
+
known?: ReadonlySet<string>
|
|
151
|
+
): UnknownElementType[] => {
|
|
152
|
+
const knownTypes = resolveKnown(known);
|
|
153
|
+
if (knownTypes === null || !Array.isArray(elements)) return [];
|
|
154
|
+
|
|
155
|
+
const found: UnknownElementType[] = [];
|
|
156
|
+
|
|
157
|
+
const visit = (node: unknown, path: string): void => {
|
|
158
|
+
if (!isRecord(node)) return;
|
|
159
|
+
if (isUnknownElement(node, knownTypes)) {
|
|
160
|
+
found.push({
|
|
161
|
+
path,
|
|
162
|
+
elementId: typeof node.id === "string" ? node.id : "(no id)",
|
|
163
|
+
elementType: node.type as string,
|
|
164
|
+
});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(node.children)) {
|
|
168
|
+
node.children.forEach((child, i) => visit(child, `${path}.children[${i}]`));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
elements.forEach((element, i) => visit(element, `${basePath}[${i}]`));
|
|
173
|
+
return found;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/** Same check across a whole steps array, for a caller holding a fetched onboarding. */
|
|
177
|
+
export const collectUnknownElementTypesInSteps = (
|
|
178
|
+
steps: unknown,
|
|
179
|
+
known?: ReadonlySet<string>
|
|
180
|
+
): UnknownElementType[] => {
|
|
181
|
+
if (!Array.isArray(steps)) return [];
|
|
182
|
+
return steps.flatMap((step, i) => {
|
|
183
|
+
if (!isRecord(step)) return [];
|
|
184
|
+
const payload = step.payload;
|
|
185
|
+
if (!isRecord(payload) || !Array.isArray(payload.elements)) return [];
|
|
186
|
+
const stepId = typeof step.id === "string" ? step.id : String(i);
|
|
187
|
+
return collectUnknownElementTypes(payload.elements, `step[${stepId}].elements`, known);
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** Human-readable report; returns "" when there is nothing to say. */
|
|
192
|
+
export const formatUnknownElementTypes = (found: UnknownElementType[]): string => {
|
|
193
|
+
if (found.length === 0) return "";
|
|
194
|
+
const lines = found.map(
|
|
195
|
+
(f) => ` • ${f.path} ("${f.elementId}"): element type "${f.elementType}"`
|
|
196
|
+
);
|
|
197
|
+
return (
|
|
198
|
+
`[onboarding] ${found.length} element${found.length === 1 ? "" : "s"} ` +
|
|
199
|
+
`${found.length === 1 ? "uses a type" : "use types"} this SDK build does not know, ` +
|
|
200
|
+
`so ${found.length === 1 ? "it is" : "they are"} omitted and the rest of the screen ` +
|
|
201
|
+
`renders. Upgrade to a newer @rocapine/react-native-onboarding to render ` +
|
|
202
|
+
`${found.length === 1 ? "it" : "them"}:\n${lines.join("\n")}`
|
|
203
|
+
);
|
|
204
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { deriveVariantKeySets, getElementRegistry } from "./elementTypeRegistry";
|
|
2
|
+
import { ButtonActionSchema } from "../steps/common.types";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* Detection for keys
|
|
5
|
-
*
|
|
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 { UIElementSchema } from "./types";
|
|
|
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`
|
|
20
|
-
* rather than hardcoded, so they cannot drift as elements
|
|
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,52 +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;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (def.type === "union") return (def.options ?? []).flatMap(literalsOf);
|
|
68
|
-
return [];
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
let registry: Map<string, ElementKeySets> | null = null;
|
|
72
|
-
|
|
73
|
-
// Built once, lazily. Any shape change in zod's internals degrades to "no
|
|
74
|
-
// registry", which makes the whole feature a no-op rather than a crash — this is
|
|
75
|
-
// a diagnostic, it must never be able to break rendering.
|
|
76
|
-
const getRegistry = (): Map<string, ElementKeySets> => {
|
|
77
|
-
if (registry) return registry;
|
|
78
|
-
const built = new Map<string, ElementKeySets>();
|
|
79
|
-
try {
|
|
80
|
-
const lazyDef = zdef(UIElementSchema);
|
|
81
|
-
const union = typeof lazyDef?.getter === "function" ? lazyDef.getter() : UIElementSchema;
|
|
82
|
-
const options = zdef(union)?.options ?? [];
|
|
83
|
-
for (const option of options) {
|
|
84
|
-
const shape = zdef(option)?.shape;
|
|
85
|
-
if (!shape) continue;
|
|
86
|
-
const propsShape = zdef(shape.props)?.shape ?? {};
|
|
87
|
-
const keySets: ElementKeySets = {
|
|
88
|
-
topLevel: new Set(Object.keys(shape)),
|
|
89
|
-
props: new Set(Object.keys(propsShape)),
|
|
90
|
-
};
|
|
91
|
-
for (const typeName of literalsOf(shape.type)) built.set(typeName, keySets);
|
|
92
|
-
}
|
|
93
|
-
} catch {
|
|
94
|
-
// fall through to whatever was built before the failure
|
|
95
|
-
}
|
|
96
|
-
registry = built;
|
|
97
|
-
return registry;
|
|
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;
|
|
98
74
|
};
|
|
99
75
|
|
|
100
76
|
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
@@ -113,18 +89,79 @@ const valuesDiffer = (a: unknown, b: unknown): boolean => {
|
|
|
113
89
|
}
|
|
114
90
|
};
|
|
115
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
|
+
|
|
116
150
|
/**
|
|
117
151
|
* Walk an element tree and report unrecognized top-level keys.
|
|
118
152
|
*
|
|
119
153
|
* Elements whose `type` isn't in the schema are skipped rather than reported —
|
|
120
|
-
*
|
|
121
|
-
*
|
|
154
|
+
* guessing the key set of an element this build has never heard of would produce
|
|
155
|
+
* noise. Unknown element TYPES are their own concern, handled in
|
|
156
|
+
* `./unknownElementTypes.ts`: the render boundaries omit them so a screen
|
|
157
|
+
* published ahead of the installed SDK still renders (#209). Both files derive
|
|
158
|
+
* "known" from the same `./elementTypeRegistry.ts`.
|
|
122
159
|
*/
|
|
123
160
|
export const collectUnknownElementKeys = (
|
|
124
161
|
elements: unknown,
|
|
125
162
|
basePath = "elements"
|
|
126
163
|
): UnknownElementKey[] => {
|
|
127
|
-
const known =
|
|
164
|
+
const known = getElementRegistry();
|
|
128
165
|
if (known.size === 0 || !Array.isArray(elements)) return [];
|
|
129
166
|
|
|
130
167
|
const found: UnknownElementKey[] = [];
|
|
@@ -154,6 +191,17 @@ export const collectUnknownElementKeys = (
|
|
|
154
191
|
}
|
|
155
192
|
}
|
|
156
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
|
+
|
|
157
205
|
// Recurse regardless of whether this node was recognized, so a stray key
|
|
158
206
|
// nested under an unknown-typed parent is still found.
|
|
159
207
|
if (Array.isArray(node.children)) {
|
|
@@ -197,14 +245,29 @@ export const formatUnknownElementKeys = (found: UnknownElementKey[]): string =>
|
|
|
197
245
|
: ` • ${where}: "${f.key}" is ignored — ${f.suggestion} is already set to the ` +
|
|
198
246
|
`same value and is the one taking effect. Delete this top-level copy.`;
|
|
199
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
|
+
}
|
|
200
257
|
if (f.kind === "misplaced") {
|
|
201
258
|
return ` • ${where}: "${f.key}" is not a top-level key — did you mean ${f.suggestion}?`;
|
|
202
259
|
}
|
|
203
260
|
return ` • ${where}: unrecognized top-level key "${f.key}"`;
|
|
204
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";
|
|
205
268
|
return (
|
|
206
|
-
`[onboarding] ${found.length} unrecognized
|
|
207
|
-
`${found.length === 1 ? "key" : "keys"}
|
|
269
|
+
`[onboarding] ${found.length} unrecognized ` +
|
|
270
|
+
`${found.length === 1 ? "key" : "keys"} ${scopeLabel}. These are silently ` +
|
|
208
271
|
`dropped when the payload is parsed, so they have no effect:\n` +
|
|
209
272
|
lines.join("\n")
|
|
210
273
|
);
|