@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.
- package/dist/helpers/base64.js +10 -21
- package/dist/helpers/base64.js.map +1 -1
- package/dist/helpers/browser.d.ts +13 -5
- package/dist/helpers/browser.js +61 -39
- package/dist/helpers/browser.js.map +1 -1
- package/dist/helpers/collections.base.js +46 -65
- package/dist/helpers/collections.base.js.map +1 -1
- package/dist/helpers/collections.js +4 -1
- package/dist/helpers/collections.js.map +1 -1
- package/dist/helpers/date.d.ts +2 -1
- package/dist/helpers/date.js +22 -3
- package/dist/helpers/date.js.map +1 -1
- package/dist/helpers/debug.js +9 -20
- package/dist/helpers/debug.js.map +1 -1
- package/dist/helpers/objects.js +2 -11
- package/dist/helpers/objects.js.map +1 -1
- package/dist/helpers/promises.js +28 -41
- package/dist/helpers/promises.js.map +1 -1
- package/dist/helpers/strings.js +2 -1
- package/dist/helpers/strings.js.map +1 -1
- package/dist/utils/base64.js +18 -29
- package/dist/utils/base64.js.map +1 -1
- package/dist/utils/consolelogger.js +16 -27
- package/dist/utils/consolelogger.js.map +1 -1
- package/dist/utils/emails.js +5 -2
- package/dist/utils/emails.js.map +1 -1
- package/dist/utils/knownscript.js +4 -15
- package/dist/utils/knownscript.js.map +1 -1
- package/dist/utils/localstoragecache.js +3 -3
- package/dist/utils/localstoragecache.js.map +1 -1
- package/dist/utils/rest.d.ts +2 -0
- package/dist/utils/rest.js +18 -5
- package/dist/utils/rest.js.map +1 -1
- package/dist/utils/script.js +25 -40
- package/dist/utils/script.js.map +1 -1
- package/dist/utils/sharepoint.rest/file.folder.d.ts +2 -0
- package/dist/utils/sharepoint.rest/file.folder.js +123 -123
- package/dist/utils/sharepoint.rest/file.folder.js.map +1 -1
- package/dist/utils/sharepoint.rest/item.d.ts +10 -0
- package/dist/utils/sharepoint.rest/item.js +233 -237
- package/dist/utils/sharepoint.rest/item.js.map +1 -1
- package/dist/utils/sharepoint.rest/list.d.ts +30 -1
- package/dist/utils/sharepoint.rest/list.js +296 -289
- package/dist/utils/sharepoint.rest/list.js.map +1 -1
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +352 -360
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +47 -58
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -1
- package/dist/utils/sharepoint.rest/user-search.d.ts +5 -10
- package/dist/utils/sharepoint.rest/user-search.js +129 -148
- package/dist/utils/sharepoint.rest/user-search.js.map +1 -1
- package/dist/utils/sharepoint.rest/user.d.ts +1 -0
- package/dist/utils/sharepoint.rest/user.js +200 -169
- package/dist/utils/sharepoint.rest/user.js.map +1 -1
- package/dist/utils/sharepoint.rest/web.d.ts +10 -1
- package/dist/utils/sharepoint.rest/web.js +381 -401
- package/dist/utils/sharepoint.rest/web.js.map +1 -1
- package/dist/utils/sod.js +8 -19
- package/dist/utils/sod.js.map +1 -1
- package/package.json +5 -4
- package/src/helpers/browser.ts +56 -13
- package/src/helpers/date.ts +23 -1
- package/src/helpers/strings.test.js +14 -2
- package/src/helpers/strings.ts +2 -1
- package/src/utils/rest.ts +7 -0
- package/src/utils/sharepoint.rest/file.folder.ts +18 -1
- package/src/utils/sharepoint.rest/item.ts +54 -1
- package/src/utils/sharepoint.rest/list.ts +144 -0
- package/src/utils/sharepoint.rest/user-search.ts +10 -14
- package/src/utils/sharepoint.rest/user.ts +49 -3
- 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,
|
|
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,
|
|
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,
|
|
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) =>
|
|
108
|
+
.then(async (r) => {
|
|
113
109
|
let list = r.d;
|
|
114
110
|
if (options) {
|
|
115
111
|
if (options.includeViews)
|
|
116
|
-
list.Views =
|
|
112
|
+
list.Views = await GetListViews(siteUrl, listIdOrTitle, options.viewOptions);
|
|
117
113
|
if (options.includeContentTypes)
|
|
118
|
-
list.ContentTypes =
|
|
114
|
+
list.ContentTypes = await GetListContentTypes(siteUrl, listIdOrTitle);
|
|
119
115
|
if (options.includeRootFolder)
|
|
120
|
-
list.RootFolder =
|
|
116
|
+
list.RootFolder = await GetListRootFolder(siteUrl, listIdOrTitle);
|
|
121
117
|
if (options.includeEventReceivers)
|
|
122
|
-
list.EventReceivers =
|
|
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
|
-
|
|
166
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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) =>
|
|
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 =
|
|
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
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
if
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
if (thisField
|
|
415
|
-
if (thisField) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
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
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
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
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
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
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
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
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
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
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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
|
-
|
|
823
|
-
|
|
824
|
-
|
|
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
|
-
|
|
831
|
-
|
|
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
|
-
|
|
838
|
-
|
|
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
|
-
|
|
845
|
-
|
|
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
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
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
|