@flipstream/sdk 0.10.1 → 0.12.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 (94) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +98 -348
  3. package/dist/api/account.d.ts +50 -0
  4. package/dist/api/account.js +102 -0
  5. package/dist/api/account.js.map +1 -0
  6. package/dist/api/backend.d.ts +18 -0
  7. package/dist/api/backend.js +35 -4
  8. package/dist/api/backend.js.map +1 -1
  9. package/dist/api/created.d.ts +1 -1
  10. package/dist/api/created.js +3 -2
  11. package/dist/api/created.js.map +1 -1
  12. package/dist/api/credentials.js +4 -4
  13. package/dist/api/credentials.js.map +1 -1
  14. package/dist/api/datasets.d.ts +94 -14
  15. package/dist/api/datasets.js +210 -59
  16. package/dist/api/datasets.js.map +1 -1
  17. package/dist/api/index.d.ts +4 -3
  18. package/dist/api/log.d.ts +45 -24
  19. package/dist/api/log.js +113 -40
  20. package/dist/api/log.js.map +1 -1
  21. package/dist/api/me.d.ts +2 -0
  22. package/dist/api/me.js +9 -5
  23. package/dist/api/me.js.map +1 -1
  24. package/dist/api/members.d.ts +69 -7
  25. package/dist/api/members.js +110 -32
  26. package/dist/api/members.js.map +1 -1
  27. package/dist/api/time.js +4 -3
  28. package/dist/api/time.js.map +1 -1
  29. package/dist/api/wallet.d.ts +8 -5
  30. package/dist/api/wallet.js +36 -24
  31. package/dist/api/wallet.js.map +1 -1
  32. package/dist/api/workspaces.d.ts +42 -7
  33. package/dist/api/workspaces.js +80 -20
  34. package/dist/api/workspaces.js.map +1 -1
  35. package/dist/auth/discovery.d.ts +19 -6
  36. package/dist/auth/discovery.js +25 -4
  37. package/dist/auth/discovery.js.map +1 -1
  38. package/dist/auth/signIn.d.ts +18 -14
  39. package/dist/auth/signIn.js +29 -22
  40. package/dist/auth/signIn.js.map +1 -1
  41. package/dist/core/call.d.ts +4 -1
  42. package/dist/core/call.js +26 -6
  43. package/dist/core/call.js.map +1 -1
  44. package/dist/core/deadline.d.ts +30 -0
  45. package/dist/core/deadline.js +51 -0
  46. package/dist/core/deadline.js.map +1 -0
  47. package/dist/core/invalid.d.ts +7 -0
  48. package/dist/core/invalid.js +22 -0
  49. package/dist/core/invalid.js.map +1 -0
  50. package/dist/core/names.d.ts +31 -3
  51. package/dist/core/names.js +26 -6
  52. package/dist/core/names.js.map +1 -1
  53. package/dist/core/notFound.d.ts +8 -0
  54. package/dist/core/notFound.js +8 -0
  55. package/dist/core/notFound.js.map +1 -0
  56. package/dist/core/result.d.ts +17 -12
  57. package/dist/core/result.js +5 -5
  58. package/dist/core/result.js.map +1 -1
  59. package/dist/core/retry.d.ts +5 -2
  60. package/dist/core/retry.js +6 -3
  61. package/dist/core/retry.js.map +1 -1
  62. package/dist/core/scope.d.ts +20 -0
  63. package/dist/core/scope.js +54 -0
  64. package/dist/core/scope.js.map +1 -0
  65. package/dist/flipstream.d.ts +151 -70
  66. package/dist/flipstream.js +67 -45
  67. package/dist/flipstream.js.map +1 -1
  68. package/dist/node/clientSecret.js +5 -5
  69. package/dist/node/clientSecret.js.map +1 -1
  70. package/dist/node/headless.d.ts +14 -6
  71. package/dist/node/headless.js +8 -6
  72. package/dist/node/headless.js.map +1 -1
  73. package/dist/node/index.d.ts +1 -1
  74. package/dist/node/index.js +1 -1
  75. package/dist/node/index.js.map +1 -1
  76. package/dist/node/keychainChild.js +27 -10
  77. package/dist/node/keychainChild.js.map +1 -1
  78. package/dist/node/keychainError.d.ts +3 -3
  79. package/dist/node/keychainStore.d.ts +16 -12
  80. package/dist/node/keychainStore.js +50 -28
  81. package/dist/node/keychainStore.js.map +1 -1
  82. package/dist/node/loopback.d.ts +8 -1
  83. package/dist/node/loopback.js +19 -2
  84. package/dist/node/loopback.js.map +1 -1
  85. package/dist/node/session.d.ts +17 -9
  86. package/dist/node/session.js +55 -44
  87. package/dist/node/session.js.map +1 -1
  88. package/dist/node/store.d.ts +35 -2
  89. package/dist/node/store.js +56 -12
  90. package/dist/node/store.js.map +1 -1
  91. package/dist/version.gen.js +1 -1
  92. package/docs/admin.md +503 -0
  93. package/docs/node-sign-in.md +60 -35
  94. package/package.json +1 -1
package/README.md CHANGED
@@ -96,50 +96,14 @@ const { organization, user } = orThrow(await flipstream.me())
96
96
  console.log(organization.name, user.email, user.role)
97
97
  ```
98
98
 
99
- - **`organization`** is `{ id, name, slug, access }`. The slug is its short name, as the console's
100
- addresses spell it.
101
- - `access` says whether the organisation may use Flipstream, read from its billing settings by
102
- the console's rules, in the service's own words:
103
- - `{ status: 'trial', trial_ends_on }`: in trial, with `trial_ends_on` the trial's last day as
104
- `YYYY-MM-DD`;
105
- - `{ status: 'active' }`;
106
- - `{ status: 'expired', trial_ends_on }`: the service's `expired`, which doesn't say why. Today
107
- it only ever follows a trial. `trial_ends_on` is the trial's end, not necessarily the day
108
- access ended;
109
- - `{ status: 'unknown' }`: settings that can't be read, or a status this version doesn't know.
110
- It's never read as active, and it never fails `me()`.
111
- - The status is the truth. A trial past its last day stays `trial` until the service says
112
- otherwise: the SDK never reads the clock for it. A day that isn't a real `YYYY-MM-DD` is `null`.
113
- - Every role reads the same access, a viewer limited to some workspaces and Flipstream's own
114
- staff included.
115
- - **`user`** is `{ id, email, first_name, last_name, role, active, workspace_ids }`: a `Member`, as
116
- `flipstream.members` answers each person (see "Your organisation's members").
117
- - `me()` reads the token's own person and doesn't apply `members`' people-only rule. An API key's
118
- token isn't tested with it yet: service accounts come with pulse-admin#93.
119
- - `role` is the highest you hold: `'owner'`, `'admin'`, `'editor'` or `'viewer'`. It's `null`
120
- when you hold none of them, and for Flipstream's own staff (`godmode`, `swapper`), whatever
121
- else they hold. There's no guest role yet. A role this version doesn't know counts as none of
122
- ours: it never fails the answer, a known role beside it still wins, and its name is never shown.
123
- - `active` says whether your account is switched on.
124
- - `workspace_ids` are the workspaces your account names. For a viewer, they're the workspaces
125
- you may open, and a viewer with none opens every workspace of the organisation. No other role
126
- is limited by them.
127
- - **Nothing else** from the services' answers is in it.
128
- - **Three reads:** your organisation, and who your token belongs to, then that person. They share
129
- one deadline, 30 s unless the call sets its own, and the first failure, in that order, is the
130
- answer.
131
- - **Renaming your organisation is a person's to do, in the console.**
132
- `flipstream.organization.rename({ name })` never writes. It reads your organisation, then
133
- answers `needs_person` with `why`. Where a console can be named (your own `hosts.console`), the
134
- organisation's settings page is the `url`, with what it shows as `sees`, as `workspaces.rename`
135
- does. There, Owners and Admins change the name and the short name. The `name` you give is never
136
- echoed.
99
+ **The rest is in [docs/admin.md](docs/admin.md),** under "Who you are".
137
100
 
138
101
  ## Your organisation's members
139
102
 
140
103
  `flipstream.members` reads the people of your organisation, one page at a time, each as `me()`
141
104
  answers you. People, not keys: an API user, a service account, is never listed, counted or
142
- answered, as the console's People has it. (`me()` doesn't apply that rule: see "Who you are".)
105
+ answered, as the console's People has it. (`me()` doesn't apply that rule: see "Who you are" in
106
+ [docs/admin.md](docs/admin.md).)
143
107
 
144
108
  ```ts
145
109
  import { createFlipstream, orThrow } from '@flipstream/sdk'
@@ -153,33 +117,7 @@ const member = orThrow(await flipstream.members.get({ member_id: page.items[0]?.
153
117
  console.log(member.first_name, member.workspace_ids.length)
154
118
  ```
155
119
 
156
- - **A member** is `{ id, email, first_name, last_name, role, active, workspace_ids }`, and nothing
157
- else, with `role` and `workspace_ids` by `me()`'s rules (see "Who you are"): the highest role
158
- they hold, or `null` for none and for Flipstream's own staff. A role this version doesn't know
159
- counts as none of ours, and its name is never shown.
160
- - **An open invitation is in the list:** someone invited who hasn't joined yet has an empty
161
- `first_name`, as the console tells them apart.
162
- - **Keys are left out by the service itself,** so `total` counts people.
163
- - **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every member.
164
- - The limit is 100 unless you set one, and at most 1,000.
165
- - A limit or offset that isn't a whole number in range rejects, with nothing sent.
166
- - **The order is the service's own:** by email. Pages read at different times can overlap, or skip
167
- a person, when people are added or removed, or an email changes, in between. A changed `total`
168
- shows some of that, but an unchanged one doesn't prove nothing moved. For a complete, stable
169
- list, read it in one page: up to 1,000.
170
- - **Each call reads your organisation beside the people,** under one deadline for both reads, and
171
- its failure is the answer. In a list, a person of another organisation makes the answer
172
- `invalid`; they're never shown or dropped.
173
- - **What `get` answers,** for an id:
174
- - **the person,** when they're one of your organisation's people;
175
- - **`not_found`** when there's no such person for you: pulse-auth has none by that id, or your
176
- role can't read them (it answers 404), or the id is one of your organisation's API keys, which
177
- `get` answers as an id nobody has;
178
- - **`forbidden`** when pulse-auth refuses the read (403);
179
- - **`invalid`** when the answer is another organisation's person or API key, which only a staff
180
- token reaches, such as Flipstream's staff acting through a swap token. The organisation is
181
- checked before the key, so another organisation's key is `invalid` too. So is an answer that
182
- is someone else than the person asked for.
120
+ **The rest is in [docs/admin.md](docs/admin.md),** under "Your organisation's members".
183
121
 
184
122
  ## Workspaces
185
123
 
@@ -197,69 +135,11 @@ const workspace = orThrow(await flipstream.workspaces.get({ workspace_id: page.i
197
135
  console.log(workspace.slug)
198
136
  ```
199
137
 
200
- - **A workspace** is `{ id, name, slug }`. Nothing else the service sends is in it.
201
- - **A page** is `{ items, total, limit, offset }`. `total` counts every workspace, and `limit` and
202
- `offset` say what was read. `limit` is 100 when left out and at most 1,000, and a larger one is
203
- read as 1,000. A limit or offset that isn't a whole number in range rejects with a `TypeError`,
204
- with nothing sent.
205
- - **The order is the service's own:** by name alone, for workspaces. Pages read at different times
206
- can overlap, or skip a workspace, when workspaces are added, removed or renamed in between, or
207
- when two have the same name. A changed `total` shows some of that, but an unchanged one doesn't
208
- prove nothing moved. For a complete, stable list, read it in one page: up to 1,000.
209
- - **Each call reads your organisation first,** under one deadline for both reads, and its failure
210
- is the answer. A workspace of another organisation makes the answer `invalid`; it's never shown
211
- or dropped.
212
- - **Creating a workspace:** `flipstream.workspaces.create({ name })` makes one in your organisation
213
- and answers it as a `Workspace`.
138
+ **A workspace you don't open is `not_found`,** exactly as one nobody has, in every call under one
139
+ workspace, its logbook's and its datasets' included, and a write sends nothing (see "The
140
+ workspaces you open" in [docs/admin.md](docs/admin.md)).
214
141
 
215
- ```ts
216
- import { createFlipstream, orThrow } from '@flipstream/sdk'
217
-
218
- const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
219
-
220
- const made = orThrow(await flipstream.workspaces.create({ name: 'Acme NL' }))
221
- console.log(made.id, made.slug) // the short name the service chose, such as 'acme-nl-2'
222
- ```
223
-
224
- - It sends the name alone, with your organisation. The service makes the short name, unique in
225
- your organisation, so read `slug` from the answer.
226
- - **A request with any key but `name` is `refused`** (`reason: 'fields'`, naming them), with
227
- nothing sent: a `slug` or an `organization_id` it dropped would look set. A `name` that isn't a
228
- non-empty string, or is only spaces, rejects with a `TypeError`, with nothing sent.
229
- - Who may create one is the service's rule, not the SDK's: Owners and Admins. pulse-admin#181
230
- aligns the service with it; until then an Editor still succeeds. Anyone it refuses gets
231
- `forbidden`.
232
- - **It's never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
233
- `no_token` shows nothing was made. After any other failure (`timeout`, `unavailable`,
234
- `aborted`, `cancelled`, or `invalid`, which may be the service's answer that it made one) it may
235
- have been made, so list the workspaces before you create it again. Names needn't be unique, so
236
- compare that list with one from before you created it.
237
- - **Renaming or deleting a workspace is a person's to do, in the console.**
238
- `flipstream.workspaces.rename({ workspace_id, name })` and `delete({ workspace_id })` never write.
239
- Each reads the workspace (one that isn't yours is `not_found`), then answers `needs_person`:
240
-
241
- ```ts
242
- import { createFlipstream } from '@flipstream/sdk'
243
-
244
- const flipstream = createFlipstream({
245
- app: { name: 'my-app', version: '1.0.0' },
246
- token: async () => '<your token>',
247
- hosts: { console: 'http://localhost:5173' },
248
- })
249
-
250
- const result = await flipstream.workspaces.rename({ workspace_id: '<workspace id>', name: 'New name' })
251
- if (!result.ok && result.error.kind === 'needs_person') {
252
- console.log(result.error.why) // tell the person what to do, and why
253
- if (result.error.url !== undefined) console.log(result.error.url, result.error.sees)
254
- }
255
- ```
256
-
257
- - `why` is the SDK's own words, never a value you gave, so it's safe to show.
258
- - `url` and `sees` name the workspace's settings page, and are there only when a console can be
259
- named: set `hosts.console` (for example `http://localhost:5173`, while developing). It must be
260
- https, or http on this machine, with no query, fragment or credentials, or `createFlipstream`
261
- throws a `TypeError`.
262
- - `orThrow` throws it as an `ApiFailure` whose message gives `why`.
142
+ **The rest is in [docs/admin.md](docs/admin.md),** under "Workspaces".
263
143
 
264
144
  ## A workspace's logbook
265
145
 
@@ -278,74 +158,13 @@ console.log(`${page.items.length} of ${page.total}`)
278
158
  const entry = orThrow(await flipstream.log.get({ log_id: '<log entry id>' }))
279
159
  ```
280
160
 
281
- - **An entry** is `{ id, description, start_date, end_date, workspace_id, created_on, created_by_id }`,
282
- and nothing else.
283
- - `start_date` and `end_date` are ISO 8601 instants in UTC, such as `2026-10-05T00:00:00.000Z`.
284
- - A point in time starts and ends at once.
285
- - `created_on` is when it was written, in the same form, and `created_by_id` the person who wrote
286
- it. Either is `null` when the service holds none.
287
- - `flipstream.members.get({ member_id: created_by_id })` names the writer. When it doesn't answer
288
- ok (see "Your organisation's members"), show the writer as unknown, for example for an entry
289
- Flipstream staff wrote through a swap token.
290
- - **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every entry.
291
- - The limit is 100 unless you set one, and at most 1,000.
292
- - A limit or offset that isn't a whole number in range rejects, with nothing sent.
293
- - **The order is newest written first:** the logbook's own, since the SDK asks for no other.
294
- - When an entry was written never changes, so editing an entry doesn't move it.
295
- - Pages read at different times can still overlap or skip an entry, when one is written or
296
- removed in between.
297
- - Entries written at the same moment have no fixed order among themselves.
298
- - A changed `total` shows that something was added or removed; an unchanged one doesn't prove
299
- nothing was.
300
- - **The workspace is read beside the list,** with your organisation, under one deadline: one
301
- nobody has is `not_found`, and another organisation's is `invalid`, never an empty page. Their
302
- failure, then the list's, is the answer.
303
- - **An entry of another workspace or organisation** in the list makes the answer `invalid`; it's
304
- never dropped.
305
- - **A missing entry:** `get` answers `not_found`. `get` reads your organisation beside the entry, and
306
- an answer that is another entry than the one asked for, or another organisation's, is `invalid`.
307
-
308
- **Writing to it:** `add`, `update` and `remove`.
309
-
310
- ```ts
311
- import { createFlipstream, orThrow } from '@flipstream/sdk'
312
-
313
- const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
314
-
315
- const added = orThrow(
316
- await flipstream.log.add({ workspace_id: '<workspace id>', description: 'Site migration', start_date: '2026-10-05T00:00:00Z', end_date: '2026-10-06T00:00:00Z' }),
317
- )
318
- orThrow(await flipstream.log.update({ log_id: added.id, description: 'Site migration, phase 1' }))
319
- orThrow(await flipstream.log.remove({ log_id: added.id })) // null
320
- ```
321
-
322
- - **What each takes,** before anything is sent:
323
- - a key it doesn't send is `refused` (`reason: 'fields'`, naming them);
324
- - a description that isn't a non-blank string, a time not written as `2026-10-05T00:00:00Z`, or a
325
- start after the end rejects with a `TypeError`. A fraction may follow the seconds, and an offset
326
- such as `+02:00`, or none, may take the place of the `Z`. A time with no offset is read as UTC,
327
- and every time is sent as a UTC instant.
328
- - **Each write reads first.** `add` reads the workspace: one nobody has is `not_found`, and another
329
- organisation's is `invalid`, with nothing written. `update` and `remove` read the entry, held to
330
- your organisation the same way.
331
- - **`update` changes what you give,** at least one of `description`, `start_date` and `end_date`,
332
- and sends the rest back exactly as stored. When you give a time, a start after the stored end
333
- (or an end before the stored start) rejects with a `TypeError`, with nothing written. Since the
334
- whole entry goes back, a change someone else made between `update`'s read and its write is
335
- overwritten.
336
- - **`remove` answers `null`.** A log entry's remove is direct; it's not handed to a person.
337
- - **Who may write is the service's rule, not the SDK's:** Owners, Admins and Editors add; an Editor
338
- changes or removes only their own entries, and Owners and Admins any. Until the service enforces
339
- it (pulse-admin#161, for Editors), a Viewer can also add, change and remove entries, and an Editor
340
- can change anyone's. Anyone it refuses gets `forbidden`.
341
- - **A write is never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
342
- `no_token` shows nothing was written. After any other failure it may have been, so list the
343
- logbook before you write again.
161
+ **The rest is in [docs/admin.md](docs/admin.md),** under "A workspace's logbook".
344
162
 
345
163
  ## A workspace's datasets
346
164
 
347
- `flipstream.datasets` reads a workspace's datasets, its uploads and connected accounts, and pauses
348
- and resumes them. `flipstream.datasetTypes` lists the types of dataset this version knows.
165
+ `flipstream.datasets` reads a workspace's datasets, its uploads and connected accounts, or your
166
+ organisation's in every workspace you open; it counts a workspace's, and pauses and resumes them.
167
+ `flipstream.datasetTypes` lists the types of dataset this version knows.
349
168
 
350
169
  ```ts
351
170
  import { createFlipstream, orThrow } from '@flipstream/sdk'
@@ -354,94 +173,17 @@ const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' },
354
173
 
355
174
  const page = orThrow(await flipstream.datasets.list({ workspace_id: '<workspace id>', limit: 50 }))
356
175
  for (const dataset of page.items) console.log(dataset.name, dataset.type, dataset.active)
176
+ const everywhere = orThrow(await flipstream.datasets.list({ organization: true }))
177
+ for (const dataset of everywhere.items) console.log(dataset.workspace_id, dataset.name)
178
+ const { count } = orThrow(await flipstream.datasets.count({ workspace_id: '<workspace id>' }))
179
+ console.log(count)
357
180
 
358
181
  const dataset = orThrow(await flipstream.datasets.get({ dataset_id: '<dataset id>' }))
359
182
  const types = orThrow(await flipstream.datasetTypes.list())
360
183
  console.log(dataset.name, types.length)
361
184
  ```
362
185
 
363
- - **A dataset** is `{ id, name, workspace_id, type, active, created_on, created_by_id, history }`,
364
- and nothing else: never a credential, a setting or its parameters. The service's answer embeds the dataset's
365
- sign-in, so a body that isn't the service's JSON is never kept either: a failure of the dataset's
366
- own read or write gives its kind and status, with no `text`. The reads of your organisation and
367
- the workspace beside it keep theirs.
368
- - `type` is one of the types `datasetTypes.list()` gives, such as `'google_search_console'`, or
369
- a type this version doesn't know yet, kept as it came, so a new kind of dataset never makes the
370
- list unreadable. It's `null` when the service holds no type for it.
371
- - `active` says whether it's switched on.
372
- - `created_on` is when it was made, an ISO 8601 instant in UTC, and `created_by_id` the person who
373
- made it. Either is `null` when the service holds none.
374
- - `flipstream.members.get({ member_id: created_by_id })` names the maker. When it doesn't answer
375
- ok (see "Your organisation's members"), show the maker as unknown, for example for a dataset
376
- Flipstream staff made through a swap token.
377
- - `history` says how much of its history is in the warehouse, a `DatasetHistory`, in the
378
- service's own values (the SDK renames fields, never values):
379
- - `'not_available'`: no history is loaded for its kind of dataset;
380
- - `'todo'`: its history hasn't started loading. Every new dataset starts here, and the
381
- pipeline sets `'not_available'` only when it first runs for one, so `'todo'` may never start
382
- for a type that loads no history;
383
- - `'started'`: its history is loading, from the first load until it's in; a load that keeps
384
- failing stays `'started'`;
385
- - `'done'`: its history is in.
386
-
387
- Merge them as your app needs: the console shows `'todo'` and `'started'` alike as "coming in".
388
- It's `null` when it's unknown, because the service holds none or a value this version doesn't
389
- know: show "Not available yet" then, never a value of your own.
390
- - **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every dataset.
391
- - The limit is 100 unless you set one, and at most 1,000.
392
- - A limit or offset that isn't a whole number in range rejects, with nothing sent.
393
- - **The order is the service's own:** by name alone. Pages read at different times can overlap, or
394
- skip a dataset, when datasets are added, removed or renamed in between, or when two have the same
395
- name. A changed `total` shows some of that, but an unchanged one doesn't prove nothing moved. For
396
- a complete, stable list, read it in one page: up to 1,000.
397
- - **Each call reads your organisation beside the datasets,** and a list reads its workspace too,
398
- under one deadline for every read. The organisation's failure, then the workspace's, is the
399
- answer. A dataset of another organisation, or in the list one of another workspace, makes the
400
- answer `invalid`; it's never shown or dropped.
401
- - **A workspace nobody has** is `not_found`, and another organisation's is `invalid`: never an empty
402
- page, which would say it has no datasets.
403
- - **A missing dataset:** `get` answers `not_found`. An answer that is another dataset than the one
404
- asked for is `invalid`.
405
- - **`datasetTypes.list()`** sends nothing: the types are the SDK's own list, since the service has
406
- no route for them yet. Each call gives you a list of your own.
407
-
408
- **Pausing and resuming:** `pause` and `resume`.
409
-
410
- ```ts
411
- import { createFlipstream, orThrow } from '@flipstream/sdk'
412
-
413
- const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
414
-
415
- const paused = orThrow(await flipstream.datasets.pause({ dataset_id: '<dataset id>' }))
416
- console.log(paused.active) // false
417
- orThrow(await flipstream.datasets.resume({ dataset_id: '<dataset id>' })) // active: true
418
- ```
419
-
420
- - **Each answers the `Dataset`,** with `active` as asked. Pausing a paused dataset sends the same
421
- write and answers the same, so calling either twice is the same as once.
422
- - **What each takes,** before anything is sent: `dataset_id` alone. Any other key is `refused`
423
- (`reason: 'fields'`, naming them), and an id that isn't a string rejects with a `TypeError`.
424
- - **Each reads first:** the dataset, fresh, beside your organisation. One nobody has is
425
- `not_found`, and another organisation's is `invalid`, with nothing written. Then `active` alone
426
- is sent, so a rename made in between stays.
427
- - **Each reads again after the write,** fresh, and answers that read. One whose `active` isn't the
428
- one asked for is `invalid`, since the write may not have been stored, as is one of another
429
- dataset, workspace or organisation. That read comes after the write was sent, so its failure
430
- is never answered as a refusal: a 4xx kind, `refused` or `no_token` there is `invalid`, naming
431
- its kind. A `timeout`, `aborted`, `cancelled`, `unavailable` or `invalid` there keeps its kind,
432
- since it already says the write may have been made.
433
- - **Who may is the service's rule:** Owners, Admins and Editors pause and resume, and a Viewer
434
- doesn't. Anyone it refuses gets `forbidden`.
435
- - **A write is never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
436
- `no_token` shows nothing was written. After any other failure it may have been; calling it
437
- again is safe, since it's the same write.
438
-
439
- **Deleting a dataset is a person's to do, in the console.** It removes the dataset's data for good,
440
- and the console can't delete a dataset yet. `flipstream.datasets.delete({ dataset_id })` never
441
- writes. It reads the dataset first: one nobody has is `not_found`, and another organisation's is
442
- `invalid`. Then it answers `needs_person` with `why`, and, where a console can be named (your own
443
- `hosts.console`), the dataset's page as `url`, with what it shows as `sees`, as
444
- `workspaces.delete` does.
186
+ **The rest is in [docs/admin.md](docs/admin.md),** under "A workspace's datasets".
445
187
 
446
188
  ## Sign-ins to your sources
447
189
 
@@ -457,30 +199,7 @@ const page = orThrow(await flipstream.credentials.list({ limit: 50 }))
457
199
  for (const credential of page.items) console.log(credential.name, credential.type, credential.datasource_types)
458
200
  ```
459
201
 
460
- - **A credential** is `{ id, name, type, datasource_types, created_on }`, and nothing else.
461
- - `name` is the provider account it signs in as: for a Google sign-in, that account's email
462
- address.
463
- - `type` is what kind of sign-in it is, such as `'oauth2'` or `'service_account'`. A kind this
464
- version doesn't know is kept as it came, and it's `null` when the service holds none.
465
- - `datasource_types` lists the kinds of dataset it serves, such as `'google_search_console'`.
466
- - `created_on` is an ISO 8601 instant in UTC.
467
- - **Never a value.** The service doesn't mask a sign-in, so the SDK checks every answer itself. An
468
- answer holding what may be a sign-in's value (a `data` that isn't empty, or a key such as
469
- `refresh_token`, `apiKey`, `auth_values` or `password`, at any depth, however it's spelt) is
470
- `invalid`. Its issues name the place, never the value, and nothing is answered at all. A body
471
- that isn't the service's JSON is never kept either: a failure of the sign-ins' own reads gives
472
- its kind and status, with no `text`. The read of your organisation beside them keeps its.
473
- - **A list is one page:** `{ items, total, limit, offset }`, as every list is. The limit is 100
474
- unless you set one, and at most 1,000.
475
- - **It reads your organisation first,** for its id, and its failure is the answer. A sign-in of
476
- another organisation makes the answer `invalid`.
477
- - **Who may list them is the service's rule:** today Owners, Admins, Editors and Viewers. Anyone
478
- it refuses gets `forbidden`.
479
- - **Revoking or deleting a sign-in is a person's to do, in the console.** Either breaks every
480
- dataset that reads with it. `flipstream.credentials.revoke({ credential_id })` and
481
- `delete({ credential_id })` never write. Each reads the sign-in first: one nobody has is
482
- `not_found`, and another organisation's is `invalid`. Then it answers `needs_person` with `why`.
483
- There's no `url` yet: no console page names a sign-in.
202
+ **The rest is in [docs/admin.md](docs/admin.md),** under "Sign-ins to your sources".
484
203
 
485
204
  ## Wallet
486
205
 
@@ -496,25 +215,10 @@ const balance = orThrow(await flipstream.wallet.balance())
496
215
  if (balance !== null) console.log(balance.balance_micro / balance.micro_per_euro, 'euros')
497
216
 
498
217
  const ledger = orThrow(await flipstream.wallet.transactions())
499
- console.log(ledger.items.length, 'rows')
218
+ if (ledger !== null) console.log(ledger.items.length, 'rows')
500
219
  ```
501
220
 
502
- - **Amounts are whole numbers of micro,** and each answer says how many make a euro, in
503
- `micro_per_euro`. Divide by it, never by a number of your own: the basis can change.
504
- - **`balance()`** is `{ balance_micro, micro_per_euro }`, or `null` when your organisation has no
505
- wallet. No wallet is a real state, so it's not an error, and it's never a zero balance: €0.00
506
- would claim a wallet that holds nothing.
507
- - **`transactions()`** is the whole ledger, in one answer, with no paging: `{ items, micro_per_euro }`.
508
- The ledger's rows don't name their wallet, so the balance is read beside it, and the ledger is
509
- answered only when that's your organisation's wallet. Each row
510
- is `{ id, type, dataset_id, description, amount_micro, quantity, unit_price_micro, created_on }`.
511
- A row that charged no dataset, such as a credit, has `dataset_id: null`, whether the wallet
512
- wrote its `connection_id` empty or null. `created_on` is an
513
- ISO 8601 instant in UTC, such as `2026-10-31T13:08:25.312Z`, as the logbook's times are. A type
514
- this version doesn't know is kept as it came.
515
- - **Who may read it is the wallet's rule, not the SDK's.** Today that's Owners and Admins, and
516
- Editors too once pulse-wallet#15 lands. Anyone the wallet refuses gets `forbidden`, never an
517
- empty ledger.
221
+ **The rest is in [docs/admin.md](docs/admin.md),** under "Wallet".
518
222
 
519
223
  ## Signing in from Node and the CLI
520
224
 
@@ -556,7 +260,7 @@ const signedIn = await signInWithLoopback({
556
260
  })
557
261
  if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
558
262
 
559
- const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: () => signedIn.data.accessToken })
263
+ const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: () => signedIn.data.access_token })
560
264
  ```
561
265
 
562
266
  - **The SDK opens nothing and writes nothing to the terminal.** `open` does that, once the port is
@@ -565,11 +269,27 @@ const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' },
565
269
  out (after 5 minutes, or `timeoutMs`), aborted (`signal`), or `open` or `readPasted` failing
566
270
  (`readPasted` reads a pasted address when the browser can't come back: see
567
271
  [docs/node-sign-in.md](docs/node-sign-in.md)).
272
+ - **`timeoutMs` follows a call's `deadlineMs`:** taken in whole ms, rounded down, up to 2147483647;
273
+ left out or `null`, it's 5 minutes. One that can't be a wait (not a number, `NaN`, ±`Infinity`,
274
+ or more than that once rounded down) is a `TypeError` naming `signInWithLoopback`, with no port
275
+ opened. One under 1 ms ends as `timeout`, with no port opened and nothing shown, once `server`,
276
+ `clientId` and `scopes` pass the checks a sign-in makes: a mistake in them is still a `TypeError`.
568
277
  - **The redirect is checked before its code is exchanged:** the sign-in's own state first, then the
569
278
  issuer.
570
279
  - **`page: { signedIn, failed }`** sets the HTML the browser shows afterwards.
571
- - **What comes back:** `accessToken`, `scope`, `expiresAt` (ms since the epoch) when the server
572
- says, and `refreshToken` when it issues one. Never log them.
280
+ - **What comes back:** `access_token`, `scope`, `expires_at` (ms since the epoch) when the server
281
+ says, and `refresh_token` when it issues one. Never log them.
282
+ - **Every field in data the SDK returns is snake_case since the snake rename** (D569); its own
283
+ settings, such as `clientId` and `timeoutMs`, stay camelCase. Across the upgrade:
284
+ - `keychainStore` and `fileStore` still read the camelCase tokens that earlier releases saved,
285
+ and save the new shape at their next save.
286
+ - A store of your own converts its records with `fromEarlierTokenNames`, in the same change that
287
+ renames its `onTokens` fields ([docs/node-sign-in.md](docs/node-sign-in.md)).
288
+ - The new shape is one-way: an earlier release can't read it. Every process that shares a
289
+ `fileStore` file or a keychain item upgrades together, and rolling back means signing in
290
+ again, or `clear()`.
291
+ - A sign-in started before the upgrade and finished after it isn't: its `pending` is `refused`,
292
+ and the person signs in again.
573
293
 
574
294
  **The rest is in [docs/node-sign-in.md](docs/node-sign-in.md),** which ships in the package, at
575
295
  `node_modules/@flipstream/sdk/docs/node-sign-in.md`:
@@ -654,8 +374,8 @@ if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
654
374
  ## Results, not exceptions
655
375
 
656
376
  Every call settles into a result: `{ ok: true, data }` or `{ ok: false, error }`, each with the
657
- call's `traceId` when a request went out (see "Finding a request in Logs"). A call rejects only on a
658
- programming error. For instance, a request that can't be sent as JSON (a `BigInt`, a cycle) rejects
377
+ call's `trace_id` when a request went out (see "Finding a request in Logs"). A call rejects only on
378
+ a programming error. For instance, a request that can't be sent as JSON (a `BigInt`, a cycle) rejects
659
379
  with the `TypeError`, and nothing is sent. `orThrow(result)` gives the data, or throws the failure
660
380
  as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
661
381
 
@@ -676,30 +396,40 @@ as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
676
396
  (`{ status: 'ok' }` today). It works signed out: no token is asked for or sent, so it tells "the
677
397
  service is down" from "the sign-in is wrong".
678
398
  - **`flipstream.me()`** gives a `Me`: your organisation and you in it, and
679
- **`flipstream.organization.rename()`** answers `needs_person` (see "Who you are").
399
+ **`flipstream.organization.rename()`** answers `needs_person` (see "Who you are" in
400
+ [docs/admin.md](docs/admin.md)).
680
401
  - **`flipstream.workspaces.list({ limit, offset })`** gives a `Page<Workspace>`, and
681
402
  **`flipstream.workspaces.get({ workspace_id })`** and **`create({ name })`** a `Workspace` (see
682
- "Workspaces").
403
+ "Workspaces" in [docs/admin.md](docs/admin.md)).
683
404
  - **`flipstream.log.list()`** gives a `Page<LogEntry>`, **`flipstream.log.get()`**, **`add()`** and
684
- **`update()`** a `LogEntry`, and **`remove()`** `null` (see "A workspace's logbook").
685
- - **`flipstream.datasets.list()`** gives a `Page<Dataset>`, **`flipstream.datasets.get()`**,
686
- **`pause()`** and **`resume()`** a `Dataset`, **`delete()`** answers `needs_person`, and
405
+ **`update()`** a `LogEntry`, and **`remove()`** `null` (see "A workspace's logbook" in
406
+ [docs/admin.md](docs/admin.md)).
407
+ - **`flipstream.datasets.list()`** gives a `Page<Dataset>`, **`count({ workspace_id })`**
408
+ `{ count }`, **`flipstream.datasets.get()`**, **`pause()`** and **`resume()`** a `Dataset`,
409
+ **`delete()`** answers `needs_person`, and
687
410
  **`flipstream.datasetTypes.list()`** gives the `DatasetType`s this version knows (see "A
688
- workspace's datasets").
411
+ workspace's datasets" in [docs/admin.md](docs/admin.md)).
689
412
  - **`flipstream.credentials.list({ limit, offset })`** gives a `Page<Credential>`, and
690
- **`revoke()`** and **`delete()`** answer `needs_person` (see "Sign-ins to your sources").
413
+ **`revoke()`** and **`delete()`** answer `needs_person` (see "Sign-ins to your sources" in
414
+ [docs/admin.md](docs/admin.md)).
691
415
  - **`flipstream.wallet.balance()`** gives a `Balance` or `null`, and
692
- **`flipstream.wallet.transactions()`** a `Ledger` (see "Wallet").
416
+ **`flipstream.wallet.transactions()`** a `Ledger` or `null` (see "Wallet" in
417
+ [docs/admin.md](docs/admin.md)).
693
418
  - **`flipstream.members.list({ limit, offset })`** gives a `Page<Member>`, and
694
- **`flipstream.members.get({ member_id })`** a `Member` (see "Your organisation's members").
419
+ **`flipstream.members.get({ member_id })`** a `Member` (see "Your organisation's members" in
420
+ [docs/admin.md](docs/admin.md)).
695
421
 
696
422
  **Every answer is checked against the API's spec.** An answer that doesn't match, with a missing
697
423
  field or a value of the wrong type, is an `invalid` failure that names the field. It never comes
698
424
  back as data. Some of a dataset's fields are read more leniently, so one new or missing backend
699
425
  value never makes a workspace's datasets unreadable: a `type` this version doesn't know is kept as
700
- it came, `created_on` and `created_by_id` are `null` when missing, and `history` is `null` when
701
- missing or when it holds a value this version doesn't know (see "A workspace's datasets"). A field the SDK doesn't know yet is kept, except in the answers of `me()`,
702
- `workspaces`, `log`, `datasets`, `wallet` and `members`, which hold only the fields their types name.
426
+ it came, `created_on` and `created_by_id` are `null` when missing, and `history` and
427
+ `refresh_status` are `null` when missing or when they hold a value this version doesn't know. A
428
+ member's `created_on` and `created_by_id` are `null` when missing too, and its `created_on` also
429
+ when it isn't a time, so one member's time never fails `me()` or a page of members. (See "A
430
+ workspace's datasets" and "Your organisation's members" in [docs/admin.md](docs/admin.md).) A field
431
+ the SDK doesn't know yet is kept, except in the answers of `me()`, `workspaces`, `log`, `datasets`,
432
+ `wallet` and `members`, which hold only the fields their types name.
703
433
 
704
434
  ## Typed errors
705
435
 
@@ -721,11 +451,19 @@ missing or when it holds a value this version doesn't know (see "A workspace's d
721
451
  - It keeps the API's `code` and `message` when the body is an error body, or its `text` when it
722
452
  isn't (a proxy's `Bad gateway`). The sign-ins' and the datasets' own reads and writes keep no
723
453
  `text`, since a body there may hold a sign-in's value (see "Sign-ins to your sources" and "A
724
- workspace's datasets"). The reads of your organisation and a workspace beside them keep theirs.
454
+ workspace's datasets" in [docs/admin.md](docs/admin.md)). The reads of your organisation and a
455
+ workspace beside them keep theirs.
456
+ - An `invalid` the SDK finds by checking an answer after it arrived (another organisation's record,
457
+ a page that leaks, an id that can't name the next path) has the `status` that route answers by
458
+ its backend's own code: 200 for every read, and for pause, resume and `log.update`. The SDK takes
459
+ any 2xx as ok, so that status is assumed, never observed. A check of a create's answer
460
+ (`workspaces.create`, `log.add`) has none, since that route's success status isn't known. When
461
+ the read after pause's or resume's write fails, the `invalid` keeps that read's status, if it had
462
+ one.
725
463
  - `isPlannerCode(error.code)` narrows the code to the ones the query API documents
726
464
  (`PlannerErrorCode`), so a switch over them can be exhaustive. A code added since is kept as it
727
465
  came.
728
- - When the API asked the caller to wait, the failure keeps that as `retryAfterMs`.
466
+ - When the API asked the caller to wait, the failure keeps that as `retry_after_ms`.
729
467
 
730
468
  **A `refused` call says why, in `reason`** (`RefusedReason`), and `orThrow`'s message names it,
731
469
  never the value:
@@ -756,7 +494,7 @@ function explain(error: ApiError): string {
756
494
  case 'rejected':
757
495
  return isPlannerCode(error.code) ? `${error.code}: ${error.message ?? ''}` : `Refused: ${String(error.status)}`
758
496
  case 'unavailable':
759
- return error.status === undefined ? 'No answer: offline?' : `Busy: try again in ${String(error.retryAfterMs ?? 1000)} ms`
497
+ return error.status === undefined ? 'No answer: offline?' : `Busy: try again in ${String(error.retry_after_ms ?? 1000)} ms`
760
498
  case 'invalid':
761
499
  return `An answer outside the contract: ${error.issues}`
762
500
  case 'timeout':
@@ -833,6 +571,14 @@ await flipstream.catalog.list({ conversationId: 'c-456', traceparent: '00-4bf92f
833
571
  - A wait that wouldn't end before the deadline isn't started.
834
572
  - **Deadlines:** 60 s for `query`, 10 s for `health` and 30 s for the rest (for `me`, its three
835
573
  reads together), every attempt and wait included. `deadlineMs` sets one call's.
574
+ - `deadlineMs` is taken in whole ms, rounded down, up to 2147483647, the most a timer holds;
575
+ left out or `null`, the endpoint's own applies. A value that can't be a deadline (not a number,
576
+ `NaN`, ±`Infinity`, or more than that once rounded down) is a `TypeError` naming the call, such
577
+ as `flipstream.catalog.list`, with nothing sent.
578
+ - A spent deadline answers `timeout` and sends nothing: one under 1 ms, or one used up before a
579
+ request would go out, say `me`'s last read once its three reads' 30 s are up.
580
+ - They run on the monotonic clock, as their timers do, so a clock change never moves them. Tests
581
+ that fake only `Date` must also move `performance.now()`, since every deadline runs on it.
836
582
  - **Abort:** `signal` ends a call at once, also while it waits for a token or to try again.
837
583
  - **Warnings:** the SDK's warnings go to `onWarning`, or to `console.warn` without it; `() => {}`
838
584
  silences them. Today there is one kind: a catalogue format type this version doesn't know,
@@ -841,7 +587,11 @@ await flipstream.catalog.list({ conversationId: 'c-456', traceparent: '00-4bf92f
841
587
  - **Your own transport:** an app that attaches the token itself passes `{ transport }` instead of
842
588
  `token` and `fetch`. Retries and deadlines still apply, above it. `health` carries no token, so
843
589
  it never goes through your transport: it goes to the query host, over https, with the global
844
- `fetch`.
590
+ `fetch`. When your transport rejects a request, the call rejects too, but only once none of its
591
+ reads is still waited on: the call ends its other reads at once, through their `signal`, and the
592
+ rejection is the first read's to reject, in the order the call started them. A failure that comes
593
+ back as a result keeps each call's own order. Your transport may still be running after the call
594
+ ended its read, or after a read's deadline; the SDK no longer waits for it.
845
595
 
846
596
  ## Which app sent a request
847
597
 
@@ -879,7 +629,7 @@ the SDK has no telemetry. In Node, each signed-in request to an API host carries
879
629
 
880
630
  ## Finding a request in Logs
881
631
 
882
- Every result says which trace its call's requests carried, as `traceId`, so a person can find them
632
+ Every result says which trace its call's requests carried, as `trace_id`, so a person can find them
883
633
  in Logs:
884
634
 
885
635
  ```ts
@@ -888,25 +638,25 @@ import { createFlipstream } from '@flipstream/sdk'
888
638
  const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
889
639
 
890
640
  const result = await flipstream.catalog.list()
891
- if (!result.ok) console.error(`${result.error.kind} (request ${result.traceId ?? 'not sent'})`)
641
+ if (!result.ok) console.error(`${result.error.kind} (request ${result.trace_id ?? 'not sent'})`)
892
642
  ```
893
643
 
894
- - **On both arms:** `{ ok: true, data, traceId }` and `{ ok: false, error, traceId }`. It's the
644
+ - **On both arms:** `{ ok: true, data, trace_id }` and `{ ok: false, error, trace_id }`. It's the
895
645
  W3C trace-id the call's `traceparent` carried: 32 lowercase hex digits.
896
646
  - **One call, one trace:** a call that makes several requests, such as `me()`'s reads or
897
647
  `workspaces.list()`'s two, sends them all under one trace-id, each with its own parent-id. So
898
648
  does a retry, and the resend after a 401.
899
- - **Your trace:** a call given your own `traceparent` keeps it, and `traceId` is its trace-id.
900
- - **Nothing sent, no `traceId`:** a call `refused` before anything is sent (a path, fields,
649
+ - **Your trace:** a call given your own `traceparent` keeps it, and `trace_id` is its trace-id.
650
+ - **Nothing sent, no `trace_id`:** a call `refused` before anything is sent (a path, fields,
901
651
  identification, the conversation's id, the destination) has none, and neither does a `no_token`
902
652
  from the first ask for a token.
903
653
  - **Once a request went out, the call has one,** whatever comes after: a `no_token` when the token
904
654
  function fails after a 401 (the refused request is the one to look up), or a `timeout` while a
905
655
  request is on its way. "Went out" means the SDK handed it to `fetch`: a host that was never
906
- reached (refused, or not found by DNS) gives `unavailable` with a `traceId` that no host logged.
907
- - **`orThrow`'s message ends with `(request <traceId>)`** when there is one, so a CLI or an app
656
+ reached (refused, or not found by DNS) gives `unavailable` with a `trace_id` that no host logged.
657
+ - **`orThrow`'s message ends with `(request <trace_id>)`** when there is one, so a CLI or an app
908
658
  that prints the error carries the id with no code of its own. The `ApiFailure` it throws has the
909
- id as `traceId` too, for a log field or an error tracker's tag:
659
+ id as `trace_id` too, for a log field or an error tracker's tag:
910
660
 
911
661
  ```ts
912
662
  import { ApiFailure, createFlipstream, orThrow } from '@flipstream/sdk'
@@ -916,17 +666,17 @@ if (!result.ok) console.error(`${result.error.kind} (request ${result.traceId ??
916
666
  try {
917
667
  orThrow(await flipstream.catalog.list())
918
668
  } catch (error) {
919
- if (error instanceof ApiFailure) console.error(error.error.kind, error.traceId ?? 'not sent')
669
+ if (error instanceof ApiFailure) console.error(error.error.kind, error.trace_id ?? 'not sent')
920
670
  }
921
671
  ```
922
672
 
923
673
  It's there only when the result had one, and only as a W3C trace-id.
924
674
  - **Only what reaches the API hosts is in it:** the auth server gets no `traceparent`, so a read
925
675
  made there, such as `me()`'s userinfo and person, isn't in the call's trace.
926
- - **With your own transport,** the SDK can't see the request leave, so a result has `traceId` once
676
+ - **With your own transport,** the SDK can't see the request leave, so a result has `trace_id` once
927
677
  an answer came back.
928
678
  - **Not from a browser yet:** a browser sends no `traceparent` (see "In a browser"), so its results
929
- have no `traceId`.
679
+ have no `trace_id`.
930
680
  - **The service's side:** finding the id needs the API hosts to log it, and Logs to index it. Until
931
681
  then, the id is still the one to quote.
932
682