@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
package/dist/apps.js CHANGED
@@ -1,14 +1,20 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  import { z } from 'zod';
3
3
  import { slug } from './common.js';
4
+ import { mcpRobotDatasheet } from './mcp.js';
5
+ import { roleCollectionRights } from './collections-rights.js';
6
+ import { ACCESS_KINDS, accessKind, roleKey } from './rights.js';
4
7
  /**
5
8
  * Apps, roles and rights.
6
9
  *
7
- * The rule that shapes all of this: **roles are the only filter**. A robot
8
- * assigned to an app exposes every one of its services to that app; what a
9
- * role does not grant does not exist for that user. There is no second
10
- * visibility mechanism, and adding one later would create two places to look
11
- * when someone cannot see something.
10
+ * The rule that shapes all of this: **a role is the only thing that grants**.
11
+ * A robot assigned to an app is reachable through it, and what a user may use
12
+ * on that robot is decided by the user's role against what the robot's
13
+ * `fleetless.yaml` and the organization's defaults require; what the role does
14
+ * not grant does not exist for that user. An app can only take rights away: its
15
+ * locks win over every role and never grant anything. So there are two places
16
+ * to look when someone cannot see something, the requirement and the lock, and
17
+ * no third.
12
18
  */
13
19
  /**
14
20
  * The app identifier a client sends at login. Same rule as a service slug:
@@ -35,38 +41,26 @@ export const app = z.object({
35
41
  }),
36
42
  /** Robots are referenced individually; tags never grant rights. */
37
43
  robot_ids: z.array(z.uuid()).meta({
38
- description: 'The robots this app may reach, each referenced individually. Tags never grant rights, and a robot absent from this list is invisible to the app whatever a role grants.',
44
+ description: 'The robots this app may reach, each referenced individually. Tags never grant rights, and a robot absent from this list is invisible to the app. What a user of the app may use on an attached robot follows that robot\'s `fleetless.yaml` and the organization\'s defaults, less what the app locks.',
39
45
  }),
40
46
  /**
41
- * **The app's default role — and the two-space cut gave it a server-side
42
- * reader it did not have.**
43
- *
44
- * Through the assignment model this was a console prefill and nothing more:
45
- * `putAssignmentRequest` always carried the role explicitly, so no part of
46
- * the cloud authorized anybody with it. Assignments are gone. An app user is
47
- * created or invited **with** a role, and when the request omits one this is
48
- * the role they get — so the field now decides access on two write paths
49
- * (`createAppUserRequest`, `createAppInvitationRequest`) rather than
50
- * pre-filling a form.
51
- *
52
- * Worth saying: it changes what a wrong value costs.
53
- * A prefill somebody can see and correct became a default applied on the
54
- * server, and the obvious next question — should it be required instead? —
55
- * has a deliberate answer: no, because an invitation resolves the role at
56
- * *creation* time and stores it, so an outstanding invitation is never
57
- * re-aimed by a later change here.
47
+ * **The app's default role, by key.** An app user created, invited or
48
+ * self-registered without an explicit role gets this one, so the field decides
49
+ * access on those paths rather than pre-filling a form.
58
50
  *
59
51
  * `null` — and nullable rather than absent — means *this app has not chosen
60
- * one*. That is a normal state, not an unset field: every app is created
61
- * before its roles are configured. A create or invite that omits `role_id`
62
- * against an app in that state is a `validation_error`, not a user with no
63
- * role.
52
+ * one*, the normal state of an app until somebody picks a default. A create or
53
+ * invite that names no role against such an app is refused rather than
54
+ * producing a user with no role. An invitation resolves the role when it is
55
+ * issued, so a later change here never re-aims one already sent.
64
56
  *
65
- * The role must belong to **this** app; the schema sees a uuid and cannot
66
- * check that, so `PATCH /api/apps/:id` does.
57
+ * The key is read as it is stored. It need not name a role: a role deleted
58
+ * since leaves the key behind, which grants nothing and shows up as a warning
59
+ * of the app's access. The field is written by `PUT /api/apps/:id/access`,
60
+ * together with the locks, and by no other route.
67
61
  */
68
- default_role_id: z.uuid().nullable().meta({
69
- description: 'The role an app user gets when created or invited without an explicit one. `null` means this app has not chosen a default, the normal state of an app created before its roles were configured — and then a create or invite that omits `role_id` gets `validation_error`, not a user with no role. An invitation resolves the role when issued, so changing this never re-aims an outstanding one. The role must belong to this app, which `PATCH /api/apps/:id` checks and the schema cannot.',
62
+ default_role: roleKey.nullable().meta({
63
+ description: 'The role, by key, that an app user gets when created, invited or self-registered without an explicit one. `null` means this app has not chosen a default, the normal state of an app until someone picks one, and then a create or invite that names no role is refused. An invitation resolves the role when issued, so changing this never re-aims an outstanding one. The key is shown as stored and may name no role, which grants nothing; `GET /api/apps/:id/access` warns about it. It is set by `PUT /api/apps/:id/access`, not by `PATCH /api/apps/:id`.',
70
64
  }),
71
65
  created_at: z.iso.datetime().meta({
72
66
  description: 'When the app was created, as an ISO 8601 timestamp. `GET /api/apps` orders by this field.',
@@ -82,11 +76,14 @@ export const appListResponse = z.object({
82
76
  * What deleting an app would destroy — read before the irreversible click,
83
77
  * and carried again by the `app.deleted` audit event.
84
78
  *
85
- * **Six numbers, never a sum**, for the reason `robotDeletionSummary` states
79
+ * **Seven numbers, never a sum**, for the reason `robotDeletionSummary` states
86
80
  * at length: the console reads this aloud as one sentence, and a total would
87
- * describe six unrelated magnitudes with one figure on the one screen whose
81
+ * describe seven unrelated magnitudes with one figure on the one screen whose
88
82
  * entire justification is naming what cannot be undone.
89
83
  *
84
+ * Roles are not here: they belong to the organization, so deleting an app
85
+ * deletes none of them. What the app locks goes with its settings.
86
+ *
90
87
  * Robots are not here because they do not go: they belong to the
91
88
  * organization, not to the app. The audit trail is not here either — a record
92
89
  * of what happened outlives the thing it happened to.
@@ -95,9 +92,6 @@ export const appDeletionSummary = z.object({
95
92
  user_count: z.number().int().nonnegative().meta({
96
93
  description: 'App users deleted with the app. They are the developer\'s own customers, not Fleetless users, and exist in no other app.',
97
94
  }),
98
- role_count: z.number().int().nonnegative().meta({
99
- description: 'Roles deleted with the app, each with its per-robot slug grants.',
100
- }),
101
95
  server_key_count: z.number().int().nonnegative().meta({
102
96
  description: 'Server keys deleted with the app. A client still holding one is refused at its next request.',
103
97
  }),
@@ -110,6 +104,12 @@ export const appDeletionSummary = z.object({
110
104
  mail_template_count: z.number().int().nonnegative().meta({
111
105
  description: 'Custom mail templates, of at most three. A kind using the Fleetless default text is not counted — there is no row to lose.',
112
106
  }),
107
+ collection_count: z.number().int().nonnegative().meta({
108
+ description: 'Collections of the app\'s latest published schema. They go with the app, together with their records and history.',
109
+ }),
110
+ record_count: z.number().int().nonnegative().meta({
111
+ description: 'Records of the app\'s collections, deleted with the app.',
112
+ }),
113
113
  });
114
114
  /**
115
115
  * **`robot_ids` is accepted here, and `.strict()` catches everything else.**
@@ -149,6 +149,11 @@ export const createAppRequest = z.object({
149
149
  * remains only for MCP. `group_id` named a group that owned the app; who may
150
150
  * log into an app is the app's own user list.
151
151
  *
152
+ * The id-based default role is absent too, and it does have a successor: the
153
+ * default role is part of the app's access, replaced together with its locks by
154
+ * `PUT /api/apps/:id/access` and read as `app.default_role`. A patch that still
155
+ * names the old field is refused rather than dropped.
156
+ *
152
157
  * The route keeps its own check as belt-and-braces; a schema and a handler
153
158
  * agreeing is not two policies, it is one policy stated where each half can
154
159
  * enforce it.
@@ -156,19 +161,6 @@ export const createAppRequest = z.object({
156
161
  export const updateAppRequest = z.object({
157
162
  name: z.string().min(1).max(120).optional(),
158
163
  robot_ids: z.array(z.uuid()).optional(),
159
- /**
160
- * `app.default_role_id`'s write half — an app *setting*, which is where the
161
- * two-identity-space model
162
- * put the default role, so it belongs on the app's own PATCH and not on a
163
- * route of its own.
164
- *
165
- * **`.nullable().optional()`, and the two mean different things.** Absent
166
- * leaves the current default alone; an explicit `null` clears it. A field
167
- * that could only be set and never unset would make "we changed our mind"
168
- * unreachable through the API — the same silence `.strict()` above exists to
169
- * avoid, from the other direction.
170
- */
171
- default_role_id: z.uuid().nullable().optional(),
172
164
  }).strict();
173
165
  /**
174
166
  * A server key carries full app rights for server-side code — never for
@@ -205,128 +197,200 @@ export const createServerKeyResponse = z.object({
205
197
  key: serverKeyToken,
206
198
  });
207
199
  /**
208
- * Every app starts with `observe` and `operate`; custom roles are allowed
209
- * too. `builtin` marks the two starting roles — editable, renamable and
210
- * deletable like any other; the flag only tells the console where they came
211
- * from.
200
+ * The most exposures one robot's datasheet lists, so the most slugs a lock on
201
+ * one robot can name. Exported for whoever grows a lock (a slug rename adds
202
+ * the new name beside the old one) and must know when there is no room left.
212
203
  */
213
- export const role = z.object({
214
- id: z.uuid().meta({
215
- description: 'The role, and what an app user\'s `role_id` and an app\'s `default_role_id` refer to.',
204
+ export const MAX_LOCK_SLUGS = 2000;
205
+ /** The most robots one app can lock single exposures on; whole kinds go in `locked_kinds`. */
206
+ const MAX_APP_LOCKS = 1000;
207
+ /** A list names nothing twice. */
208
+ const namedOnce = (items) => new Set(items).size === items.length;
209
+ /**
210
+ * **What an app locks, and what it falls back on.** Roles decide who may use
211
+ * what; an app can only take rights away from them, never add any. A lock wins
212
+ * over every role and over the organization's defaults, and applies to the
213
+ * app's users and to its server keys alike.
214
+ *
215
+ * Two ways to lock: a whole kind of access on every robot the app reaches
216
+ * (`locked_kinds`), or single capabilities of single robots (`locked`). The
217
+ * robot-wide `assets` and `job_history` can only be locked as a kind.
218
+ */
219
+ export const appLock = z.object({
220
+ robot_id: z.uuid().meta({
221
+ description: 'The robot whose capabilities are locked for this app.',
216
222
  }),
217
- app_id: z.uuid().meta({
218
- description: 'The app this role belongs to. Roles are never shared between apps, so a role id from another app reads as `not_found`.',
223
+ slugs: z.array(slug).min(1).max(MAX_LOCK_SLUGS).refine(namedOnce, { message: 'Name each slug once.' }).meta({
224
+ uniqueItems: true,
225
+ description: `The slugs of that robot\'s exposures to lock, at least one and each named once, at most ${MAX_LOCK_SLUGS}. A slug the robot has no exposure for is accepted and warns, and locks nothing.`,
219
226
  }),
220
- name: z.string().min(1).max(60).meta({
221
- description: 'The role\'s name, shown wherever a user\'s access is chosen. The two roles every app starts with are named `observe` and `operate`.',
227
+ }).strict();
228
+ /** The three fields `appAccess` and `appAccessResponse` share. */
229
+ const appAccessFields = {
230
+ default_role: roleKey.nullable().meta({
231
+ description: 'The role, by key, that an app user gets when created, invited or self-registered without an explicit one. `null` means the app has none, ' +
232
+ 'and a create or invite that names no role is refused. A key that names no role is accepted and warns; it grants nothing.',
222
233
  }),
223
- builtin: z.boolean().meta({
224
- description: '`true` for the two roles every app starts with. Their **rights may be re-scoped** exactly like a custom role\'s, through `PUT /api/apps/:id/roles/:roleId/permissions` — the flag exists so the console can explain where they came from, not to protect them. Built-in roles can be renamed and deleted like any other; the flag only records that the cloud seeded them.',
234
+ locked_kinds: z.array(accessKind).max(ACCESS_KINDS.length).refine(namedOnce, { message: 'Name each kind once.' }).meta({
235
+ uniqueItems: true,
236
+ description: 'Kinds of access locked for every user and server key of the app, on every robot it reaches: `read`, `invoke`, `publish`, `assets` or ' +
237
+ '`job_history`, each at most once. The only way to lock `assets` or `job_history`, which belong to the robot as a whole.',
225
238
  }),
226
- });
227
- /** What `GET /api/apps/:id/roles` answers: the app's roles, builtin and custom alike. */
228
- export const roleListResponse = z.object({
229
- roles: z.array(role).meta({
230
- description: 'The app\'s roles, built-in and custom alike, ordered by `created_at` and then by `name`. The tie-break is not cosmetic — the two built-in roles are inserted in one statement and share a creation time to the microsecond, so never read a role by position.',
239
+ locked: z.array(appLock).max(MAX_APP_LOCKS)
240
+ .refine((locks) => namedOnce(locks.map((lock) => lock.robot_id)), { message: 'Give each robot one entry; list all of its slugs in it.' })
241
+ .meta({
242
+ description: `Single exposures locked on single robots, one entry per robot and at most ${MAX_APP_LOCKS}. A lock never grants anything: it only takes ` +
243
+ 'away what a role would give.',
231
244
  }),
232
- });
245
+ };
233
246
  /**
234
- * The body of `PATCH /api/apps/:id/roles/:roleId`: the role's new name.
247
+ * **Which state of the access a write was composed from.** A fingerprint of
248
+ * the stored access that changes whenever the stored access does, whoever
249
+ * changed it: another developer's write, but also a slug rename, which adds the
250
+ * new name to every lock that lists the old one, and a robot detached from the
251
+ * app, which drops its lock. Opaque: compare it, do not compute it.
235
252
  *
236
- * The same bounds as `role.name`, trimmed. Names are unique per app, compared
237
- * exactly as stored after trimming; a clash answers `409 role_name_taken`.
253
+ * It is what keeps a full replacement from silently undoing a lock that
254
+ * landed after the caller read the access.
238
255
  */
239
- export const roleRenameRequest = z.object({
240
- name: z.string().trim().min(1).max(60).meta({
241
- description: 'The new name, trimmed, 1 to 60 characters. Unique per app: another role of this app with the same name answers `409 role_name_taken`. The role\'s users keep it under its new name.',
242
- }),
243
- }).strict();
256
+ const appAccessRevision = z.string().regex(/^[0-9a-f]{64}$/).meta({
257
+ description: 'A fingerprint of the stored access, 64 lower-case hexadecimal characters. It changes whenever the stored access changes, by whichever route ' +
258
+ '(a write here, a slug rename that adds the new name to a lock, a robot detached from the app). Treat it as opaque: send back the one you read.',
259
+ });
244
260
  /**
245
- * The query of `DELETE /api/apps/:id/roles/:roleId`.
261
+ * `PUT /api/apps/:id/access`: the whole access of one app, **replaced**. Every
262
+ * field is named on every write, so the body is exactly what the app has
263
+ * afterwards; strict, so a field this route does not take is refused rather
264
+ * than dropped.
246
265
  *
247
- * `move_to` is what makes a held role deletable: every app user and pending
248
- * invitation holding the role moves to it, and so does the app's default when
249
- * it pointed at the role, in the same transaction as the delete. Without it a
250
- * held role answers `409 role_in_use` with `roleInUseDetails`, so a client
251
- * can ask where they should go instead of guessing.
266
+ * `revision` is the one field that is not part of the access: it says which
267
+ * state this body was composed from. A caller that read before it wrote sends
268
+ * it back, and a write composed from a stale read is refused instead of
269
+ * lifting a lock that landed in between.
252
270
  */
253
- export const roleDeleteQuery = z.object({
254
- move_to: z.uuid().optional().meta({
255
- description: 'Another role of the same app that takes over the deleted role\'s app users, pending invitations and, when it applies, the app\'s default. The role itself or a role of another app answers `400 validation_error`.',
271
+ export const appAccess = z.object({
272
+ ...appAccessFields,
273
+ revision: appAccessRevision.optional().meta({
274
+ description: 'The `revision` of the access this body was composed from, as `GET` or `PUT /api/apps/:id/access` answered it. When it is sent and the stored ' +
275
+ 'access has changed since, the write is refused with `409 target_state_conflict` naming `revision` (rule `stale`) and nothing is written; read ' +
276
+ 'the access again and compose the body anew. Left out, the body replaces whatever is stored: the last writer wins.',
256
277
  }),
257
278
  }).strict();
258
279
  /**
259
- * `details` of `409 role_in_use`: what still holds the role.
260
- *
261
- * All three are reported, zeros included, so a client renders one sentence
262
- * from one shape rather than inferring a missing key.
280
+ * Something in an app's access that grants or locks nothing as written. Never
281
+ * a refusal: the access is stored as sent, and these say what is out of step.
263
282
  */
264
- export const roleInUseDetails = z.object({
265
- users: z.number().int().nonnegative().meta({
266
- description: 'App users whose role this is.',
283
+ export const accessWarning = z.object({
284
+ code: z.enum(['unknown_default_role', 'unknown_lock_slug', 'lock_robot_not_attached']).meta({
285
+ description: '`unknown_default_role`: the default role names no role of the organization. `unknown_lock_slug`: a lock names a slug the robot has no ' +
286
+ 'published exposure for. `lock_robot_not_attached`: a lock names a robot that is not attached to the app.',
267
287
  }),
268
- invitations: z.number().int().nonnegative().meta({
269
- description: 'Pending invitations that would grant this role when accepted.',
288
+ message: z.string().min(1).meta({
289
+ description: 'A sentence a person can read, naming the key, robot or slug.',
270
290
  }),
271
- is_default: z.boolean().meta({
272
- description: '`true` when this is the app\'s `default_role_id`; the default then moves with the users to `move_to`.',
291
+ robot_id: z.uuid().nullable().meta({
292
+ description: 'The robot a lock warning is about; `null` for `unknown_default_role`.',
273
293
  }),
274
- }).strict();
294
+ slug: z.string().nullable().meta({
295
+ description: 'The slug an `unknown_lock_slug` warning is about; `null` for the other warnings.',
296
+ }),
297
+ });
298
+ /** What `GET` and `PUT /api/apps/:id/access` answer: the access as it stands, its revision, and what is out of step in it. */
299
+ export const appAccessResponse = z.object({
300
+ ...appAccessFields,
301
+ revision: appAccessRevision.meta({
302
+ description: 'The revision of the access as it stands. Send it back as `revision` of the next `PUT` to have that write refused when the access has changed in between.',
303
+ }),
304
+ warnings: z.array(accessWarning).meta({
305
+ description: 'What the access names that does not exist as written. Empty when nothing is out of step.',
306
+ }),
307
+ });
275
308
  /**
276
- * The rights matrix of one role: which slugs of which robot it may use, plus
277
- * the capabilities roles also govern. `capabilities`' own doc comment
278
- * below says which of them are enforced today and which is still a switch
279
- * that changes nothing.
309
+ * `GET /api/apps/:id/effective-rights`: look at the app as one role sees it,
310
+ * or as one app user does. Exactly one of the two.
311
+ *
312
+ * The cross-field rule is a `.refine()`, which JSON Schema cannot express, so
313
+ * `effective-rights-query.schema.json` describes two independent optional
314
+ * parameters; the cloud is the only place both-or-neither is refused.
280
315
  */
281
- export const rolePermissions = z.object({
282
- role_id: z.uuid(),
283
- /**
284
- * **A slug is unique per robot across ALL exposure kinds** — one namespace,
285
- * not one per kind — and the cloud's configuration validation enforces that
286
- * with a kind-agnostic collection pass. That is why this list carries slugs
287
- * and not (kind, slug) pairs: a grant means the same thing whichever kind the
288
- * slug turns out to name. `GET /api/robots/:id/exposures` is the companion
289
- * read that lists every grantable slug of a robot **with** its kind, so a
290
- * rights matrix can offer them.
291
- */
292
- grants: z.array(z.object({
293
- robot_id: z.uuid(),
294
- slugs: z.array(slug),
295
- })),
296
- /**
297
- * App-wide abilities a role grants, as opposed to per-slug grants above.
298
- *
299
- * **A capability here is a promise, and one of them is still not kept.** A
300
- * capability with no route, no SDK method and no realtime frame behind it can
301
- * be switched on while nothing changes, which is worse than its absence: the
302
- * developer believes they granted something. **This paragraph stays**
303
- * whatever the current tally is: it is the only place that says a switch may
304
- * change nothing, and it is how the next unkept capability gets caught.
305
- *
306
- * `assets` gates the asset store, which is not covered by `grants` because
307
- * **assets are not slugs** — and it is its own decision rather than a side
308
- * effect of reaching the robot, because a mesh set gives away the machine's
309
- * build.
310
- *
311
- * **`action_history` is kept.** It gates
312
- * `GET /api/robots/:id/jobs/history` — an end user whose role lacks it is
313
- * refused `403 capability_required`, naming the capability so the developer
314
- * knows which switch is off.
315
- *
316
- * **What granting it discloses.** A `jobRun` names the actor who invoked
317
- * it, and `jobActor.label` is an email — so an end user holding this
318
- * capability learns which *other* people have been driving that robot.
319
- * That is inherent in "may read the history" rather than an oversight, and
320
- * it is written down here because the switch lives in the console while its
321
- * consequence does not.
322
- *
323
- * **`presence` is still not implemented.** Nothing in the cloud, the SDK or
324
- * the realtime protocol consults it. It remains exactly what the first
325
- * paragraph describes.
326
- */
327
- capabilities: z.object({
328
- action_history: z.boolean(),
329
- presence: z.boolean(),
330
- assets: z.boolean(),
316
+ export const effectiveRightsQuery = z.object({
317
+ role: roleKey.optional().meta({
318
+ description: 'A role key to look at the app as. A key that names no role is not an error: the answer says `role_known: false` and grants nothing.',
319
+ }),
320
+ user: z.uuid().optional().meta({
321
+ description: 'An app user of this app, to look at the app as that user\'s role. A user of another app answers `404`.',
322
+ }),
323
+ }).strict().refine((query) => (query.role === undefined) !== (query.user === undefined), {
324
+ message: 'Name exactly one of role and user.',
325
+ });
326
+ /** One capability of one robot as a role sees it: granted or not, and why. */
327
+ export const effectiveCapability = z.object({
328
+ name: slug.meta({
329
+ description: 'The exposure\'s slug, or `assets` or `job_history` for the capabilities that belong to the robot as a whole.',
330
+ }),
331
+ kind: accessKind.meta({
332
+ description: 'The kind of access the capability needs.',
333
+ }),
334
+ granted: z.boolean().meta({
335
+ description: 'Whether the role may use it: its requirement is met and the app has not locked it.',
336
+ }),
337
+ requirement: z.array(z.string()).meta({
338
+ description: 'The role keys that qualify, from the entry, the rule or the default that decided. Holding one of them, or inheriting from one, is enough. Empty when nobody qualifies.',
339
+ }),
340
+ source: z.enum(['entry', 'rule', 'robot', 'org_default']).meta({
341
+ description: 'Where the requirement came from: `entry` is the entry\'s own `role`, `rule` the first matching rule of `access.rules`, `robot` the robot\'s ' +
342
+ '`access.assets` or `access.job_history`, and `org_default` the organization\'s default for the kind.',
343
+ }),
344
+ rule_index: z.number().int().nonnegative().nullable().meta({
345
+ description: 'For `rule`, the position of the deciding rule in `access.rules`, counted from zero; `null` otherwise.',
346
+ }),
347
+ rule_match: z.string().nullable().meta({
348
+ description: 'For `rule`, that rule\'s `match` glob; `null` otherwise.',
349
+ }),
350
+ satisfied_by: z.string().nullable().meta({
351
+ description: 'The key from `requirement` that the role holds through inheritance. `null` when the role is named in the requirement itself, and when it ' +
352
+ 'does not meet the requirement at all. Independent of locks.',
353
+ }),
354
+ locked: z.boolean().meta({
355
+ description: 'Whether the app locks this capability, as a kind or as a single lock. A lock wins over the requirement.',
356
+ }),
357
+ unknown_roles: z.array(z.string()).meta({
358
+ description: 'Keys in the requirement that name no role of the organization. They grant nothing.',
359
+ }),
360
+ });
361
+ /** One attached robot as a role sees it. */
362
+ export const effectiveRobotRights = z.object({
363
+ robot_id: z.uuid().meta({ description: 'The robot, one that is attached to the app.' }),
364
+ robot_name: z.string().min(1).max(200).meta({ description: 'The robot\'s name.' }),
365
+ published_version: z.number().int().positive().nullable().meta({
366
+ description: 'The version of the robot\'s published `fleetless.yaml` that the answer was computed from; `null` when nothing is published.',
367
+ }),
368
+ reachable: z.boolean().meta({
369
+ description: 'Whether a session of this role reaches the robot at all: at least one slug or one capability is granted once the locks are applied. When `false`, ' +
370
+ '`robots.describe` answers `not_found` for the robot and `robots.list` leaves it out; `capabilities` says why, and `datasheet` is the empty one.',
371
+ }),
372
+ capabilities: z.array(effectiveCapability).meta({
373
+ description: 'Every capability of the published configuration, and `assets` and `job_history`, each granted or not.',
374
+ }),
375
+ datasheet: mcpRobotDatasheet.meta({
376
+ description: 'The datasheet an MCP session of this role would get for the robot.',
377
+ }),
378
+ });
379
+ /** What `GET /api/apps/:id/effective-rights` answers. */
380
+ export const effectiveRightsResponse = z.object({
381
+ role: z.string().nullable().meta({
382
+ description: 'The role key the answer is for: the one asked about, or the app user\'s own. `null` when the app user holds none.',
383
+ }),
384
+ role_known: z.boolean().meta({
385
+ description: 'Whether the key names a role of the organization. `false` means every capability below is not granted.',
386
+ }),
387
+ user_id: z.uuid().nullable().meta({
388
+ description: 'The app user asked about; `null` when a role was asked about. A user who is not `active` reaches nothing, whatever role they hold: every capability below is not granted.',
389
+ }),
390
+ robots: z.array(effectiveRobotRights).meta({
391
+ description: 'The robots attached to the app, each with what the role may use.',
392
+ }),
393
+ collections: z.array(roleCollectionRights).meta({
394
+ description: 'What the role may do with the records of each collection of the app\'s latest published schema, in the schema\'s order. Empty when the app has no published schema. A role that is no role, and a user who is not `active`, are granted nothing in any row.',
331
395
  }),
332
396
  });
package/dist/audit.d.ts CHANGED
@@ -6,8 +6,9 @@ import { z } from 'zod';
6
6
  * its actor — never anonymous**. Reads are not audited.
7
7
  *
8
8
  * What is written: logins, failed logins, user management, configuration
9
- * publishes, bridge connect and disconnect. The log is filterable, exportable
10
- * as CSV, and kept for ninety days.
9
+ * publishes, bridge connect and disconnect, and the writes of app collections
10
+ * (`COLLECTION_AUDIT_ACTIONS`). The log is filterable, exportable as CSV, and
11
+ * kept for ninety days.
11
12
  */
12
13
  /**
13
14
  * The kinds of actor the platform knows. `label` is what a human reads in the
@@ -38,11 +39,11 @@ import { z } from 'zod';
38
39
  export declare const auditActor: z.ZodObject<{
39
40
  kind: z.ZodEnum<{
40
41
  developer: "developer";
42
+ fleetless: "fleetless";
41
43
  server_key: "server_key";
42
44
  bridge: "bridge";
43
45
  end_user: "end_user";
44
46
  app_user: "app_user";
45
- fleetless: "fleetless";
46
47
  }>;
47
48
  id: z.ZodUUID;
48
49
  label: z.ZodString;
@@ -56,11 +57,11 @@ export declare const auditEvent: z.ZodObject<{
56
57
  actor: z.ZodObject<{
57
58
  kind: z.ZodEnum<{
58
59
  developer: "developer";
60
+ fleetless: "fleetless";
59
61
  server_key: "server_key";
60
62
  bridge: "bridge";
61
63
  end_user: "end_user";
62
64
  app_user: "app_user";
63
- fleetless: "fleetless";
64
65
  }>;
65
66
  id: z.ZodUUID;
66
67
  label: z.ZodString;
@@ -95,11 +96,11 @@ export declare const auditListResponse: z.ZodObject<{
95
96
  actor: z.ZodObject<{
96
97
  kind: z.ZodEnum<{
97
98
  developer: "developer";
99
+ fleetless: "fleetless";
98
100
  server_key: "server_key";
99
101
  bridge: "bridge";
100
102
  end_user: "end_user";
101
103
  app_user: "app_user";
102
- fleetless: "fleetless";
103
104
  }>;
104
105
  id: z.ZodUUID;
105
106
  label: z.ZodString;
@@ -135,3 +136,32 @@ export declare const AUDIT_CSV_COLUMNS: readonly ["seq", "at", "actor_kind", "ac
135
136
  * as `ROBOT_ASSET_STORE_BYTES`.
136
137
  */
137
138
  export declare const AUDIT_RETENTION_DAYS = 90;
139
+ /**
140
+ * **The audit actions of app collections.** Each write request writes exactly
141
+ * one entry, whatever it changed: an import of 5,000 rows is one
142
+ * `collection_import.completed`, not 5,000 record entries. Reads and exports
143
+ * are not audited, here as everywhere in this log.
144
+ *
145
+ * - `collection_schema.published`: a schema version was published; the entry
146
+ * names the version and counts the effects it had on data. A role rename
147
+ * that rewrites the key in the `access` of an app's collections also appends
148
+ * a version, which changes no record: its entry has no effects and carries
149
+ * `role_rename` with the `from` and `to` keys, and its actor is the
150
+ * developer who renamed the role.
151
+ * - `collection_schema.restored`: an earlier version was restored; the entry
152
+ * names the version, says whether records were put back too and counts what
153
+ * changed.
154
+ * - `collection_record.created`, `.updated`, `.deleted`, `.restored`: one
155
+ * record write; the entry names the collection, the record and its robot.
156
+ * - `collection_import.completed`: an import was carried out; the entry names
157
+ * the collection and the mode and counts the records created, updated and
158
+ * deleted.
159
+ * - `collection_history.purged`: an organization owner removed history older
160
+ * than a date; the entry names the date, the collection or the whole app,
161
+ * and how many revisions went. The actor is the owner.
162
+ *
163
+ * The strings are stable: filter the log with `action` or with
164
+ * `action_prefix` (`collection_record.`).
165
+ */
166
+ export declare const COLLECTION_AUDIT_ACTIONS: readonly ["collection_schema.published", "collection_schema.restored", "collection_record.created", "collection_record.updated", "collection_record.deleted", "collection_record.restored", "collection_import.completed", "collection_history.purged"];
167
+ export type CollectionAuditAction = (typeof COLLECTION_AUDIT_ACTIONS)[number];
package/dist/audit.js CHANGED
@@ -7,8 +7,9 @@ import { wireSeqCursor, wireTimestampMs } from './common.js';
7
7
  * its actor — never anonymous**. Reads are not audited.
8
8
  *
9
9
  * What is written: logins, failed logins, user management, configuration
10
- * publishes, bridge connect and disconnect. The log is filterable, exportable
11
- * as CSV, and kept for ninety days.
10
+ * publishes, bridge connect and disconnect, and the writes of app collections
11
+ * (`COLLECTION_AUDIT_ACTIONS`). The log is filterable, exportable as CSV, and
12
+ * kept for ninety days.
12
13
  */
13
14
  /**
14
15
  * The kinds of actor the platform knows. `label` is what a human reads in the
@@ -226,3 +227,40 @@ export const AUDIT_CSV_COLUMNS = ['seq', 'at', 'actor_kind', 'actor_id', 'action
226
227
  * as `ROBOT_ASSET_STORE_BYTES`.
227
228
  */
228
229
  export const AUDIT_RETENTION_DAYS = 90;
230
+ /**
231
+ * **The audit actions of app collections.** Each write request writes exactly
232
+ * one entry, whatever it changed: an import of 5,000 rows is one
233
+ * `collection_import.completed`, not 5,000 record entries. Reads and exports
234
+ * are not audited, here as everywhere in this log.
235
+ *
236
+ * - `collection_schema.published`: a schema version was published; the entry
237
+ * names the version and counts the effects it had on data. A role rename
238
+ * that rewrites the key in the `access` of an app's collections also appends
239
+ * a version, which changes no record: its entry has no effects and carries
240
+ * `role_rename` with the `from` and `to` keys, and its actor is the
241
+ * developer who renamed the role.
242
+ * - `collection_schema.restored`: an earlier version was restored; the entry
243
+ * names the version, says whether records were put back too and counts what
244
+ * changed.
245
+ * - `collection_record.created`, `.updated`, `.deleted`, `.restored`: one
246
+ * record write; the entry names the collection, the record and its robot.
247
+ * - `collection_import.completed`: an import was carried out; the entry names
248
+ * the collection and the mode and counts the records created, updated and
249
+ * deleted.
250
+ * - `collection_history.purged`: an organization owner removed history older
251
+ * than a date; the entry names the date, the collection or the whole app,
252
+ * and how many revisions went. The actor is the owner.
253
+ *
254
+ * The strings are stable: filter the log with `action` or with
255
+ * `action_prefix` (`collection_record.`).
256
+ */
257
+ export const COLLECTION_AUDIT_ACTIONS = [
258
+ 'collection_schema.published',
259
+ 'collection_schema.restored',
260
+ 'collection_record.created',
261
+ 'collection_record.updated',
262
+ 'collection_record.deleted',
263
+ 'collection_record.restored',
264
+ 'collection_import.completed',
265
+ 'collection_history.purged',
266
+ ];