matterbridge 3.2.8 → 3.2.9-dev-20250922-517cae7
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 +24 -1
- package/README-NGINX.md +47 -23
- package/dist/cli.js +2 -91
- package/dist/cliEmitter.js +0 -30
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -94
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -84
- package/dist/devices/temperatureControl.js +3 -25
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +45 -435
- package/dist/frontendTypes.js +3 -51
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -30
- 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 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +57 -780
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +55 -1373
- package/dist/matterbridgeEndpointHelpers.js +12 -345
- package/dist/matterbridgePlatform.js +0 -304
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +3 -249
- package/dist/shelly.js +11 -172
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -124
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +5 -91
- package/dist/utils/spawn.js +0 -68
- package/dist/utils/wait.js +8 -60
- package/frontend/build/assets/index.js +2 -2
- package/frontend/build/assets/vendor_lodash.js +1 -1
- package/frontend/build/assets/vendor_mdi.js +1 -1
- package/frontend/build/assets/vendor_mui.js +31 -23
- package/frontend/build/assets/vendor_node_modules.js +28 -45
- package/frontend/build/assets/vendor_notistack.js +2 -2
- package/frontend/build/assets/vendor_qrcode.js +1 -1
- package/frontend/build/assets/vendor_rjsf.js +12 -3
- package/frontend/build/index.html +0 -1
- package/frontend/package-lock.json +208 -283
- package/frontend/package.json +4 -13
- package/npm-shrinkwrap.json +44 -44
- package/package.json +2 -3
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -112
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -228
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -572
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -33
- 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 -442
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1747
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -761
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1515
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -380
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -190
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -270
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- 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 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -99
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/jestHelpers.d.ts +0 -137
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -84
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -33
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- package/frontend/build/assets/vendor_react_table.js +0 -1
package/dist/utils/network.js
CHANGED
|
@@ -1,38 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file contains the network functions.
|
|
3
|
-
* @file network.ts
|
|
4
|
-
* @author Luca Liguori
|
|
5
|
-
* @created 2024-02-17
|
|
6
|
-
* @version 1.0.1
|
|
7
|
-
* @license Apache-2.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, BLUE, CYAN, nf } from 'node-ansi-logger';
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
29
|
-
*
|
|
30
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
31
|
-
*/
|
|
32
3
|
export function getIpv4InterfaceAddress() {
|
|
33
4
|
let ipv4Address;
|
|
34
5
|
const networkInterfaces = os.networkInterfaces();
|
|
35
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
36
6
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
37
7
|
if (!interfaceDetails) {
|
|
38
8
|
break;
|
|
@@ -46,18 +16,11 @@ export function getIpv4InterfaceAddress() {
|
|
|
46
16
|
break;
|
|
47
17
|
}
|
|
48
18
|
}
|
|
49
|
-
// console.log('Selected Network Interfaces:', ipv4Address);
|
|
50
19
|
return ipv4Address;
|
|
51
20
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
54
|
-
*
|
|
55
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
56
|
-
*/
|
|
57
21
|
export function getIpv6InterfaceAddress() {
|
|
58
22
|
let ipv6Address;
|
|
59
23
|
const networkInterfaces = os.networkInterfaces();
|
|
60
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
61
24
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
62
25
|
if (!interfaceDetails) {
|
|
63
26
|
break;
|
|
@@ -71,18 +34,11 @@ export function getIpv6InterfaceAddress() {
|
|
|
71
34
|
break;
|
|
72
35
|
}
|
|
73
36
|
}
|
|
74
|
-
// console.log('Selected Network Interfaces:', ipv6Address);
|
|
75
37
|
return ipv6Address;
|
|
76
38
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Retrieves the mac address of the first non-internal network interface.
|
|
79
|
-
*
|
|
80
|
-
* @returns {string | undefined} The mac address, or undefined if not found.
|
|
81
|
-
*/
|
|
82
39
|
export function getMacAddress() {
|
|
83
40
|
let macAddress;
|
|
84
41
|
const networkInterfaces = os.networkInterfaces();
|
|
85
|
-
// console.log('Available Network Interfaces:', networkInterfaces);
|
|
86
42
|
for (const interfaceDetails of Object.values(networkInterfaces)) {
|
|
87
43
|
if (!interfaceDetails) {
|
|
88
44
|
break;
|
|
@@ -98,14 +54,9 @@ export function getMacAddress() {
|
|
|
98
54
|
}
|
|
99
55
|
return macAddress;
|
|
100
56
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Logs the available network interfaces and their details.
|
|
103
|
-
*
|
|
104
|
-
* @returns {void}
|
|
105
|
-
*/
|
|
106
57
|
export function logInterfaces() {
|
|
107
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4
|
|
108
|
-
log.logLevel = "info"
|
|
58
|
+
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
|
|
59
|
+
log.logLevel = "info";
|
|
109
60
|
log.logName = 'LogInterfaces';
|
|
110
61
|
log.info('Available Network Interfaces:');
|
|
111
62
|
const availableAddresses = Object.entries(os.networkInterfaces());
|
|
@@ -119,36 +70,16 @@ export function logInterfaces() {
|
|
|
119
70
|
}
|
|
120
71
|
}
|
|
121
72
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Resolves the given hostname to an IP address.
|
|
124
|
-
*
|
|
125
|
-
* @param {string} hostname - The hostname to resolve.
|
|
126
|
-
* @param {0 | 4 | 6} [family] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
127
|
-
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
128
|
-
*
|
|
129
|
-
* @remarks
|
|
130
|
-
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
131
|
-
*/
|
|
132
73
|
export async function resolveHostname(hostname, family = 4) {
|
|
133
74
|
const dns = await import('node:dns');
|
|
134
75
|
try {
|
|
135
|
-
const addresses = await dns.promises.lookup(hostname.toLowerCase()
|
|
76
|
+
const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
|
|
136
77
|
return addresses.address;
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
138
78
|
}
|
|
139
79
|
catch (error) {
|
|
140
80
|
return null;
|
|
141
81
|
}
|
|
142
82
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Retrieves the version of an npm package from the npm registry.
|
|
145
|
-
*
|
|
146
|
-
* @param {string} packageName - The name of the npm package.
|
|
147
|
-
* @param {string} [tag] - The tag of the package version to retrieve (default is 'latest').
|
|
148
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
|
|
149
|
-
* @returns {Promise<string>} A promise that resolves to the version string of the package.
|
|
150
|
-
* @throws {Error} If the request fails or the tag is not found.
|
|
151
|
-
*/
|
|
152
83
|
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
|
|
153
84
|
const https = await import('node:https');
|
|
154
85
|
return new Promise((resolve, reject) => {
|
|
@@ -162,7 +93,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
162
93
|
let data = '';
|
|
163
94
|
if (res.statusCode !== 200) {
|
|
164
95
|
clearTimeout(timeoutId);
|
|
165
|
-
res.resume();
|
|
96
|
+
res.resume();
|
|
166
97
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
167
98
|
return;
|
|
168
99
|
}
|
|
@@ -173,7 +104,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
173
104
|
clearTimeout(timeoutId);
|
|
174
105
|
try {
|
|
175
106
|
const jsonData = JSON.parse(data);
|
|
176
|
-
// console.log(`Package ${packageName} tag ${tag}`, jsonData);
|
|
177
107
|
const version = jsonData['dist-tags']?.[tag];
|
|
178
108
|
if (version) {
|
|
179
109
|
resolve(version);
|
|
@@ -193,15 +123,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
193
123
|
});
|
|
194
124
|
});
|
|
195
125
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Retrieves a file from the public directory of the Matterbridge GitHub repository.
|
|
198
|
-
*
|
|
199
|
-
* @param {string} branch - The branch from which to fetch the file.
|
|
200
|
-
* @param {string} file - The file path to fetch.
|
|
201
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
|
|
202
|
-
* @returns {Promise<Record<string, boolean | string | number>>} A promise that resolves to the parsed JSON object from the file.
|
|
203
|
-
* @throws {Error} If the request fails or the JSON parsing fails.
|
|
204
|
-
*/
|
|
205
126
|
export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
206
127
|
const https = await import('node:https');
|
|
207
128
|
return new Promise((resolve, reject) => {
|
|
@@ -215,7 +136,7 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
215
136
|
let data = '';
|
|
216
137
|
if (res.statusCode !== 200) {
|
|
217
138
|
clearTimeout(timeoutId);
|
|
218
|
-
res.resume();
|
|
139
|
+
res.resume();
|
|
219
140
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
220
141
|
return;
|
|
221
142
|
}
|
|
@@ -233,18 +154,12 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
233
154
|
}
|
|
234
155
|
});
|
|
235
156
|
});
|
|
236
|
-
// istanbul ignore next
|
|
237
157
|
req.on('error', (error) => {
|
|
238
158
|
clearTimeout(timeoutId);
|
|
239
159
|
reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
|
|
240
160
|
});
|
|
241
161
|
});
|
|
242
162
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Retrieves the path to the global Node.js modules directory.
|
|
245
|
-
*
|
|
246
|
-
* @returns {Promise<string>} A promise that resolves to the path of the global Node.js modules directory.
|
|
247
|
-
*/
|
|
248
163
|
export async function getGlobalNodeModules() {
|
|
249
164
|
const { exec } = await import('node:child_process');
|
|
250
165
|
return new Promise((resolve, reject) => {
|
|
@@ -258,4 +173,3 @@ export async function getGlobalNodeModules() {
|
|
|
258
173
|
});
|
|
259
174
|
});
|
|
260
175
|
}
|
|
261
|
-
//# sourceMappingURL=network.js.map
|
package/dist/utils/spawn.js
CHANGED
|
@@ -1,51 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file contains the spawn functions.
|
|
3
|
-
* @file spawn.ts
|
|
4
|
-
* @author Luca Liguori
|
|
5
|
-
* @created 2025-02-16
|
|
6
|
-
* @version 1.1.0
|
|
7
|
-
* @license Apache-2.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
1
|
import { hasParameter } from './commandLine.js';
|
|
24
|
-
/**
|
|
25
|
-
* Spawns a child process with the given command and arguments.
|
|
26
|
-
*
|
|
27
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance to use for logging and sending messages.
|
|
28
|
-
* @param {string} command - The command to execute.
|
|
29
|
-
* @param {string[]} args - The arguments to pass to the command (default: []).
|
|
30
|
-
* @returns {Promise<boolean>} A promise that resolves when the child process exits successfully, or rejects if there is an error.
|
|
31
|
-
*/
|
|
32
2
|
export async function spawnCommand(matterbridge, command, args) {
|
|
33
3
|
const { spawn } = await import('node:child_process');
|
|
34
|
-
/*
|
|
35
|
-
npm > npm.cmd on windows
|
|
36
|
-
cmd.exe ['dir'] on windows
|
|
37
|
-
await this.spawnCommand('npm', ['install', '-g', 'matterbridge']);
|
|
38
|
-
*/
|
|
39
4
|
const cmdLine = command + ' ' + args.join(' ');
|
|
40
5
|
if (process.platform === 'win32' && command === 'npm') {
|
|
41
|
-
// Must be spawn('cmd.exe', ['/c', 'npm -g install <package>']);
|
|
42
6
|
const argstring = 'npm ' + args.join(' ');
|
|
43
7
|
args.splice(0, args.length, '/c', argstring);
|
|
44
8
|
command = 'cmd.exe';
|
|
45
9
|
}
|
|
46
|
-
// Decide when using sudo on linux and macOS
|
|
47
|
-
// When you need sudo: Spawn stderr: npm error Error: EACCES: permission denied
|
|
48
|
-
// When you don't need sudo: Failed to start child process "npm install -g matterbridge-eve-door": spawn sudo ENOENT
|
|
49
10
|
if (hasParameter('sudo') || (process.platform !== 'win32' && command === 'npm' && !hasParameter('docker') && !hasParameter('nosudo'))) {
|
|
50
11
|
args.unshift(command);
|
|
51
12
|
command = 'sudo';
|
|
@@ -93,20 +54,6 @@ export async function spawnCommand(matterbridge, command, args) {
|
|
|
93
54
|
matterbridge.log.debug(`Spawn output (stdout): ${message}`);
|
|
94
55
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', message);
|
|
95
56
|
});
|
|
96
|
-
/*
|
|
97
|
-
childProcess.stdout.on('close', () => {
|
|
98
|
-
matterbridge.log.debug(`Spawn output (stdout): closed`);
|
|
99
|
-
resolve(true);
|
|
100
|
-
});
|
|
101
|
-
childProcess.stdout.on('end', () => {
|
|
102
|
-
matterbridge.log.debug(`Spawn output (stdout): ended`);
|
|
103
|
-
resolve(true);
|
|
104
|
-
});
|
|
105
|
-
childProcess.stdout.on('error', () => {
|
|
106
|
-
matterbridge.log.debug(`Spawn output (stdout): error`);
|
|
107
|
-
resolve(true);
|
|
108
|
-
});
|
|
109
|
-
*/
|
|
110
57
|
}
|
|
111
58
|
if (childProcess.stderr) {
|
|
112
59
|
childProcess.stderr.on('data', (data) => {
|
|
@@ -114,21 +61,6 @@ export async function spawnCommand(matterbridge, command, args) {
|
|
|
114
61
|
matterbridge.log.debug(`Spawn verbose (stderr): ${message}`);
|
|
115
62
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', message);
|
|
116
63
|
});
|
|
117
|
-
/*
|
|
118
|
-
childProcess.stderr.on('close', () => {
|
|
119
|
-
matterbridge.log.debug(`Spawn verbose (stderr): closed`);
|
|
120
|
-
resolve(true);
|
|
121
|
-
});
|
|
122
|
-
childProcess.stderr.on('end', () => {
|
|
123
|
-
matterbridge.log.debug(`Spawn verbose (stderr): ended`);
|
|
124
|
-
resolve(true);
|
|
125
|
-
});
|
|
126
|
-
childProcess.stderr.on('error', () => {
|
|
127
|
-
matterbridge.log.debug(`Spawn verbose (stderr): error`);
|
|
128
|
-
resolve(true);
|
|
129
|
-
});
|
|
130
|
-
*/
|
|
131
64
|
}
|
|
132
65
|
});
|
|
133
66
|
}
|
|
134
|
-
//# sourceMappingURL=spawn.js.map
|
package/dist/utils/wait.js
CHANGED
|
@@ -1,41 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the wait, waiter and withTimeout functions.
|
|
3
|
-
*
|
|
4
|
-
* @file wait.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2025-02-16
|
|
7
|
-
* @version 1.0.2
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
// AnsiLogger module
|
|
25
1
|
import { AnsiLogger } from 'node-ansi-logger';
|
|
26
|
-
/**
|
|
27
|
-
* Asynchronous waiter function that resolves when the provided condition is met or rejects on timeout.
|
|
28
|
-
*
|
|
29
|
-
* @param {string} name - The name of the waiter.
|
|
30
|
-
* @param {() => boolean} check - A function that checks the condition. Should return a boolean.
|
|
31
|
-
* @param {boolean} [exitWithReject] - Optional. If true, the promise will be rejected on timeout. Default is false.
|
|
32
|
-
* @param {number} [resolveTimeout] - Optional. The timeout duration in milliseconds. Default is 5000ms.
|
|
33
|
-
* @param {number} [resolveInterval] - Optional. The interval duration in milliseconds between condition checks. Default is 500ms.
|
|
34
|
-
* @param {boolean} [debug] - Optional. If true, debug messages will be logged to the console. Default is false.
|
|
35
|
-
* @returns {Promise<boolean>} A promise that resolves to true when the condition is met, or false if the timeout occurs.
|
|
36
|
-
*/
|
|
37
2
|
export async function waiter(name, check, exitWithReject = false, resolveTimeout = 5000, resolveInterval = 500, debug = false) {
|
|
38
|
-
const log = new AnsiLogger({ logName: 'Waiter', logTimestampFormat: 4
|
|
3
|
+
const log = new AnsiLogger({ logName: 'Waiter', logTimestampFormat: 4, logLevel: "debug" });
|
|
39
4
|
if (check()) {
|
|
40
5
|
if (debug)
|
|
41
6
|
log.debug(`Waiter "${name}" already true`);
|
|
@@ -66,16 +31,8 @@ export async function waiter(name, check, exitWithReject = false, resolveTimeout
|
|
|
66
31
|
}, resolveInterval).unref();
|
|
67
32
|
});
|
|
68
33
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Asynchronously waits for a specified amount of time.
|
|
71
|
-
*
|
|
72
|
-
* @param {number} timeout - The duration to wait in milliseconds. Default is 1000ms.
|
|
73
|
-
* @param {string} name - The name of the wait operation. Default is undefined.
|
|
74
|
-
* @param {boolean} debug - Whether to enable debug logging. Default is false.
|
|
75
|
-
* @returns {Promise<void>} A Promise that resolves after the specified timeout.
|
|
76
|
-
*/
|
|
77
34
|
export async function wait(timeout = 1000, name, debug = false) {
|
|
78
|
-
const log = new AnsiLogger({ logName: 'Wait', logTimestampFormat: 4
|
|
35
|
+
const log = new AnsiLogger({ logName: 'Wait', logTimestampFormat: 4, logLevel: "debug" });
|
|
79
36
|
if (debug)
|
|
80
37
|
log.debug(`Wait "${name}" started...`);
|
|
81
38
|
return new Promise((resolve) => {
|
|
@@ -87,14 +44,6 @@ export async function wait(timeout = 1000, name, debug = false) {
|
|
|
87
44
|
}, timeout).unref();
|
|
88
45
|
});
|
|
89
46
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Wraps a promise with a timeout. If the promise does not resolve or reject within the specified time, it will be rejected.
|
|
92
|
-
*
|
|
93
|
-
* @param {Promise<T>} promise - The promise to wrap.
|
|
94
|
-
* @param {number} [timeoutMillisecs] - The timeout duration in milliseconds. Default is 10000ms.
|
|
95
|
-
* @param {boolean} [reThrow] - Optional. If true, the promise will rethrow the original promise and will reject on timeout. Default is true.
|
|
96
|
-
* @returns {Promise<T>} A new promise that resolves or rejects based on the original promise and the timeout.
|
|
97
|
-
*/
|
|
98
47
|
export function withTimeout(promise, timeoutMillisecs = 10000, reThrow = true) {
|
|
99
48
|
return new Promise((resolve, reject) => {
|
|
100
49
|
const timer = setTimeout(() => {
|
|
@@ -102,24 +51,23 @@ export function withTimeout(promise, timeoutMillisecs = 10000, reThrow = true) {
|
|
|
102
51
|
reject(new Error('Operation timed out'));
|
|
103
52
|
}
|
|
104
53
|
else {
|
|
105
|
-
resolve(undefined);
|
|
54
|
+
resolve(undefined);
|
|
106
55
|
}
|
|
107
|
-
}, timeoutMillisecs).unref();
|
|
56
|
+
}, timeoutMillisecs).unref();
|
|
108
57
|
promise
|
|
109
58
|
.then((result) => {
|
|
110
|
-
clearTimeout(timer);
|
|
59
|
+
clearTimeout(timer);
|
|
111
60
|
resolve(result);
|
|
112
61
|
return result;
|
|
113
62
|
})
|
|
114
63
|
.catch((error) => {
|
|
115
|
-
clearTimeout(timer);
|
|
64
|
+
clearTimeout(timer);
|
|
116
65
|
if (reThrow) {
|
|
117
|
-
reject(error);
|
|
66
|
+
reject(error);
|
|
118
67
|
}
|
|
119
68
|
else {
|
|
120
|
-
resolve(undefined);
|
|
69
|
+
resolve(undefined);
|
|
121
70
|
}
|
|
122
71
|
});
|
|
123
72
|
});
|
|
124
73
|
}
|
|
125
|
-
//# sourceMappingURL=wait.js.map
|