From 2f43fff46d088cae2637be4e163e5b39226efcb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez=20Rubio?= Date: Fri, 4 Oct 2024 18:10:02 +0200 Subject: [PATCH] feat: move system to modules + bump @oh/config - fix #98 (#99) --- app/server/deno.json | 3 +- app/server/deno.lock | 29 +++++++++---------- app/server/mod.ts | 2 +- app/server/src/main.ts | 1 - .../modules/api/v2/account/login.request.ts | 2 +- .../modules/api/v2/account/logout.request.ts | 2 +- .../api/v2/account/otp/delete.request.ts | 2 +- .../api/v2/account/otp/post.request.ts | 2 +- .../api/v2/account/otp/verify.request.ts | 2 +- .../modules/api/v2/account/ping.request.ts | 2 +- .../api/v2/account/refresh-session.request.ts | 2 +- .../api/v2/account/register.request.ts | 2 +- .../modules/api/v2/account/verify.request.ts | 2 +- .../src/modules/api/v2/admin/admin.request.ts | 2 +- .../modules/api/v2/admin/update.request.ts | 2 +- .../api/v2/server/claim-session.request.ts | 2 +- .../api/v2/server/create-ticket.request.ts | 2 +- .../src/modules/api/v2/version.request.ts | 2 +- app/server/src/{ => modules}/system/api.ts | 2 +- .../src/{ => modules}/system/captcha.ts | 2 +- app/server/src/{ => modules}/system/db.ts | 2 +- app/server/src/{ => modules}/system/email.ts | 0 app/server/src/{ => modules}/system/main.ts | 2 +- app/server/src/{ => modules}/system/otp.ts | 2 +- .../src/{ => modules}/system/sessions.ts | 2 +- app/server/src/{ => modules}/system/tasks.ts | 0 app/server/src/shared/utils/account.utils.ts | 2 +- 27 files changed, 37 insertions(+), 40 deletions(-) delete mode 100644 app/server/src/main.ts rename app/server/src/{ => modules}/system/api.ts (98%) rename app/server/src/{ => modules}/system/captcha.ts (93%) rename app/server/src/{ => modules}/system/db.ts (93%) rename app/server/src/{ => modules}/system/email.ts (100%) rename app/server/src/{ => modules}/system/main.ts (94%) rename app/server/src/{ => modules}/system/otp.ts (93%) rename app/server/src/{ => modules}/system/sessions.ts (98%) rename app/server/src/{ => modules}/system/tasks.ts (100%) diff --git a/app/server/deno.json b/app/server/deno.json index e7ea26c..e9d97ac 100644 --- a/app/server/deno.json +++ b/app/server/deno.json @@ -16,10 +16,9 @@ "imports": { "@oh/queue": "jsr:@oh/queue@1.1.1", "@oh/updater": "jsr:@oh/updater@1.1.1", - "@oh/config": "jsr:@oh/config@1.0.1", + "@oh/config": "jsr:@oh/config@1.1.1", "shared/": "./src/shared/", - "system/": "./src/system/", "modules/": "./src/modules/", "deno/": "https://deno.land/std@0.221.0/", diff --git a/app/server/deno.lock b/app/server/deno.lock index 3dafe64..8aa39ae 100644 --- a/app/server/deno.lock +++ b/app/server/deno.lock @@ -2,22 +2,22 @@ "version": "3", "packages": { "specifiers": { - "jsr:@oh/config@1.0.1": "jsr:@oh/config@1.0.1", + "jsr:@oh/config@1.1.1": "jsr:@oh/config@1.1.1", "jsr:@oh/queue@1.1.1": "jsr:@oh/queue@1.1.1", "jsr:@oh/updater@1.1.1": "jsr:@oh/updater@1.1.1", - "jsr:@oh/yaml@1.0.2": "jsr:@oh/yaml@1.0.2", + "jsr:@oh/yaml@1.1.0": "jsr:@oh/yaml@1.1.0", "jsr:@std/fs@1.0.4": "jsr:@std/fs@1.0.4", "jsr:@std/path@1.0.6": "jsr:@std/path@1.0.6", "jsr:@std/path@^1.0.6": "jsr:@std/path@1.0.6", + "jsr:@std/yaml@1.0.5": "jsr:@std/yaml@1.0.5", "npm:nodemailer@6.9.15": "npm:nodemailer@6.9.15", - "npm:yaml@2.4.2": "npm:yaml@2.4.2", - "npm:yaml@2.5.1": "npm:yaml@2.5.1" + "npm:yaml@2.4.2": "npm:yaml@2.4.2" }, "jsr": { - "@oh/config@1.0.1": { - "integrity": "91271bbd88999b13ffe1d161453f83cef2b37900a4b1467da7a9688d051d71fc", + "@oh/config@1.1.1": { + "integrity": "5dc84429d3e4926ce1f4d7dbe72ed13da44ce26f8fa4440a7ceef4b78dd7fed1", "dependencies": [ - "jsr:@oh/yaml@1.0.2" + "jsr:@oh/yaml@1.1.0" ] }, "@oh/queue@1.1.1": { @@ -29,12 +29,12 @@ "jsr:@std/path@1.0.6" ] }, - "@oh/yaml@1.0.2": { - "integrity": "06921094d666924dc39280961578acc197a9449199b9425647a60738140bd279", + "@oh/yaml@1.1.0": { + "integrity": "57f2f01bf259dff8896fb9d8f4f49e477e6533ccc5cbc4559ebd8410142aeff5", "dependencies": [ "jsr:@std/fs@1.0.4", "jsr:@std/path@1.0.6", - "npm:yaml@2.5.1" + "jsr:@std/yaml@1.0.5" ] }, "@std/fs@1.0.4": { @@ -45,6 +45,9 @@ }, "@std/path@1.0.6": { "integrity": "ab2c55f902b380cf28e0eec501b4906e4c1960d13f00e11cfbcd21de15f18fed" + }, + "@std/yaml@1.0.5": { + "integrity": "71ba3d334305ee2149391931508b2c293a8490f94a337eef3a09cade1a2a2742" } }, "npm": { @@ -55,10 +58,6 @@ "yaml@2.4.2": { "integrity": "sha512-B3VqDZ+JAg1nZpaEmWtTXUlBneoGx6CPM9b0TENK6aoSu5t73dItudwdgmi6tHlIZZId4dZ9skcAQ2UbcyAeVA==", "dependencies": {} - }, - "yaml@2.5.1": { - "integrity": "sha512-bLQOjaX/ADgQ20isPJRvF0iRUHIxVhYvr53Of7wGcWlO2jvtUlH5m87DsmulFVxRpNLOnI4tB6p/oh8D7kpn9Q==", - "dependencies": {} } } }, @@ -203,7 +202,7 @@ }, "workspace": { "dependencies": [ - "jsr:@oh/config@1.0.1", + "jsr:@oh/config@1.1.1", "jsr:@oh/queue@1.1.1", "jsr:@oh/updater@1.1.1", "npm:nodemailer@6.9.15", diff --git a/app/server/mod.ts b/app/server/mod.ts index fe6999f..01a29ad 100644 --- a/app/server/mod.ts +++ b/app/server/mod.ts @@ -1,4 +1,4 @@ -import { System } from "./src/main.ts"; +import { System } from "modules/system/main.ts"; import { load as loadEnv } from "loadenv"; import { getProcessedEnvs } from "shared/utils/main.ts"; diff --git a/app/server/src/main.ts b/app/server/src/main.ts deleted file mode 100644 index ec02433..0000000 --- a/app/server/src/main.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./system/main.ts"; diff --git a/app/server/src/modules/api/v2/account/login.request.ts b/app/server/src/modules/api/v2/account/login.request.ts index 823708f..4013817 100644 --- a/app/server/src/modules/api/v2/account/login.request.ts +++ b/app/server/src/modules/api/v2/account/login.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; import { getIpFromRequest, diff --git a/app/server/src/modules/api/v2/account/logout.request.ts b/app/server/src/modules/api/v2/account/logout.request.ts index 38275dc..703125b 100644 --- a/app/server/src/modules/api/v2/account/logout.request.ts +++ b/app/server/src/modules/api/v2/account/logout.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; export const logoutRequest: RequestType = { diff --git a/app/server/src/modules/api/v2/account/otp/delete.request.ts b/app/server/src/modules/api/v2/account/otp/delete.request.ts index 48d5528..443c6ff 100644 --- a/app/server/src/modules/api/v2/account/otp/delete.request.ts +++ b/app/server/src/modules/api/v2/account/otp/delete.request.ts @@ -4,7 +4,7 @@ import { getAccountFromRequest, isAccountAuthValid, } from "shared/utils/account.utils.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const deleteRequest: RequestType = { method: RequestMethod.DELETE, diff --git a/app/server/src/modules/api/v2/account/otp/post.request.ts b/app/server/src/modules/api/v2/account/otp/post.request.ts index aec5c87..3e43bdf 100644 --- a/app/server/src/modules/api/v2/account/otp/post.request.ts +++ b/app/server/src/modules/api/v2/account/otp/post.request.ts @@ -4,7 +4,7 @@ import { getAccountFromRequest, isAccountAuthValid, } from "shared/utils/account.utils.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const postRequest: RequestType = { method: RequestMethod.POST, diff --git a/app/server/src/modules/api/v2/account/otp/verify.request.ts b/app/server/src/modules/api/v2/account/otp/verify.request.ts index ce22388..f163ce2 100644 --- a/app/server/src/modules/api/v2/account/otp/verify.request.ts +++ b/app/server/src/modules/api/v2/account/otp/verify.request.ts @@ -4,7 +4,7 @@ import { getAccountFromRequest, isAccountAuthValid, } from "shared/utils/account.utils.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const verifyRequest: RequestType = { method: RequestMethod.GET, diff --git a/app/server/src/modules/api/v2/account/ping.request.ts b/app/server/src/modules/api/v2/account/ping.request.ts index 7a075b8..86cf1af 100644 --- a/app/server/src/modules/api/v2/account/ping.request.ts +++ b/app/server/src/modules/api/v2/account/ping.request.ts @@ -1,7 +1,7 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; import { getIpFromRequest } from "shared/utils/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import { SERVER_SESSION_EXPIRE_TIME } from "shared/consts/main.ts"; export const pingRequest: RequestType = { diff --git a/app/server/src/modules/api/v2/account/refresh-session.request.ts b/app/server/src/modules/api/v2/account/refresh-session.request.ts index d0a75f6..69b7a79 100644 --- a/app/server/src/modules/api/v2/account/refresh-session.request.ts +++ b/app/server/src/modules/api/v2/account/refresh-session.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; import { SESSION_EXPIRE_TIME, diff --git a/app/server/src/modules/api/v2/account/register.request.ts b/app/server/src/modules/api/v2/account/register.request.ts index b79b5a5..24acd09 100644 --- a/app/server/src/modules/api/v2/account/register.request.ts +++ b/app/server/src/modules/api/v2/account/register.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; import { PASSWORD_REGEX, diff --git a/app/server/src/modules/api/v2/account/verify.request.ts b/app/server/src/modules/api/v2/account/verify.request.ts index 02969f2..8faa965 100644 --- a/app/server/src/modules/api/v2/account/verify.request.ts +++ b/app/server/src/modules/api/v2/account/verify.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; export const verifyRequest: RequestType = { diff --git a/app/server/src/modules/api/v2/admin/admin.request.ts b/app/server/src/modules/api/v2/admin/admin.request.ts index 7c473ed..cb8e065 100644 --- a/app/server/src/modules/api/v2/admin/admin.request.ts +++ b/app/server/src/modules/api/v2/admin/admin.request.ts @@ -7,7 +7,7 @@ import { isAccountAdminValid, isAccountAuthValid, } from "shared/utils/account.utils.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const accountGetRequest: RequestType = { method: RequestMethod.GET, diff --git a/app/server/src/modules/api/v2/admin/update.request.ts b/app/server/src/modules/api/v2/admin/update.request.ts index 18d0f4e..9c2cab4 100644 --- a/app/server/src/modules/api/v2/admin/update.request.ts +++ b/app/server/src/modules/api/v2/admin/update.request.ts @@ -2,7 +2,7 @@ import { RequestType } from "shared/types/request.types.ts"; import { RequestMethod } from "shared/enums/request.enum.ts"; import { isAccountAdminValid } from "shared/utils/account.utils.ts"; import { load as loadUpdater } from "modules/updater/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const updateGetRequest: RequestType = { method: RequestMethod.GET, diff --git a/app/server/src/modules/api/v2/server/claim-session.request.ts b/app/server/src/modules/api/v2/server/claim-session.request.ts index e213f26..0b2a211 100644 --- a/app/server/src/modules/api/v2/server/claim-session.request.ts +++ b/app/server/src/modules/api/v2/server/claim-session.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; import { SERVER_SESSION_EXPIRE_TIME } from "shared/consts/session.consts.ts"; import { getIpFromRequest } from "shared/utils/ip.utils.ts"; diff --git a/app/server/src/modules/api/v2/server/create-ticket.request.ts b/app/server/src/modules/api/v2/server/create-ticket.request.ts index 0aaf8af..b8fea05 100644 --- a/app/server/src/modules/api/v2/server/create-ticket.request.ts +++ b/app/server/src/modules/api/v2/server/create-ticket.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; import { TICKET_EXPIRE_TIME } from "shared/consts/tickets.consts.ts"; diff --git a/app/server/src/modules/api/v2/version.request.ts b/app/server/src/modules/api/v2/version.request.ts index 2af2f0e..af2e2fb 100644 --- a/app/server/src/modules/api/v2/version.request.ts +++ b/app/server/src/modules/api/v2/version.request.ts @@ -1,6 +1,6 @@ import { RequestType } from "shared/types/main.ts"; import { RequestMethod } from "shared/enums/main.ts"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const versionRequest: RequestType = { method: RequestMethod.GET, diff --git a/app/server/src/system/api.ts b/app/server/src/modules/system/api.ts similarity index 98% rename from app/server/src/system/api.ts rename to app/server/src/modules/system/api.ts index 26f8ff9..2f21e22 100644 --- a/app/server/src/system/api.ts +++ b/app/server/src/modules/system/api.ts @@ -4,7 +4,7 @@ import { getContentType, getCORSHeaders, } from "shared/utils/main.ts"; -import { System } from "system/main.ts"; +import { System } from "./main.ts"; export const api = () => { const load = () => { diff --git a/app/server/src/system/captcha.ts b/app/server/src/modules/system/captcha.ts similarity index 93% rename from app/server/src/system/captcha.ts rename to app/server/src/modules/system/captcha.ts index 8879c42..09ccb3c 100644 --- a/app/server/src/system/captcha.ts +++ b/app/server/src/modules/system/captcha.ts @@ -1,4 +1,4 @@ -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const captcha = () => { const verify = async (sessionId: string): Promise => { diff --git a/app/server/src/system/db.ts b/app/server/src/modules/system/db.ts similarity index 93% rename from app/server/src/system/db.ts rename to app/server/src/modules/system/db.ts index e2f775c..bdaf438 100644 --- a/app/server/src/system/db.ts +++ b/app/server/src/modules/system/db.ts @@ -1,4 +1,4 @@ -import { System } from "system/main.ts"; +import { System } from "./main.ts"; export const db = () => { let kv; diff --git a/app/server/src/system/email.ts b/app/server/src/modules/system/email.ts similarity index 100% rename from app/server/src/system/email.ts rename to app/server/src/modules/system/email.ts diff --git a/app/server/src/system/main.ts b/app/server/src/modules/system/main.ts similarity index 94% rename from app/server/src/system/main.ts rename to app/server/src/modules/system/main.ts index 1640be7..cf51041 100644 --- a/app/server/src/system/main.ts +++ b/app/server/src/modules/system/main.ts @@ -25,7 +25,7 @@ export const System = (() => { const load = async (envs: Envs) => { if (await loadUpdater(envs)) return; - $config = await $getConfig(CONFIG_DEFAULT); + $config = await $getConfig({ defaults: CONFIG_DEFAULT }); $envs = envs; $tasks.load(); diff --git a/app/server/src/system/otp.ts b/app/server/src/modules/system/otp.ts similarity index 93% rename from app/server/src/system/otp.ts rename to app/server/src/modules/system/otp.ts index d96b450..ba87d4f 100644 --- a/app/server/src/system/otp.ts +++ b/app/server/src/modules/system/otp.ts @@ -1,5 +1,5 @@ import * as OTPAuth from "otp"; -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; export const otp = () => { const $getTOTP = (email: string, otpSecret: string): OTPAuth.TOTP => diff --git a/app/server/src/system/sessions.ts b/app/server/src/modules/system/sessions.ts similarity index 98% rename from app/server/src/system/sessions.ts rename to app/server/src/modules/system/sessions.ts index 9ae5ff3..d9342df 100644 --- a/app/server/src/system/sessions.ts +++ b/app/server/src/modules/system/sessions.ts @@ -1,4 +1,4 @@ -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import { TickerQueue } from "@oh/queue"; import { getServerSessionList } from "shared/utils/main.ts"; diff --git a/app/server/src/system/tasks.ts b/app/server/src/modules/system/tasks.ts similarity index 100% rename from app/server/src/system/tasks.ts rename to app/server/src/modules/system/tasks.ts diff --git a/app/server/src/shared/utils/account.utils.ts b/app/server/src/shared/utils/account.utils.ts index 1b0d2b9..7f44285 100644 --- a/app/server/src/shared/utils/account.utils.ts +++ b/app/server/src/shared/utils/account.utils.ts @@ -1,4 +1,4 @@ -import { System } from "system/main.ts"; +import { System } from "modules/system/main.ts"; import * as bcrypt from "bcrypt"; export const getAccountFromRequest = async ({ headers }: Request) => {