matterbridge 2.1.4 → 2.1.5-dev.2

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