@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.
Files changed (70) hide show
  1. package/dist/OnboardingStudioClient.d.ts +23 -5
  2. package/dist/OnboardingStudioClient.d.ts.map +1 -1
  3. package/dist/OnboardingStudioClient.js +82 -6
  4. package/dist/OnboardingStudioClient.js.map +1 -1
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +6 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/infra/provider/OnboardingProvider.d.ts +25 -0
  10. package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
  11. package/dist/infra/provider/OnboardingProvider.js +63 -3
  12. package/dist/infra/provider/OnboardingProvider.js.map +1 -1
  13. package/dist/infra/queries/cacheKey.d.ts +22 -4
  14. package/dist/infra/queries/cacheKey.d.ts.map +1 -1
  15. package/dist/infra/queries/cacheKey.js +26 -5
  16. package/dist/infra/queries/cacheKey.js.map +1 -1
  17. package/dist/paywalls/PaywallProvider.d.ts +66 -0
  18. package/dist/paywalls/PaywallProvider.d.ts.map +1 -0
  19. package/dist/paywalls/PaywallProvider.js +227 -0
  20. package/dist/paywalls/PaywallProvider.js.map +1 -0
  21. package/dist/paywalls/getPaywalls.query.d.ts +37 -0
  22. package/dist/paywalls/getPaywalls.query.d.ts.map +1 -0
  23. package/dist/paywalls/getPaywalls.query.js +114 -0
  24. package/dist/paywalls/getPaywalls.query.js.map +1 -0
  25. package/dist/paywalls/present.d.ts +100 -0
  26. package/dist/paywalls/present.d.ts.map +1 -0
  27. package/dist/paywalls/present.js +113 -0
  28. package/dist/paywalls/present.js.map +1 -0
  29. package/dist/paywalls/types.d.ts +95 -0
  30. package/dist/paywalls/types.d.ts.map +1 -0
  31. package/dist/paywalls/types.js +10 -0
  32. package/dist/paywalls/types.js.map +1 -0
  33. package/dist/paywalls/usePaywall.d.ts +29 -0
  34. package/dist/paywalls/usePaywall.d.ts.map +1 -0
  35. package/dist/paywalls/usePaywall.js +17 -0
  36. package/dist/paywalls/usePaywall.js.map +1 -0
  37. package/dist/products/ProductRuntimeContext.d.ts +15 -0
  38. package/dist/products/ProductRuntimeContext.d.ts.map +1 -0
  39. package/dist/products/ProductRuntimeContext.js +19 -0
  40. package/dist/products/ProductRuntimeContext.js.map +1 -0
  41. package/dist/products/index.d.ts +1 -0
  42. package/dist/products/index.d.ts.map +1 -1
  43. package/dist/products/index.js +4 -1
  44. package/dist/products/index.js.map +1 -1
  45. package/dist/products/mergeProductRuntimes.d.ts +55 -0
  46. package/dist/products/mergeProductRuntimes.d.ts.map +1 -0
  47. package/dist/products/mergeProductRuntimes.js +79 -0
  48. package/dist/products/mergeProductRuntimes.js.map +1 -0
  49. package/dist/steps/common.types.d.ts +22 -1
  50. package/dist/steps/common.types.d.ts.map +1 -1
  51. package/dist/steps/common.types.js +10 -1
  52. package/dist/steps/common.types.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/OnboardingStudioClient.ts +110 -7
  55. package/src/__tests__/mergeProductRuntimes.test.ts +172 -0
  56. package/src/__tests__/resolveLocalProductArgs.test.ts +41 -0
  57. package/src/index.ts +12 -0
  58. package/src/infra/provider/OnboardingProvider.tsx +73 -3
  59. package/src/infra/queries/cacheKey.ts +27 -4
  60. package/src/paywalls/PaywallProvider.tsx +342 -0
  61. package/src/paywalls/__tests__/getPaywalls.test.ts +334 -0
  62. package/src/paywalls/__tests__/present.test.ts +190 -0
  63. package/src/paywalls/getPaywalls.query.ts +123 -0
  64. package/src/paywalls/present.ts +141 -0
  65. package/src/paywalls/types.ts +99 -0
  66. package/src/paywalls/usePaywall.ts +35 -0
  67. package/src/products/ProductRuntimeContext.tsx +17 -0
  68. package/src/products/index.ts +1 -0
  69. package/src/products/mergeProductRuntimes.ts +78 -0
  70. package/src/steps/common.types.ts +34 -1
@@ -8,7 +8,15 @@ import {
8
8
  UserDefinedParams,
9
9
  BaseStepType,
10
10
  } from "./types";
11
- import { getOnboardingCacheKey } from "./infra/queries/cacheKey";
11
+ import {
12
+ getOnboardingCacheKey,
13
+ getPaywallsCacheKey,
14
+ } from "./infra/queries/cacheKey";
15
+ import {
16
+ PaywallCatalog,
17
+ PaywallOptions,
18
+ GetPaywallsResponseHeaders,
19
+ } from "./paywalls/types";
12
20
 
13
21
  import { Platform } from "react-native";
14
22
 
@@ -27,14 +35,18 @@ export class OnboardingStudioClient {
27
35
  }
28
36
 
29
37
  /**
30
- * Removes this client's cached onboarding payload from AsyncStorage (the key
31
- * derived from `options.cacheKey`, or the default key). The next query mount
32
- * or app launch is then a cache miss and refetches. To force an in-session
33
- * refetch as well, also invalidate the React Query key
34
- * `["onboardingQuestions", ...]`.
38
+ * Removes this client's cached onboarding payload AND cached paywall catalog
39
+ * from AsyncStorage (the keys derived from `options.cacheKey`, or the
40
+ * default keys). The next query mount or app launch is then a cache miss
41
+ * and refetches both. To force an in-session refetch as well, also
42
+ * invalidate the React Query keys `["onboardingQuestions", ...]` and
43
+ * `["paywallCatalog", ...]`.
35
44
  */
36
45
  async clearCache(): Promise<void> {
37
- await AsyncStorage.removeItem(getOnboardingCacheKey(this.options.cacheKey));
46
+ await Promise.all([
47
+ AsyncStorage.removeItem(getOnboardingCacheKey(this.options.cacheKey)),
48
+ AsyncStorage.removeItem(getPaywallsCacheKey(this.options.cacheKey)),
49
+ ]);
38
50
  }
39
51
 
40
52
  async getSteps<StepType extends BaseStepType = OnboardingStepType>(
@@ -115,4 +127,95 @@ export class OnboardingStudioClient {
115
127
  throw error;
116
128
  }
117
129
  }
130
+
131
+ /**
132
+ * Fetches the paywall catalog for this project/audience/locale from
133
+ * `get-paywalls`. By design **omits `placement` by default** — the endpoint
134
+ * deliberately returns every placement in one round-trip so a paywall can
135
+ * be presented the instant the user taps upgrade, without a network call at
136
+ * that moment (spec §6.1). Pass `paywallOptions.placement` only when a
137
+ * single placement is genuinely all that's needed.
138
+ *
139
+ * Unlike `getSteps`, there is no fallback-payload option here: a
140
+ * non-`ok` response or a network failure always rejects rather than
141
+ * resolving to a stand-in catalog.
142
+ */
143
+ async getPaywalls(
144
+ paywallOptions?: PaywallOptions,
145
+ userDefinedParams?: UserDefinedParams
146
+ ): Promise<{ data: PaywallCatalog; headers: GetPaywallsResponseHeaders }> {
147
+ console.info("OnboardingStudioClient getPaywalls");
148
+ const isSandbox = this.options.isSandbox;
149
+
150
+ const urlParams = new URLSearchParams();
151
+ // Add userDefinedParams to URL
152
+ if (userDefinedParams) {
153
+ Object.entries(userDefinedParams).forEach(([key, value]) => {
154
+ urlParams.append(key, value);
155
+ });
156
+ }
157
+
158
+ urlParams.append("projectId", this.projectId);
159
+ urlParams.append("platform", Platform.OS);
160
+
161
+ const appVersion = this.options.appVersion; // TODO get the version from the expo app
162
+ if (appVersion) {
163
+ urlParams.append("appVersion", appVersion);
164
+ }
165
+
166
+ if (isSandbox) {
167
+ urlParams.append("draft", "true");
168
+ }
169
+
170
+ // Add paywallOptions to URL
171
+ if (paywallOptions?.locale) {
172
+ urlParams.append("locale", paywallOptions.locale);
173
+ }
174
+
175
+ // Narrows the response to a single paywall. Omitted unless explicitly
176
+ // requested — see the method doc above.
177
+ if (paywallOptions?.placement) {
178
+ urlParams.append("placement", paywallOptions.placement);
179
+ }
180
+
181
+ // Deliberately NOT sending spec §6.1's `omitNulls=true`: it's a
182
+ // convenience for untyped consumers that strips null-valued keys from the
183
+ // response, which would make the runtime shape diverge from `PaywallCatalog`
184
+ // and `Paywall`'s declared `| null` fields. This client parses into those
185
+ // typed objects, so the fields must always be present (possibly `null`),
186
+ // not sometimes missing.
187
+ const url = `${this.baseUrl}/get-paywalls?${urlParams.toString()}`;
188
+ console.info("OnboardingStudioClient getPaywalls url", url);
189
+ try {
190
+ const response = await Promise.race(
191
+ this.options.timeout
192
+ ? [
193
+ fetch(url),
194
+ new Promise<Response>((_, reject) =>
195
+ setTimeout(
196
+ () => reject(new Error("timeout")),
197
+ this.options.timeout
198
+ )
199
+ ),
200
+ ]
201
+ : [fetch(url)]
202
+ );
203
+ if (!response.ok) {
204
+ throw new Error(
205
+ `Failed to fetch paywalls: ${response.status} ${response.statusText}`
206
+ );
207
+ }
208
+ const data = await response.json();
209
+ return {
210
+ data,
211
+ headers: {
212
+ "ONBS-Audience-Id": response.headers.get("ONBS-Audience-Id"),
213
+ "ONBS-Paywall-Ids": response.headers.get("ONBS-Paywall-Ids"),
214
+ },
215
+ };
216
+ } catch (error) {
217
+ console.error("OnboardingStudioClient getPaywalls error", error);
218
+ throw error;
219
+ }
220
+ }
118
221
  }
@@ -0,0 +1,172 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { mergeProductRuntimes } from "../products/mergeProductRuntimes";
3
+ import type { ProductRuntime, ProductWithDerived } from "../products/types";
4
+
5
+ const product = (key: string): ProductWithDerived => ({
6
+ key,
7
+ productId: `com.app.${key}`,
8
+ store: "app_store",
9
+ title: key,
10
+ description: key,
11
+ price: "$1.99",
12
+ priceAmount: 1.99,
13
+ currencyCode: "USD",
14
+ period: null,
15
+ periodCount: 1,
16
+ periodIso: null,
17
+ });
18
+
19
+ const makeRuntime = (overrides: Partial<ProductRuntime> = {}): ProductRuntime => ({
20
+ products: {},
21
+ status: "idle",
22
+ purchasing: false,
23
+ purchase: async () => ({ status: "cancelled" }),
24
+ restore: async () => ({ status: "nothing_to_restore" }),
25
+ ...overrides,
26
+ });
27
+
28
+ // Finding 5, 2026-08-17 final review: `OnboardingProvider` publishes ONE of
29
+ // two ProductRuntimes (the shared `PaywallProvider` context one, or its own
30
+ // local `useProducts` call) — never both — so a host's own `productRefs`
31
+ // resolved locally were invisible whenever a context runtime existed. This
32
+ // function is the fix: it unions the two into one runtime.
33
+ describe("mergeProductRuntimes", () => {
34
+ it("returns the context runtime UNCHANGED when there are no local refs to add — the common case", () => {
35
+ const contextRuntime = makeRuntime({ products: { yearly: product("yearly") }, status: "ready" });
36
+ const localRuntime = makeRuntime();
37
+
38
+ const result = mergeProductRuntimes(contextRuntime, localRuntime, false, true);
39
+
40
+ expect(result).toBe(contextRuntime);
41
+ });
42
+
43
+ it("unions both runtimes' products when the host declared local productRefs", () => {
44
+ const contextRuntime = makeRuntime({ products: { yearly: product("yearly") }, status: "ready" });
45
+ const localRuntime = makeRuntime({ products: { lifetime: product("lifetime") }, status: "ready" });
46
+
47
+ const result = mergeProductRuntimes(contextRuntime, localRuntime, true, true);
48
+
49
+ expect(result.products).toEqual({
50
+ yearly: product("yearly"),
51
+ lifetime: product("lifetime"),
52
+ });
53
+ });
54
+
55
+ it("is not ready until BOTH runtimes are ready", () => {
56
+ const contextRuntime = makeRuntime({ status: "ready" });
57
+ const localRuntime = makeRuntime({ status: "loading" });
58
+
59
+ expect(mergeProductRuntimes(contextRuntime, localRuntime, true, true).status).toBe("loading");
60
+ });
61
+
62
+ it("reports 'error' if either runtime errored", () => {
63
+ const contextRuntime = makeRuntime({ status: "ready" });
64
+ const localRuntime = makeRuntime({ status: "error", error: "boom" });
65
+
66
+ const result = mergeProductRuntimes(contextRuntime, localRuntime, true, true);
67
+ expect(result.status).toBe("error");
68
+ expect(result.error).toBe("boom");
69
+ });
70
+
71
+ it("is 'ready' once both runtimes resolved", () => {
72
+ const contextRuntime = makeRuntime({ status: "ready" });
73
+ const localRuntime = makeRuntime({ status: "ready" });
74
+
75
+ expect(mergeProductRuntimes(contextRuntime, localRuntime, true, true).status).toBe("ready");
76
+ });
77
+
78
+ // N3, round 2 of the final review: productRefs declared with no local
79
+ // productProvider is a real, unremarkable configuration (the shared context
80
+ // runtime is expected to cover it) — useProducts then never leaves the
81
+ // local runtime's status at anything but "idle" (it bails before ever
82
+ // calling a provider it doesn't have). A naive mergeStatus would drag the
83
+ // context runtime's "ready" down to "idle" forever, closing every
84
+ // renderWhen gate on products.loaded for the life of the component.
85
+ it("hasLocalProvider=false: merged status is the context runtime's alone, not dragged down by a permanently-idle local runtime", () => {
86
+ const contextRuntime = makeRuntime({ status: "ready", products: { yearly: product("yearly") } });
87
+ const localRuntime = makeRuntime({ status: "idle" });
88
+
89
+ const result = mergeProductRuntimes(contextRuntime, localRuntime, true, false);
90
+
91
+ expect(result.status).toBe("ready");
92
+ });
93
+
94
+ it("hasLocalProvider=false: still surfaces the context runtime's error, since that's a real failure", () => {
95
+ const contextRuntime = makeRuntime({ status: "error", error: "boom" });
96
+ const localRuntime = makeRuntime({ status: "idle" });
97
+
98
+ const result = mergeProductRuntimes(contextRuntime, localRuntime, true, false);
99
+
100
+ expect(result.status).toBe("error");
101
+ expect(result.error).toBe("boom");
102
+ });
103
+
104
+ it("purchasing is true if EITHER runtime is mid-purchase", () => {
105
+ const contextRuntime = makeRuntime({ purchasing: false });
106
+ const localRuntime = makeRuntime({ purchasing: true });
107
+
108
+ expect(mergeProductRuntimes(contextRuntime, localRuntime, true, true).purchasing).toBe(true);
109
+ });
110
+
111
+ it("purchase() routes a key resolved by the LOCAL runtime through the local provider", async () => {
112
+ let calledLocal = false;
113
+ const contextRuntime = makeRuntime({
114
+ products: { yearly: product("yearly") },
115
+ purchase: async () => {
116
+ throw new Error("must not call context purchase for a local-only key");
117
+ },
118
+ });
119
+ const localRuntime = makeRuntime({
120
+ products: { lifetime: product("lifetime") },
121
+ purchase: async (key) => {
122
+ calledLocal = true;
123
+ return { status: "purchased", productKey: key };
124
+ },
125
+ });
126
+
127
+ const result = await mergeProductRuntimes(contextRuntime, localRuntime, true, true).purchase("lifetime");
128
+
129
+ expect(calledLocal).toBe(true);
130
+ expect(result).toEqual({ status: "purchased", productKey: "lifetime" });
131
+ });
132
+
133
+ it("purchase() routes anything else — including an unknown key — through the context runtime", async () => {
134
+ let calledContext = false;
135
+ const contextRuntime = makeRuntime({
136
+ products: { yearly: product("yearly") },
137
+ purchase: async (key) => {
138
+ calledContext = true;
139
+ return { status: "purchased", productKey: key };
140
+ },
141
+ });
142
+ const localRuntime = makeRuntime({ products: { lifetime: product("lifetime") } });
143
+
144
+ const result = await mergeProductRuntimes(contextRuntime, localRuntime, true, true).purchase("yearly");
145
+
146
+ expect(calledContext).toBe(true);
147
+ expect(result).toEqual({ status: "purchased", productKey: "yearly" });
148
+ });
149
+
150
+ it("restore() always delegates to the context runtime — restoring is store-account-wide, not per-ref", async () => {
151
+ let calledContext = false;
152
+ let calledLocal = false;
153
+ const contextRuntime = makeRuntime({
154
+ restore: async () => {
155
+ calledContext = true;
156
+ return { status: "restored", entitlements: ["pro"] };
157
+ },
158
+ });
159
+ const localRuntime = makeRuntime({
160
+ restore: async () => {
161
+ calledLocal = true;
162
+ return { status: "restored", entitlements: ["pro"] };
163
+ },
164
+ });
165
+
166
+ const result = await mergeProductRuntimes(contextRuntime, localRuntime, true, true).restore();
167
+
168
+ expect(calledContext).toBe(true);
169
+ expect(calledLocal).toBe(false);
170
+ expect(result).toEqual({ status: "restored", entitlements: ["pro"] });
171
+ });
172
+ });
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+
3
+ // OnboardingProvider.tsx transitively imports `react-native` (via
4
+ // OnboardingStudioClient/registry.ts) and AsyncStorage — mocked the same way
5
+ // getOnboarding.query.test.ts does, so the module loads under Node.
6
+ vi.mock("@react-native-async-storage/async-storage", () => ({
7
+ default: { getItem: vi.fn(), setItem: vi.fn(), removeItem: vi.fn() },
8
+ }));
9
+ vi.mock("react-native", () => ({ Platform: { OS: "ios" } }));
10
+
11
+ import { resolveLocalProductArgs } from "../infra/provider/OnboardingProvider";
12
+ import type { ProductProvider, ProductRef } from "../products/types";
13
+
14
+ const REFS: ProductRef[] = [{ key: "yearly", ios: "com.app.yearly" }];
15
+ const PROVIDER: ProductProvider = {
16
+ getProducts: async () => [],
17
+ purchase: async () => ({ status: "cancelled" }),
18
+ restore: async () => ({ status: "nothing_to_restore" }),
19
+ };
20
+
21
+ // Finding 5, 2026-08-17 final review: this function used to zero refs/provider
22
+ // out whenever a context runtime existed, on the assumption that the paywall
23
+ // catalog's product union is always a superset of the host's own `productRefs`
24
+ // — that silently broke a documented Phase 3 prop the moment a `PaywallProvider`
25
+ // was mounted above. It now passes the host's own args through UNCONDITIONALLY;
26
+ // `mergeProductRuntimes` (see its own test) does the unioning at the runtime
27
+ // level. This test guards the pass-through itself against a regression back to
28
+ // the old zeroing behavior.
29
+ describe("resolveLocalProductArgs", () => {
30
+ it("passes the host's own refs/provider through unchanged", () => {
31
+ const result = resolveLocalProductArgs(REFS, PROVIDER);
32
+ expect(result.refs).toBe(REFS);
33
+ expect(result.provider).toBe(PROVIDER);
34
+ });
35
+
36
+ it("stays undefined when the host declared no productRefs/productProvider props", () => {
37
+ const result = resolveLocalProductArgs(undefined, undefined);
38
+ expect(result.refs).toBeUndefined();
39
+ expect(result.provider).toBeUndefined();
40
+ });
41
+ });
package/src/index.ts CHANGED
@@ -79,3 +79,15 @@ export {
79
79
  } from "./steps/common.types";
80
80
  // Product runtime (paywall phase 3) — vendor-neutral store products
81
81
  export * from "./products";
82
+ // Paywalls (paywall phase 5) — catalog types, provider, and the `usePaywall` hook
83
+ export type {
84
+ Paywall,
85
+ PaywallCatalog,
86
+ PaywallOptions,
87
+ GetPaywallsResponseHeaders,
88
+ PresentResult,
89
+ } from "./paywalls/types";
90
+ export { PaywallProvider, usePaywallHost } from "./paywalls/PaywallProvider";
91
+ export type { PaywallContextValue } from "./paywalls/PaywallProvider";
92
+ export { usePaywall } from "./paywalls/usePaywall";
93
+ export type { UsePaywallResult } from "./paywalls/usePaywall";
@@ -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";
@@ -12,6 +12,8 @@ import { OnboardingNavigationAdapter } from "../navigation/types";
12
12
  import { expoRouterAdapter } from "../navigation/expoRouterAdapter";
13
13
  import { useProducts } from "../../products/useProducts";
14
14
  import { ProductProvider, ProductRef, ProductRuntime } from "../../products/types";
15
+ import { useProductRuntime } from "../../products/ProductRuntimeContext";
16
+ import { mergeProductRuntimes } from "../../products/mergeProductRuntimes";
15
17
 
16
18
  const queryClient = new QueryClient({
17
19
  defaultOptions: {
@@ -32,6 +34,41 @@ const EMPTY_PRODUCT_RUNTIME: ProductRuntime = {
32
34
  restore: async () => ({ status: "error", error: new Error("No ProductProvider") }),
33
35
  };
34
36
 
37
+ /**
38
+ * Args for the local `useProducts` call.
39
+ *
40
+ * This function used to zero refs/provider out entirely whenever a
41
+ * `PaywallProvider` (or other ancestor) already published a `ProductRuntime`
42
+ * via `ProductRuntimeContext` — on the assumption that the paywall catalog's
43
+ * product union is always a superset of whatever `productRefs` this
44
+ * `OnboardingProvider` declares. Finding 5 (2026-08-17 final review) found
45
+ * that assumption wrong: it is a claim about a host-supplied prop, not a
46
+ * property of the code, and it silently stopped resolving any `productRefs`
47
+ * key absent from the catalog union the moment a host added a
48
+ * `PaywallProvider` above an existing `OnboardingProvider` — no error,
49
+ * nothing that type-checks, just a variable that renders empty.
50
+ *
51
+ * `productRefs`/`productProvider` are therefore passed through UNCHANGED
52
+ * regardless of whether a context runtime exists — `mergeProductRuntimes`
53
+ * (in `OnboardingProvider` below) unions the resulting local runtime back
54
+ * into the context one. Exported so the pass-through itself is covered by an
55
+ * importable, real test, not only inspection: this is the exact seam Finding
56
+ * 5's silent regression went through.
57
+ */
58
+ export const resolveLocalProductArgs = (
59
+ productRefs: ProductRef[] | undefined,
60
+ productProvider: ProductProvider | undefined
61
+ ): { refs: ProductRef[] | undefined; provider: ProductProvider | undefined } => ({
62
+ refs: productRefs,
63
+ provider: productProvider,
64
+ });
65
+
66
+ // Frozen at module scope, not `= {}` inline: a default PARAMETER re-allocates on
67
+ // every render, and `customActions` is a RenderContext dependency, so a host that
68
+ // omits the prop would get a fresh `ctx` on every variable write and re-render the
69
+ // whole tree. Same reason EMPTY_PRODUCT_RUNTIME above is hoisted.
70
+ const EMPTY_CUSTOM_ACTIONS: CustomActions = Object.freeze({});
71
+
35
72
  export type CustomActionHandler = (args: {
36
73
  variables: Record<string, ComposableVariableEntry | undefined>;
37
74
  /**
@@ -153,7 +190,7 @@ export const OnboardingProvider = ({
153
190
  client,
154
191
  locale = "en",
155
192
  customAudienceParams = {},
156
- customActions = {},
193
+ customActions = EMPTY_CUSTOM_ACTIONS,
157
194
  fontsFallback,
158
195
  navigation = expoRouterAdapter,
159
196
  onComplete,
@@ -201,7 +238,40 @@ export const OnboardingProvider = ({
201
238
  });
202
239
  }, [onComplete, onboarding]);
203
240
 
204
- const productRuntime = useProducts(productRefs, productProvider, locale);
241
+ // A ProductRuntime may already be published above by a `PaywallProvider`
242
+ // (Phase 5 Task 6) sharing one product catalog with this provider. Hooks
243
+ // can't be called conditionally, so `useProducts` is always called, with
244
+ // this provider's OWN `productRefs`/`productProvider` regardless of whether
245
+ // a context runtime exists (`resolveLocalProductArgs`) — when a context
246
+ // runtime is present, `mergeProductRuntimes` unions the two into the one
247
+ // `ProductRuntime` published below (Finding 5, 2026-08-17 final review: the
248
+ // two runtimes used to never merge, so a context runtime silently made
249
+ // `productRefs` unresolvable). Do not "simplify" this into a conditional
250
+ // hook call.
251
+ const contextRuntime = useProductRuntime();
252
+ const { refs: localProductRefs, provider: localProductProvider } = resolveLocalProductArgs(
253
+ productRefs,
254
+ productProvider
255
+ );
256
+ const localProductRuntime = useProducts(localProductRefs, localProductProvider, locale);
257
+ const hasLocalRefs = (productRefs?.length ?? 0) > 0;
258
+ const hasLocalProvider = !!localProductProvider;
259
+ // Memoized — round 2 of the final review (N1) caught that calling
260
+ // `mergeProductRuntimes` inline in the render body allocates a fresh object
261
+ // (and a fresh `purchase` closure) on EVERY render whenever `hasLocalRefs`,
262
+ // breaking `ScreenHost.products`'s "referentially stable across variable
263
+ // writes" contract (`ScreenHost.ts`) the moment a host uses `productRefs`
264
+ // alongside a `PaywallProvider` ancestor — every memoized element would
265
+ // re-render on every keystroke, since `setVariables` always allocates a new
266
+ // object. Keyed on the two runtimes plus the two booleans that change the
267
+ // merge's shape, exactly the inputs the function reads.
268
+ const productRuntime = useMemo(
269
+ () =>
270
+ contextRuntime
271
+ ? mergeProductRuntimes(contextRuntime, localProductRuntime, hasLocalRefs, hasLocalProvider)
272
+ : localProductRuntime,
273
+ [contextRuntime, localProductRuntime, hasLocalRefs, hasLocalProvider]
274
+ );
205
275
 
206
276
  return (
207
277
  <QueryClientProvider client={queryClient}>
@@ -1,9 +1,11 @@
1
1
  /**
2
- * AsyncStorage key derivation for the cached onboarding payload.
2
+ * AsyncStorage key derivation for the SDK's cached payloads (onboarding
3
+ * steps, paywall catalog).
3
4
  *
4
- * Lives in its own module so both `getOnboarding.query.ts` and
5
- * `OnboardingStudioClient` can use it as a value without a circular import
6
- * (the query module imports `OnboardingStudioClient` for typing).
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;