@flipstream/sdk 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +48 -20
  3. package/dist/api/backend.d.ts +7 -0
  4. package/dist/api/backend.js +7 -0
  5. package/dist/api/backend.js.map +1 -1
  6. package/dist/api/credentials.js +4 -4
  7. package/dist/api/credentials.js.map +1 -1
  8. package/dist/api/datasets.js +30 -50
  9. package/dist/api/datasets.js.map +1 -1
  10. package/dist/api/handoff.d.ts +1 -1
  11. package/dist/api/handoff.js +7 -0
  12. package/dist/api/handoff.js.map +1 -1
  13. package/dist/api/log.d.ts +4 -4
  14. package/dist/api/log.js +23 -42
  15. package/dist/api/log.js.map +1 -1
  16. package/dist/api/me.d.ts +5 -3
  17. package/dist/api/me.js +3 -3
  18. package/dist/api/me.js.map +1 -1
  19. package/dist/api/members.d.ts +40 -17
  20. package/dist/api/members.js +66 -29
  21. package/dist/api/members.js.map +1 -1
  22. package/dist/api/ownRecord.d.ts +46 -0
  23. package/dist/api/ownRecord.js +57 -0
  24. package/dist/api/ownRecord.js.map +1 -0
  25. package/dist/api/refusal.d.ts +14 -0
  26. package/dist/api/refusal.js +23 -0
  27. package/dist/api/refusal.js.map +1 -0
  28. package/dist/api/wallet.d.ts +2 -1
  29. package/dist/api/wallet.js +18 -24
  30. package/dist/api/wallet.js.map +1 -1
  31. package/dist/api/workspaces.d.ts +7 -2
  32. package/dist/api/workspaces.js +14 -8
  33. package/dist/api/workspaces.js.map +1 -1
  34. package/dist/auth/discovery.js +4 -5
  35. package/dist/auth/discovery.js.map +1 -1
  36. package/dist/core/call.d.ts +5 -4
  37. package/dist/core/call.js +5 -7
  38. package/dist/core/call.js.map +1 -1
  39. package/dist/core/identify.d.ts +6 -0
  40. package/dist/core/identify.js +15 -7
  41. package/dist/core/identify.js.map +1 -1
  42. package/dist/core/inPlaceOf.d.ts +6 -0
  43. package/dist/core/inPlaceOf.js +17 -0
  44. package/dist/core/inPlaceOf.js.map +1 -0
  45. package/dist/core/invalid.d.ts +32 -9
  46. package/dist/core/invalid.js +36 -23
  47. package/dist/core/invalid.js.map +1 -1
  48. package/dist/core/notFound.d.ts +2 -2
  49. package/dist/core/notFound.js.map +1 -1
  50. package/dist/core/read.d.ts +4 -10
  51. package/dist/core/read.js +1 -11
  52. package/dist/core/read.js.map +1 -1
  53. package/dist/core/result.d.ts +13 -9
  54. package/dist/core/result.js +1 -0
  55. package/dist/core/result.js.map +1 -1
  56. package/dist/core/shared.d.ts +13 -9
  57. package/dist/core/shared.js +7 -6
  58. package/dist/core/shared.js.map +1 -1
  59. package/dist/flipstream.d.ts +81 -27
  60. package/dist/flipstream.js +37 -26
  61. package/dist/flipstream.js.map +1 -1
  62. package/dist/index.d.ts +2 -2
  63. package/dist/index.js +3 -2
  64. package/dist/index.js.map +1 -1
  65. package/dist/node/keychainChild.js +60 -25
  66. package/dist/node/keychainChild.js.map +1 -1
  67. package/dist/node/keychainError.d.ts +4 -1
  68. package/dist/node/keychainError.js.map +1 -1
  69. package/dist/node/keychainStore.js +42 -8
  70. package/dist/node/keychainStore.js.map +1 -1
  71. package/dist/node/session.js +6 -7
  72. package/dist/node/session.js.map +1 -1
  73. package/dist/query/query.d.ts +52 -8
  74. package/dist/query/query.js +133 -19
  75. package/dist/query/query.js.map +1 -1
  76. package/dist/version.gen.js +1 -1
  77. package/docs/admin.md +53 -4
  78. package/docs/node-sign-in.md +8 -4
  79. package/package.json +1 -1
package/docs/admin.md CHANGED
@@ -95,6 +95,13 @@ section's basics, and its most common example, are in the package's README under
95
95
  token reaches, such as Flipstream's staff acting through a swap token. The organisation is
96
96
  checked before the key, so another organisation's key is `invalid` too. So is an answer that
97
97
  is someone else than the person asked for.
98
+ - **Removing someone from your organisation is a person's to do, in the console.** It can't be
99
+ undone. `flipstream.members.remove({ member_id })` never writes. It reads the person first, by
100
+ `get`'s rules above: `not_found` when there's no such person for you (an API key included),
101
+ `forbidden` when pulse-auth refuses the read, and `invalid` for another organisation's person.
102
+ Then it answers `needs_person` with `why`, and, where a console can be named (your own
103
+ `hosts.console`), the person's page in People as `url`, with what it shows as `sees`, as
104
+ `datasets.delete` does. There, Owners and Admins remove them.
98
105
 
99
106
  ## The workspaces you open
100
107
 
@@ -107,6 +114,20 @@ section's basics, and its most common example, are in the package's README under
107
114
  no workspace opens every one, whatever its role, a role read as none included.
108
115
  - **One you don't open is `not_found`,** exactly as one nobody has, so the answer says no more than
109
116
  that. A write sends nothing, and a hand-off isn't made.
117
+ - **A record the service refuses you is `not_found` too** (D578): its own refusal of the record's
118
+ read, a 403 with code `FORBIDDEN_EXCEPTION`, says it exists, so it's answered as one nobody has, as
119
+ a workspace you don't open is (D571). That holds for a workspace's own read, in every call under
120
+ one, and for a record named by its id. In a scope, the answer names the same request as a record
121
+ nobody has would.
122
+ - **Still `forbidden`:**
123
+ - your own read's refusal;
124
+ - a 403 that isn't the service's own refusal of the record: a page from something in front of
125
+ it, such as a proxy or a sign-in gate, or the service's refusal of the token
126
+ (`TOKEN_INVALID_EXCEPTION`). Those say nothing about the record;
127
+ - a 403 on a workspace's list read beside it;
128
+ - a write's own 403 once the record is read: a role that can read but not write.
129
+ - **Accepted knowingly:** a role the service refuses every record gets `not_found` for every id,
130
+ and so does a token whose scopes don't cover the route, since the service refuses both alike.
110
131
  - **When it's checked:**
111
132
  - **A workspace named up front** (a workspace's own calls, its logbook's `list` and `add`, its
112
133
  datasets' `list` and `count`): your organisation and you are read first. One you don't open is
@@ -116,8 +137,19 @@ section's basics, and its most common example, are in the package's README under
116
137
  yours, then the workspace's, then the list's, is the answer.
117
138
  - **A record named by its id** (an entry's `get`, `update` and `remove`; a dataset's `get`,
118
139
  `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.
140
+ read beside it, and the service's own failure of that read is passed on as it came, but its own
141
+ refusal of the record, which is `not_found` (D578, above). The answer is your organisation's
142
+ failure, then yours, then the record's, then its checks: another organisation's record is
143
+ `invalid`, and one in a workspace you don't open is `not_found`.
144
+ - A sign-in whose read of you fails, such as one the sign-in service refuses or one that isn't
145
+ a person, gets that failure whether the record exists or not, so it can't tell the two apart.
146
+ Once your read has failed, the call answers without waiting for the record.
147
+ - A sign-in that isn't a person, such as a service account, gets `not_found` with the sign-in
148
+ service's code, `USER_NOT_FOUND`: the same kind as a record nobody has, so read `error.code`
149
+ to tell the two apart.
150
+ - Another organisation's record answering `invalid` still says it exists, to a token the service
151
+ answers other organisations' records for, such as Flipstream's own staff's. That's intended:
152
+ such a record is never shown as yours.
121
153
  - **You're read as `flipstream.me()` reads you:** who your token belongs to, then that person, under
122
154
  the call's deadline. That's one more round trip to the sign-in service per call, two reads in a
123
155
  row, with nothing cached. In a scope, the calls of one piece of work share it (see "One piece of
@@ -181,10 +213,26 @@ section's basics, and its most common example, are in the package's README under
181
213
  - **Closing a scope ends its reads still on their way,** and a call still waiting on one answers
182
214
  `aborted`. A call that takes a closed scope reads its own, as outside a scope: a late refetch is
183
215
  fine.
184
- - **A shared read goes out under a trace of its own,** never a caller's `traceparent`, and every call
216
+ - **A shared read goes out under a trace of its own,** never a call's `traceparent`, and every call
185
217
  it answers names that trace in `trace_id` (see "Finding a request in Logs" in
186
218
  [README.md](../README.md)): the read's whose failure is the call's answer, else the call's own
187
219
  requests', else the first shared read the call asked for.
220
+ - **Or under the scope's trace, when you give it one:** `flipstream.scope({ traceparent })` and
221
+ `withScope(run, { traceparent })` take your W3C trace context, as a call's `traceparent` does
222
+ (#409). Every shared read the scope sends to the admin host, your organisation's and a
223
+ workspace's own, goes out under its trace-id and flags, with a parent-id of its own for each
224
+ attempt, and the calls those reads answer name that trace-id. So one command is one trace.
225
+ - Your reads of you go to the sign-in service, which no request carries a trace to, so they carry
226
+ none, with or without it.
227
+ - From a browser, the SDK sends the admin host no trace yet, until its CORS allows one (see
228
+ "Which app sent a request" in [README.md](../README.md)), so there the option changes nothing.
229
+ - A call names the request that answered it as its `trace_id`. So a call answered by shared
230
+ reads alone, such as `me()`, names the scope's trace-id, even when it was given its own
231
+ `traceparent`.
232
+ - One that isn't a valid version-00 traceparent, a value that isn't a string included, is dropped
233
+ silently, as a call's is, and the shared reads keep traces of their own.
234
+ - It never reaches a call's own requests: those take the call's own `traceparent`, or a trace of
235
+ their own. And a call's own `traceparent` never reaches a shared read.
188
236
 
189
237
  ## Workspaces
190
238
 
@@ -360,7 +408,8 @@ orThrow(await flipstream.log.remove({ log_id: added.id })) // null
360
408
  nothing else: never a credential, a setting or its parameters, beyond its account's id. The
361
409
  service's answer embeds the dataset's sign-in, so a body that isn't the service's JSON is never
362
410
  kept either: a failure of the dataset's own read or write gives its kind and status, with no
363
- `text`. The reads of your organisation and the workspace beside it keep theirs.
411
+ `text`. The reads of your organisation and the workspace beside it keep theirs, but the service's
412
+ own refusal of the workspace, which is `not_found` (see "The workspaces you open").
364
413
  - `type` is one of the types `datasetTypes.list()` gives, such as `'google_search_console'`, or
365
414
  a type this version doesn't know yet, kept as it came, so a new kind of dataset never makes the
366
415
  list unreadable. It's `null` when the service holds no type for it.
@@ -207,7 +207,11 @@ if (signedOut.cleared === 'failed') {
207
207
  reboot;
208
208
  - `refused`: any other refusal, in the keychain's own words;
209
209
  - `timeout`: the step took longer than its `timeoutMs`;
210
- - `helper`: the helper process couldn't start, or ended before it answered (`exit` says how);
210
+ - `helper`: the helper process couldn't start, or ended before it answered (`exit` says how).
211
+ One that couldn't start for want of file descriptors (`EMFILE`, your process's own limit, or
212
+ `ENFILE`, the whole system's table) has the spawn's own error, with that `code`, as the
213
+ error's `cause`, when Node reports it in time: a hint for your logs, not a promise, so never
214
+ let your app depend on it;
211
215
  - `missing`: `@napi-rs/keyring` isn't installed, and the message names it;
212
216
  - `too-long`: the tokens are over 2,560 bytes, so nothing was saved.
213
217
 
@@ -242,9 +246,9 @@ if (signedOut.cleared === 'failed') {
242
246
  the same 30 s. The helper never keeps your app running. It's `process.execPath`, so it needs a
243
247
  Node that runs a script: not an Electron app (without `ELECTRON_RUN_AS_NODE`), a Node
244
248
  single-executable application, or a compiled Bun binary. A bundle must keep `keychainChild.js`
245
- beside the module, with `zod` and `@napi-rs/keyring` resolvable from there, and
246
- `import.meta.url` set. Where it doesn't (an esbuild CommonJS bundle, say), only the keychain's
247
- steps fail, as `store_failed`.
249
+ beside the module, with `@napi-rs/keyring` resolvable from there, and `import.meta.url` set.
250
+ Where it doesn't (an esbuild CommonJS bundle, say), only the keychain's steps fail, as
251
+ `store_failed`.
248
252
  - Through `session.token()`, a keychain read that takes longer than the caller's wait, 15 s
249
253
  unless you pass `createSession({ waitMs })`, is `unavailable`. On macOS a read can wait on
250
254
  an access dialog, every time, for an item another program saved: give `waitMs` as long as
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipstream/sdk",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "TypeScript SDK for the Flipstream APIs: typed requests and checked answers, in Node and in browsers.",
5
5
  "keywords": [
6
6
  "flipstream",