@flipstream/sdk 0.11.0 → 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.
- package/CHANGELOG.md +48 -0
- package/README.md +97 -412
- package/dist/api/backend.d.ts +10 -0
- package/dist/api/backend.js +24 -4
- package/dist/api/backend.js.map +1 -1
- package/dist/api/credentials.js +4 -4
- package/dist/api/credentials.js.map +1 -1
- package/dist/api/datasets.d.ts +82 -14
- package/dist/api/datasets.js +193 -57
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/log.d.ts +25 -20
- package/dist/api/log.js +63 -48
- package/dist/api/log.js.map +1 -1
- package/dist/api/me.js +7 -4
- package/dist/api/me.js.map +1 -1
- package/dist/api/members.d.ts +34 -1
- package/dist/api/members.js +67 -27
- package/dist/api/members.js.map +1 -1
- package/dist/api/wallet.d.ts +8 -5
- package/dist/api/wallet.js +36 -24
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +28 -7
- package/dist/api/workspaces.js +46 -16
- package/dist/api/workspaces.js.map +1 -1
- package/dist/auth/discovery.d.ts +19 -6
- package/dist/auth/discovery.js +25 -4
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.d.ts +18 -14
- package/dist/auth/signIn.js +29 -22
- package/dist/auth/signIn.js.map +1 -1
- package/dist/core/call.d.ts +4 -1
- package/dist/core/call.js +26 -6
- package/dist/core/call.js.map +1 -1
- package/dist/core/deadline.d.ts +30 -0
- package/dist/core/deadline.js +51 -0
- package/dist/core/deadline.js.map +1 -0
- package/dist/core/invalid.d.ts +7 -0
- package/dist/core/invalid.js +22 -0
- package/dist/core/invalid.js.map +1 -0
- package/dist/core/names.d.ts +13 -2
- package/dist/core/names.js +11 -2
- package/dist/core/names.js.map +1 -1
- package/dist/core/notFound.d.ts +8 -0
- package/dist/core/notFound.js +8 -0
- package/dist/core/notFound.js.map +1 -0
- package/dist/core/result.d.ts +17 -12
- package/dist/core/result.js +5 -5
- package/dist/core/result.js.map +1 -1
- package/dist/core/retry.d.ts +5 -2
- package/dist/core/retry.js +6 -3
- package/dist/core/retry.js.map +1 -1
- package/dist/core/scope.d.ts +20 -0
- package/dist/core/scope.js +54 -0
- package/dist/core/scope.js.map +1 -0
- package/dist/flipstream.d.ts +136 -69
- package/dist/flipstream.js +67 -45
- package/dist/flipstream.js.map +1 -1
- package/dist/node/clientSecret.js +5 -5
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/headless.d.ts +14 -6
- package/dist/node/headless.js +8 -6
- package/dist/node/headless.js.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.js +26 -14
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +3 -3
- package/dist/node/keychainStore.d.ts +10 -7
- package/dist/node/keychainStore.js +44 -23
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/loopback.d.ts +8 -1
- package/dist/node/loopback.js +19 -2
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +17 -9
- package/dist/node/session.js +55 -44
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +35 -2
- package/dist/node/store.js +56 -12
- package/dist/node/store.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/admin.md +503 -0
- package/docs/node-sign-in.md +60 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,51 +96,14 @@ const { organization, user } = orThrow(await flipstream.me())
|
|
|
96
96
|
console.log(organization.name, user.email, user.role)
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
|
|
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
|
|
116
|
-
`{ id, email, first_name, last_name, role, active, workspace_ids, created_on, created_by_id }`: a
|
|
117
|
-
`Member`, as `flipstream.members` answers each person (see "Your organisation's members").
|
|
118
|
-
- `me()` reads the token's own person and doesn't apply `members`' people-only rule. An API key's
|
|
119
|
-
token isn't tested with it yet: service accounts come with pulse-admin#93.
|
|
120
|
-
- `role` is the highest you hold: `'owner'`, `'admin'`, `'editor'` or `'viewer'`. It's `null`
|
|
121
|
-
when you hold none of them, and for Flipstream's own staff (`godmode`, `swapper`), whatever
|
|
122
|
-
else they hold. There's no guest role yet. A role this version doesn't know counts as none of
|
|
123
|
-
ours: it never fails the answer, a known role beside it still wins, and its name is never shown.
|
|
124
|
-
- `active` says whether your account is switched on.
|
|
125
|
-
- `workspace_ids` are the workspaces your account names. For a viewer, they're the workspaces
|
|
126
|
-
you may open, and a viewer with none opens every workspace of the organisation. No other role
|
|
127
|
-
is limited by them.
|
|
128
|
-
- **Nothing else** from the services' answers is in it.
|
|
129
|
-
- **Three reads:** your organisation, and who your token belongs to, then that person. They share
|
|
130
|
-
one deadline, 30 s unless the call sets its own, and the first failure, in that order, is the
|
|
131
|
-
answer.
|
|
132
|
-
- **Renaming your organisation is a person's to do, in the console.**
|
|
133
|
-
`flipstream.organization.rename({ name })` never writes. It reads your organisation, then
|
|
134
|
-
answers `needs_person` with `why`. Where a console can be named (your own `hosts.console`), the
|
|
135
|
-
organisation's settings page is the `url`, with what it shows as `sees`, as `workspaces.rename`
|
|
136
|
-
does. There, Owners and Admins change the name and the short name. The `name` you give is never
|
|
137
|
-
echoed.
|
|
99
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "Who you are".
|
|
138
100
|
|
|
139
101
|
## Your organisation's members
|
|
140
102
|
|
|
141
103
|
`flipstream.members` reads the people of your organisation, one page at a time, each as `me()`
|
|
142
104
|
answers you. People, not keys: an API user, a service account, is never listed, counted or
|
|
143
|
-
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).)
|
|
144
107
|
|
|
145
108
|
```ts
|
|
146
109
|
import { createFlipstream, orThrow } from '@flipstream/sdk'
|
|
@@ -154,43 +117,7 @@ const member = orThrow(await flipstream.members.get({ member_id: page.items[0]?.
|
|
|
154
117
|
console.log(member.first_name, member.workspace_ids.length)
|
|
155
118
|
```
|
|
156
119
|
|
|
157
|
-
|
|
158
|
-
`{ id, email, first_name, last_name, role, active, workspace_ids, created_on, created_by_id }`,
|
|
159
|
-
and nothing else, with `role` and `workspace_ids` by `me()`'s rules (see "Who you are"): the
|
|
160
|
-
highest role they hold, or `null` for none and for Flipstream's own staff. A role this version
|
|
161
|
-
doesn't know counts as none of ours, and its name is never shown.
|
|
162
|
-
- `created_on` is when their account was made, an ISO 8601 instant in UTC. For someone invited,
|
|
163
|
-
that's when they were invited if the invitation made it (an open invitation is in this list),
|
|
164
|
-
or when they accepted if accepting did. It's `null` when the service holds none, or one that
|
|
165
|
-
isn't a time: unlike a dataset's, it never fails the answer.
|
|
166
|
-
- `created_by_id` is the person who made their account, `null` when the service holds none.
|
|
167
|
-
- `flipstream.members.get({ member_id: created_by_id })` names the maker. When it doesn't answer
|
|
168
|
-
ok (see below), show the maker as unknown, for example for Flipstream's staff or an account
|
|
169
|
-
made by another organisation. The SDK doesn't guess which: a `not_found` may also be someone
|
|
170
|
-
your role can't read.
|
|
171
|
-
- **An open invitation is in the list:** someone invited who hasn't joined yet has an empty
|
|
172
|
-
`first_name`, as the console tells them apart.
|
|
173
|
-
- **Keys are left out by the service itself,** so `total` counts people.
|
|
174
|
-
- **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every member.
|
|
175
|
-
- The limit is 100 unless you set one, and at most 1,000.
|
|
176
|
-
- A limit or offset that isn't a whole number in range rejects, with nothing sent.
|
|
177
|
-
- **The order is the service's own:** by email. Pages read at different times can overlap, or skip
|
|
178
|
-
a person, when people are added or removed, or an email changes, in between. A changed `total`
|
|
179
|
-
shows some of that, but an unchanged one doesn't prove nothing moved. For a complete, stable
|
|
180
|
-
list, read it in one page: up to 1,000.
|
|
181
|
-
- **Each call reads your organisation beside the people,** under one deadline for both reads, and
|
|
182
|
-
its failure is the answer. In a list, a person of another organisation makes the answer
|
|
183
|
-
`invalid`; they're never shown or dropped.
|
|
184
|
-
- **What `get` answers,** for an id:
|
|
185
|
-
- **the person,** when they're one of your organisation's people;
|
|
186
|
-
- **`not_found`** when there's no such person for you: pulse-auth has none by that id, or your
|
|
187
|
-
role can't read them (it answers 404), or the id is one of your organisation's API keys, which
|
|
188
|
-
`get` answers as an id nobody has;
|
|
189
|
-
- **`forbidden`** when pulse-auth refuses the read (403);
|
|
190
|
-
- **`invalid`** when the answer is another organisation's person or API key, which only a staff
|
|
191
|
-
token reaches, such as Flipstream's staff acting through a swap token. The organisation is
|
|
192
|
-
checked before the key, so another organisation's key is `invalid` too. So is an answer that
|
|
193
|
-
is someone else than the person asked for.
|
|
120
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "Your organisation's members".
|
|
194
121
|
|
|
195
122
|
## Workspaces
|
|
196
123
|
|
|
@@ -208,79 +135,11 @@ const workspace = orThrow(await flipstream.workspaces.get({ workspace_id: page.i
|
|
|
208
135
|
console.log(workspace.slug)
|
|
209
136
|
```
|
|
210
137
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
something other than text reads `unreadable` here, where the console can't read that workspace
|
|
215
|
-
at all.
|
|
216
|
-
- `{ status: 'known', on }`, with `on` the keys of the services that are on, as the backend
|
|
217
|
-
stores them, such as `['trackers']`, or `[]` when none is;
|
|
218
|
-
- `{ status: 'unreadable' }` when the workspace's `meta` can't be read. The services are then
|
|
219
|
-
neither on nor off: say they can't be read, not that they're off. The workspace still reads.
|
|
220
|
-
|
|
221
|
-
Turning a service on isn't in the SDK yet.
|
|
222
|
-
- **A page** is `{ items, total, limit, offset }`. `total` counts every workspace, and `limit` and
|
|
223
|
-
`offset` say what was read. `limit` is 100 when left out and at most 1,000, and a larger one is
|
|
224
|
-
read as 1,000. A limit or offset that isn't a whole number in range rejects with a `TypeError`,
|
|
225
|
-
with nothing sent.
|
|
226
|
-
- **The order is the service's own:** by name alone, for workspaces. Pages read at different times
|
|
227
|
-
can overlap, or skip a workspace, when workspaces are added, removed or renamed in between, or
|
|
228
|
-
when two have the same name. A changed `total` shows some of that, but an unchanged one doesn't
|
|
229
|
-
prove nothing moved. For a complete, stable list, read it in one page: up to 1,000.
|
|
230
|
-
- **Each call reads your organisation first,** under one deadline for both reads, and its failure
|
|
231
|
-
is the answer. A workspace of another organisation makes the answer `invalid`; it's never shown
|
|
232
|
-
or dropped.
|
|
233
|
-
- **Creating a workspace:** `flipstream.workspaces.create({ name })` makes one in your organisation
|
|
234
|
-
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)).
|
|
235
141
|
|
|
236
|
-
|
|
237
|
-
import { createFlipstream, orThrow } from '@flipstream/sdk'
|
|
238
|
-
|
|
239
|
-
const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
|
|
240
|
-
|
|
241
|
-
const made = orThrow(await flipstream.workspaces.create({ name: 'Acme NL' }))
|
|
242
|
-
console.log(made.id, made.slug) // the short name the service chose, such as 'acme-nl-2'
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
- It sends the name alone, with your organisation. The service makes the short name, unique in
|
|
246
|
-
your organisation, so read `slug` from the answer.
|
|
247
|
-
- **A request with any key but `name` is `refused`** (`reason: 'fields'`, naming them), with
|
|
248
|
-
nothing sent: a `slug` or an `organization_id` it dropped would look set. A `name` that isn't a
|
|
249
|
-
non-empty string, or is only spaces, rejects with a `TypeError`, with nothing sent.
|
|
250
|
-
- Who may create one is the service's rule, not the SDK's: Owners and Admins. pulse-admin#181
|
|
251
|
-
aligns the service with it; until then an Editor still succeeds. Anyone it refuses gets
|
|
252
|
-
`forbidden`.
|
|
253
|
-
- **It's never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
|
|
254
|
-
`no_token` shows nothing was made. After any other failure (`timeout`, `unavailable`,
|
|
255
|
-
`aborted`, `cancelled`, or `invalid`, which may be the service's answer that it made one) it may
|
|
256
|
-
have been made, so list the workspaces before you create it again. Names needn't be unique, so
|
|
257
|
-
compare that list with one from before you created it.
|
|
258
|
-
- **Renaming or deleting a workspace is a person's to do, in the console.**
|
|
259
|
-
`flipstream.workspaces.rename({ workspace_id, name })` and `delete({ workspace_id })` never write.
|
|
260
|
-
Each reads the workspace (one that isn't yours is `not_found`), then answers `needs_person`:
|
|
261
|
-
|
|
262
|
-
```ts
|
|
263
|
-
import { createFlipstream } from '@flipstream/sdk'
|
|
264
|
-
|
|
265
|
-
const flipstream = createFlipstream({
|
|
266
|
-
app: { name: 'my-app', version: '1.0.0' },
|
|
267
|
-
token: async () => '<your token>',
|
|
268
|
-
hosts: { console: 'http://localhost:5173' },
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
const result = await flipstream.workspaces.rename({ workspace_id: '<workspace id>', name: 'New name' })
|
|
272
|
-
if (!result.ok && result.error.kind === 'needs_person') {
|
|
273
|
-
console.log(result.error.why) // tell the person what to do, and why
|
|
274
|
-
if (result.error.url !== undefined) console.log(result.error.url, result.error.sees)
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
- `why` is the SDK's own words, never a value you gave, so it's safe to show.
|
|
279
|
-
- `url` and `sees` name the workspace's settings page, and are there only when a console can be
|
|
280
|
-
named: set `hosts.console` (for example `http://localhost:5173`, while developing). It must be
|
|
281
|
-
https, or http on this machine, with no query, fragment or credentials, or `createFlipstream`
|
|
282
|
-
throws a `TypeError`.
|
|
283
|
-
- `orThrow` throws it as an `ApiFailure` whose message gives `why`.
|
|
142
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "Workspaces".
|
|
284
143
|
|
|
285
144
|
## A workspace's logbook
|
|
286
145
|
|
|
@@ -299,96 +158,13 @@ console.log(`${page.items.length} of ${page.total}`)
|
|
|
299
158
|
const entry = orThrow(await flipstream.log.get({ log_id: '<log entry id>' }))
|
|
300
159
|
```
|
|
301
160
|
|
|
302
|
-
|
|
303
|
-
and nothing else.
|
|
304
|
-
- `start_date` and `end_date` are ISO 8601 instants in UTC, such as `2026-10-05T00:00:00.000Z`.
|
|
305
|
-
- A point in time starts and ends at once.
|
|
306
|
-
- `created_on` is when it was written, in the same form, and `created_by_id` the person who wrote
|
|
307
|
-
it. Either is `null` when the service holds none.
|
|
308
|
-
- `flipstream.members.get({ member_id: created_by_id })` names the writer. When it doesn't answer
|
|
309
|
-
ok (see "Your organisation's members"), show the writer as unknown, for example for an entry
|
|
310
|
-
Flipstream staff wrote through a swap token.
|
|
311
|
-
- **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every entry.
|
|
312
|
-
- The limit is 100 unless you set one, and at most 1,000.
|
|
313
|
-
- A limit or offset that isn't a whole number in range rejects, with nothing sent.
|
|
314
|
-
- **The order is newest written first:** the logbook's own, since the SDK asks for no other.
|
|
315
|
-
- When an entry was written never changes, so editing an entry doesn't move it.
|
|
316
|
-
- Pages read at different times can still overlap or skip an entry, when one is written or
|
|
317
|
-
removed in between.
|
|
318
|
-
- Entries written at the same moment have no fixed order among themselves.
|
|
319
|
-
- A changed `total` shows that something was added or removed; an unchanged one doesn't prove
|
|
320
|
-
nothing was.
|
|
321
|
-
- **The workspace is read beside the list,** with your organisation, under one deadline: one
|
|
322
|
-
nobody has is `not_found`, and another organisation's is `invalid`, never an empty page. Their
|
|
323
|
-
failure, then the list's, is the answer.
|
|
324
|
-
- **An entry of another workspace or organisation** in the list makes the answer `invalid`; it's
|
|
325
|
-
never dropped.
|
|
326
|
-
- **A missing entry:** `get` answers `not_found`. `get` reads your organisation beside the entry, and
|
|
327
|
-
an answer that is another entry than the one asked for, or another organisation's, is `invalid`.
|
|
328
|
-
|
|
329
|
-
**One member's entries,** in every workspace of your organisation, for a person's page for example:
|
|
330
|
-
`list({ member_id })` instead of `{ workspace_id }`.
|
|
331
|
-
|
|
332
|
-
```ts
|
|
333
|
-
import { createFlipstream, orThrow } from '@flipstream/sdk'
|
|
334
|
-
|
|
335
|
-
const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
|
|
336
|
-
|
|
337
|
-
const theirs = orThrow(await flipstream.log.list({ member_id: '<member id>', limit: 5 }))
|
|
338
|
-
for (const entry of theirs.items) console.log(entry.start_date, entry.workspace_id, entry.description)
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
- **Exactly one of `workspace_id` and `member_id`:** both, or neither, rejects with a `TypeError`,
|
|
342
|
-
with nothing sent.
|
|
343
|
-
- **You and the member are read first,** with your organisation, under one deadline. A person who
|
|
344
|
-
isn't a member, or a key, is `not_found`, and another organisation's member `invalid`, and no
|
|
345
|
-
entries are asked for. Your organisation's failure, then yours, then the member's, is the answer.
|
|
346
|
-
- **Every entry must be the member's, your organisation's, and in a workspace you open.** If your
|
|
347
|
-
account names workspaces, you open only those, unless you're an owner, an admin or an editor;
|
|
348
|
-
otherwise you open every one. Any other entry makes the answer `invalid`; none is dropped.
|
|
349
|
-
- **The page and the order** are a workspace's: the backend's, newest written first.
|
|
350
|
-
|
|
351
|
-
**Writing to it:** `add`, `update` and `remove`.
|
|
352
|
-
|
|
353
|
-
```ts
|
|
354
|
-
import { createFlipstream, orThrow } from '@flipstream/sdk'
|
|
355
|
-
|
|
356
|
-
const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
|
|
357
|
-
|
|
358
|
-
const added = orThrow(
|
|
359
|
-
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' }),
|
|
360
|
-
)
|
|
361
|
-
orThrow(await flipstream.log.update({ log_id: added.id, description: 'Site migration, phase 1' }))
|
|
362
|
-
orThrow(await flipstream.log.remove({ log_id: added.id })) // null
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
- **What each takes,** before anything is sent:
|
|
366
|
-
- a key it doesn't send is `refused` (`reason: 'fields'`, naming them);
|
|
367
|
-
- a description that isn't a non-blank string, a time not written as `2026-10-05T00:00:00Z`, or a
|
|
368
|
-
start after the end rejects with a `TypeError`. A fraction may follow the seconds, and an offset
|
|
369
|
-
such as `+02:00`, or none, may take the place of the `Z`. A time with no offset is read as UTC,
|
|
370
|
-
and every time is sent as a UTC instant.
|
|
371
|
-
- **Each write reads first.** `add` reads the workspace: one nobody has is `not_found`, and another
|
|
372
|
-
organisation's is `invalid`, with nothing written. `update` and `remove` read the entry, held to
|
|
373
|
-
your organisation the same way.
|
|
374
|
-
- **`update` changes what you give,** at least one of `description`, `start_date` and `end_date`,
|
|
375
|
-
and sends the rest back exactly as stored. When you give a time, a start after the stored end
|
|
376
|
-
(or an end before the stored start) rejects with a `TypeError`, with nothing written. Since the
|
|
377
|
-
whole entry goes back, a change someone else made between `update`'s read and its write is
|
|
378
|
-
overwritten.
|
|
379
|
-
- **`remove` answers `null`.** A log entry's remove is direct; it's not handed to a person.
|
|
380
|
-
- **Who may write is the service's rule, not the SDK's:** Owners, Admins and Editors add; an Editor
|
|
381
|
-
changes or removes only their own entries, and Owners and Admins any. Until the service enforces
|
|
382
|
-
it (pulse-admin#161, for Editors), a Viewer can also add, change and remove entries, and an Editor
|
|
383
|
-
can change anyone's. Anyone it refuses gets `forbidden`.
|
|
384
|
-
- **A write is never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
|
|
385
|
-
`no_token` shows nothing was written. After any other failure it may have been, so list the
|
|
386
|
-
logbook before you write again.
|
|
161
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "A workspace's logbook".
|
|
387
162
|
|
|
388
163
|
## A workspace's datasets
|
|
389
164
|
|
|
390
|
-
`flipstream.datasets` reads a workspace's datasets, its uploads and connected accounts,
|
|
391
|
-
|
|
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.
|
|
392
168
|
|
|
393
169
|
```ts
|
|
394
170
|
import { createFlipstream, orThrow } from '@flipstream/sdk'
|
|
@@ -397,113 +173,17 @@ const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' },
|
|
|
397
173
|
|
|
398
174
|
const page = orThrow(await flipstream.datasets.list({ workspace_id: '<workspace id>', limit: 50 }))
|
|
399
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)
|
|
400
180
|
|
|
401
181
|
const dataset = orThrow(await flipstream.datasets.get({ dataset_id: '<dataset id>' }))
|
|
402
182
|
const types = orThrow(await flipstream.datasetTypes.list())
|
|
403
183
|
console.log(dataset.name, types.length)
|
|
404
184
|
```
|
|
405
185
|
|
|
406
|
-
|
|
407
|
-
`{ id, name, workspace_id, type, active, created_on, created_by_id, history, account }`, and
|
|
408
|
-
nothing else: never a credential, a setting or its parameters, beyond its account's id. The
|
|
409
|
-
service's answer embeds the dataset's sign-in, so a body that isn't the service's JSON is never
|
|
410
|
-
kept either: a failure of the dataset's own read or write gives its kind and status, with no
|
|
411
|
-
`text`. The reads of your organisation and the workspace beside it keep theirs.
|
|
412
|
-
- `type` is one of the types `datasetTypes.list()` gives, such as `'google_search_console'`, or
|
|
413
|
-
a type this version doesn't know yet, kept as it came, so a new kind of dataset never makes the
|
|
414
|
-
list unreadable. It's `null` when the service holds no type for it.
|
|
415
|
-
- `active` says whether it's switched on.
|
|
416
|
-
- `created_on` is when it was made, an ISO 8601 instant in UTC, and `created_by_id` the person who
|
|
417
|
-
made it. Either is `null` when the service holds none.
|
|
418
|
-
- `flipstream.members.get({ member_id: created_by_id })` names the maker. When it doesn't answer
|
|
419
|
-
ok (see "Your organisation's members"), show the maker as unknown, for example for a dataset
|
|
420
|
-
Flipstream staff made through a swap token.
|
|
421
|
-
- `history` says how much of its history is in the warehouse, a `DatasetHistory`, in the
|
|
422
|
-
service's own values (the SDK renames fields, never values):
|
|
423
|
-
- `'not_available'`: no history is loaded for its kind of dataset;
|
|
424
|
-
- `'todo'`: its history hasn't started loading. Every new dataset starts here, and the
|
|
425
|
-
pipeline sets `'not_available'` only when it first runs for one, so `'todo'` may never start
|
|
426
|
-
for a type that loads no history;
|
|
427
|
-
- `'started'`: its history is loading, from the first load until it's in; a load that keeps
|
|
428
|
-
failing stays `'started'`;
|
|
429
|
-
- `'done'`: its history is in.
|
|
430
|
-
|
|
431
|
-
Merge them as your app needs: the console shows `'todo'` and `'started'` alike as "coming in".
|
|
432
|
-
It's `null` when it's unknown, because the service holds none or a value this version doesn't
|
|
433
|
-
know: show "Not available yet" then, never a value of your own.
|
|
434
|
-
- `account` says which account it reads, a `DatasetAccount`, as the console labels a dataset:
|
|
435
|
-
- `id` is the id as the service holds it: a string as stored, or a whole number from 1 to
|
|
436
|
-
2^53 - 1 as its digits. Use it to find or send back the stored id;
|
|
437
|
-
- `shown` is the id as its source writes it, trimmed: a Google Ads id as `'412-883-1024'`, any
|
|
438
|
-
other as `id`, such as `'sc-domain:acme.nl'`. Compare two accounts of one `type` by `shown`,
|
|
439
|
-
as the console's connect dialog does within one source, so a Google Ads account stored as
|
|
440
|
-
`'4128831024'` and as `'412-883-1024'` is one account. Across types, two ids can be the same
|
|
441
|
-
digits for different accounts.
|
|
442
|
-
|
|
443
|
-
The SDK reads the key a type keeps its account under, and only its id: Search Console,
|
|
444
|
-
Analytics and Google Ads keep a property, Business Profile a location, Meta Ads and LinkedIn
|
|
445
|
-
Ads an account (an older LinkedIn Ads dataset a property), Facebook Pages a page. It's `null`
|
|
446
|
-
for any other type, or when the service holds no readable id: show the dataset's name then.
|
|
447
|
-
The console shows a label where the SDK says `null` only for an id the SDK refuses, because it
|
|
448
|
-
can't show it safely or exactly: one longer than 512 UTF-16 code units, one with a control or
|
|
449
|
-
format character or a line or paragraph separator in it (a terminal escape, say), or a finite
|
|
450
|
-
number that isn't a whole one from 1 to 2^53 - 1. A refused id ends the read: the SDK never
|
|
451
|
-
shows another key's account in its place, such as an older LinkedIn Ads dataset's property.
|
|
452
|
-
- **A list is one page:** `{ items, total, limit, offset }`, where `total` counts every dataset.
|
|
453
|
-
- The limit is 100 unless you set one, and at most 1,000.
|
|
454
|
-
- A limit or offset that isn't a whole number in range rejects, with nothing sent.
|
|
455
|
-
- **The order is the service's own:** by name alone. Pages read at different times can overlap, or
|
|
456
|
-
skip a dataset, when datasets are added, removed or renamed in between, or when two have the same
|
|
457
|
-
name. A changed `total` shows some of that, but an unchanged one doesn't prove nothing moved. For
|
|
458
|
-
a complete, stable list, read it in one page: up to 1,000.
|
|
459
|
-
- **Each call reads your organisation beside the datasets,** and a list reads its workspace too,
|
|
460
|
-
under one deadline for every read. The organisation's failure, then the workspace's, is the
|
|
461
|
-
answer. A dataset of another organisation, or in the list one of another workspace, makes the
|
|
462
|
-
answer `invalid`; it's never shown or dropped.
|
|
463
|
-
- **A workspace nobody has** is `not_found`, and another organisation's is `invalid`: never an empty
|
|
464
|
-
page, which would say it has no datasets.
|
|
465
|
-
- **A missing dataset:** `get` answers `not_found`. An answer that is another dataset than the one
|
|
466
|
-
asked for is `invalid`.
|
|
467
|
-
- **`datasetTypes.list()`** sends nothing: the types are the SDK's own list, since the service has
|
|
468
|
-
no route for them yet. Each call gives you a list of your own.
|
|
469
|
-
|
|
470
|
-
**Pausing and resuming:** `pause` and `resume`.
|
|
471
|
-
|
|
472
|
-
```ts
|
|
473
|
-
import { createFlipstream, orThrow } from '@flipstream/sdk'
|
|
474
|
-
|
|
475
|
-
const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
|
|
476
|
-
|
|
477
|
-
const paused = orThrow(await flipstream.datasets.pause({ dataset_id: '<dataset id>' }))
|
|
478
|
-
console.log(paused.active) // false
|
|
479
|
-
orThrow(await flipstream.datasets.resume({ dataset_id: '<dataset id>' })) // active: true
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
- **Each answers the `Dataset`,** with `active` as asked. Pausing a paused dataset sends the same
|
|
483
|
-
write and answers the same, so calling either twice is the same as once.
|
|
484
|
-
- **What each takes,** before anything is sent: `dataset_id` alone. Any other key is `refused`
|
|
485
|
-
(`reason: 'fields'`, naming them), and an id that isn't a string rejects with a `TypeError`.
|
|
486
|
-
- **Each reads first:** the dataset, fresh, beside your organisation. One nobody has is
|
|
487
|
-
`not_found`, and another organisation's is `invalid`, with nothing written. Then `active` alone
|
|
488
|
-
is sent, so a rename made in between stays.
|
|
489
|
-
- **Each reads again after the write,** fresh, and answers that read. One whose `active` isn't the
|
|
490
|
-
one asked for is `invalid`, since the write may not have been stored, as is one of another
|
|
491
|
-
dataset, workspace or organisation. That read comes after the write was sent, so its failure
|
|
492
|
-
is never answered as a refusal: a 4xx kind, `refused` or `no_token` there is `invalid`, naming
|
|
493
|
-
its kind. A `timeout`, `aborted`, `cancelled`, `unavailable` or `invalid` there keeps its kind,
|
|
494
|
-
since it already says the write may have been made.
|
|
495
|
-
- **Who may is the service's rule:** Owners, Admins and Editors pause and resume, and a Viewer
|
|
496
|
-
doesn't. Anyone it refuses gets `forbidden`.
|
|
497
|
-
- **A write is never tried again.** Only a refusal (a 4xx kind such as `forbidden`), `refused` or
|
|
498
|
-
`no_token` shows nothing was written. After any other failure it may have been; calling it
|
|
499
|
-
again is safe, since it's the same write.
|
|
500
|
-
|
|
501
|
-
**Deleting a dataset is a person's to do, in the console.** It removes the dataset's data for good,
|
|
502
|
-
and the console can't delete a dataset yet. `flipstream.datasets.delete({ dataset_id })` never
|
|
503
|
-
writes. It reads the dataset first: one nobody has is `not_found`, and another organisation's is
|
|
504
|
-
`invalid`. Then it answers `needs_person` with `why`, and, where a console can be named (your own
|
|
505
|
-
`hosts.console`), the dataset's page as `url`, with what it shows as `sees`, as
|
|
506
|
-
`workspaces.delete` does.
|
|
186
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "A workspace's datasets".
|
|
507
187
|
|
|
508
188
|
## Sign-ins to your sources
|
|
509
189
|
|
|
@@ -519,30 +199,7 @@ const page = orThrow(await flipstream.credentials.list({ limit: 50 }))
|
|
|
519
199
|
for (const credential of page.items) console.log(credential.name, credential.type, credential.datasource_types)
|
|
520
200
|
```
|
|
521
201
|
|
|
522
|
-
|
|
523
|
-
- `name` is the provider account it signs in as: for a Google sign-in, that account's email
|
|
524
|
-
address.
|
|
525
|
-
- `type` is what kind of sign-in it is, such as `'oauth2'` or `'service_account'`. A kind this
|
|
526
|
-
version doesn't know is kept as it came, and it's `null` when the service holds none.
|
|
527
|
-
- `datasource_types` lists the kinds of dataset it serves, such as `'google_search_console'`.
|
|
528
|
-
- `created_on` is an ISO 8601 instant in UTC.
|
|
529
|
-
- **Never a value.** The service doesn't mask a sign-in, so the SDK checks every answer itself. An
|
|
530
|
-
answer holding what may be a sign-in's value (a `data` that isn't empty, or a key such as
|
|
531
|
-
`refresh_token`, `apiKey`, `auth_values` or `password`, at any depth, however it's spelt) is
|
|
532
|
-
`invalid`. Its issues name the place, never the value, and nothing is answered at all. A body
|
|
533
|
-
that isn't the service's JSON is never kept either: a failure of the sign-ins' own reads gives
|
|
534
|
-
its kind and status, with no `text`. The read of your organisation beside them keeps its.
|
|
535
|
-
- **A list is one page:** `{ items, total, limit, offset }`, as every list is. The limit is 100
|
|
536
|
-
unless you set one, and at most 1,000.
|
|
537
|
-
- **It reads your organisation first,** for its id, and its failure is the answer. A sign-in of
|
|
538
|
-
another organisation makes the answer `invalid`.
|
|
539
|
-
- **Who may list them is the service's rule:** today Owners, Admins, Editors and Viewers. Anyone
|
|
540
|
-
it refuses gets `forbidden`.
|
|
541
|
-
- **Revoking or deleting a sign-in is a person's to do, in the console.** Either breaks every
|
|
542
|
-
dataset that reads with it. `flipstream.credentials.revoke({ credential_id })` and
|
|
543
|
-
`delete({ credential_id })` never write. Each reads the sign-in first: one nobody has is
|
|
544
|
-
`not_found`, and another organisation's is `invalid`. Then it answers `needs_person` with `why`.
|
|
545
|
-
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".
|
|
546
203
|
|
|
547
204
|
## Wallet
|
|
548
205
|
|
|
@@ -558,25 +215,10 @@ const balance = orThrow(await flipstream.wallet.balance())
|
|
|
558
215
|
if (balance !== null) console.log(balance.balance_micro / balance.micro_per_euro, 'euros')
|
|
559
216
|
|
|
560
217
|
const ledger = orThrow(await flipstream.wallet.transactions())
|
|
561
|
-
console.log(ledger.items.length, 'rows')
|
|
218
|
+
if (ledger !== null) console.log(ledger.items.length, 'rows')
|
|
562
219
|
```
|
|
563
220
|
|
|
564
|
-
|
|
565
|
-
`micro_per_euro`. Divide by it, never by a number of your own: the basis can change.
|
|
566
|
-
- **`balance()`** is `{ balance_micro, micro_per_euro }`, or `null` when your organisation has no
|
|
567
|
-
wallet. No wallet is a real state, so it's not an error, and it's never a zero balance: €0.00
|
|
568
|
-
would claim a wallet that holds nothing.
|
|
569
|
-
- **`transactions()`** is the whole ledger, in one answer, with no paging: `{ items, micro_per_euro }`.
|
|
570
|
-
The ledger's rows don't name their wallet, so the balance is read beside it, and the ledger is
|
|
571
|
-
answered only when that's your organisation's wallet. Each row
|
|
572
|
-
is `{ id, type, dataset_id, description, amount_micro, quantity, unit_price_micro, created_on }`.
|
|
573
|
-
A row that charged no dataset, such as a credit, has `dataset_id: null`, whether the wallet
|
|
574
|
-
wrote its `connection_id` empty or null. `created_on` is an
|
|
575
|
-
ISO 8601 instant in UTC, such as `2026-10-31T13:08:25.312Z`, as the logbook's times are. A type
|
|
576
|
-
this version doesn't know is kept as it came.
|
|
577
|
-
- **Who may read it is the wallet's rule, not the SDK's.** Today that's Owners and Admins, and
|
|
578
|
-
Editors too once pulse-wallet#15 lands. Anyone the wallet refuses gets `forbidden`, never an
|
|
579
|
-
empty ledger.
|
|
221
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "Wallet".
|
|
580
222
|
|
|
581
223
|
## Signing in from Node and the CLI
|
|
582
224
|
|
|
@@ -618,7 +260,7 @@ const signedIn = await signInWithLoopback({
|
|
|
618
260
|
})
|
|
619
261
|
if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
620
262
|
|
|
621
|
-
const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: () => signedIn.data.
|
|
263
|
+
const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: () => signedIn.data.access_token })
|
|
622
264
|
```
|
|
623
265
|
|
|
624
266
|
- **The SDK opens nothing and writes nothing to the terminal.** `open` does that, once the port is
|
|
@@ -627,11 +269,27 @@ const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' },
|
|
|
627
269
|
out (after 5 minutes, or `timeoutMs`), aborted (`signal`), or `open` or `readPasted` failing
|
|
628
270
|
(`readPasted` reads a pasted address when the browser can't come back: see
|
|
629
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`.
|
|
630
277
|
- **The redirect is checked before its code is exchanged:** the sign-in's own state first, then the
|
|
631
278
|
issuer.
|
|
632
279
|
- **`page: { signedIn, failed }`** sets the HTML the browser shows afterwards.
|
|
633
|
-
- **What comes back:** `
|
|
634
|
-
says, and `
|
|
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.
|
|
635
293
|
|
|
636
294
|
**The rest is in [docs/node-sign-in.md](docs/node-sign-in.md),** which ships in the package, at
|
|
637
295
|
`node_modules/@flipstream/sdk/docs/node-sign-in.md`:
|
|
@@ -716,8 +374,8 @@ if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
|
716
374
|
## Results, not exceptions
|
|
717
375
|
|
|
718
376
|
Every call settles into a result: `{ ok: true, data }` or `{ ok: false, error }`, each with the
|
|
719
|
-
call's `
|
|
720
|
-
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
|
|
721
379
|
with the `TypeError`, and nothing is sent. `orThrow(result)` gives the data, or throws the failure
|
|
722
380
|
as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
|
|
723
381
|
|
|
@@ -738,33 +396,40 @@ as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
|
|
|
738
396
|
(`{ status: 'ok' }` today). It works signed out: no token is asked for or sent, so it tells "the
|
|
739
397
|
service is down" from "the sign-in is wrong".
|
|
740
398
|
- **`flipstream.me()`** gives a `Me`: your organisation and you in it, and
|
|
741
|
-
**`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)).
|
|
742
401
|
- **`flipstream.workspaces.list({ limit, offset })`** gives a `Page<Workspace>`, and
|
|
743
402
|
**`flipstream.workspaces.get({ workspace_id })`** and **`create({ name })`** a `Workspace` (see
|
|
744
|
-
"Workspaces").
|
|
403
|
+
"Workspaces" in [docs/admin.md](docs/admin.md)).
|
|
745
404
|
- **`flipstream.log.list()`** gives a `Page<LogEntry>`, **`flipstream.log.get()`**, **`add()`** and
|
|
746
|
-
**`update()`** a `LogEntry`, and **`remove()`** `null` (see "A workspace's logbook"
|
|
747
|
-
|
|
748
|
-
|
|
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
|
|
749
410
|
**`flipstream.datasetTypes.list()`** gives the `DatasetType`s this version knows (see "A
|
|
750
|
-
workspace's datasets").
|
|
411
|
+
workspace's datasets" in [docs/admin.md](docs/admin.md)).
|
|
751
412
|
- **`flipstream.credentials.list({ limit, offset })`** gives a `Page<Credential>`, and
|
|
752
|
-
**`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)).
|
|
753
415
|
- **`flipstream.wallet.balance()`** gives a `Balance` or `null`, and
|
|
754
|
-
**`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)).
|
|
755
418
|
- **`flipstream.members.list({ limit, offset })`** gives a `Page<Member>`, and
|
|
756
|
-
**`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)).
|
|
757
421
|
|
|
758
422
|
**Every answer is checked against the API's spec.** An answer that doesn't match, with a missing
|
|
759
423
|
field or a value of the wrong type, is an `invalid` failure that names the field. It never comes
|
|
760
424
|
back as data. Some of a dataset's fields are read more leniently, so one new or missing backend
|
|
761
425
|
value never makes a workspace's datasets unreadable: a `type` this version doesn't know is kept as
|
|
762
|
-
it came, `created_on` and `created_by_id` are `null` when missing, and `history`
|
|
763
|
-
missing or when
|
|
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
|
|
764
428
|
member's `created_on` and `created_by_id` are `null` when missing too, and its `created_on` also
|
|
765
|
-
when it isn't a time, so one member's time never fails `me()` or a page of members (
|
|
766
|
-
|
|
767
|
-
|
|
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.
|
|
768
433
|
|
|
769
434
|
## Typed errors
|
|
770
435
|
|
|
@@ -786,11 +451,19 @@ organisation's members"). A field the SDK doesn't know yet is kept, except in th
|
|
|
786
451
|
- It keeps the API's `code` and `message` when the body is an error body, or its `text` when it
|
|
787
452
|
isn't (a proxy's `Bad gateway`). The sign-ins' and the datasets' own reads and writes keep no
|
|
788
453
|
`text`, since a body there may hold a sign-in's value (see "Sign-ins to your sources" and "A
|
|
789
|
-
workspace's datasets"). The reads of your organisation and a
|
|
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.
|
|
790
463
|
- `isPlannerCode(error.code)` narrows the code to the ones the query API documents
|
|
791
464
|
(`PlannerErrorCode`), so a switch over them can be exhaustive. A code added since is kept as it
|
|
792
465
|
came.
|
|
793
|
-
- When the API asked the caller to wait, the failure keeps that as `
|
|
466
|
+
- When the API asked the caller to wait, the failure keeps that as `retry_after_ms`.
|
|
794
467
|
|
|
795
468
|
**A `refused` call says why, in `reason`** (`RefusedReason`), and `orThrow`'s message names it,
|
|
796
469
|
never the value:
|
|
@@ -821,7 +494,7 @@ function explain(error: ApiError): string {
|
|
|
821
494
|
case 'rejected':
|
|
822
495
|
return isPlannerCode(error.code) ? `${error.code}: ${error.message ?? ''}` : `Refused: ${String(error.status)}`
|
|
823
496
|
case 'unavailable':
|
|
824
|
-
return error.status === undefined ? 'No answer: offline?' : `Busy: try again in ${String(error.
|
|
497
|
+
return error.status === undefined ? 'No answer: offline?' : `Busy: try again in ${String(error.retry_after_ms ?? 1000)} ms`
|
|
825
498
|
case 'invalid':
|
|
826
499
|
return `An answer outside the contract: ${error.issues}`
|
|
827
500
|
case 'timeout':
|
|
@@ -898,6 +571,14 @@ await flipstream.catalog.list({ conversationId: 'c-456', traceparent: '00-4bf92f
|
|
|
898
571
|
- A wait that wouldn't end before the deadline isn't started.
|
|
899
572
|
- **Deadlines:** 60 s for `query`, 10 s for `health` and 30 s for the rest (for `me`, its three
|
|
900
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.
|
|
901
582
|
- **Abort:** `signal` ends a call at once, also while it waits for a token or to try again.
|
|
902
583
|
- **Warnings:** the SDK's warnings go to `onWarning`, or to `console.warn` without it; `() => {}`
|
|
903
584
|
silences them. Today there is one kind: a catalogue format type this version doesn't know,
|
|
@@ -906,7 +587,11 @@ await flipstream.catalog.list({ conversationId: 'c-456', traceparent: '00-4bf92f
|
|
|
906
587
|
- **Your own transport:** an app that attaches the token itself passes `{ transport }` instead of
|
|
907
588
|
`token` and `fetch`. Retries and deadlines still apply, above it. `health` carries no token, so
|
|
908
589
|
it never goes through your transport: it goes to the query host, over https, with the global
|
|
909
|
-
`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.
|
|
910
595
|
|
|
911
596
|
## Which app sent a request
|
|
912
597
|
|
|
@@ -944,7 +629,7 @@ the SDK has no telemetry. In Node, each signed-in request to an API host carries
|
|
|
944
629
|
|
|
945
630
|
## Finding a request in Logs
|
|
946
631
|
|
|
947
|
-
Every result says which trace its call's requests carried, as `
|
|
632
|
+
Every result says which trace its call's requests carried, as `trace_id`, so a person can find them
|
|
948
633
|
in Logs:
|
|
949
634
|
|
|
950
635
|
```ts
|
|
@@ -953,25 +638,25 @@ import { createFlipstream } from '@flipstream/sdk'
|
|
|
953
638
|
const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
|
|
954
639
|
|
|
955
640
|
const result = await flipstream.catalog.list()
|
|
956
|
-
if (!result.ok) console.error(`${result.error.kind} (request ${result.
|
|
641
|
+
if (!result.ok) console.error(`${result.error.kind} (request ${result.trace_id ?? 'not sent'})`)
|
|
957
642
|
```
|
|
958
643
|
|
|
959
|
-
- **On both arms:** `{ ok: true, data,
|
|
644
|
+
- **On both arms:** `{ ok: true, data, trace_id }` and `{ ok: false, error, trace_id }`. It's the
|
|
960
645
|
W3C trace-id the call's `traceparent` carried: 32 lowercase hex digits.
|
|
961
646
|
- **One call, one trace:** a call that makes several requests, such as `me()`'s reads or
|
|
962
647
|
`workspaces.list()`'s two, sends them all under one trace-id, each with its own parent-id. So
|
|
963
648
|
does a retry, and the resend after a 401.
|
|
964
|
-
- **Your trace:** a call given your own `traceparent` keeps it, and `
|
|
965
|
-
- **Nothing sent, no `
|
|
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,
|
|
966
651
|
identification, the conversation's id, the destination) has none, and neither does a `no_token`
|
|
967
652
|
from the first ask for a token.
|
|
968
653
|
- **Once a request went out, the call has one,** whatever comes after: a `no_token` when the token
|
|
969
654
|
function fails after a 401 (the refused request is the one to look up), or a `timeout` while a
|
|
970
655
|
request is on its way. "Went out" means the SDK handed it to `fetch`: a host that was never
|
|
971
|
-
reached (refused, or not found by DNS) gives `unavailable` with a `
|
|
972
|
-
- **`orThrow`'s message ends with `(request <
|
|
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
|
|
973
658
|
that prints the error carries the id with no code of its own. The `ApiFailure` it throws has the
|
|
974
|
-
id as `
|
|
659
|
+
id as `trace_id` too, for a log field or an error tracker's tag:
|
|
975
660
|
|
|
976
661
|
```ts
|
|
977
662
|
import { ApiFailure, createFlipstream, orThrow } from '@flipstream/sdk'
|
|
@@ -981,17 +666,17 @@ if (!result.ok) console.error(`${result.error.kind} (request ${result.traceId ??
|
|
|
981
666
|
try {
|
|
982
667
|
orThrow(await flipstream.catalog.list())
|
|
983
668
|
} catch (error) {
|
|
984
|
-
if (error instanceof ApiFailure) console.error(error.error.kind, error.
|
|
669
|
+
if (error instanceof ApiFailure) console.error(error.error.kind, error.trace_id ?? 'not sent')
|
|
985
670
|
}
|
|
986
671
|
```
|
|
987
672
|
|
|
988
673
|
It's there only when the result had one, and only as a W3C trace-id.
|
|
989
674
|
- **Only what reaches the API hosts is in it:** the auth server gets no `traceparent`, so a read
|
|
990
675
|
made there, such as `me()`'s userinfo and person, isn't in the call's trace.
|
|
991
|
-
- **With your own transport,** the SDK can't see the request leave, so a result has `
|
|
676
|
+
- **With your own transport,** the SDK can't see the request leave, so a result has `trace_id` once
|
|
992
677
|
an answer came back.
|
|
993
678
|
- **Not from a browser yet:** a browser sends no `traceparent` (see "In a browser"), so its results
|
|
994
|
-
have no `
|
|
679
|
+
have no `trace_id`.
|
|
995
680
|
- **The service's side:** finding the id needs the API hosts to log it, and Logs to index it. Until
|
|
996
681
|
then, the id is still the one to quote.
|
|
997
682
|
|