@flipstream/sdk 0.6.0 → 0.7.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 +44 -0
- package/README.md +212 -34
- package/dist/auth/discovery.d.ts +5 -4
- package/dist/auth/discovery.js +10 -8
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.js +10 -5
- package/dist/auth/signIn.js.map +1 -1
- package/dist/auth/transport.d.ts +20 -2
- package/dist/auth/transport.js +25 -5
- package/dist/auth/transport.js.map +1 -1
- package/dist/core/fetch.d.ts +5 -0
- package/dist/core/fetch.js +8 -1
- package/dist/core/fetch.js.map +1 -1
- package/dist/flipstream.d.ts +8 -0
- package/dist/flipstream.js +4 -3
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/node/fileLock.d.ts +21 -0
- package/dist/node/fileLock.js +23 -54
- package/dist/node/fileLock.js.map +1 -1
- package/dist/node/fileStore.d.ts +23 -1
- package/dist/node/fileStore.js +20 -18
- package/dist/node/fileStore.js.map +1 -1
- package/dist/node/keychainChild.js +84 -48
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainStore.d.ts +7 -3
- package/dist/node/keychainStore.js +169 -51
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/loopback.js +1 -1
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +31 -2
- package/dist/node/session.js +88 -17
- package/dist/node/session.js.map +1 -1
- package/dist/node/store.d.ts +5 -1
- package/dist/node/store.js +12 -4
- package/dist/node/store.js.map +1 -1
- package/dist/query/catalog.d.ts +271 -2
- package/dist/query/catalog.js +93 -5
- package/dist/query/catalog.js.map +1 -1
- package/dist/query/query.d.ts +14 -5
- package/dist/query/query.js +21 -6
- package/dist/query/query.js.map +1 -1
- package/dist/spec/query-planner/index.d.ts +1 -1
- package/dist/spec/query-planner/types.gen.d.ts +35 -4
- package/dist/spec/query-planner/zod.gen.d.ts +257 -64
- package/dist/spec/query-planner/zod.gen.js +31 -5
- package/dist/spec/query-planner/zod.gen.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.7.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.6.0...typescript-v0.7.0) (2026-10-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* **typescript:** Format is a union on type. Read decimals, format or thousandSeparator only after narrowing on type. An unknown type arrives as { type: 'unknown', declared }, and a known type with a part missing makes the answer invalid.
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **typescript:** a field's format is a union on its type ([#156](https://github.com/flipstream-io/sdk/issues/156)) ([4427029](https://github.com/flipstream-io/sdk/commit/4427029741b88d54322596cad3458837b682eea9))
|
|
13
|
+
* **typescript:** an app can check a query's fields before it sends ([#184](https://github.com/flipstream-io/sdk/issues/184)) ([c708b78](https://github.com/flipstream-io/sdk/commit/c708b78cdced950d2dfb69dcf06a129a883899eb))
|
|
14
|
+
* **typescript:** fileStore(path, { lock: true }) also returns its lock ([#186](https://github.com/flipstream-io/sdk/issues/186)) ([f34b6f4](https://github.com/flipstream-io/sdk/commit/f34b6f4e7c431ad697dbdfc7d0f4b129f900e74b))
|
|
15
|
+
* **typescript:** onWarning decides where the SDK's warnings go ([#173](https://github.com/flipstream-io/sdk/issues/173)) ([11e1f58](https://github.com/flipstream-io/sdk/commit/11e1f589596af28cd129f88b236729acb440e000))
|
|
16
|
+
* **typescript:** session.settled() waits for the session before an exit ([#185](https://github.com/flipstream-io/sdk/issues/185)) ([9aa6dc5](https://github.com/flipstream-io/sdk/commit/9aa6dc51cde1ebecd51d2dcfb62c0cd0b4d75977))
|
|
17
|
+
* **typescript:** sign-in accepts a local http auth server, opt-in ([#172](https://github.com/flipstream-io/sdk/issues/172)) ([e626d08](https://github.com/flipstream-io/sdk/commit/e626d08651992144aba3464632272511cb39bea3))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **typescript:** a sign-out also revokes a rotation held only in memory ([#167](https://github.com/flipstream-io/sdk/issues/167)) ([826f925](https://github.com/flipstream-io/sdk/commit/826f925b77289c40ff77137ad9ca19a47ee49d56))
|
|
23
|
+
* **typescript:** two spellings of one token file take one turn ([#174](https://github.com/flipstream-io/sdk/issues/174)) ([2c0d893](https://github.com/flipstream-io/sdk/commit/2c0d893cdff87b2b2839a32b10fb0806191774f6))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Performance Improvements
|
|
27
|
+
|
|
28
|
+
* **typescript:** keychainStore keeps one helper process warm ([#159](https://github.com/flipstream-io/sdk/issues/159)) ([f2823e6](https://github.com/flipstream-io/sdk/commit/f2823e6200152f12eb4f1eb436c76a46d1567a51))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Documentation
|
|
32
|
+
|
|
33
|
+
* **typescript:** fileLock on Ctrl-C, and the decisions behind its rules ([#166](https://github.com/flipstream-io/sdk/issues/166)) ([49d936d](https://github.com/flipstream-io/sdk/commit/49d936d0695f3f34d53c3ec56dfebb5258644b76))
|
|
34
|
+
* **typescript:** keychain by default, and fileLock's Windows limits ([#158](https://github.com/flipstream-io/sdk/issues/158)) ([d463a9c](https://github.com/flipstream-io/sdk/commit/d463a9cd0899751234551b0cb0f971b4a1312606))
|
|
35
|
+
* **typescript:** on Ctrl-C, a hold still waiting for the lock gives up ([#180](https://github.com/flipstream-io/sdk/issues/180)) ([cef2e80](https://github.com/flipstream-io/sdk/commit/cef2e805159dea0ebcd7604b8fb896b1e5f27e97))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Tests
|
|
39
|
+
|
|
40
|
+
* **typescript:** check:lock-live cleans up after a failed case ([#177](https://github.com/flipstream-io/sdk/issues/177)) ([648d36a](https://github.com/flipstream-io/sdk/commit/648d36a226e7f911037c18925822539cf32ad246))
|
|
41
|
+
* **typescript:** check:lock-live's third case, across two processes ([#179](https://github.com/flipstream-io/sdk/issues/179)) ([127444e](https://github.com/flipstream-io/sdk/commit/127444e8c54d8431ae696e7a1228a56743a68fcc))
|
|
42
|
+
* **typescript:** fileLock's slow cases run on a quarter of its timings ([#161](https://github.com/flipstream-io/sdk/issues/161)) ([e1126dd](https://github.com/flipstream-io/sdk/commit/e1126dd80b9e7ffd5c1a71e948fbe5e0be1fcb90))
|
|
43
|
+
* **typescript:** install:check holds the keyring to an optional peer ([#178](https://github.com/flipstream-io/sdk/issues/178)) ([ee2fce7](https://github.com/flipstream-io/sdk/commit/ee2fce7a21df523f7433a3d858fd258146652ed1))
|
|
44
|
+
* **typescript:** no lock turn outlives check:lock-live's clean-up ([#182](https://github.com/flipstream-io/sdk/issues/182)) ([bf603dc](https://github.com/flipstream-io/sdk/commit/bf603dcf24ddfaf2f3af0fce5895c3660c5f58d9))
|
|
45
|
+
* **typescript:** session.test.mjs ends in 5 s, not 60 s ([#162](https://github.com/flipstream-io/sdk/issues/162)) ([de96632](https://github.com/flipstream-io/sdk/commit/de96632c287b26ec6b4f58a373ab84640a95e208))
|
|
46
|
+
|
|
3
47
|
## [0.6.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.5.0...typescript-v0.6.0) (2026-10-17)
|
|
4
48
|
|
|
5
49
|
|
package/README.md
CHANGED
|
@@ -46,6 +46,39 @@ console.log(answer.rows, answer.lastRow)
|
|
|
46
46
|
The catalogue names each source with its dimensions and metrics. `fs.catalog.get({ source })` gives
|
|
47
47
|
one source.
|
|
48
48
|
|
|
49
|
+
Each dimension and metric has a `format`, a union on its `type`:
|
|
50
|
+
- `number`, `currency` and `percentage` carry `decimals`, and a `number` may carry
|
|
51
|
+
`thousandSeparator`;
|
|
52
|
+
- `date` carries its pattern, `YYYY-MM-DD`;
|
|
53
|
+
- `string` carries nothing more.
|
|
54
|
+
|
|
55
|
+
A type this version of the SDK doesn't know arrives as `{ type: 'unknown', declared }`, naming the
|
|
56
|
+
type it came as, and the rest of the catalogue reads as usual. The SDK then warns once per process
|
|
57
|
+
for each such type, on the console, or to your `onWarning` (see "Options"). The warning names the
|
|
58
|
+
type, the source and field it was first seen on, and how to update the SDK. A known type with a
|
|
59
|
+
part missing, such as a
|
|
60
|
+
`number` without `decimals`, makes the answer `invalid`, like any other answer that breaks the
|
|
61
|
+
contract.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import type { Format } from '@flipstream/sdk'
|
|
65
|
+
|
|
66
|
+
function shownAs(format: Format): string {
|
|
67
|
+
switch (format.type) {
|
|
68
|
+
case 'number':
|
|
69
|
+
case 'currency':
|
|
70
|
+
case 'percentage':
|
|
71
|
+
return `${format.type}, ${format.decimals} decimals`
|
|
72
|
+
case 'date':
|
|
73
|
+
return `a date, ${format.format}`
|
|
74
|
+
case 'string':
|
|
75
|
+
return 'text'
|
|
76
|
+
case 'unknown':
|
|
77
|
+
return `as it comes (${format.declared})`
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
49
82
|
## Signing in from Node and the CLI
|
|
50
83
|
|
|
51
84
|
For an app that runs on the person's own machine, or in their terminal: a CLI, a script, a local
|
|
@@ -57,6 +90,12 @@ ready for them (see "Keeping the person signed in"). A web app signs in on its s
|
|
|
57
90
|
In a TypeScript project, add `@types/node` (`npm install --save-dev @types/node`): this entry's
|
|
58
91
|
types use Node's own.
|
|
59
92
|
|
|
93
|
+
**Against an auth server on your own machine,** while developing it, pass `allowLocalhostHttp: true`
|
|
94
|
+
to `discover`, `signInWithLoopback`, `finishSignIn` and `createSession`, as `createFlipstream` takes
|
|
95
|
+
it. Plain http is then accepted for `localhost`, `127.0.0.1` and `[::1]` only, and every endpoint
|
|
96
|
+
such a server names must be on its own origin. It's off unless your code sets it: the SDK never
|
|
97
|
+
reads it from the environment. Never set it in production.
|
|
98
|
+
|
|
60
99
|
### With a browser on the same machine
|
|
61
100
|
|
|
62
101
|
`signInWithLoopback` opens a one-time server on `127.0.0.1`, on a port the system chooses, and
|
|
@@ -182,20 +221,29 @@ SDK has two stores ready for it, which keep the store's rules for you.
|
|
|
182
221
|
|
|
183
222
|
```ts
|
|
184
223
|
import { createFlipstream, discover } from '@flipstream/sdk'
|
|
185
|
-
import { createSession, fileStore,
|
|
224
|
+
import { createSession, fileStore, keychainStore, signInWithLoopback } from '@flipstream/sdk/node'
|
|
186
225
|
import { homedir } from 'node:os'
|
|
187
226
|
import { join } from 'node:path'
|
|
188
227
|
|
|
189
228
|
const issuer = 'https://auth.flipstream.io'
|
|
190
229
|
|
|
191
|
-
// The system's keychain
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
230
|
+
// The system's keychain by default. A file that only this user can read when the person asks for
|
|
231
|
+
// one, for a machine with no keychain (Linux without a Secret Service, as on most servers). A real
|
|
232
|
+
// app remembers that choice, in its config say, so every run uses the same store.
|
|
233
|
+
const inFile = process.argv.includes('--tokens-in-file')
|
|
234
|
+
const tokensFile = join(homedir(), '.config', 'example-cli', 'tokens.json')
|
|
235
|
+
const store = inFile ? fileStore(tokensFile) : keychainStore({ service: 'io.example.cli', account: issuer })
|
|
236
|
+
if (inFile) console.error(`Your sign-in is kept in ${tokensFile}, which only your user can read.`)
|
|
237
|
+
|
|
238
|
+
// A store that can't be read is the person's to fix: never a quiet switch from the keychain to a file.
|
|
239
|
+
const saved = await store.tokens().catch((error: unknown) => {
|
|
240
|
+
const why = error instanceof Error ? error.message : String(error)
|
|
241
|
+
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`)
|
|
243
|
+
})
|
|
196
244
|
|
|
197
245
|
// Sign in once, and save the tokens. Only signing in needs the server first.
|
|
198
|
-
if (
|
|
246
|
+
if (saved === null) {
|
|
199
247
|
const server = await discover(issuer)
|
|
200
248
|
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
201
249
|
const signedIn = await signInWithLoopback({
|
|
@@ -239,19 +287,28 @@ console.log(signedOut.kind)
|
|
|
239
287
|
refresh's tokens only while it still holds the ones they replace, so a newer sign-in is kept.
|
|
240
288
|
`save` is for a sign-in's tokens, and `clear` for an app that signs out without a session:
|
|
241
289
|
`session.revoke()` clears the store itself.
|
|
242
|
-
- **`fileStore(path)`**
|
|
243
|
-
|
|
290
|
+
- **`fileStore(path)`** is for a machine with no keychain, chosen by the app or the person, never
|
|
291
|
+
switched to quietly when the keychain fails: tell them where the file is. **The risk:** anyone
|
|
292
|
+
who can read their files, as them or as an administrator, can use the tokens in it.
|
|
293
|
+
It writes the whole file under a temporary name in its folder, flushes it to disk, renames it
|
|
294
|
+
over the old one and flushes the folder: a reader, or a power cut, sees the old
|
|
244
295
|
tokens or the new ones, never half. The file's mode is 0600, and a folder it makes is 0700. It
|
|
245
296
|
refuses a file that is a link, isn't this user's or is open to others, and it won't read or
|
|
246
297
|
save in a folder others can write to. On Windows the folder isn't flushed, and nothing checks
|
|
247
|
-
who owns what.
|
|
298
|
+
who owns what. With `{ lock: true }` it also brings a lock for several processes (see
|
|
299
|
+
"Several processes on one store").
|
|
248
300
|
- **`keychainStore({ service, account })`** keeps the tokens in one item of the system's
|
|
249
301
|
credential store: the macOS keychain, Windows' Credential Manager, or the Secret Service on
|
|
250
302
|
Linux (GNOME Keyring, KWallet). It needs the optional package `@napi-rs/keyring`
|
|
251
303
|
(`npm install @napi-rs/keyring`); without it, every step fails as `store_failed`, naming the
|
|
252
304
|
package.
|
|
253
|
-
-
|
|
254
|
-
|
|
305
|
+
- Its steps run in one helper process, one at a time. The first step starts it, and it stays
|
|
306
|
+
warm while your app runs (about 57 MB), so a step after that takes a keychain call, not a
|
|
307
|
+
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
|
|
255
312
|
it needs a Node that runs a script: not an Electron app (without `ELECTRON_RUN_AS_NODE`), a
|
|
256
313
|
Node single-executable application, or a compiled Bun binary. A bundle must keep
|
|
257
314
|
`keychainChild.js` beside the module, with `zod` and `@napi-rs/keyring` resolvable from
|
|
@@ -263,6 +320,9 @@ console.log(signedOut.kind)
|
|
|
263
320
|
- Tokens over 2,560 bytes, Windows' limit, kept on every platform, fail the save with nothing
|
|
264
321
|
written. A Flipstream sign-in's tokens take about 1.6 KB.
|
|
265
322
|
- On Linux without a Secret Service, as on most servers, use `fileStore`.
|
|
323
|
+
- 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`.
|
|
266
326
|
- On macOS, a script run by the same Node can read the item without a prompt, much as with a
|
|
267
327
|
file only the person can read.
|
|
268
328
|
- It's tested on macOS. Windows and Linux aren't tested yet.
|
|
@@ -270,15 +330,27 @@ console.log(signedOut.kind)
|
|
|
270
330
|
process takes, which settles only once its work has settled. Two sessions on one store refresh as
|
|
271
331
|
two processes would, and the server can end the session.
|
|
272
332
|
- **In one process,** the ready-made stores take each save, update and clear of the same file or
|
|
273
|
-
item in turn, so a sign-in saved while a refresh is saving is kept.
|
|
333
|
+
item in turn, so a sign-in saved while a refresh is saving is kept. A file counts as the same
|
|
334
|
+
however its folder is spelt (through a link, or in another case on macOS), but not when its own
|
|
335
|
+
name differs only in case.
|
|
274
336
|
- **Across processes,** take the session's lock around `save` and `clear` too: a store's compare
|
|
275
337
|
and its write are one step only among processes that take turns.
|
|
276
338
|
- **`session.token()`** rejects with a `SessionError` when there's no token to give: `signed-out`,
|
|
277
339
|
`unavailable` (after 15 s at most), `store_failed` or `refresh_failed`.
|
|
340
|
+
- **Before your process exits, `await session.settled()`.** It resolves once the session has no
|
|
341
|
+
refresh, save or sign-out in flight. `unavailable` comes while a refresh may still be saving the
|
|
342
|
+
token it got, and an exit then loses it. It never rejects and starts nothing.
|
|
343
|
+
- **It waits at most as long as the session's own limits.** A store that never answers a read or
|
|
344
|
+
a save holds it, and so does a lock that ignores its signal. A sign-out's store call still
|
|
345
|
+
running after 60 s isn't waited for.
|
|
346
|
+
- **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.
|
|
348
|
+
- **Stop making calls before you await it:** calls that keep coming keep it waiting.
|
|
278
349
|
- **`session.revoke()`** gives `revoked`, or `unconfirmed` with the reason. It ends the session the
|
|
279
350
|
store holds when its turn comes, and, whatever the result, clears it through `onTokens`
|
|
280
351
|
(`cleared`), once, in the same hold of the lock, so a refresh can't bring it back. A sign-in saved
|
|
281
|
-
after that is kept.
|
|
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
|
|
282
354
|
may still be on its way: once it reaches the lock, it waits at most 60 s for the lock and for each
|
|
283
355
|
of its three store calls, so up to about four minutes. A lock held longer than its 60 s by another
|
|
284
356
|
process, or a store call that doesn't answer within its 60 s, leaves the store as it was.
|
|
@@ -325,26 +397,36 @@ run several times at once.
|
|
|
325
397
|
import { homedir } from 'node:os'
|
|
326
398
|
import { join } from 'node:path'
|
|
327
399
|
import { discover } from '@flipstream/sdk'
|
|
328
|
-
import { createSession, fileLock,
|
|
400
|
+
import { createSession, fileLock, signInWithLoopback, type TokenStore } from '@flipstream/sdk/node'
|
|
329
401
|
|
|
330
|
-
const
|
|
331
|
-
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
402
|
+
const issuer = 'https://auth.flipstream.io'
|
|
332
403
|
|
|
333
|
-
//
|
|
334
|
-
declare const store:
|
|
335
|
-
tokens(): Promise<SessionTokens | null>
|
|
336
|
-
onTokens(update: TokenUpdate): Promise<void>
|
|
337
|
-
clear(): Promise<void>
|
|
338
|
-
}
|
|
404
|
+
// The store, chosen as above: the keychain, or the file the person asked for.
|
|
405
|
+
declare const store: TokenStore
|
|
339
406
|
|
|
340
407
|
// One lock file for every process on this machine.
|
|
341
|
-
const lock = fileLock(join(homedir(), '.config', '
|
|
342
|
-
const session = createSession({
|
|
408
|
+
const lock = fileLock(join(homedir(), '.config', 'example-cli', 'session.lock'))
|
|
409
|
+
const session = createSession({ issuer, clientId: '<your client id>', ...store, lock })
|
|
343
410
|
|
|
344
|
-
//
|
|
345
|
-
//
|
|
411
|
+
// A sign-in's save takes the same lock. Give it longer than the 10 s a lock file left by a crash
|
|
412
|
+
// can take to go stale.
|
|
413
|
+
if ((await store.tokens()) === null) {
|
|
414
|
+
const server = await discover(issuer)
|
|
415
|
+
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
416
|
+
const signedIn = await signInWithLoopback({
|
|
417
|
+
server: server.data,
|
|
418
|
+
clientId: '<your client id>',
|
|
419
|
+
scopes: ['<scope>'],
|
|
420
|
+
open: (url) => {
|
|
421
|
+
console.log(`Sign in at ${url}`)
|
|
422
|
+
},
|
|
423
|
+
})
|
|
424
|
+
if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
425
|
+
await lock(() => store.save(signedIn.data), AbortSignal.timeout(30_000))
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Signing out takes the lock itself, and clears the store inside it.
|
|
346
429
|
await session.revoke()
|
|
347
|
-
await lock(() => store.clear(), AbortSignal.timeout(30_000))
|
|
348
430
|
```
|
|
349
431
|
|
|
350
432
|
- **Give every process the same absolute path,** on a local disk, for processes on this machine's
|
|
@@ -358,12 +440,94 @@ await lock(() => store.clear(), AbortSignal.timeout(30_000))
|
|
|
358
440
|
every second, and a waiter takes a file over once nobody has touched it for 10 s and it has
|
|
359
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
|
|
360
442
|
within about 3 s.
|
|
443
|
+
- **On Ctrl-C,** Node ends the process without letting a held lock go, and the next process waits
|
|
444
|
+
up to 10 s for it. An app that wants it gone sooner can handle SIGINT itself, and exit only once
|
|
445
|
+
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.
|
|
451
|
+
|
|
452
|
+
```ts
|
|
453
|
+
import { homedir } from 'node:os'
|
|
454
|
+
import { join } from 'node:path'
|
|
455
|
+
import { fileLock, type Session } from '@flipstream/sdk/node'
|
|
456
|
+
|
|
457
|
+
// The lock for the session and the app's own saves, with every hold kept until it settles. Once
|
|
458
|
+
// the app is stopping, a hold still waiting for the file gives up, and a new one creates nothing
|
|
459
|
+
// (fileLock with a signal that has fired), so the wait below is only for work already running.
|
|
460
|
+
const file = fileLock(join(homedir(), '.config', 'example-cli', 'session.lock'))
|
|
461
|
+
const holds = new Set<Promise<unknown>>()
|
|
462
|
+
const stop = new AbortController()
|
|
463
|
+
const lock: typeof file = (work, signal) => {
|
|
464
|
+
const hold = file(work, AbortSignal.any([signal, stop.signal]))
|
|
465
|
+
holds.add(hold)
|
|
466
|
+
const done = (): void => {
|
|
467
|
+
holds.delete(hold)
|
|
468
|
+
}
|
|
469
|
+
hold.then(done, done)
|
|
470
|
+
return hold
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
declare const session: Session
|
|
474
|
+
|
|
475
|
+
// On Ctrl-C, exit once every hold has let its lock file go and the session's own work is done; a
|
|
476
|
+
// second Ctrl-C exits at once.
|
|
477
|
+
process.on('SIGINT', () => {
|
|
478
|
+
if (stop.signal.aborted) process.exit(130)
|
|
479
|
+
stop.abort(new Error('stopping'))
|
|
480
|
+
void Promise.all([Promise.allSettled([...holds]), session.settled()]).then(() => process.exit(130))
|
|
481
|
+
})
|
|
482
|
+
```
|
|
483
|
+
|
|
361
484
|
- **A holder that can't touch its file for 10 s loses the lock,** and its work goes on beside the
|
|
362
485
|
next holder's: a thread blocked by a synchronous store waiting for a person, or a process stopped
|
|
363
486
|
by Ctrl-Z or a debugger. Keep your store asynchronous.
|
|
364
|
-
- **Take the same lock for the store's other writes,**
|
|
365
|
-
|
|
366
|
-
Never inside `onTokens`, which runs inside it already: the lock isn't
|
|
487
|
+
- **Take the same lock for the store's other writes,** a sign-in's `save`, or a `clear` without a
|
|
488
|
+
session, so they can't land between a refresh's compare and its set. `session.revoke()` takes it
|
|
489
|
+
for its own clear. Never take it inside `onTokens`, which runs inside it already: the lock isn't
|
|
490
|
+
reentrant.
|
|
491
|
+
- **On Windows, `fileLock` hasn't been tried yet.** What may differ there:
|
|
492
|
+
- the lock file and its folder take the folder's own permissions, so they aren't private to this
|
|
493
|
+
user;
|
|
494
|
+
- a lock file it isn't allowed to create, for the folder's permissions, reads as held by another
|
|
495
|
+
process: a refresh then waits out its 60 s and is `unavailable`, not `store_failed`. A file
|
|
496
|
+
antivirus still holds open reads as held only until it lets go;
|
|
497
|
+
- taking over a crashed holder's file fails while antivirus or the indexer has it open, as
|
|
498
|
+
`store_failed`;
|
|
499
|
+
- a path such as `\my-app\session.lock` counts as absolute but names a file on whichever drive
|
|
500
|
+
is current: give the drive as well (`C:\…`).
|
|
501
|
+
|
|
502
|
+
**A file store can bring its own lock.** `fileStore(path, { lock: true })` also returns `lock`:
|
|
503
|
+
`fileLock` on the file's path with `.lock` added, beside it. Every process, and every version of
|
|
504
|
+
your app, that opens the same file then takes the same lock, with no path of its own to agree on.
|
|
505
|
+
|
|
506
|
+
```ts
|
|
507
|
+
import { homedir } from 'node:os'
|
|
508
|
+
import { join } from 'node:path'
|
|
509
|
+
import { createSession, fileStore, type SessionTokens } from '@flipstream/sdk/node'
|
|
510
|
+
|
|
511
|
+
const store = fileStore(join(homedir(), '.config', 'example-cli', 'tokens.json'), { lock: true })
|
|
512
|
+
|
|
513
|
+
// Spread in, so the session takes store.lock for its refreshes and sign-outs.
|
|
514
|
+
const session = createSession({ issuer: 'https://auth.flipstream.io', clientId: '<your client id>', ...store })
|
|
515
|
+
|
|
516
|
+
// A sign-in's save takes it too, as does a clear of your own.
|
|
517
|
+
declare const signedIn: SessionTokens
|
|
518
|
+
await store.lock(() => store.save(signedIn), AbortSignal.timeout(30_000))
|
|
519
|
+
|
|
520
|
+
// Signing out takes it itself.
|
|
521
|
+
await session.revoke()
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
- **The store's own steps never take it,** so a `save` or `clear` inside it doesn't wait for itself,
|
|
525
|
+
and a clear leaves the lock file alone. Without `{ lock: true }`, nothing changes.
|
|
526
|
+
- **Don't pass a `lock` of your own as well:** `{ ...store, lock }` leaves the session on yours and
|
|
527
|
+
your saves on `store.lock`, and `{ lock, ...store }` swaps yours out without a word. Either way a
|
|
528
|
+
sign-in can land between a refresh's compare and its write.
|
|
529
|
+
- **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).
|
|
367
531
|
|
|
368
532
|
## In a browser
|
|
369
533
|
|
|
@@ -417,7 +581,10 @@ if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
|
417
581
|
- **The secret goes only in the token request's `Authorization: Basic` header** (RFC 6749 §2.3.1),
|
|
418
582
|
and only to the token endpoint of the `server` you pass. A `pending` that names another server,
|
|
419
583
|
or another client ID than `clientId`, is refused, with nothing sent. The secret is never in a body, a URL, a result or an error, and
|
|
420
|
-
|
|
584
|
+
never logged. The SDK logs nothing but one warning per catalogue format type it doesn't know,
|
|
585
|
+
which never holds a token, a secret or a field's value, and which `onWarning` routes or
|
|
586
|
+
silences. A `fetch` you pass sees the request,
|
|
587
|
+
header included: don't log it.
|
|
421
588
|
- **A failure keeps its kind, status and OAuth code** (`invalid_client`, `invalid_grant`, …), but
|
|
422
589
|
not the server's description or body (an empty `message` or `text`): a server or proxy that
|
|
423
590
|
echoes the request would put the credentials there.
|
|
@@ -444,6 +611,11 @@ throws the failure as an `ApiFailure` carrying its `error`, for callers who'd ra
|
|
|
444
611
|
`dimensions`, `metrics`, `filters`, `sort`, `offset` and `rows`. A request with any other key,
|
|
445
612
|
`table` included, is `refused` with nothing sent, and `error.fields` names each one, so a
|
|
446
613
|
misspelt field never quietly changes the numbers.
|
|
614
|
+
- **`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
|
|
617
|
+
instance, before its other calls. It reads only the keys; a missing `source` is still the
|
|
618
|
+
API's to refuse.
|
|
447
619
|
- **`fs.health()`** gives the planner's answer to `GET /health`, an object of strings
|
|
448
620
|
(`{ status: 'ok' }` today). It works signed out: no token is asked for or sent, so it tells "the
|
|
449
621
|
service is down" from "the sign-in is wrong".
|
|
@@ -517,8 +689,9 @@ function explain(error: ApiError): string {
|
|
|
517
689
|
- `not_a_url` and `wrong_redirect`: a pasted address that isn't a URL, or isn't this sign-in's
|
|
518
690
|
redirect (`parsePastedRedirect`, or `signInWithLoopback`'s `readPasted`).
|
|
519
691
|
|
|
520
|
-
There, `refused` also covers an issuer that isn't https
|
|
521
|
-
storage the app couldn't read back).
|
|
692
|
+
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.
|
|
522
695
|
|
|
523
696
|
## Options
|
|
524
697
|
|
|
@@ -532,6 +705,7 @@ const fs = createFlipstream({
|
|
|
532
705
|
token: ({ rejected }) => session.accessToken(rejected),
|
|
533
706
|
fetch: globalThis.fetch, // optional: every request goes through it
|
|
534
707
|
hosts: { query: 'https://query.flipstream.io' }, // optional: the default
|
|
708
|
+
onWarning: (message) => process.stderr.write(`${message}\n`), // optional: console.warn by default
|
|
535
709
|
})
|
|
536
710
|
|
|
537
711
|
const controller = new AbortController()
|
|
@@ -554,6 +728,10 @@ await fs.catalog.list({ signal: controller.signal, deadlineMs: 10_000 })
|
|
|
554
728
|
- **Deadlines:** 60 s for `query`, 10 s for `health` and 30 s for the rest, every attempt and
|
|
555
729
|
wait included. `deadlineMs` sets one call's.
|
|
556
730
|
- **Abort:** `signal` ends a call at once, also while it waits for a token or to try again.
|
|
731
|
+
- **Warnings:** the SDK's warnings go to `onWarning`, or to `console.warn` without it; `() => {}`
|
|
732
|
+
silences them. Today there is one kind: a catalogue format type this version doesn't know,
|
|
733
|
+
reported once per process to the client that read it first. A handler that throws is ignored,
|
|
734
|
+
and the read goes on.
|
|
557
735
|
- **Your own transport:** an app that attaches the token itself passes `{ transport }` instead of
|
|
558
736
|
`token` and `fetch`. Retries and deadlines still apply, above it. `health` carries no token, so
|
|
559
737
|
it never goes through your transport: it goes to the query host, over https, with the global
|
package/dist/auth/discovery.d.ts
CHANGED
|
@@ -15,9 +15,10 @@ export interface AuthServer {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* The authorization server at `issuer`, from its RFC 8414 metadata. `refused`, with nothing sent,
|
|
18
|
-
* when `issuer` isn't an https URL
|
|
19
|
-
* exactly (§3.3), an endpoint that is
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* when `issuer` isn't an https URL, or with `allowLocalhostHttp`, an http one on this machine.
|
|
19
|
+
* Refused as `invalid`: metadata that doesn't name `issuer` exactly (§3.3), an endpoint that is
|
|
20
|
+
* not an https URL (for an http issuer on this machine, one not on its own origin), and a server
|
|
21
|
+
* that doesn't list PKCE's S256, since one that lists no methods supports no PKCE (§2), and a code
|
|
22
|
+
* it issues is bound to no verifier.
|
|
22
23
|
*/
|
|
23
24
|
export declare function discover(issuer: string, options?: AuthCallOptions): Promise<ApiResult<AuthServer>>;
|
package/dist/auth/discovery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
|
-
import { authTransport,
|
|
3
|
+
import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
|
|
4
4
|
// Unknown fields are kept and never read: `first_party_client_id` among them, which the SDK never
|
|
5
5
|
// uses in place of the app's own client ID (D421).
|
|
6
6
|
const zMetadata = z.looseObject({
|
|
@@ -13,13 +13,14 @@ const zMetadata = z.looseObject({
|
|
|
13
13
|
});
|
|
14
14
|
/**
|
|
15
15
|
* The authorization server at `issuer`, from its RFC 8414 metadata. `refused`, with nothing sent,
|
|
16
|
-
* when `issuer` isn't an https URL
|
|
17
|
-
* exactly (§3.3), an endpoint that is
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* when `issuer` isn't an https URL, or with `allowLocalhostHttp`, an http one on this machine.
|
|
17
|
+
* Refused as `invalid`: metadata that doesn't name `issuer` exactly (§3.3), an endpoint that is
|
|
18
|
+
* not an https URL (for an http issuer on this machine, one not on its own origin), and a server
|
|
19
|
+
* that doesn't list PKCE's S256, since one that lists no methods supports no PKCE (§2), and a code
|
|
20
|
+
* it issues is bound to no verifier.
|
|
20
21
|
*/
|
|
21
22
|
export async function discover(issuer, options = {}) {
|
|
22
|
-
if (typeof issuer !== 'string' || !
|
|
23
|
+
if (typeof issuer !== 'string' || !isSignInUrl(issuer, options.allowLocalhostHttp))
|
|
23
24
|
return { ok: false, error: { kind: 'refused' } };
|
|
24
25
|
const read = await call(authTransport(options), {
|
|
25
26
|
effect: 'read',
|
|
@@ -62,8 +63,9 @@ function problemWith(doc, issuer) {
|
|
|
62
63
|
if (doc.issuer !== issuer)
|
|
63
64
|
return 'the metadata names another issuer';
|
|
64
65
|
const endpoints = [doc.authorization_endpoint, doc.token_endpoint, ...(doc.revocation_endpoint === undefined ? [] : [doc.revocation_endpoint])];
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
const problem = endpointProblem(issuer, endpoints);
|
|
67
|
+
if (problem !== null)
|
|
68
|
+
return problem;
|
|
67
69
|
if (doc.code_challenge_methods_supported?.includes('S256') !== true)
|
|
68
70
|
return 'the server does not list PKCE S256';
|
|
69
71
|
return null;
|
|
@@ -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,
|
|
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,CA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AAK,IAAI;QAAE,OAAO,oCAAoC,CAAA;IAChH,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/auth/signIn.js
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
3
|
import { challengeOf, randomValue } from './pkce.js';
|
|
4
4
|
import { tokenCall } from './tokenEndpoint.js';
|
|
5
|
-
import { authTransport,
|
|
5
|
+
import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
|
|
6
6
|
const nonEmpty = (value) => typeof value === 'string' && value !== '';
|
|
7
7
|
/**
|
|
8
8
|
* The URL to send the person to, and what finishing will need. Rejects with a TypeError, before
|
|
@@ -64,16 +64,21 @@ export function readCallback(callbackUrl, pending) {
|
|
|
64
64
|
const code = params.get('code');
|
|
65
65
|
return nonEmpty(code) ? { kind: 'code', code } : { kind: 'no_code' };
|
|
66
66
|
}
|
|
67
|
-
const zPending = z
|
|
67
|
+
const zPending = z
|
|
68
|
+
.object({
|
|
68
69
|
state: z.string().min(1),
|
|
69
70
|
verifier: z.string().min(43).max(128),
|
|
70
71
|
clientId: z.string().min(1),
|
|
71
72
|
redirectUri: z.string().min(1),
|
|
72
73
|
scope: z.string().min(1),
|
|
73
74
|
issuer: z.string().min(1),
|
|
74
|
-
tokenEndpoint: z.string()
|
|
75
|
+
tokenEndpoint: z.string(),
|
|
75
76
|
issuerOnRedirect: z.boolean(),
|
|
76
|
-
})
|
|
77
|
+
})
|
|
78
|
+
// A pending from storage may have been edited. Its token endpoint is held to the issuer's rule:
|
|
79
|
+
// https for an https issuer; for an http one on this machine, its own origin, which `finishSignIn`
|
|
80
|
+
// then sends to only with `allowLocalhostHttp` (#164).
|
|
81
|
+
.refine((pending) => endpointProblem(pending.issuer, [pending.tokenEndpoint]) === null);
|
|
77
82
|
/** A pending sign-in as `startSignIn` makes one, checked: it comes back from the app's storage. */
|
|
78
83
|
export const isPendingSignIn = (value) => zPending.safeParse(value).success;
|
|
79
84
|
/**
|
|
@@ -91,7 +96,7 @@ export function finishSignIn(callbackUrl, pending, options = {}) {
|
|
|
91
96
|
* entry never exports this, so browser code has no way to send client credentials.
|
|
92
97
|
*/
|
|
93
98
|
export async function exchangeCode(callbackUrl, pending, options, authorization) {
|
|
94
|
-
if (!isPendingSignIn(pending) || !URL.canParse(callbackUrl))
|
|
99
|
+
if (!isPendingSignIn(pending) || !isSignInUrl(pending.tokenEndpoint, options.allowLocalhostHttp) || !URL.canParse(callbackUrl))
|
|
95
100
|
return { ok: false, error: { kind: 'refused' } };
|
|
96
101
|
const callback = readCallback(callbackUrl, pending);
|
|
97
102
|
if (callback.kind !== 'code')
|
package/dist/auth/signIn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGtC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGtC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAwB,MAAM,gBAAgB,CAAA;AAoElG,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAA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AY,EAAE,OAAO,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9I,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAA;IACtE,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ,WAAW,EAAE,YAAY;YACzB,+FAA+F;YAC/F,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnE,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC;YAC9E,wFAAwF;YACxF,wBAAwB;YACxB,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK;SAC9B;KACF,CAAA;AACH,CAAC"}
|
package/dist/auth/transport.d.ts
CHANGED
|
@@ -5,14 +5,32 @@ export interface AuthCallOptions {
|
|
|
5
5
|
readonly signal?: AbortSignal | undefined;
|
|
6
6
|
/** The app's own fetch, called as a plain function; the global one when it is undefined. */
|
|
7
7
|
readonly fetch?: typeof fetch | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Plain http to an auth server on this machine (localhost, 127.0.0.1, [::1]), as
|
|
10
|
+
* `createFlipstream`'s option: for developing against a local pulse-auth, never in production.
|
|
11
|
+
* Off unless set, and only ever the app's choice, never read from the environment (D503). An http
|
|
12
|
+
* issuer's endpoints must then all be on its own origin.
|
|
13
|
+
*/
|
|
14
|
+
readonly allowLocalhostHttp?: boolean | undefined;
|
|
8
15
|
}
|
|
9
16
|
/**
|
|
10
17
|
* An absolute https URL a Request can be made for: one with a user or password in it is refused
|
|
11
18
|
* by fetch, so it is no endpoint either.
|
|
12
19
|
*/
|
|
13
20
|
export declare function isHttpsUrl(value: string): boolean;
|
|
21
|
+
/** As `isHttpsUrl`, and with `allowLocalhostHttp`, an http URL on this machine too (#164). */
|
|
22
|
+
export declare function isSignInUrl(value: string, allowLocalhostHttp: boolean | undefined): boolean;
|
|
14
23
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
24
|
+
* What's wrong with an issuer's endpoints, or null (#164). An https issuer's must be https, with or
|
|
25
|
+
* without `allowLocalhostHttp`, as before. An http issuer, which only the option lets through, is a
|
|
26
|
+
* server on this machine: its endpoints must all be on its own origin (scheme, host and port), so
|
|
27
|
+
* it can't send the sign-in elsewhere. The one rule for every place endpoints come from:
|
|
28
|
+
* `discover`, a pending sign-in from storage, a server the app builds.
|
|
29
|
+
*/
|
|
30
|
+
export declare function endpointProblem(issuer: string, endpoints: readonly string[]): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Sign-in's transport: https only, or with `allowLocalhostHttp` http to this machine, and no
|
|
33
|
+
* token, since these calls are how a token is had. It sends as the default transport does
|
|
34
|
+
* (`sendRequest`): no cookies, and no redirect followed.
|
|
17
35
|
*/
|
|
18
36
|
export declare function authTransport(options: AuthCallOptions): Transport;
|