matterbridge 2.0.0-edge1 → 2.1.0-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 +36 -3
- package/README.md +1 -1
- package/dist/cli.js +0 -26
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +2 -27
- package/dist/frontend.js +99 -245
- package/dist/index.js +2 -33
- package/dist/logger/export.js +0 -1
- package/dist/matter/export.js +0 -7
- package/dist/matterbridge.js +99 -710
- package/dist/matterbridgeAccessoryPlatform.js +0 -33
- package/dist/matterbridgeBehaviors.js +42 -32
- package/dist/matterbridgeDeviceTypes.js +90 -84
- package/dist/matterbridgeDynamicPlatform.js +0 -33
- package/dist/matterbridgeEndpoint.js +992 -2454
- package/dist/matterbridgePlatform.js +11 -130
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +7 -251
- 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 -255
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.ea28015b.js → main.26dbf9b9.js} +3 -3
- package/frontend/build/static/js/main.26dbf9b9.js.map +1 -0
- package/npm-shrinkwrap.json +97 -79
- package/package.json +2 -4
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -46
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/frontend.d.ts +0 -98
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -357
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -123
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -109
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1167
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -154
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -238
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -221
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js.map +0 -1
- package/frontend/build/static/js/main.ea28015b.js.map +0 -1
- /package/frontend/build/static/js/{main.ea28015b.js.LICENSE.txt → main.26dbf9b9.js.LICENSE.txt} +0 -0
package/dist/utils/utils.js
CHANGED
|
@@ -1,93 +1,28 @@
|
|
|
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 { createWriteStream, statSync } from 'fs';
|
|
26
3
|
import path from 'path';
|
|
27
4
|
import * as dns from 'dns';
|
|
28
5
|
import { promises as fs } from 'fs';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import { glob } from 'glob';
|
|
32
|
-
// AnsiLogger module
|
|
33
|
-
import { AnsiLogger, idn, LogLevel, rs, TimestampFormat } from 'node-ansi-logger';
|
|
34
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: TimestampFormat.TIME_MILLIS, logLevel: LogLevel.INFO });
|
|
35
|
-
/**
|
|
36
|
-
* Performs a deep comparison between two values to determine if they are equivalent.
|
|
37
|
-
* This comparison includes primitive types, arrays, and objects, allowing for optional
|
|
38
|
-
* exclusion of specific properties from the comparison in objects.
|
|
39
|
-
*
|
|
40
|
-
* @param {any} a The first value to compare.
|
|
41
|
-
* @param {any} b The second value to compare.
|
|
42
|
-
* @param {string[]} [excludeProperties=[]] An array of property names to exclude from the comparison in objects.
|
|
43
|
-
* @returns {boolean} True if the values are deeply equal, excluding any specified properties; otherwise, false.
|
|
44
|
-
*
|
|
45
|
-
* Note: This function utilizes recursion for deep comparison of nested structures and includes a debugging
|
|
46
|
-
* mechanism that can be toggled on or off for detailed comparison logging. It is important to ensure that
|
|
47
|
-
* objects do not contain circular references when enabling debug logging to avoid infinite loops.
|
|
48
|
-
*
|
|
49
|
-
* Example usage:
|
|
50
|
-
* ```
|
|
51
|
-
* const obj1 = { a: 1, b: { c: 2 } };
|
|
52
|
-
* const obj2 = { a: 1, b: { c: 2 } };
|
|
53
|
-
* console.log(deepEqual(obj1, obj2)); // true
|
|
54
|
-
*
|
|
55
|
-
* const arr1 = [1, 2, [3, 4]];
|
|
56
|
-
* const arr2 = [1, 2, [3, 4]];
|
|
57
|
-
* console.log(deepEqual(arr1, arr2)); // true
|
|
58
|
-
*
|
|
59
|
-
* const obj3 = { a: 1, b: { c: 2, d: 3 } };
|
|
60
|
-
* const obj4 = { a: 1, b: { c: 2 } };
|
|
61
|
-
* console.log(deepEqual(obj3, obj4, ['d'])); // true, excluding property 'd' from comparison
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
import { AnsiLogger, idn, rs } from 'node-ansi-logger';
|
|
7
|
+
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
|
|
65
8
|
export function deepEqual(a, b, excludeProperties = []) {
|
|
66
|
-
// Toggle debugging on or off easily
|
|
67
9
|
const debug = false;
|
|
68
|
-
// Helper function for conditional logging
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
10
|
const debugLog = (...messages) => {
|
|
71
11
|
if (debug) {
|
|
72
|
-
// eslint-disable-next-line no-console
|
|
73
12
|
console.log(...messages);
|
|
74
13
|
}
|
|
75
14
|
};
|
|
76
|
-
// If both are the same instance, return true (handles primitives and same object references)
|
|
77
15
|
if (a === b) {
|
|
78
16
|
return true;
|
|
79
17
|
}
|
|
80
|
-
// If types are different, return false
|
|
81
18
|
if (typeof a !== typeof b) {
|
|
82
19
|
debugLog(`deepEqual false for typeof a: ${typeof a} typeof b: ${typeof b}`);
|
|
83
20
|
return false;
|
|
84
21
|
}
|
|
85
|
-
// If one of them is null (and we know they are not equal from the first check), return false
|
|
86
22
|
if (a == null || b == null) {
|
|
87
23
|
debugLog('deepEqual false for == null');
|
|
88
24
|
return false;
|
|
89
25
|
}
|
|
90
|
-
// Handle Arrays
|
|
91
26
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
92
27
|
if (a.length !== b.length) {
|
|
93
28
|
debugLog(`deepEqual false for array a.length(${a.length}) !== b.length(${b.length})`);
|
|
@@ -103,75 +38,54 @@ export function deepEqual(a, b, excludeProperties = []) {
|
|
|
103
38
|
}
|
|
104
39
|
return true;
|
|
105
40
|
}
|
|
106
|
-
// Handle Objects (and exclude null, functions, and arrays)
|
|
107
41
|
if (typeof a === 'object' && typeof b === 'object') {
|
|
108
42
|
const aProps = Object.getOwnPropertyNames(a).filter((prop) => !excludeProperties.includes(prop));
|
|
109
43
|
const bProps = Object.getOwnPropertyNames(b).filter((prop) => !excludeProperties.includes(prop));
|
|
110
|
-
// If their property lengths are different, they're different objects
|
|
111
44
|
if (aProps.length !== bProps.length) {
|
|
112
45
|
debugLog(`deepEqual false for aProps.length(${aProps.length}) !== bProps.length(${bProps.length})`);
|
|
113
46
|
debugLog(`- aProps.length(${aProps.length}):`, aProps);
|
|
114
47
|
debugLog(`- bProps.length(${bProps.length}):`, bProps);
|
|
115
48
|
return false;
|
|
116
49
|
}
|
|
117
|
-
// Check each property in 'a' to see if it's in 'b' and if it's equal (deep check)
|
|
118
50
|
for (const prop of aProps) {
|
|
119
51
|
if (!Object.prototype.hasOwnProperty.call(b, prop)) {
|
|
120
52
|
debugLog(`deepEqual false for !b.hasOwnProperty(${prop})`);
|
|
121
53
|
return false;
|
|
122
54
|
}
|
|
123
55
|
if (!deepEqual(a[prop], b[prop], excludeProperties)) {
|
|
124
|
-
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`
|
|
56
|
+
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`);
|
|
125
57
|
return false;
|
|
126
58
|
}
|
|
127
59
|
}
|
|
128
60
|
return true;
|
|
129
61
|
}
|
|
130
|
-
// If none of the above, the objects are not equal
|
|
131
62
|
return false;
|
|
132
63
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Creates a deep copy of the given value.
|
|
135
|
-
*
|
|
136
|
-
* @template T - The type of the value being copied.
|
|
137
|
-
* @param {T} value - The value to be copied.
|
|
138
|
-
* @returns {T} - The deep copy of the value.
|
|
139
|
-
*/
|
|
140
64
|
export function deepCopy(value) {
|
|
141
65
|
if (typeof value !== 'object' || value === null) {
|
|
142
|
-
// Primitive value (string, number, boolean, bigint, undefined, symbol) or null
|
|
143
66
|
return value;
|
|
144
67
|
}
|
|
145
68
|
else if (Array.isArray(value)) {
|
|
146
|
-
// Array: Recursively copy each element
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
69
|
return value.map((item) => deepCopy(item));
|
|
149
70
|
}
|
|
150
71
|
else if (value instanceof Date) {
|
|
151
|
-
// Date objects
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
72
|
return new Date(value.getTime());
|
|
154
73
|
}
|
|
155
74
|
else if (value instanceof Map) {
|
|
156
|
-
// Maps
|
|
157
75
|
const mapCopy = new Map();
|
|
158
76
|
value.forEach((val, key) => {
|
|
159
77
|
mapCopy.set(key, deepCopy(val));
|
|
160
78
|
});
|
|
161
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
79
|
return mapCopy;
|
|
163
80
|
}
|
|
164
81
|
else if (value instanceof Set) {
|
|
165
|
-
// Sets
|
|
166
82
|
const setCopy = new Set();
|
|
167
83
|
value.forEach((item) => {
|
|
168
84
|
setCopy.add(deepCopy(item));
|
|
169
85
|
});
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
171
86
|
return setCopy;
|
|
172
87
|
}
|
|
173
88
|
else {
|
|
174
|
-
// Objects: Create a copy with the same prototype as the original
|
|
175
89
|
const proto = Object.getPrototypeOf(value);
|
|
176
90
|
const copy = Object.create(proto);
|
|
177
91
|
for (const key in value) {
|
|
@@ -182,14 +96,9 @@ export function deepCopy(value) {
|
|
|
182
96
|
return copy;
|
|
183
97
|
}
|
|
184
98
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
187
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
188
|
-
*/
|
|
189
99
|
export function getIpv4InterfaceAddress() {
|
|
190
100
|
let ipv4Address;
|
|
191
101
|
const networkInterfaces = os.networkInterfaces();
|
|
192
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
193
102
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
194
103
|
if (!interfaceDetails) {
|
|
195
104
|
break;
|
|
@@ -203,17 +112,11 @@ export function getIpv4InterfaceAddress() {
|
|
|
203
112
|
break;
|
|
204
113
|
}
|
|
205
114
|
}
|
|
206
|
-
// console.log('Selected Network Interfaces:', ipv4Address);
|
|
207
115
|
return ipv4Address;
|
|
208
116
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
211
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
212
|
-
*/
|
|
213
117
|
export function getIpv6InterfaceAddress() {
|
|
214
118
|
let ipv6Address;
|
|
215
119
|
const networkInterfaces = os.networkInterfaces();
|
|
216
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
217
120
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
218
121
|
if (!interfaceDetails) {
|
|
219
122
|
break;
|
|
@@ -227,17 +130,11 @@ export function getIpv6InterfaceAddress() {
|
|
|
227
130
|
break;
|
|
228
131
|
}
|
|
229
132
|
}
|
|
230
|
-
// console.log('Selected Network Interfaces:', ipv6Address);
|
|
231
133
|
return ipv6Address;
|
|
232
134
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Retrieves the mac address of the first non-internal network interface.
|
|
235
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
236
|
-
*/
|
|
237
135
|
export function getMacAddress() {
|
|
238
136
|
let macAddress;
|
|
239
137
|
const networkInterfaces = os.networkInterfaces();
|
|
240
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
241
138
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
242
139
|
if (!interfaceDetails) {
|
|
243
140
|
break;
|
|
@@ -253,25 +150,10 @@ export function getMacAddress() {
|
|
|
253
150
|
}
|
|
254
151
|
return macAddress;
|
|
255
152
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Checks if a given string is a valid IPv4 address.
|
|
258
|
-
*
|
|
259
|
-
* @param {string} ipv4Address - The string to be checked.
|
|
260
|
-
* @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
|
|
261
|
-
*/
|
|
262
153
|
export function isValidIpv4Address(ipv4Address) {
|
|
263
154
|
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]?)$/;
|
|
264
155
|
return ipv4Regex.test(ipv4Address);
|
|
265
156
|
}
|
|
266
|
-
/**
|
|
267
|
-
* Checks if a value is a valid number within the specified range.
|
|
268
|
-
*
|
|
269
|
-
* @param {any} value - The value to be checked.
|
|
270
|
-
* @param {number} min - The minimum value allowed (optional).
|
|
271
|
-
* @param {number} max - The maximum value allowed (optional).
|
|
272
|
-
* @returns {boolean} Returns true if the value is a valid number within the specified range, otherwise false.
|
|
273
|
-
*/
|
|
274
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
275
157
|
export function isValidNumber(value, min, max) {
|
|
276
158
|
if (value === undefined || value === null || typeof value !== 'number' || Number.isNaN(value))
|
|
277
159
|
return false;
|
|
@@ -281,25 +163,9 @@ export function isValidNumber(value, min, max) {
|
|
|
281
163
|
return false;
|
|
282
164
|
return true;
|
|
283
165
|
}
|
|
284
|
-
/**
|
|
285
|
-
* Checks if a value is a valid boolean.
|
|
286
|
-
*
|
|
287
|
-
* @param {any} value - The value to be checked.
|
|
288
|
-
* @returns {boolean} `true` if the value is a valid boolean, `false` otherwise.
|
|
289
|
-
*/
|
|
290
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
166
|
export function isValidBoolean(value) {
|
|
292
167
|
return value !== undefined && value !== null && typeof value === 'boolean';
|
|
293
168
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Checks if a value is a valid string.
|
|
296
|
-
*
|
|
297
|
-
* @param {any} value - The value to be checked.
|
|
298
|
-
* @param {number} minLength - The min string length (optional).
|
|
299
|
-
* @param {number} maxLength - The max string length (optional).
|
|
300
|
-
* @returns {boolean} A boolean indicating whether the value is a valid string.
|
|
301
|
-
*/
|
|
302
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
303
169
|
export function isValidString(value, minLength, maxLength) {
|
|
304
170
|
if (value === undefined || value === null || typeof value !== 'string')
|
|
305
171
|
return false;
|
|
@@ -309,15 +175,6 @@ export function isValidString(value, minLength, maxLength) {
|
|
|
309
175
|
return false;
|
|
310
176
|
return true;
|
|
311
177
|
}
|
|
312
|
-
/**
|
|
313
|
-
* Checks if a value is a valid object.
|
|
314
|
-
*
|
|
315
|
-
* @param {any} value - The value to be checked.
|
|
316
|
-
* @param {number} minLength - The min number of keys (optional).
|
|
317
|
-
* @param {number} maxLength - The max number of keys (optional).
|
|
318
|
-
* @returns {boolean} A boolean indicating whether the value is a valid object.
|
|
319
|
-
*/
|
|
320
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
321
178
|
export function isValidObject(value, minLength, maxLength) {
|
|
322
179
|
if (value === undefined || value === null || typeof value !== 'object' || Array.isArray(value))
|
|
323
180
|
return false;
|
|
@@ -328,15 +185,6 @@ export function isValidObject(value, minLength, maxLength) {
|
|
|
328
185
|
return false;
|
|
329
186
|
return true;
|
|
330
187
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Checks if a value is a valid array.
|
|
333
|
-
*
|
|
334
|
-
* @param {any} value - The value to be checked.
|
|
335
|
-
* @param {number} minLength - The min number of elements (optional).
|
|
336
|
-
* @param {number} maxLength - The max number of elements (optional).
|
|
337
|
-
* @returns {boolean} A boolean indicating whether the value is a valid array.
|
|
338
|
-
*/
|
|
339
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
340
188
|
export function isValidArray(value, minLength, maxLength) {
|
|
341
189
|
if (value === undefined || value === null || !Array.isArray(value))
|
|
342
190
|
return false;
|
|
@@ -346,33 +194,14 @@ export function isValidArray(value, minLength, maxLength) {
|
|
|
346
194
|
return false;
|
|
347
195
|
return true;
|
|
348
196
|
}
|
|
349
|
-
/**
|
|
350
|
-
* Checks if the given value is null.
|
|
351
|
-
*
|
|
352
|
-
* @param {any} value - The value to check.
|
|
353
|
-
* @returns {boolean} `true` if the value is null, `false` otherwise.
|
|
354
|
-
*/
|
|
355
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
356
197
|
export function isValidNull(value) {
|
|
357
198
|
return value === null;
|
|
358
199
|
}
|
|
359
|
-
/**
|
|
360
|
-
* Checks if a value is undefined.
|
|
361
|
-
*
|
|
362
|
-
* @param {any} value - The value to check.
|
|
363
|
-
* @returns {boolean} `true` if the value is undefined, `false` otherwise.
|
|
364
|
-
*/
|
|
365
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
366
200
|
export function isValidUndefined(value) {
|
|
367
201
|
return value === undefined;
|
|
368
202
|
}
|
|
369
|
-
/**
|
|
370
|
-
* Logs the available network interfaces and their details.
|
|
371
|
-
* @param {boolean} log - Whether to enable logging of network interface details.
|
|
372
|
-
* @returns {string | undefined} The IPv6 address of the network interface, if available.
|
|
373
|
-
*/
|
|
374
203
|
export function logInterfaces(debug = true) {
|
|
375
|
-
log.logLevel =
|
|
204
|
+
log.logLevel = "info";
|
|
376
205
|
log.logName = 'LogInterfaces';
|
|
377
206
|
let ipv6Address;
|
|
378
207
|
const networkInterfaces = os.networkInterfaces();
|
|
@@ -390,18 +219,8 @@ export function logInterfaces(debug = true) {
|
|
|
390
219
|
}
|
|
391
220
|
return ipv6Address;
|
|
392
221
|
}
|
|
393
|
-
/**
|
|
394
|
-
* Asynchronous waiter function that resolves when the provided condition is met or rejects on timeout.
|
|
395
|
-
* @param {string} name - The name of the waiter.
|
|
396
|
-
* @param {() => boolean} check - A function that checks the condition. Should return a boolean.
|
|
397
|
-
* @param {boolean} [exitWithReject=false] - Optional. If true, the promise will be rejected on timeout. Default is false.
|
|
398
|
-
* @param {number} [resolveTimeout=5000] - Optional. The timeout duration in milliseconds. Default is 5000ms.
|
|
399
|
-
* @param {number} [resolveInterval=500] - Optional. The interval duration in milliseconds between condition checks. Default is 500ms.
|
|
400
|
-
* @param {boolean} [debug=false] - Optional. If true, debug messages will be logged to the console. Default is false.
|
|
401
|
-
* @returns {Promise<boolean>} A promise that resolves to true when the condition is met, or false if the timeout occurs.
|
|
402
|
-
*/
|
|
403
222
|
export async function waiter(name, check, exitWithReject = false, resolveTimeout = 5000, resolveInterval = 500, debug = false) {
|
|
404
|
-
log.logLevel =
|
|
223
|
+
log.logLevel = "debug";
|
|
405
224
|
log.logName = 'Waiter';
|
|
406
225
|
if (debug)
|
|
407
226
|
log.debug(`Waiter "${name}" started...`);
|
|
@@ -427,19 +246,11 @@ export async function waiter(name, check, exitWithReject = false, resolveTimeout
|
|
|
427
246
|
}, resolveInterval);
|
|
428
247
|
});
|
|
429
248
|
}
|
|
430
|
-
/**
|
|
431
|
-
* Asynchronously waits for a specified amount of time.
|
|
432
|
-
* @param {number} timeout - The duration to wait in milliseconds. Default is 1000ms.
|
|
433
|
-
* @param {string} name - The name of the wait operation. Default is undefined.
|
|
434
|
-
* @param {boolean} debug - Whether to enable debug logging. Default is false.
|
|
435
|
-
* @returns {Promise<void>} A Promise that resolves after the specified timeout.
|
|
436
|
-
*/
|
|
437
249
|
export async function wait(timeout = 1000, name, debug = false) {
|
|
438
|
-
log.logLevel =
|
|
250
|
+
log.logLevel = "debug";
|
|
439
251
|
log.logName = 'Wait';
|
|
440
252
|
if (debug)
|
|
441
253
|
log.debug(`Wait "${name}" started...`);
|
|
442
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
443
254
|
return new Promise((resolve, reject) => {
|
|
444
255
|
const timeoutId = setTimeout(() => {
|
|
445
256
|
if (debug)
|
|
@@ -449,28 +260,16 @@ export async function wait(timeout = 1000, name, debug = false) {
|
|
|
449
260
|
}, timeout);
|
|
450
261
|
});
|
|
451
262
|
}
|
|
452
|
-
/**
|
|
453
|
-
* Creates a ZIP archive from the specified source pattern or directory and writes it to the specified output path.
|
|
454
|
-
*
|
|
455
|
-
* @param {string} outputPath - The path where the output ZIP file will be written.
|
|
456
|
-
* @param {string[]} sourcePaths - The source pattern or directory to be zipped (use path.join for sourcePath).
|
|
457
|
-
* @returns {Promise<number>} - A promise that resolves to the total number of bytes written to the ZIP file.
|
|
458
|
-
*
|
|
459
|
-
* @remarks
|
|
460
|
-
* This function uses the `archiver` library to create a ZIP archive. It sets the compression level to 9 (maximum compression).
|
|
461
|
-
* The function ensures that the output file is properly closed after the archiving process is complete.
|
|
462
|
-
* It logs the progress and the total number of bytes written to the console.
|
|
463
|
-
*
|
|
464
|
-
* This function uses the `glob` library to match files based on the source pattern (internally converted in posix).
|
|
465
|
-
*/
|
|
466
263
|
export async function createZip(outputPath, ...sourcePaths) {
|
|
467
|
-
|
|
264
|
+
const { default: archiver } = await import('archiver');
|
|
265
|
+
const { glob } = await import('glob');
|
|
266
|
+
log.logLevel = "info";
|
|
468
267
|
log.logName = 'Archive';
|
|
469
268
|
log.debug(`creating archive ${outputPath} from ${sourcePaths.join(', ')} ...`);
|
|
470
269
|
return new Promise((resolve, reject) => {
|
|
471
270
|
const output = createWriteStream(outputPath);
|
|
472
271
|
const archive = archiver('zip', {
|
|
473
|
-
zlib: { level: 9 },
|
|
272
|
+
zlib: { level: 9 },
|
|
474
273
|
});
|
|
475
274
|
output.on('close', () => {
|
|
476
275
|
log.debug(`archive ${outputPath} closed with ${archive.pointer()} total bytes`);
|
|
@@ -497,7 +296,6 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
497
296
|
});
|
|
498
297
|
archive.pipe(output);
|
|
499
298
|
for (const sourcePath of sourcePaths) {
|
|
500
|
-
// Check if the sourcePath is a file or directory
|
|
501
299
|
let stats;
|
|
502
300
|
try {
|
|
503
301
|
stats = statSync(sourcePath);
|
|
@@ -525,35 +323,22 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
525
323
|
archive.directory(sourcePath, path.basename(sourcePath));
|
|
526
324
|
}
|
|
527
325
|
}
|
|
528
|
-
// Finalize the archive (i.e., we are done appending files but streams have to finish yet)
|
|
529
326
|
log.debug(`finalizing archive ${outputPath}...`);
|
|
530
327
|
archive.finalize().catch(reject);
|
|
531
328
|
});
|
|
532
329
|
}
|
|
533
|
-
/**
|
|
534
|
-
* Copies a directory and all its subdirectories and files to a new location.
|
|
535
|
-
*
|
|
536
|
-
* @param {string} srcDir - The path to the source directory.
|
|
537
|
-
* @param {string} destDir - The path to the destination directory.
|
|
538
|
-
* @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
|
|
539
|
-
* @throws {Error} - Throws an error if the copy operation fails.
|
|
540
|
-
*/
|
|
541
330
|
export async function copyDirectory(srcDir, destDir) {
|
|
542
331
|
log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
|
|
543
332
|
try {
|
|
544
|
-
// Create destination directory if it doesn't exist
|
|
545
333
|
await fs.mkdir(destDir, { recursive: true });
|
|
546
|
-
// Read contents of the source directory
|
|
547
334
|
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
548
335
|
for (const entry of entries) {
|
|
549
336
|
const srcPath = path.join(srcDir, entry.name);
|
|
550
337
|
const destPath = path.join(destDir, entry.name);
|
|
551
338
|
if (entry.isDirectory()) {
|
|
552
|
-
// Recursive call if entry is a directory
|
|
553
339
|
await copyDirectory(srcPath, destPath);
|
|
554
340
|
}
|
|
555
341
|
else if (entry.isFile()) {
|
|
556
|
-
// Copy file if entry is a file
|
|
557
342
|
await fs.copyFile(srcPath, destPath);
|
|
558
343
|
}
|
|
559
344
|
}
|
|
@@ -564,32 +349,15 @@ export async function copyDirectory(srcDir, destDir) {
|
|
|
564
349
|
return false;
|
|
565
350
|
}
|
|
566
351
|
}
|
|
567
|
-
/**
|
|
568
|
-
* Resolves the given hostname to an IP address.
|
|
569
|
-
*
|
|
570
|
-
* @param {string} hostname - The hostname to resolve.
|
|
571
|
-
* @param {0 | 4 | 6} [family=4] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
572
|
-
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
573
|
-
*
|
|
574
|
-
* @remarks
|
|
575
|
-
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
576
|
-
*/
|
|
577
352
|
export async function resolveHostname(hostname, family = 4) {
|
|
578
353
|
try {
|
|
579
354
|
const addresses = await dns.promises.lookup(hostname.toLowerCase() + '.local', { family });
|
|
580
355
|
return addresses.address;
|
|
581
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
582
356
|
}
|
|
583
357
|
catch (error) {
|
|
584
358
|
return null;
|
|
585
359
|
}
|
|
586
360
|
}
|
|
587
|
-
/**
|
|
588
|
-
* Retrieves the value of a command-line parameter.
|
|
589
|
-
*
|
|
590
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
591
|
-
* @returns {string | undefined} The value of the parameter, or undefined if not found.
|
|
592
|
-
*/
|
|
593
361
|
export function getParameter(name) {
|
|
594
362
|
const commandArguments = process.argv.slice(2);
|
|
595
363
|
let markerIndex = commandArguments.indexOf(`-${name}`);
|
|
@@ -599,12 +367,6 @@ export function getParameter(name) {
|
|
|
599
367
|
return undefined;
|
|
600
368
|
return commandArguments[markerIndex + 1];
|
|
601
369
|
}
|
|
602
|
-
/**
|
|
603
|
-
* Checks if a command-line parameter is present.
|
|
604
|
-
*
|
|
605
|
-
* @param {string} name - The name of the parameter to check.
|
|
606
|
-
* @returns {boolean} True if the parameter is present, otherwise false.
|
|
607
|
-
*/
|
|
608
370
|
export function hasParameter(name) {
|
|
609
371
|
const commandArguments = process.argv.slice(2);
|
|
610
372
|
let markerIncluded = commandArguments.includes(`-${name}`);
|
|
@@ -612,12 +374,6 @@ export function hasParameter(name) {
|
|
|
612
374
|
markerIncluded = commandArguments.includes(`--${name}`);
|
|
613
375
|
return markerIncluded;
|
|
614
376
|
}
|
|
615
|
-
/**
|
|
616
|
-
* Retrieves the value of a command-line parameter as an integer.
|
|
617
|
-
*
|
|
618
|
-
* @param {string} name - The name of the parameter to retrieve.
|
|
619
|
-
* @returns {number | undefined} The integer value of the parameter, or undefined if not found or invalid.
|
|
620
|
-
*/
|
|
621
377
|
export function getIntParameter(name) {
|
|
622
378
|
const value = getParameter(name);
|
|
623
379
|
if (value === undefined)
|
|
@@ -627,4 +383,3 @@ export function getIntParameter(name) {
|
|
|
627
383
|
return undefined;
|
|
628
384
|
return intValue;
|
|
629
385
|
}
|
|
630
|
-
//# 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.26dbf9b9.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.26dbf9b9.js.map": "./static/js/main.26dbf9b9.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.26dbf9b9.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.26dbf9b9.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>
|