From 584903e55d5b1c7f0416b34e042958ec3e569781 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Wed, 29 Dec 2021 15:08:40 +0100 Subject: [PATCH 01/42] FIX: The dev script can now run in any directory Initially, the directory was required to be called 'server'; This is not the case anymore --- dev.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dev.sh b/dev.sh index 0b96319..d6b8e5a 100755 --- a/dev.sh +++ b/dev.sh @@ -1,14 +1,14 @@ #!/bin/bash -DATABASE_PASSWORD=server docker-compose up -d mail postgres redis +DATABASE_PASSWORD=server COMPOSE_PROJECT_NAME=detleph_server docker-compose up -d mail postgres redis -if [ ! "$(docker ps -a | grep server_dev)" ]; then - echo "Creating \"server_dev\" container" +if [ ! "$(docker ps -a | grep detleph_server_dev)" ]; then + echo "Creating the server container" docker run -it \ - --name server_dev \ + --name detleph_server_dev \ --mount type=bind,source="$(pwd)",target=/app \ - --network server_default \ + --network detleph_server_default \ -p 3000:3000 -e PORT=3000 \ -e DATABASE_URL="postgresql://server:server@postgres:5432/management?schema=public" \ -e DATABASE_USER=server \ @@ -16,11 +16,11 @@ if [ ! "$(docker ps -a | grep server_dev)" ]; then --entrypoint "/app/scripts/docker-entrypoint.dev.sh" \ node else - echo "Container \"server_dev\" already exists; Starting container" + echo "The server container already exists; Starting..." - docker start -ia server_dev + docker start -ia detleph_server_dev fi # After container termination -docker-compose stop +COMPOSE_PROJECT_NAME=detleph_server docker-compose stop From eb70a14c6125e9d67123952d6166f020410b9362 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Tue, 30 Nov 2021 11:12:43 +0100 Subject: [PATCH 02/42] Add routes for admin authentication endpoints + Add router to the app --- src/Routes/admin_auth.routes.ts | 8 ++++++++ src/app.ts | 4 ++++ 2 files changed, 12 insertions(+) create mode 100644 src/Routes/admin_auth.routes.ts diff --git a/src/Routes/admin_auth.routes.ts b/src/Routes/admin_auth.routes.ts new file mode 100644 index 0000000..e9408d3 --- /dev/null +++ b/src/Routes/admin_auth.routes.ts @@ -0,0 +1,8 @@ +import express from "express"; +import { authenticateUser } from "../Controllers/admin_auth.controller"; + +const router = express.Router(); + +router.post("/", authenticateUser); + +export default router; diff --git a/src/app.ts b/src/app.ts index 84e6cee..7507b63 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,7 @@ import express from "express"; import prisma from "./lib/prisma"; import eventRouter from "./Routes/event.routes"; +import adminAuthRouter from "./Routes/admin_auth.routes"; require("dotenv").config(); // Load dotenv config @@ -13,6 +14,9 @@ async function main() { app.use(express.urlencoded({ extended: true })); app.use(express.json()); + // Admin authentication endpoints + app.use("/api/authentication", adminAuthRouter); + // All API endpoints are behind /api/... app.use("/api/events", eventRouter); From 59f4d53af5ba2c08714bba7282ff8648cf90960c Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Wed, 1 Dec 2021 16:37:28 +0100 Subject: [PATCH 03/42] Add a controller for getting all admin user details + Requires Authentication --- src/Controllers/admin.controller.ts | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Controllers/admin.controller.ts diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts new file mode 100644 index 0000000..bdd64d0 --- /dev/null +++ b/src/Controllers/admin.controller.ts @@ -0,0 +1,40 @@ +import prisma from "../lib/prisma"; +import { Request, Response } from "express"; + +// requires: auth(elevated) +export const getAllAdmins = async (req: Request, res: Response) => { + if (!req.auth?.isAuthenticated) { + return res.status(500).json({ + type: "failure", + payload: { + message: "The server was not able to validate your credentials; Please try again later", + }, + }); + } + + if (req.auth.permission_level !== "ELEVATED") { + return res.status(403).json({ + type: "error", + payload: { + message: "You do not have sufficient permissions to use this feature", + }, + _links: [ + { + rel: "authentication", + href: "/api/authentication", + type: "POST", + }, + ], + }); + } + + // TODO: Add exception handling + const users = await prisma.admin.findMany({ select: { pid: true, name: true, permission_level: true } }); + + res.status(200).json({ + type: "success", + payload: { + users, + }, + }); +}; From 913e0ee0e05b4d4e7d5fdffe41926062980939e2 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Fri, 3 Dec 2021 13:15:50 +0100 Subject: [PATCH 04/42] Remove event <-> admin association and introduce a default value for revision --- prisma/schema.prisma | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cabd3e2..0a4bcbe 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -17,7 +17,6 @@ model Event { description String disciplines Discipline[] - admins Admin[] organisations Organisation[] campaign Campaign[] } @@ -47,14 +46,11 @@ model Link { model Admin { id Int @id @default(autoincrement()) pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String + name String // TODO: This should maybe be unique password String // TODO: Probably specify hash size (VarChar or some other type) permission_level AdminLevel @default(STANDARD) - revision String + revision String @default(dbgenerated("gen_random_uuid()")) @db.Uuid groups Group[] - - event Event @relation(fields: [eventId], references: [id]) - eventId Int } model Discipline { @@ -143,4 +139,4 @@ enum Gender { MALE FEMALE OTHER -} \ No newline at end of file +} From b82a84322b2fced9d5a70811942e1d97b7436c2c Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Mon, 20 Dec 2021 08:48:04 +0100 Subject: [PATCH 05/42] Extract code for error messages for better reusability + Create function for generating permission errors --- src/Controllers/admin.controller.ts | 44 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index bdd64d0..083d3c9 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -1,31 +1,37 @@ import prisma from "../lib/prisma"; import { Request, Response } from "express"; +import { AdminLevel } from "@prisma/client"; + +const AUTH_ERROR = { + type: "failure", + payload: { + message: "The server was not able to validate your credentials; Please try again later", + }, +}; + +const createInsufficientPermissionsError = (required: AdminLevel = "ELEVATED") => ({ + type: "error", + payload: { + message: "You do not have sufficient permissions to use this feature", + required_level: required, + }, + _links: [ + { + rel: "authentication", + href: "/api/authentication", + type: "POST", + }, + ], +}); // requires: auth(elevated) export const getAllAdmins = async (req: Request, res: Response) => { if (!req.auth?.isAuthenticated) { - return res.status(500).json({ - type: "failure", - payload: { - message: "The server was not able to validate your credentials; Please try again later", - }, - }); + return res.status(500).json(AUTH_ERROR); } if (req.auth.permission_level !== "ELEVATED") { - return res.status(403).json({ - type: "error", - payload: { - message: "You do not have sufficient permissions to use this feature", - }, - _links: [ - { - rel: "authentication", - href: "/api/authentication", - type: "POST", - }, - ], - }); + return res.status(403).json(createInsufficientPermissionsError()); } // TODO: Add exception handling From b57315d916c647f46de3545a1116c9fda428eba2 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Mon, 20 Dec 2021 09:06:05 +0100 Subject: [PATCH 06/42] Add controller for adding a user + Add function to narrow type of string to AdminLevel --- src/Controllers/admin.controller.ts | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index 083d3c9..526d80f 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -1,6 +1,7 @@ import prisma from "../lib/prisma"; import { Request, Response } from "express"; import { AdminLevel } from "@prisma/client"; +import argon2 from "argon2"; const AUTH_ERROR = { type: "failure", @@ -44,3 +45,58 @@ export const getAllAdmins = async (req: Request, res: Response) => { }, }); }; + +interface CreateAdminBody { + name?: string; + password: string; + permission_level: string; + // TODO: Add groups or events +} + +const PERMISSION_LEVELS: readonly AdminLevel[] = ["ELEVATED", "STANDARD"]; // TODO: Enforce completeness + +const isPermissionLevel = (level: string): level is AdminLevel => PERMISSION_LEVELS.includes(level as any); + +// requires: auth(elevated) +export const createAdmin = async (req: Request<{}, {}, CreateAdminBody>, res: Response) => { + if (!req.auth?.isAuthenticated) { + return res.status(500).json(AUTH_ERROR); + } + + if (req.auth.permission_level !== "ELEVATED") { + return res.status(403).json(createInsufficientPermissionsError()); + } + + const { name, password, permission_level } = req.body || {}; + + if (!(typeof name === "string" && typeof password == "string" && isPermissionLevel(permission_level))) { + return res.status(400).json({ + type: "error", + payload: { + message: "The body of your request did not conform to the requirements", + schema: { + body: { + name: "string", + password_level: "string", + permission_level: "'STANDARD' | 'ELEVATED'", + }, + }, + }, + }); + } + + const password_hash = await argon2.hash(password, { type: argon2.argon2id }); + + // TODO: Check for uniqueness of the name + const user = await prisma.admin.create({ + data: { name, password: password_hash, permission_level }, + select: { pid: true, name: true, permission_level: true }, + }); + + res.status(201).json({ + type: "success", + payload: { + user, + }, + }); +}; From 9b2c8b17c61acbd2510146961b80c375b702910a Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Mon, 20 Dec 2021 09:11:46 +0100 Subject: [PATCH 07/42] Add router for the /admin endpoint --- src/Routes/admin.routes.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/Routes/admin.routes.ts diff --git a/src/Routes/admin.routes.ts b/src/Routes/admin.routes.ts new file mode 100644 index 0000000..49fe551 --- /dev/null +++ b/src/Routes/admin.routes.ts @@ -0,0 +1,11 @@ +import express from "express"; +import { getAllAdmins, createAdmin } from "../Controllers/admin.controller"; +import { requireAuthentication } from "../Middleware/auth/auth"; + +const router = express.Router(); + +router.get("/", requireAuthentication, getAllAdmins); + +router.post("/", requireAuthentication, createAdmin); + +export default router; From 3363039f79bb63087fc2a07afe87df65d13bc0d6 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Mon, 20 Dec 2021 10:12:06 +0100 Subject: [PATCH 08/42] Add code that ensures that an (admin) user is always present --- src/app.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/app.ts b/src/app.ts index 7507b63..ce9c33f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,12 +2,20 @@ import express from "express"; import prisma from "./lib/prisma"; import eventRouter from "./Routes/event.routes"; import adminAuthRouter from "./Routes/admin_auth.routes"; +import argon2 from "argon2"; require("dotenv").config(); // Load dotenv config const app = express(); async function main() { + // Dev + await prisma.admin.upsert({ + where: { id: 1 }, + create: { name: "admin", password: await argon2.hash("test", { type: argon2.argon2id }) }, + update: {}, + }); + // Todo: Everything // Bodyparser and urlencoded to parse post request bodies From 97fee47c6e27eefd900e4eacf9f87c9bc5dfacfb Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Tue, 21 Dec 2021 12:19:17 +0100 Subject: [PATCH 09/42] Allow for groups to be specified when POSTing /api/admins + Add the admin router to the global app --- src/Controllers/admin.controller.ts | 29 +++++++++++++++++++++++++---- src/app.ts | 3 +++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index 526d80f..d15d720 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -50,7 +50,7 @@ interface CreateAdminBody { name?: string; password: string; permission_level: string; - // TODO: Add groups or events + groups?: string[]; } const PERMISSION_LEVELS: readonly AdminLevel[] = ["ELEVATED", "STANDARD"]; // TODO: Enforce completeness @@ -67,9 +67,13 @@ export const createAdmin = async (req: Request<{}, {}, CreateAdminBody>, res: Re return res.status(403).json(createInsufficientPermissionsError()); } - const { name, password, permission_level } = req.body || {}; + const { name, password, permission_level, groups } = req.body || {}; - if (!(typeof name === "string" && typeof password == "string" && isPermissionLevel(permission_level))) { + const groupsIsValid = groups ? groups.filter((e) => typeof e !== "string").length === 0 : true; + + if ( + !(typeof name === "string" && typeof password == "string" && isPermissionLevel(permission_level) && groupsIsValid) + ) { return res.status(400).json({ type: "error", payload: { @@ -87,9 +91,26 @@ export const createAdmin = async (req: Request<{}, {}, CreateAdminBody>, res: Re const password_hash = await argon2.hash(password, { type: argon2.argon2id }); + // Check if all gropus exist + for (const groupId of groups || []) { + if (!(await prisma.group.findUnique({ where: { pid: groupId } }))) { + return res.status(404).json({ + type: "error", + payload: { + message: `The group with ID '${groupId}' could not be found!`, + }, + }); + } + } + // TODO: Check for uniqueness of the name const user = await prisma.admin.create({ - data: { name, password: password_hash, permission_level }, + data: { + name, + password: password_hash, + permission_level, + groups: { connect: groups?.map((group) => ({ pid: group })) }, + }, select: { pid: true, name: true, permission_level: true }, }); diff --git a/src/app.ts b/src/app.ts index ce9c33f..75f3c95 100644 --- a/src/app.ts +++ b/src/app.ts @@ -3,6 +3,7 @@ import prisma from "./lib/prisma"; import eventRouter from "./Routes/event.routes"; import adminAuthRouter from "./Routes/admin_auth.routes"; import argon2 from "argon2"; +import adminRouter from "./Routes/admin.routes"; require("dotenv").config(); // Load dotenv config @@ -28,6 +29,8 @@ async function main() { // All API endpoints are behind /api/... app.use("/api/events", eventRouter); + app.use("/api/admins", adminRouter); + app.listen(process.env.PORT, () => { console.log(`Listening on Port: ${process.env.PORT}`); }); From bfca7e8672adaba09f091efc1e44fa44872652d3 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Tue, 21 Dec 2021 16:16:29 +0100 Subject: [PATCH 10/42] Add the permission_level 'ELEVATED' to the default user --- src/app.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 75f3c95..deffe8a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,7 +13,11 @@ async function main() { // Dev await prisma.admin.upsert({ where: { id: 1 }, - create: { name: "admin", password: await argon2.hash("test", { type: argon2.argon2id }) }, + create: { + name: "admin", + password: await argon2.hash("test", { type: argon2.argon2id }), + permission_level: "ELEVATED", + }, update: {}, }); From 5b02905d7169a0a1b272fadf22aa178d084f4dbe Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Fri, 31 Dec 2021 00:11:04 +0100 Subject: [PATCH 11/42] Add a controller and router to update a user's password + Add a function to update the password internally + The current interface could be improved (made more RESTful) --- src/Controllers/admin.controller.ts | 92 +++++++++++++++++++++++++++++ src/Routes/admin.routes.ts | 5 +- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index d15d720..46ee403 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -121,3 +121,95 @@ export const createAdmin = async (req: Request<{}, {}, CreateAdminBody>, res: Re }, }); }; + +interface UpdatePasswordBody { + name?: string; + password?: string; + new_password: string; +} + +// Expects a valid username (Should be tested beforehand) +const updatePasswordField = async (name: string, new_password: string) => { + const new_password_hash = await argon2.hash(new_password, { type: argon2.argon2id }); + + await prisma.admin.updateMany({ where: { name }, data: { password: new_password_hash } }); +}; + +// requires: auth +export const updatePassword = async (req: Request<{}, {}, UpdatePasswordBody>, res: Response) => { + if (!req.auth?.isAuthenticated) { + return res.status(500).json(AUTH_ERROR); + } + + const name = req.body.name || req.auth.name; + + if (typeof req.body.new_password !== "string") { + return res.status(400).json({ + type: "error", + payload: { + message: "The body of your request did not conform to the requirements", + schema: { + body: { + new_password: "string", + }, + }, + }, + }); + } + + const user_to_upate = await prisma.admin.findFirst({ where: { name } }); + + if (!user_to_upate) { + // REVIEW: This allows potential attackers (which are authorized with some account) + // to test account names + return res.status(404).json({ + type: "error", + payload: { + message: "The requested user was not found", + }, + }); + } + + if (req.auth.permission_level == "ELEVATED" && user_to_upate.permission_level == "STANDARD") { + updatePasswordField(name, req.body.new_password); + + res.status(200).json({ + type: "success", + }); + } else if (req.auth.name === name) { + if (typeof req.body.password !== "string") { + return res.status(400).json({ + type: "error", + payload: "The body of your request did not conform to the requirements", + schema: { + body: { + password: "string", + new_password: "string", + }, + }, + }); + } + + if (await argon2.verify(user_to_upate.password, req.body.password, { type: argon2.argon2id })) { + updatePasswordField(name, req.body.new_password); + + return res.status(200).json({ + type: "success", + }); + } + + return res.status(401).json({ + type: "error", + payload: { + message: "The provided password is not valid", + }, + }); + } else { + res.status(403).json({ + type: "error", + payload: { + message: "Operation not permitted; Try logging in as another user", + }, + }); + } +}; diff --git a/src/Routes/admin.routes.ts b/src/Routes/admin.routes.ts index 49fe551..20d5df7 100644 --- a/src/Routes/admin.routes.ts +++ b/src/Routes/admin.routes.ts @@ -1,5 +1,5 @@ import express from "express"; -import { getAllAdmins, createAdmin } from "../Controllers/admin.controller"; +import { getAllAdmins, createAdmin, updatePassword } from "../Controllers/admin.controller"; import { requireAuthentication } from "../Middleware/auth/auth"; const router = express.Router(); @@ -8,4 +8,7 @@ router.get("/", requireAuthentication, getAllAdmins); router.post("/", requireAuthentication, createAdmin); +// TODO: Use URL parameters to specify the user to update +router.put("/password", requireAuthentication, updatePassword); + export default router; From cc1c394dcecb922bcc7f210e15ec68dbf9f6b2be Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sun, 2 Jan 2022 15:46:47 +0100 Subject: [PATCH 12/42] Change the controller for changing passwords to use PIDs and not usernames --- src/Controllers/admin.controller.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index 46ee403..9cf735c 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -123,16 +123,16 @@ export const createAdmin = async (req: Request<{}, {}, CreateAdminBody>, res: Re }; interface UpdatePasswordBody { - name?: string; + pid?: string; password?: string; new_password: string; } // Expects a valid username (Should be tested beforehand) -const updatePasswordField = async (name: string, new_password: string) => { +const updatePasswordField = async (pid: string, new_password: string) => { const new_password_hash = await argon2.hash(new_password, { type: argon2.argon2id }); - await prisma.admin.updateMany({ where: { name }, data: { password: new_password_hash } }); + await prisma.admin.update({ where: { pid }, data: { password: new_password_hash } }); }; // requires: auth @@ -141,7 +141,7 @@ export const updatePassword = async (req: Request<{}, {}, UpdatePasswordBody>, r return res.status(500).json(AUTH_ERROR); } - const name = req.body.name || req.auth.name; + const pid = req.body.pid || req.auth.pid; if (typeof req.body.new_password !== "string") { return res.status(400).json({ @@ -157,7 +157,7 @@ export const updatePassword = async (req: Request<{}, {}, UpdatePasswordBody>, r }); } - const user_to_upate = await prisma.admin.findFirst({ where: { name } }); + const user_to_upate = await prisma.admin.findUnique({ where: { pid } }); if (!user_to_upate) { // REVIEW: This allows potential attackers (which are authorized with some account) @@ -171,12 +171,12 @@ export const updatePassword = async (req: Request<{}, {}, UpdatePasswordBody>, r } if (req.auth.permission_level == "ELEVATED" && user_to_upate.permission_level == "STANDARD") { - updatePasswordField(name, req.body.new_password); + updatePasswordField(pid, req.body.new_password); res.status(200).json({ type: "success", }); - } else if (req.auth.name === name) { + } else if (req.auth.pid === pid) { if (typeof req.body.password !== "string") { return res.status(400).json({ type: "error", @@ -191,7 +191,7 @@ export const updatePassword = async (req: Request<{}, {}, UpdatePasswordBody>, r } if (await argon2.verify(user_to_upate.password, req.body.password, { type: argon2.argon2id })) { - updatePasswordField(name, req.body.new_password); + updatePasswordField(pid, req.body.new_password); return res.status(200).json({ type: "success", From 4d23eccba64f3d64ffbcbe1f3a36ca7ac6ca8146 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sun, 2 Jan 2022 16:49:01 +0100 Subject: [PATCH 13/42] Restructure the process of changing a password + Requests are now dispatched to the according user ressource, not the collection + The current user can be referenced by setting the pid to 'current' + Refactored the error logic --- src/Controllers/admin.controller.ts | 119 +++++++++++++++------------- src/Controllers/common.ts | 20 +++++ src/Routes/admin.routes.ts | 6 +- 3 files changed, 88 insertions(+), 57 deletions(-) create mode 100644 src/Controllers/common.ts diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index 9cf735c..1cd66a1 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -2,6 +2,7 @@ import prisma from "../lib/prisma"; import { Request, Response } from "express"; import { AdminLevel } from "@prisma/client"; import argon2 from "argon2"; +import { DataType, generateInvalidBodyError } from "./common"; const AUTH_ERROR = { type: "failure", @@ -122,12 +123,6 @@ export const createAdmin = async (req: Request<{}, {}, CreateAdminBody>, res: Re }); }; -interface UpdatePasswordBody { - pid?: string; - password?: string; - new_password: string; -} - // Expects a valid username (Should be tested beforehand) const updatePasswordField = async (pid: string, new_password: string) => { const new_password_hash = await argon2.hash(new_password, { type: argon2.argon2id }); @@ -135,28 +130,72 @@ const updatePasswordField = async (pid: string, new_password: string) => { await prisma.admin.update({ where: { pid }, data: { password: new_password_hash } }); }; -// requires: auth -export const updatePassword = async (req: Request<{}, {}, UpdatePasswordBody>, res: Response) => { +interface UpdateForeignPasswordBody { + new_password?: string; +} + +interface UpdateForeignPasswordQueryParams { + pid: string; +} + +export const updateForeignPassword = async ( + req: Request, + res: Response +) => { if (!req.auth?.isAuthenticated) { return res.status(500).json(AUTH_ERROR); } - const pid = req.body.pid || req.auth.pid; - if (typeof req.body.new_password !== "string") { - return res.status(400).json({ + return res.status(400).json(generateInvalidBodyError({ new_password: DataType.STRING })); + } + + const user_to_upate = await prisma.admin.findUnique({ where: { pid: req.params.pid } }); + + if (!user_to_upate) { + // REVIEW: This allows potential attackers (which are authorized with some account) + // to test account names + return res.status(404).json({ type: "error", payload: { - message: "The body of your request did not conform to the requirements", - schema: { - body: { - new_password: "string", - }, - }, + message: "The requested user was not found", }, }); } + if (req.auth.permission_level == "ELEVATED" && user_to_upate.permission_level == "STANDARD") { + updatePasswordField(req.params.pid, req.body.new_password); + + res.status(200).json({ + type: "success", + }); + } else { + res.status(403).json({ + type: "error", + payload: { + message: "Operation not permitted; Try logging in as another user", + }, + }); + } +}; + +interface UpdatePasswordBody { + password?: string; + new_password?: string; +} + +// requires: auth +export const updateOwnPassword = async (req: Request<{}, {}, UpdatePasswordBody>, res: Response) => { + if (!req.auth?.isAuthenticated) { + return res.status(500).json(AUTH_ERROR); + } + + const pid = req.auth.pid; + + if (typeof req.body.password !== "string" || typeof req.body.new_password !== "string") { + return res.status(400).json(generateInvalidBodyError({ password: DataType.STRING, new_password: DataType.STRING })); + } + const user_to_upate = await prisma.admin.findUnique({ where: { pid } }); if (!user_to_upate) { @@ -170,46 +209,18 @@ export const updatePassword = async (req: Request<{}, {}, UpdatePasswordBody>, r }); } - if (req.auth.permission_level == "ELEVATED" && user_to_upate.permission_level == "STANDARD") { + if (await argon2.verify(user_to_upate.password, req.body.password, { type: argon2.argon2id })) { updatePasswordField(pid, req.body.new_password); - res.status(200).json({ + return res.status(200).json({ type: "success", }); - } else if (req.auth.pid === pid) { - if (typeof req.body.password !== "string") { - return res.status(400).json({ - type: "error", - payload: "The body of your request did not conform to the requirements", - schema: { - body: { - password: "string", - new_password: "string", - }, - }, - }); - } - - if (await argon2.verify(user_to_upate.password, req.body.password, { type: argon2.argon2id })) { - updatePasswordField(pid, req.body.new_password); - - return res.status(200).json({ - type: "success", - }); - } - - return res.status(401).json({ - type: "error", - payload: { - message: "The provided password is not valid", - }, - }); - } else { - res.status(403).json({ - type: "error", - payload: { - message: "Operation not permitted; Try logging in as another user", - }, - }); } + + return res.status(401).json({ + type: "error", + payload: { + message: "The provided password is not valid", + }, + }); }; diff --git a/src/Controllers/common.ts b/src/Controllers/common.ts new file mode 100644 index 0000000..2adc291 --- /dev/null +++ b/src/Controllers/common.ts @@ -0,0 +1,20 @@ +export enum DataType { + STRING = "string", + NUMBER = "number", + INTEGER = "integer", + PERMISSION_LEVEL = "'ELEVATED' | 'STANDARD'", +} + +interface Body { + [k: string]: DataType; +} + +export function generateInvalidBodyError(body: Body) { + return { + type: "error", + payload: { + message: "The body of your request did not conform to the requirements", + schema: { body }, + }, + }; +} diff --git a/src/Routes/admin.routes.ts b/src/Routes/admin.routes.ts index 20d5df7..b4be6ce 100644 --- a/src/Routes/admin.routes.ts +++ b/src/Routes/admin.routes.ts @@ -1,5 +1,5 @@ import express from "express"; -import { getAllAdmins, createAdmin, updatePassword } from "../Controllers/admin.controller"; +import { getAllAdmins, createAdmin, updateOwnPassword, updateForeignPassword } from "../Controllers/admin.controller"; import { requireAuthentication } from "../Middleware/auth/auth"; const router = express.Router(); @@ -8,7 +8,7 @@ router.get("/", requireAuthentication, getAllAdmins); router.post("/", requireAuthentication, createAdmin); -// TODO: Use URL parameters to specify the user to update -router.put("/password", requireAuthentication, updatePassword); +router.put("/current/password", requireAuthentication, updateOwnPassword); +router.put<"/:pid/password", { pid: string }>("/:pid/password", requireAuthentication, updateForeignPassword); export default router; From 08419d581bb5b972215cd5904d95b18cb2e0c84b Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sun, 2 Jan 2022 17:26:20 +0100 Subject: [PATCH 14/42] Update the admin revision on password change + Update type of revision to DateTime --- prisma/schema.prisma | 2 +- src/Controllers/admin.controller.ts | 18 ++++++++++++++++-- src/Controllers/admin_auth.controller.ts | 4 ++-- src/Middleware/auth/auth.ts | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0a4bcbe..7d830ce 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -49,7 +49,7 @@ model Admin { name String // TODO: This should maybe be unique password String // TODO: Probably specify hash size (VarChar or some other type) permission_level AdminLevel @default(STANDARD) - revision String @default(dbgenerated("gen_random_uuid()")) @db.Uuid + revision DateTime @default(now()) groups Group[] } diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index 1cd66a1..69dd28f 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -3,6 +3,18 @@ import { Request, Response } from "express"; import { AdminLevel } from "@prisma/client"; import argon2 from "argon2"; import { DataType, generateInvalidBodyError } from "./common"; +import { authClient } from "../lib/redis"; + +export const regenerateRevision = async (pid: string) => { + // TOOO: Add error handling + const { revision } = await prisma.admin.update({ + where: { pid }, + data: { revision: new Date() }, + select: { revision: true }, + }); + + await authClient.set(pid, revision.toISOString()); +}; const AUTH_ERROR = { type: "failure", @@ -164,7 +176,8 @@ export const updateForeignPassword = async ( } if (req.auth.permission_level == "ELEVATED" && user_to_upate.permission_level == "STANDARD") { - updatePasswordField(req.params.pid, req.body.new_password); + await updatePasswordField(req.params.pid, req.body.new_password); // REVIEW: Should this be awaited? + await regenerateRevision(req.params.pid); res.status(200).json({ type: "success", @@ -210,7 +223,8 @@ export const updateOwnPassword = async (req: Request<{}, {}, UpdatePasswordBody> } if (await argon2.verify(user_to_upate.password, req.body.password, { type: argon2.argon2id })) { - updatePasswordField(pid, req.body.new_password); + await updatePasswordField(pid, req.body.new_password); + await regenerateRevision(pid); return res.status(200).json({ type: "success", diff --git a/src/Controllers/admin_auth.controller.ts b/src/Controllers/admin_auth.controller.ts index 97161d9..8d1ec0e 100644 --- a/src/Controllers/admin_auth.controller.ts +++ b/src/Controllers/admin_auth.controller.ts @@ -21,7 +21,7 @@ function createAdminJWT(admin: Admin & { groups: Group[] }) { pid: admin.pid, name: admin.name, permission_level: admin.permission_level, - revision: admin.revision, + revision: admin.revision.toISOString(), groups: admin.groups.map((group) => group.pid), }; @@ -64,7 +64,7 @@ export const authenticateUser = async (req: Request<{}, {}, AuthenticateUserBody if (await argon2.verify(user.password, password, { type: argon2.argon2id })) { // Set password revision ID in redis - await authClient.set(user.pid, user.revision); + await authClient.set(user.pid, user.revision.toISOString()); return res.status(200).json({ type: "success", diff --git a/src/Middleware/auth/auth.ts b/src/Middleware/auth/auth.ts index 37853b5..0b66952 100644 --- a/src/Middleware/auth/auth.ts +++ b/src/Middleware/auth/auth.ts @@ -62,7 +62,7 @@ export const requireAuthentication = async (req: Request, res: Response, next: N const user = await prisma.admin.findUnique({ where: { pid }, select: { revision: true } }); if (user) { - db_revision = user.revision; + db_revision = user.revision.toISOString(); await authClient.set(pid, db_revision); } From 064497a4cabe02965c10eb86cd8a12a891bbffdc Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sun, 2 Jan 2022 17:36:21 +0100 Subject: [PATCH 15/42] Refactor the endpoints to share common code --- src/Controllers/admin.controller.ts | 20 +++++++------------- src/Controllers/admin_auth.controller.ts | 8 ++------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index 69dd28f..714d98c 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -87,19 +87,13 @@ export const createAdmin = async (req: Request<{}, {}, CreateAdminBody>, res: Re if ( !(typeof name === "string" && typeof password == "string" && isPermissionLevel(permission_level) && groupsIsValid) ) { - return res.status(400).json({ - type: "error", - payload: { - message: "The body of your request did not conform to the requirements", - schema: { - body: { - name: "string", - password_level: "string", - permission_level: "'STANDARD' | 'ELEVATED'", - }, - }, - }, - }); + return res.status(400).json( + generateInvalidBodyError({ + name: DataType.STRING, + password: DataType.STRING, + permission_level: DataType.PERMISSION_LEVEL, + }) + ); } const password_hash = await argon2.hash(password, { type: argon2.argon2id }); diff --git a/src/Controllers/admin_auth.controller.ts b/src/Controllers/admin_auth.controller.ts index 8d1ec0e..33ce37b 100644 --- a/src/Controllers/admin_auth.controller.ts +++ b/src/Controllers/admin_auth.controller.ts @@ -4,6 +4,7 @@ import { authClient } from "../lib/redis"; import prisma from "../lib/prisma"; import argon2 from "argon2"; import jwt from "jsonwebtoken"; +import { DataType, generateInvalidBodyError } from "./common"; const JWT_SECRET = process.env.JWT_SECRET || "secret"; const TOKEN_EXPIRY = "4 days"; @@ -39,12 +40,7 @@ export const authenticateUser = async (req: Request<{}, {}, AuthenticateUserBody const { name, password } = req.body || {}; if (name == null || password == null) { - return res.status(400).json({ - type: "error", - payload: { - message: "The body must contain 'name' and 'password' attributes of type string", - }, - }); + return res.status(400).json(generateInvalidBodyError({ name: DataType.STRING, password: DataType.STRING })); } const user = await prisma.admin.findFirst({ where: { name }, include: { groups: true } }); From 907c2c68fa7913d54e2369d36513e6708f3e0f4d Mon Sep 17 00:00:00 2001 From: Stefan-5422 <32109571+Stefan-5422@users.noreply.github.com> Date: Sun, 20 Mar 2022 15:31:20 +0100 Subject: [PATCH 16/42] Fix json parser return stack trace see Issue #24; --- src/app.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index deffe8a..6ef80fa 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,4 +1,4 @@ -import express from "express"; +import express, { ErrorRequestHandler, NextFunction, Request, Response } from "express"; import prisma from "./lib/prisma"; import eventRouter from "./Routes/event.routes"; import adminAuthRouter from "./Routes/admin_auth.routes"; @@ -27,6 +27,17 @@ async function main() { app.use(express.urlencoded({ extended: true })); app.use(express.json()); + app.use((err: any, req: Request, res: Response, next: NextFunction) => { + if (err) { + res.status(400).send({ + type: "error", + payload: "The body of your request did not contain valid data" + }) + } else { + next() + } + }); + // Admin authentication endpoints app.use("/api/authentication", adminAuthRouter); From 626ae40683a7626854a1dba3710306b5c3a20681 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 20 Mar 2022 17:37:51 +0100 Subject: [PATCH 17/42] [create-pull-request] push formatted files (#27) Co-authored-by: Stefan-5422 --- src/app.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index 6ef80fa..6af2048 100644 --- a/src/app.ts +++ b/src/app.ts @@ -31,10 +31,10 @@ async function main() { if (err) { res.status(400).send({ type: "error", - payload: "The body of your request did not contain valid data" - }) + payload: "The body of your request did not contain valid data", + }); } else { - next() + next(); } }); From c0ce7f32ca9b279c1c7b79cba56b7ea374ffd4eb Mon Sep 17 00:00:00 2001 From: Laurin <60652077+Flexla54@users.noreply.github.com> Date: Sun, 13 Mar 2022 02:34:20 +0100 Subject: [PATCH 18/42] updating Role model (v.2.0) --- prisma/schema.prisma | 47 +++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7d830ce..4106c5f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -46,8 +46,9 @@ model Link { model Admin { id Int @id @default(autoincrement()) pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String // TODO: This should maybe be unique + name String @unique password String // TODO: Probably specify hash size (VarChar or some other type) + permission_level AdminLevel @default(STANDARD) revision DateTime @default(now()) groups Group[] @@ -59,34 +60,33 @@ model Discipline { name String minTeamSize Int maxTeamSize Int - roles Role[] + roles RoleSchema[] teams Team[] event Event @relation(fields: [eventId], references: [id]) eventId Int } -model Role { +model RoleSchema { id Int @id @default(autoincrement()) pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid name String schema Json - participant Participant[] - discipline Discipline @relation(fields: [disciplineId], references: [id]) + roles Role[] + discipline Discipline @relation(fields: [disciplineId], references: [id]) disciplineId Int } model Team { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + leaderEmail String - participants Participant[] @relation(name: "participants") - discipline Discipline @relation(fields: [disciplineId], references: [id]) + roles Role[] @relation(name: "participants") + discipline Discipline @relation(fields: [disciplineId], references: [id]) disciplineId Int - leader Participant? @relation(name: "leader", fields: [leaderId], references: [id]) - leaderId Int @unique } model Participant { @@ -94,16 +94,26 @@ model Participant { pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid firstName String lastName String - email String gender Gender group Group @relation(fields: [groupId], references: [id]) groupId Int - team Team @relation(name: "participants", fields: [teamId], references: [id]) - teamId Int - leaderOf Team? @relation(name: "leader") roles Role[] +} +model Role { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random")) + name String //e.g. runner, swimmer,... + importance Job + score String + + participant Participant? @relation(fields: [participantId], references: [id]) + participantId Int? + team Team @relation(name: "participants", fields: [teamId], references: [id]) + teamId Int + schema RoleSchema @relation(fields: [schemaId], references: [id]) + schemaId Int } model Organisation { @@ -140,3 +150,8 @@ enum Gender { FEMALE OTHER } + +enum Job { + TEAMLEADER + MEMBER +} \ No newline at end of file From fe31a7fa34530fec7595eafa5e3116983cb8519d Mon Sep 17 00:00:00 2001 From: Laurin <60652077+Flexla54@users.noreply.github.com> Date: Sun, 20 Mar 2022 14:34:49 +0100 Subject: [PATCH 19/42] Adding VisualElement (v.2.1) --- prisma/schema.prisma | 328 ++++++++++++++++++++++--------------------- 1 file changed, 171 insertions(+), 157 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4106c5f..03ea4e4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,157 +1,171 @@ -// Schema for the main database - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} - -generator client { - provider = "prisma-client-js" -} - -model Event { - id Int @id @default(autoincrement()) // Primary key - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid // Public key - date DateTime - name String - description String - - disciplines Discipline[] - organisations Organisation[] - campaign Campaign[] -} - -model Campaign { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - start DateTime - expiresAt DateTime - - links Link[] - event Event @relation(fields: [eventId], references: [id]) - eventId Int @unique -} - -model Link { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - link String - - campaign Campaign @relation(fields: [campaignId], references: [id]) - campaignId Int - group Group? @relation(fields: [groupId], references: [id]) - groupId Int @unique -} - -model Admin { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String @unique - password String // TODO: Probably specify hash size (VarChar or some other type) - - permission_level AdminLevel @default(STANDARD) - revision DateTime @default(now()) - groups Group[] -} - -model Discipline { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String - minTeamSize Int - maxTeamSize Int - roles RoleSchema[] - - teams Team[] - event Event @relation(fields: [eventId], references: [id]) - eventId Int -} - -model RoleSchema { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String - schema Json - - roles Role[] - discipline Discipline @relation(fields: [disciplineId], references: [id]) - disciplineId Int -} - -model Team { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String - leaderEmail String - - roles Role[] @relation(name: "participants") - discipline Discipline @relation(fields: [disciplineId], references: [id]) - disciplineId Int -} - -model Participant { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - firstName String - lastName String - gender Gender - - group Group @relation(fields: [groupId], references: [id]) - groupId Int - roles Role[] -} - -model Role { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random")) - name String //e.g. runner, swimmer,... - importance Job - score String - - participant Participant? @relation(fields: [participantId], references: [id]) - participantId Int? - team Team @relation(name: "participants", fields: [teamId], references: [id]) - teamId Int - schema RoleSchema @relation(fields: [schemaId], references: [id]) - schemaId Int -} - -model Organisation { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String - - groups Group[] - event Event @relation(fields: [eventId], references: [id]) - eventId Int -} - -model Group { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String - user_limit Int @default(40) - level Int - - oragnisation Organisation @relation(fields: [oragnisationId], references: [id]) - oragnisationId Int - participants Participant[] - link Link? - admins Admin[] -} - -enum AdminLevel { - STANDARD - ELEVATED -} - -enum Gender { - MALE - FEMALE - OTHER -} - -enum Job { - TEAMLEADER - MEMBER -} \ No newline at end of file +// Schema for the main database + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" +} + +model Event { + id Int @id @default(autoincrement()) // Primary key + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid // Public key + date DateTime + name String + description String + + disciplines Discipline[] + organisations Organisation[] + campaign Campaign[] + visual VisualElement[] +} + +model Campaign { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + start DateTime + expiresAt DateTime + + links Link[] + event Event @relation(fields: [eventId], references: [id]) + eventId Int @unique +} + +model Link { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + link String + + campaign Campaign @relation(fields: [campaignId], references: [id]) + campaignId Int + group Group? @relation(fields: [groupId], references: [id]) + groupId Int @unique +} + +model Admin { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String @unique + password String // TODO: Probably specify hash size (VarChar or some other type) + + permission_level AdminLevel @default(STANDARD) + revision DateTime @default(now()) + groups Group[] +} + +model Discipline { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + minTeamSize Int + maxTeamSize Int + roles RoleSchema[] + + teams Team[] + event Event @relation(fields: [eventId], references: [id]) + eventId Int + visual VisualElement[] +} + +model RoleSchema { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + schema Json + + roles Role[] + discipline Discipline @relation(fields: [disciplineId], references: [id]) + disciplineId Int + visual VisualElement[] +} + +model Team { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + leaderEmail String + + roles Role[] @relation(name: "participants") + discipline Discipline @relation(fields: [disciplineId], references: [id]) + disciplineId Int +} + +model Participant { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + firstName String + lastName String + gender Gender + relevance Job + + group Group @relation(fields: [groupId], references: [id]) + groupId Int + roles Role[] +} + +model Role { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random")) + name String //e.g. runner, swimmer,... + score String + + participant Participant? @relation(fields: [participantId], references: [id]) + participantId Int? + team Team @relation(name: "participants", fields: [teamId], references: [id]) + teamId Int + schema RoleSchema @relation(fields: [schemaId], references: [id]) + schemaId Int +} + +model Organisation { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + + groups Group[] + event Event @relation(fields: [eventId], references: [id]) + eventId Int +} + +model Group { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + user_limit Int @default(40) + level Int + + oragnisation Organisation @relation(fields: [oragnisationId], references: [id]) + oragnisationId Int + participants Participant[] + link Link? + admins Admin[] +} + +model VisualElement { + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + description String + location String + + event Event[] + discipline Discipline[] + role RoleSchema[] +} + +enum AdminLevel { + STANDARD + ELEVATED +} + +enum Gender { + MALE + FEMALE + OTHER +} + +enum Job { + TEAMLEADER + MEMBER +} From 9b8c6b18b714868efb31aa4c4ef83a45c9b3da33 Mon Sep 17 00:00:00 2001 From: Laurin <60652077+Flexla54@users.noreply.github.com> Date: Sun, 20 Mar 2022 17:14:34 +0100 Subject: [PATCH 20/42] Updated Media, Adding referential actions(v.2.2) --- prisma/schema.prisma | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 03ea4e4..a4103a3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -19,7 +19,7 @@ model Event { disciplines Discipline[] organisations Organisation[] campaign Campaign[] - visual VisualElement[] + visual Media[] } model Campaign { @@ -29,7 +29,7 @@ model Campaign { expiresAt DateTime links Link[] - event Event @relation(fields: [eventId], references: [id]) + event Event @relation(fields: [eventId], references: [id], onDelete: Cascade) eventId Int @unique } @@ -38,9 +38,9 @@ model Link { pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid link String - campaign Campaign @relation(fields: [campaignId], references: [id]) + campaign Campaign @relation(fields: [campaignId], references: [id], onDelete: Cascade) campaignId Int - group Group? @relation(fields: [groupId], references: [id]) + group Group @relation(fields: [groupId], references: [id], onDelete: Cascade) groupId Int @unique } @@ -56,17 +56,17 @@ model Admin { } model Discipline { - id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid + id Int @id @default(autoincrement()) + pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid name String minTeamSize Int maxTeamSize Int - roles RoleSchema[] + roles RoleSchema[] teams Team[] - event Event @relation(fields: [eventId], references: [id]) + event Event @relation(fields: [eventId], references: [id], onDelete: Cascade) eventId Int - visual VisualElement[] + visual Media[] } model RoleSchema { @@ -76,9 +76,9 @@ model RoleSchema { schema Json roles Role[] - discipline Discipline @relation(fields: [disciplineId], references: [id]) + discipline Discipline @relation(fields: [disciplineId], references: [id], onDelete: Cascade) disciplineId Int - visual VisualElement[] + visual Media[] } model Team { @@ -88,7 +88,7 @@ model Team { leaderEmail String roles Role[] @relation(name: "participants") - discipline Discipline @relation(fields: [disciplineId], references: [id]) + discipline Discipline @relation(fields: [disciplineId], references: [id], onDelete: Cascade) disciplineId Int } @@ -100,7 +100,7 @@ model Participant { gender Gender relevance Job - group Group @relation(fields: [groupId], references: [id]) + group Group @relation(fields: [groupId], references: [id], onDelete: Cascade) groupId Int roles Role[] } @@ -108,14 +108,13 @@ model Participant { model Role { id Int @id @default(autoincrement()) pid String @unique @default(dbgenerated("gen_random")) - name String //e.g. runner, swimmer,... score String - participant Participant? @relation(fields: [participantId], references: [id]) + participant Participant? @relation(fields: [participantId], references: [id], onDelete: SetNull) participantId Int? - team Team @relation(name: "participants", fields: [teamId], references: [id]) + team Team @relation(name: "participants", fields: [teamId], references: [id], onDelete: Cascade) teamId Int - schema RoleSchema @relation(fields: [schemaId], references: [id]) + schema RoleSchema @relation(fields: [schemaId], references: [id], onDelete: Cascade) schemaId Int } @@ -125,7 +124,7 @@ model Organisation { name String groups Group[] - event Event @relation(fields: [eventId], references: [id]) + event Event @relation(fields: [eventId], references: [id], onDelete: Cascade) eventId Int } @@ -136,18 +135,18 @@ model Group { user_limit Int @default(40) level Int - oragnisation Organisation @relation(fields: [oragnisationId], references: [id]) + oragnisation Organisation @relation(fields: [oragnisationId], references: [id], onDelete: Cascade) oragnisationId Int participants Participant[] link Link? admins Admin[] } -model VisualElement { +model Media { id Int @id @default(autoincrement()) pid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid description String - location String + location String @unique event Event[] discipline Discipline[] From cdacc56f7f1b66c50f2293c5803c02413c75decf Mon Sep 17 00:00:00 2001 From: Stefan-5422 <32109571+Stefan-5422@users.noreply.github.com> Date: Sun, 20 Mar 2022 17:29:25 +0100 Subject: [PATCH 21/42] Update Event Endpoints to give better errors; --- src/Controllers/common.ts | 2 + src/Controllers/event.controller.ts | 93 +++++++++++++++++++++++++---- src/Routes/event.routes.ts | 7 ++- 3 files changed, 90 insertions(+), 12 deletions(-) diff --git a/src/Controllers/common.ts b/src/Controllers/common.ts index 2adc291..f327a5d 100644 --- a/src/Controllers/common.ts +++ b/src/Controllers/common.ts @@ -3,6 +3,8 @@ export enum DataType { NUMBER = "number", INTEGER = "integer", PERMISSION_LEVEL = "'ELEVATED' | 'STANDARD'", + DATETIME = "ISOstring (8601)", + UUID = "UUID string", } interface Body { diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index 814766e..00256c9 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -1,7 +1,9 @@ +import { Prisma } from "@prisma/client"; import { Request, Response } from "express"; import prisma from "../lib/prisma"; +import { DataType, generateInvalidBodyError } from "./common"; -const getAllEvents = async (req: Request, res: Response) => { +export const getAllEvents = async (req: Request, res: Response) => { const events = await prisma.event.findMany({ select: { name: true, @@ -11,17 +13,84 @@ const getAllEvents = async (req: Request, res: Response) => { id: false, }, }); - if (events.length > 0) res.status(200).send(events); - else res.status(204).send(); + if (events.length > 0) res.status(200).json(events); + else res.status(200).json([]); }; -const addEvent = async (req: Request, res: Response) => { - // TODO: Add checks if user has admin permissions +export const getEvent = async (req: Request, res: Response) => { + const eventId = req.params.eventId; - if (req.body.name == null || undefined || req.body.date == null || undefined) { - res.status(400).send("Malformed request"); + if (eventId === undefined || null) { + res.status(400).json( + generateInvalidBodyError({ + eventId: DataType.STRING, + }) + ); return; } + try { + const event = await prisma.event.findUnique({ + where: { + pid: eventId, + }, + select: { + name: true, + description: true, + date: true, + pid: true, + id: false, + }, + }); + + res.status(200).json(event); + } catch (e) { + if (e instanceof Prisma.PrismaClientKnownRequestError) { + res.status(500).json({ + type: "error", + payload: { + message: `Internal Server error occured. Try again later`, + }, + }); + return; + } + if (e instanceof Prisma.PrismaClientUnknownRequestError) { + res.status(500).json({ + type: "error", + payload: { + message: "Unknown error occured with your request. Check if your parameters are correct", + shema: { + eventId: DataType.UUID, + }, + }, + }); + return; + } + } +}; + +export const addEvent = async (req: Request, res: Response) => { + if ( + req.body.name == null || + undefined || + typeof req.body.name !== "string" || + req.body.date == null || + undefined || + typeof req.body.date !== "string" || + req.body.description == null || + undefined || + typeof req.body.description !== "string" + ) { + res.status(400).json( + generateInvalidBodyError({ + name: DataType.STRING, + date: DataType.DATETIME, + description: DataType.STRING, + }) + ); + return; + } + + //TODO: Check if date is valid const event = await prisma.event.create({ data: { @@ -36,7 +105,11 @@ const addEvent = async (req: Request, res: Response) => { id: false, }, }); - res.status(201).send(event); -}; -export { getAllEvents, addEvent }; + res.status(201).json({ + type: "succes", + payload: { + event, + }, + }); +}; diff --git a/src/Routes/event.routes.ts b/src/Routes/event.routes.ts index de0cfde..2ce9e38 100644 --- a/src/Routes/event.routes.ts +++ b/src/Routes/event.routes.ts @@ -1,9 +1,12 @@ import Express from "express"; -import { addEvent, getAllEvents } from "../Controllers/event.controller"; +import { addEvent, getAllEvents, getEvent } from "../Controllers/event.controller"; +import { requireAuthentication } from "../Middleware/auth/auth"; const router = Express.Router(); router.get("/", getAllEvents); -router.post("/", addEvent); +router.get("/:eventId", getEvent); + +router.post("/", requireAuthentication, addEvent); export default router; From 0f3b1ac707f2322329cb73e75b7fef6f83d1c950 Mon Sep 17 00:00:00 2001 From: Stefan-5422 <32109571+Stefan-5422@users.noreply.github.com> Date: Sun, 20 Mar 2022 17:50:11 +0100 Subject: [PATCH 22/42] Update common.ts types because nagging. --- src/Controllers/common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controllers/common.ts b/src/Controllers/common.ts index f327a5d..f568c75 100644 --- a/src/Controllers/common.ts +++ b/src/Controllers/common.ts @@ -3,8 +3,8 @@ export enum DataType { NUMBER = "number", INTEGER = "integer", PERMISSION_LEVEL = "'ELEVATED' | 'STANDARD'", - DATETIME = "ISOstring (8601)", - UUID = "UUID string", + DATETIME = "ISOstring", + UUID = "string", } interface Body { From 68b9044a9dc88c32c5c9e2c0a58c9be2f8db9b10 Mon Sep 17 00:00:00 2001 From: Stefan-5422 <32109571+Stefan-5422@users.noreply.github.com> Date: Tue, 22 Mar 2022 07:37:21 +0100 Subject: [PATCH 23/42] Minor changes Fixed complaints for PR #30 --- src/Controllers/event.controller.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index 00256c9..df5a8a4 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -57,7 +57,7 @@ export const getEvent = async (req: Request, res: Response) => { res.status(500).json({ type: "error", payload: { - message: "Unknown error occured with your request. Check if your parameters are correct", + message: "Unknown error occurred with your request. Check if your parameters are correct", shema: { eventId: DataType.UUID, }, @@ -70,14 +70,8 @@ export const getEvent = async (req: Request, res: Response) => { export const addEvent = async (req: Request, res: Response) => { if ( - req.body.name == null || - undefined || typeof req.body.name !== "string" || - req.body.date == null || - undefined || typeof req.body.date !== "string" || - req.body.description == null || - undefined || typeof req.body.description !== "string" ) { res.status(400).json( @@ -103,6 +97,7 @@ export const addEvent = async (req: Request, res: Response) => { date: true, pid: true, id: false, + description: true, }, }); From 43bb7baa882524bfaba860ad0ac793265e0445a2 Mon Sep 17 00:00:00 2001 From: Stefan-5422 <32109571+Stefan-5422@users.noreply.github.com> Date: Mon, 28 Mar 2022 11:52:25 +0200 Subject: [PATCH 24/42] Minor changes --- package-lock.json | 1123 +++++++++++++++++++++++++-- src/Controllers/event.controller.ts | 6 +- 2 files changed, 1076 insertions(+), 53 deletions(-) diff --git a/package-lock.json b/package-lock.json index 298b852..9948b4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,11 +10,16 @@ "license": "ISC", "dependencies": { "@prisma/client": "^3.3.0", + "@types/jsonwebtoken": "^8.5.5", "@types/node": "^16.10.3", "@types/nodemailer": "^6.4.4", + "@types/redis": "^2.8.32", + "argon2": "^0.28.2", "dotenv": "^10.0.0", "express": "^4.17.1", - "nodemailer": "^6.7.0" + "jsonwebtoken": "^8.5.1", + "nodemailer": "^6.7.0", + "redis": "^3.1.2" }, "devDependencies": { "@types/chai": "^4.2.22", @@ -52,6 +57,33 @@ "node": ">=12" } }, + "node_modules/@mapbox/node-pre-gyp": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.8.tgz", + "integrity": "sha512-CMGKi28CF+qlbXh26hDe6NxCd7amqeAzEqnS6IHeO6LoaKyM/n+Xw3HT1COdq8cuioOdlKdqn/hCmqPUOMOywg==", + "dependencies": { + "detect-libc": "^1.0.3", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.5", + "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/@phc/format": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@phc/format/-/format-1.0.0.tgz", + "integrity": "sha512-m7X9U6BG2+J+R1lSOdCiITLLrxm+cWlNI3HUFA92oLO77ObGNzaKdh8pMLqdZcshtkKuV84olNNXDfMc4FezBQ==", + "engines": { + "node": ">=10" + } + }, "node_modules/@prisma/client": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.3.0.tgz", @@ -181,6 +213,14 @@ "@types/range-parser": "*" } }, + "node_modules/@types/jsonwebtoken": { + "version": "8.5.8", + "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-8.5.8.tgz", + "integrity": "sha512-zm6xBQpFDIDM6o9r6HSgDeIcLy82TKWctCXEPbJJcXb5AKmi5BNNdLXneixK4lplX3PqIVcwLBCGE/kAGnlD4A==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/mime": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz", @@ -218,6 +258,14 @@ "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", "dev": true }, + "node_modules/@types/redis": { + "version": "2.8.32", + "resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.32.tgz", + "integrity": "sha512-7jkMKxcGq9p242exlbsVzuJb57KqHRhNl4dHoQu2Y5v9bCAbtIXXH0R3HleSQW4CTOqpHIYUW3t6tpUj4BVQ+w==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/serve-static": { "version": "1.13.10", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.10.tgz", @@ -244,6 +292,11 @@ "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", "dev": true }, + "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.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -277,6 +330,38 @@ "node": ">=0.4.0" } }, + "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-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", @@ -290,7 +375,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "engines": { "node": ">=8" } @@ -323,12 +407,56 @@ "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/are-we-there-yet/node_modules/readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true }, + "node_modules/argon2": { + "version": "0.28.5", + "resolved": "https://registry.npmjs.org/argon2/-/argon2-0.28.5.tgz", + "integrity": "sha512-kGFCctzc3VWmR1aCOYjNgvoTmVF5uVBUtWlXCKKO54d1K+31zRz45KAcDIqMo2746ozv/52d25nfEekitaXP0w==", + "hasInstallScript": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.8", + "@phc/format": "^1.0.0", + "node-addon-api": "^4.3.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -358,8 +486,7 @@ "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==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/binary-extensions": { "version": "2.2.0", @@ -394,7 +521,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -418,6 +544,11 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, + "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": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, "node_modules/bytes": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", @@ -543,6 +674,14 @@ "fsevents": "~2.3.2" } }, + "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/cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", @@ -572,6 +711,14 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "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/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -593,8 +740,12 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "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": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" }, "node_modules/content-disposition": { "version": "0.5.3", @@ -687,6 +838,19 @@ "node": ">=0.4.0" } }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" + }, + "node_modules/denque": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", + "engines": { + "node": ">=0.10" + } + }, "node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -700,6 +864,17 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "node_modules/detect-libc": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", + "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", + "bin": { + "detect-libc": "bin/detect-libc.js" + }, + "engines": { + "node": ">=0.10" + } + }, "node_modules/diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -717,6 +892,14 @@ "node": ">=10" } }, + "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", @@ -725,8 +908,7 @@ "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==", - "dev": true + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "node_modules/encodeurl": { "version": "1.0.2", @@ -909,11 +1091,21 @@ "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.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "node_modules/fsevents": { "version": "2.3.2", @@ -929,6 +1121,25 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "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-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -951,7 +1162,6 @@ "version": "7.1.7", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", - "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -997,6 +1207,11 @@ "node": ">=8" } }, + "node_modules/has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" + }, "node_modules/he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", @@ -1021,6 +1236,39 @@ "node": ">= 0.6" } }, + "node_modules/https-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", + "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "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", @@ -1036,7 +1284,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -1089,7 +1336,6 @@ "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==", - "dev": true, "engines": { "node": ">=8" } @@ -1172,6 +1418,59 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsonwebtoken": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", + "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^5.6.0" + }, + "engines": { + "node": ">=4", + "npm": ">=1.4.28" + } + }, + "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/jsonwebtoken/node_modules/semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "bin": { + "semver": "bin/semver" + } + }, + "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/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -1187,6 +1486,41 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -1203,6 +1537,39 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "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/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -1264,7 +1631,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -1272,6 +1638,40 @@ "node": "*" } }, + "node_modules/minipass": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.6.tgz", + "integrity": "sha512-rty5kpw9/z8SX9dmxblFA6edItUmwJgMeYDZRrwlIVN27i8gysGbznJwUggw2V/FVqFSDdWy040ZPS811DYAqQ==", + "dependencies": { + "yallist": "^4.0.0" + }, + "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/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/mocha": { "version": "9.1.3", "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.3.tgz", @@ -1378,6 +1778,30 @@ "node": ">= 0.6" } }, + "node_modules/node-addon-api": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", + "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==" + }, + "node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/nodemailer": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.0.tgz", @@ -1386,6 +1810,20 @@ "node": ">=6.0.0" } }, + "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/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -1395,6 +1833,25 @@ "node": ">=0.10.0" } }, + "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": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -1410,7 +1867,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "dependencies": { "wrappy": "1" } @@ -1466,7 +1922,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -1598,6 +2053,48 @@ "node": ">=8.10.0" } }, + "node_modules/redis": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz", + "integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==", + "dependencies": { + "denque": "^1.5.0", + "redis-commands": "^1.7.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-redis" + } + }, + "node_modules/redis-commands": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz", + "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==" + }, + "node_modules/redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=", + "engines": { + "node": ">=4" + } + }, + "node_modules/redis-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=", + "dependencies": { + "redis-errors": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -1607,6 +2104,20 @@ "node": ">=0.10.0" } }, + "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.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -1617,6 +2128,20 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "node_modules/semver": { + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/send": { "version": "0.17.1", "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", @@ -1668,11 +2193,21 @@ "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": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, "node_modules/setprototypeof": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, + "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": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -1685,7 +2220,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -1694,7 +2228,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -1708,7 +2241,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -1779,6 +2311,22 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, + "node_modules/tar": { + "version": "6.1.11", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz", + "integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^3.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 10" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -1799,6 +2347,11 @@ "node": ">=0.6" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, "node_modules/ts-node": { "version": "10.2.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.2.1.tgz", @@ -1888,8 +2441,7 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "node_modules/utils-merge": { "version": "1.0.1", @@ -1907,6 +2459,20 @@ "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": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -1922,6 +2488,14 @@ "node": ">= 8" } }, + "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/workerpool": { "version": "6.1.5", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.5.tgz", @@ -1948,8 +2522,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "node_modules/y18n": { "version": "5.0.8", @@ -1960,6 +2533,11 @@ "node": ">=10" } }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/yargs": { "version": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", @@ -2040,6 +2618,27 @@ "@cspotcode/source-map-consumer": "0.8.0" } }, + "@mapbox/node-pre-gyp": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.8.tgz", + "integrity": "sha512-CMGKi28CF+qlbXh26hDe6NxCd7amqeAzEqnS6IHeO6LoaKyM/n+Xw3HT1COdq8cuioOdlKdqn/hCmqPUOMOywg==", + "requires": { + "detect-libc": "^1.0.3", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.5", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + } + }, + "@phc/format": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@phc/format/-/format-1.0.0.tgz", + "integrity": "sha512-m7X9U6BG2+J+R1lSOdCiITLLrxm+cWlNI3HUFA92oLO77ObGNzaKdh8pMLqdZcshtkKuV84olNNXDfMc4FezBQ==" + }, "@prisma/client": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.3.0.tgz", @@ -2155,6 +2754,14 @@ "@types/range-parser": "*" } }, + "@types/jsonwebtoken": { + "version": "8.5.8", + "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-8.5.8.tgz", + "integrity": "sha512-zm6xBQpFDIDM6o9r6HSgDeIcLy82TKWctCXEPbJJcXb5AKmi5BNNdLXneixK4lplX3PqIVcwLBCGE/kAGnlD4A==", + "requires": { + "@types/node": "*" + } + }, "@types/mime": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz", @@ -2192,6 +2799,14 @@ "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", "dev": true }, + "@types/redis": { + "version": "2.8.32", + "resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.32.tgz", + "integrity": "sha512-7jkMKxcGq9p242exlbsVzuJb57KqHRhNl4dHoQu2Y5v9bCAbtIXXH0R3HleSQW4CTOqpHIYUW3t6tpUj4BVQ+w==", + "requires": { + "@types/node": "*" + } + }, "@types/serve-static": { "version": "1.13.10", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.10.tgz", @@ -2218,6 +2833,11 @@ "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", "dev": true }, + "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.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -2239,6 +2859,29 @@ "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true }, + "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-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", @@ -2248,8 +2891,7 @@ "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" }, "ansi-styles": { "version": "4.3.0", @@ -2270,12 +2912,48 @@ "picomatch": "^2.0.4" } }, + "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" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true }, + "argon2": { + "version": "0.28.5", + "resolved": "https://registry.npmjs.org/argon2/-/argon2-0.28.5.tgz", + "integrity": "sha512-kGFCctzc3VWmR1aCOYjNgvoTmVF5uVBUtWlXCKKO54d1K+31zRz45KAcDIqMo2746ozv/52d25nfEekitaXP0w==", + "requires": { + "@mapbox/node-pre-gyp": "^1.0.8", + "@phc/format": "^1.0.0", + "node-addon-api": "^4.3.0" + } + }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -2302,8 +2980,7 @@ "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "binary-extensions": { "version": "2.2.0", @@ -2332,7 +3009,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2353,6 +3029,11 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, + "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": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, "bytes": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", @@ -2445,6 +3126,11 @@ "readdirp": "~3.6.0" } }, + "chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==" + }, "cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", @@ -2471,6 +3157,11 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "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==" + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -2489,8 +3180,12 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" }, "content-disposition": { "version": "0.5.3", @@ -2562,6 +3257,16 @@ "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", "dev": true }, + "delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" + }, + "denque": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==" + }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -2572,6 +3277,11 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "detect-libc": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", + "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=" + }, "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -2583,6 +3293,14 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" }, + "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", @@ -2591,8 +3309,7 @@ "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==", - "dev": true + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "encodeurl": { "version": "1.0.2", @@ -2730,11 +3447,18 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "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" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "2.3.2", @@ -2743,6 +3467,22 @@ "dev": true, "optional": true }, + "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-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -2759,7 +3499,6 @@ "version": "7.1.7", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -2790,6 +3529,11 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, + "has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" + }, "he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", @@ -2808,6 +3552,30 @@ "toidentifier": "1.0.0" } }, + "https-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", + "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "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", @@ -2820,7 +3588,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -2860,8 +3627,7 @@ "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==", - "dev": true + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" }, "is-glob": { "version": "4.0.3", @@ -2920,6 +3686,54 @@ "argparse": "^2.0.1" } }, + "jsonwebtoken": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", + "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", + "requires": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^5.6.0" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + } + } + }, + "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" + } + }, "locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -2929,6 +3743,41 @@ "p-locate": "^5.0.0" } }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" + }, + "lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" + }, + "lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" + }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, "log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -2939,6 +3788,29 @@ "is-unicode-supported": "^0.1.0" } }, + "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==" + } + } + }, "make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -2982,11 +3854,32 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } }, + "minipass": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.6.tgz", + "integrity": "sha512-rty5kpw9/z8SX9dmxblFA6edItUmwJgMeYDZRrwlIVN27i8gysGbznJwUggw2V/FVqFSDdWy040ZPS811DYAqQ==", + "requires": { + "yallist": "^4.0.0" + } + }, + "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" + } + }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + }, "mocha": { "version": "9.1.3", "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.3.tgz", @@ -3066,17 +3959,54 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, + "node-addon-api": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", + "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==" + }, + "node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, "nodemailer": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.0.tgz", "integrity": "sha512-AtiTVUFHLiiDnMQ43zi0YgkzHOEWUkhDgPlBXrsDzJiJvB29Alo4OKxHQ0ugF3gRqRQIneCLtZU3yiUo7pItZw==" }, + "nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "requires": { + "abbrev": "1" + } + }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, + "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": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -3089,7 +4019,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -3126,8 +4055,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-to-regexp": { "version": "0.1.7", @@ -3224,12 +4152,49 @@ "picomatch": "^2.2.1" } }, + "redis": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz", + "integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==", + "requires": { + "denque": "^1.5.0", + "redis-commands": "^1.7.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0" + } + }, + "redis-commands": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz", + "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==" + }, + "redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=" + }, + "redis-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=", + "requires": { + "redis-errors": "^1.0.0" + } + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", "dev": true }, + "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.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -3240,6 +4205,14 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "semver": { + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "requires": { + "lru-cache": "^6.0.0" + } + }, "send": { "version": "0.17.1", "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", @@ -3287,11 +4260,21 @@ "send": "0.17.1" } }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, "setprototypeof": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, + "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": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -3301,7 +4284,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "requires": { "safe-buffer": "~5.1.0" } @@ -3310,7 +4292,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "requires": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -3321,7 +4302,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "requires": { "ansi-regex": "^5.0.1" } @@ -3376,6 +4356,19 @@ "has-flag": "^4.0.0" } }, + "tar": { + "version": "6.1.11", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz", + "integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==", + "requires": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^3.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + } + }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -3390,6 +4383,11 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, "ts-node": { "version": "10.2.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.2.1.tgz", @@ -3439,8 +4437,7 @@ "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "utils-merge": { "version": "1.0.1", @@ -3452,6 +4449,20 @@ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -3461,6 +4472,14 @@ "isexe": "^2.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" + } + }, "workerpool": { "version": "6.1.5", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.5.tgz", @@ -3481,8 +4500,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "y18n": { "version": "5.0.8", @@ -3490,6 +4508,11 @@ "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "dev": true }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "yargs": { "version": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index df5a8a4..465b8bf 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -20,10 +20,10 @@ export const getAllEvents = async (req: Request, res: Response) => { export const getEvent = async (req: Request, res: Response) => { const eventId = req.params.eventId; - if (eventId === undefined || null) { + if (typeof eventId !== "string") { res.status(400).json( generateInvalidBodyError({ - eventId: DataType.STRING, + eventId: DataType.UUID, }) ); return; @@ -58,7 +58,7 @@ export const getEvent = async (req: Request, res: Response) => { type: "error", payload: { message: "Unknown error occurred with your request. Check if your parameters are correct", - shema: { + schema: { eventId: DataType.UUID, }, }, From d7e7694249b910f4f3b8d3af8bb3775af9c31bdd Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:01:45 +0200 Subject: [PATCH 25/42] Fix: The server should always return 403 on failed login --- src/Controllers/admin_auth.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/admin_auth.controller.ts b/src/Controllers/admin_auth.controller.ts index 33ce37b..760e85d 100644 --- a/src/Controllers/admin_auth.controller.ts +++ b/src/Controllers/admin_auth.controller.ts @@ -50,7 +50,7 @@ export const authenticateUser = async (req: Request<{}, {}, AuthenticateUserBody // with only the username if (!user) { - return res.status(404).json({ + return res.status(403).json({ type: "error", payload: { message: `The provided credentials are not valid`, From d2de4e9208829496917ce35b1dfa54244d760b26 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:52:23 +0200 Subject: [PATCH 26/42] HOTFIX: Name of uuid function The prisma schema didn't compile with the previous schema --- prisma/schema.prisma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index a4103a3..8025cd4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -107,7 +107,7 @@ model Participant { model Role { id Int @id @default(autoincrement()) - pid String @unique @default(dbgenerated("gen_random")) + pid String @unique @default(dbgenerated("gen_random_uuid()")) score String participant Participant? @relation(fields: [participantId], references: [id], onDelete: SetNull) From dce75d1a9779e8540e22bf7f3a6ae73a695b2d6f Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Tue, 26 Apr 2022 11:22:45 +0200 Subject: [PATCH 27/42] Port yens dev script to detleph + Provides more config options + Allows deleting and resetting the database --- dev.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/dev.sh b/dev.sh index d6b8e5a..b669776 100755 --- a/dev.sh +++ b/dev.sh @@ -1,26 +1,59 @@ #!/bin/bash -DATABASE_PASSWORD=server COMPOSE_PROJECT_NAME=detleph_server docker-compose up -d mail postgres redis +D_SERVICES="mail postgres redis" + +DATABASE_PASSWORD=server COMPOSE_PROJECT_NAME=detleph_server docker-compose up -d $D_SERVICES + +# Flag: Should the container be deleted and created again? +RECREATE=true +D_PORT="${PORT:-3000}" + +if [ "$(docker ps -a | grep detleph_server_dev)" ]; then + echo "The dev server is already on the system!" + + RECREATE=false + + # Use -s flag to skip any prompts + if [ "$1" != "-s" ]; then + echo "Do you want to recreate it? [y/n]" + read input + + if [ "$input" = "y" ]; then + RECREATE=true + fi + fi + + if [ "$RECREATE" = true ]; then + echo "Removing container" + docker rm detleph_server_dev + rm -f INITIALIZED # Flag has to be reset + + echo "Do you also want to reset the other services? [y/n]" + read input + + if [ "$input" = "y" ]; then + COMPOSE_PROJECT_NAME=detleph_server docker-compose down + DATABASE_PASSWORD=server COMPOSE_PROJECT_NAME=detleph_server docker-compose up -d $D_SERVICES + fi + + else + echo "Starting existing container" + docker start -ia detleph_server_dev + fi +fi + +if [ "$RECREATE" = true ]; then + echo "Creating the dev container" -if [ ! "$(docker ps -a | grep detleph_server_dev)" ]; then - echo "Creating the server container" - docker run -it \ --name detleph_server_dev \ --mount type=bind,source="$(pwd)",target=/app \ --network detleph_server_default \ - -p 3000:3000 -e PORT=3000 \ - -e DATABASE_URL="postgresql://server:server@postgres:5432/management?schema=public" \ - -e DATABASE_USER=server \ + -p $D_PORT:$D_PORT -e PORT=$D_PORT \ -e DATABASE_PASSWORD=server \ + -e DATABASE_URL="postgresql://server:server@postgres:5432/management?schema=public" \ --entrypoint "/app/scripts/docker-entrypoint.dev.sh" \ node -else - echo "The server container already exists; Starting..." - - docker start -ia detleph_server_dev fi -# After container termination - COMPOSE_PROJECT_NAME=detleph_server docker-compose stop From 37437152da955afe53a2ccba3e1ae6ea1ee0028e Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:57:18 +0200 Subject: [PATCH 28/42] Add the organisation controller + Add function to get all organisation + Add function to get a specific organisation --- src/Controllers/organisation.controller.ts | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Controllers/organisation.controller.ts diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts new file mode 100644 index 0000000..48c9cd9 --- /dev/null +++ b/src/Controllers/organisation.controller.ts @@ -0,0 +1,51 @@ +import { Request, Response } from "express"; +import prisma from "../lib/prisma"; +import { DataType, generateInvalidBodyError } from "./common"; + +export const getAllOrganisations = async (req: Request, res: Response) => { + const organisations = await prisma.organisation.findMany({ + select: { pid: true, name: true, event: { select: { pid: true, name: true } } }, + }); + + res.status(200).json({ + type: "success", + payload: { + organisations, + }, + }); +}; + +interface GetOrganisationQueryParams { + pid: string; +} + +export const getOrganisation = async (req: Request, res: Response) => { + const { pid } = req.params; + + const organisation = await prisma.organisation.findUnique({ + where: { pid }, + select: { pid: true, name: true, event: { select: { pid: true, date: true, name: true, description: true } } }, + }); + + if (!organisation) { + return res.status(404).json({ + type: "error", + payload: { + message: `The organisation with ID '${pid} could not be found'`, + }, + }); + } + + return res.status(200).json({ + type: "success", + payload: { + organisation: { + ...organisation, + event: { + ...organisation.event, + _links: [{ rel: "self", type: "GET", href: `/api/event/${organisation.event.pid}` }], + }, + }, + }, + }); +}; From ab62e39d8edcc1d3635e814d9628292a7180b19d Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 15:47:24 +0200 Subject: [PATCH 29/42] Add function to create new organisations + Extract common functions from the admin controller --- src/Controllers/admin.controller.ts | 24 +-------- src/Controllers/common.ts | 24 +++++++++ src/Controllers/organisation.controller.ts | 62 +++++++++++++++++++++- 3 files changed, 86 insertions(+), 24 deletions(-) diff --git a/src/Controllers/admin.controller.ts b/src/Controllers/admin.controller.ts index 714d98c..cdbc2ed 100644 --- a/src/Controllers/admin.controller.ts +++ b/src/Controllers/admin.controller.ts @@ -2,7 +2,7 @@ import prisma from "../lib/prisma"; import { Request, Response } from "express"; import { AdminLevel } from "@prisma/client"; import argon2 from "argon2"; -import { DataType, generateInvalidBodyError } from "./common"; +import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common"; import { authClient } from "../lib/redis"; export const regenerateRevision = async (pid: string) => { @@ -16,28 +16,6 @@ export const regenerateRevision = async (pid: string) => { await authClient.set(pid, revision.toISOString()); }; -const AUTH_ERROR = { - type: "failure", - payload: { - message: "The server was not able to validate your credentials; Please try again later", - }, -}; - -const createInsufficientPermissionsError = (required: AdminLevel = "ELEVATED") => ({ - type: "error", - payload: { - message: "You do not have sufficient permissions to use this feature", - required_level: required, - }, - _links: [ - { - rel: "authentication", - href: "/api/authentication", - type: "POST", - }, - ], -}); - // requires: auth(elevated) export const getAllAdmins = async (req: Request, res: Response) => { if (!req.auth?.isAuthenticated) { diff --git a/src/Controllers/common.ts b/src/Controllers/common.ts index f568c75..2e6bb5e 100644 --- a/src/Controllers/common.ts +++ b/src/Controllers/common.ts @@ -1,3 +1,5 @@ +import { AdminLevel } from "@prisma/client"; + export enum DataType { STRING = "string", NUMBER = "number", @@ -20,3 +22,25 @@ export function generateInvalidBodyError(body: Body) { }, }; } + +export const AUTH_ERROR = { + type: "failure", + payload: { + message: "The server was not able to validate your credentials; Please try again later", + }, +}; + +export const createInsufficientPermissionsError = (required: AdminLevel = "ELEVATED") => ({ + type: "error", + payload: { + message: "You do not have sufficient permissions to use this feature", + required_level: required, + }, + _links: [ + { + rel: "authentication", + href: "/api/authentication", + type: "POST", + }, + ], +}); diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index 48c9cd9..c5ec5df 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -1,6 +1,7 @@ +import { PrismaClientUnknownRequestError } from "@prisma/client/runtime"; import { Request, Response } from "express"; import prisma from "../lib/prisma"; -import { DataType, generateInvalidBodyError } from "./common"; +import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common"; export const getAllOrganisations = async (req: Request, res: Response) => { const organisations = await prisma.organisation.findMany({ @@ -49,3 +50,62 @@ export const getOrganisation = async (req: Request, }, }); }; + +interface CreateOrganisationQueryParams { + eventPid: string; +} + +interface CreateOrganisationBody { + name?: string; +} + +// at: POST /api/events/:eventPid/organisations +// requires: auth(ELEVATED) +export const createOrganisation = async ( + req: Request, + res: Response +) => { + if (!req.auth?.isAuthenticated) { + return res.status(500).json(AUTH_ERROR); + } + + if (req.auth.permission_level !== "ELEVATED") { + return res.status(403).json(createInsufficientPermissionsError()); + } + + const { name } = req.body || {}; + const { eventPid } = req.params; + + if (typeof name !== "string") { + return res.status(400).json(generateInvalidBodyError({ name: DataType.STRING, eventId: DataType.UUID })); + } + + // Check if event exists + + try { + const event = await prisma.event.findUnique({ where: { pid: eventPid } }); + + if (!event) { + return res.status(404).json({ + type: "error", + payload: { + message: `The event with the ID ${eventPid} could not be found`, + }, + }); + } + } catch (e) { + // REVIEW: Check for valid UUID + if (e instanceof PrismaClientUnknownRequestError) { + return res.status(400).send({ + type: "error", + payload: { + message: "Unknown error occured. This could be to malformed IDs", + }, + }); + } + } + + const organisation = await prisma.organisation.create({ data: { name, event: { connect: { pid: eventPid } } } }); + + res.status(201).json({ type: "success", payload: { organisation } }); +}; From 08e18db3c3b5c22899ca7141dd7f1ccc59b4bc8f Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 15:56:55 +0200 Subject: [PATCH 30/42] Extract common function to handle selecting organisations --- src/Controllers/organisation.controller.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index c5ec5df..559cc8d 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -3,12 +3,13 @@ import { Request, Response } from "express"; import prisma from "../lib/prisma"; import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common"; -export const getAllOrganisations = async (req: Request, res: Response) => { +export const _getAllOrganisations = async (res: Response, eventId: number | undefined = undefined) => { const organisations = await prisma.organisation.findMany({ + where: { eventId }, select: { pid: true, name: true, event: { select: { pid: true, name: true } } }, }); - res.status(200).json({ + return res.status(200).json({ type: "success", payload: { organisations, @@ -16,6 +17,16 @@ export const getAllOrganisations = async (req: Request, res: Response) => { }); }; +interface GetAllOrganisationsSearchParams { + eventId?: string; +} + +export const getAllOrganisations = async (req: Request<{}, {}, {}, GetAllOrganisationsSearchParams>, res: Response) => { + const eventId = parseInt(req.query.eventId || ""); + + return _getAllOrganisations(res, isNaN(eventId) ? undefined : eventId); +}; + interface GetOrganisationQueryParams { pid: string; } From 831017e7c23fbd4b47af133e9f784f6a0af30c7b Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 16:13:32 +0200 Subject: [PATCH 31/42] Add routes for organisations + FIX: Change eventId type --- src/Controllers/organisation.controller.ts | 18 +++++++++++++---- src/Routes/organisation.routes.ts | 23 ++++++++++++++++++++++ src/app.ts | 3 +++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/Routes/organisation.routes.ts diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index 559cc8d..1987ee9 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -3,9 +3,9 @@ import { Request, Response } from "express"; import prisma from "../lib/prisma"; import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common"; -export const _getAllOrganisations = async (res: Response, eventId: number | undefined = undefined) => { +export const _getAllOrganisations = async (res: Response, eventId: string | undefined = undefined) => { const organisations = await prisma.organisation.findMany({ - where: { eventId }, + where: { event: { pid: eventId } }, select: { pid: true, name: true, event: { select: { pid: true, name: true } } }, }); @@ -22,9 +22,19 @@ interface GetAllOrganisationsSearchParams { } export const getAllOrganisations = async (req: Request<{}, {}, {}, GetAllOrganisationsSearchParams>, res: Response) => { - const eventId = parseInt(req.query.eventId || ""); + // TODO: Maybe rename to eventPid + return _getAllOrganisations(res, req.query.eventId); +}; - return _getAllOrganisations(res, isNaN(eventId) ? undefined : eventId); +interface GetAllOrganisationsWithParamQueryParams { + eventPid: string; +} + +export const getAllOrganisationsWithParam = async ( + req: Request, + res: Response +) => { + return _getAllOrganisations(res, req.params.eventPid); }; interface GetOrganisationQueryParams { diff --git a/src/Routes/organisation.routes.ts b/src/Routes/organisation.routes.ts new file mode 100644 index 0000000..19a25a7 --- /dev/null +++ b/src/Routes/organisation.routes.ts @@ -0,0 +1,23 @@ +import express from "express"; +import eventRouter from "./event.routes"; +import { + createOrganisation, + getAllOrganisations, + getAllOrganisationsWithParam, + getOrganisation, +} from "../Controllers/organisation.controller"; +import { requireAuthentication } from "../Middleware/auth/auth"; + +const router = express.Router(); + +router.get("/", getAllOrganisations); +router.get("/:pid", getOrganisation); + +eventRouter.get("/:eventPid/organisations", getAllOrganisationsWithParam); +eventRouter.post<"/:eventPid/organisations", { eventPid: string }>( + "/:eventPid/organisations", + requireAuthentication, + createOrganisation +); + +export default router; diff --git a/src/app.ts b/src/app.ts index 6af2048..0c5c408 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,6 +4,7 @@ import eventRouter from "./Routes/event.routes"; import adminAuthRouter from "./Routes/admin_auth.routes"; import argon2 from "argon2"; import adminRouter from "./Routes/admin.routes"; +import organisationRouter from "./Routes/organisation.routes"; require("dotenv").config(); // Load dotenv config @@ -46,6 +47,8 @@ async function main() { app.use("/api/admins", adminRouter); + app.use("/api/organisations", organisationRouter); + app.listen(process.env.PORT, () => { console.log(`Listening on Port: ${process.env.PORT}`); }); From 12034fa32ab61185c9073cd90b408ef43f3746be Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:10:23 +0200 Subject: [PATCH 32/42] Add function to update an organisation + Extract basicOrganisation and detailedOrganiation select types --- src/Controllers/organisation.controller.ts | 83 ++++++++++++++++++++-- src/Routes/organisation.routes.ts | 2 + 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index 1987ee9..3f5d9ba 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -2,11 +2,37 @@ import { PrismaClientUnknownRequestError } from "@prisma/client/runtime"; import { Request, Response } from "express"; import prisma from "../lib/prisma"; import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common"; +import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; +import { Prisma } from "@prisma/client"; + +const detailedOrganisation = { + pid: true, + name: true, + event: { + select: { + pid: true, + name: true, + date: true, + description: true, + }, + }, +} as const; + +const basicOrganisation = { + pid: true, + name: true, + event: { + select: { + pid: true, + name: true, + }, + }, +} as const; export const _getAllOrganisations = async (res: Response, eventId: string | undefined = undefined) => { const organisations = await prisma.organisation.findMany({ where: { event: { pid: eventId } }, - select: { pid: true, name: true, event: { select: { pid: true, name: true } } }, + select: basicOrganisation, }); return res.status(200).json({ @@ -46,7 +72,7 @@ export const getOrganisation = async (req: Request, const organisation = await prisma.organisation.findUnique({ where: { pid }, - select: { pid: true, name: true, event: { select: { pid: true, date: true, name: true, description: true } } }, + select: detailedOrganisation, }); if (!organisation) { @@ -104,7 +130,7 @@ export const createOrganisation = async ( // Check if event exists try { - const event = await prisma.event.findUnique({ where: { pid: eventPid } }); + const event = await prisma.event.findUnique({ where: { pid: eventPid }, select: { id: true } }); if (!event) { return res.status(404).json({ @@ -126,7 +152,56 @@ export const createOrganisation = async ( } } - const organisation = await prisma.organisation.create({ data: { name, event: { connect: { pid: eventPid } } } }); + const organisation = await prisma.organisation.create({ + data: { name, event: { connect: { pid: eventPid } } }, + select: detailedOrganisation, + }); res.status(201).json({ type: "success", payload: { organisation } }); }; + +interface UpdateOrganisationQueryParams { + pid: string; +} + +interface UpdateOrganisationBody { + name?: string; +} + +// requires: auth(ELEVATED) +export const updateOrganisation = async ( + req: Request, + res: Response +) => { + if (!req.auth?.isAuthenticated) { + return res.status(500).json(AUTH_ERROR); + } + + if (req.auth.permission_level !== "ELEVATED") { + return res.status(403).json(createInsufficientPermissionsError()); + } + + const { pid } = req.params; + const { name } = req.body; + + if (name && typeof name !== "string") { + return res.status(400).json( + generateInvalidBodyError({ + name: DataType.STRING, + }) + ); + } + + const organisation = await prisma.organisation.update({ + where: { pid }, + data: { name }, + select: detailedOrganisation, + }); + + return res.status(200).json({ + type: "success", + payload: { + organisation, + }, + }); +}; diff --git a/src/Routes/organisation.routes.ts b/src/Routes/organisation.routes.ts index 19a25a7..7cff08d 100644 --- a/src/Routes/organisation.routes.ts +++ b/src/Routes/organisation.routes.ts @@ -5,6 +5,7 @@ import { getAllOrganisations, getAllOrganisationsWithParam, getOrganisation, + updateOrganisation, } from "../Controllers/organisation.controller"; import { requireAuthentication } from "../Middleware/auth/auth"; @@ -12,6 +13,7 @@ const router = express.Router(); router.get("/", getAllOrganisations); router.get("/:pid", getOrganisation); +router.put<"/:pid", { pid: string }>("/:pid", requireAuthentication, updateOrganisation); eventRouter.get("/:eventPid/organisations", getAllOrganisationsWithParam); eventRouter.post<"/:eventPid/organisations", { eventPid: string }>( From ca11eba3d4fb0eb0dd8c0e67d8ffd95d3248b0ea Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:21:14 +0200 Subject: [PATCH 33/42] Add better error handling --- src/Controllers/organisation.controller.ts | 59 +++++++++++++++++----- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index 3f5d9ba..cab0c0d 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -5,6 +5,10 @@ import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInval import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; import { Prisma } from "@prisma/client"; +function validateOranisationName(name: string) { + return name.length > 0; +} + const detailedOrganisation = { pid: true, name: true, @@ -127,6 +131,15 @@ export const createOrganisation = async ( return res.status(400).json(generateInvalidBodyError({ name: DataType.STRING, eventId: DataType.UUID })); } + if (!validateOranisationName(name)) { + return res.status(400).json({ + type: "error", + payload: { + message: "The name has to be at least 1 character long", + }, + }); + } + // Check if event exists try { @@ -184,7 +197,7 @@ export const updateOrganisation = async ( const { pid } = req.params; const { name } = req.body; - if (name && typeof name !== "string") { + if (name !== undefined && typeof name !== "string") { return res.status(400).json( generateInvalidBodyError({ name: DataType.STRING, @@ -192,16 +205,38 @@ export const updateOrganisation = async ( ); } - const organisation = await prisma.organisation.update({ - where: { pid }, - data: { name }, - select: detailedOrganisation, - }); + if (name !== undefined && !validateOranisationName(name)) { + return res.status(400).json({ + type: "error", + payload: { + message: "The name has to be at least 1 character long", + }, + }); + } - return res.status(200).json({ - type: "success", - payload: { - organisation, - }, - }); + try { + const organisation = await prisma.organisation.update({ + where: { pid }, + data: { name }, + select: detailedOrganisation, + }); + + return res.status(200).json({ + type: "success", + payload: { + organisation, + }, + }); + } catch (e) { + if (e instanceof PrismaClientKnownRequestError) { + if (e.code === "P2025") { + return res.status(404).json({ + type: "error", + payload: { + message: `The organiation with the ID '${pid}' could not be found!`, + }, + }); + } + } + } }; From 8aa4e5ef1609a346f4e671bf71c746661e3ffb2f Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:42:01 +0200 Subject: [PATCH 34/42] Improve error handling and simplify code --- src/Controllers/common.ts | 16 +++++++ src/Controllers/organisation.controller.ts | 53 +++++++++++++++++++--- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/Controllers/common.ts b/src/Controllers/common.ts index 2e6bb5e..994ae79 100644 --- a/src/Controllers/common.ts +++ b/src/Controllers/common.ts @@ -44,3 +44,19 @@ export const createInsufficientPermissionsError = (required: AdminLevel = "ELEVA }, ], }); + +export const generateError = (message: string) => { + return { + type: "error", + payload: { + message, + }, + }; +}; + +export const genericError = { + type: "error", + payload: { + message: "There was an error processing your request, please try again later", + }, +}; diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index cab0c0d..d18cf56 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -1,7 +1,14 @@ import { PrismaClientUnknownRequestError } from "@prisma/client/runtime"; import { Request, Response } from "express"; import prisma from "../lib/prisma"; -import { AUTH_ERROR, createInsufficientPermissionsError, DataType, generateInvalidBodyError } from "./common"; +import { + AUTH_ERROR, + createInsufficientPermissionsError, + DataType, + generateError, + generateInvalidBodyError, + genericError, +} from "./common"; import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; import { Prisma } from "@prisma/client"; @@ -230,13 +237,45 @@ export const updateOrganisation = async ( } catch (e) { if (e instanceof PrismaClientKnownRequestError) { if (e.code === "P2025") { - return res.status(404).json({ - type: "error", - payload: { - message: `The organiation with the ID '${pid}' could not be found!`, - }, - }); + return res.status(404).json(generateError(`The organisation with the ID ${pid} could not be found`)); } + } else if (e instanceof PrismaClientUnknownRequestError) { + return res.status(400).send(generateError("Unkonwn error occured. This could be due to malformed IDs")); } } + + return res.status(500).json(genericError); +}; + +interface DeleteOrganisationQueryParams { + pid: string; +} + +// requires: auth(ELEVATED) +export const deleteOrganisation = async (req: Request, res: Response) => { + if (!req.auth?.isAuthenticated) { + return res.status(500).json(AUTH_ERROR); + } + + if (req.auth.permission_level !== "ELEVATED") { + return res.status(403).json(createInsufficientPermissionsError()); + } + + const { pid } = req.params; + + try { + prisma.organisation.delete({ where: { pid } }); + + res.status(204).end(); + } catch (e) { + if (e instanceof PrismaClientKnownRequestError) { + if ((e.code = "P2025")) { + return res.status(404).json(generateError(`The organisation with the ID ${pid} could not be found`)); + } + } else if (e instanceof PrismaClientUnknownRequestError) { + return res.status(400).send(generateError("Unkonwn error occured. This could be due to malformed IDs")); + } + } + + return res.status(500).json(genericError); }; From 0c65aec96cea81e19a800650655da4af46e9d19c Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:28:47 +0200 Subject: [PATCH 35/42] Add controller and routes for groups --- src/Controllers/group.controllers.ts | 92 ++++++++++++++++++++++++++++ src/Routes/group.routes.ts | 12 ++++ src/app.ts | 3 + 3 files changed, 107 insertions(+) create mode 100644 src/Controllers/group.controllers.ts create mode 100644 src/Routes/group.routes.ts diff --git a/src/Controllers/group.controllers.ts b/src/Controllers/group.controllers.ts new file mode 100644 index 0000000..b9ba189 --- /dev/null +++ b/src/Controllers/group.controllers.ts @@ -0,0 +1,92 @@ +import { PrismaClientUnknownRequestError } from "@prisma/client/runtime"; +import { Request, Response } from "express"; +import prisma from "../lib/prisma"; +import { generateError, genericError } from "./common"; + +const basicGroup = { + pid: true, + name: true, + oragnisation: { select: { pid: true, name: true } }, +} as const; + +export const _getAllGroups = async (res: Response, organisationId: string | undefined) => { + const groups = await prisma.group.findMany({ + where: { oragnisation: { pid: organisationId } }, + select: basicGroup, + }); + + return res.status(200).json({ + type: "success", + payload: { + groups, + }, + }); +}; + +interface GetAllGroupsSearchParams { + organisationPid?: string; +} + +export const getAllGroups = async (req: Request<{}, {}, {}, GetAllGroupsSearchParams>, res: Response) => { + return _getAllGroups(res, req.query.organisationPid); +}; + +interface getAllGroupsWithParamQueryParams { + organisationPid: string; +} + +export const getAllGroupsWithParam = async (req: Request, res: Response) => { + return _getAllGroups(res, req.params.organisationPid); +}; + +interface GetGroupQueryParams { + pid: string; +} + +export const getGroup = async (req: Request, res: Response) => { + const { pid } = req.params; + + try { + const group = await prisma.group.findUnique({ + where: { pid }, + select: { + pid: true, + name: true, + oragnisation: { select: { pid: true, name: true } }, + admins: { select: { pid: true, name: true } }, + participants: { select: { pid: true } }, + }, + }); + + if (!group) { + return res.status(404).json(generateError(`The group with ID '${pid}' could not be found`)); + } + + return res.status(200).json({ + type: "success", + payload: { + group: { + ...group, + organisation: { + ...group.oragnisation, + _links: [{ rel: "self", type: "GET", href: `/api/organisation/${group.oragnisation.pid}` }], + }, + admins: group.admins.map((admin) => ({ + ...admin, + _links: [{ rel: "self", type: "GET", href: `/api/admins/${admin.pid}` }], + })), + participants: group.participants.map((participant) => ({ + ...participant, + _links: [{ rel: "self", type: "GET", href: `/api/participant/${participant.pid}` }], + })), + }, + }, + }); + } catch (e) { + if (e instanceof PrismaClientUnknownRequestError) { + return res.status(400).json(generateError("Unknown error occured. This could be due to malformed IDs")); + } + } + + return res.status(500).json(genericError); +}; diff --git a/src/Routes/group.routes.ts b/src/Routes/group.routes.ts new file mode 100644 index 0000000..54e43a0 --- /dev/null +++ b/src/Routes/group.routes.ts @@ -0,0 +1,12 @@ +import express from "express"; +import { getAllGroups, getAllGroupsWithParam, getGroup } from "../Controllers/group.controllers"; +import organisationRouter from "./organisation.routes"; + +const router = express.Router(); + +router.get("/", getAllGroups); +router.get("/:pid", getGroup); + +organisationRouter.get("/:organisationPid/groups", getAllGroupsWithParam); + +export default router; diff --git a/src/app.ts b/src/app.ts index 0c5c408..bb3b56b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,6 +5,7 @@ import adminAuthRouter from "./Routes/admin_auth.routes"; import argon2 from "argon2"; import adminRouter from "./Routes/admin.routes"; import organisationRouter from "./Routes/organisation.routes"; +import groupRouter from "./Routes/group.routes"; require("dotenv").config(); // Load dotenv config @@ -49,6 +50,8 @@ async function main() { app.use("/api/organisations", organisationRouter); + app.use("/api/groups", groupRouter); + app.listen(process.env.PORT, () => { console.log(`Listening on Port: ${process.env.PORT}`); }); From fe6879ea56671129fd6dd7ae948a3cb2a765f79f Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:50:52 +0200 Subject: [PATCH 36/42] Only show details when authenticated --- src/Controllers/group.controllers.ts | 45 ++++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/Controllers/group.controllers.ts b/src/Controllers/group.controllers.ts index b9ba189..ec95ada 100644 --- a/src/Controllers/group.controllers.ts +++ b/src/Controllers/group.controllers.ts @@ -1,3 +1,4 @@ +import { Admin } from "@prisma/client"; import { PrismaClientUnknownRequestError } from "@prisma/client/runtime"; import { Request, Response } from "express"; import prisma from "../lib/prisma"; @@ -47,15 +48,23 @@ export const getGroup = async (req: Request, res: Response) const { pid } = req.params; try { - const group = await prisma.group.findUnique({ + const group: { + pid: string; + name: string; + oragnisation: { pid: string; name: string }; + admins?: { pid: string; name: string }[]; + participants?: { pid: string }[]; + } | null = await prisma.group.findUnique({ where: { pid }, - select: { - pid: true, - name: true, - oragnisation: { select: { pid: true, name: true } }, - admins: { select: { pid: true, name: true } }, - participants: { select: { pid: true } }, - }, + select: req.auth?.isAuthenticated + ? { + pid: true, + name: true, + oragnisation: { select: { pid: true, name: true } }, + admins: { select: { pid: true, name: true } }, + participants: { select: { pid: true } }, + } + : basicGroup, }); if (!group) { @@ -71,14 +80,18 @@ export const getGroup = async (req: Request, res: Response) ...group.oragnisation, _links: [{ rel: "self", type: "GET", href: `/api/organisation/${group.oragnisation.pid}` }], }, - admins: group.admins.map((admin) => ({ - ...admin, - _links: [{ rel: "self", type: "GET", href: `/api/admins/${admin.pid}` }], - })), - participants: group.participants.map((participant) => ({ - ...participant, - _links: [{ rel: "self", type: "GET", href: `/api/participant/${participant.pid}` }], - })), + ...(req.auth?.isAuthenticated + ? { + admins: group.admins?.map((admin) => ({ + ...admin, + _links: [{ rel: "self", type: "GET", href: `/api/admins/${admin.pid}` }], + })), + participants: group.participants?.map((participant) => ({ + ...participant, + _links: [{ rel: "self", type: "GET", href: `/api/participant/${participant.pid}` }], + })), + } + : {}), }, }, }); From bff9dcc5f890c5bd070b088a9c13704b70418acf Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Tue, 26 Apr 2022 14:46:23 +0200 Subject: [PATCH 37/42] Extract function to create an object by name + Add route to create groups --- src/Controllers/common.ts | 90 +++++++++++++++++++++- src/Controllers/group.controllers.ts | 13 +++- src/Controllers/organisation.controller.ts | 62 ++------------- src/Routes/group.routes.ts | 4 +- 4 files changed, 111 insertions(+), 58 deletions(-) diff --git a/src/Controllers/common.ts b/src/Controllers/common.ts index 994ae79..1658ef5 100644 --- a/src/Controllers/common.ts +++ b/src/Controllers/common.ts @@ -1,4 +1,7 @@ -import { AdminLevel } from "@prisma/client"; +import { AdminLevel, Prisma } from "@prisma/client"; +import { PrismaClientKnownRequestError, PrismaClientUnknownRequestError } from "@prisma/client/runtime"; +import { Request, Response } from "express"; +import prisma from "../lib/prisma"; export enum DataType { STRING = "string", @@ -60,3 +63,88 @@ export const genericError = { message: "There was an error processing your request, please try again later", }, }; + +export function validateName(name: string) { + return name.length > 0; +} + +type Organisation = Partial; +type Group = Partial; + +export async function handleCreateByName( + create: { type: "oragnisation"; data: Organisation }, + link: { type: "event"; id: string }, + req: Request, + res: Response +): Promise; +export async function handleCreateByName( + create: { type: "group"; data: Group }, + link: { type: "oragnisation"; id: string }, + req: Request, + res: Response +): Promise; +export async function handleCreateByName( + create: { type: "oragnisation" | "group"; data: Organisation | Group }, + link: { type: "event" | "oragnisation"; id: string }, + req: Request, + res: Response +) { + if (!req.auth?.isAuthenticated) { + return res.status(500).json(AUTH_ERROR); + } + + if (req.auth.permission_level !== "ELEVATED") { + return res.status(403).json(createInsufficientPermissionsError()); + } + + const { name } = create.data; + + if (typeof name !== "string") { + return res + .status(400) + .json(generateInvalidBodyError({ name: DataType.STRING, [link.type + "Pid"]: DataType.STRING })); + } + + if (!validateName(name)) { + return res.status(400).json({ + type: "error", + payload: { + message: "The name has to be at least 1 character long", + }, + }); + } + + // Check if link object exsits + + try { + // @ts-ignore + const linked = await prisma[link.type].findUnique({ where: { pid: link.id }, select: { id: true } }); + + if (!linked) { + return res.status(404).json({ + type: "error", + payload: { + message: `Could not link to ${link.type} with ID '${link.id}'`, + }, + }); + } + } catch (e) { + // REVIEW: Check for valid UUID + if (e instanceof PrismaClientUnknownRequestError) { + return res.status(400).json({ + type: "error", + payload: { + message: "Unknown error occured. This could be due to malformed IDs", + }, + }); + } + } + + // @ts-ignore + const object = await prisma[create.type].create({ + data: { ...create.data, [link.type]: { connect: { pid: link.id } } }, + select: { pid: true, name: true }, + }); + + res.status(201).json({ type: "success", payload: { [create.type]: object } }); +} diff --git a/src/Controllers/group.controllers.ts b/src/Controllers/group.controllers.ts index ec95ada..54ab975 100644 --- a/src/Controllers/group.controllers.ts +++ b/src/Controllers/group.controllers.ts @@ -2,7 +2,7 @@ import { Admin } from "@prisma/client"; import { PrismaClientUnknownRequestError } from "@prisma/client/runtime"; import { Request, Response } from "express"; import prisma from "../lib/prisma"; -import { generateError, genericError } from "./common"; +import { generateError, genericError, handleCreateByName } from "./common"; const basicGroup = { pid: true, @@ -103,3 +103,14 @@ export const getGroup = async (req: Request, res: Response) return res.status(500).json(genericError); }; + +// at: POST /api/organisations/:eventPid/groups +// requires: auth(ELEVATED) +export const createGroup = async (req: Request<{ organisationPid: string }, {}, { name?: string }>, res: Response) => { + return handleCreateByName( + { type: "group", data: { name: req.body.name, level: 1 } }, + { type: "oragnisation", id: req.params.organisationPid }, + req, + res + ); +}; diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index d18cf56..8a22d64 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -8,6 +8,7 @@ import { generateError, generateInvalidBodyError, genericError, + handleCreateByName, } from "./common"; import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; import { Prisma } from "@prisma/client"; @@ -123,61 +124,12 @@ export const createOrganisation = async ( req: Request, res: Response ) => { - if (!req.auth?.isAuthenticated) { - return res.status(500).json(AUTH_ERROR); - } - - if (req.auth.permission_level !== "ELEVATED") { - return res.status(403).json(createInsufficientPermissionsError()); - } - - const { name } = req.body || {}; - const { eventPid } = req.params; - - if (typeof name !== "string") { - return res.status(400).json(generateInvalidBodyError({ name: DataType.STRING, eventId: DataType.UUID })); - } - - if (!validateOranisationName(name)) { - return res.status(400).json({ - type: "error", - payload: { - message: "The name has to be at least 1 character long", - }, - }); - } - - // Check if event exists - - try { - const event = await prisma.event.findUnique({ where: { pid: eventPid }, select: { id: true } }); - - if (!event) { - return res.status(404).json({ - type: "error", - payload: { - message: `The event with the ID ${eventPid} could not be found`, - }, - }); - } - } catch (e) { - // REVIEW: Check for valid UUID - if (e instanceof PrismaClientUnknownRequestError) { - return res.status(400).send({ - type: "error", - payload: { - message: "Unknown error occured. This could be to malformed IDs", - }, - }); - } - } - - const organisation = await prisma.organisation.create({ - data: { name, event: { connect: { pid: eventPid } } }, - select: detailedOrganisation, - }); - - res.status(201).json({ type: "success", payload: { organisation } }); + return handleCreateByName( + { type: "oragnisation", data: { name: req.body.name } }, + { type: "event", id: req.params.eventPid }, + req, + res + ); }; interface UpdateOrganisationQueryParams { diff --git a/src/Routes/group.routes.ts b/src/Routes/group.routes.ts index 54e43a0..12ae59d 100644 --- a/src/Routes/group.routes.ts +++ b/src/Routes/group.routes.ts @@ -1,5 +1,6 @@ import express from "express"; -import { getAllGroups, getAllGroupsWithParam, getGroup } from "../Controllers/group.controllers"; +import { createGroup, getAllGroups, getAllGroupsWithParam, getGroup } from "../Controllers/group.controllers"; +import { requireAuthentication } from "../Middleware/auth/auth"; import organisationRouter from "./organisation.routes"; const router = express.Router(); @@ -8,5 +9,6 @@ router.get("/", getAllGroups); router.get("/:pid", getGroup); organisationRouter.get("/:organisationPid/groups", getAllGroupsWithParam); +organisationRouter.post("/:organisationPid/groups", requireAuthentication, createGroup); export default router; From 01077dab22b5e82639bcd44df89e222ffee3f299 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Wed, 27 Apr 2022 08:24:34 +0200 Subject: [PATCH 38/42] Change name from oragnisation to organisation --- src/Controllers/common.ts | 8 ++++---- src/Controllers/group.controllers.ts | 14 +++++++------- src/Controllers/organisation.controller.ts | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Controllers/common.ts b/src/Controllers/common.ts index 1658ef5..a9a0caf 100644 --- a/src/Controllers/common.ts +++ b/src/Controllers/common.ts @@ -72,20 +72,20 @@ type Organisation = Partial; type Group = Partial; export async function handleCreateByName( - create: { type: "oragnisation"; data: Organisation }, + create: { type: "organisation"; data: Organisation }, link: { type: "event"; id: string }, req: Request, res: Response ): Promise; export async function handleCreateByName( create: { type: "group"; data: Group }, - link: { type: "oragnisation"; id: string }, + link: { type: "organisation"; id: string }, req: Request, res: Response ): Promise; export async function handleCreateByName( - create: { type: "oragnisation" | "group"; data: Organisation | Group }, - link: { type: "event" | "oragnisation"; id: string }, + create: { type: "organisation" | "group"; data: Organisation | Group }, + link: { type: "event" | "organisation"; id: string }, req: Request, res: Response ) { diff --git a/src/Controllers/group.controllers.ts b/src/Controllers/group.controllers.ts index 54ab975..10f42c7 100644 --- a/src/Controllers/group.controllers.ts +++ b/src/Controllers/group.controllers.ts @@ -7,12 +7,12 @@ import { generateError, genericError, handleCreateByName } from "./common"; const basicGroup = { pid: true, name: true, - oragnisation: { select: { pid: true, name: true } }, + organisation: { select: { pid: true, name: true } }, } as const; export const _getAllGroups = async (res: Response, organisationId: string | undefined) => { const groups = await prisma.group.findMany({ - where: { oragnisation: { pid: organisationId } }, + where: { organisation: { pid: organisationId } }, select: basicGroup, }); @@ -51,7 +51,7 @@ export const getGroup = async (req: Request, res: Response) const group: { pid: string; name: string; - oragnisation: { pid: string; name: string }; + organisation: { pid: string; name: string }; admins?: { pid: string; name: string }[]; participants?: { pid: string }[]; } | null = await prisma.group.findUnique({ @@ -60,7 +60,7 @@ export const getGroup = async (req: Request, res: Response) ? { pid: true, name: true, - oragnisation: { select: { pid: true, name: true } }, + organisation: { select: { pid: true, name: true } }, admins: { select: { pid: true, name: true } }, participants: { select: { pid: true } }, } @@ -77,8 +77,8 @@ export const getGroup = async (req: Request, res: Response) group: { ...group, organisation: { - ...group.oragnisation, - _links: [{ rel: "self", type: "GET", href: `/api/organisation/${group.oragnisation.pid}` }], + ...group.organisation, + _links: [{ rel: "self", type: "GET", href: `/api/organisation/${group.organisation.pid}` }], }, ...(req.auth?.isAuthenticated ? { @@ -109,7 +109,7 @@ export const getGroup = async (req: Request, res: Response) export const createGroup = async (req: Request<{ organisationPid: string }, {}, { name?: string }>, res: Response) => { return handleCreateByName( { type: "group", data: { name: req.body.name, level: 1 } }, - { type: "oragnisation", id: req.params.organisationPid }, + { type: "organisation", id: req.params.organisationPid }, req, res ); diff --git a/src/Controllers/organisation.controller.ts b/src/Controllers/organisation.controller.ts index 8a22d64..146594e 100644 --- a/src/Controllers/organisation.controller.ts +++ b/src/Controllers/organisation.controller.ts @@ -125,7 +125,7 @@ export const createOrganisation = async ( res: Response ) => { return handleCreateByName( - { type: "oragnisation", data: { name: req.body.name } }, + { type: "organisation", data: { name: req.body.name } }, { type: "event", id: req.params.eventPid }, req, res From 9965acee40814cbffdc3f534b9483ced5fa4778d Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Wed, 27 Apr 2022 08:26:51 +0200 Subject: [PATCH 39/42] Update name to organisation --- prisma/schema.prisma | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8025cd4..c316eca 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -135,8 +135,8 @@ model Group { user_limit Int @default(40) level Int - oragnisation Organisation @relation(fields: [oragnisationId], references: [id], onDelete: Cascade) - oragnisationId Int + organisation Organisation @relation(fields: [organisationId], references: [id], onDelete: Cascade) + organisationId Int participants Participant[] link Link? admins Admin[] From 2936aa77f19cd387eb75451ea38f3e4326edd90b Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Thu, 28 Apr 2022 12:36:02 +0200 Subject: [PATCH 40/42] FIX: Event endpoints are now using the correct format --- src/Controllers/event.controller.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index 465b8bf..db5efcf 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -13,8 +13,13 @@ export const getAllEvents = async (req: Request, res: Response) => { id: false, }, }); - if (events.length > 0) res.status(200).json(events); - else res.status(200).json([]); + if (events.length > 0) + res.status(200).json({ + type: "success", + payload: { + events, + }, + }); }; export const getEvent = async (req: Request, res: Response) => { @@ -42,7 +47,12 @@ export const getEvent = async (req: Request, res: Response) => { }, }); - res.status(200).json(event); + res.status(200).json({ + type: "success", + payload: { + event, + }, + }); } catch (e) { if (e instanceof Prisma.PrismaClientKnownRequestError) { res.status(500).json({ @@ -102,7 +112,7 @@ export const addEvent = async (req: Request, res: Response) => { }); res.status(201).json({ - type: "succes", + type: "success", payload: { event, }, From 6d471eced2d8f546f15c684ed61983fafec2bfb0 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Thu, 28 Apr 2022 12:42:33 +0200 Subject: [PATCH 41/42] Add function for deleting events --- src/Controllers/event.controller.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index db5efcf..31a799f 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -1,7 +1,8 @@ import { Prisma } from "@prisma/client"; +import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; import { Request, Response } from "express"; import prisma from "../lib/prisma"; -import { DataType, generateInvalidBodyError } from "./common"; +import { createInsufficientPermissionsError, DataType, generateError, generateInvalidBodyError } from "./common"; export const getAllEvents = async (req: Request, res: Response) => { const events = await prisma.event.findMany({ @@ -118,3 +119,28 @@ export const addEvent = async (req: Request, res: Response) => { }, }); }; + +interface DeleteEventQueryParams { + pid: string; +} + +// requires: auth(ELEVATED) +export const deleteEvent = (req: Request, res: Response) => { + if (req.auth?.permission_level !== "ELEVATED") { + res.status(403).json(createInsufficientPermissionsError()); + } + + const { pid } = req.params; + + try { + prisma.event.delete({ where: { pid } }); + + return res.status(204).end(); + } catch (e) { + if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") { + return res.status(404).json(generateError(`The organisation with the ID ${pid} could not be found`)); + } + + throw e; + } +}; From 4a65dd4665db23ab151cd423388c6800cfb6b241 Mon Sep 17 00:00:00 2001 From: Stephan <57194608+stephan418@users.noreply.github.com> Date: Thu, 28 Apr 2022 12:46:26 +0200 Subject: [PATCH 42/42] Add authorization --- src/Controllers/event.controller.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index 31a799f..4789a1f 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -79,20 +79,24 @@ export const getEvent = async (req: Request, res: Response) => { } }; +// requires: auth(ELEVATED) export const addEvent = async (req: Request, res: Response) => { + if (req.auth?.permission_level !== "ELEVATED") { + res.status(403).json(createInsufficientPermissionsError()); + } + if ( typeof req.body.name !== "string" || typeof req.body.date !== "string" || typeof req.body.description !== "string" ) { - res.status(400).json( + return res.status(400).json( generateInvalidBodyError({ name: DataType.STRING, date: DataType.DATETIME, description: DataType.STRING, }) ); - return; } //TODO: Check if date is valid