@fantastic.dev/better-stripe 0.103.0 → 0.105.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/configure/transport.d.ts +100 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +17 -2
- package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +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 +19 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +71 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts +25 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js +62 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +14 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +17 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -1
- 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/billing/renewalAttach/internal/producer/configureWrite.d.ts +30 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +224 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts +61 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js +73 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js.map +1 -0
- package/docs/renewal-context-reads.md +79 -4
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/configure/transport.ts +31 -2
- 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 +132 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalData.ts +84 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +16 -0
- package/src/client/billing/renewalAttach/internal/producer/configurePreflight.ts +170 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +317 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWriteFactory.ts +88 -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/producer/producerConfigureWrite.integration.test.ts +158 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureWriteControls.integration.test.ts +537 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +136 -6
|
@@ -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,132 @@
|
|
|
1
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
2
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
3
|
+
import {
|
|
4
|
+
captureConfigureHistory,
|
|
5
|
+
checkConfigureRetention,
|
|
6
|
+
object,
|
|
7
|
+
} from "./configureJournalData.js";
|
|
8
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
9
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
10
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
11
|
+
import {
|
|
12
|
+
requireConfigure,
|
|
13
|
+
checkOperationLoad,
|
|
14
|
+
checkEmptyConfigureHistory,
|
|
15
|
+
matchConfigureDATA,
|
|
16
|
+
} from "./configureJournalData.js";
|
|
17
|
+
|
|
18
|
+
/** Bounded read fence only, without an atomic lock against subsequent writes. */
|
|
19
|
+
export async function assertConfigurePreflightFrontier(token: object) {
|
|
20
|
+
requireConfigure(arguments.length === 1);
|
|
21
|
+
const lineage = readConfigureLineage(token),
|
|
22
|
+
work = journalWorkForConfigureLineage(token);
|
|
23
|
+
const owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
24
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
25
|
+
readConfigureLineage(token);
|
|
26
|
+
requireConfigure(work.idle());
|
|
27
|
+
const reply = await owned(call);
|
|
28
|
+
readConfigureLineage(token);
|
|
29
|
+
requireConfigure(work.idle());
|
|
30
|
+
return reply;
|
|
31
|
+
}
|
|
32
|
+
checkOperationLoad(
|
|
33
|
+
await checked(() => lineage.journal.loadAuthorizedOperation()),
|
|
34
|
+
lineage.reservation,
|
|
35
|
+
lineage.parent.basisJSON,
|
|
36
|
+
);
|
|
37
|
+
matchConfigureDATA(
|
|
38
|
+
await checked(() => lineage.journal.readProviderAcknowledgement()),
|
|
39
|
+
null,
|
|
40
|
+
);
|
|
41
|
+
const history: unknown = await checked(() =>
|
|
42
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
43
|
+
);
|
|
44
|
+
checkEmptyConfigureHistory(history, lineage.reservation);
|
|
45
|
+
requireConfigure(work.idle());
|
|
46
|
+
readConfigureLineage(token);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Fixed expected event DATA from the actor, verified against full stored events. */
|
|
50
|
+
export async function assertConfigureWriteFrontier(
|
|
51
|
+
token: object,
|
|
52
|
+
expectedEvents: readonly unknown[],
|
|
53
|
+
known: {
|
|
54
|
+
receiptJSON: string;
|
|
55
|
+
receiptBinding: string;
|
|
56
|
+
retention: ReturnType<typeof checkConfigureRetention>;
|
|
57
|
+
} | null = null,
|
|
58
|
+
) {
|
|
59
|
+
const lineage = readConfigureLineage(token),
|
|
60
|
+
work = journalWorkForConfigureLineage(token);
|
|
61
|
+
const owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
62
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
63
|
+
readConfigureLineage(token);
|
|
64
|
+
requireConfigure(work.idle());
|
|
65
|
+
const reply = await owned(call);
|
|
66
|
+
readConfigureLineage(token);
|
|
67
|
+
requireConfigure(work.idle());
|
|
68
|
+
return reply;
|
|
69
|
+
}
|
|
70
|
+
const canonical = [];
|
|
71
|
+
for (let i = 0; i < expectedEvents.length; i++) {
|
|
72
|
+
requireConfigure(i < 3);
|
|
73
|
+
canonical.push(
|
|
74
|
+
await checked(() =>
|
|
75
|
+
canonicalJournalEvent(
|
|
76
|
+
i + 1,
|
|
77
|
+
JSON.stringify(renewalSnapshot(expectedEvents[i])),
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
checkOperationLoad(
|
|
83
|
+
await checked(() => lineage.journal.loadAuthorizedOperation()),
|
|
84
|
+
lineage.reservation,
|
|
85
|
+
lineage.parent.basisJSON,
|
|
86
|
+
);
|
|
87
|
+
const history = await checked(() =>
|
|
88
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
89
|
+
);
|
|
90
|
+
const events = captureConfigureHistory(
|
|
91
|
+
history,
|
|
92
|
+
lineage.reservation,
|
|
93
|
+
canonical.length,
|
|
94
|
+
);
|
|
95
|
+
for (let i = 0; i < events.length; i++) {
|
|
96
|
+
requireConfigure(events[i].binding === canonical[i].binding);
|
|
97
|
+
matchConfigureDATA(
|
|
98
|
+
await checked(() =>
|
|
99
|
+
lineage.journal.readStageEvent({
|
|
100
|
+
attemptId: lineage.reservation.attemptId,
|
|
101
|
+
sequence: i === 0 ? 1 : i === 1 ? 2 : 3,
|
|
102
|
+
}),
|
|
103
|
+
),
|
|
104
|
+
{ ...events[i], dataJSON: canonical[i].json },
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const ack = await checked(() =>
|
|
108
|
+
lineage.journal.readProviderAcknowledgement(),
|
|
109
|
+
);
|
|
110
|
+
if (known) {
|
|
111
|
+
const own = object(ack);
|
|
112
|
+
matchConfigureDATA(own.retention, known.retention);
|
|
113
|
+
checkConfigureRetention(
|
|
114
|
+
own.retention,
|
|
115
|
+
lineage.reservation,
|
|
116
|
+
events,
|
|
117
|
+
known.receiptBinding,
|
|
118
|
+
);
|
|
119
|
+
matchConfigureDATA(ack, {
|
|
120
|
+
retention: own.retention,
|
|
121
|
+
receiptJSON: known.receiptJSON,
|
|
122
|
+
});
|
|
123
|
+
} else matchConfigureDATA(ack, null);
|
|
124
|
+
// Final complete head read follows ACK and event inspection. This is not a lock.
|
|
125
|
+
matchConfigureDATA(
|
|
126
|
+
await checked(() =>
|
|
127
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
128
|
+
),
|
|
129
|
+
{ reservation: lineage.reservation, events },
|
|
130
|
+
);
|
|
131
|
+
return events;
|
|
132
|
+
}
|
|
@@ -246,3 +246,87 @@ export function checkParentAcknowledgement(
|
|
|
246
246
|
},
|
|
247
247
|
});
|
|
248
248
|
}
|
|
249
|
+
|
|
250
|
+
/** Complete bounded configure history descriptors, without promoting DATA to custody. */
|
|
251
|
+
export function captureConfigureHistory(
|
|
252
|
+
raw: unknown,
|
|
253
|
+
reservation: OperationalReservationDATA,
|
|
254
|
+
count: number,
|
|
255
|
+
) {
|
|
256
|
+
const own = closed(raw, ["reservation", "events"]);
|
|
257
|
+
requireConfigure(
|
|
258
|
+
Number.isInteger(count) &&
|
|
259
|
+
count >= 1 &&
|
|
260
|
+
count <= 3 &&
|
|
261
|
+
!types.isProxy(own.events) &&
|
|
262
|
+
Array.isArray(own.events) &&
|
|
263
|
+
Object.getPrototypeOf(own.events) === Array.prototype &&
|
|
264
|
+
own.events.length === count,
|
|
265
|
+
);
|
|
266
|
+
const events = Array.from({ length: count }, (_, index) => {
|
|
267
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
268
|
+
own.events,
|
|
269
|
+
String(index),
|
|
270
|
+
);
|
|
271
|
+
requireConfigure(
|
|
272
|
+
descriptor && descriptor.enumerable && "value" in descriptor,
|
|
273
|
+
);
|
|
274
|
+
const event = closed(descriptor.value, [
|
|
275
|
+
"operationId",
|
|
276
|
+
"attemptId",
|
|
277
|
+
"stage",
|
|
278
|
+
"sourcePayloadId",
|
|
279
|
+
"sequence",
|
|
280
|
+
"binding",
|
|
281
|
+
"payloadId",
|
|
282
|
+
"eventId",
|
|
283
|
+
]);
|
|
284
|
+
return {
|
|
285
|
+
operationId: reservation.operationId,
|
|
286
|
+
attemptId: reservation.attemptId,
|
|
287
|
+
stage: "configure" as const,
|
|
288
|
+
sourcePayloadId: reservation.payloadId,
|
|
289
|
+
sequence: index + 1,
|
|
290
|
+
binding: text(event.binding),
|
|
291
|
+
payloadId: text(event.payloadId),
|
|
292
|
+
eventId: text(event.eventId),
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
requireConfigure(
|
|
296
|
+
new Set(events.map((e) => e.eventId)).size === count &&
|
|
297
|
+
new Set(events.map((e) => e.payloadId)).size === count &&
|
|
298
|
+
events.every((e) => e.payloadId !== reservation.payloadId),
|
|
299
|
+
);
|
|
300
|
+
matchConfigureDATA(raw, { reservation, events });
|
|
301
|
+
return events;
|
|
302
|
+
}
|
|
303
|
+
export function checkConfigureRetention(
|
|
304
|
+
raw: unknown,
|
|
305
|
+
reservation: OperationalReservationDATA,
|
|
306
|
+
events: ReturnType<typeof captureConfigureHistory>,
|
|
307
|
+
receiptBinding: string,
|
|
308
|
+
) {
|
|
309
|
+
requireConfigure(events.length >= 2);
|
|
310
|
+
const own = object(raw),
|
|
311
|
+
receiptPayloadId = text(own.receiptPayloadId);
|
|
312
|
+
requireConfigure(
|
|
313
|
+
receiptPayloadId !== reservation.payloadId &&
|
|
314
|
+
!events.some((event) => event.payloadId === receiptPayloadId),
|
|
315
|
+
);
|
|
316
|
+
const expected = {
|
|
317
|
+
status: "retained" as const,
|
|
318
|
+
operationId: reservation.operationId,
|
|
319
|
+
schemaVersion: 1 as const,
|
|
320
|
+
stage: "configure" as const,
|
|
321
|
+
attemptId: reservation.attemptId,
|
|
322
|
+
sourcePayloadId: reservation.payloadId,
|
|
323
|
+
dispatchEventId: events[0].eventId,
|
|
324
|
+
dispatchPayloadId: events[0].payloadId,
|
|
325
|
+
responseEventId: events[1].eventId,
|
|
326
|
+
responsePayloadId: events[1].payloadId,
|
|
327
|
+
receiptPayloadId,
|
|
328
|
+
receiptBinding,
|
|
329
|
+
};
|
|
330
|
+
matchConfigureDATA(raw, expected);
|
|
331
|
+
return expected;
|
|
332
|
+
}
|
|
@@ -33,6 +33,22 @@ function construct(token: object) {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
},
|
|
36
|
+
async retain(receiptJSON: string) {
|
|
37
|
+
requireConfigure(arguments.length === 1);
|
|
38
|
+
gate();
|
|
39
|
+
pending++;
|
|
40
|
+
try {
|
|
41
|
+
const reply = await original.journal.retainProviderAcknowledgement({
|
|
42
|
+
attemptId: original.reservation.attemptId,
|
|
43
|
+
expectedSequence: 2,
|
|
44
|
+
receiptJSON,
|
|
45
|
+
});
|
|
46
|
+
gate();
|
|
47
|
+
return reply;
|
|
48
|
+
} finally {
|
|
49
|
+
pending--;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
36
52
|
idle() {
|
|
37
53
|
requireConfigure(arguments.length === 0);
|
|
38
54
|
gate();
|