@fleetless/contracts 13.0.0 → 13.1.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.
@@ -24,6 +24,8 @@ const uuidRowTable = z.enum([
24
24
  'organization_exports', 'ops_notification_jobs', 'console_oauth_codes',
25
25
  ]);
26
26
  const member = { membership_kind: membership };
27
+ // Retention sweeps name an expired time range instead of every deleted row.
28
+ const retentionRangeTable = z.enum(['datapoint_series_samples', 'bridge_latency_buckets']);
27
29
  export const journalManifestRow = z.union([
28
30
  z.strictObject({ ...member, type: z.literal('uuid_row'), table: uuidRowTable, id: uuid, row_generation: uuid }),
29
31
  z.strictObject({ ...member, type: z.literal('basic_activity_observation'), org_id: uuid, audit_event_id: uuid }),
@@ -44,11 +46,30 @@ export const journalManifestRow = z.union([
44
46
  z.strictObject({ ...member, type: z.literal('global_ops_event'), event_id: uuid }),
45
47
  z.strictObject({ ...member, type: z.literal('org_operator_audit'), org_id: uuid, audit_id: uuid }),
46
48
  z.strictObject({ ...member, type: z.literal('global_operator_audit'), audit_id: uuid }),
49
+ z.strictObject({
50
+ type: z.literal('retention_range'),
51
+ membership_kind: z.literal('affected'),
52
+ table: retentionRangeTable.meta({ description: 'The table the range was deleted from.' }),
53
+ org_id: uuid,
54
+ robot_id: uuid,
55
+ series_id: positive.optional().meta({ description: 'The one datapoint series of the range; absent when the range covers every series of the robot. Never set for latency buckets.' }),
56
+ from: utcMillis.meta({ description: 'Inclusive lower bound of the deleted range (UTC, milliseconds).' }),
57
+ cutoff: utcMillis.meta({ description: 'Exclusive upper bound of the deleted range (UTC, milliseconds). Replay deletes every row of the table inside [from, cutoff) for this robot and series and no row at or after the cutoff.' }),
58
+ row_count: positive.meta({ description: 'How many rows the range held when it was frozen.' }),
59
+ rows_digest: hash.meta({ description: 'SHA-256 over the sorted row keys the range held when it was frozen (retention range digest v1); lets a backup of the range be checked against what was deleted.' }),
60
+ }),
47
61
  ]).superRefine((row, ctx) => {
48
62
  if (row.type === 'uuid_row' && row.row_generation !== row.id) {
49
63
  ctx.addIssue({ code: 'custom', path: ['row_generation'], message: 'Immutable UUID row generation must equal its ID' });
50
64
  }
51
- }).describe('JSON Schema consumers must also check uuid_row generation equality and exact physical identity.');
65
+ if (row.type === 'retention_range') {
66
+ if (row.from >= row.cutoff)
67
+ ctx.addIssue({ code: 'custom', path: ['cutoff'], message: 'A retention range must end after it starts' });
68
+ if (row.table === 'bridge_latency_buckets' && row.series_id !== undefined) {
69
+ ctx.addIssue({ code: 'custom', path: ['series_id'], message: 'Latency buckets are not kept per series' });
70
+ }
71
+ }
72
+ }).describe('JSON Schema consumers must also check uuid_row generation equality, exact physical identity and that a retention range starts before it ends.');
52
73
  const entry = { mapping_id: uuid, source_project_id: opaqueId, source_bucket: opaqueId,
53
74
  old_key: opaqueId, version_ids: z.array(opaqueId).min(1), membership_kind: membership };
54
75
  export const journalManifestEntry = z.union([
@@ -92,6 +113,7 @@ function rowKey(row) {
92
113
  case 'global_ops_event': return JSON.stringify(['ops_events', row.event_id]);
93
114
  case 'org_operator_audit':
94
115
  case 'global_operator_audit': return JSON.stringify(['operator_audit', row.audit_id]);
116
+ case 'retention_range': return JSON.stringify([row.table, 'range', row.robot_id, row.series_id ?? null, row.from]);
95
117
  }
96
118
  }
97
119
  function entryKey(value) { return JSON.stringify([value.kind, value.mapping_id]); }
@@ -128,6 +150,53 @@ const nonOrganizationScope = {
128
150
  'operator_audit.retention': 'operator_audit',
129
151
  'auth_factor.remove': 'subject',
130
152
  };
153
+ const rangeTableOfKind = {
154
+ 'history.retention': 'datapoint_series_samples',
155
+ 'history.slug_delete': 'datapoint_series_samples',
156
+ 'latency.retention': 'bridge_latency_buckets',
157
+ };
158
+ /**
159
+ * A retention range belongs to exactly the history and latency retention
160
+ * kinds, stays inside the organization, robot, series and cutoff of its
161
+ * intent, and no two ranges of one robot overlap (a robot's ranges name a
162
+ * series all or none of them).
163
+ */
164
+ function retentionRangeProblems(kind, ids, ranges) {
165
+ const problems = [];
166
+ const table = rangeTableOfKind[kind];
167
+ if (table === undefined)
168
+ return ['Retention ranges belong only to history and latency retention'];
169
+ for (const range of ranges) {
170
+ if (range.table !== table)
171
+ problems.push('Range table does not match the intent kind');
172
+ if (range.org_id !== ids.org_id)
173
+ problems.push('Range organization does not match the intent');
174
+ if (kind === 'history.slug_delete' && (range.robot_id !== ids.robot_id || range.series_id !== ids.series_id)) {
175
+ problems.push('Range robot or series does not match the intent');
176
+ }
177
+ if (kind !== 'history.slug_delete' && typeof ids.cutoff_at === 'string' && range.cutoff > ids.cutoff_at) {
178
+ problems.push('Range reaches past the sweep cutoff');
179
+ }
180
+ }
181
+ const byRobot = new Map();
182
+ for (const range of ranges)
183
+ byRobot.set(range.robot_id, [...(byRobot.get(range.robot_id) ?? []), range]);
184
+ for (const group of byRobot.values()) {
185
+ if (new Set(group.map((range) => range.series_id === undefined)).size > 1) {
186
+ problems.push('A robot\'s ranges must name a series all or none');
187
+ continue;
188
+ }
189
+ const bySeries = new Map();
190
+ for (const range of group)
191
+ bySeries.set(range.series_id, [...(bySeries.get(range.series_id) ?? []), range]);
192
+ for (const series of bySeries.values()) {
193
+ const ordered = [...series].sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : 0));
194
+ if (ordered.some((range, index) => index > 0 && range.from < ordered[index - 1].cutoff))
195
+ problems.push('Ranges of one robot overlap');
196
+ }
197
+ }
198
+ return problems;
199
+ }
131
200
  /** A structural candidate; it is not a signed intent or protected readback. */
132
201
  export const journalManifestBinding = z.strictObject({
133
202
  intent: journalManifestIntentProjection, manifest: journalDeletionManifest,
@@ -159,6 +228,10 @@ export const journalManifestBinding = z.strictObject({
159
228
  const allows = allowedRows[manifest.scope.kind];
160
229
  if (allows && !manifest.rows.every(allows))
161
230
  problem('Row outside closed source scope', ['manifest', 'rows']);
231
+ const ranges = manifest.rows.filter((row) => row.type === 'retention_range');
232
+ if (ranges.length > 0)
233
+ for (const message of new Set(retentionRangeProblems(intent.kind, ids, ranges)))
234
+ problem(message, ['manifest', 'rows']);
162
235
  const isSweep = sweepKinds.some((kind) => kind === intent.kind);
163
236
  const isExplicit = explicitKinds.some((kind) => kind === intent.kind);
164
237
  if (isSweep || isExplicit) {
package/dist/routes.js CHANGED
@@ -3178,14 +3178,14 @@ export const ROUTES = [
3178
3178
  },
3179
3179
  {
3180
3180
  method: 'GET', path: '/api/billing/invoices/:id/pdf', section: 'billing',
3181
- summary: "Downloads an invoice's original or cancellation PDF.",
3181
+ summary: "Downloads a historical Cloud invoice's original PDF.",
3182
3182
  audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
3183
3183
  params: [{ name: 'id', description: 'The invoice id, from `billingInvoice.id` in `GET /api/billing`\'s `invoices`.' }],
3184
3184
  query: billingInvoicePdfQuery, request: null, response: null, contentType: 'application/pdf',
3185
3185
  errors: [...DEVELOPER_GUARD, 'tier_required', 'validation_error', 'not_found'], transport: 'http',
3186
3186
  notes: 'Owner-only. Omitted `kind` or `kind=invoice` returns the original PDF, rendered once with `pdfkit` when issued and stored as bytes. ' +
3187
- '`kind=cancellation` returns the stored cancellation PDF for this same invoice id; no read renders a new PDF. ' +
3188
- '`404 not_found` for an unknown id, one from another org, or a missing cancellation number or PDF. This reads historical Cloud ' +
3187
+ '`kind=cancellation` returns `404 not_found`: Cloud has no cancellation PDFs. Cancellation documents are held in Lexware. ' +
3188
+ '`404 not_found` also covers an unknown id or one from another org. This reads historical Cloud ' +
3189
3189
  "invoices only: a due charge has no PDF of its own here — its eventual Lexware invoice is a document, read through " +
3190
3190
  '`GET /api/billing/documents/:id/file`.',
3191
3191
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetless/contracts",
3
- "version": "13.0.0",
3
+ "version": "13.1.0",
4
4
  "description": "Fleetless wire contracts: the bridge-cloud protocol, the REST API schemas and the error codes, as zod schemas with generated JSON Schema and OpenAPI artifacts.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Dehne Robotik GmbH",