@fantastic.dev/better-stripe 0.97.0 → 0.98.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +38 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts +11 -0
- package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/material/classifiers.js +57 -22
- package/dist/client/billing/renewalAttach/internal/material/classifiers.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +54 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +44 -37
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +71 -46
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +21 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +161 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +35 -4
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +42 -0
- package/src/client/billing/renewalAttach/internal/material/classifiers.ts +64 -22
- package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +55 -48
- package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +91 -55
- package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
- package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +25 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
- package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +175 -0
- package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
- package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
- package/src/client/billing/renewalAttach/internal/producer/producerMaterial.integration.test.ts +251 -0
- package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
- package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +100 -11
package/src/client/billing/renewalAttach/internal/producer/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
|
+
});
|