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 CHANGED
@@ -6,7 +6,7 @@ import { GraphTypes, SPTypes } from "./sptypes";
6
6
  * SharePoint REST Library
7
7
  */
8
8
  export const $REST = {
9
- __ver: 9.75,
9
+ __ver: 9.77,
10
10
  AppContext: (siteUrl) => { return Lib.Site.getAppContext(siteUrl); },
11
11
  Apps: Lib.Apps,
12
12
  ContextInfo: Lib.ContextInfo,
@@ -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
- // Create a new object
702
- new XHRRequest(true, new TargetInfo(targetInfo), (xhr) => {
703
- var _a, _b;
704
- // Convert the response and see if values were returned
705
- let data = JSON.parse(xhr.response);
706
- if (data.d || data.value) {
707
- // See if we are not bypassing the processing of the response
708
- if (base.targetInfo.disableProcessing != true) {
709
- // Update the data collection
710
- Helper.updateDataCollection(base, ((_a = data.d) === null || _a === void 0 ? void 0 : _a.results) || data.value);
711
- // Update the expanded properties
712
- Helper.updateExpandedProperties(base);
713
- }
714
- // Append the raw data results
715
- if ((_b = base["d"]) === null || _b === void 0 ? void 0 : _b.results) {
716
- base["d"].results = base["d"].results.concat(data.d.results);
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
- base["value"] = base["value"].concat(data.value);
740
+ // Resolve the promise
741
+ resolve();
720
742
  }
721
- // Validate the data collection
722
- request(xhr, resolve);
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