matterbridge 3.0.0 → 3.0.1-dev-20250501-4f463f9
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 +2 -0
- package/README.md +22 -4
- package/dist/cli.js +2 -37
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +19 -352
- package/dist/index.js +1 -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 +46 -747
- package/dist/matterbridgeAccessoryPlatform.js +0 -34
- package/dist/matterbridgeBehaviors.js +1 -33
- package/dist/matterbridgeDeviceTypes.js +12 -431
- package/dist/matterbridgeDynamicPlatform.js +0 -34
- package/dist/matterbridgeEndpoint.js +11 -794
- package/dist/matterbridgeEndpointHelpers.js +9 -142
- package/dist/matterbridgePlatform.js +7 -225
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -262
- package/dist/shelly.js +6 -146
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -52
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/copyDirectory.js +1 -37
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +0 -40
- package/dist/utils/deepEqual.js +1 -65
- package/dist/utils/export.js +0 -1
- package/dist/utils/isvalid.js +0 -86
- package/dist/utils/network.js +5 -76
- package/dist/utils/parameter.js +0 -53
- package/dist/utils/wait.js +5 -48
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.1d983660.js → main.356788d7.js} +3 -3
- package/frontend/build/static/js/{main.1d983660.js.map → main.356788d7.js.map} +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/cli.d.ts +0 -29
- 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 -222
- 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 -431
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -40
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1514
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -494
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -40
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -943
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2706
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -294
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -187
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -271
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -92
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.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/update.d.ts +0 -32
- package/dist/update.d.ts.map +0 -1
- package/dist/update.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/copyDirectory.d.ts +0 -32
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -38
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -31
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -53
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/export.d.ts +0 -10
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -87
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -69
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/parameter.d.ts +0 -58
- package/dist/utils/parameter.d.ts.map +0 -1
- package/dist/utils/parameter.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -43
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- /package/frontend/build/static/js/{main.1d983660.js.LICENSE.txt → main.356788d7.js.LICENSE.txt} +0 -0
|
@@ -1,54 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the copyDirectory function.
|
|
3
|
-
*
|
|
4
|
-
* @file copyDirectory.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 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
|
-
// AnsiLogger module
|
|
24
1
|
import { AnsiLogger } from '../logger/export.js';
|
|
25
|
-
/**
|
|
26
|
-
* Copies a directory and all its subdirectories and files to a new location.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} srcDir - The path to the source directory.
|
|
29
|
-
* @param {string} destDir - The path to the destination directory.
|
|
30
|
-
* @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
|
|
31
|
-
* @throws {Error} - Throws an error if the copy operation fails.
|
|
32
|
-
*/
|
|
33
2
|
export async function copyDirectory(srcDir, destDir) {
|
|
34
|
-
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4
|
|
3
|
+
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4, logLevel: "info" });
|
|
35
4
|
const fs = await import('node:fs').then((mod) => mod.promises);
|
|
36
5
|
const path = await import('node:path');
|
|
37
6
|
log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
|
|
38
7
|
try {
|
|
39
|
-
// Create destination directory if it doesn't exist
|
|
40
8
|
await fs.mkdir(destDir, { recursive: true });
|
|
41
|
-
// Read contents of the source directory
|
|
42
9
|
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
43
10
|
for (const entry of entries) {
|
|
44
11
|
const srcPath = path.join(srcDir, entry.name);
|
|
45
12
|
const destPath = path.join(destDir, entry.name);
|
|
46
13
|
if (entry.isDirectory()) {
|
|
47
|
-
// Recursive call if entry is a directory
|
|
48
14
|
await copyDirectory(srcPath, destPath);
|
|
49
15
|
}
|
|
50
16
|
else if (entry.isFile()) {
|
|
51
|
-
// Copy file if entry is a file
|
|
52
17
|
await fs.copyFile(srcPath, destPath);
|
|
53
18
|
}
|
|
54
19
|
}
|
|
@@ -59,4 +24,3 @@ export async function copyDirectory(srcDir, destDir) {
|
|
|
59
24
|
return false;
|
|
60
25
|
}
|
|
61
26
|
}
|
|
62
|
-
//# sourceMappingURL=copyDirectory.js.map
|
package/dist/utils/createZip.js
CHANGED
|
@@ -1,43 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the createZip function.
|
|
3
|
-
*
|
|
4
|
-
* @file createZip.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 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
|
-
// AnsiLogger module
|
|
24
1
|
import { AnsiLogger } from '../logger/export.js';
|
|
25
|
-
/**
|
|
26
|
-
* Creates a ZIP archive from the specified source pattern or directory and writes it to the specified output path.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} outputPath - The path where the output ZIP file will be written.
|
|
29
|
-
* @param {string[]} sourcePaths - The source pattern or directory to be zipped (use path.join for sourcePath).
|
|
30
|
-
* @returns {Promise<number>} - A promise that resolves to the total number of bytes written to the ZIP file.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* This function uses the `archiver` library to create a ZIP archive. It sets the compression level to 9 (maximum compression).
|
|
34
|
-
* The function ensures that the output file is properly closed after the archiving process is complete.
|
|
35
|
-
* It logs the progress and the total number of bytes written to the console.
|
|
36
|
-
*
|
|
37
|
-
* This function uses the `glob` library to match files based on the source pattern (internally converted in posix).
|
|
38
|
-
*/
|
|
39
2
|
export async function createZip(outputPath, ...sourcePaths) {
|
|
40
|
-
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4
|
|
3
|
+
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4, logLevel: "info" });
|
|
41
4
|
const { default: archiver } = await import('archiver');
|
|
42
5
|
const { glob } = await import('glob');
|
|
43
6
|
const { createWriteStream, statSync } = await import('node:fs');
|
|
@@ -46,7 +9,7 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
46
9
|
return new Promise((resolve, reject) => {
|
|
47
10
|
const output = createWriteStream(outputPath);
|
|
48
11
|
const archive = archiver('zip', {
|
|
49
|
-
zlib: { level: 9 },
|
|
12
|
+
zlib: { level: 9 },
|
|
50
13
|
});
|
|
51
14
|
output.on('close', () => {
|
|
52
15
|
log.debug(`archive ${outputPath} closed with ${archive.pointer()} total bytes`);
|
|
@@ -73,7 +36,6 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
73
36
|
});
|
|
74
37
|
archive.pipe(output);
|
|
75
38
|
for (const sourcePath of sourcePaths) {
|
|
76
|
-
// Check if the sourcePath is a file or directory
|
|
77
39
|
let stats;
|
|
78
40
|
try {
|
|
79
41
|
stats = statSync(sourcePath);
|
|
@@ -101,9 +63,7 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
101
63
|
archive.directory(sourcePath, path.basename(sourcePath));
|
|
102
64
|
}
|
|
103
65
|
}
|
|
104
|
-
// Finalize the archive (i.e., we are done appending files but streams have to finish yet)
|
|
105
66
|
log.debug(`finalizing archive ${outputPath}...`);
|
|
106
67
|
archive.finalize().catch(reject);
|
|
107
68
|
});
|
|
108
69
|
}
|
|
109
|
-
//# sourceMappingURL=createZip.js.map
|
package/dist/utils/deepCopy.js
CHANGED
|
@@ -1,67 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the deepCopy function.
|
|
3
|
-
*
|
|
4
|
-
* @file deepCopy.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 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
|
-
/**
|
|
24
|
-
* Creates a deep copy of the given value.
|
|
25
|
-
*
|
|
26
|
-
* @template T - The type of the value being copied.
|
|
27
|
-
* @param {T} value - The value to be copied.
|
|
28
|
-
* @returns {T} - The deep copy of the value.
|
|
29
|
-
*/
|
|
30
1
|
export function deepCopy(value) {
|
|
31
2
|
if (typeof value !== 'object' || value === null) {
|
|
32
|
-
// Primitive value (string, number, boolean, bigint, undefined, symbol) or null
|
|
33
3
|
return value;
|
|
34
4
|
}
|
|
35
5
|
else if (Array.isArray(value)) {
|
|
36
|
-
// Array: Recursively copy each element
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
6
|
return value.map((item) => deepCopy(item));
|
|
39
7
|
}
|
|
40
8
|
else if (value instanceof Date) {
|
|
41
|
-
// Date objects
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
9
|
return new Date(value.getTime());
|
|
44
10
|
}
|
|
45
11
|
else if (value instanceof Map) {
|
|
46
|
-
// Maps
|
|
47
12
|
const mapCopy = new Map();
|
|
48
13
|
value.forEach((val, key) => {
|
|
49
14
|
mapCopy.set(key, deepCopy(val));
|
|
50
15
|
});
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
16
|
return mapCopy;
|
|
53
17
|
}
|
|
54
18
|
else if (value instanceof Set) {
|
|
55
|
-
// Sets
|
|
56
19
|
const setCopy = new Set();
|
|
57
20
|
value.forEach((item) => {
|
|
58
21
|
setCopy.add(deepCopy(item));
|
|
59
22
|
});
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
23
|
return setCopy;
|
|
62
24
|
}
|
|
63
25
|
else {
|
|
64
|
-
// Objects: Create a copy with the same prototype as the original
|
|
65
26
|
const proto = Object.getPrototypeOf(value);
|
|
66
27
|
const copy = Object.create(proto);
|
|
67
28
|
for (const key in value) {
|
|
@@ -72,4 +33,3 @@ export function deepCopy(value) {
|
|
|
72
33
|
return copy;
|
|
73
34
|
}
|
|
74
35
|
}
|
|
75
|
-
//# sourceMappingURL=deepCopy.js.map
|
package/dist/utils/deepEqual.js
CHANGED
|
@@ -1,80 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the deepEqual function.
|
|
3
|
-
*
|
|
4
|
-
* @file deepEqual.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 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
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
24
|
-
/**
|
|
25
|
-
* Performs a deep comparison between two values to determine if they are equivalent.
|
|
26
|
-
* This comparison includes primitive types, arrays, and objects, allowing for optional
|
|
27
|
-
* exclusion of specific properties from the comparison in objects.
|
|
28
|
-
*
|
|
29
|
-
* @param {any} a The first value to compare.
|
|
30
|
-
* @param {any} b The second value to compare.
|
|
31
|
-
* @param {string[]} [excludeProperties=[]] An array of property names to exclude from the comparison in objects.
|
|
32
|
-
* @returns {boolean} True if the values are deeply equal, excluding any specified properties; otherwise, false.
|
|
33
|
-
*
|
|
34
|
-
* Note: This function utilizes recursion for deep comparison of nested structures and includes a debugging
|
|
35
|
-
* mechanism that can be toggled on or off for detailed comparison logging. It is important to ensure that
|
|
36
|
-
* objects do not contain circular references when enabling debug logging to avoid infinite loops.
|
|
37
|
-
*
|
|
38
|
-
* Example usage:
|
|
39
|
-
* ```
|
|
40
|
-
* const obj1 = { a: 1, b: { c: 2 } };
|
|
41
|
-
* const obj2 = { a: 1, b: { c: 2 } };
|
|
42
|
-
* console.log(deepEqual(obj1, obj2)); // true
|
|
43
|
-
*
|
|
44
|
-
* const arr1 = [1, 2, [3, 4]];
|
|
45
|
-
* const arr2 = [1, 2, [3, 4]];
|
|
46
|
-
* console.log(deepEqual(arr1, arr2)); // true
|
|
47
|
-
*
|
|
48
|
-
* const obj3 = { a: 1, b: { c: 2, d: 3 } };
|
|
49
|
-
* const obj4 = { a: 1, b: { c: 2 } };
|
|
50
|
-
* console.log(deepEqual(obj3, obj4, ['d'])); // true, excluding property 'd' from comparison
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
1
|
export function deepEqual(a, b, excludeProperties = []) {
|
|
54
|
-
// Toggle debugging on or off easily
|
|
55
2
|
const debug = false;
|
|
56
|
-
// Helper function for conditional logging
|
|
57
3
|
const debugLog = (...messages) => {
|
|
58
4
|
if (debug) {
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
5
|
console.log(...messages);
|
|
61
6
|
}
|
|
62
7
|
};
|
|
63
|
-
// If both are the same instance, return true (handles primitives and same object references)
|
|
64
8
|
if (a === b) {
|
|
65
9
|
return true;
|
|
66
10
|
}
|
|
67
|
-
// If types are different, return false
|
|
68
11
|
if (typeof a !== typeof b) {
|
|
69
12
|
debugLog(`deepEqual false for typeof a: ${typeof a} typeof b: ${typeof b}`);
|
|
70
13
|
return false;
|
|
71
14
|
}
|
|
72
|
-
// If one of them is null (and we know they are not equal from the first check), return false
|
|
73
15
|
if (a == null || b == null) {
|
|
74
16
|
debugLog('deepEqual false for == null');
|
|
75
17
|
return false;
|
|
76
18
|
}
|
|
77
|
-
// Handle Arrays
|
|
78
19
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
79
20
|
if (a.length !== b.length) {
|
|
80
21
|
debugLog(`deepEqual false for array a.length(${a.length}) !== b.length(${b.length})`);
|
|
@@ -90,31 +31,26 @@ export function deepEqual(a, b, excludeProperties = []) {
|
|
|
90
31
|
}
|
|
91
32
|
return true;
|
|
92
33
|
}
|
|
93
|
-
// Handle Objects (and exclude null, functions, and arrays)
|
|
94
34
|
if (typeof a === 'object' && typeof b === 'object') {
|
|
95
35
|
const aProps = Object.getOwnPropertyNames(a).filter((prop) => !excludeProperties.includes(prop));
|
|
96
36
|
const bProps = Object.getOwnPropertyNames(b).filter((prop) => !excludeProperties.includes(prop));
|
|
97
|
-
// If their property lengths are different, they're different objects
|
|
98
37
|
if (aProps.length !== bProps.length) {
|
|
99
38
|
debugLog(`deepEqual false for aProps.length(${aProps.length}) !== bProps.length(${bProps.length})`);
|
|
100
39
|
debugLog(`- aProps.length(${aProps.length}):`, aProps);
|
|
101
40
|
debugLog(`- bProps.length(${bProps.length}):`, bProps);
|
|
102
41
|
return false;
|
|
103
42
|
}
|
|
104
|
-
// Check each property in 'a' to see if it's in 'b' and if it's equal (deep check)
|
|
105
43
|
for (const prop of aProps) {
|
|
106
44
|
if (!Object.prototype.hasOwnProperty.call(b, prop)) {
|
|
107
45
|
debugLog(`deepEqual false for !b.hasOwnProperty(${prop})`);
|
|
108
46
|
return false;
|
|
109
47
|
}
|
|
110
48
|
if (!deepEqual(a[prop], b[prop], excludeProperties)) {
|
|
111
|
-
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`
|
|
49
|
+
debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`);
|
|
112
50
|
return false;
|
|
113
51
|
}
|
|
114
52
|
}
|
|
115
53
|
return true;
|
|
116
54
|
}
|
|
117
|
-
// If none of the above, the objects are not equal
|
|
118
55
|
return false;
|
|
119
56
|
}
|
|
120
|
-
//# sourceMappingURL=deepEqual.js.map
|
package/dist/utils/export.js
CHANGED
package/dist/utils/isvalid.js
CHANGED
|
@@ -1,44 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the deepEqual function.
|
|
3
|
-
*
|
|
4
|
-
* @file isvalid.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2025-02-16
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 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
|
-
/**
|
|
24
|
-
* Checks if a given string is a valid IPv4 address.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} ipv4Address - The string to be checked.
|
|
27
|
-
* @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
|
|
28
|
-
*/
|
|
29
1
|
export function isValidIpv4Address(ipv4Address) {
|
|
30
2
|
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]?)$/;
|
|
31
3
|
return ipv4Regex.test(ipv4Address);
|
|
32
4
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Checks if a value is a valid number within the specified range.
|
|
35
|
-
*
|
|
36
|
-
* @param {any} value - The value to be checked.
|
|
37
|
-
* @param {number} min - The minimum value allowed (optional).
|
|
38
|
-
* @param {number} max - The maximum value allowed (optional).
|
|
39
|
-
* @returns {boolean} Returns true if the value is a valid number within the specified range, otherwise false.
|
|
40
|
-
*/
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
5
|
export function isValidNumber(value, min, max) {
|
|
43
6
|
if (value === undefined || value === null || typeof value !== 'number' || Number.isNaN(value))
|
|
44
7
|
return false;
|
|
@@ -48,25 +11,9 @@ export function isValidNumber(value, min, max) {
|
|
|
48
11
|
return false;
|
|
49
12
|
return true;
|
|
50
13
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Checks if a value is a valid boolean.
|
|
53
|
-
*
|
|
54
|
-
* @param {any} value - The value to be checked.
|
|
55
|
-
* @returns {boolean} `true` if the value is a valid boolean, `false` otherwise.
|
|
56
|
-
*/
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
14
|
export function isValidBoolean(value) {
|
|
59
15
|
return value !== undefined && value !== null && typeof value === 'boolean';
|
|
60
16
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Checks if a value is a valid string.
|
|
63
|
-
*
|
|
64
|
-
* @param {any} value - The value to be checked.
|
|
65
|
-
* @param {number} minLength - The min string length (optional).
|
|
66
|
-
* @param {number} maxLength - The max string length (optional).
|
|
67
|
-
* @returns {boolean} A boolean indicating whether the value is a valid string.
|
|
68
|
-
*/
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
17
|
export function isValidString(value, minLength, maxLength) {
|
|
71
18
|
if (value === undefined || value === null || typeof value !== 'string')
|
|
72
19
|
return false;
|
|
@@ -76,15 +23,6 @@ export function isValidString(value, minLength, maxLength) {
|
|
|
76
23
|
return false;
|
|
77
24
|
return true;
|
|
78
25
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Checks if a value is a valid object.
|
|
81
|
-
*
|
|
82
|
-
* @param {any} value - The value to be checked.
|
|
83
|
-
* @param {number} minLength - The min number of keys (optional).
|
|
84
|
-
* @param {number} maxLength - The max number of keys (optional).
|
|
85
|
-
* @returns {boolean} A boolean indicating whether the value is a valid object.
|
|
86
|
-
*/
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
26
|
export function isValidObject(value, minLength, maxLength) {
|
|
89
27
|
if (value === undefined || value === null || typeof value !== 'object' || Array.isArray(value))
|
|
90
28
|
return false;
|
|
@@ -95,15 +33,6 @@ export function isValidObject(value, minLength, maxLength) {
|
|
|
95
33
|
return false;
|
|
96
34
|
return true;
|
|
97
35
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Checks if a value is a valid array.
|
|
100
|
-
*
|
|
101
|
-
* @param {any} value - The value to be checked.
|
|
102
|
-
* @param {number} minLength - The min number of elements (optional).
|
|
103
|
-
* @param {number} maxLength - The max number of elements (optional).
|
|
104
|
-
* @returns {boolean} A boolean indicating whether the value is a valid array.
|
|
105
|
-
*/
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
36
|
export function isValidArray(value, minLength, maxLength) {
|
|
108
37
|
if (value === undefined || value === null || !Array.isArray(value))
|
|
109
38
|
return false;
|
|
@@ -113,24 +42,9 @@ export function isValidArray(value, minLength, maxLength) {
|
|
|
113
42
|
return false;
|
|
114
43
|
return true;
|
|
115
44
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Checks if the given value is null.
|
|
118
|
-
*
|
|
119
|
-
* @param {any} value - The value to check.
|
|
120
|
-
* @returns {boolean} `true` if the value is null, `false` otherwise.
|
|
121
|
-
*/
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
45
|
export function isValidNull(value) {
|
|
124
46
|
return value === null;
|
|
125
47
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Checks if a value is undefined.
|
|
128
|
-
*
|
|
129
|
-
* @param {any} value - The value to check.
|
|
130
|
-
* @returns {boolean} `true` if the value is undefined, `false` otherwise.
|
|
131
|
-
*/
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
48
|
export function isValidUndefined(value) {
|
|
134
49
|
return value === undefined;
|
|
135
50
|
}
|
|
136
|
-
//# sourceMappingURL=isvalid.js.map
|
package/dist/utils/network.js
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the network function.
|
|
3
|
-
*
|
|
4
|
-
* @file network.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-02-17
|
|
7
|
-
* @version 1.0.0
|
|
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 'node:os';
|
|
25
|
-
// AnsiLogger module
|
|
26
2
|
import { AnsiLogger, idn, rs } from '../logger/export.js';
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
29
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
30
|
-
*/
|
|
31
3
|
export function getIpv4InterfaceAddress() {
|
|
32
4
|
let ipv4Address;
|
|
33
5
|
const networkInterfaces = os.networkInterfaces();
|
|
34
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
35
6
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
36
7
|
if (!interfaceDetails) {
|
|
37
8
|
break;
|
|
@@ -45,17 +16,11 @@ export function getIpv4InterfaceAddress() {
|
|
|
45
16
|
break;
|
|
46
17
|
}
|
|
47
18
|
}
|
|
48
|
-
// console.log('Selected Network Interfaces:', ipv4Address);
|
|
49
19
|
return ipv4Address;
|
|
50
20
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
53
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
54
|
-
*/
|
|
55
21
|
export function getIpv6InterfaceAddress() {
|
|
56
22
|
let ipv6Address;
|
|
57
23
|
const networkInterfaces = os.networkInterfaces();
|
|
58
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
59
24
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
60
25
|
if (!interfaceDetails) {
|
|
61
26
|
break;
|
|
@@ -69,17 +34,11 @@ export function getIpv6InterfaceAddress() {
|
|
|
69
34
|
break;
|
|
70
35
|
}
|
|
71
36
|
}
|
|
72
|
-
// console.log('Selected Network Interfaces:', ipv6Address);
|
|
73
37
|
return ipv6Address;
|
|
74
38
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Retrieves the mac address of the first non-internal network interface.
|
|
77
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
78
|
-
*/
|
|
79
39
|
export function getMacAddress() {
|
|
80
40
|
let macAddress;
|
|
81
41
|
const networkInterfaces = os.networkInterfaces();
|
|
82
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
83
42
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
84
43
|
if (!interfaceDetails) {
|
|
85
44
|
break;
|
|
@@ -95,13 +54,9 @@ export function getMacAddress() {
|
|
|
95
54
|
}
|
|
96
55
|
return macAddress;
|
|
97
56
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Logs the available network interfaces and their details.
|
|
100
|
-
* @param {boolean} log - Whether to enable logging of network interface details.
|
|
101
|
-
*/
|
|
102
57
|
export function logInterfaces(debug = true) {
|
|
103
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4
|
|
104
|
-
log.logLevel = "info"
|
|
58
|
+
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
|
|
59
|
+
log.logLevel = "info";
|
|
105
60
|
log.logName = 'LogInterfaces';
|
|
106
61
|
const networkInterfaces = os.networkInterfaces();
|
|
107
62
|
if (debug)
|
|
@@ -117,36 +72,16 @@ export function logInterfaces(debug = true) {
|
|
|
117
72
|
}
|
|
118
73
|
}
|
|
119
74
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Resolves the given hostname to an IP address.
|
|
122
|
-
*
|
|
123
|
-
* @param {string} hostname - The hostname to resolve.
|
|
124
|
-
* @param {0 | 4 | 6} [family=4] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
125
|
-
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
126
|
-
*
|
|
127
|
-
* @remarks
|
|
128
|
-
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
129
|
-
*/
|
|
130
75
|
export async function resolveHostname(hostname, family = 4) {
|
|
131
76
|
const dns = await import('node:dns');
|
|
132
77
|
try {
|
|
133
|
-
const addresses = await dns.promises.lookup(hostname.toLowerCase()
|
|
78
|
+
const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
|
|
134
79
|
return addresses.address;
|
|
135
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
136
80
|
}
|
|
137
81
|
catch (error) {
|
|
138
82
|
return null;
|
|
139
83
|
}
|
|
140
84
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Retrieves the version of an npm package from the npm registry.
|
|
143
|
-
*
|
|
144
|
-
* @param {string} packageName - The name of the npm package.
|
|
145
|
-
* @param {string} [tag='latest'] - The tag of the package version to retrieve (default is 'latest').
|
|
146
|
-
* @param {number} [timeout=5000] - The timeout duration in milliseconds (default is 5000ms).
|
|
147
|
-
* @returns {Promise<string>} A promise that resolves to the version string of the package.
|
|
148
|
-
* @throws {Error} If the request fails or the tag is not found.
|
|
149
|
-
*/
|
|
150
85
|
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
|
|
151
86
|
const https = await import('https');
|
|
152
87
|
return new Promise((resolve, reject) => {
|
|
@@ -160,8 +95,8 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
160
95
|
let data = '';
|
|
161
96
|
if (res.statusCode !== 200) {
|
|
162
97
|
clearTimeout(timeoutId);
|
|
163
|
-
res.resume();
|
|
164
|
-
req.destroy();
|
|
98
|
+
res.resume();
|
|
99
|
+
req.destroy();
|
|
165
100
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
166
101
|
return;
|
|
167
102
|
}
|
|
@@ -172,7 +107,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
172
107
|
clearTimeout(timeoutId);
|
|
173
108
|
try {
|
|
174
109
|
const jsonData = JSON.parse(data);
|
|
175
|
-
// console.log(`Package ${packageName} tag ${tag}`, jsonData);
|
|
176
110
|
const version = jsonData['dist-tags']?.[tag];
|
|
177
111
|
if (version) {
|
|
178
112
|
resolve(version);
|
|
@@ -192,10 +126,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
192
126
|
});
|
|
193
127
|
});
|
|
194
128
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Retrieves the path to the global Node.js modules directory.
|
|
197
|
-
* @returns A promise that resolves to the path of the global Node.js modules directory.
|
|
198
|
-
*/
|
|
199
129
|
export async function getGlobalNodeModules() {
|
|
200
130
|
const { exec } = await import('node:child_process');
|
|
201
131
|
return new Promise((resolve, reject) => {
|
|
@@ -209,4 +139,3 @@ export async function getGlobalNodeModules() {
|
|
|
209
139
|
});
|
|
210
140
|
});
|
|
211
141
|
}
|
|
212
|
-
//# sourceMappingURL=network.js.map
|