@rocapine/react-native-onboarding 1.75.0 → 1.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +16 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/onboarding-example.d.ts +140 -0
  6. package/dist/onboarding-example.d.ts.map +1 -1
  7. package/dist/onboarding-example.js +41 -1
  8. package/dist/onboarding-example.js.map +1 -1
  9. package/dist/paywalls/PaywallProvider.d.ts +71 -5
  10. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  11. package/dist/paywalls/PaywallProvider.js +237 -57
  12. package/dist/paywalls/PaywallProvider.js.map +1 -1
  13. package/dist/paywalls/customScreens.d.ts +31 -0
  14. package/dist/paywalls/customScreens.d.ts.map +1 -1
  15. package/dist/paywalls/observer.d.ts +129 -0
  16. package/dist/paywalls/observer.d.ts.map +1 -0
  17. package/dist/paywalls/observer.js +211 -0
  18. package/dist/paywalls/observer.js.map +1 -0
  19. package/dist/paywalls/present.d.ts +19 -15
  20. package/dist/paywalls/present.d.ts.map +1 -1
  21. package/dist/paywalls/present.js +21 -17
  22. package/dist/paywalls/present.js.map +1 -1
  23. package/dist/paywalls/types.d.ts +3 -1
  24. package/dist/paywalls/types.d.ts.map +1 -1
  25. package/dist/products/adapters/expoIap.d.ts +38 -1
  26. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  27. package/dist/products/adapters/expoIap.js +509 -75
  28. package/dist/products/adapters/expoIap.js.map +1 -1
  29. package/dist/products/index.d.ts +1 -0
  30. package/dist/products/index.d.ts.map +1 -1
  31. package/dist/products/index.js.map +1 -1
  32. package/dist/products/types.d.ts +13 -0
  33. package/dist/products/types.d.ts.map +1 -1
  34. package/dist/screens/completingActions.d.ts +55 -3
  35. package/dist/screens/completingActions.d.ts.map +1 -1
  36. package/dist/screens/completingActions.js +209 -15
  37. package/dist/screens/completingActions.js.map +1 -1
  38. package/dist/screens/elementTypeRegistry.d.ts +14 -0
  39. package/dist/screens/elementTypeRegistry.d.ts.map +1 -1
  40. package/dist/screens/elementTypeRegistry.js +38 -1
  41. package/dist/screens/elementTypeRegistry.js.map +1 -1
  42. package/dist/screens/elements/ButtonElement.d.ts +3 -2
  43. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  44. package/dist/screens/elements/ButtonElement.js +5 -1
  45. package/dist/screens/elements/ButtonElement.js.map +1 -1
  46. package/dist/screens/types.d.ts +2 -2
  47. package/dist/screens/types.d.ts.map +1 -1
  48. package/dist/screens/types.js +5 -1
  49. package/dist/screens/types.js.map +1 -1
  50. package/dist/screens/unknownKeys.d.ts +25 -4
  51. package/dist/screens/unknownKeys.d.ts.map +1 -1
  52. package/dist/screens/unknownKeys.js +81 -2
  53. package/dist/screens/unknownKeys.js.map +1 -1
  54. package/dist/steps/common.types.d.ts +178 -6
  55. package/dist/steps/common.types.d.ts.map +1 -1
  56. package/dist/steps/common.types.js +64 -3
  57. package/dist/steps/common.types.js.map +1 -1
  58. package/package.json +1 -1
  59. package/src/__tests__/authoringDocEscapes.test.ts +59 -0
  60. package/src/__tests__/completingActions.test.ts +371 -1
  61. package/src/__tests__/customActionHooks.test.ts +224 -0
  62. package/src/__tests__/onboardingExampleElements.test.ts +47 -0
  63. package/src/__tests__/requestPermissionAction.test.ts +138 -0
  64. package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
  65. package/src/__tests__/unknownKeys.test.ts +110 -0
  66. package/src/index.ts +33 -1
  67. package/src/onboarding-example.ts +41 -1
  68. package/src/paywalls/PaywallProvider.tsx +370 -66
  69. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
  70. package/src/paywalls/__tests__/observer.test.ts +401 -0
  71. package/src/paywalls/__tests__/present.test.ts +0 -18
  72. package/src/paywalls/customScreens.ts +34 -1
  73. package/src/paywalls/observer.ts +308 -0
  74. package/src/paywalls/present.ts +24 -18
  75. package/src/paywalls/types.ts +3 -1
  76. package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
  77. package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
  78. package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
  79. package/src/products/adapters/expoIap.ts +609 -78
  80. package/src/products/index.ts +1 -0
  81. package/src/products/types.ts +13 -0
  82. package/src/screens/completingActions.ts +223 -15
  83. package/src/screens/elementTypeRegistry.ts +34 -0
  84. package/src/screens/elements/ButtonElement.ts +9 -1
  85. package/src/screens/types.ts +2 -2
  86. package/src/screens/unknownKeys.ts +113 -7
  87. package/src/steps/common.types.ts +213 -6
@@ -147,30 +147,41 @@ describe("expoIapProductProvider — purchase", () => {
147
147
  const resolved = async (M: any) => (await expoIapProductProvider(M).getProducts([YEARLY]))[0];
148
148
 
149
149
  it("sends the per-platform request shape with the subscription type", async () => {
150
- // The old flat `{ request: { sku } }` reached neither platform branch, so
151
- // StoreKit received an undefined sku.
152
- const M = mock5({ requestPurchase: vi.fn().mockResolvedValue({ id: "tx" }) });
150
+ // `apple` / `google`, which is what `normalizeRequestProps` reads — on 5.x
151
+ // exclusively, and on 4.x in preference to the deprecated `ios` / `android`.
152
+ // This assertion previously named `ios` / `android`, so it passed while
153
+ // every real purchase was rejected with `empty-sku-list`; the behavioural
154
+ // proof now lives in expoIap.contract.test.ts, which cannot agree with a
155
+ // payload the store would refuse.
156
+ const M = mock5({ requestPurchase: vi.fn().mockResolvedValue({ id: "tx", productId: "pro_yearly" }) });
153
157
  const provider = expoIapProductProvider(M);
154
158
  const product = (await provider.getProducts([YEARLY]))[0];
155
159
  await provider.purchase(product);
156
160
  expect(M.requestPurchase).toHaveBeenCalledWith({
157
- request: { ios: { sku: "pro_yearly" }, android: { skus: ["pro_yearly"] } },
161
+ request: { apple: { sku: "pro_yearly" }, google: { skus: ["pro_yearly"] } },
158
162
  type: "subs",
159
163
  });
160
164
  });
161
165
 
162
166
  it("sends type in-app for a one-off product", async () => {
163
- const M = mock5({ requestPurchase: vi.fn().mockResolvedValue({ id: "tx" }) });
167
+ const M = mock5({
168
+ requestPurchase: vi.fn().mockResolvedValue({ id: "tx", productId: "pro_lifetime" }),
169
+ });
164
170
  const provider = expoIapProductProvider(M);
165
171
  const product = (await provider.getProducts([LIFETIME]))[0];
166
172
  await provider.purchase(product);
167
173
  expect(M.requestPurchase.mock.calls[0][0].type).toBe("in-app");
168
174
  });
169
175
 
170
- it("resolves pending — not purchased — when requestPurchase resolves null", async () => {
171
- // The normal 5.x outcome: the transaction arrives via purchaseUpdatedListener,
172
- // so nothing is confirmed yet. Reporting "purchased" granted access for a
173
- // purchase that may still fail.
176
+ it("resolves pending on a peer with no purchase listeners at all", async () => {
177
+ // `mock5` has no `purchaseUpdatedListener`, which is a peer too old to
178
+ // report an outcome. Nothing is confirmed, so "pending" is the only honest
179
+ // answer — and it is returned at once rather than after the timeout, since
180
+ // there is no event that could ever arrive.
181
+ //
182
+ // On a real 5.x peer this is NOT the normal path: the transaction lands on
183
+ // the listener and resolves "purchased". That is the #241 fix, proved in
184
+ // expoIap.contract.test.ts.
174
185
  const M = mock5({ requestPurchase: vi.fn().mockResolvedValue(null) });
175
186
  const provider = expoIapProductProvider(M);
176
187
  const product = (await provider.getProducts([YEARLY]))[0];
@@ -180,7 +191,10 @@ describe("expoIapProductProvider — purchase", () => {
180
191
 
181
192
  it("finishes the transaction when one comes back", async () => {
182
193
  // Unfinished transactions are re-delivered by StoreKit on every launch.
183
- const purchase = { id: "tx-1" };
194
+ // `productId` is not decoration: the directly-returned transaction goes
195
+ // through the same sku check as a delivered one, so a `Purchase` without it
196
+ // is not attributed to this call.
197
+ const purchase = { id: "tx-1", productId: "pro_yearly" };
184
198
  const M = mock5({ requestPurchase: vi.fn().mockResolvedValue(purchase) });
185
199
  const provider = expoIapProductProvider(M);
186
200
  const product = (await provider.getProducts([YEARLY]))[0];
@@ -191,7 +205,7 @@ describe("expoIapProductProvider — purchase", () => {
191
205
  it("still reports purchased when finishing throws", async () => {
192
206
  // A finish failure does not un-buy anything; it must not become an error.
193
207
  const M = mock5({
194
- requestPurchase: vi.fn().mockResolvedValue({ id: "tx-1" }),
208
+ requestPurchase: vi.fn().mockResolvedValue({ id: "tx-1", productId: "pro_yearly" }),
195
209
  finishTransaction: vi.fn().mockRejectedValue(new Error("finish failed")),
196
210
  });
197
211
  const provider = expoIapProductProvider(M);
@@ -0,0 +1,288 @@
1
+ /**
2
+ * A behavioural fake of expo-iap 5.x, transcribed from the INSTALLED package
3
+ * rather than written from the adapter's expectations.
4
+ *
5
+ * Why a fake instead of `expect(requestPurchase).toHaveBeenCalledWith(...)`:
6
+ * the hand-written expectation is what let #241 ship. The old suite asserted
7
+ * `{ request: { ios, android } }` was correct, so it passed while every real
8
+ * purchase threw — the test and the bug agreed with each other. A fake that
9
+ * *behaves* like the store cannot agree with a wrong payload: it rejects it,
10
+ * exactly as the device does.
11
+ *
12
+ * Provenance — expo-iap 5.3.2, `build/index.js`. Every rule below is a
13
+ * transcription of a line there, not an inference:
14
+ *
15
+ * :650-656 normalizeRequestProps() reads `request.apple` (ios) /
16
+ * `request.google` (android). No `ios`/`android` keys: 5.0 removed
17
+ * the deprecation shim that 4.x still had (4.7.2 `build/index.js`
18
+ * :666-674 warns and accepts them; 5.3.2 does not).
19
+ * :712-728 iOS with no `request.apple.sku` throws ErrorCode.EmptySkuList.
20
+ * :745-751 iOS resolves the native purchase when there is one, else `[]`
21
+ * for `subs` and `null` for `in-app`.
22
+ * :756-766 Android with no `request.google.skus[]` throws EmptySkuList.
23
+ * :453-477 fetchProducts() throws EmptySkuList on an empty `skus`, and
24
+ * filters the store's answer by `item.id ∈ new Set(skus)` — an id
25
+ * the store does not know simply does not come back.
26
+ * :676-679 "The result is delivered through `purchaseUpdatedListener` — NOT
27
+ * the return value."
28
+ * :145-176 purchaseUpdatedListener's iOS DEDUPE — see below, it is the whole
29
+ * reason this fake exists in its current form.
30
+ * :195-200 purchaseErrorListener forwards the event verbatim: no product
31
+ * filtering of any kind, so attribution is the caller's problem.
32
+ * :886-899 restorePurchases() syncs and refreshes, and returns nothing.
33
+ * types.js:41 ErrorCode.UserCancelled === "user-cancelled" — kebab-case,
34
+ * and PurchaseError carries no `userCancelled` boolean.
35
+ *
36
+ * ## The dedupe, which the first version of this fake got wrong
37
+ *
38
+ * That version modelled listeners as plain push/splice. Real 5.3.2 keeps a
39
+ * **process-wide** history of iOS transaction ids and seeds every NEW listener
40
+ * from it:
41
+ *
42
+ * const listenerDedupeHistoryIOS = {
43
+ * ids: new Set(purchaseUpdatedDedupeHistoryIOS.ids), // :148
44
+ * ...
45
+ * };
46
+ * // on each event, recorded into BOTH (:163-164):
47
+ * rememberPurchaseUpdatedTransactionIOS(transactionId, listenerDedupeHistoryIOS);
48
+ * rememberPurchaseUpdatedTransactionIOS(transactionId, purchaseUpdatedDedupeHistoryIOS);
49
+ * if (!receiveDuplicateTransactionUpdatesIOS && isDuplicateForListener) return; // :165-167
50
+ *
51
+ * So a listener subscribed *after* a transaction has been seen anywhere in the
52
+ * process — by the host's own `useIAP`, for instance — never receives it.
53
+ * Modelling this without the dedupe made a subscribe-per-Buy-tap adapter look
54
+ * correct. It is iOS-only (`if (Platform.OS === 'ios')`, :155), and the global
55
+ * history is cleared only by a successful `endConnection`.
56
+ *
57
+ * Two other divergences were checked and left unmodelled on purpose, because
58
+ * nothing in this adapter can reach them: `validateAndroidPurchaseBranchOptions`
59
+ * (the adapter never sends subscription-only fields on an `in-app` request) and
60
+ * the `isProductIOS`/`isProductAndroid` platform filter inside `fetchProducts`
61
+ * (the catalogs here are single-platform).
62
+ *
63
+ * Deliberately NOT modelled: Play's requirement that a subscription purchase
64
+ * carry an `offerToken`. That rule lives in openiap-google's native layer, and
65
+ * this run could not verify which error code surfaces — so the suite asserts
66
+ * the payload the adapter sends instead of a failure it invented.
67
+ */
68
+
69
+ export type FakePurchase = {
70
+ id: string;
71
+ productId: string;
72
+ purchaseState?: "purchased" | "pending" | "unknown";
73
+ purchaseToken?: string;
74
+ ids?: string[];
75
+ };
76
+
77
+ export type FakeOptions = {
78
+ /** Products the store knows, keyed by the bare id it would report. */
79
+ catalog?: any[];
80
+ /**
81
+ * Which platform branch the store is running. Read lazily, so one fake can
82
+ * serve a suite that flips `Platform.OS` between tests.
83
+ */
84
+ platform?: () => "ios" | "android";
85
+ /**
86
+ * What the store does when a purchase is dispatched. Default: deliver a
87
+ * purchased transaction through purchaseUpdatedListener — the normal 5.x
88
+ * outcome. Return `null` to model a store that emits nothing yet.
89
+ */
90
+ onDispatch?: (sku: string, type: string) => FakePurchase | { error: any } | null;
91
+ /** What `getAvailablePurchases` reports — unfinished purchases included. */
92
+ purchases?: FakePurchase[];
93
+ /** Stand in for a store that answers the product query with `null`. */
94
+ fetchProductsResult?: null;
95
+ /** Make `finishTransaction` throw, to exercise the retry path. */
96
+ finishFails?: () => boolean;
97
+ };
98
+
99
+ const err = (code: string, message: string) => Object.assign(new Error(message), { code });
100
+
101
+ export const makeExpoIap5 = (options: FakeOptions = {}) => {
102
+ const catalog = options.catalog ?? [];
103
+ const platformOf = () => options.platform?.() ?? "ios";
104
+
105
+ // The process-wide dedupe history (`purchaseUpdatedDedupeHistoryIOS`).
106
+ const globalSeenIOS = new Set<string>();
107
+
108
+ type Registered = { listener: (p: FakePurchase) => void; seen: Set<string> };
109
+ const updatedListeners: Registered[] = [];
110
+ const errorListeners: ((e: any) => void)[] = [];
111
+
112
+ const calls = {
113
+ initConnection: 0,
114
+ endConnection: 0,
115
+ restorePurchases: 0,
116
+ requestPurchase: [] as any[],
117
+ fetchProducts: [] as any[],
118
+ finishTransaction: [] as any[],
119
+ /** Subscriptions taken out minus subscriptions removed. */
120
+ liveListeners: 0,
121
+ /** How many times purchaseUpdatedListener was ever called. */
122
+ updatedSubscribes: 0,
123
+ };
124
+
125
+ let prepared = false;
126
+ // A real store issues a NEW transaction id per purchase, and the dedupe above
127
+ // makes that load-bearing: reusing one id would make the second Buy tap look
128
+ // like a duplicate and be dropped.
129
+ let txSeq = 0;
130
+
131
+ const api = {
132
+ calls,
133
+ /** Force the "another useIAP unmounted" case the adapter has to survive. */
134
+ dropConnection() {
135
+ prepared = false;
136
+ },
137
+ /**
138
+ * Attach a listener that is not the adapter's — the host's own `useIAP`.
139
+ * Its only job in a test is to populate the process-wide dedupe history.
140
+ */
141
+ attachForeignListener() {
142
+ return api.purchaseUpdatedListener(() => {});
143
+ },
144
+ emitUpdated(p: FakePurchase) {
145
+ // :153-171, in order: check this listener's own history, record into both
146
+ // it and the global, then drop if it was already there for THIS listener.
147
+ for (const reg of [...updatedListeners]) {
148
+ if (platformOf() === "ios") {
149
+ const tx = typeof p.id === "string" && p.id ? p.id : null;
150
+ if (tx != null) {
151
+ const duplicateForListener = reg.seen.has(tx);
152
+ reg.seen.add(tx);
153
+ globalSeenIOS.add(tx);
154
+ if (duplicateForListener) continue;
155
+ }
156
+ }
157
+ reg.listener(p);
158
+ }
159
+ },
160
+ emitError(e: any) {
161
+ errorListeners.forEach((l) => l(e));
162
+ },
163
+
164
+ async initConnection() {
165
+ calls.initConnection += 1;
166
+ prepared = true;
167
+ return true;
168
+ },
169
+ async endConnection() {
170
+ calls.endConnection += 1;
171
+ prepared = false;
172
+ globalSeenIOS.clear(); // :568-571
173
+ return true;
174
+ },
175
+
176
+ purchaseUpdatedListener(listener: (p: FakePurchase) => void) {
177
+ // :147-151 — seeded from the PROCESS-WIDE set, not from nothing.
178
+ const reg: Registered = { listener, seen: new Set(globalSeenIOS) };
179
+ updatedListeners.push(reg);
180
+ calls.liveListeners += 1;
181
+ calls.updatedSubscribes += 1;
182
+ return {
183
+ remove() {
184
+ const i = updatedListeners.indexOf(reg);
185
+ if (i >= 0) updatedListeners.splice(i, 1);
186
+ calls.liveListeners -= 1;
187
+ },
188
+ };
189
+ },
190
+ purchaseErrorListener(listener: (e: any) => void) {
191
+ errorListeners.push(listener);
192
+ calls.liveListeners += 1;
193
+ return {
194
+ remove() {
195
+ const i = errorListeners.indexOf(listener);
196
+ if (i >= 0) errorListeners.splice(i, 1);
197
+ calls.liveListeners -= 1;
198
+ },
199
+ };
200
+ },
201
+
202
+ // :453-477
203
+ async fetchProducts(request: { skus?: string[]; type?: string }) {
204
+ calls.fetchProducts.push(request);
205
+ const skus = request?.skus;
206
+ if (!Array.isArray(skus) || skus.length === 0) {
207
+ throw err("empty-sku-list", "No SKUs provided");
208
+ }
209
+ if (!prepared) throw err("not-prepared", "IAP not prepared");
210
+ // FetchProductsResult is `Product[] | ... | null` (types.d.ts:527).
211
+ if ("fetchProductsResult" in options && options.fetchProductsResult === null) return null;
212
+ const wanted = new Set(skus);
213
+ return catalog.filter((p) => wanted.has(p.id));
214
+ },
215
+
216
+ // :702-830
217
+ async requestPurchase(args: any) {
218
+ calls.requestPurchase.push(args);
219
+ if (!prepared) throw err("not-prepared", "IAP not prepared");
220
+ const { request, type } = args ?? {};
221
+ if (type === "all") {
222
+ throw err("developer-error", "Product type all is only supported for product queries.");
223
+ }
224
+
225
+ let sku: string;
226
+ if (platformOf() === "ios") {
227
+ const apple = request?.apple; // :652
228
+ if (!apple?.sku) {
229
+ throw err(
230
+ "empty-sku-list",
231
+ "Invalid request for Apple. The `sku` property is required and must be a string."
232
+ );
233
+ }
234
+ sku = apple.sku;
235
+ } else {
236
+ const google = request?.google; // :655
237
+ if (!google?.skus?.length) {
238
+ throw err(
239
+ "empty-sku-list",
240
+ "Invalid request for Google. The `skus` property is required and must be a non-empty array."
241
+ );
242
+ }
243
+ sku = google.skus[0];
244
+ }
245
+
246
+ const outcome = options.onDispatch
247
+ ? options.onDispatch(sku, type)
248
+ : ({
249
+ id: `tx-${sku}-${(txSeq += 1)}`,
250
+ productId: sku,
251
+ purchaseState: "purchased",
252
+ } as FakePurchase);
253
+
254
+ // The store answers on its own turn of the event loop, never inside the
255
+ // dispatch call — which is why an adapter reading the return value sees
256
+ // nothing. :676-679
257
+ if (outcome && "error" in outcome) {
258
+ setTimeout(() => api.emitError(outcome.error), 0);
259
+ } else if (outcome) {
260
+ setTimeout(() => api.emitUpdated(outcome), 0);
261
+ }
262
+
263
+ // :745-751 — nothing useful comes back on the normal path.
264
+ return type === "subs" ? [] : null;
265
+ },
266
+
267
+ async finishTransaction(args: { purchase: any; isConsumable?: boolean }) {
268
+ calls.finishTransaction.push(args);
269
+ if (!args?.purchase) throw err("developer-error", "purchase is required");
270
+ if (options.finishFails?.()) throw err("network-error", "could not finish");
271
+ return undefined;
272
+ },
273
+
274
+ // :886-899 — syncs, then refreshes, and returns nothing itself.
275
+ async restorePurchases() {
276
+ calls.restorePurchases += 1;
277
+ if (!prepared) throw err("not-prepared", "IAP not prepared");
278
+ return undefined;
279
+ },
280
+
281
+ async getAvailablePurchases(): Promise<FakePurchase[]> {
282
+ if (!prepared) throw err("not-prepared", "IAP not prepared");
283
+ return options.purchases ?? [];
284
+ },
285
+ };
286
+
287
+ return api;
288
+ };