@kwiz/common 1.0.4 → 1.0.6

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 (71) hide show
  1. package/dist/helpers/base64.js +10 -21
  2. package/dist/helpers/base64.js.map +1 -1
  3. package/dist/helpers/browser.d.ts +13 -5
  4. package/dist/helpers/browser.js +61 -39
  5. package/dist/helpers/browser.js.map +1 -1
  6. package/dist/helpers/collections.base.js +46 -65
  7. package/dist/helpers/collections.base.js.map +1 -1
  8. package/dist/helpers/collections.js +4 -1
  9. package/dist/helpers/collections.js.map +1 -1
  10. package/dist/helpers/date.d.ts +2 -1
  11. package/dist/helpers/date.js +22 -3
  12. package/dist/helpers/date.js.map +1 -1
  13. package/dist/helpers/debug.js +9 -20
  14. package/dist/helpers/debug.js.map +1 -1
  15. package/dist/helpers/objects.js +2 -11
  16. package/dist/helpers/objects.js.map +1 -1
  17. package/dist/helpers/promises.js +28 -41
  18. package/dist/helpers/promises.js.map +1 -1
  19. package/dist/helpers/strings.js +2 -1
  20. package/dist/helpers/strings.js.map +1 -1
  21. package/dist/utils/base64.js +18 -29
  22. package/dist/utils/base64.js.map +1 -1
  23. package/dist/utils/consolelogger.js +16 -27
  24. package/dist/utils/consolelogger.js.map +1 -1
  25. package/dist/utils/emails.js +5 -2
  26. package/dist/utils/emails.js.map +1 -1
  27. package/dist/utils/knownscript.js +4 -15
  28. package/dist/utils/knownscript.js.map +1 -1
  29. package/dist/utils/localstoragecache.js +3 -3
  30. package/dist/utils/localstoragecache.js.map +1 -1
  31. package/dist/utils/rest.d.ts +2 -0
  32. package/dist/utils/rest.js +18 -5
  33. package/dist/utils/rest.js.map +1 -1
  34. package/dist/utils/script.js +25 -40
  35. package/dist/utils/script.js.map +1 -1
  36. package/dist/utils/sharepoint.rest/file.folder.d.ts +2 -0
  37. package/dist/utils/sharepoint.rest/file.folder.js +123 -123
  38. package/dist/utils/sharepoint.rest/file.folder.js.map +1 -1
  39. package/dist/utils/sharepoint.rest/item.d.ts +10 -0
  40. package/dist/utils/sharepoint.rest/item.js +233 -237
  41. package/dist/utils/sharepoint.rest/item.js.map +1 -1
  42. package/dist/utils/sharepoint.rest/list.d.ts +30 -1
  43. package/dist/utils/sharepoint.rest/list.js +296 -289
  44. package/dist/utils/sharepoint.rest/list.js.map +1 -1
  45. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +352 -360
  46. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
  47. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +47 -58
  48. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -1
  49. package/dist/utils/sharepoint.rest/user-search.d.ts +5 -10
  50. package/dist/utils/sharepoint.rest/user-search.js +129 -148
  51. package/dist/utils/sharepoint.rest/user-search.js.map +1 -1
  52. package/dist/utils/sharepoint.rest/user.d.ts +1 -0
  53. package/dist/utils/sharepoint.rest/user.js +200 -169
  54. package/dist/utils/sharepoint.rest/user.js.map +1 -1
  55. package/dist/utils/sharepoint.rest/web.d.ts +10 -1
  56. package/dist/utils/sharepoint.rest/web.js +381 -401
  57. package/dist/utils/sharepoint.rest/web.js.map +1 -1
  58. package/dist/utils/sod.js +8 -19
  59. package/dist/utils/sod.js.map +1 -1
  60. package/package.json +5 -4
  61. package/src/helpers/browser.ts +56 -13
  62. package/src/helpers/date.ts +23 -1
  63. package/src/helpers/strings.test.js +14 -2
  64. package/src/helpers/strings.ts +2 -1
  65. package/src/utils/rest.ts +7 -0
  66. package/src/utils/sharepoint.rest/file.folder.ts +18 -1
  67. package/src/utils/sharepoint.rest/item.ts +54 -1
  68. package/src/utils/sharepoint.rest/list.ts +144 -0
  69. package/src/utils/sharepoint.rest/user-search.ts +10 -14
  70. package/src/utils/sharepoint.rest/user.ts +49 -3
  71. package/src/utils/sharepoint.rest/web.ts +23 -1
@@ -1,20 +1,13 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CreateList = exports.RemoveListPermission = exports.AssignListPermission = exports.BreakListbPermissionInheritance = exports.ListHasUniquePermissions = exports.ReloadListLastModified = exports.GetListLastItemModifiedDate = exports.DeleteListEventReceiver = exports.AddListEventReceiver = exports.GetListEventReceivers = exports.FindListItemById = exports.GetListItemsSync = exports.GetListItems = exports.GetFieldSchema = exports.GetFieldSchemaSync = exports.GetListFormUrl = exports.GetListContentTypesSync = exports.GetListContentTypes = exports.AddViewFieldToListView = exports.GetListViewsSync = exports.GetListViews = exports.DeleteField = exports.UpdateField = exports.CreateField = exports.UserHasPermissionsSync = exports.UserHasPermissions = exports.UserHasEditPermissions = exports.UserHasManagePermissions = exports.GetListWorkflows = exports.GetListFieldsAsHashSync = exports.GetListFieldsAsHash = exports.GetListFieldsSync = exports.GetListFields = exports.GetStandardListFields = exports.GetListField = exports.GetListRootFolderSync = exports.GetListRootFolder = exports.GetListName = exports.GetListNameSync = exports.GetListSync = exports.GetList = exports.GetListTitle = exports.GetSiteAssetLibrary = exports.EnsureAssetLibrary = exports.GetListIdFromPageSync = exports.GetListId = exports.GetListRestUrl = void 0;
3
+ exports.SearchList = exports.CreateList = exports.RemoveListPermission = exports.AssignListPermission = exports.BreakListbPermissionInheritance = exports.ListHasUniquePermissions = exports.ReloadListLastModified = exports.GetListLastItemModifiedDate = exports.DeleteListEventReceiver = exports.AddListEventReceiver = exports.GetListEventReceivers = exports.FindListItemById = exports.GetListItemsSync = exports.GetListItems = exports.GetFieldSchema = exports.GetFieldSchemaSync = exports.GetListFormUrl = exports.GetListContentTypesSync = exports.GetListContentTypes = exports.AddViewFieldToListView = exports.GetListViewsSync = exports.GetListViews = exports.DeleteField = exports.UpdateField = exports.CreateField = exports.UserHasPermissionsSync = exports.UserHasPermissions = exports.UserHasEditPermissions = exports.UserHasManagePermissions = exports.GetListWorkflows = exports.GetListFieldsAsHashSync = exports.GetListFieldsAsHash = exports.GetListFieldsSync = exports.GetListFields = exports.GetStandardListFields = exports.GetListField = exports.GetListRootFolderSync = exports.GetListRootFolder = exports.GetListName = exports.GetListNameSync = exports.GetListSync = exports.GetList = exports.GetListTitle = exports.GetSiteAssetLibrary = exports.EnsureAssetLibrary = exports.GetListIdFromPageSync = exports.GetListId = exports.GetListRestUrl = void 0;
13
4
  const _dependencies_1 = require("../_dependencies");
5
+ const consolelogger_1 = require("../consolelogger");
14
6
  const rest_1 = require("../rest");
15
7
  const common_1 = require("./common");
16
8
  const common_2 = require("./listutils/common");
17
9
  const web_1 = require("./web");
10
+ const logger = consolelogger_1.ConsoleLogger.get("SharePoint.Rest.List");
18
11
  /** returns /_api/web/lists/getById() or /_api/web/lists/getByTitle() */
19
12
  function GetListRestUrl(siteUrl, listIdOrTitle) {
20
13
  siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
@@ -42,7 +35,10 @@ exports.GetListId = GetListId;
42
35
  /** get the list ID from a list page, such as a list view or an item form */
43
36
  function GetListIdFromPageSync(siteUrl, listPageUrl) {
44
37
  let url = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/getlist('${(0, _dependencies_1.makeServerRelativeUrl)(listPageUrl.split('?')[0].split('#')[0])}')?$select=id`;
45
- let response = (0, rest_1.GetJsonSync)(url, null, Object.assign(Object.assign({}, rest_1.longLocalCache), { jsonMetadata: _dependencies_1.jsonTypes.nometadata }));
38
+ let response = (0, rest_1.GetJsonSync)(url, null, {
39
+ ...rest_1.longLocalCache,
40
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata
41
+ });
46
42
  if (!(0, _dependencies_1.isNullOrUndefined)(response) && response.success) {
47
43
  let listId = response.result.Id;
48
44
  return (0, _dependencies_1.normalizeGuid)(listId);
@@ -55,7 +51,7 @@ function EnsureAssetLibrary(siteUrl) {
55
51
  siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
56
52
  var url = (0, common_1.GetRestBaseUrl)(siteUrl) +
57
53
  "/web/lists/EnsureSiteAssetsLibrary?$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists&$expand=RootFolder";
58
- return (0, rest_1.GetJson)(url, null, Object.assign({ method: "POST", spWebUrl: siteUrl }, rest_1.longLocalCache)).then(result => {
54
+ return (0, rest_1.GetJson)(url, null, { method: "POST", spWebUrl: siteUrl, ...rest_1.longLocalCache }).then(result => {
59
55
  if (result && result.d) {
60
56
  return {
61
57
  Id: result.d.Id,
@@ -75,7 +71,7 @@ function GetSiteAssetLibrary(siteUrl, sync) {
75
71
  + `$filter=EntityTypeName%20eq%20%27SiteAssets%27&$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists`
76
72
  + `&$expand=RootFolder`;
77
73
  let caller = sync ? rest_1.GetJsonSync : rest_1.GetJson;
78
- let result = caller(reqUrl, null, Object.assign(Object.assign({}, rest_1.longLocalCache), { jsonMetadata: _dependencies_1.jsonTypes.nometadata }));
74
+ let result = caller(reqUrl, null, { ...rest_1.longLocalCache, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
79
75
  let transform = (v) => {
80
76
  if ((0, _dependencies_1.isNotEmptyArray)(v && v.value)) {
81
77
  let assetLibrary = v.value[0];
@@ -109,17 +105,17 @@ function GetList(siteUrlOrId, listIdOrTitle, options) {
109
105
  if ((0, _dependencies_1.isNullOrEmptyString)(listIdOrTitle))
110
106
  return null;
111
107
  return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `?$select=${common_1.LIST_SELECT}&$expand=${common_1.LIST_EXPAND}`, null, { allowCache: true })
112
- .then((r) => __awaiter(this, void 0, void 0, function* () {
108
+ .then(async (r) => {
113
109
  let list = r.d;
114
110
  if (options) {
115
111
  if (options.includeViews)
116
- list.Views = yield GetListViews(siteUrl, listIdOrTitle, options.viewOptions);
112
+ list.Views = await GetListViews(siteUrl, listIdOrTitle, options.viewOptions);
117
113
  if (options.includeContentTypes)
118
- list.ContentTypes = yield GetListContentTypes(siteUrl, listIdOrTitle);
114
+ list.ContentTypes = await GetListContentTypes(siteUrl, listIdOrTitle);
119
115
  if (options.includeRootFolder)
120
- list.RootFolder = yield GetListRootFolder(siteUrl, listIdOrTitle);
116
+ list.RootFolder = await GetListRootFolder(siteUrl, listIdOrTitle);
121
117
  if (options.includeEventReceivers)
122
- list.EventReceivers = yield GetListEventReceivers(siteUrl, listIdOrTitle);
118
+ list.EventReceivers = await GetListEventReceivers(siteUrl, listIdOrTitle);
123
119
  }
124
120
  if (list.EffectiveBasePermissions
125
121
  && ((0, _dependencies_1.isString)(list.EffectiveBasePermissions.High)
@@ -130,7 +126,7 @@ function GetList(siteUrlOrId, listIdOrTitle, options) {
130
126
  };
131
127
  }
132
128
  return list;
133
- }))
129
+ })
134
130
  .catch(() => null);
135
131
  }
136
132
  exports.GetList = GetList;
@@ -161,11 +157,9 @@ function GetListNameSync(webUrl, listIdOrTitle) {
161
157
  return (0, _dependencies_1.NormalizeListName)({ EntityTypeName: list.EntityTypeName, BaseType: list.BaseType });
162
158
  }
163
159
  exports.GetListNameSync = GetListNameSync;
164
- function GetListName(webUrl, listIdOrTitle) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- let list = yield GetList(webUrl, listIdOrTitle);
167
- return (0, _dependencies_1.NormalizeListName)({ EntityTypeName: list.EntityTypeName, BaseType: list.BaseType });
168
- });
160
+ async function GetListName(webUrl, listIdOrTitle) {
161
+ let list = await GetList(webUrl, listIdOrTitle);
162
+ return (0, _dependencies_1.NormalizeListName)({ EntityTypeName: list.EntityTypeName, BaseType: list.BaseType });
169
163
  }
170
164
  exports.GetListName = GetListName;
171
165
  function GetListRootFolder(siteUrlOrId, listIdOrTitle) {
@@ -250,16 +244,14 @@ function GetListFieldsSync(siteUrlOrId, listIdOrTitle, options = {}) {
250
244
  return null;
251
245
  }
252
246
  exports.GetListFieldsSync = GetListFieldsSync;
253
- function GetListFieldsAsHash(siteUrlOrId, listIdOrTitle, refreshCache) {
254
- return __awaiter(this, void 0, void 0, function* () {
255
- let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
256
- let fields = yield GetListFields(siteUrl, listIdOrTitle, { refreshCache: refreshCache });
257
- let hash = {};
258
- if ((0, _dependencies_1.isNotEmptyArray)(fields)) {
259
- hash = (0, _dependencies_1.toHash)(fields, f => f.InternalName);
260
- }
261
- return hash;
262
- });
247
+ async function GetListFieldsAsHash(siteUrlOrId, listIdOrTitle, refreshCache) {
248
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
249
+ let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: refreshCache });
250
+ let hash = {};
251
+ if ((0, _dependencies_1.isNotEmptyArray)(fields)) {
252
+ hash = (0, _dependencies_1.toHash)(fields, f => f.InternalName);
253
+ }
254
+ return hash;
263
255
  }
264
256
  exports.GetListFieldsAsHash = GetListFieldsAsHash;
265
257
  function GetListFieldsAsHashSync(siteUrlOrId, listIdOrTitle, refreshCache) {
@@ -293,7 +285,7 @@ function GetListWorkflows(siteUrl, listIdOrTitle, refreshCache) {
293
285
  exports.GetListWorkflows = GetListWorkflows;
294
286
  function UserHasManagePermissions(siteUrl, listIdOrTitle) {
295
287
  siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
296
- return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, Object.assign({}, rest_1.shortLocalCache))
288
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, { ...rest_1.shortLocalCache })
297
289
  .then(r => {
298
290
  return new _dependencies_1.SPBasePermissions(r.d.EffectiveBasePermissions).has(_dependencies_1.SPBasePermissionKind.ManageLists);
299
291
  })
@@ -306,7 +298,7 @@ function UserHasEditPermissions(siteUrl, listIdOrTitle) {
306
298
  exports.UserHasEditPermissions = UserHasEditPermissions;
307
299
  function UserHasPermissions(siteUrlOrId, listIdOrTitle, permissionKind) {
308
300
  let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
309
- return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, Object.assign({}, rest_1.shortLocalCache))
301
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, { ...rest_1.shortLocalCache })
310
302
  .then(r => {
311
303
  return new _dependencies_1.SPBasePermissions(r.d.EffectiveBasePermissions).has(permissionKind);
312
304
  })
@@ -315,18 +307,18 @@ function UserHasPermissions(siteUrlOrId, listIdOrTitle, permissionKind) {
315
307
  exports.UserHasPermissions = UserHasPermissions;
316
308
  function UserHasPermissionsSync(siteUrlOrId, listIdOrTitle, permissionKind) {
317
309
  let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
318
- const res = (0, rest_1.GetJsonSync)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, Object.assign({}, rest_1.shortLocalCache));
310
+ const res = (0, rest_1.GetJsonSync)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, { ...rest_1.shortLocalCache });
319
311
  return new _dependencies_1.SPBasePermissions(res.result.d.EffectiveBasePermissions).has(permissionKind);
320
312
  }
321
313
  exports.UserHasPermissionsSync = UserHasPermissionsSync;
322
314
  /** create a new column and try to add it to default view. Send either Title and Type, or SchemaXml. Create with SchemaXml also adds to all content types */
323
315
  function CreateField(siteUrl, listIdOrTitle, options) {
324
316
  siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
325
- let finish = (result) => __awaiter(this, void 0, void 0, function* () {
317
+ let finish = async (result) => {
326
318
  if (result && result.d) {
327
319
  let internalName = result.d.InternalName;
328
320
  //we need to clear and reload the list fields cache, so call it and return our field from that collection.
329
- let fields = yield GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
321
+ let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
330
322
  try {
331
323
  if (options.SkipAddToDefaultView !== true) {
332
324
  //try to add it to default view, don't wait for it
@@ -341,7 +333,7 @@ function CreateField(siteUrl, listIdOrTitle, options) {
341
333
  return (0, _dependencies_1.firstOrNull)(fields, f => f.InternalName === internalName);
342
334
  }
343
335
  return null;
344
- });
336
+ };
345
337
  if (!(0, _dependencies_1.isNullOrEmptyString)(options.SchemaXml)) {
346
338
  return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/createFieldAsXml`, JSON.stringify({
347
339
  'parameters': {
@@ -381,83 +373,79 @@ function CreateField(siteUrl, listIdOrTitle, options) {
381
373
  }
382
374
  exports.CreateField = CreateField;
383
375
  /** Update field SchemaXml OR Title, only 1 update at a time supported. */
384
- function UpdateField(siteUrlOrId, listIdOrTitle, fieldInternalName, options) {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
387
- let finish = () => __awaiter(this, void 0, void 0, function* () {
388
- //we need to clear and reload the list fields cache, so call it and return our field from that collection.
389
- let fields = yield GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
390
- return (0, _dependencies_1.firstOrNull)(fields, f => f.InternalName === fieldInternalName);
391
- });
392
- //updates can either be SchemaXml, or others. Cannot be both.
393
- let updates = {
394
- '__metadata': { 'type': 'SP.Field' }
395
- };
396
- if (!(0, _dependencies_1.isNullOrEmptyString)(options.SchemaXml)) {
397
- updates.SchemaXml = options.SchemaXml;
398
- }
399
- else {
400
- //cannot send schema updates with other updates.
401
- if (!(0, _dependencies_1.isNullOrEmptyString)(options.Title)) {
402
- updates.Title = options.Title;
403
- }
404
- if (!(0, _dependencies_1.isNullOrEmptyString)(options.FieldType)) {
405
- updates.TypeAsString = options.FieldType;
406
- }
407
- if ((0, _dependencies_1.isBoolean)(options.Required)) {
408
- updates.Required = options.Required === true;
409
- }
410
- if ((0, _dependencies_1.isBoolean)(options.Hidden)) {
411
- //this requries the CanToggleHidden to be in the schema... if not - we will need to add it before we can update this.
412
- let fields = yield GetListFieldsAsHash(siteUrl, listIdOrTitle, false);
413
- let thisField = fields[fieldInternalName];
414
- if (thisField.Hidden !== options.Hidden) {
415
- if (thisField) {
416
- if (thisField.SchemaJson.Attributes.CanToggleHidden !== "TRUE") {
417
- yield UpdateField(siteUrl, listIdOrTitle, fieldInternalName, {
418
- SchemaXml: thisField.SchemaXml.replace("<Field ", `<Field CanToggleHidden="TRUE" `)
419
- });
420
- }
376
+ async function UpdateField(siteUrlOrId, listIdOrTitle, fieldInternalName, options) {
377
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
378
+ let finish = async () => {
379
+ //we need to clear and reload the list fields cache, so call it and return our field from that collection.
380
+ let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
381
+ return (0, _dependencies_1.firstOrNull)(fields, f => f.InternalName === fieldInternalName);
382
+ };
383
+ //updates can either be SchemaXml, or others. Cannot be both.
384
+ let updates = {
385
+ '__metadata': { 'type': 'SP.Field' }
386
+ };
387
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.SchemaXml)) {
388
+ updates.SchemaXml = options.SchemaXml;
389
+ }
390
+ else {
391
+ //cannot send schema updates with other updates.
392
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.Title)) {
393
+ updates.Title = options.Title;
394
+ }
395
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.FieldType)) {
396
+ updates.TypeAsString = options.FieldType;
397
+ }
398
+ if ((0, _dependencies_1.isBoolean)(options.Required)) {
399
+ updates.Required = options.Required === true;
400
+ }
401
+ if ((0, _dependencies_1.isBoolean)(options.Hidden)) {
402
+ //this requries the CanToggleHidden to be in the schema... if not - we will need to add it before we can update this.
403
+ let fields = await GetListFieldsAsHash(siteUrl, listIdOrTitle, false);
404
+ let thisField = fields[fieldInternalName];
405
+ if (thisField.Hidden !== options.Hidden) {
406
+ if (thisField) {
407
+ if (thisField.SchemaJson.Attributes.CanToggleHidden !== "TRUE") {
408
+ await UpdateField(siteUrl, listIdOrTitle, fieldInternalName, {
409
+ SchemaXml: thisField.SchemaXml.replace("<Field ", `<Field CanToggleHidden="TRUE" `)
410
+ });
421
411
  }
422
- updates.Hidden = options.Hidden === true;
423
412
  }
413
+ updates.Hidden = options.Hidden === true;
424
414
  }
425
- if (!(0, _dependencies_1.isNullOrEmptyString)(options.ClientSideComponentId))
426
- updates.ClientSideComponentId = options.ClientSideComponentId;
427
- if (!(0, _dependencies_1.isNullOrEmptyString)(options.ClientSideComponentProperties))
428
- updates.ClientSideComponentProperties = options.ClientSideComponentProperties;
429
- }
430
- if (Object.keys(updates).length > 1) {
431
- return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getbyinternalnameortitle('${fieldInternalName}')`, JSON.stringify(updates), { xHttpMethod: "MERGE" })
432
- .then(r => {
433
- return finish();
434
- })
435
- .catch(() => null);
436
- }
437
- else {
438
- console.error("You must send an option to update");
439
- return null;
440
415
  }
441
- });
416
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.ClientSideComponentId))
417
+ updates.ClientSideComponentId = options.ClientSideComponentId;
418
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.ClientSideComponentProperties))
419
+ updates.ClientSideComponentProperties = options.ClientSideComponentProperties;
420
+ }
421
+ if (Object.keys(updates).length > 1) {
422
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getbyinternalnameortitle('${fieldInternalName}')`, JSON.stringify(updates), { xHttpMethod: "MERGE" })
423
+ .then(r => {
424
+ return finish();
425
+ })
426
+ .catch(() => null);
427
+ }
428
+ else {
429
+ console.error("You must send an option to update");
430
+ return null;
431
+ }
442
432
  }
443
433
  exports.UpdateField = UpdateField;
444
- function DeleteField(siteUrl, listIdOrTitle, fieldInternalName, options) {
445
- return __awaiter(this, void 0, void 0, function* () {
446
- siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
447
- // let finish = async () => {
448
- // //we need to clear and reload the list fields cache, so call it and return our field from that collection.
449
- // let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
450
- // return firstOrNull(fields, f => f.InternalName === fieldInternalName);
451
- // };
452
- if (options && options.DeleteHiddenField)
453
- yield UpdateField(siteUrl, listIdOrTitle, fieldInternalName, { Hidden: false });
454
- return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getbyinternalnameortitle('${fieldInternalName}')`, null, {
455
- method: "POST",
456
- xHttpMethod: "DELETE"
457
- })
458
- .then(r => true)
459
- .catch((e) => false);
460
- });
434
+ async function DeleteField(siteUrl, listIdOrTitle, fieldInternalName, options) {
435
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
436
+ // let finish = async () => {
437
+ // //we need to clear and reload the list fields cache, so call it and return our field from that collection.
438
+ // let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
439
+ // return firstOrNull(fields, f => f.InternalName === fieldInternalName);
440
+ // };
441
+ if (options && options.DeleteHiddenField)
442
+ await UpdateField(siteUrl, listIdOrTitle, fieldInternalName, { Hidden: false });
443
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getbyinternalnameortitle('${fieldInternalName}')`, null, {
444
+ method: "POST",
445
+ xHttpMethod: "DELETE"
446
+ })
447
+ .then(r => true)
448
+ .catch((e) => false);
461
449
  }
462
450
  exports.DeleteField = DeleteField;
463
451
  function GetListViews(siteUrl, listIdOrTitle, options) {
@@ -491,45 +479,43 @@ function GetListViewsSync(siteUrl, listIdOrTitle) {
491
479
  return null;
492
480
  }
493
481
  exports.GetListViewsSync = GetListViewsSync;
494
- function AddViewFieldToListView(siteUrl, listIdOrTitle, viewId, viewField) {
495
- return __awaiter(this, void 0, void 0, function* () {
496
- siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
497
- if ((0, _dependencies_1.isNullOrEmptyString)(viewField) || !(0, _dependencies_1.isValidGuid)(viewId)) {
498
- return false;
499
- }
500
- let views = yield GetListViews(siteUrl, listIdOrTitle, { includeViewFields: true });
501
- if ((0, _dependencies_1.isNullOrEmptyArray)(views)) {
502
- return false;
503
- }
504
- let view = views.filter((view) => {
505
- return (0, _dependencies_1.normalizeGuid)(view.Id) === (0, _dependencies_1.normalizeGuid)(viewId);
506
- })[0];
507
- if ((0, _dependencies_1.isNullOrUndefined)(view)) {
508
- return false;
509
- }
510
- let hasField = view.ViewFields.includes(viewField);
511
- if (hasField === true) {
482
+ async function AddViewFieldToListView(siteUrl, listIdOrTitle, viewId, viewField) {
483
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
484
+ if ((0, _dependencies_1.isNullOrEmptyString)(viewField) || !(0, _dependencies_1.isValidGuid)(viewId)) {
485
+ return false;
486
+ }
487
+ let views = await GetListViews(siteUrl, listIdOrTitle, { includeViewFields: true });
488
+ if ((0, _dependencies_1.isNullOrEmptyArray)(views)) {
489
+ return false;
490
+ }
491
+ let view = views.filter((view) => {
492
+ return (0, _dependencies_1.normalizeGuid)(view.Id) === (0, _dependencies_1.normalizeGuid)(viewId);
493
+ })[0];
494
+ if ((0, _dependencies_1.isNullOrUndefined)(view)) {
495
+ return false;
496
+ }
497
+ let hasField = view.ViewFields.includes(viewField);
498
+ if (hasField === true) {
499
+ return true;
500
+ }
501
+ try {
502
+ let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${(0, _dependencies_1.normalizeGuid)(view.Id)}')/viewfields/addviewfield('${viewField}')`;
503
+ let result = await (0, rest_1.GetJson)(url, null, { method: "POST" });
504
+ console.log(result);
505
+ if (result && result.d.AddViewField === null) {
512
506
  return true;
513
507
  }
514
- try {
515
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${(0, _dependencies_1.normalizeGuid)(view.Id)}')/viewfields/addviewfield('${viewField}')`;
516
- let result = yield (0, rest_1.GetJson)(url, null, { method: "POST" });
517
- console.log(result);
518
- if (result && result.d.AddViewField === null) {
519
- return true;
520
- }
521
- }
522
- catch (_a) { }
523
- return false;
524
- });
508
+ }
509
+ catch { }
510
+ return false;
525
511
  }
526
512
  exports.AddViewFieldToListView = AddViewFieldToListView;
527
513
  function GetListContentTypes(siteUrl, listIdOrTitle, options) {
528
- return (0, web_1.GetContentTypes)(siteUrl, Object.assign(Object.assign({}, (options || {})), { listIdOrTitle: listIdOrTitle }));
514
+ return (0, web_1.GetContentTypes)(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle });
529
515
  }
530
516
  exports.GetListContentTypes = GetListContentTypes;
531
517
  function GetListContentTypesSync(siteUrl, listIdOrTitle, options) {
532
- return (0, web_1.GetContentTypesSync)(siteUrl, Object.assign(Object.assign({}, (options || {})), { listIdOrTitle: listIdOrTitle }));
518
+ return (0, web_1.GetContentTypesSync)(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle });
533
519
  }
534
520
  exports.GetListContentTypesSync = GetListContentTypesSync;
535
521
  /** generic version. for the KWIZ forms version that supports action id call GetListFormUrlAppsWeb instead */
@@ -575,54 +561,50 @@ function GetFieldSchemaSync(siteUrl, listIdOrTitle, fieldInternalName, refreshCa
575
561
  //#endregion
576
562
  }
577
563
  exports.GetFieldSchemaSync = GetFieldSchemaSync;
578
- function GetFieldSchema(siteUrl, listIdOrTitle, fieldInternalName, refreshCache) {
579
- return __awaiter(this, void 0, void 0, function* () {
580
- siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
581
- //ISSUE: 1516 - The get schema request will fail if the field doesn't exist in the list, so we load the fields and ensure the field
582
- //exists before requesting the schema
583
- let fields = yield GetListFields(siteUrl, listIdOrTitle, {
584
- refreshCache: refreshCache,
585
- fieldNames: [fieldInternalName]
586
- });
587
- if ((0, _dependencies_1.isNullOrEmptyArray)(fields)) {
588
- return null;
589
- }
590
- let field = fields[0];
591
- return (0, _dependencies_1.SchemaXmlToJson)(field.SchemaXml);
564
+ async function GetFieldSchema(siteUrl, listIdOrTitle, fieldInternalName, refreshCache) {
565
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
566
+ //ISSUE: 1516 - The get schema request will fail if the field doesn't exist in the list, so we load the fields and ensure the field
567
+ //exists before requesting the schema
568
+ let fields = await GetListFields(siteUrl, listIdOrTitle, {
569
+ refreshCache: refreshCache,
570
+ fieldNames: [fieldInternalName]
592
571
  });
572
+ if ((0, _dependencies_1.isNullOrEmptyArray)(fields)) {
573
+ return null;
574
+ }
575
+ let field = fields[0];
576
+ return (0, _dependencies_1.SchemaXmlToJson)(field.SchemaXml);
593
577
  }
594
578
  exports.GetFieldSchema = GetFieldSchema;
595
- function GetListItems(siteUrl, listIdOrTitle, options) {
596
- return __awaiter(this, void 0, void 0, function* () {
597
- let info = _GetListItemsInfo(siteUrl, listIdOrTitle, options);
598
- let items = [];
599
- do {
600
- let resultItems = [];
601
- let next = null;
602
- if (info.noMetadata) {
603
- let requestResult = (yield (0, rest_1.GetJson)(info.requestUrl, null, {
604
- allowCache: options.refreshCache !== true,
605
- jsonMetadata: options.jsonMetadata
606
- }));
607
- resultItems = requestResult.value;
608
- next = requestResult["odata.nextLink"];
609
- }
610
- else {
611
- let requestResult = (yield (0, rest_1.GetJson)(info.requestUrl, null, {
612
- allowCache: options.refreshCache !== true
613
- }));
614
- resultItems = requestResult.d.results;
615
- next = requestResult.d.__next;
616
- }
617
- if ((0, _dependencies_1.isNotEmptyArray)(resultItems))
618
- items.push(...resultItems);
619
- if (info.totalNumberOfItemsToGet > items.length)
620
- info.requestUrl = next;
621
- else
622
- info.requestUrl = null;
623
- } while (!(0, _dependencies_1.isNullOrEmptyString)(info.requestUrl));
624
- return (0, common_2.__fixGetListItemsResults)(siteUrl, listIdOrTitle, items, options.foldersBehaviour, info.expandedLookupFields);
625
- });
579
+ async function GetListItems(siteUrl, listIdOrTitle, options) {
580
+ let info = _GetListItemsInfo(siteUrl, listIdOrTitle, options);
581
+ let items = [];
582
+ do {
583
+ let resultItems = [];
584
+ let next = null;
585
+ if (info.noMetadata) {
586
+ let requestResult = (await (0, rest_1.GetJson)(info.requestUrl, null, {
587
+ allowCache: options.refreshCache !== true,
588
+ jsonMetadata: options.jsonMetadata
589
+ }));
590
+ resultItems = requestResult.value;
591
+ next = requestResult["odata.nextLink"];
592
+ }
593
+ else {
594
+ let requestResult = (await (0, rest_1.GetJson)(info.requestUrl, null, {
595
+ allowCache: options.refreshCache !== true
596
+ }));
597
+ resultItems = requestResult.d.results;
598
+ next = requestResult.d.__next;
599
+ }
600
+ if ((0, _dependencies_1.isNotEmptyArray)(resultItems))
601
+ items.push(...resultItems);
602
+ if (info.totalNumberOfItemsToGet > items.length)
603
+ info.requestUrl = next;
604
+ else
605
+ info.requestUrl = null;
606
+ } while (!(0, _dependencies_1.isNullOrEmptyString)(info.requestUrl));
607
+ return (0, common_2.__fixGetListItemsResults)(siteUrl, listIdOrTitle, items, options.foldersBehaviour, info.expandedLookupFields);
626
608
  }
627
609
  exports.GetListItems = GetListItems;
628
610
  function GetListItemsSync(siteUrl, listIdOrTitle, options) {
@@ -727,58 +709,56 @@ exports.FindListItemById = FindListItemById;
727
709
  function _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle) {
728
710
  return GetListRestUrl(siteUrl, listIdOrTitle) + `/EventReceivers`;
729
711
  }
730
- function GetListEventReceivers(siteUrl, listIdOrTitle, refreshCache) {
731
- return __awaiter(this, void 0, void 0, function* () {
732
- try {
733
- let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
734
- let response = yield (0, rest_1.GetJson)(url, null, {
735
- allowCache: refreshCache !== true,
736
- jsonMetadata: _dependencies_1.jsonTypes.nometadata
737
- });
738
- return !(0, _dependencies_1.isNullOrUndefined)(response) ? response.value : null;
739
- }
740
- catch (_a) {
741
- }
742
- return null;
743
- });
712
+ async function GetListEventReceivers(siteUrl, listIdOrTitle, refreshCache) {
713
+ try {
714
+ let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
715
+ let response = await (0, rest_1.GetJson)(url, null, {
716
+ allowCache: refreshCache !== true,
717
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata
718
+ });
719
+ return !(0, _dependencies_1.isNullOrUndefined)(response) ? response.value : null;
720
+ }
721
+ catch {
722
+ }
723
+ return null;
744
724
  }
745
725
  exports.GetListEventReceivers = GetListEventReceivers;
746
- function AddListEventReceiver(siteUrl, listIdOrTitle, eventReceiverDefinition) {
747
- return __awaiter(this, void 0, void 0, function* () {
748
- let newEventReceiver = Object.assign({ ReceiverAssembly: "", ReceiverClass: "" }, eventReceiverDefinition);
749
- try {
750
- let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
751
- let response = yield (0, rest_1.GetJson)(url, JSON.stringify(newEventReceiver), {
752
- method: "POST",
753
- includeDigestInPost: true,
754
- jsonMetadata: _dependencies_1.jsonTypes.nometadata,
755
- headers: {
756
- "content-type": _dependencies_1.contentTypes.json
757
- }
758
- });
759
- return !(0, _dependencies_1.isNullOrUndefined)(response) && (0, _dependencies_1.isValidGuid)(response.ReceiverId) ? response : null;
760
- }
761
- catch (_a) {
762
- }
763
- return null;
764
- });
726
+ async function AddListEventReceiver(siteUrl, listIdOrTitle, eventReceiverDefinition) {
727
+ let newEventReceiver = {
728
+ ReceiverAssembly: "",
729
+ ReceiverClass: "",
730
+ ...eventReceiverDefinition
731
+ };
732
+ try {
733
+ let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
734
+ let response = await (0, rest_1.GetJson)(url, JSON.stringify(newEventReceiver), {
735
+ method: "POST",
736
+ includeDigestInPost: true,
737
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata,
738
+ headers: {
739
+ "content-type": _dependencies_1.contentTypes.json
740
+ }
741
+ });
742
+ return !(0, _dependencies_1.isNullOrUndefined)(response) && (0, _dependencies_1.isValidGuid)(response.ReceiverId) ? response : null;
743
+ }
744
+ catch {
745
+ }
746
+ return null;
765
747
  }
766
748
  exports.AddListEventReceiver = AddListEventReceiver;
767
- function DeleteListEventReceiver(siteUrl, listIdOrTitle, eventReceiverId) {
768
- return __awaiter(this, void 0, void 0, function* () {
769
- try {
770
- let url = `${_getListEventReceiversRequestUrl(siteUrl, listIdOrTitle)}('${(0, _dependencies_1.normalizeGuid)(eventReceiverId)}')/deleteObject`;
771
- let response = yield (0, rest_1.GetJson)(url, null, {
772
- method: "POST",
773
- includeDigestInPost: true,
774
- jsonMetadata: _dependencies_1.jsonTypes.nometadata
775
- });
776
- return !(0, _dependencies_1.isNullOrUndefined)(response) && response["odata.null"] === true;
777
- }
778
- catch (_a) {
779
- }
780
- return false;
781
- });
749
+ async function DeleteListEventReceiver(siteUrl, listIdOrTitle, eventReceiverId) {
750
+ try {
751
+ let url = `${_getListEventReceiversRequestUrl(siteUrl, listIdOrTitle)}('${(0, _dependencies_1.normalizeGuid)(eventReceiverId)}')/deleteObject`;
752
+ let response = await (0, rest_1.GetJson)(url, null, {
753
+ method: "POST",
754
+ includeDigestInPost: true,
755
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata
756
+ });
757
+ return !(0, _dependencies_1.isNullOrUndefined)(response) && response["odata.null"] === true;
758
+ }
759
+ catch {
760
+ }
761
+ return false;
782
762
  }
783
763
  exports.DeleteListEventReceiver = DeleteListEventReceiver;
784
764
  function GetListLastItemModifiedDate(siteUrl, listIdOrTitle, options) {
@@ -797,72 +777,99 @@ function GetListLastItemModifiedDate(siteUrl, listIdOrTitle, options) {
797
777
  return result.success ? result.result.value : null;
798
778
  }
799
779
  exports.GetListLastItemModifiedDate = GetListLastItemModifiedDate;
800
- function ReloadListLastModified(siteUrl, listIdOrTitle) {
801
- return __awaiter(this, void 0, void 0, function* () {
802
- yield GetListLastItemModifiedDate(siteUrl, listIdOrTitle, { refreshCache: true });
803
- //make sure we do it for both title and id, we don't know how the other callers may use this in their API
804
- if (!(0, _dependencies_1.isValidGuid)(listIdOrTitle)) {
805
- try {
806
- var listId = GetListId(siteUrl, listIdOrTitle);
807
- yield GetListLastItemModifiedDate(siteUrl, listId, { refreshCache: true });
808
- }
809
- catch (e) { }
780
+ async function ReloadListLastModified(siteUrl, listIdOrTitle) {
781
+ await GetListLastItemModifiedDate(siteUrl, listIdOrTitle, { refreshCache: true });
782
+ //make sure we do it for both title and id, we don't know how the other callers may use this in their API
783
+ if (!(0, _dependencies_1.isValidGuid)(listIdOrTitle)) {
784
+ try {
785
+ var listId = GetListId(siteUrl, listIdOrTitle);
786
+ await GetListLastItemModifiedDate(siteUrl, listId, { refreshCache: true });
810
787
  }
811
- else {
812
- try {
813
- var listTitle = yield GetListTitle(siteUrl, listIdOrTitle);
814
- yield GetListLastItemModifiedDate(siteUrl, listTitle, { refreshCache: true });
815
- }
816
- catch (e) { }
788
+ catch (e) { }
789
+ }
790
+ else {
791
+ try {
792
+ var listTitle = await GetListTitle(siteUrl, listIdOrTitle);
793
+ await GetListLastItemModifiedDate(siteUrl, listTitle, { refreshCache: true });
817
794
  }
818
- });
795
+ catch (e) { }
796
+ }
819
797
  }
820
798
  exports.ReloadListLastModified = ReloadListLastModified;
821
- function ListHasUniquePermissions(siteUrl, listIdOrTitle) {
822
- return __awaiter(this, void 0, void 0, function* () {
823
- let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/?$select=hasuniqueroleassignments`;
824
- let has = yield (0, rest_1.GetJson)(url, undefined, { allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
825
- return has.HasUniqueRoleAssignments === true;
826
- });
799
+ async function ListHasUniquePermissions(siteUrl, listIdOrTitle) {
800
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/?$select=hasuniqueroleassignments`;
801
+ let has = await (0, rest_1.GetJson)(url, undefined, { allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
802
+ return has.HasUniqueRoleAssignments === true;
827
803
  }
828
804
  exports.ListHasUniquePermissions = ListHasUniquePermissions;
829
- function BreakListbPermissionInheritance(siteUrl, listIdOrTitle, clear = true) {
830
- return __awaiter(this, void 0, void 0, function* () {
831
- let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/breakroleinheritance(copyRoleAssignments=${clear ? 'false' : 'true'}, clearSubscopes=true)`;
832
- yield (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
833
- });
805
+ async function BreakListbPermissionInheritance(siteUrl, listIdOrTitle, clear = true) {
806
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/breakroleinheritance(copyRoleAssignments=${clear ? 'false' : 'true'}, clearSubscopes=true)`;
807
+ await (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
834
808
  }
835
809
  exports.BreakListbPermissionInheritance = BreakListbPermissionInheritance;
836
- function AssignListPermission(siteUrl, listIdOrTitle, principalId, roleId) {
837
- return __awaiter(this, void 0, void 0, function* () {
838
- let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/addroleassignment(principalid=${principalId},roleDefId=${roleId})`;
839
- yield (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
840
- });
810
+ async function AssignListPermission(siteUrl, listIdOrTitle, principalId, roleId) {
811
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/addroleassignment(principalid=${principalId},roleDefId=${roleId})`;
812
+ await (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
841
813
  }
842
814
  exports.AssignListPermission = AssignListPermission;
843
- function RemoveListPermission(siteUrl, listIdOrTitle, principalId, roleId) {
844
- return __awaiter(this, void 0, void 0, function* () {
845
- let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/removeroleassignment(principalid=${principalId},roleDefId=${roleId})`;
846
- yield (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
847
- });
815
+ async function RemoveListPermission(siteUrl, listIdOrTitle, principalId, roleId) {
816
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/removeroleassignment(principalid=${principalId},roleDefId=${roleId})`;
817
+ await (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
848
818
  }
849
819
  exports.RemoveListPermission = RemoveListPermission;
850
- function CreateList(siteUrl, info) {
851
- return __awaiter(this, void 0, void 0, function* () {
852
- let url = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/lists`;
853
- const body = {
854
- __metadata: { type: 'SP.List' },
855
- AllowContentTypes: false,
856
- ContentTypesEnabled: false,
857
- BaseTemplate: info.template,
858
- BaseType: info.type,
859
- Description: info.description,
860
- Title: info.title
861
- };
862
- let newList = (yield (0, rest_1.GetJson)(url, (0, _dependencies_1.jsonStringify)(body))).d;
863
- (0, _dependencies_1.normalizeGuid)(newList.Id);
864
- return newList;
865
- });
820
+ async function CreateList(siteUrl, info) {
821
+ let url = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/lists`;
822
+ const body = {
823
+ __metadata: { type: 'SP.List' },
824
+ AllowContentTypes: false,
825
+ ContentTypesEnabled: false,
826
+ BaseTemplate: info.template,
827
+ BaseType: info.type,
828
+ Description: info.description,
829
+ Title: info.title
830
+ };
831
+ let newList = (await (0, rest_1.GetJson)(url, (0, _dependencies_1.jsonStringify)(body))).d;
832
+ (0, _dependencies_1.normalizeGuid)(newList.Id);
833
+ return newList;
866
834
  }
867
835
  exports.CreateList = CreateList;
836
+ async function SearchList(siteUrl, listIdOrTitle, query) {
837
+ let listId = GetListId(siteUrl, listIdOrTitle);
838
+ let url = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/search/query?querytext='(${query}*)'&querytemplate='{searchTerms} (NormListID:${listId})'`;
839
+ try {
840
+ const result = await (0, rest_1.GetJson)(url, null, { jsonMetadata: _dependencies_1.jsonTypes.nometadata });
841
+ logger.json(result.PrimaryQueryResult.RelevantResults, `search ${query}`);
842
+ let rows = result.PrimaryQueryResult.RelevantResults.Table.Rows;
843
+ const mapped = [];
844
+ rows.forEach(r => {
845
+ try {
846
+ const rowValues = {};
847
+ r.Cells.forEach(cell => {
848
+ rowValues[cell.Key] = cell.ValueType === "Edm.Int64" || cell.ValueType === "Edm.Double"
849
+ ? parseInt(cell.Value, 10)
850
+ : cell.ValueType === "Edm.DateTime"
851
+ ? new Date(cell.Value)
852
+ : cell.ValueType === "Null"
853
+ ? ""
854
+ : cell.Value;
855
+ });
856
+ let resultPath = (0, _dependencies_1.isNullOrEmptyString)(rowValues.Path) ? "" : rowValues.Path.toLowerCase();
857
+ let indexOfId = resultPath.toLowerCase().indexOf("id=");
858
+ let itemId = indexOfId >= 0 ? parseInt(resultPath.slice(indexOfId + 3)) : -1;
859
+ if (itemId >= 0)
860
+ rowValues.$itemId = itemId;
861
+ mapped.push(rowValues);
862
+ }
863
+ catch (e) {
864
+ return null;
865
+ }
866
+ });
867
+ return mapped;
868
+ }
869
+ catch (e) {
870
+ logger.error(e);
871
+ return [];
872
+ }
873
+ }
874
+ exports.SearchList = SearchList;
868
875
  //# sourceMappingURL=list.js.map