Skip to content

Commit

Permalink
update yarn and update import paths (#14)
Browse files Browse the repository at this point in the history
* update yarn

* path aliases

* update to fix security issue

* there is no yarn test command

* added missing command

* fixed jest test alias resolving

* lint fix
  • Loading branch information
volarname authored May 20, 2024
1 parent 9b93f6f commit 21f6e2f
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 37 deletions.
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ module.exports = {
],
verbose: true,
setupFiles: ['<rootDir>/test/setup-tests.ts'],
moduleNameMapper: {
'@/(.*)': '<rootDir>/src/$1'
},
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -25,14 +25,15 @@
"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",
"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",
Expand All @@ -56,10 +57,11 @@
"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",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.6.2"
}
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/pubsub/notification-pub-sub.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/server/websocket-server.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/util/user-token-verifier.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion test/model/user-connections.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/pubsub/notification-pub-sub.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/server/websocket-server.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/setup-tests.ts
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"ts-node": {
"require": ["tsconfig-paths/register"]
},
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
Expand Down Expand Up @@ -31,6 +34,7 @@
"node_modules/@types"
],
"paths": {
"@/*": ["./src/*"],
"*": [
"node_modules/*"
]
Expand Down
41 changes: 30 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -5469,11 +5476,12 @@ __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"
tsconfig-paths: "npm:^4.2.0"
tslib: "npm:^2.6.2"
typedi: "npm:^0.10.0"
typescript: "npm:^5.3.3"
Expand Down Expand Up @@ -6004,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

Expand Down Expand Up @@ -6142,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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 21f6e2f

Please sign in to comment.