@rocapine/react-native-onboarding 1.61.0 → 1.63.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 +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/hooks/index.d.ts +1 -0
- package/dist/infra/hooks/index.d.ts.map +1 -1
- package/dist/infra/hooks/index.js +3 -1
- package/dist/infra/hooks/index.js.map +1 -1
- package/dist/infra/hooks/useProgressHeaderConfig.d.ts +14 -0
- package/dist/infra/hooks/useProgressHeaderConfig.d.ts.map +1 -0
- package/dist/infra/hooks/useProgressHeaderConfig.js +24 -0
- package/dist/infra/hooks/useProgressHeaderConfig.js.map +1 -0
- package/dist/infra/preload/extractAssetUrls.d.ts.map +1 -1
- package/dist/infra/preload/extractAssetUrls.js +67 -0
- package/dist/infra/preload/extractAssetUrls.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 +74 -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/onboarding-example.d.ts +1063 -60
- package/dist/onboarding-example.d.ts.map +1 -1
- package/dist/onboarding-example.js +140 -0
- package/dist/onboarding-example.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/screens/elements/AnimatedTextElement.d.ts +7 -0
- package/dist/screens/elements/AnimatedTextElement.d.ts.map +1 -1
- package/dist/screens/elements/BaseBoxProps.d.ts +39 -0
- package/dist/screens/elements/BaseBoxProps.d.ts.map +1 -1
- package/dist/screens/elements/BaseBoxProps.js +9 -0
- package/dist/screens/elements/BaseBoxProps.js.map +1 -1
- package/dist/screens/elements/ButtonElement.d.ts +28 -0
- package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
- package/dist/screens/elements/CarouselElement.d.ts +38 -0
- package/dist/screens/elements/CarouselElement.d.ts.map +1 -1
- package/dist/screens/elements/CarouselElement.js +1 -0
- package/dist/screens/elements/CarouselElement.js.map +1 -1
- package/dist/screens/elements/CheckboxGroupElement.d.ts +7 -0
- package/dist/screens/elements/CheckboxGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/DatePickerElement.d.ts +7 -0
- package/dist/screens/elements/DatePickerElement.d.ts.map +1 -1
- package/dist/screens/elements/DrawingPadElement.d.ts +7 -0
- package/dist/screens/elements/DrawingPadElement.d.ts.map +1 -1
- package/dist/screens/elements/IconElement.d.ts +7 -0
- package/dist/screens/elements/IconElement.d.ts.map +1 -1
- package/dist/screens/elements/ImageElement.d.ts +26 -0
- package/dist/screens/elements/ImageElement.d.ts.map +1 -1
- package/dist/screens/elements/ImageElement.js +1 -0
- package/dist/screens/elements/ImageElement.js.map +1 -1
- package/dist/screens/elements/InputElement.d.ts +7 -0
- package/dist/screens/elements/InputElement.d.ts.map +1 -1
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts +7 -0
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts.map +1 -1
- package/dist/screens/elements/LottieElement.d.ts +7 -0
- package/dist/screens/elements/LottieElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressIndicatorElement.d.ts +7 -0
- package/dist/screens/elements/ProgressIndicatorElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts +7 -0
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts.map +1 -1
- package/dist/screens/elements/RadioGroupElement.d.ts +7 -0
- package/dist/screens/elements/RadioGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/RepeatElement.d.ts +79 -0
- package/dist/screens/elements/RepeatElement.d.ts.map +1 -0
- package/dist/screens/elements/RepeatElement.js +10 -0
- package/dist/screens/elements/RepeatElement.js.map +1 -0
- package/dist/screens/elements/RichTextElement.d.ts +7 -0
- package/dist/screens/elements/RichTextElement.d.ts.map +1 -1
- package/dist/screens/elements/RiveElement.d.ts +7 -0
- package/dist/screens/elements/RiveElement.d.ts.map +1 -1
- package/dist/screens/elements/SafeAreaViewElement.d.ts +7 -0
- package/dist/screens/elements/SafeAreaViewElement.d.ts.map +1 -1
- package/dist/screens/elements/ScrollViewElement.d.ts +7 -0
- package/dist/screens/elements/ScrollViewElement.d.ts.map +1 -1
- package/dist/screens/elements/SliderElement.d.ts +7 -0
- package/dist/screens/elements/SliderElement.d.ts.map +1 -1
- package/dist/screens/elements/StackElement.d.ts +7 -0
- package/dist/screens/elements/StackElement.d.ts.map +1 -1
- package/dist/screens/elements/TextElement.d.ts +7 -0
- package/dist/screens/elements/TextElement.d.ts.map +1 -1
- package/dist/screens/elements/TypewriterTextElement.d.ts +26 -0
- package/dist/screens/elements/TypewriterTextElement.d.ts.map +1 -1
- package/dist/screens/elements/TypewriterTextElement.js +1 -0
- package/dist/screens/elements/TypewriterTextElement.js.map +1 -1
- package/dist/screens/elements/VideoElement.d.ts +7 -0
- package/dist/screens/elements/VideoElement.d.ts.map +1 -1
- package/dist/screens/elements/WheelPickerElement.d.ts +7 -0
- package/dist/screens/elements/WheelPickerElement.d.ts.map +1 -1
- package/dist/screens/elements/ZStackElement.d.ts +7 -0
- package/dist/screens/elements/ZStackElement.d.ts.map +1 -1
- package/dist/screens/types.d.ts +9 -0
- package/dist/screens/types.d.ts.map +1 -1
- package/dist/screens/types.js +9 -0
- package/dist/screens/types.js.map +1 -1
- package/dist/screens/unknownKeys.d.ts +67 -0
- package/dist/screens/unknownKeys.d.ts.map +1 -0
- package/dist/screens/unknownKeys.js +160 -0
- package/dist/screens/unknownKeys.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/dist/types.d.ts +73 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/OnboardingStudioClient.ts +110 -7
- package/src/__tests__/extractAssetUrls.test.ts +104 -0
- package/src/__tests__/mergeProductRuntimes.test.ts +172 -0
- package/src/__tests__/resolveLocalProductArgs.test.ts +41 -0
- package/src/__tests__/unknownKeys.test.ts +234 -0
- package/src/index.ts +20 -0
- package/src/infra/hooks/index.ts +1 -0
- package/src/infra/hooks/useProgressHeaderConfig.ts +21 -0
- package/src/infra/preload/extractAssetUrls.ts +72 -0
- package/src/infra/provider/OnboardingProvider.tsx +87 -3
- package/src/infra/queries/cacheKey.ts +27 -4
- package/src/onboarding-example.ts +140 -0
- 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/screens/elements/BaseBoxProps.ts +56 -0
- package/src/screens/elements/CarouselElement.ts +31 -0
- package/src/screens/elements/ImageElement.ts +16 -0
- package/src/screens/elements/RepeatElement.ts +80 -0
- package/src/screens/elements/TypewriterTextElement.ts +19 -0
- package/src/screens/types.ts +18 -0
- package/src/screens/unknownKeys.ts +211 -0
- package/src/steps/common.types.ts +34 -1
- package/src/types.ts +86 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
collectUnknownElementKeys,
|
|
4
|
+
collectUnknownKeysInSteps,
|
|
5
|
+
formatUnknownElementKeys,
|
|
6
|
+
} from "../screens/unknownKeys";
|
|
7
|
+
import { ComposableScreenStepTypeSchema } from "../steps/ComposableScreen/types";
|
|
8
|
+
|
|
9
|
+
describe("collectUnknownElementKeys", () => {
|
|
10
|
+
it("finds a BaseBoxProp written one level too high and says where it belongs", () => {
|
|
11
|
+
// The real-world case: `animation` next to `type`/`props` instead of inside
|
|
12
|
+
// `props`. Parses fine, renders fine, animation never happens.
|
|
13
|
+
const found = collectUnknownElementKeys([
|
|
14
|
+
{
|
|
15
|
+
id: "hero",
|
|
16
|
+
type: "Image",
|
|
17
|
+
props: { url: "https://x/y.png" },
|
|
18
|
+
animation: { entering: { preset: "FadeInDown", duration: 300 } },
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
expect(found).toHaveLength(1);
|
|
23
|
+
expect(found[0]).toMatchObject({
|
|
24
|
+
path: "elements[0]",
|
|
25
|
+
elementId: "hero",
|
|
26
|
+
elementType: "Image",
|
|
27
|
+
key: "animation",
|
|
28
|
+
kind: "misplaced",
|
|
29
|
+
suggestion: "props.animation",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("distinguishes a STALE DUPLICATE from a misplaced prop", () => {
|
|
34
|
+
// The real corpus case: `props.animation` is already present and working
|
|
35
|
+
// (200ms), and a stale top-level copy (300ms) sits alongside it doing
|
|
36
|
+
// nothing. "did you mean props.animation?" would be actively misleading —
|
|
37
|
+
// they didn't forget it, they have two and are probably editing the dead one.
|
|
38
|
+
const found = collectUnknownElementKeys([
|
|
39
|
+
{
|
|
40
|
+
id: "loader-img-1",
|
|
41
|
+
type: "Image",
|
|
42
|
+
props: {
|
|
43
|
+
url: "https://x/y.png",
|
|
44
|
+
animation: { entering: { preset: "FadeIn", duration: 200, easing: "ease-in" } },
|
|
45
|
+
},
|
|
46
|
+
animation: { entering: { preset: "FadeIn", duration: 300, easing: "ease-in-out" } },
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
expect(found).toHaveLength(1);
|
|
51
|
+
expect(found[0]).toMatchObject({
|
|
52
|
+
key: "animation",
|
|
53
|
+
kind: "shadowed",
|
|
54
|
+
suggestion: "props.animation",
|
|
55
|
+
conflicts: true,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("does not cry wolf when the duplicate is identical", () => {
|
|
60
|
+
const anim = { entering: { preset: "FadeIn", duration: 200 } };
|
|
61
|
+
const found = collectUnknownElementKeys([
|
|
62
|
+
{ id: "i", type: "Image", props: { url: "u", animation: anim }, animation: { ...anim } },
|
|
63
|
+
]);
|
|
64
|
+
expect(found[0]).toMatchObject({ kind: "shadowed", conflicts: false });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("treats a key absent from props as misplaced even when props exists", () => {
|
|
68
|
+
const found = collectUnknownElementKeys([
|
|
69
|
+
{ id: "i", type: "Image", props: { url: "u" }, onPress: [] },
|
|
70
|
+
]);
|
|
71
|
+
expect(found[0]).toMatchObject({ kind: "misplaced", suggestion: "props.onPress" });
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("confirms the misplaced key really is dropped by the schema (why this exists)", () => {
|
|
75
|
+
const step = {
|
|
76
|
+
id: "s",
|
|
77
|
+
name: "n",
|
|
78
|
+
type: "ComposableScreen",
|
|
79
|
+
displayProgressHeader: true,
|
|
80
|
+
payload: {
|
|
81
|
+
elements: [
|
|
82
|
+
{
|
|
83
|
+
id: "hero",
|
|
84
|
+
type: "Image",
|
|
85
|
+
props: { url: "https://x/y.png" },
|
|
86
|
+
animation: { entering: { preset: "FadeInDown", duration: 300 } },
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const parsed = ComposableScreenStepTypeSchema.safeParse(step);
|
|
93
|
+
// Parsing SUCCEEDS — that is the whole problem.
|
|
94
|
+
expect(parsed.success).toBe(true);
|
|
95
|
+
expect((parsed as any).data.payload.elements[0].animation).toBeUndefined();
|
|
96
|
+
// ...and the diagnostic is what surfaces it.
|
|
97
|
+
expect(collectUnknownElementKeys(step.payload.elements)).toHaveLength(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("reports a genuinely unknown key with no suggestion", () => {
|
|
101
|
+
const found = collectUnknownElementKeys([
|
|
102
|
+
{ id: "t", type: "Text", props: { content: "hi" }, wobble: 3 },
|
|
103
|
+
]);
|
|
104
|
+
expect(found).toHaveLength(1);
|
|
105
|
+
expect(found[0].key).toBe("wobble");
|
|
106
|
+
expect(found[0].kind).toBe("unknown");
|
|
107
|
+
expect(found[0].suggestion).toBeUndefined();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("is silent on correct elements, including every valid top-level key", () => {
|
|
111
|
+
const found = collectUnknownElementKeys([
|
|
112
|
+
{
|
|
113
|
+
id: "stack",
|
|
114
|
+
name: "a name",
|
|
115
|
+
type: "YStack",
|
|
116
|
+
renderWhen: { variable: "v", operator: "eq", value: 1 },
|
|
117
|
+
props: { gap: 8 },
|
|
118
|
+
children: [{ id: "t", type: "Text", props: { content: "hi" } }],
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
expect(found).toEqual([]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("descends into children and reports the nested path", () => {
|
|
125
|
+
const found = collectUnknownElementKeys([
|
|
126
|
+
{
|
|
127
|
+
id: "outer",
|
|
128
|
+
type: "YStack",
|
|
129
|
+
props: {},
|
|
130
|
+
children: [
|
|
131
|
+
{ id: "ok", type: "Text", props: { content: "fine" } },
|
|
132
|
+
{ id: "bad", type: "Text", props: { content: "x" }, onPress: [] },
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
]);
|
|
136
|
+
expect(found).toHaveLength(1);
|
|
137
|
+
expect(found[0].path).toBe("elements[0].children[1]");
|
|
138
|
+
expect(found[0].suggestion).toBe("props.onPress");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("skips unknown element types but still checks their children", () => {
|
|
142
|
+
// An unknown `type` is a parse error the union already reports well; guessing
|
|
143
|
+
// its key set would be noise. Its children are still ordinary elements.
|
|
144
|
+
const found = collectUnknownElementKeys([
|
|
145
|
+
{
|
|
146
|
+
id: "mystery",
|
|
147
|
+
type: "NotAnElement",
|
|
148
|
+
props: {},
|
|
149
|
+
bogus: 1,
|
|
150
|
+
children: [{ id: "t", type: "Text", props: { content: "x" }, animation: {} }],
|
|
151
|
+
},
|
|
152
|
+
]);
|
|
153
|
+
expect(found).toHaveLength(1);
|
|
154
|
+
expect(found[0].elementId).toBe("t");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("never throws on malformed input", () => {
|
|
158
|
+
expect(collectUnknownElementKeys(undefined)).toEqual([]);
|
|
159
|
+
expect(collectUnknownElementKeys("nope")).toEqual([]);
|
|
160
|
+
expect(collectUnknownElementKeys([null, 42, undefined])).toEqual([]);
|
|
161
|
+
expect(collectUnknownElementKeys([{ type: "Text" }])).toEqual([]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("derives allowed keys from the schema, so container children are recognised", () => {
|
|
165
|
+
// `children` is valid on YStack but not on Image — derived per variant, not
|
|
166
|
+
// from one hardcoded list.
|
|
167
|
+
expect(collectUnknownElementKeys([{ id: "y", type: "YStack", props: {}, children: [] }])).toEqual([]);
|
|
168
|
+
const onImage = collectUnknownElementKeys([
|
|
169
|
+
{ id: "i", type: "Image", props: { url: "u" }, children: [] },
|
|
170
|
+
]);
|
|
171
|
+
expect(onImage).toHaveLength(1);
|
|
172
|
+
expect(onImage[0].key).toBe("children");
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("collectUnknownKeysInSteps", () => {
|
|
177
|
+
it("scans every ComposableScreen step and labels findings by step id", () => {
|
|
178
|
+
const found = collectUnknownKeysInSteps([
|
|
179
|
+
{ id: "intro", type: "MediaContent", payload: { title: "no elements here" } },
|
|
180
|
+
{
|
|
181
|
+
id: "reveal",
|
|
182
|
+
type: "ComposableScreen",
|
|
183
|
+
payload: {
|
|
184
|
+
elements: [
|
|
185
|
+
{ id: "a", type: "Image", props: { url: "u" }, animation: {} },
|
|
186
|
+
{ id: "b", type: "Image", props: { url: "u" }, animation: {} },
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
]);
|
|
191
|
+
expect(found).toHaveLength(2);
|
|
192
|
+
expect(found[0].path).toBe("step[reveal].elements[0]");
|
|
193
|
+
expect(found.every((f) => f.suggestion === "props.animation")).toBe(true);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("returns nothing for step lists with no element trees", () => {
|
|
197
|
+
expect(collectUnknownKeysInSteps([{ id: "x", type: "Ratings", payload: {} }])).toEqual([]);
|
|
198
|
+
expect(collectUnknownKeysInSteps(undefined)).toEqual([]);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("formatUnknownElementKeys", () => {
|
|
203
|
+
it("returns an empty string when there is nothing to report", () => {
|
|
204
|
+
expect(formatUnknownElementKeys([])).toBe("");
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("says which copy wins for a stale duplicate, and never says 'did you mean'", () => {
|
|
208
|
+
const msg = formatUnknownElementKeys(
|
|
209
|
+
collectUnknownElementKeys([
|
|
210
|
+
{
|
|
211
|
+
id: "loader-img-1",
|
|
212
|
+
type: "Image",
|
|
213
|
+
props: { url: "u", animation: { entering: { duration: 200 } } },
|
|
214
|
+
animation: { entering: { duration: 300 } },
|
|
215
|
+
},
|
|
216
|
+
])
|
|
217
|
+
);
|
|
218
|
+
expect(msg).toContain("is ignored");
|
|
219
|
+
expect(msg).toContain("different value");
|
|
220
|
+
expect(msg).toContain("taking effect");
|
|
221
|
+
expect(msg).not.toContain("did you mean");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("names the fix for a misplaced prop", () => {
|
|
225
|
+
const msg = formatUnknownElementKeys(
|
|
226
|
+
collectUnknownElementKeys([
|
|
227
|
+
{ id: "hero", type: "Image", props: { url: "u" }, animation: {} },
|
|
228
|
+
])
|
|
229
|
+
);
|
|
230
|
+
expect(msg).toContain('did you mean props.animation?');
|
|
231
|
+
expect(msg).toContain("hero");
|
|
232
|
+
expect(msg).toContain("silently dropped");
|
|
233
|
+
});
|
|
234
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -47,6 +47,14 @@ export {
|
|
|
47
47
|
generateWheelPickerRangeItems,
|
|
48
48
|
resolveWheelPickerItems,
|
|
49
49
|
} from "./steps/ComposableScreen/types";
|
|
50
|
+
// Payload diagnostics — non-fatal detection of keys placed at an element's top
|
|
51
|
+
// level that the schema silently drops (e.g. `animation` outside `props`).
|
|
52
|
+
export {
|
|
53
|
+
collectUnknownElementKeys,
|
|
54
|
+
collectUnknownKeysInSteps,
|
|
55
|
+
formatUnknownElementKeys,
|
|
56
|
+
} from "./screens/unknownKeys";
|
|
57
|
+
export type { UnknownElementKey } from "./screens/unknownKeys";
|
|
50
58
|
// Hooks and providers
|
|
51
59
|
export * from "./infra";
|
|
52
60
|
// Navigation adapter (dependency-injected navigation)
|
|
@@ -79,3 +87,15 @@ export {
|
|
|
79
87
|
} from "./steps/common.types";
|
|
80
88
|
// Product runtime (paywall phase 3) — vendor-neutral store products
|
|
81
89
|
export * from "./products";
|
|
90
|
+
// Paywalls (paywall phase 5) — catalog types, provider, and the `usePaywall` hook
|
|
91
|
+
export type {
|
|
92
|
+
Paywall,
|
|
93
|
+
PaywallCatalog,
|
|
94
|
+
PaywallOptions,
|
|
95
|
+
GetPaywallsResponseHeaders,
|
|
96
|
+
PresentResult,
|
|
97
|
+
} from "./paywalls/types";
|
|
98
|
+
export { PaywallProvider, usePaywallHost } from "./paywalls/PaywallProvider";
|
|
99
|
+
export type { PaywallContextValue } from "./paywalls/PaywallProvider";
|
|
100
|
+
export { usePaywall } from "./paywalls/usePaywall";
|
|
101
|
+
export type { UsePaywallResult } from "./paywalls/usePaywall";
|
package/src/infra/hooks/index.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { useOnboardingStart } from "./useOnboardingStart";
|
|
|
3
3
|
export { useOnboarding } from "./useOnboarding";
|
|
4
4
|
export { useOnboardingHeaderHeight } from "./useOnboardingHeaderHeight";
|
|
5
5
|
export { useOnboardingNavigation } from "./useOnboardingNavigation";
|
|
6
|
+
export { useProgressHeaderConfig } from "./useProgressHeaderConfig";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { OnboardingProgressContext } from "../provider/OnboardingProvider";
|
|
3
|
+
import type { ProgressHeaderConfiguration } from "../../types";
|
|
4
|
+
|
|
5
|
+
const EMPTY: ProgressHeaderConfiguration = {};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Studio-authored progress-header styling (`configuration.progressHeader`).
|
|
9
|
+
*
|
|
10
|
+
* Returns an empty object when the onboarding hasn't loaded yet or the studio
|
|
11
|
+
* hasn't authored the block, so callers can read fields unconditionally and fall
|
|
12
|
+
* back per-field rather than branching on the whole object.
|
|
13
|
+
*
|
|
14
|
+
* The progress header is host-rendered (the app mounts `<ProgressBar>` in its
|
|
15
|
+
* layout), so the bar reads this itself instead of the provider passing props
|
|
16
|
+
* down — that keeps the studio knob working without every host changing code.
|
|
17
|
+
*/
|
|
18
|
+
export const useProgressHeaderConfig = (): ProgressHeaderConfiguration => {
|
|
19
|
+
const { onboarding } = useContext(OnboardingProgressContext);
|
|
20
|
+
return onboarding?.configuration?.progressHeader ?? EMPTY;
|
|
21
|
+
};
|
|
@@ -36,13 +36,33 @@ const mediaTypeToKind = (type: unknown): AssetKind => {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
// An unresolved `{{var}}` placeholder. Such a url is a TEMPLATE, not an address:
|
|
40
|
+
// prefetching it would fire a request for a literal "https://cdn/{{sign}}.png"
|
|
41
|
+
// that always 404s, and the real url isn't knowable until the variable resolves.
|
|
42
|
+
const hasPlaceholder = (url: string): boolean => url.includes("{{");
|
|
43
|
+
|
|
39
44
|
// Push a url with kind, re-tagging SVG images so the runner HTTP-warms them.
|
|
40
45
|
const pushAsset = (out: AssetRef[], url: unknown, kind: AssetKind): void => {
|
|
41
46
|
if (typeof url !== "string" || url.length === 0) return;
|
|
47
|
+
// Skip templates. Reached by an `Image` with `mode: "expression"`, and by the
|
|
48
|
+
// template inside a `Repeat` (whose per-row urls are pushed separately, below,
|
|
49
|
+
// where the row data makes them resolvable).
|
|
50
|
+
if (hasPlaceholder(url)) return;
|
|
42
51
|
const finalKind: AssetKind = kind === "image" && isSvgUrl(url) ? "image-svg" : kind;
|
|
43
52
|
out.push({ url, kind: finalKind });
|
|
44
53
|
};
|
|
45
54
|
|
|
55
|
+
// Resolve `{{scope.field}}` against one Repeat row. Only the row scope is
|
|
56
|
+
// substituted — anything referencing a runtime variable stays a placeholder and
|
|
57
|
+
// is dropped by `pushAsset`, which is correct: it still isn't knowable up front.
|
|
58
|
+
const resolveRowUrl = (url: string, row: Record<string, unknown>, scope: string): string =>
|
|
59
|
+
url.replace(/\{\{([^}]+?)\}\}/g, (match, key: string) => {
|
|
60
|
+
const trimmed = key.trim();
|
|
61
|
+
if (!trimmed.startsWith(`${scope}.`)) return match;
|
|
62
|
+
const value = row[trimmed.slice(scope.length + 1)];
|
|
63
|
+
return value == null ? match : String(value);
|
|
64
|
+
});
|
|
65
|
+
|
|
46
66
|
// A `{ type, url }` MediaSource is remote (prefetchable); a `{ type, localPathId }`
|
|
47
67
|
// MediaSource is a bundled asset — skip it.
|
|
48
68
|
const pushMediaSource = (out: AssetRef[], media: any): void => {
|
|
@@ -76,11 +96,63 @@ const walkElement = (out: AssetRef[], element: any): void => {
|
|
|
76
96
|
break;
|
|
77
97
|
}
|
|
78
98
|
|
|
99
|
+
// A `Repeat` renders its template once per row, so the assets it actually
|
|
100
|
+
// shows are the template's url props resolved against each row — the template
|
|
101
|
+
// string itself is unfetchable and was skipped above. Walk the template once
|
|
102
|
+
// per row with the row substituted in, so repeated media still preloads.
|
|
103
|
+
if (element.type === "Repeat" && Array.isArray(props.data)) {
|
|
104
|
+
const scope = typeof props.as === "string" && props.as ? props.as : "item";
|
|
105
|
+
for (const row of props.data) {
|
|
106
|
+
if (!row || typeof row !== "object") continue;
|
|
107
|
+
const resolved: AssetRef[] = [];
|
|
108
|
+
if (Array.isArray(element.children)) {
|
|
109
|
+
for (const child of element.children) walkElementWithRow(resolved, child, row, scope);
|
|
110
|
+
}
|
|
111
|
+
out.push(...resolved);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
79
116
|
if (Array.isArray(element.children)) {
|
|
80
117
|
for (const child of element.children) walkElement(out, child);
|
|
81
118
|
}
|
|
82
119
|
};
|
|
83
120
|
|
|
121
|
+
// `walkElement`, but url props are resolved against a Repeat row first. Separate
|
|
122
|
+
// from `walkElement` so the ordinary path stays allocation-free.
|
|
123
|
+
const walkElementWithRow = (
|
|
124
|
+
out: AssetRef[],
|
|
125
|
+
element: any,
|
|
126
|
+
row: Record<string, unknown>,
|
|
127
|
+
scope: string
|
|
128
|
+
): void => {
|
|
129
|
+
if (!element || typeof element !== "object") return;
|
|
130
|
+
const props = element.props ?? {};
|
|
131
|
+
const resolve = (u: unknown) => (typeof u === "string" ? resolveRowUrl(u, row, scope) : u);
|
|
132
|
+
|
|
133
|
+
switch (element.type) {
|
|
134
|
+
case "Image":
|
|
135
|
+
case "ProgressiveBlurImage":
|
|
136
|
+
pushAsset(out, resolve(props.url), "image");
|
|
137
|
+
break;
|
|
138
|
+
case "Video":
|
|
139
|
+
pushAsset(out, resolve(props.url), "video");
|
|
140
|
+
break;
|
|
141
|
+
case "Lottie":
|
|
142
|
+
pushAsset(out, resolve(props.source), "lottie");
|
|
143
|
+
break;
|
|
144
|
+
case "Rive":
|
|
145
|
+
pushAsset(out, resolve(props.url), "rive");
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (Array.isArray(element.children)) {
|
|
152
|
+
for (const child of element.children) walkElementWithRow(out, child, row, scope);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
84
156
|
// Collect every remote asset from one step. Defensive: a malformed step throws
|
|
85
157
|
// here and is swallowed by the per-step guard in extractAssetUrls.
|
|
86
158
|
const extractFromStep = (out: AssetRef[], step: BaseStepType): void => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useCallback, useEffect, useRef, useState } from "react";
|
|
1
|
+
import { createContext, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/react-query";
|
|
3
3
|
import { OnboardingStudioClient } from "../../OnboardingStudioClient";
|
|
4
4
|
import { getOnboardingQuery } from "../queries/getOnboarding.query";
|
|
@@ -8,10 +8,16 @@ import { ComposableVariableEntry } from "../../steps/ComposableScreen/types";
|
|
|
8
8
|
import { FontLoaderGate } from "./FontLoader";
|
|
9
9
|
import { extractAssetUrls } from "../preload/extractAssetUrls";
|
|
10
10
|
import { preloadAssets } from "../preload/preloadAssets";
|
|
11
|
+
import { collectUnknownKeysInSteps, formatUnknownElementKeys } from "../../screens/unknownKeys";
|
|
11
12
|
import { OnboardingNavigationAdapter } from "../navigation/types";
|
|
12
13
|
import { expoRouterAdapter } from "../navigation/expoRouterAdapter";
|
|
13
14
|
import { useProducts } from "../../products/useProducts";
|
|
14
15
|
import { ProductProvider, ProductRef, ProductRuntime } from "../../products/types";
|
|
16
|
+
import { useProductRuntime } from "../../products/ProductRuntimeContext";
|
|
17
|
+
import { mergeProductRuntimes } from "../../products/mergeProductRuntimes";
|
|
18
|
+
|
|
19
|
+
// React Native's dev flag; guarded at every use so non-RN consumers are fine.
|
|
20
|
+
declare const __DEV__: boolean;
|
|
15
21
|
|
|
16
22
|
const queryClient = new QueryClient({
|
|
17
23
|
defaultOptions: {
|
|
@@ -32,6 +38,41 @@ const EMPTY_PRODUCT_RUNTIME: ProductRuntime = {
|
|
|
32
38
|
restore: async () => ({ status: "error", error: new Error("No ProductProvider") }),
|
|
33
39
|
};
|
|
34
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Args for the local `useProducts` call.
|
|
43
|
+
*
|
|
44
|
+
* This function used to zero refs/provider out entirely whenever a
|
|
45
|
+
* `PaywallProvider` (or other ancestor) already published a `ProductRuntime`
|
|
46
|
+
* via `ProductRuntimeContext` — on the assumption that the paywall catalog's
|
|
47
|
+
* product union is always a superset of whatever `productRefs` this
|
|
48
|
+
* `OnboardingProvider` declares. Finding 5 (2026-08-17 final review) found
|
|
49
|
+
* that assumption wrong: it is a claim about a host-supplied prop, not a
|
|
50
|
+
* property of the code, and it silently stopped resolving any `productRefs`
|
|
51
|
+
* key absent from the catalog union the moment a host added a
|
|
52
|
+
* `PaywallProvider` above an existing `OnboardingProvider` — no error,
|
|
53
|
+
* nothing that type-checks, just a variable that renders empty.
|
|
54
|
+
*
|
|
55
|
+
* `productRefs`/`productProvider` are therefore passed through UNCHANGED
|
|
56
|
+
* regardless of whether a context runtime exists — `mergeProductRuntimes`
|
|
57
|
+
* (in `OnboardingProvider` below) unions the resulting local runtime back
|
|
58
|
+
* into the context one. Exported so the pass-through itself is covered by an
|
|
59
|
+
* importable, real test, not only inspection: this is the exact seam Finding
|
|
60
|
+
* 5's silent regression went through.
|
|
61
|
+
*/
|
|
62
|
+
export const resolveLocalProductArgs = (
|
|
63
|
+
productRefs: ProductRef[] | undefined,
|
|
64
|
+
productProvider: ProductProvider | undefined
|
|
65
|
+
): { refs: ProductRef[] | undefined; provider: ProductProvider | undefined } => ({
|
|
66
|
+
refs: productRefs,
|
|
67
|
+
provider: productProvider,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Frozen at module scope, not `= {}` inline: a default PARAMETER re-allocates on
|
|
71
|
+
// every render, and `customActions` is a RenderContext dependency, so a host that
|
|
72
|
+
// omits the prop would get a fresh `ctx` on every variable write and re-render the
|
|
73
|
+
// whole tree. Same reason EMPTY_PRODUCT_RUNTIME above is hoisted.
|
|
74
|
+
const EMPTY_CUSTOM_ACTIONS: CustomActions = Object.freeze({});
|
|
75
|
+
|
|
35
76
|
export type CustomActionHandler = (args: {
|
|
36
77
|
variables: Record<string, ComposableVariableEntry | undefined>;
|
|
37
78
|
/**
|
|
@@ -136,6 +177,16 @@ const OnboardingDataGate = ({
|
|
|
136
177
|
if (!data || preloadedRef.current === data) return;
|
|
137
178
|
preloadedRef.current = data;
|
|
138
179
|
preloadAssets(extractAssetUrls(data));
|
|
180
|
+
|
|
181
|
+
// Dev-only payload diagnostic: report keys sitting at an element's top level
|
|
182
|
+
// that the schema silently drops (classically `animation` outside `props`,
|
|
183
|
+
// which parses, renders, and simply never animates). Non-fatal by design —
|
|
184
|
+
// rejecting these would turn a no-op into a broken screen. Dev-gated and run
|
|
185
|
+
// once per payload, so it costs production nothing.
|
|
186
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
187
|
+
const report = formatUnknownElementKeys(collectUnknownKeysInSteps(data.steps));
|
|
188
|
+
if (report) console.warn(report);
|
|
189
|
+
}
|
|
139
190
|
}, [data]);
|
|
140
191
|
|
|
141
192
|
if (error) throw error;
|
|
@@ -153,7 +204,7 @@ export const OnboardingProvider = ({
|
|
|
153
204
|
client,
|
|
154
205
|
locale = "en",
|
|
155
206
|
customAudienceParams = {},
|
|
156
|
-
customActions =
|
|
207
|
+
customActions = EMPTY_CUSTOM_ACTIONS,
|
|
157
208
|
fontsFallback,
|
|
158
209
|
navigation = expoRouterAdapter,
|
|
159
210
|
onComplete,
|
|
@@ -201,7 +252,40 @@ export const OnboardingProvider = ({
|
|
|
201
252
|
});
|
|
202
253
|
}, [onComplete, onboarding]);
|
|
203
254
|
|
|
204
|
-
|
|
255
|
+
// A ProductRuntime may already be published above by a `PaywallProvider`
|
|
256
|
+
// (Phase 5 Task 6) sharing one product catalog with this provider. Hooks
|
|
257
|
+
// can't be called conditionally, so `useProducts` is always called, with
|
|
258
|
+
// this provider's OWN `productRefs`/`productProvider` regardless of whether
|
|
259
|
+
// a context runtime exists (`resolveLocalProductArgs`) — when a context
|
|
260
|
+
// runtime is present, `mergeProductRuntimes` unions the two into the one
|
|
261
|
+
// `ProductRuntime` published below (Finding 5, 2026-08-17 final review: the
|
|
262
|
+
// two runtimes used to never merge, so a context runtime silently made
|
|
263
|
+
// `productRefs` unresolvable). Do not "simplify" this into a conditional
|
|
264
|
+
// hook call.
|
|
265
|
+
const contextRuntime = useProductRuntime();
|
|
266
|
+
const { refs: localProductRefs, provider: localProductProvider } = resolveLocalProductArgs(
|
|
267
|
+
productRefs,
|
|
268
|
+
productProvider
|
|
269
|
+
);
|
|
270
|
+
const localProductRuntime = useProducts(localProductRefs, localProductProvider, locale);
|
|
271
|
+
const hasLocalRefs = (productRefs?.length ?? 0) > 0;
|
|
272
|
+
const hasLocalProvider = !!localProductProvider;
|
|
273
|
+
// Memoized — round 2 of the final review (N1) caught that calling
|
|
274
|
+
// `mergeProductRuntimes` inline in the render body allocates a fresh object
|
|
275
|
+
// (and a fresh `purchase` closure) on EVERY render whenever `hasLocalRefs`,
|
|
276
|
+
// breaking `ScreenHost.products`'s "referentially stable across variable
|
|
277
|
+
// writes" contract (`ScreenHost.ts`) the moment a host uses `productRefs`
|
|
278
|
+
// alongside a `PaywallProvider` ancestor — every memoized element would
|
|
279
|
+
// re-render on every keystroke, since `setVariables` always allocates a new
|
|
280
|
+
// object. Keyed on the two runtimes plus the two booleans that change the
|
|
281
|
+
// merge's shape, exactly the inputs the function reads.
|
|
282
|
+
const productRuntime = useMemo(
|
|
283
|
+
() =>
|
|
284
|
+
contextRuntime
|
|
285
|
+
? mergeProductRuntimes(contextRuntime, localProductRuntime, hasLocalRefs, hasLocalProvider)
|
|
286
|
+
: localProductRuntime,
|
|
287
|
+
[contextRuntime, localProductRuntime, hasLocalRefs, hasLocalProvider]
|
|
288
|
+
);
|
|
205
289
|
|
|
206
290
|
return (
|
|
207
291
|
<QueryClientProvider client={queryClient}>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AsyncStorage key derivation for the cached onboarding
|
|
2
|
+
* AsyncStorage key derivation for the SDK's cached payloads (onboarding
|
|
3
|
+
* steps, paywall catalog).
|
|
3
4
|
*
|
|
4
|
-
* Lives in its own module so
|
|
5
|
-
* `OnboardingStudioClient` can use
|
|
6
|
-
* (the query
|
|
5
|
+
* Lives in its own module so `getOnboarding.query.ts`, `getPaywalls.query.ts`
|
|
6
|
+
* and `OnboardingStudioClient` can all use these as values without a circular
|
|
7
|
+
* import (the query modules import `OnboardingStudioClient` for typing) —
|
|
8
|
+
* this module itself has no imports.
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
/** Default cache key used when the host does not provide a custom one. */
|
|
@@ -22,3 +24,24 @@ export const getOnboardingCacheKey = (customKey?: string): string =>
|
|
|
22
24
|
customKey
|
|
23
25
|
? `rocapine-onboarding-sdk-${customKey}`
|
|
24
26
|
: DEFAULT_ONBOARDING_CACHE_KEY;
|
|
27
|
+
|
|
28
|
+
/** Default cache key used when the host does not provide a custom one. */
|
|
29
|
+
export const DEFAULT_PAYWALLS_CACHE_KEY = "rocapine-paywalls-studio";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Derives the AsyncStorage key for the cached paywall catalog.
|
|
33
|
+
*
|
|
34
|
+
* Namespaced separately from `getOnboardingCacheKey`
|
|
35
|
+
* (`rocapine-paywalls-*` vs `rocapine-onboarding-*`) so the two caches never
|
|
36
|
+
* collide, even though both derive from the same `client.options.cacheKey`.
|
|
37
|
+
*
|
|
38
|
+
* - No custom key → the shared default `"rocapine-paywalls-studio"`
|
|
39
|
+
* (stale-while-revalidate: served cache-first and healed in the background).
|
|
40
|
+
* - Custom key → `"rocapine-paywalls-sdk-{customKey}"`, which the SDK persists
|
|
41
|
+
* cache-first with **no** background revalidation, so the host owns when to
|
|
42
|
+
* refetch (see `OnboardingStudioClient.clearCache`).
|
|
43
|
+
*/
|
|
44
|
+
export const getPaywallsCacheKey = (customKey?: string): string =>
|
|
45
|
+
customKey
|
|
46
|
+
? `rocapine-paywalls-sdk-${customKey}`
|
|
47
|
+
: DEFAULT_PAYWALLS_CACHE_KEY;
|