smart-home-engine 1.5.0 → 1.5.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.
@@ -1,4 +1,4 @@
1
- import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-76-mgKLK.js";/*!-----------------------------------------------------------------------------
1
+ import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-COVhu4fS.js";/*!-----------------------------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
4
4
  * Released under the MIT license
@@ -172,7 +172,7 @@
172
172
  }
173
173
  })();
174
174
  </script>
175
- <script type="module" crossorigin src="/assets/index-76-mgKLK.js"></script>
175
+ <script type="module" crossorigin src="/assets/index-COVhu4fS.js"></script>
176
176
  <link rel="modulepreload" crossorigin href="/assets/monaco-langs-BW2J83t5.js">
177
177
  <link rel="stylesheet" crossorigin href="/assets/monaco-langs-DyX1CsEw.css">
178
178
  <link rel="stylesheet" crossorigin href="/assets/index-CiYcuYTG.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-home-engine",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Node.js based script runner for use in MQTT based Smart Home environments",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -577,6 +577,51 @@ router.post('/ca/import', async (req, res) => {
577
577
  }
578
578
  });
579
579
 
580
+ /**
581
+ * GET /she/broker/fs/complete?path=<prefix>
582
+ * Returns filesystem path completions for a partial absolute path.
583
+ * Works locally or via SSH when broker.ssh is configured.
584
+ */
585
+ router.get('/fs/complete', async (req, res) => {
586
+ try {
587
+ const bc = getBrokerConfig(req);
588
+ const inputPath = String(req.query.path || '').trim();
589
+ if (!inputPath.startsWith('/')) return res.json({ suggestions: [] });
590
+
591
+ const endsWithSlash = inputPath.endsWith('/');
592
+ const posix = require('path').posix;
593
+ const dir = endsWithSlash ? inputPath : posix.dirname(inputPath);
594
+ const prefix = endsWithSlash ? '' : posix.basename(inputPath);
595
+
596
+ let entries = [];
597
+ if (bc.ssh && bc.ssh.host) {
598
+ try {
599
+ const { stdout } = await sshDeploy.runCommand(bc.ssh, `ls -1p -- "${dir}" 2>/dev/null`);
600
+ entries = stdout.split('\n').filter(Boolean);
601
+ } catch {
602
+ entries = [];
603
+ }
604
+ } else {
605
+ try {
606
+ const items = fs.readdirSync(dir, { withFileTypes: true });
607
+ entries = items.map((d) => d.name + (d.isDirectory() ? '/' : ''));
608
+ } catch {
609
+ entries = [];
610
+ }
611
+ }
612
+
613
+ const base = dir.endsWith('/') ? dir : dir + '/';
614
+ const suggestions = entries
615
+ .filter((e) => e.startsWith(prefix))
616
+ .map((e) => base + e)
617
+ .slice(0, 25);
618
+
619
+ res.json({ suggestions });
620
+ } catch {
621
+ res.json({ suggestions: [] });
622
+ }
623
+ });
624
+
580
625
  /** GET /she/broker/ca/server — Server cert info */
581
626
  router.get('/ca/server', async (req, res) => {
582
627
  try {
@@ -649,6 +694,35 @@ router.post('/ca/server/import', async (req, res) => {
649
694
  }
650
695
  });
651
696
 
697
+ /**
698
+ * POST /she/broker/ca/server/pathlink
699
+ * Install a server cert+key from existing file paths on the broker host.
700
+ * Reads via SSH if broker.ssh is configured, otherwise reads local files.
701
+ * Body: { certPath: string, keyPath: string }
702
+ */
703
+ router.post('/ca/server/pathlink', async (req, res) => {
704
+ try {
705
+ const bc = getBrokerConfig(req);
706
+ const { certPath, keyPath } = req.body;
707
+ if (!certPath || !keyPath) return res.status(400).json({ error: 'certPath and keyPath are required' });
708
+ if (!certPath.startsWith('/') || !keyPath.startsWith('/')) return res.status(400).json({ error: 'Absolute paths required' });
709
+
710
+ let certPem, keyPem;
711
+ if (bc.ssh && bc.ssh.host) {
712
+ certPem = await sshDeploy.readRemoteFile(bc.ssh, certPath);
713
+ keyPem = await sshDeploy.readRemoteFile(bc.ssh, keyPath);
714
+ } else {
715
+ certPem = fs.readFileSync(certPath, 'utf8');
716
+ keyPem = fs.readFileSync(keyPath, 'utf8');
717
+ }
718
+
719
+ const result = await ca.importServerCert(bc, { certPem, keyPem });
720
+ res.json({ ok: true, server: result });
721
+ } catch (err) {
722
+ handleError(res, err);
723
+ }
724
+ });
725
+
652
726
  /** GET /she/broker/ca/certs — List issued client certs (from sheDB) */
653
727
  router.get('/ca/certs', async (req, res) => {
654
728
  try {
@@ -826,6 +900,33 @@ router.delete('/ca/trusted/:fingerprint', async (req, res) => {
826
900
  }
827
901
  });
828
902
 
903
+ /**
904
+ * POST /she/broker/ca/trusted/addpath
905
+ * Add a trusted CA cert from an existing file path on the broker host.
906
+ * Reads via SSH if broker.ssh is configured, otherwise reads local file.
907
+ * Body: { path: string }
908
+ */
909
+ router.post('/ca/trusted/addpath', async (req, res) => {
910
+ try {
911
+ const bc = getBrokerConfig(req);
912
+ const { path: filePath } = req.body;
913
+ if (!filePath || typeof filePath !== 'string') return res.status(400).json({ error: 'path required' });
914
+ if (!filePath.startsWith('/')) return res.status(400).json({ error: 'Absolute path required' });
915
+
916
+ let pemContent;
917
+ if (bc.ssh && bc.ssh.host) {
918
+ pemContent = await sshDeploy.readRemoteFile(bc.ssh, filePath);
919
+ } else {
920
+ pemContent = fs.readFileSync(filePath, 'utf8');
921
+ }
922
+
923
+ const result = await ca.addTrustedCert(bc, pemContent);
924
+ res.json({ ok: true, ...result });
925
+ } catch (err) {
926
+ handleError(res, err);
927
+ }
928
+ });
929
+
829
930
  module.exports = { router, setLogger, setStore };
830
931
 
831
932
  // ── SSH routes ─────────────────────────────────────────────────────────────────