@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/routes.js CHANGED
@@ -1,23 +1,27 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- import { appListResponse, appDeletionSummary, createAppRequest, createServerKeyResponse, app as appSchema, role, roleListResponse, roleDeleteQuery, rolePermissions, roleRenameRequest, serverKeyListResponse, updateAppRequest, } from './apps.js';
2
+ import { appAccess, appAccessResponse, appListResponse, appDeletionSummary, createAppRequest, createServerKeyResponse, app as appSchema, effectiveRightsQuery, effectiveRightsResponse, serverKeyListResponse, updateAppRequest, } from './apps.js';
3
3
  import { alertListResponse, orgAlertsQuery, orgFiringAlertsResponse } from './alerts.js';
4
4
  import { asset, assetListResponse, assetsClearResponse, assetSyncRequest, assetSyncResponse, assetSyncStatus, missingAssetQuery } from './assets.js';
5
5
  import { auditListResponse, auditQuery } from './audit.js';
6
+ import { collectionDefinitionsResponse, collectionListResponse, collectionRecord, collectionRecordHistoryQuery, collectionRecordHistoryResponse, collectionRecordListQuery, collectionRecordGetQuery, collectionRecordListResponse, collectionRecordRestoreRequest, collectionRecordWrite, } from './collections-records.js';
7
+ import { collectionsDraftResponse, collectionsPublishRequest, collectionsPublishResponse, collectionsPurgePreview, collectionsPurgeRequest, collectionsPurgeResponse, collectionsRestorePreview, collectionsRestorePreviewQuery, collectionsRestoreRequest, collectionsRestoreResponse, collectionsSchemaPreview, collectionsVersionResponse, collectionsVersionsResponse, putCollectionsDraftRequest, } from './collections-schema.js';
8
+ import { collectionExportQuery, collectionImportPreview, collectionImportRequest, collectionImportResult } from './collections-transfer.js';
6
9
  import { feedbackRequest, feedbackResponse } from './feedback.js';
7
10
  import { CLIENT_OIDC_CALLBACK_PATH, clientAcceptInvitationRequest, clientIdentity, clientLoginCodeRequest, clientLoginCodeVerifyRequest, clientLoginRequest, clientLogoutRequest, clientMcpInteraction, clientMcpInteractionDecisionResponse, clientOidcCallbackQuery, clientOidcExchangeRequest, clientOidcStartQuery, clientPasswordResetConfirmRequest, clientPasswordResetRequest, clientProviderListQuery, clientProviderListResponse, clientRefreshRequest, clientRegisterRequest, clientResendVerificationRequest, clientSignInResult, clientTwoFactorDisableRequest, clientTwoFactorSetupConfirmRequest, clientTwoFactorSetupConfirmResponse, clientTwoFactorSetupRequest, clientTwoFactorVerifyRequest, clientVerifyEmailRequest, mcpConsentGrantListResponse, } from './client-auth.js';
8
11
  import { clientRobotListResponse } from './client-robots.js';
9
12
  import { appAuthConfig, appInvitation, appInvitationListResponse, appMailTemplate, appMailTemplateListResponse, appOidcProvider, appOidcProviderListResponse, appUser, appUserListResponse, createAppInvitationRequest, createAppOidcProviderRequest, createAppUserRequest, mailOutcome, mailTemplatePreviewRequest, mailTemplatePreviewResponse, patchAppOidcProviderRequest, patchAppUserRequest, putAppAuthLookRequest, putAppAuthMcpRequest, putAppAuthRegistrationRequest, putAppAuthSignInRequest, putAppAuthUrlsRequest, putAppMailTemplateRequest, } from './app-users.js';
13
+ import { createOrgRoleRequest, orgRole, orgRoleListResponse, patchOrgRoleRequest, putRoleDefaultsRequest, roleDefaultsResponse, } from './org-roles.js';
10
14
  import { controllerRegisterOrgResponse, controllerRegisterWrite } from './controller-register.js';
11
15
  import { acceptTeamInviteRequest, authMeResponse, createPasskeyRequest, createPasskeyResponse, createTeamInviteRequest, developerPasskey, developerTwoFactor, fleetlessUser, fleetlessUserListResponse, passwordChangeRequest, patchAuthMeRequest, patchFleetlessUserRequest, patchOrgRequest, patchOrgResponse, pendingTeamInviteListResponse, refreshRequest, sessionTokens, teamInvite, recoveryCodesResponse, renamePasskeyRequest, tierChangeRequest, totpConfirmRequest, totpConfirmResponse, twoFactorSetupResponse, waitlistRequest, webauthnOptionsResponse, } from './identity.js';
12
16
  import { jobRunListResponse, jobRunQuery, jobRunSummary, jobRunSummaryQuery } from './jobs.js';
13
17
  import { legalAcceptanceListQuery, legalAcceptanceListResponse } from './legal-acceptances.js';
14
18
  import { legalOfferListQuery, legalOfferListResponse, legalOfferDisplayRequest, legalOfferDisplayResponse, legalOfferDecisionRequest, legalOfferDecisionLookupQuery, legalOfferDecisionResult, } from './legal-offers.js';
15
- import { MCP_APP_PATHS, mcpRobotDatasheet, mcpRolePreviewResponse } from './mcp.js';
19
+ import { MCP_APP_PATHS, mcpRobotDatasheet } from './mcp.js';
16
20
  import { authorizationServerMetadata, dynamicClientRegistrationRequest, dynamicClientRegistrationResponse, oauthAuthorizeQuery, oauthRedirectResponse, oauthTokenRequest, oauthTokenResponse, protectedResourceMetadata, } from './oauth.js';
17
21
  import { adminPlanChangeRequest, orgPlan, planChangeRequest, planChangePrepareRequest, planChangeDecisionLookupQuery, planChangeDecisionStatusResponse } from './plans.js';
18
22
  import { supportRenewFailRequest, supportTokenRequest, supportTokenResponse } from './support.js';
19
23
  import { purchaseIntentLookupQuery, purchaseIntentConfirmRequest, billingDecisionDisplayRequest, billingDecisionDisplayResponse, planChangePrepareResponse, purchaseIntentResponse, invoicePayRequest, billingCancelRequest, billingChangeRequest, billingChangeResponse, billingDetailsUpdate, billingInvoicePdfQuery, billingDocumentDetail, billingDocumentFileQuery, billingDocumentList, billingView, chargePayRequest, checkoutRequest, checkoutResponse, checkoutStatus, paymentMethodChangeRequest, vatIdCheckRequest, vatIdCheckResponse, } from './billing.js';
20
- import { cameraListResponse, cancelRequest, recoverHeldJobRequest, recoverHeldJobResponse, configDraftResponse, configVersionResponse, configVersionsResponse, createRobotRequest, createRobotResponse, datapointListResponse, datapointValue, exposureListResponse, fetchTypesRequest, fetchTypesResponse, historyQuery, historyResponse, introspectionResponse, invokeOrServiceResponse, invokeRequest, jobResponse, liveSessionResponse, orgHealthQuery, orgLatencyQuery, orgLatencyResponse, orgQuotaUsage, orgUsageQuery, orgUsageResponse, patchRobotRequest, patchRobotResponse, publishConfigResponse, publishRequest, putConfigDraftRequest, putRobotDetailsRequest, putRobotDetailsResponse, robotTokenRotateResponse, jointStatePutRequest, jointStatePutResponse, releaseLiveQuery, renameSlugRequest, renameSlugResponse, robotDeleteQuery, resourceHealthListResponse, robotDeletionSummary, robotDetailResponse, robotJobsResponse, robotListResponse, slugUsageResponse, snapshotMetaResponse, typesResponse, } from './rest.js';
24
+ import { cameraListResponse, cancelRequest, recoverHeldJobRequest, recoverHeldJobResponse, configDraftResponse, configVersionResponse, configVersionsResponse, createRobotRequest, createRobotResponse, datapointListResponse, datapointValue, exposureListResponse, fetchTypesRequest, fetchTypesResponse, historyQuery, historyResponse, introspectionResponse, invokeOrServiceResponse, invokeRequest, jobResponse, liveSessionResponse, orgHealthQuery, orgLatencyQuery, orgLatencyResponse, orgQuotaUsage, orgUsageQuery, orgUsageResponse, patchRobotRequest, patchRobotResponse, publishConfigResponse, publishRequest, putConfigDraftRequest, robotTokenRotateResponse, jointStatePutRequest, jointStatePutResponse, releaseLiveQuery, renameSlugRequest, renameSlugResponse, robotDeleteQuery, resourceHealthListResponse, robotDeletionSummary, robotDetailResponse, robotJobsResponse, robotListResponse, slugUsageResponse, snapshotMetaResponse, typesResponse, } from './rest.js';
21
25
  export const ROUTE_SECTIONS = [
22
26
  { id: 'health', title: 'Health' },
23
27
  { id: 'developer-auth', title: 'Developer auth' },
@@ -26,6 +30,7 @@ export const ROUTE_SECTIONS = [
26
30
  { id: 'billing', title: 'Billing' },
27
31
  { id: 'users', title: 'Team' },
28
32
  { id: 'apps', title: 'Apps' },
33
+ { id: 'collections', title: 'App collections' },
29
34
  { id: 'robots', title: 'Robots' },
30
35
  { id: 'config', title: 'Configuration (draft/publish)' },
31
36
  { id: 'alerts', title: 'Alerts' },
@@ -130,13 +135,75 @@ const MOLLIE = ['payment_provider_unavailable'];
130
135
  * code in `ERROR_CODES` satisfies every one of them.
131
136
  *
132
137
  * It keeps `forbidden`, which `DEVELOPER_GUARD` no longer carries: this guard's
133
- * routes have live 403 producers — a slug the role does not grant
138
+ * routes have live 403 producers — a slug the caller's rights do not cover
134
139
  * (`routes/history.ts`), a capability the role does not carry
135
- * (`routes/commands.ts`), a camera or datapoint outside the grant
140
+ * (`routes/commands.ts`), a camera or datapoint outside the caller's rights
136
141
  * (`routes/cameras.ts`, `routes/robots.ts`). That divergence is the reason the
137
142
  * two lists were kept as separate constants while they still read alike.
138
143
  */
139
144
  const CLIENT_GUARD = ['unauthorized', 'token_expired', 'token_revoked', 'forbidden'];
145
+ /**
146
+ * **What the app collection routes share**, written once: the path parameters
147
+ * they describe the same way, the refusals every one of them can answer, and the
148
+ * two paragraphs that tell a reader who may do what.
149
+ */
150
+ const COLLECTIONS_APP = {
151
+ name: 'id',
152
+ description: "The app's uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`. A malformed id is `400 invalid_uuid`.",
153
+ };
154
+ const COLLECTIONS_VERSION = {
155
+ name: 'v',
156
+ description: 'The schema version number, as listed by `GET /api/apps/:id/collections/schema/versions`: a positive whole number of at most nine digits. Anything else is the same `404 not_found` as a version the app does not have.',
157
+ };
158
+ const COLLECTIONS_KEY = {
159
+ name: 'c',
160
+ description: "The collection's key, as listed by `GET /api/apps/:id/collections`. The records of a collection whose key is `schema` or `history` are reached the same way.",
161
+ };
162
+ const COLLECTIONS_KEY_CLIENT = {
163
+ name: 'c',
164
+ description: "The collection's key, as listed by `GET /api/client/collections`.",
165
+ };
166
+ const COLLECTIONS_RECORD = {
167
+ name: 'rid',
168
+ description: "The record's uuid: the `id` of a record that a create or a list returned. A malformed id is `400 invalid_uuid`.",
169
+ };
170
+ /** The guard's refusals, a malformed uuid, and an app (or record) that is not there. */
171
+ const COLLECTIONS_DEVELOPER = [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'];
172
+ /**
173
+ * The same for the client twins, which also name a collection and can be refused for a missing right. A route with a record in
174
+ * its path can answer a malformed id and a missing record; one with only a collection key (a list, a create, an import, an
175
+ * export) answers neither, because the app is the bearer's and a collection key is not an id.
176
+ */
177
+ const COLLECTIONS_CLIENT = [...CLIENT_GUARD, 'invalid_uuid', 'not_found', 'collection_not_found'];
178
+ const COLLECTIONS_CLIENT_COLLECTION = [...CLIENT_GUARD, 'collection_not_found'];
179
+ const COLLECTIONS_RIGHTS = "**Who may do what.** Developers and the app's server keys do everything with records. The schema, its versions and its restore are for " +
180
+ "developers only, and purging old history is for an organization owner alone. An app user's rights come from `access` in the published " +
181
+ "schema, per collection: `read`, `create`, `update` and `delete` each name roles, and `update` and `delete` can also say `{ all, own }`, " +
182
+ "where `own` compares `created_by` with the caller. A collection, or an action, that `access` does not mention is allowed to nobody. " +
183
+ "In a collection that belongs to robots a caller reaches only the records of robots the app has attached and the caller's role reaches. " +
184
+ "The history of a record is readable, and its revisions restorable, by whoever may update it; a deleted record is brought back with " +
185
+ "the right to create.";
186
+ const COLLECTIONS_UNKNOWN = "**`404 collection_not_found` or `403 forbidden`.** A caller who has none of `read`, `create`, `update` and `delete` on a collection is " +
187
+ "answered `404 collection_not_found`, exactly as for a key the schema does not have, so a collection they may not touch cannot be found " +
188
+ "out by asking. A caller who has some right on it, but not the one the request needs, is answered `403 forbidden`.";
189
+ const COLLECTIONS_PAGES = "**A page can be cut short.** A page of records ends at 4 MiB of stored record values (for the list of deleted records, of the revisions that " +
190
+ "deleted them), so it can hold fewer than `limit` records while more follow. It always holds at least one record when there is one, " +
191
+ "`next_cursor` continues after the last record it holds, and a list of ordinary size is never cut; only `next_cursor: null` says the list is at " +
192
+ "its end. `total` is not affected, and the records `expand` embeds are not counted.";
193
+ const COLLECTIONS_HISTORY_PAGES = "A page of revisions ends at 4 MiB of stored revisions, since the changes of a revision keep the old and the new value and a `delete` " +
194
+ "the whole record. It always holds at least one revision, `next_before_seq` names the last revision the page holds, and a history of ordinary " +
195
+ "size is never cut.";
196
+ const COLLECTIONS_RECORD_SIZE = "The values of a record may be 1,048,576 bytes as JSON; more is `400 validation_error` (field `values`, rule `record_too_large`), and so is a " +
197
+ "request body of more than 2 MiB, so a record at the cap is sent in a body a little over 1 MiB.";
198
+ const COLLECTIONS_IMPORT_LIMITS = "The request body is at most 21,048,576 bytes (twice the 10,000,000 characters of a file, since a file inside a JSON string can double in " +
199
+ "size on the way, plus 1 MiB); a larger one is `400 validation_error`, field `content`, rule `too_large`. A request without a bearer token is " +
200
+ "`401` before its body is read. An app runs one import at a time, preview or confirmation, and the cloud three at once; the next is " +
201
+ "`429 rate_limited` with `retry_after_ms: 5000`. A large file can take a while in each of its two requests. The cloud sets no " +
202
+ "request timeout of its own, so a reverse proxy in front of it must not cut these routes short.";
203
+ const COLLECTIONS_IMPORT_CELLS = "A blank cell is no value: the field's default on a new record, a cleared field on an existing one. A multiple `select` is a JSON list or " +
204
+ "comma-separated values, and a `json` field is JSON text. A column named after a system field is left out unless it is mapped, and the apostrophe " +
205
+ "that an export puts in front of a cell that looks like a formula is taken off.";
206
+ const COLLECTIONS_NOT_FOR_DEVELOPERS = "A developer's bearer is answered `403 forbidden` (\"Developers use /api/apps/:id/collections.\").";
140
207
  /**
141
208
  * **The steps of a developer sign-in, written once for both portal flows.**
142
209
  *
@@ -552,6 +619,84 @@ export const ROUTES = [
552
619
  notes: 'The authenticated org is the only target. Null contacts explicitly clear earlier values. ' +
553
620
  'The write is atomic and audited; billing data is never an implicit source. Support sessions cannot write.',
554
621
  },
622
+ {
623
+ method: 'GET', path: '/api/org/roles', section: 'org',
624
+ summary: "Lists the organization's roles with how much depends on each, and the keys that are written somewhere but are no role.",
625
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
626
+ params: [], query: null, request: null, response: orgRoleListResponse,
627
+ errors: [...DEVELOPER_GUARD], transport: 'http',
628
+ notes: 'Roles belong to the organization and are shared by all its apps; console members hold none and are never filtered by them. Each role ' +
629
+ 'carries the number of app users that hold it, of invitations that carry it, of apps that use it as their default and of places in ' +
630
+ 'documents that name it. `dangling` lists the keys that are written somewhere and are no role, each with every place that writes it, ' +
631
+ 'so a deleted or misspelled key can be found. None of this is an error: a key that names no role grants nothing and is reported here.',
632
+ },
633
+ {
634
+ method: 'POST', path: '/api/org/roles', section: 'org',
635
+ summary: 'Creates an organization role.',
636
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 201,
637
+ params: [], query: null, request: createOrgRoleRequest, response: orgRole,
638
+ errors: [...DEVELOPER_GUARD, 'validation_error', 'role_cycle', 'role_key_taken'], transport: 'http',
639
+ notes: 'An organization holds at most 50 roles; the next one is `400 validation_error`. A key in `inherits` that names no role is accepted and ' +
640
+ 'warns: inheritance through it grants nothing until a role with that key exists. A role that would inherit from itself, as `inherits` ' +
641
+ 'naming its own key does, is `400 role_cycle`. A key that another role has is `409 role_key_taken`.',
642
+ },
643
+ {
644
+ method: 'PATCH', path: '/api/org/roles/:key', section: 'org',
645
+ summary: "Changes a role's name, its parents or its key.",
646
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
647
+ params: [{ name: 'key', description: "The role's key, as listed by `GET /api/org/roles`; a key that names no role answers `404`." }],
648
+ query: null, request: patchOrgRoleRequest, response: orgRole,
649
+ errors: [...DEVELOPER_GUARD, 'validation_error', 'not_found', 'role_cycle', 'role_key_taken', 'confirmation_required', 'rate_limited'],
650
+ transport: 'http',
651
+ notes: 'A field that is left out stays as it is; `inherits` replaces the whole list. A change to `inherits` that would lead back to the role is ' +
652
+ '`400 role_cycle`, with the loop in `details`. \n\n**Renaming the key is one call or two.** Without `update_references`, the rename is ' +
653
+ 'accepted at once; everything that still names the old key, in documents, assignments, invitations, default roles, other roles and ' +
654
+ 'organization defaults, keeps it and turns into a warning. With `update_references: true` and no `confirm`, a rename that has places to ' +
655
+ 'rewrite changes nothing and answers `409 confirmation_required` whose `details` is a `roleRenamePreview`: every place that would be ' +
656
+ 'rewritten, the document it is in, the version a published document would get, and a `confirm` token. A rename with no place to ' +
657
+ 'rewrite applies at once and needs no token. The second call repeats the same body with ' +
658
+ '`confirm` set to that token and rewrites all of it in one transaction. Assignments and role rows change directly; each affected ' +
659
+ 'published `fleetless.yaml` and each app\'s published collections schema get a new version that differs only in the key, and an ' +
660
+ 'existing draft of either is updated the same way. If the ' +
661
+ 'places changed between the two calls, the token is stale and the second call answers a new preview instead of applying. A rename ' +
662
+ 'that has to rewrite the collections schema of an app whose collections are busy with a publish, a restore or a purge waits up to two ' +
663
+ 'seconds for it, then answers `429 rate_limited` with `retry_after_ms` and changes nothing; repeat the call. A schema whose text cannot ' +
664
+ 'be rewritten without losing it, because an access rule is an alias for instance, refuses the rename with `400 validation_error` ' +
665
+ 'naming `update_references` and changes nothing; rename the role without `update_references` and edit that schema by hand. A new key ' +
666
+ 'that another role has is `409 role_key_taken`.',
667
+ },
668
+ {
669
+ method: 'DELETE', path: '/api/org/roles/:key', section: 'org',
670
+ summary: 'Deletes a role at once.',
671
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 204,
672
+ params: [{ name: 'key', description: "The role's key, as listed by `GET /api/org/roles`; a key that names no role answers `404`." }],
673
+ query: null, request: null, response: null,
674
+ errors: [...DEVELOPER_GUARD, 'validation_error', 'not_found'], transport: 'http',
675
+ notes: 'Nothing is moved and nothing is refused for what depends on the role. App users that hold it keep their account and can sign in, with ' +
676
+ 'no rights from the role; everything that names the key turns into a warning and is listed under `dangling` of `GET /api/org/roles`. ' +
677
+ 'Live subscriptions that relied on the role are re-checked at once. Creating a role with the same key later makes the places that ' +
678
+ 'name it count again.',
679
+ },
680
+ {
681
+ method: 'GET', path: '/api/org/roles/defaults', section: 'org',
682
+ summary: "Reads the organization's default roles for each kind of access.",
683
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
684
+ params: [], query: null, request: null, response: roleDefaultsResponse,
685
+ errors: [...DEVELOPER_GUARD], transport: 'http',
686
+ notes: 'Every kind of access is present; an empty list means nobody holds it, not even the most senior role. A default applies where a robot\'s ' +
687
+ 'published `fleetless.yaml` names no role for the thing asked about. A new organization starts with `observe` for `read` and `assets`, ' +
688
+ 'and `operate` for `invoke`, `publish` and `job_history`.',
689
+ },
690
+ {
691
+ method: 'PUT', path: '/api/org/roles/defaults', section: 'org',
692
+ summary: "Changes the organization's default roles for the named kinds of access.",
693
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
694
+ params: [], query: null, request: putRoleDefaultsRequest, response: roleDefaultsResponse,
695
+ errors: [...DEVELOPER_GUARD, 'validation_error'], transport: 'http',
696
+ notes: 'Despite the verb, kinds that are not named keep their default; `null` or `[]` sets a kind to nobody. A key that names no role is ' +
697
+ 'accepted and warns, and grants nothing. Answers all the defaults as they stand afterwards. A default that narrows who holds a kind ' +
698
+ 're-checks the live subscriptions it affects.',
699
+ },
555
700
  {
556
701
  method: 'GET', path: '/api/audit', section: 'org',
557
702
  summary: "Reads the org's audit log, newest first, cursor-paged over the durable sequence number.",
@@ -580,7 +725,8 @@ export const ROUTES = [
580
725
  errors: [...DEVELOPER_GUARD, 'validation_error', 'identifier_taken', 'quota_exceeded'], transport: 'http',
581
726
  notes: 'Every robot id is checked before anything is created, so a bad one never leaves a robotless app to clean up. The identifier `mcp` is ' +
582
727
  'reserved by the central MCP server and refused as a `validation_error`. An app belongs to the org and to nothing inside it: the group ' +
583
- 'an app used to be created in, and the `409 target_state_conflict` that refused the Org Admins one, are both gone with the group model.',
728
+ 'an app used to be created in, and the `409 target_state_conflict` that refused the Org Admins one, are both gone with the group model. ' +
729
+ 'A new app has no default role: `default_role` is `null` until `PUT /api/apps/:id/access` sets one.',
584
730
  },
585
731
  {
586
732
  method: 'GET', path: '/api/apps', section: 'apps',
@@ -597,17 +743,19 @@ export const ROUTES = [
597
743
  params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
598
744
  query: null, request: null, response: appSchema,
599
745
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
600
- notes: 'An app belonging to another org reads exactly like one that does not exist — `404`, never a `403`.',
746
+ notes: 'An app belonging to another org reads exactly like one that does not exist — `404`, never a `403`. `default_role` is the key as stored, ' +
747
+ 'or `null` when the app has none; a key that names no role is shown as it is, and `GET /api/apps/:id/access` warns about it.',
601
748
  },
602
749
  {
603
750
  method: 'PATCH', path: '/api/apps/:id', section: 'apps',
604
- summary: "Changes an app's name, its attached robots or its default role.",
751
+ summary: "Changes an app's name or its attached robots.",
605
752
  audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
606
753
  params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
607
754
  query: null, request: updateAppRequest, response: appSchema,
608
755
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'validation_error', 'not_found'], transport: 'http',
609
- notes: 'A `default_role_id` naming a role of another app is refused: it is the one cross-app authorization check this shape can carry. ' +
610
- 'Changing the robot set closes every live subscription the app\'s users hold, since a grant may no longer name a reachable robot.',
756
+ notes: 'The default role is not set here: `PUT /api/apps/:id/access` replaces it together with the locks, and a body that names ' +
757
+ 'a default role, by id or by key, is `400 validation_error`. ' +
758
+ 'Changing the robot set closes every live subscription the app\'s users hold, since a robot they were using may no longer be reachable.',
611
759
  },
612
760
  {
613
761
  method: 'GET', path: '/api/apps/:id/deletion-preview', section: 'apps',
@@ -629,98 +777,12 @@ export const ROUTES = [
629
777
  params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
630
778
  query: null, request: null, response: null,
631
779
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
632
- notes: 'An app outside the caller\'s org answers `404`, as an unknown id does. A full cascade — its users, roles, server keys, ' +
633
- 'invitations, OIDC provider configuration and mail templates all go, recorded once as `app.deleted` carrying an `appDeletionSummary`. ' +
634
- 'Its robots are untouched: they belong to the org, not to the app. \n\n**No `force` parameter** — see ' +
780
+ notes: 'An app outside the caller\'s org answers `404`, as an unknown id does. A full cascade — its users, server keys, ' +
781
+ 'invitations, OIDC provider configuration, mail templates, and collections with their records and history all go, recorded once as ' +
782
+ '`app.deleted` carrying an `appDeletionSummary`. ' +
783
+ 'Its robots and the organization\'s roles are untouched: they belong to the org, not to the app. \n\n**No `force` parameter** — see ' +
635
784
  '`GET /api/apps/:id/deletion-preview`.',
636
785
  },
637
- {
638
- method: 'POST', path: '/api/apps/:id/roles', section: 'apps',
639
- summary: 'Creates a custom role on the app.',
640
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 201,
641
- params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
642
- query: null, request: null, response: role,
643
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error'], transport: 'http',
644
- notes: 'The body is `{ "name": string }` — non-empty, trimmed, at most 60 characters as on `role.name` — and is deliberately not a contract shape: contracts ' +
645
- 'define the `role` this answers with, not this one trivial request. **The answer is a bare `role`, not an envelope**, unlike the ' +
646
- 'listing beside it.',
647
- },
648
- {
649
- method: 'GET', path: '/api/apps/:id/roles', section: 'apps',
650
- summary: "Lists the app's roles, builtin and custom.",
651
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
652
- params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
653
- query: null, request: null, response: roleListResponse,
654
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
655
- notes: 'Answers `{ "roles": [role, …] }`, builtin roles included — a role a developer never created is still one a user can hold.',
656
- },
657
- {
658
- method: 'PUT', path: '/api/apps/:id/roles/:roleId/permissions', section: 'apps',
659
- summary: "Replaces a role's grants and capabilities in one write.",
660
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
661
- params: [
662
- { name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' },
663
- { name: 'roleId', description: 'The role\'s uuid, from `GET /api/apps/:id/roles`; a role of another app answers `404`.' },
664
- ],
665
- query: null, request: rolePermissions, response: rolePermissions,
666
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error'], transport: 'http',
667
- notes: '`role_id` in the body must name the role in the path, compared case-insensitively — a uuid is a value, not a string, and a client that ' +
668
- 'uppercases them consistently must not be refused for repeating what the path says. A grant naming a robot the app does not have is ' +
669
- 'refused rather than stored: a permission for something the role cannot reach reads as authoritative to whoever writes the next consumer. ' +
670
- 'Every user holding this role has their live subscriptions re-authorized.',
671
- },
672
- {
673
- method: 'GET', path: '/api/apps/:id/roles/:roleId/permissions', section: 'apps',
674
- summary: "Reads a role's grants and capabilities.",
675
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
676
- params: [
677
- { name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' },
678
- { name: 'roleId', description: 'The role\'s uuid, from `GET /api/apps/:id/roles`; a role of another app answers `404`.' },
679
- ],
680
- query: null, request: null, response: rolePermissions,
681
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
682
- },
683
- {
684
- method: 'GET', path: '/api/apps/:id/roles/:roleId/mcp-tools', section: 'apps',
685
- summary: 'Previews the robot datasheets an MCP caller holding this role would be offered.',
686
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
687
- params: [
688
- { name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' },
689
- { name: 'roleId', description: 'The role\'s uuid, from `GET /api/apps/:id/roles`; a role of another app answers `404`.' },
690
- ],
691
- query: null, request: null, response: mcpRolePreviewResponse,
692
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
693
- notes: 'Built by the same builder the MCP server\'s own `robots.describe` uses, so the two cannot drift. It answers what the role *would* be ' +
694
- 'offered and consults nothing about any user\'s actual MCP entitlement. A robot the role grants nothing on still appears, with an empty ' +
695
- '`exposures` — dropping it would read as "not attached", which is a different fact.',
696
- },
697
- {
698
- method: 'PATCH', path: '/api/apps/:id/roles/:roleId', section: 'apps',
699
- summary: 'Renames a role; its users keep it.',
700
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
701
- params: [
702
- { name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' },
703
- { name: 'roleId', description: 'The role\'s uuid, from `GET /api/apps/:id/roles`; a role of another app answers `404`.' },
704
- ],
705
- query: null, request: roleRenameRequest, response: role,
706
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error', 'role_name_taken'], transport: 'http',
707
- notes: 'Names are unique per app, compared exactly as stored after trimming. Built-in roles can be renamed.',
708
- },
709
- {
710
- method: 'DELETE', path: '/api/apps/:id/roles/:roleId', section: 'apps',
711
- summary: 'Deletes a role, moving its users, pending invitations and default-role status to another role.',
712
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 204,
713
- params: [
714
- { name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' },
715
- { name: 'roleId', description: 'The role\'s uuid, from `GET /api/apps/:id/roles`; a role of another app answers `404`.' },
716
- ],
717
- query: roleDeleteQuery, request: null, response: null,
718
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error', 'role_in_use', 'last_role'], transport: 'http',
719
- notes: 'Without `move_to`, a role that app users or pending invitations hold, or that is the app\'s default, answers ' +
720
- '`409 role_in_use` with `{ users, invitations, is_default }`. With `move_to` — another role of the same app, else ' +
721
- '`400 validation_error` — one transaction moves `app_users.role_id`, pending invitations and `default_role_id`, then deletes ' +
722
- 'the role and its permissions. The app\'s only role answers `409 last_role`. Built-in roles can be deleted like any other.',
723
- },
724
786
  {
725
787
  method: 'POST', path: '/api/apps/:id/server-keys', section: 'apps',
726
788
  summary: 'Mints a server key for the app and returns the raw secret once.',
@@ -728,8 +790,8 @@ export const ROUTES = [
728
790
  params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
729
791
  query: null, request: null, response: createServerKeyResponse,
730
792
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error'], transport: 'http',
731
- notes: 'A server key carries full app rights and outlives its creator\'s removal. The body is `{ "name": string }`, the same ' +
732
- 'trivial shape role creation takes. `key` is the only moment the raw secret exists outside the caller\'s hands — it is never in a ' +
793
+ notes: 'A server key carries full app rights and outlives its creator\'s removal. The body is `{ "name": string }`, too ' +
794
+ 'trivial to be a contract shape. `key` is the only moment the raw secret exists outside the caller\'s hands — it is never in a ' +
733
795
  'listing, never in an audit event, and cannot be read back.',
734
796
  },
735
797
  {
@@ -768,6 +830,51 @@ export const ROUTES = [
768
830
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
769
831
  notes: 'The key stops working at once. Minting, rotating and revoking all decide who may speak for the whole app.',
770
832
  },
833
+ {
834
+ method: 'GET', path: '/api/apps/:id/access', section: 'apps',
835
+ summary: "Reads what an app locks and which role its users get by default, with what is out of step in it.",
836
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
837
+ params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
838
+ query: null, request: null, response: appAccessResponse,
839
+ errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
840
+ notes: 'An app can only lock, never extend: roles decide who may use what, and a lock takes capabilities away from every user and server key of ' +
841
+ 'the app, whatever their role. `warnings` lists what the access names that does not exist as written, such as a default role that ' +
842
+ 'is no role or a lock on a slug the robot does not have. None of it is an error. `revision` identifies the access as it stands: ' +
843
+ 'send it back with the next `PUT` and a write composed from a stale read is refused.',
844
+ },
845
+ {
846
+ method: 'PUT', path: '/api/apps/:id/access', section: 'apps',
847
+ summary: "Replaces what an app locks and which role its users get by default.",
848
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
849
+ params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
850
+ query: null, request: appAccess, response: appAccessResponse,
851
+ errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'validation_error', 'not_found', 'target_state_conflict'], transport: 'http',
852
+ notes: 'A full replacement: the body is exactly what the app has afterwards, so a lock that is not in it is lifted. A default role that is no ' +
853
+ 'role, a lock on a slug the robot does not have and a lock on a robot the app does not attach are accepted and come back as ' +
854
+ '`warnings`. A change that can narrow rights re-checks the live subscriptions of the app\'s users at once. \n\n**Send the `revision` you ' +
855
+ 'read.** The access can change under a caller without a write of its own: a slug rename adds the new name to every lock that lists the ' +
856
+ 'old one, and detaching a robot drops its lock. A body composed before such a change would lift the lock it added, so a `revision` that ' +
857
+ 'is no longer the stored one is `409 target_state_conflict` naming `revision` (rule `stale`), and nothing is written, audited or ' +
858
+ 'announced; read the access again and compose the body anew. Left out, the body replaces whatever is stored, as before: the last ' +
859
+ 'writer wins. A `revision` that is not a revision is `400 validation_error`.',
860
+ },
861
+ {
862
+ method: 'GET', path: '/api/apps/:id/effective-rights', section: 'apps',
863
+ summary: 'Shows what one role, or one app user, may use on each robot the app attaches.',
864
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
865
+ params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }],
866
+ query: effectiveRightsQuery, request: null, response: effectiveRightsResponse,
867
+ errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'validation_error', 'not_found'], transport: 'http',
868
+ notes: 'Name exactly one of `role` and `user`; both or neither is `400 validation_error`. Per attached robot, every capability is listed with ' +
869
+ 'whether it is granted, the requirement, where that came from (the entry, rule n of `access.rules`, or the organization default), the ' +
870
+ 'inherited role that satisfied it and whether the app locks it; the datasheet is the one an MCP session of that role would get. ' +
871
+ 'Only the published configuration counts: a robot with nothing published has no exposures, and its `assets` and `job_history` follow ' +
872
+ 'the organization defaults. `reachable` says whether a session of the role reaches the robot at all; a robot it does not reach is ' +
873
+ 'still listed, with every capability that explains why. A role that is no role is not an error; it answers `role_known: false` with ' +
874
+ 'nothing granted, and so does a user who is not `active`. A user of another app answers `404`. `collections` says what the role may do ' +
875
+ 'with the records of each collection of the latest published schema: read, create, and update and delete for every record, only the ' +
876
+ 'role\'s own, or none; it is empty when the app has no published schema.',
877
+ },
771
878
  /* -------------------------------------- the app's users and invitations */
772
879
  {
773
880
  method: 'GET', path: '/api/apps/:id/users', section: 'apps',
@@ -779,7 +886,8 @@ export const ROUTES = [
779
886
  notes: 'Answers `{ "users": [appUser, …] }`. **A different identity space from `GET /api/org/users`**, and nothing joins the two: an app user ' +
780
887
  'belongs to exactly one app, their address is unique per app rather than globally, and the same address may exist as unrelated accounts ' +
781
888
  'in several apps of one org. No password hash, no token and no provider secret appears here — `appUser` names the fields it carries ' +
782
- 'rather than spreading the stored row.',
889
+ 'rather than spreading the stored row. An account that holds no role key lists with `role: null`; it reaches nothing until ' +
890
+ '`PATCH /api/apps/:id/users/:userId` gives it one.',
783
891
  },
784
892
  {
785
893
  method: 'POST', path: '/api/apps/:id/users', section: 'apps',
@@ -791,13 +899,14 @@ export const ROUTES = [
791
899
  notes: 'The developer-authenticated door into the app\'s user table, and the one place `409 email_taken` is an honest answer about an app user: ' +
792
900
  'the caller is authenticated into this app already, so telling them the address is taken discloses nothing they could not read from the ' +
793
901
  'listing beside it. `POST /api/client/register` answers `202` to the same fact, because there the caller is a stranger. `404 not_found` ' +
794
- 'is the app, or a `role_id` that is not a role of it — a role of another app is refused rather than stored, since a user holding one ' +
795
- 'would carry rights nothing in this app can resolve. **The password policy answers `400 validation_error`**, not a code of its own: the ' +
902
+ 'is the app. The `role` is a key of the organization\'s roles: a malformed one is `400 validation_error`, and a well-formed one is stored ' +
903
+ 'as given even when it names no role, which grants nothing and shows up under `dangling` of `GET /api/org/roles`. **The password policy ' +
904
+ 'answers `400 validation_error`**, not a code of its own: the ' +
796
905
  'twelve-character minimum is the `password` field\'s schema rule, and every route that takes a password refuses a ' +
797
906
  'short one exactly the way it refuses any other malformed field. An account created here is `active` immediately: a developer entering ' +
798
907
  'somebody by hand has made the decision the verification mail automates, and its address counts as proven. `409 target_state_conflict` ' +
799
- 'names `default_role_id` when `role_id` is absent and the app has no default role, or its default names a role that no longer resolves ' +
800
- '— a user with no role holds rights nothing in this app can read, so nothing is created. \n\n**`409 quota_exceeded` when the org holds as ' +
908
+ 'names `default_role` with rule `not_set` when `role` is absent and the app has no default role — there would be no role to give the ' +
909
+ 'user, so nothing is created. \n\n**`409 quota_exceeded` when the org holds as ' +
801
910
  'many app users as `max_end_users` allows**, counted across every app of the org — the same number `GET /api/org/quotas` reports as ' +
802
911
  '`usage.max_end_users`, since the same address in two apps is two accounts. `details` carries `{ quota, limit }`, as every count quota\'s ' +
803
912
  'refusal does. The check is at **creation** only: an existing user signs in, is patched and is deleted at the quota exactly as under it, ' +
@@ -827,7 +936,9 @@ export const ROUTES = [
827
936
  'who typed an address they do not own log in without ever spending the mailed token. Unblocking restores the status the account had — ' +
828
937
  '`active` for one whose address was proven, `pending_verification` for one blocked before it ever verified. A write that names the ' +
829
938
  'status the account already holds changes nothing and mints no event, so it does not end the sessions a re-sent form would otherwise ' +
830
- 'have killed. A `role_id` naming a role of another app is `404 not_found`, the same refusal creation makes.',
939
+ 'have killed. A `role` is stored as given, as creation does: a malformed key is `400 validation_error`, one that names no role grants ' +
940
+ 'nothing, and the same key the user already holds changes nothing. A changed role is applied to the user\'s open subscriptions at once, ' +
941
+ 'and those the new role no longer allows end.',
831
942
  },
832
943
  {
833
944
  method: 'DELETE', path: '/api/apps/:id/users/:userId', section: 'apps',
@@ -926,7 +1037,8 @@ export const ROUTES = [
926
1037
  'revoke. **No `accept_url`**, the rule the team listing already keeps: this list exists so a developer can see what is outstanding and ' +
927
1038
  'withdraw it, and neither needs the token, while a list that carried it would turn every screenshot and browser-history entry of that ' +
928
1039
  'page into a live credential for somebody else\'s account. `mail` is omitted too — it described what happened at creation time, and ' +
929
- 're-serving it invites a reader to take it as current.',
1040
+ 're-serving it invites a reader to take it as current. An invitation that holds no role key and whose app has no default role lists ' +
1041
+ 'with `role: null`; accepting or reissuing it is `409 target_state_conflict` naming `default_role`.',
930
1042
  },
931
1043
  {
932
1044
  method: 'POST', path: '/api/apps/:id/invitations', section: 'apps',
@@ -937,12 +1049,13 @@ export const ROUTES = [
937
1049
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'validation_error', 'not_found', 'email_taken', 'target_state_conflict', 'rate_limited'],
938
1050
  transport: 'http',
939
1051
  notes: '**An app user, not a team member.** `POST /api/org/invitations` is the other space and leads to the console; this link leads into the ' +
940
- 'developer\'s own app. The role is resolved and stored now, so a later change to `default_role_id` does not re-aim a link already sent. ' +
1052
+ 'developer\'s own app. The role is resolved and stored now, so a later change to `default_role` does not re-aim a link already sent. ' +
941
1053
  'An invitation **always bypasses `allowed_domains`**. \n\nThe answer carries `accept_url`: the app\'s `invite_url` with the token in it, ' +
942
1054
  'or the Fleetless-hosted invitation page when the app has configured none — so mailing it is never refused for a missing URL. ' +
943
- '`409 target_state_conflict` names `default_role_id` when `role_id` is absent and the app has no default role, or its default no longer resolves: an invitation ' +
944
- 'that names no role has nothing to hand its acceptor, so it is refused here rather than at the acceptance a week later. `409 ' +
945
- 'email_taken` is an address the app already has as a user; `404 not_found` is the app or a `role_id` that is not one of its roles. ' +
1055
+ '`409 target_state_conflict` names `default_role` with rule `not_set` when `role` is absent and the app has no default role: an invitation ' +
1056
+ 'that names no role has nothing to hand its acceptor, so it is refused here rather than at the acceptance a week later. A `role` that ' +
1057
+ 'names no role is accepted and grants nothing; a malformed key is `400 validation_error`. `409 ' +
1058
+ 'email_taken` is an address the app already has as a user; `404 not_found` is the app. ' +
946
1059
  '\n\nCreating shares the reissue route\'s ceiling of **five invitation mails a minute per app**, answering `429 rate_limited` with ' +
947
1060
  '`retry_after_ms`: re-creating an invitation for one address replaces it and mails again, so a limit that bound only reissue would be ' +
948
1061
  'a limit on the wrong door.',
@@ -953,11 +1066,13 @@ export const ROUTES = [
953
1066
  audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
954
1067
  params: [{ name: 'id', description: 'The app\'s uuid, as returned by `POST /api/apps` or listed by `GET /api/apps`.' }, { name: 'invId', description: 'The invitation\'s uuid, from `GET /api/apps/:id/invitations`; an invitation of another app answers `404`.' }],
955
1068
  query: null, request: null, response: appInvitation,
956
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'rate_limited'], transport: 'http',
1069
+ errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'target_state_conflict', 'rate_limited'], transport: 'http',
957
1070
  notes: 'The old link stops resolving the instant this returns: the row is found by token hash and the previous hash is gone. Two live links to ' +
958
1071
  'one invitation would reopen the door the listing\'s missing `accept_url` closes. \n\n**The answer carries a new `id`.** The old row ' +
959
1072
  'is revoked and a fresh one takes its place, so a caller holding the previous `id` gets `404` from its next revoke or reissue: re-read ' +
960
- 'the listing after this call rather than keeping the id you sent. The seven days start again. \n\nLimited server-side to **five ' +
1073
+ 'the listing after this call rather than keeping the id you sent. The new invitation holds the same role, and the seven days start ' +
1074
+ 'again. An invitation that holds no role key and whose app has no default role is refused with `409 target_state_conflict` naming ' +
1075
+ '`default_role` (rule `not_set`) before the old link is revoked: set the default role, or revoke it and invite again. \n\nLimited server-side to **five ' +
961
1076
  'reissues a minute per app** — shared with `POST /api/apps/:id/invitations`, since both mint a link and mail it — answering `429 ' +
962
1077
  'rate_limited` with `retry_after_ms`. A disabled button is a hint, this is the limit. An invitation that has already been accepted is ' +
963
1078
  'not pending and answers `404`.',
@@ -1654,8 +1769,8 @@ export const ROUTES = [
1654
1769
  errors: ['not_found', 'unauthorized', 'forbidden'], transport: 'http',
1655
1770
  notes: 'JSON-RPC over MCP\'s Streamable HTTP, so neither the request nor the response is a shape contracts describes — exactly as `POST /mcp` ' +
1656
1771
  'is, and stateless for the same reason: a fresh transport per request, no session id, nothing surviving the call. **App users only.** ' +
1657
- 'The tools are this app\'s robots filtered by the caller\'s role, built by the same builder `GET /api/apps/:id/roles/:roleId/mcp-tools` ' +
1658
- 'previews, so the console\'s preview and the live catalog cannot drift. The console tool family belongs to the central endpoint and is ' +
1772
+ 'The tools are this app\'s robots filtered by the caller\'s role, built by the same builder `GET /api/robots/:id/datasheet` ' +
1773
+ 'answers, so the datasheet and the live catalog cannot drift. The console tool family belongs to the central endpoint and is ' +
1659
1774
  'offered here to nobody. \n\n**The bearer is verified inside the handler**, not by a route guard, for the two reasons the central ' +
1660
1775
  'endpoint gives — the identity comes from the token and the path names none of it, and the refusal has to carry a `WWW-Authenticate` ' +
1661
1776
  'challenge a guard shared with the REST surface does not send. The challenge names **this app\'s** protected-resource document (RFC ' +
@@ -1861,8 +1976,9 @@ export const ROUTES = [
1861
1976
  'or sent while it is off: an email-code-only app registers people without one. `404 not_found` names an ' +
1862
1977
  '**app identifier no app carries**, and never an address: an app identifier is already public (it is in the MCP metadata path and in the ' +
1863
1978
  'developer\'s own URLs), while collapsing it into `registration_closed` sent a developer who mistyped their own identifier hunting a ' +
1864
- 'configuration bug that was not there. `409 target_state_conflict` when the app has no default role — there would be no role to give ' +
1865
- 'the person. An app with no `verify_url` is not refused: the mailed link points at the hosted confirmation page instead. ' +
1979
+ 'configuration bug that was not there. `409 target_state_conflict` naming `default_role` with rule `not_set` when the app has no default ' +
1980
+ 'role — there would be no role to give the person. A default that names no role is not a refusal: the account holds the key and ' +
1981
+ 'reaches nothing. An app with no `verify_url` is not refused: the mailed link points at the hosted confirmation page instead. ' +
1866
1982
  '\n\n**`409 quota_exceeded` when the org is at its `max_end_users` limit**, counted across every app of the org. It is the one refusal ' +
1867
1983
  'here that is answered **before the address is looked at** — and that ordering is the point rather than an implementation detail: a ' +
1868
1984
  'quota checked after the existence branch would answer `202` for an address the app already knows and `409` for one it does not, which ' +
@@ -1948,9 +2064,11 @@ export const ROUTES = [
1948
2064
  'than being spent, so the developer can revoke it or point the person at the login. An address that registered itself and is still ' +
1949
2065
  '`pending_verification` is not that state: accepting sets the password the invitee just chose, activates the account and gives it the ' +
1950
2066
  'invitation\'s role, because reading the invitation mail proves the address the verification link was waiting on. \n\n`409 ' +
1951
- 'target_state_conflict` names `role_id` with rule `not_set` when the role the invitation was fixed to has since been deleted and the ' +
1952
- 'app has no default role to fall back on: there is no access to hand the acceptor, and creating an account with none would be worse ' +
1953
- 'than saying so. \n\n**`409 quota_exceeded` when accepting would CREATE an account and the org is at its `max_end_users` limit**, counted ' +
2067
+ 'target_state_conflict` names `default_role` with rule `not_set` when the invitation holds no role key (it lists with `role: null`) ' +
2068
+ 'and the app has no default role to fall back on: there is no access to hand the acceptor, and creating an account with none would ' +
2069
+ 'be worse than saying so. A role deleted since the invitation was issued is no obstacle: the account is created holding the key and ' +
2070
+ 'reaches nothing. ' +
2071
+ '\n\n**`409 quota_exceeded` when accepting would CREATE an account and the org is at its `max_end_users` limit**, counted ' +
1954
2072
  'across every app of the org. An invitation that names a row the developer already created, and one whose address is held by an ' +
1955
2073
  'unfinished self-registration, both finish an account that already counts — those are not refused, because the org is not one account ' +
1956
2074
  'larger afterwards. The token is not spent by the refusal: the developer can raise the limit, or delete somebody, and the same link ' +
@@ -1999,7 +2117,9 @@ export const ROUTES = [
1999
2117
  params: [], query: null, request: null, response: clientIdentity,
2000
2118
  errors: [...CLIENT_GUARD], transport: 'http',
2001
2119
  notes: 'The one route that answers for all three caller kinds — a developer bearer, an app-user bearer and a server key — which is why the ' +
2002
- 'shape names each of `developer_id`, `app_user_id` and `server_key_id` and fills exactly one.',
2120
+ 'shape names each of `developer_id`, `app_user_id` and `server_key_id` and fills exactly one. `role` is the organization role an app ' +
2121
+ 'user holds, as its key and display name; it is `null` for a developer and a server key, and for an app user whose key names no role ' +
2122
+ '(the role was deleted), who signs in and reaches nothing.',
2003
2123
  },
2004
2124
  /* ------------------------------------------------ app-user two-factor */
2005
2125
  {
@@ -2318,7 +2438,7 @@ export const ROUTES = [
2318
2438
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
2319
2439
  notes: 'The same shape the delete\'s own audit event carries, computed by the same function on purpose: the confirmation dialog and the eventual ' +
2320
2440
  'receipt agree by construction, and any difference between them is real drift — a robot that kept recording in between — rather than two ' +
2321
- 'estimates that quietly disagree.',
2441
+ 'estimates that quietly disagree. `collection_records` counts, per app, the app collection records that go with the robot.',
2322
2442
  },
2323
2443
  {
2324
2444
  method: 'DELETE', path: '/api/robots/:id', section: 'robots',
@@ -2332,16 +2452,6 @@ export const ROUTES = [
2332
2452
  '`409 robot_in_use` unless `?force=true` is passed, matched as the bare string so the caller has to actually say it. A cascade that ' +
2333
2453
  'fails partway is `500 robot_deletion_partial` with the progress, never a bare `internal_error` that would read as "nothing happened".',
2334
2454
  },
2335
- {
2336
- method: 'PUT', path: '/api/robots/:id/details', section: 'robots',
2337
- summary: 'Replaces the developer-maintained details document shown alongside the robot.',
2338
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
2339
- params: [{ name: 'id', description: 'The robot\'s uuid, as returned by `POST /api/robots` or listed by `GET /api/robots`.' }],
2340
- query: null, request: putRobotDetailsRequest, response: putRobotDetailsResponse,
2341
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error'], transport: 'http',
2342
- notes: 'Answers `{ "details": robotDetailsDoc }` — the stored document, which is the one that was sent. The update is fanned out to every ' +
2343
- '`/realtime` subscriber of the `robot_details` built-in, so a client watching the robot sees the new document without polling.',
2344
- },
2345
2455
  {
2346
2456
  method: 'GET', path: '/api/robots/:id/datapoints', section: 'robots',
2347
2457
  summary: 'Lists the datapoints of a robot, filtered to what the caller\'s role grants.',
@@ -2349,17 +2459,17 @@ export const ROUTES = [
2349
2459
  params: [{ name: 'id', description: 'The robot\'s uuid; an end user reaches it through an app that attaches it.' }],
2350
2460
  query: null, request: null, response: datapointListResponse,
2351
2461
  errors: [...CLIENT_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
2352
- notes: 'A developer bearer sees the robot\'s whole list unfiltered; an end user or a server key sees only the slugs their role grants, and a ' +
2462
+ notes: 'A developer bearer sees the robot\'s whole list unfiltered; an end user sees only the slugs their role grants, a server key every slug its app does not lock, and a ' +
2353
2463
  'robot their app does not attach answers `404` exactly as one that does not exist.',
2354
2464
  },
2355
2465
  {
2356
2466
  method: 'GET', path: '/api/robots/:id/exposures', section: 'robots',
2357
- summary: 'Lists every grantable slug of a robot with its kind — the material the roles matrix is built from.',
2467
+ summary: 'Lists every exposed slug of a robot with its kind — the material an app picks its locks from.',
2358
2468
  audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
2359
2469
  params: [{ name: 'id', description: 'The robot\'s uuid, as returned by `POST /api/robots` or listed by `GET /api/robots`.' }],
2360
2470
  query: null, request: null, response: exposureListResponse,
2361
2471
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
2362
- notes: 'Developer-only: this is what a role *could* be granted, which is a configuration fact rather than something an end user is entitled to enumerate.',
2472
+ notes: 'Developer-only: this is what a role could be required to use and an app could lock, which is a configuration fact rather than something an end user is entitled to enumerate.',
2363
2473
  },
2364
2474
  {
2365
2475
  method: 'GET', path: '/api/robots/:id/datapoints/:slug', section: 'robots',
@@ -2374,7 +2484,7 @@ export const ROUTES = [
2374
2484
  notes: 'For a client caller the grant check runs **before** any existence lookup, with no extra query on either path to time: a denied slug and ' +
2375
2485
  'a nonexistent one must be one answer. That is why an ungranted slug is `403 forbidden` while a granted-but-unconfigured one is ' +
2376
2486
  '`404 unknown_datapoint` and a configured one with no sample yet is `404 no_data` — three facts a caller who is entitled to them needs ' +
2377
- 'told apart. The plane built-ins (`bridge_state`, `robot_details`) answer here too, without appearing in any document.',
2487
+ 'told apart. The plane built-in `bridge_state` answers here too, without appearing in any document.',
2378
2488
  },
2379
2489
  /* ------------------------------------------ discovery: the REST twins of the two MCP tools a session starts from */
2380
2490
  {
@@ -2398,7 +2508,7 @@ export const ROUTES = [
2398
2508
  errors: [...CLIENT_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
2399
2509
  notes: '**The REST twin of the MCP action `robots.describe`**: one answer per robot — every datapoint, action, service, publisher and camera the ' +
2400
2510
  'role grants, each with its `input_schema` where it takes parameters, plus the two capabilities that gate whole features, ' +
2401
- '`action_history` and `assets`. A robot with nothing published answers an empty `exposures` list, never a refusal. A robot the caller ' +
2511
+ '`job_history` and `assets`. A robot with nothing published answers an empty `exposures` list, never a refusal. A robot the caller ' +
2402
2512
  'does not reach — not attached to their app, or attached with a role that grants nothing on it — answers `404` exactly as one that ' +
2403
2513
  'does not exist. The app-user datapoint and camera listings under this prefix stay; this is the one read that also names actions, ' +
2404
2514
  'services, publishers and capabilities, which is what an app needs before it can draw a screen.',
@@ -2437,7 +2547,9 @@ export const ROUTES = [
2437
2547
  notes: 'A draft that is valid YAML but not a Fleetless configuration is `422 draft_not_a_document`, carrying every issue rather than the ' +
2438
2548
  'blocking subset — nothing about that text is publishable, so there is no subset to pick, and the warning naming the checks that could ' +
2439
2549
  'not run is part of reading the list correctly. A document with `severity: "error"` issues is `422 validation_error` with just those. ' +
2440
- 'The draft\'s own text travels into the version, so a restore later returns what the author wrote rather than a re-rendering of it.',
2550
+ 'The draft\'s own text travels into the version, so a restore later returns what the author wrote rather than a re-rendering of it. ' +
2551
+ 'The answer carries `warnings`: every `warning` of the published document, role keys that name no role of the organization included. ' +
2552
+ 'A warning never blocks a publish.',
2441
2553
  },
2442
2554
  {
2443
2555
  method: 'GET', path: '/api/robots/:id/config/versions', section: 'config',
@@ -2476,16 +2588,20 @@ export const ROUTES = [
2476
2588
  },
2477
2589
  {
2478
2590
  method: 'POST', path: '/api/robots/:id/config/rename-slug', section: 'config',
2479
- summary: 'Renames a slug in the draft and moves every role grant and the recorded history with the name.',
2591
+ summary: 'Renames a slug in the draft and moves the app locks and the recorded history with the name.',
2480
2592
  audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
2481
2593
  params: [{ name: 'id', description: 'The robot\'s uuid, as returned by `POST /api/robots` or listed by `GET /api/robots`.' }],
2482
2594
  query: null, request: renameSlugRequest, response: renameSlugResponse,
2483
2595
  errors: [
2484
2596
  ...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error', 'draft_not_a_document',
2485
- 'unknown_slug', 'reserved_slug', 'duplicate_slug', 'history_migrating', 'internal_error',
2597
+ 'unknown_slug', 'reserved_slug', 'duplicate_slug', 'history_migrating', 'target_state_conflict', 'internal_error',
2486
2598
  ], transport: 'http',
2487
- notes: 'One transaction: the draft document and every app-role grant carrying the slug are rewritten, and the recorded history moves with ' +
2488
- 'the name without rewriting any stored sample, so a rename takes the same time however much history there is. Samples the robot ' +
2599
+ notes: 'One transaction: the draft document and every app lock that lists the slug are rewritten, and the recorded history moves with ' +
2600
+ 'the name without rewriting any stored sample, so a rename takes the same time however much history there is. Locks follow the ' +
2601
+ 'rename: a lock that listed the old slug lists the new one as well, in every app of the organization, so a locked capability stays ' +
2602
+ 'locked; the old name stays in the lock until the next `PUT /api/apps/:id/access`, and `rewritten_locks` counts the locks touched. A ' +
2603
+ 'lock that would grow past the most slugs it can hold refuses the whole rename with `409 target_state_conflict` naming `to` (rule ' +
2604
+ '`lock_full`); nothing is written. Samples the robot ' +
2489
2605
  'still sends under the old slug until the next publish join the renamed history. The published configuration is immutable, so ' +
2490
2606
  '`requires_publish` says the rename is not live on the robot yet. A draft that is not a document is `409 draft_not_a_document` — the ' +
2491
2607
  'same word the usage preview uses for the same state. While the recorded history is being migrated the rename is refused with ' +
@@ -2504,7 +2620,7 @@ export const ROUTES = [
2504
2620
  notes: 'A draft that is valid YAML but not a Fleetless document is refused rather than answered with `alert_count: 0`: the two states are ' +
2505
2621
  '*this slug has no alerts* and *there is no document to ask*, and a zero cannot tell them apart — it would show a smaller blast radius ' +
2506
2622
  'than the rename actually has. The other three counts are real whatever the draft holds, and a partial answer to a preview whose whole ' +
2507
- 'purpose is to be complete is not worth the ambiguity.',
2623
+ 'purpose is to be complete is not worth the ambiguity. `lock_count` counts the app locks the rename would extend with the new name.',
2508
2624
  },
2509
2625
  /* -------------------------------------------------------------- alerts */
2510
2626
  {
@@ -2591,7 +2707,7 @@ export const ROUTES = [
2591
2707
  params: [{ name: 'id', description: 'The robot\'s uuid; an end user reaches it through an app that attaches it.' }],
2592
2708
  query: jobRunQuery, request: null, response: jobRunListResponse,
2593
2709
  errors: [...CLIENT_GUARD, 'invalid_uuid', 'not_found', 'capability_required', 'validation_error'], transport: 'http',
2594
- notes: 'Needs the `action_history` capability, and **this route is what makes that switch mean something** — it was unkeepable while nothing ' +
2710
+ notes: 'Needs the `job_history` capability, and **this route is what makes that switch mean something** — it was unkeepable while nothing ' +
2595
2711
  'durable recorded what had run. Two residuals worth stating rather than implying away. `history` is a syntactically valid slug, and ' +
2596
2712
  'a static segment matches before a parameter, so a robot with a service literally slugged `history` can no longer be **read** through ' +
2597
2713
  '`GET /api/robots/:id/jobs/:slug`; invoking, cancelling and the listing are unaffected. And a run row names its actor by email address, ' +
@@ -2611,7 +2727,7 @@ export const ROUTES = [
2611
2727
  ...CLIENT_GUARD, 'invalid_uuid', 'not_found', 'validation_error', 'parameter_invalid',
2612
2728
  'robot_offline', 'busy', 'bridge_timeout', 'internal_error',
2613
2729
  ], transport: 'http',
2614
- notes: '**One route for both kinds**, because a path segment naming the kind would demand a fact a role grant does not carry. An action answers ' +
2730
+ notes: '**One route for both kinds**, because a path segment naming the kind would demand a fact the rights model does not carry. An action answers ' +
2615
2731
  '`202` with an `invokeResponse` the moment the job exists; a service answers `200` with a `serviceCallResponse` once the result is in — ' +
2616
2732
  'two shapes, carried by one union (`invokeOrServiceResponse`) and told apart by whether `kind` or a bare `result` arrives. Parameters are checked **before** anything about the world (offline, busy): ' +
2617
2733
  'the same request must get the same verdict whether or not the robot happens to be reachable, or a developer testing against an offline ' +
@@ -2905,7 +3021,11 @@ export const ROUTES = [
2905
3021
  'because the same address in two apps is two accounts, and that sum is the number the four routes that create an app user refuse ' +
2906
3022
  '`409 quota_exceeded` against: `POST /api/apps/:id/users`, `POST /api/client/register`, `POST /api/client/invitations/accept`, and a ' +
2907
3023
  'federated sign-in that would create an account, which carries `quota_exceeded` back to the app as its error redirect. A gauge nothing ' +
2908
- 'enforces is a number that reads as a limit and is not one.',
3024
+ 'enforces is a number that reads as a limit and is not one. \n\n' +
3025
+ '`collection_records` and `collection_bytes` are the plan limits of the same names, `null` when the plan leaves them to the contract, and ' +
3026
+ 'their usage counts the **current** records of all the org\'s apps; a write or an import that would add data past either is refused ' +
3027
+ '`409 plan_limit` naming the key, and reads continue. `collection_history_bytes` is the size of the history and only informs: nothing ' +
3028
+ 'is refused against it. A usage figure the cloud does not measure is absent, never `0`.',
2909
3029
  },
2910
3030
  {
2911
3031
  method: 'GET', path: '/api/org/health', section: 'org',
@@ -3283,6 +3403,403 @@ export const ROUTES = [
3283
3403
  'robot inside that same hook, which is why `rateLimited` is `false`: there is no rate-limiting preHandler registered on this route. The ' +
3284
3404
  'URDF itself is never refused for the store; only meshes and textures are charged against it.',
3285
3405
  },
3406
+ /* ------------------------------------------------------ app collections */
3407
+ {
3408
+ method: 'GET', path: '/api/apps/:id/collections', section: 'collections',
3409
+ summary: 'Lists the collections of the published schema with their binding, counts, readers and warnings.',
3410
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3411
+ params: [COLLECTIONS_APP], query: null, request: null, response: collectionListResponse,
3412
+ errors: [...COLLECTIONS_DEVELOPER], transport: 'http',
3413
+ notes: "Per collection: the binding, how many records and fields it has, the roles that may read it, the size of its history and the warnings " +
3414
+ "(`no_role_access`, `unknown_role`, `history_growing`). `version` is `null` and the list empty until a schema has been published. \n\n" +
3415
+ COLLECTIONS_RIGHTS + " \n\n" + COLLECTIONS_UNKNOWN,
3416
+ },
3417
+ {
3418
+ method: 'GET', path: '/api/apps/:id/collections/schema/draft', section: 'collections',
3419
+ summary: "Reads the app's schema draft, or the published version's text when there is no draft.",
3420
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3421
+ params: [COLLECTIONS_APP], query: null, request: null, response: collectionsDraftResponse,
3422
+ errors: [...COLLECTIONS_DEVELOPER], transport: 'http',
3423
+ notes: "`source` is the text a developer edits: the saved draft; without one, the text of the published version; before the first publish, " +
3424
+ "empty. `updated_at: null` says no draft is saved. `doc` is the parsed document, `null` for empty text. \n\n" +
3425
+ "**Developers only.** The schema routes (draft, preview, publish, versions, restore) can be used by a developer and by nobody else: no app " +
3426
+ "role and no server key can be granted them, which is why none of them has a twin under `/api/client`. Rights for the records of the " +
3427
+ "collections are written in the schema itself, as `access` on each collection, and take effect when it is published.",
3428
+ },
3429
+ {
3430
+ method: 'PUT', path: '/api/apps/:id/collections/schema/draft', section: 'collections',
3431
+ summary: 'Replaces the schema draft with a whole document and answers what was found in it.',
3432
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3433
+ params: [COLLECTIONS_APP], query: null, request: putCollectionsDraftRequest, response: collectionsDraftResponse,
3434
+ errors: [...COLLECTIONS_DEVELOPER, 'validation_error'], transport: 'http',
3435
+ notes: "The request carries the document as YAML or JSON text. **Unlike a robot's configuration draft, a document with errors is refused**: " +
3436
+ "`400 validation_error`, with `details.fields` naming each error by its path in the document. A syntax error is refused the same way. " +
3437
+ "What is saved comes back with its warnings and information in `issues`, such as an `access` that names a role the organization does not have. " +
3438
+ "Saving the text of the published version again discards the draft, and `updated_at` is `null`.",
3439
+ },
3440
+ {
3441
+ method: 'DELETE', path: '/api/apps/:id/collections/schema/draft', section: 'collections',
3442
+ summary: 'Discards the schema draft.',
3443
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 204,
3444
+ params: [COLLECTIONS_APP], query: null, request: null, response: null,
3445
+ errors: [...COLLECTIONS_DEVELOPER], transport: 'http',
3446
+ notes: "The next `GET` of the draft answers the text of the published version again. The published version and the records are not touched.",
3447
+ },
3448
+ {
3449
+ method: 'GET', path: '/api/apps/:id/collections/schema/preview', section: 'collections',
3450
+ summary: 'Computes what publishing the draft would do to the data as it is now.',
3451
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3452
+ params: [COLLECTIONS_APP], query: null, request: null, response: collectionsSchemaPreview,
3453
+ errors: [...COLLECTIONS_DEVELOPER], transport: 'http',
3454
+ notes: "`effects` lists what would happen to existing records: collections removed or started again, fields removed or converted, values " +
3455
+ "dropped, defaults filled. An effect that would change nothing is not listed, so an empty list means publishing touches no data. " +
3456
+ "`access_changes` and the warnings in `issues` are information and need no confirmation. `token` stands for exactly the effects listed, on " +
3457
+ "exactly this draft text and the version in force, and is `null` when there are no effects. `source_sha256` is the hash of the draft text " +
3458
+ "that was previewed, for a publish to name even when there is no token. Nothing is written. Without a saved draft there is nothing to " +
3459
+ "preview: `404 not_found`.",
3460
+ },
3461
+ {
3462
+ method: 'POST', path: '/api/apps/:id/collections/schema/publish', section: 'collections',
3463
+ summary: 'Publishes the draft as the next schema version.',
3464
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3465
+ params: [COLLECTIONS_APP], query: null, request: collectionsPublishRequest, requestOptional: true, response: collectionsPublishResponse,
3466
+ errors: [...COLLECTIONS_DEVELOPER, 'validation_error', 'confirmation_required'], transport: 'http',
3467
+ notes: "A publish whose preview lists no effects needs no body. One with effects needs the `token` of the current preview as `confirm`; a " +
3468
+ "missing or outdated token is `409 confirmation_required` with the current preview, and its new token, in `details.preview`, and nothing is " +
3469
+ "changed. If the data changed between the preview and the publish so that the effects differ, or somebody saved the draft again, the token is " +
3470
+ "outdated and the caller confirms the new preview. To be sure that the draft published is the draft that was looked at, also when there are no " +
3471
+ "effects and so no token, send the preview's `source_sha256`: a draft with another text is not published, and the answer is " +
3472
+ "`409 confirmation_required` with the current preview. The new version, every effect on records with its revisions, and the audit entry `collection_schema.published` " +
3473
+ "are written in one transaction or not at all. Afterwards every socket with a collection subscription in the app receives " +
3474
+ "`collections_schema_published`, and subscriptions whose rights or collection are gone end. What the platform does itself, such as filling " +
3475
+ "in defaults or creating the records of a collection with one record per robot, is never refused for a plan limit.",
3476
+ },
3477
+ {
3478
+ method: 'GET', path: '/api/apps/:id/collections/schema/versions', section: 'collections',
3479
+ summary: 'Lists the published schema versions, newest first.',
3480
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3481
+ params: [COLLECTIONS_APP], query: null, request: null, response: collectionsVersionsResponse,
3482
+ errors: [...COLLECTIONS_DEVELOPER], transport: 'http',
3483
+ notes: "`current` is the version in force, `null` before the first publish. Each version says who published it, when, how many records or values its " +
3484
+ "effects touched and whether restoring it can also put records back (`restore_with_data`). A version that a restore published says whether that " +
3485
+ "restore also put records back (`with_data`) and, if it did, how many changes were reverted, records came back or were deleted, and records " +
3486
+ "of deleted robots stayed lost (`reverted_totals`). Versions are kept for the life of the app.",
3487
+ },
3488
+ {
3489
+ method: 'GET', path: '/api/apps/:id/collections/schema/versions/:v', section: 'collections',
3490
+ summary: 'Reads one published version: its document and the text it was published from.',
3491
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3492
+ params: [COLLECTIONS_APP, COLLECTIONS_VERSION], query: null, request: null, response: collectionsVersionResponse,
3493
+ errors: [...COLLECTIONS_DEVELOPER], transport: 'http',
3494
+ notes: "A `:v` that is not a positive whole number of at most nine digits and one that names no version of this app are the same `404 not_found`.",
3495
+ },
3496
+ {
3497
+ method: 'GET', path: '/api/apps/:id/collections/schema/versions/:v/restore-preview', section: 'collections',
3498
+ summary: 'Computes what restoring a version would do, optionally including the records.',
3499
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3500
+ params: [COLLECTIONS_APP, COLLECTIONS_VERSION], query: collectionsRestorePreviewQuery, request: null, response: collectionsRestorePreview,
3501
+ errors: [...COLLECTIONS_DEVELOPER, 'validation_error'], transport: 'http',
3502
+ notes: "Without `data` a restore publishes the version's document with the ordinary effects of a publish. With `data=true` it also puts records back to " +
3503
+ "their state at the version's **restore point**, the moment before the version that replaced it was published, **only in the collections the " +
3504
+ "schema difference between the current version and this one touches**; the others keep their data. `collections` deselects some of those. " +
3505
+ "`data_possible` and `data_reason` say whether that can be done at all: not when the restore point is more than 90 days old, not after an owner purged the " +
3506
+ "history it needs, not for the current version. Asking for the records when they cannot come back is `400 validation_error`. Records of robots " +
3507
+ "that were deleted since cannot come back and are counted in `robots_gone`. `token` is `null` when the restore would change no data. A `:v` " +
3508
+ "that is not a version of this app is `404 not_found`.",
3509
+ },
3510
+ {
3511
+ method: 'POST', path: '/api/apps/:id/collections/schema/versions/:v/restore', section: 'collections',
3512
+ summary: 'Restores a version by publishing its document as a new version, optionally with its records.',
3513
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3514
+ params: [COLLECTIONS_APP, COLLECTIONS_VERSION], query: null, request: collectionsRestoreRequest, requestOptional: true, response: collectionsRestoreResponse,
3515
+ errors: [...COLLECTIONS_DEVELOPER, 'validation_error', 'confirmation_required'], transport: 'http',
3516
+ notes: "Send the `data` and `collections` of the preview together with its `token` as `confirm`; confirmation works as for a publish, " +
3517
+ "including the `409 confirmation_required` answer with the current preview. Changes made since the restore point are reverted by new " +
3518
+ "revisions, so they stay in the history and can be restored one by one. The restore is itself a version and can be undone by restoring the " +
3519
+ "version before it. Every key of the body is optional, so a restore of the document alone needs no body. Audited as `collection_schema.restored`.",
3520
+ },
3521
+ {
3522
+ method: 'POST', path: '/api/apps/:id/collections/history/purge-preview', section: 'collections',
3523
+ summary: 'Computes what removing the history older than a date would remove.',
3524
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
3525
+ params: [COLLECTIONS_APP], query: null, request: collectionsPurgeRequest, response: collectionsPurgePreview,
3526
+ errors: [...DEVELOPER_GUARD, 'tier_required', 'support_forbidden', 'invalid_uuid', 'not_found', 'validation_error'], transport: 'http',
3527
+ notes: "**Owner tier**: an organization owner, not a developer and not an app user. A developer is answered `403 tier_required`. The body is the one the purge " +
3528
+ "takes; this call never removes anything. It counts the revisions older than `before` and their size, and names the schema versions whose " +
3529
+ "records could no longer be put back: those whose records could be put back today and could not afterwards, judged like `restore_with_data` of " +
3530
+ "the version list, and for the purge of one collection only the versions whose restore touches it. `before` must be in the past " +
3531
+ "(`400 validation_error`, field `before`, rule `not_in_past`), and a date that would remove nothing is refused as well (rule " +
3532
+ "`nothing_to_purge`). A support session is answered `403 support_forbidden`. Current values of records are never touched. Purging history is " +
3533
+ "not offered through MCP.",
3534
+ },
3535
+ {
3536
+ method: 'POST', path: '/api/apps/:id/collections/history/purge', section: 'collections',
3537
+ summary: 'Removes the history older than a date, for one collection or the whole app.',
3538
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: true, status: 200,
3539
+ params: [COLLECTIONS_APP], query: null, request: collectionsPurgeRequest, response: collectionsPurgeResponse,
3540
+ errors: [...DEVELOPER_GUARD, 'tier_required', 'support_forbidden', 'invalid_uuid', 'not_found', 'validation_error', 'confirmation_required'], transport: 'http',
3541
+ notes: "**Owner tier.** Always confirmed: the `token` of the preview goes in `confirm`, and an outdated one is `409 confirmation_required` with the " +
3542
+ "current preview. The purge is audited as `collection_history.purged` and recorded for good with the collection, independent of how long the " +
3543
+ "audit log is kept: the history of every affected record starts with a note saying who removed what, which the history answers as `purged`. " +
3544
+ "The refusals of the preview apply (`not_in_past`, `nothing_to_purge`), and a support session is answered `403 support_forbidden`.",
3545
+ },
3546
+ {
3547
+ method: 'GET', path: '/api/apps/:id/collections/:c/records', section: 'collections',
3548
+ summary: 'Lists the records of a collection, filtered, searched and sorted.',
3549
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3550
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY], query: collectionRecordListQuery, request: null, response: collectionRecordListResponse,
3551
+ errors: [...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'robot_not_attached'], transport: 'http',
3552
+ notes: "A developer has every right, so here `404 collection_not_found` only means that the published schema has no collection with that key. App " +
3553
+ "users and server keys use `/api/client/collections`, where `access` in the schema decides what each may do with a collection's records. " +
3554
+ "Records of a collection that belongs to robots are those of robots the app has attached; a detached robot's records are kept and hidden until " +
3555
+ "it is attached again. \n\n" +
3556
+ "`filter` is JSON text, `sort` takes up to three fields and breaks ties by `id`, `limit` is at most 500, and `next_cursor` is `null` on the last " +
3557
+ "page. `robot=<id>` finds the record of one robot in a collection with one record per robot. " +
3558
+ "`deleted=true` lists deleted records instead, newest deletion first, each with `deleted_at` and `deleted_by`, which a live record does not have. " +
3559
+ "A filter that breaks the grammar, an unknown field or a cursor that does not belong to this query is `400 validation_error` naming the path. \n\n" +
3560
+ COLLECTIONS_PAGES,
3561
+ },
3562
+ {
3563
+ method: 'POST', path: '/api/apps/:id/collections/:c/records', section: 'collections',
3564
+ summary: 'Creates a record.',
3565
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 201,
3566
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY], query: null, request: collectionRecordWrite, response: collectionRecord,
3567
+ errors: [
3568
+ ...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'required_missing', 'reference_invalid', 'robot_not_attached', 'plan_limit', 'rate_limited',
3569
+ ], transport: 'http',
3570
+ notes: "`values` holds the fields by key; defaults fill the fields left out. A collection that belongs to robots needs the `robot_id` of a robot the app has " +
3571
+ "attached (`400 robot_not_attached`). A collection with one record per robot never creates or deletes records through the API: they come " +
3572
+ "with the robots, and the attempt is `400 validation_error` with `rule: one_per_robot_is_automatic`. A required field with no value is " +
3573
+ "`400 required_missing`, a reference that does not hold is `400 reference_invalid`, a value taken by another record of a unique field " +
3574
+ "is `400 validation_error` with `rule: unique`. " + COLLECTIONS_RECORD_SIZE + " Over the plan's record or byte limit " +
3575
+ "the answer is `409 plan_limit`. \n\n" +
3576
+ "Writes are limited to 600 a minute for the app and 120 for one caller; above that the answer is `429 rate_limited` with `retry_after_ms` in " +
3577
+ "the details and a `Retry-After` header in seconds. Audited as `collection_record.created`.",
3578
+ },
3579
+ {
3580
+ method: 'GET', path: '/api/apps/:id/collections/:c/records/:rid', section: 'collections',
3581
+ summary: 'Reads one record.',
3582
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3583
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY, COLLECTIONS_RECORD], query: collectionRecordGetQuery, request: null, response: collectionRecord,
3584
+ errors: [...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error'], transport: 'http',
3585
+ notes: "A record that is deleted, of another collection or of a robot the app has not attached reads exactly like one that never existed: `404 not_found`. " +
3586
+ "Deleted records are found with `deleted=true` on the list. `expand` works as on the list: a reference field named in it holds the referenced record " +
3587
+ "instead of its id, one hop deep; a name that is not a reference field is `400 validation_error`.",
3588
+ },
3589
+ {
3590
+ method: 'PATCH', path: '/api/apps/:id/collections/:c/records/:rid', section: 'collections',
3591
+ summary: 'Changes some fields of a record.',
3592
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3593
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY, COLLECTIONS_RECORD], query: null, request: collectionRecordWrite, response: collectionRecord,
3594
+ errors: [
3595
+ ...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'required_missing', 'reference_invalid', 'record_changed', 'plan_limit', 'rate_limited',
3596
+ ], transport: 'http',
3597
+ notes: "Only the fields sent change; `null` clears a field. With `expected_revision`, a record that has moved on is `409 record_changed` with its " +
3598
+ "current `revision` in the details, and nothing is changed. Clearing a required field is `400 required_missing`; a record whose required fields " +
3599
+ "were emptied by a schema change can still be updated in its other fields. The `robot_id` of a record never changes: sending it is " +
3600
+ "`400 validation_error`. " + COLLECTIONS_RECORD_SIZE + " An update that makes the record bigger can be refused with `409 plan_limit`; one that " +
3601
+ "makes it smaller never is. Audited as `collection_record.updated`.",
3602
+ },
3603
+ {
3604
+ method: 'DELETE', path: '/api/apps/:id/collections/:c/records/:rid', section: 'collections',
3605
+ summary: 'Deletes a record.',
3606
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 204,
3607
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY, COLLECTIONS_RECORD], query: null, request: null, response: null,
3608
+ errors: [...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'record_referenced', 'rate_limited'], transport: 'http',
3609
+ notes: "A record that other records point at through a reference with `on_delete: prevent` is not deleted: `409 record_referenced`, with the collections " +
3610
+ "that point at it, among those the caller may read, and how many records each has, never their ids or values. With `on_delete: clear` those " +
3611
+ "references are cleared, each as " +
3612
+ "a revision. The record stays in the history, with all its values, and can be restored. A collection with one record per robot " +
3613
+ "refuses a delete with `400 validation_error`. Audited as `collection_record.deleted`.",
3614
+ },
3615
+ {
3616
+ method: 'GET', path: '/api/apps/:id/collections/:c/records/:rid/history', section: 'collections',
3617
+ summary: "Reads a record's history, newest first.",
3618
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3619
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY, COLLECTIONS_RECORD], query: collectionRecordHistoryQuery, request: null, response: collectionRecordHistoryResponse,
3620
+ errors: [...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error'], transport: 'http',
3621
+ notes: "Each revision names the operation, the actor, the time, the reason when the change was not an ordinary write (`schema v5`, `import`, `restore v4`) " +
3622
+ "and the fields it changed with their old and new value; a `delete` revision carries the whole record. The history also answers for a " +
3623
+ "deleted record. `purged` is set when an organization owner removed the older part of it. Page with `before_seq`. Reads are not audited. \n\n" +
3624
+ COLLECTIONS_HISTORY_PAGES,
3625
+ },
3626
+ {
3627
+ method: 'POST', path: '/api/apps/:id/collections/:c/records/:rid/restore', section: 'collections',
3628
+ summary: 'Puts a record back to an earlier revision, or brings a deleted record back.',
3629
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3630
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY, COLLECTIONS_RECORD], query: null, request: collectionRecordRestoreRequest, requestOptional: true, response: collectionRecord,
3631
+ errors: [...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'plan_limit', 'rate_limited'], transport: 'http',
3632
+ notes: "With `seq`, the record gets the values it had after that revision; without it, a deleted record comes back as it was deleted, with its id. " +
3633
+ "Fields that the schema no longer has and values that no longer validate are dropped, and a value that is now taken by another record of a " +
3634
+ "unique field is refused with `400 validation_error`. The restore is a new revision (`op: restore`), never a rewrite of the history. " +
3635
+ "Audited as `collection_record.restored`.",
3636
+ },
3637
+ {
3638
+ method: 'POST', path: '/api/apps/:id/collections/:c/import/preview', section: 'collections',
3639
+ summary: 'Checks a file of records against a collection and answers what importing it would do.',
3640
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3641
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY], query: null, request: collectionImportRequest, response: collectionImportPreview,
3642
+ errors: [...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'robot_not_attached', 'rate_limited'], transport: 'http',
3643
+ notes: "CSV (UTF-8, a header row, RFC 4180; a `json` field as JSON text) or a JSON array of objects, at most 10 MB and 50,000 rows; more is " +
3644
+ "`400 validation_error`. Nothing is written. `counts` says how many records would be unchanged, new, updated and deleted. Every problem is " +
3645
+ "listed with its row, column, value and reason, up to 1,000 of them; one invalid row, a reference that cannot be resolved, a plan limit " +
3646
+ "that would be exceeded or a deletion that a `prevent` reference blocks fails the whole import. `token` is `null` while there are errors. " +
3647
+ "In `mirror` mode, `mirror_scope: collection` means every record not in the file would be deleted: show it prominently. A `confirm` sent to " +
3648
+ "this route is ignored. " + COLLECTIONS_IMPORT_CELLS + " \n\n" + COLLECTIONS_IMPORT_LIMITS,
3649
+ },
3650
+ {
3651
+ method: 'POST', path: '/api/apps/:id/collections/:c/import', section: 'collections',
3652
+ summary: 'Imports a file of records, all or nothing, once the preview has been confirmed.',
3653
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3654
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY], query: null, request: collectionImportRequest, response: collectionImportResult,
3655
+ errors: [
3656
+ ...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'robot_not_attached', 'confirmation_required', 'plan_limit', 'rate_limited',
3657
+ ], transport: 'http',
3658
+ notes: "The same body as the preview, with the preview's `token` as `confirm`. **Without `confirm` nothing is imported and the answer is `200` with " +
3659
+ "the preview**, the body of the preview route and not an import result. With a token that is not the one of the current preview, because the " +
3660
+ "data moved on or it belongs to another import, nothing is imported and the answer is `409 confirmation_required` with the current preview in " +
3661
+ "`details.preview`. A file with errors is never imported: its preview, with `token: null`, comes back whatever `confirm` says. The token " +
3662
+ "stands for the file and its settings, the counts, the records the import would match with their revisions and the ones a mirror would delete. " +
3663
+ "It is not single-use, so a keyless import confirmed twice creates its rows twice: look at the collection before repeating a confirmation " +
3664
+ "whose answer was lost. A confirmed import runs in one " +
3665
+ "transaction: either every row is written, with revisions whose reason is `import`, or none is. It counts as one write for the rate limit " +
3666
+ "however many rows it has, and is audited once as `collection_import.completed`. Records the import adds can take the organization over its " +
3667
+ "plan's limit: `409 plan_limit`. On a single-organization instance whose licence has lapsed (read-only administration) it is " +
3668
+ "`423 instance_read_only`; the preview is not. \n\n" + COLLECTIONS_IMPORT_LIMITS,
3669
+ },
3670
+ {
3671
+ method: 'GET', path: '/api/apps/:id/collections/:c/export', section: 'collections',
3672
+ summary: 'Downloads the records of a collection as a CSV or JSON file.',
3673
+ audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
3674
+ params: [COLLECTIONS_APP, COLLECTIONS_KEY], query: collectionExportQuery, request: null, response: null, contentType: 'text/csv',
3675
+ errors: [...COLLECTIONS_DEVELOPER, 'collection_not_found', 'validation_error', 'robot_not_attached'], transport: 'http',
3676
+ notes: "Answers `text/csv; charset=utf-8` as an attachment, or, with `format=json`, an attachment of `application/json`: an array of objects. Either way " +
3677
+ "there is no response schema. The filter, search and sort are those of the record list, so the file holds what the list showed. The columns " +
3678
+ "are `robot` (the robot's name) first in a collection that belongs to robots, then the fields, then with `system=true` `robot_id` (robot-bound " +
3679
+ "collections), `id`, `created_at`, `created_by`, `updated_at`, `updated_by` and `revision`, where `created_by` and `updated_by` are the " +
3680
+ "actors' labels. `references` writes reference fields as ids, or as a unique field of the target, so that the file can be imported again; a " +
3681
+ "reference field whose target has no such unique field is `400 validation_error` (field `references`, rule `not_unique`). A cell that could " +
3682
+ "be read as a formula gets an apostrophe in front, which an import takes off again. Reads and exports are not audited.",
3683
+ },
3684
+ /* ---- the same collections for app users and server keys, under /api/client */
3685
+ {
3686
+ method: 'GET', path: '/api/client/collections', section: 'collections',
3687
+ summary: 'Lists the collections the caller may read, with their fields and what the caller may do with them.',
3688
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3689
+ params: [], query: null, request: null, response: collectionDefinitionsResponse,
3690
+ errors: [...CLIENT_GUARD], transport: 'http',
3691
+ notes: "Everything an app needs to draw a form: for each readable collection its fields, its display template and `can`, what this caller may " +
3692
+ "do with its records. A collection the caller cannot read is absent. The caller is an app user or a server key of the app; **a developer's " +
3693
+ "bearer is answered `403 forbidden`**, because developers use `/api/apps/:id/collections`. \n\n" +
3694
+ COLLECTIONS_RIGHTS + " \n\n" + COLLECTIONS_UNKNOWN,
3695
+ },
3696
+ {
3697
+ method: 'GET', path: '/api/client/collections/:c/records', section: 'collections',
3698
+ summary: 'Lists the records of a collection the caller may read, filtered, searched and sorted.',
3699
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3700
+ params: [COLLECTIONS_KEY_CLIENT], query: collectionRecordListQuery, request: null, response: collectionRecordListResponse,
3701
+ errors: [...COLLECTIONS_CLIENT_COLLECTION, 'validation_error', 'robot_not_attached'], transport: 'http',
3702
+ notes: "The twin of `GET /api/apps/:id/collections/:c/records`, for the app the bearer belongs to. " +
3703
+ COLLECTIONS_UNKNOWN + " Records of a collection that belongs to robots are those of robots the app has attached and the caller's role " +
3704
+ "reaches; asking for another robot is `400 robot_not_attached`. With `expand`, a referenced record is embedded only when the caller may " +
3705
+ "read its collection; otherwise the field keeps the id. `deleted=true` needs the right to create, and lists each record with `deleted_at` and " +
3706
+ "`deleted_by`. \n\n" + COLLECTIONS_PAGES + " \n\n" + COLLECTIONS_NOT_FOR_DEVELOPERS,
3707
+ },
3708
+ {
3709
+ method: 'POST', path: '/api/client/collections/:c/records', section: 'collections',
3710
+ summary: 'Creates a record in a collection the caller may create in.',
3711
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 201,
3712
+ params: [COLLECTIONS_KEY_CLIENT], query: null, request: collectionRecordWrite, response: collectionRecord,
3713
+ errors: [
3714
+ ...COLLECTIONS_CLIENT_COLLECTION, 'validation_error', 'required_missing', 'reference_invalid', 'robot_not_attached', 'plan_limit', 'rate_limited',
3715
+ ], transport: 'http',
3716
+ notes: "The twin of `POST /api/apps/:id/collections/:c/records`, with the same rules and limits. The caller needs the right to create in `access`. " +
3717
+ "An app user who sets a reference must be allowed to read the target collection, otherwise `400 reference_invalid` with the reason " +
3718
+ "`not_readable`. The record's `created_by` is the caller; it is what `own` compares later. " + COLLECTIONS_RECORD_SIZE + " \n\n" +
3719
+ COLLECTIONS_NOT_FOR_DEVELOPERS,
3720
+ },
3721
+ {
3722
+ method: 'GET', path: '/api/client/collections/:c/records/:rid', section: 'collections',
3723
+ summary: 'Reads one record the caller may read.',
3724
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3725
+ params: [COLLECTIONS_KEY_CLIENT, COLLECTIONS_RECORD], query: collectionRecordGetQuery, request: null, response: collectionRecord,
3726
+ errors: [...COLLECTIONS_CLIENT, 'validation_error'], transport: 'http',
3727
+ notes: "A record of a robot the caller does not reach reads exactly like one that does not exist: `404 not_found`. `expand` works as on the list: " +
3728
+ "a referenced record is embedded only when the caller may read its collection, otherwise the field keeps the id; a name that is not a " +
3729
+ "reference field is `400 validation_error`. " + COLLECTIONS_NOT_FOR_DEVELOPERS,
3730
+ },
3731
+ {
3732
+ method: 'PATCH', path: '/api/client/collections/:c/records/:rid', section: 'collections',
3733
+ summary: 'Changes some fields of a record the caller may update.',
3734
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3735
+ params: [COLLECTIONS_KEY_CLIENT, COLLECTIONS_RECORD], query: null, request: collectionRecordWrite, response: collectionRecord,
3736
+ errors: [
3737
+ ...COLLECTIONS_CLIENT, 'validation_error', 'required_missing', 'reference_invalid', 'record_changed', 'plan_limit', 'rate_limited',
3738
+ ], transport: 'http',
3739
+ notes: "The twin of `PATCH /api/apps/:id/collections/:c/records/:rid`. Where `access` allows `update` for `own` records only, a record created " +
3740
+ "by someone else is `403 forbidden` for this caller. " + COLLECTIONS_RECORD_SIZE + " " + COLLECTIONS_NOT_FOR_DEVELOPERS,
3741
+ },
3742
+ {
3743
+ method: 'DELETE', path: '/api/client/collections/:c/records/:rid', section: 'collections',
3744
+ summary: 'Deletes a record the caller may delete.',
3745
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 204,
3746
+ params: [COLLECTIONS_KEY_CLIENT, COLLECTIONS_RECORD], query: null, request: null, response: null,
3747
+ errors: [...COLLECTIONS_CLIENT, 'validation_error', 'record_referenced', 'rate_limited'], transport: 'http',
3748
+ notes: "The twin of `DELETE /api/apps/:id/collections/:c/records/:rid`. `409 record_referenced` carries counts only, and names only collections the " +
3749
+ "caller may read, so a caller learns nothing about records in collections they may not read. " + COLLECTIONS_NOT_FOR_DEVELOPERS,
3750
+ },
3751
+ {
3752
+ method: 'GET', path: '/api/client/collections/:c/records/:rid/history', section: 'collections',
3753
+ summary: "Reads the history of a record the caller may update.",
3754
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3755
+ params: [COLLECTIONS_KEY_CLIENT, COLLECTIONS_RECORD], query: collectionRecordHistoryQuery, request: null, response: collectionRecordHistoryResponse,
3756
+ errors: [...COLLECTIONS_CLIENT, 'validation_error'], transport: 'http',
3757
+ notes: "Whoever may update a record may read its history; the right to read alone is not enough. With `own`, that is the records the caller created. " +
3758
+ COLLECTIONS_HISTORY_PAGES + " " + COLLECTIONS_NOT_FOR_DEVELOPERS,
3759
+ },
3760
+ {
3761
+ method: 'POST', path: '/api/client/collections/:c/records/:rid/restore', section: 'collections',
3762
+ summary: 'Puts a record back to an earlier revision, or brings a deleted record back.',
3763
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3764
+ params: [COLLECTIONS_KEY_CLIENT, COLLECTIONS_RECORD], query: null, request: collectionRecordRestoreRequest, requestOptional: true, response: collectionRecord,
3765
+ errors: [...COLLECTIONS_CLIENT, 'validation_error', 'plan_limit', 'rate_limited'], transport: 'http',
3766
+ notes: "The twin of `POST /api/apps/:id/collections/:c/records/:rid/restore`. Restoring a revision of a live record needs the right to update it; " +
3767
+ "bringing a deleted record back needs the right to create. Every key of the body is optional. " + COLLECTIONS_NOT_FOR_DEVELOPERS,
3768
+ },
3769
+ {
3770
+ method: 'POST', path: '/api/client/collections/:c/import/preview', section: 'collections',
3771
+ summary: 'Checks a file of records against a collection and answers what importing it would do.',
3772
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3773
+ params: [COLLECTIONS_KEY_CLIENT], query: null, request: collectionImportRequest, response: collectionImportPreview,
3774
+ errors: [...COLLECTIONS_CLIENT_COLLECTION, 'validation_error', 'robot_not_attached', 'rate_limited'], transport: 'http',
3775
+ notes: "The twin of `POST /api/apps/:id/collections/:c/import/preview`. **A server key only**: import and export are for developers and for the app's " +
3776
+ "server keys, so an app user is answered `403 forbidden` for any collection key, one that does not exist included, before the collection is " +
3777
+ "looked at. " + COLLECTIONS_NOT_FOR_DEVELOPERS + " \n\n" + COLLECTIONS_IMPORT_CELLS + " \n\n" + COLLECTIONS_IMPORT_LIMITS,
3778
+ },
3779
+ {
3780
+ method: 'POST', path: '/api/client/collections/:c/import', section: 'collections',
3781
+ summary: 'Imports a file of records, all or nothing, once the preview has been confirmed.',
3782
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3783
+ params: [COLLECTIONS_KEY_CLIENT], query: null, request: collectionImportRequest, response: collectionImportResult,
3784
+ errors: [
3785
+ ...COLLECTIONS_CLIENT_COLLECTION, 'validation_error', 'robot_not_attached', 'confirmation_required', 'plan_limit', 'rate_limited',
3786
+ ], transport: 'http',
3787
+ notes: "The twin of `POST /api/apps/:id/collections/:c/import`, with the same two-step confirmation: without `confirm` the answer is `200` with the " +
3788
+ "preview and nothing is imported, and the token is not single-use. **A server key only**; an app user is answered `403 forbidden` for any " +
3789
+ "collection key, one that does not exist included, before the collection is looked at. On a single-organization instance whose licence has " +
3790
+ "lapsed (read-only administration) it is `423 instance_read_only`, as the developer import is; the preview, single record writes and reads " +
3791
+ "stay allowed. " + COLLECTIONS_NOT_FOR_DEVELOPERS + " \n\n" + COLLECTIONS_IMPORT_LIMITS,
3792
+ },
3793
+ {
3794
+ method: 'GET', path: '/api/client/collections/:c/export', section: 'collections',
3795
+ summary: 'Downloads the records of a collection as a CSV or JSON file.',
3796
+ audience: 'client', auth: 'developer_or_client', rateLimited: false, ownerTier: false, status: 200,
3797
+ params: [COLLECTIONS_KEY_CLIENT], query: collectionExportQuery, request: null, response: null, contentType: 'text/csv',
3798
+ errors: [...COLLECTIONS_CLIENT_COLLECTION, 'validation_error', 'robot_not_attached'], transport: 'http',
3799
+ notes: "The twin of `GET /api/apps/:id/collections/:c/export`: `text/csv; charset=utf-8` as an attachment, or JSON when `format=json`. **A server key " +
3800
+ "only**; an app user is answered `403 forbidden` for any collection key, one that does not exist included, before the collection is looked at. " +
3801
+ "A server key exports the records of the robots the app has attached. " + COLLECTIONS_NOT_FOR_DEVELOPERS,
3802
+ },
3286
3803
  /* ------------------------------------ realtime and bridge transports */
3287
3804
  {
3288
3805
  method: 'GET', path: '/bridge', section: 'transports',
@@ -3292,9 +3809,17 @@ export const ROUTES = [
3292
3809
  },
3293
3810
  {
3294
3811
  method: 'GET', path: '/realtime', section: 'transports',
3295
- summary: 'The client WebSocket: subscriptions on datapoints, jobs, bridge state and presence, plus full command parity with REST.',
3812
+ summary: 'The client WebSocket: subscriptions on datapoints (the built-in bridge state included), jobs, cameras and app collections, plus full command parity with REST.',
3296
3813
  audience: 'client', auth: 'none', rateLimited: false, ownerTier: false, status: 101,
3297
3814
  params: [], query: null, request: null, response: null, errors: ['invalid_token', 'rate_limited'], transport: 'websocket',
3298
- notes: 'Authentication happens in the first frame, not on the upgrade. The frame types are the `realtime` schemas.',
3815
+ notes: 'Authentication happens in the first frame, not on the upgrade. The frame types are the `realtime` schemas. ' +
3816
+ '\n\n**App collections.** `collection_subscribe` and `collection_unsubscribe` open and close a subscription to the records of one collection; ' +
3817
+ '`collection_subscribed` says that an accepted subscription is registered; `collection_event` carries `created`, `updated`, `deleted`, ' +
3818
+ '`removed` and `entered` with the whole record; `collection_subscribe_error` refuses a subscribe or ends a running subscription; ' +
3819
+ '`collections_schema_published` tells every socket with a subscription of the app that a version is in force. There is no snapshot: subscribe, ' +
3820
+ 'wait for `collection_subscribed`, then list, and no change can fall between the list and the events. A developer connection names the ' +
3821
+ 'app in `app_id`. A socket holds at most 50 collection subscriptions. A frame of more than 16,384 bytes closes the socket with 1009, and a ' +
3822
+ 'socket that falls too far behind (more than 8 MiB in its send buffer, or more than 2,000 collection changes waiting to be delivered, as a ' +
3823
+ 'bulk import into a big collection causes) is closed with 1013, "try again later": the client reconnects, subscribes, waits for `collection_subscribed` and lists again.',
3299
3824
  },
3300
3825
  ];