From ed1ca83f5b36e1e64e2918e7c4461b966e72d6d6 Mon Sep 17 00:00:00 2001 From: seaerchin <44049504+seaerchin@users.noreply.github.com> Date: Wed, 30 Mar 2022 12:26:28 +0800 Subject: [PATCH] feat(identity): infrastructure changes (#405) * chore(www.js): rename www -> www.js for ts to transpile it * build(package): changed start commands and added a build script the start command is retrieved from: https://stackoverflow.com/questions/61342753/paths-from-tsconfig-json-doesnt-work-after-tsc this is required because ts doesn't destructure the path aliases into the actual imports. * build(tsocnfig): updated tsconfig to emit this won't affect npm run dev as we are using ts-node and it will transpile on the fly * ci(ci): add step to build * chore(gitignore): ignore build drivre * fix(tsconfig): remove swc :( swc transpiles experimental flags (metadata/decorators) wrongly; this results in sequelize-typescript being transpiled wrongly * chore(authmiddlewareservice): remove logging of cookies --- .github/workflows/ci.yml | 2 + .gitignore | 3 +- bin/{www => www.js} | 0 package-lock.json | 158 +++++++++++------- package.json | 10 +- .../AuthMiddlewareService.js | 10 +- tsconfig.build.json | 11 ++ tsconfig.json | 5 +- 8 files changed, 131 insertions(+), 68 deletions(-) rename bin/{www => www.js} (100%) create mode 100644 tsconfig.build.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0eca591f..2304e915b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,8 @@ jobs: ${{ runner.OS }}- - name: Install NPM run: npm ci + - name: Build application + run: npm run build - name: Zip application run: zip -r "deploy.zip" * .platform -x .env-example .gitignore package-lock.json - name: Get timestamp diff --git a/.gitignore b/.gitignore index 1b2c41a16..c694bd6cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env node_modules/ -.vscode/ \ No newline at end of file +.vscode/ +build/ \ No newline at end of file diff --git a/bin/www b/bin/www.js similarity index 100% rename from bin/www rename to bin/www.js diff --git a/package-lock.json b/package-lock.json index e02cb426a..ce92e5d79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2401,104 +2401,144 @@ "@sinonjs/commons": "^1.7.0" } }, + "@swc/cli": { + "version": "0.1.56", + "resolved": "https://registry.npmjs.org/@swc/cli/-/cli-0.1.56.tgz", + "integrity": "sha512-CFQzS271l9LfLg8JwtN4l/ZNDbdcoS4xbgiRwh7Oxx2sRxWxE/6fJRTzXHw7Z2TDuyYtx+D0vwjyjulbePmTeg==", + "dev": true, + "requires": { + "commander": "^7.1.0", + "fast-glob": "^3.2.5", + "slash": "3.0.0", + "source-map": "^0.7.3" + }, + "dependencies": { + "source-map": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", + "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", + "dev": true + } + } + }, "@swc/core": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.2.152.tgz", - "integrity": "sha512-ZklzoNsvEUWqc73BdYvM+F97N+ghwa01Fd49Hpt6abqYz8ZCvXkY2Hloe0HuppCX4BKCaMDfCgDtWMBqCacSKw==", - "requires": { - "@swc/core-android-arm-eabi": "1.2.152", - "@swc/core-android-arm64": "1.2.152", - "@swc/core-darwin-arm64": "1.2.152", - "@swc/core-darwin-x64": "1.2.152", - "@swc/core-freebsd-x64": "1.2.152", - "@swc/core-linux-arm-gnueabihf": "1.2.152", - "@swc/core-linux-arm64-gnu": "1.2.152", - "@swc/core-linux-arm64-musl": "1.2.152", - "@swc/core-linux-x64-gnu": "1.2.152", - "@swc/core-linux-x64-musl": "1.2.152", - "@swc/core-win32-arm64-msvc": "1.2.152", - "@swc/core-win32-ia32-msvc": "1.2.152", - "@swc/core-win32-x64-msvc": "1.2.152" + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.2.160.tgz", + "integrity": "sha512-nXoC7HA+aY7AtBPsiqGXocoRLAzzA7MV+InWQtILN7Uru4hB9+rLnLCPc3zSdg7pgnxJLa1tHup1Rz7Vv6TcIQ==", + "dev": true, + "requires": { + "@swc/core-android-arm-eabi": "1.2.160", + "@swc/core-android-arm64": "1.2.160", + "@swc/core-darwin-arm64": "1.2.160", + "@swc/core-darwin-x64": "1.2.160", + "@swc/core-freebsd-x64": "1.2.160", + "@swc/core-linux-arm-gnueabihf": "1.2.160", + "@swc/core-linux-arm64-gnu": "1.2.160", + "@swc/core-linux-arm64-musl": "1.2.160", + "@swc/core-linux-x64-gnu": "1.2.160", + "@swc/core-linux-x64-musl": "1.2.160", + "@swc/core-win32-arm64-msvc": "1.2.160", + "@swc/core-win32-ia32-msvc": "1.2.160", + "@swc/core-win32-x64-msvc": "1.2.160" } }, "@swc/core-android-arm-eabi": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.2.152.tgz", - "integrity": "sha512-Vl4mHTL5mEDqPiJMLAqwsTvsl8aREudjUmEfjmM7C+ZcD0W+lNpzpZInbWIaVblNLj04wXoKR2JOpxUC43yy1Q==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.2.160.tgz", + "integrity": "sha512-VzFP7tYgvpkUhd8wgyNtERqvoPBBDretyMFxAxPe2SxClaBs9Ka95PdiPPZalRq+vFCb/dFxD8Vhz+XO16Kpjg==", + "dev": true, "optional": true }, "@swc/core-android-arm64": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm64/-/core-android-arm64-1.2.152.tgz", - "integrity": "sha512-+Xwe882tK1cyVViZhSNYSQmpLtuYIVGw2AvKsrP+VjWf9giiL4Y0Faj6w8KoC24THSxgSX2OTMzw71C+yduj2g==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-android-arm64/-/core-android-arm64-1.2.160.tgz", + "integrity": "sha512-m+xqQaa7TqW3Vm9MUvITtdU8OlAc/9yT+TgOS4l8WlfFI87IDnLLfinKKEp+xfKwzYDdIsh+sC+jdGdIBTMB+Q==", + "dev": true, "optional": true }, "@swc/core-darwin-arm64": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.2.152.tgz", - "integrity": "sha512-UGhzOz8KC3uT1Uzjttv9Gxd4bAXIgyjJ338eI0hxmwXDauoiPYK6PylhmQr91ExNmDnXJH4WkP9UME3fk5JgVg==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.2.160.tgz", + "integrity": "sha512-9bG70KYKvjNf7tZtjOu1h4kDZPtoidZptIXPGSHuUgJ1BbSJYpfRR5xAmq4k37+GqOjIPJp4+lSGQPa2HfejpA==", + "dev": true, "optional": true }, "@swc/core-darwin-x64": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.2.152.tgz", - "integrity": "sha512-2B18L/mD2I5r7OJJjZzikXrzj9+9+izRgSbg9Unwo33eUwtlKrk4gT/iV5FaNjHDeWpJ8+SPquFyic8Plq6rGQ==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.2.160.tgz", + "integrity": "sha512-+b4HdKAVf/XPZ9DjgG2axGLbquPEuYwEP3zeWgbWn0s0FYQ7WTFxznf3YrTJE9MYadJeCOs3U80E2xVAtRRS9Q==", + "dev": true, "optional": true }, "@swc/core-freebsd-x64": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-freebsd-x64/-/core-freebsd-x64-1.2.152.tgz", - "integrity": "sha512-fe/qqSX14uKFWYN/72BmjSl3DEgK1M5+bJnJpbHFoPePEf3Jv5Vwwo/dq6YxGf4ITo5O8++/9VAkq346vhAHAg==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-freebsd-x64/-/core-freebsd-x64-1.2.160.tgz", + "integrity": "sha512-E5agJwv+RVMoZ8FQIPSO5wLPDQx6jqcMpV207EB3pPaxPWGe4n3DH3vcibHp80RACDNdiaqo5lBeBnGJI4ithw==", + "dev": true, "optional": true }, "@swc/core-linux-arm-gnueabihf": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.2.152.tgz", - "integrity": "sha512-Vqn9O7AK9GlGGTwvJ8Ze+3XyDS/DSAnEVaC4VMk1c6fWh4xHXxmEdnhVGKt+nWpxU/mRir5ayTCcUSd/ia7ogw==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.2.160.tgz", + "integrity": "sha512-uCttZRNx+lWVhCYGC6/pGUej08g1SQc5am6R9NVFh111goytcdlPnC4jV8oWzq2QhDWkkKxLoP2CZOytzI4+0w==", + "dev": true, "optional": true }, "@swc/core-linux-arm64-gnu": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.2.152.tgz", - "integrity": "sha512-79hGkWLS0H2l6tMJpdsFacTh8PmHdRIg8vfs5cHn9mNvXTKLOrIHe9eUwiYGrM2XyYVQikebaXyJXjJIOoMw9Q==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.2.160.tgz", + "integrity": "sha512-sB18roiv8m/zsY6tXLSrbUls0eKkSkxOEF0ennXVEtz97rMJ+WWnkOc8gI+rUpj3MHbVAIxyDNyyZU4cH5g1jQ==", + "dev": true, "optional": true }, "@swc/core-linux-arm64-musl": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.2.152.tgz", - "integrity": "sha512-Rb81Ds1J+0swDrmqsL9dgowiNtVy+1Rf09kC9oKHSWYt2qXWacul8r42O5s1BPK8K5O/6ufj8stYU+g92YjARg==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.2.160.tgz", + "integrity": "sha512-PJ7Ukb+BRR3pGYcUag8qRWOB11eByc5YLx/xAMSc3bRmaYW/oj6s8k+1DYiR//BAuNQdf14MpMFzDuWiDEUh7A==", + "dev": true, "optional": true }, "@swc/core-linux-x64-gnu": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.2.152.tgz", - "integrity": "sha512-K8uOIO594Mpr9KXUVc7grGfT5KU3wh/BZwUVHBSVaYbCCgwxitHDDQR3KzvYpZSKjx/YwLwRWXZuo0dxmw+NcQ==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.2.160.tgz", + "integrity": "sha512-wVh8Q86xz3t0y5zoUryWQ64bFG/YxdcykBgaog8lU9xkFb1KSqVRE9ia7aKA12/ZtAfpJZLRBleZxBAcaCg9FQ==", + "dev": true, "optional": true }, "@swc/core-linux-x64-musl": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.2.152.tgz", - "integrity": "sha512-Q34NF30LM5vynfyCTZNR+Co0AT/0TsLoeXOxkroT9GOfQ+UcsawFs1ZCTBdX15Jv8MXrqZAw5FwcaSReuG58rw==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.2.160.tgz", + "integrity": "sha512-AnWdarl9WWuDdbc2AX1w76W1jaekSCokxRrWdSGUgQytaZRtybKZEgThvJCQDrSlYQD4XDOhhVRCurTvy4JsfQ==", + "dev": true, "optional": true }, "@swc/core-win32-arm64-msvc": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.2.152.tgz", - "integrity": "sha512-i9QaNgntUDDrgj8k3ZyUh3HjGgG3aKa2diPCKR+fPArfFpN352mW3pC4EgSj+gF0FdgmTPnRGzT/n/kq770xqg==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.2.160.tgz", + "integrity": "sha512-ScL27mZRTwEIqBIv9RY34nQvyBvhosiM5Lus4dCFmS71flPcAEv7hJgy4GE3YUQV0ryGNK9NaO43H8sAyNwKVQ==", + "dev": true, "optional": true }, "@swc/core-win32-ia32-msvc": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.2.152.tgz", - "integrity": "sha512-HFtEADtw8EF4Rcp87smgEcrm1h2bUVIMshN77K3nzNnjoKRqkTCXpcEaYWzW0pKovEDscHUGQ+YC7LVVAGayMA==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.2.160.tgz", + "integrity": "sha512-e75zbWlhlyrd5HdrYzELa6OlZxgyaVpJj+c9xMD95HcdklVbmsyt1vuqRxMyqaZUDLyehwwCDRX/ZeDme//M/A==", + "dev": true, "optional": true }, "@swc/core-win32-x64-msvc": { - "version": "1.2.152", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.2.152.tgz", - "integrity": "sha512-zdSzmtlwaJga/48KQncKIo9vH1miS40Gr/TJ2QGtMU7u3XyiFz/PL8BDYQFLqSEWSSRcAwVpm6Mucb30mvuf7Q==", + "version": "1.2.160", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.2.160.tgz", + "integrity": "sha512-GAYT+WzYQY4sr17S21yJh4flJp/sQ62mAs6RfN89p7jIWgm0Bl/SooRl6ocsftTlnZm7K7QC8zmQVeNCWDCLPw==", + "dev": true, "optional": true }, + "@swc/helpers": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.3.8.tgz", + "integrity": "sha512-aWItSZvJj4+GI6FWkjZR13xPNPctq2RRakzo+O6vN7bC2yjwdg5EFpgaSAUn95b7BGSgcflvzVDPoKmJv24IOg==", + "dev": true + }, "@tokenizer/token": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz", @@ -10296,6 +10336,12 @@ "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" }, + "regenerator-runtime": { + "version": "0.13.9", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz", + "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==", + "dev": true + }, "regexpp": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", diff --git a/package.json b/package.json index 203a5ad11..85645ac2e 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "version": "0.3.0", "private": true, "scripts": { - "start": "ts-node ./bin/www", + "build": "tsc -p tsconfig.build.json", + "start": "node -r ts-node/register/transpile-only -r tsconfig-paths/register build/bin/www.js", "dev:services": "docker compose up -d", - "dev": "source .env && ts-node-dev --respawn ./bin/www", + "dev": "source .env && ts-node-dev --respawn ./bin/www.js", "test": "source .env.test && jest", "release": "npm version $npm_config_isomer_update && git push --tags", "lint": "npx eslint .", @@ -16,7 +17,6 @@ }, "dependencies": { "@aws-sdk/client-secrets-manager": "^3.24.0", - "@swc/core": "^1.2.152", "auto-bind": "^4.0.0", "aws-sdk": "^2.946.0", "axios": "^0.21.3", @@ -64,6 +64,9 @@ "yaml": "^1.10.2" }, "devDependencies": { + "@swc/cli": "^0.1.56", + "@swc/core": "^1.2.160", + "@swc/helpers": "^0.3.8", "@tsconfig/recommended": "^1.0.1", "@types/express": "^4.17.13", "@types/jest": "^27.4.1", @@ -87,6 +90,7 @@ "jest-mock-axios": "^4.5.0", "lint-staged": "^11.1.2", "prettier": "2.2.1", + "regenerator-runtime": "^0.13.9", "sqlite3": "^5.0.2", "ts-jest": "^27.1.3", "ts-node-dev": "^1.1.8", diff --git a/services/middlewareServices/AuthMiddlewareService.js b/services/middlewareServices/AuthMiddlewareService.js index 4fdcf4095..7979ba629 100644 --- a/services/middlewareServices/AuthMiddlewareService.js +++ b/services/middlewareServices/AuthMiddlewareService.js @@ -64,20 +64,20 @@ class AuthMiddlewareService { const userId = retrievedId return { accessToken, userId } } catch (err) { + // NOTE: Cookies aren't being logged here because they get caught as "Object object", which is not useful + // The cookies should be converted to a JSON struct before logging if (err.name === "NotLoggedInError") { logger.error( - `Authentication error: user not logged in with email. Cookie: ${cookies}, Url: ${url}` + `Authentication error: user not logged in with email. Url: ${url}` ) throw new AuthError( `Authentication error: user not logged in with email` ) } else if (err.name === "TokenExpiredError") { - logger.error( - `Authentication error: JWT token expired. Cookie: ${cookies}, Url: ${url}` - ) + logger.error(`Authentication error: JWT token expired. Url: ${url}`) throw new AuthError(`JWT token has expired`) } else { - logger.error(`Authentication error. Cookie: ${cookies}, Url: ${url}`) + logger.error(`Authentication error. Url: ${url}`) } throw err } diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 000000000..d04a6d381 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,11 @@ +// Main tsconfig for building, prevents tests from being compiled. +{ + "extends": "./tsconfig.json", + "exclude": [ + "tests/", + "**/*.spec.ts", + "**/*.test.ts", + "**/__tests__/", + "**/__mocks__/" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 54c54c39c..a9a8c3c06 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,12 +7,12 @@ "skipLibCheck": true, "esModuleInterop": true, "strict": true, + "outDir": "build/", "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "commonjs", "moduleResolution": "node", "isolatedModules": true, - "noEmit": true, "downlevelIteration": true, "baseUrl": "./", "resolveJsonModule": true, @@ -37,8 +37,7 @@ }, "ts-node": { "require": ["tsconfig-paths/register"], - "transpileOnly": true, - "swc": true + "transpileOnly": true }, "exclude": ["node_modules", "dist"] }