@kwiz/common 1.0.107 → 1.0.108

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