@lindle/sharepoint_requests 0.1.10 → 0.1.12

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.
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
- var axios = _interopDefault(require('axios'));
7
+ var axios = require('axios');
8
+ var axios__default = _interopDefault(axios);
8
9
 
9
10
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
10
11
  try {
@@ -149,32 +150,49 @@ function _regeneratorDefine(e, r, n, t) {
149
150
  }, _regeneratorDefine(e, r, n, t);
150
151
  }
151
152
 
153
+ var defaultConfig = {
154
+ headers: {
155
+ Accept: 'application/json; odata=verbose',
156
+ 'Content-Type': 'application/json; odata=verbose'
157
+ },
158
+ timeout: 15000,
159
+ withCredentials: true
160
+ };
152
161
  var instance = function instance(baseURL, config) {
153
- if (config === void 0) {
154
- config = {
155
- headers: {
156
- Accept: 'application/json; odata=verbose',
157
- 'Content-Type': 'application/json; odata=verbose'
158
- },
159
- timeout: 1000,
160
- withCredentials: true
161
- };
162
- }
163
- return axios.create(_extends({
164
- baseURL: baseURL
165
- }, config));
162
+ var _config$headers;
163
+ var userHeaders = (config == null ? void 0 : config.headers) instanceof axios.AxiosHeaders ? config.headers.toJSON() : (_config$headers = config == null ? void 0 : config.headers) != null ? _config$headers : {};
164
+ return axios__default.create(_extends({}, defaultConfig, config, {
165
+ baseURL: baseURL,
166
+ headers: _extends({}, defaultConfig.headers, userHeaders)
167
+ }));
166
168
  };
167
169
 
168
170
  var HTTPSharePointRequests = /*#__PURE__*/function () {
169
- function HTTPSharePointRequests(baseURL) {
171
+ /**
172
+ * Creates an HTTP SharePoint requester bound to the provided base URL.
173
+ *
174
+ * @param baseURL The root SharePoint site URL (with or without trailing slash).
175
+ * @param config Optional axios configuration overrides.
176
+ */
177
+ function HTTPSharePointRequests(baseURL, config) {
170
178
  var _this = this;
171
179
  this.lists = {
180
+ /**
181
+ * Fetches all SharePoint lists available to the current site.
182
+ *
183
+ * @returns Promise resolving to the list collection response payload.
184
+ */
172
185
  get: function get() {
173
186
  _this.endpoint = '_api/web/lists';
174
187
  return _this.get_v2();
175
188
  }
176
189
  };
177
190
  this.folders = {
191
+ /**
192
+ * Retrieves SharePoint folders from the default folders endpoint.
193
+ *
194
+ * @returns A promise resolving with folder metadata.
195
+ */
178
196
  get: function get() {
179
197
  _this.endpoint = '_api/web/folders';
180
198
  _this.get_v2();
@@ -210,6 +228,11 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
210
228
  }
211
229
  };
212
230
  this.user = {
231
+ /**
232
+ * Provides accessors for the current user's profile information.
233
+ *
234
+ * @returns Helper exposing a `get` function to retrieve profile details.
235
+ */
213
236
  properties: function properties() {
214
237
  return {
215
238
  get: function get() {
@@ -217,12 +240,30 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
217
240
  }
218
241
  };
219
242
  },
243
+ /**
244
+ * Searches across site users and their groups.
245
+ *
246
+ * @param searchValue Query string to match site users.
247
+ * @returns Promise resolving to matching site users.
248
+ */
220
249
  searchSiteUser: function searchSiteUser(searchValue) {
221
250
  return _this.getSiteUser(searchValue);
222
251
  },
252
+ /**
253
+ * Performs a people-picker search scoped to the current site collection.
254
+ *
255
+ * @param input Search prefix.
256
+ * @param filter Optional additional filter condition.
257
+ * @returns Promise with type-ahead person results.
258
+ */
223
259
  searchUser: function searchUser(input, filter) {
224
260
  return _this.typeAhead(input, filter);
225
261
  },
262
+ /**
263
+ * Fetches the currently authenticated SharePoint user.
264
+ *
265
+ * @returns Helper exposing `get` that resolves to the current user payload.
266
+ */
226
267
  current: function current() {
227
268
  _this.endpoint = '_api/web/currentUser';
228
269
  return {
@@ -231,6 +272,11 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
231
272
  }
232
273
  };
233
274
  },
275
+ /**
276
+ * Retrieves calculated permission level for the current user.
277
+ *
278
+ * @returns Helper exposing `get` resolving to the user's permission definition.
279
+ */
234
280
  currentPermission: function currentPermission() {
235
281
  return {
236
282
  get: function get() {
@@ -242,8 +288,14 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
242
288
  this.baseURL = baseURL.endsWith('/') ? baseURL : baseURL + "/";
243
289
  this.endpoint = '/api';
244
290
  this.listName = '';
245
- this.instance = instance(this.baseURL);
291
+ this.instance = instance(this.baseURL, config);
246
292
  }
293
+ /**
294
+ * Converts array values in a payload to the `Collection(Edm.String)` structure
295
+ * expected by SharePoint REST endpoints.
296
+ *
297
+ * @param data The list item payload to harmonise in-place.
298
+ */
247
299
  var _proto = HTTPSharePointRequests.prototype;
248
300
  _proto.transformArraysToEdmStrings = function transformArraysToEdmStrings(data) {
249
301
  for (var key in data) {
@@ -264,7 +316,14 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
264
316
  this.listName = listName;
265
317
  this.endpoint = "_vti_bin/ListData.svc/" + listName;
266
318
  return this;
267
- };
319
+ }
320
+ /**
321
+ * Selects a SharePoint list and exposes list-scoped CRUD helpers.
322
+ *
323
+ * @param listName Logical list key configured in the generic type map.
324
+ * @param sharepoint_ver SharePoint version used to choose the correct REST endpoint.
325
+ * @returns Chainable helpers bound to the selected list.
326
+ */;
268
327
  _proto.from = function from(listName, sharepoint_ver) {
269
328
  var _this2 = this;
270
329
  if (sharepoint_ver === void 0) {
@@ -298,7 +357,13 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
298
357
  };
299
358
  }
300
359
  };
301
- };
360
+ }
361
+ /**
362
+ * Targets a SharePoint folder path and exposes file retrieval helpers.
363
+ *
364
+ * @param folderName Optional folder path relative to `Shared Documents`.
365
+ * @returns Helper exposing `get` to fetch files or sub-folders.
366
+ */;
302
367
  _proto.folder = function folder(folderName) {
303
368
  var _this3 = this;
304
369
  var filePath = ['Shared Documents'];
@@ -307,6 +372,12 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
307
372
  }
308
373
  this.endpoint = "_api/web/GetFolderByServerRelativeUrl('" + filePath.join('/') + "')";
309
374
  return {
375
+ /**
376
+ * Fetches files or folders from the targeted path.
377
+ *
378
+ * @param options Optional REST query options to refine the result set.
379
+ * @returns Promise resolving to folder contents and metadata.
380
+ */
310
381
  get: function get(options) {
311
382
  if (!(options != null && options.type)) {
312
383
  _this3.endpoint += '/Files';
@@ -316,11 +387,22 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
316
387
  return _this3.get_files(options);
317
388
  }
318
389
  };
319
- };
390
+ }
391
+ /**
392
+ * Retrieves user list items and exposes a get helper with optional query parameters.
393
+ *
394
+ * @param options Optional REST query options.
395
+ * @returns Helper exposing `get` returning SharePoint user rows.
396
+ */;
320
397
  _proto.users = function users(options) {
321
398
  var _this4 = this;
322
399
  this.endpoint = '_api/web/SiteUserInfoList/items';
323
400
  return {
401
+ /**
402
+ * Executes the user list request using the specified options.
403
+ *
404
+ * @returns Promise resolving to the SharePoint user list response.
405
+ */
324
406
  get: function get() {
325
407
  return _this4.get_v2(options);
326
408
  }
@@ -366,8 +448,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
366
448
  return _getDigest.apply(this, arguments);
367
449
  }
368
450
  return getDigest;
369
- }();
370
- _proto.get_only = /*#__PURE__*/function () {
451
+ }()
452
+ /**
453
+ * Executes a GET request without additional metadata wrapping.
454
+ *
455
+ * @param options Optional REST query options.
456
+ * @returns SharePoint response payload or undefined when empty.
457
+ */
458
+ ;
459
+ _proto.get_only =
460
+ /*#__PURE__*/
461
+ function () {
371
462
  var _get_only = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
372
463
  var _ref, expand, orderBy, limit, filter, cols, skip, params, _yield$this$instance$, data;
373
464
  return _regenerator().w(function (_context2) {
@@ -403,8 +494,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
403
494
  return _get_only.apply(this, arguments);
404
495
  }
405
496
  return get_only;
406
- }();
407
- _proto.get_files = /*#__PURE__*/function () {
497
+ }()
498
+ /**
499
+ * Retrieves folder contents with optional filtering and returns the payload with metadata.
500
+ *
501
+ * @param options REST options describing expand/filter/order conditions.
502
+ * @returns Folder data and the fully resolved request URL.
503
+ */
504
+ ;
505
+ _proto.get_files =
506
+ /*#__PURE__*/
507
+ function () {
408
508
  var _get_files = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
409
509
  var _ref2, expand, orderBy, limit, filter, cols, skip, params, url, response, data, meta;
410
510
  return _regenerator().w(function (_context3) {
@@ -450,8 +550,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
450
550
  return _get_files.apply(this, arguments);
451
551
  }
452
552
  return get_files;
453
- }();
454
- _proto.get_v2 = /*#__PURE__*/function () {
553
+ }()
554
+ /**
555
+ * Performs a typed list read against the current endpoint.
556
+ *
557
+ * @param options Optional REST query options governing expand, filter, ordering and pagination.
558
+ * @returns SharePoint list items alongside the fully-resolved request URL.
559
+ */
560
+ ;
561
+ _proto.get_v2 =
562
+ /*#__PURE__*/
563
+ function () {
455
564
  var _get_v = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(options) {
456
565
  var _ref4, expand, orderBy, limit, filter, cols, skip, params, url, response, data, meta;
457
566
  return _regenerator().w(function (_context4) {
@@ -497,8 +606,19 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
497
606
  return _get_v.apply(this, arguments);
498
607
  }
499
608
  return get_v2;
500
- }();
501
- _proto.update_2 = /*#__PURE__*/function () {
609
+ }()
610
+ /**
611
+ * Updates an item in the currently selected list.
612
+ *
613
+ * @param id Target list item identifier.
614
+ * @param data Payload with fields to update.
615
+ * @param digest Optional pre-fetched form digest to reuse.
616
+ * @returns Axios response of the update request.
617
+ */
618
+ ;
619
+ _proto.update_2 =
620
+ /*#__PURE__*/
621
+ function () {
502
622
  var _update_ = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(id, data, digest) {
503
623
  var formDigestValue, url, response, _t2;
504
624
  return _regenerator().w(function (_context5) {
@@ -540,8 +660,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
540
660
  return _update_.apply(this, arguments);
541
661
  }
542
662
  return update_2;
543
- }();
544
- _proto.create_v2 = /*#__PURE__*/function () {
663
+ }()
664
+ /**
665
+ * Creates a new item within the active list.
666
+ *
667
+ * @param listData SharePoint list item payload.
668
+ * @returns Axios response resolved from the create request.
669
+ */
670
+ ;
671
+ _proto.create_v2 =
672
+ /*#__PURE__*/
673
+ function () {
545
674
  var _create_v = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(listData) {
546
675
  var response, _t3, _t4, _t5, _t6, _t7;
547
676
  return _regenerator().w(function (_context6) {
@@ -579,8 +708,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
579
708
  return _create_v.apply(this, arguments);
580
709
  }
581
710
  return create_v2;
582
- }();
583
- _proto.createFile = /*#__PURE__*/function () {
711
+ }()
712
+ /**
713
+ * Uploads an attachment file to an existing list item.
714
+ *
715
+ * @param props File payload and target item identifier.
716
+ * @returns Axios response describing the upload result.
717
+ */
718
+ ;
719
+ _proto.createFile =
720
+ /*#__PURE__*/
721
+ function () {
584
722
  var _createFile = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(_ref6) {
585
723
  var file, itemId, requestUrl, res, _t8, _t9, _t0, _t1, _t10;
586
724
  return _regenerator().w(function (_context7) {
@@ -613,8 +751,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
613
751
  return _createFile.apply(this, arguments);
614
752
  }
615
753
  return createFile;
616
- }();
617
- _proto["delete"] = /*#__PURE__*/function () {
754
+ }()
755
+ /**
756
+ * Deletes an item using the current endpoint.
757
+ *
758
+ * @param ID Identifier of the entity to remove.
759
+ * @returns Axios response from the delete call.
760
+ */
761
+ ;
762
+ _proto["delete"] =
763
+ /*#__PURE__*/
764
+ function () {
618
765
  var _delete2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(ID) {
619
766
  var response;
620
767
  return _regenerator().w(function (_context8) {
@@ -682,8 +829,18 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
682
829
  return _sendEmail.apply(this, arguments);
683
830
  }
684
831
  return sendEmail;
685
- }();
686
- _proto.typeAhead = /*#__PURE__*/function () {
832
+ }()
833
+ /**
834
+ * Queries SharePoint's people picker endpoint for matching users.
835
+ *
836
+ * @param input Free-text search term.
837
+ * @param filter Optional additional filter condition.
838
+ * @returns Promise with type-ahead results payload.
839
+ */
840
+ ;
841
+ _proto.typeAhead =
842
+ /*#__PURE__*/
843
+ function () {
687
844
  var _typeAhead = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(input, filter) {
688
845
  var filterValue, response;
689
846
  return _regenerator().w(function (_context0) {
@@ -702,8 +859,16 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
702
859
  return _typeAhead.apply(this, arguments);
703
860
  }
704
861
  return typeAhead;
705
- }();
706
- _proto.currentUserProperties = /*#__PURE__*/function () {
862
+ }()
863
+ /**
864
+ * Retrieves the current user profile and flattens selected properties.
865
+ *
866
+ * @returns Promise containing the current user's profile information.
867
+ */
868
+ ;
869
+ _proto.currentUserProperties =
870
+ /*#__PURE__*/
871
+ function () {
707
872
  var _currentUserProperties = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
708
873
  var requestUrl, profile;
709
874
  return _regenerator().w(function (_context1) {
@@ -737,8 +902,17 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
737
902
  return _currentUserProperties.apply(this, arguments);
738
903
  }
739
904
  return currentUserProperties;
740
- }();
741
- _proto.getSiteUser = /*#__PURE__*/function () {
905
+ }()
906
+ /**
907
+ * Searches site users based on a substring match across common fields.
908
+ *
909
+ * @param searchValue Term to match against the SharePoint user directory.
910
+ * @returns Promise with matching site users and their groups.
911
+ */
912
+ ;
913
+ _proto.getSiteUser =
914
+ /*#__PURE__*/
915
+ function () {
742
916
  var _getSiteUser = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(searchValue) {
743
917
  var requestUrl, response;
744
918
  return _regenerator().w(function (_context10) {
@@ -757,8 +931,16 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
757
931
  return _getSiteUser.apply(this, arguments);
758
932
  }
759
933
  return getSiteUser;
760
- }();
761
- _proto.roleDefinitions = /*#__PURE__*/function () {
934
+ }()
935
+ /**
936
+ * Retrieves all available role definitions for the current site.
937
+ *
938
+ * @returns Promise resolving to an array of role definitions.
939
+ */
940
+ ;
941
+ _proto.roleDefinitions =
942
+ /*#__PURE__*/
943
+ function () {
762
944
  var _roleDefinitions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
763
945
  var requestUrl, response;
764
946
  return _regenerator().w(function (_context11) {
@@ -777,8 +959,16 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
777
959
  return _roleDefinitions.apply(this, arguments);
778
960
  }
779
961
  return roleDefinitions;
780
- }();
781
- _proto.getEffectiveBasePermissions = /*#__PURE__*/function () {
962
+ }()
963
+ /**
964
+ * Fetches the bit-encoded permissions of the current user.
965
+ *
966
+ * @returns Promise resolving to the `EffectiveBasePermissions` object.
967
+ */
968
+ ;
969
+ _proto.getEffectiveBasePermissions =
970
+ /*#__PURE__*/
971
+ function () {
782
972
  var _getEffectiveBasePermissions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
783
973
  var requestUrl, response;
784
974
  return _regenerator().w(function (_context12) {
@@ -797,8 +987,16 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
797
987
  return _getEffectiveBasePermissions.apply(this, arguments);
798
988
  }
799
989
  return getEffectiveBasePermissions;
800
- }();
801
- _proto.currentUserPermissions = /*#__PURE__*/function () {
990
+ }()
991
+ /**
992
+ * Matches the current user's effective permissions against known role definitions.
993
+ *
994
+ * @returns The matching SharePoint role definition as a structured permission object.
995
+ */
996
+ ;
997
+ _proto.currentUserPermissions =
998
+ /*#__PURE__*/
999
+ function () {
802
1000
  var _currentUserPermissions = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
803
1001
  var _yield$this$getEffect, High, roleDefinitions, result;
804
1002
  return _regenerator().w(function (_context13) {
@@ -832,19 +1030,21 @@ var HTTPSharePointRequests = /*#__PURE__*/function () {
832
1030
  // Load environment variables from .env file
833
1031
  function createBase() {
834
1032
  function create(_ref) {
835
- var baseURL = _ref.baseURL;
1033
+ var baseURL = _ref.baseURL,
1034
+ config = _ref.config;
836
1035
  if (!baseURL) {
837
1036
  throw new Error('A valid SharePoint URL must be provided.');
838
1037
  }
839
- return new HTTPSharePointRequests(baseURL);
1038
+ return new HTTPSharePointRequests(baseURL, config);
840
1039
  }
841
1040
  return {
842
1041
  /**
843
1042
  * @deprecated Use `create` instead.
844
1043
  */
845
- baseURL: function baseURL(url) {
1044
+ baseURL: function baseURL(url, config) {
846
1045
  return create({
847
- baseURL: url
1046
+ baseURL: url,
1047
+ config: config
848
1048
  });
849
1049
  },
850
1050
  create: create