@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.
Files changed (310) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_dependencies.d.ts +1 -0
  3. package/dist/_dependencies.js +8 -0
  4. package/dist/_dependencies.js.map +1 -0
  5. package/dist/helpers/Guid.d.ts +119 -0
  6. package/dist/helpers/Guid.js +183 -0
  7. package/dist/helpers/Guid.js.map +1 -0
  8. package/dist/helpers/_dependencies.d.ts +2 -0
  9. package/dist/helpers/_dependencies.js +21 -0
  10. package/dist/helpers/_dependencies.js.map +1 -0
  11. package/dist/helpers/base64.d.ts +8 -0
  12. package/dist/helpers/base64.js +178 -0
  13. package/dist/helpers/base64.js.map +1 -0
  14. package/dist/helpers/browser.d.ts +144 -0
  15. package/dist/helpers/browser.js +1200 -0
  16. package/dist/helpers/browser.js.map +1 -0
  17. package/dist/helpers/browserinfo.d.ts +23 -0
  18. package/dist/helpers/browserinfo.js +215 -0
  19. package/dist/helpers/browserinfo.js.map +1 -0
  20. package/dist/helpers/collections.base.d.ts +128 -0
  21. package/dist/helpers/collections.base.js +430 -0
  22. package/dist/helpers/collections.base.js.map +1 -0
  23. package/dist/helpers/collections.d.ts +18 -0
  24. package/dist/helpers/collections.js +99 -0
  25. package/dist/helpers/collections.js.map +1 -0
  26. package/dist/helpers/color.d.ts +11 -0
  27. package/dist/helpers/color.js +57 -0
  28. package/dist/helpers/color.js.map +1 -0
  29. package/dist/helpers/cookies.d.ts +6 -0
  30. package/dist/helpers/cookies.js +56 -0
  31. package/dist/helpers/cookies.js.map +1 -0
  32. package/dist/helpers/date.d.ts +43 -0
  33. package/dist/helpers/date.js +158 -0
  34. package/dist/helpers/date.js.map +1 -0
  35. package/dist/helpers/debug.d.ts +33 -0
  36. package/dist/helpers/debug.js +177 -0
  37. package/dist/helpers/debug.js.map +1 -0
  38. package/dist/helpers/emails.d.ts +2 -0
  39. package/dist/helpers/emails.js +10 -0
  40. package/dist/helpers/emails.js.map +1 -0
  41. package/dist/helpers/eval.d.ts +1 -0
  42. package/dist/helpers/eval.js +10 -0
  43. package/dist/helpers/eval.js.map +1 -0
  44. package/dist/helpers/file.d.ts +11 -0
  45. package/dist/helpers/file.js +55 -0
  46. package/dist/helpers/file.js.map +1 -0
  47. package/dist/helpers/flatted.d.ts +20 -0
  48. package/dist/helpers/flatted.js +135 -0
  49. package/dist/helpers/flatted.js.map +1 -0
  50. package/dist/helpers/functions.d.ts +4 -0
  51. package/dist/helpers/functions.js +17 -0
  52. package/dist/helpers/functions.js.map +1 -0
  53. package/dist/helpers/graph/calendar.types.d.ts +3 -0
  54. package/dist/helpers/graph/calendar.types.js +15 -0
  55. package/dist/helpers/graph/calendar.types.js.map +1 -0
  56. package/dist/helpers/http.d.ts +25 -0
  57. package/dist/helpers/http.js +70 -0
  58. package/dist/helpers/http.js.map +1 -0
  59. package/dist/helpers/images.d.ts +16 -0
  60. package/dist/helpers/images.js +21 -0
  61. package/dist/helpers/images.js.map +1 -0
  62. package/dist/helpers/index.d.ts +29 -0
  63. package/dist/helpers/index.js +46 -0
  64. package/dist/helpers/index.js.map +1 -0
  65. package/dist/helpers/json.d.ts +3 -0
  66. package/dist/helpers/json.js +44 -0
  67. package/dist/helpers/json.js.map +1 -0
  68. package/dist/helpers/md5.d.ts +5 -0
  69. package/dist/helpers/md5.js +172 -0
  70. package/dist/helpers/md5.js.map +1 -0
  71. package/dist/helpers/objects.d.ts +49 -0
  72. package/dist/helpers/objects.js +271 -0
  73. package/dist/helpers/objects.js.map +1 -0
  74. package/dist/helpers/promises.d.ts +14 -0
  75. package/dist/helpers/promises.js +112 -0
  76. package/dist/helpers/promises.js.map +1 -0
  77. package/dist/helpers/random.d.ts +2 -0
  78. package/dist/helpers/random.js +32 -0
  79. package/dist/helpers/random.js.map +1 -0
  80. package/dist/helpers/scheduler/scheduler.d.ts +39 -0
  81. package/dist/helpers/scheduler/scheduler.js +109 -0
  82. package/dist/helpers/scheduler/scheduler.js.map +1 -0
  83. package/dist/helpers/sharepoint.d.ts +112 -0
  84. package/dist/helpers/sharepoint.js +629 -0
  85. package/dist/helpers/sharepoint.js.map +1 -0
  86. package/dist/helpers/strings.d.ts +56 -0
  87. package/dist/helpers/strings.js +282 -0
  88. package/dist/helpers/strings.js.map +1 -0
  89. package/dist/helpers/typecheckers.d.ts +56 -0
  90. package/dist/helpers/typecheckers.js +274 -0
  91. package/dist/helpers/typecheckers.js.map +1 -0
  92. package/dist/helpers/url.d.ts +46 -0
  93. package/dist/helpers/url.js +199 -0
  94. package/dist/helpers/url.js.map +1 -0
  95. package/dist/helpers/urlhelper.d.ts +16 -0
  96. package/dist/helpers/urlhelper.js +96 -0
  97. package/dist/helpers/urlhelper.js.map +1 -0
  98. package/dist/index.d.ts +15 -0
  99. package/dist/index.js +37 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/types/common.types.d.ts +19 -0
  102. package/dist/types/common.types.js +4 -0
  103. package/dist/types/common.types.js.map +1 -0
  104. package/dist/types/flatted.types.d.ts +49 -0
  105. package/dist/types/flatted.types.js +3 -0
  106. package/dist/types/flatted.types.js.map +1 -0
  107. package/dist/types/globals.types.d.ts +6 -0
  108. package/dist/types/globals.types.js +3 -0
  109. package/dist/types/globals.types.js.map +1 -0
  110. package/dist/types/graph/calendar.types.d.ts +79 -0
  111. package/dist/types/graph/calendar.types.js +3 -0
  112. package/dist/types/graph/calendar.types.js.map +1 -0
  113. package/dist/types/graph/index.d.ts +1 -0
  114. package/dist/types/graph/index.js +18 -0
  115. package/dist/types/graph/index.js.map +1 -0
  116. package/dist/types/index.d.ts +11 -0
  117. package/dist/types/index.js +28 -0
  118. package/dist/types/index.js.map +1 -0
  119. package/dist/types/knownscript.types.d.ts +22 -0
  120. package/dist/types/knownscript.types.js +3 -0
  121. package/dist/types/knownscript.types.js.map +1 -0
  122. package/dist/types/libs/datajs.types.d.ts +29 -0
  123. package/dist/types/libs/datajs.types.js +3 -0
  124. package/dist/types/libs/datajs.types.js.map +1 -0
  125. package/dist/types/libs/ics.types.d.ts +29 -0
  126. package/dist/types/libs/ics.types.js +3 -0
  127. package/dist/types/libs/ics.types.js.map +1 -0
  128. package/dist/types/libs/index.d.ts +3 -0
  129. package/dist/types/libs/index.js +20 -0
  130. package/dist/types/libs/index.js.map +1 -0
  131. package/dist/types/libs/msal.types.d.ts +33 -0
  132. package/dist/types/libs/msal.types.js +63 -0
  133. package/dist/types/libs/msal.types.js.map +1 -0
  134. package/dist/types/locales.d.ts +122 -0
  135. package/dist/types/locales.js +1 -0
  136. package/dist/types/locales.js.map +1 -0
  137. package/dist/types/localstoragecache.types.d.ts +8 -0
  138. package/dist/types/localstoragecache.types.js +3 -0
  139. package/dist/types/localstoragecache.types.js.map +1 -0
  140. package/dist/types/moment.d.ts +6 -0
  141. package/dist/types/moment.js +1 -0
  142. package/dist/types/moment.js.map +1 -0
  143. package/dist/types/regex.types.d.ts +14 -0
  144. package/dist/types/regex.types.js +3 -0
  145. package/dist/types/regex.types.js.map +1 -0
  146. package/dist/types/rest.types.d.ts +81 -0
  147. package/dist/types/rest.types.js +24 -0
  148. package/dist/types/rest.types.js.map +1 -0
  149. package/dist/types/sharepoint.types.d.ts +1432 -0
  150. package/dist/types/sharepoint.types.js +629 -0
  151. package/dist/types/sharepoint.types.js.map +1 -0
  152. package/dist/types/sharepoint.utils.types.d.ts +246 -0
  153. package/dist/types/sharepoint.utils.types.js +26 -0
  154. package/dist/types/sharepoint.utils.types.js.map +1 -0
  155. package/dist/utils/_dependencies.d.ts +3 -0
  156. package/dist/utils/_dependencies.js +24 -0
  157. package/dist/utils/_dependencies.js.map +1 -0
  158. package/dist/utils/base64.d.ts +2 -0
  159. package/dist/utils/base64.js +41 -0
  160. package/dist/utils/base64.js.map +1 -0
  161. package/dist/utils/consolelogger.d.ts +73 -0
  162. package/dist/utils/consolelogger.js +281 -0
  163. package/dist/utils/consolelogger.js.map +1 -0
  164. package/dist/utils/date.d.ts +10 -0
  165. package/dist/utils/date.js +30 -0
  166. package/dist/utils/date.js.map +1 -0
  167. package/dist/utils/emails.d.ts +2 -0
  168. package/dist/utils/emails.js +24 -0
  169. package/dist/utils/emails.js.map +1 -0
  170. package/dist/utils/index.d.ts +13 -0
  171. package/dist/utils/index.js +31 -0
  172. package/dist/utils/index.js.map +1 -0
  173. package/dist/utils/knownscript.d.ts +99 -0
  174. package/dist/utils/knownscript.js +261 -0
  175. package/dist/utils/knownscript.js.map +1 -0
  176. package/dist/utils/localstoragecache.d.ts +19 -0
  177. package/dist/utils/localstoragecache.js +372 -0
  178. package/dist/utils/localstoragecache.js.map +1 -0
  179. package/dist/utils/rest.d.ts +17 -0
  180. package/dist/utils/rest.js +402 -0
  181. package/dist/utils/rest.js.map +1 -0
  182. package/dist/utils/script.d.ts +33 -0
  183. package/dist/utils/script.js +169 -0
  184. package/dist/utils/script.js.map +1 -0
  185. package/dist/utils/sharepoint.rest/common.d.ts +32 -0
  186. package/dist/utils/sharepoint.rest/common.js +146 -0
  187. package/dist/utils/sharepoint.rest/common.js.map +1 -0
  188. package/dist/utils/sharepoint.rest/date.d.ts +2 -0
  189. package/dist/utils/sharepoint.rest/date.js +57 -0
  190. package/dist/utils/sharepoint.rest/date.js.map +1 -0
  191. package/dist/utils/sharepoint.rest/file.folder.d.ts +58 -0
  192. package/dist/utils/sharepoint.rest/file.folder.js +305 -0
  193. package/dist/utils/sharepoint.rest/file.folder.js.map +1 -0
  194. package/dist/utils/sharepoint.rest/index.d.ts +11 -0
  195. package/dist/utils/sharepoint.rest/index.js +28 -0
  196. package/dist/utils/sharepoint.rest/index.js.map +1 -0
  197. package/dist/utils/sharepoint.rest/item.d.ts +81 -0
  198. package/dist/utils/sharepoint.rest/item.js +444 -0
  199. package/dist/utils/sharepoint.rest/item.js.map +1 -0
  200. package/dist/utils/sharepoint.rest/list.d.ts +228 -0
  201. package/dist/utils/sharepoint.rest/list.js +868 -0
  202. package/dist/utils/sharepoint.rest/list.js.map +1 -0
  203. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.d.ts +19 -0
  204. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +629 -0
  205. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -0
  206. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.d.ts +14 -0
  207. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +222 -0
  208. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -0
  209. package/dist/utils/sharepoint.rest/listutils/common.d.ts +3 -0
  210. package/dist/utils/sharepoint.rest/listutils/common.js +198 -0
  211. package/dist/utils/sharepoint.rest/listutils/common.js.map +1 -0
  212. package/dist/utils/sharepoint.rest/user-search.d.ts +76 -0
  213. package/dist/utils/sharepoint.rest/user-search.js +239 -0
  214. package/dist/utils/sharepoint.rest/user-search.js.map +1 -0
  215. package/dist/utils/sharepoint.rest/user.d.ts +71 -0
  216. package/dist/utils/sharepoint.rest/user.js +404 -0
  217. package/dist/utils/sharepoint.rest/user.js.map +1 -0
  218. package/dist/utils/sharepoint.rest/web.d.ts +107 -0
  219. package/dist/utils/sharepoint.rest/web.js +929 -0
  220. package/dist/utils/sharepoint.rest/web.js.map +1 -0
  221. package/dist/utils/sod.d.ts +29 -0
  222. package/dist/utils/sod.js +177 -0
  223. package/dist/utils/sod.js.map +1 -0
  224. package/package.json +60 -0
  225. package/readme.md +13 -0
  226. package/src/_dependencies.ts +2 -0
  227. package/src/helpers/Guid.ts +182 -0
  228. package/src/helpers/_dependencies.ts +3 -0
  229. package/src/helpers/base64.ts +174 -0
  230. package/src/helpers/browser.test.js +9 -0
  231. package/src/helpers/browser.ts +1299 -0
  232. package/src/helpers/browserinfo.ts +293 -0
  233. package/src/helpers/collections.base.test.js +26 -0
  234. package/src/helpers/collections.base.ts +439 -0
  235. package/src/helpers/collections.ts +108 -0
  236. package/src/helpers/color.ts +55 -0
  237. package/src/helpers/cookies.ts +55 -0
  238. package/src/helpers/date.test.js +97 -0
  239. package/src/helpers/date.ts +163 -0
  240. package/src/helpers/debug.ts +187 -0
  241. package/src/helpers/emails.ts +7 -0
  242. package/src/helpers/eval.ts +5 -0
  243. package/src/helpers/file.test.js +51 -0
  244. package/src/helpers/file.ts +59 -0
  245. package/src/helpers/flatted.ts +150 -0
  246. package/src/helpers/functions.ts +17 -0
  247. package/src/helpers/graph/calendar.types.ts +11 -0
  248. package/src/helpers/http.ts +70 -0
  249. package/src/helpers/images.ts +23 -0
  250. package/src/helpers/index.ts +29 -0
  251. package/src/helpers/json.ts +39 -0
  252. package/src/helpers/md5.ts +190 -0
  253. package/src/helpers/objects.test.js +27 -0
  254. package/src/helpers/objects.ts +256 -0
  255. package/src/helpers/promises.test.js +18 -0
  256. package/src/helpers/promises.ts +102 -0
  257. package/src/helpers/random.ts +27 -0
  258. package/src/helpers/scheduler/scheduler.test.js +104 -0
  259. package/src/helpers/scheduler/scheduler.ts +132 -0
  260. package/src/helpers/sharepoint.ts +681 -0
  261. package/src/helpers/strings.test.js +43 -0
  262. package/src/helpers/strings.ts +288 -0
  263. package/src/helpers/typecheckers.test.js +35 -0
  264. package/src/helpers/typecheckers.ts +263 -0
  265. package/src/helpers/url.test.js +18 -0
  266. package/src/helpers/url.ts +202 -0
  267. package/src/helpers/urlhelper.ts +104 -0
  268. package/src/index.ts +24 -0
  269. package/src/types/common.types.ts +16 -0
  270. package/src/types/flatted.types.ts +60 -0
  271. package/src/types/globals.types.ts +7 -0
  272. package/src/types/graph/calendar.types.ts +81 -0
  273. package/src/types/graph/index.ts +1 -0
  274. package/src/types/index.ts +12 -0
  275. package/src/types/knownscript.types.ts +19 -0
  276. package/src/types/libs/datajs.types.ts +29 -0
  277. package/src/types/libs/ics.types.ts +31 -0
  278. package/src/types/libs/index.ts +4 -0
  279. package/src/types/libs/msal.types.ts +79 -0
  280. package/src/types/locales.ts +125 -0
  281. package/src/types/localstoragecache.types.ts +9 -0
  282. package/src/types/moment.ts +7 -0
  283. package/src/types/regex.types.ts +17 -0
  284. package/src/types/rest.types.ts +94 -0
  285. package/src/types/sharepoint.types.ts +1413 -0
  286. package/src/types/sharepoint.utils.types.ts +246 -0
  287. package/src/utils/_dependencies.ts +4 -0
  288. package/src/utils/base64.ts +27 -0
  289. package/src/utils/consolelogger.ts +315 -0
  290. package/src/utils/date.ts +36 -0
  291. package/src/utils/emails.ts +25 -0
  292. package/src/utils/index.ts +13 -0
  293. package/src/utils/knownscript.ts +280 -0
  294. package/src/utils/localstoragecache.ts +419 -0
  295. package/src/utils/rest.ts +465 -0
  296. package/src/utils/script.ts +168 -0
  297. package/src/utils/sharepoint.rest/common.ts +149 -0
  298. package/src/utils/sharepoint.rest/date.ts +61 -0
  299. package/src/utils/sharepoint.rest/file.folder.ts +368 -0
  300. package/src/utils/sharepoint.rest/index.ts +11 -0
  301. package/src/utils/sharepoint.rest/item.ts +456 -0
  302. package/src/utils/sharepoint.rest/list.ts +1144 -0
  303. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +750 -0
  304. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +265 -0
  305. package/src/utils/sharepoint.rest/listutils/common.ts +202 -0
  306. package/src/utils/sharepoint.rest/user-search.ts +254 -0
  307. package/src/utils/sharepoint.rest/user.ts +447 -0
  308. package/src/utils/sharepoint.rest/web.ts +1031 -0
  309. package/src/utils/sod.ts +193 -0
  310. package/tsconfig.json +21 -0
@@ -0,0 +1,868 @@
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
+ 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;
13
+ const _dependencies_1 = require("../_dependencies");
14
+ const rest_1 = require("../rest");
15
+ const common_1 = require("./common");
16
+ const common_2 = require("./listutils/common");
17
+ const web_1 = require("./web");
18
+ /** returns /_api/web/lists/getById() or /_api/web/lists/getByTitle() */
19
+ function GetListRestUrl(siteUrl, listIdOrTitle) {
20
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
21
+ let listId = GetListId(siteUrl, listIdOrTitle);
22
+ let listPart = (0, _dependencies_1.isValidGuid)(listId) ? `getById('${(0, _dependencies_1.normalizeGuid)(listId)}')` : `getByTitle('${encodeURIComponent(listIdOrTitle)}')`;
23
+ return (0, common_1.GetRestBaseUrl)(siteUrl) + `/web/lists/${listPart}`;
24
+ }
25
+ exports.GetListRestUrl = GetListRestUrl;
26
+ function GetListId(siteUrl, listIdOrTitle) {
27
+ if ((0, _dependencies_1.isNullOrEmptyString)(listIdOrTitle))
28
+ return null;
29
+ if ((0, _dependencies_1.isValidGuid)(listIdOrTitle))
30
+ return listIdOrTitle;
31
+ //Issue 7508
32
+ //When translation is enabled, and user changes list title but he is not on the same language as the site
33
+ //he translates the list, but not changing its title
34
+ //so REST api /lists/getByTitle will not work
35
+ //instead, we need to get the list id from the web's lists collection.
36
+ let lists = (0, web_1.GetListsSync)(siteUrl);
37
+ var lower = listIdOrTitle.toLowerCase();
38
+ var list = (0, _dependencies_1.firstOrNull)(lists, l => l.Title.toLowerCase() === lower);
39
+ return list && list.Id || null;
40
+ }
41
+ exports.GetListId = GetListId;
42
+ /** get the list ID from a list page, such as a list view or an item form */
43
+ function GetListIdFromPageSync(siteUrl, listPageUrl) {
44
+ let url = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/getlist('${(0, _dependencies_1.makeServerRelativeUrl)(listPageUrl.split('?')[0].split('#')[0])}')?$select=id`;
45
+ let response = (0, rest_1.GetJsonSync)(url, null, Object.assign(Object.assign({}, rest_1.longLocalCache), { jsonMetadata: _dependencies_1.jsonTypes.nometadata }));
46
+ if (!(0, _dependencies_1.isNullOrUndefined)(response) && response.success) {
47
+ let listId = response.result.Id;
48
+ return (0, _dependencies_1.normalizeGuid)(listId);
49
+ }
50
+ return null;
51
+ }
52
+ exports.GetListIdFromPageSync = GetListIdFromPageSync;
53
+ /** ensures the site assets library exists and return its info. on errors - it will return null. */
54
+ function EnsureAssetLibrary(siteUrl) {
55
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
56
+ var url = (0, common_1.GetRestBaseUrl)(siteUrl) +
57
+ "/web/lists/EnsureSiteAssetsLibrary?$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists&$expand=RootFolder";
58
+ return (0, rest_1.GetJson)(url, null, Object.assign({ method: "POST", spWebUrl: siteUrl }, rest_1.longLocalCache)).then(result => {
59
+ if (result && result.d) {
60
+ return {
61
+ Id: result.d.Id,
62
+ Name: result.d.RootFolder.Name,
63
+ ServerRelativeUrl: result.d.RootFolder.ServerRelativeUrl
64
+ };
65
+ }
66
+ else
67
+ return null;
68
+ }).catch(() => null);
69
+ }
70
+ exports.EnsureAssetLibrary = EnsureAssetLibrary;
71
+ function GetSiteAssetLibrary(siteUrl, sync) {
72
+ let reqUrl = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/lists?`
73
+ //Issue 1492: isSiteAssetsLibrary eq true does not work for reader users.
74
+ //+ `$filter=isSiteAssetsLibrary eq true&$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists`
75
+ + `$filter=EntityTypeName%20eq%20%27SiteAssets%27&$select=ID,RootFolder/Name,RootFolder/ServerRelativeUrl,RootFolder/Exists`
76
+ + `&$expand=RootFolder`;
77
+ let caller = sync ? rest_1.GetJsonSync : rest_1.GetJson;
78
+ let result = caller(reqUrl, null, Object.assign(Object.assign({}, rest_1.longLocalCache), { jsonMetadata: _dependencies_1.jsonTypes.nometadata }));
79
+ let transform = (v) => {
80
+ if ((0, _dependencies_1.isNotEmptyArray)(v && v.value)) {
81
+ let assetLibrary = v.value[0];
82
+ return {
83
+ Id: assetLibrary.Id,
84
+ Name: assetLibrary.RootFolder.Name,
85
+ ServerRelativeUrl: assetLibrary.RootFolder.ServerRelativeUrl
86
+ };
87
+ }
88
+ return null;
89
+ };
90
+ if ((0, _dependencies_1.isPromise)(result))
91
+ return result.then(r => transform(r), () => null);
92
+ else
93
+ return result.success ? transform(result.result) : null;
94
+ }
95
+ exports.GetSiteAssetLibrary = GetSiteAssetLibrary;
96
+ /** Return the list Title */
97
+ function GetListTitle(siteUrl, listIdOrTitle) {
98
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
99
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/Title`, null, { allowCache: true })
100
+ .then(r => {
101
+ return r.d.Title;
102
+ })
103
+ .catch(() => null);
104
+ }
105
+ exports.GetListTitle = GetListTitle;
106
+ /** Return the list */
107
+ function GetList(siteUrlOrId, listIdOrTitle, options) {
108
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
109
+ if ((0, _dependencies_1.isNullOrEmptyString)(listIdOrTitle))
110
+ return null;
111
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `?$select=${common_1.LIST_SELECT}&$expand=${common_1.LIST_EXPAND}`, null, { allowCache: true })
112
+ .then((r) => __awaiter(this, void 0, void 0, function* () {
113
+ let list = r.d;
114
+ if (options) {
115
+ if (options.includeViews)
116
+ list.Views = yield GetListViews(siteUrl, listIdOrTitle, options.viewOptions);
117
+ if (options.includeContentTypes)
118
+ list.ContentTypes = yield GetListContentTypes(siteUrl, listIdOrTitle);
119
+ if (options.includeRootFolder)
120
+ list.RootFolder = yield GetListRootFolder(siteUrl, listIdOrTitle);
121
+ if (options.includeEventReceivers)
122
+ list.EventReceivers = yield GetListEventReceivers(siteUrl, listIdOrTitle);
123
+ }
124
+ if (list.EffectiveBasePermissions
125
+ && ((0, _dependencies_1.isString)(list.EffectiveBasePermissions.High)
126
+ || (0, _dependencies_1.isString)(list.EffectiveBasePermissions.Low))) {
127
+ list.EffectiveBasePermissions = {
128
+ High: Number(list.EffectiveBasePermissions.High),
129
+ Low: Number(list.EffectiveBasePermissions.Low)
130
+ };
131
+ }
132
+ return list;
133
+ }))
134
+ .catch(() => null);
135
+ }
136
+ exports.GetList = GetList;
137
+ /** Return the list */
138
+ function GetListSync(siteUrl, listIdOrTitle) {
139
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
140
+ if ((0, _dependencies_1.isNullOrEmptyString)(listIdOrTitle))
141
+ return null;
142
+ let result = (0, rest_1.GetJsonSync)(GetListRestUrl(siteUrl, listIdOrTitle) + `?$select=${common_1.LIST_SELECT}&$expand=${common_1.LIST_EXPAND}`, null, rest_1.shortLocalCache);
143
+ if (result && result.success) {
144
+ let list = result.result.d;
145
+ if (list.EffectiveBasePermissions
146
+ && ((0, _dependencies_1.isString)(list.EffectiveBasePermissions.High)
147
+ || (0, _dependencies_1.isString)(list.EffectiveBasePermissions.Low))) {
148
+ list.EffectiveBasePermissions = {
149
+ High: Number(list.EffectiveBasePermissions.High),
150
+ Low: Number(list.EffectiveBasePermissions.Low)
151
+ };
152
+ }
153
+ return list;
154
+ }
155
+ else
156
+ return null;
157
+ }
158
+ exports.GetListSync = GetListSync;
159
+ function GetListNameSync(webUrl, listIdOrTitle) {
160
+ let list = GetListSync(webUrl, listIdOrTitle);
161
+ return (0, _dependencies_1.NormalizeListName)({ EntityTypeName: list.EntityTypeName, BaseType: list.BaseType });
162
+ }
163
+ exports.GetListNameSync = GetListNameSync;
164
+ function GetListName(webUrl, listIdOrTitle) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ let list = yield GetList(webUrl, listIdOrTitle);
167
+ return (0, _dependencies_1.NormalizeListName)({ EntityTypeName: list.EntityTypeName, BaseType: list.BaseType });
168
+ });
169
+ }
170
+ exports.GetListName = GetListName;
171
+ function GetListRootFolder(siteUrlOrId, listIdOrTitle) {
172
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
173
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/RootFolder?$Select=Name,ServerRelativeUrl`, null, rest_1.longLocalCache)
174
+ .then(r => {
175
+ return r.d;
176
+ })
177
+ .catch(() => null);
178
+ }
179
+ exports.GetListRootFolder = GetListRootFolder;
180
+ function GetListRootFolderSync(siteUrlOrId, listIdOrTitle) {
181
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
182
+ let result = (0, rest_1.GetJsonSync)(GetListRestUrl(siteUrl, listIdOrTitle) + `/RootFolder?$Select=Name,ServerRelativeUrl`, null, rest_1.longLocalCache);
183
+ return (0, _dependencies_1.SafeIfElse)(() => result.result.d, null);
184
+ }
185
+ exports.GetListRootFolderSync = GetListRootFolderSync;
186
+ function GetListField(siteUrlOrId, listIdOrTitle, fieldIdOrName, refreshCache) {
187
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
188
+ var url = GetListRestUrl(siteUrl, listIdOrTitle) + `/fields`;
189
+ if ((0, _dependencies_1.isValidGuid)(fieldIdOrName)) {
190
+ url += `('${(0, _dependencies_1.normalizeGuid)(fieldIdOrName)}')`;
191
+ }
192
+ else {
193
+ url += `/getbyinternalnameortitle(@u)?@u='${encodeURIComponent(fieldIdOrName)}'`;
194
+ }
195
+ let result = (0, rest_1.GetJson)(url, null, { allowCache: refreshCache !== true })
196
+ .then(r => {
197
+ return r.d;
198
+ })
199
+ .catch(() => null);
200
+ return result;
201
+ }
202
+ exports.GetListField = GetListField;
203
+ function _getListFieldsRequestUrl(siteUrl, listIdOrTitle) {
204
+ return GetListRestUrl(siteUrl, listIdOrTitle) + `/fields`;
205
+ }
206
+ /** Gets ID, Title, ContentType Author, Editor, Created and Modified fields */
207
+ function GetStandardListFields(siteUrlOrId, listIdOrTitle, refreshCache) {
208
+ let fieldNames = ["ID", "Title", "ContentType", "Author", "Editor", "Created", "Modified"];
209
+ return GetListFields(siteUrlOrId, listIdOrTitle, { refreshCache: refreshCache, fieldNames: fieldNames });
210
+ }
211
+ exports.GetStandardListFields = GetStandardListFields;
212
+ function _processGetListFields(fields, fieldNames) {
213
+ if ((0, _dependencies_1.isNullOrEmptyArray)(fields)) {
214
+ return fields;
215
+ }
216
+ let extendedFields = fields.map(f => (0, _dependencies_1.extendFieldInfo)(f, fields));
217
+ if (!(0, _dependencies_1.isNullOrEmptyArray)(fieldNames)) {
218
+ return extendedFields.filter((extendedField) => {
219
+ return fieldNames.includes(extendedField.InternalName);
220
+ });
221
+ }
222
+ return extendedFields;
223
+ }
224
+ function GetListFields(siteUrlOrId, listIdOrTitle, options = {}) {
225
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
226
+ let url = _getListFieldsRequestUrl(siteUrl, listIdOrTitle);
227
+ let restOptions = {
228
+ allowCache: options.refreshCache !== true,
229
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata
230
+ };
231
+ return (0, rest_1.GetJson)(url, null, restOptions)
232
+ .then((result) => {
233
+ return _processGetListFields(result.value, options.fieldNames);
234
+ }).catch(() => {
235
+ return null;
236
+ });
237
+ }
238
+ exports.GetListFields = GetListFields;
239
+ function GetListFieldsSync(siteUrlOrId, listIdOrTitle, options = {}) {
240
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
241
+ let url = _getListFieldsRequestUrl(siteUrl, listIdOrTitle);
242
+ let restOptions = {
243
+ allowCache: options.refreshCache !== true,
244
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata
245
+ };
246
+ let result = (0, rest_1.GetJsonSync)(url, null, restOptions);
247
+ if (result.success && !(0, _dependencies_1.isNullOrUndefined)(result.result)) {
248
+ return _processGetListFields(result.result.value, options.fieldNames);
249
+ }
250
+ return null;
251
+ }
252
+ exports.GetListFieldsSync = GetListFieldsSync;
253
+ function GetListFieldsAsHash(siteUrlOrId, listIdOrTitle, refreshCache) {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
256
+ let fields = yield GetListFields(siteUrl, listIdOrTitle, { refreshCache: refreshCache });
257
+ let hash = {};
258
+ if ((0, _dependencies_1.isNotEmptyArray)(fields)) {
259
+ hash = (0, _dependencies_1.toHash)(fields, f => f.InternalName);
260
+ }
261
+ return hash;
262
+ });
263
+ }
264
+ exports.GetListFieldsAsHash = GetListFieldsAsHash;
265
+ function GetListFieldsAsHashSync(siteUrlOrId, listIdOrTitle, refreshCache) {
266
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
267
+ let fields = GetListFieldsSync(siteUrl, listIdOrTitle, { refreshCache: refreshCache });
268
+ let hash = {};
269
+ if ((0, _dependencies_1.isNotEmptyArray)(fields)) {
270
+ fields.forEach(f => { hash[f.InternalName] = f; });
271
+ }
272
+ return hash;
273
+ }
274
+ exports.GetListFieldsAsHashSync = GetListFieldsAsHashSync;
275
+ function GetListWorkflows(siteUrl, listIdOrTitle, refreshCache) {
276
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
277
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/workflowAssociations`, null, { allowCache: refreshCache !== true })
278
+ .then(r => {
279
+ if (r && r.d && (0, _dependencies_1.isNotEmptyArray)(r.d.results)) {
280
+ r.d.results.forEach(wf => {
281
+ wf.BaseId = (0, _dependencies_1.normalizeGuid)(wf.BaseId);
282
+ wf.Id = (0, _dependencies_1.normalizeGuid)(wf.Id);
283
+ wf.ListId = (0, _dependencies_1.normalizeGuid)(wf.ListId);
284
+ wf.WebId = (0, _dependencies_1.normalizeGuid)(wf.WebId);
285
+ });
286
+ return r.d.results;
287
+ }
288
+ else
289
+ return [];
290
+ })
291
+ .catch(() => []);
292
+ }
293
+ exports.GetListWorkflows = GetListWorkflows;
294
+ function UserHasManagePermissions(siteUrl, listIdOrTitle) {
295
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
296
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, Object.assign({}, rest_1.shortLocalCache))
297
+ .then(r => {
298
+ return new _dependencies_1.SPBasePermissions(r.d.EffectiveBasePermissions).has(_dependencies_1.SPBasePermissionKind.ManageLists);
299
+ })
300
+ .catch(() => null);
301
+ }
302
+ exports.UserHasManagePermissions = UserHasManagePermissions;
303
+ function UserHasEditPermissions(siteUrl, listIdOrTitle) {
304
+ return UserHasPermissions(siteUrl, listIdOrTitle, _dependencies_1.SPBasePermissionKind.EditListItems);
305
+ }
306
+ exports.UserHasEditPermissions = UserHasEditPermissions;
307
+ function UserHasPermissions(siteUrlOrId, listIdOrTitle, permissionKind) {
308
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
309
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, Object.assign({}, rest_1.shortLocalCache))
310
+ .then(r => {
311
+ return new _dependencies_1.SPBasePermissions(r.d.EffectiveBasePermissions).has(permissionKind);
312
+ })
313
+ .catch(() => null);
314
+ }
315
+ exports.UserHasPermissions = UserHasPermissions;
316
+ function UserHasPermissionsSync(siteUrlOrId, listIdOrTitle, permissionKind) {
317
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
318
+ const res = (0, rest_1.GetJsonSync)(GetListRestUrl(siteUrl, listIdOrTitle) + `/EffectiveBasePermissions`, null, Object.assign({}, rest_1.shortLocalCache));
319
+ return new _dependencies_1.SPBasePermissions(res.result.d.EffectiveBasePermissions).has(permissionKind);
320
+ }
321
+ exports.UserHasPermissionsSync = UserHasPermissionsSync;
322
+ /** 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
+ function CreateField(siteUrl, listIdOrTitle, options) {
324
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
325
+ let finish = (result) => __awaiter(this, void 0, void 0, function* () {
326
+ if (result && result.d) {
327
+ let internalName = result.d.InternalName;
328
+ //we need to clear and reload the list fields cache, so call it and return our field from that collection.
329
+ let fields = yield GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
330
+ try {
331
+ if (options.SkipAddToDefaultView !== true) {
332
+ //try to add it to default view, don't wait for it
333
+ GetListViews(siteUrl, listIdOrTitle).then(views => {
334
+ let defaultView = (0, _dependencies_1.firstOrNull)(views, v => v.DefaultView);
335
+ if (defaultView)
336
+ (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${defaultView.Id}')/ViewFields/addViewField('${internalName}')`, null, { method: "POST", spWebUrl: siteUrl });
337
+ });
338
+ }
339
+ }
340
+ catch (e) { }
341
+ return (0, _dependencies_1.firstOrNull)(fields, f => f.InternalName === internalName);
342
+ }
343
+ return null;
344
+ });
345
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.SchemaXml)) {
346
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/createFieldAsXml`, JSON.stringify({
347
+ 'parameters': {
348
+ '__metadata': { 'type': 'SP.XmlSchemaFieldCreationInformation' },
349
+ 'SchemaXml': options.SchemaXml,
350
+ 'Options': options.SchemaXmlSpecificInternalName !== true ?
351
+ 4 : //SP.AddFieldOptions.addToAllContentTypes
352
+ 4 | 8 //SP.AddFieldOptions.addToAllContentTypes | addFieldInternalNameHint
353
+ }
354
+ }))
355
+ .then(r => {
356
+ return finish(r);
357
+ })
358
+ .catch(() => null);
359
+ }
360
+ else if (!(0, _dependencies_1.isNullOrEmptyString)(options.Title) && !(0, _dependencies_1.isNullOrUndefined)(options.Type)) {
361
+ let updateObject = {
362
+ '__metadata': { 'type': 'SP.Field' },
363
+ 'Title': options.Title,
364
+ 'FieldTypeKind': options.Type,
365
+ 'Required': options.Required === true
366
+ };
367
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.ClientSideComponentId))
368
+ updateObject.ClientSideComponentId = options.ClientSideComponentId;
369
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.ClientSideComponentProperties))
370
+ updateObject.ClientSideComponentProperties = options.ClientSideComponentProperties;
371
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields`, JSON.stringify(updateObject))
372
+ .then(r => {
373
+ return finish(r);
374
+ })
375
+ .catch(() => null);
376
+ }
377
+ else {
378
+ console.error("You must send either SchemaXml or Title and Type");
379
+ return null;
380
+ }
381
+ }
382
+ exports.CreateField = CreateField;
383
+ /** Update field SchemaXml OR Title, only 1 update at a time supported. */
384
+ function UpdateField(siteUrlOrId, listIdOrTitle, fieldInternalName, options) {
385
+ return __awaiter(this, void 0, void 0, function* () {
386
+ let siteUrl = (0, common_1.GetSiteUrl)(siteUrlOrId);
387
+ let finish = () => __awaiter(this, void 0, void 0, function* () {
388
+ //we need to clear and reload the list fields cache, so call it and return our field from that collection.
389
+ let fields = yield GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
390
+ return (0, _dependencies_1.firstOrNull)(fields, f => f.InternalName === fieldInternalName);
391
+ });
392
+ //updates can either be SchemaXml, or others. Cannot be both.
393
+ let updates = {
394
+ '__metadata': { 'type': 'SP.Field' }
395
+ };
396
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.SchemaXml)) {
397
+ updates.SchemaXml = options.SchemaXml;
398
+ }
399
+ else {
400
+ //cannot send schema updates with other updates.
401
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.Title)) {
402
+ updates.Title = options.Title;
403
+ }
404
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.FieldType)) {
405
+ updates.TypeAsString = options.FieldType;
406
+ }
407
+ if ((0, _dependencies_1.isBoolean)(options.Required)) {
408
+ updates.Required = options.Required === true;
409
+ }
410
+ if ((0, _dependencies_1.isBoolean)(options.Hidden)) {
411
+ //this requries the CanToggleHidden to be in the schema... if not - we will need to add it before we can update this.
412
+ let fields = yield GetListFieldsAsHash(siteUrl, listIdOrTitle, false);
413
+ let thisField = fields[fieldInternalName];
414
+ if (thisField.Hidden !== options.Hidden) {
415
+ if (thisField) {
416
+ if (thisField.SchemaJson.Attributes.CanToggleHidden !== "TRUE") {
417
+ yield UpdateField(siteUrl, listIdOrTitle, fieldInternalName, {
418
+ SchemaXml: thisField.SchemaXml.replace("<Field ", `<Field CanToggleHidden="TRUE" `)
419
+ });
420
+ }
421
+ }
422
+ updates.Hidden = options.Hidden === true;
423
+ }
424
+ }
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
+ }
441
+ });
442
+ }
443
+ exports.UpdateField = UpdateField;
444
+ function DeleteField(siteUrl, listIdOrTitle, fieldInternalName, options) {
445
+ return __awaiter(this, void 0, void 0, function* () {
446
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
447
+ // let finish = async () => {
448
+ // //we need to clear and reload the list fields cache, so call it and return our field from that collection.
449
+ // let fields = await GetListFields(siteUrl, listIdOrTitle, { refreshCache: true });
450
+ // return firstOrNull(fields, f => f.InternalName === fieldInternalName);
451
+ // };
452
+ if (options && options.DeleteHiddenField)
453
+ yield UpdateField(siteUrl, listIdOrTitle, fieldInternalName, { Hidden: false });
454
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getbyinternalnameortitle('${fieldInternalName}')`, null, {
455
+ method: "POST",
456
+ xHttpMethod: "DELETE"
457
+ })
458
+ .then(r => true)
459
+ .catch((e) => false);
460
+ });
461
+ }
462
+ exports.DeleteField = DeleteField;
463
+ function GetListViews(siteUrl, listIdOrTitle, options) {
464
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
465
+ return (0, rest_1.GetJson)(GetListRestUrl(siteUrl, listIdOrTitle) + `/views?$select=Title,Id,ServerRelativeUrl,RowLimit,Paged,ViewQuery,ListViewXml,PersonalView,MobileView,MobileDefaultView,Hidden,DefaultView,ReadOnlyView${options && options.includeViewFields ? "&$expand=ViewFields" : ""}`, null, { allowCache: true, jsonMetadata: _dependencies_1.jsonTypes.nometadata })
466
+ .then(r => {
467
+ let views = r.value;
468
+ if ((0, _dependencies_1.isNotEmptyArray)(views)) {
469
+ views.forEach(v => {
470
+ v.Id = (0, _dependencies_1.normalizeGuid)(v.Id);
471
+ if (options && options.includeViewFields) {
472
+ v.ViewFields = v.ViewFields && v.ViewFields["Items"] && v.ViewFields["Items"] || [];
473
+ }
474
+ });
475
+ }
476
+ return views;
477
+ })
478
+ .catch(() => null);
479
+ }
480
+ exports.GetListViews = GetListViews;
481
+ function GetListViewsSync(siteUrl, listIdOrTitle) {
482
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
483
+ let result = (0, rest_1.GetJsonSync)(GetListRestUrl(siteUrl, listIdOrTitle) + `/views`, null, { allowCache: true });
484
+ if (result.success) {
485
+ let views = result && result.result && result.result.d && result.result.d.results;
486
+ if ((0, _dependencies_1.isNotEmptyArray)(views)) {
487
+ views.forEach(v => { v.Id = (0, _dependencies_1.normalizeGuid)(v.Id); });
488
+ }
489
+ return views;
490
+ }
491
+ return null;
492
+ }
493
+ exports.GetListViewsSync = GetListViewsSync;
494
+ function AddViewFieldToListView(siteUrl, listIdOrTitle, viewId, viewField) {
495
+ return __awaiter(this, void 0, void 0, function* () {
496
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
497
+ if ((0, _dependencies_1.isNullOrEmptyString)(viewField) || !(0, _dependencies_1.isValidGuid)(viewId)) {
498
+ return false;
499
+ }
500
+ let views = yield GetListViews(siteUrl, listIdOrTitle, { includeViewFields: true });
501
+ if ((0, _dependencies_1.isNullOrEmptyArray)(views)) {
502
+ return false;
503
+ }
504
+ let view = views.filter((view) => {
505
+ return (0, _dependencies_1.normalizeGuid)(view.Id) === (0, _dependencies_1.normalizeGuid)(viewId);
506
+ })[0];
507
+ if ((0, _dependencies_1.isNullOrUndefined)(view)) {
508
+ return false;
509
+ }
510
+ let hasField = view.ViewFields.includes(viewField);
511
+ if (hasField === true) {
512
+ return true;
513
+ }
514
+ try {
515
+ let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/views('${(0, _dependencies_1.normalizeGuid)(view.Id)}')/viewfields/addviewfield('${viewField}')`;
516
+ let result = yield (0, rest_1.GetJson)(url, null, { method: "POST" });
517
+ console.log(result);
518
+ if (result && result.d.AddViewField === null) {
519
+ return true;
520
+ }
521
+ }
522
+ catch (_a) { }
523
+ return false;
524
+ });
525
+ }
526
+ exports.AddViewFieldToListView = AddViewFieldToListView;
527
+ function GetListContentTypes(siteUrl, listIdOrTitle, options) {
528
+ return (0, web_1.GetContentTypes)(siteUrl, Object.assign(Object.assign({}, (options || {})), { listIdOrTitle: listIdOrTitle }));
529
+ }
530
+ exports.GetListContentTypes = GetListContentTypes;
531
+ function GetListContentTypesSync(siteUrl, listIdOrTitle, options) {
532
+ return (0, web_1.GetContentTypesSync)(siteUrl, Object.assign(Object.assign({}, (options || {})), { listIdOrTitle: listIdOrTitle }));
533
+ }
534
+ exports.GetListContentTypesSync = GetListContentTypesSync;
535
+ /** generic version. for the KWIZ forms version that supports action id call GetListFormUrlAppsWeb instead */
536
+ function GetListFormUrl(siteUrl, listId, pageType, params) {
537
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
538
+ if (!(0, _dependencies_1.isValidGuid)(listId))
539
+ console.error('GetListFormUrl requires a list id');
540
+ let url = `${(0, _dependencies_1.normalizeUrl)(siteUrl)}/_layouts/15/listform.aspx?PageType=${pageType}&ListId=${encodeURIComponent(listId)}`;
541
+ if (params) {
542
+ if (!(0, _dependencies_1.isNullOrEmptyString)(params.contentTypeId))
543
+ url += `&ContentTypeId=${encodeURIComponent(params.contentTypeId)}`;
544
+ if (!(0, _dependencies_1.isNullOrEmptyString)(params.itemId))
545
+ url += `&ID=${encodeURIComponent(params.itemId)}`;
546
+ }
547
+ return url;
548
+ }
549
+ exports.GetListFormUrl = GetListFormUrl;
550
+ function GetFieldSchemaSync(siteUrl, listIdOrTitle, fieldInternalName, refreshCache) {
551
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
552
+ //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
553
+ //exists before requesting the schema.
554
+ let fields = GetListFieldsSync(siteUrl, listIdOrTitle, {
555
+ refreshCache: refreshCache,
556
+ fieldNames: [fieldInternalName]
557
+ });
558
+ if ((0, _dependencies_1.isNullOrEmptyArray)(fields)) {
559
+ return null;
560
+ }
561
+ let field = fields[0];
562
+ return (0, _dependencies_1.SchemaXmlToJson)(field.SchemaXml);
563
+ // let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/fields/getByInternalNameOrTitle('${fieldInternalName}')?$select=SchemaXml`;
564
+ // let result = GetJsonSync<{ d: { SchemaXml: string; }; }>(
565
+ // url,
566
+ // null,
567
+ // {
568
+ // ...shortLocalCache,
569
+ // forceCacheUpdate: refreshCache === true
570
+ // });
571
+ // if (result && result.success) {
572
+ // return SchemaXmlToJson(result.result.d.SchemaXml);
573
+ // }
574
+ // return null;
575
+ //#endregion
576
+ }
577
+ exports.GetFieldSchemaSync = GetFieldSchemaSync;
578
+ function GetFieldSchema(siteUrl, listIdOrTitle, fieldInternalName, refreshCache) {
579
+ return __awaiter(this, void 0, void 0, function* () {
580
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
581
+ //ISSUE: 1516 - The get schema request will fail if the field doesn't exist in the list, so we load the fields and ensure the field
582
+ //exists before requesting the schema
583
+ let fields = yield GetListFields(siteUrl, listIdOrTitle, {
584
+ refreshCache: refreshCache,
585
+ fieldNames: [fieldInternalName]
586
+ });
587
+ if ((0, _dependencies_1.isNullOrEmptyArray)(fields)) {
588
+ return null;
589
+ }
590
+ let field = fields[0];
591
+ return (0, _dependencies_1.SchemaXmlToJson)(field.SchemaXml);
592
+ });
593
+ }
594
+ exports.GetFieldSchema = GetFieldSchema;
595
+ function GetListItems(siteUrl, listIdOrTitle, options) {
596
+ return __awaiter(this, void 0, void 0, function* () {
597
+ let info = _GetListItemsInfo(siteUrl, listIdOrTitle, options);
598
+ let items = [];
599
+ do {
600
+ let resultItems = [];
601
+ let next = null;
602
+ if (info.noMetadata) {
603
+ let requestResult = (yield (0, rest_1.GetJson)(info.requestUrl, null, {
604
+ allowCache: options.refreshCache !== true,
605
+ jsonMetadata: options.jsonMetadata
606
+ }));
607
+ resultItems = requestResult.value;
608
+ next = requestResult["odata.nextLink"];
609
+ }
610
+ else {
611
+ let requestResult = (yield (0, rest_1.GetJson)(info.requestUrl, null, {
612
+ allowCache: options.refreshCache !== true
613
+ }));
614
+ resultItems = requestResult.d.results;
615
+ next = requestResult.d.__next;
616
+ }
617
+ if ((0, _dependencies_1.isNotEmptyArray)(resultItems))
618
+ items.push(...resultItems);
619
+ if (info.totalNumberOfItemsToGet > items.length)
620
+ info.requestUrl = next;
621
+ else
622
+ info.requestUrl = null;
623
+ } while (!(0, _dependencies_1.isNullOrEmptyString)(info.requestUrl));
624
+ return (0, common_2.__fixGetListItemsResults)(siteUrl, listIdOrTitle, items, options.foldersBehaviour, info.expandedLookupFields);
625
+ });
626
+ }
627
+ exports.GetListItems = GetListItems;
628
+ function GetListItemsSync(siteUrl, listIdOrTitle, options) {
629
+ let info = _GetListItemsInfo(siteUrl, listIdOrTitle, options);
630
+ let items = [];
631
+ do {
632
+ let resultItems = [];
633
+ let next = null;
634
+ if (info.noMetadata) {
635
+ let requestResult = (0, rest_1.GetJsonSync)(info.requestUrl, null, { allowCache: true });
636
+ if (requestResult.success) {
637
+ resultItems = requestResult.result.value;
638
+ next = requestResult.result["odata.nextLink"];
639
+ }
640
+ }
641
+ else {
642
+ let requestResult = (0, rest_1.GetJsonSync)(info.requestUrl, null, { allowCache: true });
643
+ if (requestResult.success) {
644
+ resultItems = requestResult.result.d.results;
645
+ next = requestResult.result.d.__next;
646
+ }
647
+ }
648
+ if ((0, _dependencies_1.isNotEmptyArray)(resultItems))
649
+ items.push(...resultItems);
650
+ if (info.totalNumberOfItemsToGet > items.length)
651
+ info.requestUrl = next;
652
+ else
653
+ info.requestUrl = null;
654
+ } while (!(0, _dependencies_1.isNullOrEmptyString)(info.requestUrl));
655
+ return (0, common_2.__fixGetListItemsResults)(siteUrl, listIdOrTitle, items, options.foldersBehaviour, info.expandedLookupFields);
656
+ }
657
+ exports.GetListItemsSync = GetListItemsSync;
658
+ function _GetListItemsInfo(siteUrl, listIdOrTitle, options) {
659
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
660
+ let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items`;
661
+ let queryParams = [];
662
+ //Issue 8189 expand lookup fields
663
+ let columns = [];
664
+ let expand = [];
665
+ let expandedLookupFields = [];
666
+ options.columns.forEach(c => {
667
+ if ((0, _dependencies_1.isString)(c))
668
+ columns.push(c);
669
+ else {
670
+ let internalName = c.InternalName;
671
+ //Issue 828, 336
672
+ if (internalName.startsWith("_"))
673
+ internalName = `OData_${internalName}`;
674
+ if (c.TypeAsString === "Lookup" || c.TypeAsString === "LookupMulti" || c.TypeAsString === "User" || c.TypeAsString === "UserMulti") {
675
+ //ISSUE: 1519 - Added lookupField property to able to retrieve value of the additional lookup field key
676
+ let lookupField = c.LookupField;
677
+ if (!(0, _dependencies_1.isNullOrEmptyString)(lookupField)) {
678
+ columns.push(`${internalName}/${lookupField}`);
679
+ }
680
+ //we want to expand it
681
+ columns.push(`${internalName}/Title`);
682
+ columns.push(`${internalName}/Id`);
683
+ expand.push(internalName);
684
+ expandedLookupFields.push(c);
685
+ }
686
+ else
687
+ columns.push(internalName);
688
+ }
689
+ });
690
+ if ((0, _dependencies_1.isNotEmptyArray)(options.expand)) {
691
+ expand.push(...options.expand);
692
+ }
693
+ //add the ones we need
694
+ (0, _dependencies_1.PushNoDuplicate)(columns, "Id");
695
+ (0, _dependencies_1.PushNoDuplicate)(columns, "FileRef");
696
+ (0, _dependencies_1.PushNoDuplicate)(columns, "FileSystemObjectType");
697
+ queryParams.push(`$select=${encodeURIComponent((0, _dependencies_1.makeUniqueArray)(columns).join(','))}`);
698
+ if ((0, _dependencies_1.isNotEmptyArray)(expand))
699
+ queryParams.push(`$expand=${encodeURIComponent((0, _dependencies_1.makeUniqueArray)(expand).join(','))}`);
700
+ let batchSize = 2000;
701
+ let limit = options.rowLimit >= 0 && options.rowLimit < batchSize ? options.rowLimit : batchSize;
702
+ let totalNumberOfItemsToGet = !(0, _dependencies_1.isNumber)(options.rowLimit) || options.rowLimit < 1 ? 99999 : options.rowLimit > batchSize ? options.rowLimit : limit;
703
+ if (!(0, _dependencies_1.isNullOrEmptyString)(options.$filter))
704
+ queryParams.push(`$filter=${options.$filter}`);
705
+ queryParams.push(`$top=${limit}`);
706
+ let requestUrl = url + (queryParams.length > 0 ? '?' + queryParams.join('&') : '');
707
+ let noMetadata = options.jsonMetadata === _dependencies_1.jsonTypes.nometadata;
708
+ return { requestUrl, noMetadata, totalNumberOfItemsToGet, expandedLookupFields };
709
+ }
710
+ /** Find an item by id, even if it is nested in a sub-folder */
711
+ function FindListItemById(items, itemId) {
712
+ for (let i = 0; i < items.length; i++) {
713
+ let current = items[i];
714
+ if (current.Id === itemId)
715
+ return current;
716
+ else if ((0, _dependencies_1.isNotEmptyArray)(current.__Items)) //folder? look inside
717
+ {
718
+ let nestedResult = FindListItemById(current.__Items, itemId);
719
+ if (!(0, _dependencies_1.isNullOrUndefined)(nestedResult))
720
+ return nestedResult;
721
+ }
722
+ }
723
+ //not found
724
+ return null;
725
+ }
726
+ exports.FindListItemById = FindListItemById;
727
+ function _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle) {
728
+ return GetListRestUrl(siteUrl, listIdOrTitle) + `/EventReceivers`;
729
+ }
730
+ function GetListEventReceivers(siteUrl, listIdOrTitle, refreshCache) {
731
+ return __awaiter(this, void 0, void 0, function* () {
732
+ try {
733
+ let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
734
+ let response = yield (0, rest_1.GetJson)(url, null, {
735
+ allowCache: refreshCache !== true,
736
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata
737
+ });
738
+ return !(0, _dependencies_1.isNullOrUndefined)(response) ? response.value : null;
739
+ }
740
+ catch (_a) {
741
+ }
742
+ return null;
743
+ });
744
+ }
745
+ exports.GetListEventReceivers = GetListEventReceivers;
746
+ function AddListEventReceiver(siteUrl, listIdOrTitle, eventReceiverDefinition) {
747
+ return __awaiter(this, void 0, void 0, function* () {
748
+ let newEventReceiver = Object.assign({ ReceiverAssembly: "", ReceiverClass: "" }, eventReceiverDefinition);
749
+ try {
750
+ let url = _getListEventReceiversRequestUrl(siteUrl, listIdOrTitle);
751
+ let response = yield (0, rest_1.GetJson)(url, JSON.stringify(newEventReceiver), {
752
+ method: "POST",
753
+ includeDigestInPost: true,
754
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata,
755
+ headers: {
756
+ "content-type": _dependencies_1.contentTypes.json
757
+ }
758
+ });
759
+ return !(0, _dependencies_1.isNullOrUndefined)(response) && (0, _dependencies_1.isValidGuid)(response.ReceiverId) ? response : null;
760
+ }
761
+ catch (_a) {
762
+ }
763
+ return null;
764
+ });
765
+ }
766
+ exports.AddListEventReceiver = AddListEventReceiver;
767
+ function DeleteListEventReceiver(siteUrl, listIdOrTitle, eventReceiverId) {
768
+ return __awaiter(this, void 0, void 0, function* () {
769
+ try {
770
+ let url = `${_getListEventReceiversRequestUrl(siteUrl, listIdOrTitle)}('${(0, _dependencies_1.normalizeGuid)(eventReceiverId)}')/deleteObject`;
771
+ let response = yield (0, rest_1.GetJson)(url, null, {
772
+ method: "POST",
773
+ includeDigestInPost: true,
774
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata
775
+ });
776
+ return !(0, _dependencies_1.isNullOrUndefined)(response) && response["odata.null"] === true;
777
+ }
778
+ catch (_a) {
779
+ }
780
+ return false;
781
+ });
782
+ }
783
+ exports.DeleteListEventReceiver = DeleteListEventReceiver;
784
+ function GetListLastItemModifiedDate(siteUrl, listIdOrTitle, options) {
785
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
786
+ let endPoint = options && options.userChangesOnly ? 'LastItemUserModifiedDate' : 'LastItemModifiedDate';
787
+ let sync = options && options.sync ? true : false;
788
+ let caller = sync ? rest_1.GetJsonSync : rest_1.GetJson;
789
+ let result = caller(GetListRestUrl(siteUrl, listIdOrTitle) + `/${endPoint}`, null, {
790
+ allowCache: true, //in memory only
791
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata,
792
+ forceCacheUpdate: options && options.refreshCache === true || false
793
+ });
794
+ if ((0, _dependencies_1.isPromise)(result))
795
+ return result.then(r => r.value, () => null);
796
+ else
797
+ return result.success ? result.result.value : null;
798
+ }
799
+ exports.GetListLastItemModifiedDate = GetListLastItemModifiedDate;
800
+ function ReloadListLastModified(siteUrl, listIdOrTitle) {
801
+ return __awaiter(this, void 0, void 0, function* () {
802
+ yield GetListLastItemModifiedDate(siteUrl, listIdOrTitle, { refreshCache: true });
803
+ //make sure we do it for both title and id, we don't know how the other callers may use this in their API
804
+ if (!(0, _dependencies_1.isValidGuid)(listIdOrTitle)) {
805
+ try {
806
+ var listId = GetListId(siteUrl, listIdOrTitle);
807
+ yield GetListLastItemModifiedDate(siteUrl, listId, { refreshCache: true });
808
+ }
809
+ catch (e) { }
810
+ }
811
+ else {
812
+ try {
813
+ var listTitle = yield GetListTitle(siteUrl, listIdOrTitle);
814
+ yield GetListLastItemModifiedDate(siteUrl, listTitle, { refreshCache: true });
815
+ }
816
+ catch (e) { }
817
+ }
818
+ });
819
+ }
820
+ exports.ReloadListLastModified = ReloadListLastModified;
821
+ function ListHasUniquePermissions(siteUrl, listIdOrTitle) {
822
+ return __awaiter(this, void 0, void 0, function* () {
823
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/?$select=hasuniqueroleassignments`;
824
+ let has = yield (0, rest_1.GetJson)(url, undefined, { allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
825
+ return has.HasUniqueRoleAssignments === true;
826
+ });
827
+ }
828
+ exports.ListHasUniquePermissions = ListHasUniquePermissions;
829
+ function BreakListbPermissionInheritance(siteUrl, listIdOrTitle, clear = true) {
830
+ return __awaiter(this, void 0, void 0, function* () {
831
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/breakroleinheritance(copyRoleAssignments=${clear ? 'false' : 'true'}, clearSubscopes=true)`;
832
+ yield (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
833
+ });
834
+ }
835
+ exports.BreakListbPermissionInheritance = BreakListbPermissionInheritance;
836
+ function AssignListPermission(siteUrl, listIdOrTitle, principalId, roleId) {
837
+ return __awaiter(this, void 0, void 0, function* () {
838
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/addroleassignment(principalid=${principalId},roleDefId=${roleId})`;
839
+ yield (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
840
+ });
841
+ }
842
+ exports.AssignListPermission = AssignListPermission;
843
+ function RemoveListPermission(siteUrl, listIdOrTitle, principalId, roleId) {
844
+ return __awaiter(this, void 0, void 0, function* () {
845
+ let url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/roleassignments/removeroleassignment(principalid=${principalId},roleDefId=${roleId})`;
846
+ yield (0, rest_1.GetJson)(url, undefined, { method: "POST", allowCache: false, jsonMetadata: _dependencies_1.jsonTypes.nometadata });
847
+ });
848
+ }
849
+ exports.RemoveListPermission = RemoveListPermission;
850
+ function CreateList(siteUrl, info) {
851
+ return __awaiter(this, void 0, void 0, function* () {
852
+ let url = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/lists`;
853
+ const body = {
854
+ __metadata: { type: 'SP.List' },
855
+ AllowContentTypes: false,
856
+ ContentTypesEnabled: false,
857
+ BaseTemplate: info.template,
858
+ BaseType: info.type,
859
+ Description: info.description,
860
+ Title: info.title
861
+ };
862
+ let newList = (yield (0, rest_1.GetJson)(url, (0, _dependencies_1.jsonStringify)(body))).d;
863
+ (0, _dependencies_1.normalizeGuid)(newList.Id);
864
+ return newList;
865
+ });
866
+ }
867
+ exports.CreateList = CreateList;
868
+ //# sourceMappingURL=list.js.map