gd-sprest 9.3.8 → 9.3.9

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.38,
12
+ __ver: 9.39,
13
13
  AppContext: function (siteUrl) { return Lib.Site.getAppContext(siteUrl); },
14
14
  Apps: Lib.Apps,
15
15
  ContextInfo: Lib.ContextInfo,
@@ -71,23 +71,23 @@ var Batch = /** @class */ (function () {
71
71
  // See if this is v2
72
72
  if (isV2) {
73
73
  // Create the batch requests
74
- batchRequests = Batch.createBatchV2(requests);
74
+ batchRequests.push(Batch.createBatchV2(batchId, requests));
75
75
  }
76
76
  else {
77
77
  // Create the batch requests
78
78
  batchRequests.push(Batch.createBatch(batchId, requests));
79
- // End the batch request
80
- batchRequests.push("--" + batchId + "--");
81
79
  }
80
+ // End the batch request
81
+ batchRequests.push("--" + batchId + "--");
82
82
  // Return the target information
83
83
  return new _1.TargetInfo({
84
84
  url: url,
85
85
  endpoint: (isV2 ? "_api/v2.0/" : "") + "$batch",
86
86
  method: "POST",
87
- data: isV2 ? { requests: batchRequests } : batchRequests.join("\r\n"),
87
+ data: batchRequests.join("\r\n"),
88
88
  requestDigest: requestDigest,
89
89
  requestHeader: {
90
- "Content-Type": isV2 ? "application/json" : 'multipart/mixed; boundary="' + batchId + '"'
90
+ "Content-Type": 'multipart/mixed; boundary="' + batchId + '"'
91
91
  }
92
92
  });
93
93
  };
@@ -145,29 +145,49 @@ var Batch = /** @class */ (function () {
145
145
  return request.join("\r\n");
146
146
  };
147
147
  // Method to generate a batch request
148
- Batch.createBatchV2 = function (requests) {
148
+ Batch.createBatchV2 = function (batchId, requests) {
149
149
  var batch = [];
150
150
  // Parse the requests
151
151
  for (var i = 0; i < requests.length; i++) {
152
152
  var request = requests[i];
153
153
  // Create the batch request
154
- var batchRequest = {
155
- id: (i + 1).toString(),
156
- method: request.targetInfo.requestMethod,
157
- url: request.targetInfo.requestUrl
158
- };
159
- // See if a body is set
160
- if (request.targetInfo.requestData) {
161
- batchRequest.body = request.targetInfo.requestData;
162
- batchRequest.headers = {
163
- "Content-Type": "application/json"
164
- };
154
+ batch.push("--" + batchId);
155
+ // Determine if the batch requires a change set
156
+ var requiresChangeset = request && request.targetInfo.requestMethod != "GET";
157
+ if (requiresChangeset) {
158
+ // Create a change set
159
+ batch.push("Content-Type: multipart/mixed; boundary=" + request.changesetId);
160
+ batch.push("");
161
+ batch.push("--" + request.changesetId);
162
+ batch.push("Content-Type: application/http");
163
+ batch.push("Content-Transfer-Encoding: binary");
164
+ batch.push("");
165
+ batch.push(request.targetInfo.requestMethod + " " + request.targetInfo.requestUrl + " HTTP/1.1");
166
+ batch.push("Content-Type: application/json;odata=verbose");
167
+ // See if we are making a delete/update
168
+ if (request.targetInfo.requestMethod == "DELETE" || request.targetInfo.requestMethod == "MERGE") {
169
+ // Append the header for deleting/updating
170
+ batch.push("IF-MATCH: *");
171
+ }
172
+ batch.push("");
173
+ request.targetInfo.requestData ? batch.push(request.targetInfo.requestData) : null;
174
+ batch.push("");
175
+ batch.push("--" + request.changesetId + "--");
176
+ }
177
+ else {
178
+ // Create a change set
179
+ batch.push("Content-Type: application/http");
180
+ batch.push("Content-Transfer-Encoding: binary");
181
+ batch.push("");
182
+ batch.push("GET " + request.targetInfo.requestUrl + " HTTP/1.1");
183
+ batch.push("Accept: application/json");
184
+ batch.push("");
185
+ request.targetInfo.requestData ? batch.push(request.targetInfo.requestData) : null;
186
+ batch.push("");
165
187
  }
166
- // Add the batch request
167
- batch.push(batchRequest);
168
188
  }
169
- // Return the batch requests
170
- return batch;
189
+ // Return the batch request
190
+ return batch.join("\r\n");
171
191
  };
172
192
  // Process the batch request callbacks
173
193
  Batch.processCallbacks = function (batchRequests) {