@lindle/sharepoint_requests 0.1.12 → 0.1.14

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 +596 -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 +596 -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 +35 -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,607 @@ 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
+ };
240
+ _context.n = 2;
241
+ return _t.instance.call(_t, {
242
+ url: _t2,
243
+ method: 'POST',
244
+ data: _t3,
245
+ headers: _t5
246
+ });
247
+ case 2:
248
+ response = _context.v;
249
+ return _context.a(2, response);
250
+ }
251
+ }, _callee);
252
+ }));
253
+ return _createListItem.apply(this, arguments);
254
+ }
255
+
256
+ function createAttachment(_x, _x2) {
257
+ return _createAttachment.apply(this, arguments);
258
+ }
259
+ function _createAttachment() {
260
+ _createAttachment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
261
+ var file, itemId, requestUrl, response, _t, _t2, _t3, _t4, _t5;
262
+ return _regenerator().w(function (_context) {
263
+ while (1) switch (_context.n) {
264
+ case 0:
265
+ file = _ref.file, itemId = _ref.itemId;
266
+ requestUrl = "_api/lists/getbytitle('" + context.listName + "')/items(" + itemId + ")/AttachmentFiles/add(FileName='" + file.name + "')";
267
+ _t = context.instance;
268
+ _t2 = requestUrl;
269
+ _t3 = file;
270
+ _context.n = 1;
271
+ return fetchDigest(context.instance, context.baseURL);
272
+ case 1:
273
+ _t4 = _context.v;
274
+ _t5 = {
275
+ 'X-RequestDigest': _t4
276
+ };
277
+ _context.n = 2;
278
+ return _t.post.call(_t, _t2, _t3, {
279
+ headers: _t5,
280
+ withCredentials: true
281
+ });
282
+ case 2:
283
+ response = _context.v;
284
+ return _context.a(2, response);
285
+ }
286
+ }, _callee);
287
+ }));
288
+ return _createAttachment.apply(this, arguments);
289
+ }
290
+
291
+ function deleteItem(_x, _x2) {
292
+ return _deleteItem.apply(this, arguments);
293
+ }
294
+ function _deleteItem() {
295
+ _deleteItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, id) {
296
+ var response;
297
+ return _regenerator().w(function (_context) {
298
+ while (1) switch (_context.n) {
299
+ case 0:
300
+ _context.n = 1;
301
+ return context.instance["delete"](context.endpoint + "(" + id + ")");
302
+ case 1:
303
+ response = _context.v;
304
+ return _context.a(2, response);
305
+ }
306
+ }, _callee);
307
+ }));
308
+ return _deleteItem.apply(this, arguments);
309
+ }
310
+
311
+ function buildODataParams(options, orderBySeparator) {
312
+ if (orderBySeparator === void 0) {
313
+ orderBySeparator = ',';
314
+ }
315
+ var _ref = options || {},
316
+ expand = _ref.expand,
317
+ orderBy = _ref.orderBy,
318
+ limit = _ref.limit,
319
+ filter = _ref.filter,
320
+ cols = _ref.cols,
321
+ skip = _ref.skip;
322
+ var params = {
323
+ $expand: Array.isArray(expand) ? expand.join(',') : expand,
324
+ $top: limit,
325
+ $skip: skip,
326
+ $select: Array.isArray(cols) ? cols.join(',') : cols,
327
+ $filter: filter,
328
+ $orderby: Array.isArray(orderBy) ? orderBy.join(orderBySeparator) : orderBy
329
+ };
330
+ return params;
331
+ }
332
+ function appendParamsToUrl(baseUrl, params) {
333
+ Object.entries(params).forEach(function (_ref2) {
334
+ var key = _ref2[0],
335
+ value = _ref2[1];
336
+ if (value !== undefined && value !== null) {
337
+ baseUrl.searchParams.append(key, String(value));
338
+ }
339
+ });
340
+ }
341
+
342
+ function getFiles(_x, _x2) {
343
+ return _getFiles.apply(this, arguments);
344
+ }
345
+ function _getFiles() {
346
+ _getFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, options) {
347
+ var params, url, response, data, meta;
348
+ return _regenerator().w(function (_context) {
349
+ while (1) switch (_context.n) {
350
+ case 0:
351
+ params = buildODataParams(options, ',');
352
+ url = new URL(context.endpoint, context.instance.defaults.baseURL);
353
+ appendParamsToUrl(url, params);
354
+ _context.n = 1;
355
+ return context.instance.request({
356
+ url: context.endpoint,
357
+ method: 'GET',
358
+ params: params
359
+ });
360
+ case 1:
361
+ response = _context.v;
362
+ data = options != null && options.limit || !response.data.d.results ? response.data.d : response.data.d.results;
363
+ meta = {
364
+ url: url
365
+ };
366
+ return _context.a(2, {
367
+ data: data,
368
+ meta: meta
369
+ });
370
+ }
371
+ }, _callee);
372
+ }));
373
+ return _getFiles.apply(this, arguments);
374
+ }
375
+
376
+ function getListItems(_x, _x2) {
377
+ return _getListItems.apply(this, arguments);
378
+ }
379
+ function _getListItems() {
380
+ _getListItems = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, options) {
381
+ var _ref, _response$data$d$resu, _response$data, _response$data2;
382
+ var params, url, response, rawData, cols, keys, filterItem, data, meta;
383
+ return _regenerator().w(function (_context) {
384
+ while (1) switch (_context.n) {
385
+ case 0:
386
+ params = buildODataParams(options, ' ');
387
+ url = new URL(context.endpoint, context.instance.defaults.baseURL);
388
+ appendParamsToUrl(url, params);
389
+ _context.n = 1;
390
+ return context.instance.request({
391
+ url: context.endpoint,
392
+ method: 'GET',
393
+ params: params
394
+ });
395
+ case 1:
396
+ response = _context.v;
397
+ 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;
398
+ cols = options == null ? void 0 : options.cols;
399
+ keys = cols ? (Array.isArray(cols) ? cols : [cols]).filter(Boolean) : undefined;
400
+ filterItem = function filterItem(item) {
401
+ if (!keys || !item || typeof item !== 'object') {
402
+ return item;
403
+ }
404
+ return keys.reduce(function (acc, key) {
405
+ if (key in item) {
406
+ acc[key] = item[key];
407
+ }
408
+ return acc;
409
+ }, {});
410
+ };
411
+ data = Array.isArray(rawData) ? rawData.map(filterItem) : filterItem(rawData);
412
+ meta = {
413
+ url: url
414
+ };
415
+ return _context.a(2, {
416
+ data: data,
417
+ meta: meta
418
+ });
419
+ }
420
+ }, _callee);
421
+ }));
422
+ return _getListItems.apply(this, arguments);
423
+ }
424
+
425
+ function getOnly(_x, _x2, _x3) {
426
+ return _getOnly.apply(this, arguments);
427
+ }
428
+ function _getOnly() {
429
+ _getOnly = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, endpoint, options) {
430
+ var params, _yield$instance$get, data;
431
+ return _regenerator().w(function (_context) {
432
+ while (1) switch (_context.n) {
433
+ case 0:
434
+ params = buildODataParams(options, ',');
435
+ _context.n = 1;
436
+ return instance.get(endpoint, {
437
+ params: params
438
+ });
439
+ case 1:
440
+ _yield$instance$get = _context.v;
441
+ data = _yield$instance$get.data;
442
+ if (!data) {
443
+ _context.n = 2;
444
+ break;
445
+ }
446
+ return _context.a(2, data.d.results ? data.d.results : data.d);
447
+ case 2:
448
+ return _context.a(2);
449
+ }
450
+ }, _callee);
451
+ }));
452
+ return _getOnly.apply(this, arguments);
453
+ }
454
+
455
+ function updateListItem(_x, _x2, _x3, _x4) {
456
+ return _updateListItem.apply(this, arguments);
457
+ }
458
+ function _updateListItem() {
459
+ _updateListItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, id, data, digest) {
460
+ var formDigestValue, url, response, _t;
461
+ return _regenerator().w(function (_context) {
462
+ while (1) switch (_context.n) {
463
+ case 0:
464
+ _t = digest;
465
+ if (_t) {
466
+ _context.n = 2;
467
+ break;
468
+ }
469
+ _context.n = 1;
470
+ return fetchDigest(context.instance, context.baseURL);
471
+ case 1:
472
+ _t = _context.v;
473
+ case 2:
474
+ formDigestValue = _t;
475
+ data.__metadata = {
476
+ type: "SP.Data." + context.listName + "ListItem"
477
+ };
478
+ url = "_api/lists/getbytitle('" + context.listName + "')/getItemById('" + id + "')";
479
+ _context.n = 3;
480
+ return context.instance({
481
+ url: url,
482
+ method: 'POST',
483
+ data: JSON.stringify(data),
484
+ headers: {
485
+ 'X-RequestDigest': formDigestValue,
486
+ 'IF-MATCH': '*',
487
+ 'X-Http-Method': 'PATCH'
488
+ }
489
+ });
490
+ case 3:
491
+ response = _context.v;
492
+ return _context.a(2, response);
493
+ }
494
+ }, _callee);
495
+ }));
496
+ return _updateListItem.apply(this, arguments);
497
+ }
498
+
499
+ function sendEmail(_x, _x2) {
500
+ return _sendEmail.apply(this, arguments);
501
+ }
502
+ function _sendEmail() {
503
+ _sendEmail = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
504
+ var From, To, Subject, Body, httpRequest, response, _t, _t2, _t3, _t4, _t5;
505
+ return _regenerator().w(function (_context) {
506
+ while (1) switch (_context.n) {
507
+ case 0:
508
+ From = _ref.From, To = _ref.To, Subject = _ref.Subject, Body = _ref.Body;
509
+ httpRequest = '_api/SP.Utilities.Utility.SendEmail';
510
+ _t = context;
511
+ _t2 = httpRequest;
512
+ _context.n = 1;
513
+ return fetchDigest(context.instance, context.baseURL);
514
+ case 1:
515
+ _t3 = _context.v;
516
+ _t4 = {
517
+ 'X-RequestDigest': _t3,
518
+ 'X-Http-Method': 'POST',
519
+ 'Content-Type': 'application/json;odata=verbose'
520
+ };
521
+ _t5 = JSON.stringify({
522
+ properties: {
523
+ __metadata: {
524
+ type: 'SP.Utilities.EmailProperties'
525
+ },
526
+ From: From,
527
+ To: {
528
+ results: Array.isArray(To) ? To : [To]
529
+ },
530
+ Body: Body,
531
+ Subject: Subject
532
+ }
533
+ });
534
+ _context.n = 2;
535
+ return _t.instance.call(_t, {
536
+ url: _t2,
537
+ method: 'POST',
538
+ headers: _t4,
539
+ data: _t5
540
+ });
541
+ case 2:
542
+ response = _context.v;
543
+ return _context.a(2, response);
544
+ }
545
+ }, _callee);
546
+ }));
547
+ return _sendEmail.apply(this, arguments);
548
+ }
549
+
550
+ function typeAhead(_x, _x2, _x3) {
551
+ return _typeAhead.apply(this, arguments);
552
+ }
553
+ function _typeAhead() {
554
+ _typeAhead = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, input, filter) {
555
+ var requestUrl, data, response;
556
+ return _regenerator().w(function (_context) {
557
+ while (1) switch (_context.n) {
558
+ case 0:
559
+ requestUrl = "_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";
560
+ data = {
561
+ queryParams: {
562
+ __metadata: {
563
+ type: 'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
564
+ },
565
+ AllowEmailAddresses: true,
566
+ AllowMultipleEntities: false,
567
+ AllUrlZones: false,
568
+ MaximumEntitySuggestions: 10,
569
+ PrincipalSource: 15,
570
+ PrincipalType: 1,
571
+ QueryString: input
572
+ }
573
+ };
574
+ if (filter) {
575
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
576
+ data.queryParams.RequiredProperties = [filter];
577
+ }
578
+ _context.n = 1;
579
+ return instance.post(requestUrl, JSON.stringify(data), {
580
+ headers: {
581
+ Accept: 'application/json; odata=verbose',
582
+ 'Content-Type': 'application/json;odata=verbose'
583
+ }
584
+ });
585
+ case 1:
586
+ response = _context.v;
587
+ return _context.a(2, response.data.d.ClientPeoplePickerSearchUser);
588
+ }
589
+ }, _callee);
590
+ }));
591
+ return _typeAhead.apply(this, arguments);
592
+ }
593
+ function currentUserProperties(_x4) {
594
+ return _currentUserProperties.apply(this, arguments);
595
+ }
596
+ function _currentUserProperties() {
597
+ _currentUserProperties = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(instance) {
598
+ var requestUrl, profile;
599
+ return _regenerator().w(function (_context2) {
600
+ while (1) switch (_context2.n) {
601
+ case 0:
602
+ requestUrl = '_api/sp.userprofiles.peoplemanager/getmyproperties';
603
+ _context2.n = 1;
604
+ return instance.get(requestUrl);
605
+ case 1:
606
+ profile = _context2.v;
607
+ profile = profile.data.d;
608
+ profile.UserProfileProperties.results.forEach(function (prop) {
609
+ if (prop.Key === 'FirstName') {
610
+ profile.FirstName = prop.Value;
611
+ }
612
+ if (prop.Key === 'LastName') {
613
+ profile.LastName = prop.Value;
614
+ }
615
+ if (prop.Key === 'Country') {
616
+ profile.Country = prop.Value;
617
+ }
618
+ if (prop.Key === 'UserName') {
619
+ profile.UserName = prop.Value;
620
+ }
621
+ });
622
+ return _context2.a(2, profile);
623
+ }
624
+ }, _callee2);
625
+ }));
626
+ return _currentUserProperties.apply(this, arguments);
627
+ }
628
+ function getSiteUser(_x5, _x6) {
629
+ return _getSiteUser.apply(this, arguments);
630
+ }
631
+ function _getSiteUser() {
632
+ _getSiteUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(instance, searchValue) {
633
+ var requestUrl, response;
634
+ return _regenerator().w(function (_context3) {
635
+ while (1) switch (_context3.n) {
636
+ case 0:
637
+ requestUrl = "_api/web/siteusers?&$filter=substringof('" + searchValue + "', Title) or substringof('" + searchValue + "', LoginName) or substringof('" + searchValue + "', Email)&$top=50&$expand=Groups";
638
+ _context3.n = 1;
639
+ return instance.get(requestUrl);
640
+ case 1:
641
+ response = _context3.v;
642
+ return _context3.a(2, response.data.d);
643
+ }
644
+ }, _callee3);
645
+ }));
646
+ return _getSiteUser.apply(this, arguments);
647
+ }
648
+ function roleDefinitions(_x7) {
649
+ return _roleDefinitions.apply(this, arguments);
650
+ }
651
+ function _roleDefinitions() {
652
+ _roleDefinitions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(instance) {
653
+ var requestUrl, response;
654
+ return _regenerator().w(function (_context4) {
655
+ while (1) switch (_context4.n) {
656
+ case 0:
657
+ requestUrl = "_api/Web/RoleDefinitions";
658
+ _context4.n = 1;
659
+ return instance.get(requestUrl);
660
+ case 1:
661
+ response = _context4.v;
662
+ return _context4.a(2, response.data.d.results);
663
+ }
664
+ }, _callee4);
665
+ }));
666
+ return _roleDefinitions.apply(this, arguments);
667
+ }
668
+ function getEffectiveBasePermissions(_x8) {
669
+ return _getEffectiveBasePermissions.apply(this, arguments);
670
+ }
671
+ function _getEffectiveBasePermissions() {
672
+ _getEffectiveBasePermissions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(instance) {
673
+ var requestUrl, response;
674
+ return _regenerator().w(function (_context5) {
675
+ while (1) switch (_context5.n) {
676
+ case 0:
677
+ requestUrl = "_api/Web/effectiveBasePermissions";
678
+ _context5.n = 1;
679
+ return instance.get(requestUrl);
680
+ case 1:
681
+ response = _context5.v;
682
+ return _context5.a(2, response.data.d.EffectiveBasePermissions);
683
+ }
684
+ }, _callee5);
685
+ }));
686
+ return _getEffectiveBasePermissions.apply(this, arguments);
687
+ }
688
+ function currentUserPermissions(_x9) {
689
+ return _currentUserPermissions.apply(this, arguments);
690
+ }
691
+ function _currentUserPermissions() {
692
+ _currentUserPermissions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(context) {
693
+ var _yield$getEffectiveBa, High, definitions, result;
694
+ return _regenerator().w(function (_context6) {
695
+ while (1) switch (_context6.n) {
696
+ case 0:
697
+ _context6.n = 1;
698
+ return getEffectiveBasePermissions(context.instance);
699
+ case 1:
700
+ _yield$getEffectiveBa = _context6.v;
701
+ High = _yield$getEffectiveBa.High;
702
+ _context6.n = 2;
703
+ return roleDefinitions(context.instance);
704
+ case 2:
705
+ definitions = _context6.v;
706
+ result = definitions.find(function (_ref) {
707
+ var BasePermissions = _ref.BasePermissions;
708
+ return BasePermissions.High === High;
709
+ });
710
+ return _context6.a(2, result);
711
+ }
712
+ }, _callee6);
713
+ }));
714
+ return _currentUserPermissions.apply(this, arguments);
715
+ }
716
+
170
717
  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
718
  function HTTPSharePointRequests(baseURL, config) {
178
719
  var _this = this;
179
720
  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
721
  get: function get() {
186
722
  _this.endpoint = '_api/web/lists';
187
- return _this.get_v2();
723
+ _this.sharepointVersion = '2013';
724
+ return getListItems(_this.getContext());
188
725
  }
189
726
  };
190
727
  this.folders = {
191
- /**
192
- * Retrieves SharePoint folders from the default folders endpoint.
193
- *
194
- * @returns A promise resolving with folder metadata.
195
- */
196
728
  get: function get() {
197
729
  _this.endpoint = '_api/web/folders';
198
- _this.get_v2();
730
+ _this.sharepointVersion = '2013';
731
+ getListItems(_this.getContext());
199
732
  }
200
733
  };
201
734
  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
735
  send: function send(props) {
227
- return _this.sendEmail(props);
736
+ _this.sharepointVersion = '2013';
737
+ return sendEmail(_this.getContext(), props);
228
738
  }
229
739
  };
230
740
  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
741
  properties: function properties() {
237
742
  return {
238
743
  get: function get() {
239
- return _this.currentUserProperties();
744
+ _this.sharepointVersion = '2013';
745
+ return currentUserProperties(_this.instance);
240
746
  }
241
747
  };
242
748
  },
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
749
  searchSiteUser: function searchSiteUser(searchValue) {
250
- return _this.getSiteUser(searchValue);
750
+ _this.sharepointVersion = '2013';
751
+ return getSiteUser(_this.instance, searchValue);
251
752
  },
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
753
  searchUser: function searchUser(input, filter) {
260
- return _this.typeAhead(input, filter);
754
+ _this.sharepointVersion = '2013';
755
+ return typeAhead(_this.instance, input, filter);
261
756
  },
262
- /**
263
- * Fetches the currently authenticated SharePoint user.
264
- *
265
- * @returns Helper exposing `get` that resolves to the current user payload.
266
- */
267
757
  current: function current() {
268
758
  _this.endpoint = '_api/web/currentUser';
759
+ _this.sharepointVersion = '2013';
269
760
  return {
270
761
  get: function get() {
271
- return _this.get_only();
762
+ return getOnly(_this.instance, _this.endpoint);
272
763
  }
273
764
  };
274
765
  },
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
766
  currentPermission: function currentPermission() {
281
767
  return {
282
768
  get: function get() {
283
- return _this.currentUserPermissions();
769
+ _this.sharepointVersion = '2013';
770
+ return currentUserPermissions(_this.getContext());
284
771
  }
285
772
  };
286
773
  }
@@ -289,25 +776,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
289
776
  this.endpoint = '/api';
290
777
  this.listName = '';
291
778
  this.instance = instance(this.baseURL, config);
779
+ this.sharepointVersion = '2013';
292
780
  }
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
781
  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
- }
782
+ _proto.getContext = function getContext() {
783
+ return {
784
+ instance: this.instance,
785
+ baseURL: this.baseURL,
786
+ endpoint: this.endpoint,
787
+ listName: this.listName,
788
+ sharepointVersion: this.sharepointVersion
789
+ };
311
790
  }
312
791
  /**
313
792
  * @deprecated Use `from` instead.
@@ -315,55 +794,44 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
315
794
  _proto.list = function list(listName) {
316
795
  this.listName = listName;
317
796
  this.endpoint = "_vti_bin/ListData.svc/" + listName;
797
+ this.sharepointVersion = '2010';
318
798
  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
- */;
799
+ };
327
800
  _proto.from = function from(listName, sharepoint_ver) {
328
801
  var _this2 = this;
329
- if (sharepoint_ver === void 0) {
330
- sharepoint_ver = '2013';
331
- }
802
+ var version = sharepoint_ver != null ? sharepoint_ver : '2013';
332
803
  this.listName = listName;
333
- this.endpoint = sharepoint_ver === '2013' ? "_api/web/lists/GetByTitle('" + this.listName + "')/items" : "_vti_bin/ListData.svc/" + listName;
804
+ this.sharepointVersion = version;
805
+ this.endpoint = version === '2013' ? "_api/web/lists/GetByTitle('" + this.listName + "')/items" : "_vti_bin/ListData.svc/" + listName;
806
+ var getContext = function getContext() {
807
+ return _this2.getContext();
808
+ };
334
809
  return {
335
810
  create: function create(data) {
336
- return _this2.create_v2(data);
811
+ return createListItem(getContext(), data);
337
812
  },
338
813
  get: function get(options) {
339
- return _this2.get_v2(options);
814
+ return getListItems(getContext(), options);
340
815
  },
341
816
  update: function update(id, data, digest) {
342
- return _this2.update_2(id, data, digest);
817
+ return updateListItem(getContext(), id, data, digest);
343
818
  },
344
819
  "delete": function _delete(id) {
345
- return _this2["delete"](id);
820
+ return deleteItem(getContext(), id);
346
821
  },
347
822
  createFile: function createFile(props) {
348
- return _this2.createFile(props);
823
+ return createAttachment(getContext(), props);
349
824
  },
350
825
  fields: function fields(options) {
351
- // return this.field_v2(options)
352
826
  _this2.endpoint = !(options != null && options.fieldName) ? "_api/web/lists/GetByTitle('" + _this2.listName + "')/fields" : "_api/web/lists/GetByTitle('" + _this2.listName + "')/fields/getbytitle('" + options.fieldName + "')";
353
827
  return {
354
828
  get: function get() {
355
- return _this2.get_only(options);
829
+ return getOnly(_this2.instance, _this2.endpoint, options);
356
830
  }
357
831
  };
358
832
  }
359
833
  };
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
- */;
834
+ };
367
835
  _proto.folder = function folder(folderName) {
368
836
  var _this3 = this;
369
837
  var filePath = ['Shared Documents'];
@@ -371,659 +839,31 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
371
839
  filePath = Array.isArray(folderName) ? [].concat(filePath, folderName) : [].concat(filePath, [folderName]);
372
840
  }
373
841
  this.endpoint = "_api/web/GetFolderByServerRelativeUrl('" + filePath.join('/') + "')";
842
+ this.sharepointVersion = '2013';
843
+ var getContext = function getContext() {
844
+ return _this3.getContext();
845
+ };
374
846
  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
847
  get: function get(options) {
382
848
  if (!(options != null && options.type)) {
383
849
  _this3.endpoint += '/Files';
384
850
  } else {
385
851
  _this3.endpoint += "/" + options.type;
386
852
  }
387
- return _this3.get_files(options);
853
+ return getFiles(getContext(), options);
388
854
  }
389
855
  };
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
- */;
856
+ };
397
857
  _proto.users = function users(options) {
398
858
  var _this4 = this;
399
859
  this.endpoint = '_api/web/SiteUserInfoList/items';
860
+ this.sharepointVersion = '2013';
400
861
  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
862
  get: function get() {
407
- return _this4.get_v2(options);
863
+ return getListItems(_this4.getContext(), options);
408
864
  }
409
865
  };
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
- }();
866
+ };
1027
867
  return HTTPSharePointRequests;
1028
868
  }();
1029
869