@fantastic.dev/better-stripe 0.108.0 → 0.109.1

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 (57) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts +31 -0
  4. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +112 -0
  6. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +17 -0
  8. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -0
  9. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +191 -0
  10. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -0
  11. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +29 -0
  12. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/observation/invocation.js +205 -0
  14. package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +1 -0
  16. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/observation/profile.js +5 -1
  18. package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts +4 -58
  20. package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/observation/reader.js +12 -152
  22. package/dist/client/billing/renewalAttach/internal/observation/reader.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +7 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +1 -0
  26. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -1
  27. package/dist/client/billing/renewalObservation/evidence-invoice.d.ts.map +1 -1
  28. package/dist/client/billing/renewalObservation/evidence-invoice.js +1 -0
  29. package/dist/client/billing/renewalObservation/evidence-invoice.js.map +1 -1
  30. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  31. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  32. package/dist/component/balanceFunding/mutations.d.ts +27 -27
  33. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  34. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  35. package/dist/component/earnings/triggers.d.ts +16 -16
  36. package/dist/component/payoutRelease/queries.d.ts +2 -2
  37. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  38. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  39. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  40. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  41. package/docs/renewal-context-reads.md +55 -0
  42. package/docs/renewal-material-observation.md +4 -1
  43. package/package.json +1 -1
  44. package/src/client/billing/renewalAttach/internal/observation/freshActor.integration.test.ts +360 -0
  45. package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +175 -0
  46. package/src/client/billing/renewalAttach/internal/observation/freshActorControls.integration.test.ts +442 -0
  47. package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +252 -0
  48. package/src/client/billing/renewalAttach/internal/observation/invocation.ts +299 -0
  49. package/src/client/billing/renewalAttach/internal/observation/profile.ts +9 -1
  50. package/src/client/billing/renewalAttach/internal/observation/reader.ts +15 -221
  51. package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +8 -0
  52. package/src/client/billing/renewalAttach/internal/test-fixtures/freshObservation.ts +94 -0
  53. package/src/client/billing/renewalAttach/internal/test-fixtures/historySnapshot.ts +5 -1
  54. package/src/client/billing/renewalAttach/internal/test-fixtures/observationReader.ts +2 -1
  55. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +32 -4
  56. package/src/client/billing/renewalObservation/evidence-invoice-identity.test.ts +48 -0
  57. package/src/client/billing/renewalObservation/evidence-invoice.ts +1 -0
@@ -4,9 +4,13 @@ import { captureAdmittedConfigureWrite } from "../producer/configureWrite.js";
4
4
 
5
5
  export async function historySnapshot(
6
6
  h: Parameters<typeof prepareAdmittedConfigure>[0],
7
+ options: { write?: boolean; beforeWrite?: () => void } = {},
7
8
  ) {
8
9
  const { child, token } = await prepareAdmittedConfigure(h);
9
- await captureAdmittedConfigureWrite(token).invoke();
10
+ if (options.write !== false) {
11
+ options.beforeWrite?.();
12
+ await captureAdmittedConfigureWrite(token).invoke();
13
+ }
10
14
  async function read(journal: typeof child.journal) {
11
15
  const operation = await journal.loadAuthorizedOperation();
12
16
  assert(operation?.activeAttempt);
@@ -46,8 +46,9 @@ export const authorizeObservation = queryGeneric({
46
46
  });
47
47
  export async function prepareObservationReader(
48
48
  h: Parameters<typeof historySnapshot>[0],
49
+ options: NonNullable<Parameters<typeof historySnapshot>[1]> = {},
49
50
  ) {
50
- const full = await historySnapshot(h);
51
+ const full = await historySnapshot(h, options);
51
52
  const operationId = full.configure.operation.operationId;
52
53
  const parentOperationId = full.parent.operation.operationId;
53
54
  const binding = await captureMaintainedJournalBinding(h.sdk, {
@@ -31,6 +31,8 @@ const controls = vi.hoisted(() => ({
31
31
  legacy: 0,
32
32
  selectors: 0,
33
33
  history: [] as unknown[],
34
+ observation: [] as unknown[],
35
+ onSelect: null as null | ((client: object) => void),
34
36
  }));
35
37
  vi.mock("../operations/sourceOperations.js", () => {
36
38
  const poison = () => {
@@ -43,6 +45,7 @@ vi.mock("../operations/sourceOperations.js", () => {
43
45
  COMPILED_PREFLIGHT_ENTRIES: controls.preflight,
44
46
  COMPILED_CONFIGURE_WRITE_ENTRIES: controls.write,
45
47
  COMPILED_OBSERVATION_HISTORY_ENTRIES: controls.history,
48
+ COMPILED_FRESH_OBSERVATION_ENTRIES: controls.observation,
46
49
  loadConfigureWriteTransportSource: poison,
47
50
  loadConfigureReplayTransportSource: poison,
48
51
  loadFixedConfigureWriteOperation: poison,
@@ -80,18 +83,36 @@ vi.mock("../../../../helpers.js", async (original) => {
80
83
  ...actual,
81
84
  getStripeClient(...args: Parameters<typeof actual.getStripeClient>) {
82
85
  controls.selectors++;
83
- return actual.getStripeClient(...args);
86
+ const client = actual.getStripeClient(...args);
87
+ controls.onSelect?.(client);
88
+ return client;
84
89
  },
85
90
  };
86
91
  });
87
92
  export const admissionControls = controls;
88
93
  const canonical = (value: unknown) => JSON.stringify(renewalSnapshot(value));
94
+ function admissionBaseline(targetInterval?: "week") {
95
+ const baseline = makeConfigureReadNativeBaseline();
96
+ if (targetInterval) {
97
+ const target = baseline.original.attachRequest.preparation.targetPrice;
98
+ Object.assign(target.recurring, { interval: targetInterval });
99
+ baseline.original.originalBundle.wireTargetPrice = structuredClone(target);
100
+ const subscription =
101
+ baseline.original.attachRequest.preparation.subscription;
102
+ Object.assign(subscription, { trial_start: null, trial_end: null });
103
+ baseline.original.originalBundle.wireSubscription =
104
+ structuredClone(subscription);
105
+ }
106
+ return baseline;
107
+ }
89
108
  beforeEach(() => {
90
109
  controls.legacy = 0;
91
110
  controls.preflight.splice(0);
92
111
  controls.write.splice(0);
93
112
  controls.selectors = 0;
94
113
  controls.history.splice(0);
114
+ controls.observation.splice(0);
115
+ controls.onSelect = null;
95
116
  controls.entries.splice(0, controls.entries.length, {
96
117
  coversRetained: () => true,
97
118
  coversFresh: () => true,
@@ -115,12 +136,15 @@ afterEach(() => {
115
136
  async function setup(
116
137
  input: Parameters<Parameters<typeof initialOperations>[0]>[0],
117
138
  completion: { mode: string; posts: number },
118
- hooks: { beforeFetch?: (path: string, method: string) => Promise<void> },
139
+ hooks: {
140
+ beforeFetch?: (path: string, method: string) => Promise<void>;
141
+ targetInterval?: "week";
142
+ },
119
143
  ) {
120
144
  const { journal, fresh, sdk, ctx, index } = input;
121
145
  assert(fresh.result.disposition === "acquired" && fresh.call);
122
146
  const parentReservation = fresh.result.reservation;
123
- const baseline = makeConfigureReadNativeBaseline();
147
+ const baseline = admissionBaseline(hooks.targetInterval);
124
148
  const source = captureRetainedInput(baseline.original);
125
149
  const calls: {
126
150
  method: string;
@@ -367,11 +391,15 @@ async function setup(
367
391
  complete,
368
392
  eventsFor,
369
393
  configureReads,
394
+ setControlledRead(path: string, body: unknown) {
395
+ routes.set(path, body);
396
+ },
370
397
  };
371
398
  }
372
399
  export async function configureAdmissionFixture(
373
400
  work: (h: Awaited<ReturnType<typeof setup>>) => Promise<void>,
374
401
  options: {
402
+ targetInterval?: "week";
375
403
  identity?: NonNullable<Parameters<typeof initialOperations>[2]>["identity"];
376
404
  hostQuery?: NonNullable<
377
405
  Parameters<typeof initialOperations>[2]
@@ -390,7 +418,7 @@ export async function configureAdmissionFixture(
390
418
  beforeFetch?: (path: string, method: string) => Promise<void>;
391
419
  } = {},
392
420
  ) {
393
- const baseline = makeConfigureReadNativeBaseline();
421
+ const baseline = admissionBaseline(options.targetInterval);
394
422
  const completion = { mode: "initial", posts: 0, appends: 0 };
395
423
  await initialOperations(
396
424
  async (input) => {
@@ -0,0 +1,48 @@
1
+ import { expect, it } from "vitest";
2
+ import { inspectRenewalEvidenceV1 } from "./evidence-v1.js";
3
+ import { object } from "./common.js";
4
+ import {
5
+ invoiceRecipe,
6
+ prerequisites,
7
+ bounded,
8
+ set,
9
+ } from "../../../../tests/renewalObservation/evidenceFixtures.js";
10
+
11
+ it.each(["string", "minimal-expanded", "full-expanded"] as const)(
12
+ "one invoice ID cannot prove two renewal invoices with %s pointers",
13
+ async (pointer) => {
14
+ const f = invoiceRecipe("subscription_cycle", "open");
15
+ await prerequisites(f.h);
16
+ const positive = await inspectRenewalEvidenceV1(f.h.input);
17
+ expect(positive.invoiceEvidence.predicate).toBe("invoice_lines_correlated");
18
+
19
+ // Keep two otherwise valid period/item inventories. Every current relation
20
+ // now names I0, so a foreign-ID refusal cannot mask the missing invariant.
21
+ const id = f.originalInvoice.id;
22
+ set(f.currentInvoice, "id", id);
23
+ set(f.currentLine, "invoice", id);
24
+ set(f.currentPages[0], "url", `/v1/invoices/${id}/lines`);
25
+ set(
26
+ object(f.h.input.reads.subscription),
27
+ "latest_invoice",
28
+ pointer === "string"
29
+ ? id
30
+ : pointer === "minimal-expanded"
31
+ ? { id, object: "invoice" }
32
+ : structuredClone(f.currentInvoice),
33
+ );
34
+ const before = bounded(f.h.input);
35
+ const result = await inspectRenewalEvidenceV1(f.h.input);
36
+ expect(result.invoiceEvidence).toEqual({
37
+ predicate: "conflict",
38
+ original: null,
39
+ current: null,
40
+ reason: "invoice_relation_mismatch",
41
+ });
42
+ expect(result.operationalAuthority).toBe(false);
43
+ expect(result.authenticationEstablished).toBe(false);
44
+ expect(result.acknowledgementEstablished).toBe(false);
45
+ expect(Reflect.ownKeys(result)).toHaveLength(12);
46
+ expect(f.h.input).toEqual(before);
47
+ },
48
+ );
@@ -184,6 +184,7 @@ export async function inspectInvoiceEvidenceV1(
184
184
  };
185
185
  const originalInvoiceId = invoiceId(originalSub.latest_invoice),
186
186
  currentInvoiceId = invoiceId(sub.latest_invoice);
187
+ relation(originalInvoiceId !== currentInvoiceId);
187
188
  const examine = (role: "original" | "current") => {
188
189
  const row = closed(inventory[role], ["invoice", "linePages"]);
189
190
  const invoice = invoiceRecordV1(row.invoice);