@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
package/src/products/index.ts
CHANGED
|
@@ -20,5 +20,6 @@ export { ProductRuntimeContext, useProductRuntime } from "./ProductRuntimeContex
|
|
|
20
20
|
export { stubProductProvider } from "./adapters/stub";
|
|
21
21
|
export { revenueCatProductProvider } from "./adapters/revenueCat";
|
|
22
22
|
export { expoIapProductProvider } from "./adapters/expoIap";
|
|
23
|
+
export type { ExpoIapProviderOptions, ExpoIapProvider } from "./adapters/expoIap";
|
|
23
24
|
export { stripeLinkProductProvider } from "./adapters/stripeLink";
|
|
24
25
|
export type { StripeLinkProviderConfig } from "./adapters/stripeLink";
|
package/src/products/types.ts
CHANGED
|
@@ -122,4 +122,17 @@ export type ProductRuntime = {
|
|
|
122
122
|
purchasing: boolean;
|
|
123
123
|
purchase: (key: string) => Promise<PurchaseResult>;
|
|
124
124
|
restore: () => Promise<RestoreResult>;
|
|
125
|
+
/**
|
|
126
|
+
* `true` once the paywall presentation this runtime was published for has
|
|
127
|
+
* left the screen. Only `PaywallProvider` sets it, on the runtime it
|
|
128
|
+
* publishes while a `present()` paywall is showing; absent everywhere else,
|
|
129
|
+
* which means "never ended".
|
|
130
|
+
*
|
|
131
|
+
* A `purchase` through an ended runtime is refused: the store is not opened
|
|
132
|
+
* and it resolves `{ status: "cancelled" }`. The action engine checks this
|
|
133
|
+
* BEFORE calling `purchase` and ends the whole action chain instead, so a
|
|
134
|
+
* paywall's stale chain runs none of `onSuccess`/`onCancel`/`onError`/
|
|
135
|
+
* `onPending` and no action after it.
|
|
136
|
+
*/
|
|
137
|
+
presentationEnded?: () => boolean;
|
|
125
138
|
};
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Can the user still get off this screen?" — the guard the unknown-element
|
|
3
|
+
* strip needs (#209).
|
|
4
|
+
*
|
|
5
|
+
* A ComposableScreen's CTA is authored INSIDE the element tree.
|
|
6
|
+
* `ComposableScreenRenderer` passes no `button` to `OnboardingTemplate`, so
|
|
7
|
+
* `runActions` — reached only from something the user can press in that tree —
|
|
8
|
+
* is the single path to `onContinue`. Drop the element that happens to be the
|
|
9
|
+
* screen's root container and the payload still parses, to `elements: []`: a
|
|
10
|
+
* blank screen with no CTA, and on a `displayProgressHeader: false` step no back
|
|
11
|
+
* chevron either. Stripping would then have replaced a throw that at least
|
|
12
|
+
* reached `componentDidCatch` with a silent dead end, which is worse.
|
|
13
|
+
*
|
|
14
|
+
* So the renderer asks this before it renders a stripped tree, and supplies its
|
|
15
|
+
* own escape when the answer is no — the same choice the two existing
|
|
16
|
+
* boundaries make: an unknown *step* type renders a Continue button
|
|
17
|
+
* (`OnboardingPage`), and a paywall whose elements fail to parse calls
|
|
18
|
+
* `onContinue()` "so the user is not trapped" (`Pages/Paywall/Renderer`).
|
|
19
|
+
*
|
|
20
|
+
* WHAT COUNTS. `runActions` calls `onContinue` for exactly two actions —
|
|
21
|
+
* `"continue"` and `{type:"dismiss"}` — so those two, wherever a press can
|
|
22
|
+
* reach them, are the whole definition. Two exceptions to "wherever":
|
|
23
|
+
* `requestPermission` and `custom` are read with AND across their outcome hooks
|
|
24
|
+
* rather than OR (see `permissionAskCompletes` and `customActionEscapes`),
|
|
25
|
+
* because neither a grant nor a backend's answer is the user's to give — a
|
|
26
|
+
* `"continue"` sitting only in `onGranted`/`onResolve` strands everyone on the
|
|
27
|
+
* other branch. Everything else (`setVariable`, `presentPaywall`) leaves the
|
|
28
|
+
* user on the screen as far as this SDK can tell, and is not counted.
|
|
29
|
+
*
|
|
30
|
+
* The walk deliberately errs toward "no": an unrecognised action shape, or a
|
|
31
|
+
* `continue` somewhere the runtime would not actually run it, reads as no way
|
|
32
|
+
* forward. A redundant escape CTA on an already-degraded screen is a cosmetic
|
|
33
|
+
* cost; a missed one is the trap this exists to close.
|
|
34
|
+
*
|
|
35
|
+
* NOT CONSIDERED: `renderWhen`. A CTA the author gated behind a condition may
|
|
36
|
+
* be hidden at runtime, but that is authored intent evaluated against live
|
|
37
|
+
* variables, not something a static payload walk can or should second-guess.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
41
|
+
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Element types whose renderer owns its own press handling, so the generic
|
|
45
|
+
* `onPress` from `BaseBoxProps` is never wired for them.
|
|
46
|
+
*
|
|
47
|
+
* Mirrors `PRESS_HANDLED_TYPES` in `renderElement.tsx` — the UI package cannot
|
|
48
|
+
* be imported here, so the two lists are held equal by a source-level test in
|
|
49
|
+
* `packages/onboarding-ui/src/UI/Runtime/__tests__/unknownElementTypes.test.ts`.
|
|
50
|
+
* Counting an ignored `onPress` as a way forward would leave a user trapped on a
|
|
51
|
+
* screen whose only remaining "CTA" the runtime never dispatches.
|
|
52
|
+
*/
|
|
53
|
+
const PRESS_HANDLED_TYPES: ReadonlySet<string> = new Set([
|
|
54
|
+
"Button",
|
|
55
|
+
"RadioGroup",
|
|
56
|
+
"CheckboxGroup",
|
|
57
|
+
"DatePicker",
|
|
58
|
+
"Input",
|
|
59
|
+
"WheelPicker",
|
|
60
|
+
"DrawingPad",
|
|
61
|
+
"Slider",
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* WHICH completing action a press can reach, not just whether it can reach one.
|
|
66
|
+
*
|
|
67
|
+
* `runActions` needs the kind, not the boolean: when it stands in for an ask
|
|
68
|
+
* whose module is missing it has to call `complete` the way the AUTHOR'S OWN
|
|
69
|
+
* escape would have (review round 2, finding 1 — a bare `onContinue()` walked
|
|
70
|
+
* the user through a hard paywall gate that the authored `{dismiss}` would have
|
|
71
|
+
* held shut). One walk answers both questions, so the two cannot disagree.
|
|
72
|
+
*/
|
|
73
|
+
export type EscapeAction = "continue" | "dismiss";
|
|
74
|
+
|
|
75
|
+
const union = (...sets: ReadonlySet<EscapeAction>[]): Set<EscapeAction> => {
|
|
76
|
+
const out = new Set<EscapeAction>();
|
|
77
|
+
for (const s of sets) for (const v of s) out.add(v);
|
|
78
|
+
return out;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Every completing action reachable through one list — directly, or nested in
|
|
83
|
+
* one of an action's branch lists (`purchase.onSuccess`,
|
|
84
|
+
* `restore.onNothingToRestore`, …).
|
|
85
|
+
*
|
|
86
|
+
* Branch lists are found by shape rather than by name, so a branch added to
|
|
87
|
+
* `purchase`/`restore` later is covered without a change here.
|
|
88
|
+
*/
|
|
89
|
+
const listEscapes = (value: unknown): Set<EscapeAction> => {
|
|
90
|
+
if (!Array.isArray(value)) return new Set<EscapeAction>();
|
|
91
|
+
const before = new Set<EscapeAction>();
|
|
92
|
+
for (let i = 0; i < value.length; i++) {
|
|
93
|
+
const action = value[i];
|
|
94
|
+
// `custom` is a BARRIER, not just another item: it is the one action whose
|
|
95
|
+
// OWN escape has to be read with AND (see `customActionEscapes`), and the
|
|
96
|
+
// actions after it are reachable on each of its paths, so they belong to
|
|
97
|
+
// both terms of that conjunction rather than being counted on their own.
|
|
98
|
+
// They are handed on as `rest`.
|
|
99
|
+
//
|
|
100
|
+
// Everything BEFORE the barrier keeps the plain OR reading, for a different
|
|
101
|
+
// reason: a completing action there returns from `runActions` before the
|
|
102
|
+
// handler is ever called, so it does not depend on the handler's outcome.
|
|
103
|
+
if (isRecord(action) && action.type === "custom") {
|
|
104
|
+
return union(before, customActionEscapes(action, value.slice(i + 1)));
|
|
105
|
+
}
|
|
106
|
+
for (const escape of actionEscapes(action)) before.add(escape);
|
|
107
|
+
}
|
|
108
|
+
return before;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const listCompletes = (value: unknown): boolean => listEscapes(value).size > 0;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* `requestPermission` is the one action read with AND rather than OR, because
|
|
115
|
+
* its outcome is not the user's to choose.
|
|
116
|
+
*
|
|
117
|
+
* `runActions` has exactly three paths: a grant runs `onGranted`, a refusal
|
|
118
|
+
* runs `onDenied`, and "this build cannot ask" runs `onUnavailable` when
|
|
119
|
+
* declared. All of them have to reach a `"continue"` / `{dismiss}` for the ask
|
|
120
|
+
* to be a way OFF the screen — a CTA whose only `"continue"` sits in
|
|
121
|
+
* `onGranted` strands everyone who refuses.
|
|
122
|
+
*
|
|
123
|
+
* The third path is the one the runtime rescues by itself: with no
|
|
124
|
+
* `onUnavailable` declared it completes the screen rather than running
|
|
125
|
+
* `onDenied` (review round 1 of #196 — the old fallback recorded a refusal the
|
|
126
|
+
* user was never asked for, and rescued nobody when `onDenied` was absent too).
|
|
127
|
+
* So a declared-but-dead `onUnavailable` still reads as a trap here, while its
|
|
128
|
+
* ABSENCE no longer does.
|
|
129
|
+
*
|
|
130
|
+
* `purchase` / `restore` keep the generic OR reading on purpose: a cancelled
|
|
131
|
+
* purchase leaves the user free to press again, whereas a standing OS denial is
|
|
132
|
+
* final for the life of the install. Not symmetric, so not shared.
|
|
133
|
+
*
|
|
134
|
+
* Mirrors the runtime's own shape (`runActions.ts` — `onUnavailable` present but
|
|
135
|
+
* empty runs nothing, exactly as an empty array does here).
|
|
136
|
+
*/
|
|
137
|
+
const permissionAskEscapes = (
|
|
138
|
+
action: Record<string, unknown>
|
|
139
|
+
): Set<EscapeAction> => {
|
|
140
|
+
const onGranted = listEscapes(action.onGranted);
|
|
141
|
+
const onDenied = listEscapes(action.onDenied);
|
|
142
|
+
// Absent `onUnavailable`: the runtime completes the screen itself iff the
|
|
143
|
+
// author put a completing action somewhere in the ask — the same
|
|
144
|
+
// `actionsCanComplete(onGranted) || actionsCanComplete(onDenied)` test
|
|
145
|
+
// `runActions` runs. Written out rather than folded into the conjunction
|
|
146
|
+
// below, so this stays readable as the runtime's three paths.
|
|
147
|
+
const onUnavailable = action.onUnavailable
|
|
148
|
+
? listEscapes(action.onUnavailable)
|
|
149
|
+
: union(onGranted, onDenied);
|
|
150
|
+
if (!onGranted.size || !onDenied.size || !onUnavailable.size)
|
|
151
|
+
return new Set<EscapeAction>();
|
|
152
|
+
return union(onGranted, onDenied, onUnavailable);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const permissionAskCompletes = (action: Record<string, unknown>): boolean =>
|
|
156
|
+
permissionAskEscapes(action).size > 0;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* `custom` is the second AND-read action, for the same reason (#191, review
|
|
160
|
+
* round 1, finding 6): its outcome is the service's, not the user's.
|
|
161
|
+
*
|
|
162
|
+
* RE-DERIVED from the semantics decision of 2026-09-11 (recorded on #191, and
|
|
163
|
+
* the subject of #266), which removed the abort a thrown handler used to
|
|
164
|
+
* perform. `runActions` now has exactly TWO paths, and `rest` — whatever
|
|
165
|
+
* follows the action in the same list — is reachable from both:
|
|
166
|
+
*
|
|
167
|
+
* - the handler RESOLVES: `onResolve` runs, then `rest`;
|
|
168
|
+
* - the handler FAILS: `onError` runs, then `rest`. One rule for every way of
|
|
169
|
+
* failing — a throw with every retry spent, an attempt that never settled
|
|
170
|
+
* (`retry.timeoutMs`), and a `function` name the host never registered.
|
|
171
|
+
*
|
|
172
|
+
* So the escape set is `onResolve ∪ rest` AND `onError ∪ rest`, both non-empty.
|
|
173
|
+
*
|
|
174
|
+
* THE CONJUNCTION IS NOW COMPLETE, and that is the whole change here. The same
|
|
175
|
+
* two terms used to be a JUDGEMENT: there was a third path (throw → `onError`
|
|
176
|
+
* → abort, `rest` unreachable) that was deliberately left out of the
|
|
177
|
+
* conjunction, on the argument that a throw is the one outcome a user can talk
|
|
178
|
+
* out of by pressing again — the reading `purchase`/`restore` get. That
|
|
179
|
+
* argument was load-bearing and is now moot: the third path does not exist, so
|
|
180
|
+
* nothing is being excluded and no retryability argument is needed to justify
|
|
181
|
+
* the answer.
|
|
182
|
+
*
|
|
183
|
+
* WHAT THAT RESCUES. `[{custom}, "continue"]` — the shape an author writes when
|
|
184
|
+
* the CTA fires a handler and then moves on, and the ONLY `custom` shape Studio
|
|
185
|
+
* can author until `rocapine/onboarding-studio#288` lands — is a way off the
|
|
186
|
+
* screen on EVERY path, not on two of three. Round 2 of this PR required
|
|
187
|
+
* `onError` there and so read every such payload in the field as a trap,
|
|
188
|
+
* bolting a duplicate escape CTA onto any screen that had also been stripped
|
|
189
|
+
* (#209) plus a `console.error` naming a trap that was not one. Pinned by
|
|
190
|
+
* `onboarding-ui/src/UI/Runtime/__tests__/mergeBaseEscapeParity.test.ts`, which
|
|
191
|
+
* runs verbatim against this PR's merge base, and by
|
|
192
|
+
* `onboarding-ui/src/UI/Runtime/__tests__/customActionEscapeCoherence.test.ts`,
|
|
193
|
+
* which runs this walk and `runActions` against the same payloads and requires
|
|
194
|
+
* them to agree — the check that was missing while the two disagreed.
|
|
195
|
+
*
|
|
196
|
+
* What round 1, finding 6 established SURVIVES, and the decision does not touch
|
|
197
|
+
* it: a `"continue"` in `onResolve` alone is still not a way off the screen,
|
|
198
|
+
* because the failure path is then empty — and `customActions: {}` is
|
|
199
|
+
* `ScreenHost`'s own default, so that is not a hypothetical host. (#266 costed
|
|
200
|
+
* this decision as "reverts to the generic OR walk"; it does not. OR would
|
|
201
|
+
* credit that `onResolve` and re-open finding 6. What the decision removes is
|
|
202
|
+
* the third term, which was never in the code.)
|
|
203
|
+
*
|
|
204
|
+
* WHY `rest` STILL GOES THROUGH BOTH TERMS rather than being OR-ed on its own:
|
|
205
|
+
* the two readings agree on the boolean, but not on WHICH escape is reachable,
|
|
206
|
+
* and `completingActionKind` spends that answer. With `onResolve: [{dismiss}]`,
|
|
207
|
+
* no `onError` and a trailing `"continue"`, OR-ing `rest` separately loses the
|
|
208
|
+
* reachable `{dismiss}` and the runtime would substitute the more permissive
|
|
209
|
+
* advance — the review-round-2 finding-1 bug, one level down.
|
|
210
|
+
*/
|
|
211
|
+
const customActionEscapes = (
|
|
212
|
+
action: Record<string, unknown>,
|
|
213
|
+
rest: readonly unknown[] = []
|
|
214
|
+
): Set<EscapeAction> => {
|
|
215
|
+
const afterwards = listEscapes(rest);
|
|
216
|
+
const resolved = union(listEscapes(action.onResolve), afterwards);
|
|
217
|
+
const failed = union(listEscapes(action.onError), afterwards);
|
|
218
|
+
if (!resolved.size || !failed.size) return new Set<EscapeAction>();
|
|
219
|
+
return union(resolved, failed);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const actionEscapes = (action: unknown): Set<EscapeAction> => {
|
|
223
|
+
// `ButtonActionSchema` declares continue as the string literal, not an
|
|
224
|
+
// object: `{type:"continue"}` is not an action the runtime runs.
|
|
225
|
+
if (action === "continue") return new Set<EscapeAction>(["continue"]);
|
|
226
|
+
if (!isRecord(action)) return new Set<EscapeAction>();
|
|
227
|
+
if (action.type === "dismiss") return new Set<EscapeAction>(["dismiss"]);
|
|
228
|
+
if (action.type === "requestPermission") return permissionAskEscapes(action);
|
|
229
|
+
if (action.type === "custom") return customActionEscapes(action);
|
|
230
|
+
return union(...Object.values(action).map(listEscapes));
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const nodeCanComplete = (node: unknown): boolean => {
|
|
234
|
+
if (!isRecord(node)) return false;
|
|
235
|
+
const props = isRecord(node.props) ? node.props : undefined;
|
|
236
|
+
if (props) {
|
|
237
|
+
if (props.actions != null) {
|
|
238
|
+
// `Button` reads `actions ?? (action === "continue" ? …)`, so a present
|
|
239
|
+
// `actions` shadows the deprecated shorthand — even when it is empty.
|
|
240
|
+
//
|
|
241
|
+
// Read as ONE list, not action-by-action: order matters, because an
|
|
242
|
+
// action BEFORE a `custom` runs whatever the handler does, while one
|
|
243
|
+
// AFTER it has to satisfy both terms of that action's conjunction.
|
|
244
|
+
// `.some(isCompletingAction)` could express neither, and credited a
|
|
245
|
+
// `"continue"` inside an `onResolve` hook it never looked at the
|
|
246
|
+
// reachability of at all.
|
|
247
|
+
if (listCompletes(props.actions)) return true;
|
|
248
|
+
} else if (props.action === "continue") {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
if (
|
|
252
|
+
!PRESS_HANDLED_TYPES.has(String(node.type)) &&
|
|
253
|
+
listCompletes(props.onPress)
|
|
254
|
+
) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return Array.isArray(node.children) && node.children.some(nodeCanComplete);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Whether anything in this element tree can complete the screen.
|
|
263
|
+
*
|
|
264
|
+
* Pure, linear, and total: any malformed input (non-array, `null` nodes,
|
|
265
|
+
* non-record props) answers `false` rather than throwing, because it runs on a
|
|
266
|
+
* payload that has not been parsed yet.
|
|
267
|
+
*/
|
|
268
|
+
export const hasCompletingAction = (elements: unknown): boolean =>
|
|
269
|
+
Array.isArray(elements) && elements.some(nodeCanComplete);
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The same walk over ONE action list rather than a whole element tree.
|
|
273
|
+
*
|
|
274
|
+
* Exists for the runtime, which needs the question answered at press time and
|
|
275
|
+
* had been deciding it by hand: `runActions` reaches "the build cannot ask for
|
|
276
|
+
* this permission and the author declared no `onUnavailable`" and has to choose
|
|
277
|
+
* between logging and moving on, and stranding the user. Whether the press was
|
|
278
|
+
* the screen's only way forward is exactly what this module already knows, so
|
|
279
|
+
* the runtime consults it instead of re-deriving it (review round 1, finding 1).
|
|
280
|
+
*
|
|
281
|
+
* OR across the list — "did the author intend this press to move the user on" —
|
|
282
|
+
* not `permissionAskCompletes`' AND across one ask's outcomes, which answers the
|
|
283
|
+
* stricter "does EVERY outcome move them on". Total on junk for the same reason
|
|
284
|
+
* `hasCompletingAction` is.
|
|
285
|
+
*/
|
|
286
|
+
export const actionsCanComplete = (actions: unknown): boolean => listCompletes(actions);
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* WHICH completing action stands in for a press list — the kind, where
|
|
290
|
+
* `actionsCanComplete` gives only the yes/no.
|
|
291
|
+
*
|
|
292
|
+
* `"dismiss"` wins when the list can reach both, and that preference is the
|
|
293
|
+
* whole reason this exists (review round 2, finding 1). The runtime calls it
|
|
294
|
+
* for one case: a `requestPermission` on a build that cannot ask, with no
|
|
295
|
+
* `onUnavailable` declared. Nobody was asked anything, so the SDK must not
|
|
296
|
+
* claim the more permissive of the two answers the author authored — and the
|
|
297
|
+
* two are not equivalent downstream. `complete()` with no outcome is what
|
|
298
|
+
* `Pages/Paywall/Renderer`'s hard gate reads as "advance"
|
|
299
|
+
* (`shouldAdvanceOnComplete(undefined) === true`), so substituting it for an
|
|
300
|
+
* authored `{dismiss}` handed out paid content to a user who never purchased.
|
|
301
|
+
* `{status:"dismissed"}` is ignored by an onboarding step (it still advances)
|
|
302
|
+
* and resolves a `present()`ed paywall, so preferring it costs nothing on the
|
|
303
|
+
* surfaces where both outcomes mean the same thing, and holds the gate on the
|
|
304
|
+
* one where they do not.
|
|
305
|
+
*
|
|
306
|
+
* `undefined` = this list was never a way off the screen; the runtime then
|
|
307
|
+
* leaves the user where they are rather than inventing an exit.
|
|
308
|
+
*/
|
|
309
|
+
export const completingActionKind = (
|
|
310
|
+
actions: unknown
|
|
311
|
+
): EscapeAction | undefined => {
|
|
312
|
+
const escapes = listEscapes(actions);
|
|
313
|
+
if (escapes.has("dismiss")) return "dismiss";
|
|
314
|
+
if (escapes.has("continue")) return "continue";
|
|
315
|
+
return undefined;
|
|
316
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { UIElementSchema } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The element `type` names this SDK build knows, and the key sets each of them
|
|
5
|
+
* accepts — read off `UIElementSchema` itself at runtime rather than hardcoded,
|
|
6
|
+
* so nothing here can drift as elements are added.
|
|
7
|
+
*
|
|
8
|
+
* Two consumers, deliberately sharing one derivation: `unknownKeys.ts` (which
|
|
9
|
+
* keys it needs) and `unknownElementTypes.ts` (which *types* exist at all).
|
|
10
|
+
* They used to be able to disagree about what "known" means, which for a
|
|
11
|
+
* forward-compatibility strip is not a cosmetic risk: a type the strip thinks
|
|
12
|
+
* is unknown is a type the app silently refuses to render.
|
|
13
|
+
*/
|
|
14
|
+
export type ElementKeySets = { topLevel: Set<string>; props: Set<string> };
|
|
15
|
+
|
|
16
|
+
const zdef = (schema: any): any => schema?._zod?.def ?? schema?._def;
|
|
17
|
+
|
|
18
|
+
// Every string literal a `type` field can hold. Variants use `z.literal("X")`;
|
|
19
|
+
// a `z.union([literal, literal])` is tolerated for robustness.
|
|
20
|
+
const literalsOf = (schema: any): string[] => {
|
|
21
|
+
const def = zdef(schema);
|
|
22
|
+
if (!def) return [];
|
|
23
|
+
if (def.type === "literal") {
|
|
24
|
+
const values = def.values ?? (def.value !== undefined ? [def.value] : []);
|
|
25
|
+
return values.filter((v: unknown): v is string => typeof v === "string");
|
|
26
|
+
}
|
|
27
|
+
if (def.type === "union") return (def.options ?? []).flatMap(literalsOf);
|
|
28
|
+
return [];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The derivation itself, over ANY element union — this package's, or another
|
|
33
|
+
* package's re-declared mirror of it.
|
|
34
|
+
*
|
|
35
|
+
* Kept schema-agnostic because the onboarding-ui package has to derive its own
|
|
36
|
+
* capability set rather than inherit this one's: it re-declares its own
|
|
37
|
+
* `UIElementSchema`, that mirror is what actually parses and renders an element
|
|
38
|
+
* tree, and the peer-dependency range between the two packages lets a host
|
|
39
|
+
* resolve different versions of them. Sharing the mechanism but not the answer
|
|
40
|
+
* is the point — one place that knows how to read a discriminated union, two
|
|
41
|
+
* honest answers about two schemas.
|
|
42
|
+
*/
|
|
43
|
+
const buildElementRegistry = (schema: unknown): Map<string, ElementKeySets> => {
|
|
44
|
+
const built = new Map<string, ElementKeySets>();
|
|
45
|
+
try {
|
|
46
|
+
const lazyDef = zdef(schema);
|
|
47
|
+
const union = typeof lazyDef?.getter === "function" ? lazyDef.getter() : schema;
|
|
48
|
+
const options = zdef(union)?.options ?? [];
|
|
49
|
+
for (const option of options) {
|
|
50
|
+
const shape = zdef(option)?.shape;
|
|
51
|
+
if (!shape) continue;
|
|
52
|
+
const propsShape = zdef(shape.props)?.shape ?? {};
|
|
53
|
+
const keySets: ElementKeySets = {
|
|
54
|
+
topLevel: new Set(Object.keys(shape)),
|
|
55
|
+
props: new Set(Object.keys(propsShape)),
|
|
56
|
+
};
|
|
57
|
+
for (const typeName of literalsOf(shape.type)) built.set(typeName, keySets);
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
// fall through to whatever was built before the failure
|
|
61
|
+
}
|
|
62
|
+
return built;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The same union reading, one level shallower: a `type`-discriminated union's
|
|
67
|
+
* variant name → the key set that variant declares.
|
|
68
|
+
*
|
|
69
|
+
* Serves the `ButtonAction` union (`unknownKeys.ts`, so a misspelled
|
|
70
|
+
* `purchase.onSucces` / `requestPermission.onDeneid` can be reported rather
|
|
71
|
+
* than silently stripped). It lives beside the element derivation because this
|
|
72
|
+
* file is the one place that knows how to read zod's internals — duplicating
|
|
73
|
+
* `zdef` would give us two things to fix the next time they move.
|
|
74
|
+
*
|
|
75
|
+
* EMPTY means "could not tell", and every caller must read it that way: this
|
|
76
|
+
* only ever feeds diagnostics, never a reject.
|
|
77
|
+
*/
|
|
78
|
+
export const deriveVariantKeySets = (schema: unknown): Map<string, ReadonlySet<string>> => {
|
|
79
|
+
const built = new Map<string, ReadonlySet<string>>();
|
|
80
|
+
try {
|
|
81
|
+
const lazyDef = zdef(schema);
|
|
82
|
+
const union = typeof lazyDef?.getter === "function" ? lazyDef.getter() : schema;
|
|
83
|
+
for (const option of zdef(union)?.options ?? []) {
|
|
84
|
+
const optionDef = zdef(option);
|
|
85
|
+
// A union member may itself be lazy (the recursive action variants are).
|
|
86
|
+
const resolved =
|
|
87
|
+
typeof optionDef?.getter === "function" ? optionDef.getter() : option;
|
|
88
|
+
const shape = zdef(resolved)?.shape;
|
|
89
|
+
if (!shape) continue;
|
|
90
|
+
const keys = new Set(Object.keys(shape));
|
|
91
|
+
for (const name of literalsOf(shape.type)) built.set(name, keys);
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
// fall through to whatever was built before the failure
|
|
95
|
+
}
|
|
96
|
+
return built;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Every element `type` a given element union declares. EMPTY means "could not
|
|
101
|
+
* tell" — zod internals moved, or this is not an element union — and every
|
|
102
|
+
* caller must read it as "learn nothing" rather than "reject everything", which
|
|
103
|
+
* would blank every screen in every app.
|
|
104
|
+
*/
|
|
105
|
+
export const deriveElementTypeNames = (schema: unknown): ReadonlySet<string> =>
|
|
106
|
+
new Set(buildElementRegistry(schema).keys());
|
|
107
|
+
|
|
108
|
+
let registry: Map<string, ElementKeySets> | null = null;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Built once, lazily, from THIS package's schema. Any shape change in zod's
|
|
112
|
+
* internals degrades to an EMPTY registry, read as "learn nothing" — this is a
|
|
113
|
+
* diagnostic and a forward-compat aid, it must never be able to break rendering.
|
|
114
|
+
*/
|
|
115
|
+
export const getElementRegistry = (): Map<string, ElementKeySets> => {
|
|
116
|
+
if (registry) return registry;
|
|
117
|
+
registry = buildElementRegistry(UIElementSchema);
|
|
118
|
+
return registry;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Every element `type` this build can parse. Empty means "could not tell". */
|
|
122
|
+
export const getKnownElementTypes = (): ReadonlySet<string> => new Set(getElementRegistry().keys());
|
|
@@ -16,8 +16,15 @@ import {
|
|
|
16
16
|
export {
|
|
17
17
|
type CustomButtonAction,
|
|
18
18
|
CustomButtonActionSchema,
|
|
19
|
+
type CustomActionRetry,
|
|
20
|
+
CustomActionRetrySchema,
|
|
19
21
|
type SetVariableButtonAction,
|
|
20
22
|
SetVariableButtonActionSchema,
|
|
23
|
+
type RequestPermissionButtonAction,
|
|
24
|
+
RequestPermissionButtonActionSchema,
|
|
25
|
+
type PermissionKind,
|
|
26
|
+
PermissionKindSchema,
|
|
27
|
+
PERMISSION_KINDS,
|
|
21
28
|
} from "../../steps/common.types";
|
|
22
29
|
export type { ButtonAction };
|
|
23
30
|
export { ButtonActionSchema };
|
|
@@ -40,7 +47,8 @@ export type ButtonElementProps = BaseBoxProps & {
|
|
|
40
47
|
label: string;
|
|
41
48
|
/**
|
|
42
49
|
* Ordered list of actions to run on press. Sequential, await async handlers,
|
|
43
|
-
*
|
|
50
|
+
* `"continue"` is terminal. A failing action runs its own `onError` hook and
|
|
51
|
+
* the list carries on.
|
|
44
52
|
*/
|
|
45
53
|
actions?: ButtonAction[];
|
|
46
54
|
/**
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { hasCompletingAction } from "./completingActions";
|
|
2
|
+
import {
|
|
3
|
+
collectUnknownElementTypes,
|
|
4
|
+
dropUnknownElementTypesInStep,
|
|
5
|
+
type UnknownElementType,
|
|
6
|
+
} from "./unknownElementTypes";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The whole render-boundary decision for element-type forward compatibility
|
|
10
|
+
* (#209): what to parse, what to log, and whether the renderer must supply its
|
|
11
|
+
* own way off the screen.
|
|
12
|
+
*
|
|
13
|
+
* It lives here rather than in the renderer because the onboarding-ui package's
|
|
14
|
+
* vitest runs in plain Node and cannot import `react-native` — logic decided
|
|
15
|
+
* there is only assertable at source level, and the escape decision is the part
|
|
16
|
+
* of this feature that must not be wrong.
|
|
17
|
+
*/
|
|
18
|
+
export type RenderableStep<T> = {
|
|
19
|
+
/**
|
|
20
|
+
* The step to parse and render. The SAME reference as the input when nothing
|
|
21
|
+
* was stripped, so the common path allocates nothing and stays `useMemo`-stable.
|
|
22
|
+
*/
|
|
23
|
+
step: T;
|
|
24
|
+
/** The elements omitted, for the log. Empty when nothing was stripped. */
|
|
25
|
+
omitted: UnknownElementType[];
|
|
26
|
+
/**
|
|
27
|
+
* The strip left nothing in the tree that can complete the screen, so the
|
|
28
|
+
* renderer must supply an escape of its own — otherwise the user sits on a
|
|
29
|
+
* screen with no CTA and, on a `displayProgressHeader: false` step, no back
|
|
30
|
+
* chevron: the dead end #209 exists to close, re-created silently.
|
|
31
|
+
*
|
|
32
|
+
* Only ever true when something WAS stripped. An authored screen with no way
|
|
33
|
+
* forward is an authoring bug (and the host may advance it another way, e.g. a
|
|
34
|
+
* custom action that navigates); injecting a CTA into shipped screens that
|
|
35
|
+
* have nothing to do with an unknown element type is not this feature's call.
|
|
36
|
+
*/
|
|
37
|
+
needsEscape: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param step A step as fetched, unparsed.
|
|
42
|
+
* @param known The element types the CALLER can render — the renderer's own
|
|
43
|
+
* capability, not this package's schema. The two are separate packages with a
|
|
44
|
+
* peer-dependency range between them, so their versions can legitimately
|
|
45
|
+
* differ, and it is what draws that must decide what is kept. An empty set
|
|
46
|
+
* means "could not tell" and strips nothing.
|
|
47
|
+
*/
|
|
48
|
+
export const resolveRenderableStep = <T>(step: T, known?: ReadonlySet<string>): RenderableStep<T> => {
|
|
49
|
+
const renderable = dropUnknownElementTypesInStep(step, known);
|
|
50
|
+
if (renderable === step) return { step, omitted: [], needsEscape: false };
|
|
51
|
+
|
|
52
|
+
const authoredElements = (step as { payload?: { elements?: unknown } })?.payload?.elements;
|
|
53
|
+
const renderableElements = (renderable as { payload?: { elements?: unknown } })?.payload?.elements;
|
|
54
|
+
return {
|
|
55
|
+
step: renderable,
|
|
56
|
+
omitted: collectUnknownElementTypes(authoredElements, "elements", known),
|
|
57
|
+
needsEscape: !hasCompletingAction(renderableElements),
|
|
58
|
+
};
|
|
59
|
+
};
|
package/src/screens/types.ts
CHANGED
|
@@ -72,8 +72,8 @@ export type { RiveElementProps } from "./elements/RiveElement";
|
|
|
72
72
|
export type { IconElementProps } from "./elements/IconElement";
|
|
73
73
|
export type { VideoElementProps } from "./elements/VideoElement";
|
|
74
74
|
export type { InputElementProps } from "./elements/InputElement";
|
|
75
|
-
export type { ButtonElementProps, ButtonAction, CustomButtonAction, SetVariableButtonAction } from "./elements/ButtonElement";
|
|
76
|
-
export { ButtonActionSchema, CustomButtonActionSchema, SetVariableButtonActionSchema } from "./elements/ButtonElement";
|
|
75
|
+
export type { ButtonElementProps, ButtonAction, CustomButtonAction, CustomActionRetry, SetVariableButtonAction, RequestPermissionButtonAction, PermissionKind } from "./elements/ButtonElement";
|
|
76
|
+
export { ButtonActionSchema, CustomButtonActionSchema, CustomActionRetrySchema, SetVariableButtonActionSchema, RequestPermissionButtonActionSchema, PermissionKindSchema, PERMISSION_KINDS } from "./elements/ButtonElement";
|
|
77
77
|
export type { RadioGroupElementProps } from "./elements/RadioGroupElement";
|
|
78
78
|
export type { CheckboxGroupElementProps } from "./elements/CheckboxGroupElement";
|
|
79
79
|
export type { DatePickerElementProps } from "./elements/DatePickerElement";
|