gd-sprest 9.5.1 → 9.5.2

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
@@ -9,7 +9,7 @@ var sptypes_1 = require("./sptypes");
9
9
  * SharePoint REST Library
10
10
  */
11
11
  exports.$REST = {
12
- __ver: 9.51,
12
+ __ver: 9.52,
13
13
  AppContext: function (siteUrl) { return Lib.Site.getAppContext(siteUrl); },
14
14
  Apps: Lib.Apps,
15
15
  ContextInfo: Lib.ContextInfo,
@@ -1,7 +1,6 @@
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");
5
4
  var lib_1 = require("../lib");
6
5
  /**
7
6
  * XML HTTP Request Class
@@ -236,68 +235,69 @@ var XHRRequest = /** @class */ (function () {
236
235
  // Method to execute the xml http request
237
236
  XHRRequest.prototype.executeRequest = function (requestDigest) {
238
237
  var _this = 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
- };
238
+ // Ensure the xml http request exists
239
+ if (this.xhr == null) {
240
+ return null;
241
+ }
242
+ // Open the request
243
+ if (this.isGraph) {
244
+ this.xhr.open(this.targetInfo.requestMethod, this.targetInfo.requestUrl, this.asyncFl);
245
+ }
246
+ else {
247
+ this.xhr.open(this.targetInfo.requestMethod == "GET" ? "GET" : "POST", this.targetInfo.requestUrl, this.asyncFl);
248
+ }
249
+ // See if we are making an asynchronous request
250
+ if (this.asyncFl) {
251
+ // Set the state change event
252
+ this.xhr.onreadystatechange = function () {
253
+ // See if the request has finished
254
+ if (_this.xhr.readyState == 4) {
255
+ // Execute the request completed event
256
+ _this.onRequestCompleted ? _this.onRequestCompleted(_this) : null;
257
+ }
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);
264
273
  }
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";
274
+ }
275
+ // See if we are executing the request
276
+ if (this.executeFl) {
277
+ // See if we are using keep alive
278
+ if (this.targetInfo.props.keepalive && this.asyncFl) {
279
+ // Create a fetch request
280
+ fetch(this.targetInfo.requestUrl, {
281
+ body: this.targetInfo.requestData,
282
+ headers: this.headers,
283
+ keepalive: true,
284
+ method: this.isGraph ? this.targetInfo.requestMethod : (this.targetInfo.requestMethod == "GET" ? "GET" : "POST")
285
+ }).then(function (response) {
286
+ // Set the xhr object
287
+ _this.xhr = response;
288
+ // Return the response
289
+ return (_this.targetInfo.props.bufferFl ? response.arrayBuffer() : response.text());
290
+ }).then(function (response) {
291
+ // Set the xhr response
292
+ _this.xhr.response = response;
293
+ // Execute the request completed event
294
+ _this.onRequestCompleted ? _this.onRequestCompleted(_this) : null;
295
+ });
270
296
  }
271
297
  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);
278
- }
279
- }
280
- // See if we are executing the request
281
- if (_this.executeFl) {
282
298
  // Execute the request
283
- _this.targetInfo.props.bufferFl || _this.targetInfo.requestData == null ? _this.xhr.send() : _this.xhr.send(_this.targetInfo.requestData);
299
+ this.targetInfo.props.bufferFl || this.targetInfo.requestData == null ? this.xhr.send() : this.xhr.send(this.targetInfo.requestData);
284
300
  }
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();
297
- }
298
- else {
299
- // Execute the request
300
- sendRequest();
301
301
  }
302
302
  };
303
303
  return XHRRequest;