gd-sprest 9.4.4 → 9.4.6
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/helper/methods/index.js +1 -0
- package/build/helper/methods/webWorker.js +36 -0
- package/build/lib/contextInfo.js +13 -12
- package/build/rest.js +1 -1
- package/build/utils/request.js +5 -4
- package/dist/gd-sprest.js +1 -1
- package/dist/gd-sprest.js.LICENSE.txt +4 -0
- package/dist/gd-sprest.min.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebWorker = void 0;
|
|
4
|
+
// Web Worker
|
|
5
|
+
var WebWorker = /** @class */ (function () {
|
|
6
|
+
// Constructor
|
|
7
|
+
function WebWorker(callback, interval) {
|
|
8
|
+
if (interval === void 0) { interval = 1000; }
|
|
9
|
+
var _this = this;
|
|
10
|
+
this._worker = null;
|
|
11
|
+
// Create the worker process
|
|
12
|
+
var blob = new Blob([WorkerCode(interval)], { type: "application/javascript" });
|
|
13
|
+
this._worker = new Worker(URL.createObjectURL(blob));
|
|
14
|
+
// Set the callback method
|
|
15
|
+
this._worker.onmessage = function () {
|
|
16
|
+
// Call the callback method
|
|
17
|
+
callback();
|
|
18
|
+
};
|
|
19
|
+
// Watch the unload event to stop the loop
|
|
20
|
+
window.addEventListener("beforeunload", function () {
|
|
21
|
+
// Stop the loop
|
|
22
|
+
_this.stop();
|
|
23
|
+
_this._worker.terminate();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// Starts the loop
|
|
27
|
+
WebWorker.prototype.start = function () { this._worker.postMessage("start"); };
|
|
28
|
+
// Stops the loop
|
|
29
|
+
WebWorker.prototype.stop = function () { this._worker.postMessage("stop"); };
|
|
30
|
+
return WebWorker;
|
|
31
|
+
}());
|
|
32
|
+
exports.WebWorker = WebWorker;
|
|
33
|
+
// The worker code
|
|
34
|
+
function WorkerCode(interval) {
|
|
35
|
+
return "\nlet interval = [Default Interval];\nlet loopId = null;\nself.onmessage = (e) => {\n // See if the input is a number\n if (typeof (e.data) === \"number\") {\n // Set the interval value\n interval = e.data;\n }\n\n // See if we are stopping the loop\n if (e.data == \"stop\") {\n // Stop the interval and loop id\n clearInterval(loopId);\n loopId = null;\n return;\n }\n\n // See if we are starting the loop\n if (e.data == \"start\") {\n // Ensure it's not already started\n if (loopId != null) { return; }\n\n // Start the loop\n loopId = setInterval(() => {\n // Trigger the callback\n self.postMessage(null);\n }, interval || 1000);\n }\n}".replace('[Default Interval]', interval.toString());
|
|
36
|
+
}
|
package/build/lib/contextInfo.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ContextInfo = void 0;
|
|
4
|
+
var webWorker_1 = require("../helper/methods/webWorker");
|
|
4
5
|
var utils_1 = require("../utils");
|
|
5
6
|
var graph_1 = require("./graph");
|
|
6
7
|
/**
|
|
@@ -751,12 +752,12 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
751
752
|
if (callback) {
|
|
752
753
|
this._onRefresh.push(callback);
|
|
753
754
|
}
|
|
754
|
-
//
|
|
755
|
+
// Ensure the request digest exists
|
|
755
756
|
if (this.formDigestValue == null) {
|
|
756
757
|
return;
|
|
757
758
|
}
|
|
758
|
-
// See if we already have a
|
|
759
|
-
if (this.
|
|
759
|
+
// See if we already have a worker process
|
|
760
|
+
if (this._worker) {
|
|
760
761
|
return;
|
|
761
762
|
}
|
|
762
763
|
// Refresh method for REST
|
|
@@ -779,9 +780,8 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
779
780
|
}, function () {
|
|
780
781
|
// Log
|
|
781
782
|
console.info("[gd-sprest] Unable to get the context information to refresh the token.");
|
|
782
|
-
// Stop the
|
|
783
|
-
|
|
784
|
-
_this._loopId = null;
|
|
783
|
+
// Stop the process
|
|
784
|
+
_this._worker.stop();
|
|
785
785
|
});
|
|
786
786
|
};
|
|
787
787
|
// Refresh method for Graph
|
|
@@ -805,18 +805,19 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
805
805
|
}, function () {
|
|
806
806
|
// Log
|
|
807
807
|
console.info("[gd-sprest] Unable to refresh the graph token.");
|
|
808
|
-
// Stop the
|
|
809
|
-
|
|
810
|
-
_this._loopId = null;
|
|
808
|
+
// Stop the process
|
|
809
|
+
_this._worker.stop();
|
|
811
810
|
});
|
|
812
811
|
};
|
|
813
|
-
// Create
|
|
814
|
-
this.
|
|
812
|
+
// Create the process
|
|
813
|
+
this._worker = new webWorker_1.WebWorker(function () {
|
|
815
814
|
// Refresh the REST API token
|
|
816
815
|
refreshREST();
|
|
817
816
|
// Refresh the Graph API token
|
|
818
817
|
refreshGraph();
|
|
819
818
|
}, 1000);
|
|
819
|
+
// Start the process
|
|
820
|
+
this._worker.start();
|
|
820
821
|
};
|
|
821
822
|
Object.defineProperty(_ContextInfo, "refreshToken", {
|
|
822
823
|
get: function () { return this._refreshToken; },
|
|
@@ -849,7 +850,7 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
849
850
|
// Enable the refresh token
|
|
850
851
|
_a.enableRefreshToken();
|
|
851
852
|
};
|
|
852
|
-
_ContextInfo.
|
|
853
|
+
_ContextInfo._worker = null;
|
|
853
854
|
_ContextInfo._onRefresh = [];
|
|
854
855
|
// Value in minutes to refresh the token
|
|
855
856
|
// Default is 5 minutes prior to it expiring
|
package/build/rest.js
CHANGED
package/build/utils/request.js
CHANGED
|
@@ -507,6 +507,7 @@ exports.Request = {
|
|
|
507
507
|
},
|
|
508
508
|
// Method to convert the input arguments into an object
|
|
509
509
|
updateDataObject: function (base, isBatchRequest, batchIdx) {
|
|
510
|
+
var _a;
|
|
510
511
|
if (isBatchRequest === void 0) { isBatchRequest = false; }
|
|
511
512
|
if (batchIdx === void 0) { batchIdx = 0; }
|
|
512
513
|
// Ensure the request was successful
|
|
@@ -580,10 +581,10 @@ exports.Request = {
|
|
|
580
581
|
// Else, see if the data properties exists
|
|
581
582
|
else if (data.d) {
|
|
582
583
|
// Get the endpoint method to see if it's part of the response
|
|
583
|
-
var endpointInfo = base.targetInfo.endpoint.split('/');
|
|
584
|
-
var endpointMethod = endpointInfo[endpointInfo.length - 1] || "";
|
|
585
|
-
endpointMethod = endpointMethod[0].toUpperCase() + endpointMethod.substring(1);
|
|
586
|
-
if (data.d[endpointMethod]) {
|
|
584
|
+
var endpointInfo = ((_a = base.targetInfo.endpoint) === null || _a === void 0 ? void 0 : _a.split('/')) || "";
|
|
585
|
+
var endpointMethod = endpointInfo ? endpointInfo[endpointInfo.length - 1] || "" : "";
|
|
586
|
+
endpointMethod = endpointMethod ? endpointMethod[0].toUpperCase() + endpointMethod.substring(1) : "";
|
|
587
|
+
if (endpointMethod && data.d[endpointMethod]) {
|
|
587
588
|
// Update the response to be that object
|
|
588
589
|
data.d = data.d[endpointMethod];
|
|
589
590
|
}
|