From 5428b71a96d604c69021540a6b76420aaac00646 Mon Sep 17 00:00:00 2001 From: volar Date: Wed, 15 May 2024 11:24:22 +0200 Subject: [PATCH 1/7] update yarn --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db3b7b3..c22ca1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notification-server", - "packageManager": "yarn@4.1.1", + "packageManager": "yarn@4.2.2", "version": "1.1.0", "description": "", "license": "Apache-2.0", From d4d539874fa2e9898a3994adbb35220949ef80d8 Mon Sep 17 00:00:00 2001 From: volar Date: Wed, 15 May 2024 12:03:00 +0200 Subject: [PATCH 2/7] path aliases --- package.json | 1 + src/index.ts | 8 ++++---- src/pubsub/notification-pub-sub.ts | 4 ++-- src/server/websocket-server.ts | 8 ++++---- src/util/user-token-verifier.ts | 6 +++--- tsconfig.json | 4 ++++ yarn.lock | 21 ++++++++++++++++++++- 7 files changed, 38 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index c22ca1f..8410d2a 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "ts-jest": "^29.1.1", "ts-node": "^10.9.2", "tsc": "^2.0.4", + "tsconfig-paths": "^4.2.0", "tslib": "^2.6.2" } } diff --git a/src/index.ts b/src/index.ts index d15d73e..9dd0a5e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ import 'reflect-metadata' -import { Config } from './config/config' -import { NotificationPubSub } from './pubsub/notification-pub-sub' -import AppLogger from './logger/app-logger' import { Container } from 'typedi' -import { WebsocketServer } from './server/websocket-server' import ws from 'ws' +import AppLogger from '@/logger/app-logger' +import { Config } from '@/config/config' +import { NotificationPubSub } from '@/pubsub/notification-pub-sub' +import { WebsocketServer } from '@/server/websocket-server' declare module 'ws' { export interface WebSocket extends ws { diff --git a/src/pubsub/notification-pub-sub.ts b/src/pubsub/notification-pub-sub.ts index ce01d91..72a6767 100644 --- a/src/pubsub/notification-pub-sub.ts +++ b/src/pubsub/notification-pub-sub.ts @@ -1,7 +1,7 @@ import { Message, PubSub, Subscription, Topic } from '@google-cloud/pubsub' -import AppLogger from '../logger/app-logger' +import AppLogger from '@/logger/app-logger' import { Inject, Service } from 'typedi' -import { UserConnections } from '../model/user-connections' +import { UserConnections } from '@/model/user-connections' @Service() export class NotificationPubSub { diff --git a/src/server/websocket-server.ts b/src/server/websocket-server.ts index b41ef38..daeee8a 100644 --- a/src/server/websocket-server.ts +++ b/src/server/websocket-server.ts @@ -1,11 +1,11 @@ import http, { IncomingMessage, Server } from 'http' import WebSocket from 'ws' import stream from 'node:stream' -import { verifyAuthorization } from '../util/user-token-verifier' +import { verifyAuthorization } from '@/util/user-token-verifier' import { Inject, Service } from 'typedi' -import { UserConnections } from '../model/user-connections' -import AppLogger from '../logger/app-logger' -import { Config } from '../config/config' +import { UserConnections } from '@/model/user-connections' +import AppLogger from '@/logger/app-logger' +import { Config } from '@/config/config' // todo, better types - remove as diff --git a/src/util/user-token-verifier.ts b/src/util/user-token-verifier.ts index 06e994e..e6b282e 100644 --- a/src/util/user-token-verifier.ts +++ b/src/util/user-token-verifier.ts @@ -1,9 +1,9 @@ import jwt from 'jsonwebtoken' -import { Config } from '../config/config' +import { Config } from '@/config/config' import Cookies from 'cookies' import { IncomingMessage, ServerResponse } from 'http' -import { IUserToken } from '../model/user-token' -import AppLogger from '../logger/app-logger' +import { IUserToken } from '@/model/user-token' +import AppLogger from '@/logger/app-logger' export function verifyAuthorization(request: IncomingMessage, logger: AppLogger): IUserToken { const cookies = new Cookies(request, new ServerResponse(request)) diff --git a/tsconfig.json b/tsconfig.json index e0b50cb..f20cb5e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,7 @@ { + "ts-node": { + "require": ["tsconfig-paths/register"] + }, "compilerOptions": { "module": "commonjs", "esModuleInterop": true, @@ -31,6 +34,7 @@ "node_modules/@types" ], "paths": { + "@/*": ["./src/*"], "*": [ "node_modules/*" ] diff --git a/yarn.lock b/yarn.lock index c9c977a..29f1f98 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4783,7 +4783,7 @@ __metadata: languageName: node linkType: hard -"json5@npm:^2.2.3": +"json5@npm:^2.2.2, json5@npm:^2.2.3": version: 2.2.3 resolution: "json5@npm:2.2.3" bin: @@ -5193,6 +5193,13 @@ __metadata: languageName: node linkType: hard +"minimist@npm:^1.2.6": + version: 1.2.8 + resolution: "minimist@npm:1.2.8" + checksum: 10c0/19d3fcdca050087b84c2029841a093691a91259a47def2f18222f41e7645a0b7c44ef4b40e88a1e58a40c84d2ef0ee6047c55594d298146d0eb3f6b737c20ce6 + languageName: node + linkType: hard + "minipass-collect@npm:^1.0.2": version: 1.0.2 resolution: "minipass-collect@npm:1.0.2" @@ -5474,6 +5481,7 @@ __metadata: ts-jest: "npm:^29.1.1" ts-node: "npm:^10.9.2" tsc: "npm:^2.0.4" + tsconfig-paths: "npm:^4.2.0" tslib: "npm:^2.6.2" typedi: "npm:^0.10.0" typescript: "npm:^5.3.3" @@ -6895,6 +6903,17 @@ __metadata: languageName: node linkType: hard +"tsconfig-paths@npm:^4.2.0": + version: 4.2.0 + resolution: "tsconfig-paths@npm:4.2.0" + dependencies: + json5: "npm:^2.2.2" + minimist: "npm:^1.2.6" + strip-bom: "npm:^3.0.0" + checksum: 10c0/09a5877402d082bb1134930c10249edeebc0211f36150c35e1c542e5b91f1047b1ccf7da1e59babca1ef1f014c525510f4f870de7c9bda470c73bb4e2721b3ea + languageName: node + linkType: hard + "tslib@npm:^2.6.2": version: 2.6.2 resolution: "tslib@npm:2.6.2" From 40278b37a5401a5250f968c941fbc440b2c35bbf Mon Sep 17 00:00:00 2001 From: volar Date: Fri, 17 May 2024 18:04:03 +0200 Subject: [PATCH 3/7] update to fix security issue --- package.json | 4 ++-- yarn.lock | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 8410d2a..d16965c 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "cookies": "^0.9.1", "dotenv": "^16.3.1", "jsonwebtoken": "^9.0.2", - "reflect-metadata": "^0.2.1", + "reflect-metadata": "^0.2.2", "typedi": "^0.10.0", "typescript": "^5.3.3", "winston": "^3.11.0", @@ -56,7 +56,7 @@ "nodemon": "^3.0.2", "npm-run-all": "^4.1.5", "prettier": "^3.1.1", - "rimraf": "^5.0.5", + "rimraf": "^5.0.7", "ts-jest": "^29.1.1", "ts-node": "^10.9.2", "tsc": "^2.0.4", diff --git a/yarn.lock b/yarn.lock index 29f1f98..95c37bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5476,8 +5476,8 @@ __metadata: nodemon: "npm:^3.0.2" npm-run-all: "npm:^4.1.5" prettier: "npm:^3.1.1" - reflect-metadata: "npm:^0.2.1" - rimraf: "npm:^5.0.5" + reflect-metadata: "npm:^0.2.2" + rimraf: "npm:^5.0.7" ts-jest: "npm:^29.1.1" ts-node: "npm:^10.9.2" tsc: "npm:^2.0.4" @@ -6012,10 +6012,10 @@ __metadata: languageName: node linkType: hard -"reflect-metadata@npm:^0.2.1": - version: 0.2.1 - resolution: "reflect-metadata@npm:0.2.1" - checksum: 10c0/6ca3c674bb43cf8ec3a3f5f38c8730a6116335f8e562fcdcdf3a492af168c5a7f0e8f17476a5710c3fe6bf9b5d22e8a463f14c0e26e326339cab65e099900ef7 +"reflect-metadata@npm:^0.2.2": + version: 0.2.2 + resolution: "reflect-metadata@npm:0.2.2" + checksum: 10c0/1cd93a15ea291e420204955544637c264c216e7aac527470e393d54b4bb075f10a17e60d8168ec96600c7e0b9fcc0cb0bb6e91c3fbf5b0d8c9056f04e6ac1ec2 languageName: node linkType: hard @@ -6150,14 +6150,14 @@ __metadata: languageName: node linkType: hard -"rimraf@npm:^5.0.5": - version: 5.0.5 - resolution: "rimraf@npm:5.0.5" +"rimraf@npm:^5.0.7": + version: 5.0.7 + resolution: "rimraf@npm:5.0.7" dependencies: glob: "npm:^10.3.7" bin: rimraf: dist/esm/bin.mjs - checksum: 10c0/d50dbe724f33835decd88395b25ed35995077c60a50ae78ded06e0185418914e555817aad1b4243edbff2254548c2f6ad6f70cc850040bebb4da9e8cc016f586 + checksum: 10c0/bd6dbfaa98ae34ce1e54d1e06045d2d63e8859d9a1979bb4a4628b652b459a2d17b17dc20ee072b034bd2d09bd691e801d24c4d9cfe94e16fdbcc8470a1d4807 languageName: node linkType: hard From 32d8a9bc0e46f64ecb2b4e55168b0eaf652161a1 Mon Sep 17 00:00:00 2001 From: volar Date: Fri, 17 May 2024 18:08:06 +0200 Subject: [PATCH 4/7] there is no yarn test command --- .github/workflows/node.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 6aec923..c861495 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -47,5 +47,5 @@ jobs: - name: Run Security check run: yarn npm audit - - name: Run Yarn Tests - run: yarn test +# - name: Run Yarn Tests +# run: yarn test From 8a215c92d5bb956e42ceb5c7819ba14d3b12d3d9 Mon Sep 17 00:00:00 2001 From: volar Date: Fri, 17 May 2024 18:09:57 +0200 Subject: [PATCH 5/7] added missing command --- .github/workflows/node.yml | 4 ++-- package.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index c861495..6aec923 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -47,5 +47,5 @@ jobs: - name: Run Security check run: yarn npm audit -# - name: Run Yarn Tests -# run: yarn test + - name: Run Yarn Tests + run: yarn test diff --git a/package.json b/package.json index d16965c..93f28f0 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "production": "yarn build", "prod": "NODE_OPTIONS=\"--max-old-space-size=200\" node dist/index.js --max-http-header-size=16000", "dev": "TS_NODE=true NODE_OPTIONS=\"-r ts-node/register\" node src/index.ts --max-http-header-size=16000", - "watch": "nodemon --watch src -e ts --exec yarn dev" + "watch": "nodemon --watch src -e ts --exec yarn dev", + "test": "jest --coverage=true --runInBand" }, "dependencies": { "@google-cloud/pubsub": "^4.1.1", From 3ff58259433c44c1c8037bf7243ed64b225d8af6 Mon Sep 17 00:00:00 2001 From: volar Date: Fri, 17 May 2024 18:17:55 +0200 Subject: [PATCH 6/7] fixed jest test alias resolving --- jest.config.js | 3 +++ test/model/user-connections.test.ts | 2 +- test/pubsub/notification-pub-sub.test.ts | 6 +++--- test/server/websocket-server.test.ts | 8 ++++---- test/setup-tests.ts | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/jest.config.js b/jest.config.js index 46e79d2..7492798 100644 --- a/jest.config.js +++ b/jest.config.js @@ -18,4 +18,7 @@ module.exports = { ], verbose: true, setupFiles: ['/test/setup-tests.ts'], + moduleNameMapper: { + "@/(.*)": "/src/$1" + }, } diff --git a/test/model/user-connections.test.ts b/test/model/user-connections.test.ts index 093d6c4..99fdc50 100644 --- a/test/model/user-connections.test.ts +++ b/test/model/user-connections.test.ts @@ -1,4 +1,4 @@ -import { UserConnections } from '../../src/model/user-connections' +import { UserConnections } from '@/model/user-connections' import { WebSocket } from 'ws' describe('model/user-connections test', () => { diff --git a/test/pubsub/notification-pub-sub.test.ts b/test/pubsub/notification-pub-sub.test.ts index 9a7b4d6..dadf0e6 100644 --- a/test/pubsub/notification-pub-sub.test.ts +++ b/test/pubsub/notification-pub-sub.test.ts @@ -1,7 +1,7 @@ -import { UserConnections } from '../../src/model/user-connections' +import { UserConnections } from '@/model/user-connections' import { PubSub } from '@google-cloud/pubsub' -import { NotificationPubSub } from '../../src/pubsub/notification-pub-sub' -import AppLogger from '../../src/logger/app-logger' +import { NotificationPubSub } from '@/pubsub/notification-pub-sub' +import AppLogger from '@/logger/app-logger' import { WebSocket } from 'ws' describe('pubsub/notification-pub-sub test', () => { diff --git a/test/server/websocket-server.test.ts b/test/server/websocket-server.test.ts index 5ef17ac..910522b 100644 --- a/test/server/websocket-server.test.ts +++ b/test/server/websocket-server.test.ts @@ -1,8 +1,8 @@ import { WebSocket } from 'ws' -import { WebsocketServer } from '../../src/server/websocket-server' -import { UserConnections } from '../../src/model/user-connections' -import { Config } from '../../src/config/config' -import AppLogger from '../../src/logger/app-logger' +import { WebsocketServer } from '@/server/websocket-server' +import { UserConnections } from '@/model/user-connections' +import { Config } from '@/config/config' +import AppLogger from '@/logger/app-logger' import jwt from 'jsonwebtoken' class WebSocketClient extends WebSocket { diff --git a/test/setup-tests.ts b/test/setup-tests.ts index 2bbd85c..ef40a05 100644 --- a/test/setup-tests.ts +++ b/test/setup-tests.ts @@ -1,6 +1,6 @@ import 'reflect-metadata' import { initPubSubMock } from './_mock/mq' -import { Config } from '../src/config/config' +import { Config } from '@/config/config' Config.loadEnv('test') From 633f804b0cc56703f4fb1fec574fc6c2a5b9ea1e Mon Sep 17 00:00:00 2001 From: volar Date: Fri, 17 May 2024 18:20:27 +0200 Subject: [PATCH 7/7] lint fix --- jest.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 7492798..368af8d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,6 +19,6 @@ module.exports = { verbose: true, setupFiles: ['/test/setup-tests.ts'], moduleNameMapper: { - "@/(.*)": "/src/$1" + '@/(.*)': '/src/$1' }, }