@kwiz/common 1.0.107 → 1.0.109

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