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