@kwiz/common 1.0.1
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/LICENSE +21 -0
- package/dist/_dependencies.d.ts +1 -0
- package/dist/_dependencies.js +8 -0
- package/dist/_dependencies.js.map +1 -0
- package/dist/helpers/Guid.d.ts +119 -0
- package/dist/helpers/Guid.js +183 -0
- package/dist/helpers/Guid.js.map +1 -0
- package/dist/helpers/_dependencies.d.ts +2 -0
- package/dist/helpers/_dependencies.js +21 -0
- package/dist/helpers/_dependencies.js.map +1 -0
- package/dist/helpers/base64.d.ts +8 -0
- package/dist/helpers/base64.js +178 -0
- package/dist/helpers/base64.js.map +1 -0
- package/dist/helpers/browser.d.ts +144 -0
- package/dist/helpers/browser.js +1200 -0
- package/dist/helpers/browser.js.map +1 -0
- package/dist/helpers/browserinfo.d.ts +23 -0
- package/dist/helpers/browserinfo.js +215 -0
- package/dist/helpers/browserinfo.js.map +1 -0
- package/dist/helpers/collections.base.d.ts +128 -0
- package/dist/helpers/collections.base.js +430 -0
- package/dist/helpers/collections.base.js.map +1 -0
- package/dist/helpers/collections.d.ts +18 -0
- package/dist/helpers/collections.js +99 -0
- package/dist/helpers/collections.js.map +1 -0
- package/dist/helpers/color.d.ts +11 -0
- package/dist/helpers/color.js +57 -0
- package/dist/helpers/color.js.map +1 -0
- package/dist/helpers/cookies.d.ts +6 -0
- package/dist/helpers/cookies.js +56 -0
- package/dist/helpers/cookies.js.map +1 -0
- package/dist/helpers/date.d.ts +43 -0
- package/dist/helpers/date.js +158 -0
- package/dist/helpers/date.js.map +1 -0
- package/dist/helpers/debug.d.ts +33 -0
- package/dist/helpers/debug.js +177 -0
- package/dist/helpers/debug.js.map +1 -0
- package/dist/helpers/emails.d.ts +2 -0
- package/dist/helpers/emails.js +10 -0
- package/dist/helpers/emails.js.map +1 -0
- package/dist/helpers/eval.d.ts +1 -0
- package/dist/helpers/eval.js +10 -0
- package/dist/helpers/eval.js.map +1 -0
- package/dist/helpers/file.d.ts +11 -0
- package/dist/helpers/file.js +55 -0
- package/dist/helpers/file.js.map +1 -0
- package/dist/helpers/flatted.d.ts +20 -0
- package/dist/helpers/flatted.js +135 -0
- package/dist/helpers/flatted.js.map +1 -0
- package/dist/helpers/functions.d.ts +4 -0
- package/dist/helpers/functions.js +17 -0
- package/dist/helpers/functions.js.map +1 -0
- package/dist/helpers/graph/calendar.types.d.ts +3 -0
- package/dist/helpers/graph/calendar.types.js +15 -0
- package/dist/helpers/graph/calendar.types.js.map +1 -0
- package/dist/helpers/http.d.ts +25 -0
- package/dist/helpers/http.js +70 -0
- package/dist/helpers/http.js.map +1 -0
- package/dist/helpers/images.d.ts +16 -0
- package/dist/helpers/images.js +21 -0
- package/dist/helpers/images.js.map +1 -0
- package/dist/helpers/index.d.ts +29 -0
- package/dist/helpers/index.js +46 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/json.d.ts +3 -0
- package/dist/helpers/json.js +44 -0
- package/dist/helpers/json.js.map +1 -0
- package/dist/helpers/md5.d.ts +5 -0
- package/dist/helpers/md5.js +172 -0
- package/dist/helpers/md5.js.map +1 -0
- package/dist/helpers/objects.d.ts +49 -0
- package/dist/helpers/objects.js +271 -0
- package/dist/helpers/objects.js.map +1 -0
- package/dist/helpers/promises.d.ts +14 -0
- package/dist/helpers/promises.js +112 -0
- package/dist/helpers/promises.js.map +1 -0
- package/dist/helpers/random.d.ts +2 -0
- package/dist/helpers/random.js +32 -0
- package/dist/helpers/random.js.map +1 -0
- package/dist/helpers/scheduler/scheduler.d.ts +39 -0
- package/dist/helpers/scheduler/scheduler.js +109 -0
- package/dist/helpers/scheduler/scheduler.js.map +1 -0
- package/dist/helpers/sharepoint.d.ts +112 -0
- package/dist/helpers/sharepoint.js +629 -0
- package/dist/helpers/sharepoint.js.map +1 -0
- package/dist/helpers/strings.d.ts +56 -0
- package/dist/helpers/strings.js +282 -0
- package/dist/helpers/strings.js.map +1 -0
- package/dist/helpers/typecheckers.d.ts +56 -0
- package/dist/helpers/typecheckers.js +274 -0
- package/dist/helpers/typecheckers.js.map +1 -0
- package/dist/helpers/url.d.ts +46 -0
- package/dist/helpers/url.js +199 -0
- package/dist/helpers/url.js.map +1 -0
- package/dist/helpers/urlhelper.d.ts +16 -0
- package/dist/helpers/urlhelper.js +96 -0
- package/dist/helpers/urlhelper.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/types/common.types.d.ts +19 -0
- package/dist/types/common.types.js +4 -0
- package/dist/types/common.types.js.map +1 -0
- package/dist/types/flatted.types.d.ts +49 -0
- package/dist/types/flatted.types.js +3 -0
- package/dist/types/flatted.types.js.map +1 -0
- package/dist/types/globals.types.d.ts +6 -0
- package/dist/types/globals.types.js +3 -0
- package/dist/types/globals.types.js.map +1 -0
- package/dist/types/graph/calendar.types.d.ts +79 -0
- package/dist/types/graph/calendar.types.js +3 -0
- package/dist/types/graph/calendar.types.js.map +1 -0
- package/dist/types/graph/index.d.ts +1 -0
- package/dist/types/graph/index.js +18 -0
- package/dist/types/graph/index.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +28 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/knownscript.types.d.ts +22 -0
- package/dist/types/knownscript.types.js +3 -0
- package/dist/types/knownscript.types.js.map +1 -0
- package/dist/types/libs/datajs.types.d.ts +29 -0
- package/dist/types/libs/datajs.types.js +3 -0
- package/dist/types/libs/datajs.types.js.map +1 -0
- package/dist/types/libs/ics.types.d.ts +29 -0
- package/dist/types/libs/ics.types.js +3 -0
- package/dist/types/libs/ics.types.js.map +1 -0
- package/dist/types/libs/index.d.ts +3 -0
- package/dist/types/libs/index.js +20 -0
- package/dist/types/libs/index.js.map +1 -0
- package/dist/types/libs/msal.types.d.ts +33 -0
- package/dist/types/libs/msal.types.js +63 -0
- package/dist/types/libs/msal.types.js.map +1 -0
- package/dist/types/locales.d.ts +122 -0
- package/dist/types/locales.js +1 -0
- package/dist/types/locales.js.map +1 -0
- package/dist/types/localstoragecache.types.d.ts +8 -0
- package/dist/types/localstoragecache.types.js +3 -0
- package/dist/types/localstoragecache.types.js.map +1 -0
- package/dist/types/moment.d.ts +6 -0
- package/dist/types/moment.js +1 -0
- package/dist/types/moment.js.map +1 -0
- package/dist/types/regex.types.d.ts +14 -0
- package/dist/types/regex.types.js +3 -0
- package/dist/types/regex.types.js.map +1 -0
- package/dist/types/rest.types.d.ts +81 -0
- package/dist/types/rest.types.js +24 -0
- package/dist/types/rest.types.js.map +1 -0
- package/dist/types/sharepoint.types.d.ts +1432 -0
- package/dist/types/sharepoint.types.js +629 -0
- package/dist/types/sharepoint.types.js.map +1 -0
- package/dist/types/sharepoint.utils.types.d.ts +246 -0
- package/dist/types/sharepoint.utils.types.js +26 -0
- package/dist/types/sharepoint.utils.types.js.map +1 -0
- package/dist/utils/_dependencies.d.ts +3 -0
- package/dist/utils/_dependencies.js +24 -0
- package/dist/utils/_dependencies.js.map +1 -0
- package/dist/utils/base64.d.ts +2 -0
- package/dist/utils/base64.js +41 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/consolelogger.d.ts +73 -0
- package/dist/utils/consolelogger.js +281 -0
- package/dist/utils/consolelogger.js.map +1 -0
- package/dist/utils/date.d.ts +10 -0
- package/dist/utils/date.js +30 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/emails.d.ts +2 -0
- package/dist/utils/emails.js +24 -0
- package/dist/utils/emails.js.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/knownscript.d.ts +99 -0
- package/dist/utils/knownscript.js +261 -0
- package/dist/utils/knownscript.js.map +1 -0
- package/dist/utils/localstoragecache.d.ts +19 -0
- package/dist/utils/localstoragecache.js +372 -0
- package/dist/utils/localstoragecache.js.map +1 -0
- package/dist/utils/rest.d.ts +17 -0
- package/dist/utils/rest.js +402 -0
- package/dist/utils/rest.js.map +1 -0
- package/dist/utils/script.d.ts +33 -0
- package/dist/utils/script.js +169 -0
- package/dist/utils/script.js.map +1 -0
- package/dist/utils/sharepoint.rest/common.d.ts +32 -0
- package/dist/utils/sharepoint.rest/common.js +146 -0
- package/dist/utils/sharepoint.rest/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/date.d.ts +2 -0
- package/dist/utils/sharepoint.rest/date.js +57 -0
- package/dist/utils/sharepoint.rest/date.js.map +1 -0
- package/dist/utils/sharepoint.rest/file.folder.d.ts +58 -0
- package/dist/utils/sharepoint.rest/file.folder.js +305 -0
- package/dist/utils/sharepoint.rest/file.folder.js.map +1 -0
- package/dist/utils/sharepoint.rest/index.d.ts +11 -0
- package/dist/utils/sharepoint.rest/index.js +28 -0
- package/dist/utils/sharepoint.rest/index.js.map +1 -0
- package/dist/utils/sharepoint.rest/item.d.ts +81 -0
- package/dist/utils/sharepoint.rest/item.js +444 -0
- package/dist/utils/sharepoint.rest/item.js.map +1 -0
- package/dist/utils/sharepoint.rest/list.d.ts +228 -0
- package/dist/utils/sharepoint.rest/list.js +868 -0
- package/dist/utils/sharepoint.rest/list.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.d.ts +19 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +629 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.d.ts +14 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +222 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/common.d.ts +3 -0
- package/dist/utils/sharepoint.rest/listutils/common.js +198 -0
- package/dist/utils/sharepoint.rest/listutils/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/user-search.d.ts +76 -0
- package/dist/utils/sharepoint.rest/user-search.js +239 -0
- package/dist/utils/sharepoint.rest/user-search.js.map +1 -0
- package/dist/utils/sharepoint.rest/user.d.ts +71 -0
- package/dist/utils/sharepoint.rest/user.js +404 -0
- package/dist/utils/sharepoint.rest/user.js.map +1 -0
- package/dist/utils/sharepoint.rest/web.d.ts +107 -0
- package/dist/utils/sharepoint.rest/web.js +929 -0
- package/dist/utils/sharepoint.rest/web.js.map +1 -0
- package/dist/utils/sod.d.ts +29 -0
- package/dist/utils/sod.js +177 -0
- package/dist/utils/sod.js.map +1 -0
- package/package.json +60 -0
- package/readme.md +13 -0
- package/src/_dependencies.ts +2 -0
- package/src/helpers/Guid.ts +182 -0
- package/src/helpers/_dependencies.ts +3 -0
- package/src/helpers/base64.ts +174 -0
- package/src/helpers/browser.test.js +9 -0
- package/src/helpers/browser.ts +1299 -0
- package/src/helpers/browserinfo.ts +293 -0
- package/src/helpers/collections.base.test.js +26 -0
- package/src/helpers/collections.base.ts +439 -0
- package/src/helpers/collections.ts +108 -0
- package/src/helpers/color.ts +55 -0
- package/src/helpers/cookies.ts +55 -0
- package/src/helpers/date.test.js +97 -0
- package/src/helpers/date.ts +163 -0
- package/src/helpers/debug.ts +187 -0
- package/src/helpers/emails.ts +7 -0
- package/src/helpers/eval.ts +5 -0
- package/src/helpers/file.test.js +51 -0
- package/src/helpers/file.ts +59 -0
- package/src/helpers/flatted.ts +150 -0
- package/src/helpers/functions.ts +17 -0
- package/src/helpers/graph/calendar.types.ts +11 -0
- package/src/helpers/http.ts +70 -0
- package/src/helpers/images.ts +23 -0
- package/src/helpers/index.ts +29 -0
- package/src/helpers/json.ts +39 -0
- package/src/helpers/md5.ts +190 -0
- package/src/helpers/objects.test.js +27 -0
- package/src/helpers/objects.ts +256 -0
- package/src/helpers/promises.test.js +18 -0
- package/src/helpers/promises.ts +102 -0
- package/src/helpers/random.ts +27 -0
- package/src/helpers/scheduler/scheduler.test.js +104 -0
- package/src/helpers/scheduler/scheduler.ts +132 -0
- package/src/helpers/sharepoint.ts +681 -0
- package/src/helpers/strings.test.js +43 -0
- package/src/helpers/strings.ts +288 -0
- package/src/helpers/typecheckers.test.js +35 -0
- package/src/helpers/typecheckers.ts +263 -0
- package/src/helpers/url.test.js +18 -0
- package/src/helpers/url.ts +202 -0
- package/src/helpers/urlhelper.ts +104 -0
- package/src/index.ts +24 -0
- package/src/types/common.types.ts +16 -0
- package/src/types/flatted.types.ts +60 -0
- package/src/types/globals.types.ts +7 -0
- package/src/types/graph/calendar.types.ts +81 -0
- package/src/types/graph/index.ts +1 -0
- package/src/types/index.ts +12 -0
- package/src/types/knownscript.types.ts +19 -0
- package/src/types/libs/datajs.types.ts +29 -0
- package/src/types/libs/ics.types.ts +31 -0
- package/src/types/libs/index.ts +4 -0
- package/src/types/libs/msal.types.ts +79 -0
- package/src/types/locales.ts +125 -0
- package/src/types/localstoragecache.types.ts +9 -0
- package/src/types/moment.ts +7 -0
- package/src/types/regex.types.ts +17 -0
- package/src/types/rest.types.ts +94 -0
- package/src/types/sharepoint.types.ts +1413 -0
- package/src/types/sharepoint.utils.types.ts +246 -0
- package/src/utils/_dependencies.ts +4 -0
- package/src/utils/base64.ts +27 -0
- package/src/utils/consolelogger.ts +315 -0
- package/src/utils/date.ts +36 -0
- package/src/utils/emails.ts +25 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/knownscript.ts +280 -0
- package/src/utils/localstoragecache.ts +419 -0
- package/src/utils/rest.ts +465 -0
- package/src/utils/script.ts +168 -0
- package/src/utils/sharepoint.rest/common.ts +149 -0
- package/src/utils/sharepoint.rest/date.ts +61 -0
- package/src/utils/sharepoint.rest/file.folder.ts +368 -0
- package/src/utils/sharepoint.rest/index.ts +11 -0
- package/src/utils/sharepoint.rest/item.ts +456 -0
- package/src/utils/sharepoint.rest/list.ts +1144 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +750 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +265 -0
- package/src/utils/sharepoint.rest/listutils/common.ts +202 -0
- package/src/utils/sharepoint.rest/user-search.ts +254 -0
- package/src/utils/sharepoint.rest/user.ts +447 -0
- package/src/utils/sharepoint.rest/web.ts +1031 -0
- package/src/utils/sod.ts +193 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,1144 @@
|
|
|
1
|
+
import { BaseTypes, FieldTypeAsString, FieldTypes, GeListItemsFoldersBehaviour, IDictionary, IFieldInfo, IFieldInfoEX, IFieldInfoExHash, IFieldJsonSchema, IFieldLookupInfo, IListWorkflowAssociation, IRestItem, IRestOptions, ISPEventReceiver, ListExperienceOptions, ListTemplateTypes, NormalizeListName, PageType, PushNoDuplicate, SPBasePermissionKind, SPBasePermissions, SafeIfElse, SchemaXmlToJson, contentTypes, extendFieldInfo, firstOrNull, iContentType, iList, iListView, isBoolean, isNotEmptyArray, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isNumber, isPromise, isString, isValidGuid, jsonStringify, jsonTypes, makeServerRelativeUrl, makeUniqueArray, normalizeGuid, normalizeUrl, toHash } from "../_dependencies";
|
|
2
|
+
import { GetJson, GetJsonSync, longLocalCache, shortLocalCache } from "../rest";
|
|
3
|
+
import { GetRestBaseUrl, GetSiteUrl, LIST_EXPAND, LIST_SELECT } from "./common";
|
|
4
|
+
import { __fixGetListItemsResults } from "./listutils/common";
|
|
5
|
+
import { GetContentTypes, GetContentTypesSync, GetListsSync } from "./web";
|
|
6
|
+
|
|
7
|
+
/** returns /_api/web/lists/getById() or /_api/web/lists/getByTitle() */
|
|
8
|
+
export function GetListRestUrl(siteUrl: string, listIdOrTitle: string): string {
|
|
9
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
10
|
+
|
|
11
|
+
let listId = GetListId(siteUrl, listIdOrTitle);
|
|
12
|
+
|
|
13
|
+
let listPart = isValidGuid(listId) ? `getById('${normalizeGuid(listId)}')` : `getByTitle('${encodeURIComponent(listIdOrTitle)}')`;
|
|
14
|
+
return GetRestBaseUrl(siteUrl) + `/web/lists/${listPart}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function GetListId(siteUrl: string, listIdOrTitle: string): string {
|
|
18
|
+
if (isNullOrEmptyString(listIdOrTitle)) return null;
|
|
19
|
+
if (isValidGuid(listIdOrTitle)) return listIdOrTitle;
|
|
20
|
+
//Issue 7508
|
|
21
|
+
//When translation is enabled, and user changes list title but he is not on the same language as the site
|
|
22
|
+
//he translates the list, but not changing its title
|
|
23
|
+
//so REST api /lists/getByTitle will not work
|
|
24
|
+
//instead, we need to get the list id from the web's lists collection.
|
|
25
|
+
let lists = GetListsSync(siteUrl);
|
|
26
|
+
var lower = listIdOrTitle.toLowerCase();
|
|
27
|
+
var list = firstOrNull(lists, l => l.Title.toLowerCase() === lower);
|
|
28
|
+
return list && list.Id || null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** get the list ID from a list page, such as a list view or an item form */
|
|
32
|
+
export function GetListIdFromPageSync(siteUrl: string, listPageUrl: string): string {
|
|
33
|
+
let url = `${GetRestBaseUrl(siteUrl)}/web/getlist('${makeServerRelativeUrl(listPageUrl.split('?')[0].split('#')[0])}')?$select=id`;
|
|
34
|
+
let response = GetJsonSync<{ Id: string; }>(url, null, {
|
|
35
|
+
...longLocalCache,
|
|
36
|
+
jsonMetadata: jsonTypes.nometadata
|
|
37
|
+
});
|
|
38
|
+
if (!isNullOrUndefined(response) && response.success) {
|
|
39
|
+
let listId = response.result.Id;
|
|
40
|
+
return normalizeGuid(listId);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface IGetSiteAssetLibraryResult { Id: string, Name: string, ServerRelativeUrl: string }
|
|
46
|
+
interface IGetSiteAssetLibraryReturnValue {
|
|
47
|
+
value: {
|
|
48
|
+
Id: string;
|
|
49
|
+
RootFolder: {
|
|
50
|
+
Name: string;
|
|
51
|
+
ServerRelativeUrl: string;
|
|
52
|
+
Exists: boolean;
|
|
53
|
+
};
|
|
54
|
+
}[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** ensures the site assets library exists and return its info. on errors - it will return null. */
|
|
58
|
+
export function EnsureAssetLibrary(siteUrl: string): Promise<IGetSiteAssetLibraryResult> {
|
|
59
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
60
|
+
|
|
61
|
+
var url = GetRestBaseUrl(siteUrl) +
|
|
62
|
+
"/web/lists/EnsureSiteAssetsLibrary?$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists&$expand=RootFolder";
|
|
63
|
+
return GetJson<{
|
|
64
|
+
d: { Id: string; RootFolder: { Name: string; ServerRelativeUrl: string; Exists: boolean; }; };
|
|
65
|
+
}>(url, null, { method: "POST", spWebUrl: siteUrl, ...longLocalCache }).then(result => {
|
|
66
|
+
if (result && result.d) {
|
|
67
|
+
return {
|
|
68
|
+
Id: result.d.Id,
|
|
69
|
+
Name: result.d.RootFolder.Name,
|
|
70
|
+
ServerRelativeUrl: result.d.RootFolder.ServerRelativeUrl
|
|
71
|
+
};
|
|
72
|
+
} else return null;
|
|
73
|
+
}).catch<IGetSiteAssetLibraryResult>(() => null);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function GetSiteAssetLibrary(siteUrl: string, sync?: false): Promise<IGetSiteAssetLibraryResult>;
|
|
77
|
+
export function GetSiteAssetLibrary(siteUrl: string, sync: true): IGetSiteAssetLibraryResult;
|
|
78
|
+
export function GetSiteAssetLibrary(siteUrl: string, sync?: boolean): IGetSiteAssetLibraryResult | Promise<IGetSiteAssetLibraryResult> {
|
|
79
|
+
let reqUrl = `${GetRestBaseUrl(siteUrl)}/web/lists?`
|
|
80
|
+
//Issue 1492: isSiteAssetsLibrary eq true does not work for reader users.
|
|
81
|
+
//+ `$filter=isSiteAssetsLibrary eq true&$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists`
|
|
82
|
+
+ `$filter=EntityTypeName%20eq%20%27SiteAssets%27&$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists`
|
|
83
|
+
+ `&$expand=RootFolder`;
|
|
84
|
+
|
|
85
|
+
let caller = sync ? GetJsonSync : GetJson;
|
|
86
|
+
|
|
87
|
+
let result = caller<IGetSiteAssetLibraryReturnValue>(reqUrl, null, { ...longLocalCache, jsonMetadata: jsonTypes.nometadata });
|
|
88
|
+
|
|
89
|
+
let transform: (v: IGetSiteAssetLibraryReturnValue) => IGetSiteAssetLibraryResult = (v) => {
|
|
90
|
+
if (isNotEmptyArray(v && v.value)) {
|
|
91
|
+
let assetLibrary = v.value[0];
|
|
92
|
+
return {
|
|
93
|
+
Id: assetLibrary.Id,
|
|
94
|
+
Name: assetLibrary.RootFolder.Name,
|
|
95
|
+
ServerRelativeUrl: assetLibrary.RootFolder.ServerRelativeUrl
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
if (isPromise(result))
|
|
102
|
+
return result.then(r => transform(r), () => null);
|
|
103
|
+
else
|
|
104
|
+
return result.success ? transform(result.result) : null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Return the list Title */
|
|
108
|
+
export function GetListTitle(siteUrl: string, listIdOrTitle: string): Promise<string> {
|
|
109
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
110
|
+
|
|
111
|
+
return GetJson<{ d: { Title: string; }; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `/Title`, null, { allowCache: true })
|
|
112
|
+
.then(r => {
|
|
113
|
+
return r.d.Title;
|
|
114
|
+
})
|
|
115
|
+
.catch<string>(() => null);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Return the list */
|
|
119
|
+
export function GetList(siteUrlOrId: string, listIdOrTitle: string, options?: {
|
|
120
|
+
includeViews?: boolean;
|
|
121
|
+
viewOptions?: IListViewOptions;
|
|
122
|
+
includeContentTypes?: boolean;
|
|
123
|
+
includeRootFolder?: boolean;
|
|
124
|
+
includeEventReceivers?: boolean;
|
|
125
|
+
}): Promise<iList> {
|
|
126
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
127
|
+
|
|
128
|
+
if (isNullOrEmptyString(listIdOrTitle)) return null;
|
|
129
|
+
|
|
130
|
+
return GetJson<{ d: iList; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `?$select=${LIST_SELECT}&$expand=${LIST_EXPAND}`, null, { allowCache: true })
|
|
131
|
+
.then(async r => {
|
|
132
|
+
let list = r.d;
|
|
133
|
+
if (options) {
|
|
134
|
+
if (options.includeViews)
|
|
135
|
+
list.Views = await GetListViews(siteUrl, listIdOrTitle, options.viewOptions);
|
|
136
|
+
if (options.includeContentTypes)
|
|
137
|
+
list.ContentTypes = await GetListContentTypes(siteUrl, listIdOrTitle);
|
|
138
|
+
if (options.includeRootFolder)
|
|
139
|
+
list.RootFolder = await GetListRootFolder(siteUrl, listIdOrTitle);
|
|
140
|
+
if (options.includeEventReceivers)
|
|
141
|
+
list.EventReceivers = await GetListEventReceivers(siteUrl, listIdOrTitle);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (list.EffectiveBasePermissions
|
|
145
|
+
&& (isString(list.EffectiveBasePermissions.High)
|
|
146
|
+
|| isString(list.EffectiveBasePermissions.Low))) {
|
|
147
|
+
list.EffectiveBasePermissions = {
|
|
148
|
+
High: Number(list.EffectiveBasePermissions.High),
|
|
149
|
+
Low: Number(list.EffectiveBasePermissions.Low)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return list;
|
|
154
|
+
})
|
|
155
|
+
.catch<iList>(() => null);
|
|
156
|
+
}
|
|
157
|
+
/** Return the list */
|
|
158
|
+
export function GetListSync(siteUrl: string, listIdOrTitle: string): iList {
|
|
159
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
160
|
+
|
|
161
|
+
if (isNullOrEmptyString(listIdOrTitle)) return null;
|
|
162
|
+
|
|
163
|
+
let result = GetJsonSync<{ d: iList; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `?$select=${LIST_SELECT}&$expand=${LIST_EXPAND}`, null, shortLocalCache);
|
|
164
|
+
if (result && result.success) {
|
|
165
|
+
let list = result.result.d;
|
|
166
|
+
|
|
167
|
+
if (list.EffectiveBasePermissions
|
|
168
|
+
&& (isString(list.EffectiveBasePermissions.High)
|
|
169
|
+
|| isString(list.EffectiveBasePermissions.Low))) {
|
|
170
|
+
list.EffectiveBasePermissions = {
|
|
171
|
+
High: Number(list.EffectiveBasePermissions.High),
|
|
172
|
+
Low: Number(list.EffectiveBasePermissions.Low)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return list;
|
|
177
|
+
}
|
|
178
|
+
else return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function GetListNameSync(webUrl: string, listIdOrTitle: string): string {
|
|
182
|
+
let list = GetListSync(webUrl, listIdOrTitle);
|
|
183
|
+
return NormalizeListName({ EntityTypeName: list.EntityTypeName, BaseType: list.BaseType });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function GetListName(webUrl: string, listIdOrTitle: string) {
|
|
187
|
+
let list = await GetList(webUrl, listIdOrTitle);
|
|
188
|
+
return NormalizeListName({ EntityTypeName: list.EntityTypeName, BaseType: list.BaseType });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function GetListRootFolder(siteUrlOrId: string, listIdOrTitle: string): Promise<{ ServerRelativeUrl: string; Name: string; }> {
|
|
192
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
193
|
+
|
|
194
|
+
return GetJson<{
|
|
195
|
+
d: { ServerRelativeUrl: string; Name: string; };
|
|
196
|
+
}>(GetListRestUrl(siteUrl, listIdOrTitle) + `/RootFolder?$Select=Name,ServerRelativeUrl`,
|
|
197
|
+
null, longLocalCache)
|
|
198
|
+
.then(r => {
|
|
199
|
+
return r.d;
|
|
200
|
+
})
|
|
201
|
+
.catch<{ ServerRelativeUrl: string; Name: string; }>(() => null);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function GetListRootFolderSync(siteUrlOrId: string, listIdOrTitle: string): { ServerRelativeUrl: string; Name: string; } {
|
|
205
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
206
|
+
|
|
207
|
+
let result = GetJsonSync<{
|
|
208
|
+
d: { ServerRelativeUrl: string; Name: string; };
|
|
209
|
+
}>(GetListRestUrl(siteUrl, listIdOrTitle) + `/RootFolder?$Select=Name,ServerRelativeUrl`,
|
|
210
|
+
null, longLocalCache);
|
|
211
|
+
|
|
212
|
+
return SafeIfElse(() => result.result.d, null);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function GetListField(siteUrlOrId: string, listIdOrTitle: string, fieldIdOrName: string, refreshCache?: boolean): Promise<IFieldInfo> {
|
|
216
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
217
|
+
|
|
218
|
+
var url = GetListRestUrl(siteUrl, listIdOrTitle) + `/fields`;
|
|
219
|
+
|
|
220
|
+
if (isValidGuid(fieldIdOrName)) {
|
|
221
|
+
url += `('${normalizeGuid(fieldIdOrName)}')`;
|
|
222
|
+
} else {
|
|
223
|
+
url += `/getbyinternalnameortitle(@u)?@u='${encodeURIComponent(fieldIdOrName)}'`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let result = GetJson<{ d: IFieldInfo; }>(url, null, { allowCache: refreshCache !== true })
|
|
227
|
+
.then(r => {
|
|
228
|
+
return r.d;
|
|
229
|
+
})
|
|
230
|
+
.catch<IFieldInfo>(() => null);
|
|
231
|
+
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function _getListFieldsRequestUrl(siteUrl: string, listIdOrTitle: string) {
|
|
236
|
+
return GetListRestUrl(siteUrl, listIdOrTitle) + `/fields`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Gets ID, Title, ContentType Author, Editor, Created and Modified fields */
|
|
240
|
+
export function GetStandardListFields(siteUrlOrId: string, listIdOrTitle: string, refreshCache?: boolean) {
|
|
241
|
+
let fieldNames = ["ID", "Title", "ContentType", "Author", "Editor", "Created", "Modified"];
|
|
242
|
+
return GetListFields(siteUrlOrId, listIdOrTitle, { refreshCache: refreshCache, fieldNames: fieldNames });
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface IGetListFieldsOptions {
|
|
246
|
+
refreshCache?: boolean;
|
|
247
|
+
/** fieldNames that should be returned with the request */
|
|
248
|
+
fieldNames?: string[];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function _processGetListFields(fields: IFieldInfo[], fieldNames: string[]) {
|
|
252
|
+
if (isNullOrEmptyArray(fields)) {
|
|
253
|
+
return fields as IFieldInfoEX[];
|
|
254
|
+
}
|
|
255
|
+
let extendedFields = fields.map(f => extendFieldInfo(f, fields));
|
|
256
|
+
|
|
257
|
+
if (!isNullOrEmptyArray(fieldNames)) {
|
|
258
|
+
return extendedFields.filter((extendedField) => {
|
|
259
|
+
return fieldNames.includes(extendedField.InternalName);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return extendedFields;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function GetListFields(siteUrlOrId: string, listIdOrTitle: string, options: IGetListFieldsOptions = {}): Promise<IFieldInfoEX[]> {
|
|
266
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
267
|
+
let url = _getListFieldsRequestUrl(siteUrl, listIdOrTitle);
|
|
268
|
+
|
|
269
|
+
let restOptions: IRestOptions = {
|
|
270
|
+
allowCache: options.refreshCache !== true,
|
|
271
|
+
jsonMetadata: jsonTypes.nometadata
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
return GetJson<{ value: IFieldInfo[]; }>(url, null, restOptions)
|
|
275
|
+
.then((result) => {
|
|
276
|
+
return _processGetListFields(result.value, options.fieldNames);
|
|
277
|
+
}).catch<IFieldInfoEX[]>(() => {
|
|
278
|
+
return null;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function GetListFieldsSync(siteUrlOrId: string, listIdOrTitle: string, options: IGetListFieldsOptions = {}): IFieldInfoEX[] {
|
|
283
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
284
|
+
let url = _getListFieldsRequestUrl(siteUrl, listIdOrTitle);
|
|
285
|
+
|
|
286
|
+
let restOptions: IRestOptions = {
|
|
287
|
+
allowCache: options.refreshCache !== true,
|
|
288
|
+
jsonMetadata: jsonTypes.nometadata
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
let result = GetJsonSync<{ value: IFieldInfo[]; }>(url, null, restOptions);
|
|
292
|
+
if (result.success && !isNullOrUndefined(result.result)) {
|
|
293
|
+
return _processGetListFields(result.result.value, options.fieldNames);
|
|
294
|
+
}
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export async function GetListFieldsAsHash(siteUrlOrId: string, listIdOrTitle: string, refreshCache?: boolean): Promise<IFieldInfoExHash> {
|
|
299
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
300
|
+
|
|
301
|
+
let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: refreshCache });
|
|
302
|
+
let hash: IFieldInfoExHash = {};
|
|
303
|
+
if (isNotEmptyArray(fields)) {
|
|
304
|
+
hash = toHash(fields, f => f.InternalName);
|
|
305
|
+
}
|
|
306
|
+
return hash;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function GetListFieldsAsHashSync(siteUrlOrId: string, listIdOrTitle: string, refreshCache?: boolean): IFieldInfoExHash {
|
|
310
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
311
|
+
|
|
312
|
+
let fields = GetListFieldsSync(siteUrl, listIdOrTitle, { refreshCache: refreshCache });
|
|
313
|
+
let hash: IFieldInfoExHash = {};
|
|
314
|
+
if (isNotEmptyArray(fields)) {
|
|
315
|
+
fields.forEach(f => { hash[f.InternalName] = f; });
|
|
316
|
+
}
|
|
317
|
+
return hash;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function GetListWorkflows(siteUrl: string, listIdOrTitle: string, refreshCache?: boolean): Promise<IListWorkflowAssociation[]> {
|
|
321
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
322
|
+
|
|
323
|
+
return GetJson<{
|
|
324
|
+
d: { results: IListWorkflowAssociation[]; };
|
|
325
|
+
}>(GetListRestUrl(siteUrl, listIdOrTitle) + `/workflowAssociations`,
|
|
326
|
+
null, { allowCache: refreshCache !== true })
|
|
327
|
+
.then(r => {
|
|
328
|
+
if (r && r.d && isNotEmptyArray(r.d.results)) {
|
|
329
|
+
r.d.results.forEach(wf => {
|
|
330
|
+
wf.BaseId = normalizeGuid(wf.BaseId);
|
|
331
|
+
wf.Id = normalizeGuid(wf.Id);
|
|
332
|
+
wf.ListId = normalizeGuid(wf.ListId);
|
|
333
|
+
wf.WebId = normalizeGuid(wf.WebId);
|
|
334
|
+
});
|
|
335
|
+
return r.d.results;
|
|
336
|
+
}
|
|
337
|
+
else return [];
|
|
338
|
+
})
|
|
339
|
+
.catch<IListWorkflowAssociation[]>(() => []);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export function UserHasManagePermissions(siteUrl: string, listIdOrTitle: string): Promise<boolean> {
|
|
343
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
344
|
+
|
|
345
|
+
return GetJson<{ d: { EffectiveBasePermissions: { High: number; Low: number; }; }; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null,
|
|
346
|
+
{ ...shortLocalCache })
|
|
347
|
+
.then(r => {
|
|
348
|
+
return new SPBasePermissions(r.d.EffectiveBasePermissions).has(SPBasePermissionKind.ManageLists);
|
|
349
|
+
})
|
|
350
|
+
.catch<boolean>(() => null);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export function UserHasEditPermissions(siteUrl: string, listIdOrTitle: string): Promise<boolean> {
|
|
354
|
+
return UserHasPermissions(siteUrl, listIdOrTitle, SPBasePermissionKind.EditListItems);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function UserHasPermissions(siteUrlOrId: string, listIdOrTitle: string, permissionKind: SPBasePermissionKind): Promise<boolean> {
|
|
358
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
359
|
+
|
|
360
|
+
return GetJson<{ d: { EffectiveBasePermissions: { High: number; Low: number; }; }; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null,
|
|
361
|
+
{ ...shortLocalCache })
|
|
362
|
+
.then(r => {
|
|
363
|
+
return new SPBasePermissions(r.d.EffectiveBasePermissions).has(permissionKind);
|
|
364
|
+
})
|
|
365
|
+
.catch<boolean>(() => null);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export function UserHasPermissionsSync(siteUrlOrId: string, listIdOrTitle: string, permissionKind: SPBasePermissionKind): boolean {
|
|
369
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
370
|
+
|
|
371
|
+
const res = GetJsonSync<{ d: { EffectiveBasePermissions: { High: number; Low: number; }; }; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null,
|
|
372
|
+
{ ...shortLocalCache });
|
|
373
|
+
|
|
374
|
+
return new SPBasePermissions(res.result.d.EffectiveBasePermissions).has(permissionKind);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** 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 */
|
|
378
|
+
export function CreateField(siteUrl: string, listIdOrTitle: string, options: {
|
|
379
|
+
Title?: string;
|
|
380
|
+
Type?: FieldTypes;
|
|
381
|
+
Required?: boolean;
|
|
382
|
+
SchemaXml?: string;
|
|
383
|
+
SchemaXmlSpecificInternalName?: boolean;
|
|
384
|
+
SkipAddToDefaultView?: boolean;
|
|
385
|
+
ClientSideComponentId?: string;
|
|
386
|
+
ClientSideComponentProperties?: string;
|
|
387
|
+
|
|
388
|
+
}): Promise<IFieldInfoEX> {
|
|
389
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
390
|
+
|
|
391
|
+
let finish = async (result: { d: IFieldInfo; }) => {
|
|
392
|
+
if (result && result.d) {
|
|
393
|
+
let internalName = result.d.InternalName;
|
|
394
|
+
//we need to clear and reload the list fields cache, so call it and return our field from that collection.
|
|
395
|
+
let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
|
|
396
|
+
|
|
397
|
+
try {
|
|
398
|
+
if (options.SkipAddToDefaultView !== true) {
|
|
399
|
+
//try to add it to default view, don't wait for it
|
|
400
|
+
GetListViews(siteUrl, listIdOrTitle).then(views => {
|
|
401
|
+
let defaultView = firstOrNull(views, v => v.DefaultView);
|
|
402
|
+
if (defaultView)
|
|
403
|
+
GetJson(GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${defaultView.Id}')/ViewFields/addViewField('${internalName}')`, null, { method: "POST", spWebUrl: siteUrl });
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (e) { }
|
|
408
|
+
|
|
409
|
+
return firstOrNull(fields, f => f.InternalName === internalName);
|
|
410
|
+
}
|
|
411
|
+
return null;
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
if (!isNullOrEmptyString(options.SchemaXml)) {
|
|
415
|
+
return GetJson<{ d: IFieldInfo; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/createFieldAsXml`,
|
|
416
|
+
JSON.stringify({
|
|
417
|
+
'parameters': {
|
|
418
|
+
'__metadata': { 'type': 'SP.XmlSchemaFieldCreationInformation' },
|
|
419
|
+
'SchemaXml': options.SchemaXml,
|
|
420
|
+
'Options': options.SchemaXmlSpecificInternalName !== true ?
|
|
421
|
+
4 ://SP.AddFieldOptions.addToAllContentTypes
|
|
422
|
+
4 | 8//SP.AddFieldOptions.addToAllContentTypes | addFieldInternalNameHint
|
|
423
|
+
}
|
|
424
|
+
}))
|
|
425
|
+
.then(r => {
|
|
426
|
+
return finish(r);
|
|
427
|
+
})
|
|
428
|
+
.catch<IFieldInfoEX>(() => null);
|
|
429
|
+
}
|
|
430
|
+
else if (!isNullOrEmptyString(options.Title) && !isNullOrUndefined(options.Type)) {
|
|
431
|
+
let updateObject: IDictionary<any> = {
|
|
432
|
+
'__metadata': { 'type': 'SP.Field' },
|
|
433
|
+
'Title': options.Title,
|
|
434
|
+
'FieldTypeKind': options.Type,
|
|
435
|
+
'Required': options.Required === true
|
|
436
|
+
};
|
|
437
|
+
if (!isNullOrEmptyString(options.ClientSideComponentId))
|
|
438
|
+
updateObject.ClientSideComponentId = options.ClientSideComponentId;
|
|
439
|
+
if (!isNullOrEmptyString(options.ClientSideComponentProperties))
|
|
440
|
+
updateObject.ClientSideComponentProperties = options.ClientSideComponentProperties;
|
|
441
|
+
|
|
442
|
+
return GetJson<{ d: IFieldInfo; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields`,
|
|
443
|
+
JSON.stringify(updateObject))
|
|
444
|
+
.then(r => {
|
|
445
|
+
return finish(r);
|
|
446
|
+
})
|
|
447
|
+
.catch<IFieldInfoEX>(() => null);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
console.error("You must send either SchemaXml or Title and Type");
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/** Update field SchemaXml OR Title, only 1 update at a time supported. */
|
|
455
|
+
export async function UpdateField(siteUrlOrId: string, listIdOrTitle: string, fieldInternalName: string, options: {
|
|
456
|
+
Title?: string;
|
|
457
|
+
SchemaXml?: string;
|
|
458
|
+
FieldType?: FieldTypeAsString;
|
|
459
|
+
Required?: boolean;
|
|
460
|
+
Hidden?: boolean;
|
|
461
|
+
ClientSideComponentId?: string;
|
|
462
|
+
ClientSideComponentProperties?: string;
|
|
463
|
+
}): Promise<IFieldInfoEX> {
|
|
464
|
+
let siteUrl = GetSiteUrl(siteUrlOrId);
|
|
465
|
+
|
|
466
|
+
let finish = async () => {
|
|
467
|
+
//we need to clear and reload the list fields cache, so call it and return our field from that collection.
|
|
468
|
+
let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
|
|
469
|
+
return firstOrNull(fields, f => f.InternalName === fieldInternalName);
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
//updates can either be SchemaXml, or others. Cannot be both.
|
|
473
|
+
let updates: IDictionary<any> = {
|
|
474
|
+
'__metadata': { 'type': 'SP.Field' }
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
if (!isNullOrEmptyString(options.SchemaXml)) {
|
|
478
|
+
updates.SchemaXml = options.SchemaXml;
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
//cannot send schema updates with other updates.
|
|
482
|
+
|
|
483
|
+
if (!isNullOrEmptyString(options.Title)) {
|
|
484
|
+
updates.Title = options.Title;
|
|
485
|
+
}
|
|
486
|
+
if (!isNullOrEmptyString(options.FieldType)) {
|
|
487
|
+
updates.TypeAsString = options.FieldType;
|
|
488
|
+
}
|
|
489
|
+
if (isBoolean(options.Required)) {
|
|
490
|
+
updates.Required = options.Required === true;
|
|
491
|
+
}
|
|
492
|
+
if (isBoolean(options.Hidden)) {
|
|
493
|
+
//this requries the CanToggleHidden to be in the schema... if not - we will need to add it before we can update this.
|
|
494
|
+
let fields = await GetListFieldsAsHash(siteUrl, listIdOrTitle, false);
|
|
495
|
+
let thisField = fields[fieldInternalName];
|
|
496
|
+
if (thisField.Hidden !== options.Hidden) {
|
|
497
|
+
if (thisField) {
|
|
498
|
+
if (thisField.SchemaJson.Attributes.CanToggleHidden !== "TRUE") {
|
|
499
|
+
await UpdateField(siteUrl, listIdOrTitle, fieldInternalName, {
|
|
500
|
+
SchemaXml:
|
|
501
|
+
thisField.SchemaXml.replace("<Field ", `<Field CanToggleHidden="TRUE" `)
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
updates.Hidden = options.Hidden === true;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (!isNullOrEmptyString(options.ClientSideComponentId))
|
|
510
|
+
updates.ClientSideComponentId = options.ClientSideComponentId;
|
|
511
|
+
if (!isNullOrEmptyString(options.ClientSideComponentProperties))
|
|
512
|
+
updates.ClientSideComponentProperties = options.ClientSideComponentProperties;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (Object.keys(updates).length > 1) {
|
|
516
|
+
return GetJson(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getbyinternalnameortitle('${fieldInternalName}')`,
|
|
517
|
+
JSON.stringify(updates), { xHttpMethod: "MERGE" })
|
|
518
|
+
.then(r => {
|
|
519
|
+
return finish();
|
|
520
|
+
})
|
|
521
|
+
.catch<IFieldInfoEX>(() => null);
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
console.error("You must send an option to update");
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export async function DeleteField(siteUrl: string, listIdOrTitle: string, fieldInternalName: string, options?: { DeleteHiddenField?: boolean; }): Promise<boolean> {
|
|
530
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
531
|
+
|
|
532
|
+
// let finish = async () => {
|
|
533
|
+
// //we need to clear and reload the list fields cache, so call it and return our field from that collection.
|
|
534
|
+
// let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
|
|
535
|
+
// return firstOrNull(fields, f => f.InternalName === fieldInternalName);
|
|
536
|
+
// };
|
|
537
|
+
|
|
538
|
+
if (options && options.DeleteHiddenField)
|
|
539
|
+
await UpdateField(siteUrl, listIdOrTitle, fieldInternalName, { Hidden: false });
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
return GetJson(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getbyinternalnameortitle('${fieldInternalName}')`, null, {
|
|
543
|
+
method: "POST",
|
|
544
|
+
xHttpMethod: "DELETE"
|
|
545
|
+
})
|
|
546
|
+
.then(r => true)
|
|
547
|
+
.catch<boolean>((e) => false);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export interface IListViewOptions { includeViewFields?: boolean; }
|
|
551
|
+
export function GetListViews(siteUrl: string, listIdOrTitle: string, options?: IListViewOptions): Promise<iListView[]> {
|
|
552
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
553
|
+
|
|
554
|
+
return GetJson<{
|
|
555
|
+
value: iListView[];
|
|
556
|
+
}>(GetListRestUrl(siteUrl, listIdOrTitle) + `/views?$select=Title,Id,ServerRelativeUrl,RowLimit,Paged,ViewQuery,ListViewXml,PersonalView,MobileView,MobileDefaultView,Hidden,DefaultView,ReadOnlyView${options && options.includeViewFields ? "&$expand=ViewFields" : ""}`,
|
|
557
|
+
null, { allowCache: true, jsonMetadata: jsonTypes.nometadata })
|
|
558
|
+
.then(r => {
|
|
559
|
+
let views = r.value;
|
|
560
|
+
if (isNotEmptyArray(views)) {
|
|
561
|
+
views.forEach(v => {
|
|
562
|
+
v.Id = normalizeGuid(v.Id);
|
|
563
|
+
if (options && options.includeViewFields) {
|
|
564
|
+
v.ViewFields = v.ViewFields && v.ViewFields["Items"] && v.ViewFields["Items"] || [];
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
return views;
|
|
569
|
+
})
|
|
570
|
+
.catch<iListView[]>(() => null);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export function GetListViewsSync(siteUrl: string, listIdOrTitle: string): iListView[] {
|
|
574
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
575
|
+
|
|
576
|
+
let result = GetJsonSync<{
|
|
577
|
+
d: {
|
|
578
|
+
results: iListView[];
|
|
579
|
+
};
|
|
580
|
+
}>(GetListRestUrl(siteUrl, listIdOrTitle) + `/views`,
|
|
581
|
+
null, { allowCache: true });
|
|
582
|
+
if (result.success) {
|
|
583
|
+
let views = result && result.result && result.result.d && result.result.d.results;
|
|
584
|
+
if (isNotEmptyArray(views)) {
|
|
585
|
+
views.forEach(v => { v.Id = normalizeGuid(v.Id); });
|
|
586
|
+
}
|
|
587
|
+
return views;
|
|
588
|
+
}
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
export async function AddViewFieldToListView(siteUrl: string, listIdOrTitle: string, viewId: string, viewField: string) {
|
|
593
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
594
|
+
|
|
595
|
+
if (isNullOrEmptyString(viewField) || !isValidGuid(viewId)) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
let views = await GetListViews(siteUrl, listIdOrTitle, { includeViewFields: true });
|
|
600
|
+
|
|
601
|
+
if (isNullOrEmptyArray(views)) {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
let view = views.filter((view) => {
|
|
606
|
+
return normalizeGuid(view.Id) === normalizeGuid(viewId);
|
|
607
|
+
})[0];
|
|
608
|
+
|
|
609
|
+
if (isNullOrUndefined(view)) {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
let hasField = view.ViewFields.includes(viewField);
|
|
614
|
+
|
|
615
|
+
if (hasField === true) {
|
|
616
|
+
return true;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
try {
|
|
620
|
+
let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${normalizeGuid(view.Id)}')/viewfields/addviewfield('${viewField}')`;
|
|
621
|
+
|
|
622
|
+
let result = await GetJson<{
|
|
623
|
+
d: {
|
|
624
|
+
AddViewField: null
|
|
625
|
+
}
|
|
626
|
+
}>(url, null, { method: "POST" });
|
|
627
|
+
|
|
628
|
+
console.log(result);
|
|
629
|
+
|
|
630
|
+
if (result && result.d.AddViewField === null) {
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
} catch { }
|
|
634
|
+
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export function GetListContentTypes(siteUrl: string, listIdOrTitle: string,
|
|
639
|
+
options?: {
|
|
640
|
+
ignoreFolders?: boolean;
|
|
641
|
+
ignoreHidden?: boolean;
|
|
642
|
+
includeFields?: boolean;
|
|
643
|
+
}): Promise<iContentType[]> {
|
|
644
|
+
return GetContentTypes(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle });
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export function GetListContentTypesSync(siteUrl: string, listIdOrTitle: string,
|
|
648
|
+
options?: {
|
|
649
|
+
ignoreFolders?: boolean;
|
|
650
|
+
ignoreHidden?: boolean;
|
|
651
|
+
includeFields?: boolean;
|
|
652
|
+
}): iContentType[] {
|
|
653
|
+
return GetContentTypesSync(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle });
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** generic version. for the KWIZ forms version that supports action id call GetListFormUrlAppsWeb instead */
|
|
657
|
+
export function GetListFormUrl(siteUrl: string, listId: string, pageType: PageType, params?: { contentTypeId?: string; itemId?: number | string; }) {
|
|
658
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
659
|
+
|
|
660
|
+
if (!isValidGuid(listId)) console.error('GetListFormUrl requires a list id');
|
|
661
|
+
let url = `${normalizeUrl(siteUrl)}/_layouts/15/listform.aspx?PageType=${pageType}&ListId=${encodeURIComponent(listId)}`;
|
|
662
|
+
if (params) {
|
|
663
|
+
if (!isNullOrEmptyString(params.contentTypeId))
|
|
664
|
+
url += `&ContentTypeId=${encodeURIComponent(params.contentTypeId)}`;
|
|
665
|
+
if (!isNullOrEmptyString(params.itemId))
|
|
666
|
+
url += `&ID=${encodeURIComponent(params.itemId as string)}`;
|
|
667
|
+
}
|
|
668
|
+
return url;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export function GetFieldSchemaSync(siteUrl: string, listIdOrTitle: string, fieldInternalName: string, refreshCache?: boolean): IFieldJsonSchema {
|
|
672
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
673
|
+
|
|
674
|
+
//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
|
|
675
|
+
//exists before requesting the schema.
|
|
676
|
+
let fields = GetListFieldsSync(siteUrl, listIdOrTitle, {
|
|
677
|
+
refreshCache: refreshCache,
|
|
678
|
+
fieldNames: [fieldInternalName]
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
if (isNullOrEmptyArray(fields)) {
|
|
682
|
+
return null;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
let field = fields[0];
|
|
686
|
+
return SchemaXmlToJson(field.SchemaXml);
|
|
687
|
+
// let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getByInternalNameOrTitle('${fieldInternalName}')?$select=SchemaXml`;
|
|
688
|
+
// let result = GetJsonSync<{ d: { SchemaXml: string; }; }>(
|
|
689
|
+
// url,
|
|
690
|
+
// null,
|
|
691
|
+
// {
|
|
692
|
+
// ...shortLocalCache,
|
|
693
|
+
// forceCacheUpdate: refreshCache === true
|
|
694
|
+
// });
|
|
695
|
+
|
|
696
|
+
// if (result && result.success) {
|
|
697
|
+
// return SchemaXmlToJson(result.result.d.SchemaXml);
|
|
698
|
+
// }
|
|
699
|
+
// return null;
|
|
700
|
+
//#endregion
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export async function GetFieldSchema(siteUrl: string, listIdOrTitle: string, fieldInternalName: string, refreshCache?: boolean) {
|
|
704
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
705
|
+
|
|
706
|
+
//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
|
|
707
|
+
//exists before requesting the schema
|
|
708
|
+
let fields = await GetListFields(siteUrl, listIdOrTitle, {
|
|
709
|
+
refreshCache: refreshCache,
|
|
710
|
+
fieldNames: [fieldInternalName]
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
if (isNullOrEmptyArray(fields)) {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
let field = fields[0];
|
|
718
|
+
return SchemaXmlToJson(field.SchemaXml);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
export async function GetListItems(siteUrl: string, listIdOrTitle: string, options: {
|
|
722
|
+
/** Optional, default: 1000. 0: get all items. */
|
|
723
|
+
rowLimit?: number;
|
|
724
|
+
/** Id, Title, Modified, FileLeafRef, FileDirRef, FileRef, FileSystemObjectType */
|
|
725
|
+
columns: (string | IFieldInfoEX)[];
|
|
726
|
+
foldersBehaviour?: GeListItemsFoldersBehaviour;
|
|
727
|
+
/** Optional, request to expand some columns. */
|
|
728
|
+
expand?: string[];
|
|
729
|
+
/** allow to change the jsonMetadata for this request, default: verbose */
|
|
730
|
+
jsonMetadata?: jsonTypes;
|
|
731
|
+
refreshCache?: boolean;
|
|
732
|
+
/** allow to send a filter statement */
|
|
733
|
+
$filter?: string;
|
|
734
|
+
}): Promise<IRestItem[]> {
|
|
735
|
+
let info = _GetListItemsInfo(siteUrl, listIdOrTitle, options);
|
|
736
|
+
|
|
737
|
+
let items: IRestItem[] = [];
|
|
738
|
+
|
|
739
|
+
do {
|
|
740
|
+
let resultItems: IRestItem[] = [];
|
|
741
|
+
let next: string = null;
|
|
742
|
+
if (info.noMetadata) {
|
|
743
|
+
let requestResult = (await GetJson<{
|
|
744
|
+
value: IRestItem[];
|
|
745
|
+
"odata.nextLink": string;
|
|
746
|
+
}>(info.requestUrl, null, {
|
|
747
|
+
allowCache: options.refreshCache !== true,
|
|
748
|
+
jsonMetadata: options.jsonMetadata
|
|
749
|
+
}));
|
|
750
|
+
resultItems = requestResult.value;
|
|
751
|
+
next = requestResult["odata.nextLink"];
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
let requestResult = (await GetJson<{
|
|
755
|
+
d: {
|
|
756
|
+
results: IRestItem[];
|
|
757
|
+
__next?: string;
|
|
758
|
+
};
|
|
759
|
+
}>(info.requestUrl, null, {
|
|
760
|
+
allowCache: options.refreshCache !== true
|
|
761
|
+
}));
|
|
762
|
+
resultItems = requestResult.d.results;
|
|
763
|
+
next = requestResult.d.__next;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (isNotEmptyArray(resultItems))
|
|
767
|
+
items.push(...resultItems);
|
|
768
|
+
|
|
769
|
+
if (info.totalNumberOfItemsToGet > items.length)
|
|
770
|
+
info.requestUrl = next;
|
|
771
|
+
else
|
|
772
|
+
info.requestUrl = null;
|
|
773
|
+
|
|
774
|
+
} while (!isNullOrEmptyString(info.requestUrl));
|
|
775
|
+
|
|
776
|
+
return __fixGetListItemsResults(siteUrl, listIdOrTitle, items, options.foldersBehaviour, info.expandedLookupFields);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export function GetListItemsSync(siteUrl: string, listIdOrTitle: string, options: {
|
|
780
|
+
/** Optional, default: 1000. 0: get all items. */
|
|
781
|
+
rowLimit?: number;
|
|
782
|
+
/** Id, Title, Modified, FileLeafRef, FileDirRef, FileRef, FileSystemObjectType */
|
|
783
|
+
columns: (string | IFieldInfoEX)[];
|
|
784
|
+
foldersBehaviour?: GeListItemsFoldersBehaviour;
|
|
785
|
+
/** Optional, request to expand some columns. */
|
|
786
|
+
expand?: string[];
|
|
787
|
+
/** allow to send a filter statement */
|
|
788
|
+
$filter?: string;
|
|
789
|
+
}): IRestItem[] {
|
|
790
|
+
let info = _GetListItemsInfo(siteUrl, listIdOrTitle, options);
|
|
791
|
+
|
|
792
|
+
let items: IRestItem[] = [];
|
|
793
|
+
|
|
794
|
+
do {
|
|
795
|
+
let resultItems: IRestItem[] = [];
|
|
796
|
+
let next: string = null;
|
|
797
|
+
if (info.noMetadata) {
|
|
798
|
+
let requestResult = GetJsonSync<{
|
|
799
|
+
value: IRestItem[];
|
|
800
|
+
"odata.nextLink": string;
|
|
801
|
+
}>(info.requestUrl, null, { allowCache: true });
|
|
802
|
+
if (requestResult.success) {
|
|
803
|
+
resultItems = requestResult.result.value;
|
|
804
|
+
next = requestResult.result["odata.nextLink"];
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
let requestResult = GetJsonSync<{
|
|
809
|
+
d: { results: IRestItem[]; __next?: string; };
|
|
810
|
+
}>(info.requestUrl, null, { allowCache: true });
|
|
811
|
+
if (requestResult.success) {
|
|
812
|
+
resultItems = requestResult.result.d.results;
|
|
813
|
+
next = requestResult.result.d.__next;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (isNotEmptyArray(resultItems))
|
|
818
|
+
items.push(...resultItems);
|
|
819
|
+
|
|
820
|
+
if (info.totalNumberOfItemsToGet > items.length)
|
|
821
|
+
info.requestUrl = next;
|
|
822
|
+
else
|
|
823
|
+
info.requestUrl = null;
|
|
824
|
+
|
|
825
|
+
} while (!isNullOrEmptyString(info.requestUrl));
|
|
826
|
+
|
|
827
|
+
return __fixGetListItemsResults(siteUrl, listIdOrTitle, items, options.foldersBehaviour, info.expandedLookupFields);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function _GetListItemsInfo(siteUrl: string, listIdOrTitle: string, options: {
|
|
831
|
+
/** Optional, default: 1000. 0: get all items. */
|
|
832
|
+
rowLimit?: number;
|
|
833
|
+
/** Id, Title, Modified, FileLeafRef, FileDirRef, FileRef, FileSystemObjectType */
|
|
834
|
+
columns: (string | IFieldInfoEX)[];
|
|
835
|
+
/** Optional, request to expand some columns. */
|
|
836
|
+
expand?: string[];
|
|
837
|
+
/** allow to change the jsonMetadata for this request, default: verbose */
|
|
838
|
+
jsonMetadata?: jsonTypes;
|
|
839
|
+
/** allow to send a filter statement */
|
|
840
|
+
$filter?: string;
|
|
841
|
+
}) {
|
|
842
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
843
|
+
|
|
844
|
+
let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items`;
|
|
845
|
+
let queryParams: string[] = [];
|
|
846
|
+
|
|
847
|
+
//Issue 8189 expand lookup fields
|
|
848
|
+
let columns: string[] = [];
|
|
849
|
+
let expand: string[] = [];
|
|
850
|
+
let expandedLookupFields: IFieldInfoEX[] = [];
|
|
851
|
+
options.columns.forEach(c => {
|
|
852
|
+
if (isString(c)) columns.push(c);
|
|
853
|
+
else {
|
|
854
|
+
let internalName = c.InternalName;
|
|
855
|
+
//Issue 828, 336
|
|
856
|
+
if (internalName.startsWith("_")) internalName = `OData_${internalName}`;
|
|
857
|
+
|
|
858
|
+
if (c.TypeAsString === "Lookup" || c.TypeAsString === "LookupMulti" || c.TypeAsString === "User" || c.TypeAsString === "UserMulti") {
|
|
859
|
+
//ISSUE: 1519 - Added lookupField property to able to retrieve value of the additional lookup field key
|
|
860
|
+
let lookupField = (c as IFieldLookupInfo).LookupField;
|
|
861
|
+
if (!isNullOrEmptyString(lookupField)) {
|
|
862
|
+
columns.push(`${internalName}/${lookupField}`);
|
|
863
|
+
}
|
|
864
|
+
//we want to expand it
|
|
865
|
+
columns.push(`${internalName}/Title`);
|
|
866
|
+
columns.push(`${internalName}/Id`);
|
|
867
|
+
expand.push(internalName);
|
|
868
|
+
expandedLookupFields.push(c);
|
|
869
|
+
}
|
|
870
|
+
else columns.push(internalName);
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
if (isNotEmptyArray(options.expand)) {
|
|
874
|
+
expand.push(...options.expand);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
//add the ones we need
|
|
878
|
+
PushNoDuplicate(columns, "Id");
|
|
879
|
+
PushNoDuplicate(columns, "FileRef");
|
|
880
|
+
PushNoDuplicate(columns, "FileSystemObjectType");
|
|
881
|
+
|
|
882
|
+
queryParams.push(`$select=${encodeURIComponent(makeUniqueArray(columns).join(','))}`);
|
|
883
|
+
|
|
884
|
+
if (isNotEmptyArray(expand))
|
|
885
|
+
queryParams.push(`$expand=${encodeURIComponent(makeUniqueArray(expand).join(','))}`);
|
|
886
|
+
|
|
887
|
+
let batchSize = 2000;
|
|
888
|
+
let limit = options.rowLimit >= 0 && options.rowLimit < batchSize ? options.rowLimit : batchSize;
|
|
889
|
+
let totalNumberOfItemsToGet = !isNumber(options.rowLimit) || options.rowLimit < 1 ? 99999 : options.rowLimit > batchSize ? options.rowLimit : limit;
|
|
890
|
+
|
|
891
|
+
if (!isNullOrEmptyString(options.$filter))
|
|
892
|
+
queryParams.push(`$filter=${options.$filter}`);
|
|
893
|
+
queryParams.push(`$top=${limit}`);
|
|
894
|
+
|
|
895
|
+
let requestUrl = url + (queryParams.length > 0 ? '?' + queryParams.join('&') : '');
|
|
896
|
+
let noMetadata = options.jsonMetadata === jsonTypes.nometadata;
|
|
897
|
+
|
|
898
|
+
return { requestUrl, noMetadata, totalNumberOfItemsToGet, expandedLookupFields };
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/** Find an item by id, even if it is nested in a sub-folder */
|
|
902
|
+
export function FindListItemById(items: IRestItem[], itemId: number): IRestItem {
|
|
903
|
+
for (let i = 0; i < items.length; i++) {
|
|
904
|
+
let current = items[i];
|
|
905
|
+
if (current.Id === itemId) return current;
|
|
906
|
+
else if (isNotEmptyArray(current.__Items))//folder? look inside
|
|
907
|
+
{
|
|
908
|
+
let nestedResult = FindListItemById(current.__Items, itemId);
|
|
909
|
+
if (!isNullOrUndefined(nestedResult)) return nestedResult;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
//not found
|
|
913
|
+
return null;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
function _getListEventReceiversRequestUrl(siteUrl: string, listIdOrTitle: string) {
|
|
917
|
+
return GetListRestUrl(siteUrl, listIdOrTitle) + `/EventReceivers`
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
export async function GetListEventReceivers(siteUrl: string, listIdOrTitle: string, refreshCache?: boolean): Promise<ISPEventReceiver[]> {
|
|
921
|
+
try {
|
|
922
|
+
let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
|
|
923
|
+
let response = await GetJson<{
|
|
924
|
+
value: ISPEventReceiver[];
|
|
925
|
+
}>(url,
|
|
926
|
+
null, {
|
|
927
|
+
allowCache: refreshCache !== true,
|
|
928
|
+
jsonMetadata: jsonTypes.nometadata
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
return !isNullOrUndefined(response) ? response.value : null;
|
|
932
|
+
} catch {
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
export async function AddListEventReceiver(siteUrl: string, listIdOrTitle: string, eventReceiverDefinition: Pick<ISPEventReceiver, "EventType" | "ReceiverName" | "ReceiverUrl" | "SequenceNumber">): Promise<ISPEventReceiver> {
|
|
939
|
+
let newEventReceiver: Omit<ISPEventReceiver, "ReceiverId" | "Synchronization"> = {
|
|
940
|
+
ReceiverAssembly: "",
|
|
941
|
+
ReceiverClass: "",
|
|
942
|
+
...eventReceiverDefinition
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
try {
|
|
946
|
+
let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
|
|
947
|
+
let response = await GetJson<ISPEventReceiver>(url, JSON.stringify(newEventReceiver), {
|
|
948
|
+
method: "POST",
|
|
949
|
+
includeDigestInPost: true,
|
|
950
|
+
jsonMetadata: jsonTypes.nometadata,
|
|
951
|
+
headers: {
|
|
952
|
+
"content-type": contentTypes.json
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
return !isNullOrUndefined(response) && isValidGuid(response.ReceiverId) ? response : null;
|
|
957
|
+
} catch {
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
return null;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
export async function DeleteListEventReceiver(siteUrl: string, listIdOrTitle: string, eventReceiverId: string): Promise<boolean> {
|
|
964
|
+
try {
|
|
965
|
+
let url = `${_getListEventReceiversRequestUrl(siteUrl, listIdOrTitle)}('${normalizeGuid(eventReceiverId)}')/deleteObject`;
|
|
966
|
+
let response = await GetJson<{ "odata.null": boolean }>(url, null, {
|
|
967
|
+
method: "POST",
|
|
968
|
+
includeDigestInPost: true,
|
|
969
|
+
jsonMetadata: jsonTypes.nometadata
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
return !isNullOrUndefined(response) && response["odata.null"] === true;
|
|
973
|
+
} catch {
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
return false;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/** timestamp of changes:
|
|
980
|
+
* - item updates
|
|
981
|
+
* - changes to columns
|
|
982
|
+
* - content types
|
|
983
|
+
* - list versioning settings
|
|
984
|
+
* - list title/description
|
|
985
|
+
* - content approval settings
|
|
986
|
+
* does not track:
|
|
987
|
+
* - Changes to views
|
|
988
|
+
* - changing list/items permissions
|
|
989
|
+
*/
|
|
990
|
+
export function GetListLastItemModifiedDate(siteUrl: string, listIdOrTitle: string, options: {
|
|
991
|
+
sync: true;
|
|
992
|
+
refreshCache?: boolean;
|
|
993
|
+
/** ignore system changes */
|
|
994
|
+
userChangesOnly?: boolean;
|
|
995
|
+
}): string;
|
|
996
|
+
/** timestamp of changes:
|
|
997
|
+
* - item updates
|
|
998
|
+
* - changes to columns
|
|
999
|
+
* - content types
|
|
1000
|
+
* - list versioning settings
|
|
1001
|
+
* - list title/description
|
|
1002
|
+
* - content approval settings
|
|
1003
|
+
* does not track:
|
|
1004
|
+
* - Changes to views
|
|
1005
|
+
* - changing list/items permissions
|
|
1006
|
+
*/
|
|
1007
|
+
export function GetListLastItemModifiedDate(siteUrl: string, listIdOrTitle: string, options?: {
|
|
1008
|
+
sync?: false;
|
|
1009
|
+
refreshCache?: boolean;
|
|
1010
|
+
/** ignore system changes */
|
|
1011
|
+
userChangesOnly?: boolean;
|
|
1012
|
+
}): Promise<string>;
|
|
1013
|
+
|
|
1014
|
+
export function GetListLastItemModifiedDate(siteUrl: string, listIdOrTitle: string, options?: {
|
|
1015
|
+
sync?: boolean;
|
|
1016
|
+
refreshCache?: boolean;
|
|
1017
|
+
/** ignore system changes */
|
|
1018
|
+
userChangesOnly?: boolean;
|
|
1019
|
+
}): string | Promise<string> {
|
|
1020
|
+
siteUrl = GetSiteUrl(siteUrl);
|
|
1021
|
+
|
|
1022
|
+
let endPoint = options && options.userChangesOnly ? 'LastItemUserModifiedDate' : 'LastItemModifiedDate';
|
|
1023
|
+
|
|
1024
|
+
let sync = options && options.sync ? true : false;
|
|
1025
|
+
let caller = sync ? GetJsonSync : GetJson;
|
|
1026
|
+
|
|
1027
|
+
let result = caller<{ value: string; }>(GetListRestUrl(siteUrl, listIdOrTitle) + `/${endPoint}`, null, {
|
|
1028
|
+
allowCache: true,//in memory only
|
|
1029
|
+
jsonMetadata: jsonTypes.nometadata,
|
|
1030
|
+
forceCacheUpdate: options && options.refreshCache === true || false
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
if (isPromise(result))
|
|
1034
|
+
return result.then(r => r.value, () => null);
|
|
1035
|
+
else
|
|
1036
|
+
return result.success ? result.result.value : null;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
export async function ReloadListLastModified(siteUrl: string, listIdOrTitle: string) {
|
|
1040
|
+
await GetListLastItemModifiedDate(siteUrl, listIdOrTitle, { refreshCache: true });
|
|
1041
|
+
//make sure we do it for both title and id, we don't know how the other callers may use this in their API
|
|
1042
|
+
|
|
1043
|
+
if (!isValidGuid(listIdOrTitle)) {
|
|
1044
|
+
try {
|
|
1045
|
+
var listId = GetListId(siteUrl, listIdOrTitle);
|
|
1046
|
+
await GetListLastItemModifiedDate(siteUrl, listId, { refreshCache: true });
|
|
1047
|
+
} catch (e) { }
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
try {
|
|
1051
|
+
var listTitle = await GetListTitle(siteUrl, listIdOrTitle);
|
|
1052
|
+
await GetListLastItemModifiedDate(siteUrl, listTitle, { refreshCache: true });
|
|
1053
|
+
} catch (e) { }
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
export async function ListHasUniquePermissions(siteUrl: string, listIdOrTitle: string): Promise<boolean> {
|
|
1058
|
+
let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/?$select=hasuniqueroleassignments`;
|
|
1059
|
+
let has = await GetJson<{ HasUniqueRoleAssignments: boolean }>(url, undefined, { allowCache: false, jsonMetadata: jsonTypes.nometadata });
|
|
1060
|
+
return has.HasUniqueRoleAssignments === true;
|
|
1061
|
+
}
|
|
1062
|
+
export async function BreakListbPermissionInheritance(siteUrl: string, listIdOrTitle: string, clear = true): Promise<void> {
|
|
1063
|
+
let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/breakroleinheritance(copyRoleAssignments=${clear ? 'false' : 'true'}, clearSubscopes=true)`;
|
|
1064
|
+
await GetJson(url, undefined, { method: "POST", allowCache: false, jsonMetadata: jsonTypes.nometadata });
|
|
1065
|
+
}
|
|
1066
|
+
export async function AssignListPermission(siteUrl: string, listIdOrTitle: string, principalId: number, roleId: number) {
|
|
1067
|
+
let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/addroleassignment(principalid=${principalId},roleDefId=${roleId})`;
|
|
1068
|
+
await GetJson(url, undefined, { method: "POST", allowCache: false, jsonMetadata: jsonTypes.nometadata });
|
|
1069
|
+
}
|
|
1070
|
+
export async function RemoveListPermission(siteUrl: string, listIdOrTitle: string, principalId: number, roleId: number) {
|
|
1071
|
+
let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/removeroleassignment(principalid=${principalId},roleDefId=${roleId})`;
|
|
1072
|
+
await GetJson(url, undefined, { method: "POST", allowCache: false, jsonMetadata: jsonTypes.nometadata });
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
interface iCreateListResult {
|
|
1076
|
+
AllowContentTypes: boolean,
|
|
1077
|
+
BaseTemplate: ListTemplateTypes,
|
|
1078
|
+
BaseType: BaseTypes,
|
|
1079
|
+
ContentTypesEnabled: boolean,
|
|
1080
|
+
Created: string,
|
|
1081
|
+
DefaultItemOpenUseListSetting: boolean,
|
|
1082
|
+
Description: string,
|
|
1083
|
+
DisableCommenting: boolean,
|
|
1084
|
+
DisableGridEditing: boolean,
|
|
1085
|
+
DocumentTemplateUrl: string,//"/sites/s/cms/CMSLayouts/Forms/template.dotx",
|
|
1086
|
+
DraftVersionVisibility: 0,
|
|
1087
|
+
EnableAttachments: boolean,
|
|
1088
|
+
EnableFolderCreation: boolean,
|
|
1089
|
+
EnableMinorVersions: boolean,
|
|
1090
|
+
EnableModeration: false,
|
|
1091
|
+
EnableRequestSignOff: boolean,
|
|
1092
|
+
EnableVersioning: boolean,
|
|
1093
|
+
EntityTypeName: string,//"CMSLayouts",
|
|
1094
|
+
ExemptFromBlockDownloadOfNonViewableFiles: boolean,
|
|
1095
|
+
FileSavePostProcessingEnabled: boolean,
|
|
1096
|
+
ForceCheckout: boolean,
|
|
1097
|
+
HasExternalDataSource: boolean,
|
|
1098
|
+
Hidden: boolean,
|
|
1099
|
+
Id: string,//"c21d4eb4-70cc-4c95-925a-aa34bb9e01e0",
|
|
1100
|
+
ImagePath: {
|
|
1101
|
+
DecodedUrl: string,//"/_layouts/15/images/itdl.png?rev=47"
|
|
1102
|
+
},
|
|
1103
|
+
ImageUrl: string,//"/_layouts/15/images/itdl.png?rev=47",
|
|
1104
|
+
IsApplicationList: boolean,
|
|
1105
|
+
IsCatalog: boolean,
|
|
1106
|
+
IsPrivate: boolean,
|
|
1107
|
+
ItemCount: 0,
|
|
1108
|
+
LastItemDeletedDate: string,//"2024-02-05T18:26:05Z",
|
|
1109
|
+
LastItemModifiedDate: string,//"2024-02-05T18:26:06Z",
|
|
1110
|
+
LastItemUserModifiedDate: string,//"2024-02-05T18:26:05Z",
|
|
1111
|
+
ListExperienceOptions: ListExperienceOptions,
|
|
1112
|
+
ListItemEntityTypeFullName: string,//"SP.Data.CMSLayoutsItem",
|
|
1113
|
+
MajorVersionLimit: number,//500,
|
|
1114
|
+
MajorWithMinorVersionsLimit: number,//0,
|
|
1115
|
+
MultipleDataList: boolean,
|
|
1116
|
+
NoCrawl: boolean,
|
|
1117
|
+
ParentWebPath: {
|
|
1118
|
+
DecodedUrl: string,//"/sites/s/cms"
|
|
1119
|
+
},
|
|
1120
|
+
ParentWebUrl: string,//"/sites/s/cms",
|
|
1121
|
+
ParserDisabled: boolean,
|
|
1122
|
+
ServerTemplateCanCreateFolders: boolean,
|
|
1123
|
+
TemplateFeatureId: string,//"00bfea71-e717-4e80-aa17-d0c71b360101",
|
|
1124
|
+
Title: string,//"CMSLayouts"
|
|
1125
|
+
}
|
|
1126
|
+
export async function CreateList(siteUrl: string, info: {
|
|
1127
|
+
title: string; description: string;
|
|
1128
|
+
type: BaseTypes; template: ListTemplateTypes;
|
|
1129
|
+
}): Promise<iCreateListResult> {
|
|
1130
|
+
let url = `${GetRestBaseUrl(siteUrl)}/web/lists`;
|
|
1131
|
+
const body = {
|
|
1132
|
+
__metadata: { type: 'SP.List' },
|
|
1133
|
+
AllowContentTypes: false,
|
|
1134
|
+
ContentTypesEnabled: false,
|
|
1135
|
+
BaseTemplate: info.template,
|
|
1136
|
+
BaseType: info.type,
|
|
1137
|
+
Description: info.description,
|
|
1138
|
+
Title: info.title
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
let newList = (await GetJson<{ d: iCreateListResult }>(url, jsonStringify(body))).d;
|
|
1142
|
+
normalizeGuid(newList.Id);
|
|
1143
|
+
return newList;
|
|
1144
|
+
}
|