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,CAAY","file":"/npm/@vonage/auth@1.15.0/dist/cjs/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@vonage/auth@1.15.0/dist/cjs/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n  for (var name in all)\n    __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n  if (from && typeof from === \"object\" || typeof from === \"function\") {\n    for (let key of __getOwnPropNames(from))\n      if (!__hasOwnProp.call(to, key) && key !== except)\n        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n  }\n  return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n  // If the importer is in node compatibility mode or this is not an ESM\n  // file that has been converted to a CommonJS file using a Babel-\n  // compatible transform (i.e. \"__esModule\" has not been set), then set\n  // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n  isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n  mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// lib/index.ts\nvar index_exports = {};\n__export(index_exports, {\n  AlgorithmTypes: () => AlgorithmTypes,\n  Auth: () => Auth,\n  InvalidApiKeyError: () => InvalidApiKeyError,\n  InvalidApiSecretError: () => InvalidApiSecretError,\n  InvalidSignatureAlgorithmError: () => InvalidSignatureAlgorithmError,\n  MissingApiKeyError: () => MissingApiKeyError,\n  MissingApiSecretError: () => MissingApiSecretError,\n  MissingSignatureError: () => MissingSignatureError\n});\nmodule.exports = __toCommonJS(index_exports);\n\n// lib/auth.ts\nvar import_jwt = require(\"@vonage/jwt\");\nvar import_node_crypto = require(\"crypto\");\nvar import_node_fs = require(\"fs\");\n\n// lib/enums/AlgroithmTypes.ts\nvar AlgorithmTypes = /* @__PURE__ */ ((AlgorithmTypes2) => {\n  AlgorithmTypes2[\"md5hash\"] = \"MD5HASH\";\n  AlgorithmTypes2[\"md5hmac\"] = \"MD5HMAC\";\n  AlgorithmTypes2[\"sha1hmac\"] = \"SHA1HMAC\";\n  AlgorithmTypes2[\"sha256hmac\"] = \"SHA256HMAC\";\n  AlgorithmTypes2[\"sha512hmac\"] = \"SHA512HMAC\";\n  return AlgorithmTypes2;\n})(AlgorithmTypes || {});\n\n// lib/errors/InvalidApiKeyError.ts\nvar InvalidApiKeyError = class extends Error {\n  constructor() {\n    super(\"API Key must be a string\");\n  }\n};\n\n// lib/errors/InvalidApiSecretError.ts\nvar InvalidApiSecretError = class extends Error {\n  constructor() {\n    super(\"API Secret must be a string\");\n  }\n};\n\n// lib/errors/InvalidSignatureAlgroithmError.ts\nvar InvalidSignatureAlgorithmError = class extends Error {\n  constructor() {\n    super(\"Invalid Signature algorithm\");\n  }\n};\n\n// lib/errors/MissingApiKeyError.ts\nvar MissingApiKeyError = class extends Error {\n  constructor() {\n    super(\"Missing API Key\");\n  }\n};\n\n// lib/errors/MissingApiSecretError.ts\nvar MissingApiSecretError = class extends Error {\n  constructor() {\n    super(\"Missing API Secret\");\n  }\n};\n\n// lib/errors/MissingSignatureError.ts\nvar MissingSignatureError = class extends Error {\n  constructor() {\n    super(\"Missing signature algorithm\");\n  }\n};\n\n// lib/auth.ts\nvar import_debug = __toESM(require(\"debug\"));\nvar log = (0, import_debug.default)(\"vonage:auth\");\nvar Auth = class {\n  /**\n   * @property {string} apiKey - The API key used for authentication.\n   */\n  apiKey;\n  /**\n   * @property {string} apiSecret - The API secret used for authentication.\n   */\n  apiSecret;\n  /**\n   * @property {string | null} [privateKey] - The private key used for JWT\n   *     authentication, either as a string or read from a file.\n   */\n  privateKey;\n  /**\n   * @property {string | null} [applicationId] - The application ID used for\n   *     JWT authentication.\n   */\n  applicationId;\n  /**\n   * @property {SignedHashParams | null} [signature] - The signature parameters\n   *     used for signature authentication.\n   */\n  signature;\n  /**\n   * @property {GeneratorOptions} jwtOptions - Options used for generating JWTs.\n   */\n  jwtOptions;\n  constructor(opts) {\n    this.apiKey = opts?.apiKey || \"\";\n    this.apiSecret = opts?.apiSecret || \"\";\n    this.signature = opts?.signature || null;\n    this.applicationId = opts?.applicationId || null;\n    this.jwtOptions = opts?.jwtOptions || {};\n    let privateKey = opts?.privateKey;\n    if ((0, import_node_fs.existsSync)(opts?.privateKey)) {\n      log(\"Reading private key file\");\n      privateKey = (0, import_node_fs.readFileSync)(opts?.privateKey).toString();\n    }\n    this.privateKey = privateKey instanceof Buffer ? privateKey.toString() : privateKey;\n  }\n  /**\n   * Generates query parameters for authentication, optionally merging with\n   * provided parameters.\n   *\n   *\n   * @param {T} [params] - Additional parameters to merge with the\n   *     generated authentication query parameters.\n   *\n   * @return {Promise<AuthQueryParams>} - A promise that resolves\n   *     with the merged authentication query parameters.\n   *\n   * @throws {MissingApiKeyError} - Thrown when the API key is missing.\n   * @throws {MissingApiSecretError} - Thrown when the API secret is missing.\n   * @throws {InvalidApiKeyError} - Thrown when the API key is not a valid string.\n   * @throws {InvalidApiSecretError} - Thrown when the API secret is not a valid string.\n   *\n   * @example\n   * Generate query parameters\n   *\n   * ```ts\n   * const queryParams = await auth.getQueryParams();\n   * ```\n   *\n   * @example\n   * Generate query parameters and merge with additional Parameters\n   *\n   * ```ts\n   * const queryParams = await auth.getQueryParams({\n   *   to: '15555555555',\n   *   from: '15555555556',\n   *   text: 'Hello from Vonage SMS API'\n   * });\n   * ```\n   */\n  getQueryParams = async (params) => {\n    if (!this.apiKey) {\n      throw new MissingApiKeyError();\n    }\n    if (!this.apiSecret) {\n      throw new MissingApiSecretError();\n    }\n    if (typeof this.apiKey !== \"string\") {\n      throw new InvalidApiKeyError();\n    }\n    if (typeof this.apiSecret !== \"string\") {\n      throw new InvalidApiSecretError();\n    }\n    return {\n      ...params,\n      api_key: this.apiKey,\n      api_secret: this.apiSecret\n    };\n  };\n  /**\n   * Generates a basic authentication header.\n   *\n   * @return {Promise<string>} - A promise that resolves with the\n   *     generated basic authentication header.\n   *\n   * @throws {MissingApiKeyError} - Thrown when the API key is missing.\n   * @throws {MissingApiSecretError} - Thrown when the API secret is missing.\n   * @throws {InvalidApiKeyError} - Thrown when the API key is not a valid string.\n   * @throws {InvalidApiSecretError} - Thrown when the API secret is not a valid string.\n   *\n   * @example\n   * Generate a basic authentication headers\n   *\n   * ```ts\n   * const basicAuthHeader = await auth.createBasicHeader();\n   * ```\n   */\n  createBasicHeader = async () => {\n    log(\"Creating basic auth header\");\n    if (!this.apiKey) {\n      throw new MissingApiKeyError();\n    }\n    if (!this.apiSecret) {\n      throw new MissingApiSecretError();\n    }\n    if (typeof this.apiKey !== \"string\") {\n      throw new InvalidApiKeyError();\n    }\n    if (typeof this.apiSecret !== \"string\") {\n      throw new InvalidApiSecretError();\n    }\n    const buf = Buffer.from(`${this.apiKey}:${this.apiSecret}`);\n    return `Basic ${buf.toString(\"base64\")}`;\n  };\n  /**\n   * Generates a bearer authentication header.\n   *\n   * @return {Promise<string>} - A promise that resolves with the\n   *     generated bearer authentication header.\n   *\n   * @example\n   * Generate a bearer authentication headers\n   *\n   * ```ts\n   * const bearerAuthHeader = await auth.createBearerHeader();\n   * ```\n   */\n  createBearerHeader = async () => {\n    log(\"Creating bearer header\");\n    return `Bearer ${(0, import_jwt.tokenGenerate)(\n      this.applicationId || \"\",\n      this.privateKey || \"\",\n      this.jwtOptions\n    )}`;\n  };\n  /**\n   * Generates a signature hash for authentication, merging it with\n   * provided parameters.\n   *\n   * @template T - Type of the parameters to merge with.\n   * @param {T} params - Parameters to merge with the generated\n   *     signature hash.\n   * @return {Promise<AuthSignedParams>} - A promise that resolves\n   *     with the merged signature hash and parameters.\n   *\n   * @throws {MissingApiKeyError} - Thrown when the API key is missing.\n   * @throws {InvalidApiKeyError} - Thrown when the API key is not a valid string.\n   * @throws {MissingSignatureError} - Thrown when the signature algorithm is missing.\n   * @throws {MissingApiSecretError} - Thrown when the API secret is missing.\n   * @throws {InvalidApiSecretError} - Thrown when the API secret is not a valid string.\n   * @throws {InvalidSignatureAlgorithmError} - Thrown when an invalid signature algorithm is provided.\n   *\n   * @example\n   * Generate a signature hash\n   *\n   * ```ts\n   * const signatureHash = await auth.createSignatureHash({\n   *   to: '15555555555',\n   *   from: '15555555556',\n   *   text: 'Hello from Vonage SMS API',\n   *   timestamp: '1516878400',\n   *   sig: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6',\n   * });\n   * ```\n   */\n  createSignatureHash = async (params) => {\n    log(\"Creating signature hash\");\n    if (!this.apiKey) {\n      throw new MissingApiKeyError();\n    }\n    if (typeof this.apiKey !== \"string\") {\n      throw new InvalidApiKeyError();\n    }\n    if (!this.signature?.algorithm) {\n      throw new MissingSignatureError();\n    }\n    if (!this.signature?.secret) {\n      throw new MissingApiSecretError();\n    }\n    if (typeof this.signature?.secret !== \"string\") {\n      throw new InvalidApiSecretError();\n    }\n    const returnParams = {\n      ...params,\n      api_key: this.apiKey\n    };\n    if (!returnParams.timestamp) {\n      returnParams.timestamp = Math.floor(Date.now() / 1e3).toString();\n    }\n    const sortedParams = new URLSearchParams(returnParams);\n    sortedParams.sort();\n    const stringifiedParamsforSigning = sortedParams.toString().replace(/(&|=)/gi, \"_\");\n    switch (this.signature.algorithm) {\n      case \"MD5HASH\" /* md5hash */:\n        returnParams.sig = (0, import_node_crypto.createHash)(\"md5\").update(`${stringifiedParamsforSigning}${this.signature.secret}`).digest(\"hex\");\n        break;\n      case \"MD5HMAC\" /* md5hmac */:\n        returnParams.sig = (0, import_node_crypto.createHmac)(\"md5\", this.signature.secret).update(stringifiedParamsforSigning).digest(\"hex\");\n        break;\n      case \"SHA1HMAC\" /* sha1hmac */:\n        returnParams.sig = (0, import_node_crypto.createHmac)(\"sha1\", this.signature.secret).update(stringifiedParamsforSigning).digest(\"hex\");\n        break;\n      case \"SHA256HMAC\" /* sha256hmac */:\n        returnParams.sig = (0, import_node_crypto.createHmac)(\"sha256\", this.signature.secret).update(stringifiedParamsforSigning).digest(\"hex\");\n        break;\n      case \"SHA512HMAC\" /* sha512hmac */:\n        returnParams.sig = (0, import_node_crypto.createHmac)(\"sha512\", this.signature.secret).update(stringifiedParamsforSigning).digest(\"hex\");\n        break;\n      default:\n        throw new InvalidSignatureAlgorithmError();\n    }\n    return returnParams;\n  };\n};\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n  AlgorithmTypes,\n  Auth,\n  InvalidApiKeyError,\n  InvalidApiSecretError,\n  InvalidSignatureAlgorithmError,\n  MissingApiKeyError,\n  MissingApiSecretError,\n  MissingSignatureError\n});\n"]}