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