@fleetless/contracts 14.0.0 → 15.0.1
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 +184 -0
- package/artifacts/openapi.json +20210 -11764
- package/artifacts/routes.json +1160 -39
- package/artifacts/schema/addon-catalogue-entry.schema.json +3 -1
- package/artifacts/schema/admin-plan-change-request.schema.json +26 -0
- package/artifacts/schema/app-deletion-summary.schema.json +15 -1
- package/artifacts/schema/asset-plan-limit-details.schema.json +3 -1
- package/artifacts/schema/billing-change-response.schema.json +9 -8
- package/artifacts/schema/checkout-response.schema.json +6 -6
- package/artifacts/schema/cloud-config.schema.json +5 -5
- package/artifacts/schema/collection-actor.schema.json +35 -0
- package/artifacts/schema/collection-definitions-response.schema.json +612 -0
- package/artifacts/schema/collection-event.schema.json +216 -0
- package/artifacts/schema/collection-export-query.schema.json +56 -0
- package/artifacts/schema/collection-filter.schema.json +9 -0
- package/artifacts/schema/collection-import-preview.schema.json +143 -0
- package/artifacts/schema/collection-import-request.schema.json +105 -0
- package/artifacts/schema/collection-import-result.schema.json +38 -0
- package/artifacts/schema/collection-list-response.schema.json +119 -0
- package/artifacts/schema/collection-record-get-query.schema.json +12 -0
- package/artifacts/schema/collection-record-history-query.schema.json +35 -0
- package/artifacts/schema/collection-record-history-response.schema.json +389 -0
- package/artifacts/schema/collection-record-list-query.schema.json +67 -0
- package/artifacts/schema/collection-record-list-response.schema.json +212 -0
- package/artifacts/schema/collection-record-restore-request.schema.json +14 -0
- package/artifacts/schema/collection-record-write.schema.json +31 -0
- package/artifacts/schema/collection-record.schema.json +180 -0
- package/artifacts/schema/collection-revision.schema.json +295 -0
- package/artifacts/schema/collection-subscribe-error.schema.json +31 -0
- package/artifacts/schema/collection-subscribe.schema.json +48 -0
- package/artifacts/schema/collection-subscribed.schema.json +22 -0
- package/artifacts/schema/collection-summary.schema.json +92 -0
- package/artifacts/schema/collection-unsubscribe.schema.json +22 -0
- package/artifacts/schema/collections-access-change.schema.json +34 -0
- package/artifacts/schema/collections-document.schema.json +732 -0
- package/artifacts/schema/collections-draft-response.schema.json +845 -0
- package/artifacts/schema/collections-effect.schema.json +384 -0
- package/artifacts/schema/collections-issue.schema.json +36 -0
- package/artifacts/schema/collections-publish-request.schema.json +18 -0
- package/artifacts/schema/collections-publish-response.schema.json +450 -0
- package/artifacts/schema/collections-purge-preview.schema.json +60 -0
- package/artifacts/schema/collections-purge-request.schema.json +27 -0
- package/artifacts/schema/collections-purge-response.schema.json +30 -0
- package/artifacts/schema/collections-restore-preview-query.schema.json +20 -0
- package/artifacts/schema/collections-restore-preview.schema.json +581 -0
- package/artifacts/schema/collections-restore-request.schema.json +27 -0
- package/artifacts/schema/collections-restore-response.schema.json +455 -0
- package/artifacts/schema/collections-schema-preview.schema.json +519 -0
- package/artifacts/schema/collections-schema-published.schema.json +22 -0
- package/artifacts/schema/collections-version-response.schema.json +869 -0
- package/artifacts/schema/collections-version-summary.schema.json +139 -0
- package/artifacts/schema/collections-versions-response.schema.json +167 -0
- package/artifacts/schema/config-draft-response.schema.json +5 -5
- package/artifacts/schema/config-version-response.schema.json +5 -5
- package/artifacts/schema/confirmation-required-details.schema.json +13 -0
- package/artifacts/schema/dangling-reference.schema.json +7 -6
- package/artifacts/schema/datapoint-list-response.schema.json +2 -2
- package/artifacts/schema/effective-rights-response.schema.json +87 -1
- package/artifacts/schema/org-plan.schema.json +29 -1
- package/artifacts/schema/org-quota-usage-counts.schema.json +18 -0
- package/artifacts/schema/org-quota-usage.schema.json +47 -1
- package/artifacts/schema/org-quotas.schema.json +29 -1
- package/artifacts/schema/org-role-list-response.schema.json +8 -7
- package/artifacts/schema/org-role.schema.json +1 -1
- package/artifacts/schema/plan-catalogue-entry.schema.json +29 -1
- package/artifacts/schema/plan-change-decision-status-response.schema.json +29 -1
- package/artifacts/schema/plan-limit-details.schema.json +3 -1
- package/artifacts/schema/plan-limits.schema.json +29 -1
- package/artifacts/schema/plan-overrides.schema.json +26 -0
- package/artifacts/schema/purchase-conflict-details.schema.json +6 -6
- package/artifacts/schema/purchase-intent-draft.schema.json +5 -5
- package/artifacts/schema/purchase-intent-payment-started.schema.json +1 -1
- package/artifacts/schema/purchase-intent-response.schema.json +10 -9
- package/artifacts/schema/put-collections-draft-request.schema.json +16 -0
- package/artifacts/schema/record-changed-details.schema.json +16 -0
- package/artifacts/schema/record-referenced-details.schema.json +35 -0
- package/artifacts/schema/reference-invalid-details.schema.json +25 -0
- package/artifacts/schema/reference-place.schema.json +7 -6
- package/artifacts/schema/required-missing-details.schema.json +19 -0
- package/artifacts/schema/robot-config-doc.schema.json +5 -5
- package/artifacts/schema/robot-deletion-summary.schema.json +33 -1
- package/artifacts/schema/role-collection-rights.schema.json +82 -0
- package/artifacts/schema/role-rename-preview.schema.json +7 -6
- package/dist/apps.d.ts +18 -2
- package/dist/apps.js +12 -2
- package/dist/audit.d.ts +32 -2
- package/dist/audit.js +40 -2
- package/dist/billing.js +12 -3
- package/dist/collections-issues.d.ts +67 -0
- package/dist/collections-issues.js +340 -0
- package/dist/collections-records.d.ts +562 -0
- package/dist/collections-records.js +525 -0
- package/dist/collections-rights.d.ts +17 -0
- package/dist/collections-rights.js +41 -0
- package/dist/collections-schema.d.ts +1064 -0
- package/dist/collections-schema.js +386 -0
- package/dist/collections-templates.d.ts +55 -0
- package/dist/collections-templates.js +137 -0
- package/dist/collections-transfer.d.ts +101 -0
- package/dist/collections-transfer.js +206 -0
- package/dist/collections-values.d.ts +67 -0
- package/dist/collections-values.js +284 -0
- package/dist/collections.d.ts +568 -0
- package/dist/collections.js +332 -0
- package/dist/config.d.ts +8 -8
- package/dist/config.js +13 -13
- package/dist/errors.d.ts +50 -1
- package/dist/errors.js +117 -2
- package/dist/index.d.ts +24 -8
- package/dist/index.js +13 -3
- package/dist/org-roles.d.ts +4 -0
- package/dist/org-roles.js +10 -9
- package/dist/plans.d.ts +22 -2
- package/dist/plans.js +26 -4
- package/dist/realtime.d.ts +166 -0
- package/dist/realtime.js +163 -0
- package/dist/rest.d.ts +28 -28
- package/dist/rest.js +39 -27
- package/dist/rights.d.ts +2 -2
- package/dist/rights.js +1 -1
- package/dist/routes.d.ts +1 -1
- package/dist/routes.js +495 -21
- package/package.json +1 -1
- package/artifacts/schema/put-robot-details-request.schema.json +0 -41
- package/artifacts/schema/put-robot-details-response.schema.json +0 -43
- package/artifacts/schema/robot-details-doc.schema.json +0 -33
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* The schema document of an app's collections: the one YAML (or JSON) document
|
|
5
|
+
* that says which collections an app has, what fields their records carry and
|
|
6
|
+
* which roles may touch them.
|
|
7
|
+
*
|
|
8
|
+
* **This file is the document's grammar, nothing more.** Whether the document is
|
|
9
|
+
* *valid* — a reference that points at a collection that exists, a default that
|
|
10
|
+
* fits its field, no more than the allowed number of collections — is a second
|
|
11
|
+
* question that needs the whole document at once, and
|
|
12
|
+
* `collectionsDocumentIssues` in `collections-issues.ts` answers it. A zod
|
|
13
|
+
* schema that tried to be both would refuse a document with one unhelpful
|
|
14
|
+
* sentence where the issue list names every problem and its path.
|
|
15
|
+
*
|
|
16
|
+
* Every object here is `.strict()`. A key the format does not know is almost
|
|
17
|
+
* always a typo or a misremembered option (`maxlength`, `required_if`), and a
|
|
18
|
+
* schema that silently dropped it would publish a document that means less than
|
|
19
|
+
* it says.
|
|
20
|
+
*/
|
|
21
|
+
/** The document format this package describes. A document names it in `format`. */
|
|
22
|
+
export const COLLECTIONS_FORMAT_VERSION = 1;
|
|
23
|
+
/**
|
|
24
|
+
* Keys a record already uses for itself, so a field may not be called any of
|
|
25
|
+
* them. `robot` is reserved too: `robot.name` in a `display` template names the
|
|
26
|
+
* record's robot, and a field called `robot` would make that ambiguous.
|
|
27
|
+
*/
|
|
28
|
+
export const COLLECTION_RESERVED_KEYS = [
|
|
29
|
+
'id',
|
|
30
|
+
'robot',
|
|
31
|
+
'robot_id',
|
|
32
|
+
'created_at',
|
|
33
|
+
'created_by',
|
|
34
|
+
'updated_at',
|
|
35
|
+
'updated_by',
|
|
36
|
+
'revision',
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Every fixed cap of the collections feature, on every plan. Limits that depend
|
|
40
|
+
* on the plan (records and bytes per organization) are plan limits and live in
|
|
41
|
+
* `plans.ts`.
|
|
42
|
+
*/
|
|
43
|
+
export const COLLECTION_LIMITS = {
|
|
44
|
+
/** Collections in one document. */
|
|
45
|
+
collections: 50,
|
|
46
|
+
/** Fields in one collection. */
|
|
47
|
+
fields: 100,
|
|
48
|
+
/** One record, as serialized JSON. */
|
|
49
|
+
recordBytes: 1_048_576,
|
|
50
|
+
/** The longest a `text` field may be set to. */
|
|
51
|
+
textMax: 1000,
|
|
52
|
+
/** The length of a `text` field without `max_length`. */
|
|
53
|
+
textDefault: 255,
|
|
54
|
+
/** The longest a `long_text` field may be set to. */
|
|
55
|
+
longTextMax: 100_000,
|
|
56
|
+
/** The length of a `long_text` field without `max_length`. */
|
|
57
|
+
longTextDefault: 10_000,
|
|
58
|
+
/** Options of one `select` field. */
|
|
59
|
+
selectOptions: 500,
|
|
60
|
+
/** Values in one `in` filter condition. */
|
|
61
|
+
inValues: 100,
|
|
62
|
+
/** Levels of nested `and` / `or` in a filter. */
|
|
63
|
+
filterDepth: 3,
|
|
64
|
+
/** Conditions in one filter. */
|
|
65
|
+
filterConditions: 50,
|
|
66
|
+
/** Words in one `search` query. */
|
|
67
|
+
searchWords: 10,
|
|
68
|
+
/** Fields in one `sort`. */
|
|
69
|
+
sortFields: 3,
|
|
70
|
+
/** Records per page when `limit` is not given. */
|
|
71
|
+
pageDefault: 50,
|
|
72
|
+
/** The largest `limit`. */
|
|
73
|
+
pageMax: 500,
|
|
74
|
+
/** The largest import file. */
|
|
75
|
+
importBytes: 10_000_000,
|
|
76
|
+
/** The most rows in one import. */
|
|
77
|
+
importRows: 50_000,
|
|
78
|
+
/** Record writes per minute for one app. An import counts as one. */
|
|
79
|
+
writesPerMinuteApp: 600,
|
|
80
|
+
/** Record writes per minute for one acting user or key. An import counts as one. */
|
|
81
|
+
writesPerMinuteActor: 120,
|
|
82
|
+
/** How long after its restore point a schema version can be restored together with its data. */
|
|
83
|
+
restoreDays: 90,
|
|
84
|
+
/** The history is reported as growing when it holds more than this many times as many revisions as records... */
|
|
85
|
+
growthFactor: 10,
|
|
86
|
+
/** ...and at least this many revisions. */
|
|
87
|
+
growthMinRevisions: 10_000,
|
|
88
|
+
/** The schema document as text, counted in bytes of UTF-8 and not in characters. */
|
|
89
|
+
schemaSourceBytes: 1_000_000,
|
|
90
|
+
/** The longest `pattern` of a `text` field, in characters. */
|
|
91
|
+
patternMax: 1000,
|
|
92
|
+
/** Levels of arrays and objects inside one `json` value. */
|
|
93
|
+
jsonDepth: 32,
|
|
94
|
+
/** The longest column name or value an import error repeats, an ellipsis included. */
|
|
95
|
+
importErrorText: 200,
|
|
96
|
+
};
|
|
97
|
+
const KEY_RULE = /^[a-z][a-z0-9_]{0,62}$/;
|
|
98
|
+
/**
|
|
99
|
+
* A collection key or a field key. Keys are the API contract (they appear in
|
|
100
|
+
* URLs, filters and record bodies), so they are fixed lowercase identifiers;
|
|
101
|
+
* `label` carries the words a person reads.
|
|
102
|
+
*/
|
|
103
|
+
export const collectionKey = z
|
|
104
|
+
.string()
|
|
105
|
+
.regex(KEY_RULE, {
|
|
106
|
+
message: 'A key starts with a lowercase letter and continues with lowercase letters, digits or underscores, up to 63 characters in all.',
|
|
107
|
+
})
|
|
108
|
+
.meta({ description: 'A collection key or a field key: `^[a-z][a-z0-9_]{0,62}$`. Keys appear in URLs, filters and record bodies; `label` is the text people read.' });
|
|
109
|
+
/**
|
|
110
|
+
* How a collection relates to robots. A property of the collection and not a
|
|
111
|
+
* field type, so a record's robot can neither be left out of a robot-bound
|
|
112
|
+
* collection nor changed afterwards.
|
|
113
|
+
*/
|
|
114
|
+
export const collectionBinding = z
|
|
115
|
+
.enum(['global', 'per_robot', 'one_per_robot'])
|
|
116
|
+
.meta({
|
|
117
|
+
description: '`global`: records belong to the app and no robot. `per_robot`: every record belongs to one robot (system field `robot_id`, fixed when the record is created). `one_per_robot`: every robot of the app has exactly one record, which Fleetless creates itself.',
|
|
118
|
+
});
|
|
119
|
+
/** The nine kinds of value a field can hold. */
|
|
120
|
+
export const collectionFieldType = z.enum([
|
|
121
|
+
'text',
|
|
122
|
+
'long_text',
|
|
123
|
+
'number',
|
|
124
|
+
'boolean',
|
|
125
|
+
'select',
|
|
126
|
+
'date',
|
|
127
|
+
'datetime',
|
|
128
|
+
'json',
|
|
129
|
+
'reference',
|
|
130
|
+
]);
|
|
131
|
+
const label = z.string().max(120).meta({ description: 'A short name for people to read. It may change at any time; the key is what code uses.' });
|
|
132
|
+
const description = z.string().max(1000).meta({ description: 'Free text that explains the field to the people who fill it in.' });
|
|
133
|
+
/** Options every field type carries. */
|
|
134
|
+
const common = {
|
|
135
|
+
label: label.optional(),
|
|
136
|
+
description: description.optional(),
|
|
137
|
+
required: z
|
|
138
|
+
.boolean()
|
|
139
|
+
.meta({ description: 'A new record must set this field, and an update may not clear it.' })
|
|
140
|
+
.optional(),
|
|
141
|
+
unique: z
|
|
142
|
+
.union([z.boolean(), z.literal('collection')])
|
|
143
|
+
.meta({
|
|
144
|
+
description: '`true`: no two records hold the same value, within the collection (`global`) or within one robot (`per_robot`, `one_per_robot`). `collection`: on a robot-bound collection, across all robots. Empty values never collide. Not allowed on `boolean` and `json` fields.',
|
|
145
|
+
})
|
|
146
|
+
.optional(),
|
|
147
|
+
default: z
|
|
148
|
+
.unknown()
|
|
149
|
+
.meta({ description: 'The value a record gets when it does not set this field. It must itself be a valid value of the field.' })
|
|
150
|
+
.optional(),
|
|
151
|
+
};
|
|
152
|
+
const textField = z
|
|
153
|
+
.object({
|
|
154
|
+
type: z.literal('text'),
|
|
155
|
+
...common,
|
|
156
|
+
max_length: z
|
|
157
|
+
.number()
|
|
158
|
+
.int()
|
|
159
|
+
.min(1)
|
|
160
|
+
.max(COLLECTION_LIMITS.textMax)
|
|
161
|
+
.meta({ description: `Longest value in characters. Default ${COLLECTION_LIMITS.textDefault}, at most ${COLLECTION_LIMITS.textMax}.` })
|
|
162
|
+
.optional(),
|
|
163
|
+
pattern: z
|
|
164
|
+
.string()
|
|
165
|
+
.max(COLLECTION_LIMITS.patternMax)
|
|
166
|
+
.meta({
|
|
167
|
+
description: `A regular expression in the RE2 subset, checked in unicode mode: lookahead, lookbehind and backreferences are not supported. At most ${COLLECTION_LIMITS.patternMax.toLocaleString('en-US')} characters, and the cloud may also refuse a pattern as too complex (its compiled size is bounded; counted repeats such as \`{n}\` multiply it), which a document reports as an invalid pattern. The value must match somewhere in it; anchor it with \`^\` and \`$\` to match the whole value.`,
|
|
168
|
+
})
|
|
169
|
+
.optional(),
|
|
170
|
+
searchable: z.boolean().meta({ description: 'Include this field in the `search` of record lists.' }).optional(),
|
|
171
|
+
})
|
|
172
|
+
.strict();
|
|
173
|
+
const longTextField = z
|
|
174
|
+
.object({
|
|
175
|
+
type: z.literal('long_text'),
|
|
176
|
+
...common,
|
|
177
|
+
max_length: z
|
|
178
|
+
.number()
|
|
179
|
+
.int()
|
|
180
|
+
.min(1)
|
|
181
|
+
.max(COLLECTION_LIMITS.longTextMax)
|
|
182
|
+
.meta({ description: `Longest value in characters. Default ${COLLECTION_LIMITS.longTextDefault}, at most ${COLLECTION_LIMITS.longTextMax}.` })
|
|
183
|
+
.optional(),
|
|
184
|
+
searchable: z.boolean().meta({ description: 'Include this field in the `search` of record lists.' }).optional(),
|
|
185
|
+
})
|
|
186
|
+
.strict();
|
|
187
|
+
const numberField = z
|
|
188
|
+
.object({
|
|
189
|
+
type: z.literal('number'),
|
|
190
|
+
...common,
|
|
191
|
+
integer: z.boolean().meta({ description: 'Accept whole numbers only.' }).optional(),
|
|
192
|
+
min: z.number().meta({ description: 'Smallest accepted value.' }).optional(),
|
|
193
|
+
max: z.number().meta({ description: 'Largest accepted value.' }).optional(),
|
|
194
|
+
unit: z.string().meta({ description: 'A unit to show next to the value, such as `m` or `rad/s`. Display only; nothing converts values.' }).optional(),
|
|
195
|
+
})
|
|
196
|
+
.strict();
|
|
197
|
+
const booleanField = z.object({ type: z.literal('boolean'), ...common }).strict();
|
|
198
|
+
/** One choice of a `select` field. */
|
|
199
|
+
const selectOption = z
|
|
200
|
+
.object({
|
|
201
|
+
value: z.string().min(1).max(200).meta({ description: 'What is stored in records and used in filters.' }),
|
|
202
|
+
label: z.string().meta({ description: 'What people see instead of the value.' }).optional(),
|
|
203
|
+
})
|
|
204
|
+
.strict();
|
|
205
|
+
const selectField = z
|
|
206
|
+
.object({
|
|
207
|
+
type: z.literal('select'),
|
|
208
|
+
...common,
|
|
209
|
+
options: z
|
|
210
|
+
.array(selectOption)
|
|
211
|
+
.min(1)
|
|
212
|
+
.max(COLLECTION_LIMITS.selectOptions)
|
|
213
|
+
.meta({ description: `The accepted values, 1 to ${COLLECTION_LIMITS.selectOptions}. Two options may not share a value.` }),
|
|
214
|
+
multiple: z.boolean().meta({ description: 'Hold a list of distinct options instead of one.' }).optional(),
|
|
215
|
+
searchable: z.boolean().meta({ description: 'Include the values and labels of the chosen options in the `search` of record lists.' }).optional(),
|
|
216
|
+
})
|
|
217
|
+
.strict();
|
|
218
|
+
const dateField = z.object({ type: z.literal('date'), ...common }).strict();
|
|
219
|
+
const datetimeField = z.object({ type: z.literal('datetime'), ...common }).strict();
|
|
220
|
+
const jsonField = z
|
|
221
|
+
.object({
|
|
222
|
+
type: z.literal('json'),
|
|
223
|
+
...common,
|
|
224
|
+
schema: z
|
|
225
|
+
.union([z.string(), z.record(z.string(), z.unknown())])
|
|
226
|
+
.meta({
|
|
227
|
+
description: 'What the value must look like: the name of a built-in template (`pose2d`, `point2d`, `polygon2d`, `range1d`) or an inline JSON Schema (draft 2020-12). Without it any JSON value is accepted.',
|
|
228
|
+
})
|
|
229
|
+
.optional(),
|
|
230
|
+
})
|
|
231
|
+
.strict();
|
|
232
|
+
const referenceField = z
|
|
233
|
+
.object({
|
|
234
|
+
type: z.literal('reference'),
|
|
235
|
+
...common,
|
|
236
|
+
to: collectionKey.meta({ description: 'The key of the collection whose records this field points at. It must be a collection of the same document.' }),
|
|
237
|
+
on_delete: z
|
|
238
|
+
.enum(['prevent', 'clear'])
|
|
239
|
+
.meta({
|
|
240
|
+
description: '`prevent` (the default): a record that other records point at cannot be deleted. `clear`: deleting it clears the reference in the records that pointed at it.',
|
|
241
|
+
})
|
|
242
|
+
.optional(),
|
|
243
|
+
})
|
|
244
|
+
.strict();
|
|
245
|
+
/**
|
|
246
|
+
* One field definition, discriminated on `type`. A union and not one object
|
|
247
|
+
* with every option optional: `max_length` on a `number` would otherwise parse
|
|
248
|
+
* and mean nothing.
|
|
249
|
+
*/
|
|
250
|
+
export const collectionField = z.discriminatedUnion('type', [
|
|
251
|
+
textField,
|
|
252
|
+
longTextField,
|
|
253
|
+
numberField,
|
|
254
|
+
booleanField,
|
|
255
|
+
selectField,
|
|
256
|
+
dateField,
|
|
257
|
+
datetimeField,
|
|
258
|
+
jsonField,
|
|
259
|
+
referenceField,
|
|
260
|
+
]);
|
|
261
|
+
/** The key of an organization role, as the organization spells it. A key that names no role grants nothing and is a warning. */
|
|
262
|
+
export const collectionAccessValue = z
|
|
263
|
+
.union([z.string().min(1).max(63), z.array(z.string().min(1).max(63))])
|
|
264
|
+
.meta({ description: 'The key of an organization role, or a list of keys. A key that names no role grants nothing.' });
|
|
265
|
+
const allOwn = z
|
|
266
|
+
.object({
|
|
267
|
+
all: collectionAccessValue.meta({ description: 'Roles that may do this to every record.' }).optional(),
|
|
268
|
+
own: collectionAccessValue.meta({ description: 'Roles that may do this only to records they created themselves.' }).optional(),
|
|
269
|
+
})
|
|
270
|
+
.strict();
|
|
271
|
+
/**
|
|
272
|
+
* Which roles may do what with a collection's records. A key that is missing,
|
|
273
|
+
* or a collection without `access`, grants that action to nobody; developers
|
|
274
|
+
* and the app's server keys always may. A role key the organization does not
|
|
275
|
+
* have is a warning (see `collectionsAccessWarnings`), never a reason to
|
|
276
|
+
* refuse the document.
|
|
277
|
+
*/
|
|
278
|
+
export const collectionAccess = z
|
|
279
|
+
.object({
|
|
280
|
+
read: collectionAccessValue.meta({ description: 'Roles that may read records.' }).optional(),
|
|
281
|
+
create: collectionAccessValue.meta({ description: 'Roles that may create records. Has no effect on `one_per_robot` collections, whose records Fleetless creates.' }).optional(),
|
|
282
|
+
update: z
|
|
283
|
+
.union([collectionAccessValue, allOwn])
|
|
284
|
+
.meta({ description: 'Roles that may change records: a role key, a list, or `{ all, own }` to tell every record from the ones a role created itself.' })
|
|
285
|
+
.optional(),
|
|
286
|
+
delete: z
|
|
287
|
+
.union([collectionAccessValue, allOwn])
|
|
288
|
+
.meta({ description: 'Roles that may delete records: a role key, a list, or `{ all, own }`. Has no effect on `one_per_robot` collections, whose records are never deleted through the API.' })
|
|
289
|
+
.optional(),
|
|
290
|
+
})
|
|
291
|
+
.strict()
|
|
292
|
+
.meta({ description: 'Which roles may read, create, update and delete the records of this collection. A missing key grants that action to nobody; developers and server keys can always do everything.' });
|
|
293
|
+
/** One collection: its binding, how its records are named, who may use it and its fields. */
|
|
294
|
+
export const collectionDefinition = z
|
|
295
|
+
.object({
|
|
296
|
+
label: z.string().meta({ description: 'A name for people to read. It may change at any time; the key is what code uses.' }).optional(),
|
|
297
|
+
description: z.string().meta({ description: 'Free text that explains the collection to people.' }).optional(),
|
|
298
|
+
binding: collectionBinding,
|
|
299
|
+
display: z
|
|
300
|
+
.string()
|
|
301
|
+
.meta({
|
|
302
|
+
description: 'A template that names a record in lists, references and titles, for example `{{name}} ({{location.name}})`. A placeholder is a field of this collection, a system field (`id`, `created_at`, `created_by`, `updated_at`, `updated_by`, `revision`, and `robot_id` on robot-bound collections), `robot.name` on robot-bound collections, or `<reference field>.<field of the target>`.',
|
|
303
|
+
})
|
|
304
|
+
.optional(),
|
|
305
|
+
access: collectionAccess.optional(),
|
|
306
|
+
fields: z
|
|
307
|
+
.record(collectionKey, collectionField)
|
|
308
|
+
.meta({ description: `The fields of a record, at most ${COLLECTION_LIMITS.fields}. Their order is the order of the record form.` }),
|
|
309
|
+
})
|
|
310
|
+
.strict();
|
|
311
|
+
const collectionsMap = z.record(collectionKey, collectionDefinition);
|
|
312
|
+
/**
|
|
313
|
+
* The document itself. The caps on collections and fields are validity rules of
|
|
314
|
+
* `collectionsDocumentIssues` rather than zod limits, so a document one
|
|
315
|
+
* collection over still parses and is told exactly which rule it breaks.
|
|
316
|
+
*
|
|
317
|
+
* `collections:` with nothing under it, which YAML reads as `null`, is the
|
|
318
|
+
* same as `collections: {}`: a document that has no collections yet, which is
|
|
319
|
+
* what a template for a new app looks like. Anything else that is not a map is
|
|
320
|
+
* still refused.
|
|
321
|
+
*/
|
|
322
|
+
export const collectionsDocument = z
|
|
323
|
+
.object({
|
|
324
|
+
format: z.literal(COLLECTIONS_FORMAT_VERSION).meta({ description: `The document format version. Always ${COLLECTIONS_FORMAT_VERSION}.` }),
|
|
325
|
+
// A codec on the property and not a preprocess on the document: the published JSON Schema then says `object | null` and still lists
|
|
326
|
+
// `collections` as required, and the parsed value (and the output schema) is the plain map.
|
|
327
|
+
collections: z
|
|
328
|
+
.codec(collectionsMap.nullable(), collectionsMap, { decode: (value) => value ?? {}, encode: (value) => value })
|
|
329
|
+
.meta({ description: `The collections of the app by key, at most ${COLLECTION_LIMITS.collections}. Nothing under \`collections:\` (null) means none.` }),
|
|
330
|
+
})
|
|
331
|
+
.strict()
|
|
332
|
+
.meta({ description: 'The data model of an app: its collections, their fields, and who may use them.' });
|
package/dist/config.d.ts
CHANGED
|
@@ -133,13 +133,13 @@ export declare const parameterMap: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
|
133
133
|
* sections at once** — slugs are one namespace, so a name reserved here is
|
|
134
134
|
* reserved everywhere.
|
|
135
135
|
*
|
|
136
|
-
* The first
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
136
|
+
* The first is a built-in: the cloud already publishes something under it,
|
|
137
|
+
* so a configured entry would be a second producer for one name. The other
|
|
138
|
+
* three are reserved for a different reason and are not built-ins — nothing
|
|
139
|
+
* publishes them. `assets` and `job_history` are the robot-level capabilities
|
|
140
|
+
* a role can be required for and an app can lock; an entry of the same name
|
|
141
|
+
* would leave a capability's `name` ambiguous between an exposure and the
|
|
142
|
+
* robot as a whole. `history` is reserved because
|
|
143
143
|
* `GET /api/robots/:id/jobs/history` is a **literal sibling** of
|
|
144
144
|
* `GET /api/robots/:id/jobs/:slug`, so an action or service named `history`
|
|
145
145
|
* would have a job route no caller could ever reach. Reserving the name is the
|
|
@@ -161,7 +161,7 @@ export declare const parameterMap: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
|
161
161
|
* ships those sentences to readers who have only the JSON Schema, and
|
|
162
162
|
* "here" would have promised them a refusal this parse does not make.
|
|
163
163
|
*/
|
|
164
|
-
export declare const RESERVED_SLUGS: readonly ["bridge_state", "
|
|
164
|
+
export declare const RESERVED_SLUGS: readonly ["bridge_state", "history", "assets", "job_history"];
|
|
165
165
|
/**
|
|
166
166
|
* When an alert fires and when it is ok again. There is no discriminator:
|
|
167
167
|
* `resolve_at` absent means equality, present means a threshold whose
|
package/dist/config.js
CHANGED
|
@@ -658,13 +658,13 @@ export const parameterMap = slugKeyed(parameterSpec)
|
|
|
658
658
|
* sections at once** — slugs are one namespace, so a name reserved here is
|
|
659
659
|
* reserved everywhere.
|
|
660
660
|
*
|
|
661
|
-
* The first
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
661
|
+
* The first is a built-in: the cloud already publishes something under it,
|
|
662
|
+
* so a configured entry would be a second producer for one name. The other
|
|
663
|
+
* three are reserved for a different reason and are not built-ins — nothing
|
|
664
|
+
* publishes them. `assets` and `job_history` are the robot-level capabilities
|
|
665
|
+
* a role can be required for and an app can lock; an entry of the same name
|
|
666
|
+
* would leave a capability's `name` ambiguous between an exposure and the
|
|
667
|
+
* robot as a whole. `history` is reserved because
|
|
668
668
|
* `GET /api/robots/:id/jobs/history` is a **literal sibling** of
|
|
669
669
|
* `GET /api/robots/:id/jobs/:slug`, so an action or service named `history`
|
|
670
670
|
* would have a job route no caller could ever reach. Reserving the name is the
|
|
@@ -686,7 +686,7 @@ export const parameterMap = slugKeyed(parameterSpec)
|
|
|
686
686
|
* ships those sentences to readers who have only the JSON Schema, and
|
|
687
687
|
* "here" would have promised them a refusal this parse does not make.
|
|
688
688
|
*/
|
|
689
|
-
export const RESERVED_SLUGS = ['bridge_state', '
|
|
689
|
+
export const RESERVED_SLUGS = ['bridge_state', 'history', 'assets', 'job_history'];
|
|
690
690
|
/**
|
|
691
691
|
* When an alert fires and when it is ok again. There is no discriminator:
|
|
692
692
|
* `resolve_at` absent means equality, present means a threshold whose
|
|
@@ -2036,26 +2036,26 @@ export const robotConfigDoc = strictObject({
|
|
|
2036
2036
|
defaultSnippets: [underSlug('${1:drive}', SHARED_MESSAGE_SNIPPET)],
|
|
2037
2037
|
}).optional(),
|
|
2038
2038
|
datapoints: capped(datapointConfig, 200, 'datapoints').meta({
|
|
2039
|
-
description: 'Values the robot publishes, each one field of one topic or a whole topic, and **never several topics**. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state`
|
|
2039
|
+
description: 'Values the robot publishes, each one field of one topic or a whole topic, and **never several topics**. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state` is built-in, `history` is reserved because `GET …/jobs/history` would shadow an action of that name, and `assets` and `job_history` are reserved because they name the robot-level capabilities; all four are refused when the document is validated.',
|
|
2040
2040
|
defaultSnippets: [
|
|
2041
2041
|
underSlug('${1:battery_voltage}', DATAPOINT_SNIPPET),
|
|
2042
2042
|
underSlug('${1:battery}', NUMERIC_DATAPOINT_SNIPPET),
|
|
2043
2043
|
],
|
|
2044
2044
|
}).optional(),
|
|
2045
2045
|
actions: capped(actionConfig, 200, 'actions').meta({
|
|
2046
|
-
description: 'Things the robot does on request that take time, each reported as a job with progress. **At most one job runs per action slug**: a second call is refused `busy`, and every observer of that slug watches the same job. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state`
|
|
2046
|
+
description: 'Things the robot does on request that take time, each reported as a job with progress. **At most one job runs per action slug**: a second call is refused `busy`, and every observer of that slug watches the same job. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state` is built-in, `history` is reserved because `GET …/jobs/history` would shadow an action of that name, and `assets` and `job_history` are reserved because they name the robot-level capabilities; all four are refused when the document is validated.',
|
|
2047
2047
|
defaultSnippets: [underSlug('${1:navigate}', ACTION_SNIPPET)],
|
|
2048
2048
|
}).optional(),
|
|
2049
2049
|
services: capped(serviceConfig, 200, 'services').meta({
|
|
2050
|
-
description: 'ROS service calls the robot answers — one request, one reply. Unlike an action a service reports **no progress** and the call returns with its result already on the job, so there is nothing left to observe; a second concurrent call is still refused `busy`, exactly as for an action. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state`
|
|
2050
|
+
description: 'ROS service calls the robot answers — one request, one reply. Unlike an action a service reports **no progress** and the call returns with its result already on the job, so there is nothing left to observe; a second concurrent call is still refused `busy`, exactly as for an action. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state` is built-in, `history` is reserved because `GET …/jobs/history` would shadow an action of that name, and `assets` and `job_history` are reserved because they name the robot-level capabilities; all four are refused when the document is validated.',
|
|
2051
2051
|
defaultSnippets: [underSlug('${1:reset_odometry}', SERVICE_SNIPPET)],
|
|
2052
2052
|
}).optional(),
|
|
2053
2053
|
publishers: capped(publisherConfig, 200, 'publishers').meta({
|
|
2054
|
-
description: 'Topics clients may send to, and where the format\'s whole safety story lives. The `message` template fixes every value a caller cannot change, and **`failsafe` is required**: once a client falls silent the bridge sends the failsafe message itself, so an operator whose window closed does not leave a robot driving. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state`
|
|
2054
|
+
description: 'Topics clients may send to, and where the format\'s whole safety story lives. The `message` template fixes every value a caller cannot change, and **`failsafe` is required**: once a client falls silent the bridge sends the failsafe message itself, so an operator whose window closed does not leave a robot driving. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state` is built-in, `history` is reserved because `GET …/jobs/history` would shadow an action of that name, and `assets` and `job_history` are reserved because they name the robot-level capabilities; all four are refused when the document is validated.',
|
|
2055
2055
|
defaultSnippets: [underSlug('${1:drive}', PUBLISHER_SNIPPET)],
|
|
2056
2056
|
}).optional(),
|
|
2057
2057
|
cameras: capped(cameraConfig, 50, 'cameras').meta({
|
|
2058
|
-
description: 'Video the robot streams, and the still frames the cloud serves from it. `width`, `height`, `fps` and `bitrate_kbps` are what **the bridge produces before sending**, not what the camera captures — they live in the configuration rather than in a viewer\'s request precisely so that no viewer can make a robot send more. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state`
|
|
2058
|
+
description: 'Video the robot streams, and the still frames the cloud serves from it. `width`, `height`, `fps` and `bitrate_kbps` are what **the bridge produces before sending**, not what the camera captures — they live in the configuration rather than in a viewer\'s request precisely so that no viewer can make a robot send more. Keys are slugs, one namespace across all five exposure sections, which is what lets an app lock name `{robot, slug}` without naming a kind; `bridge_state` is built-in, `history` is reserved because `GET …/jobs/history` would shadow an action of that name, and `assets` and `job_history` are reserved because they name the robot-level capabilities; all four are refused when the document is validated.',
|
|
2059
2059
|
defaultSnippets: [underSlug('${1:front}', CAMERA_SNIPPET)],
|
|
2060
2060
|
}).optional(),
|
|
2061
2061
|
access: accessSection.meta({
|
package/dist/errors.d.ts
CHANGED
|
@@ -95,6 +95,8 @@ export declare const planLimitDetails: z.ZodObject<{
|
|
|
95
95
|
app_users: "app_users";
|
|
96
96
|
live_video_ms_per_month: "live_video_ms_per_month";
|
|
97
97
|
asset_bytes_per_robot: "asset_bytes_per_robot";
|
|
98
|
+
collection_records: "collection_records";
|
|
99
|
+
collection_bytes: "collection_bytes";
|
|
98
100
|
}>;
|
|
99
101
|
used: z.ZodNumber;
|
|
100
102
|
max: z.ZodNumber;
|
|
@@ -149,6 +151,8 @@ export declare const assetPlanLimitDetails: z.ZodObject<{
|
|
|
149
151
|
app_users: "app_users";
|
|
150
152
|
live_video_ms_per_month: "live_video_ms_per_month";
|
|
151
153
|
asset_bytes_per_robot: "asset_bytes_per_robot";
|
|
154
|
+
collection_records: "collection_records";
|
|
155
|
+
collection_bytes: "collection_bytes";
|
|
152
156
|
}>;
|
|
153
157
|
used: z.ZodNumber;
|
|
154
158
|
max: z.ZodNumber;
|
|
@@ -241,6 +245,51 @@ export declare const billingDocumentsUnavailableDetails: z.ZodObject<{
|
|
|
241
245
|
}>;
|
|
242
246
|
}, z.core.$strict>;
|
|
243
247
|
export type BillingDocumentsUnavailableDetails = z.infer<typeof billingDocumentsUnavailableDetails>;
|
|
248
|
+
/**
|
|
249
|
+
* The `details` of a `409 confirmation_required` refusal: the preview as it is
|
|
250
|
+
* now, which carries the `token` that confirms it. Sent when a publish, a
|
|
251
|
+
* restore, a purge or an import would change or remove data and the request
|
|
252
|
+
* brought no token, or one for data that has changed since.
|
|
253
|
+
*/
|
|
254
|
+
export declare const confirmationRequiredDetails: z.ZodObject<{
|
|
255
|
+
preview: z.ZodUnknown;
|
|
256
|
+
}, z.core.$strict>;
|
|
257
|
+
export type ConfirmationRequiredDetails = z.infer<typeof confirmationRequiredDetails>;
|
|
258
|
+
/**
|
|
259
|
+
* The `details` of a `409 record_referenced` refusal. Counts only: the caller
|
|
260
|
+
* may not be allowed to read the records that point here, so neither their
|
|
261
|
+
* ids nor their values are told. Nor is the key of a collection the caller may
|
|
262
|
+
* not read, for the reason `collection_not_found` is answered for one: the list
|
|
263
|
+
* names only collections the caller may read, and it is empty when every
|
|
264
|
+
* collection that points here is one they may not.
|
|
265
|
+
*/
|
|
266
|
+
export declare const recordReferencedDetails: z.ZodObject<{
|
|
267
|
+
references: z.ZodArray<z.ZodObject<{
|
|
268
|
+
collection: z.ZodString;
|
|
269
|
+
count: z.ZodNumber;
|
|
270
|
+
}, z.core.$strict>>;
|
|
271
|
+
}, z.core.$strict>;
|
|
272
|
+
export type RecordReferencedDetails = z.infer<typeof recordReferencedDetails>;
|
|
273
|
+
/** The `details` of a `409 record_changed` refusal: the revision the record is at now, for the caller to read it again. */
|
|
274
|
+
export declare const recordChangedDetails: z.ZodObject<{
|
|
275
|
+
revision: z.ZodNumber;
|
|
276
|
+
}, z.core.$strict>;
|
|
277
|
+
export type RecordChangedDetails = z.infer<typeof recordChangedDetails>;
|
|
278
|
+
/** The `details` of a `400 reference_invalid` refusal: which reference field, and why its value was refused. */
|
|
279
|
+
export declare const referenceInvalidDetails: z.ZodObject<{
|
|
280
|
+
field: z.ZodString;
|
|
281
|
+
reason: z.ZodEnum<{
|
|
282
|
+
missing: "missing";
|
|
283
|
+
other_robot: "other_robot";
|
|
284
|
+
not_readable: "not_readable";
|
|
285
|
+
}>;
|
|
286
|
+
}, z.core.$strict>;
|
|
287
|
+
export type ReferenceInvalidDetails = z.infer<typeof referenceInvalidDetails>;
|
|
288
|
+
/** The `details` of a `400 required_missing` refusal: every required field the write would leave empty. */
|
|
289
|
+
export declare const requiredMissingDetails: z.ZodObject<{
|
|
290
|
+
fields: z.ZodArray<z.ZodString>;
|
|
291
|
+
}, z.core.$strict>;
|
|
292
|
+
export type RequiredMissingDetails = z.infer<typeof requiredMissingDetails>;
|
|
244
293
|
/**
|
|
245
294
|
* The `details` of a `400 role_cycle` refusal: the loop the change would have
|
|
246
295
|
* made, along the `inherits` edges, as `[a, b, a]` — the first key again at
|
|
@@ -255,5 +304,5 @@ export type RoleCycleDetails = z.infer<typeof roleCycleDetails>;
|
|
|
255
304
|
* list is the shared vocabulary, not a closed set, so a new refusal never
|
|
256
305
|
* needs a contracts release before it can be reported honestly.
|
|
257
306
|
*/
|
|
258
|
-
export declare const ERROR_CODES: readonly ["not_found", "validation_error", "bad_request", "unknown_datapoint", "invalid_token", "protocol_mismatch", "bridge_too_old", "invalid_frame", "duplicate_slug", "reserved_slug", "unknown_slug", "unknown_field_path", "unknown_type", "unknown_topic", "invalid_rate", "invalid_range", "config_conflict", "no_data", "robot_offline", "bridge_timeout", "unauthorized", "forbidden", "invalid_credentials", "token_expired", "token_revoked", "email_taken", "identifier_taken", "weak_password", "account_blocked", "busy", "parameter_invalid", "cancel_rejected", "job_lost", "operator_verified_stopped", "job_unknown_to_bridge", "action_server_lost", "action_failed", "goal_rejected", "goal_send_failed", "result_failed", "goal_uncontrollable", "bridge_disconnected", "config_changed", "publisher_busy", "unknown_command", "not_subscribable", "camera_offline", "no_snapshot_yet", "live_unavailable", "wrong_kind", "not_recorded", "not_aggregatable", "quota_exceeded", "credential_in_use", "goal_timeout", "robot_in_use", "robot_deletion_partial", "job_queue_full", "invalid_uuid", "rate_limited", "tier_required", "token_spent", "service_timeout", "asset_missing", "dynamic_registration_disabled", "client_limit_reached", "idp_unavailable", "mcp_disabled", "tool_not_available", "capability_required", "last_owner", "role_cycle", "role_key_taken", "confirmation_required", "target_state_conflict", "job_state_conflict", "signup_closed", "draft_not_a_document", "internal_error", "not_cancellable", "unsupported_media_type", "wrong_browser", "invalid_yaml", "unstorable_yaml", "registration_closed", "domain_not_allowed", "email_unverified", "origin_not_allowed", "template_invalid", "provider_disabled", "provider_misconfigured", "invalid_redirect_uri", "interaction_expired", "invalid_code", "method_not_allowed", "plan_limit", "plan_required", "org_locked", "file_too_large", "billing_unavailable", "legal_offer_unavailable", "payment_provider_unavailable", "history_migrating", "billing_documents_unavailable", "support_read_only", "support_forbidden"];
|
|
307
|
+
export declare const ERROR_CODES: readonly ["not_found", "validation_error", "bad_request", "unknown_datapoint", "invalid_token", "protocol_mismatch", "bridge_too_old", "invalid_frame", "duplicate_slug", "reserved_slug", "unknown_slug", "unknown_field_path", "unknown_type", "unknown_topic", "invalid_rate", "invalid_range", "config_conflict", "no_data", "robot_offline", "bridge_timeout", "unauthorized", "forbidden", "invalid_credentials", "token_expired", "token_revoked", "email_taken", "identifier_taken", "weak_password", "account_blocked", "busy", "parameter_invalid", "cancel_rejected", "job_lost", "operator_verified_stopped", "job_unknown_to_bridge", "action_server_lost", "action_failed", "goal_rejected", "goal_send_failed", "result_failed", "goal_uncontrollable", "bridge_disconnected", "config_changed", "publisher_busy", "unknown_command", "not_subscribable", "camera_offline", "no_snapshot_yet", "live_unavailable", "wrong_kind", "not_recorded", "not_aggregatable", "quota_exceeded", "credential_in_use", "goal_timeout", "robot_in_use", "robot_deletion_partial", "job_queue_full", "invalid_uuid", "rate_limited", "tier_required", "token_spent", "service_timeout", "asset_missing", "dynamic_registration_disabled", "client_limit_reached", "idp_unavailable", "mcp_disabled", "tool_not_available", "capability_required", "last_owner", "role_cycle", "role_key_taken", "confirmation_required", "target_state_conflict", "job_state_conflict", "signup_closed", "draft_not_a_document", "internal_error", "not_cancellable", "unsupported_media_type", "wrong_browser", "invalid_yaml", "unstorable_yaml", "registration_closed", "domain_not_allowed", "email_unverified", "origin_not_allowed", "template_invalid", "provider_disabled", "provider_misconfigured", "invalid_redirect_uri", "interaction_expired", "invalid_code", "method_not_allowed", "plan_limit", "plan_required", "org_locked", "file_too_large", "billing_unavailable", "legal_offer_unavailable", "payment_provider_unavailable", "history_migrating", "billing_documents_unavailable", "support_read_only", "support_forbidden", "record_referenced", "record_changed", "collection_not_found", "collection_removed", "reference_invalid", "required_missing", "robot_not_attached"];
|
|
259
308
|
export type ErrorCode = (typeof ERROR_CODES)[number];
|