@fantastic.dev/better-stripe 0.105.0 → 0.106.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/c10/configureEvents.d.ts +23 -0
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js +28 -0
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +200 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +31 -4
- package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.d.ts +19 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.js +11 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.d.ts +56 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.js +79 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +31 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +33 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.js +259 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts +2 -25
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +15 -30
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +55 -3
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/c10/configureEvents.ts +37 -0
- package/src/client/billing/renewalAttach/internal/configure/transport.ts +37 -4
- package/src/client/billing/renewalAttach/internal/producer/configureAcknowledgement.ts +11 -0
- package/src/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.ts +121 -0
- package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +63 -0
- package/src/client/billing/renewalAttach/internal/producer/configureRecovery.ts +361 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +18 -47
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureRecovery.integration.test.ts +99 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureRecoveryControls.integration.test.ts +420 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { readOriginalConfigureWriteTransport } from "../configure/transport.js";
|
|
2
|
+
import { need } from "../configure/request.js";
|
|
3
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
4
|
+
import type { CurrentEvidence } from "../preflight/grammar.js";
|
|
5
|
+
import type { checkConfigureRetention } from "./configureJournalData.js";
|
|
6
|
+
import type {
|
|
7
|
+
ConstructRenewalConfigurationReceiptV2Options,
|
|
8
|
+
RenewalConfigurationReceiptV2,
|
|
9
|
+
} from "../../../renewalV2/index.js";
|
|
10
|
+
|
|
11
|
+
type Pair = ReturnType<typeof readOriginalConfigureWriteTransport>;
|
|
12
|
+
export type ConfigureCompletion = Readonly<{
|
|
13
|
+
output: unknown;
|
|
14
|
+
receipt: unknown;
|
|
15
|
+
rawReceipt: unknown;
|
|
16
|
+
acknowledgement: Pair["preflight"]["acknowledgement"];
|
|
17
|
+
originalEntry: unknown;
|
|
18
|
+
configureEntry: unknown;
|
|
19
|
+
coversConfigure: unknown;
|
|
20
|
+
operationalAuthority: false;
|
|
21
|
+
}>;
|
|
22
|
+
export type ConfigureAttempt = {
|
|
23
|
+
pair: Pair;
|
|
24
|
+
started: boolean;
|
|
25
|
+
settled: boolean;
|
|
26
|
+
recoveryReserved: boolean;
|
|
27
|
+
freshEvidence: CurrentEvidence | null;
|
|
28
|
+
recoveryEvidence: CurrentEvidence | null;
|
|
29
|
+
response: Readonly<{
|
|
30
|
+
body: Record<string, unknown>;
|
|
31
|
+
transport: ConstructRenewalConfigurationReceiptV2Options["transport"];
|
|
32
|
+
}> | null;
|
|
33
|
+
receipt: RenewalConfigurationReceiptV2 | null;
|
|
34
|
+
rawReceipt: ConstructRenewalConfigurationReceiptV2Options | null;
|
|
35
|
+
retention: ReturnType<typeof checkConfigureRetention> | null;
|
|
36
|
+
completion: { view: ConfigureCompletion; guard: () => void } | null;
|
|
37
|
+
};
|
|
38
|
+
const attempts = new WeakMap<object, ConfigureAttempt>();
|
|
39
|
+
const recoveries = new WeakMap<
|
|
40
|
+
object,
|
|
41
|
+
{ token: object; attempt: ConfigureAttempt }
|
|
42
|
+
>();
|
|
43
|
+
/** Only the original, internally constructed pair can create this private attempt. */
|
|
44
|
+
export function createConfigureWriteAttempt(token: object, pair: Pair) {
|
|
45
|
+
need(arguments.length === 2 && !attempts.has(token));
|
|
46
|
+
need(readOriginalConfigureWriteTransport(token) === pair);
|
|
47
|
+
const attempt: ConfigureAttempt = {
|
|
48
|
+
pair,
|
|
49
|
+
started: false,
|
|
50
|
+
settled: false,
|
|
51
|
+
recoveryReserved: false,
|
|
52
|
+
freshEvidence: null,
|
|
53
|
+
recoveryEvidence: null,
|
|
54
|
+
response: null,
|
|
55
|
+
receipt: null,
|
|
56
|
+
rawReceipt: null,
|
|
57
|
+
retention: null,
|
|
58
|
+
completion: null,
|
|
59
|
+
};
|
|
60
|
+
attempts.set(token, attempt);
|
|
61
|
+
return attempt;
|
|
62
|
+
}
|
|
63
|
+
export function readOriginalConfigureAttempt(token: object) {
|
|
64
|
+
need(arguments.length === 1);
|
|
65
|
+
const attempt = attempts.get(token);
|
|
66
|
+
need(attempt);
|
|
67
|
+
need(readOriginalConfigureWriteTransport(token) === attempt.pair);
|
|
68
|
+
return attempt;
|
|
69
|
+
}
|
|
70
|
+
/** Reserve original runtime custody synchronously, before any recovery await. */
|
|
71
|
+
export function takeOriginalConfigureRecovery(token: object, arity: number) {
|
|
72
|
+
const attempt = attempts.get(token);
|
|
73
|
+
need(attempt && !attempt.recoveryReserved);
|
|
74
|
+
attempt.recoveryReserved = true;
|
|
75
|
+
need(arity === 1);
|
|
76
|
+
need(readOriginalConfigureAttempt(token) === attempt);
|
|
77
|
+
need(
|
|
78
|
+
attempt.started &&
|
|
79
|
+
attempt.settled &&
|
|
80
|
+
attempt.freshEvidence !== null &&
|
|
81
|
+
attempt.completion === null &&
|
|
82
|
+
journalWorkForConfigureLineage(token).idle(),
|
|
83
|
+
);
|
|
84
|
+
const disposition = attempt.pair.transport.postDisposition();
|
|
85
|
+
need(disposition !== "NOT_STARTED" && disposition !== "PENDING");
|
|
86
|
+
need(
|
|
87
|
+
attempt.response !== null ||
|
|
88
|
+
attempt.receipt !== null ||
|
|
89
|
+
disposition === "REJECTED" ||
|
|
90
|
+
disposition === "FULFILLED_UNVERIFIED",
|
|
91
|
+
);
|
|
92
|
+
const recovery = Object.freeze({ operationalAuthority: false as const });
|
|
93
|
+
recoveries.set(recovery, { token, attempt });
|
|
94
|
+
return recovery;
|
|
95
|
+
}
|
|
96
|
+
export function readConfigureRecoveryAuthority(recovery: object) {
|
|
97
|
+
need(arguments.length === 1);
|
|
98
|
+
const current = recoveries.get(recovery);
|
|
99
|
+
need(current);
|
|
100
|
+
need(
|
|
101
|
+
readOriginalConfigureAttempt(current.token) === current.attempt &&
|
|
102
|
+
current.attempt.recoveryReserved &&
|
|
103
|
+
current.attempt.settled,
|
|
104
|
+
);
|
|
105
|
+
return current;
|
|
106
|
+
}
|
|
107
|
+
/** DATA only. Neither this view nor copied receipts can register recovery or ACK. */
|
|
108
|
+
export function readAdmittedConfigureWriteAttempt(token: object) {
|
|
109
|
+
need(arguments.length === 1);
|
|
110
|
+
const attempt = readOriginalConfigureAttempt(token);
|
|
111
|
+
const view = Object.freeze({
|
|
112
|
+
postDisposition: attempt.pair.transport.postDisposition(),
|
|
113
|
+
receiptKnown: attempt.receipt !== null,
|
|
114
|
+
receipt: attempt.receipt,
|
|
115
|
+
rawReceipt: attempt.rawReceipt,
|
|
116
|
+
returned: attempt.completion !== null,
|
|
117
|
+
operationalAuthority: false as const,
|
|
118
|
+
});
|
|
119
|
+
attempt.pair.guard();
|
|
120
|
+
return view;
|
|
121
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
1
2
|
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
2
3
|
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
3
4
|
import {
|
|
@@ -130,3 +131,65 @@ export async function assertConfigureWriteFrontier(
|
|
|
130
131
|
);
|
|
131
132
|
return events;
|
|
132
133
|
}
|
|
134
|
+
|
|
135
|
+
/** Validate an existing prefix without adopting journal DATA as provider custody. */
|
|
136
|
+
export async function assertConfigureRecoveryPrefix(
|
|
137
|
+
token: object,
|
|
138
|
+
expectedEvents: readonly unknown[],
|
|
139
|
+
known: {
|
|
140
|
+
receiptJSON: string;
|
|
141
|
+
receiptBinding: string;
|
|
142
|
+
retention: ReturnType<typeof checkConfigureRetention> | null;
|
|
143
|
+
} | null,
|
|
144
|
+
) {
|
|
145
|
+
const lineage = readConfigureLineage(token),
|
|
146
|
+
work = journalWorkForConfigureLineage(token);
|
|
147
|
+
const owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
148
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
149
|
+
readConfigureLineage(token);
|
|
150
|
+
requireConfigure(work.idle());
|
|
151
|
+
const reply = await owned(call);
|
|
152
|
+
readConfigureLineage(token);
|
|
153
|
+
requireConfigure(work.idle());
|
|
154
|
+
return reply;
|
|
155
|
+
}
|
|
156
|
+
const history: unknown = await checked(() =>
|
|
157
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
158
|
+
);
|
|
159
|
+
const own = object(history);
|
|
160
|
+
requireConfigure(!types.isProxy(own.events) && Array.isArray(own.events));
|
|
161
|
+
const events = captureConfigureHistory(
|
|
162
|
+
history,
|
|
163
|
+
lineage.reservation,
|
|
164
|
+
own.events.length,
|
|
165
|
+
);
|
|
166
|
+
requireConfigure(events.length <= expectedEvents.length);
|
|
167
|
+
const ack: unknown = await checked(() =>
|
|
168
|
+
lineage.journal.readProviderAcknowledgement(),
|
|
169
|
+
);
|
|
170
|
+
let retention: ReturnType<typeof checkConfigureRetention> | null = null;
|
|
171
|
+
if (ack !== null) {
|
|
172
|
+
requireConfigure(known !== null);
|
|
173
|
+
const reply = object(ack);
|
|
174
|
+
retention = checkConfigureRetention(
|
|
175
|
+
reply.retention,
|
|
176
|
+
lineage.reservation,
|
|
177
|
+
events,
|
|
178
|
+
known.receiptBinding,
|
|
179
|
+
);
|
|
180
|
+
if (known.retention !== null)
|
|
181
|
+
matchConfigureDATA(retention, known.retention);
|
|
182
|
+
matchConfigureDATA(ack, { retention, receiptJSON: known.receiptJSON });
|
|
183
|
+
} else
|
|
184
|
+
requireConfigure(
|
|
185
|
+
(known === null || known.retention === null) && events.length < 3,
|
|
186
|
+
);
|
|
187
|
+
const verified = await checked(() =>
|
|
188
|
+
assertConfigureWriteFrontier(
|
|
189
|
+
token,
|
|
190
|
+
expectedEvents.slice(0, events.length),
|
|
191
|
+
retention && known ? { ...known, retention } : null,
|
|
192
|
+
),
|
|
193
|
+
);
|
|
194
|
+
return { events: verified, retention };
|
|
195
|
+
}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import {
|
|
2
|
+
takeOriginalConfigureRecovery,
|
|
3
|
+
readConfigureRecoveryAuthority,
|
|
4
|
+
type ConfigureCompletion,
|
|
5
|
+
} from "./configureAttemptAuthority.js";
|
|
6
|
+
import { createAdmittedConfigureReplayTransport } from "../configure/transport.js";
|
|
7
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
8
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
9
|
+
import { createRecoveryConfigureEventCompiler } from "../c10/configureEvents.js";
|
|
10
|
+
import {
|
|
11
|
+
assertConfigureRecoveryPrefix,
|
|
12
|
+
assertConfigureWriteFrontier,
|
|
13
|
+
} from "./configureFrontier.js";
|
|
14
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
15
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
16
|
+
import {
|
|
17
|
+
verifyPreflightRecordDATA,
|
|
18
|
+
verifyCurrentPreflightDATA,
|
|
19
|
+
} from "../preflight/relations.js";
|
|
20
|
+
import { releasePreflightDATA } from "../preflight/output.js";
|
|
21
|
+
import {
|
|
22
|
+
projectRenewalConfigurationV2,
|
|
23
|
+
constructRenewalScheduleAttachmentReceiptV2,
|
|
24
|
+
constructRenewalConfigurationReceiptV2,
|
|
25
|
+
} from "../../../renewalV2/index.js";
|
|
26
|
+
import { need, seven } from "../configure/request.js";
|
|
27
|
+
import {
|
|
28
|
+
admitConfigureACK,
|
|
29
|
+
admitConfigureFailure,
|
|
30
|
+
configureControl,
|
|
31
|
+
} from "../configure/output.js";
|
|
32
|
+
import { withinConfigureRetention } from "../configure/replay.js";
|
|
33
|
+
import { freeze } from "../material/nodeKernel.js";
|
|
34
|
+
import { closed } from "../operations/types.js";
|
|
35
|
+
import {
|
|
36
|
+
checkConfigureRetention,
|
|
37
|
+
matchConfigureDATA,
|
|
38
|
+
} from "./configureJournalData.js";
|
|
39
|
+
import { equal } from "../../../renewalAggregate/shared.js";
|
|
40
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
41
|
+
import type { Bundle } from "../material/capture.js";
|
|
42
|
+
import type { PreflightRecord } from "../preflight/grammar.js";
|
|
43
|
+
|
|
44
|
+
function matchesBundle(
|
|
45
|
+
value: unknown,
|
|
46
|
+
record: PreflightRecord,
|
|
47
|
+
): value is Bundle {
|
|
48
|
+
return equal(value, {
|
|
49
|
+
...record.originalBundle,
|
|
50
|
+
wireSubscription: record.configuration.freshSubscription,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** One explicit same-live-Owner recovery reservation; no DATA registration input. */
|
|
54
|
+
export function captureAdmittedConfigureRecovery(token: object) {
|
|
55
|
+
const recovery = takeOriginalConfigureRecovery(token, arguments.length);
|
|
56
|
+
const { attempt } = readConfigureRecoveryAuthority(recovery),
|
|
57
|
+
source = attempt.pair;
|
|
58
|
+
const lineage = readConfigureLineage(token),
|
|
59
|
+
owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
60
|
+
const compiler = createRecoveryConfigureEventCompiler(recovery),
|
|
61
|
+
work = journalWorkForConfigureLineage(token);
|
|
62
|
+
let used = false,
|
|
63
|
+
closedActor = false;
|
|
64
|
+
let pair = source;
|
|
65
|
+
function guard() {
|
|
66
|
+
need(!closedActor);
|
|
67
|
+
readConfigureRecoveryAuthority(recovery);
|
|
68
|
+
pair.guard();
|
|
69
|
+
}
|
|
70
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
71
|
+
guard();
|
|
72
|
+
const reply = await owned(call);
|
|
73
|
+
guard();
|
|
74
|
+
return reply;
|
|
75
|
+
}
|
|
76
|
+
function retentionWindow() {
|
|
77
|
+
need(
|
|
78
|
+
withinConfigureRetention(
|
|
79
|
+
source.owner.check().nowSeconds,
|
|
80
|
+
source.record.request.firstDispatchedAt,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return Object.freeze({
|
|
85
|
+
async invoke() {
|
|
86
|
+
need(!used);
|
|
87
|
+
used = true;
|
|
88
|
+
need(arguments.length === 0);
|
|
89
|
+
let actualError: Error | null = null;
|
|
90
|
+
function providerFailure(
|
|
91
|
+
fact: NonNullable<ReturnType<typeof pair.capability.consumeReadCatch>>,
|
|
92
|
+
) {
|
|
93
|
+
const failure = admitConfigureFailure(
|
|
94
|
+
fact.phase,
|
|
95
|
+
fact.resource,
|
|
96
|
+
fact.ordinal,
|
|
97
|
+
source.record.request,
|
|
98
|
+
fact.diagnostics,
|
|
99
|
+
);
|
|
100
|
+
const error = Error("OWNED_CONFIGURE_PROVIDER_REJECTED");
|
|
101
|
+
Object.defineProperty(error, "failure", { value: failure });
|
|
102
|
+
return error;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
guard();
|
|
106
|
+
need(work.idle());
|
|
107
|
+
const original = source.record.request;
|
|
108
|
+
const dispatch = {
|
|
109
|
+
event: "dispatch",
|
|
110
|
+
stage: "configure",
|
|
111
|
+
request: original,
|
|
112
|
+
};
|
|
113
|
+
if (attempt.response === null && attempt.receipt === null) {
|
|
114
|
+
await checked(() => assertConfigureWriteFrontier(token, [dispatch]));
|
|
115
|
+
retentionWindow();
|
|
116
|
+
pair = createAdmittedConfigureReplayTransport(token);
|
|
117
|
+
const projected = await checked(() =>
|
|
118
|
+
projectRenewalConfigurationV2(source.record.configuration),
|
|
119
|
+
);
|
|
120
|
+
need(
|
|
121
|
+
projected.status === "projected_configure_request" &&
|
|
122
|
+
equal(projected, original),
|
|
123
|
+
);
|
|
124
|
+
const attachment = await checked(() =>
|
|
125
|
+
constructRenewalScheduleAttachmentReceiptV2(
|
|
126
|
+
source.record.configuration.attachReceipt,
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
const record = verifyPreflightRecordDATA(
|
|
130
|
+
source.retained,
|
|
131
|
+
projected,
|
|
132
|
+
attachment,
|
|
133
|
+
);
|
|
134
|
+
await checked(() => assertConfigureWriteFrontier(token, [dispatch]));
|
|
135
|
+
retentionWindow();
|
|
136
|
+
const reader = createSelectedRawAcquisition(
|
|
137
|
+
source.owner,
|
|
138
|
+
pair.transport.readTransport,
|
|
139
|
+
attachment.scheduleId,
|
|
140
|
+
);
|
|
141
|
+
const acquired = await checked(() =>
|
|
142
|
+
reader.acquire(record.configuration.preparation.expected),
|
|
143
|
+
);
|
|
144
|
+
if (!acquired.ok) {
|
|
145
|
+
const fact = pair.capability.consumeReadCatch();
|
|
146
|
+
if (fact) {
|
|
147
|
+
actualError = providerFailure(fact);
|
|
148
|
+
throw actualError;
|
|
149
|
+
}
|
|
150
|
+
return configureControl(
|
|
151
|
+
"not_dispatched",
|
|
152
|
+
"fresh_reads_unavailable",
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (!matchesBundle(acquired.bundle, record))
|
|
156
|
+
return configureControl(
|
|
157
|
+
"not_dispatched",
|
|
158
|
+
"preconfigure_baseline_changed",
|
|
159
|
+
);
|
|
160
|
+
const evidence = Object.freeze({
|
|
161
|
+
bundle: acquired.bundle,
|
|
162
|
+
schedule: acquired.schedule,
|
|
163
|
+
observedAt: acquired.observedAt,
|
|
164
|
+
});
|
|
165
|
+
verifyCurrentPreflightDATA(record, evidence);
|
|
166
|
+
const fresh = await checked(() =>
|
|
167
|
+
projectRenewalConfigurationV2({
|
|
168
|
+
...record.configuration,
|
|
169
|
+
freshSubscription: evidence.bundle.wireSubscription,
|
|
170
|
+
targetPrice: evidence.bundle.wireTargetPrice,
|
|
171
|
+
...(Object.prototype.hasOwnProperty.call(
|
|
172
|
+
record.configuration,
|
|
173
|
+
"billingCustomer",
|
|
174
|
+
)
|
|
175
|
+
? { billingCustomer: evidence.bundle.wireBillingCustomer }
|
|
176
|
+
: {}),
|
|
177
|
+
schedule: evidence.schedule,
|
|
178
|
+
observedAt: evidence.observedAt,
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
need(
|
|
182
|
+
fresh.status === "projected_configure_request" &&
|
|
183
|
+
equal(fresh, original),
|
|
184
|
+
);
|
|
185
|
+
need(
|
|
186
|
+
Reflect.apply(source.covers, source.entry, [
|
|
187
|
+
record,
|
|
188
|
+
evidence,
|
|
189
|
+
fresh,
|
|
190
|
+
]) === true,
|
|
191
|
+
);
|
|
192
|
+
guard();
|
|
193
|
+
releasePreflightDATA(record, evidence, fresh, projected, attachment);
|
|
194
|
+
attempt.recoveryEvidence = freeze(evidence);
|
|
195
|
+
await checked(() => compiler.dispatch(dispatch));
|
|
196
|
+
await checked(() => assertConfigureWriteFrontier(token, [dispatch]));
|
|
197
|
+
retentionWindow();
|
|
198
|
+
const reply = await checked(() => pair.transport.postConfigure());
|
|
199
|
+
if (pair.capability.consumeNotStarted(reply))
|
|
200
|
+
return configureControl("not_dispatched", "post_not_started");
|
|
201
|
+
const fact = pair.capability.consumePostCatch(reply);
|
|
202
|
+
if (fact) {
|
|
203
|
+
actualError = providerFailure(fact);
|
|
204
|
+
throw actualError;
|
|
205
|
+
}
|
|
206
|
+
if (reply.outcome !== "fulfilled_safe")
|
|
207
|
+
return configureControl("configure_unknown", "post_unverified");
|
|
208
|
+
attempt.response = Object.freeze({
|
|
209
|
+
body: reply.body,
|
|
210
|
+
transport: reply.transport,
|
|
211
|
+
});
|
|
212
|
+
} else {
|
|
213
|
+
need(attempt.response !== null);
|
|
214
|
+
const response = {
|
|
215
|
+
event: "response",
|
|
216
|
+
stage: "configure",
|
|
217
|
+
request: original,
|
|
218
|
+
...attempt.response,
|
|
219
|
+
};
|
|
220
|
+
const known = attempt.receipt
|
|
221
|
+
? {
|
|
222
|
+
receiptJSON: JSON.stringify(renewalSnapshot(attempt.receipt)),
|
|
223
|
+
receiptBinding: attempt.receipt.binding,
|
|
224
|
+
retention: attempt.retention,
|
|
225
|
+
}
|
|
226
|
+
: null;
|
|
227
|
+
const expected = [
|
|
228
|
+
dispatch,
|
|
229
|
+
response,
|
|
230
|
+
...(attempt.receipt
|
|
231
|
+
? [
|
|
232
|
+
{
|
|
233
|
+
event: "receipt",
|
|
234
|
+
stage: "configure",
|
|
235
|
+
request: original,
|
|
236
|
+
receipt: attempt.receipt,
|
|
237
|
+
},
|
|
238
|
+
]
|
|
239
|
+
: []),
|
|
240
|
+
];
|
|
241
|
+
const prefix = await checked(() =>
|
|
242
|
+
assertConfigureRecoveryPrefix(token, expected, known),
|
|
243
|
+
);
|
|
244
|
+
if (prefix.retention) attempt.retention = freeze(prefix.retention);
|
|
245
|
+
await checked(() => compiler.dispatch(dispatch));
|
|
246
|
+
}
|
|
247
|
+
const saved = attempt.response;
|
|
248
|
+
need(saved);
|
|
249
|
+
const response = {
|
|
250
|
+
event: "response",
|
|
251
|
+
stage: "configure",
|
|
252
|
+
request: original,
|
|
253
|
+
body: saved.body,
|
|
254
|
+
transport: saved.transport,
|
|
255
|
+
};
|
|
256
|
+
await checked(() => compiler.response(response));
|
|
257
|
+
if (attempt.receipt === null) {
|
|
258
|
+
const raw = Object.freeze({
|
|
259
|
+
configuration: source.record.configuration,
|
|
260
|
+
actualDispatch: seven(original),
|
|
261
|
+
providerSnapshot: saved.body,
|
|
262
|
+
transport: saved.transport,
|
|
263
|
+
});
|
|
264
|
+
const receipt = await checked(() =>
|
|
265
|
+
constructRenewalConfigurationReceiptV2(raw),
|
|
266
|
+
);
|
|
267
|
+
attempt.rawReceipt = freeze(raw);
|
|
268
|
+
attempt.receipt = freeze(receipt);
|
|
269
|
+
}
|
|
270
|
+
const receipt = attempt.receipt,
|
|
271
|
+
rawReceipt = attempt.rawReceipt;
|
|
272
|
+
need(rawReceipt);
|
|
273
|
+
const receiptJSON = JSON.stringify(renewalSnapshot(receipt));
|
|
274
|
+
const published = {
|
|
275
|
+
event: "receipt",
|
|
276
|
+
stage: "configure",
|
|
277
|
+
request: original,
|
|
278
|
+
receipt,
|
|
279
|
+
};
|
|
280
|
+
const prefix = await checked(() =>
|
|
281
|
+
assertConfigureRecoveryPrefix(
|
|
282
|
+
token,
|
|
283
|
+
[dispatch, response, published],
|
|
284
|
+
{
|
|
285
|
+
receiptJSON,
|
|
286
|
+
receiptBinding: receipt.binding,
|
|
287
|
+
retention: attempt.retention,
|
|
288
|
+
},
|
|
289
|
+
),
|
|
290
|
+
);
|
|
291
|
+
const retained: unknown = await checked(() => work.retain(receiptJSON));
|
|
292
|
+
const retention = checkConfigureRetention(
|
|
293
|
+
retained,
|
|
294
|
+
lineage.reservation,
|
|
295
|
+
prefix.events,
|
|
296
|
+
receipt.binding,
|
|
297
|
+
);
|
|
298
|
+
if (attempt.retention !== null)
|
|
299
|
+
matchConfigureDATA(retention, attempt.retention);
|
|
300
|
+
attempt.retention = freeze(retention);
|
|
301
|
+
const known = {
|
|
302
|
+
receiptJSON,
|
|
303
|
+
receiptBinding: receipt.binding,
|
|
304
|
+
retention,
|
|
305
|
+
};
|
|
306
|
+
await checked(() =>
|
|
307
|
+
assertConfigureRecoveryPrefix(
|
|
308
|
+
token,
|
|
309
|
+
[dispatch, response, published],
|
|
310
|
+
known,
|
|
311
|
+
),
|
|
312
|
+
);
|
|
313
|
+
const output = admitConfigureACK(source.record, rawReceipt, receipt);
|
|
314
|
+
const returned = closed(output, [
|
|
315
|
+
"status",
|
|
316
|
+
"originalRecord",
|
|
317
|
+
"rawReceipt",
|
|
318
|
+
"receipt",
|
|
319
|
+
"operationalAuthority",
|
|
320
|
+
]);
|
|
321
|
+
await checked(() => compiler.receipt(published));
|
|
322
|
+
await checked(() =>
|
|
323
|
+
assertConfigureWriteFrontier(
|
|
324
|
+
token,
|
|
325
|
+
[dispatch, response, published],
|
|
326
|
+
known,
|
|
327
|
+
),
|
|
328
|
+
);
|
|
329
|
+
const view: ConfigureCompletion = Object.freeze({
|
|
330
|
+
output,
|
|
331
|
+
receipt: returned.receipt,
|
|
332
|
+
rawReceipt: returned.rawReceipt,
|
|
333
|
+
acknowledgement: source.preflight.acknowledgement,
|
|
334
|
+
originalEntry: source.preflight.originalEntry,
|
|
335
|
+
configureEntry: source.entry,
|
|
336
|
+
coversConfigure: source.covers,
|
|
337
|
+
operationalAuthority: false,
|
|
338
|
+
});
|
|
339
|
+
guard();
|
|
340
|
+
source.capability.discardFulfilledQuarantine();
|
|
341
|
+
pair.capability.discardFulfilledQuarantine();
|
|
342
|
+
attempt.completion = { view, guard };
|
|
343
|
+
return output;
|
|
344
|
+
} catch (error) {
|
|
345
|
+
let live = false;
|
|
346
|
+
try {
|
|
347
|
+
guard();
|
|
348
|
+
live = true;
|
|
349
|
+
} catch {
|
|
350
|
+
/* Closed custody allows no provider reflection. */
|
|
351
|
+
}
|
|
352
|
+
closedActor = true;
|
|
353
|
+
if (live && actualError === error) throw error;
|
|
354
|
+
return configureControl(
|
|
355
|
+
"configure_unknown",
|
|
356
|
+
live ? "recovery_unverified" : "owner_closed_after_post",
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createConfigureWriteAttempt,
|
|
3
|
+
type ConfigureCompletion,
|
|
4
|
+
} from "./configureAttemptAuthority.js";
|
|
5
|
+
export { readAdmittedConfigureAcknowledgement } from "./configureAcknowledgement.js";
|
|
6
|
+
export { readAdmittedConfigureWriteAttempt } from "./configureAttemptAuthority.js";
|
|
1
7
|
import { freeze } from "../material/nodeKernel.js";
|
|
2
8
|
import { closed as closedFields } from "../operations/types.js";
|
|
3
9
|
import { readConfigureLineage } from "./configureLineage.js";
|
|
@@ -42,29 +48,11 @@ function matchesCurrentBundle(
|
|
|
42
48
|
});
|
|
43
49
|
}
|
|
44
50
|
type Pair = ReturnType<typeof createAdmittedConfigureWriteTransport>;
|
|
45
|
-
type ACK = ReturnType<typeof admitConfigureACK>;
|
|
46
|
-
type Completion = Readonly<{
|
|
47
|
-
output: ACK;
|
|
48
|
-
receipt: unknown;
|
|
49
|
-
rawReceipt: unknown;
|
|
50
|
-
acknowledgement: Pair["preflight"]["acknowledgement"];
|
|
51
|
-
originalEntry: unknown;
|
|
52
|
-
configureEntry: unknown;
|
|
53
|
-
coversConfigure: unknown;
|
|
54
|
-
operationalAuthority: false;
|
|
55
|
-
}>;
|
|
56
|
-
type Attempt = { pair: Pair; receipt: unknown; rawReceipt: unknown };
|
|
57
|
-
const attempts = new WeakMap<object, Attempt>();
|
|
58
|
-
const completions = new WeakMap<
|
|
59
|
-
object,
|
|
60
|
-
{ view: Completion; guard: () => void }
|
|
61
|
-
>();
|
|
62
51
|
/** One fixed initial configure attempt. No replay, caller frame or output registration. */
|
|
63
52
|
export function captureAdmittedConfigureWrite(token: object) {
|
|
64
53
|
const pair = createAdmittedConfigureWriteTransport(token);
|
|
65
54
|
need(arguments.length === 1);
|
|
66
|
-
const attempt
|
|
67
|
-
attempts.set(token, attempt);
|
|
55
|
+
const attempt = createConfigureWriteAttempt(token, pair);
|
|
68
56
|
const lineage = readConfigureLineage(token),
|
|
69
57
|
owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
70
58
|
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
@@ -101,6 +89,7 @@ export function captureAdmittedConfigureWrite(token: object) {
|
|
|
101
89
|
need(!used);
|
|
102
90
|
used = true;
|
|
103
91
|
need(arguments.length === 0);
|
|
92
|
+
attempt.started = true;
|
|
104
93
|
let actualError: Error | null = null;
|
|
105
94
|
try {
|
|
106
95
|
guard();
|
|
@@ -173,6 +162,7 @@ export function captureAdmittedConfigureWrite(token: object) {
|
|
|
173
162
|
);
|
|
174
163
|
guard();
|
|
175
164
|
releasePreflightDATA(record, evidence, fresh, original, attachment);
|
|
165
|
+
attempt.freshEvidence = freeze(evidence);
|
|
176
166
|
await checked(() => assertConfigurePreflightFrontier(token));
|
|
177
167
|
const dispatch = {
|
|
178
168
|
event: "dispatch",
|
|
@@ -191,6 +181,10 @@ export function captureAdmittedConfigureWrite(token: object) {
|
|
|
191
181
|
}
|
|
192
182
|
if (reply.outcome !== "fulfilled_safe")
|
|
193
183
|
return configureControl("configure_unknown", "post_unverified");
|
|
184
|
+
attempt.response = Object.freeze({
|
|
185
|
+
body: reply.body,
|
|
186
|
+
transport: reply.transport,
|
|
187
|
+
});
|
|
194
188
|
const response = {
|
|
195
189
|
event: "response",
|
|
196
190
|
stage: "configure",
|
|
@@ -224,6 +218,7 @@ export function captureAdmittedConfigureWrite(token: object) {
|
|
|
224
218
|
events,
|
|
225
219
|
receipt.binding,
|
|
226
220
|
);
|
|
221
|
+
attempt.retention = freeze(retention);
|
|
227
222
|
const known = {
|
|
228
223
|
receiptJSON,
|
|
229
224
|
receiptBinding: receipt.binding,
|
|
@@ -254,7 +249,7 @@ export function captureAdmittedConfigureWrite(token: object) {
|
|
|
254
249
|
known,
|
|
255
250
|
),
|
|
256
251
|
);
|
|
257
|
-
const view:
|
|
252
|
+
const view: ConfigureCompletion = Object.freeze({
|
|
258
253
|
output,
|
|
259
254
|
receipt: returned.receipt,
|
|
260
255
|
rawReceipt: returned.rawReceipt,
|
|
@@ -267,7 +262,7 @@ export function captureAdmittedConfigureWrite(token: object) {
|
|
|
267
262
|
guard();
|
|
268
263
|
// No callback, reflection or Owner sample follows the final gate before discard.
|
|
269
264
|
pair.capability.discardFulfilledQuarantine();
|
|
270
|
-
|
|
265
|
+
attempt.completion = { view, guard };
|
|
271
266
|
return output;
|
|
272
267
|
} catch (error) {
|
|
273
268
|
let live = false;
|
|
@@ -285,33 +280,9 @@ export function captureAdmittedConfigureWrite(token: object) {
|
|
|
285
280
|
live ? "post_unverified" : "owner_closed_after_post",
|
|
286
281
|
);
|
|
287
282
|
throw error;
|
|
283
|
+
} finally {
|
|
284
|
+
attempt.settled = true;
|
|
288
285
|
}
|
|
289
286
|
},
|
|
290
287
|
});
|
|
291
288
|
}
|
|
292
|
-
/** Actual returned ACK custody only, without accepting any copied receipt or output. */
|
|
293
|
-
export function readAdmittedConfigureAcknowledgement(token: object) {
|
|
294
|
-
need(arguments.length === 1);
|
|
295
|
-
const completed = completions.get(token);
|
|
296
|
-
need(completed);
|
|
297
|
-
completed.guard();
|
|
298
|
-
return completed.view;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/** Private live attempt DATA, never an ACK registration or replay grant. */
|
|
302
|
-
export function readAdmittedConfigureWriteAttempt(token: object) {
|
|
303
|
-
need(arguments.length === 1);
|
|
304
|
-
const attempt = attempts.get(token);
|
|
305
|
-
need(attempt);
|
|
306
|
-
attempt.pair.guard();
|
|
307
|
-
const view = Object.freeze({
|
|
308
|
-
postDisposition: attempt.pair.transport.postDisposition(),
|
|
309
|
-
receiptKnown: attempt.receipt !== null,
|
|
310
|
-
receipt: attempt.receipt,
|
|
311
|
-
rawReceipt: attempt.rawReceipt,
|
|
312
|
-
returned: completions.has(token),
|
|
313
|
-
operationalAuthority: false as const,
|
|
314
|
-
});
|
|
315
|
-
attempt.pair.guard();
|
|
316
|
-
return view;
|
|
317
|
-
}
|