@fantastic.dev/better-stripe 0.102.0 → 0.104.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 (65) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/c10/appendAck.d.ts +7 -0
  4. package/dist/client/billing/renewalAttach/internal/c10/appendAck.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/c10/appendAck.js +13 -1
  6. package/dist/client/billing/renewalAttach/internal/c10/appendAck.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts +23 -0
  8. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js +34 -2
  10. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +22 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +105 -3
  14. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +1 -0
  16. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/preflight/output.js +6 -2
  18. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +3 -1
  20. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/preflight/record.js +8 -3
  22. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +2 -0
  24. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +12 -5
  26. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -1
  27. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +3 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +25 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +6 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +49 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts +16 -0
  36. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js +117 -0
  38. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js.map +1 -0
  39. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  40. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  41. package/dist/component/balanceFunding/mutations.d.ts +27 -27
  42. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  43. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  44. package/dist/component/earnings/triggers.d.ts +16 -16
  45. package/dist/component/payoutRelease/queries.d.ts +2 -2
  46. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  47. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  48. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  49. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  50. package/docs/renewal-context-reads.md +72 -4
  51. package/package.json +1 -1
  52. package/src/client/billing/renewalAttach/internal/c10/appendAck.ts +17 -0
  53. package/src/client/billing/renewalAttach/internal/c10/configureEvents.ts +45 -2
  54. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +148 -3
  55. package/src/client/billing/renewalAttach/internal/preflight/output.ts +20 -3
  56. package/src/client/billing/renewalAttach/internal/preflight/record.ts +11 -3
  57. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +20 -5
  58. package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +40 -0
  59. package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +53 -0
  60. package/src/client/billing/renewalAttach/internal/producer/configurePreflight.ts +170 -0
  61. package/src/client/billing/renewalAttach/internal/producer/producerConfigureChannelControls.integration.test.ts +542 -0
  62. package/src/client/billing/renewalAttach/internal/producer/producerConfigureChannels.integration.test.ts +321 -0
  63. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflight.integration.test.ts +67 -0
  64. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflightControls.integration.test.ts +475 -0
  65. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +89 -5
@@ -0,0 +1,475 @@
1
+ import {
2
+ configureAdmissionFixture,
3
+ admissionControls,
4
+ } from "../test-fixtures/producerConfigureAdmission.js";
5
+ import { webcrypto } from "node:crypto";
6
+ import { expect, it, vi } from "vitest";
7
+ import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
8
+ import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
9
+ import {
10
+ captureAdmittedConfigurePreflight,
11
+ readAdmittedConfigurePreflight,
12
+ } from "./configurePreflight.js";
13
+
14
+ it("an invalid invoke argument spends the readonly actor without reading or reminting", async () => {
15
+ await configureAdmissionFixture(async (h) => {
16
+ await h.complete();
17
+ const child = await h.child();
18
+ const token = await h.core.admitConfigure(child.fresh.call, child.journal);
19
+ h.configureReads(child);
20
+ admissionControls.preflight.push({
21
+ originalEntry: admissionControls.entries[0],
22
+ coversPreflight: () => true,
23
+ });
24
+ const actor = captureAdmittedConfigurePreflight(token),
25
+ before = h.calls.length;
26
+ let traps = 0;
27
+ const input = new Proxy(
28
+ {},
29
+ {
30
+ get() {
31
+ traps++;
32
+ throw Error("REPLACEMENT_INVOKED");
33
+ },
34
+ },
35
+ );
36
+ await expect(Reflect.apply(actor.invoke, actor, [input])).rejects.toThrow();
37
+ expect(h.calls).toHaveLength(before);
38
+ expect(traps).toBe(0);
39
+ let refused = false;
40
+ try {
41
+ await actor.invoke();
42
+ } catch {
43
+ refused = true;
44
+ }
45
+ expect(refused).toBe(true);
46
+ expect(h.calls).toHaveLength(before);
47
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
48
+ });
49
+ });
50
+
51
+ it.each([
52
+ "empty",
53
+ "foreign-entry",
54
+ "ambiguous",
55
+ "copy",
56
+ "proxy",
57
+ "extra-capture",
58
+ ])(
59
+ "refuses %s preflight capture without another selector or provider read",
60
+ async (scenario) => {
61
+ await configureAdmissionFixture(async (h) => {
62
+ await h.complete();
63
+ const child = await h.child();
64
+ const token = await h.core.admitConfigure(
65
+ child.fresh.call,
66
+ child.journal,
67
+ );
68
+ h.configureReads(child);
69
+ if (scenario !== "empty")
70
+ admissionControls.preflight.push({
71
+ originalEntry:
72
+ scenario === "foreign-entry" ? {} : admissionControls.entries[0],
73
+ coversPreflight: () => true,
74
+ });
75
+ if (scenario === "ambiguous")
76
+ admissionControls.preflight.push({ ...admissionControls.preflight[0] });
77
+ let traps = 0;
78
+ const value =
79
+ scenario === "copy"
80
+ ? { ...token }
81
+ : scenario === "proxy"
82
+ ? new Proxy(token, {
83
+ getPrototypeOf() {
84
+ traps++;
85
+ throw Error("PROXY_INVOKED");
86
+ },
87
+ })
88
+ : token;
89
+ const calls = h.calls.length,
90
+ selectors = admissionControls.selectors;
91
+ let refused = false;
92
+ try {
93
+ Reflect.apply(
94
+ captureAdmittedConfigurePreflight,
95
+ undefined,
96
+ scenario === "extra-capture" ? [value, {}] : [value],
97
+ );
98
+ } catch {
99
+ refused = true;
100
+ }
101
+ expect(refused).toBe(true);
102
+ expect(traps).toBe(0);
103
+ expect(h.calls).toHaveLength(calls);
104
+ expect(admissionControls.selectors).toBe(selectors);
105
+ if (scenario === "copy" || scenario === "proxy")
106
+ await captureAdmittedConfigurePreflight(token).invoke();
107
+ else expect(() => captureAdmittedConfigurePreflight(token)).toThrow();
108
+ });
109
+ },
110
+ );
111
+ it("a pending raw read cannot become actual returned preflight custody", async () => {
112
+ let armed = false,
113
+ release!: () => void,
114
+ entered!: () => void;
115
+ const barrier = new Promise<void>((resolve) => {
116
+ release = resolve;
117
+ });
118
+ const reached = new Promise<void>((resolve) => {
119
+ entered = resolve;
120
+ });
121
+ await configureAdmissionFixture(
122
+ async (h) => {
123
+ await h.complete();
124
+ const child = await h.child();
125
+ const token = await h.core.admitConfigure(
126
+ child.fresh.call,
127
+ child.journal,
128
+ );
129
+ h.configureReads(child);
130
+ admissionControls.preflight.push({
131
+ originalEntry: admissionControls.entries[0],
132
+ coversPreflight: () => true,
133
+ });
134
+ const actor = captureAdmittedConfigurePreflight(token);
135
+ armed = true;
136
+ let completed = false;
137
+ const pending = actor.invoke().then((value) => {
138
+ completed = true;
139
+ return value;
140
+ });
141
+ try {
142
+ expect(
143
+ await Promise.race([
144
+ reached.then(() => "reached"),
145
+ pending.then(
146
+ () => "resolved",
147
+ (error: unknown) => String(error),
148
+ ),
149
+ ]),
150
+ ).toBe("reached");
151
+ expect(completed).toBe(false);
152
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
153
+ } finally {
154
+ release();
155
+ }
156
+ const output = await pending;
157
+ expect(readAdmittedConfigurePreflight(token).output === output).toBe(
158
+ true,
159
+ );
160
+ await expect(actor.invoke()).rejects.toThrow();
161
+ },
162
+ {
163
+ beforeFetch: async (_path, method) => {
164
+ if (armed && method === "GET") {
165
+ armed = false;
166
+ entered();
167
+ await barrier;
168
+ }
169
+ },
170
+ },
171
+ );
172
+ });
173
+ it("parent retirement rejects a pending read without returning or registering output", async () => {
174
+ let armed = false,
175
+ release!: () => void,
176
+ entered!: () => void;
177
+ const barrier = new Promise<void>((resolve) => {
178
+ release = resolve;
179
+ });
180
+ const reached = new Promise<void>((resolve) => {
181
+ entered = resolve;
182
+ });
183
+ await configureAdmissionFixture(
184
+ async (h) => {
185
+ await h.complete();
186
+ const child = await h.child();
187
+ const token = await h.core.admitConfigure(
188
+ child.fresh.call,
189
+ child.journal,
190
+ );
191
+ h.configureReads(child);
192
+ admissionControls.preflight.push({
193
+ originalEntry: admissionControls.entries[0],
194
+ coversPreflight: () => true,
195
+ });
196
+ const actor = captureAdmittedConfigurePreflight(token);
197
+ armed = true;
198
+ const pending = actor.invoke();
199
+ const refused = expect(pending).rejects.toThrow();
200
+ try {
201
+ expect(
202
+ await Promise.race([
203
+ reached.then(() => "reached"),
204
+ pending.then(
205
+ () => "resolved",
206
+ (error: unknown) => String(error),
207
+ ),
208
+ ]),
209
+ ).toBe("reached");
210
+ h.core.owner.retire();
211
+ await refused;
212
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
213
+ } finally {
214
+ release();
215
+ }
216
+ await vi.advanceTimersByTimeAsync(0);
217
+ expect(() => captureAdmittedConfigurePreflight(token)).toThrow();
218
+ },
219
+ {
220
+ beforeFetch: async (_path, method) => {
221
+ if (armed && method === "GET") {
222
+ armed = false;
223
+ entered();
224
+ await barrier;
225
+ }
226
+ },
227
+ },
228
+ );
229
+ });
230
+ it.each(["schedule", "coupon", "privacy", "predicate"])(
231
+ "changed %s material refuses without returned output or POST",
232
+ async (scenario) => {
233
+ await configureAdmissionFixture(async (h) => {
234
+ await h.complete();
235
+ const child = await h.child();
236
+ const token = await h.core.admitConfigure(
237
+ child.fresh.call,
238
+ child.journal,
239
+ );
240
+ const current = h.configureReads(child);
241
+ admissionControls.preflight.push({
242
+ originalEntry: admissionControls.entries[0],
243
+ coversPreflight: () => scenario !== "predicate",
244
+ });
245
+ if (scenario === "schedule")
246
+ current.schedule.metadata = { changed: true };
247
+ if (scenario === "coupon")
248
+ current.coupons[0].wireCoupon.times_redeemed = 99;
249
+ if (scenario === "privacy")
250
+ Reflect.set(
251
+ current.subscription,
252
+ "future",
253
+ "Bearer synthetic-preflight-private-control",
254
+ );
255
+ const before = h.calls.length,
256
+ actor = captureAdmittedConfigurePreflight(token);
257
+ await expect(actor.invoke()).rejects.toThrow();
258
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
259
+ expect(h.calls.slice(before).every((row) => row.method === "GET")).toBe(
260
+ true,
261
+ );
262
+ expect(admissionControls.legacy).toBe(0);
263
+ });
264
+ },
265
+ );
266
+ it("copied outputs cannot register custody and changed eligibility cannot revive a cached view", async () => {
267
+ await configureAdmissionFixture(async (h) => {
268
+ await h.complete();
269
+ const child = await h.child();
270
+ const token = await h.core.admitConfigure(child.fresh.call, child.journal);
271
+ h.configureReads(child);
272
+ const entry = {
273
+ originalEntry: admissionControls.entries[0],
274
+ coversPreflight: () => true,
275
+ };
276
+ admissionControls.preflight.push(entry);
277
+ const output = await captureAdmittedConfigurePreflight(token).invoke();
278
+ const view = readAdmittedConfigurePreflight(token);
279
+ expect(readAdmittedConfigurePreflight(token) === view).toBe(true);
280
+ const copy = JSON.parse(JSON.stringify(output));
281
+ expect(copy).toEqual(output);
282
+ expect(() =>
283
+ Reflect.apply(readAdmittedConfigurePreflight, undefined, [token, copy]),
284
+ ).toThrow();
285
+ expect(() => readAdmittedConfigurePreflight({ ...token })).toThrow();
286
+ const original = entry.coversPreflight;
287
+ entry.coversPreflight = () => true;
288
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
289
+ entry.coversPreflight = original;
290
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
291
+ });
292
+ });
293
+
294
+ it("a child intent committed during original reconstruction refuses before any provider reads", async () => {
295
+ let invoking = false,
296
+ armed = false;
297
+ await configureAdmissionFixture(
298
+ async (h) => {
299
+ await h.complete();
300
+ const child = await h.child();
301
+ const token = await h.core.admitConfigure(
302
+ child.fresh.call,
303
+ child.journal,
304
+ );
305
+ h.configureReads(child);
306
+ admissionControls.preflight.push({
307
+ originalEntry: admissionControls.entries[0],
308
+ coversPreflight: () => true,
309
+ });
310
+ const actor = captureAdmittedConfigurePreflight(token);
311
+ if (child.fresh.result.disposition !== "acquired")
312
+ throw Error("INVALID_FIXTURE_CAS");
313
+ const reservation = child.fresh.result.reservation;
314
+ const event = await canonicalJournalEvent(
315
+ 1,
316
+ JSON.stringify(
317
+ renewalSnapshot({
318
+ event: "dispatch",
319
+ stage: "configure",
320
+ request: child.record.configureRecord.request,
321
+ }),
322
+ ),
323
+ );
324
+ let release!: () => void,
325
+ entered!: () => void,
326
+ first = true;
327
+ const barrier = new Promise<void>((resolve) => {
328
+ release = resolve;
329
+ }),
330
+ reached = new Promise<void>((resolve) => {
331
+ entered = resolve;
332
+ });
333
+ vi.stubGlobal("crypto", {
334
+ subtle: {
335
+ async digest(
336
+ algorithm: Parameters<typeof webcrypto.subtle.digest>[0],
337
+ input: Parameters<typeof webcrypto.subtle.digest>[1],
338
+ ) {
339
+ const result = await webcrypto.subtle.digest(algorithm, input);
340
+ if (
341
+ armed &&
342
+ first &&
343
+ ArrayBuffer.isView(input) &&
344
+ JSON.parse(
345
+ new TextDecoder().decode(
346
+ new Uint8Array(
347
+ input.buffer,
348
+ input.byteOffset,
349
+ input.byteLength,
350
+ ),
351
+ ),
352
+ )[2] === "renewal-configure"
353
+ ) {
354
+ first = false;
355
+ entered();
356
+ await barrier;
357
+ }
358
+ return result;
359
+ },
360
+ },
361
+ });
362
+ invoking = true;
363
+ const before = h.calls.length;
364
+ const pending = actor.invoke(),
365
+ refused = expect(pending).rejects.toThrow();
366
+ try {
367
+ expect(
368
+ await Promise.race([
369
+ reached.then(() => "reached"),
370
+ pending.then(
371
+ () => "resolved",
372
+ (error: unknown) => String(error),
373
+ ),
374
+ ]),
375
+ ).toBe("reached");
376
+ await child.journal.appendStageEvent({
377
+ reservation,
378
+ expectedSequence: 0,
379
+ event: { sequence: 1, binding: event.binding, dataJSON: event.json },
380
+ });
381
+ } finally {
382
+ release();
383
+ }
384
+ await refused;
385
+ expect(h.calls).toHaveLength(before);
386
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
387
+ },
388
+ {
389
+ afterQuery: async (_reply, reference) => {
390
+ if (invoking && reference.endsWith("/readAttempt")) armed = true;
391
+ },
392
+ },
393
+ );
394
+ });
395
+
396
+ it("an intent committed during HTTP prevents output custody", async () => {
397
+ let append: (() => Promise<void>) | undefined;
398
+ await configureAdmissionFixture(
399
+ async (h) => {
400
+ await h.complete();
401
+ const child = await h.child();
402
+ const token = await h.core.admitConfigure(
403
+ child.fresh.call,
404
+ child.journal,
405
+ );
406
+ h.configureReads(child);
407
+ admissionControls.preflight.push({
408
+ originalEntry: admissionControls.entries[0],
409
+ coversPreflight: () => true,
410
+ });
411
+ if (child.fresh.result.disposition !== "acquired")
412
+ throw Error("INVALID_FIXTURE_CAS");
413
+ const reservation = child.fresh.result.reservation;
414
+ const event = await canonicalJournalEvent(
415
+ 1,
416
+ JSON.stringify(
417
+ renewalSnapshot({
418
+ event: "dispatch",
419
+ stage: "configure",
420
+ request: child.record.configureRecord.request,
421
+ }),
422
+ ),
423
+ );
424
+ append = async () => {
425
+ await child.journal.appendStageEvent({
426
+ reservation,
427
+ expectedSequence: 0,
428
+ event: { sequence: 1, binding: event.binding, dataJSON: event.json },
429
+ });
430
+ };
431
+ const before = h.calls.length;
432
+ await expect(
433
+ captureAdmittedConfigurePreflight(token).invoke(),
434
+ ).rejects.toThrow();
435
+ expect(h.calls.slice(before).every((call) => call.method === "GET")).toBe(
436
+ true,
437
+ );
438
+ expect(() => readAdmittedConfigurePreflight(token)).toThrow();
439
+ },
440
+ {
441
+ beforeFetch: async (_path, method) => {
442
+ if (append && method === "GET") {
443
+ const run = append;
444
+ append = undefined;
445
+ await run();
446
+ }
447
+ },
448
+ },
449
+ );
450
+ });
451
+
452
+ it("preflight keeps original custody across a second genuine Action context", async () => {
453
+ await configureAdmissionFixture(async (h) => {
454
+ await h.complete();
455
+ const child = await h.child();
456
+ const token = await h.core.admitConfigure(child.fresh.call, child.journal);
457
+ h.configureReads(child);
458
+ admissionControls.preflight.push({
459
+ originalEntry: admissionControls.entries[0],
460
+ coversPreflight: () => true,
461
+ });
462
+ const actor = captureAdmittedConfigurePreflight(token);
463
+ await h.inAnotherAction(async () => {
464
+ const output = await actor.invoke();
465
+ expect(readAdmittedConfigurePreflight(token).output === output).toBe(
466
+ true,
467
+ );
468
+ expect(
469
+ readAdmittedConfigurePreflight(token).acknowledgement ===
470
+ h.core.attachAcknowledgement(),
471
+ ).toBe(true);
472
+ });
473
+ expect(admissionControls.legacy).toBe(0);
474
+ });
475
+ });
@@ -12,12 +12,17 @@ import {
12
12
  prepareRenewalPriceReplacementV2,
13
13
  prepareRenewalScheduleAttachmentV2,
14
14
  projectRenewalConfigurationV2,
15
+ constructRenewalConfigurationReceiptV2,
15
16
  } from "../../../renewalV2/index.js";
16
17
  import { INITIAL_NS } from "./producerInitialDeclarations.js";
17
18
 
18
19
  const controls = vi.hoisted(() => ({
19
20
  entries: [{ coversRetained: () => true, coversFresh: () => true }],
20
21
  recovery: [] as { originalEntry: unknown; coversReplay(): boolean }[],
22
+ preflight: [] as {
23
+ originalEntry: unknown;
24
+ coversPreflight(...args: unknown[]): boolean;
25
+ }[],
21
26
  legacy: 0,
22
27
  selectors: 0,
23
28
  }));
@@ -29,6 +34,9 @@ vi.mock("../operations/sourceOperations.js", () => {
29
34
  return {
30
35
  COMPILED_INITIAL_ENTRIES: controls.entries,
31
36
  COMPILED_RECOVERY_ENTRIES: controls.recovery,
37
+ COMPILED_PREFLIGHT_ENTRIES: controls.preflight,
38
+ loadOwnedConfigureOperation: poison,
39
+ loadConfigureOwnedReadTransportSource: poison,
32
40
  ORIGINAL_ORIGIN_ASSOCIATION: null,
33
41
  loadFixedInitialOperation: poison,
34
42
  loadFixedExplicitRecoveryOperation: poison,
@@ -68,6 +76,7 @@ export const admissionControls = controls;
68
76
  const canonical = (value: unknown) => JSON.stringify(renewalSnapshot(value));
69
77
  beforeEach(() => {
70
78
  controls.legacy = 0;
79
+ controls.preflight.splice(0);
71
80
  controls.selectors = 0;
72
81
  controls.entries.splice(0, controls.entries.length, {
73
82
  coversRetained: () => true,
@@ -92,13 +101,19 @@ afterEach(() => {
92
101
  async function setup(
93
102
  input: Parameters<Parameters<typeof initialOperations>[0]>[0],
94
103
  completion: { mode: string; posts: number },
104
+ hooks: { beforeFetch?: (path: string, method: string) => Promise<void> },
95
105
  ) {
96
106
  const { journal, fresh, sdk, ctx, index } = input;
97
107
  assert(fresh.result.disposition === "acquired" && fresh.call);
98
108
  const parentReservation = fresh.result.reservation;
99
109
  const baseline = makeConfigureReadNativeBaseline();
100
110
  const source = captureRetainedInput(baseline.original);
101
- const calls: { method: string; path: string }[] = [];
111
+ const calls: {
112
+ method: string;
113
+ path: string;
114
+ query: string;
115
+ hasBody: boolean;
116
+ }[] = [];
102
117
  const routes = new Map<string, unknown>([
103
118
  ["/v1/subscriptions/sub_original", source.originalBundle.wireSubscription],
104
119
  ["/v1/prices/price_target", source.originalBundle.wireTargetPrice],
@@ -109,9 +124,16 @@ async function setup(
109
124
  ]),
110
125
  ]);
111
126
  vi.stubGlobal("fetch", async (url: RequestInfo | URL, init?: RequestInit) => {
112
- const path = new URL(String(url)).pathname;
127
+ const parsed = new URL(String(url));
128
+ const path = parsed.pathname;
113
129
  const method = init?.method ?? "";
114
- calls.push({ method, path });
130
+ calls.push({
131
+ method,
132
+ path,
133
+ query: parsed.search,
134
+ hasBody: init?.body !== undefined,
135
+ });
136
+ await hooks.beforeFetch?.(path, method);
115
137
  if (method === "POST") {
116
138
  completion.posts++;
117
139
  if (completion.mode === "replay" && completion.posts === 1)
@@ -266,7 +288,66 @@ async function setup(
266
288
  }
267
289
  return core.recoverAttach().invoke();
268
290
  }
269
- return { ...input, core, child, calls, baseline, source, complete };
291
+ function configureReads(value: Awaited<ReturnType<typeof child>>) {
292
+ const configuration = value.record.configureRecord.configuration;
293
+ const current = {
294
+ subscription: structuredClone(configuration.freshSubscription),
295
+ price: structuredClone(configuration.targetPrice),
296
+ customer: structuredClone(configuration.billingCustomer),
297
+ schedule: structuredClone(configuration.schedule),
298
+ coupons: structuredClone(source.originalBundle.couponReads),
299
+ };
300
+ routes.set("/v1/subscriptions/sub_original", current.subscription);
301
+ routes.set("/v1/prices/price_target", current.price);
302
+ routes.set("/v1/customers/cus_buyer", current.customer);
303
+ routes.set(
304
+ "/v1/subscription_schedules/" + baseline.schedule.id,
305
+ current.schedule,
306
+ );
307
+ for (const row of current.coupons)
308
+ routes.set(
309
+ "/v1/coupons/" + encodeURIComponent(String(row.couponId)),
310
+ row.wireCoupon,
311
+ );
312
+ vi.setSystemTime(baseline.configurationTime * 1000);
313
+ return current;
314
+ }
315
+ async function eventsFor(value: Awaited<ReturnType<typeof child>>) {
316
+ const request = value.record.configureRecord.request;
317
+ const transport = {
318
+ status: 200,
319
+ requestId: "req_synthetic_configure_channel",
320
+ };
321
+ const receipt = await constructRenewalConfigurationReceiptV2({
322
+ configuration: value.record.configureRecord.configuration,
323
+ actualDispatch: value.record.dispatch,
324
+ providerSnapshot: baseline.schedule,
325
+ transport,
326
+ });
327
+ return {
328
+ dispatch: { event: "dispatch", stage: "configure", request },
329
+ response: {
330
+ event: "response",
331
+ stage: "configure",
332
+ request,
333
+ body: baseline.schedule,
334
+ transport,
335
+ },
336
+ receiptEvent: { event: "receipt", stage: "configure", request, receipt },
337
+ receipt,
338
+ };
339
+ }
340
+ return {
341
+ ...input,
342
+ core,
343
+ child,
344
+ calls,
345
+ baseline,
346
+ source,
347
+ complete,
348
+ eventsFor,
349
+ configureReads,
350
+ };
270
351
  }
271
352
  export async function configureAdmissionFixture(
272
353
  work: (h: Awaited<ReturnType<typeof setup>>) => Promise<void>,
@@ -280,13 +361,15 @@ export async function configureAdmissionFixture(
280
361
  args: unknown,
281
362
  ) => Promise<void>;
282
363
  afterAppend?: () => Promise<void>;
364
+ beforeAppend?: () => Promise<void>;
365
+ beforeFetch?: (path: string, method: string) => Promise<void>;
283
366
  } = {},
284
367
  ) {
285
368
  const baseline = makeConfigureReadNativeBaseline();
286
369
  const completion = { mode: "initial", posts: 0, appends: 0 };
287
370
  await initialOperations(
288
371
  async (input) => {
289
- const h = await setup(input, completion);
372
+ const h = await setup(input, completion, options);
290
373
  try {
291
374
  await work(h);
292
375
  } finally {
@@ -299,6 +382,7 @@ export async function configureAdmissionFixture(
299
382
  source: captureRetainedInput(baseline.original),
300
383
  afterBind: options.afterBind,
301
384
  afterQuery: options.afterQuery,
385
+ beforeAppend: options.beforeAppend,
302
386
  afterAppend: async () => {
303
387
  completion.appends++;
304
388
  if (completion.mode === "resume" && completion.appends === 2)