@fantastic.dev/better-stripe 0.103.0 → 0.104.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 +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +22 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +105 -3
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/output.js +6 -2
- package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +3 -1
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/record.js +8 -3
- package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js +12 -5
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +25 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js +117 -0
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +34 -2
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +148 -3
- package/src/client/billing/renewalAttach/internal/preflight/output.ts +20 -3
- package/src/client/billing/renewalAttach/internal/preflight/record.ts +11 -3
- package/src/client/billing/renewalAttach/internal/preflight/relations.ts +20 -5
- package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +40 -0
- package/src/client/billing/renewalAttach/internal/producer/configurePreflight.ts +170 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflight.integration.test.ts +67 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflightControls.integration.test.ts +475 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +51 -4
|
@@ -3,7 +3,15 @@ import { OWNER } from "../originalOwner.js";
|
|
|
3
3
|
import { closed, need, stop, type SourceMethod } from "./types.js";
|
|
4
4
|
import { requiredJSONSnapshot } from "../material/requiredJson.js";
|
|
5
5
|
import { resourceId } from "../../../renewalAggregate/shared.js";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
loadConfigureOwnedReadTransportSource,
|
|
8
|
+
COMPILED_PREFLIGHT_ENTRIES,
|
|
9
|
+
} from "./sourceOperations.js";
|
|
10
|
+
import { readConfigureLineage } from "../producer/configureLineage.js";
|
|
11
|
+
import { readAttachAcknowledgementForLineage } from "../producer/attachAcknowledgement.js";
|
|
12
|
+
import { captureInitialStockRawDelegate } from "../producer/stockDelegateFactory.js";
|
|
13
|
+
import { capturePreflightRecordDATA } from "../preflight/record.js";
|
|
14
|
+
import { object } from "../producer/configureJournalData.js";
|
|
7
15
|
|
|
8
16
|
const API = "2026-09-30.endive";
|
|
9
17
|
type Resource = "subscription" | "price" | "customer" | "coupon" | "schedule";
|
|
@@ -159,8 +167,15 @@ export function createConfigureOwnedReadTransport() {
|
|
|
159
167
|
OWNER.check();
|
|
160
168
|
const source = loadConfigureOwnedReadTransportSource();
|
|
161
169
|
OWNER.check();
|
|
170
|
+
return configureReadKernel(source, OWNER);
|
|
171
|
+
}
|
|
172
|
+
function configureReadKernel(
|
|
173
|
+
source: unknown,
|
|
174
|
+
owner: typeof OWNER,
|
|
175
|
+
guard?: () => void,
|
|
176
|
+
) {
|
|
162
177
|
const frame = closed(source, ["owner", "operation", "readPlan", "delegate"]);
|
|
163
|
-
need(frame.owner ===
|
|
178
|
+
need(frame.owner === owner);
|
|
164
179
|
const operation = frame.operation,
|
|
165
180
|
delegate = frame.delegate,
|
|
166
181
|
readPlanReference = frame.readPlan,
|
|
@@ -179,7 +194,9 @@ export function createConfigureOwnedReadTransport() {
|
|
|
179
194
|
}
|
|
180
195
|
checking = true;
|
|
181
196
|
try {
|
|
182
|
-
|
|
197
|
+
guard?.();
|
|
198
|
+
owner.check();
|
|
199
|
+
guard?.();
|
|
183
200
|
if (closedOwner) stop();
|
|
184
201
|
} catch {
|
|
185
202
|
closedOwner = true;
|
|
@@ -283,3 +300,131 @@ export function createConfigureOwnedReadTransport() {
|
|
|
283
300
|
capability,
|
|
284
301
|
});
|
|
285
302
|
}
|
|
303
|
+
|
|
304
|
+
const admittedReads = new WeakSet<object>();
|
|
305
|
+
/** Fixed, qualified readonly plan and actual stock promise; no caller frame. */
|
|
306
|
+
export function createAdmittedConfigureReadTransport(token: object) {
|
|
307
|
+
need(
|
|
308
|
+
typeof token === "object" && token !== null && !admittedReads.has(token),
|
|
309
|
+
);
|
|
310
|
+
admittedReads.add(token);
|
|
311
|
+
need(arguments.length === 1);
|
|
312
|
+
need(
|
|
313
|
+
!types.isProxy(COMPILED_PREFLIGHT_ENTRIES) &&
|
|
314
|
+
Array.isArray(COMPILED_PREFLIGHT_ENTRIES) &&
|
|
315
|
+
COMPILED_PREFLIGHT_ENTRIES.length > 0,
|
|
316
|
+
);
|
|
317
|
+
const lineage = readConfigureLineage(token);
|
|
318
|
+
const acknowledgement = readAttachAcknowledgementForLineage(
|
|
319
|
+
lineage.parentToken,
|
|
320
|
+
);
|
|
321
|
+
const candidates = COMPILED_PREFLIGHT_ENTRIES.filter((entry) => {
|
|
322
|
+
const fields = closed(entry, ["originalEntry", "coversPreflight"]);
|
|
323
|
+
need(
|
|
324
|
+
typeof fields.coversPreflight === "function" &&
|
|
325
|
+
!types.isProxy(fields.coversPreflight),
|
|
326
|
+
);
|
|
327
|
+
return fields.originalEntry === acknowledgement.originalEntry;
|
|
328
|
+
});
|
|
329
|
+
need(candidates.length === 1);
|
|
330
|
+
const entry = candidates[0],
|
|
331
|
+
fields = closed(entry, ["originalEntry", "coversPreflight"]),
|
|
332
|
+
covers = fields.coversPreflight;
|
|
333
|
+
need(typeof covers === "function");
|
|
334
|
+
function guard() {
|
|
335
|
+
const current = readConfigureLineage(token);
|
|
336
|
+
need(
|
|
337
|
+
current.originalReservation === lineage.originalReservation &&
|
|
338
|
+
current.journal === lineage.journal &&
|
|
339
|
+
current.owner === lineage.owner,
|
|
340
|
+
);
|
|
341
|
+
need(
|
|
342
|
+
!types.isProxy(COMPILED_PREFLIGHT_ENTRIES) &&
|
|
343
|
+
Array.isArray(COMPILED_PREFLIGHT_ENTRIES) &&
|
|
344
|
+
COMPILED_PREFLIGHT_ENTRIES.includes(entry),
|
|
345
|
+
);
|
|
346
|
+
const now = closed(entry, ["originalEntry", "coversPreflight"]);
|
|
347
|
+
need(
|
|
348
|
+
now.originalEntry === acknowledgement.originalEntry &&
|
|
349
|
+
now.coversPreflight === covers &&
|
|
350
|
+
!types.isProxy(covers),
|
|
351
|
+
);
|
|
352
|
+
need(
|
|
353
|
+
readAttachAcknowledgementForLineage(lineage.parentToken) ===
|
|
354
|
+
acknowledgement,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
guard();
|
|
358
|
+
const full = object(JSON.parse(lineage.reservation.recordJSON));
|
|
359
|
+
const retained = capturePreflightRecordDATA(full.configureRecord);
|
|
360
|
+
const expected = retained.configuration.preparation.expected;
|
|
361
|
+
const customer = retained.originalBundle.wireBillingCustomer.id;
|
|
362
|
+
need(typeof customer === "string");
|
|
363
|
+
const receipt = object(acknowledgement.receipt),
|
|
364
|
+
scheduleId = receipt.scheduleId;
|
|
365
|
+
need(typeof scheduleId === "string");
|
|
366
|
+
const rows = [
|
|
367
|
+
{
|
|
368
|
+
resource: "subscription",
|
|
369
|
+
path:
|
|
370
|
+
"/v1/subscriptions/" +
|
|
371
|
+
encodeURIComponent(expected.subscriptionId) +
|
|
372
|
+
query,
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
resource: "price",
|
|
376
|
+
path: "/v1/prices/" + encodeURIComponent(expected.targetPriceId),
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
resource: "customer",
|
|
380
|
+
path: "/v1/customers/" + encodeURIComponent(customer),
|
|
381
|
+
},
|
|
382
|
+
...retained.originalBundle.couponReads.map((row) => {
|
|
383
|
+
need(typeof row.couponId === "string");
|
|
384
|
+
return {
|
|
385
|
+
resource: "coupon",
|
|
386
|
+
path: "/v1/coupons/" + encodeURIComponent(row.couponId),
|
|
387
|
+
};
|
|
388
|
+
}),
|
|
389
|
+
{
|
|
390
|
+
resource: "schedule",
|
|
391
|
+
path: "/v1/subscription_schedules/" + encodeURIComponent(scheduleId),
|
|
392
|
+
},
|
|
393
|
+
];
|
|
394
|
+
const readPlan = Object.freeze(
|
|
395
|
+
rows.map((row, index) =>
|
|
396
|
+
Object.freeze({
|
|
397
|
+
...row,
|
|
398
|
+
ordinal: index + 1,
|
|
399
|
+
method: "GET",
|
|
400
|
+
body: undefined,
|
|
401
|
+
options: Object.freeze({ apiVersion: API, maxNetworkRetries: 0 }),
|
|
402
|
+
}),
|
|
403
|
+
),
|
|
404
|
+
);
|
|
405
|
+
const delegate = captureInitialStockRawDelegate(lineage.parentToken);
|
|
406
|
+
const pair = configureReadKernel(
|
|
407
|
+
{ owner: lineage.owner, operation: token, readPlan, delegate },
|
|
408
|
+
lineage.owner,
|
|
409
|
+
guard,
|
|
410
|
+
);
|
|
411
|
+
need(
|
|
412
|
+
pair.capability.assertSourceOperationBinding(
|
|
413
|
+
token,
|
|
414
|
+
readPlan,
|
|
415
|
+
delegate,
|
|
416
|
+
delegate.rawRequest,
|
|
417
|
+
),
|
|
418
|
+
);
|
|
419
|
+
need(pair.capability.reserveAcquisition());
|
|
420
|
+
guard();
|
|
421
|
+
return Object.freeze({
|
|
422
|
+
readTransport: pair.transport.readTransport,
|
|
423
|
+
guard,
|
|
424
|
+
entry,
|
|
425
|
+
covers,
|
|
426
|
+
acknowledgement,
|
|
427
|
+
retained,
|
|
428
|
+
scheduleId,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
@@ -12,14 +12,13 @@ import type {
|
|
|
12
12
|
ProjectedRenewalConfigurationV2,
|
|
13
13
|
RenewalScheduleAttachmentReceiptV2,
|
|
14
14
|
} from "../../../renewalV2/index.js";
|
|
15
|
-
export function
|
|
15
|
+
export function releasePreflightDATA(
|
|
16
16
|
record: PreflightRecord,
|
|
17
17
|
currentEvidence: CurrentEvidence,
|
|
18
18
|
request: ProjectedRenewalConfigurationV2,
|
|
19
19
|
originalC6: ProjectedRenewalConfigurationV2,
|
|
20
20
|
ackC3: RenewalScheduleAttachmentReceiptV2,
|
|
21
21
|
): PreflightOutput {
|
|
22
|
-
OWNER.check();
|
|
23
22
|
need(
|
|
24
23
|
equal(record.request, originalC6) &&
|
|
25
24
|
equal(request, originalC6) &&
|
|
@@ -37,6 +36,24 @@ export function releasePreflight(
|
|
|
37
36
|
for (const [path, value] of Object.entries(expected))
|
|
38
37
|
need(captured.slots.get(path) === value);
|
|
39
38
|
const output = freeze(materialize(captured.node));
|
|
40
|
-
OWNER.check();
|
|
41
39
|
return output as PreflightOutput;
|
|
42
40
|
}
|
|
41
|
+
|
|
42
|
+
export function releasePreflight(
|
|
43
|
+
record: PreflightRecord,
|
|
44
|
+
currentEvidence: CurrentEvidence,
|
|
45
|
+
request: ProjectedRenewalConfigurationV2,
|
|
46
|
+
originalC6: ProjectedRenewalConfigurationV2,
|
|
47
|
+
ackC3: RenewalScheduleAttachmentReceiptV2,
|
|
48
|
+
): PreflightOutput {
|
|
49
|
+
OWNER.check();
|
|
50
|
+
const output = releasePreflightDATA(
|
|
51
|
+
record,
|
|
52
|
+
currentEvidence,
|
|
53
|
+
request,
|
|
54
|
+
originalC6,
|
|
55
|
+
ackC3,
|
|
56
|
+
);
|
|
57
|
+
OWNER.check();
|
|
58
|
+
return output;
|
|
59
|
+
}
|
|
@@ -108,8 +108,9 @@ const child = (node: Node, key: string): Node => {
|
|
|
108
108
|
need(row);
|
|
109
109
|
return row[1];
|
|
110
110
|
};
|
|
111
|
-
export function
|
|
112
|
-
|
|
111
|
+
export function capturePreflightRecordDATA(
|
|
112
|
+
raw: unknown,
|
|
113
|
+
): CapturedPreflightRecord {
|
|
113
114
|
const captured = capture(raw, false);
|
|
114
115
|
const configuration = freeze(
|
|
115
116
|
materialize(child(captured.node, "configuration")),
|
|
@@ -117,7 +118,6 @@ export function capturePreflightRecord(raw: unknown): CapturedPreflightRecord {
|
|
|
117
118
|
originalBundle = freeze(
|
|
118
119
|
materialize(child(captured.node, "originalBundle")),
|
|
119
120
|
) as Bundle;
|
|
120
|
-
OWNER.check();
|
|
121
121
|
return Object.freeze({ captured, configuration, originalBundle });
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -125,3 +125,11 @@ export function capturePreflightRecord(raw: unknown): CapturedPreflightRecord {
|
|
|
125
125
|
export function capturePreflightOutput(value: unknown): CapturedRecord {
|
|
126
126
|
return capture(value, true);
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
/** Legacy Source wrapper; DATA capture alone grants no invocation custody. */
|
|
130
|
+
export function capturePreflightRecord(raw: unknown): CapturedPreflightRecord {
|
|
131
|
+
OWNER.check();
|
|
132
|
+
const captured = capturePreflightRecordDATA(raw);
|
|
133
|
+
OWNER.check();
|
|
134
|
+
return captured;
|
|
135
|
+
}
|
|
@@ -103,19 +103,17 @@ export function expectedSlots(
|
|
|
103
103
|
...Object.entries(record).filter(([k]) => k.startsWith("/request/")),
|
|
104
104
|
]);
|
|
105
105
|
}
|
|
106
|
-
export function
|
|
106
|
+
export function verifyPreflightRecordDATA(
|
|
107
107
|
captured: CapturedPreflightRecord,
|
|
108
108
|
originalC6: ProjectedRenewalConfigurationV2,
|
|
109
109
|
ackC3: RenewalScheduleAttachmentReceiptV2,
|
|
110
110
|
): PreflightRecord {
|
|
111
|
-
OWNER.check();
|
|
112
111
|
const expected = expectedSlots(originalC6, ackC3, false);
|
|
113
112
|
for (const [path, value] of Object.entries(expected))
|
|
114
113
|
need(captured.captured.slots.get(path) === value);
|
|
115
114
|
const record = materialize(captured.captured.node) as PreflightRecord;
|
|
116
115
|
need(equal(record.request, originalC6) && equal(record.attachReceipt, ackC3));
|
|
117
116
|
verifyOriginalRaw(record, ackC3);
|
|
118
|
-
OWNER.check();
|
|
119
117
|
return freeze(record);
|
|
120
118
|
}
|
|
121
119
|
function association(value: unknown, id: string, configuration: Configuration) {
|
|
@@ -172,11 +170,10 @@ function verifyOriginalRaw(
|
|
|
172
170
|
};
|
|
173
171
|
rebuild(preconfigure);
|
|
174
172
|
}
|
|
175
|
-
export function
|
|
173
|
+
export function verifyCurrentPreflightDATA(
|
|
176
174
|
record: PreflightRecord,
|
|
177
175
|
evidence: CurrentEvidence,
|
|
178
176
|
) {
|
|
179
|
-
OWNER.check();
|
|
180
177
|
closed(evidence, ["bundle", "schedule", "observedAt"]);
|
|
181
178
|
need(Number.isSafeInteger(evidence.observedAt) && evidence.observedAt >= 0);
|
|
182
179
|
const c = record.configuration,
|
|
@@ -205,5 +202,23 @@ export function verifyCurrentPreflight(
|
|
|
205
202
|
equal(b.derivedCouponJoins, o.derivedCouponJoins),
|
|
206
203
|
);
|
|
207
204
|
association(b.wireSubscription.schedule, record.attachReceipt.scheduleId, c);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function verifyPreflightRecord(
|
|
208
|
+
captured: CapturedPreflightRecord,
|
|
209
|
+
originalC6: ProjectedRenewalConfigurationV2,
|
|
210
|
+
ackC3: RenewalScheduleAttachmentReceiptV2,
|
|
211
|
+
): PreflightRecord {
|
|
212
|
+
OWNER.check();
|
|
213
|
+
const record = verifyPreflightRecordDATA(captured, originalC6, ackC3);
|
|
214
|
+
OWNER.check();
|
|
215
|
+
return record;
|
|
216
|
+
}
|
|
217
|
+
export function verifyCurrentPreflight(
|
|
218
|
+
record: PreflightRecord,
|
|
219
|
+
evidence: CurrentEvidence,
|
|
220
|
+
): void {
|
|
221
|
+
OWNER.check();
|
|
222
|
+
verifyCurrentPreflightDATA(record, evidence);
|
|
208
223
|
OWNER.check();
|
|
209
224
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
2
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
3
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
4
|
+
import {
|
|
5
|
+
requireConfigure,
|
|
6
|
+
checkOperationLoad,
|
|
7
|
+
checkEmptyConfigureHistory,
|
|
8
|
+
matchConfigureDATA,
|
|
9
|
+
} from "./configureJournalData.js";
|
|
10
|
+
|
|
11
|
+
/** Bounded read fence only, without an atomic lock against subsequent writes. */
|
|
12
|
+
export async function assertConfigurePreflightFrontier(token: object) {
|
|
13
|
+
requireConfigure(arguments.length === 1);
|
|
14
|
+
const lineage = readConfigureLineage(token),
|
|
15
|
+
work = journalWorkForConfigureLineage(token);
|
|
16
|
+
const owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
17
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
18
|
+
readConfigureLineage(token);
|
|
19
|
+
requireConfigure(work.idle());
|
|
20
|
+
const reply = await owned(call);
|
|
21
|
+
readConfigureLineage(token);
|
|
22
|
+
requireConfigure(work.idle());
|
|
23
|
+
return reply;
|
|
24
|
+
}
|
|
25
|
+
checkOperationLoad(
|
|
26
|
+
await checked(() => lineage.journal.loadAuthorizedOperation()),
|
|
27
|
+
lineage.reservation,
|
|
28
|
+
lineage.parent.basisJSON,
|
|
29
|
+
);
|
|
30
|
+
matchConfigureDATA(
|
|
31
|
+
await checked(() => lineage.journal.readProviderAcknowledgement()),
|
|
32
|
+
null,
|
|
33
|
+
);
|
|
34
|
+
const history: unknown = await checked(() =>
|
|
35
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
36
|
+
);
|
|
37
|
+
checkEmptyConfigureHistory(history, lineage.reservation);
|
|
38
|
+
requireConfigure(work.idle());
|
|
39
|
+
readConfigureLineage(token);
|
|
40
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
2
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
3
|
+
import { assertConfigurePreflightFrontier } from "./configureFrontier.js";
|
|
4
|
+
import { createAdmittedConfigureReadTransport } from "../operations/configureReadTransport.js";
|
|
5
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
6
|
+
import {
|
|
7
|
+
projectRenewalConfigurationV2,
|
|
8
|
+
constructRenewalScheduleAttachmentReceiptV2,
|
|
9
|
+
} from "../../../renewalV2/index.js";
|
|
10
|
+
import {
|
|
11
|
+
verifyPreflightRecordDATA,
|
|
12
|
+
verifyCurrentPreflightDATA,
|
|
13
|
+
} from "../preflight/relations.js";
|
|
14
|
+
import { releasePreflightDATA } from "../preflight/output.js";
|
|
15
|
+
import { requireConfigure } from "./configureJournalData.js";
|
|
16
|
+
import { equal } from "../../../renewalAggregate/shared.js";
|
|
17
|
+
import type { PreflightOutput, PreflightRecord } from "../preflight/grammar.js";
|
|
18
|
+
import type { Bundle } from "../material/capture.js";
|
|
19
|
+
|
|
20
|
+
function matchesCurrentBundle(
|
|
21
|
+
value: unknown,
|
|
22
|
+
record: PreflightRecord,
|
|
23
|
+
): value is Bundle {
|
|
24
|
+
return equal(value, {
|
|
25
|
+
...record.originalBundle,
|
|
26
|
+
wireSubscription: record.configuration.freshSubscription,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const captures = new WeakSet<object>();
|
|
30
|
+
type PreflightView = Readonly<{
|
|
31
|
+
output: PreflightOutput;
|
|
32
|
+
originalEntry: unknown;
|
|
33
|
+
preflightEntry: unknown;
|
|
34
|
+
coversPreflight: unknown;
|
|
35
|
+
acknowledgement: ReturnType<
|
|
36
|
+
typeof createAdmittedConfigureReadTransport
|
|
37
|
+
>["acknowledgement"];
|
|
38
|
+
operationalAuthority: false;
|
|
39
|
+
}>;
|
|
40
|
+
const completions = new WeakMap<
|
|
41
|
+
object,
|
|
42
|
+
{ view: PreflightView; guard: () => void }
|
|
43
|
+
>();
|
|
44
|
+
/** Actual admitted child only. This readonly consistency actor grants no write. */
|
|
45
|
+
export function captureAdmittedConfigurePreflight(token: object) {
|
|
46
|
+
requireConfigure(
|
|
47
|
+
typeof token === "object" && token !== null && !captures.has(token),
|
|
48
|
+
);
|
|
49
|
+
captures.add(token);
|
|
50
|
+
requireConfigure(arguments.length === 1);
|
|
51
|
+
const pair = createAdmittedConfigureReadTransport(token);
|
|
52
|
+
const lineage = readConfigureLineage(token),
|
|
53
|
+
owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
54
|
+
let used = false,
|
|
55
|
+
closed = false;
|
|
56
|
+
function guard() {
|
|
57
|
+
requireConfigure(!closed);
|
|
58
|
+
try {
|
|
59
|
+
pair.guard();
|
|
60
|
+
} catch (error) {
|
|
61
|
+
closed = true;
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
66
|
+
guard();
|
|
67
|
+
const result = await owned(call);
|
|
68
|
+
guard();
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
const actor = Object.freeze({
|
|
72
|
+
async invoke() {
|
|
73
|
+
requireConfigure(!used);
|
|
74
|
+
used = true;
|
|
75
|
+
requireConfigure(arguments.length === 0);
|
|
76
|
+
try {
|
|
77
|
+
guard();
|
|
78
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
79
|
+
const original = await checked(() =>
|
|
80
|
+
projectRenewalConfigurationV2(pair.retained.configuration),
|
|
81
|
+
);
|
|
82
|
+
requireConfigure(original.status === "projected_configure_request");
|
|
83
|
+
const ack = await checked(() =>
|
|
84
|
+
constructRenewalScheduleAttachmentReceiptV2(
|
|
85
|
+
pair.retained.configuration.attachReceipt,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
const record = verifyPreflightRecordDATA(pair.retained, original, ack);
|
|
89
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
90
|
+
guard();
|
|
91
|
+
const reader = createSelectedRawAcquisition(
|
|
92
|
+
lineage.owner,
|
|
93
|
+
pair.readTransport,
|
|
94
|
+
pair.scheduleId,
|
|
95
|
+
);
|
|
96
|
+
const acquired = await checked(() =>
|
|
97
|
+
reader.acquire(record.configuration.preparation.expected),
|
|
98
|
+
);
|
|
99
|
+
requireConfigure(acquired.ok);
|
|
100
|
+
requireConfigure(matchesCurrentBundle(acquired.bundle, record));
|
|
101
|
+
const evidence = Object.freeze({
|
|
102
|
+
bundle: acquired.bundle,
|
|
103
|
+
schedule: acquired.schedule,
|
|
104
|
+
observedAt: acquired.observedAt,
|
|
105
|
+
});
|
|
106
|
+
verifyCurrentPreflightDATA(record, evidence);
|
|
107
|
+
guard();
|
|
108
|
+
const configuration = {
|
|
109
|
+
...record.configuration,
|
|
110
|
+
freshSubscription: evidence.bundle.wireSubscription,
|
|
111
|
+
targetPrice: evidence.bundle.wireTargetPrice,
|
|
112
|
+
...(Object.prototype.hasOwnProperty.call(
|
|
113
|
+
record.configuration,
|
|
114
|
+
"billingCustomer",
|
|
115
|
+
)
|
|
116
|
+
? { billingCustomer: evidence.bundle.wireBillingCustomer }
|
|
117
|
+
: {}),
|
|
118
|
+
schedule: evidence.schedule,
|
|
119
|
+
observedAt: evidence.observedAt,
|
|
120
|
+
};
|
|
121
|
+
const fresh = await checked(() =>
|
|
122
|
+
projectRenewalConfigurationV2(configuration),
|
|
123
|
+
);
|
|
124
|
+
requireConfigure(
|
|
125
|
+
fresh.status === "projected_configure_request" &&
|
|
126
|
+
equal(fresh, original) &&
|
|
127
|
+
equal(fresh, record.request),
|
|
128
|
+
);
|
|
129
|
+
requireConfigure(
|
|
130
|
+
Reflect.apply(pair.covers, pair.entry, [record, evidence, fresh]) ===
|
|
131
|
+
true,
|
|
132
|
+
);
|
|
133
|
+
guard();
|
|
134
|
+
const output = releasePreflightDATA(
|
|
135
|
+
record,
|
|
136
|
+
evidence,
|
|
137
|
+
fresh,
|
|
138
|
+
original,
|
|
139
|
+
ack,
|
|
140
|
+
);
|
|
141
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
142
|
+
guard();
|
|
143
|
+
completions.set(token, {
|
|
144
|
+
guard,
|
|
145
|
+
view: Object.freeze({
|
|
146
|
+
output,
|
|
147
|
+
originalEntry: pair.acknowledgement.originalEntry,
|
|
148
|
+
preflightEntry: pair.entry,
|
|
149
|
+
coversPreflight: pair.covers,
|
|
150
|
+
acknowledgement: pair.acknowledgement,
|
|
151
|
+
operationalAuthority: false as const,
|
|
152
|
+
}),
|
|
153
|
+
});
|
|
154
|
+
return output;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
closed = true;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
return actor;
|
|
162
|
+
}
|
|
163
|
+
/** Actual completed return identity; copied output is never a registration input. */
|
|
164
|
+
export function readAdmittedConfigurePreflight(token: object) {
|
|
165
|
+
requireConfigure(arguments.length === 1);
|
|
166
|
+
const completed = completions.get(token);
|
|
167
|
+
requireConfigure(completed);
|
|
168
|
+
completed.guard();
|
|
169
|
+
return completed.view;
|
|
170
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configureAdmissionFixture,
|
|
3
|
+
admissionControls,
|
|
4
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
5
|
+
import { expect, it } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
captureAdmittedConfigurePreflight,
|
|
8
|
+
readAdmittedConfigurePreflight,
|
|
9
|
+
} from "./configurePreflight.js";
|
|
10
|
+
|
|
11
|
+
it.each(["initial", "replay", "resume"] as const)(
|
|
12
|
+
"runs fixed readonly configure preflight after %s ACK with actual returned custody",
|
|
13
|
+
async (mode) => {
|
|
14
|
+
await configureAdmissionFixture(async (h) => {
|
|
15
|
+
await h.complete(mode);
|
|
16
|
+
const child = await h.child();
|
|
17
|
+
const token = await h.core.admitConfigure(
|
|
18
|
+
child.fresh.call,
|
|
19
|
+
child.journal,
|
|
20
|
+
);
|
|
21
|
+
h.configureReads(child);
|
|
22
|
+
admissionControls.preflight.push({
|
|
23
|
+
originalEntry: admissionControls.entries[0],
|
|
24
|
+
coversPreflight: () => true,
|
|
25
|
+
});
|
|
26
|
+
const start = h.calls.length,
|
|
27
|
+
selectors = admissionControls.selectors,
|
|
28
|
+
basis = h.core.basisJSON;
|
|
29
|
+
const actor = captureAdmittedConfigurePreflight(token);
|
|
30
|
+
expect(actor).not.toBeNull();
|
|
31
|
+
const output = await actor.invoke();
|
|
32
|
+
expect(output.status).toBe("configure_preflight_consistent");
|
|
33
|
+
expect(output.request).toEqual(child.record.configureRecord.request);
|
|
34
|
+
expect(output.currentEvidence.observedAt).toBe(
|
|
35
|
+
h.baseline.configurationTime,
|
|
36
|
+
);
|
|
37
|
+
expect(output.operationalAuthority).toBe(false);
|
|
38
|
+
const view = readAdmittedConfigurePreflight(token);
|
|
39
|
+
expect(view.output === output).toBe(true);
|
|
40
|
+
expect(view.originalEntry === admissionControls.entries[0]).toBe(true);
|
|
41
|
+
expect(
|
|
42
|
+
view.coversPreflight === admissionControls.preflight[0].coversPreflight,
|
|
43
|
+
).toBe(true);
|
|
44
|
+
expect(view.acknowledgement === h.core.attachAcknowledgement()).toBe(
|
|
45
|
+
true,
|
|
46
|
+
);
|
|
47
|
+
expect(
|
|
48
|
+
h.calls.slice(start).map((row) => row.method + ":" + row.path),
|
|
49
|
+
).toEqual([
|
|
50
|
+
"GET:/v1/subscriptions/sub_original",
|
|
51
|
+
"GET:/v1/prices/price_target",
|
|
52
|
+
"GET:/v1/customers/cus_buyer",
|
|
53
|
+
...h.source.originalBundle.couponReads.map(
|
|
54
|
+
(row) =>
|
|
55
|
+
"GET:/v1/coupons/" + encodeURIComponent(String(row.couponId)),
|
|
56
|
+
),
|
|
57
|
+
"GET:/v1/subscription_schedules/" + h.baseline.schedule.id,
|
|
58
|
+
]);
|
|
59
|
+
expect(h.calls.slice(start).every((row) => row.hasBody === false)).toBe(
|
|
60
|
+
true,
|
|
61
|
+
);
|
|
62
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
63
|
+
expect(admissionControls.legacy).toBe(0);
|
|
64
|
+
expect(h.core.basisJSON).toBe(basis);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
);
|