@fantastic.dev/better-stripe 0.97.1 → 0.99.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 +11 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +39 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts +22 -0
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js +13 -5
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts +17 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js +140 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +61 -9
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +41 -411
- 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 +141 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +132 -182
- 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/operations/transportKernel.d.ts +63 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js +380 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.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 +25 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
- 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 +162 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +87 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.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/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
- package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
- package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +69 -156
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
- package/docs/renewal-context-reads.md +69 -8
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +45 -3
- package/src/client/billing/renewalAttach/internal/c10/attachEvents.ts +17 -5
- package/src/client/billing/renewalAttach/internal/operations/actorFailureControl.ts +165 -0
- package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +48 -535
- package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +168 -209
- 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/operations/transportKernel.ts +500 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +28 -0
- package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
- package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +176 -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/producerRecovery.integration.test.ts +394 -0
- package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
- package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
- package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
- package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +109 -0
- package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
- package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
- package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
- package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
- package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +107 -188
- package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +82 -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
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { readInitialLineage } from "./lineageAuthority.js";
|
|
3
|
+
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
4
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
|
+
import { recoveryOperationForLineage } from "./recoveryFactory.js";
|
|
6
|
+
import { captureExplicitAttachRecoveryForLineage } from "../recovery/recoveryActor.js";
|
|
7
|
+
import { COMPILED_RECOVERY_ENTRIES } from "../operations/sourceOperations.js";
|
|
8
|
+
import {
|
|
9
|
+
need,
|
|
10
|
+
refuse,
|
|
11
|
+
seven,
|
|
12
|
+
sourceMethod,
|
|
13
|
+
} from "../operations/initialActorData.js";
|
|
14
|
+
import { closed } from "../operations/types.js";
|
|
15
|
+
import { createRecoveryAttachEventCompiler } from "../c10/attachEvents.js";
|
|
16
|
+
import { constructRenewalScheduleAttachmentReceiptV2 as c3 } from "../../../renewalV2/index.js";
|
|
17
|
+
import { retainInitialReceiptForLineage } from "./operationFactory.js";
|
|
18
|
+
import { admitInitialOutput } from "../recovery/material.js";
|
|
19
|
+
|
|
20
|
+
const actors = new WeakMap<object, ReturnType<typeof construct>>();
|
|
21
|
+
export function captureLiveAttachRecovery(token: object) {
|
|
22
|
+
need(arguments.length === 1);
|
|
23
|
+
readInitialLineage(token);
|
|
24
|
+
let actor = actors.get(token);
|
|
25
|
+
if (!actor) {
|
|
26
|
+
actor = construct(token);
|
|
27
|
+
actors.set(token, actor);
|
|
28
|
+
}
|
|
29
|
+
return actor;
|
|
30
|
+
}
|
|
31
|
+
function construct(token: object) {
|
|
32
|
+
let consumed = false;
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
async invoke() {
|
|
35
|
+
need(arguments.length === 0);
|
|
36
|
+
if (consumed) return refuse("invocation_consumed");
|
|
37
|
+
consumed = true;
|
|
38
|
+
need(
|
|
39
|
+
Array.isArray(COMPILED_RECOVERY_ENTRIES) &&
|
|
40
|
+
!types.isProxy(COMPILED_RECOVERY_ENTRIES),
|
|
41
|
+
);
|
|
42
|
+
if (COMPILED_RECOVERY_ENTRIES.length === 0)
|
|
43
|
+
return refuse("no_qualified_recovery_class");
|
|
44
|
+
const owner = ownerForInitialLineage(token);
|
|
45
|
+
owner.check();
|
|
46
|
+
// This consumes actual attempt custody synchronously, before any await.
|
|
47
|
+
const frame = await recoveryOperationForLineage(token);
|
|
48
|
+
const snapshot = frame.snapshot;
|
|
49
|
+
need(
|
|
50
|
+
sourceMethod(snapshot.entry, "coversRetained") ===
|
|
51
|
+
snapshot.retainedPredicate,
|
|
52
|
+
);
|
|
53
|
+
need(
|
|
54
|
+
sourceMethod(snapshot.entry, "coversFresh") === snapshot.freshPredicate,
|
|
55
|
+
);
|
|
56
|
+
const relations = COMPILED_RECOVERY_ENTRIES.filter((value) => {
|
|
57
|
+
const relation = closed(value, ["originalEntry", "coversReplay"]);
|
|
58
|
+
sourceMethod(value, "coversReplay");
|
|
59
|
+
return relation.originalEntry === snapshot.entry;
|
|
60
|
+
});
|
|
61
|
+
need(relations.length === 1);
|
|
62
|
+
if (snapshot.response === null)
|
|
63
|
+
return captureExplicitAttachRecoveryForLineage(token).invoke();
|
|
64
|
+
const response = snapshot.response;
|
|
65
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
66
|
+
const compiler = createRecoveryAttachEventCompiler(token);
|
|
67
|
+
owner.check();
|
|
68
|
+
await owned(() =>
|
|
69
|
+
compiler.dispatch({
|
|
70
|
+
event: "dispatch",
|
|
71
|
+
stage: "attach",
|
|
72
|
+
request: snapshot.request,
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
await owned(() =>
|
|
76
|
+
compiler.response({
|
|
77
|
+
event: "response",
|
|
78
|
+
stage: "attach",
|
|
79
|
+
request: snapshot.request,
|
|
80
|
+
body: response.body,
|
|
81
|
+
status: response.status,
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
const receipt = await owned(() =>
|
|
85
|
+
c3({
|
|
86
|
+
attachRequest: snapshot.raw,
|
|
87
|
+
actualDispatch: seven(snapshot.request),
|
|
88
|
+
providerSnapshot: response.body as Record<string, unknown>,
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
await owned(() => retainInitialReceiptForLineage(token, receipt));
|
|
92
|
+
await owned(() =>
|
|
93
|
+
compiler.receipt({
|
|
94
|
+
event: "receipt",
|
|
95
|
+
stage: "attach",
|
|
96
|
+
request: snapshot.request,
|
|
97
|
+
receipt,
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
const admitted = admitInitialOutput(
|
|
101
|
+
receipt,
|
|
102
|
+
snapshot.prepared,
|
|
103
|
+
snapshot.request,
|
|
104
|
+
);
|
|
105
|
+
owner.check();
|
|
106
|
+
return admitted;
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { takeInitialRecoveryRecord } from "../operations/initialAttach.js";
|
|
2
|
+
import { readInitialLineage } from "./lineageAuthority.js";
|
|
3
|
+
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
4
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
|
+
import { operationForInitialLineage } from "./operationFactory.js";
|
|
6
|
+
import { journalWorkForInitialLineage } from "./journalWorkFactory.js";
|
|
7
|
+
import { build } from "../operations/transportKernel.js";
|
|
8
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
9
|
+
import { need, sourceMethod } from "../operations/initialActorData.js";
|
|
10
|
+
import { closed } from "../operations/types.js";
|
|
11
|
+
import { COMPILED_RECOVERY_ENTRIES } from "../operations/sourceOperations.js";
|
|
12
|
+
|
|
13
|
+
const frames = new WeakMap<object, ReturnType<typeof construct>>();
|
|
14
|
+
/** One reservation of actual initial custody, synchronously before construction awaits. */
|
|
15
|
+
export function recoveryOperationForLineage(token: object) {
|
|
16
|
+
need(arguments.length === 1);
|
|
17
|
+
const owner = ownerForInitialLineage(token);
|
|
18
|
+
owner.check();
|
|
19
|
+
let pending = frames.get(token);
|
|
20
|
+
if (!pending) {
|
|
21
|
+
const snapshot = takeInitialRecoveryRecord(token);
|
|
22
|
+
need(
|
|
23
|
+
sourceMethod(snapshot.entry, "coversRetained") ===
|
|
24
|
+
snapshot.retainedPredicate,
|
|
25
|
+
);
|
|
26
|
+
need(
|
|
27
|
+
sourceMethod(snapshot.entry, "coversFresh") === snapshot.freshPredicate,
|
|
28
|
+
);
|
|
29
|
+
const relations = COMPILED_RECOVERY_ENTRIES.filter((value) => {
|
|
30
|
+
const relation = closed(value, ["originalEntry", "coversReplay"]);
|
|
31
|
+
sourceMethod(value, "coversReplay");
|
|
32
|
+
return relation.originalEntry === snapshot.entry;
|
|
33
|
+
});
|
|
34
|
+
need(relations.length === 1);
|
|
35
|
+
pending = construct(token, snapshot);
|
|
36
|
+
frames.set(token, pending);
|
|
37
|
+
}
|
|
38
|
+
return pending;
|
|
39
|
+
}
|
|
40
|
+
async function construct(
|
|
41
|
+
token: object,
|
|
42
|
+
snapshot: ReturnType<typeof takeInitialRecoveryRecord>,
|
|
43
|
+
) {
|
|
44
|
+
const owner = ownerForInitialLineage(token);
|
|
45
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
46
|
+
const lineage = readInitialLineage(token);
|
|
47
|
+
const original = await owned(() => operationForInitialLineage(token));
|
|
48
|
+
owner.check();
|
|
49
|
+
if (snapshot.response !== null)
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
snapshot,
|
|
52
|
+
operation: null,
|
|
53
|
+
pair: null,
|
|
54
|
+
reader: null,
|
|
55
|
+
});
|
|
56
|
+
const manifest = await owned(() =>
|
|
57
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
58
|
+
);
|
|
59
|
+
need(
|
|
60
|
+
manifest &&
|
|
61
|
+
manifest.events.length === 1 &&
|
|
62
|
+
manifest.events[0].sequence === 1,
|
|
63
|
+
);
|
|
64
|
+
need(
|
|
65
|
+
(await owned(() => lineage.journal.readProviderAcknowledgement())) === null,
|
|
66
|
+
);
|
|
67
|
+
need(journalWorkForInitialLineage(token).idle());
|
|
68
|
+
let reserved = false;
|
|
69
|
+
const operation = Object.freeze({
|
|
70
|
+
owner,
|
|
71
|
+
originAssociation: lineage.originAssociation,
|
|
72
|
+
originalEntry: snapshot.entry,
|
|
73
|
+
originalRecord: snapshot.originalRecord,
|
|
74
|
+
readPlan: original.operation.readPlan,
|
|
75
|
+
delegate: original.operation.delegate,
|
|
76
|
+
sink: original.operation.sink,
|
|
77
|
+
reserve(claimedOwner: unknown, origin: unknown, entry: unknown) {
|
|
78
|
+
need(
|
|
79
|
+
arguments.length === 3 &&
|
|
80
|
+
!reserved &&
|
|
81
|
+
claimedOwner === owner &&
|
|
82
|
+
origin === lineage.originAssociation &&
|
|
83
|
+
entry === snapshot.entry,
|
|
84
|
+
);
|
|
85
|
+
reserved = true;
|
|
86
|
+
owner.check();
|
|
87
|
+
return Object.freeze({});
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const pair = build(
|
|
91
|
+
{
|
|
92
|
+
owner,
|
|
93
|
+
request: original.request,
|
|
94
|
+
readPlan: operation.readPlan,
|
|
95
|
+
delegate: operation.delegate,
|
|
96
|
+
},
|
|
97
|
+
{ operation, readPlan: operation.readPlan, delegate: operation.delegate },
|
|
98
|
+
token,
|
|
99
|
+
);
|
|
100
|
+
const acquisition = createSelectedRawAcquisition(
|
|
101
|
+
owner,
|
|
102
|
+
pair.transport.readTransport,
|
|
103
|
+
);
|
|
104
|
+
const reader = Object.freeze({
|
|
105
|
+
acquire() {
|
|
106
|
+
need(arguments.length === 0);
|
|
107
|
+
return owned(() => acquisition.acquire(original.expected));
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
owner.check();
|
|
111
|
+
return Object.freeze({ snapshot, operation, pair, reader });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Best-effort final read fence; this is not an atomic journal/provider lock. */
|
|
115
|
+
export async function assertReplayFrontierForLineage(token: object) {
|
|
116
|
+
need(arguments.length === 1 && frames.has(token));
|
|
117
|
+
const owner = ownerForInitialLineage(token);
|
|
118
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
119
|
+
const lineage = readInitialLineage(token);
|
|
120
|
+
owner.check();
|
|
121
|
+
need(journalWorkForInitialLineage(token).idle());
|
|
122
|
+
need(
|
|
123
|
+
(await owned(() => lineage.journal.readProviderAcknowledgement())) === null,
|
|
124
|
+
);
|
|
125
|
+
const manifest = await owned(() =>
|
|
126
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
127
|
+
);
|
|
128
|
+
need(
|
|
129
|
+
manifest &&
|
|
130
|
+
manifest.events.length === 1 &&
|
|
131
|
+
manifest.events[0].sequence === 1,
|
|
132
|
+
);
|
|
133
|
+
need(journalWorkForInitialLineage(token).idle());
|
|
134
|
+
owner.check();
|
|
135
|
+
}
|