@arch-cadre/core 0.0.23 → 0.0.24

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.
Files changed (90) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -29
  2. package/dist/_virtual/_rolldown/runtime.mjs +1 -18
  3. package/dist/core/auth/augment.cjs +1 -71
  4. package/dist/core/auth/augment.d.cts.map +1 -1
  5. package/dist/core/auth/augment.d.mts.map +1 -1
  6. package/dist/core/auth/augment.mjs +1 -65
  7. package/dist/core/auth/augment.mjs.map +1 -1
  8. package/dist/core/auth/email-verification.cjs +1 -99
  9. package/dist/core/auth/email-verification.mjs +1 -91
  10. package/dist/core/auth/email-verification.mjs.map +1 -1
  11. package/dist/core/auth/logic.cjs +1 -224
  12. package/dist/core/auth/logic.mjs +1 -212
  13. package/dist/core/auth/logic.mjs.map +1 -1
  14. package/dist/core/auth/password-reset.cjs +1 -118
  15. package/dist/core/auth/password-reset.mjs +1 -110
  16. package/dist/core/auth/password-reset.mjs.map +1 -1
  17. package/dist/core/auth/rbac.cjs +1 -118
  18. package/dist/core/auth/rbac.mjs +1 -103
  19. package/dist/core/auth/rbac.mjs.map +1 -1
  20. package/dist/core/auth/session.cjs +1 -154
  21. package/dist/core/auth/session.mjs +1 -142
  22. package/dist/core/auth/session.mjs.map +1 -1
  23. package/dist/core/auth/types.d.cts.map +1 -1
  24. package/dist/core/auth/types.d.mts.map +1 -1
  25. package/dist/core/auth/utils/encode.cjs +1 -27
  26. package/dist/core/auth/utils/encode.mjs +1 -25
  27. package/dist/core/auth/utils/encode.mjs.map +1 -1
  28. package/dist/core/auth/utils/encryption.cjs +1 -67
  29. package/dist/core/auth/utils/encryption.mjs +1 -63
  30. package/dist/core/auth/utils/encryption.mjs.map +1 -1
  31. package/dist/core/auth/validation.cjs +1 -39
  32. package/dist/core/auth/validation.mjs +1 -30
  33. package/dist/core/auth/validation.mjs.map +1 -1
  34. package/dist/core/bootstrap.cjs +1 -39
  35. package/dist/core/bootstrap.mjs +1 -39
  36. package/dist/core/bootstrap.mjs.map +1 -1
  37. package/dist/core/config.cjs +1 -6
  38. package/dist/core/config.mjs +1 -5
  39. package/dist/core/config.mjs.map +1 -1
  40. package/dist/core/config.server.cjs +1 -60
  41. package/dist/core/config.server.mjs +1 -56
  42. package/dist/core/config.server.mjs.map +1 -1
  43. package/dist/core/event-bus.cjs +1 -48
  44. package/dist/core/event-bus.d.cts.map +1 -1
  45. package/dist/core/event-bus.d.mts.map +1 -1
  46. package/dist/core/event-bus.mjs +1 -47
  47. package/dist/core/event-bus.mjs.map +1 -1
  48. package/dist/core/filesystem/index.cjs +1 -11
  49. package/dist/core/filesystem/index.mjs +1 -12
  50. package/dist/core/filesystem/index.mjs.map +1 -1
  51. package/dist/core/filesystem/providers/local.cjs +1 -43
  52. package/dist/core/filesystem/providers/local.mjs +1 -40
  53. package/dist/core/filesystem/providers/local.mjs.map +1 -1
  54. package/dist/core/filesystem/service.cjs +1 -43
  55. package/dist/core/filesystem/service.mjs +1 -42
  56. package/dist/core/filesystem/service.mjs.map +1 -1
  57. package/dist/core/notifications/actions.cjs +1 -36
  58. package/dist/core/notifications/actions.mjs +1 -32
  59. package/dist/core/notifications/actions.mjs.map +1 -1
  60. package/dist/core/notifications/index.cjs +1 -2
  61. package/dist/core/notifications/index.mjs +1 -4
  62. package/dist/core/notifications/service.cjs +1 -30
  63. package/dist/core/notifications/service.mjs +1 -30
  64. package/dist/core/notifications/service.mjs.map +1 -1
  65. package/dist/core/setup.cjs +1 -25
  66. package/dist/core/setup.mjs +1 -24
  67. package/dist/core/setup.mjs.map +1 -1
  68. package/dist/index.cjs +1 -30
  69. package/dist/index.mjs +1 -6
  70. package/dist/server/auth/email.cjs +1 -24
  71. package/dist/server/auth/email.mjs +1 -22
  72. package/dist/server/auth/email.mjs.map +1 -1
  73. package/dist/server/auth/password.cjs +1 -37
  74. package/dist/server/auth/password.mjs +1 -33
  75. package/dist/server/auth/password.mjs.map +1 -1
  76. package/dist/server/auth/user.cjs +1 -165
  77. package/dist/server/auth/user.mjs +1 -152
  78. package/dist/server/auth/user.mjs.map +1 -1
  79. package/dist/server/database/inject.cjs +1 -24
  80. package/dist/server/database/inject.mjs +1 -22
  81. package/dist/server/database/inject.mjs.map +1 -1
  82. package/dist/server/database/schema.cjs +1 -163
  83. package/dist/server/database/schema.mjs +1 -150
  84. package/dist/server/database/schema.mjs.map +1 -1
  85. package/dist/server/emails/index.cjs +1 -32
  86. package/dist/server/emails/index.mjs +1 -28
  87. package/dist/server/emails/index.mjs.map +1 -1
  88. package/dist/server.cjs +1 -145
  89. package/dist/server.mjs +1 -23
  90. package/package.json +1 -1
@@ -1,33 +1,2 @@
1
- "use server";
2
-
3
- import { db } from "../../server/database/inject.mjs";
4
- import { notificationTable } from "../../server/database/schema.mjs";
5
- import { getCurrentSession } from "../auth/session.mjs";
6
- import { desc, eq } from "drizzle-orm";
7
-
8
- //#region src/core/notifications/actions.ts
9
- async function getUserNotifications() {
10
- const { user } = await getCurrentSession();
11
- if (!user) return null;
12
- return await db.select().from(notificationTable).where(eq(notificationTable.userId, user.id)).orderBy(desc(notificationTable.createdAt));
13
- }
14
- async function createNotification(data) {
15
- const [notification] = await db.insert(notificationTable).values({
16
- ...data,
17
- isRead: false
18
- }).returning();
19
- return notification;
20
- }
21
- async function markNotificationAsRead(id) {
22
- const [updated] = await db.update(notificationTable).set({ isRead: true }).where(eq(notificationTable.id, id)).returning();
23
- return updated;
24
- }
25
- async function markAllNotificationsAsRead() {
26
- const { user } = await getCurrentSession();
27
- if (!user) return null;
28
- return await db.update(notificationTable).set({ isRead: true }).where(eq(notificationTable.userId, user.id)).returning();
29
- }
30
-
31
- //#endregion
32
- export { createNotification, getUserNotifications, markAllNotificationsAsRead, markNotificationAsRead };
1
+ "use server";import{db as e}from"../../server/database/inject.mjs";import{notificationTable as t}from"../../server/database/schema.mjs";import{getCurrentSession as n}from"../auth/session.mjs";import{desc as r,eq as i}from"drizzle-orm";async function a(){let{user:a}=await n();return a?await e.select().from(t).where(i(t.userId,a.id)).orderBy(r(t.createdAt)):null}async function o(n){let[r]=await e.insert(t).values({...n,isRead:!1}).returning();return r}async function s(n){let[r]=await e.update(t).set({isRead:!0}).where(i(t.id,n)).returning();return r}async function c(){let{user:r}=await n();return r?await e.update(t).set({isRead:!0}).where(i(t.userId,r.id)).returning():null}export{o as createNotification,a as getUserNotifications,c as markAllNotificationsAsRead,s as markNotificationAsRead};
33
2
  //# sourceMappingURL=actions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.mjs","names":[],"sources":["../../../src/core/notifications/actions.ts"],"sourcesContent":["\"use server\";\n\nimport { desc, eq } from \"drizzle-orm\";\nimport { db } from \"../../server/database/inject\";\nimport { notificationTable } from \"../../server/database/schema\";\nimport { getCurrentSession } from \"../auth/session\";\nimport type { CreateNotificationPayload } from \"./types\";\n\nexport async function getUserNotifications() {\n const { user } = await getCurrentSession();\n if (!user) return null;\n\n return await db\n .select()\n .from(notificationTable)\n .where(eq(notificationTable.userId, user.id))\n .orderBy(desc(notificationTable.createdAt));\n}\n\nexport async function createNotification(data: CreateNotificationPayload) {\n const [notification] = await db\n .insert(notificationTable)\n .values({\n ...data,\n isRead: false,\n })\n .returning();\n\n return notification;\n}\n\nexport async function markNotificationAsRead(id: string) {\n const [updated] = await db\n .update(notificationTable)\n .set({ isRead: true })\n .where(eq(notificationTable.id, id))\n .returning();\n\n return updated;\n}\n\nexport async function markAllNotificationsAsRead() {\n const { user } = await getCurrentSession();\n if (!user) return null;\n\n return await db\n .update(notificationTable)\n .set({ isRead: true })\n .where(eq(notificationTable.userId, user.id))\n .returning();\n}\n"],"mappings":";;;;;;;;AAQA,eAAsB,uBAAuB;CAC3C,MAAM,EAAE,SAAS,MAAM,mBAAmB;AAC1C,KAAI,CAAC,KAAM,QAAO;AAElB,QAAO,MAAM,GACV,QAAQ,CACR,KAAK,kBAAkB,CACvB,MAAM,GAAG,kBAAkB,QAAQ,KAAK,GAAG,CAAC,CAC5C,QAAQ,KAAK,kBAAkB,UAAU,CAAC;;AAG/C,eAAsB,mBAAmB,MAAiC;CACxE,MAAM,CAAC,gBAAgB,MAAM,GAC1B,OAAO,kBAAkB,CACzB,OAAO;EACN,GAAG;EACH,QAAQ;EACT,CAAC,CACD,WAAW;AAEd,QAAO;;AAGT,eAAsB,uBAAuB,IAAY;CACvD,MAAM,CAAC,WAAW,MAAM,GACrB,OAAO,kBAAkB,CACzB,IAAI,EAAE,QAAQ,MAAM,CAAC,CACrB,MAAM,GAAG,kBAAkB,IAAI,GAAG,CAAC,CACnC,WAAW;AAEd,QAAO;;AAGT,eAAsB,6BAA6B;CACjD,MAAM,EAAE,SAAS,MAAM,mBAAmB;AAC1C,KAAI,CAAC,KAAM,QAAO;AAElB,QAAO,MAAM,GACV,OAAO,kBAAkB,CACzB,IAAI,EAAE,QAAQ,MAAM,CAAC,CACrB,MAAM,GAAG,kBAAkB,QAAQ,KAAK,GAAG,CAAC,CAC5C,WAAW"}
1
+ {"version":3,"file":"actions.mjs","names":[],"sources":["../../../src/core/notifications/actions.ts"],"sourcesContent":["\"use server\";\n\nimport { desc, eq } from \"drizzle-orm\";\nimport { db } from \"../../server/database/inject.js\";\nimport { notificationTable } from \"../../server/database/schema.js\";\nimport { getCurrentSession } from \"../auth/session.js\";\nimport type { CreateNotificationPayload } from \"./types.js\";\n\nexport async function getUserNotifications() {\n const { user } = await getCurrentSession();\n if (!user) return null;\n\n return await db\n .select()\n .from(notificationTable)\n .where(eq(notificationTable.userId, user.id))\n .orderBy(desc(notificationTable.createdAt));\n}\n\nexport async function createNotification(data: CreateNotificationPayload) {\n const [notification] = await db\n .insert(notificationTable)\n .values({\n ...data,\n isRead: false,\n })\n .returning();\n\n return notification;\n}\n\nexport async function markNotificationAsRead(id: string) {\n const [updated] = await db\n .update(notificationTable)\n .set({ isRead: true })\n .where(eq(notificationTable.id, id))\n .returning();\n\n return updated;\n}\n\nexport async function markAllNotificationsAsRead() {\n const { user } = await getCurrentSession();\n if (!user) return null;\n\n return await db\n .update(notificationTable)\n .set({ isRead: true })\n .where(eq(notificationTable.userId, user.id))\n .returning();\n}\n"],"mappings":"2OAQA,eAAsB,GAAuB,CAC3C,GAAM,CAAE,QAAS,MAAM,GAAmB,CAG1C,OAFK,EAEE,MAAM,EACV,QAAQ,CACR,KAAK,EAAkB,CACvB,MAAM,EAAG,EAAkB,OAAQ,EAAK,GAAG,CAAC,CAC5C,QAAQ,EAAK,EAAkB,UAAU,CAAC,CAN3B,KASpB,eAAsB,EAAmB,EAAiC,CACxE,GAAM,CAAC,GAAgB,MAAM,EAC1B,OAAO,EAAkB,CACzB,OAAO,CACN,GAAG,EACH,OAAQ,GACT,CAAC,CACD,WAAW,CAEd,OAAO,EAGT,eAAsB,EAAuB,EAAY,CACvD,GAAM,CAAC,GAAW,MAAM,EACrB,OAAO,EAAkB,CACzB,IAAI,CAAE,OAAQ,GAAM,CAAC,CACrB,MAAM,EAAG,EAAkB,GAAI,EAAG,CAAC,CACnC,WAAW,CAEd,OAAO,EAGT,eAAsB,GAA6B,CACjD,GAAM,CAAE,QAAS,MAAM,GAAmB,CAG1C,OAFK,EAEE,MAAM,EACV,OAAO,EAAkB,CACzB,IAAI,CAAE,OAAQ,GAAM,CAAC,CACrB,MAAM,EAAG,EAAkB,OAAQ,EAAK,GAAG,CAAC,CAC5C,WAAW,CANI"}
@@ -1,2 +1 @@
1
- const require_actions = require('./actions.cjs');
2
- const require_service = require('./service.cjs');
1
+ require(`./actions.cjs`),require(`./service.cjs`);
@@ -1,4 +1 @@
1
- import { createNotification, getUserNotifications, markAllNotificationsAsRead, markNotificationAsRead } from "./actions.mjs";
2
- import { notificationService } from "./service.mjs";
3
-
4
- export { };
1
+ import{createNotification as e,getUserNotifications as t,markAllNotificationsAsRead as n,markNotificationAsRead as r}from"./actions.mjs";import{notificationService as i}from"./service.mjs";export{};
@@ -1,30 +1 @@
1
- const require_event_bus = require('../event-bus.cjs');
2
- const require_actions = require('./actions.cjs');
3
-
4
- //#region src/core/notifications/service.ts
5
- var NotificationService = class {
6
- constructor() {
7
- this.initialized = false;
8
- }
9
- init() {
10
- if (this.initialized) return;
11
- console.log("[Notification Service] Subscribing to notification:send...");
12
- require_event_bus.eventBus.subscribe("notification:send", "notification-service", async (event) => {
13
- console.log("[Notification Service] Received notification:send event", event.payload);
14
- try {
15
- const result = await require_actions.createNotification(event.payload);
16
- console.log("[Notification Service] Notification created successfully:", result.id);
17
- } catch (error) {
18
- console.error("[Notification Service] Failed to process notification:send", error);
19
- }
20
- });
21
- this.initialized = true;
22
- console.log("[NotificationService] Initialized and listening for events.");
23
- }
24
- };
25
- const globalForNotifications = globalThis;
26
- const notificationService = globalForNotifications.__KRYO_NOTIFICATION_SERVICE__ ?? new NotificationService();
27
- globalForNotifications.__KRYO_NOTIFICATION_SERVICE__ = notificationService;
28
-
29
- //#endregion
30
- exports.notificationService = notificationService;
1
+ const e=require(`../event-bus.cjs`),t=require(`./actions.cjs`);var n=class{constructor(){this.initialized=!1}init(){this.initialized||(console.log(`[Notification Service] Subscribing to notification:send...`),e.eventBus.subscribe(`notification:send`,`notification-service`,async e=>{console.log(`[Notification Service] Received notification:send event`,e.payload);try{let n=await t.createNotification(e.payload);console.log(`[Notification Service] Notification created successfully:`,n.id)}catch(e){console.error(`[Notification Service] Failed to process notification:send`,e)}}),this.initialized=!0,console.log(`[NotificationService] Initialized and listening for events.`))}};const r=globalThis,i=r.__KRYO_NOTIFICATION_SERVICE__??new n;r.__KRYO_NOTIFICATION_SERVICE__=i,exports.notificationService=i;
@@ -1,31 +1,2 @@
1
- import { eventBus } from "../event-bus.mjs";
2
- import { createNotification } from "./actions.mjs";
3
-
4
- //#region src/core/notifications/service.ts
5
- var NotificationService = class {
6
- constructor() {
7
- this.initialized = false;
8
- }
9
- init() {
10
- if (this.initialized) return;
11
- console.log("[Notification Service] Subscribing to notification:send...");
12
- eventBus.subscribe("notification:send", "notification-service", async (event) => {
13
- console.log("[Notification Service] Received notification:send event", event.payload);
14
- try {
15
- const result = await createNotification(event.payload);
16
- console.log("[Notification Service] Notification created successfully:", result.id);
17
- } catch (error) {
18
- console.error("[Notification Service] Failed to process notification:send", error);
19
- }
20
- });
21
- this.initialized = true;
22
- console.log("[NotificationService] Initialized and listening for events.");
23
- }
24
- };
25
- const globalForNotifications = globalThis;
26
- const notificationService = globalForNotifications.__KRYO_NOTIFICATION_SERVICE__ ?? new NotificationService();
27
- globalForNotifications.__KRYO_NOTIFICATION_SERVICE__ = notificationService;
28
-
29
- //#endregion
30
- export { notificationService };
1
+ import{eventBus as e}from"../event-bus.mjs";import{createNotification as t}from"./actions.mjs";var n=class{constructor(){this.initialized=!1}init(){this.initialized||(console.log(`[Notification Service] Subscribing to notification:send...`),e.subscribe(`notification:send`,`notification-service`,async e=>{console.log(`[Notification Service] Received notification:send event`,e.payload);try{let n=await t(e.payload);console.log(`[Notification Service] Notification created successfully:`,n.id)}catch(e){console.error(`[Notification Service] Failed to process notification:send`,e)}}),this.initialized=!0,console.log(`[NotificationService] Initialized and listening for events.`))}};const r=globalThis,i=r.__KRYO_NOTIFICATION_SERVICE__??new n;r.__KRYO_NOTIFICATION_SERVICE__=i;export{i as notificationService};
31
2
  //# sourceMappingURL=service.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.mjs","names":[],"sources":["../../../src/core/notifications/service.ts"],"sourcesContent":["import { eventBus } from \"../event-bus\";\nimport { createNotification } from \"./actions\";\nimport type { CreateNotificationPayload } from \"./types\";\n\nclass NotificationService {\n private initialized = false;\n\n public init() {\n if (this.initialized) {\n // console.log(\"[Notification Service] Already initialized.\");\n return;\n }\n\n console.log(\"[Notification Service] Subscribing to notification:send...\");\n\n eventBus.subscribe(\n \"notification:send\",\n \"notification-service\",\n async (event) => {\n console.log(\n \"[Notification Service] Received notification:send event\",\n event.payload,\n );\n try {\n // const { createNotification } = await import(\"./actions\");\n const result = await createNotification(\n event.payload as CreateNotificationPayload,\n );\n console.log(\n \"[Notification Service] Notification created successfully:\",\n result.id,\n );\n } catch (error) {\n console.error(\n \"[Notification Service] Failed to process notification:send\",\n error,\n );\n }\n },\n );\n\n this.initialized = true;\n console.log(\"[NotificationService] Initialized and listening for events.\");\n }\n}\n\n// Global Singleton Pattern\nconst globalForNotifications = globalThis as unknown as {\n __KRYO_NOTIFICATION_SERVICE__: NotificationService | undefined;\n};\n\nexport const notificationService =\n globalForNotifications.__KRYO_NOTIFICATION_SERVICE__ ??\n new NotificationService();\n\nglobalForNotifications.__KRYO_NOTIFICATION_SERVICE__ = notificationService;\n"],"mappings":";;;;AAIA,IAAM,sBAAN,MAA0B;;qBACF;;CAEtB,AAAO,OAAO;AACZ,MAAI,KAAK,YAEP;AAGF,UAAQ,IAAI,6DAA6D;AAEzE,WAAS,UACP,qBACA,wBACA,OAAO,UAAU;AACf,WAAQ,IACN,2DACA,MAAM,QACP;AACD,OAAI;IAEF,MAAM,SAAS,MAAM,mBACnB,MAAM,QACP;AACD,YAAQ,IACN,6DACA,OAAO,GACR;YACM,OAAO;AACd,YAAQ,MACN,8DACA,MACD;;IAGN;AAED,OAAK,cAAc;AACnB,UAAQ,IAAI,8DAA8D;;;AAK9E,MAAM,yBAAyB;AAI/B,MAAa,sBACX,uBAAuB,iCACvB,IAAI,qBAAqB;AAE3B,uBAAuB,gCAAgC"}
1
+ {"version":3,"file":"service.mjs","names":[],"sources":["../../../src/core/notifications/service.ts"],"sourcesContent":["import { eventBus } from \"../event-bus.js\";\nimport { createNotification } from \"./actions.js\";\nimport type { CreateNotificationPayload } from \"./types.js\";\n\nclass NotificationService {\n private initialized = false;\n\n public init() {\n if (this.initialized) {\n // console.log(\"[Notification Service] Already initialized.\");\n return;\n }\n\n console.log(\"[Notification Service] Subscribing to notification:send...\");\n\n eventBus.subscribe(\n \"notification:send\",\n \"notification-service\",\n async (event) => {\n console.log(\n \"[Notification Service] Received notification:send event\",\n event.payload,\n );\n try {\n // const { createNotification } = await import(\"./actions\");\n const result = await createNotification(\n event.payload as CreateNotificationPayload,\n );\n console.log(\n \"[Notification Service] Notification created successfully:\",\n result.id,\n );\n } catch (error) {\n console.error(\n \"[Notification Service] Failed to process notification:send\",\n error,\n );\n }\n },\n );\n\n this.initialized = true;\n console.log(\"[NotificationService] Initialized and listening for events.\");\n }\n}\n\n// Global Singleton Pattern\nconst globalForNotifications = globalThis as unknown as {\n __KRYO_NOTIFICATION_SERVICE__: NotificationService | undefined;\n};\n\nexport const notificationService =\n globalForNotifications.__KRYO_NOTIFICATION_SERVICE__ ??\n new NotificationService();\n\nglobalForNotifications.__KRYO_NOTIFICATION_SERVICE__ = notificationService;\n"],"mappings":"+FAIA,IAAM,EAAN,KAA0B,gCACF,GAEtB,MAAc,CACR,KAAK,cAKT,QAAQ,IAAI,6DAA6D,CAEzE,EAAS,UACP,oBACA,uBACA,KAAO,IAAU,CACf,QAAQ,IACN,0DACA,EAAM,QACP,CACD,GAAI,CAEF,IAAM,EAAS,MAAM,EACnB,EAAM,QACP,CACD,QAAQ,IACN,4DACA,EAAO,GACR,OACM,EAAO,CACd,QAAQ,MACN,6DACA,EACD,GAGN,CAED,KAAK,YAAc,GACnB,QAAQ,IAAI,8DAA8D,IAK9E,MAAM,EAAyB,WAIlB,EACX,EAAuB,+BACvB,IAAI,EAEN,EAAuB,8BAAgC"}
@@ -1,25 +1 @@
1
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
- const require_inject = require('../server/database/inject.cjs');
3
- const require_schema = require('../server/database/schema.cjs');
4
- let drizzle_orm = require("drizzle-orm");
5
-
6
- //#region src/core/setup.ts
7
- /**
8
- * Checks if the system is installed.
9
- * A system is considered installed if at least one user exists in the database.
10
- */
11
- async function isSystemInstalled() {
12
- try {
13
- console.log("[Kernel:Setup] Checking if system is installed...");
14
- const result = await require_inject.db.select({ count: drizzle_orm.sql`count(*)` }).from(require_schema.userTable);
15
- const count = Number(result[0]?.count || 0);
16
- console.log(`[Kernel:Setup] User count: ${count}`);
17
- return count > 0;
18
- } catch (error) {
19
- console.log(`[Kernel:Setup] System not installed or error: ${error.message}`);
20
- return false;
21
- }
22
- }
23
-
24
- //#endregion
25
- exports.isSystemInstalled = isSystemInstalled;
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../server/database/inject.cjs`),t=require(`../server/database/schema.cjs`);let n=require(`drizzle-orm`);async function r(){try{console.log(`[Kernel:Setup] Checking if system is installed...`);let r=await e.db.select({count:n.sql`count(*)`}).from(t.userTable),i=Number(r[0]?.count||0);return console.log(`[Kernel:Setup] User count: ${i}`),i>0}catch(e){return console.log(`[Kernel:Setup] System not installed or error: ${e.message}`),!1}}exports.isSystemInstalled=r;
@@ -1,25 +1,2 @@
1
- import { db } from "../server/database/inject.mjs";
2
- import { userTable } from "../server/database/schema.mjs";
3
- import { sql } from "drizzle-orm";
4
-
5
- //#region src/core/setup.ts
6
- /**
7
- * Checks if the system is installed.
8
- * A system is considered installed if at least one user exists in the database.
9
- */
10
- async function isSystemInstalled() {
11
- try {
12
- console.log("[Kernel:Setup] Checking if system is installed...");
13
- const result = await db.select({ count: sql`count(*)` }).from(userTable);
14
- const count = Number(result[0]?.count || 0);
15
- console.log(`[Kernel:Setup] User count: ${count}`);
16
- return count > 0;
17
- } catch (error) {
18
- console.log(`[Kernel:Setup] System not installed or error: ${error.message}`);
19
- return false;
20
- }
21
- }
22
-
23
- //#endregion
24
- export { isSystemInstalled };
1
+ import{db as e}from"../server/database/inject.mjs";import{userTable as t}from"../server/database/schema.mjs";import{sql as n}from"drizzle-orm";async function r(){try{console.log(`[Kernel:Setup] Checking if system is installed...`);let r=await e.select({count:n`count(*)`}).from(t),i=Number(r[0]?.count||0);return console.log(`[Kernel:Setup] User count: ${i}`),i>0}catch(e){return console.log(`[Kernel:Setup] System not installed or error: ${e.message}`),!1}}export{r as isSystemInstalled};
25
2
  //# sourceMappingURL=setup.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup.mjs","names":[],"sources":["../../src/core/setup.ts"],"sourcesContent":["import { sql } from \"drizzle-orm\";\nimport { db } from \"../server/database/inject\";\nimport { userTable } from \"../server/database/schema\";\n\n/**\n * Checks if the system is installed.\n * A system is considered installed if at least one user exists in the database.\n */\nexport async function isSystemInstalled(): Promise<boolean> {\n try {\n // We check if the users table exists and has at least one record\n console.log(\"[Kernel:Setup] Checking if system is installed...\");\n const result = await db\n .select({ count: sql<string | number>`count(*)` })\n .from(userTable);\n const count = Number(result[0]?.count || 0);\n console.log(`[Kernel:Setup] User count: ${count}`);\n return count > 0;\n } catch (error: any) {\n console.log(\n `[Kernel:Setup] System not installed or error: ${error.message}`,\n );\n // If table doesn't exist, it's definitely not installed\n return false;\n }\n}\n"],"mappings":";;;;;;;;;AAQA,eAAsB,oBAAsC;AAC1D,KAAI;AAEF,UAAQ,IAAI,oDAAoD;EAChE,MAAM,SAAS,MAAM,GAClB,OAAO,EAAE,OAAO,GAAoB,YAAY,CAAC,CACjD,KAAK,UAAU;EAClB,MAAM,QAAQ,OAAO,OAAO,IAAI,SAAS,EAAE;AAC3C,UAAQ,IAAI,8BAA8B,QAAQ;AAClD,SAAO,QAAQ;UACR,OAAY;AACnB,UAAQ,IACN,iDAAiD,MAAM,UACxD;AAED,SAAO"}
1
+ {"version":3,"file":"setup.mjs","names":[],"sources":["../../src/core/setup.ts"],"sourcesContent":["import { sql } from \"drizzle-orm\";\nimport { db } from \"../server/database/inject.js\";\nimport { userTable } from \"../server/database/schema.js\";\n\n/**\n * Checks if the system is installed.\n * A system is considered installed if at least one user exists in the database.\n */\nexport async function isSystemInstalled(): Promise<boolean> {\n try {\n // We check if the users table exists and has at least one record\n console.log(\"[Kernel:Setup] Checking if system is installed...\");\n const result = await db\n .select({ count: sql<string | number>`count(*)` })\n .from(userTable);\n const count = Number(result[0]?.count || 0);\n console.log(`[Kernel:Setup] User count: ${count}`);\n return count > 0;\n } catch (error: any) {\n console.log(\n `[Kernel:Setup] System not installed or error: ${error.message}`,\n );\n // If table doesn't exist, it's definitely not installed\n return false;\n }\n}\n"],"mappings":"+IAQA,eAAsB,GAAsC,CAC1D,GAAI,CAEF,QAAQ,IAAI,oDAAoD,CAChE,IAAM,EAAS,MAAM,EAClB,OAAO,CAAE,MAAO,CAAoB,WAAY,CAAC,CACjD,KAAK,EAAU,CACZ,EAAQ,OAAO,EAAO,IAAI,OAAS,EAAE,CAE3C,OADA,QAAQ,IAAI,8BAA8B,IAAQ,CAC3C,EAAQ,QACR,EAAY,CAKnB,OAJA,QAAQ,IACN,iDAAiD,EAAM,UACxD,CAEM"}
package/dist/index.cjs CHANGED
@@ -1,30 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_validation = require('./core/auth/validation.cjs');
3
- const require_event_bus = require('./core/event-bus.cjs');
4
- const require_schema = require('./server/database/schema.cjs');
5
- const require_service = require('./core/notifications/service.cjs');
6
-
7
- exports.coreSchema = require_schema.coreSchema;
8
- exports.emailVerificationTable = require_schema.emailVerificationTable;
9
- exports.eventBus = require_event_bus.eventBus;
10
- exports.forgotPasswordSchema = require_validation.forgotPasswordSchema;
11
- exports.loginSchema = require_validation.loginSchema;
12
- exports.notificationService = require_service.notificationService;
13
- exports.notificationTable = require_schema.notificationTable;
14
- exports.passkeysSetupSchema = require_validation.passkeysSetupSchema;
15
- exports.passwordResetSessionTable = require_schema.passwordResetSessionTable;
16
- exports.permissionsTable = require_schema.permissionsTable;
17
- exports.recoveryCodeVerifySchema = require_validation.recoveryCodeVerifySchema;
18
- exports.registerSchema = require_validation.registerSchema;
19
- exports.relations = require_schema.relations;
20
- exports.resetPasswordSchema = require_validation.resetPasswordSchema;
21
- exports.rolesTable = require_schema.rolesTable;
22
- exports.rolesToPermissionsTable = require_schema.rolesToPermissionsTable;
23
- exports.sessionTable = require_schema.sessionTable;
24
- exports.systemModulesTable = require_schema.systemModulesTable;
25
- exports.totpSetupSchema = require_validation.totpSetupSchema;
26
- exports.totpVerifySchema = require_validation.totpVerifySchema;
27
- exports.userTable = require_schema.userTable;
28
- exports.usersToPermissionsTable = require_schema.usersToPermissionsTable;
29
- exports.usersToRolesTable = require_schema.usersToRolesTable;
30
- exports.verifyEmailSchema = require_validation.verifyEmailSchema;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./core/auth/validation.cjs`),t=require(`./core/event-bus.cjs`),n=require(`./server/database/schema.cjs`),r=require(`./core/notifications/service.cjs`);exports.coreSchema=n.coreSchema,exports.emailVerificationTable=n.emailVerificationTable,exports.eventBus=t.eventBus,exports.forgotPasswordSchema=e.forgotPasswordSchema,exports.loginSchema=e.loginSchema,exports.notificationService=r.notificationService,exports.notificationTable=n.notificationTable,exports.passkeysSetupSchema=e.passkeysSetupSchema,exports.passwordResetSessionTable=n.passwordResetSessionTable,exports.permissionsTable=n.permissionsTable,exports.recoveryCodeVerifySchema=e.recoveryCodeVerifySchema,exports.registerSchema=e.registerSchema,exports.relations=n.relations,exports.resetPasswordSchema=e.resetPasswordSchema,exports.rolesTable=n.rolesTable,exports.rolesToPermissionsTable=n.rolesToPermissionsTable,exports.sessionTable=n.sessionTable,exports.systemModulesTable=n.systemModulesTable,exports.totpSetupSchema=e.totpSetupSchema,exports.totpVerifySchema=e.totpVerifySchema,exports.userTable=n.userTable,exports.usersToPermissionsTable=n.usersToPermissionsTable,exports.usersToRolesTable=n.usersToRolesTable,exports.verifyEmailSchema=e.verifyEmailSchema;
package/dist/index.mjs CHANGED
@@ -1,6 +1 @@
1
- import { forgotPasswordSchema, loginSchema, passkeysSetupSchema, recoveryCodeVerifySchema, registerSchema, resetPasswordSchema, totpSetupSchema, totpVerifySchema, verifyEmailSchema } from "./core/auth/validation.mjs";
2
- import { eventBus } from "./core/event-bus.mjs";
3
- import { coreSchema, emailVerificationTable, notificationTable, passwordResetSessionTable, permissionsTable, relations, rolesTable, rolesToPermissionsTable, sessionTable, systemModulesTable, userTable, usersToPermissionsTable, usersToRolesTable } from "./server/database/schema.mjs";
4
- import { notificationService } from "./core/notifications/service.mjs";
5
-
6
- export { coreSchema, emailVerificationTable, eventBus, forgotPasswordSchema, loginSchema, notificationService, notificationTable, passkeysSetupSchema, passwordResetSessionTable, permissionsTable, recoveryCodeVerifySchema, registerSchema, relations, resetPasswordSchema, rolesTable, rolesToPermissionsTable, sessionTable, systemModulesTable, totpSetupSchema, totpVerifySchema, userTable, usersToPermissionsTable, usersToRolesTable, verifyEmailSchema };
1
+ import{forgotPasswordSchema as e,loginSchema as t,passkeysSetupSchema as n,recoveryCodeVerifySchema as r,registerSchema as i,resetPasswordSchema as a,totpSetupSchema as o,totpVerifySchema as s,verifyEmailSchema as c}from"./core/auth/validation.mjs";import{eventBus as l}from"./core/event-bus.mjs";import{coreSchema as u,emailVerificationTable as d,notificationTable as f,passwordResetSessionTable as p,permissionsTable as m,relations as h,rolesTable as g,rolesToPermissionsTable as _,sessionTable as v,systemModulesTable as y,userTable as b,usersToPermissionsTable as x,usersToRolesTable as S}from"./server/database/schema.mjs";import{notificationService as C}from"./core/notifications/service.mjs";export{u as coreSchema,d as emailVerificationTable,l as eventBus,e as forgotPasswordSchema,t as loginSchema,C as notificationService,f as notificationTable,n as passkeysSetupSchema,p as passwordResetSessionTable,m as permissionsTable,r as recoveryCodeVerifySchema,i as registerSchema,h as relations,a as resetPasswordSchema,g as rolesTable,_ as rolesToPermissionsTable,v as sessionTable,y as systemModulesTable,o as totpSetupSchema,s as totpVerifySchema,b as userTable,x as usersToPermissionsTable,S as usersToRolesTable,c as verifyEmailSchema};
@@ -1,24 +1 @@
1
- const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
2
- const require_inject = require('../database/inject.cjs');
3
- const require_schema = require('../database/schema.cjs');
4
- let drizzle_orm = require("drizzle-orm");
5
-
6
- //#region src/server/auth/email.ts
7
- /**
8
- * Validates the email format and length.
9
- */
10
- function verifyEmailInput(email) {
11
- return /^.+@.+\..+$/.test(email) && email.length < 256 && email.length > 0;
12
- }
13
- /**
14
- * Checks if an email address is already in use.
15
- * @returns True if the email is available, false otherwise.
16
- */
17
- async function checkEmailAvailability(email) {
18
- const [entries] = await require_inject.db.select({ count: (0, drizzle_orm.count)() }).from(require_schema.userTable).where((0, drizzle_orm.eq)(require_schema.userTable.email, email));
19
- return entries.count === 0;
20
- }
21
-
22
- //#endregion
23
- exports.checkEmailAvailability = checkEmailAvailability;
24
- exports.verifyEmailInput = verifyEmailInput;
1
+ require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../database/inject.cjs`),t=require(`../database/schema.cjs`);let n=require(`drizzle-orm`);function r(e){return/^.+@.+\..+$/.test(e)&&e.length<256&&e.length>0}async function i(r){let[i]=await e.db.select({count:(0,n.count)()}).from(t.userTable).where((0,n.eq)(t.userTable.email,r));return i.count===0}exports.checkEmailAvailability=i,exports.verifyEmailInput=r;
@@ -1,23 +1,2 @@
1
- import { db } from "../database/inject.mjs";
2
- import { userTable } from "../database/schema.mjs";
3
- import { count, eq } from "drizzle-orm";
4
-
5
- //#region src/server/auth/email.ts
6
- /**
7
- * Validates the email format and length.
8
- */
9
- function verifyEmailInput(email) {
10
- return /^.+@.+\..+$/.test(email) && email.length < 256 && email.length > 0;
11
- }
12
- /**
13
- * Checks if an email address is already in use.
14
- * @returns True if the email is available, false otherwise.
15
- */
16
- async function checkEmailAvailability(email) {
17
- const [entries] = await db.select({ count: count() }).from(userTable).where(eq(userTable.email, email));
18
- return entries.count === 0;
19
- }
20
-
21
- //#endregion
22
- export { checkEmailAvailability, verifyEmailInput };
1
+ import{db as e}from"../database/inject.mjs";import{userTable as t}from"../database/schema.mjs";import{count as n,eq as r}from"drizzle-orm";function i(e){return/^.+@.+\..+$/.test(e)&&e.length<256&&e.length>0}async function a(i){let[a]=await e.select({count:n()}).from(t).where(r(t.email,i));return a.count===0}export{a as checkEmailAvailability,i as verifyEmailInput};
23
2
  //# sourceMappingURL=email.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"email.mjs","names":[],"sources":["../../../src/server/auth/email.ts"],"sourcesContent":["import { count, eq } from \"drizzle-orm\";\nimport { db } from \"../database/inject\";\nimport { userTable } from \"../database/schema\";\n\n/**\n * Validates the email format and length.\n */\nexport function verifyEmailInput(email: string): boolean {\n return /^.+@.+\\..+$/.test(email) && email.length < 256 && email.length > 0;\n}\n\n/**\n * Checks if an email address is already in use.\n * @returns True if the email is available, false otherwise.\n */\nexport async function checkEmailAvailability(email: string): Promise<boolean> {\n const [entries] = await db\n .select({ count: count() })\n .from(userTable)\n .where(eq(userTable.email, email));\n\n return entries.count === 0;\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,iBAAiB,OAAwB;AACvD,QAAO,cAAc,KAAK,MAAM,IAAI,MAAM,SAAS,OAAO,MAAM,SAAS;;;;;;AAO3E,eAAsB,uBAAuB,OAAiC;CAC5E,MAAM,CAAC,WAAW,MAAM,GACrB,OAAO,EAAE,OAAO,OAAO,EAAE,CAAC,CAC1B,KAAK,UAAU,CACf,MAAM,GAAG,UAAU,OAAO,MAAM,CAAC;AAEpC,QAAO,QAAQ,UAAU"}
1
+ {"version":3,"file":"email.mjs","names":[],"sources":["../../../src/server/auth/email.ts"],"sourcesContent":["import { count, eq } from \"drizzle-orm\";\nimport { db } from \"../database/inject.js\";\nimport { userTable } from \"../database/schema.js\";\n\n/**\n * Validates the email format and length.\n */\nexport function verifyEmailInput(email: string): boolean {\n return /^.+@.+\\..+$/.test(email) && email.length < 256 && email.length > 0;\n}\n\n/**\n * Checks if an email address is already in use.\n * @returns True if the email is available, false otherwise.\n */\nexport async function checkEmailAvailability(email: string): Promise<boolean> {\n const [entries] = await db\n .select({ count: count() })\n .from(userTable)\n .where(eq(userTable.email, email));\n\n return entries.count === 0;\n}\n"],"mappings":"2IAOA,SAAgB,EAAiB,EAAwB,CACvD,MAAO,cAAc,KAAK,EAAM,EAAI,EAAM,OAAS,KAAO,EAAM,OAAS,EAO3E,eAAsB,EAAuB,EAAiC,CAC5E,GAAM,CAAC,GAAW,MAAM,EACrB,OAAO,CAAE,MAAO,GAAO,CAAE,CAAC,CAC1B,KAAK,EAAU,CACf,MAAM,EAAG,EAAU,MAAO,EAAM,CAAC,CAEpC,OAAO,EAAQ,QAAU"}
@@ -1,37 +1 @@
1
- "use server";
2
-
3
- const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
4
- let bcryptjs = require("bcryptjs");
5
- bcryptjs = require_runtime.__toESM(bcryptjs);
6
-
7
- //#region src/server/auth/password.ts
8
- /**
9
- * Hashes the password using bcrypt.
10
- * @param password Password to be hashed.
11
- * @returns Returns the hashed password.
12
- */
13
- async function hashPassword(password) {
14
- return await bcryptjs.default.hash(password, 10);
15
- }
16
- /**
17
- * Verifies the password hash.
18
- * @param hash bcrypt hash.
19
- * @param password Password for comparison.
20
- * @returns Returns true if the password is correct, false otherwise.
21
- */
22
- async function verifyPasswordHash(hash, password) {
23
- return await bcryptjs.default.compare(password, hash);
24
- }
25
- /**
26
- * Validates password strength.
27
- * @param password Password to validate.
28
- * @returns Returns true if the password meets complexity requirements.
29
- */
30
- async function verifyPasswordStrength(password) {
31
- return password.length >= 8 && password.length <= 255;
32
- }
33
-
34
- //#endregion
35
- exports.hashPassword = hashPassword;
36
- exports.verifyPasswordHash = verifyPasswordHash;
37
- exports.verifyPasswordStrength = verifyPasswordStrength;
1
+ "use server";const e=require(`../../_virtual/_rolldown/runtime.cjs`);let t=require(`bcryptjs`);t=e.__toESM(t);async function n(e){return await t.default.hash(e,10)}async function r(e,n){return await t.default.compare(n,e)}async function i(e){return e.length>=8&&e.length<=255}exports.hashPassword=n,exports.verifyPasswordHash=r,exports.verifyPasswordStrength=i;
@@ -1,34 +1,2 @@
1
- "use server";
2
-
3
- import bcrypt from "bcryptjs";
4
-
5
- //#region src/server/auth/password.ts
6
- /**
7
- * Hashes the password using bcrypt.
8
- * @param password Password to be hashed.
9
- * @returns Returns the hashed password.
10
- */
11
- async function hashPassword(password) {
12
- return await bcrypt.hash(password, 10);
13
- }
14
- /**
15
- * Verifies the password hash.
16
- * @param hash bcrypt hash.
17
- * @param password Password for comparison.
18
- * @returns Returns true if the password is correct, false otherwise.
19
- */
20
- async function verifyPasswordHash(hash, password) {
21
- return await bcrypt.compare(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
- async function verifyPasswordStrength(password) {
29
- return password.length >= 8 && password.length <= 255;
30
- }
31
-
32
- //#endregion
33
- export { hashPassword, verifyPasswordHash, verifyPasswordStrength };
1
+ "use server";import e from"bcryptjs";async function t(t){return await e.hash(t,10)}async function n(t,n){return await e.compare(n,t)}async function r(e){return e.length>=8&&e.length<=255}export{t as hashPassword,n as verifyPasswordHash,r as verifyPasswordStrength};
34
2
  //# sourceMappingURL=password.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"password.mjs","names":[],"sources":["../../../src/server/auth/password.ts"],"sourcesContent":["\"use server\";\n\nimport bcrypt from \"bcryptjs\";\n\n/**\n * Hashes the password using bcrypt.\n * @param password Password to be hashed.\n * @returns Returns the hashed password.\n */\nexport async function hashPassword(password: string): Promise<string> {\n const saltRounds = 10;\n return await bcrypt.hash(password, saltRounds);\n // return password;\n}\n\n/**\n * Verifies the password hash.\n * @param hash bcrypt hash.\n * @param password Password for comparison.\n * @returns Returns true if the password is correct, false otherwise.\n */\nexport async function verifyPasswordHash(\n hash: string,\n password: string,\n): Promise<boolean> {\n return await bcrypt.compare(password, hash);\n // return password === hash;\n}\n\n/**\n * Validates password strength.\n * @param password Password to validate.\n * @returns Returns true if the password meets complexity requirements.\n */\nexport async function verifyPasswordStrength(\n password: string,\n): Promise<boolean> {\n return password.length >= 8 && password.length <= 255;\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,aAAa,UAAmC;AAEpE,QAAO,MAAM,OAAO,KAAK,UADN,GAC2B;;;;;;;;AAUhD,eAAsB,mBACpB,MACA,UACkB;AAClB,QAAO,MAAM,OAAO,QAAQ,UAAU,KAAK;;;;;;;AAS7C,eAAsB,uBACpB,UACkB;AAClB,QAAO,SAAS,UAAU,KAAK,SAAS,UAAU"}
1
+ {"version":3,"file":"password.mjs","names":[],"sources":["../../../src/server/auth/password.ts"],"sourcesContent":["\"use server\";\n\nimport bcrypt from \"bcryptjs\";\n\n/**\n * Hashes the password using bcrypt.\n * @param password Password to be hashed.\n * @returns Returns the hashed password.\n */\nexport async function hashPassword(password: string): Promise<string> {\n const saltRounds = 10;\n return await bcrypt.hash(password, saltRounds);\n // return password;\n}\n\n/**\n * Verifies the password hash.\n * @param hash bcrypt hash.\n * @param password Password for comparison.\n * @returns Returns true if the password is correct, false otherwise.\n */\nexport async function verifyPasswordHash(\n hash: string,\n password: string,\n): Promise<boolean> {\n return await bcrypt.compare(password, hash);\n // return password === hash;\n}\n\n/**\n * Validates password strength.\n * @param password Password to validate.\n * @returns Returns true if the password meets complexity requirements.\n */\nexport async function verifyPasswordStrength(\n password: string,\n): Promise<boolean> {\n return password.length >= 8 && password.length <= 255;\n}\n"],"mappings":"qCASA,eAAsB,EAAa,EAAmC,CAEpE,OAAO,MAAM,EAAO,KAAK,EADN,GAC2B,CAUhD,eAAsB,EACpB,EACA,EACkB,CAClB,OAAO,MAAM,EAAO,QAAQ,EAAU,EAAK,CAS7C,eAAsB,EACpB,EACkB,CAClB,OAAO,EAAS,QAAU,GAAK,EAAS,QAAU"}
@@ -1,165 +1 @@
1
- "use server";
2
-
3
- const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
4
- const require_inject = require('../database/inject.cjs');
5
- const require_schema = require('../database/schema.cjs');
6
- const require_password = require('./password.cjs');
7
- const require_encode = require('../../core/auth/utils/encode.cjs');
8
- const require_encryption = require('../../core/auth/utils/encryption.cjs');
9
- const require_index = require('../emails/index.cjs');
10
- let drizzle_orm = require("drizzle-orm");
11
-
12
- //#region src/server/auth/user.ts
13
- /**
14
- * Validates the username input.
15
- */
16
- async function verifyUsernameInput(username) {
17
- return username.length > 3 && username.length < 32 && username.trim() === username;
18
- }
19
- /**
20
- * Creates a new user with an initial recovery code and default 'user' role.
21
- */
22
- async function createUser(email, username, password) {
23
- const passwordHash = await require_password.hashPassword(password);
24
- const recoveryCode = require_encode.generateRandomRecoveryCode();
25
- const encryptedRecoveryCode = require_encryption.encryptString(recoveryCode);
26
- return await require_inject.db.transaction(async (tx) => {
27
- const [row] = await tx.insert(require_schema.userTable).values({
28
- email,
29
- name: username,
30
- password: passwordHash,
31
- recovery_code: Buffer.from(encryptedRecoveryCode)
32
- }).returning();
33
- if (!row) throw new Error("Failed to create user");
34
- let [role] = await tx.select().from(require_schema.rolesTable).where((0, drizzle_orm.eq)(require_schema.rolesTable.name, "user"));
35
- if (!role) [role] = await tx.insert(require_schema.rolesTable).values({
36
- name: "user",
37
- description: "Default user role"
38
- }).returning();
39
- await tx.insert(require_schema.usersToRolesTable).values({
40
- userId: row.id,
41
- roleId: role.id
42
- });
43
- await /* @__PURE__ */ require_index.sendRecoveryCode(row.email, recoveryCode);
44
- return row;
45
- });
46
- }
47
- /**
48
- * Creates a new user from an OAuth provider.
49
- */
50
- async function createOAuthUser(email, name, image) {
51
- const encryptedRecoveryCode = require_encryption.encryptString(require_encode.generateRandomRecoveryCode());
52
- return await require_inject.db.transaction(async (tx) => {
53
- const [row] = await tx.insert(require_schema.userTable).values({
54
- email,
55
- name,
56
- image,
57
- emailVerifiedAt: /* @__PURE__ */ new Date(),
58
- recovery_code: Buffer.from(encryptedRecoveryCode)
59
- }).returning();
60
- let [role] = await tx.select().from(require_schema.rolesTable).where((0, drizzle_orm.eq)(require_schema.rolesTable.name, "user"));
61
- if (!role) [role] = await tx.insert(require_schema.rolesTable).values({
62
- name: "user",
63
- description: "Default user role"
64
- }).returning();
65
- await tx.insert(require_schema.usersToRolesTable).values({
66
- userId: row.id,
67
- roleId: role.id
68
- });
69
- return row;
70
- });
71
- }
72
- /**
73
- * Returns a user by ID.
74
- */
75
- async function getUserById(userId) {
76
- const [user] = await require_inject.db.select().from(require_schema.userTable).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId));
77
- if (!user) return null;
78
- const { password, recovery_code, ...safeUser } = user;
79
- return safeUser;
80
- }
81
- /**
82
- * Decrypts and returns the user's recovery code.
83
- */
84
- async function getUserRecoverCode(userId) {
85
- const [user] = await require_inject.db.select({ recovery_code: require_schema.userTable.recovery_code }).from(require_schema.userTable).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId));
86
- if (!user || !user.recovery_code) throw new Error("Recovery code not found for user");
87
- return require_encryption.decryptToString(user.recovery_code);
88
- }
89
- /**
90
- * Generates and sets a new recovery code for the user.
91
- */
92
- async function resetUserRecoveryCode(userId) {
93
- const recoveryCode = require_encode.generateRandomRecoveryCode();
94
- const encrypted = require_encryption.encryptString(recoveryCode);
95
- const [currentUser] = await require_inject.db.update(require_schema.userTable).set({ recovery_code: Buffer.from(encrypted) }).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId)).returning();
96
- if (!currentUser) throw new Error("User not found");
97
- await /* @__PURE__ */ require_index.sendRecoveryCode(currentUser.email, recoveryCode);
98
- return recoveryCode;
99
- }
100
- /**
101
- * Updates the user's password.
102
- */
103
- async function updateUserPassword(userId, password) {
104
- const passwordHash = await require_password.hashPassword(password);
105
- await require_inject.db.update(require_schema.userTable).set({ password: passwordHash }).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId));
106
- }
107
- /**
108
- * Updates the user's name.
109
- */
110
- async function updateUserName(userId, name) {
111
- await require_inject.db.update(require_schema.userTable).set({ name }).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId));
112
- }
113
- /**
114
- * Updates the user's image.
115
- */
116
- async function updateUserAwatar(userId, image) {
117
- await require_inject.db.update(require_schema.userTable).set({ image }).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId));
118
- }
119
- /**
120
- * Updates the user's email and marks it as verified.
121
- */
122
- async function updateUserEmailAndSetEmailAsVerified(userId, email) {
123
- await require_inject.db.update(require_schema.userTable).set({
124
- email,
125
- emailVerifiedAt: /* @__PURE__ */ new Date()
126
- }).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId));
127
- }
128
- /**
129
- * Sets the user as email verified if the provided email matches.
130
- */
131
- async function setUserAsEmailVerifiedIfEmailMatches(userId, email) {
132
- return (await require_inject.db.update(require_schema.userTable).set({ emailVerifiedAt: /* @__PURE__ */ new Date() }).where((0, drizzle_orm.and)((0, drizzle_orm.eq)(require_schema.userTable.id, userId), (0, drizzle_orm.eq)(require_schema.userTable.email, email))).returning({ id: require_schema.userTable.id })).length > 0;
133
- }
134
- /**
135
- * Returns the user's password hash.
136
- */
137
- async function getUserPasswordHash(userId) {
138
- const [user] = await require_inject.db.select({ password: require_schema.userTable.password }).from(require_schema.userTable).where((0, drizzle_orm.eq)(require_schema.userTable.id, userId));
139
- if (!user) throw new Error("User not found");
140
- return user.password;
141
- }
142
- /**
143
- * Returns a user by email.
144
- */
145
- async function getUserFromEmail(email) {
146
- const [user] = await require_inject.db.select().from(require_schema.userTable).where((0, drizzle_orm.eq)(require_schema.userTable.email, email));
147
- if (!user) return null;
148
- const { password, recovery_code, ...safeUser } = user;
149
- return safeUser;
150
- }
151
-
152
- //#endregion
153
- exports.createOAuthUser = createOAuthUser;
154
- exports.createUser = createUser;
155
- exports.getUserById = getUserById;
156
- exports.getUserFromEmail = getUserFromEmail;
157
- exports.getUserPasswordHash = getUserPasswordHash;
158
- exports.getUserRecoverCode = getUserRecoverCode;
159
- exports.resetUserRecoveryCode = resetUserRecoveryCode;
160
- exports.setUserAsEmailVerifiedIfEmailMatches = setUserAsEmailVerifiedIfEmailMatches;
161
- exports.updateUserAwatar = updateUserAwatar;
162
- exports.updateUserEmailAndSetEmailAsVerified = updateUserEmailAndSetEmailAsVerified;
163
- exports.updateUserName = updateUserName;
164
- exports.updateUserPassword = updateUserPassword;
165
- exports.verifyUsernameInput = verifyUsernameInput;
1
+ "use server";require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../database/inject.cjs`),t=require(`../database/schema.cjs`),n=require(`./password.cjs`),r=require(`../../core/auth/utils/encode.cjs`),i=require(`../../core/auth/utils/encryption.cjs`),a=require(`../emails/index.cjs`);let o=require(`drizzle-orm`);async function s(e){return e.length>3&&e.length<32&&e.trim()===e}async function c(s,c,l){let u=await n.hashPassword(l),d=r.generateRandomRecoveryCode(),f=i.encryptString(d);return await e.db.transaction(async e=>{let[n]=await e.insert(t.userTable).values({email:s,name:c,password:u,recovery_code:Buffer.from(f)}).returning();if(!n)throw Error(`Failed to create user`);let[r]=await e.select().from(t.rolesTable).where((0,o.eq)(t.rolesTable.name,`user`));return r||([r]=await e.insert(t.rolesTable).values({name:`user`,description:`Default user role`}).returning()),await e.insert(t.usersToRolesTable).values({userId:n.id,roleId:r.id}),await a.sendRecoveryCode(n.email,d),n})}async function l(n,a,s){let c=i.encryptString(r.generateRandomRecoveryCode());return await e.db.transaction(async e=>{let[r]=await e.insert(t.userTable).values({email:n,name:a,image:s,emailVerifiedAt:new Date,recovery_code:Buffer.from(c)}).returning(),[i]=await e.select().from(t.rolesTable).where((0,o.eq)(t.rolesTable.name,`user`));return i||([i]=await e.insert(t.rolesTable).values({name:`user`,description:`Default user role`}).returning()),await e.insert(t.usersToRolesTable).values({userId:r.id,roleId:i.id}),r})}async function u(n){let[r]=await e.db.select().from(t.userTable).where((0,o.eq)(t.userTable.id,n));if(!r)return null;let{password:i,recovery_code:a,...s}=r;return s}async function d(n){let[r]=await e.db.select({recovery_code:t.userTable.recovery_code}).from(t.userTable).where((0,o.eq)(t.userTable.id,n));if(!r||!r.recovery_code)throw Error(`Recovery code not found for user`);return i.decryptToString(r.recovery_code)}async function f(n){let s=r.generateRandomRecoveryCode(),c=i.encryptString(s),[l]=await e.db.update(t.userTable).set({recovery_code:Buffer.from(c)}).where((0,o.eq)(t.userTable.id,n)).returning();if(!l)throw Error(`User not found`);return await a.sendRecoveryCode(l.email,s),s}async function p(r,i){let a=await n.hashPassword(i);await e.db.update(t.userTable).set({password:a}).where((0,o.eq)(t.userTable.id,r))}async function m(n,r){await e.db.update(t.userTable).set({name:r}).where((0,o.eq)(t.userTable.id,n))}async function h(n,r){await e.db.update(t.userTable).set({image:r}).where((0,o.eq)(t.userTable.id,n))}async function g(n,r){await e.db.update(t.userTable).set({email:r,emailVerifiedAt:new Date}).where((0,o.eq)(t.userTable.id,n))}async function _(n,r){return(await e.db.update(t.userTable).set({emailVerifiedAt:new Date}).where((0,o.and)((0,o.eq)(t.userTable.id,n),(0,o.eq)(t.userTable.email,r))).returning({id:t.userTable.id})).length>0}async function v(n){let[r]=await e.db.select({password:t.userTable.password}).from(t.userTable).where((0,o.eq)(t.userTable.id,n));if(!r)throw Error(`User not found`);return r.password}async function y(n){let[r]=await e.db.select().from(t.userTable).where((0,o.eq)(t.userTable.email,n));if(!r)return null;let{password:i,recovery_code:a,...s}=r;return s}exports.createOAuthUser=l,exports.createUser=c,exports.getUserById=u,exports.getUserFromEmail=y,exports.getUserPasswordHash=v,exports.getUserRecoverCode=d,exports.resetUserRecoveryCode=f,exports.setUserAsEmailVerifiedIfEmailMatches=_,exports.updateUserAwatar=h,exports.updateUserEmailAndSetEmailAsVerified=g,exports.updateUserName=m,exports.updateUserPassword=p,exports.verifyUsernameInput=s;