@kwiz/common 1.0.132 → 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 (98) hide show
  1. package/package.json +1 -1
  2. package/.github/workflows/npm-publish.yml +0 -24
  3. package/src/_dependencies.ts +0 -13
  4. package/src/config.ts +0 -19
  5. package/src/exports-index.ts +0 -4
  6. package/src/helpers/Guid.ts +0 -182
  7. package/src/helpers/base64.ts +0 -174
  8. package/src/helpers/browser.test.js +0 -13
  9. package/src/helpers/browser.ts +0 -1505
  10. package/src/helpers/browserinfo.ts +0 -293
  11. package/src/helpers/collections.base.test.js +0 -26
  12. package/src/helpers/collections.base.ts +0 -438
  13. package/src/helpers/collections.ts +0 -108
  14. package/src/helpers/color.ts +0 -55
  15. package/src/helpers/cookies.ts +0 -60
  16. package/src/helpers/date.test.js +0 -120
  17. package/src/helpers/date.ts +0 -189
  18. package/src/helpers/debug.ts +0 -187
  19. package/src/helpers/diagrams.ts +0 -44
  20. package/src/helpers/emails.ts +0 -7
  21. package/src/helpers/eval.ts +0 -5
  22. package/src/helpers/exports-index.ts +0 -30
  23. package/src/helpers/file.test.js +0 -51
  24. package/src/helpers/file.ts +0 -64
  25. package/src/helpers/flatted.ts +0 -150
  26. package/src/helpers/functions.ts +0 -17
  27. package/src/helpers/graph/calendar.types.ts +0 -11
  28. package/src/helpers/graph/exports-index.ts +0 -1
  29. package/src/helpers/http.ts +0 -70
  30. package/src/helpers/images.ts +0 -23
  31. package/src/helpers/json.ts +0 -45
  32. package/src/helpers/md5.ts +0 -190
  33. package/src/helpers/objects.test.js +0 -34
  34. package/src/helpers/objects.ts +0 -275
  35. package/src/helpers/promises.test.js +0 -38
  36. package/src/helpers/promises.ts +0 -166
  37. package/src/helpers/random.ts +0 -27
  38. package/src/helpers/scheduler/exports-index.ts +0 -1
  39. package/src/helpers/scheduler/scheduler.test.js +0 -104
  40. package/src/helpers/scheduler/scheduler.ts +0 -132
  41. package/src/helpers/sharepoint.ts +0 -797
  42. package/src/helpers/strings.test.js +0 -123
  43. package/src/helpers/strings.ts +0 -338
  44. package/src/helpers/typecheckers.test.js +0 -35
  45. package/src/helpers/typecheckers.ts +0 -267
  46. package/src/helpers/url.test.js +0 -44
  47. package/src/helpers/url.ts +0 -208
  48. package/src/helpers/urlhelper.ts +0 -112
  49. package/src/index.ts +0 -6
  50. package/src/types/auth.ts +0 -63
  51. package/src/types/common.types.ts +0 -16
  52. package/src/types/exports-index.ts +0 -15
  53. package/src/types/flatted.types.ts +0 -60
  54. package/src/types/globals.types.ts +0 -7
  55. package/src/types/graph/calendar.types.ts +0 -81
  56. package/src/types/graph/exports-index.ts +0 -1
  57. package/src/types/knownscript.types.ts +0 -19
  58. package/src/types/libs/datajs.types.ts +0 -29
  59. package/src/types/libs/exports-index.ts +0 -3
  60. package/src/types/libs/ics.types.ts +0 -31
  61. package/src/types/libs/msal.types.ts +0 -58
  62. package/src/types/locales.ts +0 -126
  63. package/src/types/localstoragecache.types.ts +0 -9
  64. package/src/types/location.types.ts +0 -28
  65. package/src/types/moment.ts +0 -12
  66. package/src/types/regex.types.ts +0 -17
  67. package/src/types/rest.types.ts +0 -96
  68. package/src/types/sharepoint.types.ts +0 -1467
  69. package/src/types/sharepoint.utils.types.ts +0 -307
  70. package/src/utils/auth/common.ts +0 -119
  71. package/src/utils/auth/discovery.test.js +0 -13
  72. package/src/utils/auth/discovery.ts +0 -132
  73. package/src/utils/auth/exports-index.ts +0 -2
  74. package/src/utils/base64.ts +0 -28
  75. package/src/utils/consolelogger.ts +0 -334
  76. package/src/utils/date.ts +0 -173
  77. package/src/utils/emails.ts +0 -25
  78. package/src/utils/exports-index.ts +0 -11
  79. package/src/utils/knownscript.ts +0 -287
  80. package/src/utils/localstoragecache.ts +0 -447
  81. package/src/utils/rest.ts +0 -502
  82. package/src/utils/script.ts +0 -171
  83. package/src/utils/sharepoint.rest/common.ts +0 -160
  84. package/src/utils/sharepoint.rest/date.ts +0 -63
  85. package/src/utils/sharepoint.rest/exports-index.ts +0 -11
  86. package/src/utils/sharepoint.rest/file.folder.ts +0 -685
  87. package/src/utils/sharepoint.rest/item.ts +0 -547
  88. package/src/utils/sharepoint.rest/list.ts +0 -1572
  89. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +0 -775
  90. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +0 -275
  91. package/src/utils/sharepoint.rest/listutils/common.ts +0 -207
  92. package/src/utils/sharepoint.rest/listutils/exports-index.ts +0 -3
  93. package/src/utils/sharepoint.rest/location.ts +0 -142
  94. package/src/utils/sharepoint.rest/navigation-links.ts +0 -87
  95. package/src/utils/sharepoint.rest/user-search.ts +0 -253
  96. package/src/utils/sharepoint.rest/user.ts +0 -559
  97. package/src/utils/sharepoint.rest/web.ts +0 -1385
  98. package/src/utils/sod.ts +0 -195
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwiz/common",
3
- "version": "1.0.132",
3
+ "version": "1.0.133",
4
4
  "description": "KWIZ common utilities and helpers for M365 platform",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -1,24 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- push:
8
- tags:
9
- - 'v*.*.*' # run every time we commit with a new version number
10
-
11
- jobs:
12
- build-publish-npm:
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v4
16
- - uses: actions/setup-node@v4
17
- with:
18
- node-version: 18
19
- registry-url: https://registry.npmjs.org/
20
- - run: npm ci
21
- - run: npm run build
22
- - run: npm publish --access public
23
- env:
24
- NODE_AUTH_TOKEN: ${{secrets.KWIZ_NPM_TOKEN}}
@@ -1,13 +0,0 @@
1
-
2
- export var BuildNumber = "unset";
3
- export var IsLocalDev = false;
4
- export var ReleaseStatus = "npm";
5
- export function SetDependencies(params: {
6
- BuildNumber?: string;
7
- IsLocalDev?: boolean;
8
- ReleaseStatus?: string;
9
- }) {
10
- if (typeof params.BuildNumber === "string") BuildNumber = params.BuildNumber;
11
- if (typeof params.IsLocalDev === "boolean") IsLocalDev = params.IsLocalDev;
12
- if (typeof params.ReleaseStatus === "string") ReleaseStatus = params.ReleaseStatus;
13
- }
package/src/config.ts DELETED
@@ -1,19 +0,0 @@
1
- import { SetDependencies } from './_dependencies';
2
- import { ConsoleLogger } from './utils/consolelogger';
3
-
4
- export function config(params: {
5
- BuildNumber?: string;
6
- IsLocalDev?: boolean;
7
- ReleaseStatus?: string;
8
- ProjectName?: string;
9
- }) {
10
- SetDependencies(params);
11
- function GetLogger(name: string) {
12
- return ConsoleLogger.get(name, params.ProjectName);
13
- }
14
- return {
15
- GetLogger,
16
- /** @deprecated exported as GetLogger, which is how is used anyways */
17
- logger: GetLogger
18
- }
19
- }
@@ -1,4 +0,0 @@
1
- export * from './helpers/exports-index';
2
- export * from './types/exports-index';
3
- export * from './utils/exports-index';
4
- export * from './config';
@@ -1,182 +0,0 @@
1
- /**
2
- * This class represents a globally unique identifier, as described by
3
- * IETF RFC 4122.
4
- *
5
- * @remarks
6
- * The input string is normalized and validated, which provides
7
- * important guarantees that simplify other code that works with the GUID.
8
- * This class also provides basic support for generating a pseudo-random GUID;
9
- * however, be aware that the uniqueness depends on the browser's `Math.random()`
10
- * function and may be not be suitable for some applications.
11
- *
12
- * See {@link https://www.ietf.org/rfc/rfc4122.txt | RFC4122} for more information.
13
- *
14
- * @public
15
- */
16
-
17
- import { isNullOrEmptyString, isNullOrUndefined } from "./typecheckers";
18
-
19
- export class Guid {
20
- private _guid;
21
- /**
22
- * Returns a new empty Guid instance.
23
- *
24
- * @returns A new empty Guid object.
25
- */
26
- public static empty = new Guid('00000000-0000-0000-0000-000000000000');
27
- private static _guidRegEx = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i;
28
-
29
- /**
30
- * Use `Guid.parse()` or `Guid.tryParse()` instead of the constructor.
31
- * @param guid - a normalized, already valid Guid string
32
- */
33
- constructor(guid) {
34
- this._guid = guid;
35
- }
36
- /**
37
- * Returns a new Guid instance with a pseudo-randomly generated GUID, according
38
- * to the version 4 UUID algorithm from RFC 4122.
39
- *
40
- * @returns A new unique Guid object
41
- */
42
- public static newGuid(randomNumberGenerator) {
43
- return new Guid(Guid._generateGuid(randomNumberGenerator));
44
- }
45
- /**
46
- * Parses the input string to construct a new Guid object.
47
- * If the string cannot be parsed, then an error is thrown.
48
- *
49
- * @remarks
50
- * Example syntaxes accepted by this function:
51
- *
52
- * - `"d5369f3bbd7a412a9c0f7f0650bb5489"`
53
- *
54
- * - `"d5369f3b-bd7a-412a-9c0f-7f0650bb5489"`
55
- *
56
- * - `"{d5369f3b-bd7a-412a-9c0f-7f0650bb5489}"`
57
- *
58
- * - `"/Guid(d5369f3b-bd7a-412a-9c0f-7f0650bb5489)/"`
59
- *
60
- * @param guid - The input string.
61
- * @returns A valid Guid object
62
- */
63
- public static parse(guidString) {
64
- var guid = Guid.tryParse(guidString);
65
- if (!guid) {
66
- throw new Error(`***Invalid GUID string: "${guidString}"`)
67
- }
68
- return guid;
69
- }
70
- /**
71
- * Attempts to parse the input string to construct a new Guid object.
72
- * If the string cannot be parsed, then undefined is returned.
73
- *
74
- * @remarks
75
- * Example syntaxes accepted by this function:
76
- *
77
- * - `"d5369f3bbd7a412a9c0f7f0650bb5489"`
78
- *
79
- * - `"d5369f3b-bd7a-412a-9c0f-7f0650bb5489"`
80
- *
81
- * - `"{d5369f3b-bd7a-412a-9c0f-7f0650bb5489}"`
82
- *
83
- * - `"/Guid(d5369f3b-bd7a-412a-9c0f-7f0650bb5489)/"`
84
- *
85
- * @param guid - The input string.
86
- * @returns The Guid object, or undefined if the string could not be parsed.
87
- */
88
- public static tryParse(guid) {
89
- if (guid) {
90
- guid = Guid._normalize(guid);
91
- if (Guid._guidRegEx.test(guid)) {
92
- return new Guid(guid);
93
- }
94
- }
95
- return undefined;
96
- }
97
- /**
98
- * Indicates whether a GUID is valid, i.e. whether it would be successfully
99
- * parsed by `Guid.tryParse()`. This function is cheaper than `Guid.tryParse()`
100
- * because it does not construct a Guid object.
101
- *
102
- * @param guid - The input string.
103
- * @returns true, if the Guid is valid.
104
- */
105
- public static isValid(guid) {
106
- if (guid) {
107
- guid = Guid._normalize(guid);
108
- if (Guid._guidRegEx.test(guid)) {
109
- return true;
110
- }
111
- }
112
- return false;
113
- }
114
- /**
115
- * SharePoint can have guids in the form:
116
- * - `Guid(...)`
117
- * - `{...}`
118
- * _normalize transforms guids in this format to the standard
119
- * guid format.
120
- *
121
- * Example: `Guid(d5369f3b-bd7a-412a-9c0f-7f0650bb5489)` becomes `d5369f3b-bd7a-412a-9c0f-7f0650bb5489`
122
- * Example: `{d5369f3b-bd7a-412a-9c0f-7f0650bb5489}` becomes `d5369f3b-bd7a-412a-9c0f-7f0650bb5489`
123
- *
124
- * @param guid - Guid to be normalized, could already be normalized.
125
- * @returns Normalized guid.
126
- */
127
- private static _normalize(guid) {
128
- if (isNullOrEmptyString(guid)) {
129
- throw new Error(`***The value for "guid" must not be an empty string`)
130
- }
131
- // Check for Guid(...) and strip
132
- var result = /^Guid\((.*)\)/i.exec(guid); /* tslint:disable-line:no-null-keyword */
133
- if (result) {
134
- guid = result[1];
135
- }
136
- // Check for and strip leading or trailing curly braces
137
- if (guid.length === 38) {
138
- guid = guid.substr(1, 36);
139
- }
140
- return guid.toLowerCase();
141
- }
142
- /**
143
- * Creates a new guid.
144
- *
145
- * @returns A valid guid (according to RFC4122)
146
- */
147
- private static _generateGuid(randomNumberGenerator) {
148
- return 'AAAAAAAA-AAAA-4AAA-BAAA-AAAAAAAAAAAA'.replace(/[AB]/g,
149
- // Callback for String.replace() when generating a guid.
150
- function (character) {
151
- var randomNumber = randomNumberGenerator ? randomNumberGenerator.generate() : Math.random();
152
- /* tslint:disable:no-bitwise */
153
- var num = randomNumber * 16 | 0;
154
- // Check for 'A' in template string because the first characters in the
155
- // third and fourth blocks must be specific characters (according to "version 4" UUID from RFC 4122)
156
- var masked = character === 'A' ? num : (num & 0x3 | 0x8);
157
- return masked.toString(16);
158
- });
159
- }
160
- /**
161
- * Compare this instance to another Guid instance
162
- *
163
- * @returns True if this instance and the specified Guid object
164
- * represent the same value.
165
- */
166
- public equals(guid) {
167
- if (isNullOrUndefined(guid)) {
168
- throw new Error(`"***The value for "guid" must not be null or undefined"`)
169
- }
170
- return guid && this._guid.toString() === guid.toString();
171
- }
172
- /**
173
- * Returns a string representation of the GUID
174
- *
175
- * @returns The GUID value in lowercase hexadecimal without braces.
176
- *
177
- * Example: `'d5369f3b-bd7a-412a-9c0f-7f0650bb5489'`
178
- */
179
- public toString = function () {
180
- return this._guid;
181
- }
182
- }
@@ -1,174 +0,0 @@
1
-
2
- export async function blobToBase64(data: Blob): Promise<string> {
3
- return new Promise<string>((resolve, reject) => {
4
- var fileReader = new FileReader();
5
- fileReader.onloadend = () => {
6
- resolve(fileReader.result as string);
7
- };
8
- fileReader.onerror = () => {
9
- reject();
10
- };
11
- fileReader.readAsDataURL(data);
12
- });
13
- }
14
-
15
- /** returns true of the string is a data: with base64 content */
16
- export function isBase64ImageData(str: string): boolean {
17
- return str.startsWith("data") && str.indexOf("base64") > 0;
18
- }
19
-
20
- const alphabet = [
21
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
22
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
23
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
24
- 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
25
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
26
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
27
- 'w', 'x', 'y', 'z', '0', '1', '2', '3',
28
- '4', '5', '6', '7', '8', '9', '+', '/'
29
- ];
30
-
31
- const values = {};
32
- for (let i = 0; i < alphabet.length; ++i) {
33
- values[alphabet[i]] = i;
34
- }
35
-
36
- function encode(bytes: ArrayBuffer): string {
37
- const array = new Uint8Array(bytes);
38
- const base64 = [];
39
- let index = 0;
40
- let quantum;
41
- let value;
42
-
43
- // Grab as many sets of 3 bytes as we can, that form 24 bits.
44
- while (index + 2 < array.byteLength) {
45
- quantum = (array[index] << 16) | (array[index + 1] << 8) | array[index + 2];
46
- // 24 bits will become 4 base64 chars.
47
- value = (quantum >> 18) & 0x3f;
48
- base64.push(alphabet[value]);
49
- value = (quantum >> 12) & 0x3f;
50
- base64.push(alphabet[value]);
51
- value = (quantum >> 6) & 0x3f;
52
- base64.push(alphabet[value]);
53
- value = quantum & 0x3f;
54
- base64.push(alphabet[value]);
55
- index += 3;
56
- }
57
- // At this point, there are 0, 1 or 2 bytes left.
58
- if (index + 1 === array.byteLength) {
59
- // 8 bits; shift by 4 to pad on the right with 0s to make 12 bits total.
60
- quantum = array[index] << 4;
61
- value = (quantum >> 6) & 0x3f;
62
- base64.push(alphabet[value]);
63
- value = quantum & 0x3f;
64
- base64.push(alphabet[value]);
65
- base64.push('==');
66
- } else if (index + 2 === array.byteLength) {
67
- // 16 bits; shift by 2 to pad on the right with 0s to make 18 bits total.
68
- quantum = (array[index] << 10) | (array[index + 1] << 2);
69
- value = (quantum >> 12) & 0x3f;
70
- base64.push(alphabet[value]);
71
- value = (quantum >> 6) & 0x3f;
72
- base64.push(alphabet[value]);
73
- value = quantum & 0x3f;
74
- base64.push(alphabet[value]);
75
- base64.push('=');
76
- }
77
- return base64.join('');
78
- }
79
-
80
- function decode(string: string): Uint8Array {
81
- let size = string.length;
82
- if (size === 0) {
83
- return new Uint8Array(new ArrayBuffer(0));
84
- }
85
- if (size % 4 !== 0) {
86
- throw new Error('Bad length: ' + size);
87
- }
88
- if (!string.match(/^[a-zA-Z0-9+/]+={0,2}$/)) {
89
- throw new Error('Invalid base64 encoded value');
90
- }
91
- // Every 4 base64 chars = 24 bits = 3 bytes. But, we also need to figure out
92
- // padding, if any.
93
- let bytes = 3 * (size / 4);
94
- let numPad = 0;
95
- if (string.charAt(size - 1) === '=') {
96
- numPad++;
97
- bytes--;
98
- }
99
- if (string.charAt(size - 2) === '=') {
100
- numPad++;
101
- bytes--;
102
- }
103
- const buffer = new Uint8Array(new ArrayBuffer(bytes));
104
- let index = 0;
105
- let bufferIndex = 0;
106
- let quantum;
107
- if (numPad > 0) {
108
- size -= 4; // handle the last one specially
109
- }
110
-
111
- while (index < size) {
112
- quantum = 0;
113
- for (let i = 0; i < 4; ++i) {
114
- quantum = (quantum << 6) | values[string.charAt(index + i)];
115
- }
116
- // quantum is now a 24-bit value.
117
- buffer[bufferIndex++] = (quantum >> 16) & 0xff;
118
- buffer[bufferIndex++] = (quantum >> 8) & 0xff;
119
- buffer[bufferIndex++] = quantum & 0xff;
120
- index += 4;
121
- }
122
- if (numPad > 0) {
123
- // if numPad === 1, there is one =, and we have 18 bits with 2 0s at end.
124
- // if numPad === 2, there is two ==, and we have 12 bits with 4 0s at end.
125
- // First, grab my quantum.
126
- quantum = 0;
127
- for (let i = 0; i < 4 - numPad; ++i) {
128
- quantum = (quantum << 6) | values[string.charAt(index + i)];
129
- }
130
- if (numPad === 1) {
131
- // quantum is 18 bits, but really represents two bytes.
132
- quantum = quantum >> 2;
133
- buffer[bufferIndex++] = (quantum >> 8) & 0xff;
134
- buffer[bufferIndex++] = quantum & 0xff;
135
- } else {
136
- // quantum is 12 bits, but really represents only one byte.
137
- quantum = quantum >> 4;
138
- buffer[bufferIndex++] = quantum & 0xff;
139
- }
140
- }
141
- return buffer;
142
- }
143
-
144
- export function toArrayBuffer(base64: string): ArrayBuffer {
145
- var uint8Array = decode(base64);
146
- return uint8Array.buffer;
147
- }
148
-
149
- export function toUint8Array(base64: string): Uint8Array {
150
- return decode(base64);
151
- }
152
-
153
- export function fromArrayBuffer(arraybuffer: ArrayBuffer) {
154
- return encode(arraybuffer);
155
- }
156
-
157
- export function fromUint8Array(uint8Array: Uint8Array) {
158
- return encode(uint8Array.buffer);
159
- }
160
-
161
- export function dataURLtoFile(dataurl, filename): File {
162
-
163
- var arr = dataurl.split(','),
164
- mime = arr[0].match(/:(.*?);/)[1],
165
- bstr = atob(arr[1]),
166
- n = bstr.length,
167
- u8arr = new Uint8Array(n);
168
-
169
- while (n--) {
170
- u8arr[n] = bstr.charCodeAt(n);
171
- }
172
-
173
- return new File([u8arr], filename, { type: mime });
174
- }
@@ -1,13 +0,0 @@
1
- import assert from 'assert/strict';
2
- import test from 'node:test';
3
- import { DisableAnchorInterceptInHtml, HTMLDecode } from "./browser";
4
-
5
- test('DisableAnchorInterceptInHtml', async t => {
6
- assert.strictEqual(DisableAnchorInterceptInHtml(`<a href="blah">test</a>`), `<a data-interception="off" href="blah">test</a>`);
7
- assert.strictEqual(DisableAnchorInterceptInHtml(`<div><a href="blah">test</a><a href="blah">test</a></div>`), `<div><a data-interception="off" href="blah">test</a><a data-interception="off" href="blah">test</a></div>`);
8
- assert.strictEqual(DisableAnchorInterceptInHtml(`<p href="blah">test</p>`), `<p href="blah">test</p>`);
9
- });
10
-
11
- test('HTMLDecode', async t => {
12
- assert.strictEqual(HTMLDecode(`hello &lt; &#58;`), `hello < :`);
13
- });