@autofleet/network 1.4.6 → 1.4.8-beta-1
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 +25 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -46,12 +46,8 @@ module.exports = class Network {
|
|
|
46
46
|
constructor(settings = {}) {
|
|
47
47
|
this.settings = merge(defaultSettings, settings);
|
|
48
48
|
if (this.settings.keepAlive) {
|
|
49
|
-
const keepaliveAgent = new Agent(
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
const keepaliveHttpsAgent = new HttpsAgent({
|
|
53
|
-
maxSockets: 1000
|
|
54
|
-
});
|
|
49
|
+
const keepaliveAgent = new Agent();
|
|
50
|
+
const keepaliveHttpsAgent = new HttpsAgent();
|
|
55
51
|
this.settings.httpAgent = keepaliveAgent;
|
|
56
52
|
this.settings.httpsAgent = keepaliveHttpsAgent;
|
|
57
53
|
delete this.settings.keepAlive;
|
|
@@ -165,4 +161,27 @@ module.exports = class Network {
|
|
|
165
161
|
|
|
166
162
|
return currentResult;
|
|
167
163
|
}
|
|
164
|
+
|
|
165
|
+
async getAllPagesFromQueryEndpoint(url, options = {}) {
|
|
166
|
+
let currentResult = [];
|
|
167
|
+
|
|
168
|
+
if(!options.perPage) {
|
|
169
|
+
throw new Error('Missing perPage option');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const perPage = options.perPage;
|
|
173
|
+
let lastResultSizeIsLessThanPerPage = false;
|
|
174
|
+
let page = 0;
|
|
175
|
+
while(!lastResultSizeIsLessThanPerPage) {
|
|
176
|
+
const { data } = await this.get(url, {
|
|
177
|
+
...options,
|
|
178
|
+
page: currentResult.length / perPage + 1,
|
|
179
|
+
});
|
|
180
|
+
page += 1;
|
|
181
|
+
currentResult = currentResult.concat(data);
|
|
182
|
+
lastResultSizeIsLessThanPerPage = data.length < perPage;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return currentResult;
|
|
186
|
+
}
|
|
168
187
|
};
|