gd-sprest 9.7.7 → 9.7.8

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.77,
9
+ __ver: 9.78,
10
10
  AppContext: (siteUrl) => { return Lib.Site.getAppContext(siteUrl); },
11
11
  Apps: Lib.Apps,
12
12
  ContextInfo: Lib.ContextInfo,
@@ -698,18 +698,13 @@ 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
- // Determine if we are about to get throttled
702
- let rateLimitRemaining = parseInt(xhr.getResponseHeader("RateLimit-Remaining"));
703
- let rateLimitReset = parseInt(xhr.getResponseHeader("RateLimit-Reset"));
701
+ // Set the sleep value to prevent throttling
704
702
  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
- }
703
+ if (xhr.rateLimit && xhr.rateLimit.remaining < 50) {
704
+ // Set the rate
705
+ sleepInMS = xhr.rateLimit.reset * 1000;
706
+ // Log
707
+ console.info("[gd-sprest] Throttle approaching... Waiting " + sleepInMS + "ms before sending the next request.", xhr.rateLimit);
713
708
  }
714
709
  // Wait before we execute the call
715
710
  setTimeout(() => {
@@ -726,6 +721,8 @@ export const Request = {
726
721
  // Update the expanded properties
727
722
  Helper.updateExpandedProperties(base);
728
723
  }
724
+ // Set the rate limit information
725
+ base.rateLimit = xhr.rateLimit;
729
726
  // Append the raw data results
730
727
  if ((_b = base["d"]) === null || _b === void 0 ? void 0 : _b.results) {
731
728
  base["d"].results = base["d"].results.concat(data.d.results);
@@ -41,6 +41,19 @@ export class XHRRequest {
41
41
  get request() { return this.xhr ? this.xhr : null; }
42
42
  // The data send in the body of the request
43
43
  get requestData() { return this.targetInfo.requestData; }
44
+ // Return the rate limit information
45
+ get rateLimit() {
46
+ // Ensure the rate limit information exists
47
+ if (this.xhr == null || this.getResponseHeader("RateLimit-Limit") == null) {
48
+ return null;
49
+ }
50
+ // Return the rate limit information
51
+ return {
52
+ limit: this.getResponseHeader("RateLimit-Limit"),
53
+ remaining: parseInt(this.getResponseHeader("RateLimit-Remaining")),
54
+ reset: parseInt(this.getResponseHeader("RateLimit-Reset"))
55
+ };
56
+ }
44
57
  // The request headers
45
58
  get requestHeaders() { return this.headers; }
46
59
  // The request information