@kwiz/common 1.0.129 → 1.0.133

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 (111) hide show
  1. package/LICENSE +21 -21
  2. package/lib/cjs/config.js +2 -0
  3. package/lib/cjs/config.js.map +1 -1
  4. package/lib/cjs/types/libs/msal.types.js +26 -26
  5. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  6. package/lib/esm/config.js +2 -0
  7. package/lib/esm/config.js.map +1 -1
  8. package/lib/esm/types/libs/msal.types.js +26 -26
  9. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  10. package/lib/types/config.d.ts +2 -0
  11. package/package.json +81 -81
  12. package/readme.md +17 -17
  13. package/.github/workflows/npm-publish.yml +0 -24
  14. package/.madgerc +0 -3
  15. package/fix-folder-imports.js +0 -27
  16. package/src/_dependencies.ts +0 -13
  17. package/src/config.ts +0 -17
  18. package/src/exports-index.ts +0 -4
  19. package/src/helpers/Guid.ts +0 -182
  20. package/src/helpers/base64.ts +0 -174
  21. package/src/helpers/browser.test.js +0 -13
  22. package/src/helpers/browser.ts +0 -1505
  23. package/src/helpers/browserinfo.ts +0 -293
  24. package/src/helpers/collections.base.test.js +0 -26
  25. package/src/helpers/collections.base.ts +0 -438
  26. package/src/helpers/collections.ts +0 -108
  27. package/src/helpers/color.ts +0 -55
  28. package/src/helpers/cookies.ts +0 -60
  29. package/src/helpers/date.test.js +0 -120
  30. package/src/helpers/date.ts +0 -189
  31. package/src/helpers/debug.ts +0 -187
  32. package/src/helpers/diagrams.ts +0 -44
  33. package/src/helpers/emails.ts +0 -7
  34. package/src/helpers/eval.ts +0 -5
  35. package/src/helpers/exports-index.ts +0 -30
  36. package/src/helpers/file.test.js +0 -51
  37. package/src/helpers/file.ts +0 -64
  38. package/src/helpers/flatted.ts +0 -150
  39. package/src/helpers/functions.ts +0 -17
  40. package/src/helpers/graph/calendar.types.ts +0 -11
  41. package/src/helpers/graph/exports-index.ts +0 -1
  42. package/src/helpers/http.ts +0 -70
  43. package/src/helpers/images.ts +0 -23
  44. package/src/helpers/json.ts +0 -45
  45. package/src/helpers/md5.ts +0 -190
  46. package/src/helpers/objects.test.js +0 -34
  47. package/src/helpers/objects.ts +0 -275
  48. package/src/helpers/promises.test.js +0 -38
  49. package/src/helpers/promises.ts +0 -166
  50. package/src/helpers/random.ts +0 -27
  51. package/src/helpers/scheduler/exports-index.ts +0 -1
  52. package/src/helpers/scheduler/scheduler.test.js +0 -104
  53. package/src/helpers/scheduler/scheduler.ts +0 -132
  54. package/src/helpers/sharepoint.ts +0 -797
  55. package/src/helpers/strings.test.js +0 -123
  56. package/src/helpers/strings.ts +0 -338
  57. package/src/helpers/typecheckers.test.js +0 -35
  58. package/src/helpers/typecheckers.ts +0 -267
  59. package/src/helpers/url.test.js +0 -44
  60. package/src/helpers/url.ts +0 -208
  61. package/src/helpers/urlhelper.ts +0 -112
  62. package/src/index.ts +0 -6
  63. package/src/types/auth.ts +0 -63
  64. package/src/types/common.types.ts +0 -16
  65. package/src/types/exports-index.ts +0 -15
  66. package/src/types/flatted.types.ts +0 -60
  67. package/src/types/globals.types.ts +0 -7
  68. package/src/types/graph/calendar.types.ts +0 -81
  69. package/src/types/graph/exports-index.ts +0 -1
  70. package/src/types/knownscript.types.ts +0 -19
  71. package/src/types/libs/datajs.types.ts +0 -29
  72. package/src/types/libs/exports-index.ts +0 -3
  73. package/src/types/libs/ics.types.ts +0 -31
  74. package/src/types/libs/msal.types.ts +0 -58
  75. package/src/types/locales.ts +0 -126
  76. package/src/types/localstoragecache.types.ts +0 -9
  77. package/src/types/location.types.ts +0 -28
  78. package/src/types/moment.ts +0 -12
  79. package/src/types/regex.types.ts +0 -17
  80. package/src/types/rest.types.ts +0 -96
  81. package/src/types/sharepoint.types.ts +0 -1467
  82. package/src/types/sharepoint.utils.types.ts +0 -307
  83. package/src/utils/auth/common.ts +0 -119
  84. package/src/utils/auth/discovery.test.js +0 -13
  85. package/src/utils/auth/discovery.ts +0 -132
  86. package/src/utils/auth/exports-index.ts +0 -2
  87. package/src/utils/base64.ts +0 -28
  88. package/src/utils/consolelogger.ts +0 -334
  89. package/src/utils/date.ts +0 -173
  90. package/src/utils/emails.ts +0 -25
  91. package/src/utils/exports-index.ts +0 -11
  92. package/src/utils/knownscript.ts +0 -287
  93. package/src/utils/localstoragecache.ts +0 -447
  94. package/src/utils/rest.ts +0 -502
  95. package/src/utils/script.ts +0 -171
  96. package/src/utils/sharepoint.rest/common.ts +0 -160
  97. package/src/utils/sharepoint.rest/date.ts +0 -63
  98. package/src/utils/sharepoint.rest/exports-index.ts +0 -11
  99. package/src/utils/sharepoint.rest/file.folder.ts +0 -685
  100. package/src/utils/sharepoint.rest/item.ts +0 -547
  101. package/src/utils/sharepoint.rest/list.ts +0 -1572
  102. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +0 -775
  103. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +0 -275
  104. package/src/utils/sharepoint.rest/listutils/common.ts +0 -207
  105. package/src/utils/sharepoint.rest/listutils/exports-index.ts +0 -3
  106. package/src/utils/sharepoint.rest/location.ts +0 -142
  107. package/src/utils/sharepoint.rest/navigation-links.ts +0 -87
  108. package/src/utils/sharepoint.rest/user-search.ts +0 -253
  109. package/src/utils/sharepoint.rest/user.ts +0 -559
  110. package/src/utils/sharepoint.rest/web.ts +0 -1385
  111. package/src/utils/sod.ts +0 -195
@@ -1,120 +0,0 @@
1
- import assert from 'assert/strict';
2
- import test from 'node:test';
3
- import { getDateFromToken, getTotalDaysInMonth, isISODate, isISODateUTC, isNowToken, isStandardDate, isTodayToken, shiftMonths } from "./date";
4
-
5
- test('isTodayToken', t => {
6
- assert.strictEqual(isTodayToken(''), false);
7
- assert.strictEqual(isTodayToken('today'), false);
8
- assert.strictEqual(isTodayToken('[ to day]'), false);
9
- assert.strictEqual(isTodayToken('[today ]'), false);
10
- assert.strictEqual(isTodayToken('asd[today]'), false);
11
- assert.strictEqual(isTodayToken('[today]adsd'), true);
12
- assert.strictEqual(isTodayToken('[today] asd'), true);
13
- assert.strictEqual(isTodayToken('[today]'), true);
14
- });
15
-
16
- test('isNowToken', t => {
17
- assert.strictEqual(isNowToken(''), false);
18
- assert.strictEqual(isNowToken('now'), false);
19
- assert.strictEqual(isNowToken('[ now]'), false);
20
- assert.strictEqual(isNowToken('[now ]'), false);
21
- assert.strictEqual(isNowToken('asd[now]'), false);
22
- assert.strictEqual(isNowToken('[now]adsd'), true);
23
- assert.strictEqual(isNowToken('[now] asd'), true);
24
- assert.strictEqual(isNowToken('[now]'), true);
25
- });
26
-
27
- test('getDateFromToken', async t => {
28
- let now = new Date();
29
- var result = getDateFromToken('[today]+1', { now: now });
30
- var expected = new Date(now.getTime());
31
- expected.setDate(expected.getDate() + 1);
32
- await t.test('1. [today]+1', () => assert.strictEqual(result.getTime(), expected.getTime()));
33
-
34
- result = getDateFromToken('[today]-1', { now: now });
35
- expected = new Date(now.getTime());
36
- expected.setDate(expected.getDate() - 1);
37
- await t.test('1. [today]-1', () => assert.strictEqual(result.getTime(), expected.getTime()));
38
-
39
- result = getDateFromToken('[now]+15', { now: now });
40
- expected = new Date(now.getTime());
41
- expected.setMinutes(expected.getMinutes() + 15);
42
- await t.test('1. [now]+15', () => assert.strictEqual(result.getTime(), expected.getTime()));
43
-
44
- result = getDateFromToken('[now]-15', { now: now });
45
- expected = new Date(now.getTime());
46
- expected.setMinutes(expected.getMinutes() - 15);
47
- await t.test('1. [now]-15', () => assert.strictEqual(result.getTime(), expected.getTime()));
48
-
49
- let test = new Date(now.getTime());
50
- test.setHours(0, 0, 0, 0);
51
-
52
- result = getDateFromToken('[today]+1', { now: now, zeroTimeForToday: true });
53
- expected = new Date(test.getTime());
54
- expected.setDate(expected.getDate() + 1);
55
- await t.test('2. [today]+1', () => assert.strictEqual(result.getTime(), expected.getTime()));
56
-
57
- result = getDateFromToken('[today]-1', { now: now, zeroTimeForToday: true });
58
- expected = new Date(test.getTime());
59
- expected.setDate(expected.getDate() - 1);
60
- await t.test('2. [today]-1', () => assert.strictEqual(result.getTime(), expected.getTime()));
61
-
62
- });
63
-
64
- test('isStandardDate', t => {
65
- assert.strictEqual(isStandardDate(''), false);
66
- assert.strictEqual(isStandardDate('2023-08-21T15:54:14.954Z'), false);
67
- assert.strictEqual(isStandardDate('2023-08-21T15:54:14.954'), false);
68
- assert.strictEqual(isStandardDate('2023-08-21T15:54:14Z'), false);
69
- assert.strictEqual(isStandardDate('2023-08-21T15:54:14'), false);
70
- assert.strictEqual(isStandardDate('2023-08-21T15:54'), true);
71
- });
72
-
73
- test('isISODate', t => {
74
- assert.strictEqual(isISODate(''), false);
75
- assert.strictEqual(isISODate('2023-08-21T15:54:14.954Z'), true);
76
- assert.strictEqual(isISODate('2023-08-21T15:54:14.954'), true);
77
- assert.strictEqual(isISODate('2023-08-21T15:54:14Z'), true);
78
- assert.strictEqual(isISODate('2023-08-21T15:54:14'), true);
79
- assert.strictEqual(isISODate('2023-08-21T15:54'), false);
80
- });
81
-
82
- test('isISODateUTC', t => {
83
- assert.strictEqual(isISODateUTC(''), false);
84
- assert.strictEqual(isISODateUTC('2023-08-21T15:54:14.954Z'), true);
85
- assert.strictEqual(isISODateUTC('2023-08-21T15:54:14.954'), false);
86
- assert.strictEqual(isISODateUTC('2023-08-21T15:54:14Z'), true);
87
- assert.strictEqual(isISODateUTC('2023-08-21T15:54:14'), false);
88
- assert.strictEqual(isISODateUTC('2023-08-21T15:54'), false);
89
- });
90
-
91
- test('getTotalDaysInMonth', t => {
92
- var d = new Date("01-01-2023");
93
- assert.strictEqual(getTotalDaysInMonth(d), 31);
94
-
95
- d = new Date("09-01-2023");
96
- assert.strictEqual(getTotalDaysInMonth(d), 30);
97
-
98
- d = new Date("02-01-2023");
99
- assert.strictEqual(getTotalDaysInMonth(d), 28);
100
-
101
- d = new Date("02-01-2024"); //leap year
102
- assert.strictEqual(getTotalDaysInMonth(d), 29);
103
- });
104
-
105
- test('shiftMonths', t => {
106
- var d = new Date("01-31-2023");
107
- shiftMonths(d, 1)
108
- assert.strictEqual(d.getMonth() + 1, 2);
109
- assert.strictEqual(d.getDate(), 28);
110
-
111
- d = new Date("01-31-2023");
112
- shiftMonths(d, 13)
113
- assert.strictEqual(d.getMonth() + 1, 2);
114
- assert.strictEqual(d.getDate(), 29); //leap year
115
-
116
- d = new Date("01-31-2023");
117
- shiftMonths(d, -11)
118
- assert.strictEqual(d.getMonth() + 1, 2);
119
- assert.strictEqual(d.getDate(), 28);
120
- });
@@ -1,189 +0,0 @@
1
- /**
2
- * a date helper that is not relying on SharePoint or any utils at all
3
- * can be synced to the server code and external projects
4
- * do not add code that needs SP or utils -> move it to utils/date
5
- */
6
-
7
- import { endsWith } from "./strings";
8
- import { isDate, isNullOrUndefined, isString } from "./typecheckers";
9
-
10
- export function isISODateUTC(d: string) {
11
- //2023-08-21T15:54:14.954Z = true
12
- //2023-08-21T15:54:14.954 = false
13
- //2023-08-21T15:54:14Z = true
14
- //2023-08-21T15:54:14 = false
15
- //2023-08-21T15:54 = false
16
- return isISODate(d) && endsWith(d, "Z", true);
17
- }
18
-
19
- export function isISODate(d: string) {
20
- //2023-08-21T15:54:14.954Z = true
21
- //2023-08-21T15:54:14.954 = true
22
- //2023-08-21T15:54:14Z = true
23
- //2023-08-21T15:54:14 = true
24
- //2023-08-21T15:54 = false
25
- return isString(d) && /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/.test(d);
26
- }
27
-
28
- export function isStandardDate(d: string) {
29
- //2023-08-21T15:54:14.954Z = false
30
- //2023-08-21T15:54:14.954 = false
31
- //2023-08-21T15:54:14Z = false
32
- //2023-08-21T15:54:14 = false
33
- //2023-08-21T15:54 = true
34
- return isString(d) && /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.test(d);
35
- }
36
-
37
- export function parseISODate(a: string): Date | null {
38
- if (!Date.prototype.toISOString) {
39
- if (a.length < 19) {
40
- return null;
41
- }
42
- var i = Number(a.substr(0, 4)),
43
- f = Number(a.substr(5, 2)),
44
- d = Number(a.substr(8, 2)),
45
- h = Number(a.substr(11, 2)),
46
- e = Number(a.substr(14, 2)),
47
- g = Number(a.substr(17, 2));
48
- if (isNaN(i) || isNaN(f) || isNaN(d) || isNaN(h) || isNaN(e) || isNaN(g)) {
49
- return null;
50
- }
51
- // b = new Date(Date.UTC(i, f - 1, d, h, e, g));
52
- return new Date(Date.UTC(i, f - 1, d, h, e, g));
53
- } else {
54
- return new Date(a);
55
- }
56
- }
57
-
58
- /** Get now date, without seconds or milliseconds. */
59
- export function getNow() {
60
- let now = new Date();
61
- now.setSeconds(0, 0);
62
- return now;
63
- }
64
- /** Get today date, without hours, minutes, seconds or milliseconds. */
65
- export function getToday() {
66
- let today = new Date();
67
- today.setHours(0, 0, 0, 0);
68
- return today;
69
- }
70
-
71
- // eslint-disable-next-line no-shadow
72
- export enum DateFormats {
73
- YMD = "yyyy-MM-dd"
74
- }
75
- export function changeDate(options: { years?: number; months?: number; days?: number; hours?: number; minutes?: number; }, startDate?: Date): Date {
76
- let newDate = isDate(startDate) ? new Date(startDate.getTime()) : new Date();//today, or the day that was passed
77
-
78
- if (options) {
79
- if (!isNullOrUndefined(options.years))
80
- newDate.setFullYear(newDate.getFullYear() + options.years);
81
-
82
- if (!isNullOrUndefined(options.months))
83
- newDate.setMonth(newDate.getMonth() + options.months);
84
-
85
- if (!isNullOrUndefined(options.days))
86
- options.hours = (isNullOrUndefined(options.hours) ? 0 : options.hours) + (options.days * 24);
87
-
88
- if (!isNullOrUndefined(options.hours))
89
- options.minutes = (isNullOrUndefined(options.minutes) ? 0 : options.minutes) + (options.hours * 60);
90
- if (!isNullOrUndefined(options.minutes) && options.minutes !== 0)
91
- newDate = new Date(newDate.getTime() + (options.minutes * 60 * 1000));
92
- }
93
-
94
- return newDate;
95
- }
96
-
97
- export function cloneDate(date: Date) {
98
- return new Date(date.getTime());
99
- }
100
-
101
- /** Returns a new date object adjusted for the time format */
102
- export function getDateFromToken(str: string, options?: { now?: Date; zeroTimeForToday?: boolean; }) {
103
- let now = options && options.now ? new Date(options.now.getTime()) : new Date();
104
-
105
- if (!isTodayToken(str) && !isNowToken(str)) return now;
106
- let token: "Now" | "Today" = isTodayToken(str) ? "Today" : "Now";
107
- var includeTime = token === "Now";
108
- if (!includeTime && options && options.zeroTimeForToday) {
109
- now.setHours(0, 0, 0, 0);
110
- }
111
-
112
- var n = str.replace(new RegExp(`\\[${token}\\]`, "im"), "");
113
- n = n.replace(/\s/g, "");
114
- var offset = n && n !== "" ? Number(n) : 0;
115
-
116
- if (includeTime) {
117
- now.setMinutes(now.getMinutes() + offset);
118
- } else {
119
- now.setDate(now.getDate() + offset);
120
- }
121
-
122
- return now;
123
- }
124
-
125
- export function isTodayToken(str: string) {
126
- return str.match(/^\[today\]/im) !== null;
127
- }
128
- export function isNowToken(str: string) {
129
- return str.match(/^\[now\]/im) !== null;
130
- }
131
-
132
- /** Get the number of seconds from date (in the past) to now */
133
- export function getSecondsElapsed(from: Date) {
134
- let secondsElapsed = (new Date().getTime() - from.getTime()) / 1000;
135
- return secondsElapsed;
136
- }
137
-
138
- /** Get the total number of days in a given month specified by a date object */
139
- export function getTotalDaysInMonth(obj: Date) {
140
- if (isDate(obj)) {
141
- let d = new Date(obj.getFullYear(), obj.getMonth() + 1, 0);
142
- return d.getDate();
143
- }
144
- return 0;
145
- }
146
-
147
- /** Shifts the date by a certain number of months and takes into account the total number of days in the new month.
148
- * For example, if you shift January 31st by one month it will return February 28th (29th for a leap year) instead of March 3rd (2nd in leap year)
149
- */
150
- export function shiftMonths(obj: Date, months: number) {
151
- let desiredDate = obj.getDate();
152
- //move to first day to avoid skipping months (ie. Jan 31 -> March 3)
153
- obj.setDate(1);
154
- obj.setMonth(obj.getMonth() + months);
155
- obj.setDate(Math.min(desiredDate, getTotalDaysInMonth(obj)));
156
- }
157
-
158
- /**
159
- * Gets last day of month given a date
160
- */
161
- export function getLastDayOfMonth(obj: Date) {
162
- return new Date(obj.getFullYear(), obj.getMonth() + 1, 0);
163
- }
164
-
165
- // in miliseconds
166
- var units = {
167
- year: 24 * 60 * 60 * 1000 * 365,
168
- month: 24 * 60 * 60 * 1000 * 365 / 12,
169
- day: 24 * 60 * 60 * 1000,
170
- hour: 60 * 60 * 1000,
171
- minute: 60 * 1000,
172
- second: 1000
173
- }
174
-
175
- const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
176
- //const rtf = new Intl.RelativeTimeFormat('en', { style: 'short' });
177
-
178
- export function getRelativeTime(d1: Date, d2 = new Date()) {
179
- try {
180
- var elapsed = d1.getTime() - d2.getTime();
181
-
182
- // "Math.abs" accounts for both "past" & "future" scenarios
183
- for (var u in units)
184
- if (Math.abs(elapsed) > units[u] || u === 'second')
185
- return rtf.format(Math.round(elapsed / units[u]), u as Intl.RelativeTimeFormatUnit);
186
- } catch (e) {
187
- return "";
188
- }
189
- }
@@ -1,187 +0,0 @@
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
- }
@@ -1,44 +0,0 @@
1
- import { sortArray } from "./collections.base";
2
- import { isNullOrEmptyString } from "./typecheckers";
3
-
4
- export const stockUrl = "https://apps.kwizcom.com/products/apsig/images/diagrams";
5
- type DiagramInfo = {
6
- name: string;
7
- folderPrefix: string;
8
- filePrefix: string;
9
- };
10
- const diagrams: DiagramInfo[] = sortArray([
11
- { name: "Body, male, all", folderPrefix: "body-all", filePrefix: "body-all-" },
12
- { name: "Body, female, all", folderPrefix: "body-all", filePrefix: "body-all-fem-" },
13
- { name: "Body, male, front", folderPrefix: "body-frontal", filePrefix: "body-frontal-" },
14
- { name: "Body, female, front", folderPrefix: "body-frontal", filePrefix: "body-frontal-fem-" },
15
- { name: "Car", folderPrefix: "car", filePrefix: "car-" },
16
- { name: "Cat & Dog", folderPrefix: "cat-dog", filePrefix: "cat-dog-" },
17
- { name: "Cat", folderPrefix: "cat-dog", filePrefix: "cat-" },
18
- { name: "Dog", folderPrefix: "cat-dog", filePrefix: "dog-" },
19
- { name: "Face", folderPrefix: "face", filePrefix: "face-" },
20
- { name: "Pickup truck", folderPrefix: "pickup", filePrefix: "pickup-" },
21
- { name: "Shoulder & head", folderPrefix: "shoulder-head", filePrefix: "shoulder-head-" },
22
- { name: "Shoulder & head, female", folderPrefix: "shoulder-head", filePrefix: "shoulder-head-fem-" },
23
- { name: "Shoulder & head, all", folderPrefix: "shoulder-head-all", filePrefix: "shoulder-head-all-" },
24
- { name: "Shoulder & head, female, all", folderPrefix: "shoulder-head-all", filePrefix: "shoulder-head-all-fem-" },
25
- { name: "Signature line", folderPrefix: "signature", filePrefix: "signature-" }
26
- ], d => d.name);
27
- type DiagramOption = {
28
- url: string;
29
- name: string;
30
- };
31
- const diagramTypes = [{ suffix: "diagram-transparent", label: "transparent" }, { suffix: "diagram-whitebg-transparent", label: "partially transparent" }, { suffix: "diagram-whitebg", label: "" }];
32
- var diagramOptionsHiRes: DiagramOption[] = [];
33
- var diagramOptions: DiagramOption[] = [];
34
- function addDiagramOptions(info: DiagramInfo, options: DiagramOption[]) {
35
- diagramTypes.forEach(type => options.push({
36
- name: `${info.name}${isNullOrEmptyString(type.label) ? '' : `, ${type.label}`}`,
37
- url: `${info.folderPrefix}/${info.filePrefix}${type.suffix}.png`
38
- }));
39
- }
40
- diagrams.forEach(d => {
41
- addDiagramOptions(d, diagramOptionsHiRes);
42
- addDiagramOptions({ folderPrefix: `${d.folderPrefix}/small`, filePrefix: d.filePrefix, name: `${d.name}, small` }, diagramOptions);
43
- });
44
- export const DiagramOptions = { options: diagramOptions, hiRes: diagramOptionsHiRes };
@@ -1,7 +0,0 @@
1
- import { isNullOrEmptyString } from "./typecheckers";
2
-
3
- export function isValidEmail(email: string) {
4
- return !isNullOrEmptyString(email) && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
5
- }
6
-
7
- export const freeEmailNotAllowedMessage = "Please use a work email, free emails are not allowed";
@@ -1,5 +0,0 @@
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,30 +0,0 @@
1
- export * from './graph/exports-index';
2
- export * from './scheduler/exports-index';
3
- export * from './Guid';
4
- export * from './base64';
5
- export * from './browser';
6
- export * from './browserinfo';
7
- export * from './collections.base';
8
- export * from './collections';
9
- export * from './color';
10
- export * from './cookies';
11
- export * from './date';
12
- export * from './debug';
13
- export * from './diagrams';
14
- export * from './emails';
15
- export * from './eval';
16
- export * from './file';
17
- export * from './flatted';
18
- export * from './functions';
19
- export * from './http';
20
- export * from './images';
21
- export * from './json';
22
- export * from './md5';
23
- export * from './objects';
24
- export * from './promises';
25
- export * from './random';
26
- export * from './sharepoint';
27
- export * from './strings';
28
- export * from './typecheckers';
29
- export * from './url';
30
- export * from './urlhelper';
@@ -1,51 +0,0 @@
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
- });