@flipstream/sdk 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +179 -424
  3. package/dist/api/backend.d.ts +21 -3
  4. package/dist/api/backend.js +50 -10
  5. package/dist/api/backend.js.map +1 -1
  6. package/dist/api/credentials.js +4 -4
  7. package/dist/api/credentials.js.map +1 -1
  8. package/dist/api/datasets.d.ts +82 -14
  9. package/dist/api/datasets.js +193 -57
  10. package/dist/api/datasets.js.map +1 -1
  11. package/dist/api/index.d.ts +1 -1
  12. package/dist/api/log.d.ts +25 -20
  13. package/dist/api/log.js +63 -48
  14. package/dist/api/log.js.map +1 -1
  15. package/dist/api/me.js +9 -5
  16. package/dist/api/me.js.map +1 -1
  17. package/dist/api/members.d.ts +34 -1
  18. package/dist/api/members.js +67 -27
  19. package/dist/api/members.js.map +1 -1
  20. package/dist/api/wallet.d.ts +8 -5
  21. package/dist/api/wallet.js +40 -25
  22. package/dist/api/wallet.js.map +1 -1
  23. package/dist/api/workspaces.d.ts +35 -14
  24. package/dist/api/workspaces.js +53 -23
  25. package/dist/api/workspaces.js.map +1 -1
  26. package/dist/auth/discovery.d.ts +19 -6
  27. package/dist/auth/discovery.js +30 -6
  28. package/dist/auth/discovery.js.map +1 -1
  29. package/dist/auth/signIn.d.ts +18 -14
  30. package/dist/auth/signIn.js +29 -22
  31. package/dist/auth/signIn.js.map +1 -1
  32. package/dist/core/call.d.ts +13 -1
  33. package/dist/core/call.js +34 -9
  34. package/dist/core/call.js.map +1 -1
  35. package/dist/core/deadline.d.ts +30 -0
  36. package/dist/core/deadline.js +51 -0
  37. package/dist/core/deadline.js.map +1 -0
  38. package/dist/core/identify.d.ts +59 -14
  39. package/dist/core/identify.js +54 -20
  40. package/dist/core/identify.js.map +1 -1
  41. package/dist/core/invalid.d.ts +10 -0
  42. package/dist/core/invalid.js +28 -0
  43. package/dist/core/invalid.js.map +1 -0
  44. package/dist/core/names.d.ts +13 -2
  45. package/dist/core/names.js +11 -2
  46. package/dist/core/names.js.map +1 -1
  47. package/dist/core/notFound.d.ts +8 -0
  48. package/dist/core/notFound.js +8 -0
  49. package/dist/core/notFound.js.map +1 -0
  50. package/dist/core/read.d.ts +9 -0
  51. package/dist/core/read.js +14 -5
  52. package/dist/core/read.js.map +1 -1
  53. package/dist/core/result.d.ts +22 -13
  54. package/dist/core/result.js +5 -5
  55. package/dist/core/result.js.map +1 -1
  56. package/dist/core/retry.d.ts +5 -2
  57. package/dist/core/retry.js +6 -3
  58. package/dist/core/retry.js.map +1 -1
  59. package/dist/core/scope.d.ts +20 -0
  60. package/dist/core/scope.js +54 -0
  61. package/dist/core/scope.js.map +1 -0
  62. package/dist/core/shared.d.ts +39 -0
  63. package/dist/core/shared.js +177 -0
  64. package/dist/core/shared.js.map +1 -0
  65. package/dist/core/signal.d.ts +12 -0
  66. package/dist/core/signal.js +25 -0
  67. package/dist/core/signal.js.map +1 -0
  68. package/dist/flipstream.d.ts +223 -72
  69. package/dist/flipstream.js +225 -88
  70. package/dist/flipstream.js.map +1 -1
  71. package/dist/index.d.ts +1 -1
  72. package/dist/node/clientSecret.js +7 -6
  73. package/dist/node/clientSecret.js.map +1 -1
  74. package/dist/node/headless.d.ts +14 -6
  75. package/dist/node/headless.js +8 -6
  76. package/dist/node/headless.js.map +1 -1
  77. package/dist/node/index.d.ts +1 -1
  78. package/dist/node/index.js +1 -1
  79. package/dist/node/index.js.map +1 -1
  80. package/dist/node/keychainChild.js +26 -14
  81. package/dist/node/keychainChild.js.map +1 -1
  82. package/dist/node/keychainError.d.ts +3 -3
  83. package/dist/node/keychainStore.d.ts +10 -7
  84. package/dist/node/keychainStore.js +44 -23
  85. package/dist/node/keychainStore.js.map +1 -1
  86. package/dist/node/loopback.d.ts +13 -3
  87. package/dist/node/loopback.js +47 -5
  88. package/dist/node/loopback.js.map +1 -1
  89. package/dist/node/session.d.ts +17 -9
  90. package/dist/node/session.js +68 -50
  91. package/dist/node/session.js.map +1 -1
  92. package/dist/node/store.d.ts +35 -2
  93. package/dist/node/store.js +56 -12
  94. package/dist/node/store.js.map +1 -1
  95. package/dist/version.gen.js +1 -1
  96. package/docs/admin.md +558 -0
  97. package/docs/node-sign-in.md +63 -39
  98. package/package.json +1 -1
package/docs/admin.md ADDED
@@ -0,0 +1,558 @@
1
+ # Your organisation, its people and its workspaces: the reference
2
+
3
+ Part of `@flipstream/sdk`'s documentation, shipped in the package as `docs/admin.md`. Each
4
+ section's basics, and its most common example, are in the package's README under the same name
5
+ ([README.md](../README.md)).
6
+
7
+ ## Who you are
8
+
9
+ - **`organization`** is `{ id, name, slug, access }`. The slug is its short name, as the console's
10
+ addresses spell it.
11
+ - `access` says whether the organisation may use Flipstream, read from its billing settings by
12
+ the console's rules, in the service's own words:
13
+ - `{ status: 'trial', trial_ends_on }`: in trial, with `trial_ends_on` the trial's last day as
14
+ `YYYY-MM-DD`;
15
+ - `{ status: 'active' }`;
16
+ - `{ status: 'expired', trial_ends_on }`: the service's `expired`, which doesn't say why. Today
17
+ it only ever follows a trial. `trial_ends_on` is the trial's end, not necessarily the day
18
+ access ended;
19
+ - `{ status: 'unknown' }`: settings that can't be read, or a status this version doesn't know.
20
+ It's never read as active, and it never fails `me()`.
21
+ - The status is the truth. A trial past its last day stays `trial` until the service says
22
+ otherwise: the SDK never reads the clock for it. A day that isn't a real `YYYY-MM-DD` is `null`.
23
+ - Every role reads the same access, a viewer limited to some workspaces and Flipstream's own
24
+ staff included.
25
+ - **`user`** is
26
+ `{ id, email, first_name, last_name, role, roles, unknown_roles, active, workspace_ids, created_on, created_by_id }`:
27
+ a `Member`, as `flipstream.members` answers each person (see "Your organisation's members").
28
+ - `me()` reads the token's own person and doesn't apply `members`' people-only rule. An API key's
29
+ token isn't tested with it yet: service accounts come with pulse-admin#93. Every call under one
30
+ workspace reads you the same way, so the same holds there (see "The workspaces you open").
31
+ - `role` is the highest you hold: `'owner'`, `'admin'`, `'editor'` or `'viewer'`. It's `null`
32
+ when you hold none of them, and for Flipstream's own staff (`godmode`, `swapper`), whatever
33
+ else they hold. There's no guest role yet. A role this version doesn't know counts as none of
34
+ ours: it never fails the answer, a known role beside it still wins, and its name is never shown.
35
+ - `roles` is every one of those four you hold, highest first, so `roles[0]` is `role` whenever
36
+ you hold one. It's empty when you hold none, and for Flipstream's own staff, whatever else they
37
+ hold.
38
+ - `unknown_roles` counts the roles you hold that aren't ours, without naming them: a role this
39
+ version doesn't know, and the service's `user` and `client`, which it reads as none of ours.
40
+ Each counts once. Flipstream's own staff roles are never counted or named: a staff member's
41
+ other roles count as anyone's do.
42
+ - `active` says whether your account is switched on.
43
+ - `workspace_ids` are the workspaces your account names. The service limits only a viewer to them
44
+ (an account whose roles are exactly `['viewer']`), and a viewer with none opens every workspace
45
+ of the organisation. The SDK also holds a role read as none to them (see "The workspaces you
46
+ open").
47
+ - **Nothing else** from the services' answers is in it.
48
+ - **Three reads:** your organisation, and who your token belongs to, then that person. They share
49
+ one deadline, 30 s unless the call sets its own, and the first failure, in that order, is the
50
+ answer.
51
+ - **Renaming your organisation is a person's to do, in the console.**
52
+ `flipstream.organization.rename({ name })` never writes. It reads your organisation, then
53
+ answers `needs_person` with `why`. Where a console can be named (your own `hosts.console`, an
54
+ option of `createFlipstream`: see "Options" in [README.md](../README.md)), the organisation's
55
+ settings page is the `url`, with what it shows as `sees`, as `workspaces.rename` does. There,
56
+ Owners and Admins change the name and the short name. The `name` you give is never echoed.
57
+
58
+ ## Your organisation's members
59
+
60
+ - **A member** is
61
+ `{ id, email, first_name, last_name, role, roles, unknown_roles, active, workspace_ids, created_on, created_by_id }`,
62
+ and nothing else, with `role`, `roles`, `unknown_roles` and `workspace_ids` by `me()`'s rules (see
63
+ "Who you are"): the highest role they hold, or `null` for none and for Flipstream's own staff,
64
+ then every role of ours they hold, highest first, and a count of the rest. A role this version
65
+ doesn't know counts as none of ours, and its name is never shown.
66
+ - `created_on` is when their account was made, an ISO 8601 instant in UTC. For someone invited,
67
+ that's when they were invited if the invitation made it (an open invitation is in this list),
68
+ or when they accepted if accepting did. It's `null` when the service holds none, or one that
69
+ isn't a time: unlike a dataset's, it never fails the answer.
70
+ - `created_by_id` is the person who made their account, `null` when the service holds none.
71
+ - `flipstream.members.get({ member_id: created_by_id })` names the maker. When it doesn't answer
72
+ ok (see below), show the maker as unknown, for example for Flipstream's staff or an account
73
+ made by another organisation. The SDK doesn't guess which: a `not_found` may also be someone
74
+ your role can't read.
75
+ - **An open invitation is in the list:** someone invited who hasn't joined yet has an empty
76
+ `first_name`, as the console tells them apart.
77
+ - **Keys are left out by the service itself,** so `total` counts people.
78
+ - **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every member.
79
+ - The limit is 100 unless you set one, and at most 1,000.
80
+ - A limit or offset that isn't a whole number in range rejects, with nothing sent.
81
+ - **The order is the service's own:** by email. Pages read at different times can overlap, or skip
82
+ a person, when people are added or removed, or an email changes, in between. A changed `total`
83
+ shows some of that, but an unchanged one doesn't prove nothing moved. For a complete, stable
84
+ list, read it in one page: up to 1,000.
85
+ - **Each call reads your organisation beside the people,** under one deadline for both reads, and
86
+ its failure is the answer. In a list, a person of another organisation makes the answer
87
+ `invalid`; they're never shown or dropped.
88
+ - **What `get` answers,** for an id:
89
+ - **the person,** when they're one of your organisation's people;
90
+ - **`not_found`** when there's no such person for you: pulse-auth has none by that id, or your
91
+ role can't read them (it answers 404), or the id is one of your organisation's API keys, which
92
+ `get` answers as an id nobody has;
93
+ - **`forbidden`** when pulse-auth refuses the read (403);
94
+ - **`invalid`** when the answer is another organisation's person or API key, which only a staff
95
+ token reaches, such as Flipstream's staff acting through a swap token. The organisation is
96
+ checked before the key, so another organisation's key is `invalid` too. So is an answer that
97
+ is someone else than the person asked for.
98
+
99
+ ## The workspaces you open
100
+
101
+ - **Every call under one workspace holds it to the workspaces you open:** a workspace's `get`,
102
+ `rename` and `delete`; its logbook's `list`, and an entry's `get`, `add`, `update` and `remove`;
103
+ its datasets' `list` and `count`, and a dataset's `get`, `pause`, `resume` and `delete`.
104
+ - **Which you open:** an owner, an admin or an editor opens every workspace. Anyone else whose
105
+ account names workspaces opens only those: a viewer, and a role read as none (one this version
106
+ doesn't know, the service's `user` or `client`, or Flipstream's own staff). An account that names
107
+ no workspace opens every one, whatever its role, a role read as none included.
108
+ - **One you don't open is `not_found`,** exactly as one nobody has, so the answer says no more than
109
+ that. A write sends nothing, and a hand-off isn't made.
110
+ - **When it's checked:**
111
+ - **A workspace named up front** (a workspace's own calls, its logbook's `list` and `add`, its
112
+ datasets' `list` and `count`): your organisation and you are read first. One you don't open is
113
+ then `not_found` before anything under it is sent: no workspace read and no list, so its
114
+ datasets, with their embedded sign-ins, are never fetched, and a refusal of them can't tell it
115
+ apart. Then the workspace and its list are read side by side. Your organisation's failure, then
116
+ yours, then the workspace's, then the list's, is the answer.
117
+ - **A record named by its id** (an entry's `get`, `update` and `remove`; a dataset's `get`,
118
+ `pause`, `resume` and `delete`): its workspace is known only once the record is read, so you're
119
+ read beside it, and the service's own failure of that read is passed on as it came. Your
120
+ organisation's failure, then the record's, then yours, is the answer.
121
+ - **You're read as `flipstream.me()` reads you:** who your token belongs to, then that person, under
122
+ the call's deadline. That's one more round trip to the sign-in service per call, two reads in a
123
+ row, with nothing cached. In a scope, the calls of one piece of work share it (see "One piece of
124
+ work"). Your read's failure is the answer, with nothing written.
125
+ - **An API key's token isn't tested with it yet,** as with `me()`: service accounts come with
126
+ pulse-admin#93, and will need their own rule then.
127
+ - **The service's own limits still hold.** The SDK isn't a security boundary: it keeps its own
128
+ answers consistent, since the service doesn't yet hold a member to their workspaces on every
129
+ route. That's the root fix; until it lands, the SDK checks.
130
+ - **`workspaces.list` isn't held:** the service scopes it only for an account whose roles are
131
+ exactly `['viewer']`. So any other account the SDK holds to the workspaces it names, such as a
132
+ viewer holding another role beside it, or a role read as none, can list workspaces the other calls
133
+ answer `not_found` for.
134
+
135
+ ## One piece of work
136
+
137
+ - **A scope is one piece of work,** such as a page's load or a command. The calls in it share three
138
+ reads that every call outside a scope makes for itself, each time: your organisation, you (who
139
+ your token belongs to, then that person), and a workspace's own read, when several calls name
140
+ the same workspace.
141
+ - `const scope = flipstream.scope()` makes one, and each call takes it as `{ scope }`.
142
+ `await scope.close()` ends it, and works everywhere. `await using scope = flipstream.scope()`
143
+ closes it when the block ends, but only on a runtime that has `Symbol.asyncDispose`; with
144
+ TypeScript, `await using` also needs the `ESNext.Disposable` lib, or Node's types.
145
+ - `flipstream.withScope(async (f) => …)` does both for you: every call made through `f` is in the
146
+ scope, which is closed when your function settles, so it can't be left open. It answers what
147
+ your function answers, and rejects with what it throws. `f` has no scope of its own.
148
+ - A scope another client made is a `TypeError` naming the call, with nothing sent.
149
+ - A scope keeps each answer until it closes. It's one piece of work, never a session: what it
150
+ holds grows with the distinct reads that work makes.
151
+ - **The reads come from the service at the first call that needs them.** Every later call in the
152
+ scope reuses that read, whether it's still on its way or has answered. Nothing is taken on your
153
+ word. So three calls under one workspace send one organisation read, one read of you and one of
154
+ the workspace, then each call's own reads.
155
+ - **A shared read is the read of the call that started it:** that call's deadline and retries. So a
156
+ read that stalls ends at that call's deadline, however many calls join it, and a wait the service
157
+ asks for that the starting call can't fit is every waiting call's answer, as it would be the
158
+ starting call's outside a scope.
159
+ - **Each call keeps its own deadline and signal.** They end that call's wait, never the read: a call
160
+ that times out answers `timeout`, one that's aborted answers `aborted`, and the others still get
161
+ the read's answer. When the read times out at its starting call's deadline, a call still waiting
162
+ with time left reads again. A read no call waits on any more is ended.
163
+ - **Failures:**
164
+ - A failed shared read is the answer of every call waiting on it, as it would be outside a scope.
165
+ - A definitive one is then every later call's answer too, as its own copy, with no new read:
166
+ `forbidden`, `not_found`, `conflict`, `refused`, `rejected` but a 408 or a 425, and `invalid`
167
+ but a 2xx whose body isn't JSON or a status outside the contract (a proxy's or a portal's page,
168
+ or a sign-in gate's redirect).
169
+ - A transient one isn't kept, so the next call that needs it reads again: `unavailable`,
170
+ `timeout`, `aborted`, `no_token`, a 408 or 425, a body that isn't JSON, a status outside the
171
+ contract, or a transport that throws.
172
+ - **One identity a scope.** Two signals drop every shared read, so the next call reads them all
173
+ again: a 401 on a shared read, and an app's own transport answering one `cancelled`, since its
174
+ person or scope moved. A token that quietly switches to another person or organisation isn't seen
175
+ otherwise: close the scope on a sign-out or an organisation switch. A workspace of another
176
+ organisation, which only a staff token reaches, drops nothing: the call answers it `invalid`, as
177
+ it would outside a scope.
178
+ - **Each call reads the shared answer as it would its own,** with the answer's status. One that
179
+ needs only your organisation's id still answers when its short name is missing, and one that needs
180
+ the short name fails exactly as it would alone.
181
+ - **Closing a scope ends its reads still on their way,** and a call still waiting on one answers
182
+ `aborted`. A call that takes a closed scope reads its own, as outside a scope: a late refetch is
183
+ fine.
184
+ - **A shared read goes out under a trace of its own,** never a caller's `traceparent`, and every call
185
+ it answers names that trace in `trace_id` (see "Finding a request in Logs" in
186
+ [README.md](../README.md)): the read's whose failure is the call's answer, else the call's own
187
+ requests', else the first shared read the call asked for.
188
+
189
+ ## Workspaces
190
+
191
+ - **A workspace** is `{ id, name, slug, services }`. Nothing else the service sends is in it.
192
+ - **`services` says which services are on in it,** read from the workspace's `meta` field as the
193
+ console reads it (#291), so an app and the console agree. One exception: a `meta` that comes as
194
+ something other than text reads `unreadable` here, where the console can't read that workspace
195
+ at all.
196
+ - `{ status: 'known', on }`, with `on` the keys of the services that are on, as the backend
197
+ stores them, such as `['trackers']`, or `[]` when none is;
198
+ - `{ status: 'unreadable' }` when the workspace's `meta` can't be read. The services are then
199
+ neither on nor off: say they can't be read, not that they're off. The workspace still reads.
200
+
201
+ Turning a service on isn't in the SDK yet.
202
+ - **A page** is `{ items, total, limit, offset }`. `total` counts every workspace, and `limit` and
203
+ `offset` say what was read. `limit` is 100 when left out and at most 1,000, and a larger one is
204
+ read as 1,000. A limit or offset that isn't a whole number in range rejects with a `TypeError`,
205
+ with nothing sent.
206
+ - **The order is the service's own:** by name alone, for workspaces. Pages read at different times
207
+ can overlap, or skip a workspace, when workspaces are added, removed or renamed in between, or
208
+ when two have the same name. A changed `total` shows some of that, but an unchanged one doesn't
209
+ prove nothing moved. For a complete, stable list, read it in one page: up to 1,000.
210
+ - **Each call reads your organisation first,** and a call under one workspace you too, under one
211
+ deadline, and the first failure is the answer. A workspace of another organisation makes the
212
+ answer `invalid`; it's never shown or dropped. One you don't open is `not_found` (see "The
213
+ workspaces you open").
214
+ - **Creating a workspace:** `flipstream.workspaces.create({ name })` makes one in your organisation
215
+ and answers it as a `Workspace`.
216
+
217
+ ```ts
218
+ import { createFlipstream, orThrow } from '@flipstream/sdk'
219
+
220
+ const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
221
+
222
+ const made = orThrow(await flipstream.workspaces.create({ name: 'Acme NL' }))
223
+ console.log(made.id, made.slug) // the short name the service chose, such as 'acme-nl-2'
224
+ ```
225
+
226
+ - It sends the name alone, with your organisation. The service makes the short name, unique in
227
+ your organisation, so read `slug` from the answer.
228
+ - **A request with any key but `name` is `refused`** (`reason: 'fields'`, naming them), with
229
+ nothing sent: a `slug` or an `organization_id` it dropped would look set. A `name` that isn't a
230
+ non-empty string, or is only spaces, rejects with a `TypeError`, with nothing sent.
231
+ - Who may create one is the service's rule, not the SDK's: Owners and Admins. pulse-admin#181
232
+ aligns the service with it; until then an Editor still succeeds. Anyone it refuses gets
233
+ `forbidden`.
234
+ - **It's never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
235
+ `no_token` shows nothing was made. After any other failure (`timeout`, `unavailable`,
236
+ `aborted`, `cancelled`, or `invalid`, which may be the service's answer that it made one) it may
237
+ have been made, so list the workspaces before you create it again. Names needn't be unique, so
238
+ compare that list with one from before you created it.
239
+ - **Renaming or deleting a workspace is a person's to do, in the console.**
240
+ `flipstream.workspaces.rename({ workspace_id, name })` and `delete({ workspace_id })` never write.
241
+ Each reads the workspace (one that isn't yours is `not_found`), then answers `needs_person`:
242
+
243
+ ```ts
244
+ import { createFlipstream } from '@flipstream/sdk'
245
+
246
+ const flipstream = createFlipstream({
247
+ app: { name: 'my-app', version: '1.0.0' },
248
+ token: async () => '<your token>',
249
+ hosts: { console: 'http://localhost:5173' },
250
+ })
251
+
252
+ const result = await flipstream.workspaces.rename({ workspace_id: '<workspace id>', name: 'New name' })
253
+ if (!result.ok && result.error.kind === 'needs_person') {
254
+ console.log(result.error.why) // tell the person what to do, and why
255
+ if (result.error.url !== undefined) console.log(result.error.url, result.error.sees)
256
+ }
257
+ ```
258
+
259
+ - `why` is the SDK's own words, never a value you gave, so it's safe to show.
260
+ - `url` and `sees` name the workspace's settings page, and are there only when a console can be
261
+ named: set `hosts.console` (for example `http://localhost:5173`, while developing). It must be
262
+ https, or http on this machine, with no query, fragment or credentials, or `createFlipstream`
263
+ throws a `TypeError`.
264
+ - `orThrow` throws it as an `ApiFailure` whose message gives `why`.
265
+
266
+ ## A workspace's logbook
267
+
268
+ - **An entry** is `{ id, description, start_date, end_date, workspace_id, created_on, created_by_id }`,
269
+ and nothing else.
270
+ - `start_date` and `end_date` are ISO 8601 instants in UTC, such as `2026-10-05T00:00:00.000Z`.
271
+ - A point in time starts and ends at once.
272
+ - `created_on` is when it was written, in the same form, and `created_by_id` the person who wrote
273
+ it. Either is `null` when the service holds none.
274
+ - `flipstream.members.get({ member_id: created_by_id })` names the writer. When it doesn't answer
275
+ ok (see "Your organisation's members"), show the writer as unknown, for example for an entry
276
+ Flipstream staff wrote through a swap token.
277
+ - **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every entry.
278
+ - The limit is 100 unless you set one, and at most 1,000.
279
+ - A limit or offset that isn't a whole number in range rejects, with nothing sent.
280
+ - **The order is newest written first:** the logbook's own, since the SDK asks for no other.
281
+ - When an entry was written never changes, so editing an entry doesn't move it.
282
+ - Pages read at different times can still overlap or skip an entry, when one is written or
283
+ removed in between.
284
+ - Entries written at the same moment have no fixed order among themselves.
285
+ - A changed `total` shows that something was added or removed; an unchanged one doesn't prove
286
+ nothing was.
287
+ - **Your organisation and you are read first, then the workspace beside the list,** under one
288
+ deadline: one you don't open (see "The workspaces you open"), or one nobody has, is `not_found`,
289
+ and another organisation's is `invalid`, never an empty page. Your organisation's failure, then
290
+ yours, then the workspace's, then the list's, is the answer.
291
+ - **An entry of another workspace or organisation** in the list makes the answer `invalid`; it's
292
+ never dropped.
293
+ - **A missing entry:** `get` answers `not_found`, and so does one in a workspace you don't open.
294
+ `get` reads your organisation beside the entry, and an answer that is another entry than the one
295
+ asked for, or another organisation's, is `invalid`.
296
+
297
+ **One member's entries,** in every workspace of your organisation, for a person's page for example:
298
+ `list({ member_id })` instead of `{ workspace_id }`.
299
+
300
+ ```ts
301
+ import { createFlipstream, orThrow } from '@flipstream/sdk'
302
+
303
+ const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
304
+
305
+ const theirs = orThrow(await flipstream.log.list({ member_id: '<member id>', limit: 5 }))
306
+ for (const entry of theirs.items) console.log(entry.start_date, entry.workspace_id, entry.description)
307
+ ```
308
+
309
+ - **Exactly one of `workspace_id` and `member_id`:** both, or neither, rejects with a `TypeError`,
310
+ with nothing sent.
311
+ - **You and the member are read first,** with your organisation, under one deadline. A person who
312
+ isn't a member, or a key, is `not_found`, and another organisation's member `invalid`, and no
313
+ entries are asked for. Your organisation's failure, then yours, then the member's, is the answer.
314
+ - **Every entry must be the member's, your organisation's, and in a workspace you open.** If your
315
+ account names workspaces, you open only those, unless you're an owner, an admin or an editor;
316
+ otherwise you open every one. Any other entry makes the answer `invalid`; none is dropped.
317
+ - **The page and the order** are a workspace's: the backend's, newest written first.
318
+
319
+ **Writing to it:** `add`, `update` and `remove`.
320
+
321
+ ```ts
322
+ import { createFlipstream, orThrow } from '@flipstream/sdk'
323
+
324
+ const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
325
+
326
+ const added = orThrow(
327
+ 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' }),
328
+ )
329
+ orThrow(await flipstream.log.update({ log_id: added.id, description: 'Site migration, phase 1' }))
330
+ orThrow(await flipstream.log.remove({ log_id: added.id })) // null
331
+ ```
332
+
333
+ - **What each takes,** before anything is sent:
334
+ - a key it doesn't send is `refused` (`reason: 'fields'`, naming them);
335
+ - a description that isn't a non-blank string, a time not written as `2026-10-05T00:00:00Z`, or a
336
+ start after the end rejects with a `TypeError`. A fraction may follow the seconds, and an offset
337
+ such as `+02:00`, or none, may take the place of the `Z`. A time with no offset is read as UTC,
338
+ and every time is sent as a UTC instant.
339
+ - **Each write reads first.** `add` reads the workspace: one nobody has, or one you don't open, is
340
+ `not_found`, and another organisation's is `invalid`, with nothing written. `update` and `remove`
341
+ read the entry, held to your organisation and your workspaces the same way.
342
+ - **`update` changes what you give,** at least one of `description`, `start_date` and `end_date`,
343
+ and sends the rest back exactly as stored. When you give a time, a start after the stored end
344
+ (or an end before the stored start) rejects with a `TypeError`, with nothing written. Since the
345
+ whole entry goes back, a change someone else made between `update`'s read and its write is
346
+ overwritten.
347
+ - **`remove` answers `null`.** A log entry's remove is direct; it's not handed to a person.
348
+ - **Who may write is the service's rule, not the SDK's:** Owners, Admins and Editors add; an Editor
349
+ changes or removes only their own entries, and Owners and Admins any. Until the service enforces
350
+ it (pulse-admin#161, for Editors), a Viewer can also add, change and remove entries, and an Editor
351
+ can change anyone's. Anyone it refuses gets `forbidden`.
352
+ - **A write is never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
353
+ `no_token` shows nothing was written. After any other failure it may have been, so list the
354
+ logbook before you write again.
355
+
356
+ ## A workspace's datasets
357
+
358
+ - **A dataset** is
359
+ `{ id, name, workspace_id, type, active, created_on, created_by_id, history, refresh_status, account }`, and
360
+ nothing else: never a credential, a setting or its parameters, beyond its account's id. The
361
+ service's answer embeds the dataset's sign-in, so a body that isn't the service's JSON is never
362
+ kept either: a failure of the dataset's own read or write gives its kind and status, with no
363
+ `text`. The reads of your organisation and the workspace beside it keep theirs.
364
+ - `type` is one of the types `datasetTypes.list()` gives, such as `'google_search_console'`, or
365
+ a type this version doesn't know yet, kept as it came, so a new kind of dataset never makes the
366
+ list unreadable. It's `null` when the service holds no type for it.
367
+ - `active` says whether it's switched on.
368
+ - `created_on` is when it was made, an ISO 8601 instant in UTC, and `created_by_id` the person who
369
+ made it. Either is `null` when the service holds none.
370
+ - `flipstream.members.get({ member_id: created_by_id })` names the maker. When it doesn't answer
371
+ ok (see "Your organisation's members"), show the maker as unknown, for example for a dataset
372
+ Flipstream staff made through a swap token.
373
+ - `history` says how much of its history is in the warehouse, a `DatasetHistory`, in the
374
+ service's own values (the SDK renames fields, never values):
375
+ - `'not_available'`: no history is loaded for its kind of dataset;
376
+ - `'todo'`: its history hasn't started loading. Every new dataset starts here, and the
377
+ pipeline sets `'not_available'` only when it first runs for one, so `'todo'` may never start
378
+ for a type that loads no history;
379
+ - `'started'`: its history is loading, from the first load until it's in; a load that keeps
380
+ failing stays `'started'`;
381
+ - `'done'`: its history is in.
382
+
383
+ Merge them as your app needs: the console shows `'todo'` and `'started'` alike as "coming in".
384
+ It's `null` when it's unknown, because the service holds none or a value this version doesn't
385
+ know: show "Not available yet" then, never a value of your own.
386
+ - `refresh_status` is the service's record of the last request to rebuild the dataset's
387
+ custom-dimension tables, a `DatasetRefreshStatus`, as the service left it, in its own values. A
388
+ rebuild is asked for when the custom dimensions change, and the pipeline writes back what it
389
+ did; nothing else moves it on. So each value is the last one written, never a promise of what
390
+ comes next or when, and it says nothing of the daily load. As pulse-admin dff6bf9b
391
+ (`change_custom_dimensions.py`) and pulse-dagster 040fcf4 (`ops/transform.py`) write it:
392
+ - `'idle'`: the default; every new dataset starts here;
393
+ - `'data_refresh_requested'`: a rebuild was asked for and the pipeline hasn't taken it up. It
394
+ can stay so: a run skips a dataset none of whose tables it builds, or one that shares its
395
+ tables with a dataset the run already built;
396
+ - `'data_refresh_in_progress'`: the pipeline took it up. It can stay so for good: only a build
397
+ that fails is written back as `'data_refresh_failed'`, so a run that stops another way, or a
398
+ write back that fails, leaves it here, and a change of the custom dimensions asks for nothing
399
+ from here;
400
+ - `'data_refresh_completed'`: the pipeline finished a rebuild. It may be one made with the
401
+ custom dimensions from before a change: a change made while one is in progress asks for no
402
+ new one;
403
+ - `'data_refresh_failed'`: the pipeline's rebuild failed. A change of the custom dimensions asks
404
+ for a new one.
405
+
406
+ Show it as what it is, the custom dimensions' rebuild, never as the dataset's health. It's
407
+ `null` when it's unknown, because the service holds none or a value this version doesn't know:
408
+ show it as unknown then, never as idle.
409
+ - `account` says which account it reads, a `DatasetAccount`, as the console labels a dataset:
410
+ - `id` is the id as the service holds it: a string as stored, or a whole number from 1 to
411
+ 2^53 - 1 as its digits. Use it to find or send back the stored id;
412
+ - `shown` is the id as its source writes it, trimmed: a Google Ads id as `'412-883-1024'`, any
413
+ other as `id`, such as `'sc-domain:acme.nl'`. Compare two accounts of one `type` by `shown`,
414
+ as the console's connect dialog does within one source, so a Google Ads account stored as
415
+ `'4128831024'` and as `'412-883-1024'` is one account. Across types, two ids can be the same
416
+ digits for different accounts.
417
+
418
+ The SDK reads the key a type keeps its account under, and only its id: Search Console,
419
+ Analytics and Google Ads keep a property, Business Profile a location, Meta Ads and LinkedIn
420
+ Ads an account (an older LinkedIn Ads dataset a property), Facebook Pages a page. It's `null`
421
+ for any other type, or when the service holds no readable id: show the dataset's name then.
422
+ The console shows a label where the SDK says `null` only for an id the SDK refuses, because it
423
+ can't show it safely or exactly: one longer than 512 UTF-16 code units, one with a control or
424
+ format character or a line or paragraph separator in it (a terminal escape, say), or a finite
425
+ number that isn't a whole one from 1 to 2^53 - 1. A refused id ends the read: the SDK never
426
+ shows another key's account in its place, such as an older LinkedIn Ads dataset's property.
427
+ - **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every dataset.
428
+ - The limit is 100 unless you set one, and at most 1,000.
429
+ - A limit or offset that isn't a whole number in range rejects, with nothing sent.
430
+ - **The order is the service's own:** by name alone. Pages read at different times can overlap, or
431
+ skip a dataset, when datasets are added, removed or renamed in between, or when two have the same
432
+ name. A changed `total` shows some of that, but an unchanged one doesn't prove nothing moved. For
433
+ a complete, stable list, read it in one page: up to 1,000.
434
+ - **Each call reads your organisation and you,** and a workspace's list reads its workspace too,
435
+ under one deadline for every read. A workspace's list reads your organisation and you first, then
436
+ the workspace beside the datasets, so your organisation's failure, then yours, then the
437
+ workspace's, then the list's, is the answer. A dataset of another organisation, or in the list one
438
+ of another workspace, makes the answer `invalid`; it's never shown or dropped.
439
+ - **A workspace nobody has** is `not_found`, and so is one you don't open (see "The workspaces you
440
+ open").
441
+ Another organisation's is `invalid`: never an empty page, which would say it has no datasets.
442
+ - **Your organisation's datasets:** `list({ organization: true })`, in place of `workspace_id`,
443
+ lists them in every workspace you open, paged and ordered as a workspace's are.
444
+ - Exactly one of the two: both, neither, or an `organization` that isn't `true` rejects with a
445
+ `TypeError`, with nothing sent.
446
+ - Your organisation is read first, since its id names the route, and the list once it answers,
447
+ with you read beside both: two round trips in a row, under the same deadline. No workspace is
448
+ read. Your organisation's failure, then yours, then the list's, is the answer; an organisation
449
+ id that can't name the route counts as your organisation's failure.
450
+ - Every dataset must be your organisation's and in a workspace you open: if your account names
451
+ workspaces, only those, unless you're an owner, an admin or an editor. Any other makes the
452
+ answer `invalid`; it's never shown or dropped. The service holds a viewer to their workspaces
453
+ too, so this is a second check.
454
+ - **A workspace's count:** `count({ workspace_id })` answers `{ count }`, how many datasets the
455
+ workspace has, from the service's own count: the total of one page of one dataset, read as
456
+ `list` reads a page.
457
+ - Of that dataset only its workspace and organisation are read, so one `list` would refuse for
458
+ anything else can't lose the count; one of another workspace or organisation makes it
459
+ `invalid`, as does a page whose count is smaller than its datasets, or above 0 with none
460
+ on it.
461
+ - The workspace is read beside it, as `list` reads it: one you don't open, or one nobody has, is
462
+ `not_found`, and another organisation's `invalid`, never a count of 0. The organisation's
463
+ failure, then yours, then the workspace's, then the count's, is the answer. A `workspace_id` that isn't a string rejects with a
464
+ `TypeError`, with nothing sent. There's no count across your organisation yet.
465
+ - The console's Warehouse → Datasets shows counts of its own: it counts the datasets it lists,
466
+ and a tracker list once, so its numbers can differ from this one.
467
+ - **A missing dataset:** `get` answers `not_found`, and so does one in a workspace you don't open.
468
+ An answer that is another dataset than the one asked for is `invalid`.
469
+ - **`datasetTypes.list()`** sends nothing: the types are the SDK's own list, since the service has
470
+ no route for them yet. Each call gives you a list of your own.
471
+
472
+ **Pausing and resuming:** `pause` and `resume`.
473
+
474
+ ```ts
475
+ import { createFlipstream, orThrow } from '@flipstream/sdk'
476
+
477
+ const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
478
+
479
+ const paused = orThrow(await flipstream.datasets.pause({ dataset_id: '<dataset id>' }))
480
+ console.log(paused.active) // false
481
+ orThrow(await flipstream.datasets.resume({ dataset_id: '<dataset id>' })) // active: true
482
+ ```
483
+
484
+ - **Each answers the `Dataset`,** with `active` as asked. Pausing a paused dataset sends the same
485
+ write and answers the same, so calling either twice is the same as once.
486
+ - **What each takes,** before anything is sent: `dataset_id` alone. Any other key is `refused`
487
+ (`reason: 'fields'`, naming them), and an id that isn't a string rejects with a `TypeError`.
488
+ - **Each reads first:** the dataset, fresh, beside your organisation and you. One nobody has, or
489
+ one in a workspace you don't open, is `not_found`, and another organisation's is `invalid`, with
490
+ nothing written. Then `active` alone is sent, so a rename made in between stays.
491
+ - **Each reads again after the write,** fresh, and answers that read. One whose `active` isn't the
492
+ one asked for is `invalid`, since the write may not have been stored, as is one of another
493
+ dataset, workspace or organisation. That read comes after the write was sent, so its failure
494
+ is never answered as a refusal: a 4xx kind, `refused` or `no_token` there is `invalid`, naming
495
+ its kind, with that read's status when it had one (a 4xx's). A `timeout`, `aborted`, `cancelled`, `unavailable` or `invalid` there keeps its kind,
496
+ since it already says the write may have been made.
497
+ - **Who may is the service's rule:** Owners, Admins and Editors pause and resume, and a Viewer
498
+ doesn't. Anyone it refuses gets `forbidden`.
499
+ - **A write is never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
500
+ `no_token` shows nothing was written. After any other failure it may have been; calling it
501
+ again is safe, since it's the same write.
502
+
503
+ **Deleting a dataset is a person's to do, in the console.** It removes the dataset's data for good,
504
+ and the console can't delete a dataset yet. `flipstream.datasets.delete({ dataset_id })` never
505
+ writes. It reads the dataset first: one nobody has, or one in a workspace you don't open (see "The
506
+ workspaces you open"), is `not_found`, and another organisation's is `invalid`. Then it answers
507
+ `needs_person` with `why`, and, where a console can be named (your own `hosts.console`), the
508
+ dataset's page as `url`, with what it shows as `sees`, as `workspaces.delete` does.
509
+
510
+ ## Sign-ins to your sources
511
+
512
+ - **A credential** is `{ id, name, type, datasource_types, created_on }`, and nothing else.
513
+ - `name` is the provider account it signs in as: for a Google sign-in, that account's email
514
+ address.
515
+ - `type` is what kind of sign-in it is, such as `'oauth2'` or `'service_account'`. A kind this
516
+ version doesn't know is kept as it came, and it's `null` when the service holds none.
517
+ - `datasource_types` lists the kinds of dataset it serves, such as `'google_search_console'`.
518
+ - `created_on` is an ISO 8601 instant in UTC.
519
+ - **Never a value.** The service doesn't mask a sign-in, so the SDK checks every answer itself. An
520
+ answer holding what may be a sign-in's value (a `data` that isn't empty, or a key such as
521
+ `refresh_token`, `apiKey`, `auth_values` or `password`, at any depth, however it's spelt) is
522
+ `invalid`. Its issues name the place, never the value, and nothing is answered at all. A body
523
+ that isn't the service's JSON is never kept either: a failure of the sign-ins' own reads gives
524
+ its kind and status, with no `text`. The read of your organisation beside them keeps its.
525
+ - **A list is one page:** `{ items, total, limit, offset }`, as every list is. The limit is 100
526
+ unless you set one, and at most 1,000.
527
+ - **It reads your organisation first,** for its id, and its failure is the answer. A sign-in of
528
+ another organisation makes the answer `invalid`.
529
+ - **Who may list them is the service's rule:** today Owners, Admins, Editors and Viewers. Anyone
530
+ it refuses gets `forbidden`.
531
+ - **Revoking or deleting a sign-in is a person's to do, in the console.** Either breaks every
532
+ dataset that reads with it. `flipstream.credentials.revoke({ credential_id })` and
533
+ `delete({ credential_id })` never write. Each reads the sign-in first: one nobody has is
534
+ `not_found`, and another organisation's is `invalid`. Then it answers `needs_person` with `why`.
535
+ There's no `url` yet: no console page names a sign-in.
536
+
537
+ ## Wallet
538
+
539
+ - **Amounts are whole numbers of micro,** and every answer that holds them says how many make a
540
+ euro, in `micro_per_euro`. Divide by it, never by a number of your own: the basis can change.
541
+ Both reads answer `null` when your organisation has no wallet, and `null` holds no amounts.
542
+ - **`balance()`** is `{ balance_micro, micro_per_euro }`, or `null` when your organisation has no
543
+ wallet. No wallet is a real state, so it's not an error, and it's never a zero balance: €0.00
544
+ would claim a wallet that holds nothing.
545
+ - **`transactions()`** is the whole ledger, in one answer, with no paging: `{ items, micro_per_euro }`,
546
+ or `null` when your organisation has no wallet, as `balance()` is. A wallet with no rows is
547
+ `{ items: [] }`, never `null`. The ledger's rows don't name their wallet, so the balance is read
548
+ beside it, and the ledger is answered only when that's your organisation's wallet. The balance
549
+ settles no wallet: the answer is `null` even when the ledger can't be read, and a row then is
550
+ `invalid`, as is a ledger answer the SDK can't read, which may hold rows. Each row
551
+ is `{ id, type, dataset_id, description, amount_micro, quantity, unit_price_micro, created_on }`.
552
+ A row that charged no dataset, such as a credit, has `dataset_id: null`, whether the wallet
553
+ wrote its `connection_id` empty or null. `created_on` is an
554
+ ISO 8601 instant in UTC, such as `2026-10-31T13:08:25.312Z`, as the logbook's times are. A type
555
+ this version doesn't know is kept as it came.
556
+ - **Who may read it is the wallet's rule, not the SDK's.** Today that's Owners and Admins, and
557
+ Editors too once pulse-wallet#15 lands. Anyone the wallet refuses gets `forbidden`, never an
558
+ empty ledger.