@fantastic.dev/better-stripe 0.105.0 → 0.107.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 +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/observation/history.d.ts +41 -0
- package/dist/client/billing/renewalAttach/internal/observation/history.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/history.js +161 -0
- package/dist/client/billing/renewalAttach/internal/observation/history.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.d.ts +55 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.js +83 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.js.map +1 -0
- 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/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/docs/renewal-context-reads.md +90 -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/observation/history.integration.test.ts +79 -0
- package/src/client/billing/renewalAttach/internal/observation/history.ts +200 -0
- package/src/client/billing/renewalAttach/internal/observation/historyControls.integration.test.ts +238 -0
- package/src/client/billing/renewalAttach/internal/observation/historyEvents.ts +114 -0
- 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
- package/src/client/billing/renewalAttach/internal/test-fixtures/historySnapshot.ts +47 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { rejectProxyJSON } from "../acquisition/rawWireSource.js";
|
|
2
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
3
|
+
import { closed, freeze, sevenWire } from "../c10/ownData.js";
|
|
4
|
+
import { canonicalInitialBasis } from "../../../../../shared/renewalOperationJournal.js";
|
|
5
|
+
import {
|
|
6
|
+
reconstructConfigurationV2,
|
|
7
|
+
constructRenewalConfigurationReceiptV2,
|
|
8
|
+
} from "../../../renewalV2/index.js";
|
|
9
|
+
import { captureObservationRecord, verifyObservationRecord } from "./record.js";
|
|
10
|
+
import { admitConfigureACK } from "../configure/output.js";
|
|
11
|
+
import {
|
|
12
|
+
checkOperationLoad,
|
|
13
|
+
matchConfigureDATA,
|
|
14
|
+
object,
|
|
15
|
+
text,
|
|
16
|
+
requireConfigure as need,
|
|
17
|
+
} from "../producer/configureJournalData.js";
|
|
18
|
+
import {
|
|
19
|
+
captureHistoryStage,
|
|
20
|
+
verifyHistoryEvents,
|
|
21
|
+
verifyHistoryRetention,
|
|
22
|
+
} from "./historyEvents.js";
|
|
23
|
+
|
|
24
|
+
/** Pure retained DATA. No Source, actual returned ACK, authorization or execution grant. */
|
|
25
|
+
export async function captureRetainedObservationHistory(raw: unknown) {
|
|
26
|
+
need(arguments.length === 1);
|
|
27
|
+
// Capture the complete graph before the first await, including opaque JSON strings.
|
|
28
|
+
rejectProxyJSON(raw);
|
|
29
|
+
const copy = renewalSnapshot(raw);
|
|
30
|
+
need(new TextEncoder().encode(JSON.stringify(copy)).length <= 500000);
|
|
31
|
+
matchConfigureDATA(raw, copy);
|
|
32
|
+
freeze(copy);
|
|
33
|
+
const snapshot = closed(copy, ["parent", "configure"]);
|
|
34
|
+
const parent = captureHistoryStage(snapshot.parent, "attach");
|
|
35
|
+
const child = captureHistoryStage(snapshot.configure, "configure");
|
|
36
|
+
need(
|
|
37
|
+
parent.reservation.operationId !== child.reservation.operationId &&
|
|
38
|
+
parent.reservation.attemptId !== child.reservation.attemptId,
|
|
39
|
+
);
|
|
40
|
+
const original = object(JSON.parse(child.reservation.recordJSON));
|
|
41
|
+
const parentOriginal = object(JSON.parse(parent.reservation.recordJSON));
|
|
42
|
+
const captured = captureObservationRecord(original.configureRecord);
|
|
43
|
+
const record = captured.record;
|
|
44
|
+
const rebuilt = await reconstructConfigurationV2(record.configuration);
|
|
45
|
+
need(rebuilt.material && "requestIdentity" in rebuilt.result);
|
|
46
|
+
verifyObservationRecord(captured, rebuilt.result, rebuilt.material.receipt);
|
|
47
|
+
const receipt = rebuilt.material.receipt,
|
|
48
|
+
request = rebuilt.result;
|
|
49
|
+
matchConfigureDATA(original.parentAttachment, {
|
|
50
|
+
operationId: parent.reservation.operationId,
|
|
51
|
+
attemptId: parent.reservation.attemptId,
|
|
52
|
+
sourcePayloadId: parent.reservation.payloadId,
|
|
53
|
+
receiptBinding: receipt.binding,
|
|
54
|
+
});
|
|
55
|
+
matchConfigureDATA(
|
|
56
|
+
record.configuration.attachReceipt.attachRequest,
|
|
57
|
+
parentOriginal.attachRequest,
|
|
58
|
+
);
|
|
59
|
+
matchConfigureDATA(record.originalBundle, parentOriginal.originalBundle);
|
|
60
|
+
matchConfigureDATA(original.account, parentOriginal.account);
|
|
61
|
+
matchConfigureDATA(original.account, {
|
|
62
|
+
mode: "platform",
|
|
63
|
+
stripeAccount: null,
|
|
64
|
+
livemode: receipt.livemode,
|
|
65
|
+
});
|
|
66
|
+
need(
|
|
67
|
+
original.apiVersion === parentOriginal.apiVersion &&
|
|
68
|
+
original.apiVersion === request.apiVersion,
|
|
69
|
+
);
|
|
70
|
+
matchConfigureDATA(original.dispatch, sevenWire(request));
|
|
71
|
+
matchConfigureDATA(parentOriginal.dispatch, sevenWire(receipt.request));
|
|
72
|
+
need(
|
|
73
|
+
child.reservation.requestBinding === request.requestIdentity.binding &&
|
|
74
|
+
parent.reservation.requestBinding ===
|
|
75
|
+
receipt.request.requestIdentity.binding,
|
|
76
|
+
);
|
|
77
|
+
const policy = object(original.timingPolicy),
|
|
78
|
+
parentPolicy = object(parentOriginal.timingPolicy);
|
|
79
|
+
for (const key of ["workEndWallMs", "endWallMs", "periodStart", "periodEnd"])
|
|
80
|
+
need(policy[key] === parentPolicy[key]);
|
|
81
|
+
const parentLoad = object(parent.operation),
|
|
82
|
+
basis = object(parentLoad.initialBasis);
|
|
83
|
+
const basisJSON = text(basis.basisJSON);
|
|
84
|
+
need(
|
|
85
|
+
canonicalInitialBasis(parent.reservation.timingPolicyJSON, basisJSON)
|
|
86
|
+
.basisJSON === basisJSON,
|
|
87
|
+
);
|
|
88
|
+
need(
|
|
89
|
+
canonicalInitialBasis(child.reservation.timingPolicyJSON, basisJSON)
|
|
90
|
+
.basisJSON === basisJSON,
|
|
91
|
+
);
|
|
92
|
+
checkOperationLoad(parent.operation, parent.reservation, basisJSON);
|
|
93
|
+
checkOperationLoad(
|
|
94
|
+
child.operation,
|
|
95
|
+
child.reservation,
|
|
96
|
+
basisJSON,
|
|
97
|
+
child.events.length === 0,
|
|
98
|
+
);
|
|
99
|
+
await verifyHistoryEvents(parent, [
|
|
100
|
+
{ event: "dispatch", stage: "attach", request: receipt.request },
|
|
101
|
+
{
|
|
102
|
+
event: "response",
|
|
103
|
+
stage: "attach",
|
|
104
|
+
request: receipt.request,
|
|
105
|
+
body: receipt.providerSnapshot,
|
|
106
|
+
status: parent.events[1].data.status,
|
|
107
|
+
},
|
|
108
|
+
{ event: "receipt", stage: "attach", request: receipt.request, receipt },
|
|
109
|
+
]);
|
|
110
|
+
const attachmentRetention = verifyHistoryRetention(parent, receipt);
|
|
111
|
+
const expected: unknown[] = [];
|
|
112
|
+
if (child.events.length >= 1)
|
|
113
|
+
expected.push({ event: "dispatch", stage: "configure", request });
|
|
114
|
+
const response = child.events[1]?.data;
|
|
115
|
+
if (response)
|
|
116
|
+
expected.push({
|
|
117
|
+
event: "response",
|
|
118
|
+
stage: "configure",
|
|
119
|
+
request,
|
|
120
|
+
body: response.body,
|
|
121
|
+
transport: response.transport,
|
|
122
|
+
});
|
|
123
|
+
let configureReceipt = null,
|
|
124
|
+
rawConfigureReceipt = null,
|
|
125
|
+
configureRetention = null;
|
|
126
|
+
if (response) {
|
|
127
|
+
const t = closed(response.transport, ["status"], ["requestId"]);
|
|
128
|
+
need(typeof t.status === "number");
|
|
129
|
+
need(t.requestId === undefined || typeof t.requestId === "string");
|
|
130
|
+
const rawResponse = {
|
|
131
|
+
configuration: record.configuration,
|
|
132
|
+
actualDispatch: sevenWire(request),
|
|
133
|
+
providerSnapshot: object(response.body),
|
|
134
|
+
transport: {
|
|
135
|
+
status: t.status,
|
|
136
|
+
...(typeof t.requestId === "string" ? { requestId: t.requestId } : {}),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const reconstructed =
|
|
140
|
+
await constructRenewalConfigurationReceiptV2(rawResponse);
|
|
141
|
+
admitConfigureACK(record, rawResponse, reconstructed);
|
|
142
|
+
// Response2 may be valid without durable C9. Reconstruction does not retain it.
|
|
143
|
+
if (child.acknowledgement !== null) {
|
|
144
|
+
rawConfigureReceipt = rawResponse;
|
|
145
|
+
configureReceipt = reconstructed;
|
|
146
|
+
configureRetention = verifyHistoryRetention(child, configureReceipt);
|
|
147
|
+
}
|
|
148
|
+
} else need(child.acknowledgement === null);
|
|
149
|
+
if (child.events.length === 3) {
|
|
150
|
+
need(configureReceipt);
|
|
151
|
+
expected.push({
|
|
152
|
+
event: "receipt",
|
|
153
|
+
stage: "configure",
|
|
154
|
+
request,
|
|
155
|
+
receipt: configureReceipt,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
await verifyHistoryEvents(child, expected);
|
|
159
|
+
// IDs remain opaque DATA. Even equal complete records never become runtime tokens.
|
|
160
|
+
const payloads = [
|
|
161
|
+
parent.reservation.payloadId,
|
|
162
|
+
child.reservation.payloadId,
|
|
163
|
+
...parent.events.map((e) => e.descriptor.payloadId),
|
|
164
|
+
...child.events.map((e) => e.descriptor.payloadId),
|
|
165
|
+
object(attachmentRetention.retention).receiptPayloadId,
|
|
166
|
+
...(configureRetention
|
|
167
|
+
? [object(configureRetention.retention).receiptPayloadId]
|
|
168
|
+
: []),
|
|
169
|
+
];
|
|
170
|
+
const eventIds = [...parent.events, ...child.events].map(
|
|
171
|
+
(e) => e.descriptor.eventId,
|
|
172
|
+
);
|
|
173
|
+
need(
|
|
174
|
+
new Set(payloads).size === payloads.length &&
|
|
175
|
+
new Set(eventIds).size === eventIds.length,
|
|
176
|
+
);
|
|
177
|
+
const ids = [
|
|
178
|
+
parent.reservation.operationId,
|
|
179
|
+
child.reservation.operationId,
|
|
180
|
+
parent.reservation.attemptId,
|
|
181
|
+
child.reservation.attemptId,
|
|
182
|
+
...payloads,
|
|
183
|
+
...eventIds,
|
|
184
|
+
];
|
|
185
|
+
need(new Set(ids).size === ids.length);
|
|
186
|
+
return freeze({
|
|
187
|
+
status: "retained_observation_history_data" as const,
|
|
188
|
+
record,
|
|
189
|
+
configureHead: child.events.length,
|
|
190
|
+
configureReceipt,
|
|
191
|
+
rawConfigureReceipt,
|
|
192
|
+
attachmentReceipt: receipt,
|
|
193
|
+
attachmentRetention,
|
|
194
|
+
configureRetention,
|
|
195
|
+
snapshot: { parent: snapshot.parent, configure: snapshot.configure },
|
|
196
|
+
operationalAuthority: false as const,
|
|
197
|
+
authenticationEstablished: false as const,
|
|
198
|
+
publicDeliveryEstablished: false as const,
|
|
199
|
+
});
|
|
200
|
+
}
|
package/src/client/billing/renewalAttach/internal/observation/historyControls.integration.test.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { expect } from "vitest";
|
|
2
|
+
import { configureAdmissionCase } from "../test-fixtures/producerConfigureAdmission.js";
|
|
3
|
+
import {
|
|
4
|
+
historySnapshot,
|
|
5
|
+
historyPrefix,
|
|
6
|
+
type HistorySnapshot,
|
|
7
|
+
} from "../test-fixtures/historySnapshot.js";
|
|
8
|
+
import { captureRetainedObservationHistory } from "./history.js";
|
|
9
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
10
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
11
|
+
|
|
12
|
+
// Mutable controlled fixture DATA only, never the detached production reader.
|
|
13
|
+
function object(value: unknown): Record<string, unknown> {
|
|
14
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
15
|
+
throw Error("FIXTURE_OBJECT");
|
|
16
|
+
return value as Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function rewriteRecord(
|
|
20
|
+
s: HistorySnapshot,
|
|
21
|
+
change: (r: Record<string, unknown>) => void,
|
|
22
|
+
) {
|
|
23
|
+
const record = object(JSON.parse(s.configure.operation.recordJSON));
|
|
24
|
+
change(record);
|
|
25
|
+
const json = JSON.stringify(renewalSnapshot(record));
|
|
26
|
+
s.configure.operation.recordJSON = json;
|
|
27
|
+
s.configure.attempt.reservation.recordJSON = json;
|
|
28
|
+
}
|
|
29
|
+
async function rewriteEvent(
|
|
30
|
+
s: HistorySnapshot,
|
|
31
|
+
change: (r: Record<string, unknown>) => void,
|
|
32
|
+
) {
|
|
33
|
+
const event = s.configure.events[1]!;
|
|
34
|
+
const data = object(JSON.parse(event!.dataJSON));
|
|
35
|
+
change(data);
|
|
36
|
+
const canonical = await canonicalJournalEvent(2, JSON.stringify(data));
|
|
37
|
+
Object.assign(event!, {
|
|
38
|
+
binding: canonical.binding,
|
|
39
|
+
dataJSON: canonical.json,
|
|
40
|
+
});
|
|
41
|
+
s.configure.attempt.events[1].binding = canonical.binding;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
configureAdmissionCase(
|
|
45
|
+
"rejects inconsistent full history, response, C9 and immutable parent relations",
|
|
46
|
+
historySnapshot,
|
|
47
|
+
async (_h, full) => {
|
|
48
|
+
const controls: [string, (s: HistorySnapshot) => void | Promise<void>][] = [
|
|
49
|
+
[
|
|
50
|
+
"foreign parent",
|
|
51
|
+
(s) =>
|
|
52
|
+
rewriteRecord(s, (r) => {
|
|
53
|
+
object(r.parentAttachment).operationId = "foreign";
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
"raw original material",
|
|
58
|
+
(s) =>
|
|
59
|
+
rewriteRecord(s, (r) => {
|
|
60
|
+
object(
|
|
61
|
+
object(object(r.configureRecord).originalBundle).wireTargetPrice,
|
|
62
|
+
).metadata = { changed: true };
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
"account",
|
|
67
|
+
(s) =>
|
|
68
|
+
rewriteRecord(s, (r) => {
|
|
69
|
+
object(r.account).livemode = true;
|
|
70
|
+
}),
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"deadline",
|
|
74
|
+
(s) =>
|
|
75
|
+
rewriteRecord(s, (r) => {
|
|
76
|
+
const p = object(r.timingPolicy);
|
|
77
|
+
p.endWallMs = Number(p.endWallMs) + 1;
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
"basis",
|
|
82
|
+
(s) => {
|
|
83
|
+
object(object(s.configure.operation).initialBasis).basisJSON = "{}";
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
"missing bound basis",
|
|
88
|
+
(s) => {
|
|
89
|
+
Object.assign(s.configure.operation, { initialBasis: null });
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
"descriptor mismatch",
|
|
94
|
+
(s) => {
|
|
95
|
+
s.configure.attempt.events[0].eventId = "other-event";
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
"binding mismatch",
|
|
100
|
+
(s) => {
|
|
101
|
+
s.configure.events[0]!.binding = "wrong";
|
|
102
|
+
s.configure.attempt.events[0].binding = "wrong";
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"response request",
|
|
107
|
+
async (s) =>
|
|
108
|
+
rewriteEvent(s, (r) => {
|
|
109
|
+
object(r.request).key = "different-key";
|
|
110
|
+
}),
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
"response body",
|
|
114
|
+
async (s) =>
|
|
115
|
+
rewriteEvent(s, (r) => {
|
|
116
|
+
object(r.body).id = "sub_sched_foreign";
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
"contradictory C9",
|
|
121
|
+
(s) => {
|
|
122
|
+
const ack = s.configure.acknowledgement!;
|
|
123
|
+
const r = JSON.parse(ack.receiptJSON);
|
|
124
|
+
r.providerSnapshot.metadata = { changed: true };
|
|
125
|
+
ack.receiptJSON = JSON.stringify(renewalSnapshot(r));
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
"missing head3 retention",
|
|
130
|
+
(s) => {
|
|
131
|
+
s.configure.acknowledgement = null;
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
"retention source alias",
|
|
136
|
+
(s) => {
|
|
137
|
+
s.configure.acknowledgement!.retention.receiptPayloadId =
|
|
138
|
+
s.configure.attempt.reservation.payloadId;
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
"retention event alias",
|
|
143
|
+
(s) => {
|
|
144
|
+
s.configure.acknowledgement!.retention.receiptPayloadId =
|
|
145
|
+
s.configure.attempt.events[2].payloadId;
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
"retention event identity alias",
|
|
150
|
+
(s) => {
|
|
151
|
+
s.configure.acknowledgement!.retention.receiptPayloadId =
|
|
152
|
+
s.configure.attempt.events[1].eventId;
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"parent receipt alias",
|
|
157
|
+
(s) => {
|
|
158
|
+
s.parent.acknowledgement!.retention.receiptPayloadId =
|
|
159
|
+
s.parent.attempt.reservation.payloadId;
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
[
|
|
163
|
+
"cross stage payload alias",
|
|
164
|
+
(s) => {
|
|
165
|
+
s.configure.acknowledgement!.retention.receiptPayloadId =
|
|
166
|
+
s.parent.acknowledgement!.retention.receiptPayloadId;
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
"parent event missing",
|
|
171
|
+
(s) => {
|
|
172
|
+
s.parent.events.pop();
|
|
173
|
+
s.parent.attempt.events.pop();
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
"extra stage key",
|
|
178
|
+
(s) => {
|
|
179
|
+
Object.assign(s.configure, { callback: null });
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
];
|
|
183
|
+
for (const [name, change] of controls) {
|
|
184
|
+
const s = structuredClone(full);
|
|
185
|
+
await change(s);
|
|
186
|
+
let refused = false;
|
|
187
|
+
try {
|
|
188
|
+
await captureRetainedObservationHistory(s);
|
|
189
|
+
} catch {
|
|
190
|
+
refused = true;
|
|
191
|
+
}
|
|
192
|
+
expect(refused, name).toBe(true);
|
|
193
|
+
}
|
|
194
|
+
const absent = historyPrefix(full, 2);
|
|
195
|
+
await rewriteEvent(absent, (r) => {
|
|
196
|
+
object(r.body).id = "sub_sched_foreign";
|
|
197
|
+
});
|
|
198
|
+
await expect(
|
|
199
|
+
captureRetainedObservationHistory(absent),
|
|
200
|
+
"foreign response without retained C9",
|
|
201
|
+
).rejects.toThrow();
|
|
202
|
+
},
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
configureAdmissionCase(
|
|
206
|
+
"rejects proxy traps, getters, hidden keys, sparse arrays and oversized graphs before awaits",
|
|
207
|
+
historySnapshot,
|
|
208
|
+
async (_h, full) => {
|
|
209
|
+
let touched = 0;
|
|
210
|
+
const proxy = new Proxy(full, {
|
|
211
|
+
ownKeys() {
|
|
212
|
+
touched++;
|
|
213
|
+
throw Error("TRAP");
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
await expect(captureRetainedObservationHistory(proxy)).rejects.toThrow();
|
|
217
|
+
expect(touched).toBe(0);
|
|
218
|
+
const getter = { ...full };
|
|
219
|
+
Object.defineProperty(getter, "parent", {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
get() {
|
|
222
|
+
touched++;
|
|
223
|
+
return full.parent;
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
await expect(captureRetainedObservationHistory(getter)).rejects.toThrow();
|
|
227
|
+
expect(touched).toBe(0);
|
|
228
|
+
const hidden = structuredClone(full);
|
|
229
|
+
Object.defineProperty(hidden.configure, "secret", { value: true });
|
|
230
|
+
await expect(captureRetainedObservationHistory(hidden)).rejects.toThrow();
|
|
231
|
+
const sparse = structuredClone(full);
|
|
232
|
+
delete sparse.configure.events[0];
|
|
233
|
+
await expect(captureRetainedObservationHistory(sparse)).rejects.toThrow();
|
|
234
|
+
const huge = structuredClone(full);
|
|
235
|
+
huge.configure.operation.recordJSON = "x".repeat(500001);
|
|
236
|
+
await expect(captureRetainedObservationHistory(huge)).rejects.toThrow();
|
|
237
|
+
},
|
|
238
|
+
);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
2
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
3
|
+
import { closed, freeze } from "../c10/ownData.js";
|
|
4
|
+
import {
|
|
5
|
+
captureAttachDispatch,
|
|
6
|
+
captureAttachResponse,
|
|
7
|
+
captureAttachReceipt,
|
|
8
|
+
captureConfigureDispatch,
|
|
9
|
+
captureConfigureResponse,
|
|
10
|
+
captureConfigureReceipt,
|
|
11
|
+
} from "../c10/eventCapture.js";
|
|
12
|
+
import {
|
|
13
|
+
captureOperationalReservation,
|
|
14
|
+
captureParentHistory,
|
|
15
|
+
captureConfigureHistory,
|
|
16
|
+
matchConfigureDATA,
|
|
17
|
+
object,
|
|
18
|
+
text,
|
|
19
|
+
requireConfigure as need,
|
|
20
|
+
} from "../producer/configureJournalData.js";
|
|
21
|
+
|
|
22
|
+
/** Complete bounded query DATA, never a class journal or actual ACK. */
|
|
23
|
+
export function captureHistoryStage(
|
|
24
|
+
raw: unknown,
|
|
25
|
+
stage: "attach" | "configure",
|
|
26
|
+
) {
|
|
27
|
+
const x = closed(raw, ["operation", "attempt", "events", "acknowledgement"]);
|
|
28
|
+
const attempt = closed(x.attempt, ["reservation", "events"]);
|
|
29
|
+
const reservation = captureOperationalReservation(attempt.reservation, stage);
|
|
30
|
+
need(Array.isArray(attempt.events) && Array.isArray(x.events));
|
|
31
|
+
const count = attempt.events.length;
|
|
32
|
+
need(count <= 3 && x.events.length === count);
|
|
33
|
+
const descriptors =
|
|
34
|
+
stage === "attach"
|
|
35
|
+
? captureParentHistory(x.attempt, reservation)
|
|
36
|
+
: count === 0
|
|
37
|
+
? (matchConfigureDATA(x.attempt, { reservation, events: [] }), [])
|
|
38
|
+
: captureConfigureHistory(x.attempt, reservation, count);
|
|
39
|
+
const allPayloads = [
|
|
40
|
+
reservation.payloadId,
|
|
41
|
+
...descriptors.map((e) => e.payloadId),
|
|
42
|
+
];
|
|
43
|
+
need(new Set(allPayloads).size === allPayloads.length);
|
|
44
|
+
const events = x.events.map((raw, index) => {
|
|
45
|
+
const event = closed(raw, [...Object.keys(descriptors[index]), "dataJSON"]);
|
|
46
|
+
const dataJSON = text(event.dataJSON);
|
|
47
|
+
need(dataJSON.length <= 500000);
|
|
48
|
+
const parsed: unknown = JSON.parse(dataJSON);
|
|
49
|
+
const captures =
|
|
50
|
+
stage === "attach"
|
|
51
|
+
? [captureAttachDispatch, captureAttachResponse, captureAttachReceipt]
|
|
52
|
+
: [
|
|
53
|
+
captureConfigureDispatch,
|
|
54
|
+
captureConfigureResponse,
|
|
55
|
+
captureConfigureReceipt,
|
|
56
|
+
];
|
|
57
|
+
captures[index](parsed);
|
|
58
|
+
matchConfigureDATA(raw, { ...descriptors[index], dataJSON });
|
|
59
|
+
return { descriptor: descriptors[index], dataJSON, data: object(parsed) };
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
operation: x.operation,
|
|
63
|
+
reservation,
|
|
64
|
+
events,
|
|
65
|
+
acknowledgement: x.acknowledgement,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export async function verifyHistoryEvents(
|
|
69
|
+
stage: ReturnType<typeof captureHistoryStage>,
|
|
70
|
+
expected: readonly unknown[],
|
|
71
|
+
) {
|
|
72
|
+
need(stage.events.length === expected.length);
|
|
73
|
+
for (let index = 0; index < expected.length; index++) {
|
|
74
|
+
const event = stage.events[index];
|
|
75
|
+
matchConfigureDATA(event.data, expected[index]);
|
|
76
|
+
const canonical = await canonicalJournalEvent(index + 1, event.dataJSON);
|
|
77
|
+
need(
|
|
78
|
+
canonical.json === event.dataJSON &&
|
|
79
|
+
canonical.binding === event.descriptor.binding,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function verifyHistoryRetention(
|
|
84
|
+
stage: ReturnType<typeof captureHistoryStage>,
|
|
85
|
+
receipt: unknown,
|
|
86
|
+
) {
|
|
87
|
+
need(stage.events.length >= 2);
|
|
88
|
+
const ack = closed(stage.acknowledgement, ["retention", "receiptJSON"]);
|
|
89
|
+
const retention = object(ack.retention),
|
|
90
|
+
r = object(receipt);
|
|
91
|
+
const receiptPayloadId = text(retention.receiptPayloadId);
|
|
92
|
+
need(
|
|
93
|
+
receiptPayloadId !== stage.reservation.payloadId &&
|
|
94
|
+
stage.events.every((e) => e.descriptor.payloadId !== receiptPayloadId),
|
|
95
|
+
);
|
|
96
|
+
const [dispatch, response] = stage.events;
|
|
97
|
+
matchConfigureDATA(JSON.parse(text(ack.receiptJSON)), receipt);
|
|
98
|
+
need(JSON.stringify(renewalSnapshot(receipt)) === ack.receiptJSON);
|
|
99
|
+
matchConfigureDATA(ack.retention, {
|
|
100
|
+
status: "retained",
|
|
101
|
+
operationId: stage.reservation.operationId,
|
|
102
|
+
schemaVersion: 1,
|
|
103
|
+
stage: stage.reservation.stage,
|
|
104
|
+
attemptId: stage.reservation.attemptId,
|
|
105
|
+
sourcePayloadId: stage.reservation.payloadId,
|
|
106
|
+
dispatchEventId: dispatch.descriptor.eventId,
|
|
107
|
+
dispatchPayloadId: dispatch.descriptor.payloadId,
|
|
108
|
+
responseEventId: response.descriptor.eventId,
|
|
109
|
+
responsePayloadId: response.descriptor.payloadId,
|
|
110
|
+
receiptPayloadId,
|
|
111
|
+
receiptBinding: r.binding,
|
|
112
|
+
});
|
|
113
|
+
return freeze({ retention: ack.retention, receiptJSON: ack.receiptJSON });
|
|
114
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readOriginalConfigureAttempt } from "./configureAttemptAuthority.js";
|
|
2
|
+
import { need } from "../configure/request.js";
|
|
3
|
+
/** Actual returned initial/recovered output identity, never a receipt registration API. */
|
|
4
|
+
export function readAdmittedConfigureAcknowledgement(token: object) {
|
|
5
|
+
need(arguments.length === 1);
|
|
6
|
+
const attempt = readOriginalConfigureAttempt(token),
|
|
7
|
+
completed = attempt.completion;
|
|
8
|
+
need(completed);
|
|
9
|
+
completed.guard();
|
|
10
|
+
return completed.view;
|
|
11
|
+
}
|
|
@@ -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
|
+
}
|