@kwiz/common 1.0.129 → 1.0.132

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 (100) hide show
  1. package/.github/workflows/npm-publish.yml +24 -24
  2. package/LICENSE +21 -21
  3. package/lib/cjs/config.js +2 -0
  4. package/lib/cjs/config.js.map +1 -1
  5. package/lib/cjs/types/libs/msal.types.js +26 -26
  6. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  7. package/lib/esm/config.js +2 -0
  8. package/lib/esm/config.js.map +1 -1
  9. package/lib/esm/types/libs/msal.types.js +26 -26
  10. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  11. package/lib/types/config.d.ts +2 -0
  12. package/package.json +81 -81
  13. package/readme.md +17 -17
  14. package/src/_dependencies.ts +12 -12
  15. package/src/config.ts +19 -17
  16. package/src/helpers/Guid.ts +181 -181
  17. package/src/helpers/base64.ts +173 -173
  18. package/src/helpers/browser.test.js +13 -13
  19. package/src/helpers/browser.ts +1504 -1504
  20. package/src/helpers/browserinfo.ts +292 -292
  21. package/src/helpers/collections.base.test.js +25 -25
  22. package/src/helpers/collections.base.ts +437 -437
  23. package/src/helpers/collections.ts +107 -107
  24. package/src/helpers/color.ts +54 -54
  25. package/src/helpers/cookies.ts +59 -59
  26. package/src/helpers/date.test.js +119 -119
  27. package/src/helpers/date.ts +188 -188
  28. package/src/helpers/debug.ts +186 -186
  29. package/src/helpers/diagrams.ts +43 -43
  30. package/src/helpers/emails.ts +6 -6
  31. package/src/helpers/eval.ts +5 -5
  32. package/src/helpers/file.test.js +50 -50
  33. package/src/helpers/file.ts +63 -63
  34. package/src/helpers/flatted.ts +149 -149
  35. package/src/helpers/functions.ts +16 -16
  36. package/src/helpers/graph/calendar.types.ts +10 -10
  37. package/src/helpers/http.ts +69 -69
  38. package/src/helpers/images.ts +22 -22
  39. package/src/helpers/json.ts +44 -44
  40. package/src/helpers/md5.ts +189 -189
  41. package/src/helpers/objects.test.js +33 -33
  42. package/src/helpers/objects.ts +274 -274
  43. package/src/helpers/promises.test.js +37 -37
  44. package/src/helpers/promises.ts +165 -165
  45. package/src/helpers/random.ts +27 -27
  46. package/src/helpers/scheduler/scheduler.test.js +103 -103
  47. package/src/helpers/scheduler/scheduler.ts +131 -131
  48. package/src/helpers/sharepoint.ts +796 -796
  49. package/src/helpers/strings.test.js +122 -122
  50. package/src/helpers/strings.ts +337 -337
  51. package/src/helpers/typecheckers.test.js +34 -34
  52. package/src/helpers/typecheckers.ts +266 -266
  53. package/src/helpers/url.test.js +43 -43
  54. package/src/helpers/url.ts +207 -207
  55. package/src/helpers/urlhelper.ts +111 -111
  56. package/src/index.ts +6 -6
  57. package/src/types/auth.ts +62 -62
  58. package/src/types/common.types.ts +15 -15
  59. package/src/types/flatted.types.ts +59 -59
  60. package/src/types/globals.types.ts +6 -6
  61. package/src/types/graph/calendar.types.ts +80 -80
  62. package/src/types/knownscript.types.ts +18 -18
  63. package/src/types/libs/datajs.types.ts +28 -28
  64. package/src/types/libs/ics.types.ts +30 -30
  65. package/src/types/libs/msal.types.ts +57 -57
  66. package/src/types/locales.ts +125 -125
  67. package/src/types/localstoragecache.types.ts +8 -8
  68. package/src/types/location.types.ts +27 -27
  69. package/src/types/moment.ts +11 -11
  70. package/src/types/regex.types.ts +16 -16
  71. package/src/types/rest.types.ts +95 -95
  72. package/src/types/sharepoint.types.ts +1466 -1466
  73. package/src/types/sharepoint.utils.types.ts +306 -306
  74. package/src/utils/auth/common.ts +118 -118
  75. package/src/utils/auth/discovery.test.js +12 -12
  76. package/src/utils/auth/discovery.ts +132 -132
  77. package/src/utils/base64.ts +27 -27
  78. package/src/utils/consolelogger.ts +333 -333
  79. package/src/utils/date.ts +172 -172
  80. package/src/utils/emails.ts +24 -24
  81. package/src/utils/knownscript.ts +286 -286
  82. package/src/utils/localstoragecache.ts +446 -446
  83. package/src/utils/rest.ts +501 -501
  84. package/src/utils/script.ts +170 -170
  85. package/src/utils/sharepoint.rest/common.ts +159 -159
  86. package/src/utils/sharepoint.rest/date.ts +62 -62
  87. package/src/utils/sharepoint.rest/file.folder.ts +685 -685
  88. package/src/utils/sharepoint.rest/item.ts +547 -547
  89. package/src/utils/sharepoint.rest/list.ts +1572 -1572
  90. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  91. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  92. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  93. package/src/utils/sharepoint.rest/location.ts +141 -141
  94. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  95. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  96. package/src/utils/sharepoint.rest/user.ts +558 -558
  97. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  98. package/src/utils/sod.ts +194 -194
  99. package/.madgerc +0 -3
  100. package/fix-folder-imports.js +0 -27
@@ -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"];