matterbridge 2.0.0-edge1 → 2.1.0-dev.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 (82) hide show
  1. package/CHANGELOG.md +36 -3
  2. package/README.md +1 -1
  3. package/dist/cli.js +0 -26
  4. package/dist/cluster/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +0 -23
  6. package/dist/deviceManager.js +2 -27
  7. package/dist/frontend.js +99 -245
  8. package/dist/index.js +2 -33
  9. package/dist/logger/export.js +0 -1
  10. package/dist/matter/export.js +0 -7
  11. package/dist/matterbridge.js +99 -710
  12. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  13. package/dist/matterbridgeBehaviors.js +42 -32
  14. package/dist/matterbridgeDeviceTypes.js +90 -84
  15. package/dist/matterbridgeDynamicPlatform.js +0 -33
  16. package/dist/matterbridgeEndpoint.js +992 -2454
  17. package/dist/matterbridgePlatform.js +11 -130
  18. package/dist/matterbridgeTypes.js +0 -25
  19. package/dist/pluginManager.js +7 -251
  20. package/dist/storage/export.js +0 -1
  21. package/dist/utils/colorUtils.js +2 -205
  22. package/dist/utils/export.js +0 -1
  23. package/dist/utils/utils.js +10 -255
  24. package/frontend/build/asset-manifest.json +3 -3
  25. package/frontend/build/index.html +1 -1
  26. package/frontend/build/static/js/{main.ea28015b.js → main.26dbf9b9.js} +3 -3
  27. package/frontend/build/static/js/main.26dbf9b9.js.map +1 -0
  28. package/npm-shrinkwrap.json +97 -79
  29. package/package.json +2 -4
  30. package/dist/cli.d.ts.map +0 -1
  31. package/dist/cli.js.map +0 -1
  32. package/dist/cluster/export.d.ts.map +0 -1
  33. package/dist/cluster/export.js.map +0 -1
  34. package/dist/defaultConfigSchema.d.ts.map +0 -1
  35. package/dist/defaultConfigSchema.js.map +0 -1
  36. package/dist/deviceManager.d.ts +0 -46
  37. package/dist/deviceManager.d.ts.map +0 -1
  38. package/dist/deviceManager.js.map +0 -1
  39. package/dist/frontend.d.ts +0 -98
  40. package/dist/frontend.d.ts.map +0 -1
  41. package/dist/frontend.js.map +0 -1
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/logger/export.d.ts.map +0 -1
  45. package/dist/logger/export.js.map +0 -1
  46. package/dist/matter/export.d.ts.map +0 -1
  47. package/dist/matter/export.js.map +0 -1
  48. package/dist/matterbridge.d.ts +0 -357
  49. package/dist/matterbridge.d.ts.map +0 -1
  50. package/dist/matterbridge.js.map +0 -1
  51. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  52. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  53. package/dist/matterbridgeBehaviors.d.ts +0 -123
  54. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  55. package/dist/matterbridgeBehaviors.js.map +0 -1
  56. package/dist/matterbridgeDeviceTypes.d.ts +0 -109
  57. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  58. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  59. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  60. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  61. package/dist/matterbridgeEndpoint.d.ts +0 -1167
  62. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  63. package/dist/matterbridgeEndpoint.js.map +0 -1
  64. package/dist/matterbridgePlatform.d.ts +0 -154
  65. package/dist/matterbridgePlatform.d.ts.map +0 -1
  66. package/dist/matterbridgePlatform.js.map +0 -1
  67. package/dist/matterbridgeTypes.d.ts.map +0 -1
  68. package/dist/matterbridgeTypes.js.map +0 -1
  69. package/dist/pluginManager.d.ts +0 -238
  70. package/dist/pluginManager.d.ts.map +0 -1
  71. package/dist/pluginManager.js.map +0 -1
  72. package/dist/storage/export.d.ts.map +0 -1
  73. package/dist/storage/export.js.map +0 -1
  74. package/dist/utils/colorUtils.d.ts.map +0 -1
  75. package/dist/utils/colorUtils.js.map +0 -1
  76. package/dist/utils/export.d.ts.map +0 -1
  77. package/dist/utils/export.js.map +0 -1
  78. package/dist/utils/utils.d.ts +0 -221
  79. package/dist/utils/utils.d.ts.map +0 -1
  80. package/dist/utils/utils.js.map +0 -1
  81. package/frontend/build/static/js/main.ea28015b.js.map +0 -1
  82. /package/frontend/build/static/js/{main.ea28015b.js.LICENSE.txt → main.26dbf9b9.js.LICENSE.txt} +0 -0
@@ -1,29 +1,4 @@
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.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
- /* eslint-disable @typescript-eslint/no-unused-vars */
24
- // NodeStorage and AnsiLogger modules
25
- import { AnsiLogger, BLUE, db, er, LogLevel, nf, nt, rs, TimestampFormat, UNDERLINE, UNDERLINEOFF, wr } from 'node-ansi-logger';
26
- // Node.js modules
1
+ import { AnsiLogger, BLUE, db, er, nf, nt, rs, UNDERLINE, UNDERLINEOFF, wr } from './logger/export.js';
27
2
  import path from 'path';
28
3
  import { promises as fs } from 'fs';
29
4
  import { pathToFileURL } from 'url';
@@ -37,9 +12,8 @@ export class PluginManager {
37
12
  log;
38
13
  constructor(matterbridge) {
39
14
  this.matterbridge = matterbridge;
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
15
  this.nodeContext = matterbridge.nodeContext;
42
- this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: TimestampFormat.TIME_MILLIS, logLevel: matterbridge.log.logLevel });
16
+ this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
43
17
  this.log.debug('Matterbridge plugin manager starting...');
44
18
  }
45
19
  get length() {
@@ -74,7 +48,6 @@ export class PluginManager {
74
48
  }
75
49
  catch (error) {
76
50
  this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}:`, error);
77
- // throw error;
78
51
  }
79
52
  });
80
53
  await Promise.all(tasks);
@@ -85,31 +58,13 @@ export class PluginManager {
85
58
  set logLevel(logLevel) {
86
59
  this.log.logLevel = logLevel;
87
60
  }
88
- /**
89
- * Loads registered plugins from storage.
90
- *
91
- * This method retrieves an array of registered plugins from the storage and converts it
92
- * into a map where the plugin names are the keys and the plugin objects are the values.
93
- *
94
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
95
- */
96
61
  async loadFromStorage() {
97
- // Load the array from storage and convert it to a map
98
62
  const pluginsArray = await this.nodeContext.get('plugins', []);
99
63
  for (const plugin of pluginsArray)
100
64
  this._plugins.set(plugin.name, plugin);
101
65
  return pluginsArray;
102
66
  }
103
- /**
104
- * Loads registered plugins from storage.
105
- *
106
- * This method retrieves an array of registered plugins from the storage and converts it
107
- * into a map where the plugin names are the keys and the plugin objects are the values.
108
- *
109
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
110
- */
111
67
  async saveToStorage() {
112
- // Convert the map to an array
113
68
  const plugins = [];
114
69
  const pluginArrayFromMap = Array.from(this._plugins.values());
115
70
  for (const plugin of pluginArrayFromMap) {
@@ -129,18 +84,11 @@ export class PluginManager {
129
84
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
130
85
  return plugins.length;
131
86
  }
132
- /**
133
- * Resolves the name of a plugin by loading and parsing its package.json file.
134
- * @param pluginPath - The path to the plugin or the path to the plugin's package.json file.
135
- * @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.
136
- */
137
87
  async resolve(pluginPath) {
138
88
  if (!pluginPath.endsWith('package.json'))
139
89
  pluginPath = path.join(pluginPath, 'package.json');
140
- // Resolve the package.json of the plugin
141
90
  let packageJsonPath = path.resolve(pluginPath);
142
91
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
143
- // Check if the package.json file exists
144
92
  try {
145
93
  await fs.access(packageJsonPath);
146
94
  }
@@ -150,13 +98,11 @@ export class PluginManager {
150
98
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
151
99
  }
152
100
  try {
153
- // Load the package.json of the plugin
154
101
  const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
155
102
  if (!packageJson.name) {
156
103
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
157
104
  return null;
158
105
  }
159
- // Check for main issues
160
106
  if (!packageJson.type || packageJson.type !== 'module') {
161
107
  this.log.error(`Plugin at ${packageJsonPath} is not a module`);
162
108
  return null;
@@ -165,13 +111,6 @@ export class PluginManager {
165
111
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
166
112
  return null;
167
113
  }
168
- /*
169
- if (!packageJson.types) {
170
- this.log.error(`Plugin at ${packageJsonPath} has no types in package.json`);
171
- return null;
172
- }
173
- */
174
- // Check for @project-chip packages in dependencies and devDependencies
175
114
  const checkForProjectChipPackages = (dependencies) => {
176
115
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
177
116
  };
@@ -193,7 +132,6 @@ export class PluginManager {
193
132
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
194
133
  return null;
195
134
  }
196
- // Check for matterbridge package in dependencies and devDependencies
197
135
  const checkForMatterbridgePackage = (dependencies) => {
198
136
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
199
137
  };
@@ -223,11 +161,6 @@ export class PluginManager {
223
161
  return null;
224
162
  }
225
163
  }
226
- /**
227
- * Loads and parse the plugin package.json and returns it.
228
- * @param plugin - The plugin to load the package from.
229
- * @returns A Promise that resolves to the package.json object or undefined if the package.json could not be loaded.
230
- */
231
164
  async parse(plugin) {
232
165
  this.log.debug(`Parsing package.json of plugin ${plg}${plugin.name}${db}`);
233
166
  try {
@@ -244,7 +177,6 @@ export class PluginManager {
244
177
  this.log.error(`Plugin ${plg}${plugin.name}${er} is not a module`);
245
178
  if (!packageJson.main)
246
179
  this.log.error(`Plugin ${plg}${plugin.name}${er} has no main entrypoint in package.json`);
247
- // if (!packageJson.types) this.log.error(`Plugin ${plg}${plugin.name}${er} has no types in package.json`);
248
180
  plugin.name = packageJson.name || 'Unknown name';
249
181
  plugin.version = packageJson.version || '1.0.0';
250
182
  plugin.description = packageJson.description || 'Unknown description';
@@ -253,7 +185,6 @@ export class PluginManager {
253
185
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no path`);
254
186
  if (!plugin.type)
255
187
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
256
- // Check for @project-chip packages in dependencies and devDependencies
257
188
  const checkForProjectChipPackages = (dependencies) => {
258
189
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
259
190
  };
@@ -275,7 +206,6 @@ export class PluginManager {
275
206
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
276
207
  return null;
277
208
  }
278
- // Check for matterbridge package in dependencies and devDependencies
279
209
  const checkForMatterbridgePackage = (dependencies) => {
280
210
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
281
211
  };
@@ -297,7 +227,6 @@ export class PluginManager {
297
227
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
298
228
  return null;
299
229
  }
300
- // await this.saveToStorage(); // No need to save the plugin to storage
301
230
  return packageJson;
302
231
  }
303
232
  catch (err) {
@@ -306,16 +235,6 @@ export class PluginManager {
306
235
  return null;
307
236
  }
308
237
  }
309
- /**
310
- * Enables a plugin by its name or path.
311
- *
312
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
313
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
314
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
315
- *
316
- * @param {string} nameOrPath - The name or path of the plugin to enable.
317
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
318
- */
319
238
  async enable(nameOrPath) {
320
239
  if (!nameOrPath || nameOrPath === '')
321
240
  return null;
@@ -348,16 +267,6 @@ export class PluginManager {
348
267
  return null;
349
268
  }
350
269
  }
351
- /**
352
- * Enables a plugin by its name or path.
353
- *
354
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
355
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
356
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
357
- *
358
- * @param {string} nameOrPath - The name or path of the plugin to enable.
359
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
360
- */
361
270
  async disable(nameOrPath) {
362
271
  if (!nameOrPath || nameOrPath === '')
363
272
  return null;
@@ -390,16 +299,6 @@ export class PluginManager {
390
299
  return null;
391
300
  }
392
301
  }
393
- /**
394
- * Removes a plugin by its name or path.
395
- *
396
- * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
397
- * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
398
- * the plugin's `package.json` file to retrieve its name and remove it.
399
- *
400
- * @param {string} nameOrPath - The name or path of the plugin to remove.
401
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
402
- */
403
302
  async remove(nameOrPath) {
404
303
  if (!nameOrPath || nameOrPath === '')
405
304
  return null;
@@ -432,17 +331,6 @@ export class PluginManager {
432
331
  return null;
433
332
  }
434
333
  }
435
- /**
436
- * Adds a plugin by its name or path.
437
- *
438
- * This method adds a plugin to the `_plugins` map and saves the updated plugin information to storage.
439
- * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
440
- * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
441
- * and saves the updated plugin information to storage.
442
- *
443
- * @param {string} nameOrPath - The name or path of the plugin to add.
444
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
445
- */
446
334
  async add(nameOrPath) {
447
335
  if (!nameOrPath || nameOrPath === '')
448
336
  return null;
@@ -468,15 +356,6 @@ export class PluginManager {
468
356
  return null;
469
357
  }
470
358
  }
471
- /**
472
- * Installs a plugin by its name.
473
- *
474
- * This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
475
- * It logs the installation process and retrieves the installed version of the plugin.
476
- *
477
- * @param {string} name - The name of the plugin to install.
478
- * @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
479
- */
480
359
  async install(name) {
481
360
  await this.uninstall(name);
482
361
  this.log.info(`Installing plugin ${plg}${name}${nf}`);
@@ -490,13 +369,11 @@ export class PluginManager {
490
369
  else {
491
370
  this.log.info(`Installed plugin ${plg}${name}${nf}`);
492
371
  this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
493
- // Get the installed version
494
372
  exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
495
373
  if (listError) {
496
374
  this.log.error(`List error: ${listError}`);
497
375
  resolve(undefined);
498
376
  }
499
- // Clean the output to get only the package name and version
500
377
  const lines = listStdout.split('\n');
501
378
  const versionLine = lines.find((line) => line.includes(`${name}@`));
502
379
  if (versionLine) {
@@ -512,15 +389,6 @@ export class PluginManager {
512
389
  });
513
390
  });
514
391
  }
515
- /**
516
- * Uninstalls a plugin by its name.
517
- *
518
- * This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
519
- * and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
520
- *
521
- * @param {string} name - The name of the plugin to uninstall.
522
- * @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
523
- */
524
392
  async uninstall(name) {
525
393
  this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
526
394
  return new Promise((resolve, reject) => {
@@ -538,14 +406,6 @@ export class PluginManager {
538
406
  });
539
407
  });
540
408
  }
541
- /**
542
- * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
543
- * @param plugin - The plugin to load.
544
- * @param start - Optional flag indicating whether to start the plugin after loading. Default is false.
545
- * @param message - Optional message to pass to the plugin when starting.
546
- * @returns A Promise that resolves to the loaded MatterbridgePlatform instance.
547
- * @throws An error if the plugin is not enabled, already loaded, or fails to load.
548
- */
549
409
  async load(plugin, start = false, message = '', configure = false) {
550
410
  if (!plugin.enabled) {
551
411
  this.log.error(`Plugin ${plg}${plugin.name}${er} not enabled`);
@@ -557,19 +417,14 @@ export class PluginManager {
557
417
  }
558
418
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
559
419
  try {
560
- // Load the package.json of the plugin
561
420
  const packageJson = JSON.parse(await fs.readFile(plugin.path, 'utf8'));
562
- // Resolve the main module path relative to package.json
563
421
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
564
- // Dynamically import the plugin
565
422
  const pluginUrl = pathToFileURL(pluginEntry);
566
423
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
567
424
  const pluginInstance = await import(pluginUrl.href);
568
425
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
569
- // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
570
426
  if (pluginInstance.default) {
571
427
  const config = await this.loadConfig(plugin);
572
- // 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.
573
428
  plugin.name = packageJson.name;
574
429
  plugin.description = packageJson.description ?? 'No description';
575
430
  plugin.version = packageJson.version;
@@ -578,7 +433,7 @@ export class PluginManager {
578
433
  plugin.schemaJson = await this.loadSchema(plugin);
579
434
  config.name = plugin.name;
580
435
  config.version = packageJson.version;
581
- const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: TimestampFormat.TIME_MILLIS, logLevel: config.debug ? LogLevel.DEBUG : this.matterbridge.log.logLevel });
436
+ const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
582
437
  const platform = pluginInstance.default(this.matterbridge, log, config);
583
438
  config.type = platform.type;
584
439
  platform.name = packageJson.name;
@@ -595,7 +450,7 @@ export class PluginManager {
595
450
  plugin.addedDevices = 0;
596
451
  plugin.configJson = config;
597
452
  plugin.schemaJson = await this.loadSchema(plugin);
598
- await this.saveToStorage(); // Save the plugin to storage
453
+ await this.saveToStorage();
599
454
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nf} type ${typ}${platform.type}${db} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
600
455
  if (start)
601
456
  await this.start(plugin, message, false);
@@ -614,14 +469,6 @@ export class PluginManager {
614
469
  }
615
470
  return undefined;
616
471
  }
617
- /**
618
- * Starts a plugin.
619
- *
620
- * @param {RegisteredPlugin} plugin - The plugin to start.
621
- * @param {string} [message] - Optional message to pass to the plugin's onStart method.
622
- * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
623
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
624
- */
625
472
  async start(plugin, message, configure = false) {
626
473
  if (!plugin.loaded) {
627
474
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -651,12 +498,6 @@ export class PluginManager {
651
498
  }
652
499
  return undefined;
653
500
  }
654
- /**
655
- * Configures a plugin.
656
- *
657
- * @param {RegisteredPlugin} plugin - The plugin to configure.
658
- * @returns {Promise<void>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
659
- */
660
501
  async configure(plugin) {
661
502
  if (!plugin.loaded) {
662
503
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -679,7 +520,6 @@ export class PluginManager {
679
520
  await plugin.platform.onConfigure();
680
521
  this.log.notice(`Configured plugin ${plg}${plugin.name}${nt} type ${typ}${plugin.type}${nt}`);
681
522
  plugin.configured = true;
682
- // await this.saveConfigFromPlugin(plugin);
683
523
  return plugin;
684
524
  }
685
525
  catch (err) {
@@ -688,18 +528,6 @@ export class PluginManager {
688
528
  }
689
529
  return undefined;
690
530
  }
691
- /**
692
- * Shuts down a plugin.
693
- *
694
- * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
695
- * It logs the shutdown process and optionally removes all devices associated with the plugin.
696
- *
697
- * @param {RegisteredPlugin} plugin - The plugin to shut down.
698
- * @param {string} [reason] - The reason for shutting down the plugin.
699
- * @param {boolean} [removeAllDevices=false] - Whether to remove all devices associated with the plugin.
700
- * @param {boolean} [force=false] - Whether to force the shutdown even if the plugin is not loaded or started.
701
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
702
- */
703
531
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
704
532
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
705
533
  if (!plugin.loaded) {
@@ -727,7 +555,6 @@ export class PluginManager {
727
555
  plugin.loaded = undefined;
728
556
  plugin.started = undefined;
729
557
  plugin.configured = undefined;
730
- plugin.connected = undefined;
731
558
  plugin.platform = undefined;
732
559
  if (removeAllDevices) {
733
560
  this.log.info(`Removing all endpoints for plugin ${plg}${plugin.name}${nf}: ${reason}...`);
@@ -743,15 +570,6 @@ export class PluginManager {
743
570
  }
744
571
  return undefined;
745
572
  }
746
- /**
747
- * Loads the configuration for a plugin.
748
- * If the configuration file exists, it reads the file and returns the parsed JSON data.
749
- * If the configuration file does not exist, it creates a new file with default configuration and returns it.
750
- * If any error occurs during file access or creation, it logs an error and return un empty config.
751
- *
752
- * @param plugin - The plugin for which to load the configuration.
753
- * @returns A promise that resolves to the loaded or created configuration.
754
- */
755
573
  async loadConfig(plugin) {
756
574
  const configFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.config.json`);
757
575
  try {
@@ -759,8 +577,6 @@ export class PluginManager {
759
577
  const data = await fs.readFile(configFile, 'utf8');
760
578
  const config = JSON.parse(data);
761
579
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
762
- // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
763
- // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
764
580
  config.name = plugin.name;
765
581
  config.type = plugin.type;
766
582
  if (config.debug === undefined)
@@ -785,7 +601,6 @@ export class PluginManager {
785
601
  try {
786
602
  await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
787
603
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
788
- // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
789
604
  return config;
790
605
  }
791
606
  catch (err) {
@@ -802,18 +617,6 @@ export class PluginManager {
802
617
  return { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
803
618
  }
804
619
  }
805
- /**
806
- * Saves the configuration of a plugin to a file.
807
- *
808
- * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
809
- * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
810
- * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
811
- * the error and rejects the promise.
812
- *
813
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
814
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
815
- * @throws {Error} If the plugin's configuration is not found.
816
- */
817
620
  async saveConfigFromPlugin(plugin) {
818
621
  if (!plugin.platform?.config) {
819
622
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}: config not found`);
@@ -823,7 +626,6 @@ export class PluginManager {
823
626
  try {
824
627
  await fs.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
825
628
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
826
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
827
629
  return Promise.resolve();
828
630
  }
829
631
  catch (err) {
@@ -831,19 +633,6 @@ export class PluginManager {
831
633
  return Promise.reject(err);
832
634
  }
833
635
  }
834
- /**
835
- * Saves the configuration of a plugin from a JSON object to a file.
836
- *
837
- * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
838
- * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
839
- * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
840
- * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
841
- * during the file write operation, it logs the error and returns.
842
- *
843
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
844
- * @param {PlatformConfig} config - The configuration data to be saved.
845
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
846
- */
847
636
  async saveConfigFromJson(plugin, config) {
848
637
  if (!config.name || !config.type || config.name !== plugin.name) {
849
638
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}. Wrong config data content:${rs}\n`, config);
@@ -854,26 +643,14 @@ export class PluginManager {
854
643
  await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
855
644
  plugin.configJson = config;
856
645
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
857
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
858
646
  }
859
647
  catch (err) {
860
648
  this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err}`);
861
649
  return;
862
650
  }
863
651
  }
864
- /**
865
- * Loads the schema for a plugin.
866
- *
867
- * This method attempts to load the schema file for the specified plugin. If the schema file is found,
868
- * it reads and parses the file, updates the schema's title and description, and logs the process.
869
- * It also attempts to delete any old schema file from the matterbridge directory. If the schema file
870
- * is not found, it logs the event and loads a default schema for the plugin.
871
- *
872
- * @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
873
- * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
874
- */
875
652
  async loadSchema(plugin) {
876
- let schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
653
+ const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
877
654
  try {
878
655
  await fs.access(schemaFile);
879
656
  const data = await fs.readFile(schemaFile, 'utf8');
@@ -881,33 +658,13 @@ export class PluginManager {
881
658
  schema.title = plugin.description;
882
659
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
883
660
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
884
- // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
885
- // Delete the schema file from old position
886
- schemaFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.schema.json`);
887
- try {
888
- await fs.unlink(schemaFile);
889
- this.log.debug(`Schema file ${schemaFile} deleted.`);
890
- }
891
- catch (err) {
892
- this.log.debug(`Schema file ${schemaFile} to delete not found.`);
893
- }
894
661
  return schema;
895
662
  }
896
- catch (err) {
897
- this.log.debug(`Schema file ${schemaFile} for plugin ${plg}${plugin.name}${db} not found. Loading default schema.`);
663
+ catch (error) {
664
+ this.log.debug(`Schema file ${schemaFile} for plugin ${plg}${plugin.name}${db} not found. Loading default schema. Error: ${error instanceof Error ? error.message : error}`);
898
665
  return this.getDefaultSchema(plugin);
899
666
  }
900
667
  }
901
- /**
902
- * Returns the default schema for a plugin.
903
- *
904
- * This method generates a default schema object for the specified plugin. The schema includes
905
- * metadata such as the plugin's title, description, version, and author. It also defines the
906
- * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
907
- *
908
- * @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
909
- * @returns {PlatformSchema} The default schema object for the plugin.
910
- */
911
668
  getDefaultSchema(plugin) {
912
669
  return {
913
670
  title: plugin.description,
@@ -938,4 +695,3 @@ export class PluginManager {
938
695
  };
939
696
  }
940
697
  }
941
- //# sourceMappingURL=pluginManager.js.map
@@ -1,2 +1 @@
1
1
  export * from 'node-persist-manager';
2
- //# sourceMappingURL=export.js.map