gd-sprest 9.4.9 → 9.5.1
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/targetInfo.d.ts +3 -0
- package/build/lib/contextInfo.js +21 -0
- package/build/lib/graph.js +0 -2
- package/build/rest.js +1 -1
- package/build/utils/request.js +0 -1
- package/build/utils/xhrRequest.js +61 -39
- package/dist/gd-sprest.d.ts +3 -0
- package/dist/gd-sprest.js +1 -1
- package/dist/gd-sprest.min.js +1 -1
- package/package.json +1 -1
package/build/lib/contextInfo.js
CHANGED
|
@@ -748,6 +748,7 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
748
748
|
};
|
|
749
749
|
_ContextInfo.enableRefreshToken = function (callback) {
|
|
750
750
|
var _this = this;
|
|
751
|
+
var isRunning = false;
|
|
751
752
|
// Set the refresh event
|
|
752
753
|
if (callback) {
|
|
753
754
|
this._onRefresh.push(callback);
|
|
@@ -762,12 +763,18 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
762
763
|
}
|
|
763
764
|
// Refresh method for REST
|
|
764
765
|
var refreshREST = function () {
|
|
766
|
+
// Do nothing if it's currently running
|
|
767
|
+
if (isRunning) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
765
770
|
// See if the digest is valid
|
|
766
771
|
if (_this.validateToken()) {
|
|
767
772
|
return;
|
|
768
773
|
}
|
|
769
774
|
// Log
|
|
770
775
|
console.info("[gd-sprest] Token has expired. Trying to refresh the token.");
|
|
776
|
+
// Set the flag
|
|
777
|
+
isRunning = true;
|
|
771
778
|
// Get the context
|
|
772
779
|
_this.getWeb().execute(function (context) {
|
|
773
780
|
// Log
|
|
@@ -777,15 +784,23 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
777
784
|
_this._contextInfo.formDigestValue = context.GetContextWebInformation.FormDigestValue;
|
|
778
785
|
// Call the events
|
|
779
786
|
_this._onRefresh.forEach(function (callback) { callback(); });
|
|
787
|
+
// Set the flag
|
|
788
|
+
isRunning = false;
|
|
780
789
|
}, function () {
|
|
781
790
|
// Log
|
|
782
791
|
console.info("[gd-sprest] Unable to get the context information to refresh the token.");
|
|
783
792
|
// Stop the process
|
|
784
793
|
_this._worker.stop();
|
|
794
|
+
// Set the flag
|
|
795
|
+
isRunning = false;
|
|
785
796
|
});
|
|
786
797
|
};
|
|
787
798
|
// Refresh method for Graph
|
|
788
799
|
var refreshGraph = function () {
|
|
800
|
+
// Do nothing if it's currently running
|
|
801
|
+
if (isRunning) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
789
804
|
// Ensure we have a token
|
|
790
805
|
if (graph_1.Graph.TokenExpiration) {
|
|
791
806
|
// See if the digest is valid
|
|
@@ -795,6 +810,8 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
795
810
|
}
|
|
796
811
|
// Log
|
|
797
812
|
console.info("[gd-sprest] Graph Token has expired. Trying to refresh the token.");
|
|
813
|
+
// Set the flag
|
|
814
|
+
isRunning = true;
|
|
798
815
|
// Get the cloud access token
|
|
799
816
|
graph_1.Graph.getAccessToken(graph_1.Graph.Cloud, "SPO").execute(function (auth) {
|
|
800
817
|
// Log
|
|
@@ -802,11 +819,15 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
802
819
|
// Set the access token and expiration
|
|
803
820
|
graph_1.Graph.Token = auth.access_token;
|
|
804
821
|
graph_1.Graph.TokenExpiration = parseInt(auth.expires_on) * 1000;
|
|
822
|
+
// Set the flag
|
|
823
|
+
isRunning = false;
|
|
805
824
|
}, function () {
|
|
806
825
|
// Log
|
|
807
826
|
console.info("[gd-sprest] Unable to refresh the graph token.");
|
|
808
827
|
// Stop the process
|
|
809
828
|
_this._worker.stop();
|
|
829
|
+
// Set the flag
|
|
830
|
+
isRunning = false;
|
|
810
831
|
});
|
|
811
832
|
};
|
|
812
833
|
// Create the process
|
package/build/lib/graph.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Graph = void 0;
|
|
4
4
|
var sptypes_1 = require("../sptypes");
|
|
5
5
|
var utils_1 = require("../utils");
|
|
6
|
-
var contextInfo_1 = require("./contextInfo");
|
|
7
6
|
// Default Token
|
|
8
7
|
//export const Token
|
|
9
8
|
/**
|
|
@@ -46,7 +45,6 @@ exports.Graph.getAccessToken = function (resource, tokenType) {
|
|
|
46
45
|
return new utils_1.Base({
|
|
47
46
|
endpoint: "SP.OAuth.Token/Acquire",
|
|
48
47
|
method: "POST",
|
|
49
|
-
requestDigest: contextInfo_1.ContextInfo.formDigestValue,
|
|
50
48
|
data: data
|
|
51
49
|
});
|
|
52
50
|
};
|
package/build/rest.js
CHANGED
package/build/utils/request.js
CHANGED
|
@@ -59,7 +59,6 @@ exports.Request = {
|
|
|
59
59
|
}
|
|
60
60
|
// Get the methods for this object type
|
|
61
61
|
methods = mapper_1.MapperV2[objType];
|
|
62
|
-
console.log("[gd-sprest] v2 response detected. Type is: " + objType, methods);
|
|
63
62
|
}
|
|
64
63
|
// Else, get the methods from the default mapper, otherwise get it from the custom mapper
|
|
65
64
|
else if ((methods = mapper_1.Mapper[objType + (isCollection ? ".Collection" : "")]) == null) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.XHRRequest = void 0;
|
|
4
|
+
var webWorker_1 = require("../helper/methods/webWorker");
|
|
4
5
|
var lib_1 = require("../lib");
|
|
5
6
|
/**
|
|
6
7
|
* XML HTTP Request Class
|
|
@@ -203,9 +204,9 @@ var XHRRequest = /** @class */ (function () {
|
|
|
203
204
|
// Set the request digest
|
|
204
205
|
var requestDigest = this.targetInfo.props.requestDigest || "";
|
|
205
206
|
if (requestDigest == "") {
|
|
206
|
-
//
|
|
207
|
-
requestDigest = lib_1.ContextInfo.document ? lib_1.ContextInfo.document.querySelector("#__REQUESTDIGEST") : "";
|
|
207
|
+
// Set the request digest
|
|
208
208
|
requestDigest = requestDigest ? requestDigest.value : lib_1.ContextInfo.formDigestValue;
|
|
209
|
+
requestDigest = requestDigest ? requestDigest : (lib_1.ContextInfo.document ? lib_1.ContextInfo.document.querySelector("#__REQUESTDIGEST") : "");
|
|
209
210
|
}
|
|
210
211
|
// See if we are targeting the context endpoint
|
|
211
212
|
if (this.targetInfo.props.endpoint == "contextinfo") {
|
|
@@ -235,47 +236,68 @@ var XHRRequest = /** @class */ (function () {
|
|
|
235
236
|
// Method to execute the xml http request
|
|
236
237
|
XHRRequest.prototype.executeRequest = function (requestDigest) {
|
|
237
238
|
var _this = this;
|
|
238
|
-
//
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
//
|
|
254
|
-
|
|
255
|
-
//
|
|
256
|
-
_this.
|
|
239
|
+
// Executes the request
|
|
240
|
+
var sendRequest = function (onComplete) {
|
|
241
|
+
// Ensure the xml http request exists
|
|
242
|
+
if (_this.xhr == null) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
// Open the request
|
|
246
|
+
if (_this.isGraph) {
|
|
247
|
+
_this.xhr.open(_this.targetInfo.requestMethod, _this.targetInfo.requestUrl, _this.asyncFl);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
_this.xhr.open(_this.targetInfo.requestMethod == "GET" ? "GET" : "POST", _this.targetInfo.requestUrl, _this.asyncFl);
|
|
251
|
+
}
|
|
252
|
+
// See if we are making an asynchronous request
|
|
253
|
+
if (_this.asyncFl) {
|
|
254
|
+
// Set the state change event
|
|
255
|
+
_this.xhr.onreadystatechange = function () {
|
|
256
|
+
// See if the request has finished
|
|
257
|
+
if (_this.xhr.readyState == 4) {
|
|
258
|
+
// Execute the request completed event
|
|
259
|
+
_this.onRequestCompleted ? _this.onRequestCompleted(_this) : null;
|
|
260
|
+
// Execute the event
|
|
261
|
+
onComplete ? onComplete() : null;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
// See if we the response type is an array buffer
|
|
266
|
+
// Note - Updating the response type is only allow for asynchronous requests. Any error will be thrown otherwise.
|
|
267
|
+
if (_this.targetInfo.props.bufferFl && _this.asyncFl) {
|
|
268
|
+
// Set the response type
|
|
269
|
+
_this.xhr.responseType = "arraybuffer";
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
// Default the headers
|
|
273
|
+
_this.defaultHeaders(requestDigest);
|
|
274
|
+
// Ensure the arguments passed is defaulted as a string, unless it's an array buffer
|
|
275
|
+
if (_this.targetInfo.requestData && typeof (_this.targetInfo.requestData) !== "string") {
|
|
276
|
+
// Stringify the data object, if it's not an array buffer
|
|
277
|
+
_this.targetInfo.requestData = _this.targetInfo.requestData.byteLength ? _this.targetInfo.requestData : JSON.stringify(_this.targetInfo.requestData);
|
|
257
278
|
}
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
// See if we the response type is an array buffer
|
|
261
|
-
// Note - Updating the response type is only allow for asynchronous requests. Any error will be thrown otherwise.
|
|
262
|
-
if (this.targetInfo.props.bufferFl && this.asyncFl) {
|
|
263
|
-
// Set the response type
|
|
264
|
-
this.xhr.responseType = "arraybuffer";
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
// Default the headers
|
|
268
|
-
this.defaultHeaders(requestDigest);
|
|
269
|
-
// Ensure the arguments passed is defaulted as a string, unless it's an array buffer
|
|
270
|
-
if (this.targetInfo.requestData && typeof (this.targetInfo.requestData) !== "string") {
|
|
271
|
-
// Stringify the data object, if it's not an array buffer
|
|
272
|
-
this.targetInfo.requestData = this.targetInfo.requestData.byteLength ? this.targetInfo.requestData : JSON.stringify(this.targetInfo.requestData);
|
|
273
279
|
}
|
|
280
|
+
// See if we are executing the request
|
|
281
|
+
if (_this.executeFl) {
|
|
282
|
+
// Execute the request
|
|
283
|
+
_this.targetInfo.props.bufferFl || _this.targetInfo.requestData == null ? _this.xhr.send() : _this.xhr.send(_this.targetInfo.requestData);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
// See if this is an async request
|
|
287
|
+
if (this.asyncFl) {
|
|
288
|
+
// Execute the request within a worker process
|
|
289
|
+
var worker_1 = (0, webWorker_1.WebWorker)(function () {
|
|
290
|
+
// Stop the process so we don't send multiple
|
|
291
|
+
worker_1.stop();
|
|
292
|
+
// Execute the request
|
|
293
|
+
sendRequest();
|
|
294
|
+
}, 10);
|
|
295
|
+
// Start the process
|
|
296
|
+
worker_1.start();
|
|
274
297
|
}
|
|
275
|
-
|
|
276
|
-
if (this.executeFl) {
|
|
298
|
+
else {
|
|
277
299
|
// Execute the request
|
|
278
|
-
|
|
300
|
+
sendRequest();
|
|
279
301
|
}
|
|
280
302
|
};
|
|
281
303
|
return XHRRequest;
|
package/dist/gd-sprest.d.ts
CHANGED
|
@@ -7672,6 +7672,9 @@ declare module 'gd-sprest/utils/targetInfo' {
|
|
|
7672
7672
|
/** The endpoint of the request. */
|
|
7673
7673
|
endpoint?: string;
|
|
7674
7674
|
|
|
7675
|
+
/** Uses a fetch instead of xml http request. */
|
|
7676
|
+
keepalive?: boolean;
|
|
7677
|
+
|
|
7675
7678
|
/** The method to execute. */
|
|
7676
7679
|
method?: string;
|
|
7677
7680
|
|