@rocapine/react-native-onboarding 1.75.0 → 1.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +16 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/onboarding-example.d.ts +140 -0
  6. package/dist/onboarding-example.d.ts.map +1 -1
  7. package/dist/onboarding-example.js +41 -1
  8. package/dist/onboarding-example.js.map +1 -1
  9. package/dist/paywalls/PaywallProvider.d.ts +71 -5
  10. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  11. package/dist/paywalls/PaywallProvider.js +237 -57
  12. package/dist/paywalls/PaywallProvider.js.map +1 -1
  13. package/dist/paywalls/customScreens.d.ts +31 -0
  14. package/dist/paywalls/customScreens.d.ts.map +1 -1
  15. package/dist/paywalls/observer.d.ts +129 -0
  16. package/dist/paywalls/observer.d.ts.map +1 -0
  17. package/dist/paywalls/observer.js +211 -0
  18. package/dist/paywalls/observer.js.map +1 -0
  19. package/dist/paywalls/present.d.ts +19 -15
  20. package/dist/paywalls/present.d.ts.map +1 -1
  21. package/dist/paywalls/present.js +21 -17
  22. package/dist/paywalls/present.js.map +1 -1
  23. package/dist/paywalls/types.d.ts +3 -1
  24. package/dist/paywalls/types.d.ts.map +1 -1
  25. package/dist/products/adapters/expoIap.d.ts +38 -1
  26. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  27. package/dist/products/adapters/expoIap.js +509 -75
  28. package/dist/products/adapters/expoIap.js.map +1 -1
  29. package/dist/products/index.d.ts +1 -0
  30. package/dist/products/index.d.ts.map +1 -1
  31. package/dist/products/index.js.map +1 -1
  32. package/dist/products/types.d.ts +13 -0
  33. package/dist/products/types.d.ts.map +1 -1
  34. package/dist/screens/completingActions.d.ts +55 -3
  35. package/dist/screens/completingActions.d.ts.map +1 -1
  36. package/dist/screens/completingActions.js +209 -15
  37. package/dist/screens/completingActions.js.map +1 -1
  38. package/dist/screens/elementTypeRegistry.d.ts +14 -0
  39. package/dist/screens/elementTypeRegistry.d.ts.map +1 -1
  40. package/dist/screens/elementTypeRegistry.js +38 -1
  41. package/dist/screens/elementTypeRegistry.js.map +1 -1
  42. package/dist/screens/elements/ButtonElement.d.ts +3 -2
  43. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  44. package/dist/screens/elements/ButtonElement.js +5 -1
  45. package/dist/screens/elements/ButtonElement.js.map +1 -1
  46. package/dist/screens/types.d.ts +2 -2
  47. package/dist/screens/types.d.ts.map +1 -1
  48. package/dist/screens/types.js +5 -1
  49. package/dist/screens/types.js.map +1 -1
  50. package/dist/screens/unknownKeys.d.ts +25 -4
  51. package/dist/screens/unknownKeys.d.ts.map +1 -1
  52. package/dist/screens/unknownKeys.js +81 -2
  53. package/dist/screens/unknownKeys.js.map +1 -1
  54. package/dist/steps/common.types.d.ts +178 -6
  55. package/dist/steps/common.types.d.ts.map +1 -1
  56. package/dist/steps/common.types.js +64 -3
  57. package/dist/steps/common.types.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/__tests__/authoringDocEscapes.test.ts +59 -0
  60. package/src/__tests__/completingActions.test.ts +371 -1
  61. package/src/__tests__/customActionHooks.test.ts +224 -0
  62. package/src/__tests__/onboardingExampleElements.test.ts +47 -0
  63. package/src/__tests__/requestPermissionAction.test.ts +138 -0
  64. package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
  65. package/src/__tests__/unknownKeys.test.ts +110 -0
  66. package/src/index.ts +33 -1
  67. package/src/onboarding-example.ts +41 -1
  68. package/src/paywalls/PaywallProvider.tsx +370 -66
  69. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
  70. package/src/paywalls/__tests__/observer.test.ts +401 -0
  71. package/src/paywalls/__tests__/present.test.ts +0 -18
  72. package/src/paywalls/customScreens.ts +34 -1
  73. package/src/paywalls/observer.ts +308 -0
  74. package/src/paywalls/present.ts +24 -18
  75. package/src/paywalls/types.ts +3 -1
  76. package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
  77. package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
  78. package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
  79. package/src/products/adapters/expoIap.ts +609 -78
  80. package/src/products/index.ts +1 -0
  81. package/src/products/types.ts +13 -0
  82. package/src/screens/completingActions.ts +223 -15
  83. package/src/screens/elementTypeRegistry.ts +34 -0
  84. package/src/screens/elements/ButtonElement.ts +9 -1
  85. package/src/screens/types.ts +2 -2
  86. package/src/screens/unknownKeys.ts +113 -7
  87. package/src/steps/common.types.ts +213 -6
@@ -53,17 +53,120 @@ export type HapticStyle = z.infer<typeof HapticStyleSchema>;
53
53
  // `{type:"presentPaywall"}` (asks the host to present a paywall by placement —
54
54
  // works from an onboarding step or a paywall alike).
55
55
 
56
+ /**
57
+ * Bounded retry for a `custom` action (#191). The cap is REQUIRED and small:
58
+ * an onboarding gate that keeps hammering a dead service just holds the user on
59
+ * a screen that never resolves, so there is deliberately no "retry until it
60
+ * works" spelling.
61
+ *
62
+ * **The handler must be safe to re-run.** A retry re-invokes the SAME host
63
+ * function with the SAME press-time variables, so a handler that writes is
64
+ * asked to write again: `maxAttempts: 3` over a `/create-plan` or a charge is
65
+ * three records or three charges for one press, and neither the schema, the
66
+ * runtime nor the console can tell a safe handler from an unsafe one — this
67
+ * field is the only place the hazard is stated. `timeoutMs` widens it rather
68
+ * than bounding it: a timed-out attempt is an ordinary failed attempt, so a
69
+ * request that reached the server and lost only the ANSWER to the clock is sent
70
+ * again. Retry a read, a validation, or a write carrying an idempotency key;
71
+ * for anything else leave `retry` absent and put the recovery in `onError`.
72
+ * (Same class as the `purchase` double-fire that `disabledWhen` on
73
+ * `products.purchasing` exists to prevent — one press, several writes, nothing
74
+ * reporting it.)
75
+ */
76
+ export type CustomActionRetry = {
77
+ /**
78
+ * TOTAL attempts, counting the first — `2` means "try once, retry once".
79
+ * 1..10. Absent `retry` is the default and means exactly one attempt.
80
+ */
81
+ maxAttempts: number;
82
+ /** Fixed pause between attempts, ms (0..10000). Defaults to 0. */
83
+ delayMs?: number;
84
+ /**
85
+ * How long ONE attempt may take before it counts as failed, ms
86
+ * (1000..300000). Absent means UNBOUNDED — the behaviour before this field
87
+ * existed, and the right default: a legitimate LLM call can take 60s+, and
88
+ * cutting one off by default would be a worse bug than the hang (#264).
89
+ *
90
+ * The hang it prevents is a dead screen, not a slow one. The handler is
91
+ * awaited while the runtime holds this element's single-flight claim, so a
92
+ * promise that never settles leaves `actions.pending.<elementId>` reading
93
+ * `"true"` for the life of the screen — and the payload these docs recommend
94
+ * disables the CTA on exactly that, with no back chevron on a
95
+ * `displayProgressHeader: false` step.
96
+ *
97
+ * A timed-out attempt is an ordinary failed attempt: it retries if the budget
98
+ * allows, and otherwise runs `onError` like any other failure. Declaring a
99
+ * timeout without retries is `{ maxAttempts: 1, timeoutMs: … }` — the object
100
+ * is the attempt policy, and one attempt is a policy.
101
+ */
102
+ timeoutMs?: number;
103
+ };
104
+
105
+ export const CustomActionRetrySchema = z.object({
106
+ maxAttempts: z
107
+ .number()
108
+ .int("maxAttempts must be a whole number of attempts")
109
+ .min(1, "maxAttempts must be at least 1")
110
+ .max(10, "maxAttempts must be at most 10"),
111
+ delayMs: z.number().min(0).max(10000).optional(),
112
+ timeoutMs: z
113
+ .number()
114
+ .min(1000, "timeoutMs must be at least 1000 (no real handler answers faster)")
115
+ .max(300000, "timeoutMs must be at most 300000 (five minutes)")
116
+ .optional(),
117
+ });
118
+
56
119
  export type CustomButtonAction = {
57
120
  type: "custom";
58
121
  function: string;
59
122
  variables?: string[];
123
+ /**
124
+ * Actions to run once the host handler's promise RESOLVES. Non-terminal: the
125
+ * enclosing action list carries on afterwards, exactly as it does for a
126
+ * handler with no hooks.
127
+ *
128
+ * This is where anything that must only happen ON SUCCESS belongs — writing
129
+ * the result into a variable a later screen reads, and the `"continue"` of a
130
+ * gate that must not advance on failure. A `"continue"` placed AFTER the
131
+ * `custom` action instead advances on every outcome, which is the right
132
+ * shape for "fire and move on" and the wrong one for a gate.
133
+ */
134
+ onResolve?: ButtonAction[];
135
+ /**
136
+ * Actions to run when the handler FAILS — it threw with every attempt spent,
137
+ * an attempt exceeded `retry.timeoutMs`, or the `function` name is not
138
+ * registered on the host at all. One rule for all three.
139
+ *
140
+ * NOT terminal, with or without this hook: the enclosing list carries on,
141
+ * exactly as `purchase`/`restore` do on their own `onError`. `custom` used to
142
+ * diverge here — a throw aborted the list — and that divergence is gone
143
+ * (semantics decisions 1 and 2, recorded on #191 on 2026-09-11; ticket #266).
144
+ * It cost more than it bought: two spellings of "on error" inside one action
145
+ * union behaving differently with nothing in the payload, the schema or the
146
+ * console to tell them apart, and the two `custom` failure modes disagreeing
147
+ * with each other. What the abort was protecting — a trailing `"continue"`
148
+ * walking the user onto a screen that reads variables the handler never wrote
149
+ * — is `onResolve`'s job, where the author says it rather than the runtime
150
+ * guessing it.
151
+ *
152
+ * The failure is still `console.error`ed whether or not this hook is declared
153
+ * — a declared hook is error UI, not a reason to lose the stack trace.
154
+ */
155
+ onError?: ButtonAction[];
156
+ /** Bounded retry of the handler. Absent means one attempt, no retry. */
157
+ retry?: CustomActionRetry;
60
158
  };
61
159
 
62
- export const CustomButtonActionSchema = z.object({
63
- type: z.literal("custom"),
64
- function: z.string().min(1, "function must not be empty"),
65
- variables: z.array(z.string()).optional(),
66
- });
160
+ export const CustomButtonActionSchema: z.ZodType<CustomButtonAction> = z.lazy(() =>
161
+ z.object({
162
+ type: z.literal("custom"),
163
+ function: z.string().min(1, "function must not be empty"),
164
+ variables: z.array(z.string()).optional(),
165
+ onResolve: z.array(ButtonActionSchema).optional(),
166
+ onError: z.array(ButtonActionSchema).optional(),
167
+ retry: CustomActionRetrySchema.optional(),
168
+ })
169
+ );
67
170
 
68
171
  export type SetVariableButtonAction = {
69
172
  type: "setVariable";
@@ -229,6 +332,97 @@ export const PresentPaywallButtonActionSchema = z.object({
229
332
  placement: z.string().min(1, "placement must not be empty"),
230
333
  });
231
334
 
335
+ /**
336
+ * The permissions a `requestPermission` action can ask for.
337
+ *
338
+ * Deliberately narrow, and closed. Every member here is reachable through an
339
+ * **optionally installed** Expo module that the UI package dynamic-`require`s
340
+ * at press time (the `expo-haptics` precedent), so an app that does not need a
341
+ * permission does not carry its native code:
342
+ *
343
+ * | kind | module(s) tried, in order |
344
+ * |---|---|
345
+ * | `notifications` | `expo-notifications` |
346
+ * | `appTrackingTransparency` | `expo-tracking-transparency` (iOS 14+; other platforms report `granted`) |
347
+ * | `locationWhenInUse` | `expo-location` (foreground only — background location needs its own review justification) |
348
+ * | `camera` | `expo-camera` |
349
+ * | `microphone` | `expo-audio`, then `expo-camera` |
350
+ * | `photoLibrary` | `expo-image-picker`, then `expo-media-library` |
351
+ *
352
+ * NOT members, on purpose: **HealthKit** and **Screen Time / Family Controls**.
353
+ * Both need app-owned entitlements and a config plugin neither package ships,
354
+ * so neither can be honestly requested from inside the SDK. They arrive through
355
+ * the host `requestPermission` resolver on the `ScreenHost` (the same seam as
356
+ * `products` / `presentPaywall`) once a `kind` for them is added — a
357
+ * deliberately separate decision, not a silent no-op today.
358
+ *
359
+ * READING a permission's current status is not here either: this is a press
360
+ * action, and "skip the screen when already granted" is a variable-bag
361
+ * capability with nowhere to live in this shape. Tracked separately.
362
+ */
363
+ export const PERMISSION_KINDS = [
364
+ "notifications",
365
+ "appTrackingTransparency",
366
+ "locationWhenInUse",
367
+ "camera",
368
+ "microphone",
369
+ "photoLibrary",
370
+ ] as const;
371
+
372
+ export type PermissionKind = (typeof PERMISSION_KINDS)[number];
373
+
374
+ export const PermissionKindSchema = z.enum(PERMISSION_KINDS);
375
+
376
+ /**
377
+ * Ask the OS for a permission, then branch on the answer **within the same
378
+ * press**.
379
+ *
380
+ * This is what `[{type:"custom", …}, "continue"]` could not do: a custom
381
+ * handler's return value is discarded, so a host asking for notifications could
382
+ * only influence a LATER screen, through a variable it wrote. Here `onGranted`
383
+ * and `onDenied` are ordinary nested `ButtonAction[]` lists — the exact shape
384
+ * `purchase.onSuccess` / `restore.onNothingToRestore` already use, recursed
385
+ * through the same `runActions` — so one CTA can advance on a grant and, say,
386
+ * set a variable and still advance on a refusal.
387
+ *
388
+ * Asking is **idempotent from the OS's point of view, not the SDK's**: iOS shows
389
+ * its system prompt only the first time, and every later request resolves
390
+ * immediately with the standing answer. So a second press does not re-prompt —
391
+ * but it does re-run the matching hook.
392
+ *
393
+ * `onUnavailable` covers "this build cannot ask": the Expo module is not
394
+ * installed, or the platform has no such permission. It does **not** fall back
395
+ * to `onDenied` — nobody refused anything, and running the refusal branch wrote
396
+ * `att = "denied"` and fired refusal analytics for a user who was never asked
397
+ * (review round 1 of #196). Omitted, the runtime instead REUSES THIS ASK'S OWN
398
+ * completing action: if `onGranted`/`onDenied` reach a `"continue"` or a
399
+ * `{dismiss}`, the screen is completed with that same action (`{dismiss}`
400
+ * winning when both are reachable, since the SDK must not claim the more
401
+ * permissive of two answers nobody gave), and no other authored side effect
402
+ * runs. If the ask was never a way off the screen — a "turn on notifications"
403
+ * button beside its own Skip CTA — nothing happens. Either way it is reported
404
+ * with `console.error`: declare `onUnavailable` if you care which.
405
+ */
406
+ export type RequestPermissionButtonAction = {
407
+ type: "requestPermission";
408
+ kind: PermissionKind;
409
+ /** Runs when the OS reports the permission granted. */
410
+ onGranted?: ButtonAction[];
411
+ /** Runs when the OS reports it denied, restricted, or dismissed. */
412
+ onDenied?: ButtonAction[];
413
+ /**
414
+ * Runs when this build cannot ask at all — module absent, or platform has no
415
+ * such permission.
416
+ *
417
+ * Omitted, the runtime does NOT run `onDenied` (the user refused nothing). It
418
+ * completes the screen with whichever completing action this ask already
419
+ * declares, preferring `{dismiss}` over `"continue"`, and runs no other side
420
+ * effect; an ask that was never a way off the screen does nothing. Both cases
421
+ * log a `console.error`. Declare this hook to decide it yourself.
422
+ */
423
+ onUnavailable?: ButtonAction[];
424
+ };
425
+
232
426
  export type ButtonAction =
233
427
  | "continue"
234
428
  | CustomButtonAction
@@ -236,7 +430,8 @@ export type ButtonAction =
236
430
  | PurchaseButtonAction
237
431
  | RestoreButtonAction
238
432
  | DismissButtonAction
239
- | PresentPaywallButtonAction;
433
+ | PresentPaywallButtonAction
434
+ | RequestPermissionButtonAction;
240
435
 
241
436
  export const PurchaseButtonActionSchema: z.ZodType<PurchaseButtonAction> = z.lazy(() =>
242
437
  z.object({
@@ -258,6 +453,17 @@ export const RestoreButtonActionSchema: z.ZodType<RestoreButtonAction> = z.lazy(
258
453
  })
259
454
  );
260
455
 
456
+ export const RequestPermissionButtonActionSchema: z.ZodType<RequestPermissionButtonAction> =
457
+ z.lazy(() =>
458
+ z.object({
459
+ type: z.literal("requestPermission"),
460
+ kind: PermissionKindSchema,
461
+ onGranted: z.array(ButtonActionSchema).optional(),
462
+ onDenied: z.array(ButtonActionSchema).optional(),
463
+ onUnavailable: z.array(ButtonActionSchema).optional(),
464
+ })
465
+ );
466
+
261
467
  export const ButtonActionSchema: z.ZodType<ButtonAction> = z.lazy(() =>
262
468
  z.union([
263
469
  z.literal("continue"),
@@ -267,6 +473,7 @@ export const ButtonActionSchema: z.ZodType<ButtonAction> = z.lazy(() =>
267
473
  RestoreButtonActionSchema,
268
474
  DismissButtonActionSchema,
269
475
  PresentPaywallButtonActionSchema,
476
+ RequestPermissionButtonActionSchema,
270
477
  ])
271
478
  );
272
479