@cloudflare/workers-auth 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,232 +1,8 @@
1
- import { ApiCredentials, ComplianceConfig } from '@cloudflare/workers-utils';
1
+ import { O as OAuthFlowLogger, U as UserAuthConfig, A as AuthConfigStorage, C as CredentialStore, F as FileFormat } from './file-format-CWtMNfzC.mjs';
2
+ export { a as ConfigStorage, D as DeactivateDirectoryResult, i as DirectoryBindingOperations, j as DirectoryBindingsStorage, L as LoginOrRefreshFailureReason, d as LoginOrRefreshResult, e as LoginProps, b as OAuthFlowContext, P as ProfileConfigOperations, k as ProfileStore, T as TemporaryPreviewAccount, c as createOAuthFlow, h as createProfileStore, g as generateAuthUrl, f as generateRandomState, v as validateProfileName } from './file-format-CWtMNfzC.mjs';
3
+ import { ApiCredentials } from '@cloudflare/workers-utils';
2
4
  import { SpawnSyncReturns } from 'node:child_process';
3
5
 
4
- /**
5
- * Pluggable persistence for a typed config blob.
6
- *
7
- */
8
- interface ConfigStorage<T> {
9
- /**
10
- * Read and parse the stored config.
11
- *
12
- * Consumers can treat a `read()` that resolves with `undefined` as
13
- * "not logged in / no temporary account / etc.", and leave error handling
14
- * for the surfaces that benefit from it.
15
- *
16
- * @returns `undefined` for the *empty* state — i.e. when the
17
- * backing store does not exist yet, or when it exists but no longer
18
- * contains usable data (e.g. encrypted-file present but the keyring entry
19
- * is missing, ciphertext fails its auth tag, deserialised payload is not
20
- * shaped like `T`). All of these collapse to "nothing usable stored
21
- * here" from the consumer's perspective, so the default is to return
22
- * `undefined` rather than throw.
23
- *
24
- * @throws *genuine* errors that the consumer needs to act on — typically
25
- * filesystem or permission failures (`EACCES`, `EISDIR`, disk full).
26
- * Those propagate so the user can see what's wrong, rather than silently
27
- * behaving as "not logged in".
28
- */
29
- read(): T | undefined;
30
- /** Serialize and persist the config. */
31
- write(config: T): void;
32
- /** Remove the backing store; returns whether anything existed beforehand. */
33
- clear(): boolean;
34
- /** Human-readable location of the backing store, for display and warnings. */
35
- path(): string;
36
- }
37
-
38
- /**
39
- * The data that may be read from the on-disk user auth config file.
40
- */
41
- interface UserAuthConfig {
42
- oauth_token?: string;
43
- refresh_token?: string;
44
- expiration_time?: string;
45
- scopes?: string[];
46
- /** @deprecated - this field was only provided by the deprecated v1 `wrangler config` command. */
47
- api_token?: string;
48
- }
49
- type AuthConfigStorage = ConfigStorage<UserAuthConfig>;
50
-
51
- /**
52
- * A short-lived "temporary preview account"
53
- */
54
- type TemporaryPreviewAccount = {
55
- account: {
56
- id: string;
57
- name: string;
58
- apiToken: string;
59
- expiresAt: string;
60
- };
61
- claim: {
62
- url: string;
63
- expiresAt: string;
64
- };
65
- };
66
- type TemporaryAccountStorage = ConfigStorage<TemporaryPreviewAccount>;
67
-
68
- interface GenerateAuthUrlProps {
69
- authUrl: string;
70
- clientId: string;
71
- scopes: string[];
72
- stateQueryParam: string;
73
- codeChallenge: string;
74
- redirectUri: string;
75
- }
76
- /**
77
- * Build the OAuth 2.0 authorize URL for the Cloudflare auth endpoint.
78
- *
79
- * Extracted from the rest of the OAuth flow so consumers (or tests) can
80
- * substitute a deterministic implementation when a stable URL is needed
81
- * (e.g. for snapshot testing).
82
- */
83
- declare const generateAuthUrl: ({ authUrl, clientId, scopes, stateQueryParam, codeChallenge, redirectUri, }: GenerateAuthUrlProps) => string;
84
-
85
- /**
86
- * Generates random state to be passed for anti-csrf.
87
- *
88
- * Extracted from the rest of the OAuth flow so consumers (or tests) can
89
- * substitute a deterministic implementation when a stable state value is
90
- * needed (e.g. for snapshot testing).
91
- */
92
- declare function generateRandomState(lengthOfState: number): string;
93
-
94
- /**
95
- * The dependencies the OAuth flow needs to mint/reuse a short-lived "temporary
96
- * preview account"
97
- */
98
- interface OAuthFlowTemporaryContext {
99
- /** Persistence backend for the cached temporary preview account. */
100
- storage: TemporaryAccountStorage;
101
- /**
102
- * Hook to customise the terms-acceptance interactive prompt
103
- * - question: the question to ask a user in interactive mode.
104
- * return answer === "yes" (must be the literal string)
105
- * - notice: the notice to print on stderr if in non-interactive mode
106
- * always return true
107
- */
108
- prompt: (question: string, notice: string) => Promise<boolean>;
109
- }
110
- /**
111
- * The branded OAuth consent pages the provider redirects the browser to after
112
- * the user grants or denies consent.
113
- */
114
- interface OAuthConsentPages {
115
- /** Redirect target shown after the user grants consent. */
116
- granted: {
117
- url: string;
118
- };
119
- /** Redirect target shown after the user denies consent, plus the error
120
- * surfaced to the terminal. */
121
- denied: {
122
- url: string;
123
- error: string;
124
- };
125
- }
126
- /**
127
- * Subset of the wrangler `logger` singleton used by the OAuth flow.
128
- * Consumers pass in an implementation that maps to their own logging surface.
129
- */
130
- interface OAuthFlowLogger {
131
- debug(...args: unknown[]): void;
132
- info(...args: unknown[]): void;
133
- log(...args: unknown[]): void;
134
- warn(...args: unknown[]): void;
135
- error(...args: unknown[]): void;
136
- }
137
- /**
138
- * Dependency-injection surface for {@link createOAuthFlow}.
139
- *
140
- * The OAuth flow only talks to OAuth endpoints (`/oauth2/auth`, `/oauth2/token`,
141
- * `/oauth2/revoke`) using `undici`'s `fetch` directly — there is no Cloudflare
142
- * API client wired into this context.
143
- */
144
- interface OAuthFlowContext {
145
- logger: OAuthFlowLogger;
146
- /**
147
- * Whether the process should not prompt the user. The OAuth flow uses this to
148
- * decide whether to short-circuit interactive login attempts.
149
- */
150
- isNonInteractiveOrCI: () => boolean;
151
- /**
152
- * Open the given URL in the user's default browser. Called during the
153
- * interactive OAuth login flow with the authorize URL.
154
- */
155
- openInBrowser: (url: string) => Promise<void>;
156
- /**
157
- * Whether environment-based credentials are present. When `true`, the OAuth
158
- * flow short-circuits because the env credentials take priority over stored
159
- * OAuth tokens:
160
- * - `login` refuses to start
161
- * - `logout` is a no-op (it cannot revoke env credentials)
162
- * - the refresh check returns `false` so an expired stored OAuth token does
163
- * not trigger a needless refresh attempt
164
- */
165
- hasEnvCredentials: () => boolean;
166
- /**
167
- * Called after a successful `login` or `logout` so the consumer can invalidate
168
- * any caches that depend on the active token (e.g. wrangler's selected-account
169
- * cache).
170
- */
171
- purgeOnLoginOrLogout?: () => void;
172
- /**
173
- * The OAuth client ID identifying the consuming CLI to the Cloudflare OAuth
174
- * server. Consumer-specific (each CLI registers its own OAuth app), so it is
175
- * required. Pass a function to resolve it lazily — e.g. so an env-var read at
176
- * call time can switch between production and staging apps.
177
- */
178
- clientId: string | (() => string);
179
- /**
180
- * The branded consent pages the provider redirects to after the user grants
181
- * or denies consent.
182
- */
183
- consent: OAuthConsentPages;
184
- /**
185
- * The `redirect_uri` registered on the consumer's OAuth app
186
- */
187
- redirectUri: string;
188
- /**
189
- * Factory that returns a persistence backend for the given auth profile.
190
- *
191
- * Called with the active profile name (e.g. `"default"`) on every storage
192
- * access so the flow always reads/writes the correct backing store.
193
- * The consumer is responsible for mapping profile names to concrete storage
194
- * backends (e.g. wrangler maps each profile to a separate TOML file under
195
- * the global config directory).
196
- *
197
- * Consumers that want OS-keyring-backed encryption pass the
198
- * `storageFactory` from {@link createCredentialStorageContext} (in the
199
- * `credential-store` module) — for each profile that adapter resolves
200
- * between the plaintext TOML file and the encrypted-file-with-keyring-key
201
- * implementation on every call, so runtime preference changes
202
- * (`--use-keyring` / `CLOUDFLARE_AUTH_USE_KEYRING`) take effect without
203
- * rebuilding the flow.
204
- */
205
- storageFactory: (profile?: string) => AuthConfigStorage;
206
- /**
207
- * Whether the flow's credential resolvers (`getAPIToken` / `requireApiToken`)
208
- * should honour the global API key + email pair in addition to scoped API
209
- * tokens.
210
- */
211
- allowGlobalAuthKey: boolean;
212
- /**
213
- * Dependencies for minting/reusing a temporary preview account.
214
- */
215
- temporary: OAuthFlowTemporaryContext | undefined;
216
- /**
217
- * Override the OAuth authorize URL generator. Used by tests to produce a
218
- * deterministic URL for snapshot testing. Defaults to the standard
219
- * implementation.
220
- */
221
- generateAuthUrl?: typeof generateAuthUrl;
222
- /**
223
- * Override the random state generator. Used by tests to produce a
224
- * deterministic state value for snapshot testing. Defaults to the standard
225
- * implementation.
226
- */
227
- generateRandomState?: typeof generateRandomState;
228
- }
229
-
230
6
  /** `CLOUDFLARE_API_TOKEN` (legacy alias `CF_API_TOKEN`): a scoped API token. */
231
7
  declare const getCloudflareAPITokenFromEnv: () => string | undefined;
232
8
  /** `CLOUDFLARE_API_KEY` (legacy alias `CF_API_KEY`): the global API key. */
@@ -297,6 +73,14 @@ declare function getAccessHeaders(domain: string, options: {
297
73
  * `WRANGLER_API_ENVIRONMENT=staging` environment variable instead.
298
74
  */
299
75
  declare const getAuthUrlFromEnv: () => string;
76
+ /**
77
+ * `CLOUDFLARE_ACCOUNT_ID` overrides the account inferred from the current user.
78
+ *
79
+ * This is a Cloudflare-wide variable (not wrangler-specific), so it lives in the
80
+ * shared core rather than a consumer layer. `CF_ACCOUNT_ID` is the deprecated
81
+ * spelling.
82
+ */
83
+ declare const getCloudflareAccountIdFromEnv: () => string | undefined;
300
84
  /**
301
85
  * `CLOUDFLARE_AUTH_USE_KEYRING` overrides where OAuth credentials are stored.
302
86
  *
@@ -312,173 +96,6 @@ declare const getAuthUrlFromEnv: () => string;
312
96
  */
313
97
  declare const getCloudflareAuthUseKeyringFromEnv: () => boolean | undefined;
314
98
 
315
- /**
316
- * Reason why {@link OAuthFlowAPI.loginOrRefreshIfRequired} could not
317
- * authenticate the user.
318
- */
319
- type LoginOrRefreshFailureReason =
320
- /** no stored credentials and the environment is non-interactive (CI, piped stdin, etc.) so a browser login cannot be started. */
321
- "no-credentials-non-interactive"
322
- /** stored credentials and the interactive login attempt was unsuccessful (user cancelled, etc.). */
323
- | "no-credentials-login-failed"
324
- /** the stored token has expired, refresh failed, and the environment is non-interactive so a browser login cannot be started. */
325
- | "token-expired-non-interactive"
326
- /** the stored token has expired, refresh failed, and the interactive login attempt was unsuccessful. */
327
- | "token-expired-login-failed";
328
- /**
329
- * Discriminated union returned by {@link OAuthFlowAPI.loginOrRefreshIfRequired}.
330
- *
331
- * When `loggedIn` is `true` the caller can proceed. When `false`, `reason`
332
- * describes why authentication failed so the caller can surface a
333
- * targeted error message.
334
- */
335
- type LoginOrRefreshResult = {
336
- loggedIn: true;
337
- } | {
338
- loggedIn: false;
339
- reason: LoginOrRefreshFailureReason;
340
- };
341
- /**
342
- * Options for an interactive OAuth login.
343
- */
344
- interface LoginProps {
345
- complianceConfig: ComplianceConfig;
346
- /**
347
- * The OAuth scopes to request. The catalog of valid scope keys is
348
- * consumer-defined; this package treats scopes as opaque strings.
349
- */
350
- scopes: string[];
351
- /**
352
- * Whether to open the authorize URL in a browser. Defaults to `true`.
353
- * When `false` the URL is printed for the user to copy/paste.
354
- */
355
- browser?: boolean;
356
- /** Host the local callback server listens on. Defaults to `localhost`. */
357
- callbackHost?: string;
358
- /** Port the local callback server listens on. Defaults to `8976`. */
359
- callbackPort?: number;
360
- /**
361
- * Named auth profile to store the token under. When omitted, the default
362
- * profile (`default.toml`) is used.
363
- * Only for use by 'auth create', not exposed to the user
364
- */
365
- profile?: string;
366
- }
367
- /**
368
- * Public surface returned by {@link createOAuthFlow}.
369
- */
370
- interface OAuthFlowAPI {
371
- /**
372
- * Set the active auth profile for all subsequent storage lookups.
373
- *
374
- * Called once at top of command dispatch by the consumer after resolving the
375
- * active profile. `"default"` if never called.
376
- */
377
- setProfile(profile: string): void;
378
- getActiveProfile(): string;
379
- /**
380
- * Open the authorize URL in the user's browser, wait for the callback to be
381
- * hit on the local HTTP server, exchange the code for an access token, and
382
- * persist the result to disk.
383
- *
384
- * Refuses to start when `ctx.hasEnvCredentials()` returns `true`.
385
- * Refuses to start when the compliance region is `fedramp_high`.
386
- *
387
- * When `props.profile` is set, the token is stored under that profile
388
- * instead of the active one. This is used by `auth create <name>`.
389
- *
390
- * @returns `true` on success, `false` when env credentials are present.
391
- */
392
- login(props: LoginProps): Promise<boolean>;
393
- /**
394
- * Revoke the stored refresh token at the Cloudflare OAuth endpoint and
395
- * delete the on-disk auth config file.
396
- *
397
- * No-op when `ctx.hasEnvCredentials()` returns `true` (env credentials
398
- * cannot be revoked).
399
- *
400
- * When `profile` is passed, operates on that profile instead of the
401
- * active one. This is used by `auth delete <name>`.
402
- */
403
- logout(profile?: string): Promise<void>;
404
- /**
405
- * If the user has no stored OAuth token, attempt an interactive login.
406
- * If they have one but it is expired, attempt a refresh; if refresh fails,
407
- * fall back to an interactive login.
408
- *
409
- * Scopes are required in case an interactive login is triggered — the
410
- * consumer's scope catalog lives outside this package.
411
- *
412
- * @returns `{ loggedIn: true }` when the user is authenticated (or env
413
- * credentials are present). When authentication fails, returns
414
- * `{ loggedIn: false, reason }` describing why — see
415
- * {@link LoginOrRefreshFailureReason}.
416
- */
417
- loginOrRefreshIfRequired(props: LoginProps): Promise<LoginOrRefreshResult>;
418
- /**
419
- * Read the OAuth access token from local state, refreshing it first if
420
- * needed. Returns `undefined` when there is no stored OAuth token or the
421
- * refresh fails.
422
- *
423
- * This intentionally does NOT consult env credentials — callers that want
424
- * env-or-OAuth resolution should check env first themselves.
425
- */
426
- getOAuthTokenFromLocalState(): Promise<string | undefined>;
427
- /**
428
- * Resolve API credentials, preferring an active temporary preview account
429
- * (when one has been latched via {@link activateTemporaryAccount}) over the
430
- * env / stored-OAuth resolution performed by the shared credential resolver.
431
- *
432
- * Returns `undefined` when no credentials are available.
433
- */
434
- getAPIToken(): ApiCredentials | undefined;
435
- /**
436
- * Like {@link getAPIToken}, but throws a `UserError` when no credentials are
437
- * available.
438
- */
439
- requireApiToken(): ApiCredentials;
440
- /**
441
- * Return the scopes granted to the stored OAuth token for the active
442
- * profile, or `undefined` when no OAuth token is stored.
443
- */
444
- getScopes(): string[] | undefined;
445
- /**
446
- * Establish whether `--temporary` is permitted for this invocation. Called
447
- * once at command dispatch by the consumer. Also drops any temporary account
448
- * latched by a previous dispatch, so that — when multiple commands share a
449
- * process (e.g. in tests) — each invocation starts a fresh temporary session.
450
- * No-op when the flow was created without a `temporary` context.
451
- */
452
- setTemporaryAllowed(allowed: boolean): void;
453
- /**
454
- * Whether `--temporary` is permitted for this invocation (see
455
- * {@link setTemporaryAllowed}). Always `false` without a `temporary` context.
456
- */
457
- isTemporaryAllowed(): boolean;
458
- /**
459
- * The temporary preview account latched for this invocation, or `undefined`.
460
- * Only set after {@link activateTemporaryAccount} has run.
461
- */
462
- getActiveTemporaryAccount(): TemporaryPreviewAccount | undefined;
463
- /**
464
- * The sole creator of the temporary-account latch: mint a fresh temporary
465
- * preview account (or reuse a cached one), latch it for this invocation, and
466
- * return it. Requires a `temporary` context.
467
- */
468
- activateTemporaryAccount(): Promise<{
469
- account: TemporaryPreviewAccount;
470
- cached: boolean;
471
- }>;
472
- }
473
- /**
474
- * Build an instance of the OAuth flow bound to the given context.
475
- *
476
- * The returned object owns module-private state (the transient OAuth flow
477
- * state and the deprecated-v1 warning latch). In practice consumers create
478
- * exactly one instance per process.
479
- */
480
- declare function createOAuthFlow(ctx: OAuthFlowContext): OAuthFlowAPI;
481
-
482
99
  declare const TEMPORARY_TERMS_PROMPT: string;
483
100
  declare const TEMPORARY_TERMS_NOTICE: string;
484
101
 
@@ -487,43 +104,6 @@ declare const TEMPORARY_TERMS_NOTICE: string;
487
104
  */
488
105
  declare const PKCE_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
489
106
 
490
- interface ProfileConfigOperations {
491
- exists(profile: string): boolean;
492
- list(): string[];
493
- delete(profile: string): void;
494
- }
495
- interface DirectoryBindingsStorage {
496
- read(): Record<string, string>;
497
- write(bindings: Record<string, string>): void;
498
- }
499
- interface DirectoryBindingOperations extends DirectoryBindingsStorage {
500
- activate(profile: string, dir: string): void;
501
- deactivate(dir: string): DeactivateDirectoryResult;
502
- getProfileForDirectory(startDir: string): string | undefined;
503
- getBindingsForProfile(profile: string): string[];
504
- removeAllBindingsForProfile(profile: string): string[];
505
- }
506
- interface ProfileStore {
507
- configs: ProfileConfigOperations;
508
- bindings: DirectoryBindingOperations;
509
- resolve(args: {
510
- profile?: string;
511
- cwd: string;
512
- }): string;
513
- }
514
- interface DeactivateDirectoryResult {
515
- removedProfile: string;
516
- newResolution: {
517
- profile: string | undefined;
518
- source: string;
519
- };
520
- }
521
- declare function createProfileStore(args: {
522
- configs: ProfileConfigOperations;
523
- bindings: DirectoryBindingsStorage;
524
- }): ProfileStore;
525
- declare function validateProfileName(name: string): void;
526
-
527
107
  interface RefreshToken {
528
108
  value: string;
529
109
  }
@@ -568,41 +148,6 @@ declare function readStoredAuthState(options: {
568
148
  storage: AuthConfigStorage;
569
149
  }): StoredAuthState;
570
150
 
571
- /**
572
- * Pluggable backend for the persisted OAuth credentials.
573
- *
574
- * Concrete implementations:
575
- * - {@link FileCredentialStore} — the plaintext TOML file at
576
- * `<globalWranglerConfigPath>/config/<env>.toml`. Used by default and as
577
- * a fallback when keyring storage is unavailable.
578
- * - {@link EncryptedFileCredentialStore} — an AES-256-GCM-encrypted file at
579
- * `<globalWranglerConfigPath>/config/<env>.enc`, with the encryption key
580
- * stored in the OS keyring via a {@link KeyProvider}.
581
- *
582
- * Extends the consumer-facing {@link AuthConfigStorage} contract with two
583
- * keyring-specific extras:
584
- * - `kind`: discriminant so consumers can tell apart "plain file" and
585
- * "encrypted file" stores without sniffing for methods.
586
- * - `describe()`: human-readable, possibly multi-line description (e.g.
587
- * `"Encrypted file (path) with key in macOS Keychain"`) for surfaces
588
- * like `wrangler whoami` that want richer copy than the raw `path()`.
589
- *
590
- * The interface is synchronous so it can be plugged into existing
591
- * `AuthConfigStorage` call sites without forcing every caller to become
592
- * async. Under the hood, both implementations use synchronous primitives
593
- * (subprocess `spawnSync`, `@napi-rs/keyring`'s sync `Entry` class,
594
- * `node:crypto` sync APIs, synchronous filesystem calls).
595
- */
596
- interface CredentialStore extends AuthConfigStorage {
597
- readonly kind: "file" | "encrypted-file";
598
- /**
599
- * Human-readable description of where credentials are stored, suitable
600
- * for consumers' `whoami`-style output. May be multi-line / richer
601
- * than the raw `path()`.
602
- */
603
- describe(): string;
604
- }
605
-
606
151
  /**
607
152
  * Absolute path to the plaintext TOML credentials file for the given auth
608
153
  * profile (defaulting to the active Cloudflare API environment's default
@@ -617,7 +162,7 @@ interface CredentialStore extends AuthConfigStorage {
617
162
  * defensive scrubs on logout, and tests that assert against it can all point at
618
163
  * the same location as the {@link FileCredentialStore}.
619
164
  */
620
- declare function getAuthConfigFilePath(configPath: string, profile?: string): string;
165
+ declare function getAuthConfigFilePath(configPath: string, profile?: string, extension?: string): string;
621
166
  /**
622
167
  * The plaintext-TOML credentials store.
623
168
  *
@@ -628,14 +173,18 @@ declare function getAuthConfigFilePath(configPath: string, profile?: string): st
628
173
  declare class FileCredentialStore implements CredentialStore {
629
174
  private readonly configPath;
630
175
  private readonly profile?;
176
+ private readonly format;
631
177
  readonly kind: "file";
632
178
  /**
633
179
  * @param configPath consumer-provided global config directory (the CLI
634
180
  * owns where its config lives, so workers-auth never resolves it itself).
635
181
  * @param profile the auth profile (defaults to the active environment's
636
182
  * default profile).
183
+ * @param format on-disk file format (defaults to TOML for wrangler's
184
+ * historical layout; cf and other CLIs pass JSON).
637
185
  */
638
- constructor(configPath: string, profile?: string | undefined);
186
+ constructor(configPath: string, profile?: string | undefined, format?: FileFormat);
187
+ private filePath;
639
188
  read(): UserAuthConfig | undefined;
640
189
  write(config: UserAuthConfig): void;
641
190
  clear(): boolean;
@@ -730,17 +279,21 @@ declare class EncryptedFileCredentialStore implements CredentialStore {
730
279
  private readonly keyProvider;
731
280
  private readonly onPlaintextMigration?;
732
281
  private readonly profile?;
282
+ private readonly format;
733
283
  readonly kind: "encrypted-file";
734
284
  /**
735
285
  * @param configPath consumer-provided global config directory (the CLI
736
286
  * owns where its config lives, so workers-auth never resolves it itself).
737
287
  * @param keyProvider the OS-keyring backend holding the encryption key.
738
288
  * @param onPlaintextMigration optional callback invoked when a plaintext
739
- * TOML file is migrated into the encrypted layout on first read.
289
+ * file is migrated into the encrypted layout on first read.
740
290
  * @param profile the auth profile (defaults to the active environment's
741
291
  * default profile).
292
+ * @param format on-disk format of the plaintext sibling file and the
293
+ * encrypted payload (defaults to TOML for wrangler).
742
294
  */
743
- constructor(configPath: string, keyProvider: KeyProvider, onPlaintextMigration?: OnPlaintextMigration | undefined, profile?: string | undefined);
295
+ constructor(configPath: string, keyProvider: KeyProvider, onPlaintextMigration?: OnPlaintextMigration | undefined, profile?: string | undefined, format?: FileFormat);
296
+ private plaintextPath;
744
297
  read(): UserAuthConfig | undefined;
745
298
  write(config: UserAuthConfig): void;
746
299
  clear(): boolean;
@@ -796,11 +349,18 @@ interface CredentialStorageContext {
796
349
  /** Whether the process should not prompt the user. */
797
350
  isNonInteractiveOrCI: () => boolean;
798
351
  /**
799
- * Consumer's CLI name for error-message templating, e.g. `"wrangler"`.
800
- * Used in hints like ``Run `<cliName> login --use-keyring` …``.
801
- * Defaults to `"your CLI"` when omitted.
352
+ * Login command for error-message templating, e.g. `"wrangler login"`.
353
+ * Defaults to `"your CLI login"` when omitted.
354
+ */
355
+ loginCommand?: string;
356
+ /**
357
+ * On-disk format of the plaintext credentials file (`.toml` / `.json`).
358
+ * Defaults to TOML for wrangler; cf and other CLIs pass JSON. The encrypted
359
+ * `.enc` sibling is format-independent (its payload is opaque ciphertext),
360
+ * but the format still governs the plaintext file extension and the
361
+ * plaintext→encrypted migration read.
802
362
  */
803
- cliName?: string;
363
+ format?: FileFormat;
804
364
  }
805
365
  /**
806
366
  * Bundle returned by {@link createCredentialStorageContext}.
@@ -885,6 +445,7 @@ declare function scrubEncryptedCredentials(options: {
885
445
  serviceName: string;
886
446
  configPath: string;
887
447
  profile?: string;
448
+ format?: FileFormat;
888
449
  }): ScrubEncryptedCredentialsResult;
889
450
 
890
451
  /**
@@ -1222,4 +783,4 @@ declare function decryptString(envelope: EncryptedEnvelope, key: Uint8Array): st
1222
783
  */
1223
784
  declare function parseEncryptedEnvelope(raw: unknown): EncryptedEnvelope | undefined;
1224
785
 
1225
- export { type AuthConfigStorage, type ConfigStorage, type CredentialStorageBundle, type CredentialStorageContext, type CredentialStore, type DeactivateDirectoryResult, type DirectoryBindingOperations, type DirectoryBindingsStorage, type EncryptedEnvelope, EncryptedFileCredentialStore, FileCredentialStore, type KeyProvider, type KeyProviderResolution, type KeyringEntry, type KeyringEntryFactory, LinuxSecretToolKeyProvider, type LinuxSecretToolRunner, type LoginOrRefreshFailureReason, type LoginOrRefreshResult, type LoginProps, type MacSecurityCommandRunner, MacSecurityKeyProvider, NapiKeyringKeyProvider, type NpmRunner, type OAuthFlowContext, type OAuthFlowLogger, PINNED_KEYRING_VERSION, PKCE_CHARSET, type ProfileConfigOperations, type ProfileStore, type ScrubEncryptedCredentialsResult, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, type TemporaryPreviewAccount, type UserAuthConfig, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, createOAuthFlow, createProfileStore, decryptString, domainUsesAccess, encryptString, findKeyringBinding, generateAuthUrl, generateKey, generateRandomState, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, validateProfileName };
786
+ export { AuthConfigStorage, type CredentialStorageBundle, type CredentialStorageContext, CredentialStore, type EncryptedEnvelope, EncryptedFileCredentialStore, FileCredentialStore, type KeyProvider, type KeyProviderResolution, type KeyringEntry, type KeyringEntryFactory, LinuxSecretToolKeyProvider, type LinuxSecretToolRunner, type MacSecurityCommandRunner, MacSecurityKeyProvider, NapiKeyringKeyProvider, type NpmRunner, OAuthFlowLogger, PINNED_KEYRING_VERSION, PKCE_CHARSET, type ScrubEncryptedCredentialsResult, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, UserAuthConfig, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, decryptString, domainUsesAccess, encryptString, findKeyringBinding, generateKey, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner };