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