@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
package/src/utils/sod.ts CHANGED
@@ -1,195 +1,195 @@
1
- import { isDebug } from "../helpers/debug";
2
- import { getFromFullName, isFunction, isNullOrEmptyString, isNullOrUndefined, isString, isTypeofFullNameNullOrUndefined, typeofFullName } from "../helpers/typecheckers";
3
- import { ksGlobal } from "../types/knownscript.types";
4
-
5
- declare global {
6
- interface Window {
7
- g_kwizcom_sods: { [sodName: string]: Sod; };
8
- }
9
- }
10
-
11
- interface ISodCallback {
12
- called: boolean;
13
- callback: () => void;
14
- }
15
-
16
- // eslint-disable-next-line no-shadow
17
- enum SodState {
18
- pending = "pending",
19
- done = "done"
20
- }
21
-
22
- export default class Sod {
23
- private sodName: string;
24
- private url: string;
25
- private script: HTMLScriptElement;
26
- private state: string;
27
- private notified: boolean;
28
- private callbacks: ISodCallback[];
29
-
30
- public constructor(url: string, sodName: string) {
31
- this.url = url;
32
- this.sodName = sodName;
33
- this.state = SodState.pending;
34
- this.notified = false;
35
- this.callbacks = [];
36
- this.script = null;
37
- }
38
-
39
- private error() {
40
- if (isDebug()) console.log('unhandled error in sod');
41
- }
42
-
43
- private loadScript(scriptUrl: string, sync = false) {
44
- let self = this;
45
- var successCallback = () => {
46
- self.load();
47
- };
48
- var errorCallback = () => {
49
- self.error();
50
- };
51
- self.script = Sod.loadScript(scriptUrl, successCallback, errorCallback, sync);
52
- self.state = SodState.pending;
53
- }
54
-
55
- private load() {
56
- let self = this;
57
- self.state = SodState.done;
58
- if (!self.notified) {
59
- self.notify();
60
- }
61
- }
62
-
63
- private notify() {
64
- let self = this;
65
- var callbackLength = self.callbacks.length;
66
- for (var i = 0; i < callbackLength; i++) {
67
- var sodCallback = self.callbacks[i];
68
- if (!sodCallback.called && typeof (sodCallback.callback) === "function") {
69
- try {
70
- sodCallback.callback();
71
- sodCallback.called = true;
72
- } catch (ex) {
73
- if (isDebug()) console.log('unhandled error in sod');
74
- }
75
- }
76
- }
77
- self.notified = true;
78
- }
79
-
80
- private reset() {
81
- let self = this;
82
- var callbackLength = self.callbacks.length;
83
- for (var i = 0; i < callbackLength; i++) {
84
- this.callbacks[i].called = false;
85
- }
86
- self.notified = false;
87
- }
88
-
89
- private static loadScript(url: string, successCallback: () => void, errCallback: () => void, sync = false) {
90
- let scriptElm = document.createElement("script");
91
- if (sync === true) {
92
- let req = new XMLHttpRequest();
93
- req.open("GET", url, false);
94
- req.send();
95
- scriptElm.appendChild(document.createTextNode(req.responseText));
96
- successCallback();
97
- }
98
- else {
99
- let agt = navigator.userAgent.toLowerCase();
100
- let ie8down = agt.indexOf("msie") !== -1 && parseInt(agt.substring(agt.indexOf("msie ") + 5), 10) <= 8;
101
-
102
- let getCallback = (cb: () => void) => {
103
- return () => {
104
- var loaded = false;
105
-
106
- if (ie8down && typeof (scriptElm as any).readyState !== "undefined") {
107
- loaded = (scriptElm as any).readyState === "complete" || (scriptElm as any).readyState === "loaded";
108
- } else {
109
- loaded = true;
110
- }
111
-
112
- if (loaded) {
113
- (scriptElm as any).onreadystatechange = null;
114
- scriptElm.onload = null;
115
- scriptElm.onerror = null;
116
- cb();
117
- }
118
- };
119
- };
120
-
121
- scriptElm.type = "text/javascript";
122
- scriptElm.src = url;
123
- if (ie8down) {
124
- (scriptElm as any).onreadystatechange = getCallback(successCallback);
125
- } else {
126
- scriptElm.onload = getCallback(successCallback);
127
- scriptElm.onerror = getCallback(errCallback);
128
- }
129
- }
130
- (document.head || document.getElementsByTagName("HEAD")[0]).appendChild(scriptElm);
131
- return scriptElm;
132
- }
133
-
134
- public static getGlobal(global: ksGlobal) {
135
- if (isString(global))
136
- return getFromFullName(global);
137
- else
138
- return global.getter();
139
- }
140
-
141
- public static ensureScriptNoPromise(scriptUrl: string, global: ksGlobal, callback?: () => void, sodName?: string, sync = false) {
142
- if (!isNullOrEmptyString(global) && typeofFullName(Sod.getGlobal(global)) !== "undefined") {
143
- //this global object already exists, no need to reload this script.
144
- if (isFunction(callback)) {
145
- callback();
146
- }
147
- }
148
- else {
149
- sodName = (isNullOrEmptyString(sodName) === false && sodName || scriptUrl).toLowerCase();
150
- var sod = Sod._getGlobalSod(sodName);
151
-
152
- if (!sod) {
153
- sod = Sod._addGlobalSod(sodName, scriptUrl);
154
- }
155
-
156
- if (!isNullOrUndefined(callback)) {
157
- sod.callbacks.push({ "called": false, "callback": callback });
158
- }
159
-
160
- if (!sod.script) {
161
- sod.loadScript(scriptUrl, sync);
162
- } else if (sod.state === SodState.done || sod.notified) {
163
- sod.notify();
164
- }
165
- }
166
- }
167
-
168
- public static async ensureScript(scriptUrl: string, global: ksGlobal, callback?: () => void, sodName?: string, sync = false): Promise<void> {
169
- return new Promise<void>((resolve, reject) => {
170
- let resolveCallback = () => {
171
- if (!isNullOrUndefined(callback)) callback();
172
- resolve();
173
- };
174
- Sod.ensureScriptNoPromise(scriptUrl, global, resolveCallback, sodName, sync);
175
- });
176
- }
177
-
178
- private static _initGlobalSods() {
179
- //static must be globally shared between all instances...
180
- if (isTypeofFullNameNullOrUndefined("g_kwizcom_sods")) {
181
- window.g_kwizcom_sods = {};
182
- }
183
- }
184
-
185
- private static _getGlobalSod(name: string) {
186
- Sod._initGlobalSods();
187
- return window.g_kwizcom_sods[name];
188
- }
189
-
190
- private static _addGlobalSod(name: string, scriptUrl: string) {
191
- Sod._initGlobalSods();
192
- window.g_kwizcom_sods[name] = new Sod(scriptUrl, name);
193
- return window.g_kwizcom_sods[name];
194
- }
1
+ import { isDebug } from "../helpers/debug";
2
+ import { getFromFullName, isFunction, isNullOrEmptyString, isNullOrUndefined, isString, isTypeofFullNameNullOrUndefined, typeofFullName } from "../helpers/typecheckers";
3
+ import { ksGlobal } from "../types/knownscript.types";
4
+
5
+ declare global {
6
+ interface Window {
7
+ g_kwizcom_sods: { [sodName: string]: Sod; };
8
+ }
9
+ }
10
+
11
+ interface ISodCallback {
12
+ called: boolean;
13
+ callback: () => void;
14
+ }
15
+
16
+ // eslint-disable-next-line no-shadow
17
+ enum SodState {
18
+ pending = "pending",
19
+ done = "done"
20
+ }
21
+
22
+ export default class Sod {
23
+ private sodName: string;
24
+ private url: string;
25
+ private script: HTMLScriptElement;
26
+ private state: string;
27
+ private notified: boolean;
28
+ private callbacks: ISodCallback[];
29
+
30
+ public constructor(url: string, sodName: string) {
31
+ this.url = url;
32
+ this.sodName = sodName;
33
+ this.state = SodState.pending;
34
+ this.notified = false;
35
+ this.callbacks = [];
36
+ this.script = null;
37
+ }
38
+
39
+ private error() {
40
+ if (isDebug()) console.log('unhandled error in sod');
41
+ }
42
+
43
+ private loadScript(scriptUrl: string, sync = false) {
44
+ let self = this;
45
+ var successCallback = () => {
46
+ self.load();
47
+ };
48
+ var errorCallback = () => {
49
+ self.error();
50
+ };
51
+ self.script = Sod.loadScript(scriptUrl, successCallback, errorCallback, sync);
52
+ self.state = SodState.pending;
53
+ }
54
+
55
+ private load() {
56
+ let self = this;
57
+ self.state = SodState.done;
58
+ if (!self.notified) {
59
+ self.notify();
60
+ }
61
+ }
62
+
63
+ private notify() {
64
+ let self = this;
65
+ var callbackLength = self.callbacks.length;
66
+ for (var i = 0; i < callbackLength; i++) {
67
+ var sodCallback = self.callbacks[i];
68
+ if (!sodCallback.called && typeof (sodCallback.callback) === "function") {
69
+ try {
70
+ sodCallback.callback();
71
+ sodCallback.called = true;
72
+ } catch (ex) {
73
+ if (isDebug()) console.log('unhandled error in sod');
74
+ }
75
+ }
76
+ }
77
+ self.notified = true;
78
+ }
79
+
80
+ private reset() {
81
+ let self = this;
82
+ var callbackLength = self.callbacks.length;
83
+ for (var i = 0; i < callbackLength; i++) {
84
+ this.callbacks[i].called = false;
85
+ }
86
+ self.notified = false;
87
+ }
88
+
89
+ private static loadScript(url: string, successCallback: () => void, errCallback: () => void, sync = false) {
90
+ let scriptElm = document.createElement("script");
91
+ if (sync === true) {
92
+ let req = new XMLHttpRequest();
93
+ req.open("GET", url, false);
94
+ req.send();
95
+ scriptElm.appendChild(document.createTextNode(req.responseText));
96
+ successCallback();
97
+ }
98
+ else {
99
+ let agt = navigator.userAgent.toLowerCase();
100
+ let ie8down = agt.indexOf("msie") !== -1 && parseInt(agt.substring(agt.indexOf("msie ") + 5), 10) <= 8;
101
+
102
+ let getCallback = (cb: () => void) => {
103
+ return () => {
104
+ var loaded = false;
105
+
106
+ if (ie8down && typeof (scriptElm as any).readyState !== "undefined") {
107
+ loaded = (scriptElm as any).readyState === "complete" || (scriptElm as any).readyState === "loaded";
108
+ } else {
109
+ loaded = true;
110
+ }
111
+
112
+ if (loaded) {
113
+ (scriptElm as any).onreadystatechange = null;
114
+ scriptElm.onload = null;
115
+ scriptElm.onerror = null;
116
+ cb();
117
+ }
118
+ };
119
+ };
120
+
121
+ scriptElm.type = "text/javascript";
122
+ scriptElm.src = url;
123
+ if (ie8down) {
124
+ (scriptElm as any).onreadystatechange = getCallback(successCallback);
125
+ } else {
126
+ scriptElm.onload = getCallback(successCallback);
127
+ scriptElm.onerror = getCallback(errCallback);
128
+ }
129
+ }
130
+ (document.head || document.getElementsByTagName("HEAD")[0]).appendChild(scriptElm);
131
+ return scriptElm;
132
+ }
133
+
134
+ public static getGlobal(global: ksGlobal) {
135
+ if (isString(global))
136
+ return getFromFullName(global);
137
+ else
138
+ return global.getter();
139
+ }
140
+
141
+ public static ensureScriptNoPromise(scriptUrl: string, global: ksGlobal, callback?: () => void, sodName?: string, sync = false) {
142
+ if (!isNullOrEmptyString(global) && typeofFullName(Sod.getGlobal(global)) !== "undefined") {
143
+ //this global object already exists, no need to reload this script.
144
+ if (isFunction(callback)) {
145
+ callback();
146
+ }
147
+ }
148
+ else {
149
+ sodName = (isNullOrEmptyString(sodName) === false && sodName || scriptUrl).toLowerCase();
150
+ var sod = Sod._getGlobalSod(sodName);
151
+
152
+ if (!sod) {
153
+ sod = Sod._addGlobalSod(sodName, scriptUrl);
154
+ }
155
+
156
+ if (!isNullOrUndefined(callback)) {
157
+ sod.callbacks.push({ "called": false, "callback": callback });
158
+ }
159
+
160
+ if (!sod.script) {
161
+ sod.loadScript(scriptUrl, sync);
162
+ } else if (sod.state === SodState.done || sod.notified) {
163
+ sod.notify();
164
+ }
165
+ }
166
+ }
167
+
168
+ public static async ensureScript(scriptUrl: string, global: ksGlobal, callback?: () => void, sodName?: string, sync = false): Promise<void> {
169
+ return new Promise<void>((resolve, reject) => {
170
+ let resolveCallback = () => {
171
+ if (!isNullOrUndefined(callback)) callback();
172
+ resolve();
173
+ };
174
+ Sod.ensureScriptNoPromise(scriptUrl, global, resolveCallback, sodName, sync);
175
+ });
176
+ }
177
+
178
+ private static _initGlobalSods() {
179
+ //static must be globally shared between all instances...
180
+ if (isTypeofFullNameNullOrUndefined("g_kwizcom_sods")) {
181
+ window.g_kwizcom_sods = {};
182
+ }
183
+ }
184
+
185
+ private static _getGlobalSod(name: string) {
186
+ Sod._initGlobalSods();
187
+ return window.g_kwizcom_sods[name];
188
+ }
189
+
190
+ private static _addGlobalSod(name: string, scriptUrl: string) {
191
+ Sod._initGlobalSods();
192
+ window.g_kwizcom_sods[name] = new Sod(scriptUrl, name);
193
+ return window.g_kwizcom_sods[name];
194
+ }
195
195
  }
package/.madgerc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "fileExtensions": ["js", "ts"]
3
- }
@@ -1,27 +0,0 @@
1
- const glob = require('glob');
2
- const fs = require("fs-extra");
3
- const exportsFileName = "exports-index";
4
- const exportsFileNameWithExt = `${exportsFileName}.ts`;
5
- const exportsIndexFiles = glob.sync(`./src/**/${exportsFileNameWithExt}`);
6
- //loop every exportsIndexFiles and find any import to a directory, and replace with /exports-index
7
- console.time("fixing direcry imports");
8
- exportsIndexFiles.forEach(file => {
9
- var content = fs.readFileSync(file, "utf8").split("\n");
10
- var parentFolderContent = fs.readdirSync(file.replace(exportsFileNameWithExt, ''));
11
- var hasChanges = false;
12
- //loop every import - if it does not match a file in the folder, but matches a sub-folder - append exports-index to it
13
- content.forEach((line, idx) => {
14
- if (line.replace(/ /g, '').length > 0) {
15
- let importName = line.slice(line.indexOf('./') + 2, line.length - 2);
16
- if (parentFolderContent.includes(importName))//its a folder, otherwise it would be .ts
17
- {
18
- content[idx] = line.replace(`./${importName}`, `./${importName}/${exportsFileName}`);
19
- hasChanges = true;
20
- }
21
- }
22
- });
23
- if (hasChanges) {
24
- fs.writeFileSync(file, content.join('\n'));
25
- }
26
- });
27
- console.timeEnd("fixing direcry imports");