@autofleet/network 1.5.1 → 1.5.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 +12 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -174,12 +174,22 @@ module.exports = class Network {
|
|
|
174
174
|
return currentResult;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Fetches all pages from a paginated API endpoint until all results are retrieved
|
|
179
|
+
* or an optional page limit is reached.
|
|
180
|
+
*
|
|
181
|
+
* @param {string} url - The endpoint URL to send the request to.
|
|
182
|
+
* @param {object} [options={}] - Additional options to include in the request payload.
|
|
183
|
+
* @param {number} [pageLimit=100] - The maximum number of pages to fetch.
|
|
184
|
+
* Set to -1 for no limit.
|
|
185
|
+
* @returns {Promise<Array>} - A promise that resolves to an array of all results.
|
|
186
|
+
*/
|
|
187
|
+
async getAllPagesFromQueryEndpoint(url, options = {}, pageLimit = 100) {
|
|
178
188
|
let currentResult = [];
|
|
179
189
|
|
|
180
190
|
let moreResultsToLoad = true;
|
|
181
191
|
let page = 1;
|
|
182
|
-
while(moreResultsToLoad && page <
|
|
192
|
+
while (moreResultsToLoad && (pageLimit === -1 || page < pageLimit)) {
|
|
183
193
|
const { data } = await this.post(url, {
|
|
184
194
|
...options,
|
|
185
195
|
page: page,
|