matterbridge 2.1.5 → 2.1.6-dev.1
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.
- package/CHANGELOG.md +17 -0
- package/README-DOCKER.md +17 -7
- package/dist/cli.js +0 -26
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +55 -280
- package/dist/index.js +0 -28
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -2
- package/dist/matter/types.js +0 -2
- package/dist/matterbridge.js +68 -765
- package/dist/matterbridgeAccessoryPlatform.js +0 -33
- package/dist/matterbridgeBehaviors.js +1 -32
- package/dist/matterbridgeDeviceTypes.js +11 -112
- package/dist/matterbridgeDynamicPlatform.js +0 -33
- package/dist/matterbridgeEndpoint.js +6 -690
- package/dist/matterbridgeEndpointHelpers.js +9 -117
- package/dist/matterbridgePlatform.js +41 -123
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -230
- package/dist/storage/export.js +0 -1
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/export.js +0 -1
- package/dist/utils/utils.js +10 -264
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.cd192588.js → main.a241d4f0.js} +9 -9
- package/frontend/build/static/js/main.a241d4f0.js.map +1 -0
- package/npm-shrinkwrap.json +47 -47
- package/package.json +2 -3
- package/dist/cli.d.ts +0 -25
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts +0 -2
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -27
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -114
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/frontend.d.ts +0 -143
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/index.d.ts +0 -35
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -409
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1056
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -177
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -835
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -159
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -169
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -236
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -61
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/export.d.ts +0 -3
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -231
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js.map +0 -1
- package/frontend/build/static/js/main.cd192588.js.map +0 -1
- /package/frontend/build/static/js/{main.cd192588.js.LICENSE.txt → main.a241d4f0.js.LICENSE.txt} +0 -0
package/dist/utils/utils.js
CHANGED
|
@@ -1,87 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the deepEqual function.
|
|
3
|
-
*
|
|
4
|
-
* @file utils.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-02-17
|
|
7
|
-
* @version 1.2.9
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
// Node.js modules
|
|
24
1
|
import os from 'os';
|
|
25
2
|
import path from 'path';
|
|
26
|
-
// AnsiLogger module
|
|
27
3
|
import { AnsiLogger, idn, rs } from 'node-ansi-logger';
|
|
28
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4
|
|
29
|
-
/**
|
|
30
|
-
* Performs a deep comparison between two values to determine if they are equivalent.
|
|
31
|
-
* This comparison includes primitive types, arrays, and objects, allowing for optional
|
|
32
|
-
* exclusion of specific properties from the comparison in objects.
|
|
33
|
-
*
|
|
34
|
-
* @param {any} a The first value to compare.
|
|
35
|
-
* @param {any} b The second value to compare.
|
|
36
|
-
* @param {string[]} [excludeProperties=[]] An array of property names to exclude from the comparison in objects.
|
|
37
|
-
* @returns {boolean} True if the values are deeply equal, excluding any specified properties; otherwise, false.
|
|
38
|
-
*
|
|
39
|
-
* Note: This function utilizes recursion for deep comparison of nested structures and includes a debugging
|
|
40
|
-
* mechanism that can be toggled on or off for detailed comparison logging. It is important to ensure that
|
|
41
|
-
* objects do not contain circular references when enabling debug logging to avoid infinite loops.
|
|
42
|
-
*
|
|
43
|
-
* Example usage:
|
|
44
|
-
* ```
|
|
45
|
-
* const obj1 = { a: 1, b: { c: 2 } };
|
|
46
|
-
* const obj2 = { a: 1, b: { c: 2 } };
|
|
47
|
-
* console.log(deepEqual(obj1, obj2)); // true
|
|
48
|
-
*
|
|
49
|
-
* const arr1 = [1, 2, [3, 4]];
|
|
50
|
-
* const arr2 = [1, 2, [3, 4]];
|
|
51
|
-
* console.log(deepEqual(arr1, arr2)); // true
|
|
52
|
-
*
|
|
53
|
-
* const obj3 = { a: 1, b: { c: 2, d: 3 } };
|
|
54
|
-
* const obj4 = { a: 1, b: { c: 2 } };
|
|
55
|
-
* console.log(deepEqual(obj3, obj4, ['d'])); // true, excluding property 'd' from comparison
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
|
|
59
5
|
export function deepEqual(a, b, excludeProperties = []) {
|
|
60
|
-
// Toggle debugging on or off easily
|
|
61
6
|
const debug = false;
|
|
62
|
-
// Helper function for conditional logging
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
7
|
const debugLog = (...messages) => {
|
|
65
8
|
if (debug) {
|
|
66
|
-
// eslint-disable-next-line no-console
|
|
67
9
|
console.log(...messages);
|
|
68
10
|
}
|
|
69
11
|
};
|
|
70
|
-
// If both are the same instance, return true (handles primitives and same object references)
|
|
71
12
|
if (a === b) {
|
|
72
13
|
return true;
|
|
73
14
|
}
|
|
74
|
-
// If types are different, return false
|
|
75
15
|
if (typeof a !== typeof b) {
|
|
76
16
|
debugLog(`deepEqual false for typeof a: ${typeof a} typeof b: ${typeof b}`);
|
|
77
17
|
return false;
|
|
78
18
|
}
|
|
79
|
-
// If one of them is null (and we know they are not equal from the first check), return false
|
|
80
19
|
if (a == null || b == null) {
|
|
81
20
|
debugLog('deepEqual false for == null');
|
|
82
21
|
return false;
|
|
83
22
|
}
|
|
84
|
-
// Handle Arrays
|
|
85
23
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
86
24
|
if (a.length !== b.length) {
|
|
87
25
|
debugLog(`deepEqual false for array a.length(${a.length}) !== b.length(${b.length})`);
|
|
@@ -97,75 +35,54 @@ export function deepEqual(a, b, excludeProperties = []) {
|
|
|
97
35
|
}
|
|
98
36
|
return true;
|
|
99
37
|
}
|
|
100
|
-
// Handle Objects (and exclude null, functions, and arrays)
|
|
101
38
|
if (typeof a === 'object' && typeof b === 'object') {
|
|
102
39
|
const aProps = Object.getOwnPropertyNames(a).filter((prop) => !excludeProperties.includes(prop));
|
|
103
40
|
const bProps = Object.getOwnPropertyNames(b).filter((prop) => !excludeProperties.includes(prop));
|
|
104
|
-
// If their property lengths are different, they're different objects
|
|
105
41
|
if (aProps.length !== bProps.length) {
|
|
106
42
|
debugLog(`deepEqual false for aProps.length(${aProps.length}) !== bProps.length(${bProps.length})`);
|
|
107
43
|
debugLog(`- aProps.length(${aProps.length}):`, aProps);
|
|
108
44
|
debugLog(`- bProps.length(${bProps.length}):`, bProps);
|
|
109
45
|
return false;
|
|
110
46
|
}
|
|
111
|
-
// Check each property in 'a' to see if it's in 'b' and if it's equal (deep check)
|
|
112
47
|
for (const prop of aProps) {
|
|
113
48
|
if (!Object.prototype.hasOwnProperty.call(b, prop)) {
|
|
114
49
|
debugLog(`deepEqual false for !b.hasOwnProperty(${prop})`);
|
|
115
50
|
return false;
|
|
116
51
|
}
|
|
117
52
|
if (!deepEqual(a[prop], b[prop], excludeProperties)) {
|
|
118
|
-
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`
|
|
53
|
+
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`);
|
|
119
54
|
return false;
|
|
120
55
|
}
|
|
121
56
|
}
|
|
122
57
|
return true;
|
|
123
58
|
}
|
|
124
|
-
// If none of the above, the objects are not equal
|
|
125
59
|
return false;
|
|
126
60
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Creates a deep copy of the given value.
|
|
129
|
-
*
|
|
130
|
-
* @template T - The type of the value being copied.
|
|
131
|
-
* @param {T} value - The value to be copied.
|
|
132
|
-
* @returns {T} - The deep copy of the value.
|
|
133
|
-
*/
|
|
134
61
|
export function deepCopy(value) {
|
|
135
62
|
if (typeof value !== 'object' || value === null) {
|
|
136
|
-
// Primitive value (string, number, boolean, bigint, undefined, symbol) or null
|
|
137
63
|
return value;
|
|
138
64
|
}
|
|
139
65
|
else if (Array.isArray(value)) {
|
|
140
|
-
// Array: Recursively copy each element
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
66
|
return value.map((item) => deepCopy(item));
|
|
143
67
|
}
|
|
144
68
|
else if (value instanceof Date) {
|
|
145
|
-
// Date objects
|
|
146
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
147
69
|
return new Date(value.getTime());
|
|
148
70
|
}
|
|
149
71
|
else if (value instanceof Map) {
|
|
150
|
-
// Maps
|
|
151
72
|
const mapCopy = new Map();
|
|
152
73
|
value.forEach((val, key) => {
|
|
153
74
|
mapCopy.set(key, deepCopy(val));
|
|
154
75
|
});
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
76
|
return mapCopy;
|
|
157
77
|
}
|
|
158
78
|
else if (value instanceof Set) {
|
|
159
|
-
// Sets
|
|
160
79
|
const setCopy = new Set();
|
|
161
80
|
value.forEach((item) => {
|
|
162
81
|
setCopy.add(deepCopy(item));
|
|
163
82
|
});
|
|
164
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
83
|
return setCopy;
|
|
166
84
|
}
|
|
167
85
|
else {
|
|
168
|
-
// Objects: Create a copy with the same prototype as the original
|
|
169
86
|
const proto = Object.getPrototypeOf(value);
|
|
170
87
|
const copy = Object.create(proto);
|
|
171
88
|
for (const key in value) {
|
|
@@ -176,14 +93,9 @@ export function deepCopy(value) {
|
|
|
176
93
|
return copy;
|
|
177
94
|
}
|
|
178
95
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
181
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
182
|
-
*/
|
|
183
96
|
export function getIpv4InterfaceAddress() {
|
|
184
97
|
let ipv4Address;
|
|
185
98
|
const networkInterfaces = os.networkInterfaces();
|
|
186
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
187
99
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
188
100
|
if (!interfaceDetails) {
|
|
189
101
|
break;
|
|
@@ -197,17 +109,11 @@ export function getIpv4InterfaceAddress() {
|
|
|
197
109
|
break;
|
|
198
110
|
}
|
|
199
111
|
}
|
|
200
|
-
// console.log('Selected Network Interfaces:', ipv4Address);
|
|
201
112
|
return ipv4Address;
|
|
202
113
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
205
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
206
|
-
*/
|
|
207
114
|
export function getIpv6InterfaceAddress() {
|
|
208
115
|
let ipv6Address;
|
|
209
116
|
const networkInterfaces = os.networkInterfaces();
|
|
210
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
211
117
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
212
118
|
if (!interfaceDetails) {
|
|
213
119
|
break;
|
|
@@ -221,17 +127,11 @@ export function getIpv6InterfaceAddress() {
|
|
|
221
127
|
break;
|
|
222
128
|
}
|
|
223
129
|
}
|
|
224
|
-
// console.log('Selected Network Interfaces:', ipv6Address);
|
|
225
130
|
return ipv6Address;
|
|
226
131
|
}
|
|
227
|
-
/**
|
|
228
|
-
* Retrieves the mac address of the first non-internal network interface.
|
|
229
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
230
|
-
*/
|
|
231
132
|
export function getMacAddress() {
|
|
232
133
|
let macAddress;
|
|
233
134
|
const networkInterfaces = os.networkInterfaces();
|
|
234
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
235
135
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
236
136
|
if (!interfaceDetails) {
|
|
237
137
|
break;
|
|
@@ -247,25 +147,10 @@ export function getMacAddress() {
|
|
|
247
147
|
}
|
|
248
148
|
return macAddress;
|
|
249
149
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Checks if a given string is a valid IPv4 address.
|
|
252
|
-
*
|
|
253
|
-
* @param {string} ipv4Address - The string to be checked.
|
|
254
|
-
* @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
|
|
255
|
-
*/
|
|
256
150
|
export function isValidIpv4Address(ipv4Address) {
|
|
257
151
|
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
258
152
|
return ipv4Regex.test(ipv4Address);
|
|
259
153
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Checks if a value is a valid number within the specified range.
|
|
262
|
-
*
|
|
263
|
-
* @param {any} value - The value to be checked.
|
|
264
|
-
* @param {number} min - The minimum value allowed (optional).
|
|
265
|
-
* @param {number} max - The maximum value allowed (optional).
|
|
266
|
-
* @returns {boolean} Returns true if the value is a valid number within the specified range, otherwise false.
|
|
267
|
-
*/
|
|
268
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
269
154
|
export function isValidNumber(value, min, max) {
|
|
270
155
|
if (value === undefined || value === null || typeof value !== 'number' || Number.isNaN(value))
|
|
271
156
|
return false;
|
|
@@ -275,25 +160,9 @@ export function isValidNumber(value, min, max) {
|
|
|
275
160
|
return false;
|
|
276
161
|
return true;
|
|
277
162
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Checks if a value is a valid boolean.
|
|
280
|
-
*
|
|
281
|
-
* @param {any} value - The value to be checked.
|
|
282
|
-
* @returns {boolean} `true` if the value is a valid boolean, `false` otherwise.
|
|
283
|
-
*/
|
|
284
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
285
163
|
export function isValidBoolean(value) {
|
|
286
164
|
return value !== undefined && value !== null && typeof value === 'boolean';
|
|
287
165
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Checks if a value is a valid string.
|
|
290
|
-
*
|
|
291
|
-
* @param {any} value - The value to be checked.
|
|
292
|
-
* @param {number} minLength - The min string length (optional).
|
|
293
|
-
* @param {number} maxLength - The max string length (optional).
|
|
294
|
-
* @returns {boolean} A boolean indicating whether the value is a valid string.
|
|
295
|
-
*/
|
|
296
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
297
166
|
export function isValidString(value, minLength, maxLength) {
|
|
298
167
|
if (value === undefined || value === null || typeof value !== 'string')
|
|
299
168
|
return false;
|
|
@@ -303,15 +172,6 @@ export function isValidString(value, minLength, maxLength) {
|
|
|
303
172
|
return false;
|
|
304
173
|
return true;
|
|
305
174
|
}
|
|
306
|
-
/**
|
|
307
|
-
* Checks if a value is a valid object.
|
|
308
|
-
*
|
|
309
|
-
* @param {any} value - The value to be checked.
|
|
310
|
-
* @param {number} minLength - The min number of keys (optional).
|
|
311
|
-
* @param {number} maxLength - The max number of keys (optional).
|
|
312
|
-
* @returns {boolean} A boolean indicating whether the value is a valid object.
|
|
313
|
-
*/
|
|
314
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
315
175
|
export function isValidObject(value, minLength, maxLength) {
|
|
316
176
|
if (value === undefined || value === null || typeof value !== 'object' || Array.isArray(value))
|
|
317
177
|
return false;
|
|
@@ -322,15 +182,6 @@ export function isValidObject(value, minLength, maxLength) {
|
|
|
322
182
|
return false;
|
|
323
183
|
return true;
|
|
324
184
|
}
|
|
325
|
-
/**
|
|
326
|
-
* Checks if a value is a valid array.
|
|
327
|
-
*
|
|
328
|
-
* @param {any} value - The value to be checked.
|
|
329
|
-
* @param {number} minLength - The min number of elements (optional).
|
|
330
|
-
* @param {number} maxLength - The max number of elements (optional).
|
|
331
|
-
* @returns {boolean} A boolean indicating whether the value is a valid array.
|
|
332
|
-
*/
|
|
333
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
334
185
|
export function isValidArray(value, minLength, maxLength) {
|
|
335
186
|
if (value === undefined || value === null || !Array.isArray(value))
|
|
336
187
|
return false;
|
|
@@ -340,33 +191,14 @@ export function isValidArray(value, minLength, maxLength) {
|
|
|
340
191
|
return false;
|
|
341
192
|
return true;
|
|
342
193
|
}
|
|
343
|
-
/**
|
|
344
|
-
* Checks if the given value is null.
|
|
345
|
-
*
|
|
346
|
-
* @param {any} value - The value to check.
|
|
347
|
-
* @returns {boolean} `true` if the value is null, `false` otherwise.
|
|
348
|
-
*/
|
|
349
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
350
194
|
export function isValidNull(value) {
|
|
351
195
|
return value === null;
|
|
352
196
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Checks if a value is undefined.
|
|
355
|
-
*
|
|
356
|
-
* @param {any} value - The value to check.
|
|
357
|
-
* @returns {boolean} `true` if the value is undefined, `false` otherwise.
|
|
358
|
-
*/
|
|
359
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
197
|
export function isValidUndefined(value) {
|
|
361
198
|
return value === undefined;
|
|
362
199
|
}
|
|
363
|
-
/**
|
|
364
|
-
* Logs the available network interfaces and their details.
|
|
365
|
-
* @param {boolean} log - Whether to enable logging of network interface details.
|
|
366
|
-
* @returns {string | undefined} The IPv6 address of the network interface, if available.
|
|
367
|
-
*/
|
|
368
200
|
export function logInterfaces(debug = true) {
|
|
369
|
-
log.logLevel = "info"
|
|
201
|
+
log.logLevel = "info";
|
|
370
202
|
log.logName = 'LogInterfaces';
|
|
371
203
|
let ipv6Address;
|
|
372
204
|
const networkInterfaces = os.networkInterfaces();
|
|
@@ -384,18 +216,8 @@ export function logInterfaces(debug = true) {
|
|
|
384
216
|
}
|
|
385
217
|
return ipv6Address;
|
|
386
218
|
}
|
|
387
|
-
/**
|
|
388
|
-
* Asynchronous waiter function that resolves when the provided condition is met or rejects on timeout.
|
|
389
|
-
* @param {string} name - The name of the waiter.
|
|
390
|
-
* @param {() => boolean} check - A function that checks the condition. Should return a boolean.
|
|
391
|
-
* @param {boolean} [exitWithReject=false] - Optional. If true, the promise will be rejected on timeout. Default is false.
|
|
392
|
-
* @param {number} [resolveTimeout=5000] - Optional. The timeout duration in milliseconds. Default is 5000ms.
|
|
393
|
-
* @param {number} [resolveInterval=500] - Optional. The interval duration in milliseconds between condition checks. Default is 500ms.
|
|
394
|
-
* @param {boolean} [debug=false] - Optional. If true, debug messages will be logged to the console. Default is false.
|
|
395
|
-
* @returns {Promise<boolean>} A promise that resolves to true when the condition is met, or false if the timeout occurs.
|
|
396
|
-
*/
|
|
397
219
|
export async function waiter(name, check, exitWithReject = false, resolveTimeout = 5000, resolveInterval = 500, debug = false) {
|
|
398
|
-
log.logLevel = "debug"
|
|
220
|
+
log.logLevel = "debug";
|
|
399
221
|
log.logName = 'Waiter';
|
|
400
222
|
if (debug)
|
|
401
223
|
log.debug(`Waiter "${name}" started...`);
|
|
@@ -421,19 +243,11 @@ export async function waiter(name, check, exitWithReject = false, resolveTimeout
|
|
|
421
243
|
}, resolveInterval);
|
|
422
244
|
});
|
|
423
245
|
}
|
|
424
|
-
/**
|
|
425
|
-
* Asynchronously waits for a specified amount of time.
|
|
426
|
-
* @param {number} timeout - The duration to wait in milliseconds. Default is 1000ms.
|
|
427
|
-
* @param {string} name - The name of the wait operation. Default is undefined.
|
|
428
|
-
* @param {boolean} debug - Whether to enable debug logging. Default is false.
|
|
429
|
-
* @returns {Promise<void>} A Promise that resolves after the specified timeout.
|
|
430
|
-
*/
|
|
431
246
|
export async function wait(timeout = 1000, name, debug = false) {
|
|
432
|
-
log.logLevel = "debug"
|
|
247
|
+
log.logLevel = "debug";
|
|
433
248
|
log.logName = 'Wait';
|
|
434
249
|
if (debug)
|
|
435
250
|
log.debug(`Wait "${name}" started...`);
|
|
436
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
437
251
|
return new Promise((resolve, reject) => {
|
|
438
252
|
const timeoutId = setTimeout(() => {
|
|
439
253
|
if (debug)
|
|
@@ -443,31 +257,17 @@ export async function wait(timeout = 1000, name, debug = false) {
|
|
|
443
257
|
}, timeout);
|
|
444
258
|
});
|
|
445
259
|
}
|
|
446
|
-
/**
|
|
447
|
-
* Creates a ZIP archive from the specified source pattern or directory and writes it to the specified output path.
|
|
448
|
-
*
|
|
449
|
-
* @param {string} outputPath - The path where the output ZIP file will be written.
|
|
450
|
-
* @param {string[]} sourcePaths - The source pattern or directory to be zipped (use path.join for sourcePath).
|
|
451
|
-
* @returns {Promise<number>} - A promise that resolves to the total number of bytes written to the ZIP file.
|
|
452
|
-
*
|
|
453
|
-
* @remarks
|
|
454
|
-
* This function uses the `archiver` library to create a ZIP archive. It sets the compression level to 9 (maximum compression).
|
|
455
|
-
* The function ensures that the output file is properly closed after the archiving process is complete.
|
|
456
|
-
* It logs the progress and the total number of bytes written to the console.
|
|
457
|
-
*
|
|
458
|
-
* This function uses the `glob` library to match files based on the source pattern (internally converted in posix).
|
|
459
|
-
*/
|
|
460
260
|
export async function createZip(outputPath, ...sourcePaths) {
|
|
461
261
|
const { default: archiver } = await import('archiver');
|
|
462
262
|
const { glob } = await import('glob');
|
|
463
263
|
const { createWriteStream, statSync } = await import('fs');
|
|
464
|
-
log.logLevel = "info"
|
|
264
|
+
log.logLevel = "info";
|
|
465
265
|
log.logName = 'Archive';
|
|
466
266
|
log.debug(`creating archive ${outputPath} from ${sourcePaths.join(', ')} ...`);
|
|
467
267
|
return new Promise((resolve, reject) => {
|
|
468
268
|
const output = createWriteStream(outputPath);
|
|
469
269
|
const archive = archiver('zip', {
|
|
470
|
-
zlib: { level: 9 },
|
|
270
|
+
zlib: { level: 9 },
|
|
471
271
|
});
|
|
472
272
|
output.on('close', () => {
|
|
473
273
|
log.debug(`archive ${outputPath} closed with ${archive.pointer()} total bytes`);
|
|
@@ -494,7 +294,6 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
494
294
|
});
|
|
495
295
|
archive.pipe(output);
|
|
496
296
|
for (const sourcePath of sourcePaths) {
|
|
497
|
-
// Check if the sourcePath is a file or directory
|
|
498
297
|
let stats;
|
|
499
298
|
try {
|
|
500
299
|
stats = statSync(sourcePath);
|
|
@@ -522,36 +321,23 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
522
321
|
archive.directory(sourcePath, path.basename(sourcePath));
|
|
523
322
|
}
|
|
524
323
|
}
|
|
525
|
-
// Finalize the archive (i.e., we are done appending files but streams have to finish yet)
|
|
526
324
|
log.debug(`finalizing archive ${outputPath}...`);
|
|
527
325
|
archive.finalize().catch(reject);
|
|
528
326
|
});
|
|
529
327
|
}
|
|
530
|
-
/**
|
|
531
|
-
* Copies a directory and all its subdirectories and files to a new location.
|
|
532
|
-
*
|
|
533
|
-
* @param {string} srcDir - The path to the source directory.
|
|
534
|
-
* @param {string} destDir - The path to the destination directory.
|
|
535
|
-
* @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
|
|
536
|
-
* @throws {Error} - Throws an error if the copy operation fails.
|
|
537
|
-
*/
|
|
538
328
|
export async function copyDirectory(srcDir, destDir) {
|
|
539
329
|
const fs = await import('fs').then((mod) => mod.promises);
|
|
540
330
|
log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
|
|
541
331
|
try {
|
|
542
|
-
// Create destination directory if it doesn't exist
|
|
543
332
|
await fs.mkdir(destDir, { recursive: true });
|
|
544
|
-
// Read contents of the source directory
|
|
545
333
|
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
546
334
|
for (const entry of entries) {
|
|
547
335
|
const srcPath = path.join(srcDir, entry.name);
|
|
548
336
|
const destPath = path.join(destDir, entry.name);
|
|
549
337
|
if (entry.isDirectory()) {
|
|
550
|
-
// Recursive call if entry is a directory
|
|
551
338
|
await copyDirectory(srcPath, destPath);
|
|
552
339
|
}
|
|
553
340
|
else if (entry.isFile()) {
|
|
554
|
-
// Copy file if entry is a file
|
|
555
341
|
await fs.copyFile(srcPath, destPath);
|
|
556
342
|
}
|
|
557
343
|
}
|
|
@@ -562,33 +348,16 @@ export async function copyDirectory(srcDir, destDir) {
|
|
|
562
348
|
return false;
|
|
563
349
|
}
|
|
564
350
|
}
|
|
565
|
-
/**
|
|
566
|
-
* Resolves the given hostname to an IP address.
|
|
567
|
-
*
|
|
568
|
-
* @param {string} hostname - The hostname to resolve.
|
|
569
|
-
* @param {0 | 4 | 6} [family=4] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
570
|
-
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
571
|
-
*
|
|
572
|
-
* @remarks
|
|
573
|
-
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
574
|
-
*/
|
|
575
351
|
export async function resolveHostname(hostname, family = 4) {
|
|
576
352
|
const dns = await import('dns');
|
|
577
353
|
try {
|
|
578
|
-
const addresses = await dns.promises.lookup(hostname.toLowerCase()
|
|
354
|
+
const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
|
|
579
355
|
return addresses.address;
|
|
580
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
581
356
|
}
|
|
582
357
|
catch (error) {
|
|
583
358
|
return null;
|
|
584
359
|
}
|
|
585
360
|
}
|
|
586
|
-
/**
|
|
587
|
-
* Retrieves the value of a command-line parameter.
|
|
588
|
-
*
|
|
589
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
590
|
-
* @returns {string | undefined} The value of the parameter, or undefined if not found.
|
|
591
|
-
*/
|
|
592
361
|
export function getParameter(name) {
|
|
593
362
|
const commandArguments = process.argv.slice(2);
|
|
594
363
|
let markerIndex = commandArguments.indexOf(`-${name}`);
|
|
@@ -598,12 +367,6 @@ export function getParameter(name) {
|
|
|
598
367
|
return undefined;
|
|
599
368
|
return commandArguments[markerIndex + 1];
|
|
600
369
|
}
|
|
601
|
-
/**
|
|
602
|
-
* Checks if a command-line parameter is present.
|
|
603
|
-
*
|
|
604
|
-
* @param {string} name - The name of the parameter to check.
|
|
605
|
-
* @returns {boolean} True if the parameter is present, otherwise false.
|
|
606
|
-
*/
|
|
607
370
|
export function hasParameter(name) {
|
|
608
371
|
const commandArguments = process.argv.slice(2);
|
|
609
372
|
let markerIncluded = commandArguments.includes(`-${name}`);
|
|
@@ -611,12 +374,6 @@ export function hasParameter(name) {
|
|
|
611
374
|
markerIncluded = commandArguments.includes(`--${name}`);
|
|
612
375
|
return markerIncluded;
|
|
613
376
|
}
|
|
614
|
-
/**
|
|
615
|
-
* Retrieves the value of a command-line parameter as an integer.
|
|
616
|
-
*
|
|
617
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
618
|
-
* @returns {number | undefined} The integer value of the parameter, or undefined if not found or invalid.
|
|
619
|
-
*/
|
|
620
377
|
export function getIntParameter(name) {
|
|
621
378
|
const value = getParameter(name);
|
|
622
379
|
if (value === undefined)
|
|
@@ -626,15 +383,6 @@ export function getIntParameter(name) {
|
|
|
626
383
|
return undefined;
|
|
627
384
|
return intValue;
|
|
628
385
|
}
|
|
629
|
-
/**
|
|
630
|
-
* Retrieves the version of an npm package from the npm registry.
|
|
631
|
-
*
|
|
632
|
-
* @param {string} packageName - The name of the npm package.
|
|
633
|
-
* @param {string} [tag='latest'] - The tag of the package version to retrieve (default is 'latest').
|
|
634
|
-
* @param {number} [timeout=5000] - The timeout duration in milliseconds (default is 5000ms).
|
|
635
|
-
* @returns {Promise<string>} A promise that resolves to the version string of the package.
|
|
636
|
-
* @throws {Error} If the request fails or the tag is not found.
|
|
637
|
-
*/
|
|
638
386
|
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 5000) {
|
|
639
387
|
const https = await import('https');
|
|
640
388
|
return new Promise((resolve, reject) => {
|
|
@@ -648,8 +396,8 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
648
396
|
let data = '';
|
|
649
397
|
if (res.statusCode !== 200) {
|
|
650
398
|
clearTimeout(timeoutId);
|
|
651
|
-
res.resume();
|
|
652
|
-
req.destroy();
|
|
399
|
+
res.resume();
|
|
400
|
+
req.destroy();
|
|
653
401
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
654
402
|
return;
|
|
655
403
|
}
|
|
@@ -660,7 +408,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
660
408
|
clearTimeout(timeoutId);
|
|
661
409
|
try {
|
|
662
410
|
const jsonData = JSON.parse(data);
|
|
663
|
-
// console.log(`Package ${packageName} tag ${tag}`, jsonData);
|
|
664
411
|
const version = jsonData['dist-tags']?.[tag];
|
|
665
412
|
if (version) {
|
|
666
413
|
resolve(version);
|
|
@@ -680,4 +427,3 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
680
427
|
});
|
|
681
428
|
});
|
|
682
429
|
}
|
|
683
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"main.css": "./static/css/main.cf25d33e.css",
|
|
4
|
-
"main.js": "./static/js/main.
|
|
4
|
+
"main.js": "./static/js/main.a241d4f0.js",
|
|
5
5
|
"static/js/453.abd36b29.chunk.js": "./static/js/453.abd36b29.chunk.js",
|
|
6
6
|
"static/media/roboto-latin-700-normal.woff2": "./static/media/roboto-latin-700-normal.4535474e1cf8598695ad.woff2",
|
|
7
7
|
"static/media/roboto-latin-500-normal.woff2": "./static/media/roboto-latin-500-normal.7077203b1982951ecf76.woff2",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"static/media/roboto-greek-ext-400-normal.woff": "./static/media/roboto-greek-ext-400-normal.16eb83b4a3b1ea994243.woff",
|
|
62
62
|
"index.html": "./index.html",
|
|
63
63
|
"main.cf25d33e.css.map": "./static/css/main.cf25d33e.css.map",
|
|
64
|
-
"main.
|
|
64
|
+
"main.a241d4f0.js.map": "./static/js/main.a241d4f0.js.map",
|
|
65
65
|
"453.abd36b29.chunk.js.map": "./static/js/453.abd36b29.chunk.js.map"
|
|
66
66
|
},
|
|
67
67
|
"entrypoints": [
|
|
68
68
|
"static/css/main.cf25d33e.css",
|
|
69
|
-
"static/js/main.
|
|
69
|
+
"static/js/main.a241d4f0.js"
|
|
70
70
|
]
|
|
71
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.a241d4f0.js"></script><link href="./static/css/main.cf25d33e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|