@fleetless/contracts 14.0.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 (119) hide show
  1. package/CHANGELOG.md +163 -0
  2. package/artifacts/openapi.json +19842 -11398
  3. package/artifacts/routes.json +1160 -39
  4. package/artifacts/schema/addon-catalogue-entry.schema.json +3 -1
  5. package/artifacts/schema/admin-plan-change-request.schema.json +26 -0
  6. package/artifacts/schema/app-deletion-summary.schema.json +15 -1
  7. package/artifacts/schema/asset-plan-limit-details.schema.json +3 -1
  8. package/artifacts/schema/cloud-config.schema.json +5 -5
  9. package/artifacts/schema/collection-actor.schema.json +35 -0
  10. package/artifacts/schema/collection-definitions-response.schema.json +612 -0
  11. package/artifacts/schema/collection-event.schema.json +216 -0
  12. package/artifacts/schema/collection-export-query.schema.json +56 -0
  13. package/artifacts/schema/collection-filter.schema.json +9 -0
  14. package/artifacts/schema/collection-import-preview.schema.json +143 -0
  15. package/artifacts/schema/collection-import-request.schema.json +105 -0
  16. package/artifacts/schema/collection-import-result.schema.json +38 -0
  17. package/artifacts/schema/collection-list-response.schema.json +119 -0
  18. package/artifacts/schema/collection-record-get-query.schema.json +12 -0
  19. package/artifacts/schema/collection-record-history-query.schema.json +35 -0
  20. package/artifacts/schema/collection-record-history-response.schema.json +389 -0
  21. package/artifacts/schema/collection-record-list-query.schema.json +67 -0
  22. package/artifacts/schema/collection-record-list-response.schema.json +212 -0
  23. package/artifacts/schema/collection-record-restore-request.schema.json +14 -0
  24. package/artifacts/schema/collection-record-write.schema.json +31 -0
  25. package/artifacts/schema/collection-record.schema.json +180 -0
  26. package/artifacts/schema/collection-revision.schema.json +295 -0
  27. package/artifacts/schema/collection-subscribe-error.schema.json +31 -0
  28. package/artifacts/schema/collection-subscribe.schema.json +48 -0
  29. package/artifacts/schema/collection-subscribed.schema.json +22 -0
  30. package/artifacts/schema/collection-summary.schema.json +92 -0
  31. package/artifacts/schema/collection-unsubscribe.schema.json +22 -0
  32. package/artifacts/schema/collections-access-change.schema.json +34 -0
  33. package/artifacts/schema/collections-document.schema.json +732 -0
  34. package/artifacts/schema/collections-draft-response.schema.json +845 -0
  35. package/artifacts/schema/collections-effect.schema.json +384 -0
  36. package/artifacts/schema/collections-issue.schema.json +36 -0
  37. package/artifacts/schema/collections-publish-request.schema.json +18 -0
  38. package/artifacts/schema/collections-publish-response.schema.json +450 -0
  39. package/artifacts/schema/collections-purge-preview.schema.json +60 -0
  40. package/artifacts/schema/collections-purge-request.schema.json +27 -0
  41. package/artifacts/schema/collections-purge-response.schema.json +30 -0
  42. package/artifacts/schema/collections-restore-preview-query.schema.json +20 -0
  43. package/artifacts/schema/collections-restore-preview.schema.json +581 -0
  44. package/artifacts/schema/collections-restore-request.schema.json +27 -0
  45. package/artifacts/schema/collections-restore-response.schema.json +455 -0
  46. package/artifacts/schema/collections-schema-preview.schema.json +519 -0
  47. package/artifacts/schema/collections-schema-published.schema.json +22 -0
  48. package/artifacts/schema/collections-version-response.schema.json +869 -0
  49. package/artifacts/schema/collections-version-summary.schema.json +139 -0
  50. package/artifacts/schema/collections-versions-response.schema.json +167 -0
  51. package/artifacts/schema/config-draft-response.schema.json +5 -5
  52. package/artifacts/schema/config-version-response.schema.json +5 -5
  53. package/artifacts/schema/confirmation-required-details.schema.json +13 -0
  54. package/artifacts/schema/dangling-reference.schema.json +7 -6
  55. package/artifacts/schema/datapoint-list-response.schema.json +2 -2
  56. package/artifacts/schema/effective-rights-response.schema.json +87 -1
  57. package/artifacts/schema/org-plan.schema.json +29 -1
  58. package/artifacts/schema/org-quota-usage-counts.schema.json +18 -0
  59. package/artifacts/schema/org-quota-usage.schema.json +47 -1
  60. package/artifacts/schema/org-quotas.schema.json +29 -1
  61. package/artifacts/schema/org-role-list-response.schema.json +8 -7
  62. package/artifacts/schema/org-role.schema.json +1 -1
  63. package/artifacts/schema/plan-catalogue-entry.schema.json +29 -1
  64. package/artifacts/schema/plan-change-decision-status-response.schema.json +29 -1
  65. package/artifacts/schema/plan-limit-details.schema.json +3 -1
  66. package/artifacts/schema/plan-limits.schema.json +29 -1
  67. package/artifacts/schema/plan-overrides.schema.json +26 -0
  68. package/artifacts/schema/put-collections-draft-request.schema.json +16 -0
  69. package/artifacts/schema/record-changed-details.schema.json +16 -0
  70. package/artifacts/schema/record-referenced-details.schema.json +35 -0
  71. package/artifacts/schema/reference-invalid-details.schema.json +25 -0
  72. package/artifacts/schema/reference-place.schema.json +7 -6
  73. package/artifacts/schema/required-missing-details.schema.json +19 -0
  74. package/artifacts/schema/robot-config-doc.schema.json +5 -5
  75. package/artifacts/schema/robot-deletion-summary.schema.json +33 -1
  76. package/artifacts/schema/role-collection-rights.schema.json +82 -0
  77. package/artifacts/schema/role-rename-preview.schema.json +7 -6
  78. package/dist/apps.d.ts +18 -2
  79. package/dist/apps.js +12 -2
  80. package/dist/audit.d.ts +32 -2
  81. package/dist/audit.js +40 -2
  82. package/dist/collections-issues.d.ts +67 -0
  83. package/dist/collections-issues.js +340 -0
  84. package/dist/collections-records.d.ts +562 -0
  85. package/dist/collections-records.js +525 -0
  86. package/dist/collections-rights.d.ts +17 -0
  87. package/dist/collections-rights.js +41 -0
  88. package/dist/collections-schema.d.ts +1064 -0
  89. package/dist/collections-schema.js +386 -0
  90. package/dist/collections-templates.d.ts +55 -0
  91. package/dist/collections-templates.js +137 -0
  92. package/dist/collections-transfer.d.ts +101 -0
  93. package/dist/collections-transfer.js +206 -0
  94. package/dist/collections-values.d.ts +67 -0
  95. package/dist/collections-values.js +284 -0
  96. package/dist/collections.d.ts +568 -0
  97. package/dist/collections.js +332 -0
  98. package/dist/config.d.ts +8 -8
  99. package/dist/config.js +13 -13
  100. package/dist/errors.d.ts +50 -1
  101. package/dist/errors.js +115 -0
  102. package/dist/index.d.ts +24 -8
  103. package/dist/index.js +13 -3
  104. package/dist/org-roles.d.ts +4 -0
  105. package/dist/org-roles.js +10 -9
  106. package/dist/plans.d.ts +19 -1
  107. package/dist/plans.js +21 -1
  108. package/dist/realtime.d.ts +166 -0
  109. package/dist/realtime.js +163 -0
  110. package/dist/rest.d.ts +28 -28
  111. package/dist/rest.js +39 -27
  112. package/dist/rights.d.ts +2 -2
  113. package/dist/rights.js +1 -1
  114. package/dist/routes.d.ts +1 -1
  115. package/dist/routes.js +495 -21
  116. package/package.json +1 -1
  117. package/artifacts/schema/put-robot-details-request.schema.json +0 -41
  118. package/artifacts/schema/put-robot-details-response.schema.json +0 -43
  119. package/artifacts/schema/robot-details-doc.schema.json +0 -33
package/dist/routes.js CHANGED
@@ -3,6 +3,9 @@ import { appAccess, appAccessResponse, appListResponse, appDeletionSummary, crea
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';
@@ -18,7 +21,7 @@ import { authorizationServerMetadata, dynamicClientRegistrationRequest, dynamicC
18
21
  import { adminPlanChangeRequest, orgPlan, planChangeRequest, planChangePrepareRequest, planChangeDecisionLookupQuery, planChangeDecisionStatusResponse } from './plans.js';
19
22
  import { supportRenewFailRequest, supportTokenRequest, supportTokenResponse } from './support.js';
20
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';
21
- 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';
22
25
  export const ROUTE_SECTIONS = [
23
26
  { id: 'health', title: 'Health' },
24
27
  { id: 'developer-auth', title: 'Developer auth' },
@@ -27,6 +30,7 @@ export const ROUTE_SECTIONS = [
27
30
  { id: 'billing', title: 'Billing' },
28
31
  { id: 'users', title: 'Team' },
29
32
  { id: 'apps', title: 'Apps' },
33
+ { id: 'collections', title: 'App collections' },
30
34
  { id: 'robots', title: 'Robots' },
31
35
  { id: 'config', title: 'Configuration (draft/publish)' },
32
36
  { id: 'alerts', title: 'Alerts' },
@@ -138,6 +142,68 @@ const MOLLIE = ['payment_provider_unavailable'];
138
142
  * two lists were kept as separate constants while they still read alike.
139
143
  */
140
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.\").";
141
207
  /**
142
208
  * **The steps of a developer sign-in, written once for both portal flows.**
143
209
  *
@@ -580,7 +646,8 @@ export const ROUTES = [
580
646
  audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
581
647
  params: [{ name: 'key', description: "The role's key, as listed by `GET /api/org/roles`; a key that names no role answers `404`." }],
582
648
  query: null, request: patchOrgRoleRequest, response: orgRole,
583
- errors: [...DEVELOPER_GUARD, 'validation_error', 'not_found', 'role_cycle', 'role_key_taken', 'confirmation_required'], transport: 'http',
649
+ errors: [...DEVELOPER_GUARD, 'validation_error', 'not_found', 'role_cycle', 'role_key_taken', 'confirmation_required', 'rate_limited'],
650
+ transport: 'http',
584
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 ' +
585
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 ' +
586
653
  'accepted at once; everything that still names the old key, in documents, assignments, invitations, default roles, other roles and ' +
@@ -589,8 +656,13 @@ export const ROUTES = [
589
656
  'rewritten, the document it is in, the version a published document would get, and a `confirm` token. A rename with no place to ' +
590
657
  'rewrite applies at once and needs no token. The second call repeats the same body with ' +
591
658
  '`confirm` set to that token and rewrites all of it in one transaction. Assignments and role rows change directly; each affected ' +
592
- 'published `fleetless.yaml` gets a new version that differs only in the key, and an existing draft is updated the same way. If the ' +
593
- 'places changed between the two calls, the token is stale and the second call answers a new preview instead of applying. A new key ' +
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 ' +
594
666
  'that another role has is `409 role_key_taken`.',
595
667
  },
596
668
  {
@@ -706,7 +778,8 @@ export const ROUTES = [
706
778
  query: null, request: null, response: null,
707
779
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
708
780
  notes: 'An app outside the caller\'s org answers `404`, as an unknown id does. A full cascade — its users, server keys, ' +
709
- 'invitations, OIDC provider configuration and mail templates all go, recorded once as `app.deleted` carrying an `appDeletionSummary`. ' +
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`. ' +
710
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 ' +
711
784
  '`GET /api/apps/:id/deletion-preview`.',
712
785
  },
@@ -798,7 +871,9 @@ export const ROUTES = [
798
871
  'Only the published configuration counts: a robot with nothing published has no exposures, and its `assets` and `job_history` follow ' +
799
872
  'the organization defaults. `reachable` says whether a session of the role reaches the robot at all; a robot it does not reach is ' +
800
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 ' +
801
- 'nothing granted, and so does a user who is not `active`. A user of another app answers `404`.',
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.',
802
877
  },
803
878
  /* -------------------------------------- the app's users and invitations */
804
879
  {
@@ -2363,7 +2438,7 @@ export const ROUTES = [
2363
2438
  errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found'], transport: 'http',
2364
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 ' +
2365
2440
  'receipt agree by construction, and any difference between them is real drift — a robot that kept recording in between — rather than two ' +
2366
- 'estimates that quietly disagree.',
2441
+ 'estimates that quietly disagree. `collection_records` counts, per app, the app collection records that go with the robot.',
2367
2442
  },
2368
2443
  {
2369
2444
  method: 'DELETE', path: '/api/robots/:id', section: 'robots',
@@ -2377,16 +2452,6 @@ export const ROUTES = [
2377
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 ' +
2378
2453
  'fails partway is `500 robot_deletion_partial` with the progress, never a bare `internal_error` that would read as "nothing happened".',
2379
2454
  },
2380
- {
2381
- method: 'PUT', path: '/api/robots/:id/details', section: 'robots',
2382
- summary: 'Replaces the developer-maintained details document shown alongside the robot.',
2383
- audience: 'developer', auth: 'developer', rateLimited: false, ownerTier: false, status: 200,
2384
- params: [{ name: 'id', description: 'The robot\'s uuid, as returned by `POST /api/robots` or listed by `GET /api/robots`.' }],
2385
- query: null, request: putRobotDetailsRequest, response: putRobotDetailsResponse,
2386
- errors: [...DEVELOPER_GUARD, 'invalid_uuid', 'not_found', 'validation_error'], transport: 'http',
2387
- notes: 'Answers `{ "details": robotDetailsDoc }` — the stored document, which is the one that was sent. The update is fanned out to every ' +
2388
- '`/realtime` subscriber of the `robot_details` built-in, so a client watching the robot sees the new document without polling.',
2389
- },
2390
2455
  {
2391
2456
  method: 'GET', path: '/api/robots/:id/datapoints', section: 'robots',
2392
2457
  summary: 'Lists the datapoints of a robot, filtered to what the caller\'s role grants.',
@@ -2419,7 +2484,7 @@ export const ROUTES = [
2419
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 ' +
2420
2485
  'a nonexistent one must be one answer. That is why an ungranted slug is `403 forbidden` while a granted-but-unconfigured one is ' +
2421
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 ' +
2422
- '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.',
2423
2488
  },
2424
2489
  /* ------------------------------------------ discovery: the REST twins of the two MCP tools a session starts from */
2425
2490
  {
@@ -2956,7 +3021,11 @@ export const ROUTES = [
2956
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 ' +
2957
3022
  '`409 quota_exceeded` against: `POST /api/apps/:id/users`, `POST /api/client/register`, `POST /api/client/invitations/accept`, and a ' +
2958
3023
  'federated sign-in that would create an account, which carries `quota_exceeded` back to the app as its error redirect. A gauge nothing ' +
2959
- '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`.',
2960
3029
  },
2961
3030
  {
2962
3031
  method: 'GET', path: '/api/org/health', section: 'org',
@@ -3334,6 +3403,403 @@ export const ROUTES = [
3334
3403
  'robot inside that same hook, which is why `rateLimited` is `false`: there is no rate-limiting preHandler registered on this route. The ' +
3335
3404
  'URDF itself is never refused for the store; only meshes and textures are charged against it.',
3336
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
+ },
3337
3803
  /* ------------------------------------ realtime and bridge transports */
3338
3804
  {
3339
3805
  method: 'GET', path: '/bridge', section: 'transports',
@@ -3343,9 +3809,17 @@ export const ROUTES = [
3343
3809
  },
3344
3810
  {
3345
3811
  method: 'GET', path: '/realtime', section: 'transports',
3346
- summary: 'The client WebSocket: subscriptions on datapoints (the built-in bridge state included), jobs and cameras, 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.',
3347
3813
  audience: 'client', auth: 'none', rateLimited: false, ownerTier: false, status: 101,
3348
3814
  params: [], query: null, request: null, response: null, errors: ['invalid_token', 'rate_limited'], transport: 'websocket',
3349
- 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.',
3350
3824
  },
3351
3825
  ];