@rocapine/react-native-onboarding 1.74.1 → 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.
- package/dist/evaluateCondition.d.ts.map +1 -1
- package/dist/evaluateCondition.js +103 -4
- package/dist/evaluateCondition.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/onboarding-example.d.ts +375 -99
- package/dist/onboarding-example.d.ts.map +1 -1
- package/dist/onboarding-example.js +118 -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/screens/completingActions.d.ts +95 -0
- package/dist/screens/completingActions.d.ts.map +1 -0
- package/dist/screens/completingActions.js +302 -0
- package/dist/screens/completingActions.js.map +1 -0
- package/dist/screens/elementTypeRegistry.d.ts +45 -0
- package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
- package/dist/screens/elementTypeRegistry.js +119 -0
- package/dist/screens/elementTypeRegistry.js.map +1 -0
- 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/resolveRenderableStep.d.ts +42 -0
- package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
- package/dist/screens/resolveRenderableStep.js +28 -0
- package/dist/screens/resolveRenderableStep.js.map +1 -0
- 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/unknownElementTypes.d.ts +94 -0
- package/dist/screens/unknownElementTypes.d.ts.map +1 -0
- package/dist/screens/unknownElementTypes.js +141 -0
- package/dist/screens/unknownElementTypes.js.map +1 -0
- package/dist/screens/unknownKeys.d.ts +30 -6
- package/dist/screens/unknownKeys.d.ts.map +1 -1
- package/dist/screens/unknownKeys.js +88 -54
- package/dist/screens/unknownKeys.js.map +1 -1
- package/dist/steps/common.types.d.ts +262 -9
- 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/package.json +1 -1
- package/src/__tests__/authoringDocEscapes.test.ts +59 -0
- package/src/__tests__/completingActions.test.ts +509 -0
- package/src/__tests__/customActionHooks.test.ts +224 -0
- package/src/__tests__/elementTypeRegistry.test.ts +48 -0
- package/src/__tests__/evaluateCondition.test.ts +228 -3
- package/src/__tests__/onboardingExampleElements.test.ts +74 -0
- package/src/__tests__/requestPermissionAction.test.ts +138 -0
- package/src/__tests__/resolveRenderableStep.test.ts +117 -0
- package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
- package/src/__tests__/unknownElementTypes.test.ts +240 -0
- package/src/__tests__/unknownKeys.test.ts +110 -0
- package/src/evaluateCondition.ts +107 -4
- package/src/index.ts +55 -0
- package/src/onboarding-example.ts +119 -1
- package/src/paywalls/PaywallProvider.tsx +370 -66
- package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -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/screens/completingActions.ts +316 -0
- package/src/screens/elementTypeRegistry.ts +122 -0
- package/src/screens/elements/ButtonElement.ts +9 -1
- package/src/screens/resolveRenderableStep.ts +59 -0
- package/src/screens/types.ts +2 -2
- package/src/screens/unknownElementTypes.ts +204 -0
- package/src/screens/unknownKeys.ts +119 -56
- package/src/steps/common.types.ts +297 -9
|
@@ -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.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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";
|
|
@@ -71,9 +174,90 @@ export type SetVariableButtonAction = {
|
|
|
71
174
|
value: string;
|
|
72
175
|
label?: string;
|
|
73
176
|
/**
|
|
74
|
-
* When `"expression"`, `value` is parsed as an
|
|
75
|
-
*
|
|
76
|
-
*
|
|
177
|
+
* When `"expression"`, `value` is parsed as an expression over `{{var}}`
|
|
178
|
+
* references, numeric literals, quoted string literals, `+ - * /` (parens
|
|
179
|
+
* supported) and a small function stdlib:
|
|
180
|
+
*
|
|
181
|
+
* - numeric — `min(a, b, ...)`, `max(a, b, ...)`, `abs(a)`,
|
|
182
|
+
* `round(a[, digits])`, `clamp(a, lo, hi)`
|
|
183
|
+
* - dates — `addDays(date, n)`, `format(date, spec[, locale])`. `date` is an
|
|
184
|
+
* ISO string (what `DatePicker` stores) or the `"now"` sentinel `DatePicker`
|
|
185
|
+
* already accepts. `spec` is the `DatePicker` `format` prop's Intl
|
|
186
|
+
* vocabulary: a bare `dateStyle` name (`"medium"`) or `key:value` pairs
|
|
187
|
+
* (`"weekday:long, month:short, day:numeric"`). Not a token language —
|
|
188
|
+
* there is no `YYYY-MM-DD`.
|
|
189
|
+
* - listing — `list(x[, conjunction])` ("A, B and C"), `join(x[, separator])`,
|
|
190
|
+
* `count(x)`, `plural(n, one, other)`. `x` is an untagged multi-select
|
|
191
|
+
* variable (the JSON `string[]` `CheckboxGroup` writes); member LABELS are
|
|
192
|
+
* used when present, matching interpolation's label-first precedence. A
|
|
193
|
+
* scalar answer counts as one member, also by its label. Two things are not
|
|
194
|
+
* lists and fail the call rather than counting as one: a variable holding a
|
|
195
|
+
* number (`count({{age}})` — `plural({{age}}, ...)` is what you wanted),
|
|
196
|
+
* and a value that parses as JSON and is NOT a `string[]` (`"[1,2,3]"`,
|
|
197
|
+
* `{"a":1}`).
|
|
198
|
+
*
|
|
199
|
+
* **This runs at press time only.** Actions have no mount/appear hook and
|
|
200
|
+
* `Text mode: "expression"` interpolates rather than evaluating, so a
|
|
201
|
+
* headline needing a computed value must have it written to a variable by an
|
|
202
|
+
* earlier press (typically the previous screen's Continue) and then simply
|
|
203
|
+
* interpolated.
|
|
204
|
+
*
|
|
205
|
+
* A quoted literal's CONTENTS interpolate, so `{{var}}` means the same thing
|
|
206
|
+
* everywhere in the template: `list({{goals}}) + " for {{name}}"` reads
|
|
207
|
+
* "… for Ada" rather than emitting the braces to the user.
|
|
208
|
+
*
|
|
209
|
+
* A template with no function call falls back to plain interpolation on parse
|
|
210
|
+
* failure (so `"Hello {{name}}"` still works). A template that *attempts* a
|
|
211
|
+
* call and fails stores the empty string and warns, rather than writing the
|
|
212
|
+
* unevaluated source text into a variable a headline would display verbatim.
|
|
213
|
+
*
|
|
214
|
+
* An **absent** variable reads as numeric 0 wherever it is data — which is
|
|
215
|
+
* what makes increment-before-seed arithmetic and `count()` on a skipped
|
|
216
|
+
* screen work — but is refused wherever it is configuration: a `clamp` bound
|
|
217
|
+
* or a `round` digit count, where a typo'd variable name would otherwise
|
|
218
|
+
* produce a plausible constant (`clamp({{score}}, {{floor}}, {{ceiling}})`
|
|
219
|
+
* reported 0 for a score of 42). The taint follows the value, so it also
|
|
220
|
+
* refuses one that reached a bound through arithmetic or a function
|
|
221
|
+
* (`addDays({{d}}, {{weeks}} * 7)`), but is dropped where the result could
|
|
222
|
+
* have come from an untainted argument: `max({{trialDays}}, 7)` is an
|
|
223
|
+
* explicit default and is honoured, as is `max({{seeded_zero}}, {{absent}})`.
|
|
224
|
+
* A `{{ref}}` inside a quoted LITERAL is guarded the same way when it is
|
|
225
|
+
* configuration: `list`'s conjunction, `join`'s separator, `format`'s spec
|
|
226
|
+
* and its LOCALE, and BOTH `plural` forms. `join({{goals}}, "{{sep}}")` with
|
|
227
|
+
* `sep` unset used to run the members together, and `"en{{sfx}}"` as a locale
|
|
228
|
+
* resolved to the valid `"en"` and silently swapped a date's day and month.
|
|
229
|
+
* `plural` checks its count and both forms — both forms because an absent
|
|
230
|
+
* reference in a form is an authoring error whichever one the count selects,
|
|
231
|
+
* and the count because otherwise an unseeded one picks a form silently and
|
|
232
|
+
* `plural` launders it onward.
|
|
233
|
+
*
|
|
234
|
+
* Two known limits, both deliberate. **`count()` does not taint** — a real
|
|
235
|
+
* zero is what `count({{skipped}})` should give on a screen the user never
|
|
236
|
+
* filled in, and the shipped `plural(count({{goals}}), …)` pattern depends
|
|
237
|
+
* on it — so wrapping a name in `count()` defeats the guard, and
|
|
238
|
+
* `round({{pct}}, count({{digits}}))` answers rather than failing.
|
|
239
|
+
* And **`asDate` accepts any `Date.parse`-able string**,
|
|
240
|
+
* including a bare integer, which no taint can reach because the numbers
|
|
241
|
+
* involved are seeded.
|
|
242
|
+
* "Attempts a call" means a **stdlib name** sits in front of a `(` whose
|
|
243
|
+
* contents could actually be arguments. A bare word BETWEEN the parens makes
|
|
244
|
+
* them punctuation instead, and an unglued `(` after an UNKNOWN identifier
|
|
245
|
+
* is not a call, so the English optional-plural idiom survives:
|
|
246
|
+
* `"{{n}} day(s)"` reads "3 day(s)", `"{{n}} min(s) left"` reads
|
|
247
|
+
* "3 min(s) left", `"Goals ({{n}})"` reads "Goals (2)". A STDLIB name is
|
|
248
|
+
* called glued or not — `"max (2) options"` blanks — so prose starting with
|
|
249
|
+
* one needs `valueMode: "literal"`. A stdlib name DOES outrank bare words outside its own parens,
|
|
250
|
+
* so `list({{goals}}) and more` fails loudly — **there is no implicit
|
|
251
|
+
* concatenation**, and prose beside a call must be joined with `+ "…"`. That
|
|
252
|
+
* is the one rule an author has to know to avoid a blank headline.
|
|
253
|
+
*
|
|
254
|
+
* Two residues, both warned about at runtime: an unknown name glued to a `(`
|
|
255
|
+
* with no bare word anywhere is taken as a misspelled call, so `"Save(50)"`
|
|
256
|
+
* and `"Total({{n}})"` blank (write them with a space); and a template that
|
|
257
|
+
* is nothing but a stdlib call with a bare-word argument — `count(goals)`,
|
|
258
|
+
* the braces forgotten — keeps its text but warns, because it cannot be told
|
|
259
|
+
* apart from `min(s)`.
|
|
260
|
+
*
|
|
77
261
|
* Defaults to `"literal"` — `value` stored verbatim.
|
|
78
262
|
*/
|
|
79
263
|
valueMode?: "literal" | "expression";
|
|
@@ -148,6 +332,97 @@ export const PresentPaywallButtonActionSchema = z.object({
|
|
|
148
332
|
placement: z.string().min(1, "placement must not be empty"),
|
|
149
333
|
});
|
|
150
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
|
+
|
|
151
426
|
export type ButtonAction =
|
|
152
427
|
| "continue"
|
|
153
428
|
| CustomButtonAction
|
|
@@ -155,7 +430,8 @@ export type ButtonAction =
|
|
|
155
430
|
| PurchaseButtonAction
|
|
156
431
|
| RestoreButtonAction
|
|
157
432
|
| DismissButtonAction
|
|
158
|
-
| PresentPaywallButtonAction
|
|
433
|
+
| PresentPaywallButtonAction
|
|
434
|
+
| RequestPermissionButtonAction;
|
|
159
435
|
|
|
160
436
|
export const PurchaseButtonActionSchema: z.ZodType<PurchaseButtonAction> = z.lazy(() =>
|
|
161
437
|
z.object({
|
|
@@ -177,6 +453,17 @@ export const RestoreButtonActionSchema: z.ZodType<RestoreButtonAction> = z.lazy(
|
|
|
177
453
|
})
|
|
178
454
|
);
|
|
179
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
|
+
|
|
180
467
|
export const ButtonActionSchema: z.ZodType<ButtonAction> = z.lazy(() =>
|
|
181
468
|
z.union([
|
|
182
469
|
z.literal("continue"),
|
|
@@ -186,6 +473,7 @@ export const ButtonActionSchema: z.ZodType<ButtonAction> = z.lazy(() =>
|
|
|
186
473
|
RestoreButtonActionSchema,
|
|
187
474
|
DismissButtonActionSchema,
|
|
188
475
|
PresentPaywallButtonActionSchema,
|
|
476
|
+
RequestPermissionButtonActionSchema,
|
|
189
477
|
])
|
|
190
478
|
);
|
|
191
479
|
|