@kwiz/common 1.0.127 → 1.0.128

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