@fleetless/contracts 12.1.0 → 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 +38 -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,182 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { z } from 'zod';
3
+ import { journalIntentV2Body } from './journal-intents.js';
4
+ // Restricted, decoded protected manifests. The source and target still verify
5
+ // exact protected versions, original bytes, ownership and readback separately.
6
+ const uuid = z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
7
+ const hash = z.string().regex(/^[0-9a-f]{64}$/);
8
+ const opaqueId = z.string().min(1);
9
+ const positive = z.number().int().min(1).max(Number.MAX_SAFE_INTEGER);
10
+ const utcMillis = z.iso.datetime({ precision: 3 });
11
+ const membership = z.enum(['affected', 'unaffected']);
12
+ export const journalManifestScope = z.union([
13
+ z.strictObject({ kind: z.literal('organization'), org_id: uuid }),
14
+ z.strictObject({ kind: z.literal('organization_scope'), org_id: uuid, scope_id: uuid,
15
+ scope_generation: positive, approved_predicate_digest: hash }),
16
+ z.strictObject({ kind: z.literal('central_mcp') }),
17
+ z.strictObject({ kind: z.literal('console_oauth') }),
18
+ z.strictObject({ kind: z.literal('global_ops_event') }),
19
+ z.strictObject({ kind: z.literal('operator_audit') }),
20
+ z.strictObject({ kind: z.literal('subject'), subject_kind: z.enum(['developer', 'app_user']), subject_id: uuid }),
21
+ ]);
22
+ const uuidRowTable = z.enum([
23
+ 'assets', 'audit_events', 'job_runs', 'oidc_interactions',
24
+ 'organization_exports', 'ops_notification_jobs', 'console_oauth_codes',
25
+ ]);
26
+ const member = { membership_kind: membership };
27
+ export const journalManifestRow = z.union([
28
+ z.strictObject({ ...member, type: z.literal('uuid_row'), table: uuidRowTable, id: uuid, row_generation: uuid }),
29
+ z.strictObject({ ...member, type: z.literal('basic_activity_observation'), org_id: uuid, audit_event_id: uuid }),
30
+ z.strictObject({ ...member, type: z.literal('history_sample'), robot_id: uuid, series_id: positive,
31
+ series_generation: uuid, captured_at_epoch_us: positive, sample_id: uuid }),
32
+ z.strictObject({ ...member, type: z.literal('latency_bucket'), robot_id: uuid, bucket_at: utcMillis, bucket_generation: uuid }),
33
+ z.strictObject({ ...member, type: z.literal('org_keyed_row'), table: z.enum(['basic_activity_history', 'synthetic_org_fixtures']), org_id: uuid }),
34
+ z.strictObject({ ...member, type: z.literal('app_mcp_client'), app_id: uuid, client_row_id: uuid }),
35
+ z.strictObject({ ...member, type: z.literal('central_mcp_client'), client_row_id: uuid }),
36
+ z.strictObject({ ...member, type: z.literal('app_mcp_grant'), app_id: uuid, grant_id: uuid, grant_generation: uuid }),
37
+ z.strictObject({ ...member, type: z.literal('central_mcp_grant'), grant_id: uuid, grant_generation: uuid }),
38
+ z.strictObject({ ...member, type: z.literal('app_mcp_code'), app_id: uuid, code_row_id: uuid }),
39
+ z.strictObject({ ...member, type: z.literal('central_mcp_code'), code_row_id: uuid }),
40
+ z.strictObject({ ...member, type: z.literal('app_mcp_interaction'), app_id: uuid, interaction_id: opaqueId }),
41
+ z.strictObject({ ...member, type: z.literal('central_mcp_interaction'), interaction_id: opaqueId }),
42
+ z.strictObject({ ...member, type: z.literal('console_interaction'), interaction_id: opaqueId }),
43
+ z.strictObject({ ...member, type: z.literal('org_ops_event'), org_id: uuid, event_id: uuid }),
44
+ z.strictObject({ ...member, type: z.literal('global_ops_event'), event_id: uuid }),
45
+ z.strictObject({ ...member, type: z.literal('org_operator_audit'), org_id: uuid, audit_id: uuid }),
46
+ z.strictObject({ ...member, type: z.literal('global_operator_audit'), audit_id: uuid }),
47
+ ]).superRefine((row, ctx) => {
48
+ if (row.type === 'uuid_row' && row.row_generation !== row.id) {
49
+ ctx.addIssue({ code: 'custom', path: ['row_generation'], message: 'Immutable UUID row generation must equal its ID' });
50
+ }
51
+ }).describe('JSON Schema consumers must also check uuid_row generation equality and exact physical identity.');
52
+ const entry = { mapping_id: uuid, source_project_id: opaqueId, source_bucket: opaqueId,
53
+ old_key: opaqueId, version_ids: z.array(opaqueId).min(1), membership_kind: membership };
54
+ export const journalManifestEntry = z.union([
55
+ z.strictObject({ kind: z.literal('asset_blob'), ...entry }),
56
+ z.strictObject({ kind: z.literal('export_archive'), ...entry }),
57
+ ]).superRefine((value, ctx) => {
58
+ if (new Set(value.version_ids).size !== value.version_ids.length) {
59
+ ctx.addIssue({ code: 'custom', path: ['version_ids'], message: 'Version IDs must be unique within a mapping' });
60
+ }
61
+ }).describe('Restricted object keys remain only in the protected manifest; JSON Schema consumers also check unique versions.');
62
+ const sweepKinds = [
63
+ 'history.retention', 'audit.retention', 'job_run.retention', 'latency.retention',
64
+ 'ops_event.retention', 'ops_global_event.retention', 'operator_audit.retention',
65
+ 'oidc_interaction.expire', 'mcp_interaction.expire', 'mcp_central_interaction.expire',
66
+ 'mcp_client.expire', 'mcp_central_client.expire', 'console_interaction.expire',
67
+ 'console_code.expire',
68
+ ];
69
+ const explicitKinds = ['history.slug_delete', 'robot_assets.clear'];
70
+ export const journalManifestBatch = z.union([
71
+ z.strictObject({ batch_id: uuid, kind: z.enum(sweepKinds), cutoff_at: utcMillis,
72
+ policy_revision: positive, rows: z.array(journalManifestRow).min(1) }),
73
+ z.strictObject({ batch_id: uuid, kind: z.enum(explicitKinds), rows: z.array(journalManifestRow).min(1) }),
74
+ ]).describe('A batch binds one intent and contains exactly its frozen affected rows; JSON Schema consumers check this cross-record relation.');
75
+ function rowKey(row) {
76
+ switch (row.type) {
77
+ case 'uuid_row': return JSON.stringify([row.table, row.table, row.id]);
78
+ case 'basic_activity_observation': return JSON.stringify(['basic_activity_observations', row.audit_event_id]);
79
+ case 'history_sample': return JSON.stringify(['datapoint_series_samples', row.robot_id, row.series_id, row.captured_at_epoch_us, row.sample_id]);
80
+ case 'latency_bucket': return JSON.stringify(['bridge_latency_buckets', row.robot_id, row.bucket_at]);
81
+ case 'org_keyed_row': return JSON.stringify([row.table, row.table, row.org_id]);
82
+ case 'app_mcp_client':
83
+ case 'central_mcp_client': return JSON.stringify(['mcp_oauth_clients', row.client_row_id]);
84
+ case 'app_mcp_grant':
85
+ case 'central_mcp_grant': return JSON.stringify(['mcp_oauth_consent_grants', row.grant_id]);
86
+ case 'app_mcp_code':
87
+ case 'central_mcp_code': return JSON.stringify(['mcp_oauth_codes', row.code_row_id]);
88
+ case 'app_mcp_interaction':
89
+ case 'central_mcp_interaction': return JSON.stringify(['mcp_oauth_interactions', row.interaction_id]);
90
+ case 'console_interaction': return JSON.stringify(['console_oauth_interactions', row.interaction_id]);
91
+ case 'org_ops_event':
92
+ case 'global_ops_event': return JSON.stringify(['ops_events', row.event_id]);
93
+ case 'org_operator_audit':
94
+ case 'global_operator_audit': return JSON.stringify(['operator_audit', row.audit_id]);
95
+ }
96
+ }
97
+ function entryKey(value) { return JSON.stringify([value.kind, value.mapping_id]); }
98
+ function sortedUnique(items, key) {
99
+ const keys = items.map(key);
100
+ return keys.every((value, index) => index === 0 || keys[index - 1] < value);
101
+ }
102
+ export const journalDeletionManifest = z.strictObject({
103
+ schema: z.literal('fleetless.deletion-manifest.v1'), environment: z.enum(['staging', 'production']),
104
+ generation: positive, operation_id: uuid, manifest_id: uuid, scope: journalManifestScope,
105
+ entries: z.array(journalManifestEntry), rows: z.array(journalManifestRow),
106
+ batches: z.array(journalManifestBatch),
107
+ }).superRefine((value, ctx) => {
108
+ if (!sortedUnique(value.rows, rowKey))
109
+ ctx.addIssue({ code: 'custom', path: ['rows'], message: 'Rows must be sorted and physically unique' });
110
+ if (!sortedUnique(value.entries, entryKey))
111
+ ctx.addIssue({ code: 'custom', path: ['entries'], message: 'Mappings must be sorted and physically unique' });
112
+ value.batches.forEach((batch, index) => {
113
+ if (!sortedUnique(batch.rows, rowKey))
114
+ ctx.addIssue({ code: 'custom', path: ['batches', index, 'rows'], message: 'Batch rows must be sorted and physically unique' });
115
+ });
116
+ }).describe('JSON Schema consumers also check physical uniqueness, ordering, intent binding and protected-version readbacks.');
117
+ const backedBranches = journalIntentV2Body.options.filter((branch) => 'manifest_id' in branch.shape);
118
+ export const journalManifestIntentProjection = z.union(backedBranches.map((branch) => z.strictObject({
119
+ operation_id: branch.shape.operation_id, kind: branch.shape.kind, ids: branch.shape.ids,
120
+ })));
121
+ const nonOrganizationScope = {
122
+ 'mcp_central_client.revoke': 'central_mcp',
123
+ 'mcp_central_interaction.expire': 'central_mcp',
124
+ 'mcp_central_client.expire': 'central_mcp',
125
+ 'console_interaction.expire': 'console_oauth',
126
+ 'console_code.expire': 'console_oauth',
127
+ 'ops_global_event.retention': 'global_ops_event',
128
+ 'operator_audit.retention': 'operator_audit',
129
+ 'auth_factor.remove': 'subject',
130
+ };
131
+ /** A structural candidate; it is not a signed intent or protected readback. */
132
+ export const journalManifestBinding = z.strictObject({
133
+ intent: journalManifestIntentProjection, manifest: journalDeletionManifest,
134
+ }).superRefine(({ intent, manifest }, ctx) => {
135
+ const problem = (message, path) => ctx.addIssue({ code: 'custom', message, path });
136
+ if (manifest.operation_id !== intent.operation_id)
137
+ problem('Operation ID mismatch', ['manifest', 'operation_id']);
138
+ const ids = intent.ids;
139
+ const expectedScope = intent.kind === 'organization.scope_erase' ? 'organization_scope' :
140
+ nonOrganizationScope[intent.kind] ?? ('org_id' in ids ? 'organization' : undefined);
141
+ if (manifest.scope.kind !== expectedScope)
142
+ problem('Scope kind mismatch', ['manifest', 'scope']);
143
+ if ('org_id' in manifest.scope && manifest.scope.org_id !== ids.org_id)
144
+ problem('Organization scope mismatch', ['manifest', 'scope', 'org_id']);
145
+ if (manifest.scope.kind === 'organization_scope' &&
146
+ (manifest.scope.scope_id !== ids.scope_id || manifest.scope.scope_generation !== ids.scope_generation)) {
147
+ problem('Approved scope identity or generation mismatch', ['manifest', 'scope']);
148
+ }
149
+ if (manifest.scope.kind === 'subject' &&
150
+ (manifest.scope.subject_kind !== ids.subject_kind || manifest.scope.subject_id !== ids.subject_id)) {
151
+ problem('Subject scope mismatch', ['manifest', 'scope']);
152
+ }
153
+ const allowedRows = {
154
+ central_mcp: (row) => row.type.startsWith('central_mcp_'),
155
+ console_oauth: (row) => row.type === 'console_interaction' || (row.type === 'uuid_row' && row.table === 'console_oauth_codes'),
156
+ global_ops_event: (row) => row.type === 'global_ops_event' || (row.type === 'uuid_row' && row.table === 'ops_notification_jobs'),
157
+ operator_audit: (row) => row.type === 'global_operator_audit' || row.type === 'org_operator_audit',
158
+ };
159
+ const allows = allowedRows[manifest.scope.kind];
160
+ if (allows && !manifest.rows.every(allows))
161
+ problem('Row outside closed source scope', ['manifest', 'rows']);
162
+ const isSweep = sweepKinds.some((kind) => kind === intent.kind);
163
+ const isExplicit = explicitKinds.some((kind) => kind === intent.kind);
164
+ if (isSweep || isExplicit) {
165
+ if (manifest.batches.length !== 1)
166
+ problem('Exactly one frozen batch required', ['manifest', 'batches']);
167
+ else {
168
+ const batch = manifest.batches[0];
169
+ if (batch.kind !== intent.kind || batch.batch_id !== ids.batch_id)
170
+ problem('Batch kind or ID mismatch', ['manifest', 'batches', 0]);
171
+ if (isSweep && ('cutoff_at' in batch ? batch.cutoff_at !== ids.cutoff_at || batch.policy_revision !== ids.policy_revision : true)) {
172
+ problem('Sweep cutoff or policy mismatch', ['manifest', 'batches', 0]);
173
+ }
174
+ const affected = manifest.rows.filter((row) => row.membership_kind === 'affected');
175
+ if (batch.rows.some((row) => row.membership_kind !== 'affected') ||
176
+ JSON.stringify(batch.rows) !== JSON.stringify(affected))
177
+ problem('Batch must contain every and only affected row', ['manifest', 'batches', 0, 'rows']);
178
+ }
179
+ }
180
+ else if (manifest.batches.length !== 0)
181
+ problem('Unexpected batch', ['manifest', 'batches']);
182
+ }).describe('JSON Schema consumers must also verify exact intent/scope/batch binding, sorted physical membership, original bytes and protected readbacks.');