@chrischall/mcp-utils 0.15.0 → 0.16.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/README.md +67 -1
- package/dist/session/index.d.ts +240 -15
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +428 -41
- package/dist/session/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ import light:
|
|
|
32
32
|
| Import | Contents |
|
|
33
33
|
| --- | --- |
|
|
34
34
|
| `@chrischall/mcp-utils` | core barrel: `server` + `response` + `errors` + `config` + `fs` + `http` + `concurrency` + `dates` + `zod` + `auth` + `scrape` |
|
|
35
|
-
| `@chrischall/mcp-utils/session` | session registry, session store, token manager, cookie-session manager |
|
|
35
|
+
| `@chrischall/mcp-utils/session` | session registry, session store, state persistence, token manager, cookie-session manager |
|
|
36
36
|
| `@chrischall/mcp-utils/fetchproxy` | fetchproxy transport adapter, bot-wall / retry / concurrency helpers |
|
|
37
37
|
| `@chrischall/mcp-utils/html` | opt-in HTML scraping helpers (needs `node-html-parser`) |
|
|
38
38
|
| `@chrischall/mcp-utils/scrape` | convenience alias for the zero-dep `scrape` module (also in the core barrel) |
|
|
@@ -485,6 +485,72 @@ Replaces the hand-rolled re-login / single-flight / 401-replay code in
|
|
|
485
485
|
`artsonia-mcp`, `canvas-parent-mcp`, `evite-mcp`, `signupgenius-mcp`, and
|
|
486
486
|
`skylight-mcp`.
|
|
487
487
|
|
|
488
|
+
#### Surviving a restart — `StatePersistence` *(opt-in)*
|
|
489
|
+
|
|
490
|
+
Both managers own a credential only for the life of the process. On a
|
|
491
|
+
scale-to-zero host that means a full login on every cold start — children idle
|
|
492
|
+
out after ten minutes, several services rate-limit the login endpoint, and one
|
|
493
|
+
escalates repeated attempts to a captcha that breaks server-side auth outright.
|
|
494
|
+
Pass `persistence` and the credential survives instead:
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
import {
|
|
498
|
+
TokenManager,
|
|
499
|
+
createFileStatePersistence,
|
|
500
|
+
resolveStateDir,
|
|
501
|
+
type BearerTokens,
|
|
502
|
+
} from '@chrischall/mcp-utils/session';
|
|
503
|
+
import { join } from 'node:path';
|
|
504
|
+
|
|
505
|
+
const tokens = new TokenManager({
|
|
506
|
+
// Function form: run the login ONLY when nothing usable was restored.
|
|
507
|
+
initial: () => loginWithPassword(),
|
|
508
|
+
refresh: (rt) => exchangeRefreshToken(rt),
|
|
509
|
+
persistence: createFileStatePersistence<BearerTokens>({
|
|
510
|
+
filePath: join(resolveStateDir({ subdir: '.acme-mcp' }), 'tokens.json'),
|
|
511
|
+
}),
|
|
512
|
+
});
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
What that buys, in order of how often it applies: a stored token that is still
|
|
516
|
+
valid costs **nothing**; a stored token that has expired but carries a refresh
|
|
517
|
+
token costs **one refresh** instead of a login; only an empty or unusable store
|
|
518
|
+
runs `initial`. A refresh token revoked between runs is not terminal — the
|
|
519
|
+
stored copy is discarded and the login re-runs, so a stale file cannot brick the
|
|
520
|
+
server. A *transient* refresh failure is treated differently: a `RateLimitedError`,
|
|
521
|
+
a `RequestTimeoutError` or a 5xx `ApiError` surfaces to the caller with the
|
|
522
|
+
refresh token left intact, because destroying a valid credential and burning a
|
|
523
|
+
login on a passing outage is the cost this feature exists to avoid. Override
|
|
524
|
+
`isRefreshRevoked` for a service that signals revocation some other way.
|
|
525
|
+
|
|
526
|
+
`createFileStatePersistence` writes atomically (temp file + rename), leaves the
|
|
527
|
+
file `0600`, and creates any missing directory `0700` — but does **not**
|
|
528
|
+
re-permission a directory that already exists, since a bare `resolveStateDir()`
|
|
529
|
+
is `$HOME` and `mcp-host` creates the data dir before the child starts. It never
|
|
530
|
+
throws: a read-only or full disk degrades to in-memory operation, costing a
|
|
531
|
+
login rather than a failed request. `resolveStateDir` prefers `MCP_DATA_DIR` — the variable `mcp-host`
|
|
532
|
+
injects for a registration with `state.dataDir: true` — then `HOME`, then the OS
|
|
533
|
+
home directory. It reads both through `readEnvVar`, so blank values, the
|
|
534
|
+
`'null'` / `'undefined'` sentinels and unexpanded `${...}` placeholders are all
|
|
535
|
+
treated as unset (`MCP_DATA_DIR=null` would otherwise be a *relative* `./null`
|
|
536
|
+
directory, quietly parking the credential under the process cwd).
|
|
537
|
+
|
|
538
|
+
> On `mcp-host`, set `state.dataDir: true` in the repo's `mint.yaml` when you
|
|
539
|
+
> adopt this. Without it the child's `$HOME` is on the container rootfs, which
|
|
540
|
+
> an idle-stop discards — the runner's unpersisted-state detector will report
|
|
541
|
+
> the omission, but the writes still vanish.
|
|
542
|
+
|
|
543
|
+
`CookieSessionManager` takes the same option, storing `{ session, sessionAt }`
|
|
544
|
+
so `maxAgeMs` keeps counting from the original login. Its `invalidate()` clears
|
|
545
|
+
the stored copy — without that, a session detected as expired would be read back
|
|
546
|
+
off disk and the expiry would loop.
|
|
547
|
+
|
|
548
|
+
Persistence is **opt-in throughout**: a manager constructed without it behaves
|
|
549
|
+
exactly as before, and no credential reaches a disk because a dependency was
|
|
550
|
+
upgraded. The interface is two methods (`load` / `save`, plus an optional
|
|
551
|
+
`clear`), each allowed to be async, so a backend other than the local filesystem
|
|
552
|
+
can be dropped in.
|
|
553
|
+
|
|
488
554
|
### `fetchproxy` — transport adapter *(subpath, optional peer)*
|
|
489
555
|
|
|
490
556
|
```ts
|
package/dist/session/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session scaffolding for the MCP fleet —
|
|
2
|
+
* Session scaffolding for the MCP fleet — five related-but-distinct surfaces
|
|
3
3
|
* consolidated behind one subpath (`@chrischall/mcp-utils/session`):
|
|
4
4
|
*
|
|
5
5
|
* 1. {@link SessionRegistry} — an *ephemeral, in-memory* registry of signed-in
|
|
@@ -12,12 +12,18 @@
|
|
|
12
12
|
* (0600 file / 0700 dir), normalized keys, and a most-recently-used "active"
|
|
13
13
|
* pointer. Used by ofw/creditkarma/honeybook.
|
|
14
14
|
*
|
|
15
|
-
* 3. {@link
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* 3. {@link StatePersistence} — the opt-in seam that lets the two managers
|
|
16
|
+
* below survive a process restart, with {@link createFileStatePersistence}
|
|
17
|
+
* (atomic, 0600) and {@link resolveStateDir} (`MCP_DATA_DIR` → `HOME`) as
|
|
18
|
+
* the disk-backed default. Without it a scale-to-zero host re-runs a full
|
|
19
|
+
* login on every cold start, against endpoints that often rate-limit it.
|
|
19
20
|
*
|
|
20
|
-
* 4. {@link
|
|
21
|
+
* 4. {@link TokenManager} — a bearer-token lifecycle manager: a lazily
|
|
22
|
+
* bootstrapped login, proactive refresh inside a 5-minute skew window,
|
|
23
|
+
* reactive 401-replay, and a single-flight semaphore so concurrent callers
|
|
24
|
+
* coalesce into ONE exchange. Used by skylight/canvas/creditkarma/honeybook/zola.
|
|
25
|
+
*
|
|
26
|
+
* 5. {@link CookieSessionManager} — the cookie-session analog of TokenManager:
|
|
21
27
|
* a single-flight login + reactive expiry-replay (with heuristic, not just
|
|
22
28
|
* status-code, expiry detection) + clear-on-settle so a rejected login never
|
|
23
29
|
* sticks. Used by artsonia/canvas/evite/signupgenius/skylight.
|
|
@@ -179,6 +185,98 @@ export declare class SessionStore<T extends Record<string, unknown>> {
|
|
|
179
185
|
/** Clear in-memory state without touching disk. Test helper. */
|
|
180
186
|
resetForTest(): void;
|
|
181
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* A place to keep a credential between processes.
|
|
190
|
+
*
|
|
191
|
+
* Why this exists: {@link TokenManager} and {@link CookieSessionManager} own a
|
|
192
|
+
* credential's lifecycle *within* a process, and every fleet server used to
|
|
193
|
+
* throw that credential away on exit — so a cold start re-ran the full login
|
|
194
|
+
* even when a valid refresh token had been minted seconds earlier. On
|
|
195
|
+
* `mcp-host` that is the normal case, not the exception: children idle out
|
|
196
|
+
* after ten minutes and the machine scales to zero behind them. Several
|
|
197
|
+
* services rate-limit the login endpoint, and at least one (per the kiaaccess
|
|
198
|
+
* notes) escalates repeated attempts to a captcha that breaks server-side auth
|
|
199
|
+
* for the account permanently. Re-login is not always a free retry.
|
|
200
|
+
*
|
|
201
|
+
* Deliberately opt-in: a manager given no `persistence` behaves exactly as it
|
|
202
|
+
* did before, and no credential reaches a disk because a package was upgraded.
|
|
203
|
+
*
|
|
204
|
+
* Both methods may be sync or async. The fleet's own implementation
|
|
205
|
+
* ({@link createFileStatePersistence}) is sync — it writes one small file — but
|
|
206
|
+
* the async signature leaves room for a backend that has to go over a wire.
|
|
207
|
+
*
|
|
208
|
+
* **Implementations must not throw.** The managers guard every call anyway, but
|
|
209
|
+
* the contract is that a persistence failure degrades to in-memory operation:
|
|
210
|
+
* a read-only or full disk must cost a re-login, never a failed request.
|
|
211
|
+
*/
|
|
212
|
+
export interface StatePersistence<T> {
|
|
213
|
+
/** Read the stored state; `null` when absent, unparseable, or unusable. */
|
|
214
|
+
load(): T | null | Promise<T | null>;
|
|
215
|
+
/** Write state, replacing whatever was there. */
|
|
216
|
+
save(state: T): void | Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Discard the stored state. Optional, but a manager that detects its stored
|
|
219
|
+
* credential is no good calls this — without it, an expired session is read
|
|
220
|
+
* straight back off disk and the expiry loops.
|
|
221
|
+
*/
|
|
222
|
+
clear?(): void | Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
/** Options for {@link createFileStatePersistence}. */
|
|
225
|
+
export interface FileStatePersistenceOptions<T> {
|
|
226
|
+
/** Absolute path to the JSON file. Parent directories are created as needed. */
|
|
227
|
+
filePath: string;
|
|
228
|
+
/**
|
|
229
|
+
* Narrow the parsed JSON to `T`, returning `null` to reject it. Without this
|
|
230
|
+
* any well-formed JSON is handed back and the caller must check the shape —
|
|
231
|
+
* the managers do, but a custom consumer should pass a guard.
|
|
232
|
+
*/
|
|
233
|
+
validate?: (raw: unknown) => T | null;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* File-backed {@link StatePersistence}. The file is `0600`, re-asserted after
|
|
237
|
+
* the write because `mode` only applies on creation. A directory is created
|
|
238
|
+
* `0700` and re-asserted the same way — but ONLY one this call creates: a bare
|
|
239
|
+
* {@link resolveStateDir} is `$HOME`, and on `mcp-host` the data dir exists
|
|
240
|
+
* before the child starts, so re-permissioning a pre-existing directory would
|
|
241
|
+
* be an invasive side effect of writing one token file rather than hardening.
|
|
242
|
+
*
|
|
243
|
+
* Two differences from {@link SessionStore}, which is why this is its own
|
|
244
|
+
* implementation rather than a wrapper over it. It holds ONE record rather than
|
|
245
|
+
* a keyed collection; and it replaces the file **atomically** — written to a
|
|
246
|
+
* temp file beside it, then renamed over the target — because two children of
|
|
247
|
+
* the same registration can share a data directory, and a half-written token
|
|
248
|
+
* file that parses as valid JSON is worse than none.
|
|
249
|
+
*
|
|
250
|
+
* Nothing here throws. A load failure (absent, corrupt, rejected by `validate`)
|
|
251
|
+
* returns `null`; a save failure is swallowed and leaves the previous file
|
|
252
|
+
* intact. On `mcp-host` this belongs under {@link resolveStateDir}, which needs
|
|
253
|
+
* the registration to declare `state.dataDir: true` — the runner's
|
|
254
|
+
* unpersisted-state detector will report the omission rather than let the
|
|
255
|
+
* writes silently vanish on the next idle-stop.
|
|
256
|
+
*/
|
|
257
|
+
export declare function createFileStatePersistence<T>(opts: FileStatePersistenceOptions<T>): Required<StatePersistence<T>>;
|
|
258
|
+
/** Options for {@link resolveStateDir}. */
|
|
259
|
+
export interface ResolveStateDirOptions {
|
|
260
|
+
/** Environment to read (defaults to `process.env`) — injectable for tests. */
|
|
261
|
+
env?: Record<string, string | undefined>;
|
|
262
|
+
/** Optional service-scoped subdirectory to join onto the base. */
|
|
263
|
+
subdir?: string;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Where a server should keep state that must survive a restart.
|
|
267
|
+
*
|
|
268
|
+
* `MCP_DATA_DIR` first — that is the variable `mcp-host` injects for a
|
|
269
|
+
* registration with `state.dataDir: true`, pointing at a path on the Fly volume
|
|
270
|
+
* keyed by the registration itself (a slot `$HOME` is handed out by arrival
|
|
271
|
+
* order and moves between boots, which is why the data dir is the fix and a
|
|
272
|
+
* bigger rootfs is not). Then `HOME`, then the OS home directory.
|
|
273
|
+
*
|
|
274
|
+
* Blank and unexpanded-placeholder values (`${MCP_DATA_DIR}`, the shape a host
|
|
275
|
+
* config leaves behind when a variable was never substituted) are ignored
|
|
276
|
+
* rather than used as a literal directory name — the same hardening
|
|
277
|
+
* {@link readEnvVar} applies.
|
|
278
|
+
*/
|
|
279
|
+
export declare function resolveStateDir(opts?: ResolveStateDirOptions): string;
|
|
182
280
|
/** Refresh proactively this many ms before the access token expires. */
|
|
183
281
|
export declare const TOKEN_REFRESH_SKEW_MS: number;
|
|
184
282
|
/** A bearer access token + (optional) refresh token + absolute expiry. */
|
|
@@ -198,8 +296,21 @@ export interface RefreshedTokens {
|
|
|
198
296
|
}
|
|
199
297
|
/** Options for {@link TokenManager}. */
|
|
200
298
|
export interface TokenManagerOptions {
|
|
201
|
-
/**
|
|
202
|
-
|
|
299
|
+
/**
|
|
300
|
+
* The starting tokens — either the tokens themselves, or a **bootstrap
|
|
301
|
+
* function** that mints them (typically a full login).
|
|
302
|
+
*
|
|
303
|
+
* Pass the function form to get the persistence benefit: it is invoked only
|
|
304
|
+
* when {@link TokenManagerOptions.persistence} has nothing usable, so a
|
|
305
|
+
* restart that finds a stored token never logs in at all, and one that finds
|
|
306
|
+
* an expired token with a refresh token spends a refresh instead of a login.
|
|
307
|
+
* It is single-flighted like every other credential operation here, so a
|
|
308
|
+
* burst of first calls hits a rate-limited login endpoint exactly once.
|
|
309
|
+
*
|
|
310
|
+
* The eager object form is unchanged: the caller already paid for the login,
|
|
311
|
+
* so persistence is not consulted and the tokens are used as given.
|
|
312
|
+
*/
|
|
313
|
+
initial: BearerTokens | (() => Promise<BearerTokens>);
|
|
203
314
|
/**
|
|
204
315
|
* Exchange the current refresh token for fresh tokens. Called at most once
|
|
205
316
|
* per concurrent burst (the in-flight promise is shared).
|
|
@@ -210,36 +321,109 @@ export interface TokenManagerOptions {
|
|
|
210
321
|
* refresh). Defaults to {@link TOKEN_REFRESH_SKEW_MS} (5 minutes).
|
|
211
322
|
*/
|
|
212
323
|
skewMs?: number;
|
|
324
|
+
/**
|
|
325
|
+
* Keep tokens across process restarts. Read once on the bootstrap path
|
|
326
|
+
* (function-form `initial` only), written after every successful bootstrap
|
|
327
|
+
* and refresh, including rotation. Omit for the previous in-memory-only
|
|
328
|
+
* behaviour. See {@link StatePersistence}.
|
|
329
|
+
*/
|
|
330
|
+
persistence?: StatePersistence<BearerTokens>;
|
|
331
|
+
/**
|
|
332
|
+
* Decide whether a {@link TokenManagerOptions.refresh} rejection means the
|
|
333
|
+
* credential itself is dead (re-mint via the bootstrap) or the endpoint was
|
|
334
|
+
* merely unreachable (surface it, keep the token).
|
|
335
|
+
*
|
|
336
|
+
* The distinction matters in both directions. Treating a transient failure as
|
|
337
|
+
* revocation deletes a still-VALID refresh token and burns a login against an
|
|
338
|
+
* endpoint that may rate-limit or escalate to a captcha — the exact cost this
|
|
339
|
+
* whole feature exists to avoid. Treating a real revocation as transient
|
|
340
|
+
* leaves the server broken until someone deletes the stored file by hand.
|
|
341
|
+
*
|
|
342
|
+
* The default resolves that by only excusing failures that are transient *by
|
|
343
|
+
* construction* — a {@link RateLimitedError}, a {@link RequestTimeoutError},
|
|
344
|
+
* or an {@link ApiError} with a 5xx status. Anything else is assumed to be a
|
|
345
|
+
* dead credential, which keeps the recover-from-revocation guarantee. Override
|
|
346
|
+
* it for a service that signals revocation some other way (or, conversely, one
|
|
347
|
+
* that answers a live token with a 5xx). Mirrors the permanent-vs-transient
|
|
348
|
+
* split {@link CookieSessionManagerOptions.isPermanentError} already makes.
|
|
349
|
+
*/
|
|
350
|
+
isRefreshRevoked?: (err: unknown) => boolean;
|
|
351
|
+
/** Injectable clock (defaults to `Date.now`) — for tests. */
|
|
352
|
+
now?: () => number;
|
|
213
353
|
}
|
|
214
354
|
/**
|
|
215
355
|
* Manages a bearer access token's lifecycle:
|
|
216
356
|
*
|
|
357
|
+
* - **Lazy bootstrap:** with a function-form {@link TokenManagerOptions.initial}
|
|
358
|
+
* the login runs on first use, and only if {@link TokenManagerOptions.persistence}
|
|
359
|
+
* has no usable token — the difference between a cold start costing a login
|
|
360
|
+
* and costing nothing.
|
|
217
361
|
* - **Proactive:** {@link TokenManager.getAccessToken} refreshes when the token
|
|
218
362
|
* is within `skewMs` (default 5 min) of expiry, returning a still-valid token.
|
|
219
363
|
* - **Reactive:** {@link TokenManager.withAuth} runs a request, and on a `401`
|
|
220
364
|
* refreshes once and replays exactly once (no infinite loop).
|
|
221
|
-
* - **Race-safe:** concurrent refreshes
|
|
222
|
-
*
|
|
223
|
-
* in-flight promise is cleared on settle so a later
|
|
365
|
+
* - **Race-safe:** concurrent refreshes (and concurrent bootstraps) coalesce
|
|
366
|
+
* onto a single in-flight promise, so a burst of callers triggers exactly ONE
|
|
367
|
+
* exchange. The in-flight promise is cleared on settle so a later attempt can
|
|
368
|
+
* run again — a rejected bootstrap never sticks.
|
|
369
|
+
* - **Recoverable:** when a refresh fails and a bootstrap function is available,
|
|
370
|
+
* the stored credential is discarded and the login re-runs. A refresh token
|
|
371
|
+
* revoked between two runs of the process must not brick the server.
|
|
224
372
|
*/
|
|
225
373
|
export declare class TokenManager {
|
|
226
|
-
private
|
|
227
|
-
private
|
|
228
|
-
private expiresAt;
|
|
374
|
+
private tokens;
|
|
375
|
+
private readonly bootstrapFn;
|
|
229
376
|
private readonly refreshFn;
|
|
230
377
|
private readonly skewMs;
|
|
378
|
+
private readonly persistence;
|
|
379
|
+
private readonly now;
|
|
380
|
+
private readonly isRefreshRevokedFn;
|
|
231
381
|
private inFlight;
|
|
382
|
+
private bootstrapInFlight;
|
|
383
|
+
/**
|
|
384
|
+
* Persistence is consulted at most once per process. Without this the
|
|
385
|
+
* revoked-token recovery below re-reads the SAME rejected record — `clear()`
|
|
386
|
+
* is optional on {@link StatePersistence} and its failures are swallowed, so
|
|
387
|
+
* recovery must not depend on it. After the first read the in-memory tokens
|
|
388
|
+
* (or their deliberate absence) are the truth.
|
|
389
|
+
*/
|
|
390
|
+
private persistenceRead;
|
|
232
391
|
constructor(opts: TokenManagerOptions);
|
|
233
392
|
/** Whether the token is within the skew window of (or past) expiry. */
|
|
234
393
|
private needsRefresh;
|
|
394
|
+
/**
|
|
395
|
+
* A stored token is worth using when it is still valid, OR when it carries a
|
|
396
|
+
* refresh token — an expired-but-refreshable token still saves the login,
|
|
397
|
+
* which is the expensive half.
|
|
398
|
+
*/
|
|
399
|
+
private isUsable;
|
|
400
|
+
/** Read persisted tokens, guarding shape and usability. Never throws. */
|
|
401
|
+
private loadPersisted;
|
|
402
|
+
/** Write tokens. Never throws — a failed write costs a login, not a request. */
|
|
403
|
+
private persist;
|
|
404
|
+
/** Discard persisted tokens (a refresh they could not satisfy). Never throws. */
|
|
405
|
+
private clearPersisted;
|
|
406
|
+
/** The current tokens, single-flighting the bootstrap if there are none. */
|
|
407
|
+
private ensureTokens;
|
|
408
|
+
/** One bootstrap attempt: persisted tokens if usable, else the login. */
|
|
409
|
+
private runBootstrap;
|
|
235
410
|
/**
|
|
236
411
|
* Single-flight refresh. Concurrent callers share one in-flight promise; it is
|
|
237
412
|
* cleared on settle (success or failure) so a subsequent refresh can proceed.
|
|
238
413
|
*/
|
|
239
414
|
refreshNow(): Promise<void>;
|
|
415
|
+
/** One refresh attempt against the current refresh token. */
|
|
416
|
+
private runRefresh;
|
|
417
|
+
/**
|
|
418
|
+
* Recover from a refresh the current credential could not satisfy — commonly
|
|
419
|
+
* a refresh token restored from a previous process and revoked since. Without
|
|
420
|
+
* a bootstrap to fall back on this is terminal; with one, re-minting beats
|
|
421
|
+
* staying broken forever. Shared so the two entry points cannot diverge.
|
|
422
|
+
*/
|
|
423
|
+
private reBootstrap;
|
|
240
424
|
/** Get a valid access token, refreshing proactively inside the skew window. */
|
|
241
425
|
getAccessToken(): Promise<string>;
|
|
242
|
-
/** Current absolute expiry (epoch ms). */
|
|
426
|
+
/** Current absolute expiry (epoch ms), or `0` before the first bootstrap. */
|
|
243
427
|
getExpiresAt(): number;
|
|
244
428
|
/**
|
|
245
429
|
* Run an authenticated request with reactive 401-replay. `call` receives a
|
|
@@ -329,6 +513,25 @@ export interface CookieSessionManagerOptions<S, R = Response> {
|
|
|
329
513
|
* login failure to the caller instead of the stale response.
|
|
330
514
|
*/
|
|
331
515
|
onReplayLoginError?: (err: unknown) => void;
|
|
516
|
+
/**
|
|
517
|
+
* Keep the session across process restarts. Read ONCE, on the first login
|
|
518
|
+
* path, and written after every successful login and {@link
|
|
519
|
+
* CookieSessionManager.seed}. {@link CookieSessionManager.invalidate} clears
|
|
520
|
+
* it — without that, a session detected as expired would be read straight
|
|
521
|
+
* back off disk and the expiry would loop.
|
|
522
|
+
*
|
|
523
|
+
* The stored envelope carries the login time alongside the session so
|
|
524
|
+
* {@link CookieSessionManagerOptions.maxAgeMs} keeps counting from the
|
|
525
|
+
* original login rather than restarting at the restore. Omit for the previous
|
|
526
|
+
* in-memory-only behaviour. See {@link StatePersistence}.
|
|
527
|
+
*/
|
|
528
|
+
persistence?: StatePersistence<PersistedCookieSession<S>>;
|
|
529
|
+
}
|
|
530
|
+
/** What {@link CookieSessionManagerOptions.persistence} stores: a session plus its login time. */
|
|
531
|
+
export interface PersistedCookieSession<S> {
|
|
532
|
+
session: S;
|
|
533
|
+
/** Epoch ms the session was minted or seeded — the `maxAgeMs` clock. */
|
|
534
|
+
sessionAt: number;
|
|
332
535
|
}
|
|
333
536
|
/**
|
|
334
537
|
* Cookie-session analog of {@link TokenManager}: owns a site's cookie-session
|
|
@@ -382,6 +585,16 @@ export declare class CookieSessionManager<S = CookieSession, R = Response> {
|
|
|
382
585
|
private readonly maxAgeMs;
|
|
383
586
|
private readonly now;
|
|
384
587
|
private readonly onReplayLoginErrorFn;
|
|
588
|
+
private readonly persistence;
|
|
589
|
+
/** Persistence is consulted once per process; a miss must not be re-read. */
|
|
590
|
+
private persistenceRead;
|
|
591
|
+
/**
|
|
592
|
+
* Serializes persistence writes. `seed()` and `invalidate()` are synchronous
|
|
593
|
+
* by contract and so fire-and-forget their save/clear; with an async backend a
|
|
594
|
+
* slow save could otherwise land AFTER the clear that followed it and leave an
|
|
595
|
+
* invalidated session on disk.
|
|
596
|
+
*/
|
|
597
|
+
private persistChain;
|
|
385
598
|
constructor(opts: CookieSessionManagerOptions<S, R>);
|
|
386
599
|
/** The current session, or `undefined` before the first successful login. */
|
|
387
600
|
get current(): S | undefined;
|
|
@@ -425,6 +638,18 @@ export declare class CookieSessionManager<S = CookieSession, R = Response> {
|
|
|
425
638
|
* (new config). Used to recover from a detected session expiry.
|
|
426
639
|
*/
|
|
427
640
|
invalidate(): void;
|
|
641
|
+
/**
|
|
642
|
+
* The persisted session, if there is one worth using. Read at most once per
|
|
643
|
+
* process — after that the in-memory session (or its absence) is the truth,
|
|
644
|
+
* so an invalidate() cannot be undone by a stale file.
|
|
645
|
+
*/
|
|
646
|
+
private restoreFromPersistence;
|
|
647
|
+
/** Append a persistence op to the chain, preserving call order. Never throws. */
|
|
648
|
+
private enqueuePersist;
|
|
649
|
+
/** Write the session. Never throws — a failed write costs a login, not a request. */
|
|
650
|
+
private persist;
|
|
651
|
+
/** Discard the persisted session. Never throws. */
|
|
652
|
+
private clearPersisted;
|
|
428
653
|
/**
|
|
429
654
|
* Run an authenticated `call` with the current session and reactive
|
|
430
655
|
* expiry-replay. `call` receives the session and returns a `Response`. If
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAeH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,y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CAAuC;IAC5E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0D;IACtF,6EAA6E;IAC7E,OAAO,CAAC,eAAe,CAAS;IAChC;;;;;OAKG;IACH,OAAO,CAAC,YAAY,CAAoC;gBAE5C,IAAI,EAAE,2BAA2B,CAAC,CAAC,EAAE,CAAC,CAAC;IAYnD,6EAA6E;IAC7E,IAAI,OAAO,IAAI,CAAC,GAAG,SAAS,CAE3B;IAED,0FAA0F;IAC1F,OAAO,CAAC,OAAO;IAIf;;;;;;;;;;;OAWG;IACG,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC;IAY1B;;;;;;;;;OASG;IACH,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;IAYtB;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAuChB;;;;;OAKG;IACH,UAAU,IAAI,IAAI;IASlB;;;;OAIG;YACW,sBAAsB;IAoBpC,iFAAiF;IACjF,OAAO,CAAC,cAAc;IAMtB,qFAAqF;IACrF,OAAO,CAAC,OAAO;IAWf,mDAAmD;IACnD,OAAO,CAAC,cAAc;IAWtB;;;;;;;;;;;;;OAaG;IACG,WAAW,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CA2BhE;AAED,gDAAgD;AAChD,wBAAgB,0BAA0B,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC,GAAG,QAAQ,EACxE,IAAI,EAAE,2BAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,GACtC,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAE5B"}
|
package/dist/session/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session scaffolding for the MCP fleet —
|
|
2
|
+
* Session scaffolding for the MCP fleet — five related-but-distinct surfaces
|
|
3
3
|
* consolidated behind one subpath (`@chrischall/mcp-utils/session`):
|
|
4
4
|
*
|
|
5
5
|
* 1. {@link SessionRegistry} — an *ephemeral, in-memory* registry of signed-in
|
|
@@ -12,12 +12,18 @@
|
|
|
12
12
|
* (0600 file / 0700 dir), normalized keys, and a most-recently-used "active"
|
|
13
13
|
* pointer. Used by ofw/creditkarma/honeybook.
|
|
14
14
|
*
|
|
15
|
-
* 3. {@link
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* 3. {@link StatePersistence} — the opt-in seam that lets the two managers
|
|
16
|
+
* below survive a process restart, with {@link createFileStatePersistence}
|
|
17
|
+
* (atomic, 0600) and {@link resolveStateDir} (`MCP_DATA_DIR` → `HOME`) as
|
|
18
|
+
* the disk-backed default. Without it a scale-to-zero host re-runs a full
|
|
19
|
+
* login on every cold start, against endpoints that often rate-limit it.
|
|
19
20
|
*
|
|
20
|
-
* 4. {@link
|
|
21
|
+
* 4. {@link TokenManager} — a bearer-token lifecycle manager: a lazily
|
|
22
|
+
* bootstrapped login, proactive refresh inside a 5-minute skew window,
|
|
23
|
+
* reactive 401-replay, and a single-flight semaphore so concurrent callers
|
|
24
|
+
* coalesce into ONE exchange. Used by skylight/canvas/creditkarma/honeybook/zola.
|
|
25
|
+
*
|
|
26
|
+
* 5. {@link CookieSessionManager} — the cookie-session analog of TokenManager:
|
|
21
27
|
* a single-flight login + reactive expiry-replay (with heuristic, not just
|
|
22
28
|
* status-code, expiry detection) + clear-on-settle so a rejected login never
|
|
23
29
|
* sticks. Used by artsonia/canvas/evite/signupgenius/skylight.
|
|
@@ -26,10 +32,13 @@
|
|
|
26
32
|
* the one audited implementation the fleet shares.
|
|
27
33
|
*/
|
|
28
34
|
import { z } from 'zod';
|
|
29
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync, renameSync, } from 'node:fs';
|
|
30
|
-
import { dirname } from 'node:path';
|
|
35
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync, renameSync, unlinkSync, } from 'node:fs';
|
|
36
|
+
import { dirname, join } from 'node:path';
|
|
37
|
+
import { homedir } from 'node:os';
|
|
31
38
|
import { randomBytes } from 'node:crypto';
|
|
32
39
|
import { textResult } from '../response/index.js';
|
|
40
|
+
import { readEnvVar } from '../config/index.js';
|
|
41
|
+
import { ApiError, RateLimitedError, RequestTimeoutError } from '../http/index.js';
|
|
33
42
|
/** Generate a short, collision-resistant label id. */
|
|
34
43
|
function makeSessionId() {
|
|
35
44
|
return Date.now().toString(36) + randomBytes(6).toString('hex');
|
|
@@ -389,72 +398,336 @@ export class SessionStore {
|
|
|
389
398
|
this.mostRecentKey = null;
|
|
390
399
|
}
|
|
391
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* File-backed {@link StatePersistence}. The file is `0600`, re-asserted after
|
|
403
|
+
* the write because `mode` only applies on creation. A directory is created
|
|
404
|
+
* `0700` and re-asserted the same way — but ONLY one this call creates: a bare
|
|
405
|
+
* {@link resolveStateDir} is `$HOME`, and on `mcp-host` the data dir exists
|
|
406
|
+
* before the child starts, so re-permissioning a pre-existing directory would
|
|
407
|
+
* be an invasive side effect of writing one token file rather than hardening.
|
|
408
|
+
*
|
|
409
|
+
* Two differences from {@link SessionStore}, which is why this is its own
|
|
410
|
+
* implementation rather than a wrapper over it. It holds ONE record rather than
|
|
411
|
+
* a keyed collection; and it replaces the file **atomically** — written to a
|
|
412
|
+
* temp file beside it, then renamed over the target — because two children of
|
|
413
|
+
* the same registration can share a data directory, and a half-written token
|
|
414
|
+
* file that parses as valid JSON is worse than none.
|
|
415
|
+
*
|
|
416
|
+
* Nothing here throws. A load failure (absent, corrupt, rejected by `validate`)
|
|
417
|
+
* returns `null`; a save failure is swallowed and leaves the previous file
|
|
418
|
+
* intact. On `mcp-host` this belongs under {@link resolveStateDir}, which needs
|
|
419
|
+
* the registration to declare `state.dataDir: true` — the runner's
|
|
420
|
+
* unpersisted-state detector will report the omission rather than let the
|
|
421
|
+
* writes silently vanish on the next idle-stop.
|
|
422
|
+
*/
|
|
423
|
+
export function createFileStatePersistence(opts) {
|
|
424
|
+
const { filePath, validate } = opts;
|
|
425
|
+
return {
|
|
426
|
+
load() {
|
|
427
|
+
if (!existsSync(filePath))
|
|
428
|
+
return null;
|
|
429
|
+
try {
|
|
430
|
+
const raw = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
431
|
+
if (validate !== undefined)
|
|
432
|
+
return validate(raw);
|
|
433
|
+
return raw;
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
// Corrupt or unreadable: the caller re-authenticates. Unlike
|
|
437
|
+
// SessionStore this does NOT preserve a `.corrupt` copy — the file
|
|
438
|
+
// holds one refreshable credential, not an irreplaceable capture.
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
save(state) {
|
|
443
|
+
const dir = dirname(filePath);
|
|
444
|
+
// A unique temp name so two writers cannot share (and tear) one temp file.
|
|
445
|
+
const tmp = `${filePath}.tmp-${randomBytes(6).toString('hex')}`;
|
|
446
|
+
// Only a directory THIS call creates gets tightened. `resolveStateDir()`
|
|
447
|
+
// without a `subdir` is `$HOME`, and chmodding a user's home directory to
|
|
448
|
+
// 0700 is not an acceptable side effect of writing one token file.
|
|
449
|
+
const dirExisted = existsSync(dir);
|
|
450
|
+
try {
|
|
451
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
452
|
+
// mkdir's mode is subject to the umask, so re-assert it on what we made.
|
|
453
|
+
if (!dirExisted)
|
|
454
|
+
chmodSync(dir, 0o700);
|
|
455
|
+
writeFileSync(tmp, JSON.stringify(state, null, 2), { mode: 0o600 });
|
|
456
|
+
// Tighten BEFORE the rename: the window where fresh secrets sit in a
|
|
457
|
+
// possibly-loose file should not exist at all.
|
|
458
|
+
chmodSync(tmp, 0o600);
|
|
459
|
+
renameSync(tmp, filePath);
|
|
460
|
+
chmodSync(filePath, 0o600);
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
// Degrade to in-memory. Best-effort cleanup of the temp file so a
|
|
464
|
+
// failed write does not litter the data dir.
|
|
465
|
+
try {
|
|
466
|
+
if (existsSync(tmp))
|
|
467
|
+
unlinkSync(tmp);
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
/* best-effort */
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
clear() {
|
|
475
|
+
try {
|
|
476
|
+
if (existsSync(filePath))
|
|
477
|
+
unlinkSync(filePath);
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
/* best-effort */
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Where a server should keep state that must survive a restart.
|
|
487
|
+
*
|
|
488
|
+
* `MCP_DATA_DIR` first — that is the variable `mcp-host` injects for a
|
|
489
|
+
* registration with `state.dataDir: true`, pointing at a path on the Fly volume
|
|
490
|
+
* keyed by the registration itself (a slot `$HOME` is handed out by arrival
|
|
491
|
+
* order and moves between boots, which is why the data dir is the fix and a
|
|
492
|
+
* bigger rootfs is not). Then `HOME`, then the OS home directory.
|
|
493
|
+
*
|
|
494
|
+
* Blank and unexpanded-placeholder values (`${MCP_DATA_DIR}`, the shape a host
|
|
495
|
+
* config leaves behind when a variable was never substituted) are ignored
|
|
496
|
+
* rather than used as a literal directory name — the same hardening
|
|
497
|
+
* {@link readEnvVar} applies.
|
|
498
|
+
*/
|
|
499
|
+
export function resolveStateDir(opts = {}) {
|
|
500
|
+
// Delegated rather than re-implemented: readEnvVar is the fleet's one place
|
|
501
|
+
// that suppresses blank, `'null'`, `'undefined'` AND `${...}` placeholders.
|
|
502
|
+
// The sentinels matter as much as the placeholders here — `MCP_DATA_DIR=null`
|
|
503
|
+
// is a RELATIVE `./null` directory, so the credential would be written under
|
|
504
|
+
// the process cwd and silently stop surviving restarts.
|
|
505
|
+
const env = opts.env;
|
|
506
|
+
const base = readEnvVar('MCP_DATA_DIR', { env }) ?? readEnvVar('HOME', { env }) ?? homedir();
|
|
507
|
+
return opts.subdir !== undefined ? join(base, opts.subdir) : base;
|
|
508
|
+
}
|
|
392
509
|
// ===========================================================================
|
|
393
|
-
//
|
|
510
|
+
// 4. TokenManager — bearer lifecycle (skew, proactive + reactive, race-safe)
|
|
394
511
|
// ===========================================================================
|
|
395
512
|
/** Refresh proactively this many ms before the access token expires. */
|
|
396
513
|
export const TOKEN_REFRESH_SKEW_MS = 5 * 60 * 1000;
|
|
514
|
+
/**
|
|
515
|
+
* The default {@link TokenManagerOptions.isRefreshRevoked}: everything except
|
|
516
|
+
* the failures mcp-utils itself can prove are transient. Deliberately
|
|
517
|
+
* conservative — an unrecognised error is treated as a dead credential, because
|
|
518
|
+
* a needless re-login costs one request and an unrecoverable one costs the
|
|
519
|
+
* server until a human intervenes.
|
|
520
|
+
*/
|
|
521
|
+
function defaultIsRefreshRevoked(err) {
|
|
522
|
+
if (err instanceof RateLimitedError || err instanceof RequestTimeoutError)
|
|
523
|
+
return false;
|
|
524
|
+
if (err instanceof ApiError && err.status >= 500)
|
|
525
|
+
return false;
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
/** Whether a parsed record has the shape of {@link BearerTokens}. */
|
|
529
|
+
function isBearerTokens(raw) {
|
|
530
|
+
if (raw === null || typeof raw !== 'object')
|
|
531
|
+
return false;
|
|
532
|
+
const t = raw;
|
|
533
|
+
if (typeof t.accessToken !== 'string' || t.accessToken === '')
|
|
534
|
+
return false;
|
|
535
|
+
if (typeof t.expiresAt !== 'number' || !Number.isFinite(t.expiresAt))
|
|
536
|
+
return false;
|
|
537
|
+
return t.refreshToken === undefined || typeof t.refreshToken === 'string';
|
|
538
|
+
}
|
|
397
539
|
/**
|
|
398
540
|
* Manages a bearer access token's lifecycle:
|
|
399
541
|
*
|
|
542
|
+
* - **Lazy bootstrap:** with a function-form {@link TokenManagerOptions.initial}
|
|
543
|
+
* the login runs on first use, and only if {@link TokenManagerOptions.persistence}
|
|
544
|
+
* has no usable token — the difference between a cold start costing a login
|
|
545
|
+
* and costing nothing.
|
|
400
546
|
* - **Proactive:** {@link TokenManager.getAccessToken} refreshes when the token
|
|
401
547
|
* is within `skewMs` (default 5 min) of expiry, returning a still-valid token.
|
|
402
548
|
* - **Reactive:** {@link TokenManager.withAuth} runs a request, and on a `401`
|
|
403
549
|
* refreshes once and replays exactly once (no infinite loop).
|
|
404
|
-
* - **Race-safe:** concurrent refreshes
|
|
405
|
-
*
|
|
406
|
-
* in-flight promise is cleared on settle so a later
|
|
550
|
+
* - **Race-safe:** concurrent refreshes (and concurrent bootstraps) coalesce
|
|
551
|
+
* onto a single in-flight promise, so a burst of callers triggers exactly ONE
|
|
552
|
+
* exchange. The in-flight promise is cleared on settle so a later attempt can
|
|
553
|
+
* run again — a rejected bootstrap never sticks.
|
|
554
|
+
* - **Recoverable:** when a refresh fails and a bootstrap function is available,
|
|
555
|
+
* the stored credential is discarded and the login re-runs. A refresh token
|
|
556
|
+
* revoked between two runs of the process must not brick the server.
|
|
407
557
|
*/
|
|
408
558
|
export class TokenManager {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
expiresAt;
|
|
559
|
+
tokens;
|
|
560
|
+
bootstrapFn;
|
|
412
561
|
refreshFn;
|
|
413
562
|
skewMs;
|
|
563
|
+
persistence;
|
|
564
|
+
now;
|
|
565
|
+
isRefreshRevokedFn;
|
|
414
566
|
inFlight;
|
|
567
|
+
bootstrapInFlight;
|
|
568
|
+
/**
|
|
569
|
+
* Persistence is consulted at most once per process. Without this the
|
|
570
|
+
* revoked-token recovery below re-reads the SAME rejected record — `clear()`
|
|
571
|
+
* is optional on {@link StatePersistence} and its failures are swallowed, so
|
|
572
|
+
* recovery must not depend on it. After the first read the in-memory tokens
|
|
573
|
+
* (or their deliberate absence) are the truth.
|
|
574
|
+
*/
|
|
575
|
+
persistenceRead = false;
|
|
415
576
|
constructor(opts) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
577
|
+
if (typeof opts.initial === 'function') {
|
|
578
|
+
this.bootstrapFn = opts.initial;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
this.tokens = { ...opts.initial };
|
|
582
|
+
}
|
|
419
583
|
this.refreshFn = opts.refresh;
|
|
420
584
|
this.skewMs = opts.skewMs ?? TOKEN_REFRESH_SKEW_MS;
|
|
585
|
+
this.persistence = opts.persistence;
|
|
586
|
+
this.now = opts.now ?? Date.now;
|
|
587
|
+
this.isRefreshRevokedFn = opts.isRefreshRevoked ?? defaultIsRefreshRevoked;
|
|
421
588
|
}
|
|
422
589
|
/** Whether the token is within the skew window of (or past) expiry. */
|
|
423
590
|
needsRefresh() {
|
|
424
|
-
|
|
591
|
+
if (this.tokens === undefined)
|
|
592
|
+
return false;
|
|
593
|
+
return this.now() >= this.tokens.expiresAt - this.skewMs;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* A stored token is worth using when it is still valid, OR when it carries a
|
|
597
|
+
* refresh token — an expired-but-refreshable token still saves the login,
|
|
598
|
+
* which is the expensive half.
|
|
599
|
+
*/
|
|
600
|
+
isUsable(t) {
|
|
601
|
+
return this.now() < t.expiresAt - this.skewMs || t.refreshToken !== undefined;
|
|
602
|
+
}
|
|
603
|
+
/** Read persisted tokens, guarding shape and usability. Never throws. */
|
|
604
|
+
async loadPersisted() {
|
|
605
|
+
if (this.persistence === undefined || this.persistenceRead)
|
|
606
|
+
return null;
|
|
607
|
+
this.persistenceRead = true;
|
|
608
|
+
try {
|
|
609
|
+
const raw = await this.persistence.load();
|
|
610
|
+
if (!isBearerTokens(raw) || !this.isUsable(raw))
|
|
611
|
+
return null;
|
|
612
|
+
return raw;
|
|
613
|
+
}
|
|
614
|
+
catch {
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
/** Write tokens. Never throws — a failed write costs a login, not a request. */
|
|
619
|
+
async persist(t) {
|
|
620
|
+
if (this.persistence === undefined)
|
|
621
|
+
return;
|
|
622
|
+
try {
|
|
623
|
+
await this.persistence.save(t);
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
/* in-memory tokens are still valid for this process */
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
/** Discard persisted tokens (a refresh they could not satisfy). Never throws. */
|
|
630
|
+
async clearPersisted() {
|
|
631
|
+
if (this.persistence?.clear === undefined)
|
|
632
|
+
return;
|
|
633
|
+
try {
|
|
634
|
+
await this.persistence.clear();
|
|
635
|
+
}
|
|
636
|
+
catch {
|
|
637
|
+
/* best-effort */
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
/** The current tokens, single-flighting the bootstrap if there are none. */
|
|
641
|
+
ensureTokens() {
|
|
642
|
+
if (this.tokens !== undefined)
|
|
643
|
+
return Promise.resolve(this.tokens);
|
|
644
|
+
if (this.bootstrapInFlight === undefined) {
|
|
645
|
+
this.bootstrapInFlight = this.runBootstrap().finally(() => {
|
|
646
|
+
this.bootstrapInFlight = undefined;
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
return this.bootstrapInFlight;
|
|
650
|
+
}
|
|
651
|
+
/** One bootstrap attempt: persisted tokens if usable, else the login. */
|
|
652
|
+
async runBootstrap() {
|
|
653
|
+
const stored = await this.loadPersisted();
|
|
654
|
+
if (stored !== null) {
|
|
655
|
+
this.tokens = stored;
|
|
656
|
+
return stored;
|
|
657
|
+
}
|
|
658
|
+
if (this.bootstrapFn === undefined) {
|
|
659
|
+
throw new Error('TokenManager: no tokens and no bootstrap function to mint them.');
|
|
660
|
+
}
|
|
661
|
+
const fresh = await this.bootstrapFn();
|
|
662
|
+
this.tokens = fresh;
|
|
663
|
+
await this.persist(fresh);
|
|
664
|
+
return fresh;
|
|
425
665
|
}
|
|
426
666
|
/**
|
|
427
667
|
* Single-flight refresh. Concurrent callers share one in-flight promise; it is
|
|
428
668
|
* cleared on settle (success or failure) so a subsequent refresh can proceed.
|
|
429
669
|
*/
|
|
430
670
|
refreshNow() {
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
if (rt === undefined) {
|
|
434
|
-
return Promise.reject(new Error('TokenManager: cannot refresh — no refresh token is available.'));
|
|
435
|
-
}
|
|
436
|
-
this.inFlight = (async () => {
|
|
437
|
-
const tok = await this.refreshFn(rt);
|
|
438
|
-
this.accessToken = tok.accessToken;
|
|
439
|
-
if (tok.refreshToken !== undefined && tok.refreshToken !== '') {
|
|
440
|
-
this.refreshToken = tok.refreshToken;
|
|
441
|
-
}
|
|
442
|
-
this.expiresAt = tok.expiresAt;
|
|
443
|
-
})().finally(() => {
|
|
671
|
+
if (this.inFlight === undefined) {
|
|
672
|
+
this.inFlight = this.runRefresh().finally(() => {
|
|
444
673
|
this.inFlight = undefined;
|
|
445
674
|
});
|
|
446
675
|
}
|
|
447
676
|
return this.inFlight;
|
|
448
677
|
}
|
|
678
|
+
/** One refresh attempt against the current refresh token. */
|
|
679
|
+
async runRefresh() {
|
|
680
|
+
const current = this.tokens ?? (await this.ensureTokens());
|
|
681
|
+
const rt = current.refreshToken;
|
|
682
|
+
if (rt === undefined) {
|
|
683
|
+
throw new Error('TokenManager: cannot refresh — no refresh token is available.');
|
|
684
|
+
}
|
|
685
|
+
const tok = await this.refreshFn(rt);
|
|
686
|
+
this.tokens = {
|
|
687
|
+
accessToken: tok.accessToken,
|
|
688
|
+
// Rotation is optional: keep the current refresh token when none comes back.
|
|
689
|
+
refreshToken: tok.refreshToken !== undefined && tok.refreshToken !== '' ? tok.refreshToken : rt,
|
|
690
|
+
expiresAt: tok.expiresAt,
|
|
691
|
+
};
|
|
692
|
+
await this.persist(this.tokens);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Recover from a refresh the current credential could not satisfy — commonly
|
|
696
|
+
* a refresh token restored from a previous process and revoked since. Without
|
|
697
|
+
* a bootstrap to fall back on this is terminal; with one, re-minting beats
|
|
698
|
+
* staying broken forever. Shared so the two entry points cannot diverge.
|
|
699
|
+
*/
|
|
700
|
+
async reBootstrap(err) {
|
|
701
|
+
if (this.bootstrapFn === undefined)
|
|
702
|
+
throw err;
|
|
703
|
+
// Only a credential we believe is DEAD is worth destroying. A 5xx or a
|
|
704
|
+
// timeout leaves a perfectly good refresh token that the next call can use.
|
|
705
|
+
if (!this.isRefreshRevokedFn(err))
|
|
706
|
+
throw err;
|
|
707
|
+
this.tokens = undefined;
|
|
708
|
+
await this.clearPersisted();
|
|
709
|
+
return this.ensureTokens();
|
|
710
|
+
}
|
|
449
711
|
/** Get a valid access token, refreshing proactively inside the skew window. */
|
|
450
712
|
async getAccessToken() {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
713
|
+
// Not `await this.ensureTokens()` unconditionally: with tokens already in
|
|
714
|
+
// hand that await would defer the refresh below by a microtask, and callers
|
|
715
|
+
// rely on a concurrent burst reaching the single-flight in the SAME tick.
|
|
716
|
+
let tokens = this.tokens ?? (await this.ensureTokens());
|
|
717
|
+
if (this.needsRefresh()) {
|
|
718
|
+
try {
|
|
719
|
+
await this.refreshNow();
|
|
720
|
+
}
|
|
721
|
+
catch (err) {
|
|
722
|
+
return (await this.reBootstrap(err)).accessToken;
|
|
723
|
+
}
|
|
724
|
+
tokens = this.tokens ?? tokens;
|
|
725
|
+
}
|
|
726
|
+
return tokens.accessToken;
|
|
454
727
|
}
|
|
455
|
-
/** Current absolute expiry (epoch ms). */
|
|
728
|
+
/** Current absolute expiry (epoch ms), or `0` before the first bootstrap. */
|
|
456
729
|
getExpiresAt() {
|
|
457
|
-
return this.expiresAt;
|
|
730
|
+
return this.tokens?.expiresAt ?? 0;
|
|
458
731
|
}
|
|
459
732
|
/**
|
|
460
733
|
* Run an authenticated request with reactive 401-replay. `call` receives a
|
|
@@ -472,13 +745,31 @@ export class TokenManager {
|
|
|
472
745
|
const usedToken = await this.getAccessToken();
|
|
473
746
|
let res = await call(usedToken);
|
|
474
747
|
if (res.status === 401) {
|
|
475
|
-
if (this.accessToken === usedToken)
|
|
476
|
-
|
|
477
|
-
|
|
748
|
+
if (this.tokens?.accessToken === usedToken) {
|
|
749
|
+
// Same revoked-credential recovery getAccessToken has: a 401 replay must
|
|
750
|
+
// not be the one entry point that throws where the other re-mints.
|
|
751
|
+
try {
|
|
752
|
+
await this.refreshNow();
|
|
753
|
+
}
|
|
754
|
+
catch (err) {
|
|
755
|
+
await this.reBootstrap(err);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
res = await call(this.tokens?.accessToken ?? usedToken);
|
|
478
759
|
}
|
|
479
760
|
return res;
|
|
480
761
|
}
|
|
481
762
|
}
|
|
763
|
+
/** Whether a parsed record has the shape of {@link PersistedCookieSession}. */
|
|
764
|
+
function isPersistedCookieSession(raw) {
|
|
765
|
+
if (raw === null || typeof raw !== 'object')
|
|
766
|
+
return false;
|
|
767
|
+
const r = raw;
|
|
768
|
+
if (typeof r.sessionAt !== 'number' || !Number.isFinite(r.sessionAt))
|
|
769
|
+
return false;
|
|
770
|
+
// Field-by-field, like isBearerTokens: a primitive is not a session shape.
|
|
771
|
+
return typeof r.session === 'object' && r.session !== null;
|
|
772
|
+
}
|
|
482
773
|
/**
|
|
483
774
|
* Cookie-session analog of {@link TokenManager}: owns a site's cookie-session
|
|
484
775
|
* lifecycle with the same single-flight / replay / clear-on-settle discipline,
|
|
@@ -531,6 +822,16 @@ export class CookieSessionManager {
|
|
|
531
822
|
maxAgeMs;
|
|
532
823
|
now;
|
|
533
824
|
onReplayLoginErrorFn;
|
|
825
|
+
persistence;
|
|
826
|
+
/** Persistence is consulted once per process; a miss must not be re-read. */
|
|
827
|
+
persistenceRead = false;
|
|
828
|
+
/**
|
|
829
|
+
* Serializes persistence writes. `seed()` and `invalidate()` are synchronous
|
|
830
|
+
* by contract and so fire-and-forget their save/clear; with an async backend a
|
|
831
|
+
* slow save could otherwise land AFTER the clear that followed it and leave an
|
|
832
|
+
* invalidated session on disk.
|
|
833
|
+
*/
|
|
834
|
+
persistChain = Promise.resolve();
|
|
534
835
|
constructor(opts) {
|
|
535
836
|
this.loginFn = opts.login;
|
|
536
837
|
// Optional: ensure-only consumers (no per-request expiry path) omit it; the
|
|
@@ -540,6 +841,7 @@ export class CookieSessionManager {
|
|
|
540
841
|
this.maxAgeMs = opts.maxAgeMs;
|
|
541
842
|
this.now = opts.now ?? Date.now;
|
|
542
843
|
this.onReplayLoginErrorFn = opts.onReplayLoginError;
|
|
844
|
+
this.persistence = opts.persistence;
|
|
543
845
|
}
|
|
544
846
|
/** The current session, or `undefined` before the first successful login. */
|
|
545
847
|
get current() {
|
|
@@ -588,6 +890,12 @@ export class CookieSessionManager {
|
|
|
588
890
|
this.session = session;
|
|
589
891
|
this.sessionAt = this.now();
|
|
590
892
|
this.inFlight = undefined; // detach any in-flight login (it won't re-stamp)
|
|
893
|
+
// The caller has installed a session, so the stored one is superseded and
|
|
894
|
+
// must never be restored over it (or over a later invalidate()).
|
|
895
|
+
this.persistenceRead = true;
|
|
896
|
+
// Fire-and-forget: seed() is synchronous by contract, and a persistence
|
|
897
|
+
// failure must not change what the caller just installed.
|
|
898
|
+
void this.persist(session, this.sessionAt);
|
|
591
899
|
}
|
|
592
900
|
/**
|
|
593
901
|
* One login attempt. Self-clears `inFlight` on settle so a rejected login
|
|
@@ -602,11 +910,26 @@ export class CookieSessionManager {
|
|
|
602
910
|
const holder = {};
|
|
603
911
|
holder.p = (async () => {
|
|
604
912
|
try {
|
|
913
|
+
// A restored session is the whole point: skip the login entirely.
|
|
914
|
+
// Guarded rather than awaited unconditionally — with no persistence the
|
|
915
|
+
// await would defer loginFn() past the tick a concurrent burst needs.
|
|
916
|
+
const restored = this.persistence !== undefined && !this.persistenceRead
|
|
917
|
+
? await this.restoreFromPersistence()
|
|
918
|
+
: null;
|
|
919
|
+
if (restored !== null) {
|
|
920
|
+
if (this.inFlight === holder.p) {
|
|
921
|
+
this.session = restored.session;
|
|
922
|
+
this.sessionAt = restored.sessionAt;
|
|
923
|
+
}
|
|
924
|
+
return restored.session;
|
|
925
|
+
}
|
|
605
926
|
const session = await this.loginFn();
|
|
927
|
+
const at = this.now();
|
|
606
928
|
if (this.inFlight === holder.p) {
|
|
607
929
|
this.session = session;
|
|
608
|
-
this.sessionAt =
|
|
930
|
+
this.sessionAt = at;
|
|
609
931
|
}
|
|
932
|
+
await this.persist(session, at);
|
|
610
933
|
return session;
|
|
611
934
|
}
|
|
612
935
|
catch (err) {
|
|
@@ -630,6 +953,70 @@ export class CookieSessionManager {
|
|
|
630
953
|
invalidate() {
|
|
631
954
|
this.session = undefined;
|
|
632
955
|
this.inFlight = undefined;
|
|
956
|
+
// Fire-and-forget, and unconditional: the stored copy is the same session
|
|
957
|
+
// that just proved unusable. Leaving it would have the next ensure() read
|
|
958
|
+
// it back and loop on the very expiry that caused this call.
|
|
959
|
+
void this.clearPersisted();
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* The persisted session, if there is one worth using. Read at most once per
|
|
963
|
+
* process — after that the in-memory session (or its absence) is the truth,
|
|
964
|
+
* so an invalidate() cannot be undone by a stale file.
|
|
965
|
+
*/
|
|
966
|
+
async restoreFromPersistence() {
|
|
967
|
+
if (this.persistence === undefined || this.persistenceRead)
|
|
968
|
+
return null;
|
|
969
|
+
this.persistenceRead = true;
|
|
970
|
+
try {
|
|
971
|
+
// Through the chain, not around it: `invalidate()` queues its `clear()`,
|
|
972
|
+
// and a read that jumped that queue would restore the very session the
|
|
973
|
+
// clear is about to remove.
|
|
974
|
+
let raw = null;
|
|
975
|
+
await this.enqueuePersist(async () => {
|
|
976
|
+
raw = await this.persistence?.load();
|
|
977
|
+
});
|
|
978
|
+
if (!isPersistedCookieSession(raw))
|
|
979
|
+
return null;
|
|
980
|
+
// Honour the proactive TTL against the ORIGINAL login time.
|
|
981
|
+
if (this.maxAgeMs !== undefined && this.now() - raw.sessionAt >= this.maxAgeMs)
|
|
982
|
+
return null;
|
|
983
|
+
return raw;
|
|
984
|
+
}
|
|
985
|
+
catch {
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
/** Append a persistence op to the chain, preserving call order. Never throws. */
|
|
990
|
+
enqueuePersist(op) {
|
|
991
|
+
const next = this.persistChain.then(op);
|
|
992
|
+
this.persistChain = next.catch(() => undefined);
|
|
993
|
+
return next;
|
|
994
|
+
}
|
|
995
|
+
/** Write the session. Never throws — a failed write costs a login, not a request. */
|
|
996
|
+
persist(session, sessionAt) {
|
|
997
|
+
return this.enqueuePersist(async () => {
|
|
998
|
+
if (this.persistence === undefined)
|
|
999
|
+
return;
|
|
1000
|
+
try {
|
|
1001
|
+
await this.persistence.save({ session, sessionAt });
|
|
1002
|
+
}
|
|
1003
|
+
catch {
|
|
1004
|
+
/* the in-memory session is still usable for this process */
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
/** Discard the persisted session. Never throws. */
|
|
1009
|
+
clearPersisted() {
|
|
1010
|
+
return this.enqueuePersist(async () => {
|
|
1011
|
+
if (this.persistence?.clear === undefined)
|
|
1012
|
+
return;
|
|
1013
|
+
try {
|
|
1014
|
+
await this.persistence.clear();
|
|
1015
|
+
}
|
|
1016
|
+
catch {
|
|
1017
|
+
/* best-effort */
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
633
1020
|
}
|
|
634
1021
|
/**
|
|
635
1022
|
* Run an authenticated `call` with the current session and reactive
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,UAAU,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EACT,SAAS,EACT,UAAU,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AA8ClD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AK,CAAC,CAAC;IACrB,CAAC;CACF;AAED,gDAAgD;AAChD,MAAM,UAAU,0BAA0B,CACxC,IAAuC;IAEvC,OAAO,IAAI,oBAAoB,CAAO,IAAI,CAAC,CAAC;AAC9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrischall/mcp-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Shared scaffolding for the chrischall MCP fleet — server bootstrap, tool-result formatting, helpful errors, hardened env/config, a bearer API-client kit, zod atoms, session registries, a fetchproxy transport adapter, auth resolver skeletons, an in-memory test harness, and opt-in HTML helpers. The generic MCP glue hoisted out of ~19 sibling servers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|