@fantastic.dev/better-stripe 0.97.0 → 0.98.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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +38 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts +11 -0
- package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/material/classifiers.js +57 -22
- package/dist/client/billing/renewalAttach/internal/material/classifiers.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +54 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +44 -37
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +71 -46
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +21 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +161 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +35 -4
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +42 -0
- package/src/client/billing/renewalAttach/internal/material/classifiers.ts +64 -22
- package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +55 -48
- package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +91 -55
- package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
- package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +25 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
- package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +175 -0
- package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
- package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
- package/src/client/billing/renewalAttach/internal/producer/producerMaterial.integration.test.ts +251 -0
- package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
- package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +100 -11
package/src/client/billing/renewalAttach/internal/producer/producerMaterial.integration.test.ts
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
3
|
+
import { initialOperations } from "../test-fixtures/producerInitialOperation.js";
|
|
4
|
+
import { declaredInputs } from "../test-fixtures/attachEntries.js";
|
|
5
|
+
import { INITIAL_NS } from "../test-fixtures/producerInitialDeclarations.js";
|
|
6
|
+
import {
|
|
7
|
+
captureInitialInvocationCore,
|
|
8
|
+
type InitialInvocationCore,
|
|
9
|
+
} from "./invocationProducer.js";
|
|
10
|
+
import {
|
|
11
|
+
prepareRenewalPriceReplacementV2,
|
|
12
|
+
prepareRenewalScheduleAttachmentV2,
|
|
13
|
+
} from "../../../renewalV2/index.js";
|
|
14
|
+
import { createInitialMaterialClassifiers } from "../material/classifiers.js";
|
|
15
|
+
|
|
16
|
+
const legacy = vi.hoisted(() => ({ touched: 0 }));
|
|
17
|
+
vi.mock("../originalOwner.js", () => ({
|
|
18
|
+
OWNER: Object.freeze({
|
|
19
|
+
get basis() {
|
|
20
|
+
legacy.touched++;
|
|
21
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
22
|
+
},
|
|
23
|
+
check() {
|
|
24
|
+
legacy.touched++;
|
|
25
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
26
|
+
},
|
|
27
|
+
sample() {
|
|
28
|
+
legacy.touched++;
|
|
29
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
30
|
+
},
|
|
31
|
+
subscribe() {
|
|
32
|
+
legacy.touched++;
|
|
33
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
34
|
+
},
|
|
35
|
+
retire() {
|
|
36
|
+
legacy.touched++;
|
|
37
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
}));
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
legacy.touched = 0;
|
|
43
|
+
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
|
|
44
|
+
vi.setSystemTime(
|
|
45
|
+
(declaredInputs("INITIAL-ACK").original.attachRequest.firstDispatchedAt +
|
|
46
|
+
1) *
|
|
47
|
+
1000,
|
|
48
|
+
);
|
|
49
|
+
vi.spyOn(process.hrtime, "bigint").mockReturnValue(INITIAL_NS);
|
|
50
|
+
});
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
vi.useRealTimers();
|
|
53
|
+
vi.unstubAllGlobals();
|
|
54
|
+
vi.restoreAllMocks();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("classifies original retained and fresh Coupon material with its actual invocation Owner", async () => {
|
|
58
|
+
const source = declaredInputs("INITIAL-ACK").original;
|
|
59
|
+
const prepared = await prepareRenewalPriceReplacementV2(
|
|
60
|
+
source.attachRequest.preparation,
|
|
61
|
+
);
|
|
62
|
+
const request = await prepareRenewalScheduleAttachmentV2({
|
|
63
|
+
prepared,
|
|
64
|
+
apiVersion: source.attachRequest.apiVersion,
|
|
65
|
+
attachKey: source.attachRequest.attachKey,
|
|
66
|
+
firstDispatchedAt: source.attachRequest.firstDispatchedAt,
|
|
67
|
+
});
|
|
68
|
+
await initialOperations(
|
|
69
|
+
async ({ fresh, journal }) => {
|
|
70
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
71
|
+
try {
|
|
72
|
+
expect(core.material).toBeDefined();
|
|
73
|
+
const retained = await core.material.retained();
|
|
74
|
+
expect(retained.status).toBe("classified");
|
|
75
|
+
assert(retained.status === "classified");
|
|
76
|
+
expect(retained.kind).toBe("RENEWAL_MATERIAL_V2_DATA_CONSISTENCY_ONLY");
|
|
77
|
+
expect(retained.material.originalPrepared).toEqual(prepared);
|
|
78
|
+
expect(retained.material.completeRequest).toEqual(request);
|
|
79
|
+
expect(retained.material.rawSources.attachRequest).toEqual(
|
|
80
|
+
source.attachRequest,
|
|
81
|
+
);
|
|
82
|
+
const current = structuredClone(source.originalBundle);
|
|
83
|
+
const live = await core.material.fresh(
|
|
84
|
+
current,
|
|
85
|
+
source.attachRequest.firstDispatchedAt,
|
|
86
|
+
);
|
|
87
|
+
expect(live.status).toBe("classified");
|
|
88
|
+
assert(live.status === "classified");
|
|
89
|
+
expect(live.material.freshness).toBe("fresh");
|
|
90
|
+
expect(live.material.completeRequest).toEqual(request);
|
|
91
|
+
expect(Object.isFrozen(live.material)).toBe(true);
|
|
92
|
+
expect(legacy.touched).toBe(0);
|
|
93
|
+
expect(core.operationalAuthority).toBe(false);
|
|
94
|
+
} finally {
|
|
95
|
+
core.owner.retire();
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
1,
|
|
99
|
+
{
|
|
100
|
+
source,
|
|
101
|
+
workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
|
|
102
|
+
endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("refuses replacement retained source and incompatible fresh material without legacy access", async () => {
|
|
108
|
+
const source = declaredInputs("INITIAL-ACK").original;
|
|
109
|
+
await initialOperations(
|
|
110
|
+
async ({ fresh, journal }) => {
|
|
111
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
112
|
+
try {
|
|
113
|
+
expect(core.material).toBeDefined();
|
|
114
|
+
let read = 0;
|
|
115
|
+
const foreign = {
|
|
116
|
+
get attachRequest() {
|
|
117
|
+
read++;
|
|
118
|
+
throw Error("FOREIGN_SOURCE");
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
expect(() =>
|
|
122
|
+
Reflect.apply(core.material.retained, undefined, [foreign]),
|
|
123
|
+
).toThrow("INITIAL_MATERIAL_UNBOUND");
|
|
124
|
+
expect(read).toBe(0);
|
|
125
|
+
const current = structuredClone(source.originalBundle);
|
|
126
|
+
current.wireSubscription.schedule = "sub_sched_foreign";
|
|
127
|
+
expect(
|
|
128
|
+
(
|
|
129
|
+
await core.material.fresh(
|
|
130
|
+
current,
|
|
131
|
+
source.attachRequest.firstDispatchedAt,
|
|
132
|
+
)
|
|
133
|
+
).status,
|
|
134
|
+
).toBe("unsupported");
|
|
135
|
+
expect((await core.material.retained()).status).toBe("classified");
|
|
136
|
+
core.owner.retire();
|
|
137
|
+
expect(() => core.material.retained()).toThrow("INITIAL_OWNER_STOP");
|
|
138
|
+
expect(legacy.touched).toBe(0);
|
|
139
|
+
} finally {
|
|
140
|
+
core.owner.retire();
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
1,
|
|
144
|
+
{
|
|
145
|
+
source,
|
|
146
|
+
workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
|
|
147
|
+
endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("retiring one Owner rejects its pending material reconstruction while another finishes", async () => {
|
|
153
|
+
const source = declaredInputs("INITIAL-ACK").original;
|
|
154
|
+
const cores: InitialInvocationCore[] = [];
|
|
155
|
+
let ready = () => {},
|
|
156
|
+
entered = () => {},
|
|
157
|
+
retired = () => {},
|
|
158
|
+
release = () => {};
|
|
159
|
+
const bothReady = new Promise<void>((resolve) => {
|
|
160
|
+
ready = resolve;
|
|
161
|
+
});
|
|
162
|
+
const bothPending = new Promise<void>((resolve) => {
|
|
163
|
+
entered = resolve;
|
|
164
|
+
});
|
|
165
|
+
const firstRetired = new Promise<void>((resolve) => {
|
|
166
|
+
retired = resolve;
|
|
167
|
+
});
|
|
168
|
+
const gate = new Promise<void>((resolve) => {
|
|
169
|
+
release = resolve;
|
|
170
|
+
});
|
|
171
|
+
let holding = false,
|
|
172
|
+
pending = 0;
|
|
173
|
+
const nativeDigest = crypto.subtle.digest.bind(crypto.subtle);
|
|
174
|
+
vi.spyOn(crypto.subtle, "digest").mockImplementation(
|
|
175
|
+
async (algorithm, data) => {
|
|
176
|
+
const value = await nativeDigest(algorithm, data);
|
|
177
|
+
if (holding) {
|
|
178
|
+
if (++pending === 2) entered();
|
|
179
|
+
await gate;
|
|
180
|
+
}
|
|
181
|
+
return value;
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
await initialOperations(
|
|
185
|
+
async ({ fresh, journal, index }) => {
|
|
186
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
187
|
+
cores[index] = core;
|
|
188
|
+
try {
|
|
189
|
+
expect(core.material).toBeDefined();
|
|
190
|
+
if (cores.filter(Boolean).length === 2) ready();
|
|
191
|
+
await bothReady;
|
|
192
|
+
holding = true;
|
|
193
|
+
const observed = core.material.retained().then(
|
|
194
|
+
(value) => ({ ok: true, value }),
|
|
195
|
+
(error: unknown) => ({ ok: false, error }),
|
|
196
|
+
);
|
|
197
|
+
await bothPending;
|
|
198
|
+
if (index === 0) {
|
|
199
|
+
core.owner.retire();
|
|
200
|
+
expect((await observed).ok).toBe(false);
|
|
201
|
+
retired();
|
|
202
|
+
} else {
|
|
203
|
+
await firstRetired;
|
|
204
|
+
release();
|
|
205
|
+
const result = await observed;
|
|
206
|
+
expect(result.ok).toBe(true);
|
|
207
|
+
assert("value" in result);
|
|
208
|
+
expect(result.value.status).toBe("classified");
|
|
209
|
+
expect(core.owner.check().retired).toBe(false);
|
|
210
|
+
}
|
|
211
|
+
expect(legacy.touched).toBe(0);
|
|
212
|
+
} finally {
|
|
213
|
+
release();
|
|
214
|
+
core.owner.retire();
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
2,
|
|
218
|
+
{
|
|
219
|
+
source,
|
|
220
|
+
workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
|
|
221
|
+
endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("opaque stored material remains unsupported rather than gaining source qualification", async () => {
|
|
227
|
+
// The original codec fixture has an opaque bundle instead of raw Coupon joins.
|
|
228
|
+
vi.setSystemTime(1700000002000);
|
|
229
|
+
await initialOperations(async ({ fresh, journal }) => {
|
|
230
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
231
|
+
try {
|
|
232
|
+
expect((await core.material.retained()).status).toBe("unsupported");
|
|
233
|
+
expect((await core.material.fresh({}, 1700000002)).status).toBe(
|
|
234
|
+
"unsupported",
|
|
235
|
+
);
|
|
236
|
+
expect(core.operationalAuthority).toBe(false);
|
|
237
|
+
expect(legacy.touched).toBe(0);
|
|
238
|
+
} finally {
|
|
239
|
+
core.owner.retire();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("forged lineage cannot select a classifier Owner or sample clocks", () => {
|
|
245
|
+
const now = vi.spyOn(Date, "now");
|
|
246
|
+
expect(() => createInitialMaterialClassifiers(Object.freeze({}))).toThrow(
|
|
247
|
+
"INITIAL_LINEAGE_UNBOUND",
|
|
248
|
+
);
|
|
249
|
+
expect(now).not.toHaveBeenCalled();
|
|
250
|
+
expect(legacy.touched).toBe(0);
|
|
251
|
+
});
|
package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
3
|
+
import { initialOperations } from "../test-fixtures/producerInitialOperation.js";
|
|
4
|
+
import { declaredInputs } from "../test-fixtures/attachEntries.js";
|
|
5
|
+
import { INITIAL_NS } from "../test-fixtures/producerInitialDeclarations.js";
|
|
6
|
+
import {
|
|
7
|
+
captureInitialInvocationCore,
|
|
8
|
+
type InitialInvocationCore,
|
|
9
|
+
} from "./invocationProducer.js";
|
|
10
|
+
import { mintInitialLineage, readInitialLineage } from "./lineageAuthority.js";
|
|
11
|
+
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
12
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
13
|
+
import { captureInitialStockRawDelegate } from "./stockDelegateFactory.js";
|
|
14
|
+
import { operationForInitialLineage } from "./operationFactory.js";
|
|
15
|
+
import { getStripeClient } from "../../../../helpers.js";
|
|
16
|
+
|
|
17
|
+
async function liveToken(
|
|
18
|
+
input: Parameters<Parameters<typeof initialOperations>[0]>[0],
|
|
19
|
+
) {
|
|
20
|
+
const token = mintInitialLineage(input.fresh.call, input.journal, 2);
|
|
21
|
+
const lineage = readInitialLineage(token);
|
|
22
|
+
const owner = ownerForInitialLineage(token);
|
|
23
|
+
const reservation = lineage.reservation;
|
|
24
|
+
assert("timingPolicyJSON" in reservation);
|
|
25
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
26
|
+
await owned(() =>
|
|
27
|
+
input.journal.bindInitialBasis({
|
|
28
|
+
attemptId: reservation.attemptId,
|
|
29
|
+
policyJSON: reservation.timingPolicyJSON,
|
|
30
|
+
basisJSON: lineage.basisJSON,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
owner.check();
|
|
34
|
+
return { token, lineage, owner, owned };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const legacy = vi.hoisted(() => ({ touched: 0 }));
|
|
38
|
+
vi.mock("../originalOwner.js", () => ({
|
|
39
|
+
OWNER: Object.freeze({
|
|
40
|
+
get basis() {
|
|
41
|
+
legacy.touched++;
|
|
42
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
43
|
+
},
|
|
44
|
+
check() {
|
|
45
|
+
legacy.touched++;
|
|
46
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
47
|
+
},
|
|
48
|
+
sample() {
|
|
49
|
+
legacy.touched++;
|
|
50
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
51
|
+
},
|
|
52
|
+
subscribe() {
|
|
53
|
+
legacy.touched++;
|
|
54
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
55
|
+
},
|
|
56
|
+
retire() {
|
|
57
|
+
legacy.touched++;
|
|
58
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
function declaration() {
|
|
64
|
+
const source = declaredInputs("INITIAL-ACK").original;
|
|
65
|
+
return {
|
|
66
|
+
source,
|
|
67
|
+
workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
|
|
68
|
+
endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const query = String(
|
|
72
|
+
new URLSearchParams(
|
|
73
|
+
["discounts", "items.data.discounts", "items.data.price"].map(
|
|
74
|
+
(value, index) => ["expand[" + index + "]", value],
|
|
75
|
+
),
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
legacy.touched = 0;
|
|
80
|
+
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
|
|
81
|
+
vi.setSystemTime(
|
|
82
|
+
(declaration().source.attachRequest.firstDispatchedAt + 1) * 1000,
|
|
83
|
+
);
|
|
84
|
+
vi.spyOn(process.hrtime, "bigint").mockReturnValue(INITIAL_NS);
|
|
85
|
+
});
|
|
86
|
+
afterEach(() => {
|
|
87
|
+
vi.useRealTimers();
|
|
88
|
+
vi.unstubAllGlobals();
|
|
89
|
+
vi.restoreAllMocks();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("constructs one canonical bounded transport from its actual original journal invocation", async () => {
|
|
93
|
+
const options = declaration();
|
|
94
|
+
await initialOperations(
|
|
95
|
+
async ({ fresh, journal, sdk }) => {
|
|
96
|
+
const calls: {
|
|
97
|
+
method: string | undefined;
|
|
98
|
+
path: string;
|
|
99
|
+
version: string | null;
|
|
100
|
+
auth: string | null;
|
|
101
|
+
redirect: RequestRedirect | undefined;
|
|
102
|
+
}[] = [];
|
|
103
|
+
const path =
|
|
104
|
+
"/v1/subscriptions/" +
|
|
105
|
+
options.source.attachRequest.preparation.expected.subscriptionId +
|
|
106
|
+
"?" +
|
|
107
|
+
query;
|
|
108
|
+
vi.stubGlobal(
|
|
109
|
+
"fetch",
|
|
110
|
+
async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
111
|
+
const url = new URL(String(input));
|
|
112
|
+
const headers = new Headers(init?.headers);
|
|
113
|
+
calls.push({
|
|
114
|
+
method: init?.method,
|
|
115
|
+
path: url.pathname + url.search,
|
|
116
|
+
version: headers.get("stripe-version"),
|
|
117
|
+
auth: headers.get("authorization"),
|
|
118
|
+
redirect: init?.redirect,
|
|
119
|
+
});
|
|
120
|
+
assert.equal(url.origin, "https://api.stripe.com");
|
|
121
|
+
assert.equal(url.pathname + url.search, path);
|
|
122
|
+
assert.equal(init?.method, "GET");
|
|
123
|
+
return new Response(
|
|
124
|
+
JSON.stringify(options.source.originalBundle.wireSubscription),
|
|
125
|
+
{
|
|
126
|
+
status: 200,
|
|
127
|
+
headers: {
|
|
128
|
+
"content-type": "application/json",
|
|
129
|
+
"request-id": "req_initial_transport",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
136
|
+
try {
|
|
137
|
+
expect(typeof core.transport).toBe("function");
|
|
138
|
+
const pair = await core.transport();
|
|
139
|
+
expect((await core.transport()) === pair).toBe(true);
|
|
140
|
+
expect((await pair.transport.postAttach()).outcome).toBe("not_started");
|
|
141
|
+
expect(calls).toHaveLength(0);
|
|
142
|
+
const reply = await core.owned(() =>
|
|
143
|
+
pair.transport.readTransport.rawRequest("GET", path, undefined, {
|
|
144
|
+
apiVersion: sdk.stripeApiVersion,
|
|
145
|
+
maxNetworkRetries: 0,
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
expect(reply).toMatchObject({
|
|
149
|
+
id: options.source.attachRequest.preparation.expected.subscriptionId,
|
|
150
|
+
});
|
|
151
|
+
expect(calls).toEqual([
|
|
152
|
+
{
|
|
153
|
+
method: "GET",
|
|
154
|
+
path,
|
|
155
|
+
version: sdk.stripeApiVersion,
|
|
156
|
+
auth: "Bearer sk_test_invalid_owner_core",
|
|
157
|
+
redirect: "error",
|
|
158
|
+
},
|
|
159
|
+
]);
|
|
160
|
+
expect((await pair.transport.postAttach()).outcome).toBe("not_started");
|
|
161
|
+
expect(legacy.touched).toBe(0);
|
|
162
|
+
expect(core.operationalAuthority).toBe(false);
|
|
163
|
+
} finally {
|
|
164
|
+
core.owner.retire();
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
1,
|
|
168
|
+
options,
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("refuses replacement construction arguments and an out-of-plan read before HTTP", async () => {
|
|
173
|
+
const options = declaration();
|
|
174
|
+
await initialOperations(
|
|
175
|
+
async ({ fresh, journal }) => {
|
|
176
|
+
let requests = 0,
|
|
177
|
+
foreign = 0;
|
|
178
|
+
vi.stubGlobal("fetch", () => {
|
|
179
|
+
requests++;
|
|
180
|
+
throw Error("UNEXPECTED_HTTP");
|
|
181
|
+
});
|
|
182
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
183
|
+
try {
|
|
184
|
+
expect(typeof core.transport).toBe("function");
|
|
185
|
+
const replacement = {
|
|
186
|
+
get client() {
|
|
187
|
+
foreign++;
|
|
188
|
+
throw Error("FOREIGN_CLIENT");
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
const now = vi.spyOn(Date, "now");
|
|
192
|
+
const clockReads = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
193
|
+
await expect(
|
|
194
|
+
Reflect.apply(core.transport, undefined, [replacement]),
|
|
195
|
+
).rejects.toThrow("INITIAL_OPERATION_UNBOUND");
|
|
196
|
+
expect(now).not.toHaveBeenCalled();
|
|
197
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(
|
|
198
|
+
clockReads,
|
|
199
|
+
);
|
|
200
|
+
expect(foreign).toBe(0);
|
|
201
|
+
const pair = await core.transport();
|
|
202
|
+
await expect(
|
|
203
|
+
pair.transport.readTransport.rawRequest(
|
|
204
|
+
"GET",
|
|
205
|
+
"/v1/prices/price_target",
|
|
206
|
+
undefined,
|
|
207
|
+
{ apiVersion: "2026-09-30.endive", maxNetworkRetries: 0 },
|
|
208
|
+
),
|
|
209
|
+
).rejects.toThrow();
|
|
210
|
+
expect(requests).toBe(0);
|
|
211
|
+
expect(legacy.touched).toBe(0);
|
|
212
|
+
} finally {
|
|
213
|
+
core.owner.retire();
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
1,
|
|
217
|
+
options,
|
|
218
|
+
);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("the fixed stock delegate retains the actual maintained SDK promise and original receiver", async () => {
|
|
222
|
+
const options = declaration();
|
|
223
|
+
await initialOperations(
|
|
224
|
+
async (input) => {
|
|
225
|
+
const calls: string[] = [];
|
|
226
|
+
vi.stubGlobal(
|
|
227
|
+
"fetch",
|
|
228
|
+
async (_request: RequestInfo | URL, init?: RequestInit) => {
|
|
229
|
+
calls.push(new Headers(init?.headers).get("authorization") ?? "");
|
|
230
|
+
return new Response(
|
|
231
|
+
JSON.stringify({ id: "sub_original", object: "subscription" }),
|
|
232
|
+
{ status: 200, headers: { "content-type": "application/json" } },
|
|
233
|
+
);
|
|
234
|
+
},
|
|
235
|
+
);
|
|
236
|
+
const h = await liveToken(input);
|
|
237
|
+
try {
|
|
238
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
239
|
+
h.lineage.client,
|
|
240
|
+
"_requestSender",
|
|
241
|
+
);
|
|
242
|
+
assert(
|
|
243
|
+
descriptor &&
|
|
244
|
+
descriptor.value &&
|
|
245
|
+
typeof descriptor.value === "object",
|
|
246
|
+
);
|
|
247
|
+
const sender = descriptor.value;
|
|
248
|
+
const original = sender._rawRequest;
|
|
249
|
+
assert(typeof original === "function");
|
|
250
|
+
const promises: unknown[] = [];
|
|
251
|
+
vi.spyOn(sender, "_rawRequest").mockImplementation(
|
|
252
|
+
(...args: unknown[]) => {
|
|
253
|
+
const promise = Reflect.apply(original, sender, args);
|
|
254
|
+
promises.push(promise);
|
|
255
|
+
return promise;
|
|
256
|
+
},
|
|
257
|
+
);
|
|
258
|
+
const foreign = getStripeClient(
|
|
259
|
+
"sk_test_invalid_foreign_native_promise",
|
|
260
|
+
input.sdk.stripeApiVersion,
|
|
261
|
+
{ singleAttempt: true },
|
|
262
|
+
);
|
|
263
|
+
const delegate = captureInitialStockRawDelegate(h.token);
|
|
264
|
+
const actual = delegate.rawRequest.call(
|
|
265
|
+
foreign,
|
|
266
|
+
"GET",
|
|
267
|
+
"/v1/subscriptions/sub_original",
|
|
268
|
+
undefined,
|
|
269
|
+
{ apiVersion: input.sdk.stripeApiVersion, maxNetworkRetries: 0 },
|
|
270
|
+
);
|
|
271
|
+
expect(promises.length).toBe(1);
|
|
272
|
+
expect(actual === promises[0]).toBe(true);
|
|
273
|
+
expect(await h.owned(() => actual)).toMatchObject({
|
|
274
|
+
id: "sub_original",
|
|
275
|
+
});
|
|
276
|
+
expect(calls).toEqual(["Bearer sk_test_invalid_owner_core"]);
|
|
277
|
+
expect(legacy.touched).toBe(0);
|
|
278
|
+
} finally {
|
|
279
|
+
h.owner.retire();
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
1,
|
|
283
|
+
options,
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("canonical original slots refuse a foreign Owner before clocks and cannot be revived", async () => {
|
|
288
|
+
const options = declaration();
|
|
289
|
+
const entries: Awaited<ReturnType<typeof liveToken>>[] = [];
|
|
290
|
+
let constructed = 0;
|
|
291
|
+
let ready = () => {},
|
|
292
|
+
first = () => {};
|
|
293
|
+
const bothReady = new Promise<void>((resolve) => {
|
|
294
|
+
ready = resolve;
|
|
295
|
+
});
|
|
296
|
+
const firstDone = new Promise<void>((resolve) => {
|
|
297
|
+
first = resolve;
|
|
298
|
+
});
|
|
299
|
+
await initialOperations(
|
|
300
|
+
async (input) => {
|
|
301
|
+
const h = await liveToken(input);
|
|
302
|
+
entries[input.index] = h;
|
|
303
|
+
try {
|
|
304
|
+
const frame = await operationForInitialLineage(h.token);
|
|
305
|
+
expect((await operationForInitialLineage(h.token)) === frame).toBe(
|
|
306
|
+
true,
|
|
307
|
+
);
|
|
308
|
+
expect(
|
|
309
|
+
frame.operation.originAssociation === h.lineage.originAssociation,
|
|
310
|
+
).toBe(true);
|
|
311
|
+
if (++constructed === 2) ready();
|
|
312
|
+
await bothReady;
|
|
313
|
+
if (input.index === 0) {
|
|
314
|
+
const reads = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
315
|
+
expect(frame.operation.slot.takeOnce(entries[1].owner)).toBeNull();
|
|
316
|
+
expect(frame.operation.slot.takeOnce(h.owner)).toBeNull();
|
|
317
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(
|
|
318
|
+
reads,
|
|
319
|
+
);
|
|
320
|
+
first();
|
|
321
|
+
} else {
|
|
322
|
+
await firstDone;
|
|
323
|
+
const selected = frame.operation.slot.takeOnce(h.owner);
|
|
324
|
+
assert(selected);
|
|
325
|
+
expect(selected.rawAttachRequest).toEqual(
|
|
326
|
+
options.source.attachRequest,
|
|
327
|
+
);
|
|
328
|
+
expect(selected.originalBundle).toEqual(
|
|
329
|
+
options.source.originalBundle,
|
|
330
|
+
);
|
|
331
|
+
expect(frame.operation.slot.takeOnce(h.owner)).toBeNull();
|
|
332
|
+
}
|
|
333
|
+
expect(legacy.touched).toBe(0);
|
|
334
|
+
} finally {
|
|
335
|
+
first();
|
|
336
|
+
h.owner.retire();
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
2,
|
|
340
|
+
options,
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("stock capture rejects extra client arguments before lineage or clock access", () => {
|
|
345
|
+
const reads = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
346
|
+
expect(() =>
|
|
347
|
+
Reflect.apply(captureInitialStockRawDelegate, undefined, [{}, {}]),
|
|
348
|
+
).toThrow("INITIAL_OPERATION_UNBOUND");
|
|
349
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(reads);
|
|
350
|
+
expect(legacy.touched).toBe(0);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("two pending actual SDK reads retain independent Owners and transport attempt state", async () => {
|
|
354
|
+
const options = declaration();
|
|
355
|
+
const cores: InitialInvocationCore[] = [];
|
|
356
|
+
let ready = () => {},
|
|
357
|
+
first = () => {},
|
|
358
|
+
both = () => {},
|
|
359
|
+
retired = () => {},
|
|
360
|
+
release = () => {};
|
|
361
|
+
const readyGate = new Promise<void>((resolve) => {
|
|
362
|
+
ready = resolve;
|
|
363
|
+
});
|
|
364
|
+
const firstRead = new Promise<void>((resolve) => {
|
|
365
|
+
first = resolve;
|
|
366
|
+
});
|
|
367
|
+
const bothReads = new Promise<void>((resolve) => {
|
|
368
|
+
both = resolve;
|
|
369
|
+
});
|
|
370
|
+
const firstRetired = new Promise<void>((resolve) => {
|
|
371
|
+
retired = resolve;
|
|
372
|
+
});
|
|
373
|
+
const responseGate = new Promise<void>((resolve) => {
|
|
374
|
+
release = resolve;
|
|
375
|
+
});
|
|
376
|
+
let requests = 0;
|
|
377
|
+
await initialOperations(
|
|
378
|
+
async ({ fresh, journal, index, sdk }) => {
|
|
379
|
+
vi.stubGlobal("fetch", async () => {
|
|
380
|
+
if (++requests === 1) first();
|
|
381
|
+
if (requests === 2) both();
|
|
382
|
+
await responseGate;
|
|
383
|
+
return new Response(
|
|
384
|
+
JSON.stringify(options.source.originalBundle.wireSubscription),
|
|
385
|
+
{
|
|
386
|
+
status: 200,
|
|
387
|
+
headers: {
|
|
388
|
+
"content-type": "application/json",
|
|
389
|
+
"request-id": "req_two_initial_transports",
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
);
|
|
393
|
+
});
|
|
394
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
395
|
+
cores[index] = core;
|
|
396
|
+
try {
|
|
397
|
+
expect(typeof core.transport).toBe("function");
|
|
398
|
+
const pair = await core.transport();
|
|
399
|
+
if (cores.filter(Boolean).length === 2) ready();
|
|
400
|
+
await readyGate;
|
|
401
|
+
if (index === 1) await firstRead;
|
|
402
|
+
const path =
|
|
403
|
+
"/v1/subscriptions/" +
|
|
404
|
+
options.source.attachRequest.preparation.expected.subscriptionId +
|
|
405
|
+
"?" +
|
|
406
|
+
query;
|
|
407
|
+
const observed = core
|
|
408
|
+
.owned(() =>
|
|
409
|
+
pair.transport.readTransport.rawRequest("GET", path, undefined, {
|
|
410
|
+
apiVersion: sdk.stripeApiVersion,
|
|
411
|
+
maxNetworkRetries: 0,
|
|
412
|
+
}),
|
|
413
|
+
)
|
|
414
|
+
.then(
|
|
415
|
+
(value) => ({ ok: true, value }),
|
|
416
|
+
(error: unknown) => ({ ok: false, error }),
|
|
417
|
+
);
|
|
418
|
+
await bothReads;
|
|
419
|
+
if (index === 0) {
|
|
420
|
+
core.owner.retire();
|
|
421
|
+
expect((await observed).ok).toBe(false);
|
|
422
|
+
retired();
|
|
423
|
+
} else {
|
|
424
|
+
await firstRetired;
|
|
425
|
+
release();
|
|
426
|
+
const result = await observed;
|
|
427
|
+
expect(result.ok).toBe(true);
|
|
428
|
+
expect(core.owner.check().retired).toBe(false);
|
|
429
|
+
}
|
|
430
|
+
expect(requests).toBe(2);
|
|
431
|
+
expect(legacy.touched).toBe(0);
|
|
432
|
+
} finally {
|
|
433
|
+
release();
|
|
434
|
+
core.owner.retire();
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
2,
|
|
438
|
+
options,
|
|
439
|
+
);
|
|
440
|
+
});
|