@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.
- package/CHANGELOG.md +69 -0
- package/README.md +179 -424
- package/dist/api/backend.d.ts +21 -3
- package/dist/api/backend.js +50 -10
- 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 +9 -5
- 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 +40 -25
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +35 -14
- package/dist/api/workspaces.js +53 -23
- package/dist/api/workspaces.js.map +1 -1
- package/dist/auth/discovery.d.ts +19 -6
- package/dist/auth/discovery.js +30 -6
- 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 +13 -1
- package/dist/core/call.js +34 -9
- 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/identify.d.ts +59 -14
- package/dist/core/identify.js +54 -20
- package/dist/core/identify.js.map +1 -1
- package/dist/core/invalid.d.ts +10 -0
- package/dist/core/invalid.js +28 -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/read.d.ts +9 -0
- package/dist/core/read.js +14 -5
- package/dist/core/read.js.map +1 -1
- package/dist/core/result.d.ts +22 -13
- 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/core/shared.d.ts +39 -0
- package/dist/core/shared.js +177 -0
- package/dist/core/shared.js.map +1 -0
- package/dist/core/signal.d.ts +12 -0
- package/dist/core/signal.js +25 -0
- package/dist/core/signal.js.map +1 -0
- package/dist/flipstream.d.ts +223 -72
- package/dist/flipstream.js +225 -88
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/node/clientSecret.js +7 -6
- 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 +13 -3
- package/dist/node/loopback.js +47 -5
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +17 -9
- package/dist/node/session.js +68 -50
- 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 +558 -0
- package/docs/node-sign-in.md +63 -39
- 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,43 @@ 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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
221
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "Wallet".
|
|
222
|
+
|
|
223
|
+
## One piece of work
|
|
224
|
+
|
|
225
|
+
Outside a scope, every call that needs them reads your organisation, you and its workspace first,
|
|
226
|
+
each time. A scope lets the calls of one piece of work, such as a page's load or a command, share
|
|
227
|
+
those reads. They're read from the service at the first call that needs them, and dropped when the
|
|
228
|
+
scope closes. `flipstream.withScope(run)` makes one for the length of `run`; `flipstream.scope()`
|
|
229
|
+
makes one each call takes as `{ scope }`, which you close (or `await using`).
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
import { createFlipstream } from '@flipstream/sdk'
|
|
233
|
+
|
|
234
|
+
const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
|
|
235
|
+
|
|
236
|
+
const [workspace, datasets, log] = await flipstream.withScope((f) =>
|
|
237
|
+
Promise.all([
|
|
238
|
+
f.workspaces.get({ workspace_id: '<workspace id>' }),
|
|
239
|
+
f.datasets.list({ workspace_id: '<workspace id>' }),
|
|
240
|
+
f.log.list({ workspace_id: '<workspace id>' }),
|
|
241
|
+
]),
|
|
242
|
+
)
|
|
243
|
+
console.log(workspace.ok, datasets.ok, log.ok)
|
|
244
|
+
|
|
245
|
+
const scope = flipstream.scope()
|
|
246
|
+
try {
|
|
247
|
+
const me = await flipstream.me({ scope })
|
|
248
|
+
console.log(me.ok)
|
|
249
|
+
} finally {
|
|
250
|
+
await scope.close()
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**The rest is in [docs/admin.md](docs/admin.md),** under "One piece of work".
|
|
580
255
|
|
|
581
256
|
## Signing in from Node and the CLI
|
|
582
257
|
|
|
@@ -618,7 +293,7 @@ const signedIn = await signInWithLoopback({
|
|
|
618
293
|
})
|
|
619
294
|
if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
620
295
|
|
|
621
|
-
const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: () => signedIn.data.
|
|
296
|
+
const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: () => signedIn.data.access_token })
|
|
622
297
|
```
|
|
623
298
|
|
|
624
299
|
- **The SDK opens nothing and writes nothing to the terminal.** `open` does that, once the port is
|
|
@@ -627,11 +302,33 @@ const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' },
|
|
|
627
302
|
out (after 5 minutes, or `timeoutMs`), aborted (`signal`), or `open` or `readPasted` failing
|
|
628
303
|
(`readPasted` reads a pasted address when the browser can't come back: see
|
|
629
304
|
[docs/node-sign-in.md](docs/node-sign-in.md)).
|
|
305
|
+
- **`timeoutMs` follows a call's `deadlineMs`:** taken in whole ms, rounded down, up to 2147483647;
|
|
306
|
+
left out or `null`, it's 5 minutes. One that can't be a wait (not a number, `NaN`, ±`Infinity`,
|
|
307
|
+
or more than that once rounded down) is a `TypeError` naming `signInWithLoopback`, with no port
|
|
308
|
+
opened. One under 1 ms ends as `timeout`, with no port opened and nothing shown, once `server`,
|
|
309
|
+
`clientId` and `scopes` pass the checks a sign-in makes: a mistake in them is still a `TypeError`.
|
|
310
|
+
- **`open`, `readPasted` and `signal` of the wrong kind are a `TypeError` naming the option,**
|
|
311
|
+
before any port opens, whatever `timeoutMs` and even with a `signal` already aborted: an `open` or
|
|
312
|
+
a `readPasted` that isn't a function, or a `signal` with no `aborted` or no `addEventListener`
|
|
313
|
+
method (`null` is a `signal` left out). Only JavaScript can pass them, or leave out the options,
|
|
314
|
+
which is a `TypeError` naming `signInWithLoopback`. `open_failed` and `paste_failed` are an
|
|
315
|
+
`open` or a reader that throws or rejects.
|
|
630
316
|
- **The redirect is checked before its code is exchanged:** the sign-in's own state first, then the
|
|
631
317
|
issuer.
|
|
632
318
|
- **`page: { signedIn, failed }`** sets the HTML the browser shows afterwards.
|
|
633
|
-
- **What comes back:** `
|
|
634
|
-
says, and `
|
|
319
|
+
- **What comes back:** `access_token`, `scope`, `expires_at` (ms since the epoch) when the server
|
|
320
|
+
says, and `refresh_token` when it issues one. Never log them.
|
|
321
|
+
- **Every field in data the SDK returns is snake_case since the snake rename** (D569); its own
|
|
322
|
+
settings, such as `clientId` and `timeoutMs`, stay camelCase. Across the upgrade:
|
|
323
|
+
- `keychainStore` and `fileStore` still read the camelCase tokens that earlier releases saved,
|
|
324
|
+
and save the new shape at their next save.
|
|
325
|
+
- A store of your own converts its records with `fromEarlierTokenNames`, in the same change that
|
|
326
|
+
renames its `onTokens` fields ([docs/node-sign-in.md](docs/node-sign-in.md)).
|
|
327
|
+
- The new shape is one-way: an earlier release can't read it. Every process that shares a
|
|
328
|
+
`fileStore` file or a keychain item upgrades together, and rolling back means signing in
|
|
329
|
+
again, or `clear()`.
|
|
330
|
+
- A sign-in started before the upgrade and finished after it isn't: its `pending` is `refused`,
|
|
331
|
+
and the person signs in again.
|
|
635
332
|
|
|
636
333
|
**The rest is in [docs/node-sign-in.md](docs/node-sign-in.md),** which ships in the package, at
|
|
637
334
|
`node_modules/@flipstream/sdk/docs/node-sign-in.md`:
|
|
@@ -647,11 +344,13 @@ The main entry, `@flipstream/sdk`, runs in browsers with no Node polyfills. Only
|
|
|
647
344
|
|
|
648
345
|
- **Pass a token function** that returns the session's current access token. Never put an API key
|
|
649
346
|
in a browser.
|
|
650
|
-
- **The API must allow your page's origin (CORS).** The query API
|
|
651
|
-
so until it
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
347
|
+
- **The API must allow your page's origin (CORS).** The query API's CORS takes the origins it allows
|
|
348
|
+
from its own settings, and lists none in production yet, so until it lists yours, call it from a
|
|
349
|
+
server.
|
|
350
|
+
- **A page identifies itself to the deployed query API,** as `Flipstream-Client`, with `traceparent`
|
|
351
|
+
and `baggage` (see "Which app sent a request"). To a custom `hosts.query`, pulse-admin and
|
|
352
|
+
pulse-wallet, not: their CORS isn't known to allow those headers. `app`, `agent` and
|
|
353
|
+
`conversationId` are required and checked as in Node.
|
|
655
354
|
- **Signing in from a page** uses the same two halves as the paste-back ("Over SSH, in CI, or
|
|
656
355
|
with no display" in [docs/node-sign-in.md](docs/node-sign-in.md)):
|
|
657
356
|
- `startSignIn` gives the URL to send the person to, and a `pending` to keep, for instance in
|
|
@@ -716,8 +415,8 @@ if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
|
716
415
|
## Results, not exceptions
|
|
717
416
|
|
|
718
417
|
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
|
|
418
|
+
call's `trace_id` when a request went out (see "Finding a request in Logs"). A call rejects only on
|
|
419
|
+
a programming error. For instance, a request that can't be sent as JSON (a `BigInt`, a cycle) rejects
|
|
721
420
|
with the `TypeError`, and nothing is sent. `orThrow(result)` gives the data, or throws the failure
|
|
722
421
|
as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
|
|
723
422
|
|
|
@@ -738,33 +437,40 @@ as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
|
|
|
738
437
|
(`{ status: 'ok' }` today). It works signed out: no token is asked for or sent, so it tells "the
|
|
739
438
|
service is down" from "the sign-in is wrong".
|
|
740
439
|
- **`flipstream.me()`** gives a `Me`: your organisation and you in it, and
|
|
741
|
-
**`flipstream.organization.rename()`** answers `needs_person` (see "Who you are"
|
|
440
|
+
**`flipstream.organization.rename()`** answers `needs_person` (see "Who you are" in
|
|
441
|
+
[docs/admin.md](docs/admin.md)).
|
|
742
442
|
- **`flipstream.workspaces.list({ limit, offset })`** gives a `Page<Workspace>`, and
|
|
743
443
|
**`flipstream.workspaces.get({ workspace_id })`** and **`create({ name })`** a `Workspace` (see
|
|
744
|
-
"Workspaces").
|
|
444
|
+
"Workspaces" in [docs/admin.md](docs/admin.md)).
|
|
745
445
|
- **`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
|
-
|
|
446
|
+
**`update()`** a `LogEntry`, and **`remove()`** `null` (see "A workspace's logbook" in
|
|
447
|
+
[docs/admin.md](docs/admin.md)).
|
|
448
|
+
- **`flipstream.datasets.list()`** gives a `Page<Dataset>`, **`count({ workspace_id })`**
|
|
449
|
+
`{ count }`, **`flipstream.datasets.get()`**, **`pause()`** and **`resume()`** a `Dataset`,
|
|
450
|
+
**`delete()`** answers `needs_person`, and
|
|
749
451
|
**`flipstream.datasetTypes.list()`** gives the `DatasetType`s this version knows (see "A
|
|
750
|
-
workspace's datasets").
|
|
452
|
+
workspace's datasets" in [docs/admin.md](docs/admin.md)).
|
|
751
453
|
- **`flipstream.credentials.list({ limit, offset })`** gives a `Page<Credential>`, and
|
|
752
|
-
**`revoke()`** and **`delete()`** answer `needs_person` (see "Sign-ins to your sources"
|
|
454
|
+
**`revoke()`** and **`delete()`** answer `needs_person` (see "Sign-ins to your sources" in
|
|
455
|
+
[docs/admin.md](docs/admin.md)).
|
|
753
456
|
- **`flipstream.wallet.balance()`** gives a `Balance` or `null`, and
|
|
754
|
-
**`flipstream.wallet.transactions()`** a `Ledger` (see "Wallet"
|
|
457
|
+
**`flipstream.wallet.transactions()`** a `Ledger` or `null` (see "Wallet" in
|
|
458
|
+
[docs/admin.md](docs/admin.md)).
|
|
755
459
|
- **`flipstream.members.list({ limit, offset })`** gives a `Page<Member>`, and
|
|
756
|
-
**`flipstream.members.get({ member_id })`** a `Member` (see "Your organisation's members"
|
|
460
|
+
**`flipstream.members.get({ member_id })`** a `Member` (see "Your organisation's members" in
|
|
461
|
+
[docs/admin.md](docs/admin.md)).
|
|
757
462
|
|
|
758
463
|
**Every answer is checked against the API's spec.** An answer that doesn't match, with a missing
|
|
759
464
|
field or a value of the wrong type, is an `invalid` failure that names the field. It never comes
|
|
760
465
|
back as data. Some of a dataset's fields are read more leniently, so one new or missing backend
|
|
761
466
|
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
|
|
467
|
+
it came, `created_on` and `created_by_id` are `null` when missing, and `history` and
|
|
468
|
+
`refresh_status` are `null` when missing or when they hold a value this version doesn't know. A
|
|
764
469
|
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
|
-
|
|
470
|
+
when it isn't a time, so one member's time never fails `me()` or a page of members. (See "A
|
|
471
|
+
workspace's datasets" and "Your organisation's members" in [docs/admin.md](docs/admin.md).) A field
|
|
472
|
+
the SDK doesn't know yet is kept, except in the answers of `me()`, `workspaces`, `log`, `datasets`,
|
|
473
|
+
`wallet` and `members`, which hold only the fields their types name.
|
|
768
474
|
|
|
769
475
|
## Typed errors
|
|
770
476
|
|
|
@@ -786,11 +492,21 @@ organisation's members"). A field the SDK doesn't know yet is kept, except in th
|
|
|
786
492
|
- It keeps the API's `code` and `message` when the body is an error body, or its `text` when it
|
|
787
493
|
isn't (a proxy's `Bad gateway`). The sign-ins' and the datasets' own reads and writes keep no
|
|
788
494
|
`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
|
|
495
|
+
workspace's datasets" in [docs/admin.md](docs/admin.md)). The reads of your organisation and a
|
|
496
|
+
workspace beside them keep theirs.
|
|
497
|
+
- An `invalid` the SDK finds by checking an answer after it arrived (another organisation's record,
|
|
498
|
+
a page that leaks, an id that can't name the next path) has the `status` that route answers by
|
|
499
|
+
its backend's own code: 200 for every read, and for pause, resume and `log.update`. The SDK takes
|
|
500
|
+
any 2xx as ok, so on Flipstream's routes that status is assumed, never observed. A check of an
|
|
501
|
+
authorisation server's answer, in `discover()` or a session's OpenID configuration, has the 2xx
|
|
502
|
+
that server answered, since any server can be named there. A check of a create's answer
|
|
503
|
+
(`workspaces.create`, `log.add`) has none, since that route's success status isn't known. When
|
|
504
|
+
the read after pause's or resume's write fails, the `invalid` keeps that read's status, if it had
|
|
505
|
+
one.
|
|
790
506
|
- `isPlannerCode(error.code)` narrows the code to the ones the query API documents
|
|
791
507
|
(`PlannerErrorCode`), so a switch over them can be exhaustive. A code added since is kept as it
|
|
792
508
|
came.
|
|
793
|
-
- When the API asked the caller to wait, the failure keeps that as `
|
|
509
|
+
- When the API asked the caller to wait, the failure keeps that as `retry_after_ms`.
|
|
794
510
|
|
|
795
511
|
**A `refused` call says why, in `reason`** (`RefusedReason`), and `orThrow`'s message names it,
|
|
796
512
|
never the value:
|
|
@@ -821,7 +537,7 @@ function explain(error: ApiError): string {
|
|
|
821
537
|
case 'rejected':
|
|
822
538
|
return isPlannerCode(error.code) ? `${error.code}: ${error.message ?? ''}` : `Refused: ${String(error.status)}`
|
|
823
539
|
case 'unavailable':
|
|
824
|
-
return error.status === undefined ? 'No answer: offline?' : `Busy: try again in ${String(error.
|
|
540
|
+
return error.status === undefined ? 'No answer: offline?' : `Busy: try again in ${String(error.retry_after_ms ?? 1000)} ms`
|
|
825
541
|
case 'invalid':
|
|
826
542
|
return `An answer outside the contract: ${error.issues}`
|
|
827
543
|
case 'timeout':
|
|
@@ -898,7 +614,17 @@ await flipstream.catalog.list({ conversationId: 'c-456', traceparent: '00-4bf92f
|
|
|
898
614
|
- A wait that wouldn't end before the deadline isn't started.
|
|
899
615
|
- **Deadlines:** 60 s for `query`, 10 s for `health` and 30 s for the rest (for `me`, its three
|
|
900
616
|
reads together), every attempt and wait included. `deadlineMs` sets one call's.
|
|
901
|
-
-
|
|
617
|
+
- `deadlineMs` is taken in whole ms, rounded down, up to 2147483647, the most a timer holds;
|
|
618
|
+
left out or `null`, the endpoint's own applies. A value that can't be a deadline (not a number,
|
|
619
|
+
`NaN`, ±`Infinity`, or more than that once rounded down) is a `TypeError` naming the call, such
|
|
620
|
+
as `flipstream.catalog.list`, with nothing sent.
|
|
621
|
+
- A spent deadline answers `timeout` and sends nothing: one under 1 ms, or one used up before a
|
|
622
|
+
request would go out, say `me`'s last read once its three reads' 30 s are up.
|
|
623
|
+
- They run on the monotonic clock, as their timers do, so a clock change never moves them. Tests
|
|
624
|
+
that fake only `Date` must also move `performance.now()`, since every deadline runs on it.
|
|
625
|
+
- **Abort:** `signal` ends a call at once, also while it waits for a token or to try again. Any
|
|
626
|
+
object with `aborted` and an `addEventListener` method is taken, a polyfill's or another realm's;
|
|
627
|
+
one with no `removeEventListener` keeps the listeners it was given, and the call keeps its result.
|
|
902
628
|
- **Warnings:** the SDK's warnings go to `onWarning`, or to `console.warn` without it; `() => {}`
|
|
903
629
|
silences them. Today there is one kind: a catalogue format type this version doesn't know,
|
|
904
630
|
reported once per process to the client that read it first. A handler that throws is ignored,
|
|
@@ -906,17 +632,25 @@ await flipstream.catalog.list({ conversationId: 'c-456', traceparent: '00-4bf92f
|
|
|
906
632
|
- **Your own transport:** an app that attaches the token itself passes `{ transport }` instead of
|
|
907
633
|
`token` and `fetch`. Retries and deadlines still apply, above it. `health` carries no token, so
|
|
908
634
|
it never goes through your transport: it goes to the query host, over https, with the global
|
|
909
|
-
`fetch`.
|
|
635
|
+
`fetch`. When your transport rejects a request, the call rejects too, but only once none of its
|
|
636
|
+
reads is still waited on: the call ends its other reads at once, through their `signal`, and the
|
|
637
|
+
rejection is the first read's to reject, in the order the call started them. A failure that comes
|
|
638
|
+
back as a result keeps each call's own order. Your transport may still be running after the call
|
|
639
|
+
ended its read, or after a read's deadline; the SDK no longer waits for it.
|
|
910
640
|
|
|
911
641
|
## Which app sent a request
|
|
912
642
|
|
|
913
643
|
Every signed-in request says which app sent it, and, when you name them, which agent and
|
|
914
644
|
conversation, so a later query log can show who asked what. It reports nothing beyond the request:
|
|
915
|
-
the SDK has no telemetry. In Node, each signed-in request to an API host carries
|
|
645
|
+
the SDK has no telemetry. In Node, each signed-in request to an API host carries `User-Agent`,
|
|
646
|
+
`traceparent` and `baggage`. A browser can't set `User-Agent`, so it sends `Flipstream-Client` in
|
|
647
|
+
its place, with the same `traceparent` and `baggage`, to the hosts whose CORS allows them ("From a
|
|
648
|
+
browser", below).
|
|
916
649
|
|
|
917
650
|
| Header | Value | Standard |
|
|
918
651
|
|---|---|---|
|
|
919
652
|
| `User-Agent` | `<app>/<version> flipstream-sdk/<version> node/<version>` | RFC 9110 product tokens |
|
|
653
|
+
| `Flipstream-Client` | from a browser, in place of `User-Agent`: `<app>/<version> flipstream-sdk/<version>` | RFC 9110 product tokens, in a header of our own (RFC 6648: no `X-`) |
|
|
920
654
|
| `traceparent` | one trace-id per call, kept across its retries and shared by all of a call's requests, with a new parent-id for each request | W3C Trace Context |
|
|
921
655
|
| `baggage` | `gen_ai.agent.name`, `gen_ai.agent.version` and `gen_ai.conversation.id`, percent-encoded, only those given | W3C Baggage, with OpenTelemetry's GenAI names (not stable yet) |
|
|
922
656
|
|
|
@@ -932,19 +666,36 @@ the SDK has no telemetry. In Node, each signed-in request to an API host carries
|
|
|
932
666
|
can't refuse an ordinary value that happens to contain it. With your own transport, the SDK never
|
|
933
667
|
sees the token, so that check is your transport's.
|
|
934
668
|
- **`health` says only who the SDK is.** It's signed out and asks for no token, so it sends
|
|
935
|
-
`User-Agent: flipstream-sdk/<version> node/<version>`
|
|
936
|
-
`agent` or `conversationId`:
|
|
669
|
+
`User-Agent: flipstream-sdk/<version> node/<version>` (from a browser, `Flipstream-Client:
|
|
670
|
+
flipstream-sdk/<version>`) and a `traceparent`, and none of `app`, `agent` or `conversationId`:
|
|
671
|
+
nothing could check them there.
|
|
937
672
|
- **Your trace:** pass `traceparent` on a call to carry on your own trace. The call keeps its
|
|
938
673
|
trace-id and flags, with its own parent-id for each request. One that isn't a valid version-00
|
|
939
674
|
traceparent is dropped, as W3C Trace Context says, and the call starts its own trace, sampled
|
|
940
675
|
(`01`).
|
|
941
676
|
- **Only to the API hosts.** The auth server never gets them: `discover`, sign-in, refresh and
|
|
942
677
|
revoke send none.
|
|
943
|
-
- **
|
|
678
|
+
- **From a browser,** a page with a `document` (Electron's renderer and jsdom included), per host,
|
|
679
|
+
since a browser refuses every call to a host whose CORS doesn't allow these headers:
|
|
680
|
+
- the deployed query API (`https://query.flipstream.io`) gets `Flipstream-Client: <app>/<version>
|
|
681
|
+
flipstream-sdk/<version>`, `traceparent` and `baggage`;
|
|
682
|
+
- a custom `hosts.query` (a proxy, staging, a local planner) gets none, as before, since nothing
|
|
683
|
+
says its CORS allows them;
|
|
684
|
+
- pulse-admin and pulse-wallet get none yet, until their CORS allows them;
|
|
685
|
+
- the auth server never does, as in Node.
|
|
686
|
+
- A host is switched on only once its CORS allows them in its preflight, beside the ones every
|
|
687
|
+
call sends, as the query API's does. A refused preflight reaches the SDK as a network failure,
|
|
688
|
+
which it can't tell apart: it's `unavailable`, and tried again as one.
|
|
689
|
+
|
|
690
|
+
```http
|
|
691
|
+
Access-Control-Allow-Headers: authorization, content-type, traceparent, tracestate, baggage, flipstream-client
|
|
692
|
+
```
|
|
693
|
+
- **Another runtime that isn't Node** (Deno 1.x, a Worker, an edge function, React Native) sends
|
|
694
|
+
none of these headers.
|
|
944
695
|
|
|
945
696
|
## Finding a request in Logs
|
|
946
697
|
|
|
947
|
-
Every result says which trace its call's requests carried, as `
|
|
698
|
+
Every result says which trace its call's requests carried, as `trace_id`, so a person can find them
|
|
948
699
|
in Logs:
|
|
949
700
|
|
|
950
701
|
```ts
|
|
@@ -953,25 +704,25 @@ import { createFlipstream } from '@flipstream/sdk'
|
|
|
953
704
|
const flipstream = createFlipstream({ app: { name: 'my-app', version: '1.0.0' }, token: async () => '<your token>' })
|
|
954
705
|
|
|
955
706
|
const result = await flipstream.catalog.list()
|
|
956
|
-
if (!result.ok) console.error(`${result.error.kind} (request ${result.
|
|
707
|
+
if (!result.ok) console.error(`${result.error.kind} (request ${result.trace_id ?? 'not sent'})`)
|
|
957
708
|
```
|
|
958
709
|
|
|
959
|
-
- **On both arms:** `{ ok: true, data,
|
|
710
|
+
- **On both arms:** `{ ok: true, data, trace_id }` and `{ ok: false, error, trace_id }`. It's the
|
|
960
711
|
W3C trace-id the call's `traceparent` carried: 32 lowercase hex digits.
|
|
961
712
|
- **One call, one trace:** a call that makes several requests, such as `me()`'s reads or
|
|
962
713
|
`workspaces.list()`'s two, sends them all under one trace-id, each with its own parent-id. So
|
|
963
714
|
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 `
|
|
715
|
+
- **Your trace:** a call given your own `traceparent` keeps it, and `trace_id` is its trace-id.
|
|
716
|
+
- **Nothing sent, no `trace_id`:** a call `refused` before anything is sent (a path, fields,
|
|
966
717
|
identification, the conversation's id, the destination) has none, and neither does a `no_token`
|
|
967
718
|
from the first ask for a token.
|
|
968
719
|
- **Once a request went out, the call has one,** whatever comes after: a `no_token` when the token
|
|
969
720
|
function fails after a 401 (the refused request is the one to look up), or a `timeout` while a
|
|
970
721
|
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 <
|
|
722
|
+
reached (refused, or not found by DNS) gives `unavailable` with a `trace_id` that no host logged.
|
|
723
|
+
- **`orThrow`'s message ends with `(request <trace_id>)`** when there is one, so a CLI or an app
|
|
973
724
|
that prints the error carries the id with no code of its own. The `ApiFailure` it throws has the
|
|
974
|
-
id as `
|
|
725
|
+
id as `trace_id` too, for a log field or an error tracker's tag:
|
|
975
726
|
|
|
976
727
|
```ts
|
|
977
728
|
import { ApiFailure, createFlipstream, orThrow } from '@flipstream/sdk'
|
|
@@ -981,17 +732,18 @@ if (!result.ok) console.error(`${result.error.kind} (request ${result.traceId ??
|
|
|
981
732
|
try {
|
|
982
733
|
orThrow(await flipstream.catalog.list())
|
|
983
734
|
} catch (error) {
|
|
984
|
-
if (error instanceof ApiFailure) console.error(error.error.kind, error.
|
|
735
|
+
if (error instanceof ApiFailure) console.error(error.error.kind, error.trace_id ?? 'not sent')
|
|
985
736
|
}
|
|
986
737
|
```
|
|
987
738
|
|
|
988
739
|
It's there only when the result had one, and only as a W3C trace-id.
|
|
989
740
|
- **Only what reaches the API hosts is in it:** the auth server gets no `traceparent`, so a read
|
|
990
741
|
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 `
|
|
742
|
+
- **With your own transport,** the SDK can't see the request leave, so a result has `trace_id` once
|
|
992
743
|
an answer came back.
|
|
993
|
-
- **
|
|
994
|
-
|
|
744
|
+
- **From a browser,** a call to the deployed query API has its `trace_id`. A call to a custom query
|
|
745
|
+
host, pulse-admin or pulse-wallet has none: a browser sends those hosts no `traceparent` (see
|
|
746
|
+
"Which app sent a request").
|
|
995
747
|
- **The service's side:** finding the id needs the API hosts to log it, and Logs to index it. Until
|
|
996
748
|
then, the id is still the one to quote.
|
|
997
749
|
|
|
@@ -1013,7 +765,10 @@ reads the same in Node and in a browser bundle, with no file to load.
|
|
|
1013
765
|
- **ESM.** The package is ES modules only. On these Node versions, `require()` loads it from
|
|
1014
766
|
CommonJS too, both entries; Node 22.12 prints an experimental warning when it does.
|
|
1015
767
|
- **The types ship in the package,** for both entries. The Node entry's types use Node's own,
|
|
1016
|
-
from `@types/node`.
|
|
768
|
+
from `@types/node`. A scope's type names `Symbol.asyncDispose`, which the SDK's types declare,
|
|
769
|
+
so a project with only the ES2022 and DOM libs reads it too. `await using` itself needs
|
|
770
|
+
TypeScript's `ESNext.Disposable` lib, or Node's types, and a runtime that has the symbol;
|
|
771
|
+
`close()` works everywhere.
|
|
1017
772
|
- **`keychainStore` needs `@napi-rs/keyring` 2.1 or later,** an optional peer dependency. Nothing
|
|
1018
773
|
else needs it, and npm doesn't install it for you.
|
|
1019
774
|
|