@fantastic.dev/better-stripe 0.97.1 → 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 +6 -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/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 +6 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +19 -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 +26 -6
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +42 -0
- 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 +22 -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/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 +69 -11
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
|
+
});
|
|
@@ -3,21 +3,45 @@ import { readInitialLineage } from "./lineageAuthority.js";
|
|
|
3
3
|
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
4
4
|
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
5
|
|
|
6
|
+
function stockCall(token: object) {
|
|
7
|
+
const lineage = readInitialLineage(token);
|
|
8
|
+
const owner = ownerForInitialLineage(token);
|
|
9
|
+
return Object.freeze({
|
|
10
|
+
owner,
|
|
11
|
+
call(args: Parameters<Stripe["rawRequest"]>) {
|
|
12
|
+
return Reflect.apply(lineage.method, lineage.client, args) as ReturnType<
|
|
13
|
+
Stripe["rawRequest"]
|
|
14
|
+
>;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Transport kernels keep the original SDK promise and guard their continuation. */
|
|
20
|
+
export function captureInitialStockRawDelegate(
|
|
21
|
+
token: object,
|
|
22
|
+
): Readonly<{ rawRequest: Stripe["rawRequest"] }> {
|
|
23
|
+
if (arguments.length !== 1) throw Error("INITIAL_OPERATION_UNBOUND");
|
|
24
|
+
const binding = stockCall(token);
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
rawRequest(...args: Parameters<Stripe["rawRequest"]>) {
|
|
27
|
+
binding.owner.check();
|
|
28
|
+
return binding.call(args);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
6
33
|
/** Fixed selected client and original receiver; no replacement-client parameter. */
|
|
7
34
|
export function stockDelegateForInitialLineage(token: object): Readonly<{
|
|
8
35
|
rawRequest: Stripe["rawRequest"];
|
|
9
36
|
}> {
|
|
10
|
-
const
|
|
11
|
-
const owner = ownerForInitialLineage(token);
|
|
37
|
+
const { owner, call } = stockCall(token);
|
|
12
38
|
const owned = ownedAwaitForInitialLineage(token);
|
|
13
39
|
return Object.freeze({
|
|
14
40
|
rawRequest(
|
|
15
41
|
...args: Parameters<Stripe["rawRequest"]>
|
|
16
42
|
): ReturnType<Stripe["rawRequest"]> {
|
|
17
43
|
owner.check();
|
|
18
|
-
return owned(() =>
|
|
19
|
-
Reflect.apply(lineage.method, lineage.client, args),
|
|
20
|
-
) as ReturnType<Stripe["rawRequest"]>;
|
|
44
|
+
return owned(() => call(args)) as ReturnType<Stripe["rawRequest"]>;
|
|
21
45
|
},
|
|
22
46
|
});
|
|
23
47
|
}
|
|
@@ -36,7 +36,10 @@ export async function initialOperations(
|
|
|
36
36
|
endWallMs?: number;
|
|
37
37
|
afterBind?: () => Promise<void>;
|
|
38
38
|
afterAppend?: () => Promise<void>;
|
|
39
|
+
afterRetain?: () => Promise<void>;
|
|
39
40
|
source?: RetainedInput;
|
|
41
|
+
sources?: readonly RetainedInput[];
|
|
42
|
+
keys?: readonly string[];
|
|
40
43
|
} = {},
|
|
41
44
|
) {
|
|
42
45
|
const h = await codecFixture();
|
|
@@ -107,16 +110,59 @@ export async function initialOperations(
|
|
|
107
110
|
periodEnd: prepared.expected.periodEnd,
|
|
108
111
|
},
|
|
109
112
|
};
|
|
113
|
+
assert(!options.sources || options.sources.length === count);
|
|
114
|
+
assert(!options.keys || options.keys.length === count);
|
|
115
|
+
const records = options.sources
|
|
116
|
+
? await Promise.all(
|
|
117
|
+
options.sources.map(async (original) => {
|
|
118
|
+
const raw = original.attachRequest;
|
|
119
|
+
const prepared = await prepareRenewalPriceReplacementV2(
|
|
120
|
+
raw.preparation,
|
|
121
|
+
);
|
|
122
|
+
const request = await prepareRenewalScheduleAttachmentV2({
|
|
123
|
+
prepared,
|
|
124
|
+
apiVersion: raw.apiVersion,
|
|
125
|
+
attachKey: raw.attachKey,
|
|
126
|
+
firstDispatchedAt: raw.firstDispatchedAt,
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
...record,
|
|
130
|
+
attachRequest: raw,
|
|
131
|
+
originalBundle: original.originalBundle,
|
|
132
|
+
requestBinding: request.requestIdentity.binding,
|
|
133
|
+
dispatch: {
|
|
134
|
+
scope: request.scope,
|
|
135
|
+
apiVersion: request.apiVersion,
|
|
136
|
+
method: request.method,
|
|
137
|
+
path: request.path,
|
|
138
|
+
payload: request.payload,
|
|
139
|
+
key: request.key,
|
|
140
|
+
firstDispatchedAt: request.firstDispatchedAt,
|
|
141
|
+
},
|
|
142
|
+
timingPolicy: {
|
|
143
|
+
...record.timingPolicy,
|
|
144
|
+
firstDispatchedAt: raw.firstDispatchedAt,
|
|
145
|
+
periodStart: prepared.expected.periodStart,
|
|
146
|
+
periodEnd: prepared.expected.periodEnd,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}),
|
|
150
|
+
)
|
|
151
|
+
: null;
|
|
110
152
|
const sdk = new BetterStripe(components.betterStripe, {
|
|
111
153
|
STRIPE_SECRET_KEY: "sk_test_invalid_owner_core",
|
|
112
154
|
});
|
|
155
|
+
const sdks = options.keys?.map(
|
|
156
|
+
(key) =>
|
|
157
|
+
new BetterStripe(components.betterStripe, { STRIPE_SECRET_KEY: key }),
|
|
158
|
+
);
|
|
113
159
|
const refs = components.betterStripe.renewalOperations;
|
|
114
160
|
const host = {
|
|
115
161
|
run: actionGeneric({
|
|
116
162
|
args: {},
|
|
117
163
|
handler: async (ctx): Promise<null> => {
|
|
118
164
|
const runMutation = ctx.runMutation;
|
|
119
|
-
if (options.afterBind || options.afterAppend)
|
|
165
|
+
if (options.afterBind || options.afterAppend || options.afterRetain)
|
|
120
166
|
ctx.runMutation = async (ref, ...args) => {
|
|
121
167
|
const result = await runMutation(ref, ...args);
|
|
122
168
|
if (
|
|
@@ -133,35 +179,47 @@ export async function initialOperations(
|
|
|
133
179
|
options.afterAppend
|
|
134
180
|
)
|
|
135
181
|
await options.afterAppend();
|
|
182
|
+
if (
|
|
183
|
+
getFunctionAddress(ref).reference?.endsWith(
|
|
184
|
+
"/retainProviderAcknowledgement",
|
|
185
|
+
) &&
|
|
186
|
+
options.afterRetain
|
|
187
|
+
)
|
|
188
|
+
await options.afterRetain();
|
|
136
189
|
return result;
|
|
137
190
|
};
|
|
138
191
|
await Promise.all(
|
|
139
192
|
Array.from({ length: count }, async (_, index) => {
|
|
193
|
+
const current = records?.[index] ?? record;
|
|
194
|
+
const selectedSDK = sdks?.[index] ?? sdk;
|
|
140
195
|
const logicalOperationId =
|
|
141
|
-
|
|
142
|
-
const recordJSON = canonical({ ...
|
|
196
|
+
current.logicalOperationId + "-owner-" + index;
|
|
197
|
+
const recordJSON = canonical({ ...current, logicalOperationId });
|
|
143
198
|
const created = await ctx.runMutation(
|
|
144
199
|
refs.mutations.createAuthorizedOperation,
|
|
145
200
|
{
|
|
146
|
-
authorizationScope:
|
|
147
|
-
authorizationRevision:
|
|
201
|
+
authorizationScope: current.authorization.scope,
|
|
202
|
+
authorizationRevision: current.authorization.revision,
|
|
148
203
|
logicalOperationId,
|
|
149
204
|
recordJSON,
|
|
150
205
|
},
|
|
151
206
|
);
|
|
152
207
|
assert(created.status === "created");
|
|
153
|
-
const journal = await createClassActionOperationJournal(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
208
|
+
const journal = await createClassActionOperationJournal(
|
|
209
|
+
selectedSDK,
|
|
210
|
+
{
|
|
211
|
+
actualActionCtx: ctx,
|
|
212
|
+
operationId: created.operationId,
|
|
213
|
+
},
|
|
214
|
+
);
|
|
157
215
|
const fresh = await journal.reserveFreshAttempt({
|
|
158
216
|
expectedRevision: 0,
|
|
159
217
|
stage: "attach",
|
|
160
|
-
expectedRequestBinding:
|
|
218
|
+
expectedRequestBinding: current.requestBinding,
|
|
161
219
|
recordJSON,
|
|
162
220
|
});
|
|
163
221
|
assert(fresh.result.disposition === "acquired" && fresh.call);
|
|
164
|
-
await work({ journal, fresh, sdk, index });
|
|
222
|
+
await work({ journal, fresh, sdk: selectedSDK, index });
|
|
165
223
|
}),
|
|
166
224
|
);
|
|
167
225
|
return null;
|