/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@audc/retry-axios@3.2.6/build/src/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import axios,{isCancel}from"axios";const retryRanges=[[100,199],[429,429],[500,599]];export function attach(e){const t=e||axios;return t.interceptors.response.use(onFulfilled,(async e=>onError(t,e)))}export function detach(e,t){(t||axios).interceptors.response.eject(e)}function onFulfilled(e){return e}function normalizeArray(e){const t=[];if(e){if(Array.isArray(e))return e;if("object"==typeof e)for(const r of Object.keys(e)){const o=Number.parseInt(r,10);Number.isNaN(o)||(t[o]=e[r])}return t}}function parseRetryAfter(e){const t=Number(e);if(!Number.isNaN(t))return 1e3*t;const r=Date.parse(e);return Number.isNaN(r)?void 0:r-Date.now()}async function onError(e,t){if(isCancel(t))throw t;const r=getConfig(t)||{};r.currentRetryAttempt||=0,r.retry="number"==typeof r.retry?r.retry:3,r.retryDelay="number"==typeof r.retryDelay?r.retryDelay:100,r.instance||=e,r.backoffType||="exponential",r.httpMethodsToRetry=normalizeArray(r.httpMethodsToRetry)||["GET","HEAD","PUT","OPTIONS","DELETE"],r.noResponseRetries="number"==typeof r.noResponseRetries?r.noResponseRetries:2,r.checkRetryAfter="boolean"!=typeof r.checkRetryAfter||r.checkRetryAfter,r.maxRetryAfter="number"==typeof r.maxRetryAfter?r.maxRetryAfter:3e5,r.statusCodesToRetry=normalizeArray(r.statusCodesToRetry)||retryRanges;const o=t;o.config=o.config||{},o.config.raxConfig={...r};if(!(r.shouldRetry||shouldRetryRequest)(o))throw o;const n=new Promise(((e,t)=>{let n=0;if(r.checkRetryAfter&&o.response?.headers?.["retry-after"]){const e=parseRetryAfter(o.response.headers["retry-after"]);if(!(e&&e>0&&e<=(r.maxRetryAfter??0)))return void t(o);n=e}o.config.raxConfig.currentRetryAttempt+=1;const s=o.config.raxConfig.currentRetryAttempt;0===n&&(n="linear"===r.backoffType?1e3*s:"static"===r.backoffType?r.retryDelay:(2**s-1)/2*1e3,"number"==typeof r.maxRetryDelay&&(n=Math.min(n,r.maxRetryDelay))),setTimeout(e,n)}));return r.onError&&await r.onError(o),Promise.resolve().then((async()=>n)).then((async()=>r.onRetryAttempt?.(o))).then((async()=>r.instance?.request(o.config)))}export function shouldRetryRequest(e){const t=e.config.raxConfig;if(!t||0===t.retry)return!1;if(!e.response&&(t.currentRetryAttempt||0)>=(t.noResponseRetries??0))return!1;if(!e.config?.method||!t.httpMethodsToRetry?.includes(e.config.method.toUpperCase()))return!1;if(e.response?.status){let r=!1;for(const[o,n]of t.statusCodesToRetry){const{status:t}=e.response;if(t>=o&&t<=n){r=!0;break}}if(!r)return!1}return t.currentRetryAttempt||=0,!(t.currentRetryAttempt>=(t.retry??0))}export function getConfig(e){if(e?.config)return e.config.raxConfig}
//# sourceMappingURL=/sm/0057ac8e9dbbc7e5a63dac846a61daac655b06b4700f8753f7fcc166a54ec8dd.map