@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.
Files changed (117) hide show
  1. package/README.md +30 -4
  2. package/dist/OnboardingStudioClient.d.ts +18 -0
  3. package/dist/OnboardingStudioClient.d.ts.map +1 -1
  4. package/dist/OnboardingStudioClient.js +44 -17
  5. package/dist/OnboardingStudioClient.js.map +1 -1
  6. package/dist/index.d.ts +5 -3
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +16 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/onboarding-example.d.ts +140 -0
  11. package/dist/onboarding-example.d.ts.map +1 -1
  12. package/dist/onboarding-example.js +41 -1
  13. package/dist/onboarding-example.js.map +1 -1
  14. package/dist/paywalls/PaywallProvider.d.ts +71 -5
  15. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  16. package/dist/paywalls/PaywallProvider.js +237 -57
  17. package/dist/paywalls/PaywallProvider.js.map +1 -1
  18. package/dist/paywalls/customScreens.d.ts +31 -0
  19. package/dist/paywalls/customScreens.d.ts.map +1 -1
  20. package/dist/paywalls/observer.d.ts +129 -0
  21. package/dist/paywalls/observer.d.ts.map +1 -0
  22. package/dist/paywalls/observer.js +211 -0
  23. package/dist/paywalls/observer.js.map +1 -0
  24. package/dist/paywalls/present.d.ts +19 -15
  25. package/dist/paywalls/present.d.ts.map +1 -1
  26. package/dist/paywalls/present.js +21 -17
  27. package/dist/paywalls/present.js.map +1 -1
  28. package/dist/paywalls/types.d.ts +3 -1
  29. package/dist/paywalls/types.d.ts.map +1 -1
  30. package/dist/products/adapters/expoIap.d.ts +38 -1
  31. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  32. package/dist/products/adapters/expoIap.js +509 -75
  33. package/dist/products/adapters/expoIap.js.map +1 -1
  34. package/dist/products/index.d.ts +1 -0
  35. package/dist/products/index.d.ts.map +1 -1
  36. package/dist/products/index.js.map +1 -1
  37. package/dist/products/types.d.ts +13 -0
  38. package/dist/products/types.d.ts.map +1 -1
  39. package/dist/requestIdentity.d.ts +41 -0
  40. package/dist/requestIdentity.d.ts.map +1 -0
  41. package/dist/requestIdentity.js +70 -0
  42. package/dist/requestIdentity.js.map +1 -0
  43. package/dist/screens/completingActions.d.ts +55 -3
  44. package/dist/screens/completingActions.d.ts.map +1 -1
  45. package/dist/screens/completingActions.js +209 -15
  46. package/dist/screens/completingActions.js.map +1 -1
  47. package/dist/screens/elementTypeRegistry.d.ts +14 -0
  48. package/dist/screens/elementTypeRegistry.d.ts.map +1 -1
  49. package/dist/screens/elementTypeRegistry.js +38 -1
  50. package/dist/screens/elementTypeRegistry.js.map +1 -1
  51. package/dist/screens/elements/ButtonElement.d.ts +3 -2
  52. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  53. package/dist/screens/elements/ButtonElement.js +5 -1
  54. package/dist/screens/elements/ButtonElement.js.map +1 -1
  55. package/dist/screens/types.d.ts +2 -2
  56. package/dist/screens/types.d.ts.map +1 -1
  57. package/dist/screens/types.js +5 -1
  58. package/dist/screens/types.js.map +1 -1
  59. package/dist/screens/unknownKeys.d.ts +25 -4
  60. package/dist/screens/unknownKeys.d.ts.map +1 -1
  61. package/dist/screens/unknownKeys.js +81 -2
  62. package/dist/screens/unknownKeys.js.map +1 -1
  63. package/dist/steps/common.types.d.ts +178 -6
  64. package/dist/steps/common.types.d.ts.map +1 -1
  65. package/dist/steps/common.types.js +64 -3
  66. package/dist/steps/common.types.js.map +1 -1
  67. package/dist/types.d.ts +17 -0
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/userProperties/reserved.d.ts +16 -15
  70. package/dist/userProperties/reserved.d.ts.map +1 -1
  71. package/dist/userProperties/reserved.js +18 -14
  72. package/dist/userProperties/reserved.js.map +1 -1
  73. package/dist/version.d.ts +10 -0
  74. package/dist/version.d.ts.map +1 -0
  75. package/dist/version.js +13 -0
  76. package/dist/version.js.map +1 -0
  77. package/package.json +5 -1
  78. package/src/OnboardingStudioClient.ts +47 -19
  79. package/src/__tests__/authoringDocEscapes.test.ts +59 -0
  80. package/src/__tests__/completingActions.test.ts +371 -1
  81. package/src/__tests__/customActionHooks.test.ts +224 -0
  82. package/src/__tests__/getOnboarding.query.test.ts +30 -0
  83. package/src/__tests__/onboardingExampleElements.test.ts +47 -0
  84. package/src/__tests__/requestIdentity.client.test.ts +115 -0
  85. package/src/__tests__/requestIdentity.test.ts +112 -0
  86. package/src/__tests__/requestPermissionAction.test.ts +138 -0
  87. package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
  88. package/src/__tests__/unknownKeys.test.ts +110 -0
  89. package/src/index.ts +33 -1
  90. package/src/onboarding-example.ts +41 -1
  91. package/src/paywalls/PaywallProvider.tsx +370 -66
  92. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
  93. package/src/paywalls/__tests__/getPaywalls.test.ts +30 -0
  94. package/src/paywalls/__tests__/observer.test.ts +401 -0
  95. package/src/paywalls/__tests__/present.test.ts +0 -18
  96. package/src/paywalls/customScreens.ts +34 -1
  97. package/src/paywalls/observer.ts +308 -0
  98. package/src/paywalls/present.ts +24 -18
  99. package/src/paywalls/types.ts +3 -1
  100. package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
  101. package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
  102. package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
  103. package/src/products/adapters/expoIap.ts +609 -78
  104. package/src/products/index.ts +1 -0
  105. package/src/products/types.ts +13 -0
  106. package/src/requestIdentity.ts +101 -0
  107. package/src/screens/completingActions.ts +223 -15
  108. package/src/screens/elementTypeRegistry.ts +34 -0
  109. package/src/screens/elements/ButtonElement.ts +9 -1
  110. package/src/screens/types.ts +2 -2
  111. package/src/screens/unknownKeys.ts +113 -7
  112. package/src/steps/common.types.ts +213 -6
  113. package/src/types.ts +17 -0
  114. package/src/userProperties/__tests__/effectiveParams.test.ts +2 -2
  115. package/src/userProperties/__tests__/primitives.test.ts +1 -1
  116. package/src/userProperties/reserved.ts +18 -14
  117. package/src/version.ts +9 -0
@@ -0,0 +1,57 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+
5
+ /**
6
+ * `retry` re-invokes the SAME host handler with the same press-time variables,
7
+ * up to ten times, and a timed-out attempt is an ordinary failed attempt — so a
8
+ * handler that POSTs is asked to POST again, including after an attempt that
9
+ * reached the server and lost only the ANSWER to the clock. Neither the schema,
10
+ * the runtime nor the console can tell a safe handler from an unsafe one, which
11
+ * leaves the prose as the only place the hazard can be stated — and until this
12
+ * test, `grep -i idempoten` over the retry docs returned nothing (review round 2
13
+ * of !263, finding 5).
14
+ *
15
+ * Declared rather than discovered, like `SURFACES` in
16
+ * `scripts/check-element-docs.mjs`: the `maxAttempts` assertion fails if a file
17
+ * stops teaching retry, so the list cannot quietly go stale in either
18
+ * direction. Deliberately NOT here: `Runtime/elements/runActions.ts` (the
19
+ * implementation, not an authoring surface) and the example payloads.
20
+ */
21
+ const RETRY_SURFACES = [
22
+ "packages/onboarding/src/steps/common.types.ts",
23
+ "packages/onboarding-ui/src/UI/Runtime/elements/actions.ts",
24
+ "website/docs/customization/custom-actions.mdx",
25
+ "website/docs/page-types.mdx",
26
+ "claude-plugin/skills/validate-step-json/SKILL.md",
27
+ "claude-plugin/skills/compose-screen-builder/SKILL.md",
28
+ "claude-plugin/agents/step-json-reviewer.md",
29
+ ];
30
+
31
+ const ROOT = join(__dirname, "../../../..");
32
+
33
+ /**
34
+ * The warning has to sit WITH the retry teaching, not merely somewhere in the
35
+ * file: `common.types.ts` already says "idempotent" ~280 lines away, about
36
+ * `requestPermission` and the OS's prompt, and a whole-file check passed on that
37
+ * sentence while the retry doc itself said nothing. So the region checked is the
38
+ * span of the file's `maxAttempts` mentions, widened by this much either side.
39
+ */
40
+ const REGION_MARGIN = 1500;
41
+
42
+ describe("retry docs — every surface that teaches `retry` warns it re-runs the handler", () => {
43
+ it.each(RETRY_SURFACES)("%s", (rel) => {
44
+ const src = readFileSync(join(ROOT, rel), "utf8");
45
+ const first = src.indexOf("maxAttempts");
46
+ expect(first, `${rel} no longer teaches retry — drop it from RETRY_SURFACES`).toBeGreaterThan(
47
+ -1
48
+ );
49
+ const region = src
50
+ .slice(Math.max(0, first - REGION_MARGIN), src.lastIndexOf("maxAttempts") + REGION_MARGIN)
51
+ .toLowerCase();
52
+ expect(
53
+ region,
54
+ `${rel} teaches retry without saying the handler must be idempotent`
55
+ ).toContain("idempot");
56
+ });
57
+ });
@@ -232,3 +232,113 @@ describe("formatUnknownElementKeys", () => {
232
232
  expect(msg).toContain("silently dropped");
233
233
  });
234
234
  });
235
+
236
+ /**
237
+ * Keys on an ACTION object, not on the element (#196, review round 1).
238
+ *
239
+ * `ButtonActionSchema` is a plain non-strict `z.object` union — deliberately, for
240
+ * the same reason the element schemas are (`unknownKeys.ts`'s header:
241
+ * `.strict()` would turn a published payload carrying a stray key into a dead
242
+ * screen). The price is that a misspelled outcome hook is completely silent:
243
+ * `{"type":"requestPermission","onGranted":["continue"],"onDeneid":["continue"]}`
244
+ * validates clean, the key is stripped, and the denial branch is dead — on a
245
+ * permission screen that is a CTA the refusing user cannot get past.
246
+ *
247
+ * So it is reported the same non-fatal way a misplaced `animation` is, through
248
+ * the `__DEV__` check `OnboardingProvider` already runs on every fetched
249
+ * payload. Key sets are derived from `ButtonActionSchema` itself, so they cover
250
+ * `purchase.onSucces` and every action added later with no change here.
251
+ */
252
+ describe("collectUnknownElementKeys — action keys", () => {
253
+ const withActions = (actions: unknown) => [
254
+ { id: "cta", type: "Button", props: { label: "Go", actions } },
255
+ ];
256
+
257
+ it("reports a misspelled requestPermission outcome hook", () => {
258
+ const found = collectUnknownElementKeys(
259
+ withActions([
260
+ { type: "requestPermission", kind: "notifications", onGranted: ["continue"], onDeneid: ["continue"] },
261
+ ])
262
+ );
263
+ expect(found).toHaveLength(1);
264
+ expect(found[0].key).toBe("onDeneid");
265
+ expect(found[0].scope).toBe("action");
266
+ expect(found[0].actionType).toBe("requestPermission");
267
+ expect(found[0].path).toBe("elements[0].props.actions[0]");
268
+ expect(found[0].elementId).toBe("cta");
269
+ });
270
+
271
+ it("reports a misspelled purchase hook — the derivation is not permission-specific", () => {
272
+ const found = collectUnknownElementKeys(
273
+ withActions([{ type: "purchase", product: "yearly", onSucces: ["continue"] }])
274
+ );
275
+ expect(found.map((f) => f.key)).toEqual(["onSucces"]);
276
+ });
277
+
278
+ it("says nothing about a correctly spelled action", () => {
279
+ expect(
280
+ collectUnknownElementKeys(
281
+ withActions([
282
+ "continue",
283
+ { type: "requestPermission", kind: "camera", onGranted: ["continue"], onDenied: ["continue"], onUnavailable: ["continue"] },
284
+ { type: "setVariable", name: "a", value: "b", valueMode: "expression", kind: "int", arrayOp: "toggle", label: "A" },
285
+ { type: "purchase", product: "yearly", onSuccess: ["continue"], onCancel: [], onError: [], onPending: [] },
286
+ { type: "restore", onSuccess: ["continue"], onNothingToRestore: [], onError: [] },
287
+ { type: "dismiss" },
288
+ { type: "presentPaywall", placement: "x" },
289
+ { type: "custom", function: "f", variables: ["a"] },
290
+ ])
291
+ )
292
+ ).toEqual([]);
293
+ });
294
+
295
+ it("walks into an outcome hook's own actions", () => {
296
+ const found = collectUnknownElementKeys(
297
+ withActions([
298
+ {
299
+ type: "requestPermission",
300
+ kind: "notifications",
301
+ onGranted: [{ type: "purchase", product: "yearly", onErrr: ["continue"] }],
302
+ onDenied: ["continue"],
303
+ },
304
+ ])
305
+ );
306
+ expect(found).toHaveLength(1);
307
+ expect(found[0].key).toBe("onErrr");
308
+ expect(found[0].path).toBe("elements[0].props.actions[0].onGranted[0]");
309
+ });
310
+
311
+ it("covers the generic onPress list too", () => {
312
+ const found = collectUnknownElementKeys([
313
+ { id: "card", type: "YStack", props: { onPress: [{ type: "dismiss", statuss: "x" }] }, children: [] },
314
+ ]);
315
+ expect(found.map((f) => f.key)).toEqual(["statuss"]);
316
+ expect(found[0].path).toBe("elements[0].props.onPress[0]");
317
+ });
318
+
319
+ // An action type this build does not know is a parse failure, not a stray
320
+ // key — guessing its key set would be noise, exactly as for an unknown
321
+ // element type.
322
+ it("skips an action type it does not know", () => {
323
+ expect(
324
+ collectUnknownElementKeys(withActions([{ type: "requestBiometrics", onGranted: ["continue"] }]))
325
+ ).toEqual([]);
326
+ });
327
+
328
+ it("tolerates malformed action lists", () => {
329
+ expect(collectUnknownElementKeys(withActions("continue"))).toEqual([]);
330
+ expect(collectUnknownElementKeys(withActions([null, 42, "continue"]))).toEqual([]);
331
+ expect(collectUnknownElementKeys(withActions([{}]))).toEqual([]);
332
+ });
333
+
334
+ it("formats an action finding as a dropped key on that action", () => {
335
+ const msg = formatUnknownElementKeys(
336
+ collectUnknownElementKeys(
337
+ withActions([{ type: "requestPermission", kind: "notifications", onDeneid: ["continue"] }])
338
+ )
339
+ );
340
+ expect(msg).toContain("onDeneid");
341
+ expect(msg).toContain("requestPermission");
342
+ expect(msg).toContain("elements[0].props.actions[0]");
343
+ });
344
+ });
package/src/index.ts CHANGED
@@ -11,7 +11,10 @@ export {
11
11
  export type {
12
12
  ButtonAction,
13
13
  CustomButtonAction,
14
+ CustomActionRetry,
14
15
  SetVariableButtonAction,
16
+ RequestPermissionButtonAction,
17
+ PermissionKind,
15
18
  ComposableVariableEntry,
16
19
  ComposableVariableKind,
17
20
  WheelPickerElementProps,
@@ -42,7 +45,11 @@ export type {
42
45
  export {
43
46
  ButtonActionSchema,
44
47
  CustomButtonActionSchema,
48
+ CustomActionRetrySchema,
45
49
  SetVariableButtonActionSchema,
50
+ RequestPermissionButtonActionSchema,
51
+ PermissionKindSchema,
52
+ PERMISSION_KINDS,
46
53
  WheelPickerElementPropsSchema,
47
54
  generateWheelPickerRangeItems,
48
55
  resolveWheelPickerItems,
@@ -123,7 +130,20 @@ export type { UnknownElementType } from "./screens/unknownElementTypes";
123
130
  // versions can differ.
124
131
  export { resolveRenderableStep } from "./screens/resolveRenderableStep";
125
132
  export type { RenderableStep } from "./screens/resolveRenderableStep";
126
- export { hasCompletingAction } from "./screens/completingActions";
133
+ // `hasCompletingAction` answers it for a whole element tree (what the strip
134
+ // needs); `actionsCanComplete` answers it for one action list, which is what the
135
+ // UI runtime consults at press time before deciding whether a permission ask it
136
+ // could not perform has left the user with no way off the screen.
137
+ // `completingActionKind` answers WHICH of the two completing actions that list
138
+ // reaches — the runtime has to stand in for the author's escape with the same
139
+ // outcome the author authored, since `complete()` and `complete({status:
140
+ // "dismissed"})` are not interchangeable at a paywall's hard gate.
141
+ export {
142
+ hasCompletingAction,
143
+ actionsCanComplete,
144
+ completingActionKind,
145
+ } from "./screens/completingActions";
146
+ export type { EscapeAction } from "./screens/completingActions";
127
147
  export { deriveElementTypeNames } from "./screens/elementTypeRegistry";
128
148
  // Hooks and providers
129
149
  export * from "./infra";
@@ -177,6 +197,18 @@ export { PaywallProvider, usePaywallHost } from "./paywalls/PaywallProvider";
177
197
  // live in the headless package. onboarding-ui re-exports both names.
178
198
  export type { CustomPaywallScreenProps, CustomPaywallScreens } from "./paywalls/customScreens";
179
199
  export type { PaywallContextValue } from "./paywalls/PaywallProvider";
200
+ // `PaywallProvider`'s `observer` prop: the host's own analytics hook into every
201
+ // presentation. Names match rocalytics-sdk's `PaywallObserver` verbatim.
202
+ export type {
203
+ PaywallObserver,
204
+ PaywallPresentationInfo,
205
+ PaywallPresentationHandle,
206
+ PaywallPresentationEnd,
207
+ PaywallTransactionInfo,
208
+ PaywallSurface,
209
+ PaywallPresentation,
210
+ PaywallPresentationSource,
211
+ } from "./paywalls/observer";
180
212
  export { usePaywall } from "./paywalls/usePaywall";
181
213
  // Exported so a host can switch exhaustively on what the catalog is doing
182
214
  // rather than inferring it from `isReady` plus a non-null check.
@@ -1211,6 +1211,19 @@ export const onboardingExample = {
1211
1211
  },
1212
1212
  ],
1213
1213
  },
1214
+ // #191 — the runtime publishes `actions.pending.<elementId>` while
1215
+ // that element's action list is awaiting, so a pending state needs
1216
+ // no host code and no new element type.
1217
+ {
1218
+ id: "hero-button-pending",
1219
+ type: "Text",
1220
+ renderWhen: {
1221
+ variable: "actions.pending.hero-button",
1222
+ operator: "eq",
1223
+ value: "true",
1224
+ },
1225
+ props: { content: "One moment…", fontSize: 14, color: "#6B7280" },
1226
+ },
1214
1227
  {
1215
1228
  id: "hero-button",
1216
1229
  type: "Button",
@@ -1219,8 +1232,35 @@ export const onboardingExample = {
1219
1232
  variant: "filled",
1220
1233
  marginVertical: 8,
1221
1234
  haptic: "medium",
1235
+ // Deliberately NOT the `onResolve: ["continue"]` async-gate
1236
+ // shape (review round 1, findings 1 and 7). This payload is
1237
+ // the exported `fallbackOnboarding`, rendered by apps that
1238
+ // pass no `customActions` at all — `trackCta` is registered
1239
+ // nowhere in the SDK — and a gate puts the screen's only way
1240
+ // forward behind a handler that host may not have. The
1241
+ // trailing `"continue"` runs on the resolve path, and
1242
+ // `onError` covers the other two. The async gate is where
1243
+ // its handler is guaranteed: `example/app/example/
1244
+ // composable-screen.tsx` (`async-gate`), which is not that
1245
+ // screen's only CTA either.
1222
1246
  actions: [
1223
- { type: "custom", function: "trackCta", variables: ["name", "plan", "goals"] },
1247
+ {
1248
+ type: "custom",
1249
+ function: "trackCta",
1250
+ variables: ["name", "plan", "goals"],
1251
+ // One attempt, bounded (#264). `trackCta` is analytics —
1252
+ // if the host's handler never settles, the press never
1253
+ // finishes, the trailing `"continue"` never runs, and the
1254
+ // single-flight claim drops every further tap: a dead CTA
1255
+ // on the screen apps get when they pass no payload at
1256
+ // all. 8s is generous for a fire-and-forget beacon.
1257
+ retry: { maxAttempts: 1, timeoutMs: 8000 },
1258
+ // Kept although the trailing `"continue"` now runs on
1259
+ // every outcome (semantics decision 1 on #191): it makes
1260
+ // the intent explicit at the point a reader asks "what
1261
+ // happens offline?", and it is where failure UI would go.
1262
+ onError: ["continue"],
1263
+ },
1224
1264
  "continue",
1225
1265
  ],
1226
1266
  },