@kwiz/common 1.0.90 → 1.0.92

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 (99) 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 +42 -20
  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/sharepoint.rest/user.js +11 -11
  9. package/lib/esm/helpers/browser.js +42 -20
  10. package/lib/esm/helpers/browser.js.map +1 -1
  11. package/lib/esm/types/libs/msal.types.js +26 -26
  12. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  13. package/lib/types/helpers/browser.d.ts +1 -0
  14. package/package.json +81 -80
  15. package/readme.md +17 -17
  16. package/src/_dependencies.ts +12 -12
  17. package/src/config.ts +17 -17
  18. package/src/helpers/Guid.ts +181 -181
  19. package/src/helpers/base64.ts +173 -173
  20. package/src/helpers/browser.test.js +13 -13
  21. package/src/helpers/browser.ts +1386 -1358
  22. package/src/helpers/browserinfo.ts +292 -292
  23. package/src/helpers/collections.base.test.js +25 -25
  24. package/src/helpers/collections.base.ts +437 -437
  25. package/src/helpers/collections.ts +107 -107
  26. package/src/helpers/color.ts +54 -54
  27. package/src/helpers/cookies.ts +59 -59
  28. package/src/helpers/date.test.js +119 -119
  29. package/src/helpers/date.ts +188 -188
  30. package/src/helpers/debug.ts +186 -186
  31. package/src/helpers/emails.ts +6 -6
  32. package/src/helpers/eval.ts +5 -5
  33. package/src/helpers/file.test.js +50 -50
  34. package/src/helpers/file.ts +60 -60
  35. package/src/helpers/flatted.ts +149 -149
  36. package/src/helpers/functions.ts +16 -16
  37. package/src/helpers/graph/calendar.types.ts +10 -10
  38. package/src/helpers/http.ts +69 -69
  39. package/src/helpers/images.ts +22 -22
  40. package/src/helpers/json.ts +38 -38
  41. package/src/helpers/md5.ts +189 -189
  42. package/src/helpers/objects.test.js +33 -33
  43. package/src/helpers/objects.ts +274 -274
  44. package/src/helpers/promises.test.js +37 -37
  45. package/src/helpers/promises.ts +165 -165
  46. package/src/helpers/random.ts +27 -27
  47. package/src/helpers/scheduler/scheduler.test.js +103 -103
  48. package/src/helpers/scheduler/scheduler.ts +131 -131
  49. package/src/helpers/sharepoint.ts +776 -776
  50. package/src/helpers/strings.test.js +101 -101
  51. package/src/helpers/strings.ts +317 -317
  52. package/src/helpers/typecheckers.test.js +34 -34
  53. package/src/helpers/typecheckers.ts +266 -266
  54. package/src/helpers/url.test.js +43 -43
  55. package/src/helpers/url.ts +207 -207
  56. package/src/helpers/urlhelper.ts +111 -111
  57. package/src/index.ts +6 -6
  58. package/src/types/auth.ts +54 -54
  59. package/src/types/common.types.ts +15 -15
  60. package/src/types/flatted.types.ts +59 -59
  61. package/src/types/globals.types.ts +6 -6
  62. package/src/types/graph/calendar.types.ts +80 -80
  63. package/src/types/knownscript.types.ts +18 -18
  64. package/src/types/libs/datajs.types.ts +28 -28
  65. package/src/types/libs/ics.types.ts +30 -30
  66. package/src/types/libs/msal.types.ts +49 -49
  67. package/src/types/locales.ts +124 -124
  68. package/src/types/localstoragecache.types.ts +8 -8
  69. package/src/types/location.types.ts +27 -27
  70. package/src/types/moment.ts +11 -11
  71. package/src/types/regex.types.ts +16 -16
  72. package/src/types/rest.types.ts +95 -95
  73. package/src/types/sharepoint.types.ts +1465 -1465
  74. package/src/types/sharepoint.utils.types.ts +287 -287
  75. package/src/utils/auth/common.ts +74 -74
  76. package/src/utils/auth/discovery.test.js +12 -12
  77. package/src/utils/auth/discovery.ts +132 -132
  78. package/src/utils/base64.ts +27 -27
  79. package/src/utils/consolelogger.ts +320 -320
  80. package/src/utils/date.ts +35 -35
  81. package/src/utils/emails.ts +24 -24
  82. package/src/utils/knownscript.ts +286 -286
  83. package/src/utils/localstoragecache.ts +441 -441
  84. package/src/utils/rest.ts +501 -501
  85. package/src/utils/script.ts +170 -170
  86. package/src/utils/sharepoint.rest/common.ts +154 -154
  87. package/src/utils/sharepoint.rest/date.ts +62 -62
  88. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  89. package/src/utils/sharepoint.rest/item.ts +547 -547
  90. package/src/utils/sharepoint.rest/list.ts +1480 -1480
  91. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  92. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  93. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  94. package/src/utils/sharepoint.rest/location.ts +141 -141
  95. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  96. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  97. package/src/utils/sharepoint.rest/user.ts +491 -491
  98. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  99. package/src/utils/sod.ts +194 -194
@@ -1,207 +1,207 @@
1
- import { lastIndexOf, toHash } from "../../../helpers/collections.base";
2
- import { isNotEmptyArray, isNullOrEmptyString, isNullOrUndefined, isNumber } from "../../../helpers/typecheckers";
3
- import { IDictionary } from "../../../types/common.types";
4
- import { jsonTypes } from "../../../types/rest.types";
5
- import { FileSystemObjectTypes, IFieldInfoEX, IFieldLookupInfo } from "../../../types/sharepoint.types";
6
- import { GeListItemsFoldersBehaviour, IRestItem } from "../../../types/sharepoint.utils.types";
7
- import { ConsoleLogger } from "../../consolelogger";
8
- import { DecodeFieldValuesAsTextKey, GetFieldNameFromRawValues } from "../common";
9
- import { GetItemsByIdSync } from "./GetListItemsById";
10
-
11
- const logger = ConsoleLogger.get("sharepoint.rest/list/common");
12
-
13
- export function __fixGetListItemsResults(siteUrl: string, listIdOrTitle: string, items: IRestItem[], foldersBehaviour?: GeListItemsFoldersBehaviour, expandedLookupFields?: IFieldInfoEX[]): IRestItem[] {
14
- let folders: { [folderPath: string]: IRestItem; } = {};
15
-
16
- let itemFileRefMap: IDictionary<{ FileRef: string; FileSystemObjectType: FileSystemObjectTypes }> = {};
17
- if (isNotEmptyArray(items) && isNullOrUndefined(items[0].FileRef)) {
18
- //customer support ticket - request was missing teh FileRef column!
19
- let additionalItems = GetItemsByIdSync(siteUrl, listIdOrTitle, items.map(i => i.Id), {
20
- select: ["Id", "FileRef", "FileSystemObjectType"],
21
- jsonMetadata: jsonTypes.nometadata
22
- });
23
- itemFileRefMap = toHash(additionalItems, i => i.Id.toString(10));
24
- }
25
-
26
- items.forEach(item => {
27
- try {
28
- if (itemFileRefMap[item.Id]) {
29
- let mappedValue = itemFileRefMap[item.Id];
30
- item.FileRef = mappedValue.FileRef;
31
- item.FileSystemObjectType = mappedValue.FileSystemObjectType;
32
- }
33
-
34
- let fileRef = item.FileRef as string || "";
35
- let parts = fileRef.split('/');
36
- item.FileLeafRef = parts.pop() || "";
37
- item.FileDirRef = parts.join('/');
38
- item.FileOrFolderName = item.FileLeafRef.split('.')[0];
39
-
40
- if (item.FileSystemObjectType === 1) {
41
- item.FileType = "folder";
42
- item.__Items = [];
43
- folders[fileRef.toLowerCase()] = item;
44
- item.__DisplayTitle = item.FileLeafRef;
45
- }
46
- else {
47
- //issue 8094 file name might have multiple dots
48
- let splitDot = item.FileLeafRef.split('.');
49
- item.FileType = splitDot.length > 1 ? splitDot.pop().toLowerCase() : "folder";
50
- item.__DisplayTitle = splitDot.join('.');
51
- if (item.FileType === '000') {
52
- item.FileType = 'listitem';
53
- item.__DisplayTitle = item.Title;
54
- if (isNullOrEmptyString(item.__DisplayTitle))
55
- item.__DisplayTitle = `Item #${item.Id}`;
56
- }
57
- }
58
-
59
- if (isNotEmptyArray(expandedLookupFields))
60
- expandedLookupFields.forEach((f: IFieldLookupInfo) => {
61
- //ISSUE: 1519
62
- let lookupField = f.LookupField;
63
-
64
- //ISSUE: 1250 - expanded lookup fields with names that start with '_'
65
- //will be returned as OData__name. We have to use the field name returned
66
- //from GetFieldNameFromRawValues without the 'Id' appended to the name because
67
- //the value has been expanded.
68
- let fieldInternalName = f.InternalName;
69
- let rawValue = item[f.InternalName];
70
- if (isNullOrUndefined(rawValue)) {
71
- fieldInternalName = GetFieldNameFromRawValues(f, {
72
- excludeIdFromName: true
73
- });
74
-
75
- rawValue = item[fieldInternalName];
76
- }
77
-
78
- if (rawValue) {
79
- item.FieldValuesAsText = item.FieldValuesAsText || {};
80
-
81
- let value: { Id: number; Title: string;[InternalName: string]: any } | { Id: number; Title: string;[InternalName: string]: any }[] = rawValue;
82
- if (Array.isArray(value))//multi value
83
- {
84
- let id: number[] = [];
85
- let text: string[] = [];
86
- value.forEach(v => {
87
- id.push(v.Id);
88
- if (!isNullOrEmptyString(lookupField) && !isNullOrUndefined(v[lookupField])) {
89
- text.push(v[lookupField]);
90
- } else {
91
- text.push(v.Title);
92
- }
93
- });
94
- item[`${fieldInternalName}Id`] = id;
95
- item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = text.join(", ");
96
- }
97
- else if (isNumber(value && value.Id)) {
98
- item[`${fieldInternalName}Id`] = value.Id;
99
- //ISSUE: 1519 - condition to check if lookup field exists and get the value from the rawValue object by string index of lookup field key
100
- if (!isNullOrEmptyString(lookupField) && !isNullOrUndefined(value[lookupField])) {
101
- item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = value[lookupField];
102
- } else {
103
- item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = value.Title;
104
- }
105
- }
106
- }
107
- });
108
- } catch (e) {
109
- logger.error(`Failed to fix list item result ${item && item.Id || 'unknown id'}`);
110
- }
111
- });
112
-
113
- //loop through items, put them inside folders
114
- let itemsInRoot: IRestItem[] = [];
115
- items.forEach(item => {
116
- let parentFolder = folders[item.FileDirRef.toLowerCase()];
117
- if (!isNullOrUndefined(parentFolder)) {
118
-
119
- if (item.FileSystemObjectType === FileSystemObjectTypes.Folder) {
120
- //add it before any items, so we have folders first (sorted) and items after
121
- let indexOfLastFolder = lastIndexOf(parentFolder.__Items, i => i.FileSystemObjectType === FileSystemObjectTypes.Folder);
122
- parentFolder.__Items.splice(indexOfLastFolder + 1, 0, item);
123
- } else
124
- parentFolder.__Items.push(item);
125
- item.__ParentFolder = parentFolder;
126
- }
127
- else itemsInRoot.push(item);
128
- });
129
-
130
- switch (foldersBehaviour) {
131
- case GeListItemsFoldersBehaviour.AllItemsNoFolders:
132
- return items.filter(r => r.FileSystemObjectType !== 1);
133
- case GeListItemsFoldersBehaviour.ItemsInsideFolders:
134
- return itemsInRoot;
135
- case GeListItemsFoldersBehaviour.ItemsAndFoldersFlat:
136
- default:
137
- return items;
138
- }
139
- }
140
-
141
- export var SkipFields: string[] = [
142
- "appauthor",
143
- "appeditor",
144
- "linktitle",
145
- "linktitlenomenu",
146
- "linkfilename",
147
- "linkfilenamenomenu",
148
- "_copysource",
149
- "_complianceflags",
150
- "_compliancetag",
151
- "_compliancetagwrittentime",
152
- "_compliancetaguserid",
153
- "_isrecord",
154
- //issue 5576: allow user to see version column "_uiversionstring",
155
- "itemchildcount",
156
- "folderchildcount",
157
- "complianceassetid",
158
- "xd_progid",
159
- "xd_signature",
160
- "_shortcuturl",
161
- "_shortcutsiteid",
162
- "_shortcutwebid",
163
- "_shortcutuniqueid",
164
- "_hascopydestinations",
165
- "sortbehavior",
166
- "permmask",
167
- "syncclientid",
168
- "progid",
169
- "scopeid",
170
- "virusstatus",
171
- "_editmenutablestart",
172
- "_editmenutablestart2",
173
- "_editmenutableend",
174
- "linkfilename2",
175
- "basename",
176
- "metainfo",
177
- "_level",
178
- "_iscurrentversion",
179
- "originatorid",
180
- "noexecute",
181
- "bsn",
182
- "_listschemaversion",
183
- "_dirty",
184
- "_parsable",
185
- "_stubfile",
186
- "_virusstatus",
187
- "_virusvendorid",
188
- "_virusinfo",
189
- "_rmstemplateid",
190
- "_iplabelid",
191
- "_displayname",
192
- "smtotalsize",
193
- "smlastmodifieddate",
194
- "smtotalfilestreamsize",
195
- "smtotalfilecount",
196
- "selecttitle",
197
- "selectfilename",
198
- "edit",
199
- "workflowversion",
200
- "workflowinstanceid",
201
- "parentversionstring",
202
- "parentleafname",
203
- "docconcurrencynumber",
204
- "parentuniqueid",
205
- "streamhash",
206
- "combine",
1
+ import { lastIndexOf, toHash } from "../../../helpers/collections.base";
2
+ import { isNotEmptyArray, isNullOrEmptyString, isNullOrUndefined, isNumber } from "../../../helpers/typecheckers";
3
+ import { IDictionary } from "../../../types/common.types";
4
+ import { jsonTypes } from "../../../types/rest.types";
5
+ import { FileSystemObjectTypes, IFieldInfoEX, IFieldLookupInfo } from "../../../types/sharepoint.types";
6
+ import { GeListItemsFoldersBehaviour, IRestItem } from "../../../types/sharepoint.utils.types";
7
+ import { ConsoleLogger } from "../../consolelogger";
8
+ import { DecodeFieldValuesAsTextKey, GetFieldNameFromRawValues } from "../common";
9
+ import { GetItemsByIdSync } from "./GetListItemsById";
10
+
11
+ const logger = ConsoleLogger.get("sharepoint.rest/list/common");
12
+
13
+ export function __fixGetListItemsResults(siteUrl: string, listIdOrTitle: string, items: IRestItem[], foldersBehaviour?: GeListItemsFoldersBehaviour, expandedLookupFields?: IFieldInfoEX[]): IRestItem[] {
14
+ let folders: { [folderPath: string]: IRestItem; } = {};
15
+
16
+ let itemFileRefMap: IDictionary<{ FileRef: string; FileSystemObjectType: FileSystemObjectTypes }> = {};
17
+ if (isNotEmptyArray(items) && isNullOrUndefined(items[0].FileRef)) {
18
+ //customer support ticket - request was missing teh FileRef column!
19
+ let additionalItems = GetItemsByIdSync(siteUrl, listIdOrTitle, items.map(i => i.Id), {
20
+ select: ["Id", "FileRef", "FileSystemObjectType"],
21
+ jsonMetadata: jsonTypes.nometadata
22
+ });
23
+ itemFileRefMap = toHash(additionalItems, i => i.Id.toString(10));
24
+ }
25
+
26
+ items.forEach(item => {
27
+ try {
28
+ if (itemFileRefMap[item.Id]) {
29
+ let mappedValue = itemFileRefMap[item.Id];
30
+ item.FileRef = mappedValue.FileRef;
31
+ item.FileSystemObjectType = mappedValue.FileSystemObjectType;
32
+ }
33
+
34
+ let fileRef = item.FileRef as string || "";
35
+ let parts = fileRef.split('/');
36
+ item.FileLeafRef = parts.pop() || "";
37
+ item.FileDirRef = parts.join('/');
38
+ item.FileOrFolderName = item.FileLeafRef.split('.')[0];
39
+
40
+ if (item.FileSystemObjectType === 1) {
41
+ item.FileType = "folder";
42
+ item.__Items = [];
43
+ folders[fileRef.toLowerCase()] = item;
44
+ item.__DisplayTitle = item.FileLeafRef;
45
+ }
46
+ else {
47
+ //issue 8094 file name might have multiple dots
48
+ let splitDot = item.FileLeafRef.split('.');
49
+ item.FileType = splitDot.length > 1 ? splitDot.pop().toLowerCase() : "folder";
50
+ item.__DisplayTitle = splitDot.join('.');
51
+ if (item.FileType === '000') {
52
+ item.FileType = 'listitem';
53
+ item.__DisplayTitle = item.Title;
54
+ if (isNullOrEmptyString(item.__DisplayTitle))
55
+ item.__DisplayTitle = `Item #${item.Id}`;
56
+ }
57
+ }
58
+
59
+ if (isNotEmptyArray(expandedLookupFields))
60
+ expandedLookupFields.forEach((f: IFieldLookupInfo) => {
61
+ //ISSUE: 1519
62
+ let lookupField = f.LookupField;
63
+
64
+ //ISSUE: 1250 - expanded lookup fields with names that start with '_'
65
+ //will be returned as OData__name. We have to use the field name returned
66
+ //from GetFieldNameFromRawValues without the 'Id' appended to the name because
67
+ //the value has been expanded.
68
+ let fieldInternalName = f.InternalName;
69
+ let rawValue = item[f.InternalName];
70
+ if (isNullOrUndefined(rawValue)) {
71
+ fieldInternalName = GetFieldNameFromRawValues(f, {
72
+ excludeIdFromName: true
73
+ });
74
+
75
+ rawValue = item[fieldInternalName];
76
+ }
77
+
78
+ if (rawValue) {
79
+ item.FieldValuesAsText = item.FieldValuesAsText || {};
80
+
81
+ let value: { Id: number; Title: string;[InternalName: string]: any } | { Id: number; Title: string;[InternalName: string]: any }[] = rawValue;
82
+ if (Array.isArray(value))//multi value
83
+ {
84
+ let id: number[] = [];
85
+ let text: string[] = [];
86
+ value.forEach(v => {
87
+ id.push(v.Id);
88
+ if (!isNullOrEmptyString(lookupField) && !isNullOrUndefined(v[lookupField])) {
89
+ text.push(v[lookupField]);
90
+ } else {
91
+ text.push(v.Title);
92
+ }
93
+ });
94
+ item[`${fieldInternalName}Id`] = id;
95
+ item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = text.join(", ");
96
+ }
97
+ else if (isNumber(value && value.Id)) {
98
+ item[`${fieldInternalName}Id`] = value.Id;
99
+ //ISSUE: 1519 - condition to check if lookup field exists and get the value from the rawValue object by string index of lookup field key
100
+ if (!isNullOrEmptyString(lookupField) && !isNullOrUndefined(value[lookupField])) {
101
+ item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = value[lookupField];
102
+ } else {
103
+ item.FieldValuesAsText[DecodeFieldValuesAsTextKey(fieldInternalName)] = value.Title;
104
+ }
105
+ }
106
+ }
107
+ });
108
+ } catch (e) {
109
+ logger.error(`Failed to fix list item result ${item && item.Id || 'unknown id'}`);
110
+ }
111
+ });
112
+
113
+ //loop through items, put them inside folders
114
+ let itemsInRoot: IRestItem[] = [];
115
+ items.forEach(item => {
116
+ let parentFolder = folders[item.FileDirRef.toLowerCase()];
117
+ if (!isNullOrUndefined(parentFolder)) {
118
+
119
+ if (item.FileSystemObjectType === FileSystemObjectTypes.Folder) {
120
+ //add it before any items, so we have folders first (sorted) and items after
121
+ let indexOfLastFolder = lastIndexOf(parentFolder.__Items, i => i.FileSystemObjectType === FileSystemObjectTypes.Folder);
122
+ parentFolder.__Items.splice(indexOfLastFolder + 1, 0, item);
123
+ } else
124
+ parentFolder.__Items.push(item);
125
+ item.__ParentFolder = parentFolder;
126
+ }
127
+ else itemsInRoot.push(item);
128
+ });
129
+
130
+ switch (foldersBehaviour) {
131
+ case GeListItemsFoldersBehaviour.AllItemsNoFolders:
132
+ return items.filter(r => r.FileSystemObjectType !== 1);
133
+ case GeListItemsFoldersBehaviour.ItemsInsideFolders:
134
+ return itemsInRoot;
135
+ case GeListItemsFoldersBehaviour.ItemsAndFoldersFlat:
136
+ default:
137
+ return items;
138
+ }
139
+ }
140
+
141
+ export var SkipFields: string[] = [
142
+ "appauthor",
143
+ "appeditor",
144
+ "linktitle",
145
+ "linktitlenomenu",
146
+ "linkfilename",
147
+ "linkfilenamenomenu",
148
+ "_copysource",
149
+ "_complianceflags",
150
+ "_compliancetag",
151
+ "_compliancetagwrittentime",
152
+ "_compliancetaguserid",
153
+ "_isrecord",
154
+ //issue 5576: allow user to see version column "_uiversionstring",
155
+ "itemchildcount",
156
+ "folderchildcount",
157
+ "complianceassetid",
158
+ "xd_progid",
159
+ "xd_signature",
160
+ "_shortcuturl",
161
+ "_shortcutsiteid",
162
+ "_shortcutwebid",
163
+ "_shortcutuniqueid",
164
+ "_hascopydestinations",
165
+ "sortbehavior",
166
+ "permmask",
167
+ "syncclientid",
168
+ "progid",
169
+ "scopeid",
170
+ "virusstatus",
171
+ "_editmenutablestart",
172
+ "_editmenutablestart2",
173
+ "_editmenutableend",
174
+ "linkfilename2",
175
+ "basename",
176
+ "metainfo",
177
+ "_level",
178
+ "_iscurrentversion",
179
+ "originatorid",
180
+ "noexecute",
181
+ "bsn",
182
+ "_listschemaversion",
183
+ "_dirty",
184
+ "_parsable",
185
+ "_stubfile",
186
+ "_virusstatus",
187
+ "_virusvendorid",
188
+ "_virusinfo",
189
+ "_rmstemplateid",
190
+ "_iplabelid",
191
+ "_displayname",
192
+ "smtotalsize",
193
+ "smlastmodifieddate",
194
+ "smtotalfilestreamsize",
195
+ "smtotalfilecount",
196
+ "selecttitle",
197
+ "selectfilename",
198
+ "edit",
199
+ "workflowversion",
200
+ "workflowinstanceid",
201
+ "parentversionstring",
202
+ "parentleafname",
203
+ "docconcurrencynumber",
204
+ "parentuniqueid",
205
+ "streamhash",
206
+ "combine",
207
207
  "repairdocument"];