@fantastic.dev/better-stripe 0.104.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 +12 -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 +300 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +44 -2
- 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 +47 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +79 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -1
- 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/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 +7 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +209 -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/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +27 -27
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- 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/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +99 -4
- 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 +64 -2
- 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 +155 -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/configureRecovery.ts +361 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +288 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWriteFactory.ts +88 -0
- 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
- 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 +85 -2
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createConfigureWriteAttempt,
|
|
3
|
+
type ConfigureCompletion,
|
|
4
|
+
} from "./configureAttemptAuthority.js";
|
|
5
|
+
export { readAdmittedConfigureAcknowledgement } from "./configureAcknowledgement.js";
|
|
6
|
+
export { readAdmittedConfigureWriteAttempt } from "./configureAttemptAuthority.js";
|
|
7
|
+
import { freeze } from "../material/nodeKernel.js";
|
|
8
|
+
import { closed as closedFields } from "../operations/types.js";
|
|
9
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
10
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
11
|
+
import { createAdmittedConfigureWriteTransport } from "../configure/transport.js";
|
|
12
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
13
|
+
import { createAdmittedConfigureEventCompiler } from "../c10/configureEvents.js";
|
|
14
|
+
import {
|
|
15
|
+
assertConfigurePreflightFrontier,
|
|
16
|
+
assertConfigureWriteFrontier,
|
|
17
|
+
} from "./configureFrontier.js";
|
|
18
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
19
|
+
import { checkConfigureRetention } from "./configureJournalData.js";
|
|
20
|
+
import {
|
|
21
|
+
projectRenewalConfigurationV2,
|
|
22
|
+
constructRenewalScheduleAttachmentReceiptV2,
|
|
23
|
+
constructRenewalConfigurationReceiptV2,
|
|
24
|
+
} from "../../../renewalV2/index.js";
|
|
25
|
+
import {
|
|
26
|
+
verifyPreflightRecordDATA,
|
|
27
|
+
verifyCurrentPreflightDATA,
|
|
28
|
+
} from "../preflight/relations.js";
|
|
29
|
+
import { releasePreflightDATA } from "../preflight/output.js";
|
|
30
|
+
import {
|
|
31
|
+
admitConfigureACK,
|
|
32
|
+
admitConfigureFailure,
|
|
33
|
+
configureControl,
|
|
34
|
+
} from "../configure/output.js";
|
|
35
|
+
import { need, seven, stop } from "../configure/request.js";
|
|
36
|
+
import { equal } from "../../../renewalAggregate/shared.js";
|
|
37
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
38
|
+
import type { Bundle } from "../material/capture.js";
|
|
39
|
+
import type { PreflightRecord } from "../preflight/grammar.js";
|
|
40
|
+
|
|
41
|
+
function matchesCurrentBundle(
|
|
42
|
+
value: unknown,
|
|
43
|
+
record: PreflightRecord,
|
|
44
|
+
): value is Bundle {
|
|
45
|
+
return equal(value, {
|
|
46
|
+
...record.originalBundle,
|
|
47
|
+
wireSubscription: record.configuration.freshSubscription,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
type Pair = ReturnType<typeof createAdmittedConfigureWriteTransport>;
|
|
51
|
+
/** One fixed initial configure attempt. No replay, caller frame or output registration. */
|
|
52
|
+
export function captureAdmittedConfigureWrite(token: object) {
|
|
53
|
+
const pair = createAdmittedConfigureWriteTransport(token);
|
|
54
|
+
need(arguments.length === 1);
|
|
55
|
+
const attempt = createConfigureWriteAttempt(token, pair);
|
|
56
|
+
const lineage = readConfigureLineage(token),
|
|
57
|
+
owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
58
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
59
|
+
work = journalWorkForConfigureLineage(token);
|
|
60
|
+
let used = false,
|
|
61
|
+
closed = false,
|
|
62
|
+
receiptKnown = false;
|
|
63
|
+
function guard() {
|
|
64
|
+
need(!closed);
|
|
65
|
+
pair.guard();
|
|
66
|
+
}
|
|
67
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
68
|
+
guard();
|
|
69
|
+
const result = await owned(call);
|
|
70
|
+
guard();
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function providerFailure(
|
|
74
|
+
fact: NonNullable<ReturnType<Pair["capability"]["consumeReadCatch"]>>,
|
|
75
|
+
) {
|
|
76
|
+
const failure = admitConfigureFailure(
|
|
77
|
+
fact.phase,
|
|
78
|
+
fact.resource,
|
|
79
|
+
fact.ordinal,
|
|
80
|
+
pair.record.request,
|
|
81
|
+
fact.diagnostics,
|
|
82
|
+
);
|
|
83
|
+
const error = Error("OWNED_CONFIGURE_PROVIDER_REJECTED");
|
|
84
|
+
Object.defineProperty(error, "failure", { value: failure });
|
|
85
|
+
return error;
|
|
86
|
+
}
|
|
87
|
+
return Object.freeze({
|
|
88
|
+
async invoke() {
|
|
89
|
+
need(!used);
|
|
90
|
+
used = true;
|
|
91
|
+
need(arguments.length === 0);
|
|
92
|
+
attempt.started = true;
|
|
93
|
+
let actualError: Error | null = null;
|
|
94
|
+
try {
|
|
95
|
+
guard();
|
|
96
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
97
|
+
const original = await checked(() =>
|
|
98
|
+
projectRenewalConfigurationV2(pair.record.configuration),
|
|
99
|
+
);
|
|
100
|
+
need(original.status === "projected_configure_request");
|
|
101
|
+
const attachment = await checked(() =>
|
|
102
|
+
constructRenewalScheduleAttachmentReceiptV2(
|
|
103
|
+
pair.record.configuration.attachReceipt,
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
const record = verifyPreflightRecordDATA(
|
|
107
|
+
pair.retained,
|
|
108
|
+
original,
|
|
109
|
+
attachment,
|
|
110
|
+
);
|
|
111
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
112
|
+
const reader = createSelectedRawAcquisition(
|
|
113
|
+
pair.owner,
|
|
114
|
+
pair.transport.readTransport,
|
|
115
|
+
attachment.scheduleId,
|
|
116
|
+
);
|
|
117
|
+
const acquired = await checked(() =>
|
|
118
|
+
reader.acquire(record.configuration.preparation.expected),
|
|
119
|
+
);
|
|
120
|
+
if (!acquired.ok) {
|
|
121
|
+
const fact = pair.capability.consumeReadCatch();
|
|
122
|
+
if (fact) {
|
|
123
|
+
actualError = providerFailure(fact);
|
|
124
|
+
throw actualError;
|
|
125
|
+
}
|
|
126
|
+
return stop();
|
|
127
|
+
}
|
|
128
|
+
if (!matchesCurrentBundle(acquired.bundle, record))
|
|
129
|
+
return configureControl(
|
|
130
|
+
"not_dispatched",
|
|
131
|
+
"preconfigure_baseline_changed",
|
|
132
|
+
);
|
|
133
|
+
const evidence = Object.freeze({
|
|
134
|
+
bundle: acquired.bundle,
|
|
135
|
+
schedule: acquired.schedule,
|
|
136
|
+
observedAt: acquired.observedAt,
|
|
137
|
+
});
|
|
138
|
+
verifyCurrentPreflightDATA(record, evidence);
|
|
139
|
+
const fresh = await checked(() =>
|
|
140
|
+
projectRenewalConfigurationV2({
|
|
141
|
+
...record.configuration,
|
|
142
|
+
freshSubscription: evidence.bundle.wireSubscription,
|
|
143
|
+
targetPrice: evidence.bundle.wireTargetPrice,
|
|
144
|
+
...(Object.prototype.hasOwnProperty.call(
|
|
145
|
+
record.configuration,
|
|
146
|
+
"billingCustomer",
|
|
147
|
+
)
|
|
148
|
+
? { billingCustomer: evidence.bundle.wireBillingCustomer }
|
|
149
|
+
: {}),
|
|
150
|
+
schedule: evidence.schedule,
|
|
151
|
+
observedAt: evidence.observedAt,
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
need(
|
|
155
|
+
fresh.status === "projected_configure_request" &&
|
|
156
|
+
equal(fresh, original) &&
|
|
157
|
+
equal(fresh, record.request),
|
|
158
|
+
);
|
|
159
|
+
need(
|
|
160
|
+
Reflect.apply(pair.covers, pair.entry, [record, evidence, fresh]) ===
|
|
161
|
+
true,
|
|
162
|
+
);
|
|
163
|
+
guard();
|
|
164
|
+
releasePreflightDATA(record, evidence, fresh, original, attachment);
|
|
165
|
+
attempt.freshEvidence = freeze(evidence);
|
|
166
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
167
|
+
const dispatch = {
|
|
168
|
+
event: "dispatch",
|
|
169
|
+
stage: "configure",
|
|
170
|
+
request: original,
|
|
171
|
+
};
|
|
172
|
+
await checked(() => compiler.dispatch(dispatch));
|
|
173
|
+
await checked(() => assertConfigureWriteFrontier(token, [dispatch]));
|
|
174
|
+
const reply = await checked(() => pair.transport.postConfigure());
|
|
175
|
+
if (pair.capability.consumeNotStarted(reply))
|
|
176
|
+
return configureControl("not_dispatched", "post_not_started");
|
|
177
|
+
const fact = pair.capability.consumePostCatch(reply);
|
|
178
|
+
if (fact) {
|
|
179
|
+
actualError = providerFailure(fact);
|
|
180
|
+
throw actualError;
|
|
181
|
+
}
|
|
182
|
+
if (reply.outcome !== "fulfilled_safe")
|
|
183
|
+
return configureControl("configure_unknown", "post_unverified");
|
|
184
|
+
attempt.response = Object.freeze({
|
|
185
|
+
body: reply.body,
|
|
186
|
+
transport: reply.transport,
|
|
187
|
+
});
|
|
188
|
+
const response = {
|
|
189
|
+
event: "response",
|
|
190
|
+
stage: "configure",
|
|
191
|
+
request: original,
|
|
192
|
+
body: reply.body,
|
|
193
|
+
transport: reply.transport,
|
|
194
|
+
};
|
|
195
|
+
await checked(() => compiler.response(response));
|
|
196
|
+
const rawReceipt = Object.freeze({
|
|
197
|
+
configuration: record.configuration,
|
|
198
|
+
actualDispatch: seven(original),
|
|
199
|
+
providerSnapshot: reply.body,
|
|
200
|
+
transport: reply.transport,
|
|
201
|
+
});
|
|
202
|
+
const receipt = await checked(() =>
|
|
203
|
+
constructRenewalConfigurationReceiptV2(rawReceipt),
|
|
204
|
+
);
|
|
205
|
+
// Known receipt closes this once-only attempt before output admission or persistence.
|
|
206
|
+
receiptKnown = true;
|
|
207
|
+
attempt.receipt = freeze(receipt);
|
|
208
|
+
attempt.rawReceipt = freeze(rawReceipt);
|
|
209
|
+
guard();
|
|
210
|
+
const events = await checked(() =>
|
|
211
|
+
assertConfigureWriteFrontier(token, [dispatch, response]),
|
|
212
|
+
);
|
|
213
|
+
const receiptJSON = JSON.stringify(renewalSnapshot(receipt));
|
|
214
|
+
const retained: unknown = await checked(() => work.retain(receiptJSON));
|
|
215
|
+
const retention = checkConfigureRetention(
|
|
216
|
+
retained,
|
|
217
|
+
lineage.reservation,
|
|
218
|
+
events,
|
|
219
|
+
receipt.binding,
|
|
220
|
+
);
|
|
221
|
+
attempt.retention = freeze(retention);
|
|
222
|
+
const known = {
|
|
223
|
+
receiptJSON,
|
|
224
|
+
receiptBinding: receipt.binding,
|
|
225
|
+
retention,
|
|
226
|
+
};
|
|
227
|
+
await checked(() =>
|
|
228
|
+
assertConfigureWriteFrontier(token, [dispatch, response], known),
|
|
229
|
+
);
|
|
230
|
+
const output = admitConfigureACK(record, rawReceipt, receipt);
|
|
231
|
+
const returned = closedFields(output, [
|
|
232
|
+
"status",
|
|
233
|
+
"originalRecord",
|
|
234
|
+
"rawReceipt",
|
|
235
|
+
"receipt",
|
|
236
|
+
"operationalAuthority",
|
|
237
|
+
]);
|
|
238
|
+
const published = {
|
|
239
|
+
event: "receipt",
|
|
240
|
+
stage: "configure",
|
|
241
|
+
request: original,
|
|
242
|
+
receipt,
|
|
243
|
+
};
|
|
244
|
+
await checked(() => compiler.receipt(published));
|
|
245
|
+
await checked(() =>
|
|
246
|
+
assertConfigureWriteFrontier(
|
|
247
|
+
token,
|
|
248
|
+
[dispatch, response, published],
|
|
249
|
+
known,
|
|
250
|
+
),
|
|
251
|
+
);
|
|
252
|
+
const view: ConfigureCompletion = Object.freeze({
|
|
253
|
+
output,
|
|
254
|
+
receipt: returned.receipt,
|
|
255
|
+
rawReceipt: returned.rawReceipt,
|
|
256
|
+
acknowledgement: pair.preflight.acknowledgement,
|
|
257
|
+
originalEntry: pair.preflight.originalEntry,
|
|
258
|
+
configureEntry: pair.entry,
|
|
259
|
+
coversConfigure: pair.covers,
|
|
260
|
+
operationalAuthority: false,
|
|
261
|
+
});
|
|
262
|
+
guard();
|
|
263
|
+
// No callback, reflection or Owner sample follows the final gate before discard.
|
|
264
|
+
pair.capability.discardFulfilledQuarantine();
|
|
265
|
+
attempt.completion = { view, guard };
|
|
266
|
+
return output;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
let live = false;
|
|
269
|
+
try {
|
|
270
|
+
guard();
|
|
271
|
+
live = true;
|
|
272
|
+
} catch {
|
|
273
|
+
/* No reflection on provider data after closure. */
|
|
274
|
+
}
|
|
275
|
+
closed = true;
|
|
276
|
+
if (live && actualError === error) throw error;
|
|
277
|
+
if (pair.transport.postDisposition() !== "NOT_STARTED" || receiptKnown)
|
|
278
|
+
return configureControl(
|
|
279
|
+
"configure_unknown",
|
|
280
|
+
live ? "post_unverified" : "owner_closed_after_post",
|
|
281
|
+
);
|
|
282
|
+
throw error;
|
|
283
|
+
} finally {
|
|
284
|
+
attempt.settled = true;
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
}
|