@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
|
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { Socket } from 'node:net';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
+
import { deadlineIn, MAX_TIMER_MS } from '../core/deadline.js';
|
|
5
6
|
import { TIMINGS } from './fileLock.js';
|
|
6
7
|
import { KeychainError, refusalKind } from './keychainError.js';
|
|
7
8
|
import { parse, storeOf } from './store.js';
|
|
@@ -26,8 +27,6 @@ function childScript() {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
const TIMEOUT_MS = 30_000;
|
|
29
|
-
// setTimeout's ceiling: a longer delay is cut to 1 ms, which would end every step at once.
|
|
30
|
-
const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
31
30
|
/**
|
|
32
31
|
* The most a saved secret may hold, on every platform: Windows' Credential Manager keeps at most
|
|
33
32
|
* 2,560 bytes (CRED_MAX_CREDENTIAL_BLOB_SIZE). The macOS keychain and the Secret Service set no
|
|
@@ -59,13 +58,16 @@ const AFTER_PARENT_MS = TIMINGS.oldWatchMs - TIMINGS.touchMs - 1_000;
|
|
|
59
58
|
* `fileStore` there.
|
|
60
59
|
* - **Its steps run in one helper process,** one at a time: started by the first step and kept warm
|
|
61
60
|
* while the app runs, for every keychain store of the process. A step past its `timeoutMs` (30 s)
|
|
62
|
-
* kills it, and the next step starts another.
|
|
63
|
-
*
|
|
64
|
-
* or
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
61
|
+
* kills it, and the next step starts another. On macOS and Linux it ignores a terminal Ctrl-C,
|
|
62
|
+
* the terminal closing, and every SIGTERM, whether to the app's process group (from a supervisor,
|
|
63
|
+
* say) or to the helper alone, from before its own code loads, though not during Node's start-up
|
|
64
|
+
* or a preload in `NODE_OPTIONS`. On Windows, Node ends a process at once on a SIGTERM. SIGQUIT,
|
|
65
|
+
* SIGKILL and every other signal whose default is to end a process still end it: to end a stuck
|
|
66
|
+
* helper, send it SIGKILL. A step whose helper died before it answered runs once more on a fresh
|
|
67
|
+
* one, within its `timeoutMs`. It never keeps the app running. When the app ends, it ends too: at
|
|
68
|
+
* once when idle or on a read, or once the save or delete it's on is done, within that step's
|
|
69
|
+
* `timeoutMs` and 1 s at most, so a refresh's save isn't lost to a Ctrl-C, a closed terminal or a
|
|
70
|
+
* SIGTERM. 1 s is less than the soonest `fileLock` lets another process take the app's lock. For
|
|
69
71
|
* a helper's first step, the 1 s counts from the helper's own start, so a slow start can't
|
|
70
72
|
* stretch it, and that step may be cut sooner. It is `process.execPath`, so it needs a Node that
|
|
71
73
|
* runs a script: not an Electron app (without `ELECTRON_RUN_AS_NODE`), a Node single-executable
|
|
@@ -83,13 +85,13 @@ export function keychainStore(options) {
|
|
|
83
85
|
* real store does, never less, and never none.
|
|
84
86
|
*/
|
|
85
87
|
export function createKeychainStore(options, { afterParentMs }) {
|
|
86
|
-
if (!Number.isInteger(afterParentMs) || afterParentMs < AFTER_PARENT_MS || afterParentMs >
|
|
87
|
-
throw new TypeError(`afterParentMs must be a whole number of ms, from ${AFTER_PARENT_MS} to ${
|
|
88
|
+
if (!Number.isInteger(afterParentMs) || afterParentMs < AFTER_PARENT_MS || afterParentMs > MAX_TIMER_MS)
|
|
89
|
+
throw new TypeError(`afterParentMs must be a whole number of ms, from ${AFTER_PARENT_MS} to ${MAX_TIMER_MS}`);
|
|
88
90
|
const { service, account, timeoutMs = TIMEOUT_MS } = options;
|
|
89
91
|
if (service === '' || account === '')
|
|
90
92
|
throw new TypeError('the keychain store needs a service and an account');
|
|
91
|
-
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs >
|
|
92
|
-
throw new TypeError(`timeoutMs must be a whole number of ms, from 1 to ${
|
|
93
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_MS)
|
|
94
|
+
throw new TypeError(`timeoutMs must be a whole number of ms, from 1 to ${MAX_TIMER_MS}`);
|
|
93
95
|
const item = { service, account };
|
|
94
96
|
return storeOf(`keychain:${JSON.stringify([service, account])}`, async () => {
|
|
95
97
|
const saved = await inChild({ op: 'get', ...item }, timeoutMs, afterParentMs);
|
|
@@ -133,7 +135,11 @@ function inChild(request, timeoutMs, afterParentMs) {
|
|
|
133
135
|
if (script === undefined)
|
|
134
136
|
return Promise.reject(new KeychainError("the keychain store can't find its child script, keychainChild.js: this module's import.meta.url is empty, as a CommonJS bundle may leave it", { kind: 'helper', exit: null }));
|
|
135
137
|
return new Promise((resolve, reject) => {
|
|
136
|
-
|
|
138
|
+
// On the monotonic clock, as the timer below is, so the two agree. By the wall clock, a step
|
|
139
|
+
// forward (a clock change, a virtual machine resuming), or a laptop waking where the monotonic
|
|
140
|
+
// clock skips sleep (Linux), made a queued step look expired while its timer still ran, and
|
|
141
|
+
// failed it unsent (#157 item 10). The SDK's one deadline (#333).
|
|
142
|
+
const deadline = deadlineIn(timeoutMs);
|
|
137
143
|
let settled = false;
|
|
138
144
|
// The helper this step was sent to, once it was: stuck on it if the deadline passes.
|
|
139
145
|
let sentTo = null;
|
|
@@ -146,7 +152,7 @@ function inChild(request, timeoutMs, afterParentMs) {
|
|
|
146
152
|
};
|
|
147
153
|
const late = () => {
|
|
148
154
|
settle(() => {
|
|
149
|
-
reject(new KeychainError(`the keychain didn't answer within ${timeoutMs / 1000} s`, { kind: 'timeout', timeoutMs }));
|
|
155
|
+
reject(new KeychainError(`the keychain didn't answer within ${timeoutMs / 1000} s`, { kind: 'timeout', timeout_ms: timeoutMs }));
|
|
150
156
|
});
|
|
151
157
|
};
|
|
152
158
|
const timer = setTimeout(() => {
|
|
@@ -155,31 +161,46 @@ function inChild(request, timeoutMs, afterParentMs) {
|
|
|
155
161
|
late();
|
|
156
162
|
}, timeoutMs);
|
|
157
163
|
// Exactly once more, on a fresh helper and within the same deadline, when the first helper
|
|
158
|
-
// closed before it answered: one that crashed, died while idle,
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
//
|
|
164
|
+
// closed before it answered: one that crashed, died while idle, was killed on its own (a
|
|
165
|
+
// SIGKILL to the helper alone, say), or died of another signal whose default ends a process
|
|
166
|
+
// (SIGALRM, say). A Ctrl-C, a closed terminal and a SIGTERM aren't among those: the helper
|
|
167
|
+
// ignores all three (#169; SIGHUP, #157 item 9; SIGTERM, #352). Every step is safe to repeat: a
|
|
168
|
+
// read or a delete changes nothing twice, and a save writes the same tokens again.
|
|
162
169
|
const turn = async () => {
|
|
163
170
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
164
171
|
if (settled)
|
|
165
172
|
return;
|
|
166
173
|
// By the clock as well as the timer: a thread blocked past the deadline gives this turn
|
|
167
174
|
// first, before the overdue timer has run, and a step that late is never sent.
|
|
168
|
-
if (
|
|
175
|
+
if (deadline.passed()) {
|
|
169
176
|
late();
|
|
170
177
|
return;
|
|
171
178
|
}
|
|
172
|
-
const
|
|
179
|
+
const warm = helpers.get(afterParentMs);
|
|
180
|
+
const current = warm ?? startHelper(script);
|
|
173
181
|
if (current instanceof Error) {
|
|
174
182
|
settle(() => {
|
|
175
183
|
reject(current);
|
|
176
184
|
});
|
|
177
185
|
return;
|
|
178
186
|
}
|
|
187
|
+
// And again once its helper is there: starting one holds the thread too, and a step it held
|
|
188
|
+
// past the deadline is never sent either. A helper started for it is stopped, never left idle:
|
|
189
|
+
// the helper counts its first request's 1 s from its own start (#157 item 15), so one kept
|
|
190
|
+
// warm would have its first save cut at once if its app then went.
|
|
191
|
+
if (deadline.passed()) {
|
|
192
|
+
if (current !== warm)
|
|
193
|
+
stop(current);
|
|
194
|
+
late();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
179
197
|
helpers.set(afterParentMs, current);
|
|
180
198
|
sentTo = current;
|
|
181
|
-
// With its time left, which the helper keeps to if this process ends while it's on the step
|
|
182
|
-
|
|
199
|
+
// With its time left, which the helper keeps to if this process ends while it's on the step:
|
|
200
|
+
// whole ms, as the helper takes them, rounded down. The check above passed only with 1 ms or
|
|
201
|
+
// more left, so the floor of 1 the helper's schema needs is reached only if the last ms ran
|
|
202
|
+
// out since.
|
|
203
|
+
const answer = await ask(current, { id: ++lastId, msLeft: Math.max(1, deadline.left()), afterParentMs, parent: process.pid, ...request });
|
|
183
204
|
sentTo = null;
|
|
184
205
|
if (answer instanceof HelperClosed && attempt === 1)
|
|
185
206
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keychainStore.js","sourceRoot":"","sources":["../../src/node/keychainStore.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,+FAA+F;AAC/F,mGAAmG;AACnG,gEAAgE;AAChE,SAAS,IAAI,CAAC,EAAU;IACtB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;IACd,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;IACd,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAA;AAClB,CAAC;AAED,SAAS,IAAI,CAAC,EAAU;IACtB,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAChB,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAChB,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;AACpB,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACxC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACjD,CAAC"}
|
package/dist/node/loopback.d.ts
CHANGED
|
@@ -21,7 +21,14 @@ export interface LoopbackSignInOptions extends Omit<SignInRequest, 'redirectUri'
|
|
|
21
21
|
readonly signedIn: string;
|
|
22
22
|
readonly failed: string;
|
|
23
23
|
};
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* How long to wait for a redirect, on the port or pasted, from when the person is shown where to
|
|
26
|
+
* sign in: 5 minutes when left out or `null`. Taken in whole ms, rounded down, up to 2147483647,
|
|
27
|
+
* the most a timer holds, as a call's `deadlineMs` is. One that can't be a wait (not a number, NaN,
|
|
28
|
+
* ±Infinity, or more than that once rounded down) is a TypeError, with no port opened. One under
|
|
29
|
+
* 1 ms ends as `timeout`, with no port opened and nothing shown, once `server`, `clientId` and
|
|
30
|
+
* `scopes` pass the checks a sign-in makes: a mistake in them is still a TypeError.
|
|
31
|
+
*/
|
|
25
32
|
readonly timeoutMs?: number;
|
|
26
33
|
}
|
|
27
34
|
export type LoopbackError = SignInError
|
package/dist/node/loopback.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
2
|
import { finishSignIn, startSignIn } from '../auth/signIn.js';
|
|
3
|
+
import { callerWaitMs } from '../core/deadline.js';
|
|
3
4
|
import { parsePastedRedirect } from './headless.js';
|
|
4
5
|
const WAIT_MS = 300_000;
|
|
5
6
|
const PAGE = (heading, text) => `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>${heading}</title></head>` +
|
|
@@ -19,10 +20,26 @@ const asError = (error) => (error instanceof Error ? error : new Error(String(er
|
|
|
19
20
|
*/
|
|
20
21
|
export async function signInWithLoopback(options) {
|
|
21
22
|
const { signal, readPasted } = options;
|
|
23
|
+
// As a call's deadlineMs, by the one rule (callerWaitMs, #340, #344): a wait no timer can keep is a
|
|
24
|
+
// TypeError before any port opens, and a spent one is runtime data, ended below as the sign-in's
|
|
25
|
+
// own timeout.
|
|
26
|
+
const waitMs = callerWaitMs('signInWithLoopback: timeoutMs', options.timeoutMs, WAIT_MS);
|
|
22
27
|
// A function, so each look reads the signal as it is now, past the awaits between them.
|
|
23
28
|
const aborted = () => signal?.aborted === true;
|
|
24
29
|
if (aborted())
|
|
25
30
|
return { ok: false, error: { kind: 'aborted' } };
|
|
31
|
+
if (waitMs < 1) {
|
|
32
|
+
// No time to wait: nobody could sign in, so no port opens and nothing is shown. The app's own
|
|
33
|
+
// arguments are checked first, by startSignIn itself, so every check of its runs, the use of
|
|
34
|
+
// server.authorization_endpoint included, and a programming error is never told as a timeout
|
|
35
|
+
// (#345's code review, 1; round 2, O2.F1). It does no I/O: random values and a hash. Its
|
|
36
|
+
// result is dropped; the redirect is the loopback's own shape, an absolute URL.
|
|
37
|
+
await startSignIn({ server: options.server, clientId: options.clientId, scopes: options.scopes, redirectUri: 'http://127.0.0.1/callback' });
|
|
38
|
+
// An abort during its hash fired no event this could hear, as on the port's path below (O3.F1).
|
|
39
|
+
if (aborted())
|
|
40
|
+
return { ok: false, error: { kind: 'aborted' } };
|
|
41
|
+
return { ok: false, error: { kind: 'timeout' } };
|
|
42
|
+
}
|
|
26
43
|
const pages = options.page ?? PAGES;
|
|
27
44
|
const listening = await listenOnLoopback();
|
|
28
45
|
if (!listening.ok)
|
|
@@ -72,7 +89,7 @@ export async function signInWithLoopback(options) {
|
|
|
72
89
|
};
|
|
73
90
|
timer = setTimeout(() => {
|
|
74
91
|
endWait({ kind: 'timeout' });
|
|
75
|
-
},
|
|
92
|
+
}, waitMs);
|
|
76
93
|
onAbort = () => {
|
|
77
94
|
if (phase !== 'done')
|
|
78
95
|
settle({ ok: false, error: { kind: 'aborted' } });
|
|
@@ -118,7 +135,7 @@ export async function signInWithLoopback(options) {
|
|
|
118
135
|
return;
|
|
119
136
|
const pasted = parsePastedRedirect(typeof text === 'string' ? text : '', pending);
|
|
120
137
|
if (pasted.ok)
|
|
121
|
-
exchange(pasted.
|
|
138
|
+
exchange(pasted.callback_url).then(exchanged, fail);
|
|
122
139
|
else
|
|
123
140
|
endWait(pasted.error);
|
|
124
141
|
}, (cause) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopback.js","sourceRoot":"","sources":["../../src/node/loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAA;AAEhG,OAAO,EAAE,YAAY,EAAE,WAAW,EAAwE,MAAM,mBAAmB,CAAA;AAEnI,OAAO,EAAE,mBAAmB,EAAuB,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"loopback.js","sourceRoot":"","sources":["../../src/node/loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAA;AAEhG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OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/node/session.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { type AuthServer } from '../auth/discovery.js';
|
|
|
4
4
|
import type { Tokens } from '../auth/signIn.js';
|
|
5
5
|
import { type AuthCallOptions } from '../auth/transport.js';
|
|
6
6
|
/** What the app's store holds: `finishSignIn`'s tokens fit. */
|
|
7
|
-
export type SessionTokens = Pick<Tokens, '
|
|
7
|
+
export type SessionTokens = Pick<Tokens, 'access_token' | 'refresh_token' | 'expires_at'>;
|
|
8
8
|
/**
|
|
9
9
|
* New tokens from a refresh, for the app to save before anything uses them, or the end of the
|
|
10
10
|
* session. `replaces` is the store's key when the refresh began (D472): its refresh token, or its
|
|
11
|
-
* access token when it has none or an empty one, as `
|
|
11
|
+
* access token when it has none or an empty one, as `refresh_token || access_token`. Write only while
|
|
12
12
|
* the store's key is still `replaces` (compare and set, or delete), so a refresh of an old session
|
|
13
13
|
* never overwrites a newer sign-in that another process saved meanwhile.
|
|
14
14
|
*/
|
|
@@ -16,9 +16,9 @@ export type TokenUpdate =
|
|
|
16
16
|
/** A new refresh token came: save both. The one sent is spent. */
|
|
17
17
|
{
|
|
18
18
|
readonly kind: 'rotated';
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
19
|
+
readonly access_token: string;
|
|
20
|
+
readonly refresh_token: string;
|
|
21
|
+
readonly expires_at?: number;
|
|
22
22
|
readonly replaces: string;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -28,8 +28,8 @@ export type TokenUpdate =
|
|
|
28
28
|
*/
|
|
29
29
|
| {
|
|
30
30
|
readonly kind: 'access-only';
|
|
31
|
-
readonly
|
|
32
|
-
readonly
|
|
31
|
+
readonly access_token: string;
|
|
32
|
+
readonly expires_at?: number;
|
|
33
33
|
readonly replaces: string;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -84,7 +84,15 @@ export type SessionOptions = Pick<AuthCallOptions, 'fetch' | 'allowLocalhostHttp
|
|
|
84
84
|
/**
|
|
85
85
|
* The tokens as the store holds them now, or null when nobody is signed in. Read again before
|
|
86
86
|
* every refresh, so the refresh token sent is the current one, even after another process
|
|
87
|
-
* rotated it, and again just before a refresh's answer is saved.
|
|
87
|
+
* rotated it, and again just before a refresh's answer is saved. Their fields are snake_case
|
|
88
|
+
* since the snake rename (#353, D569). A store of your own converts the records that releases
|
|
89
|
+
* before the rename saved in camelCase, with `fromEarlierTokenNames`, in the same change that
|
|
90
|
+
* renames its `onTokens` fields: a refresh refuses one that still holds those names
|
|
91
|
+
* (`store_failed`, at the read), before anything is sent or spent. A sign-out clears through
|
|
92
|
+
* your own `onTokens`, so convert the stored record first: until you do, `revoke()` still
|
|
93
|
+
* revokes the right refresh token, but its clear comes back `cleared: 'kept'` and the old record
|
|
94
|
+
* stays. `keychainStore` and `fileStore` read those names themselves, until a later breaking
|
|
95
|
+
* release.
|
|
88
96
|
*
|
|
89
97
|
* The store's contract (D457): this returns only what `onTokens` has durably saved. Write first,
|
|
90
98
|
* make visible second, so no reader, in this process or another, ever sees tokens whose save
|
|
@@ -98,7 +106,7 @@ export type SessionOptions = Pick<AuthCallOptions, 'fetch' | 'allowLocalhostHttp
|
|
|
98
106
|
readonly tokens: () => SessionTokens | null | Promise<SessionTokens | null>;
|
|
99
107
|
/**
|
|
100
108
|
* Saves a refresh's tokens, or clears them once the session is over, only while the store's key
|
|
101
|
-
* (`
|
|
109
|
+
* (`refresh_token || access_token`) is still `update.replaces`. The session reads the
|
|
102
110
|
* store again just before, and lets the answer go when the store has moved on (a newer sign-in,
|
|
103
111
|
* or a sign-out); comparing and setting on `replaces` closes the moment between that read and
|
|
104
112
|
* this write, and a store that refuses then throws a `StoreMovedOnError`: a sign-out reads it as
|
package/dist/node/session.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { call } from '../core/call.js';
|
|
3
|
-
import {
|
|
3
|
+
import { deadlineIn, MAX_TIMER_MS, wallClock } from '../core/deadline.js';
|
|
4
|
+
import { discover, serverProblem } from '../auth/discovery.js';
|
|
4
5
|
import { tokenCall } from '../auth/tokenEndpoint.js';
|
|
5
6
|
import { authTransport, endpointProblem, isSignInUrl } from '../auth/transport.js';
|
|
6
7
|
import { clientAuthorization, vouched } from './clientSecret.js';
|
|
7
|
-
import { StoreMovedOnError } from './store.js';
|
|
8
|
+
import { readTokens, StoreMovedOnError } from './store.js';
|
|
8
9
|
/** Thrown by `session.token()`; the default transport turns it into `no_token`, with this as its `cause`. */
|
|
9
10
|
export class SessionError extends Error {
|
|
10
11
|
failure;
|
|
@@ -16,8 +17,6 @@ export class SessionError extends Error {
|
|
|
16
17
|
}
|
|
17
18
|
/** A caller waits this long for a token unless `waitMs` says otherwise, then gets `unavailable` (the os's `refresh.ts`). */
|
|
18
19
|
const WAIT_MS = 15_000;
|
|
19
|
-
/** The longest wait a timer takes: past this, setTimeout fires at once. */
|
|
20
|
-
const MAX_TIMER_MS = 2_147_483_647;
|
|
21
20
|
/** The refresh's own limit: past the callers' wait, so a slow answer is still saved. */
|
|
22
21
|
const REFRESH_DEADLINE_MS = 60_000;
|
|
23
22
|
/** A revocation's own limit, the lock's wait and the store's read included. */
|
|
@@ -33,12 +32,8 @@ const SEND_FLOOR_MS = 5_000;
|
|
|
33
32
|
* and at most this for each of its store calls; then it gives up, touching nothing more (D487).
|
|
34
33
|
*/
|
|
35
34
|
const SIGN_OUT_WAIT_MS = 60_000;
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
accessToken: z.string().min(1),
|
|
39
|
-
refreshToken: z.string().optional(),
|
|
40
|
-
expiresAt: z.number().optional(),
|
|
41
|
-
});
|
|
35
|
+
// Why a refresh refuses a record of the app's own store in the earlier names.
|
|
36
|
+
const EARLIER_NAMES = "the stored tokens use the camelCase names of releases before the snake rename (D569): convert the store's records with fromEarlierTokenNames";
|
|
42
37
|
const failedAt = (step, cause) => ({ cleared: 'failed', failure: { step, cause } });
|
|
43
38
|
const SIGNED_OUT = { kind: 'signed-out' };
|
|
44
39
|
const UNAVAILABLE = { kind: 'unavailable' };
|
|
@@ -50,8 +45,11 @@ export function createSession(options) {
|
|
|
50
45
|
throw new TypeError(options.allowLocalhostHttp === true ? 'createSession: issuer must be an https URL, or an http one on this machine' : 'createSession: issuer must be an https URL');
|
|
51
46
|
}
|
|
52
47
|
const given = options.server;
|
|
48
|
+
const problem = given === undefined ? null : serverProblem(given);
|
|
49
|
+
if (problem !== null)
|
|
50
|
+
throw new TypeError(`createSession: ${problem}: pass discover()'s answer, in its snake_case names (D569)`);
|
|
53
51
|
if (options.allowLocalhostHttp === true && given !== undefined) {
|
|
54
|
-
const endpoints = [given.
|
|
52
|
+
const endpoints = [given.authorization_endpoint, given.token_endpoint, ...(given.revocation_endpoint === undefined ? [] : [given.revocation_endpoint])];
|
|
55
53
|
if (endpointProblem(given.issuer, endpoints) !== null)
|
|
56
54
|
throw new TypeError("createSession: the server's endpoints must be https, or for an http issuer on this machine, on its origin");
|
|
57
55
|
}
|
|
@@ -104,10 +102,12 @@ export function createSession(options) {
|
|
|
104
102
|
try {
|
|
105
103
|
const stored = await options.tokens();
|
|
106
104
|
if (stored === null)
|
|
107
|
-
return { ok: true, tokens: null };
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
return { ok: true, tokens: null, earlier: false };
|
|
106
|
+
// By the SDK's one rule (store.ts `readTokens`), which the ready-made stores read by too.
|
|
107
|
+
const read = readTokens(stored);
|
|
108
|
+
if (read.ok)
|
|
109
|
+
return { ok: true, tokens: read.tokens, earlier: read.earlier };
|
|
110
|
+
return { ok: false, failure: { kind: 'store_failed', step: 'read', cause: new TypeError(`the stored tokens are not tokens: ${read.problem}`) } };
|
|
111
111
|
}
|
|
112
112
|
catch (cause) {
|
|
113
113
|
return { ok: false, failure: { kind: 'store_failed', step: 'read', cause } };
|
|
@@ -119,7 +119,7 @@ export function createSession(options) {
|
|
|
119
119
|
* newer sign-in, a sign-out) sets the unsaved rotation aside, for the next sign-out (D500).
|
|
120
120
|
*/
|
|
121
121
|
function liveOf(held) {
|
|
122
|
-
const stored = held?.
|
|
122
|
+
const stored = held?.refresh_token;
|
|
123
123
|
if (unsaved !== null && unsaved.replaces !== stored) {
|
|
124
124
|
setAside.push(unsaved.refreshToken);
|
|
125
125
|
unsaved = null;
|
|
@@ -142,12 +142,19 @@ export function createSession(options) {
|
|
|
142
142
|
return UNAVAILABLE;
|
|
143
143
|
if (!now.ok)
|
|
144
144
|
return now.failure;
|
|
145
|
+
// A refresh spends the refresh token and then saves through the store's own compare and set,
|
|
146
|
+
// which reads its raw record: one still in the camelCase names of releases before the snake
|
|
147
|
+
// rename would refuse the save, with the new token unsaved. So it fails here, before anything
|
|
148
|
+
// is sent (#355's O1.B1). A sign-out spends nothing, and reads the record converted. The
|
|
149
|
+
// ready-made stores read those names themselves, so theirs never arrive here camelCase.
|
|
150
|
+
if (now.earlier)
|
|
151
|
+
return { kind: 'store_failed', step: 'read', cause: new TypeError(EARLIER_NAMES) };
|
|
145
152
|
const held = now.tokens;
|
|
146
153
|
const live = liveOf(held);
|
|
147
154
|
if (held === null)
|
|
148
155
|
return SIGNED_OUT;
|
|
149
|
-
if (held.
|
|
150
|
-
return { kind: 'token', accessToken: held.
|
|
156
|
+
if (held.access_token !== stale && fresh(held))
|
|
157
|
+
return { kind: 'token', accessToken: held.access_token };
|
|
151
158
|
if (live === undefined)
|
|
152
159
|
return SIGNED_OUT;
|
|
153
160
|
// The server, discovered now if this is the first turn that needs it (#130).
|
|
@@ -160,9 +167,9 @@ export function createSession(options) {
|
|
|
160
167
|
// new token, and the next refresh then ends the session (K6). Unsent is better.
|
|
161
168
|
if (limit.left() < SEND_FLOOR_MS)
|
|
162
169
|
return UNAVAILABLE;
|
|
163
|
-
const sentAt =
|
|
170
|
+
const sentAt = wallClock();
|
|
164
171
|
const form = { grant_type: 'refresh_token', refresh_token: live.token, client_id: clientId };
|
|
165
|
-
const answer = vouched(await call(transport, tokenCall('auth.refresh', server.
|
|
172
|
+
const answer = vouched(await call(transport, tokenCall('auth.refresh', server.token_endpoint, form, limit.left(), authorization)), authorization);
|
|
166
173
|
doubtful = !answer.ok && unanswered(answer.error) ? live.token : null;
|
|
167
174
|
if (!answer.ok) {
|
|
168
175
|
const failure = failureOf(answer.error);
|
|
@@ -176,7 +183,7 @@ export function createSession(options) {
|
|
|
176
183
|
const after = await read();
|
|
177
184
|
if (!after.ok)
|
|
178
185
|
return after.failure;
|
|
179
|
-
if (after.tokens?.
|
|
186
|
+
if (after.tokens?.refresh_token !== live.stored)
|
|
180
187
|
continue;
|
|
181
188
|
try {
|
|
182
189
|
await options.onTokens({ kind: 'cleared', replaces: live.stored });
|
|
@@ -192,7 +199,7 @@ export function createSession(options) {
|
|
|
192
199
|
// fail to save, and the refresh stays the one every caller takes. A rotation not saved is kept.
|
|
193
200
|
const keep = () => {
|
|
194
201
|
if (update.kind === 'rotated')
|
|
195
|
-
unsaved = { refreshToken: update.
|
|
202
|
+
unsaved = { refreshToken: update.refresh_token, replaces: live.stored };
|
|
196
203
|
};
|
|
197
204
|
const before = await read();
|
|
198
205
|
if (!before.ok) {
|
|
@@ -203,10 +210,10 @@ export function createSession(options) {
|
|
|
203
210
|
// overwrite: the answer isn't saved, and the refresh starts over from the store as it is now.
|
|
204
211
|
// The token sent is spent. A rotation it got is live at pulse-auth, and no longer the
|
|
205
212
|
// session's, so it's set aside for the next sign-out (D500).
|
|
206
|
-
if (before.tokens?.
|
|
213
|
+
if (before.tokens?.refresh_token !== live.stored) {
|
|
207
214
|
unsaved = null;
|
|
208
215
|
if (update.kind === 'rotated')
|
|
209
|
-
setAside.push(update.
|
|
216
|
+
setAside.push(update.refresh_token);
|
|
210
217
|
continue;
|
|
211
218
|
}
|
|
212
219
|
try {
|
|
@@ -218,7 +225,7 @@ export function createSession(options) {
|
|
|
218
225
|
}
|
|
219
226
|
if (update.kind === 'rotated')
|
|
220
227
|
unsaved = null;
|
|
221
|
-
return { kind: 'token', accessToken: update.
|
|
228
|
+
return { kind: 'token', accessToken: update.access_token };
|
|
222
229
|
}
|
|
223
230
|
}
|
|
224
231
|
/**
|
|
@@ -308,9 +315,9 @@ export function createSession(options) {
|
|
|
308
315
|
const held = now.tokens;
|
|
309
316
|
if (held === null)
|
|
310
317
|
return SIGNED_OUT;
|
|
311
|
-
if (held.
|
|
312
|
-
return { kind: 'token', accessToken: held.
|
|
313
|
-
return shared(held.
|
|
318
|
+
if (held.access_token !== ask.rejected && fresh(held))
|
|
319
|
+
return { kind: 'token', accessToken: held.access_token };
|
|
320
|
+
return shared(held.access_token);
|
|
314
321
|
}
|
|
315
322
|
// RFC 7009 on the tokens as they are once no refresh is spending them. pulse-auth answers 200
|
|
316
323
|
// whatever it is sent, a spent refresh token or an access token that has run out included, and
|
|
@@ -363,7 +370,7 @@ export function createSession(options) {
|
|
|
363
370
|
if (!found.ok)
|
|
364
371
|
return { kind: 'unconfirmed', reason: limit.ended() ?? found.error };
|
|
365
372
|
const server = found.data;
|
|
366
|
-
const endpoint = server.
|
|
373
|
+
const endpoint = server.revocation_endpoint;
|
|
367
374
|
if (endpoint === undefined)
|
|
368
375
|
return { kind: 'unconfirmed', reason: { kind: 'no_endpoint' } };
|
|
369
376
|
const result = stored === null ? null : await revokeStored(stored, live, server, endpoint, limit);
|
|
@@ -376,13 +383,13 @@ export function createSession(options) {
|
|
|
376
383
|
// failure of a token with the same 401 (expired, another audience, an ended session).
|
|
377
384
|
// A known expiry only: a token that could run out between the two checks would revoke nothing,
|
|
378
385
|
// and still be refused after (S6.B1).
|
|
379
|
-
if (held.
|
|
380
|
-
const before = await taken(server, held.
|
|
386
|
+
if (held.expires_at !== undefined && held.expires_at - wallClock() >= CHECK_MARGIN_MS) {
|
|
387
|
+
const before = await taken(server, held.access_token, limit);
|
|
381
388
|
if (before.kind === 'taken') {
|
|
382
|
-
const sent = await revocation(endpoint, held.
|
|
389
|
+
const sent = await revocation(endpoint, held.access_token, 'access_token', limit);
|
|
383
390
|
if (!sent.ok)
|
|
384
391
|
return { kind: 'unconfirmed', reason: sent.error };
|
|
385
|
-
const after = await taken(server, held.
|
|
392
|
+
const after = await taken(server, held.access_token, limit);
|
|
386
393
|
if (after.kind === 'taken')
|
|
387
394
|
return { kind: 'unconfirmed', reason: { kind: 'still_live' } };
|
|
388
395
|
if (after.kind === 'failed')
|
|
@@ -393,11 +400,11 @@ export function createSession(options) {
|
|
|
393
400
|
}
|
|
394
401
|
// Nothing to compare the answer after with: the session is still ended as best it can be,
|
|
395
402
|
// and the result says why it can't be confirmed.
|
|
396
|
-
const sent = await revocation(endpoint, live?.token ?? held.
|
|
403
|
+
const sent = await revocation(endpoint, live?.token ?? held.access_token, live === undefined ? 'access_token' : 'refresh_token', limit);
|
|
397
404
|
return { kind: 'unconfirmed', reason: sent.ok ? { kind: 'check_failed', error: before.error } : sent.error };
|
|
398
405
|
}
|
|
399
406
|
// No access token to check with: the live refresh token goes, or, with none, the access token.
|
|
400
|
-
const sent = await revocation(endpoint, live?.token ?? held.
|
|
407
|
+
const sent = await revocation(endpoint, live?.token ?? held.access_token, live === undefined ? 'access_token' : 'refresh_token', limit);
|
|
401
408
|
if (!sent.ok)
|
|
402
409
|
return { kind: 'unconfirmed', reason: sent.error };
|
|
403
410
|
return { kind: 'unconfirmed', reason: { kind: live !== undefined && doubtful === live.token ? 'maybe_spent' : 'unconfirmable' } };
|
|
@@ -586,10 +593,12 @@ export function createSession(options) {
|
|
|
586
593
|
},
|
|
587
594
|
};
|
|
588
595
|
}
|
|
589
|
-
|
|
590
|
-
|
|
596
|
+
// A token's expiry is an instant on the wall clock (`expires_at`, from when its request was sent), so
|
|
597
|
+
// these read the wall clock, never a deadline (#333).
|
|
598
|
+
const fresh = (held) => held.expires_at === undefined || held.expires_at - wallClock() > MARGIN_MS;
|
|
599
|
+
const unexpired = (held) => held.expires_at === undefined || held.expires_at > wallClock();
|
|
591
600
|
/** What a store compares on (D472): its refresh token, or its access token when it has none (`||`). */
|
|
592
|
-
const keyOf = (held) => (held === null ? undefined : held.
|
|
601
|
+
const keyOf = (held) => (held === null ? undefined : held.refresh_token || held.access_token);
|
|
593
602
|
/**
|
|
594
603
|
* A refresh the server may have carried out without the session learning of it: no answer, past
|
|
595
604
|
* the deadline, a server error, or a success it couldn't read. A 4xx answer, or a request never
|
|
@@ -603,7 +612,9 @@ const ABORTED = { kind: 'aborted' };
|
|
|
603
612
|
const isAborted = (value) => value === ABORTED;
|
|
604
613
|
function createLimit(ms, caller) {
|
|
605
614
|
const stop = new AbortController();
|
|
606
|
-
|
|
615
|
+
// On the monotonic clock, as the timer below is: by the wall clock, a step forward ended a refresh,
|
|
616
|
+
// revoke or sign-out still waiting its turn at once, with nothing sent (#333, #157 item 21).
|
|
617
|
+
const deadline = deadlineIn(ms);
|
|
607
618
|
let reason = 'timeout';
|
|
608
619
|
const timer = setTimeout(() => {
|
|
609
620
|
stop.abort();
|
|
@@ -622,11 +633,11 @@ function createLimit(ms, caller) {
|
|
|
622
633
|
return {
|
|
623
634
|
signal: stop.signal,
|
|
624
635
|
caller,
|
|
625
|
-
left:
|
|
636
|
+
left: deadline.left,
|
|
626
637
|
unconfirmed: () => ({ kind: 'unconfirmed', reason: { kind: reason } }),
|
|
627
638
|
// The clock as well as the timer: a store that blocks the thread past the deadline returns
|
|
628
639
|
// before the timer has had a chance to run (S7.F1).
|
|
629
|
-
ended: () => (stop.signal.aborted ||
|
|
640
|
+
ended: () => (stop.signal.aborted || deadline.passed() ? { kind: reason } : null),
|
|
630
641
|
callerAborted,
|
|
631
642
|
dispose: () => {
|
|
632
643
|
clearTimeout(timer);
|
|
@@ -682,10 +693,10 @@ async function within(work, ms) {
|
|
|
682
693
|
}
|
|
683
694
|
// RFC 6749 §6: a new refresh token replaces the old; none (pulse-auth sends "") means keep it.
|
|
684
695
|
function updateOf(answer, replaces, sentAt) {
|
|
685
|
-
const expiry = answer.expires_in === undefined ? {} : {
|
|
696
|
+
const expiry = answer.expires_in === undefined ? {} : { expires_at: sentAt + answer.expires_in * 1000 };
|
|
686
697
|
return answer.refresh_token !== undefined && answer.refresh_token !== ''
|
|
687
|
-
? { kind: 'rotated',
|
|
688
|
-
: { kind: 'access-only',
|
|
698
|
+
? { kind: 'rotated', access_token: answer.access_token, refresh_token: answer.refresh_token, ...expiry, replaces }
|
|
699
|
+
: { kind: 'access-only', access_token: answer.access_token, ...expiry, replaces };
|
|
689
700
|
}
|
|
690
701
|
/** A discovery that failed in a refresh's turn: no answer is `unavailable`; anything else, a refresh that failed. */
|
|
691
702
|
function discoveryFailure(error) {
|