import{i as e}from"./chunk-DQhVL27x.js";const t="axios-retry";function r(t){return!t.response&&!!t.code&&!["ERR_CANCELED","ECONNABORTED"].includes(t.code)&&e(t)}const n=["get","head","options"],o=n.concat(["put","delete"]);function s(e){return"ECONNABORTED"!==e.code&&(!e.response||429===e.response.status||e.response.status>=500&&e.response.status<=599)}function i(e){var t;return!!(null==(t=e.config)?void 0:t.method)&&s(e)&&-1!==o.indexOf(e.config.method)}function a(e){return r(e)||i(e)}function u(e=void 0){var t;const r=null==(t=null==e?void 0:e.response)?void 0:t.headers["retry-after"];if(!r)return 0;let n=1e3*(Number(r)||0);return 0===n&&(n=(new Date(r).valueOf()||0)-Date.now()),Math.max(0,n)}const c={retries:3,retryCondition:a,retryDelay:function(e=0,t=void 0){return Math.max(0,u(t))},shouldResetTimeout:!1,onRetry:()=>{},onMaxRetryTimesExceeded:()=>{},validateResponse:null};function l(e,r,n=!1){const o=(s=e,i=r||{},{...c,...i,...s[t]});var s,i;return o.retryCount=o.retryCount||0,o.lastRequestTime&&!n||(o.lastRequestTime=Date.now()),e[t]=o,o}const d=(e,r)=>({requestInterceptorId:e.interceptors.request.use(e=>{var n;return l(e,r,!0),(null==(n=e[t])?void 0:n.validateResponse)&&(e.validateStatus=()=>!1),e}),responseInterceptorId:e.interceptors.response.use(null,async t=>{var n;const{config:o}=t;if(!o)return Promise.reject(t);const s=l(o,r);return t.response&&(null==(n=s.validateResponse)?void 0:n.call(s,t.response))?t.response:await async function(e,t){const{retries:r,retryCondition:n}=e,o=(e.retryCount||0)<r&&n(t);if("object"==typeof o)try{return!1!==await o}catch(s){return!1}return o}(s,t)?async function(e,t,r,n){var o;t.retryCount+=1;const{retryDelay:s,shouldResetTimeout:i,onRetry:a}=t,u=s(t.retryCount,r);if(l=n,(c=e).defaults.agent===l.agent&&delete l.agent,c.defaults.httpAgent===l.httpAgent&&delete l.httpAgent,c.defaults.httpsAgent===l.httpsAgent&&delete l.httpsAgent,!i&&n.timeout&&t.lastRequestTime){const e=Date.now()-t.lastRequestTime,o=n.timeout-e-u;if(o<=0)return Promise.reject(r);n.timeout=o}var c,l;return n.transformRequest=[e=>e],await a(t.retryCount,r,n),(null==(o=n.signal)?void 0:o.aborted)?Promise.resolve(e(n)):new Promise(t=>{var r;const o=()=>{clearTimeout(s),t(e(n))},s=setTimeout(()=>{var r;t(e(n)),(null==(r=n.signal)?void 0:r.removeEventListener)&&n.signal.removeEventListener("abort",o)},u);(null==(r=n.signal)?void 0:r.addEventListener)&&n.signal.addEventListener("abort",o,{once:!0})})}(e,s,t,o):(await async function(e,t){e.retryCount>=e.retries&&await e.onMaxRetryTimesExceeded(t,e.retryCount)}(s,t),Promise.reject(t))})});d.isNetworkError=r,d.isSafeRequestError=function(e){var t;return!!(null==(t=e.config)?void 0:t.method)&&s(e)&&-1!==n.indexOf(e.config.method)},d.isIdempotentRequestError=i,d.isNetworkOrIdempotentRequestError=a,d.exponentialDelay=function(e=0,t=void 0,r=100){const n=2**e*r,o=Math.max(n,u(t));return o+.2*o*Math.random()},d.linearDelay=function(e=100){return(t=0,r=void 0)=>{const n=t*e;return Math.max(n,u(r))}},d.isRetryableError=s;export{d as a};
