From 0490bf9145f092f33fdc73d2155c70f352aa9dd4 Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Fri, 7 Apr 2023 14:01:59 +0530 Subject: [PATCH 1/8] feat: add readme --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..704d1b06 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# FullStack Assignment \ No newline at end of file From 4a7fc586c9752f3e56cdd1361bae7af6b9a89df3 Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Fri, 7 Apr 2023 20:28:07 +0530 Subject: [PATCH 2/8] feat: added signup and login routes --- .env.example | 1 + .gitignore | 1 + controllers/authController.js | 78 +++ index.js | 94 +-- middlewares/validators.js | 12 + models/User.js | 3 + package-lock.json | 1180 ++++++++++++++++++++++++++++++++- package.json | 6 +- routes/authRoutes.js | 14 + 9 files changed, 1346 insertions(+), 43 deletions(-) create mode 100644 .env.example create mode 100644 controllers/authController.js create mode 100644 middlewares/validators.js create mode 100644 models/User.js create mode 100644 routes/authRoutes.js diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..2224db35 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +Create a .env file and add "JWT_SECRET" as variable name \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3c3629e6..1dcef2d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.env \ No newline at end of file diff --git a/controllers/authController.js b/controllers/authController.js new file mode 100644 index 00000000..d08fb8ad --- /dev/null +++ b/controllers/authController.js @@ -0,0 +1,78 @@ +const { validationResult } = require("express-validator"); +const USERS = require("../models/User"); +const bcrypt = require("bcrypt"); + +exports.signup = async (req, res) => { + // Check for validation errors + const errors = validationResult(req); + + console.log(req.body); + + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + + // Check if user already exists + const existingUser = USERS.find((user) => user.email === req.body.email); + if (existingUser) { + return res + .status(409) + .json({ message: "User with this email already exists" }); + } + + try { + // Hash password + const hashedPassword = await bcrypt.hash(req.body.password, 10); + + // Add user to USERS array + USERS.push({ email: req.body.email, password: hashedPassword }); + + // Send success response + res.sendStatus(201); + } catch (error) { + // Handle errors + console.error(error); + res.status(500).json({ message: "Internal server error" }); + } +}; + +exports.signin = async (req, res) => { + // Check for validation errors + const errors = validationResult(req); + + console.log(req.body); + + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { email, password } = req.body; + + try { + // Check if user exists in USERS array + const user = await USERS.find(); + if (!user) { + return res.status(401).json({ msg: "Invalid email or password" }); + } + + // Check if password is correct + const isMatch = await bcrypt.compare(password, user.password); + if (!isMatch) { + return res.status(401).json({ msg: "Invalid email or password" }); + } + + // Generate JSON Web Token (JWT) + const payload = { + user: { + id: user.id, + }, + }; + const token = jwt.sign(payload, process.env.JWT_SECRET, { + expiresIn: "1h", + }); + + res.json({ token }); + } catch (err) { + console.error(err.message); + res.status(500).send("Server Error"); + } +}; diff --git a/index.js b/index.js index e189e725..429e899b 100644 --- a/index.js +++ b/index.js @@ -1,68 +1,80 @@ const express = require('express') -const app = express() -const port = 3001 +require("dotenv").config(); +const authRoutes = require("./routes/authRoutes"); +const app = express(); +const port = 3001; -const USERS = []; - -const QUESTIONS = [{ +const QUESTIONS = [ + { title: "Two states", description: "Given an array , return the maximum of the array?", - testCases: [{ + testCases: [ + { input: "[1,2,3,4,5]", - output: "5" - }] -}]; - + output: "5", + }, + ], + }, +]; const SUBMISSION = [ + // { + // userId: '', + // questionId:'', + // code:'' + // status:'' + // } +]; + +app.use(express.json()); -] +app.use(authRoutes); -app.post('/signup', function(req, res) { - // Add logic to decode body - // body should have email and password +// app.post('/signup', function(req, res) { +// // Add logic to decode body +// // body should have email and password - //Store email and password (as is for now) in the USERS array above (only if the user with the given email doesnt exist) +// //Store email and password (as is for now) in the USERS array above (only if the user with the given email doesnt exist) - // return back 200 status code to the client - res.send('Hello World!') -}) +// // return back 200 status code to the client +// res.send('Hello World!') +// }) -app.post('/login', function(req, res) { - // Add logic to decode body - // body should have email and password +// app.post('/login', function(req, res) { +// // Add logic to decode body +// // body should have email and password - // Check if the user with the given email exists in the USERS array - // Also ensure that the password is the same +// // Check if the user with the given email exists in the USERS array +// // Also ensure that the password is the same - // If the password is the same, return back 200 status code to the client - // Also send back a token (any random string will do for now) - // If the password is not the same, return back 401 status code to the client +// // If the password is the same, return back 200 status code to the client +// // Also send back a token (any random string will do for now) +// // If the password is not the same, return back 401 status code to the client - res.send('Hello World from route 2!') -}) +// res.send('Hello World from route 2!') +// }) -app.get('/questions', function(req, res) { +// app.get('/questions', function(req, res) { - //return the user all the questions in the QUESTIONS array - res.send("Hello World from route 3!") -}) +// //return the user all the questions in the QUESTIONS array +// res.send("Hello World from route 3!") +// }) -app.get("/submissions", function(req, res) { - // return the users submissions for this problem - res.send("Hello World from route 4!") -}); +// app.get("/submissions", function(req, res) { +// // return the users submissions for this problem +// res.send("Hello World from route 4!") +// }); -app.post("/submissions", function(req, res) { - // let the user submit a problem, randomly accept or reject the solution - // Store the submission in the SUBMISSION array above - res.send("Hello World from route 4!") -}); +// app.post("/submissions", function(req, res) { +// // let the user submit a problem, randomly accept or reject the solution +// // Store the submission in the SUBMISSION array above +// res.send("Hello World from route 4!") +// }); // leaving as hard todos // Create a route that lets an admin add a new problem diff --git a/middlewares/validators.js b/middlewares/validators.js new file mode 100644 index 00000000..77d63fc8 --- /dev/null +++ b/middlewares/validators.js @@ -0,0 +1,12 @@ +const { body } = require("express-validator"); + +//Adding validation and santization + +exports.emailValidation = body("email") + .isEmail() + .normalizeEmail() + .withMessage("Invalid email address"); +exports.passwordValidation = body("password") + .isLength({ min: 8 }) + .escape() + .withMessage("Password must be at least 8 characters long"); diff --git a/models/User.js b/models/User.js new file mode 100644 index 00000000..bc93bd51 --- /dev/null +++ b/models/User.js @@ -0,0 +1,3 @@ +let USERS = []; + +module.exports = USERS; diff --git a/package-lock.json b/package-lock.json index e52b99a3..0e2ef565 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,37 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "express": "^4.18.2" + "bcrypt": "^5.1.0", + "dotenv": "^16.0.3", + "express": "^4.18.2", + "express-validator": "^6.15.0", + "jsonwebtoken": "^9.0.0" } }, + "node_modules/@mapbox/node-pre-gyp": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz", + "integrity": "sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==", + "dependencies": { + "detect-libc": "^2.0.0", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.7", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + }, + "bin": { + "node-pre-gyp": "bin/node-pre-gyp" + } + }, + "node_modules/abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -24,11 +52,86 @@ "node": ">= 0.6" } }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/agent-base/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/agent-base/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/aproba": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", + "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==" + }, + "node_modules/are-we-there-yet": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", + "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/bcrypt": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-5.1.0.tgz", + "integrity": "sha512-RHBS7HI5N5tEnGTmtR/pppX0mmDSBpQ4aCBsj7CEQfYXDcO74A8sIBYcJMuCsis2E81zDxeENYhv66oZwLiA+Q==", + "hasInstallScript": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.10", + "node-addon-api": "^5.0.0" + }, + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/body-parser": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", @@ -52,6 +155,20 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "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==" + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -72,6 +189,32 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "engines": { + "node": ">=10" + } + }, + "node_modules/color-support": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", + "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", + "bin": { + "color-support": "bin.js" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "node_modules/console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -112,6 +255,11 @@ "ms": "2.0.0" } }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -129,11 +277,40 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/detect-libc": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", + "integrity": "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==", + "engines": { + "node": ">=8" + } + }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, + "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==", + "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", "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -196,6 +373,18 @@ "node": ">= 0.10.0" } }, + "node_modules/express-validator": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.15.0.tgz", + "integrity": "sha512-r05VYoBL3i2pswuehoFSy+uM8NBuVaY7avp5qrYjQBDzagx2Z5A77FZqPT8/gNLF3HopWkIzaTFaC4JysWXLqg==", + "dependencies": { + "lodash": "^4.17.21", + "validator": "^13.9.0" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/finalhandler": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", @@ -229,11 +418,57 @@ "node": ">= 0.6" } }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs-minipass/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, + "node_modules/gauge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", + "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "dependencies": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.2", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.1", + "object-assign": "^4.1.1", + "signal-exit": "^3.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.2" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/get-intrinsic": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz", @@ -247,6 +482,25 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -269,6 +523,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" + }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -284,6 +543,39 @@ "node": ">= 0.8" } }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/https-proxy-agent/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/https-proxy-agent/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -295,6 +587,15 @@ "node": ">=0.10.0" } }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -308,6 +609,91 @@ "node": ">= 0.10" } }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "engines": { + "node": ">=8" + } + }, + "node_modules/jsonwebtoken": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.0.tgz", + "integrity": "sha512-tuGfYXxkQGDPnLJ7SibiQgVgeDgfbPq2k2ICcbgqW8WxWLBAxKQM/ZCu/IT8SOSwmaYl4dpTFCW5xZv7YbbWUw==", + "dependencies": { + "jws": "^3.2.2", + "lodash": "^4.17.21", + "ms": "^2.1.1", + "semver": "^7.3.8" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jsonwebtoken/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "dependencies": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "dependencies": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -359,6 +745,59 @@ "node": ">= 0.6" } }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minipass": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.5.tgz", + "integrity": "sha512-+yQl7SX3bIT83Lhb4BVorMAHVuqsskxRdlmO9kTpyukp8vsm2Sn/fUOV9xlnG8/a5JsypJzap21lz/y3FBMJ8Q==", + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minizlib/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -372,6 +811,63 @@ "node": ">= 0.6" } }, + "node_modules/node-addon-api": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", + "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==" + }, + "node_modules/node-fetch": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", + "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/npmlog": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", + "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "dependencies": { + "are-we-there-yet": "^2.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^3.0.0", + "set-blocking": "^2.0.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.12.3", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", @@ -391,6 +887,14 @@ "node": ">= 0.8" } }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dependencies": { + "wrappy": "1" + } + }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -399,6 +903,14 @@ "node": ">= 0.8" } }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", @@ -452,6 +964,33 @@ "node": ">= 0.8" } }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -476,6 +1015,20 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/send": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", @@ -518,6 +1071,11 @@ "node": ">= 0.8.0" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + }, "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", @@ -536,6 +1094,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -544,6 +1107,54 @@ "node": ">= 0.8" } }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/tar": { + "version": "6.1.13", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.13.tgz", + "integrity": "sha512-jdIBIN6LTIe2jqzay/2vtYLlBHa3JF42ot3h1dW8Q0PaAG4v8rm0cvpVePtau5C6OKXGGcgO9q2AMNSWxiLqKw==", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^4.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", @@ -552,6 +1163,11 @@ "node": ">=0.6" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -572,6 +1188,11 @@ "node": ">= 0.8" } }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", @@ -580,6 +1201,14 @@ "node": ">= 0.4.0" } }, + "node_modules/validator": { + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", + "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -587,9 +1216,62 @@ "engines": { "node": ">= 0.8" } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/wide-align": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", + "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", + "dependencies": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" } }, "dependencies": { + "@mapbox/node-pre-gyp": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz", + "integrity": "sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==", + "requires": { + "detect-libc": "^2.0.0", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.7", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + } + }, + "abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" + }, "accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -599,11 +1281,67 @@ "negotiator": "0.6.3" } }, + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "requires": { + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + }, + "aproba": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", + "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==" + }, + "are-we-there-yet": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", + "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + } + }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "bcrypt": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-5.1.0.tgz", + "integrity": "sha512-RHBS7HI5N5tEnGTmtR/pppX0mmDSBpQ4aCBsj7CEQfYXDcO74A8sIBYcJMuCsis2E81zDxeENYhv66oZwLiA+Q==", + "requires": { + "@mapbox/node-pre-gyp": "^1.0.10", + "node-addon-api": "^5.0.0" + } + }, "body-parser": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", @@ -623,6 +1361,20 @@ "unpipe": "1.0.0" } }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "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==" + }, "bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -637,6 +1389,26 @@ "get-intrinsic": "^1.0.2" } }, + "chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==" + }, + "color-support": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", + "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==" + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" + }, "content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -668,6 +1440,11 @@ "ms": "2.0.0" } }, + "delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" + }, "depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -678,11 +1455,34 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" }, + "detect-libc": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", + "integrity": "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==" + }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, + "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==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -736,6 +1536,15 @@ "vary": "~1.1.2" } }, + "express-validator": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.15.0.tgz", + "integrity": "sha512-r05VYoBL3i2pswuehoFSy+uM8NBuVaY7avp5qrYjQBDzagx2Z5A77FZqPT8/gNLF3HopWkIzaTFaC4JysWXLqg==", + "requires": { + "lodash": "^4.17.21", + "validator": "^13.9.0" + } + }, "finalhandler": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", @@ -760,11 +1569,50 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==" }, + "fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "requires": { + "minipass": "^3.0.0" + }, + "dependencies": { + "minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "requires": { + "yallist": "^4.0.0" + } + } + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, + "gauge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", + "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "requires": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.2", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.1", + "object-assign": "^4.1.1", + "signal-exit": "^3.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.2" + } + }, "get-intrinsic": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz", @@ -775,6 +1623,19 @@ "has-symbols": "^1.0.3" } }, + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -788,6 +1649,11 @@ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" }, + "has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" + }, "http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -800,6 +1666,30 @@ "toidentifier": "1.0.1" } }, + "https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "requires": { + "agent-base": "6", + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -808,6 +1698,15 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -818,6 +1717,76 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "jsonwebtoken": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.0.tgz", + "integrity": "sha512-tuGfYXxkQGDPnLJ7SibiQgVgeDgfbPq2k2ICcbgqW8WxWLBAxKQM/ZCu/IT8SOSwmaYl4dpTFCW5xZv7YbbWUw==", + "requires": { + "jws": "^3.2.2", + "lodash": "^4.17.21", + "ms": "^2.1.1", + "semver": "^7.3.8" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, + "jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "requires": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "requires": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "requires": { + "semver": "^6.0.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + } + } + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -851,6 +1820,43 @@ "mime-db": "1.52.0" } }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minipass": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.5.tgz", + "integrity": "sha512-+yQl7SX3bIT83Lhb4BVorMAHVuqsskxRdlmO9kTpyukp8vsm2Sn/fUOV9xlnG8/a5JsypJzap21lz/y3FBMJ8Q==" + }, + "minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "requires": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "dependencies": { + "minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "requires": { + "yallist": "^4.0.0" + } + } + } + }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -861,6 +1867,43 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, + "node-addon-api": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", + "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==" + }, + "node-fetch": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", + "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, + "nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "requires": { + "abbrev": "1" + } + }, + "npmlog": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", + "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "requires": { + "are-we-there-yet": "^2.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^3.0.0", + "set-blocking": "^2.0.0" + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" + }, "object-inspect": { "version": "1.12.3", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", @@ -874,11 +1917,24 @@ "ee-first": "1.1.1" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "requires": { + "wrappy": "1" + } + }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==" + }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", @@ -917,6 +1973,24 @@ "unpipe": "1.0.0" } }, + "readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "requires": { + "glob": "^7.1.3" + } + }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -927,6 +2001,14 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "requires": { + "lru-cache": "^6.0.0" + } + }, "send": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", @@ -965,6 +2047,11 @@ "send": "0.18.0" } }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + }, "setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", @@ -980,16 +2067,65 @@ "object-inspect": "^1.9.0" } }, + "signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + }, "statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "requires": { + "safe-buffer": "~5.2.0" + } + }, + "string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "requires": { + "ansi-regex": "^5.0.1" + } + }, + "tar": { + "version": "6.1.13", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.13.tgz", + "integrity": "sha512-jdIBIN6LTIe2jqzay/2vtYLlBHa3JF42ot3h1dW8Q0PaAG4v8rm0cvpVePtau5C6OKXGGcgO9q2AMNSWxiLqKw==", + "requires": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^4.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + } + }, "toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -1004,15 +2140,57 @@ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==" }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, "utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, + "validator": { + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", + "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==" + }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "wide-align": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", + "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", + "requires": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" } } } diff --git a/package.json b/package.json index a891f8f9..2cacf8f6 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,10 @@ "author": "", "license": "ISC", "dependencies": { - "express": "^4.18.2" + "bcrypt": "^5.1.0", + "dotenv": "^16.0.3", + "express": "^4.18.2", + "express-validator": "^6.15.0", + "jsonwebtoken": "^9.0.0" } } diff --git a/routes/authRoutes.js b/routes/authRoutes.js new file mode 100644 index 00000000..6e3aa619 --- /dev/null +++ b/routes/authRoutes.js @@ -0,0 +1,14 @@ +const express = require("express"); +const { + emailValidation, + passwordValidation, +} = require("../middlewares/validators"); +const { signup, login } = require("../controllers/authController"); + +const router = express.Router(); + +router.post("/signup", [emailValidation, passwordValidation], signup); + +router.post("/login", [emailValidation, passwordValidation], login); + +module.exports = router; From d0483672fb6804b4bbbb7692b6bd60c9d596c278 Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Fri, 7 Apr 2023 21:40:02 +0530 Subject: [PATCH 3/8] feat: add cookie and user id --- controllers/authController.js | 19 +++++++++++++------ package-lock.json | 16 +++++++++++++++- package.json | 3 ++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/controllers/authController.js b/controllers/authController.js index d08fb8ad..c8e38d59 100644 --- a/controllers/authController.js +++ b/controllers/authController.js @@ -1,6 +1,8 @@ const { validationResult } = require("express-validator"); const USERS = require("../models/User"); const bcrypt = require("bcrypt"); +const { v1 } = require("uuid"); +const jwt = require("jsonwebtoken"); exports.signup = async (req, res) => { // Check for validation errors @@ -25,7 +27,11 @@ exports.signup = async (req, res) => { const hashedPassword = await bcrypt.hash(req.body.password, 10); // Add user to USERS array - USERS.push({ email: req.body.email, password: hashedPassword }); + USERS.push({ + id: v1(), // add unique id + email: req.body.email, + password: hashedPassword, + }); // Send success response res.sendStatus(201); @@ -36,7 +42,7 @@ exports.signup = async (req, res) => { } }; -exports.signin = async (req, res) => { +exports.login = async (req, res) => { // Check for validation errors const errors = validationResult(req); @@ -49,7 +55,7 @@ exports.signin = async (req, res) => { try { // Check if user exists in USERS array - const user = await USERS.find(); + const user = await USERS.find((val) => val.email === email); if (!user) { return res.status(401).json({ msg: "Invalid email or password" }); } @@ -64,15 +70,16 @@ exports.signin = async (req, res) => { const payload = { user: { id: user.id, + email: user.email, }, }; const token = jwt.sign(payload, process.env.JWT_SECRET, { expiresIn: "1h", }); - - res.json({ token }); + res.cookie("token", token, { httpOnly: true, maxAge: 3600 }); + res.sendStatus(200); } catch (err) { - console.error(err.message); + console.error(err); res.status(500).send("Server Error"); } }; diff --git a/package-lock.json b/package-lock.json index 0e2ef565..1586f257 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "dotenv": "^16.0.3", "express": "^4.18.2", "express-validator": "^6.15.0", - "jsonwebtoken": "^9.0.0" + "jsonwebtoken": "^9.0.0", + "uuid": "^9.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -1201,6 +1202,14 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/validator": { "version": "13.9.0", "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", @@ -2150,6 +2159,11 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, + "uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==" + }, "validator": { "version": "13.9.0", "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", diff --git a/package.json b/package.json index 2cacf8f6..f2c1e08a 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dotenv": "^16.0.3", "express": "^4.18.2", "express-validator": "^6.15.0", - "jsonwebtoken": "^9.0.0" + "jsonwebtoken": "^9.0.0", + "uuid": "^9.0.0" } } From fa0eb19ca9fe0636084b0d0e1509a51d6fef57d4 Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Sat, 8 Apr 2023 14:56:04 +0530 Subject: [PATCH 4/8] feat: add questions and submissions routes --- controllers/authController.js | 4 -- controllers/questionsController.js | 13 ++++++ controllers/submissionController.js | 54 +++++++++++++++++++++++++ index.js | 51 +++++++++++++---------- middlewares/authMiddleware.js | 23 +++++++++++ models/Questions.js | 63 +++++++++++++++++++++++++++++ models/Submissions.js | 36 +++++++++++++++++ package-lock.json | 37 +++++++++++++++++ package.json | 1 + routes/questionRoutes.js | 11 +++++ routes/submissionRoutes.js | 19 +++++++++ 11 files changed, 287 insertions(+), 25 deletions(-) create mode 100644 controllers/questionsController.js create mode 100644 controllers/submissionController.js create mode 100644 middlewares/authMiddleware.js create mode 100644 models/Questions.js create mode 100644 models/Submissions.js create mode 100644 routes/questionRoutes.js create mode 100644 routes/submissionRoutes.js diff --git a/controllers/authController.js b/controllers/authController.js index c8e38d59..0eecdf37 100644 --- a/controllers/authController.js +++ b/controllers/authController.js @@ -8,8 +8,6 @@ exports.signup = async (req, res) => { // Check for validation errors const errors = validationResult(req); - console.log(req.body); - if (!errors.isEmpty()) { return res.status(400).json({ errors: errors.array() }); } @@ -46,8 +44,6 @@ exports.login = async (req, res) => { // Check for validation errors const errors = validationResult(req); - console.log(req.body); - if (!errors.isEmpty()) { return res.status(400).json({ errors: errors.array() }); } diff --git a/controllers/questionsController.js b/controllers/questionsController.js new file mode 100644 index 00000000..a326f073 --- /dev/null +++ b/controllers/questionsController.js @@ -0,0 +1,13 @@ +const QUESTIONS = require("../models/Questions"); + +exports.getAllQuestions = (req, res) => { + try { + const formattedQuestions = QUESTIONS; + + res.status(200).json(formattedQuestions); + } catch (err) { + return res.status(500).json({ error: "Server error" }); + } +}; + +//TODO: Admin can post questions diff --git a/controllers/submissionController.js b/controllers/submissionController.js new file mode 100644 index 00000000..69aaeba9 --- /dev/null +++ b/controllers/submissionController.js @@ -0,0 +1,54 @@ +const QUESTIONS = require("../models/Questions"); +const SUBMISSIONS = require("../models/Submissions"); + +exports.getSubmissionsByQuestion = (req, res) => { + try { + const questionId = req.params.questionId; + + const submissions = SUBMISSIONS.filter( + (val) => val.questionId.toString() === questionId + ); + + return res.status(200).json(submissions); + } catch (err) { + console.error(err); + return res.status(500).json({ error: "Server error" }); + } +}; + +exports.submitSolution = (req, res) => { + try { + const question = QUESTIONS.find( + (val) => val.id.toString() === req.params.questionId + ); + if (!question) { + return res.status(404).json({ error: "Question not found" }); + } + + const userId = req.user.id; + const code = req.body.code; + + const submission = { + userId: userId, + code: code, + status: Math.random() > 0.5 ? "ACCEPTED" : "REJECTED", + }; + + const submissionIndex = SUBMISSIONS.findIndex( + (s) => s.questionID === req.params.questionId + ); + + if (submissionIndex === -1) { + SUBMISSIONS.push({ + questionId: req.params.questionId, + submissions: [submission], + }); + } else { + SUBMISSIONS[submissionIndex].submissions.push(submission); + } + + return res.status(201).json({ message: "Solution submitted successfully" }); + } catch (err) { + return res.status(500).json({ error: "Server error" }); + } +}; diff --git a/index.js b/index.js index 429e899b..398212ed 100644 --- a/index.js +++ b/index.js @@ -1,34 +1,43 @@ const express = require('express') +const cookieParser = require("cookie-parser"); + require("dotenv").config(); const authRoutes = require("./routes/authRoutes"); +const questionRoutes = require("./routes/questionRoutes"); +const submissionRoutes = require("./routes/submissionRoutes"); const app = express(); const port = 3001; -const QUESTIONS = [ - { - title: "Two states", - description: "Given an array , return the maximum of the array?", - testCases: [ - { - input: "[1,2,3,4,5]", - output: "5", - }, - ], - }, -]; - -const SUBMISSION = [ - // { - // userId: '', - // questionId:'', - // code:'' - // status:'' - // } -]; + app.use(express.json()); +app.use(cookieParser()); app.use(authRoutes); +app.use(questionRoutes); +app.use(submissionRoutes); + +// const QUESTIONS = [ +// { +// title: "Two states", +// description: "Given an array , return the maximum of the array?", +// testCases: [ +// { +// input: "[1,2,3,4,5]", +// output: "5", +// }, +// ], +// }, +// ]; + +// const SUBMISSION = [ +// // { +// // userId: '', +// // questionId:'', +// // code:'' +// // status:'' +// // } +// ]; // app.post('/signup', function(req, res) { // // Add logic to decode body diff --git a/middlewares/authMiddleware.js b/middlewares/authMiddleware.js new file mode 100644 index 00000000..6b77d775 --- /dev/null +++ b/middlewares/authMiddleware.js @@ -0,0 +1,23 @@ +const jwt = require("jsonwebtoken"); +const USERS = require("../models/User"); + +exports.authMiddleware = function (req, res, next) { + const token = req.cookies["token"]; + if (!token) { + return res.status(401).json({ error: "Unauthorized" }); + } + + try { + const decoded = jwt.verify(token, process.env.JWT_SECRET); + req.user = decoded.user; + const user = USERS.find((val) => val.id === decoded.user.id); + if (!user) { + return res.status(401).json({ error: "User doesn't exists" }); + } + next(); // TODO: might remove later + } catch (err) { + return res.status(401).json({ error: "Unauthorized" }); + } +}; + +//TODO: add a admin authentication diff --git a/models/Questions.js b/models/Questions.js new file mode 100644 index 00000000..b4c433b2 --- /dev/null +++ b/models/Questions.js @@ -0,0 +1,63 @@ +let QUESTIONS = [ + { + id: 1, + title: "Two states", + description: "Given an array, return the maximum of the array?", + testCases: [ + { + input: "[1,2,3,4,5]", + output: "5", + }, + { + input: "[-10,-5,0,5,10]", + output: "10", + }, + { + input: "[3,7,2,8,4]", + output: "8", + }, + ], + }, + { + id: 2, + title: "Palindrome", + description: "Given a string, determine if it is a palindrome", + testCases: [ + { + input: "racecar", + output: "true", + }, + { + input: "hello", + output: "false", + }, + { + input: "A man a plan a canal Panama", + output: "true", + }, + ], + }, + { + id: 3, + title: "FizzBuzz", + description: + "Print the numbers from 1 to n, but for multiples of 3 print 'Fizz', for multiples of 5 print 'Buzz', and for multiples of both 3 and 5 print 'FizzBuzz'", + testCases: [ + { + input: "15", + output: + "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz", + }, + { + input: "7", + output: "1\n2\nFizz\n4\nBuzz\nFizz\n7", + }, + { + input: "10", + output: "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz", + }, + ], + }, +]; + +module.exports = QUESTIONS; diff --git a/models/Submissions.js b/models/Submissions.js new file mode 100644 index 00000000..51e51bf8 --- /dev/null +++ b/models/Submissions.js @@ -0,0 +1,36 @@ +let SUBMISSIONS = []; + +// SUBMISSIONS: [ +// { +// questionID: "1", +// submissions: [ +// { +// userId: "123", +// code: "console.log('hello world')", +// status: "accept", +// }, +// { +// userId: "456", +// code: "console.log('hello')", +// status: "reject", +// }, +// ], +// }, +// { +// questionID: "2", +// submissions: [ +// { +// userId: "123", +// code: "function add(a, b) { return a + b; }", +// status: "accept", +// }, +// { +// userId: "789", +// code: "console.log('hello')", +// status: "reject", +// }, +// ], +// }, +// ]; + +module.exports = SUBMISSIONS; diff --git a/package-lock.json b/package-lock.json index 1586f257..88b383b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "bcrypt": "^5.1.0", + "cookie-parser": "^1.4.6", "dotenv": "^16.0.3", "express": "^4.18.2", "express-validator": "^6.15.0", @@ -243,6 +244,26 @@ "node": ">= 0.6" } }, + "node_modules/cookie-parser": { + "version": "1.4.6", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz", + "integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==", + "dependencies": { + "cookie": "0.4.1", + "cookie-signature": "1.0.6" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/cookie-parser/node_modules/cookie": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", + "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", @@ -1436,6 +1457,22 @@ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==" }, + "cookie-parser": { + "version": "1.4.6", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz", + "integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==", + "requires": { + "cookie": "0.4.1", + "cookie-signature": "1.0.6" + }, + "dependencies": { + "cookie": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", + "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==" + } + } + }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", diff --git a/package.json b/package.json index f2c1e08a..7420de1d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "bcrypt": "^5.1.0", + "cookie-parser": "^1.4.6", "dotenv": "^16.0.3", "express": "^4.18.2", "express-validator": "^6.15.0", diff --git a/routes/questionRoutes.js b/routes/questionRoutes.js new file mode 100644 index 00000000..71a1ac0f --- /dev/null +++ b/routes/questionRoutes.js @@ -0,0 +1,11 @@ +const express = require("express"); +const router = express.Router(); +const { getAllQuestions } = require("../controllers/questionsController"); +const { authMiddleware } = require("../middlewares/authMiddleware"); + +router.get("/questions", authMiddleware, getAllQuestions); + +//TODO: Only Admins can post questions +//router.post() + +module.exports = router; diff --git a/routes/submissionRoutes.js b/routes/submissionRoutes.js new file mode 100644 index 00000000..2fdbc452 --- /dev/null +++ b/routes/submissionRoutes.js @@ -0,0 +1,19 @@ +const express = require("express"); +const { + getSubmissionsByQuestion, + submitSolution, +} = require("../controllers/submissionController"); +const router = express.Router(); +const { authMiddleware } = require("../middlewares/authMiddleware"); + +// Get submissions based on specific question +router.get( + "/submissions/:questionId", + authMiddleware, + getSubmissionsByQuestion +); + +// Submit a solution for a specific question +router.post("/submissions/:questionId", authMiddleware, submitSolution); + +module.exports = router; From 114a1ecbe20f019e7cc13dc1ef674693d0eb4bbe Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Sat, 8 Apr 2023 16:17:42 +0530 Subject: [PATCH 5/8] refactor: update readme file --- README.md | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 704d1b06..fedaf85b 100644 --- a/README.md +++ b/README.md @@ -1 +1,103 @@ -# FullStack Assignment \ No newline at end of file +# FullStack Assignment + +## Usage + +1. Start the server: `npm start` +2. Open your browser and navigate to `http://localhost:3001` +## Folder Structure + +The project follows a modular architecture, where the code is organized into separate folders for better maintainability and scalability. Here's a brief description of each folder: + +- `controllers`: Contains the controllers for handling incoming requests, performing necessary actions, and sending the response back. +- `middleware`: Contains the middleware functions to handle common tasks such as authentication, input validation, error handling, etc. +- `models`: Contains the models for the data store used in the application. +- `routes`: Contains the route handlers for mapping HTTP requests to the corresponding controller functions. + +## API Endpoints + +### Authentication + +- `/signup` (POST): Allows users to sign up for the platform +- `/login` (POST): Allows registered users to login to the platform + +### Questions + +- `/questions` (GET): Returns a list of all available questions + +### Submissions + +- `/submissions/:questionId` (GET): Returns a list of submissions for a particular question +- `/submissions/:questionId` (POST): Allows logged in users to submit a solution for a particular question + +## Object Types + +### Question Type + +| Field | Type | Description | +| ----------- | ------ | ------------------------------------ | +| id | Number | The unique ID of the question | +| title | String | The title of the question | +| description | String | The description of the question | +| testCases | Array | An array of test cases for the question | + +The `testCases` array contains objects with the following fields: + +| Field | Type | Description | +| ------ | ------ | ------------------------------- | +| input | String | The input for the test case | +| output | String | The expected output for the test case | + +```json +{ + "id": 1, + "title": "Two states", + "description": "Given an array, return the maximum of the array?", + "testCases": [ + { + "input": "[1,2,3,4,5]", + "output": "5" + }, + { + "input": "[-10,-5,0,5,10]", + "output": "10" + }, + { + "input": "[3,7,2,8,4]", + "output": "8" + } + ] +} +``` + +### Submission Type + +| Field | Type | Description | +| ------------ | ------ | ---------------------------------------------- | +| questionID | String | The ID of the question the submission relates to | +| submissions | Array | An array of submissions for the question | + +The `submissions` array contains objects with the following fields: + +| Field | Type | Description | +| ------- | ------ | ---------------------------------- | +| userId | String | The ID of the user making the submission | +| code | String | The code for the submission | +| status | String | The status of the submission | + +```json +{ + "questionID": "1", + "submissions": [ + { + "userId": "123", + "code": "console.log('hello world')", + "status": "accept" + }, + { + "userId": "456", + "code": "console.log('hello')", + "status": "reject" + } + ] +} +``` \ No newline at end of file From 60be4d799f8f65b9099645d8d948dbc0250f9de3 Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Sat, 8 Apr 2023 23:08:28 +0530 Subject: [PATCH 6/8] feat: only admin can add questions Added proper validators and sanitisation for adding Question --- controllers/adminController.js | 81 +++++++++++++++++++++++++++++ controllers/questionsController.js | 27 +++++++++- controllers/submissionController.js | 6 +++ index.js | 2 + middlewares/adminMiddleware.js | 21 ++++++++ middlewares/authMiddleware.js | 1 - middlewares/validators.js | 32 ++++++++++++ models/Admin.js | 3 ++ routes/adminRoutes.js | 14 +++++ routes/questionRoutes.js | 14 ++++- routes/submissionRoutes.js | 8 ++- 11 files changed, 204 insertions(+), 5 deletions(-) create mode 100644 controllers/adminController.js create mode 100644 middlewares/adminMiddleware.js create mode 100644 models/Admin.js create mode 100644 routes/adminRoutes.js diff --git a/controllers/adminController.js b/controllers/adminController.js new file mode 100644 index 00000000..b90342fd --- /dev/null +++ b/controllers/adminController.js @@ -0,0 +1,81 @@ +const { validationResult } = require("express-validator"); +const ADMINS = require("../models/Admin"); +const bcrypt = require("bcrypt"); +const { v1 } = require("uuid"); +const jwt = require("jsonwebtoken"); + +exports.signup = async (req, res) => { + // Check for validation errors + const errors = validationResult(req); + + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + + // Check if admin already exists + const existingAdmin = ADMINS.find((admin) => admin.email === req.body.email); + if (existingAdmin) { + return res + .status(409) + .json({ message: "Admin with this email already exists" }); + } + + try { + // Hash password + const hashedPassword = await bcrypt.hash(req.body.password, 10); + + // Add admin to ADMINS array + ADMINS.push({ + id: v1(), // add unique id + email: req.body.email, + password: hashedPassword, + }); + + // Send success response + res.sendStatus(201); + } catch (error) { + // Handle errors + console.error(error); + res.status(500).json({ message: "Internal server error" }); + } +}; + +exports.login = async (req, res) => { + // Check for validation errors + const errors = validationResult(req); + + if (!errors.isEmpty()) { + return res.status(400).json({ errors: errors.array() }); + } + const { email, password } = req.body; + + try { + // Check if admin exists in ADMINS array + const admin = await ADMINS.find((val) => val.email === email); + if (!admin) { + return res.status(401).json({ msg: "Invalid email or password" }); + } + + // Check if password is correct + const isMatch = await bcrypt.compare(password, admin.password); + if (!isMatch) { + return res.status(401).json({ msg: "Invalid email or password" }); + } + + // Generate JSON Web Token (JWT) + const payload = { + admin: { + id: admin.id, + email: admin.email, + }, + }; + const token = jwt.sign(payload, process.env.JWT_SECRET, { + expiresIn: "1h", + }); + res.cookie("token", token, { httpOnly: true, maxAge: 3600 }); + res.sendStatus(200); + } catch (err) { + console.error(err); + res.status(500).send("Server Error"); + } +}; diff --git a/controllers/questionsController.js b/controllers/questionsController.js index a326f073..f7a7663b 100644 --- a/controllers/questionsController.js +++ b/controllers/questionsController.js @@ -1,3 +1,4 @@ +const { validationResult } = require("express-validator"); const QUESTIONS = require("../models/Questions"); exports.getAllQuestions = (req, res) => { @@ -10,4 +11,28 @@ exports.getAllQuestions = (req, res) => { } }; -//TODO: Admin can post questions +exports.addQuestion = (req, res) => { + // Validate and sanitize inputs using express-validator + const errors = validationResult(req); + if (!errors.isEmpty()) { + return res.status(422).json({ errors: errors.array() }); + } + + try { + const { title, description, testCases } = req.body; + + const newQuestion = { + id: QUESTIONS.length + 1, + title, + description, + testCases, + }; + + QUESTIONS.push(newQuestion); + res + .status(201) + .json({ message: "Question added successfully!", question: newQuestion }); + } catch (error) { + return res.status(500).json({ error: "Server error" }); + } +}; diff --git a/controllers/submissionController.js b/controllers/submissionController.js index 69aaeba9..c121785c 100644 --- a/controllers/submissionController.js +++ b/controllers/submissionController.js @@ -1,3 +1,4 @@ +const { validationResult } = require("express-validator"); const QUESTIONS = require("../models/Questions"); const SUBMISSIONS = require("../models/Submissions"); @@ -17,6 +18,11 @@ exports.getSubmissionsByQuestion = (req, res) => { }; exports.submitSolution = (req, res) => { + const errors = validationResult(req); + if (!errors.isEmpty()) { + return res.status(422).json({ errors: errors.array() }); + } + try { const question = QUESTIONS.find( (val) => val.id.toString() === req.params.questionId diff --git a/index.js b/index.js index 398212ed..3d5b6120 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const cookieParser = require("cookie-parser"); require("dotenv").config(); const authRoutes = require("./routes/authRoutes"); +const adminRoutes = require("./routes/adminRoutes"); const questionRoutes = require("./routes/questionRoutes"); const submissionRoutes = require("./routes/submissionRoutes"); const app = express(); @@ -14,6 +15,7 @@ app.use(express.json()); app.use(cookieParser()); app.use(authRoutes); +app.use(adminRoutes); app.use(questionRoutes); app.use(submissionRoutes); diff --git a/middlewares/adminMiddleware.js b/middlewares/adminMiddleware.js new file mode 100644 index 00000000..9ee7cbe7 --- /dev/null +++ b/middlewares/adminMiddleware.js @@ -0,0 +1,21 @@ +const jwt = require("jsonwebtoken"); +const ADMINS = require("../models/Admin"); + +exports.adminMiddleware = function (req, res, next) { + const token = req.cookies["token"]; + if (!token) { + return res.status(401).json({ error: "Unauthorized" }); + } + + try { + const decoded = jwt.verify(token, process.env.JWT_SECRET); + req.admin = decoded.admin; + const admin = ADMINS.find((val) => val.id === decoded.admin.id); + if (!admin) { + return res.status(401).json({ error: "Admin doesn't exists" }); + } + next(); // TODO: might remove later + } catch (err) { + return res.status(401).json({ error: "Unauthorized" }); + } +}; diff --git a/middlewares/authMiddleware.js b/middlewares/authMiddleware.js index 6b77d775..efc9d80a 100644 --- a/middlewares/authMiddleware.js +++ b/middlewares/authMiddleware.js @@ -20,4 +20,3 @@ exports.authMiddleware = function (req, res, next) { } }; -//TODO: add a admin authentication diff --git a/middlewares/validators.js b/middlewares/validators.js index 77d63fc8..d0605743 100644 --- a/middlewares/validators.js +++ b/middlewares/validators.js @@ -10,3 +10,35 @@ exports.passwordValidation = body("password") .isLength({ min: 8 }) .escape() .withMessage("Password must be at least 8 characters long"); + +exports.codeValidator = body("code") + .notEmpty() + .withMessage("Code is required") + .escape(); + +exports.createQuestionValidator = [ + body("title") + .trim() + .isLength({ min: 1, max: 100 }) + .escape() + .withMessage("Title is required"), + body("description") + .trim() + .isLength({ min: 1, max: 500 }) + .escape() + .withMessage("Description is required"), + body("testCases") + .isArray() + .notEmpty() + .withMessage("Test cases must be an array with at least one element"), + body("testCases.*.input") + .trim() + .isLength({ min: 1, max: 100 }) + .escape() + .withMessage("Test case must have input and output fields"), + body("testCases.*.output") + .trim() + .isLength({ min: 1, max: 100 }) + .escape() + .withMessage("Test case must have input and output fields"), +]; diff --git a/models/Admin.js b/models/Admin.js new file mode 100644 index 00000000..ba5e2eca --- /dev/null +++ b/models/Admin.js @@ -0,0 +1,3 @@ +let ADMINS = []; + +module.exports = ADMINS; diff --git a/routes/adminRoutes.js b/routes/adminRoutes.js new file mode 100644 index 00000000..b1d6c461 --- /dev/null +++ b/routes/adminRoutes.js @@ -0,0 +1,14 @@ +const express = require("express"); +const { + emailValidation, + passwordValidation, +} = require("../middlewares/validators"); +const { signup, login } = require("../controllers/adminController"); + +const router = express.Router(); + +router.post("/admin/signup", [emailValidation, passwordValidation], signup); + +router.post("/admin/login", [emailValidation, passwordValidation], login); + +module.exports = router; diff --git a/routes/questionRoutes.js b/routes/questionRoutes.js index 71a1ac0f..e944d329 100644 --- a/routes/questionRoutes.js +++ b/routes/questionRoutes.js @@ -1,11 +1,21 @@ const express = require("express"); const router = express.Router(); -const { getAllQuestions } = require("../controllers/questionsController"); +const { + getAllQuestions, + addQuestion, +} = require("../controllers/questionsController"); +const { adminMiddleware } = require("../middlewares/adminMiddleware"); const { authMiddleware } = require("../middlewares/authMiddleware"); +const { createQuestionValidator } = require("../middlewares/validators"); router.get("/questions", authMiddleware, getAllQuestions); //TODO: Only Admins can post questions -//router.post() +router.post( + "/admin/question", + adminMiddleware, + [createQuestionValidator], + addQuestion +); module.exports = router; diff --git a/routes/submissionRoutes.js b/routes/submissionRoutes.js index 2fdbc452..18918bca 100644 --- a/routes/submissionRoutes.js +++ b/routes/submissionRoutes.js @@ -5,6 +5,7 @@ const { } = require("../controllers/submissionController"); const router = express.Router(); const { authMiddleware } = require("../middlewares/authMiddleware"); +const { codeValidator } = require("../middlewares/validators"); // Get submissions based on specific question router.get( @@ -14,6 +15,11 @@ router.get( ); // Submit a solution for a specific question -router.post("/submissions/:questionId", authMiddleware, submitSolution); +router.post( + "/submissions/:questionId", + authMiddleware, + [codeValidator], + submitSolution +); module.exports = router; From 1966c237c15ef6a021ed1b4cb9851fe5f756fb9d Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Sun, 9 Apr 2023 00:45:50 +0530 Subject: [PATCH 7/8] refactor: update readme --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fedaf85b..44c2b3f2 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,11 @@ The project follows a modular architecture, where the code is organized into sep - `/submissions/:questionId` (GET): Returns a list of submissions for a particular question - `/submissions/:questionId` (POST): Allows logged in users to submit a solution for a particular question - + ### Admin Routes + Implemented separate routes, controllers, middleware, and models for admin functionality, for separation of concerns +- `/admin/signup` (POST): Allows admin to sign up for the platform +- `/admin/login` (POST): Allows registered admin to login to the platform +- `/admin/question` (POST): Allows registered admin to add question. ## Object Types ### Question Type @@ -100,4 +104,45 @@ The `submissions` array contains objects with the following fields: } ] } -``` \ No newline at end of file +``` + + +## Input Validation and Sanitisation + +To ensure data integrity and prevent security vulnerabilities, this application uses input validation and sanitization. We have used the express-validator library to add validation and sanitization middleware for the following routes: + +- `/signup`: Validates and sanitizes the user's email and password inputs. +- `/login`: Validates and sanitizes the user's email and password inputs. +- `/admin/question`: Validates and sanitizes the admin's question inputs. +- `/submissions/question`: Validates and santizes the code input. + +Example: +```js +exports.createQuestionValidator = [ + body("title") + .trim() + .isLength({ min: 1, max: 100 }) + .escape() + .withMessage("Title is required"), + body("description") + .trim() + .isLength({ min: 1, max: 500 }) + .escape() + .withMessage("Description is required"), + body("testCases") + .isArray() + .notEmpty() + .withMessage("Test cases must be an array with at least one element"), + body("testCases.*.input") + .trim() + .isLength({ min: 1, max: 100 }) + .escape() + .withMessage("Test case must have input and output fields"), + body("testCases.*.output") + .trim() + .isLength({ min: 1, max: 100 }) + .escape() + .withMessage("Test case must have input and output fields"), +]; +``` + From 578552acd41f61d2fd360bc284e8e3c19784756f Mon Sep 17 00:00:00 2001 From: adityaKumarModak Date: Sun, 9 Apr 2023 00:48:57 +0530 Subject: [PATCH 8/8] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 44c2b3f2..ef4f7ee5 100644 --- a/README.md +++ b/README.md @@ -146,3 +146,12 @@ exports.createQuestionValidator = [ ]; ``` +## Authentication +The application uses `JSON Web Tokens (JWT)` for authentication. When a user logs in, a JWT is generated and sent to the user with a cookie. For subsequent requests, the JWT is included in the cookie, which is then verified on the server side to authenticate the user. + +It's important to note that while the authentication process is similar for both users and admins, admin authentication requires a separate set of routes, controllers, middleware, and models for separation of concerns. + +To protect routes, the application uses an `authMiddleware` which checks if the user is authenticated and authorized to access the route. The middleware checks for the presence of the JWT cookie in the request headers. If the cookie is present and the JWT is verified, the user is considered authenticated and authorized to access the route. + +In order to get the cookie in the `authMiddleware`, the application uses the `cookie-parser `middleware which parses the cookie from the request headers and makes it available to the authMiddleware for authentication and authorization checks. +