@fantastic.dev/better-stripe 0.93.0 → 0.95.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 (57) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts +47 -0
  4. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/operationJournal.js +388 -0
  6. package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +24 -5
  8. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +182 -4
  10. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +13 -0
  12. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +43 -0
  14. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +32 -0
  16. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +105 -0
  18. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -0
  19. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts +3 -0
  20. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js +59 -0
  22. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts +11 -0
  24. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js +121 -0
  26. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +6 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +16 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -0
  31. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  32. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  33. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  34. package/dist/component/balanceFunding/mutations.d.ts +43 -43
  35. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  36. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  37. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  38. package/docs/renewal-context-reads.md +57 -5
  39. package/package.json +1 -1
  40. package/src/client/billing/renewalAttach/internal/operationJournal.acknowledgement.integration.test.ts +500 -0
  41. package/src/client/billing/renewalAttach/internal/operationJournal.c10.integration.test.ts +560 -0
  42. package/src/client/billing/renewalAttach/internal/operationJournal.controls.integration.test.ts +356 -0
  43. package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +181 -1
  44. package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
  45. package/src/client/billing/renewalAttach/internal/operationJournal.ts +573 -0
  46. package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +246 -8
  47. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +58 -0
  48. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +161 -0
  49. package/src/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.ts +54 -0
  50. package/src/client/billing/renewalAttach/internal/producer/ownerFactory.ts +124 -0
  51. package/src/client/billing/renewalAttach/internal/producer/producerGuards.integration.test.ts +323 -0
  52. package/src/client/billing/renewalAttach/internal/producer/producerInitial.integration.test.ts +301 -0
  53. package/src/client/billing/renewalAttach/internal/producer/producerIsolation.integration.test.ts +531 -0
  54. package/src/client/billing/renewalAttach/internal/producer/producerOwner.integration.test.ts +457 -0
  55. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +23 -0
  56. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialDeclarations.ts +5 -0
  57. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +80 -0
@@ -0,0 +1,457 @@
1
+ import assert from "node:assert/strict";
2
+ import Stripe from "stripe";
3
+ import { getStripeClient } from "../../../../helpers.js";
4
+ import { afterEach, beforeEach, expect, it, vi } from "vitest";
5
+ import { initialOperations } from "../test-fixtures/producerInitialOperation.js";
6
+ import {
7
+ captureInitialInvocationCore,
8
+ type InitialInvocationCore,
9
+ } from "./invocationProducer.js";
10
+ import {
11
+ INITIAL_WALL,
12
+ INITIAL_NS,
13
+ WORK_WALL,
14
+ } from "../test-fixtures/producerInitialDeclarations.js";
15
+
16
+ let monotonic = INITIAL_NS;
17
+ beforeEach(() => {
18
+ vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
19
+ vi.setSystemTime(INITIAL_WALL);
20
+ monotonic = INITIAL_NS;
21
+ vi.spyOn(process.hrtime, "bigint").mockImplementation(() => monotonic);
22
+ });
23
+
24
+ it.each(["wall", "monotonic"] as const)(
25
+ "%s regression irreversibly retires only its Owner",
26
+ async (clock) => {
27
+ await initialOperations(async ({ fresh, journal }) => {
28
+ const core = await captureInitialInvocationCore(fresh.call, journal);
29
+ vi.setSystemTime(INITIAL_WALL + 1);
30
+ monotonic = INITIAL_NS + 1n;
31
+ core.owner.check();
32
+ if (clock === "wall") vi.setSystemTime(INITIAL_WALL);
33
+ else monotonic = INITIAL_NS;
34
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
35
+ vi.setSystemTime(INITIAL_WALL + 2);
36
+ monotonic = INITIAL_NS + 2n;
37
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
38
+ });
39
+ },
40
+ );
41
+
42
+ it.each(["wall", "monotonic"] as const)(
43
+ "the %s work cutoff independently refuses at equality",
44
+ async (clock) => {
45
+ await initialOperations(async ({ fresh, journal }) => {
46
+ const core = await captureInitialInvocationCore(fresh.call, journal);
47
+ if (clock === "wall") vi.setSystemTime(WORK_WALL);
48
+ else monotonic = core.owner.basis.workEndNs;
49
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
50
+ expect(() => core.owned(() => "unreachable")).toThrow();
51
+ });
52
+ },
53
+ );
54
+
55
+ it("rejects an extra replacement-client argument before clocks and spends custody", async () => {
56
+ await initialOperations(async ({ fresh, journal }) => {
57
+ const foreignClient = new Stripe("sk_test_invalid_foreign_owner_core");
58
+ const now = vi.spyOn(Date, "now");
59
+ const before = now.mock.calls.length;
60
+ await expect(
61
+ Reflect.apply(captureInitialInvocationCore, undefined, [
62
+ fresh.call,
63
+ journal,
64
+ foreignClient,
65
+ ]),
66
+ ).rejects.toThrow();
67
+ expect(now.mock.calls.length).toBe(before);
68
+ await expect(
69
+ captureInitialInvocationCore(fresh.call, journal),
70
+ ).rejects.toThrow();
71
+ });
72
+ });
73
+
74
+ it.each(["wide aperture", "u64 overflow"] as const)(
75
+ "rejects %s without binding a replacement basis",
76
+ async (reason) => {
77
+ await initialOperations(async ({ fresh, journal }) => {
78
+ const read = vi.mocked(process.hrtime.bigint);
79
+ if (reason === "wide aperture") {
80
+ read
81
+ .mockReturnValueOnce(INITIAL_NS)
82
+ .mockReturnValueOnce(INITIAL_NS + 1000001n);
83
+ } else monotonic = 18446744073709551615n - 1n;
84
+ await expect(
85
+ captureInitialInvocationCore(fresh.call, journal),
86
+ ).rejects.toThrow();
87
+ const stored = await journal.loadAuthorizedOperation();
88
+ assert(stored && "initialBasis" in stored);
89
+ expect(stored.initialBasis).toBeNull();
90
+ monotonic = INITIAL_NS;
91
+ await expect(
92
+ captureInitialInvocationCore(fresh.call, journal),
93
+ ).rejects.toThrow();
94
+ });
95
+ },
96
+ );
97
+
98
+ it("does not mint from an existing component result or a copied handle", async () => {
99
+ await initialOperations(async ({ fresh, journal }) => {
100
+ assert(fresh.result.disposition === "acquired");
101
+ const reservation = fresh.result.reservation;
102
+ const existing = await journal.reserveFreshAttempt({
103
+ expectedRevision: 0,
104
+ stage: "attach",
105
+ expectedRequestBinding: reservation.requestBinding,
106
+ recordJSON: reservation.recordJSON,
107
+ });
108
+ expect(existing.call).toBeNull();
109
+ await expect(
110
+ captureInitialInvocationCore(existing.result, journal),
111
+ ).rejects.toThrow();
112
+ await expect(
113
+ captureInitialInvocationCore({ ...fresh.call }, journal),
114
+ ).rejects.toThrow();
115
+ const core = await captureInitialInvocationCore(fresh.call, journal);
116
+ expect(core.owner.check().retired).toBe(false);
117
+ core.owner.retire();
118
+ });
119
+ });
120
+
121
+ it("refuses descriptor-only configuration drift without reading a clock", async () => {
122
+ await initialOperations(async ({ fresh, journal, sdk }) => {
123
+ const before = Object.getOwnPropertyDescriptor(sdk, "stripeApiVersion");
124
+ assert(before);
125
+ const now = vi.spyOn(Date, "now");
126
+ const calls = now.mock.calls.length;
127
+ Object.defineProperty(sdk, "stripeApiVersion", {
128
+ ...before,
129
+ writable: false,
130
+ });
131
+ await expect(
132
+ captureInitialInvocationCore(fresh.call, journal),
133
+ ).rejects.toThrow();
134
+ expect(now.mock.calls.length).toBe(calls);
135
+ Object.defineProperty(sdk, "stripeApiVersion", before);
136
+ await expect(
137
+ captureInitialInvocationCore(fresh.call, journal),
138
+ ).rejects.toThrow();
139
+ });
140
+ });
141
+ afterEach(() => {
142
+ vi.useRealTimers();
143
+ vi.unstubAllGlobals();
144
+ vi.restoreAllMocks();
145
+ });
146
+
147
+ it("retains the selected stock method receiver through controlled HTTP despite a foreign call receiver", async () => {
148
+ await initialOperations(async ({ fresh, journal, sdk }) => {
149
+ const requests: {
150
+ method: string | undefined;
151
+ authorization: string | null;
152
+ version: string | null;
153
+ redirect: RequestRedirect | undefined;
154
+ }[] = [];
155
+ vi.stubGlobal(
156
+ "fetch",
157
+ async (_input: RequestInfo | URL, init?: RequestInit) => {
158
+ const headers = new Headers(init?.headers);
159
+ requests.push({
160
+ method: init?.method,
161
+ authorization: headers.get("authorization"),
162
+ version: headers.get("stripe-version"),
163
+ redirect: init?.redirect,
164
+ });
165
+ return new Response(
166
+ JSON.stringify({
167
+ id: "sub_owner_receiver_probe",
168
+ object: "subscription",
169
+ }),
170
+ {
171
+ status: 200,
172
+ headers: {
173
+ "content-type": "application/json",
174
+ "request-id": "req_owner_receiver_probe",
175
+ },
176
+ },
177
+ );
178
+ },
179
+ );
180
+ const foreign = getStripeClient(
181
+ "sk_test_invalid_foreign_receiver",
182
+ sdk.stripeApiVersion,
183
+ { singleAttempt: true },
184
+ );
185
+ const core = await captureInitialInvocationCore(fresh.call, journal);
186
+ try {
187
+ const reply = await core.delegate.rawRequest.call(
188
+ foreign,
189
+ "GET",
190
+ "/v1/subscriptions/sub_owner_receiver_probe",
191
+ undefined,
192
+ {
193
+ apiVersion: sdk.stripeApiVersion,
194
+ maxNetworkRetries: 0,
195
+ },
196
+ );
197
+ expect(reply).toMatchObject({
198
+ id: "sub_owner_receiver_probe",
199
+ object: "subscription",
200
+ });
201
+ expect(requests).toEqual([
202
+ {
203
+ method: "GET",
204
+ authorization: "Bearer sk_test_invalid_owner_core",
205
+ version: sdk.stripeApiVersion,
206
+ redirect: "error",
207
+ },
208
+ ]);
209
+ core.owner.retire();
210
+ expect(() =>
211
+ core.delegate.rawRequest(
212
+ "GET",
213
+ "/v1/subscriptions/sub_owner_receiver_probe",
214
+ ),
215
+ ).toThrow("INITIAL_OWNER_STOP");
216
+ expect(requests).toHaveLength(1);
217
+ } finally {
218
+ core.owner.retire();
219
+ }
220
+ });
221
+ });
222
+
223
+ it("binds the actual fresh call to an isolated Owner with the original absolute cutoffs", async () => {
224
+ await initialOperations(async ({ fresh, journal }) => {
225
+ const core = await captureInitialInvocationCore(fresh.call, journal);
226
+ expect(core).not.toBeNull();
227
+ assert(core);
228
+ const basis = core.owner.basis;
229
+ expect(basis.startWallMs).toBe(1700000002000);
230
+ expect(basis.workEndWallMs).toBe(1700000005000);
231
+ expect(basis.endWallMs).toBe(1700000006000);
232
+ expect(basis.workEndNs - basis.startNs).toBe(3000000000n);
233
+ expect(basis.endNs - basis.startNs).toBe(4000000000n);
234
+ expect(core.operationalAuthority).toBe(false);
235
+ expect(core.owner.sample).toBe(core.owner.check);
236
+ expect(core.owner.check()).toMatchObject({
237
+ nowSeconds: 1700000002,
238
+ retired: false,
239
+ });
240
+ const stored = await journal.loadAuthorizedOperation();
241
+ assert(stored && "initialBasis" in stored);
242
+ expect(stored.initialBasis?.basisJSON).toBe(core.basisJSON);
243
+ await expect(
244
+ captureInitialInvocationCore(fresh.call, journal),
245
+ ).rejects.toThrow();
246
+ core.owner.retire();
247
+ expect(() => core.owner.check()).toThrow();
248
+ });
249
+ });
250
+
251
+ it("retiring one operation does not retire a second Owner or its pending work", async () => {
252
+ const cores: InitialInvocationCore[] = [];
253
+ await initialOperations(async ({ fresh, journal }) => {
254
+ const core = await captureInitialInvocationCore(fresh.call, journal);
255
+ assert(core);
256
+ cores.push(core);
257
+ if (cores.length !== 2) return;
258
+ const [first, second] = cores;
259
+ expect(first.owner).not.toBe(second.owner);
260
+ let resolve = (_value: string) => {};
261
+ const work = new Promise<string>((done) => {
262
+ resolve = done;
263
+ });
264
+ const stopped = first.owned(() => work);
265
+ const live = second.owned(() => work);
266
+ const rejection = expect(stopped).rejects.toThrow();
267
+ first.owner.retire();
268
+ await rejection;
269
+ expect(second.owner.check().retired).toBe(false);
270
+ resolve("complete");
271
+ await expect(live).resolves.toBe("complete");
272
+ second.owner.retire();
273
+ }, 2);
274
+ });
275
+
276
+ it("refuses changed SDK configuration after reservation and spends the winning call", async () => {
277
+ await initialOperations(async ({ fresh, journal, sdk }) => {
278
+ const original = Object.getOwnPropertyDescriptor(sdk, "_apiKey");
279
+ assert(original);
280
+ let reads = 0;
281
+ Object.defineProperty(sdk, "_apiKey", {
282
+ configurable: true,
283
+ enumerable: true,
284
+ get() {
285
+ reads++;
286
+ throw Error("SELECTOR_TOUCHED");
287
+ },
288
+ });
289
+ await expect(
290
+ captureInitialInvocationCore(fresh.call, journal),
291
+ ).rejects.toThrow();
292
+ expect(reads).toBe(0);
293
+ Object.defineProperty(sdk, "_apiKey", original);
294
+ await expect(
295
+ captureInitialInvocationCore(fresh.call, journal),
296
+ ).rejects.toThrow();
297
+ const stored = await journal.loadAuthorizedOperation();
298
+ assert(stored && "initialBasis" in stored);
299
+ expect(stored.initialBasis).toBeNull();
300
+ });
301
+ });
302
+
303
+ it("work deadline retirement is exclusive, irreversible and not reset by a backward wall jump", async () => {
304
+ await initialOperations(async ({ fresh, journal }) => {
305
+ const core = await captureInitialInvocationCore(fresh.call, journal);
306
+ assert(core);
307
+ let retired = 0;
308
+ core.owner.subscribe(() => {
309
+ retired++;
310
+ });
311
+ vi.advanceTimersByTime(3000);
312
+ expect(retired).toBe(1);
313
+ expect(() => core.owner.check()).toThrow();
314
+ vi.setSystemTime(1700000002000);
315
+ expect(() => core.owner.check()).toThrow();
316
+ core.owner.retire();
317
+ expect(retired).toBe(1);
318
+ });
319
+ });
320
+
321
+ it("two overlapping registered-Action operations keep distinct canonical Owners", async () => {
322
+ const cores: InitialInvocationCore[] = [];
323
+ let release = () => {};
324
+ const both = new Promise<void>((resolve) => {
325
+ release = resolve;
326
+ });
327
+ await initialOperations(async ({ fresh, journal }) => {
328
+ const core = await captureInitialInvocationCore(fresh.call, journal);
329
+ cores.push(core);
330
+ if (cores.length === 2) release();
331
+ await both;
332
+ expect(cores).toHaveLength(2);
333
+ expect(cores[0].owner).not.toBe(cores[1].owner);
334
+ expect(cores[0].owner.basis).not.toBe(cores[1].owner.basis);
335
+ expect(
336
+ await core.owned(async () => {
337
+ await Promise.resolve();
338
+ return core.owner.check().nowSeconds;
339
+ }),
340
+ ).toBe(1700000002);
341
+ core.owner.retire();
342
+ }, 2);
343
+ });
344
+
345
+ it("configuration drift during a continuation closes the Owner before returning a value", async () => {
346
+ await initialOperations(async ({ fresh, journal, sdk }) => {
347
+ const core = await captureInitialInvocationCore(fresh.call, journal);
348
+ const descriptor = Object.getOwnPropertyDescriptor(sdk, "_apiKey");
349
+ assert(descriptor);
350
+ let release = () => {};
351
+ const pending = core.owned(
352
+ () =>
353
+ new Promise<string>((resolve) => {
354
+ release = () => resolve("must not return");
355
+ }),
356
+ );
357
+ const rejection = expect(pending).rejects.toThrow("INITIAL_OWNER_STOP");
358
+ Object.defineProperty(sdk, "_apiKey", {
359
+ ...descriptor,
360
+ value: "sk_test_other_root_configuration",
361
+ });
362
+ release();
363
+ await rejection;
364
+ Object.defineProperty(sdk, "_apiKey", descriptor);
365
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
366
+ });
367
+ });
368
+
369
+ it("refuses a conflicting already-bound basis without changing retained history", async () => {
370
+ await initialOperations(async ({ fresh, journal }) => {
371
+ assert(fresh.result.disposition === "acquired");
372
+ const reservation = fresh.result.reservation;
373
+ assert("timingPolicyJSON" in reservation);
374
+ await journal.bindInitialBasis({
375
+ attemptId: reservation.attemptId,
376
+ policyJSON: reservation.timingPolicyJSON,
377
+ basisJSON: JSON.stringify({
378
+ startWallMs: INITIAL_WALL,
379
+ startNsDecimal: "100",
380
+ workEndWallMs: WORK_WALL,
381
+ workEndNsDecimal: "3000000100",
382
+ endWallMs: 1700000006000,
383
+ endNsDecimal: "4000000100",
384
+ }),
385
+ });
386
+ const before = await journal.loadAuthorizedOperation();
387
+ await expect(
388
+ captureInitialInvocationCore(fresh.call, journal),
389
+ ).rejects.toThrow();
390
+ expect(await journal.loadAuthorizedOperation()).toEqual(before);
391
+ await expect(
392
+ captureInitialInvocationCore(fresh.call, journal),
393
+ ).rejects.toThrow();
394
+ });
395
+ });
396
+
397
+ it("keeps duplicate waiter registrations independent and notifies each once", async () => {
398
+ await initialOperations(async ({ fresh, journal }) => {
399
+ const core = await captureInitialInvocationCore(fresh.call, journal);
400
+ let calls = 0;
401
+ const waiter = () => {
402
+ calls++;
403
+ };
404
+ core.owner.subscribe(waiter);
405
+ core.owner.subscribe(waiter);
406
+ const remove = core.owner.subscribe(waiter);
407
+ remove();
408
+ remove();
409
+ core.owner.retire();
410
+ expect(calls).toBe(2);
411
+ core.owner.retire();
412
+ expect(calls).toBe(2);
413
+ core.owner.subscribe(waiter);
414
+ expect(calls).toBe(3);
415
+ });
416
+ });
417
+
418
+ it("refuses a monotonic regression below the high capture sample before basis binding", async () => {
419
+ await initialOperations(async ({ fresh, journal }) => {
420
+ vi.mocked(process.hrtime.bigint)
421
+ .mockReturnValueOnce(INITIAL_NS)
422
+ .mockReturnValueOnce(INITIAL_NS + 100n);
423
+ await expect(
424
+ captureInitialInvocationCore(fresh.call, journal),
425
+ ).rejects.toThrow();
426
+ const stored = await journal.loadAuthorizedOperation();
427
+ assert(stored && "initialBasis" in stored);
428
+ expect(stored.initialBasis).toBeNull();
429
+ });
430
+ });
431
+
432
+ it("notifies waiters without exposing a callback receiver", async () => {
433
+ await initialOperations(async ({ fresh, journal }) => {
434
+ const core = await captureInitialInvocationCore(fresh.call, journal);
435
+ const receivers: unknown[] = [];
436
+ core.owner.subscribe(function (this: unknown) {
437
+ receivers.push(this);
438
+ });
439
+ core.owner.retire();
440
+ expect(receivers).toEqual([undefined]);
441
+ });
442
+ });
443
+
444
+ it("rejects proxy waiters without invoking their apply trap", async () => {
445
+ await initialOperations(async ({ fresh, journal }) => {
446
+ const core = await captureInitialInvocationCore(fresh.call, journal);
447
+ let traps = 0;
448
+ const proxy = new Proxy(() => {}, {
449
+ apply() {
450
+ traps++;
451
+ },
452
+ });
453
+ expect(() => core.owner.subscribe(proxy)).toThrow("INITIAL_OWNER_STOP");
454
+ expect(traps).toBe(0);
455
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
456
+ });
457
+ });
@@ -0,0 +1,23 @@
1
+ import type Stripe from "stripe";
2
+ import { readInitialLineage } from "./lineageAuthority.js";
3
+ import { ownerForInitialLineage } from "./ownerFactory.js";
4
+ import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
5
+
6
+ /** Fixed selected client and original receiver; no replacement-client parameter. */
7
+ export function stockDelegateForInitialLineage(token: object): Readonly<{
8
+ rawRequest: Stripe["rawRequest"];
9
+ }> {
10
+ const lineage = readInitialLineage(token);
11
+ const owner = ownerForInitialLineage(token);
12
+ const owned = ownedAwaitForInitialLineage(token);
13
+ return Object.freeze({
14
+ rawRequest(
15
+ ...args: Parameters<Stripe["rawRequest"]>
16
+ ): ReturnType<Stripe["rawRequest"]> {
17
+ owner.check();
18
+ return owned(() =>
19
+ Reflect.apply(lineage.method, lineage.client, args),
20
+ ) as ReturnType<Stripe["rawRequest"]>;
21
+ },
22
+ });
23
+ }
@@ -0,0 +1,5 @@
1
+ // Independent synthetic declarations for construction-only Node tests.
2
+ export const INITIAL_WALL = 1700000002000;
3
+ export const INITIAL_NS = 1000000000n;
4
+ export const WORK_WALL = 1700000005000;
5
+ export const END_WALL = 1700000006000;
@@ -0,0 +1,80 @@
1
+ import assert from "node:assert/strict";
2
+ import { convexTest } from "convex-test";
3
+ import {
4
+ actionGeneric,
5
+ defineSchema,
6
+ makeFunctionReference,
7
+ } from "convex/server";
8
+ import { BetterStripe } from "../../../../index.js";
9
+ import { components } from "../../../../../../example/convex/_generated/api.js";
10
+ import { modules, schema } from "../../../../../test.js";
11
+ import {
12
+ canonical,
13
+ codecFixture,
14
+ } from "../../../../../component/renewalOperations/timingPolicy.fixtures.js";
15
+ import { createClassActionOperationJournal } from "../operationJournal.js";
16
+
17
+ type Journal = Awaited<ReturnType<typeof createClassActionOperationJournal>>;
18
+ type Fresh = Awaited<ReturnType<Journal["reserveFreshAttempt"]>>;
19
+ export async function initialOperations(
20
+ work: (input: {
21
+ journal: Journal;
22
+ fresh: Fresh;
23
+ sdk: BetterStripe;
24
+ index: number;
25
+ }) => Promise<void>,
26
+ count = 1,
27
+ ) {
28
+ const h = await codecFixture();
29
+ const sdk = new BetterStripe(components.betterStripe, {
30
+ STRIPE_SECRET_KEY: "sk_test_invalid_owner_core",
31
+ });
32
+ const refs = components.betterStripe.renewalOperations;
33
+ const host = {
34
+ run: actionGeneric({
35
+ args: {},
36
+ handler: async (ctx): Promise<null> => {
37
+ await Promise.all(
38
+ Array.from({ length: count }, async (_, index) => {
39
+ const logicalOperationId =
40
+ h.record.logicalOperationId + "-owner-" + index;
41
+ const recordJSON = canonical({ ...h.record, logicalOperationId });
42
+ const created = await ctx.runMutation(
43
+ refs.mutations.createAuthorizedOperation,
44
+ {
45
+ authorizationScope: h.record.authorization.scope,
46
+ authorizationRevision: h.record.authorization.revision,
47
+ logicalOperationId,
48
+ recordJSON,
49
+ },
50
+ );
51
+ assert(created.status === "created");
52
+ const journal = await createClassActionOperationJournal(sdk, {
53
+ actualActionCtx: ctx,
54
+ operationId: created.operationId,
55
+ });
56
+ const fresh = await journal.reserveFreshAttempt({
57
+ expectedRevision: 0,
58
+ stage: "attach",
59
+ expectedRequestBinding: h.record.requestBinding,
60
+ recordJSON,
61
+ });
62
+ assert(fresh.result.disposition === "acquired" && fresh.call);
63
+ await work({ journal, fresh, sdk, index });
64
+ }),
65
+ );
66
+ return null;
67
+ },
68
+ }),
69
+ };
70
+ const t = convexTest(defineSchema({}), {
71
+ "./_generated/api.ts": async () => ({}),
72
+ "./initialOwner.ts": async () => host,
73
+ });
74
+ t.registerComponent("betterStripe", schema, modules);
75
+ await t.action(
76
+ makeFunctionReference<"action", {}, null>("initialOwner:run"),
77
+ {},
78
+ );
79
+ assert(h.fetchCalls() === 0);
80
+ }