@cloudflare/workers-auth 0.14.1 → 0.15.1

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,4 +1,4 @@
1
- import { Logger, ComplianceConfig, ApiCredentials } from '@cloudflare/workers-utils';
1
+ import { Logger, ComplianceConfig, ApiCredentials, UserError } from '@cloudflare/workers-utils';
2
2
 
3
3
  /**
4
4
  * Pluggable persistence for a typed config blob.
@@ -99,6 +99,8 @@ interface OAuthFlowTemporaryContext {
99
99
  storage: TemporaryAccountStorage;
100
100
  /** Consumer name used in temporary-account errors. */
101
101
  cliDisplayName?: string;
102
+ /** Consumer temporary-account flag spelling. Defaults to `--temporary-account`. */
103
+ temporaryAccountFlag?: string;
102
104
  /** Consumer command used to clear a cached temporary account. */
103
105
  logoutCommand?: string;
104
106
  /**
@@ -513,4 +515,10 @@ interface CredentialStore extends AuthConfigStorage {
513
515
  */
514
516
  type FileFormat = "toml" | "json";
515
517
 
516
- export { type AuthConfigStorage as A, type CredentialStore as C, type DeactivateDirectoryResult as D, type FileFormat as F, type LoginOrRefreshFailureReason as L, type OAuthFlowLogger as O, type ProfileConfigOperations as P, type TemporaryAccountRequest as T, type UserAuthConfig as U, type ConfigStorage as a, type DirectoryBindingOperations as b, type DirectoryBindingsStorage as c, type LoginOrRefreshResult as d, type LoginProps as e, type OAuthFlowContext as f, type ProfileStore as g, type TemporaryPreviewAccount as h, createOAuthFlow as i, createProfileStore as j, generateAuthUrl as k, generateRandomState as l, type TemporaryAccountLogger as m, type OAuthConsentPages as n, validateProfileName as v };
518
+ /** Authentication failed before an API request, with a machine-readable reason. */
519
+ declare class AuthenticationError extends UserError {
520
+ readonly reason: LoginOrRefreshFailureReason;
521
+ constructor(message: string, reason: LoginOrRefreshFailureReason, telemetryMessage: string);
522
+ }
523
+
524
+ export { type AuthConfigStorage as A, type CredentialStore as C, type DeactivateDirectoryResult as D, type FileFormat as F, type LoginOrRefreshFailureReason as L, type OAuthFlowLogger as O, type ProfileConfigOperations as P, type TemporaryAccountRequest as T, type UserAuthConfig as U, AuthenticationError as a, type ConfigStorage as b, type DirectoryBindingOperations as c, type DirectoryBindingsStorage as d, type LoginOrRefreshResult as e, type LoginProps as f, type OAuthFlowContext as g, type ProfileStore as h, type TemporaryPreviewAccount as i, createOAuthFlow as j, createProfileStore as k, generateAuthUrl as l, generateRandomState as m, type TemporaryAccountLogger as n, type OAuthConsentPages as o, validateProfileName as v };
@@ -1,6 +1,7 @@
1
- import { a as ConfigStorage, A as AuthConfigStorage, U as UserAuthConfig, f as OAuthFlowContext, g as ProfileStore } from '../file-format-DLf_MRuS.mjs';
2
- import { C as CliDescriptor, A as AuthContext, a as CloudflareAuth, U as UserPreferences, K as KeyringPreferenceContext, S as SetKeyringPreferenceResult } from '../keyring-preference-DIwv0hwY.mjs';
3
- export { b as CloudflareLoginProps } from '../keyring-preference-DIwv0hwY.mjs';
1
+ import { b as ConfigStorage, A as AuthConfigStorage, U as UserAuthConfig, g as OAuthFlowContext, h as ProfileStore } from '../authentication-error-DcqALFv6.mjs';
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';
4
5
  import '@cloudflare/workers-utils';
5
6
 
6
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-F2REEYJC.mjs';
3
- import '../chunk-2K52M2W5.mjs';
2
+ import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-L7K6HL3F.mjs';
3
+ export { AuthenticationError } from '../chunk-3PJ54H4K.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';
@@ -581,6 +581,7 @@ var {
581
581
  var CF_CLI = {
582
582
  cliName: CF_CLI_NAME,
583
583
  displayName: CF_DISPLAY_NAME,
584
+ temporaryAccountFlag: "--temporary-account",
584
585
  commands: {
585
586
  login: "cf auth login",
586
587
  logout: "cf auth logout",
@@ -421,13 +421,13 @@ function solveChallenge(challenge) {
421
421
  __name(solveChallenge, "solveChallenge");
422
422
 
423
423
  // src/temporary.ts
424
+ var DEFAULT_TEMPORARY_ACCOUNT_FLAG = "--temporary-account";
424
425
  var TEMPORARY_TERMS_URLS = {
425
426
  termsOfService: "https://www.cloudflare.com/terms/",
426
427
  privacyPolicy: "https://www.cloudflare.com/privacypolicy/"
427
428
  };
428
429
  var TEMPORARY_TERMS_PROMPT = `You must accept Cloudflare's Terms of Service (${TEMPORARY_TERMS_URLS.termsOfService}) and Privacy Policy (${TEMPORARY_TERMS_URLS.privacyPolicy}) in order to continue. By typing "yes", you agree to these terms. Type "yes" to continue.`;
429
430
  var TEMPORARY_TERMS_NOTICE = `Continuing means you accept Cloudflare's Terms of Service (${TEMPORARY_TERMS_URLS.termsOfService}) and Privacy Policy (${TEMPORARY_TERMS_URLS.privacyPolicy}).`;
430
- var TEMPORARY_TERMS_ERROR = `You must accept Cloudflare's Terms of Service (${TEMPORARY_TERMS_URLS.termsOfService}) and Privacy Policy (${TEMPORARY_TERMS_URLS.privacyPolicy}) to use --temporary.`;
431
431
  var EVENT_ACCOUNT_ERRORS = /* @__PURE__ */ new Map([
432
432
  [
433
433
  1035,
@@ -674,9 +674,10 @@ async function getOrCreateTemporaryPreviewAccount(options) {
674
674
  TEMPORARY_TERMS_NOTICE
675
675
  );
676
676
  if (!termsAccepted) {
677
- throw new UserError(TEMPORARY_TERMS_ERROR, {
678
- telemetryMessage: "user temporary terms not accepted"
679
- });
677
+ throw new UserError(
678
+ `You must accept Cloudflare's Terms of Service (${TEMPORARY_TERMS_URLS.termsOfService}) and Privacy Policy (${TEMPORARY_TERMS_URLS.privacyPolicy}) to use ${options.temporaryAccountFlag ?? DEFAULT_TEMPORARY_ACCOUNT_FLAG}.`,
679
+ { telemetryMessage: "user temporary terms not accepted" }
680
+ );
680
681
  }
681
682
  const temporaryPreviewAccount = await createTemporaryPreviewAccount(
682
683
  options.temporaryAccountLogger,
@@ -2700,11 +2701,21 @@ var EncryptedFileCredentialStore = class {
2700
2701
  };
2701
2702
  var PINNED_KEYRING_VERSION = "1.3.0";
2702
2703
  function defaultNpmRunner(args) {
2703
- return spawnSync("npm", args, {
2704
+ const options = {
2704
2705
  encoding: "utf-8",
2705
- stdio: ["ignore", "pipe", "pipe"],
2706
- shell: process.platform === "win32"
2707
- });
2706
+ stdio: ["ignore", "pipe", "pipe"]
2707
+ };
2708
+ if (process.platform === "win32") {
2709
+ const env = { ...process.env };
2710
+ const quotedArgRefs = args.map((arg, i) => {
2711
+ const name = `WORKERS_AUTH_NPM_ARG_${i}`;
2712
+ env[name] = arg;
2713
+ return `"%${name}%"`;
2714
+ });
2715
+ const command = ["npm", ...quotedArgRefs].join(" ");
2716
+ return spawnSync(command, { ...options, env, shell: true });
2717
+ }
2718
+ return spawnSync("npm", args, options);
2708
2719
  }
2709
2720
  __name(defaultNpmRunner, "defaultNpmRunner");
2710
2721
  var npmRunner = defaultNpmRunner;
@@ -3372,6 +3383,15 @@ function scrubEncryptedCredentials(options) {
3372
3383
  return { backendAvailable: false, encryptedFileExisted };
3373
3384
  }
3374
3385
  __name(scrubEncryptedCredentials, "scrubEncryptedCredentials");
3386
+ var AuthenticationError = class extends UserError {
3387
+ constructor(message, reason, telemetryMessage) {
3388
+ super(message, { telemetryMessage });
3389
+ this.reason = reason;
3390
+ }
3391
+ static {
3392
+ __name(this, "AuthenticationError");
3393
+ }
3394
+ };
3375
3395
  /*! Bundled license information:
3376
3396
 
3377
3397
  smol-toml/dist/error.js:
@@ -3636,4 +3656,4 @@ smol-toml/dist/index.js:
3636
3656
  *)
3637
3657
  */
3638
3658
 
3639
- export { 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 };
3659
+ 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 };
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'node:module';
2
- import { stringifyFile, parseFile, dedent, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, validateAccountId, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-2K52M2W5.mjs';
2
+ import { stringifyFile, parseFile, dedent, DEFAULT_TEMPORARY_ACCOUNT_FLAG, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, AuthenticationError, validateAccountId, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-3PJ54H4K.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';
@@ -786,6 +786,7 @@ function createCloudflareAuth(descriptor, ctx) {
786
786
  const { logger } = ctx;
787
787
  const temporaryAccountLogger = ctx.temporaryAccountLogger ?? logger;
788
788
  const cliName = descriptor.cliName;
789
+ const temporaryAccountFlag = descriptor.temporaryAccountFlag ?? DEFAULT_TEMPORARY_ACCOUNT_FLAG;
789
790
  const NOT_LOGGED_IN_ERROR_BODIES = notLoggedInErrorBodies(
790
791
  descriptor.commands.login
791
792
  );
@@ -829,6 +830,7 @@ Run \`${descriptor.commands.whoami}\` to check your current authentication statu
829
830
  ),
830
831
  cliDisplayName: descriptor.displayName,
831
832
  logoutCommand: descriptor.commands.logout,
833
+ temporaryAccountFlag,
832
834
  prompt: createTemporaryTermsPrompt({
833
835
  temporaryAccountLogger,
834
836
  prompt: ctx.prompt
@@ -962,9 +964,10 @@ Run \`${descriptor.commands.whoami}\` to check your current authentication statu
962
964
  const { throwOnEmpty = true } = options;
963
965
  const loginResult = await loginOrRefreshIfRequired(complianceConfig);
964
966
  if (!loginResult.loggedIn) {
965
- throw new UserError(
967
+ throw new AuthenticationError(
966
968
  `Not logged in. ${NOT_LOGGED_IN_ERROR_BODIES[loginResult.reason]}${NOT_LOGGED_IN_WHOAMI_TIP}`,
967
- { telemetryMessage: "cfetch auth login required" }
969
+ loginResult.reason,
970
+ "cfetch auth login required"
968
971
  );
969
972
  }
970
973
  const credentials = requireApiToken();
@@ -1094,7 +1097,7 @@ ${accounts.map(
1094
1097
  }
1095
1098
  if (getAPIToken()) {
1096
1099
  throw new UserError(
1097
- "You're already authenticated with Cloudflare, so `--temporary` can't be used. Temporary preview accounts are only for unauthenticated use. Either remove `--temporary` to use your existing account, or log out (and unset CLOUDFLARE_API_TOKEN) first.",
1100
+ `You're already authenticated with Cloudflare, so \`${temporaryAccountFlag}\` can't be used. Temporary preview accounts are only for unauthenticated use. Either remove \`${temporaryAccountFlag}\` to use your existing account, or log out (and unset CLOUDFLARE_API_TOKEN) first.`,
1098
1101
  {
1099
1102
  telemetryMessage: "user temporary account already authenticated"
1100
1103
  }
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OAuthFlowLogger, U as UserAuthConfig, A as AuthConfigStorage, C as CredentialStore, F as FileFormat } from './file-format-DLf_MRuS.mjs';
2
- export { a as ConfigStorage, D as DeactivateDirectoryResult, b as DirectoryBindingOperations, c as DirectoryBindingsStorage, L as LoginOrRefreshFailureReason, d as LoginOrRefreshResult, e as LoginProps, f as OAuthFlowContext, P as ProfileConfigOperations, g as ProfileStore, T as TemporaryAccountRequest, h as TemporaryPreviewAccount, i as createOAuthFlow, j as createProfileStore, k as generateAuthUrl, l as generateRandomState, v as validateProfileName } from './file-format-DLf_MRuS.mjs';
1
+ import { O as OAuthFlowLogger, U as UserAuthConfig, A as AuthConfigStorage, C as CredentialStore, F as FileFormat } from './authentication-error-DcqALFv6.mjs';
2
+ export { a as AuthenticationError, b as ConfigStorage, D as DeactivateDirectoryResult, c as DirectoryBindingOperations, d as DirectoryBindingsStorage, L as LoginOrRefreshFailureReason, e as LoginOrRefreshResult, f as LoginProps, g as OAuthFlowContext, P as ProfileConfigOperations, h as ProfileStore, T as TemporaryAccountRequest, i as TemporaryPreviewAccount, j as createOAuthFlow, k as createProfileStore, l as generateAuthUrl, m as generateRandomState, v as validateProfileName } from './authentication-error-DcqALFv6.mjs';
3
3
  import { ApiCredentials } from '@cloudflare/workers-utils';
4
4
  import { SpawnSyncReturns } from 'node:child_process';
5
5
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'node:module';
2
- export { 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-2K52M2W5.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, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, validateProfileName } from './chunk-3PJ54H4K.mjs';
3
3
  import './chunk-VAZEJK55.mjs';
4
4
 
5
5
  createRequire(import.meta.url || (typeof __filename === "string" ? __filename : "/"));
@@ -1,4 +1,4 @@
1
- import { f as OAuthFlowContext, m as TemporaryAccountLogger, n as OAuthConsentPages, F as FileFormat, C as CredentialStore, T as TemporaryAccountRequest, d as LoginOrRefreshResult, U as UserAuthConfig } from './file-format-DLf_MRuS.mjs';
1
+ import { g as OAuthFlowContext, n as TemporaryAccountLogger, o as OAuthConsentPages, F as FileFormat, C as CredentialStore, T as TemporaryAccountRequest, e as LoginOrRefreshResult, U as UserAuthConfig } from './authentication-error-DcqALFv6.mjs';
2
2
  import { ApiCredentials, ComplianceConfig } from '@cloudflare/workers-utils';
3
3
 
4
4
  /** Minimal shape of the interactive `select` prompt's options for account selection. */
@@ -60,6 +60,8 @@ interface CliDescriptor {
60
60
  * {@link CliDescriptor.cliName}, which names the executable.
61
61
  */
62
62
  displayName: string;
63
+ /** Temporary-account flag spelling in user guidance. Defaults to `--temporary-account`. */
64
+ temporaryAccountFlag?: string;
63
65
  /** Commands surfaced in auth guidance. */
64
66
  commands: {
65
67
  login: string;
@@ -156,7 +158,7 @@ interface CloudflareAuth {
156
158
  getActiveProfile: () => string;
157
159
  /** The currently-active credential store for the active profile. */
158
160
  getCredentialStore: () => CredentialStore;
159
- /** Mark whether `--temporary` is permitted for the current invocation. */
161
+ /** Mark whether temporary-account mode is permitted for the current invocation. */
160
162
  setTemporaryAllowed: (allowed: boolean, request?: TemporaryAccountRequest) => void;
161
163
  /** Resolve API credentials (env / temporary account / stored OAuth token). */
162
164
  getAPIToken: () => ApiCredentials | undefined;