@lindle/sharepoint_requests 0.1.12 → 0.1.13

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