@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
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { ButtonActionSchema, CustomButtonActionSchema } from "../steps/common.types";
|
|
3
|
+
import { hasCompletingAction } from "../screens/completingActions";
|
|
4
|
+
|
|
5
|
+
// RNO#191 — the declarative half of an async gate. `custom` gains the same
|
|
6
|
+
// nested-`ButtonAction[]` outcome hooks `purchase`/`restore` already carry,
|
|
7
|
+
// plus a bounded retry. These assert the HEADLESS schema (the one that
|
|
8
|
+
// validates the payload); the UI mirror is asserted in
|
|
9
|
+
// `packages/onboarding-ui/src/UI/Runtime/__tests__/runActions.test.ts`.
|
|
10
|
+
|
|
11
|
+
describe("CustomButtonAction schema — outcome hooks", () => {
|
|
12
|
+
// Asserting the PARSED OUTPUT, not just `success`: Zod strips unrecognized
|
|
13
|
+
// keys, so an unimplemented hook parses "successfully" and silently vanishes
|
|
14
|
+
// before it ever reaches `runActions`.
|
|
15
|
+
it("accepts onResolve and onError action lists and keeps them", () => {
|
|
16
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
17
|
+
type: "custom",
|
|
18
|
+
function: "generatePlan",
|
|
19
|
+
variables: ["goal"],
|
|
20
|
+
onResolve: ["continue"],
|
|
21
|
+
onError: [{ type: "setVariable", name: "planError", value: "true" }],
|
|
22
|
+
});
|
|
23
|
+
expect(parsed.success).toBe(true);
|
|
24
|
+
expect((parsed as any).data.onResolve).toEqual(["continue"]);
|
|
25
|
+
expect((parsed as any).data.onError).toEqual([
|
|
26
|
+
{ type: "setVariable", name: "planError", value: "true" },
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("accepts a nested custom action inside onError (recursion)", () => {
|
|
31
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
32
|
+
type: "custom",
|
|
33
|
+
function: "generatePlan",
|
|
34
|
+
onError: [{ type: "custom", function: "reportFailure" }],
|
|
35
|
+
});
|
|
36
|
+
expect(parsed.success).toBe(true);
|
|
37
|
+
expect((parsed as any).data.onError[0].function).toBe("reportFailure");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("still accepts the pre-#191 three-field shape", () => {
|
|
41
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
42
|
+
type: "custom",
|
|
43
|
+
function: "generatePlan",
|
|
44
|
+
variables: ["goal"],
|
|
45
|
+
});
|
|
46
|
+
expect(parsed.success).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("is reachable through the ButtonAction union with its hooks", () => {
|
|
50
|
+
const parsed = ButtonActionSchema.safeParse({
|
|
51
|
+
type: "custom",
|
|
52
|
+
function: "generatePlan",
|
|
53
|
+
onResolve: ["continue"],
|
|
54
|
+
});
|
|
55
|
+
expect(parsed.success).toBe(true);
|
|
56
|
+
expect((parsed as any).data.onResolve).toEqual(["continue"]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("CustomButtonAction schema — bounded retry", () => {
|
|
61
|
+
it("accepts an explicit attempt cap", () => {
|
|
62
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
63
|
+
type: "custom",
|
|
64
|
+
function: "generatePlan",
|
|
65
|
+
retry: { maxAttempts: 3, delayMs: 500 },
|
|
66
|
+
});
|
|
67
|
+
expect(parsed.success).toBe(true);
|
|
68
|
+
expect((parsed as any).data.retry).toEqual({ maxAttempts: 3, delayMs: 500 });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// The cap is what makes the retry BOUNDED — a payload that forgets it, or
|
|
72
|
+
// asks for an unbounded/absurd number of attempts, must fail at parse time
|
|
73
|
+
// rather than hang a screen behind a dead service.
|
|
74
|
+
it("rejects a retry with no attempt cap", () => {
|
|
75
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
76
|
+
type: "custom",
|
|
77
|
+
function: "generatePlan",
|
|
78
|
+
retry: { delayMs: 500 },
|
|
79
|
+
});
|
|
80
|
+
expect(parsed.success).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("rejects fewer than one attempt", () => {
|
|
84
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
85
|
+
type: "custom",
|
|
86
|
+
function: "generatePlan",
|
|
87
|
+
retry: { maxAttempts: 0 },
|
|
88
|
+
});
|
|
89
|
+
expect(parsed.success).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("rejects more attempts than the runtime will make", () => {
|
|
93
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
94
|
+
type: "custom",
|
|
95
|
+
function: "generatePlan",
|
|
96
|
+
retry: { maxAttempts: 11 },
|
|
97
|
+
});
|
|
98
|
+
expect(parsed.success).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("rejects a fractional attempt cap", () => {
|
|
102
|
+
const parsed = CustomButtonActionSchema.safeParse({
|
|
103
|
+
type: "custom",
|
|
104
|
+
function: "generatePlan",
|
|
105
|
+
retry: { maxAttempts: 2.5 },
|
|
106
|
+
});
|
|
107
|
+
expect(parsed.success).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// RNO#264 — `maxAttempts` bounds the NUMBER of attempts; nothing bounded ONE
|
|
112
|
+
// attempt's duration, so a handler whose promise never settles held the
|
|
113
|
+
// single-flight claim for the life of the screen and the documented
|
|
114
|
+
// `disabledWhen: actions.pending.<id>` payload greyed the CTA out permanently.
|
|
115
|
+
describe("CustomActionRetry schema — per-attempt timeoutMs (#264)", () => {
|
|
116
|
+
const retry = (retry: Record<string, unknown>) =>
|
|
117
|
+
CustomButtonActionSchema.safeParse({
|
|
118
|
+
type: "custom",
|
|
119
|
+
function: "generatePlan",
|
|
120
|
+
retry,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("accepts a per-attempt timeout and keeps it", () => {
|
|
124
|
+
const parsed = retry({ maxAttempts: 3, delayMs: 400, timeoutMs: 15000 });
|
|
125
|
+
expect(parsed.success).toBe(true);
|
|
126
|
+
expect((parsed as any).data.retry).toEqual({
|
|
127
|
+
maxAttempts: 3,
|
|
128
|
+
delayMs: 400,
|
|
129
|
+
timeoutMs: 15000,
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// A timeout without retries is the #264 repro itself — one attempt that never
|
|
134
|
+
// answers — so it must be authorable without pretending to want retries.
|
|
135
|
+
it("accepts a timeout on a single-attempt policy", () => {
|
|
136
|
+
const parsed = retry({ maxAttempts: 1, timeoutMs: 30000 });
|
|
137
|
+
expect(parsed.success).toBe(true);
|
|
138
|
+
expect((parsed as any).data.retry.timeoutMs).toBe(30000);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("is optional — an absent timeout means unbounded, as before", () => {
|
|
142
|
+
const parsed = retry({ maxAttempts: 2 });
|
|
143
|
+
expect(parsed.success).toBe(true);
|
|
144
|
+
expect((parsed as any).data.retry.timeoutMs).toBeUndefined();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// A sub-second timeout cannot be met by any real network call, so it is a
|
|
148
|
+
// typo (milliseconds meant as seconds), not a policy.
|
|
149
|
+
it("rejects a timeout too short for any real handler", () => {
|
|
150
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 0 }).success).toBe(false);
|
|
151
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 250 }).success).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Generous on purpose: a legitimate LLM call can take 60s+, and cutting one
|
|
155
|
+
// off would be a worse bug than the hang. Five minutes is the ceiling.
|
|
156
|
+
it("accepts a generous timeout and rejects one past the ceiling", () => {
|
|
157
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 300000 }).success).toBe(true);
|
|
158
|
+
expect(retry({ maxAttempts: 1, timeoutMs: 300001 }).success).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("rejects a non-numeric timeout", () => {
|
|
162
|
+
expect(retry({ maxAttempts: 1, timeoutMs: "5000" }).success).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe("hasCompletingAction and a custom action's hooks (#209 guard)", () => {
|
|
167
|
+
// Round 1 asserted the opposite of this — that `onResolve: ["continue"]` alone
|
|
168
|
+
// makes the screen completable — and review round 1, finding 6 refuted it.
|
|
169
|
+
// The resolve path is not the user's to reach: `ScreenHost`'s default is
|
|
170
|
+
// `customActions: {}`, and an unregistered name runs `onError` and whatever
|
|
171
|
+
// follows the action, never `onResolve`. So a `"continue"` in `onResolve`
|
|
172
|
+
// alone is not a way off the screen. Read with AND across the outcomes, like
|
|
173
|
+
// `requestPermission` (`completingActions.ts` — `customActionEscapes`), over
|
|
174
|
+
// the action's two paths: the handler resolved, and the handler failed.
|
|
175
|
+
const cta = (actions: unknown[]) => [
|
|
176
|
+
{ type: "Button", id: "cta", props: { label: "Generate", actions } },
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
it("does not count a continue reachable only on the resolve path", () => {
|
|
180
|
+
expect(
|
|
181
|
+
hasCompletingAction(
|
|
182
|
+
cta([{ type: "custom", function: "generatePlan", onResolve: ["continue"] }])
|
|
183
|
+
)
|
|
184
|
+
).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("counts it when the error path also reaches a way off the screen", () => {
|
|
188
|
+
expect(
|
|
189
|
+
hasCompletingAction(
|
|
190
|
+
cta([
|
|
191
|
+
{
|
|
192
|
+
type: "custom",
|
|
193
|
+
function: "generatePlan",
|
|
194
|
+
onResolve: ["continue"],
|
|
195
|
+
onError: ["continue"],
|
|
196
|
+
},
|
|
197
|
+
])
|
|
198
|
+
)
|
|
199
|
+
).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("counts a sibling continue after the custom action", () => {
|
|
203
|
+
// The trailing `"continue"` runs on both of the action's paths — handler
|
|
204
|
+
// resolved, and handler failed however it failed — so it IS the screen's
|
|
205
|
+
// way forward. It used to be reachable on only two of three paths, the
|
|
206
|
+
// throw path having aborted the list; the semantics decision of 2026-09-11
|
|
207
|
+
// removed that path, so this row no longer rests on a retryability
|
|
208
|
+
// argument.
|
|
209
|
+
//
|
|
210
|
+
// Round 2 of this PR required `onError` here, which read every
|
|
211
|
+
// `[{custom}, "continue"]` payload in the field as a trap: Studio's action
|
|
212
|
+
// editor cannot author `onResolve`/`onError` until
|
|
213
|
+
// `rocapine/onboarding-studio#288` lands, so the prescribed fix was not
|
|
214
|
+
// available to anyone the verdict applied to.
|
|
215
|
+
expect(
|
|
216
|
+
hasCompletingAction(cta([{ type: "custom", function: "generatePlan" }, "continue"]))
|
|
217
|
+
).toBe(true);
|
|
218
|
+
expect(
|
|
219
|
+
hasCompletingAction(
|
|
220
|
+
cta([{ type: "custom", function: "generatePlan", onError: ["continue"] }, "continue"])
|
|
221
|
+
)
|
|
222
|
+
).toBe(true);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -209,3 +209,33 @@ describe("OnboardingStudioClient.clearCache", () => {
|
|
|
209
209
|
warn.mockRestore();
|
|
210
210
|
});
|
|
211
211
|
});
|
|
212
|
+
|
|
213
|
+
describe("cache key and request identity", () => {
|
|
214
|
+
beforeEach(() => {
|
|
215
|
+
getItem.mockReset();
|
|
216
|
+
setItem.mockReset();
|
|
217
|
+
getItem.mockResolvedValue(null);
|
|
218
|
+
setItem.mockResolvedValue(undefined);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// The SDK's own identity is sent on the request but must NOT enter the cache
|
|
222
|
+
// key: a key that changed with every app update would leave a returning user
|
|
223
|
+
// who is offline right after updating with no cached onboarding, and would stop a
|
|
224
|
+
// custom `cacheKey` from pinning content across updates.
|
|
225
|
+
const withIdentity = (client: any, identity: Record<string, string>) => {
|
|
226
|
+
client.identityParams = () => identity;
|
|
227
|
+
return client;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
it("same cache key across builds when only the SDK-derived identity changes", async () => {
|
|
231
|
+
await run(withIdentity(makeClient({ isSandbox: false, onboardingId: "real", data: realOnboarding }), { appVersion: "2.3.0", build: "45", sdkVersion: "1.77.0", environment: "production" }));
|
|
232
|
+
await run(withIdentity(makeClient({ isSandbox: false, onboardingId: "real", data: realOnboarding }), { appVersion: "2.4.0", build: "46", sdkVersion: "1.78.0", environment: "production" }));
|
|
233
|
+
const keys = setItem.mock.calls.map(([key]) => key);
|
|
234
|
+
expect(keys).toEqual([CACHE_KEY, CACHE_KEY]);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("custom cacheKey is unaffected by identity", async () => {
|
|
238
|
+
await run(withIdentity(makeClient({ isSandbox: false, onboardingId: "real", data: realOnboarding, cacheKey: CUSTOM_KEY }), { appVersion: "2.3.0", build: "45", sdkVersion: "1.77.0", environment: "production" }));
|
|
239
|
+
expect(setItem).toHaveBeenCalledWith(CUSTOM_CACHE_KEY, JSON.stringify(realOnboarding));
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { ScreenElementsSchema } from "../screens/types";
|
|
3
|
+
import { actionsCanComplete, hasCompletingAction } from "../screens/completingActions";
|
|
3
4
|
import { onboardingExample } from "../onboarding-example";
|
|
4
5
|
|
|
5
6
|
// The default onboarding is the payload every example app and the studio's
|
|
@@ -25,3 +26,49 @@ describe("onboarding-example ComposableScreen payloads", () => {
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
});
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The exported payload is also the documented `fallbackOnboarding`
|
|
32
|
+
* (`getting-started.mdx`), rendered by apps that pass no `customActions` at all
|
|
33
|
+
* — `ScreenHost`'s default is `{}`. So no step in it may depend on a registered
|
|
34
|
+
* handler for its way forward (review round 1, findings 1 and 7).
|
|
35
|
+
*
|
|
36
|
+
* Round 1 of #191 moved the hero button's only `"continue"` into the
|
|
37
|
+
* `onResolve` of a `{type:"custom", function:"trackCta"}` action. `trackCta` is
|
|
38
|
+
* registered nowhere in the SDK, so on the fallback path the primary CTA logged
|
|
39
|
+
* one line and did nothing: a step with no way off it.
|
|
40
|
+
*/
|
|
41
|
+
describe("onboarding-example ComposableScreen steps stay navigable", () => {
|
|
42
|
+
const composableSteps = onboardingExample.steps.filter(
|
|
43
|
+
(s) => s.type === "ComposableScreen"
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
for (const step of composableSteps) {
|
|
47
|
+
it(`step "${step.name}" can be completed with no customActions registered`, () => {
|
|
48
|
+
expect(hasCompletingAction(step.payload?.elements)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Tree-wide is not enough for the PRIMARY CTA: the screen keeping SOME way
|
|
53
|
+
// forward elsewhere in the tree does not make a dead "Get Started" button
|
|
54
|
+
// acceptable. This asserts the button itself.
|
|
55
|
+
const findById = (nodes: unknown, id: string): any => {
|
|
56
|
+
if (!Array.isArray(nodes)) return undefined;
|
|
57
|
+
for (const node of nodes) {
|
|
58
|
+
if (node && typeof node === "object") {
|
|
59
|
+
const n = node as any;
|
|
60
|
+
if (n.id === id) return n;
|
|
61
|
+
const inner = findById(n.children, id);
|
|
62
|
+
if (inner) return inner;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
it("the hero CTA advances on a host with no customActions", () => {
|
|
69
|
+
const step = composableSteps[0];
|
|
70
|
+
const hero = findById(step.payload?.elements, "hero-button");
|
|
71
|
+
expect(hero, "hero-button not found in the example payload").toBeTruthy();
|
|
72
|
+
expect(actionsCanComplete(hero.props.actions)).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("react-native", () => ({ Platform: { OS: "ios" } }));
|
|
4
|
+
vi.mock("@react-native-async-storage/async-storage", () => ({
|
|
5
|
+
default: {
|
|
6
|
+
getItem: vi.fn(async () => null),
|
|
7
|
+
setItem: vi.fn(async () => {}),
|
|
8
|
+
removeItem: vi.fn(async () => {}),
|
|
9
|
+
getAllKeys: vi.fn(async () => []),
|
|
10
|
+
multiRemove: vi.fn(async () => {}),
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
13
|
+
// The client reads expo-application through `readNativeAppInfo`; replace only
|
|
14
|
+
// that export so each test chooses what the device reports.
|
|
15
|
+
const native = vi.hoisted(() => ({ info: {} as { appVersion?: string; build?: string } }));
|
|
16
|
+
vi.mock("../requestIdentity", async (importOriginal) => ({
|
|
17
|
+
...(await importOriginal<typeof import("../requestIdentity")>()),
|
|
18
|
+
readNativeAppInfo: () => native.info,
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
import { OnboardingStudioClient } from "../OnboardingStudioClient";
|
|
22
|
+
import { SDK_VERSION } from "../version";
|
|
23
|
+
|
|
24
|
+
const fakeResponse = (body: unknown) => ({
|
|
25
|
+
ok: true,
|
|
26
|
+
status: 200,
|
|
27
|
+
statusText: "OK",
|
|
28
|
+
json: async () => body,
|
|
29
|
+
headers: { get: () => null },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const fetches = {
|
|
33
|
+
getSteps: (c: OnboardingStudioClient, params?: Record<string, string>) =>
|
|
34
|
+
c.getSteps({ locale: "en" }, params),
|
|
35
|
+
getPaywalls: (c: OnboardingStudioClient, params?: Record<string, string>) =>
|
|
36
|
+
c.getPaywalls({ locale: "en" }, params),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe.each(Object.entries(fetches))("%s request identity", (_name, fetchWith) => {
|
|
40
|
+
let fetchMock: ReturnType<typeof vi.fn>;
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
native.info = {};
|
|
44
|
+
fetchMock = vi.fn().mockResolvedValue(fakeResponse({ metadata: {}, steps: [], paywalls: {} }));
|
|
45
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
46
|
+
vi.spyOn(console, "info").mockImplementation(() => {});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
vi.unstubAllGlobals();
|
|
51
|
+
vi.restoreAllMocks();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const sent = () => new URL(fetchMock.mock.calls[0][0] as string).searchParams;
|
|
55
|
+
|
|
56
|
+
it("sends appVersion and build from expo-application, plus sdkVersion and environment", async () => {
|
|
57
|
+
native.info = { appVersion: "2.3.0", build: "45" };
|
|
58
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}));
|
|
59
|
+
expect(sent().get("appVersion")).toBe("2.3.0");
|
|
60
|
+
expect(sent().get("build")).toBe("45");
|
|
61
|
+
expect(sent().get("sdkVersion")).toBe(SDK_VERSION);
|
|
62
|
+
expect(sent().get("environment")).toBe("production");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("host appVersion and build win over expo-application", async () => {
|
|
66
|
+
native.info = { appVersion: "2.3.0", build: "45" };
|
|
67
|
+
await fetchWith(new OnboardingStudioClient("proj-1", { appVersion: "3.0.0", build: "300" }));
|
|
68
|
+
expect(sent().get("appVersion")).toBe("3.0.0");
|
|
69
|
+
expect(sent().get("build")).toBe("300");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("omits appVersion and build when neither source has them", async () => {
|
|
73
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}));
|
|
74
|
+
expect(sent().has("appVersion")).toBe(false);
|
|
75
|
+
expect(sent().has("build")).toBe(false);
|
|
76
|
+
expect(sent().get("sdkVersion")).toBe(SDK_VERSION);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("environment: sandbox in sandbox mode, normalized when the host sets it", async () => {
|
|
80
|
+
await fetchWith(new OnboardingStudioClient("proj-1", { isSandbox: true }));
|
|
81
|
+
expect(sent().get("environment")).toBe("sandbox");
|
|
82
|
+
fetchMock.mockClear();
|
|
83
|
+
await fetchWith(new OnboardingStudioClient("proj-1", { environment: "Staging Env!" }));
|
|
84
|
+
expect(sent().get("environment")).toBe("stagingenv");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("SDK-owned keys replace a same-named user param (the server reads the first occurrence)", async () => {
|
|
88
|
+
native.info = { appVersion: "2.3.0", build: "45" };
|
|
89
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}), {
|
|
90
|
+
build: "from-user",
|
|
91
|
+
environment: "from-user",
|
|
92
|
+
sdkVersion: "from-user",
|
|
93
|
+
projectId: "other",
|
|
94
|
+
plan: "pro",
|
|
95
|
+
});
|
|
96
|
+
expect(sent().getAll("build")).toEqual(["45"]);
|
|
97
|
+
expect(sent().getAll("environment")).toEqual(["production"]);
|
|
98
|
+
expect(sent().getAll("sdkVersion")).toEqual([SDK_VERSION]);
|
|
99
|
+
expect(sent().getAll("projectId")).toEqual(["proj-1"]);
|
|
100
|
+
expect(sent().get("plan")).toBe("pro");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("a user appVersion or build never reaches the wire, even when the SDK has none to send", async () => {
|
|
104
|
+
// A property persisted before these names were reserved is re-read from
|
|
105
|
+
// disk without a reserved-key check, so it can still arrive here.
|
|
106
|
+
await fetchWith(new OnboardingStudioClient("proj-1", {}), {
|
|
107
|
+
appVersion: "from-user",
|
|
108
|
+
build: "from-user",
|
|
109
|
+
plan: "pro",
|
|
110
|
+
});
|
|
111
|
+
expect(sent().has("appVersion")).toBe(false);
|
|
112
|
+
expect(sent().has("build")).toBe(false);
|
|
113
|
+
expect(sent().get("plan")).toBe("pro");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
defaultEnvironment,
|
|
6
|
+
normalizeEnvironment,
|
|
7
|
+
readNativeAppInfo,
|
|
8
|
+
resolveRequestIdentity,
|
|
9
|
+
} from "../requestIdentity";
|
|
10
|
+
import { SDK_VERSION } from "../version";
|
|
11
|
+
|
|
12
|
+
describe("SDK_VERSION", () => {
|
|
13
|
+
it("equals the package version", () => {
|
|
14
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "../..", "package.json"), "utf8"));
|
|
15
|
+
expect(SDK_VERSION).toBe(pkg.version);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("readNativeAppInfo", () => {
|
|
20
|
+
it("reads version and build from expo-application", () => {
|
|
21
|
+
expect(
|
|
22
|
+
readNativeAppInfo(() => ({ nativeApplicationVersion: "2.3.0", nativeBuildVersion: "45" })),
|
|
23
|
+
).toEqual({ appVersion: "2.3.0", build: "45" });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("is empty when expo-application is not installed", () => {
|
|
27
|
+
expect(readNativeAppInfo(() => null)).toEqual({});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("is empty, without throwing, when loading expo-application throws", () => {
|
|
31
|
+
expect(
|
|
32
|
+
readNativeAppInfo(() => {
|
|
33
|
+
throw new Error("Cannot find module 'expo-application'");
|
|
34
|
+
}),
|
|
35
|
+
).toEqual({});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("omits null and blank values (web, or an unlinked native module)", () => {
|
|
39
|
+
expect(
|
|
40
|
+
readNativeAppInfo(() => ({ nativeApplicationVersion: null, nativeBuildVersion: " " })),
|
|
41
|
+
).toEqual({ appVersion: undefined, build: undefined });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("the default loader never throws", () => {
|
|
45
|
+
expect(() => readNativeAppInfo()).not.toThrow();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("defaultEnvironment", () => {
|
|
50
|
+
it("is sandbox in sandbox mode, whatever __DEV__ says", () => {
|
|
51
|
+
expect(defaultEnvironment(true, true)).toBe("sandbox");
|
|
52
|
+
expect(defaultEnvironment(true, false)).toBe("sandbox");
|
|
53
|
+
});
|
|
54
|
+
it("is development under __DEV__, production otherwise", () => {
|
|
55
|
+
expect(defaultEnvironment(false, true)).toBe("development");
|
|
56
|
+
expect(defaultEnvironment(undefined, false)).toBe("production");
|
|
57
|
+
});
|
|
58
|
+
it("reads __DEV__ when not told, and treats an undefined __DEV__ as production", () => {
|
|
59
|
+
expect(defaultEnvironment(undefined)).toBe("production");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("normalizeEnvironment", () => {
|
|
64
|
+
it("lower-cases and drops characters outside [a-z0-9_-]", () => {
|
|
65
|
+
expect(normalizeEnvironment("Staging Env!", "production")).toBe("stagingenv");
|
|
66
|
+
expect(normalizeEnvironment("qa_2-eu", "production")).toBe("qa_2-eu");
|
|
67
|
+
});
|
|
68
|
+
it("caps at 32 characters", () => {
|
|
69
|
+
expect(normalizeEnvironment("a".repeat(200), "production")).toBe("a".repeat(32));
|
|
70
|
+
});
|
|
71
|
+
it("falls back when nothing survives or the value is not a string", () => {
|
|
72
|
+
expect(normalizeEnvironment(" ", "production")).toBe("production");
|
|
73
|
+
expect(normalizeEnvironment("!!!", "sandbox")).toBe("sandbox");
|
|
74
|
+
expect(normalizeEnvironment(undefined, "development")).toBe("development");
|
|
75
|
+
expect(normalizeEnvironment(42, "production")).toBe("production");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("resolveRequestIdentity", () => {
|
|
80
|
+
const native = { appVersion: "2.3.0", build: "45" };
|
|
81
|
+
|
|
82
|
+
it("host values win over expo-application", () => {
|
|
83
|
+
expect(resolveRequestIdentity({ appVersion: "9.9.9", build: "1" }, native, false)).toEqual({
|
|
84
|
+
appVersion: "9.9.9",
|
|
85
|
+
build: "1",
|
|
86
|
+
sdkVersion: SDK_VERSION,
|
|
87
|
+
environment: "production",
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("expo-application fills what the host left out, and a blank host value counts as left out", () => {
|
|
92
|
+
expect(resolveRequestIdentity({ appVersion: " " }, native, false)).toEqual({
|
|
93
|
+
appVersion: "2.3.0",
|
|
94
|
+
build: "45",
|
|
95
|
+
sdkVersion: SDK_VERSION,
|
|
96
|
+
environment: "production",
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("omits appVersion and build when neither source has them", () => {
|
|
101
|
+
expect(resolveRequestIdentity({}, {}, false)).toEqual({
|
|
102
|
+
sdkVersion: SDK_VERSION,
|
|
103
|
+
environment: "production",
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("normalizes a host environment and defaults from the mode", () => {
|
|
108
|
+
expect(resolveRequestIdentity({ environment: "Staging" }, {}, false).environment).toBe("staging");
|
|
109
|
+
expect(resolveRequestIdentity({ isSandbox: true }, {}, false).environment).toBe("sandbox");
|
|
110
|
+
expect(resolveRequestIdentity({}, {}, true).environment).toBe("development");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
ButtonActionSchema,
|
|
4
|
+
PERMISSION_KINDS,
|
|
5
|
+
PermissionKindSchema,
|
|
6
|
+
} from "../steps/common.types";
|
|
7
|
+
import { UIElementSchema } from "../screens/types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The headless half of the `requestPermission` ButtonAction (#196).
|
|
11
|
+
*
|
|
12
|
+
* The headless schema is what validates a published payload, so a variant that
|
|
13
|
+
* exists only in the UI mirror still throws `invalid_union` on parse — the
|
|
14
|
+
* failure mode CLAUDE.md's step 3 warns about. These tests pin the headless
|
|
15
|
+
* side: the eighth union member, its closed `kind` enum, and the fact that its
|
|
16
|
+
* three outcome hooks recurse through `ButtonActionSchema` the way
|
|
17
|
+
* `purchase`/`restore` do.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
describe("PermissionKind", () => {
|
|
21
|
+
// Deliberately narrow: every kind here must be reachable through an
|
|
22
|
+
// optionally-installed Expo module the SDK can dynamic-`require` at press
|
|
23
|
+
// time. HealthKit and Screen Time / Family Controls need app-owned
|
|
24
|
+
// entitlements and a config plugin neither package ships, so they are NOT
|
|
25
|
+
// members — they arrive later behind the host `requestPermission` resolver.
|
|
26
|
+
it("is exactly the six kinds an Expo module can request", () => {
|
|
27
|
+
expect([...PERMISSION_KINDS]).toEqual([
|
|
28
|
+
"notifications",
|
|
29
|
+
"appTrackingTransparency",
|
|
30
|
+
"locationWhenInUse",
|
|
31
|
+
"camera",
|
|
32
|
+
"microphone",
|
|
33
|
+
"photoLibrary",
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("rejects a kind outside the enum", () => {
|
|
38
|
+
expect(PermissionKindSchema.safeParse("healthkit").success).toBe(false);
|
|
39
|
+
expect(PermissionKindSchema.safeParse("notification").success).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("ButtonActionSchema — requestPermission", () => {
|
|
44
|
+
it("accepts the minimal action (kind only)", () => {
|
|
45
|
+
const parsed = ButtonActionSchema.safeParse({
|
|
46
|
+
type: "requestPermission",
|
|
47
|
+
kind: "notifications",
|
|
48
|
+
});
|
|
49
|
+
expect(parsed.success).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("accepts all three outcome hooks as nested ButtonAction lists", () => {
|
|
53
|
+
const parsed = ButtonActionSchema.safeParse({
|
|
54
|
+
type: "requestPermission",
|
|
55
|
+
kind: "notifications",
|
|
56
|
+
onGranted: [{ type: "setVariable", name: "push", value: "on" }, "continue"],
|
|
57
|
+
onDenied: ["continue"],
|
|
58
|
+
onUnavailable: [{ type: "dismiss" }],
|
|
59
|
+
});
|
|
60
|
+
expect(parsed.success).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("accepts a requestPermission nested inside another action's hook", () => {
|
|
64
|
+
// Recursion through the same union is what makes ask-then-ask possible, and
|
|
65
|
+
// is the property `purchase.onSuccess` already relies on.
|
|
66
|
+
const parsed = ButtonActionSchema.safeParse({
|
|
67
|
+
type: "purchase",
|
|
68
|
+
product: "yearly",
|
|
69
|
+
onSuccess: [{ type: "requestPermission", kind: "notifications", onGranted: ["continue"] }],
|
|
70
|
+
});
|
|
71
|
+
expect(parsed.success).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("rejects a missing kind", () => {
|
|
75
|
+
expect(
|
|
76
|
+
ButtonActionSchema.safeParse({ type: "requestPermission" }).success
|
|
77
|
+
).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("rejects an unknown kind", () => {
|
|
81
|
+
expect(
|
|
82
|
+
ButtonActionSchema.safeParse({ type: "requestPermission", kind: "healthkit" }).success
|
|
83
|
+
).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("rejects a non-array outcome hook", () => {
|
|
87
|
+
expect(
|
|
88
|
+
ButtonActionSchema.safeParse({
|
|
89
|
+
type: "requestPermission",
|
|
90
|
+
kind: "camera",
|
|
91
|
+
onGranted: "continue",
|
|
92
|
+
}).success
|
|
93
|
+
).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("rejects a garbage action inside an outcome hook", () => {
|
|
97
|
+
expect(
|
|
98
|
+
ButtonActionSchema.safeParse({
|
|
99
|
+
type: "requestPermission",
|
|
100
|
+
kind: "camera",
|
|
101
|
+
onGranted: [{ type: "notAnAction" }],
|
|
102
|
+
}).success
|
|
103
|
+
).toBe(false);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("UIElement round-trip", () => {
|
|
108
|
+
it("parses a Button whose actions request a permission", () => {
|
|
109
|
+
const parsed = UIElementSchema.safeParse({
|
|
110
|
+
id: "cta",
|
|
111
|
+
type: "Button",
|
|
112
|
+
props: {
|
|
113
|
+
label: "Enable notifications",
|
|
114
|
+
actions: [
|
|
115
|
+
{
|
|
116
|
+
type: "requestPermission",
|
|
117
|
+
kind: "notifications",
|
|
118
|
+
onGranted: ["continue"],
|
|
119
|
+
onDenied: ["continue"],
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
expect(parsed.success).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("parses a generic onPress that requests a permission", () => {
|
|
128
|
+
const parsed = UIElementSchema.safeParse({
|
|
129
|
+
id: "card",
|
|
130
|
+
type: "YStack",
|
|
131
|
+
props: {
|
|
132
|
+
onPress: [{ type: "requestPermission", kind: "photoLibrary", onGranted: ["continue"] }],
|
|
133
|
+
},
|
|
134
|
+
children: [],
|
|
135
|
+
});
|
|
136
|
+
expect(parsed.success).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
});
|