@mediocre/walmart-marketplace
Advanced tools
Comparing version 1.4.2 to 1.4.3
60
index.js
@@ -772,2 +772,4 @@ const crypto = require('crypto'); | ||
* @param {Object} [options] | ||
* @param {Boolean} [options.autoPagination] If true, automatically fetches all pages of results. Defaults to false. | ||
* @param {Number} [options.limit] Number of records to be returned. Default is 10. | ||
* @param {String} [options.reportVersion] Version of report for which the request is created. Example, v1. | ||
@@ -789,26 +791,50 @@ * @param {String} [options.requestStatus] Status of report request. Possible values are RECEIVED, INPROGRESS, READY, ERROR. | ||
const queryParameters = new URLSearchParams({ reportType }); | ||
const reportRequests = []; | ||
['reportVersion', 'requestStatus', 'requestSubmissionEndDate', 'requestSubmissionStartDate'].forEach(key => { | ||
if (Object.hasOwn(options, key)) { | ||
queryParameters.set(key, options[key]); | ||
const fetchReportRequests = async cursor => { | ||
let url; | ||
if (cursor) { | ||
url = `${_options.url}/v3/reports/reportRequests?${cursor}`; | ||
} else { | ||
const queryParameters = new URLSearchParams({ reportType }); | ||
['limit', 'reportVersion', 'requestStatus', 'requestSubmissionEndDate', 'requestSubmissionStartDate'].forEach(key => { | ||
if (Object.hasOwn(options, key)) { | ||
queryParameters.set(key, options[key]); | ||
} | ||
}); | ||
url = `${_options.url}/v3/reports/reportRequests?${queryParameters.toString()}`; | ||
} | ||
}); | ||
const url = `${_options.url}/v3/reports/reportRequests?${queryParameters.toString()}`; | ||
const response = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
'WM_QOS.CORRELATION_ID': crypto.randomUUID(), | ||
'WM_SEC.ACCESS_TOKEN': (await _this.authentication.getAccessToken()).access_token, | ||
'WM_SVC.NAME': _options['WM_SVC.NAME'] | ||
} | ||
}); | ||
const response = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
'WM_QOS.CORRELATION_ID': options['WM_QOS.CORRELATION_ID'] || crypto.randomUUID(), | ||
'WM_SEC.ACCESS_TOKEN': (await _this.authentication.getAccessToken()).access_token, | ||
'WM_SVC.NAME': _options['WM_SVC.NAME'] | ||
if (!response.ok) { | ||
throw new Error(response.statusText, { cause: response }); | ||
} | ||
}); | ||
if (!response.ok) { | ||
throw new Error(response.statusText, { cause: response }); | ||
} | ||
const data = await response.json(); | ||
return finalize(null, await response.json(), callback); | ||
if (Array.isArray(data?.requests)) { | ||
reportRequests.push(...data.requests); | ||
// Check for more pages and if pagination is requested | ||
if (options.autoPagination && data?.nextCursor) { | ||
await fetchReportRequests(data.nextCursor); | ||
} | ||
} | ||
}; | ||
// Initial call to fetch report requests | ||
await fetchReportRequests(null); | ||
return finalize(null, reportRequests, callback); | ||
} catch(err) { | ||
@@ -815,0 +841,0 @@ return finalize(err, null, callback); |
@@ -20,3 +20,3 @@ { | ||
}, | ||
"version": "1.4.2" | ||
"version": "1.4.3" | ||
} |
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
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
98557
777