@arch-cadre/core 0.0.42 → 0.0.43
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/dist/core/auth/augment.d.ts +18 -0
- package/dist/core/auth/augment.d.ts.map +1 -0
- package/dist/core/auth/augment.js +45 -0
- package/dist/core/auth/email-verification.d.ts +58 -0
- package/dist/core/auth/email-verification.d.ts.map +1 -0
- package/dist/core/auth/email-verification.js +105 -0
- package/dist/core/auth/events.d.ts +53 -0
- package/dist/core/auth/events.d.ts.map +1 -0
- package/dist/core/auth/events.js +1 -0
- package/dist/core/auth/logic.d.ts +106 -0
- package/dist/core/auth/logic.d.ts.map +1 -0
- package/dist/core/auth/logic.js +245 -0
- package/dist/core/auth/password-reset.d.ts +35 -0
- package/dist/core/auth/password-reset.d.ts.map +1 -0
- package/dist/core/auth/password-reset.js +122 -0
- package/dist/core/auth/rbac.d.ts +56 -0
- package/dist/core/auth/rbac.d.ts.map +1 -0
- package/dist/core/auth/rbac.js +134 -0
- package/dist/core/auth/session.d.ts +50 -0
- package/dist/core/auth/session.d.ts.map +1 -0
- package/dist/core/auth/session.js +152 -0
- package/dist/core/auth/types.d.ts +52 -0
- package/dist/core/auth/types.d.ts.map +1 -0
- package/dist/core/auth/types.js +1 -0
- package/dist/core/auth/utils/encode.d.ts +12 -0
- package/dist/core/auth/utils/encode.d.ts.map +1 -0
- package/dist/core/auth/utils/encode.js +20 -0
- package/dist/core/auth/utils/{encryption.d.mts → encryption.d.ts} +5 -8
- package/dist/core/auth/utils/encryption.d.ts.map +1 -0
- package/dist/core/auth/utils/encryption.js +62 -0
- package/dist/core/auth/validation.d.ts +44 -0
- package/dist/core/auth/validation.d.ts.map +1 -0
- package/dist/core/auth/validation.js +41 -0
- package/dist/core/bootstrap.d.ts +2 -0
- package/dist/core/bootstrap.d.ts.map +1 -0
- package/dist/core/bootstrap.js +51 -0
- package/dist/core/config.d.ts +9 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +3 -0
- package/dist/core/config.server.d.ts +12 -0
- package/dist/core/config.server.d.ts.map +1 -0
- package/dist/core/config.server.js +61 -0
- package/dist/core/event-bus.d.ts +14 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +51 -0
- package/dist/core/filesystem/index.d.ts +4 -0
- package/dist/core/filesystem/index.d.ts.map +1 -0
- package/dist/core/filesystem/index.js +10 -0
- package/dist/core/filesystem/providers/local.d.ts +8 -0
- package/dist/core/filesystem/providers/local.d.ts.map +1 -0
- package/dist/core/filesystem/providers/local.js +42 -0
- package/dist/core/filesystem/service.d.ts +16 -0
- package/dist/core/filesystem/service.d.ts.map +1 -0
- package/dist/core/filesystem/service.js +51 -0
- package/dist/core/filesystem/types.d.ts +19 -0
- package/dist/core/filesystem/types.d.ts.map +1 -0
- package/dist/core/filesystem/types.js +1 -0
- package/dist/core/notifications/actions.d.ts +54 -0
- package/dist/core/notifications/actions.d.ts.map +1 -0
- package/dist/core/notifications/actions.js +43 -0
- package/dist/core/notifications/index.d.ts +4 -0
- package/dist/core/notifications/index.d.ts.map +1 -0
- package/dist/core/notifications/index.js +3 -0
- package/dist/core/notifications/service.d.ts +7 -0
- package/dist/core/notifications/service.d.ts.map +1 -0
- package/dist/core/notifications/service.js +32 -0
- package/dist/core/notifications/types.d.ts +17 -0
- package/dist/core/notifications/types.d.ts.map +1 -0
- package/dist/core/notifications/types.js +1 -0
- package/dist/core/setup.d.ts +6 -0
- package/dist/core/setup.d.ts.map +1 -0
- package/dist/core/setup.js +25 -0
- package/dist/core/types.d.ts +10 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/server/auth/email.d.ts +10 -0
- package/dist/server/auth/email.d.ts.map +1 -0
- package/dist/server/auth/email.js +20 -0
- package/dist/server/auth/{password.d.mts → password.d.ts} +4 -7
- package/dist/server/auth/password.d.ts.map +1 -0
- package/dist/server/auth/password.js +30 -0
- package/dist/server/auth/types.d.ts +13 -0
- package/dist/server/auth/types.d.ts.map +1 -0
- package/dist/server/auth/types.js +1 -0
- package/dist/server/auth/user.d.ts +54 -0
- package/dist/server/auth/user.d.ts.map +1 -0
- package/dist/server/auth/user.js +222 -0
- package/dist/server/database/inject.d.ts +11 -0
- package/dist/server/database/inject.d.ts.map +1 -0
- package/dist/server/database/inject.js +29 -0
- package/dist/server/database/schema.d.ts +2953 -0
- package/dist/server/database/{schema.d.mts.map → schema.d.ts.map} +1 -1
- package/dist/server/database/schema.js +192 -0
- package/dist/server/database/types.d.ts +12 -0
- package/dist/server/database/types.d.ts.map +1 -0
- package/dist/server/database/types.js +1 -0
- package/dist/server/emails/index.d.ts +23 -0
- package/dist/server/emails/index.d.ts.map +1 -0
- package/dist/server/emails/index.js +67 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +32 -0
- package/package.json +5 -6
- package/dist/_virtual/_rolldown/runtime.mjs +0 -1
- package/dist/core/auth/augment.d.mts +0 -20
- package/dist/core/auth/augment.d.mts.map +0 -1
- package/dist/core/auth/augment.mjs +0 -2
- package/dist/core/auth/augment.mjs.map +0 -1
- package/dist/core/auth/email-verification.d.mts +0 -62
- package/dist/core/auth/email-verification.d.mts.map +0 -1
- package/dist/core/auth/email-verification.mjs +0 -2
- package/dist/core/auth/email-verification.mjs.map +0 -1
- package/dist/core/auth/logic.d.mts +0 -110
- package/dist/core/auth/logic.d.mts.map +0 -1
- package/dist/core/auth/logic.mjs +0 -2
- package/dist/core/auth/logic.mjs.map +0 -1
- package/dist/core/auth/password-reset.d.mts +0 -39
- package/dist/core/auth/password-reset.d.mts.map +0 -1
- package/dist/core/auth/password-reset.mjs +0 -2
- package/dist/core/auth/password-reset.mjs.map +0 -1
- package/dist/core/auth/rbac.d.mts +0 -61
- package/dist/core/auth/rbac.d.mts.map +0 -1
- package/dist/core/auth/rbac.mjs +0 -2
- package/dist/core/auth/rbac.mjs.map +0 -1
- package/dist/core/auth/session.d.mts +0 -54
- package/dist/core/auth/session.d.mts.map +0 -1
- package/dist/core/auth/session.mjs +0 -2
- package/dist/core/auth/session.mjs.map +0 -1
- package/dist/core/auth/types.d.mts +0 -55
- package/dist/core/auth/types.d.mts.map +0 -1
- package/dist/core/auth/utils/encode.d.mts +0 -15
- package/dist/core/auth/utils/encode.d.mts.map +0 -1
- package/dist/core/auth/utils/encode.mjs +0 -2
- package/dist/core/auth/utils/encode.mjs.map +0 -1
- package/dist/core/auth/utils/encryption.d.mts.map +0 -1
- package/dist/core/auth/utils/encryption.mjs +0 -2
- package/dist/core/auth/utils/encryption.mjs.map +0 -1
- package/dist/core/auth/validation.d.mts +0 -48
- package/dist/core/auth/validation.d.mts.map +0 -1
- package/dist/core/auth/validation.mjs +0 -2
- package/dist/core/auth/validation.mjs.map +0 -1
- package/dist/core/bootstrap.d.mts +0 -5
- package/dist/core/bootstrap.d.mts.map +0 -1
- package/dist/core/bootstrap.mjs +0 -2
- package/dist/core/bootstrap.mjs.map +0 -1
- package/dist/core/config.d.mts +0 -11
- package/dist/core/config.d.mts.map +0 -1
- package/dist/core/config.mjs +0 -2
- package/dist/core/config.mjs.map +0 -1
- package/dist/core/config.server.d.mts +0 -16
- package/dist/core/config.server.d.mts.map +0 -1
- package/dist/core/config.server.mjs +0 -2
- package/dist/core/config.server.mjs.map +0 -1
- package/dist/core/event-bus.d.mts +0 -17
- package/dist/core/event-bus.d.mts.map +0 -1
- package/dist/core/event-bus.mjs +0 -2
- package/dist/core/event-bus.mjs.map +0 -1
- package/dist/core/filesystem/index.mjs +0 -2
- package/dist/core/filesystem/index.mjs.map +0 -1
- package/dist/core/filesystem/providers/local.mjs +0 -2
- package/dist/core/filesystem/providers/local.mjs.map +0 -1
- package/dist/core/filesystem/service.d.mts +0 -19
- package/dist/core/filesystem/service.d.mts.map +0 -1
- package/dist/core/filesystem/service.mjs +0 -2
- package/dist/core/filesystem/service.mjs.map +0 -1
- package/dist/core/filesystem/types.d.mts +0 -22
- package/dist/core/filesystem/types.d.mts.map +0 -1
- package/dist/core/notifications/actions.d.mts +0 -58
- package/dist/core/notifications/actions.d.mts.map +0 -1
- package/dist/core/notifications/actions.mjs +0 -2
- package/dist/core/notifications/actions.mjs.map +0 -1
- package/dist/core/notifications/index.mjs +0 -1
- package/dist/core/notifications/service.d.mts +0 -9
- package/dist/core/notifications/service.d.mts.map +0 -1
- package/dist/core/notifications/service.mjs +0 -2
- package/dist/core/notifications/service.mjs.map +0 -1
- package/dist/core/notifications/types.d.mts +0 -21
- package/dist/core/notifications/types.d.mts.map +0 -1
- package/dist/core/setup.d.mts +0 -9
- package/dist/core/setup.d.mts.map +0 -1
- package/dist/core/setup.mjs +0 -2
- package/dist/core/setup.mjs.map +0 -1
- package/dist/core/types.d.mts +0 -13
- package/dist/core/types.d.mts.map +0 -1
- package/dist/index.d.mts +0 -8
- package/dist/index.mjs +0 -1
- package/dist/server/auth/email.d.mts +0 -13
- package/dist/server/auth/email.d.mts.map +0 -1
- package/dist/server/auth/email.mjs +0 -2
- package/dist/server/auth/email.mjs.map +0 -1
- package/dist/server/auth/password.d.mts.map +0 -1
- package/dist/server/auth/password.mjs +0 -2
- package/dist/server/auth/password.mjs.map +0 -1
- package/dist/server/auth/user.d.mts +0 -58
- package/dist/server/auth/user.d.mts.map +0 -1
- package/dist/server/auth/user.mjs +0 -2
- package/dist/server/auth/user.mjs.map +0 -1
- package/dist/server/database/inject.d.mts +0 -15
- package/dist/server/database/inject.d.mts.map +0 -1
- package/dist/server/database/inject.mjs +0 -2
- package/dist/server/database/inject.mjs.map +0 -1
- package/dist/server/database/schema.d.mts +0 -2962
- package/dist/server/database/schema.mjs +0 -2
- package/dist/server/database/schema.mjs.map +0 -1
- package/dist/server/emails/index.d.mts +0 -26
- package/dist/server/emails/index.d.mts.map +0 -1
- package/dist/server/emails/index.mjs +0 -2
- package/dist/server/emails/index.mjs.map +0 -1
- package/dist/server.d.mts +0 -26
- package/dist/server.mjs +0 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { desc, eq } from "drizzle-orm";
|
|
3
|
+
import { db } from "../../server/database/inject";
|
|
4
|
+
import { notificationTable } from "../../server/database/schema";
|
|
5
|
+
import { getCurrentSession } from "../auth/session";
|
|
6
|
+
export async function getUserNotifications() {
|
|
7
|
+
const { user } = await getCurrentSession();
|
|
8
|
+
if (!user)
|
|
9
|
+
return null;
|
|
10
|
+
return await db
|
|
11
|
+
.select()
|
|
12
|
+
.from(notificationTable)
|
|
13
|
+
.where(eq(notificationTable.userId, user.id))
|
|
14
|
+
.orderBy(desc(notificationTable.createdAt));
|
|
15
|
+
}
|
|
16
|
+
export async function createNotification(data) {
|
|
17
|
+
const [notification] = await db
|
|
18
|
+
.insert(notificationTable)
|
|
19
|
+
.values({
|
|
20
|
+
...data,
|
|
21
|
+
isRead: false,
|
|
22
|
+
})
|
|
23
|
+
.returning();
|
|
24
|
+
return notification;
|
|
25
|
+
}
|
|
26
|
+
export async function markNotificationAsRead(id) {
|
|
27
|
+
const [updated] = await db
|
|
28
|
+
.update(notificationTable)
|
|
29
|
+
.set({ isRead: true })
|
|
30
|
+
.where(eq(notificationTable.id, id))
|
|
31
|
+
.returning();
|
|
32
|
+
return updated;
|
|
33
|
+
}
|
|
34
|
+
export async function markAllNotificationsAsRead() {
|
|
35
|
+
const { user } = await getCurrentSession();
|
|
36
|
+
if (!user)
|
|
37
|
+
return null;
|
|
38
|
+
return await db
|
|
39
|
+
.update(notificationTable)
|
|
40
|
+
.set({ isRead: true })
|
|
41
|
+
.where(eq(notificationTable.userId, user.id))
|
|
42
|
+
.returning();
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/notifications/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/core/notifications/service.ts"],"names":[],"mappings":"AAIA,cAAM,mBAAmB;IACvB,OAAO,CAAC,WAAW,CAAS;IAErB,IAAI;CAqCZ;AAOD,eAAO,MAAM,mBAAmB,qBAEL,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { eventBus } from "../event-bus";
|
|
3
|
+
import { createNotification } from "./actions";
|
|
4
|
+
class NotificationService {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.initialized = false;
|
|
7
|
+
}
|
|
8
|
+
init() {
|
|
9
|
+
if (this.initialized) {
|
|
10
|
+
// console.log("[Notification Service] Already initialized.");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
console.log("[Notification Service] Subscribing to notification:send...");
|
|
14
|
+
eventBus.subscribe("notification:send", "notification-service", async (event) => {
|
|
15
|
+
console.log("[Notification Service] Received notification:send event", event.payload);
|
|
16
|
+
try {
|
|
17
|
+
// const { createNotification } = await import("./actions");
|
|
18
|
+
const result = await createNotification(event.payload);
|
|
19
|
+
console.log("[Notification Service] Notification created successfully:", result.id);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error("[Notification Service] Failed to process notification:send", error);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
this.initialized = true;
|
|
26
|
+
console.log("[NotificationService] Initialized and listening for events.");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Global Singleton Pattern
|
|
30
|
+
const globalForNotifications = globalThis;
|
|
31
|
+
export const notificationService = (_a = globalForNotifications.__KRYO_NOTIFICATION_SERVICE__) !== null && _a !== void 0 ? _a : new NotificationService();
|
|
32
|
+
globalForNotifications.__KRYO_NOTIFICATION_SERVICE__ = notificationService;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InferSelectModel } from "drizzle-orm";
|
|
2
|
+
import type { notificationTable } from "../../server/database/schema";
|
|
3
|
+
export type Notification = InferSelectModel<typeof notificationTable>;
|
|
4
|
+
export type CreateNotificationPayload = {
|
|
5
|
+
title: string;
|
|
6
|
+
content?: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
target?: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
resourceId?: string;
|
|
11
|
+
resourceType?: string;
|
|
12
|
+
};
|
|
13
|
+
export type NotificationEvents = {
|
|
14
|
+
"notification:send": CreateNotificationPayload;
|
|
15
|
+
"notification:created": Notification;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/notifications/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEtE,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,mBAAmB,EAAE,yBAAyB,CAAC;IAC/C,sBAAsB,EAAE,YAAY,CAAC;CACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/core/setup.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAiB1D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { db } from "../server/database/inject";
|
|
3
|
+
import { userTable } from "../server/database/schema";
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the system is installed.
|
|
6
|
+
* A system is considered installed if at least one user exists in the database.
|
|
7
|
+
*/
|
|
8
|
+
export async function isSystemInstalled() {
|
|
9
|
+
var _a;
|
|
10
|
+
try {
|
|
11
|
+
// We check if the users table exists and has at least one record
|
|
12
|
+
console.log("[Kernel:Setup] Checking if system is installed...");
|
|
13
|
+
const result = await db
|
|
14
|
+
.select({ count: sql `count(*)` })
|
|
15
|
+
.from(userTable);
|
|
16
|
+
const count = Number(((_a = result[0]) === null || _a === void 0 ? void 0 : _a.count) || 0);
|
|
17
|
+
console.log(`[Kernel:Setup] User count: ${count}`);
|
|
18
|
+
return count > 0;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.log(`[Kernel:Setup] System not installed or error: ${error.message}`);
|
|
22
|
+
// If table doesn't exist, it's definitely not installed
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type UserRole = "user" | "admin" | string;
|
|
2
|
+
export type UserPermission = string;
|
|
3
|
+
export interface SystemEvent<T = any> {
|
|
4
|
+
type: string;
|
|
5
|
+
payload: T;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
source: string;
|
|
8
|
+
}
|
|
9
|
+
export type EventHandler<T = any> = (event: SystemEvent<T>) => Promise<void> | void;
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACjD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI,CAClC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAClB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./core/auth/types";
|
|
2
|
+
export * from "./core/auth/validation";
|
|
3
|
+
export * from "./core/event-bus";
|
|
4
|
+
export * from "./core/notifications/service";
|
|
5
|
+
export * from "./core/notifications/types";
|
|
6
|
+
export * from "./core/types";
|
|
7
|
+
export * from "./server/database/schema";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,kBAAkB,CAAC;AAMjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,cAAc,CAAC;AAE7B,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// export { ExtensionPoint } from "./client/extension-point";
|
|
2
|
+
// export { ExtensionPointClient } from "./client/extension-point-client";
|
|
3
|
+
// export { WidgetArea } from "./client/widget-area";
|
|
4
|
+
// Common Types & Constants
|
|
5
|
+
export * from "./core/auth/types";
|
|
6
|
+
export * from "./core/auth/validation";
|
|
7
|
+
// Shared Services (Singletons / Handlers)
|
|
8
|
+
export * from "./core/event-bus";
|
|
9
|
+
// Shared Constants & Models (Safe for Browser)
|
|
10
|
+
// export * from "./core/modules/ui";
|
|
11
|
+
// export * from "./core/modules/types";
|
|
12
|
+
// Client Hooks & Providers
|
|
13
|
+
export * from "./core/notifications/service";
|
|
14
|
+
export * from "./core/notifications/types";
|
|
15
|
+
export * from "./core/types";
|
|
16
|
+
export * from "./server/database/schema";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates the email format and length.
|
|
3
|
+
*/
|
|
4
|
+
export declare function verifyEmailInput(email: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if an email address is already in use.
|
|
7
|
+
* @returns True if the email is available, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkEmailAvailability(email: string): Promise<boolean>;
|
|
10
|
+
//# sourceMappingURL=email.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../../src/server/auth/email.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO5E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { count, eq } from "drizzle-orm";
|
|
2
|
+
import { db } from "../database/inject";
|
|
3
|
+
import { userTable } from "../database/schema";
|
|
4
|
+
/**
|
|
5
|
+
* Validates the email format and length.
|
|
6
|
+
*/
|
|
7
|
+
export function verifyEmailInput(email) {
|
|
8
|
+
return /^.+@.+\..+$/.test(email) && email.length < 256 && email.length > 0;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Checks if an email address is already in use.
|
|
12
|
+
* @returns True if the email is available, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export async function checkEmailAvailability(email) {
|
|
15
|
+
const [entries] = await db
|
|
16
|
+
.select({ count: count() })
|
|
17
|
+
.from(userTable)
|
|
18
|
+
.where(eq(userTable.email, email));
|
|
19
|
+
return entries.count === 0;
|
|
20
|
+
}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
//#region src/server/auth/password.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Hashes the password using bcrypt.
|
|
4
3
|
* @param password Password to be hashed.
|
|
5
4
|
* @returns Returns the hashed password.
|
|
6
5
|
*/
|
|
7
|
-
declare function hashPassword(password: string): Promise<string>;
|
|
6
|
+
export declare function hashPassword(password: string): Promise<string>;
|
|
8
7
|
/**
|
|
9
8
|
* Verifies the password hash.
|
|
10
9
|
* @param hash bcrypt hash.
|
|
11
10
|
* @param password Password for comparison.
|
|
12
11
|
* @returns Returns true if the password is correct, false otherwise.
|
|
13
12
|
*/
|
|
14
|
-
declare function verifyPasswordHash(hash: string, password: string): Promise<boolean>;
|
|
13
|
+
export declare function verifyPasswordHash(hash: string, password: string): Promise<boolean>;
|
|
15
14
|
/**
|
|
16
15
|
* Validates password strength.
|
|
17
16
|
* @param password Password to validate.
|
|
18
17
|
* @returns Returns true if the password meets complexity requirements.
|
|
19
18
|
*/
|
|
20
|
-
declare function verifyPasswordStrength(password: string): Promise<boolean>;
|
|
21
|
-
//#
|
|
22
|
-
export { hashPassword, verifyPasswordHash, verifyPasswordStrength };
|
|
23
|
-
//# sourceMappingURL=password.d.mts.map
|
|
19
|
+
export declare function verifyPasswordStrength(password: string): Promise<boolean>;
|
|
20
|
+
//# sourceMappingURL=password.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../../src/server/auth/password.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIpE;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAElB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import bcrypt from "bcryptjs";
|
|
3
|
+
/**
|
|
4
|
+
* Hashes the password using bcrypt.
|
|
5
|
+
* @param password Password to be hashed.
|
|
6
|
+
* @returns Returns the hashed password.
|
|
7
|
+
*/
|
|
8
|
+
export async function hashPassword(password) {
|
|
9
|
+
const saltRounds = 10;
|
|
10
|
+
return await bcrypt.hash(password, saltRounds);
|
|
11
|
+
// return password;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Verifies the password hash.
|
|
15
|
+
* @param hash bcrypt hash.
|
|
16
|
+
* @param password Password for comparison.
|
|
17
|
+
* @returns Returns true if the password is correct, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export async function verifyPasswordHash(hash, password) {
|
|
20
|
+
return await bcrypt.compare(password, hash);
|
|
21
|
+
// return password === hash;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validates password strength.
|
|
25
|
+
* @param password Password to validate.
|
|
26
|
+
* @returns Returns true if the password meets complexity requirements.
|
|
27
|
+
*/
|
|
28
|
+
export async function verifyPasswordStrength(password) {
|
|
29
|
+
return password.length >= 8 && password.length <= 255;
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "../../core/auth/types";
|
|
2
|
+
import type { UserSession as CoreUserSession, FullUser } from "../../core/auth/types";
|
|
3
|
+
export interface User2FAStatus {
|
|
4
|
+
registeredTOTP: boolean;
|
|
5
|
+
registeredPasskey: boolean;
|
|
6
|
+
registered2FA: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use FullUser from core/auth/types
|
|
10
|
+
*/
|
|
11
|
+
export type UserWith2FA = FullUser;
|
|
12
|
+
export type { CoreUserSession as UserSession };
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/server/auth/types.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AAEtC,OAAO,KAAK,EACV,WAAW,IAAI,eAAe,EAC9B,QAAQ,EACT,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;AAEnC,YAAY,EAAE,eAAe,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../core/auth/types";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { User } from "../../core/auth/types";
|
|
2
|
+
/**
|
|
3
|
+
* Validates the username input.
|
|
4
|
+
*/
|
|
5
|
+
export declare function verifyUsernameInput(username: string): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new user with an initial recovery code and default 'user' role.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createUser(email: string, username: string, password: string): Promise<User>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new user from an OAuth provider.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createOAuthUser(email: string, name: string, image?: string): Promise<User>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a user by ID.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getUserById(userId: string): Promise<User | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Decrypts and returns the user's recovery code.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getUserRecoverCode(userId: string): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Generates and sets a new recovery code for the user.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resetUserRecoveryCode(userId: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Updates the user's password.
|
|
28
|
+
*/
|
|
29
|
+
export declare function updateUserPassword(userId: string, password: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Updates the user's name.
|
|
32
|
+
*/
|
|
33
|
+
export declare function updateUserName(userId: string, name: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Updates the user's image.
|
|
36
|
+
*/
|
|
37
|
+
export declare function updateUserAwatar(userId: string, image: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Updates the user's email and marks it as verified.
|
|
40
|
+
*/
|
|
41
|
+
export declare function updateUserEmailAndSetEmailAsVerified(userId: string, email: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the user as email verified if the provided email matches.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setUserAsEmailVerifiedIfEmailMatches(userId: string, email: string): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the user's password hash.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getUserPasswordHash(userId: string): Promise<string | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a user by email.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getUserFromEmail(email: string): Promise<User | null>;
|
|
54
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/server/auth/user.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAWlD;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAI5E;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CA0Cf;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAStE;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAaxE;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB3E;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAOf;AACD;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;GAEG;AACH,wBAAsB,oCAAoC,CACxD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;GAEG;AACH,wBAAsB,oCAAoC,CACxD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC,CAUlB;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAaxB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAS1E"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { and, eq } from "drizzle-orm";
|
|
3
|
+
import { generateRandomRecoveryCode } from "../../core/auth/utils/encode";
|
|
4
|
+
import { decryptToString, encryptString, } from "../../core/auth/utils/encryption";
|
|
5
|
+
import { db } from "../database/inject";
|
|
6
|
+
import { rolesTable, usersToRolesTable, userTable } from "../database/schema";
|
|
7
|
+
import { sendRecoveryCode } from "../emails/index";
|
|
8
|
+
import { hashPassword } from "./password";
|
|
9
|
+
/**
|
|
10
|
+
* Validates the username input.
|
|
11
|
+
*/
|
|
12
|
+
export async function verifyUsernameInput(username) {
|
|
13
|
+
return (username.length > 3 && username.length < 32 && username.trim() === username);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new user with an initial recovery code and default 'user' role.
|
|
17
|
+
*/
|
|
18
|
+
export async function createUser(email, username, password) {
|
|
19
|
+
const passwordHash = await hashPassword(password);
|
|
20
|
+
const recoveryCode = generateRandomRecoveryCode();
|
|
21
|
+
const encryptedRecoveryCode = encryptString(recoveryCode);
|
|
22
|
+
return await db.transaction(async (tx) => {
|
|
23
|
+
const [row] = await tx
|
|
24
|
+
.insert(userTable)
|
|
25
|
+
.values({
|
|
26
|
+
email: email,
|
|
27
|
+
name: username,
|
|
28
|
+
password: passwordHash,
|
|
29
|
+
recovery_code: Buffer.from(encryptedRecoveryCode),
|
|
30
|
+
})
|
|
31
|
+
.returning();
|
|
32
|
+
if (!row) {
|
|
33
|
+
throw new Error("Failed to create user");
|
|
34
|
+
}
|
|
35
|
+
// Assign default 'user' role
|
|
36
|
+
let [role] = await tx
|
|
37
|
+
.select()
|
|
38
|
+
.from(rolesTable)
|
|
39
|
+
.where(eq(rolesTable.name, "user"));
|
|
40
|
+
if (!role) {
|
|
41
|
+
[role] = await tx
|
|
42
|
+
.insert(rolesTable)
|
|
43
|
+
.values({ name: "user", description: "Default user role" })
|
|
44
|
+
.returning();
|
|
45
|
+
}
|
|
46
|
+
await tx.insert(usersToRolesTable).values({
|
|
47
|
+
userId: row.id,
|
|
48
|
+
roleId: role.id,
|
|
49
|
+
});
|
|
50
|
+
await sendRecoveryCode(row.email, recoveryCode);
|
|
51
|
+
return row;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new user from an OAuth provider.
|
|
56
|
+
*/
|
|
57
|
+
export async function createOAuthUser(email, name, image) {
|
|
58
|
+
const recoveryCode = generateRandomRecoveryCode();
|
|
59
|
+
const encryptedRecoveryCode = encryptString(recoveryCode);
|
|
60
|
+
return await db.transaction(async (tx) => {
|
|
61
|
+
const [row] = await tx
|
|
62
|
+
.insert(userTable)
|
|
63
|
+
.values({
|
|
64
|
+
email: email,
|
|
65
|
+
name: name,
|
|
66
|
+
image: image,
|
|
67
|
+
emailVerifiedAt: new Date(),
|
|
68
|
+
recovery_code: Buffer.from(encryptedRecoveryCode),
|
|
69
|
+
})
|
|
70
|
+
.returning();
|
|
71
|
+
// Assign default 'user' role
|
|
72
|
+
let [role] = await tx
|
|
73
|
+
.select()
|
|
74
|
+
.from(rolesTable)
|
|
75
|
+
.where(eq(rolesTable.name, "user"));
|
|
76
|
+
if (!role) {
|
|
77
|
+
[role] = await tx
|
|
78
|
+
.insert(rolesTable)
|
|
79
|
+
.values({ name: "user", description: "Default user role" })
|
|
80
|
+
.returning();
|
|
81
|
+
}
|
|
82
|
+
await tx.insert(usersToRolesTable).values({
|
|
83
|
+
userId: row.id,
|
|
84
|
+
roleId: role.id,
|
|
85
|
+
});
|
|
86
|
+
return row;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns a user by ID.
|
|
91
|
+
*/
|
|
92
|
+
export async function getUserById(userId) {
|
|
93
|
+
const [user] = await db
|
|
94
|
+
.select()
|
|
95
|
+
.from(userTable)
|
|
96
|
+
.where(eq(userTable.id, userId));
|
|
97
|
+
if (!user)
|
|
98
|
+
return null;
|
|
99
|
+
const { password, recovery_code, ...safeUser } = user;
|
|
100
|
+
return safeUser;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Decrypts and returns the user's recovery code.
|
|
104
|
+
*/
|
|
105
|
+
export async function getUserRecoverCode(userId) {
|
|
106
|
+
const [user] = await db
|
|
107
|
+
.select({
|
|
108
|
+
recovery_code: userTable.recovery_code,
|
|
109
|
+
})
|
|
110
|
+
.from(userTable)
|
|
111
|
+
.where(eq(userTable.id, userId));
|
|
112
|
+
if (!user || !user.recovery_code) {
|
|
113
|
+
throw new Error("Recovery code not found for user");
|
|
114
|
+
}
|
|
115
|
+
return decryptToString(user.recovery_code);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generates and sets a new recovery code for the user.
|
|
119
|
+
*/
|
|
120
|
+
export async function resetUserRecoveryCode(userId) {
|
|
121
|
+
const recoveryCode = generateRandomRecoveryCode();
|
|
122
|
+
const encrypted = encryptString(recoveryCode);
|
|
123
|
+
const [currentUser] = await db
|
|
124
|
+
.update(userTable)
|
|
125
|
+
.set({
|
|
126
|
+
recovery_code: Buffer.from(encrypted),
|
|
127
|
+
})
|
|
128
|
+
.where(eq(userTable.id, userId))
|
|
129
|
+
.returning();
|
|
130
|
+
if (!currentUser) {
|
|
131
|
+
throw new Error("User not found");
|
|
132
|
+
}
|
|
133
|
+
await sendRecoveryCode(currentUser.email, recoveryCode);
|
|
134
|
+
return recoveryCode;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Updates the user's password.
|
|
138
|
+
*/
|
|
139
|
+
export async function updateUserPassword(userId, password) {
|
|
140
|
+
const passwordHash = await hashPassword(password);
|
|
141
|
+
await db
|
|
142
|
+
.update(userTable)
|
|
143
|
+
.set({
|
|
144
|
+
password: passwordHash,
|
|
145
|
+
})
|
|
146
|
+
.where(eq(userTable.id, userId));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Updates the user's name.
|
|
150
|
+
*/
|
|
151
|
+
export async function updateUserName(userId, name) {
|
|
152
|
+
await db
|
|
153
|
+
.update(userTable)
|
|
154
|
+
.set({
|
|
155
|
+
name: name,
|
|
156
|
+
})
|
|
157
|
+
.where(eq(userTable.id, userId));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Updates the user's image.
|
|
161
|
+
*/
|
|
162
|
+
export async function updateUserAwatar(userId, image) {
|
|
163
|
+
await db
|
|
164
|
+
.update(userTable)
|
|
165
|
+
.set({
|
|
166
|
+
image,
|
|
167
|
+
})
|
|
168
|
+
.where(eq(userTable.id, userId));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Updates the user's email and marks it as verified.
|
|
172
|
+
*/
|
|
173
|
+
export async function updateUserEmailAndSetEmailAsVerified(userId, email) {
|
|
174
|
+
await db
|
|
175
|
+
.update(userTable)
|
|
176
|
+
.set({
|
|
177
|
+
email: email,
|
|
178
|
+
emailVerifiedAt: new Date(),
|
|
179
|
+
})
|
|
180
|
+
.where(eq(userTable.id, userId));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Sets the user as email verified if the provided email matches.
|
|
184
|
+
*/
|
|
185
|
+
export async function setUserAsEmailVerifiedIfEmailMatches(userId, email) {
|
|
186
|
+
const result = await db
|
|
187
|
+
.update(userTable)
|
|
188
|
+
.set({
|
|
189
|
+
emailVerifiedAt: new Date(),
|
|
190
|
+
})
|
|
191
|
+
.where(and(eq(userTable.id, userId), eq(userTable.email, email)))
|
|
192
|
+
.returning({ id: userTable.id });
|
|
193
|
+
return result.length > 0;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns the user's password hash.
|
|
197
|
+
*/
|
|
198
|
+
export async function getUserPasswordHash(userId) {
|
|
199
|
+
const [user] = await db
|
|
200
|
+
.select({
|
|
201
|
+
password: userTable.password,
|
|
202
|
+
})
|
|
203
|
+
.from(userTable)
|
|
204
|
+
.where(eq(userTable.id, userId));
|
|
205
|
+
if (!user) {
|
|
206
|
+
throw new Error("User not found");
|
|
207
|
+
}
|
|
208
|
+
return user.password;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Returns a user by email.
|
|
212
|
+
*/
|
|
213
|
+
export async function getUserFromEmail(email) {
|
|
214
|
+
const [user] = await db
|
|
215
|
+
.select()
|
|
216
|
+
.from(userTable)
|
|
217
|
+
.where(eq(userTable.email, email));
|
|
218
|
+
if (!user)
|
|
219
|
+
return null;
|
|
220
|
+
const { password, recovery_code, ...safeUser } = user;
|
|
221
|
+
return safeUser;
|
|
222
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import type * as schema from "./schema";
|
|
3
|
+
export type KryoDatabase = NodePgDatabase<typeof schema>;
|
|
4
|
+
export declare function injectDb(db: KryoDatabase): void;
|
|
5
|
+
/**
|
|
6
|
+
* Shared 'db' proxy.
|
|
7
|
+
* Resolves to globalThis.__KRYO_DB__ on every property access.
|
|
8
|
+
* Safe to import statically at top-level.
|
|
9
|
+
*/
|
|
10
|
+
export declare const db: KryoDatabase;
|
|
11
|
+
//# sourceMappingURL=inject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../../../src/server/database/inject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,KAAK,MAAM,MAAM,UAAU,CAAC;AAExC,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,MAAM,CAAC,CAAC;AAKzD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,YAAY,QAIxC;AAED;;;;GAIG;AACH,eAAO,MAAM,EAAE,cAmBb,CAAC"}
|