@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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
2
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
3
|
+
import { assertConfigurePreflightFrontier } from "./configureFrontier.js";
|
|
4
|
+
import { createAdmittedConfigureReadTransport } from "../operations/configureReadTransport.js";
|
|
5
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
6
|
+
import {
|
|
7
|
+
projectRenewalConfigurationV2,
|
|
8
|
+
constructRenewalScheduleAttachmentReceiptV2,
|
|
9
|
+
} from "../../../renewalV2/index.js";
|
|
10
|
+
import {
|
|
11
|
+
verifyPreflightRecordDATA,
|
|
12
|
+
verifyCurrentPreflightDATA,
|
|
13
|
+
} from "../preflight/relations.js";
|
|
14
|
+
import { releasePreflightDATA } from "../preflight/output.js";
|
|
15
|
+
import { requireConfigure } from "./configureJournalData.js";
|
|
16
|
+
import { equal } from "../../../renewalAggregate/shared.js";
|
|
17
|
+
import type { PreflightOutput, PreflightRecord } from "../preflight/grammar.js";
|
|
18
|
+
import type { Bundle } from "../material/capture.js";
|
|
19
|
+
|
|
20
|
+
function matchesCurrentBundle(
|
|
21
|
+
value: unknown,
|
|
22
|
+
record: PreflightRecord,
|
|
23
|
+
): value is Bundle {
|
|
24
|
+
return equal(value, {
|
|
25
|
+
...record.originalBundle,
|
|
26
|
+
wireSubscription: record.configuration.freshSubscription,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const captures = new WeakSet<object>();
|
|
30
|
+
type PreflightView = Readonly<{
|
|
31
|
+
output: PreflightOutput;
|
|
32
|
+
originalEntry: unknown;
|
|
33
|
+
preflightEntry: unknown;
|
|
34
|
+
coversPreflight: unknown;
|
|
35
|
+
acknowledgement: ReturnType<
|
|
36
|
+
typeof createAdmittedConfigureReadTransport
|
|
37
|
+
>["acknowledgement"];
|
|
38
|
+
operationalAuthority: false;
|
|
39
|
+
}>;
|
|
40
|
+
const completions = new WeakMap<
|
|
41
|
+
object,
|
|
42
|
+
{ view: PreflightView; guard: () => void }
|
|
43
|
+
>();
|
|
44
|
+
/** Actual admitted child only. This readonly consistency actor grants no write. */
|
|
45
|
+
export function captureAdmittedConfigurePreflight(token: object) {
|
|
46
|
+
requireConfigure(
|
|
47
|
+
typeof token === "object" && token !== null && !captures.has(token),
|
|
48
|
+
);
|
|
49
|
+
captures.add(token);
|
|
50
|
+
requireConfigure(arguments.length === 1);
|
|
51
|
+
const pair = createAdmittedConfigureReadTransport(token);
|
|
52
|
+
const lineage = readConfigureLineage(token),
|
|
53
|
+
owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
54
|
+
let used = false,
|
|
55
|
+
closed = false;
|
|
56
|
+
function guard() {
|
|
57
|
+
requireConfigure(!closed);
|
|
58
|
+
try {
|
|
59
|
+
pair.guard();
|
|
60
|
+
} catch (error) {
|
|
61
|
+
closed = true;
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
66
|
+
guard();
|
|
67
|
+
const result = await owned(call);
|
|
68
|
+
guard();
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
const actor = Object.freeze({
|
|
72
|
+
async invoke() {
|
|
73
|
+
requireConfigure(!used);
|
|
74
|
+
used = true;
|
|
75
|
+
requireConfigure(arguments.length === 0);
|
|
76
|
+
try {
|
|
77
|
+
guard();
|
|
78
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
79
|
+
const original = await checked(() =>
|
|
80
|
+
projectRenewalConfigurationV2(pair.retained.configuration),
|
|
81
|
+
);
|
|
82
|
+
requireConfigure(original.status === "projected_configure_request");
|
|
83
|
+
const ack = await checked(() =>
|
|
84
|
+
constructRenewalScheduleAttachmentReceiptV2(
|
|
85
|
+
pair.retained.configuration.attachReceipt,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
const record = verifyPreflightRecordDATA(pair.retained, original, ack);
|
|
89
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
90
|
+
guard();
|
|
91
|
+
const reader = createSelectedRawAcquisition(
|
|
92
|
+
lineage.owner,
|
|
93
|
+
pair.readTransport,
|
|
94
|
+
pair.scheduleId,
|
|
95
|
+
);
|
|
96
|
+
const acquired = await checked(() =>
|
|
97
|
+
reader.acquire(record.configuration.preparation.expected),
|
|
98
|
+
);
|
|
99
|
+
requireConfigure(acquired.ok);
|
|
100
|
+
requireConfigure(matchesCurrentBundle(acquired.bundle, record));
|
|
101
|
+
const evidence = Object.freeze({
|
|
102
|
+
bundle: acquired.bundle,
|
|
103
|
+
schedule: acquired.schedule,
|
|
104
|
+
observedAt: acquired.observedAt,
|
|
105
|
+
});
|
|
106
|
+
verifyCurrentPreflightDATA(record, evidence);
|
|
107
|
+
guard();
|
|
108
|
+
const configuration = {
|
|
109
|
+
...record.configuration,
|
|
110
|
+
freshSubscription: evidence.bundle.wireSubscription,
|
|
111
|
+
targetPrice: evidence.bundle.wireTargetPrice,
|
|
112
|
+
...(Object.prototype.hasOwnProperty.call(
|
|
113
|
+
record.configuration,
|
|
114
|
+
"billingCustomer",
|
|
115
|
+
)
|
|
116
|
+
? { billingCustomer: evidence.bundle.wireBillingCustomer }
|
|
117
|
+
: {}),
|
|
118
|
+
schedule: evidence.schedule,
|
|
119
|
+
observedAt: evidence.observedAt,
|
|
120
|
+
};
|
|
121
|
+
const fresh = await checked(() =>
|
|
122
|
+
projectRenewalConfigurationV2(configuration),
|
|
123
|
+
);
|
|
124
|
+
requireConfigure(
|
|
125
|
+
fresh.status === "projected_configure_request" &&
|
|
126
|
+
equal(fresh, original) &&
|
|
127
|
+
equal(fresh, record.request),
|
|
128
|
+
);
|
|
129
|
+
requireConfigure(
|
|
130
|
+
Reflect.apply(pair.covers, pair.entry, [record, evidence, fresh]) ===
|
|
131
|
+
true,
|
|
132
|
+
);
|
|
133
|
+
guard();
|
|
134
|
+
const output = releasePreflightDATA(
|
|
135
|
+
record,
|
|
136
|
+
evidence,
|
|
137
|
+
fresh,
|
|
138
|
+
original,
|
|
139
|
+
ack,
|
|
140
|
+
);
|
|
141
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
142
|
+
guard();
|
|
143
|
+
completions.set(token, {
|
|
144
|
+
guard,
|
|
145
|
+
view: Object.freeze({
|
|
146
|
+
output,
|
|
147
|
+
originalEntry: pair.acknowledgement.originalEntry,
|
|
148
|
+
preflightEntry: pair.entry,
|
|
149
|
+
coversPreflight: pair.covers,
|
|
150
|
+
acknowledgement: pair.acknowledgement,
|
|
151
|
+
operationalAuthority: false as const,
|
|
152
|
+
}),
|
|
153
|
+
});
|
|
154
|
+
return output;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
closed = true;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
return actor;
|
|
162
|
+
}
|
|
163
|
+
/** Actual completed return identity; copied output is never a registration input. */
|
|
164
|
+
export function readAdmittedConfigurePreflight(token: object) {
|
|
165
|
+
requireConfigure(arguments.length === 1);
|
|
166
|
+
const completed = completions.get(token);
|
|
167
|
+
requireConfigure(completed);
|
|
168
|
+
completed.guard();
|
|
169
|
+
return completed.view;
|
|
170
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { freeze } from "../material/nodeKernel.js";
|
|
2
|
+
import { closed as closedFields } from "../operations/types.js";
|
|
3
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
4
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
|
+
import { createAdmittedConfigureWriteTransport } from "../configure/transport.js";
|
|
6
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
7
|
+
import { createAdmittedConfigureEventCompiler } from "../c10/configureEvents.js";
|
|
8
|
+
import {
|
|
9
|
+
assertConfigurePreflightFrontier,
|
|
10
|
+
assertConfigureWriteFrontier,
|
|
11
|
+
} from "./configureFrontier.js";
|
|
12
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
13
|
+
import { checkConfigureRetention } from "./configureJournalData.js";
|
|
14
|
+
import {
|
|
15
|
+
projectRenewalConfigurationV2,
|
|
16
|
+
constructRenewalScheduleAttachmentReceiptV2,
|
|
17
|
+
constructRenewalConfigurationReceiptV2,
|
|
18
|
+
} from "../../../renewalV2/index.js";
|
|
19
|
+
import {
|
|
20
|
+
verifyPreflightRecordDATA,
|
|
21
|
+
verifyCurrentPreflightDATA,
|
|
22
|
+
} from "../preflight/relations.js";
|
|
23
|
+
import { releasePreflightDATA } from "../preflight/output.js";
|
|
24
|
+
import {
|
|
25
|
+
admitConfigureACK,
|
|
26
|
+
admitConfigureFailure,
|
|
27
|
+
configureControl,
|
|
28
|
+
} from "../configure/output.js";
|
|
29
|
+
import { need, seven, stop } from "../configure/request.js";
|
|
30
|
+
import { equal } from "../../../renewalAggregate/shared.js";
|
|
31
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
32
|
+
import type { Bundle } from "../material/capture.js";
|
|
33
|
+
import type { PreflightRecord } from "../preflight/grammar.js";
|
|
34
|
+
|
|
35
|
+
function matchesCurrentBundle(
|
|
36
|
+
value: unknown,
|
|
37
|
+
record: PreflightRecord,
|
|
38
|
+
): value is Bundle {
|
|
39
|
+
return equal(value, {
|
|
40
|
+
...record.originalBundle,
|
|
41
|
+
wireSubscription: record.configuration.freshSubscription,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
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
|
+
/** One fixed initial configure attempt. No replay, caller frame or output registration. */
|
|
63
|
+
export function captureAdmittedConfigureWrite(token: object) {
|
|
64
|
+
const pair = createAdmittedConfigureWriteTransport(token);
|
|
65
|
+
need(arguments.length === 1);
|
|
66
|
+
const attempt: Attempt = { pair, receipt: null, rawReceipt: null };
|
|
67
|
+
attempts.set(token, attempt);
|
|
68
|
+
const lineage = readConfigureLineage(token),
|
|
69
|
+
owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
70
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
71
|
+
work = journalWorkForConfigureLineage(token);
|
|
72
|
+
let used = false,
|
|
73
|
+
closed = false,
|
|
74
|
+
receiptKnown = false;
|
|
75
|
+
function guard() {
|
|
76
|
+
need(!closed);
|
|
77
|
+
pair.guard();
|
|
78
|
+
}
|
|
79
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
80
|
+
guard();
|
|
81
|
+
const result = await owned(call);
|
|
82
|
+
guard();
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function providerFailure(
|
|
86
|
+
fact: NonNullable<ReturnType<Pair["capability"]["consumeReadCatch"]>>,
|
|
87
|
+
) {
|
|
88
|
+
const failure = admitConfigureFailure(
|
|
89
|
+
fact.phase,
|
|
90
|
+
fact.resource,
|
|
91
|
+
fact.ordinal,
|
|
92
|
+
pair.record.request,
|
|
93
|
+
fact.diagnostics,
|
|
94
|
+
);
|
|
95
|
+
const error = Error("OWNED_CONFIGURE_PROVIDER_REJECTED");
|
|
96
|
+
Object.defineProperty(error, "failure", { value: failure });
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
return Object.freeze({
|
|
100
|
+
async invoke() {
|
|
101
|
+
need(!used);
|
|
102
|
+
used = true;
|
|
103
|
+
need(arguments.length === 0);
|
|
104
|
+
let actualError: Error | null = null;
|
|
105
|
+
try {
|
|
106
|
+
guard();
|
|
107
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
108
|
+
const original = await checked(() =>
|
|
109
|
+
projectRenewalConfigurationV2(pair.record.configuration),
|
|
110
|
+
);
|
|
111
|
+
need(original.status === "projected_configure_request");
|
|
112
|
+
const attachment = await checked(() =>
|
|
113
|
+
constructRenewalScheduleAttachmentReceiptV2(
|
|
114
|
+
pair.record.configuration.attachReceipt,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
const record = verifyPreflightRecordDATA(
|
|
118
|
+
pair.retained,
|
|
119
|
+
original,
|
|
120
|
+
attachment,
|
|
121
|
+
);
|
|
122
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
123
|
+
const reader = createSelectedRawAcquisition(
|
|
124
|
+
pair.owner,
|
|
125
|
+
pair.transport.readTransport,
|
|
126
|
+
attachment.scheduleId,
|
|
127
|
+
);
|
|
128
|
+
const acquired = await checked(() =>
|
|
129
|
+
reader.acquire(record.configuration.preparation.expected),
|
|
130
|
+
);
|
|
131
|
+
if (!acquired.ok) {
|
|
132
|
+
const fact = pair.capability.consumeReadCatch();
|
|
133
|
+
if (fact) {
|
|
134
|
+
actualError = providerFailure(fact);
|
|
135
|
+
throw actualError;
|
|
136
|
+
}
|
|
137
|
+
return stop();
|
|
138
|
+
}
|
|
139
|
+
if (!matchesCurrentBundle(acquired.bundle, record))
|
|
140
|
+
return configureControl(
|
|
141
|
+
"not_dispatched",
|
|
142
|
+
"preconfigure_baseline_changed",
|
|
143
|
+
);
|
|
144
|
+
const evidence = Object.freeze({
|
|
145
|
+
bundle: acquired.bundle,
|
|
146
|
+
schedule: acquired.schedule,
|
|
147
|
+
observedAt: acquired.observedAt,
|
|
148
|
+
});
|
|
149
|
+
verifyCurrentPreflightDATA(record, evidence);
|
|
150
|
+
const fresh = await checked(() =>
|
|
151
|
+
projectRenewalConfigurationV2({
|
|
152
|
+
...record.configuration,
|
|
153
|
+
freshSubscription: evidence.bundle.wireSubscription,
|
|
154
|
+
targetPrice: evidence.bundle.wireTargetPrice,
|
|
155
|
+
...(Object.prototype.hasOwnProperty.call(
|
|
156
|
+
record.configuration,
|
|
157
|
+
"billingCustomer",
|
|
158
|
+
)
|
|
159
|
+
? { billingCustomer: evidence.bundle.wireBillingCustomer }
|
|
160
|
+
: {}),
|
|
161
|
+
schedule: evidence.schedule,
|
|
162
|
+
observedAt: evidence.observedAt,
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
need(
|
|
166
|
+
fresh.status === "projected_configure_request" &&
|
|
167
|
+
equal(fresh, original) &&
|
|
168
|
+
equal(fresh, record.request),
|
|
169
|
+
);
|
|
170
|
+
need(
|
|
171
|
+
Reflect.apply(pair.covers, pair.entry, [record, evidence, fresh]) ===
|
|
172
|
+
true,
|
|
173
|
+
);
|
|
174
|
+
guard();
|
|
175
|
+
releasePreflightDATA(record, evidence, fresh, original, attachment);
|
|
176
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
177
|
+
const dispatch = {
|
|
178
|
+
event: "dispatch",
|
|
179
|
+
stage: "configure",
|
|
180
|
+
request: original,
|
|
181
|
+
};
|
|
182
|
+
await checked(() => compiler.dispatch(dispatch));
|
|
183
|
+
await checked(() => assertConfigureWriteFrontier(token, [dispatch]));
|
|
184
|
+
const reply = await checked(() => pair.transport.postConfigure());
|
|
185
|
+
if (pair.capability.consumeNotStarted(reply))
|
|
186
|
+
return configureControl("not_dispatched", "post_not_started");
|
|
187
|
+
const fact = pair.capability.consumePostCatch(reply);
|
|
188
|
+
if (fact) {
|
|
189
|
+
actualError = providerFailure(fact);
|
|
190
|
+
throw actualError;
|
|
191
|
+
}
|
|
192
|
+
if (reply.outcome !== "fulfilled_safe")
|
|
193
|
+
return configureControl("configure_unknown", "post_unverified");
|
|
194
|
+
const response = {
|
|
195
|
+
event: "response",
|
|
196
|
+
stage: "configure",
|
|
197
|
+
request: original,
|
|
198
|
+
body: reply.body,
|
|
199
|
+
transport: reply.transport,
|
|
200
|
+
};
|
|
201
|
+
await checked(() => compiler.response(response));
|
|
202
|
+
const rawReceipt = Object.freeze({
|
|
203
|
+
configuration: record.configuration,
|
|
204
|
+
actualDispatch: seven(original),
|
|
205
|
+
providerSnapshot: reply.body,
|
|
206
|
+
transport: reply.transport,
|
|
207
|
+
});
|
|
208
|
+
const receipt = await checked(() =>
|
|
209
|
+
constructRenewalConfigurationReceiptV2(rawReceipt),
|
|
210
|
+
);
|
|
211
|
+
// Known receipt closes this once-only attempt before output admission or persistence.
|
|
212
|
+
receiptKnown = true;
|
|
213
|
+
attempt.receipt = freeze(receipt);
|
|
214
|
+
attempt.rawReceipt = freeze(rawReceipt);
|
|
215
|
+
guard();
|
|
216
|
+
const events = await checked(() =>
|
|
217
|
+
assertConfigureWriteFrontier(token, [dispatch, response]),
|
|
218
|
+
);
|
|
219
|
+
const receiptJSON = JSON.stringify(renewalSnapshot(receipt));
|
|
220
|
+
const retained: unknown = await checked(() => work.retain(receiptJSON));
|
|
221
|
+
const retention = checkConfigureRetention(
|
|
222
|
+
retained,
|
|
223
|
+
lineage.reservation,
|
|
224
|
+
events,
|
|
225
|
+
receipt.binding,
|
|
226
|
+
);
|
|
227
|
+
const known = {
|
|
228
|
+
receiptJSON,
|
|
229
|
+
receiptBinding: receipt.binding,
|
|
230
|
+
retention,
|
|
231
|
+
};
|
|
232
|
+
await checked(() =>
|
|
233
|
+
assertConfigureWriteFrontier(token, [dispatch, response], known),
|
|
234
|
+
);
|
|
235
|
+
const output = admitConfigureACK(record, rawReceipt, receipt);
|
|
236
|
+
const returned = closedFields(output, [
|
|
237
|
+
"status",
|
|
238
|
+
"originalRecord",
|
|
239
|
+
"rawReceipt",
|
|
240
|
+
"receipt",
|
|
241
|
+
"operationalAuthority",
|
|
242
|
+
]);
|
|
243
|
+
const published = {
|
|
244
|
+
event: "receipt",
|
|
245
|
+
stage: "configure",
|
|
246
|
+
request: original,
|
|
247
|
+
receipt,
|
|
248
|
+
};
|
|
249
|
+
await checked(() => compiler.receipt(published));
|
|
250
|
+
await checked(() =>
|
|
251
|
+
assertConfigureWriteFrontier(
|
|
252
|
+
token,
|
|
253
|
+
[dispatch, response, published],
|
|
254
|
+
known,
|
|
255
|
+
),
|
|
256
|
+
);
|
|
257
|
+
const view: Completion = Object.freeze({
|
|
258
|
+
output,
|
|
259
|
+
receipt: returned.receipt,
|
|
260
|
+
rawReceipt: returned.rawReceipt,
|
|
261
|
+
acknowledgement: pair.preflight.acknowledgement,
|
|
262
|
+
originalEntry: pair.preflight.originalEntry,
|
|
263
|
+
configureEntry: pair.entry,
|
|
264
|
+
coversConfigure: pair.covers,
|
|
265
|
+
operationalAuthority: false,
|
|
266
|
+
});
|
|
267
|
+
guard();
|
|
268
|
+
// No callback, reflection or Owner sample follows the final gate before discard.
|
|
269
|
+
pair.capability.discardFulfilledQuarantine();
|
|
270
|
+
completions.set(token, { view, guard });
|
|
271
|
+
return output;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
let live = false;
|
|
274
|
+
try {
|
|
275
|
+
guard();
|
|
276
|
+
live = true;
|
|
277
|
+
} catch {
|
|
278
|
+
/* No reflection on provider data after closure. */
|
|
279
|
+
}
|
|
280
|
+
closed = true;
|
|
281
|
+
if (live && actualError === error) throw error;
|
|
282
|
+
if (pair.transport.postDisposition() !== "NOT_STARTED" || receiptKnown)
|
|
283
|
+
return configureControl(
|
|
284
|
+
"configure_unknown",
|
|
285
|
+
live ? "post_unverified" : "owner_closed_after_post",
|
|
286
|
+
);
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { COMPILED_CONFIGURE_WRITE_ENTRIES } from "../operations/sourceOperations.js";
|
|
3
|
+
import { closed } from "../operations/types.js";
|
|
4
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
5
|
+
import { readAdmittedConfigurePreflight } from "./configurePreflight.js";
|
|
6
|
+
import { captureInitialStockRawDelegate } from "./stockDelegateFactory.js";
|
|
7
|
+
import { capturePreflightRecordDATA } from "../preflight/record.js";
|
|
8
|
+
import { expectedPlan, need, ownMethod } from "../configure/request.js";
|
|
9
|
+
|
|
10
|
+
const captures = new WeakSet<object>();
|
|
11
|
+
/** Derive a fixed write frame from actual completed readonly custody. */
|
|
12
|
+
export function captureAdmittedConfigureWriteFrame(
|
|
13
|
+
token: object,
|
|
14
|
+
arity: number,
|
|
15
|
+
) {
|
|
16
|
+
need(typeof token === "object" && token !== null && !captures.has(token));
|
|
17
|
+
captures.add(token);
|
|
18
|
+
need(arity === 1);
|
|
19
|
+
const lineage = readConfigureLineage(token);
|
|
20
|
+
const preflight = readAdmittedConfigurePreflight(token);
|
|
21
|
+
need(
|
|
22
|
+
!types.isProxy(COMPILED_CONFIGURE_WRITE_ENTRIES) &&
|
|
23
|
+
Array.isArray(COMPILED_CONFIGURE_WRITE_ENTRIES),
|
|
24
|
+
);
|
|
25
|
+
const candidates = COMPILED_CONFIGURE_WRITE_ENTRIES.filter((entry) => {
|
|
26
|
+
const fields = closed(entry, ["originalEntry", "coversConfigure"]);
|
|
27
|
+
ownMethod(entry, "coversConfigure");
|
|
28
|
+
return fields.originalEntry === preflight.originalEntry;
|
|
29
|
+
});
|
|
30
|
+
need(candidates.length === 1);
|
|
31
|
+
const entry = candidates[0],
|
|
32
|
+
covers = ownMethod(entry, "coversConfigure");
|
|
33
|
+
const record = preflight.output.originalRecord;
|
|
34
|
+
const retained = capturePreflightRecordDATA(record);
|
|
35
|
+
let closedFrame = false;
|
|
36
|
+
function guard() {
|
|
37
|
+
need(!closedFrame);
|
|
38
|
+
try {
|
|
39
|
+
const current = readConfigureLineage(token);
|
|
40
|
+
need(
|
|
41
|
+
current.owner === lineage.owner &&
|
|
42
|
+
current.originalReservation === lineage.originalReservation &&
|
|
43
|
+
current.journal === lineage.journal,
|
|
44
|
+
);
|
|
45
|
+
need(readAdmittedConfigurePreflight(token) === preflight);
|
|
46
|
+
need(
|
|
47
|
+
!types.isProxy(COMPILED_CONFIGURE_WRITE_ENTRIES) &&
|
|
48
|
+
Array.isArray(COMPILED_CONFIGURE_WRITE_ENTRIES) &&
|
|
49
|
+
COMPILED_CONFIGURE_WRITE_ENTRIES.includes(entry),
|
|
50
|
+
);
|
|
51
|
+
const fields = closed(entry, ["originalEntry", "coversConfigure"]);
|
|
52
|
+
need(
|
|
53
|
+
fields.originalEntry === preflight.originalEntry &&
|
|
54
|
+
fields.coversConfigure === covers &&
|
|
55
|
+
!types.isProxy(covers),
|
|
56
|
+
);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
closedFrame = true;
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
guard();
|
|
63
|
+
const delegate = captureInitialStockRawDelegate(lineage.parentToken);
|
|
64
|
+
const expected = expectedPlan(record);
|
|
65
|
+
const readPlan = Object.freeze(
|
|
66
|
+
expected.map(({ resource, ordinal, method, path, body, options }) =>
|
|
67
|
+
Object.freeze({ resource, ordinal, method, path, body, options }),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
const frame = Object.freeze({
|
|
71
|
+
owner: lineage.owner,
|
|
72
|
+
operation: token,
|
|
73
|
+
request: record.request,
|
|
74
|
+
readPlan,
|
|
75
|
+
delegate,
|
|
76
|
+
});
|
|
77
|
+
return Object.freeze({
|
|
78
|
+
frame,
|
|
79
|
+
expected,
|
|
80
|
+
owner: lineage.owner,
|
|
81
|
+
guard,
|
|
82
|
+
record,
|
|
83
|
+
retained,
|
|
84
|
+
preflight,
|
|
85
|
+
entry,
|
|
86
|
+
covers,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configureAdmissionFixture,
|
|
3
|
+
admissionControls,
|
|
4
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
5
|
+
import { expect, it } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
captureAdmittedConfigurePreflight,
|
|
8
|
+
readAdmittedConfigurePreflight,
|
|
9
|
+
} from "./configurePreflight.js";
|
|
10
|
+
|
|
11
|
+
it.each(["initial", "replay", "resume"] as const)(
|
|
12
|
+
"runs fixed readonly configure preflight after %s ACK with actual returned custody",
|
|
13
|
+
async (mode) => {
|
|
14
|
+
await configureAdmissionFixture(async (h) => {
|
|
15
|
+
await h.complete(mode);
|
|
16
|
+
const child = await h.child();
|
|
17
|
+
const token = await h.core.admitConfigure(
|
|
18
|
+
child.fresh.call,
|
|
19
|
+
child.journal,
|
|
20
|
+
);
|
|
21
|
+
h.configureReads(child);
|
|
22
|
+
admissionControls.preflight.push({
|
|
23
|
+
originalEntry: admissionControls.entries[0],
|
|
24
|
+
coversPreflight: () => true,
|
|
25
|
+
});
|
|
26
|
+
const start = h.calls.length,
|
|
27
|
+
selectors = admissionControls.selectors,
|
|
28
|
+
basis = h.core.basisJSON;
|
|
29
|
+
const actor = captureAdmittedConfigurePreflight(token);
|
|
30
|
+
expect(actor).not.toBeNull();
|
|
31
|
+
const output = await actor.invoke();
|
|
32
|
+
expect(output.status).toBe("configure_preflight_consistent");
|
|
33
|
+
expect(output.request).toEqual(child.record.configureRecord.request);
|
|
34
|
+
expect(output.currentEvidence.observedAt).toBe(
|
|
35
|
+
h.baseline.configurationTime,
|
|
36
|
+
);
|
|
37
|
+
expect(output.operationalAuthority).toBe(false);
|
|
38
|
+
const view = readAdmittedConfigurePreflight(token);
|
|
39
|
+
expect(view.output === output).toBe(true);
|
|
40
|
+
expect(view.originalEntry === admissionControls.entries[0]).toBe(true);
|
|
41
|
+
expect(
|
|
42
|
+
view.coversPreflight === admissionControls.preflight[0].coversPreflight,
|
|
43
|
+
).toBe(true);
|
|
44
|
+
expect(view.acknowledgement === h.core.attachAcknowledgement()).toBe(
|
|
45
|
+
true,
|
|
46
|
+
);
|
|
47
|
+
expect(
|
|
48
|
+
h.calls.slice(start).map((row) => row.method + ":" + row.path),
|
|
49
|
+
).toEqual([
|
|
50
|
+
"GET:/v1/subscriptions/sub_original",
|
|
51
|
+
"GET:/v1/prices/price_target",
|
|
52
|
+
"GET:/v1/customers/cus_buyer",
|
|
53
|
+
...h.source.originalBundle.couponReads.map(
|
|
54
|
+
(row) =>
|
|
55
|
+
"GET:/v1/coupons/" + encodeURIComponent(String(row.couponId)),
|
|
56
|
+
),
|
|
57
|
+
"GET:/v1/subscription_schedules/" + h.baseline.schedule.id,
|
|
58
|
+
]);
|
|
59
|
+
expect(h.calls.slice(start).every((row) => row.hasBody === false)).toBe(
|
|
60
|
+
true,
|
|
61
|
+
);
|
|
62
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
63
|
+
expect(admissionControls.legacy).toBe(0);
|
|
64
|
+
expect(h.core.basisJSON).toBe(basis);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
);
|