@fantastic.dev/better-stripe 0.111.0 → 0.113.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 +564 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +103 -21
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +18 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +54 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js +6 -1
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts +38 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js +172 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts +135 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.js +143 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts +85 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js +121 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts +44 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js +4 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts +21 -21
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +3 -3
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/_generated/api.d.ts +24 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +94 -10
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/renewalWitnesses/mutations.d.ts +45 -0
- package/dist/component/renewalWitnesses/mutations.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/mutations.js +14 -0
- package/dist/component/renewalWitnesses/mutations.js.map +1 -0
- package/dist/component/renewalWitnesses/queries.d.ts +39 -0
- package/dist/component/renewalWitnesses/queries.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/queries.js +11 -0
- package/dist/component/renewalWitnesses/queries.js.map +1 -0
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-example-authorization.md +74 -0
- package/docs/renewal-witness-protocol.md +61 -10
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +142 -19
- package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +90 -1
- package/src/client/billing/renewalAttach/internal/observation/invocation.ts +2 -0
- package/src/client/billing/renewalAttach/internal/observation/readerAuthorization.ts +6 -1
- package/src/client/billing/renewalAttach/internal/observation/witnessAcquisition.integration.test.ts +348 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessActor.integration.test.ts +204 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessAuthorization.ts +239 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessCapabilities.integration.test.ts +231 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessData.ts +189 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessHistorical.integration.test.ts +98 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessImmutable.integration.test.ts +78 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessInvoice.integration.test.ts +85 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessLifecycle.integration.test.ts +264 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessOperation.ts +205 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessProfile.integration.test.ts +93 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessRPCControls.integration.test.ts +256 -0
- package/src/client/billing/renewalAttach/internal/operations/witnessProfiles.ts +58 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/invoiceObservation.ts +3 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +8 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +28 -11
- package/src/client/billing/renewalAttach/internal/test-fixtures/witnessHistory.ts +70 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/witnessObservation.ts +353 -0
- package/src/component/_generated/api.ts +24 -0
- package/src/component/_generated/component.ts +98 -10
- package/src/component/renewalWitnesses/mutations.ts +17 -0
- package/src/component/renewalWitnesses/queries.ts +11 -0
- package/src/component/renewalWitnesses/routes.test.ts +154 -0
package/src/client/billing/renewalAttach/internal/observation/witnessAcquisition.integration.test.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import {
|
|
2
|
+
witnessControls,
|
|
3
|
+
prepareWitnessObservation,
|
|
4
|
+
readStoredWitness,
|
|
5
|
+
witnessFixtureOptions,
|
|
6
|
+
} from "../test-fixtures/witnessObservation.js";
|
|
7
|
+
import {
|
|
8
|
+
configureAdmissionCase,
|
|
9
|
+
admissionControls,
|
|
10
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
11
|
+
import {
|
|
12
|
+
captureObservationInvocation,
|
|
13
|
+
readObservationInvocation,
|
|
14
|
+
closeObservationInvocation,
|
|
15
|
+
} from "./invocation.js";
|
|
16
|
+
import * as transportAPI from "./freshTransport.js";
|
|
17
|
+
import { createWitnessOperation } from "./witnessOperation.js";
|
|
18
|
+
import {
|
|
19
|
+
baseReadRows,
|
|
20
|
+
observationCouponIds,
|
|
21
|
+
couponReadRow,
|
|
22
|
+
} from "./profile.js";
|
|
23
|
+
import { expect } from "vitest";
|
|
24
|
+
import assert from "node:assert/strict";
|
|
25
|
+
import type { FreshObservationProfile } from "../operations/sourceOperations.js";
|
|
26
|
+
|
|
27
|
+
configureAdmissionCase(
|
|
28
|
+
"supplied material and a live selected SDK cannot substitute for actual fresh GET acquisition",
|
|
29
|
+
prepareWitnessObservation,
|
|
30
|
+
async (h, prepared) => {
|
|
31
|
+
const before = h.calls.length;
|
|
32
|
+
await h.inAnotherAction(async (ctx) => {
|
|
33
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
34
|
+
actualActionCtx: ctx,
|
|
35
|
+
operationId: prepared.operationId,
|
|
36
|
+
parentOperationId: prepared.parentOperationId,
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
await readObservationInvocation(token).captureHistory();
|
|
40
|
+
const port = transportAPI.captureFreshGetTransport(
|
|
41
|
+
token,
|
|
42
|
+
prepared.profile,
|
|
43
|
+
);
|
|
44
|
+
const supplied = {
|
|
45
|
+
...prepared.reads,
|
|
46
|
+
coupons: h.source.originalBundle.couponReads.map(
|
|
47
|
+
(row) => row.wireCoupon,
|
|
48
|
+
),
|
|
49
|
+
};
|
|
50
|
+
await expect(
|
|
51
|
+
(async () => {
|
|
52
|
+
const operation = Reflect.apply(createWitnessOperation, undefined, [
|
|
53
|
+
token,
|
|
54
|
+
prepared.captureProfile,
|
|
55
|
+
"retain",
|
|
56
|
+
prepared.scope.identity,
|
|
57
|
+
port.guard,
|
|
58
|
+
]);
|
|
59
|
+
return Reflect.apply(operation.retain, operation, [supplied, null]);
|
|
60
|
+
})(),
|
|
61
|
+
).rejects.toThrow();
|
|
62
|
+
const operation = createWitnessOperation(
|
|
63
|
+
token,
|
|
64
|
+
prepared.captureProfile,
|
|
65
|
+
"retain",
|
|
66
|
+
prepared.scope.identity,
|
|
67
|
+
);
|
|
68
|
+
await expect(operation.retain()).rejects.toThrow(
|
|
69
|
+
"FRESH_OBSERVATION_UNBOUND",
|
|
70
|
+
);
|
|
71
|
+
} finally {
|
|
72
|
+
closeObservationInvocation(token);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
expect(h.calls).toHaveLength(before);
|
|
76
|
+
expect(witnessControls.retainQueries).toBe(0);
|
|
77
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
78
|
+
},
|
|
79
|
+
witnessFixtureOptions,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
configureAdmissionCase(
|
|
83
|
+
"one invocation cannot mint a second transport or consume acquisition before its actual reads",
|
|
84
|
+
prepareWitnessObservation,
|
|
85
|
+
async (h, prepared) => {
|
|
86
|
+
const before = h.calls.length,
|
|
87
|
+
selectors = admissionControls.selectors;
|
|
88
|
+
await h.inAnotherAction(async (ctx) => {
|
|
89
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
90
|
+
actualActionCtx: ctx,
|
|
91
|
+
operationId: prepared.operationId,
|
|
92
|
+
parentOperationId: prepared.parentOperationId,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
await readObservationInvocation(token).captureHistory();
|
|
96
|
+
transportAPI.captureFreshGetTransport(token, prepared.profile);
|
|
97
|
+
expect(() =>
|
|
98
|
+
transportAPI.captureFreshGetTransport(token, prepared.profile),
|
|
99
|
+
).toThrow();
|
|
100
|
+
const consume = Reflect.get(
|
|
101
|
+
transportAPI,
|
|
102
|
+
"consumeFreshObservationAcquisition",
|
|
103
|
+
);
|
|
104
|
+
expect(typeof consume).toBe("function");
|
|
105
|
+
expect(() =>
|
|
106
|
+
Reflect.apply(consume, transportAPI, [token, prepared.profile, null]),
|
|
107
|
+
).toThrow();
|
|
108
|
+
} finally {
|
|
109
|
+
closeObservationInvocation(token);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
expect(admissionControls.selectors).toBe(selectors + 1);
|
|
113
|
+
expect(h.calls).toHaveLength(before);
|
|
114
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
115
|
+
},
|
|
116
|
+
witnessFixtureOptions,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
configureAdmissionCase(
|
|
120
|
+
"only completed original transport bodies create a once-consumed acquisition receipt",
|
|
121
|
+
prepareWitnessObservation,
|
|
122
|
+
async (h, prepared) => {
|
|
123
|
+
const before = h.calls.length;
|
|
124
|
+
await h.inAnotherAction(async (ctx) => {
|
|
125
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
126
|
+
actualActionCtx: ctx,
|
|
127
|
+
operationId: prepared.operationId,
|
|
128
|
+
parentOperationId: prepared.parentOperationId,
|
|
129
|
+
});
|
|
130
|
+
try {
|
|
131
|
+
const captured =
|
|
132
|
+
await readObservationInvocation(token).captureHistory();
|
|
133
|
+
const port = transportAPI.captureFreshGetTransport(
|
|
134
|
+
token,
|
|
135
|
+
prepared.profile,
|
|
136
|
+
);
|
|
137
|
+
const bodies = [];
|
|
138
|
+
for (const row of baseReadRows(captured.history.record)) {
|
|
139
|
+
const result = await port.read(row);
|
|
140
|
+
assert(result.kind === "fulfilled");
|
|
141
|
+
bodies.push(result.body);
|
|
142
|
+
}
|
|
143
|
+
const consume = Reflect.get(
|
|
144
|
+
transportAPI,
|
|
145
|
+
"consumeFreshObservationAcquisition",
|
|
146
|
+
);
|
|
147
|
+
expect(typeof consume).toBe("function");
|
|
148
|
+
expect(() =>
|
|
149
|
+
Reflect.apply(consume, transportAPI, [token, prepared.profile, null]),
|
|
150
|
+
).toThrow();
|
|
151
|
+
const coupons = [];
|
|
152
|
+
for (const id of observationCouponIds(
|
|
153
|
+
captured.history.record,
|
|
154
|
+
bodies[1],
|
|
155
|
+
)) {
|
|
156
|
+
const result = await port.read(couponReadRow(id, 5 + coupons.length));
|
|
157
|
+
assert(result.kind === "fulfilled");
|
|
158
|
+
coupons.push(result.body);
|
|
159
|
+
}
|
|
160
|
+
const receipt = Reflect.apply(consume, transportAPI, [
|
|
161
|
+
token,
|
|
162
|
+
prepared.profile,
|
|
163
|
+
null,
|
|
164
|
+
]);
|
|
165
|
+
expect(receipt.reads).toEqual({
|
|
166
|
+
schedule: bodies[0],
|
|
167
|
+
subscription: bodies[1],
|
|
168
|
+
targetPrice: bodies[2],
|
|
169
|
+
billingCustomer: bodies[3],
|
|
170
|
+
coupons,
|
|
171
|
+
});
|
|
172
|
+
expect(receipt.invoiceContext).toBeNull();
|
|
173
|
+
expect(() =>
|
|
174
|
+
Reflect.apply(consume, transportAPI, [token, prepared.profile, null]),
|
|
175
|
+
).toThrow();
|
|
176
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
177
|
+
} finally {
|
|
178
|
+
closeObservationInvocation(token);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
182
|
+
Array(6).fill("GET"),
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
witnessFixtureOptions,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
configureAdmissionCase(
|
|
189
|
+
"an invoice acquisition receipt requires the actual complete fenced invoice plan",
|
|
190
|
+
(h) => prepareWitnessObservation(h, false, true),
|
|
191
|
+
async (h, prepared) => {
|
|
192
|
+
const before = h.calls.length;
|
|
193
|
+
await h.inAnotherAction(async (ctx) => {
|
|
194
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
195
|
+
actualActionCtx: ctx,
|
|
196
|
+
operationId: prepared.operationId,
|
|
197
|
+
parentOperationId: prepared.parentOperationId,
|
|
198
|
+
});
|
|
199
|
+
try {
|
|
200
|
+
const captured =
|
|
201
|
+
await readObservationInvocation(token).captureHistory();
|
|
202
|
+
assert(prepared.captureProfile.invoiceProfile);
|
|
203
|
+
const port = transportAPI.captureFreshGetTransport(
|
|
204
|
+
token,
|
|
205
|
+
prepared.profile,
|
|
206
|
+
prepared.captureProfile.invoiceProfile,
|
|
207
|
+
);
|
|
208
|
+
const bodies = [];
|
|
209
|
+
for (const row of baseReadRows(captured.history.record)) {
|
|
210
|
+
const result = await port.read(row);
|
|
211
|
+
assert(result.kind === "fulfilled");
|
|
212
|
+
bodies.push(result.body);
|
|
213
|
+
}
|
|
214
|
+
let ordinal = 5;
|
|
215
|
+
for (const id of observationCouponIds(
|
|
216
|
+
captured.history.record,
|
|
217
|
+
bodies[1],
|
|
218
|
+
)) {
|
|
219
|
+
const result = await port.read(couponReadRow(id, ordinal++));
|
|
220
|
+
assert(result.kind === "fulfilled");
|
|
221
|
+
}
|
|
222
|
+
expect(() =>
|
|
223
|
+
transportAPI.consumeFreshObservationAcquisition(
|
|
224
|
+
token,
|
|
225
|
+
prepared.profile,
|
|
226
|
+
prepared.captureProfile.invoiceProfile,
|
|
227
|
+
),
|
|
228
|
+
).toThrow();
|
|
229
|
+
const result = await port.acquireInvoices();
|
|
230
|
+
expect(result.status).toBe("complete");
|
|
231
|
+
const receipt = transportAPI.consumeFreshObservationAcquisition(
|
|
232
|
+
token,
|
|
233
|
+
prepared.profile,
|
|
234
|
+
prepared.captureProfile.invoiceProfile,
|
|
235
|
+
);
|
|
236
|
+
expect(receipt.invoiceContext).toEqual(result.context);
|
|
237
|
+
expect(() =>
|
|
238
|
+
transportAPI.consumeFreshObservationAcquisition(
|
|
239
|
+
token,
|
|
240
|
+
prepared.profile,
|
|
241
|
+
prepared.captureProfile.invoiceProfile,
|
|
242
|
+
),
|
|
243
|
+
).toThrow();
|
|
244
|
+
} finally {
|
|
245
|
+
closeObservationInvocation(token);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
249
|
+
Array(11).fill("GET"),
|
|
250
|
+
);
|
|
251
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
252
|
+
},
|
|
253
|
+
witnessFixtureOptions,
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
configureAdmissionCase(
|
|
257
|
+
"reentrant Source qualification cannot mint a second transport before registration",
|
|
258
|
+
prepareWitnessObservation,
|
|
259
|
+
async (h, prepared) => {
|
|
260
|
+
const selectors = admissionControls.selectors,
|
|
261
|
+
before = h.calls.length;
|
|
262
|
+
await h.inAnotherAction(async (ctx) => {
|
|
263
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
264
|
+
actualActionCtx: ctx,
|
|
265
|
+
operationId: prepared.operationId,
|
|
266
|
+
parentOperationId: prepared.parentOperationId,
|
|
267
|
+
});
|
|
268
|
+
let entered = false,
|
|
269
|
+
nested: unknown = null,
|
|
270
|
+
nestedError: unknown = null;
|
|
271
|
+
const profile: FreshObservationProfile = Object.freeze({
|
|
272
|
+
...prepared.profile,
|
|
273
|
+
coversObservation() {
|
|
274
|
+
if (!entered) {
|
|
275
|
+
entered = true;
|
|
276
|
+
try {
|
|
277
|
+
nested = transportAPI.captureFreshGetTransport(token, profile);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
nestedError = error;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return true;
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
admissionControls.observation.splice(
|
|
286
|
+
0,
|
|
287
|
+
admissionControls.observation.length,
|
|
288
|
+
profile,
|
|
289
|
+
);
|
|
290
|
+
try {
|
|
291
|
+
await readObservationInvocation(token).captureHistory();
|
|
292
|
+
transportAPI.captureFreshGetTransport(token, profile);
|
|
293
|
+
expect(nested).toBeNull();
|
|
294
|
+
expect(nestedError).toEqual(Error("FRESH_OBSERVATION_UNBOUND"));
|
|
295
|
+
} finally {
|
|
296
|
+
closeObservationInvocation(token);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
expect(admissionControls.selectors).toBe(selectors + 1);
|
|
300
|
+
expect(h.calls).toHaveLength(before);
|
|
301
|
+
},
|
|
302
|
+
witnessFixtureOptions,
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
configureAdmissionCase(
|
|
306
|
+
"failed transport qualification cannot reset the same invocation's acquisition attempt",
|
|
307
|
+
prepareWitnessObservation,
|
|
308
|
+
async (h, prepared) => {
|
|
309
|
+
const selectors = admissionControls.selectors;
|
|
310
|
+
await h.inAnotherAction(async (ctx) => {
|
|
311
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
312
|
+
actualActionCtx: ctx,
|
|
313
|
+
operationId: prepared.operationId,
|
|
314
|
+
parentOperationId: prepared.parentOperationId,
|
|
315
|
+
});
|
|
316
|
+
let fail = true,
|
|
317
|
+
qualifications = 0;
|
|
318
|
+
const profile: FreshObservationProfile = Object.freeze({
|
|
319
|
+
...prepared.profile,
|
|
320
|
+
coversObservation() {
|
|
321
|
+
qualifications++;
|
|
322
|
+
if (fail) throw Error("CONTROLLED_SOURCE_QUALIFICATION_FAILURE");
|
|
323
|
+
return true;
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
admissionControls.observation.splice(
|
|
327
|
+
0,
|
|
328
|
+
admissionControls.observation.length,
|
|
329
|
+
profile,
|
|
330
|
+
);
|
|
331
|
+
try {
|
|
332
|
+
await readObservationInvocation(token).captureHistory();
|
|
333
|
+
expect(() =>
|
|
334
|
+
transportAPI.captureFreshGetTransport(token, profile),
|
|
335
|
+
).toThrow("CONTROLLED_SOURCE_QUALIFICATION_FAILURE");
|
|
336
|
+
fail = false;
|
|
337
|
+
expect(() =>
|
|
338
|
+
transportAPI.captureFreshGetTransport(token, profile),
|
|
339
|
+
).toThrow("FRESH_OBSERVATION_UNBOUND");
|
|
340
|
+
expect(qualifications).toBe(1);
|
|
341
|
+
} finally {
|
|
342
|
+
closeObservationInvocation(token);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
346
|
+
},
|
|
347
|
+
witnessFixtureOptions,
|
|
348
|
+
);
|
package/src/client/billing/renewalAttach/internal/observation/witnessActor.integration.test.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
witnessControls,
|
|
4
|
+
prepareWitnessObservation,
|
|
5
|
+
authorizeWitnessRetention,
|
|
6
|
+
authorizeWitnessRead,
|
|
7
|
+
authorizeWitnessObservation,
|
|
8
|
+
} from "../test-fixtures/witnessObservation.js";
|
|
9
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
10
|
+
import * as actors from "./freshActor.js";
|
|
11
|
+
import { components } from "../../../../../../example/convex/_generated/api.js";
|
|
12
|
+
import { configureAdmissionCase } from "../test-fixtures/producerConfigureAdmission.js";
|
|
13
|
+
import { observerIdentity } from "../test-fixtures/observationReader.js";
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
witnessControls.captures.splice(0);
|
|
17
|
+
witnessControls.readers.splice(0);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => vi.restoreAllMocks());
|
|
21
|
+
|
|
22
|
+
it.each([
|
|
23
|
+
"captureFreshWitnessRenewalObservation",
|
|
24
|
+
"captureHistoricalWitnessRenewalObservation",
|
|
25
|
+
])(
|
|
26
|
+
"EMPTY witness profile refuses %s before reflection or clocks",
|
|
27
|
+
async (name) => {
|
|
28
|
+
let traps = 0;
|
|
29
|
+
const poison = new Proxy(
|
|
30
|
+
{},
|
|
31
|
+
{
|
|
32
|
+
get() {
|
|
33
|
+
traps++;
|
|
34
|
+
throw Error("UNEXPECTED_INPUT_REFLECTION");
|
|
35
|
+
},
|
|
36
|
+
ownKeys() {
|
|
37
|
+
traps++;
|
|
38
|
+
throw Error("UNEXPECTED_INPUT_REFLECTION");
|
|
39
|
+
},
|
|
40
|
+
getPrototypeOf() {
|
|
41
|
+
traps++;
|
|
42
|
+
throw Error("UNEXPECTED_ROOT_REFLECTION");
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
const wall = vi.spyOn(Date, "now"),
|
|
47
|
+
ns = vi.spyOn(process.hrtime, "bigint");
|
|
48
|
+
const capture = Reflect.get(actors, name);
|
|
49
|
+
expect(typeof capture).toBe("function");
|
|
50
|
+
await expect(
|
|
51
|
+
Reflect.apply(capture, actors, [poison, poison]),
|
|
52
|
+
).rejects.toThrow("RENEWAL_WITNESS_UNBOUND");
|
|
53
|
+
expect(traps).toBe(0);
|
|
54
|
+
expect(wall).not.toHaveBeenCalled();
|
|
55
|
+
expect(ns).not.toHaveBeenCalled();
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
for (const retained of [false, true])
|
|
60
|
+
configureAdmissionCase(
|
|
61
|
+
"retains actual fresh native reads and later acquires historical material with captured C9 " +
|
|
62
|
+
retained,
|
|
63
|
+
(h) => prepareWitnessObservation(h, retained),
|
|
64
|
+
async (h, state) => {
|
|
65
|
+
let acknowledgement: Record<string, unknown> | null = null;
|
|
66
|
+
const capture = Reflect.get(
|
|
67
|
+
actors,
|
|
68
|
+
"captureFreshWitnessRenewalObservation",
|
|
69
|
+
);
|
|
70
|
+
const read = Reflect.get(
|
|
71
|
+
actors,
|
|
72
|
+
"captureHistoricalWitnessRenewalObservation",
|
|
73
|
+
);
|
|
74
|
+
expect(typeof capture).toBe("function");
|
|
75
|
+
expect(typeof read).toBe("function");
|
|
76
|
+
const before = h.calls.length;
|
|
77
|
+
let originalPayloadJSON = "";
|
|
78
|
+
await h.inAnotherAction(async (ctx) => {
|
|
79
|
+
const actor = await Reflect.apply(capture, actors, [
|
|
80
|
+
h.sdk,
|
|
81
|
+
{
|
|
82
|
+
actualActionCtx: ctx,
|
|
83
|
+
parentOperationId: state.parentOperationId,
|
|
84
|
+
operationId: state.operationId,
|
|
85
|
+
witnessId: state.scope.identity.witnessId,
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
const output = await actor.invoke();
|
|
89
|
+
assert(output.evidence);
|
|
90
|
+
expect(output.evidence.currentMaterial.predicate).toBe(
|
|
91
|
+
"current_target_material_match",
|
|
92
|
+
);
|
|
93
|
+
assert(
|
|
94
|
+
"witnessRetention" in output &&
|
|
95
|
+
output.witnessRetention?.status === "retained",
|
|
96
|
+
);
|
|
97
|
+
expect(output.witnessRetention.status).toBe("retained");
|
|
98
|
+
expect(output.witnessRetention.descriptor.identity).toEqual(
|
|
99
|
+
state.scope.identity,
|
|
100
|
+
);
|
|
101
|
+
expect(output.witnessRetention.descriptor.nativePeriod).toEqual(
|
|
102
|
+
state.scope.nativePeriod,
|
|
103
|
+
);
|
|
104
|
+
expect(
|
|
105
|
+
output.witnessRetention.descriptor.publicDeliveryEstablished,
|
|
106
|
+
).toBe(false);
|
|
107
|
+
acknowledgement = output.witnessRetention;
|
|
108
|
+
const stored = await ctx.runQuery(
|
|
109
|
+
components.betterStripe.renewalWitnesses.queries
|
|
110
|
+
.readAuthorizedWitness,
|
|
111
|
+
{ identity: state.scope.identity },
|
|
112
|
+
);
|
|
113
|
+
assert(stored);
|
|
114
|
+
originalPayloadJSON = stored.payloadJSON;
|
|
115
|
+
const payload = JSON.parse(stored.payloadJSON);
|
|
116
|
+
const expectedStage = (
|
|
117
|
+
stage: typeof state.full.parent,
|
|
118
|
+
parent: boolean,
|
|
119
|
+
) => {
|
|
120
|
+
const { recordJSON: _recordJSON, ...reservation } =
|
|
121
|
+
stage.attempt.reservation;
|
|
122
|
+
void _recordJSON;
|
|
123
|
+
return {
|
|
124
|
+
record: JSON.parse(stage.operation.recordJSON),
|
|
125
|
+
reservation,
|
|
126
|
+
acknowledgement:
|
|
127
|
+
stage.acknowledgement === null
|
|
128
|
+
? null
|
|
129
|
+
: {
|
|
130
|
+
retention: stage.acknowledgement.retention,
|
|
131
|
+
receipt: JSON.parse(stage.acknowledgement.receiptJSON),
|
|
132
|
+
},
|
|
133
|
+
...(parent
|
|
134
|
+
? { initialBasis: Reflect.get(stage.operation, "initialBasis") }
|
|
135
|
+
: {}),
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
expect(payload.source).toEqual({
|
|
139
|
+
parent: expectedStage(state.full.parent, true),
|
|
140
|
+
configure: expectedStage(state.full.configure, false),
|
|
141
|
+
});
|
|
142
|
+
expect(payload.reads).toEqual({
|
|
143
|
+
...state.reads,
|
|
144
|
+
coupons: h.source.originalBundle.couponReads.map(
|
|
145
|
+
(row) => row.wireCoupon,
|
|
146
|
+
),
|
|
147
|
+
});
|
|
148
|
+
expect(payload.invoiceContext).toBeNull();
|
|
149
|
+
expect(payload.capturedSubject).toBe(observerIdentity.tokenIdentifier);
|
|
150
|
+
expect(payload.acquisition).toEqual({
|
|
151
|
+
observedAtMs: Date.now(),
|
|
152
|
+
elapsedWallMs: 0,
|
|
153
|
+
elapsedNsDecimal: "0",
|
|
154
|
+
apiVersion: "2026-09-30.endive",
|
|
155
|
+
baseReadProfile: "endive-schedule-first-44-v1",
|
|
156
|
+
invoiceReadProfile: null,
|
|
157
|
+
});
|
|
158
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
159
|
+
});
|
|
160
|
+
expect(witnessControls.retainQueries).toBe(2);
|
|
161
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
162
|
+
Array(6).fill("GET"),
|
|
163
|
+
);
|
|
164
|
+
state.reads.subscription.cancel_at_period_end = true;
|
|
165
|
+
await h.inAnotherAction(async (ctx) => {
|
|
166
|
+
const actor = await Reflect.apply(read, actors, [
|
|
167
|
+
h.sdk,
|
|
168
|
+
{
|
|
169
|
+
actualActionCtx: ctx,
|
|
170
|
+
parentOperationId: state.parentOperationId,
|
|
171
|
+
operationId: state.operationId,
|
|
172
|
+
witnessId: state.scope.identity.witnessId,
|
|
173
|
+
},
|
|
174
|
+
]);
|
|
175
|
+
const output = await actor.invoke();
|
|
176
|
+
assert(output.evidence);
|
|
177
|
+
expect(output.evidence.currentMaterial.predicate).toBe("conflict");
|
|
178
|
+
expect(output.evidence.historicalMaterial.predicate).toBe(
|
|
179
|
+
"snapshot_target_material_match",
|
|
180
|
+
);
|
|
181
|
+
assert("witness" in output);
|
|
182
|
+
expect(output.witness.descriptor).toEqual(
|
|
183
|
+
acknowledgement && Reflect.get(acknowledgement, "descriptor"),
|
|
184
|
+
);
|
|
185
|
+
expect(output.operationalAuthority).toBe(false);
|
|
186
|
+
const stored = await ctx.runQuery(
|
|
187
|
+
components.betterStripe.renewalWitnesses.queries
|
|
188
|
+
.readAuthorizedWitness,
|
|
189
|
+
{ identity: state.scope.identity },
|
|
190
|
+
);
|
|
191
|
+
expect(stored?.payloadJSON).toBe(originalPayloadJSON);
|
|
192
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
193
|
+
});
|
|
194
|
+
expect(witnessControls.readQueries).toBe(2);
|
|
195
|
+
expect(h.calls.slice(before).every((c) => c.method === "GET")).toBe(true);
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
identity: observerIdentity,
|
|
199
|
+
hostQuery: authorizeWitnessObservation,
|
|
200
|
+
targetInterval: "week",
|
|
201
|
+
hostWitnessRetainQuery: authorizeWitnessRetention,
|
|
202
|
+
hostWitnessReadQuery: authorizeWitnessRead,
|
|
203
|
+
},
|
|
204
|
+
);
|