@lindle/sharepoint_requests 0.1.19 → 0.1.20

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 (49) hide show
  1. package/dist/index.d.mts +469 -0
  2. package/dist/index.d.ts +460 -8
  3. package/dist/index.js +892 -5
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +863 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +5 -5
  8. package/src/root/index.ts +29 -9
  9. package/src/root/instance.ts +7 -0
  10. package/src/root/internal/context.ts +0 -1
  11. package/src/root/internal/digest.ts +16 -10
  12. package/src/root/internal/emailRequests.ts +2 -5
  13. package/src/root/internal/listRequests/createAttachment.ts +2 -2
  14. package/src/root/internal/listRequests/createListItem.ts +3 -18
  15. package/src/root/internal/listRequests/deleteFile.ts +1 -2
  16. package/src/root/internal/listRequests/deleteItem.ts +1 -1
  17. package/src/root/internal/listRequests/getListItems.ts +34 -7
  18. package/src/root/internal/listRequests/resolveMetadataType.ts +14 -0
  19. package/src/root/internal/listRequests/updateListItem.ts +3 -19
  20. package/src/root/internal/listRequests/uploadFile.ts +8 -13
  21. package/src/root/internal/userRequests.ts +52 -28
  22. package/src/types.ts +3 -2
  23. package/dist/root/index.d.ts +0 -163
  24. package/dist/root/instance.d.ts +0 -3
  25. package/dist/root/internal/context.d.ts +0 -11
  26. package/dist/root/internal/digest.d.ts +0 -2
  27. package/dist/root/internal/emailRequests.d.ts +0 -10
  28. package/dist/root/internal/listRequests/createAttachment.d.ts +0 -3
  29. package/dist/root/internal/listRequests/createListItem.d.ts +0 -3
  30. package/dist/root/internal/listRequests/deleteFile.d.ts +0 -3
  31. package/dist/root/internal/listRequests/deleteItem.d.ts +0 -3
  32. package/dist/root/internal/listRequests/getFiles.d.ts +0 -8
  33. package/dist/root/internal/listRequests/getListItems.d.ts +0 -8
  34. package/dist/root/internal/listRequests/getOnly.d.ts +0 -3
  35. package/dist/root/internal/listRequests/index.d.ts +0 -9
  36. package/dist/root/internal/listRequests/normalizePayload.d.ts +0 -4
  37. package/dist/root/internal/listRequests/updateListItem.d.ts +0 -3
  38. package/dist/root/internal/listRequests/uploadFile.d.ts +0 -6
  39. package/dist/root/internal/listRequests/utils.d.ts +0 -2
  40. package/dist/root/internal/odata.d.ts +0 -5
  41. package/dist/root/internal/sharepointUrl.d.ts +0 -2
  42. package/dist/root/internal/userRequests.d.ts +0 -15
  43. package/dist/sharepoint_requests.cjs.development.js +0 -1497
  44. package/dist/sharepoint_requests.cjs.development.js.map +0 -1
  45. package/dist/sharepoint_requests.cjs.production.min.js +0 -2
  46. package/dist/sharepoint_requests.cjs.production.min.js.map +0 -1
  47. package/dist/sharepoint_requests.esm.js +0 -1490
  48. package/dist/sharepoint_requests.esm.js.map +0 -1
  49. package/dist/types.d.ts +0 -260
@@ -1,1490 +0,0 @@
1
- import axios, { AxiosHeaders } from 'axios';
2
-
3
- function _arrayLikeToArray(r, a) {
4
- (null == a || a > r.length) && (a = r.length);
5
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
6
- return n;
7
- }
8
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
9
- try {
10
- var i = n[a](c),
11
- u = i.value;
12
- } catch (n) {
13
- return void e(n);
14
- }
15
- i.done ? t(u) : Promise.resolve(u).then(r, o);
16
- }
17
- function _asyncToGenerator(n) {
18
- return function () {
19
- var t = this,
20
- e = arguments;
21
- return new Promise(function (r, o) {
22
- var a = n.apply(t, e);
23
- function _next(n) {
24
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
25
- }
26
- function _throw(n) {
27
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
28
- }
29
- _next(void 0);
30
- });
31
- };
32
- }
33
- function _createForOfIteratorHelperLoose(r, e) {
34
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
35
- if (t) return (t = t.call(r)).next.bind(t);
36
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
37
- t && (r = t);
38
- var o = 0;
39
- return function () {
40
- return o >= r.length ? {
41
- done: !0
42
- } : {
43
- done: !1,
44
- value: r[o++]
45
- };
46
- };
47
- }
48
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
49
- }
50
- function _extends() {
51
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
52
- for (var e = 1; e < arguments.length; e++) {
53
- var t = arguments[e];
54
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
55
- }
56
- return n;
57
- }, _extends.apply(null, arguments);
58
- }
59
- function _regenerator() {
60
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
61
- var e,
62
- t,
63
- r = "function" == typeof Symbol ? Symbol : {},
64
- n = r.iterator || "@@iterator",
65
- o = r.toStringTag || "@@toStringTag";
66
- function i(r, n, o, i) {
67
- var c = n && n.prototype instanceof Generator ? n : Generator,
68
- u = Object.create(c.prototype);
69
- return _regeneratorDefine(u, "_invoke", function (r, n, o) {
70
- var i,
71
- c,
72
- u,
73
- f = 0,
74
- p = o || [],
75
- y = !1,
76
- G = {
77
- p: 0,
78
- n: 0,
79
- v: e,
80
- a: d,
81
- f: d.bind(e, 4),
82
- d: function (t, r) {
83
- return i = t, c = 0, u = e, G.n = r, a;
84
- }
85
- };
86
- function d(r, n) {
87
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
88
- var o,
89
- i = p[t],
90
- d = G.p,
91
- l = i[2];
92
- 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));
93
- }
94
- if (o || r > 1) return a;
95
- throw y = !0, n;
96
- }
97
- return function (o, p, l) {
98
- if (f > 1) throw TypeError("Generator is already running");
99
- for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
100
- i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
101
- try {
102
- if (f = 2, i) {
103
- if (c || (o = "next"), t = i[o]) {
104
- if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
105
- if (!t.done) return t;
106
- u = t.value, c < 2 && (c = 0);
107
- } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
108
- i = e;
109
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
110
- } catch (t) {
111
- i = e, c = 1, u = t;
112
- } finally {
113
- f = 1;
114
- }
115
- }
116
- return {
117
- value: t,
118
- done: y
119
- };
120
- };
121
- }(r, o, i), !0), u;
122
- }
123
- var a = {};
124
- function Generator() {}
125
- function GeneratorFunction() {}
126
- function GeneratorFunctionPrototype() {}
127
- t = Object.getPrototypeOf;
128
- var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
129
- return this;
130
- }), t),
131
- u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
132
- function f(e) {
133
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
134
- }
135
- 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 () {
136
- return this;
137
- }), _regeneratorDefine(u, "toString", function () {
138
- return "[object Generator]";
139
- }), (_regenerator = function () {
140
- return {
141
- w: i,
142
- m: f
143
- };
144
- })();
145
- }
146
- function _regeneratorDefine(e, r, n, t) {
147
- var i = Object.defineProperty;
148
- try {
149
- i({}, "", {});
150
- } catch (e) {
151
- i = 0;
152
- }
153
- _regeneratorDefine = function (e, r, n, t) {
154
- function o(r, n) {
155
- _regeneratorDefine(e, r, function (e) {
156
- return this._invoke(r, n, e);
157
- });
158
- }
159
- r ? i ? i(e, r, {
160
- value: n,
161
- enumerable: !t,
162
- configurable: !t,
163
- writable: !t
164
- }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
165
- }, _regeneratorDefine(e, r, n, t);
166
- }
167
- function _unsupportedIterableToArray(r, a) {
168
- if (r) {
169
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
170
- var t = {}.toString.call(r).slice(8, -1);
171
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
172
- }
173
- }
174
-
175
- var defaultConfig = {
176
- headers: {
177
- Accept: 'application/json; odata=verbose',
178
- 'Content-Type': 'application/json; odata=verbose'
179
- },
180
- timeout: 15000,
181
- withCredentials: true
182
- };
183
- var instance = function instance(baseURL, config) {
184
- var _config$headers;
185
- var userHeaders = (config == null ? void 0 : config.headers) instanceof AxiosHeaders ? config.headers.toJSON() : (_config$headers = config == null ? void 0 : config.headers) != null ? _config$headers : {};
186
- return axios.create(_extends({}, defaultConfig, config, {
187
- baseURL: baseURL,
188
- headers: _extends({}, defaultConfig.headers, userHeaders)
189
- }));
190
- };
191
-
192
- function fetchDigest(_x, _x2) {
193
- return _fetchDigest.apply(this, arguments);
194
- }
195
- function _fetchDigest() {
196
- _fetchDigest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, baseURL) {
197
- var _response$data, response, formDigestValue, cause, _t;
198
- return _regenerator().w(function (_context) {
199
- while (1) switch (_context.p = _context.n) {
200
- case 0:
201
- _context.p = 0;
202
- _context.n = 1;
203
- return instance.post(baseURL + "_api/contextinfo");
204
- case 1:
205
- response = _context.v;
206
- formDigestValue = (_response$data = response.data) == null || (_response$data = _response$data.d) == null || (_response$data = _response$data.GetContextWebInformation) == null ? void 0 : _response$data.FormDigestValue;
207
- if (formDigestValue) {
208
- _context.n = 2;
209
- break;
210
- }
211
- throw new Error('Invalid response structure: Missing FormDigestValue');
212
- case 2:
213
- return _context.a(2, formDigestValue);
214
- case 3:
215
- _context.p = 3;
216
- _t = _context.v;
217
- cause = _t instanceof Error ? _t.message : 'Unknown contextinfo error';
218
- throw new Error("Error retrieving Form Digest Value: " + cause);
219
- case 4:
220
- return _context.a(2);
221
- }
222
- }, _callee, null, [[0, 3]]);
223
- }));
224
- return _fetchDigest.apply(this, arguments);
225
- }
226
-
227
- function sendEmail(_x, _x2) {
228
- return _sendEmail.apply(this, arguments);
229
- }
230
- function _sendEmail() {
231
- _sendEmail = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
232
- var From, To, Subject, Body, httpRequest, response, _t, _t2, _t3, _t4, _t5;
233
- return _regenerator().w(function (_context) {
234
- while (1) switch (_context.n) {
235
- case 0:
236
- From = _ref.From, To = _ref.To, Subject = _ref.Subject, Body = _ref.Body;
237
- httpRequest = '_api/SP.Utilities.Utility.SendEmail';
238
- _t = context;
239
- _t2 = httpRequest;
240
- _context.n = 1;
241
- return fetchDigest(context.instance, context.baseURL);
242
- case 1:
243
- _t3 = _context.v;
244
- _t4 = {
245
- 'X-RequestDigest': _t3,
246
- 'X-Http-Method': 'POST',
247
- 'Content-Type': 'application/json;odata=verbose'
248
- };
249
- _t5 = JSON.stringify({
250
- properties: {
251
- __metadata: {
252
- type: 'SP.Utilities.EmailProperties'
253
- },
254
- From: From,
255
- To: {
256
- results: Array.isArray(To) ? To : [To]
257
- },
258
- Body: Body,
259
- Subject: Subject
260
- }
261
- });
262
- _context.n = 2;
263
- return _t.instance.call(_t, {
264
- url: _t2,
265
- method: 'POST',
266
- headers: _t4,
267
- data: _t5
268
- });
269
- case 2:
270
- response = _context.v;
271
- return _context.a(2, response);
272
- }
273
- }, _callee);
274
- }));
275
- return _sendEmail.apply(this, arguments);
276
- }
277
-
278
- var LOOKUP_ID_KEYS = ['lookupId', 'LookupId', 'lookupID', 'LookupID', 'Id', 'ID'];
279
- function isPlainObject(value) {
280
- return !!value && typeof value === 'object' && !Array.isArray(value);
281
- }
282
- function extractLookupPrimitive(value, allowGenericId) {
283
- for (var _iterator = _createForOfIteratorHelperLoose(LOOKUP_ID_KEYS), _step; !(_step = _iterator()).done;) {
284
- var key = _step.value;
285
- if (!allowGenericId && (key === 'Id' || key === 'ID')) {
286
- continue;
287
- }
288
- if (value[key] !== undefined && value[key] !== null) {
289
- return value[key];
290
- }
291
- }
292
- return undefined;
293
- }
294
- function normalizeLookupValue(value) {
295
- if (Array.isArray(value)) {
296
- return {
297
- results: value
298
- };
299
- }
300
- if (isPlainObject(value)) {
301
- if (Array.isArray(value.results)) {
302
- return {
303
- results: value.results
304
- };
305
- }
306
- var primitive = extractLookupPrimitive(value, true);
307
- if (primitive !== undefined) {
308
- return primitive;
309
- }
310
- }
311
- if (typeof value === 'string') {
312
- var trimmed = value.trim();
313
- if (!trimmed) {
314
- return value;
315
- }
316
- var numeric = Number(trimmed);
317
- return Number.isNaN(numeric) ? trimmed : numeric;
318
- }
319
- return value;
320
- }
321
- function resolveLookupField(key, value) {
322
- var lower = key.toLowerCase();
323
- var endsWithId = lower.endsWith('id');
324
- var endsWithRef = lower.endsWith('ref');
325
- var endsWithLookup = lower.endsWith('lookup');
326
- var hasLookupHint = endsWithId || endsWithRef || endsWithLookup;
327
- if (value === undefined) {
328
- return null;
329
- }
330
- if (Array.isArray(value)) {
331
- var _targetKey = endsWithId ? key : key + "Id";
332
- return {
333
- key: _targetKey,
334
- value: {
335
- results: value
336
- }
337
- };
338
- }
339
- if (isPlainObject(value)) {
340
- var primitive = extractLookupPrimitive(value, hasLookupHint);
341
- if (primitive !== undefined) {
342
- var _targetKey2 = endsWithId ? key : key + "Id";
343
- return {
344
- key: _targetKey2,
345
- value: normalizeLookupValue(primitive)
346
- };
347
- }
348
- if (Array.isArray(value.results)) {
349
- var _targetKey3 = endsWithId ? key : key + "Id";
350
- return {
351
- key: _targetKey3,
352
- value: {
353
- results: value.results
354
- }
355
- };
356
- }
357
- if (!hasLookupHint) {
358
- return null;
359
- }
360
- } else if (!hasLookupHint) {
361
- return null;
362
- }
363
- var targetKey = endsWithId ? key : key + "Id";
364
- if (value === null) {
365
- return {
366
- key: targetKey,
367
- value: null
368
- };
369
- }
370
- if (typeof value === 'number') {
371
- return {
372
- key: targetKey,
373
- value: value
374
- };
375
- }
376
- if (typeof value === 'string') {
377
- var trimmed = value.trim();
378
- if (!trimmed) {
379
- return {
380
- key: targetKey,
381
- value: ''
382
- };
383
- }
384
- var numeric = Number(trimmed);
385
- return {
386
- key: targetKey,
387
- value: Number.isNaN(numeric) ? trimmed : numeric
388
- };
389
- }
390
- return null;
391
- }
392
- function normalizeListPayload(data) {
393
- var result = {};
394
- if (!data) {
395
- return result;
396
- }
397
- for (var _i = 0, _Object$entries = Object.entries(data); _i < _Object$entries.length; _i++) {
398
- var _Object$entries$_i = _Object$entries[_i],
399
- key = _Object$entries$_i[0],
400
- value = _Object$entries$_i[1];
401
- if (key === '__metadata') {
402
- continue;
403
- }
404
- var lookupField = resolveLookupField(key, value);
405
- if (lookupField) {
406
- result[lookupField.key] = lookupField.value;
407
- continue;
408
- }
409
- if (value !== undefined) {
410
- result[key] = value;
411
- }
412
- }
413
- return result;
414
- }
415
-
416
- function resolveMetadataType(_x) {
417
- return _resolveMetadataType.apply(this, arguments);
418
- }
419
- function _resolveMetadataType() {
420
- _resolveMetadataType = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context) {
421
- return _regenerator().w(function (_context) {
422
- while (1) switch (_context.n) {
423
- case 0:
424
- if (!context.resolveListItemEntityType) {
425
- _context.n = 1;
426
- break;
427
- }
428
- return _context.a(2, context.resolveListItemEntityType());
429
- case 1:
430
- if (!context.listItemEntityTypeFullName) {
431
- _context.n = 2;
432
- break;
433
- }
434
- return _context.a(2, context.listItemEntityTypeFullName);
435
- case 2:
436
- return _context.a(2, "SP.Data." + context.listName + "ListItem");
437
- }
438
- }, _callee);
439
- }));
440
- return _resolveMetadataType.apply(this, arguments);
441
- }
442
- function createListItem(_x2, _x3) {
443
- return _createListItem.apply(this, arguments);
444
- }
445
- function _createListItem() {
446
- _createListItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(context, listData) {
447
- var normalizedData, payload, metadataType, userMetadata, response, _t, _t2, _t3, _t4, _t5;
448
- return _regenerator().w(function (_context2) {
449
- while (1) switch (_context2.n) {
450
- case 0:
451
- normalizedData = normalizeListPayload(listData);
452
- payload = normalizedData;
453
- if (!(context.sharepointVersion === '2013')) {
454
- _context2.n = 2;
455
- break;
456
- }
457
- _context2.n = 1;
458
- return resolveMetadataType(context);
459
- case 1:
460
- metadataType = _context2.v;
461
- userMetadata = listData.__metadata;
462
- payload = _extends({}, normalizedData, {
463
- __metadata: _extends({}, userMetadata && typeof userMetadata === 'object' ? userMetadata : {}, {
464
- type: metadataType
465
- })
466
- });
467
- case 2:
468
- _t = context;
469
- _t2 = context.endpoint;
470
- _t3 = JSON.stringify(payload);
471
- _context2.n = 3;
472
- return fetchDigest(context.instance, context.baseURL);
473
- case 3:
474
- _t4 = _context2.v;
475
- _t5 = {
476
- 'X-RequestDigest': _t4
477
- };
478
- _context2.n = 4;
479
- return _t.instance.call(_t, {
480
- url: _t2,
481
- method: 'POST',
482
- data: _t3,
483
- headers: _t5
484
- });
485
- case 4:
486
- response = _context2.v;
487
- return _context2.a(2, response);
488
- }
489
- }, _callee2);
490
- }));
491
- return _createListItem.apply(this, arguments);
492
- }
493
-
494
- function escapeODataStringLiteral(value) {
495
- return value.replace(/'/g, "''");
496
- }
497
- function buildListByTitleEndpoint(listName) {
498
- return "_api/web/lists/GetByTitle('" + escapeODataStringLiteral(listName) + "')";
499
- }
500
-
501
- function buildLibraryPath(folderPath) {
502
- if (!folderPath) {
503
- return '';
504
- }
505
- var segments = Array.isArray(folderPath) ? folderPath : folderPath.split('/').filter(Boolean);
506
- if (!segments.length) {
507
- return '';
508
- }
509
- var escapedSegments = segments.map(function (segment) {
510
- if (!segment.trim()) {
511
- throw new Error('Folder path segments cannot be empty.');
512
- }
513
- var sanitized = segment.replace(/'/g, "''");
514
- return "/Folders('" + encodeURIComponent(sanitized) + "')";
515
- });
516
- return escapedSegments.join('');
517
- }
518
- function encodeFileName(fileName) {
519
- if (!fileName.trim()) {
520
- throw new Error('File name cannot be empty.');
521
- }
522
- return encodeURIComponent(fileName.replace(/'/g, "''"));
523
- }
524
-
525
- function createAttachment(_x, _x2) {
526
- return _createAttachment.apply(this, arguments);
527
- }
528
- function _createAttachment() {
529
- _createAttachment = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
530
- var file, itemId, encodedFileName, requestUrl, response, _t, _t2, _t3, _t4, _t5;
531
- return _regenerator().w(function (_context) {
532
- while (1) switch (_context.n) {
533
- case 0:
534
- file = _ref.file, itemId = _ref.itemId;
535
- if (!(context.sharepointVersion !== '2013')) {
536
- _context.n = 1;
537
- break;
538
- }
539
- throw new Error('createAttachment is only supported for SharePoint 2013 REST endpoints.');
540
- case 1:
541
- encodedFileName = encodeFileName(file.name);
542
- requestUrl = buildListByTitleEndpoint(context.listName) + "/items(" + itemId + ")/AttachmentFiles/add(FileName='" + encodedFileName + "')";
543
- _t = context.instance;
544
- _t2 = requestUrl;
545
- _t3 = file;
546
- _context.n = 2;
547
- return fetchDigest(context.instance, context.baseURL);
548
- case 2:
549
- _t4 = _context.v;
550
- _t5 = {
551
- 'X-RequestDigest': _t4
552
- };
553
- _context.n = 3;
554
- return _t.post.call(_t, _t2, _t3, {
555
- headers: _t5,
556
- withCredentials: true
557
- });
558
- case 3:
559
- response = _context.v;
560
- return _context.a(2, response);
561
- }
562
- }, _callee);
563
- }));
564
- return _createAttachment.apply(this, arguments);
565
- }
566
-
567
- function deleteItem(_x, _x2) {
568
- return _deleteItem.apply(this, arguments);
569
- }
570
- function _deleteItem() {
571
- _deleteItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, id) {
572
- var requestDigest, url, response;
573
- return _regenerator().w(function (_context) {
574
- while (1) switch (_context.n) {
575
- case 0:
576
- _context.n = 1;
577
- return fetchDigest(context.instance, context.baseURL);
578
- case 1:
579
- requestDigest = _context.v;
580
- url = context.sharepointVersion === '2013' ? buildListByTitleEndpoint(context.listName) + "/items(" + id + ")" : context.endpoint + "(" + id + ")";
581
- _context.n = 2;
582
- return context.instance.post(url, undefined, {
583
- headers: {
584
- 'X-RequestDigest': requestDigest,
585
- 'IF-MATCH': '*',
586
- 'X-HTTP-Method': 'DELETE'
587
- }
588
- });
589
- case 2:
590
- response = _context.v;
591
- return _context.a(2, response);
592
- }
593
- }, _callee);
594
- }));
595
- return _deleteItem.apply(this, arguments);
596
- }
597
-
598
- var SUPPORTED_VERSION = '2013';
599
- function deleteFile(_x, _x2) {
600
- return _deleteFile.apply(this, arguments);
601
- }
602
- function _deleteFile() {
603
- _deleteFile = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
604
- var fileName, folderPath, encodedFileName, requestUrl, digest, response;
605
- return _regenerator().w(function (_context) {
606
- while (1) switch (_context.n) {
607
- case 0:
608
- fileName = _ref.fileName, folderPath = _ref.folderPath;
609
- if (!(context.sharepointVersion !== SUPPORTED_VERSION)) {
610
- _context.n = 1;
611
- break;
612
- }
613
- throw new Error('deleteFile is only supported for SharePoint 2013 REST endpoints.');
614
- case 1:
615
- encodedFileName = encodeFileName(fileName);
616
- requestUrl = buildListByTitleEndpoint(context.listName) + "/RootFolder";
617
- requestUrl += buildLibraryPath(folderPath);
618
- requestUrl += "/Files('" + encodedFileName + "')";
619
- _context.n = 2;
620
- return fetchDigest(context.instance, context.baseURL);
621
- case 2:
622
- digest = _context.v;
623
- _context.n = 3;
624
- return context.instance.post(requestUrl, undefined, {
625
- headers: {
626
- 'X-HTTP-Method': 'DELETE',
627
- 'IF-MATCH': '*',
628
- 'X-RequestDigest': digest
629
- },
630
- withCredentials: true
631
- });
632
- case 3:
633
- response = _context.v;
634
- return _context.a(2, response);
635
- }
636
- }, _callee);
637
- }));
638
- return _deleteFile.apply(this, arguments);
639
- }
640
-
641
- function buildODataParams(options, orderBySeparator) {
642
- if (orderBySeparator === void 0) {
643
- orderBySeparator = ',';
644
- }
645
- var _ref = options || {},
646
- expand = _ref.expand,
647
- orderBy = _ref.orderBy,
648
- limit = _ref.limit,
649
- filter = _ref.filter,
650
- cols = _ref.cols,
651
- skip = _ref.skip;
652
- var params = {
653
- $expand: Array.isArray(expand) ? expand.join(',') : expand,
654
- $top: limit,
655
- $skip: skip,
656
- $select: Array.isArray(cols) ? cols.join(',') : cols,
657
- $filter: filter,
658
- $orderby: Array.isArray(orderBy) ? orderBy.join(orderBySeparator) : orderBy
659
- };
660
- return params;
661
- }
662
- function appendParamsToUrl(baseUrl, params) {
663
- Object.entries(params).forEach(function (_ref2) {
664
- var key = _ref2[0],
665
- value = _ref2[1];
666
- if (value !== undefined && value !== null) {
667
- baseUrl.searchParams.append(key, String(value));
668
- }
669
- });
670
- }
671
-
672
- function getFiles(_x, _x2) {
673
- return _getFiles.apply(this, arguments);
674
- }
675
- function _getFiles() {
676
- _getFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, options) {
677
- var _ref, _response$data$d$resu, _response$data, _response$data2;
678
- var params, url, response, data, meta;
679
- return _regenerator().w(function (_context) {
680
- while (1) switch (_context.n) {
681
- case 0:
682
- params = buildODataParams(options, ',');
683
- url = new URL(context.endpoint, context.instance.defaults.baseURL);
684
- appendParamsToUrl(url, params);
685
- _context.n = 1;
686
- return context.instance.request({
687
- url: context.endpoint,
688
- method: 'GET',
689
- params: params
690
- });
691
- case 1:
692
- response = _context.v;
693
- data = (_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;
694
- meta = {
695
- url: url
696
- };
697
- return _context.a(2, {
698
- data: data,
699
- meta: meta
700
- });
701
- }
702
- }, _callee);
703
- }));
704
- return _getFiles.apply(this, arguments);
705
- }
706
-
707
- function getListItems(_x, _x2) {
708
- return _getListItems.apply(this, arguments);
709
- }
710
- function _getListItems() {
711
- _getListItems = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, options) {
712
- var _ref, _response$data$d$resu, _response$data, _response$data2;
713
- var params, url, response, rawData, cols, keys, filterItem, data, meta;
714
- return _regenerator().w(function (_context) {
715
- while (1) switch (_context.n) {
716
- case 0:
717
- params = buildODataParams(options, ' ');
718
- url = new URL(context.endpoint, context.instance.defaults.baseURL);
719
- appendParamsToUrl(url, params);
720
- _context.n = 1;
721
- return context.instance.request({
722
- url: context.endpoint,
723
- method: 'GET',
724
- params: params
725
- });
726
- case 1:
727
- response = _context.v;
728
- 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;
729
- cols = options == null ? void 0 : options.cols;
730
- keys = cols ? (Array.isArray(cols) ? cols : [cols]).filter(Boolean) : undefined;
731
- filterItem = function filterItem(item) {
732
- if (!keys || !item || typeof item !== 'object') {
733
- return item;
734
- }
735
- return keys.reduce(function (acc, key) {
736
- if (key in item) {
737
- acc[key] = item[key];
738
- }
739
- return acc;
740
- }, {});
741
- };
742
- data = Array.isArray(rawData) ? rawData.map(filterItem) : filterItem(rawData);
743
- meta = {
744
- url: url
745
- };
746
- return _context.a(2, {
747
- data: data,
748
- meta: meta
749
- });
750
- }
751
- }, _callee);
752
- }));
753
- return _getListItems.apply(this, arguments);
754
- }
755
-
756
- function getOnly(_x, _x2, _x3) {
757
- return _getOnly.apply(this, arguments);
758
- }
759
- function _getOnly() {
760
- _getOnly = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, endpoint, options) {
761
- var params, _yield$instance$get, data;
762
- return _regenerator().w(function (_context) {
763
- while (1) switch (_context.n) {
764
- case 0:
765
- params = buildODataParams(options, ',');
766
- _context.n = 1;
767
- return instance.get(endpoint, {
768
- params: params
769
- });
770
- case 1:
771
- _yield$instance$get = _context.v;
772
- data = _yield$instance$get.data;
773
- if (data) {
774
- _context.n = 2;
775
- break;
776
- }
777
- return _context.a(2, undefined);
778
- case 2:
779
- if (!data.d) {
780
- _context.n = 3;
781
- break;
782
- }
783
- return _context.a(2, data.d.results ? data.d.results : data.d);
784
- case 3:
785
- return _context.a(2, data);
786
- }
787
- }, _callee);
788
- }));
789
- return _getOnly.apply(this, arguments);
790
- }
791
-
792
- function resolveMetadataType$1(_x) {
793
- return _resolveMetadataType$1.apply(this, arguments);
794
- }
795
- function _resolveMetadataType$1() {
796
- _resolveMetadataType$1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context) {
797
- return _regenerator().w(function (_context) {
798
- while (1) switch (_context.n) {
799
- case 0:
800
- if (!context.resolveListItemEntityType) {
801
- _context.n = 1;
802
- break;
803
- }
804
- return _context.a(2, context.resolveListItemEntityType());
805
- case 1:
806
- if (!context.listItemEntityTypeFullName) {
807
- _context.n = 2;
808
- break;
809
- }
810
- return _context.a(2, context.listItemEntityTypeFullName);
811
- case 2:
812
- return _context.a(2, "SP.Data." + context.listName + "ListItem");
813
- }
814
- }, _callee);
815
- }));
816
- return _resolveMetadataType$1.apply(this, arguments);
817
- }
818
- function updateListItem(_x2, _x3, _x4, _x5) {
819
- return _updateListItem.apply(this, arguments);
820
- }
821
- function _updateListItem() {
822
- _updateListItem = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(context, id, data, digest) {
823
- var formDigestValue, normalizedData, payload, metadataType, userMetadata, url, response, _t;
824
- return _regenerator().w(function (_context2) {
825
- while (1) switch (_context2.n) {
826
- case 0:
827
- _t = digest;
828
- if (_t) {
829
- _context2.n = 2;
830
- break;
831
- }
832
- _context2.n = 1;
833
- return fetchDigest(context.instance, context.baseURL);
834
- case 1:
835
- _t = _context2.v;
836
- case 2:
837
- formDigestValue = _t;
838
- normalizedData = normalizeListPayload(data);
839
- payload = normalizedData;
840
- if (!(context.sharepointVersion === '2013')) {
841
- _context2.n = 4;
842
- break;
843
- }
844
- _context2.n = 3;
845
- return resolveMetadataType$1(context);
846
- case 3:
847
- metadataType = _context2.v;
848
- userMetadata = data.__metadata;
849
- payload = _extends({}, normalizedData, {
850
- __metadata: _extends({}, userMetadata && typeof userMetadata === 'object' ? userMetadata : {}, {
851
- type: metadataType
852
- })
853
- });
854
- case 4:
855
- url = context.sharepointVersion === '2013' ? buildListByTitleEndpoint(context.listName) + "/items(" + id + ")" : context.endpoint + "(" + id + ")";
856
- _context2.n = 5;
857
- return context.instance({
858
- url: url,
859
- method: 'POST',
860
- data: JSON.stringify(payload),
861
- headers: {
862
- 'X-RequestDigest': formDigestValue,
863
- 'IF-MATCH': '*',
864
- 'X-HTTP-Method': 'MERGE'
865
- }
866
- });
867
- case 5:
868
- response = _context2.v;
869
- return _context2.a(2, response);
870
- }
871
- }, _callee2);
872
- }));
873
- return _updateListItem.apply(this, arguments);
874
- }
875
-
876
- var SUPPORTED_VERSION$1 = '2013';
877
- function uploadFile(_x, _x2) {
878
- return _uploadFile.apply(this, arguments);
879
- }
880
- function _uploadFile() {
881
- _uploadFile = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, _ref) {
882
- var _response$data$d, _response$data, _ref2, _ref3, _listItemFields$Id, _listItemFields$__def;
883
- var file, folderPath, _ref$overwrite, overwrite, requestUrl, encodedFileName, digest, response, responseData, listItemFields, itemId, _listItemResponse$dat, _listItemResponse$dat2, _listItemResponse$dat3, listItemResponse, deferredId;
884
- return _regenerator().w(function (_context) {
885
- while (1) switch (_context.n) {
886
- case 0:
887
- file = _ref.file, folderPath = _ref.folderPath, _ref$overwrite = _ref.overwrite, overwrite = _ref$overwrite === void 0 ? true : _ref$overwrite;
888
- if (!(context.sharepointVersion !== SUPPORTED_VERSION$1)) {
889
- _context.n = 1;
890
- break;
891
- }
892
- throw new Error('uploadFile is only supported for SharePoint 2013 REST endpoints.');
893
- case 1:
894
- if (file != null && file.name) {
895
- _context.n = 2;
896
- break;
897
- }
898
- throw new Error('A file with a valid name must be provided.');
899
- case 2:
900
- requestUrl = buildListByTitleEndpoint(context.listName) + "/RootFolder";
901
- requestUrl += buildLibraryPath(folderPath);
902
- encodedFileName = encodeFileName(file.name);
903
- requestUrl += "/Files/add(url='" + encodedFileName + "',overwrite=" + (overwrite ? 'true' : 'false') + ")?$expand=ListItemAllFields&$select=ListItemAllFields/Id";
904
- _context.n = 3;
905
- return fetchDigest(context.instance, context.baseURL);
906
- case 3:
907
- digest = _context.v;
908
- _context.n = 4;
909
- return context.instance.post(requestUrl, file, {
910
- headers: {
911
- 'Content-Type': file.type || 'application/octet-stream',
912
- 'X-RequestDigest': digest
913
- },
914
- withCredentials: true
915
- });
916
- case 4:
917
- response = _context.v;
918
- responseData = (_response$data$d = (_response$data = response.data) == null ? void 0 : _response$data.d) != null ? _response$data$d : response.data;
919
- listItemFields = responseData == null ? void 0 : responseData.ListItemAllFields;
920
- itemId = (_ref2 = (_ref3 = (_listItemFields$Id = listItemFields == null ? void 0 : listItemFields.Id) != null ? _listItemFields$Id : listItemFields == null ? void 0 : listItemFields.ID) != null ? _ref3 : responseData == null ? void 0 : responseData.Id) != null ? _ref2 : responseData == null ? void 0 : responseData.ID;
921
- if (!(typeof itemId !== 'undefined')) {
922
- _context.n = 5;
923
- break;
924
- }
925
- response.itemId = itemId;
926
- _context.n = 7;
927
- break;
928
- case 5:
929
- if (!(listItemFields != null && (_listItemFields$__def = listItemFields.__deferred) != null && _listItemFields$__def.uri)) {
930
- _context.n = 7;
931
- break;
932
- }
933
- _context.n = 6;
934
- return context.instance.get(listItemFields.__deferred.uri);
935
- case 6:
936
- listItemResponse = _context.v;
937
- deferredId = (_listItemResponse$dat = (_listItemResponse$dat2 = listItemResponse.data) == null || (_listItemResponse$dat2 = _listItemResponse$dat2.d) == null ? void 0 : _listItemResponse$dat2.Id) != null ? _listItemResponse$dat : (_listItemResponse$dat3 = listItemResponse.data) == null ? void 0 : _listItemResponse$dat3.Id;
938
- if (typeof deferredId !== 'undefined') {
939
- response.itemId = deferredId;
940
- }
941
- case 7:
942
- return _context.a(2, response);
943
- }
944
- }, _callee);
945
- }));
946
- return _uploadFile.apply(this, arguments);
947
- }
948
-
949
- function typeAhead(_x, _x2, _x3) {
950
- return _typeAhead.apply(this, arguments);
951
- }
952
- function _typeAhead() {
953
- _typeAhead = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(instance, input, filter) {
954
- var _response$data$d$Clie, _response$data, _response$data2;
955
- var requestUrl, data, response, searchResults, parsed;
956
- return _regenerator().w(function (_context) {
957
- while (1) switch (_context.n) {
958
- case 0:
959
- requestUrl = "_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";
960
- data = {
961
- queryParams: {
962
- __metadata: {
963
- type: 'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'
964
- },
965
- AllowEmailAddresses: true,
966
- AllowMultipleEntities: false,
967
- AllUrlZones: false,
968
- MaximumEntitySuggestions: 10,
969
- PrincipalSource: 15,
970
- PrincipalType: 1,
971
- QueryString: input
972
- }
973
- };
974
- if (filter) {
975
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
976
- data.queryParams.RequiredProperties = [filter];
977
- }
978
- _context.n = 1;
979
- return instance.post(requestUrl, JSON.stringify(data), {
980
- headers: {
981
- Accept: 'application/json; odata=verbose',
982
- 'Content-Type': 'application/json;odata=verbose'
983
- }
984
- });
985
- case 1:
986
- response = _context.v;
987
- searchResults = (_response$data$d$Clie = (_response$data = response.data) == null || (_response$data = _response$data.d) == null ? void 0 : _response$data.ClientPeoplePickerSearchUser) != null ? _response$data$d$Clie : (_response$data2 = response.data) == null ? void 0 : _response$data2.ClientPeoplePickerSearchUser;
988
- if (!(typeof searchResults === 'string')) {
989
- _context.n = 3;
990
- break;
991
- }
992
- parsed = JSON.parse(searchResults);
993
- if (!(Array.isArray(parsed) && parsed.length > 0)) {
994
- _context.n = 2;
995
- break;
996
- }
997
- return _context.a(2, parsed[0]);
998
- case 2:
999
- throw new Error('People picker returned no results.');
1000
- case 3:
1001
- if (!(Array.isArray(searchResults) && searchResults.length > 0)) {
1002
- _context.n = 4;
1003
- break;
1004
- }
1005
- return _context.a(2, searchResults[0]);
1006
- case 4:
1007
- if (!(searchResults && typeof searchResults === 'object')) {
1008
- _context.n = 5;
1009
- break;
1010
- }
1011
- return _context.a(2, searchResults);
1012
- case 5:
1013
- throw new Error('Invalid people picker response.');
1014
- case 6:
1015
- return _context.a(2);
1016
- }
1017
- }, _callee);
1018
- }));
1019
- return _typeAhead.apply(this, arguments);
1020
- }
1021
- function currentUserProperties(_x4) {
1022
- return _currentUserProperties.apply(this, arguments);
1023
- }
1024
- function _currentUserProperties() {
1025
- _currentUserProperties = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(instance) {
1026
- var requestUrl, profile;
1027
- return _regenerator().w(function (_context2) {
1028
- while (1) switch (_context2.n) {
1029
- case 0:
1030
- requestUrl = '_api/sp.userprofiles.peoplemanager/getmyproperties';
1031
- _context2.n = 1;
1032
- return instance.get(requestUrl);
1033
- case 1:
1034
- profile = _context2.v;
1035
- profile = profile.data.d;
1036
- profile.UserProfileProperties.results.forEach(function (prop) {
1037
- if (prop.Key === 'FirstName') {
1038
- profile.FirstName = prop.Value;
1039
- }
1040
- if (prop.Key === 'LastName') {
1041
- profile.LastName = prop.Value;
1042
- }
1043
- if (prop.Key === 'Country') {
1044
- profile.Country = prop.Value;
1045
- }
1046
- if (prop.Key === 'UserName') {
1047
- profile.UserName = prop.Value;
1048
- }
1049
- });
1050
- return _context2.a(2, profile);
1051
- }
1052
- }, _callee2);
1053
- }));
1054
- return _currentUserProperties.apply(this, arguments);
1055
- }
1056
- function getSiteUser(_x5, _x6) {
1057
- return _getSiteUser.apply(this, arguments);
1058
- }
1059
- function _getSiteUser() {
1060
- _getSiteUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(instance, searchValue) {
1061
- var safeSearchValue, response;
1062
- return _regenerator().w(function (_context3) {
1063
- while (1) switch (_context3.n) {
1064
- case 0:
1065
- safeSearchValue = escapeODataStringLiteral(searchValue);
1066
- _context3.n = 1;
1067
- return instance.get('_api/web/siteusers', {
1068
- params: {
1069
- $filter: "substringof('" + safeSearchValue + "', Title) or substringof('" + safeSearchValue + "', LoginName) or substringof('" + safeSearchValue + "', Email)",
1070
- $top: 50,
1071
- $expand: 'Groups'
1072
- }
1073
- });
1074
- case 1:
1075
- response = _context3.v;
1076
- return _context3.a(2, response.data.d);
1077
- }
1078
- }, _callee3);
1079
- }));
1080
- return _getSiteUser.apply(this, arguments);
1081
- }
1082
- function roleDefinitions(_x7) {
1083
- return _roleDefinitions.apply(this, arguments);
1084
- }
1085
- function _roleDefinitions() {
1086
- _roleDefinitions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(instance) {
1087
- var requestUrl, response;
1088
- return _regenerator().w(function (_context4) {
1089
- while (1) switch (_context4.n) {
1090
- case 0:
1091
- requestUrl = "_api/Web/RoleDefinitions";
1092
- _context4.n = 1;
1093
- return instance.get(requestUrl);
1094
- case 1:
1095
- response = _context4.v;
1096
- return _context4.a(2, response.data.d.results);
1097
- }
1098
- }, _callee4);
1099
- }));
1100
- return _roleDefinitions.apply(this, arguments);
1101
- }
1102
- function getEffectiveBasePermissions(_x8) {
1103
- return _getEffectiveBasePermissions.apply(this, arguments);
1104
- }
1105
- function _getEffectiveBasePermissions() {
1106
- _getEffectiveBasePermissions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(instance) {
1107
- var requestUrl, response;
1108
- return _regenerator().w(function (_context5) {
1109
- while (1) switch (_context5.n) {
1110
- case 0:
1111
- requestUrl = "_api/Web/effectiveBasePermissions";
1112
- _context5.n = 1;
1113
- return instance.get(requestUrl);
1114
- case 1:
1115
- response = _context5.v;
1116
- return _context5.a(2, response.data.d.EffectiveBasePermissions);
1117
- }
1118
- }, _callee5);
1119
- }));
1120
- return _getEffectiveBasePermissions.apply(this, arguments);
1121
- }
1122
- function currentUserPermissions(_x9) {
1123
- return _currentUserPermissions.apply(this, arguments);
1124
- }
1125
- function _currentUserPermissions() {
1126
- _currentUserPermissions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(context) {
1127
- var _yield$getEffectiveBa, High, definitions, result;
1128
- return _regenerator().w(function (_context6) {
1129
- while (1) switch (_context6.n) {
1130
- case 0:
1131
- _context6.n = 1;
1132
- return getEffectiveBasePermissions(context.instance);
1133
- case 1:
1134
- _yield$getEffectiveBa = _context6.v;
1135
- High = _yield$getEffectiveBa.High;
1136
- _context6.n = 2;
1137
- return roleDefinitions(context.instance);
1138
- case 2:
1139
- definitions = _context6.v;
1140
- result = definitions.find(function (_ref) {
1141
- var BasePermissions = _ref.BasePermissions;
1142
- return BasePermissions.High === High;
1143
- });
1144
- if (result) {
1145
- _context6.n = 3;
1146
- break;
1147
- }
1148
- throw new Error("Unable to resolve current user permission for BasePermissions.High=\"" + High + "\".");
1149
- case 3:
1150
- return _context6.a(2, result);
1151
- }
1152
- }, _callee6);
1153
- }));
1154
- return _currentUserPermissions.apply(this, arguments);
1155
- }
1156
-
1157
- var HTTPSharePointRequests = /*#__PURE__*/function () {
1158
- function HTTPSharePointRequests(baseURL, config) {
1159
- var _this = this;
1160
- this.baseURL = void 0;
1161
- this.instance = void 0;
1162
- this.listItemEntityTypeCache = void 0;
1163
- this.email = void 0;
1164
- this.user = {
1165
- properties: function properties() {
1166
- return {
1167
- get: function get() {
1168
- return currentUserProperties(_this.instance);
1169
- }
1170
- };
1171
- },
1172
- searchSiteUser: function searchSiteUser(searchValue) {
1173
- return getSiteUser(_this.instance, searchValue);
1174
- },
1175
- searchUser: function searchUser(input, filter) {
1176
- return typeAhead(_this.instance, input, filter);
1177
- },
1178
- current: function current() {
1179
- return {
1180
- get: function get() {
1181
- return getOnly(_this.instance, '_api/web/currentUser');
1182
- }
1183
- };
1184
- },
1185
- currentPermission: function currentPermission() {
1186
- return {
1187
- get: function get() {
1188
- return currentUserPermissions(_this.createContext({
1189
- endpoint: '_api/web/effectiveBasePermissions',
1190
- listName: '',
1191
- sharepointVersion: '2013'
1192
- }));
1193
- }
1194
- };
1195
- }
1196
- };
1197
- this.baseURL = baseURL.endsWith('/') ? baseURL : baseURL + "/";
1198
- this.instance = instance(this.baseURL, config);
1199
- this.listItemEntityTypeCache = new Map();
1200
- this.email = Object.assign(function (from, to, subject, body) {
1201
- return _this.sendEmail({
1202
- From: from,
1203
- To: to,
1204
- Subject: subject,
1205
- Body: body
1206
- });
1207
- }, {
1208
- send: function send(props) {
1209
- return _this.sendEmail(props);
1210
- }
1211
- });
1212
- }
1213
- var _proto = HTTPSharePointRequests.prototype;
1214
- _proto.createContext = function createContext(_ref) {
1215
- var endpoint = _ref.endpoint,
1216
- listName = _ref.listName,
1217
- sharepointVersion = _ref.sharepointVersion,
1218
- listItemEntityTypeFullName = _ref.listItemEntityTypeFullName,
1219
- resolveListItemEntityType = _ref.resolveListItemEntityType;
1220
- return {
1221
- instance: this.instance,
1222
- baseURL: this.baseURL,
1223
- endpoint: endpoint,
1224
- listName: listName,
1225
- sharepointVersion: sharepointVersion,
1226
- listItemEntityTypeFullName: listItemEntityTypeFullName,
1227
- resolveListItemEntityType: resolveListItemEntityType
1228
- };
1229
- };
1230
- _proto.resolveListItemEntityTypeFullName = /*#__PURE__*/function () {
1231
- var _resolveListItemEntityTypeFullName = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(listName) {
1232
- var _response$data$d$List, _response$data, _response$data2;
1233
- var cacheKey, cachedType, response, entityType;
1234
- return _regenerator().w(function (_context) {
1235
- while (1) switch (_context.n) {
1236
- case 0:
1237
- cacheKey = listName;
1238
- cachedType = this.listItemEntityTypeCache.get(cacheKey);
1239
- if (!cachedType) {
1240
- _context.n = 1;
1241
- break;
1242
- }
1243
- return _context.a(2, cachedType);
1244
- case 1:
1245
- _context.n = 2;
1246
- return this.instance.get(buildListByTitleEndpoint(listName) + "?$select=ListItemEntityTypeFullName");
1247
- case 2:
1248
- response = _context.v;
1249
- entityType = (_response$data$d$List = (_response$data = response.data) == null || (_response$data = _response$data.d) == null ? void 0 : _response$data.ListItemEntityTypeFullName) != null ? _response$data$d$List : (_response$data2 = response.data) == null ? void 0 : _response$data2.ListItemEntityTypeFullName;
1250
- if (!(!entityType || typeof entityType !== 'string')) {
1251
- _context.n = 3;
1252
- break;
1253
- }
1254
- throw new Error("Unable to resolve ListItemEntityTypeFullName for list \"" + listName + "\".");
1255
- case 3:
1256
- this.listItemEntityTypeCache.set(cacheKey, entityType);
1257
- return _context.a(2, entityType);
1258
- }
1259
- }, _callee, this);
1260
- }));
1261
- function resolveListItemEntityTypeFullName(_x) {
1262
- return _resolveListItemEntityTypeFullName.apply(this, arguments);
1263
- }
1264
- return resolveListItemEntityTypeFullName;
1265
- }();
1266
- _proto.buildListScope = function buildListScope(listName, version) {
1267
- var _this2 = this;
1268
- var listNameValue = String(listName);
1269
- var endpoint = version === '2013' ? buildListByTitleEndpoint(listNameValue) + "/items" : "_vti_bin/ListData.svc/" + encodeURIComponent(listNameValue);
1270
- var scopedEntityType;
1271
- var resolveListItemEntityType = /*#__PURE__*/function () {
1272
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
1273
- return _regenerator().w(function (_context2) {
1274
- while (1) switch (_context2.n) {
1275
- case 0:
1276
- if (!scopedEntityType) {
1277
- _context2.n = 1;
1278
- break;
1279
- }
1280
- return _context2.a(2, scopedEntityType);
1281
- case 1:
1282
- if (!(version !== '2013')) {
1283
- _context2.n = 2;
1284
- break;
1285
- }
1286
- scopedEntityType = "SP.Data." + listNameValue + "ListItem";
1287
- return _context2.a(2, scopedEntityType);
1288
- case 2:
1289
- _context2.n = 3;
1290
- return _this2.resolveListItemEntityTypeFullName(listNameValue);
1291
- case 3:
1292
- scopedEntityType = _context2.v;
1293
- return _context2.a(2, scopedEntityType);
1294
- }
1295
- }, _callee2);
1296
- }));
1297
- return function resolveListItemEntityType() {
1298
- return _ref2.apply(this, arguments);
1299
- };
1300
- }();
1301
- var getContext = function getContext() {
1302
- return _this2.createContext({
1303
- endpoint: endpoint,
1304
- listName: listNameValue,
1305
- sharepointVersion: version,
1306
- listItemEntityTypeFullName: scopedEntityType,
1307
- resolveListItemEntityType: resolveListItemEntityType
1308
- });
1309
- };
1310
- var removeItem = function removeItem(id) {
1311
- return deleteItem(getContext(), id);
1312
- };
1313
- var removeFile = function removeFile(props) {
1314
- return deleteFile(getContext(), props);
1315
- };
1316
- return {
1317
- create: function create(data) {
1318
- return createListItem(getContext(), data);
1319
- },
1320
- get: function get(options) {
1321
- return getListItems(getContext(), options);
1322
- },
1323
- update: function update(id, data, digest) {
1324
- return updateListItem(getContext(), id, data, digest);
1325
- },
1326
- "delete": removeItem,
1327
- remove: removeItem,
1328
- createFile: function createFile(props) {
1329
- return createAttachment(getContext(), props);
1330
- },
1331
- uploadFile: function uploadFile$1(props) {
1332
- return uploadFile(getContext(), props);
1333
- },
1334
- deleteFile: removeFile,
1335
- removeFile: removeFile,
1336
- fields: function fields(options) {
1337
- var fieldsEndpoint = !(options != null && options.fieldName) ? buildListByTitleEndpoint(listNameValue) + "/fields" : buildListByTitleEndpoint(listNameValue) + "/fields/getbytitle('" + escapeODataStringLiteral(String(options.fieldName)) + "')";
1338
- return {
1339
- get: function get() {
1340
- return getOnly(_this2.instance, fieldsEndpoint, options);
1341
- }
1342
- };
1343
- },
1344
- items: {
1345
- create: function create(data) {
1346
- return createListItem(getContext(), data);
1347
- },
1348
- get: function get(options) {
1349
- return getListItems(getContext(), options);
1350
- },
1351
- update: function update(id, data, digest) {
1352
- return updateListItem(getContext(), id, data, digest);
1353
- },
1354
- "delete": removeItem,
1355
- remove: removeItem
1356
- },
1357
- files: {
1358
- attach: function attach(props) {
1359
- return createAttachment(getContext(), props);
1360
- },
1361
- upload: function upload(props) {
1362
- return uploadFile(getContext(), props);
1363
- },
1364
- "delete": removeFile,
1365
- remove: removeFile
1366
- }
1367
- };
1368
- }
1369
- /**
1370
- * @deprecated Use `from(listName, '2010')` instead.
1371
- */;
1372
- _proto.list = function list(listName) {
1373
- return this.from(listName, '2010');
1374
- };
1375
- _proto.from = function from(listName, sharepointVersion) {
1376
- var version = sharepointVersion != null ? sharepointVersion : '2013';
1377
- return this.buildListScope(listName, version);
1378
- };
1379
- _proto.field = function field(listName, fieldName, sharepointVersion) {
1380
- return this.from(listName, sharepointVersion).fields({
1381
- fieldName: fieldName
1382
- }).get();
1383
- };
1384
- _proto.lists = function lists(options) {
1385
- var context = this.createContext({
1386
- endpoint: '_api/web/lists',
1387
- listName: '',
1388
- sharepointVersion: '2013'
1389
- });
1390
- return {
1391
- get: function get() {
1392
- return getListItems(context, options);
1393
- }
1394
- };
1395
- };
1396
- _proto.getDigest = function getDigest() {
1397
- return fetchDigest(this.instance, this.baseURL);
1398
- };
1399
- _proto.folders = function folders(options) {
1400
- var context = this.createContext({
1401
- endpoint: '_api/web/folders',
1402
- listName: '',
1403
- sharepointVersion: '2013'
1404
- });
1405
- return {
1406
- get: function get() {
1407
- return getFiles(context, options);
1408
- }
1409
- };
1410
- };
1411
- _proto.folder = function folder(folderName) {
1412
- var _this3 = this;
1413
- var defaultPath = ['Shared Documents'];
1414
- var segments = folderName ? Array.isArray(folderName) ? [].concat(defaultPath, folderName) : [].concat(defaultPath, folderName.split('/').filter(Boolean)) : defaultPath;
1415
- var serverRelativePath = escapeODataStringLiteral(segments.join('/'));
1416
- var baseEndpoint = "_api/web/GetFolderByServerRelativeUrl('" + serverRelativePath + "')";
1417
- return {
1418
- get: function get(options) {
1419
- var _options$type;
1420
- var folderType = (_options$type = options == null ? void 0 : options.type) != null ? _options$type : 'Files';
1421
- var endpoint = baseEndpoint + "/" + folderType;
1422
- var context = _this3.createContext({
1423
- endpoint: endpoint,
1424
- listName: '',
1425
- sharepointVersion: '2013'
1426
- });
1427
- return getFiles(context, _extends({}, options, {
1428
- type: folderType
1429
- }));
1430
- }
1431
- };
1432
- };
1433
- _proto.users = function users(options) {
1434
- var context = this.createContext({
1435
- endpoint: '_api/web/SiteUserInfoList/items',
1436
- listName: '',
1437
- sharepointVersion: '2013'
1438
- });
1439
- return {
1440
- get: function get() {
1441
- return getListItems(context, options);
1442
- }
1443
- };
1444
- };
1445
- _proto.sendEmail = function sendEmail$1(props) {
1446
- var context = this.createContext({
1447
- endpoint: '_api/SP.Utilities.Utility.SendEmail',
1448
- listName: '',
1449
- sharepointVersion: '2013'
1450
- });
1451
- return sendEmail(context, props);
1452
- };
1453
- _proto.getCurrentUser = function getCurrentUser() {
1454
- return this.user.current().get();
1455
- };
1456
- _proto.currentUserProperties = function currentUserProperties() {
1457
- return this.user.properties().get();
1458
- };
1459
- _proto.currentUserPermission = function currentUserPermission() {
1460
- return this.user.currentPermission().get();
1461
- };
1462
- return HTTPSharePointRequests;
1463
- }();
1464
-
1465
- // Load environment variables from .env file
1466
- function createBase() {
1467
- function create(_ref) {
1468
- var baseURL = _ref.baseURL,
1469
- config = _ref.config;
1470
- if (!baseURL) {
1471
- throw new Error('A valid SharePoint URL must be provided.');
1472
- }
1473
- return new HTTPSharePointRequests(baseURL, config);
1474
- }
1475
- return {
1476
- /**
1477
- * @deprecated Use `create` instead.
1478
- */
1479
- baseURL: function baseURL(url, config) {
1480
- return create({
1481
- baseURL: url,
1482
- config: config
1483
- });
1484
- },
1485
- create: create
1486
- };
1487
- }
1488
-
1489
- export default createBase;
1490
- //# sourceMappingURL=sharepoint_requests.esm.js.map