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