@flipstream/sdk 0.7.0 → 0.9.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 (51) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +211 -65
  3. package/dist/auth/discovery.js +1 -1
  4. package/dist/auth/discovery.js.map +1 -1
  5. package/dist/auth/signIn.js +7 -2
  6. package/dist/auth/signIn.js.map +1 -1
  7. package/dist/core/fetch.d.ts +5 -0
  8. package/dist/core/fetch.js +3 -0
  9. package/dist/core/fetch.js.map +1 -1
  10. package/dist/core/identify.d.ts +63 -0
  11. package/dist/core/identify.js +122 -0
  12. package/dist/core/identify.js.map +1 -0
  13. package/dist/core/names.d.ts +61 -0
  14. package/dist/core/names.js +73 -0
  15. package/dist/core/names.js.map +1 -0
  16. package/dist/core/read.js +8 -2
  17. package/dist/core/read.js.map +1 -1
  18. package/dist/core/result.d.ts +26 -3
  19. package/dist/core/result.js +22 -3
  20. package/dist/core/result.js.map +1 -1
  21. package/dist/core/transport.d.ts +6 -2
  22. package/dist/flipstream.d.ts +47 -3
  23. package/dist/flipstream.js +46 -5
  24. package/dist/flipstream.js.map +1 -1
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/node/clientSecret.js +1 -1
  29. package/dist/node/clientSecret.js.map +1 -1
  30. package/dist/node/index.d.ts +3 -0
  31. package/dist/node/index.js +2 -0
  32. package/dist/node/index.js.map +1 -1
  33. package/dist/node/keychainChild.js +78 -18
  34. package/dist/node/keychainChild.js.map +1 -1
  35. package/dist/node/keychainError.d.ts +53 -0
  36. package/dist/node/keychainError.js +48 -0
  37. package/dist/node/keychainError.js.map +1 -0
  38. package/dist/node/keychainStore.d.ts +19 -9
  39. package/dist/node/keychainStore.js +61 -27
  40. package/dist/node/keychainStore.js.map +1 -1
  41. package/dist/node/session.d.ts +88 -28
  42. package/dist/node/session.js +60 -40
  43. package/dist/node/session.js.map +1 -1
  44. package/dist/node/store.d.ts +11 -1
  45. package/dist/node/store.js +14 -1
  46. package/dist/node/store.js.map +1 -1
  47. package/dist/query/query.d.ts +15 -10
  48. package/dist/query/query.js +21 -11
  49. package/dist/query/query.js.map +1 -1
  50. package/dist/version.gen.js +1 -1
  51. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.8.0...typescript-v0.9.0) (2026-10-31)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * **typescript:** RevokeResult gains a required `cleared`, and revoke() now answers once its clear is done, which can take minutes on a stalled store, where it used to answer within 10 s. When `cleared` is `failed`, `failure: { step, cause }` says where the store failed (`read`, `lock` or `clear`) and what it threw. Adds StoreMovedOnError, for a store that has moved on: `fileStore` and `keychainStore` now throw `StoreMovedOnError` where they threw a plain `Error`. A store of your own should throw it too: a sign-out then says `kept`, and any other throw from its clear says `failed`.
9
+ * **typescript:** createFlipstream requires app: { name, version }, on both ways of making a client. In Node, each request to an API host says which app sent it (User-Agent), carries a W3C traceparent, and, when given, the agent and conversation as baggage.
10
+
11
+ ### Features
12
+
13
+ * **typescript:** a query names its dataset as dataset_id, sent as connection_id ([#207](https://github.com/flipstream-io/sdk/issues/207)) ([2f1e956](https://github.com/flipstream-io/sdk/commit/2f1e956ccb5cdab75afa5e0619caf53d2f015e8d))
14
+ * **typescript:** a refused call says why, in reason ([#204](https://github.com/flipstream-io/sdk/issues/204)) ([b1cebb6](https://github.com/flipstream-io/sdk/commit/b1cebb658da12509fdc771afd623671a047d6850))
15
+ * **typescript:** every request says which app and agent sent it ([#195](https://github.com/flipstream-io/sdk/issues/195)) ([5653c8a](https://github.com/flipstream-io/sdk/commit/5653c8aa317147eb1a1e0fa0eeacd9fe19ce04d7))
16
+ * **typescript:** revoke() waits for its clear, and says how it went ([#197](https://github.com/flipstream-io/sdk/issues/197)) ([8936d61](https://github.com/flipstream-io/sdk/commit/8936d61d255ccbfdb7268d852757b5049a5226e0))
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **typescript:** a short token refuses only a value equal to it ([#203](https://github.com/flipstream-io/sdk/issues/203)) ([ea05225](https://github.com/flipstream-io/sdk/commit/ea0522560a20e5d366fc59734cdbf6a4d4331024))
22
+ * **typescript:** health sends none of the caller's values ([#202](https://github.com/flipstream-io/sdk/issues/202)) ([32ce143](https://github.com/flipstream-io/sdk/commit/32ce143f2fbca14e48d648cbc645f01921f082f2))
23
+ * **typescript:** the keychain helper ignores Ctrl-C before zod loads ([#201](https://github.com/flipstream-io/sdk/issues/201)) ([660ea0c](https://github.com/flipstream-io/sdk/commit/660ea0ca393f084afb287e4b082c05f102aaf784))
24
+
25
+
26
+ ### Miscellaneous
27
+
28
+ * **typescript:** the client is flipstream, not fs ([#227](https://github.com/flipstream-io/sdk/issues/227)) ([8ae4981](https://github.com/flipstream-io/sdk/commit/8ae498154263e9ee954e51a68456b6cc0804121a))
29
+
30
+
31
+ ### Tests
32
+
33
+ * **typescript:** a keychain test follows its helper by its spawn ([#200](https://github.com/flipstream-io/sdk/issues/200)) ([58d747d](https://github.com/flipstream-io/sdk/commit/58d747dabff2c908cb392b7ccb7f23a3b665adee))
34
+
35
+ ## [0.8.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.7.0...typescript-v0.8.0) (2026-10-23)
36
+
37
+
38
+ ### Features
39
+
40
+ * **typescript:** a KeychainError says why a keychain step failed ([#181](https://github.com/flipstream-io/sdk/issues/181)) ([4cafc6a](https://github.com/flipstream-io/sdk/commit/4cafc6ab8969214b80f0098ce36830f50147650e))
41
+ * **typescript:** createSession({ waitMs }) for stores that ask a person ([#188](https://github.com/flipstream-io/sdk/issues/188)) ([a45b790](https://github.com/flipstream-io/sdk/commit/a45b79034456dc284cddae746911c5c158bcbf4d))
42
+
43
+
44
+ ### Bug Fixes
45
+
46
+ * **typescript:** a keychain helper slow to start can't land a late save ([#191](https://github.com/flipstream-io/sdk/issues/191)) ([24a6cd0](https://github.com/flipstream-io/sdk/commit/24a6cd083258df09c72daf2a7b9b26d6e4657aca))
47
+ * **typescript:** the keychain helper finishes its step through a Ctrl-C ([#175](https://github.com/flipstream-io/sdk/issues/175)) ([7eced26](https://github.com/flipstream-io/sdk/commit/7eced261f5b143ad4820ba0715014e3b9467cb85))
48
+
49
+
50
+ ### Documentation
51
+
52
+ * **typescript:** on macOS, the keychain dialog stays open after Ctrl-C ([#189](https://github.com/flipstream-io/sdk/issues/189)) ([ef679bd](https://github.com/flipstream-io/sdk/commit/ef679bde3df414154e2c75340530120dbf85fd1c))
53
+
3
54
  ## [0.7.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.6.0...typescript-v0.7.0) (2026-10-18)
4
55
 
5
56
 
package/README.md CHANGED
@@ -26,16 +26,20 @@ npm install @flipstream/sdk
26
26
  ```ts
27
27
  import { createFlipstream, orThrow } from '@flipstream/sdk'
28
28
 
29
- // Asked before every attempt: return the current access token.
30
- const fs = createFlipstream({ token: async () => '<your token>' })
29
+ const flipstream = createFlipstream({
30
+ // Required: every request says which app sent it (see "Which app sent a request").
31
+ app: { name: 'my-app', version: '1.0.0' },
32
+ // Asked before every attempt: return the current access token.
33
+ token: async () => '<your token>',
34
+ })
31
35
 
32
- const catalog = await fs.catalog.list()
36
+ const catalog = await flipstream.catalog.list()
33
37
  if (!catalog.ok) console.error(catalog.error.kind) // 'unauthorized', 'unavailable', …
34
38
 
35
39
  const answer = orThrow(
36
- await fs.query({
40
+ await flipstream.query({
37
41
  source: '<source>',
38
- connection_id: '<connection id>',
42
+ dataset_id: '<dataset id>',
39
43
  dimensions: ['<dimension>'],
40
44
  metrics: ['<metric>'],
41
45
  }),
@@ -43,8 +47,8 @@ const answer = orThrow(
43
47
  console.log(answer.rows, answer.lastRow)
44
48
  ```
45
49
 
46
- The catalogue names each source with its dimensions and metrics. `fs.catalog.get({ source })` gives
47
- one source.
50
+ The catalogue names each source with its dimensions and metrics.
51
+ `flipstream.catalog.get({ source })` gives one source.
48
52
 
49
53
  Each dimension and metric has a `format`, a union on its `type`:
50
54
  - `number`, `currency` and `percentage` carry `decimals`, and a `number` may carry
@@ -119,7 +123,7 @@ const signedIn = await signInWithLoopback({
119
123
  })
120
124
  if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
121
125
 
122
- const fs = createFlipstream({ token: () => signedIn.data.accessToken })
126
+ const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: () => signedIn.data.accessToken })
123
127
  ```
124
128
 
125
129
  - **The SDK opens nothing and writes nothing to the terminal.** `open` does that, once the port is
@@ -221,7 +225,7 @@ SDK has two stores ready for it, which keep the store's rules for you.
221
225
 
222
226
  ```ts
223
227
  import { createFlipstream, discover } from '@flipstream/sdk'
224
- import { createSession, fileStore, keychainStore, signInWithLoopback } from '@flipstream/sdk/node'
228
+ import { createSession, fileStore, KeychainError, keychainStore, signInWithLoopback } from '@flipstream/sdk/node'
225
229
  import { homedir } from 'node:os'
226
230
  import { join } from 'node:path'
227
231
 
@@ -239,7 +243,10 @@ if (inFile) console.error(`Your sign-in is kept in ${tokensFile}, which only you
239
243
  const saved = await store.tokens().catch((error: unknown) => {
240
244
  const why = error instanceof Error ? error.message : String(error)
241
245
  if (inFile) throw new Error(`${tokensFile} can't be read (${why})`)
242
- throw new Error(`the keychain can't be read (${why}): if it's locked, unlock it or log in at this machine once; where there is no keychain, run with --tokens-in-file`)
246
+ const kind = error instanceof KeychainError ? error.failure.kind : undefined
247
+ if (kind === 'unavailable') throw new Error('this machine has no keychain: run with --tokens-in-file')
248
+ if (kind === 'locked') throw new Error('the keychain is locked: unlock it, or log in at this machine once')
249
+ throw new Error(`the keychain can't be read (${why})`)
243
250
  })
244
251
 
245
252
  // Sign in once, and save the tokens. Only signing in needs the server first.
@@ -260,11 +267,19 @@ if (saved === null) {
260
267
 
261
268
  // The session discovers the server itself, only when a refresh or a sign-out needs it.
262
269
  const session = createSession({ issuer, clientId: '<your client id>', ...store })
263
- const fs = createFlipstream({ token: session.token })
270
+ const flipstream = createFlipstream({ app: { name: 'my-cli', version: '1.0.0' }, token: session.token })
264
271
 
265
- // Signing out ends the session at the server, and clears the store through onTokens.
272
+ // Signing out ends the session at the server, then clears the store through onTokens, and says
273
+ // how each went.
266
274
  const signedOut = await session.revoke()
267
275
  console.log(signedOut.kind)
276
+ if (signedOut.cleared === 'failed') {
277
+ // Where the store failed (read, lock or clear), and its own error: a KeychainError says why.
278
+ const { step, cause } = signedOut.failure
279
+ console.error(`the tokens may still be stored: the ${step} failed (${cause instanceof Error ? cause.message : String(cause)})`)
280
+ } else if (signedOut.cleared !== 'cleared' && signedOut.cleared !== 'kept') {
281
+ console.error(`the tokens may still be stored (${signedOut.cleared}): sign out again`)
282
+ }
268
283
  ```
269
284
 
270
285
  - **`issuer`,** as above, discovers the server itself, only when a refresh or a sign-out needs it,
@@ -300,29 +315,65 @@ console.log(signedOut.kind)
300
315
  - **`keychainStore({ service, account })`** keeps the tokens in one item of the system's
301
316
  credential store: the macOS keychain, Windows' Credential Manager, or the Secret Service on
302
317
  Linux (GNOME Keyring, KWallet). It needs the optional package `@napi-rs/keyring`
303
- (`npm install @napi-rs/keyring`); without it, every step fails as `store_failed`, naming the
304
- package.
318
+ (`npm install @napi-rs/keyring`).
319
+ - **Every failure of the keychain or its helper is a `KeychainError`,** which is also the
320
+ `cause` of a session's `store_failed`. Three failures are the store's own, not the
321
+ keychain's: `save` rejects tokens with no access token as a `TypeError` before any step; an
322
+ item holding something other than tokens fails its read with a plain `Error` that never
323
+ quotes it; and an update for tokens the item no longer holds is refused with a
324
+ `StoreMovedOnError`, which a sign-out reads as `kept` and a refresh reports as `store_failed`
325
+ (`save`). A `KeychainError`'s `failure.kind` says why:
326
+ - `unavailable`: there's no keychain on this machine, as on Linux with no Secret Service or no
327
+ D-Bus session (most servers and containers). It's the only kind after which a file may
328
+ stand in, if your app or the person chooses it;
329
+ - `locked`: the keychain is locked and can't ask to be unlocked, as on a Mac over SSH after a
330
+ reboot;
331
+ - `refused`: any other refusal, in the keychain's own words;
332
+ - `timeout`: the step took longer than its `timeoutMs`;
333
+ - `helper`: the helper process couldn't start, or ended before it answered (`exit` says how);
334
+ - `missing`: `@napi-rs/keyring` isn't installed, and the message names it;
335
+ - `too-long`: the tokens are over 2,560 bytes, so nothing was saved.
336
+
337
+ `unavailable` and `locked` are read from the keychain library's words, which carry no code.
338
+ Only words known for them match, and anything else is `refused`. The words for a locked
339
+ macOS keychain, and any on Windows, haven't been seen yet, so those failures may read as
340
+ `refused` for now.
305
341
  - Its steps run in one helper process, one at a time. The first step starts it, and it stays
306
342
  warm while your app runs (about 57 MB), so a step after that takes a keychain call, not a
307
343
  process start. A step that takes longer than 30 s (`timeoutMs`) ends it, so a keychain prompt
308
- that nobody answers can't hold up your app, and the next step starts another. A step whose
309
- helper died before it answered (a Ctrl-C reaches the helper too) runs once more on a fresh
310
- one, within the same 30 s. The helper never keeps your app running, and it ends when your
311
- app does. It's `process.execPath`, so
312
- it needs a Node that runs a script: not an Electron app (without `ELECTRON_RUN_AS_NODE`), a
313
- Node single-executable application, or a compiled Bun binary. A bundle must keep
344
+ that nobody answers can't hold up your app, and the next step starts another. A Ctrl-C in
345
+ the terminal reaches the helper too, and it ignores it, from before its own code loads. Not
346
+ during Node's own start-up, though, or any preload in `NODE_OPTIONS`: a Ctrl-C then still
347
+ ends a helper that is just starting. When your app ends, the helper ends
348
+ too: at once if it's idle or reading, or once it has finished the save or delete it's on, so
349
+ a refresh's save isn't lost to a Ctrl-C. It gives that step 1 s more at most, less than the
350
+ soonest `fileLock` lets another process take the lock your app held: at the soonest about
351
+ 2 s after your app ends, for an app whose heartbeat was running (3 s after its last touch),
352
+ when the clock has stepped or your app's clock runs behind. So a late save can't land over
353
+ that process's. For a helper's first step, that 1 s counts from the helper's own start, so a
354
+ helper slow to start (on a loaded machine, say) can't stretch it. A first step still going
355
+ when your app ends may therefore be cut sooner. A save waiting on a keychain prompt is ended
356
+ then. On macOS, the keychain's
357
+ own dialog stays open after a Ctrl-C until someone answers it, even once your app and its
358
+ helper have ended. A step whose helper died
359
+ before it answered runs once more on a fresh one, within the same 30 s. The helper never
360
+ keeps your app running. It's `process.execPath`, so it needs a Node that runs a script: not an Electron
361
+ app (without `ELECTRON_RUN_AS_NODE`), a Node single-executable application, or a compiled
362
+ Bun binary. A bundle must keep
314
363
  `keychainChild.js` beside the module, with `zod` and `@napi-rs/keyring` resolvable from
315
364
  there, and `import.meta.url` set. Where it doesn't (an esbuild CommonJS bundle, say), only the
316
365
  keychain's steps fail, as `store_failed`.
317
- - Through `session.token()`, a keychain read that takes longer than the caller's 15 s wait is
318
- `unavailable`. A longer `timeoutMs` helps your own `tokens`, `save` and `clear`, and a
319
- refresh, which goes on after the caller's wait.
366
+ - Through `session.token()`, a keychain read that takes longer than the caller's wait, 15 s
367
+ unless you pass `createSession({ waitMs })`, is `unavailable`. On macOS a read can wait on
368
+ an access dialog, every time, for an item another program saved: give `waitMs` as long as
369
+ the person may take. Each keychain step still ends at its own `timeoutMs`.
320
370
  - Tokens over 2,560 bytes, Windows' limit, kept on every platform, fail the save with nothing
321
371
  written. A Flipstream sign-in's tokens take about 1.6 KB.
322
- - On Linux without a Secret Service, as on most servers, use `fileStore`.
372
+ - On Linux without a Secret Service, as on most servers, every step is `unavailable`: use
373
+ `fileStore`.
323
374
  - Over SSH on a Mac it works too, unless the keychain is locked, as after a reboot with nobody
324
- logged in at the screen: then every step fails, at the latest after its 30 s, until the person
325
- logs in at the machine once, or runs `security unlock-keychain`.
375
+ logged in at the screen. Then every step fails, as `locked` or at the latest after its 30 s,
376
+ until the person logs in at the machine once, or runs `security unlock-keychain`.
326
377
  - On macOS, a script run by the same Node can read the item without a prompt, much as with a
327
378
  file only the person can read.
328
379
  - It's tested on macOS. Windows and Linux aren't tested yet.
@@ -336,7 +387,11 @@ console.log(signedOut.kind)
336
387
  - **Across processes,** take the session's lock around `save` and `clear` too: a store's compare
337
388
  and its write are one step only among processes that take turns.
338
389
  - **`session.token()`** rejects with a `SessionError` when there's no token to give: `signed-out`,
339
- `unavailable` (after 15 s at most), `store_failed` or `refresh_failed`.
390
+ `unavailable`, `store_failed` or `refresh_failed`.
391
+ - **`unavailable` comes at the caller's wait,** the store's read included: 15 s unless you pass
392
+ `createSession({ waitMs })`. Give a store that can wait on a person, such as a keychain asking
393
+ for access, as long as they may take: 120 s when interactive, say. Only this wait changes. A
394
+ refresh still waits at most 60 s for its answer, and a sign-out sends nothing after its 10 s.
340
395
  - **Before your process exits, `await session.settled()`.** It resolves once the session has no
341
396
  refresh, save or sign-out in flight. `unavailable` comes while a refresh may still be saving the
342
397
  token it got, and an exit then loses it. It never rejects and starts nothing.
@@ -344,26 +399,52 @@ console.log(signedOut.kind)
344
399
  a save holds it, and so does a lock that ignores its signal. A sign-out's store call still
345
400
  running after 60 s isn't waited for.
346
401
  - **The SDK's own stores answer every call.** A `keychainStore` save or clear is two steps of up
347
- to its `timeoutMs` each, so keep `timeoutMs` at 30 s or under, or a sign-out's clear can be cut.
402
+ to its `timeoutMs` each, so keep `timeoutMs` at 30 s or under, or a sign-out's clear can be cut,
403
+ which it reports as `cut`.
348
404
  - **Stop making calls before you await it:** calls that keep coming keep it waiting.
349
- - **`session.revoke()`** gives `revoked`, or `unconfirmed` with the reason. It ends the session the
350
- store holds when its turn comes, and, whatever the result, clears it through `onTokens`
351
- (`cleared`), once, in the same hold of the lock, so a refresh can't bring it back. A sign-in saved
352
- after that is kept. A refresh token the session holds only because saving it failed goes too,
353
- after the stored session, even once the store has moved on, and the session then lets it go. It waits for the clear at most 10 s. After `timeout` or `aborted`, the clear
354
- may still be on its way: once it reaches the lock, it waits at most 60 s for the lock and for each
355
- of its three store calls, so up to about four minutes. A lock held longer than its 60 s by another
356
- process, or a store call that doesn't answer within its 60 s, leaves the store as it was.
405
+ - **`session.revoke()`** ends the session the store holds when its turn comes, then, whatever the
406
+ server said, clears it through `onTokens` (`cleared`), once, in the same hold of the lock, so a
407
+ refresh can't bring it back. A sign-in saved after that is kept. A refresh token the session holds
408
+ only because saving it failed goes too, after the stored session, even once the store has moved
409
+ on, and the session then lets it go.
410
+ - **It answers once both are done:** `kind` is `revoked`, or `unconfirmed` with the reason, and
411
+ `cleared` says what became of the store:
412
+ - `cleared`: it was cleared;
413
+ - `kept`: there was nothing to clear: nothing stored, or the store moved on meanwhile, to a
414
+ newer sign-in, which is kept, or to another sign-out's clear;
415
+ - `failed`: the store failed, and `failure` says where and how: its `step` is `read`, `lock`
416
+ or `clear`, and its `cause` is what the store threw, such as a `KeychainError`, whose
417
+ `failure.kind` and message say why. A clear or a lock that rejects with something other
418
+ than an `Error` gives an `Error` carrying its text instead. A clear it refuses with anything
419
+ but `StoreMovedOnError` counts as failed, at `clear`;
420
+ - `cut`: the lock or a store call took longer than its 60 s;
421
+ - `pending`: your `signal` answered first, and the clear goes on, unless the signal had already
422
+ fired when you called, when nothing runs at all.
423
+
424
+ After anything but `cleared` and `kept`, the tokens may still be stored: tell the person, so
425
+ they can sign out again.
426
+ - **It can take minutes on a stalled store, and longer behind one.** It sends nothing after its
427
+ 10 s, but it waits for the clear. First it waits for any turn ahead of it, for as long as that
428
+ takes: a refresh that is still saving, or a lock that ignores its signal. Then it waits at most
429
+ 60 s for the lock and for each of its three store calls, so up to about four minutes. It used to
430
+ answer within 10 s while the clear went on behind it. A lock held longer than its 60 s by
431
+ another process, or a store call that doesn't answer within its 60 s, leaves the store as it
432
+ was, unless that call finishes later on its own.
433
+ - **Pass a `signal` to stop waiting:** it answers at once, with `cleared: 'pending'`, and the
434
+ clear goes on. Await `session.settled()` before the process exits. A signal that has already
435
+ fired when you call runs nothing at all, and answers `pending` too.
357
436
 
358
437
  **Writing your own store:** give `tokens` and `onTokens` instead, and keep the same two rules.
359
438
  `tokens()` returns only what `onTokens` has durably saved: write first, show second. `onTokens`
360
- writes only while the store's key is still `update.replaces`, and throws when it refuses. The key is
361
- the stored refresh token, or the access token when it has none or an empty one
362
- (`refreshToken || accessToken`). Here in memory:
439
+ writes only while the store's key is still `update.replaces`, and when it refuses, throws a
440
+ `StoreMovedOnError`, as the ready-made stores do. A sign-out whose clear is refused that way says
441
+ `kept`: the store holds a newer sign-in, or nothing. Any other throw is read as the store failing,
442
+ and the sign-out says `failed`. The key is the stored refresh token, or the access token when it has
443
+ none or an empty one (`refreshToken || accessToken`). Here in memory:
363
444
 
364
445
  ```ts
365
446
  import { discover } from '@flipstream/sdk'
366
- import { createSession, type SessionTokens, type TokenUpdate } from '@flipstream/sdk/node'
447
+ import { createSession, StoreMovedOnError, type SessionTokens, type TokenUpdate } from '@flipstream/sdk/node'
367
448
 
368
449
  const server = await discover('https://auth.flipstream.io')
369
450
  if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
@@ -376,7 +457,7 @@ const session = createSession({
376
457
  tokens: () => stored,
377
458
  onTokens: (update: TokenUpdate) => {
378
459
  // Compare and set: only while the store's key is still the one this update replaces.
379
- if (stored === null || (stored.refreshToken || stored.accessToken) !== update.replaces) throw new Error('the store moved on')
460
+ if (stored === null || (stored.refreshToken || stored.accessToken) !== update.replaces) throw new StoreMovedOnError()
380
461
  if (update.kind === 'cleared') {
381
462
  stored = null
382
463
  return
@@ -438,16 +519,17 @@ await session.revoke()
438
519
  nothing.
439
520
  - **A process that dies holding it** holds the others off for about 10 s: a holder touches the file
440
521
  every second, and a waiter takes a file over once nobody has touched it for 10 s and it has
441
- watched it for 3 s. A sign-out, which has 10 s in all, takes over a file left 10 s or more before
442
- within about 3 s.
522
+ watched it for 3 s. A sign-out, which sends nothing after its 10 s, takes over a file left 10 s or
523
+ more before within about 3 s.
443
524
  - **On Ctrl-C,** Node ends the process without letting a held lock go, and the next process waits
444
525
  up to 10 s for it. An app that wants it gone sooner can handle SIGINT itself, and exit only once
445
526
  every hold of its lock has settled, as below: a hold still waiting for the file gives up at once,
446
- and one running its work finishes it. Waiting for the session's calls isn't enough:
447
- `token()` and `revoke()` can answer before their hold ends. Await `session.settled()` too, so the
448
- session's own work has finished before the exit. The keychain store's own helper gets
449
- the Ctrl-C too; a step it was running is tried once more on a fresh helper, within its 30 s, and
450
- the lock file goes when its work settles.
527
+ and one running its work finishes it. Waiting for the session's calls isn't enough: `token()` can
528
+ answer before its hold ends, and so can `revoke()` at its `signal`. Await `session.settled()`
529
+ too, so the session's own work has finished before the exit. The keychain store's own helper
530
+ ignores the Ctrl-C and finishes the step it's on, within that step's 30 s and at most 1 s after
531
+ the app has gone; the lock file goes when that work settles, as long as the app waits for it, as
532
+ below.
451
533
 
452
534
  ```ts
453
535
  import { homedir } from 'node:os'
@@ -527,7 +609,11 @@ await session.revoke()
527
609
  your saves on `store.lock`, and `{ lock, ...store }` swaps yours out without a word. Either way a
528
610
  sign-in can land between a refresh's compare and its write.
529
611
  - **Never call the session inside `store.lock`:** the lock isn't reentrant, so the call waits for
530
- the hold it's in, and fails at its own limit (`token()` at 15 s, `revoke()` at 10 s).
612
+ the hold it's in, and fails at its own limit (`token()` at its `waitMs`, `revoke()` once its turn
613
+ gives up on the lock, 60 s on, with `cut`).
614
+ - **Nor from your own `tokens` or `onTokens`,** if you wrap the store's: they run inside the
615
+ session's own turn. A `revoke()` there waits for that turn for ever, answering only at its
616
+ `signal`, and a `token()` answers only at its `waitMs`.
531
617
 
532
618
  ## In a browser
533
619
 
@@ -538,6 +624,9 @@ The main entry, `@flipstream/sdk`, runs in browsers with no Node polyfills. Only
538
624
  in a browser.
539
625
  - **The API must allow your page's origin (CORS).** The query API doesn't allow other origins yet,
540
626
  so until it does, call it from a server.
627
+ - **A browser sends no identification yet.** `app`, `agent` and `conversationId` are still
628
+ required and checked, but none of "Which app sent a request"'s headers go from a page until the
629
+ hosts' CORS allows them (query-planner#48); a page can't set `User-Agent` anyway.
541
630
  - **Signing in from a page** uses the same two halves as the paste-back above:
542
631
  - `startSignIn` gives the URL to send the person to, and a `pending` to keep, for instance in
543
632
  `sessionStorage`;
@@ -604,19 +693,20 @@ only on a programming error. For instance, a request that can't be sent as JSON
604
693
  cycle) rejects with the `TypeError`, and nothing is sent. `orThrow(result)` gives the data, or
605
694
  throws the failure as an `ApiFailure` carrying its `error`, for callers who'd rather catch.
606
695
 
607
- - **`fs.catalog.list()`** gives a `Catalog`.
608
- - **`fs.catalog.get({ source })`** gives a `CatalogSource`: a source plus `catalogVersion`.
609
- - **`fs.query(request)`** gives a `QueryResponse`, with `rows` and `lastRow`, and sometimes
610
- `totals` and `timings`. Only the request's declared fields are sent: `source`, `connection_id`,
611
- `dimensions`, `metrics`, `filters`, `sort`, `offset` and `rows`. A request with any other key,
612
- `table` included, is `refused` with nothing sent, and `error.fields` names each one, so a
613
- misspelt field never quietly changes the numbers.
696
+ - **`flipstream.catalog.list()`** gives a `Catalog`.
697
+ - **`flipstream.catalog.get({ source })`** gives a `CatalogSource`: a source plus `catalogVersion`.
698
+ - **`flipstream.query(request)`** gives a `QueryResponse`, with `rows` and `lastRow`, and sometimes
699
+ `totals` and `timings`. Only the request's declared fields are sent: `source`, `dataset_id`,
700
+ `dimensions`, `metrics`, `filters`, `sort`, `offset` and `rows`. The query API names the dataset
701
+ `connection_id`, so `dataset_id` goes as that, and the API's own errors may say so. A request
702
+ with any other key, `table` and `connection_id` included, is `refused` with nothing sent, and
703
+ `error.fields` names each one, so a misspelt field never quietly changes the numbers.
614
704
  - **`refusedQueryFields(request)`** runs that check on its own, with no client and nothing
615
- sent. It gives the same names, sorted, or `[]` for a request `fs.query` would send. So an
616
- app can refuse a request before anything else it does: a CLI given a raw JSON body, for
705
+ sent. It gives the same names, sorted, or `[]` for a request `flipstream.query` would send.
706
+ So an app can refuse a request before anything else it does: a CLI given a raw JSON body, for
617
707
  instance, before its other calls. It reads only the keys; a missing `source` is still the
618
708
  API's to refuse.
619
- - **`fs.health()`** gives the planner's answer to `GET /health`, an object of strings
709
+ - **`flipstream.health()`** gives the planner's answer to `GET /health`, an object of strings
620
710
  (`{ status: 'ok' }` today). It works signed out: no token is asked for or sent, so it tells "the
621
711
  service is down" from "the sign-in is wrong".
622
712
 
@@ -635,7 +725,7 @@ back as data. A field the SDK doesn't know yet is kept.
635
725
  | `invalid` | Outside the contract: an answer that isn't JSON or doesn't match its type, or a status no API sends |
636
726
  | `timeout` | The call's own deadline passed |
637
727
  | `aborted` | The caller's `signal` fired |
638
- | `refused` | Nothing was sent, by rule: a destination that isn't one of the configured hosts over https, a `source` of `''`, `.` or `..`, or a query with keys it doesn't send, named in `fields` |
728
+ | `refused` | Nothing was sent, by rule, and `reason` says which (below) |
639
729
  | `no_token` | The token function failed, or gave no token. `cause` is what it threw |
640
730
  | `cancelled` | The app's own transport cancelled the call, because the session it was made for moved on |
641
731
 
@@ -647,6 +737,22 @@ back as data. A field the SDK doesn't know yet is kept.
647
737
  came.
648
738
  - When the API asked the caller to wait, the failure keeps that as `retryAfterMs`.
649
739
 
740
+ **A `refused` call says why, in `reason`** (`RefusedReason`), and `orThrow`'s message names it,
741
+ never the value:
742
+
743
+ | `reason` | When |
744
+ |---|---|
745
+ | `destination` | Not an allowed host: a configured one, or for sign-in the issuer's own, over https, or over http on this machine with `allowLocalhostHttp`, for the client as for sign-in |
746
+ | `identification` | A value identifying the app, its agent or the conversation holds the access token (see "Which app sent a request") |
747
+ | `path` | A `source` of `''`, `.` or `..`, which can't stay one path segment |
748
+ | `conversation-id` | A call's own `conversationId` that breaks its rule |
749
+ | `fields` | A query with keys it doesn't send, each named in `fields` |
750
+ | `pending` | Sign-in: a `pending` that isn't one, wasn't started by this app at this server, or whose token endpoint breaks its issuer's rule |
751
+ | `callback` | Sign-in: a callback URL that can't be read |
752
+
753
+ Every refusal the SDK returns has a `reason`. The type leaves it optional, so an error your own
754
+ code builds, such as a test double, may leave it out.
755
+
650
756
  ```ts
651
757
  import { isPlannerCode, type ApiError } from '@flipstream/sdk'
652
758
 
@@ -669,7 +775,7 @@ function explain(error: ApiError): string {
669
775
  case 'cancelled':
670
776
  return 'Stopped.'
671
777
  case 'refused':
672
- return error.fields === undefined ? 'Not sent.' : `Not sent: unknown field ${error.fields.join(', ')}`
778
+ return error.fields === undefined ? `Not sent: ${error.reason ?? 'refused'}.` : `Not sent: unknown field ${error.fields.join(', ')}`
673
779
  case 'no_token':
674
780
  return 'No token to send.'
675
781
  default: {
@@ -690,8 +796,9 @@ function explain(error: ApiError): string {
690
796
  redirect (`parsePastedRedirect`, or `signInWithLoopback`'s `readPasted`).
691
797
 
692
798
  There, `refused` also covers an issuer that isn't https (unless it's http on this machine, with
693
- `allowLocalhostHttp`), and a `pending` that isn't one (from storage the app couldn't read back).
694
- Nothing is sent for either.
799
+ `allowLocalhostHttp`), with `reason: 'destination'`; a `pending` that isn't one (from storage the
800
+ app couldn't read back), with `reason: 'pending'`; and a callback URL that can't be read, with
801
+ `reason: 'callback'`. Nothing is sent for any of them.
695
802
 
696
803
  ## Options
697
804
 
@@ -700,7 +807,10 @@ import { createFlipstream } from '@flipstream/sdk'
700
807
 
701
808
  declare const session: { accessToken(rejected?: string): Promise<string> }
702
809
 
703
- const fs = createFlipstream({
810
+ const flipstream = createFlipstream({
811
+ app: { name: 'my-cli', version: '1.0.0' }, // required: see "Which app sent a request"
812
+ agent: { name: 'claude-code', version: '2.1.0' }, // optional: the agent running the app
813
+ conversationId: 'c-123', // optional: the conversation or run the calls belong to
704
814
  // Asked before every attempt; after a 401, asked once more with the token the API refused.
705
815
  token: ({ rejected }) => session.accessToken(rejected),
706
816
  fetch: globalThis.fetch, // optional: every request goes through it
@@ -709,7 +819,9 @@ const fs = createFlipstream({
709
819
  })
710
820
 
711
821
  const controller = new AbortController()
712
- await fs.catalog.list({ signal: controller.signal, deadlineMs: 10_000 })
822
+ await flipstream.catalog.list({ signal: controller.signal, deadlineMs: 10_000 })
823
+ // A call may name its own conversation, and carry on the caller's W3C trace context.
824
+ await flipstream.catalog.list({ conversationId: 'c-456', traceparent: '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01' })
713
825
  ```
714
826
 
715
827
  - **The token function** is asked before every attempt, so a renewed token is always the one sent.
@@ -737,6 +849,40 @@ await fs.catalog.list({ signal: controller.signal, deadlineMs: 10_000 })
737
849
  it never goes through your transport: it goes to the query host, over https, with the global
738
850
  `fetch`.
739
851
 
852
+ ## Which app sent a request
853
+
854
+ Every signed-in request says which app sent it, and, when you name them, which agent and
855
+ conversation, so a later query log can show who asked what. It reports nothing beyond the request:
856
+ the SDK has no telemetry. In Node, each signed-in request to an API host carries:
857
+
858
+ | Header | Value | Standard |
859
+ |---|---|---|
860
+ | `User-Agent` | `<app>/<version> flipstream-sdk/<version> node/<version>` | RFC 9110 product tokens |
861
+ | `traceparent` | one trace-id per call, kept across its retries, with a new parent-id for each request | W3C Trace Context |
862
+ | `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) |
863
+
864
+ - **`app` is required;** `agent` and `conversationId` are optional, and a call's own
865
+ `conversationId` replaces the client's for that call.
866
+ - **Strict values:** names and versions are 1 to 64 of RFC 9110's token characters (letters,
867
+ digits and ``!#$%&'*+-.^_`|~``); `conversationId` is 1 to 128 of A-Z, a-z, 0-9, `.`, `_`, `:`
868
+ and `-`. Anything else is a TypeError at creation, which names the option but not its value. A
869
+ call's `conversationId` that breaks the rule is `refused`, with nothing sent.
870
+ - **Never the token:** a call whose `app`, `agent` or `conversationId` holds the access token is
871
+ `refused`, with nothing sent. A token of 16 characters or more is looked for anywhere in a value.
872
+ A shorter one, which only tests and local servers use, counts only when a value equals it, so it
873
+ can't refuse an ordinary value that happens to contain it. With your own transport, the SDK never
874
+ sees the token, so that check is your transport's.
875
+ - **`health` says only who the SDK is.** It's signed out and asks for no token, so it sends
876
+ `User-Agent: flipstream-sdk/<version> node/<version>` and a `traceparent`, and none of `app`,
877
+ `agent` or `conversationId`: nothing could check them there.
878
+ - **Your trace:** pass `traceparent` on a call to carry on your own trace. The call keeps its
879
+ trace-id and flags, with its own parent-id for each request. One that isn't a valid version-00
880
+ traceparent is dropped, as W3C Trace Context says, and the call starts its own trace, sampled
881
+ (`01`).
882
+ - **Only to the API hosts.** The auth server never gets them: `discover`, sign-in, refresh and
883
+ revoke send none.
884
+ - **Not from a browser yet:** see "In a browser".
885
+
740
886
  ## Which version is running
741
887
 
742
888
  ```ts
@@ -21,7 +21,7 @@ const zMetadata = z.looseObject({
21
21
  */
22
22
  export async function discover(issuer, options = {}) {
23
23
  if (typeof issuer !== 'string' || !isSignInUrl(issuer, options.allowLocalhostHttp))
24
- return { ok: false, error: { kind: 'refused' } };
24
+ return { ok: false, error: { kind: 'refused', reason: 'destination' } };
25
25
  const read = await call(authTransport(options), {
26
26
  effect: 'read',
27
27
  service: 'auth',
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAwB,MAAM,gBAAgB,CAAA;AAgBlG,kGAAkG;AAClG,mDAAmD;AACnD,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;IAC9B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,sBAAsB,EAAE,CAAC,CAAC,MAAM,EAAE;IAClC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,aAAa,EAAE;IAC/C,gCAAgC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,aAAa,EAAE;IACrE,8CAA8C,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,aAAa,EAAE;CAC5E,CAAC,CAAA;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,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Ac;IACjE,4FAA4F;IAC5F,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,mCAAmC,CAAA;IACrE,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,GAAG,CAAC,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAA;IAC/I,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAClD,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,OAAO,CAAA;IACpC,IAAI,GAAG,CAAC,gCAAgC,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,IAAI;QAAE,OAAO,oCAAoC,CAAA;IAChH,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -96,8 +96,13 @@ export function finishSignIn(callbackUrl, pending, options = {}) {
96
96
  * entry never exports this, so browser code has no way to send client credentials.
97
97
  */
98
98
  export async function exchangeCode(callbackUrl, pending, options, authorization) {
99
- if (!isPendingSignIn(pending) || !isSignInUrl(pending.tokenEndpoint, options.allowLocalhostHttp) || !URL.canParse(callbackUrl))
100
- return { ok: false, error: { kind: 'refused' } };
99
+ // Refused with nothing sent, each for its own reason (#199): what it refuses is as before.
100
+ if (!isPendingSignIn(pending))
101
+ return { ok: false, error: { kind: 'refused', reason: 'pending' } };
102
+ if (!isSignInUrl(pending.tokenEndpoint, options.allowLocalhostHttp))
103
+ return { ok: false, error: { kind: 'refused', reason: 'destination' } };
104
+ if (!URL.canParse(callbackUrl))
105
+ return { ok: false, error: { kind: 'refused', reason: 'callback' } };
101
106
  const callback = readCallback(callbackUrl, pending);
102
107
  if (callback.kind !== 'code')
103
108
  return { ok: false, error: callback };
@@ -1 +1 @@
1
- {"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"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AAwF;YACxF,wBAAwB;YACxB,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK;SAC9B;KACF,CAAA;AACH,CAAC"}
@@ -15,6 +15,11 @@ export interface FetchTransportOptions {
15
15
  readonly hosts: Readonly<Partial<Record<ServiceName, string>>>;
16
16
  /** Plain http to a loopback host (localhost, 127.0.0.1, [::1]): development and tests only. */
17
17
  readonly allowLocalhostHttp?: boolean | undefined;
18
+ /**
19
+ * Whether `request`, as built, carries `token` where only its authorization header may: then it
20
+ * is refused, unsent (#192). createFlipstream's check of the values that identify the caller.
21
+ */
22
+ readonly holdsToken?: ((request: Request, token: string) => boolean) | undefined;
18
23
  }
19
24
  /**
20
25
  * Plain http to this machine (localhost, 127.0.0.1, [::1]), which `allowLocalhostHttp` lets
@@ -9,6 +9,7 @@ export function isLoopbackHttp(url) {
9
9
  }
10
10
  const ABORTED = { kind: 'aborted' };
11
11
  const REFUSED = { kind: 'refused', reason: 'destination' };
12
+ const HOLDS_TOKEN = { kind: 'refused', reason: 'identification' };
12
13
  export function fetchTransport(options) {
13
14
  const send = options.fetch ?? globalThis.fetch;
14
15
  const allowed = destinations(options);
@@ -26,6 +27,8 @@ export function fetchTransport(options) {
26
27
  return token;
27
28
  if (call.signal.aborted)
28
29
  return ABORTED;
30
+ if (options.holdsToken?.(built, token.token) === true)
31
+ return HOLDS_TOKEN;
29
32
  const headers = new Headers(built.headers);
30
33
  try {
31
34
  headers.set('authorization', `Bearer ${token.token}`);