@rocapine/react-native-onboarding 1.74.1 → 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 (105) hide show
  1. package/dist/evaluateCondition.d.ts.map +1 -1
  2. package/dist/evaluateCondition.js +103 -4
  3. package/dist/evaluateCondition.js.map +1 -1
  4. package/dist/index.d.ts +10 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +39 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/onboarding-example.d.ts +375 -99
  9. package/dist/onboarding-example.d.ts.map +1 -1
  10. package/dist/onboarding-example.js +118 -1
  11. package/dist/onboarding-example.js.map +1 -1
  12. package/dist/paywalls/PaywallProvider.d.ts +71 -5
  13. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  14. package/dist/paywalls/PaywallProvider.js +237 -57
  15. package/dist/paywalls/PaywallProvider.js.map +1 -1
  16. package/dist/paywalls/customScreens.d.ts +31 -0
  17. package/dist/paywalls/customScreens.d.ts.map +1 -1
  18. package/dist/paywalls/observer.d.ts +129 -0
  19. package/dist/paywalls/observer.d.ts.map +1 -0
  20. package/dist/paywalls/observer.js +211 -0
  21. package/dist/paywalls/observer.js.map +1 -0
  22. package/dist/paywalls/present.d.ts +19 -15
  23. package/dist/paywalls/present.d.ts.map +1 -1
  24. package/dist/paywalls/present.js +21 -17
  25. package/dist/paywalls/present.js.map +1 -1
  26. package/dist/paywalls/types.d.ts +3 -1
  27. package/dist/paywalls/types.d.ts.map +1 -1
  28. package/dist/products/adapters/expoIap.d.ts +38 -1
  29. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  30. package/dist/products/adapters/expoIap.js +509 -75
  31. package/dist/products/adapters/expoIap.js.map +1 -1
  32. package/dist/products/index.d.ts +1 -0
  33. package/dist/products/index.d.ts.map +1 -1
  34. package/dist/products/index.js.map +1 -1
  35. package/dist/products/types.d.ts +13 -0
  36. package/dist/products/types.d.ts.map +1 -1
  37. package/dist/screens/completingActions.d.ts +95 -0
  38. package/dist/screens/completingActions.d.ts.map +1 -0
  39. package/dist/screens/completingActions.js +302 -0
  40. package/dist/screens/completingActions.js.map +1 -0
  41. package/dist/screens/elementTypeRegistry.d.ts +45 -0
  42. package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
  43. package/dist/screens/elementTypeRegistry.js +119 -0
  44. package/dist/screens/elementTypeRegistry.js.map +1 -0
  45. package/dist/screens/elements/ButtonElement.d.ts +3 -2
  46. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  47. package/dist/screens/elements/ButtonElement.js +5 -1
  48. package/dist/screens/elements/ButtonElement.js.map +1 -1
  49. package/dist/screens/resolveRenderableStep.d.ts +42 -0
  50. package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
  51. package/dist/screens/resolveRenderableStep.js +28 -0
  52. package/dist/screens/resolveRenderableStep.js.map +1 -0
  53. package/dist/screens/types.d.ts +2 -2
  54. package/dist/screens/types.d.ts.map +1 -1
  55. package/dist/screens/types.js +5 -1
  56. package/dist/screens/types.js.map +1 -1
  57. package/dist/screens/unknownElementTypes.d.ts +94 -0
  58. package/dist/screens/unknownElementTypes.d.ts.map +1 -0
  59. package/dist/screens/unknownElementTypes.js +141 -0
  60. package/dist/screens/unknownElementTypes.js.map +1 -0
  61. package/dist/screens/unknownKeys.d.ts +30 -6
  62. package/dist/screens/unknownKeys.d.ts.map +1 -1
  63. package/dist/screens/unknownKeys.js +88 -54
  64. package/dist/screens/unknownKeys.js.map +1 -1
  65. package/dist/steps/common.types.d.ts +262 -9
  66. package/dist/steps/common.types.d.ts.map +1 -1
  67. package/dist/steps/common.types.js +64 -3
  68. package/dist/steps/common.types.js.map +1 -1
  69. package/package.json +1 -1
  70. package/src/__tests__/authoringDocEscapes.test.ts +59 -0
  71. package/src/__tests__/completingActions.test.ts +509 -0
  72. package/src/__tests__/customActionHooks.test.ts +224 -0
  73. package/src/__tests__/elementTypeRegistry.test.ts +48 -0
  74. package/src/__tests__/evaluateCondition.test.ts +228 -3
  75. package/src/__tests__/onboardingExampleElements.test.ts +74 -0
  76. package/src/__tests__/requestPermissionAction.test.ts +138 -0
  77. package/src/__tests__/resolveRenderableStep.test.ts +117 -0
  78. package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
  79. package/src/__tests__/unknownElementTypes.test.ts +240 -0
  80. package/src/__tests__/unknownKeys.test.ts +110 -0
  81. package/src/evaluateCondition.ts +107 -4
  82. package/src/index.ts +55 -0
  83. package/src/onboarding-example.ts +119 -1
  84. package/src/paywalls/PaywallProvider.tsx +370 -66
  85. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
  86. package/src/paywalls/__tests__/observer.test.ts +401 -0
  87. package/src/paywalls/__tests__/present.test.ts +0 -18
  88. package/src/paywalls/customScreens.ts +34 -1
  89. package/src/paywalls/observer.ts +308 -0
  90. package/src/paywalls/present.ts +24 -18
  91. package/src/paywalls/types.ts +3 -1
  92. package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
  93. package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
  94. package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
  95. package/src/products/adapters/expoIap.ts +609 -78
  96. package/src/products/index.ts +1 -0
  97. package/src/products/types.ts +13 -0
  98. package/src/screens/completingActions.ts +316 -0
  99. package/src/screens/elementTypeRegistry.ts +122 -0
  100. package/src/screens/elements/ButtonElement.ts +9 -1
  101. package/src/screens/resolveRenderableStep.ts +59 -0
  102. package/src/screens/types.ts +2 -2
  103. package/src/screens/unknownElementTypes.ts +204 -0
  104. package/src/screens/unknownKeys.ts +119 -56
  105. package/src/steps/common.types.ts +297 -9
@@ -0,0 +1,401 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import {
3
+ openPaywallPresentation,
4
+ sanitizePaywallTransaction,
5
+ type PaywallObserver,
6
+ type PaywallPresentationSource,
7
+ } from "../observer";
8
+
9
+ const PAYWALL: PaywallPresentationSource = {
10
+ id: "pw-1",
11
+ moment: "onboarding_end",
12
+ audienceId: 42,
13
+ billing: "store",
14
+ products: [
15
+ { key: "annual", ios: "com.app.annual.ios", android: "com.app.annual.android" },
16
+ { key: "monthly", ios: "com.app.monthly" },
17
+ ],
18
+ };
19
+
20
+ const recordingObserver = () => {
21
+ const calls: Array<[string, unknown?]> = [];
22
+ const observer: PaywallObserver = {
23
+ start: (info) => {
24
+ calls.push(["start", info]);
25
+ return {
26
+ shown: () => void calls.push(["shown"]),
27
+ end: (outcome) => void calls.push(["end", outcome]),
28
+ };
29
+ },
30
+ };
31
+ return { observer, calls };
32
+ };
33
+
34
+ beforeEach(() => {
35
+ vi.spyOn(console, "warn").mockImplementation(() => {});
36
+ });
37
+ afterEach(() => {
38
+ vi.restoreAllMocks();
39
+ });
40
+
41
+ describe("openPaywallPresentation — the info handed to start()", () => {
42
+ it("stringifies audienceId, defaults renderMode to elements, and names the surface", () => {
43
+ const { observer, calls } = recordingObserver();
44
+ openPaywallPresentation(observer, PAYWALL, "present", "ios");
45
+ expect(calls).toEqual([
46
+ [
47
+ "start",
48
+ {
49
+ moment: "onboarding_end",
50
+ paywallId: "pw-1",
51
+ audienceId: "42",
52
+ renderMode: "elements",
53
+ billing: "store",
54
+ surface: "present",
55
+ },
56
+ ],
57
+ ]);
58
+ // variantKey, deploymentId and onboardingRun stay UNSET, not undefined-valued.
59
+ const info = calls[0][1] as Record<string, unknown>;
60
+ expect(Object.keys(info)).not.toContain("variantKey");
61
+ expect(Object.keys(info)).not.toContain("deploymentId");
62
+ expect(Object.keys(info)).not.toContain("onboardingRun");
63
+ });
64
+
65
+ it("keeps a null audienceId null, passes renderMode custom through, and defaults a missing billing to store", () => {
66
+ const { observer, calls } = recordingObserver();
67
+ openPaywallPresentation(
68
+ observer,
69
+ { id: "pw-2", moment: "m", audienceId: null, renderMode: "custom" },
70
+ "paywall_step",
71
+ "android"
72
+ );
73
+ expect(calls[0][1]).toMatchObject({
74
+ audienceId: null,
75
+ renderMode: "custom",
76
+ billing: "store",
77
+ surface: "paywall_step",
78
+ });
79
+ });
80
+ });
81
+
82
+ describe("openPaywallPresentation — once-guards", () => {
83
+ it("calls end() exactly once, however often it is asked", () => {
84
+ const { observer, calls } = recordingObserver();
85
+ const p = openPaywallPresentation(observer, PAYWALL, "present", "ios");
86
+ p.end({ status: "dismissed" });
87
+ p.end({ status: "error", reason: "render-error" });
88
+ p.end({ status: "purchased" }, "annual");
89
+ expect(calls.filter(([n]) => n === "end")).toEqual([["end", { status: "dismissed" }]]);
90
+ });
91
+
92
+ it("calls shown() at most once, and never after end()", () => {
93
+ const { observer, calls } = recordingObserver();
94
+ const p = openPaywallPresentation(observer, PAYWALL, "present", "ios");
95
+ p.shown();
96
+ p.shown();
97
+ expect(calls.filter(([n]) => n === "shown")).toHaveLength(1);
98
+
99
+ const { observer: o2, calls: c2 } = recordingObserver();
100
+ const q = openPaywallPresentation(o2, PAYWALL, "present", "ios");
101
+ q.end({ status: "dismissed" });
102
+ q.shown();
103
+ expect(c2.map(([n]) => n)).toEqual(["start", "end"]);
104
+ });
105
+ });
106
+
107
+ describe("openPaywallPresentation — the outcome handed to end()", () => {
108
+ it("forwards an error reason as a string and sends no transaction", () => {
109
+ const { observer, calls } = recordingObserver();
110
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({
111
+ status: "error",
112
+ reason: "host-never-presented",
113
+ });
114
+ expect(calls[1]).toEqual(["end", { status: "error", reason: "host-never-presented" }]);
115
+ });
116
+
117
+ it("resolves a purchase's productId from the purchased slot for the running platform", () => {
118
+ const ios = recordingObserver();
119
+ openPaywallPresentation(ios.observer, PAYWALL, "present", "ios").end({ status: "purchased" }, "annual");
120
+ expect(ios.calls[1]).toEqual([
121
+ "end",
122
+ { status: "purchased", transaction: { productId: "com.app.annual.ios" } },
123
+ ]);
124
+
125
+ const android = recordingObserver();
126
+ openPaywallPresentation(android.observer, PAYWALL, "present", "android").end(
127
+ { status: "purchased" },
128
+ "annual"
129
+ );
130
+ expect(android.calls[1]).toEqual([
131
+ "end",
132
+ { status: "purchased", transaction: { productId: "com.app.annual.android" } },
133
+ ]);
134
+ });
135
+
136
+ it("resolves productId against the paywall the purchase was made on, when it differs from the one started", () => {
137
+ // A variant swap keeps one presentation (started on PAYWALL) but the user
138
+ // bought on the variant shown after it, whose slot has its own store id.
139
+ const swapped: PaywallPresentationSource = {
140
+ ...PAYWALL,
141
+ id: "pw-2",
142
+ products: [{ key: "annual", ios: "com.app.annual.b" }],
143
+ };
144
+ const { observer, calls } = recordingObserver();
145
+ openPaywallPresentation(observer, PAYWALL, "paywall_step", "ios").end(
146
+ { status: "purchased" },
147
+ "annual",
148
+ swapped
149
+ );
150
+ expect(calls[0]).toEqual(["start", expect.objectContaining({ paywallId: "pw-1" })]);
151
+ expect(calls[1]).toEqual(["end", { status: "purchased", transaction: { productId: "com.app.annual.b" } }]);
152
+ });
153
+
154
+ it("omits transaction entirely when no id resolves (unknown key, empty platform slot, web, no key)", () => {
155
+ for (const [key, platform] of [
156
+ ["nope", "ios"],
157
+ ["monthly", "android"],
158
+ ["annual", "web"],
159
+ [undefined, "ios"],
160
+ ] as const) {
161
+ const { observer, calls } = recordingObserver();
162
+ openPaywallPresentation(observer, PAYWALL, "present", platform).end({ status: "purchased" }, key);
163
+ expect(calls[1]).toEqual(["end", { status: "purchased" }]);
164
+ }
165
+ });
166
+
167
+ it("never sends a transaction with a status other than purchased", () => {
168
+ const { observer, calls } = recordingObserver();
169
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status: "cancelled" }, "annual");
170
+ expect(calls[1]).toEqual(["end", { status: "cancelled" }]);
171
+ });
172
+ });
173
+
174
+ describe("openPaywallPresentation — a hostile observer cannot hurt the caller", () => {
175
+ it("is a silent no-op with no observer at all", () => {
176
+ const p = openPaywallPresentation(undefined, PAYWALL, "present", "ios");
177
+ expect(() => {
178
+ p.shown();
179
+ p.end({ status: "dismissed" });
180
+ }).not.toThrow();
181
+ });
182
+
183
+ it("accepts a start() that returns void, or a non-handle", () => {
184
+ for (const returned of [undefined, null, 42, "x", {}, { shown: 1, end: 2 }]) {
185
+ const observer = { start: () => returned } as unknown as PaywallObserver;
186
+ const p = openPaywallPresentation(observer, PAYWALL, "present", "ios");
187
+ expect(() => {
188
+ p.shown();
189
+ p.end({ status: "dismissed" });
190
+ }).not.toThrow();
191
+ }
192
+ });
193
+
194
+ it("swallows a throw from start(), shown() and end()", () => {
195
+ const boom = () => {
196
+ throw new Error("observer bug");
197
+ };
198
+ const throwingStart = { start: boom } as unknown as PaywallObserver;
199
+ expect(() => openPaywallPresentation(throwingStart, PAYWALL, "present", "ios")).not.toThrow();
200
+
201
+ const throwingHandle: PaywallObserver = { start: () => ({ shown: boom, end: boom }) };
202
+ const p = openPaywallPresentation(throwingHandle, PAYWALL, "present", "ios");
203
+ expect(() => {
204
+ p.shown();
205
+ p.end({ status: "dismissed" });
206
+ }).not.toThrow();
207
+ expect(console.warn).toHaveBeenCalled();
208
+ });
209
+
210
+ it("tolerates an observer that is not an object, or whose start is not a function", () => {
211
+ for (const observer of [42, "x", {}, { start: "nope" }]) {
212
+ expect(() =>
213
+ openPaywallPresentation(observer as unknown as PaywallObserver, PAYWALL, "present", "ios").end({
214
+ status: "dismissed",
215
+ })
216
+ ).not.toThrow();
217
+ }
218
+ });
219
+
220
+ it("swallows a rejected promise returned by an async observer", async () => {
221
+ const unhandled = vi.fn();
222
+ process.on("unhandledRejection", unhandled);
223
+ try {
224
+ const observer = {
225
+ start: () => ({
226
+ shown: () => Promise.reject(new Error("async shown")),
227
+ end: () => Promise.reject(new Error("async end")),
228
+ }),
229
+ } as unknown as PaywallObserver;
230
+ const p = openPaywallPresentation(observer, PAYWALL, "present", "ios");
231
+ p.shown();
232
+ p.end({ status: "dismissed" });
233
+ await new Promise((r) => setTimeout(r, 10));
234
+ expect(unhandled).not.toHaveBeenCalled();
235
+ } finally {
236
+ process.off("unhandledRejection", unhandled);
237
+ }
238
+ });
239
+ });
240
+
241
+ describe("sanitizePaywallTransaction — what a custom screen may report (#287)", () => {
242
+ it("keeps non-empty string ids and restored: true", () => {
243
+ expect(
244
+ sanitizePaywallTransaction({
245
+ originalTransactionIdentifier: "2000000123",
246
+ purchaseToken: "tok",
247
+ productId: "com.app.annual.ios",
248
+ restored: true,
249
+ })
250
+ ).toEqual({
251
+ originalTransactionIdentifier: "2000000123",
252
+ purchaseToken: "tok",
253
+ productId: "com.app.annual.ios",
254
+ restored: true,
255
+ });
256
+ });
257
+
258
+ it("drops non-string and empty ids, a restored that is not true, and unknown fields", () => {
259
+ expect(
260
+ sanitizePaywallTransaction({
261
+ originalTransactionIdentifier: 2000000123,
262
+ purchaseToken: "",
263
+ productId: "com.app.annual.ios",
264
+ restored: "true",
265
+ price: 9.99,
266
+ })
267
+ ).toEqual({ productId: "com.app.annual.ios" });
268
+ expect(sanitizePaywallTransaction({ productId: "p", restored: false })).toEqual({ productId: "p" });
269
+ expect(sanitizePaywallTransaction({ productId: "p", restored: 1 })).toEqual({ productId: "p" });
270
+ });
271
+
272
+ it("returns undefined for a non-object, an array, or an object with nothing left", () => {
273
+ for (const value of [undefined, null, "tx", 42, true, ["a"], {}, { productId: "" }, { restored: false }]) {
274
+ expect(sanitizePaywallTransaction(value)).toBeUndefined();
275
+ }
276
+ });
277
+ });
278
+
279
+ describe("openPaywallPresentation — a transaction reported by a custom screen (#287)", () => {
280
+ const reported = { originalTransactionIdentifier: "2000000123", productId: "com.app.annual.ios" };
281
+
282
+ it("forwards it, sanitized, with a purchased end", () => {
283
+ const { observer, calls } = recordingObserver();
284
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status: "purchased" }, null, null, {
285
+ ...reported,
286
+ restored: "yes",
287
+ extra: 1,
288
+ });
289
+ expect(calls[1]).toEqual(["end", { status: "purchased", transaction: reported }]);
290
+ });
291
+
292
+ it("never forwards it with an end other than purchased", () => {
293
+ for (const status of ["dismissed", "cancelled", "error"] as const) {
294
+ const { observer, calls } = recordingObserver();
295
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status }, null, null, reported);
296
+ expect(calls[1]).toEqual(["end", { status }]);
297
+ }
298
+ });
299
+
300
+ it("omits transaction entirely when nothing survives sanitizing", () => {
301
+ const { observer, calls } = recordingObserver();
302
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status: "purchased" }, null, null, {
303
+ productId: 1,
304
+ });
305
+ expect(calls[1]).toEqual(["end", { status: "purchased" }]);
306
+ });
307
+
308
+ it("with a recorded purchase, adds the reported ids only when the reported productId is present and equal", () => {
309
+ const { observer, calls } = recordingObserver();
310
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status: "purchased" }, "annual", null, {
311
+ originalTransactionIdentifier: "2000000123",
312
+ productId: "com.app.annual.ios",
313
+ });
314
+ expect(calls[1]).toEqual([
315
+ "end",
316
+ { status: "purchased", transaction: { originalTransactionIdentifier: "2000000123", productId: "com.app.annual.ios" } },
317
+ ]);
318
+ expect(console.warn).not.toHaveBeenCalled();
319
+ });
320
+
321
+ it("with a recorded purchase, drops reported ids that name no productId, with a warning", () => {
322
+ const { observer, calls } = recordingObserver();
323
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status: "purchased" }, "annual", null, {
324
+ originalTransactionIdentifier: "2000000123",
325
+ });
326
+ expect(calls[1]).toEqual(["end", { status: "purchased", transaction: { productId: "com.app.annual.ios" } }]);
327
+ expect(console.warn).toHaveBeenCalledTimes(1);
328
+ });
329
+
330
+ it("never merges restored onto a recorded purchase, even for the same product", () => {
331
+ const { observer, calls } = recordingObserver();
332
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status: "purchased" }, "annual", null, {
333
+ originalTransactionIdentifier: "2000000123",
334
+ productId: "com.app.annual.ios",
335
+ restored: true,
336
+ });
337
+ expect(calls[1]).toEqual([
338
+ "end",
339
+ { status: "purchased", transaction: { originalTransactionIdentifier: "2000000123", productId: "com.app.annual.ios" } },
340
+ ]);
341
+ expect(console.warn).toHaveBeenCalledTimes(1);
342
+ });
343
+
344
+ it("with a recorded purchase that resolves no store id here, drops the reported ids rather than replace it", () => {
345
+ for (const reportedTx of [{ originalTransactionIdentifier: "2000000123" }, { productId: "com.app.other" }]) {
346
+ vi.mocked(console.warn).mockClear();
347
+ const { observer, calls } = recordingObserver();
348
+ // `monthly` has no android id: a purchase is recorded, but names nothing on this platform.
349
+ openPaywallPresentation(observer, PAYWALL, "present", "android").end(
350
+ { status: "purchased" },
351
+ "monthly",
352
+ null,
353
+ reportedTx
354
+ );
355
+ expect(calls[1]).toEqual(["end", { status: "purchased" }]);
356
+ expect(console.warn).toHaveBeenCalledTimes(1);
357
+ }
358
+ });
359
+
360
+ it("with a recorded purchase of a DIFFERENT product, keeps the recorded one alone and drops the reported ids", () => {
361
+ const { observer, calls } = recordingObserver();
362
+ openPaywallPresentation(observer, PAYWALL, "present", "ios").end({ status: "purchased" }, "annual", null, {
363
+ originalTransactionIdentifier: "2000000123",
364
+ productId: "com.app.monthly",
365
+ });
366
+ expect(calls[1]).toEqual(["end", { status: "purchased", transaction: { productId: "com.app.annual.ios" } }]);
367
+ expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("com.app.monthly"));
368
+ });
369
+ });
370
+
371
+ describe("openPaywallPresentation — a hostile reported transaction costs only the transaction (#287 round 2)", () => {
372
+ const hostile = () => {
373
+ const revocable = Proxy.revocable({}, {});
374
+ revocable.revoke();
375
+ return [
376
+ revocable.proxy,
377
+ Object.defineProperty({}, "originalTransactionIdentifier", {
378
+ enumerable: true,
379
+ get() {
380
+ throw new Error("getter bug");
381
+ },
382
+ }),
383
+ ];
384
+ };
385
+
386
+ it("sanitizes a throwing getter or a revoked proxy to undefined", () => {
387
+ for (const value of hostile()) expect(sanitizePaywallTransaction(value)).toBeUndefined();
388
+ });
389
+
390
+ it("still reaches the observer exactly once, without a transaction", () => {
391
+ for (const value of hostile()) {
392
+ const { observer, calls } = recordingObserver();
393
+ const p = openPaywallPresentation(observer, PAYWALL, "present", "ios");
394
+ expect(() => p.end({ status: "purchased" }, "annual", null, value)).not.toThrow();
395
+ p.end({ status: "dismissed" });
396
+ expect(calls.slice(1)).toEqual([
397
+ ["end", { status: "purchased", transaction: { productId: "com.app.annual.ios" } }],
398
+ ]);
399
+ }
400
+ });
401
+ });
@@ -8,7 +8,6 @@ import {
8
8
  resolvePresentedOutcome,
9
9
  selectActiveProductRuntime,
10
10
  shouldBreakPresentationWedge,
11
- shouldRecordPurchaseOutcome,
12
11
  } from "../present";
13
12
  import type { Paywall, PaywallCatalog } from "../types";
14
13
  import type { ProductRuntime, PurchaseResult } from "../../products/types";
@@ -254,23 +253,6 @@ describe("resolvePresentedOutcome", () => {
254
253
  });
255
254
  });
256
255
 
257
- describe("shouldRecordPurchaseOutcome", () => {
258
- it("records when the presentation is still the one the purchase started in", () => {
259
- expect(shouldRecordPurchaseOutcome(1, 1)).toBe(true);
260
- });
261
-
262
- it("does NOT record when a newer presentation has started since the purchase began — the race this guards against", () => {
263
- // Paywall A's purchase() captured generation 1; the user dismissed A and
264
- // paywall B was presented (generation bumped to 2) before A's promise
265
- // settled. A's write must not land in B's tracker.
266
- expect(shouldRecordPurchaseOutcome(1, 2)).toBe(false);
267
- });
268
-
269
- it("does NOT record for a generation older than the current one by more than one step either", () => {
270
- expect(shouldRecordPurchaseOutcome(1, 5)).toBe(false);
271
- });
272
- });
273
-
274
256
  describe("computeCatalogStatus", () => {
275
257
  const catalog = makeCatalog([makePaywall({ id: "1", moment: "hard_paywall" })]);
276
258
 
@@ -1,4 +1,5 @@
1
1
  import type { ComponentType } from "react";
2
+ import type { PaywallTransactionInfo } from "./observer";
2
3
  import type { PaywallCustomPayload } from "./types";
3
4
 
4
5
  /**
@@ -50,8 +51,40 @@ export type CustomPaywallScreenProps = {
50
51
  * resolves pending, which means UNCONFIRMED. `PresentResult` describes how a
51
52
  * paywall CLOSED, never what the user is entitled to — read entitlement from
52
53
  * the billing SDK.
54
+ *
55
+ * `transaction` (optional, #287) is the purchase your billing SDK made, so a
56
+ * `PaywallProvider` `observer` can attribute it to this presentation; the
57
+ * SDK never sees a purchase a custom screen makes on its own. Pass it with
58
+ * `{ status: "purchased" }`:
59
+ * - `originalTransactionIdentifier`: the purchase's store transaction id —
60
+ * the iOS StoreKit original transaction id, the Android Play order id
61
+ * (`GPA.…`); the value you pass to your analytics' purchase call.
62
+ * - `purchaseToken`: Android only, the Play purchase token.
63
+ * - `productId`: the store product id that was bought.
64
+ * - `restored`: `true` when the purchase only restored existing access, so
65
+ * it is not counted as a conversion.
66
+ *
67
+ * It is sanitized before the observer sees it: an id that is not a
68
+ * non-empty string, a `restored` that is not exactly `true`, and any other
69
+ * field are dropped, and so is a transaction that throws when read. It is
70
+ * dropped entirely, with a warning, with any status other than
71
+ * `"purchased"`. When this presentation already recorded a purchase made
72
+ * through the SDK's own product runtime, that purchase wins: your ids are
73
+ * added to it only when your `productId` is present and names the same
74
+ * store product, `restored` is never added, and otherwise your ids are
75
+ * dropped with a warning. On a `Paywall` step, a `complete` captured during
76
+ * an earlier visit (the user left and came back) never ends the visit on
77
+ * screen and never carries its transaction; only its `{ status:
78
+ * "purchased" }` still advances the step, and only while the step is on
79
+ * screen, so a payer is never stranded; the step advances at most once per
80
+ * visit. Any other such call does nothing. It never
81
+ * changes what `present()` resolves or whether a step advances. Omitted,
82
+ * everything behaves as before.
53
83
  */
54
- complete: (outcome?: { status: "purchased" | "dismissed" | "cancelled" }) => void;
84
+ complete: (outcome?: {
85
+ status: "purchased" | "dismissed" | "cancelled";
86
+ transaction?: PaywallTransactionInfo;
87
+ }) => void;
55
88
  /**
56
89
  * Which paywall is being shown. `moment` is what resolved it; `id` and
57
90
  * `name` are the studio's, for analytics. Enough to report a conversion