@lindle/sharepoint_requests 0.1.9-beta.0

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.
@@ -0,0 +1,908 @@
1
+ import axios from 'axios';
2
+
3
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
4
+ try {
5
+ var i = n[a](c),
6
+ u = i.value;
7
+ } catch (n) {
8
+ return void e(n);
9
+ }
10
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
11
+ }
12
+ function _asyncToGenerator(n) {
13
+ return function () {
14
+ var t = this,
15
+ e = arguments;
16
+ return new Promise(function (r, o) {
17
+ var a = n.apply(t, e);
18
+ function _next(n) {
19
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
20
+ }
21
+ function _throw(n) {
22
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
23
+ }
24
+ _next(void 0);
25
+ });
26
+ };
27
+ }
28
+ function _regenerator() {
29
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
30
+ var e,
31
+ t,
32
+ r = "function" == typeof Symbol ? Symbol : {},
33
+ n = r.iterator || "@@iterator",
34
+ o = r.toStringTag || "@@toStringTag";
35
+ function i(r, n, o, i) {
36
+ var c = n && n.prototype instanceof Generator ? n : Generator,
37
+ u = Object.create(c.prototype);
38
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
39
+ var i,
40
+ c,
41
+ u,
42
+ f = 0,
43
+ p = o || [],
44
+ y = !1,
45
+ G = {
46
+ p: 0,
47
+ n: 0,
48
+ v: e,
49
+ a: d,
50
+ f: d.bind(e, 4),
51
+ d: function (t, r) {
52
+ return i = t, c = 0, u = e, G.n = r, a;
53
+ }
54
+ };
55
+ function d(r, n) {
56
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
57
+ var o,
58
+ i = p[t],
59
+ d = G.p,
60
+ l = i[2];
61
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
62
+ }
63
+ if (o || r > 1) return a;
64
+ throw y = !0, n;
65
+ }
66
+ return function (o, p, l) {
67
+ if (f > 1) throw TypeError("Generator is already running");
68
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
69
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
70
+ try {
71
+ if (f = 2, i) {
72
+ if (c || (o = "next"), t = i[o]) {
73
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
74
+ if (!t.done) return t;
75
+ u = t.value, c < 2 && (c = 0);
76
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
77
+ i = e;
78
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
79
+ } catch (t) {
80
+ i = e, c = 1, u = t;
81
+ } finally {
82
+ f = 1;
83
+ }
84
+ }
85
+ return {
86
+ value: t,
87
+ done: y
88
+ };
89
+ };
90
+ }(r, o, i), !0), u;
91
+ }
92
+ var a = {};
93
+ function Generator() {}
94
+ function GeneratorFunction() {}
95
+ function GeneratorFunctionPrototype() {}
96
+ t = Object.getPrototypeOf;
97
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
98
+ return this;
99
+ }), t),
100
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
101
+ function f(e) {
102
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
103
+ }
104
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
105
+ return this;
106
+ }), _regeneratorDefine(u, "toString", function () {
107
+ return "[object Generator]";
108
+ }), (_regenerator = function () {
109
+ return {
110
+ w: i,
111
+ m: f
112
+ };
113
+ })();
114
+ }
115
+ function _regeneratorDefine(e, r, n, t) {
116
+ var i = Object.defineProperty;
117
+ try {
118
+ i({}, "", {});
119
+ } catch (e) {
120
+ i = 0;
121
+ }
122
+ _regeneratorDefine = function (e, r, n, t) {
123
+ if (r) i ? i(e, r, {
124
+ value: n,
125
+ enumerable: !t,
126
+ configurable: !t,
127
+ writable: !t
128
+ }) : e[r] = n;else {
129
+ function o(r, n) {
130
+ _regeneratorDefine(e, r, function (e) {
131
+ return this._invoke(r, n, e);
132
+ });
133
+ }
134
+ o("next", 0), o("throw", 1), o("return", 2);
135
+ }
136
+ }, _regeneratorDefine(e, r, n, t);
137
+ }
138
+
139
+ var get = /*#__PURE__*/function () {
140
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, options) {
141
+ var instance, endpoint, _ref3, expand, orderBy, limit, filter, cols, skip, params, url, response, data, meta;
142
+ return _regenerator().w(function (_context) {
143
+ while (1) switch (_context.n) {
144
+ case 0:
145
+ instance = _ref.instance, endpoint = _ref.endpoint;
146
+ _ref3 = options || {}, expand = _ref3.expand, orderBy = _ref3.orderBy, limit = _ref3.limit, filter = _ref3.filter, cols = _ref3.cols, skip = _ref3.skip;
147
+ params = {
148
+ $expand: Array.isArray(expand) ? expand.join(',') : expand,
149
+ $top: limit,
150
+ $skip: skip,
151
+ $select: Array.isArray(cols) ? cols.join(',') : cols,
152
+ $filter: filter,
153
+ $orderby: Array.isArray(orderBy) ? orderBy.join(' ') : orderBy
154
+ };
155
+ url = new URL(endpoint, instance.defaults.baseURL);
156
+ Object.entries(params).forEach(function (_ref4) {
157
+ var key = _ref4[0],
158
+ value = _ref4[1];
159
+ if (value !== undefined && value !== null) {
160
+ url.searchParams.append(key, String(value));
161
+ }
162
+ });
163
+ _context.n = 1;
164
+ return instance.request({
165
+ url: endpoint,
166
+ method: 'GET',
167
+ params: params
168
+ });
169
+ case 1:
170
+ response = _context.v;
171
+ data = limit || !response.data.d.results ? response.data.d : response.data.d.results;
172
+ meta = {
173
+ url: url
174
+ };
175
+ return _context.a(2, {
176
+ data: data,
177
+ meta: meta
178
+ });
179
+ }
180
+ }, _callee);
181
+ }));
182
+ return function get(_x, _x2) {
183
+ return _ref2.apply(this, arguments);
184
+ };
185
+ }();
186
+
187
+ var getDigest = /*#__PURE__*/function () {
188
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
189
+ var instance, baseURL, _response$data, response, _t;
190
+ return _regenerator().w(function (_context) {
191
+ while (1) switch (_context.p = _context.n) {
192
+ case 0:
193
+ instance = _ref.instance, baseURL = _ref.baseURL;
194
+ _context.p = 1;
195
+ _context.n = 2;
196
+ return instance.post(baseURL + "_api/contextinfo");
197
+ case 2:
198
+ response = _context.v;
199
+ if ((_response$data = response.data) != null && (_response$data = _response$data.d) != null && (_response$data = _response$data.GetContextWebInformation) != null && _response$data.FormDigestValue) {
200
+ _context.n = 3;
201
+ break;
202
+ }
203
+ throw new Error('Invalid response structure: Missing FormDigestValue');
204
+ case 3:
205
+ return _context.a(2, response.data.d.GetContextWebInformation.FormDigestValue);
206
+ case 4:
207
+ _context.p = 4;
208
+ _t = _context.v;
209
+ console.error('Failed to retrieve the Form Digest Value:', _t);
210
+ throw new Error("Error retrieving Form Digest Value");
211
+ case 5:
212
+ return _context.a(2);
213
+ }
214
+ }, _callee, null, [[1, 4]]);
215
+ }));
216
+ return function getDigest(_x) {
217
+ return _ref2.apply(this, arguments);
218
+ };
219
+ }();
220
+
221
+ var HTTPSharePointRequests = /*#__PURE__*/function () {
222
+ function HTTPSharePointRequests(baseURL) {
223
+ var _this = this;
224
+ this.lists = {
225
+ get: function get() {
226
+ _this.endpoint = '_api/web/lists';
227
+ return _this.get_v2();
228
+ }
229
+ };
230
+ this.folders = {
231
+ get: function get() {
232
+ _this.endpoint = '_api/web/folders';
233
+ _this.get_v2();
234
+ }
235
+ };
236
+ // public users(options?: Options<any>) {
237
+ // this.endpoint = '_api/web/SiteUserInfoList/items';
238
+ // return {
239
+ // get: () => this.get_v2(options),
240
+ // };
241
+ // }
242
+ this.users = {
243
+ get: function () {
244
+ var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
245
+ return _regenerator().w(function (_context) {
246
+ while (1) switch (_context.n) {
247
+ case 0:
248
+ _this.endpoint = '_api/web/SiteUserInfoList/items';
249
+ _context.n = 1;
250
+ return _this.get_v2(options);
251
+ case 1:
252
+ return _context.a(2, _context.v);
253
+ }
254
+ }, _callee);
255
+ }));
256
+ function get(_x) {
257
+ return _get.apply(this, arguments);
258
+ }
259
+ return get;
260
+ }()
261
+ };
262
+ this.email = {
263
+ /**
264
+ * Sends an email using SharePoint's Utility.SendEmail API.
265
+ *
266
+ * @param {EmailProps} param0 - The email properties.
267
+ * @param {string} param0.From - The sender's email address.
268
+ * @example
269
+ * Example of a sender's email address
270
+ * "sender@example.com"
271
+ * @param {string | string[]} param0.To - The recipient's email address or an array of email addresses.
272
+ * @example
273
+ * Example of a single recipient's email address
274
+ * "recipient@example.com"
275
+ * Example of multiple recipients' email addresses
276
+ * ["recipient1@example.com", "recipient2@example.com"]
277
+ * @param {string} param0.Subject - The subject of the email.
278
+ * @example
279
+ * Example of an email subject
280
+ * "Meeting Reminder"
281
+ * @param {string} param0.Body - The body content of the email.
282
+ * @example
283
+ * Example of an email body
284
+ * "Dear team, please be reminded of the meeting scheduled for tomorrow at 10 AM."
285
+ * @returns {Promise<any>} - A promise that resolves to the response of the email send request.
286
+ */
287
+ send: function send(props) {
288
+ return _this.sendEmail(props);
289
+ }
290
+ };
291
+ this.user = {
292
+ properties: function properties() {
293
+ return {
294
+ get: function get() {
295
+ return _this.currentUserProperties();
296
+ }
297
+ };
298
+ },
299
+ searchSiteUser: function searchSiteUser(searchValue) {
300
+ return _this.getSiteUser(searchValue);
301
+ },
302
+ searchUser: function searchUser(input, filter) {
303
+ return _this.typeAhead(input, filter);
304
+ },
305
+ current: function current() {
306
+ _this.endpoint = '_api/web/currentUser';
307
+ return {
308
+ get: function get() {
309
+ return _this.get_only();
310
+ }
311
+ };
312
+ },
313
+ currentPermission: function currentPermission() {
314
+ return {
315
+ get: function get() {
316
+ return _this.currentUserPermissions();
317
+ }
318
+ };
319
+ }
320
+ };
321
+ this.baseURL = baseURL.endsWith('/') ? baseURL : baseURL + "/";
322
+ this.endpoint = '/api';
323
+ this.listName = '';
324
+ var headers = {
325
+ Accept: 'application/json; odata=verbose',
326
+ 'Content-Type': 'application/json; odata=verbose'
327
+ };
328
+ this.instance = axios.create({
329
+ baseURL: "" + this.baseURL,
330
+ withCredentials: true,
331
+ headers: {
332
+ common: headers,
333
+ post: headers
334
+ }
335
+ });
336
+ }
337
+ var _proto = HTTPSharePointRequests.prototype;
338
+ _proto.transformArraysToEdmStrings = function transformArraysToEdmStrings(data) {
339
+ for (var key in data) {
340
+ if (Array.isArray(data[key])) {
341
+ data[key] = {
342
+ __metadata: {
343
+ type: 'Collection(Edm.String)'
344
+ },
345
+ results: data[key]
346
+ };
347
+ }
348
+ }
349
+ }
350
+ /**
351
+ * @deprecated Use `from` instead.
352
+ */;
353
+ _proto.list = function list(listName) {
354
+ this.listName = listName;
355
+ this.endpoint = "_vti_bin/ListData.svc/" + listName;
356
+ return this;
357
+ };
358
+ _proto.from = function from(listName, sharepoint_ver) {
359
+ var _this2 = this;
360
+ if (sharepoint_ver === void 0) {
361
+ sharepoint_ver = '2013';
362
+ }
363
+ this.listName = listName;
364
+ this.endpoint = sharepoint_ver === '2013' ? "_api/web/lists/GetByTitle('" + this.listName + "')/items" : "_vti_bin/ListData.svc/" + listName;
365
+ return {
366
+ create: function create(data) {
367
+ return _this2.create_v2(data);
368
+ },
369
+ get: function get(options) {
370
+ return _this2.get_v2(options);
371
+ },
372
+ update: function update(id, data, digest) {
373
+ return _this2.update_2(id, data, digest);
374
+ },
375
+ "delete": function _delete(id) {
376
+ return _this2["delete"](id);
377
+ },
378
+ createFile: function createFile(props) {
379
+ return _this2.createFile(props);
380
+ },
381
+ fields: function fields(options) {
382
+ // return this.field_v2(options)
383
+ _this2.endpoint = !(options != null && options.fieldName) ? "_api/web/lists/GetByTitle('" + _this2.listName + "')/fields" : "_api/web/lists/GetByTitle('" + _this2.listName + "')/fields/getbytitle('" + options.fieldName + "')";
384
+ return {
385
+ get: function get() {
386
+ return _this2.get_only(options);
387
+ }
388
+ };
389
+ }
390
+ };
391
+ };
392
+ _proto.folder = function folder(folderName) {
393
+ var _this3 = this;
394
+ var filePath = ['Shared Documents'];
395
+ if (folderName) {
396
+ filePath = Array.isArray(folderName) ? [].concat(filePath, folderName) : [].concat(filePath, [folderName]);
397
+ }
398
+ this.endpoint = "_api/web/GetFolderByServerRelativeUrl('" + filePath.join('/') + "')";
399
+ return {
400
+ get: function get(options) {
401
+ if (!(options != null && options.type)) {
402
+ _this3.endpoint += '/Files';
403
+ } else {
404
+ _this3.endpoint += "/" + options.type;
405
+ }
406
+ return _this3.get_files(options);
407
+ }
408
+ };
409
+ }
410
+ /**
411
+ * Asynchronously retrieves the Form Digest Value from the context information API.
412
+ *
413
+ * @returns {Promise<string>} A promise that resolves to the Form Digest Value.
414
+ * @throws {Error} If the HTTP request fails or the response does not contain the expected data.
415
+ */;
416
+ _proto.getDigest =
417
+ /*#__PURE__*/
418
+ function () {
419
+ var _getDigest2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
420
+ var value;
421
+ return _regenerator().w(function (_context2) {
422
+ while (1) switch (_context2.n) {
423
+ case 0:
424
+ _context2.n = 1;
425
+ return getDigest({
426
+ instance: this.instance,
427
+ baseURL: this.baseURL
428
+ });
429
+ case 1:
430
+ value = _context2.v;
431
+ return _context2.a(2, value);
432
+ }
433
+ }, _callee2, this);
434
+ }));
435
+ function getDigest$1() {
436
+ return _getDigest2.apply(this, arguments);
437
+ }
438
+ return getDigest$1;
439
+ }();
440
+ _proto.get_only = /*#__PURE__*/function () {
441
+ var _get_only = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
442
+ var _ref, expand, orderBy, limit, filter, cols, skip, params, _yield$this$instance$, data;
443
+ return _regenerator().w(function (_context3) {
444
+ while (1) switch (_context3.n) {
445
+ case 0:
446
+ _ref = options || {}, expand = _ref.expand, orderBy = _ref.orderBy, limit = _ref.limit, filter = _ref.filter, cols = _ref.cols, skip = _ref.skip;
447
+ params = {
448
+ $expand: Array.isArray(expand) ? expand.join(',') : expand,
449
+ $top: limit,
450
+ $skip: skip,
451
+ $select: Array.isArray(cols) ? cols.join(',') : cols,
452
+ $filter: filter,
453
+ $orderby: Array.isArray(orderBy) ? orderBy.join(',') : orderBy
454
+ };
455
+ _context3.n = 1;
456
+ return this.instance.get(this.endpoint, {
457
+ params: params
458
+ });
459
+ case 1:
460
+ _yield$this$instance$ = _context3.v;
461
+ data = _yield$this$instance$.data;
462
+ if (!data) {
463
+ _context3.n = 2;
464
+ break;
465
+ }
466
+ return _context3.a(2, data.d.results ? data.d.results : data.d);
467
+ case 2:
468
+ return _context3.a(2);
469
+ }
470
+ }, _callee3, this);
471
+ }));
472
+ function get_only(_x2) {
473
+ return _get_only.apply(this, arguments);
474
+ }
475
+ return get_only;
476
+ }();
477
+ _proto.get_files = /*#__PURE__*/function () {
478
+ var _get_files = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(options) {
479
+ var _ref2, expand, orderBy, limit, filter, cols, skip, params, url, response, data, meta;
480
+ return _regenerator().w(function (_context4) {
481
+ while (1) switch (_context4.n) {
482
+ case 0:
483
+ _ref2 = options || {}, expand = _ref2.expand, orderBy = _ref2.orderBy, limit = _ref2.limit, filter = _ref2.filter, cols = _ref2.cols, skip = _ref2.skip;
484
+ params = {
485
+ $expand: Array.isArray(expand) ? expand.join(',') : expand,
486
+ $top: limit,
487
+ $skip: skip,
488
+ $select: Array.isArray(cols) ? cols.join(',') : cols,
489
+ $filter: filter,
490
+ $orderby: Array.isArray(orderBy) ? orderBy.join(',') : orderBy
491
+ };
492
+ url = new URL(this.endpoint, this.instance.defaults.baseURL);
493
+ Object.entries(params).forEach(function (_ref3) {
494
+ var key = _ref3[0],
495
+ value = _ref3[1];
496
+ if (value !== undefined && value !== null) {
497
+ url.searchParams.append(key, String(value));
498
+ }
499
+ });
500
+ _context4.n = 1;
501
+ return this.instance.request({
502
+ url: this.endpoint,
503
+ method: 'GET',
504
+ params: params
505
+ });
506
+ case 1:
507
+ response = _context4.v;
508
+ data = limit || !response.data.d.results ? response.data.d : response.data.d.results;
509
+ meta = {
510
+ url: url
511
+ };
512
+ return _context4.a(2, {
513
+ data: data,
514
+ meta: meta
515
+ });
516
+ }
517
+ }, _callee4, this);
518
+ }));
519
+ function get_files(_x3) {
520
+ return _get_files.apply(this, arguments);
521
+ }
522
+ return get_files;
523
+ }();
524
+ _proto.get_v2 = /*#__PURE__*/function () {
525
+ var _get_v = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(options) {
526
+ var _yield$get, data, meta;
527
+ return _regenerator().w(function (_context5) {
528
+ while (1) switch (_context5.n) {
529
+ case 0:
530
+ _context5.n = 1;
531
+ return get({
532
+ instance: this.instance,
533
+ endpoint: this.endpoint
534
+ }, options);
535
+ case 1:
536
+ _yield$get = _context5.v;
537
+ data = _yield$get.data;
538
+ meta = _yield$get.meta;
539
+ return _context5.a(2, {
540
+ data: data,
541
+ meta: meta
542
+ });
543
+ }
544
+ }, _callee5, this);
545
+ }));
546
+ function get_v2(_x4) {
547
+ return _get_v.apply(this, arguments);
548
+ }
549
+ return get_v2;
550
+ }();
551
+ _proto.update_2 = /*#__PURE__*/function () {
552
+ var _update_ = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(id, data, digest) {
553
+ var formDigestValue, url, response, _t;
554
+ return _regenerator().w(function (_context6) {
555
+ while (1) switch (_context6.n) {
556
+ case 0:
557
+ _t = digest;
558
+ if (_t) {
559
+ _context6.n = 2;
560
+ break;
561
+ }
562
+ _context6.n = 1;
563
+ return this.getDigest();
564
+ case 1:
565
+ _t = _context6.v;
566
+ case 2:
567
+ formDigestValue = _t;
568
+ data.__metadata = {
569
+ type: "SP.Data." + this.listName + "ListItem"
570
+ };
571
+ url = "_api/lists/getbytitle('" + this.listName + "')/getItemById('" + id + "')";
572
+ _context6.n = 3;
573
+ return this.instance({
574
+ url: url,
575
+ method: 'POST',
576
+ data: JSON.stringify(data),
577
+ headers: {
578
+ 'X-RequestDigest': formDigestValue,
579
+ 'IF-MATCH': '*',
580
+ 'X-Http-Method': 'PATCH'
581
+ }
582
+ });
583
+ case 3:
584
+ response = _context6.v;
585
+ return _context6.a(2, response);
586
+ }
587
+ }, _callee6, this);
588
+ }));
589
+ function update_2(_x5, _x6, _x7) {
590
+ return _update_.apply(this, arguments);
591
+ }
592
+ return update_2;
593
+ }();
594
+ _proto.create_v2 = /*#__PURE__*/function () {
595
+ var _create_v = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(listData) {
596
+ var response, _t2, _t3, _t4, _t5, _t6, _t7;
597
+ return _regenerator().w(function (_context7) {
598
+ while (1) switch (_context7.n) {
599
+ case 0:
600
+ this.transformArraysToEdmStrings(listData);
601
+ listData.__metadata = {
602
+ type: "SP.Data." + this.listName + "ListItem"
603
+ };
604
+ _t2 = this;
605
+ _t3 = this.endpoint;
606
+ _t4 = JSON.stringify(listData);
607
+ _context7.n = 1;
608
+ return this.getDigest();
609
+ case 1:
610
+ _t5 = _context7.v;
611
+ _t6 = {
612
+ 'X-RequestDigest': _t5,
613
+ 'IF-MATCH': '*'
614
+ };
615
+ _t7 = {
616
+ url: _t3,
617
+ method: 'POST',
618
+ data: _t4,
619
+ headers: _t6
620
+ };
621
+ _context7.n = 2;
622
+ return _t2.instance.call(_t2, _t7);
623
+ case 2:
624
+ response = _context7.v;
625
+ return _context7.a(2, response);
626
+ }
627
+ }, _callee7, this);
628
+ }));
629
+ function create_v2(_x8) {
630
+ return _create_v.apply(this, arguments);
631
+ }
632
+ return create_v2;
633
+ }();
634
+ _proto.createFile = /*#__PURE__*/function () {
635
+ var _createFile = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(_ref4) {
636
+ var file, itemId, requestUrl, res, _t8, _t9, _t0, _t1, _t10, _t11;
637
+ return _regenerator().w(function (_context8) {
638
+ while (1) switch (_context8.n) {
639
+ case 0:
640
+ file = _ref4.file, itemId = _ref4.itemId;
641
+ requestUrl = "_api/lists/getbytitle('" + this.listName + "')/items(" + itemId + ")/AttachmentFiles/add(FileName='" + file.name + "')";
642
+ _t8 = this.instance;
643
+ _t9 = requestUrl;
644
+ _t0 = file;
645
+ _context8.n = 1;
646
+ return this.getDigest();
647
+ case 1:
648
+ _t1 = _context8.v;
649
+ _t10 = {
650
+ 'X-RequestDigest': _t1
651
+ };
652
+ _t11 = {
653
+ headers: _t10,
654
+ withCredentials: true
655
+ };
656
+ _context8.n = 2;
657
+ return _t8.post.call(_t8, _t9, _t0, _t11);
658
+ case 2:
659
+ res = _context8.v;
660
+ return _context8.a(2, res);
661
+ }
662
+ }, _callee8, this);
663
+ }));
664
+ function createFile(_x9) {
665
+ return _createFile.apply(this, arguments);
666
+ }
667
+ return createFile;
668
+ }();
669
+ _proto["delete"] = /*#__PURE__*/function () {
670
+ var _delete2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(ID) {
671
+ var response;
672
+ return _regenerator().w(function (_context9) {
673
+ while (1) switch (_context9.n) {
674
+ case 0:
675
+ _context9.n = 1;
676
+ return this.instance["delete"](this.endpoint + "(" + ID + ")");
677
+ case 1:
678
+ response = _context9.v;
679
+ return _context9.a(2, response);
680
+ }
681
+ }, _callee9, this);
682
+ }));
683
+ function _delete(_x0) {
684
+ return _delete2.apply(this, arguments);
685
+ }
686
+ return _delete;
687
+ }();
688
+ _proto.sendEmail = /*#__PURE__*/function () {
689
+ var _sendEmail = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(_ref5) {
690
+ var From, To, Subject, Body, httpRequest, response, _t12, _t13, _t14, _t15, _t16, _t17;
691
+ return _regenerator().w(function (_context0) {
692
+ while (1) switch (_context0.n) {
693
+ case 0:
694
+ From = _ref5.From, To = _ref5.To, Subject = _ref5.Subject, Body = _ref5.Body;
695
+ httpRequest = '_api/SP.Utilities.Utility.SendEmail';
696
+ _t12 = this;
697
+ _t13 = httpRequest;
698
+ _context0.n = 1;
699
+ return this.getDigest();
700
+ case 1:
701
+ _t14 = _context0.v;
702
+ _t15 = {
703
+ 'X-RequestDigest': _t14,
704
+ 'X-Http-Method': 'POST',
705
+ 'Content-Type': 'application/json;odata=verbose'
706
+ };
707
+ _t16 = JSON.stringify({
708
+ properties: {
709
+ __metadata: {
710
+ type: 'SP.Utilities.EmailProperties'
711
+ },
712
+ From: From,
713
+ To: {
714
+ results: Array.isArray(To) ? To : [To]
715
+ },
716
+ Body: Body,
717
+ Subject: Subject
718
+ }
719
+ });
720
+ _t17 = {
721
+ url: _t13,
722
+ method: 'POST',
723
+ headers: _t15,
724
+ data: _t16
725
+ };
726
+ _context0.n = 2;
727
+ return _t12.instance.call(_t12, _t17);
728
+ case 2:
729
+ response = _context0.v;
730
+ return _context0.a(2, response);
731
+ }
732
+ }, _callee0, this);
733
+ }));
734
+ function sendEmail(_x1) {
735
+ return _sendEmail.apply(this, arguments);
736
+ }
737
+ return sendEmail;
738
+ }();
739
+ _proto.typeAhead = /*#__PURE__*/function () {
740
+ var _typeAhead = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(input, filter) {
741
+ var filterValue, response;
742
+ return _regenerator().w(function (_context1) {
743
+ while (1) switch (_context1.n) {
744
+ case 0:
745
+ filterValue = filter ? " and " + filter : '';
746
+ _context1.n = 1;
747
+ return this.instance.get("_vti_bin/listdata.svc/UserInformationList?$top=10&$filter=substringof('" + input + "',Name) or substringof('" + input + "',WorkEmail)" + filterValue);
748
+ case 1:
749
+ response = _context1.v;
750
+ return _context1.a(2, response.data.d);
751
+ }
752
+ }, _callee1, this);
753
+ }));
754
+ function typeAhead(_x10, _x11) {
755
+ return _typeAhead.apply(this, arguments);
756
+ }
757
+ return typeAhead;
758
+ }();
759
+ _proto.currentUserProperties = /*#__PURE__*/function () {
760
+ var _currentUserProperties = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
761
+ var requestUrl, profile;
762
+ return _regenerator().w(function (_context10) {
763
+ while (1) switch (_context10.n) {
764
+ case 0:
765
+ requestUrl = '_api/sp.userprofiles.peoplemanager/getmyproperties';
766
+ _context10.n = 1;
767
+ return this.instance.get(requestUrl);
768
+ case 1:
769
+ profile = _context10.v;
770
+ profile = profile.data.d;
771
+ profile.UserProfileProperties.results.forEach(function (prop) {
772
+ if (prop.Key === 'FirstName') {
773
+ profile.FirstName = prop.Value;
774
+ }
775
+ if (prop.Key === 'LastName') {
776
+ profile.LastName = prop.Value;
777
+ }
778
+ if (prop.Key === 'Country') {
779
+ profile.Country = prop.Value;
780
+ }
781
+ if (prop.Key === 'UserName') {
782
+ profile.UserName = prop.Value;
783
+ }
784
+ });
785
+ return _context10.a(2, profile);
786
+ }
787
+ }, _callee10, this);
788
+ }));
789
+ function currentUserProperties() {
790
+ return _currentUserProperties.apply(this, arguments);
791
+ }
792
+ return currentUserProperties;
793
+ }();
794
+ _proto.getSiteUser = /*#__PURE__*/function () {
795
+ var _getSiteUser = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(searchValue) {
796
+ var requestUrl, response;
797
+ return _regenerator().w(function (_context11) {
798
+ while (1) switch (_context11.n) {
799
+ case 0:
800
+ requestUrl = "_api/web/siteusers?&$filter=substringof('" + searchValue + "', Title) or substringof('" + searchValue + "', LoginName) or substringof('" + searchValue + "', Email)&$top=50&$expand=Groups";
801
+ _context11.n = 1;
802
+ return this.instance.get(requestUrl);
803
+ case 1:
804
+ response = _context11.v;
805
+ return _context11.a(2, response.data.d);
806
+ }
807
+ }, _callee11, this);
808
+ }));
809
+ function getSiteUser(_x12) {
810
+ return _getSiteUser.apply(this, arguments);
811
+ }
812
+ return getSiteUser;
813
+ }();
814
+ _proto.roleDefinitions = /*#__PURE__*/function () {
815
+ var _roleDefinitions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
816
+ var requestUrl, response;
817
+ return _regenerator().w(function (_context12) {
818
+ while (1) switch (_context12.n) {
819
+ case 0:
820
+ requestUrl = "_api/Web/RoleDefinitions";
821
+ _context12.n = 1;
822
+ return this.instance.get(requestUrl);
823
+ case 1:
824
+ response = _context12.v;
825
+ return _context12.a(2, response.data.d.results);
826
+ }
827
+ }, _callee12, this);
828
+ }));
829
+ function roleDefinitions() {
830
+ return _roleDefinitions.apply(this, arguments);
831
+ }
832
+ return roleDefinitions;
833
+ }();
834
+ _proto.getEffectiveBasePermissions = /*#__PURE__*/function () {
835
+ var _getEffectiveBasePermissions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
836
+ var requestUrl, response;
837
+ return _regenerator().w(function (_context13) {
838
+ while (1) switch (_context13.n) {
839
+ case 0:
840
+ requestUrl = "_api/Web/effectiveBasePermissions";
841
+ _context13.n = 1;
842
+ return this.instance.get(requestUrl);
843
+ case 1:
844
+ response = _context13.v;
845
+ return _context13.a(2, response.data.d.EffectiveBasePermissions);
846
+ }
847
+ }, _callee13, this);
848
+ }));
849
+ function getEffectiveBasePermissions() {
850
+ return _getEffectiveBasePermissions.apply(this, arguments);
851
+ }
852
+ return getEffectiveBasePermissions;
853
+ }();
854
+ _proto.currentUserPermissions = /*#__PURE__*/function () {
855
+ var _currentUserPermissions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
856
+ var _yield$this$getEffect, High, roleDefinitions, result;
857
+ return _regenerator().w(function (_context14) {
858
+ while (1) switch (_context14.n) {
859
+ case 0:
860
+ _context14.n = 1;
861
+ return this.getEffectiveBasePermissions();
862
+ case 1:
863
+ _yield$this$getEffect = _context14.v;
864
+ High = _yield$this$getEffect.High;
865
+ _context14.n = 2;
866
+ return this.roleDefinitions();
867
+ case 2:
868
+ roleDefinitions = _context14.v;
869
+ result = roleDefinitions.find(function (_ref6) {
870
+ var BasePermissions = _ref6.BasePermissions;
871
+ return BasePermissions.High === High;
872
+ });
873
+ return _context14.a(2, result);
874
+ }
875
+ }, _callee14, this);
876
+ }));
877
+ function currentUserPermissions() {
878
+ return _currentUserPermissions.apply(this, arguments);
879
+ }
880
+ return currentUserPermissions;
881
+ }();
882
+ return HTTPSharePointRequests;
883
+ }();
884
+
885
+ // Load environment variables from .env file
886
+ function createBase() {
887
+ function create(_ref) {
888
+ var baseURL = _ref.baseURL;
889
+ if (!baseURL) {
890
+ throw new Error('A valid SharePoint URL must be provided.');
891
+ }
892
+ return new HTTPSharePointRequests(baseURL);
893
+ }
894
+ return {
895
+ /**
896
+ * @deprecated Use `create` instead.
897
+ */
898
+ baseURL: function baseURL(url) {
899
+ return create({
900
+ baseURL: url
901
+ });
902
+ },
903
+ create: create
904
+ };
905
+ }
906
+
907
+ export default createBase;
908
+ //# sourceMappingURL=sharepoint_requests.esm.js.map