gd-sprest 9.7.6 → 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/@types/utils/base.d.ts +0 -3
- package/build/rest.js +1 -1
- package/build/utils/helper.js +0 -1
- package/build/utils/methodInfo.js +0 -3
- package/build/utils/oData.js +0 -4
- package/build/utils/request.js +14 -1
- package/build/utils/xhrRequest.js +2 -0
- package/dist/gd-sprest.d.ts +0 -3
- package/dist/gd-sprest.js +1 -1
- package/dist/gd-sprest.min.js +1 -1
- package/package.json +2 -2
package/@types/utils/base.d.ts
CHANGED
|
@@ -58,9 +58,6 @@ export interface IBase<Type = any, Result = Type, QueryResult = Result> extends
|
|
|
58
58
|
/** Flag to get all items. */
|
|
59
59
|
getAllItemsFl: boolean;
|
|
60
60
|
|
|
61
|
-
/** Time in ms to wait inbetween requests when getting all items. */
|
|
62
|
-
getAllItemsWaitTime: number;
|
|
63
|
-
|
|
64
61
|
/** Flag determining if more items exist. */
|
|
65
62
|
nextFl: boolean;
|
|
66
63
|
|
package/build/rest.js
CHANGED
package/build/utils/helper.js
CHANGED
|
@@ -124,7 +124,6 @@ export const Helper = {
|
|
|
124
124
|
// Set the properties
|
|
125
125
|
obj.base = base.base ? base.base : base;
|
|
126
126
|
obj.getAllItemsFl = methodInfo.getAllItemsFl;
|
|
127
|
-
obj.getAllItemsWaitTime = methodInfo.getAllItemsWaitTime;
|
|
128
127
|
obj.parent = base;
|
|
129
128
|
obj.requestType = methodConfig.requestType;
|
|
130
129
|
// Ensure the return type exists
|
|
@@ -28,8 +28,6 @@ export class MethodInfo {
|
|
|
28
28
|
get body() { return this.methodData; }
|
|
29
29
|
// Flag to determine if we are getting all items
|
|
30
30
|
get getAllItemsFl() { return this.methodInfo.getAllItemsFl; }
|
|
31
|
-
// Time in ms to wait inbetween requests for getting all items
|
|
32
|
-
get getAllItemsWaitTime() { return this.methodInfo.getAllItemsWaitTime; }
|
|
33
31
|
// Flag to determine if this method replaces the endpoint
|
|
34
32
|
get replaceEndpointFl() { return this.methodInfo.replaceEndpointFl ? true : false; }
|
|
35
33
|
// The request method
|
|
@@ -198,7 +196,6 @@ export class MethodInfo {
|
|
|
198
196
|
url = "?" + oData.QueryString;
|
|
199
197
|
// Set the get all items Flag
|
|
200
198
|
this.methodInfo.getAllItemsFl = oData.GetAllItems;
|
|
201
|
-
this.methodInfo.getAllItemsWaitTime = oData.GetAllItemsWaitTime;
|
|
202
199
|
}
|
|
203
200
|
// Else, see if we are not passing the data in the body or query string as a variable
|
|
204
201
|
else if (!this.passDataInBody && !this.passDataInQSAsVar) {
|
package/build/utils/oData.js
CHANGED
|
@@ -12,7 +12,6 @@ export class OData {
|
|
|
12
12
|
this._expand = oData && oData.Expand ? oData.Expand : [];
|
|
13
13
|
this._filter = oData && oData.Filter ? oData.Filter : null;
|
|
14
14
|
this._getAllItems = oData && oData.GetAllItems ? oData.GetAllItems : false;
|
|
15
|
-
this._getAllItemsWaitTime = oData && oData.GetAllItemsWaitTime ? oData.GetAllItemsWaitTime : 0;
|
|
16
15
|
this._orderBy = oData && oData.OrderBy ? oData.OrderBy : [];
|
|
17
16
|
this._search = oData && oData.Search ? oData.Search : null;
|
|
18
17
|
this._select = oData && oData.Select ? oData.Select : [];
|
|
@@ -35,9 +34,6 @@ export class OData {
|
|
|
35
34
|
// Flag to get all items
|
|
36
35
|
get GetAllItems() { return this._getAllItems; }
|
|
37
36
|
set GetAllItems(value) { this._getAllItems = value; }
|
|
38
|
-
// Time in ms to wait between calls to avoid throttling
|
|
39
|
-
get GetAllItemsWaitTime() { return this._getAllItemsWaitTime; }
|
|
40
|
-
set GetAllItemsWaitTime(value) { this._getAllItemsWaitTime = value; }
|
|
41
37
|
// Order By
|
|
42
38
|
get OrderBy() { return this._orderBy; }
|
|
43
39
|
set OrderBy(value) { this._orderBy = value; }
|
package/build/utils/request.js
CHANGED
|
@@ -698,6 +698,19 @@ 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"));
|
|
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
|
+
}
|
|
701
714
|
// Wait before we execute the call
|
|
702
715
|
setTimeout(() => {
|
|
703
716
|
// Create a new object
|
|
@@ -728,7 +741,7 @@ export const Request = {
|
|
|
728
741
|
resolve();
|
|
729
742
|
}
|
|
730
743
|
});
|
|
731
|
-
},
|
|
744
|
+
}, sleepInMS);
|
|
732
745
|
}
|
|
733
746
|
else {
|
|
734
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
|
package/dist/gd-sprest.d.ts
CHANGED
|
@@ -7439,9 +7439,6 @@ declare module 'gd-sprest/utils/base' {
|
|
|
7439
7439
|
/** Flag to get all items. */
|
|
7440
7440
|
getAllItemsFl: boolean;
|
|
7441
7441
|
|
|
7442
|
-
/** Time in ms to wait inbetween requests when getting all items. */
|
|
7443
|
-
getAllItemsWaitTime: number;
|
|
7444
|
-
|
|
7445
7442
|
/** Flag determining if more items exist. */
|
|
7446
7443
|
nextFl: boolean;
|
|
7447
7444
|
|