@fleetless/contracts 13.3.0 → 15.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 (182) hide show
  1. package/CHANGELOG.md +304 -0
  2. package/artifacts/openapi.json +20156 -10513
  3. package/artifacts/routes.json +1429 -292
  4. package/artifacts/schema/access-warning.schema.json +51 -0
  5. package/artifacts/schema/action-config.schema.json +35 -0
  6. package/artifacts/schema/addon-catalogue-entry.schema.json +3 -1
  7. package/artifacts/schema/admin-plan-change-request.schema.json +26 -0
  8. package/artifacts/schema/app-access-response.schema.json +136 -0
  9. package/artifacts/schema/app-access.schema.json +80 -0
  10. package/artifacts/schema/app-deletion-summary.schema.json +15 -8
  11. package/artifacts/schema/app-invitation-list-response.schema.json +13 -6
  12. package/artifacts/schema/app-invitation.schema.json +5 -5
  13. package/artifacts/schema/app-list-response.schema.json +6 -6
  14. package/artifacts/schema/app-lock.schema.json +30 -0
  15. package/artifacts/schema/app-user-list-response.schema.json +13 -6
  16. package/artifacts/schema/app-user.schema.json +13 -6
  17. package/artifacts/schema/app.schema.json +6 -6
  18. package/artifacts/schema/asset-plan-limit-details.schema.json +3 -1
  19. package/artifacts/schema/auth-ok.schema.json +20 -6
  20. package/artifacts/schema/camera-list-response.schema.json +1 -1
  21. package/artifacts/schema/client-identity.schema.json +21 -6
  22. package/artifacts/schema/cloud-config.schema.json +359 -5
  23. package/artifacts/schema/collection-actor.schema.json +35 -0
  24. package/artifacts/schema/collection-definitions-response.schema.json +612 -0
  25. package/artifacts/schema/collection-event.schema.json +216 -0
  26. package/artifacts/schema/collection-export-query.schema.json +56 -0
  27. package/artifacts/schema/collection-filter.schema.json +9 -0
  28. package/artifacts/schema/collection-import-preview.schema.json +143 -0
  29. package/artifacts/schema/collection-import-request.schema.json +105 -0
  30. package/artifacts/schema/collection-import-result.schema.json +38 -0
  31. package/artifacts/schema/collection-list-response.schema.json +119 -0
  32. package/artifacts/schema/collection-record-get-query.schema.json +12 -0
  33. package/artifacts/schema/collection-record-history-query.schema.json +35 -0
  34. package/artifacts/schema/collection-record-history-response.schema.json +389 -0
  35. package/artifacts/schema/collection-record-list-query.schema.json +67 -0
  36. package/artifacts/schema/collection-record-list-response.schema.json +212 -0
  37. package/artifacts/schema/collection-record-restore-request.schema.json +14 -0
  38. package/artifacts/schema/collection-record-write.schema.json +31 -0
  39. package/artifacts/schema/collection-record.schema.json +180 -0
  40. package/artifacts/schema/collection-revision.schema.json +295 -0
  41. package/artifacts/schema/collection-subscribe-error.schema.json +31 -0
  42. package/artifacts/schema/collection-subscribe.schema.json +48 -0
  43. package/artifacts/schema/collection-subscribed.schema.json +22 -0
  44. package/artifacts/schema/collection-summary.schema.json +92 -0
  45. package/artifacts/schema/collection-unsubscribe.schema.json +22 -0
  46. package/artifacts/schema/collections-access-change.schema.json +34 -0
  47. package/artifacts/schema/collections-document.schema.json +732 -0
  48. package/artifacts/schema/collections-draft-response.schema.json +845 -0
  49. package/artifacts/schema/collections-effect.schema.json +384 -0
  50. package/artifacts/schema/collections-issue.schema.json +36 -0
  51. package/artifacts/schema/collections-publish-request.schema.json +18 -0
  52. package/artifacts/schema/collections-publish-response.schema.json +450 -0
  53. package/artifacts/schema/collections-purge-preview.schema.json +60 -0
  54. package/artifacts/schema/collections-purge-request.schema.json +27 -0
  55. package/artifacts/schema/collections-purge-response.schema.json +30 -0
  56. package/artifacts/schema/collections-restore-preview-query.schema.json +20 -0
  57. package/artifacts/schema/collections-restore-preview.schema.json +581 -0
  58. package/artifacts/schema/collections-restore-request.schema.json +27 -0
  59. package/artifacts/schema/collections-restore-response.schema.json +455 -0
  60. package/artifacts/schema/collections-schema-preview.schema.json +519 -0
  61. package/artifacts/schema/collections-schema-published.schema.json +22 -0
  62. package/artifacts/schema/collections-version-response.schema.json +869 -0
  63. package/artifacts/schema/collections-version-summary.schema.json +139 -0
  64. package/artifacts/schema/collections-versions-response.schema.json +167 -0
  65. package/artifacts/schema/config-draft-response.schema.json +359 -5
  66. package/artifacts/schema/config-version-response.schema.json +359 -5
  67. package/artifacts/schema/confirmation-required-details.schema.json +13 -0
  68. package/artifacts/schema/create-app-invitation-request.schema.json +4 -4
  69. package/artifacts/schema/create-app-user-request.schema.json +4 -4
  70. package/artifacts/schema/create-org-role-request.schema.json +33 -0
  71. package/artifacts/schema/dangling-reference.schema.json +130 -0
  72. package/artifacts/schema/datapoint-config.schema.json +35 -0
  73. package/artifacts/schema/datapoint-list-response.schema.json +2 -2
  74. package/artifacts/schema/effective-capability.schema.json +104 -0
  75. package/artifacts/schema/effective-rights-query.schema.json +19 -0
  76. package/artifacts/schema/effective-rights-response.schema.json +396 -0
  77. package/artifacts/schema/effective-robot-rights.schema.json +266 -0
  78. package/artifacts/schema/invoke-or-service-response.schema.json +1 -1
  79. package/artifacts/schema/invoke-response.schema.json +1 -1
  80. package/artifacts/schema/journal-intent-v2-body.schema.json +74 -0
  81. package/artifacts/schema/journal-intent-v2.schema.json +84 -0
  82. package/artifacts/schema/journal-replay-receipt-body.schema.json +1 -0
  83. package/artifacts/schema/journal-replay-receipt.schema.json +1 -0
  84. package/artifacts/schema/mcp-robot-datasheet.schema.json +2 -2
  85. package/artifacts/schema/org-plan.schema.json +29 -1
  86. package/artifacts/schema/org-quota-usage-counts.schema.json +18 -0
  87. package/artifacts/schema/org-quota-usage.schema.json +47 -1
  88. package/artifacts/schema/org-quotas.schema.json +29 -1
  89. package/artifacts/schema/org-role-list-response.schema.json +206 -0
  90. package/artifacts/schema/org-role.schema.json +59 -0
  91. package/artifacts/schema/patch-app-user-request.schema.json +4 -4
  92. package/artifacts/schema/patch-org-role-request.schema.json +38 -0
  93. package/artifacts/schema/plan-catalogue-entry.schema.json +29 -1
  94. package/artifacts/schema/plan-change-decision-status-response.schema.json +29 -1
  95. package/artifacts/schema/plan-limit-details.schema.json +3 -1
  96. package/artifacts/schema/plan-limits.schema.json +29 -1
  97. package/artifacts/schema/plan-overrides.schema.json +26 -0
  98. package/artifacts/schema/publish-config-response.schema.json +48 -1
  99. package/artifacts/schema/publisher-config.schema.json +35 -0
  100. package/artifacts/schema/put-collections-draft-request.schema.json +16 -0
  101. package/artifacts/schema/put-role-defaults-request.schema.json +127 -0
  102. package/artifacts/schema/record-changed-details.schema.json +16 -0
  103. package/artifacts/schema/record-referenced-details.schema.json +35 -0
  104. package/artifacts/schema/reference-invalid-details.schema.json +25 -0
  105. package/artifacts/schema/reference-place.schema.json +112 -0
  106. package/artifacts/schema/rename-slug-response.schema.json +4 -3
  107. package/artifacts/schema/required-missing-details.schema.json +19 -0
  108. package/artifacts/schema/robot-config-doc.schema.json +359 -5
  109. package/artifacts/schema/robot-deletion-summary.schema.json +33 -1
  110. package/artifacts/schema/role-collection-rights.schema.json +82 -0
  111. package/artifacts/schema/role-cycle-details.schema.json +18 -0
  112. package/artifacts/schema/role-defaults-response.schema.json +59 -0
  113. package/artifacts/schema/role-rename-preview.schema.json +147 -0
  114. package/artifacts/schema/service-config.schema.json +35 -0
  115. package/artifacts/schema/slug-usage-response.schema.json +4 -3
  116. package/artifacts/schema/update-app-request.schema.json +0 -12
  117. package/dist/app-users.d.ts +11 -8
  118. package/dist/app-users.js +18 -10
  119. package/dist/apps.d.ts +258 -71
  120. package/dist/apps.js +215 -151
  121. package/dist/audit.d.ts +35 -5
  122. package/dist/audit.js +40 -2
  123. package/dist/billing.d.ts +10 -10
  124. package/dist/client-auth.d.ts +5 -2
  125. package/dist/client-auth.js +11 -3
  126. package/dist/client-robots.d.ts +1 -1
  127. package/dist/client-robots.js +1 -1
  128. package/dist/collections-issues.d.ts +67 -0
  129. package/dist/collections-issues.js +340 -0
  130. package/dist/collections-records.d.ts +562 -0
  131. package/dist/collections-records.js +525 -0
  132. package/dist/collections-rights.d.ts +17 -0
  133. package/dist/collections-rights.js +41 -0
  134. package/dist/collections-schema.d.ts +1064 -0
  135. package/dist/collections-schema.js +386 -0
  136. package/dist/collections-templates.d.ts +55 -0
  137. package/dist/collections-templates.js +137 -0
  138. package/dist/collections-transfer.d.ts +101 -0
  139. package/dist/collections-transfer.js +206 -0
  140. package/dist/collections-values.d.ts +67 -0
  141. package/dist/collections-values.js +284 -0
  142. package/dist/collections.d.ts +568 -0
  143. package/dist/collections.js +332 -0
  144. package/dist/common.d.ts +1 -1
  145. package/dist/common.js +1 -1
  146. package/dist/config-issues.d.ts +1 -1
  147. package/dist/config-issues.js +1 -1
  148. package/dist/config.d.ts +78 -12
  149. package/dist/config.js +109 -15
  150. package/dist/errors.d.ts +63 -5
  151. package/dist/errors.js +152 -24
  152. package/dist/index.d.ts +40 -14
  153. package/dist/index.js +27 -7
  154. package/dist/journal-intents.d.ts +30 -0
  155. package/dist/journal-intents.js +3 -0
  156. package/dist/legal-acceptances.d.ts +2 -2
  157. package/dist/mcp.d.ts +5 -37
  158. package/dist/mcp.js +4 -14
  159. package/dist/org-roles.d.ts +186 -0
  160. package/dist/org-roles.js +199 -0
  161. package/dist/plans.d.ts +25 -7
  162. package/dist/plans.js +21 -1
  163. package/dist/protocol.d.ts +19 -1
  164. package/dist/realtime.d.ts +172 -3
  165. package/dist/realtime.js +164 -1
  166. package/dist/rest.d.ts +104 -53
  167. package/dist/rest.js +79 -55
  168. package/dist/rights.d.ts +197 -0
  169. package/dist/rights.js +396 -0
  170. package/dist/routes.d.ts +1 -1
  171. package/dist/routes.js +675 -150
  172. package/package.json +1 -1
  173. package/artifacts/schema/mcp-role-preview-response.schema.json +0 -134
  174. package/artifacts/schema/put-robot-details-request.schema.json +0 -41
  175. package/artifacts/schema/put-robot-details-response.schema.json +0 -43
  176. package/artifacts/schema/robot-details-doc.schema.json +0 -33
  177. package/artifacts/schema/role-delete-query.schema.json +0 -13
  178. package/artifacts/schema/role-in-use-details.schema.json +0 -28
  179. package/artifacts/schema/role-list-response.schema.json +0 -48
  180. package/artifacts/schema/role-permissions.schema.json +0 -61
  181. package/artifacts/schema/role-rename-request.schema.json +0 -16
  182. package/artifacts/schema/role.schema.json +0 -35
@@ -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/common.d.ts CHANGED
@@ -47,7 +47,7 @@ export declare const SLUG_RULE = "A name is lower-case: it starts with a letter,
47
47
  *
48
48
  * Names are stable and decoupled from ROS names — renaming a
49
49
  * topic on the robot must never break a client app. The reverse also holds
50
- * and costs more: changing a name breaks every client, role grant and MCP
50
+ * and costs more: changing a name breaks every client, role rule, app lock and MCP
51
51
  * tool name that uses it.
52
52
  */
53
53
  export declare const slug: z.ZodString;
package/dist/common.js CHANGED
@@ -47,7 +47,7 @@ export const SLUG_RULE = 'A name is lower-case: it starts with a letter, continu
47
47
  *
48
48
  * Names are stable and decoupled from ROS names — renaming a
49
49
  * topic on the robot must never break a client app. The reverse also holds
50
- * and costs more: changing a name breaks every client, role grant and MCP
50
+ * and costs more: changing a name breaks every client, role rule, app lock and MCP
51
51
  * tool name that uses it.
52
52
  */
53
53
  export const slug = z
@@ -36,7 +36,7 @@ export type SchemaIssue = z.core.$ZodIssue;
36
36
  export declare const DOCUMENT_ROOT_PATH = "(document)";
37
37
  /**
38
38
  * The five sections whose keys are slugs — one namespace across all of them,
39
- * which is what lets a role grant say `{robot, slug}` without naming a kind.
39
+ * which is what lets an app lock name `{robot, slug}` without naming a kind.
40
40
  * `messages:` is deliberately not among them: its names are their own
41
41
  * namespace.
42
42
  *
@@ -3,7 +3,7 @@
3
3
  export const DOCUMENT_ROOT_PATH = '(document)';
4
4
  /**
5
5
  * The five sections whose keys are slugs — one namespace across all of them,
6
- * which is what lets a role grant say `{robot, slug}` without naming a kind.
6
+ * which is what lets an app lock name `{robot, slug}` without naming a kind.
7
7
  * `messages:` is deliberately not among them: its names are their own
8
8
  * namespace.
9
9
  *
package/dist/config.d.ts CHANGED
@@ -133,14 +133,18 @@ 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 three are built-ins: the cloud or the bridge already publishes
137
- * something under them, so a configured entry would be a second producer for
138
- * one name. `history` is reserved for a different reason and is not a built-in
139
- * — nothing publishes it. `GET /api/robots/:id/jobs/history` is a **literal
140
- * sibling** of `GET /api/robots/:id/jobs/:slug`, so an action or service named
141
- * `history` would have a job route no caller could ever reach. Reserving the
142
- * name is the honest half of that: the alternative is a slug the format
143
- * accepts and one route silently cannot address.
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
+ * `GET /api/robots/:id/jobs/history` is a **literal sibling** of
144
+ * `GET /api/robots/:id/jobs/:slug`, so an action or service named `history`
145
+ * would have a job route no caller could ever reach. Reserving the name is the
146
+ * honest half of that: the alternative is a slug the format accepts and one
147
+ * route silently cannot address.
144
148
  *
145
149
  * **This constant is the only list.** The cloud builds its set from it and
146
150
  * emits `reserved_slug`; the rename path reads it for the target; an editor
@@ -157,7 +161,7 @@ export declare const parameterMap: z.ZodRecord<z.ZodString, z.ZodObject<{
157
161
  * ships those sentences to readers who have only the JSON Schema, and
158
162
  * "here" would have promised them a refusal this parse does not make.
159
163
  */
160
- export declare const RESERVED_SLUGS: readonly ["bridge_state", "robot_details", "history"];
164
+ export declare const RESERVED_SLUGS: readonly ["bridge_state", "history", "assets", "job_history"];
161
165
  /**
162
166
  * When an alert fires and when it is ok again. There is no discriminator:
163
167
  * `resolve_at` absent means equality, present means a threshold whose
@@ -305,6 +309,7 @@ export declare const datapointConfig: z.ZodObject<{
305
309
  name: z.ZodOptional<z.ZodString>;
306
310
  enabled: z.ZodOptional<z.ZodBoolean>;
307
311
  }, z.core.$strict>>>;
312
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
308
313
  }, z.core.$strict>;
309
314
  export type DatapointConfig = z.infer<typeof datapointConfig>;
310
315
  /**
@@ -418,6 +423,7 @@ export declare const actionConfig: z.ZodObject<{
418
423
  description: z.ZodOptional<z.ZodString>;
419
424
  }, z.core.$strict>>>;
420
425
  description: z.ZodOptional<z.ZodString>;
426
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
421
427
  }, z.core.$strict>;
422
428
  export type ActionConfig = z.infer<typeof actionConfig>;
423
429
  /** A ROS service call with validated parameters. */
@@ -451,6 +457,7 @@ export declare const serviceConfig: z.ZodObject<{
451
457
  description: z.ZodOptional<z.ZodString>;
452
458
  }, z.core.$strict>>>;
453
459
  description: z.ZodOptional<z.ZodString>;
460
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
454
461
  }, z.core.$strict>;
455
462
  export type ServiceConfig = z.infer<typeof serviceConfig>;
456
463
  /**
@@ -509,6 +516,7 @@ export declare const publisherConfig: z.ZodObject<{
509
516
  }, z.core.$strict>;
510
517
  quiet_timeout_ms: z.ZodNumber;
511
518
  description: z.ZodOptional<z.ZodString>;
519
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
512
520
  }, z.core.$strict>;
513
521
  export type PublisherConfig = z.infer<typeof publisherConfig>;
514
522
  /**
@@ -614,6 +622,7 @@ export declare const cameraConfig: z.ZodObject<{
614
622
  bitrate_kbps: z.ZodNumber;
615
623
  snapshot_interval_seconds: z.ZodNumber;
616
624
  description: z.ZodOptional<z.ZodString>;
625
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
617
626
  }, z.core.$strict>;
618
627
  export type CameraConfig = z.infer<typeof cameraConfig>;
619
628
  /**
@@ -648,9 +657,9 @@ export declare const LOW_BANDWIDTH_DEFAULTS: {
648
657
  */
649
658
  export declare const lowBandwidthSection: z.ZodObject<{
650
659
  mode: z.ZodOptional<z.ZodEnum<{
651
- off: "off";
652
660
  auto: "auto";
653
661
  on: "on";
662
+ off: "off";
654
663
  }>>;
655
664
  enter_lag_ms: z.ZodOptional<z.ZodNumber>;
656
665
  enter_after_s: z.ZodOptional<z.ZodNumber>;
@@ -670,6 +679,45 @@ export type LowBandwidthSection = z.infer<typeof lowBandwidthSection>;
670
679
  * numbers called version would be the likeliest confusion in the format.
671
680
  */
672
681
  export declare const FLEETLESS_FORMAT_VERSION = 1;
682
+ /**
683
+ * One rule of `access.rules`: a role for every entry whose ROS name fits.
684
+ *
685
+ * Rules are ordered and the first one that fits an entry decides, so a narrow
686
+ * rule goes above a wide one. An entry's own `role` is not consulted against
687
+ * rules at all — it wins outright — and a rule never touches `assets` or
688
+ * `job_history`, which are the robot's and say so under `access`.
689
+ */
690
+ export declare const accessRule: z.ZodObject<{
691
+ match: z.ZodString;
692
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
693
+ read: "read";
694
+ invoke: "invoke";
695
+ publish: "publish";
696
+ }>>>;
697
+ role: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
698
+ }, z.core.$strict>;
699
+ export type AccessRule = z.infer<typeof accessRule>;
700
+ /**
701
+ * The rights a robot's document sets beyond the `role` of single entries.
702
+ *
703
+ * `assets` and `job_history` are the robot's own capabilities and have no ROS
704
+ * name, so rules cannot reach them; they are named here, one role or a list
705
+ * each, and without them the organization's default applies.
706
+ */
707
+ export declare const accessSection: z.ZodObject<{
708
+ rules: z.ZodOptional<z.ZodArray<z.ZodObject<{
709
+ match: z.ZodString;
710
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
711
+ read: "read";
712
+ invoke: "invoke";
713
+ publish: "publish";
714
+ }>>>;
715
+ role: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
716
+ }, z.core.$strict>>>;
717
+ assets: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
718
+ job_history: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
719
+ }, z.core.$strict>;
720
+ export type AccessSection = z.infer<typeof accessSection>;
673
721
  /**
674
722
  * A whole robot configuration — everything configurable about one robot.
675
723
  *
@@ -678,7 +726,7 @@ export declare const FLEETLESS_FORMAT_VERSION = 1;
678
726
  * rule somebody has to write, and the name reads as the entry's heading.
679
727
  *
680
728
  * Slugs remain ONE namespace across all five exposure sections, which
681
- * is what lets a role grant say `{robot, slug}` without naming a kind. That
729
+ * is what lets an app lock name `{robot, slug}` without naming a kind. That
682
730
  * check spans sections and therefore lives in the cloud, not here.
683
731
  */
684
732
  export declare const robotConfigDoc: z.ZodObject<{
@@ -723,6 +771,7 @@ export declare const robotConfigDoc: z.ZodObject<{
723
771
  name: z.ZodOptional<z.ZodString>;
724
772
  enabled: z.ZodOptional<z.ZodBoolean>;
725
773
  }, z.core.$strict>>>;
774
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
726
775
  }, z.core.$strict>>>;
727
776
  actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
728
777
  ros_name: z.ZodString;
@@ -754,6 +803,7 @@ export declare const robotConfigDoc: z.ZodObject<{
754
803
  description: z.ZodOptional<z.ZodString>;
755
804
  }, z.core.$strict>>>;
756
805
  description: z.ZodOptional<z.ZodString>;
806
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
757
807
  }, z.core.$strict>>>;
758
808
  services: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
759
809
  ros_name: z.ZodString;
@@ -785,6 +835,7 @@ export declare const robotConfigDoc: z.ZodObject<{
785
835
  description: z.ZodOptional<z.ZodString>;
786
836
  }, z.core.$strict>>>;
787
837
  description: z.ZodOptional<z.ZodString>;
838
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
788
839
  }, z.core.$strict>>>;
789
840
  publishers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
790
841
  topic: z.ZodString;
@@ -821,6 +872,7 @@ export declare const robotConfigDoc: z.ZodObject<{
821
872
  }, z.core.$strict>;
822
873
  quiet_timeout_ms: z.ZodNumber;
823
874
  description: z.ZodOptional<z.ZodString>;
875
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
824
876
  }, z.core.$strict>>>;
825
877
  cameras: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
826
878
  source: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -855,12 +907,26 @@ export declare const robotConfigDoc: z.ZodObject<{
855
907
  bitrate_kbps: z.ZodNumber;
856
908
  snapshot_interval_seconds: z.ZodNumber;
857
909
  description: z.ZodOptional<z.ZodString>;
910
+ role: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
858
911
  }, z.core.$strict>>>;
912
+ access: z.ZodOptional<z.ZodObject<{
913
+ rules: z.ZodOptional<z.ZodArray<z.ZodObject<{
914
+ match: z.ZodString;
915
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
916
+ read: "read";
917
+ invoke: "invoke";
918
+ publish: "publish";
919
+ }>>>;
920
+ role: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
921
+ }, z.core.$strict>>>;
922
+ assets: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
923
+ job_history: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
924
+ }, z.core.$strict>>;
859
925
  low_bandwidth: z.ZodOptional<z.ZodObject<{
860
926
  mode: z.ZodOptional<z.ZodEnum<{
861
- off: "off";
862
927
  auto: "auto";
863
928
  on: "on";
929
+ off: "off";
864
930
  }>>;
865
931
  enter_lag_ms: z.ZodOptional<z.ZodNumber>;
866
932
  enter_after_s: z.ZodOptional<z.ZodNumber>;