@lindle/sharepoint_requests 0.1.17 → 0.1.19
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/README.md +121 -116
- package/dist/index.d.ts +2 -2
- package/dist/root/index.d.ts +106 -31
- package/dist/root/internal/context.d.ts +2 -2
- package/dist/root/internal/digest.d.ts +1 -1
- package/dist/root/internal/emailRequests.d.ts +3 -3
- package/dist/root/internal/listRequests/createAttachment.d.ts +2 -2
- package/dist/root/internal/listRequests/createListItem.d.ts +3 -3
- package/dist/root/internal/listRequests/deleteFile.d.ts +2 -2
- package/dist/root/internal/listRequests/deleteItem.d.ts +2 -2
- package/dist/root/internal/listRequests/getFiles.d.ts +2 -2
- package/dist/root/internal/listRequests/getListItems.d.ts +3 -3
- package/dist/root/internal/listRequests/getOnly.d.ts +2 -2
- package/dist/root/internal/listRequests/normalizePayload.d.ts +4 -0
- package/dist/root/internal/listRequests/updateListItem.d.ts +3 -3
- package/dist/root/internal/listRequests/uploadFile.d.ts +3 -3
- package/dist/root/internal/odata.d.ts +1 -1
- package/dist/root/internal/sharepointUrl.d.ts +2 -0
- package/dist/root/internal/userRequests.d.ts +3 -3
- package/dist/sharepoint_requests.cjs.development.js +572 -229
- package/dist/sharepoint_requests.cjs.development.js.map +1 -1
- package/dist/sharepoint_requests.cjs.production.min.js +1 -1
- package/dist/sharepoint_requests.cjs.production.min.js.map +1 -1
- package/dist/sharepoint_requests.esm.js +572 -229
- package/dist/sharepoint_requests.esm.js.map +1 -1
- package/dist/types.d.ts +30 -11
- package/package.json +1 -1
- package/src/index.ts +3 -5
- package/src/root/index.ts +263 -144
- package/src/root/internal/context.ts +2 -2
- package/src/root/internal/digest.ts +4 -3
- package/src/root/internal/emailRequests.ts +4 -7
- package/src/root/internal/listRequests/createAttachment.ts +14 -3
- package/src/root/internal/listRequests/createListItem.ts +24 -13
- package/src/root/internal/listRequests/deleteFile.ts +4 -3
- package/src/root/internal/listRequests/deleteItem.ts +17 -3
- package/src/root/internal/listRequests/getFiles.ts +4 -10
- package/src/root/internal/listRequests/getListItems.ts +16 -9
- package/src/root/internal/listRequests/getOnly.ts +10 -7
- package/src/root/internal/listRequests/normalizePayload.ts +165 -0
- package/src/root/internal/listRequests/updateListItem.ts +31 -13
- package/src/root/internal/listRequests/uploadFile.ts +5 -8
- package/src/root/internal/listRequests/utils.ts +1 -1
- package/src/root/internal/odata.ts +2 -4
- package/src/root/internal/sharepointUrl.ts +7 -0
- package/src/root/internal/userRequests.ts +43 -11
- package/src/types.ts +138 -105
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import axios, { AxiosHeaders } from 'axios';
|
|
2
2
|
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
3
8
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
4
9
|
try {
|
|
5
10
|
var i = n[a](c),
|
|
@@ -25,6 +30,23 @@ function _asyncToGenerator(n) {
|
|
|
25
30
|
});
|
|
26
31
|
};
|
|
27
32
|
}
|
|
33
|
+
function _createForOfIteratorHelperLoose(r, e) {
|
|
34
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
35
|
+
if (t) return (t = t.call(r)).next.bind(t);
|
|
36
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
37
|
+
t && (r = t);
|
|
38
|
+
var o = 0;
|
|
39
|
+
return function () {
|
|
40
|
+
return o >= r.length ? {
|
|
41
|
+
done: !0
|
|
42
|
+
} : {
|
|
43
|
+
done: !1,
|
|
44
|
+
value: r[o++]
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
49
|
+
}
|
|
28
50
|
function _extends() {
|
|
29
51
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
30
52
|
for (var e = 1; e < arguments.length; e++) {
|
|
@@ -142,6 +164,13 @@ function _regeneratorDefine(e, r, n, t) {
|
|
|
142
164
|
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
143
165
|
}, _regeneratorDefine(e, r, n, t);
|
|
144
166
|
}
|
|
167
|
+
function _unsupportedIterableToArray(r, a) {
|
|
168
|
+
if (r) {
|
|
169
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
170
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
171
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
145
174
|
|
|
146
175
|
var defaultConfig = {
|
|
147
176
|
headers: {
|
|
@@ -165,7 +194,7 @@ function fetchDigest(_x, _x2) {
|
|
|
165
194
|
}
|
|
166
195
|
function _fetchDigest() {
|
|
167
196
|
_fetchDigest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, baseURL) {
|
|
168
|
-
var _response$data, response, formDigestValue, _t;
|
|
197
|
+
var _response$data, response, formDigestValue, cause, _t;
|
|
169
198
|
return _regenerator().w(function (_context) {
|
|
170
199
|
while (1) switch (_context.p = _context.n) {
|
|
171
200
|
case 0:
|
|
@@ -185,8 +214,8 @@ function _fetchDigest() {
|
|
|
185
214
|
case 3:
|
|
186
215
|
_context.p = 3;
|
|
187
216
|
_t = _context.v;
|
|
188
|
-
|
|
189
|
-
throw new Error("Error retrieving Form Digest Value");
|
|
217
|
+
cause = _t instanceof Error ? _t.message : 'Unknown contextinfo error';
|
|
218
|
+
throw new Error("Error retrieving Form Digest Value: " + cause);
|
|
190
219
|
case 4:
|
|
191
220
|
return _context.a(2);
|
|
192
221
|
}
|
|
@@ -195,6 +224,195 @@ function _fetchDigest() {
|
|
|
195
224
|
return _fetchDigest.apply(this, arguments);
|
|
196
225
|
}
|
|
197
226
|
|
|
227
|
+
function sendEmail(_x, _x2) {
|
|
228
|
+
return _sendEmail.apply(this, arguments);
|
|
229
|
+
}
|
|
230
|
+
function _sendEmail() {
|
|
231
|
+
_sendEmail = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
|
|
232
|
+
var From, To, Subject, Body, httpRequest, response, _t, _t2, _t3, _t4, _t5;
|
|
233
|
+
return _regenerator().w(function (_context) {
|
|
234
|
+
while (1) switch (_context.n) {
|
|
235
|
+
case 0:
|
|
236
|
+
From = _ref.From, To = _ref.To, Subject = _ref.Subject, Body = _ref.Body;
|
|
237
|
+
httpRequest = '_api/SP.Utilities.Utility.SendEmail';
|
|
238
|
+
_t = context;
|
|
239
|
+
_t2 = httpRequest;
|
|
240
|
+
_context.n = 1;
|
|
241
|
+
return fetchDigest(context.instance, context.baseURL);
|
|
242
|
+
case 1:
|
|
243
|
+
_t3 = _context.v;
|
|
244
|
+
_t4 = {
|
|
245
|
+
'X-RequestDigest': _t3,
|
|
246
|
+
'X-Http-Method': 'POST',
|
|
247
|
+
'Content-Type': 'application/json;odata=verbose'
|
|
248
|
+
};
|
|
249
|
+
_t5 = JSON.stringify({
|
|
250
|
+
properties: {
|
|
251
|
+
__metadata: {
|
|
252
|
+
type: 'SP.Utilities.EmailProperties'
|
|
253
|
+
},
|
|
254
|
+
From: From,
|
|
255
|
+
To: {
|
|
256
|
+
results: Array.isArray(To) ? To : [To]
|
|
257
|
+
},
|
|
258
|
+
Body: Body,
|
|
259
|
+
Subject: Subject
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
_context.n = 2;
|
|
263
|
+
return _t.instance.call(_t, {
|
|
264
|
+
url: _t2,
|
|
265
|
+
method: 'POST',
|
|
266
|
+
headers: _t4,
|
|
267
|
+
data: _t5
|
|
268
|
+
});
|
|
269
|
+
case 2:
|
|
270
|
+
response = _context.v;
|
|
271
|
+
return _context.a(2, response);
|
|
272
|
+
}
|
|
273
|
+
}, _callee);
|
|
274
|
+
}));
|
|
275
|
+
return _sendEmail.apply(this, arguments);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
var LOOKUP_ID_KEYS = ['lookupId', 'LookupId', 'lookupID', 'LookupID', 'Id', 'ID'];
|
|
279
|
+
function isPlainObject(value) {
|
|
280
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
281
|
+
}
|
|
282
|
+
function extractLookupPrimitive(value, allowGenericId) {
|
|
283
|
+
for (var _iterator = _createForOfIteratorHelperLoose(LOOKUP_ID_KEYS), _step; !(_step = _iterator()).done;) {
|
|
284
|
+
var key = _step.value;
|
|
285
|
+
if (!allowGenericId && (key === 'Id' || key === 'ID')) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (value[key] !== undefined && value[key] !== null) {
|
|
289
|
+
return value[key];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
function normalizeLookupValue(value) {
|
|
295
|
+
if (Array.isArray(value)) {
|
|
296
|
+
return {
|
|
297
|
+
results: value
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
if (isPlainObject(value)) {
|
|
301
|
+
if (Array.isArray(value.results)) {
|
|
302
|
+
return {
|
|
303
|
+
results: value.results
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
var primitive = extractLookupPrimitive(value, true);
|
|
307
|
+
if (primitive !== undefined) {
|
|
308
|
+
return primitive;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (typeof value === 'string') {
|
|
312
|
+
var trimmed = value.trim();
|
|
313
|
+
if (!trimmed) {
|
|
314
|
+
return value;
|
|
315
|
+
}
|
|
316
|
+
var numeric = Number(trimmed);
|
|
317
|
+
return Number.isNaN(numeric) ? trimmed : numeric;
|
|
318
|
+
}
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
function resolveLookupField(key, value) {
|
|
322
|
+
var lower = key.toLowerCase();
|
|
323
|
+
var endsWithId = lower.endsWith('id');
|
|
324
|
+
var endsWithRef = lower.endsWith('ref');
|
|
325
|
+
var endsWithLookup = lower.endsWith('lookup');
|
|
326
|
+
var hasLookupHint = endsWithId || endsWithRef || endsWithLookup;
|
|
327
|
+
if (value === undefined) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
if (Array.isArray(value)) {
|
|
331
|
+
var _targetKey = endsWithId ? key : key + "Id";
|
|
332
|
+
return {
|
|
333
|
+
key: _targetKey,
|
|
334
|
+
value: {
|
|
335
|
+
results: value
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (isPlainObject(value)) {
|
|
340
|
+
var primitive = extractLookupPrimitive(value, hasLookupHint);
|
|
341
|
+
if (primitive !== undefined) {
|
|
342
|
+
var _targetKey2 = endsWithId ? key : key + "Id";
|
|
343
|
+
return {
|
|
344
|
+
key: _targetKey2,
|
|
345
|
+
value: normalizeLookupValue(primitive)
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (Array.isArray(value.results)) {
|
|
349
|
+
var _targetKey3 = endsWithId ? key : key + "Id";
|
|
350
|
+
return {
|
|
351
|
+
key: _targetKey3,
|
|
352
|
+
value: {
|
|
353
|
+
results: value.results
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
if (!hasLookupHint) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
} else if (!hasLookupHint) {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
var targetKey = endsWithId ? key : key + "Id";
|
|
364
|
+
if (value === null) {
|
|
365
|
+
return {
|
|
366
|
+
key: targetKey,
|
|
367
|
+
value: null
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
if (typeof value === 'number') {
|
|
371
|
+
return {
|
|
372
|
+
key: targetKey,
|
|
373
|
+
value: value
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (typeof value === 'string') {
|
|
377
|
+
var trimmed = value.trim();
|
|
378
|
+
if (!trimmed) {
|
|
379
|
+
return {
|
|
380
|
+
key: targetKey,
|
|
381
|
+
value: ''
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
var numeric = Number(trimmed);
|
|
385
|
+
return {
|
|
386
|
+
key: targetKey,
|
|
387
|
+
value: Number.isNaN(numeric) ? trimmed : numeric
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
function normalizeListPayload(data) {
|
|
393
|
+
var result = {};
|
|
394
|
+
if (!data) {
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
for (var _i = 0, _Object$entries = Object.entries(data); _i < _Object$entries.length; _i++) {
|
|
398
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
399
|
+
key = _Object$entries$_i[0],
|
|
400
|
+
value = _Object$entries$_i[1];
|
|
401
|
+
if (key === '__metadata') {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
var lookupField = resolveLookupField(key, value);
|
|
405
|
+
if (lookupField) {
|
|
406
|
+
result[lookupField.key] = lookupField.value;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (value !== undefined) {
|
|
410
|
+
result[key] = value;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
|
|
198
416
|
function resolveMetadataType(_x) {
|
|
199
417
|
return _resolveMetadataType.apply(this, arguments);
|
|
200
418
|
}
|
|
@@ -226,37 +444,45 @@ function createListItem(_x2, _x3) {
|
|
|
226
444
|
}
|
|
227
445
|
function _createListItem() {
|
|
228
446
|
_createListItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(context, listData) {
|
|
229
|
-
var
|
|
447
|
+
var normalizedData, payload, metadataType, userMetadata, response, _t, _t2, _t3, _t4, _t5;
|
|
230
448
|
return _regenerator().w(function (_context2) {
|
|
231
449
|
while (1) switch (_context2.n) {
|
|
232
450
|
case 0:
|
|
451
|
+
normalizedData = normalizeListPayload(listData);
|
|
452
|
+
payload = normalizedData;
|
|
453
|
+
if (!(context.sharepointVersion === '2013')) {
|
|
454
|
+
_context2.n = 2;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
233
457
|
_context2.n = 1;
|
|
234
458
|
return resolveMetadataType(context);
|
|
235
459
|
case 1:
|
|
236
460
|
metadataType = _context2.v;
|
|
237
|
-
|
|
238
|
-
|
|
461
|
+
userMetadata = listData.__metadata;
|
|
462
|
+
payload = _extends({}, normalizedData, {
|
|
463
|
+
__metadata: _extends({}, userMetadata && typeof userMetadata === 'object' ? userMetadata : {}, {
|
|
239
464
|
type: metadataType
|
|
240
|
-
}
|
|
465
|
+
})
|
|
241
466
|
});
|
|
467
|
+
case 2:
|
|
242
468
|
_t = context;
|
|
243
469
|
_t2 = context.endpoint;
|
|
244
470
|
_t3 = JSON.stringify(payload);
|
|
245
|
-
_context2.n =
|
|
471
|
+
_context2.n = 3;
|
|
246
472
|
return fetchDigest(context.instance, context.baseURL);
|
|
247
|
-
case
|
|
473
|
+
case 3:
|
|
248
474
|
_t4 = _context2.v;
|
|
249
475
|
_t5 = {
|
|
250
476
|
'X-RequestDigest': _t4
|
|
251
477
|
};
|
|
252
|
-
_context2.n =
|
|
478
|
+
_context2.n = 4;
|
|
253
479
|
return _t.instance.call(_t, {
|
|
254
480
|
url: _t2,
|
|
255
481
|
method: 'POST',
|
|
256
482
|
data: _t3,
|
|
257
483
|
headers: _t5
|
|
258
484
|
});
|
|
259
|
-
case
|
|
485
|
+
case 4:
|
|
260
486
|
response = _context2.v;
|
|
261
487
|
return _context2.a(2, response);
|
|
262
488
|
}
|
|
@@ -265,33 +491,71 @@ function _createListItem() {
|
|
|
265
491
|
return _createListItem.apply(this, arguments);
|
|
266
492
|
}
|
|
267
493
|
|
|
494
|
+
function escapeODataStringLiteral(value) {
|
|
495
|
+
return value.replace(/'/g, "''");
|
|
496
|
+
}
|
|
497
|
+
function buildListByTitleEndpoint(listName) {
|
|
498
|
+
return "_api/web/lists/GetByTitle('" + escapeODataStringLiteral(listName) + "')";
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function buildLibraryPath(folderPath) {
|
|
502
|
+
if (!folderPath) {
|
|
503
|
+
return '';
|
|
504
|
+
}
|
|
505
|
+
var segments = Array.isArray(folderPath) ? folderPath : folderPath.split('/').filter(Boolean);
|
|
506
|
+
if (!segments.length) {
|
|
507
|
+
return '';
|
|
508
|
+
}
|
|
509
|
+
var escapedSegments = segments.map(function (segment) {
|
|
510
|
+
if (!segment.trim()) {
|
|
511
|
+
throw new Error('Folder path segments cannot be empty.');
|
|
512
|
+
}
|
|
513
|
+
var sanitized = segment.replace(/'/g, "''");
|
|
514
|
+
return "/Folders('" + encodeURIComponent(sanitized) + "')";
|
|
515
|
+
});
|
|
516
|
+
return escapedSegments.join('');
|
|
517
|
+
}
|
|
518
|
+
function encodeFileName(fileName) {
|
|
519
|
+
if (!fileName.trim()) {
|
|
520
|
+
throw new Error('File name cannot be empty.');
|
|
521
|
+
}
|
|
522
|
+
return encodeURIComponent(fileName.replace(/'/g, "''"));
|
|
523
|
+
}
|
|
524
|
+
|
|
268
525
|
function createAttachment(_x, _x2) {
|
|
269
526
|
return _createAttachment.apply(this, arguments);
|
|
270
527
|
}
|
|
271
528
|
function _createAttachment() {
|
|
272
529
|
_createAttachment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
|
|
273
|
-
var file, itemId, requestUrl, response, _t, _t2, _t3, _t4, _t5;
|
|
530
|
+
var file, itemId, encodedFileName, requestUrl, response, _t, _t2, _t3, _t4, _t5;
|
|
274
531
|
return _regenerator().w(function (_context) {
|
|
275
532
|
while (1) switch (_context.n) {
|
|
276
533
|
case 0:
|
|
277
534
|
file = _ref.file, itemId = _ref.itemId;
|
|
278
|
-
|
|
535
|
+
if (!(context.sharepointVersion !== '2013')) {
|
|
536
|
+
_context.n = 1;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
throw new Error('createAttachment is only supported for SharePoint 2013 REST endpoints.');
|
|
540
|
+
case 1:
|
|
541
|
+
encodedFileName = encodeFileName(file.name);
|
|
542
|
+
requestUrl = buildListByTitleEndpoint(context.listName) + "/items(" + itemId + ")/AttachmentFiles/add(FileName='" + encodedFileName + "')";
|
|
279
543
|
_t = context.instance;
|
|
280
544
|
_t2 = requestUrl;
|
|
281
545
|
_t3 = file;
|
|
282
|
-
_context.n =
|
|
546
|
+
_context.n = 2;
|
|
283
547
|
return fetchDigest(context.instance, context.baseURL);
|
|
284
|
-
case
|
|
548
|
+
case 2:
|
|
285
549
|
_t4 = _context.v;
|
|
286
550
|
_t5 = {
|
|
287
551
|
'X-RequestDigest': _t4
|
|
288
552
|
};
|
|
289
|
-
_context.n =
|
|
553
|
+
_context.n = 3;
|
|
290
554
|
return _t.post.call(_t, _t2, _t3, {
|
|
291
555
|
headers: _t5,
|
|
292
556
|
withCredentials: true
|
|
293
557
|
});
|
|
294
|
-
case
|
|
558
|
+
case 3:
|
|
295
559
|
response = _context.v;
|
|
296
560
|
return _context.a(2, response);
|
|
297
561
|
}
|
|
@@ -305,13 +569,24 @@ function deleteItem(_x, _x2) {
|
|
|
305
569
|
}
|
|
306
570
|
function _deleteItem() {
|
|
307
571
|
_deleteItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, id) {
|
|
308
|
-
var response;
|
|
572
|
+
var requestDigest, url, response;
|
|
309
573
|
return _regenerator().w(function (_context) {
|
|
310
574
|
while (1) switch (_context.n) {
|
|
311
575
|
case 0:
|
|
312
576
|
_context.n = 1;
|
|
313
|
-
return context.instance
|
|
577
|
+
return fetchDigest(context.instance, context.baseURL);
|
|
314
578
|
case 1:
|
|
579
|
+
requestDigest = _context.v;
|
|
580
|
+
url = context.sharepointVersion === '2013' ? buildListByTitleEndpoint(context.listName) + "/items(" + id + ")" : context.endpoint + "(" + id + ")";
|
|
581
|
+
_context.n = 2;
|
|
582
|
+
return context.instance.post(url, undefined, {
|
|
583
|
+
headers: {
|
|
584
|
+
'X-RequestDigest': requestDigest,
|
|
585
|
+
'IF-MATCH': '*',
|
|
586
|
+
'X-HTTP-Method': 'DELETE'
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
case 2:
|
|
315
590
|
response = _context.v;
|
|
316
591
|
return _context.a(2, response);
|
|
317
592
|
}
|
|
@@ -320,30 +595,6 @@ function _deleteItem() {
|
|
|
320
595
|
return _deleteItem.apply(this, arguments);
|
|
321
596
|
}
|
|
322
597
|
|
|
323
|
-
function buildLibraryPath(folderPath) {
|
|
324
|
-
if (!folderPath) {
|
|
325
|
-
return '';
|
|
326
|
-
}
|
|
327
|
-
var segments = Array.isArray(folderPath) ? folderPath : folderPath.split('/').filter(Boolean);
|
|
328
|
-
if (!segments.length) {
|
|
329
|
-
return '';
|
|
330
|
-
}
|
|
331
|
-
var escapedSegments = segments.map(function (segment) {
|
|
332
|
-
if (!segment.trim()) {
|
|
333
|
-
throw new Error('Folder path segments cannot be empty.');
|
|
334
|
-
}
|
|
335
|
-
var sanitized = segment.replace(/'/g, "''");
|
|
336
|
-
return "/Folders('" + encodeURIComponent(sanitized) + "')";
|
|
337
|
-
});
|
|
338
|
-
return escapedSegments.join('');
|
|
339
|
-
}
|
|
340
|
-
function encodeFileName(fileName) {
|
|
341
|
-
if (!fileName.trim()) {
|
|
342
|
-
throw new Error('File name cannot be empty.');
|
|
343
|
-
}
|
|
344
|
-
return encodeURIComponent(fileName.replace(/'/g, "''"));
|
|
345
|
-
}
|
|
346
|
-
|
|
347
598
|
var SUPPORTED_VERSION = '2013';
|
|
348
599
|
function deleteFile(_x, _x2) {
|
|
349
600
|
return _deleteFile.apply(this, arguments);
|
|
@@ -362,7 +613,7 @@ function _deleteFile() {
|
|
|
362
613
|
throw new Error('deleteFile is only supported for SharePoint 2013 REST endpoints.');
|
|
363
614
|
case 1:
|
|
364
615
|
encodedFileName = encodeFileName(fileName);
|
|
365
|
-
requestUrl =
|
|
616
|
+
requestUrl = buildListByTitleEndpoint(context.listName) + "/RootFolder";
|
|
366
617
|
requestUrl += buildLibraryPath(folderPath);
|
|
367
618
|
requestUrl += "/Files('" + encodedFileName + "')";
|
|
368
619
|
_context.n = 2;
|
|
@@ -423,6 +674,7 @@ function getFiles(_x, _x2) {
|
|
|
423
674
|
}
|
|
424
675
|
function _getFiles() {
|
|
425
676
|
_getFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, options) {
|
|
677
|
+
var _ref, _response$data$d$resu, _response$data, _response$data2;
|
|
426
678
|
var params, url, response, data, meta;
|
|
427
679
|
return _regenerator().w(function (_context) {
|
|
428
680
|
while (1) switch (_context.n) {
|
|
@@ -438,7 +690,7 @@ function _getFiles() {
|
|
|
438
690
|
});
|
|
439
691
|
case 1:
|
|
440
692
|
response = _context.v;
|
|
441
|
-
data =
|
|
693
|
+
data = (_ref = (_response$data$d$resu = (_response$data = response.data) == null || (_response$data = _response$data.d) == null ? void 0 : _response$data.results) != null ? _response$data$d$resu : (_response$data2 = response.data) == null ? void 0 : _response$data2.d) != null ? _ref : response.data;
|
|
442
694
|
meta = {
|
|
443
695
|
url: url
|
|
444
696
|
};
|
|
@@ -518,13 +770,19 @@ function _getOnly() {
|
|
|
518
770
|
case 1:
|
|
519
771
|
_yield$instance$get = _context.v;
|
|
520
772
|
data = _yield$instance$get.data;
|
|
521
|
-
if (
|
|
773
|
+
if (data) {
|
|
522
774
|
_context.n = 2;
|
|
523
775
|
break;
|
|
524
776
|
}
|
|
525
|
-
return _context.a(2,
|
|
777
|
+
return _context.a(2, undefined);
|
|
526
778
|
case 2:
|
|
527
|
-
|
|
779
|
+
if (!data.d) {
|
|
780
|
+
_context.n = 3;
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
return _context.a(2, data.d.results ? data.d.results : data.d);
|
|
784
|
+
case 3:
|
|
785
|
+
return _context.a(2, data);
|
|
528
786
|
}
|
|
529
787
|
}, _callee);
|
|
530
788
|
}));
|
|
@@ -562,7 +820,7 @@ function updateListItem(_x2, _x3, _x4, _x5) {
|
|
|
562
820
|
}
|
|
563
821
|
function _updateListItem() {
|
|
564
822
|
_updateListItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(context, id, data, digest) {
|
|
565
|
-
var formDigestValue,
|
|
823
|
+
var formDigestValue, normalizedData, payload, metadataType, userMetadata, url, response, _t;
|
|
566
824
|
return _regenerator().w(function (_context2) {
|
|
567
825
|
while (1) switch (_context2.n) {
|
|
568
826
|
case 0:
|
|
@@ -577,17 +835,25 @@ function _updateListItem() {
|
|
|
577
835
|
_t = _context2.v;
|
|
578
836
|
case 2:
|
|
579
837
|
formDigestValue = _t;
|
|
838
|
+
normalizedData = normalizeListPayload(data);
|
|
839
|
+
payload = normalizedData;
|
|
840
|
+
if (!(context.sharepointVersion === '2013')) {
|
|
841
|
+
_context2.n = 4;
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
580
844
|
_context2.n = 3;
|
|
581
845
|
return resolveMetadataType$1(context);
|
|
582
846
|
case 3:
|
|
583
847
|
metadataType = _context2.v;
|
|
584
|
-
|
|
585
|
-
|
|
848
|
+
userMetadata = data.__metadata;
|
|
849
|
+
payload = _extends({}, normalizedData, {
|
|
850
|
+
__metadata: _extends({}, userMetadata && typeof userMetadata === 'object' ? userMetadata : {}, {
|
|
586
851
|
type: metadataType
|
|
587
|
-
}
|
|
852
|
+
})
|
|
588
853
|
});
|
|
589
|
-
|
|
590
|
-
|
|
854
|
+
case 4:
|
|
855
|
+
url = context.sharepointVersion === '2013' ? buildListByTitleEndpoint(context.listName) + "/items(" + id + ")" : context.endpoint + "(" + id + ")";
|
|
856
|
+
_context2.n = 5;
|
|
591
857
|
return context.instance({
|
|
592
858
|
url: url,
|
|
593
859
|
method: 'POST',
|
|
@@ -595,10 +861,10 @@ function _updateListItem() {
|
|
|
595
861
|
headers: {
|
|
596
862
|
'X-RequestDigest': formDigestValue,
|
|
597
863
|
'IF-MATCH': '*',
|
|
598
|
-
'X-
|
|
864
|
+
'X-HTTP-Method': 'MERGE'
|
|
599
865
|
}
|
|
600
866
|
});
|
|
601
|
-
case
|
|
867
|
+
case 5:
|
|
602
868
|
response = _context2.v;
|
|
603
869
|
return _context2.a(2, response);
|
|
604
870
|
}
|
|
@@ -631,7 +897,7 @@ function _uploadFile() {
|
|
|
631
897
|
}
|
|
632
898
|
throw new Error('A file with a valid name must be provided.');
|
|
633
899
|
case 2:
|
|
634
|
-
requestUrl =
|
|
900
|
+
requestUrl = buildListByTitleEndpoint(context.listName) + "/RootFolder";
|
|
635
901
|
requestUrl += buildLibraryPath(folderPath);
|
|
636
902
|
encodedFileName = encodeFileName(file.name);
|
|
637
903
|
requestUrl += "/Files/add(url='" + encodedFileName + "',overwrite=" + (overwrite ? 'true' : 'false') + ")?$expand=ListItemAllFields&$select=ListItemAllFields/Id";
|
|
@@ -680,63 +946,13 @@ function _uploadFile() {
|
|
|
680
946
|
return _uploadFile.apply(this, arguments);
|
|
681
947
|
}
|
|
682
948
|
|
|
683
|
-
function sendEmail(_x, _x2) {
|
|
684
|
-
return _sendEmail.apply(this, arguments);
|
|
685
|
-
}
|
|
686
|
-
function _sendEmail() {
|
|
687
|
-
_sendEmail = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
|
|
688
|
-
var From, To, Subject, Body, httpRequest, response, _t, _t2, _t3, _t4, _t5;
|
|
689
|
-
return _regenerator().w(function (_context) {
|
|
690
|
-
while (1) switch (_context.n) {
|
|
691
|
-
case 0:
|
|
692
|
-
From = _ref.From, To = _ref.To, Subject = _ref.Subject, Body = _ref.Body;
|
|
693
|
-
httpRequest = '_api/SP.Utilities.Utility.SendEmail';
|
|
694
|
-
_t = context;
|
|
695
|
-
_t2 = httpRequest;
|
|
696
|
-
_context.n = 1;
|
|
697
|
-
return fetchDigest(context.instance, context.baseURL);
|
|
698
|
-
case 1:
|
|
699
|
-
_t3 = _context.v;
|
|
700
|
-
_t4 = {
|
|
701
|
-
'X-RequestDigest': _t3,
|
|
702
|
-
'X-Http-Method': 'POST',
|
|
703
|
-
'Content-Type': 'application/json;odata=verbose'
|
|
704
|
-
};
|
|
705
|
-
_t5 = JSON.stringify({
|
|
706
|
-
properties: {
|
|
707
|
-
__metadata: {
|
|
708
|
-
type: 'SP.Utilities.EmailProperties'
|
|
709
|
-
},
|
|
710
|
-
From: From,
|
|
711
|
-
To: {
|
|
712
|
-
results: Array.isArray(To) ? To : [To]
|
|
713
|
-
},
|
|
714
|
-
Body: Body,
|
|
715
|
-
Subject: Subject
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
_context.n = 2;
|
|
719
|
-
return _t.instance.call(_t, {
|
|
720
|
-
url: _t2,
|
|
721
|
-
method: 'POST',
|
|
722
|
-
headers: _t4,
|
|
723
|
-
data: _t5
|
|
724
|
-
});
|
|
725
|
-
case 2:
|
|
726
|
-
response = _context.v;
|
|
727
|
-
return _context.a(2, response);
|
|
728
|
-
}
|
|
729
|
-
}, _callee);
|
|
730
|
-
}));
|
|
731
|
-
return _sendEmail.apply(this, arguments);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
949
|
function typeAhead(_x, _x2, _x3) {
|
|
735
950
|
return _typeAhead.apply(this, arguments);
|
|
736
951
|
}
|
|
737
952
|
function _typeAhead() {
|
|
738
953
|
_typeAhead = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, input, filter) {
|
|
739
|
-
var
|
|
954
|
+
var _response$data$d$Clie, _response$data, _response$data2;
|
|
955
|
+
var requestUrl, data, response, searchResults, parsed;
|
|
740
956
|
return _regenerator().w(function (_context) {
|
|
741
957
|
while (1) switch (_context.n) {
|
|
742
958
|
case 0:
|
|
@@ -768,7 +984,35 @@ function _typeAhead() {
|
|
|
768
984
|
});
|
|
769
985
|
case 1:
|
|
770
986
|
response = _context.v;
|
|
771
|
-
|
|
987
|
+
searchResults = (_response$data$d$Clie = (_response$data = response.data) == null || (_response$data = _response$data.d) == null ? void 0 : _response$data.ClientPeoplePickerSearchUser) != null ? _response$data$d$Clie : (_response$data2 = response.data) == null ? void 0 : _response$data2.ClientPeoplePickerSearchUser;
|
|
988
|
+
if (!(typeof searchResults === 'string')) {
|
|
989
|
+
_context.n = 3;
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
parsed = JSON.parse(searchResults);
|
|
993
|
+
if (!(Array.isArray(parsed) && parsed.length > 0)) {
|
|
994
|
+
_context.n = 2;
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
return _context.a(2, parsed[0]);
|
|
998
|
+
case 2:
|
|
999
|
+
throw new Error('People picker returned no results.');
|
|
1000
|
+
case 3:
|
|
1001
|
+
if (!(Array.isArray(searchResults) && searchResults.length > 0)) {
|
|
1002
|
+
_context.n = 4;
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
return _context.a(2, searchResults[0]);
|
|
1006
|
+
case 4:
|
|
1007
|
+
if (!(searchResults && typeof searchResults === 'object')) {
|
|
1008
|
+
_context.n = 5;
|
|
1009
|
+
break;
|
|
1010
|
+
}
|
|
1011
|
+
return _context.a(2, searchResults);
|
|
1012
|
+
case 5:
|
|
1013
|
+
throw new Error('Invalid people picker response.');
|
|
1014
|
+
case 6:
|
|
1015
|
+
return _context.a(2);
|
|
772
1016
|
}
|
|
773
1017
|
}, _callee);
|
|
774
1018
|
}));
|
|
@@ -814,13 +1058,19 @@ function getSiteUser(_x5, _x6) {
|
|
|
814
1058
|
}
|
|
815
1059
|
function _getSiteUser() {
|
|
816
1060
|
_getSiteUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(instance, searchValue) {
|
|
817
|
-
var
|
|
1061
|
+
var safeSearchValue, response;
|
|
818
1062
|
return _regenerator().w(function (_context3) {
|
|
819
1063
|
while (1) switch (_context3.n) {
|
|
820
1064
|
case 0:
|
|
821
|
-
|
|
1065
|
+
safeSearchValue = escapeODataStringLiteral(searchValue);
|
|
822
1066
|
_context3.n = 1;
|
|
823
|
-
return instance.get(
|
|
1067
|
+
return instance.get('_api/web/siteusers', {
|
|
1068
|
+
params: {
|
|
1069
|
+
$filter: "substringof('" + safeSearchValue + "', Title) or substringof('" + safeSearchValue + "', LoginName) or substringof('" + safeSearchValue + "', Email)",
|
|
1070
|
+
$top: 50,
|
|
1071
|
+
$expand: 'Groups'
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
824
1074
|
case 1:
|
|
825
1075
|
response = _context3.v;
|
|
826
1076
|
return _context3.a(2, response.data.d);
|
|
@@ -891,6 +1141,12 @@ function _currentUserPermissions() {
|
|
|
891
1141
|
var BasePermissions = _ref.BasePermissions;
|
|
892
1142
|
return BasePermissions.High === High;
|
|
893
1143
|
});
|
|
1144
|
+
if (result) {
|
|
1145
|
+
_context6.n = 3;
|
|
1146
|
+
break;
|
|
1147
|
+
}
|
|
1148
|
+
throw new Error("Unable to resolve current user permission for BasePermissions.High=\"" + High + "\".");
|
|
1149
|
+
case 3:
|
|
894
1150
|
return _context6.a(2, result);
|
|
895
1151
|
}
|
|
896
1152
|
}, _callee6);
|
|
@@ -902,155 +1158,160 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
|
|
|
902
1158
|
function HTTPSharePointRequests(baseURL, config) {
|
|
903
1159
|
var _this = this;
|
|
904
1160
|
this.baseURL = void 0;
|
|
905
|
-
this.endpoint = void 0;
|
|
906
|
-
this.listName = void 0;
|
|
907
1161
|
this.instance = void 0;
|
|
908
|
-
this.
|
|
909
|
-
this.
|
|
910
|
-
this.lists = {
|
|
911
|
-
get: function get() {
|
|
912
|
-
_this.endpoint = '_api/web/lists';
|
|
913
|
-
_this.sharepointVersion = '2013';
|
|
914
|
-
return getListItems(_this.getContext());
|
|
915
|
-
}
|
|
916
|
-
};
|
|
917
|
-
this.folders = {
|
|
918
|
-
get: function get() {
|
|
919
|
-
_this.endpoint = '_api/web/folders';
|
|
920
|
-
_this.sharepointVersion = '2013';
|
|
921
|
-
getListItems(_this.getContext());
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
this.email = {
|
|
925
|
-
send: function send(props) {
|
|
926
|
-
_this.sharepointVersion = '2013';
|
|
927
|
-
return sendEmail(_this.getContext(), props);
|
|
928
|
-
}
|
|
929
|
-
};
|
|
1162
|
+
this.listItemEntityTypeCache = void 0;
|
|
1163
|
+
this.email = void 0;
|
|
930
1164
|
this.user = {
|
|
931
1165
|
properties: function properties() {
|
|
932
1166
|
return {
|
|
933
1167
|
get: function get() {
|
|
934
|
-
_this.sharepointVersion = '2013';
|
|
935
1168
|
return currentUserProperties(_this.instance);
|
|
936
1169
|
}
|
|
937
1170
|
};
|
|
938
1171
|
},
|
|
939
1172
|
searchSiteUser: function searchSiteUser(searchValue) {
|
|
940
|
-
_this.sharepointVersion = '2013';
|
|
941
1173
|
return getSiteUser(_this.instance, searchValue);
|
|
942
1174
|
},
|
|
943
1175
|
searchUser: function searchUser(input, filter) {
|
|
944
|
-
_this.sharepointVersion = '2013';
|
|
945
1176
|
return typeAhead(_this.instance, input, filter);
|
|
946
1177
|
},
|
|
947
1178
|
current: function current() {
|
|
948
|
-
_this.endpoint = '_api/web/currentUser';
|
|
949
|
-
_this.sharepointVersion = '2013';
|
|
950
1179
|
return {
|
|
951
1180
|
get: function get() {
|
|
952
|
-
return getOnly(_this.instance,
|
|
1181
|
+
return getOnly(_this.instance, '_api/web/currentUser');
|
|
953
1182
|
}
|
|
954
1183
|
};
|
|
955
1184
|
},
|
|
956
1185
|
currentPermission: function currentPermission() {
|
|
957
1186
|
return {
|
|
958
1187
|
get: function get() {
|
|
959
|
-
_this.
|
|
960
|
-
|
|
1188
|
+
return currentUserPermissions(_this.createContext({
|
|
1189
|
+
endpoint: '_api/web/effectiveBasePermissions',
|
|
1190
|
+
listName: '',
|
|
1191
|
+
sharepointVersion: '2013'
|
|
1192
|
+
}));
|
|
961
1193
|
}
|
|
962
1194
|
};
|
|
963
1195
|
}
|
|
964
1196
|
};
|
|
965
1197
|
this.baseURL = baseURL.endsWith('/') ? baseURL : baseURL + "/";
|
|
966
|
-
this.endpoint = '/api';
|
|
967
|
-
this.listName = '';
|
|
968
1198
|
this.instance = instance(this.baseURL, config);
|
|
969
|
-
this.
|
|
970
|
-
this.
|
|
1199
|
+
this.listItemEntityTypeCache = new Map();
|
|
1200
|
+
this.email = Object.assign(function (from, to, subject, body) {
|
|
1201
|
+
return _this.sendEmail({
|
|
1202
|
+
From: from,
|
|
1203
|
+
To: to,
|
|
1204
|
+
Subject: subject,
|
|
1205
|
+
Body: body
|
|
1206
|
+
});
|
|
1207
|
+
}, {
|
|
1208
|
+
send: function send(props) {
|
|
1209
|
+
return _this.sendEmail(props);
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
971
1212
|
}
|
|
972
1213
|
var _proto = HTTPSharePointRequests.prototype;
|
|
973
|
-
_proto.
|
|
1214
|
+
_proto.createContext = function createContext(_ref) {
|
|
1215
|
+
var endpoint = _ref.endpoint,
|
|
1216
|
+
listName = _ref.listName,
|
|
1217
|
+
sharepointVersion = _ref.sharepointVersion,
|
|
1218
|
+
listItemEntityTypeFullName = _ref.listItemEntityTypeFullName,
|
|
1219
|
+
resolveListItemEntityType = _ref.resolveListItemEntityType;
|
|
974
1220
|
return {
|
|
975
1221
|
instance: this.instance,
|
|
976
1222
|
baseURL: this.baseURL,
|
|
977
|
-
endpoint:
|
|
978
|
-
listName:
|
|
979
|
-
sharepointVersion:
|
|
980
|
-
listItemEntityTypeFullName:
|
|
981
|
-
resolveListItemEntityType:
|
|
1223
|
+
endpoint: endpoint,
|
|
1224
|
+
listName: listName,
|
|
1225
|
+
sharepointVersion: sharepointVersion,
|
|
1226
|
+
listItemEntityTypeFullName: listItemEntityTypeFullName,
|
|
1227
|
+
resolveListItemEntityType: resolveListItemEntityType
|
|
982
1228
|
};
|
|
983
1229
|
};
|
|
984
1230
|
_proto.resolveListItemEntityTypeFullName = /*#__PURE__*/function () {
|
|
985
|
-
var _resolveListItemEntityTypeFullName = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1231
|
+
var _resolveListItemEntityTypeFullName = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(listName) {
|
|
986
1232
|
var _response$data$d$List, _response$data, _response$data2;
|
|
987
|
-
var response, entityType;
|
|
1233
|
+
var cacheKey, cachedType, response, entityType;
|
|
988
1234
|
return _regenerator().w(function (_context) {
|
|
989
1235
|
while (1) switch (_context.n) {
|
|
990
1236
|
case 0:
|
|
991
|
-
|
|
1237
|
+
cacheKey = listName;
|
|
1238
|
+
cachedType = this.listItemEntityTypeCache.get(cacheKey);
|
|
1239
|
+
if (!cachedType) {
|
|
992
1240
|
_context.n = 1;
|
|
993
1241
|
break;
|
|
994
1242
|
}
|
|
995
|
-
return _context.a(2,
|
|
1243
|
+
return _context.a(2, cachedType);
|
|
996
1244
|
case 1:
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
break;
|
|
1000
|
-
}
|
|
1001
|
-
throw new Error('List name is not set.');
|
|
1245
|
+
_context.n = 2;
|
|
1246
|
+
return this.instance.get(buildListByTitleEndpoint(listName) + "?$select=ListItemEntityTypeFullName");
|
|
1002
1247
|
case 2:
|
|
1003
|
-
if (!(this.sharepointVersion !== '2013')) {
|
|
1004
|
-
_context.n = 3;
|
|
1005
|
-
break;
|
|
1006
|
-
}
|
|
1007
|
-
this.listItemEntityTypeFullName = "SP.Data." + this.listName + "ListItem";
|
|
1008
|
-
return _context.a(2, this.listItemEntityTypeFullName);
|
|
1009
|
-
case 3:
|
|
1010
|
-
_context.n = 4;
|
|
1011
|
-
return this.instance.get("_api/web/lists/GetByTitle('" + this.listName + "')?$select=ListItemEntityTypeFullName");
|
|
1012
|
-
case 4:
|
|
1013
1248
|
response = _context.v;
|
|
1014
1249
|
entityType = (_response$data$d$List = (_response$data = response.data) == null || (_response$data = _response$data.d) == null ? void 0 : _response$data.ListItemEntityTypeFullName) != null ? _response$data$d$List : (_response$data2 = response.data) == null ? void 0 : _response$data2.ListItemEntityTypeFullName;
|
|
1015
1250
|
if (!(!entityType || typeof entityType !== 'string')) {
|
|
1016
|
-
_context.n =
|
|
1251
|
+
_context.n = 3;
|
|
1017
1252
|
break;
|
|
1018
1253
|
}
|
|
1019
|
-
throw new Error("Unable to resolve ListItemEntityTypeFullName for list \"" +
|
|
1020
|
-
case
|
|
1021
|
-
this.
|
|
1022
|
-
return _context.a(2,
|
|
1254
|
+
throw new Error("Unable to resolve ListItemEntityTypeFullName for list \"" + listName + "\".");
|
|
1255
|
+
case 3:
|
|
1256
|
+
this.listItemEntityTypeCache.set(cacheKey, entityType);
|
|
1257
|
+
return _context.a(2, entityType);
|
|
1023
1258
|
}
|
|
1024
1259
|
}, _callee, this);
|
|
1025
1260
|
}));
|
|
1026
|
-
function resolveListItemEntityTypeFullName() {
|
|
1261
|
+
function resolveListItemEntityTypeFullName(_x) {
|
|
1027
1262
|
return _resolveListItemEntityTypeFullName.apply(this, arguments);
|
|
1028
1263
|
}
|
|
1029
1264
|
return resolveListItemEntityTypeFullName;
|
|
1030
|
-
}()
|
|
1031
|
-
|
|
1032
|
-
* @deprecated Use `from` instead.
|
|
1033
|
-
*/
|
|
1034
|
-
;
|
|
1035
|
-
_proto.list = function list(listName) {
|
|
1036
|
-
this.listName = listName;
|
|
1037
|
-
this.endpoint = "_vti_bin/ListData.svc/" + listName;
|
|
1038
|
-
this.sharepointVersion = '2010';
|
|
1039
|
-
this.listItemEntityTypeFullName = undefined;
|
|
1040
|
-
return this;
|
|
1041
|
-
};
|
|
1042
|
-
_proto.getDigest = function getDigest() {
|
|
1043
|
-
return fetchDigest(this.instance, this.baseURL);
|
|
1044
|
-
};
|
|
1045
|
-
_proto.from = function from(listName, sharepoint_ver) {
|
|
1265
|
+
}();
|
|
1266
|
+
_proto.buildListScope = function buildListScope(listName, version) {
|
|
1046
1267
|
var _this2 = this;
|
|
1047
|
-
var
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1268
|
+
var listNameValue = String(listName);
|
|
1269
|
+
var endpoint = version === '2013' ? buildListByTitleEndpoint(listNameValue) + "/items" : "_vti_bin/ListData.svc/" + encodeURIComponent(listNameValue);
|
|
1270
|
+
var scopedEntityType;
|
|
1271
|
+
var resolveListItemEntityType = /*#__PURE__*/function () {
|
|
1272
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
1273
|
+
return _regenerator().w(function (_context2) {
|
|
1274
|
+
while (1) switch (_context2.n) {
|
|
1275
|
+
case 0:
|
|
1276
|
+
if (!scopedEntityType) {
|
|
1277
|
+
_context2.n = 1;
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
return _context2.a(2, scopedEntityType);
|
|
1281
|
+
case 1:
|
|
1282
|
+
if (!(version !== '2013')) {
|
|
1283
|
+
_context2.n = 2;
|
|
1284
|
+
break;
|
|
1285
|
+
}
|
|
1286
|
+
scopedEntityType = "SP.Data." + listNameValue + "ListItem";
|
|
1287
|
+
return _context2.a(2, scopedEntityType);
|
|
1288
|
+
case 2:
|
|
1289
|
+
_context2.n = 3;
|
|
1290
|
+
return _this2.resolveListItemEntityTypeFullName(listNameValue);
|
|
1291
|
+
case 3:
|
|
1292
|
+
scopedEntityType = _context2.v;
|
|
1293
|
+
return _context2.a(2, scopedEntityType);
|
|
1294
|
+
}
|
|
1295
|
+
}, _callee2);
|
|
1296
|
+
}));
|
|
1297
|
+
return function resolveListItemEntityType() {
|
|
1298
|
+
return _ref2.apply(this, arguments);
|
|
1299
|
+
};
|
|
1300
|
+
}();
|
|
1052
1301
|
var getContext = function getContext() {
|
|
1053
|
-
return _this2.
|
|
1302
|
+
return _this2.createContext({
|
|
1303
|
+
endpoint: endpoint,
|
|
1304
|
+
listName: listNameValue,
|
|
1305
|
+
sharepointVersion: version,
|
|
1306
|
+
listItemEntityTypeFullName: scopedEntityType,
|
|
1307
|
+
resolveListItemEntityType: resolveListItemEntityType
|
|
1308
|
+
});
|
|
1309
|
+
};
|
|
1310
|
+
var removeItem = function removeItem(id) {
|
|
1311
|
+
return deleteItem(getContext(), id);
|
|
1312
|
+
};
|
|
1313
|
+
var removeFile = function removeFile(props) {
|
|
1314
|
+
return deleteFile(getContext(), props);
|
|
1054
1315
|
};
|
|
1055
1316
|
return {
|
|
1056
1317
|
create: function create(data) {
|
|
@@ -1062,60 +1323,142 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
|
|
|
1062
1323
|
update: function update(id, data, digest) {
|
|
1063
1324
|
return updateListItem(getContext(), id, data, digest);
|
|
1064
1325
|
},
|
|
1065
|
-
"delete":
|
|
1066
|
-
|
|
1067
|
-
},
|
|
1326
|
+
"delete": removeItem,
|
|
1327
|
+
remove: removeItem,
|
|
1068
1328
|
createFile: function createFile(props) {
|
|
1069
1329
|
return createAttachment(getContext(), props);
|
|
1070
1330
|
},
|
|
1071
1331
|
uploadFile: function uploadFile$1(props) {
|
|
1072
1332
|
return uploadFile(getContext(), props);
|
|
1073
1333
|
},
|
|
1074
|
-
deleteFile:
|
|
1075
|
-
|
|
1076
|
-
},
|
|
1334
|
+
deleteFile: removeFile,
|
|
1335
|
+
removeFile: removeFile,
|
|
1077
1336
|
fields: function fields(options) {
|
|
1078
|
-
|
|
1337
|
+
var fieldsEndpoint = !(options != null && options.fieldName) ? buildListByTitleEndpoint(listNameValue) + "/fields" : buildListByTitleEndpoint(listNameValue) + "/fields/getbytitle('" + escapeODataStringLiteral(String(options.fieldName)) + "')";
|
|
1079
1338
|
return {
|
|
1080
1339
|
get: function get() {
|
|
1081
|
-
return getOnly(_this2.instance,
|
|
1340
|
+
return getOnly(_this2.instance, fieldsEndpoint, options);
|
|
1082
1341
|
}
|
|
1083
1342
|
};
|
|
1343
|
+
},
|
|
1344
|
+
items: {
|
|
1345
|
+
create: function create(data) {
|
|
1346
|
+
return createListItem(getContext(), data);
|
|
1347
|
+
},
|
|
1348
|
+
get: function get(options) {
|
|
1349
|
+
return getListItems(getContext(), options);
|
|
1350
|
+
},
|
|
1351
|
+
update: function update(id, data, digest) {
|
|
1352
|
+
return updateListItem(getContext(), id, data, digest);
|
|
1353
|
+
},
|
|
1354
|
+
"delete": removeItem,
|
|
1355
|
+
remove: removeItem
|
|
1356
|
+
},
|
|
1357
|
+
files: {
|
|
1358
|
+
attach: function attach(props) {
|
|
1359
|
+
return createAttachment(getContext(), props);
|
|
1360
|
+
},
|
|
1361
|
+
upload: function upload(props) {
|
|
1362
|
+
return uploadFile(getContext(), props);
|
|
1363
|
+
},
|
|
1364
|
+
"delete": removeFile,
|
|
1365
|
+
remove: removeFile
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* @deprecated Use `from(listName, '2010')` instead.
|
|
1371
|
+
*/;
|
|
1372
|
+
_proto.list = function list(listName) {
|
|
1373
|
+
return this.from(listName, '2010');
|
|
1374
|
+
};
|
|
1375
|
+
_proto.from = function from(listName, sharepointVersion) {
|
|
1376
|
+
var version = sharepointVersion != null ? sharepointVersion : '2013';
|
|
1377
|
+
return this.buildListScope(listName, version);
|
|
1378
|
+
};
|
|
1379
|
+
_proto.field = function field(listName, fieldName, sharepointVersion) {
|
|
1380
|
+
return this.from(listName, sharepointVersion).fields({
|
|
1381
|
+
fieldName: fieldName
|
|
1382
|
+
}).get();
|
|
1383
|
+
};
|
|
1384
|
+
_proto.lists = function lists(options) {
|
|
1385
|
+
var context = this.createContext({
|
|
1386
|
+
endpoint: '_api/web/lists',
|
|
1387
|
+
listName: '',
|
|
1388
|
+
sharepointVersion: '2013'
|
|
1389
|
+
});
|
|
1390
|
+
return {
|
|
1391
|
+
get: function get() {
|
|
1392
|
+
return getListItems(context, options);
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
};
|
|
1396
|
+
_proto.getDigest = function getDigest() {
|
|
1397
|
+
return fetchDigest(this.instance, this.baseURL);
|
|
1398
|
+
};
|
|
1399
|
+
_proto.folders = function folders(options) {
|
|
1400
|
+
var context = this.createContext({
|
|
1401
|
+
endpoint: '_api/web/folders',
|
|
1402
|
+
listName: '',
|
|
1403
|
+
sharepointVersion: '2013'
|
|
1404
|
+
});
|
|
1405
|
+
return {
|
|
1406
|
+
get: function get() {
|
|
1407
|
+
return getFiles(context, options);
|
|
1084
1408
|
}
|
|
1085
1409
|
};
|
|
1086
1410
|
};
|
|
1087
1411
|
_proto.folder = function folder(folderName) {
|
|
1088
1412
|
var _this3 = this;
|
|
1089
|
-
var
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
this.endpoint = "_api/web/GetFolderByServerRelativeUrl('" + filePath.join('/') + "')";
|
|
1094
|
-
this.sharepointVersion = '2013';
|
|
1095
|
-
var getContext = function getContext() {
|
|
1096
|
-
return _this3.getContext();
|
|
1097
|
-
};
|
|
1413
|
+
var defaultPath = ['Shared Documents'];
|
|
1414
|
+
var segments = folderName ? Array.isArray(folderName) ? [].concat(defaultPath, folderName) : [].concat(defaultPath, folderName.split('/').filter(Boolean)) : defaultPath;
|
|
1415
|
+
var serverRelativePath = escapeODataStringLiteral(segments.join('/'));
|
|
1416
|
+
var baseEndpoint = "_api/web/GetFolderByServerRelativeUrl('" + serverRelativePath + "')";
|
|
1098
1417
|
return {
|
|
1099
1418
|
get: function get(options) {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1419
|
+
var _options$type;
|
|
1420
|
+
var folderType = (_options$type = options == null ? void 0 : options.type) != null ? _options$type : 'Files';
|
|
1421
|
+
var endpoint = baseEndpoint + "/" + folderType;
|
|
1422
|
+
var context = _this3.createContext({
|
|
1423
|
+
endpoint: endpoint,
|
|
1424
|
+
listName: '',
|
|
1425
|
+
sharepointVersion: '2013'
|
|
1426
|
+
});
|
|
1427
|
+
return getFiles(context, _extends({}, options, {
|
|
1428
|
+
type: folderType
|
|
1429
|
+
}));
|
|
1106
1430
|
}
|
|
1107
1431
|
};
|
|
1108
1432
|
};
|
|
1109
1433
|
_proto.users = function users(options) {
|
|
1110
|
-
var
|
|
1111
|
-
|
|
1112
|
-
|
|
1434
|
+
var context = this.createContext({
|
|
1435
|
+
endpoint: '_api/web/SiteUserInfoList/items',
|
|
1436
|
+
listName: '',
|
|
1437
|
+
sharepointVersion: '2013'
|
|
1438
|
+
});
|
|
1113
1439
|
return {
|
|
1114
1440
|
get: function get() {
|
|
1115
|
-
return getListItems(
|
|
1441
|
+
return getListItems(context, options);
|
|
1116
1442
|
}
|
|
1117
1443
|
};
|
|
1118
1444
|
};
|
|
1445
|
+
_proto.sendEmail = function sendEmail$1(props) {
|
|
1446
|
+
var context = this.createContext({
|
|
1447
|
+
endpoint: '_api/SP.Utilities.Utility.SendEmail',
|
|
1448
|
+
listName: '',
|
|
1449
|
+
sharepointVersion: '2013'
|
|
1450
|
+
});
|
|
1451
|
+
return sendEmail(context, props);
|
|
1452
|
+
};
|
|
1453
|
+
_proto.getCurrentUser = function getCurrentUser() {
|
|
1454
|
+
return this.user.current().get();
|
|
1455
|
+
};
|
|
1456
|
+
_proto.currentUserProperties = function currentUserProperties() {
|
|
1457
|
+
return this.user.properties().get();
|
|
1458
|
+
};
|
|
1459
|
+
_proto.currentUserPermission = function currentUserPermission() {
|
|
1460
|
+
return this.user.currentPermission().get();
|
|
1461
|
+
};
|
|
1119
1462
|
return HTTPSharePointRequests;
|
|
1120
1463
|
}();
|
|
1121
1464
|
|