@nuskin/axios-util
Advanced tools
Comparing version 1.0.2 to 2.0.0-ngei-508.1
{ | ||
"name": "@nuskin/axios-util", | ||
"version": "1.0.2", | ||
"version": "2.0.0-ngei-508.1", | ||
"description": "An Axios utility ...", | ||
@@ -22,2 +22,3 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"axios": "0.27.2", | ||
"axios-mock-adapter": "1.19.0", | ||
@@ -30,9 +31,11 @@ "eslint": "7.19.0", | ||
"jest-sonar-reporter": "2.0.0", | ||
"json-colorizer": "2.2.2", | ||
"prettier": "2.2.1" | ||
}, | ||
"dependencies": { | ||
"axios": "0.21.1", | ||
"axios-retry": "3.1.9" | ||
"axios-retry": "3.1.9", | ||
"deepmerge": "4.2.2" | ||
}, | ||
"peerDependencies": { | ||
"axios": "^0.27.2" | ||
}, | ||
"files": [ | ||
@@ -39,0 +42,0 @@ "/src" |
# @nuskin/axios-util | ||
`axios-util` allows you to use Axios in the exact same way you would use Axios | ||
by itself, with one exception. `axios-util` builds the `retry` and `timeout` | ||
resiliency patterns into Axios for you. | ||
by itself. By default `axios-util` will set the **timeout** to _10000ms_. | ||
The default timeout has been set to `10000ms`. | ||
Retry has been implemented with the [axios-retry](https://www.npmjs.com/package/axios-retry) module. | ||
Use `getRetryAxiosInstance()` to get an axios instance with `retry` added to it. All defaults of | ||
`axios-retry` are used except for *retryDelay*. *retryDelay* is set to *axiosRetry.exponentialDelay*. | ||
You can set your own behavior by providing an `axios-retry` options object to `getRetryAxiosInstance()`. | ||
Retry has been implemented with the [axios-retry](https://www.npmjs.com/package/axios-retry) module. All defaults of `axios-retry` are used except for *retryDelay*. *retryDelay* | ||
is set to *axiosRetry.exponentialDelay* | ||
## Installing | ||
@@ -17,3 +16,3 @@ | ||
```bash | ||
npm add @nuskin/axios-util | ||
npm install @nuskin/axios-util | ||
``` | ||
@@ -39,8 +38,12 @@ | ||
```js | ||
const { axios, axiosRetry } = require('@nuskin/axios-util') | ||
const { axios, getRetryAxiosInstance } = require('@nuskin/axios-util') | ||
// Custom retry delay | ||
axiosRetry(axios, { retryDelay: (retryCount) => { | ||
return retryCount * 1000; | ||
}}) | ||
const myAxiosWithRetry = getRetryAxiosInstance({ | ||
retries: 3, | ||
shouldResetTimeout: true, | ||
retryDelay: (retryCount) => { | ||
return retryCount * 1000; | ||
} | ||
}) | ||
``` | ||
@@ -47,0 +50,0 @@ |
@@ -7,3 +7,4 @@ 'use strict' | ||
*/ | ||
const axios = require('axios') | ||
const merge = require('deepmerge') | ||
const axios = require('axios').default | ||
const axiosRetry = require('axios-retry') | ||
@@ -13,7 +14,17 @@ | ||
axiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay }) | ||
/** | ||
* | ||
* @param {Object} options `axios-retry` options to pass in. | ||
* @returns {AxiosInstance} | ||
*/ | ||
const getRetryAxiosInstance = (options = {}) => { | ||
const retryConfig = merge({ retryDelay: axiosRetry.exponentialDelay }, options) | ||
const axiosRetryInstance = axios.create() | ||
axiosRetry(axiosRetryInstance, retryConfig) | ||
return axiosRetryInstance | ||
} | ||
module.exports = { | ||
axios, | ||
axiosRetry | ||
getRetryAxiosInstance | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3170
23
60
3
1
+ Addeddeepmerge@4.2.2
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@0.27.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddeepmerge@4.2.2(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
- Removedaxios@0.21.1
- Removedaxios@0.21.1(transitive)