@doist/cli-core 0.16.0 → 0.17.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 CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.17.0](https://github.com/Doist/cli-core/compare/v0.16.1...v0.17.0) (2026-05-19)
2
+
3
+ ### Features
4
+
5
+ * **auth:** add TokenBundle storage contract to TokenStore ([#37](https://github.com/Doist/cli-core/issues/37)) ([6513aaa](https://github.com/Doist/cli-core/commit/6513aaa8b6222eb421239f6e41ec63b12cf946e9))
6
+
7
+ ## [0.16.1](https://github.com/Doist/cli-core/compare/v0.16.0...v0.16.1) (2026-05-16)
8
+
9
+ ### Bug Fixes
10
+
11
+ * **auth:** open browser on WSL via cmd.exe; always surface URL ([#29](https://github.com/Doist/cli-core/issues/29)) ([4ac2824](https://github.com/Doist/cli-core/commit/4ac282474ca8a5f5cde1fe690b1a2bca7fcd5be1))
12
+
1
13
  ## [0.16.0](https://github.com/Doist/cli-core/compare/v0.15.0...v0.16.0) (2026-05-16)
2
14
 
3
15
  ### Features
package/README.md CHANGED
@@ -12,20 +12,20 @@ npm install @doist/cli-core
12
12
 
13
13
  ## What's in it
14
14
 
15
- | Module | Key exports | Purpose |
16
- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
- | `auth` (subpath) | `attachLoginCommand`, `attachLogoutCommand`, `attachStatusCommand`, `attachTokenViewCommand`, `runOAuthFlow`, `createPkceProvider`, `createSecureStore`, `createKeyringTokenStore`, `migrateLegacyAuth`, PKCE helpers, `AuthProvider` / `TokenStore` / `AccountRef` / `SecureStore` / `UserRecordStore` types, `AttachLogoutRevokeContext` | OAuth runtime plus the Commander attachers for `<cli> [auth] login` / `logout` / `status` / `token`. `attachLogoutCommand` accepts an optional `revokeToken` hook for best-effort server-side token revocation. Ships the standard public-client PKCE flow (`createPkceProvider`), a thin cross-platform OS-keyring wrapper (`createSecureStore`), and a multi-account keyring-backed `TokenStore` (`createKeyringTokenStore`) that stores secrets in the OS credential manager and degrades to plaintext in the consumer's config when the keyring is unavailable (WSL/headless Linux/containers). `AuthProvider` and `TokenStore` remain the escape hatches for DCR or fully bespoke backends. `logout` / `status` / `token` always attach `--user <ref>` and thread the parsed ref to `store.active(ref)` (and `store.clear(ref)` on `logout`). `commander` (when using the attachers), `open` (browser launch), and `@napi-rs/keyring` (when using `createSecureStore` or the keyring `TokenStore`) are optional peer/optional deps. |
18
- | `commands` (subpath) | `registerChangelogCommand`, `registerUpdateCommand` (+ semver helpers) | Commander wiring for cli-core's standard commands (e.g. `<cli> changelog`, `<cli> update`, `<cli> update switch`). **Requires** `commander` as an optional peer-dep. |
19
- | `config` | `getConfigPath`, `readConfig`, `readConfigStrict`, `writeConfig`, `updateConfig`, `CoreConfig`, `UpdateChannel` | Read / write a per-CLI JSON config file with typed error codes; `CoreConfig` is the shape of fields cli-core itself owns (extend it for per-CLI fields). |
20
- | `empty` | `printEmpty` | Print an empty-state message gated on `--json` / `--ndjson` so machine consumers never see human strings on stdout. |
21
- | `errors` | `CliError` | Typed CLI error class with `code` and exit-code mapping. |
22
- | `global-args` | `parseGlobalArgs`, `stripUserFlag`, `createGlobalArgsStore`, `createAccessibleGate`, `createSpinnerGate`, `getProgressJsonlPath`, `isProgressJsonlEnabled` | Parse well-known global flags (`--json`, `--ndjson`, `--quiet`, `--verbose`, `--accessible`, `--no-spinner`, `--progress-jsonl`, `--user <ref>`) and derive predicates from them. `stripUserFlag` removes `--user` tokens from argv so the cleaned array can be forwarded to Commander when the flag has no root-program attachment. |
23
- | `json` | `formatJson`, `formatNdjson` | Stable JSON / newline-delimited JSON formatting for stdout. |
24
- | `markdown` (subpath) | `preloadMarkdown`, `renderMarkdown`, `TerminalRendererOptions` | Lazy-init terminal markdown renderer. **Requires** `marked` and `marked-terminal-renderer` as peer-deps — install only if your CLI uses this subpath. |
25
- | `options` | `ViewOptions` | Type contract for `{ json?, ndjson? }` per-command options that machine-output gates derive from. |
26
- | `spinner` | `createSpinner` | Loading spinner factory wrapping `yocto-spinner` with disable gates. |
27
- | `terminal` | `isCI`, `isStderrTTY`, `isStdinTTY`, `isStdoutTTY` | TTY / CI detection helpers. |
28
- | `testing` (subpath) | `describeEmptyMachineOutput` | Vitest helpers reusable by consuming CLIs (e.g. parametrised empty-state suite covering `--json` / `--ndjson` / human modes). |
15
+ | Module | Key exports | Purpose |
16
+ | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
+ | `auth` (subpath) | `attachLoginCommand`, `attachLogoutCommand`, `attachStatusCommand`, `attachTokenViewCommand`, `runOAuthFlow`, `createPkceProvider`, `createSecureStore`, `createKeyringTokenStore`, `migrateLegacyAuth`, `persistBundle`, PKCE helpers, `AuthProvider` / `TokenStore` / `TokenBundle` / `RefreshInput` / `AccountRef` / `SecureStore` / `UserRecordStore` types, `AttachLogoutRevokeContext` | OAuth runtime plus the Commander attachers for `<cli> [auth] login` / `logout` / `status` / `token`. `attachLogoutCommand` accepts an optional `revokeToken` hook for best-effort server-side token revocation. Ships the standard public-client PKCE flow (`createPkceProvider`), a thin cross-platform OS-keyring wrapper (`createSecureStore`), and a multi-account keyring-backed `TokenStore` (`createKeyringTokenStore`) that stores secrets in the OS credential manager and degrades to plaintext in the consumer's config when the keyring is unavailable (WSL/headless Linux/containers). The store contract supports an optional `setBundle(account, bundle)` write method (required on `KeyringTokenStore`) so consumers that need refresh-token persistence can opt in via `TokenBundle`; `active()` stays narrow (access token + account only) so callers that don't need refresh state don't pay extra keyring IPC. `AuthProvider` and `TokenStore` remain the escape hatches for DCR or fully bespoke backends. `logout` / `status` / `token` always attach `--user <ref>` and thread the parsed ref to `store.active(ref)` (and `store.clear(ref)` on `logout`). `commander` (when using the attachers), `open` (browser launch), and `@napi-rs/keyring` (when using `createSecureStore` or the keyring `TokenStore`) are optional peer/optional deps. |
18
+ | `commands` (subpath) | `registerChangelogCommand`, `registerUpdateCommand` (+ semver helpers) | Commander wiring for cli-core's standard commands (e.g. `<cli> changelog`, `<cli> update`, `<cli> update switch`). **Requires** `commander` as an optional peer-dep. |
19
+ | `config` | `getConfigPath`, `readConfig`, `readConfigStrict`, `writeConfig`, `updateConfig`, `CoreConfig`, `UpdateChannel` | Read / write a per-CLI JSON config file with typed error codes; `CoreConfig` is the shape of fields cli-core itself owns (extend it for per-CLI fields). |
20
+ | `empty` | `printEmpty` | Print an empty-state message gated on `--json` / `--ndjson` so machine consumers never see human strings on stdout. |
21
+ | `errors` | `CliError` | Typed CLI error class with `code` and exit-code mapping. |
22
+ | `global-args` | `parseGlobalArgs`, `stripUserFlag`, `createGlobalArgsStore`, `createAccessibleGate`, `createSpinnerGate`, `getProgressJsonlPath`, `isProgressJsonlEnabled` | Parse well-known global flags (`--json`, `--ndjson`, `--quiet`, `--verbose`, `--accessible`, `--no-spinner`, `--progress-jsonl`, `--user <ref>`) and derive predicates from them. `stripUserFlag` removes `--user` tokens from argv so the cleaned array can be forwarded to Commander when the flag has no root-program attachment. |
23
+ | `json` | `formatJson`, `formatNdjson` | Stable JSON / newline-delimited JSON formatting for stdout. |
24
+ | `markdown` (subpath) | `preloadMarkdown`, `renderMarkdown`, `TerminalRendererOptions` | Lazy-init terminal markdown renderer. **Requires** `marked` and `marked-terminal-renderer` as peer-deps — install only if your CLI uses this subpath. |
25
+ | `options` | `ViewOptions` | Type contract for `{ json?, ndjson? }` per-command options that machine-output gates derive from. |
26
+ | `spinner` | `createSpinner` | Loading spinner factory wrapping `yocto-spinner` with disable gates. |
27
+ | `terminal` | `isCI`, `isStderrTTY`, `isStdinTTY`, `isStdoutTTY` | TTY / CI detection helpers. |
28
+ | `testing` (subpath) | `describeEmptyMachineOutput` | Vitest helpers reusable by consuming CLIs (e.g. parametrised empty-state suite covering `--json` / `--ndjson` / human modes). |
29
29
 
30
30
  ## Usage
31
31
 
@@ -132,7 +132,7 @@ Wire `<cli> [auth] login` and the supporting OAuth runtime. cli-core ships the s
132
132
  npm install commander open
133
133
  ```
134
134
 
135
- `commander` is required when using `attachLoginCommand`. `open` is optional when it's missing or `open()` throws, the authorize URL is surfaced via `onAuthorizeUrl` (or printed to stdout in human mode, stderr in `--json` / `--ndjson` mode) so the user can complete the flow manually.
135
+ `commander` is required when using `attachLoginCommand`. `open` is optional. The authorize URL is **always** surfaced via `onAuthorizeUrl` (or printed to stdout in human mode, stderr in `--json` / `--ndjson` mode) — even when the browser launch succeeds — because the launch can resolve cleanly yet open no actual browser (WSL silent no-op, headless Linux, locked-down corporate envs). WSL hosts get routed through `cmd.exe` directly so the user's real Windows browser opens. Headless Linux skips the launch entirely and relies on the URL print.
136
136
 
137
137
  #### Quick start (PKCE)
138
138
 
@@ -229,10 +229,10 @@ Both attachers strip the standard `--json` / `--ndjson` / `--user` registrar fla
229
229
  | ------------------------ | -------------------------------------------------------------------------------------- |
230
230
  | `--read-only` | Threaded through to `resolveScopes` and the provider hooks via `readOnly`. |
231
231
  | `--callback-port <port>` | Override `preferredPort` per invocation. Validated as `[0..65535]`; `0` = OS-assigned. |
232
- | `--json` | Machine-output mode. Authorize-URL fallback is routed to stderr. |
233
- | `--ndjson` | Machine-output mode. Same fallback routing. |
232
+ | `--json` | Machine-output mode. Authorize-URL print is routed to stderr. |
233
+ | `--ndjson` | Machine-output mode. Same print routing. |
234
234
 
235
- Under `--json` / `--ndjson`, the authorize-URL fallback (printed when `open` is missing or `open()` throws) goes to stderr so the JSON / NDJSON envelope on stdout stays clean. Pass `onAuthorizeUrl` to override the destination. The success / error HTML returned by `renderSuccess` / `renderError` is a render hook — every CLI brings its own template (no shared layout enforced).
235
+ Under `--json` / `--ndjson`, the always-printed authorize URL goes to stderr so the JSON / NDJSON envelope on stdout stays clean. Pass `onAuthorizeUrl` to override the destination. The success / error HTML returned by `renderSuccess` / `renderError` is a render hook — every CLI brings its own template (no shared layout enforced).
236
236
 
237
237
  #### Implementing `TokenStore`
238
238
 
@@ -288,6 +288,14 @@ export const tokenStore: TokenStore<Account> = {
288
288
 
289
289
  For multi-account storage (OS keychain, per-user config slots, …), implement the same five methods against your backend and honour `ref` on `active` / `clear` / `setDefault`. `AccountRef` is an opaque `string` — cli-core does not constrain matching semantics (id-exact, email-case-insensitive, label, …). The store impl owns that.
290
290
 
291
+ ##### Refresh-token storage (`TokenBundle`)
292
+
293
+ Stores that target servers issuing refresh tokens may implement the optional `setBundle(account, bundle, options?)` method. `TokenBundle` carries `{ accessToken, refreshToken?, accessTokenExpiresAt?, refreshTokenExpiresAt? }`. Stores that omit `setBundle` continue to work — cli-core helpers (`persistBundle`) fall back to `set(account, bundle.accessToken)` and silently drop refresh state. `KeyringTokenStore` implements `setBundle` as a required override and routes the refresh token to a sibling keyring slot.
294
+
295
+ `active()` still returns the narrow `{ token, account }` snapshot — refresh-state material is stored but not surfaced on the hot read path so commands that only need the access token don't pay an extra keyring IPC. A bundle-aware read path lands alongside the silent-refresh helper in a follow-up PR.
296
+
297
+ The `persistBundle({ store, account, bundle, promoteDefault? })` helper is the recommended write path for bundle-capable consumers — it prefers `setBundle` when available and falls back to `set` otherwise (the `set` fallback can't honour `promoteDefault`, so multi-account stores wanting silent-refresh-safe selection must implement `setBundle`). cli-core's own `runOAuthFlow` still persists via `store.set()` today; it switches to `persistBundle` when the refresh helper lands.
298
+
291
299
  #### Keyring primitive (`createSecureStore`)
292
300
 
293
301
  When the OS credential manager is the right place for your token, `createSecureStore` is a thin cross-platform wrapper around `@napi-rs/keyring`. It exposes a three-method handle (`getSecret` / `setSecret` / `deleteSecret`) for one slot identified by `serviceName` + `account`:
@@ -22,8 +22,15 @@ export type RunOAuthFlowOptions<TAccount extends AuthAccount = AuthAccount> = {
22
22
  renderError: (message: string) => string;
23
23
  /** Override the browser opener (tests). When omitted, dynamically imports `open`. */
24
24
  openBrowser?: (url: string) => Promise<void>;
25
- /** Print the authorize URL to stdout as a fallback when the browser can't open it. */
26
- onAuthorizeUrl?: (url: string) => void;
25
+ /**
26
+ * Receives the authorize URL on every login attempt — not only when the
27
+ * browser launch fails — because the launch can resolve cleanly yet
28
+ * open no browser (WSL no-op, headless Linux, locked-down hosts).
29
+ * Treat as a fire-and-forget output channel: a sync hook is awaited,
30
+ * an async hook is awaited too, and any throw / rejection is swallowed
31
+ * so a buggy logger can never abort an otherwise-working login.
32
+ */
33
+ onAuthorizeUrl?: (url: string) => void | Promise<void>;
27
34
  /** Callback timeout in ms. Default 3 minutes. */
28
35
  timeoutMs?: number;
29
36
  /** Cancellation signal (Ctrl-C wiring). */
@@ -1 +1 @@
1
- {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/auth/flow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvE,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,WAAW,GAAG,WAAW,IAAI;IAC1E,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAA;IAChC,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;IAC3B,sCAAsC;IACtC,MAAM,EAAE,MAAM,EAAE,CAAA;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B,CAAC,QAAQ,CAAC,GACvC,OAAO,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CA0GvC"}
package/dist/auth/flow.js CHANGED
@@ -1,7 +1,38 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
1
3
  import { createServer } from 'node:http';
4
+ import { promisify } from 'node:util';
2
5
  import { CliError, getErrorMessage } from '../errors.js';
3
6
  import { isStdoutTTY } from '../terminal.js';
4
7
  import { generateState } from './pkce.js';
8
+ // WSL's `open` package routes through `xdg-open` / `wslview`, both of which
9
+ // silently no-op on headless WSL installs — the spawn resolves cleanly but no
10
+ // browser ever appears, so the OAuth callback wait runs to its 3-minute
11
+ // timeout. Detect at call time and route WSL through `cmd.exe` directly.
12
+ // Non-Linux platforms short-circuit before the fs read.
13
+ function isWsl() {
14
+ if (process.platform !== 'linux')
15
+ return false;
16
+ try {
17
+ return /microsoft/i.test(readFileSync('/proc/version', 'utf8'));
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
23
+ // SSH sessions, containers, CI runners, headless servers — same failure mode
24
+ // as WSL but with no Windows side to bounce through. With no DISPLAY /
25
+ // WAYLAND_DISPLAY (and no $BROWSER override for Codespaces-style setups
26
+ // that route through a remote bridge), `xdg-open` will either error or
27
+ // no-op, so the spawn is pure noise — skip it and let the URL print do the
28
+ // work.
29
+ function isHeadlessLinux() {
30
+ if (process.platform !== 'linux')
31
+ return false;
32
+ if (process.env.BROWSER)
33
+ return false;
34
+ return !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY;
35
+ }
5
36
  const DEFAULT_PORT_FALLBACK_COUNT = 5;
6
37
  const DEFAULT_CALLBACK_TIMEOUT_MS = 3 * 60 * 1000;
7
38
  const DEFAULT_CALLBACK_PATH = '/callback';
@@ -294,24 +325,41 @@ function assertValidPort(port, label) {
294
325
  }
295
326
  }
296
327
  async function openOrFallback(url, options) {
297
- const opener = options.openBrowser ?? (await loadDefaultOpener());
298
- if (opener) {
328
+ // Surface the URL up-front, before attempting the browser spawn. The
329
+ // spawn can succeed yet open no browser (WSL without working interop,
330
+ // headless Linux, locked-down corporate envs, missing `open` peer), and
331
+ // we have no reliable signal that the user actually landed on the page
332
+ // — so printing here guarantees a copy-pasteable path on every platform.
333
+ // The hook is purely an output channel: isolate its failures so a buggy
334
+ // logger can't abort the login that the user is actually here to do.
335
+ if (options.onAuthorizeUrl) {
299
336
  try {
300
- await opener(url);
301
- return;
337
+ await options.onAuthorizeUrl(url);
302
338
  }
303
339
  catch {
304
- // Fall through to the URL print below.
340
+ // Hook errors don't propagate.
305
341
  }
306
342
  }
307
- // No opener available, or the opener threw. Surface the URL so the user
308
- // can finish the flow manually.
309
- if (options.onAuthorizeUrl)
310
- options.onAuthorizeUrl(url);
311
343
  else if (isStdoutTTY())
312
344
  console.log(`Open this URL in your browser:\n ${url}`);
345
+ const opener = options.openBrowser ?? (await loadDefaultOpener());
346
+ if (!opener)
347
+ return;
348
+ try {
349
+ await opener(url);
350
+ }
351
+ catch {
352
+ // URL is already surfaced above.
353
+ }
313
354
  }
314
355
  async function loadDefaultOpener() {
356
+ // WSL check must run before the headless check: WSL is `platform === 'linux'`
357
+ // and often has no DISPLAY, but `cmd.exe` does work and reaches the user's
358
+ // real Windows browser, so it's worth the spawn.
359
+ if (isWsl())
360
+ return openViaCmdExe;
361
+ if (isHeadlessLinux())
362
+ return null;
315
363
  try {
316
364
  const mod = (await import('open'));
317
365
  return async (url) => {
@@ -322,4 +370,22 @@ async function loadDefaultOpener() {
322
370
  return null;
323
371
  }
324
372
  }
373
+ const execFileAsync = promisify(execFile);
374
+ // Two layers of escaping are needed because `cmd.exe /c` is a shell:
375
+ // 1. Wrap the URL in literal double quotes. WSL interop only auto-quotes
376
+ // args that contain spaces; an OAuth URL (no spaces, plenty of `&`s)
377
+ // would otherwise be re-parsed by cmd.exe with `&` acting as a
378
+ // statement separator, so only the prefix up to the first `&` would
379
+ // reach `start`.
380
+ // 2. Double every `%` to `%%`. cmd.exe expands `%NAME%` even inside
381
+ // quoted strings; OAuth URLs are full of percent-encoded bytes
382
+ // (`%3A`, `%2F`, …) and a chance match against a defined env var
383
+ // (`%PATH%`, `%TEMP%`, …) would silently mangle the URL.
384
+ // `start ""` — the empty title arg is mandatory; otherwise `start` consumes
385
+ // the URL as a window title and never launches a browser. (`execFile`'s
386
+ // no-shell guarantee doesn't apply when the target is itself a shell.)
387
+ async function openViaCmdExe(url) {
388
+ const escaped = url.replaceAll('%', '%%');
389
+ await execFileAsync('cmd.exe', ['/c', 'start', '""', `"${escaped}"`], { windowsHide: true });
390
+ }
325
391
  //# sourceMappingURL=flow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"flow.js","sourceRoot":"","sources":["../../src/auth/flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0D,YAAY,EAAE,MAAM,WAAW,CAAA;AAChG,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAuCzC,MAAM,2BAA2B,GAAG,CAAC,CAAA;AACrC,MAAM,2BAA2B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,qBAAqB,GAAG,WAAW,CAAA;AACzC,MAAM,qBAAqB,GAAG,WAAW,CAAA;AAEzC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAC9B,OAAsC;IAEtC,eAAe,CAAC,OAAO,CAAC,aAAa,EAAE,eAAe,CAAC,CAAA;IAEvD,MAAM,KAAK,GAAG,aAAa,EAAE,CAAA;IAC7B,IAAI,gBAAgB,GAA4B,EAAE,CAAA;IAElD,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC;QACrC,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,2BAA2B;QAC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sBAAsB;AACtB,sEAAsE;AACtE,oEAAoE;AACpE,sEAAsE;AACtE,8DAA8D;AAC9D,4EAA4E;AAC5E,wEAAwE;AACxE,uEAAuE;AACvE,KAAK,UAAU,aAAa,CAAC,GAAW;IACpC,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACzC,MAAM,aAAa,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,OAAO,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;AAChG,CAAC"}
@@ -11,9 +11,11 @@ export { attachTokenViewCommand } from './token-view.js';
11
11
  export type { AttachTokenViewCommandOptions } from './token-view.js';
12
12
  export { DEFAULT_VERIFIER_ALPHABET, deriveChallenge, generateState, generateVerifier, } from './pkce.js';
13
13
  export type { GenerateVerifierOptions } from './pkce.js';
14
+ export { persistBundle } from './persist.js';
15
+ export type { PersistBundleOptions } from './persist.js';
14
16
  export { createPkceProvider } from './providers/pkce.js';
15
17
  export type { PkceLazyString, PkceProviderOptions } from './providers/pkce.js';
16
- export type { AccountRef, AuthAccount, AuthorizeInput, AuthorizeResult, AuthProvider, ExchangeInput, ExchangeResult, PrepareInput, PrepareResult, TokenStore, ValidateInput, } from './types.js';
18
+ export type { AccountRef, AuthAccount, AuthorizeInput, AuthorizeResult, AuthProvider, ExchangeInput, ExchangeResult, PrepareInput, PrepareResult, RefreshInput, TokenBundle, TokenStore, ValidateInput, } from './types.js';
17
19
  export { SecureStoreUnavailableError, createKeyringTokenStore, createSecureStore, migrateLegacyAuth, } from './keyring/index.js';
18
20
  export type { CreateKeyringTokenStoreOptions, CreateSecureStoreOptions, KeyringTokenStore, MigrateAuthResult, MigrateLegacyAuthOptions, MigrateSkipReason, SecureStore, TokenStorageLocation, TokenStorageResult, UserRecord, UserRecordStore, } from './keyring/index.js';
19
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1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9E,YAAY,EACR,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,aAAa,GAChB,MAAM,YAAY,CAAA;AACnB,OAAO,EACH,2BAA2B,EAC3B,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,oBAAoB,CAAA;AAC3B,YAAY,EACR,8BAA8B,EAC9B,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,eAAe,GAClB,MAAM,oBAAoB,CAAA"}
@@ -4,6 +4,7 @@ export { attachLogoutCommand } from './logout.js';
4
4
  export { attachStatusCommand } from './status.js';
5
5
  export { attachTokenViewCommand } from './token-view.js';
6
6
  export { DEFAULT_VERIFIER_ALPHABET, deriveChallenge, generateState, generateVerifier, } from './pkce.js';
7
+ export { persistBundle } from './persist.js';
7
8
  export { createPkceProvider } from './providers/pkce.js';
8
9
  export { SecureStoreUnavailableError, createKeyringTokenStore, createSecureStore, migrateLegacyAuth, } from './keyring/index.js';
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAMjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,EACH,yBAAyB,EACzB,eAAe,EACf,aAAa,EACb,gBAAgB,GACnB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAexD,OAAO,EACH,2BAA2B,EAC3B,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAMjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,EACH,yBAAyB,EACzB,eAAe,EACf,aAAa,EACb,gBAAgB,GACnB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAiBxD,OAAO,EACH,2BAA2B,EAC3B,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,oBAAoB,CAAA"}
@@ -1,9 +1,16 @@
1
- import type { AuthAccount } from '../types.js';
1
+ import type { AuthAccount, TokenBundle } from '../types.js';
2
2
  import { type SecureStore } from './secure-store.js';
3
3
  import type { UserRecordStore } from './types.js';
4
4
  type WriteRecordOptions<TAccount extends AuthAccount> = {
5
5
  /** Per-account keyring slot, already configured by the caller (e.g. via `createSecureStore`). */
6
6
  secureStore: SecureStore;
7
+ /**
8
+ * Optional refresh-token keyring slot. When supplied, any orphan refresh
9
+ * material from a prior `setBundle` is wiped best-effort AFTER the user
10
+ * record is upserted (see the deferred-cleanup contract on
11
+ * `writeBundleWithKeyringFallback`).
12
+ */
13
+ refreshStore?: SecureStore;
7
14
  userRecords: UserRecordStore<TAccount>;
8
15
  account: TAccount;
9
16
  token: string;
@@ -12,23 +19,58 @@ type WriteRecordResult = {
12
19
  /** `true` when the secret landed in the OS keyring; `false` when the keyring was unavailable and the token was written to `fallbackToken` on the user record. */
13
20
  storedSecurely: boolean;
14
21
  };
22
+ type WriteBundleOptions<TAccount extends AuthAccount> = {
23
+ /** Per-account access-token keyring slot. */
24
+ accessStore: SecureStore;
25
+ /** Per-account refresh-token keyring slot. */
26
+ refreshStore: SecureStore;
27
+ userRecords: UserRecordStore<TAccount>;
28
+ account: TAccount;
29
+ bundle: TokenBundle;
30
+ };
31
+ type WriteBundleResult = {
32
+ /** `true` when the access token landed in the OS keyring; `false` when it fell back to `fallbackToken`. */
33
+ accessStoredSecurely: boolean;
34
+ /**
35
+ * `true` when a refresh token landed in the OS keyring. `false` when it
36
+ * fell back to `fallbackRefreshToken`. `undefined` when the bundle
37
+ * carried no refresh token (nothing to store).
38
+ */
39
+ refreshStoredSecurely: boolean | undefined;
40
+ };
15
41
  /**
16
- * Shared keyring-then-record write used by `createKeyringTokenStore.set` and
17
- * `migrateLegacyAuth`. Encapsulates the order-of-operations contract that
18
- * matters for credential safety:
19
- *
20
- * 1. Keyring `setSecret` first. On `SecureStoreUnavailableError`, swallow
21
- * the failure and record a `fallbackToken` on the user record instead.
22
- * Any other error rethrows.
23
- * 2. `userRecords.upsert(record)`. On failure, best-effort rollback the
24
- * keyring write so we don't leave an orphan credential for an account
25
- * cli-core never managed to register. Original error rethrows.
42
+ * Single-token write. Thin wrapper over `writeBundleWithKeyringFallback`
43
+ * passing a refresh-less bundle, so trim/validate, access-slot fallback,
44
+ * upsert rollback, and the deferred refresh-slot wipe all share one
45
+ * implementation.
26
46
  *
27
- * Default promotion (`setDefaultId`) is intentionally **not** in here both
28
- * call sites do it best-effort outside the critical section because it is a
29
- * preference, not a correctness requirement, and an error there must not
30
- * dirty up a successful credential write.
47
+ * `refreshStore` is optional purely for legacy callers (`migrateLegacyAuth`)
48
+ * that don't have one wired; the migrate path never had refresh state so
49
+ * skipping the wipe is correct there.
31
50
  */
32
51
  export declare function writeRecordWithKeyringFallback<TAccount extends AuthAccount>(options: WriteRecordOptions<TAccount>): Promise<WriteRecordResult>;
52
+ /**
53
+ * Two-slot write. Order: access slot → refresh slot → upsert → deferred
54
+ * refresh wipe.
55
+ *
56
+ * 1. Validate `bundle.accessToken` (non-empty after trim).
57
+ * 2. `accessStore.setSecret`. `SecureStoreUnavailableError` degrades to
58
+ * `fallbackToken` on the record; any other error rethrows.
59
+ * 3. `refreshStore.setSecret` when `bundle.refreshToken` is present.
60
+ * `SecureStoreUnavailableError` degrades to `fallbackRefreshToken`. A
61
+ * non-keyring failure rolls back the access slot before rethrowing
62
+ * (no partial credentials left behind for an unregistered user).
63
+ * 4. `userRecords.upsert(record)`. On failure, best-effort
64
+ * `Promise.allSettled` rollback of any slot writes that succeeded.
65
+ * 5. Only after a successful upsert: if the bundle has no refresh token,
66
+ * wipe any orphan slot from a prior `setBundle` (best-effort). Doing
67
+ * this BEFORE the upsert would lose refresh state if the upsert then
68
+ * rejected — the new record's `hasRefreshToken` would still claim
69
+ * false but the old slot would be gone with no rollback path.
70
+ *
71
+ * Default promotion is external — preference, not correctness, and an
72
+ * error there must not dirty up a successful credential write.
73
+ */
74
+ export declare function writeBundleWithKeyringFallback<TAccount extends AuthAccount>(options: WriteBundleOptions<TAccount>): Promise<WriteBundleResult>;
33
75
  export {};
34
76
  //# sourceMappingURL=record-write.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"record-write.d.ts","sourceRoot":"","sources":["../../../src/auth/keyring/record-write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,KAAK,WAAW,EAA+B,MAAM,mBAAmB,CAAA;AACjF,OAAO,KAAK,EAAc,eAAe,EAAE,MAAM,YAAY,CAAA;AAE7D,KAAK,kBAAkB,CAAC,QAAQ,SAAS,WAAW,IAAI;IACpD,iGAAiG;IACjG,WAAW,EAAE,WAAW,CAAA;IACxB,WAAW,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