@fantastic.dev/better-stripe 0.103.0 → 0.105.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 (64) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +100 -0
  4. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/configure/transport.js +17 -2
  6. package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +22 -0
  8. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +105 -3
  10. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +1 -0
  12. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/preflight/output.js +6 -2
  14. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +3 -1
  16. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/preflight/record.js +8 -3
  18. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +2 -0
  20. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +12 -5
  22. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +19 -0
  24. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +71 -0
  26. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts +25 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts.map +1 -1
  29. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js +62 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js.map +1 -1
  31. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +14 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -1
  33. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +17 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -1
  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/billing/renewalAttach/internal/producer/configureWrite.d.ts +30 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -0
  41. package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +224 -0
  42. package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js.map +1 -0
  43. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts +61 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js +73 -0
  46. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js.map +1 -0
  47. package/docs/renewal-context-reads.md +79 -4
  48. package/package.json +1 -1
  49. package/src/client/billing/renewalAttach/internal/configure/transport.ts +31 -2
  50. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +148 -3
  51. package/src/client/billing/renewalAttach/internal/preflight/output.ts +20 -3
  52. package/src/client/billing/renewalAttach/internal/preflight/record.ts +11 -3
  53. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +20 -5
  54. package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +132 -0
  55. package/src/client/billing/renewalAttach/internal/producer/configureJournalData.ts +84 -0
  56. package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +16 -0
  57. package/src/client/billing/renewalAttach/internal/producer/configurePreflight.ts +170 -0
  58. package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +317 -0
  59. package/src/client/billing/renewalAttach/internal/producer/configureWriteFactory.ts +88 -0
  60. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflight.integration.test.ts +67 -0
  61. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflightControls.integration.test.ts +475 -0
  62. package/src/client/billing/renewalAttach/internal/producer/producerConfigureWrite.integration.test.ts +158 -0
  63. package/src/client/billing/renewalAttach/internal/producer/producerConfigureWriteControls.integration.test.ts +537 -0
  64. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +136 -6
@@ -1,8 +1,9 @@
1
1
  import assert from "node:assert/strict";
2
- import { afterEach, beforeEach, vi } from "vitest";
2
+ import { afterEach, beforeEach, describe, it, vi } from "vitest";
3
3
  import { initialOperations } from "./producerInitialOperation.js";
4
4
  import { makeConfigureReadNativeBaseline } from "./configureReadNativeBaseline.js";
5
5
  import { captureRetainedInput } from "../material/capture.js";
6
+ import { captureAdmittedConfigurePreflight } from "../producer/configurePreflight.js";
6
7
  import { captureInitialInvocationCore } from "../producer/invocationProducer.js";
7
8
  import { createClassActionOperationJournal } from "../operationJournal.js";
8
9
  import { components } from "../../../../../../example/convex/_generated/api.js";
@@ -19,6 +20,14 @@ import { INITIAL_NS } from "./producerInitialDeclarations.js";
19
20
  const controls = vi.hoisted(() => ({
20
21
  entries: [{ coversRetained: () => true, coversFresh: () => true }],
21
22
  recovery: [] as { originalEntry: unknown; coversReplay(): boolean }[],
23
+ preflight: [] as {
24
+ originalEntry: unknown;
25
+ coversPreflight(...args: unknown[]): boolean;
26
+ }[],
27
+ write: [] as {
28
+ originalEntry: unknown;
29
+ coversConfigure(...args: unknown[]): boolean;
30
+ }[],
22
31
  legacy: 0,
23
32
  selectors: 0,
24
33
  }));
@@ -30,6 +39,14 @@ vi.mock("../operations/sourceOperations.js", () => {
30
39
  return {
31
40
  COMPILED_INITIAL_ENTRIES: controls.entries,
32
41
  COMPILED_RECOVERY_ENTRIES: controls.recovery,
42
+ COMPILED_PREFLIGHT_ENTRIES: controls.preflight,
43
+ COMPILED_CONFIGURE_WRITE_ENTRIES: controls.write,
44
+ loadConfigureWriteTransportSource: poison,
45
+ loadConfigureReplayTransportSource: poison,
46
+ loadFixedConfigureWriteOperation: poison,
47
+ loadFixedConfigureReplayOperation: poison,
48
+ loadOwnedConfigureOperation: poison,
49
+ loadConfigureOwnedReadTransportSource: poison,
33
50
  ORIGINAL_ORIGIN_ASSOCIATION: null,
34
51
  loadFixedInitialOperation: poison,
35
52
  loadFixedExplicitRecoveryOperation: poison,
@@ -69,6 +86,8 @@ export const admissionControls = controls;
69
86
  const canonical = (value: unknown) => JSON.stringify(renewalSnapshot(value));
70
87
  beforeEach(() => {
71
88
  controls.legacy = 0;
89
+ controls.preflight.splice(0);
90
+ controls.write.splice(0);
72
91
  controls.selectors = 0;
73
92
  controls.entries.splice(0, controls.entries.length, {
74
93
  coversRetained: () => true,
@@ -93,13 +112,21 @@ afterEach(() => {
93
112
  async function setup(
94
113
  input: Parameters<Parameters<typeof initialOperations>[0]>[0],
95
114
  completion: { mode: string; posts: number },
115
+ hooks: { beforeFetch?: (path: string, method: string) => Promise<void> },
96
116
  ) {
97
117
  const { journal, fresh, sdk, ctx, index } = input;
98
118
  assert(fresh.result.disposition === "acquired" && fresh.call);
99
119
  const parentReservation = fresh.result.reservation;
100
120
  const baseline = makeConfigureReadNativeBaseline();
101
121
  const source = captureRetainedInput(baseline.original);
102
- const calls: { method: string; path: string }[] = [];
122
+ const calls: {
123
+ method: string;
124
+ path: string;
125
+ query: string;
126
+ hasBody: boolean;
127
+ idempotencyKey: string | null;
128
+ apiVersion: string | null;
129
+ }[] = [];
103
130
  const routes = new Map<string, unknown>([
104
131
  ["/v1/subscriptions/sub_original", source.originalBundle.wireSubscription],
105
132
  ["/v1/prices/price_target", source.originalBundle.wireTargetPrice],
@@ -110,9 +137,18 @@ async function setup(
110
137
  ]),
111
138
  ]);
112
139
  vi.stubGlobal("fetch", async (url: RequestInfo | URL, init?: RequestInit) => {
113
- const path = new URL(String(url)).pathname;
140
+ const parsed = new URL(String(url));
141
+ const path = parsed.pathname;
114
142
  const method = init?.method ?? "";
115
- calls.push({ method, path });
143
+ calls.push({
144
+ method,
145
+ path,
146
+ query: parsed.search,
147
+ hasBody: init?.body !== undefined,
148
+ idempotencyKey: new Headers(init?.headers).get("idempotency-key"),
149
+ apiVersion: new Headers(init?.headers).get("stripe-version"),
150
+ });
151
+ await hooks.beforeFetch?.(path, method);
116
152
  if (method === "POST") {
117
153
  completion.posts++;
118
154
  if (completion.mode === "replay" && completion.posts === 1)
@@ -122,7 +158,9 @@ async function setup(
122
158
  assert(body);
123
159
  assert(
124
160
  method === "GET" ||
125
- (method === "POST" && path === "/v1/subscription_schedules"),
161
+ (method === "POST" &&
162
+ (path === "/v1/subscription_schedules" ||
163
+ path === "/v1/subscription_schedules/" + baseline.schedule.id)),
126
164
  );
127
165
  return new Response(JSON.stringify(body), {
128
166
  status: 200,
@@ -267,6 +305,30 @@ async function setup(
267
305
  }
268
306
  return core.recoverAttach().invoke();
269
307
  }
308
+ function configureReads(value: Awaited<ReturnType<typeof child>>) {
309
+ const configuration = value.record.configureRecord.configuration;
310
+ const current = {
311
+ subscription: structuredClone(configuration.freshSubscription),
312
+ price: structuredClone(configuration.targetPrice),
313
+ customer: structuredClone(configuration.billingCustomer),
314
+ schedule: structuredClone(configuration.schedule),
315
+ coupons: structuredClone(source.originalBundle.couponReads),
316
+ };
317
+ routes.set("/v1/subscriptions/sub_original", current.subscription);
318
+ routes.set("/v1/prices/price_target", current.price);
319
+ routes.set("/v1/customers/cus_buyer", current.customer);
320
+ routes.set(
321
+ "/v1/subscription_schedules/" + baseline.schedule.id,
322
+ current.schedule,
323
+ );
324
+ for (const row of current.coupons)
325
+ routes.set(
326
+ "/v1/coupons/" + encodeURIComponent(String(row.couponId)),
327
+ row.wireCoupon,
328
+ );
329
+ vi.setSystemTime(baseline.configurationTime * 1000);
330
+ return current;
331
+ }
270
332
  async function eventsFor(value: Awaited<ReturnType<typeof child>>) {
271
333
  const request = value.record.configureRecord.request;
272
334
  const transport = {
@@ -301,6 +363,7 @@ async function setup(
301
363
  source,
302
364
  complete,
303
365
  eventsFor,
366
+ configureReads,
304
367
  };
305
368
  }
306
369
  export async function configureAdmissionFixture(
@@ -316,13 +379,15 @@ export async function configureAdmissionFixture(
316
379
  ) => Promise<void>;
317
380
  afterAppend?: () => Promise<void>;
318
381
  beforeAppend?: () => Promise<void>;
382
+ afterRetain?: () => Promise<void>;
383
+ beforeFetch?: (path: string, method: string) => Promise<void>;
319
384
  } = {},
320
385
  ) {
321
386
  const baseline = makeConfigureReadNativeBaseline();
322
387
  const completion = { mode: "initial", posts: 0, appends: 0 };
323
388
  await initialOperations(
324
389
  async (input) => {
325
- const h = await setup(input, completion);
390
+ const h = await setup(input, completion, options);
326
391
  try {
327
392
  await work(h);
328
393
  } finally {
@@ -336,6 +401,7 @@ export async function configureAdmissionFixture(
336
401
  afterBind: options.afterBind,
337
402
  afterQuery: options.afterQuery,
338
403
  beforeAppend: options.beforeAppend,
404
+ afterRetain: options.afterRetain,
339
405
  afterAppend: async () => {
340
406
  completion.appends++;
341
407
  if (completion.mode === "resume" && completion.appends === 2)
@@ -351,3 +417,67 @@ export async function configureAdmissionFixture(
351
417
  },
352
418
  );
353
419
  }
420
+
421
+ /** Stage real Action prerequisites separately while joining every test continuation. */
422
+ export function configureAdmissionCase<T>(
423
+ name: string,
424
+ prepare: (h: Awaited<ReturnType<typeof setup>>) => Promise<T>,
425
+ verify: (h: Awaited<ReturnType<typeof setup>>, state: T) => Promise<void>,
426
+ options: Parameters<typeof configureAdmissionFixture>[1] = {},
427
+ ) {
428
+ describe(name, () => {
429
+ let pending: Promise<void>,
430
+ start!: () => void,
431
+ run = false;
432
+ beforeEach(async () => {
433
+ run = false;
434
+ let ready!: () => void, failed!: (error: unknown) => void;
435
+ const prepared = new Promise<void>((resolve, reject) => {
436
+ ready = resolve;
437
+ failed = reject;
438
+ });
439
+ const entered = new Promise<void>((resolve) => {
440
+ start = resolve;
441
+ });
442
+ pending = configureAdmissionFixture(async (h) => {
443
+ const state = await prepare(h);
444
+ ready();
445
+ await entered;
446
+ if (run) await verify(h, state);
447
+ }, options);
448
+ void pending.catch(failed);
449
+ await prepared;
450
+ });
451
+ afterEach(async () => {
452
+ start?.();
453
+ await pending?.catch(() => {});
454
+ });
455
+ it(name, async () => {
456
+ run = true;
457
+ start();
458
+ await pending;
459
+ });
460
+ });
461
+ }
462
+
463
+ /** Actual initial ACK, child admission and completed readonly preflight prerequisites. */
464
+ export async function prepareAdmittedConfigure(
465
+ h: Awaited<ReturnType<typeof setup>>,
466
+ ) {
467
+ await h.complete();
468
+ const child = await h.child();
469
+ const token = await h.core.admitConfigure(child.fresh.call, child.journal);
470
+ const current = h.configureReads(child);
471
+ if (controls.preflight.length === 0)
472
+ controls.preflight.push({
473
+ originalEntry: controls.entries[0],
474
+ coversPreflight: () => true,
475
+ });
476
+ if (controls.write.length === 0)
477
+ controls.write.push({
478
+ originalEntry: controls.entries[0],
479
+ coversConfigure: () => true,
480
+ });
481
+ await captureAdmittedConfigurePreflight(token).invoke();
482
+ return { child, token, current };
483
+ }