@cloudflare/workers-auth 0.16.0 → 0.18.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.
@@ -1,7 +1,7 @@
1
1
  import { b as ConfigStorage, A as AuthConfigStorage, U as UserAuthConfig, g as OAuthFlowContext, h as ProfileStore } from '../authentication-error-DcqALFv6.mjs';
2
2
  export { a as AuthenticationError } from '../authentication-error-DcqALFv6.mjs';
3
- import { C as CliDescriptor, A as AuthContext, a as CloudflareAuth, U as UserPreferences, K as KeyringPreferenceContext, S as SetKeyringPreferenceResult } from '../keyring-preference-DGkctqNO.mjs';
4
- export { b as CloudflareLoginProps } from '../keyring-preference-DGkctqNO.mjs';
3
+ import { C as CliDescriptor, A as AuthContext, a as CloudflareAuth, U as UserPreferences, K as KeyringPreferenceContext, S as SetKeyringPreferenceResult } from '../keyring-preference-BUyxOJDK.mjs';
4
+ export { b as CloudflareLoginProps } from '../keyring-preference-BUyxOJDK.mjs';
5
5
  import '@cloudflare/workers-utils';
6
6
 
7
7
  /**
package/dist/cf/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
- import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-YWQXTXOY.mjs';
3
- export { AuthenticationError } from '../chunk-SOBRPAPT.mjs';
2
+ import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-PCKGSFVR.mjs';
3
+ export { AuthenticationError } from '../chunk-Q5KVZMHK.mjs';
4
4
  import { __name } from '../chunk-VAZEJK55.mjs';
5
5
  import { getEnvironmentVariableFactory, getGlobalConfigPath, getCloudflareApiEnvironmentFromEnv } from '@cloudflare/workers-utils';
6
6
  import path from 'node:path';
@@ -597,9 +597,8 @@ var CF_CLI = {
597
597
  // cf gets its own cache dir (`.cache/cloudflare` / `.cloudflare/cache`) so
598
598
  // `cf auth login`/`logout` never purges wrangler's shared cache.
599
599
  cacheNamespace: "cloudflare",
600
- // cf persists its default account in `config.json` (`defaults.accountId`);
601
- // this label is surfaced in the "set account_id in your <file>" hint.
602
- getConfigFileLabel: /* @__PURE__ */ __name(() => "cf config", "getConfigFileLabel"),
600
+ // This label is surfaced in shared account configuration hints.
601
+ getConfigFileLabel: /* @__PURE__ */ __name(() => "cloudflare.config.ts", "getConfigFileLabel"),
603
602
  getDefaultScopeKeys: /* @__PURE__ */ __name(() => DefaultScopeKeys, "getDefaultScopeKeys")
604
603
  };
605
604
  var cfPreferences = createPreferences(getCfConfigPath);
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'node:module';
2
- import { stringifyFile, parseFile, dedent, DEFAULT_TEMPORARY_ACCOUNT_FLAG, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, AuthenticationError, validateAccountId, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-SOBRPAPT.mjs';
2
+ import { stringifyFile, parseFile, dedent, DEFAULT_TEMPORARY_ACCOUNT_FLAG, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, AuthenticationError, validateAccountId, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-Q5KVZMHK.mjs';
3
3
  import { __name } from './chunk-VAZEJK55.mjs';
4
4
  import { existsSync, rmSync, mkdirSync, writeFileSync, chmodSync, readFileSync as readFileSync$1, readdirSync } from 'node:fs';
5
5
  import path3 from 'node:path';
@@ -793,10 +793,22 @@ function createCloudflareAuth(descriptor, ctx) {
793
793
  const NOT_LOGGED_IN_WHOAMI_TIP = `
794
794
  Run \`${descriptor.commands.whoami}\` to check your current authentication status.`;
795
795
  const preferences = createPreferences(descriptor.getConfigPath);
796
+ const persistAccountSelection = descriptor.persistAccountSelection ?? false;
796
797
  const configCache = createConfigCache(
797
798
  logger,
798
799
  descriptor.cacheNamespace ? { namespace: descriptor.cacheNamespace } : void 0
799
800
  );
801
+ let accountSelection;
802
+ let accountSelectionPromise;
803
+ function clearAccountSelection() {
804
+ accountSelection = void 0;
805
+ }
806
+ __name(clearAccountSelection, "clearAccountSelection");
807
+ function purgeAccountCaches() {
808
+ clearAccountSelection();
809
+ configCache.purgeConfigCaches();
810
+ }
811
+ __name(purgeAccountCaches, "purgeAccountCaches");
800
812
  const credentialStorage = createCredentialStorageContext({
801
813
  serviceName: descriptor.keyringServiceName,
802
814
  getConfigPath: descriptor.getConfigPath,
@@ -812,7 +824,7 @@ Run \`${descriptor.commands.whoami}\` to check your current authentication statu
812
824
  isNonInteractiveOrCI: isNonInteractiveOrCI,
813
825
  openInBrowser: /* @__PURE__ */ __name((url) => openInBrowser(url, logger), "openInBrowser"),
814
826
  hasEnvCredentials: /* @__PURE__ */ __name(() => getAuthFromEnv({ allowGlobalAuthKey }) !== void 0, "hasEnvCredentials"),
815
- purgeOnLoginOrLogout: configCache.purgeConfigCaches,
827
+ purgeOnLoginOrLogout: purgeAccountCaches,
816
828
  clientId: descriptor.clientId,
817
829
  consent: descriptor.consent,
818
830
  cliDisplayName: descriptor.displayName,
@@ -904,6 +916,7 @@ Run \`${descriptor.commands.whoami}\` to check your current authentication statu
904
916
  }
905
917
  __name(readAuthCredentials, "readAuthCredentials");
906
918
  function writeAuthCredentials(config) {
919
+ clearAccountSelection();
907
920
  credentialStorage.storageFactory(getActiveProfile()).write(config);
908
921
  }
909
922
  __name(writeAuthCredentials, "writeAuthCredentials");
@@ -915,14 +928,34 @@ Run \`${descriptor.commands.whoami}\` to check your current authentication statu
915
928
  return `${descriptor.accountCachePrefix}-${profile}.json`;
916
929
  }
917
930
  __name(getAccountCacheFileName, "getAccountCacheFileName");
918
- function saveAccountToCache(account) {
919
- configCache.saveToConfigCache(
920
- getAccountCacheFileName(),
921
- { account }
922
- );
931
+ function retainAccountSelection(account) {
932
+ accountSelection = {
933
+ account,
934
+ profile: getActiveProfile()
935
+ };
936
+ if (persistAccountSelection) {
937
+ configCache.saveToConfigCache(
938
+ getAccountCacheFileName(),
939
+ { account }
940
+ );
941
+ }
923
942
  }
924
- __name(saveAccountToCache, "saveAccountToCache");
943
+ __name(retainAccountSelection, "retainAccountSelection");
944
+ function resolveAccountSelection() {
945
+ const profile = getActiveProfile();
946
+ if (persistAccountSelection) {
947
+ const account = getAccountFromCache();
948
+ accountSelection = account ? { account, profile } : void 0;
949
+ } else if (accountSelection?.profile !== profile) {
950
+ clearAccountSelection();
951
+ }
952
+ return accountSelection?.account;
953
+ }
954
+ __name(resolveAccountSelection, "resolveAccountSelection");
925
955
  function getAccountFromCache() {
956
+ if (!persistAccountSelection) {
957
+ return void 0;
958
+ }
926
959
  return configCache.getConfigCache(
927
960
  getAccountCacheFileName()
928
961
  ).account;
@@ -993,13 +1026,13 @@ Run \`${descriptor.commands.whoami}\` to check your current authentication statu
993
1026
  `Failed to automatically retrieve account IDs for the logged in user.
994
1027
  You may have incorrect permissions on your API token, or an environment variable such as CLOUDFLARE_API_TOKEN, CLOUDFLARE_API_KEY, or CLOUDFLARE_EMAIL may be set to an invalid value.
995
1028
  Check your environment and unset or correct any Cloudflare credential variables, or run \`${descriptor.commands.login}\` to re-authenticate.
996
- You can also skip this account check by adding an \`account_id\` in your ${descriptor.getConfigFileLabel()} file, or by setting the value of CLOUDFLARE_ACCOUNT_ID`,
1029
+ You can also skip this account check by adding an account ID to your ${descriptor.getConfigFileLabel()} file, or by setting the value of CLOUDFLARE_ACCOUNT_ID`,
997
1030
  { telemetryMessage: "user account fetch permission denied" }
998
1031
  );
999
1032
  }
1000
1033
  throw new UserError(
1001
1034
  `Failed to automatically retrieve account IDs for the logged in user.
1002
- You may have incorrect permissions on your API token, or your authentication may have expired. Try running \`${descriptor.commands.login}\` to re-authenticate. You can also skip this account check by adding an \`account_id\` in your ${descriptor.getConfigFileLabel()} file, or by setting the value of CLOUDFLARE_ACCOUNT_ID`,
1035
+ You may have incorrect permissions on your API token, or your authentication may have expired. Try running \`${descriptor.commands.login}\` to re-authenticate. You can also skip this account check by adding an account ID to your ${descriptor.getConfigFileLabel()} file, or by setting the value of CLOUDFLARE_ACCOUNT_ID`,
1003
1036
  { telemetryMessage: "user account fetch permission denied" }
1004
1037
  );
1005
1038
  } else {
@@ -1015,7 +1048,7 @@ You may have incorrect permissions on your API token, or your authentication may
1015
1048
  if (usableAccounts.length === 0 && throwOnEmpty) {
1016
1049
  throw new UserError(
1017
1050
  `Failed to automatically retrieve account IDs for the logged in user.
1018
- In a non-interactive environment, it is mandatory to specify an account ID, either by assigning its value to CLOUDFLARE_ACCOUNT_ID, or as \`account_id\` in your ${descriptor.getConfigFileLabel()} file.
1051
+ In a non-interactive environment, it is mandatory to specify an account ID, either by assigning its value to CLOUDFLARE_ACCOUNT_ID, or in your ${descriptor.getConfigFileLabel()} file.
1019
1052
  Alternatively, try running \`${descriptor.commands.login}\` to re-authenticate.`,
1020
1053
  { telemetryMessage: "user account fetch empty" }
1021
1054
  );
@@ -1031,24 +1064,20 @@ Alternatively, try running \`${descriptor.commands.login}\` to re-authenticate.`
1031
1064
  if (config.account_id) {
1032
1065
  return validateAccountId(
1033
1066
  config.account_id,
1034
- `set as \`account_id\` in your ${descriptor.getConfigFileLabel()} file`
1067
+ `set in your ${descriptor.getConfigFileLabel()} file`
1035
1068
  );
1036
1069
  }
1037
1070
  const envAccountId = getCloudflareAccountIdFromEnv();
1038
1071
  if (envAccountId) {
1039
1072
  return envAccountId;
1040
1073
  }
1041
- return getAccountFromCache()?.id;
1074
+ return resolveAccountSelection()?.id;
1042
1075
  }
1043
1076
  __name(getActiveAccountId, "getActiveAccountId");
1044
- async function getOrSelectAccountId(config) {
1045
- const activeAccountId = getActiveAccountId(config);
1046
- if (activeAccountId) {
1047
- return activeAccountId;
1048
- }
1077
+ async function selectAccountId(config) {
1049
1078
  const accounts = await fetchAllAccounts(config);
1050
1079
  if (accounts.length === 1) {
1051
- saveAccountToCache({ id: accounts[0].id, name: accounts[0].name });
1080
+ retainAccountSelection({ id: accounts[0].id, name: accounts[0].name });
1052
1081
  return accounts[0].id;
1053
1082
  }
1054
1083
  try {
@@ -1062,14 +1091,14 @@ Alternatively, try running \`${descriptor.commands.login}\` to re-authenticate.`
1062
1091
  if (!account) {
1063
1092
  throw new Error("Selected account not found in accounts list");
1064
1093
  }
1065
- saveAccountToCache({ id: account.id, name: account.name });
1094
+ retainAccountSelection({ id: account.id, name: account.name });
1066
1095
  return accountID;
1067
1096
  } catch (e) {
1068
1097
  if (ctx.isNoDefaultValueProvidedError(e)) {
1069
1098
  const redactAccountName = isCI();
1070
1099
  throw new UserError(
1071
1100
  `More than one account available but unable to select one in non-interactive mode.
1072
- Please set the appropriate \`account_id\` in your ${descriptor.getConfigFileLabel()} file or assign it to the \`CLOUDFLARE_ACCOUNT_ID\` environment variable.
1101
+ Please set the appropriate account ID in your ${descriptor.getConfigFileLabel()} file or assign it to the \`CLOUDFLARE_ACCOUNT_ID\` environment variable.
1073
1102
  Available accounts are (\`<name>\`: \`<account_id>\`):
1074
1103
  ${accounts.map(
1075
1104
  (account) => ` \`${redactAccountName ? "(redacted)" : account.name}\`: \`${account.id}\``
@@ -1080,6 +1109,17 @@ ${accounts.map(
1080
1109
  throw e;
1081
1110
  }
1082
1111
  }
1112
+ __name(selectAccountId, "selectAccountId");
1113
+ async function getOrSelectAccountId(config) {
1114
+ const activeAccountId = getActiveAccountId(config);
1115
+ if (activeAccountId) {
1116
+ return activeAccountId;
1117
+ }
1118
+ accountSelectionPromise ??= selectAccountId(config).finally(() => {
1119
+ accountSelectionPromise = void 0;
1120
+ });
1121
+ return accountSelectionPromise;
1122
+ }
1083
1123
  __name(getOrSelectAccountId, "getOrSelectAccountId");
1084
1124
  async function requireAuth(config) {
1085
1125
  if (oauthFlow.isTemporaryAllowed()) {
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { __name } from './chunk-VAZEJK55.mjs';
3
- import { getEnvironmentVariableFactory, getCloudflareApiEnvironmentFromEnv, getBooleanEnvironmentVariableFactory, UserError, readFileSync, isNonInteractiveOrCI, FatalError, getCloudflareApiBaseUrl, COMPLIANCE_REGION_CONFIG_PUBLIC, getCloudflareComplianceRegion, parseTOML } from '@cloudflare/workers-utils';
3
+ import { getEnvironmentVariableFactory, getCloudflareApiEnvironmentFromEnv, getBooleanEnvironmentVariableFactory, UserError, readFileSync, isNonInteractiveOrCI, FatalError, getCloudflareApiBaseUrl, COMPLIANCE_REGION_CONFIG_PUBLIC, addCustomApiHeaders, getCloudflareComplianceRegion, parseTOML } from '@cloudflare/workers-utils';
4
4
  import { spawn, spawnSync } from 'node:child_process';
5
- import { fetch } from 'undici';
5
+ import { fetch, Headers } from 'undici';
6
6
  import { webcrypto, createHash, randomBytes, createCipheriv, createDecipheriv } from 'node:crypto';
7
7
  import { TextEncoder } from 'node:util';
8
8
  import assert2 from 'node:assert';
@@ -114,6 +114,9 @@ function validateAccountId(accountId, source) {
114
114
  __name(validateAccountId, "validateAccountId");
115
115
 
116
116
  // src/env-vars.ts
117
+ var getCloudflareAuthProfileFromEnv = getEnvironmentVariableFactory({
118
+ variableName: "CLOUDFLARE_AUTH_PROFILE"
119
+ });
117
120
  var getAuthDomainFromEnv = getEnvironmentVariableFactory({
118
121
  variableName: "WRANGLER_AUTH_DOMAIN",
119
122
  defaultValue: /* @__PURE__ */ __name(() => getCloudflareApiEnvironmentFromEnv() === "staging" ? "dash.staging.cloudflare.com" : "dash.cloudflare.com", "defaultValue")
@@ -542,9 +545,11 @@ function getCachedTemporaryPreviewAccount(storage) {
542
545
  }
543
546
  __name(getCachedTemporaryPreviewAccount, "getCachedTemporaryPreviewAccount");
544
547
  async function requestPowSolution(temporaryAccountLogger, cliDisplayName) {
548
+ const headers = new Headers({ "Content-Type": "application/json" });
549
+ addCustomApiHeaders(headers);
545
550
  const response = await fetch(getTemporaryPreviewChallengeUrl(), {
546
551
  method: "POST",
547
- headers: { "Content-Type": "application/json" },
552
+ headers,
548
553
  body: "{}"
549
554
  });
550
555
  if (!response.ok) {
@@ -585,9 +590,11 @@ async function requestPowSolution(temporaryAccountLogger, cliDisplayName) {
585
590
  __name(requestPowSolution, "requestPowSolution");
586
591
  async function createTemporaryPreviewAccount(temporaryAccountLogger, request, cliDisplayName = "Wrangler") {
587
592
  const pow = await requestPowSolution(temporaryAccountLogger, cliDisplayName);
593
+ const headers = new Headers({ "Content-Type": "application/json" });
594
+ addCustomApiHeaders(headers);
588
595
  const response = await fetch(getTemporaryPreviewUrl(), {
589
596
  method: "POST",
590
- headers: { "Content-Type": "application/json" },
597
+ headers,
591
598
  body: JSON.stringify({
592
599
  termsOfService: TEMPORARY_TERMS_URLS.termsOfService,
593
600
  privacyPolicy: TEMPORARY_TERMS_URLS.privacyPolicy,
@@ -2140,12 +2147,13 @@ function createProfileStore(args) {
2140
2147
  configs: args.configs,
2141
2148
  bindings,
2142
2149
  resolve(resolveArgs) {
2143
- if (resolveArgs.profile) {
2144
- if (resolveArgs.profile === "default") {
2150
+ const profile = resolveArgs.profile || getCloudflareAuthProfileFromEnv();
2151
+ if (profile) {
2152
+ if (profile === "default") {
2145
2153
  return "default";
2146
2154
  }
2147
- validateProfileName(resolveArgs.profile);
2148
- return resolveArgs.profile;
2155
+ validateProfileName(profile);
2156
+ return profile;
2149
2157
  }
2150
2158
  const dirProfile = bindings.getProfileForDirectory(resolveArgs.cwd);
2151
2159
  if (dirProfile) {
@@ -3670,4 +3678,4 @@ smol-toml/dist/index.js:
3670
3678
  *)
3671
3679
  */
3672
3680
 
3673
- export { AuthenticationError, DEFAULT_TEMPORARY_ACCOUNT_FLAG, EncryptedFileCredentialStore, FileCredentialStore, LinuxSecretToolKeyProvider, MacSecurityKeyProvider, NapiKeyringKeyProvider, PINNED_KEYRING_VERSION, PKCE_CHARSET, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, createOAuthFlow, createProfileStore, decryptString, dedent, domainUsesAccess, encryptString, findKeyringBinding, generateAuthUrl, generateKey, generateRandomState, generateVerificationUrl, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, parseFile, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, stringifyFile, validateAccountId, validateProfileName };
3681
+ export { AuthenticationError, DEFAULT_TEMPORARY_ACCOUNT_FLAG, EncryptedFileCredentialStore, FileCredentialStore, LinuxSecretToolKeyProvider, MacSecurityKeyProvider, NapiKeyringKeyProvider, PINNED_KEYRING_VERSION, PKCE_CHARSET, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, createOAuthFlow, createProfileStore, decryptString, dedent, domainUsesAccess, encryptString, findKeyringBinding, generateAuthUrl, generateKey, generateRandomState, generateVerificationUrl, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthProfileFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, parseFile, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, stringifyFile, validateAccountId, validateProfileName };
package/dist/index.d.mts CHANGED
@@ -80,6 +80,11 @@ declare function getAccessHeaders(domain: string, options: {
80
80
  previewToken?: string;
81
81
  }): Promise<Record<string, string>>;
82
82
 
83
+ /**
84
+ * Select a named auth profile for this process and its children.
85
+ * Explicit profile arguments take precedence; directory bindings are the fallback.
86
+ */
87
+ declare const getCloudflareAuthProfileFromEnv: () => string | undefined;
83
88
  /**
84
89
  * `WRANGLER_AUTH_URL` is the path that is used to access OAuth
85
90
  * for the Cloudflare APIs.
@@ -833,4 +838,4 @@ declare function decryptString(envelope: EncryptedEnvelope, key: Uint8Array): st
833
838
  */
834
839
  declare function parseEncryptedEnvelope(raw: unknown): EncryptedEnvelope | undefined;
835
840
 
836
- 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, generateVerificationUrl, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner };
841
+ 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, generateVerificationUrl, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthProfileFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'node:module';
2
- export { AuthenticationError, EncryptedFileCredentialStore, FileCredentialStore, LinuxSecretToolKeyProvider, MacSecurityKeyProvider, NapiKeyringKeyProvider, PINNED_KEYRING_VERSION, PKCE_CHARSET, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, createOAuthFlow, createProfileStore, decryptString, domainUsesAccess, encryptString, findKeyringBinding, generateAuthUrl, generateKey, generateRandomState, generateVerificationUrl, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, validateProfileName } from './chunk-SOBRPAPT.mjs';
2
+ export { AuthenticationError, EncryptedFileCredentialStore, FileCredentialStore, LinuxSecretToolKeyProvider, MacSecurityKeyProvider, NapiKeyringKeyProvider, PINNED_KEYRING_VERSION, PKCE_CHARSET, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, createOAuthFlow, createProfileStore, decryptString, domainUsesAccess, encryptString, findKeyringBinding, generateAuthUrl, generateKey, generateRandomState, generateVerificationUrl, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthProfileFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, validateProfileName } from './chunk-Q5KVZMHK.mjs';
3
3
  import './chunk-VAZEJK55.mjs';
4
4
 
5
5
  createRequire(import.meta.url || (typeof __filename === "string" ? __filename : "/"));
@@ -105,6 +105,12 @@ interface CliDescriptor {
105
105
  getTemporaryAccountConfigPath: () => string;
106
106
  /** On-disk file format for credentials / temporary-account / profile files. */
107
107
  fileFormat: FileFormat;
108
+ /**
109
+ * Whether an account selected from the current credentials is persisted in
110
+ * the config cache for later invocations. When disabled, the selection is
111
+ * retained only for the lifetime of the auth instance. Defaults to `false`.
112
+ */
113
+ persistAccountSelection?: boolean;
108
114
  /**
109
115
  * Filename prefix for the cached account selection in the config cache
110
116
  * (e.g. `"wrangler-account"` → `wrangler-account.json`). Always JSON.
@@ -117,9 +123,9 @@ interface CliDescriptor {
117
123
  */
118
124
  cacheNamespace?: string;
119
125
  /**
120
- * Label for the CLI's config file, used in "set `account_id` in your <file>"
121
- * hints. A getter so it can reflect runtime config state (wrangler resolves
122
- * this from `configFileName(undefined)`).
126
+ * Label for the CLI's account config file, used in account ID guidance. A
127
+ * getter so it can reflect runtime config state (wrangler resolves this from
128
+ * `configFileName(undefined)`).
123
129
  */
124
130
  getConfigFileLabel: () => string;
125
131
  /** The live default OAuth scope keys (a getter so any reassignment of the mutable `DefaultScopeKeys` binding is observed). */
@@ -127,14 +133,14 @@ interface CliDescriptor {
127
133
  }
128
134
 
129
135
  /** Details for one of the user's accounts. */
130
- type Account = {
136
+ interface Account {
131
137
  id: string;
132
138
  name: string;
133
- };
139
+ }
134
140
  /** The config surface {@link CloudflareAuth.requireAuth} needs: compliance settings plus an optional `account_id`. */
135
- type RequireAuthConfig = ComplianceConfig & {
141
+ interface RequireAuthConfig extends ComplianceConfig {
136
142
  account_id?: string;
137
- };
143
+ }
138
144
  /** Overrides accepted by {@link CloudflareAuth.login} / {@link CloudflareAuth.loginOrRefreshIfRequired}. */
139
145
  interface CloudflareLoginProps {
140
146
  scopes?: string[];
@@ -178,7 +184,7 @@ interface CloudflareAuth {
178
184
  readAuthCredentials: () => UserAuthConfig | undefined;
179
185
  /** Persist OAuth credentials via the active credential store. */
180
186
  writeAuthCredentials: (config: UserAuthConfig) => void;
181
- /** Returns the active account ID without side effects (config → env → cache). */
187
+ /** Returns the active account ID without fetching accounts or prompting. */
182
188
  getActiveAccountId: (config: {
183
189
  account_id?: string;
184
190
  }) => string | undefined;