@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
|
@@ -19,11 +19,43 @@ import {
|
|
|
19
19
|
} from "./paywalls/types";
|
|
20
20
|
|
|
21
21
|
import { Platform } from "react-native";
|
|
22
|
+
import { readNativeAppInfo, resolveRequestIdentity } from "./requestIdentity";
|
|
22
23
|
|
|
23
24
|
export class OnboardingStudioClient {
|
|
24
25
|
private baseUrl: string;
|
|
25
26
|
public projectId: string;
|
|
26
27
|
public options: OnboardingStudioClientOptions;
|
|
28
|
+
private identity?: Record<string, string>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `appVersion`, `build`, `sdkVersion`, `environment`: the params this SDK
|
|
32
|
+
* adds to every request (see `requestIdentity.ts`). Memoized: none of them
|
|
33
|
+
* can change while the process runs. Deliberately NOT part of any cache key:
|
|
34
|
+
* a key that changed with every app update would leave a user who is offline
|
|
35
|
+
* right after updating with no cached payload, and would stop a custom
|
|
36
|
+
* `cacheKey` from pinning content across updates.
|
|
37
|
+
*/
|
|
38
|
+
identityParams(): Record<string, string> {
|
|
39
|
+
if (!this.identity) {
|
|
40
|
+
this.identity = resolveRequestIdentity(this.options, readNativeAppInfo());
|
|
41
|
+
}
|
|
42
|
+
return this.identity;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Writes the identity onto a querystring that already holds the user params.
|
|
47
|
+
* `appVersion` and `build` are removed first, because the identity omits them
|
|
48
|
+
* when neither the host nor `expo-application` has a value, and `set` alone
|
|
49
|
+
* would then leave a same-named user param on the wire (a property persisted
|
|
50
|
+
* before these names were reserved is re-read without a reserved-key check).
|
|
51
|
+
*/
|
|
52
|
+
private writeIdentity(urlParams: URLSearchParams): void {
|
|
53
|
+
urlParams.delete("appVersion");
|
|
54
|
+
urlParams.delete("build");
|
|
55
|
+
for (const [key, value] of Object.entries(this.identityParams())) {
|
|
56
|
+
urlParams.set(key, value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
27
59
|
|
|
28
60
|
constructor(projectId: string, options: OnboardingStudioClientOptions) {
|
|
29
61
|
console.info("OnboardingStudioClient init: projectId ", projectId);
|
|
@@ -80,21 +112,20 @@ export class OnboardingStudioClient {
|
|
|
80
112
|
});
|
|
81
113
|
}
|
|
82
114
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
115
|
+
// SDK-owned keys use `set`, never `append`: the server reads each with
|
|
116
|
+
// `searchParams.get`, which returns the FIRST occurrence, so an appended
|
|
117
|
+
// value would lose to a same-named user param added above.
|
|
118
|
+
urlParams.set("projectId", this.projectId);
|
|
119
|
+
urlParams.set("platform", Platform.OS);
|
|
120
|
+
this.writeIdentity(urlParams);
|
|
90
121
|
|
|
91
122
|
if (isSandbox) {
|
|
92
|
-
urlParams.
|
|
123
|
+
urlParams.set("draft", "true");
|
|
93
124
|
}
|
|
94
125
|
|
|
95
126
|
// Add onboardingOptions to URL
|
|
96
127
|
if (onboardingOptions?.locale) {
|
|
97
|
-
urlParams.
|
|
128
|
+
urlParams.set("locale", onboardingOptions.locale);
|
|
98
129
|
}
|
|
99
130
|
|
|
100
131
|
const url = `${this.baseUrl}/get-onboarding-steps?${urlParams.toString()}`;
|
|
@@ -171,27 +202,24 @@ export class OnboardingStudioClient {
|
|
|
171
202
|
});
|
|
172
203
|
}
|
|
173
204
|
|
|
174
|
-
|
|
175
|
-
urlParams.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (appVersion) {
|
|
179
|
-
urlParams.append("appVersion", appVersion);
|
|
180
|
-
}
|
|
205
|
+
// SDK-owned keys use `set`, never `append` (see getSteps).
|
|
206
|
+
urlParams.set("projectId", this.projectId);
|
|
207
|
+
urlParams.set("platform", Platform.OS);
|
|
208
|
+
this.writeIdentity(urlParams);
|
|
181
209
|
|
|
182
210
|
if (isSandbox) {
|
|
183
|
-
urlParams.
|
|
211
|
+
urlParams.set("draft", "true");
|
|
184
212
|
}
|
|
185
213
|
|
|
186
214
|
// Add paywallOptions to URL
|
|
187
215
|
if (paywallOptions?.locale) {
|
|
188
|
-
urlParams.
|
|
216
|
+
urlParams.set("locale", paywallOptions.locale);
|
|
189
217
|
}
|
|
190
218
|
|
|
191
219
|
// Narrows the response to a single paywall. Omitted unless explicitly
|
|
192
220
|
// requested — see the method doc above.
|
|
193
221
|
if (paywallOptions?.moment) {
|
|
194
|
-
urlParams.
|
|
222
|
+
urlParams.set("moment", paywallOptions.moment);
|
|
195
223
|
}
|
|
196
224
|
|
|
197
225
|
// Deliberately NOT sending spec §6.1's `omitNulls=true`: it's a
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { actionsCanComplete, hasCompletingAction } from "../screens/completingActions";
|
|
5
|
+
|
|
6
|
+
// The authoring surfaces are prose, so nothing type-checks the payloads they
|
|
7
|
+
// teach against the runtime that reads them — and a `custom` CTA is exactly
|
|
8
|
+
// where that costs something. Reads the docs off disk, the same technique as
|
|
9
|
+
// `unknownElementTypes.test.ts` and `actionSchemaMirror.test.ts` (review round
|
|
10
|
+
// 2 of !263, finding 4).
|
|
11
|
+
|
|
12
|
+
const ROOT = join(__dirname, "../../../..");
|
|
13
|
+
const read = (rel: string): string => readFileSync(join(ROOT, rel), "utf8");
|
|
14
|
+
|
|
15
|
+
/** The fenced code block that contains `marker`, parsed as JSON. */
|
|
16
|
+
const jsonBlockAround = (src: string, rel: string, marker: string): unknown => {
|
|
17
|
+
const at = src.indexOf(marker);
|
|
18
|
+
expect(at, `${rel} no longer mentions ${marker}`).toBeGreaterThan(-1);
|
|
19
|
+
const fence = src.lastIndexOf("```", at);
|
|
20
|
+
const body = src.indexOf("\n", fence) + 1;
|
|
21
|
+
return JSON.parse(src.slice(body, src.indexOf("```", body)));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** The inline `` `actions: [...]` `` span that contains `marker`, parsed as JSON. */
|
|
25
|
+
const inlineActionsAround = (src: string, rel: string, marker: string): unknown => {
|
|
26
|
+
const at = src.indexOf(marker);
|
|
27
|
+
expect(at, `${rel} no longer mentions ${marker}`).toBeGreaterThan(-1);
|
|
28
|
+
const span = src.slice(src.lastIndexOf("`", at) + 1, src.indexOf("`", at));
|
|
29
|
+
return JSON.parse(span.replace(/^actions:\s*/, ""));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A `custom` action is a way off the screen only when BOTH of its paths reach
|
|
34
|
+
* one — `onResolve ∪ rest` and `onError ∪ rest` (`completingActions.ts`). A doc
|
|
35
|
+
* that teaches a shape failing that test is teaching a screen nobody can leave,
|
|
36
|
+
* and — once anything else on it is stripped by the #209 boundary — one the
|
|
37
|
+
* renderer bolts a second Continue button onto.
|
|
38
|
+
*/
|
|
39
|
+
describe("authoring docs — the `custom` CTAs they teach can be left", () => {
|
|
40
|
+
it("credits the Tier 2 canonical button, which trails its custom with a continue", () => {
|
|
41
|
+
const rel = "claude-plugin/skills/customize-onboarding-components/SKILL.md";
|
|
42
|
+
const element = jsonBlockAround(read(rel), rel, "trackOnboardingComplete");
|
|
43
|
+
// `[{custom}, "continue"]`: the trailing escape runs whether the handler
|
|
44
|
+
// resolved or failed, so it satisfies both terms of the conjunction. This
|
|
45
|
+
// half of the finding never reproduced — it was written against the earlier
|
|
46
|
+
// `(onResolve ∪ rest) ∧ onError` reading, before `rest` flowed through both
|
|
47
|
+
// terms — and is pinned here rather than "fixed".
|
|
48
|
+
expect(hasCompletingAction([element])).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("credits the `delayedContinue` loader fallback", () => {
|
|
52
|
+
const rel = "claude-plugin/skills/create-step-json/references/composable-archetypes.md";
|
|
53
|
+
const actions = inlineActionsAround(read(rel), rel, "delayedContinue");
|
|
54
|
+
// This one was a bare `[{custom}]` — nothing after the action and neither
|
|
55
|
+
// hook declared, so the press escapes on NO path: the host's timer resolves,
|
|
56
|
+
// the handler's return value is discarded, and the screen never advances.
|
|
57
|
+
expect(actionsCanComplete(actions)).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
actionsCanComplete,
|
|
4
|
+
completingActionKind,
|
|
5
|
+
hasCompletingAction,
|
|
6
|
+
} from "../screens/completingActions";
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* "Can the user still get off this screen?" (#209, review finding 1).
|
|
@@ -137,3 +141,369 @@ describe("hasCompletingAction", () => {
|
|
|
137
141
|
expect(hasCompletingAction([button("cta", [{ type: "continue" }])])).toBe(false);
|
|
138
142
|
});
|
|
139
143
|
});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* `requestPermission` (#196) is the one action whose branch lists must NOT be
|
|
147
|
+
* read with the generic "any nested list completes it" rule, and review round 1
|
|
148
|
+
* caught the first version doing exactly that.
|
|
149
|
+
*
|
|
150
|
+
* The question this predicate answers is "can the user still get off this
|
|
151
|
+
* screen?", and for a permission ask the honest answer is "only on the outcomes
|
|
152
|
+
* the author covered". The runtime has three: a grant runs `onGranted`, a
|
|
153
|
+
* refusal runs `onDenied`, and "this build cannot ask" runs
|
|
154
|
+
* `onUnavailable ?? onDenied`. A CTA holding its only `"continue"` in
|
|
155
|
+
* `onGranted` traps every user who refuses — and traps EVERY user on a build
|
|
156
|
+
* that never installed the optional Expo module, which is a packaging fact the
|
|
157
|
+
* person pressing the button cannot do anything about.
|
|
158
|
+
*
|
|
159
|
+
* So the rule is AND across the outcomes, not OR: the action counts as a way
|
|
160
|
+
* forward only when a grant AND a non-grant both reach `"continue"` /
|
|
161
|
+
* `{dismiss}`. That is the file's stated bias ("errs toward no") applied to the
|
|
162
|
+
* one action whose result the user does not fully control. `purchase` and
|
|
163
|
+
* `restore` keep the OR reading deliberately — a cancelled purchase leaves the
|
|
164
|
+
* user free to press again, whereas a standing OS denial cannot be retried.
|
|
165
|
+
*/
|
|
166
|
+
describe("hasCompletingAction — requestPermission outcome hooks", () => {
|
|
167
|
+
const ask = (hooks: Record<string, unknown[]>) => [
|
|
168
|
+
button("cta", [{ type: "requestPermission", kind: "notifications", ...hooks }]),
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
it("counts an ask that advances on a grant AND on a refusal", () => {
|
|
172
|
+
expect(hasCompletingAction(ask({ onGranted: ["continue"], onDenied: ["continue"] }))).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("counts a grant path that continues and a refusal path that dismisses", () => {
|
|
176
|
+
expect(
|
|
177
|
+
hasCompletingAction(ask({ onGranted: ["continue"], onDenied: [{ type: "dismiss" }] }))
|
|
178
|
+
).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// The trap. `onGranted` alone reads as NO way forward, so the #209 strip
|
|
182
|
+
// supplies its own escape CTA.
|
|
183
|
+
it("reports no way forward when only the grant path advances", () => {
|
|
184
|
+
expect(hasCompletingAction(ask({ onGranted: ["continue"] }))).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("reports no way forward when only the refusal path advances", () => {
|
|
188
|
+
expect(hasCompletingAction(ask({ onDenied: ["continue"] }))).toBe(false);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// `onUnavailable` covers the module-absent outcome only; a denial still needs
|
|
192
|
+
// `onDenied`, so this shape strands the user who taps "Don't Allow".
|
|
193
|
+
it("reports no way forward when onDenied is missing but onUnavailable advances", () => {
|
|
194
|
+
expect(
|
|
195
|
+
hasCompletingAction(ask({ onGranted: ["continue"], onUnavailable: ["continue"] }))
|
|
196
|
+
).toBe(false);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// All three declared: every runtime path advances.
|
|
200
|
+
it("counts an ask that covers all three outcomes", () => {
|
|
201
|
+
expect(
|
|
202
|
+
hasCompletingAction(
|
|
203
|
+
ask({ onGranted: ["continue"], onDenied: ["continue"], onUnavailable: ["continue"] })
|
|
204
|
+
)
|
|
205
|
+
).toBe(true);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// `onUnavailable` present but dead, while `onDenied` advances: the
|
|
209
|
+
// module-absent build runs onUnavailable and stays put, so this is a trap the
|
|
210
|
+
// OR reading would have missed too.
|
|
211
|
+
it("reports no way forward when a declared onUnavailable does not advance", () => {
|
|
212
|
+
expect(
|
|
213
|
+
hasCompletingAction(
|
|
214
|
+
ask({
|
|
215
|
+
onGranted: ["continue"],
|
|
216
|
+
onDenied: ["continue"],
|
|
217
|
+
onUnavailable: [{ type: "setVariable", name: "push", value: "n/a" }],
|
|
218
|
+
})
|
|
219
|
+
)
|
|
220
|
+
).toBe(false);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// A typo'd hook name is stripped by the (deliberately non-strict) schema, so
|
|
224
|
+
// the payload validates clean and the denial path is dead. The AND rule is
|
|
225
|
+
// what turns that into a visible escape CTA rather than a silent trap.
|
|
226
|
+
it("reports no way forward when the refusal hook is misspelled", () => {
|
|
227
|
+
expect(
|
|
228
|
+
hasCompletingAction(ask({ onGranted: ["continue"], onDeneid: ["continue"] }))
|
|
229
|
+
).toBe(false);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("reports no way forward for a permission ask with no terminal hook", () => {
|
|
233
|
+
expect(
|
|
234
|
+
hasCompletingAction(ask({ onGranted: [{ type: "setVariable", name: "push", value: "on" }] }))
|
|
235
|
+
).toBe(false);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// A separate CTA elsewhere on the screen is still a way forward — the rule
|
|
239
|
+
// narrows what the ASK itself counts for, nothing else.
|
|
240
|
+
it("still finds a sibling skip button", () => {
|
|
241
|
+
expect(
|
|
242
|
+
hasCompletingAction([
|
|
243
|
+
button("cta", [{ type: "requestPermission", kind: "notifications", onGranted: ["continue"] }]),
|
|
244
|
+
button("skip", ["continue"]),
|
|
245
|
+
])
|
|
246
|
+
).toBe(true);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Nesting: an ask inside another action's branch list is walked the same way.
|
|
250
|
+
it("counts a fully covered ask nested inside purchase.onSuccess", () => {
|
|
251
|
+
expect(
|
|
252
|
+
hasCompletingAction([
|
|
253
|
+
button("cta", [
|
|
254
|
+
{
|
|
255
|
+
type: "purchase",
|
|
256
|
+
product: "yearly",
|
|
257
|
+
onSuccess: [
|
|
258
|
+
{
|
|
259
|
+
type: "requestPermission",
|
|
260
|
+
kind: "notifications",
|
|
261
|
+
onGranted: ["continue"],
|
|
262
|
+
onDenied: ["continue"],
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
},
|
|
266
|
+
]),
|
|
267
|
+
])
|
|
268
|
+
).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* `actionsCanComplete` — the same walk, exposed for ONE action list rather than
|
|
274
|
+
* a whole element tree, so the runtime can consult the SDK's own definition of
|
|
275
|
+
* "this was a way off the screen" instead of re-deriving it (review round 1,
|
|
276
|
+
* finding 1).
|
|
277
|
+
*
|
|
278
|
+
* `runActions` needs it at press time for exactly one decision: a
|
|
279
|
+
* `requestPermission` whose build cannot ask at all, with no `onUnavailable`
|
|
280
|
+
* declared. Whether that press was the screen's only way forward is the
|
|
281
|
+
* difference between "log and move on" and "the user is stuck", and it is the
|
|
282
|
+
* same question this module already answers statically.
|
|
283
|
+
*
|
|
284
|
+
* OR across the list, unlike `permissionAskCompletes`' AND across one ask's
|
|
285
|
+
* outcomes: the caller asks "did the author intend this press to move the user
|
|
286
|
+
* on", not "does every outcome move them on".
|
|
287
|
+
*/
|
|
288
|
+
describe("actionsCanComplete", () => {
|
|
289
|
+
it("is true for a list holding continue or dismiss", () => {
|
|
290
|
+
expect(actionsCanComplete(["continue"])).toBe(true);
|
|
291
|
+
expect(actionsCanComplete([{ type: "dismiss" }])).toBe(true);
|
|
292
|
+
expect(actionsCanComplete([{ type: "setVariable", name: "a", value: "b" }, "continue"])).toBe(
|
|
293
|
+
true
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("is false for a list that leaves the user on the screen", () => {
|
|
298
|
+
expect(actionsCanComplete([{ type: "setVariable", name: "a", value: "b" }])).toBe(false);
|
|
299
|
+
expect(actionsCanComplete([{ type: "custom", function: "doThing" }])).toBe(false);
|
|
300
|
+
expect(actionsCanComplete([{ type: "presentPaywall", placement: "hard" }])).toBe(false);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("walks nested branch lists", () => {
|
|
304
|
+
expect(
|
|
305
|
+
actionsCanComplete([{ type: "purchase", product: "yearly", onSuccess: ["continue"] }])
|
|
306
|
+
).toBe(true);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Total on junk: it runs on a payload the runtime has already parsed, but the
|
|
310
|
+
// predicate is the one thing that must not throw while deciding whether a
|
|
311
|
+
// user is trapped.
|
|
312
|
+
it("is false for anything that is not an action list", () => {
|
|
313
|
+
expect(actionsCanComplete(undefined)).toBe(false);
|
|
314
|
+
expect(actionsCanComplete(null)).toBe(false);
|
|
315
|
+
expect(actionsCanComplete("continue")).toBe(false);
|
|
316
|
+
expect(actionsCanComplete([null, 3, { type: "continue" }])).toBe(false);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Review round 2, finding 1. `actionsCanComplete`'s yes/no was not enough: the
|
|
322
|
+
* runtime substitutes the author's escape for an ask it could not perform, and
|
|
323
|
+
* the two completing actions report DIFFERENT outcomes to the host.
|
|
324
|
+
* `complete()` (bare) is what `Pages/Paywall/Renderer`'s hard gate reads as
|
|
325
|
+
* "advance", so standing in for an authored `{dismiss}` with a bare advance
|
|
326
|
+
* handed out paid content. `"dismiss"` therefore wins whenever both are
|
|
327
|
+
* reachable — nobody was asked anything, so the SDK claims the LESS permissive
|
|
328
|
+
* of the two answers the author authored.
|
|
329
|
+
*/
|
|
330
|
+
describe("completingActionKind", () => {
|
|
331
|
+
it("names the completing action a list reaches", () => {
|
|
332
|
+
expect(completingActionKind(["continue"])).toBe("continue");
|
|
333
|
+
expect(completingActionKind([{ type: "dismiss" }])).toBe("dismiss");
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("prefers dismiss when both are reachable, in either order", () => {
|
|
337
|
+
expect(completingActionKind(["continue", { type: "dismiss" }])).toBe("dismiss");
|
|
338
|
+
expect(completingActionKind([{ type: "dismiss" }, "continue"])).toBe("dismiss");
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("walks nested branch lists like the predicate does", () => {
|
|
342
|
+
expect(
|
|
343
|
+
completingActionKind([
|
|
344
|
+
{ type: "purchase", product: "yearly", onSuccess: [{ type: "dismiss" }] },
|
|
345
|
+
])
|
|
346
|
+
).toBe("dismiss");
|
|
347
|
+
expect(
|
|
348
|
+
completingActionKind([{ type: "restore", onSuccess: ["continue"] }])
|
|
349
|
+
).toBe("continue");
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// A nested ask keeps the AND-across-outcomes rule: it contributes an escape
|
|
353
|
+
// only when it is one on EVERY path.
|
|
354
|
+
it("respects the requestPermission AND rule when nested", () => {
|
|
355
|
+
expect(
|
|
356
|
+
completingActionKind([
|
|
357
|
+
{ type: "requestPermission", kind: "notifications", onGranted: ["continue"] },
|
|
358
|
+
])
|
|
359
|
+
).toBeUndefined();
|
|
360
|
+
expect(
|
|
361
|
+
completingActionKind([
|
|
362
|
+
{
|
|
363
|
+
type: "requestPermission",
|
|
364
|
+
kind: "notifications",
|
|
365
|
+
onGranted: ["continue"],
|
|
366
|
+
onDenied: [{ type: "dismiss" }],
|
|
367
|
+
},
|
|
368
|
+
])
|
|
369
|
+
).toBe("dismiss");
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("is undefined for a list that leaves the user on the screen, and for junk", () => {
|
|
373
|
+
expect(completingActionKind([{ type: "setVariable", name: "a", value: "b" }])).toBeUndefined();
|
|
374
|
+
expect(completingActionKind([])).toBeUndefined();
|
|
375
|
+
expect(completingActionKind(undefined)).toBeUndefined();
|
|
376
|
+
expect(completingActionKind(null)).toBeUndefined();
|
|
377
|
+
expect(completingActionKind("continue")).toBeUndefined();
|
|
378
|
+
expect(completingActionKind([null, 3, { type: "continue" }])).toBeUndefined();
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// The two must never disagree about WHETHER there is an escape — one walk
|
|
382
|
+
// answers both, and this is the assertion that keeps it that way.
|
|
383
|
+
it("agrees with actionsCanComplete on every shape", () => {
|
|
384
|
+
for (const actions of [
|
|
385
|
+
["continue"],
|
|
386
|
+
[{ type: "dismiss" }],
|
|
387
|
+
[{ type: "setVariable", name: "a", value: "b" }],
|
|
388
|
+
[{ type: "purchase", product: "yearly", onSuccess: ["continue"] }],
|
|
389
|
+
[{ type: "requestPermission", kind: "camera", onGranted: ["continue"] }],
|
|
390
|
+
undefined,
|
|
391
|
+
null,
|
|
392
|
+
[],
|
|
393
|
+
]) {
|
|
394
|
+
expect(completingActionKind(actions) !== undefined).toBe(actionsCanComplete(actions));
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* `custom` is read with AND across its outcomes, like `requestPermission` and
|
|
401
|
+
* unlike everything else (#191, review round 1, finding 6).
|
|
402
|
+
*
|
|
403
|
+
* The async gate this SDK documents puts the screen's only `"continue"` inside
|
|
404
|
+
* `onResolve`. That is the exact shape `permissionAskCompletes` was carved out
|
|
405
|
+
* to refuse: `onResolve` runs on the resolve path and NOWHERE else, so a
|
|
406
|
+
* `"continue"` reachable only there is not a way off the screen for a user
|
|
407
|
+
* whose backend is down — nor for one running a host with `customActions: {}`,
|
|
408
|
+
* which is `ScreenHost`'s own default. The generic OR read it as one, which is
|
|
409
|
+
* what let the walk report "this screen has a CTA" for a screen nobody could
|
|
410
|
+
* leave.
|
|
411
|
+
*
|
|
412
|
+
* The AND is over the action's TWO paths — the handler resolved, and the
|
|
413
|
+
* handler failed (a throw with the budget spent, an attempt past
|
|
414
|
+
* `retry.timeoutMs`, or a name the host never registered: one rule since the
|
|
415
|
+
* semantics decision of 2026-09-11, #191 / #266). Both leave the enclosing list
|
|
416
|
+
* running, so whatever follows the action counts for both terms, and
|
|
417
|
+
* `[{custom}, "continue"]` IS a way off the screen — on every path, not on two
|
|
418
|
+
* of three as it was while a throw aborted. Round 2 of this PR required
|
|
419
|
+
* `onError` on its own and therefore read that shape — the only `custom` shape
|
|
420
|
+
* Studio can author today — as a trap; see
|
|
421
|
+
* `onboarding-ui/src/UI/Runtime/__tests__/mergeBaseEscapeParity.test.ts`, and
|
|
422
|
+
* `customActionEscapeCoherence.test.ts` beside it for the check that this walk
|
|
423
|
+
* and `runActions` agree.
|
|
424
|
+
*/
|
|
425
|
+
describe("completingActions — custom is AND across its outcome hooks", () => {
|
|
426
|
+
const gate = (extra: Record<string, unknown>) => [
|
|
427
|
+
{ type: "custom", function: "generatePlan", ...extra },
|
|
428
|
+
];
|
|
429
|
+
|
|
430
|
+
it("does not count a continue reachable only when the handler resolves", () => {
|
|
431
|
+
expect(actionsCanComplete(gate({ onResolve: ["continue"] }))).toBe(false);
|
|
432
|
+
expect(
|
|
433
|
+
actionsCanComplete(
|
|
434
|
+
gate({
|
|
435
|
+
onResolve: ["continue"],
|
|
436
|
+
onError: [{ type: "setVariable", name: "planError", value: "true" }],
|
|
437
|
+
})
|
|
438
|
+
)
|
|
439
|
+
).toBe(false);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it("counts it when BOTH outcomes reach a way off the screen", () => {
|
|
443
|
+
expect(
|
|
444
|
+
actionsCanComplete(gate({ onResolve: ["continue"], onError: ["continue"] }))
|
|
445
|
+
).toBe(true);
|
|
446
|
+
expect(
|
|
447
|
+
completingActionKind(gate({ onResolve: ["continue"], onError: [{ type: "dismiss" }] }))
|
|
448
|
+
).toBe("dismiss");
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("does not count a bare custom action, nor one whose `variables` are named like actions", () => {
|
|
452
|
+
expect(actionsCanComplete(gate({}))).toBe(false);
|
|
453
|
+
// `variables: ["continue"]` used to satisfy the generic OR walk.
|
|
454
|
+
expect(actionsCanComplete(gate({ variables: ["continue"] }))).toBe(false);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it("counts a sibling AFTER the custom action (retro round 2, finding 2)", () => {
|
|
458
|
+
// `[{custom}, "continue"]` is the shape an author writes when Studio cannot
|
|
459
|
+
// spell `onResolve` — which is every `custom` payload in the field until
|
|
460
|
+
// `rocapine/onboarding-studio#288` lands. The trailing `"continue"` runs on
|
|
461
|
+
// BOTH of the action's paths — the handler resolved, or it failed — so it
|
|
462
|
+
// is a way off the screen, and reading it as a trap bolted a duplicate CTA
|
|
463
|
+
// onto stripped screens that already had one.
|
|
464
|
+
expect(actionsCanComplete([...gate({}), "continue"])).toBe(true);
|
|
465
|
+
expect(
|
|
466
|
+
actionsCanComplete([
|
|
467
|
+
...gate({ onError: [{ type: "setVariable", name: "planError", value: "true" }] }),
|
|
468
|
+
"continue",
|
|
469
|
+
])
|
|
470
|
+
).toBe(true);
|
|
471
|
+
// An `onError` that escapes is a way off the screen on its own terms, so it
|
|
472
|
+
// does not need the sibling — but the sibling does not disqualify it either.
|
|
473
|
+
expect(actionsCanComplete([...gate({ onError: ["continue"] }), "continue"])).toBe(true);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it("still refuses a custom whose ONLY escape is on the resolve path", () => {
|
|
477
|
+
// The sibling rule above must not launder round 1's finding 6 back in, and
|
|
478
|
+
// neither does removing the abort: with nothing trailing the action, a host
|
|
479
|
+
// running `customActions: {}` — the `ScreenHost` default — reaches neither
|
|
480
|
+
// `onResolve` nor anything after it. (#266 costed this decision as
|
|
481
|
+
// "reverts to the generic OR walk". OR would credit this `onResolve` and
|
|
482
|
+
// re-open finding 6; what the decision removes is a third term the code
|
|
483
|
+
// never had.)
|
|
484
|
+
expect(actionsCanComplete(gate({ onResolve: ["continue"] }))).toBe(false);
|
|
485
|
+
expect(actionsCanComplete([...gate({ onResolve: ["continue"] })])).toBe(false);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("counts a sibling BEFORE it, which runs whatever the handler does", () => {
|
|
489
|
+
// `runActions` returns at the first completing action, so the custom never
|
|
490
|
+
// runs and the escape is unconditional — which is why everything before the
|
|
491
|
+
// barrier keeps the plain OR reading.
|
|
492
|
+
expect(actionsCanComplete(["continue", ...gate({})])).toBe(true);
|
|
493
|
+
expect(completingActionKind([{ type: "dismiss" }, ...gate({})])).toBe("dismiss");
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("reads the classic shape the same way inside an element tree", () => {
|
|
497
|
+
expect(hasCompletingAction([button("cta", [...gate({}), "continue"])])).toBe(true);
|
|
498
|
+
// And still strands when the only escape is behind the handler.
|
|
499
|
+
expect(hasCompletingAction([button("cta", gate({ onResolve: ["continue"] }))])).toBe(false);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it("reads a whole element tree the same way", () => {
|
|
503
|
+
const screen = [button("cta", gate({ onResolve: ["continue"] }))];
|
|
504
|
+
expect(hasCompletingAction(screen)).toBe(false);
|
|
505
|
+
expect(
|
|
506
|
+
hasCompletingAction([button("cta", gate({ onResolve: ["continue"], onError: ["continue"] }))])
|
|
507
|
+
).toBe(true);
|
|
508
|
+
});
|
|
509
|
+
});
|