startx 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +0 -13
- package/.prettierrc.js +52 -52
- package/.vscode/launch.json +32 -0
- package/.vscode/settings.json +9 -3
- package/apps/core-server/.env.example +18 -24
- package/apps/core-server/Dockerfile +35 -61
- package/apps/core-server/eslint.config.ts +7 -0
- package/apps/core-server/package.json +41 -52
- package/apps/core-server/src/config/custom-type.ts +2 -40
- package/apps/core-server/src/events/index.ts +37 -37
- package/apps/core-server/src/index.ts +4 -13
- package/apps/core-server/src/middlewares/auth-middleware.ts +24 -7
- package/apps/core-server/src/middlewares/cors-middleware.ts +7 -6
- package/apps/core-server/src/middlewares/error-middleware.ts +7 -4
- package/apps/core-server/src/middlewares/logger-middleware.ts +81 -21
- package/apps/core-server/src/middlewares/notfound-middleware.ts +6 -14
- package/apps/core-server/src/middlewares/serve-static.ts +30 -24
- package/apps/core-server/src/routes/files/router.ts +9 -7
- package/apps/core-server/src/routes/server.ts +30 -36
- package/apps/core-server/tsdown.config.ts +4 -3
- package/biome.json +58 -60
- package/configs/eslint-config/package.json +16 -19
- package/configs/eslint-config/src/configs/base.ts +185 -225
- package/configs/eslint-config/src/configs/extend.ts +3 -0
- package/configs/eslint-config/src/configs/frontend.ts +81 -56
- package/configs/eslint-config/src/configs/node.ts +6 -6
- package/configs/eslint-config/src/plugin.ts +1 -0
- package/configs/eslint-config/src/rules/index.ts +8 -12
- package/configs/eslint-config/src/rules/no-json-parse-json-stringify.test.ts +30 -17
- package/configs/eslint-config/src/rules/no-json-parse-json-stringify.ts +52 -49
- package/configs/eslint-config/src/rules/no-uncaught-json-parse.ts +43 -45
- package/configs/tsdown-config/package.json +10 -3
- package/configs/typescript-config/package.json +10 -1
- package/configs/typescript-config/tsconfig.common.json +3 -3
- package/configs/vitest-config/dist/base.mjs +1 -0
- package/configs/vitest-config/dist/frontend.mjs +1 -0
- package/configs/vitest-config/dist/node.mjs +1 -0
- package/configs/vitest-config/package.json +12 -0
- package/configs/vitest-config/src/base.ts +17 -29
- package/configs/vitest-config/src/index.ts +1 -0
- package/package.json +15 -26
- package/packages/@repo/constants/eslint.config.ts +4 -0
- package/packages/@repo/constants/package.json +16 -0
- package/packages/@repo/constants/src/index.ts +8 -8
- package/packages/@repo/db/eslint.config.ts +4 -0
- package/packages/@repo/db/package.json +16 -8
- package/packages/@repo/db/src/index.ts +26 -20
- package/packages/@repo/db/src/schema/common.ts +45 -49
- package/packages/@repo/env/eslint.config.ts +4 -0
- package/packages/@repo/env/package.json +39 -0
- package/packages/@repo/env/src/default-env.ts +12 -0
- package/packages/@repo/env/src/define-env.ts +70 -0
- package/packages/@repo/env/src/index.ts +2 -0
- package/packages/@repo/env/src/utils.ts +52 -0
- package/packages/@repo/env/tsconfig.json +7 -0
- package/packages/@repo/lib/eslint.config.ts +4 -0
- package/packages/@repo/lib/package.json +34 -34
- package/packages/@repo/lib/src/bucket-module/file-storage.ts +50 -49
- package/packages/@repo/lib/src/bucket-module/index.ts +3 -0
- package/packages/@repo/lib/src/bucket-module/s3-storage.ts +120 -114
- package/packages/@repo/lib/src/bucket-module/utils.ts +10 -11
- package/packages/@repo/lib/src/{cookie-module.ts → cookie-module/cookie-module.ts} +48 -42
- package/packages/@repo/lib/src/cookie-module/index.ts +1 -0
- package/packages/@repo/lib/src/extra/index.ts +1 -0
- package/packages/@repo/lib/src/extra/pagination-module.ts +35 -0
- package/packages/@repo/lib/src/{token-module.ts → extra/token-module.ts} +12 -5
- package/packages/@repo/lib/src/file-system-module/index.ts +170 -0
- package/packages/@repo/lib/src/{hashing-module.ts → hashing-module/index.ts} +9 -9
- package/packages/@repo/lib/src/index.ts +0 -26
- package/packages/@repo/lib/src/mail-module/index.ts +2 -0
- package/packages/@repo/lib/src/mail-module/mock.ts +8 -8
- package/packages/@repo/lib/src/mail-module/nodemailer.ts +17 -7
- package/packages/@repo/lib/src/notification-module/index.ts +1 -172
- package/packages/@repo/lib/src/notification-module/push-notification.ts +97 -90
- package/packages/@repo/lib/src/{oauth2-client.ts → oauth2-module/index.ts} +107 -109
- package/packages/@repo/lib/src/otp-module/index.ts +91 -0
- package/packages/@repo/lib/src/session-module/index.ts +113 -0
- package/packages/@repo/lib/src/utils.ts +43 -42
- package/packages/@repo/lib/src/validation-module/index.ts +242 -0
- package/packages/@repo/logger/eslint.config.ts +4 -0
- package/packages/@repo/logger/package.json +40 -0
- package/packages/@repo/logger/src/index.ts +2 -0
- package/packages/@repo/logger/src/logger.ts +72 -0
- package/packages/@repo/{lib/src/logger-module → logger/src}/memory-profiler.ts +64 -65
- package/packages/@repo/logger/tsconfig.json +7 -0
- package/packages/@repo/mail/eslint.config.ts +4 -0
- package/packages/@repo/mail/package.json +10 -3
- package/packages/@repo/mail/src/emails/admin/OtpEmail.tsx +169 -168
- package/packages/@repo/mail/src/index.ts +1 -2
- package/packages/@repo/mail/tsconfig.json +3 -3
- package/packages/@repo/redis/dist/index.d.mts +3 -0
- package/packages/@repo/redis/dist/index.mjs +5 -0
- package/packages/@repo/redis/dist/lib/redis-client.d.mts +7 -0
- package/packages/@repo/redis/dist/lib/redis-client.mjs +25 -0
- package/packages/@repo/redis/dist/lib/redis-client.mjs.map +1 -0
- package/packages/@repo/redis/dist/lib/redis-module.d.mts +5 -0
- package/packages/@repo/redis/dist/lib/redis-module.mjs +6 -0
- package/packages/@repo/redis/dist/lib/redis-module.mjs.map +1 -0
- package/packages/@repo/redis/eslint.config.ts +4 -0
- package/packages/@repo/redis/package.json +13 -10
- package/packages/@repo/redis/src/index.ts +2 -2
- package/packages/@repo/redis/src/lib/redis-client.ts +36 -23
- package/packages/@repo/redis/src/lib/redis-module.ts +69 -3
- package/packages/cli/dist/index.mjs +203 -0
- package/packages/cli/eslint.config.ts +4 -0
- package/packages/cli/package.json +44 -0
- package/packages/cli/tsconfig.json +12 -0
- package/packages/cli/tsdown.config.ts +17 -0
- package/packages/ui/components.json +0 -1
- package/packages/ui/eslint.config.ts +4 -0
- package/packages/ui/package.json +16 -3
- package/packages/ui/postcss.config.mjs +9 -9
- package/packages/ui/src/components/lib/utils.ts +53 -53
- package/packages/ui/src/components/ui/alert-dialog.tsx +118 -116
- package/packages/ui/src/components/ui/avatar.tsx +52 -53
- package/packages/ui/src/components/ui/badge.tsx +45 -46
- package/packages/ui/src/components/ui/breadcrumb.tsx +108 -109
- package/packages/ui/src/components/ui/card.tsx +91 -92
- package/packages/ui/src/components/ui/carousel.tsx +243 -243
- package/packages/ui/src/components/ui/checkbox.tsx +32 -32
- package/packages/ui/src/components/ui/command.tsx +144 -155
- package/packages/ui/src/components/ui/dialog.tsx +124 -127
- package/packages/ui/src/components/ui/form.tsx +166 -165
- package/packages/ui/src/components/ui/input-otp.tsx +74 -76
- package/packages/ui/src/components/ui/input.tsx +19 -21
- package/packages/ui/src/components/ui/multiple-select.tsx +4 -4
- package/packages/ui/src/{components/lucide.tsx → lucide.ts} +3 -3
- package/packages/ui/tailwind.config.ts +94 -94
- package/packages/ui/tsconfig.json +7 -1
- package/pnpm-workspace.yaml +41 -1
- package/startx.json +22 -0
- package/turbo.json +20 -27
- package/apps/core-server/eslint.config.mjs +0 -47
- package/configs/eslint-config/src/rules/no-dynamic-import-template.ts +0 -32
- package/configs/eslint-config/src/rules/no-plain-errors.ts +0 -50
- package/configs/eslint-config/tsdown.config.ts +0 -11
- package/packages/@repo/constants/eslint.config.mjs +0 -21
- package/packages/@repo/db/eslint.config.mjs +0 -21
- package/packages/@repo/lib/eslint.config.mjs +0 -49
- package/packages/@repo/lib/src/command-module.ts +0 -77
- package/packages/@repo/lib/src/constants.ts +0 -3
- package/packages/@repo/lib/src/custom-type.ts +0 -54
- package/packages/@repo/lib/src/env.ts +0 -13
- package/packages/@repo/lib/src/file-system/index.ts +0 -90
- package/packages/@repo/lib/src/logger-module/log-config.ts +0 -16
- package/packages/@repo/lib/src/logger-module/logger.ts +0 -78
- package/packages/@repo/lib/src/mail-module/api.ts +0 -0
- package/packages/@repo/lib/src/otp-module.ts +0 -98
- package/packages/@repo/lib/src/pagination-module.ts +0 -49
- package/packages/@repo/lib/src/user-session.ts +0 -117
- package/packages/@repo/lib/src/validation-module.ts +0 -187
- package/packages/@repo/mail/tsconfig.build.json +0 -14
- package/packages/@repo/mail/tsdown.config.ts +0 -9
- package/packages/@repo/redis/eslint.config.mjs +0 -8
- package/packages/ui/eslint.config.mjs +0 -18
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.$onUpdate(() => new Date()),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// ----------------------------------------------------------------------------
|
|
1
|
+
import { pgEnum, pgTable, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
|
2
|
+
|
|
3
|
+
export const userRoleEnum = pgEnum("user_role", ["user", "admin", "superuser"]);
|
|
4
|
+
|
|
5
|
+
export const usersTable = pgTable("users", {
|
|
6
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
7
|
+
email: varchar("email", { length: 255 }).notNull().unique(),
|
|
8
|
+
fullName: varchar("full_name", { length: 255 }).default("Guest").notNull(),
|
|
9
|
+
password: varchar("password", { length: 255 }).default("foresight").notNull(),
|
|
10
|
+
countries: varchar("countries", { length: 255 }).array().notNull().default([]),
|
|
11
|
+
verifiedAt: timestamp("verified_at"),
|
|
12
|
+
pwdUpdatedAt: timestamp("pwd_updated_at"),
|
|
13
|
+
deletedAt: timestamp("deleted_at"),
|
|
14
|
+
createdAt: timestamp("created_at").defaultNow(),
|
|
15
|
+
lastLoginAt: timestamp("last_login_at").defaultNow(),
|
|
16
|
+
updatedAt: timestamp("updated_at")
|
|
17
|
+
.defaultNow()
|
|
18
|
+
.$onUpdate(() => new Date()),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const filesTable = pgTable("files", {
|
|
22
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
23
|
+
fileName: varchar("file_name", { length: 255 }).notNull(),
|
|
24
|
+
url: text("url").notNull(),
|
|
25
|
+
mimetype: text("mimetype").notNull(),
|
|
26
|
+
preview: text("preview"),
|
|
27
|
+
createdAt: timestamp("created_at").defaultNow(),
|
|
28
|
+
updatedAt: timestamp("updated_at")
|
|
29
|
+
.defaultNow()
|
|
30
|
+
.$onUpdate(() => new Date()),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const otps = pgTable("otp", {
|
|
34
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
35
|
+
email: varchar("email", { length: 255 }).notNull().unique(),
|
|
36
|
+
phone: varchar("phone", { length: 50 }),
|
|
37
|
+
status: varchar("status", { enum: ["pending", "verified"] })
|
|
38
|
+
.notNull()
|
|
39
|
+
.default("pending"),
|
|
40
|
+
otp: varchar("otp", { length: 255 }).notNull(),
|
|
41
|
+
createdAt: timestamp("created_at").defaultNow(),
|
|
42
|
+
updatedAt: timestamp("updated_at")
|
|
43
|
+
.defaultNow()
|
|
44
|
+
.$onUpdate(() => new Date()),
|
|
45
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@repo/env",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": true,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rimraf dist .turbo",
|
|
8
|
+
"watch:dev": "pnpm watch",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"format": "biome format --write .",
|
|
11
|
+
"format:check": "biome ci .",
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"lint:fix": "eslint . --fix",
|
|
14
|
+
"watch": "tsc -p tsconfig.build.json --watch"
|
|
15
|
+
},
|
|
16
|
+
"exports": "./src/index.ts",
|
|
17
|
+
"types": "./src/index.ts",
|
|
18
|
+
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"eslint-config": "workspace:*",
|
|
21
|
+
"typescript-config": "workspace:*",
|
|
22
|
+
"vitest": "catalog:",
|
|
23
|
+
"vitest-config": "workspace:*"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"dotenv": "catalog:"
|
|
27
|
+
},
|
|
28
|
+
"startx": {
|
|
29
|
+
"tags": [
|
|
30
|
+
"node"
|
|
31
|
+
],
|
|
32
|
+
"requiredDeps": [
|
|
33
|
+
"@repo/env"
|
|
34
|
+
],
|
|
35
|
+
"requiredDevDeps": [
|
|
36
|
+
"typescript-config"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
import { defineEnv } from "./define-env.js";
|
|
4
|
+
|
|
5
|
+
export const ENV = defineEnv({
|
|
6
|
+
NODE_ENV: z.enum(["development", "production", "test", "staging"]).default("production"),
|
|
7
|
+
CLIENT_URL: z.string().optional().default("http://localhost:5000"),
|
|
8
|
+
SERVER_URL: z.string().optional().default("http://localhost:3000"),
|
|
9
|
+
CORS_URL: z.string().optional().default("http://localhost:3000"),
|
|
10
|
+
PORT: z.string().optional().default("3000"),
|
|
11
|
+
LOG_LEVEL: z.enum(["error", "warn", "info", "http", "debug"]).default("debug"),
|
|
12
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ZodTypeAny } from "zod";
|
|
2
|
+
import { ZodError, z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { loadDotenv } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
loadDotenv();
|
|
7
|
+
|
|
8
|
+
type SpecEntry =
|
|
9
|
+
| ZodTypeAny
|
|
10
|
+
| {
|
|
11
|
+
schema: ZodTypeAny;
|
|
12
|
+
default?: unknown;
|
|
13
|
+
env?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type Spec = Record<string, SpecEntry>;
|
|
18
|
+
|
|
19
|
+
type InferSpec<S extends Spec> = {
|
|
20
|
+
[K in keyof S]: S[K] extends ZodTypeAny
|
|
21
|
+
? z.infer<S[K]>
|
|
22
|
+
: S[K] extends { schema: ZodTypeAny }
|
|
23
|
+
? z.infer<S[K]["schema"]>
|
|
24
|
+
: never;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function isZod(v: SpecEntry): v is ZodTypeAny {
|
|
28
|
+
return typeof v === "object" && v !== null && "parse" in v;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const tempEnv = new Map<string, string>();
|
|
32
|
+
|
|
33
|
+
export function defineEnv<S extends Spec>(spec: S): InferSpec<S> {
|
|
34
|
+
const rawEnv: Record<string, unknown> = {};
|
|
35
|
+
const zodShape: Record<string, ZodTypeAny> = {};
|
|
36
|
+
|
|
37
|
+
for (const key of Object.keys(spec) as Array<keyof S>) {
|
|
38
|
+
const entry = spec[key];
|
|
39
|
+
|
|
40
|
+
const normalized = isZod(entry)
|
|
41
|
+
? { schema: entry, default: undefined, env: key as string }
|
|
42
|
+
: {
|
|
43
|
+
schema: entry.schema,
|
|
44
|
+
default: entry.default,
|
|
45
|
+
env: entry.env ?? (key as string),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if (process.env[normalized.env]) {
|
|
49
|
+
tempEnv.set(normalized.env, process.env[normalized.env] ?? "");
|
|
50
|
+
delete process.env[normalized.env];
|
|
51
|
+
}
|
|
52
|
+
const raw = tempEnv.get(normalized.env);
|
|
53
|
+
|
|
54
|
+
rawEnv[key as string] = raw === undefined ? normalized.default : raw;
|
|
55
|
+
|
|
56
|
+
zodShape[key as string] = normalized.schema;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const result = z.object(zodShape).parse(rawEnv);
|
|
61
|
+
return result as InferSpec<S>;
|
|
62
|
+
} catch (err: unknown) {
|
|
63
|
+
if (err instanceof ZodError) {
|
|
64
|
+
const messages = err.issues.map(e => `${e.path.join(".")}: ${e.message}`);
|
|
65
|
+
|
|
66
|
+
throw new Error(`Invalid environment variables:\n ❌ ${messages.join("\n ❌ ")}`);
|
|
67
|
+
}
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
process.env.DOTENV_CONFIG_QUIET = "true";
|
|
2
|
+
|
|
3
|
+
import { config } from "dotenv";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a stable project root:
|
|
9
|
+
* - prefer explicit PROJECT_ROOT env var if set (handy for CI)
|
|
10
|
+
* - else, base on this file's location (safe in ESM)
|
|
11
|
+
* - fallback to process.cwd()
|
|
12
|
+
*/
|
|
13
|
+
export function projectRoot() {
|
|
14
|
+
if (process.env.PROJECT_ROOT) return path.resolve(process.env.PROJECT_ROOT);
|
|
15
|
+
try {
|
|
16
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
+
const thisDir = path.dirname(__filename);
|
|
18
|
+
return path.resolve(thisDir, "../../../../");
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error({ error });
|
|
21
|
+
return process.cwd();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Load .env files with a clear precedence:
|
|
27
|
+
* - test: .env.test (and optional .env.test.local)
|
|
28
|
+
* - otherwise: .env -> .env.local (local should override .env)
|
|
29
|
+
*
|
|
30
|
+
* Behavior: load base first, then local override with override: true so local wins.
|
|
31
|
+
*/
|
|
32
|
+
export function loadDotenv(opts?: { root?: string }) {
|
|
33
|
+
const root = opts?.root ?? projectRoot();
|
|
34
|
+
|
|
35
|
+
if (process.env.NODE_ENV === "test") {
|
|
36
|
+
config({ path: path.join(root, ".env.test") });
|
|
37
|
+
// optional: if you want local test overrides
|
|
38
|
+
config({ path: path.join(root, ".env.test.local"), override: true });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// production/dev flow
|
|
43
|
+
config({ path: path.join(process.cwd(), ".env") }); // prod
|
|
44
|
+
// dev env
|
|
45
|
+
config({ path: path.join(root, ".env") });
|
|
46
|
+
// .env.local should override the base (for dev machine secrets)
|
|
47
|
+
config({ path: path.join(root, ".env.local"), override: true });
|
|
48
|
+
// also load .env.${NODE_ENV}.local if you want per-env local overrides:
|
|
49
|
+
if (process.env.NODE_ENV) {
|
|
50
|
+
config({ path: path.join(root, `.env.${process.env.NODE_ENV}.local`), override: true });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repo/lib",
|
|
3
3
|
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"private": true,
|
|
5
6
|
"scripts": {
|
|
6
7
|
"clean": "rimraf dist .turbo",
|
|
@@ -12,46 +13,45 @@
|
|
|
12
13
|
"lint:fix": "eslint . --fix",
|
|
13
14
|
"watch": "tsc -p tsconfig.build.json --watch"
|
|
14
15
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./src/index.ts",
|
|
18
|
+
"./*": "./src/*/index.ts"
|
|
19
|
+
},
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"@repo/email": "workspace:*",
|
|
21
|
-
"@repo/redis": "workspace:*",
|
|
22
|
-
"@types/eslint": "^8.56.5",
|
|
23
|
-
"@types/express": "^5.0.0",
|
|
24
|
-
"@types/node": "^20.16.5",
|
|
25
21
|
"@types/jsonwebtoken": "^9.0.7",
|
|
26
22
|
"@types/nodemailer": "^6.4.16",
|
|
27
23
|
"eslint-config": "workspace:*",
|
|
28
|
-
"tsc-alias": "^1.8.10",
|
|
29
24
|
"typescript-config": "workspace:*",
|
|
30
|
-
"
|
|
31
|
-
"vitest-config": "workspace:*"
|
|
32
|
-
"vitest-mock-extended": "^3.1.0",
|
|
33
|
-
"vine": "link:@types/vinejs/vine"
|
|
25
|
+
"vine": "link:@types/vinejs/vine",
|
|
26
|
+
"vitest-config": "workspace:*"
|
|
34
27
|
},
|
|
35
28
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@repo/
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
29
|
+
"@repo/redis": "workspace:*",
|
|
30
|
+
"@aws-sdk/client-s3": "catalog:",
|
|
31
|
+
"@repo/mail": "workspace:*",
|
|
32
|
+
"@repo/logger": "workspace:*",
|
|
33
|
+
"@repo/env": "workspace:*",
|
|
34
|
+
"@types/express": "catalog:",
|
|
35
|
+
"@types/express-fileupload": "catalog:",
|
|
36
|
+
"bcryptjs": "catalog:",
|
|
37
|
+
"firebase-admin": "catalog:",
|
|
38
|
+
"jsonwebtoken": "catalog:",
|
|
39
|
+
"nodemailer": "catalog:",
|
|
40
|
+
"yaml": "^2.8.2"
|
|
41
|
+
},
|
|
42
|
+
"startx": {
|
|
43
|
+
"tags": [
|
|
44
|
+
"node",
|
|
45
|
+
"backend"
|
|
46
|
+
],
|
|
47
|
+
"requiredDeps": [
|
|
48
|
+
"@repo/env",
|
|
49
|
+
"@repo/logger",
|
|
50
|
+
"@repo/mail",
|
|
51
|
+
"@repo/redis"
|
|
52
|
+
],
|
|
53
|
+
"requiredDevDeps": [
|
|
54
|
+
"typescript-config"
|
|
55
|
+
]
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1,49 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
await
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
1
|
+
import { ENV } from "@repo/env";
|
|
2
|
+
import { logger } from "@repo/logger";
|
|
3
|
+
import type { UploadedFile } from "express-fileupload";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
|
|
7
|
+
import { Random } from "../utils.js";
|
|
8
|
+
|
|
9
|
+
export class FileBasedBucket {
|
|
10
|
+
static async upload(file: UploadedFile, subpath?: string) {
|
|
11
|
+
const fileName = Random.generateString(4, "hex") + path.extname(file.name);
|
|
12
|
+
const filePath = path.join(process.cwd(), "storage", subpath ?? "", fileName);
|
|
13
|
+
await FileBasedBucket.createDirectoryIfNotExists(`storage/${subpath ?? ""}`);
|
|
14
|
+
await file.mv(filePath);
|
|
15
|
+
const publicUrl = FileBasedBucket.getPublicUrl(`${subpath ?? ""}/${fileName}`);
|
|
16
|
+
return publicUrl;
|
|
17
|
+
}
|
|
18
|
+
static deleteFile(url: string) {
|
|
19
|
+
const filePath = FileBasedBucket.getPath(url);
|
|
20
|
+
try {
|
|
21
|
+
fs.unlinkSync(filePath);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.error("Error deleting file:", error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static getPath(url: string) {
|
|
28
|
+
const path = url.replace(`${ENV.SERVER_URL}/files/`, `${process.cwd()}/storage/`);
|
|
29
|
+
return path;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static getPublicUrl(key: string) {
|
|
33
|
+
return path.join(ENV.SERVER_URL, "/files", key);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static async createDirectoryIfNotExists(path: string) {
|
|
37
|
+
return await new Promise<boolean>((resolve, reject) => {
|
|
38
|
+
if (fs.existsSync(path)) {
|
|
39
|
+
resolve(true);
|
|
40
|
+
} else {
|
|
41
|
+
fs.mkdir(path, { recursive: true }, err => {
|
|
42
|
+
if (err) {
|
|
43
|
+
reject(err);
|
|
44
|
+
}
|
|
45
|
+
resolve(true);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|