matterbridge 3.3.0-dev-20251003-626ea2f → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/dist/cli.d.ts +26 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +91 -2
  4. package/dist/cli.js.map +1 -0
  5. package/dist/cliEmitter.d.ts +34 -0
  6. package/dist/cliEmitter.d.ts.map +1 -0
  7. package/dist/cliEmitter.js +30 -0
  8. package/dist/cliEmitter.js.map +1 -0
  9. package/dist/clusters/export.d.ts +2 -0
  10. package/dist/clusters/export.d.ts.map +1 -0
  11. package/dist/clusters/export.js +2 -0
  12. package/dist/clusters/export.js.map +1 -0
  13. package/dist/defaultConfigSchema.d.ts +28 -0
  14. package/dist/defaultConfigSchema.d.ts.map +1 -0
  15. package/dist/defaultConfigSchema.js +24 -0
  16. package/dist/defaultConfigSchema.js.map +1 -0
  17. package/dist/deviceManager.d.ts +112 -0
  18. package/dist/deviceManager.d.ts.map +1 -0
  19. package/dist/deviceManager.js +94 -1
  20. package/dist/deviceManager.js.map +1 -0
  21. package/dist/devices/airConditioner.d.ts +98 -0
  22. package/dist/devices/airConditioner.d.ts.map +1 -0
  23. package/dist/devices/airConditioner.js +57 -0
  24. package/dist/devices/airConditioner.js.map +1 -0
  25. package/dist/devices/batteryStorage.d.ts +48 -0
  26. package/dist/devices/batteryStorage.d.ts.map +1 -0
  27. package/dist/devices/batteryStorage.js +48 -1
  28. package/dist/devices/batteryStorage.js.map +1 -0
  29. package/dist/devices/cooktop.d.ts +60 -0
  30. package/dist/devices/cooktop.d.ts.map +1 -0
  31. package/dist/devices/cooktop.js +55 -0
  32. package/dist/devices/cooktop.js.map +1 -0
  33. package/dist/devices/dishwasher.d.ts +71 -0
  34. package/dist/devices/dishwasher.d.ts.map +1 -0
  35. package/dist/devices/dishwasher.js +57 -0
  36. package/dist/devices/dishwasher.js.map +1 -0
  37. package/dist/devices/evse.d.ts +75 -0
  38. package/dist/devices/evse.d.ts.map +1 -0
  39. package/dist/devices/evse.js +74 -10
  40. package/dist/devices/evse.js.map +1 -0
  41. package/dist/devices/export.d.ts +17 -0
  42. package/dist/devices/export.d.ts.map +1 -0
  43. package/dist/devices/export.js +5 -0
  44. package/dist/devices/export.js.map +1 -0
  45. package/dist/devices/extractorHood.d.ts +46 -0
  46. package/dist/devices/extractorHood.d.ts.map +1 -0
  47. package/dist/devices/extractorHood.js +42 -0
  48. package/dist/devices/extractorHood.js.map +1 -0
  49. package/dist/devices/heatPump.d.ts +47 -0
  50. package/dist/devices/heatPump.d.ts.map +1 -0
  51. package/dist/devices/heatPump.js +50 -2
  52. package/dist/devices/heatPump.js.map +1 -0
  53. package/dist/devices/laundryDryer.d.ts +67 -0
  54. package/dist/devices/laundryDryer.d.ts.map +1 -0
  55. package/dist/devices/laundryDryer.js +62 -3
  56. package/dist/devices/laundryDryer.js.map +1 -0
  57. package/dist/devices/laundryWasher.d.ts +81 -0
  58. package/dist/devices/laundryWasher.d.ts.map +1 -0
  59. package/dist/devices/laundryWasher.js +70 -4
  60. package/dist/devices/laundryWasher.js.map +1 -0
  61. package/dist/devices/microwaveOven.d.ts +168 -0
  62. package/dist/devices/microwaveOven.d.ts.map +1 -0
  63. package/dist/devices/microwaveOven.js +88 -5
  64. package/dist/devices/microwaveOven.js.map +1 -0
  65. package/dist/devices/oven.d.ts +105 -0
  66. package/dist/devices/oven.d.ts.map +1 -0
  67. package/dist/devices/oven.js +85 -0
  68. package/dist/devices/oven.js.map +1 -0
  69. package/dist/devices/refrigerator.d.ts +118 -0
  70. package/dist/devices/refrigerator.d.ts.map +1 -0
  71. package/dist/devices/refrigerator.js +102 -0
  72. package/dist/devices/refrigerator.js.map +1 -0
  73. package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
  74. package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
  75. package/dist/devices/roboticVacuumCleaner.js +100 -9
  76. package/dist/devices/roboticVacuumCleaner.js.map +1 -0
  77. package/dist/devices/solarPower.d.ts +40 -0
  78. package/dist/devices/solarPower.d.ts.map +1 -0
  79. package/dist/devices/solarPower.js +38 -0
  80. package/dist/devices/solarPower.js.map +1 -0
  81. package/dist/devices/speaker.d.ts +87 -0
  82. package/dist/devices/speaker.d.ts.map +1 -0
  83. package/dist/devices/speaker.js +84 -0
  84. package/dist/devices/speaker.js.map +1 -0
  85. package/dist/devices/temperatureControl.d.ts +166 -0
  86. package/dist/devices/temperatureControl.d.ts.map +1 -0
  87. package/dist/devices/temperatureControl.js +25 -3
  88. package/dist/devices/temperatureControl.js.map +1 -0
  89. package/dist/devices/waterHeater.d.ts +111 -0
  90. package/dist/devices/waterHeater.d.ts.map +1 -0
  91. package/dist/devices/waterHeater.js +82 -2
  92. package/dist/devices/waterHeater.js.map +1 -0
  93. package/dist/dgram/coap.d.ts +205 -0
  94. package/dist/dgram/coap.d.ts.map +1 -0
  95. package/dist/dgram/coap.js +126 -13
  96. package/dist/dgram/coap.js.map +1 -0
  97. package/dist/dgram/dgram.d.ts +141 -0
  98. package/dist/dgram/dgram.d.ts.map +1 -0
  99. package/dist/dgram/dgram.js +114 -2
  100. package/dist/dgram/dgram.js.map +1 -0
  101. package/dist/dgram/mb_coap.d.ts +24 -0
  102. package/dist/dgram/mb_coap.d.ts.map +1 -0
  103. package/dist/dgram/mb_coap.js +41 -3
  104. package/dist/dgram/mb_coap.js.map +1 -0
  105. package/dist/dgram/mb_mdns.d.ts +24 -0
  106. package/dist/dgram/mb_mdns.d.ts.map +1 -0
  107. package/dist/dgram/mb_mdns.js +80 -15
  108. package/dist/dgram/mb_mdns.js.map +1 -0
  109. package/dist/dgram/mdns.d.ts +290 -0
  110. package/dist/dgram/mdns.d.ts.map +1 -0
  111. package/dist/dgram/mdns.js +299 -137
  112. package/dist/dgram/mdns.js.map +1 -0
  113. package/dist/dgram/multicast.d.ts +67 -0
  114. package/dist/dgram/multicast.d.ts.map +1 -0
  115. package/dist/dgram/multicast.js +62 -1
  116. package/dist/dgram/multicast.js.map +1 -0
  117. package/dist/dgram/unicast.d.ts +56 -0
  118. package/dist/dgram/unicast.d.ts.map +1 -0
  119. package/dist/dgram/unicast.js +54 -0
  120. package/dist/dgram/unicast.js.map +1 -0
  121. package/dist/frontend.d.ts +232 -0
  122. package/dist/frontend.d.ts.map +1 -0
  123. package/dist/frontend.js +454 -61
  124. package/dist/frontend.js.map +1 -0
  125. package/dist/frontendTypes.d.ts +514 -0
  126. package/dist/frontendTypes.d.ts.map +1 -0
  127. package/dist/frontendTypes.js +45 -0
  128. package/dist/frontendTypes.js.map +1 -0
  129. package/dist/globalMatterbridge.d.ts +59 -0
  130. package/dist/globalMatterbridge.d.ts.map +1 -0
  131. package/dist/globalMatterbridge.js +47 -0
  132. package/dist/globalMatterbridge.js.map +1 -0
  133. package/dist/helpers.d.ts +48 -0
  134. package/dist/helpers.d.ts.map +1 -0
  135. package/dist/helpers.js +53 -0
  136. package/dist/helpers.js.map +1 -0
  137. package/dist/index.d.ts +33 -0
  138. package/dist/index.d.ts.map +1 -0
  139. package/dist/index.js +30 -1
  140. package/dist/index.js.map +1 -0
  141. package/dist/logger/export.d.ts +2 -0
  142. package/dist/logger/export.d.ts.map +1 -0
  143. package/dist/logger/export.js +1 -0
  144. package/dist/logger/export.js.map +1 -0
  145. package/dist/matter/behaviors.d.ts +2 -0
  146. package/dist/matter/behaviors.d.ts.map +1 -0
  147. package/dist/matter/behaviors.js +2 -0
  148. package/dist/matter/behaviors.js.map +1 -0
  149. package/dist/matter/clusters.d.ts +2 -0
  150. package/dist/matter/clusters.d.ts.map +1 -0
  151. package/dist/matter/clusters.js +2 -0
  152. package/dist/matter/clusters.js.map +1 -0
  153. package/dist/matter/devices.d.ts +2 -0
  154. package/dist/matter/devices.d.ts.map +1 -0
  155. package/dist/matter/devices.js +2 -0
  156. package/dist/matter/devices.js.map +1 -0
  157. package/dist/matter/endpoints.d.ts +2 -0
  158. package/dist/matter/endpoints.d.ts.map +1 -0
  159. package/dist/matter/endpoints.js +2 -0
  160. package/dist/matter/endpoints.js.map +1 -0
  161. package/dist/matter/export.d.ts +5 -0
  162. package/dist/matter/export.d.ts.map +1 -0
  163. package/dist/matter/export.js +3 -0
  164. package/dist/matter/export.js.map +1 -0
  165. package/dist/matter/types.d.ts +3 -0
  166. package/dist/matter/types.d.ts.map +1 -0
  167. package/dist/matter/types.js +3 -0
  168. package/dist/matter/types.js.map +1 -0
  169. package/dist/matterbridge.d.ts +430 -0
  170. package/dist/matterbridge.d.ts.map +1 -0
  171. package/dist/matterbridge.js +788 -68
  172. package/dist/matterbridge.js.map +1 -0
  173. package/dist/matterbridgeAccessoryPlatform.d.ts +42 -0
  174. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
  175. package/dist/matterbridgeAccessoryPlatform.js +36 -0
  176. package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
  177. package/dist/matterbridgeBehaviors.d.ts +1747 -0
  178. package/dist/matterbridgeBehaviors.d.ts.map +1 -0
  179. package/dist/matterbridgeBehaviors.js +65 -5
  180. package/dist/matterbridgeBehaviors.js.map +1 -0
  181. package/dist/matterbridgeDeviceTypes.d.ts +761 -0
  182. package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
  183. package/dist/matterbridgeDeviceTypes.js +630 -17
  184. package/dist/matterbridgeDeviceTypes.js.map +1 -0
  185. package/dist/matterbridgeDynamicPlatform.d.ts +42 -0
  186. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
  187. package/dist/matterbridgeDynamicPlatform.js +36 -0
  188. package/dist/matterbridgeDynamicPlatform.js.map +1 -0
  189. package/dist/matterbridgeEndpoint.d.ts +1534 -0
  190. package/dist/matterbridgeEndpoint.d.ts.map +1 -0
  191. package/dist/matterbridgeEndpoint.js +1398 -58
  192. package/dist/matterbridgeEndpoint.js.map +1 -0
  193. package/dist/matterbridgeEndpointHelpers.d.ts +407 -0
  194. package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
  195. package/dist/matterbridgeEndpointHelpers.js +345 -12
  196. package/dist/matterbridgeEndpointHelpers.js.map +1 -0
  197. package/dist/matterbridgePlatform.d.ts +402 -0
  198. package/dist/matterbridgePlatform.d.ts.map +1 -0
  199. package/dist/matterbridgePlatform.js +340 -1
  200. package/dist/matterbridgePlatform.js.map +1 -0
  201. package/dist/matterbridgeTypes.d.ts +201 -0
  202. package/dist/matterbridgeTypes.d.ts.map +1 -0
  203. package/dist/matterbridgeTypes.js +30 -0
  204. package/dist/matterbridgeTypes.js.map +1 -0
  205. package/dist/pluginManager.d.ts +270 -0
  206. package/dist/pluginManager.d.ts.map +1 -0
  207. package/dist/pluginManager.js +249 -3
  208. package/dist/pluginManager.js.map +1 -0
  209. package/dist/shelly.d.ts +174 -0
  210. package/dist/shelly.d.ts.map +1 -0
  211. package/dist/shelly.js +168 -7
  212. package/dist/shelly.js.map +1 -0
  213. package/dist/storage/export.d.ts +2 -0
  214. package/dist/storage/export.d.ts.map +1 -0
  215. package/dist/storage/export.js +1 -0
  216. package/dist/storage/export.js.map +1 -0
  217. package/dist/update.d.ts +75 -0
  218. package/dist/update.d.ts.map +1 -0
  219. package/dist/update.js +69 -0
  220. package/dist/update.js.map +1 -0
  221. package/dist/utils/colorUtils.d.ts +99 -0
  222. package/dist/utils/colorUtils.d.ts.map +1 -0
  223. package/dist/utils/colorUtils.js +97 -2
  224. package/dist/utils/colorUtils.js.map +1 -0
  225. package/dist/utils/commandLine.d.ts +59 -0
  226. package/dist/utils/commandLine.d.ts.map +1 -0
  227. package/dist/utils/commandLine.js +54 -0
  228. package/dist/utils/commandLine.js.map +1 -0
  229. package/dist/utils/copyDirectory.d.ts +33 -0
  230. package/dist/utils/copyDirectory.d.ts.map +1 -0
  231. package/dist/utils/copyDirectory.js +38 -1
  232. package/dist/utils/copyDirectory.js.map +1 -0
  233. package/dist/utils/createDirectory.d.ts +34 -0
  234. package/dist/utils/createDirectory.d.ts.map +1 -0
  235. package/dist/utils/createDirectory.js +33 -0
  236. package/dist/utils/createDirectory.js.map +1 -0
  237. package/dist/utils/createZip.d.ts +39 -0
  238. package/dist/utils/createZip.d.ts.map +1 -0
  239. package/dist/utils/createZip.js +47 -2
  240. package/dist/utils/createZip.js.map +1 -0
  241. package/dist/utils/deepCopy.d.ts +32 -0
  242. package/dist/utils/deepCopy.d.ts.map +1 -0
  243. package/dist/utils/deepCopy.js +39 -0
  244. package/dist/utils/deepCopy.js.map +1 -0
  245. package/dist/utils/deepEqual.d.ts +54 -0
  246. package/dist/utils/deepEqual.d.ts.map +1 -0
  247. package/dist/utils/deepEqual.js +72 -1
  248. package/dist/utils/deepEqual.js.map +1 -0
  249. package/dist/utils/error.d.ts +44 -0
  250. package/dist/utils/error.d.ts.map +1 -0
  251. package/dist/utils/error.js +41 -0
  252. package/dist/utils/error.js.map +1 -0
  253. package/dist/utils/export.d.ts +13 -0
  254. package/dist/utils/export.d.ts.map +1 -0
  255. package/dist/utils/export.js +1 -0
  256. package/dist/utils/export.js.map +1 -0
  257. package/dist/utils/hex.d.ts +89 -0
  258. package/dist/utils/hex.d.ts.map +1 -0
  259. package/dist/utils/hex.js +124 -0
  260. package/dist/utils/hex.js.map +1 -0
  261. package/dist/utils/isvalid.d.ts +103 -0
  262. package/dist/utils/isvalid.d.ts.map +1 -0
  263. package/dist/utils/isvalid.js +101 -0
  264. package/dist/utils/isvalid.js.map +1 -0
  265. package/dist/utils/jestHelpers.d.ts +137 -0
  266. package/dist/utils/jestHelpers.d.ts.map +1 -0
  267. package/dist/utils/jestHelpers.js +153 -3
  268. package/dist/utils/jestHelpers.js.map +1 -0
  269. package/dist/utils/network.d.ts +84 -0
  270. package/dist/utils/network.d.ts.map +1 -0
  271. package/dist/utils/network.js +91 -5
  272. package/dist/utils/network.js.map +1 -0
  273. package/dist/utils/spawn.d.ts +34 -0
  274. package/dist/utils/spawn.d.ts.map +1 -0
  275. package/dist/utils/spawn.js +69 -0
  276. package/dist/utils/spawn.js.map +1 -0
  277. package/dist/utils/wait.d.ts +54 -0
  278. package/dist/utils/wait.d.ts.map +1 -0
  279. package/dist/utils/wait.js +60 -8
  280. package/dist/utils/wait.js.map +1 -0
  281. package/npm-shrinkwrap.json +2 -2
  282. package/package.json +2 -1
@@ -0,0 +1,84 @@
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
+ /**
24
+ * Retrieves the IPv4 address of the first non-internal network interface.
25
+ *
26
+ * @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
27
+ */
28
+ export declare function getIpv4InterfaceAddress(): string | undefined;
29
+ /**
30
+ * Retrieves the IPv6 address of the first non-internal network interface.
31
+ *
32
+ * @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
33
+ */
34
+ export declare function getIpv6InterfaceAddress(): string | undefined;
35
+ /**
36
+ * Retrieves the mac address of the first non-internal network interface.
37
+ *
38
+ * @returns {string | undefined} The mac address, or undefined if not found.
39
+ */
40
+ export declare function getMacAddress(): string | undefined;
41
+ /**
42
+ * Logs the available network interfaces and their details.
43
+ *
44
+ * @returns {void}
45
+ */
46
+ export declare function logInterfaces(): void;
47
+ /**
48
+ * Resolves the given hostname to an IP address.
49
+ *
50
+ * @param {string} hostname - The hostname to resolve.
51
+ * @param {0 | 4 | 6} [family] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
52
+ * @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
53
+ *
54
+ * @remarks
55
+ * This function uses DNS lookup to resolve the hostname, which can take some time to complete.
56
+ */
57
+ export declare function resolveHostname(hostname: string, family?: 0 | 4 | 6): Promise<string | null>;
58
+ /**
59
+ * Retrieves the version of an npm package from the npm registry.
60
+ *
61
+ * @param {string} packageName - The name of the npm package.
62
+ * @param {string} [tag] - The tag of the package version to retrieve (default is 'latest').
63
+ * @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
64
+ * @returns {Promise<string>} A promise that resolves to the version string of the package.
65
+ * @throws {Error} If the request fails or the tag is not found.
66
+ */
67
+ export declare function getNpmPackageVersion(packageName: string, tag?: string, timeout?: number): Promise<string>;
68
+ /**
69
+ * Retrieves a file from the public directory of the Matterbridge GitHub repository.
70
+ *
71
+ * @param {string} branch - The branch from which to fetch the file.
72
+ * @param {string} file - The file path to fetch.
73
+ * @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
74
+ * @returns {Promise<Record<string, boolean | string | number>>} A promise that resolves to the parsed JSON object from the file.
75
+ * @throws {Error} If the request fails or the JSON parsing fails.
76
+ */
77
+ export declare function getGitHubUpdate(branch: 'main' | 'dev', file: string, timeout?: number): Promise<Record<string, boolean | string | number>>;
78
+ /**
79
+ * Retrieves the path to the global Node.js modules directory.
80
+ *
81
+ * @returns {Promise<string>} A promise that resolves to the path of the global Node.js modules directory.
82
+ */
83
+ export declare function getGlobalNodeModules(): Promise<string>;
84
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAUH;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAmB5D;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAmB5D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAkBlD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAmBpC;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,CAAC,GAAG,CAAC,GAAG,CAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASrG;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAE,MAAiB,EAAE,OAAO,GAAE,MAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CA8ChI;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAc,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC,CAyCvJ;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAW5D"}
@@ -1,8 +1,38 @@
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
1
24
  import os from 'node:os';
25
+ // AnsiLogger module
2
26
  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
+ */
3
32
  export function getIpv4InterfaceAddress() {
4
33
  let ipv4Address;
5
34
  const networkInterfaces = os.networkInterfaces();
35
+ // console.log('Available Network Interfaces:', networkInterfaces);
6
36
  for (const interfaceDetails of Object.values(networkInterfaces)) {
7
37
  if (!interfaceDetails) {
8
38
  break;
@@ -16,11 +46,18 @@ export function getIpv4InterfaceAddress() {
16
46
  break;
17
47
  }
18
48
  }
49
+ // console.log('Selected Network Interfaces:', ipv4Address);
19
50
  return ipv4Address;
20
51
  }
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
+ */
21
57
  export function getIpv6InterfaceAddress() {
22
58
  let ipv6Address;
23
59
  const networkInterfaces = os.networkInterfaces();
60
+ // console.log('Available Network Interfaces:', networkInterfaces);
24
61
  for (const interfaceDetails of Object.values(networkInterfaces)) {
25
62
  if (!interfaceDetails) {
26
63
  break;
@@ -34,11 +71,18 @@ export function getIpv6InterfaceAddress() {
34
71
  break;
35
72
  }
36
73
  }
74
+ // console.log('Selected Network Interfaces:', ipv6Address);
37
75
  return ipv6Address;
38
76
  }
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
+ */
39
82
  export function getMacAddress() {
40
83
  let macAddress;
41
84
  const networkInterfaces = os.networkInterfaces();
85
+ // console.log('Available Network Interfaces:', networkInterfaces);
42
86
  for (const interfaceDetails of Object.values(networkInterfaces)) {
43
87
  if (!interfaceDetails) {
44
88
  break;
@@ -54,9 +98,14 @@ export function getMacAddress() {
54
98
  }
55
99
  return macAddress;
56
100
  }
101
+ /**
102
+ * Logs the available network interfaces and their details.
103
+ *
104
+ * @returns {void}
105
+ */
57
106
  export function logInterfaces() {
58
- const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
59
- log.logLevel = "info";
107
+ const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
108
+ log.logLevel = "info" /* LogLevel.INFO */;
60
109
  log.logName = 'LogInterfaces';
61
110
  log.info('Available Network Interfaces:');
62
111
  const availableAddresses = Object.entries(os.networkInterfaces());
@@ -70,16 +119,36 @@ export function logInterfaces() {
70
119
  }
71
120
  }
72
121
  }
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
+ */
73
132
  export async function resolveHostname(hostname, family = 4) {
74
133
  const dns = await import('node:dns');
75
134
  try {
76
- const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
135
+ const addresses = await dns.promises.lookup(hostname.toLowerCase() /* + '.local'*/, { family });
77
136
  return addresses.address;
137
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
78
138
  }
79
139
  catch (error) {
80
140
  return null;
81
141
  }
82
142
  }
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
+ */
83
152
  export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
84
153
  const https = await import('node:https');
85
154
  return new Promise((resolve, reject) => {
@@ -93,7 +162,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
93
162
  let data = '';
94
163
  if (res.statusCode !== 200) {
95
164
  clearTimeout(timeoutId);
96
- res.resume();
165
+ res.resume(); // Discard response data to close the socket properly
97
166
  reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
98
167
  return;
99
168
  }
@@ -104,6 +173,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
104
173
  clearTimeout(timeoutId);
105
174
  try {
106
175
  const jsonData = JSON.parse(data);
176
+ // console.log(`Package ${packageName} tag ${tag}`, jsonData);
107
177
  const version = jsonData['dist-tags']?.[tag];
108
178
  if (version) {
109
179
  resolve(version);
@@ -123,6 +193,15 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
123
193
  });
124
194
  });
125
195
  }
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
+ */
126
205
  export async function getGitHubUpdate(branch, file, timeout = 10000) {
127
206
  const https = await import('node:https');
128
207
  return new Promise((resolve, reject) => {
@@ -136,7 +215,7 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
136
215
  let data = '';
137
216
  if (res.statusCode !== 200) {
138
217
  clearTimeout(timeoutId);
139
- res.resume();
218
+ res.resume(); // Discard response data to close the socket properly
140
219
  reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
141
220
  return;
142
221
  }
@@ -154,12 +233,18 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
154
233
  }
155
234
  });
156
235
  });
236
+ // istanbul ignore next
157
237
  req.on('error', (error) => {
158
238
  clearTimeout(timeoutId);
159
239
  reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
160
240
  });
161
241
  });
162
242
  }
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
+ */
163
248
  export async function getGlobalNodeModules() {
164
249
  const { exec } = await import('node:child_process');
165
250
  return new Promise((resolve, reject) => {
@@ -173,3 +258,4 @@ export async function getGlobalNodeModules() {
173
258
  });
174
259
  });
175
260
  }
261
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,kBAAkB;AAClB,OAAO,EAAE,MAAM,SAAS,CAAC;AAIzB,oBAAoB;AACpB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAY,EAAE,EAAmB,MAAM,kBAAkB,CAAC;AAEzF;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,WAA+B,CAAC;IACpC,MAAM,iBAAiB,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC;IACjD,mEAAmE;IACnE,KAAK,MAAM,gBAAgB,IAAI,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAChE,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM;QACR,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE,CAAC;YACtC,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9E,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM;QACR,CAAC;IACH,CAAC;IACD,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O,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,34 @@
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
+ import type { Matterbridge } from '../matterbridge.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
+ * @param {string} [packageName] - The name of the package being installed (optional).
31
+ * @returns {Promise<boolean>} A promise that resolves when the child process exits successfully, or rejects if there is an error.
32
+ */
33
+ export declare function spawnCommand(matterbridge: Matterbridge, command: string, args: string[], packageName?: string): Promise<boolean>;
34
+ //# sourceMappingURL=spawn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/utils/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAsHtI"}
@@ -1,12 +1,52 @@
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
+ */
1
23
  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
+ * @param {string} [packageName] - The name of the package being installed (optional).
31
+ * @returns {Promise<boolean>} A promise that resolves when the child process exits successfully, or rejects if there is an error.
32
+ */
2
33
  export async function spawnCommand(matterbridge, command, args, packageName) {
3
34
  const { spawn } = await import('node:child_process');
35
+ /*
36
+ npm > npm.cmd on windows
37
+ cmd.exe ['dir'] on windows
38
+ await this.spawnCommand('npm', ['install', '-g', 'matterbridge']);
39
+ */
4
40
  const cmdLine = command + ' ' + args.join(' ');
5
41
  if (process.platform === 'win32' && command === 'npm') {
42
+ // Must be spawn('cmd.exe', ['/c', 'npm -g install <package>']);
6
43
  const argstring = 'npm ' + args.join(' ');
7
44
  args.splice(0, args.length, '/c', argstring);
8
45
  command = 'cmd.exe';
9
46
  }
47
+ // Decide when using sudo on linux and macOS
48
+ // When you need sudo: Spawn stderr: npm error Error: EACCES: permission denied
49
+ // When you don't need sudo: Failed to start child process "npm install -g matterbridge-eve-door": spawn sudo ENOENT
10
50
  if (hasParameter('sudo') || (process.platform !== 'win32' && command === 'npm' && !hasParameter('docker') && !hasParameter('nosudo'))) {
11
51
  args.unshift(command);
12
52
  command = 'sudo';
@@ -63,6 +103,20 @@ export async function spawnCommand(matterbridge, command, args, packageName) {
63
103
  matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', line);
64
104
  }
65
105
  });
106
+ /*
107
+ childProcess.stdout.on('close', () => {
108
+ matterbridge.log.debug(`Spawn output (stdout): closed`);
109
+ resolve(true);
110
+ });
111
+ childProcess.stdout.on('end', () => {
112
+ matterbridge.log.debug(`Spawn output (stdout): ended`);
113
+ resolve(true);
114
+ });
115
+ childProcess.stdout.on('error', () => {
116
+ matterbridge.log.debug(`Spawn output (stdout): error`);
117
+ resolve(true);
118
+ });
119
+ */
66
120
  }
67
121
  if (childProcess.stderr) {
68
122
  childProcess.stderr.on('data', (data) => {
@@ -73,6 +127,21 @@ export async function spawnCommand(matterbridge, command, args, packageName) {
73
127
  matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', line);
74
128
  }
75
129
  });
130
+ /*
131
+ childProcess.stderr.on('close', () => {
132
+ matterbridge.log.debug(`Spawn verbose (stderr): closed`);
133
+ resolve(true);
134
+ });
135
+ childProcess.stderr.on('end', () => {
136
+ matterbridge.log.debug(`Spawn verbose (stderr): ended`);
137
+ resolve(true);
138
+ });
139
+ childProcess.stderr.on('error', () => {
140
+ matterbridge.log.debug(`Spawn verbose (stderr): error`);
141
+ resolve(true);
142
+ });
143
+ */
76
144
  }
77
145
  });
78
146
  }
147
+ //# sourceMappingURL=spawn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../src/utils/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AY,EAAE,EAAE;gBAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;gBACvC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAClC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACzB,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;oBAC1D,YAAY,CAAC,QAAQ,CAAC,iBAAiB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,oBAAoB,EAAE,IAAI,CAAC,CAAC;gBACvG,CAAC;YACH,CAAC,CAAC,CAAC;YACH;;;;;;;;;;;;;cAaE;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,54 @@
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
+ /**
25
+ * Asynchronous waiter function that resolves when the provided condition is met or rejects on timeout.
26
+ *
27
+ * @param {string} name - The name of the waiter.
28
+ * @param {() => boolean} check - A function that checks the condition. Should return a boolean.
29
+ * @param {boolean} [exitWithReject] - Optional. If true, the promise will be rejected on timeout. Default is false.
30
+ * @param {number} [resolveTimeout] - Optional. The timeout duration in milliseconds. Default is 5000ms.
31
+ * @param {number} [resolveInterval] - Optional. The interval duration in milliseconds between condition checks. Default is 500ms.
32
+ * @param {boolean} [debug] - Optional. If true, debug messages will be logged to the console. Default is false.
33
+ * @returns {Promise<boolean>} A promise that resolves to true when the condition is met, or false if the timeout occurs.
34
+ */
35
+ export declare function waiter(name: string, check: () => boolean, exitWithReject?: boolean, resolveTimeout?: number, resolveInterval?: number, debug?: boolean): Promise<boolean>;
36
+ /**
37
+ * Asynchronously waits for a specified amount of time.
38
+ *
39
+ * @param {number} timeout - The duration to wait in milliseconds. Default is 1000ms.
40
+ * @param {string} name - The name of the wait operation. Default is undefined.
41
+ * @param {boolean} debug - Whether to enable debug logging. Default is false.
42
+ * @returns {Promise<void>} A Promise that resolves after the specified timeout.
43
+ */
44
+ export declare function wait(timeout?: number, name?: string, debug?: boolean): Promise<void>;
45
+ /**
46
+ * Wraps a promise with a timeout. If the promise does not resolve or reject within the specified time, it will be rejected.
47
+ *
48
+ * @param {Promise<T>} promise - The promise to wrap.
49
+ * @param {number} [timeoutMillisecs] - The timeout duration in milliseconds. Default is 10000ms.
50
+ * @param {boolean} [reThrow] - Optional. If true, the promise will rethrow the original promise and will reject on timeout. Default is true.
51
+ * @returns {Promise<T>} A new promise that resolves or rejects based on the original promise and the timeout.
52
+ */
53
+ export declare function withTimeout<T>(promise: Promise<T>, timeoutMillisecs?: number, reThrow?: boolean): Promise<T>;
54
+ //# sourceMappingURL=wait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../../src/utils/wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH;;;;;;;;;;GAUG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,OAAO,EAAE,cAAc,GAAE,OAAe,EAAE,cAAc,GAAE,MAAa,EAAE,eAAe,GAAE,MAAY,EAAE,KAAK,GAAE,OAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BxM;AAED;;;;;;;GAOG;AACH,wBAAsB,IAAI,CAAC,OAAO,GAAE,MAAa,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAWvG;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,gBAAgB,GAAE,MAAc,EAAE,OAAO,GAAE,OAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAwBzH"}
@@ -1,6 +1,41 @@
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
1
25
  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
+ */
2
37
  export async function waiter(name, check, exitWithReject = false, resolveTimeout = 5000, resolveInterval = 500, debug = false) {
3
- const log = new AnsiLogger({ logName: 'Waiter', logTimestampFormat: 4, logLevel: "debug" });
38
+ const log = new AnsiLogger({ logName: 'Waiter', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "debug" /* LogLevel.DEBUG */ });
4
39
  if (check()) {
5
40
  if (debug)
6
41
  log.debug(`Waiter "${name}" already true`);
@@ -31,8 +66,16 @@ export async function waiter(name, check, exitWithReject = false, resolveTimeout
31
66
  }, resolveInterval).unref();
32
67
  });
33
68
  }
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
+ */
34
77
  export async function wait(timeout = 1000, name, debug = false) {
35
- const log = new AnsiLogger({ logName: 'Wait', logTimestampFormat: 4, logLevel: "debug" });
78
+ const log = new AnsiLogger({ logName: 'Wait', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "debug" /* LogLevel.DEBUG */ });
36
79
  if (debug)
37
80
  log.debug(`Wait "${name}" started...`);
38
81
  return new Promise((resolve) => {
@@ -44,6 +87,14 @@ export async function wait(timeout = 1000, name, debug = false) {
44
87
  }, timeout).unref();
45
88
  });
46
89
  }
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
+ */
47
98
  export function withTimeout(promise, timeoutMillisecs = 10000, reThrow = true) {
48
99
  return new Promise((resolve, reject) => {
49
100
  const timer = setTimeout(() => {
@@ -51,23 +102,24 @@ export function withTimeout(promise, timeoutMillisecs = 10000, reThrow = true) {
51
102
  reject(new Error('Operation timed out'));
52
103
  }
53
104
  else {
54
- resolve(undefined);
105
+ resolve(undefined); // Resolve with undefined if reThrow is false
55
106
  }
56
- }, timeoutMillisecs).unref();
107
+ }, timeoutMillisecs).unref(); // Unref the timer to prevent it from keeping the event loop alive
57
108
  promise
58
109
  .then((result) => {
59
- clearTimeout(timer);
110
+ clearTimeout(timer); // Ensure timeout does not fire if promise resolves first
60
111
  resolve(result);
61
112
  return result;
62
113
  })
63
114
  .catch((error) => {
64
- clearTimeout(timer);
115
+ clearTimeout(timer); // Ensure timeout does not fire if promise rejects first
65
116
  if (reThrow) {
66
- reject(error);
117
+ reject(error); // Reject with the original error
67
118
  }
68
119
  else {
69
- resolve(undefined);
120
+ resolve(undefined); // Resolve with undefined if reThrow is false
70
121
  }
71
122
  });
72
123
  });
73
124
  }
125
+ //# sourceMappingURL=wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.js","sourceRoot":"","sources":["../../src/utils/wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,oBAAoB;AACpB,OAAO,EAAE,UAAU,EAA6B,MAAM,kBAAkB,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAY,EAAE,KAAoB,EAAE,iBAA0B,KAAK,EAAE,iBAAyB,IAAI,EAAE,kBAA0B,GAAG,EAAE,QAAiB,KAAK;IACpL,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,qCAA6B,EAAE,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C,KAAK,EAAE,EAAE;YACf,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,wDAAwD;YAC7E,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,iCAAiC;YAClD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,SAAyB,CAAC,CAAC,CAAC,6CAA6C;YACnF,CAAC;QACH,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge",
3
- "version": "3.3.0-dev-20251003-626ea2f",
3
+ "version": "3.3.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge",
9
- "version": "3.3.0-dev-20251003-626ea2f",
9
+ "version": "3.3.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@matter/main": "0.15.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge",
3
- "version": "3.3.0-dev-20251003-626ea2f",
3
+ "version": "3.3.0",
4
4
  "description": "Matterbridge plugin manager for Matter",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",
@@ -40,6 +40,7 @@
40
40
  ],
41
41
  "type": "module",
42
42
  "main": "dist/index.js",
43
+ "types": "dist/index.d.ts",
43
44
  "bin": {
44
45
  "matterbridge": "bin/matterbridge.js",
45
46
  "mb_mdns": "bin/mb_mdns.js",