@rocapine/react-native-onboarding 1.61.0 → 1.62.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/OnboardingStudioClient.d.ts +23 -5
- package/dist/OnboardingStudioClient.d.ts.map +1 -1
- package/dist/OnboardingStudioClient.js +82 -6
- package/dist/OnboardingStudioClient.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/provider/OnboardingProvider.d.ts +25 -0
- package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
- package/dist/infra/provider/OnboardingProvider.js +63 -3
- package/dist/infra/provider/OnboardingProvider.js.map +1 -1
- package/dist/infra/queries/cacheKey.d.ts +22 -4
- package/dist/infra/queries/cacheKey.d.ts.map +1 -1
- package/dist/infra/queries/cacheKey.js +26 -5
- package/dist/infra/queries/cacheKey.js.map +1 -1
- package/dist/paywalls/PaywallProvider.d.ts +66 -0
- package/dist/paywalls/PaywallProvider.d.ts.map +1 -0
- package/dist/paywalls/PaywallProvider.js +227 -0
- package/dist/paywalls/PaywallProvider.js.map +1 -0
- package/dist/paywalls/getPaywalls.query.d.ts +37 -0
- package/dist/paywalls/getPaywalls.query.d.ts.map +1 -0
- package/dist/paywalls/getPaywalls.query.js +114 -0
- package/dist/paywalls/getPaywalls.query.js.map +1 -0
- package/dist/paywalls/present.d.ts +100 -0
- package/dist/paywalls/present.d.ts.map +1 -0
- package/dist/paywalls/present.js +113 -0
- package/dist/paywalls/present.js.map +1 -0
- package/dist/paywalls/types.d.ts +95 -0
- package/dist/paywalls/types.d.ts.map +1 -0
- package/dist/paywalls/types.js +10 -0
- package/dist/paywalls/types.js.map +1 -0
- package/dist/paywalls/usePaywall.d.ts +29 -0
- package/dist/paywalls/usePaywall.d.ts.map +1 -0
- package/dist/paywalls/usePaywall.js +17 -0
- package/dist/paywalls/usePaywall.js.map +1 -0
- package/dist/products/ProductRuntimeContext.d.ts +15 -0
- package/dist/products/ProductRuntimeContext.d.ts.map +1 -0
- package/dist/products/ProductRuntimeContext.js +19 -0
- package/dist/products/ProductRuntimeContext.js.map +1 -0
- package/dist/products/index.d.ts +1 -0
- package/dist/products/index.d.ts.map +1 -1
- package/dist/products/index.js +4 -1
- package/dist/products/index.js.map +1 -1
- package/dist/products/mergeProductRuntimes.d.ts +55 -0
- package/dist/products/mergeProductRuntimes.d.ts.map +1 -0
- package/dist/products/mergeProductRuntimes.js +79 -0
- package/dist/products/mergeProductRuntimes.js.map +1 -0
- package/dist/steps/common.types.d.ts +22 -1
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +10 -1
- package/dist/steps/common.types.js.map +1 -1
- package/package.json +1 -1
- package/src/OnboardingStudioClient.ts +110 -7
- package/src/__tests__/mergeProductRuntimes.test.ts +172 -0
- package/src/__tests__/resolveLocalProductArgs.test.ts +41 -0
- package/src/index.ts +12 -0
- package/src/infra/provider/OnboardingProvider.tsx +73 -3
- package/src/infra/queries/cacheKey.ts +27 -4
- package/src/paywalls/PaywallProvider.tsx +342 -0
- package/src/paywalls/__tests__/getPaywalls.test.ts +334 -0
- package/src/paywalls/__tests__/present.test.ts +190 -0
- package/src/paywalls/getPaywalls.query.ts +123 -0
- package/src/paywalls/present.ts +141 -0
- package/src/paywalls/types.ts +99 -0
- package/src/paywalls/usePaywall.ts +35 -0
- package/src/products/ProductRuntimeContext.tsx +17 -0
- package/src/products/index.ts +1 -0
- package/src/products/mergeProductRuntimes.ts +78 -0
- package/src/steps/common.types.ts +34 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ProductRuntime, ProductStatus } from "./types";
|
|
2
|
+
|
|
3
|
+
const mergeStatus = (a: ProductStatus, b: ProductStatus): ProductStatus => {
|
|
4
|
+
if (a === "error" || b === "error") return "error";
|
|
5
|
+
if (a === "ready" && b === "ready") return "ready";
|
|
6
|
+
if (a === "loading" || b === "loading") return "loading";
|
|
7
|
+
return "idle";
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Publishes ONE `ProductRuntime` out of the shared context runtime (a
|
|
12
|
+
* `PaywallProvider` ancestor's catalog union) and this `OnboardingProvider`'s
|
|
13
|
+
* own local resolution of its `productRefs` prop.
|
|
14
|
+
*
|
|
15
|
+
* Finding 5, 2026-08-17 final review: `OnboardingProvider` used to zero the
|
|
16
|
+
* local ref set out entirely whenever a context runtime existed, on the
|
|
17
|
+
* assumption that the paywall catalog's product union is always a superset of
|
|
18
|
+
* whatever `productRefs` the host declares — an assumption about a
|
|
19
|
+
* host-supplied prop, not a property of the code. That silently broke a
|
|
20
|
+
* documented Phase 3 prop the moment a host added a `PaywallProvider` above
|
|
21
|
+
* an existing `OnboardingProvider`: `productRefs` keys absent from the
|
|
22
|
+
* catalog union resolved to nothing, with no error and nothing that
|
|
23
|
+
* type-checks. `productRefs` is therefore ALWAYS resolved locally now,
|
|
24
|
+
* regardless of whether a context runtime exists (see
|
|
25
|
+
* `resolveLocalProductArgs`) — this function unions the result back into the
|
|
26
|
+
* one `ProductRuntime` the rest of the app reads.
|
|
27
|
+
*
|
|
28
|
+
* **Callers MUST memoize this** (`OnboardingProvider.tsx` wraps it in
|
|
29
|
+
* `useMemo`, keyed on the four arguments) — round 2 of the final review (N1)
|
|
30
|
+
* found the object literal below allocated fresh, plus a fresh `purchase`
|
|
31
|
+
* closure, on every call, which breaks `ScreenHost.products`'s "referentially
|
|
32
|
+
* stable across variable writes" contract when called inline in a render
|
|
33
|
+
* body.
|
|
34
|
+
*
|
|
35
|
+
* Returns `contextRuntime` UNCHANGED when there is nothing local to add
|
|
36
|
+
* (`hasLocalRefs` false — the common case: no host-declared `productRefs`),
|
|
37
|
+
* so the well-established "one shared runtime, no local round trip" identity
|
|
38
|
+
* and behavior is untouched for every app that doesn't use this prop.
|
|
39
|
+
*
|
|
40
|
+
* `purchase` routes by key: a key resolved by the LOCAL runtime purchases
|
|
41
|
+
* through the local provider (it is the only one that resolved it); anything
|
|
42
|
+
* else — including an unknown key — goes through the context runtime, which
|
|
43
|
+
* already reports "No resolved product for key" for that case (`useProducts.
|
|
44
|
+
* purchase`), so no separate handling is needed here. `restore` delegates to
|
|
45
|
+
* the context runtime only: restoring is a whole store-account operation, not
|
|
46
|
+
* scoped to individual refs, so one call through the shared adapter is
|
|
47
|
+
* correct even with a local ref set also present — the same billing adapter
|
|
48
|
+
* type is the expected real-world setup for both `productProvider` props.
|
|
49
|
+
*
|
|
50
|
+
* `hasLocalProvider` (N3, round 2): a host can declare `productRefs` with NO
|
|
51
|
+
* local `productProvider` — nothing unusual, since the shared context runtime
|
|
52
|
+
* is normally expected to cover everything. `useProducts` then never leaves
|
|
53
|
+
* `"idle"` for the local runtime (it bails before ever calling a provider it
|
|
54
|
+
* doesn't have — `useProducts.ts`), and a naive `mergeStatus` would drag the
|
|
55
|
+
* context runtime's `"ready"` down to `"idle"` FOREVER, closing every
|
|
56
|
+
* `renderWhen: {"products.loaded": {eq:"true"}}` gate for good — the same
|
|
57
|
+
* "idle blocks readiness when there's nothing to actually wait for" trap
|
|
58
|
+
* `computeIsReady` (`present.ts`) already special-cases for an empty ref set.
|
|
59
|
+
* When there is no local provider, the local runtime has nothing pending, so
|
|
60
|
+
* the merged status is just the context runtime's.
|
|
61
|
+
*/
|
|
62
|
+
export const mergeProductRuntimes = (
|
|
63
|
+
contextRuntime: ProductRuntime,
|
|
64
|
+
localRuntime: ProductRuntime,
|
|
65
|
+
hasLocalRefs: boolean,
|
|
66
|
+
hasLocalProvider: boolean
|
|
67
|
+
): ProductRuntime => {
|
|
68
|
+
if (!hasLocalRefs) return contextRuntime;
|
|
69
|
+
return {
|
|
70
|
+
products: { ...contextRuntime.products, ...localRuntime.products },
|
|
71
|
+
status: hasLocalProvider ? mergeStatus(contextRuntime.status, localRuntime.status) : contextRuntime.status,
|
|
72
|
+
error: contextRuntime.error ?? localRuntime.error,
|
|
73
|
+
purchasing: contextRuntime.purchasing || localRuntime.purchasing,
|
|
74
|
+
purchase: (key: string) =>
|
|
75
|
+
key in localRuntime.products ? localRuntime.purchase(key) : contextRuntime.purchase(key),
|
|
76
|
+
restore: contextRuntime.restore,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -48,6 +48,10 @@ export type HapticStyle = z.infer<typeof HapticStyleSchema>;
|
|
|
48
48
|
// (BaseBoxProps). An action is `"continue"` (terminal — advances the onboarding),
|
|
49
49
|
// `{type:"custom"}` (invokes a host-registered customAction), or
|
|
50
50
|
// `{type:"setVariable"}` (writes an onboarding variable). Run sequentially.
|
|
51
|
+
// Also: `{type:"purchase"}` / `{type:"restore"}` (billing), `{type:"dismiss"}`
|
|
52
|
+
// (terminal — finishes the screen with a `{status:"dismissed"}` outcome), and
|
|
53
|
+
// `{type:"presentPaywall"}` (asks the host to present a paywall by placement —
|
|
54
|
+
// works from an onboarding step or a paywall alike).
|
|
51
55
|
|
|
52
56
|
export type CustomButtonAction = {
|
|
53
57
|
type: "custom";
|
|
@@ -117,12 +121,39 @@ export type RestoreButtonAction = {
|
|
|
117
121
|
onError?: ButtonAction[];
|
|
118
122
|
};
|
|
119
123
|
|
|
124
|
+
/** Terminal — finishes the screen with a `{ status: "dismissed" }` outcome. */
|
|
125
|
+
export type DismissButtonAction = {
|
|
126
|
+
type: "dismiss";
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const DismissButtonActionSchema = z.object({
|
|
130
|
+
type: z.literal("dismiss"),
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Asks the host to present a paywall by placement. Available from an
|
|
135
|
+
* onboarding step or a paywall alike — that is how an onboarding step opens a
|
|
136
|
+
* paywall mid-flow. No-ops (with a warning) on a host that doesn't support it.
|
|
137
|
+
*/
|
|
138
|
+
export type PresentPaywallButtonAction = {
|
|
139
|
+
type: "presentPaywall";
|
|
140
|
+
/** Paywall placement key to present, e.g. "hard_paywall". */
|
|
141
|
+
placement: string;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const PresentPaywallButtonActionSchema = z.object({
|
|
145
|
+
type: z.literal("presentPaywall"),
|
|
146
|
+
placement: z.string().min(1, "placement must not be empty"),
|
|
147
|
+
});
|
|
148
|
+
|
|
120
149
|
export type ButtonAction =
|
|
121
150
|
| "continue"
|
|
122
151
|
| CustomButtonAction
|
|
123
152
|
| SetVariableButtonAction
|
|
124
153
|
| PurchaseButtonAction
|
|
125
|
-
| RestoreButtonAction
|
|
154
|
+
| RestoreButtonAction
|
|
155
|
+
| DismissButtonAction
|
|
156
|
+
| PresentPaywallButtonAction;
|
|
126
157
|
|
|
127
158
|
export const PurchaseButtonActionSchema: z.ZodType<PurchaseButtonAction> = z.lazy(() =>
|
|
128
159
|
z.object({
|
|
@@ -150,6 +181,8 @@ export const ButtonActionSchema: z.ZodType<ButtonAction> = z.lazy(() =>
|
|
|
150
181
|
SetVariableButtonActionSchema,
|
|
151
182
|
PurchaseButtonActionSchema,
|
|
152
183
|
RestoreButtonActionSchema,
|
|
184
|
+
DismissButtonActionSchema,
|
|
185
|
+
PresentPaywallButtonActionSchema,
|
|
153
186
|
])
|
|
154
187
|
);
|
|
155
188
|
|