From 538198840c7db9ce32a95d7f95c5e8e3975d3e6a Mon Sep 17 00:00:00 2001 From: Suman991 Date: Thu, 16 Apr 2026 15:02:18 +0530 Subject: [PATCH] added basic auth, schemas and some ws event handling --- package-lock.json | 785 +++++++++++++++++- package.json | 13 +- src/app.module.ts | 25 +- src/auth/auth.controller.ts | 38 + src/auth/auth.module.ts | 23 + src/auth/auth.service.ts | 45 + src/auth/dto/create-auth.dto.ts | 1 + src/auth/dto/update-auth.dto.ts | 4 + src/chat/chat.gateway.ts | 184 ++++ src/chat/chat.module.ts | 20 + src/chat/chat.service.ts | 6 + src/chat/dto/chat-message.dto.ts | 9 + src/chat/dto/join-leave-room.dto.ts | 12 + src/chat/dto/room-message.dto.ts | 13 + src/chat/guards/ws-jwt.guard.ts | 20 + src/conversations/conversations.controller.ts | 34 + src/conversations/conversations.module.ts | 18 + src/conversations/conversations.service.ts | 34 + .../dto/create-conversation.dto.ts | 1 + .../dto/update-conversation.dto.ts | 4 + .../schemas/conversation.schema.ts | 27 + src/main.ts | 33 +- src/messages/dto/create-message.dto.ts | 1 + src/messages/dto/update-message.dto.ts | 4 + src/messages/messages.controller.ts | 34 + src/messages/messages.module.ts | 17 + src/messages/messages.service.ts | 30 + src/messages/schemas/message.schema.ts | 19 + src/users/dto/create-user.dto.ts | 9 + src/users/dto/update-user.dto.ts | 4 + src/users/schemas/user.schema.ts | 11 + src/users/users.controller.ts | 34 + src/users/users.module.ts | 18 + src/users/users.service.ts | 33 + 34 files changed, 1552 insertions(+), 11 deletions(-) create mode 100644 src/auth/auth.controller.ts create mode 100644 src/auth/auth.module.ts create mode 100644 src/auth/auth.service.ts create mode 100644 src/auth/dto/create-auth.dto.ts create mode 100644 src/auth/dto/update-auth.dto.ts create mode 100644 src/chat/chat.gateway.ts create mode 100644 src/chat/chat.module.ts create mode 100644 src/chat/chat.service.ts create mode 100644 src/chat/dto/chat-message.dto.ts create mode 100644 src/chat/dto/join-leave-room.dto.ts create mode 100644 src/chat/dto/room-message.dto.ts create mode 100644 src/chat/guards/ws-jwt.guard.ts create mode 100644 src/conversations/conversations.controller.ts create mode 100644 src/conversations/conversations.module.ts create mode 100644 src/conversations/conversations.service.ts create mode 100644 src/conversations/dto/create-conversation.dto.ts create mode 100644 src/conversations/dto/update-conversation.dto.ts create mode 100644 src/conversations/schemas/conversation.schema.ts create mode 100644 src/messages/dto/create-message.dto.ts create mode 100644 src/messages/dto/update-message.dto.ts create mode 100644 src/messages/messages.controller.ts create mode 100644 src/messages/messages.module.ts create mode 100644 src/messages/messages.service.ts create mode 100644 src/messages/schemas/message.schema.ts create mode 100644 src/users/dto/create-user.dto.ts create mode 100644 src/users/dto/update-user.dto.ts create mode 100644 src/users/schemas/user.schema.ts create mode 100644 src/users/users.controller.ts create mode 100644 src/users/users.module.ts create mode 100644 src/users/users.service.ts diff --git a/package-lock.json b/package-lock.json index 5647559..5eb98a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,10 +10,21 @@ "license": "UNLICENSED", "dependencies": { "@nestjs/common": "^11.0.1", + "@nestjs/config": "^4.0.4", "@nestjs/core": "^11.0.1", + "@nestjs/jwt": "^11.0.2", + "@nestjs/mapped-types": "*", + "@nestjs/mongoose": "^11.0.4", "@nestjs/platform-express": "^11.0.1", + "@nestjs/platform-socket.io": "^11.1.19", + "@nestjs/swagger": "^11.3.0", + "@nestjs/websockets": "^11.1.19", + "class-transformer": "^0.5.1", + "class-validator": "^0.15.1", + "mongoose": "^9.4.1", "reflect-metadata": "^0.2.2", - "rxjs": "^7.8.1" + "rxjs": "^7.8.1", + "socket.io": "^4.8.3" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", @@ -2041,6 +2052,21 @@ "node": ">=8" } }, + "node_modules/@microsoft/tsdoc": { + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.16.0.tgz", + "integrity": "sha512-xgAyonlVVS+q7Vc7qLW0UrJU7rSFcETRWsqdXZtjzRU8dF+6CkozTK4V4y1LwOX7j8r/vHphjDeMeGI4tNGeGA==", + "license": "MIT" + }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.4.6", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.6.tgz", + "integrity": "sha512-y+x3H1xBZd38n10NZF/rEBlvDOOMQ6LKUTHqr8R9VkJ+mmQOYtJFxIlkkK8fZrtOiL6VixbOBWMbZGBdal3Z1g==", + "license": "MIT", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, "node_modules/@napi-rs/wasm-runtime": { "version": "0.2.12", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.12.tgz", @@ -2301,6 +2327,21 @@ } } }, + "node_modules/@nestjs/config": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@nestjs/config/-/config-4.0.4.tgz", + "integrity": "sha512-CJPjNitr0bAufSEnRe2N+JbnVmMmDoo6hvKCPzXgZoGwJSmp/dZPk9f/RMbuD/+Q1ZJPjwsRpq0vxna++Knwow==", + "license": "MIT", + "dependencies": { + "dotenv": "17.4.1", + "dotenv-expand": "12.0.3", + "lodash": "4.18.1" + }, + "peerDependencies": { + "@nestjs/common": "^10.0.0 || ^11.0.0", + "rxjs": "^7.1.0" + } + }, "node_modules/@nestjs/core": { "version": "11.1.19", "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-11.1.19.tgz", @@ -2342,6 +2383,51 @@ } } }, + "node_modules/@nestjs/jwt": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/@nestjs/jwt/-/jwt-11.0.2.tgz", + "integrity": "sha512-rK8aE/3/Ma45gAWfCksAXUNbOoSOUudU0Kn3rT39htPF7wsYXtKfjALKeKKJbFrIWbLjsbqfXX5bIJNvgBugGA==", + "license": "MIT", + "dependencies": { + "@types/jsonwebtoken": "9.0.10", + "jsonwebtoken": "9.0.3" + }, + "peerDependencies": { + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0" + } + }, + "node_modules/@nestjs/mapped-types": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.1.1.tgz", + "integrity": "sha512-SCCoMEJ6jdeI5h/N+KCVF1+pmg/hmEkNA5nHTS8Gvww7T/LCl4o1gFLinw2iQ60w7slFkszHcGLKGdazVI4F8A==", + "license": "MIT", + "peerDependencies": { + "@nestjs/common": "^10.0.0 || ^11.0.0", + "class-transformer": "^0.4.0 || ^0.5.0", + "class-validator": "^0.13.0 || ^0.14.0 || ^0.15.0", + "reflect-metadata": "^0.1.12 || ^0.2.0" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, + "node_modules/@nestjs/mongoose": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/@nestjs/mongoose/-/mongoose-11.0.4.tgz", + "integrity": "sha512-LUOlUeSOfbjdIu22QwOmczv2CzJQr9LUBo2mOfbXrGCu2svpr5Hiu71zBFrb/9UC+H8BjGMKbBOq1nEbMF6ZJA==", + "license": "MIT", + "peerDependencies": { + "@nestjs/common": "^10.0.0 || ^11.0.0", + "@nestjs/core": "^10.0.0 || ^11.0.0", + "mongoose": "^7.0.0 || ^8.0.0 || ^9.0.0", + "rxjs": "^7.0.0" + } + }, "node_modules/@nestjs/platform-express": { "version": "11.1.19", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-11.1.19.tgz", @@ -2363,6 +2449,25 @@ "@nestjs/core": "^11.0.0" } }, + "node_modules/@nestjs/platform-socket.io": { + "version": "11.1.19", + "resolved": "https://registry.npmjs.org/@nestjs/platform-socket.io/-/platform-socket.io-11.1.19.tgz", + "integrity": "sha512-gu1nPIEaP5Qjjg/Cl8wXyvwGpdZGzgbtK4KcH65YRAA+GTKUkIHb4BNpLJ27Ymq/wqLJKNEbCjajfzD0BEjMGA==", + "license": "MIT", + "dependencies": { + "socket.io": "4.8.3", + "tslib": "2.8.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^11.0.0", + "@nestjs/websockets": "^11.0.0", + "rxjs": "^7.1.0" + } + }, "node_modules/@nestjs/schematics": { "version": "11.0.10", "resolved": "https://registry.npmjs.org/@nestjs/schematics/-/schematics-11.0.10.tgz", @@ -2461,6 +2566,39 @@ "tslib": "^2.1.0" } }, + "node_modules/@nestjs/swagger": { + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-11.3.0.tgz", + "integrity": "sha512-SCS8fG2DL/ZF+9l5in09FwPhpBo5i1Gdo8Se3GYlJ2cn+iNTzF7u13QjHo5XI92BN8DN+Gcug+QTcmWmGvZyNw==", + "license": "MIT", + "dependencies": { + "@microsoft/tsdoc": "0.16.0", + "@nestjs/mapped-types": "2.1.1", + "js-yaml": "4.1.1", + "lodash": "4.18.1", + "path-to-regexp": "8.4.2", + "swagger-ui-dist": "5.32.4" + }, + "peerDependencies": { + "@fastify/static": "^8.0.0 || ^9.0.0", + "@nestjs/common": "^11.0.1", + "@nestjs/core": "^11.0.1", + "class-transformer": "*", + "class-validator": "*", + "reflect-metadata": "^0.1.12 || ^0.2.0" + }, + "peerDependenciesMeta": { + "@fastify/static": { + "optional": true + }, + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, "node_modules/@nestjs/testing": { "version": "11.1.19", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-11.1.19.tgz", @@ -2489,6 +2627,29 @@ } } }, + "node_modules/@nestjs/websockets": { + "version": "11.1.19", + "resolved": "https://registry.npmjs.org/@nestjs/websockets/-/websockets-11.1.19.tgz", + "integrity": "sha512-2qo8jtIwwwgkqAI1BtnJ02EaFLrRkKA39eYXS8IhZCHilhBHCWdjnJ5cLcFq4oF+s+KZ7LcLGD/3stxJy8ijzg==", + "license": "MIT", + "dependencies": { + "iterare": "1.2.1", + "object-hash": "3.0.0", + "tslib": "2.8.1" + }, + "peerDependencies": { + "@nestjs/common": "^11.0.0", + "@nestjs/core": "^11.0.0", + "@nestjs/platform-socket.io": "^11.0.0", + "reflect-metadata": "^0.1.12 || ^0.2.0", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "@nestjs/platform-socket.io": { + "optional": true + } + } + }, "node_modules/@noble/hashes": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz", @@ -2552,6 +2713,13 @@ "url": "https://opencollective.com/pkgr" } }, + "node_modules/@scarf/scarf": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.4.0.tgz", + "integrity": "sha512-xxeapPiUXdZAE3che6f3xogoJPeZgig6omHEy1rIY5WVsB3H2BHNnZH+gHG6x91SCWyQCzWGsuL2Hh3ClO5/qQ==", + "hasInstallScript": true, + "license": "Apache-2.0" + }, "node_modules/@sinclair/typebox": { "version": "0.34.49", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.49.tgz", @@ -2579,6 +2747,12 @@ "@sinonjs/commons": "^3.0.1" } }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz", + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==", + "license": "MIT" + }, "node_modules/@tokenizer/inflate": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/@tokenizer/inflate/-/inflate-0.4.1.tgz", @@ -2714,6 +2888,15 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/cors": { + "version": "2.8.19", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz", + "integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/eslint": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.1.tgz", @@ -2820,6 +3003,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/jsonwebtoken": { + "version": "9.0.10", + "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz", + "integrity": "sha512-asx5hIG9Qmf/1oStypjanR7iKTv0gXQ1Ov/jfrX6kS/EO0OFni8orbmGCn0672NHR3kXHwpAwR+B368ZGN/2rA==", + "license": "MIT", + "dependencies": { + "@types/ms": "*", + "@types/node": "*" + } + }, "node_modules/@types/methods": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/@types/methods/-/methods-1.1.4.tgz", @@ -2827,11 +3020,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/ms": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", + "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", + "license": "MIT" + }, "node_modules/@types/node": { "version": "24.12.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-24.12.2.tgz", "integrity": "sha512-A1sre26ke7HDIuY/M23nd9gfB+nrmhtYyMINbjI1zHJxYteKR6qSMX56FsmjMcDb3SMcjJg5BiRRgOCC/yBD0g==", - "dev": true, "license": "MIT", "dependencies": { "undici-types": "~7.16.0" @@ -2903,6 +3101,36 @@ "@types/superagent": "^8.1.0" } }, + "node_modules/@types/validator": { + "version": "13.15.10", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.15.10.tgz", + "integrity": "sha512-T8L6i7wCuyoK8A/ZeLYt1+q0ty3Zb9+qbSSvrIVitzT3YjZqkTZ40IbRsPanlB4h1QB3JVL1SYCdR6ngtFYcuA==", + "license": "MIT" + }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==", + "license": "MIT" + }, + "node_modules/@types/whatwg-url": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==", + "license": "MIT", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, + "node_modules/@types/ws": { + "version": "8.18.1", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz", + "integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/yargs": { "version": "17.0.35", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.35.tgz", @@ -3890,7 +4118,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true, "license": "Python-2.0" }, "node_modules/array-timsort": { @@ -4041,6 +4268,15 @@ ], "license": "MIT" }, + "node_modules/base64id": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", + "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", + "license": "MIT", + "engines": { + "node": "^4.5.0 || >= 5.9" + } + }, "node_modules/baseline-browser-mapping": { "version": "2.10.19", "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.19.tgz", @@ -4171,6 +4407,15 @@ "node-int64": "^0.4.0" } }, + "node_modules/bson": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-7.2.0.tgz", + "integrity": "sha512-YCEo7KjMlbNlyHhz7zAZNDpIpQbd+wOEHJYezv0nMYTn4x31eIUM2yomNNubclAt63dObUzKHWsBLJ9QcZNSnQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=20.19.0" + } + }, "node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", @@ -4196,6 +4441,12 @@ "ieee754": "^1.1.13" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", + "license": "BSD-3-Clause" + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -4375,6 +4626,23 @@ "dev": true, "license": "MIT" }, + "node_modules/class-transformer": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", + "license": "MIT" + }, + "node_modules/class-validator": { + "version": "0.15.1", + "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.15.1.tgz", + "integrity": "sha512-LqoS80HBBSCVhz/3KloUly0ovokxpdOLR++Al3J3+dHXWt9sTKlKd4eYtoxhxyUjoe5+UcIM+5k9MIxyBWnRTw==", + "license": "MIT", + "dependencies": { + "@types/validator": "^13.15.3", + "libphonenumber-js": "^1.11.1", + "validator": "^13.15.22" + } + }, "node_modules/cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -4818,6 +5086,45 @@ "node": ">=0.3.1" } }, + "node_modules/dotenv": { + "version": "17.4.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.1.tgz", + "integrity": "sha512-k8DaKGP6r1G30Lx8V4+pCsLzKr8vLmV2paqEj1Y55GdAgJuIqpRp5FfajGF8KtwMxCz9qJc6wUIJnm053d/WCw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dotenv-expand": { + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-12.0.3.tgz", + "integrity": "sha512-uc47g4b+4k/M/SeaW1y4OApx+mtLWl92l5LMPP0GNXctZqELk+YGgOPIIC5elYmUH4OuoK3JLhuRUYegeySiFA==", + "license": "BSD-2-Clause", + "dependencies": { + "dotenv": "^16.4.5" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dotenv-expand/node_modules/dotenv": { + "version": "16.6.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", + "integrity": "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -4839,6 +5146,15 @@ "dev": true, "license": "MIT" }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -4881,6 +5197,79 @@ "node": ">= 0.8" } }, + "node_modules/engine.io": { + "version": "6.6.6", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.6.tgz", + "integrity": "sha512-U2SN0w3OpjFRVlrc17E6TMDmH58Xl9rai1MblNjAdwWp07Kk+llmzX0hjDpQdrDGzwmvOtgM5yI+meYX6iZ2xA==", + "license": "MIT", + "dependencies": { + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "@types/ws": "^8.5.12", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.7.2", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.18.3" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/engine.io-parser": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/engine.io/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==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/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==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/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==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/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==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/enhanced-resolve": { "version": "5.20.1", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.20.1.tgz", @@ -7067,7 +7456,6 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==", - "dev": true, "license": "MIT", "dependencies": { "argparse": "^2.0.1" @@ -7150,6 +7538,58 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jsonwebtoken": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", + "license": "MIT", + "dependencies": { + "jws": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/kareem": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-3.2.0.tgz", + "integrity": "sha512-VS8MWZz/cT+SqBCpVfNN4zoVz5VskR3N4+sTmUXme55e9avQHntpwpNq0yjnosISXqwJ3AQVjlbI4Dyzv//JtA==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -7184,6 +7624,12 @@ "node": ">= 0.8.0" } }, + "node_modules/libphonenumber-js": { + "version": "1.12.41", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.12.41.tgz", + "integrity": "sha512-lsmMmGXBxXIK/VMLEj0kL6MtUs1kBGj1nTCzi6zgQoG1DEwqwt2DQyHxcLykceIxAnfE3hya7NuIh6PpC6S3fA==", + "license": "MIT" + }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", @@ -7244,7 +7690,42 @@ "version": "4.18.1", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", - "dev": true, + "license": "MIT" + }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==", + "license": "MIT" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==", + "license": "MIT" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==", + "license": "MIT" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==", + "license": "MIT" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", + "license": "MIT" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==", "license": "MIT" }, "node_modules/lodash.memoize": { @@ -7261,6 +7742,12 @@ "dev": true, "license": "MIT" }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", + "license": "MIT" + }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -7362,6 +7849,12 @@ "node": ">= 4.0.0" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "license": "MIT" + }, "node_modules/merge-descriptors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", @@ -7499,6 +7992,104 @@ "node": ">=16 || 14 >=14.17" } }, + "node_modules/mongodb": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.1.1.tgz", + "integrity": "sha512-067DXiMjcpYQl6bGjWQoTUEE9UoRViTtKFcoqX7z08I+iDZv/emH1g8XEFiO3qiDfXAheT5ozl1VffDTKhIW/w==", + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.3.0", + "bson": "^7.1.1", + "mongodb-connection-string-url": "^7.0.0" + }, + "engines": { + "node": ">=20.19.0" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.806.0", + "@mongodb-js/zstd": "^7.0.0", + "gcp-metadata": "^7.0.1", + "kerberos": "^7.0.0", + "mongodb-client-encryption": ">=7.0.0 <7.1.0", + "snappy": "^7.3.2", + "socks": "^2.8.6" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.1.tgz", + "integrity": "sha512-h0AZ9A7IDVwwHyMxmdMXKy+9oNlF0zFoahHiX3vQ8e3KFcSP3VmsmfvtRSuLPxmyv2vjIDxqty8smTgie/SNRQ==", + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^13.0.0", + "whatwg-url": "^14.1.0" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/mongoose": { + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.4.1.tgz", + "integrity": "sha512-4rFBWa+/wdBQSfvnOPJBpiSG6UCEbhSQh865dEdaH9Y8WfHBUC+I2XT28dp0IBIGrEwmh+gzrgZgea5PbmrHWA==", + "license": "MIT", + "dependencies": { + "kareem": "3.2.0", + "mongodb": "~7.1", + "mpath": "0.9.0", + "mquery": "6.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-6.0.0.tgz", + "integrity": "sha512-b2KQNsmgtkscfeDgkYMcWGn9vZI9YoXh802VDEwE6qc50zxBFQ0Oo8ROkawbPAsXCY1/Z1yp0MagqsZStPWJjw==", + "license": "MIT", + "engines": { + "node": ">=20.19.0" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -7679,6 +8270,15 @@ "node": ">=0.10.0" } }, + "node_modules/object-hash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz", + "integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==", + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, "node_modules/object-inspect": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", @@ -8130,7 +8730,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -8381,7 +8980,6 @@ "version": "7.7.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", - "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -8536,6 +9134,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", + "license": "MIT" + }, "node_modules/signal-exit": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", @@ -8559,6 +9163,90 @@ "node": ">=8" } }, + "node_modules/socket.io": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.3.tgz", + "integrity": "sha512-2Dd78bqzzjE6KPkD5fHZmDAKRNe3J15q+YHDrIsy9WEkqttc7GY+kT9OBLSMaPbQaEd0x1BjcmtMtXkfpc+T5A==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.4.1", + "engine.io": "~6.6.0", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/socket.io-adapter": { + "version": "2.5.6", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.6.tgz", + "integrity": "sha512-DkkO/dz7MGln0dHn5bmN3pPy+JmywNICWrJqVWiVOyvXjWQFIv9c2h24JrQLLFJ2aQVQf/Cvl1vblnd4r2apLQ==", + "license": "MIT", + "dependencies": { + "debug": "~4.4.1", + "ws": "~8.18.3" + } + }, + "node_modules/socket.io-parser": { + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.6.tgz", + "integrity": "sha512-asJqbVBDsBCJx0pTqw3WfesSY0iRX+2xzWEWzrpcH7L6fLzrhyF8WPI8UaeM4YCuDfpwA/cgsdugMsmtz8EJeg==", + "license": "MIT", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.4.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io/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==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/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==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/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==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/socket.io/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==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/source-map": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", @@ -8590,6 +9278,15 @@ "node": ">=0.10.0" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "license": "MIT", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -8816,6 +9513,15 @@ "node": ">=8" } }, + "node_modules/swagger-ui-dist": { + "version": "5.32.4", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.32.4.tgz", + "integrity": "sha512-0AADFFQNJzExEN49SrD/34Nn9cxNxVLiydYl2MBwSZFPVXNkVwC/EFAjoezGGqE8oDegiDC+p47t8lKObCinMQ==", + "license": "Apache-2.0", + "dependencies": { + "@scarf/scarf": "=1.4.0" + } + }, "node_modules/symbol-observable": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", @@ -9123,6 +9829,18 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/ts-api-utils": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz", @@ -9450,7 +10168,6 @@ "version": "7.16.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", - "dev": true, "license": "MIT" }, "node_modules/universalify": { @@ -9576,6 +10293,15 @@ "node": ">=10.12.0" } }, + "node_modules/validator": { + "version": "13.15.35", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.15.35.tgz", + "integrity": "sha512-TQ5pAGhd5whStmqWvYF4OjQROlmv9SMFVt37qoCBdqRffuuklWYQlCNnEs2ZaIBD1kZRNnikiZOS1eqgkar0iw==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -9619,6 +10345,15 @@ "defaults": "^1.0.3" } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/webpack": { "version": "5.106.1", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.106.1.tgz", @@ -9820,6 +10555,19 @@ "url": "https://opencollective.com/webpack" } }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -9907,6 +10655,27 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 604b94a..86ed12c 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,21 @@ }, "dependencies": { "@nestjs/common": "^11.0.1", + "@nestjs/config": "^4.0.4", "@nestjs/core": "^11.0.1", + "@nestjs/jwt": "^11.0.2", + "@nestjs/mapped-types": "*", + "@nestjs/mongoose": "^11.0.4", "@nestjs/platform-express": "^11.0.1", + "@nestjs/platform-socket.io": "^11.1.19", + "@nestjs/swagger": "^11.3.0", + "@nestjs/websockets": "^11.1.19", + "class-transformer": "^0.5.1", + "class-validator": "^0.15.1", + "mongoose": "^9.4.1", "reflect-metadata": "^0.2.2", - "rxjs": "^7.8.1" + "rxjs": "^7.8.1", + "socket.io": "^4.8.3" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", diff --git a/src/app.module.ts b/src/app.module.ts index 8662803..445790d 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,9 +1,32 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; +import { UsersModule } from './users/users.module'; +import { ConversationsModule } from './conversations/conversations.module'; +import { MessagesModule } from './messages/messages.module'; +import { ChatModule } from './chat/chat.module'; +import { AuthModule } from './auth/auth.module'; +import { MongooseModule } from '@nestjs/mongoose'; +import { ConfigModule, ConfigService } from '@nestjs/config'; @Module({ - imports: [], + imports: [ + ConfigModule.forRoot({ isGlobal: true }), //access env anywhere + + // connect db + MongooseModule.forRootAsync({ + inject: [ConfigService], + useFactory: (configService: ConfigService) => ({ + uri: configService.get('DB_URI'), + }), + }), + UsersModule, + ConversationsModule, + MessagesModule, + ChatModule, + AuthModule, + + ], controllers: [AppController], providers: [AppService], }) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts new file mode 100644 index 0000000..e5a71fd --- /dev/null +++ b/src/auth/auth.controller.ts @@ -0,0 +1,38 @@ +import { UsersService } from './../users/users.service'; +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { AuthService } from './auth.service'; +import { ApiOperation } from '@nestjs/swagger'; +import { CreateUserDto } from 'src/users/dto/create-user.dto'; + +@Controller('auth') +export class AuthController { + constructor(private readonly authService: AuthService, + + ) {} + + @Post('/token') + @ApiOperation({ summary: 'sign in', description: 'Authenticates a user Returns a JWT access token.' }) + create(@Body() createUserDto: CreateUserDto ) { + return this.authService.create(createUserDto); + } + + // @Get() + // findAll() { + // return this.authService.findAll(); + // } + + // @Get(':id') + // findOne(@Param('id') id: string) { + // return this.authService.findOne(+id); + // } + + // @Patch(':id') + // update(@Param('id') id: string, @Body() updateAuthDto: UpdateAuthDto) { + // return this.authService.update(+id, updateAuthDto); + // } + + // @Delete(':id') + // remove(@Param('id') id: string) { + // return this.authService.remove(+id); + // } +} diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts new file mode 100644 index 0000000..ef63d25 --- /dev/null +++ b/src/auth/auth.module.ts @@ -0,0 +1,23 @@ +import { Module } from '@nestjs/common'; +import { AuthService } from './auth.service'; +import { AuthController } from './auth.controller'; +import { UsersService } from 'src/users/users.service'; +import { JwtModule, JwtService } from '@nestjs/jwt'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { UsersModule } from 'src/users/users.module'; + +@Module({ + imports:[UsersModule, + JwtModule.registerAsync({ + imports: [ConfigModule], + inject: [ConfigService], + useFactory: (config: ConfigService) => ({ + secret: config.get('JWT_SECRET'), + signOptions: { expiresIn: config.get('JWT_EXPIRES_IN', '7') }, + }), + }), + ], + controllers: [AuthController], + providers: [AuthService], +}) +export class AuthModule {} diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts new file mode 100644 index 0000000..466a166 --- /dev/null +++ b/src/auth/auth.service.ts @@ -0,0 +1,45 @@ +import { CreateUserDto } from './../users/dto/create-user.dto'; +import { User } from './../users/schemas/user.schema'; +import { UsersService } from './../users/users.service'; +import { Injectable } from '@nestjs/common'; +import { UpdateAuthDto } from './dto/update-auth.dto'; +import { JwtService } from '@nestjs/jwt'; + +@Injectable() +export class AuthService { + constructor( + private readonly usersService: UsersService, + private readonly jwtService: JwtService, + ) {} + + async create(createUserDto: CreateUserDto) { + // check if user exist + let user=await this.usersService.findOne(createUserDto.name) + if(!user){ + user = await this.usersService.create(createUserDto); + } + const token = this.jwtService.sign({ + // sub: user.name.toLowerCase().replace(/\s+/g, '-'), // as name is unique + sub:user._id, // mongodb id + username: user.name, + }); + + return { token, username: user.name }; + } + + findAll() { + return `This action returns all auth`; + } + + findOne(id: number) { + return `This action returns a #${id} auth`; + } + + update(id: number, updateAuthDto: UpdateAuthDto) { + return `This action updates a #${id} auth`; + } + + remove(id: number) { + return `This action removes a #${id} auth`; + } +} diff --git a/src/auth/dto/create-auth.dto.ts b/src/auth/dto/create-auth.dto.ts new file mode 100644 index 0000000..00ef00f --- /dev/null +++ b/src/auth/dto/create-auth.dto.ts @@ -0,0 +1 @@ +export class CreateAuthDto {} diff --git a/src/auth/dto/update-auth.dto.ts b/src/auth/dto/update-auth.dto.ts new file mode 100644 index 0000000..100de4f --- /dev/null +++ b/src/auth/dto/update-auth.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateAuthDto } from './create-auth.dto'; + +export class UpdateAuthDto extends PartialType(CreateAuthDto) {} diff --git a/src/chat/chat.gateway.ts b/src/chat/chat.gateway.ts new file mode 100644 index 0000000..cef8972 --- /dev/null +++ b/src/chat/chat.gateway.ts @@ -0,0 +1,184 @@ +import { + WebSocketGateway, + SubscribeMessage, + MessageBody, + OnGatewayInit, + OnGatewayConnection, + OnGatewayDisconnect, + WebSocketServer, + WsException, + ConnectedSocket, +} from '@nestjs/websockets'; +import { ChatService } from './chat.service'; +import { Server, Socket } from 'socket.io'; +import { Logger, UseGuards } from '@nestjs/common'; +import { JwtService } from '@nestjs/jwt'; +import { JoinLeaveRoomDto } from './dto/join-leave-room.dto'; +import { WsJwtGuard } from './guards/ws-jwt.guard'; +import { RoomMessageDto } from './dto/room-message.dto'; + +@WebSocketGateway({ + namespace: '/chat', + cors: { origin: '*' }, +}) +export class ChatGateway + implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect +{ + constructor( + private readonly chatService: ChatService, + private readonly jwtService: JwtService, + ) {} + + @WebSocketServer() + server!: Server; + + private readonly logger = new Logger(ChatGateway.name); + + private users = new Map(); // {socketId:{userId:'12rt3',username:'suman'}} + + afterInit(server: Server) { + this.logger.log('/chat namespace initialized'); + // server.setMaxListeners(20); + } + + handleConnection(client: Socket) { + try { + // st-1: Extract token + const token = + client.handshake.auth?.token || client.handshake.headers?.authorization; // fallback + + if (!token) { + throw new WsException('No token provided'); + } + // strip 'Bearer' prefix if present + const rawToken = token.replace(/^Bearer\s+/i, ''); + + // st-2: verify jwt + const payload = this.jwtService.verify(rawToken); + + // st-3:attach user to client + client.data.user = { + id: payload.sub, // mongo id + username: payload.username, + }; + // in memeory + this.users.set(client.id, { + userId: payload.sub, + username: payload.username, + }); + + this.logger.log(`[+] Authenticated: ${payload.username} (${client.id})`); + // tell the new client their own info + client.emit('connected', { + YourId: client.id, + username: payload.username, + message: `welcome, ${payload.username}`, + }); + + // tell everyone else someone joined + client.broadcast.emit('serverNotice', `[+] ${payload.username} joined`); + + } catch (err) { + // st-4: Disconnect unauthorized clients + this.logger.warn(`[!] Rejected connection: ${err}`); + client.emit('authError', { + mesage: err || 'Unauthorized', + }); + + client.disconnect(); + } + } + + handleDisconnect(client: Socket) { + const user = this.users.get(client.id); + if (user) { + this.users.delete(client.id); + this.logger.log(`[-] Disconnected: ${user.username} (${client.id})`); + this.server.emit('serverNotice', `[-] ${user.username} left`); + } + } + + @UseGuards(WsJwtGuard) + @SubscribeMessage('joinRoom') + handleJoinRoom( + @MessageBody() body: JoinLeaveRoomDto, //roomId + @ConnectedSocket() client: Socket, + ) { + + // extract user + const username=client.data.user.username; + + // join user in the room(front-end will provide roomId(standard appraoch)) + client.join(body.roomId) + + // tell the joiner he successfully joined + client.emit("roomJoined",{ + roomId:body.roomId, + message:`You joined room: ${body.roomId}`, + }) + + // also tell others in the room except the new joiner + client.to(body.roomId).emit("roomNotice",{ + roomId: body.roomId, + message: `[+] ${username} joined the room`, + }) + + // return acknowledgement + return { success: true, roomId: body.roomId }; + + } + + @UseGuards(WsJwtGuard) + @SubscribeMessage('leaveRoom') + handleLeaveRoom( + @MessageBody() body: JoinLeaveRoomDto, //roomId + @ConnectedSocket() client: Socket, + ) { + // extract user + const username=client.data.user.username; + + // remove the user from the room + client.leave(body.roomId) + + // confirm to the leaver + client.emit('roomLeft', { roomId: body.roomId }); + + // Notify remaining memebers only + client.to(body.roomId).emit('roomNotice', { + roomId: body.roomId, + message: `[-] ${username} left the room`, + }); + + return { success: true, roomId: body.roomId }; + } + + @UseGuards(WsJwtGuard) + @SubscribeMessage('roomMessage') + handleRoomMessage( + @MessageBody() body:RoomMessageDto, //text:string + @ConnectedSocket() sender:Socket + ){ + // extract user + const username=sender.data.user.username + // Check if user is in room + const isMember = sender.rooms.has(body.roomId); + if (!isMember) { + sender.emit('roomError', { + message: 'You are not allowed', + }); + return; + } + + this.logger.log(`[ROOM:${body.roomId}] ${username}: ${body.text}`); + + // send everone in the room(including the sender) + this.server.to(body.roomId).emit('roomMessage', { + roomId: body.roomId, + senderId: sender.id, + username, + text: body.text, + }); + + } + +} diff --git a/src/chat/chat.module.ts b/src/chat/chat.module.ts new file mode 100644 index 0000000..93bd78b --- /dev/null +++ b/src/chat/chat.module.ts @@ -0,0 +1,20 @@ +import { Module } from '@nestjs/common'; +import { ChatService } from './chat.service'; +import { ChatGateway } from './chat.gateway'; +import { JwtModule } from '@nestjs/jwt'; +import { ConfigModule, ConfigService } from '@nestjs/config'; + +@Module({ + imports: [ + JwtModule.registerAsync({ + imports: [ConfigModule], + inject: [ConfigService], + useFactory: (config: ConfigService) => ({ + secret: config.get('JWT_SECRET'), + signOptions: { expiresIn: config.get('JWT_EXPIRES_IN', '7') }, + }), + }), + ], + providers: [ChatGateway, ChatService], +}) +export class ChatModule {} diff --git a/src/chat/chat.service.ts b/src/chat/chat.service.ts new file mode 100644 index 0000000..dfe1c2b --- /dev/null +++ b/src/chat/chat.service.ts @@ -0,0 +1,6 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class ChatService { + +} diff --git a/src/chat/dto/chat-message.dto.ts b/src/chat/dto/chat-message.dto.ts new file mode 100644 index 0000000..94d009f --- /dev/null +++ b/src/chat/dto/chat-message.dto.ts @@ -0,0 +1,9 @@ +import { IsNotEmpty, IsString, MaxLength, MinLength } from 'class-validator'; + +export class ChatMessageDto { + @IsString({ message: 'text must be a string' }) + @IsNotEmpty({ message: 'text cannot be empty' }) + @MinLength(1, { message: 'Message is too short' }) + @MaxLength(500, { message: 'Message cannot exceed 500 characters' }) + text!: string; +} diff --git a/src/chat/dto/join-leave-room.dto.ts b/src/chat/dto/join-leave-room.dto.ts new file mode 100644 index 0000000..36d52a9 --- /dev/null +++ b/src/chat/dto/join-leave-room.dto.ts @@ -0,0 +1,12 @@ +import { IsNotEmpty, IsString, Matches, MaxLength } from "class-validator"; + +export class JoinLeaveRoomDto { + @IsString() + @IsNotEmpty({ message: 'roomId cannot be empty' }) + @MaxLength(50, { message: 'Room name too long (max 50 chars)' }) + @Matches(/^[a-z0-9-_]+$/, { + message: + 'roomId can only contain lowercase letters, numbers, hyphens and underscores', + }) + roomId!: string; +} diff --git a/src/chat/dto/room-message.dto.ts b/src/chat/dto/room-message.dto.ts new file mode 100644 index 0000000..45bd08e --- /dev/null +++ b/src/chat/dto/room-message.dto.ts @@ -0,0 +1,13 @@ +import { IsNotEmpty, IsString, Matches, MaxLength, MinLength } from "class-validator"; +export class RoomMessageDto { + @IsString() + @IsNotEmpty() + @Matches(/^[a-z0-9-_]+$/, { message: 'Invalid roomId format' }) + roomId!: string; + + @IsString() + @IsNotEmpty({ message: 'Message cannot be empty' }) + @MinLength(1) + @MaxLength(500, { message: 'Message cannot exceed 500 characters' }) + text!: string; +} \ No newline at end of file diff --git a/src/chat/guards/ws-jwt.guard.ts b/src/chat/guards/ws-jwt.guard.ts new file mode 100644 index 0000000..2cf9b50 --- /dev/null +++ b/src/chat/guards/ws-jwt.guard.ts @@ -0,0 +1,20 @@ +import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; +import { WsException } from '@nestjs/websockets'; +import { Socket } from 'socket.io'; + +@Injectable() +export class WsJwtGuard implements CanActivate { + canActivate(context: ExecutionContext): boolean { + const client: Socket = context.switchToWs().getClient(); + + // client.data.user was set in handleConnection() after JWT verification + const user = client.data?.user; + if (!user) { + throw new WsException('Unauthorized — no authenticated user on socket'); + } + + // optionally check role + + return true; + } +} diff --git a/src/conversations/conversations.controller.ts b/src/conversations/conversations.controller.ts new file mode 100644 index 0000000..c228d20 --- /dev/null +++ b/src/conversations/conversations.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { ConversationsService } from './conversations.service'; +import { CreateConversationDto } from './dto/create-conversation.dto'; +import { UpdateConversationDto } from './dto/update-conversation.dto'; + +@Controller('conversations') +export class ConversationsController { + constructor(private readonly conversationsService: ConversationsService) {} + + @Post() + create(@Body() createConversationDto: CreateConversationDto) { + return this.conversationsService.create(createConversationDto); + } + + @Get() + findAll() { + return this.conversationsService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.conversationsService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateConversationDto: UpdateConversationDto) { + return this.conversationsService.update(+id, updateConversationDto); + } + + @Delete(':id') + remove(@Param('id') id: string) { + return this.conversationsService.remove(+id); + } +} diff --git a/src/conversations/conversations.module.ts b/src/conversations/conversations.module.ts new file mode 100644 index 0000000..61ae2f6 --- /dev/null +++ b/src/conversations/conversations.module.ts @@ -0,0 +1,18 @@ +import { Module } from '@nestjs/common'; +import { ConversationsService } from './conversations.service'; +import { ConversationsController } from './conversations.controller'; +import { MongooseModule } from '@nestjs/mongoose'; +import { Conversation, ConversationSchema } from './schemas/conversation.schema'; + +@Module({ + imports:[ + MongooseModule.forFeature([ + {name:Conversation.name,schema:ConversationSchema}, + + ]) + ], + controllers: [ConversationsController], + providers: [ConversationsService], + exports:[ConversationsService] +}) +export class ConversationsModule {} diff --git a/src/conversations/conversations.service.ts b/src/conversations/conversations.service.ts new file mode 100644 index 0000000..9ddc013 --- /dev/null +++ b/src/conversations/conversations.service.ts @@ -0,0 +1,34 @@ +import { Injectable } from '@nestjs/common'; +import { CreateConversationDto } from './dto/create-conversation.dto'; +import { UpdateConversationDto } from './dto/update-conversation.dto'; +import { Conversation, ConversationDocument } from './schemas/conversation.schema'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; + +@Injectable() +export class ConversationsService { + + constructor( + @InjectModel(Conversation.name) private userModel: Model, + + ) {} + create(createConversationDto: CreateConversationDto) { + return 'This action adds a new conversation'; + } + + findAll() { + return `This action returns all conversations`; + } + + findOne(id: number) { + return `This action returns a #${id} conversation`; + } + + update(id: number, updateConversationDto: UpdateConversationDto) { + return `This action updates a #${id} conversation`; + } + + remove(id: number) { + return `This action removes a #${id} conversation`; + } +} diff --git a/src/conversations/dto/create-conversation.dto.ts b/src/conversations/dto/create-conversation.dto.ts new file mode 100644 index 0000000..8b3bd5d --- /dev/null +++ b/src/conversations/dto/create-conversation.dto.ts @@ -0,0 +1 @@ +export class CreateConversationDto {} diff --git a/src/conversations/dto/update-conversation.dto.ts b/src/conversations/dto/update-conversation.dto.ts new file mode 100644 index 0000000..9fc1952 --- /dev/null +++ b/src/conversations/dto/update-conversation.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateConversationDto } from './create-conversation.dto'; + +export class UpdateConversationDto extends PartialType(CreateConversationDto) {} diff --git a/src/conversations/schemas/conversation.schema.ts b/src/conversations/schemas/conversation.schema.ts new file mode 100644 index 0000000..2705fb8 --- /dev/null +++ b/src/conversations/schemas/conversation.schema.ts @@ -0,0 +1,27 @@ +import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; + +export type ConversationDocument = Conversation & Document; + export enum ConversationType{ + P2P='p2p', + GROUP='group' + } + +@Schema({ timestamps: true }) +export class Conversation { + @Prop({ + type:String, + enum:ConversationType, + required:true + }) + type!:ConversationType + + @Prop({type:[String], required:true}) + participants!:string[] + + @Prop({required:false,default:null}) + name!:string // for p2p no name + + createdAt!:Date +} + +export const ConversationSchema = SchemaFactory.createForClass(Conversation); diff --git a/src/main.ts b/src/main.ts index f76bc8d..20a6cb7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,39 @@ +import { ConfigService } from '@nestjs/config'; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; +import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; +import { ValidationPipe } from '@nestjs/common'; async function bootstrap() { const app = await NestFactory.create(AppModule); - await app.listen(process.env.PORT ?? 3000); + app.enableCors({ origin: '*' }); + app.useGlobalPipes( + new ValidationPipe({ + whitelist:true, // strips unknown properties from @Body() + forbidNonWhitelisted:true, // throws 400 if unknown props are sent + transform:true // converts query string numbers/booleans from strings → correct types + }) + ) + const config = new DocumentBuilder() + .setTitle('Chat app') + .setDescription('The chat API description') + .setVersion('1.0') + // .addBearerAuth( + // { + // type: 'http', + // scheme: 'bearer', + // bearerFormat: 'JWT', + // in: 'header', + // }, + // 'jwt', + // ) + .build(); + const document = SwaggerModule.createDocument(app, config); + SwaggerModule.setup('api', app, document); + + const configService=app.get(ConfigService) + const port=configService.get('PORT')|| 3000; + + await app.listen(port); } bootstrap(); diff --git a/src/messages/dto/create-message.dto.ts b/src/messages/dto/create-message.dto.ts new file mode 100644 index 0000000..6ae798f --- /dev/null +++ b/src/messages/dto/create-message.dto.ts @@ -0,0 +1 @@ +export class CreateMessageDto {} diff --git a/src/messages/dto/update-message.dto.ts b/src/messages/dto/update-message.dto.ts new file mode 100644 index 0000000..a8b82f0 --- /dev/null +++ b/src/messages/dto/update-message.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateMessageDto } from './create-message.dto'; + +export class UpdateMessageDto extends PartialType(CreateMessageDto) {} diff --git a/src/messages/messages.controller.ts b/src/messages/messages.controller.ts new file mode 100644 index 0000000..0f46d06 --- /dev/null +++ b/src/messages/messages.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { MessagesService } from './messages.service'; +import { CreateMessageDto } from './dto/create-message.dto'; +import { UpdateMessageDto } from './dto/update-message.dto'; + +@Controller('messages') +export class MessagesController { + constructor(private readonly messagesService: MessagesService) {} + + @Post() + create(@Body() createMessageDto: CreateMessageDto) { + return this.messagesService.create(createMessageDto); + } + + @Get() + findAll() { + return this.messagesService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.messagesService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateMessageDto: UpdateMessageDto) { + return this.messagesService.update(+id, updateMessageDto); + } + + @Delete(':id') + remove(@Param('id') id: string) { + return this.messagesService.remove(+id); + } +} diff --git a/src/messages/messages.module.ts b/src/messages/messages.module.ts new file mode 100644 index 0000000..b3fc8dd --- /dev/null +++ b/src/messages/messages.module.ts @@ -0,0 +1,17 @@ +import { Module } from '@nestjs/common'; +import { MessagesService } from './messages.service'; +import { MessagesController } from './messages.controller'; +import { MongooseModule } from '@nestjs/mongoose'; +import { Message, MessageSchema } from './schemas/message.schema'; + +@Module({ + imports:[ + MongooseModule.forFeature([ + {name:Message.name,schema:MessageSchema}, + ]) + ], + controllers: [MessagesController], + providers: [MessagesService], + exports:[MessagesService] +}) +export class MessagesModule {} diff --git a/src/messages/messages.service.ts b/src/messages/messages.service.ts new file mode 100644 index 0000000..71d9066 --- /dev/null +++ b/src/messages/messages.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@nestjs/common'; +import { CreateMessageDto } from './dto/create-message.dto'; +import { UpdateMessageDto } from './dto/update-message.dto'; +import { InjectModel } from '@nestjs/mongoose'; +import { Message, MessageDocument } from './schemas/message.schema'; +import { Model } from 'mongoose'; + +@Injectable() +export class MessagesService { + constructor( @InjectModel(Message.name) private MessageModel: Model,){} + create(createMessageDto: CreateMessageDto) { + return 'This action adds a new message'; + } + + findAll() { + return `This action returns all messages`; + } + + findOne(id: number) { + return `This action returns a #${id} message`; + } + + update(id: number, updateMessageDto: UpdateMessageDto) { + return `This action updates a #${id} message`; + } + + remove(id: number) { + return `This action removes a #${id} message`; + } +} diff --git a/src/messages/schemas/message.schema.ts b/src/messages/schemas/message.schema.ts new file mode 100644 index 0000000..e00a31c --- /dev/null +++ b/src/messages/schemas/message.schema.ts @@ -0,0 +1,19 @@ +import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; + +export type MessageDocument = Message & Document; + +@Schema({timestamps:true}) +export class Message { + @Prop({ required:true}) + conversationId!:string + + @Prop({ required:true}) + senderId!:string + + @Prop({ required:false}) + text!:string + + createdAt!:Date +} + +export const MessageSchema = SchemaFactory.createForClass(Message); diff --git a/src/users/dto/create-user.dto.ts b/src/users/dto/create-user.dto.ts new file mode 100644 index 0000000..420cab6 --- /dev/null +++ b/src/users/dto/create-user.dto.ts @@ -0,0 +1,9 @@ +import {IsNotEmpty, IsString } from 'class-validator'; +import { ApiProperty } from '@nestjs/swagger'; + +export class CreateUserDto { + @ApiProperty({ example: 'Jane Doe', description: 'Full name of the user' }) + @IsNotEmpty() + @IsString() + name!: string; +} diff --git a/src/users/dto/update-user.dto.ts b/src/users/dto/update-user.dto.ts new file mode 100644 index 0000000..dfd37fb --- /dev/null +++ b/src/users/dto/update-user.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateUserDto } from './create-user.dto'; + +export class UpdateUserDto extends PartialType(CreateUserDto) {} diff --git a/src/users/schemas/user.schema.ts b/src/users/schemas/user.schema.ts new file mode 100644 index 0000000..8de074e --- /dev/null +++ b/src/users/schemas/user.schema.ts @@ -0,0 +1,11 @@ +import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; +import { Document } from 'mongoose'; + +export type UserDocument = User & Document; + +@Schema({timestamps:true}) +export class User { + @Prop({required:true, unique:true}) + name!:string +} +export const UserSchema = SchemaFactory.createForClass(User); \ No newline at end of file diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts new file mode 100644 index 0000000..92aee89 --- /dev/null +++ b/src/users/users.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { UsersService } from './users.service'; +import { CreateUserDto } from './dto/create-user.dto'; +import { UpdateUserDto } from './dto/update-user.dto'; + +@Controller('users') +export class UsersController { + constructor(private readonly usersService: UsersService) {} + + // @Post() + // create(@Body() createUserDto: CreateUserDto) { + // return this.usersService.create(createUserDto); + // } + + @Get() + findAll() { + return this.usersService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.usersService.findOne(id); + } + + // @Patch(':id') + // update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) { + // return this.usersService.update(+id, updateUserDto); + // } + + // @Delete(':id') + // remove(@Param('id') id: string) { + // return this.usersService.remove(+id); + // } +} diff --git a/src/users/users.module.ts b/src/users/users.module.ts new file mode 100644 index 0000000..97eed0d --- /dev/null +++ b/src/users/users.module.ts @@ -0,0 +1,18 @@ +import { Module } from '@nestjs/common'; +import { UsersService } from './users.service'; +import { UsersController } from './users.controller'; +import { MongooseModule } from '@nestjs/mongoose'; +import { User, UserSchema } from './schemas/user.schema'; + +@Module({ + imports:[ + MongooseModule.forFeature([ + {name:User.name,schema:UserSchema}, + + ]) + ], + controllers: [UsersController], + providers: [UsersService], + exports:[UsersService] +}) +export class UsersModule {} diff --git a/src/users/users.service.ts b/src/users/users.service.ts new file mode 100644 index 0000000..00ad1a2 --- /dev/null +++ b/src/users/users.service.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@nestjs/common'; +import { CreateUserDto } from './dto/create-user.dto'; +import { UpdateUserDto } from './dto/update-user.dto'; +import { User, UserDocument } from './schemas/user.schema'; +import { Model } from 'mongoose'; +import { InjectModel } from '@nestjs/mongoose'; + +@Injectable() +export class UsersService { + + constructor(@InjectModel(User.name) private userModel:Model){ + + } + async create(createUserDto: CreateUserDto):Promise { + return await this.userModel.create(createUserDto) + } + + findAll() { + return `This action returns all users`; + } + + async findOne(name: string):Promise { + return await this.userModel.findOne({name}).exec() + } + + // update(id: number, updateUserDto: UpdateUserDto) { + // return `This action updates a #${id} user`; + // } + + // remove(id: number) { + // return `This action removes a #${id} user`; + // } +}