@kwiz/common 1.0.78 → 1.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +24 -0
- package/.madgerc +2 -2
- package/LICENSE +21 -21
- package/fix-folder-imports.js +26 -26
- package/lib/cjs/helpers/sharepoint.js +5 -1
- package/lib/cjs/helpers/sharepoint.js.map +1 -1
- package/lib/cjs/helpers/typecheckers.js +5 -1
- package/lib/cjs/helpers/typecheckers.js.map +1 -1
- package/lib/cjs/types/libs/msal.types.js +26 -26
- package/lib/cjs/utils/sharepoint.rest/list.js +1 -1
- package/lib/cjs/utils/sharepoint.rest/list.js.map +1 -1
- package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
- package/lib/esm/helpers/sharepoint.js +3 -0
- package/lib/esm/helpers/sharepoint.js.map +1 -1
- package/lib/esm/helpers/typecheckers.js +3 -0
- package/lib/esm/helpers/typecheckers.js.map +1 -1
- package/lib/esm/types/libs/msal.types.js +26 -26
- package/lib/esm/utils/sharepoint.rest/list.js +2 -2
- package/lib/esm/utils/sharepoint.rest/list.js.map +1 -1
- package/lib/esm/utils/sharepoint.rest/user.js +11 -11
- package/lib/types/helpers/sharepoint.d.ts +1 -0
- package/lib/types/helpers/typecheckers.d.ts +1 -0
- package/package.json +77 -77
- package/readme.md +17 -17
- package/src/_dependencies.ts +12 -12
- package/src/config.ts +17 -17
- package/src/helpers/Guid.ts +181 -181
- package/src/helpers/base64.ts +173 -173
- package/src/helpers/browser.test.js +13 -13
- package/src/helpers/browser.ts +1348 -1348
- package/src/helpers/browserinfo.ts +292 -292
- package/src/helpers/collections.base.test.js +25 -25
- package/src/helpers/collections.base.ts +437 -437
- package/src/helpers/collections.ts +107 -107
- package/src/helpers/color.ts +54 -54
- package/src/helpers/cookies.ts +59 -59
- package/src/helpers/date.test.js +119 -119
- package/src/helpers/date.ts +188 -188
- package/src/helpers/debug.ts +186 -186
- package/src/helpers/emails.ts +6 -6
- package/src/helpers/eval.ts +5 -5
- package/src/helpers/file.test.js +50 -50
- package/src/helpers/file.ts +58 -58
- package/src/helpers/flatted.ts +149 -149
- package/src/helpers/functions.ts +16 -16
- package/src/helpers/graph/calendar.types.ts +10 -10
- package/src/helpers/http.ts +69 -69
- package/src/helpers/images.ts +22 -22
- package/src/helpers/json.ts +38 -38
- package/src/helpers/md5.ts +189 -189
- package/src/helpers/objects.test.js +33 -33
- package/src/helpers/objects.ts +270 -270
- package/src/helpers/promises.test.js +37 -37
- package/src/helpers/promises.ts +165 -165
- package/src/helpers/random.ts +27 -27
- package/src/helpers/scheduler/scheduler.test.js +103 -103
- package/src/helpers/scheduler/scheduler.ts +131 -131
- package/src/helpers/sharepoint.ts +776 -772
- package/src/helpers/strings.test.js +101 -101
- package/src/helpers/strings.ts +317 -317
- package/src/helpers/typecheckers.test.js +34 -34
- package/src/helpers/typecheckers.ts +266 -262
- package/src/helpers/url.test.js +43 -43
- package/src/helpers/url.ts +207 -207
- package/src/helpers/urlhelper.ts +111 -111
- package/src/index.ts +6 -6
- package/src/types/auth.ts +54 -54
- package/src/types/common.types.ts +15 -15
- package/src/types/flatted.types.ts +59 -59
- package/src/types/globals.types.ts +6 -6
- package/src/types/graph/calendar.types.ts +80 -80
- package/src/types/knownscript.types.ts +18 -18
- package/src/types/libs/datajs.types.ts +28 -28
- package/src/types/libs/ics.types.ts +30 -30
- package/src/types/libs/msal.types.ts +49 -49
- package/src/types/locales.ts +124 -124
- package/src/types/localstoragecache.types.ts +8 -8
- package/src/types/location.types.ts +27 -27
- package/src/types/moment.ts +11 -11
- package/src/types/regex.types.ts +16 -16
- package/src/types/rest.types.ts +95 -95
- package/src/types/sharepoint.types.ts +1465 -1465
- package/src/types/sharepoint.utils.types.ts +287 -287
- package/src/utils/auth/common.ts +74 -74
- package/src/utils/auth/discovery.test.js +12 -12
- package/src/utils/auth/discovery.ts +132 -132
- package/src/utils/base64.ts +27 -27
- package/src/utils/consolelogger.ts +320 -320
- package/src/utils/date.ts +35 -35
- package/src/utils/emails.ts +24 -24
- package/src/utils/knownscript.ts +286 -286
- package/src/utils/localstoragecache.ts +441 -441
- package/src/utils/rest.ts +501 -501
- package/src/utils/script.ts +170 -170
- package/src/utils/sharepoint.rest/common.ts +154 -154
- package/src/utils/sharepoint.rest/date.ts +62 -62
- package/src/utils/sharepoint.rest/file.folder.ts +598 -598
- package/src/utils/sharepoint.rest/item.ts +547 -547
- package/src/utils/sharepoint.rest/list.ts +1388 -1388
- package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
- package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
- package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
- package/src/utils/sharepoint.rest/location.ts +141 -141
- package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
- package/src/utils/sharepoint.rest/user-search.ts +252 -252
- package/src/utils/sharepoint.rest/user.ts +491 -491
- package/src/utils/sharepoint.rest/web.ts +1384 -1384
- package/src/utils/sod.ts +194 -194
- package/lib/cjs/helpers/_dependencies.js +0 -21
- package/lib/cjs/helpers/_dependencies.js.map +0 -1
- package/lib/cjs/utils/_dependencies.js +0 -24
- package/lib/cjs/utils/_dependencies.js.map +0 -1
- package/lib/esm/helpers/_dependencies.js +0 -3
- package/lib/esm/helpers/_dependencies.js.map +0 -1
- package/lib/esm/utils/_dependencies.js +0 -4
- package/lib/esm/utils/_dependencies.js.map +0 -1
- package/lib/types/helpers/_dependencies.d.ts +0 -2
- package/lib/types/utils/_dependencies.d.ts +0 -3
package/src/helpers/debug.ts
CHANGED
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
import { IsLocalDev } from "../_dependencies";
|
|
2
|
-
import { deleteCookie, getCookie, setCookie } from "./cookies";
|
|
3
|
-
import { $w, getKWizComGlobal } from "./objects";
|
|
4
|
-
import { sleepAsync } from "./promises";
|
|
5
|
-
import { isFunction, isNotEmptyArray, isNullOrEmptyString, isNullOrUndefined } from "./typecheckers";
|
|
6
|
-
|
|
7
|
-
interface IKWizComGlobalDebug {
|
|
8
|
-
_debug: boolean;
|
|
9
|
-
_consoleLoggerFilter: string[];
|
|
10
|
-
On: (Permanent?: boolean) => void;
|
|
11
|
-
Off: () => void;
|
|
12
|
-
ToggleLogs: (categoryName: string, silent?: boolean) => void;
|
|
13
|
-
/** purge all cache storage (SPFx may keep scripts cached) */
|
|
14
|
-
PurgeCache: (options?: {
|
|
15
|
-
skipCookies?: boolean;
|
|
16
|
-
skipStorage?: boolean;
|
|
17
|
-
onlyKWizComCaches?: boolean;
|
|
18
|
-
}) => Promise<{ success: boolean; error?: any; message?: string; }>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Get the global debug object. it will only be on the top window so don't put it in the IKWizComGlobals */
|
|
22
|
-
export function GetGlobalDebug() {
|
|
23
|
-
return getKWizComGlobal(true) as { Debug?: IKWizComGlobalDebug; } & IKWizComGlobals;
|
|
24
|
-
}
|
|
25
|
-
function SetGlobalDebugFunction() {
|
|
26
|
-
var kGlobal = GetGlobalDebug();
|
|
27
|
-
|
|
28
|
-
if (isNullOrUndefined(kGlobal.Debug)) {
|
|
29
|
-
kGlobal.Debug = {
|
|
30
|
-
_debug: null,
|
|
31
|
-
_consoleLoggerFilter: null,
|
|
32
|
-
On: (Permanent?: boolean) => {
|
|
33
|
-
kGlobal.Debug._debug = true;
|
|
34
|
-
setCookie("KWizComDebug", "true", Permanent === true ? 365 : 1);
|
|
35
|
-
console.log("KWIZ Debug Mode: On");
|
|
36
|
-
},
|
|
37
|
-
Off: () => {
|
|
38
|
-
kGlobal.Debug._debug = false;
|
|
39
|
-
deleteCookie("KWizComDebug");
|
|
40
|
-
console.log("KWIZ Debug Mode: Off");
|
|
41
|
-
},
|
|
42
|
-
ToggleLogs: (categoryName: string, silent?: boolean) => {
|
|
43
|
-
if (silent === true) {
|
|
44
|
-
if (kGlobal.Debug._consoleLoggerFilter === null)
|
|
45
|
-
kGlobal.Debug._consoleLoggerFilter = [categoryName];
|
|
46
|
-
else if (!kGlobal.Debug._consoleLoggerFilter.includes(categoryName))
|
|
47
|
-
kGlobal.Debug._consoleLoggerFilter.push(categoryName);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
if (kGlobal.Debug._consoleLoggerFilter === null)
|
|
51
|
-
kGlobal.Debug._consoleLoggerFilter = [];
|
|
52
|
-
else if (kGlobal.Debug._consoleLoggerFilter.includes(categoryName))
|
|
53
|
-
kGlobal.Debug._consoleLoggerFilter = kGlobal.Debug._consoleLoggerFilter.filter(c => c !== categoryName);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setCookie("KWizComDebugFilter", kGlobal.Debug._consoleLoggerFilter.join('~'), 365);
|
|
57
|
-
console.log(`logs for ${categoryName} will ${silent === true ? 'not show up' : 'show up'}`);
|
|
58
|
-
},
|
|
59
|
-
PurgeCache: async (options?: {
|
|
60
|
-
skipCookies?: boolean;
|
|
61
|
-
skipStorage?: boolean;
|
|
62
|
-
onlyKWizComCaches?: boolean;
|
|
63
|
-
}) => {
|
|
64
|
-
options = options || {};
|
|
65
|
-
|
|
66
|
-
let result: { success: boolean; error?: any; message?: string; } = { success: true };
|
|
67
|
-
let failedKeys: string[] = [];
|
|
68
|
-
if (options.skipStorage !== true) {
|
|
69
|
-
console.log(`purging local storage`);
|
|
70
|
-
localStorage.clear();
|
|
71
|
-
console.log(`purging session storage`);
|
|
72
|
-
sessionStorage.clear();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (options.skipCookies !== true) {
|
|
76
|
-
console.log(`purging all cookies`);
|
|
77
|
-
var cookies = document.cookie.split(";");
|
|
78
|
-
cookies.forEach(cookie => { document.cookie = cookie.split("=")[0] + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
console.log(`purging caches`);
|
|
82
|
-
try {
|
|
83
|
-
let keys = await caches.keys();
|
|
84
|
-
for (let i1 = 0; i1 < keys.length; i1++) {
|
|
85
|
-
let key = keys[i1];
|
|
86
|
-
try {
|
|
87
|
-
let cache = await caches.open(key);
|
|
88
|
-
if (cache) {
|
|
89
|
-
let subKeys = await cache.keys();
|
|
90
|
-
if (subKeys && subKeys.length) {
|
|
91
|
-
let keysToRemove = options.onlyKWizComCaches !== true ? subKeys : subKeys.filter(k => k.url.toLowerCase().indexOf('apps.kwizcom.com/') >= 0);
|
|
92
|
-
for (let i2 = 0; i2 < keysToRemove.length; i2++) {
|
|
93
|
-
let success = await cache.delete(keysToRemove[i2]);
|
|
94
|
-
if (!success)//failed
|
|
95
|
-
failedKeys.push(keysToRemove[i2].url);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
} catch (b) {
|
|
100
|
-
failedKeys.push(key);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
} catch (e) {
|
|
104
|
-
result.success = false;
|
|
105
|
-
result.error = e;
|
|
106
|
-
result.message = (e.message || "Something went wrong.");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (isNotEmptyArray(failedKeys)) {
|
|
110
|
-
result.success = false;
|
|
111
|
-
result.message = (isNullOrEmptyString(result.message) ? '' : ' ') + `Failed keys: ${failedKeys.join()}`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
console.group('PurgeCache complete');
|
|
115
|
-
console.dir(result);
|
|
116
|
-
console.groupEnd();
|
|
117
|
-
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
//no need to do this anymore, once we added max-age cache to our response headers, the SP Service worker now clears
|
|
122
|
-
//the cache of our SPFx controls on its own.
|
|
123
|
-
// //by default - DO NOT clear cookies/storage and non-KWIZ caches!
|
|
124
|
-
// window.setTimeout(() => kGlobal.Debug.PurgeCache({
|
|
125
|
-
// skipCookies: true,
|
|
126
|
-
// skipStorage: true,
|
|
127
|
-
// onlyKWizComCaches: true
|
|
128
|
-
// }), 3000);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
SetGlobalDebugFunction();
|
|
133
|
-
|
|
134
|
-
export function isDebug() {
|
|
135
|
-
var kGlobal = GetGlobalDebug();
|
|
136
|
-
|
|
137
|
-
if (isNullOrUndefined(kGlobal.Debug._debug)) {
|
|
138
|
-
kGlobal.Debug._debug = IsLocalDev ||
|
|
139
|
-
$w.location.href.indexOf('kwdebug=true') > 0 ||
|
|
140
|
-
$w.location.href.indexOf('/workbench.aspx') > 0 ||
|
|
141
|
-
getCookie("KWizComDebug") === "true";
|
|
142
|
-
}
|
|
143
|
-
return kGlobal.Debug._debug === true;
|
|
144
|
-
}
|
|
145
|
-
/** returns true if this is a kwizcom production/test tenant */
|
|
146
|
-
export function isKWizComTenant() {
|
|
147
|
-
return $w.location.host === "kwizcom.sharepoint.com" || window.location.host === "kwizcomqa.sharepoint.com";
|
|
148
|
-
}
|
|
149
|
-
export function isDebugOnKWizComTenant() {
|
|
150
|
-
return isKWizComTenant() && isDebug();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function consoleLoggerFilter() {
|
|
154
|
-
var kGlobal = GetGlobalDebug();
|
|
155
|
-
|
|
156
|
-
if (isNullOrUndefined(kGlobal.Debug._consoleLoggerFilter)) {
|
|
157
|
-
let KWizComDebugFilter = getCookie("KWizComDebugFilter");
|
|
158
|
-
if (!isNullOrEmptyString(KWizComDebugFilter))
|
|
159
|
-
kGlobal.Debug._consoleLoggerFilter = KWizComDebugFilter.split('~');
|
|
160
|
-
else kGlobal.Debug._consoleLoggerFilter = [];
|
|
161
|
-
}
|
|
162
|
-
return kGlobal.Debug._consoleLoggerFilter;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export async function waitIfDebug(seconds?: number): Promise<void> {
|
|
166
|
-
if (isDebug())
|
|
167
|
-
await sleepAsync(seconds);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function trackChangesToObject<T>(parent: unknown, objectName: string, tracker: {
|
|
171
|
-
onBeforeGet?: (v: T) => void;
|
|
172
|
-
onBeforeSet?: (v: T) => void;
|
|
173
|
-
onAfterSet?: (v: T) => void;
|
|
174
|
-
}) {
|
|
175
|
-
let originalValue: T = parent[objectName];
|
|
176
|
-
Object.defineProperty(parent, objectName, {
|
|
177
|
-
set: (newValue: T) => {
|
|
178
|
-
if (isFunction(tracker.onBeforeSet)) tracker.onBeforeSet(newValue);
|
|
179
|
-
originalValue = newValue;
|
|
180
|
-
if (isFunction(tracker.onAfterSet)) tracker.onAfterSet(newValue);
|
|
181
|
-
},
|
|
182
|
-
get: () => {
|
|
183
|
-
if (isFunction(tracker.onBeforeGet)) tracker.onBeforeGet(originalValue);
|
|
184
|
-
return originalValue;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
1
|
+
import { IsLocalDev } from "../_dependencies";
|
|
2
|
+
import { deleteCookie, getCookie, setCookie } from "./cookies";
|
|
3
|
+
import { $w, getKWizComGlobal } from "./objects";
|
|
4
|
+
import { sleepAsync } from "./promises";
|
|
5
|
+
import { isFunction, isNotEmptyArray, isNullOrEmptyString, isNullOrUndefined } from "./typecheckers";
|
|
6
|
+
|
|
7
|
+
interface IKWizComGlobalDebug {
|
|
8
|
+
_debug: boolean;
|
|
9
|
+
_consoleLoggerFilter: string[];
|
|
10
|
+
On: (Permanent?: boolean) => void;
|
|
11
|
+
Off: () => void;
|
|
12
|
+
ToggleLogs: (categoryName: string, silent?: boolean) => void;
|
|
13
|
+
/** purge all cache storage (SPFx may keep scripts cached) */
|
|
14
|
+
PurgeCache: (options?: {
|
|
15
|
+
skipCookies?: boolean;
|
|
16
|
+
skipStorage?: boolean;
|
|
17
|
+
onlyKWizComCaches?: boolean;
|
|
18
|
+
}) => Promise<{ success: boolean; error?: any; message?: string; }>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Get the global debug object. it will only be on the top window so don't put it in the IKWizComGlobals */
|
|
22
|
+
export function GetGlobalDebug() {
|
|
23
|
+
return getKWizComGlobal(true) as { Debug?: IKWizComGlobalDebug; } & IKWizComGlobals;
|
|
24
|
+
}
|
|
25
|
+
function SetGlobalDebugFunction() {
|
|
26
|
+
var kGlobal = GetGlobalDebug();
|
|
27
|
+
|
|
28
|
+
if (isNullOrUndefined(kGlobal.Debug)) {
|
|
29
|
+
kGlobal.Debug = {
|
|
30
|
+
_debug: null,
|
|
31
|
+
_consoleLoggerFilter: null,
|
|
32
|
+
On: (Permanent?: boolean) => {
|
|
33
|
+
kGlobal.Debug._debug = true;
|
|
34
|
+
setCookie("KWizComDebug", "true", Permanent === true ? 365 : 1);
|
|
35
|
+
console.log("KWIZ Debug Mode: On");
|
|
36
|
+
},
|
|
37
|
+
Off: () => {
|
|
38
|
+
kGlobal.Debug._debug = false;
|
|
39
|
+
deleteCookie("KWizComDebug");
|
|
40
|
+
console.log("KWIZ Debug Mode: Off");
|
|
41
|
+
},
|
|
42
|
+
ToggleLogs: (categoryName: string, silent?: boolean) => {
|
|
43
|
+
if (silent === true) {
|
|
44
|
+
if (kGlobal.Debug._consoleLoggerFilter === null)
|
|
45
|
+
kGlobal.Debug._consoleLoggerFilter = [categoryName];
|
|
46
|
+
else if (!kGlobal.Debug._consoleLoggerFilter.includes(categoryName))
|
|
47
|
+
kGlobal.Debug._consoleLoggerFilter.push(categoryName);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (kGlobal.Debug._consoleLoggerFilter === null)
|
|
51
|
+
kGlobal.Debug._consoleLoggerFilter = [];
|
|
52
|
+
else if (kGlobal.Debug._consoleLoggerFilter.includes(categoryName))
|
|
53
|
+
kGlobal.Debug._consoleLoggerFilter = kGlobal.Debug._consoleLoggerFilter.filter(c => c !== categoryName);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setCookie("KWizComDebugFilter", kGlobal.Debug._consoleLoggerFilter.join('~'), 365);
|
|
57
|
+
console.log(`logs for ${categoryName} will ${silent === true ? 'not show up' : 'show up'}`);
|
|
58
|
+
},
|
|
59
|
+
PurgeCache: async (options?: {
|
|
60
|
+
skipCookies?: boolean;
|
|
61
|
+
skipStorage?: boolean;
|
|
62
|
+
onlyKWizComCaches?: boolean;
|
|
63
|
+
}) => {
|
|
64
|
+
options = options || {};
|
|
65
|
+
|
|
66
|
+
let result: { success: boolean; error?: any; message?: string; } = { success: true };
|
|
67
|
+
let failedKeys: string[] = [];
|
|
68
|
+
if (options.skipStorage !== true) {
|
|
69
|
+
console.log(`purging local storage`);
|
|
70
|
+
localStorage.clear();
|
|
71
|
+
console.log(`purging session storage`);
|
|
72
|
+
sessionStorage.clear();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (options.skipCookies !== true) {
|
|
76
|
+
console.log(`purging all cookies`);
|
|
77
|
+
var cookies = document.cookie.split(";");
|
|
78
|
+
cookies.forEach(cookie => { document.cookie = cookie.split("=")[0] + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log(`purging caches`);
|
|
82
|
+
try {
|
|
83
|
+
let keys = await caches.keys();
|
|
84
|
+
for (let i1 = 0; i1 < keys.length; i1++) {
|
|
85
|
+
let key = keys[i1];
|
|
86
|
+
try {
|
|
87
|
+
let cache = await caches.open(key);
|
|
88
|
+
if (cache) {
|
|
89
|
+
let subKeys = await cache.keys();
|
|
90
|
+
if (subKeys && subKeys.length) {
|
|
91
|
+
let keysToRemove = options.onlyKWizComCaches !== true ? subKeys : subKeys.filter(k => k.url.toLowerCase().indexOf('apps.kwizcom.com/') >= 0);
|
|
92
|
+
for (let i2 = 0; i2 < keysToRemove.length; i2++) {
|
|
93
|
+
let success = await cache.delete(keysToRemove[i2]);
|
|
94
|
+
if (!success)//failed
|
|
95
|
+
failedKeys.push(keysToRemove[i2].url);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (b) {
|
|
100
|
+
failedKeys.push(key);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch (e) {
|
|
104
|
+
result.success = false;
|
|
105
|
+
result.error = e;
|
|
106
|
+
result.message = (e.message || "Something went wrong.");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isNotEmptyArray(failedKeys)) {
|
|
110
|
+
result.success = false;
|
|
111
|
+
result.message = (isNullOrEmptyString(result.message) ? '' : ' ') + `Failed keys: ${failedKeys.join()}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
console.group('PurgeCache complete');
|
|
115
|
+
console.dir(result);
|
|
116
|
+
console.groupEnd();
|
|
117
|
+
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
//no need to do this anymore, once we added max-age cache to our response headers, the SP Service worker now clears
|
|
122
|
+
//the cache of our SPFx controls on its own.
|
|
123
|
+
// //by default - DO NOT clear cookies/storage and non-KWIZ caches!
|
|
124
|
+
// window.setTimeout(() => kGlobal.Debug.PurgeCache({
|
|
125
|
+
// skipCookies: true,
|
|
126
|
+
// skipStorage: true,
|
|
127
|
+
// onlyKWizComCaches: true
|
|
128
|
+
// }), 3000);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
SetGlobalDebugFunction();
|
|
133
|
+
|
|
134
|
+
export function isDebug() {
|
|
135
|
+
var kGlobal = GetGlobalDebug();
|
|
136
|
+
|
|
137
|
+
if (isNullOrUndefined(kGlobal.Debug._debug)) {
|
|
138
|
+
kGlobal.Debug._debug = IsLocalDev ||
|
|
139
|
+
$w.location.href.indexOf('kwdebug=true') > 0 ||
|
|
140
|
+
$w.location.href.indexOf('/workbench.aspx') > 0 ||
|
|
141
|
+
getCookie("KWizComDebug") === "true";
|
|
142
|
+
}
|
|
143
|
+
return kGlobal.Debug._debug === true;
|
|
144
|
+
}
|
|
145
|
+
/** returns true if this is a kwizcom production/test tenant */
|
|
146
|
+
export function isKWizComTenant() {
|
|
147
|
+
return $w.location.host === "kwizcom.sharepoint.com" || window.location.host === "kwizcomqa.sharepoint.com";
|
|
148
|
+
}
|
|
149
|
+
export function isDebugOnKWizComTenant() {
|
|
150
|
+
return isKWizComTenant() && isDebug();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function consoleLoggerFilter() {
|
|
154
|
+
var kGlobal = GetGlobalDebug();
|
|
155
|
+
|
|
156
|
+
if (isNullOrUndefined(kGlobal.Debug._consoleLoggerFilter)) {
|
|
157
|
+
let KWizComDebugFilter = getCookie("KWizComDebugFilter");
|
|
158
|
+
if (!isNullOrEmptyString(KWizComDebugFilter))
|
|
159
|
+
kGlobal.Debug._consoleLoggerFilter = KWizComDebugFilter.split('~');
|
|
160
|
+
else kGlobal.Debug._consoleLoggerFilter = [];
|
|
161
|
+
}
|
|
162
|
+
return kGlobal.Debug._consoleLoggerFilter;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function waitIfDebug(seconds?: number): Promise<void> {
|
|
166
|
+
if (isDebug())
|
|
167
|
+
await sleepAsync(seconds);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function trackChangesToObject<T>(parent: unknown, objectName: string, tracker: {
|
|
171
|
+
onBeforeGet?: (v: T) => void;
|
|
172
|
+
onBeforeSet?: (v: T) => void;
|
|
173
|
+
onAfterSet?: (v: T) => void;
|
|
174
|
+
}) {
|
|
175
|
+
let originalValue: T = parent[objectName];
|
|
176
|
+
Object.defineProperty(parent, objectName, {
|
|
177
|
+
set: (newValue: T) => {
|
|
178
|
+
if (isFunction(tracker.onBeforeSet)) tracker.onBeforeSet(newValue);
|
|
179
|
+
originalValue = newValue;
|
|
180
|
+
if (isFunction(tracker.onAfterSet)) tracker.onAfterSet(newValue);
|
|
181
|
+
},
|
|
182
|
+
get: () => {
|
|
183
|
+
if (isFunction(tracker.onBeforeGet)) tracker.onBeforeGet(originalValue);
|
|
184
|
+
return originalValue;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
187
|
}
|
package/src/helpers/emails.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isNullOrEmptyString } from "./typecheckers";
|
|
2
|
-
|
|
3
|
-
export function isValidEmail(email: string) {
|
|
4
|
-
return !isNullOrEmptyString(email) && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
5
|
-
}
|
|
6
|
-
|
|
1
|
+
import { isNullOrEmptyString } from "./typecheckers";
|
|
2
|
+
|
|
3
|
+
export function isValidEmail(email: string) {
|
|
4
|
+
return !isNullOrEmptyString(email) && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
7
|
export const freeEmailNotAllowedMessage = "Please use a work email, free emails are not allowed";
|
package/src/helpers/eval.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//eval breaks treeshaking for the entire module it is in, so keep it in separate
|
|
2
|
-
export function eval2(str: string) {
|
|
3
|
-
// eslint-disable-next-line no-eval
|
|
4
|
-
return eval(str);
|
|
5
|
-
}
|
|
1
|
+
//eval breaks treeshaking for the entire module it is in, so keep it in separate
|
|
2
|
+
export function eval2(str: string) {
|
|
3
|
+
// eslint-disable-next-line no-eval
|
|
4
|
+
return eval(str);
|
|
5
|
+
}
|
package/src/helpers/file.test.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import assert from 'assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
import { validateFilename, validateFoldername } from './file'
|
|
4
|
-
|
|
5
|
-
test('validateFilename', t => {
|
|
6
|
-
'"*:<>?/\\|'.split("").forEach((char) => {
|
|
7
|
-
let result = validateFilename(`random${char}filename.txt`);
|
|
8
|
-
assert.strictEqual(result.valid, false);
|
|
9
|
-
assert.strictEqual(result.hasIllegalCharacter, true);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
".lock|CON|PRN|AUX|NUL|COM3|COM9|COM0|LPT8|LPT2|LPT6|random_VTI_filename|~$randomfilename".split("|").forEach((name) => {
|
|
13
|
-
let result = validateFilename(`${name}.txt`);
|
|
14
|
-
assert.strictEqual(result.valid, false);
|
|
15
|
-
assert.strictEqual(result.hasIllegalName, true);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
let result = validateFilename(`desktop.ini`);
|
|
19
|
-
assert.strictEqual(result.valid, false);
|
|
20
|
-
assert.strictEqual(result.hasIllegalName, true);
|
|
21
|
-
|
|
22
|
-
["filename.txt", "test.jpg", "image.png", "worddocument.doc"].forEach((name) => {
|
|
23
|
-
result = validateFilename(name);
|
|
24
|
-
assert.strictEqual(result.valid, true);
|
|
25
|
-
assert.strictEqual(result.hasIllegalName, false);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('validateFoldername', t => {
|
|
30
|
-
'"*:<>?/\\|'.split("").forEach((char) => {
|
|
31
|
-
let result = validateFoldername(`random${char}folder`);
|
|
32
|
-
assert.strictEqual(result.valid, false);
|
|
33
|
-
assert.strictEqual(result.hasIllegalCharacter, true);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
".lock|CON|PRN|AUX|NUL|COM3|COM9|COM0|LPT8|LPT2|LPT6|random_VTI_folder|~$randomfolder".split("|").forEach((name) => {
|
|
37
|
-
let result = validateFoldername(`${name}`);
|
|
38
|
-
assert.strictEqual(result.valid, false);
|
|
39
|
-
assert.strictEqual(result.hasIllegalName, true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
let result = validateFoldername(`desktop.ini`);
|
|
43
|
-
assert.strictEqual(result.valid, false);
|
|
44
|
-
assert.strictEqual(result.hasIllegalName, true);
|
|
45
|
-
|
|
46
|
-
["folder1", "imagesfolder", "assets", "kwizcom"].forEach((name) => {
|
|
47
|
-
result = validateFoldername(name);
|
|
48
|
-
assert.strictEqual(result.valid, true);
|
|
49
|
-
assert.strictEqual(result.hasIllegalName, false);
|
|
50
|
-
});
|
|
1
|
+
import assert from 'assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { validateFilename, validateFoldername } from './file'
|
|
4
|
+
|
|
5
|
+
test('validateFilename', t => {
|
|
6
|
+
'"*:<>?/\\|'.split("").forEach((char) => {
|
|
7
|
+
let result = validateFilename(`random${char}filename.txt`);
|
|
8
|
+
assert.strictEqual(result.valid, false);
|
|
9
|
+
assert.strictEqual(result.hasIllegalCharacter, true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
".lock|CON|PRN|AUX|NUL|COM3|COM9|COM0|LPT8|LPT2|LPT6|random_VTI_filename|~$randomfilename".split("|").forEach((name) => {
|
|
13
|
+
let result = validateFilename(`${name}.txt`);
|
|
14
|
+
assert.strictEqual(result.valid, false);
|
|
15
|
+
assert.strictEqual(result.hasIllegalName, true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
let result = validateFilename(`desktop.ini`);
|
|
19
|
+
assert.strictEqual(result.valid, false);
|
|
20
|
+
assert.strictEqual(result.hasIllegalName, true);
|
|
21
|
+
|
|
22
|
+
["filename.txt", "test.jpg", "image.png", "worddocument.doc"].forEach((name) => {
|
|
23
|
+
result = validateFilename(name);
|
|
24
|
+
assert.strictEqual(result.valid, true);
|
|
25
|
+
assert.strictEqual(result.hasIllegalName, false);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('validateFoldername', t => {
|
|
30
|
+
'"*:<>?/\\|'.split("").forEach((char) => {
|
|
31
|
+
let result = validateFoldername(`random${char}folder`);
|
|
32
|
+
assert.strictEqual(result.valid, false);
|
|
33
|
+
assert.strictEqual(result.hasIllegalCharacter, true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
".lock|CON|PRN|AUX|NUL|COM3|COM9|COM0|LPT8|LPT2|LPT6|random_VTI_folder|~$randomfolder".split("|").forEach((name) => {
|
|
37
|
+
let result = validateFoldername(`${name}`);
|
|
38
|
+
assert.strictEqual(result.valid, false);
|
|
39
|
+
assert.strictEqual(result.hasIllegalName, true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let result = validateFoldername(`desktop.ini`);
|
|
43
|
+
assert.strictEqual(result.valid, false);
|
|
44
|
+
assert.strictEqual(result.hasIllegalName, true);
|
|
45
|
+
|
|
46
|
+
["folder1", "imagesfolder", "assets", "kwizcom"].forEach((name) => {
|
|
47
|
+
result = validateFoldername(name);
|
|
48
|
+
assert.strictEqual(result.valid, true);
|
|
49
|
+
assert.strictEqual(result.hasIllegalName, false);
|
|
50
|
+
});
|
|
51
51
|
});
|
package/src/helpers/file.ts
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { escapeRegExp } from "./strings";
|
|
2
|
-
|
|
3
|
-
//https://support.microsoft.com/en-gb/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa
|
|
4
|
-
//These names aren't allowed for files or folders: .lock, CON, PRN, AUX, NUL, COM0 - COM9, LPT0 - LPT9, _vti_,
|
|
5
|
-
//desktop.ini, any filename starting with ~$. "_vti_" can't appear anywhere in a file name.
|
|
6
|
-
|
|
7
|
-
function _getRegexCollection() {
|
|
8
|
-
return {
|
|
9
|
-
IllegalCharsRegex: new RegExp("[" + escapeRegExp(`"*:<>?/\\|`) + "]", "gi"),
|
|
10
|
-
IllegalCharsExtraRegex: new RegExp("[" + escapeRegExp(`~"#%&*:<>?/\\|`) + "]", "gi"),
|
|
11
|
-
IllegalNamesRegex: /^(\.lock|CON|PRN|AUX|NUL|COM\d|LPT\d|.*_VTI_.*|~\$.*)$/gi,
|
|
12
|
-
IsDesktopIni: /^desktop\.ini$/gi
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function validateFilename(fileNameWithExtension: string) {
|
|
17
|
-
let filenameWithOutExtension = fileNameWithExtension;
|
|
18
|
-
let split = filenameWithOutExtension.split(".");
|
|
19
|
-
split.pop();
|
|
20
|
-
filenameWithOutExtension = split.join(".");
|
|
21
|
-
|
|
22
|
-
let regexCollection = _getRegexCollection();
|
|
23
|
-
|
|
24
|
-
let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(filenameWithOutExtension);
|
|
25
|
-
let hasIllegalName = regexCollection.IllegalNamesRegex.test(filenameWithOutExtension) || regexCollection.IsDesktopIni.test(fileNameWithExtension);
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
hasIllegalCharacter,
|
|
29
|
-
hasIllegalName,
|
|
30
|
-
valid: !hasIllegalCharacter && !hasIllegalName
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function validateFoldername(folderName: string) {
|
|
35
|
-
let regexCollection = _getRegexCollection();
|
|
36
|
-
|
|
37
|
-
let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(folderName);
|
|
38
|
-
let hasIllegalName = regexCollection.IllegalNamesRegex.test(folderName) || regexCollection.IsDesktopIni.test(folderName);
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
hasIllegalCharacter,
|
|
42
|
-
hasIllegalName,
|
|
43
|
-
valid: !hasIllegalCharacter && !hasIllegalName
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function validateAndSetFilename(fileNameWithExtension: string) {
|
|
48
|
-
let regexCollection = _getRegexCollection();
|
|
49
|
-
|
|
50
|
-
let validateFilenameChk = validateFilename(fileNameWithExtension);
|
|
51
|
-
if (!validateFilenameChk.valid || regexCollection.IllegalCharsExtraRegex.test(fileNameWithExtension)) {
|
|
52
|
-
fileNameWithExtension =
|
|
53
|
-
fileNameWithExtension.replace(regexCollection.IllegalCharsRegex, "")
|
|
54
|
-
.replace(regexCollection.IllegalCharsExtraRegex, "")
|
|
55
|
-
.replace(regexCollection.IllegalNamesRegex, "")
|
|
56
|
-
.replace(regexCollection.IsDesktopIni, "");
|
|
57
|
-
}
|
|
58
|
-
return fileNameWithExtension;
|
|
1
|
+
import { escapeRegExp } from "./strings";
|
|
2
|
+
|
|
3
|
+
//https://support.microsoft.com/en-gb/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa
|
|
4
|
+
//These names aren't allowed for files or folders: .lock, CON, PRN, AUX, NUL, COM0 - COM9, LPT0 - LPT9, _vti_,
|
|
5
|
+
//desktop.ini, any filename starting with ~$. "_vti_" can't appear anywhere in a file name.
|
|
6
|
+
|
|
7
|
+
function _getRegexCollection() {
|
|
8
|
+
return {
|
|
9
|
+
IllegalCharsRegex: new RegExp("[" + escapeRegExp(`"*:<>?/\\|`) + "]", "gi"),
|
|
10
|
+
IllegalCharsExtraRegex: new RegExp("[" + escapeRegExp(`~"#%&*:<>?/\\|`) + "]", "gi"),
|
|
11
|
+
IllegalNamesRegex: /^(\.lock|CON|PRN|AUX|NUL|COM\d|LPT\d|.*_VTI_.*|~\$.*)$/gi,
|
|
12
|
+
IsDesktopIni: /^desktop\.ini$/gi
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function validateFilename(fileNameWithExtension: string) {
|
|
17
|
+
let filenameWithOutExtension = fileNameWithExtension;
|
|
18
|
+
let split = filenameWithOutExtension.split(".");
|
|
19
|
+
split.pop();
|
|
20
|
+
filenameWithOutExtension = split.join(".");
|
|
21
|
+
|
|
22
|
+
let regexCollection = _getRegexCollection();
|
|
23
|
+
|
|
24
|
+
let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(filenameWithOutExtension);
|
|
25
|
+
let hasIllegalName = regexCollection.IllegalNamesRegex.test(filenameWithOutExtension) || regexCollection.IsDesktopIni.test(fileNameWithExtension);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
hasIllegalCharacter,
|
|
29
|
+
hasIllegalName,
|
|
30
|
+
valid: !hasIllegalCharacter && !hasIllegalName
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function validateFoldername(folderName: string) {
|
|
35
|
+
let regexCollection = _getRegexCollection();
|
|
36
|
+
|
|
37
|
+
let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(folderName);
|
|
38
|
+
let hasIllegalName = regexCollection.IllegalNamesRegex.test(folderName) || regexCollection.IsDesktopIni.test(folderName);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
hasIllegalCharacter,
|
|
42
|
+
hasIllegalName,
|
|
43
|
+
valid: !hasIllegalCharacter && !hasIllegalName
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function validateAndSetFilename(fileNameWithExtension: string) {
|
|
48
|
+
let regexCollection = _getRegexCollection();
|
|
49
|
+
|
|
50
|
+
let validateFilenameChk = validateFilename(fileNameWithExtension);
|
|
51
|
+
if (!validateFilenameChk.valid || regexCollection.IllegalCharsExtraRegex.test(fileNameWithExtension)) {
|
|
52
|
+
fileNameWithExtension =
|
|
53
|
+
fileNameWithExtension.replace(regexCollection.IllegalCharsRegex, "")
|
|
54
|
+
.replace(regexCollection.IllegalCharsExtraRegex, "")
|
|
55
|
+
.replace(regexCollection.IllegalNamesRegex, "")
|
|
56
|
+
.replace(regexCollection.IsDesktopIni, "");
|
|
57
|
+
}
|
|
58
|
+
return fileNameWithExtension;
|
|
59
59
|
}
|