@flipstream/sdk 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +179 -424
  3. package/dist/api/backend.d.ts +21 -3
  4. package/dist/api/backend.js +50 -10
  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.d.ts +82 -14
  9. package/dist/api/datasets.js +193 -57
  10. package/dist/api/datasets.js.map +1 -1
  11. package/dist/api/index.d.ts +1 -1
  12. package/dist/api/log.d.ts +25 -20
  13. package/dist/api/log.js +63 -48
  14. package/dist/api/log.js.map +1 -1
  15. package/dist/api/me.js +9 -5
  16. package/dist/api/me.js.map +1 -1
  17. package/dist/api/members.d.ts +34 -1
  18. package/dist/api/members.js +67 -27
  19. package/dist/api/members.js.map +1 -1
  20. package/dist/api/wallet.d.ts +8 -5
  21. package/dist/api/wallet.js +40 -25
  22. package/dist/api/wallet.js.map +1 -1
  23. package/dist/api/workspaces.d.ts +35 -14
  24. package/dist/api/workspaces.js +53 -23
  25. package/dist/api/workspaces.js.map +1 -1
  26. package/dist/auth/discovery.d.ts +19 -6
  27. package/dist/auth/discovery.js +30 -6
  28. package/dist/auth/discovery.js.map +1 -1
  29. package/dist/auth/signIn.d.ts +18 -14
  30. package/dist/auth/signIn.js +29 -22
  31. package/dist/auth/signIn.js.map +1 -1
  32. package/dist/core/call.d.ts +13 -1
  33. package/dist/core/call.js +34 -9
  34. package/dist/core/call.js.map +1 -1
  35. package/dist/core/deadline.d.ts +30 -0
  36. package/dist/core/deadline.js +51 -0
  37. package/dist/core/deadline.js.map +1 -0
  38. package/dist/core/identify.d.ts +59 -14
  39. package/dist/core/identify.js +54 -20
  40. package/dist/core/identify.js.map +1 -1
  41. package/dist/core/invalid.d.ts +10 -0
  42. package/dist/core/invalid.js +28 -0
  43. package/dist/core/invalid.js.map +1 -0
  44. package/dist/core/names.d.ts +13 -2
  45. package/dist/core/names.js +11 -2
  46. package/dist/core/names.js.map +1 -1
  47. package/dist/core/notFound.d.ts +8 -0
  48. package/dist/core/notFound.js +8 -0
  49. package/dist/core/notFound.js.map +1 -0
  50. package/dist/core/read.d.ts +9 -0
  51. package/dist/core/read.js +14 -5
  52. package/dist/core/read.js.map +1 -1
  53. package/dist/core/result.d.ts +22 -13
  54. package/dist/core/result.js +5 -5
  55. package/dist/core/result.js.map +1 -1
  56. package/dist/core/retry.d.ts +5 -2
  57. package/dist/core/retry.js +6 -3
  58. package/dist/core/retry.js.map +1 -1
  59. package/dist/core/scope.d.ts +20 -0
  60. package/dist/core/scope.js +54 -0
  61. package/dist/core/scope.js.map +1 -0
  62. package/dist/core/shared.d.ts +39 -0
  63. package/dist/core/shared.js +177 -0
  64. package/dist/core/shared.js.map +1 -0
  65. package/dist/core/signal.d.ts +12 -0
  66. package/dist/core/signal.js +25 -0
  67. package/dist/core/signal.js.map +1 -0
  68. package/dist/flipstream.d.ts +223 -72
  69. package/dist/flipstream.js +225 -88
  70. package/dist/flipstream.js.map +1 -1
  71. package/dist/index.d.ts +1 -1
  72. package/dist/node/clientSecret.js +7 -6
  73. package/dist/node/clientSecret.js.map +1 -1
  74. package/dist/node/headless.d.ts +14 -6
  75. package/dist/node/headless.js +8 -6
  76. package/dist/node/headless.js.map +1 -1
  77. package/dist/node/index.d.ts +1 -1
  78. package/dist/node/index.js +1 -1
  79. package/dist/node/index.js.map +1 -1
  80. package/dist/node/keychainChild.js +26 -14
  81. package/dist/node/keychainChild.js.map +1 -1
  82. package/dist/node/keychainError.d.ts +3 -3
  83. package/dist/node/keychainStore.d.ts +10 -7
  84. package/dist/node/keychainStore.js +44 -23
  85. package/dist/node/keychainStore.js.map +1 -1
  86. package/dist/node/loopback.d.ts +13 -3
  87. package/dist/node/loopback.js +47 -5
  88. package/dist/node/loopback.js.map +1 -1
  89. package/dist/node/session.d.ts +17 -9
  90. package/dist/node/session.js +68 -50
  91. package/dist/node/session.js.map +1 -1
  92. package/dist/node/store.d.ts +35 -2
  93. package/dist/node/store.js +56 -12
  94. package/dist/node/store.js.map +1 -1
  95. package/dist/version.gen.js +1 -1
  96. package/docs/admin.md +558 -0
  97. package/docs/node-sign-in.md +63 -39
  98. package/package.json +1 -1
@@ -42,7 +42,16 @@ if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
42
42
  sign-in's own address, then its state. A paste that fails ends the sign-in with its reason, such
43
43
  as `wrong_state`, and nothing is exchanged.
44
44
  - **A reader that rejects** ends the sign-in as `paste_failed`. `readPasted` is called once, just
45
- after `open`.
45
+ after `open`. One given that isn't a function is a `TypeError` naming it, before any port opens,
46
+ as is an `open` that isn't one or a `signal` with no `aborted` or no `addEventListener` method,
47
+ whatever `timeoutMs`.
48
+ - **`timeoutMs` is the time from opening the browser until a redirect arrives,** on the port or
49
+ pasted: 5 minutes when left out or `null`. Opening the port and the code's exchange (with its own
50
+ deadline) aren't in it. It's taken in whole ms, rounded down, up to 2147483647, as a call's
51
+ `deadlineMs` is. One that can't be a wait (not a number, `NaN`, ±`Infinity`, or more than that
52
+ once rounded down) is a `TypeError` before any port opens. One under 1 ms ends as `timeout`, with
53
+ no port opened and nothing shown, once `server`, `clientId` and `scopes` pass the checks a
54
+ sign-in makes: a mistake in them is still a `TypeError`.
46
55
 
47
56
  ## Over SSH, in CI, or with no display
48
57
 
@@ -74,7 +83,7 @@ if (isHeadless(process.env)) {
74
83
  prompt.close()
75
84
  if (!pasted.ok) throw new Error(`that isn't this sign-in's redirect: ${pasted.error.kind}`)
76
85
 
77
- const signedIn = await finishSignIn(pasted.callbackUrl, pending)
86
+ const signedIn = await finishSignIn(pasted.callback_url, pending)
78
87
  if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
79
88
  }
80
89
  ```
@@ -209,31 +218,33 @@ if (signedOut.cleared === 'failed') {
209
218
  - Its steps run in one helper process, one at a time. The first step starts it, and it stays
210
219
  warm while your app runs (about 57 MB), so a step after that takes a keychain call, not a
211
220
  process start. A step that takes longer than 30 s (`timeoutMs`) ends it, so a keychain prompt
212
- that nobody answers can't hold up your app, and the next step starts another. A Ctrl-C in
213
- the terminal reaches the helper too, and so does the terminal closing (SIGHUP) on macOS and
214
- Linux, and it ignores both, from before its own code loads; on Windows the helper follows your
215
- app through the end of its input instead, within the same bound. Not during Node's own
216
- start-up, though, or any preload in `NODE_OPTIONS`: a Ctrl-C or a closed terminal then still
217
- ends a helper that is just starting. A quit
218
- (`Ctrl-\`, SIGQUIT) is deliberate, so it still ends the helper at once. When your app ends,
219
- the helper ends too: at once if it's idle or reading, or once it has finished the save or
220
- delete it's on, so a refresh's save isn't lost to a Ctrl-C or a closed terminal. It gives
221
- that step 1 s more at most, less than the soonest `fileLock` lets another process take the
222
- lock your app held: at the soonest about
223
- 2 s after your app ends, for an app whose heartbeat was running (3 s after its last touch),
224
- when the clock has stepped or your app's clock runs behind. So a late save can't land over
225
- that process's. For a helper's first step, that 1 s counts from the helper's own start, so a
226
- helper slow to start (on a loaded machine, say) can't stretch it. A first step still going
227
- when your app ends may therefore be cut sooner. A save waiting on a keychain prompt is ended
228
- then. On macOS, the keychain's own dialog stays open after a Ctrl-C or a closed terminal
229
- until someone answers it, even once your app and its helper have ended. A step whose helper died
230
- before it answered runs once more on a fresh one, within the same 30 s. The helper never
231
- keeps your app running. It's `process.execPath`, so it needs a Node that runs a script: not an Electron
232
- app (without `ELECTRON_RUN_AS_NODE`), a Node single-executable application, or a compiled
233
- Bun binary. A bundle must keep
234
- `keychainChild.js` beside the module, with `zod` and `@napi-rs/keyring` resolvable from
235
- there, and `import.meta.url` set. Where it doesn't (an esbuild CommonJS bundle, say), only the
236
- keychain's steps fail, as `store_failed`.
221
+ that nobody answers can't hold up your app, and the next step starts another. A Ctrl-C in the
222
+ terminal reaches the helper too, and so do the terminal closing (SIGHUP) and a SIGTERM sent to
223
+ your app's process group (by a supervisor, say, or a pane that closes) on macOS and Linux. It
224
+ ignores all three, from before its own code loads, and a SIGTERM sent to the helper alone too,
225
+ since Node can't tell the two apart. On Windows the helper follows your app through the end of
226
+ its input instead, within the same bound. Not during Node's own start-up, though, or any
227
+ preload in `NODE_OPTIONS`: one of them then still ends a helper that is just starting. A quit
228
+ (`Ctrl-\`) is deliberate: SIGQUIT, SIGKILL and every other signal whose default is to end a
229
+ process still end it. To end a stuck helper yourself, send it SIGKILL; it also ends on its
230
+ own, within its bound, once your app has gone. When your app ends, the helper ends too: at
231
+ once if it's idle or reading, or once it has finished the save or delete it's on, so a
232
+ refresh's save isn't lost to a Ctrl-C, a closed terminal or a SIGTERM. It gives that step 1 s
233
+ more at most, less than the soonest `fileLock` lets another process take the lock your app
234
+ held: at the soonest about 2 s after your app ends, for an app whose heartbeat was running (3
235
+ s after its last touch), when the clock has stepped or your app's clock runs behind. So a late
236
+ save can't land over that process's. For a helper's first step, that 1 s counts from the
237
+ helper's own start, so a helper slow to start (on a loaded machine, say) can't stretch it. A
238
+ first step still going when your app ends may therefore be cut sooner. A save waiting on a
239
+ keychain prompt is ended then. On macOS, the keychain's own dialog stays open after a Ctrl-C,
240
+ a closed terminal or a SIGTERM until someone answers it, even once your app and its helper
241
+ have ended. A step whose helper died before it answered runs once more on a fresh one, within
242
+ the same 30 s. The helper never keeps your app running. It's `process.execPath`, so it needs a
243
+ Node that runs a script: not an Electron app (without `ELECTRON_RUN_AS_NODE`), a Node
244
+ 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`.
237
248
  - Through `session.token()`, a keychain read that takes longer than the caller's wait, 15 s
238
249
  unless you pass `createSession({ waitMs })`, is `unavailable`. On macOS a read can wait on
239
250
  an access dialog, every time, for an item another program saved: give `waitMs` as long as
@@ -256,11 +267,11 @@ if (signedOut.cleared === 'failed') {
256
267
  - "Always Allow" trusts that Node build with the item, until the next upgrade;
257
268
  - nothing is refused: a sign-out still clears the tokens, after its dialogs.
258
269
  - **Each dialog must be answered within the call's limits:** `session.token()`'s wait, 15 s
259
- unless you pass `waitMs` (see "Through `session.token()`" above; #233's first read took
260
- 18.6 s); each keychain step's `timeoutMs`, 30 s by default; and a sign-out's 10 s for its
261
- revocation, which its first read's dialog counts against. So after an upgrade, a sign-out
262
- whose first dialog is slow still clears the tokens, but ends `unconfirmed`, without
263
- revoking them at the server.
270
+ unless you pass `waitMs` (the bullet above that begins with "Through `session.token()`";
271
+ #233's first read took 18.6 s); each keychain step's `timeoutMs`, 30 s by default; and a
272
+ sign-out's 10 s for its revocation, which its first read's dialog counts against. So after an
273
+ upgrade, a sign-out whose first dialog is slow still clears the tokens, but ends
274
+ `unconfirmed`, without revoking them at the server.
264
275
 
265
276
  nodejs.org's builds are signed with the Node.js Foundation's Developer ID, so they keep their
266
277
  identity across versions, and an upgrade shouldn't ask. Checked on macOS 26 with a copy of
@@ -330,16 +341,29 @@ writes only while the store's key is still `update.replaces`, and when it refuse
330
341
  `StoreMovedOnError`, as the ready-made stores do. A sign-out whose clear is refused that way says
331
342
  `kept`: the store holds a newer sign-in, or nothing. Any other throw is read as the store failing,
332
343
  and the sign-out says `failed`. The key is the stored refresh token, or the access token when it has
333
- none or an empty one (`refreshToken || accessToken`). Here in memory:
344
+ none or an empty one (`refresh_token || access_token`).
345
+
346
+ **The tokens are snake_case since the snake rename (D569).** `keychainStore` and `fileStore` still
347
+ read the camelCase tokens that earlier releases saved, and save the new shape at their next save. A
348
+ store of your own converts its records with `fromEarlierTokenNames`, in the same change that
349
+ renames its `onTokens` fields. It follows the SDK's own rule: complete snake_case fields win, and
350
+ camelCase alone is converted. Convert the record itself, as the example does, not only what
351
+ `tokens()` returns: your compare and set reads the record. A refresh refuses a record still in
352
+ camelCase (`store_failed`, at the read, before anything is sent). A sign-out clears through your
353
+ own `onTokens`, so convert the stored record first: until you do, `revoke()` still revokes the
354
+ right refresh token, but its clear comes back `cleared: 'kept'` and the old record stays. The new
355
+ shape is one-way, so every process that shares a store upgrades together. Here in memory:
334
356
 
335
357
  ```ts
336
358
  import { discover } from '@flipstream/sdk'
337
- import { createSession, StoreMovedOnError, type SessionTokens, type TokenUpdate } from '@flipstream/sdk/node'
359
+ import { createSession, fromEarlierTokenNames, StoreMovedOnError, type SessionTokens, type TokenUpdate } from '@flipstream/sdk/node'
338
360
 
339
361
  const server = await discover('https://auth.flipstream.io')
340
362
  if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
341
363
 
342
- let stored: SessionTokens | null = null
364
+ // What your storage holds: an earlier release's record has camelCase names, so convert it as you read it.
365
+ declare const saved: object | null
366
+ let stored: SessionTokens | null = saved === null ? null : fromEarlierTokenNames(saved)
343
367
 
344
368
  const session = createSession({
345
369
  server: server.data,
@@ -347,14 +371,14 @@ const session = createSession({
347
371
  tokens: () => stored,
348
372
  onTokens: (update: TokenUpdate) => {
349
373
  // Compare and set: only while the store's key is still the one this update replaces.
350
- if (stored === null || (stored.refreshToken || stored.accessToken) !== update.replaces) throw new StoreMovedOnError()
374
+ if (stored === null || (stored.refresh_token || stored.access_token) !== update.replaces) throw new StoreMovedOnError()
351
375
  if (update.kind === 'cleared') {
352
376
  stored = null
353
377
  return
354
378
  }
355
- const { accessToken, expiresAt } = update
356
- const refreshToken = update.kind === 'rotated' ? update.refreshToken : stored.refreshToken
357
- stored = { accessToken, ...(refreshToken === undefined ? {} : { refreshToken }), ...(expiresAt === undefined ? {} : { expiresAt }) }
379
+ const { access_token, expires_at } = update
380
+ const refresh_token = update.kind === 'rotated' ? update.refresh_token : stored.refresh_token
381
+ stored = { access_token, ...(refresh_token === undefined ? {} : { refresh_token }), ...(expires_at === undefined ? {} : { expires_at }) }
358
382
  },
359
383
  })
360
384
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipstream/sdk",
3
- "version": "0.11.0",
3
+ "version": "0.13.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",