@kwiz/common 1.0.105 → 1.0.106

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 (106) hide show
  1. package/.github/workflows/npm-publish.yml +24 -24
  2. package/.madgerc +2 -2
  3. package/LICENSE +21 -21
  4. package/fix-folder-imports.js +26 -26
  5. package/lib/cjs/helpers/browser.js +26 -1
  6. package/lib/cjs/helpers/browser.js.map +1 -1
  7. package/lib/cjs/types/libs/msal.types.js +26 -26
  8. package/lib/cjs/utils/date.js +139 -1
  9. package/lib/cjs/utils/date.js.map +1 -1
  10. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  11. package/lib/esm/helpers/browser.js +24 -0
  12. package/lib/esm/helpers/browser.js.map +1 -1
  13. package/lib/esm/types/libs/msal.types.js +26 -26
  14. package/lib/esm/utils/date.js +137 -0
  15. package/lib/esm/utils/date.js.map +1 -1
  16. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  17. package/lib/types/helpers/browser.d.ts +1 -0
  18. package/lib/types/types/locales.d.ts +1 -0
  19. package/lib/types/utils/date.d.ts +1 -0
  20. package/package.json +81 -81
  21. package/readme.md +17 -17
  22. package/src/_dependencies.ts +12 -12
  23. package/src/config.ts +17 -17
  24. package/src/helpers/Guid.ts +181 -181
  25. package/src/helpers/base64.ts +173 -173
  26. package/src/helpers/browser.test.js +13 -13
  27. package/src/helpers/browser.ts +1428 -1428
  28. package/src/helpers/browserinfo.ts +292 -292
  29. package/src/helpers/collections.base.test.js +25 -25
  30. package/src/helpers/collections.base.ts +437 -437
  31. package/src/helpers/collections.ts +107 -107
  32. package/src/helpers/color.ts +54 -54
  33. package/src/helpers/cookies.ts +59 -59
  34. package/src/helpers/date.test.js +119 -119
  35. package/src/helpers/date.ts +188 -188
  36. package/src/helpers/debug.ts +186 -186
  37. package/src/helpers/diagrams.ts +43 -43
  38. package/src/helpers/emails.ts +6 -6
  39. package/src/helpers/eval.ts +5 -5
  40. package/src/helpers/file.test.js +50 -50
  41. package/src/helpers/file.ts +63 -63
  42. package/src/helpers/flatted.ts +149 -149
  43. package/src/helpers/functions.ts +16 -16
  44. package/src/helpers/graph/calendar.types.ts +10 -10
  45. package/src/helpers/http.ts +69 -69
  46. package/src/helpers/images.ts +22 -22
  47. package/src/helpers/json.ts +44 -44
  48. package/src/helpers/md5.ts +189 -189
  49. package/src/helpers/objects.test.js +33 -33
  50. package/src/helpers/objects.ts +274 -274
  51. package/src/helpers/promises.test.js +37 -37
  52. package/src/helpers/promises.ts +165 -165
  53. package/src/helpers/random.ts +27 -27
  54. package/src/helpers/scheduler/scheduler.test.js +103 -103
  55. package/src/helpers/scheduler/scheduler.ts +131 -131
  56. package/src/helpers/sharepoint.ts +785 -785
  57. package/src/helpers/strings.test.js +122 -122
  58. package/src/helpers/strings.ts +337 -337
  59. package/src/helpers/typecheckers.test.js +34 -34
  60. package/src/helpers/typecheckers.ts +266 -266
  61. package/src/helpers/url.test.js +43 -43
  62. package/src/helpers/url.ts +207 -207
  63. package/src/helpers/urlhelper.ts +111 -111
  64. package/src/index.ts +6 -6
  65. package/src/types/auth.ts +54 -54
  66. package/src/types/common.types.ts +15 -15
  67. package/src/types/flatted.types.ts +59 -59
  68. package/src/types/globals.types.ts +6 -6
  69. package/src/types/graph/calendar.types.ts +80 -80
  70. package/src/types/knownscript.types.ts +18 -18
  71. package/src/types/libs/datajs.types.ts +28 -28
  72. package/src/types/libs/ics.types.ts +30 -30
  73. package/src/types/libs/msal.types.ts +49 -49
  74. package/src/types/locales.ts +125 -124
  75. package/src/types/localstoragecache.types.ts +8 -8
  76. package/src/types/location.types.ts +27 -27
  77. package/src/types/moment.ts +11 -11
  78. package/src/types/regex.types.ts +16 -16
  79. package/src/types/rest.types.ts +95 -95
  80. package/src/types/sharepoint.types.ts +1466 -1466
  81. package/src/types/sharepoint.utils.types.ts +287 -287
  82. package/src/utils/auth/common.ts +74 -74
  83. package/src/utils/auth/discovery.test.js +12 -12
  84. package/src/utils/auth/discovery.ts +132 -132
  85. package/src/utils/base64.ts +27 -27
  86. package/src/utils/consolelogger.ts +320 -320
  87. package/src/utils/date.ts +172 -172
  88. package/src/utils/emails.ts +24 -24
  89. package/src/utils/knownscript.ts +286 -286
  90. package/src/utils/localstoragecache.ts +446 -446
  91. package/src/utils/rest.ts +501 -501
  92. package/src/utils/script.ts +170 -170
  93. package/src/utils/sharepoint.rest/common.ts +154 -154
  94. package/src/utils/sharepoint.rest/date.ts +62 -62
  95. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  96. package/src/utils/sharepoint.rest/item.ts +547 -547
  97. package/src/utils/sharepoint.rest/list.ts +1481 -1481
  98. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  99. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  100. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  101. package/src/utils/sharepoint.rest/location.ts +141 -141
  102. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  103. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  104. package/src/utils/sharepoint.rest/user.ts +491 -491
  105. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  106. package/src/utils/sod.ts +194 -194
@@ -1,786 +1,786 @@
1
- import { IDictionary } from "../types/common.types";
2
- import { FieldTypeAsString, FieldTypes, IFieldCalculatedInfo, IFieldInfo, IFieldInfoEX, IFieldJsonSchema, IFieldTaxonomyInfo, PrincipalType, RententionLabelFieldValueType, SPBasePermissionKind, ThumbnailValueType, UrlValueType } from "../types/sharepoint.types";
3
- import { UserEntityValueType } from "../types/sharepoint.utils.types";
4
- import { waitFor, waitForWindowObject } from "./browser";
5
- import { firstOrNull, forEach } from "./collections.base";
6
- import { deleteCookie, getCookie, setCookie } from "./cookies";
7
- import { isValidEmail } from "./emails";
8
- import { jsonParse } from "./json";
9
- import { hasOwnProperty } from "./objects";
10
- import { isValidDomainLogin, normalizeGuid } from "./strings";
11
- import { isNotEmptyArray, isNullOrEmptyString, isNullOrNaN, isNullOrUndefined, isNumber, isNumeric, isString, isTypeofFullNameNullOrUndefined, isTypeofFullNameUndefined, isUndefined, isValidGuid } from "./typecheckers";
12
- import { makeServerRelativeUrl, normalizeUrl } from "./url";
13
-
14
- export const KWIZ_CONTROLLER_FIELD_NAME = "kwizcomcontrollerfield";
15
- const MODERN_EXPERIENCE_COOKIE_NAME = "splnu";
16
- const MODERN_EXPERIENCE_TEMP_COOKIE_NAME = `${MODERN_EXPERIENCE_COOKIE_NAME}_kwizcom_original`;
17
- const MOBILE_EXPERIENCE_COOKIE_NAME = "mobile";
18
- const MOBILE_EXPERIENCE_TEMP_COOKIE_NAME = `${MOBILE_EXPERIENCE_COOKIE_NAME}_kwizcom_original`;
19
-
20
- //const logger = ConsoleLogger.get("_modules/helpers/sharepoint");
21
- export function IsClassicPage() {
22
- //on premises has g_spribbon but no g_Workspace
23
- //can't use g_spribbon because it gets created whenever you load the init.js script
24
- if (!isUndefined(window)
25
- && window.document
26
- && document.body
27
- && document.body.childNodes.length
28
- && document.body.childNodes) {
29
- //only classic pages have the s4-workspace element, so try this first because it is the most reliable
30
- return !!document.getElementById("s4-workspace");
31
- } else if (!isUndefined((<any>window)._spWebPartComponents)) {
32
- //only classic pages have the _spWebPartComponents object created on the page inline, not in a script that
33
- //can be loaded
34
- return true;
35
- } else if (!isUndefined((<any>window)._spClientSideComponentIds)) {
36
- //only modern pages have the _spClientSideComponentIds object created on the page inline, not a in script that
37
- //can be loaded
38
- return false;
39
- } else if (!isUndefined((<any>window).g_Workspace)) {
40
- //online has g_Workspace
41
- return true;
42
- } else {
43
- return false;
44
- }
45
- }
46
-
47
- export function restoreExperience() {
48
- var splnu_original = getCookie(MODERN_EXPERIENCE_TEMP_COOKIE_NAME);
49
- deleteCookie(MODERN_EXPERIENCE_TEMP_COOKIE_NAME);
50
- deleteCookie(MODERN_EXPERIENCE_COOKIE_NAME);
51
-
52
- if (isString(splnu_original)) {
53
- setCookie(MODERN_EXPERIENCE_COOKIE_NAME, splnu_original);
54
- }
55
-
56
- var mobile_original = getCookie(MOBILE_EXPERIENCE_TEMP_COOKIE_NAME);
57
- deleteCookie(MOBILE_EXPERIENCE_TEMP_COOKIE_NAME);
58
- deleteCookie(MOBILE_EXPERIENCE_COOKIE_NAME);
59
-
60
- if (isString(mobile_original)) {
61
- setCookie(MOBILE_EXPERIENCE_COOKIE_NAME, mobile_original, null, "/");
62
- }
63
- }
64
-
65
- export function ensureClassicExperience(listId: string) {
66
- var splnu = getCookie(MODERN_EXPERIENCE_COOKIE_NAME);
67
- var mobile = getCookie(MOBILE_EXPERIENCE_COOKIE_NAME);
68
- if (isString(splnu)) {
69
- setCookie(MODERN_EXPERIENCE_TEMP_COOKIE_NAME, splnu);
70
- }
71
- if (isString(mobile)) {
72
- setCookie(MOBILE_EXPERIENCE_TEMP_COOKIE_NAME, splnu);
73
- }
74
- setCookie(MOBILE_EXPERIENCE_COOKIE_NAME, "0", null, "/");
75
- switchToClassicExperience(listId);
76
- }
77
-
78
- export function setExperienceCookie(value: string, reload?: boolean) {
79
- setCookie(MODERN_EXPERIENCE_COOKIE_NAME, value);
80
- if (reload === true) {
81
- window.location.reload();
82
- }
83
- }
84
-
85
- export function switchToClassicExperience(listId: string, reload?: boolean) {
86
- setExperienceCookie(listId ? `{${normalizeGuid(listId)}}` : "0", reload);
87
- }
88
-
89
- export function switchToModernExperience(reload?: boolean) {
90
- setExperienceCookie("1", reload);
91
- }
92
-
93
- /** Gets field schema XML and converts it into JSON object */
94
- export function SchemaXmlToJson(xml: string): IFieldJsonSchema {
95
- let result: IFieldJsonSchema = { Attributes: {}, Customizations: {} };
96
- try {
97
- if (!isNullOrEmptyString(xml !== null)) {
98
- //IE9+ supports this, we don't need to support IE8 anymore
99
- let SchemaXmlDoc: Document = new DOMParser().parseFromString(xml, "text/xml");
100
- let xField = SchemaXmlDoc.getElementsByTagName("Field")[0];
101
- for (var i = 0; i < xField.attributes.length; i++) {
102
- result.Attributes[xField.attributes[i].name] = xField.attributes[i].value;
103
- }
104
-
105
- let properties = xField.querySelectorAll("Customization>ArrayOfProperty>Property");
106
- if (properties && properties.length > 0) {
107
- properties.forEach(p => {
108
- let name = p.querySelector("Name");
109
- let value = p.querySelector("Value");
110
- if (name && value && !isNullOrEmptyString(name.textContent))
111
- result.Customizations[name.textContent] = value.textContent;
112
- });
113
- }
114
- }
115
- } catch (e) { }
116
- return result;
117
- }
118
- export function SchemaJsonToXml(json: IFieldJsonSchema): string {
119
- let doc = new Document();
120
- let fieldElm = doc.createElement("Field");
121
- forEach(json.Attributes, (name, value) => {
122
- fieldElm.setAttribute(name, value);
123
- });
124
- if (Object.keys(json.Customizations).length) {
125
- let custElm = doc.createElement("Customization");
126
- fieldElm.appendChild(custElm);
127
- let arrElm = doc.createElement("ArrayOfProperty");
128
- custElm.appendChild(arrElm);
129
- forEach(json.Customizations, (name, value) => {
130
- let propElm = doc.createElement("Property");
131
- arrElm.appendChild(propElm);
132
-
133
- let nameElm = doc.createElement("Name");
134
- propElm.appendChild(nameElm);
135
- let valElm = doc.createElement("Value");
136
- propElm.appendChild(valElm);
137
- nameElm.textContent = name;
138
- valElm.textContent = value;
139
- });
140
- }
141
- if (isNotEmptyArray(json["Choices"])) {
142
- let choices = doc.createElement("CHOICES");
143
- fieldElm.appendChild(choices);
144
- json["Choices"].forEach(c => {
145
- let choice = doc.createElement("CHOICE");
146
- choice.textContent = c;
147
- choices.appendChild(choice);
148
- });
149
- }
150
- return fieldElm.outerHTML;
151
- }
152
-
153
- export function NormalizeListName(list: { EntityTypeName: string; BaseType: number; }): string {
154
- let Name = list.EntityTypeName;//get list name. if it is a list, it will be [Name]List so cut the list out.
155
- try {
156
- if (list.BaseType === 0 && Name.endsWith("List"))
157
- Name = Name.substr(0, Name.length - 4);//remove List
158
- } catch (e) { }
159
- return Name;
160
- }
161
-
162
- export class SPBasePermissions {
163
- private $High = 0;
164
- private $Low = 0;
165
- public constructor(EffectiveBasePermissions: { High: number; Low: number; }) {
166
- this.initPropertiesFromJson(EffectiveBasePermissions);
167
- }
168
- public set(perm: SPBasePermissionKind) {
169
- if (perm === SPBasePermissionKind.FullMask) {
170
- this.$Low = 65535;
171
- this.$High = 32767;
172
- return;
173
- }
174
-
175
- if (!perm) {
176
- this.$Low = 0;
177
- this.$High = 0;
178
- return;
179
- }
180
- var $v_0 = perm;
181
-
182
- $v_0 = $v_0 - 1;
183
- var $v_1 = 1;
184
-
185
- if ($v_0 >= 0 && $v_0 < 32) {
186
- $v_1 = $v_1 << $v_0;
187
- this.$Low = this.$Low | $v_1;
188
- }
189
- else if ($v_0 >= 32 && $v_0 < 64) {
190
- $v_1 = $v_1 << $v_0 - 32;
191
- this.$High = this.$High | $v_1;
192
- }
193
- }
194
- public clear(perm) {
195
- var $v_0 = perm;
196
-
197
- $v_0 = $v_0 - 1;
198
- var $v_1 = 1;
199
-
200
- if ($v_0 >= 0 && $v_0 < 32) {
201
- $v_1 = $v_1 << $v_0;
202
- $v_1 = ~$v_1;
203
- this.$Low = this.$Low & $v_1;
204
- }
205
- else if ($v_0 >= 32 && $v_0 < 64) {
206
- $v_1 = $v_1 << $v_0 - 32;
207
- $v_1 = ~$v_1;
208
- this.$High = this.$High & $v_1;
209
- }
210
- }
211
- public clearAll() {
212
- this.$High = 0;
213
- this.$Low = 0;
214
- }
215
- public has(perm: SPBasePermissionKind) {
216
- if (!perm) {
217
- return true;
218
- }
219
- if (perm === SPBasePermissionKind.FullMask) {
220
- return (this.$High & 32767) === 32767 && this.$Low === 65535;
221
- }
222
- var $v_0 = perm;
223
-
224
- $v_0 = $v_0 - 1;
225
- var $v_1 = 1;
226
-
227
- if ($v_0 >= 0 && $v_0 < 32) {
228
- $v_1 = $v_1 << $v_0;
229
- return 0 !== (this.$Low & $v_1);
230
- }
231
- else if ($v_0 >= 32 && $v_0 < 64) {
232
- $v_1 = $v_1 << $v_0 - 32;
233
- return 0 !== (this.$High & $v_1);
234
- }
235
- return false;
236
- }
237
- public hasAny(...requestedPerms: SPBasePermissionKind[]) {
238
- return (requestedPerms || []).some((t) => {
239
- return this.has(t);
240
- });
241
- }
242
- public haAll(...requestedPerms: SPBasePermissionKind[]) {
243
- return (requestedPerms || []).every((t) => {
244
- return this.has(t);
245
- });
246
- }
247
- public hasPermissions(requestedPerms: { High: number; Low: number; }) {
248
- return (this.$High & requestedPerms.High) === requestedPerms.High && (this.$Low & requestedPerms.Low) === requestedPerms.Low;
249
- }
250
- public hasAnyPermissions(...requestedPerms: { High: number; Low: number; }[]) {
251
- return (requestedPerms || []).some((t) => {
252
- return this.hasPermissions(t);
253
- });
254
- }
255
- public hasAllPermissions(...requestedPerms: { High: number; Low: number; }[]) {
256
- return (requestedPerms || []).every((t) => {
257
- return this.hasPermissions(t);
258
- });
259
- }
260
- public initPropertiesFromJson(EffectiveBasePermissions: { High: number; Low: number; }) {
261
- this.$High = 0;
262
- this.$Low = 0;
263
- if (isNullOrUndefined(EffectiveBasePermissions)) return;
264
-
265
- if (!isNullOrNaN(EffectiveBasePermissions.High)) {
266
- this.$High = EffectiveBasePermissions.High;
267
- }
268
- if (!isNullOrNaN(EffectiveBasePermissions.Low)) {
269
- this.$Low = EffectiveBasePermissions.Low;
270
- }
271
- }
272
- }
273
-
274
- export interface ISPPeoplePickerControlFormEntity {
275
- /** ie: i:0#.f|membership|user@kwizcom.com */
276
- Key: string;
277
- EntityType: "FormsRole" | "SecGroup" | "SPGroup";
278
- EntityData?: {
279
- SPGroupID?: string;
280
- PrincipalType?: "User" | "SecurityGroup" | "SharePointGroup";
281
- /** string of number "8" */
282
- SPUserID?: string;
283
- SIPAddress?: string;
284
- Email?: string;
285
- };
286
- Resolved?: boolean;
287
- }
288
-
289
- /** remove i:0#.f|membership| prefix from login */
290
- export function CleanupUserClaimsLogin(login: string) {
291
- if (login.indexOf('|membership|') >= 0)
292
- return login.slice(login.lastIndexOf('|') + 1);
293
- else return login;
294
- }
295
-
296
- export function IsSPPeoplePickerControlFormEntity(entity: any): entity is ISPPeoplePickerControlFormEntity {
297
- let asType = entity as ISPPeoplePickerControlFormEntity;
298
- return !isNullOrUndefined(entity)
299
- && !isNullOrEmptyString(asType.Key)
300
- && (!isNullOrUndefined(asType.EntityData) || !isNullOrUndefined(asType.Resolved));
301
- }
302
-
303
- export function getPrincipalTypeFromPickerEntity(entity: ISPPeoplePickerControlFormEntity): PrincipalType.SecurityGroup | PrincipalType.SharePointGroup | PrincipalType.User {
304
- if (entity.EntityType === "FormsRole"
305
- || entity.EntityType === "SecGroup"
306
- || entity.EntityData && entity.EntityData.PrincipalType === "SecurityGroup") {
307
- return PrincipalType.SecurityGroup;
308
- }
309
-
310
- if (entity.EntityType === "SPGroup"
311
- || entity.EntityData && (isNumeric(entity.EntityData.SPGroupID) || entity.EntityData.PrincipalType === "SharePointGroup")) {
312
- return PrincipalType.SharePointGroup;
313
- }
314
-
315
- if (entity.EntityType === "User" || entity.EntityType === "" && entity.EntityData && entity.EntityData.PrincipalType === "User") {
316
- if (entity.EntityData && isValidEmail(entity.EntityData.Email) || isString(entity.EntityData.SIPAddress)) {
317
- return PrincipalType.User;
318
- }
319
-
320
- var keyparts = entity.Key.split("|");
321
- if (keyparts.length === 3 && isValidEmail(keyparts[keyparts.length - 1])) {
322
- //sharepoint online key for a user is in the form xxxx|membership|email;
323
- return PrincipalType.User;
324
- } else if (keyparts.length === 2 && isValidDomainLogin(keyparts[keyparts.length - 1])) {
325
- //sharepoint onpremise key for a user is in the form xxxx|domain\\user;
326
- return PrincipalType.User;
327
- } else {
328
- //SharePoint groups on saved classic forms item are shown with EntityType = User but dont have a SIPAddress/Email
329
- //and the key does not contain a valid domain login/email
330
- return PrincipalType.SharePointGroup;
331
- }
332
- }
333
-
334
- return PrincipalType.User;
335
- }
336
-
337
- /** rest object might put array values under ".results", this will place them at the property value directly */
338
- export function NormalizeRestObject<T>(o: T): T {
339
- //extract collections such as choice field "choices"
340
- if (o) {
341
- Object.keys(o as any).forEach(key => {
342
- if (!isNullOrUndefined(o[key]) && hasOwnProperty(o[key], "results") && Array.isArray(o[key].results))
343
- o[key] = o[key].results;
344
- });
345
- }
346
- return o;
347
- }
348
-
349
- /**
350
- * Extends a field info into field info EX (adding SchemaJson)
351
- * @param field REST field data
352
- * @param allFields Optional - all list fields, used for discovering multi TaxonomyField's update hidden text field
353
- */
354
- export function extendFieldInfo(field: IFieldInfo, allFields?: IFieldInfo[]): IFieldInfoEX {
355
- let fieldEx = field as IFieldInfoEX;
356
- fieldEx.Id = normalizeGuid(field.Id);
357
-
358
- if (field.InternalName === "ContentType") {
359
- fieldEx.Required = true;
360
- }
361
- else {
362
- switch (fieldEx.TypeAsString) {
363
- case "TaxonomyFieldTypeMulti"://find the hidden rich text for updates!
364
- {
365
- let taxonomyField = (fieldEx as IFieldTaxonomyInfo);
366
- let textFieldId = normalizeGuid(taxonomyField.TextField);
367
- let related = isNotEmptyArray(allFields) ? firstOrNull(allFields, relatedField => relatedField.Id === textFieldId) : null;
368
- if (related !== null)
369
- taxonomyField.HiddenMultiValueFieldName = related.InternalName;
370
- }
371
- break;
372
- }
373
- }
374
-
375
- fieldEx.OutputTypeAsString = getFieldOutputType(fieldEx);
376
-
377
- if (isNullOrUndefined(fieldEx.SchemaJson)) {
378
- Object.defineProperty(fieldEx, 'SchemaJson', {
379
- get: function () {
380
- if (isUndefined(this._schemaJson)) {
381
- this._schemaJson = SchemaXmlToJson(this.SchemaXml);
382
- }
383
- return this._schemaJson;
384
- }
385
- });
386
- }
387
-
388
- if (field.InternalName === KWIZ_CONTROLLER_FIELD_NAME) {
389
- //not hidden by SharePoint so its shown in views/forms but as far as our products concerned - should be treated as hidden
390
- field.Hidden = true;
391
- }
392
-
393
- return fieldEx;
394
- }
395
-
396
- export function extendFieldInfos(fields: IFieldInfo[]) {
397
- return fields.map(f => extendFieldInfo(f, fields));
398
- }
399
-
400
- export function getFieldOutputType(field: IFieldInfo) {
401
- let outputType = field.TypeAsString;
402
-
403
- if (outputType === "Calculated") {
404
- switch ((field as IFieldCalculatedInfo).OutputType) {
405
- case FieldTypes.DateTime:
406
- outputType = "DateTime";
407
- break;
408
- case FieldTypes.Boolean:
409
- outputType = "Boolean";
410
- break;
411
- case FieldTypes.Currency:
412
- outputType = "Currency";
413
- break;
414
- case FieldTypes.Number:
415
- outputType = "Number";
416
- break;
417
- default:
418
- outputType = "Text";
419
- break;
420
- }
421
- }
422
-
423
- return outputType as FieldTypeAsString;
424
- }
425
-
426
- export function isDocLib(list?: { BaseType: number; }): boolean {
427
- return list && list.BaseType === 1;
428
- }
429
-
430
- export function GetOrderByFromCaml(camlQuery: string): { Name: string; IsAscending: boolean; }[] {
431
- let xmlDoc = new DOMParser().parseFromString(camlQuery, "text/xml");
432
-
433
- let orderByElm = xmlDoc.querySelector("OrderBy");
434
- let OrderBy: { Name: string; IsAscending: boolean; }[] = [];
435
- if (orderByElm) {
436
- let orderFieldsElms = orderByElm.querySelectorAll("FieldRef");
437
- orderFieldsElms.forEach(f => {
438
- let name = f.getAttribute("Name");
439
- let asc = f.getAttribute("Ascending") || "";
440
- //Issue 1019 default value is true if ommitted - https://learn.microsoft.com/en-us/sharepoint/dev/schema/fieldref-element-query
441
- let IsAscending = asc.toUpperCase() !== "FALSE";
442
- if (!isNullOrEmptyString(name))
443
- OrderBy.push({ Name: name, IsAscending: IsAscending });
444
- });
445
- }
446
-
447
- return OrderBy;
448
- }
449
-
450
- export function RemoveOrderByFromCaml(camlQuery: string): string {
451
- let xmlDoc = new DOMParser().parseFromString(camlQuery, "text/xml");
452
-
453
- let orderByElm = xmlDoc.querySelector("OrderBy");
454
- //let OrderBy: { Name: string; IsAscending: boolean; }[] = [];
455
- if (orderByElm) {
456
- orderByElm.remove();
457
- return xmlDoc.documentElement.outerHTML;
458
- }
459
-
460
- return camlQuery;
461
- }
462
-
463
- export function EnsureViewFields(camlQuery: string, fields: string[], forceCreateViewFields: boolean, removeAllOthers?: boolean) {
464
- let xmlDoc = new DOMParser().parseFromString(camlQuery, "text/xml");
465
- let viewElm = xmlDoc.querySelector("View");
466
- if (!isNullOrUndefined(viewElm)) {
467
- let viewFieldsElm = viewElm.querySelector("ViewFields");
468
-
469
- if (forceCreateViewFields && isNullOrUndefined(viewFieldsElm)) {
470
- viewFieldsElm = xmlDoc.createElement("ViewFields");
471
- viewElm.appendChild(viewFieldsElm);
472
- }
473
-
474
- if (!isNullOrUndefined(viewFieldsElm)) {
475
- let viewFieldsElms = viewFieldsElm.querySelectorAll("FieldRef");
476
-
477
- if (removeAllOthers)
478
- viewFieldsElms.forEach(e => e.remove());
479
-
480
- let viewFields = removeAllOthers ? [] : Array.from(viewFieldsElms).map(viewFieldNode => {
481
- let name = viewFieldNode.getAttribute("Name");
482
- return name.toLowerCase();
483
- });
484
-
485
- let changed = false;
486
- fields.forEach(f => {
487
- if (viewFields.indexOf(f.toLowerCase()) === -1) {
488
- let newViewFieldElm = xmlDoc.createElement("FieldRef");
489
- newViewFieldElm.setAttribute("Name", f);
490
- viewFieldsElm.appendChild(newViewFieldElm);
491
- changed = true;
492
- }
493
- });
494
-
495
- if (viewFieldsElm.querySelectorAll("FieldRef").length < 1 && !forceCreateViewFields) {
496
- //don't leave an empty object
497
- viewFieldsElm.remove();
498
- changed = true;
499
- }
500
-
501
- if (changed) return xmlDoc.documentElement.outerHTML;
502
- }
503
- }
504
-
505
- return camlQuery;
506
- }
507
-
508
- /**If it is a thumbnail field - parse and return a typed value */
509
- export function ParseThumbnalFieldValue(value?: string, context?: {
510
- itemId: number;
511
- rootFolder: string;
512
- }): ThumbnailValueType {
513
- if (!isNullOrEmptyString(value)) {
514
- try {
515
- let parsed = jsonParse<ThumbnailValueType>(value);
516
-
517
- if (isNullOrUndefined(parsed)) {
518
- return null;
519
- }
520
-
521
- if (!isNullOrEmptyString(parsed.serverRelativeUrl)) {
522
- return parsed;
523
- } else if (!isNullOrEmptyString(parsed.fileName)
524
- && !isNullOrUndefined(context)
525
- && isNumber(context.itemId)
526
- && !isNullOrEmptyString(context.rootFolder)) {
527
- let { itemId, rootFolder } = context;
528
- parsed.serverRelativeUrl = `${makeServerRelativeUrl(rootFolder)}/Attachments/${itemId}/${parsed.fileName}`
529
- return parsed;
530
- }
531
- } catch (e) {
532
- }
533
- }
534
- return null;
535
- }
536
-
537
- export function isTitleField(fieldName: string) {
538
- return fieldName === "Title" || fieldName === "LinkTitleNoMenu" || fieldName === "LinkTitle";
539
- }
540
-
541
- /** we are on a list view page, not a web part page with possible multiple list views */
542
- export function isSingleViewPage() {
543
- return !isNullOrUndefined(_spPageContextInfo) && isValidGuid(_spPageContextInfo.viewId);
544
- }
545
-
546
- /**
547
- * Splits the ViewFields of a CAML query into separate entries based on the batch size.
548
- * @param {string} camlQuery - The CAML query string.
549
- * @param {number} batchSize - The size of each batch (number of ViewFields per entry).
550
- */
551
- export function splitViewFieldsByBatch(camlQuery: string, allListFieldsToLowerHash: IDictionary<IFieldInfoEX>, batchSize: number): string[] {
552
- let xmlDoc = new DOMParser().parseFromString(camlQuery, 'text/xml');
553
- let viewNode = xmlDoc.querySelector("View, view");
554
- let viewFieldsNode = viewNode && viewNode.querySelector("ViewFields, viewfields");
555
-
556
- if (isNullOrUndefined(viewFieldsNode)) {
557
- return [camlQuery]; // No ViewFields element found, return the original query as is
558
- }
559
-
560
- let viewFieldNodes = Array.from(viewFieldsNode.children);
561
- let numberOfEntries = Math.ceil(viewFieldNodes.length / batchSize);
562
-
563
- let splitQueries: string[] = [];
564
- for (let i = 0; i < numberOfEntries; i++) {
565
- let startIndex = i * batchSize;
566
- let endIndex = startIndex + batchSize;
567
- let slicedViewFields = viewFieldNodes.slice(startIndex, endIndex);
568
-
569
- let clonedXmlDoc = xmlDoc.cloneNode(true) as XMLDocument;
570
- let clonedViewFieldsElement = clonedXmlDoc.getElementsByTagName('ViewFields')[0];
571
-
572
- // Remove existing child nodes from cloned ViewFields
573
- while (clonedViewFieldsElement.firstChild) {
574
- clonedViewFieldsElement.removeChild(clonedViewFieldsElement.firstChild);
575
- }
576
-
577
- // Append sliced ViewFields to cloned ViewFields
578
- for (let slicedViewField of slicedViewFields) {
579
- clonedViewFieldsElement.appendChild(slicedViewField.cloneNode(true));
580
- }
581
-
582
- let splitQuery = new XMLSerializer().serializeToString(clonedXmlDoc);
583
- splitQueries.push(splitQuery);
584
- }
585
-
586
- return splitQueries;
587
- }
588
-
589
- /** Size=S = 48×48 px, M = 72×72 px, L = 300×300 px */
590
- export function UserPhoto(siteUrl: string, userName: string, size: "S" | "M" | "L" = "L") {
591
- return `${normalizeUrl(siteUrl)}/_layouts/15/userphoto.aspx?size=${size}&accountname=${encodeURIComponent(userName)}`;
592
- }
593
-
594
- export function IsFolderContentType(contentTypeId: string) {
595
- //item:0x0100
596
- //file:0x0101
597
- //folder:0x0120
598
- //item in MS Lists:0x00 Issue 7121
599
- return contentTypeId.startsWith("0x0120");
600
- }
601
-
602
- export enum PageContainerTypes {
603
- M365SPFx, M365OOBListForm,
604
- SP2019SPFx, SP2019ListForm
605
- }
606
- export function GetModernPageContainers() {
607
- let mainContent: HTMLElement = document.querySelector("section.mainContent");
608
- if (mainContent)
609
- return { mainContent, commandBar: document.querySelector(".commandBarWrapper") as HTMLElement, type: PageContainerTypes.M365SPFx };
610
-
611
- mainContent = document.querySelector("div[class^=canvasWrapper]");//document.querySelector("div.SPCanvas");
612
- if (mainContent)
613
- return { mainContent, commandBar: document.querySelector(".commandBarWrapper") as HTMLElement, type: PageContainerTypes.SP2019SPFx };
614
-
615
- mainContent = document.querySelector(".flex-mainColumn");
616
- if (mainContent)
617
- return { mainContent, commandBar: null, type: PageContainerTypes.M365OOBListForm };
618
-
619
- mainContent = document.querySelector(".Files-mainColumn");
620
- if (mainContent)
621
- return { mainContent, commandBar: null, type: PageContainerTypes.SP2019ListForm };
622
-
623
- return { mainContent: null, commandBar: null, type: PageContainerTypes.SP2019ListForm };
624
- }
625
-
626
- export function AddCamlQueryFragmentToViewQuery(viewXml: string, queryFragmentXml: string): string {
627
-
628
- const combineWithExistingConditions = (doc: XMLDocument, existingConditions: Element[], newConditionXml: string): Element => {
629
- const parser = new DOMParser();
630
- const newConditionDoc = parser.parseFromString(newConditionXml, 'text/xml');
631
- const newCondition = doc.importNode(newConditionDoc.documentElement, true);
632
-
633
- if (existingConditions.length === 0) {
634
- return newCondition;
635
- } else if (existingConditions.length === 1) {
636
- const andElement = doc.createElement("And");
637
- andElement.appendChild(existingConditions[0]);
638
- andElement.appendChild(newCondition);
639
- return andElement;
640
- } else {
641
- const lastCondition = existingConditions.pop();
642
- const andElement = doc.createElement("And");
643
- andElement.appendChild(combineWithExistingConditions(doc, existingConditions, ""));
644
- andElement.appendChild(lastCondition);
645
- return andElement;
646
- }
647
- }
648
- try {
649
- const parser = new DOMParser();
650
- const xmlDoc = parser.parseFromString(viewXml, 'text/xml');
651
- const whereClause = xmlDoc.querySelector('Where') || xmlDoc.createElement('Where');
652
- const existingConditions = Array.from(whereClause.children);
653
-
654
- const combinedCondition = combineWithExistingConditions(xmlDoc, existingConditions, queryFragmentXml);
655
- whereClause.textContent = ''; // Clear existing conditions
656
- whereClause.appendChild(combinedCondition);
657
-
658
- const query = xmlDoc.querySelector('Query') || xmlDoc.createElement('Query');
659
- query.appendChild(whereClause);
660
-
661
- const view = xmlDoc.querySelector('View') || xmlDoc.createElement('View');
662
- view.appendChild(query);
663
-
664
- const serializer = new XMLSerializer();
665
- let modifiedCamlXml = serializer.serializeToString(xmlDoc);
666
-
667
- return modifiedCamlXml;
668
- } catch (error) {
669
- return viewXml;
670
- }
671
- }
672
-
673
- export function IsUserEntityValueType(value: any): value is UserEntityValueType {
674
- if (isNullOrUndefined(value) || isString(value)) {
675
- return false;
676
- }
677
- var asUserEntityValueType = value as UserEntityValueType;
678
- var isEntityValueType =
679
- asUserEntityValueType.principalType === PrincipalType.SharePointGroup
680
- || asUserEntityValueType.principalType === PrincipalType.User
681
- || asUserEntityValueType.principalType === PrincipalType.SecurityGroup;
682
-
683
- return isEntityValueType;
684
- }
685
-
686
- export function IsMultiUserEntityValueType(value: any[]): value is UserEntityValueType[] {
687
- if (isNullOrUndefined(value) || isString(value) || !Array.isArray(value)) {
688
- return false;
689
- }
690
-
691
- return value.every((v) => {
692
- return IsUserEntityValueType(v);
693
- });
694
- }
695
-
696
- export function IsUrlValueType(value: any): value is UrlValueType {
697
- if (isNullOrUndefined(value) || isString(value)) {
698
- return false;
699
- }
700
- let asType = value as UrlValueType;
701
- return !isNullOrUndefined(asType.Url) && !isNullOrUndefined(asType.Description);
702
- }
703
-
704
- export function IsRetentionLabelValueType(value: any): value is RententionLabelFieldValueType {
705
- if (isNullOrUndefined(value) || isString(value)) {
706
- return false;
707
- }
708
- let asType = value as RententionLabelFieldValueType;
709
- return isValidGuid(asType.TagId) && !isNullOrEmptyString(asType.TagName);
710
- }
711
-
712
- export function isHostedInTeams() {
713
- return window.location.pathname.toLowerCase().indexOf("teamshostedapp.aspx") >= 0;
714
- }
715
- export function isClassicAppIframe() {
716
- return window.location.search.toLowerCase().indexOf("sphosturl=") >= 0 &&
717
- window.location.search.toLowerCase().indexOf("spappweburl=") >= 0;
718
- }
719
-
720
- export function isNumberFieldType(fieldInfo: IFieldInfoEX) {
721
- let targetColumnOutputType = getFieldOutputType(fieldInfo);
722
- return targetColumnOutputType === "Currency"
723
- || targetColumnOutputType === "Number"
724
- || targetColumnOutputType === "Counter"
725
- || targetColumnOutputType === "Integer";
726
- }
727
-
728
- export async function isSharePointOnline() {
729
- let url = new URL(window.location.href);
730
- //Most cases are satisfied by this check. Very few customers have custom domains for SharePoint online.
731
- if (url.host.toLowerCase().endsWith(".sharepoint.com")) {
732
- return true;
733
- }
734
-
735
- let contextReady = await waitFor(() => {
736
- return !isTypeofFullNameUndefined("_spPageContextInfo");
737
- });
738
-
739
- if (contextReady) {
740
- return _spPageContextInfo.isSPO === true;
741
- }
742
-
743
- return false;
744
- }
745
-
746
- export function isSharePointOnlineSync() {
747
- let url = new URL(window.location.href);
748
- //Most cases are satisfied by this check. Very few customers have custom domains for SharePoint online.
749
- if (url.host.toLowerCase().endsWith(".sharepoint.com")) {
750
- return true;
751
- }
752
-
753
- if (!isTypeofFullNameUndefined("_spPageContextInfo")) {
754
- return _spPageContextInfo.isSPO === true;
755
- }
756
-
757
- return false;
758
- }
759
-
760
- export async function isAppWeb() {
761
- let contextReady = await waitFor(() => {
762
- return !isTypeofFullNameUndefined("_spPageContextInfo");
763
- });
764
-
765
- if (contextReady) {
766
- return _spPageContextInfo.isAppWeb === true;
767
- }
768
-
769
- return false;
770
- }
771
-
772
- export function isAppWebSync() {
773
- if (!isTypeofFullNameUndefined("_spPageContextInfo")) {
774
- return _spPageContextInfo.isAppWeb === true;
775
- }
776
-
777
- return false;
778
- }
779
-
780
- export async function isSPPageContextInfoReady() {
781
- return await waitForWindowObject("_spPageContextInfo");
782
- }
783
-
784
- export function isSPPageContextInfoReadySync() {
785
- return !isTypeofFullNameNullOrUndefined("_spPageContextInfo");
1
+ import { IDictionary } from "../types/common.types";
2
+ import { FieldTypeAsString, FieldTypes, IFieldCalculatedInfo, IFieldInfo, IFieldInfoEX, IFieldJsonSchema, IFieldTaxonomyInfo, PrincipalType, RententionLabelFieldValueType, SPBasePermissionKind, ThumbnailValueType, UrlValueType } from "../types/sharepoint.types";
3
+ import { UserEntityValueType } from "../types/sharepoint.utils.types";
4
+ import { waitFor, waitForWindowObject } from "./browser";
5
+ import { firstOrNull, forEach } from "./collections.base";
6
+ import { deleteCookie, getCookie, setCookie } from "./cookies";
7
+ import { isValidEmail } from "./emails";
8
+ import { jsonParse } from "./json";
9
+ import { hasOwnProperty } from "./objects";
10
+ import { isValidDomainLogin, normalizeGuid } from "./strings";
11
+ import { isNotEmptyArray, isNullOrEmptyString, isNullOrNaN, isNullOrUndefined, isNumber, isNumeric, isString, isTypeofFullNameNullOrUndefined, isTypeofFullNameUndefined, isUndefined, isValidGuid } from "./typecheckers";
12
+ import { makeServerRelativeUrl, normalizeUrl } from "./url";
13
+
14
+ export const KWIZ_CONTROLLER_FIELD_NAME = "kwizcomcontrollerfield";
15
+ const MODERN_EXPERIENCE_COOKIE_NAME = "splnu";
16
+ const MODERN_EXPERIENCE_TEMP_COOKIE_NAME = `${MODERN_EXPERIENCE_COOKIE_NAME}_kwizcom_original`;
17
+ const MOBILE_EXPERIENCE_COOKIE_NAME = "mobile";
18
+ const MOBILE_EXPERIENCE_TEMP_COOKIE_NAME = `${MOBILE_EXPERIENCE_COOKIE_NAME}_kwizcom_original`;
19
+
20
+ //const logger = ConsoleLogger.get("_modules/helpers/sharepoint");
21
+ export function IsClassicPage() {
22
+ //on premises has g_spribbon but no g_Workspace
23
+ //can't use g_spribbon because it gets created whenever you load the init.js script
24
+ if (!isUndefined(window)
25
+ && window.document
26
+ && document.body
27
+ && document.body.childNodes.length
28
+ && document.body.childNodes) {
29
+ //only classic pages have the s4-workspace element, so try this first because it is the most reliable
30
+ return !!document.getElementById("s4-workspace");
31
+ } else if (!isUndefined((<any>window)._spWebPartComponents)) {
32
+ //only classic pages have the _spWebPartComponents object created on the page inline, not in a script that
33
+ //can be loaded
34
+ return true;
35
+ } else if (!isUndefined((<any>window)._spClientSideComponentIds)) {
36
+ //only modern pages have the _spClientSideComponentIds object created on the page inline, not a in script that
37
+ //can be loaded
38
+ return false;
39
+ } else if (!isUndefined((<any>window).g_Workspace)) {
40
+ //online has g_Workspace
41
+ return true;
42
+ } else {
43
+ return false;
44
+ }
45
+ }
46
+
47
+ export function restoreExperience() {
48
+ var splnu_original = getCookie(MODERN_EXPERIENCE_TEMP_COOKIE_NAME);
49
+ deleteCookie(MODERN_EXPERIENCE_TEMP_COOKIE_NAME);
50
+ deleteCookie(MODERN_EXPERIENCE_COOKIE_NAME);
51
+
52
+ if (isString(splnu_original)) {
53
+ setCookie(MODERN_EXPERIENCE_COOKIE_NAME, splnu_original);
54
+ }
55
+
56
+ var mobile_original = getCookie(MOBILE_EXPERIENCE_TEMP_COOKIE_NAME);
57
+ deleteCookie(MOBILE_EXPERIENCE_TEMP_COOKIE_NAME);
58
+ deleteCookie(MOBILE_EXPERIENCE_COOKIE_NAME);
59
+
60
+ if (isString(mobile_original)) {
61
+ setCookie(MOBILE_EXPERIENCE_COOKIE_NAME, mobile_original, null, "/");
62
+ }
63
+ }
64
+
65
+ export function ensureClassicExperience(listId: string) {
66
+ var splnu = getCookie(MODERN_EXPERIENCE_COOKIE_NAME);
67
+ var mobile = getCookie(MOBILE_EXPERIENCE_COOKIE_NAME);
68
+ if (isString(splnu)) {
69
+ setCookie(MODERN_EXPERIENCE_TEMP_COOKIE_NAME, splnu);
70
+ }
71
+ if (isString(mobile)) {
72
+ setCookie(MOBILE_EXPERIENCE_TEMP_COOKIE_NAME, splnu);
73
+ }
74
+ setCookie(MOBILE_EXPERIENCE_COOKIE_NAME, "0", null, "/");
75
+ switchToClassicExperience(listId);
76
+ }
77
+
78
+ export function setExperienceCookie(value: string, reload?: boolean) {
79
+ setCookie(MODERN_EXPERIENCE_COOKIE_NAME, value);
80
+ if (reload === true) {
81
+ window.location.reload();
82
+ }
83
+ }
84
+
85
+ export function switchToClassicExperience(listId: string, reload?: boolean) {
86
+ setExperienceCookie(listId ? `{${normalizeGuid(listId)}}` : "0", reload);
87
+ }
88
+
89
+ export function switchToModernExperience(reload?: boolean) {
90
+ setExperienceCookie("1", reload);
91
+ }
92
+
93
+ /** Gets field schema XML and converts it into JSON object */
94
+ export function SchemaXmlToJson(xml: string): IFieldJsonSchema {
95
+ let result: IFieldJsonSchema = { Attributes: {}, Customizations: {} };
96
+ try {
97
+ if (!isNullOrEmptyString(xml !== null)) {
98
+ //IE9+ supports this, we don't need to support IE8 anymore
99
+ let SchemaXmlDoc: Document = new DOMParser().parseFromString(xml, "text/xml");
100
+ let xField = SchemaXmlDoc.getElementsByTagName("Field")[0];
101
+ for (var i = 0; i < xField.attributes.length; i++) {
102
+ result.Attributes[xField.attributes[i].name] = xField.attributes[i].value;
103
+ }
104
+
105
+ let properties = xField.querySelectorAll("Customization>ArrayOfProperty>Property");
106
+ if (properties && properties.length > 0) {
107
+ properties.forEach(p => {
108
+ let name = p.querySelector("Name");
109
+ let value = p.querySelector("Value");
110
+ if (name && value && !isNullOrEmptyString(name.textContent))
111
+ result.Customizations[name.textContent] = value.textContent;
112
+ });
113
+ }
114
+ }
115
+ } catch (e) { }
116
+ return result;
117
+ }
118
+ export function SchemaJsonToXml(json: IFieldJsonSchema): string {
119
+ let doc = new Document();
120
+ let fieldElm = doc.createElement("Field");
121
+ forEach(json.Attributes, (name, value) => {
122
+ fieldElm.setAttribute(name, value);
123
+ });
124
+ if (Object.keys(json.Customizations).length) {
125
+ let custElm = doc.createElement("Customization");
126
+ fieldElm.appendChild(custElm);
127
+ let arrElm = doc.createElement("ArrayOfProperty");
128
+ custElm.appendChild(arrElm);
129
+ forEach(json.Customizations, (name, value) => {
130
+ let propElm = doc.createElement("Property");
131
+ arrElm.appendChild(propElm);
132
+
133
+ let nameElm = doc.createElement("Name");
134
+ propElm.appendChild(nameElm);
135
+ let valElm = doc.createElement("Value");
136
+ propElm.appendChild(valElm);
137
+ nameElm.textContent = name;
138
+ valElm.textContent = value;
139
+ });
140
+ }
141
+ if (isNotEmptyArray(json["Choices"])) {
142
+ let choices = doc.createElement("CHOICES");
143
+ fieldElm.appendChild(choices);
144
+ json["Choices"].forEach(c => {
145
+ let choice = doc.createElement("CHOICE");
146
+ choice.textContent = c;
147
+ choices.appendChild(choice);
148
+ });
149
+ }
150
+ return fieldElm.outerHTML;
151
+ }
152
+
153
+ export function NormalizeListName(list: { EntityTypeName: string; BaseType: number; }): string {
154
+ let Name = list.EntityTypeName;//get list name. if it is a list, it will be [Name]List so cut the list out.
155
+ try {
156
+ if (list.BaseType === 0 && Name.endsWith("List"))
157
+ Name = Name.substr(0, Name.length - 4);//remove List
158
+ } catch (e) { }
159
+ return Name;
160
+ }
161
+
162
+ export class SPBasePermissions {
163
+ private $High = 0;
164
+ private $Low = 0;
165
+ public constructor(EffectiveBasePermissions: { High: number; Low: number; }) {
166
+ this.initPropertiesFromJson(EffectiveBasePermissions);
167
+ }
168
+ public set(perm: SPBasePermissionKind) {
169
+ if (perm === SPBasePermissionKind.FullMask) {
170
+ this.$Low = 65535;
171
+ this.$High = 32767;
172
+ return;
173
+ }
174
+
175
+ if (!perm) {
176
+ this.$Low = 0;
177
+ this.$High = 0;
178
+ return;
179
+ }
180
+ var $v_0 = perm;
181
+
182
+ $v_0 = $v_0 - 1;
183
+ var $v_1 = 1;
184
+
185
+ if ($v_0 >= 0 && $v_0 < 32) {
186
+ $v_1 = $v_1 << $v_0;
187
+ this.$Low = this.$Low | $v_1;
188
+ }
189
+ else if ($v_0 >= 32 && $v_0 < 64) {
190
+ $v_1 = $v_1 << $v_0 - 32;
191
+ this.$High = this.$High | $v_1;
192
+ }
193
+ }
194
+ public clear(perm) {
195
+ var $v_0 = perm;
196
+
197
+ $v_0 = $v_0 - 1;
198
+ var $v_1 = 1;
199
+
200
+ if ($v_0 >= 0 && $v_0 < 32) {
201
+ $v_1 = $v_1 << $v_0;
202
+ $v_1 = ~$v_1;
203
+ this.$Low = this.$Low & $v_1;
204
+ }
205
+ else if ($v_0 >= 32 && $v_0 < 64) {
206
+ $v_1 = $v_1 << $v_0 - 32;
207
+ $v_1 = ~$v_1;
208
+ this.$High = this.$High & $v_1;
209
+ }
210
+ }
211
+ public clearAll() {
212
+ this.$High = 0;
213
+ this.$Low = 0;
214
+ }
215
+ public has(perm: SPBasePermissionKind) {
216
+ if (!perm) {
217
+ return true;
218
+ }
219
+ if (perm === SPBasePermissionKind.FullMask) {
220
+ return (this.$High & 32767) === 32767 && this.$Low === 65535;
221
+ }
222
+ var $v_0 = perm;
223
+
224
+ $v_0 = $v_0 - 1;
225
+ var $v_1 = 1;
226
+
227
+ if ($v_0 >= 0 && $v_0 < 32) {
228
+ $v_1 = $v_1 << $v_0;
229
+ return 0 !== (this.$Low & $v_1);
230
+ }
231
+ else if ($v_0 >= 32 && $v_0 < 64) {
232
+ $v_1 = $v_1 << $v_0 - 32;
233
+ return 0 !== (this.$High & $v_1);
234
+ }
235
+ return false;
236
+ }
237
+ public hasAny(...requestedPerms: SPBasePermissionKind[]) {
238
+ return (requestedPerms || []).some((t) => {
239
+ return this.has(t);
240
+ });
241
+ }
242
+ public haAll(...requestedPerms: SPBasePermissionKind[]) {
243
+ return (requestedPerms || []).every((t) => {
244
+ return this.has(t);
245
+ });
246
+ }
247
+ public hasPermissions(requestedPerms: { High: number; Low: number; }) {
248
+ return (this.$High & requestedPerms.High) === requestedPerms.High && (this.$Low & requestedPerms.Low) === requestedPerms.Low;
249
+ }
250
+ public hasAnyPermissions(...requestedPerms: { High: number; Low: number; }[]) {
251
+ return (requestedPerms || []).some((t) => {
252
+ return this.hasPermissions(t);
253
+ });
254
+ }
255
+ public hasAllPermissions(...requestedPerms: { High: number; Low: number; }[]) {
256
+ return (requestedPerms || []).every((t) => {
257
+ return this.hasPermissions(t);
258
+ });
259
+ }
260
+ public initPropertiesFromJson(EffectiveBasePermissions: { High: number; Low: number; }) {
261
+ this.$High = 0;
262
+ this.$Low = 0;
263
+ if (isNullOrUndefined(EffectiveBasePermissions)) return;
264
+
265
+ if (!isNullOrNaN(EffectiveBasePermissions.High)) {
266
+ this.$High = EffectiveBasePermissions.High;
267
+ }
268
+ if (!isNullOrNaN(EffectiveBasePermissions.Low)) {
269
+ this.$Low = EffectiveBasePermissions.Low;
270
+ }
271
+ }
272
+ }
273
+
274
+ export interface ISPPeoplePickerControlFormEntity {
275
+ /** ie: i:0#.f|membership|user@kwizcom.com */
276
+ Key: string;
277
+ EntityType: "FormsRole" | "SecGroup" | "SPGroup";
278
+ EntityData?: {
279
+ SPGroupID?: string;
280
+ PrincipalType?: "User" | "SecurityGroup" | "SharePointGroup";
281
+ /** string of number "8" */
282
+ SPUserID?: string;
283
+ SIPAddress?: string;
284
+ Email?: string;
285
+ };
286
+ Resolved?: boolean;
287
+ }
288
+
289
+ /** remove i:0#.f|membership| prefix from login */
290
+ export function CleanupUserClaimsLogin(login: string) {
291
+ if (login.indexOf('|membership|') >= 0)
292
+ return login.slice(login.lastIndexOf('|') + 1);
293
+ else return login;
294
+ }
295
+
296
+ export function IsSPPeoplePickerControlFormEntity(entity: any): entity is ISPPeoplePickerControlFormEntity {
297
+ let asType = entity as ISPPeoplePickerControlFormEntity;
298
+ return !isNullOrUndefined(entity)
299
+ && !isNullOrEmptyString(asType.Key)
300
+ && (!isNullOrUndefined(asType.EntityData) || !isNullOrUndefined(asType.Resolved));
301
+ }
302
+
303
+ export function getPrincipalTypeFromPickerEntity(entity: ISPPeoplePickerControlFormEntity): PrincipalType.SecurityGroup | PrincipalType.SharePointGroup | PrincipalType.User {
304
+ if (entity.EntityType === "FormsRole"
305
+ || entity.EntityType === "SecGroup"
306
+ || entity.EntityData && entity.EntityData.PrincipalType === "SecurityGroup") {
307
+ return PrincipalType.SecurityGroup;
308
+ }
309
+
310
+ if (entity.EntityType === "SPGroup"
311
+ || entity.EntityData && (isNumeric(entity.EntityData.SPGroupID) || entity.EntityData.PrincipalType === "SharePointGroup")) {
312
+ return PrincipalType.SharePointGroup;
313
+ }
314
+
315
+ if (entity.EntityType === "User" || entity.EntityType === "" && entity.EntityData && entity.EntityData.PrincipalType === "User") {
316
+ if (entity.EntityData && isValidEmail(entity.EntityData.Email) || isString(entity.EntityData.SIPAddress)) {
317
+ return PrincipalType.User;
318
+ }
319
+
320
+ var keyparts = entity.Key.split("|");
321
+ if (keyparts.length === 3 && isValidEmail(keyparts[keyparts.length - 1])) {
322
+ //sharepoint online key for a user is in the form xxxx|membership|email;
323
+ return PrincipalType.User;
324
+ } else if (keyparts.length === 2 && isValidDomainLogin(keyparts[keyparts.length - 1])) {
325
+ //sharepoint onpremise key for a user is in the form xxxx|domain\\user;
326
+ return PrincipalType.User;
327
+ } else {
328
+ //SharePoint groups on saved classic forms item are shown with EntityType = User but dont have a SIPAddress/Email
329
+ //and the key does not contain a valid domain login/email
330
+ return PrincipalType.SharePointGroup;
331
+ }
332
+ }
333
+
334
+ return PrincipalType.User;
335
+ }
336
+
337
+ /** rest object might put array values under ".results", this will place them at the property value directly */
338
+ export function NormalizeRestObject<T>(o: T): T {
339
+ //extract collections such as choice field "choices"
340
+ if (o) {
341
+ Object.keys(o as any).forEach(key => {
342
+ if (!isNullOrUndefined(o[key]) && hasOwnProperty(o[key], "results") && Array.isArray(o[key].results))
343
+ o[key] = o[key].results;
344
+ });
345
+ }
346
+ return o;
347
+ }
348
+
349
+ /**
350
+ * Extends a field info into field info EX (adding SchemaJson)
351
+ * @param field REST field data
352
+ * @param allFields Optional - all list fields, used for discovering multi TaxonomyField's update hidden text field
353
+ */
354
+ export function extendFieldInfo(field: IFieldInfo, allFields?: IFieldInfo[]): IFieldInfoEX {
355
+ let fieldEx = field as IFieldInfoEX;
356
+ fieldEx.Id = normalizeGuid(field.Id);
357
+
358
+ if (field.InternalName === "ContentType") {
359
+ fieldEx.Required = true;
360
+ }
361
+ else {
362
+ switch (fieldEx.TypeAsString) {
363
+ case "TaxonomyFieldTypeMulti"://find the hidden rich text for updates!
364
+ {
365
+ let taxonomyField = (fieldEx as IFieldTaxonomyInfo);
366
+ let textFieldId = normalizeGuid(taxonomyField.TextField);
367
+ let related = isNotEmptyArray(allFields) ? firstOrNull(allFields, relatedField => relatedField.Id === textFieldId) : null;
368
+ if (related !== null)
369
+ taxonomyField.HiddenMultiValueFieldName = related.InternalName;
370
+ }
371
+ break;
372
+ }
373
+ }
374
+
375
+ fieldEx.OutputTypeAsString = getFieldOutputType(fieldEx);
376
+
377
+ if (isNullOrUndefined(fieldEx.SchemaJson)) {
378
+ Object.defineProperty(fieldEx, 'SchemaJson', {
379
+ get: function () {
380
+ if (isUndefined(this._schemaJson)) {
381
+ this._schemaJson = SchemaXmlToJson(this.SchemaXml);
382
+ }
383
+ return this._schemaJson;
384
+ }
385
+ });
386
+ }
387
+
388
+ if (field.InternalName === KWIZ_CONTROLLER_FIELD_NAME) {
389
+ //not hidden by SharePoint so its shown in views/forms but as far as our products concerned - should be treated as hidden
390
+ field.Hidden = true;
391
+ }
392
+
393
+ return fieldEx;
394
+ }
395
+
396
+ export function extendFieldInfos(fields: IFieldInfo[]) {
397
+ return fields.map(f => extendFieldInfo(f, fields));
398
+ }
399
+
400
+ export function getFieldOutputType(field: IFieldInfo) {
401
+ let outputType = field.TypeAsString;
402
+
403
+ if (outputType === "Calculated") {
404
+ switch ((field as IFieldCalculatedInfo).OutputType) {
405
+ case FieldTypes.DateTime:
406
+ outputType = "DateTime";
407
+ break;
408
+ case FieldTypes.Boolean:
409
+ outputType = "Boolean";
410
+ break;
411
+ case FieldTypes.Currency:
412
+ outputType = "Currency";
413
+ break;
414
+ case FieldTypes.Number:
415
+ outputType = "Number";
416
+ break;
417
+ default:
418
+ outputType = "Text";
419
+ break;
420
+ }
421
+ }
422
+
423
+ return outputType as FieldTypeAsString;
424
+ }
425
+
426
+ export function isDocLib(list?: { BaseType: number; }): boolean {
427
+ return list && list.BaseType === 1;
428
+ }
429
+
430
+ export function GetOrderByFromCaml(camlQuery: string): { Name: string; IsAscending: boolean; }[] {
431
+ let xmlDoc = new DOMParser().parseFromString(camlQuery, "text/xml");
432
+
433
+ let orderByElm = xmlDoc.querySelector("OrderBy");
434
+ let OrderBy: { Name: string; IsAscending: boolean; }[] = [];
435
+ if (orderByElm) {
436
+ let orderFieldsElms = orderByElm.querySelectorAll("FieldRef");
437
+ orderFieldsElms.forEach(f => {
438
+ let name = f.getAttribute("Name");
439
+ let asc = f.getAttribute("Ascending") || "";
440
+ //Issue 1019 default value is true if ommitted - https://learn.microsoft.com/en-us/sharepoint/dev/schema/fieldref-element-query
441
+ let IsAscending = asc.toUpperCase() !== "FALSE";
442
+ if (!isNullOrEmptyString(name))
443
+ OrderBy.push({ Name: name, IsAscending: IsAscending });
444
+ });
445
+ }
446
+
447
+ return OrderBy;
448
+ }
449
+
450
+ export function RemoveOrderByFromCaml(camlQuery: string): string {
451
+ let xmlDoc = new DOMParser().parseFromString(camlQuery, "text/xml");
452
+
453
+ let orderByElm = xmlDoc.querySelector("OrderBy");
454
+ //let OrderBy: { Name: string; IsAscending: boolean; }[] = [];
455
+ if (orderByElm) {
456
+ orderByElm.remove();
457
+ return xmlDoc.documentElement.outerHTML;
458
+ }
459
+
460
+ return camlQuery;
461
+ }
462
+
463
+ export function EnsureViewFields(camlQuery: string, fields: string[], forceCreateViewFields: boolean, removeAllOthers?: boolean) {
464
+ let xmlDoc = new DOMParser().parseFromString(camlQuery, "text/xml");
465
+ let viewElm = xmlDoc.querySelector("View");
466
+ if (!isNullOrUndefined(viewElm)) {
467
+ let viewFieldsElm = viewElm.querySelector("ViewFields");
468
+
469
+ if (forceCreateViewFields && isNullOrUndefined(viewFieldsElm)) {
470
+ viewFieldsElm = xmlDoc.createElement("ViewFields");
471
+ viewElm.appendChild(viewFieldsElm);
472
+ }
473
+
474
+ if (!isNullOrUndefined(viewFieldsElm)) {
475
+ let viewFieldsElms = viewFieldsElm.querySelectorAll("FieldRef");
476
+
477
+ if (removeAllOthers)
478
+ viewFieldsElms.forEach(e => e.remove());
479
+
480
+ let viewFields = removeAllOthers ? [] : Array.from(viewFieldsElms).map(viewFieldNode => {
481
+ let name = viewFieldNode.getAttribute("Name");
482
+ return name.toLowerCase();
483
+ });
484
+
485
+ let changed = false;
486
+ fields.forEach(f => {
487
+ if (viewFields.indexOf(f.toLowerCase()) === -1) {
488
+ let newViewFieldElm = xmlDoc.createElement("FieldRef");
489
+ newViewFieldElm.setAttribute("Name", f);
490
+ viewFieldsElm.appendChild(newViewFieldElm);
491
+ changed = true;
492
+ }
493
+ });
494
+
495
+ if (viewFieldsElm.querySelectorAll("FieldRef").length < 1 && !forceCreateViewFields) {
496
+ //don't leave an empty object
497
+ viewFieldsElm.remove();
498
+ changed = true;
499
+ }
500
+
501
+ if (changed) return xmlDoc.documentElement.outerHTML;
502
+ }
503
+ }
504
+
505
+ return camlQuery;
506
+ }
507
+
508
+ /**If it is a thumbnail field - parse and return a typed value */
509
+ export function ParseThumbnalFieldValue(value?: string, context?: {
510
+ itemId: number;
511
+ rootFolder: string;
512
+ }): ThumbnailValueType {
513
+ if (!isNullOrEmptyString(value)) {
514
+ try {
515
+ let parsed = jsonParse<ThumbnailValueType>(value);
516
+
517
+ if (isNullOrUndefined(parsed)) {
518
+ return null;
519
+ }
520
+
521
+ if (!isNullOrEmptyString(parsed.serverRelativeUrl)) {
522
+ return parsed;
523
+ } else if (!isNullOrEmptyString(parsed.fileName)
524
+ && !isNullOrUndefined(context)
525
+ && isNumber(context.itemId)
526
+ && !isNullOrEmptyString(context.rootFolder)) {
527
+ let { itemId, rootFolder } = context;
528
+ parsed.serverRelativeUrl = `${makeServerRelativeUrl(rootFolder)}/Attachments/${itemId}/${parsed.fileName}`
529
+ return parsed;
530
+ }
531
+ } catch (e) {
532
+ }
533
+ }
534
+ return null;
535
+ }
536
+
537
+ export function isTitleField(fieldName: string) {
538
+ return fieldName === "Title" || fieldName === "LinkTitleNoMenu" || fieldName === "LinkTitle";
539
+ }
540
+
541
+ /** we are on a list view page, not a web part page with possible multiple list views */
542
+ export function isSingleViewPage() {
543
+ return !isNullOrUndefined(_spPageContextInfo) && isValidGuid(_spPageContextInfo.viewId);
544
+ }
545
+
546
+ /**
547
+ * Splits the ViewFields of a CAML query into separate entries based on the batch size.
548
+ * @param {string} camlQuery - The CAML query string.
549
+ * @param {number} batchSize - The size of each batch (number of ViewFields per entry).
550
+ */
551
+ export function splitViewFieldsByBatch(camlQuery: string, allListFieldsToLowerHash: IDictionary<IFieldInfoEX>, batchSize: number): string[] {
552
+ let xmlDoc = new DOMParser().parseFromString(camlQuery, 'text/xml');
553
+ let viewNode = xmlDoc.querySelector("View, view");
554
+ let viewFieldsNode = viewNode && viewNode.querySelector("ViewFields, viewfields");
555
+
556
+ if (isNullOrUndefined(viewFieldsNode)) {
557
+ return [camlQuery]; // No ViewFields element found, return the original query as is
558
+ }
559
+
560
+ let viewFieldNodes = Array.from(viewFieldsNode.children);
561
+ let numberOfEntries = Math.ceil(viewFieldNodes.length / batchSize);
562
+
563
+ let splitQueries: string[] = [];
564
+ for (let i = 0; i < numberOfEntries; i++) {
565
+ let startIndex = i * batchSize;
566
+ let endIndex = startIndex + batchSize;
567
+ let slicedViewFields = viewFieldNodes.slice(startIndex, endIndex);
568
+
569
+ let clonedXmlDoc = xmlDoc.cloneNode(true) as XMLDocument;
570
+ let clonedViewFieldsElement = clonedXmlDoc.getElementsByTagName('ViewFields')[0];
571
+
572
+ // Remove existing child nodes from cloned ViewFields
573
+ while (clonedViewFieldsElement.firstChild) {
574
+ clonedViewFieldsElement.removeChild(clonedViewFieldsElement.firstChild);
575
+ }
576
+
577
+ // Append sliced ViewFields to cloned ViewFields
578
+ for (let slicedViewField of slicedViewFields) {
579
+ clonedViewFieldsElement.appendChild(slicedViewField.cloneNode(true));
580
+ }
581
+
582
+ let splitQuery = new XMLSerializer().serializeToString(clonedXmlDoc);
583
+ splitQueries.push(splitQuery);
584
+ }
585
+
586
+ return splitQueries;
587
+ }
588
+
589
+ /** Size=S = 48×48 px, M = 72×72 px, L = 300×300 px */
590
+ export function UserPhoto(siteUrl: string, userName: string, size: "S" | "M" | "L" = "L") {
591
+ return `${normalizeUrl(siteUrl)}/_layouts/15/userphoto.aspx?size=${size}&accountname=${encodeURIComponent(userName)}`;
592
+ }
593
+
594
+ export function IsFolderContentType(contentTypeId: string) {
595
+ //item:0x0100
596
+ //file:0x0101
597
+ //folder:0x0120
598
+ //item in MS Lists:0x00 Issue 7121
599
+ return contentTypeId.startsWith("0x0120");
600
+ }
601
+
602
+ export enum PageContainerTypes {
603
+ M365SPFx, M365OOBListForm,
604
+ SP2019SPFx, SP2019ListForm
605
+ }
606
+ export function GetModernPageContainers() {
607
+ let mainContent: HTMLElement = document.querySelector("section.mainContent");
608
+ if (mainContent)
609
+ return { mainContent, commandBar: document.querySelector(".commandBarWrapper") as HTMLElement, type: PageContainerTypes.M365SPFx };
610
+
611
+ mainContent = document.querySelector("div[class^=canvasWrapper]");//document.querySelector("div.SPCanvas");
612
+ if (mainContent)
613
+ return { mainContent, commandBar: document.querySelector(".commandBarWrapper") as HTMLElement, type: PageContainerTypes.SP2019SPFx };
614
+
615
+ mainContent = document.querySelector(".flex-mainColumn");
616
+ if (mainContent)
617
+ return { mainContent, commandBar: null, type: PageContainerTypes.M365OOBListForm };
618
+
619
+ mainContent = document.querySelector(".Files-mainColumn");
620
+ if (mainContent)
621
+ return { mainContent, commandBar: null, type: PageContainerTypes.SP2019ListForm };
622
+
623
+ return { mainContent: null, commandBar: null, type: PageContainerTypes.SP2019ListForm };
624
+ }
625
+
626
+ export function AddCamlQueryFragmentToViewQuery(viewXml: string, queryFragmentXml: string): string {
627
+
628
+ const combineWithExistingConditions = (doc: XMLDocument, existingConditions: Element[], newConditionXml: string): Element => {
629
+ const parser = new DOMParser();
630
+ const newConditionDoc = parser.parseFromString(newConditionXml, 'text/xml');
631
+ const newCondition = doc.importNode(newConditionDoc.documentElement, true);
632
+
633
+ if (existingConditions.length === 0) {
634
+ return newCondition;
635
+ } else if (existingConditions.length === 1) {
636
+ const andElement = doc.createElement("And");
637
+ andElement.appendChild(existingConditions[0]);
638
+ andElement.appendChild(newCondition);
639
+ return andElement;
640
+ } else {
641
+ const lastCondition = existingConditions.pop();
642
+ const andElement = doc.createElement("And");
643
+ andElement.appendChild(combineWithExistingConditions(doc, existingConditions, ""));
644
+ andElement.appendChild(lastCondition);
645
+ return andElement;
646
+ }
647
+ }
648
+ try {
649
+ const parser = new DOMParser();
650
+ const xmlDoc = parser.parseFromString(viewXml, 'text/xml');
651
+ const whereClause = xmlDoc.querySelector('Where') || xmlDoc.createElement('Where');
652
+ const existingConditions = Array.from(whereClause.children);
653
+
654
+ const combinedCondition = combineWithExistingConditions(xmlDoc, existingConditions, queryFragmentXml);
655
+ whereClause.textContent = ''; // Clear existing conditions
656
+ whereClause.appendChild(combinedCondition);
657
+
658
+ const query = xmlDoc.querySelector('Query') || xmlDoc.createElement('Query');
659
+ query.appendChild(whereClause);
660
+
661
+ const view = xmlDoc.querySelector('View') || xmlDoc.createElement('View');
662
+ view.appendChild(query);
663
+
664
+ const serializer = new XMLSerializer();
665
+ let modifiedCamlXml = serializer.serializeToString(xmlDoc);
666
+
667
+ return modifiedCamlXml;
668
+ } catch (error) {
669
+ return viewXml;
670
+ }
671
+ }
672
+
673
+ export function IsUserEntityValueType(value: any): value is UserEntityValueType {
674
+ if (isNullOrUndefined(value) || isString(value)) {
675
+ return false;
676
+ }
677
+ var asUserEntityValueType = value as UserEntityValueType;
678
+ var isEntityValueType =
679
+ asUserEntityValueType.principalType === PrincipalType.SharePointGroup
680
+ || asUserEntityValueType.principalType === PrincipalType.User
681
+ || asUserEntityValueType.principalType === PrincipalType.SecurityGroup;
682
+
683
+ return isEntityValueType;
684
+ }
685
+
686
+ export function IsMultiUserEntityValueType(value: any[]): value is UserEntityValueType[] {
687
+ if (isNullOrUndefined(value) || isString(value) || !Array.isArray(value)) {
688
+ return false;
689
+ }
690
+
691
+ return value.every((v) => {
692
+ return IsUserEntityValueType(v);
693
+ });
694
+ }
695
+
696
+ export function IsUrlValueType(value: any): value is UrlValueType {
697
+ if (isNullOrUndefined(value) || isString(value)) {
698
+ return false;
699
+ }
700
+ let asType = value as UrlValueType;
701
+ return !isNullOrUndefined(asType.Url) && !isNullOrUndefined(asType.Description);
702
+ }
703
+
704
+ export function IsRetentionLabelValueType(value: any): value is RententionLabelFieldValueType {
705
+ if (isNullOrUndefined(value) || isString(value)) {
706
+ return false;
707
+ }
708
+ let asType = value as RententionLabelFieldValueType;
709
+ return isValidGuid(asType.TagId) && !isNullOrEmptyString(asType.TagName);
710
+ }
711
+
712
+ export function isHostedInTeams() {
713
+ return window.location.pathname.toLowerCase().indexOf("teamshostedapp.aspx") >= 0;
714
+ }
715
+ export function isClassicAppIframe() {
716
+ return window.location.search.toLowerCase().indexOf("sphosturl=") >= 0 &&
717
+ window.location.search.toLowerCase().indexOf("spappweburl=") >= 0;
718
+ }
719
+
720
+ export function isNumberFieldType(fieldInfo: IFieldInfoEX) {
721
+ let targetColumnOutputType = getFieldOutputType(fieldInfo);
722
+ return targetColumnOutputType === "Currency"
723
+ || targetColumnOutputType === "Number"
724
+ || targetColumnOutputType === "Counter"
725
+ || targetColumnOutputType === "Integer";
726
+ }
727
+
728
+ export async function isSharePointOnline() {
729
+ let url = new URL(window.location.href);
730
+ //Most cases are satisfied by this check. Very few customers have custom domains for SharePoint online.
731
+ if (url.host.toLowerCase().endsWith(".sharepoint.com")) {
732
+ return true;
733
+ }
734
+
735
+ let contextReady = await waitFor(() => {
736
+ return !isTypeofFullNameUndefined("_spPageContextInfo");
737
+ });
738
+
739
+ if (contextReady) {
740
+ return _spPageContextInfo.isSPO === true;
741
+ }
742
+
743
+ return false;
744
+ }
745
+
746
+ export function isSharePointOnlineSync() {
747
+ let url = new URL(window.location.href);
748
+ //Most cases are satisfied by this check. Very few customers have custom domains for SharePoint online.
749
+ if (url.host.toLowerCase().endsWith(".sharepoint.com")) {
750
+ return true;
751
+ }
752
+
753
+ if (!isTypeofFullNameUndefined("_spPageContextInfo")) {
754
+ return _spPageContextInfo.isSPO === true;
755
+ }
756
+
757
+ return false;
758
+ }
759
+
760
+ export async function isAppWeb() {
761
+ let contextReady = await waitFor(() => {
762
+ return !isTypeofFullNameUndefined("_spPageContextInfo");
763
+ });
764
+
765
+ if (contextReady) {
766
+ return _spPageContextInfo.isAppWeb === true;
767
+ }
768
+
769
+ return false;
770
+ }
771
+
772
+ export function isAppWebSync() {
773
+ if (!isTypeofFullNameUndefined("_spPageContextInfo")) {
774
+ return _spPageContextInfo.isAppWeb === true;
775
+ }
776
+
777
+ return false;
778
+ }
779
+
780
+ export async function isSPPageContextInfoReady() {
781
+ return await waitForWindowObject("_spPageContextInfo");
782
+ }
783
+
784
+ export function isSPPageContextInfoReadySync() {
785
+ return !isTypeofFullNameNullOrUndefined("_spPageContextInfo");
786
786
  }