{"_id":"@banyudu/axios-retry","name":"@banyudu/axios-retry","dist-tags":{"latest":"4.5.0"},"versions":{"4.5.0":{"name":"@banyudu/axios-retry","version":"4.5.0","author":{"name":"Rubén Norte","email":"ruben.norte@softonic.com"},"description":"Axios plugin that intercepts failed requests and retries them whenever posible.","license":"Apache-2.0","homepage":"https://github.com/softonic/axios-retry","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"scripts":{"lint":"eslint .","pretest":"npm run lint","test":"ts-node --project tsconfig-cjs.json node_modules/jasmine/bin/jasmine","prebuild":"npm run test","build":"rm -fr dist/* && npm run build:esm && npm run build:cjs","build:esm":"tsc -p tsconfig.json && echo '{\"type\":\"module\"}' > dist/esm/package.json","build:cjs":"tsc -p tsconfig-cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json","prerelease":"npm run build","prepublishOnly":"npm run build","release":"npm version -m \"New version: %s\"","postrelease":"npm run push && npm publish","push":"git push origin master && git push origin --tags","prepare":"husky install"},"lint-staged":{"*.ts":["eslint --cache --fix","prettier --write"]},"dependencies":{"is-retry-allowed":"^2.2.0"},"peerDependencies":{"axios":"0.x || 1.x"},"devDependencies":{"@types/axios":"^0.14.0","@types/node":"^20.9.1","@types/jasmine":"^5.1.2","@typescript-eslint/eslint-plugin":"^6.11.0","@typescript-eslint/parser":"^6.11.0","axios":"^1.6.2","eslint":"^8.53.0","eslint-config-prettier":"^9.0.0","eslint-plugin-jasmine":"^4.1.3","eslint-plugin-prettier":"^5.0.1","husky":"^8.0.3","jasmine":"^5.1.0","lint-staged":"^15.1.0","nock":"^13.3.8","prettier":"^3.1.0","ts-node":"^10.9.1","typescript":"^5.2.2"},"repository":{"type":"git","url":"git+https://github.com/softonic/axios-retry.git"},"bugs":{"url":"https://github.com/softonic/axios-retry/issues"},"types":"dist/cjs/index.d.ts","main":"dist/cjs/index.js","module":"dist/esm/index.js","exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}},"./package.json":"./package.json"},"_id":"@banyudu/axios-retry@4.5.0","gitHead":"25b35e0a9f3cd5b831fed5c009c683dedbc6c283","_nodeVersion":"18.20.0","_npmVersion":"10.5.0","dist":{"integrity":"sha512-EXcUc5xN2lQMSj1jWLW4DmwAuMW+1CfCCmsezHuOocPWVLeOErgOBQWVDrZfp+iWpHi/qH8tRTEFK8QEMVe+6A==","shasum":"1d2656c12b5aee746a417dc1a2f13bf8137d7dcc","tarball":"https://registry.npmjs.org/@banyudu/axios-retry/-/axios-retry-4.5.0.tgz","fileCount":9,"unpackedSize":33538,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD/WENeYZx8e1L7RU5MwbTnrVuHXMFN6EFOPFgWB8vOzgIgEVrVuG2IsNQ6n09IIgJDjrrjR/ccxny8D/9lPij8yLo="}]},"_npmUser":{"name":"banyudu","email":"banyudu@gmail.com"},"directories":{},"maintainers":[{"name":"banyudu","email":"banyudu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/axios-retry_4.5.0_1733723363863_0.9315208819073961"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-09T05:49:23.731Z","4.5.0":"2024-12-09T05:49:24.031Z","modified":"2024-12-09T05:49:24.340Z"},"maintainers":[{"name":"banyudu","email":"banyudu@gmail.com"}],"description":"Axios plugin that intercepts failed requests and retries them whenever posible.","homepage":"https://github.com/softonic/axios-retry","repository":{"type":"git","url":"git+https://github.com/softonic/axios-retry.git"},"author":{"name":"Rubén Norte","email":"ruben.norte@softonic.com"},"bugs":{"url":"https://github.com/softonic/axios-retry/issues"},"license":"Apache-2.0","readme":"# axios-retry\n\n[![Node.js CI](https://github.com/softonic/axios-retry/actions/workflows/node.js.yml/badge.svg)](https://github.com/softonic/axios-retry/actions/workflows/node.js.yml)\n\nAxios plugin that intercepts failed requests and retries them whenever possible.\n\n## Installation\n\n```bash\nnpm install axios-retry\n```\n\n## Usage\n\n```js\n// CommonJS\n// const axiosRetry = require('axios-retry').default;\n\n// ES6\nimport axiosRetry from 'axios-retry';\n\naxiosRetry(axios, { retries: 3 });\n\naxios.get('http://example.com/test') // The first request fails and the second returns 'ok'\n  .then(result => {\n    result.data; // 'ok'\n  });\n\n// Exponential back-off retry delay between requests\naxiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay });\n\n// Liner retry delay between requests\naxiosRetry(axios, { retryDelay: axiosRetry.linearDelay() });\n\n// Custom retry delay\naxiosRetry(axios, { retryDelay: (retryCount) => {\n  return retryCount * 1000;\n}});\n\n// Works with custom axios instances\nconst client = axios.create({ baseURL: 'http://example.com' });\naxiosRetry(client, { retries: 3 });\n\nclient.get('/test') // The first request fails and the second returns 'ok'\n  .then(result => {\n    result.data; // 'ok'\n  });\n\n// Allows request-specific configuration\nclient\n  .get('/test', {\n    'axios-retry': {\n      retries: 0\n    }\n  })\n  .catch(error => { // The first request fails\n    error !== undefined\n  });\n```\n\n**Note:** Unless `shouldResetTimeout` is set, the plugin interprets the request timeout as a global value, so it is not used for each retry but for the whole request lifecycle.\n\n## Options\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| retries | `Number` | `3` | The number of times to retry before failing. 1 = One retry after first failure |\n| retryCondition | `Function` | `isNetworkOrIdempotentRequestError` | A callback to further control if a request should be retried.  By default, it retries if it is a network error or a 5xx error on an idempotent request (GET, HEAD, OPTIONS, PUT or DELETE). |\n| shouldResetTimeout | `Boolean` | false | Defines if the timeout should be reset between retries |\n| retryDelay | `Function` | `function noDelay() { return 0; }` | A callback to further control the delay in milliseconds between retried requests. By default there is no delay between retries. Another option is exponentialDelay ([Exponential Backoff](https://developers.google.com/analytics/devguides/reporting/core/v3/errors#backoff)) or `linearDelay`. The function is passed `retryCount` and `error`. |\n| onRetry | `Function` | `function onRetry(retryCount, error, requestConfig) { return; }` | A callback to notify when a retry is about to occur. Useful for tracing and you can any async process for example refresh a token on 401. By default nothing will occur. The function is passed `retryCount`, `error`, and `requestConfig`. |\n| onMaxRetryTimesExceeded | `Function` | `function onMaxRetryTimesExceeded(error, retryCount) { return; }` | After all the retries are failed, this callback will be called with the last error before throwing the error. |\n| validateResponse | `Function \\| null` | `null` | A callback to define whether a response should be resolved or rejected. If null is passed, it will fallback to the axios default (only 2xx status codes are resolved). |\n\n## Testing\n\nClone the repository and execute:\n\n```bash\nnpm test\n```\n\n## Contribute\n\n1. Fork it: `git clone https://github.com/softonic/axios-retry.git`\n2. Create your feature branch: `git checkout -b feature/my-new-feature`\n3. Commit your changes: `git commit -am 'Added some feature'`\n4. Check the build: `npm run build`\n5. Push to the branch: `git push origin my-new-feature`\n6. Submit a pull request :D\n","readmeFilename":"README.md"}