@fleetless/contracts 12.1.0-next.1 → 13.0.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/artifacts/openapi.json +15968 -13701
  3. package/artifacts/routes.json +123 -1
  4. package/artifacts/schema/billing-decision-display-response.schema.json +749 -504
  5. package/artifacts/schema/billing-decision-period.schema.json +573 -504
  6. package/artifacts/schema/billing-decision-snapshot.schema.json +749 -504
  7. package/artifacts/schema/journal-access-proof.schema.json +342 -0
  8. package/artifacts/schema/journal-deletion-manifest.schema.json +2103 -0
  9. package/artifacts/schema/journal-evidence-ref.schema.json +596 -0
  10. package/artifacts/schema/journal-export-item.schema.json +2910 -0
  11. package/artifacts/schema/journal-final-seal-body.schema.json +160 -0
  12. package/artifacts/schema/journal-final-seal.schema.json +169 -0
  13. package/artifacts/schema/journal-first-checkpoint-body.schema.json +101 -0
  14. package/artifacts/schema/journal-first-checkpoint.schema.json +111 -0
  15. package/artifacts/schema/journal-generation-checkpoint-body.schema.json +88 -0
  16. package/artifacts/schema/journal-generation-checkpoint.schema.json +97 -0
  17. package/artifacts/schema/journal-intent-v2-body.schema.json +4166 -0
  18. package/artifacts/schema/journal-intent-v2.schema.json +4616 -0
  19. package/artifacts/schema/journal-manifest-batch.schema.json +1236 -0
  20. package/artifacts/schema/journal-manifest-binding.schema.json +3541 -0
  21. package/artifacts/schema/journal-manifest-entry.schema.json +106 -0
  22. package/artifacts/schema/journal-manifest-intent-projection.schema.json +1428 -0
  23. package/artifacts/schema/journal-manifest-row.schema.json +578 -0
  24. package/artifacts/schema/journal-manifest-scope.schema.json +135 -0
  25. package/artifacts/schema/journal-mirror-attempt.schema.json +182 -0
  26. package/artifacts/schema/journal-mixed-export.schema.json +3115 -0
  27. package/artifacts/schema/journal-registry-activation-receipt-body.schema.json +304 -0
  28. package/artifacts/schema/journal-registry-activation-receipt.schema.json +324 -0
  29. package/artifacts/schema/journal-registry-transition-body.schema.json +113 -0
  30. package/artifacts/schema/journal-registry-transition.schema.json +123 -0
  31. package/artifacts/schema/journal-replay-receipt-body.schema.json +1252 -0
  32. package/artifacts/schema/journal-replay-receipt.schema.json +1261 -0
  33. package/artifacts/schema/journal-v2-activation-checkpoint-body.schema.json +99 -0
  34. package/artifacts/schema/journal-v2-activation-checkpoint.schema.json +108 -0
  35. package/artifacts/schema/legal-acceptance-list-response.schema.json +31 -2
  36. package/artifacts/schema/legal-acceptance-version-row.schema.json +31 -2
  37. package/artifacts/schema/legal-offer-conflict-details.schema.json +32 -0
  38. package/artifacts/schema/legal-offer-decision-lookup-query.schema.json +16 -0
  39. package/artifacts/schema/legal-offer-decision-request.schema.json +37 -0
  40. package/artifacts/schema/legal-offer-decision-result.schema.json +409 -0
  41. package/artifacts/schema/legal-offer-decision-snapshot.schema.json +678 -0
  42. package/artifacts/schema/legal-offer-display-request.schema.json +16 -0
  43. package/artifacts/schema/legal-offer-display-response.schema.json +712 -0
  44. package/artifacts/schema/legal-offer-list-query.schema.json +17 -0
  45. package/artifacts/schema/legal-offer-list-response.schema.json +347 -0
  46. package/artifacts/schema/legal-offer-summary.schema.json +321 -0
  47. package/artifacts/schema/plan-change-prepare-response.schema.json +749 -504
  48. package/dist/billing.d.ts +361 -275
  49. package/dist/billing.js +25 -4
  50. package/dist/errors.d.ts +1 -1
  51. package/dist/errors.js +2 -0
  52. package/dist/index.d.ts +12 -0
  53. package/dist/index.js +6 -0
  54. package/dist/journal-controls.d.ts +228 -0
  55. package/dist/journal-controls.js +111 -0
  56. package/dist/journal-intents.d.ts +1695 -0
  57. package/dist/journal-intents.js +97 -0
  58. package/dist/journal-manifests.d.ts +1670 -0
  59. package/dist/journal-manifests.js +182 -0
  60. package/dist/journal-restore.d.ts +1871 -0
  61. package/dist/journal-restore.js +324 -0
  62. package/dist/journal-seals.d.ts +147 -0
  63. package/dist/journal-seals.js +89 -0
  64. package/dist/legal-acceptances.d.ts +4 -0
  65. package/dist/legal-acceptances.js +9 -2
  66. package/dist/legal-offers.d.ts +468 -0
  67. package/dist/legal-offers.js +91 -0
  68. package/dist/realtime.d.ts +2 -2
  69. package/dist/routes.js +54 -0
  70. package/package.json +1 -1
@@ -0,0 +1,324 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { z } from 'zod';
3
+ import { journalIntentV2Body } from './journal-intents.js';
4
+ // Decoded restricted restore records. Shape validation does not verify exact
5
+ // protected versions, original bytes, signatures, or mirror readback.
6
+ const hash = z.string().regex(/^[0-9a-f]{64}$/);
7
+ const uuid = z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
8
+ const opaqueId = z.string().min(1);
9
+ const utcMillis = z.iso.datetime({ precision: 3 });
10
+ const count = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
11
+ const positiveInteger = z.number().int().min(1).max(Number.MAX_SAFE_INTEGER);
12
+ const signature = z.string().regex(/^[A-Za-z0-9_-]{85}[AQgw]$/);
13
+ const lsn = z.string().regex(/^(?:0|[1-9A-F][0-9A-F]{0,7})\/(?:0|[1-9A-F][0-9A-F]{0,7})$/);
14
+ const bytesB64Url = z.string().min(1).regex(/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-][AQgw]|[A-Za-z0-9_-]{2}[AEIMQUYcgkosw048])?$/);
15
+ const recoveryPoint = z.discriminatedUnion('kind', [
16
+ z.strictObject({ kind: z.literal('timestamp'), at: utcMillis }),
17
+ z.strictObject({ kind: z.literal('lsn'), timeline: positiveInteger, lsn, at: utcMillis }),
18
+ ]);
19
+ const mirrorCommon = { attempt_id: opaqueId, observed_at: utcMillis };
20
+ const objectVersion = z.strictObject({
21
+ ...mirrorCommon, type: z.literal('object_version'), version_id: opaqueId,
22
+ delete_marker: z.literal(false), stored_sha256: hash, readback_sha256: hash,
23
+ readback_at: utcMillis, effective_retain_until: utcMillis,
24
+ object_lock_mode: z.literal('COMPLIANCE'),
25
+ });
26
+ const unexpectedMarker = z.strictObject({
27
+ ...mirrorCommon, type: z.literal('delete_marker'), version_id: opaqueId,
28
+ delete_marker: z.literal(true), failure_code: z.literal('UNEXPECTED_DELETE_MARKER'),
29
+ });
30
+ const inventoryError = z.union([
31
+ z.strictObject({ ...mirrorCommon, type: z.literal('inventory_error'),
32
+ failure_code: z.enum(['MISSING_VERSION', 'INCOMPLETE_LISTING']), version_id: opaqueId.optional() }),
33
+ z.strictObject({ ...mirrorCommon, type: z.literal('inventory_error'),
34
+ failure_code: z.enum(['CONFLICTING_BYTES', 'UNKNOWN_RETENTION']), version_id: opaqueId }),
35
+ ]);
36
+ /** Failed arms remain serializable inventory evidence, never replay coverage. */
37
+ export const journalMirrorAttempt = z.union([objectVersion, unexpectedMarker, inventoryError]);
38
+ const itemCommon = {
39
+ generation: uuid, stored_bytes_b64url: bytesB64Url, mirror_inventory_digest: hash,
40
+ };
41
+ const sequenced = { sequence: positiveInteger, previous_hash: hash, record_hash: hash };
42
+ function mirrored(shape) {
43
+ return [
44
+ z.strictObject({ ...itemCommon, ...shape, mirror_verdict: z.literal('complete'), mirror_attempts: z.array(objectVersion).min(1) }),
45
+ z.strictObject({ ...itemCommon, ...shape, mirror_verdict: z.literal('failed'), mirror_attempts: z.array(journalMirrorAttempt).min(1) }),
46
+ ];
47
+ }
48
+ const exportItemShape = z.union([
49
+ ...mirrored({ type: z.literal('c0'), schema: z.literal('fleetless.journal-first-checkpoint.v1'), sequence: z.literal(0), checkpoint_hash: hash }),
50
+ ...mirrored({ type: z.literal('intent_v1'), schema: z.literal('fleetless.deletion-intent.v1'), ...sequenced, operation_id: uuid }),
51
+ ...mirrored({ type: z.literal('intent_v2'), schema: z.literal('fleetless.deletion-intent.v2'), ...sequenced, operation_id: uuid }),
52
+ ...mirrored({ type: z.literal('registry_transition'), schema: z.literal('fleetless.registry-transition.v1'), ...sequenced }),
53
+ ...mirrored({ type: z.literal('v2_activation_checkpoint'), schema: z.literal('fleetless.journal-v2-activation-checkpoint.v1'), ...sequenced }),
54
+ ...mirrored({ type: z.literal('generation_checkpoint'), schema: z.literal('fleetless.journal-generation-checkpoint.v1'), ...sequenced }),
55
+ ...mirrored({ type: z.literal('registry_activation_receipt'), schema: z.literal('fleetless.registry-activation-receipt.v1'), control_sequence: count, control_hash: hash, receipt_hash: hash }),
56
+ ...mirrored({ type: z.literal('seal'), schema: z.literal('fleetless.journal-final-seal.v1'), final_sequence: count, final_hash: hash, seal_hash: hash }),
57
+ ]);
58
+ /** A failed mirror attempt remains visible but cannot be marked complete. */
59
+ export const journalExportItem = exportItemShape.superRefine((item, ctx) => {
60
+ const attempts = item.mirror_attempts;
61
+ if (new Set(attempts.map((attempt) => attempt.attempt_id)).size !== attempts.length) {
62
+ ctx.addIssue({ code: 'custom', path: ['mirror_attempts'], message: 'Mirror attempt IDs must be unique' });
63
+ }
64
+ if (item.mirror_verdict === 'complete' && attempts.some((attempt) => attempt.type !== 'object_version' || attempt.stored_sha256 !== attempt.readback_sha256)) {
65
+ ctx.addIssue({ code: 'custom', path: ['mirror_verdict'], message: 'Complete requires matching object-version readbacks only' });
66
+ }
67
+ }).describe('JSON Schema consumers must also reject complete coverage with marker/error arms or unequal readbacks, and verify exact stored bytes and all versions.');
68
+ /** The mixed container does not re-sign historical v1 bytes or grant replay permission. */
69
+ export const journalMixedExport = z.strictObject({
70
+ schema: z.literal('fleetless.journal-mixed-export.v1'), environment: opaqueId,
71
+ restore_attempt_id: opaqueId, source_db_timeline: positiveInteger, source_db_lsn: lsn,
72
+ selected_recovery_point: recoveryPoint, oldest_mapping_bearing_point: recoveryPoint,
73
+ copy_inventory_digest: hash, copy_coverage_digest: hash,
74
+ lower_sequence: count, lower_hash: hash, upper_sequence: count, upper_hash: hash,
75
+ registry_chain_digest: hash, pinned_standby_id: opaqueId, pinned_standby_head_hash: hash,
76
+ seal_hash: hash, seal_version_id: opaqueId, items: z.array(journalExportItem).min(1),
77
+ }).superRefine((value, ctx) => {
78
+ const problem = (message, path) => ctx.addIssue({ code: 'custom', message, path });
79
+ if (value.lower_sequence > value.upper_sequence)
80
+ problem('Invalid committed range', ['lower_sequence']);
81
+ const first = value.items[0];
82
+ if (value.lower_sequence === 0 && (first.type !== 'c0' || first.checkpoint_hash !== value.lower_hash)) {
83
+ problem('Sequence zero requires the C0 lower anchor', ['items', 0]);
84
+ }
85
+ const last = value.items[value.items.length - 1];
86
+ if (last.type !== 'seal' || last.final_sequence !== value.upper_sequence ||
87
+ last.final_hash !== value.upper_hash || last.seal_hash !== value.seal_hash) {
88
+ problem('Final item must bind the upper head and seal', ['items']);
89
+ }
90
+ if (value.items.filter((item) => item.type === 'seal').length !== 1)
91
+ problem('Exactly one final seal is required', ['items']);
92
+ value.items.forEach((item, index) => {
93
+ if (item.type === 'registry_activation_receipt') {
94
+ const prior = value.items[index - 1];
95
+ if (!prior || (prior.type !== 'c0' && prior.type !== 'registry_transition') ||
96
+ item.control_sequence !== prior.sequence || item.control_hash !==
97
+ (prior.type === 'c0' ? prior.checkpoint_hash : prior.record_hash)) {
98
+ problem('Activation receipt must immediately bind C0 or its transition', ['items', index]);
99
+ }
100
+ }
101
+ if (item.type === 'c0' || item.type === 'registry_transition') {
102
+ if (value.items[index + 1]?.type !== 'registry_activation_receipt') {
103
+ problem('C0 and transitions require activation receipts', ['items', index]);
104
+ }
105
+ }
106
+ });
107
+ }).describe('JSON Schema consumers must also verify ordered C0/transition receipts, seal anchors, original v1 bytes, mirror coverage, standby and #844 copy inventory.');
108
+ const evidenceCommon = {
109
+ evidence_id: opaqueId, version_id: opaqueId, sha256: hash, observed_at: utcMillis,
110
+ bundle_digest: hash, seal_hash: hash, target_fingerprint: hash,
111
+ };
112
+ const operationBinding = { binding_scope: z.literal('operation'), operation_id: uuid };
113
+ const globalBinding = { binding_scope: z.literal('global') };
114
+ const probeFields = { surface_id: opaqueId, outcome: z.enum(['denied', 'allowed', 'failed']), credential_class: opaqueId };
115
+ const probeGlobal = z.strictObject({
116
+ ...evidenceCommon, ...globalBinding, type: z.literal('probe_ref'),
117
+ ...probeFields, surface_id: z.literal('source.version_read'),
118
+ });
119
+ const probeOperation = z.strictObject({ ...evidenceCommon, ...operationBinding, type: z.literal('probe_ref'), ...probeFields });
120
+ const policyFields = {
121
+ ...evidenceCommon, ...operationBinding, type: z.literal('policy_ref'),
122
+ evaluated_at: utcMillis, negative_export_probe_ids: z.array(opaqueId).min(1),
123
+ };
124
+ const policyDeadline = z.strictObject({
125
+ ...policyFields, policy_class: z.literal('retrieval_deadline'), effective_deadline: utcMillis,
126
+ });
127
+ const policyDecision = z.strictObject({
128
+ ...policyFields, policy_class: z.literal('section_6_6_decision'),
129
+ decision_id: opaqueId, section_11_rights_digest: hash,
130
+ });
131
+ const preservation = z.strictObject({
132
+ ...evidenceCommon, ...operationBinding, type: z.literal('preservation_ref'),
133
+ manifest_id: uuid, manifest_version_id: opaqueId, manifest_hash: hash,
134
+ frozen_unaffected_digest: hash, target_unaffected_digest: hash,
135
+ });
136
+ const copy = z.strictObject({
137
+ ...evidenceCommon, ...globalBinding, type: z.literal('copy_ref'),
138
+ copy_inventory_digest: hash, source_isolation_digest: hash,
139
+ target_inventory_digest: hash, last_restorable_deadline: utcMillis,
140
+ });
141
+ const closure = z.strictObject({
142
+ ...evidenceCommon, ...globalBinding, type: z.literal('closure_ref'),
143
+ restore_attempt_id: opaqueId, attempt_descriptor_hash: hash,
144
+ attempt_descriptor_version_id: opaqueId, original_restore_at: utcMillis,
145
+ original_affected_count: count, closure_row_digest: hash, closure_commit_marker: opaqueId,
146
+ schema_preflight_digest: hash, zero_open_sessions_count: z.literal(0),
147
+ zero_open_sessions_at: utcMillis,
148
+ });
149
+ /** Global refs forbid an operation; access, policy and preservation refs require one. */
150
+ export const journalEvidenceRef = z.union([
151
+ probeGlobal, probeOperation, policyDeadline, policyDecision, preservation, copy, closure,
152
+ ]);
153
+ const intentKindValues = journalIntentV2Body.options.map((branch) => branch.shape.kind.value);
154
+ const intentKind = z.enum(intentKindValues);
155
+ // These kinds have an unconditional target surface. Other object/authority
156
+ // obligations depend on the signed kind registry and protected manifest.
157
+ const objectRequiredKinds = new Set(['app_logo.delete', 'organization_export.expire']);
158
+ const authorityRequiredKinds = new Set([
159
+ 'server_key.revoke', 'mcp_grant.revoke', 'mcp_central_grant.revoke',
160
+ 'mcp_client.revoke', 'mcp_central_client.revoke',
161
+ 'instance.serial_lock', 'instance.serial_rotate_old', 'instance.license_revoke',
162
+ 'instance.reporter_key_revoke', 'instance.instance_key_revoke',
163
+ ]);
164
+ const operationResult = z.strictObject({
165
+ sequence: positiveInteger, operation_id: uuid, kind: intentKind,
166
+ apply_result: z.enum(['applied', 'already-effective', 'failed']),
167
+ database: z.enum(['absent', 'revoked', 'failed', 'not-applicable']),
168
+ customer_target_object: z.enum(['absent', 'failed', 'not-applicable']),
169
+ authority: z.enum(['revoked', 'failed', 'not-applicable']),
170
+ evidence_ref_ids: z.array(opaqueId),
171
+ });
172
+ const proofCommon = { operation_id: uuid, probe_ref_ids: z.array(opaqueId) };
173
+ const passingProofCommon = { ...proofCommon, probe_ref_ids: z.array(opaqueId).min(1) };
174
+ const wholeProof = z.union([
175
+ z.strictObject({ ...passingProofCommon, kind: z.literal('organization.erase'), affected_verdict: z.literal('denied'), unaffected_verdict: z.literal('not-applicable') }),
176
+ z.strictObject({ ...proofCommon, kind: z.literal('organization.erase'), affected_verdict: z.literal('failed'), unaffected_verdict: z.enum(['not-applicable', 'failed']) }),
177
+ z.strictObject({ ...proofCommon, kind: z.literal('organization.erase'), affected_verdict: z.literal('denied'), unaffected_verdict: z.literal('failed') }),
178
+ ]);
179
+ const scopeProofCommon = { ...proofCommon, kind: z.literal('organization.scope_erase') };
180
+ const passingScopeProofCommon = { ...passingProofCommon, kind: z.literal('organization.scope_erase') };
181
+ const scopeAllowed = z.strictObject({
182
+ ...passingScopeProofCommon, affected_verdict: z.literal('denied'), unaffected_verdict: z.literal('allowed'),
183
+ unaffected_state_ref_id: opaqueId,
184
+ });
185
+ const scopePolicyDenied = z.strictObject({
186
+ ...passingScopeProofCommon, affected_verdict: z.literal('denied'), unaffected_verdict: z.literal('policy-denied'),
187
+ unaffected_state_ref_id: opaqueId, policy_ref_id: opaqueId,
188
+ });
189
+ const scopeFailed = z.union([
190
+ z.strictObject({ ...scopeProofCommon, affected_verdict: z.literal('failed'),
191
+ unaffected_verdict: z.enum(['allowed', 'failed']), unaffected_state_ref_id: opaqueId.optional() }),
192
+ z.strictObject({ ...scopeProofCommon, affected_verdict: z.literal('failed'),
193
+ unaffected_verdict: z.literal('policy-denied'), unaffected_state_ref_id: opaqueId.optional(), policy_ref_id: opaqueId }),
194
+ z.strictObject({ ...scopeProofCommon, affected_verdict: z.literal('denied'),
195
+ unaffected_verdict: z.literal('failed'), unaffected_state_ref_id: opaqueId.optional() }),
196
+ ]);
197
+ /** Failed scope proofs can omit preservation; successful scopes cannot. */
198
+ export const journalAccessProof = z.union([wholeProof, scopeAllowed, scopePolicyDenied, scopeFailed]);
199
+ const receiptFields = {
200
+ schema: z.literal('fleetless.journal-replay-receipt.v2'), environment: opaqueId, signing_key_id: opaqueId,
201
+ run_id: opaqueId, restore_attempt_id: opaqueId, bundle_digest: hash, seal_hash: hash,
202
+ seal_version_id: opaqueId, registry_chain_digest: hash, source_fingerprint: hash,
203
+ target_fingerprint: hash, schema_preflight_digest: hash, copy_inventory_digest: hash,
204
+ copy_coverage_digest: hash, target_inventory_digest: hash,
205
+ lower_sequence: count, lower_hash: hash, upper_sequence: count, upper_hash: hash,
206
+ operation_count: count, applied_count: count, already_effective_count: count,
207
+ failed_count: count, last_applied_sequence: count,
208
+ operations: z.array(operationResult), evidence_refs: z.array(journalEvidenceRef),
209
+ source_isolation_ref_id: opaqueId, copy_ref_id: opaqueId, closure_ref_id: opaqueId,
210
+ access_proofs: z.array(journalAccessProof), original_restore_at: utcMillis,
211
+ original_closure_affected_count: count, zero_open_sessions_count: z.literal(0),
212
+ final_probe_at: utcMillis, completed_at: utcMillis, verdict: z.enum(['pass', 'fail']),
213
+ };
214
+ /** Structural gate report. The consumer still verifies signed bytes and protected evidence. */
215
+ export const journalReplayReceiptBody = z.strictObject(receiptFields).superRefine((value, ctx) => {
216
+ const problem = (message, path) => ctx.addIssue({ code: 'custom', message, path });
217
+ const refs = new Map();
218
+ value.evidence_refs.forEach((ref, index) => {
219
+ if (refs.has(ref.evidence_id))
220
+ problem('Duplicate evidence ID', ['evidence_refs', index, 'evidence_id']);
221
+ refs.set(ref.evidence_id, ref);
222
+ if (ref.bundle_digest !== value.bundle_digest || ref.seal_hash !== value.seal_hash || ref.target_fingerprint !== value.target_fingerprint) {
223
+ problem('Evidence must bind this bundle, seal and target', ['evidence_refs', index]);
224
+ }
225
+ });
226
+ const bound = (id, type, operationId) => {
227
+ const ref = refs.get(id);
228
+ if (!ref || ref.type !== type || ref.binding_scope !== (operationId ? 'operation' : 'global') ||
229
+ (operationId && ('operation_id' in ref ? ref.operation_id : undefined) !== operationId))
230
+ return undefined;
231
+ return ref;
232
+ };
233
+ const source = bound(value.source_isolation_ref_id, 'probe_ref');
234
+ if (!source)
235
+ problem('Source isolation must resolve to a global probe', ['source_isolation_ref_id']);
236
+ const copyRef = bound(value.copy_ref_id, 'copy_ref');
237
+ if (!copyRef || copyRef.type !== 'copy_ref' || copyRef.copy_inventory_digest !== value.copy_inventory_digest ||
238
+ copyRef.target_inventory_digest !== value.target_inventory_digest)
239
+ problem('Copy inventory reference mismatch', ['copy_ref_id']);
240
+ const closureRef = bound(value.closure_ref_id, 'closure_ref');
241
+ if (!closureRef || closureRef.type !== 'closure_ref' || closureRef.restore_attempt_id !== value.restore_attempt_id ||
242
+ closureRef.original_restore_at !== value.original_restore_at ||
243
+ closureRef.original_affected_count !== value.original_closure_affected_count ||
244
+ closureRef.schema_preflight_digest !== value.schema_preflight_digest)
245
+ problem('Closure reference mismatch', ['closure_ref_id']);
246
+ const counts = { applied: 0, 'already-effective': 0, failed: 0 };
247
+ const erase = new Set();
248
+ const operationIds = new Set();
249
+ let previousSequence = 0;
250
+ value.operations.forEach((operation, index) => {
251
+ counts[operation.apply_result]++;
252
+ if (operation.sequence <= previousSequence || operationIds.has(operation.operation_id))
253
+ problem('Operations must be sorted and unique', ['operations', index]);
254
+ previousSequence = operation.sequence;
255
+ operationIds.add(operation.operation_id);
256
+ if (operation.kind === 'organization.erase' || operation.kind === 'organization.scope_erase')
257
+ erase.add(`${operation.kind}:${operation.operation_id}`);
258
+ operation.evidence_ref_ids.forEach((id) => {
259
+ const ref = refs.get(id);
260
+ if (!ref || ref.binding_scope !== 'operation' || ref.operation_id !== operation.operation_id) {
261
+ problem('Operation evidence binding mismatch', ['operations', index, 'evidence_ref_ids']);
262
+ }
263
+ });
264
+ });
265
+ if (value.operation_count !== value.operations.length || value.applied_count !== counts.applied ||
266
+ value.already_effective_count !== counts['already-effective'] || value.failed_count !== counts.failed)
267
+ problem('Replay counts mismatch', ['operation_count']);
268
+ const lastApplied = [...value.operations].reverse().find((operation) => operation.apply_result !== 'failed')?.sequence ?? 0;
269
+ if (value.last_applied_sequence !== lastApplied)
270
+ problem('Last applied sequence mismatch', ['last_applied_sequence']);
271
+ const seenProofs = new Set();
272
+ value.access_proofs.forEach((proof, index) => {
273
+ const key = `${proof.kind}:${proof.operation_id}`;
274
+ if (seenProofs.has(key) || !erase.has(key))
275
+ problem('Extra or duplicate erase access proof', ['access_proofs', index]);
276
+ seenProofs.add(key);
277
+ proof.probe_ref_ids.forEach((id) => { if (!bound(id, 'probe_ref', proof.operation_id))
278
+ problem('Probe must bind the erase operation', ['access_proofs', index, 'probe_ref_ids']); });
279
+ if ('unaffected_state_ref_id' in proof && proof.unaffected_state_ref_id && !bound(proof.unaffected_state_ref_id, 'preservation_ref', proof.operation_id)) {
280
+ problem('Preservation must bind the erase operation', ['access_proofs', index, 'unaffected_state_ref_id']);
281
+ }
282
+ if ('policy_ref_id' in proof && proof.policy_ref_id) {
283
+ const policy = bound(proof.policy_ref_id, 'policy_ref', proof.operation_id);
284
+ if (!policy || policy.type !== 'policy_ref')
285
+ problem('Policy must bind the erase operation', ['access_proofs', index, 'policy_ref_id']);
286
+ else
287
+ policy.negative_export_probe_ids.forEach((id) => {
288
+ const probe = bound(id, 'probe_ref', proof.operation_id);
289
+ if (!probe || probe.type !== 'probe_ref' || probe.outcome !== 'denied') {
290
+ problem('Negative export probe must bind the erase operation and deny access', ['access_proofs', index, 'policy_ref_id']);
291
+ }
292
+ });
293
+ }
294
+ });
295
+ if (erase.size !== seenProofs.size)
296
+ problem('Access proof set must equal erase operations', ['access_proofs']);
297
+ if (value.verdict === 'pass') {
298
+ if (value.failed_count !== 0 || value.operations.some((operation) => operation.database === 'failed' ||
299
+ operation.customer_target_object === 'failed' || operation.authority === 'failed'))
300
+ problem('Failed operation cannot pass', ['verdict']);
301
+ value.operations.forEach((operation, index) => {
302
+ if ((operation.kind === 'organization.erase' || operation.kind === 'organization.scope_erase') && operation.database !== 'absent') {
303
+ problem('Passing organization erase requires database absence', ['operations', index, 'database']);
304
+ }
305
+ if (objectRequiredKinds.has(operation.kind) && operation.customer_target_object !== 'absent') {
306
+ problem('Passing object deletion requires target object absence', ['operations', index, 'customer_target_object']);
307
+ }
308
+ if (authorityRequiredKinds.has(operation.kind) && operation.authority !== 'revoked') {
309
+ problem('Passing authority revocation requires revoked authority', ['operations', index, 'authority']);
310
+ }
311
+ });
312
+ if (value.access_proofs.some((proof) => proof.affected_verdict === 'failed' || proof.unaffected_verdict === 'failed'))
313
+ problem('Failed access proof cannot pass', ['verdict']);
314
+ if (value.access_proofs.some((proof) => proof.probe_ref_ids.some((id) => {
315
+ const probe = bound(id, 'probe_ref', proof.operation_id);
316
+ return !probe || probe.type !== 'probe_ref' || probe.outcome === 'failed';
317
+ })))
318
+ problem('Failed or missing access probe cannot pass', ['verdict']);
319
+ if (!source || source.type !== 'probe_ref' || source.outcome !== 'denied')
320
+ problem('Source isolation not proved', ['verdict']);
321
+ }
322
+ })
323
+ .describe('JSON Schema consumers must also verify counts, exact erase-proof set, reference bindings, kind/registry surface applicability and pass outcomes, signatures and protected-version readbacks.');
324
+ export const journalReplayReceipt = journalReplayReceiptBody.safeExtend({ receipt_hash: hash, signature });
@@ -0,0 +1,147 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { z } from 'zod';
3
+ /** Consumes one sequence; all subsequent obligations use v2. */
4
+ export declare const journalV2ActivationCheckpointBody: z.ZodObject<{
5
+ first_v2_sequence: z.ZodNumber;
6
+ binding_backfill_evidence_hash: z.ZodString;
7
+ binding_backfill_evidence_version_id: z.ZodString;
8
+ environment: z.ZodString;
9
+ generation: z.ZodString;
10
+ sequence: z.ZodNumber;
11
+ previous_hash: z.ZodString;
12
+ checkpoint_at: z.ZodISODateTime;
13
+ fence_drain_evidence_hash: z.ZodString;
14
+ fence_drain_evidence_version_id: z.ZodString;
15
+ source_db_timeline: z.ZodNumber;
16
+ source_db_lsn: z.ZodString;
17
+ registry_chain_digest: z.ZodString;
18
+ registry_digest: z.ZodString;
19
+ build_set_digest: z.ZodString;
20
+ signing_key_id: z.ZodString;
21
+ schema: z.ZodLiteral<"fleetless.journal-v2-activation-checkpoint.v1">;
22
+ }, z.core.$strict>;
23
+ export type JournalV2ActivationCheckpointBody = z.infer<typeof journalV2ActivationCheckpointBody>;
24
+ export declare const journalV2ActivationCheckpoint: z.ZodObject<{
25
+ first_v2_sequence: z.ZodNumber;
26
+ binding_backfill_evidence_hash: z.ZodString;
27
+ binding_backfill_evidence_version_id: z.ZodString;
28
+ environment: z.ZodString;
29
+ generation: z.ZodString;
30
+ sequence: z.ZodNumber;
31
+ previous_hash: z.ZodString;
32
+ checkpoint_at: z.ZodISODateTime;
33
+ fence_drain_evidence_hash: z.ZodString;
34
+ fence_drain_evidence_version_id: z.ZodString;
35
+ source_db_timeline: z.ZodNumber;
36
+ source_db_lsn: z.ZodString;
37
+ registry_chain_digest: z.ZodString;
38
+ registry_digest: z.ZodString;
39
+ build_set_digest: z.ZodString;
40
+ signing_key_id: z.ZodString;
41
+ schema: z.ZodLiteral<"fleetless.journal-v2-activation-checkpoint.v1">;
42
+ record_hash: z.ZodString;
43
+ signature: z.ZodString;
44
+ }, z.core.$strict>;
45
+ export type JournalV2ActivationCheckpoint = z.infer<typeof journalV2ActivationCheckpoint>;
46
+ /** Advances generation without resetting the shared journal sequence. */
47
+ export declare const journalGenerationCheckpointBody: z.ZodObject<{
48
+ previous_generation: z.ZodString;
49
+ environment: z.ZodString;
50
+ generation: z.ZodString;
51
+ sequence: z.ZodNumber;
52
+ previous_hash: z.ZodString;
53
+ checkpoint_at: z.ZodISODateTime;
54
+ fence_drain_evidence_hash: z.ZodString;
55
+ fence_drain_evidence_version_id: z.ZodString;
56
+ source_db_timeline: z.ZodNumber;
57
+ source_db_lsn: z.ZodString;
58
+ registry_chain_digest: z.ZodString;
59
+ registry_digest: z.ZodString;
60
+ build_set_digest: z.ZodString;
61
+ signing_key_id: z.ZodString;
62
+ schema: z.ZodLiteral<"fleetless.journal-generation-checkpoint.v1">;
63
+ }, z.core.$strict>;
64
+ export type JournalGenerationCheckpointBody = z.infer<typeof journalGenerationCheckpointBody>;
65
+ export declare const journalGenerationCheckpoint: z.ZodObject<{
66
+ previous_generation: z.ZodString;
67
+ environment: z.ZodString;
68
+ generation: z.ZodString;
69
+ sequence: z.ZodNumber;
70
+ previous_hash: z.ZodString;
71
+ checkpoint_at: z.ZodISODateTime;
72
+ fence_drain_evidence_hash: z.ZodString;
73
+ fence_drain_evidence_version_id: z.ZodString;
74
+ source_db_timeline: z.ZodNumber;
75
+ source_db_lsn: z.ZodString;
76
+ registry_chain_digest: z.ZodString;
77
+ registry_digest: z.ZodString;
78
+ build_set_digest: z.ZodString;
79
+ signing_key_id: z.ZodString;
80
+ schema: z.ZodLiteral<"fleetless.journal-generation-checkpoint.v1">;
81
+ record_hash: z.ZodString;
82
+ signature: z.ZodString;
83
+ }, z.core.$strict>;
84
+ export type JournalGenerationCheckpoint = z.infer<typeof journalGenerationCheckpoint>;
85
+ /** Domain-separated final drain seal, not permission to open target traffic. */
86
+ export declare const journalFinalSealBody: z.ZodObject<{
87
+ schema: z.ZodLiteral<"fleetless.journal-final-seal.v1">;
88
+ environment: z.ZodString;
89
+ signing_key_id: z.ZodString;
90
+ incident_id: z.ZodString;
91
+ isolated_target_id: z.ZodString;
92
+ restore_attempt_id: z.ZodString;
93
+ final_sequence: z.ZodNumber;
94
+ final_hash: z.ZodString;
95
+ final_generation: z.ZodString;
96
+ selected_recovery_point: z.ZodDiscriminatedUnion<[z.ZodObject<{
97
+ kind: z.ZodLiteral<"timestamp">;
98
+ at: z.ZodISODateTime;
99
+ }, z.core.$strict>, z.ZodObject<{
100
+ kind: z.ZodLiteral<"lsn">;
101
+ timeline: z.ZodNumber;
102
+ lsn: z.ZodString;
103
+ at: z.ZodISODateTime;
104
+ }, z.core.$strict>], "kind">;
105
+ fence_at: z.ZodISODateTime;
106
+ e_max_ms: z.ZodNumber;
107
+ w_max_ms: z.ZodNumber;
108
+ deployment_admission_evidence_digest: z.ZodString;
109
+ cutoff_utc: z.ZodISODateTime;
110
+ previous_cutoff_utc: z.ZodISODateTime;
111
+ registry_chain_digest: z.ZodString;
112
+ copy_inventory_digest: z.ZodString;
113
+ pinned_standby_id: z.ZodString;
114
+ }, z.core.$strict>;
115
+ export type JournalFinalSealBody = z.infer<typeof journalFinalSealBody>;
116
+ export declare const journalFinalSeal: z.ZodObject<{
117
+ schema: z.ZodLiteral<"fleetless.journal-final-seal.v1">;
118
+ environment: z.ZodString;
119
+ signing_key_id: z.ZodString;
120
+ incident_id: z.ZodString;
121
+ isolated_target_id: z.ZodString;
122
+ restore_attempt_id: z.ZodString;
123
+ final_sequence: z.ZodNumber;
124
+ final_hash: z.ZodString;
125
+ final_generation: z.ZodString;
126
+ selected_recovery_point: z.ZodDiscriminatedUnion<[z.ZodObject<{
127
+ kind: z.ZodLiteral<"timestamp">;
128
+ at: z.ZodISODateTime;
129
+ }, z.core.$strict>, z.ZodObject<{
130
+ kind: z.ZodLiteral<"lsn">;
131
+ timeline: z.ZodNumber;
132
+ lsn: z.ZodString;
133
+ at: z.ZodISODateTime;
134
+ }, z.core.$strict>], "kind">;
135
+ fence_at: z.ZodISODateTime;
136
+ e_max_ms: z.ZodNumber;
137
+ w_max_ms: z.ZodNumber;
138
+ deployment_admission_evidence_digest: z.ZodString;
139
+ cutoff_utc: z.ZodISODateTime;
140
+ previous_cutoff_utc: z.ZodISODateTime;
141
+ registry_chain_digest: z.ZodString;
142
+ copy_inventory_digest: z.ZodString;
143
+ pinned_standby_id: z.ZodString;
144
+ seal_hash: z.ZodString;
145
+ signature: z.ZodString;
146
+ }, z.core.$strict>;
147
+ export type JournalFinalSeal = z.infer<typeof journalFinalSeal>;
@@ -0,0 +1,89 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { z } from 'zod';
3
+ // Decoded shapes only. Consumers verify original canonical bytes, signatures,
4
+ // committed sequence, exact-version fence evidence and standby confirmation.
5
+ const hash = z.string().regex(/^[0-9a-f]{64}$/);
6
+ const uuid = z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
7
+ const opaqueId = z.string().min(1);
8
+ const count = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
9
+ const positiveInteger = z.number().int().min(1).max(Number.MAX_SAFE_INTEGER);
10
+ const utcMillis = z.iso.datetime({ precision: 3 });
11
+ const lsn = z.string().regex(/^(?:0|[1-9A-F][0-9A-F]{0,7})\/(?:0|[1-9A-F][0-9A-F]{0,7})$/);
12
+ const signature = z.string().regex(/^[A-Za-z0-9_-]{85}[AQgw]$/);
13
+ const checkpointFields = {
14
+ environment: opaqueId,
15
+ generation: uuid,
16
+ sequence: positiveInteger,
17
+ previous_hash: hash,
18
+ checkpoint_at: utcMillis,
19
+ fence_drain_evidence_hash: hash,
20
+ fence_drain_evidence_version_id: opaqueId,
21
+ source_db_timeline: positiveInteger,
22
+ source_db_lsn: lsn,
23
+ registry_chain_digest: hash,
24
+ registry_digest: hash,
25
+ build_set_digest: hash,
26
+ signing_key_id: opaqueId,
27
+ };
28
+ /** Consumes one sequence; all subsequent obligations use v2. */
29
+ export const journalV2ActivationCheckpointBody = z.strictObject({
30
+ schema: z.literal('fleetless.journal-v2-activation-checkpoint.v1'),
31
+ ...checkpointFields,
32
+ first_v2_sequence: positiveInteger,
33
+ binding_backfill_evidence_hash: hash,
34
+ binding_backfill_evidence_version_id: opaqueId,
35
+ }).refine((value) => value.sequence < Number.MAX_SAFE_INTEGER && value.first_v2_sequence === value.sequence + 1, {
36
+ path: ['first_v2_sequence'], message: 'Must immediately follow the checkpoint sequence',
37
+ }).describe('JSON Schema consumers must also verify first_v2_sequence = sequence + 1 and journal activation evidence.');
38
+ export const journalV2ActivationCheckpoint = journalV2ActivationCheckpointBody.safeExtend({ record_hash: hash, signature });
39
+ /** Advances generation without resetting the shared journal sequence. */
40
+ export const journalGenerationCheckpointBody = z.strictObject({
41
+ schema: z.literal('fleetless.journal-generation-checkpoint.v1'),
42
+ ...checkpointFields,
43
+ previous_generation: uuid,
44
+ }).refine((value) => value.generation !== value.previous_generation, {
45
+ path: ['previous_generation'], message: 'Must differ from the new generation',
46
+ }).describe('JSON Schema consumers must also verify generation differs from previous_generation and the committed sequence is not reset.');
47
+ export const journalGenerationCheckpoint = journalGenerationCheckpointBody.safeExtend({ record_hash: hash, signature });
48
+ // The actual recovery point B. The oldest selectable mapping-bearing point
49
+ // belongs in the export header and cannot substitute for this selected point.
50
+ const recoveryPoint = z.discriminatedUnion('kind', [
51
+ z.strictObject({ kind: z.literal('timestamp'), at: utcMillis }),
52
+ z.strictObject({ kind: z.literal('lsn'), timeline: positiveInteger, lsn, at: utcMillis }),
53
+ ]);
54
+ /** Domain-separated final drain seal, not permission to open target traffic. */
55
+ export const journalFinalSealBody = z.strictObject({
56
+ schema: z.literal('fleetless.journal-final-seal.v1'),
57
+ environment: opaqueId,
58
+ signing_key_id: opaqueId,
59
+ incident_id: opaqueId,
60
+ isolated_target_id: opaqueId,
61
+ restore_attempt_id: opaqueId,
62
+ final_sequence: count,
63
+ final_hash: hash,
64
+ final_generation: uuid,
65
+ selected_recovery_point: recoveryPoint,
66
+ fence_at: utcMillis,
67
+ e_max_ms: count,
68
+ w_max_ms: count,
69
+ deployment_admission_evidence_digest: hash,
70
+ cutoff_utc: utcMillis,
71
+ previous_cutoff_utc: utcMillis,
72
+ registry_chain_digest: hash,
73
+ copy_inventory_digest: hash,
74
+ pinned_standby_id: opaqueId,
75
+ }).refine((value) => {
76
+ // BigInt prevents an otherwise safe pair of duration inputs from rounding
77
+ // when added. Validate before conversion: refinements can see invalid scalars.
78
+ const fenceAt = Date.parse(value.fence_at);
79
+ const cutoff = Date.parse(value.cutoff_utc);
80
+ const previous = Date.parse(value.previous_cutoff_utc);
81
+ if (![fenceAt, cutoff, previous, value.e_max_ms, value.w_max_ms].every(Number.isSafeInteger))
82
+ return false;
83
+ const bound = BigInt(fenceAt) + BigInt(value.e_max_ms) + BigInt(value.w_max_ms);
84
+ const rounded = (bound / 1000n + (bound % 1000n > 0n ? 1n : 0n)) * 1000n;
85
+ const next = BigInt(previous) + 1000n;
86
+ return BigInt(cutoff) === (rounded > next ? rounded : next);
87
+ }, { path: ['cutoff_utc'], message: 'Must equal max(ceil_to_second(T + E_max + W_max), previous C + 1 second)' })
88
+ .describe('JSON Schema consumers must also verify C = max(ceil_to_second(T + E_max + W_max), previous C + 1 second), original signatures and complete drain/admission evidence.');
89
+ export const journalFinalSeal = journalFinalSealBody.safeExtend({ seal_hash: hash, signature });
@@ -12,6 +12,8 @@ export declare const legalAcceptanceVersionRow: z.ZodObject<{
12
12
  invitation: "invitation";
13
13
  order: "order";
14
14
  existing_org: "existing_org";
15
+ amendment: "amendment";
16
+ price_offer: "price_offer";
15
17
  }>;
16
18
  accepted_at: z.ZodISODateTime;
17
19
  text_id: z.ZodString;
@@ -35,6 +37,8 @@ export declare const legalAcceptanceListResponse: z.ZodObject<{
35
37
  invitation: "invitation";
36
38
  order: "order";
37
39
  existing_org: "existing_org";
40
+ amendment: "amendment";
41
+ price_offer: "price_offer";
38
42
  }>;
39
43
  accepted_at: z.ZodISODateTime;
40
44
  text_id: z.ZodString;
@@ -10,12 +10,19 @@ export const legalAcceptanceListQuery = z.object({
10
10
  }).strict();
11
11
  export const legalAcceptanceVersionRow = z.object({
12
12
  id: z.uuid(),
13
- context: z.enum(['registration', 'invitation', 'order', 'existing_org']),
13
+ context: z.enum(['registration', 'invitation', 'order', 'existing_org', 'amendment', 'price_offer']),
14
14
  accepted_at: z.iso.datetime({ precision: 6 }),
15
15
  text_id: z.string().min(1).max(80).regex(/\S/),
16
16
  terms: legalDocumentReference,
17
17
  dpa: legalDocumentReference.nullable(),
18
- }).strict();
18
+ }).strict().superRefine((value, ctx) => {
19
+ if ((value.context === 'amendment' || value.context === 'price_offer') && value.dpa !== null) {
20
+ ctx.addIssue({ code: 'custom', path: ['dpa'], message: 'Offer acceptances do not incorporate a DPA.' });
21
+ }
22
+ }).meta({ allOf: [{
23
+ if: { properties: { context: { enum: ['amendment', 'price_offer'] } }, required: ['context'] },
24
+ then: { properties: { dpa: { type: 'null' } }, required: ['dpa'] },
25
+ }] });
19
26
  export const legalAcceptanceListResponse = z.object({
20
27
  acceptances: z.array(legalAcceptanceVersionRow),
21
28
  next_cursor: legalAcceptanceCursor.nullable(),