@fantastic.dev/better-stripe 0.107.0 → 0.109.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/observation/freshActor.d.ts +31 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +112 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +17 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +191 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +29 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js +205 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/profile.js +5 -1
- package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts +10 -0
- package/dist/client/billing/renewalAttach/internal/observation/reader.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/reader.js +30 -0
- package/dist/client/billing/renewalAttach/internal/observation/reader.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts +44 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js +145 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +9 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +2 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +9 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +107 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/observation/freshActor.integration.test.ts +360 -0
- package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +175 -0
- package/src/client/billing/renewalAttach/internal/observation/freshActorControls.integration.test.ts +442 -0
- package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +252 -0
- package/src/client/billing/renewalAttach/internal/observation/invocation.ts +299 -0
- package/src/client/billing/renewalAttach/internal/observation/profile.ts +9 -1
- package/src/client/billing/renewalAttach/internal/observation/reader.integration.test.ts +93 -0
- package/src/client/billing/renewalAttach/internal/observation/reader.ts +35 -0
- package/src/client/billing/renewalAttach/internal/observation/readerAuthorization.ts +179 -0
- package/src/client/billing/renewalAttach/internal/observation/readerControls.integration.test.ts +553 -0
- package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +11 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +12 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/freshObservation.ts +94 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/historySnapshot.ts +5 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationReader.ts +101 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +41 -4
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +5 -1
package/src/client/billing/renewalAttach/internal/observation/freshActorControls.integration.test.ts
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { expect, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
configureAdmissionCase,
|
|
4
|
+
admissionControls,
|
|
5
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
6
|
+
import { prepareFreshObservation } from "../test-fixtures/freshObservation.js";
|
|
7
|
+
import {
|
|
8
|
+
observerIdentity,
|
|
9
|
+
authorizeObservation,
|
|
10
|
+
readerControls,
|
|
11
|
+
} from "../test-fixtures/observationReader.js";
|
|
12
|
+
import { captureFreshRenewalObservation } from "./freshActor.js";
|
|
13
|
+
import {
|
|
14
|
+
captureObservationInvocation,
|
|
15
|
+
readObservationInvocation,
|
|
16
|
+
} from "./invocation.js";
|
|
17
|
+
import { captureFreshGetTransport } from "./freshTransport.js";
|
|
18
|
+
import Stripe from "stripe";
|
|
19
|
+
import * as replyCapture from "./capture.js";
|
|
20
|
+
import * as analyzer from "../../../renewalObservation/evidence-v1.js";
|
|
21
|
+
import { captureAuthorizedObservationHistoryReader } from "./reader.js";
|
|
22
|
+
|
|
23
|
+
const options = { identity: observerIdentity, hostQuery: authorizeObservation };
|
|
24
|
+
configureAdmissionCase(
|
|
25
|
+
"reader guard refusal clears its original timer immediately",
|
|
26
|
+
prepareFreshObservation,
|
|
27
|
+
async (h, state) => {
|
|
28
|
+
await h.inAnotherAction(async (ctx) => {
|
|
29
|
+
const original = ctx.runQuery;
|
|
30
|
+
const timers = vi.getTimerCount();
|
|
31
|
+
const reader = await captureAuthorizedObservationHistoryReader(h.sdk, {
|
|
32
|
+
actualActionCtx: ctx,
|
|
33
|
+
operationId: state.operationId,
|
|
34
|
+
parentOperationId: state.parentOperationId,
|
|
35
|
+
});
|
|
36
|
+
ctx.runQuery = async () => null;
|
|
37
|
+
try {
|
|
38
|
+
await expect(reader.read()).rejects.toThrow();
|
|
39
|
+
} finally {
|
|
40
|
+
ctx.runQuery = original;
|
|
41
|
+
}
|
|
42
|
+
expect(vi.getTimerCount()).toBe(timers);
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
options,
|
|
46
|
+
);
|
|
47
|
+
configureAdmissionCase(
|
|
48
|
+
"observer profile revocation during history acquisition refuses before selection",
|
|
49
|
+
prepareFreshObservation,
|
|
50
|
+
async (h, state) => {
|
|
51
|
+
const selectors = admissionControls.selectors,
|
|
52
|
+
calls = h.calls.length;
|
|
53
|
+
readerControls.reply = (grant) => {
|
|
54
|
+
admissionControls.observation.splice(0);
|
|
55
|
+
return grant;
|
|
56
|
+
};
|
|
57
|
+
await h.inAnotherAction(async (ctx) => {
|
|
58
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
59
|
+
actualActionCtx: ctx,
|
|
60
|
+
operationId: state.operationId,
|
|
61
|
+
parentOperationId: state.parentOperationId,
|
|
62
|
+
});
|
|
63
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
64
|
+
});
|
|
65
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
66
|
+
expect(h.calls).toHaveLength(calls);
|
|
67
|
+
},
|
|
68
|
+
options,
|
|
69
|
+
);
|
|
70
|
+
configureAdmissionCase(
|
|
71
|
+
"copied invocation tokens, supplied history and copied profiles cannot select a client",
|
|
72
|
+
prepareFreshObservation,
|
|
73
|
+
async (h, state) => {
|
|
74
|
+
const selectors = admissionControls.selectors;
|
|
75
|
+
await h.inAnotherAction(async (ctx) => {
|
|
76
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
77
|
+
actualActionCtx: ctx,
|
|
78
|
+
operationId: state.operationId,
|
|
79
|
+
parentOperationId: state.parentOperationId,
|
|
80
|
+
});
|
|
81
|
+
const cell = readObservationInvocation(token);
|
|
82
|
+
try {
|
|
83
|
+
const captured = await cell.captureHistory();
|
|
84
|
+
expect(() =>
|
|
85
|
+
captureFreshGetTransport({ ...token }, state.profile),
|
|
86
|
+
).toThrow();
|
|
87
|
+
expect(() =>
|
|
88
|
+
captureFreshGetTransport(captured.history, state.profile),
|
|
89
|
+
).toThrow();
|
|
90
|
+
expect(() =>
|
|
91
|
+
captureFreshGetTransport(token, { ...state.profile }),
|
|
92
|
+
).toThrow();
|
|
93
|
+
} finally {
|
|
94
|
+
cell.close();
|
|
95
|
+
}
|
|
96
|
+
expect(() => readObservationInvocation(token)).toThrow();
|
|
97
|
+
});
|
|
98
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
99
|
+
},
|
|
100
|
+
options,
|
|
101
|
+
);
|
|
102
|
+
configureAdmissionCase(
|
|
103
|
+
"qualifier refusal, duplicate profiles and copied history entries do not select or GET",
|
|
104
|
+
prepareFreshObservation,
|
|
105
|
+
async (h, state) => {
|
|
106
|
+
const selectors = admissionControls.selectors,
|
|
107
|
+
calls = h.calls.length;
|
|
108
|
+
admissionControls.observation.push(state.profile);
|
|
109
|
+
await expect(
|
|
110
|
+
captureFreshRenewalObservation(h.sdk, {
|
|
111
|
+
actualActionCtx: h.ctx,
|
|
112
|
+
operationId: state.operationId,
|
|
113
|
+
parentOperationId: state.parentOperationId,
|
|
114
|
+
}),
|
|
115
|
+
).rejects.toThrow();
|
|
116
|
+
admissionControls.observation.splice(
|
|
117
|
+
0,
|
|
118
|
+
2,
|
|
119
|
+
Object.freeze({ ...state.profile, historyEntry: { ...state.entry } }),
|
|
120
|
+
);
|
|
121
|
+
await expect(
|
|
122
|
+
captureFreshRenewalObservation(h.sdk, {
|
|
123
|
+
actualActionCtx: h.ctx,
|
|
124
|
+
operationId: state.operationId,
|
|
125
|
+
parentOperationId: state.parentOperationId,
|
|
126
|
+
}),
|
|
127
|
+
).rejects.toThrow();
|
|
128
|
+
admissionControls.observation.splice(
|
|
129
|
+
0,
|
|
130
|
+
1,
|
|
131
|
+
Object.freeze({ ...state.profile, coversObservation: () => false }),
|
|
132
|
+
);
|
|
133
|
+
await h.inAnotherAction(async (ctx) => {
|
|
134
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
135
|
+
actualActionCtx: ctx,
|
|
136
|
+
operationId: state.operationId,
|
|
137
|
+
parentOperationId: state.parentOperationId,
|
|
138
|
+
});
|
|
139
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
140
|
+
});
|
|
141
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
142
|
+
expect(h.calls).toHaveLength(calls);
|
|
143
|
+
},
|
|
144
|
+
options,
|
|
145
|
+
);
|
|
146
|
+
for (const point of [2, 3, 4, 5, 6, 7, 8])
|
|
147
|
+
configureAdmissionCase(
|
|
148
|
+
"revocation at authorization point " +
|
|
149
|
+
point +
|
|
150
|
+
" prevents further GETs and release",
|
|
151
|
+
(h) => prepareFreshObservation(h, { active: true }),
|
|
152
|
+
async (h, state) => {
|
|
153
|
+
const before = h.calls.length;
|
|
154
|
+
readerControls.reply = (grant, count) => (count === point ? null : grant);
|
|
155
|
+
await h.inAnotherAction(async (ctx) => {
|
|
156
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
157
|
+
actualActionCtx: ctx,
|
|
158
|
+
operationId: state.operationId,
|
|
159
|
+
parentOperationId: state.parentOperationId,
|
|
160
|
+
});
|
|
161
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
162
|
+
});
|
|
163
|
+
expect(h.calls.slice(before)).toHaveLength(point - 2);
|
|
164
|
+
expect(await h.journal.readProviderAcknowledgement()).not.toBeNull();
|
|
165
|
+
},
|
|
166
|
+
options,
|
|
167
|
+
);
|
|
168
|
+
for (const terminal of ["canceled", "released", "completed"] as const)
|
|
169
|
+
configureAdmissionCase(
|
|
170
|
+
"multi-item " +
|
|
171
|
+
terminal +
|
|
172
|
+
" preserves terminal facts and incomplete-inventory evidence",
|
|
173
|
+
prepareFreshObservation,
|
|
174
|
+
async (h, state) => {
|
|
175
|
+
const before = h.calls.length,
|
|
176
|
+
schedule = state.reads.schedule;
|
|
177
|
+
const original = state.reads.subscription.items.data[0];
|
|
178
|
+
state.reads.subscription.items.data.push({
|
|
179
|
+
...structuredClone(original),
|
|
180
|
+
id: "si_additional",
|
|
181
|
+
});
|
|
182
|
+
Object.assign(schedule, {
|
|
183
|
+
status: terminal,
|
|
184
|
+
current_phase: null,
|
|
185
|
+
subscription: terminal === "canceled" ? "sub_original" : null,
|
|
186
|
+
canceled_at:
|
|
187
|
+
terminal === "canceled" ? Math.floor(Date.now() / 1000) : null,
|
|
188
|
+
released_at:
|
|
189
|
+
terminal === "released" ? Math.floor(Date.now() / 1000) : null,
|
|
190
|
+
completed_at: terminal === "completed" ? 1773532800 : null,
|
|
191
|
+
released_subscription: terminal === "canceled" ? null : "sub_original",
|
|
192
|
+
});
|
|
193
|
+
if (terminal !== "canceled") state.reads.subscription.schedule = null;
|
|
194
|
+
await h.inAnotherAction(async (ctx) => {
|
|
195
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
196
|
+
actualActionCtx: ctx,
|
|
197
|
+
operationId: state.operationId,
|
|
198
|
+
parentOperationId: state.parentOperationId,
|
|
199
|
+
});
|
|
200
|
+
const result = await actor.invoke();
|
|
201
|
+
expect(result.status).toBe("unsupported_observation_profile");
|
|
202
|
+
expect(result.couponInventory).toBe("incomplete");
|
|
203
|
+
expect(result.reads?.coupons).toEqual([]);
|
|
204
|
+
expect(result.evidence?.lifecycle.providerStatus).toBe(terminal);
|
|
205
|
+
expect(result.evidence?.lifecycle.facts).not.toBeNull();
|
|
206
|
+
expect(result.evidence?.lifecycle.predicate).toBe(
|
|
207
|
+
terminal === "completed" ? "unknown" : "status_only",
|
|
208
|
+
);
|
|
209
|
+
expect(result.evidence?.currentMaterial.predicate).toBe("unknown");
|
|
210
|
+
});
|
|
211
|
+
expect(h.calls.slice(before)).toHaveLength(4);
|
|
212
|
+
},
|
|
213
|
+
options,
|
|
214
|
+
);
|
|
215
|
+
configureAdmissionCase(
|
|
216
|
+
"coupon inventory exceeding forty unique IDs stops after four base GETs without truncation",
|
|
217
|
+
prepareFreshObservation,
|
|
218
|
+
async (h, state) => {
|
|
219
|
+
const before = h.calls.length,
|
|
220
|
+
sub = state.reads.subscription,
|
|
221
|
+
item = sub.items.data[0];
|
|
222
|
+
const groups = [
|
|
223
|
+
[sub, "sub"],
|
|
224
|
+
[item, "item"],
|
|
225
|
+
] as const;
|
|
226
|
+
for (const [owner, level] of groups) {
|
|
227
|
+
const original = owner.discounts[0];
|
|
228
|
+
owner.discounts = Array.from({ length: 20 }, (_, index) => {
|
|
229
|
+
const discount = structuredClone(original);
|
|
230
|
+
discount.id = "di_" + level + index;
|
|
231
|
+
discount.source.coupon.id = "coupon-" + level + index;
|
|
232
|
+
return discount;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
await h.inAnotherAction(async (ctx) => {
|
|
236
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
237
|
+
actualActionCtx: ctx,
|
|
238
|
+
operationId: state.operationId,
|
|
239
|
+
parentOperationId: state.parentOperationId,
|
|
240
|
+
});
|
|
241
|
+
const result = await actor.invoke();
|
|
242
|
+
expect(result.status).toBe("unsupported_observation_profile");
|
|
243
|
+
expect(result.couponInventory).toBe("incomplete");
|
|
244
|
+
expect(result.reads?.subscription).toEqual(sub);
|
|
245
|
+
});
|
|
246
|
+
expect(h.calls.slice(before)).toHaveLength(4);
|
|
247
|
+
},
|
|
248
|
+
options,
|
|
249
|
+
);
|
|
250
|
+
let rejectRead = false;
|
|
251
|
+
for (const revoke of [false, true])
|
|
252
|
+
configureAdmissionCase(
|
|
253
|
+
"actual GET rejection retains C3 only after final authorization; revoked=" +
|
|
254
|
+
revoke,
|
|
255
|
+
async (h) => {
|
|
256
|
+
rejectRead = false;
|
|
257
|
+
return prepareFreshObservation(h);
|
|
258
|
+
},
|
|
259
|
+
async (h, state) => {
|
|
260
|
+
const before = h.calls.length;
|
|
261
|
+
rejectRead = true;
|
|
262
|
+
readerControls.reply = (grant, count) =>
|
|
263
|
+
revoke && count === 3 ? null : grant;
|
|
264
|
+
await h.inAnotherAction(async (ctx) => {
|
|
265
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
266
|
+
actualActionCtx: ctx,
|
|
267
|
+
operationId: state.operationId,
|
|
268
|
+
parentOperationId: state.parentOperationId,
|
|
269
|
+
});
|
|
270
|
+
if (revoke) await expect(actor.invoke()).rejects.toThrow();
|
|
271
|
+
else {
|
|
272
|
+
const result = await actor.invoke();
|
|
273
|
+
expect(result.status).toBe("observation_provider_rejected");
|
|
274
|
+
expect(result.failure?.category).toBe("provider_rejected");
|
|
275
|
+
expect(result.failure?.ordinal).toBe(1);
|
|
276
|
+
expect(result.history.attachmentReceipt).toEqual(
|
|
277
|
+
JSON.parse(state.full.parent.acknowledgement!.receiptJSON),
|
|
278
|
+
);
|
|
279
|
+
expect(result.evidence).toBeNull();
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
expect(readerControls.authorizations).toBe(3);
|
|
283
|
+
expect(h.calls.slice(before)).toHaveLength(1);
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
...options,
|
|
287
|
+
beforeFetch: async (_path, method) => {
|
|
288
|
+
if (rejectRead && method === "GET") {
|
|
289
|
+
rejectRead = false;
|
|
290
|
+
throw Error("CONTROLLED_ASYNC_READ_REJECTION");
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
);
|
|
295
|
+
configureAdmissionCase(
|
|
296
|
+
"a poisoned public then on the actual SDK promise is not invoked",
|
|
297
|
+
prepareFreshObservation,
|
|
298
|
+
async (h, state) => {
|
|
299
|
+
let traps = 0;
|
|
300
|
+
let restore = () => {};
|
|
301
|
+
admissionControls.onSelect = (client) => {
|
|
302
|
+
const sender: object = Reflect.get(client, "_requestSender");
|
|
303
|
+
const raw = Reflect.get(sender, "_rawRequest");
|
|
304
|
+
if (typeof raw !== "function") throw Error("TEST_SENDER_UNBOUND");
|
|
305
|
+
Reflect.set(sender, "_rawRequest", function (...args: unknown[]) {
|
|
306
|
+
const promise: object = Reflect.apply(raw, sender, args);
|
|
307
|
+
Object.defineProperty(promise, "then", {
|
|
308
|
+
configurable: true,
|
|
309
|
+
get() {
|
|
310
|
+
traps++;
|
|
311
|
+
throw Error("POISON_PUBLIC_THEN");
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
return promise;
|
|
315
|
+
});
|
|
316
|
+
restore = () => {
|
|
317
|
+
Reflect.set(sender, "_rawRequest", raw);
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
try {
|
|
321
|
+
await h.inAnotherAction(async (ctx) => {
|
|
322
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
323
|
+
actualActionCtx: ctx,
|
|
324
|
+
operationId: state.operationId,
|
|
325
|
+
parentOperationId: state.parentOperationId,
|
|
326
|
+
});
|
|
327
|
+
expect((await actor.invoke()).status).toBe("fresh_observation_data");
|
|
328
|
+
});
|
|
329
|
+
expect(traps).toBe(0);
|
|
330
|
+
} finally {
|
|
331
|
+
restore();
|
|
332
|
+
admissionControls.onSelect = null;
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
options,
|
|
336
|
+
);
|
|
337
|
+
for (const drift of ["key", "prototype", "own-method"] as const) {
|
|
338
|
+
let active = false,
|
|
339
|
+
alter = () => {};
|
|
340
|
+
configureAdmissionCase(
|
|
341
|
+
"client/config drift during an actual GET refuses output: " + drift,
|
|
342
|
+
async (h) => {
|
|
343
|
+
active = false;
|
|
344
|
+
return prepareFreshObservation(h);
|
|
345
|
+
},
|
|
346
|
+
async (h, state) => {
|
|
347
|
+
const before = h.calls.length;
|
|
348
|
+
const key = Object.getOwnPropertyDescriptor(h.sdk, "_apiKey")!;
|
|
349
|
+
const method = Object.getOwnPropertyDescriptor(
|
|
350
|
+
Stripe.prototype,
|
|
351
|
+
"rawRequest",
|
|
352
|
+
)!;
|
|
353
|
+
let client: object | null = null;
|
|
354
|
+
admissionControls.onSelect = (selected) => {
|
|
355
|
+
client = selected;
|
|
356
|
+
};
|
|
357
|
+
alter = () => {
|
|
358
|
+
if (drift === "key")
|
|
359
|
+
Object.defineProperty(h.sdk, "_apiKey", {
|
|
360
|
+
...key,
|
|
361
|
+
value: "sk_test_invalid_changed",
|
|
362
|
+
});
|
|
363
|
+
if (drift === "prototype")
|
|
364
|
+
Object.defineProperty(Stripe.prototype, "rawRequest", {
|
|
365
|
+
...method,
|
|
366
|
+
value() {
|
|
367
|
+
throw Error("POISON_METHOD");
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
if (drift === "own-method" && client)
|
|
371
|
+
Object.defineProperty(client, "rawRequest", {
|
|
372
|
+
configurable: true,
|
|
373
|
+
value() {
|
|
374
|
+
throw Error("POISON_OWN_METHOD");
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
active = true;
|
|
379
|
+
try {
|
|
380
|
+
await h.inAnotherAction(async (ctx) => {
|
|
381
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
382
|
+
actualActionCtx: ctx,
|
|
383
|
+
operationId: state.operationId,
|
|
384
|
+
parentOperationId: state.parentOperationId,
|
|
385
|
+
});
|
|
386
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
387
|
+
});
|
|
388
|
+
expect(h.calls.slice(before)).toHaveLength(1);
|
|
389
|
+
} finally {
|
|
390
|
+
active = false;
|
|
391
|
+
Object.defineProperty(h.sdk, "_apiKey", key);
|
|
392
|
+
Object.defineProperty(Stripe.prototype, "rawRequest", method);
|
|
393
|
+
if (client) Reflect.deleteProperty(client, "rawRequest");
|
|
394
|
+
admissionControls.onSelect = null;
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
...options,
|
|
399
|
+
beforeFetch: async (_path, method) => {
|
|
400
|
+
if (active && method === "GET") alter();
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
configureAdmissionCase(
|
|
406
|
+
"decoder failure is not a provider rejection; analysis failure has a finite unadmitted result",
|
|
407
|
+
prepareFreshObservation,
|
|
408
|
+
async (h, state) => {
|
|
409
|
+
const decoder = vi
|
|
410
|
+
.spyOn(replyCapture, "captureObservationReply")
|
|
411
|
+
.mockImplementationOnce(() => {
|
|
412
|
+
throw Error("CONTROLLED_DECODER_REFUSAL");
|
|
413
|
+
});
|
|
414
|
+
await h.inAnotherAction(async (ctx) => {
|
|
415
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
416
|
+
actualActionCtx: ctx,
|
|
417
|
+
operationId: state.operationId,
|
|
418
|
+
parentOperationId: state.parentOperationId,
|
|
419
|
+
});
|
|
420
|
+
await expect(actor.invoke()).rejects.toThrow(
|
|
421
|
+
"CONTROLLED_DECODER_REFUSAL",
|
|
422
|
+
);
|
|
423
|
+
});
|
|
424
|
+
decoder.mockRestore();
|
|
425
|
+
vi.spyOn(analyzer, "inspectRenewalEvidenceV1").mockRejectedValueOnce(
|
|
426
|
+
Error("CONTROLLED_ANALYSIS_REFUSAL"),
|
|
427
|
+
);
|
|
428
|
+
await h.inAnotherAction(async (ctx) => {
|
|
429
|
+
const actor = await captureFreshRenewalObservation(h.sdk, {
|
|
430
|
+
actualActionCtx: ctx,
|
|
431
|
+
operationId: state.operationId,
|
|
432
|
+
parentOperationId: state.parentOperationId,
|
|
433
|
+
});
|
|
434
|
+
const result = await actor.invoke();
|
|
435
|
+
expect(result.analysis).toBe("analysis_not_admitted");
|
|
436
|
+
expect(result.evidence).toBeNull();
|
|
437
|
+
expect(result.failure).toBeNull();
|
|
438
|
+
expect(Object.keys(result)).not.toContain("invocation");
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
options,
|
|
442
|
+
);
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import Stripe from "stripe";
|
|
2
|
+
import { types } from "node:util";
|
|
3
|
+
import {
|
|
4
|
+
COMPILED_FRESH_OBSERVATION_ENTRIES,
|
|
5
|
+
COMPILED_OBSERVATION_HISTORY_ENTRIES,
|
|
6
|
+
type FreshObservationProfile,
|
|
7
|
+
} from "../operations/sourceOperations.js";
|
|
8
|
+
import {
|
|
9
|
+
readMaintainedRootComponent,
|
|
10
|
+
captureInitialJournalSelection,
|
|
11
|
+
} from "../producer/classOwnedActionRoot.js";
|
|
12
|
+
import { readObservationInvocation } from "./invocation.js";
|
|
13
|
+
import { closed, freeze } from "../c10/ownData.js";
|
|
14
|
+
import {
|
|
15
|
+
baseReadRows,
|
|
16
|
+
couponReadRow,
|
|
17
|
+
observationCouponIds,
|
|
18
|
+
validateBaseRouting,
|
|
19
|
+
} from "./profile.js";
|
|
20
|
+
import { captureObservationReply, safeReadDiagnostics } from "./capture.js";
|
|
21
|
+
import type {
|
|
22
|
+
ObservationReadRow,
|
|
23
|
+
ObservationReads,
|
|
24
|
+
ReadFailure,
|
|
25
|
+
} from "./types.js";
|
|
26
|
+
|
|
27
|
+
export function freshStop(): never {
|
|
28
|
+
throw Error("FRESH_OBSERVATION_UNBOUND");
|
|
29
|
+
}
|
|
30
|
+
export function freshNeed(value: unknown): asserts value {
|
|
31
|
+
if (!value) freshStop();
|
|
32
|
+
}
|
|
33
|
+
const method = Object.getOwnPropertyDescriptor(
|
|
34
|
+
Stripe.prototype,
|
|
35
|
+
"rawRequest",
|
|
36
|
+
)?.value;
|
|
37
|
+
const nativeThen = Promise.prototype.then;
|
|
38
|
+
export function captureFreshObservationProfile(
|
|
39
|
+
root: object,
|
|
40
|
+
): FreshObservationProfile {
|
|
41
|
+
if (COMPILED_FRESH_OBSERVATION_ENTRIES.length === 0) freshStop();
|
|
42
|
+
const component = readMaintainedRootComponent(root);
|
|
43
|
+
const candidates = COMPILED_FRESH_OBSERVATION_ENTRIES.filter((entry) => {
|
|
44
|
+
freshNeed(!types.isProxy(entry));
|
|
45
|
+
closed(entry, ["historyEntry", "readProfile", "coversObservation"]);
|
|
46
|
+
return entry.historyEntry.component === component;
|
|
47
|
+
});
|
|
48
|
+
freshNeed(candidates.length === 1);
|
|
49
|
+
const profile = candidates[0];
|
|
50
|
+
freshNeed(
|
|
51
|
+
Object.isFrozen(profile) &&
|
|
52
|
+
profile.readProfile === "endive-schedule-first-44-v1" &&
|
|
53
|
+
COMPILED_OBSERVATION_HISTORY_ENTRIES.includes(profile.historyEntry),
|
|
54
|
+
);
|
|
55
|
+
freshNeed(
|
|
56
|
+
typeof profile.coversObservation === "function" &&
|
|
57
|
+
!types.isProxy(profile.coversObservation),
|
|
58
|
+
);
|
|
59
|
+
return profile;
|
|
60
|
+
}
|
|
61
|
+
type Settlement = Readonly<{
|
|
62
|
+
promise: object;
|
|
63
|
+
kind: "fulfilled" | "rejected";
|
|
64
|
+
value: unknown;
|
|
65
|
+
}>;
|
|
66
|
+
/** Actual fresh class selection and GET-only fixed rows. No caller transport or old lineage. */
|
|
67
|
+
export function captureFreshGetTransport(
|
|
68
|
+
token: object,
|
|
69
|
+
profile: FreshObservationProfile,
|
|
70
|
+
) {
|
|
71
|
+
freshNeed(arguments.length === 2);
|
|
72
|
+
const state = readObservationInvocation(token),
|
|
73
|
+
captured = state.readCaptured();
|
|
74
|
+
freshNeed(state.historyEntry === profile.historyEntry);
|
|
75
|
+
const covers = profile.coversObservation;
|
|
76
|
+
function profileGuard() {
|
|
77
|
+
readObservationInvocation(token);
|
|
78
|
+
freshNeed(
|
|
79
|
+
COMPILED_FRESH_OBSERVATION_ENTRIES.includes(profile) &&
|
|
80
|
+
COMPILED_FRESH_OBSERVATION_ENTRIES.filter(
|
|
81
|
+
(e) => e.historyEntry === state.historyEntry,
|
|
82
|
+
).length === 1,
|
|
83
|
+
);
|
|
84
|
+
freshNeed(
|
|
85
|
+
profile.historyEntry === state.historyEntry &&
|
|
86
|
+
profile.coversObservation === covers &&
|
|
87
|
+
profile.readProfile === "endive-schedule-first-44-v1",
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
profileGuard();
|
|
91
|
+
freshNeed(Reflect.apply(covers, profile, [captured.history.record]) === true);
|
|
92
|
+
profileGuard();
|
|
93
|
+
const selection = captureInitialJournalSelection(
|
|
94
|
+
state.binding,
|
|
95
|
+
"2026-09-30.endive",
|
|
96
|
+
);
|
|
97
|
+
const client = selection.select();
|
|
98
|
+
freshNeed(
|
|
99
|
+
client &&
|
|
100
|
+
typeof client === "object" &&
|
|
101
|
+
!types.isProxy(client) &&
|
|
102
|
+
Object.getPrototypeOf(client) === Stripe.prototype &&
|
|
103
|
+
!Object.prototype.hasOwnProperty.call(client, "rawRequest") &&
|
|
104
|
+
typeof method === "function",
|
|
105
|
+
);
|
|
106
|
+
function guard() {
|
|
107
|
+
profileGuard();
|
|
108
|
+
selection.check();
|
|
109
|
+
freshNeed(
|
|
110
|
+
Object.getPrototypeOf(client) === Stripe.prototype &&
|
|
111
|
+
!Object.prototype.hasOwnProperty.call(client, "rawRequest") &&
|
|
112
|
+
Object.getOwnPropertyDescriptor(Stripe.prototype, "rawRequest")
|
|
113
|
+
?.value === method,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
guard();
|
|
117
|
+
const base = baseReadRows(captured.history.record),
|
|
118
|
+
bodies: unknown[] = [];
|
|
119
|
+
let ordinal = 0,
|
|
120
|
+
busy = false,
|
|
121
|
+
ended = false;
|
|
122
|
+
function expected() {
|
|
123
|
+
if (ordinal < 4) return base[ordinal];
|
|
124
|
+
const reads: ObservationReads = {
|
|
125
|
+
schedule: bodies[0],
|
|
126
|
+
subscription: bodies[1],
|
|
127
|
+
targetPrice: bodies[2],
|
|
128
|
+
billingCustomer: bodies[3],
|
|
129
|
+
coupons: [],
|
|
130
|
+
};
|
|
131
|
+
validateBaseRouting(captured.history.record, reads);
|
|
132
|
+
const ids = observationCouponIds(
|
|
133
|
+
captured.history.record,
|
|
134
|
+
reads.subscription,
|
|
135
|
+
);
|
|
136
|
+
freshNeed(ordinal - 4 < ids.length);
|
|
137
|
+
return couponReadRow(ids[ordinal - 4], ordinal + 1);
|
|
138
|
+
}
|
|
139
|
+
return Object.freeze({
|
|
140
|
+
guard,
|
|
141
|
+
async read(
|
|
142
|
+
raw: ObservationReadRow,
|
|
143
|
+
): Promise<
|
|
144
|
+
| Readonly<{ kind: "fulfilled"; body: unknown }>
|
|
145
|
+
| Readonly<{ kind: "provider_rejected"; failure: ReadFailure }>
|
|
146
|
+
> {
|
|
147
|
+
if (busy || ended) {
|
|
148
|
+
ended = true;
|
|
149
|
+
state.close();
|
|
150
|
+
freshStop();
|
|
151
|
+
}
|
|
152
|
+
busy = true;
|
|
153
|
+
try {
|
|
154
|
+
guard();
|
|
155
|
+
freshNeed(ordinal < 44 && !types.isProxy(raw));
|
|
156
|
+
const row = expected(),
|
|
157
|
+
actual = closed(raw, [
|
|
158
|
+
"resource",
|
|
159
|
+
"id",
|
|
160
|
+
"ordinal",
|
|
161
|
+
"method",
|
|
162
|
+
"path",
|
|
163
|
+
"body",
|
|
164
|
+
"options",
|
|
165
|
+
]);
|
|
166
|
+
freshNeed(!types.isProxy(actual.options));
|
|
167
|
+
const options = closed(actual.options, [
|
|
168
|
+
"apiVersion",
|
|
169
|
+
"maxNetworkRetries",
|
|
170
|
+
]);
|
|
171
|
+
freshNeed(
|
|
172
|
+
actual.resource === row.resource &&
|
|
173
|
+
actual.id === row.id &&
|
|
174
|
+
actual.ordinal === row.ordinal &&
|
|
175
|
+
actual.method === "GET" &&
|
|
176
|
+
actual.path === row.path &&
|
|
177
|
+
actual.body === undefined &&
|
|
178
|
+
options.apiVersion === row.options.apiVersion &&
|
|
179
|
+
options.maxNetworkRetries === 0,
|
|
180
|
+
);
|
|
181
|
+
await state.authorizeUnchanged();
|
|
182
|
+
guard();
|
|
183
|
+
ordinal++;
|
|
184
|
+
let promise: object | null = null;
|
|
185
|
+
const cell: { capsule: Settlement | null } = { capsule: null };
|
|
186
|
+
const result: unknown = await state.owned(() => {
|
|
187
|
+
const actualPromise: unknown = Reflect.apply(method, client, [
|
|
188
|
+
"GET",
|
|
189
|
+
row.path,
|
|
190
|
+
undefined,
|
|
191
|
+
row.options,
|
|
192
|
+
]);
|
|
193
|
+
freshNeed(
|
|
194
|
+
actualPromise &&
|
|
195
|
+
typeof actualPromise === "object" &&
|
|
196
|
+
!types.isProxy(actualPromise) &&
|
|
197
|
+
types.isPromise(actualPromise),
|
|
198
|
+
);
|
|
199
|
+
promise = actualPromise;
|
|
200
|
+
return Reflect.apply(nativeThen, actualPromise, [
|
|
201
|
+
(value: unknown) =>
|
|
202
|
+
(cell.capsule = Object.freeze({
|
|
203
|
+
promise: actualPromise,
|
|
204
|
+
kind: "fulfilled" as const,
|
|
205
|
+
value,
|
|
206
|
+
})),
|
|
207
|
+
(value: unknown) =>
|
|
208
|
+
(cell.capsule = Object.freeze({
|
|
209
|
+
promise: actualPromise,
|
|
210
|
+
kind: "rejected" as const,
|
|
211
|
+
value,
|
|
212
|
+
})),
|
|
213
|
+
]) as Promise<Settlement>;
|
|
214
|
+
}, guard);
|
|
215
|
+
guard();
|
|
216
|
+
const capsule = cell.capsule;
|
|
217
|
+
freshNeed(capsule && result === capsule && capsule.promise === promise);
|
|
218
|
+
const settled: Settlement = capsule;
|
|
219
|
+
if (settled.kind === "rejected") {
|
|
220
|
+
ended = true;
|
|
221
|
+
return Object.freeze({
|
|
222
|
+
kind: "provider_rejected" as const,
|
|
223
|
+
failure: freeze({
|
|
224
|
+
category: "provider_rejected" as const,
|
|
225
|
+
phase: "read" as const,
|
|
226
|
+
resource: row.resource,
|
|
227
|
+
ordinal: row.ordinal,
|
|
228
|
+
request: {
|
|
229
|
+
method: "GET" as const,
|
|
230
|
+
path: row.path,
|
|
231
|
+
apiVersion: row.options.apiVersion,
|
|
232
|
+
},
|
|
233
|
+
diagnostics: safeReadDiagnostics(settled.value),
|
|
234
|
+
outcome: "unknown" as const,
|
|
235
|
+
operationalAuthority: false as const,
|
|
236
|
+
}),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const body = captureObservationReply(settled.value);
|
|
240
|
+
guard();
|
|
241
|
+
bodies.push(body);
|
|
242
|
+
return Object.freeze({ kind: "fulfilled" as const, body });
|
|
243
|
+
} catch (error) {
|
|
244
|
+
ended = true;
|
|
245
|
+
state.close();
|
|
246
|
+
throw error;
|
|
247
|
+
} finally {
|
|
248
|
+
busy = false;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|