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