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GAAG,UAIrB,YAHI,GAA0B,mBAAZ,EAAI,KACpB,EAAI,MAGR,CAMF,GAHa,KAAK,MAAM,QACF,UAQtB,IADA,IAAI,EAAO,KACF,EAAI,EAAG,EAAI,EAAQ,OAAQ,IAAK,CACvC,IAAI,EAAI,EAAQ,GAChB,EAAE,OAAS,EACK,IAAZ,EAAE,QACJ,EAAE,UAAY,WAAW,SAAU,GACjC,EAAI,MAAQ,EACZ,EAAI,UAAY,KAChB,EAAK,QAEL,IADA,IAAI,EAAO,EAAK,QACT,EAAK,MAAM,QAAQ,CAExB,IADA,IAAI,GAAU,EACL,EAAI,EAAG,EAAI,EAAK,OAAQ,IAC/B,GAAI,EAAK,GAAG,OAAS,EAAK,GAAG,IAAK,CAChC,GAAU,EACV,KACF,CAEF,GAAI,EAAS,MACb,EAAK,OACP,CACF,EAAE,KAAK,KAAM,GAAI,EAAE,OACc,mBAAtB,EAAE,UAAU,OACK,IAAtB,KAAK,MAAM,QAAc,EAAE,UAAU,QAG/C,MA9BE,KAAK,OAhBiB,CA+C1B,EA4CA,eAAe,sBAAwB,qBACvC,OAAO,QAAU","file":"/npm/axios-rate-limit@1.6.3/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/axios-rate-limit@1.6.3/src/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","var DURATION_MSG = \" Expected format: number+unit ms, s, m, h (e.g. '1s').\"\n\nvar DURATION_UNITS = { ms: 1, s: 1000, m: 60000, h: 3600000 }\n\nfunction throwDurationError (value) {\n  var msg = \"Unrecognized duration: '\" + String(value) + \"'.\" + DURATION_MSG\n  throw new Error(msg)\n}\n\nfunction parseDuration (value) {\n  if (typeof value === 'number' && !isNaN(value)) {\n    if (value < 0) throwDurationError(value)\n    return value\n  }\n  if (typeof value !== 'string') {\n    throwDurationError(value)\n  }\n  var s = value.trim()\n  var num\n  var mult\n  if (s.length >= 2 && s.slice(-2) === 'ms') {\n    num = parseFloat(s.slice(0, -2))\n    mult = DURATION_UNITS.ms\n  } else if (s.length >= 1) {\n    var u = s.slice(-1)\n    mult = DURATION_UNITS[u]\n    if (mult == null) throwDurationError(value)\n    num = parseFloat(s.slice(0, -1))\n  } else {\n    throwDurationError(value)\n  }\n  if (isNaN(num) || num < 0) {\n    throwDurationError(value)\n  }\n  return num * mult\n}\n\nfunction buildWindows (options) {\n  var limits = options && options.limits\n  if (limits && limits.length > 0) {\n    return limits.map(function (limit, i) {\n      var max = limit.maxRequests\n      if (typeof max !== 'number' || !isFinite(max) || max <= 0) {\n        throw new Error(\n          'Invalid rate limit option at limits[' + i + ']: ' +\n          'maxRequests is required and must be a positive number.'\n        )\n      }\n      var perMs = parseDuration(limit.duration)\n      if (typeof perMs !== 'number' || !isFinite(perMs) || perMs <= 0) {\n        throw new Error(\n          'Invalid rate limit option at limits[' + i + ']: ' +\n          'duration must be a positive finite number.'\n        )\n      }\n      return { count: 0, max: max, perMs: perMs, timeoutId: null }\n    })\n  }\n  var maxRequests = options.maxRequests\n  var perMs\n  if (options.maxRPS != null) {\n    maxRequests = options.maxRPS\n    perMs = 1000\n  } else {\n    var optD = options.duration\n    perMs = optD != null ? parseDuration(optD) : options.perMilliseconds\n  }\n  if (typeof perMs !== 'number' || !isFinite(perMs) || perMs <= 0) {\n    throw new Error(\n      'Invalid rate limit options: one of maxRPS, duration, or ' +\n      'perMilliseconds is required and must be positive.'\n    )\n  }\n  var maxInvalid = typeof maxRequests !== 'number' ||\n    !isFinite(maxRequests) || maxRequests <= 0\n  if (maxInvalid) {\n    throw new Error(\n      'Invalid rate limit options: maxRequests is required and ' +\n      'must be a positive number.'\n    )\n  }\n  return [{ count: 0, max: maxRequests, perMs: perMs, timeoutId: null }]\n}\n\nfunction clearWindowsTimeouts (windows) {\n  if (!windows) return\n  for (var i = 0; i < windows.length; i++) {\n    if (windows[i].timeoutId != null) {\n      clearTimeout(windows[i].timeoutId)\n      windows[i].timeoutId = null\n    }\n  }\n}\n\nfunction AxiosRateLimit (axios, queue) {\n  this.queue = queue\n  this.windows = []\n\n  this.interceptors = {\n    request: null,\n    response: null\n  }\n\n  this.handleRequest = this.handleRequest.bind(this)\n  this.handleResponse = this.handleResponse.bind(this)\n\n  this.enable(axios)\n}\n\nAxiosRateLimit.prototype.getMaxRPS = function () {\n  var w = this.windows[0]\n  if (!w) return 0\n  return w.max / (w.perMs / 1000)\n}\n\nAxiosRateLimit.prototype.getQueue = function () {\n  return this.queue\n}\n\nAxiosRateLimit.prototype.setMaxRPS = function (rps) {\n  this.setRateLimitOptions({\n    maxRequests: rps,\n    perMilliseconds: 1000\n  })\n}\n\nAxiosRateLimit.prototype.setRateLimitOptions = function (options) {\n  if (!options) return\n  var newWindows = buildWindows(options)\n  clearWindowsTimeouts(this.windows)\n  this.windows = newWindows\n  this.shift()\n}\n\nAxiosRateLimit.prototype.enable = function (axios) {\n  var self = this\n\n  this.interceptors.request = axios.interceptors.request.use(\n    this.handleRequest,\n    function (error) { return Promise.reject(error) }\n  )\n  this.interceptors.response = axios.interceptors.response.use(\n    this.handleResponse,\n    function (error) {\n      self.shift()\n      return Promise.reject(error)\n    }\n  )\n}\n\n/*\n * from axios library (dispatchRequest.js:11)\n * @param config\n */\nfunction throwIfCancellationRequested (config) {\n  if (config.cancelToken) {\n    config.cancelToken.throwIfRequested()\n  }\n  if (config.signal && config.signal.aborted) {\n    var reason = config.signal.reason\n    throw reason != null ? reason : new Error('canceled')\n  }\n}\n\nAxiosRateLimit.prototype.handleRequest = function (request) {\n  return new Promise(function (resolve, reject) {\n    this.push({\n      /*\n       * rejects a cancelled request and returns request has been resolved or not\n       * @returns {boolean}\n       */\n      resolve: function () {\n        try {\n          throwIfCancellationRequested(request)\n        } catch (error) {\n          reject(error)\n          return false\n        }\n        resolve(request)\n        return true\n      }\n    })\n  }.bind(this))\n}\n\nAxiosRateLimit.prototype.handleResponse = function (response) {\n  this.shift()\n  return response\n}\n\nAxiosRateLimit.prototype.push = function (requestHandler) {\n  this.queue.push(requestHandler)\n  this.shiftInitial()\n}\n\nAxiosRateLimit.prototype.shiftInitial = function () {\n  setTimeout(function () { return this.shift() }.bind(this), 0)\n}\n\nAxiosRateLimit.prototype.shift = function () {\n  if (!this.queue.length) return\n  var windows = this.windows\n  for (var i = 0; i < windows.length; i++) {\n    if (windows[i].count === windows[i].max) {\n      var tid = windows[i].timeoutId\n      if (tid && typeof tid.ref === 'function') {\n        tid.ref()\n      }\n      return\n    }\n  }\n\n  var queued = this.queue.shift()\n  var resolved = queued.resolve()\n\n  if (!resolved) {\n    this.shift()\n    return\n  }\n\n  var self = this\n  for (var j = 0; j < windows.length; j++) {\n    var w = windows[j]\n    w.count += 1\n    if (w.count === 1) {\n      w.timeoutId = setTimeout(function (win) {\n        win.count = 0\n        win.timeoutId = null\n        self.shift()\n        var wins = self.windows\n        while (self.queue.length) {\n          var blocked = false\n          for (var k = 0; k < wins.length; k++) {\n            if (wins[k].count >= wins[k].max) {\n              blocked = true\n              break\n            }\n          }\n          if (blocked) break\n          self.shift()\n        }\n      }.bind(null, w), w.perMs)\n      if (typeof w.timeoutId.unref === 'function') {\n        if (this.queue.length === 0) w.timeoutId.unref()\n      }\n    }\n  }\n}\n\n/**\n * Apply rate limit to axios instance.\n *\n * @example\n *   import axios from 'axios';\n *   import rateLimit from 'axios-rate-limit';\n *\n *   const http = rateLimit(axios.create(), { limits: [{ maxRequests: 2, duration: '1s' }] })\n *   http.getMaxRPS() // 2\n *   http.get('https://example.com/api/v1/users.json?page=1') // will perform immediately\n *   http.get('https://example.com/api/v1/users.json?page=2') // will perform immediately\n *   http.get('https://example.com/api/v1/users.json?page=3') // will perform after 1 second from the first one\n *   http.setMaxRPS(3)\n *   http.getMaxRPS() // 3\n *   http.setRateLimitOptions({ maxRequests: 6, perMilliseconds: 150 }) // same options as constructor\n *\n * @param {Object} axios axios instance\n * @param {Object} options options for rate limit, available for live update\n * @param {Number} options.maxRequests max requests to perform concurrently in given amount of time.\n * @param {Number} options.perMilliseconds amount of time to limit concurrent requests.\n * @param {Object} options.queue optional queue (object with push, shift methods and length property).\n * @param {Object} options.limits optional array of rate limit entries.\n * @param {Number} options.limits[].maxRequests max requests to perform concurrently in given amount of time.\n * @param {String} options.limits[].duration duration of the rate limit window.\n * @returns {Object} axios instance with interceptors added\n */\nfunction axiosRateLimit (axios, options) {\n  var queue = (options && options.queue) || []\n  var rateLimitInstance = new AxiosRateLimit(axios, queue)\n  if (options != null) {\n    rateLimitInstance.setRateLimitOptions(options)\n  }\n\n  axios.getQueue = AxiosRateLimit.prototype.getQueue.bind(rateLimitInstance)\n  axios.getMaxRPS = AxiosRateLimit.prototype.getMaxRPS.bind(rateLimitInstance)\n  axios.setMaxRPS = AxiosRateLimit.prototype.setMaxRPS.bind(rateLimitInstance)\n  axios.setRateLimitOptions = AxiosRateLimit.prototype.setRateLimitOptions\n    .bind(rateLimitInstance)\n\n  return axios\n}\n\naxiosRateLimit._clearWindowsTimeouts = clearWindowsTimeouts\nmodule.exports = axiosRateLimit\n"]}