diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index b90c5a48..99eb3e58 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1921,16 +1921,21 @@ } }, "node_modules/@babel/runtime": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.7.tgz", - "integrity": "sha512-UF0tvkUtxwAgZ5W/KrkHf0Rn0fdnLDU9ScxBrEVNUprE/MzirjK4MJUX1/BVDv00Sv8cljtukVK1aky++X1SjQ==", + "version": "7.25.6", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.6.tgz", + "integrity": "sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==", "dependencies": { - "regenerator-runtime": "^0.13.11" + "regenerator-runtime": "^0.14.0" }, "engines": { "node": ">=6.9.0" } }, + "node_modules/@babel/runtime/node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" + }, "node_modules/@babel/template": { "version": "7.20.7", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", @@ -3639,6 +3644,20 @@ "@types/react": "*" } }, + "node_modules/@types/readable-stream": { + "version": "4.0.15", + "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.15.tgz", + "integrity": "sha512-oAZ3kw+kJFkEqyh7xORZOku1YAKvsFTogRY8kVl4vHpEKiDkfnSA/My8haRE7fvmix5Zyy+1pwzOi7yycGLBJw==", + "dependencies": { + "@types/node": "*", + "safe-buffer": "~5.1.1" + } + }, + "node_modules/@types/readable-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, "node_modules/@types/request": { "version": "2.48.12", "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.12.tgz", @@ -3708,6 +3727,14 @@ "@types/webidl-conversions": "*" } }, + "node_modules/@types/ws": { + "version": "8.5.12", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", + "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/a-sync-waterfall": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz", @@ -4803,6 +4830,11 @@ "node": ">= 6" } }, + "node_modules/commist": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/commist/-/commist-3.2.0.tgz", + "integrity": "sha512-4PIMoPniho+LqXmpS5d3NuGYncG6XWlkBSVGiWycL22dd42OYdUGil2CWuzklaJoNxyxUSpO4MKIBU94viWNAw==" + }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -5695,6 +5727,18 @@ "resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.6.tgz", "integrity": "sha512-VhXlQgj9ioXCqGstD37E/HBeqEGV/qOD/kmbVG8h5xKBYvM1L3lR1Zn4555cQ8GkYbJa8aJSipLPndE1k6zK2w==" }, + "node_modules/fast-unique-numbers": { + "version": "8.0.13", + "resolved": "https://registry.npmjs.org/fast-unique-numbers/-/fast-unique-numbers-8.0.13.tgz", + "integrity": "sha512-7OnTFAVPefgw2eBJ1xj2PGGR9FwYzSUso9decayHgCDX4sJkHLdcsYTytTg+tYv+wKF3U8gJuSBz2jJpQV4u/g==", + "dependencies": { + "@babel/runtime": "^7.23.8", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.1.0" + } + }, "node_modules/fast-uri": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-2.2.0.tgz", @@ -7469,6 +7513,11 @@ "node": ">=0.10.40" } }, + "node_modules/help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==" + }, "node_modules/hexoid": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", @@ -7936,6 +7985,15 @@ "url": "https://github.com/sponsors/panva" } }, + "node_modules/js-sdsl": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", + "integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -8593,9 +8651,9 @@ } }, "node_modules/minimist": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", - "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -8847,6 +8905,139 @@ "node": ">=4.0.0" } }, + "node_modules/mqtt": { + "version": "5.10.1", + "resolved": "https://registry.npmjs.org/mqtt/-/mqtt-5.10.1.tgz", + "integrity": "sha512-hXCOki8sANoQ7w+2OzJzg6qMBxTtrH9RlnVNV8panLZgnl+Gh0J/t4k6r8Az8+C7y3KAcyXtn0mmLixyUom8Sw==", + "dependencies": { + "@types/readable-stream": "^4.0.5", + "@types/ws": "^8.5.9", + "commist": "^3.2.0", + "concat-stream": "^2.0.0", + "debug": "^4.3.4", + "help-me": "^5.0.0", + "lru-cache": "^10.0.1", + "minimist": "^1.2.8", + "mqtt-packet": "^9.0.0", + "number-allocator": "^1.0.14", + "readable-stream": "^4.4.2", + "reinterval": "^1.1.0", + "rfdc": "^1.3.0", + "split2": "^4.2.0", + "worker-timers": "^7.1.4", + "ws": "^8.17.1" + }, + "bin": { + "mqtt": "build/bin/mqtt.js", + "mqtt_pub": "build/bin/pub.js", + "mqtt_sub": "build/bin/sub.js" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/mqtt-packet": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-9.0.0.tgz", + "integrity": "sha512-8v+HkX+fwbodsWAZIZTI074XIoxVBOmPeggQuDFCGg1SqNcC+uoRMWu7J6QlJPqIUIJXmjNYYHxBBLr1Y/Df4w==", + "dependencies": { + "bl": "^6.0.8", + "debug": "^4.3.4", + "process-nextick-args": "^2.0.1" + } + }, + "node_modules/mqtt-packet/node_modules/bl": { + "version": "6.0.15", + "resolved": "https://registry.npmjs.org/bl/-/bl-6.0.15.tgz", + "integrity": "sha512-RGhjD1XCPS7ZdAH6cEJVaR3gLV4KJP2hvkQ49AH5kwScjiyd0jBM8RsP4oHKzcx+kNCON9752zPeRnuv0HHwzw==", + "dependencies": { + "@types/readable-stream": "^4.0.0", + "buffer": "^6.0.3", + "inherits": "^2.0.4", + "readable-stream": "^4.2.0" + } + }, + "node_modules/mqtt-packet/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/mqtt-packet/node_modules/readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/mqtt/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/mqtt/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==" + }, + "node_modules/mqtt/node_modules/readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/mquery": { "version": "3.2.5", "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.5.tgz", @@ -9201,6 +9392,15 @@ "set-blocking": "^2.0.0" } }, + "node_modules/number-allocator": { + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/number-allocator/-/number-allocator-1.0.14.tgz", + "integrity": "sha512-OrL44UTVAvkKdOdRQZIJpLkAdjXGTRda052sN4sO77bKEzYYqWKMBjQvrJFzqygI99gL6Z4u2xctPW1tB8ErvA==", + "dependencies": { + "debug": "^4.3.1", + "js-sdsl": "4.3.0" + } + }, "node_modules/nunjucks": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.3.tgz", @@ -10478,6 +10678,11 @@ "jsesc": "bin/jsesc" } }, + "node_modules/reinterval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reinterval/-/reinterval-1.1.0.tgz", + "integrity": "sha512-QIRet3SYrGp0HUHO88jVskiG6seqUGC5iAG7AwI/BV4ypGcuqk9Du6YQBUOUqm9c8pw1eyLoIaONifRua1lsEQ==" + }, "node_modules/request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -11093,9 +11298,9 @@ } }, "node_modules/split2": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz", - "integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", "engines": { "node": ">= 10.x" } @@ -11650,9 +11855,9 @@ } }, "node_modules/tslib": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", - "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==" + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" }, "node_modules/tunnel-agent": { "version": "0.6.0", @@ -12396,6 +12601,37 @@ "node": ">=0.10.0" } }, + "node_modules/worker-timers": { + "version": "7.1.8", + "resolved": "https://registry.npmjs.org/worker-timers/-/worker-timers-7.1.8.tgz", + "integrity": "sha512-R54psRKYVLuzff7c1OTFcq/4Hue5Vlz4bFtNEIarpSiCYhpifHU3aIQI29S84o1j87ePCYqbmEJPqwBTf+3sfw==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2", + "worker-timers-broker": "^6.1.8", + "worker-timers-worker": "^7.0.71" + } + }, + "node_modules/worker-timers-broker": { + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/worker-timers-broker/-/worker-timers-broker-6.1.8.tgz", + "integrity": "sha512-FUCJu9jlK3A8WqLTKXM9E6kAmI/dR1vAJ8dHYLMisLNB/n3GuaFIjJ7pn16ZcD1zCOf7P6H62lWIEBi+yz/zQQ==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "fast-unique-numbers": "^8.0.13", + "tslib": "^2.6.2", + "worker-timers-worker": "^7.0.71" + } + }, + "node_modules/worker-timers-worker": { + "version": "7.0.71", + "resolved": "https://registry.npmjs.org/worker-timers-worker/-/worker-timers-worker-7.0.71.tgz", + "integrity": "sha512-ks/5YKwZsto1c2vmljroppOKCivB/ma97g9y77MAAz2TBBjPPgpoOiS1qYQKIgvGTr2QYPT3XhJWIB6Rj2MVPQ==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -12418,6 +12654,26 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "node_modules/ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/xlsx": { "version": "0.18.5", "resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz", diff --git a/package-lock.json b/package-lock.json index b74fdaf5..e841c8e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,6 +52,7 @@ "moment-timezone": "^0.5.43", "mongodb": "^5.0.1", "mongoose": "^5.11.8", + "mqtt": "^5.10.1", "multer": "^1.4.5-lts.1", "mv": "^2.1.1", "node-cron": "^3.0.2", @@ -1985,16 +1986,21 @@ } }, "node_modules/@babel/runtime": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.7.tgz", - "integrity": "sha512-UF0tvkUtxwAgZ5W/KrkHf0Rn0fdnLDU9ScxBrEVNUprE/MzirjK4MJUX1/BVDv00Sv8cljtukVK1aky++X1SjQ==", + "version": "7.25.6", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.6.tgz", + "integrity": "sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==", "dependencies": { - "regenerator-runtime": "^0.13.11" + "regenerator-runtime": "^0.14.0" }, "engines": { "node": ">=6.9.0" } }, + "node_modules/@babel/runtime/node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" + }, "node_modules/@babel/template": { "version": "7.20.7", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", @@ -3703,6 +3709,20 @@ "@types/react": "*" } }, + "node_modules/@types/readable-stream": { + "version": "4.0.15", + "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.15.tgz", + "integrity": "sha512-oAZ3kw+kJFkEqyh7xORZOku1YAKvsFTogRY8kVl4vHpEKiDkfnSA/My8haRE7fvmix5Zyy+1pwzOi7yycGLBJw==", + "dependencies": { + "@types/node": "*", + "safe-buffer": "~5.1.1" + } + }, + "node_modules/@types/readable-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, "node_modules/@types/request": { "version": "2.48.12", "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.12.tgz", @@ -3772,6 +3792,14 @@ "@types/webidl-conversions": "*" } }, + "node_modules/@types/ws": { + "version": "8.5.12", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", + "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/a-sync-waterfall": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz", @@ -4867,6 +4895,11 @@ "node": ">= 6" } }, + "node_modules/commist": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/commist/-/commist-3.2.0.tgz", + "integrity": "sha512-4PIMoPniho+LqXmpS5d3NuGYncG6XWlkBSVGiWycL22dd42OYdUGil2CWuzklaJoNxyxUSpO4MKIBU94viWNAw==" + }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -5759,6 +5792,18 @@ "resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.6.tgz", "integrity": "sha512-VhXlQgj9ioXCqGstD37E/HBeqEGV/qOD/kmbVG8h5xKBYvM1L3lR1Zn4555cQ8GkYbJa8aJSipLPndE1k6zK2w==" }, + "node_modules/fast-unique-numbers": { + "version": "8.0.13", + "resolved": "https://registry.npmjs.org/fast-unique-numbers/-/fast-unique-numbers-8.0.13.tgz", + "integrity": "sha512-7OnTFAVPefgw2eBJ1xj2PGGR9FwYzSUso9decayHgCDX4sJkHLdcsYTytTg+tYv+wKF3U8gJuSBz2jJpQV4u/g==", + "dependencies": { + "@babel/runtime": "^7.23.8", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.1.0" + } + }, "node_modules/fast-uri": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-2.2.0.tgz", @@ -7546,6 +7591,11 @@ "node": ">=0.10.40" } }, + "node_modules/help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==" + }, "node_modules/hexoid": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", @@ -8013,6 +8063,15 @@ "url": "https://github.com/sponsors/panva" } }, + "node_modules/js-sdsl": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", + "integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -8670,9 +8729,9 @@ } }, "node_modules/minimist": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", - "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -8924,6 +8983,139 @@ "node": ">=4.0.0" } }, + "node_modules/mqtt": { + "version": "5.10.1", + "resolved": "https://registry.npmjs.org/mqtt/-/mqtt-5.10.1.tgz", + "integrity": "sha512-hXCOki8sANoQ7w+2OzJzg6qMBxTtrH9RlnVNV8panLZgnl+Gh0J/t4k6r8Az8+C7y3KAcyXtn0mmLixyUom8Sw==", + "dependencies": { + "@types/readable-stream": "^4.0.5", + "@types/ws": "^8.5.9", + "commist": "^3.2.0", + "concat-stream": "^2.0.0", + "debug": "^4.3.4", + "help-me": "^5.0.0", + "lru-cache": "^10.0.1", + "minimist": "^1.2.8", + "mqtt-packet": "^9.0.0", + "number-allocator": "^1.0.14", + "readable-stream": "^4.4.2", + "reinterval": "^1.1.0", + "rfdc": "^1.3.0", + "split2": "^4.2.0", + "worker-timers": "^7.1.4", + "ws": "^8.17.1" + }, + "bin": { + "mqtt": "build/bin/mqtt.js", + "mqtt_pub": "build/bin/pub.js", + "mqtt_sub": "build/bin/sub.js" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/mqtt-packet": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-9.0.0.tgz", + "integrity": "sha512-8v+HkX+fwbodsWAZIZTI074XIoxVBOmPeggQuDFCGg1SqNcC+uoRMWu7J6QlJPqIUIJXmjNYYHxBBLr1Y/Df4w==", + "dependencies": { + "bl": "^6.0.8", + "debug": "^4.3.4", + "process-nextick-args": "^2.0.1" + } + }, + "node_modules/mqtt-packet/node_modules/bl": { + "version": "6.0.15", + "resolved": "https://registry.npmjs.org/bl/-/bl-6.0.15.tgz", + "integrity": "sha512-RGhjD1XCPS7ZdAH6cEJVaR3gLV4KJP2hvkQ49AH5kwScjiyd0jBM8RsP4oHKzcx+kNCON9752zPeRnuv0HHwzw==", + "dependencies": { + "@types/readable-stream": "^4.0.0", + "buffer": "^6.0.3", + "inherits": "^2.0.4", + "readable-stream": "^4.2.0" + } + }, + "node_modules/mqtt-packet/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/mqtt-packet/node_modules/readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/mqtt/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/mqtt/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==" + }, + "node_modules/mqtt/node_modules/readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/mquery": { "version": "3.2.5", "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.5.tgz", @@ -9278,6 +9470,15 @@ "set-blocking": "^2.0.0" } }, + "node_modules/number-allocator": { + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/number-allocator/-/number-allocator-1.0.14.tgz", + "integrity": "sha512-OrL44UTVAvkKdOdRQZIJpLkAdjXGTRda052sN4sO77bKEzYYqWKMBjQvrJFzqygI99gL6Z4u2xctPW1tB8ErvA==", + "dependencies": { + "debug": "^4.3.1", + "js-sdsl": "4.3.0" + } + }, "node_modules/nunjucks": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.3.tgz", @@ -10555,6 +10756,11 @@ "jsesc": "bin/jsesc" } }, + "node_modules/reinterval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reinterval/-/reinterval-1.1.0.tgz", + "integrity": "sha512-QIRet3SYrGp0HUHO88jVskiG6seqUGC5iAG7AwI/BV4ypGcuqk9Du6YQBUOUqm9c8pw1eyLoIaONifRua1lsEQ==" + }, "node_modules/request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -11170,9 +11376,9 @@ } }, "node_modules/split2": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz", - "integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", "engines": { "node": ">= 10.x" } @@ -11727,9 +11933,9 @@ } }, "node_modules/tslib": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", - "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==" + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" }, "node_modules/tunnel-agent": { "version": "0.6.0", @@ -12473,6 +12679,37 @@ "node": ">=0.10.0" } }, + "node_modules/worker-timers": { + "version": "7.1.8", + "resolved": "https://registry.npmjs.org/worker-timers/-/worker-timers-7.1.8.tgz", + "integrity": "sha512-R54psRKYVLuzff7c1OTFcq/4Hue5Vlz4bFtNEIarpSiCYhpifHU3aIQI29S84o1j87ePCYqbmEJPqwBTf+3sfw==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2", + "worker-timers-broker": "^6.1.8", + "worker-timers-worker": "^7.0.71" + } + }, + "node_modules/worker-timers-broker": { + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/worker-timers-broker/-/worker-timers-broker-6.1.8.tgz", + "integrity": "sha512-FUCJu9jlK3A8WqLTKXM9E6kAmI/dR1vAJ8dHYLMisLNB/n3GuaFIjJ7pn16ZcD1zCOf7P6H62lWIEBi+yz/zQQ==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "fast-unique-numbers": "^8.0.13", + "tslib": "^2.6.2", + "worker-timers-worker": "^7.0.71" + } + }, + "node_modules/worker-timers-worker": { + "version": "7.0.71", + "resolved": "https://registry.npmjs.org/worker-timers-worker/-/worker-timers-worker-7.0.71.tgz", + "integrity": "sha512-ks/5YKwZsto1c2vmljroppOKCivB/ma97g9y77MAAz2TBBjPPgpoOiS1qYQKIgvGTr2QYPT3XhJWIB6Rj2MVPQ==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -12495,6 +12732,26 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "node_modules/ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/xlsx": { "version": "0.18.5", "resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz", @@ -13984,11 +14241,18 @@ } }, "@babel/runtime": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.7.tgz", - "integrity": "sha512-UF0tvkUtxwAgZ5W/KrkHf0Rn0fdnLDU9ScxBrEVNUprE/MzirjK4MJUX1/BVDv00Sv8cljtukVK1aky++X1SjQ==", + "version": "7.25.6", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.6.tgz", + "integrity": "sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==", "requires": { - "regenerator-runtime": "^0.13.11" + "regenerator-runtime": "^0.14.0" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" + } } }, "@babel/template": { @@ -15334,6 +15598,22 @@ "@types/react": "*" } }, + "@types/readable-stream": { + "version": "4.0.15", + "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.15.tgz", + "integrity": "sha512-oAZ3kw+kJFkEqyh7xORZOku1YAKvsFTogRY8kVl4vHpEKiDkfnSA/My8haRE7fvmix5Zyy+1pwzOi7yycGLBJw==", + "requires": { + "@types/node": "*", + "safe-buffer": "~5.1.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + } + } + }, "@types/request": { "version": "2.48.12", "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.12.tgz", @@ -15403,6 +15683,14 @@ "@types/webidl-conversions": "*" } }, + "@types/ws": { + "version": "8.5.12", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", + "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", + "requires": { + "@types/node": "*" + } + }, "a-sync-waterfall": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz", @@ -16234,6 +16522,11 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz", "integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==" }, + "commist": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/commist/-/commist-3.2.0.tgz", + "integrity": "sha512-4PIMoPniho+LqXmpS5d3NuGYncG6XWlkBSVGiWycL22dd42OYdUGil2CWuzklaJoNxyxUSpO4MKIBU94viWNAw==" + }, "commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -16927,6 +17220,15 @@ "resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.6.tgz", "integrity": "sha512-VhXlQgj9ioXCqGstD37E/HBeqEGV/qOD/kmbVG8h5xKBYvM1L3lR1Zn4555cQ8GkYbJa8aJSipLPndE1k6zK2w==" }, + "fast-unique-numbers": { + "version": "8.0.13", + "resolved": "https://registry.npmjs.org/fast-unique-numbers/-/fast-unique-numbers-8.0.13.tgz", + "integrity": "sha512-7OnTFAVPefgw2eBJ1xj2PGGR9FwYzSUso9decayHgCDX4sJkHLdcsYTytTg+tYv+wKF3U8gJuSBz2jJpQV4u/g==", + "requires": { + "@babel/runtime": "^7.23.8", + "tslib": "^2.6.2" + } + }, "fast-uri": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-2.2.0.tgz", @@ -18398,6 +18700,11 @@ } } }, + "help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==" + }, "hexoid": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", @@ -18723,6 +19030,11 @@ "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.9.tgz", "integrity": "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA==" }, + "js-sdsl": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", + "integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==" + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -19305,9 +19617,9 @@ } }, "minimist": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", - "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==" + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==" }, "minipass": { "version": "5.0.0", @@ -19472,6 +19784,101 @@ "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz", "integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g==" }, + "mqtt": { + "version": "5.10.1", + "resolved": "https://registry.npmjs.org/mqtt/-/mqtt-5.10.1.tgz", + "integrity": "sha512-hXCOki8sANoQ7w+2OzJzg6qMBxTtrH9RlnVNV8panLZgnl+Gh0J/t4k6r8Az8+C7y3KAcyXtn0mmLixyUom8Sw==", + "requires": { + "@types/readable-stream": "^4.0.5", + "@types/ws": "^8.5.9", + "commist": "^3.2.0", + "concat-stream": "^2.0.0", + "debug": "^4.3.4", + "help-me": "^5.0.0", + "lru-cache": "^10.0.1", + "minimist": "^1.2.8", + "mqtt-packet": "^9.0.0", + "number-allocator": "^1.0.14", + "readable-stream": "^4.4.2", + "reinterval": "^1.1.0", + "rfdc": "^1.3.0", + "split2": "^4.2.0", + "worker-timers": "^7.1.4", + "ws": "^8.17.1" + }, + "dependencies": { + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==" + }, + "readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "requires": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + } + } + } + }, + "mqtt-packet": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-9.0.0.tgz", + "integrity": "sha512-8v+HkX+fwbodsWAZIZTI074XIoxVBOmPeggQuDFCGg1SqNcC+uoRMWu7J6QlJPqIUIJXmjNYYHxBBLr1Y/Df4w==", + "requires": { + "bl": "^6.0.8", + "debug": "^4.3.4", + "process-nextick-args": "^2.0.1" + }, + "dependencies": { + "bl": { + "version": "6.0.15", + "resolved": "https://registry.npmjs.org/bl/-/bl-6.0.15.tgz", + "integrity": "sha512-RGhjD1XCPS7ZdAH6cEJVaR3gLV4KJP2hvkQ49AH5kwScjiyd0jBM8RsP4oHKzcx+kNCON9752zPeRnuv0HHwzw==", + "requires": { + "@types/readable-stream": "^4.0.0", + "buffer": "^6.0.3", + "inherits": "^2.0.4", + "readable-stream": "^4.2.0" + } + }, + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "requires": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + } + } + } + }, "mquery": { "version": "3.2.5", "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.5.tgz", @@ -19751,6 +20158,15 @@ "set-blocking": "^2.0.0" } }, + "number-allocator": { + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/number-allocator/-/number-allocator-1.0.14.tgz", + "integrity": "sha512-OrL44UTVAvkKdOdRQZIJpLkAdjXGTRda052sN4sO77bKEzYYqWKMBjQvrJFzqygI99gL6Z4u2xctPW1tB8ErvA==", + "requires": { + "debug": "^4.3.1", + "js-sdsl": "4.3.0" + } + }, "nunjucks": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.3.tgz", @@ -20710,6 +21126,11 @@ } } }, + "reinterval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reinterval/-/reinterval-1.1.0.tgz", + "integrity": "sha512-QIRet3SYrGp0HUHO88jVskiG6seqUGC5iAG7AwI/BV4ypGcuqk9Du6YQBUOUqm9c8pw1eyLoIaONifRua1lsEQ==" + }, "request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -21192,9 +21613,9 @@ } }, "split2": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz", - "integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==" + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==" }, "ssf": { "version": "0.11.2", @@ -21630,9 +22051,9 @@ "integrity": "sha512-iawgk0hLP3SxGKDfnDJf8wTz4p2qImnyihM5Hh/sGvQ3K37dPi/w8sRhdNIxYA1TwFwc5mDhIJq+O0RsvXBKdQ==" }, "tslib": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", - "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==" + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" }, "tunnel-agent": { "version": "0.6.0", @@ -22220,6 +22641,37 @@ "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==" }, + "worker-timers": { + "version": "7.1.8", + "resolved": "https://registry.npmjs.org/worker-timers/-/worker-timers-7.1.8.tgz", + "integrity": "sha512-R54psRKYVLuzff7c1OTFcq/4Hue5Vlz4bFtNEIarpSiCYhpifHU3aIQI29S84o1j87ePCYqbmEJPqwBTf+3sfw==", + "requires": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2", + "worker-timers-broker": "^6.1.8", + "worker-timers-worker": "^7.0.71" + } + }, + "worker-timers-broker": { + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/worker-timers-broker/-/worker-timers-broker-6.1.8.tgz", + "integrity": "sha512-FUCJu9jlK3A8WqLTKXM9E6kAmI/dR1vAJ8dHYLMisLNB/n3GuaFIjJ7pn16ZcD1zCOf7P6H62lWIEBi+yz/zQQ==", + "requires": { + "@babel/runtime": "^7.24.5", + "fast-unique-numbers": "^8.0.13", + "tslib": "^2.6.2", + "worker-timers-worker": "^7.0.71" + } + }, + "worker-timers-worker": { + "version": "7.0.71", + "resolved": "https://registry.npmjs.org/worker-timers-worker/-/worker-timers-worker-7.0.71.tgz", + "integrity": "sha512-ks/5YKwZsto1c2vmljroppOKCivB/ma97g9y77MAAz2TBBjPPgpoOiS1qYQKIgvGTr2QYPT3XhJWIB6Rj2MVPQ==", + "requires": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2" + } + }, "wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -22236,6 +22688,12 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "requires": {} + }, "xlsx": { "version": "0.18.5", "resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz", diff --git a/package.json b/package.json index e7f99557..8d38fe2e 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "moment-timezone": "^0.5.43", "mongodb": "^5.0.1", "mongoose": "^5.11.8", + "mqtt": "^5.10.1", "multer": "^1.4.5-lts.1", "mv": "^2.1.1", "node-cron": "^3.0.2", diff --git a/src/config/swagger.js b/src/config/swagger.js index 04ebf510..c82a3bf2 100644 --- a/src/config/swagger.js +++ b/src/config/swagger.js @@ -14,7 +14,7 @@ exports.options = { }, // We have to change this beacause this is running on local // we have to run on this on swagger - //host: "localhost:3000", //Devlopemnt host on lcoal + //host: "localhost:3000", //Devlopemnt host on lcoal host: "35.207.198.4:3000", //Production for swagger schemes: ["http"], diff --git a/src/controllers/admincontroller.js b/src/controllers/admincontroller.js index 5148f1f5..c389ef56 100644 --- a/src/controllers/admincontroller.js +++ b/src/controllers/admincontroller.js @@ -3,9 +3,28 @@ const boom = require("boom"); const jwt = require('jsonwebtoken') const bcrypt = require('bcrypt') + const fastify = require("fastify"); const { Tank, MotorData, IotData } = require('../models/tanks') +const JWT_SECRET = 'your-secret-key'; + +async function generateCustomerId() { + let customerId; + let isUnique = false; + + while (!isUnique) { + // Generate a random number or string for the customer ID + customerId = Math.floor(1000 + Math.random() * 9000).toString(); // Generates a random number between 1000 and 9999 + + // Check for uniqueness in the Admin collection + const existingAdmin = await Admin.findOne({ customerId }); + if (!existingAdmin) { + isUnique = true; // Exit the loop if the customer ID is unique + } + } + return customerId; +} // exports.adminSignUp = async (request, reply) => { @@ -39,73 +58,355 @@ const { Tank, MotorData, IotData } = require('../models/tanks') // } // } -exports.adminSignUp = async (request, reply) => { +// exports.adminSignUp = async (request, reply) => { - try { - const { email, password } = request.body +// try { +// const { email, password } = request.body - // Check if the email address is valid - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ - if (!emailRegex.test(email)) { - return reply.status(400).send({ message: 'Invalid email address' }) - } +// // Check if the email address is valid +// const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ +// if (!emailRegex.test(email)) { +// return reply.status(400).send({ message: 'Invalid email address' }) +// } - // Check if an admin with the same email address already exists - const existingAdmin = await Admin.findOne({ email }) +// // Check if an admin with the same email address already exists +// const existingAdmin = await Admin.findOne({ email }) - if (existingAdmin) { - return reply.status(400).send({ message: 'Email already registered' }) - } +// if (existingAdmin) { +// return reply.status(400).send({ message: 'Email already registered' }) +// } - // Hash the password using bcrypt - const hashedPassword = await bcrypt.hash(password, 10) +// // Hash the password using bcrypt +// const hashedPassword = await bcrypt.hash(password, 10) - // Create a new admin object with the hashed password - const admin = new Admin({ email, password: hashedPassword }) +// // Create a new admin object with the hashed password +// const admin = new Admin({ email, password: hashedPassword }) - // Save the new admin to the database - await admin.save() +// // Save the new admin to the database +// await admin.save() - // Generate a JWT token for the new admin - // const token = jwt.sign({ email: admin.email }, 'secret') +// // Generate a JWT token for the new admin +// // const token = jwt.sign({ email: admin.email }, 'secret') - // // Return the token to the client - // return { token } - reply.send({message : "Admin Account Created Sucessfully"}) - } catch (err) { - reply.status(500).send({ message: err.message }) - } - } +// // // Return the token to the client +// // return { token } +// reply.send({message : "Admin Account Created Sucessfully"}) +// } catch (err) { +// reply.status(500).send({ message: err.message }) +// } +// } - exports.adminLogin = async (request, reply) => { - try { - const { email, password } = request.body +// exports.adminLogin = async (request, reply) => { +// try { +// const { email, password } = request.body - // Check if an admin with the email address exists - const admin = await Admin.findOne({ email }) +// // Check if an admin with the email address exists +// const admin = await Admin.findOne({ email }) - if (!admin) { - return reply.status(401).send({ message: 'Invalid email or password' }) - } +// if (!admin) { +// return reply.status(401).send({ message: 'Invalid email or password' }) +// } - // Compare the password entered by the user with the hashed password stored in the database - const isPasswordValid = await bcrypt.compare(password, admin.password) +// // Compare the password entered by the user with the hashed password stored in the database +// const isPasswordValid = await bcrypt.compare(password, admin.password) - if (!isPasswordValid) { - return reply.status(401).send({ message: 'Invalid email or password' }) - } +// if (!isPasswordValid) { +// return reply.status(401).send({ message: 'Invalid email or password' }) +// } - // Generate a JWT token for the authenticated admin - const token = jwt.sign({ email: admin.email }, 'secret') +// // Generate a JWT token for the authenticated admin +// const token = jwt.sign({ email: admin.email }, 'secret') - // Return the token to the client - return { token } - } catch (err) { - reply.status(500).send({ message: err.message }) - } +// // Return the token to the client +// return { token } +// } catch (err) { +// reply.status(500).send({ message: err.message }) +// } +// } + + +// Admin Sign-Up Function +// exports.adminSignUp = async (request, reply) => { +// try { +// const { phone,username, password } = request.body; + +// // Check if the email address is valid +// // const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; +// // if (!emailRegex.test(email)) { +// // return reply.status(400).send({ message: 'Invalid email address' }); +// // } +// if (!username || username.trim() === '') { +// return reply.status(400).send({ message: 'Username is required' }); +// } + + +// // Check if an admin with the same email address already exists +// const existingAdminUsername = await Admin.findOne({ username }); +// const existingAdmin = await Admin.findOne({ phone }); +// if (existingAdmin) { +// return reply.status(400).send({ message: 'phone already registered' }); +// } +// if (existingAdminUsername) { +// return reply.status(400).send({ message: 'Username already registered' }); +// } + +// // Hash the password using bcrypt +// const hashedPassword = await bcrypt.hash(password, 10); + +// // Create a new admin object with the hashed password +// const admin = new Admin({ phone,username, password: hashedPassword }); + +// // Save the new admin to the database +// await admin.save(); + +// reply.send({ message: 'Admin Account Created Successfully' }); +// } catch (err) { +// reply.status(500).send({ message: err.message }); +// } +// }; + +exports.adminSignUp = async (request, reply) => { + try { + const { phone, username, password, role } = request.body; + + if (!username || username.trim() === '') { + return reply.status(400).send({ message: 'Username is required' }); + } + + // Validate role + if (!['admin', 'sales', 'store'].includes(role)) { + return reply.status(400).send({ message: 'Invalid role. Must be either admin, sales, or store' }); + } + + + + // Check if an admin with the same phone number or username already exists + const existingAdminUsername = await Admin.findOne({ username }); + const existingAdmin = await Admin.findOne({ phone }); + + if (existingAdmin) { + return reply.status(400).send({ message: 'Phone already registered' }); + } + if (existingAdminUsername) { + return reply.status(400).send({ message: 'Username already registered' }); + } + + // Hash the password using bcrypt + const hashedPassword = await bcrypt.hash(password, 10); + + const c_id = await generateCustomerId(); // Assuming you have this function defined elsewhere + const building = 'ADMIN'; // You can customize this logic to derive from a parameter or a default value + const customerId = `AWSU${building}${c_id}`; // Construct the customer ID + + // Create a new admin object with the hashed password and role + const admin = new Admin({ phone, username, password: hashedPassword, customerId, role }); + + // Save the new admin to the database + await admin.save(); + + reply.send({ message: 'Admin Account Created Successfully' }); + } catch (err) { + reply.status(500).send({ message: err.message }); + } +}; + + +// Admin Login Function (With Phone Number) +exports.adminLogin = async (request, reply) => { + try { + const { phone, password } = request.body; + + // Check if an admin with the phone number exists + const admin = await Admin.findOne({ phone }); + + if (!admin) { + return reply.status(401).send({ message: 'Invalid phone number or password' }); + } + + // Compare the password entered by the user with the hashed password stored in the database + const isPasswordValid = await bcrypt.compare(password, admin.password); + + if (!isPasswordValid) { + return reply.status(401).send({ message: 'Invalid phone number or password' }); + } + + // Generate a JWT token for the authenticated admin + const token = jwt.sign({ phone: admin.phone, role: 'admin' }, JWT_SECRET, { expiresIn: '1h' }); + + return reply.send({ token }); + } catch (err) { + reply.status(500).send({ message: err.message }); + } +}; + +// Sales and Store Login (Phone and Password) +// exports.salesStoreLogin = async (request, reply) => { +// try { +// const { phone, password } = request.body; + +// // Check if a user (sales or store) with the phone number exists +// const admin = await Admin.findOne({ phone }); + +// if (!admin) { +// return reply.status(401).send({ message: 'Invalid phone number or password' }); +// } + +// // Compare the password entered by the user with the hashed password stored in the database +// const isPasswordValid = await bcrypt.compare(password, admin.password); + +// if (!isPasswordValid) { +// return reply.status(401).send({ message: 'Invalid phone number or password' }); +// } + +// // Generate a JWT token for the authenticated user (with role sales or store) +// const token = jwt.sign({ phone: admin.phone, role: admin.role }, JWT_SECRET, { expiresIn: '1h' }); + +// return reply.send({ token }); +// } catch (err) { +// reply.status(500).send({ message: err.message }); +// } +// }; + +exports.salesStoreLogin = async (request, reply) => { + try { + const { phone, password, role } = request.body; + + // Check if a user (sales or store) with the phone number and role exists + const user = await Admin.findOne({ phone, role }); + + if (!user) { + return reply.status(401).send({ message: 'Invalid phone number, password, or role' }); + } + + // Compare the password entered by the user with the hashed password stored in the database + const isPasswordValid = await bcrypt.compare(password, user.password); + + if (!isPasswordValid) { + return reply.status(401).send({ message: 'Invalid phone number, password, or role' }); + } + + // Generate a JWT token for the authenticated user (with role sales or store) + const token = jwt.sign({ phone: user.phone, role: user.role }, JWT_SECRET, { expiresIn: '1h' }); + + return reply.send({ token }); + } catch (err) { + reply.status(500).send({ message: err.message }); + } +}; + + +exports.getUsersByRole = async (request, reply) => { + try { + const { role } = request.params; + + // Ensure the role is either 'sales' or 'store' + if (!['sales', 'store'].includes(role)) { + return reply.status(400).send({ message: 'Invalid role. Must be either sales or store.' }); + } + + // Find users with the specific role (sales or store) + const users = await Admin.find({ role }); + + // Send back the list of users + reply.send(users); + } catch (err) { + reply.status(500).send({ message: err.message }); } +}; + +exports.getUserByCustomerId = async (request, reply) => { + try { + const { customerId } = request.params; + + // Check if customerId is provided + if (!customerId) { + return reply.status(400).send({ message: 'Customer ID is required' }); + } + + // Fetch the user from the database + const user = await Admin.findOne({ customerId }); + + // If user not found, return a 404 response + if (!user) { + return reply.status(404).send({ message: 'User not found' }); + } + + // Return the user data + return reply.send(user); + } catch (err) { + return reply.status(500).send({ message: err.message }); + } +}; + + +// Create Sales/Store User (Admin Only) +// exports.createUser = async (request, reply) => { +// const { phone, password, role } = request.body; + +// // Validate role (only sales or store) +// if (!['sales', 'store'].includes(role)) { +// return reply.status(400).send({ message: 'Invalid role. Must be either sales or store' }); +// } + +// try { +// const existingUser = await Admin.findOne({ phone }); + +// if (existingUser) { +// return reply.status(400).send({ message: 'User with this phone number already exists' }); +// } + +// // Hash the password +// const hashedPassword = await bcrypt.hash(password, 10); + +// // Create the new user +// const newUser = new Admin({ +// phone, +// password: hashedPassword, +// role, +// }); + +// await newUser.save(); + +// return reply.send({ message: 'User created successfully' }); +// } catch (err) { +// reply.status(500).send({ message: err.message }); +// } +// }; + +exports.createUser = async (request, reply) => { + const { phone, password, role } = request.body; + + // Validate role (only sales or store) + if (!['sales', 'store'].includes(role)) { + return reply.status(400).send({ message: 'Invalid role. Must be either sales or store' }); + } + + try { + const existingUser = await Admin.findOne({ phone }); + + if (existingUser) { + return reply.status(400).send({ message: 'User with this phone number already exists' }); + } + + // Hash the password + const hashedPassword = await bcrypt.hash(password, 10); + + // Create the new user + const newUser = new Admin({ + phone, + password: hashedPassword, + role, + }); + + await newUser.save(); + return reply.send({ message: 'User created successfully' }); + } catch (err) { + reply.status(500).send({ message: err.message }); + } +}; + @@ -120,8 +421,3 @@ exports.adminSignUp = async (request, reply) => { } } - - - - - \ No newline at end of file diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 5934495a..52b066b1 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1423,7 +1423,18 @@ const sendNotification = async (fcmTokens, title, body) => { // } // }; - +exports.publishMotorStopStatus = async (motor_id, motor_stop_status) => { + const payload = { + topic: 'operation', + object: { + 'motor-id': motor_id, + control: motor_stop_status + } + }; + console.log("enetred publish") + console.log(payload) + client.publish('water/operation', JSON.stringify(payload)); +}; const stat_stop_intervals = {}; // exports.motorAction = async (req, reply) => { @@ -1757,7 +1768,8 @@ exports.motorAction = async (req, reply) => { } } ); - + this.publishMotorStopStatus(motorId, motorStopStatus); + // Send immediate response to the client reply.code(200).send({ message: "Motor stopped successfully." }); // Perform stop operations in the background @@ -1818,6 +1830,8 @@ exports.motorAction = async (req, reply) => { // Update the tank connections with start time and threshold time for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { + this.publishMotorStopStatus(motorId, motorStopStatus); + for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId); if (index !== -1) { await Tank.updateOne( @@ -1852,8 +1866,9 @@ exports.motorAction = async (req, reply) => { } ); emitWithTimestamp('lowWaterLevel', fcmToken); // Emit low water level notification + clearInterval(intervalId); - + this.publishMotorStopStatus(motorId, "1"); await delay(300000); const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id }); if (motorData) { @@ -3201,7 +3216,7 @@ exports.IotDeviceforstandalonedevice = async (req, reply) => { }; - + @@ -4250,3 +4265,143 @@ exports.getBlockData = async (req, reply) => { reply.code(500).send({ error: err.message }); } }; + + + + + +const mqtt = require('mqtt'); +const client = mqtt.connect('mqtt://35.207.198.4:1883'); // Connect to MQTT broker + +client.on('connect', () => { + console.log('Connected to MQTT broker'); + client.subscribe('water/iot-data', (err) => { + if (err) { + console.error('Error subscribing to topic:', err); + } else { + console.log('Subscribed to water/iot-data topic'); + } + }); +}); + +// Handling incoming MQTT messages +client.on('message', async (topic, message) => { + console.log(`Message received on topic ${topic}:`, message.toString()); + + if (topic === 'water/iot-data') { + try { + const data = JSON.parse(message.toString()); + const { hw_Id, Motor_status, tanks } = data.objects; // Updated variable names according to new format + + // Get the current date and time in the required format + const currentDate = new Date(); + const date = currentDate.toISOString(); // ISO string for date + const time = currentDate.toLocaleTimeString('en-IN', { hour12: false, timeZone: 'Asia/Kolkata' }); // Time in 'HH:MM:SS' + + // Create array of tank documents with current date and time + const tankDocuments = tanks.map(tank => ({ + tankhardwareId: tank.Id, // Updated to match the new format + tankHeight: tank.level, // Updated to match the new format + date, + time + })); + + // Save IoT data for the received tanks + const iotTankData = new IotData({ + hardwareId: hw_Id, // Updated variable name + Motor_status, + tanks: tankDocuments, + date, + time + }); + await iotTankData.save(); + + // Delete excess records (keep only the latest three records) + const recordsToKeep = 3; + const recordsToDelete = await IotData.find({ hardwareId: hw_Id }) // Updated variable name + .sort({ date: -1, time: -1 }) + .skip(recordsToKeep); + + for (const record of recordsToDelete) { + await record.remove(); + } + + // Process each tank to update water level and connections + for (const tank of tanks) { + const { Id: tankhardwareId, level: tankHeight } = tank; // Updated to match the new format + // Find the corresponding tank in the Tank schema using hardwareId and tankhardwareId + const existingTank = await Tank.findOne({ hardwareId: hw_Id, tankhardwareId }); // Updated variable name + if (!existingTank) continue; + + const customerId = existingTank.customerId; + const tank_name = existingTank.tankName; + + // Calculate water level using tank height and capacity + const tankHeightInCm = (parseInt(existingTank.height.replace(/,/g, ''), 10)) * 30.48; // Convert height to cm + const tank_height = parseInt(tankHeightInCm.toFixed(0), 10); + const waterLevelHeight = tank_height - tankHeight; + const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10); + + const waterLevel = parseInt(waterLevelHeight * waterCapacityPerCm, 10); // Calculated water level + + // Update water level in the existing tank + if (waterLevel >= 0) { + existingTank.waterlevel = waterLevel; + await existingTank.save(); + + // Update linked tanks (input/output connections) + for (const outputConnection of existingTank.connections.outputConnections) { + const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type }); + if (linkedTank) { + for (const inputConnection of linkedTank.connections.inputConnections) { + if (inputConnection.inputConnections === tank_name) { + inputConnection.water_level = waterLevel; // Update water level for linked tank + await linkedTank.save(); // Save updated linked tank + } + } + } + } + } + } + + // Update motor status + const status = Motor_status; + const motorTank = await Tank.findOne({ "connections.inputConnections.motor_id": hw_Id }); // Updated variable name + + if (!motorTank) { + console.log('Motor not found for the specified motor_id'); + return; + } + + // Find the inputConnection for the motor and update motor status + const inputConnection = motorTank.connections.inputConnections.find(conn => conn.motor_id === hw_Id); // Updated variable name + if (inputConnection) { + inputConnection.motor_status = status; // Update motor status + await motorTank.save(); // Save the updated tank + } + + console.log('Data processed successfully for hardwareId:', hw_Id); // Updated variable name + + } catch (err) { + console.error('Error processing message:', err.message); + } + } +}); + + +// Function to publish motor stop status +// exports.publishMotorStopStatus = async (motor_id, motor_stop_status) => { +// const payload = { +// topic: 'operation', +// object: { +// 'motor-id': motor_id, +// control: motor_stop_status +// } +// }; + +// client.publish('water/operation', JSON.stringify(payload)); +// }; + + + + diff --git a/src/models/admin.js b/src/models/admin.js index 29de8268..2a962f4c 100644 --- a/src/models/admin.js +++ b/src/models/admin.js @@ -1,18 +1,40 @@ const mongoose = require('mongoose') + + const adminSchema = new mongoose.Schema({ - email: { + + phone: { + type: String, + required: true, + //unique: true, + }, + + username: { type: String, required: true, unique: true, - lowercase: true }, password: { type: String, required: true - } + }, + role: { + type: String, + enum: ['admin', 'sales', 'store'], + default: 'sales', + }, + customerId: { + type: String, + required: true, // Customer ID is now required + unique: true, + }, + date: { + type: Date, + default: Date.now, + }, }) const Admin = mongoose.model('Admin', adminSchema) -module.exports = Admin +module.exports = Admin \ No newline at end of file diff --git a/src/routes/adminRoute.js b/src/routes/adminRoute.js index cbf3eff6..54629f06 100644 --- a/src/routes/adminRoute.js +++ b/src/routes/adminRoute.js @@ -3,31 +3,58 @@ const adminController = require('../controllers/admincontroller') module.exports = function (fastify, opts, next) { +// fastify.route({ +// method: "POST", +// url: "/api/adminSignup", +// schema: { +// tags: ["Admin"], +// description: "This is for cretae New Admin Account", +// summary: "This is for cretae New Admin Account", +// body: { +// type: "object", +// properties: { +// phone : { type: "string" }, +// password: { type: "string" }, +// username:{type:"string"}, +// }, +// }, +// security: [ +// { +// basicAuth: [], +// }, +// ], +// }, + +// handler: adminController.adminSignUp, + +// }); + fastify.route({ - method: "POST", - url: "/api/adminSignup", - schema: { - tags: ["Admin"], - description: "This is for cretae New Admin Account", - summary: "This is for cretae New Admin Account", - body: { - type: "object", - properties: { - email: { type: "string" }, - password: { type: "string" }, - - }, + method: "POST", + url: "/api/adminSignup", + schema: { + tags: ["Admin"], + description: "This is for creating a new Admin/sales/store Account", + summary: "This is for creating a new Admin/sales/store Account", + body: { + type: "object", + required: ["phone", "username", "password", "role"], // Add role to required fields + properties: { + phone: { type: "string" }, + password: { type: "string" }, + username: { type: "string" }, + role: { type: "string", enum: ["admin", "sales", "store"] }, // Define allowed roles }, - security: [ - { - basicAuth: [], - }, - ], }, + security: [ + { + basicAuth: [], + }, + ], + }, + handler: adminController.adminSignUp, +}); - handler: adminController.adminSignUp, - - }); fastify.post("/api/adminLogin", { schema: { @@ -36,9 +63,9 @@ fastify.route({ summary: "This is for Login Admin", body: { type: "object", - required: ["email", "password"], + required: ["phone", "password"], properties: { - email: { type: "string" }, + phone : { type: "string" }, password: { type: "string" }, }, }, @@ -46,6 +73,100 @@ fastify.route({ handler: adminController.adminLogin, }); +fastify.post("/api/salesStoreLogin", { + schema: { + description: "Login for sales/store users", + tags: ["Sales/Store Login"], + summary: "Login for sales/store users", + body: { + type: "object", + required: ["phone", "password", "role"], + properties: { + phone : { type: "string" }, + password: { type: "string" }, + role: { type: "string", enum: ["sales", "store"] } + }, + }, + }, + handler: adminController.salesStoreLogin, +}); + + +fastify.get("/api/getUsersByRole/:role", { + schema: { + description: "Get list of users by role (sales/store)", + tags: ["Sales/Store Users"], + summary: "Get list of users by role", + params: { + type: "object", + properties: { + role: { type: "string", enum: ["sales", "store"] }, + }, + required: ["role"], + }, + response: { + 200: { + type: "array", + items: { + type: "object", + properties: { + phone: { type: "string" }, + username: { type: "string" }, + role: { type: "string" }, + date: { type: "string", format: "date-time" } + } + } + } + } + }, + handler: adminController.getUsersByRole, +}); + +fastify.route({ + method: "GET", + url: "/api/users/:customerId", // Use path parameters for customerId + schema: { + tags: ["Admin"], + description: "Retrieve user information by customerId", + summary: "Get user by customerId", + params: { + type: "object", + required: ["customerId"], + properties: { + customerId: { type: "string" }, + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + handler: adminController.getUserByCustomerId, // Link the handler function +}); + + +// fastify.post("/api/createUser", { +// schema: { +// description: "This is for Create sale/store", +// tags: ["createUser for sale/sore"], +// summary: "This is for Create sale/store", +// body: { +// type: "object", +// required: ["phone", "password", "role"], +// properties: { +// phone : { type: "string" }, +// password: { type: "string" }, +// role: { type: "string", enum: ["sales", "store"] } +// }, +// }, +// }, +// handler: adminController.createUser, +// }); + + + + fastify.post("/api/integratingHardwareidToTank", { schema: { description: "This is for integrating hardwareId with tank",