@flipstream/sdk 0.4.0 → 0.5.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 +17 -0
- package/README.md +229 -18
- package/dist/auth/discovery.d.ts +2 -0
- package/dist/auth/discovery.js +4 -1
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.d.ts +11 -2
- package/dist/auth/signIn.js +19 -27
- package/dist/auth/signIn.js.map +1 -1
- package/dist/auth/tokenEndpoint.d.ts +18 -0
- package/dist/auth/tokenEndpoint.js +36 -0
- package/dist/auth/tokenEndpoint.js.map +1 -0
- package/dist/core/fetch.d.ts +8 -0
- package/dist/core/fetch.js +36 -11
- package/dist/core/fetch.js.map +1 -1
- package/dist/core/result.d.ts +4 -2
- package/dist/core/result.js +3 -1
- package/dist/core/result.js.map +1 -1
- package/dist/flipstream.d.ts +7 -0
- package/dist/flipstream.js +14 -4
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/dist/node/clientSecret.d.ts +41 -0
- package/dist/node/clientSecret.js +124 -0
- package/dist/node/clientSecret.js.map +1 -0
- package/dist/node/fileLock.d.ts +27 -0
- package/dist/node/fileLock.js +248 -0
- package/dist/node/fileLock.js.map +1 -0
- package/dist/node/headless.d.ts +7 -2
- package/dist/node/headless.js +15 -2
- package/dist/node/headless.js.map +1 -1
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +7 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/loopback.d.ts +24 -5
- package/dist/node/loopback.js +80 -23
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +192 -0
- package/dist/node/session.js +480 -0
- package/dist/node/session.js.map +1 -0
- package/dist/query/health.d.ts +16 -0
- package/dist/query/health.js +18 -0
- package/dist/query/health.js.map +1 -0
- package/dist/query/query.d.ts +8 -0
- package/dist/query/query.js +12 -0
- package/dist/query/query.js.map +1 -1
- package/package.json +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.4.0...typescript-v0.5.0) (2026-10-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **typescript:** a sign-in session with one shared refresh and revocation ([#105](https://github.com/flipstream-io/sdk/issues/105)) ([3f89388](https://github.com/flipstream-io/sdk/commit/3f893880ae006827d341d8b68b02899fee9e71da))
|
|
9
|
+
* **typescript:** fileLock, a lock across processes for one token store ([#143](https://github.com/flipstream-io/sdk/issues/143)) ([8c528cd](https://github.com/flipstream-io/sdk/commit/8c528cdc90a766a1e601dec451233e8f6c59b0d0)), closes [#114](https://github.com/flipstream-io/sdk/issues/114)
|
|
10
|
+
* **typescript:** finish a loopback sign-in from a pasted redirect ([#125](https://github.com/flipstream-io/sdk/issues/125)) ([e90b4dc](https://github.com/flipstream-io/sdk/commit/e90b4dc2cdbb7cf27af18130c977a158a26b7c6d)), closes [#112](https://github.com/flipstream-io/sdk/issues/112)
|
|
11
|
+
* **typescript:** fs.health() asks the planner if it is up, signed out ([#124](https://github.com/flipstream-io/sdk/issues/124)) ([c446f0b](https://github.com/flipstream-io/sdk/commit/c446f0bb86b6afa676e9a124052f62779715d081)), closes [#111](https://github.com/flipstream-io/sdk/issues/111)
|
|
12
|
+
* **typescript:** sign in from a server with the app's client secret ([#127](https://github.com/flipstream-io/sdk/issues/127)) ([6ef56aa](https://github.com/flipstream-io/sdk/commit/6ef56aa962a0d1884abb49578a231e5596af62c4))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **typescript:** declare @types/node as an optional peer ([#136](https://github.com/flipstream-io/sdk/issues/136)) ([8716cbe](https://github.com/flipstream-io/sdk/commit/8716cbeb07deaae43d9d1af61407cad65aed4ad7)), closes [#135](https://github.com/flipstream-io/sdk/issues/135)
|
|
18
|
+
* **typescript:** fs.query refuses a field it doesn't send, instead of dropping it ([#121](https://github.com/flipstream-io/sdk/issues/121)) ([d4d6593](https://github.com/flipstream-io/sdk/commit/d4d65930658c2d964c73c91fa5a17d63e78f15bb)), closes [#113](https://github.com/flipstream-io/sdk/issues/113)
|
|
19
|
+
|
|
3
20
|
## [0.4.0](https://github.com/flipstream-io/sdk/compare/typescript-v0.3.0...typescript-v0.4.0) (2026-10-17)
|
|
4
21
|
|
|
5
22
|
|
package/README.md
CHANGED
|
@@ -53,6 +53,9 @@ tool. `@flipstream/sdk/node` signs them in through their browser, with OAuth 2.0
|
|
|
53
53
|
code and PKCE. The SDK stores nothing: the tokens are the app's to keep. A web app signs in on its
|
|
54
54
|
server instead (see "In a browser").
|
|
55
55
|
|
|
56
|
+
In a TypeScript project, add `@types/node` (`npm install --save-dev @types/node`): this entry's
|
|
57
|
+
types use Node's own.
|
|
58
|
+
|
|
56
59
|
### With a browser on the same machine
|
|
57
60
|
|
|
58
61
|
`signInWithLoopback` opens a one-time server on `127.0.0.1`, on a port the system chooses, and
|
|
@@ -82,18 +85,60 @@ const fs = createFlipstream({ token: () => signedIn.data.accessToken })
|
|
|
82
85
|
- **The SDK opens nothing and writes nothing to the terminal.** `open` does that, once the port is
|
|
83
86
|
open.
|
|
84
87
|
- **The port listens on `127.0.0.1` only,** and is closed on every path: signed in, refused, timed
|
|
85
|
-
out (after 5 minutes, or `timeoutMs`), aborted (`signal`), or `open` failing.
|
|
88
|
+
out (after 5 minutes, or `timeoutMs`), aborted (`signal`), or `open` or `readPasted` failing.
|
|
86
89
|
- **The redirect is checked before its code is exchanged:** the sign-in's own state first, then the
|
|
87
90
|
issuer.
|
|
88
91
|
- **`page: { signedIn, failed }`** sets the HTML the browser shows afterwards.
|
|
89
92
|
- **What comes back:** `accessToken`, `scope`, `expiresAt` (ms since the epoch) when the server
|
|
90
93
|
says, and `refreshToken` when it issues one. Never log them.
|
|
91
94
|
|
|
95
|
+
### When the browser may not reach this machine
|
|
96
|
+
|
|
97
|
+
**The way for a CLI, or any app that waits while the person signs in.** In a remote session
|
|
98
|
+
nothing may say so (a tmux session started before the SSH login sets no `SSH_*` variable), and
|
|
99
|
+
the person's browser, on their own device, then can't load the address it's sent back to. Give
|
|
100
|
+
`signInWithLoopback` a `readPasted` as well: the person pastes that address back, and the same
|
|
101
|
+
sign-in finishes. Where their browser can reach the port, it does, and the prompt stops.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { discover } from '@flipstream/sdk'
|
|
105
|
+
import { signInWithLoopback } from '@flipstream/sdk/node'
|
|
106
|
+
import { createInterface } from 'node:readline/promises'
|
|
107
|
+
|
|
108
|
+
const server = await discover('https://auth.flipstream.io')
|
|
109
|
+
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
110
|
+
|
|
111
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout })
|
|
112
|
+
const signedIn = await signInWithLoopback({
|
|
113
|
+
server: server.data,
|
|
114
|
+
clientId: '<your client id>',
|
|
115
|
+
scopes: ['<scope>'],
|
|
116
|
+
open: (url) => {
|
|
117
|
+
console.log(`Sign in at ${url}`)
|
|
118
|
+
},
|
|
119
|
+
// The signal fires once a paste can't be taken any more, and stops the prompt.
|
|
120
|
+
readPasted: (signal) => prompt.question('If your browser fails to load the page after signing in, paste its address here: ', { signal }),
|
|
121
|
+
})
|
|
122
|
+
prompt.close()
|
|
123
|
+
if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- **Whichever comes first is taken,** the port's redirect or the paste, and only its code is
|
|
127
|
+
exchanged. Once one is taken, the port answers anything else with the failure page, and a later
|
|
128
|
+
paste is dropped.
|
|
129
|
+
- **A paste is checked before anything is sent,** as `parsePastedRedirect` checks one: this
|
|
130
|
+
sign-in's own address, then its state. A paste that fails ends the sign-in with its reason, such
|
|
131
|
+
as `wrong_state`, and nothing is exchanged.
|
|
132
|
+
- **A reader that rejects** ends the sign-in as `paste_failed`. `readPasted` is called once, just
|
|
133
|
+
after `open`.
|
|
134
|
+
|
|
92
135
|
### Over SSH, in CI, or with no display
|
|
93
136
|
|
|
94
137
|
When no browser can come back to this machine, the person opens the URL on another device. The
|
|
95
|
-
redirect then fails to load, and they paste back the address it ended on.
|
|
96
|
-
when
|
|
138
|
+
redirect then fails to load, and they paste back the address it ended on. If one process waits for
|
|
139
|
+
them, `readPasted` above does this. The two halves below are for when the app can't wait, or
|
|
140
|
+
won't open a port: it keeps `pending` until the paste comes, for instance in a second command.
|
|
141
|
+
`isHeadless` tells you when no browser can come back.
|
|
97
142
|
|
|
98
143
|
```ts
|
|
99
144
|
import { discover, finishSignIn, startSignIn } from '@flipstream/sdk'
|
|
@@ -128,6 +173,117 @@ if (isHeadless(process.env)) {
|
|
|
128
173
|
- **`pending` holds the PKCE verifier,** a secret. Keep it only until the sign-in finishes, and
|
|
129
174
|
never log it.
|
|
130
175
|
|
|
176
|
+
### Keeping the person signed in
|
|
177
|
+
|
|
178
|
+
`createSession` keeps an access token fresh from the tokens your store holds, and signs the person
|
|
179
|
+
out. It holds a refresh token, so it belongs in a CLI or on a server, never in browser code.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { createFlipstream, discover } from '@flipstream/sdk'
|
|
183
|
+
import { createSession, type SessionTokens, type TokenUpdate } from '@flipstream/sdk/node'
|
|
184
|
+
|
|
185
|
+
const server = await discover('https://auth.flipstream.io')
|
|
186
|
+
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
187
|
+
|
|
188
|
+
// Your store, here in memory. A real one saves first and shows second (see below).
|
|
189
|
+
let stored: SessionTokens | null = null
|
|
190
|
+
|
|
191
|
+
const session = createSession({
|
|
192
|
+
server: server.data,
|
|
193
|
+
clientId: '<your client id>',
|
|
194
|
+
tokens: () => stored,
|
|
195
|
+
onTokens: (update: TokenUpdate) => {
|
|
196
|
+
// Compare and set: only while the store's key is still the one this update replaces.
|
|
197
|
+
if (stored === null || (stored.refreshToken || stored.accessToken) !== update.replaces) throw new Error('the store moved on')
|
|
198
|
+
if (update.kind === 'cleared') {
|
|
199
|
+
stored = null
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
const { accessToken, expiresAt } = update
|
|
203
|
+
const refreshToken = update.kind === 'rotated' ? update.refreshToken : stored.refreshToken
|
|
204
|
+
stored = { accessToken, ...(refreshToken === undefined ? {} : { refreshToken }), ...(expiresAt === undefined ? {} : { expiresAt }) }
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
const fs = createFlipstream({ token: session.token })
|
|
209
|
+
|
|
210
|
+
// Signing out ends the session at the server. Then clear your own store, whatever the result.
|
|
211
|
+
const signedOut = await session.revoke()
|
|
212
|
+
stored = null
|
|
213
|
+
console.log(signedOut.kind)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- **What it guarantees:** with a store that shows only what it has saved and compares and sets on
|
|
217
|
+
`replaces`, and one lock shared by every process, the session never sends a refresh token another
|
|
218
|
+
refresh is spending, never hands out a token that wasn't saved, never overwrites a newer sign-in,
|
|
219
|
+
and says `revoked` only when the server took the access token just before and refuses it just
|
|
220
|
+
after. A lost answer or a failed save can still leave a spent token stored, and a server fault
|
|
221
|
+
between the two checks reads as `revoked`.
|
|
222
|
+
- **Your store saves first and shows second.** `tokens()` returns only what `onTokens` has durably
|
|
223
|
+
saved: the system keychain, or a file written under a temporary name, flushed to disk (fsync),
|
|
224
|
+
renamed over the old one, and its folder flushed too. `onTokens` writes only while the store's key
|
|
225
|
+
is still `update.replaces`, and throws when it refuses. The key is the stored refresh token, or the
|
|
226
|
+
access token when it has none or an empty one (`refreshToken || accessToken`).
|
|
227
|
+
- **One session per store,** shared by everything that uses it, or pass `lock`, a lock every
|
|
228
|
+
process takes, which settles only once its work has settled. Two sessions on one store refresh as
|
|
229
|
+
two processes would, and the server can end the session.
|
|
230
|
+
- **`session.token()`** rejects with a `SessionError` when there's no token to give: `signed-out`,
|
|
231
|
+
`unavailable` (after 15 s at most), `store_failed` or `refresh_failed`.
|
|
232
|
+
- **`session.revoke()`** gives `revoked`, or `unconfirmed` with the reason. It doesn't touch your
|
|
233
|
+
store: clear it yourself afterwards, whatever the result.
|
|
234
|
+
- **A known risk:** on a store that doesn't compare and set, a refresh whose save is slow can
|
|
235
|
+
land after your clear and bring a live session back. A later release moves the clear into the
|
|
236
|
+
session, inside its queue.
|
|
237
|
+
|
|
238
|
+
### Several processes on one store
|
|
239
|
+
|
|
240
|
+
`fileLock(path)` is a ready-made `lock` for Node processes that share one store, such as a CLI
|
|
241
|
+
run several times at once.
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import { homedir } from 'node:os'
|
|
245
|
+
import { join } from 'node:path'
|
|
246
|
+
import { discover } from '@flipstream/sdk'
|
|
247
|
+
import { createSession, fileLock, type SessionTokens, type TokenUpdate } from '@flipstream/sdk/node'
|
|
248
|
+
|
|
249
|
+
const server = await discover('https://auth.flipstream.io')
|
|
250
|
+
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
251
|
+
|
|
252
|
+
// Your store, kept on disk, which every process reads and writes.
|
|
253
|
+
declare const store: {
|
|
254
|
+
tokens(): Promise<SessionTokens | null>
|
|
255
|
+
onTokens(update: TokenUpdate): Promise<void>
|
|
256
|
+
clear(): Promise<void>
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// One lock file for every process on this machine.
|
|
260
|
+
const lock = fileLock(join(homedir(), '.config', 'my-app', 'session.lock'))
|
|
261
|
+
const session = createSession({ server: server.data, clientId: '<your client id>', tokens: store.tokens, onTokens: store.onTokens, lock })
|
|
262
|
+
|
|
263
|
+
// The store's other writes take the same lock: here, the clear after signing out. Give them
|
|
264
|
+
// longer than the 10 s a lock file left by a crash can take to go stale.
|
|
265
|
+
await session.revoke()
|
|
266
|
+
await lock(() => store.clear(), AbortSignal.timeout(30_000))
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
- **Give every process the same absolute path,** on a local disk, for processes on this machine's
|
|
270
|
+
clock. A holder whose clock is 10 s or more behind, in a virtual machine sharing the folder say,
|
|
271
|
+
loses the lock after 2 to 3 s without a touch. The file exists only while a process holds the
|
|
272
|
+
lock. Its folder is made when it isn't there (on macOS and Linux, for this user only).
|
|
273
|
+
- **One refresh at a time:** the next process waits for it, reads the store again, and uses the
|
|
274
|
+
token it saved. A process still waiting at the refresh's 60 s deadline gives up, and sends
|
|
275
|
+
nothing.
|
|
276
|
+
- **A process that dies holding it** holds the others off for about 10 s: a holder touches the file
|
|
277
|
+
every second, and a waiter takes a file over once nobody has touched it for 10 s and it has
|
|
278
|
+
watched it for 3 s. A sign-out, which has 10 s in all, takes over a file left 10 s or more before
|
|
279
|
+
within about 3 s.
|
|
280
|
+
- **A holder that can't touch its file for 10 s loses the lock,** and its work goes on beside the
|
|
281
|
+
next holder's: a thread blocked by a synchronous store waiting for a person, or a process stopped
|
|
282
|
+
by Ctrl-Z or a debugger. Keep your store asynchronous.
|
|
283
|
+
- **Take the same lock for the store's other writes,** such as saving a sign-in's tokens, or
|
|
284
|
+
clearing the store after `revoke()`, so they can't land between a refresh's compare and its set.
|
|
285
|
+
Never inside `onTokens`, which runs inside it already: the lock isn't reentrant.
|
|
286
|
+
|
|
131
287
|
## In a browser
|
|
132
288
|
|
|
133
289
|
The main entry, `@flipstream/sdk`, runs in browsers with no Node polyfills. Only
|
|
@@ -143,10 +299,55 @@ The main entry, `@flipstream/sdk`, runs in browsers with no Node polyfills. Only
|
|
|
143
299
|
- when they come back, `finishSignIn(location.href, pending)` checks the redirect and exchanges
|
|
144
300
|
its code.
|
|
145
301
|
- **Browser code shouldn't keep a refresh token.** We recommend signing in on your web app's
|
|
146
|
-
server instead
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
302
|
+
server instead (see "On your web app's server").
|
|
303
|
+
|
|
304
|
+
## On your web app's server
|
|
305
|
+
|
|
306
|
+
Your server signs the person in, keeps the tokens, and proves who it is with your app's client
|
|
307
|
+
secret (a confidential client). `startSignIn` comes from the main entry, with your app's
|
|
308
|
+
registered https callback as the `redirectUri`; `finishSignIn` comes from `@flipstream/sdk/node`.
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
import { discover, startSignIn } from '@flipstream/sdk'
|
|
312
|
+
import { finishSignIn } from '@flipstream/sdk/node'
|
|
313
|
+
|
|
314
|
+
const server = await discover('https://auth.flipstream.io')
|
|
315
|
+
if (!server.ok) throw new Error(`sign-in is unavailable: ${server.error.kind}`)
|
|
316
|
+
const clientSecret = process.env.FLIPSTREAM_CLIENT_SECRET
|
|
317
|
+
if (clientSecret === undefined) throw new Error('FLIPSTREAM_CLIENT_SECRET is not set')
|
|
318
|
+
|
|
319
|
+
// When the person signs in: send them to `url`, and keep `pending` in their session on the server.
|
|
320
|
+
const { url, pending } = await startSignIn({
|
|
321
|
+
server: server.data,
|
|
322
|
+
clientId: '<your client id>',
|
|
323
|
+
redirectUri: 'https://<your app>/callback',
|
|
324
|
+
scopes: ['<scope>'],
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
// When they come back to /callback: the full URL of that request, and the same `pending`.
|
|
328
|
+
const signedIn = await finishSignIn(new URL('https://<your app>/callback?code=…&state=…'), pending, {
|
|
329
|
+
server: server.data,
|
|
330
|
+
clientId: '<your client id>',
|
|
331
|
+
clientSecret,
|
|
332
|
+
})
|
|
333
|
+
if (!signedIn.ok) throw new Error(`sign-in failed: ${signedIn.error.kind}`)
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
- **The secret goes only in the token request's `Authorization: Basic` header** (RFC 6749 §2.3.1),
|
|
337
|
+
and only to the token endpoint of the `server` you pass. A `pending` that names another server,
|
|
338
|
+
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
|
|
339
|
+
the SDK logs nothing. A `fetch` you pass sees the request, header included: don't log it.
|
|
340
|
+
- **A failure keeps its kind, status and OAuth code** (`invalid_client`, `invalid_grant`, …), but
|
|
341
|
+
not the server's description or body (an empty `message` or `text`): a server or proxy that
|
|
342
|
+
echoes the request would put the credentials there.
|
|
343
|
+
- **Without `clientSecret`,** the sign-in is a public client's, with PKCE alone.
|
|
344
|
+
- **Keep the person signed in with `createSession`** (see "Keeping the person signed in"), passing
|
|
345
|
+
the same `clientSecret`. Its refresh and its revocation then carry the header too, under the same
|
|
346
|
+
rules.
|
|
347
|
+
- **Browser code can't pass a secret:** the main entry's `startSignIn` and `finishSignIn` have no
|
|
348
|
+
option for one. Never put the secret in code a browser loads.
|
|
349
|
+
- **`signInWithLoopback` isn't for this:** it waits on the server's own `127.0.0.1`, which the
|
|
350
|
+
person's browser can't reach. It's for apps on the person's own machine, which hold no secret.
|
|
150
351
|
|
|
151
352
|
## Results, not exceptions
|
|
152
353
|
|
|
@@ -159,7 +360,12 @@ throws the failure as an `ApiFailure` carrying its `error`, for callers who'd ra
|
|
|
159
360
|
- **`fs.catalog.get({ source })`** gives a `CatalogSource`: a source plus `catalogVersion`.
|
|
160
361
|
- **`fs.query(request)`** gives a `QueryResponse`, with `rows` and `lastRow`, and sometimes
|
|
161
362
|
`totals` and `timings`. Only the request's declared fields are sent: `source`, `connection_id`,
|
|
162
|
-
`dimensions`, `metrics`, `filters`, `sort`, `offset` and `rows`.
|
|
363
|
+
`dimensions`, `metrics`, `filters`, `sort`, `offset` and `rows`. A request with any other key,
|
|
364
|
+
`table` included, is `refused` with nothing sent, and `error.fields` names each one, so a
|
|
365
|
+
misspelt field never quietly changes the numbers.
|
|
366
|
+
- **`fs.health()`** gives the planner's answer to `GET /health`, an object of strings
|
|
367
|
+
(`{ status: 'ok' }` today). It works signed out: no token is asked for or sent, so it tells "the
|
|
368
|
+
service is down" from "the sign-in is wrong".
|
|
163
369
|
|
|
164
370
|
**Every answer is checked against the API's spec.** An answer that doesn't match, with a missing
|
|
165
371
|
field or a value of the wrong type, is an `invalid` failure that names the field. It never comes
|
|
@@ -176,7 +382,7 @@ back as data. A field the SDK doesn't know yet is kept.
|
|
|
176
382
|
| `invalid` | Outside the contract: an answer that isn't JSON or doesn't match its type, or a status no API sends |
|
|
177
383
|
| `timeout` | The call's own deadline passed |
|
|
178
384
|
| `aborted` | The caller's `signal` fired |
|
|
179
|
-
| `refused` | Nothing was sent, by rule: a destination that isn't one of the configured hosts over https,
|
|
385
|
+
| `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` |
|
|
180
386
|
| `no_token` | The token function failed, or gave no token. `cause` is what it threw |
|
|
181
387
|
| `cancelled` | The app's own transport cancelled the call, because the session it was made for moved on |
|
|
182
388
|
|
|
@@ -210,7 +416,7 @@ function explain(error: ApiError): string {
|
|
|
210
416
|
case 'cancelled':
|
|
211
417
|
return 'Stopped.'
|
|
212
418
|
case 'refused':
|
|
213
|
-
return 'Not sent.'
|
|
419
|
+
return error.fields === undefined ? 'Not sent.' : `Not sent: unknown field ${error.fields.join(', ')}`
|
|
214
420
|
case 'no_token':
|
|
215
421
|
return 'No token to send.'
|
|
216
422
|
default: {
|
|
@@ -226,8 +432,9 @@ function explain(error: ApiError): string {
|
|
|
226
432
|
- `provider_error`, with the server's `code`: the server ended the sign-in. It's `access_denied`
|
|
227
433
|
when the person declined;
|
|
228
434
|
- `no_code`: the redirect carried no code;
|
|
229
|
-
- `listen_failed` and `
|
|
230
|
-
- `not_a_url`:
|
|
435
|
+
- `listen_failed`, `open_failed` and `paste_failed`: from `signInWithLoopback`;
|
|
436
|
+
- `not_a_url` and `wrong_redirect`: a pasted address that isn't a URL, or isn't this sign-in's
|
|
437
|
+
redirect (`parsePastedRedirect`, or `signInWithLoopback`'s `readPasted`).
|
|
231
438
|
|
|
232
439
|
There, `refused` also covers an issuer that isn't https, and a `pending` that isn't one (from
|
|
233
440
|
storage the app couldn't read back). Nothing is sent for either.
|
|
@@ -257,16 +464,19 @@ await fs.catalog.list({ signal: controller.signal, deadlineMs: 10_000 })
|
|
|
257
464
|
cookies are sent. Plain http to a loopback host needs `allowLocalhostHttp: true`, for development
|
|
258
465
|
only.
|
|
259
466
|
- **Retries:**
|
|
260
|
-
- A read (`catalog`) is tried again after a 408, 429, 502, 503 or 504, or a
|
|
261
|
-
failed, at most twice. It waits as long as `Retry-After` asks, in seconds, or
|
|
467
|
+
- A read (`catalog`, `health`) is tried again after a 408, 429, 502, 503 or 504, or a
|
|
468
|
+
connection that failed, at most twice. It waits as long as `Retry-After` asks, in seconds, or
|
|
469
|
+
500 ms, then 1 s.
|
|
262
470
|
- `query` is never tried again: a timeout at the gateway may already have run on the warehouse.
|
|
263
471
|
- `no_token` and `refused` are never tried again.
|
|
264
472
|
- A wait that wouldn't end before the deadline isn't started.
|
|
265
|
-
- **Deadlines:** 60 s for `query` and 30 s for the rest, every attempt and
|
|
266
|
-
`deadlineMs` sets one call's.
|
|
473
|
+
- **Deadlines:** 60 s for `query`, 10 s for `health` and 30 s for the rest, every attempt and
|
|
474
|
+
wait included. `deadlineMs` sets one call's.
|
|
267
475
|
- **Abort:** `signal` ends a call at once, also while it waits for a token or to try again.
|
|
268
476
|
- **Your own transport:** an app that attaches the token itself passes `{ transport }` instead of
|
|
269
|
-
`token` and `fetch`. Retries and deadlines still apply, above it.
|
|
477
|
+
`token` and `fetch`. Retries and deadlines still apply, above it. `health` carries no token, so
|
|
478
|
+
it never goes through your transport: it goes to the query host, over https, with the global
|
|
479
|
+
`fetch`.
|
|
270
480
|
|
|
271
481
|
## Requirements
|
|
272
482
|
|
|
@@ -274,7 +484,8 @@ await fs.catalog.list({ signal: controller.signal, deadlineMs: 10_000 })
|
|
|
274
484
|
in must be served over https, or from localhost.
|
|
275
485
|
- **ESM.** The package is ES modules only. On these Node versions, `require()` loads it from
|
|
276
486
|
CommonJS too, both entries; Node 22.12 prints an experimental warning when it does.
|
|
277
|
-
- **The types ship in the package,** for both entries.
|
|
487
|
+
- **The types ship in the package,** for both entries. The Node entry's types use Node's own,
|
|
488
|
+
from `@types/node`.
|
|
278
489
|
|
|
279
490
|
## Licence
|
|
280
491
|
|
package/dist/auth/discovery.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface AuthServer {
|
|
|
8
8
|
readonly authorizationEndpoint: string;
|
|
9
9
|
/** Where the code is exchanged for tokens. */
|
|
10
10
|
readonly tokenEndpoint: string;
|
|
11
|
+
/** Where a session is ended (RFC 7009), when the server has one. */
|
|
12
|
+
readonly revocationEndpoint?: string;
|
|
11
13
|
/** The server puts `iss` on every redirect (RFC 9207), so a redirect without one is refused. */
|
|
12
14
|
readonly issuerOnRedirect: boolean;
|
|
13
15
|
}
|
package/dist/auth/discovery.js
CHANGED
|
@@ -7,6 +7,7 @@ const zMetadata = z.looseObject({
|
|
|
7
7
|
issuer: z.string(),
|
|
8
8
|
authorization_endpoint: z.string(),
|
|
9
9
|
token_endpoint: z.string(),
|
|
10
|
+
revocation_endpoint: z.string().exactOptional(),
|
|
10
11
|
code_challenge_methods_supported: z.array(z.string()).exactOptional(),
|
|
11
12
|
authorization_response_iss_parameter_supported: z.boolean().exactOptional(),
|
|
12
13
|
});
|
|
@@ -41,6 +42,7 @@ export async function discover(issuer, options = {}) {
|
|
|
41
42
|
issuer: doc.issuer,
|
|
42
43
|
authorizationEndpoint: doc.authorization_endpoint,
|
|
43
44
|
tokenEndpoint: doc.token_endpoint,
|
|
45
|
+
...(doc.revocation_endpoint === undefined ? {} : { revocationEndpoint: doc.revocation_endpoint }),
|
|
44
46
|
issuerOnRedirect: doc.authorization_response_iss_parameter_supported === true,
|
|
45
47
|
},
|
|
46
48
|
};
|
|
@@ -59,7 +61,8 @@ function problemWith(doc, issuer) {
|
|
|
59
61
|
// Identical, as §3.3 says: a redirect's `iss` is later held to this very string (RFC 9207).
|
|
60
62
|
if (doc.issuer !== issuer)
|
|
61
63
|
return 'the metadata names another issuer';
|
|
62
|
-
|
|
64
|
+
const endpoints = [doc.authorization_endpoint, doc.token_endpoint, ...(doc.revocation_endpoint === undefined ? [] : [doc.revocation_endpoint])];
|
|
65
|
+
if (!endpoints.every(isHttpsUrl))
|
|
63
66
|
return 'an endpoint is not an https URL';
|
|
64
67
|
if (doc.code_challenge_methods_supported?.includes('S256') !== true)
|
|
65
68
|
return 'the server does not list PKCE S256';
|
|
@@ -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,UAAU,EAAwB,MAAM,gBAAgB,CAAA;
|
|
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,UAAU,EAAwB,MAAM,gBAAgB,CAAA;AAgBhF,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;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC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C,mBAAmB,EAAE,CAAC;YACjG,gBAAgB,EAAE,GAAG,CAAC,8CAA8C,KAAK,IAAI;SAC9E;KACF,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3B,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACzE,GAAG,CAAC,QAAQ,GAAG,0CAA0C,IAAI,EAAE,CAAA;IAC/D,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,GAA8B,EAAE,MAAc;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,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO,iCAAiC,CAAA;IAC1E,IAAI,GAAG,CAAC,gCAAgC,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,IAAI;QAAE,OAAO,oCAAoC,CAAA;IAChH,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/auth/signIn.d.ts
CHANGED
|
@@ -89,9 +89,18 @@ export declare function readCallback(callbackUrl: string | URL, pending: Pending
|
|
|
89
89
|
readonly kind: 'code';
|
|
90
90
|
readonly code: string;
|
|
91
91
|
} | CallbackError;
|
|
92
|
+
/** A pending sign-in as `startSignIn` makes one, checked: it comes back from the app's storage. */
|
|
93
|
+
export declare const isPendingSignIn: (value: unknown) => value is PendingSignIn;
|
|
92
94
|
/**
|
|
93
95
|
* Finishes a sign-in: the redirect is read (`readCallback`), and only then is its code exchanged
|
|
94
|
-
* for tokens, once
|
|
95
|
-
* storage the app couldn't read back) is `refused`, with nothing sent.
|
|
96
|
+
* for tokens, once (`tokenCall`). A `pending` that isn't one (from
|
|
97
|
+
* storage the app couldn't read back) is `refused`, with nothing sent. A public client's: an app
|
|
98
|
+
* with a server signs in as a confidential client with `@flipstream/sdk/node`'s `finishSignIn`.
|
|
96
99
|
*/
|
|
97
100
|
export declare function finishSignIn(callbackUrl: string | URL, pending: PendingSignIn, options?: AuthCallOptions): Promise<SignInResult>;
|
|
101
|
+
/**
|
|
102
|
+
* `finishSignIn`'s work, with `authorization` as the token request's Authorization header when
|
|
103
|
+
* the app authenticates as a confidential client (only `@flipstream/sdk/node` makes one). The main
|
|
104
|
+
* entry never exports this, so browser code has no way to send client credentials.
|
|
105
|
+
*/
|
|
106
|
+
export declare function exchangeCode(callbackUrl: string | URL, pending: PendingSignIn, options: AuthCallOptions, authorization?: string): Promise<SignInResult>;
|
package/dist/auth/signIn.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
3
|
import { challengeOf, randomValue } from './pkce.js';
|
|
4
|
+
import { tokenCall } from './tokenEndpoint.js';
|
|
4
5
|
import { authTransport, isHttpsUrl } from './transport.js';
|
|
5
6
|
const nonEmpty = (value) => typeof value === 'string' && value !== '';
|
|
6
7
|
/**
|
|
@@ -73,47 +74,38 @@ const zPending = z.object({
|
|
|
73
74
|
tokenEndpoint: z.string().refine(isHttpsUrl),
|
|
74
75
|
issuerOnRedirect: z.boolean(),
|
|
75
76
|
});
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
access_token: z.string().min(1),
|
|
79
|
-
token_type: z.string().refine((type) => type.toLowerCase() === 'bearer', 'the token type is not bearer'),
|
|
80
|
-
expires_in: z.int().nonnegative().exactOptional(),
|
|
81
|
-
refresh_token: z.string().exactOptional(),
|
|
82
|
-
scope: z.string().exactOptional(),
|
|
83
|
-
});
|
|
77
|
+
/** A pending sign-in as `startSignIn` makes one, checked: it comes back from the app's storage. */
|
|
78
|
+
export const isPendingSignIn = (value) => zPending.safeParse(value).success;
|
|
84
79
|
/**
|
|
85
80
|
* Finishes a sign-in: the redirect is read (`readCallback`), and only then is its code exchanged
|
|
86
|
-
* for tokens, once
|
|
87
|
-
* storage the app couldn't read back) is `refused`, with nothing sent.
|
|
81
|
+
* for tokens, once (`tokenCall`). A `pending` that isn't one (from
|
|
82
|
+
* storage the app couldn't read back) is `refused`, with nothing sent. A public client's: an app
|
|
83
|
+
* with a server signs in as a confidential client with `@flipstream/sdk/node`'s `finishSignIn`.
|
|
88
84
|
*/
|
|
89
|
-
export
|
|
90
|
-
|
|
85
|
+
export function finishSignIn(callbackUrl, pending, options = {}) {
|
|
86
|
+
return exchangeCode(callbackUrl, pending, options);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* `finishSignIn`'s work, with `authorization` as the token request's Authorization header when
|
|
90
|
+
* the app authenticates as a confidential client (only `@flipstream/sdk/node` makes one). The main
|
|
91
|
+
* entry never exports this, so browser code has no way to send client credentials.
|
|
92
|
+
*/
|
|
93
|
+
export async function exchangeCode(callbackUrl, pending, options, authorization) {
|
|
94
|
+
if (!isPendingSignIn(pending) || !URL.canParse(callbackUrl))
|
|
91
95
|
return { ok: false, error: { kind: 'refused' } };
|
|
92
96
|
const callback = readCallback(callbackUrl, pending);
|
|
93
97
|
if (callback.kind !== 'code')
|
|
94
98
|
return { ok: false, error: callback };
|
|
95
|
-
const form =
|
|
99
|
+
const form = {
|
|
96
100
|
grant_type: 'authorization_code',
|
|
97
101
|
code: callback.code,
|
|
98
102
|
redirect_uri: pending.redirectUri,
|
|
99
103
|
client_id: pending.clientId,
|
|
100
104
|
code_verifier: pending.verifier,
|
|
101
|
-
}
|
|
105
|
+
};
|
|
102
106
|
// Before the request, so the expiry is never later than the server's own.
|
|
103
107
|
const sentAt = Date.now();
|
|
104
|
-
const answer = await call(authTransport(options),
|
|
105
|
-
effect: 'write',
|
|
106
|
-
service: 'auth',
|
|
107
|
-
endpoint: 'auth.token',
|
|
108
|
-
makeRequest: () => new Request(pending.tokenEndpoint, {
|
|
109
|
-
method: 'POST',
|
|
110
|
-
headers: { accept: 'application/json', 'content-type': 'application/x-www-form-urlencoded' },
|
|
111
|
-
body: form.toString(),
|
|
112
|
-
}),
|
|
113
|
-
schema: zTokenAnswer,
|
|
114
|
-
deadlineMs: 30_000,
|
|
115
|
-
retry: 'never',
|
|
116
|
-
}, options.signal);
|
|
108
|
+
const answer = await call(authTransport(options), tokenCall('auth.token', pending.tokenEndpoint, form, 30_000, authorization), options.signal);
|
|
117
109
|
if (!answer.ok)
|
|
118
110
|
return answer;
|
|
119
111
|
const { access_token, expires_in, refresh_token, scope } = answer.data;
|
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,aAAa,EAAE,UAAU,EAAwB,MAAM,gBAAgB,CAAA;AAoEhF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAA;AAE/F;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAsB;IACtD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,E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M,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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { CallSpec } from '../core/call.js';
|
|
3
|
+
declare const zTokenAnswer: z.ZodObject<{
|
|
4
|
+
access_token: z.ZodString;
|
|
5
|
+
token_type: z.ZodString;
|
|
6
|
+
expires_in: z.ZodExactOptional<z.ZodInt>;
|
|
7
|
+
refresh_token: z.ZodExactOptional<z.ZodString>;
|
|
8
|
+
scope: z.ZodExactOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$loose>;
|
|
10
|
+
export type TokenAnswer = z.infer<typeof zTokenAnswer>;
|
|
11
|
+
/**
|
|
12
|
+
* One POST to the token endpoint, form-encoded, with no token of its own (a public client sends
|
|
13
|
+
* none). Never tried again: a code is good once, and a refresh token resent after an answer that
|
|
14
|
+
* was lost on the way counts as reuse. `authorization` is a confidential client's own header
|
|
15
|
+
* (client_secret_basic, made only in `@flipstream/sdk/node`); the only header a caller can add.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tokenCall(endpoint: 'auth.token' | 'auth.refresh', tokenEndpoint: string, form: Record<string, string>, deadlineMs: number, authorization?: string): CallSpec<TokenAnswer>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// RFC 6749 §5.1. Kept loose: the server's own fields (`id_token`, `refresh_expires_in`) pass by.
|
|
3
|
+
const zTokenAnswer = z.looseObject({
|
|
4
|
+
access_token: z.string().min(1),
|
|
5
|
+
token_type: z.string().refine((type) => type.toLowerCase() === 'bearer', 'the token type is not bearer'),
|
|
6
|
+
expires_in: z.int().nonnegative().exactOptional(),
|
|
7
|
+
refresh_token: z.string().exactOptional(),
|
|
8
|
+
scope: z.string().exactOptional(),
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* One POST to the token endpoint, form-encoded, with no token of its own (a public client sends
|
|
12
|
+
* none). Never tried again: a code is good once, and a refresh token resent after an answer that
|
|
13
|
+
* was lost on the way counts as reuse. `authorization` is a confidential client's own header
|
|
14
|
+
* (client_secret_basic, made only in `@flipstream/sdk/node`); the only header a caller can add.
|
|
15
|
+
*/
|
|
16
|
+
export function tokenCall(endpoint, tokenEndpoint, form, deadlineMs, authorization) {
|
|
17
|
+
const body = new URLSearchParams(form).toString();
|
|
18
|
+
return {
|
|
19
|
+
effect: 'write',
|
|
20
|
+
service: 'auth',
|
|
21
|
+
endpoint,
|
|
22
|
+
makeRequest: () => new Request(tokenEndpoint, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: {
|
|
25
|
+
accept: 'application/json',
|
|
26
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
27
|
+
...(authorization === undefined ? {} : { authorization }),
|
|
28
|
+
},
|
|
29
|
+
body,
|
|
30
|
+
}),
|
|
31
|
+
schema: zTokenAnswer,
|
|
32
|
+
deadlineMs,
|
|
33
|
+
retry: 'never',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=tokenEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenEndpoint.js","sourceRoot":"","sources":["../../src/auth/tokenEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,iGAAiG;AACjG,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC;IACjC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,QAAQ,EAAE,8BAA8B,CAAC;IACxG,UAAU,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,aAAa,EAAE;IACjD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,aAAa,EAAE;IACzC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,aAAa,EAAE;CAClC,CAAC,CAAA;AAIF;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,QAAuC,EACvC,aAAqB,EACrB,IAA4B,EAC5B,UAAkB,EAClB,aAAsB;IAEtB,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;IACjD,OAAO;QACL,MAAM,EAAE,OAAO;QACf,OAAO,EAAE,MAAM;QACf,QAAQ;QACR,WAAW,EAAE,GAAG,EAAE,CAChB,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,mCAAmC;gBACnD,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC;aAC1D;YACD,IAAI;SACL,CAAC;QACJ,MAAM,EAAE,YAAY;QACpB,UAAU;QACV,KAAK,EAAE,OAAO;KACf,CAAA;AACH,CAAC"}
|
package/dist/core/fetch.d.ts
CHANGED
|
@@ -20,6 +20,14 @@ declare const ABORTED: {
|
|
|
20
20
|
readonly kind: "aborted";
|
|
21
21
|
};
|
|
22
22
|
export declare function fetchTransport(options: FetchTransportOptions): Transport;
|
|
23
|
+
/** The default transport's options, less the token function. */
|
|
24
|
+
export type TokenlessTransportOptions = Omit<FetchTransportOptions, 'token'>;
|
|
25
|
+
/**
|
|
26
|
+
* The default transport without a token, for `GET /health` (#111): the same destinations and the
|
|
27
|
+
* same send, but it asks no token function and adds no `authorization` header, so it works
|
|
28
|
+
* signed out. It never resends after a 401: there is no token to renew.
|
|
29
|
+
*/
|
|
30
|
+
export declare function tokenlessTransport(options: TokenlessTransportOptions): Transport;
|
|
23
31
|
/**
|
|
24
32
|
* One request out, as every transport of the SDK's own sends it (sign-in's too, #63), with
|
|
25
33
|
* `headers` in place of `built`'s. Nothing is sent once `signal` has fired. No cookies, and no
|