@fantastic.dev/better-stripe 0.91.0 → 0.93.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/actor.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/actor.js +46 -56
- package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js +61 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/actor.js +25 -4
- package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/capture.js +3 -2
- package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js +11 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +30 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +113 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +562 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +562 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +16 -3
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +6 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +406 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +294 -0
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- 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/renewalOperations/helpers.d.ts +236 -0
- package/dist/component/renewalOperations/helpers.d.ts.map +1 -0
- package/dist/component/renewalOperations/helpers.js +457 -0
- package/dist/component/renewalOperations/helpers.js.map +1 -0
- package/dist/component/renewalOperations/mutations.d.ts +252 -0
- package/dist/component/renewalOperations/mutations.d.ts.map +1 -0
- package/dist/component/renewalOperations/mutations.js +340 -0
- package/dist/component/renewalOperations/mutations.js.map +1 -0
- package/dist/component/renewalOperations/queries.d.ts +163 -0
- package/dist/component/renewalOperations/queries.d.ts.map +1 -0
- package/dist/component/renewalOperations/queries.js +167 -0
- package/dist/component/renewalOperations/queries.js.map +1 -0
- package/dist/component/renewalOperations/schema.d.ts +1988 -0
- package/dist/component/renewalOperations/schema.d.ts.map +1 -0
- package/dist/component/renewalOperations/schema.js +227 -0
- package/dist/component/renewalOperations/schema.js.map +1 -0
- package/dist/component/schema.d.ts +281 -0
- package/dist/component/schema.js +5 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +281 -0
- package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +281 -0
- package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
- package/dist/shared/renewalOperationJournal.d.ts +43 -0
- package/dist/shared/renewalOperationJournal.d.ts.map +1 -0
- package/dist/shared/renewalOperationJournal.js +294 -0
- package/dist/shared/renewalOperationJournal.js.map +1 -0
- package/docs/renewal-context-reads.md +152 -0
- package/docs/renewal-material-observation.md +32 -11
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/configure/actor.ts +63 -52
- package/src/client/billing/renewalAttach/internal/configure/ownedContinuation.ts +56 -0
- package/src/client/billing/renewalAttach/internal/observation/actor.ts +46 -3
- package/src/client/billing/renewalAttach/internal/observation/capture.ts +3 -2
- package/src/client/billing/renewalAttach/internal/observation/configureAcknowledgement.ts +20 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACK.integration.test.ts +36 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKControls.integration.test.ts +48 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKLifecycle.integration.test.ts +44 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfiguredHistory.integration.test.ts +34 -0
- package/src/client/billing/renewalAttach/internal/observation/types.ts +5 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +380 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +155 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +5 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +12 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDelegate.ts +38 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +8 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +10 -23
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKAssertions.ts +115 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKDeclarations.ts +141 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleAssertions.ts +74 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleDeclarations.ts +79 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleInstrumentation.ts +207 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleOperation.ts +494 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKOperation.ts +452 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryAssertions.ts +88 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryDeclarations.ts +170 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryNative.ts +99 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryOperation.ts +411 -0
- package/src/client/index.ts +24 -3
- package/src/component/_generated/api.ts +6 -0
- package/src/component/_generated/component.ts +450 -0
- package/src/component/renewalOperations/acknowledgement.fixtures.ts +552 -0
- package/src/component/renewalOperations/acknowledgement.test.ts +573 -0
- package/src/component/renewalOperations/acknowledgementReads.test.ts +442 -0
- package/src/component/renewalOperations/acknowledgementV2.test.ts +493 -0
- package/src/component/renewalOperations/acknowledgementV2Publication.test.ts +373 -0
- package/src/component/renewalOperations/basisBinding.test.ts +567 -0
- package/src/component/renewalOperations/basisLifecycle.test.ts +569 -0
- package/src/component/renewalOperations/boundHistory.test.ts +474 -0
- package/src/component/renewalOperations/helpers.ts +592 -0
- package/src/component/renewalOperations/historyReads.test.ts +595 -0
- package/src/component/renewalOperations/initialBasis.test.ts +578 -0
- package/src/component/renewalOperations/journal.test.ts +567 -0
- package/src/component/renewalOperations/mutations.ts +456 -0
- package/src/component/renewalOperations/payload.test.ts +589 -0
- package/src/component/renewalOperations/payloadEncoding.test.ts +592 -0
- package/src/component/renewalOperations/queries.ts +204 -0
- package/src/component/renewalOperations/schema.ts +268 -0
- package/src/component/renewalOperations/timingPolicy.fixtures.ts +193 -0
- package/src/component/renewalOperations/timingPolicy.test.ts +523 -0
- package/src/component/schema.ts +11 -0
- package/src/shared/renewalOperationJournal.ts +333 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { getConvexSize, type Value } from "convex/values";
|
|
2
|
+
import {
|
|
3
|
+
eventDigest,
|
|
4
|
+
objectNode,
|
|
5
|
+
scalarNode,
|
|
6
|
+
type CapturedNode,
|
|
7
|
+
} from "../client/billing/renewalAttach/internal/c10/eventCodec.js";
|
|
8
|
+
import { renewalSnapshot } from "../client/billing/renewalReplacementSnapshot.js";
|
|
9
|
+
|
|
10
|
+
function stop(): never {
|
|
11
|
+
throw Error("RENEWAL_JOURNAL_JSON_STOP");
|
|
12
|
+
}
|
|
13
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
14
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function text(value: unknown): value is string {
|
|
17
|
+
return typeof value === "string" && value.length > 0;
|
|
18
|
+
}
|
|
19
|
+
/** Intrinsic V2 policy DATA only; full C1/C2 validation is an async boundary. */
|
|
20
|
+
function validateAttachTimingPolicy(value: Record<string, unknown>): void {
|
|
21
|
+
const policy = value.timingPolicy;
|
|
22
|
+
const dispatch = value.dispatch;
|
|
23
|
+
const source = value.attachRequest;
|
|
24
|
+
if (
|
|
25
|
+
value.stage !== "attach" ||
|
|
26
|
+
Object.prototype.hasOwnProperty.call(value, "basis") ||
|
|
27
|
+
!Object.prototype.hasOwnProperty.call(value, "timingPolicy") ||
|
|
28
|
+
!record(policy) ||
|
|
29
|
+
!record(dispatch) ||
|
|
30
|
+
!record(source) ||
|
|
31
|
+
!record(source.preparation) ||
|
|
32
|
+
!record(source.preparation.expected)
|
|
33
|
+
)
|
|
34
|
+
stop();
|
|
35
|
+
const fields = [
|
|
36
|
+
"version",
|
|
37
|
+
"firstDispatchedAt",
|
|
38
|
+
"periodStart",
|
|
39
|
+
"periodEnd",
|
|
40
|
+
"workEndWallMs",
|
|
41
|
+
"endWallMs",
|
|
42
|
+
];
|
|
43
|
+
const keys = Object.keys(policy);
|
|
44
|
+
if (
|
|
45
|
+
keys.length !== fields.length ||
|
|
46
|
+
keys.some((key) => !fields.includes(key))
|
|
47
|
+
)
|
|
48
|
+
stop();
|
|
49
|
+
const {
|
|
50
|
+
firstDispatchedAt,
|
|
51
|
+
periodStart,
|
|
52
|
+
periodEnd,
|
|
53
|
+
workEndWallMs,
|
|
54
|
+
endWallMs,
|
|
55
|
+
} = policy;
|
|
56
|
+
const integer = (candidate: unknown): candidate is number =>
|
|
57
|
+
typeof candidate === "number" &&
|
|
58
|
+
Number.isSafeInteger(candidate) &&
|
|
59
|
+
candidate >= 0;
|
|
60
|
+
if (
|
|
61
|
+
policy.version !== 1 ||
|
|
62
|
+
!integer(firstDispatchedAt) ||
|
|
63
|
+
!integer(periodStart) ||
|
|
64
|
+
!integer(periodEnd) ||
|
|
65
|
+
!integer(workEndWallMs) ||
|
|
66
|
+
!integer(endWallMs) ||
|
|
67
|
+
periodEnd <= periodStart ||
|
|
68
|
+
endWallMs < workEndWallMs ||
|
|
69
|
+
firstDispatchedAt !== dispatch.firstDispatchedAt ||
|
|
70
|
+
firstDispatchedAt !== source.firstDispatchedAt ||
|
|
71
|
+
periodStart !== source.preparation.expected.periodStart ||
|
|
72
|
+
periodEnd !== source.preparation.expected.periodEnd
|
|
73
|
+
)
|
|
74
|
+
stop();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Canonical immutable authorization DATA only, never Source or provider proof. */
|
|
78
|
+
export function canonicalJournalRecord(raw: string) {
|
|
79
|
+
try {
|
|
80
|
+
if (raw.length > 500000) stop();
|
|
81
|
+
const parsed: unknown = JSON.parse(raw);
|
|
82
|
+
const value = renewalSnapshot(parsed);
|
|
83
|
+
if (
|
|
84
|
+
!record(value) ||
|
|
85
|
+
(value.schemaVersion !== 1 && value.schemaVersion !== 2)
|
|
86
|
+
)
|
|
87
|
+
stop();
|
|
88
|
+
if (value.schemaVersion === 2) validateAttachTimingPolicy(value);
|
|
89
|
+
const authorization = value.authorization;
|
|
90
|
+
if (
|
|
91
|
+
!record(authorization) ||
|
|
92
|
+
!text(authorization.scope) ||
|
|
93
|
+
!text(authorization.id) ||
|
|
94
|
+
typeof authorization.revision !== "number" ||
|
|
95
|
+
!Number.isSafeInteger(authorization.revision) ||
|
|
96
|
+
authorization.revision < 1 ||
|
|
97
|
+
!text(value.logicalOperationId) ||
|
|
98
|
+
!text(value.requestBinding)
|
|
99
|
+
)
|
|
100
|
+
stop();
|
|
101
|
+
const json = JSON.stringify(value);
|
|
102
|
+
if (json.length > 500000 || new TextEncoder().encode(json).length > 500000)
|
|
103
|
+
stop();
|
|
104
|
+
const normalized = {
|
|
105
|
+
json,
|
|
106
|
+
authorizationScope: authorization.scope,
|
|
107
|
+
authorizationId: authorization.id,
|
|
108
|
+
authorizationRevision: authorization.revision,
|
|
109
|
+
logicalOperationId: value.logicalOperationId,
|
|
110
|
+
requestBinding: value.requestBinding,
|
|
111
|
+
};
|
|
112
|
+
return value.schemaVersion === 2
|
|
113
|
+
? Object.freeze({ ...normalized, recordVersion: 2 as const })
|
|
114
|
+
: Object.freeze(normalized);
|
|
115
|
+
} catch {
|
|
116
|
+
return stop();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Complete immutable reservation DATA. This does not validate a live Owner. */
|
|
121
|
+
export function journalReservationMaterial(
|
|
122
|
+
full: ReturnType<typeof canonicalJournalRecord>,
|
|
123
|
+
) {
|
|
124
|
+
const value: unknown = JSON.parse(full.json);
|
|
125
|
+
if (!record(value)) stop();
|
|
126
|
+
const dispatch = value.dispatch;
|
|
127
|
+
const account = value.account;
|
|
128
|
+
const basis = value.basis;
|
|
129
|
+
if (
|
|
130
|
+
(value.stage !== "attach" && value.stage !== "configure") ||
|
|
131
|
+
!record(dispatch) ||
|
|
132
|
+
!text(dispatch.key) ||
|
|
133
|
+
typeof dispatch.firstDispatchedAt !== "number" ||
|
|
134
|
+
!Number.isSafeInteger(dispatch.firstDispatchedAt) ||
|
|
135
|
+
dispatch.firstDispatchedAt < 0 ||
|
|
136
|
+
!text(value.apiVersion) ||
|
|
137
|
+
dispatch.apiVersion !== value.apiVersion ||
|
|
138
|
+
dispatch.method !== "POST" ||
|
|
139
|
+
!text(dispatch.path) ||
|
|
140
|
+
!record(dispatch.payload) ||
|
|
141
|
+
!record(account) ||
|
|
142
|
+
(value.schemaVersion !== 2 && !record(basis)) ||
|
|
143
|
+
(account.mode !== "platform" && account.mode !== "connected") ||
|
|
144
|
+
dispatch.scope !== account.mode ||
|
|
145
|
+
typeof account.livemode !== "boolean" ||
|
|
146
|
+
(account.mode === "platform"
|
|
147
|
+
? account.stripeAccount !== null
|
|
148
|
+
: !text(account.stripeAccount))
|
|
149
|
+
)
|
|
150
|
+
stop();
|
|
151
|
+
admitJournalStrings([dispatch.key, value.apiVersion]);
|
|
152
|
+
const common = Object.freeze({
|
|
153
|
+
stage: value.stage,
|
|
154
|
+
key: dispatch.key,
|
|
155
|
+
apiVersion: value.apiVersion,
|
|
156
|
+
firstDispatchedAt: dispatch.firstDispatchedAt,
|
|
157
|
+
accountJSON: JSON.stringify(renewalSnapshot(account)),
|
|
158
|
+
});
|
|
159
|
+
if (value.schemaVersion === 2) {
|
|
160
|
+
if (value.stage !== "attach") stop();
|
|
161
|
+
validateAttachTimingPolicy(value);
|
|
162
|
+
return Object.freeze({
|
|
163
|
+
...common,
|
|
164
|
+
stage: "attach" as const,
|
|
165
|
+
recordVersion: 2 as const,
|
|
166
|
+
timingPolicyJSON: JSON.stringify(renewalSnapshot(value.timingPolicy)),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return Object.freeze({
|
|
170
|
+
...common,
|
|
171
|
+
basisJSON: JSON.stringify(renewalSnapshot(basis)),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Canonical six-field basis DATA and exact original-policy projection only. */
|
|
176
|
+
export function canonicalInitialBasis(policyJSON: string, basisJSON: string) {
|
|
177
|
+
try {
|
|
178
|
+
function capture(raw: string) {
|
|
179
|
+
if (raw.length > 500000) throw Error();
|
|
180
|
+
const parsed: unknown = JSON.parse(raw);
|
|
181
|
+
const value = renewalSnapshot(parsed);
|
|
182
|
+
const json = JSON.stringify(value);
|
|
183
|
+
if (
|
|
184
|
+
json.length > 500000 ||
|
|
185
|
+
new TextEncoder().encode(json).length > 500000
|
|
186
|
+
)
|
|
187
|
+
throw Error();
|
|
188
|
+
if (!record(value)) throw Error();
|
|
189
|
+
return { value, json };
|
|
190
|
+
}
|
|
191
|
+
const policy = capture(policyJSON);
|
|
192
|
+
const basis = capture(basisJSON);
|
|
193
|
+
const policyKeys = [
|
|
194
|
+
"version",
|
|
195
|
+
"firstDispatchedAt",
|
|
196
|
+
"periodStart",
|
|
197
|
+
"periodEnd",
|
|
198
|
+
"workEndWallMs",
|
|
199
|
+
"endWallMs",
|
|
200
|
+
];
|
|
201
|
+
const basisKeys = [
|
|
202
|
+
"startWallMs",
|
|
203
|
+
"startNsDecimal",
|
|
204
|
+
"workEndWallMs",
|
|
205
|
+
"workEndNsDecimal",
|
|
206
|
+
"endWallMs",
|
|
207
|
+
"endNsDecimal",
|
|
208
|
+
];
|
|
209
|
+
if (
|
|
210
|
+
Object.keys(policy.value).length !== policyKeys.length ||
|
|
211
|
+
Object.keys(policy.value).some((key) => !policyKeys.includes(key)) ||
|
|
212
|
+
Object.keys(basis.value).length !== basisKeys.length ||
|
|
213
|
+
Object.keys(basis.value).some((key) => !basisKeys.includes(key))
|
|
214
|
+
)
|
|
215
|
+
throw Error();
|
|
216
|
+
const integer = (value: unknown): value is number =>
|
|
217
|
+
typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
218
|
+
const { firstDispatchedAt, periodStart, periodEnd } = policy.value;
|
|
219
|
+
const policyWork = policy.value.workEndWallMs;
|
|
220
|
+
const policyEnd = policy.value.endWallMs;
|
|
221
|
+
const { startWallMs, workEndWallMs, endWallMs } = basis.value;
|
|
222
|
+
if (
|
|
223
|
+
policy.value.version !== 1 ||
|
|
224
|
+
!integer(firstDispatchedAt) ||
|
|
225
|
+
!integer(periodStart) ||
|
|
226
|
+
!integer(periodEnd) ||
|
|
227
|
+
periodEnd <= periodStart ||
|
|
228
|
+
!integer(policyWork) ||
|
|
229
|
+
!integer(policyEnd) ||
|
|
230
|
+
policyEnd < policyWork ||
|
|
231
|
+
!integer(startWallMs) ||
|
|
232
|
+
!integer(workEndWallMs) ||
|
|
233
|
+
!integer(endWallMs) ||
|
|
234
|
+
startWallMs >= workEndWallMs ||
|
|
235
|
+
workEndWallMs !== policyWork ||
|
|
236
|
+
endWallMs !== policyEnd
|
|
237
|
+
)
|
|
238
|
+
throw Error();
|
|
239
|
+
function u64(value: unknown): bigint {
|
|
240
|
+
if (
|
|
241
|
+
typeof value !== "string" ||
|
|
242
|
+
value.length > 20 ||
|
|
243
|
+
!/^(0|[1-9][0-9]*)$/.test(value)
|
|
244
|
+
)
|
|
245
|
+
throw Error();
|
|
246
|
+
const number = BigInt(value);
|
|
247
|
+
if (number > 18446744073709551615n) throw Error();
|
|
248
|
+
return number;
|
|
249
|
+
}
|
|
250
|
+
const startNs = u64(basis.value.startNsDecimal);
|
|
251
|
+
const workNs = u64(basis.value.workEndNsDecimal);
|
|
252
|
+
const endNs = u64(basis.value.endNsDecimal);
|
|
253
|
+
const workProjection =
|
|
254
|
+
startNs + (BigInt(workEndWallMs) - BigInt(startWallMs)) * 1000000n;
|
|
255
|
+
const endProjection =
|
|
256
|
+
startNs + (BigInt(endWallMs) - BigInt(startWallMs)) * 1000000n;
|
|
257
|
+
if (
|
|
258
|
+
workNs !== workProjection ||
|
|
259
|
+
endNs !== endProjection ||
|
|
260
|
+
startNs >= workNs ||
|
|
261
|
+
workNs > endNs
|
|
262
|
+
)
|
|
263
|
+
throw Error();
|
|
264
|
+
return Object.freeze({ policyJSON: policy.json, basisJSON: basis.json });
|
|
265
|
+
} catch {
|
|
266
|
+
throw Error("RENEWAL_JOURNAL_CONFLICT");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Existing C10 hash domain and whole budgets, for DATA consistency only. */
|
|
271
|
+
export async function canonicalJournalEvent(sequence: number, raw: string) {
|
|
272
|
+
try {
|
|
273
|
+
if (sequence !== 1 && sequence !== 2 && sequence !== 3) throw Error();
|
|
274
|
+
if (raw.length > 500000) throw Error();
|
|
275
|
+
const parsed: unknown = JSON.parse(raw);
|
|
276
|
+
const value = renewalSnapshot(parsed);
|
|
277
|
+
const json = JSON.stringify(value);
|
|
278
|
+
if (json.length > 500000 || new TextEncoder().encode(json).length > 500000)
|
|
279
|
+
throw Error();
|
|
280
|
+
function capture(value: unknown): CapturedNode {
|
|
281
|
+
if (value === null || typeof value !== "object") return scalarNode(value);
|
|
282
|
+
if (Array.isArray(value))
|
|
283
|
+
return Object.freeze({
|
|
284
|
+
kind: "array" as const,
|
|
285
|
+
entries: Object.freeze(
|
|
286
|
+
value.map((item, index) =>
|
|
287
|
+
Object.freeze([String(index), capture(item)] as const),
|
|
288
|
+
),
|
|
289
|
+
),
|
|
290
|
+
});
|
|
291
|
+
return objectNode(
|
|
292
|
+
Object.entries(value).map(
|
|
293
|
+
([key, item]) => [key, capture(item)] as const,
|
|
294
|
+
),
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
const binding = await eventDigest(
|
|
298
|
+
objectNode([
|
|
299
|
+
["sequence", scalarNode(sequence)],
|
|
300
|
+
["data", capture(value)],
|
|
301
|
+
]),
|
|
302
|
+
);
|
|
303
|
+
return Object.freeze({ sequence, binding, json });
|
|
304
|
+
} catch {
|
|
305
|
+
throw Error("RENEWAL_JOURNAL_CONFLICT");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Journal receiver boundary: exactly 1 MiB fits; strictly greater refuses. */
|
|
310
|
+
export function admitJournalValue(value: Value): void {
|
|
311
|
+
try {
|
|
312
|
+
if (getConvexSize(value) > 1048576) throw Error();
|
|
313
|
+
} catch {
|
|
314
|
+
throw Error("RENEWAL_JOURNAL_LIMIT");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Admit extracted database strings without changing the retained JSON model. */
|
|
319
|
+
export function admitJournalStrings(values: readonly string[]): void {
|
|
320
|
+
for (const value of values) {
|
|
321
|
+
for (let index = 0; index < value.length; index++) {
|
|
322
|
+
const unit = value.charCodeAt(index);
|
|
323
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
324
|
+
const next = value.charCodeAt(index + 1);
|
|
325
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
326
|
+
throw Error("RENEWAL_JOURNAL_ENCODING");
|
|
327
|
+
index++;
|
|
328
|
+
} else if (unit >= 0xdc00 && unit <= 0xdfff) {
|
|
329
|
+
throw Error("RENEWAL_JOURNAL_ENCODING");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|