@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,321 @@
1
+ import {
2
+ configureAdmissionFixture,
3
+ admissionControls,
4
+ } from "../test-fixtures/producerConfigureAdmission.js";
5
+ import { expect, it, vi } from "vitest";
6
+ import { components } from "../../../../../../example/convex/_generated/api.js";
7
+ import { createAdmittedConfigureEventCompiler } from "../c10/configureEvents.js";
8
+ import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
9
+ import { constructRenewalConfigurationReceiptV2 } from "../../../renewalV2/index.js";
10
+ import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
11
+
12
+ it.each(["absent", "null", "object"])(
13
+ "appends a distinct configure C10 sequence with %s defaults through actual component commits",
14
+ async (defaults) => {
15
+ await configureAdmissionFixture(async (h) => {
16
+ await h.complete();
17
+ const child = await h.child();
18
+ const admitted = await h.core.admitConfigure(
19
+ child.fresh.call,
20
+ child.journal,
21
+ );
22
+ const events = createAdmittedConfigureEventCompiler(admitted);
23
+ const request = child.record.configureRecord.request;
24
+ const transport = {
25
+ status: 200,
26
+ requestId: "req_synthetic_configure_channel",
27
+ };
28
+ const body: Record<string, unknown> = structuredClone(
29
+ h.baseline.schedule,
30
+ );
31
+ if (defaults === "absent") delete body.default_settings;
32
+ if (defaults === "null") body.default_settings = null;
33
+ body.future_response = { retained: [null, "complete", 1.25] };
34
+ const receipt = await constructRenewalConfigurationReceiptV2({
35
+ configuration: child.record.configureRecord.configuration,
36
+ actualDispatch: child.record.dispatch,
37
+ providerSnapshot: body,
38
+ transport,
39
+ });
40
+ const values = [
41
+ { event: "dispatch", stage: "configure", request },
42
+ {
43
+ event: "response",
44
+ stage: "configure",
45
+ request,
46
+ body,
47
+ transport,
48
+ },
49
+ { event: "receipt", stage: "configure", request, receipt },
50
+ ];
51
+ if (child.fresh.result.disposition !== "acquired")
52
+ throw Error("INVALID_FIXTURE_CAS");
53
+ const reservation = child.fresh.result.reservation;
54
+ const calls = h.calls.length,
55
+ selectors = admissionControls.selectors;
56
+ for (const [index, method] of [
57
+ events.dispatch,
58
+ events.response,
59
+ events.receipt,
60
+ ].entries()) {
61
+ if (index === 2)
62
+ await child.journal.retainProviderAcknowledgement({
63
+ attemptId: reservation.attemptId,
64
+ expectedSequence: 2,
65
+ receiptJSON: JSON.stringify(renewalSnapshot(receipt)),
66
+ });
67
+ const result = await method(values[index]);
68
+ expect(result).toEqual({
69
+ kind: "C10_EVENT_DATA_APPENDED",
70
+ stageChannel: "configure",
71
+ actualFulfillmentEstablished: false,
72
+ authenticationEstablished: false,
73
+ });
74
+ const stored = await child.journal.readStageEvent({
75
+ attemptId: reservation.attemptId,
76
+ sequence: index === 0 ? 1 : index === 1 ? 2 : 3,
77
+ });
78
+ expect(stored?.dataJSON).toBe(
79
+ JSON.stringify(renewalSnapshot(values[index])),
80
+ );
81
+ }
82
+ const history = await child.journal.readAttempt({
83
+ attemptId: reservation.attemptId,
84
+ });
85
+ expect(history?.events.map((event) => event.stage)).toEqual([
86
+ "configure",
87
+ "configure",
88
+ "configure",
89
+ ]);
90
+ const known = await child.journal.readProviderAcknowledgement();
91
+ expect(known?.receiptJSON).toBe(JSON.stringify(renewalSnapshot(receipt)));
92
+ if (h.fresh.result.disposition !== "acquired")
93
+ throw Error("INVALID_FIXTURE_PARENT");
94
+ expect(admitted.owner).toBe(h.core.owner);
95
+ const parent = await h.journal.readAttempt({
96
+ attemptId: h.fresh.result.reservation.attemptId,
97
+ });
98
+ expect(parent?.events.map((event) => event.stage)).toEqual([
99
+ "attach",
100
+ "attach",
101
+ "attach",
102
+ ]);
103
+ expect(h.calls).toHaveLength(calls);
104
+ expect(admissionControls.selectors).toBe(selectors);
105
+ expect(admissionControls.legacy).toBe(0);
106
+ expect(admitted.operationalAuthority).toBe(false);
107
+ });
108
+ },
109
+ );
110
+
111
+ it("a pending child append does not become another child's pending work", 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 one = await h.child(),
125
+ two = await h.child();
126
+ const a = await h.core.admitConfigure(one.fresh.call, one.journal),
127
+ b = await h.core.admitConfigure(two.fresh.call, two.journal);
128
+ const first = createAdmittedConfigureEventCompiler(a),
129
+ second = createAdmittedConfigureEventCompiler(b);
130
+ const av = await h.eventsFor(one),
131
+ bv = await h.eventsFor(two);
132
+ const aw = journalWorkForConfigureLineage(a),
133
+ bw = journalWorkForConfigureLineage(b);
134
+ armed = true;
135
+ const pending = first.dispatch(av.dispatch);
136
+ try {
137
+ await reached;
138
+ expect(aw.idle()).toBe(false);
139
+ expect(bw.idle()).toBe(true);
140
+ await second.dispatch(bv.dispatch);
141
+ expect(bw.idle()).toBe(true);
142
+ expect(aw.idle()).toBe(false);
143
+ } finally {
144
+ release();
145
+ }
146
+ await pending;
147
+ expect(aw.idle()).toBe(true);
148
+ expect(admissionControls.legacy).toBe(0);
149
+ },
150
+ {
151
+ afterAppend: async () => {
152
+ if (armed) {
153
+ armed = false;
154
+ entered();
155
+ await barrier;
156
+ }
157
+ },
158
+ },
159
+ );
160
+ });
161
+ it("concurrent child channels retain independent source requests and sequence heads", async () => {
162
+ await configureAdmissionFixture(async (h) => {
163
+ await h.complete();
164
+ const one = await h.child(),
165
+ two = await h.child();
166
+ const a = await h.core.admitConfigure(one.fresh.call, one.journal),
167
+ b = await h.core.admitConfigure(two.fresh.call, two.journal);
168
+ const first = createAdmittedConfigureEventCompiler(a),
169
+ second = createAdmittedConfigureEventCompiler(b);
170
+ const av = await h.eventsFor(one),
171
+ bv = await h.eventsFor(two);
172
+ await Promise.all([
173
+ first.dispatch(av.dispatch),
174
+ second.dispatch(bv.dispatch),
175
+ ]);
176
+ await Promise.all([
177
+ first.response(av.response),
178
+ second.response(bv.response),
179
+ ]);
180
+ await Promise.all([
181
+ first.receipt(av.receiptEvent),
182
+ second.receipt(bv.receiptEvent),
183
+ ]);
184
+ if (
185
+ one.fresh.result.disposition !== "acquired" ||
186
+ two.fresh.result.disposition !== "acquired"
187
+ )
188
+ throw Error("INVALID_FIXTURE_CAS");
189
+ const ah = await one.journal.readAttempt({
190
+ attemptId: one.fresh.result.reservation.attemptId,
191
+ }),
192
+ bh = await two.journal.readAttempt({
193
+ attemptId: two.fresh.result.reservation.attemptId,
194
+ });
195
+ expect(ah?.events).toHaveLength(3);
196
+ expect(bh?.events).toHaveLength(3);
197
+ expect(ah?.events[0].eventId).not.toBe(bh?.events[0].eventId);
198
+ expect(av.receipt.binding).not.toBe(bv.receipt.binding);
199
+ expect(a.owner === b.owner).toBe(true);
200
+ expect(() => h.core.owner.check()).not.toThrow();
201
+ });
202
+ });
203
+ it("closing one SDK root cannot close another root's configure channel", async () => {
204
+ let joined = 0,
205
+ release!: () => void,
206
+ retired!: () => void;
207
+ const ready = new Promise<void>((resolve) => {
208
+ release = resolve;
209
+ });
210
+ const closed = new Promise<void>((resolve) => {
211
+ retired = resolve;
212
+ });
213
+ await configureAdmissionFixture(
214
+ async (h) => {
215
+ await h.complete();
216
+ const child = await h.child();
217
+ const token = await h.core.admitConfigure(
218
+ child.fresh.call,
219
+ child.journal,
220
+ );
221
+ const compiler = createAdmittedConfigureEventCompiler(token),
222
+ values = await h.eventsFor(child);
223
+ await compiler.dispatch(values.dispatch);
224
+ if (++joined === 2) release();
225
+ await ready;
226
+ if (h.index === 0) {
227
+ h.core.owner.retire();
228
+ retired();
229
+ await expect(compiler.response(values.response)).rejects.toThrow(
230
+ "C10_SOURCE_STOP",
231
+ );
232
+ } else {
233
+ await closed;
234
+ await compiler.response(values.response);
235
+ await compiler.receipt(values.receiptEvent);
236
+ }
237
+ if (child.fresh.result.disposition !== "acquired")
238
+ throw Error("INVALID_FIXTURE_CAS");
239
+ expect(
240
+ (
241
+ await child.journal.readAttempt({
242
+ attemptId: child.fresh.result.reservation.attemptId,
243
+ })
244
+ )?.events,
245
+ ).toHaveLength(h.index === 0 ? 1 : 3);
246
+ },
247
+ {
248
+ count: 2,
249
+ keys: [
250
+ "sk_test_invalid_channel_root_a",
251
+ "sk_test_invalid_channel_root_b",
252
+ ],
253
+ },
254
+ );
255
+ });
256
+
257
+ it("rechecks the child binding after an actual constructor hash await before appending", async () => {
258
+ await configureAdmissionFixture(async (h) => {
259
+ await h.complete();
260
+ await h.inAnotherAction(async (ctx) => {
261
+ const child = await h.child({ ctx });
262
+ const token = await h.core.admitConfigure(
263
+ child.fresh.call,
264
+ child.journal,
265
+ );
266
+ const compiler = createAdmittedConfigureEventCompiler(token),
267
+ values = await h.eventsFor(child);
268
+ let entered!: () => void,
269
+ release!: () => void,
270
+ first = true;
271
+ const reached = new Promise<void>((resolve) => {
272
+ entered = resolve;
273
+ });
274
+ const barrier = new Promise<void>((resolve) => {
275
+ release = resolve;
276
+ });
277
+ const original = globalThis.crypto.subtle.digest.bind(
278
+ globalThis.crypto.subtle,
279
+ );
280
+ const digest = vi
281
+ .spyOn(globalThis.crypto.subtle, "digest")
282
+ .mockImplementation(async (...args) => {
283
+ const result = await original(...args);
284
+ if (first) {
285
+ first = false;
286
+ entered();
287
+ await barrier;
288
+ }
289
+ return result;
290
+ });
291
+ const pending = compiler.dispatch(values.dispatch);
292
+ const refused = expect(pending).rejects.toThrow("C10_SOURCE_STOP");
293
+ const query = ctx.runQuery;
294
+ try {
295
+ await reached;
296
+ ctx.runQuery = async () => {
297
+ throw Error("CHANGED_DURING_HASH");
298
+ };
299
+ expect(() => h.core.owner.check()).not.toThrow();
300
+ } finally {
301
+ release();
302
+ }
303
+ await refused;
304
+ ctx.runQuery = query;
305
+ digest.mockRestore();
306
+ if (child.fresh.result.disposition !== "acquired")
307
+ throw Error("INVALID_FIXTURE_CAS");
308
+ const history = await ctx.runQuery(
309
+ components.betterStripe.renewalOperations.queries.readAttempt,
310
+ {
311
+ operationId: child.created.operationId,
312
+ attemptId: child.fresh.result.reservation.attemptId,
313
+ },
314
+ );
315
+ expect(history?.events).toHaveLength(0);
316
+ expect(() => createAdmittedConfigureEventCompiler(token)).toThrow(
317
+ "CONFIGURE_CHANNEL_CONSUMED",
318
+ );
319
+ });
320
+ });
321
+ });
@@ -0,0 +1,67 @@
1
+ import {
2
+ configureAdmissionFixture,
3
+ admissionControls,
4
+ } from "../test-fixtures/producerConfigureAdmission.js";
5
+ import { expect, it } from "vitest";
6
+ import {
7
+ captureAdmittedConfigurePreflight,
8
+ readAdmittedConfigurePreflight,
9
+ } from "./configurePreflight.js";
10
+
11
+ it.each(["initial", "replay", "resume"] as const)(
12
+ "runs fixed readonly configure preflight after %s ACK with actual returned custody",
13
+ async (mode) => {
14
+ await configureAdmissionFixture(async (h) => {
15
+ await h.complete(mode);
16
+ const child = await h.child();
17
+ const token = await h.core.admitConfigure(
18
+ child.fresh.call,
19
+ child.journal,
20
+ );
21
+ h.configureReads(child);
22
+ admissionControls.preflight.push({
23
+ originalEntry: admissionControls.entries[0],
24
+ coversPreflight: () => true,
25
+ });
26
+ const start = h.calls.length,
27
+ selectors = admissionControls.selectors,
28
+ basis = h.core.basisJSON;
29
+ const actor = captureAdmittedConfigurePreflight(token);
30
+ expect(actor).not.toBeNull();
31
+ const output = await actor.invoke();
32
+ expect(output.status).toBe("configure_preflight_consistent");
33
+ expect(output.request).toEqual(child.record.configureRecord.request);
34
+ expect(output.currentEvidence.observedAt).toBe(
35
+ h.baseline.configurationTime,
36
+ );
37
+ expect(output.operationalAuthority).toBe(false);
38
+ const view = readAdmittedConfigurePreflight(token);
39
+ expect(view.output === output).toBe(true);
40
+ expect(view.originalEntry === admissionControls.entries[0]).toBe(true);
41
+ expect(
42
+ view.coversPreflight === admissionControls.preflight[0].coversPreflight,
43
+ ).toBe(true);
44
+ expect(view.acknowledgement === h.core.attachAcknowledgement()).toBe(
45
+ true,
46
+ );
47
+ expect(
48
+ h.calls.slice(start).map((row) => row.method + ":" + row.path),
49
+ ).toEqual([
50
+ "GET:/v1/subscriptions/sub_original",
51
+ "GET:/v1/prices/price_target",
52
+ "GET:/v1/customers/cus_buyer",
53
+ ...h.source.originalBundle.couponReads.map(
54
+ (row) =>
55
+ "GET:/v1/coupons/" + encodeURIComponent(String(row.couponId)),
56
+ ),
57
+ "GET:/v1/subscription_schedules/" + h.baseline.schedule.id,
58
+ ]);
59
+ expect(h.calls.slice(start).every((row) => row.hasBody === false)).toBe(
60
+ true,
61
+ );
62
+ expect(admissionControls.selectors).toBe(selectors);
63
+ expect(admissionControls.legacy).toBe(0);
64
+ expect(h.core.basisJSON).toBe(basis);
65
+ });
66
+ },
67
+ );