@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
|
@@ -0,0 +1,526 @@
|
|
|
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 {
|
|
6
|
+
captureRetainedInput,
|
|
7
|
+
type RetainedInput,
|
|
8
|
+
} from "../material/capture.js";
|
|
9
|
+
import { INITIAL_NS } from "../test-fixtures/producerInitialDeclarations.js";
|
|
10
|
+
import {
|
|
11
|
+
captureInitialInvocationCore,
|
|
12
|
+
type InitialInvocationCore,
|
|
13
|
+
} from "./invocationProducer.js";
|
|
14
|
+
import { data } from "../test-fixtures/attachScenarioBarriers.js";
|
|
15
|
+
import { mintInitialLineage } from "./lineageAuthority.js";
|
|
16
|
+
import { captureInitialAttachForLineage } from "../operations/initialAttach.js";
|
|
17
|
+
|
|
18
|
+
const controls = vi.hoisted(() => {
|
|
19
|
+
const entries: { coversRetained(): boolean; coversFresh(): boolean }[] = [];
|
|
20
|
+
return { entries, legacy: 0 };
|
|
21
|
+
});
|
|
22
|
+
// Synthetic TEST coverage only. Production compiled profile arrays stay EMPTY.
|
|
23
|
+
vi.mock("../operations/sourceOperations.js", () => {
|
|
24
|
+
const poisoned = () => {
|
|
25
|
+
controls.legacy++;
|
|
26
|
+
throw Error("LEGACY_SOURCE_POISON");
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
COMPILED_INITIAL_ENTRIES: controls.entries,
|
|
30
|
+
ORIGINAL_ORIGIN_ASSOCIATION: null,
|
|
31
|
+
loadFixedInitialOperation: poisoned,
|
|
32
|
+
loadOwnedTransportSource: poisoned,
|
|
33
|
+
loadInitialOwnedTransportSource: poisoned,
|
|
34
|
+
loadRecoveryOwnedTransportSource: poisoned,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
vi.mock("../originalOwner.js", () => ({
|
|
38
|
+
OWNER: Object.freeze({
|
|
39
|
+
get basis() {
|
|
40
|
+
controls.legacy++;
|
|
41
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
42
|
+
},
|
|
43
|
+
check() {
|
|
44
|
+
controls.legacy++;
|
|
45
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
46
|
+
},
|
|
47
|
+
sample() {
|
|
48
|
+
controls.legacy++;
|
|
49
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
50
|
+
},
|
|
51
|
+
subscribe() {
|
|
52
|
+
controls.legacy++;
|
|
53
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
54
|
+
},
|
|
55
|
+
retire() {
|
|
56
|
+
controls.legacy++;
|
|
57
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
}));
|
|
61
|
+
type Input = Parameters<Parameters<typeof initialOperations>[0]>[0];
|
|
62
|
+
type Declaration = {
|
|
63
|
+
source: RetainedInput;
|
|
64
|
+
post: Record<string, unknown>;
|
|
65
|
+
key: string;
|
|
66
|
+
};
|
|
67
|
+
function declaration(suffix?: string): Declaration {
|
|
68
|
+
const original = declaredInputs("INITIAL-ACK");
|
|
69
|
+
const replace = (_key: string, value: unknown) =>
|
|
70
|
+
suffix && value === "sub_original" ? "sub_original_" + suffix : value;
|
|
71
|
+
const raw = JSON.parse(JSON.stringify(original.original), replace);
|
|
72
|
+
if (suffix) raw.attachRequest.attachKey += ":" + suffix;
|
|
73
|
+
const post: Record<string, unknown> = JSON.parse(
|
|
74
|
+
JSON.stringify(original.aPost),
|
|
75
|
+
replace,
|
|
76
|
+
);
|
|
77
|
+
if (suffix) post.id += "_" + suffix;
|
|
78
|
+
return {
|
|
79
|
+
source: captureRetainedInput(raw),
|
|
80
|
+
post,
|
|
81
|
+
key: suffix
|
|
82
|
+
? "sk_test_invalid_actor_" + suffix
|
|
83
|
+
: "sk_test_invalid_owner_core",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function windowFor(source: RetainedInput) {
|
|
87
|
+
return {
|
|
88
|
+
workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
|
|
89
|
+
endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function wireFor(
|
|
93
|
+
declared: Declaration[],
|
|
94
|
+
beforePost = async (_index: number) => {},
|
|
95
|
+
) {
|
|
96
|
+
const calls: { method: string; path: string; index: number }[] = [];
|
|
97
|
+
const routes = new Map<string, { body: unknown; auth: Set<string> }>();
|
|
98
|
+
for (const item of declared) {
|
|
99
|
+
const b = item.source.originalBundle;
|
|
100
|
+
const rows: [string, unknown][] = [
|
|
101
|
+
[
|
|
102
|
+
"/v1/subscriptions/" +
|
|
103
|
+
item.source.attachRequest.preparation.expected.subscriptionId,
|
|
104
|
+
b.wireSubscription,
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"/v1/prices/" +
|
|
108
|
+
item.source.attachRequest.preparation.expected.targetPriceId,
|
|
109
|
+
b.wireTargetPrice,
|
|
110
|
+
],
|
|
111
|
+
["/v1/customers/" + b.wireBillingCustomer.id, b.wireBillingCustomer],
|
|
112
|
+
];
|
|
113
|
+
for (const row of b.couponReads) {
|
|
114
|
+
assert(typeof row.couponId === "string");
|
|
115
|
+
rows.push([
|
|
116
|
+
"/v1/coupons/" + encodeURIComponent(row.couponId),
|
|
117
|
+
row.wireCoupon,
|
|
118
|
+
]);
|
|
119
|
+
}
|
|
120
|
+
for (const [path, body] of rows) {
|
|
121
|
+
const route = routes.get(path) ?? { body, auth: new Set<string>() };
|
|
122
|
+
route.auth.add("Bearer " + item.key);
|
|
123
|
+
routes.set(path, route);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
calls,
|
|
128
|
+
fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
129
|
+
const url = new URL(String(input));
|
|
130
|
+
assert.equal(url.origin, "https://api.stripe.com");
|
|
131
|
+
assert.equal(init?.redirect, "error");
|
|
132
|
+
const headers = new Headers(init?.headers);
|
|
133
|
+
const auth = headers.get("authorization");
|
|
134
|
+
let body: unknown,
|
|
135
|
+
index = -1;
|
|
136
|
+
if (init?.method === "GET") {
|
|
137
|
+
const row = routes.get(url.pathname);
|
|
138
|
+
assert(row && auth && row.auth.has(auth));
|
|
139
|
+
body = row.body;
|
|
140
|
+
} else {
|
|
141
|
+
assert.equal(init?.method, "POST");
|
|
142
|
+
assert.equal(url.pathname, "/v1/subscription_schedules");
|
|
143
|
+
index = declared.findIndex(
|
|
144
|
+
(item) =>
|
|
145
|
+
item.source.attachRequest.attachKey ===
|
|
146
|
+
headers.get("idempotency-key"),
|
|
147
|
+
);
|
|
148
|
+
assert(index >= 0);
|
|
149
|
+
assert.equal(auth, "Bearer " + declared[index].key);
|
|
150
|
+
assert.equal(
|
|
151
|
+
new URLSearchParams(String(init?.body)).get("from_subscription"),
|
|
152
|
+
declared[index].source.attachRequest.preparation.expected
|
|
153
|
+
.subscriptionId,
|
|
154
|
+
);
|
|
155
|
+
await beforePost(index);
|
|
156
|
+
body = declared[index].post;
|
|
157
|
+
}
|
|
158
|
+
calls.push({ method: init?.method ?? "", path: url.pathname, index });
|
|
159
|
+
return new Response(JSON.stringify(body), {
|
|
160
|
+
status: 200,
|
|
161
|
+
headers: {
|
|
162
|
+
"content-type": "application/json",
|
|
163
|
+
"request-id": "req_initial_actor_" + calls.length,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
controls.legacy = 0;
|
|
171
|
+
controls.entries.splice(0, controls.entries.length, {
|
|
172
|
+
coversRetained: () => true,
|
|
173
|
+
coversFresh: () => true,
|
|
174
|
+
});
|
|
175
|
+
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
|
|
176
|
+
vi.setSystemTime(
|
|
177
|
+
(declaration().source.attachRequest.firstDispatchedAt + 1) * 1000,
|
|
178
|
+
);
|
|
179
|
+
vi.spyOn(process.hrtime, "bigint").mockReturnValue(INITIAL_NS);
|
|
180
|
+
});
|
|
181
|
+
afterEach(() => {
|
|
182
|
+
vi.useRealTimers();
|
|
183
|
+
vi.unstubAllGlobals();
|
|
184
|
+
vi.restoreAllMocks();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("runs the actual initial actor with original SDK, C10 commits and retained receipt before returning ACK DATA", async () => {
|
|
188
|
+
const declared = declaration();
|
|
189
|
+
await initialOperations(
|
|
190
|
+
async (input) => {
|
|
191
|
+
assert(input.fresh.result.disposition === "acquired");
|
|
192
|
+
const reservation = input.fresh.result.reservation;
|
|
193
|
+
const wire = wireFor([declared], async () => {
|
|
194
|
+
expect(
|
|
195
|
+
await input.journal.readStageEvent({
|
|
196
|
+
attemptId: reservation.attemptId,
|
|
197
|
+
sequence: 1,
|
|
198
|
+
}),
|
|
199
|
+
).not.toBeNull();
|
|
200
|
+
expect(await input.journal.readProviderAcknowledgement()).toBeNull();
|
|
201
|
+
});
|
|
202
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
203
|
+
const core = await captureInitialInvocationCore(
|
|
204
|
+
input.fresh.call,
|
|
205
|
+
input.journal,
|
|
206
|
+
);
|
|
207
|
+
try {
|
|
208
|
+
expect(typeof core.initialAttach).toBe("function");
|
|
209
|
+
const actor = core.initialAttach();
|
|
210
|
+
expect(core.initialAttach() === actor).toBe(true);
|
|
211
|
+
const result = data(await actor.invoke());
|
|
212
|
+
expect(result.status).toBe("attach_acknowledged");
|
|
213
|
+
expect(result.operationalAuthority).toBe(false);
|
|
214
|
+
expect(data(result.receipt).providerSnapshot).toEqual(declared.post);
|
|
215
|
+
const retained = await input.journal.readProviderAcknowledgement();
|
|
216
|
+
assert(retained);
|
|
217
|
+
expect(JSON.parse(retained.receiptJSON)).toEqual(result.receipt);
|
|
218
|
+
for (const sequence of [1, 2, 3] as const)
|
|
219
|
+
expect(
|
|
220
|
+
await input.journal.readStageEvent({
|
|
221
|
+
attemptId: reservation.attemptId,
|
|
222
|
+
sequence,
|
|
223
|
+
}),
|
|
224
|
+
).not.toBeNull();
|
|
225
|
+
const requests = wire.calls.length;
|
|
226
|
+
expect(data(await actor.invoke()).reason).toBe("invocation_consumed");
|
|
227
|
+
expect(wire.calls.length).toBe(requests);
|
|
228
|
+
expect(wire.calls.filter((row) => row.method === "POST")).toHaveLength(
|
|
229
|
+
1,
|
|
230
|
+
);
|
|
231
|
+
expect(controls.legacy).toBe(0);
|
|
232
|
+
} finally {
|
|
233
|
+
core.owner.retire();
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
1,
|
|
237
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("EMPTY capture and invocation refuse before Source, client or clock effects", async () => {
|
|
242
|
+
controls.entries.length = 0;
|
|
243
|
+
const declared = declaration();
|
|
244
|
+
await initialOperations(
|
|
245
|
+
async ({ fresh, journal }) => {
|
|
246
|
+
let http = 0;
|
|
247
|
+
vi.stubGlobal("fetch", () => {
|
|
248
|
+
http++;
|
|
249
|
+
throw Error("UNEXPECTED_HTTP");
|
|
250
|
+
});
|
|
251
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
252
|
+
try {
|
|
253
|
+
expect(typeof core.initialAttach).toBe("function");
|
|
254
|
+
const reads = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
255
|
+
expect(() =>
|
|
256
|
+
Reflect.apply(core.initialAttach, undefined, [{}]),
|
|
257
|
+
).toThrow("INITIAL_OPERATION_UNBOUND");
|
|
258
|
+
const actor = core.initialAttach();
|
|
259
|
+
expect(data(await actor.invoke()).reason).toBe(
|
|
260
|
+
"no_qualified_native_class",
|
|
261
|
+
);
|
|
262
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(reads);
|
|
263
|
+
expect(controls.legacy).toBe(0);
|
|
264
|
+
expect(http).toBe(0);
|
|
265
|
+
} finally {
|
|
266
|
+
core.owner.retire();
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
1,
|
|
270
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("a stale Owner cannot load an initial operation or write a stage event", async () => {
|
|
275
|
+
const declared = declaration();
|
|
276
|
+
await initialOperations(
|
|
277
|
+
async (input) => {
|
|
278
|
+
let http = 0;
|
|
279
|
+
vi.stubGlobal("fetch", () => {
|
|
280
|
+
http++;
|
|
281
|
+
throw Error("UNEXPECTED_HTTP");
|
|
282
|
+
});
|
|
283
|
+
const core = await captureInitialInvocationCore(
|
|
284
|
+
input.fresh.call,
|
|
285
|
+
input.journal,
|
|
286
|
+
);
|
|
287
|
+
expect(typeof core.initialAttach).toBe("function");
|
|
288
|
+
const actor = core.initialAttach();
|
|
289
|
+
const before = await input.journal.loadAuthorizedOperation();
|
|
290
|
+
core.owner.retire();
|
|
291
|
+
await expect(actor.invoke()).rejects.toThrow("INITIAL_ACTOR_STOP");
|
|
292
|
+
expect(await input.journal.loadAuthorizedOperation()).toEqual(before);
|
|
293
|
+
expect(http).toBe(0);
|
|
294
|
+
expect(controls.legacy).toBe(0);
|
|
295
|
+
},
|
|
296
|
+
1,
|
|
297
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("EMPTY factory admission does not construct an Owner for a fresh bare lineage", async () => {
|
|
302
|
+
controls.entries.length = 0;
|
|
303
|
+
const declared = declaration();
|
|
304
|
+
await initialOperations(
|
|
305
|
+
async ({ fresh, journal }) => {
|
|
306
|
+
const token = mintInitialLineage(fresh.call, journal, 2);
|
|
307
|
+
const reads = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
308
|
+
const actor = captureInitialAttachForLineage(token);
|
|
309
|
+
expect(data(await actor.invoke()).reason).toBe(
|
|
310
|
+
"no_qualified_native_class",
|
|
311
|
+
);
|
|
312
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(reads);
|
|
313
|
+
const stored = await journal.loadAuthorizedOperation();
|
|
314
|
+
assert(stored && "initialBasis" in stored);
|
|
315
|
+
expect(stored.initialBasis).toBeNull();
|
|
316
|
+
expect(controls.legacy).toBe(0);
|
|
317
|
+
},
|
|
318
|
+
1,
|
|
319
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("two distinct SDK/root actors keep retained receipt DATA separate from returned ACK after one Owner retires", async () => {
|
|
324
|
+
const declared = [declaration("alpha"), declaration("bravo")];
|
|
325
|
+
const contexts: Input[] = [];
|
|
326
|
+
const cores: InitialInvocationCore[] = [];
|
|
327
|
+
let entered = () => {},
|
|
328
|
+
retired = () => {},
|
|
329
|
+
release = () => {},
|
|
330
|
+
retainedCount = 0;
|
|
331
|
+
const bothRetained = new Promise<void>((resolve) => {
|
|
332
|
+
entered = resolve;
|
|
333
|
+
});
|
|
334
|
+
const firstRetired = new Promise<void>((resolve) => {
|
|
335
|
+
retired = resolve;
|
|
336
|
+
});
|
|
337
|
+
const gate = new Promise<void>((resolve) => {
|
|
338
|
+
release = resolve;
|
|
339
|
+
});
|
|
340
|
+
const wire = wireFor(declared);
|
|
341
|
+
await initialOperations(
|
|
342
|
+
async (input) => {
|
|
343
|
+
contexts[input.index] = input;
|
|
344
|
+
assert(input.fresh.result.disposition === "acquired");
|
|
345
|
+
const reservation = input.fresh.result.reservation;
|
|
346
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
347
|
+
const core = await captureInitialInvocationCore(
|
|
348
|
+
input.fresh.call,
|
|
349
|
+
input.journal,
|
|
350
|
+
);
|
|
351
|
+
cores[input.index] = core;
|
|
352
|
+
try {
|
|
353
|
+
expect(typeof core.initialAttach).toBe("function");
|
|
354
|
+
const observed = core
|
|
355
|
+
.initialAttach()
|
|
356
|
+
.invoke()
|
|
357
|
+
.then(
|
|
358
|
+
(value) => ({ value }),
|
|
359
|
+
(error: unknown) => ({ error }),
|
|
360
|
+
);
|
|
361
|
+
await bothRetained;
|
|
362
|
+
const stored = await input.journal.readProviderAcknowledgement();
|
|
363
|
+
assert(stored);
|
|
364
|
+
expect(
|
|
365
|
+
await input.journal.readStageEvent({
|
|
366
|
+
attemptId: reservation.attemptId,
|
|
367
|
+
sequence: 3,
|
|
368
|
+
}),
|
|
369
|
+
).toBeNull();
|
|
370
|
+
if (input.index === 0) {
|
|
371
|
+
core.owner.retire();
|
|
372
|
+
const result = await observed;
|
|
373
|
+
if ("value" in result)
|
|
374
|
+
expect(data(result.value).status).not.toBe("attach_acknowledged");
|
|
375
|
+
retired();
|
|
376
|
+
} else {
|
|
377
|
+
await firstRetired;
|
|
378
|
+
release();
|
|
379
|
+
const result = await observed;
|
|
380
|
+
assert("value" in result);
|
|
381
|
+
expect(data(result.value).status).toBe("attach_acknowledged");
|
|
382
|
+
expect(data(data(result.value).receipt).providerSnapshot).toEqual(
|
|
383
|
+
declared[1].post,
|
|
384
|
+
);
|
|
385
|
+
expect(
|
|
386
|
+
await input.journal.readStageEvent({
|
|
387
|
+
attemptId: reservation.attemptId,
|
|
388
|
+
sequence: 3,
|
|
389
|
+
}),
|
|
390
|
+
).not.toBeNull();
|
|
391
|
+
expect(core.owner.check().retired).toBe(false);
|
|
392
|
+
expect(cores[0].owner === cores[1].owner).toBe(false);
|
|
393
|
+
expect(contexts[0].sdk === contexts[1].sdk).toBe(false);
|
|
394
|
+
expect(
|
|
395
|
+
wire.calls.filter((row) => row.method === "POST"),
|
|
396
|
+
).toHaveLength(2);
|
|
397
|
+
}
|
|
398
|
+
release();
|
|
399
|
+
expect(await input.journal.readProviderAcknowledgement()).toEqual(
|
|
400
|
+
stored,
|
|
401
|
+
);
|
|
402
|
+
if (input.index === 0)
|
|
403
|
+
expect(
|
|
404
|
+
await input.journal.readStageEvent({
|
|
405
|
+
attemptId: reservation.attemptId,
|
|
406
|
+
sequence: 3,
|
|
407
|
+
}),
|
|
408
|
+
).toBeNull();
|
|
409
|
+
expect(controls.legacy).toBe(0);
|
|
410
|
+
} finally {
|
|
411
|
+
release();
|
|
412
|
+
retired();
|
|
413
|
+
core.owner.retire();
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
2,
|
|
417
|
+
{
|
|
418
|
+
sources: declared.map((item) => item.source),
|
|
419
|
+
keys: declared.map((item) => item.key),
|
|
420
|
+
...windowFor(declared[0].source),
|
|
421
|
+
afterRetain: async () => {
|
|
422
|
+
if (++retainedCount === 2) entered();
|
|
423
|
+
await gate;
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it.each(["read", "post"] as const)(
|
|
430
|
+
"actual SDK %s rejection stays bound to its invocation and cannot return ACK DATA",
|
|
431
|
+
async (phase) => {
|
|
432
|
+
const declared = declaration();
|
|
433
|
+
const wire = wireFor([declared]);
|
|
434
|
+
await initialOperations(
|
|
435
|
+
async (input) => {
|
|
436
|
+
assert(input.fresh.result.disposition === "acquired");
|
|
437
|
+
const reservation = input.fresh.result.reservation;
|
|
438
|
+
let failed = 0;
|
|
439
|
+
vi.stubGlobal(
|
|
440
|
+
"fetch",
|
|
441
|
+
async (request: RequestInfo | URL, init?: RequestInit) => {
|
|
442
|
+
if (phase === "read" || init?.method === "POST") {
|
|
443
|
+
failed++;
|
|
444
|
+
assert.equal(
|
|
445
|
+
new URL(String(request)).origin,
|
|
446
|
+
"https://api.stripe.com",
|
|
447
|
+
);
|
|
448
|
+
assert.equal(
|
|
449
|
+
new Headers(init?.headers).get("authorization"),
|
|
450
|
+
"Bearer " + declared.key,
|
|
451
|
+
);
|
|
452
|
+
if (phase === "post")
|
|
453
|
+
expect(
|
|
454
|
+
await input.journal.readStageEvent({
|
|
455
|
+
attemptId: reservation.attemptId,
|
|
456
|
+
sequence: 1,
|
|
457
|
+
}),
|
|
458
|
+
).not.toBeNull();
|
|
459
|
+
return new Response(
|
|
460
|
+
JSON.stringify({
|
|
461
|
+
error: {
|
|
462
|
+
type: "invalid_request_error",
|
|
463
|
+
code: "synthetic_rejection",
|
|
464
|
+
message: "SYNTHETIC_PRIVATE_BODY_DO_NOT_FORWARD",
|
|
465
|
+
},
|
|
466
|
+
}),
|
|
467
|
+
{
|
|
468
|
+
status: 400,
|
|
469
|
+
headers: {
|
|
470
|
+
"content-type": "application/json",
|
|
471
|
+
"request-id": "req_initial_rejection",
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
return wire.fetch(request, init);
|
|
477
|
+
},
|
|
478
|
+
);
|
|
479
|
+
const core = await captureInitialInvocationCore(
|
|
480
|
+
input.fresh.call,
|
|
481
|
+
input.journal,
|
|
482
|
+
);
|
|
483
|
+
try {
|
|
484
|
+
const actor = core.initialAttach();
|
|
485
|
+
const error: unknown = await actor.invoke().then(
|
|
486
|
+
() => assert.fail("EXPECTED_PROVIDER_REJECTION"),
|
|
487
|
+
(reason: unknown) => reason,
|
|
488
|
+
);
|
|
489
|
+
assert(error instanceof Error);
|
|
490
|
+
expect(error.message).toBe("INITIAL_PROVIDER_REJECTED");
|
|
491
|
+
const failure = data(
|
|
492
|
+
Object.getOwnPropertyDescriptor(error, "failure")?.value,
|
|
493
|
+
);
|
|
494
|
+
expect(failure).toMatchObject({
|
|
495
|
+
category: "provider_rejected",
|
|
496
|
+
phase,
|
|
497
|
+
ordinal:
|
|
498
|
+
phase === "read"
|
|
499
|
+
? 1
|
|
500
|
+
: declared.source.originalBundle.couponReads.length + 4,
|
|
501
|
+
outcome: "unknown",
|
|
502
|
+
operationalAuthority: false,
|
|
503
|
+
});
|
|
504
|
+
expect(JSON.stringify(failure)).not.toContain(
|
|
505
|
+
"SYNTHETIC_PRIVATE_BODY_DO_NOT_FORWARD",
|
|
506
|
+
);
|
|
507
|
+
expect(failed).toBe(1);
|
|
508
|
+
expect(await input.journal.readProviderAcknowledgement()).toBeNull();
|
|
509
|
+
expect(
|
|
510
|
+
await input.journal.readStageEvent({
|
|
511
|
+
attemptId: reservation.attemptId,
|
|
512
|
+
sequence: phase === "read" ? 1 : 2,
|
|
513
|
+
}),
|
|
514
|
+
).toBeNull();
|
|
515
|
+
expect(data(await actor.invoke()).reason).toBe("invocation_consumed");
|
|
516
|
+
expect(failed).toBe(1);
|
|
517
|
+
expect(controls.legacy).toBe(0);
|
|
518
|
+
} finally {
|
|
519
|
+
core.owner.retire();
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
1,
|
|
523
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
524
|
+
);
|
|
525
|
+
},
|
|
526
|
+
);
|