@fleetless/contracts 13.3.0 → 14.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 (98) hide show
  1. package/CHANGELOG.md +141 -0
  2. package/artifacts/openapi.json +1983 -784
  3. package/artifacts/routes.json +224 -208
  4. package/artifacts/schema/access-warning.schema.json +51 -0
  5. package/artifacts/schema/action-config.schema.json +35 -0
  6. package/artifacts/schema/app-access-response.schema.json +136 -0
  7. package/artifacts/schema/app-access.schema.json +80 -0
  8. package/artifacts/schema/app-deletion-summary.schema.json +0 -7
  9. package/artifacts/schema/app-invitation-list-response.schema.json +13 -6
  10. package/artifacts/schema/app-invitation.schema.json +5 -5
  11. package/artifacts/schema/app-list-response.schema.json +6 -6
  12. package/artifacts/schema/app-lock.schema.json +30 -0
  13. package/artifacts/schema/app-user-list-response.schema.json +13 -6
  14. package/artifacts/schema/app-user.schema.json +13 -6
  15. package/artifacts/schema/app.schema.json +6 -6
  16. package/artifacts/schema/auth-ok.schema.json +20 -6
  17. package/artifacts/schema/camera-list-response.schema.json +1 -1
  18. package/artifacts/schema/client-identity.schema.json +21 -6
  19. package/artifacts/schema/cloud-config.schema.json +359 -5
  20. package/artifacts/schema/config-draft-response.schema.json +359 -5
  21. package/artifacts/schema/config-version-response.schema.json +359 -5
  22. package/artifacts/schema/create-app-invitation-request.schema.json +4 -4
  23. package/artifacts/schema/create-app-user-request.schema.json +4 -4
  24. package/artifacts/schema/create-org-role-request.schema.json +33 -0
  25. package/artifacts/schema/dangling-reference.schema.json +129 -0
  26. package/artifacts/schema/datapoint-config.schema.json +35 -0
  27. package/artifacts/schema/datapoint-list-response.schema.json +1 -1
  28. package/artifacts/schema/effective-capability.schema.json +104 -0
  29. package/artifacts/schema/effective-rights-query.schema.json +19 -0
  30. package/artifacts/schema/effective-rights-response.schema.json +310 -0
  31. package/artifacts/schema/effective-robot-rights.schema.json +266 -0
  32. package/artifacts/schema/invoke-or-service-response.schema.json +1 -1
  33. package/artifacts/schema/invoke-response.schema.json +1 -1
  34. package/artifacts/schema/journal-intent-v2-body.schema.json +74 -0
  35. package/artifacts/schema/journal-intent-v2.schema.json +84 -0
  36. package/artifacts/schema/journal-replay-receipt-body.schema.json +1 -0
  37. package/artifacts/schema/journal-replay-receipt.schema.json +1 -0
  38. package/artifacts/schema/mcp-robot-datasheet.schema.json +2 -2
  39. package/artifacts/schema/org-role-list-response.schema.json +205 -0
  40. package/artifacts/schema/org-role.schema.json +59 -0
  41. package/artifacts/schema/patch-app-user-request.schema.json +4 -4
  42. package/artifacts/schema/patch-org-role-request.schema.json +38 -0
  43. package/artifacts/schema/publish-config-response.schema.json +48 -1
  44. package/artifacts/schema/publisher-config.schema.json +35 -0
  45. package/artifacts/schema/put-role-defaults-request.schema.json +127 -0
  46. package/artifacts/schema/reference-place.schema.json +111 -0
  47. package/artifacts/schema/rename-slug-response.schema.json +4 -3
  48. package/artifacts/schema/robot-config-doc.schema.json +359 -5
  49. package/artifacts/schema/role-cycle-details.schema.json +18 -0
  50. package/artifacts/schema/role-defaults-response.schema.json +59 -0
  51. package/artifacts/schema/role-rename-preview.schema.json +146 -0
  52. package/artifacts/schema/service-config.schema.json +35 -0
  53. package/artifacts/schema/slug-usage-response.schema.json +4 -3
  54. package/artifacts/schema/update-app-request.schema.json +0 -12
  55. package/dist/app-users.d.ts +11 -8
  56. package/dist/app-users.js +18 -10
  57. package/dist/apps.d.ts +242 -71
  58. package/dist/apps.js +205 -151
  59. package/dist/audit.d.ts +3 -3
  60. package/dist/billing.d.ts +10 -10
  61. package/dist/client-auth.d.ts +5 -2
  62. package/dist/client-auth.js +11 -3
  63. package/dist/client-robots.d.ts +1 -1
  64. package/dist/client-robots.js +1 -1
  65. package/dist/common.d.ts +1 -1
  66. package/dist/common.js +1 -1
  67. package/dist/config-issues.d.ts +1 -1
  68. package/dist/config-issues.js +1 -1
  69. package/dist/config.d.ts +77 -11
  70. package/dist/config.js +108 -14
  71. package/dist/errors.d.ts +14 -5
  72. package/dist/errors.js +37 -24
  73. package/dist/index.d.ts +18 -8
  74. package/dist/index.js +14 -4
  75. package/dist/journal-intents.d.ts +30 -0
  76. package/dist/journal-intents.js +3 -0
  77. package/dist/legal-acceptances.d.ts +2 -2
  78. package/dist/mcp.d.ts +5 -37
  79. package/dist/mcp.js +4 -14
  80. package/dist/org-roles.d.ts +182 -0
  81. package/dist/org-roles.js +198 -0
  82. package/dist/plans.d.ts +6 -6
  83. package/dist/protocol.d.ts +19 -1
  84. package/dist/realtime.d.ts +6 -3
  85. package/dist/realtime.js +1 -1
  86. package/dist/rest.d.ts +76 -25
  87. package/dist/rest.js +41 -29
  88. package/dist/rights.d.ts +197 -0
  89. package/dist/rights.js +396 -0
  90. package/dist/routes.js +185 -134
  91. package/package.json +1 -1
  92. package/artifacts/schema/mcp-role-preview-response.schema.json +0 -134
  93. package/artifacts/schema/role-delete-query.schema.json +0 -13
  94. package/artifacts/schema/role-in-use-details.schema.json +0 -28
  95. package/artifacts/schema/role-list-response.schema.json +0 -48
  96. package/artifacts/schema/role-permissions.schema.json +0 -61
  97. package/artifacts/schema/role-rename-request.schema.json +0 -16
  98. package/artifacts/schema/role.schema.json +0 -35
package/dist/apps.js CHANGED
@@ -1,14 +1,19 @@
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 { ACCESS_KINDS, accessKind, roleKey } from './rights.js';
4
6
  /**
5
7
  * Apps, roles and rights.
6
8
  *
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.
9
+ * The rule that shapes all of this: **a role is the only thing that grants**.
10
+ * A robot assigned to an app is reachable through it, and what a user may use
11
+ * on that robot is decided by the user's role against what the robot's
12
+ * `fleetless.yaml` and the organization's defaults require; what the role does
13
+ * not grant does not exist for that user. An app can only take rights away: its
14
+ * locks win over every role and never grant anything. So there are two places
15
+ * to look when someone cannot see something, the requirement and the lock, and
16
+ * no third.
12
17
  */
13
18
  /**
14
19
  * The app identifier a client sends at login. Same rule as a service slug:
@@ -35,38 +40,26 @@ export const app = z.object({
35
40
  }),
36
41
  /** Robots are referenced individually; tags never grant rights. */
37
42
  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.',
43
+ 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
44
  }),
40
45
  /**
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.
46
+ * **The app's default role, by key.** An app user created, invited or
47
+ * self-registered without an explicit role gets this one, so the field decides
48
+ * access on those paths rather than pre-filling a form.
58
49
  *
59
50
  * `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.
51
+ * one*, the normal state of an app until somebody picks a default. A create or
52
+ * invite that names no role against such an app is refused rather than
53
+ * producing a user with no role. An invitation resolves the role when it is
54
+ * issued, so a later change here never re-aims one already sent.
64
55
  *
65
- * The role must belong to **this** app; the schema sees a uuid and cannot
66
- * check that, so `PATCH /api/apps/:id` does.
56
+ * The key is read as it is stored. It need not name a role: a role deleted
57
+ * since leaves the key behind, which grants nothing and shows up as a warning
58
+ * of the app's access. The field is written by `PUT /api/apps/:id/access`,
59
+ * together with the locks, and by no other route.
67
60
  */
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.',
61
+ default_role: roleKey.nullable().meta({
62
+ 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
63
  }),
71
64
  created_at: z.iso.datetime().meta({
72
65
  description: 'When the app was created, as an ISO 8601 timestamp. `GET /api/apps` orders by this field.',
@@ -82,11 +75,14 @@ export const appListResponse = z.object({
82
75
  * What deleting an app would destroy — read before the irreversible click,
83
76
  * and carried again by the `app.deleted` audit event.
84
77
  *
85
- * **Six numbers, never a sum**, for the reason `robotDeletionSummary` states
78
+ * **Five numbers, never a sum**, for the reason `robotDeletionSummary` states
86
79
  * 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
80
+ * describe five unrelated magnitudes with one figure on the one screen whose
88
81
  * entire justification is naming what cannot be undone.
89
82
  *
83
+ * Roles are not here: they belong to the organization, so deleting an app
84
+ * deletes none of them. What the app locks goes with its settings.
85
+ *
90
86
  * Robots are not here because they do not go: they belong to the
91
87
  * organization, not to the app. The audit trail is not here either — a record
92
88
  * of what happened outlives the thing it happened to.
@@ -95,9 +91,6 @@ export const appDeletionSummary = z.object({
95
91
  user_count: z.number().int().nonnegative().meta({
96
92
  description: 'App users deleted with the app. They are the developer\'s own customers, not Fleetless users, and exist in no other app.',
97
93
  }),
98
- role_count: z.number().int().nonnegative().meta({
99
- description: 'Roles deleted with the app, each with its per-robot slug grants.',
100
- }),
101
94
  server_key_count: z.number().int().nonnegative().meta({
102
95
  description: 'Server keys deleted with the app. A client still holding one is refused at its next request.',
103
96
  }),
@@ -149,6 +142,11 @@ export const createAppRequest = z.object({
149
142
  * remains only for MCP. `group_id` named a group that owned the app; who may
150
143
  * log into an app is the app's own user list.
151
144
  *
145
+ * The id-based default role is absent too, and it does have a successor: the
146
+ * default role is part of the app's access, replaced together with its locks by
147
+ * `PUT /api/apps/:id/access` and read as `app.default_role`. A patch that still
148
+ * names the old field is refused rather than dropped.
149
+ *
152
150
  * The route keeps its own check as belt-and-braces; a schema and a handler
153
151
  * agreeing is not two policies, it is one policy stated where each half can
154
152
  * enforce it.
@@ -156,19 +154,6 @@ export const createAppRequest = z.object({
156
154
  export const updateAppRequest = z.object({
157
155
  name: z.string().min(1).max(120).optional(),
158
156
  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
157
  }).strict();
173
158
  /**
174
159
  * A server key carries full app rights for server-side code — never for
@@ -205,128 +190,197 @@ export const createServerKeyResponse = z.object({
205
190
  key: serverKeyToken,
206
191
  });
207
192
  /**
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.
193
+ * The most exposures one robot's datasheet lists, so the most slugs a lock on
194
+ * one robot can name. Exported for whoever grows a lock (a slug rename adds
195
+ * the new name beside the old one) and must know when there is no room left.
212
196
  */
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.',
197
+ export const MAX_LOCK_SLUGS = 2000;
198
+ /** The most robots one app can lock single exposures on; whole kinds go in `locked_kinds`. */
199
+ const MAX_APP_LOCKS = 1000;
200
+ /** A list names nothing twice. */
201
+ const namedOnce = (items) => new Set(items).size === items.length;
202
+ /**
203
+ * **What an app locks, and what it falls back on.** Roles decide who may use
204
+ * what; an app can only take rights away from them, never add any. A lock wins
205
+ * over every role and over the organization's defaults, and applies to the
206
+ * app's users and to its server keys alike.
207
+ *
208
+ * Two ways to lock: a whole kind of access on every robot the app reaches
209
+ * (`locked_kinds`), or single capabilities of single robots (`locked`). The
210
+ * robot-wide `assets` and `job_history` can only be locked as a kind.
211
+ */
212
+ export const appLock = z.object({
213
+ robot_id: z.uuid().meta({
214
+ description: 'The robot whose capabilities are locked for this app.',
216
215
  }),
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`.',
216
+ slugs: z.array(slug).min(1).max(MAX_LOCK_SLUGS).refine(namedOnce, { message: 'Name each slug once.' }).meta({
217
+ uniqueItems: true,
218
+ 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
219
  }),
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`.',
220
+ }).strict();
221
+ /** The three fields `appAccess` and `appAccessResponse` share. */
222
+ const appAccessFields = {
223
+ default_role: roleKey.nullable().meta({
224
+ 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, ' +
225
+ '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
226
  }),
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.',
227
+ locked_kinds: z.array(accessKind).max(ACCESS_KINDS.length).refine(namedOnce, { message: 'Name each kind once.' }).meta({
228
+ uniqueItems: true,
229
+ description: 'Kinds of access locked for every user and server key of the app, on every robot it reaches: `read`, `invoke`, `publish`, `assets` or ' +
230
+ '`job_history`, each at most once. The only way to lock `assets` or `job_history`, which belong to the robot as a whole.',
225
231
  }),
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.',
232
+ locked: z.array(appLock).max(MAX_APP_LOCKS)
233
+ .refine((locks) => namedOnce(locks.map((lock) => lock.robot_id)), { message: 'Give each robot one entry; list all of its slugs in it.' })
234
+ .meta({
235
+ 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 ` +
236
+ 'away what a role would give.',
231
237
  }),
232
- });
238
+ };
233
239
  /**
234
- * The body of `PATCH /api/apps/:id/roles/:roleId`: the role's new name.
240
+ * **Which state of the access a write was composed from.** A fingerprint of
241
+ * the stored access that changes whenever the stored access does, whoever
242
+ * changed it: another developer's write, but also a slug rename, which adds the
243
+ * new name to every lock that lists the old one, and a robot detached from the
244
+ * app, which drops its lock. Opaque: compare it, do not compute it.
235
245
  *
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`.
246
+ * It is what keeps a full replacement from silently undoing a lock that
247
+ * landed after the caller read the access.
238
248
  */
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();
249
+ const appAccessRevision = z.string().regex(/^[0-9a-f]{64}$/).meta({
250
+ description: 'A fingerprint of the stored access, 64 lower-case hexadecimal characters. It changes whenever the stored access changes, by whichever route ' +
251
+ '(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.',
252
+ });
244
253
  /**
245
- * The query of `DELETE /api/apps/:id/roles/:roleId`.
254
+ * `PUT /api/apps/:id/access`: the whole access of one app, **replaced**. Every
255
+ * field is named on every write, so the body is exactly what the app has
256
+ * afterwards; strict, so a field this route does not take is refused rather
257
+ * than dropped.
246
258
  *
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.
259
+ * `revision` is the one field that is not part of the access: it says which
260
+ * state this body was composed from. A caller that read before it wrote sends
261
+ * it back, and a write composed from a stale read is refused instead of
262
+ * lifting a lock that landed in between.
252
263
  */
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`.',
264
+ export const appAccess = z.object({
265
+ ...appAccessFields,
266
+ revision: appAccessRevision.optional().meta({
267
+ 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 ' +
268
+ 'access has changed since, the write is refused with `409 target_state_conflict` naming `revision` (rule `stale`) and nothing is written; read ' +
269
+ 'the access again and compose the body anew. Left out, the body replaces whatever is stored: the last writer wins.',
256
270
  }),
257
271
  }).strict();
258
272
  /**
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.
273
+ * Something in an app's access that grants or locks nothing as written. Never
274
+ * a refusal: the access is stored as sent, and these say what is out of step.
263
275
  */
264
- export const roleInUseDetails = z.object({
265
- users: z.number().int().nonnegative().meta({
266
- description: 'App users whose role this is.',
276
+ export const accessWarning = z.object({
277
+ code: z.enum(['unknown_default_role', 'unknown_lock_slug', 'lock_robot_not_attached']).meta({
278
+ 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 ' +
279
+ 'published exposure for. `lock_robot_not_attached`: a lock names a robot that is not attached to the app.',
267
280
  }),
268
- invitations: z.number().int().nonnegative().meta({
269
- description: 'Pending invitations that would grant this role when accepted.',
281
+ message: z.string().min(1).meta({
282
+ description: 'A sentence a person can read, naming the key, robot or slug.',
270
283
  }),
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`.',
284
+ robot_id: z.uuid().nullable().meta({
285
+ description: 'The robot a lock warning is about; `null` for `unknown_default_role`.',
273
286
  }),
274
- }).strict();
287
+ slug: z.string().nullable().meta({
288
+ description: 'The slug an `unknown_lock_slug` warning is about; `null` for the other warnings.',
289
+ }),
290
+ });
291
+ /** What `GET` and `PUT /api/apps/:id/access` answer: the access as it stands, its revision, and what is out of step in it. */
292
+ export const appAccessResponse = z.object({
293
+ ...appAccessFields,
294
+ revision: appAccessRevision.meta({
295
+ 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.',
296
+ }),
297
+ warnings: z.array(accessWarning).meta({
298
+ description: 'What the access names that does not exist as written. Empty when nothing is out of step.',
299
+ }),
300
+ });
275
301
  /**
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.
302
+ * `GET /api/apps/:id/effective-rights`: look at the app as one role sees it,
303
+ * or as one app user does. Exactly one of the two.
304
+ *
305
+ * The cross-field rule is a `.refine()`, which JSON Schema cannot express, so
306
+ * `effective-rights-query.schema.json` describes two independent optional
307
+ * parameters; the cloud is the only place both-or-neither is refused.
280
308
  */
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(),
309
+ export const effectiveRightsQuery = z.object({
310
+ role: roleKey.optional().meta({
311
+ 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.',
312
+ }),
313
+ user: z.uuid().optional().meta({
314
+ description: 'An app user of this app, to look at the app as that user\'s role. A user of another app answers `404`.',
315
+ }),
316
+ }).strict().refine((query) => (query.role === undefined) !== (query.user === undefined), {
317
+ message: 'Name exactly one of role and user.',
318
+ });
319
+ /** One capability of one robot as a role sees it: granted or not, and why. */
320
+ export const effectiveCapability = z.object({
321
+ name: slug.meta({
322
+ description: 'The exposure\'s slug, or `assets` or `job_history` for the capabilities that belong to the robot as a whole.',
323
+ }),
324
+ kind: accessKind.meta({
325
+ description: 'The kind of access the capability needs.',
326
+ }),
327
+ granted: z.boolean().meta({
328
+ description: 'Whether the role may use it: its requirement is met and the app has not locked it.',
329
+ }),
330
+ requirement: z.array(z.string()).meta({
331
+ 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.',
332
+ }),
333
+ source: z.enum(['entry', 'rule', 'robot', 'org_default']).meta({
334
+ 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 ' +
335
+ '`access.assets` or `access.job_history`, and `org_default` the organization\'s default for the kind.',
336
+ }),
337
+ rule_index: z.number().int().nonnegative().nullable().meta({
338
+ description: 'For `rule`, the position of the deciding rule in `access.rules`, counted from zero; `null` otherwise.',
339
+ }),
340
+ rule_match: z.string().nullable().meta({
341
+ description: 'For `rule`, that rule\'s `match` glob; `null` otherwise.',
342
+ }),
343
+ satisfied_by: z.string().nullable().meta({
344
+ description: 'The key from `requirement` that the role holds through inheritance. `null` when the role is named in the requirement itself, and when it ' +
345
+ 'does not meet the requirement at all. Independent of locks.',
346
+ }),
347
+ locked: z.boolean().meta({
348
+ description: 'Whether the app locks this capability, as a kind or as a single lock. A lock wins over the requirement.',
349
+ }),
350
+ unknown_roles: z.array(z.string()).meta({
351
+ description: 'Keys in the requirement that name no role of the organization. They grant nothing.',
352
+ }),
353
+ });
354
+ /** One attached robot as a role sees it. */
355
+ export const effectiveRobotRights = z.object({
356
+ robot_id: z.uuid().meta({ description: 'The robot, one that is attached to the app.' }),
357
+ robot_name: z.string().min(1).max(200).meta({ description: 'The robot\'s name.' }),
358
+ published_version: z.number().int().positive().nullable().meta({
359
+ description: 'The version of the robot\'s published `fleetless.yaml` that the answer was computed from; `null` when nothing is published.',
360
+ }),
361
+ reachable: z.boolean().meta({
362
+ 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`, ' +
363
+ '`robots.describe` answers `not_found` for the robot and `robots.list` leaves it out; `capabilities` says why, and `datasheet` is the empty one.',
364
+ }),
365
+ capabilities: z.array(effectiveCapability).meta({
366
+ description: 'Every capability of the published configuration, and `assets` and `job_history`, each granted or not.',
367
+ }),
368
+ datasheet: mcpRobotDatasheet.meta({
369
+ description: 'The datasheet an MCP session of this role would get for the robot.',
370
+ }),
371
+ });
372
+ /** What `GET /api/apps/:id/effective-rights` answers. */
373
+ export const effectiveRightsResponse = z.object({
374
+ role: z.string().nullable().meta({
375
+ 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.',
376
+ }),
377
+ role_known: z.boolean().meta({
378
+ description: 'Whether the key names a role of the organization. `false` means every capability below is not granted.',
379
+ }),
380
+ user_id: z.uuid().nullable().meta({
381
+ 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.',
382
+ }),
383
+ robots: z.array(effectiveRobotRights).meta({
384
+ description: 'The robots attached to the app, each with what the role may use.',
331
385
  }),
332
386
  });
package/dist/audit.d.ts CHANGED
@@ -38,11 +38,11 @@ import { z } from 'zod';
38
38
  export declare const auditActor: z.ZodObject<{
39
39
  kind: z.ZodEnum<{
40
40
  developer: "developer";
41
+ fleetless: "fleetless";
41
42
  server_key: "server_key";
42
43
  bridge: "bridge";
43
44
  end_user: "end_user";
44
45
  app_user: "app_user";
45
- fleetless: "fleetless";
46
46
  }>;
47
47
  id: z.ZodUUID;
48
48
  label: z.ZodString;
@@ -56,11 +56,11 @@ export declare const auditEvent: z.ZodObject<{
56
56
  actor: z.ZodObject<{
57
57
  kind: z.ZodEnum<{
58
58
  developer: "developer";
59
+ fleetless: "fleetless";
59
60
  server_key: "server_key";
60
61
  bridge: "bridge";
61
62
  end_user: "end_user";
62
63
  app_user: "app_user";
63
- fleetless: "fleetless";
64
64
  }>;
65
65
  id: z.ZodUUID;
66
66
  label: z.ZodString;
@@ -95,11 +95,11 @@ export declare const auditListResponse: z.ZodObject<{
95
95
  actor: z.ZodObject<{
96
96
  kind: z.ZodEnum<{
97
97
  developer: "developer";
98
+ fleetless: "fleetless";
98
99
  server_key: "server_key";
99
100
  bridge: "bridge";
100
101
  end_user: "end_user";
101
102
  app_user: "app_user";
102
- fleetless: "fleetless";
103
103
  }>;
104
104
  id: z.ZodUUID;
105
105
  label: z.ZodString;
package/dist/billing.d.ts CHANGED
@@ -353,8 +353,8 @@ export declare const billingDecisionAmounts: z.ZodObject<{
353
353
  addon_lines: z.ZodArray<z.ZodObject<{
354
354
  addon: z.ZodEnum<{
355
355
  apps: "apps";
356
- seats: "seats";
357
356
  robots: "robots";
357
+ seats: "seats";
358
358
  app_user_packs: "app_user_packs";
359
359
  live_video_packs: "live_video_packs";
360
360
  }>;
@@ -839,8 +839,8 @@ export declare const billingDecisionSnapshot: z.ZodDiscriminatedUnion<[z.ZodObje
839
839
  addon_lines: z.ZodArray<z.ZodObject<{
840
840
  addon: z.ZodEnum<{
841
841
  apps: "apps";
842
- seats: "seats";
843
842
  robots: "robots";
843
+ seats: "seats";
844
844
  app_user_packs: "app_user_packs";
845
845
  live_video_packs: "live_video_packs";
846
846
  }>;
@@ -1369,8 +1369,8 @@ export declare const billingDecisionSnapshot: z.ZodDiscriminatedUnion<[z.ZodObje
1369
1369
  addon_lines: z.ZodArray<z.ZodObject<{
1370
1370
  addon: z.ZodEnum<{
1371
1371
  apps: "apps";
1372
- seats: "seats";
1373
1372
  robots: "robots";
1373
+ seats: "seats";
1374
1374
  app_user_packs: "app_user_packs";
1375
1375
  live_video_packs: "live_video_packs";
1376
1376
  }>;
@@ -1889,8 +1889,8 @@ export declare const billingDecisionSnapshot: z.ZodDiscriminatedUnion<[z.ZodObje
1889
1889
  addon_lines: z.ZodArray<z.ZodObject<{
1890
1890
  addon: z.ZodEnum<{
1891
1891
  apps: "apps";
1892
- seats: "seats";
1893
1892
  robots: "robots";
1893
+ seats: "seats";
1894
1894
  app_user_packs: "app_user_packs";
1895
1895
  live_video_packs: "live_video_packs";
1896
1896
  }>;
@@ -2420,8 +2420,8 @@ export declare const billingDecisionDisplayResponse: z.ZodObject<{
2420
2420
  addon_lines: z.ZodArray<z.ZodObject<{
2421
2421
  addon: z.ZodEnum<{
2422
2422
  apps: "apps";
2423
- seats: "seats";
2424
2423
  robots: "robots";
2424
+ seats: "seats";
2425
2425
  app_user_packs: "app_user_packs";
2426
2426
  live_video_packs: "live_video_packs";
2427
2427
  }>;
@@ -2950,8 +2950,8 @@ export declare const billingDecisionDisplayResponse: z.ZodObject<{
2950
2950
  addon_lines: z.ZodArray<z.ZodObject<{
2951
2951
  addon: z.ZodEnum<{
2952
2952
  apps: "apps";
2953
- seats: "seats";
2954
2953
  robots: "robots";
2954
+ seats: "seats";
2955
2955
  app_user_packs: "app_user_packs";
2956
2956
  live_video_packs: "live_video_packs";
2957
2957
  }>;
@@ -3470,8 +3470,8 @@ export declare const billingDecisionDisplayResponse: z.ZodObject<{
3470
3470
  addon_lines: z.ZodArray<z.ZodObject<{
3471
3471
  addon: z.ZodEnum<{
3472
3472
  apps: "apps";
3473
- seats: "seats";
3474
3473
  robots: "robots";
3474
+ seats: "seats";
3475
3475
  app_user_packs: "app_user_packs";
3476
3476
  live_video_packs: "live_video_packs";
3477
3477
  }>;
@@ -4005,8 +4005,8 @@ export declare const planChangePrepareResponse: z.ZodObject<{
4005
4005
  addon_lines: z.ZodArray<z.ZodObject<{
4006
4006
  addon: z.ZodEnum<{
4007
4007
  apps: "apps";
4008
- seats: "seats";
4009
4008
  robots: "robots";
4009
+ seats: "seats";
4010
4010
  app_user_packs: "app_user_packs";
4011
4011
  live_video_packs: "live_video_packs";
4012
4012
  }>;
@@ -4535,8 +4535,8 @@ export declare const planChangePrepareResponse: z.ZodObject<{
4535
4535
  addon_lines: z.ZodArray<z.ZodObject<{
4536
4536
  addon: z.ZodEnum<{
4537
4537
  apps: "apps";
4538
- seats: "seats";
4539
4538
  robots: "robots";
4539
+ seats: "seats";
4540
4540
  app_user_packs: "app_user_packs";
4541
4541
  live_video_packs: "live_video_packs";
4542
4542
  }>;
@@ -5055,8 +5055,8 @@ export declare const planChangePrepareResponse: z.ZodObject<{
5055
5055
  addon_lines: z.ZodArray<z.ZodObject<{
5056
5056
  addon: z.ZodEnum<{
5057
5057
  apps: "apps";
5058
- seats: "seats";
5059
5058
  robots: "robots";
5059
+ seats: "seats";
5060
5060
  app_user_packs: "app_user_packs";
5061
5061
  live_video_packs: "live_video_packs";
5062
5062
  }>;
@@ -499,7 +499,7 @@ export type McpConsentGrantListResponse = z.infer<typeof mcpConsentGrantListResp
499
499
  * client API and appears in the audit as the developer, and the console's own
500
500
  * live views subscribe on `/realtime` as one. A developer is **org-scoped, not
501
501
  * app-scoped** — they own the configuration of every robot in their org — so
502
- * `app_id` and `role_id` are null for them, and roles do not filter what they
502
+ * `app_id` and `role` are null for them, and roles do not filter what they
503
503
  * see. `kind` states this explicitly rather than leaving it to be inferred from
504
504
  * which id happens to be set.
505
505
  *
@@ -526,7 +526,10 @@ export declare const clientIdentity: z.ZodObject<{
526
526
  app_user_id: z.ZodNullable<z.ZodUUID>;
527
527
  server_key_id: z.ZodNullable<z.ZodUUID>;
528
528
  app_id: z.ZodNullable<z.ZodUUID>;
529
- role_id: z.ZodNullable<z.ZodUUID>;
529
+ role: z.ZodNullable<z.ZodObject<{
530
+ key: z.ZodString;
531
+ name: z.ZodString;
532
+ }, z.core.$strip>>;
530
533
  email: z.ZodNullable<z.ZodEmail>;
531
534
  two_factor_enabled: z.ZodNullable<z.ZodBoolean>;
532
535
  }, z.core.$strip>;