@matterbridge/core 3.11.2-dev-20261105-a15bb91 → 3.11.2-dev-20261106-a0aeea4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/backend.js CHANGED
@@ -329,14 +329,14 @@ export class Backend extends EventEmitter {
329
329
  }
330
330
  async getApiSettings() {
331
331
  const start = performance.now();
332
- const response = await this.server.fetch({ type: 'matterbridge_apisettings', src: 'frontend', dst: 'matterbridge', params: {} });
332
+ const response = await this.server.fetch({ type: 'matterbridge_apisettings', src: this.server.name, dst: 'matterbridge', params: {} });
333
333
  if (this.diagnostic)
334
334
  writeDiagnostic('Backend', `getApiSettings() took ${(performance.now() - start).toFixed(2)} ms`);
335
335
  return response.result.data;
336
336
  }
337
337
  async getApiPlugins() {
338
338
  const start = performance.now();
339
- const response = await this.server.fetch({ type: 'plugins_apipluginarray', src: 'frontend', dst: 'plugins', params: undefined });
339
+ const response = await this.server.fetch({ type: 'plugins_apipluginarray', src: this.server.name, dst: 'plugins', params: undefined });
340
340
  if (this.diagnostic)
341
341
  writeDiagnostic('Backend', `getApiPlugins() took ${(performance.now() - start).toFixed(2)} ms`);
342
342
  return response.result.plugins;
@@ -256,12 +256,40 @@ export class BackendWsServer {
256
256
  this.wssSendRefreshRequired('matter', { matter });
257
257
  }
258
258
  else if (data.method === '/api/unregister-device') {
259
+ if (!isValidString(data.params.pluginName, 1)) {
260
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter pluginName in /api/unregister-device' });
261
+ return;
262
+ }
263
+ if (!isValidString(data.params.serialNumber, 1)) {
264
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter serialNumber in /api/unregister-device' });
265
+ return;
266
+ }
267
+ if (!isValidString(data.params.uniqueId, 1)) {
268
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter uniqueId in /api/unregister-device' });
269
+ return;
270
+ }
259
271
  this.wssSendSnackbarMessage('Resetting the device...');
260
272
  const { pluginName, serialNumber, uniqueId } = data.params;
261
273
  this.server.request({ type: 'platform_unregister_device', src: 'frontend', dst: 'platform', params: { pluginName, serialNumber, uniqueId } });
262
274
  sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
263
275
  }
264
276
  else if (data.method === '/api/rename-device') {
277
+ if (!isValidString(data.params.pluginName, 1)) {
278
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter pluginName in /api/rename-device' });
279
+ return;
280
+ }
281
+ if (!isValidString(data.params.serialNumber, 1)) {
282
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter serialNumber in /api/rename-device' });
283
+ return;
284
+ }
285
+ if (!isValidString(data.params.uniqueId, 1)) {
286
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter uniqueId in /api/rename-device' });
287
+ return;
288
+ }
289
+ if (!isValidString(data.params.label, 1)) {
290
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter label in /api/rename-device' });
291
+ return;
292
+ }
265
293
  this.wssSendSnackbarMessage('Renaming the device...');
266
294
  const { pluginName, serialNumber, uniqueId, label } = data.params;
267
295
  this.server.request({ type: 'platform_rename_device', src: 'frontend', dst: 'platform', params: { pluginName, serialNumber, uniqueId, label } });
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
- import type { ApiClusters, ApiDevice, ApiMatter, ApiPlugin, BridgeStatus, PluginStatusUpdate, RefreshRequiredChanged, WsMessageBroadcast } from '@matterbridge/types';
2
+ import type { ApiClusters, ApiDevice, ApiMatter, BridgeStatus, PluginStatusUpdate, RefreshRequiredChanged, WsMessageBroadcast } from '@matterbridge/types';
3
3
  import { LogLevel } from 'node-ansi-logger';
4
4
  import type { Matterbridge } from './matterbridge.js';
5
5
  interface FrontendEvents {
@@ -34,7 +34,6 @@ export declare class Frontend extends EventEmitter<FrontendEvents> {
34
34
  private validateReq;
35
35
  start(port?: number): Promise<void>;
36
36
  stop(): Promise<void>;
37
- getApiPlugins(): ApiPlugin[];
38
37
  getApiDevices(pluginName?: string, extended?: boolean): ApiDevice[];
39
38
  getApiCluster(pluginName: string, endpointNumber: number, serialNumber: string, uniqueId: string): ApiClusters | undefined;
40
39
  generateDiagnostic(): Promise<void>;
package/dist/frontend.js CHANGED
@@ -529,11 +529,17 @@ export class Frontend extends EventEmitter {
529
529
  res.status(500).send('Error fetching the settings.');
530
530
  }
531
531
  });
532
- this.expressApp.get('/api/plugins', (req, res) => {
532
+ this.expressApp.get('/api/plugins', async (req, res) => {
533
533
  this.log.debug('The frontend sent /api/plugins');
534
534
  if (!this.validateReq(req, res))
535
535
  return;
536
- res.json(this.getApiPlugins());
536
+ try {
537
+ res.json((await this.server.fetch({ type: 'plugins_apipluginarray', src: this.server.name, dst: 'plugins', params: undefined }, this.serverFetchTimeout)).result.plugins);
538
+ }
539
+ catch (error) {
540
+ logError(this.log, 'Error in /api/plugins fetching the plugins from the plugin manager', error);
541
+ res.status(500).send('Error fetching the plugins.');
542
+ }
537
543
  });
538
544
  this.expressApp.get('/api/devices', (req, res) => {
539
545
  this.log.debug('The frontend sent /api/devices');
@@ -826,6 +832,8 @@ export class Frontend extends EventEmitter {
826
832
  this.log.debug(`Registering frontend route for plugin ${plg}${plugin.name}${db} at ${GREEN}/plugins/${plugin.name}${db} with path ${CYAN}${plugin.frontendPath}${db}`);
827
833
  this.expressApp.use(`/plugins/${plugin.name}`, express.static(path.dirname(plugin.frontendPath)));
828
834
  const apiHandler = async (req, res) => {
835
+ if (!this.validateReq(req, res))
836
+ return;
829
837
  const method = req.method.toUpperCase();
830
838
  const path = Array.isArray(req.params.path) ? req.params.path[0] : req.params.path;
831
839
  const query = req.query;
@@ -924,45 +932,6 @@ export class Frontend extends EventEmitter {
924
932
  }
925
933
  this.log.debug('Frontend stopped successfully');
926
934
  }
927
- getApiPlugins() {
928
- if (this.matterbridge.hasCleanupStarted)
929
- return [];
930
- const plugins = [];
931
- for (const plugin of this.matterbridge.plugins.array()) {
932
- plugins.push({
933
- path: plugin.path,
934
- type: plugin.type,
935
- name: plugin.name,
936
- version: plugin.version,
937
- private: plugin.private,
938
- configurationVersion: plugin.configurationVersion,
939
- description: plugin.description,
940
- author: plugin.author,
941
- homepage: plugin.homepage,
942
- help: plugin.help,
943
- changelog: plugin.changelog,
944
- funding: plugin.funding,
945
- latestVersion: plugin.latestVersion,
946
- devVersion: plugin.devVersion,
947
- locked: plugin.locked,
948
- error: plugin.error,
949
- enabled: plugin.enabled,
950
- loaded: plugin.loaded,
951
- started: plugin.started,
952
- configured: plugin.configured,
953
- local: plugin.local,
954
- restartRequired: plugin.restartRequired,
955
- registeredDevices: plugin.registeredDevices,
956
- configJson: plugin.configJson,
957
- schemaJson: plugin.schemaJson,
958
- hasWhiteList: plugin.configJson?.whiteList !== undefined,
959
- hasBlackList: plugin.configJson?.blackList !== undefined,
960
- frontendPath: plugin.frontendPath,
961
- matter: plugin.serverNode ? getServerNodeData(plugin.serverNode) : undefined,
962
- });
963
- }
964
- return plugins;
965
- }
966
935
  getApiDevices(pluginName, extended = false) {
967
936
  if (this.matterbridge.hasCleanupStarted)
968
937
  return [];
@@ -1404,14 +1373,15 @@ export class Frontend extends EventEmitter {
1404
1373
  const start = performance.now();
1405
1374
  const settings = (await this.server.fetch({ type: 'matterbridge_apisettings', src: this.server.name, dst: 'matterbridge', params: {} }, this.serverFetchTimeout)).result.data;
1406
1375
  if (this.diagnostic)
1407
- writeDiagnostic(`Frontend:${data.sender}`, `getApiSettings() took ${(performance.now() - start).toFixed(2)} ms`);
1376
+ writeDiagnostic(`Frontend:${data.sender}`, `/api/settings took ${(performance.now() - start).toFixed(2)} ms`);
1408
1377
  sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true, response: settings });
1409
1378
  }
1410
1379
  else if (data.method === '/api/plugins') {
1411
1380
  const start = performance.now();
1412
- const plugins = this.getApiPlugins();
1381
+ const plugins = (await this.server.fetch({ type: 'plugins_apipluginarray', src: this.server.name, dst: 'plugins', params: undefined }, this.serverFetchTimeout)).result
1382
+ .plugins;
1413
1383
  if (this.diagnostic)
1414
- writeDiagnostic(`Frontend:${data.sender}`, `getApiPlugins() took ${(performance.now() - start).toFixed(2)} ms`);
1384
+ writeDiagnostic(`Frontend:${data.sender}`, `/api/plugins took ${(performance.now() - start).toFixed(2)} ms`);
1415
1385
  sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true, response: plugins });
1416
1386
  }
1417
1387
  else if (data.method === '/api/devices') {
@@ -397,8 +397,9 @@ export class PluginManager extends EventEmitter {
397
397
  registeredDevices: plugin.registeredDevices,
398
398
  configJson: plugin.configJson,
399
399
  schemaJson: plugin.schemaJson,
400
- hasWhiteList: plugin.hasWhiteList,
401
- hasBlackList: plugin.hasBlackList,
400
+ frontendPath: plugin.frontendPath,
401
+ hasWhiteList: plugin.configJson?.whiteList !== undefined,
402
+ hasBlackList: plugin.configJson?.blackList !== undefined,
402
403
  matter: plugin.serverNode ? getServerNodeData(plugin.serverNode) : undefined,
403
404
  };
404
405
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matterbridge/core",
3
- "version": "3.11.2-dev-20261105-a15bb91",
3
+ "version": "3.11.2-dev-20261106-a0aeea4",
4
4
  "description": "Matterbridge core library",
5
5
  "author": "https://github.com/Luligu",
6
6
  "homepage": "https://matterbridge.io/",
@@ -136,10 +136,10 @@
136
136
  },
137
137
  "dependencies": {
138
138
  "@matter/main": "0.18.0",
139
- "@matterbridge/dgram": "3.11.2-dev-20261105-a15bb91",
140
- "@matterbridge/thread": "3.11.2-dev-20261105-a15bb91",
141
- "@matterbridge/types": "3.11.2-dev-20261105-a15bb91",
142
- "@matterbridge/utils": "3.11.2-dev-20261105-a15bb91",
139
+ "@matterbridge/dgram": "3.11.2-dev-20261106-a0aeea4",
140
+ "@matterbridge/thread": "3.11.2-dev-20261106-a0aeea4",
141
+ "@matterbridge/types": "3.11.2-dev-20261106-a0aeea4",
142
+ "@matterbridge/utils": "3.11.2-dev-20261106-a0aeea4",
143
143
  "escape-html": "1.0.3",
144
144
  "express": "5.3.0",
145
145
  "express-rate-limit": "8.7.2",