@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
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { readInitialLineage } from "./lineageAuthority.js";
|
|
2
|
+
import { journalWorkForInitialLineage } from "./journalWorkFactory.js";
|
|
3
|
+
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
4
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
|
+
import { captureInitialStockRawDelegate } from "./stockDelegateFactory.js";
|
|
6
|
+
import { createInitialMaterialClassifiers } from "../material/classifiers.js";
|
|
7
|
+
import { captureRetainedInput } from "../material/capture.js";
|
|
8
|
+
import { captureAttachReceipt } from "../c10/eventCapture.js";
|
|
9
|
+
import { field, scalar } from "../c10/ownData.js";
|
|
10
|
+
import { materialize } from "../c10/eventCodec.js";
|
|
11
|
+
|
|
12
|
+
function stop(): never {
|
|
13
|
+
throw Error("INITIAL_OPERATION_UNBOUND");
|
|
14
|
+
}
|
|
15
|
+
const operations = new WeakMap<object, ReturnType<typeof construct>>();
|
|
16
|
+
|
|
17
|
+
async function construct(token: object) {
|
|
18
|
+
const lineage = readInitialLineage(token);
|
|
19
|
+
const owner = ownerForInitialLineage(token);
|
|
20
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
21
|
+
const classified = await createInitialMaterialClassifiers(token).retained();
|
|
22
|
+
owner.check();
|
|
23
|
+
if (classified.status !== "classified") stop();
|
|
24
|
+
const retained = JSON.parse(lineage.reservation.recordJSON);
|
|
25
|
+
const original = captureRetainedInput({
|
|
26
|
+
attachRequest: retained.attachRequest,
|
|
27
|
+
originalBundle: retained.originalBundle,
|
|
28
|
+
});
|
|
29
|
+
const request = classified.material.completeRequest;
|
|
30
|
+
const customer = classified.material.billingCustomer;
|
|
31
|
+
if (!customer || typeof customer.id !== "string") stop();
|
|
32
|
+
const query = String(
|
|
33
|
+
new URLSearchParams(
|
|
34
|
+
["discounts", "items.data.discounts", "items.data.price"].map(
|
|
35
|
+
(value, index) => ["expand[" + index + "]", value],
|
|
36
|
+
),
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
const rows = [
|
|
40
|
+
{
|
|
41
|
+
resource: "subscription",
|
|
42
|
+
path:
|
|
43
|
+
"/v1/subscriptions/" + request.payload.from_subscription + "?" + query,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
resource: "price",
|
|
47
|
+
path: "/v1/prices/" + classified.material.targetPrice.id,
|
|
48
|
+
},
|
|
49
|
+
{ resource: "customer", path: "/v1/customers/" + customer.id },
|
|
50
|
+
...original.originalBundle.couponReads.map((row) => {
|
|
51
|
+
if (typeof row.couponId !== "string") stop();
|
|
52
|
+
return {
|
|
53
|
+
resource: "coupon",
|
|
54
|
+
path: "/v1/coupons/" + encodeURIComponent(row.couponId),
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
];
|
|
58
|
+
const readPlan = Object.freeze(
|
|
59
|
+
rows.map((row, index) =>
|
|
60
|
+
Object.freeze({
|
|
61
|
+
...row,
|
|
62
|
+
ordinal: index + 1,
|
|
63
|
+
method: "GET",
|
|
64
|
+
body: undefined,
|
|
65
|
+
options: Object.freeze({
|
|
66
|
+
apiVersion: request.apiVersion,
|
|
67
|
+
maxNetworkRetries: 0,
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
const delegate = captureInitialStockRawDelegate(token);
|
|
73
|
+
const send = journalWorkForInitialLineage(token).captureSend();
|
|
74
|
+
let spent = false;
|
|
75
|
+
const slot = Object.freeze({
|
|
76
|
+
takeOnce(...args: unknown[]) {
|
|
77
|
+
if (spent) return null;
|
|
78
|
+
spent = true;
|
|
79
|
+
if (args.length !== 1 || args[0] !== owner) return null;
|
|
80
|
+
owner.check();
|
|
81
|
+
return Object.freeze({
|
|
82
|
+
rawAttachRequest: original.attachRequest,
|
|
83
|
+
originalBundle: original.originalBundle,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
const sink = Object.freeze({
|
|
88
|
+
send(record: Parameters<typeof send>[0], ack: Parameters<typeof send>[1]) {
|
|
89
|
+
return owned(() =>
|
|
90
|
+
send(record, (value) => {
|
|
91
|
+
owner.check();
|
|
92
|
+
ack(value);
|
|
93
|
+
owner.check();
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
owner.check();
|
|
99
|
+
return Object.freeze({
|
|
100
|
+
request,
|
|
101
|
+
expected: classified.material.originalPrepared.expected,
|
|
102
|
+
operation: Object.freeze({
|
|
103
|
+
owner,
|
|
104
|
+
originAssociation: lineage.originAssociation,
|
|
105
|
+
slot,
|
|
106
|
+
readPlan,
|
|
107
|
+
delegate,
|
|
108
|
+
sink,
|
|
109
|
+
}),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** One construction and origin per original winning call; failures cannot remint. */
|
|
114
|
+
export function operationForInitialLineage(token: object) {
|
|
115
|
+
if (arguments.length !== 1) stop();
|
|
116
|
+
const owner = ownerForInitialLineage(token);
|
|
117
|
+
owner.check();
|
|
118
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
119
|
+
let pending = operations.get(token);
|
|
120
|
+
if (!pending) {
|
|
121
|
+
pending = owned(async () => {
|
|
122
|
+
try {
|
|
123
|
+
return await construct(token);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
owner.retire();
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
operations.set(token, pending);
|
|
130
|
+
}
|
|
131
|
+
const captured = pending;
|
|
132
|
+
return owned(() => captured);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Persist the fully captured C3 DATA before receipt3 or a returned ACK. */
|
|
136
|
+
export async function retainInitialReceiptForLineage(
|
|
137
|
+
token: object,
|
|
138
|
+
receipt: unknown,
|
|
139
|
+
) {
|
|
140
|
+
if (arguments.length !== 2) stop();
|
|
141
|
+
const owner = ownerForInitialLineage(token);
|
|
142
|
+
owner.check();
|
|
143
|
+
const lineage = readInitialLineage(token);
|
|
144
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
145
|
+
const frame = await owned(() => operationForInitialLineage(token));
|
|
146
|
+
const captured = captureAttachReceipt({
|
|
147
|
+
event: "receipt",
|
|
148
|
+
stage: "attach",
|
|
149
|
+
request: frame.request,
|
|
150
|
+
receipt,
|
|
151
|
+
});
|
|
152
|
+
owner.check();
|
|
153
|
+
const receiptNode = field(captured, "receipt");
|
|
154
|
+
const binding = scalar(field(receiptNode, "binding"));
|
|
155
|
+
if (typeof binding !== "string") stop();
|
|
156
|
+
const receiptJSON = JSON.stringify(materialize(receiptNode));
|
|
157
|
+
const retained = await owned(() =>
|
|
158
|
+
journalWorkForInitialLineage(token).retain({
|
|
159
|
+
attemptId: lineage.reservation.attemptId,
|
|
160
|
+
expectedSequence: 2,
|
|
161
|
+
receiptJSON,
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
owner.check();
|
|
165
|
+
if (
|
|
166
|
+
retained.status !== "retained" ||
|
|
167
|
+
retained.schemaVersion !== 1 ||
|
|
168
|
+
retained.stage !== "attach" ||
|
|
169
|
+
retained.operationId !== lineage.reservation.operationId ||
|
|
170
|
+
retained.attemptId !== lineage.reservation.attemptId ||
|
|
171
|
+
retained.sourcePayloadId !== lineage.reservation.payloadId ||
|
|
172
|
+
retained.receiptBinding !== binding
|
|
173
|
+
)
|
|
174
|
+
stop();
|
|
175
|
+
return retained;
|
|
176
|
+
}
|
package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
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 { captureInitialInvocationCore } from "./invocationProducer.js";
|
|
7
|
+
|
|
8
|
+
const legacy = vi.hoisted(() => ({ touched: 0 }));
|
|
9
|
+
vi.mock("../originalOwner.js", () => ({
|
|
10
|
+
OWNER: Object.freeze({
|
|
11
|
+
get basis() {
|
|
12
|
+
legacy.touched++;
|
|
13
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
14
|
+
},
|
|
15
|
+
check() {
|
|
16
|
+
legacy.touched++;
|
|
17
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
18
|
+
},
|
|
19
|
+
sample() {
|
|
20
|
+
legacy.touched++;
|
|
21
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
22
|
+
},
|
|
23
|
+
subscribe() {
|
|
24
|
+
legacy.touched++;
|
|
25
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
26
|
+
},
|
|
27
|
+
retire() {
|
|
28
|
+
legacy.touched++;
|
|
29
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
}));
|
|
33
|
+
function declaration() {
|
|
34
|
+
const source = declaredInputs("INITIAL-ACK").original;
|
|
35
|
+
return {
|
|
36
|
+
source,
|
|
37
|
+
workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
|
|
38
|
+
endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function responses(options: ReturnType<typeof declaration>) {
|
|
42
|
+
const b = options.source.originalBundle;
|
|
43
|
+
const expected = options.source.attachRequest.preparation.expected;
|
|
44
|
+
const rows: [string, unknown][] = [
|
|
45
|
+
["/v1/subscriptions/" + expected.subscriptionId, b.wireSubscription],
|
|
46
|
+
["/v1/prices/" + expected.targetPriceId, b.wireTargetPrice],
|
|
47
|
+
["/v1/customers/" + b.wireBillingCustomer.id, b.wireBillingCustomer],
|
|
48
|
+
];
|
|
49
|
+
for (const row of b.couponReads) {
|
|
50
|
+
assert(typeof row.couponId === "string");
|
|
51
|
+
rows.push([
|
|
52
|
+
"/v1/coupons/" + encodeURIComponent(row.couponId),
|
|
53
|
+
row.wireCoupon,
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
return new Map(rows);
|
|
57
|
+
}
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
legacy.touched = 0;
|
|
60
|
+
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
|
|
61
|
+
vi.setSystemTime(
|
|
62
|
+
(declaration().source.attachRequest.firstDispatchedAt + 1) * 1000,
|
|
63
|
+
);
|
|
64
|
+
vi.spyOn(process.hrtime, "bigint").mockReturnValue(INITIAL_NS);
|
|
65
|
+
});
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
vi.useRealTimers();
|
|
68
|
+
vi.unstubAllGlobals();
|
|
69
|
+
vi.restoreAllMocks();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("acquires complete raw Coupon material through its exact maintained SDK and bounded plan", async () => {
|
|
73
|
+
const options = declaration();
|
|
74
|
+
const bodies = responses(options);
|
|
75
|
+
await initialOperations(
|
|
76
|
+
async ({ fresh, journal, sdk }) => {
|
|
77
|
+
const calls: string[] = [];
|
|
78
|
+
vi.stubGlobal(
|
|
79
|
+
"fetch",
|
|
80
|
+
async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
81
|
+
const url = new URL(String(input));
|
|
82
|
+
assert.equal(url.origin, "https://api.stripe.com");
|
|
83
|
+
assert.equal(init?.method, "GET");
|
|
84
|
+
assert.equal(init?.redirect, "error");
|
|
85
|
+
const headers = new Headers(init?.headers);
|
|
86
|
+
assert.equal(
|
|
87
|
+
headers.get("authorization"),
|
|
88
|
+
"Bearer sk_test_invalid_owner_core",
|
|
89
|
+
);
|
|
90
|
+
assert.equal(headers.get("stripe-version"), sdk.stripeApiVersion);
|
|
91
|
+
assert(bodies.has(url.pathname));
|
|
92
|
+
calls.push(url.pathname);
|
|
93
|
+
return new Response(JSON.stringify(bodies.get(url.pathname)), {
|
|
94
|
+
status: 200,
|
|
95
|
+
headers: {
|
|
96
|
+
"content-type": "application/json",
|
|
97
|
+
"request-id": "req_initial_acquisition",
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
103
|
+
try {
|
|
104
|
+
expect(typeof core.acquire).toBe("function");
|
|
105
|
+
const result = await core.acquire();
|
|
106
|
+
expect(result.ok).toBe(true);
|
|
107
|
+
assert(result.ok);
|
|
108
|
+
expect(result.bundle).toEqual(options.source.originalBundle);
|
|
109
|
+
expect(result.observedAt).toBe(
|
|
110
|
+
options.source.attachRequest.firstDispatchedAt + 1,
|
|
111
|
+
);
|
|
112
|
+
expect(result.sourceFulfillmentEstablished).toBe(false);
|
|
113
|
+
expect(result.clockProvenanceEstablished).toBe(false);
|
|
114
|
+
expect(result.operatorReady).toBe(false);
|
|
115
|
+
expect(calls).toEqual([...bodies.keys()]);
|
|
116
|
+
expect(
|
|
117
|
+
(await core.material.fresh(result.bundle, result.observedAt)).status,
|
|
118
|
+
).toBe("classified");
|
|
119
|
+
expect((await core.acquire()).ok).toBe(false);
|
|
120
|
+
expect(calls).toEqual([...bodies.keys()]);
|
|
121
|
+
expect(legacy.touched).toBe(0);
|
|
122
|
+
} finally {
|
|
123
|
+
core.owner.retire();
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
1,
|
|
127
|
+
options,
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("refuses replacement acquisition inputs before clocks or HTTP", async () => {
|
|
132
|
+
const options = declaration();
|
|
133
|
+
await initialOperations(
|
|
134
|
+
async ({ fresh, journal }) => {
|
|
135
|
+
let foreign = 0,
|
|
136
|
+
requests = 0;
|
|
137
|
+
vi.stubGlobal("fetch", () => {
|
|
138
|
+
requests++;
|
|
139
|
+
throw Error("UNEXPECTED_HTTP");
|
|
140
|
+
});
|
|
141
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
142
|
+
try {
|
|
143
|
+
expect(typeof core.acquire).toBe("function");
|
|
144
|
+
const input = {
|
|
145
|
+
get expected() {
|
|
146
|
+
foreign++;
|
|
147
|
+
throw Error("FOREIGN_EXPECTED");
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
const reads = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
151
|
+
await expect(
|
|
152
|
+
Reflect.apply(core.acquire, undefined, [input]),
|
|
153
|
+
).rejects.toThrow("INITIAL_OPERATION_UNBOUND");
|
|
154
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(reads);
|
|
155
|
+
expect(foreign).toBe(0);
|
|
156
|
+
expect(requests).toBe(0);
|
|
157
|
+
expect(legacy.touched).toBe(0);
|
|
158
|
+
} finally {
|
|
159
|
+
core.owner.retire();
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
1,
|
|
163
|
+
options,
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("two pending acquisitions retain separate read lifetimes and cannot resume a retired Owner", async () => {
|
|
168
|
+
const options = declaration();
|
|
169
|
+
const bodies = responses(options);
|
|
170
|
+
let first = () => {},
|
|
171
|
+
both = () => {},
|
|
172
|
+
retired = () => {},
|
|
173
|
+
release = () => {};
|
|
174
|
+
const firstRead = new Promise<void>((resolve) => {
|
|
175
|
+
first = resolve;
|
|
176
|
+
});
|
|
177
|
+
const bothReads = new Promise<void>((resolve) => {
|
|
178
|
+
both = resolve;
|
|
179
|
+
});
|
|
180
|
+
const firstRetired = new Promise<void>((resolve) => {
|
|
181
|
+
retired = resolve;
|
|
182
|
+
});
|
|
183
|
+
const gate = new Promise<void>((resolve) => {
|
|
184
|
+
release = resolve;
|
|
185
|
+
});
|
|
186
|
+
const calls: string[] = [];
|
|
187
|
+
await initialOperations(
|
|
188
|
+
async ({ fresh, journal, index }) => {
|
|
189
|
+
vi.stubGlobal(
|
|
190
|
+
"fetch",
|
|
191
|
+
async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
192
|
+
const url = new URL(String(input));
|
|
193
|
+
assert.equal(url.origin, "https://api.stripe.com");
|
|
194
|
+
assert.equal(init?.method, "GET");
|
|
195
|
+
assert(bodies.has(url.pathname));
|
|
196
|
+
calls.push(url.pathname);
|
|
197
|
+
if (calls.length === 1) first();
|
|
198
|
+
if (calls.length === 2) both();
|
|
199
|
+
await gate;
|
|
200
|
+
return new Response(JSON.stringify(bodies.get(url.pathname)), {
|
|
201
|
+
status: 200,
|
|
202
|
+
headers: {
|
|
203
|
+
"content-type": "application/json",
|
|
204
|
+
"request-id": "req_pending_acquisition",
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
210
|
+
try {
|
|
211
|
+
expect(typeof core.acquire).toBe("function");
|
|
212
|
+
if (index === 1) await firstRead;
|
|
213
|
+
const observed = core.acquire().then(
|
|
214
|
+
(value) => ({ ok: true, value }),
|
|
215
|
+
(error: unknown) => ({ ok: false, error }),
|
|
216
|
+
);
|
|
217
|
+
await bothReads;
|
|
218
|
+
if (index === 0) {
|
|
219
|
+
core.owner.retire();
|
|
220
|
+
expect((await observed).ok).toBe(false);
|
|
221
|
+
retired();
|
|
222
|
+
} else {
|
|
223
|
+
await firstRetired;
|
|
224
|
+
release();
|
|
225
|
+
const result = await observed;
|
|
226
|
+
assert(result.ok && "value" in result && result.value.ok);
|
|
227
|
+
expect(result.value.bundle).toEqual(options.source.originalBundle);
|
|
228
|
+
expect(calls.length).toBe(bodies.size + 1);
|
|
229
|
+
expect(core.owner.check().retired).toBe(false);
|
|
230
|
+
}
|
|
231
|
+
expect(legacy.touched).toBe(0);
|
|
232
|
+
} finally {
|
|
233
|
+
release();
|
|
234
|
+
core.owner.retire();
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
2,
|
|
238
|
+
options,
|
|
239
|
+
);
|
|
240
|
+
});
|