smart-home-engine 0.0.1 → 0.11.0

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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -0
  3. package/dist/web/assets/codicon-DCmgc-ay.ttf +0 -0
  4. package/dist/web/assets/index-BbwiXmS-.css +1 -0
  5. package/dist/web/assets/index-DD-XScWV.js +140 -0
  6. package/dist/web/assets/monaco-langs-DZ6hB11b.js +1423 -0
  7. package/dist/web/assets/monaco-langs-DyX1CsEw.css +1 -0
  8. package/dist/web/assets/tsMode-DxTbjAE2.js +16 -0
  9. package/dist/web/index.html +164 -0
  10. package/dist/web/monacoeditorwork/editor.worker.bundle.js +13519 -0
  11. package/dist/web/monacoeditorwork/ts.worker.bundle.js +256353 -0
  12. package/package.json +85 -10
  13. package/src/config.js +56 -0
  14. package/src/elastic.js +19 -0
  15. package/src/index.js +1192 -0
  16. package/src/influx.js +25 -0
  17. package/src/lib/mqtt-wildcards.js +34 -0
  18. package/src/lib/parse-payload.js +29 -0
  19. package/src/lib/redis.js +74 -0
  20. package/src/lib/shedb-core.js +447 -0
  21. package/src/lib/shedb-worker.js +126 -0
  22. package/src/lib/state-store.js +97 -0
  23. package/src/lib/storage.js +74 -0
  24. package/src/matter/controller.js +307 -0
  25. package/src/sandbox/api.js +57 -0
  26. package/src/sandbox/elastic-sandbox.js +88 -0
  27. package/src/sandbox/influx-sandbox.js +107 -0
  28. package/src/sandbox/matter-sandbox.js +92 -0
  29. package/src/sandbox/shedb-sandbox.js +89 -0
  30. package/src/sandbox/stdlib.js +132 -0
  31. package/src/scripts/hello.js +3 -0
  32. package/src/web/ai-api.js +443 -0
  33. package/src/web/auth.js +186 -0
  34. package/src/web/config-api.js +34 -0
  35. package/src/web/deps-api.js +138 -0
  36. package/src/web/git-api.js +188 -0
  37. package/src/web/log-ws.js +78 -0
  38. package/src/web/matter-api.js +102 -0
  39. package/src/web/mqtt-api.js +65 -0
  40. package/src/web/scripts-api.js +192 -0
  41. package/src/web/server.js +139 -0
  42. package/src/web/shedb-api.js +140 -0
  43. package/src/web/shedb.js +168 -0
  44. package/index.js +0 -0
package/package.json CHANGED
@@ -1,12 +1,87 @@
1
1
  {
2
- "name": "smart-home-engine",
3
- "version": "0.0.1",
4
- "description": "",
5
- "license": "ISC",
6
- "author": "",
7
- "type": "commonjs",
8
- "main": "index.js",
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- }
2
+ "name": "smart-home-engine",
3
+ "version": "0.11.0",
4
+ "description": "Node.js based script runner for use in MQTT based Smart Home environments",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "cross-env NODE_OPTIONS=\"--no-warnings\" jest --testPathPattern=test/unit --forceExit",
8
+ "test:integration": "cross-env NODE_OPTIONS=\"--no-warnings\" jest --testPathPattern=test/integration --forceExit",
9
+ "test:all": "cross-env NODE_OPTIONS=\"--no-warnings\" jest --forceExit",
10
+ "test:coverage": "cross-env NODE_OPTIONS=\"--no-warnings\" jest --coverage --forceExit",
11
+ "test:verbose": "cross-env NODE_OPTIONS=\"--no-warnings\" jest --verbose --forceExit",
12
+ "lint": "eslint --cache --cache-location .cache/.eslintcache .",
13
+ "lint:fix": "eslint --cache --cache-location .cache/.eslintcache --fix .",
14
+ "format": "prettier --cache --cache-location .cache/.prettiercache --write .",
15
+ "format:check": "prettier --cache --cache-location .cache/.prettiercache --check .",
16
+ "build:web": "cd web \u0026\u0026 npm install \u0026\u0026 npm run build"
17
+ },
18
+ "bin": {
19
+ "she": "src/index.js"
20
+ },
21
+ "files": [
22
+ "src/",
23
+ "sandbox/",
24
+ "dist/web/"
25
+ ],
26
+ "author": "Sebastian \u0027hobbyquaker\u0027 Raff \u003chobbyquaker@gmail.com\u003e",
27
+ "license": "MIT",
28
+ "dependencies": {
29
+ "bcryptjs": "^2.4.3",
30
+ "@elastic/elasticsearch": "^9.4.2",
31
+ "@influxdata/influxdb-client": "^1.35.0",
32
+ "@matter/main": "^0.17.0",
33
+ "chokidar": "^4.0.0",
34
+ "express": "^5.2.1",
35
+ "ioredis": "^5.11.0",
36
+ "mqtt": "^5.0.0",
37
+ "node-schedule": "^2.0.0",
38
+ "pino": "^9.0.0",
39
+ "pino-pretty": "^13.0.0",
40
+ "suncalc": "^1.9.0",
41
+ "ws": "^8.21.0",
42
+ "yargs": "^17.0.0"
43
+ },
44
+ "engines": {
45
+ "node": "\u003e=20.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@eslint/js": "^9.0.0",
49
+ "@sinonjs/fake-timers": "^11.0.0",
50
+ "@types/jest": "^29.5.0",
51
+ "@types/node": "^22.0.0",
52
+ "aedes": "^0.50.0",
53
+ "cross-env": "^7.0.3",
54
+ "eslint": "^9.0.0",
55
+ "eslint-config-prettier": "^10.1.8",
56
+ "eslint-plugin-n": "^17.0.0",
57
+ "eslint-plugin-prettier": "^5.0.0",
58
+ "globals": "^16.0.0",
59
+ "jest": "^29.7.0",
60
+ "prettier": "^3.0.0"
61
+ },
62
+ "directories": {
63
+ "doc": "doc"
64
+ },
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "https://github.com/hobbyquaker/she"
68
+ },
69
+ "keywords": [
70
+ "MQTT",
71
+ "javascript",
72
+ "node.js",
73
+ "npm",
74
+ "sandbox",
75
+ "vm",
76
+ "Smart",
77
+ "Home",
78
+ "Internet",
79
+ "of",
80
+ "Things",
81
+ "IoT"
82
+ ],
83
+ "bugs": {
84
+ "url": "https://github.com/hobbyquaker/she/issues"
85
+ },
86
+ "homepage": "https://github.com/hobbyquaker/she"
12
87
  }
package/src/config.js ADDED
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+
7
+ // Default config file location (can be overridden with --config on the CLI)
8
+ const configPath = path.join(os.homedir(), '.she', 'config', 'config.json');
9
+
10
+ const config = require('yargs')
11
+ .option('dir', {
12
+ alias: 'd',
13
+ describe: 'directory to load user scripts from',
14
+ default: path.join(os.homedir(), '.she', 'scripts'),
15
+ type: 'string',
16
+ })
17
+ .option('db-path', {
18
+ describe: 'path to sheDB data directory (empty string to disable)',
19
+ default: path.join(os.homedir(), '.she', 'db'),
20
+ type: 'string',
21
+ })
22
+ .option('port', {
23
+ alias: 'p',
24
+ describe: 'HTTP server port (0 = OS-assigned random port)',
25
+ type: 'number',
26
+ default: 8080,
27
+ })
28
+ .config('config', 'path to JSON config file', (cfgPath) => {
29
+ try {
30
+ return JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
31
+ } catch {
32
+ return {};
33
+ }
34
+ })
35
+ .default('config', configPath)
36
+ .hide('config')
37
+ // Sensible defaults for values not present in config.json
38
+ .default({
39
+ latitude: 48.7408,
40
+ longitude: 9.1778,
41
+ name: 'logic',
42
+ variablePrefix: 'var',
43
+ verbosity: 'info',
44
+ disableVariables: false,
45
+ disableWatch: false,
46
+ dbRetain: false,
47
+ dbPrefix: 'she/db/',
48
+ auth: 'none',
49
+ proxyHeader: 'X-Remote-User',
50
+ bindAddress: '0.0.0.0',
51
+ })
52
+ .version()
53
+ .help('help')
54
+ .parseSync();
55
+
56
+ module.exports = config;
package/src/elastic.js ADDED
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ let _client = null;
4
+
5
+ /**
6
+ * Initialise the Elasticsearch client. Called from index.js when config.elastic is set.
7
+ * @param {{ node: string, auth?: object }} opts
8
+ */
9
+ function init(opts) {
10
+ if (!opts || !opts.node) return;
11
+ const { Client } = require('@elastic/elasticsearch');
12
+ _client = new Client({ node: opts.node, ...(opts.auth ? { auth: opts.auth } : {}) });
13
+ }
14
+
15
+ function getClient() {
16
+ return _client;
17
+ }
18
+
19
+ module.exports = { init, getClient };