@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.
- package/CHANGELOG.md +48 -0
- package/README.md +97 -412
- package/dist/api/backend.d.ts +10 -0
- package/dist/api/backend.js +24 -4
- package/dist/api/backend.js.map +1 -1
- package/dist/api/credentials.js +4 -4
- package/dist/api/credentials.js.map +1 -1
- package/dist/api/datasets.d.ts +82 -14
- package/dist/api/datasets.js +193 -57
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/log.d.ts +25 -20
- package/dist/api/log.js +63 -48
- package/dist/api/log.js.map +1 -1
- package/dist/api/me.js +7 -4
- package/dist/api/me.js.map +1 -1
- package/dist/api/members.d.ts +34 -1
- package/dist/api/members.js +67 -27
- package/dist/api/members.js.map +1 -1
- package/dist/api/wallet.d.ts +8 -5
- package/dist/api/wallet.js +36 -24
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +28 -7
- package/dist/api/workspaces.js +46 -16
- package/dist/api/workspaces.js.map +1 -1
- package/dist/auth/discovery.d.ts +19 -6
- package/dist/auth/discovery.js +25 -4
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.d.ts +18 -14
- package/dist/auth/signIn.js +29 -22
- package/dist/auth/signIn.js.map +1 -1
- package/dist/core/call.d.ts +4 -1
- package/dist/core/call.js +26 -6
- package/dist/core/call.js.map +1 -1
- package/dist/core/deadline.d.ts +30 -0
- package/dist/core/deadline.js +51 -0
- package/dist/core/deadline.js.map +1 -0
- package/dist/core/invalid.d.ts +7 -0
- package/dist/core/invalid.js +22 -0
- package/dist/core/invalid.js.map +1 -0
- package/dist/core/names.d.ts +13 -2
- package/dist/core/names.js +11 -2
- package/dist/core/names.js.map +1 -1
- package/dist/core/notFound.d.ts +8 -0
- package/dist/core/notFound.js +8 -0
- package/dist/core/notFound.js.map +1 -0
- package/dist/core/result.d.ts +17 -12
- package/dist/core/result.js +5 -5
- package/dist/core/result.js.map +1 -1
- package/dist/core/retry.d.ts +5 -2
- package/dist/core/retry.js +6 -3
- package/dist/core/retry.js.map +1 -1
- package/dist/core/scope.d.ts +20 -0
- package/dist/core/scope.js +54 -0
- package/dist/core/scope.js.map +1 -0
- package/dist/flipstream.d.ts +136 -69
- package/dist/flipstream.js +67 -45
- package/dist/flipstream.js.map +1 -1
- package/dist/node/clientSecret.js +5 -5
- package/dist/node/clientSecret.js.map +1 -1
- package/dist/node/headless.d.ts +14 -6
- package/dist/node/headless.js +8 -6
- package/dist/node/headless.js.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.js +26 -14
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +3 -3
- package/dist/node/keychainStore.d.ts +10 -7
- package/dist/node/keychainStore.js +44 -23
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/loopback.d.ts +8 -1
- package/dist/node/loopback.js +19 -2
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +17 -9
- package/dist/node/session.js +55 -44
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +35 -2
- package/dist/node/store.js +56 -12
- package/dist/node/store.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/admin.md +503 -0
- package/docs/node-sign-in.md +60 -38
- package/package.json +1 -1
package/docs/node-sign-in.md
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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` (
|
|
260
|
-
18.6 s); each keychain step's `timeoutMs`, 30 s by default; and a
|
|
261
|
-
revocation, which its first read's dialog counts against. So after an
|
|
262
|
-
whose first dialog is slow still clears the tokens, but ends
|
|
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 (`
|
|
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
|
-
|
|
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.
|
|
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 {
|
|
356
|
-
const
|
|
357
|
-
stored = {
|
|
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
|
```
|