{"version":3,"sources":["jsdelivr-header.js","/npm/restify-simple-versioning@1.0.0/src/restify-simple-versioning.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,IAAI,OAAS,QAAQ;;;;;GAQrB,MAAM,UAQJ,mBAAW,CAAS,GAClB,UAAU,UAAY,CACxB,CAEA,mBAAW,GACT,OAAO,UAAU,WAAa,CAAC,EACjC,CAMA,yBAAW,GACT,OAAO,UAAU,WACnB,CAOA,cAAW,GACT,OAAQ,UAAU,cAAgB,IAAM,UAAU,YAAc,EAClE,CAYA,sBAAO,CAAgB,EAAK,EAAK,GAC/B,IAAI,EAAQ,EAAI,IAAI,MAAM,sBAEtB,GACF,UAAU,eAAgB,EAC1B,UAAU,YAAc,OAAO,EAAM,IACrC,EAAI,IAAM,EAAM,KAEhB,UAAU,eAAgB,EAErB,UAAU,iBACb,UAAU,eAAiB,UAAU,SAAS,QAAO,CAAC,EAAM,IAAS,KAAK,IAAI,EAAM,MAGtF,UAAU,YAAc,UAAU,gBAGhC,UAAU,SAAS,SAAS,UAAU,cACxC,EAAI,OAAO,cAAe,UAAU,aACpC,KAEA,EAAK,IAAI,OAAO,oBAAoB,CAClC,WAAY,IACZ,QAAS,kDAGf,EAIF,OAAO,QAAU","file":"/npm/restify-simple-versioning@1.0.0/src/restify-simple-versioning.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/restify-simple-versioning@1.0.0/src/restify-simple-versioning.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","let errors = require(\"restify-errors\");\n\n/**\n * @author Leandro Silva\n * @copyright 2017 Leandro Silva (http://grafluxe.com)\n * @license MIT\n */\n\nclass Versioner {\n  /**\n   * An array of available API versions.\n   * @type {Array}\n   * @example\n   * let versioner = require(\"restify-simple-versioning\");\n   * versioner.versions = [1, 2];\n   */\n  static set versions(val) {\n    Versioner._versions = val;\n  }\n\n  static get versions() {\n    return Versioner._versions || [1];\n  }\n\n  /**\n   * Returns the current API version.\n   * @type {Number}\n   */\n  static get currentVersion() {\n    return Versioner._currentVer;\n  }\n\n  /**\n   * Returns the API version as seen in the URI. If no version is used in\n   * the URI, an empty string is returned.\n   * @type {String}\n   */\n  static get uri() {\n    return (Versioner._versionInURI ? \"v\" + Versioner._currentVer : \"\");\n  }\n\n  /**\n   * Adds version path support to your URI. The version format is\n   * the letter \"v\" followed by a number (e.g. v1). If no version\n   * is added to the URI, the latest version will be used by default.\n   * Additionally, the header 'API-Version' is included in each response.\n   * @throws {InvalidVersionError} Throws if the version you requested does not exist.\n   * @param {Object}   req  The Restify request param.\n   * @param {Object}   res  The Restify result param.\n   * @param {Function} next The Restify next method.\n   */\n  static addVersionRoute(req, res, next) {\n    let parts = req.url.match(/^\\/v(\\d{1,})(\\/.+)/);\n\n    if (parts) {\n      Versioner._versionInURI = true;\n      Versioner._currentVer = Number(parts[1]);\n      req.url = parts[2];\n    } else {\n      Versioner._versionInURI = false;\n\n      if (!Versioner._latestVersion) {\n        Versioner._latestVersion = Versioner.versions.reduce((curr, next) => Math.max(curr, next));\n      }\n\n      Versioner._currentVer = Versioner._latestVersion;\n    }\n\n    if (Versioner.versions.includes(Versioner._currentVer)) {\n      res.header(\"API-Version\", Versioner._currentVer);\n      next();\n    } else {\n      next(new errors.InvalidVersionError({\n        statusCode: 409,\n        message: \"The API version you requested does not exist.\"\n      }));\n    }\n  }\n\n}\n\nmodule.exports = Versioner;\n"]}