@autofleet/network 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +11 -1
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -4,6 +4,8 @@ const { Logger } = require('@autofleet/node-common');
|
|
|
4
4
|
const qs = require('qs');
|
|
5
5
|
const httpAdapter = require('axios/lib/adapters/http');
|
|
6
6
|
const merge = require('deepmerge');
|
|
7
|
+
const { setupCache } = require('axios-cache-adapter');
|
|
8
|
+
|
|
7
9
|
require('dotenv').config();
|
|
8
10
|
/**
|
|
9
11
|
* Add support for nock testing
|
|
@@ -37,6 +39,14 @@ module.exports = class Network {
|
|
|
37
39
|
this.settings = merge(defaultSettings, settings);
|
|
38
40
|
this.createBaseUrl();
|
|
39
41
|
|
|
42
|
+
if(settings.cache) {
|
|
43
|
+
const cache = setupCache({
|
|
44
|
+
maxAge: 15 * 60 * 1000,
|
|
45
|
+
...settings.cache
|
|
46
|
+
});
|
|
47
|
+
settings.adapter = cache.adapter;
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
this.axios = axios.create(this.settings);
|
|
41
51
|
this.addRetry(settings);
|
|
42
52
|
this.buildClassHttpMethods();
|
|
@@ -104,7 +114,7 @@ module.exports = class Network {
|
|
|
104
114
|
|
|
105
115
|
const localOptions = { params: {}, ...options };
|
|
106
116
|
localOptions.params.page = 1;
|
|
107
|
-
while(localOptions.params.page === 1 || lastResultsSize
|
|
117
|
+
while(localOptions.params.page === 1 || lastResultsSize === resultsInFirstPage) {
|
|
108
118
|
const { data } = await this.get(url, localOptions);
|
|
109
119
|
lastResultsSize = data.length;
|
|
110
120
|
if(localOptions.params.page === 1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/network",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"author": "Dor Shay",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@autofleet/node-common": "^1.1
|
|
15
|
-
"axios": "^0.
|
|
14
|
+
"@autofleet/node-common": "^1.5.1",
|
|
15
|
+
"axios": "^0.19.2",
|
|
16
16
|
"axios-retry": "^3.1.1",
|
|
17
17
|
"deepmerge": "^3.0.0",
|
|
18
18
|
"dotenv": "^6.0.0",
|