diff --git a/.gitignore b/.gitignore index 9b2ed79f9..9a2f7ecc1 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,5 @@ vitest-coverage/ *.vitest.log test-output.txt server/job/test/fixtures + +.github diff --git a/_reference/localEmailViewer/package-lock.json b/_reference/localEmailViewer/package-lock.json index d8d53da2e..ae14abb19 100644 --- a/_reference/localEmailViewer/package-lock.json +++ b/_reference/localEmailViewer/package-lock.json @@ -9,8 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "express": "^4.21.1", - "mailparser": "^3.7.1", + "express": "^5.1.0", + "mailparser": "^3.7.2", "node-fetch": "^3.3.2" } }, @@ -28,46 +28,36 @@ } }, "node_modules/accepts": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", - "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", "license": "MIT", "dependencies": { - "mime-types": "~2.1.34", - "negotiator": "0.6.3" + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" }, "engines": { "node": ">= 0.6" } }, - "node_modules/array-flatten": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", - "license": "MIT" - }, "node_modules/body-parser": { - "version": "1.20.3", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", - "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz", + "integrity": "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg==", "license": "MIT", "dependencies": { - "bytes": "3.1.2", - "content-type": "~1.0.5", - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "1.2.0", - "http-errors": "2.0.0", - "iconv-lite": "0.4.24", - "on-finished": "2.4.1", - "qs": "6.13.0", - "raw-body": "2.5.2", - "type-is": "~1.6.18", - "unpipe": "1.0.0" + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.0", + "http-errors": "^2.0.0", + "iconv-lite": "^0.6.3", + "on-finished": "^2.4.1", + "qs": "^6.14.0", + "raw-body": "^3.0.0", + "type-is": "^2.0.0" }, "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" + "node": ">=18" } }, "node_modules/bytes": { @@ -79,17 +69,27 @@ "node": ">= 0.8" } }, - "node_modules/call-bind": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", - "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", "license": "MIT", "dependencies": { - "es-define-property": "^1.0.0", "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.4", - "set-function-length": "^1.2.1" + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" }, "engines": { "node": ">= 0.4" @@ -99,9 +99,9 @@ } }, "node_modules/content-disposition": { - "version": "0.5.4", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", - "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.0.tgz", + "integrity": "sha512-Au9nRL8VNUut/XSzbQA38+M78dzP4D+eqg3gfJHMIHHYa3bg067xj1KxMUWj+VULbiZMowKngFFbKczUrNJ1mg==", "license": "MIT", "dependencies": { "safe-buffer": "5.2.1" @@ -129,10 +129,13 @@ } }, "node_modules/cookie-signature": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", - "license": "MIT" + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } }, "node_modules/data-uri-to-buffer": { "version": "4.0.1", @@ -144,12 +147,20 @@ } }, "node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { - "ms": "2.0.0" + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } } }, "node_modules/deepmerge": { @@ -161,23 +172,6 @@ "node": ">=0.10.0" } }, - "node_modules/define-data-property": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", - "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", - "license": "MIT", - "dependencies": { - "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "gopd": "^1.0.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -187,16 +181,6 @@ "node": ">= 0.8" } }, - "node_modules/destroy": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", - "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", - "license": "MIT", - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, "node_modules/dom-serializer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", @@ -252,6 +236,20 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -268,9 +266,9 @@ } }, "node_modules/encoding-japanese": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/encoding-japanese/-/encoding-japanese-2.1.0.tgz", - "integrity": "sha512-58XySVxUgVlBikBTbQ8WdDxBDHIdXucB16LO5PBHR8t75D54wQrNo4cg+58+R1CtJfKnsVsvt9XlteRaR8xw1w==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/encoding-japanese/-/encoding-japanese-2.2.0.tgz", + "integrity": "sha512-EuJWwlHPZ1LbADuKTClvHtwbaFn4rOD+dRAbWysqEOXRc2Uui0hJInNJrsdH0c+OhJA4nrCBdSkW4DD5YxAo6A==", "license": "MIT", "engines": { "node": ">=8.10.0" @@ -289,13 +287,10 @@ } }, "node_modules/es-define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", - "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", "license": "MIT", - "dependencies": { - "get-intrinsic": "^1.2.4" - }, "engines": { "node": ">= 0.4" } @@ -309,6 +304,18 @@ "node": ">= 0.4" } }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -325,45 +332,45 @@ } }, "node_modules/express": { - "version": "4.21.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz", - "integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz", + "integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==", "license": "MIT", "dependencies": { - "accepts": "~1.3.8", - "array-flatten": "1.1.1", - "body-parser": "1.20.3", - "content-disposition": "0.5.4", - "content-type": "~1.0.4", - "cookie": "0.7.1", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "2.0.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "1.3.1", - "fresh": "0.5.2", - "http-errors": "2.0.0", - "merge-descriptors": "1.0.3", - "methods": "~1.1.2", - "on-finished": "2.4.1", - "parseurl": "~1.3.3", - "path-to-regexp": "0.1.10", - "proxy-addr": "~2.0.7", - "qs": "6.13.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.2.1", - "send": "0.19.0", - "serve-static": "1.16.2", - "setprototypeof": "1.2.0", - "statuses": "2.0.1", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" + "accepts": "^2.0.0", + "body-parser": "^2.2.0", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" }, "engines": { - "node": ">= 0.10.0" + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/fetch-blob": { @@ -390,18 +397,17 @@ } }, "node_modules/finalhandler": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz", - "integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz", + "integrity": "sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q==", "license": "MIT", "dependencies": { - "debug": "2.6.9", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "on-finished": "2.4.1", - "parseurl": "~1.3.3", - "statuses": "2.0.1", - "unpipe": "~1.0.0" + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" }, "engines": { "node": ">= 0.8" @@ -429,12 +435,12 @@ } }, "node_modules/fresh": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", "license": "MIT", "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, "node_modules/function-bind": { @@ -447,16 +453,21 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", - "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "license": "MIT", "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3", - "hasown": "^2.0.0" + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" }, "engines": { "node": ">= 0.4" @@ -465,34 +476,23 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/gopd": { + "node_modules/get-proto": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", "license": "MIT", "dependencies": { - "get-intrinsic": "^1.1.3" + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "engines": { + "node": ">= 0.4" } }, - "node_modules/has-property-descriptors": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", - "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", - "license": "MIT", - "dependencies": { - "es-define-property": "^1.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-proto": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", - "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", "license": "MIT", "engines": { "node": ">= 0.4" @@ -502,9 +502,9 @@ } }, "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", "license": "MIT", "engines": { "node": ">= 0.4" @@ -586,12 +586,12 @@ } }, "node_modules/iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "license": "MIT", "dependencies": { - "safer-buffer": ">= 2.1.2 < 3" + "safer-buffer": ">= 2.1.2 < 3.0.0" }, "engines": { "node": ">=0.10.0" @@ -612,6 +612,12 @@ "node": ">= 0.10" } }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, "node_modules/leac": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/leac/-/leac-0.6.0.tgz", @@ -628,33 +634,21 @@ "license": "MIT" }, "node_modules/libmime": { - "version": "5.3.5", - "resolved": "https://registry.npmjs.org/libmime/-/libmime-5.3.5.tgz", - "integrity": "sha512-nSlR1yRZ43L3cZCiWEw7ali3jY29Hz9CQQ96Oy+sSspYnIP5N54ucOPHqooBsXzwrX1pwn13VUE05q4WmzfaLg==", + "version": "5.3.6", + "resolved": "https://registry.npmjs.org/libmime/-/libmime-5.3.6.tgz", + "integrity": "sha512-j9mBC7eiqi6fgBPAGvKCXJKJSIASanYF4EeA4iBzSG0HxQxmXnR3KbyWqTn4CwsKSebqCv2f5XZfAO6sKzgvwA==", "license": "MIT", "dependencies": { - "encoding-japanese": "2.1.0", + "encoding-japanese": "2.2.0", "iconv-lite": "0.6.3", "libbase64": "1.3.0", - "libqp": "2.1.0" - } - }, - "node_modules/libmime/node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" + "libqp": "2.1.1" } }, "node_modules/libqp": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/libqp/-/libqp-2.1.0.tgz", - "integrity": "sha512-O6O6/fsG5jiUVbvdgT7YX3xY3uIadR6wEZ7+vy9u7PKHAlSEB6blvC1o5pHBjgsi95Uo0aiBBdkyFecj6jtb7A==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/libqp/-/libqp-2.1.1.tgz", + "integrity": "sha512-0Wd+GPz1O134cP62YU2GTOPNA7Qgl09XwCqM5zpBv87ERCXdfDtyKXvV7c9U22yWJh44QZqBocFnXN11K96qow==", "license": "MIT" }, "node_modules/linkify-it": { @@ -667,161 +661,95 @@ } }, "node_modules/mailparser": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/mailparser/-/mailparser-3.7.1.tgz", - "integrity": "sha512-RCnBhy5q8XtB3mXzxcAfT1huNqN93HTYYyL6XawlIKycfxM/rXPg9tXoZ7D46+SgCS1zxKzw+BayDQSvncSTTw==", + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/mailparser/-/mailparser-3.7.2.tgz", + "integrity": "sha512-iI0p2TCcIodR1qGiRoDBBwboSSff50vQAWytM5JRggLfABa4hHYCf3YVujtuzV454xrOP352VsAPIzviqMTo4Q==", "license": "MIT", "dependencies": { - "encoding-japanese": "2.1.0", + "encoding-japanese": "2.2.0", "he": "1.2.0", "html-to-text": "9.0.5", "iconv-lite": "0.6.3", - "libmime": "5.3.5", + "libmime": "5.3.6", "linkify-it": "5.0.0", - "mailsplit": "5.4.0", - "nodemailer": "6.9.13", + "mailsplit": "5.4.2", + "nodemailer": "6.9.16", "punycode.js": "2.3.1", - "tlds": "1.252.0" - } - }, - "node_modules/mailparser/node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" + "tlds": "1.255.0" } }, "node_modules/mailsplit": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/mailsplit/-/mailsplit-5.4.0.tgz", - "integrity": "sha512-wnYxX5D5qymGIPYLwnp6h8n1+6P6vz/MJn5AzGjZ8pwICWssL+CCQjWBIToOVHASmATot4ktvlLo6CyLfOXWYA==", + "version": "5.4.2", + "resolved": "https://registry.npmjs.org/mailsplit/-/mailsplit-5.4.2.tgz", + "integrity": "sha512-4cczG/3Iu3pyl8JgQ76dKkisurZTmxMrA4dj/e8d2jKYcFTZ7MxOzg1gTioTDMPuFXwTrVuN/gxhkrO7wLg7qA==", "license": "(MIT OR EUPL-1.1+)", "dependencies": { - "libbase64": "1.2.1", - "libmime": "5.2.0", - "libqp": "2.0.1" + "libbase64": "1.3.0", + "libmime": "5.3.6", + "libqp": "2.1.1" } }, - "node_modules/mailsplit/node_modules/encoding-japanese": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/encoding-japanese/-/encoding-japanese-2.0.0.tgz", - "integrity": "sha512-++P0RhebUC8MJAwJOsT93dT+5oc5oPImp1HubZpAuCZ5kTLnhuuBhKHj2jJeO/Gj93idPBWmIuQ9QWMe5rX3pQ==", + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", "license": "MIT", "engines": { - "node": ">=8.10.0" + "node": ">= 0.4" } }, - "node_modules/mailsplit/node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/mailsplit/node_modules/libbase64": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/libbase64/-/libbase64-1.2.1.tgz", - "integrity": "sha512-l+nePcPbIG1fNlqMzrh68MLkX/gTxk/+vdvAb388Ssi7UuUN31MI44w4Yf33mM3Cm4xDfw48mdf3rkdHszLNew==", - "license": "MIT" - }, - "node_modules/mailsplit/node_modules/libmime": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/libmime/-/libmime-5.2.0.tgz", - "integrity": "sha512-X2U5Wx0YmK0rXFbk67ASMeqYIkZ6E5vY7pNWRKtnNzqjvdYYG8xtPDpCnuUEnPU9vlgNev+JoSrcaKSUaNvfsw==", - "license": "MIT", - "dependencies": { - "encoding-japanese": "2.0.0", - "iconv-lite": "0.6.3", - "libbase64": "1.2.1", - "libqp": "2.0.1" - } - }, - "node_modules/mailsplit/node_modules/libqp": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/libqp/-/libqp-2.0.1.tgz", - "integrity": "sha512-Ka0eC5LkF3IPNQHJmYBWljJsw0UvM6j+QdKRbWyCdTmYwvIDE6a7bCm0UkTAL/K+3KXK5qXT/ClcInU01OpdLg==", - "license": "MIT" - }, "node_modules/media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", "license": "MIT", "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, "node_modules/merge-descriptors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", - "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", "license": "MIT", + "engines": { + "node": ">=18" + }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", - "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", - "license": "MIT", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", "license": "MIT", "engines": { "node": ">= 0.6" } }, "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz", + "integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==", "license": "MIT", "dependencies": { - "mime-db": "1.52.0" + "mime-db": "^1.54.0" }, "engines": { "node": ">= 0.6" } }, "node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, "node_modules/negotiator": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", - "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", "license": "MIT", "engines": { "node": ">= 0.6" @@ -865,18 +793,18 @@ } }, "node_modules/nodemailer": { - "version": "6.9.13", - "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.13.tgz", - "integrity": "sha512-7o38Yogx6krdoBf3jCAqnIN4oSQFx+fMa0I7dK1D+me9kBxx12D+/33wSb+fhOCtIxvYJ+4x4IMEhmhCKfAiOA==", + "version": "6.9.16", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.16.tgz", + "integrity": "sha512-psAuZdTIRN08HKVd/E8ObdV6NO7NTBY3KsC30F7M4H1OnmLCUNaS56FpYxyb26zWLSyYF9Ozch9KYHhHegsiOQ==", "license": "MIT-0", "engines": { "node": ">=6.0.0" } }, "node_modules/object-inspect": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", - "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", "license": "MIT", "engines": { "node": ">= 0.4" @@ -897,6 +825,15 @@ "node": ">= 0.8" } }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, "node_modules/parseley": { "version": "0.12.1", "resolved": "https://registry.npmjs.org/parseley/-/parseley-0.12.1.tgz", @@ -920,10 +857,13 @@ } }, "node_modules/path-to-regexp": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.10.tgz", - "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==", - "license": "MIT" + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", + "integrity": "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==", + "license": "MIT", + "engines": { + "node": ">=16" + } }, "node_modules/peberminta": { "version": "0.9.0", @@ -957,12 +897,12 @@ } }, "node_modules/qs": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", - "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==", "license": "BSD-3-Clause", "dependencies": { - "side-channel": "^1.0.6" + "side-channel": "^1.1.0" }, "engines": { "node": ">=0.6" @@ -981,20 +921,36 @@ } }, "node_modules/raw-body": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", - "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.0.tgz", + "integrity": "sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==", "license": "MIT", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", - "iconv-lite": "0.4.24", + "iconv-lite": "0.6.3", "unpipe": "1.0.0" }, "engines": { "node": ">= 0.8" } }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1034,74 +990,40 @@ } }, "node_modules/send": { - "version": "0.19.0", - "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", - "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.0.tgz", + "integrity": "sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw==", "license": "MIT", "dependencies": { - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "1.2.0", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "fresh": "0.5.2", - "http-errors": "2.0.0", - "mime": "1.6.0", - "ms": "2.1.3", - "on-finished": "2.4.1", - "range-parser": "~1.2.1", - "statuses": "2.0.1" + "debug": "^4.3.5", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "mime-types": "^3.0.1", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.1" }, "engines": { - "node": ">= 0.8.0" + "node": ">= 18" } }, - "node_modules/send/node_modules/encodeurl": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/send/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT" - }, "node_modules/serve-static": { - "version": "1.16.2", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", - "integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-61g9pCh0Vnh7IutZjtLGGpTA355+OPn2TyDv/6ivP2h/AdAVX9azsoxmg2/M6nZeQZNYBEwIcsne1mJd9oQItQ==", "license": "MIT", "dependencies": { - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "parseurl": "~1.3.3", - "send": "0.19.0" + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" }, "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/set-function-length": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", - "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", - "license": "MIT", - "dependencies": { - "define-data-property": "^1.1.4", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.4", - "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" + "node": ">= 18" } }, "node_modules/setprototypeof": { @@ -1111,15 +1033,69 @@ "license": "ISC" }, "node_modules/side-channel": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", - "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", "license": "MIT", "dependencies": { - "call-bind": "^1.0.7", "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.4", - "object-inspect": "^1.13.1" + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" }, "engines": { "node": ">= 0.4" @@ -1138,9 +1114,9 @@ } }, "node_modules/tlds": { - "version": "1.252.0", - "resolved": "https://registry.npmjs.org/tlds/-/tlds-1.252.0.tgz", - "integrity": "sha512-GA16+8HXvqtfEnw/DTcwB0UU354QE1n3+wh08oFjr6Znl7ZLAeUgYzCcK+/CCrOyE0vnHR8/pu3XXG3vDijXpQ==", + "version": "1.255.0", + "resolved": "https://registry.npmjs.org/tlds/-/tlds-1.255.0.tgz", + "integrity": "sha512-tcwMRIioTcF/FcxLev8MJWxCp+GUALRhFEqbDoZrnowmKSGqPrl5pqS+Sut2m8BgJ6S4FExCSSpGffZ0Tks6Aw==", "license": "MIT", "bin": { "tlds": "bin.js" @@ -1156,13 +1132,14 @@ } }, "node_modules/type-is": { - "version": "1.6.18", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", - "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", "license": "MIT", "dependencies": { - "media-typer": "0.3.0", - "mime-types": "~2.1.24" + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" }, "engines": { "node": ">= 0.6" @@ -1183,15 +1160,6 @@ "node": ">= 0.8" } }, - "node_modules/utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", - "license": "MIT", - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -1209,6 +1177,12 @@ "engines": { "node": ">= 8" } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" } } } diff --git a/_reference/localEmailViewer/package.json b/_reference/localEmailViewer/package.json index ad795b60f..74cef99ff 100644 --- a/_reference/localEmailViewer/package.json +++ b/_reference/localEmailViewer/package.json @@ -11,8 +11,8 @@ "license": "ISC", "description": "", "dependencies": { - "express": "^4.21.1", - "mailparser": "^3.7.1", + "express": "^5.1.0", + "mailparser": "^3.7.2", "node-fetch": "^3.3.2" } } diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index d92f00f41..8969c93eb 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -1,4 +1,4 @@ - + + ${ + strings.header && + ` + + +
+ +
+
${strings.header}
+
+ ` + } + ${ + strings.subHeader && + ` + + +
+ +
+

${strings.subHeader}

+
+ ` + } - - - - - - - -
- - - - - - -
${strings.body}
-
- - - - - - - - - - -` + - end + ${ + strings.body && + ` + + + +
+ +
+ ${strings.body} +
+ + ` + } + ` + + end(strings.dateLine) ); }; diff --git a/server/email/html.js b/server/email/html.js index ec96c6ff9..79f8a9fa9 100644 --- a/server/email/html.js +++ b/server/email/html.js @@ -1,2611 +1,172 @@ -const header = ` +const InstanceManager = require("../utils/instanceMgr").default; + +const header = ` + + - - + `; +const start = ` + +
+ You have received a message from ${InstanceManager({imex: "ImEX Online", rome: "Rome Online"})}. Open to see the full contents of this email. + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  + ͏‌ ͏‌ ͏‌ ͏‌  +
+ + +
+
+ + +
 
`; -const start = `
 
`; -const end = `
 
`; + +function end(dateLine) { + return ` + + + + + + + + + +
 
+
+
+ + +`}; module.exports = { header, diff --git a/server/email/sendemail.js b/server/email/sendemail.js index 26d5c8560..0c6ce4015 100644 --- a/server/email/sendemail.js +++ b/server/email/sendemail.js @@ -40,7 +40,9 @@ const logEmail = async (req, email) => { to: req?.body?.to, cc: req?.body?.cc, subject: req?.body?.subject, - email + email, + errorMessage: error?.message, + errorStack: error?.stack // info, }); } @@ -68,6 +70,7 @@ const sendServerEmail = async ({ subject, text }) => { ] } }, + // eslint-disable-next-line no-unused-vars (err, info) => { logger.log("server-email-failure", err ? "error" : "debug", null, null, { message: err?.message, @@ -80,6 +83,108 @@ const sendServerEmail = async ({ subject, text }) => { } }; +const sendWelcomeEmail = async ({ to, resetLink, dateLine, features, bcc }) => { + try { + await mailer.sendMail({ + from: InstanceManager({ + imex: `ImEX Online `, + rome: `Rome Online ` + }), + to, + bcc, + subject: InstanceManager({ + imex: "Welcome to the ImEX Online platform.", + rome: "Welcome to the Rome Online platform." + }), + html: generateEmailTemplate({ + header: InstanceManager({ + imex: "Welcome to the ImEX Online platform.", + rome: "Welcome to the Rome Online platform." + }), + subHeader: `Your ${InstanceManager({imex: features?.allAccess ? "ImEX Online": "ImEX Lite", rome: features?.allAccess ? "RO Manager" : "RO Basic"})} shop setup has been completed, and this email will include all the information you need to begin.`, + body: ` +

To finish setting up your account, visit this link and enter your desired password. Reset Password

+ + + + + +
+ +
+

To access your ${InstanceManager({imex: features.allAccess ? "ImEX Online": "ImEX Lite", rome: features.allAccess ? "RO Manager" : "RO Basic"})} shop, visit ${InstanceManager({imex: "imex.online", rome: "romeonline.io"})}. Your username is your email, and your password is what you previously set up. Contact support for additional logins.

+
+ ${InstanceManager({ + rome: ` + + +
+ + +
+

To push estimates over from your estimating system, you must download the Web-Est EMS Unzipper & Rome Online Partner (Computers using Windows only). Here are some steps to help you get started.

+
+ +
+ + +
+ + +
+

Once you successfully set up the partner, now it's time to do some initial in-product items: Please note, an estimate must be exported from the estimating platform to use tours.

+
+ +
+ + +
+ +
+

If you need any assistance with setting up the programs, or if you want a dedicated Q&A session with one of our customer success specialists, schedule by clicking this link - Rome Basic Training Booking

+
+ + +
+ +
+

If you have additional questions or need any support, feel free to use the RO Basic support chat (blue chat box located in the bottom right corner) or give us a call at (410) 357-6700. We are here to help make your experience seamless!

+
+ ` + })} + + +
+ +
+

In addition to the training tour, you can also book a live one-on-one demo to see exactly how our system can help streamline the repair process at your shop, schedule by clicking this link - ${InstanceManager({imex: "ImEX Lite", rome: "Rome Basic"})} Demo Booking

+
+ + +
+ +
+

Thanks,

+
+ + +
+
+

The ${InstanceManager({imex: "ImEX Online", rome: "Rome Online"})} Team

+ `, + dateLine + }) + }); + } catch (error) { + logger.log("server-email-failure", "error", null, null, { error }); + } +}; + const sendTaskEmail = async ({ to, subject, type = "text", html, text, attachments }) => { try { mailer.sendMail( @@ -93,6 +198,7 @@ const sendTaskEmail = async ({ to, subject, type = "text", html, text, attachmen ...(type === "text" ? { text } : { html }), attachments: attachments || null }, + // eslint-disable-next-line no-unused-vars (err, info) => { // (message, type, user, record, meta logger.log("server-email", err ? "error" : "debug", null, null, { message: err?.message, stack: err?.stack }); @@ -143,22 +249,20 @@ const sendEmail = async (req, res) => { to: req.body.to, cc: req.body.cc, subject: req.body.subject, - attachments: - [ - ...((req.body.attachments && - req.body.attachments.map((a) => { - return { - filename: a.filename, - path: a.path - }; - })) || - []), - ...downloadedMedia.map((a) => { + attachments: [ + ...(req.body.attachments && + req.body.attachments.map((a) => { return { - path: a + filename: a.filename, + path: a.path }; - }) - ] || null, + })), + ...downloadedMedia.map((a) => { + return { + path: a + }; + }) + ], html: isObject(req.body?.templateStrings) ? generateEmailTemplate(req.body.templateStrings) : req.body.html, ses: { // optional extra arguments for SendRawEmail @@ -273,6 +377,7 @@ ${body.bounce?.bouncedRecipients.map( )} ` }, + // eslint-disable-next-line no-unused-vars (err, info) => { logger.log("sns-error", err ? "error" : "debug", "api", null, { errorMessage: err?.message, @@ -294,5 +399,6 @@ module.exports = { sendEmail, sendServerEmail, sendTaskEmail, - emailBounce + emailBounce, + sendWelcomeEmail }; diff --git a/server/email/tasksEmails.js b/server/email/tasksEmails.js index b8c3c42a3..2f434b0bc 100644 --- a/server/email/tasksEmails.js +++ b/server/email/tasksEmails.js @@ -17,11 +17,13 @@ const { formatTaskPriority } = require("../notifications/stringHelpers"); const tasksEmailQueue = taskEmailQueue(); // Cleanup function for the Tasks Email Queue +// eslint-disable-next-line no-unused-vars const tasksEmailQueueCleanup = async () => { try { // Example async operation // console.log("Performing Tasks Email Reminder process cleanup..."); await new Promise((resolve) => tasksEmailQueue.destroy(() => resolve())); + // eslint-disable-next-line no-unused-vars } catch (err) { // console.error("Tasks Email Reminder process cleanup failed:", err); } @@ -254,10 +256,15 @@ const tasksRemindEmail = async (req, res) => { header: `${allTasks.length} Tasks require your attention`, subHeader: `Please click on the Tasks below to view the Task.`, dateLine, - body: `
    + body: ` + ` diff --git a/server/firebase/firebase-handler.js b/server/firebase/firebase-handler.js index c60a04fab..83c6082eb 100644 --- a/server/firebase/firebase-handler.js +++ b/server/firebase/firebase-handler.js @@ -1,14 +1,10 @@ -const path = require("path"); -require("dotenv").config({ - path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`) -}); - -const admin = require("firebase-admin"); -const logger = require("../utils/logger"); -//const { sendProManagerWelcomeEmail } = require("../email/sendemail"); -const client = require("../graphql-client/graphql-client").client; const serviceAccount = require(process.env.FIREBASE_ADMINSDK_JSON); -//const generateEmailTemplate = require("../email/generateTemplate"); +const admin = require("firebase-admin"); +const moment = require("moment-timezone"); +const logger = require("../utils/logger"); +const client = require("../graphql-client/graphql-client").client; +const { sendWelcomeEmail } = require("../email/sendemail"); +const { GET_USER_BY_EMAIL } = require("../graphql-client/queries"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), @@ -201,6 +197,94 @@ const unsubscribe = async (req, res) => { } }; +const getWelcomeEmail = async (req, res) => { + const { authid, email, bcc } = req.body; + + try { + // Fetch user from Firebase + const userRecord = await admin.auth().getUser(authid); + if (!userRecord) { + throw { status: 404, message: "User not found in Firebase." }; + } + + // Fetch user data from the database using GraphQL + const dbUserResult = await client.request(GET_USER_BY_EMAIL, { email: email.toLowerCase() }); + + const dbUser = dbUserResult?.users?.[0]; + if (!dbUser) { + throw { status: 404, message: "User not found in database." }; + } + + // Validate email before proceeding + if (!dbUser.validemail) { + logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, { + message: "User email is not valid, skipping email.", + email + }); + return res.status(200).json({ message: "User email is not valid, email not sent." }); + } + + // Generate password reset link + const resetLink = await admin.auth().generatePasswordResetLink(dbUser.email); + + // Send welcome email + await sendWelcomeEmail({ + to: dbUser.email, + resetLink, + dateLine: moment().tz(dbUser.associations?.[0]?.bodyshop?.timezone).format("MM/DD/YYYY @ hh:mm a"), + features: dbUser.associations?.[0]?.bodyshop?.features, + bcc + }); + + // Log success and return response + logger.log("admin-send-welcome-email", "debug", req.user.email, null, { + request: req.body, + ioadmin: true, + emailSentTo: email + }); + + return res.status(200).json({ message: "Welcome email sent successfully." }); + } catch (error) { + logger.log("admin-send-welcome-email-error", "ERROR", req.user.email, null, { error }); + + if (!res.headersSent) { + return res.status(error.status || 500).json({ + message: error.message || "Error sending welcome email.", + error + }); + } + } +}; + +const getResetLink = async (req, res) => { + const { authid, email } = req.body; + logger.log("admin-reset-link", "debug", req.user.email, null, { authid, email }); + + try { + // Fetch user from Firebase + const userRecord = await admin.auth().getUser(authid); + if (!userRecord) { + throw { status: 404, message: "User not found in Firebase." }; + } + + // Generate password reset link + const resetLink = await admin.auth().generatePasswordResetLink(email); + + // Log success and return response + logger.log("admin-reset-link-success", "debug", req.user.email, null, { + request: req.body, + ioadmin: true + }); + + return res.status(200).json({ message: "Reset link generated successfully.", resetLink }); + } catch (error) { + return res.status(error.status || 500).json({ + message: error.message || "Error generating reset link.", + error + }); + } +}; + module.exports = { admin, createUser, @@ -208,23 +292,7 @@ module.exports = { getUser, sendNotification, subscribe, - unsubscribe + unsubscribe, + getWelcomeEmail, + getResetLink }; - -//Admin claims code. -// const uid = "JEqqYlsadwPEXIiyRBR55fflfko1"; - -// admin -// .auth() -// .getUser(uid) -// .then((user) => { -// console.log(user); -// admin.auth().setCustomUserClaims(uid, { -// ioadmin: true, -// "https://hasura.io/jwt/claims": { -// "x-hasura-default-role": "debug", -// "x-hasura-allowed-roles": ["admin"], -// "x-hasura-user-id": uid, -// }, -// }); -// }); diff --git a/server/graphql-client/graphql-client.js b/server/graphql-client/graphql-client.js index 069386b73..79d86315b 100644 --- a/server/graphql-client/graphql-client.js +++ b/server/graphql-client/graphql-client.js @@ -1,17 +1,19 @@ const GraphQLClient = require("graphql-request").GraphQLClient; -const path = require("path"); -require("dotenv").config({ - path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`) -}); + //New bug introduced with Graphql Request. // https://github.com/prisma-labs/graphql-request/issues/206 // const { Headers } = require("cross-fetch"); // global.Headers = global.Headers || Headers; -exports.client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, { +const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, { headers: { "x-hasura-admin-secret": process.env.HASURA_ADMIN_SECRET } }); -exports.unauthclient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT); +const unauthorizedClient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT); + +module.exports = { + client, + unauthorizedClient +}; diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index 9334c9b72..d61d814b9 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -9,6 +9,7 @@ query FIND_BODYSHOP_BY_MESSAGING_SERVICE_SID($mssid: String!, $phone: String!) { } }`; +// Unused exports.GET_JOB_BY_RO_NUMBER = ` query GET_JOB_BY_RO_NUMBER($ro_number: String!) { jobs(where:{ro_number:{_eq:$ro_number}}) { @@ -1773,6 +1774,7 @@ exports.QUERY_JOB_COSTING_DETAILS_MULTI = ` query QUERY_JOB_COSTING_DETAILS_MULT } }`; +// Exists in Commented out Query exports.INSERT_IOEVENT = ` mutation INSERT_IOEVENT($event: ioevents_insert_input!) { insert_ioevents_one(object: $event) { id @@ -2802,6 +2804,7 @@ exports.GET_BODYSHOP_BY_ID = ` imexshopid intellipay_config state + notification_followers } } `; @@ -2884,3 +2887,84 @@ query GET_BODYSHOP_BY_MERCHANTID($merchantID: String!) { email } }`; + +exports.GET_USER_BY_EMAIL = ` +query GET_USER_BY_EMAIL($email: String!) { + users(where: {email: {_eq: $email}}) { + email + validemail + associations { + id + shopid + bodyshop { + id + convenient_company + features + timezone + } + } + } +}`; + +// Define the GraphQL query to get a job by RO number and shop ID +exports.GET_JOB_BY_RO_NUMBER_AND_SHOP_ID = ` + query GET_JOB_BY_RO_NUMBER_AND_SHOP_ID($roNumber: String!, $shopId: uuid!) { + jobs(where: {ro_number: {_eq: $roNumber}, shopid: {_eq: $shopId}}, limit: 1) { + id + shopid + bodyshop { + timezone + } + } + } +`; + +// Define the mutation to insert a new document +exports.INSERT_NEW_DOCUMENT = ` + mutation INSERT_NEW_DOCUMENT($docInput: [documents_insert_input!]!) { + insert_documents(objects: $docInput) { + returning { + id + name + key + } + } + } +`; + +exports.INSERT_JOB_WATCHERS = ` + mutation INSERT_JOB_WATCHERS($watchers: [job_watchers_insert_input!]!) { + insert_job_watchers(objects: $watchers, on_conflict: { constraint: job_watchers_pkey, update_columns: [] }) { + affected_rows + } + } +`; + +exports.GET_NOTIFICATION_WATCHERS = ` + query GET_NOTIFICATION_WATCHERS($shopId: uuid!, $employeeIds: [uuid!]!) { + associations(where: { + _and: [ + { shopid: { _eq: $shopId } }, + { active: { _eq: true } }, + { notifications_autoadd: { _eq: true } } + ] + }) { + id + useremail + } + employees(where: { id: { _in: $employeeIds }, shopid: { _eq: $shopId }, active: { _eq: true } }) { + user_email + } + } +`; + +exports.GET_JOB_WATCHERS_MINIMAL = ` + query GET_JOB_WATCHERS_MINIMAL($jobid: uuid!) { + job_watchers(where: { jobid: { _eq: $jobid } }) { + user_email + user { + authid + } + } + } +`; diff --git a/server/integrations/VSSTA/vsstaIntegrationRoute.js b/server/integrations/VSSTA/vsstaIntegrationRoute.js new file mode 100644 index 000000000..f7444477a --- /dev/null +++ b/server/integrations/VSSTA/vsstaIntegrationRoute.js @@ -0,0 +1,143 @@ +// Notes: At the moment we take in RO Number, and ShopID. This is not very good considering the RO number can often be null, need +// to ask if it is possible that we just send the Job ID itself, this way we don't need to really care about the bodyshop, and we +// don't risk getting a null + +const axios = require("axios"); +const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3"); +const { getSignedUrl } = require("@aws-sdk/s3-request-presigner"); +const { GET_JOB_BY_RO_NUMBER_AND_SHOP_ID, INSERT_NEW_DOCUMENT } = require("../../graphql-client/queries"); +const { InstanceRegion } = require("../../utils/instanceMgr"); +const moment = require("moment/moment"); +const client = require("../../graphql-client/graphql-client").client; + +const S3_BUCKET = process.env?.IMGPROXY_DESTINATION_BUCKET; + +/** + * @description VSSTA integration route + * @type {string[]} + */ +const requiredParams = [ + "shop_id", + "ro_nbr", + "pdf_download_link", + "company_api_key", + "scan_type", + "scan_time", + "technician", + "year", + "make", + "model" +]; + +const vsstaIntegrationRoute = async (req, res) => { + const { logger } = req; + + if (!S3_BUCKET) { + logger.log("vssta-integration-missing-bucket", "error", "api", "vssta"); + return res.status(500).json({ error: "Improper configuration" }); + } + + try { + const missingParams = requiredParams.filter((param) => !req.body[param]); + + if (missingParams.length > 0) { + logger.log(`vssta-integration-missing-param`, "error", "api", "vssta", { + params: missingParams + }); + + return res.status(400).json({ + error: "Missing required parameters", + missingParams + }); + } + + // technician, year, make, model, is also available. + const { shop_id, ro_nbr, pdf_download_link, scan_type, scan_time, company_api_key } = req.body; + + // 1. Get the job record by ro_number and shop_id + const jobResult = await client.request(GET_JOB_BY_RO_NUMBER_AND_SHOP_ID, { + roNumber: ro_nbr, + shopId: shop_id + }); + + if (!jobResult.jobs || jobResult.jobs.length === 0) { + logger.log(`vssta-integration-missing-ro`, "error", "api", "vssta"); + + return res.status(404).json({ error: "Job not found" }); + } + + const job = jobResult.jobs[0]; + + // 2. Download the base64-encoded PDF string from the provided link + const pdfResponse = await axios.get(pdf_download_link, { + responseType: "text", // Expect base64 string + headers: { + "auth-token": company_api_key + } + }); + + // 3. Decode the base64 string to a PDF buffer + const base64String = pdfResponse.data.replace(/^data:application\/pdf;base64,/, ""); + const pdfBuffer = Buffer.from(base64String, "base64"); + + // 4. Generate key for S3 + const timestamp = moment(scan_time).tz(job.bodyshop.timezone).format("YYYYMMDD-HHmmss"); + const fileName = `${timestamp}_VSSTA_${scan_type}`; + const s3Key = `${job.shopid}/${job.id}/${fileName.replace(/[^A-Z0-9]+/gi, "_")}.pdf`; + + // 5. Generate presigned URL for S3 upload + const s3Client = new S3Client({ region: InstanceRegion() }); + + const putCommand = new PutObjectCommand({ + Bucket: S3_BUCKET, + Key: s3Key, + ContentType: "application/pdf", + StorageClass: "INTELLIGENT_TIERING" + }); + + const presignedUrl = await getSignedUrl(s3Client, putCommand, { expiresIn: 360 }); + + // 6. Upload the decoded PDF to S3 + await axios.put(presignedUrl, pdfBuffer, { + headers: { "Content-Type": "application/pdf" } + }); + + // 7. Create document record in database + const documentMeta = { + jobid: job.id, + uploaded_by: "VSSTA Integration", + name: fileName, + key: s3Key, + type: "application/pdf", + extension: "pdf", + bodyshopid: job.shopid, + size: pdfBuffer.length, + takenat: scan_time + }; + + const documentInsert = await client.request(INSERT_NEW_DOCUMENT, { + docInput: [documentMeta] + }); + + if (!documentInsert.insert_documents?.returning?.length) { + logger.log(`vssta-integration-failed-to-create-document-record`, "error", "api", "vssta", { + params: missingParams + }); + return res.status(500).json({ error: "Failed to create document record" }); + } + + return res.status(200).json({ + message: "VSSTA integration successful", + documentId: documentInsert.insert_documents.returning[0].id + }); + } catch (error) { + logger.log(`vssta-integration-general`, "error", "api", "vssta", { + error: error?.message, + stack: error?.stack + }); + + return res.status(500).json({ error: error.message }); + } +}; + +module.exports = vsstaIntegrationRoute; diff --git a/server/intellipay/lib/handleInvoiceBasedPayment.js b/server/intellipay/lib/handleInvoiceBasedPayment.js index 21e4500a6..d5fc97b9c 100644 --- a/server/intellipay/lib/handleInvoiceBasedPayment.js +++ b/server/intellipay/lib/handleInvoiceBasedPayment.js @@ -107,18 +107,25 @@ const handleInvoiceBasedPayment = async (values, logger, logMeta, res) => { }); // Create payment response record - const responseResults = await gqlClient.request(INSERT_PAYMENT_RESPONSE, { - paymentResponse: { - amount: values.total, - bodyshopid: bodyshop.id, - paymentid: paymentResult.id, - jobid: job.id, - declinereason: "Approved", - ext_paymentid: values.paymentid, - successful: true, - response: values - } - }); + const responseResults = await gqlClient + .request(INSERT_PAYMENT_RESPONSE, { + paymentResponse: { + amount: values.total, + bodyshopid: bodyshop.id, + paymentid: paymentResult.insert_payments.returning[0].id, + jobid: job.id, + declinereason: "Approved", + ext_paymentid: values.paymentid, + successful: true, + response: values + } + }) + .catch((err) => { + logger.log("intellipay-postback-invoice-response-error", "ERROR", "api", null, { + err, + ...logMeta + }); + }); logger.log("intellipay-postback-invoice-response-success", "DEBUG", "api", null, { responseResults, diff --git a/server/intellipay/lib/sendPaymentNotificationEmail.js b/server/intellipay/lib/sendPaymentNotificationEmail.js index 2f83d3a3b..c7b55d6d4 100644 --- a/server/intellipay/lib/sendPaymentNotificationEmail.js +++ b/server/intellipay/lib/sendPaymentNotificationEmail.js @@ -1,5 +1,6 @@ const { sendTaskEmail } = require("../../email/sendemail"); const generateEmailTemplate = require("../../email/generateTemplate"); +const { InstanceEndpoints } = require("../../utils/instanceMgr"); /** * @description Send notification email to the user @@ -22,11 +23,9 @@ const sendPaymentNotificationEmail = async (userEmail, jobs, partialPayments, lo body: jobs.jobs .map( (job) => - `Reference: ${job.ro_number || "N/A"} | ${ - job.ownr_co_nm ? job.ownr_co_nm : `${job.ownr_fn || ""} ${job.ownr_ln || ""}`.trim() - } | ${`${job.v_model_yr || ""} ${job.v_make_desc || ""} ${job.v_model_desc || ""}`.trim()} | $${partialPayments.find((p) => p.jobid === job.id).amount}` + `

    Reference: ${job.ro_number || "N/A"} | ${job.ownr_co_nm ? job.ownr_co_nm : `${job.ownr_fn || ""} ${job.ownr_ln || ""}`.trim()} | ${`${job.v_model_yr || ""} ${job.v_make_desc || ""} ${job.v_model_desc || ""}`.trim()} | $${partialPayments.find((p) => p.jobid === job.id).amount}

    ` ) - .join("
    ") + .join("") }) }); } catch (error) { diff --git a/server/intellipay/lib/tests/handleInvoiceBasedPayment.test.js b/server/intellipay/lib/tests/handleInvoiceBasedPayment.test.js index 01352191e..ce15861eb 100644 --- a/server/intellipay/lib/tests/handleInvoiceBasedPayment.test.js +++ b/server/intellipay/lib/tests/handleInvoiceBasedPayment.test.js @@ -37,7 +37,9 @@ beforeEach(() => { ] }) .mockResolvedValueOnce({ - id: "payment123" + insert_payments: { + returning: [{ id: "payment123" }] + } }) .mockResolvedValueOnce({ insert_payment_response: { diff --git a/server/media/imgproxy-media.js b/server/media/imgproxy-media.js index fdb313984..e30aee90e 100644 --- a/server/media/imgproxy-media.js +++ b/server/media/imgproxy-media.js @@ -1,8 +1,12 @@ const path = require("path"); -require("dotenv").config({ - path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`) -}); const logger = require("../utils/logger"); +const { Upload } = require("@aws-sdk/lib-storage"); +const { getSignedUrl } = require("@aws-sdk/s3-request-presigner"); +const { InstanceRegion } = require("../utils/instanceMgr"); +const archiver = require("archiver"); +const stream = require("node:stream"); +const base64UrlEncode = require("./util/base64UrlEncode"); +const createHmacSha256 = require("./util/createHmacSha256"); const { S3Client, PutObjectCommand, @@ -10,35 +14,36 @@ const { CopyObjectCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3"); -const { Upload } = require("@aws-sdk/lib-storage"); - -const { getSignedUrl } = require("@aws-sdk/s3-request-presigner"); -const crypto = require("crypto"); -const { InstanceRegion } = require("../utils/instanceMgr"); const { GET_DOCUMENTS_BY_JOB, QUERY_TEMPORARY_DOCS, GET_DOCUMENTS_BY_IDS, DELETE_MEDIA_DOCUMENTS } = require("../graphql-client/queries"); -const archiver = require("archiver"); -const stream = require("node:stream"); const imgproxyBaseUrl = process.env.IMGPROXY_BASE_URL; // `https://u4gzpp5wm437dnm75qa42tvza40fguqr.lambda-url.ca-central-1.on.aws` //Direct Lambda function access to bypass CDN. -const imgproxyKey = process.env.IMGPROXY_KEY; const imgproxySalt = process.env.IMGPROXY_SALT; const imgproxyDestinationBucket = process.env.IMGPROXY_DESTINATION_BUCKET; -//Generate a signed upload link for the S3 bucket. -//All uploads must be going to the same shop and jobid. -exports.generateSignedUploadUrls = async (req, res) => { +/** + * Generate a Signed URL Link for the s3 bucket. + * All Uploads must be going to the same Shop and JobId + * @param req + * @param res + * @returns {Promise<*>} + */ +const generateSignedUploadUrls = async (req, res) => { const { filenames, bodyshopid, jobid } = req.body; try { - logger.log("imgproxy-upload-start", "DEBUG", req.user?.email, jobid, { filenames, bodyshopid, jobid }); + logger.log("imgproxy-upload-start", "DEBUG", req.user?.email, jobid, { + filenames, + bodyshopid, + jobid + }); const signedUrls = []; for (const filename of filenames) { - const key = filename; + const key = filename; const client = new S3Client({ region: InstanceRegion() }); const command = new PutObjectCommand({ Bucket: imgproxyDestinationBucket, @@ -50,24 +55,32 @@ exports.generateSignedUploadUrls = async (req, res) => { } logger.log("imgproxy-upload-success", "DEBUG", req.user?.email, jobid, { signedUrls }); - res.json({ + + return res.json({ success: true, signedUrls }); } catch (error) { - res.status(400).json({ - success: false, + logger.log("imgproxy-upload-error", "ERROR", req.user?.email, jobid, { message: error.message, stack: error.stack }); - logger.log("imgproxy-upload-error", "ERROR", req.user?.email, jobid, { + + return res.status(400).json({ + success: false, message: error.message, stack: error.stack }); } }; -exports.getThumbnailUrls = async (req, res) => { +/** + * Get Thumbnail URLS + * @param req + * @param res + * @returns {Promise<*>} + */ +const getThumbnailUrls = async (req, res) => { const { jobid, billid } = req.body; try { @@ -86,10 +99,11 @@ exports.getThumbnailUrls = async (req, res) => { for (const document of data.documents) { //Format to follow: - /////< base 64 URL encoded to image path> - + /////< base 64 URL encoded to image path> //When working with documents from Cloudinary, the URL does not include the extension. + let key; + if (/\.[^/.]+$/.test(document.key)) { key = document.key; } else { @@ -98,12 +112,12 @@ exports.getThumbnailUrls = async (req, res) => { // Build the S3 path to the object. const fullS3Path = `s3://${imgproxyDestinationBucket}/${key}`; const base64UrlEncodedKeyString = base64UrlEncode(fullS3Path); + //Thumbnail Generation Block const thumbProxyPath = `${thumbResizeParams}/${base64UrlEncodedKeyString}`; const thumbHmacSalt = createHmacSha256(`${imgproxySalt}/${thumbProxyPath}`); //Full Size URL block - const fullSizeProxyPath = `${base64UrlEncodedKeyString}`; const fullSizeHmacSalt = createHmacSha256(`${imgproxySalt}/${fullSizeProxyPath}`); @@ -114,8 +128,8 @@ exports.getThumbnailUrls = async (req, res) => { Bucket: imgproxyDestinationBucket, Key: key }); - const presignedGetUrl = await getSignedUrl(s3client, command, { expiresIn: 360 }); - s3Props.presignedGetUrl = presignedGetUrl; + + s3Props.presignedGetUrl = await getSignedUrl(s3client, command, { expiresIn: 360 }); const originalProxyPath = `raw:1/${base64UrlEncodedKeyString}`; const originalHmacSalt = createHmacSha256(`${imgproxySalt}/${originalProxyPath}`); @@ -133,7 +147,7 @@ exports.getThumbnailUrls = async (req, res) => { }); } - res.json(proxiedUrls); + return res.json(proxiedUrls); //Iterate over them, build the link based on the media type, and return the array. } catch (error) { logger.log("imgproxy-thumbnails-error", "ERROR", req.user?.email, jobid, { @@ -142,57 +156,72 @@ exports.getThumbnailUrls = async (req, res) => { message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } }; -exports.getBillFiles = async (req, res) => { - //Givena bill ID, get the documents associated to it. -}; - -exports.downloadFiles = async (req, res) => { +/** + * Download Files + * @param req + * @param res + * @returns {Promise<*>} + */ +const downloadFiles = async (req, res) => { //Given a series of document IDs or keys, generate a file (or a link) to download all images in bulk - const { jobid, billid, documentids } = req.body; + const { jobId, billid, documentids } = req.body; + try { - logger.log("imgproxy-download", "DEBUG", req.user?.email, jobid, { billid, jobid, documentids }); + logger.log("imgproxy-download", "DEBUG", req.user?.email, jobId, { billid, jobId, documentids }); //Delayed as the key structure may change slightly from what it is currently and will require evaluating mobile components. const client = req.userGraphQLClient; + //Query for the keys of the document IDs const data = await client.request(GET_DOCUMENTS_BY_IDS, { documentIds: documentids }); - //Using the Keys, get all of the S3 links, zip them, and send back to the client. + + //Using the Keys, get all the S3 links, zip them, and send back to the client. const s3client = new S3Client({ region: InstanceRegion() }); const archiveStream = archiver("zip"); + archiveStream.on("error", (error) => { console.error("Archival encountered an error:", error); throw new Error(error); }); - const passthrough = new stream.PassThrough(); - archiveStream.pipe(passthrough); + const passThrough = new stream.PassThrough(); + + archiveStream.pipe(passThrough); + for (const key of data.documents.map((d) => d.key)) { - const response = await s3client.send(new GetObjectCommand({ Bucket: imgproxyDestinationBucket, Key: key })); - // :: `response.Body` is a Buffer - console.log(path.basename(key)); + const response = await s3client.send( + new GetObjectCommand({ + Bucket: imgproxyDestinationBucket, + Key: key + }) + ); + archiveStream.append(response.Body, { name: path.basename(key) }); } - archiveStream.finalize(); + await archiveStream.finalize(); - const archiveKey = `archives/${jobid}/archive-${new Date().toISOString()}.zip`; + const archiveKey = `archives/${jobId || "na"}/archive-${new Date().toISOString()}.zip`; const parallelUploads3 = new Upload({ client: s3client, queueSize: 4, // optional concurrency configuration leavePartsOnError: false, // optional manually handle dropped parts - params: { Bucket: imgproxyDestinationBucket, Key: archiveKey, Body: passthrough } + params: { Bucket: imgproxyDestinationBucket, Key: archiveKey, Body: passThrough } }); - parallelUploads3.on("httpUploadProgress", (progress) => { - console.log(progress); - }); + // Disabled progress logging for upload, uncomment if needed + // parallelUploads3.on("httpUploadProgress", (progress) => { + // console.log(progress); + // }); + + await parallelUploads3.done(); - const uploadResult = await parallelUploads3.done(); //Generate the presigned URL to download it. const presignedUrl = await getSignedUrl( s3client, @@ -200,20 +229,27 @@ exports.downloadFiles = async (req, res) => { { expiresIn: 360 } ); - res.json({ success: true, url: presignedUrl }); + return res.json({ success: true, url: presignedUrl }); //Iterate over them, build the link based on the media type, and return the array. } catch (error) { - logger.log("imgproxy-thumbnails-error", "ERROR", req.user?.email, jobid, { - jobid, + logger.log("imgproxy-thumbnails-error", "ERROR", req.user?.email, jobId, { + jobId, billid, message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } }; -exports.deleteFiles = async (req, res) => { +/** + * Delete Files + * @param req + * @param res + * @returns {Promise<*>} + */ +const deleteFiles = async (req, res) => { //Mark a file for deletion in s3. Lifecycle deletion will actually delete the copy in the future. //Mark as deleted from the documents section of the database. const { ids } = req.body; @@ -232,7 +268,7 @@ exports.deleteFiles = async (req, res) => { (async () => { try { // Delete the original object - const deleteResult = await s3client.send( + await s3client.send( new DeleteObjectCommand({ Bucket: imgproxyDestinationBucket, Key: document.key @@ -250,23 +286,30 @@ exports.deleteFiles = async (req, res) => { const result = await Promise.all(deleteTransactions); const errors = result.filter((d) => d.error); - //Delete only the succesful deletes. + //Delete only the successful deletes. const deleteMutationResult = await client.request(DELETE_MEDIA_DOCUMENTS, { ids: result.filter((t) => !t.error).map((d) => d.id) }); - res.json({ errors, deleteMutationResult }); + return res.json({ errors, deleteMutationResult }); } catch (error) { logger.log("imgproxy-delete-files-error", "ERROR", req.user.email, null, { ids, message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } }; -exports.moveFiles = async (req, res) => { +/** + * Move Files + * @param req + * @param res + * @returns {Promise<*>} + */ +const moveFiles = async (req, res) => { const { documents, tojobid } = req.body; try { logger.log("imgproxy-move-files", "DEBUG", req.user.email, null, { documents, tojobid }); @@ -278,7 +321,7 @@ exports.moveFiles = async (req, res) => { (async () => { try { // Copy the object to the new key - const copyresult = await s3client.send( + await s3client.send( new CopyObjectCommand({ Bucket: imgproxyDestinationBucket, CopySource: `${imgproxyDestinationBucket}/${document.from}`, @@ -288,7 +331,7 @@ exports.moveFiles = async (req, res) => { ); // Delete the original object - const deleteResult = await s3client.send( + await s3client.send( new DeleteObjectCommand({ Bucket: imgproxyDestinationBucket, Key: document.from @@ -297,7 +340,12 @@ exports.moveFiles = async (req, res) => { return document; } catch (error) { - return { id: document.id, from: document.from, error: error, bucket: imgproxyDestinationBucket }; + return { + id: document.id, + from: document.from, + error: error, + bucket: imgproxyDestinationBucket + }; } })() ); @@ -307,6 +355,7 @@ exports.moveFiles = async (req, res) => { const errors = result.filter((d) => d.error); let mutations = ""; + result .filter((d) => !d.error) .forEach((d, idx) => { @@ -321,14 +370,16 @@ exports.moveFiles = async (req, res) => { }); const client = req.userGraphQLClient; + if (mutations !== "") { const mutationResult = await client.request(`mutation { ${mutations} }`); - res.json({ errors, mutationResult }); - } else { - res.json({ errors: "No images were succesfully moved on remote server. " }); + + return res.json({ errors, mutationResult }); } + + return res.json({ errors: "No images were successfully moved on remote server. " }); } catch (error) { logger.log("imgproxy-move-files-error", "ERROR", req.user.email, null, { documents, @@ -336,13 +387,15 @@ exports.moveFiles = async (req, res) => { message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } }; -function base64UrlEncode(str) { - return Buffer.from(str).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); -} -function createHmacSha256(data) { - return crypto.createHmac("sha256", imgproxyKey).update(data).digest("base64url"); -} +module.exports = { + generateSignedUploadUrls, + getThumbnailUrls, + downloadFiles, + deleteFiles, + moveFiles +}; diff --git a/server/media/media.js b/server/media/media.js index 06b1c9bb8..7cb8a1b5d 100644 --- a/server/media/media.js +++ b/server/media/media.js @@ -1,42 +1,55 @@ -const path = require("path"); const _ = require("lodash"); const logger = require("../utils/logger"); const client = require("../graphql-client/graphql-client").client; -const queries = require("../graphql-client/queries"); +const determineFileType = require("./util/determineFileType"); +const { DELETE_MEDIA_DOCUMENTS } = require("../graphql-client/queries"); -require("dotenv").config({ - path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`) -}); - -var cloudinary = require("cloudinary").v2; +const cloudinary = require("cloudinary").v2; cloudinary.config(process.env.CLOUDINARY_URL); +/** + * @description Creates a signed upload URL for Cloudinary. + * @param req + * @param res + */ const createSignedUploadURL = (req, res) => { logger.log("media-signed-upload", "DEBUG", req.user.email, null, null); res.send(cloudinary.utils.api_sign_request(req.body, process.env.CLOUDINARY_API_SECRET)); }; -exports.createSignedUploadURL = createSignedUploadURL; - +/** + * @description Downloads files from Cloudinary. + * @param req + * @param res + */ const downloadFiles = (req, res) => { const { ids } = req.body; + logger.log("media-bulk-download", "DEBUG", req.user.email, ids, null); const url = cloudinary.utils.download_zip_url({ public_ids: ids, flatten_folders: true }); + res.send(url); }; -exports.downloadFiles = downloadFiles; +/** + * @description Deletes files from Cloudinary and Apollo. + * @param req + * @param res + * @returns {Promise} + */ const deleteFiles = async (req, res) => { const { ids } = req.body; - const types = _.groupBy(ids, (x) => DetermineFileType(x.type)); + + const types = _.groupBy(ids, (x) => determineFileType(x.type)); logger.log("media-bulk-delete", "DEBUG", req.user.email, ids, null); const returns = []; + if (types.image) { //delete images @@ -47,8 +60,8 @@ const deleteFiles = async (req, res) => { ) ); } + if (types.video) { - //delete images returns.push( returns.push( await cloudinary.api.delete_resources( types.video.map((x) => x.key), @@ -56,8 +69,8 @@ const deleteFiles = async (req, res) => { ) ); } + if (types.raw) { - //delete images returns.push( returns.push( await cloudinary.api.delete_resources( types.raw.map((x) => `${x.key}.${x.extension}`), @@ -68,6 +81,7 @@ const deleteFiles = async (req, res) => { // Delete it on apollo. const successfulDeletes = []; + returns.forEach((resType) => { Object.keys(resType.deleted).forEach((key) => { if (resType.deleted[key] === "deleted" || resType.deleted[key] === "not_found") { @@ -77,7 +91,7 @@ const deleteFiles = async (req, res) => { }); try { - const result = await client.request(queries.DELETE_MEDIA_DOCUMENTS, { + const result = await client.request(DELETE_MEDIA_DOCUMENTS, { ids: ids.filter((i) => successfulDeletes.includes(i.key)).map((i) => i.id) }); @@ -91,24 +105,29 @@ const deleteFiles = async (req, res) => { } }; -exports.deleteFiles = deleteFiles; - +/** + * @description Renames keys in Cloudinary and updates the database. + * @param req + * @param res + * @returns {Promise} + */ const renameKeys = async (req, res) => { const { documents, tojobid } = req.body; + logger.log("media-bulk-rename", "DEBUG", req.user.email, null, documents); const proms = []; + documents.forEach((d) => { proms.push( (async () => { try { - const res = { + return { id: d.id, ...(await cloudinary.uploader.rename(d.from, d.to, { - resource_type: DetermineFileType(d.type) + resource_type: determineFileType(d.type) })) }; - return res; } catch (error) { return { id: d.id, from: d.from, error: error }; } @@ -148,18 +167,13 @@ const renameKeys = async (req, res) => { }`); res.json({ errors, mutationResult }); } else { - res.json({ errors: "No images were succesfully moved on remote server. " }); + res.json({ errors: "No images were successfully moved on remote server. " }); } }; -exports.renameKeys = renameKeys; -//Also needs to be updated in upload utility and mobile app. -function DetermineFileType(filetype) { - if (!filetype) return "auto"; - else if (filetype.startsWith("image")) return "image"; - else if (filetype.startsWith("video")) return "video"; - else if (filetype.startsWith("application/pdf")) return "image"; - else if (filetype.startsWith("application")) return "raw"; - - return "auto"; -} +module.exports = { + createSignedUploadURL, + downloadFiles, + deleteFiles, + renameKeys +}; diff --git a/server/media/tests/media-utils.test.js b/server/media/tests/media-utils.test.js new file mode 100644 index 000000000..b25678da1 --- /dev/null +++ b/server/media/tests/media-utils.test.js @@ -0,0 +1,98 @@ +import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; +import determineFileType from "../util/determineFileType"; +import base64UrlEncode from "../util/base64UrlEncode"; + +describe("Media Utils", () => { + describe("base64UrlEncode", () => { + it("should encode string to base64url format", () => { + expect(base64UrlEncode("hello world")).toBe("aGVsbG8gd29ybGQ"); + }); + + it('should replace "+" with "-"', () => { + // '+' in base64 appears when encoding specific binary data + expect(base64UrlEncode("hello+world")).toBe("aGVsbG8rd29ybGQ"); + }); + + it('should replace "/" with "_"', () => { + expect(base64UrlEncode("path/to/resource")).toBe("cGF0aC90by9yZXNvdXJjZQ"); + }); + + it('should remove trailing "=" characters', () => { + // Using a string that will produce padding in base64 + expect(base64UrlEncode("padding==")).toBe("cGFkZGluZz09"); + }); + }); + + describe("createHmacSha256", () => { + let createHmacSha256; + const originalEnv = process.env; + + beforeEach(async () => { + vi.resetModules(); + process.env = { ...originalEnv }; + process.env.IMGPROXY_KEY = "test-key"; + + // Dynamically import the module after setting env var + const module = await import("../util/createHmacSha256"); + createHmacSha256 = module.default; + }); + + afterEach(() => { + process.env = originalEnv; + }); + + it("should create a valid HMAC SHA-256 hash", () => { + const result = createHmacSha256("test-data"); + expect(typeof result).toBe("string"); + expect(result.length).toBeGreaterThan(0); + }); + + it("should produce consistent hashes for the same input", () => { + const hash1 = createHmacSha256("test-data"); + const hash2 = createHmacSha256("test-data"); + expect(hash1).toBe(hash2); + }); + + it("should produce different hashes for different inputs", () => { + const hash1 = createHmacSha256("test-data-1"); + const hash2 = createHmacSha256("test-data-2"); + expect(hash1).not.toBe(hash2); + }); + }); + + describe("determineFileType", () => { + it('should return "auto" when no filetype is provided', () => { + expect(determineFileType()).toBe("auto"); + expect(determineFileType(null)).toBe("auto"); + expect(determineFileType(undefined)).toBe("auto"); + }); + + it('should return "image" for image filetypes', () => { + expect(determineFileType("image/jpeg")).toBe("image"); + expect(determineFileType("image/png")).toBe("image"); + expect(determineFileType("image/gif")).toBe("image"); + }); + + it('should return "video" for video filetypes', () => { + expect(determineFileType("video/mp4")).toBe("video"); + expect(determineFileType("video/quicktime")).toBe("video"); + expect(determineFileType("video/x-msvideo")).toBe("video"); + }); + + it('should return "image" for PDF files', () => { + expect(determineFileType("application/pdf")).toBe("image"); + }); + + it('should return "raw" for other application types', () => { + expect(determineFileType("application/zip")).toBe("raw"); + expect(determineFileType("application/json")).toBe("raw"); + expect(determineFileType("application/msword")).toBe("raw"); + }); + + it('should return "auto" for unrecognized types', () => { + expect(determineFileType("audio/mpeg")).toBe("auto"); + expect(determineFileType("text/html")).toBe("auto"); + expect(determineFileType("unknown-type")).toBe("auto"); + }); + }); +}); diff --git a/server/media/util/base64UrlEncode.js b/server/media/util/base64UrlEncode.js new file mode 100644 index 000000000..24537cb2c --- /dev/null +++ b/server/media/util/base64UrlEncode.js @@ -0,0 +1,9 @@ +/** + * @description Converts a string to a base64url encoded string. + * @param str + * @returns {string} + */ +const base64UrlEncode = (str) => + Buffer.from(str).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); + +module.exports = base64UrlEncode; diff --git a/server/media/util/createHmacSha256.js b/server/media/util/createHmacSha256.js new file mode 100644 index 000000000..6be9d6022 --- /dev/null +++ b/server/media/util/createHmacSha256.js @@ -0,0 +1,12 @@ +const crypto = require("crypto"); + +const imgproxyKey = process.env.IMGPROXY_KEY; + +/** + * @description Creates a HMAC SHA-256 hash of the given data. + * @param data + * @returns {string} + */ +const createHmacSha256 = (data) => crypto.createHmac("sha256", imgproxyKey).update(data).digest("base64url"); + +module.exports = createHmacSha256; diff --git a/server/media/util/determineFileType.js b/server/media/util/determineFileType.js new file mode 100644 index 000000000..9bd8a4732 --- /dev/null +++ b/server/media/util/determineFileType.js @@ -0,0 +1,17 @@ +/** + * @description Determines the file type based on the filetype string. + * @note Also needs to be updated in the mobile app utility. + * @param filetype + * @returns {string} + */ +const determineFileType = (filetype) => { + if (!filetype) return "auto"; + else if (filetype.startsWith("image")) return "image"; + else if (filetype.startsWith("video")) return "video"; + else if (filetype.startsWith("application/pdf")) return "image"; + else if (filetype.startsWith("application")) return "raw"; + + return "auto"; +}; + +module.exports = determineFileType; diff --git a/server/middleware/vsstaIntegrationMiddleware.js b/server/middleware/vsstaIntegrationMiddleware.js new file mode 100644 index 000000000..44a0bb45d --- /dev/null +++ b/server/middleware/vsstaIntegrationMiddleware.js @@ -0,0 +1,17 @@ +/** + * VSSTA Integration Middleware + * @param req + * @param res + * @param next + * @returns {*} + */ +const vsstaIntegrationMiddleware = (req, res, next) => { + if (req?.headers?.["vssta-integration-secret"] !== process.env?.VSSTA_INTEGRATION_SECRET) { + return res.status(401).send("Unauthorized"); + } + + req.isIntegrationAuthorized = true; + next(); +}; + +module.exports = vsstaIntegrationMiddleware; diff --git a/server/notifications/autoAddWatchers.js b/server/notifications/autoAddWatchers.js new file mode 100644 index 000000000..e2579cffd --- /dev/null +++ b/server/notifications/autoAddWatchers.js @@ -0,0 +1,127 @@ +/** + * @module autoAddWatchers + * @description + * This module handles automatically adding watchers to new jobs based on the notifications_autoadd + * boolean field in the associations table and the notification_followers JSON field in the bodyshops table. + * It ensures users are not added twice and logs the process. + */ + +const { client: gqlClient } = require("../graphql-client/graphql-client"); +const { isEmpty } = require("lodash"); +const { + GET_JOB_WATCHERS_MINIMAL, + GET_NOTIFICATION_WATCHERS, + INSERT_JOB_WATCHERS +} = require("../graphql-client/queries"); + +// If true, the user who commits the action will NOT receive notifications; if false, they will. +const FILTER_SELF_FROM_WATCHERS = process.env?.FILTER_SELF_FROM_WATCHERS !== "false"; + +/** + * Adds watchers to a new job based on notifications_autoadd and notification_followers. + * + * @param {Object} req - The request object containing event data and logger. + * @returns {Promise} Resolves when watchers are added or if no action is needed. + * @throws {Error} If critical data (e.g., jobId, shopId) is missing. + */ +const autoAddWatchers = async (req) => { + const { event, trigger } = req.body; + const { + logger, + sessionUtils: { getBodyshopFromRedis } + } = req; + + // Validate that this is an INSERT event, bail + if (trigger?.name !== "notifications_jobs_autoadd" || event.op !== "INSERT" || event.data.old) { + return; + } + + const jobId = event?.data?.new?.id; + const shopId = event?.data?.new?.shopid; + const roNumber = event?.data?.new?.ro_number || "unknown"; + + if (!jobId || !shopId) { + throw new Error(`Missing jobId (${jobId}) or shopId (${shopId}) for auto-add watchers`); + } + + const hasuraUserRole = event?.session_variables?.["x-hasura-role"]; + const hasuraUserId = event?.session_variables?.["x-hasura-user-id"]; + + try { + // Fetch bodyshop data from Redis + const bodyshopData = await getBodyshopFromRedis(shopId); + const notificationFollowers = bodyshopData?.notification_followers || []; + + // Execute queries in parallel + const [notificationData, existingWatchersData] = await Promise.all([ + gqlClient.request(GET_NOTIFICATION_WATCHERS, { + shopId, + employeeIds: notificationFollowers.filter((id) => id) + }), + gqlClient.request(GET_JOB_WATCHERS_MINIMAL, { jobid: jobId }) + ]); + + // Get users with notifications_autoadd: true + const autoAddUsers = + notificationData?.associations?.map((assoc) => ({ + email: assoc.useremail, + associationId: assoc.id + })) || []; + + // Get users from notification_followers + const followerEmails = + notificationData?.employees + ?.filter((e) => e.user_email) + ?.map((e) => ({ + email: e.user_email, + associationId: null + })) || []; + + // Combine and deduplicate emails (use email as the unique key) + const usersToAdd = [...autoAddUsers, ...followerEmails].reduce((acc, user) => { + if (!acc.some((u) => u.email === user.email)) { + acc.push(user); + } + return acc; + }, []); + + if (isEmpty(usersToAdd)) { + return; + } + + // Check existing watchers to avoid duplicates + const existingWatcherEmails = existingWatchersData?.job_watchers?.map((w) => w.user_email) || []; + + // Filter out already existing watchers and optionally the user who created the job + const newWatchers = usersToAdd + .filter((user) => !existingWatcherEmails.includes(user.email)) + .filter((user) => { + if (FILTER_SELF_FROM_WATCHERS && hasuraUserRole === "user") { + const userData = existingWatchersData?.job_watchers?.find((w) => w.user?.authid === hasuraUserId); + return userData ? user.email !== userData.user_email : true; + } + return true; + }) + .map((user) => ({ + jobid: jobId, + user_email: user.email + })); + + if (isEmpty(newWatchers)) { + return; + } + + // Insert new watchers + await gqlClient.request(INSERT_JOB_WATCHERS, { watchers: newWatchers }); + } catch (error) { + logger.log("Error adding auto-add watchers", "error", "notifications", null, { + message: error?.message, + stack: error?.stack, + jobId, + roNumber + }); + throw error; // Re-throw to ensure the error is logged in the handler + } +}; + +module.exports = { autoAddWatchers }; diff --git a/server/notifications/eventHandlers.js b/server/notifications/eventHandlers.js index eeb86981d..5af7db500 100644 --- a/server/notifications/eventHandlers.js +++ b/server/notifications/eventHandlers.js @@ -6,6 +6,7 @@ */ const scenarioParser = require("./scenarioParser"); +const { autoAddWatchers } = require("./autoAddWatchers"); // New module /** * Processes a notification event by invoking the scenario parser. @@ -185,6 +186,27 @@ const handlePartsDispatchChange = (req, res) => res.status(200).json({ message: */ const handlePartsOrderChange = (req, res) => res.status(200).json({ message: "Parts Order change handled." }); +/** + * Handle auto-add watchers for new jobs. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @returns {Promise} JSON response with a success message. + */ +const handleAutoAddWatchers = async (req, res) => { + const { logger } = req; + + // Call autoAddWatchers but don't await it; log any error that occurs. + autoAddWatchers(req).catch((error) => { + logger.log("auto-add-watchers-error", "error", "notifications", null, { + message: error?.message, + stack: error?.stack + }); + }); + + return res.status(200).json({ message: "Auto-Add Watchers Event Handled." }); +}; + module.exports = { handleJobsChange, handleBillsChange, @@ -195,5 +217,6 @@ module.exports = { handlePartsOrderChange, handlePaymentsChange, handleTasksChange, - handleTimeTicketsChange + handleTimeTicketsChange, + handleAutoAddWatchers }; diff --git a/server/notifications/queues/emailQueue.js b/server/notifications/queues/emailQueue.js index ff6702635..7d965cb69 100644 --- a/server/notifications/queues/emailQueue.js +++ b/server/notifications/queues/emailQueue.js @@ -133,11 +133,19 @@ const loadEmailQueue = async ({ pubClient, logger }) => { subHeader: `Dear ${firstName},`, dateLine: moment().tz(timezone).format("MM/DD/YYYY hh:mm a"), body: ` -

    There have been updates to job ${jobRoNumber || "N/A"} at ${bodyShopName}:


    -
      - ${messages.map((msg) => `
    • ${msg}
    • `).join("")} -


    -

    Please check the job for more details.

    +

    There have been updates to job ${jobRoNumber || "N/A"} at ${bodyShopName}:

    +
+ + +
+
    + ${messages.map((msg) => `
  • ${msg}
  • `).join("")} +
+
+ +
+

Please check the job for more details.

` }); await sendTaskEmail({ @@ -226,6 +234,7 @@ const getQueue = () => { * @param {Object} options.logger - Logger instance for logging dispatch events. * @returns {Promise} Resolves when all notifications are added to the queue. */ +// eslint-disable-next-line no-unused-vars const dispatchEmailsToQueue = async ({ emailsToDispatch, logger }) => { const emailAddQueue = getQueue(); diff --git a/server/notifications/scenarioBuilders.js b/server/notifications/scenarioBuilders.js index b3f4d0fd2..d1bdb22a0 100644 --- a/server/notifications/scenarioBuilders.js +++ b/server/notifications/scenarioBuilders.js @@ -182,7 +182,7 @@ const newMediaAddedReassignedBuilder = (data) => { : data.changedFields?.jobid && data.changedFields.jobid.old !== data.changedFields.jobid.new ? "moved to this job" : "updated"; - const body = `An ${mediaType} has been ${action}.`; + const body = `A ${mediaType} has been ${action}.`; return buildNotification(data, "notifications.job.newMediaAdded", body, { mediaType, diff --git a/server/notifications/scenarioParser.js b/server/notifications/scenarioParser.js index ddf1ff103..aebec8205 100644 --- a/server/notifications/scenarioParser.js +++ b/server/notifications/scenarioParser.js @@ -63,7 +63,9 @@ const scenarioParser = async (req, jobIdField) => { } if (!jobId) { - logger.log(`No jobId found using path "${jobIdField}", skipping notification parsing`, "info", "notifications"); + if (process?.env?.NODE_ENV === "development") { + logger.log(`No jobId found using path "${jobIdField}", skipping notification parsing`, "info", "notifications"); + } return; } @@ -88,7 +90,9 @@ const scenarioParser = async (req, jobIdField) => { // Exit early if no job watchers are found for this job if (isEmpty(jobWatchers)) { - logger.log(`No watchers found for jobId "${jobId}", skipping notification parsing`, "info", "notifications"); + if (process?.env?.NODE_ENV === "development") { + logger.log(`No watchers found for jobId "${jobId}", skipping notification parsing`, "info", "notifications"); + } return; } @@ -130,11 +134,13 @@ const scenarioParser = async (req, jobIdField) => { // Exit early if no matching scenarios are identified if (isEmpty(matchingScenarios)) { - logger.log( - `No matching scenarios found for jobId "${jobId}", skipping notification dispatch`, - "info", - "notifications" - ); + if (process?.env?.NODE_ENV === "development") { + logger.log( + `No matching scenarios found for jobId "${jobId}", skipping notification dispatch`, + "info", + "notifications" + ); + } return; } @@ -157,11 +163,13 @@ const scenarioParser = async (req, jobIdField) => { // Exit early if no notification associations are found if (isEmpty(associationsData?.associations)) { - logger.log( - `No notification associations found for jobId "${jobId}", skipping notification dispatch`, - "info", - "notifications" - ); + if (process?.env?.NODE_ENV === "development") { + logger.log( + `No notification associations found for jobId "${jobId}", skipping notification dispatch`, + "info", + "notifications" + ); + } return; } @@ -196,11 +204,13 @@ const scenarioParser = async (req, jobIdField) => { // Exit early if no scenarios have eligible watchers after filtering if (isEmpty(finalScenarioData?.matchingScenarios)) { - logger.log( - `No eligible watchers after filtering for jobId "${jobId}", skipping notification dispatch`, - "info", - "notifications" - ); + if (process?.env?.NODE_ENV === "development") { + logger.log( + `No eligible watchers after filtering for jobId "${jobId}", skipping notification dispatch`, + "info", + "notifications" + ); + } return; } @@ -259,7 +269,9 @@ const scenarioParser = async (req, jobIdField) => { } if (isEmpty(scenariosToDispatch)) { - logger.log(`No scenarios to dispatch for jobId "${jobId}" after building`, "info", "notifications"); + if (process?.env?.NODE_ENV === "development") { + logger.log(`No scenarios to dispatch for jobId "${jobId}" after building`, "info", "notifications"); + } return; } diff --git a/server/payroll/pay-all.js b/server/payroll/pay-all.js index 03c6fbee8..33614f656 100644 --- a/server/payroll/pay-all.js +++ b/server/payroll/pay-all.js @@ -1,11 +1,10 @@ const Dinero = require("dinero.js"); const queries = require("../graphql-client/queries"); -const GraphQLClient = require("graphql-request").GraphQLClient; const _ = require("lodash"); const rdiff = require("recursive-diff"); const logger = require("../utils/logger"); -const { json } = require("body-parser"); + // Dinero.defaultCurrency = "USD"; // Dinero.globalLocale = "en-CA"; Dinero.globalRoundingMode = "HALF_EVEN"; diff --git a/server/render/inlinecss.js b/server/render/inlinecss.js index 74700b210..bf8d45ba4 100644 --- a/server/render/inlinecss.js +++ b/server/render/inlinecss.js @@ -1,16 +1,11 @@ -const path = require("path"); -require("dotenv").config({ - path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`) -}); -const logger = require("../utils/logger"); -//const inlineCssTool = require("inline-css"); const juice = require("juice"); -exports.inlinecss = async (req, res) => { - //Perform request validation +exports.inlineCSS = async (req, res) => { + const { logger } = req; + const { html } = req.body; + logger.log("email-inline-css", "DEBUG", req.user.email, null, null); - const { html, url } = req.body; try { const inlinedHtml = juice(html, { applyAttributesTableElements: false, @@ -24,15 +19,4 @@ exports.inlinecss = async (req, res) => { }); res.send(error.message); } - - // inlineCssTool(html, { url: url }) - // .then((inlinedHtml) => { - // res.send(inlinedHtml); - // }) - // .catch((error) => { - // logger.log("email-inline-css-error", "ERROR", req.user.email, null, { - // error - // }); - - // }); }; diff --git a/server/routes/adminRoutes.js b/server/routes/adminRoutes.js index 0d62d27a6..909f11344 100644 --- a/server/routes/adminRoutes.js +++ b/server/routes/adminRoutes.js @@ -2,7 +2,7 @@ const express = require("express"); const router = express.Router(); const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware"); const { createAssociation, createShop, updateShop, updateCounter } = require("../admin/adminops"); -const { updateUser, getUser, createUser } = require("../firebase/firebase-handler"); +const { updateUser, getUser, createUser, getWelcomeEmail, getResetLink } = require("../firebase/firebase-handler"); const validateAdminMiddleware = require("../middleware/validateAdminMiddleware"); router.use(validateFirebaseIdTokenMiddleware); @@ -15,5 +15,7 @@ router.post("/updatecounter", updateCounter); router.post("/updateuser", updateUser); router.post("/getuser", getUser); router.post("/createuser", createUser); +router.post("/sendwelcome", getWelcomeEmail); +router.post("/resetlink", getResetLink); module.exports = router; diff --git a/server/routes/intergrationRoutes.js b/server/routes/intergrationRoutes.js new file mode 100644 index 000000000..841805675 --- /dev/null +++ b/server/routes/intergrationRoutes.js @@ -0,0 +1,8 @@ +const express = require("express"); +const vsstaIntegration = require("../integrations/VSSTA/vsstaIntegrationRoute"); +const vsstaMiddleware = require("../middleware/vsstaIntegrationMiddleware"); +const router = express.Router(); + +router.post("/vssta", vsstaMiddleware, vsstaIntegration); + +module.exports = router; diff --git a/server/routes/jobRoutes.js b/server/routes/jobRoutes.js index aab3e8823..e7c747907 100644 --- a/server/routes/jobRoutes.js +++ b/server/routes/jobRoutes.js @@ -1,6 +1,5 @@ const express = require("express"); const router = express.Router(); -const job = require("../job/job"); const ppc = require("../ccc/partspricechange"); const { partsScan } = require("../parts-scan/parts-scan"); const eventAuthorizationMiddleware = require("../middleware/eventAuthorizationMIddleware"); diff --git a/server/routes/miscellaneousRoutes.js b/server/routes/miscellaneousRoutes.js index aeb59af93..40666302f 100644 --- a/server/routes/miscellaneousRoutes.js +++ b/server/routes/miscellaneousRoutes.js @@ -3,7 +3,6 @@ const router = express.Router(); const logger = require("../../server/utils/logger"); const sendEmail = require("../email/sendemail"); const data = require("../data/data"); -const bodyParser = require("body-parser"); const ioevent = require("../ioevent/ioevent"); const taskHandler = require("../tasks/tasks"); const os = require("../opensearch/os-handler"); @@ -123,7 +122,7 @@ router.post("/ioevent", ioevent.default); // Email router.post("/sendemail", validateFirebaseIdTokenMiddleware, sendEmail.sendEmail); -router.post("/emailbounce", bodyParser.text(), sendEmail.emailBounce); +router.post("/emailbounce", express.text(), sendEmail.emailBounce); // Tasks Email Handler router.post("/tasks-assigned-handler", eventAuthorizationMiddleware, taskAssignedEmail); diff --git a/server/routes/notificationsRoutes.js b/server/routes/notificationsRoutes.js index 0d47882b1..9e3709a79 100644 --- a/server/routes/notificationsRoutes.js +++ b/server/routes/notificationsRoutes.js @@ -12,7 +12,8 @@ const { handleNotesChange, handlePaymentsChange, handleDocumentsChange, - handleJobLinesChange + handleJobLinesChange, + handleAutoAddWatchers } = require("../notifications/eventHandlers"); const router = express.Router(); @@ -33,5 +34,6 @@ router.post("/events/handleNotesChange", eventAuthorizationMiddleware, handleNot router.post("/events/handlePaymentsChange", eventAuthorizationMiddleware, handlePaymentsChange); router.post("/events/handleDocumentsChange", eventAuthorizationMiddleware, handleDocumentsChange); router.post("/events/handleJobLinesChange", eventAuthorizationMiddleware, handleJobLinesChange); +router.post("/events/handleAutoAdd", eventAuthorizationMiddleware, handleAutoAddWatchers); module.exports = router; diff --git a/server/routes/renderRoutes.js b/server/routes/renderRoutes.js index 613e6b0b5..41b6cf6aa 100644 --- a/server/routes/renderRoutes.js +++ b/server/routes/renderRoutes.js @@ -1,12 +1,12 @@ const express = require("express"); const router = express.Router(); -const { inlinecss } = require("../render/inlinecss"); +const { inlineCSS } = require("../render/inlinecss"); const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware"); const { canvas } = require("../render/canvas-handler"); const validateCanvasInputMiddleware = require("../middleware/validateCanvasInputMiddleware"); // Define the route for inline CSS rendering -router.post("/inlinecss", validateFirebaseIdTokenMiddleware, inlinecss); +router.post("/inlinecss", validateFirebaseIdTokenMiddleware, inlineCSS); router.post("/canvas-skia", validateFirebaseIdTokenMiddleware, validateCanvasInputMiddleware, canvas); router.post("/canvas", validateFirebaseIdTokenMiddleware, validateCanvasInputMiddleware, canvas); diff --git a/server/routes/ssoRoutes.js b/server/routes/ssoRoutes.js new file mode 100644 index 000000000..aaae869ea --- /dev/null +++ b/server/routes/ssoRoutes.js @@ -0,0 +1,11 @@ +const express = require("express"); +const router = express.Router(); +const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware"); +const withUserGraphQLClientMiddleware = require("../middleware/withUserGraphQLClientMiddleware"); +const { cannySsoHandler } = require("../sso/canny"); + +router.use(validateFirebaseIdTokenMiddleware); + +router.post("/canny", withUserGraphQLClientMiddleware, cannySsoHandler); + +module.exports = router; diff --git a/server/sso/canny.js b/server/sso/canny.js new file mode 100644 index 000000000..776844465 --- /dev/null +++ b/server/sso/canny.js @@ -0,0 +1,24 @@ +const logger = require("../utils/logger"); +const jwt = require("jsonwebtoken"); + +const cannySsoHandler = async (req, res) => { + try { + const userData = { + //avatarURL: user.avatarURL, // optional, but preferred + email: req.user.email, + id: req.user.uid, + name: req.user.displayName || req.user.email + }; + return res.status(200).send(jwt.sign(userData, process.env.CANNY_PRIVATE_KEY, { algorithm: "HS256" })); + } catch (error) { + logger.log("sso-canny-error", "error", req?.user?.email, null, { + message: error.message, + stack: error.stack + }); + res.status(500).json({ error: error.message }); + } +}; + +module.exports = { + cannySsoHandler +};