diff --git a/.devcontainer/chefs_local/local.json.sample b/.devcontainer/chefs_local/local.json.sample index bc6cd6da0..9e9365c47 100644 --- a/.devcontainer/chefs_local/local.json.sample +++ b/.devcontainer/chefs_local/local.json.sample @@ -67,6 +67,7 @@ "eventStreamService": { "servers": "localhost:4222,localhost:4223,localhost:4224", "streamName": "CHEFS", + "source": "chefs", "domain": "forms", "username": "chefs", "password": "password" diff --git a/app/package-lock.json b/app/package-lock.json index d0c1738b1..ea26e8053 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -37,10 +37,12 @@ "moment": "^2.29.4", "multer": "^1.4.5-lts.1", "nats": "^2.28.0", + "nats.ws": "^1.29.2", "nested-objects-util": "^1.1.2", "objection": "^3.0.1", "pg": "^8.10.0", "uuid": "^8.3.2", + "websocket": "^1.0.35", "winston": "^3.8.2" }, "devDependencies": { @@ -2516,6 +2518,18 @@ "node": ">=4" } }, + "node_modules/bufferutil": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz", + "integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==", + "hasInstallScript": true, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=6.14.2" + } + }, "node_modules/busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -3024,6 +3038,18 @@ "resolved": "https://registry.npmjs.org/cryptr/-/cryptr-6.3.0.tgz", "integrity": "sha512-TA4byAuorT8qooU9H8YJhBwnqD151i1rcauHfJ3Divg6HmukHB2AYMp0hmjv2873J2alr4t15QqC7zAnWFrtfQ==" }, + "node_modules/d": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", + "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", + "dependencies": { + "es5-ext": "^0.10.64", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.12" + } + }, "node_modules/db-errors": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/db-errors/-/db-errors-0.2.3.tgz", @@ -3312,6 +3338,43 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/es5-ext": { + "version": "0.10.64", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", + "hasInstallScript": true, + "dependencies": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", + "next-tick": "^1.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", + "dependencies": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, + "node_modules/es6-symbol": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", + "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", + "dependencies": { + "d": "^1.0.2", + "ext": "^1.7.0" + }, + "engines": { + "node": ">=0.12" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -5600,6 +5663,20 @@ "node": ">=6" } }, + "node_modules/esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.10" + } + }, "node_modules/espree": { "version": "9.5.2", "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.2.tgz", @@ -5680,6 +5757,15 @@ "node": ">= 0.6" } }, + "node_modules/event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "dependencies": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "node_modules/events": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", @@ -5911,6 +5997,14 @@ } ] }, + "node_modules/ext": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", + "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", + "dependencies": { + "type": "^2.7.2" + } + }, "node_modules/external-editor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", @@ -7067,6 +7161,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==" + }, "node_modules/is-weakref": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-weakref/-/is-weakref-1.0.2.tgz", @@ -8491,6 +8590,14 @@ "node": ">= 14.0.0" } }, + "node_modules/nats.ws": { + "version": "1.29.2", + "resolved": "https://registry.npmjs.org/nats.ws/-/nats.ws-1.29.2.tgz", + "integrity": "sha512-dJf7aWp+5+8LwWEhgoTMc3pvfz5JlhA0yWtXKcTMDxUe43mHvgpvDaPnLyHQNL2LoDpdkjgOG176i5IeHBDlqg==", + "optionalDependencies": { + "nkeys.js": "1.1.0" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -8515,6 +8622,11 @@ "resolved": "https://registry.npmjs.org/nested-objects-util/-/nested-objects-util-1.1.2.tgz", "integrity": "sha512-jNUcnODTq1HpGGFFo9aDXP7JxrJ1ilLHSaUElSyW5Zw8EJHyYyujdBIdTwa0K4lBC/9M23dJyhExo9XyhO39LQ==" }, + "node_modules/next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -8532,6 +8644,16 @@ "node": ">=10.0.0" } }, + "node_modules/node-gyp-build": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -10518,6 +10640,11 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" }, + "node_modules/type": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz", + "integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -10582,6 +10709,14 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, + "node_modules/typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "dependencies": { + "is-typedarray": "^1.0.0" + } + }, "node_modules/typescript": { "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", @@ -10702,6 +10837,18 @@ "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", "integrity": "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw==" }, + "node_modules/utf-8-validate": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", + "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==", + "hasInstallScript": true, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=6.14.2" + } + }, "node_modules/util": { "version": "0.12.5", "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", @@ -10852,6 +10999,22 @@ "makeerror": "1.0.12" } }, + "node_modules/websocket": { + "version": "1.0.35", + "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.35.tgz", + "integrity": "sha512-/REy6amwPZl44DDzvRCkaI1q1bIiQB0mEFQLUrhz3z2EK91cp3n72rAjUlrTP0zV22HJIUOVHQGPxhFRjxjt+Q==", + "dependencies": { + "bufferutil": "^4.0.1", + "debug": "^2.2.0", + "es5-ext": "^0.10.63", + "typedarray-to-buffer": "^3.1.5", + "utf-8-validate": "^5.0.2", + "yaeti": "^0.0.6" + }, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -11115,6 +11278,14 @@ "node": ">=10" } }, + "node_modules/yaeti": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz", + "integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==", + "engines": { + "node": ">=0.10.32" + } + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", @@ -13063,6 +13234,14 @@ "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" }, + "bufferutil": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz", + "integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==", + "requires": { + "node-gyp-build": "^4.3.0" + } + }, "busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -13448,6 +13627,15 @@ "resolved": "https://registry.npmjs.org/cryptr/-/cryptr-6.3.0.tgz", "integrity": "sha512-TA4byAuorT8qooU9H8YJhBwnqD151i1rcauHfJ3Divg6HmukHB2AYMp0hmjv2873J2alr4t15QqC7zAnWFrtfQ==" }, + "d": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", + "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", + "requires": { + "es5-ext": "^0.10.64", + "type": "^2.7.2" + } + }, "db-errors": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/db-errors/-/db-errors-0.2.3.tgz", @@ -13674,6 +13862,36 @@ "is-symbol": "^1.0.2" } }, + "es5-ext": { + "version": "0.10.64", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", + "requires": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", + "next-tick": "^1.1.0" + } + }, + "es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", + "requires": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, + "es6-symbol": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", + "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", + "requires": { + "d": "^1.0.2", + "ext": "^1.7.0" + } + }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -15418,6 +15636,17 @@ "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==" }, + "esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "requires": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + } + }, "espree": { "version": "9.5.2", "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.2.tgz", @@ -15470,6 +15699,15 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==" }, + "event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "requires": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "events": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", @@ -15638,6 +15876,14 @@ } } }, + "ext": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", + "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", + "requires": { + "type": "^2.7.2" + } + }, "external-editor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", @@ -16448,6 +16694,11 @@ "has-tostringtag": "^1.0.0" } }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==" + }, "is-weakref": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-weakref/-/is-weakref-1.0.2.tgz", @@ -17526,6 +17777,14 @@ "nkeys.js": "1.1.0" } }, + "nats.ws": { + "version": "1.29.2", + "resolved": "https://registry.npmjs.org/nats.ws/-/nats.ws-1.29.2.tgz", + "integrity": "sha512-dJf7aWp+5+8LwWEhgoTMc3pvfz5JlhA0yWtXKcTMDxUe43mHvgpvDaPnLyHQNL2LoDpdkjgOG176i5IeHBDlqg==", + "requires": { + "nkeys.js": "1.1.0" + } + }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -17547,6 +17806,11 @@ "resolved": "https://registry.npmjs.org/nested-objects-util/-/nested-objects-util-1.1.2.tgz", "integrity": "sha512-jNUcnODTq1HpGGFFo9aDXP7JxrJ1ilLHSaUElSyW5Zw8EJHyYyujdBIdTwa0K4lBC/9M23dJyhExo9XyhO39LQ==" }, + "next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -17561,6 +17825,11 @@ "tweetnacl": "1.0.3" } }, + "node-gyp-build": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -19029,6 +19298,11 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" }, + "type": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz", + "integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==" + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -19075,6 +19349,14 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, + "typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "requires": { + "is-typedarray": "^1.0.0" + } + }, "typescript": { "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", @@ -19155,6 +19437,14 @@ } } }, + "utf-8-validate": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", + "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==", + "requires": { + "node-gyp-build": "^4.3.0" + } + }, "util": { "version": "0.12.5", "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", @@ -19269,6 +19559,19 @@ "makeerror": "1.0.12" } }, + "websocket": { + "version": "1.0.35", + "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.35.tgz", + "integrity": "sha512-/REy6amwPZl44DDzvRCkaI1q1bIiQB0mEFQLUrhz3z2EK91cp3n72rAjUlrTP0zV22HJIUOVHQGPxhFRjxjt+Q==", + "requires": { + "bufferutil": "^4.0.1", + "debug": "^2.2.0", + "es5-ext": "^0.10.63", + "typedarray-to-buffer": "^3.1.5", + "utf-8-validate": "^5.0.2", + "yaeti": "^0.0.6" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -19454,6 +19757,11 @@ "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "dev": true }, + "yaeti": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz", + "integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==" + }, "yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/app/package.json b/app/package.json index 25d34d8e7..5723af61a 100644 --- a/app/package.json +++ b/app/package.json @@ -75,10 +75,12 @@ "moment": "^2.29.4", "multer": "^1.4.5-lts.1", "nats": "^2.28.0", + "nats.ws": "^1.29.2", "nested-objects-util": "^1.1.2", "objection": "^3.0.1", "pg": "^8.10.0", "uuid": "^8.3.2", + "websocket": "^1.0.35", "winston": "^3.8.2" }, "devDependencies": { diff --git a/app/src/components/eventStreamService.js b/app/src/components/eventStreamService.js index 77fe9f1f3..22b68b0ae 100644 --- a/app/src/components/eventStreamService.js +++ b/app/src/components/eventStreamService.js @@ -1,5 +1,8 @@ const config = require('config'); -const nats = require('nats'); + +// shim the websocket library +globalThis.WebSocket = require('websocket').w3cwebsocket; +const { connect } = require('nats.ws'); const log = require('./log')(module.filename); const { FormVersion, Form, FormEventStreamConfig } = require('../forms/common/models'); @@ -95,7 +98,7 @@ class EventStreamService { if (this.connected) return this.nc; const me = this; - const connect = async function () { + const connectToNats = async function () { // nats.connect will throw errors only if the server is running. // nats.connect will NOT timeout if the server isn't reachable/not started. // so, let's wait twice the reconnect time and create our own timeout. @@ -108,7 +111,7 @@ class EventStreamService { }); // we either timeout or connect... - const result = await Promise.race([nats.connect(me.natsOptions), timeoutPromise]); + const result = await Promise.race([connect(me.natsOptions), timeoutPromise]); if (timeout) { clearTimeout(timeout); @@ -116,7 +119,7 @@ class EventStreamService { return result; }; - this.nc = await connect(); + this.nc = await connectToNats(); if (this.connected) { log.info('Connected', { function: 'openConnection' }); this.js = this.nc.jetstream(); diff --git a/event-stream-service/charts/event-stream-service/.helmignore b/event-stream-service/charts/event-stream-service/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/event-stream-service/charts/event-stream-service/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/event-stream-service/charts/event-stream-service/Chart.lock b/event-stream-service/charts/event-stream-service/Chart.lock new file mode 100644 index 000000000..14b51eee4 --- /dev/null +++ b/event-stream-service/charts/event-stream-service/Chart.lock @@ -0,0 +1,12 @@ +dependencies: +- name: common + repository: oci://registry-1.docker.io/bitnamicharts + version: 2.22.0 +- name: nats + repository: https://nats-io.github.io/k8s/helm/charts/ + version: 1.2.3 +- name: nginx + repository: oci://registry-1.docker.io/bitnamicharts + version: 18.1.11 +digest: sha256:479bc3fa8ee522090462f19f6e9fb7daa0736b1e0d0f57d268774e39bf498ae8 +generated: "2024-08-30T13:26:19.066946-07:00" diff --git a/event-stream-service/charts/event-stream-service/Chart.yaml b/event-stream-service/charts/event-stream-service/Chart.yaml new file mode 100644 index 000000000..ea9e2830d --- /dev/null +++ b/event-stream-service/charts/event-stream-service/Chart.yaml @@ -0,0 +1,38 @@ +apiVersion: v2 +name: event-stream-service +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" + +dependencies: + - name: common + version: 2.22.0 + repository: oci://registry-1.docker.io/bitnamicharts + alias: common + - name: nats + repository: https://nats-io.github.io/k8s/helm/charts/ + version: 1.2.3 + alias: nats + - name: nginx + version: 18.1.11 + repository: oci://registry-1.docker.io/bitnamicharts + alias: nginx diff --git a/event-stream-service/charts/event-stream-service/README b/event-stream-service/charts/event-stream-service/README new file mode 100644 index 000000000..ddfc1582a --- /dev/null +++ b/event-stream-service/charts/event-stream-service/README @@ -0,0 +1,3 @@ +helm upgrade --install event-stream-service ./charts/event-stream-service -f ./charts/event-stream-service/values.yaml +helm uninstall event-stream-service +oc delete pvc -l 'app.kubernetes.io/instance=event-stream-service' diff --git a/event-stream-service/charts/event-stream-service/charts/common-2.22.0.tgz b/event-stream-service/charts/event-stream-service/charts/common-2.22.0.tgz new file mode 100644 index 000000000..17f5674c0 Binary files /dev/null and b/event-stream-service/charts/event-stream-service/charts/common-2.22.0.tgz differ diff --git a/event-stream-service/charts/event-stream-service/charts/nats-1.2.3.tgz b/event-stream-service/charts/event-stream-service/charts/nats-1.2.3.tgz new file mode 100644 index 000000000..b83f0d89e Binary files /dev/null and b/event-stream-service/charts/event-stream-service/charts/nats-1.2.3.tgz differ diff --git a/event-stream-service/charts/event-stream-service/charts/nginx-18.1.11.tgz b/event-stream-service/charts/event-stream-service/charts/nginx-18.1.11.tgz new file mode 100644 index 000000000..d73ea7443 Binary files /dev/null and b/event-stream-service/charts/event-stream-service/charts/nginx-18.1.11.tgz differ diff --git a/event-stream-service/charts/event-stream-service/templates/NOTES.txt b/event-stream-service/charts/event-stream-service/templates/NOTES.txt new file mode 100644 index 000000000..ffd55e71d --- /dev/null +++ b/event-stream-service/charts/event-stream-service/templates/NOTES.txt @@ -0,0 +1,5 @@ +You have deployed the following: +Release: {{ include "common.names.fullname" . }} +Namespace: {{ include "common.names.namespace" . | quote}} + + diff --git a/event-stream-service/charts/event-stream-service/templates/_helpers.tpl b/event-stream-service/charts/event-stream-service/templates/_helpers.tpl new file mode 100644 index 000000000..4fa9f5dfc --- /dev/null +++ b/event-stream-service/charts/event-stream-service/templates/_helpers.tpl @@ -0,0 +1,7 @@ +{{- define "nginx.openshift.route.tls" -}} +{{- if (.Values.ess.nginx.route.tls.enabled) -}} +tls: + insecureEdgeTerminationPolicy: {{ .Values.ess.nginx.route.tls.insecureEdgeTerminationPolicy }} + termination: {{ .Values.ess.nginx.route.tls.termination }} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/event-stream-service/charts/event-stream-service/templates/nats-secrets.yaml b/event-stream-service/charts/event-stream-service/templates/nats-secrets.yaml new file mode 100644 index 000000000..bda0625bb --- /dev/null +++ b/event-stream-service/charts/event-stream-service/templates/nats-secrets.yaml @@ -0,0 +1,18 @@ +{{- $secretName := (.Values.ess.nats.secret.name) }} +{{- $adminPwdValue := randAlphaNum 32 | b64enc }} +{{- $anonymousPwdValue := randAlphaNum 32 | b64enc }} +{{- $chefsPwdValue := randAlphaNum 32 | b64enc }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ $secretName }} + namespace: {{ include "common.names.namespace" . | quote }} + labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} + {{- if .Values.commonAnnotations }} + annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} + {{- end }} +data: + admin_pwd: {{ include "common.secrets.lookup" (dict "secret" $secretName "key" "admin_pwd" "defaultValue" $adminPwdValue "context" $) }} + anonymous_pwd: {{ include "common.secrets.lookup" (dict "secret" $secretName "key" "anonymous_pwd" "defaultValue" $anonymousPwdValue "context" $) }} + chefs_pwd: {{ include "common.secrets.lookup" (dict "secret" $secretName "key" "chefs_pwd" "defaultValue" $chefsPwdValue "context" $) }} + \ No newline at end of file diff --git a/event-stream-service/charts/event-stream-service/templates/nginx-route.yaml b/event-stream-service/charts/event-stream-service/templates/nginx-route.yaml new file mode 100644 index 000000000..82642225f --- /dev/null +++ b/event-stream-service/charts/event-stream-service/templates/nginx-route.yaml @@ -0,0 +1,22 @@ +{{- if .Values.ess.nginx.route.enabled -}} +{{- $routeName := (.Values.ess.nginx.route.name) }} +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: {{ $routeName }} + namespace: {{ include "common.names.namespace" . | quote }} + labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} + annotations: + haproxy.router.openshift.io/timeout: {{ .Values.ess.nginx.route.timeout }} +spec: + host: {{ .Values.ess.nginx.route.ingressPrefix }}{{ .Values.ess.nginx.route.ingressSuffix }} + path: {{ .Values.ess.nginx.route.path }} + to: + kind: Service + name: {{ .Values.ess.nginx.route.serviceName }} + weight: 100 + port: + targetPort: {{ .Values.ess.nginx.route.targetPort }} + wildcardPolicy: {{ .Values.ess.nginx.route.wildcardPolicy }} +{{ include "nginx.openshift.route.tls" . | indent 2}} +{{- end -}} \ No newline at end of file diff --git a/event-stream-service/charts/event-stream-service/values.yaml b/event-stream-service/charts/event-stream-service/values.yaml new file mode 100644 index 000000000..1098fa171 --- /dev/null +++ b/event-stream-service/charts/event-stream-service/values.yaml @@ -0,0 +1,204 @@ +ess: + nats: + secret: + name: ess-nats-auth + nginx: + route: + name: ess-nginx-route + enabled: true + ingressPrefix: ess- + ingressSuffix: a191b5-dev.apps.silver.devops.gov.bc.ca + path: "" + serviceName: ess-nginx + targetPort: http + timeout: 2m + tls: + enabled: true + insecureEdgeTerminationPolicy: None + termination: edge + wildcardPolicy: None + +nats: + fullnameOverride: ess-nats + config: + cluster: + enabled: true + replicas: 2 + jetstream: + enabled: true + fileStore: + enabled: true + pvc: + enabled: true + size: 250Mi + websocket: + enabled: true + port: 8888 + merge: + authorization: + default_permissions: + publish: + [ + "SANDBOX.*", + "$JS.API.INFO", + "$JS.API.CONSUMER.CREATE.*", + "$JS.API.CONSUMER.CREATE.*.>", + "$JS.API.CONSUMER.DURABLE.CREATE.*.>", + "$JS.API.CONSUMER.DELETE.*.>", + "$JS.API.CONSUMER.INFO.*.>", + "$JS.API.CONSUMER.LIST.*", + "$JS.API.CONSUMER.NAMES.*", + "$JS.API.CONSUMER.MSG.NEXT.*.>", + "$JS.API.CONSUMER.MSG.NEXT.*.NEW", + "$JS.API.STREAM.MSG.GET.*", + "$JS.API.STREAM.INFO.*", + "$JS.API.STREAM.NAMES", + "$JS.ACK.*", + "$JS.ACK.*.>", + ] + subscribe: ["PUBLIC.>", "PRIVATE.>", "_INBOX.>"] + users: + - user: "anonymous" + password: << $ANONYMOUS_PWD >> + - user: "admin" + password: << $ADMIN_PWD >> + permissions: + publish: [">"] + subscribe: [">"] + - user: "chefs" + password: << $CHEFS_PWD >> + permissions: + publish: + [ + "$JS.API.INFO", + "$JS.API.STREAM.CREATE.CHEFS", + "$JS.API.STREAM.UPDATE.CHEFS", + "$JS.API.STREAM.DELETE.CHEFS", + "$JS.API.STREAM.INFO.CHEFS", + "$JS.API.STREAM.PURGE.CHEFS", + "$JS.API.STREAM.LIST", + "$JS.API.STREAM.NAMES", + "$JS.API.STREAM.MSG.DELETE.CHEFS", + "$JS.API.STREAM.MSG.GET.CHEFS", + "$JS.API.STREAM.SNAPSHOT.CHEFS", + "$JS.API.STREAM.RESTORE.CHEFS", + "$JS.API.CONSUMER.CREATE.CHEFS", + "$JS.API.CONSUMER.CREATE.CHEFS.>", + "$JS.API.CONSUMER.DURABLE.CREATE.CHEFS.>", + "$JS.API.CONSUMER.DELETE.CHEFS.>", + "$JS.API.CONSUMER.INFO.CHEFS.>", + "$JS.API.CONSUMER.LIST.CHEFS", + "$JS.API.CONSUMER.NAMES.CHEFS", + "$JS.API.CONSUMER.MSG.NEXT.CHEFS.>", + "$JS.API.CONSUMER.MSG.NEXT.CHEFS.NEW", + "$JS.API.STREAM.MSG.GET.CHEFS", + "$JS.ACK.CHEFS.>", + "PUBLIC.forms.>", + "PRIVATE.forms.>", + ] + subscribe: ["_INBOX.>"] + no_auth_user: anonymous + 01$include: params.conf + container: + env: + ADMIN_PWD: + valueFrom: + secretKeyRef: + name: ess-nats-auth + key: admin_pwd + CHEFS_PWD: + valueFrom: + secretKeyRef: + name: ess-nats-auth + key: chefs_pwd + ANONYMOUS_PWD: + valueFrom: + secretKeyRef: + name: ess-nats-auth + key: anonymous_pwd + merge: + resources: + limits: + cpu: 250m + memory: 128Mi + requests: + cpu: 50m + memory: 64Mi + service: + ports: + nats: + enabled: true + leafnodes: + enabled: false + websocket: + enabled: true + mqtt: + enabled: false + cluster: + enabled: true + gateway: + enabled: false + monitor: + enabled: false + profiling: + enabled: false + podTemplate: + topologySpreadConstraints: + kubernetes.io/hostname: + maxSkew: 1 + whenUnsatisfiable: DoNotSchedule + configMap: + merge: + data: + params.conf: | + max_payload: 2MB + natsBox: + container: + image: + tag: nonroot + merge: + resources: + limits: + cpu: 250m + memory: 128Mi + requests: + cpu: 50m + memory: 64Mi + +nginx: + fullnameOverride: ess-nginx + readinessProbe: + enabled: true + path: /health + resourcesPreset: "nano" + service: + type: ClusterIP + ports: + http: 8080 + https: 8443 + extraPorts: + tls: + enabled: true + serverBlock: |- + server { + listen 8080; + listen [::]:8080; + server_name localhost; + + location / { + proxy_pass http://ess-nats:8888; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /health { + default_type application/json; + return 200 '{"message": "healthy"}'; + } + + } diff --git a/event-stream-service/package-lock.json b/event-stream-service/package-lock.json index db4417a7c..6747ed9c3 100644 --- a/event-stream-service/package-lock.json +++ b/event-stream-service/package-lock.json @@ -10,7 +10,21 @@ "license": "Apache-2.0", "dependencies": { "cryptr": "^6.3.0", - "nats": "^2.28.0" + "nats": "^2.28.0", + "nats.ws": "^1.29.2", + "websocket": "^1.0.35" + } + }, + "node_modules/bufferutil": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz", + "integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==", + "hasInstallScript": true, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=6.14.2" } }, "node_modules/cryptr": { @@ -18,10 +32,108 @@ "resolved": "https://registry.npmjs.org/cryptr/-/cryptr-6.3.0.tgz", "integrity": "sha512-TA4byAuorT8qooU9H8YJhBwnqD151i1rcauHfJ3Divg6HmukHB2AYMp0hmjv2873J2alr4t15QqC7zAnWFrtfQ==" }, + "node_modules/d": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", + "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", + "dependencies": { + "es5-ext": "^0.10.64", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.12" + } + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/es5-ext": { + "version": "0.10.64", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", + "hasInstallScript": true, + "dependencies": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", + "next-tick": "^1.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", + "dependencies": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, + "node_modules/es6-symbol": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", + "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", + "dependencies": { + "d": "^1.0.2", + "ext": "^1.7.0" + }, + "engines": { + "node": ">=0.12" + } + }, + "node_modules/esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "dependencies": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, + "node_modules/ext": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", + "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", + "dependencies": { + "type": "^2.7.2" + } + }, + "node_modules/is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==" + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, "node_modules/nats": { - "version": "2.28.0", - "resolved": "https://registry.npmjs.org/nats/-/nats-2.28.0.tgz", - "integrity": "sha512-zXWOTOZEizUQy8UO2lMYFAee0htGrZLmJ2sddfmsDI00nc+dsK5+gS7p7bt26O1omfdCLVU5xymlnAjaqYnOmw==", + "version": "2.28.2", + "resolved": "https://registry.npmjs.org/nats/-/nats-2.28.2.tgz", + "integrity": "sha512-02cvR8EPach+0BfVaQjPgsbPFn6uMjEQAuvXS2ppg8jiWEm2KYdfmeFmtshiU9b2+kFh3LSEKMEaIfRgk3K8tw==", "dependencies": { "nkeys.js": "1.1.0" }, @@ -29,6 +141,19 @@ "node": ">= 14.0.0" } }, + "node_modules/nats.ws": { + "version": "1.29.2", + "resolved": "https://registry.npmjs.org/nats.ws/-/nats.ws-1.29.2.tgz", + "integrity": "sha512-dJf7aWp+5+8LwWEhgoTMc3pvfz5JlhA0yWtXKcTMDxUe43mHvgpvDaPnLyHQNL2LoDpdkjgOG176i5IeHBDlqg==", + "optionalDependencies": { + "nkeys.js": "1.1.0" + } + }, + "node_modules/next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, "node_modules/nkeys.js": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/nkeys.js/-/nkeys.js-1.1.0.tgz", @@ -40,10 +165,69 @@ "node": ">=10.0.0" } }, + "node_modules/node-gyp-build": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "node_modules/type": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz", + "integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==" + }, + "node_modules/typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "dependencies": { + "is-typedarray": "^1.0.0" + } + }, + "node_modules/utf-8-validate": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", + "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==", + "hasInstallScript": true, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=6.14.2" + } + }, + "node_modules/websocket": { + "version": "1.0.35", + "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.35.tgz", + "integrity": "sha512-/REy6amwPZl44DDzvRCkaI1q1bIiQB0mEFQLUrhz3z2EK91cp3n72rAjUlrTP0zV22HJIUOVHQGPxhFRjxjt+Q==", + "dependencies": { + "bufferutil": "^4.0.1", + "debug": "^2.2.0", + "es5-ext": "^0.10.63", + "typedarray-to-buffer": "^3.1.5", + "utf-8-validate": "^5.0.2", + "yaeti": "^0.0.6" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/yaeti": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz", + "integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==", + "engines": { + "node": ">=0.10.32" + } } } } diff --git a/event-stream-service/package.json b/event-stream-service/package.json index 836c7a8e4..d94fca715 100644 --- a/event-stream-service/package.json +++ b/event-stream-service/package.json @@ -6,6 +6,8 @@ "scripts": {}, "dependencies": { "cryptr": "^6.3.0", - "nats": "^2.28.0" + "nats": "^2.28.0", + "nats.ws": "^1.29.2", + "websocket": "^1.0.35" } } diff --git a/event-stream-service/pullConsumer.js b/event-stream-service/pullConsumer.js index 44cde7146..c23984be4 100644 --- a/event-stream-service/pullConsumer.js +++ b/event-stream-service/pullConsumer.js @@ -1,8 +1,12 @@ -const { AckPolicy, connect } = require("nats"); +const { AckPolicy } = require("nats"); const Cryptr = require("cryptr"); +// shim the websocket library +globalThis.WebSocket = require("websocket").w3cwebsocket; +const { connect } = require("nats.ws"); + // connection info -const servers = ["localhost:4222", "localhost:4223", "localhost:4224"]; +const servers = ["ess-a191b5-dev.apps.silver.devops.gov.bc.ca"]; //["localhost:4222", "localhost:4223", "localhost:4224"]; let nc = undefined; // nats connection let js = undefined; // jet stream @@ -14,7 +18,8 @@ const STREAM_NAME = "CHEFS"; const FILTER_SUBJECTS = ["PUBLIC.forms.>", "PRIVATE.forms.>"]; const MAX_MESSAGES = 2; const DURABLE_NAME = "pullConsumer"; -const ENCRYPTION_KEY = ""; +const ENCRYPTION_KEY = + "ad5520469720325d1694c87511afda28a0432dd974cb77b5b4b9f946a5af6985"; const printMsg = (m) => { // illustrate grabbing the sequence and timestamp from the nats message... @@ -27,13 +32,20 @@ const printMsg = (m) => { const data = m.json(); console.log(JSON.stringify(data, null, 2)); try { - if (data && data["payload"] && data["payload"]["data"]) { + if ( + data && + data["payload"] && + data["payload"]["data"] && + ENCRYPTION_KEY + ) { const cryptr = new Cryptr(ENCRYPTION_KEY); - const d = cryptr.decrypt(data["payload"]["data"]); - console.log(JSON.stringify(d, null, 2)); + const decryptedData = cryptr.decrypt(data["payload"]["data"]); + const jsonData = JSON.parse(decryptedData); + console.log("decrypted payload data:"); + console.log(jsonData); } } catch (err) { - console.error("Error decrypting payload.data"); + console.error("Error decrypting payload.data", err); } } catch (e) { console.error(`Error printing message: ${e.message}`);