@fantastic.dev/better-stripe 0.101.0 → 0.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +16 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.d.ts +7 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.js +117 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts +53 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js +198 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts +959 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.js +115 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +45 -3
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +21 -0
- package/src/client/billing/renewalAttach/internal/producer/configureAdmission.ts +179 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalData.ts +248 -0
- package/src/client/billing/renewalAttach/internal/producer/configureLineage.ts +166 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +13 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +2 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureAdmission.integration.test.ts +203 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureControls.integration.test.ts +566 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +316 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +61 -3
|
@@ -2632,6 +2632,14 @@ export declare function setupAllowance(): Promise<{
|
|
|
2632
2632
|
preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
|
|
2633
2633
|
requestKey: string;
|
|
2634
2634
|
result?: {
|
|
2635
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2636
|
+
retryable: false;
|
|
2637
|
+
status: "conflict";
|
|
2638
|
+
} | {
|
|
2639
|
+
reason: "policy_invalid";
|
|
2640
|
+
retryable: false;
|
|
2641
|
+
status: "rejected";
|
|
2642
|
+
} | {
|
|
2635
2643
|
operation: {
|
|
2636
2644
|
accountId: string;
|
|
2637
2645
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -2642,14 +2650,6 @@ export declare function setupAllowance(): Promise<{
|
|
|
2642
2650
|
} | {
|
|
2643
2651
|
enabled: boolean;
|
|
2644
2652
|
status: "unchanged";
|
|
2645
|
-
} | {
|
|
2646
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2647
|
-
retryable: false;
|
|
2648
|
-
status: "conflict";
|
|
2649
|
-
} | {
|
|
2650
|
-
reason: "policy_invalid";
|
|
2651
|
-
retryable: false;
|
|
2652
|
-
status: "rejected";
|
|
2653
2653
|
} | {
|
|
2654
2654
|
reason: "provider_pending";
|
|
2655
2655
|
retryable: true;
|
|
@@ -2660,6 +2660,14 @@ export declare function setupAllowance(): Promise<{
|
|
|
2660
2660
|
payload: import("convex/values").VString<string, "required">;
|
|
2661
2661
|
preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
|
|
2662
2662
|
result: import("convex/values").VUnion<{
|
|
2663
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2664
|
+
retryable: false;
|
|
2665
|
+
status: "conflict";
|
|
2666
|
+
} | {
|
|
2667
|
+
reason: "policy_invalid";
|
|
2668
|
+
retryable: false;
|
|
2669
|
+
status: "rejected";
|
|
2670
|
+
} | {
|
|
2663
2671
|
operation: {
|
|
2664
2672
|
accountId: string;
|
|
2665
2673
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -2670,14 +2678,6 @@ export declare function setupAllowance(): Promise<{
|
|
|
2670
2678
|
} | {
|
|
2671
2679
|
enabled: boolean;
|
|
2672
2680
|
status: "unchanged";
|
|
2673
|
-
} | {
|
|
2674
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2675
|
-
retryable: false;
|
|
2676
|
-
status: "conflict";
|
|
2677
|
-
} | {
|
|
2678
|
-
reason: "policy_invalid";
|
|
2679
|
-
retryable: false;
|
|
2680
|
-
status: "rejected";
|
|
2681
2681
|
} | {
|
|
2682
2682
|
reason: "provider_pending";
|
|
2683
2683
|
retryable: true;
|
|
@@ -219,12 +219,54 @@ changed predicates, removed class eligibility, copied DATA or unknown lineage
|
|
|
219
219
|
identities refuse. The same checks apply to cached views, and separate SDK roots
|
|
220
220
|
retain distinct output and receipt identities.
|
|
221
221
|
|
|
222
|
-
This reader
|
|
223
|
-
receipt.
|
|
224
|
-
|
|
222
|
+
This reader supplies private configure admission with the actual attachment
|
|
223
|
+
receipt. Admission uses a separately authorized stage operation and request/key.
|
|
224
|
+
Configure execution still requires its channels, transport, actors and complete
|
|
225
|
+
journal integration. The internal return record
|
|
225
226
|
does not establish delivery to a disconnected caller, qualify a provider profile
|
|
226
227
|
or create a public scheduling entrypoint.
|
|
227
228
|
|
|
229
|
+
## Private configure admission
|
|
230
|
+
|
|
231
|
+
The private initial invocation core accepts `admitConfigure(call, journal)` only
|
|
232
|
+
with the original winning child reservation call and its actual class-bound
|
|
233
|
+
journal. It spends that call before checking arity or parent custody. The parent
|
|
234
|
+
comes from the core's closure; callers cannot replace its Owner, receipt, ACK,
|
|
235
|
+
client, selector, clocks or basis. A copied admission view cannot reconstruct the
|
|
236
|
+
private identity.
|
|
237
|
+
|
|
238
|
+
Admission requires the actual returned attachment ACK from initial completion,
|
|
239
|
+
replay or no-POST resumption. A published receipt whose reply is still pending is
|
|
240
|
+
insufficient. The parent and child journals must share the actual checked SDK
|
|
241
|
+
root, root cell and component. Each retains its own checked Action receiver and
|
|
242
|
+
RPC pointers; different genuine Action contexts are supported.
|
|
243
|
+
|
|
244
|
+
The child retains the exact parent Owner, selected client, origin association,
|
|
245
|
+
clock functions and original basis. Admission performs no new selection, Owner
|
|
246
|
+
construction or origin capture. Normal Owner checks still sample its original
|
|
247
|
+
clocks. Complete C3/C6/C7 source, parent history and retained acknowledgement DATA
|
|
248
|
+
must agree, including typed dispatch/response contents before event hashing.
|
|
249
|
+
Every used reservation, load, history, event, acknowledgement and binding reply
|
|
250
|
+
receives complete bounded runtime DATA checks against the current source
|
|
251
|
+
contract. Generated attachment-only declarations and reference identities stay
|
|
252
|
+
unchanged; these checks do not establish genuine generation or deployed
|
|
253
|
+
compatibility.
|
|
254
|
+
|
|
255
|
+
The actual child basis transaction must commit and return its complete matching
|
|
256
|
+
descriptor. Reads after binding require the original basis, head zero and no
|
|
257
|
+
known child ACK. The no-ACK read precedes the final head read; no later journal
|
|
258
|
+
await precedes readiness. This is a read fence, with no atomic lock against
|
|
259
|
+
subsequent journal changes. Future execution must check its frontier again.
|
|
260
|
+
Owner retirement rejects a pending admission even if its basis mutation has
|
|
261
|
+
committed; retained DATA and failed or lost replies cannot remint the consumed
|
|
262
|
+
call.
|
|
263
|
+
|
|
264
|
+
The result is an opaque private view containing `owner`, `basisJSON` and
|
|
265
|
+
`operationalAuthority: false`. It supplies no configure transport, C10 channel,
|
|
266
|
+
preflight/write actor or public scheduling API. Those integrations remain
|
|
267
|
+
required, as do genuine generation and operational qualification. Production
|
|
268
|
+
Source profile arrays remain empty.
|
|
269
|
+
|
|
228
270
|
## Component operation journal
|
|
229
271
|
|
|
230
272
|
The component's `renewalOperations` functions retain host-authorized operation
|
package/package.json
CHANGED
|
@@ -391,3 +391,24 @@ export function captureInitialJournalSelection(
|
|
|
391
391
|
},
|
|
392
392
|
});
|
|
393
393
|
}
|
|
394
|
+
|
|
395
|
+
/** Same maintained SDK root; each Action retains its own checked RPC pointers. */
|
|
396
|
+
export function checkConfigureJournalAssociation(
|
|
397
|
+
parent: object,
|
|
398
|
+
child: object,
|
|
399
|
+
): void {
|
|
400
|
+
if (arguments.length !== 2) journalUnbound();
|
|
401
|
+
readCheckedJournalActionRPC(parent);
|
|
402
|
+
readCheckedJournalActionRPC(child);
|
|
403
|
+
const original = journalBindings.get(parent);
|
|
404
|
+
const next = journalBindings.get(child);
|
|
405
|
+
if (
|
|
406
|
+
!original ||
|
|
407
|
+
!next ||
|
|
408
|
+
original.root !== next.root ||
|
|
409
|
+
original.cell !== next.cell ||
|
|
410
|
+
original.rpc.component !== next.rpc.component ||
|
|
411
|
+
original.rpc.operationId === next.rpc.operationId
|
|
412
|
+
)
|
|
413
|
+
journalUnbound();
|
|
414
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
captureAttachDispatch,
|
|
3
|
+
captureAttachResponse,
|
|
4
|
+
captureAttachReceipt,
|
|
5
|
+
} from "../c10/eventCapture.js";
|
|
6
|
+
import { reconstructConfigurationV2 } from "../../../renewalV2/index.js";
|
|
7
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
8
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
9
|
+
import { closed } from "../operations/types.js";
|
|
10
|
+
import {
|
|
11
|
+
consumeConfigureLineage,
|
|
12
|
+
checkConfigureLineage,
|
|
13
|
+
finishConfigureLineage,
|
|
14
|
+
closeConfigureLineage,
|
|
15
|
+
} from "./configureLineage.js";
|
|
16
|
+
import {
|
|
17
|
+
checkOperationLoad,
|
|
18
|
+
checkEmptyConfigureHistory,
|
|
19
|
+
configureBasisDescriptor,
|
|
20
|
+
captureParentHistory,
|
|
21
|
+
checkParentAcknowledgement,
|
|
22
|
+
matchConfigureDATA,
|
|
23
|
+
requireConfigure,
|
|
24
|
+
object,
|
|
25
|
+
text,
|
|
26
|
+
} from "./configureJournalData.js";
|
|
27
|
+
|
|
28
|
+
/** Bind actual child custody to the live parent's exact basis; no execution profile. */
|
|
29
|
+
export async function captureConfigureAdmission(
|
|
30
|
+
parentToken: object,
|
|
31
|
+
call: unknown,
|
|
32
|
+
journal: unknown,
|
|
33
|
+
arity: number,
|
|
34
|
+
) {
|
|
35
|
+
const token = consumeConfigureLineage(parentToken, call, journal, arity);
|
|
36
|
+
const state = checkConfigureLineage(token);
|
|
37
|
+
const owned = ownedAwaitForInitialLineage(parentToken);
|
|
38
|
+
async function checked<T>(work: () => T | PromiseLike<T>): Promise<T> {
|
|
39
|
+
checkConfigureLineage(token);
|
|
40
|
+
const result = await owned(work);
|
|
41
|
+
checkConfigureLineage(token);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
async function parentFrontier() {
|
|
45
|
+
checkOperationLoad(
|
|
46
|
+
await checked(() => state.parent.journal.loadAuthorizedOperation()),
|
|
47
|
+
state.parentReservation,
|
|
48
|
+
state.parent.basisJSON,
|
|
49
|
+
);
|
|
50
|
+
const events = captureParentHistory(
|
|
51
|
+
await checked(() =>
|
|
52
|
+
state.parent.journal.readAttempt({
|
|
53
|
+
attemptId: state.parentReservation.attemptId,
|
|
54
|
+
}),
|
|
55
|
+
),
|
|
56
|
+
state.parentReservation,
|
|
57
|
+
);
|
|
58
|
+
for (const descriptor of events) {
|
|
59
|
+
const raw: unknown = await checked(() =>
|
|
60
|
+
state.parent.journal.readStageEvent({
|
|
61
|
+
attemptId: state.parentReservation.attemptId,
|
|
62
|
+
sequence: descriptor.sequence,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
const event = closed(raw, [...Object.keys(descriptor), "dataJSON"]);
|
|
66
|
+
const dataJSON = text(event.dataJSON);
|
|
67
|
+
const parsed: unknown = JSON.parse(dataJSON);
|
|
68
|
+
const receipt = object(state.acknowledgement.receipt);
|
|
69
|
+
// Typed privacy/bounds capture and complete C3 equality precede hashing.
|
|
70
|
+
if (descriptor.sequence === 1) {
|
|
71
|
+
captureAttachDispatch(parsed);
|
|
72
|
+
matchConfigureDATA(parsed, {
|
|
73
|
+
event: "dispatch",
|
|
74
|
+
stage: "attach",
|
|
75
|
+
request: receipt.request,
|
|
76
|
+
});
|
|
77
|
+
} else if (descriptor.sequence === 2) {
|
|
78
|
+
captureAttachResponse(parsed);
|
|
79
|
+
const response = object(parsed);
|
|
80
|
+
matchConfigureDATA(parsed, {
|
|
81
|
+
event: "response",
|
|
82
|
+
stage: "attach",
|
|
83
|
+
request: receipt.request,
|
|
84
|
+
body: receipt.providerSnapshot,
|
|
85
|
+
status: response.status,
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
captureAttachReceipt(parsed);
|
|
89
|
+
matchConfigureDATA(parsed, {
|
|
90
|
+
event: "receipt",
|
|
91
|
+
stage: "attach",
|
|
92
|
+
request: receipt.request,
|
|
93
|
+
receipt: state.acknowledgement.receipt,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const canonical = await checked(() =>
|
|
97
|
+
canonicalJournalEvent(descriptor.sequence, dataJSON),
|
|
98
|
+
);
|
|
99
|
+
requireConfigure(
|
|
100
|
+
canonical.json === dataJSON && canonical.binding === descriptor.binding,
|
|
101
|
+
);
|
|
102
|
+
matchConfigureDATA(raw, { ...descriptor, dataJSON });
|
|
103
|
+
}
|
|
104
|
+
checkParentAcknowledgement(
|
|
105
|
+
await checked(() => state.parent.journal.readProviderAcknowledgement()),
|
|
106
|
+
state.parentReservation,
|
|
107
|
+
events,
|
|
108
|
+
state.receiptJSON,
|
|
109
|
+
state.receiptBinding,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
async function childFrontier(allowUnbound: boolean) {
|
|
113
|
+
checkOperationLoad(
|
|
114
|
+
await checked(() => state.consumed.journal.loadAuthorizedOperation()),
|
|
115
|
+
state.reservation,
|
|
116
|
+
state.parent.basisJSON,
|
|
117
|
+
allowUnbound,
|
|
118
|
+
);
|
|
119
|
+
matchConfigureDATA(
|
|
120
|
+
await checked(() => state.consumed.journal.readProviderAcknowledgement()),
|
|
121
|
+
null,
|
|
122
|
+
);
|
|
123
|
+
// Best-effort frontier fence, not an atomic lock. No later journal await.
|
|
124
|
+
return checked(() =>
|
|
125
|
+
state.consumed.journal.readAttempt({
|
|
126
|
+
attemptId: state.reservation.attemptId,
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const rebuilt = await checked(() =>
|
|
132
|
+
reconstructConfigurationV2(state.configuration),
|
|
133
|
+
);
|
|
134
|
+
requireConfigure(rebuilt.material && "requestIdentity" in rebuilt.result);
|
|
135
|
+
const request = rebuilt.result;
|
|
136
|
+
matchConfigureDATA(state.source.request, request);
|
|
137
|
+
matchConfigureDATA(state.source.attachReceipt, rebuilt.material.receipt);
|
|
138
|
+
const { scope, apiVersion, method, path, payload, key, firstDispatchedAt } =
|
|
139
|
+
request;
|
|
140
|
+
matchConfigureDATA(state.original.dispatch, {
|
|
141
|
+
scope,
|
|
142
|
+
apiVersion,
|
|
143
|
+
method,
|
|
144
|
+
path,
|
|
145
|
+
payload,
|
|
146
|
+
key,
|
|
147
|
+
firstDispatchedAt,
|
|
148
|
+
});
|
|
149
|
+
requireConfigure(
|
|
150
|
+
state.reservation.requestBinding === request.requestIdentity.binding &&
|
|
151
|
+
state.reservation.key === key &&
|
|
152
|
+
state.reservation.apiVersion === apiVersion &&
|
|
153
|
+
state.reservation.firstDispatchedAt === firstDispatchedAt,
|
|
154
|
+
);
|
|
155
|
+
await parentFrontier();
|
|
156
|
+
checkEmptyConfigureHistory(await childFrontier(true), state.reservation);
|
|
157
|
+
const reply: unknown = await checked(() =>
|
|
158
|
+
state.consumed.journal.bindInitialBasis({
|
|
159
|
+
attemptId: state.reservation.attemptId,
|
|
160
|
+
policyJSON: state.reservation.timingPolicyJSON,
|
|
161
|
+
basisJSON: state.parent.basisJSON,
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
matchConfigureDATA(reply, {
|
|
165
|
+
status: "bound",
|
|
166
|
+
operationId: state.reservation.operationId,
|
|
167
|
+
initialBasis: configureBasisDescriptor(
|
|
168
|
+
state.reservation,
|
|
169
|
+
state.parent.basisJSON,
|
|
170
|
+
),
|
|
171
|
+
});
|
|
172
|
+
await parentFrontier();
|
|
173
|
+
checkEmptyConfigureHistory(await childFrontier(false), state.reservation);
|
|
174
|
+
return finishConfigureLineage(token);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
closeConfigureLineage(token);
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import type { Value } from "convex/values";
|
|
3
|
+
import {
|
|
4
|
+
admitJournalValue,
|
|
5
|
+
canonicalJournalRecord,
|
|
6
|
+
journalReservationMaterial,
|
|
7
|
+
} from "../../../../../shared/renewalOperationJournal.js";
|
|
8
|
+
import { closed } from "../operations/types.js";
|
|
9
|
+
|
|
10
|
+
export function configureAdmissionStop(): never {
|
|
11
|
+
throw Error("CONFIGURE_ADMISSION_UNBOUND");
|
|
12
|
+
}
|
|
13
|
+
export function requireConfigure(value: unknown): asserts value {
|
|
14
|
+
if (!value) configureAdmissionStop();
|
|
15
|
+
}
|
|
16
|
+
export function text(value: unknown): string {
|
|
17
|
+
requireConfigure(typeof value === "string" && value.length > 0);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
export function object(raw: unknown): Record<string, unknown> {
|
|
21
|
+
requireConfigure(
|
|
22
|
+
raw &&
|
|
23
|
+
typeof raw === "object" &&
|
|
24
|
+
!types.isProxy(raw) &&
|
|
25
|
+
!Array.isArray(raw),
|
|
26
|
+
);
|
|
27
|
+
const keys = Reflect.ownKeys(raw);
|
|
28
|
+
requireConfigure(
|
|
29
|
+
keys.length <= 10000 && keys.every((key) => typeof key === "string"),
|
|
30
|
+
);
|
|
31
|
+
return closed(
|
|
32
|
+
raw,
|
|
33
|
+
keys.filter((key): key is string => typeof key === "string"),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
/** Complete own-DATA equality, then the actual component return-value byte limit.
|
|
37
|
+
* Expected values are independently constructed finite wire DATA, not API types.
|
|
38
|
+
*/
|
|
39
|
+
export function matchConfigureDATA(raw: unknown, expected: unknown): void {
|
|
40
|
+
let nodes = 0;
|
|
41
|
+
function match(value: unknown, wanted: unknown, depth: number): void {
|
|
42
|
+
requireConfigure(++nodes <= 10000 && depth <= 40 && !types.isProxy(value));
|
|
43
|
+
if (wanted === null || typeof wanted !== "object") {
|
|
44
|
+
requireConfigure(value === wanted);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(wanted)) {
|
|
48
|
+
requireConfigure(
|
|
49
|
+
Array.isArray(value) &&
|
|
50
|
+
Object.getPrototypeOf(value) === Array.prototype &&
|
|
51
|
+
value.length === wanted.length,
|
|
52
|
+
);
|
|
53
|
+
const own = Reflect.ownKeys(value);
|
|
54
|
+
requireConfigure(own.length === wanted.length + 1);
|
|
55
|
+
for (let index = 0; index < wanted.length; index++) {
|
|
56
|
+
const d = Object.getOwnPropertyDescriptor(value, String(index));
|
|
57
|
+
requireConfigure(d && d.enumerable && "value" in d);
|
|
58
|
+
match(d.value, wanted[index], depth + 1);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const actual = closed(value, Object.keys(wanted));
|
|
63
|
+
for (const [key, child] of Object.entries(wanted))
|
|
64
|
+
match(actual[key], child, depth + 1);
|
|
65
|
+
}
|
|
66
|
+
match(raw, expected, 0);
|
|
67
|
+
// The complete finite graph has just been matched, before this DATA-only cast.
|
|
68
|
+
admitJournalValue(expected as Value);
|
|
69
|
+
}
|
|
70
|
+
const reservationKeys = [
|
|
71
|
+
"operationId",
|
|
72
|
+
"attemptId",
|
|
73
|
+
"payloadId",
|
|
74
|
+
"authorizationScope",
|
|
75
|
+
"authorizationId",
|
|
76
|
+
"authorizationRevision",
|
|
77
|
+
"logicalOperationId",
|
|
78
|
+
"requestBinding",
|
|
79
|
+
"key",
|
|
80
|
+
"apiVersion",
|
|
81
|
+
"accountJSON",
|
|
82
|
+
"firstDispatchedAt",
|
|
83
|
+
"ordinal",
|
|
84
|
+
"preparedRevision",
|
|
85
|
+
"committedRevision",
|
|
86
|
+
"recordJSON",
|
|
87
|
+
"stage",
|
|
88
|
+
"recordVersion",
|
|
89
|
+
"timingPolicyJSON",
|
|
90
|
+
];
|
|
91
|
+
/** Rebuild the complete current wire contract; generated references stay untouched. */
|
|
92
|
+
export function captureOperationalReservation(
|
|
93
|
+
raw: unknown,
|
|
94
|
+
stage: "attach" | "configure",
|
|
95
|
+
) {
|
|
96
|
+
const own = closed(raw, reservationKeys);
|
|
97
|
+
const full = canonicalJournalRecord(text(own.recordJSON));
|
|
98
|
+
const material = journalReservationMaterial(full);
|
|
99
|
+
requireConfigure("recordVersion" in material && material.stage === stage);
|
|
100
|
+
const id = (value: unknown) => {
|
|
101
|
+
const result = text(value);
|
|
102
|
+
requireConfigure(result.length <= 255);
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
const result = Object.freeze({
|
|
106
|
+
operationId: id(own.operationId),
|
|
107
|
+
attemptId: id(own.attemptId),
|
|
108
|
+
payloadId: id(own.payloadId),
|
|
109
|
+
authorizationScope: full.authorizationScope,
|
|
110
|
+
authorizationId: full.authorizationId,
|
|
111
|
+
authorizationRevision: full.authorizationRevision,
|
|
112
|
+
logicalOperationId: full.logicalOperationId,
|
|
113
|
+
requestBinding: full.requestBinding,
|
|
114
|
+
ordinal: 1 as const,
|
|
115
|
+
preparedRevision: 0 as const,
|
|
116
|
+
committedRevision: 1 as const,
|
|
117
|
+
recordJSON: full.json,
|
|
118
|
+
...material,
|
|
119
|
+
stage,
|
|
120
|
+
});
|
|
121
|
+
matchConfigureDATA(raw, result);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
export type OperationalReservationDATA = ReturnType<
|
|
125
|
+
typeof captureOperationalReservation
|
|
126
|
+
>;
|
|
127
|
+
export function configureBasisDescriptor(
|
|
128
|
+
reservation: OperationalReservationDATA,
|
|
129
|
+
basisJSON: string,
|
|
130
|
+
) {
|
|
131
|
+
return {
|
|
132
|
+
version: 1 as const,
|
|
133
|
+
attemptId: reservation.attemptId,
|
|
134
|
+
sourcePayloadId: reservation.payloadId,
|
|
135
|
+
stage: reservation.stage,
|
|
136
|
+
policyJSON: reservation.timingPolicyJSON,
|
|
137
|
+
basisJSON,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export function checkOperationLoad(
|
|
141
|
+
raw: unknown,
|
|
142
|
+
reservation: OperationalReservationDATA,
|
|
143
|
+
basisJSON: string,
|
|
144
|
+
allowUnbound = false,
|
|
145
|
+
) {
|
|
146
|
+
const own = closed(raw, [
|
|
147
|
+
"operationId",
|
|
148
|
+
"recordJSON",
|
|
149
|
+
"revision",
|
|
150
|
+
"recordVersion",
|
|
151
|
+
"activeAttempt",
|
|
152
|
+
"initialBasis",
|
|
153
|
+
]);
|
|
154
|
+
const { recordJSON, ...summary } = reservation;
|
|
155
|
+
const basis =
|
|
156
|
+
allowUnbound && own.initialBasis === null
|
|
157
|
+
? null
|
|
158
|
+
: configureBasisDescriptor(reservation, basisJSON);
|
|
159
|
+
matchConfigureDATA(raw, {
|
|
160
|
+
operationId: reservation.operationId,
|
|
161
|
+
recordJSON,
|
|
162
|
+
revision: 1,
|
|
163
|
+
recordVersion: 2,
|
|
164
|
+
activeAttempt: summary,
|
|
165
|
+
initialBasis: basis,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
export function checkEmptyConfigureHistory(
|
|
169
|
+
raw: unknown,
|
|
170
|
+
reservation: OperationalReservationDATA,
|
|
171
|
+
) {
|
|
172
|
+
matchConfigureDATA(raw, { reservation, events: [] });
|
|
173
|
+
}
|
|
174
|
+
export function captureParentHistory(
|
|
175
|
+
raw: unknown,
|
|
176
|
+
reservation: OperationalReservationDATA,
|
|
177
|
+
) {
|
|
178
|
+
const own = closed(raw, ["reservation", "events"]);
|
|
179
|
+
requireConfigure(
|
|
180
|
+
!types.isProxy(own.events) &&
|
|
181
|
+
Array.isArray(own.events) &&
|
|
182
|
+
Object.getPrototypeOf(own.events) === Array.prototype &&
|
|
183
|
+
own.events.length === 3,
|
|
184
|
+
);
|
|
185
|
+
const events = Array.from({ length: 3 }, (_, index) => {
|
|
186
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
187
|
+
own.events,
|
|
188
|
+
String(index),
|
|
189
|
+
);
|
|
190
|
+
requireConfigure(
|
|
191
|
+
descriptor && descriptor.enumerable && "value" in descriptor,
|
|
192
|
+
);
|
|
193
|
+
const event = closed(descriptor.value, [
|
|
194
|
+
"operationId",
|
|
195
|
+
"attemptId",
|
|
196
|
+
"stage",
|
|
197
|
+
"sourcePayloadId",
|
|
198
|
+
"sequence",
|
|
199
|
+
"binding",
|
|
200
|
+
"payloadId",
|
|
201
|
+
"eventId",
|
|
202
|
+
]);
|
|
203
|
+
return {
|
|
204
|
+
operationId: reservation.operationId,
|
|
205
|
+
attemptId: reservation.attemptId,
|
|
206
|
+
stage: "attach" as const,
|
|
207
|
+
sourcePayloadId: reservation.payloadId,
|
|
208
|
+
sequence:
|
|
209
|
+
index === 0 ? (1 as const) : index === 1 ? (2 as const) : (3 as const),
|
|
210
|
+
binding: text(event.binding),
|
|
211
|
+
payloadId: text(event.payloadId),
|
|
212
|
+
eventId: text(event.eventId),
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
requireConfigure(
|
|
216
|
+
new Set(events.map((event) => event.eventId)).size === 3 &&
|
|
217
|
+
new Set(events.map((event) => event.payloadId)).size === 3,
|
|
218
|
+
);
|
|
219
|
+
matchConfigureDATA(raw, { reservation, events });
|
|
220
|
+
return events;
|
|
221
|
+
}
|
|
222
|
+
export function checkParentAcknowledgement(
|
|
223
|
+
raw: unknown,
|
|
224
|
+
reservation: OperationalReservationDATA,
|
|
225
|
+
events: ReturnType<typeof captureParentHistory>,
|
|
226
|
+
receiptJSON: string,
|
|
227
|
+
receiptBinding: string,
|
|
228
|
+
) {
|
|
229
|
+
const own = closed(raw, ["retention", "receiptJSON"]);
|
|
230
|
+
const retained = object(own.retention);
|
|
231
|
+
matchConfigureDATA(raw, {
|
|
232
|
+
receiptJSON,
|
|
233
|
+
retention: {
|
|
234
|
+
status: "retained",
|
|
235
|
+
operationId: reservation.operationId,
|
|
236
|
+
schemaVersion: 1,
|
|
237
|
+
stage: "attach",
|
|
238
|
+
attemptId: reservation.attemptId,
|
|
239
|
+
sourcePayloadId: reservation.payloadId,
|
|
240
|
+
dispatchEventId: events[0].eventId,
|
|
241
|
+
dispatchPayloadId: events[0].payloadId,
|
|
242
|
+
responseEventId: events[1].eventId,
|
|
243
|
+
responsePayloadId: events[1].payloadId,
|
|
244
|
+
receiptPayloadId: text(retained.receiptPayloadId),
|
|
245
|
+
receiptBinding,
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
}
|