@fleetless/sdk 4.6.1 → 5.1.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,61 @@ All notable changes to `@fleetless/sdk`. The format follows Keep a Changelog; th
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [5.1.0] — 2026-11-06
8
+
9
+ ### Added
10
+
11
+ - **`client.collections`: an app's own data, over REST and realtime.** A developer defines collections (typed fields, a binding to robots, and which roles may read, create, update and delete) in the console; the app reads and writes their records as the signed-in user or with a server key.
12
+ - REST: `definitions()` (resolves `{ version, collections }`: the readable collections with their fields and what the caller may do, and the schema version they belong to, `null` before anything was published), `list(collection, options)` (search, filter, sort, `limit`, `cursor`, `count`, `expand`, `robot`, `deleted`; resolves `{ records, nextCursor, total? }`), `get` by id or by `{ robot }` for a `one_per_robot` collection, `create`, `update` (with `expectedRevision`), `delete` and `history` (resolves `{ revisions, nextBeforeSeq, purged }`).
13
+ - Realtime: `subscribe(collection, { robot?, filter?, onError?, onSchemaPublished?, onReady? }, onEvent)` follows a collection's records over the client's channel, subscribes again after every reconnect and returns the function that ends it. There is no first snapshot. `onReady` is called each time the cloud confirms the subscription (`collection_subscribed`): the first time, and again on every new connection once the subscription was sent again. It is the place to `list`: every change after the confirmation reaches `onEvent`, so none falls between the list and the events, and the same code refreshes what the app holds after a reconnect, because changes made while the connection was down are not replayed. It needs a cloud that sends the confirmation.
14
+ - A subscription whose frame, with its filter, is larger than the 16,384 bytes the cloud takes on its realtime socket is refused with `invalid_option` before anything is sent: the cloud would close the connection for it, and again after every reconnect, taking the client's other subscriptions with it. `subscribe` throws; narrow the filter or follow the collection by `robot`.
15
+ - Filters: a `filter` of `list` or `subscribe` is plain JSON, and the SDK copies it as JSON, so a reactive proxy (a Vue `reactive`, a Svelte `$state`, a MobX observable) is fine. A value JSON cannot hold (a BigInt, a function, a number that is not finite, a cycle) is refused with `invalid_option` before anything is sent: `list` rejects, `subscribe` throws.
16
+ - New exports: the types `CollectionsApi`, `CollectionListOptions`, `CollectionPage`, `CollectionHistoryOptions`, `CollectionHistoryPage`, `CollectionRecord`, `CollectionRevision`, `CollectionDefinition`, `CollectionDefinitions`, `CollectionEvent`, `CollectionSubscribeOptions`, `CollectionField`, `CollectionBinding` and `CollectionActor`, and the `error.details` schemas of the refusals specific to records, with their types: `recordChangedDetails`, `recordReferencedDetails`, `referenceInvalidDetails` and `requiredMissingDetails`.
17
+
18
+ ### Changed
19
+
20
+ - Built against `@fleetless/contracts` 15.0.0.
21
+
22
+ ### Fixed
23
+
24
+ - **An id, slug or key of `.` or `..` is refused instead of climbing out of its route.** `encodeURIComponent` leaves a value that is only dots alone, and the URL parser `fetch` runs resolves `..` (and `%2E%2E`) as a dot-segment, so `client.collections.get('..', id)` reached a different route with the caller's credentials. Every call that puts an id, slug or key into a path now rejects with `invalid_option` before a request is built. Values that merely contain dots (`a.b`, `...`) are unchanged.
25
+
26
+ ### Removed
27
+
28
+ - Nothing in this SDK's API. `robot_details` is no longer a built-in datapoint, and the platform has no route to set it: a robot's description is data an app keeps in its own collections now. Reading or subscribing to that slug is refused like any other slug the robot does not expose, with `unknown_datapoint`, and the SDK relays it as it does every code.
29
+
30
+ ### Compatibility
31
+
32
+ - `FleetlessErrorCode` gains `collection_not_found`, `collection_removed`, `record_changed`, `record_referenced`, `reference_invalid`, `required_missing` and `robot_not_attached` through `ErrorCode`. An exhaustive `switch` over `ErrorCode` gains the cases.
33
+
34
+ ## [5.0.0] — 2026-11-06
35
+
36
+ ### Changed
37
+
38
+ - **Breaking: `ClientIdentity.role_id` is replaced by `role: { key, name } | null`.** It is what `auth.me()` resolves and what the realtime channel holds after authentication. `key` is the organization role's key, the one `fleetless.yaml` and the organization's role list write; `name` is its display name. `role` is `null` where there is no role to name: for a developer, for a server key, and for an app user whose role has since been deleted, who can still sign in and reaches nothing. Code that read `role_id` reads `role?.key` now.
39
+ - **Breaking: the datasheet's capabilities say `job_history` where they said `action_history`,** without an alias. `robots.describe()` resolves `capabilities: { job_history, assets }`; `job_history` is what `jobs.history()` needs, and a `capability_required` refusal names it. The doc comments say which roles hold a capability: the robot's `access` section, otherwise the organization's defaults, less what the app locks.
40
+ - **Breaking: `FleetlessErrorCode` loses `role_name_taken`, `role_in_use` and `last_role` and gains `role_cycle`, `role_key_taken` and `confirmation_required`** through `ErrorCode`. The six belong to the role management of the console; only `capability_required` reaches an app through this SDK. An exhaustive `switch` over `ErrorCode` changes its cases.
41
+ - Built against `@fleetless/contracts` 14.0.0.
42
+
43
+ ### Fixed
44
+
45
+ - **A short outage on the cloud's side no longer ends the realtime channel.** An `auth_error` of `internal_error` (the cloud could not check the credential) used to end the channel for good and was reported to every subscription through `onError`. It is now retried with backoff like a dropped connection, as is a close with code 1011 (the cloud could not re-check the connection's rights and asks for a new authentication). The wait grows from one failed attempt to the next and a retry never comes at once.
46
+ - **A connection the cloud ends with close code 4003 stops and says so.** The code means the credential behind an authenticated connection is no longer valid: the account was removed or blocked, the key was rotated, the session was ended. The channel used to reconnect with that credential first and end only when the cloud refused it. It now reports `token_revoked` to the subscriptions' `onError` at once and does not reconnect; the next `subscribe` or command opens a new connection with whatever credential the client holds by then. A command already sent when the connection ends fails with `command_outcome_unknown`, not `token_revoked`: its reply is lost with the connection and it may or may not have run, so read the job by slug (for example `actions.subscribe`) rather than retrying. A command still waiting for the connection to authenticate was never sent and fails with the authentication error itself.
47
+
48
+ ### Also from contracts 12.0.0 to 14.0.0
49
+
50
+ 4.6.1 was built against `@fleetless/contracts` 12.0.0; the jump also brought the changes of the 12.1 and 13.x releases. For code using this SDK:
51
+
52
+ - **`AssetSyncStatus`**, as `assets.syncStatus()` resolves it, gains an optional `file_limit` on a `refused` failure: the per-file limit that was exceeded and the file's size where known. It is exclusive with the store-full `details`; the failure kinds are unchanged.
53
+ - **`FleetlessErrorCode` gains `legal_offer_unavailable`** through `ErrorCode`. It refuses an organization's Terms offer in the console; an app user's session or a server key does not receive it.
54
+ - Doc comments of the datapoint, camera and invoke responses say what a role "may read" or "may use" where they said it "grants". No shape changed.
55
+
56
+ Nothing else this SDK re-exports or parses at runtime changed.
57
+
58
+ ### Compatibility
59
+
60
+ - Against a cloud older than this release, `identity.role` and `capabilities.job_history` read `undefined`, and the old `role_id` and `action_history` are no longer typed.
61
+
7
62
  ## [4.6.1] — 2026-11-03
8
63
 
9
64
  ### Fixed
package/README.md CHANGED
@@ -35,6 +35,9 @@ Fleetless is in closed beta. The waiting list is at
35
35
  - **Show cameras**: a snapshot that is always there, or live video over
36
36
  WebRTC that starts with the first viewer and stops with the last.
37
37
  - **Follow jobs**, sync assets, and render the robot's URDF with its meshes.
38
+ - **Keep your app's own data** in collections a developer defines in the
39
+ console: records you list, search, write and follow live, under the same
40
+ roles as everything else.
38
41
  - **Sign your users in** — registration, verification, invitations, password
39
42
  reset, single sign-on and MCP consent — from screens that are entirely
40
43
  yours. Fleetless renders no page for an app user.
@@ -101,6 +104,54 @@ const { password, emailCode, twoFactor } = await client.auth.signInMethods()
101
104
  // listProviders() separately returns only federated sign-in buttons.
102
105
  ```
103
106
 
107
+ ## 🗂️ Collections
108
+
109
+ Besides what the robot exposes, an app has data of its own: **collections** a
110
+ developer defines in the console, such as a logbook per robot, a list of
111
+ components with their locations, or one settings record per robot. Each has
112
+ typed fields and says which roles may read, create, update and delete. The
113
+ records are read and written as the signed-in user, or with a server key.
114
+
115
+ ```ts
116
+ import type { CollectionRecord } from '@fleetless/sdk'
117
+
118
+ // What this caller may read, with the fields and what they may do with each,
119
+ // and the schema version they belong to.
120
+ const { version, collections } = await client.collections.definitions()
121
+
122
+ // A subscription delivers changes, not a snapshot. Once the cloud has confirmed it,
123
+ // `onReady` is called: list there, and every change after that reaches the callback.
124
+ // After a dropped connection nothing is replayed, but `onReady` is called again.
125
+ // The SDK does not handle what `onReady` returns, so a failing `list` is caught here.
126
+ let records: CollectionRecord[] = []
127
+ const reload = async () => {
128
+ try {
129
+ records = (await client.collections.list('logbook', { robot: robotId, sort: ['-created_at'], limit: 20 })).records
130
+ } catch (error) {
131
+ console.error('Could not read the logbook', error)
132
+ }
133
+ }
134
+ const unsubscribe = client.collections.subscribe('logbook', { robot: robotId, onReady: reload }, (change) => {
135
+ console.log(change.event, change.id, change.record?.display)
136
+ })
137
+
138
+ // Search and filter run in the cloud.
139
+ await client.collections.list('components', { search: 'quad xtd1', filter: { position_m: { gte: 2 } }, sort: ['position_m'] })
140
+
141
+ // Write. A `one_per_robot` collection has exactly one record per robot.
142
+ await client.collections.create('logbook', { text: 'Replaced the left wheel' }, { robot: robotId })
143
+ const settings = await client.collections.get('robot_settings', { robot: robotId })
144
+ await client.collections.update('robot_settings', settings.id, { max_linear_speed: 0.6 }, { expectedRevision: settings.revision })
145
+
146
+ unsubscribe()
147
+ ```
148
+
149
+ An update that names `expectedRevision` is refused with `record_changed` when
150
+ somebody saved first, and `recordChangedDetails.parse(error.details)` tells you
151
+ the revision the record is at now. The other refusals specific to records keep
152
+ their own codes too: `required_missing`, `reference_invalid` and
153
+ `record_referenced`.
154
+
104
155
  ## 📚 Documentation
105
156
 
106
157
  Everything past this point lives at **[docs.fleetless.dev](https://docs.fleetless.dev)**.