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