matterbridge 2.2.6 → 3.0.0-edge.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README-DEV.md +24 -12
  3. package/dist/cli.js +2 -37
  4. package/dist/cluster/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +0 -23
  6. package/dist/deviceManager.js +1 -94
  7. package/dist/frontend.js +23 -325
  8. package/dist/index.js +1 -28
  9. package/dist/logger/export.js +0 -1
  10. package/dist/matter/behaviors.js +0 -2
  11. package/dist/matter/clusters.js +0 -2
  12. package/dist/matter/devices.js +0 -2
  13. package/dist/matter/endpoints.js +0 -2
  14. package/dist/matter/export.js +0 -2
  15. package/dist/matter/types.js +0 -2
  16. package/dist/matterbridge.js +89 -760
  17. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  18. package/dist/matterbridgeBehaviors.js +15 -41
  19. package/dist/matterbridgeDeviceTypes.js +151 -228
  20. package/dist/matterbridgeDynamicPlatform.js +0 -33
  21. package/dist/matterbridgeEndpoint.js +116 -718
  22. package/dist/matterbridgeEndpointHelpers.js +30 -136
  23. package/dist/matterbridgePlatform.js +12 -221
  24. package/dist/matterbridgeTypes.js +0 -24
  25. package/dist/pluginManager.js +98 -251
  26. package/dist/shelly.js +6 -146
  27. package/dist/storage/export.js +0 -1
  28. package/dist/update.js +0 -45
  29. package/dist/utils/colorUtils.js +2 -205
  30. package/dist/utils/copyDirectory.js +1 -37
  31. package/dist/utils/createZip.js +2 -42
  32. package/dist/utils/deepCopy.js +0 -40
  33. package/dist/utils/deepEqual.js +1 -65
  34. package/dist/utils/export.js +0 -1
  35. package/dist/utils/isvalid.js +0 -86
  36. package/dist/utils/network.js +5 -76
  37. package/dist/utils/parameter.js +0 -41
  38. package/dist/utils/wait.js +5 -48
  39. package/frontend/build/asset-manifest.json +3 -3
  40. package/frontend/build/index.html +1 -1
  41. package/frontend/build/static/js/{main.f00179ca.js → main.1fa50342.js} +3 -3
  42. package/frontend/build/static/js/{main.f00179ca.js.map → main.1fa50342.js.map} +1 -1
  43. package/npm-shrinkwrap.json +44 -44
  44. package/package.json +2 -3
  45. package/dist/cli.d.ts +0 -29
  46. package/dist/cli.d.ts.map +0 -1
  47. package/dist/cli.js.map +0 -1
  48. package/dist/cluster/export.d.ts +0 -2
  49. package/dist/cluster/export.d.ts.map +0 -1
  50. package/dist/cluster/export.js.map +0 -1
  51. package/dist/defaultConfigSchema.d.ts +0 -27
  52. package/dist/defaultConfigSchema.d.ts.map +0 -1
  53. package/dist/defaultConfigSchema.js.map +0 -1
  54. package/dist/deviceManager.d.ts +0 -114
  55. package/dist/deviceManager.d.ts.map +0 -1
  56. package/dist/deviceManager.js.map +0 -1
  57. package/dist/frontend.d.ts +0 -221
  58. package/dist/frontend.d.ts.map +0 -1
  59. package/dist/frontend.js.map +0 -1
  60. package/dist/index.d.ts +0 -35
  61. package/dist/index.d.ts.map +0 -1
  62. package/dist/index.js.map +0 -1
  63. package/dist/logger/export.d.ts +0 -2
  64. package/dist/logger/export.d.ts.map +0 -1
  65. package/dist/logger/export.js.map +0 -1
  66. package/dist/matter/behaviors.d.ts +0 -2
  67. package/dist/matter/behaviors.d.ts.map +0 -1
  68. package/dist/matter/behaviors.js.map +0 -1
  69. package/dist/matter/clusters.d.ts +0 -2
  70. package/dist/matter/clusters.d.ts.map +0 -1
  71. package/dist/matter/clusters.js.map +0 -1
  72. package/dist/matter/devices.d.ts +0 -2
  73. package/dist/matter/devices.d.ts.map +0 -1
  74. package/dist/matter/devices.js.map +0 -1
  75. package/dist/matter/endpoints.d.ts +0 -2
  76. package/dist/matter/endpoints.d.ts.map +0 -1
  77. package/dist/matter/endpoints.js.map +0 -1
  78. package/dist/matter/export.d.ts +0 -5
  79. package/dist/matter/export.d.ts.map +0 -1
  80. package/dist/matter/export.js.map +0 -1
  81. package/dist/matter/types.d.ts +0 -3
  82. package/dist/matter/types.d.ts.map +0 -1
  83. package/dist/matter/types.js.map +0 -1
  84. package/dist/matterbridge.d.ts +0 -425
  85. package/dist/matterbridge.d.ts.map +0 -1
  86. package/dist/matterbridge.js.map +0 -1
  87. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
  88. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  89. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  90. package/dist/matterbridgeBehaviors.d.ts +0 -1056
  91. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  92. package/dist/matterbridgeBehaviors.js.map +0 -1
  93. package/dist/matterbridgeDeviceTypes.d.ts +0 -177
  94. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  95. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  96. package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
  97. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  98. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  99. package/dist/matterbridgeEndpoint.d.ts +0 -835
  100. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  101. package/dist/matterbridgeEndpoint.js.map +0 -1
  102. package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
  103. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  104. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  105. package/dist/matterbridgePlatform.d.ts +0 -285
  106. package/dist/matterbridgePlatform.d.ts.map +0 -1
  107. package/dist/matterbridgePlatform.js.map +0 -1
  108. package/dist/matterbridgeTypes.d.ts +0 -179
  109. package/dist/matterbridgeTypes.d.ts.map +0 -1
  110. package/dist/matterbridgeTypes.js.map +0 -1
  111. package/dist/pluginManager.d.ts +0 -236
  112. package/dist/pluginManager.d.ts.map +0 -1
  113. package/dist/pluginManager.js.map +0 -1
  114. package/dist/shelly.d.ts +0 -92
  115. package/dist/shelly.d.ts.map +0 -1
  116. package/dist/shelly.js.map +0 -1
  117. package/dist/storage/export.d.ts +0 -2
  118. package/dist/storage/export.d.ts.map +0 -1
  119. package/dist/storage/export.js.map +0 -1
  120. package/dist/update.d.ts +0 -32
  121. package/dist/update.d.ts.map +0 -1
  122. package/dist/update.js.map +0 -1
  123. package/dist/utils/colorUtils.d.ts +0 -61
  124. package/dist/utils/colorUtils.d.ts.map +0 -1
  125. package/dist/utils/colorUtils.js.map +0 -1
  126. package/dist/utils/copyDirectory.d.ts +0 -32
  127. package/dist/utils/copyDirectory.d.ts.map +0 -1
  128. package/dist/utils/copyDirectory.js.map +0 -1
  129. package/dist/utils/createZip.d.ts +0 -38
  130. package/dist/utils/createZip.d.ts.map +0 -1
  131. package/dist/utils/createZip.js.map +0 -1
  132. package/dist/utils/deepCopy.d.ts +0 -31
  133. package/dist/utils/deepCopy.d.ts.map +0 -1
  134. package/dist/utils/deepCopy.js.map +0 -1
  135. package/dist/utils/deepEqual.d.ts +0 -53
  136. package/dist/utils/deepEqual.d.ts.map +0 -1
  137. package/dist/utils/deepEqual.js.map +0 -1
  138. package/dist/utils/export.d.ts +0 -10
  139. package/dist/utils/export.d.ts.map +0 -1
  140. package/dist/utils/export.js.map +0 -1
  141. package/dist/utils/isvalid.d.ts +0 -87
  142. package/dist/utils/isvalid.d.ts.map +0 -1
  143. package/dist/utils/isvalid.js.map +0 -1
  144. package/dist/utils/network.d.ts +0 -69
  145. package/dist/utils/network.d.ts.map +0 -1
  146. package/dist/utils/network.js.map +0 -1
  147. package/dist/utils/parameter.d.ts +0 -44
  148. package/dist/utils/parameter.d.ts.map +0 -1
  149. package/dist/utils/parameter.js.map +0 -1
  150. package/dist/utils/wait.d.ts +0 -43
  151. package/dist/utils/wait.d.ts.map +0 -1
  152. package/dist/utils/wait.js.map +0 -1
  153. /package/frontend/build/static/js/{main.f00179ca.js.LICENSE.txt → main.1fa50342.js.LICENSE.txt} +0 -0
@@ -1,26 +1,3 @@
1
- /**
2
- * This file contains the Plugins class.
3
- *
4
- * @file plugins.ts
5
- * @author Luca Liguori
6
- * @date 2024-07-14
7
- * @version 1.1.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
- // AnsiLogger module
24
1
  import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr } from './logger/export.js';
25
2
  import { plg, typ } from './matterbridgeTypes.js';
26
3
  export class PluginManager {
@@ -30,9 +7,8 @@ export class PluginManager {
30
7
  log;
31
8
  constructor(matterbridge) {
32
9
  this.matterbridge = matterbridge;
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
10
  this.nodeContext = matterbridge.nodeContext;
35
- this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: matterbridge.log.logLevel });
11
+ this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
36
12
  this.log.debug('Matterbridge plugin manager starting...');
37
13
  }
38
14
  get length() {
@@ -67,9 +43,8 @@ export class PluginManager {
67
43
  try {
68
44
  await callback(plugin);
69
45
  }
70
- catch (error) {
71
- this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}:`, error);
72
- // throw error;
46
+ catch (err) {
47
+ this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
73
48
  }
74
49
  });
75
50
  await Promise.all(tasks);
@@ -77,31 +52,13 @@ export class PluginManager {
77
52
  set logLevel(logLevel) {
78
53
  this.log.logLevel = logLevel;
79
54
  }
80
- /**
81
- * Loads registered plugins from storage.
82
- *
83
- * This method retrieves an array of registered plugins from the storage and converts it
84
- * into a map where the plugin names are the keys and the plugin objects are the values.
85
- *
86
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
87
- */
88
55
  async loadFromStorage() {
89
- // Load the array from storage and convert it to a map
90
56
  const pluginsArray = await this.nodeContext.get('plugins', []);
91
57
  for (const plugin of pluginsArray)
92
58
  this._plugins.set(plugin.name, plugin);
93
59
  return pluginsArray;
94
60
  }
95
- /**
96
- * Loads registered plugins from storage.
97
- *
98
- * This method retrieves an array of registered plugins from the storage and converts it
99
- * into a map where the plugin names are the keys and the plugin objects are the values.
100
- *
101
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
102
- */
103
61
  async saveToStorage() {
104
- // Convert the map to an array
105
62
  const plugins = [];
106
63
  const pluginArrayFromMap = Array.from(this._plugins.values());
107
64
  for (const plugin of pluginArrayFromMap) {
@@ -121,20 +78,13 @@ export class PluginManager {
121
78
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
122
79
  return plugins.length;
123
80
  }
124
- /**
125
- * Resolves the name of a plugin by loading and parsing its package.json file.
126
- * @param pluginPath - The path to the plugin or the path to the plugin's package.json file.
127
- * @returns The path to the resolved package.json file, or null if the package.json file is not found or does not contain a name.
128
- */
129
81
  async resolve(pluginPath) {
130
82
  const { default: path } = await import('node:path');
131
83
  const { promises } = await import('node:fs');
132
84
  if (!pluginPath.endsWith('package.json'))
133
85
  pluginPath = path.join(pluginPath, 'package.json');
134
- // Resolve the package.json of the plugin
135
86
  let packageJsonPath = path.resolve(pluginPath);
136
87
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
137
- // Check if the package.json file exists
138
88
  try {
139
89
  await promises.access(packageJsonPath);
140
90
  }
@@ -144,13 +94,11 @@ export class PluginManager {
144
94
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
145
95
  }
146
96
  try {
147
- // Load the package.json of the plugin
148
97
  const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
149
98
  if (!packageJson.name) {
150
99
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
151
100
  return null;
152
101
  }
153
- // Check for main issues
154
102
  if (!packageJson.type || packageJson.type !== 'module') {
155
103
  this.log.error(`Plugin at ${packageJsonPath} is not a module`);
156
104
  return null;
@@ -159,7 +107,6 @@ export class PluginManager {
159
107
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
160
108
  return null;
161
109
  }
162
- // Check for @project-chip and @matter packages in dependencies and devDependencies
163
110
  const checkForProjectChipPackages = (dependencies) => {
164
111
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
165
112
  };
@@ -181,7 +128,6 @@ export class PluginManager {
181
128
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
182
129
  return null;
183
130
  }
184
- // Check for matterbridge package in dependencies and devDependencies
185
131
  const checkForMatterbridgePackage = (dependencies) => {
186
132
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
187
133
  };
@@ -207,15 +153,65 @@ export class PluginManager {
207
153
  return packageJsonPath;
208
154
  }
209
155
  catch (err) {
210
- this.log.error(`Failed to resolve plugin path ${plg}${pluginPath}${er}: ${err}`);
156
+ this.log.error(`Failed to resolve plugin path ${plg}${pluginPath}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
211
157
  return null;
212
158
  }
213
159
  }
214
- /**
215
- * Loads and parse the plugin package.json and returns it.
216
- * @param plugin - The plugin to load the package from.
217
- * @returns A Promise that resolves to the package.json object or undefined if the package.json could not be loaded.
218
- */
160
+ getAuthor(packageJson) {
161
+ if (packageJson.author && typeof packageJson.author === 'string')
162
+ return packageJson.author;
163
+ else if (packageJson.author && typeof packageJson.author === 'object' && packageJson.author.name && typeof packageJson.author.name === 'string')
164
+ return packageJson.author.name;
165
+ return 'Unknown author';
166
+ }
167
+ getHomepage(packageJson) {
168
+ if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
169
+ return packageJson.homepage.replace('git+', '').replace('.git', '');
170
+ }
171
+ else if (packageJson.repository && typeof packageJson.repository === 'object' && packageJson.repository.url && typeof packageJson.repository.url === 'string' && packageJson.repository.url.includes('http')) {
172
+ return packageJson.repository.url.replace('git+', '').replace('.git', '');
173
+ }
174
+ }
175
+ getHelp(packageJson) {
176
+ if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
177
+ return packageJson.help;
178
+ }
179
+ else if (packageJson.repository && typeof packageJson.repository === 'object' && packageJson.repository.url && typeof packageJson.repository.url === 'string' && packageJson.repository.url.includes('http')) {
180
+ return packageJson.repository.url.replace('git+', '').replace('.git', '') + '/blob/main/README.md';
181
+ }
182
+ else if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
183
+ return packageJson.homepage.replace('git+', '').replace('.git', '');
184
+ }
185
+ }
186
+ getChangelog(packageJson) {
187
+ if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
188
+ return packageJson.changelog;
189
+ }
190
+ else if (packageJson.repository && typeof packageJson.repository === 'object' && packageJson.repository.url && typeof packageJson.repository.url === 'string' && packageJson.repository.url.includes('http')) {
191
+ return packageJson.repository.url.replace('git+', '').replace('.git', '') + '/blob/main/CHANGELOG.md';
192
+ }
193
+ else if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
194
+ return packageJson.homepage.replace('git+', '').replace('.git', '');
195
+ }
196
+ }
197
+ getFunding(packageJson) {
198
+ const funding = packageJson.funding;
199
+ if (!funding)
200
+ return undefined;
201
+ if (typeof funding === 'string' && !funding.startsWith('http'))
202
+ return;
203
+ if (typeof funding === 'string' && funding.startsWith('http'))
204
+ return funding;
205
+ const fundingEntries = Array.isArray(funding) ? funding : [funding];
206
+ for (const entry of fundingEntries) {
207
+ if (entry && typeof entry === 'string' && entry.startsWith('http')) {
208
+ return entry;
209
+ }
210
+ else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
211
+ return entry.url;
212
+ }
213
+ }
214
+ }
219
215
  async parse(plugin) {
220
216
  const { promises } = await import('node:fs');
221
217
  try {
@@ -229,6 +225,8 @@ export class PluginManager {
229
225
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no description in package.json`);
230
226
  if (!packageJson.author)
231
227
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no author in package.json`);
228
+ if (!packageJson.homepage)
229
+ this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no homepage in package.json`);
232
230
  if (!packageJson.type || packageJson.type !== 'module')
233
231
  this.log.error(`Plugin ${plg}${plugin.name}${er} is not a module`);
234
232
  if (!packageJson.main)
@@ -236,12 +234,15 @@ export class PluginManager {
236
234
  plugin.name = packageJson.name || 'Unknown name';
237
235
  plugin.version = packageJson.version || '1.0.0';
238
236
  plugin.description = packageJson.description || 'Unknown description';
239
- plugin.author = packageJson.author || 'Unknown author';
237
+ plugin.author = this.getAuthor(packageJson);
238
+ plugin.homepage = this.getHomepage(packageJson);
239
+ plugin.help = this.getHelp(packageJson);
240
+ plugin.changelog = this.getChangelog(packageJson);
241
+ plugin.funding = this.getFunding(packageJson);
240
242
  if (!plugin.path)
241
243
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no path`);
242
244
  if (!plugin.type)
243
245
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
244
- // Check for @project-chip and @matter packages in dependencies and devDependencies
245
246
  const checkForProjectChipPackages = (dependencies) => {
246
247
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
247
248
  };
@@ -263,7 +264,6 @@ export class PluginManager {
263
264
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
264
265
  return null;
265
266
  }
266
- // Check for matterbridge package in dependencies and devDependencies
267
267
  const checkForMatterbridgePackage = (dependencies) => {
268
268
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
269
269
  };
@@ -285,25 +285,14 @@ export class PluginManager {
285
285
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
286
286
  return null;
287
287
  }
288
- // await this.saveToStorage(); // No need to save the plugin to storage
289
288
  return packageJson;
290
289
  }
291
290
  catch (err) {
292
- this.log.error(`Failed to parse package.json of plugin ${plg}${plugin.name}${er}: ${err}`);
291
+ this.log.error(`Failed to parse package.json of plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
293
292
  plugin.error = true;
294
293
  return null;
295
294
  }
296
295
  }
297
- /**
298
- * Enables a plugin by its name or path.
299
- *
300
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
301
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
302
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
303
- *
304
- * @param {string} nameOrPath - The name or path of the plugin to enable.
305
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
306
- */
307
296
  async enable(nameOrPath) {
308
297
  const { promises } = await import('node:fs');
309
298
  if (!nameOrPath || nameOrPath === '')
@@ -333,20 +322,10 @@ export class PluginManager {
333
322
  return plugin;
334
323
  }
335
324
  catch (err) {
336
- this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err}`);
325
+ this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
337
326
  return null;
338
327
  }
339
328
  }
340
- /**
341
- * Enables a plugin by its name or path.
342
- *
343
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
344
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
345
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
346
- *
347
- * @param {string} nameOrPath - The name or path of the plugin to enable.
348
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
349
- */
350
329
  async disable(nameOrPath) {
351
330
  const { promises } = await import('node:fs');
352
331
  if (!nameOrPath || nameOrPath === '')
@@ -376,20 +355,10 @@ export class PluginManager {
376
355
  return plugin;
377
356
  }
378
357
  catch (err) {
379
- this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err}`);
358
+ this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
380
359
  return null;
381
360
  }
382
361
  }
383
- /**
384
- * Removes a plugin by its name or path.
385
- *
386
- * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
387
- * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
388
- * the plugin's `package.json` file to retrieve its name and remove it.
389
- *
390
- * @param {string} nameOrPath - The name or path of the plugin to remove.
391
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
392
- */
393
362
  async remove(nameOrPath) {
394
363
  const { promises } = await import('node:fs');
395
364
  if (!nameOrPath || nameOrPath === '')
@@ -419,21 +388,10 @@ export class PluginManager {
419
388
  return plugin;
420
389
  }
421
390
  catch (err) {
422
- this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err}`);
391
+ this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
423
392
  return null;
424
393
  }
425
394
  }
426
- /**
427
- * Adds a plugin by its name or path.
428
- *
429
- * This method adds a plugin to the `_plugins` map and saves the updated plugin information to storage.
430
- * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
431
- * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
432
- * and saves the updated plugin information to storage.
433
- *
434
- * @param {string} nameOrPath - The name or path of the plugin to add.
435
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
436
- */
437
395
  async add(nameOrPath) {
438
396
  const { promises } = await import('node:fs');
439
397
  if (!nameOrPath || nameOrPath === '')
@@ -449,26 +407,25 @@ export class PluginManager {
449
407
  this.log.info(`Plugin ${plg}${nameOrPath}${nf} already registered`);
450
408
  return null;
451
409
  }
452
- this._plugins.set(packageJson.name, { name: packageJson.name, enabled: true, path: packageJsonPath, type: 'AnyPlatform', version: packageJson.version, description: packageJson.description, author: packageJson.author });
410
+ this._plugins.set(packageJson.name, {
411
+ name: packageJson.name,
412
+ enabled: true,
413
+ path: packageJsonPath,
414
+ type: 'AnyPlatform',
415
+ version: packageJson.version,
416
+ description: packageJson.description,
417
+ author: this.getAuthor(packageJson),
418
+ });
453
419
  this.log.info(`Added plugin ${plg}${packageJson.name}${nf}`);
454
420
  await this.saveToStorage();
455
421
  const plugin = this._plugins.get(packageJson.name);
456
422
  return plugin || null;
457
423
  }
458
424
  catch (err) {
459
- this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err instanceof Error ? err.message : err}`);
425
+ this.log.error(`Failed to parse package.json of plugin ${plg}${nameOrPath}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
460
426
  return null;
461
427
  }
462
428
  }
463
- /**
464
- * Installs a plugin by its name.
465
- *
466
- * This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
467
- * It logs the installation process and retrieves the installed version of the plugin.
468
- *
469
- * @param {string} name - The name of the plugin to install.
470
- * @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
471
- */
472
429
  async install(name) {
473
430
  const { exec } = await import('node:child_process');
474
431
  await this.uninstall(name);
@@ -483,14 +440,11 @@ export class PluginManager {
483
440
  else {
484
441
  this.log.info(`Installed plugin ${plg}${name}${nf}`);
485
442
  this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
486
- // Get the installed version
487
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
488
443
  exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
489
444
  if (listError) {
490
445
  this.log.error(`List error: ${listError}`);
491
446
  resolve(undefined);
492
447
  }
493
- // Clean the output to get only the package name and version
494
448
  const lines = listStdout.split('\n');
495
449
  const versionLine = lines.find((line) => line.includes(`${name}@`));
496
450
  if (versionLine) {
@@ -506,15 +460,6 @@ export class PluginManager {
506
460
  });
507
461
  });
508
462
  }
509
- /**
510
- * Uninstalls a plugin by its name.
511
- *
512
- * This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
513
- * and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
514
- *
515
- * @param {string} name - The name of the plugin to uninstall.
516
- * @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
517
- */
518
463
  async uninstall(name) {
519
464
  const { exec } = await import('node:child_process');
520
465
  this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
@@ -533,14 +478,6 @@ export class PluginManager {
533
478
  });
534
479
  });
535
480
  }
536
- /**
537
- * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
538
- * @param plugin - The plugin to load.
539
- * @param start - Optional flag indicating whether to start the plugin after loading. Default is false.
540
- * @param message - Optional message to pass to the plugin when starting.
541
- * @returns A Promise that resolves to the loaded MatterbridgePlatform instance.
542
- * @throws An error if the plugin is not enabled, already loaded, or fails to load.
543
- */
544
481
  async load(plugin, start = false, message = '', configure = false) {
545
482
  const { promises } = await import('node:fs');
546
483
  const { default: path } = await import('node:path');
@@ -554,29 +491,24 @@ export class PluginManager {
554
491
  }
555
492
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
556
493
  try {
557
- // Load the package.json of the plugin
558
494
  const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
559
- // Resolve the main module path relative to package.json
560
495
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
561
- // Dynamically import the plugin
562
496
  const { pathToFileURL } = await import('node:url');
563
497
  const pluginUrl = pathToFileURL(pluginEntry);
564
498
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
565
499
  const pluginInstance = await import(pluginUrl.href);
566
500
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
567
- // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
568
501
  if (pluginInstance.default) {
569
502
  const config = await this.loadConfig(plugin);
570
- // Preset the plugin properties here in case the plugin throws an error during loading. In this case the user can change the config and restart the plugin.
571
503
  plugin.name = packageJson.name;
572
504
  plugin.description = packageJson.description ?? 'No description';
573
505
  plugin.version = packageJson.version;
574
- plugin.author = packageJson.author ?? 'Unknown';
506
+ plugin.author = this.getAuthor(packageJson);
575
507
  plugin.configJson = config;
576
508
  plugin.schemaJson = await this.loadSchema(plugin);
577
509
  config.name = plugin.name;
578
510
  config.version = packageJson.version;
579
- const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
511
+ const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
580
512
  const platform = pluginInstance.default(this.matterbridge, log, config);
581
513
  config.type = platform.type;
582
514
  platform.name = packageJson.name;
@@ -585,15 +517,17 @@ export class PluginManager {
585
517
  plugin.name = packageJson.name;
586
518
  plugin.description = packageJson.description ?? 'No description';
587
519
  plugin.version = packageJson.version;
588
- plugin.author = packageJson.author ?? 'Unknown';
520
+ plugin.author = this.getAuthor(packageJson);
521
+ plugin.homepage = this.getHomepage(packageJson);
522
+ plugin.help = this.getHelp(packageJson);
523
+ plugin.changelog = this.getChangelog(packageJson);
524
+ plugin.funding = this.getFunding(packageJson);
589
525
  plugin.type = platform.type;
590
526
  plugin.platform = platform;
591
527
  plugin.loaded = true;
592
528
  plugin.registeredDevices = 0;
593
529
  plugin.addedDevices = 0;
594
- // plugin.configJson = config;
595
- // plugin.schemaJson = await this.loadSchema(plugin);
596
- await this.saveToStorage(); // Save the plugin to storage
530
+ await this.saveToStorage();
597
531
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
598
532
  if (start)
599
533
  await this.start(plugin, message, false);
@@ -607,19 +541,11 @@ export class PluginManager {
607
541
  }
608
542
  }
609
543
  catch (err) {
610
- this.log.error(`Failed to load plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message : err}`);
544
+ this.log.error(`Failed to load plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
611
545
  plugin.error = true;
612
546
  }
613
547
  return undefined;
614
548
  }
615
- /**
616
- * Starts a plugin.
617
- *
618
- * @param {RegisteredPlugin} plugin - The plugin to start.
619
- * @param {string} [message] - Optional message to pass to the plugin's onStart method.
620
- * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
621
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
622
- */
623
549
  async start(plugin, message, configure = false) {
624
550
  if (!plugin.loaded) {
625
551
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -645,16 +571,10 @@ export class PluginManager {
645
571
  }
646
572
  catch (err) {
647
573
  plugin.error = true;
648
- this.log.error(`Failed to start plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message : err}`);
574
+ this.log.error(`Failed to start plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
649
575
  }
650
576
  return undefined;
651
577
  }
652
- /**
653
- * Configures a plugin.
654
- *
655
- * @param {RegisteredPlugin} plugin - The plugin to configure.
656
- * @returns {Promise<void>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
657
- */
658
578
  async configure(plugin) {
659
579
  if (!plugin.loaded) {
660
580
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -681,22 +601,10 @@ export class PluginManager {
681
601
  }
682
602
  catch (err) {
683
603
  plugin.error = true;
684
- this.log.error(`Failed to configure plugin ${plg}${plugin.name}${er}: ${err}`);
604
+ this.log.error(`Failed to configure plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
685
605
  }
686
606
  return undefined;
687
607
  }
688
- /**
689
- * Shuts down a plugin.
690
- *
691
- * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
692
- * It logs the shutdown process and optionally removes all devices associated with the plugin.
693
- *
694
- * @param {RegisteredPlugin} plugin - The plugin to shut down.
695
- * @param {string} [reason] - The reason for shutting down the plugin.
696
- * @param {boolean} [removeAllDevices=false] - Whether to remove all devices associated with the plugin.
697
- * @param {boolean} [force=false] - Whether to force the shutdown even if the plugin is not loaded or started.
698
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
699
- */
700
608
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
701
609
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
702
610
  if (!plugin.loaded) {
@@ -735,19 +643,10 @@ export class PluginManager {
735
643
  return plugin;
736
644
  }
737
645
  catch (err) {
738
- this.log.error(`Failed to shut down plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message : err}`);
646
+ this.log.error(`Failed to shut down plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
739
647
  }
740
648
  return undefined;
741
649
  }
742
- /**
743
- * Loads the configuration for a plugin.
744
- * If the configuration file exists, it reads the file and returns the parsed JSON data.
745
- * If the configuration file does not exist, it creates a new file with default configuration and returns it.
746
- * If any error occurs during file access or creation, it logs an error and return un empty config.
747
- *
748
- * @param plugin - The plugin for which to load the configuration.
749
- * @returns A promise that resolves to the loaded or created configuration.
750
- */
751
650
  async loadConfig(plugin) {
752
651
  const { default: path } = await import('node:path');
753
652
  const { promises } = await import('node:fs');
@@ -758,8 +657,6 @@ export class PluginManager {
758
657
  const data = await promises.readFile(configFile, 'utf8');
759
658
  const config = JSON.parse(data);
760
659
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
761
- // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
762
- // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
763
660
  config.name = plugin.name;
764
661
  config.type = plugin.type;
765
662
  if (config.debug === undefined)
@@ -783,32 +680,19 @@ export class PluginManager {
783
680
  try {
784
681
  await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
785
682
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
786
- // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
787
683
  return config;
788
684
  }
789
685
  catch (err) {
790
- this.log.error(`Error creating config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message : err}`);
686
+ this.log.error(`Error creating config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
791
687
  return config;
792
688
  }
793
689
  }
794
690
  else {
795
- this.log.error(`Error accessing config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message : err}`);
691
+ this.log.error(`Error accessing config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
796
692
  return { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
797
693
  }
798
694
  }
799
695
  }
800
- /**
801
- * Saves the configuration of a plugin to a file.
802
- *
803
- * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
804
- * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
805
- * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
806
- * the error and rejects the promise.
807
- *
808
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
809
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
810
- * @throws {Error} If the plugin's configuration is not found.
811
- */
812
696
  async saveConfigFromPlugin(plugin) {
813
697
  const { default: path } = await import('node:path');
814
698
  const { promises } = await import('node:fs');
@@ -821,27 +705,13 @@ export class PluginManager {
821
705
  await promises.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
822
706
  plugin.configJson = plugin.platform.config;
823
707
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
824
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
825
708
  return Promise.resolve();
826
709
  }
827
710
  catch (err) {
828
- this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err}`);
711
+ this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
829
712
  return Promise.reject(err);
830
713
  }
831
714
  }
832
- /**
833
- * Saves the configuration of a plugin from a JSON object to a file.
834
- *
835
- * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
836
- * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
837
- * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
838
- * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
839
- * during the file write operation, it logs the error and returns.
840
- *
841
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
842
- * @param {PlatformConfig} config - The configuration data to be saved.
843
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
844
- */
845
715
  async saveConfigFromJson(plugin, config) {
846
716
  const { default: path } = await import('node:path');
847
717
  const { promises } = await import('node:fs');
@@ -859,23 +729,12 @@ export class PluginManager {
859
729
  plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
860
730
  }
861
731
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
862
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
863
732
  }
864
733
  catch (err) {
865
- this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err}`);
734
+ this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
866
735
  return;
867
736
  }
868
737
  }
869
- /**
870
- * Loads the schema for a plugin.
871
- *
872
- * This method attempts to load the schema file for the specified plugin. If the schema file is found,
873
- * it reads and parses the file, updates the schema's title and description, and logs the process.
874
- * If the schema file is not found, it logs the event and loads a default schema for the plugin.
875
- *
876
- * @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
877
- * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
878
- */
879
738
  async loadSchema(plugin) {
880
739
  const { promises } = await import('node:fs');
881
740
  const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
@@ -886,24 +745,13 @@ export class PluginManager {
886
745
  schema.title = plugin.description;
887
746
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
888
747
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
889
- // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
890
748
  return schema;
891
749
  }
892
- catch (error) {
893
- this.log.debug(`Schema file ${schemaFile} for plugin ${plg}${plugin.name}${db} not found. Loading default schema. Error: ${error instanceof Error ? error.message : error}`);
750
+ catch (err) {
751
+ this.log.debug(`Schema file ${schemaFile} for plugin ${plg}${plugin.name}${db} not found. Loading default schema. Error: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
894
752
  return this.getDefaultSchema(plugin);
895
753
  }
896
754
  }
897
- /**
898
- * Returns the default schema for a plugin.
899
- *
900
- * This method generates a default schema object for the specified plugin. The schema includes
901
- * metadata such as the plugin's title, description, version, and author. It also defines the
902
- * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
903
- *
904
- * @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
905
- * @returns {PlatformSchema} The default schema object for the plugin.
906
- */
907
755
  getDefaultSchema(plugin) {
908
756
  return {
909
757
  title: plugin.description,
@@ -934,4 +782,3 @@ export class PluginManager {
934
782
  };
935
783
  }
936
784
  }
937
- //# sourceMappingURL=pluginManager.js.map