gd-sprest 9.7.5 → 9.7.7
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/build/rest.js +1 -1
- package/build/utils/request.js +41 -25
- package/build/utils/xhrRequest.js +2 -0
- package/dist/gd-sprest.js +1 -1
- package/dist/gd-sprest.min.js +1 -1
- package/package.json +2 -2
package/build/rest.js
CHANGED
package/build/utils/request.js
CHANGED
|
@@ -698,34 +698,50 @@ export const Request = {
|
|
|
698
698
|
targetInfo.accessToken = base.targetInfo.accessToken || (base.xhr.isGraph ? Graph.Token : null);
|
|
699
699
|
targetInfo.endpoint = "";
|
|
700
700
|
targetInfo.url = data["@odata.nextLink"] || data.d.__next;
|
|
701
|
-
//
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
701
|
+
// Determine if we are about to get throttled
|
|
702
|
+
let rateLimitRemaining = parseInt(xhr.getResponseHeader("RateLimit-Remaining"));
|
|
703
|
+
let rateLimitReset = parseInt(xhr.getResponseHeader("RateLimit-Reset"));
|
|
704
|
+
let sleepInMS = 0;
|
|
705
|
+
if (typeof (rateLimitRemaining) === "number" && typeof (rateLimitReset) === "number") {
|
|
706
|
+
// Ensure we are below the threshold
|
|
707
|
+
if (rateLimitRemaining < 50) {
|
|
708
|
+
// Calculate the time to wait before executing the next call
|
|
709
|
+
sleepInMS = rateLimitReset * 1000;
|
|
710
|
+
// Log
|
|
711
|
+
console.info("[gd-sprest] Throttle approaching from response. Waiting " + sleepInMS + "ms before sending the next request.");
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
// Wait before we execute the call
|
|
715
|
+
setTimeout(() => {
|
|
716
|
+
// Create a new object
|
|
717
|
+
new XHRRequest(true, new TargetInfo(targetInfo), (xhr) => {
|
|
718
|
+
var _a, _b;
|
|
719
|
+
// Convert the response and see if values were returned
|
|
720
|
+
let data = JSON.parse(xhr.response);
|
|
721
|
+
if (data.d || data.value) {
|
|
722
|
+
// See if we are not bypassing the processing of the response
|
|
723
|
+
if (base.targetInfo.disableProcessing != true) {
|
|
724
|
+
// Update the data collection
|
|
725
|
+
Helper.updateDataCollection(base, ((_a = data.d) === null || _a === void 0 ? void 0 : _a.results) || data.value);
|
|
726
|
+
// Update the expanded properties
|
|
727
|
+
Helper.updateExpandedProperties(base);
|
|
728
|
+
}
|
|
729
|
+
// Append the raw data results
|
|
730
|
+
if ((_b = base["d"]) === null || _b === void 0 ? void 0 : _b.results) {
|
|
731
|
+
base["d"].results = base["d"].results.concat(data.d.results);
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
base["value"] = base["value"].concat(data.value);
|
|
735
|
+
}
|
|
736
|
+
// Validate the data collection
|
|
737
|
+
request(xhr, resolve);
|
|
717
738
|
}
|
|
718
739
|
else {
|
|
719
|
-
|
|
740
|
+
// Resolve the promise
|
|
741
|
+
resolve();
|
|
720
742
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
// Resolve the promise
|
|
726
|
-
resolve();
|
|
727
|
-
}
|
|
728
|
-
});
|
|
743
|
+
});
|
|
744
|
+
}, sleepInMS);
|
|
729
745
|
}
|
|
730
746
|
else {
|
|
731
747
|
// Add a method to get the next set of results
|
|
@@ -33,6 +33,8 @@ export class XHRRequest {
|
|
|
33
33
|
get isGraph() { return this.targetInfo.isGraph; }
|
|
34
34
|
// Flag indicating the request has completed
|
|
35
35
|
get completedFl() { return this.xhr ? this.xhr.readyState == 4 : false; }
|
|
36
|
+
// Gets a response header
|
|
37
|
+
getResponseHeader(key) { return this.xhr ? this.xhr.getResponseHeader(key) : ""; }
|
|
36
38
|
// The response
|
|
37
39
|
get response() { return this.xhr ? this.xhr.response : null; }
|
|
38
40
|
// The xml http request
|