@rocapine/react-native-onboarding 1.60.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 +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/provider/OnboardingProvider.d.ts +37 -1
- package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
- package/dist/infra/provider/OnboardingProvider.js +76 -2
- 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/adapters/expoIap.d.ts +4 -0
- package/dist/products/adapters/expoIap.d.ts.map +1 -0
- package/dist/products/adapters/expoIap.js +95 -0
- package/dist/products/adapters/expoIap.js.map +1 -0
- package/dist/products/adapters/revenueCat.d.ts +7 -0
- package/dist/products/adapters/revenueCat.d.ts.map +1 -0
- package/dist/products/adapters/revenueCat.js +116 -0
- package/dist/products/adapters/revenueCat.js.map +1 -0
- package/dist/products/adapters/stub.d.ts +8 -0
- package/dist/products/adapters/stub.d.ts.map +1 -0
- package/dist/products/adapters/stub.js +21 -0
- package/dist/products/adapters/stub.js.map +1 -0
- package/dist/products/derive.d.ts +19 -0
- package/dist/products/derive.d.ts.map +1 -0
- package/dist/products/derive.js +79 -0
- package/dist/products/derive.js.map +1 -0
- package/dist/products/duration.d.ts +3 -0
- package/dist/products/duration.d.ts.map +1 -0
- package/dist/products/duration.js +25 -0
- package/dist/products/duration.js.map +1 -0
- package/dist/products/index.d.ts +10 -0
- package/dist/products/index.d.ts.map +1 -0
- package/dist/products/index.js +23 -0
- package/dist/products/index.js.map +1 -0
- 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/products/toVariables.d.ts +18 -0
- package/dist/products/toVariables.d.ts.map +1 -0
- package/dist/products/toVariables.js +52 -0
- package/dist/products/toVariables.js.map +1 -0
- package/dist/products/types.d.ts +96 -0
- package/dist/products/types.d.ts.map +1 -0
- package/dist/products/types.js +3 -0
- package/dist/products/types.js.map +1 -0
- package/dist/products/useProducts.d.ts +12 -0
- package/dist/products/useProducts.d.ts.map +1 -0
- package/dist/products/useProducts.js +90 -0
- package/dist/products/useProducts.js.map +1 -0
- package/dist/screens/elements/AnimatedTextElement.d.ts +1 -24
- package/dist/screens/elements/AnimatedTextElement.d.ts.map +1 -1
- package/dist/screens/elements/BaseBoxProps.d.ts +1 -24
- package/dist/screens/elements/BaseBoxProps.d.ts.map +1 -1
- package/dist/screens/elements/ButtonElement.d.ts +6 -121
- package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
- package/dist/screens/elements/CarouselElement.d.ts +1 -24
- package/dist/screens/elements/CarouselElement.d.ts.map +1 -1
- package/dist/screens/elements/CheckboxGroupElement.d.ts +1 -24
- package/dist/screens/elements/CheckboxGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/DatePickerElement.d.ts +1 -24
- package/dist/screens/elements/DatePickerElement.d.ts.map +1 -1
- package/dist/screens/elements/DrawingPadElement.d.ts +1 -24
- package/dist/screens/elements/DrawingPadElement.d.ts.map +1 -1
- package/dist/screens/elements/IconElement.d.ts +1 -24
- package/dist/screens/elements/IconElement.d.ts.map +1 -1
- package/dist/screens/elements/ImageElement.d.ts +1 -24
- package/dist/screens/elements/ImageElement.d.ts.map +1 -1
- package/dist/screens/elements/InputElement.d.ts +1 -24
- package/dist/screens/elements/InputElement.d.ts.map +1 -1
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts +1 -24
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts.map +1 -1
- package/dist/screens/elements/LottieElement.d.ts +1 -24
- package/dist/screens/elements/LottieElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressIndicatorElement.d.ts +1 -24
- package/dist/screens/elements/ProgressIndicatorElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts +1 -24
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts.map +1 -1
- package/dist/screens/elements/RadioGroupElement.d.ts +1 -24
- package/dist/screens/elements/RadioGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/RichTextElement.d.ts +1 -24
- package/dist/screens/elements/RichTextElement.d.ts.map +1 -1
- package/dist/screens/elements/RiveElement.d.ts +1 -24
- package/dist/screens/elements/RiveElement.d.ts.map +1 -1
- package/dist/screens/elements/SafeAreaViewElement.d.ts +1 -24
- package/dist/screens/elements/SafeAreaViewElement.d.ts.map +1 -1
- package/dist/screens/elements/ScrollViewElement.d.ts +1 -24
- package/dist/screens/elements/ScrollViewElement.d.ts.map +1 -1
- package/dist/screens/elements/SliderElement.d.ts +1 -24
- package/dist/screens/elements/SliderElement.d.ts.map +1 -1
- package/dist/screens/elements/StackElement.d.ts +1 -24
- package/dist/screens/elements/StackElement.d.ts.map +1 -1
- package/dist/screens/elements/TextElement.d.ts +1 -24
- package/dist/screens/elements/TextElement.d.ts.map +1 -1
- package/dist/screens/elements/TypewriterTextElement.d.ts +1 -24
- package/dist/screens/elements/TypewriterTextElement.d.ts.map +1 -1
- package/dist/screens/elements/VideoElement.d.ts +1 -24
- package/dist/screens/elements/VideoElement.d.ts.map +1 -1
- package/dist/screens/elements/WheelPickerElement.d.ts +1 -24
- package/dist/screens/elements/WheelPickerElement.d.ts.map +1 -1
- package/dist/screens/elements/ZStackElement.d.ts +1 -24
- package/dist/screens/elements/ZStackElement.d.ts.map +1 -1
- package/dist/steps/Carousel/types.d.ts +1 -1
- package/dist/steps/Commitment/types.d.ts +1 -1
- package/dist/steps/ComposableScreen/types.d.ts +1 -1
- package/dist/steps/Loader/types.d.ts +1 -1
- package/dist/steps/MediaContent/types.d.ts +1 -1
- package/dist/steps/Picker/types.d.ts +1 -1
- package/dist/steps/Question/types.d.ts +1 -1
- package/dist/steps/Ratings/types.d.ts +1 -1
- package/dist/steps/common.types.d.ts +44 -30
- package/dist/steps/common.types.d.ts.map +1 -1
- package/dist/steps/common.types.js +27 -3
- 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__/productAdapters.test.ts +58 -0
- package/src/__tests__/productDerive.test.ts +111 -0
- package/src/__tests__/productVariables.test.ts +109 -0
- package/src/__tests__/resolveLocalProductArgs.test.ts +41 -0
- package/src/index.ts +14 -0
- package/src/infra/provider/OnboardingProvider.tsx +101 -2
- 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/adapters/expoIap.ts +93 -0
- package/src/products/adapters/revenueCat.ts +108 -0
- package/src/products/adapters/stub.ts +20 -0
- package/src/products/derive.ts +93 -0
- package/src/products/duration.ts +21 -0
- package/src/products/index.ts +20 -0
- package/src/products/mergeProductRuntimes.ts +78 -0
- package/src/products/toVariables.ts +54 -0
- package/src/products/types.ts +88 -0
- package/src/products/useProducts.ts +106 -0
- package/src/steps/common.types.ts +83 -6
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { deriveAll } from "./derive";
|
|
3
|
+
import type {
|
|
4
|
+
ProductProvider,
|
|
5
|
+
ProductRef,
|
|
6
|
+
ProductRuntime,
|
|
7
|
+
ProductStatus,
|
|
8
|
+
ProductWithDerived,
|
|
9
|
+
PurchaseResult,
|
|
10
|
+
RestoreResult,
|
|
11
|
+
} from "./types";
|
|
12
|
+
|
|
13
|
+
const EMPTY_PRODUCTS: Record<string, ProductWithDerived> = {};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolves `refs` through `provider` once per (refs, provider) pair and exposes
|
|
17
|
+
* a referentially stable ProductRuntime.
|
|
18
|
+
*
|
|
19
|
+
* Stability matters: this object lands in RenderContext's dependency array, so
|
|
20
|
+
* an identity change on every render would re-render every memoized element on
|
|
21
|
+
* every variable write — undoing the Phase 1 memoization work. It is memoized on
|
|
22
|
+
* its actual contents, and purchase/restore are useCallback-stable.
|
|
23
|
+
*/
|
|
24
|
+
export const useProducts = (
|
|
25
|
+
refs: ProductRef[] | undefined,
|
|
26
|
+
provider: ProductProvider | undefined,
|
|
27
|
+
locale?: string
|
|
28
|
+
): ProductRuntime => {
|
|
29
|
+
const [products, setProducts] = useState<Record<string, ProductWithDerived>>(EMPTY_PRODUCTS);
|
|
30
|
+
const [status, setStatus] = useState<ProductStatus>("idle");
|
|
31
|
+
const [error, setError] = useState<string | undefined>(undefined);
|
|
32
|
+
const [purchasing, setPurchasing] = useState(false);
|
|
33
|
+
|
|
34
|
+
// Refs so the callbacks below never need to be re-created.
|
|
35
|
+
const productsRef = useRef(products);
|
|
36
|
+
productsRef.current = products;
|
|
37
|
+
const providerRef = useRef(provider);
|
|
38
|
+
providerRef.current = provider;
|
|
39
|
+
|
|
40
|
+
// Key the effect on the refs' identity CONTENT, not the array identity — a
|
|
41
|
+
// host passing an inline array literal would otherwise refetch every render.
|
|
42
|
+
const refsKey = useMemo(
|
|
43
|
+
() => (refs ?? []).map((r) => `${r.key}|${r.ios ?? ""}|${r.android ?? ""}|${r.compareTo ?? ""}`).join(","),
|
|
44
|
+
[refs]
|
|
45
|
+
);
|
|
46
|
+
const refsRef = useRef(refs);
|
|
47
|
+
refsRef.current = refs;
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const current = refsRef.current;
|
|
51
|
+
const prov = providerRef.current;
|
|
52
|
+
if (!prov || !current || current.length === 0) {
|
|
53
|
+
setStatus("idle");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let cancelled = false;
|
|
57
|
+
setStatus("loading");
|
|
58
|
+
setError(undefined);
|
|
59
|
+
prov
|
|
60
|
+
.getProducts(current)
|
|
61
|
+
.then((resolved) => {
|
|
62
|
+
if (cancelled) return;
|
|
63
|
+
setProducts(deriveAll(resolved, current, locale));
|
|
64
|
+
setStatus("ready");
|
|
65
|
+
})
|
|
66
|
+
.catch((e: unknown) => {
|
|
67
|
+
if (cancelled) return;
|
|
68
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
69
|
+
setStatus("error");
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
cancelled = true;
|
|
73
|
+
};
|
|
74
|
+
}, [refsKey, locale]);
|
|
75
|
+
|
|
76
|
+
const purchase = useCallback(async (key: string): Promise<PurchaseResult> => {
|
|
77
|
+
const prov = providerRef.current;
|
|
78
|
+
const product = productsRef.current[key];
|
|
79
|
+
if (!prov || !product) {
|
|
80
|
+
return { status: "error", error: new Error(`No resolved product for key "${key}"`) };
|
|
81
|
+
}
|
|
82
|
+
setPurchasing(true);
|
|
83
|
+
try {
|
|
84
|
+
return await prov.purchase(product);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return { status: "error", error: e instanceof Error ? e : new Error(String(e)) };
|
|
87
|
+
} finally {
|
|
88
|
+
setPurchasing(false);
|
|
89
|
+
}
|
|
90
|
+
}, []);
|
|
91
|
+
|
|
92
|
+
const restore = useCallback(async (): Promise<RestoreResult> => {
|
|
93
|
+
const prov = providerRef.current;
|
|
94
|
+
if (!prov) return { status: "error", error: new Error("No ProductProvider") };
|
|
95
|
+
try {
|
|
96
|
+
return await prov.restore();
|
|
97
|
+
} catch (e) {
|
|
98
|
+
return { status: "error", error: e instanceof Error ? e : new Error(String(e)) };
|
|
99
|
+
}
|
|
100
|
+
}, []);
|
|
101
|
+
|
|
102
|
+
return useMemo(
|
|
103
|
+
() => ({ products, status, error, purchasing, purchase, restore }),
|
|
104
|
+
[products, status, error, purchasing, purchase, restore]
|
|
105
|
+
);
|
|
106
|
+
};
|
|
@@ -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";
|
|
@@ -101,13 +105,86 @@ export const SetVariableButtonActionSchema = z.object({
|
|
|
101
105
|
arrayOp: z.enum(["append", "remove", "toggle"]).optional(),
|
|
102
106
|
});
|
|
103
107
|
|
|
104
|
-
export type
|
|
108
|
+
export type PurchaseButtonAction = {
|
|
109
|
+
type: "purchase";
|
|
110
|
+
/** A product slot key, or an interpolable ref like "{{plan}}". */
|
|
111
|
+
product: string;
|
|
112
|
+
onSuccess?: ButtonAction[];
|
|
113
|
+
onCancel?: ButtonAction[];
|
|
114
|
+
onError?: ButtonAction[];
|
|
115
|
+
};
|
|
105
116
|
|
|
106
|
-
export
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
]
|
|
117
|
+
export type RestoreButtonAction = {
|
|
118
|
+
type: "restore";
|
|
119
|
+
onSuccess?: ButtonAction[];
|
|
120
|
+
onNothingToRestore?: ButtonAction[];
|
|
121
|
+
onError?: ButtonAction[];
|
|
122
|
+
};
|
|
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
|
+
|
|
149
|
+
export type ButtonAction =
|
|
150
|
+
| "continue"
|
|
151
|
+
| CustomButtonAction
|
|
152
|
+
| SetVariableButtonAction
|
|
153
|
+
| PurchaseButtonAction
|
|
154
|
+
| RestoreButtonAction
|
|
155
|
+
| DismissButtonAction
|
|
156
|
+
| PresentPaywallButtonAction;
|
|
157
|
+
|
|
158
|
+
export const PurchaseButtonActionSchema: z.ZodType<PurchaseButtonAction> = z.lazy(() =>
|
|
159
|
+
z.object({
|
|
160
|
+
type: z.literal("purchase"),
|
|
161
|
+
product: z.string().min(1, "product must not be empty"),
|
|
162
|
+
onSuccess: z.array(ButtonActionSchema).optional(),
|
|
163
|
+
onCancel: z.array(ButtonActionSchema).optional(),
|
|
164
|
+
onError: z.array(ButtonActionSchema).optional(),
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
export const RestoreButtonActionSchema: z.ZodType<RestoreButtonAction> = z.lazy(() =>
|
|
169
|
+
z.object({
|
|
170
|
+
type: z.literal("restore"),
|
|
171
|
+
onSuccess: z.array(ButtonActionSchema).optional(),
|
|
172
|
+
onNothingToRestore: z.array(ButtonActionSchema).optional(),
|
|
173
|
+
onError: z.array(ButtonActionSchema).optional(),
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
export const ButtonActionSchema: z.ZodType<ButtonAction> = z.lazy(() =>
|
|
178
|
+
z.union([
|
|
179
|
+
z.literal("continue"),
|
|
180
|
+
CustomButtonActionSchema,
|
|
181
|
+
SetVariableButtonActionSchema,
|
|
182
|
+
PurchaseButtonActionSchema,
|
|
183
|
+
RestoreButtonActionSchema,
|
|
184
|
+
DismissButtonActionSchema,
|
|
185
|
+
PresentPaywallButtonActionSchema,
|
|
186
|
+
])
|
|
187
|
+
);
|
|
111
188
|
|
|
112
189
|
// ── Branching / nextStep schemas ─────────────────────────────────────────────
|
|
113
190
|
|