@lindle/sharepoint_requests 0.1.12 → 0.1.13

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 (37) hide show
  1. package/dist/root/index.d.ts +16 -217
  2. package/dist/root/internal/context.d.ts +9 -0
  3. package/dist/root/internal/digest.d.ts +2 -0
  4. package/dist/root/internal/emailRequests.d.ts +10 -0
  5. package/dist/root/internal/listRequests/createAttachment.d.ts +3 -0
  6. package/dist/root/internal/listRequests/createListItem.d.ts +3 -0
  7. package/dist/root/internal/listRequests/deleteItem.d.ts +3 -0
  8. package/dist/root/internal/listRequests/getFiles.d.ts +8 -0
  9. package/dist/root/internal/listRequests/getListItems.d.ts +8 -0
  10. package/dist/root/internal/listRequests/getOnly.d.ts +3 -0
  11. package/dist/root/internal/listRequests/index.d.ts +7 -0
  12. package/dist/root/internal/listRequests/updateListItem.d.ts +3 -0
  13. package/dist/root/internal/odata.d.ts +5 -0
  14. package/dist/root/internal/userRequests.d.ts +15 -0
  15. package/dist/sharepoint_requests.cjs.development.js +597 -756
  16. package/dist/sharepoint_requests.cjs.development.js.map +1 -1
  17. package/dist/sharepoint_requests.cjs.production.min.js +1 -1
  18. package/dist/sharepoint_requests.cjs.production.min.js.map +1 -1
  19. package/dist/sharepoint_requests.esm.js +597 -756
  20. package/dist/sharepoint_requests.esm.js.map +1 -1
  21. package/dist/types.d.ts +38 -7
  22. package/package.json +1 -1
  23. package/src/root/index.ts +194 -598
  24. package/src/root/internal/context.ts +10 -0
  25. package/src/root/internal/digest.ts +22 -0
  26. package/src/root/internal/emailRequests.ts +45 -0
  27. package/src/root/internal/listRequests/createAttachment.ts +18 -0
  28. package/src/root/internal/listRequests/createListItem.ts +36 -0
  29. package/src/root/internal/listRequests/deleteItem.ts +10 -0
  30. package/src/root/internal/listRequests/getFiles.ts +31 -0
  31. package/src/root/internal/listRequests/getListItems.ts +50 -0
  32. package/src/root/internal/listRequests/getOnly.ts +18 -0
  33. package/src/root/internal/listRequests/index.ts +7 -0
  34. package/src/root/internal/listRequests/updateListItem.ts +32 -0
  35. package/src/root/internal/odata.ts +36 -0
  36. package/src/root/internal/userRequests.ts +109 -0
  37. package/src/types.ts +76 -36
@@ -167,120 +167,608 @@ var instance = function instance(baseURL, config) {
167
167
  }));
168
168
  };
169
169
 
170
+ function fetchDigest(_x, _x2) {
171
+ return _fetchDigest.apply(this, arguments);
172
+ }
173
+ function _fetchDigest() {
174
+ _fetchDigest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, baseURL) {
175
+ var _response$data, response, formDigestValue, _t;
176
+ return _regenerator().w(function (_context) {
177
+ while (1) switch (_context.p = _context.n) {
178
+ case 0:
179
+ _context.p = 0;
180
+ _context.n = 1;
181
+ return instance.post(baseURL + "_api/contextinfo");
182
+ case 1:
183
+ response = _context.v;
184
+ formDigestValue = (_response$data = response.data) == null || (_response$data = _response$data.d) == null || (_response$data = _response$data.GetContextWebInformation) == null ? void 0 : _response$data.FormDigestValue;
185
+ if (formDigestValue) {
186
+ _context.n = 2;
187
+ break;
188
+ }
189
+ throw new Error('Invalid response structure: Missing FormDigestValue');
190
+ case 2:
191
+ return _context.a(2, formDigestValue);
192
+ case 3:
193
+ _context.p = 3;
194
+ _t = _context.v;
195
+ console.error('Failed to retrieve the Form Digest Value:', _t);
196
+ throw new Error("Error retrieving Form Digest Value");
197
+ case 4:
198
+ return _context.a(2);
199
+ }
200
+ }, _callee, null, [[0, 3]]);
201
+ }));
202
+ return _fetchDigest.apply(this, arguments);
203
+ }
204
+
205
+ function transformArraysToEdmStrings(data) {
206
+ for (var key in data) {
207
+ if (Array.isArray(data[key])) {
208
+ data[key] = {
209
+ __metadata: {
210
+ type: 'Collection(Edm.String)'
211
+ },
212
+ results: data[key]
213
+ };
214
+ }
215
+ }
216
+ }
217
+ function createListItem(_x, _x2) {
218
+ return _createListItem.apply(this, arguments);
219
+ }
220
+ function _createListItem() {
221
+ _createListItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, listData) {
222
+ var response, _t, _t2, _t3, _t4, _t5;
223
+ return _regenerator().w(function (_context) {
224
+ while (1) switch (_context.n) {
225
+ case 0:
226
+ transformArraysToEdmStrings(listData);
227
+ listData.__metadata = {
228
+ type: "SP.Data." + context.listName + "ListItem"
229
+ };
230
+ _t = context;
231
+ _t2 = context.endpoint;
232
+ _t3 = JSON.stringify(listData);
233
+ _context.n = 1;
234
+ return fetchDigest(context.instance, context.baseURL);
235
+ case 1:
236
+ _t4 = _context.v;
237
+ _t5 = {
238
+ 'X-RequestDigest': _t4,
239
+ 'IF-MATCH': '*'
240
+ };
241
+ _context.n = 2;
242
+ return _t.instance.call(_t, {
243
+ url: _t2,
244
+ method: 'POST',
245
+ data: _t3,
246
+ headers: _t5
247
+ });
248
+ case 2:
249
+ response = _context.v;
250
+ return _context.a(2, response);
251
+ }
252
+ }, _callee);
253
+ }));
254
+ return _createListItem.apply(this, arguments);
255
+ }
256
+
257
+ function createAttachment(_x, _x2) {
258
+ return _createAttachment.apply(this, arguments);
259
+ }
260
+ function _createAttachment() {
261
+ _createAttachment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
262
+ var file, itemId, requestUrl, response, _t, _t2, _t3, _t4, _t5;
263
+ return _regenerator().w(function (_context) {
264
+ while (1) switch (_context.n) {
265
+ case 0:
266
+ file = _ref.file, itemId = _ref.itemId;
267
+ requestUrl = "_api/lists/getbytitle('" + context.listName + "')/items(" + itemId + ")/AttachmentFiles/add(FileName='" + file.name + "')";
268
+ _t = context.instance;
269
+ _t2 = requestUrl;
270
+ _t3 = file;
271
+ _context.n = 1;
272
+ return fetchDigest(context.instance, context.baseURL);
273
+ case 1:
274
+ _t4 = _context.v;
275
+ _t5 = {
276
+ 'X-RequestDigest': _t4
277
+ };
278
+ _context.n = 2;
279
+ return _t.post.call(_t, _t2, _t3, {
280
+ headers: _t5,
281
+ withCredentials: true
282
+ });
283
+ case 2:
284
+ response = _context.v;
285
+ return _context.a(2, response);
286
+ }
287
+ }, _callee);
288
+ }));
289
+ return _createAttachment.apply(this, arguments);
290
+ }
291
+
292
+ function deleteItem(_x, _x2) {
293
+ return _deleteItem.apply(this, arguments);
294
+ }
295
+ function _deleteItem() {
296
+ _deleteItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, id) {
297
+ var response;
298
+ return _regenerator().w(function (_context) {
299
+ while (1) switch (_context.n) {
300
+ case 0:
301
+ _context.n = 1;
302
+ return context.instance["delete"](context.endpoint + "(" + id + ")");
303
+ case 1:
304
+ response = _context.v;
305
+ return _context.a(2, response);
306
+ }
307
+ }, _callee);
308
+ }));
309
+ return _deleteItem.apply(this, arguments);
310
+ }
311
+
312
+ function buildODataParams(options, orderBySeparator) {
313
+ if (orderBySeparator === void 0) {
314
+ orderBySeparator = ',';
315
+ }
316
+ var _ref = options || {},
317
+ expand = _ref.expand,
318
+ orderBy = _ref.orderBy,
319
+ limit = _ref.limit,
320
+ filter = _ref.filter,
321
+ cols = _ref.cols,
322
+ skip = _ref.skip;
323
+ var params = {
324
+ $expand: Array.isArray(expand) ? expand.join(',') : expand,
325
+ $top: limit,
326
+ $skip: skip,
327
+ $select: Array.isArray(cols) ? cols.join(',') : cols,
328
+ $filter: filter,
329
+ $orderby: Array.isArray(orderBy) ? orderBy.join(orderBySeparator) : orderBy
330
+ };
331
+ return params;
332
+ }
333
+ function appendParamsToUrl(baseUrl, params) {
334
+ Object.entries(params).forEach(function (_ref2) {
335
+ var key = _ref2[0],
336
+ value = _ref2[1];
337
+ if (value !== undefined && value !== null) {
338
+ baseUrl.searchParams.append(key, String(value));
339
+ }
340
+ });
341
+ }
342
+
343
+ function getFiles(_x, _x2) {
344
+ return _getFiles.apply(this, arguments);
345
+ }
346
+ function _getFiles() {
347
+ _getFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, options) {
348
+ var params, url, response, data, meta;
349
+ return _regenerator().w(function (_context) {
350
+ while (1) switch (_context.n) {
351
+ case 0:
352
+ params = buildODataParams(options, ',');
353
+ url = new URL(context.endpoint, context.instance.defaults.baseURL);
354
+ appendParamsToUrl(url, params);
355
+ _context.n = 1;
356
+ return context.instance.request({
357
+ url: context.endpoint,
358
+ method: 'GET',
359
+ params: params
360
+ });
361
+ case 1:
362
+ response = _context.v;
363
+ data = options != null && options.limit || !response.data.d.results ? response.data.d : response.data.d.results;
364
+ meta = {
365
+ url: url
366
+ };
367
+ return _context.a(2, {
368
+ data: data,
369
+ meta: meta
370
+ });
371
+ }
372
+ }, _callee);
373
+ }));
374
+ return _getFiles.apply(this, arguments);
375
+ }
376
+
377
+ function getListItems(_x, _x2) {
378
+ return _getListItems.apply(this, arguments);
379
+ }
380
+ function _getListItems() {
381
+ _getListItems = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, options) {
382
+ var _ref, _response$data$d$resu, _response$data, _response$data2;
383
+ var params, url, response, rawData, cols, keys, filterItem, data, meta;
384
+ return _regenerator().w(function (_context) {
385
+ while (1) switch (_context.n) {
386
+ case 0:
387
+ params = buildODataParams(options, ' ');
388
+ url = new URL(context.endpoint, context.instance.defaults.baseURL);
389
+ appendParamsToUrl(url, params);
390
+ _context.n = 1;
391
+ return context.instance.request({
392
+ url: context.endpoint,
393
+ method: 'GET',
394
+ params: params
395
+ });
396
+ case 1:
397
+ response = _context.v;
398
+ rawData = (_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;
399
+ cols = options == null ? void 0 : options.cols;
400
+ keys = cols ? (Array.isArray(cols) ? cols : [cols]).filter(Boolean) : undefined;
401
+ filterItem = function filterItem(item) {
402
+ if (!keys || !item || typeof item !== 'object') {
403
+ return item;
404
+ }
405
+ return keys.reduce(function (acc, key) {
406
+ if (key in item) {
407
+ acc[key] = item[key];
408
+ }
409
+ return acc;
410
+ }, {});
411
+ };
412
+ data = Array.isArray(rawData) ? rawData.map(filterItem) : filterItem(rawData);
413
+ meta = {
414
+ url: url
415
+ };
416
+ return _context.a(2, {
417
+ data: data,
418
+ meta: meta
419
+ });
420
+ }
421
+ }, _callee);
422
+ }));
423
+ return _getListItems.apply(this, arguments);
424
+ }
425
+
426
+ function getOnly(_x, _x2, _x3) {
427
+ return _getOnly.apply(this, arguments);
428
+ }
429
+ function _getOnly() {
430
+ _getOnly = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, endpoint, options) {
431
+ var params, _yield$instance$get, data;
432
+ return _regenerator().w(function (_context) {
433
+ while (1) switch (_context.n) {
434
+ case 0:
435
+ params = buildODataParams(options, ',');
436
+ _context.n = 1;
437
+ return instance.get(endpoint, {
438
+ params: params
439
+ });
440
+ case 1:
441
+ _yield$instance$get = _context.v;
442
+ data = _yield$instance$get.data;
443
+ if (!data) {
444
+ _context.n = 2;
445
+ break;
446
+ }
447
+ return _context.a(2, data.d.results ? data.d.results : data.d);
448
+ case 2:
449
+ return _context.a(2);
450
+ }
451
+ }, _callee);
452
+ }));
453
+ return _getOnly.apply(this, arguments);
454
+ }
455
+
456
+ function updateListItem(_x, _x2, _x3, _x4) {
457
+ return _updateListItem.apply(this, arguments);
458
+ }
459
+ function _updateListItem() {
460
+ _updateListItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, id, data, digest) {
461
+ var formDigestValue, url, response, _t;
462
+ return _regenerator().w(function (_context) {
463
+ while (1) switch (_context.n) {
464
+ case 0:
465
+ _t = digest;
466
+ if (_t) {
467
+ _context.n = 2;
468
+ break;
469
+ }
470
+ _context.n = 1;
471
+ return fetchDigest(context.instance, context.baseURL);
472
+ case 1:
473
+ _t = _context.v;
474
+ case 2:
475
+ formDigestValue = _t;
476
+ data.__metadata = {
477
+ type: "SP.Data." + context.listName + "ListItem"
478
+ };
479
+ url = "_api/lists/getbytitle('" + context.listName + "')/getItemById('" + id + "')";
480
+ _context.n = 3;
481
+ return context.instance({
482
+ url: url,
483
+ method: 'POST',
484
+ data: JSON.stringify(data),
485
+ headers: {
486
+ 'X-RequestDigest': formDigestValue,
487
+ 'IF-MATCH': '*',
488
+ 'X-Http-Method': 'PATCH'
489
+ }
490
+ });
491
+ case 3:
492
+ response = _context.v;
493
+ return _context.a(2, response);
494
+ }
495
+ }, _callee);
496
+ }));
497
+ return _updateListItem.apply(this, arguments);
498
+ }
499
+
500
+ function sendEmail(_x, _x2) {
501
+ return _sendEmail.apply(this, arguments);
502
+ }
503
+ function _sendEmail() {
504
+ _sendEmail = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
505
+ var From, To, Subject, Body, httpRequest, response, _t, _t2, _t3, _t4, _t5;
506
+ return _regenerator().w(function (_context) {
507
+ while (1) switch (_context.n) {
508
+ case 0:
509
+ From = _ref.From, To = _ref.To, Subject = _ref.Subject, Body = _ref.Body;
510
+ httpRequest = '_api/SP.Utilities.Utility.SendEmail';
511
+ _t = context;
512
+ _t2 = httpRequest;
513
+ _context.n = 1;
514
+ return fetchDigest(context.instance, context.baseURL);
515
+ case 1:
516
+ _t3 = _context.v;
517
+ _t4 = {
518
+ 'X-RequestDigest': _t3,
519
+ 'X-Http-Method': 'POST',
520
+ 'Content-Type': 'application/json;odata=verbose'
521
+ };
522
+ _t5 = JSON.stringify({
523
+ properties: {
524
+ __metadata: {
525
+ type: 'SP.Utilities.EmailProperties'
526
+ },
527
+ From: From,
528
+ To: {
529
+ results: Array.isArray(To) ? To : [To]
530
+ },
531
+ Body: Body,
532
+ Subject: Subject
533
+ }
534
+ });
535
+ _context.n = 2;
536
+ return _t.instance.call(_t, {
537
+ url: _t2,
538
+ method: 'POST',
539
+ headers: _t4,
540
+ data: _t5
541
+ });
542
+ case 2:
543
+ response = _context.v;
544
+ return _context.a(2, response);
545
+ }
546
+ }, _callee);
547
+ }));
548
+ return _sendEmail.apply(this, arguments);
549
+ }
550
+
551
+ function typeAhead(_x, _x2, _x3) {
552
+ return _typeAhead.apply(this, arguments);
553
+ }
554
+ function _typeAhead() {
555
+ _typeAhead = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, input, filter) {
556
+ var requestUrl, data, response;
557
+ return _regenerator().w(function (_context) {
558
+ while (1) switch (_context.n) {
559
+ case 0:
560
+ requestUrl = "_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";
561
+ data = {
562
+ queryParams: {
563
+ __metadata: {
564
+ type: 'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
565
+ },
566
+ AllowEmailAddresses: true,
567
+ AllowMultipleEntities: false,
568
+ AllUrlZones: false,
569
+ MaximumEntitySuggestions: 10,
570
+ PrincipalSource: 15,
571
+ PrincipalType: 1,
572
+ QueryString: input
573
+ }
574
+ };
575
+ if (filter) {
576
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
577
+ data.queryParams.RequiredProperties = [filter];
578
+ }
579
+ _context.n = 1;
580
+ return instance.post(requestUrl, JSON.stringify(data), {
581
+ headers: {
582
+ Accept: 'application/json; odata=verbose',
583
+ 'Content-Type': 'application/json;odata=verbose'
584
+ }
585
+ });
586
+ case 1:
587
+ response = _context.v;
588
+ return _context.a(2, response.data.d.ClientPeoplePickerSearchUser);
589
+ }
590
+ }, _callee);
591
+ }));
592
+ return _typeAhead.apply(this, arguments);
593
+ }
594
+ function currentUserProperties(_x4) {
595
+ return _currentUserProperties.apply(this, arguments);
596
+ }
597
+ function _currentUserProperties() {
598
+ _currentUserProperties = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(instance) {
599
+ var requestUrl, profile;
600
+ return _regenerator().w(function (_context2) {
601
+ while (1) switch (_context2.n) {
602
+ case 0:
603
+ requestUrl = '_api/sp.userprofiles.peoplemanager/getmyproperties';
604
+ _context2.n = 1;
605
+ return instance.get(requestUrl);
606
+ case 1:
607
+ profile = _context2.v;
608
+ profile = profile.data.d;
609
+ profile.UserProfileProperties.results.forEach(function (prop) {
610
+ if (prop.Key === 'FirstName') {
611
+ profile.FirstName = prop.Value;
612
+ }
613
+ if (prop.Key === 'LastName') {
614
+ profile.LastName = prop.Value;
615
+ }
616
+ if (prop.Key === 'Country') {
617
+ profile.Country = prop.Value;
618
+ }
619
+ if (prop.Key === 'UserName') {
620
+ profile.UserName = prop.Value;
621
+ }
622
+ });
623
+ return _context2.a(2, profile);
624
+ }
625
+ }, _callee2);
626
+ }));
627
+ return _currentUserProperties.apply(this, arguments);
628
+ }
629
+ function getSiteUser(_x5, _x6) {
630
+ return _getSiteUser.apply(this, arguments);
631
+ }
632
+ function _getSiteUser() {
633
+ _getSiteUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(instance, searchValue) {
634
+ var requestUrl, response;
635
+ return _regenerator().w(function (_context3) {
636
+ while (1) switch (_context3.n) {
637
+ case 0:
638
+ requestUrl = "_api/web/siteusers?&$filter=substringof('" + searchValue + "', Title) or substringof('" + searchValue + "', LoginName) or substringof('" + searchValue + "', Email)&$top=50&$expand=Groups";
639
+ _context3.n = 1;
640
+ return instance.get(requestUrl);
641
+ case 1:
642
+ response = _context3.v;
643
+ return _context3.a(2, response.data.d);
644
+ }
645
+ }, _callee3);
646
+ }));
647
+ return _getSiteUser.apply(this, arguments);
648
+ }
649
+ function roleDefinitions(_x7) {
650
+ return _roleDefinitions.apply(this, arguments);
651
+ }
652
+ function _roleDefinitions() {
653
+ _roleDefinitions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(instance) {
654
+ var requestUrl, response;
655
+ return _regenerator().w(function (_context4) {
656
+ while (1) switch (_context4.n) {
657
+ case 0:
658
+ requestUrl = "_api/Web/RoleDefinitions";
659
+ _context4.n = 1;
660
+ return instance.get(requestUrl);
661
+ case 1:
662
+ response = _context4.v;
663
+ return _context4.a(2, response.data.d.results);
664
+ }
665
+ }, _callee4);
666
+ }));
667
+ return _roleDefinitions.apply(this, arguments);
668
+ }
669
+ function getEffectiveBasePermissions(_x8) {
670
+ return _getEffectiveBasePermissions.apply(this, arguments);
671
+ }
672
+ function _getEffectiveBasePermissions() {
673
+ _getEffectiveBasePermissions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(instance) {
674
+ var requestUrl, response;
675
+ return _regenerator().w(function (_context5) {
676
+ while (1) switch (_context5.n) {
677
+ case 0:
678
+ requestUrl = "_api/Web/effectiveBasePermissions";
679
+ _context5.n = 1;
680
+ return instance.get(requestUrl);
681
+ case 1:
682
+ response = _context5.v;
683
+ return _context5.a(2, response.data.d.EffectiveBasePermissions);
684
+ }
685
+ }, _callee5);
686
+ }));
687
+ return _getEffectiveBasePermissions.apply(this, arguments);
688
+ }
689
+ function currentUserPermissions(_x9) {
690
+ return _currentUserPermissions.apply(this, arguments);
691
+ }
692
+ function _currentUserPermissions() {
693
+ _currentUserPermissions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(context) {
694
+ var _yield$getEffectiveBa, High, definitions, result;
695
+ return _regenerator().w(function (_context6) {
696
+ while (1) switch (_context6.n) {
697
+ case 0:
698
+ _context6.n = 1;
699
+ return getEffectiveBasePermissions(context.instance);
700
+ case 1:
701
+ _yield$getEffectiveBa = _context6.v;
702
+ High = _yield$getEffectiveBa.High;
703
+ _context6.n = 2;
704
+ return roleDefinitions(context.instance);
705
+ case 2:
706
+ definitions = _context6.v;
707
+ result = definitions.find(function (_ref) {
708
+ var BasePermissions = _ref.BasePermissions;
709
+ return BasePermissions.High === High;
710
+ });
711
+ return _context6.a(2, result);
712
+ }
713
+ }, _callee6);
714
+ }));
715
+ return _currentUserPermissions.apply(this, arguments);
716
+ }
717
+
170
718
  var HTTPSharePointRequests = /*#__PURE__*/function () {
171
- /**
172
- * Creates an HTTP SharePoint requester bound to the provided base URL.
173
- *
174
- * @param baseURL The root SharePoint site URL (with or without trailing slash).
175
- * @param config Optional axios configuration overrides.
176
- */
177
719
  function HTTPSharePointRequests(baseURL, config) {
178
720
  var _this = this;
179
721
  this.lists = {
180
- /**
181
- * Fetches all SharePoint lists available to the current site.
182
- *
183
- * @returns Promise resolving to the list collection response payload.
184
- */
185
722
  get: function get() {
186
723
  _this.endpoint = '_api/web/lists';
187
- return _this.get_v2();
724
+ _this.sharepointVersion = '2013';
725
+ return getListItems(_this.getContext());
188
726
  }
189
727
  };
190
728
  this.folders = {
191
- /**
192
- * Retrieves SharePoint folders from the default folders endpoint.
193
- *
194
- * @returns A promise resolving with folder metadata.
195
- */
196
729
  get: function get() {
197
730
  _this.endpoint = '_api/web/folders';
198
- _this.get_v2();
731
+ _this.sharepointVersion = '2013';
732
+ getListItems(_this.getContext());
199
733
  }
200
734
  };
201
735
  this.email = {
202
- /**
203
- * Sends an email using SharePoint's Utility.SendEmail API.
204
- *
205
- * @param {EmailProps} param0 - The email properties.
206
- * @param {string} param0.From - The sender's email address.
207
- * @example
208
- * Example of a sender's email address
209
- * "sender@example.com"
210
- * @param {string | string[]} param0.To - The recipient's email address or an array of email addresses.
211
- * @example
212
- * Example of a single recipient's email address
213
- * "recipient@example.com"
214
- * Example of multiple recipients' email addresses
215
- * ["recipient1@example.com", "recipient2@example.com"]
216
- * @param {string} param0.Subject - The subject of the email.
217
- * @example
218
- * Example of an email subject
219
- * "Meeting Reminder"
220
- * @param {string} param0.Body - The body content of the email.
221
- * @example
222
- * Example of an email body
223
- * "Dear team, please be reminded of the meeting scheduled for tomorrow at 10 AM."
224
- * @returns {Promise<any>} - A promise that resolves to the response of the email send request.
225
- */
226
736
  send: function send(props) {
227
- return _this.sendEmail(props);
737
+ _this.sharepointVersion = '2013';
738
+ return sendEmail(_this.getContext(), props);
228
739
  }
229
740
  };
230
741
  this.user = {
231
- /**
232
- * Provides accessors for the current user's profile information.
233
- *
234
- * @returns Helper exposing a `get` function to retrieve profile details.
235
- */
236
742
  properties: function properties() {
237
743
  return {
238
744
  get: function get() {
239
- return _this.currentUserProperties();
745
+ _this.sharepointVersion = '2013';
746
+ return currentUserProperties(_this.instance);
240
747
  }
241
748
  };
242
749
  },
243
- /**
244
- * Searches across site users and their groups.
245
- *
246
- * @param searchValue Query string to match site users.
247
- * @returns Promise resolving to matching site users.
248
- */
249
750
  searchSiteUser: function searchSiteUser(searchValue) {
250
- return _this.getSiteUser(searchValue);
751
+ _this.sharepointVersion = '2013';
752
+ return getSiteUser(_this.instance, searchValue);
251
753
  },
252
- /**
253
- * Performs a people-picker search scoped to the current site collection.
254
- *
255
- * @param input Search prefix.
256
- * @param filter Optional additional filter condition.
257
- * @returns Promise with type-ahead person results.
258
- */
259
754
  searchUser: function searchUser(input, filter) {
260
- return _this.typeAhead(input, filter);
755
+ _this.sharepointVersion = '2013';
756
+ return typeAhead(_this.instance, input, filter);
261
757
  },
262
- /**
263
- * Fetches the currently authenticated SharePoint user.
264
- *
265
- * @returns Helper exposing `get` that resolves to the current user payload.
266
- */
267
758
  current: function current() {
268
759
  _this.endpoint = '_api/web/currentUser';
760
+ _this.sharepointVersion = '2013';
269
761
  return {
270
762
  get: function get() {
271
- return _this.get_only();
763
+ return getOnly(_this.instance, _this.endpoint);
272
764
  }
273
765
  };
274
766
  },
275
- /**
276
- * Retrieves calculated permission level for the current user.
277
- *
278
- * @returns Helper exposing `get` resolving to the user's permission definition.
279
- */
280
767
  currentPermission: function currentPermission() {
281
768
  return {
282
769
  get: function get() {
283
- return _this.currentUserPermissions();
770
+ _this.sharepointVersion = '2013';
771
+ return currentUserPermissions(_this.getContext());
284
772
  }
285
773
  };
286
774
  }
@@ -289,25 +777,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
289
777
  this.endpoint = '/api';
290
778
  this.listName = '';
291
779
  this.instance = instance(this.baseURL, config);
780
+ this.sharepointVersion = '2013';
292
781
  }
293
- /**
294
- * Converts array values in a payload to the `Collection(Edm.String)` structure
295
- * expected by SharePoint REST endpoints.
296
- *
297
- * @param data The list item payload to harmonise in-place.
298
- */
299
782
  var _proto = HTTPSharePointRequests.prototype;
300
- _proto.transformArraysToEdmStrings = function transformArraysToEdmStrings(data) {
301
- for (var key in data) {
302
- if (Array.isArray(data[key])) {
303
- data[key] = {
304
- __metadata: {
305
- type: 'Collection(Edm.String)'
306
- },
307
- results: data[key]
308
- };
309
- }
310
- }
783
+ _proto.getContext = function getContext() {
784
+ return {
785
+ instance: this.instance,
786
+ baseURL: this.baseURL,
787
+ endpoint: this.endpoint,
788
+ listName: this.listName,
789
+ sharepointVersion: this.sharepointVersion
790
+ };
311
791
  }
312
792
  /**
313
793
  * @deprecated Use `from` instead.
@@ -315,55 +795,44 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
315
795
  _proto.list = function list(listName) {
316
796
  this.listName = listName;
317
797
  this.endpoint = "_vti_bin/ListData.svc/" + listName;
798
+ this.sharepointVersion = '2010';
318
799
  return this;
319
- }
320
- /**
321
- * Selects a SharePoint list and exposes list-scoped CRUD helpers.
322
- *
323
- * @param listName Logical list key configured in the generic type map.
324
- * @param sharepoint_ver SharePoint version used to choose the correct REST endpoint.
325
- * @returns Chainable helpers bound to the selected list.
326
- */;
800
+ };
327
801
  _proto.from = function from(listName, sharepoint_ver) {
328
802
  var _this2 = this;
329
- if (sharepoint_ver === void 0) {
330
- sharepoint_ver = '2013';
331
- }
803
+ var version = sharepoint_ver != null ? sharepoint_ver : '2013';
332
804
  this.listName = listName;
333
- this.endpoint = sharepoint_ver === '2013' ? "_api/web/lists/GetByTitle('" + this.listName + "')/items" : "_vti_bin/ListData.svc/" + listName;
805
+ this.sharepointVersion = version;
806
+ this.endpoint = version === '2013' ? "_api/web/lists/GetByTitle('" + this.listName + "')/items" : "_vti_bin/ListData.svc/" + listName;
807
+ var getContext = function getContext() {
808
+ return _this2.getContext();
809
+ };
334
810
  return {
335
811
  create: function create(data) {
336
- return _this2.create_v2(data);
812
+ return createListItem(getContext(), data);
337
813
  },
338
814
  get: function get(options) {
339
- return _this2.get_v2(options);
815
+ return getListItems(getContext(), options);
340
816
  },
341
817
  update: function update(id, data, digest) {
342
- return _this2.update_2(id, data, digest);
818
+ return updateListItem(getContext(), id, data, digest);
343
819
  },
344
820
  "delete": function _delete(id) {
345
- return _this2["delete"](id);
821
+ return deleteItem(getContext(), id);
346
822
  },
347
823
  createFile: function createFile(props) {
348
- return _this2.createFile(props);
824
+ return createAttachment(getContext(), props);
349
825
  },
350
826
  fields: function fields(options) {
351
- // return this.field_v2(options)
352
827
  _this2.endpoint = !(options != null && options.fieldName) ? "_api/web/lists/GetByTitle('" + _this2.listName + "')/fields" : "_api/web/lists/GetByTitle('" + _this2.listName + "')/fields/getbytitle('" + options.fieldName + "')";
353
828
  return {
354
829
  get: function get() {
355
- return _this2.get_only(options);
830
+ return getOnly(_this2.instance, _this2.endpoint, options);
356
831
  }
357
832
  };
358
833
  }
359
834
  };
360
- }
361
- /**
362
- * Targets a SharePoint folder path and exposes file retrieval helpers.
363
- *
364
- * @param folderName Optional folder path relative to `Shared Documents`.
365
- * @returns Helper exposing `get` to fetch files or sub-folders.
366
- */;
835
+ };
367
836
  _proto.folder = function folder(folderName) {
368
837
  var _this3 = this;
369
838
  var filePath = ['Shared Documents'];
@@ -371,659 +840,31 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
371
840
  filePath = Array.isArray(folderName) ? [].concat(filePath, folderName) : [].concat(filePath, [folderName]);
372
841
  }
373
842
  this.endpoint = "_api/web/GetFolderByServerRelativeUrl('" + filePath.join('/') + "')";
843
+ this.sharepointVersion = '2013';
844
+ var getContext = function getContext() {
845
+ return _this3.getContext();
846
+ };
374
847
  return {
375
- /**
376
- * Fetches files or folders from the targeted path.
377
- *
378
- * @param options Optional REST query options to refine the result set.
379
- * @returns Promise resolving to folder contents and metadata.
380
- */
381
848
  get: function get(options) {
382
849
  if (!(options != null && options.type)) {
383
850
  _this3.endpoint += '/Files';
384
851
  } else {
385
852
  _this3.endpoint += "/" + options.type;
386
853
  }
387
- return _this3.get_files(options);
854
+ return getFiles(getContext(), options);
388
855
  }
389
856
  };
390
- }
391
- /**
392
- * Retrieves user list items and exposes a get helper with optional query parameters.
393
- *
394
- * @param options Optional REST query options.
395
- * @returns Helper exposing `get` returning SharePoint user rows.
396
- */;
857
+ };
397
858
  _proto.users = function users(options) {
398
859
  var _this4 = this;
399
860
  this.endpoint = '_api/web/SiteUserInfoList/items';
861
+ this.sharepointVersion = '2013';
400
862
  return {
401
- /**
402
- * Executes the user list request using the specified options.
403
- *
404
- * @returns Promise resolving to the SharePoint user list response.
405
- */
406
863
  get: function get() {
407
- return _this4.get_v2(options);
864
+ return getListItems(_this4.getContext(), options);
408
865
  }
409
866
  };
410
- }
411
- /**
412
- * Asynchronously retrieves the Form Digest Value from the context information API.
413
- *
414
- * @returns {Promise<string>} A promise that resolves to the Form Digest Value.
415
- * @throws {Error} If the HTTP request fails or the response does not contain the expected data.
416
- */;
417
- _proto.getDigest =
418
- /*#__PURE__*/
419
- function () {
420
- var _getDigest = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
421
- var _response$data, response, _t;
422
- return _regenerator().w(function (_context) {
423
- while (1) switch (_context.p = _context.n) {
424
- case 0:
425
- _context.p = 0;
426
- _context.n = 1;
427
- return this.instance.post(this.baseURL + "_api/contextinfo");
428
- case 1:
429
- response = _context.v;
430
- if ((_response$data = response.data) != null && (_response$data = _response$data.d) != null && (_response$data = _response$data.GetContextWebInformation) != null && _response$data.FormDigestValue) {
431
- _context.n = 2;
432
- break;
433
- }
434
- throw new Error('Invalid response structure: Missing FormDigestValue');
435
- case 2:
436
- return _context.a(2, response.data.d.GetContextWebInformation.FormDigestValue);
437
- case 3:
438
- _context.p = 3;
439
- _t = _context.v;
440
- console.error('Failed to retrieve the Form Digest Value:', _t);
441
- throw new Error("Error retrieving Form Digest Value");
442
- case 4:
443
- return _context.a(2);
444
- }
445
- }, _callee, this, [[0, 3]]);
446
- }));
447
- function getDigest() {
448
- return _getDigest.apply(this, arguments);
449
- }
450
- return getDigest;
451
- }()
452
- /**
453
- * Executes a GET request without additional metadata wrapping.
454
- *
455
- * @param options Optional REST query options.
456
- * @returns SharePoint response payload or undefined when empty.
457
- */
458
- ;
459
- _proto.get_only =
460
- /*#__PURE__*/
461
- function () {
462
- var _get_only = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
463
- var _ref, expand, orderBy, limit, filter, cols, skip, params, _yield$this$instance$, data;
464
- return _regenerator().w(function (_context2) {
465
- while (1) switch (_context2.n) {
466
- case 0:
467
- _ref = options || {}, expand = _ref.expand, orderBy = _ref.orderBy, limit = _ref.limit, filter = _ref.filter, cols = _ref.cols, skip = _ref.skip;
468
- params = {
469
- $expand: Array.isArray(expand) ? expand.join(',') : expand,
470
- $top: limit,
471
- $skip: skip,
472
- $select: Array.isArray(cols) ? cols.join(',') : cols,
473
- $filter: filter,
474
- $orderby: Array.isArray(orderBy) ? orderBy.join(',') : orderBy
475
- };
476
- _context2.n = 1;
477
- return this.instance.get(this.endpoint, {
478
- params: params
479
- });
480
- case 1:
481
- _yield$this$instance$ = _context2.v;
482
- data = _yield$this$instance$.data;
483
- if (!data) {
484
- _context2.n = 2;
485
- break;
486
- }
487
- return _context2.a(2, data.d.results ? data.d.results : data.d);
488
- case 2:
489
- return _context2.a(2);
490
- }
491
- }, _callee2, this);
492
- }));
493
- function get_only(_x) {
494
- return _get_only.apply(this, arguments);
495
- }
496
- return get_only;
497
- }()
498
- /**
499
- * Retrieves folder contents with optional filtering and returns the payload with metadata.
500
- *
501
- * @param options REST options describing expand/filter/order conditions.
502
- * @returns Folder data and the fully resolved request URL.
503
- */
504
- ;
505
- _proto.get_files =
506
- /*#__PURE__*/
507
- function () {
508
- var _get_files = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
509
- var _ref2, expand, orderBy, limit, filter, cols, skip, params, url, response, data, meta;
510
- return _regenerator().w(function (_context3) {
511
- while (1) switch (_context3.n) {
512
- case 0:
513
- _ref2 = options || {}, expand = _ref2.expand, orderBy = _ref2.orderBy, limit = _ref2.limit, filter = _ref2.filter, cols = _ref2.cols, skip = _ref2.skip;
514
- params = {
515
- $expand: Array.isArray(expand) ? expand.join(',') : expand,
516
- $top: limit,
517
- $skip: skip,
518
- $select: Array.isArray(cols) ? cols.join(',') : cols,
519
- $filter: filter,
520
- $orderby: Array.isArray(orderBy) ? orderBy.join(',') : orderBy
521
- };
522
- url = new URL(this.endpoint, this.instance.defaults.baseURL);
523
- Object.entries(params).forEach(function (_ref3) {
524
- var key = _ref3[0],
525
- value = _ref3[1];
526
- if (value !== undefined && value !== null) {
527
- url.searchParams.append(key, String(value));
528
- }
529
- });
530
- _context3.n = 1;
531
- return this.instance.request({
532
- url: this.endpoint,
533
- method: 'GET',
534
- params: params
535
- });
536
- case 1:
537
- response = _context3.v;
538
- data = limit || !response.data.d.results ? response.data.d : response.data.d.results;
539
- meta = {
540
- url: url
541
- };
542
- return _context3.a(2, {
543
- data: data,
544
- meta: meta
545
- });
546
- }
547
- }, _callee3, this);
548
- }));
549
- function get_files(_x2) {
550
- return _get_files.apply(this, arguments);
551
- }
552
- return get_files;
553
- }()
554
- /**
555
- * Performs a typed list read against the current endpoint.
556
- *
557
- * @param options Optional REST query options governing expand, filter, ordering and pagination.
558
- * @returns SharePoint list items alongside the fully-resolved request URL.
559
- */
560
- ;
561
- _proto.get_v2 =
562
- /*#__PURE__*/
563
- function () {
564
- var _get_v = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(options) {
565
- var _ref4, expand, orderBy, limit, filter, cols, skip, params, url, response, data, meta;
566
- return _regenerator().w(function (_context4) {
567
- while (1) switch (_context4.n) {
568
- case 0:
569
- _ref4 = options || {}, expand = _ref4.expand, orderBy = _ref4.orderBy, limit = _ref4.limit, filter = _ref4.filter, cols = _ref4.cols, skip = _ref4.skip;
570
- params = {
571
- $expand: Array.isArray(expand) ? expand.join(',') : expand,
572
- $top: limit,
573
- $skip: skip,
574
- $select: Array.isArray(cols) ? cols.join(',') : cols,
575
- $filter: filter,
576
- $orderby: Array.isArray(orderBy) ? orderBy.join(' ') : orderBy
577
- };
578
- url = new URL(this.endpoint, this.instance.defaults.baseURL);
579
- Object.entries(params).forEach(function (_ref5) {
580
- var key = _ref5[0],
581
- value = _ref5[1];
582
- if (value !== undefined && value !== null) {
583
- url.searchParams.append(key, String(value));
584
- }
585
- });
586
- _context4.n = 1;
587
- return this.instance.request({
588
- url: this.endpoint,
589
- method: 'GET',
590
- params: params
591
- });
592
- case 1:
593
- response = _context4.v;
594
- data = limit || !response.data.d.results ? response.data.d : response.data.d.results;
595
- meta = {
596
- url: url
597
- };
598
- return _context4.a(2, {
599
- data: data,
600
- meta: meta
601
- });
602
- }
603
- }, _callee4, this);
604
- }));
605
- function get_v2(_x3) {
606
- return _get_v.apply(this, arguments);
607
- }
608
- return get_v2;
609
- }()
610
- /**
611
- * Updates an item in the currently selected list.
612
- *
613
- * @param id Target list item identifier.
614
- * @param data Payload with fields to update.
615
- * @param digest Optional pre-fetched form digest to reuse.
616
- * @returns Axios response of the update request.
617
- */
618
- ;
619
- _proto.update_2 =
620
- /*#__PURE__*/
621
- function () {
622
- var _update_ = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(id, data, digest) {
623
- var formDigestValue, url, response, _t2;
624
- return _regenerator().w(function (_context5) {
625
- while (1) switch (_context5.n) {
626
- case 0:
627
- _t2 = digest;
628
- if (_t2) {
629
- _context5.n = 2;
630
- break;
631
- }
632
- _context5.n = 1;
633
- return this.getDigest();
634
- case 1:
635
- _t2 = _context5.v;
636
- case 2:
637
- formDigestValue = _t2;
638
- data.__metadata = {
639
- type: "SP.Data." + this.listName + "ListItem"
640
- };
641
- url = "_api/lists/getbytitle('" + this.listName + "')/getItemById('" + id + "')";
642
- _context5.n = 3;
643
- return this.instance({
644
- url: url,
645
- method: 'POST',
646
- data: JSON.stringify(data),
647
- headers: {
648
- 'X-RequestDigest': formDigestValue,
649
- 'IF-MATCH': '*',
650
- 'X-Http-Method': 'PATCH'
651
- }
652
- });
653
- case 3:
654
- response = _context5.v;
655
- return _context5.a(2, response);
656
- }
657
- }, _callee5, this);
658
- }));
659
- function update_2(_x4, _x5, _x6) {
660
- return _update_.apply(this, arguments);
661
- }
662
- return update_2;
663
- }()
664
- /**
665
- * Creates a new item within the active list.
666
- *
667
- * @param listData SharePoint list item payload.
668
- * @returns Axios response resolved from the create request.
669
- */
670
- ;
671
- _proto.create_v2 =
672
- /*#__PURE__*/
673
- function () {
674
- var _create_v = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(listData) {
675
- var response, _t3, _t4, _t5, _t6, _t7;
676
- return _regenerator().w(function (_context6) {
677
- while (1) switch (_context6.n) {
678
- case 0:
679
- this.transformArraysToEdmStrings(listData);
680
- listData.__metadata = {
681
- type: "SP.Data." + this.listName + "ListItem"
682
- };
683
- _t3 = this;
684
- _t4 = this.endpoint;
685
- _t5 = JSON.stringify(listData);
686
- _context6.n = 1;
687
- return this.getDigest();
688
- case 1:
689
- _t6 = _context6.v;
690
- _t7 = {
691
- 'X-RequestDigest': _t6,
692
- 'IF-MATCH': '*'
693
- };
694
- _context6.n = 2;
695
- return _t3.instance.call(_t3, {
696
- url: _t4,
697
- method: 'POST',
698
- data: _t5,
699
- headers: _t7
700
- });
701
- case 2:
702
- response = _context6.v;
703
- return _context6.a(2, response);
704
- }
705
- }, _callee6, this);
706
- }));
707
- function create_v2(_x7) {
708
- return _create_v.apply(this, arguments);
709
- }
710
- return create_v2;
711
- }()
712
- /**
713
- * Uploads an attachment file to an existing list item.
714
- *
715
- * @param props File payload and target item identifier.
716
- * @returns Axios response describing the upload result.
717
- */
718
- ;
719
- _proto.createFile =
720
- /*#__PURE__*/
721
- function () {
722
- var _createFile = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(_ref6) {
723
- var file, itemId, requestUrl, res, _t8, _t9, _t0, _t1, _t10;
724
- return _regenerator().w(function (_context7) {
725
- while (1) switch (_context7.n) {
726
- case 0:
727
- file = _ref6.file, itemId = _ref6.itemId;
728
- requestUrl = "_api/lists/getbytitle('" + this.listName + "')/items(" + itemId + ")/AttachmentFiles/add(FileName='" + file.name + "')";
729
- _t8 = this.instance;
730
- _t9 = requestUrl;
731
- _t0 = file;
732
- _context7.n = 1;
733
- return this.getDigest();
734
- case 1:
735
- _t1 = _context7.v;
736
- _t10 = {
737
- 'X-RequestDigest': _t1
738
- };
739
- _context7.n = 2;
740
- return _t8.post.call(_t8, _t9, _t0, {
741
- headers: _t10,
742
- withCredentials: true
743
- });
744
- case 2:
745
- res = _context7.v;
746
- return _context7.a(2, res);
747
- }
748
- }, _callee7, this);
749
- }));
750
- function createFile(_x8) {
751
- return _createFile.apply(this, arguments);
752
- }
753
- return createFile;
754
- }()
755
- /**
756
- * Deletes an item using the current endpoint.
757
- *
758
- * @param ID Identifier of the entity to remove.
759
- * @returns Axios response from the delete call.
760
- */
761
- ;
762
- _proto["delete"] =
763
- /*#__PURE__*/
764
- function () {
765
- var _delete2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(ID) {
766
- var response;
767
- return _regenerator().w(function (_context8) {
768
- while (1) switch (_context8.n) {
769
- case 0:
770
- _context8.n = 1;
771
- return this.instance["delete"](this.endpoint + "(" + ID + ")");
772
- case 1:
773
- response = _context8.v;
774
- return _context8.a(2, response);
775
- }
776
- }, _callee8, this);
777
- }));
778
- function _delete(_x9) {
779
- return _delete2.apply(this, arguments);
780
- }
781
- return _delete;
782
- }();
783
- _proto.sendEmail = /*#__PURE__*/function () {
784
- var _sendEmail = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(_ref7) {
785
- var From, To, Subject, Body, httpRequest, response, _t11, _t12, _t13, _t14, _t15;
786
- return _regenerator().w(function (_context9) {
787
- while (1) switch (_context9.n) {
788
- case 0:
789
- From = _ref7.From, To = _ref7.To, Subject = _ref7.Subject, Body = _ref7.Body;
790
- httpRequest = '_api/SP.Utilities.Utility.SendEmail';
791
- _t11 = this;
792
- _t12 = httpRequest;
793
- _context9.n = 1;
794
- return this.getDigest();
795
- case 1:
796
- _t13 = _context9.v;
797
- _t14 = {
798
- 'X-RequestDigest': _t13,
799
- 'X-Http-Method': 'POST',
800
- 'Content-Type': 'application/json;odata=verbose'
801
- };
802
- _t15 = JSON.stringify({
803
- properties: {
804
- __metadata: {
805
- type: 'SP.Utilities.EmailProperties'
806
- },
807
- From: From,
808
- To: {
809
- results: Array.isArray(To) ? To : [To]
810
- },
811
- Body: Body,
812
- Subject: Subject
813
- }
814
- });
815
- _context9.n = 2;
816
- return _t11.instance.call(_t11, {
817
- url: _t12,
818
- method: 'POST',
819
- headers: _t14,
820
- data: _t15
821
- });
822
- case 2:
823
- response = _context9.v;
824
- return _context9.a(2, response);
825
- }
826
- }, _callee9, this);
827
- }));
828
- function sendEmail(_x0) {
829
- return _sendEmail.apply(this, arguments);
830
- }
831
- return sendEmail;
832
- }()
833
- /**
834
- * Queries SharePoint's people picker endpoint for matching users.
835
- *
836
- * @param input Free-text search term.
837
- * @param filter Optional additional filter condition.
838
- * @returns Promise with type-ahead results payload.
839
- */
840
- ;
841
- _proto.typeAhead =
842
- /*#__PURE__*/
843
- function () {
844
- var _typeAhead = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(input, filter) {
845
- var filterValue, response;
846
- return _regenerator().w(function (_context0) {
847
- while (1) switch (_context0.n) {
848
- case 0:
849
- filterValue = filter ? " and " + filter : '';
850
- _context0.n = 1;
851
- return this.instance.get("_vti_bin/listdata.svc/UserInformationList?$top=10&$filter=substringof('" + input + "',Name) or substringof('" + input + "',WorkEmail)" + filterValue);
852
- case 1:
853
- response = _context0.v;
854
- return _context0.a(2, response.data.d);
855
- }
856
- }, _callee0, this);
857
- }));
858
- function typeAhead(_x1, _x10) {
859
- return _typeAhead.apply(this, arguments);
860
- }
861
- return typeAhead;
862
- }()
863
- /**
864
- * Retrieves the current user profile and flattens selected properties.
865
- *
866
- * @returns Promise containing the current user's profile information.
867
- */
868
- ;
869
- _proto.currentUserProperties =
870
- /*#__PURE__*/
871
- function () {
872
- var _currentUserProperties = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
873
- var requestUrl, profile;
874
- return _regenerator().w(function (_context1) {
875
- while (1) switch (_context1.n) {
876
- case 0:
877
- requestUrl = '_api/sp.userprofiles.peoplemanager/getmyproperties';
878
- _context1.n = 1;
879
- return this.instance.get(requestUrl);
880
- case 1:
881
- profile = _context1.v;
882
- profile = profile.data.d;
883
- profile.UserProfileProperties.results.forEach(function (prop) {
884
- if (prop.Key === 'FirstName') {
885
- profile.FirstName = prop.Value;
886
- }
887
- if (prop.Key === 'LastName') {
888
- profile.LastName = prop.Value;
889
- }
890
- if (prop.Key === 'Country') {
891
- profile.Country = prop.Value;
892
- }
893
- if (prop.Key === 'UserName') {
894
- profile.UserName = prop.Value;
895
- }
896
- });
897
- return _context1.a(2, profile);
898
- }
899
- }, _callee1, this);
900
- }));
901
- function currentUserProperties() {
902
- return _currentUserProperties.apply(this, arguments);
903
- }
904
- return currentUserProperties;
905
- }()
906
- /**
907
- * Searches site users based on a substring match across common fields.
908
- *
909
- * @param searchValue Term to match against the SharePoint user directory.
910
- * @returns Promise with matching site users and their groups.
911
- */
912
- ;
913
- _proto.getSiteUser =
914
- /*#__PURE__*/
915
- function () {
916
- var _getSiteUser = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(searchValue) {
917
- var requestUrl, response;
918
- return _regenerator().w(function (_context10) {
919
- while (1) switch (_context10.n) {
920
- case 0:
921
- requestUrl = "_api/web/siteusers?&$filter=substringof('" + searchValue + "', Title) or substringof('" + searchValue + "', LoginName) or substringof('" + searchValue + "', Email)&$top=50&$expand=Groups";
922
- _context10.n = 1;
923
- return this.instance.get(requestUrl);
924
- case 1:
925
- response = _context10.v;
926
- return _context10.a(2, response.data.d);
927
- }
928
- }, _callee10, this);
929
- }));
930
- function getSiteUser(_x11) {
931
- return _getSiteUser.apply(this, arguments);
932
- }
933
- return getSiteUser;
934
- }()
935
- /**
936
- * Retrieves all available role definitions for the current site.
937
- *
938
- * @returns Promise resolving to an array of role definitions.
939
- */
940
- ;
941
- _proto.roleDefinitions =
942
- /*#__PURE__*/
943
- function () {
944
- var _roleDefinitions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
945
- var requestUrl, response;
946
- return _regenerator().w(function (_context11) {
947
- while (1) switch (_context11.n) {
948
- case 0:
949
- requestUrl = "_api/Web/RoleDefinitions";
950
- _context11.n = 1;
951
- return this.instance.get(requestUrl);
952
- case 1:
953
- response = _context11.v;
954
- return _context11.a(2, response.data.d.results);
955
- }
956
- }, _callee11, this);
957
- }));
958
- function roleDefinitions() {
959
- return _roleDefinitions.apply(this, arguments);
960
- }
961
- return roleDefinitions;
962
- }()
963
- /**
964
- * Fetches the bit-encoded permissions of the current user.
965
- *
966
- * @returns Promise resolving to the `EffectiveBasePermissions` object.
967
- */
968
- ;
969
- _proto.getEffectiveBasePermissions =
970
- /*#__PURE__*/
971
- function () {
972
- var _getEffectiveBasePermissions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
973
- var requestUrl, response;
974
- return _regenerator().w(function (_context12) {
975
- while (1) switch (_context12.n) {
976
- case 0:
977
- requestUrl = "_api/Web/effectiveBasePermissions";
978
- _context12.n = 1;
979
- return this.instance.get(requestUrl);
980
- case 1:
981
- response = _context12.v;
982
- return _context12.a(2, response.data.d.EffectiveBasePermissions);
983
- }
984
- }, _callee12, this);
985
- }));
986
- function getEffectiveBasePermissions() {
987
- return _getEffectiveBasePermissions.apply(this, arguments);
988
- }
989
- return getEffectiveBasePermissions;
990
- }()
991
- /**
992
- * Matches the current user's effective permissions against known role definitions.
993
- *
994
- * @returns The matching SharePoint role definition as a structured permission object.
995
- */
996
- ;
997
- _proto.currentUserPermissions =
998
- /*#__PURE__*/
999
- function () {
1000
- var _currentUserPermissions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
1001
- var _yield$this$getEffect, High, roleDefinitions, result;
1002
- return _regenerator().w(function (_context13) {
1003
- while (1) switch (_context13.n) {
1004
- case 0:
1005
- _context13.n = 1;
1006
- return this.getEffectiveBasePermissions();
1007
- case 1:
1008
- _yield$this$getEffect = _context13.v;
1009
- High = _yield$this$getEffect.High;
1010
- _context13.n = 2;
1011
- return this.roleDefinitions();
1012
- case 2:
1013
- roleDefinitions = _context13.v;
1014
- result = roleDefinitions.find(function (_ref8) {
1015
- var BasePermissions = _ref8.BasePermissions;
1016
- return BasePermissions.High === High;
1017
- });
1018
- return _context13.a(2, result);
1019
- }
1020
- }, _callee13, this);
1021
- }));
1022
- function currentUserPermissions() {
1023
- return _currentUserPermissions.apply(this, arguments);
1024
- }
1025
- return currentUserPermissions;
1026
- }();
867
+ };
1027
868
  return HTTPSharePointRequests;
1028
869
  }();
1029
870