@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.
Files changed (213) hide show
  1. package/dist/core/auth/augment.d.ts +18 -0
  2. package/dist/core/auth/augment.d.ts.map +1 -0
  3. package/dist/core/auth/augment.js +45 -0
  4. package/dist/core/auth/email-verification.d.ts +58 -0
  5. package/dist/core/auth/email-verification.d.ts.map +1 -0
  6. package/dist/core/auth/email-verification.js +105 -0
  7. package/dist/core/auth/events.d.ts +53 -0
  8. package/dist/core/auth/events.d.ts.map +1 -0
  9. package/dist/core/auth/events.js +1 -0
  10. package/dist/core/auth/logic.d.ts +106 -0
  11. package/dist/core/auth/logic.d.ts.map +1 -0
  12. package/dist/core/auth/logic.js +245 -0
  13. package/dist/core/auth/password-reset.d.ts +35 -0
  14. package/dist/core/auth/password-reset.d.ts.map +1 -0
  15. package/dist/core/auth/password-reset.js +122 -0
  16. package/dist/core/auth/rbac.d.ts +56 -0
  17. package/dist/core/auth/rbac.d.ts.map +1 -0
  18. package/dist/core/auth/rbac.js +134 -0
  19. package/dist/core/auth/session.d.ts +50 -0
  20. package/dist/core/auth/session.d.ts.map +1 -0
  21. package/dist/core/auth/session.js +152 -0
  22. package/dist/core/auth/types.d.ts +52 -0
  23. package/dist/core/auth/types.d.ts.map +1 -0
  24. package/dist/core/auth/types.js +1 -0
  25. package/dist/core/auth/utils/encode.d.ts +12 -0
  26. package/dist/core/auth/utils/encode.d.ts.map +1 -0
  27. package/dist/core/auth/utils/encode.js +20 -0
  28. package/dist/core/auth/utils/{encryption.d.mts → encryption.d.ts} +5 -8
  29. package/dist/core/auth/utils/encryption.d.ts.map +1 -0
  30. package/dist/core/auth/utils/encryption.js +62 -0
  31. package/dist/core/auth/validation.d.ts +44 -0
  32. package/dist/core/auth/validation.d.ts.map +1 -0
  33. package/dist/core/auth/validation.js +41 -0
  34. package/dist/core/bootstrap.d.ts +2 -0
  35. package/dist/core/bootstrap.d.ts.map +1 -0
  36. package/dist/core/bootstrap.js +51 -0
  37. package/dist/core/config.d.ts +9 -0
  38. package/dist/core/config.d.ts.map +1 -0
  39. package/dist/core/config.js +3 -0
  40. package/dist/core/config.server.d.ts +12 -0
  41. package/dist/core/config.server.d.ts.map +1 -0
  42. package/dist/core/config.server.js +61 -0
  43. package/dist/core/event-bus.d.ts +14 -0
  44. package/dist/core/event-bus.d.ts.map +1 -0
  45. package/dist/core/event-bus.js +51 -0
  46. package/dist/core/filesystem/index.d.ts +4 -0
  47. package/dist/core/filesystem/index.d.ts.map +1 -0
  48. package/dist/core/filesystem/index.js +10 -0
  49. package/dist/core/filesystem/providers/local.d.ts +8 -0
  50. package/dist/core/filesystem/providers/local.d.ts.map +1 -0
  51. package/dist/core/filesystem/providers/local.js +42 -0
  52. package/dist/core/filesystem/service.d.ts +16 -0
  53. package/dist/core/filesystem/service.d.ts.map +1 -0
  54. package/dist/core/filesystem/service.js +51 -0
  55. package/dist/core/filesystem/types.d.ts +19 -0
  56. package/dist/core/filesystem/types.d.ts.map +1 -0
  57. package/dist/core/filesystem/types.js +1 -0
  58. package/dist/core/notifications/actions.d.ts +54 -0
  59. package/dist/core/notifications/actions.d.ts.map +1 -0
  60. package/dist/core/notifications/actions.js +43 -0
  61. package/dist/core/notifications/index.d.ts +4 -0
  62. package/dist/core/notifications/index.d.ts.map +1 -0
  63. package/dist/core/notifications/index.js +3 -0
  64. package/dist/core/notifications/service.d.ts +7 -0
  65. package/dist/core/notifications/service.d.ts.map +1 -0
  66. package/dist/core/notifications/service.js +32 -0
  67. package/dist/core/notifications/types.d.ts +17 -0
  68. package/dist/core/notifications/types.d.ts.map +1 -0
  69. package/dist/core/notifications/types.js +1 -0
  70. package/dist/core/setup.d.ts +6 -0
  71. package/dist/core/setup.d.ts.map +1 -0
  72. package/dist/core/setup.js +25 -0
  73. package/dist/core/types.d.ts +10 -0
  74. package/dist/core/types.d.ts.map +1 -0
  75. package/dist/core/types.js +1 -0
  76. package/dist/index.d.ts +8 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +16 -0
  79. package/dist/server/auth/email.d.ts +10 -0
  80. package/dist/server/auth/email.d.ts.map +1 -0
  81. package/dist/server/auth/email.js +20 -0
  82. package/dist/server/auth/{password.d.mts → password.d.ts} +4 -7
  83. package/dist/server/auth/password.d.ts.map +1 -0
  84. package/dist/server/auth/password.js +30 -0
  85. package/dist/server/auth/types.d.ts +13 -0
  86. package/dist/server/auth/types.d.ts.map +1 -0
  87. package/dist/server/auth/types.js +1 -0
  88. package/dist/server/auth/user.d.ts +54 -0
  89. package/dist/server/auth/user.d.ts.map +1 -0
  90. package/dist/server/auth/user.js +222 -0
  91. package/dist/server/database/inject.d.ts +11 -0
  92. package/dist/server/database/inject.d.ts.map +1 -0
  93. package/dist/server/database/inject.js +29 -0
  94. package/dist/server/database/schema.d.ts +2953 -0
  95. package/dist/server/database/{schema.d.mts.map → schema.d.ts.map} +1 -1
  96. package/dist/server/database/schema.js +192 -0
  97. package/dist/server/database/types.d.ts +12 -0
  98. package/dist/server/database/types.d.ts.map +1 -0
  99. package/dist/server/database/types.js +1 -0
  100. package/dist/server/emails/index.d.ts +23 -0
  101. package/dist/server/emails/index.d.ts.map +1 -0
  102. package/dist/server/emails/index.js +67 -0
  103. package/dist/server.d.ts +25 -0
  104. package/dist/server.d.ts.map +1 -0
  105. package/dist/server.js +32 -0
  106. package/package.json +5 -6
  107. package/dist/_virtual/_rolldown/runtime.mjs +0 -1
  108. package/dist/core/auth/augment.d.mts +0 -20
  109. package/dist/core/auth/augment.d.mts.map +0 -1
  110. package/dist/core/auth/augment.mjs +0 -2
  111. package/dist/core/auth/augment.mjs.map +0 -1
  112. package/dist/core/auth/email-verification.d.mts +0 -62
  113. package/dist/core/auth/email-verification.d.mts.map +0 -1
  114. package/dist/core/auth/email-verification.mjs +0 -2
  115. package/dist/core/auth/email-verification.mjs.map +0 -1
  116. package/dist/core/auth/logic.d.mts +0 -110
  117. package/dist/core/auth/logic.d.mts.map +0 -1
  118. package/dist/core/auth/logic.mjs +0 -2
  119. package/dist/core/auth/logic.mjs.map +0 -1
  120. package/dist/core/auth/password-reset.d.mts +0 -39
  121. package/dist/core/auth/password-reset.d.mts.map +0 -1
  122. package/dist/core/auth/password-reset.mjs +0 -2
  123. package/dist/core/auth/password-reset.mjs.map +0 -1
  124. package/dist/core/auth/rbac.d.mts +0 -61
  125. package/dist/core/auth/rbac.d.mts.map +0 -1
  126. package/dist/core/auth/rbac.mjs +0 -2
  127. package/dist/core/auth/rbac.mjs.map +0 -1
  128. package/dist/core/auth/session.d.mts +0 -54
  129. package/dist/core/auth/session.d.mts.map +0 -1
  130. package/dist/core/auth/session.mjs +0 -2
  131. package/dist/core/auth/session.mjs.map +0 -1
  132. package/dist/core/auth/types.d.mts +0 -55
  133. package/dist/core/auth/types.d.mts.map +0 -1
  134. package/dist/core/auth/utils/encode.d.mts +0 -15
  135. package/dist/core/auth/utils/encode.d.mts.map +0 -1
  136. package/dist/core/auth/utils/encode.mjs +0 -2
  137. package/dist/core/auth/utils/encode.mjs.map +0 -1
  138. package/dist/core/auth/utils/encryption.d.mts.map +0 -1
  139. package/dist/core/auth/utils/encryption.mjs +0 -2
  140. package/dist/core/auth/utils/encryption.mjs.map +0 -1
  141. package/dist/core/auth/validation.d.mts +0 -48
  142. package/dist/core/auth/validation.d.mts.map +0 -1
  143. package/dist/core/auth/validation.mjs +0 -2
  144. package/dist/core/auth/validation.mjs.map +0 -1
  145. package/dist/core/bootstrap.d.mts +0 -5
  146. package/dist/core/bootstrap.d.mts.map +0 -1
  147. package/dist/core/bootstrap.mjs +0 -2
  148. package/dist/core/bootstrap.mjs.map +0 -1
  149. package/dist/core/config.d.mts +0 -11
  150. package/dist/core/config.d.mts.map +0 -1
  151. package/dist/core/config.mjs +0 -2
  152. package/dist/core/config.mjs.map +0 -1
  153. package/dist/core/config.server.d.mts +0 -16
  154. package/dist/core/config.server.d.mts.map +0 -1
  155. package/dist/core/config.server.mjs +0 -2
  156. package/dist/core/config.server.mjs.map +0 -1
  157. package/dist/core/event-bus.d.mts +0 -17
  158. package/dist/core/event-bus.d.mts.map +0 -1
  159. package/dist/core/event-bus.mjs +0 -2
  160. package/dist/core/event-bus.mjs.map +0 -1
  161. package/dist/core/filesystem/index.mjs +0 -2
  162. package/dist/core/filesystem/index.mjs.map +0 -1
  163. package/dist/core/filesystem/providers/local.mjs +0 -2
  164. package/dist/core/filesystem/providers/local.mjs.map +0 -1
  165. package/dist/core/filesystem/service.d.mts +0 -19
  166. package/dist/core/filesystem/service.d.mts.map +0 -1
  167. package/dist/core/filesystem/service.mjs +0 -2
  168. package/dist/core/filesystem/service.mjs.map +0 -1
  169. package/dist/core/filesystem/types.d.mts +0 -22
  170. package/dist/core/filesystem/types.d.mts.map +0 -1
  171. package/dist/core/notifications/actions.d.mts +0 -58
  172. package/dist/core/notifications/actions.d.mts.map +0 -1
  173. package/dist/core/notifications/actions.mjs +0 -2
  174. package/dist/core/notifications/actions.mjs.map +0 -1
  175. package/dist/core/notifications/index.mjs +0 -1
  176. package/dist/core/notifications/service.d.mts +0 -9
  177. package/dist/core/notifications/service.d.mts.map +0 -1
  178. package/dist/core/notifications/service.mjs +0 -2
  179. package/dist/core/notifications/service.mjs.map +0 -1
  180. package/dist/core/notifications/types.d.mts +0 -21
  181. package/dist/core/notifications/types.d.mts.map +0 -1
  182. package/dist/core/setup.d.mts +0 -9
  183. package/dist/core/setup.d.mts.map +0 -1
  184. package/dist/core/setup.mjs +0 -2
  185. package/dist/core/setup.mjs.map +0 -1
  186. package/dist/core/types.d.mts +0 -13
  187. package/dist/core/types.d.mts.map +0 -1
  188. package/dist/index.d.mts +0 -8
  189. package/dist/index.mjs +0 -1
  190. package/dist/server/auth/email.d.mts +0 -13
  191. package/dist/server/auth/email.d.mts.map +0 -1
  192. package/dist/server/auth/email.mjs +0 -2
  193. package/dist/server/auth/email.mjs.map +0 -1
  194. package/dist/server/auth/password.d.mts.map +0 -1
  195. package/dist/server/auth/password.mjs +0 -2
  196. package/dist/server/auth/password.mjs.map +0 -1
  197. package/dist/server/auth/user.d.mts +0 -58
  198. package/dist/server/auth/user.d.mts.map +0 -1
  199. package/dist/server/auth/user.mjs +0 -2
  200. package/dist/server/auth/user.mjs.map +0 -1
  201. package/dist/server/database/inject.d.mts +0 -15
  202. package/dist/server/database/inject.d.mts.map +0 -1
  203. package/dist/server/database/inject.mjs +0 -2
  204. package/dist/server/database/inject.mjs.map +0 -1
  205. package/dist/server/database/schema.d.mts +0 -2962
  206. package/dist/server/database/schema.mjs +0 -2
  207. package/dist/server/database/schema.mjs.map +0 -1
  208. package/dist/server/emails/index.d.mts +0 -26
  209. package/dist/server/emails/index.d.mts.map +0 -1
  210. package/dist/server/emails/index.mjs +0 -2
  211. package/dist/server/emails/index.mjs.map +0 -1
  212. package/dist/server.d.mts +0 -26
  213. package/dist/server.mjs +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"bootstrap.mjs","names":[],"sources":["../../src/core/bootstrap.ts"],"sourcesContent":["import { injectDb } from \"../server/database/inject\";\nimport { initEmailVerification } from \"./auth/email-verification\";\nimport { eventBus } from \"./event-bus\";\nimport { filesystemService } from \"./filesystem/index\";\nimport { LocalFileProvider } from \"./filesystem/providers/local\";\nimport { notificationService } from \"./notifications/service\";\nimport { isSystemInstalled } from \"./setup\";\n\nexport async function ensureSystemInitialized(providedDb?: any) {\n if (typeof window !== \"undefined\") return;\n\n const g = globalThis as any;\n\n // 1. Immediate injection if provided\n if (providedDb) {\n injectDb(providedDb);\n }\n\n // 2. Prevent infinite recursion and double initialization\n if (g.__KRYO_INITIALIZED__) return;\n if (g.__KRYO_INITIALIZING__) return; // Already in progress, don't block/deadlock\n\n g.__KRYO_INITIALIZING__ = true;\n\n try {\n console.log(\"[Kryo:Bootstrap] Starting system initialization...\");\n\n // Check if we have DB after any possible injection\n if (!g.__KRYO_DB__) {\n console.warn(\n \"[Kryo:Bootstrap] DB not detected during bootstrap start. Trying to continue...\",\n );\n }\n\n // Check if system is installed before initializing modules\n if (await isSystemInstalled()) {\n // Order matters: services first, then modules (which use services)\n notificationService.init();\n await initEmailVerification();\n\n // Auto-register local filesystem provider as a fallback\n const local = new LocalFileProvider();\n\n filesystemService.registerProvider(local);\n filesystemService.setDefaultProvider(local.id);\n } else {\n console.log(\n \"[Kryo:Bootstrap] System not installed. Skipping module initialization.\",\n );\n }\n\n await eventBus.publish(\"system:start\", { runtime: \"nodejs\" });\n\n console.log(\"[Kryo:Bootstrap] System initialized successfully.\");\n g.__KRYO_INITIALIZED__ = true;\n } catch (error) {\n console.error(\"[Kryo:Bootstrap] Initialization failed:\", error);\n } finally {\n g.__KRYO_INITIALIZING__ = false;\n }\n}\n"],"mappings":"6bAQA,eAAsB,EAAwB,EAAkB,CAC9D,GAAI,OAAO,OAAW,IAAa,OAEnC,IAAM,EAAI,WAGV,GAAI,GACF,EAAS,EAAW,CAIlB,GAAE,sBACF,GAAE,sBAEN,GAAE,sBAAwB,GAE1B,GAAI,CAWF,GAVA,QAAQ,IAAI,qDAAqD,CAG5D,EAAE,aACL,QAAQ,KACN,iFACD,CAIC,MAAM,GAAmB,CAAE,CAE7B,EAAoB,MAAM,CAC1B,MAAM,GAAuB,CAG7B,IAAM,EAAQ,IAAI,EAElB,EAAkB,iBAAiB,EAAM,CACzC,EAAkB,mBAAmB,EAAM,GAAG,MAE9C,QAAQ,IACN,yEACD,CAGH,MAAM,EAAS,QAAQ,eAAgB,CAAE,QAAS,SAAU,CAAC,CAE7D,QAAQ,IAAI,oDAAoD,CAChE,EAAE,qBAAuB,SAClB,EAAO,CACd,QAAQ,MAAM,0CAA2C,EAAM,QACvD,CACR,EAAE,sBAAwB"}
@@ -1,11 +0,0 @@
1
- //#region src/core/config.d.ts
2
- interface KryoConfig {
3
- /**
4
- * Path to the directory with local modules.
5
- * Default: "./modules"
6
- */
7
- modulesDirectory?: string;
8
- }
9
- //#endregion
10
- export { KryoConfig };
11
- //# sourceMappingURL=config.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.mts","names":[],"sources":["../../src/core/config.ts"],"mappings":";UAAiB,UAAA;EAAA;;;;EAKf,gBAAA;AAAA"}
@@ -1,2 +0,0 @@
1
- const e={modulesDirectory:`modules`};export{e as DEFAULT_CONFIG};
2
- //# sourceMappingURL=config.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.mjs","names":[],"sources":["../../src/core/config.ts"],"sourcesContent":["export interface KryoConfig {\n /**\n * Path to the directory with local modules.\n * Default: \"./modules\"\n */\n modulesDirectory?: string;\n}\n\nexport const DEFAULT_CONFIG: KryoConfig = {\n modulesDirectory: \"modules\",\n};\n"],"mappings":"AAQA,MAAa,EAA6B,CACxC,iBAAkB,UACnB"}
@@ -1,16 +0,0 @@
1
- import { KryoConfig } from "./config.mjs";
2
-
3
- //#region src/core/config.server.d.ts
4
- /**
5
- * Loads the Kryo configuration from kryo.config.ts or kryo.config in the current working directory.
6
- * SERVER ONLY.
7
- */
8
- declare function getKryoConfig(): Promise<KryoConfig>;
9
- /**
10
- * Helper returning the absolute path to the modules directory.
11
- * SERVER ONLY.
12
- */
13
- declare function getModulesDir(): Promise<string>;
14
- //#endregion
15
- export { getKryoConfig, getModulesDir };
16
- //# sourceMappingURL=config.server.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.server.d.mts","names":[],"sources":["../../src/core/config.server.ts"],"mappings":";;;;;AAUA;;iBAAsB,aAAA,CAAA,GAAiB,OAAA,CAAQ,UAAA;;;AA4D/C;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
@@ -1,2 +0,0 @@
1
- import{DEFAULT_CONFIG as e}from"./config.mjs";import t from"node:fs";import n from"node:path";let r=null;async function i(){if(typeof window<`u`)throw Error(`getKryoConfig can only be called on the server.`);if(process.env.NODE_ENV===`production`&&r)return r;let i=process.cwd(),a=n.join(i,`kryo.config.ts`),o=n.join(i,`kryo.config`),s=n.join(i,`kryo.config.mjs`),c={};try{let{createJiti:e}=await import(`jiti`),n=e(i,{fsCache:!1,moduleCache:!1});if(t.existsSync(a)){let e=`?t=${Date.now()}`,t=await n.import(`file://${a}${e}`,{default:!0});c=t.default||t}else if(t.existsSync(s)){let e=await n.import(s,{default:!0});c=e.default||e}else if(t.existsSync(o)){let e=await n.import(o,{default:!0});c=e.default||e}}catch(e){console.warn(`[Kryo:Config] Could not load kryo.config.ts, using defaults.`,e)}let l={...e,...c};return process.env.NODE_ENV===`production`&&(r=l),l}async function a(){let e=(await i()).modulesDirectory||`modules`;return n.isAbsolute(e)?e:n.join(process.cwd(),e)}export{i as getKryoConfig,a as getModulesDir};
2
- //# sourceMappingURL=config.server.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.server.mjs","names":[],"sources":["../../src/core/config.server.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { DEFAULT_CONFIG, type KryoConfig } from \"./config\";\n\nlet cachedConfig: KryoConfig | null = null;\n\n/**\n * Loads the Kryo configuration from kryo.config.ts or kryo.config in the current working directory.\n * SERVER ONLY.\n */\nexport async function getKryoConfig(): Promise<KryoConfig> {\n // Prevent this from ever running on the client even if imported\n if (typeof window !== \"undefined\") {\n throw new Error(\"getKryoConfig can only be called on the server.\");\n }\n\n // Use memory cache in production\n if (process.env.NODE_ENV === \"production\" && cachedConfig) {\n return cachedConfig;\n }\n\n const cwd = process.cwd();\n const configPathTS = path.join(cwd, \"kryo.config.ts\");\n const configPathJS = path.join(cwd, \"kryo.config\");\n const configPathMJS = path.join(cwd, \"kryo.config.mjs\");\n\n let loadedConfig: Partial<KryoConfig> = {};\n\n try {\n // Dynamic import jiti only on server to avoid bundling issues\n const { createJiti } = await import(\"jiti\");\n const jiti = createJiti(cwd, {\n fsCache: false,\n moduleCache: false,\n });\n\n if (fs.existsSync(configPathTS)) {\n const cacheBuster = `?t=${Date.now()}`;\n const imported: any = await jiti.import(\n `file://${configPathTS}${cacheBuster}`,\n { default: true },\n );\n loadedConfig = imported.default || imported;\n } else if (fs.existsSync(configPathMJS)) {\n const imported: any = await jiti.import(configPathMJS, { default: true });\n loadedConfig = imported.default || imported;\n } else if (fs.existsSync(configPathJS)) {\n const imported: any = await jiti.import(configPathJS, { default: true });\n loadedConfig = imported.default || imported;\n }\n } catch (error) {\n console.warn(\n \"[Kryo:Config] Could not load kryo.config.ts, using defaults.\",\n error,\n );\n }\n\n const finalConfig = { ...DEFAULT_CONFIG, ...loadedConfig };\n\n if (process.env.NODE_ENV === \"production\") {\n cachedConfig = finalConfig;\n }\n\n return finalConfig;\n}\n\n/**\n * Helper returning the absolute path to the modules directory.\n * SERVER ONLY.\n */\nexport async function getModulesDir(): Promise<string> {\n const config = await getKryoConfig();\n\n const dir = config.modulesDirectory || \"modules\";\n return path.isAbsolute(dir) ? dir : path.join(process.cwd(), dir);\n}\n"],"mappings":"8FAIA,IAAI,EAAkC,KAMtC,eAAsB,GAAqC,CAEzD,GAAI,OAAO,OAAW,IACpB,MAAU,MAAM,kDAAkD,CAIpE,GAAI,QAAQ,IAAI,WAAa,cAAgB,EAC3C,OAAO,EAGT,IAAM,EAAM,QAAQ,KAAK,CACnB,EAAe,EAAK,KAAK,EAAK,iBAAiB,CAC/C,EAAe,EAAK,KAAK,EAAK,cAAc,CAC5C,EAAgB,EAAK,KAAK,EAAK,kBAAkB,CAEnD,EAAoC,EAAE,CAE1C,GAAI,CAEF,GAAM,CAAE,cAAe,MAAM,OAAO,QAC9B,EAAO,EAAW,EAAK,CAC3B,QAAS,GACT,YAAa,GACd,CAAC,CAEF,GAAI,EAAG,WAAW,EAAa,CAAE,CAC/B,IAAM,EAAc,MAAM,KAAK,KAAK,GAC9B,EAAgB,MAAM,EAAK,OAC/B,UAAU,IAAe,IACzB,CAAE,QAAS,GAAM,CAClB,CACD,EAAe,EAAS,SAAW,UAC1B,EAAG,WAAW,EAAc,CAAE,CACvC,IAAM,EAAgB,MAAM,EAAK,OAAO,EAAe,CAAE,QAAS,GAAM,CAAC,CACzE,EAAe,EAAS,SAAW,UAC1B,EAAG,WAAW,EAAa,CAAE,CACtC,IAAM,EAAgB,MAAM,EAAK,OAAO,EAAc,CAAE,QAAS,GAAM,CAAC,CACxE,EAAe,EAAS,SAAW,SAE9B,EAAO,CACd,QAAQ,KACN,+DACA,EACD,CAGH,IAAM,EAAc,CAAE,GAAG,EAAgB,GAAG,EAAc,CAM1D,OAJI,QAAQ,IAAI,WAAa,eAC3B,EAAe,GAGV,EAOT,eAAsB,GAAiC,CAGrD,IAAM,GAFS,MAAM,GAAe,EAEjB,kBAAoB,UACvC,OAAO,EAAK,WAAW,EAAI,CAAG,EAAM,EAAK,KAAK,QAAQ,KAAK,CAAE,EAAI"}
@@ -1,17 +0,0 @@
1
- import { EventHandler } from "./types.mjs";
2
-
3
- //#region src/core/event-bus.d.ts
4
- /**
5
- * EventBus (Pub/Sub) - Global Singleton Pattern.
6
- */
7
- declare class EventBus {
8
- private handlers;
9
- subscribe<T>(eventType: string, subscriberId: string, handler: EventHandler<T>): void;
10
- unsubscribe(eventType: string, subscriberId: string): void;
11
- clearAll(): void;
12
- publish<T>(eventType: string, payload: T, source?: string): Promise<void>;
13
- }
14
- declare const eventBus: EventBus;
15
- //#endregion
16
- export { eventBus };
17
- //# sourceMappingURL=event-bus.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-bus.d.mts","names":[],"sources":["../../src/core/event-bus.ts"],"mappings":";;;;;AAAyD;cAKnD,QAAA;EAAA,QACI,QAAA;EAED,SAAA,GAAA,CACL,SAAA,UACA,YAAA,UACA,OAAA,EAAS,YAAA,CAAa,CAAA;EAYjB,WAAA,CAAY,SAAA,UAAmB,YAAA;EAO/B,QAAA,CAAA;EAKM,OAAA,GAAA,CACX,SAAA,UACA,OAAA,EAAS,CAAA,EACT,MAAA,YACC,OAAA;AAAA;AAAA,cAkCQ,QAAA,EAAQ,QAAA"}
@@ -1,2 +0,0 @@
1
- var e=class{constructor(){this.handlers=new Map}subscribe(e,t,n){this.handlers.has(e)||this.handlers.set(e,new Map),this.handlers.get(e)?.set(t,n),console.log(`[Event Bus] Subscriber "${t}" added for "${e}"`)}unsubscribe(e,t){this.handlers.get(e)?.delete(t),console.log(`[Event Bus] Subscriber "${t}" removed from "${e}"`)}clearAll(){console.log(`[Event Bus] Resetting all listeners...`),this.handlers.clear()}async publish(e,t,n=`system`){let r=this.handlers.get(e);if(!r)return;let i=Array.from(r.values());console.log(`[Event Bus] Publishing "${e}" to ${i.length} subscribers`);let a={type:e,payload:t,timestamp:Date.now(),source:n};await Promise.all(i.map(async t=>{try{await t(a)}catch(t){console.error(`[Event Bus] Handler Error for ${e}:`,t)}}))}};const t=globalThis,n=t.__KRYO_EVENT_BUS__??new e;t.__KRYO_EVENT_BUS__=n;export{n as eventBus};
2
- //# sourceMappingURL=event-bus.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-bus.mjs","names":[],"sources":["../../src/core/event-bus.ts"],"sourcesContent":["import type { EventHandler, SystemEvent } from \"./types\";\n\n/**\n * EventBus (Pub/Sub) - Global Singleton Pattern.\n */\nclass EventBus {\n private handlers: Map<string, Map<string, EventHandler>> = new Map();\n\n public subscribe<T>(\n eventType: string,\n subscriberId: string,\n handler: EventHandler<T>,\n ): void {\n if (!this.handlers.has(eventType)) {\n this.handlers.set(eventType, new Map());\n }\n const eventHandlers = this.handlers.get(eventType);\n eventHandlers?.set(subscriberId, handler);\n console.log(\n `[Event Bus] Subscriber \"${subscriberId}\" added for \"${eventType}\"`,\n );\n }\n\n public unsubscribe(eventType: string, subscriberId: string): void {\n this.handlers.get(eventType)?.delete(subscriberId);\n console.log(\n `[Event Bus] Subscriber \"${subscriberId}\" removed from \"${eventType}\"`,\n );\n }\n\n public clearAll(): void {\n console.log(\"[Event Bus] Resetting all listeners...\");\n this.handlers.clear();\n }\n\n public async publish<T>(\n eventType: string,\n payload: T,\n source: string = \"system\",\n ): Promise<void> {\n const eventHandlers = this.handlers.get(eventType);\n if (!eventHandlers) return;\n\n const handlers = Array.from(eventHandlers.values());\n\n console.log(\n `[Event Bus] Publishing \"${eventType}\" to ${handlers.length} subscribers`,\n );\n\n const event: SystemEvent<T> = {\n type: eventType,\n payload,\n timestamp: Date.now(),\n source,\n };\n\n await Promise.all(\n handlers.map(async (handler) => {\n try {\n await handler(event);\n } catch (error) {\n console.error(`[Event Bus] Handler Error for ${eventType}:`, error);\n }\n }),\n );\n }\n}\n\n// Ensure global singleton\nconst globalForEventBus = globalThis as unknown as {\n __KRYO_EVENT_BUS__: EventBus | undefined;\n};\n\nexport const eventBus = globalForEventBus.__KRYO_EVENT_BUS__ ?? new EventBus();\n\nglobalForEventBus.__KRYO_EVENT_BUS__ = eventBus;\n"],"mappings":"AAKA,IAAM,EAAN,KAAe,6BAC8C,IAAI,IAE/D,UACE,EACA,EACA,EACM,CACD,KAAK,SAAS,IAAI,EAAU,EAC/B,KAAK,SAAS,IAAI,EAAW,IAAI,IAAM,CAEnB,KAAK,SAAS,IAAI,EAAU,EACnC,IAAI,EAAc,EAAQ,CACzC,QAAQ,IACN,2BAA2B,EAAa,eAAe,EAAU,GAClE,CAGH,YAAmB,EAAmB,EAA4B,CAChE,KAAK,SAAS,IAAI,EAAU,EAAE,OAAO,EAAa,CAClD,QAAQ,IACN,2BAA2B,EAAa,kBAAkB,EAAU,GACrE,CAGH,UAAwB,CACtB,QAAQ,IAAI,yCAAyC,CACrD,KAAK,SAAS,OAAO,CAGvB,MAAa,QACX,EACA,EACA,EAAiB,SACF,CACf,IAAM,EAAgB,KAAK,SAAS,IAAI,EAAU,CAClD,GAAI,CAAC,EAAe,OAEpB,IAAM,EAAW,MAAM,KAAK,EAAc,QAAQ,CAAC,CAEnD,QAAQ,IACN,2BAA2B,EAAU,OAAO,EAAS,OAAO,cAC7D,CAED,IAAM,EAAwB,CAC5B,KAAM,EACN,UACA,UAAW,KAAK,KAAK,CACrB,SACD,CAED,MAAM,QAAQ,IACZ,EAAS,IAAI,KAAO,IAAY,CAC9B,GAAI,CACF,MAAM,EAAQ,EAAM,OACb,EAAO,CACd,QAAQ,MAAM,iCAAiC,EAAU,GAAI,EAAM,GAErE,CACH,GAKL,MAAM,EAAoB,WAIb,EAAW,EAAkB,oBAAsB,IAAI,EAEpE,EAAkB,mBAAqB"}
@@ -1,2 +0,0 @@
1
- import{LocalFileProvider as e}from"./providers/local.mjs";import{filesystemService as t}from"./service.mjs";if(typeof window>`u`){let n=new e;t.registerProvider(n),t.setDefaultProvider(n.id)}export{};
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/core/filesystem/index.ts"],"sourcesContent":["import { LocalFileProvider } from \"./providers/local\";\nimport { filesystemService } from \"./service\";\n\nexport * from \"./types\";\nexport { filesystemService };\n\n// Auto-register local provider\nif (typeof window === \"undefined\") {\n const local = new LocalFileProvider();\n\n filesystemService.registerProvider(local);\n filesystemService.setDefaultProvider(local.id);\n}\n"],"mappings":"4GAOA,GAAI,OAAO,OAAW,IAAa,CACjC,IAAM,EAAQ,IAAI,EAElB,EAAkB,iBAAiB,EAAM,CACzC,EAAkB,mBAAmB,EAAM,GAAG"}
@@ -1,2 +0,0 @@
1
- import e from"node:fs";import t from"node:path";var n=class{constructor(){this.id=`local`,this.name=`Local Filesystem`}generateUniqueImageName(e){let t=e.replace(/\s+/g,`-`).toLowerCase(),n=Math.floor(Math.random()*Date.now()).toString(36),r=t.lastIndexOf(`.`);return r<0?`${t}-${n}`:`${t.slice(0,r)}-${n}${t.slice(r)}`}async upload(n){try{let r=process.env.FILE_STORAGE_FOLDER??`public/storage`;e.existsSync(r)||e.mkdirSync(r,{recursive:!0});let i=this.generateUniqueImageName(n.name),a=t.join(r,i),o=await n.arrayBuffer();return e.writeFileSync(a,Buffer.from(o)),{name:i,url:`${r}/${i}`.replace(`public`,``),type:n.type,size:n.size,service:`local`,serviceId:a}}catch(e){return console.error(`Error uploading file`,e),{error:`Error uploading file`}}}};export{n as LocalFileProvider};
2
- //# sourceMappingURL=local.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local.mjs","names":[],"sources":["../../../../src/core/filesystem/providers/local.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { IStorageProvider, StorageResult } from \"../types\";\n\nexport class LocalFileProvider implements IStorageProvider {\n public id = \"local\";\n public name = \"Local Filesystem\";\n\n private generateUniqueImageName(name: string) {\n const cleanName = name.replace(/\\s+/g, \"-\").toLowerCase();\n const suffix = Math.floor(Math.random() * Date.now()).toString(36);\n const index = cleanName.lastIndexOf(\".\");\n\n return index < 0\n ? `${cleanName}-${suffix}`\n : `${cleanName.slice(0, index)}-${suffix}${cleanName.slice(index)}`;\n }\n\n public async upload(file: File): Promise<StorageResult> {\n try {\n const storageFolder = process.env.FILE_STORAGE_FOLDER ?? \"public/storage\";\n\n if (!fs.existsSync(storageFolder)) {\n fs.mkdirSync(storageFolder, { recursive: true });\n }\n\n const name = this.generateUniqueImageName(file.name);\n const filePath = path.join(storageFolder, name);\n const buffer = await file.arrayBuffer();\n fs.writeFileSync(filePath, Buffer.from(buffer));\n\n const url = `${storageFolder}/${name}`.replace(\"public\", \"\");\n\n return {\n name: name,\n url,\n type: file.type,\n size: file.size,\n service: \"local\",\n serviceId: filePath,\n };\n } catch (error) {\n console.error(\"Error uploading file\", error);\n return { error: \"Error uploading file\" };\n }\n }\n}\n"],"mappings":"gDAIA,IAAa,EAAb,KAA2D,uBAC7C,kBACE,mBAEd,wBAAgC,EAAc,CAC5C,IAAM,EAAY,EAAK,QAAQ,OAAQ,IAAI,CAAC,aAAa,CACnD,EAAS,KAAK,MAAM,KAAK,QAAQ,CAAG,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG,CAC5D,EAAQ,EAAU,YAAY,IAAI,CAExC,OAAO,EAAQ,EACX,GAAG,EAAU,GAAG,IAChB,GAAG,EAAU,MAAM,EAAG,EAAM,CAAC,GAAG,IAAS,EAAU,MAAM,EAAM,GAGrE,MAAa,OAAO,EAAoC,CACtD,GAAI,CACF,IAAM,EAAgB,QAAQ,IAAI,qBAAuB,iBAEpD,EAAG,WAAW,EAAc,EAC/B,EAAG,UAAU,EAAe,CAAE,UAAW,GAAM,CAAC,CAGlD,IAAM,EAAO,KAAK,wBAAwB,EAAK,KAAK,CAC9C,EAAW,EAAK,KAAK,EAAe,EAAK,CACzC,EAAS,MAAM,EAAK,aAAa,CAKvC,OAJA,EAAG,cAAc,EAAU,OAAO,KAAK,EAAO,CAAC,CAIxC,CACC,OACN,IAJU,GAAG,EAAc,GAAG,IAAO,QAAQ,SAAU,GAAG,CAK1D,KAAM,EAAK,KACX,KAAM,EAAK,KACX,QAAS,QACT,UAAW,EACZ,OACM,EAAO,CAEd,OADA,QAAQ,MAAM,uBAAwB,EAAM,CACrC,CAAE,MAAO,uBAAwB"}
@@ -1,19 +0,0 @@
1
- import { IStorageProvider, StorageResult } from "./types.mjs";
2
-
3
- //#region src/core/filesystem/service.d.ts
4
- declare class FilesystemService {
5
- private providers;
6
- private defaultProviderId;
7
- registerProvider(provider: IStorageProvider): void;
8
- unregisterProvider(id: string): void;
9
- setDefaultProvider(id: string): void;
10
- upload(file: File, providerId?: string): Promise<StorageResult>;
11
- getProviders(): {
12
- id: string;
13
- name: string;
14
- }[];
15
- }
16
- declare const filesystemService: FilesystemService;
17
- //#endregion
18
- export { filesystemService };
19
- //# sourceMappingURL=service.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.d.mts","names":[],"sources":["../../../src/core/filesystem/service.ts"],"mappings":";;;cAEM,iBAAA;EAAA,QACI,SAAA;EAAA,QACA,iBAAA;EAED,gBAAA,CAAiB,QAAA,EAAU,gBAAA;EAQ3B,kBAAA,CAAmB,EAAA;EAUnB,kBAAA,CAAmB,EAAA;EAOb,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,UAAA,YAAsB,OAAA,CAAQ,aAAA;EAiBvD,YAAA,CAAA;;;;;cAaI,iBAAA,EAAiB,iBAAA"}
@@ -1,2 +0,0 @@
1
- var e=class{constructor(){this.providers=new Map,this.defaultProviderId=null}registerProvider(e){this.providers.set(e.id,e),(!this.defaultProviderId||this.defaultProviderId===`local`)&&(this.defaultProviderId=e.id),console.log(`[Filesystem] Provider registered: ${e.id}`)}unregisterProvider(e){this.providers.delete(e),this.defaultProviderId===e&&(this.defaultProviderId=this.providers.has(`local`)?`local`:Array.from(this.providers.keys())[0]||null),console.log(`[Filesystem] Provider unregistered: ${e}`)}setDefaultProvider(e){this.providers.has(e)&&(this.defaultProviderId=e,console.log(`[Filesystem] Default provider set to: ${e}`))}async upload(e,t){let n=t||this.defaultProviderId;(!n||!this.providers.has(n))&&(n=`local`);let r=this.providers.get(n);return r?await r.upload(e):{error:`No storage provider available (local fallback failed)`}}getProviders(){return Array.from(this.providers.values()).map(e=>({id:e.id,name:e.name}))}};const t=globalThis,n=t.__KRYO_FILESYSTEM_SERVICE__??new e;t.__KRYO_FILESYSTEM_SERVICE__=n;export{n as filesystemService};
2
- //# sourceMappingURL=service.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.mjs","names":[],"sources":["../../../src/core/filesystem/service.ts"],"sourcesContent":["import type { IStorageProvider, StorageResult } from \"./types\";\n\nclass FilesystemService {\n private providers: Map<string, IStorageProvider> = new Map();\n private defaultProviderId: string | null = null;\n\n public registerProvider(provider: IStorageProvider) {\n this.providers.set(provider.id, provider);\n if (!this.defaultProviderId || this.defaultProviderId === \"local\") {\n this.defaultProviderId = provider.id;\n }\n console.log(`[Filesystem] Provider registered: ${provider.id}`);\n }\n\n public unregisterProvider(id: string) {\n this.providers.delete(id);\n if (this.defaultProviderId === id) {\n this.defaultProviderId = this.providers.has(\"local\")\n ? \"local\"\n : Array.from(this.providers.keys())[0] || null;\n }\n console.log(`[Filesystem] Provider unregistered: ${id}`);\n }\n\n public setDefaultProvider(id: string) {\n if (this.providers.has(id)) {\n this.defaultProviderId = id;\n console.log(`[Filesystem] Default provider set to: ${id}`);\n }\n }\n\n public async upload(file: File, providerId?: string): Promise<StorageResult> {\n let id = providerId || this.defaultProviderId;\n\n // Fallback logic\n if (!id || !this.providers.has(id)) {\n id = \"local\";\n }\n\n const provider = this.providers.get(id);\n\n if (!provider) {\n return { error: \"No storage provider available (local fallback failed)\" };\n }\n\n return await provider.upload(file);\n }\n\n public getProviders() {\n return Array.from(this.providers.values()).map((p) => ({\n id: p.id,\n name: p.name,\n }));\n }\n}\n\n// Global Singleton Pattern\nconst globalForFilesystem = globalThis as unknown as {\n __KRYO_FILESYSTEM_SERVICE__: FilesystemService | undefined;\n};\n\nexport const filesystemService =\n globalForFilesystem.__KRYO_FILESYSTEM_SERVICE__ ?? new FilesystemService();\n\nglobalForFilesystem.__KRYO_FILESYSTEM_SERVICE__ = filesystemService;\n"],"mappings":"AAEA,IAAM,EAAN,KAAwB,8BAC6B,IAAI,2BACZ,KAE3C,iBAAwB,EAA4B,CAClD,KAAK,UAAU,IAAI,EAAS,GAAI,EAAS,EACrC,CAAC,KAAK,mBAAqB,KAAK,oBAAsB,WACxD,KAAK,kBAAoB,EAAS,IAEpC,QAAQ,IAAI,qCAAqC,EAAS,KAAK,CAGjE,mBAA0B,EAAY,CACpC,KAAK,UAAU,OAAO,EAAG,CACrB,KAAK,oBAAsB,IAC7B,KAAK,kBAAoB,KAAK,UAAU,IAAI,QAAQ,CAChD,QACA,MAAM,KAAK,KAAK,UAAU,MAAM,CAAC,CAAC,IAAM,MAE9C,QAAQ,IAAI,uCAAuC,IAAK,CAG1D,mBAA0B,EAAY,CAChC,KAAK,UAAU,IAAI,EAAG,GACxB,KAAK,kBAAoB,EACzB,QAAQ,IAAI,yCAAyC,IAAK,EAI9D,MAAa,OAAO,EAAY,EAA6C,CAC3E,IAAI,EAAK,GAAc,KAAK,mBAGxB,CAAC,GAAM,CAAC,KAAK,UAAU,IAAI,EAAG,IAChC,EAAK,SAGP,IAAM,EAAW,KAAK,UAAU,IAAI,EAAG,CAMvC,OAJK,EAIE,MAAM,EAAS,OAAO,EAAK,CAHzB,CAAE,MAAO,wDAAyD,CAM7E,cAAsB,CACpB,OAAO,MAAM,KAAK,KAAK,UAAU,QAAQ,CAAC,CAAC,IAAK,IAAO,CACrD,GAAI,EAAE,GACN,KAAM,EAAE,KACT,EAAE,GAKP,MAAM,EAAsB,WAIf,EACX,EAAoB,6BAA+B,IAAI,EAEzD,EAAoB,4BAA8B"}
@@ -1,22 +0,0 @@
1
- //#region src/core/filesystem/types.d.ts
2
- interface StorageData {
3
- name: string;
4
- url: string;
5
- type: string;
6
- size: number;
7
- service: string;
8
- serviceId: string;
9
- }
10
- interface StorageError {
11
- error: string;
12
- }
13
- type StorageResult = StorageData | StorageError;
14
- interface IStorageProvider {
15
- id: string;
16
- name: string;
17
- upload(file: File, options?: any): Promise<StorageResult>;
18
- delete?(serviceId: string): Promise<boolean>;
19
- }
20
- //#endregion
21
- export { IStorageProvider, StorageData, StorageError, StorageResult };
22
- //# sourceMappingURL=types.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/core/filesystem/types.ts"],"mappings":";UAAiB,WAAA;EACf,IAAA;EACA,GAAA;EACA,IAAA;EACA,IAAA;EACA,OAAA;EACA,SAAA;AAAA;AAAA,UAGe,YAAA;EACf,KAAA;AAAA;AAAA,KAGU,aAAA,GAAgB,WAAA,GAAc,YAAA;AAAA,UAEzB,gBAAA;EACf,EAAA;EACA,IAAA;EACA,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,OAAA,SAAgB,OAAA,CAAQ,aAAA;EAC3C,MAAA,EAAQ,SAAA,WAAoB,OAAA;AAAA"}
@@ -1,58 +0,0 @@
1
- import { CreateNotificationPayload } from "./types.mjs";
2
-
3
- //#region src/core/notifications/actions.d.ts
4
- declare function getUserNotifications(): Promise<{
5
- id: string;
6
- title: string;
7
- content: string | null;
8
- target: string | null;
9
- type: string | null;
10
- isRead: boolean;
11
- resourceId: string | null;
12
- resourceType: string | null;
13
- userId: string;
14
- createdAt: Date;
15
- updatedAt: Date | null;
16
- }[] | null>;
17
- declare function createNotification(data: CreateNotificationPayload): Promise<{
18
- type: string | null;
19
- id: string;
20
- createdAt: Date;
21
- updatedAt: Date | null;
22
- userId: string;
23
- title: string;
24
- content: string | null;
25
- target: string | null;
26
- isRead: boolean;
27
- resourceId: string | null;
28
- resourceType: string | null;
29
- }>;
30
- declare function markNotificationAsRead(id: string): Promise<{
31
- id: string;
32
- title: string;
33
- content: string | null;
34
- target: string | null;
35
- type: string | null;
36
- isRead: boolean;
37
- resourceId: string | null;
38
- resourceType: string | null;
39
- userId: string;
40
- createdAt: Date;
41
- updatedAt: Date | null;
42
- }>;
43
- declare function markAllNotificationsAsRead(): Promise<{
44
- id: string;
45
- title: string;
46
- content: string | null;
47
- target: string | null;
48
- type: string | null;
49
- isRead: boolean;
50
- resourceId: string | null;
51
- resourceType: string | null;
52
- userId: string;
53
- createdAt: Date;
54
- updatedAt: Date | null;
55
- }[] | null>;
56
- //#endregion
57
- export { createNotification, getUserNotifications, markAllNotificationsAsRead, markNotificationAsRead };
58
- //# sourceMappingURL=actions.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.d.mts","names":[],"sources":["../../../src/core/notifications/actions.ts"],"mappings":";;;iBAQsB,oBAAA,CAAA,GAAoB,OAAA;;;;;;;;;;;;;iBAWpB,kBAAA,CAAmB,IAAA,EAAM,yBAAA,GAAyB,OAAA;;;;;;;;;;;;;iBAYlD,sBAAA,CAAuB,EAAA,WAAU,OAAA;;;;;;;;;;;;;iBAUjC,0BAAA,CAAA,GAA0B,OAAA"}
@@ -1,2 +0,0 @@
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};
2
- //# sourceMappingURL=actions.mjs.map
@@ -1 +0,0 @@
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":"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 +0,0 @@
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,9 +0,0 @@
1
- //#region src/core/notifications/service.d.ts
2
- declare class NotificationService {
3
- private initialized;
4
- init(): void;
5
- }
6
- declare const notificationService: NotificationService;
7
- //#endregion
8
- export { notificationService };
9
- //# sourceMappingURL=service.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.d.mts","names":[],"sources":["../../../src/core/notifications/service.ts"],"mappings":";cAIM,mBAAA;EAAA,QACI,WAAA;EAED,IAAA,CAAA;AAAA;AAAA,cA4CI,mBAAA,EAAmB,mBAAA"}
@@ -1,2 +0,0 @@
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};
2
- //# sourceMappingURL=service.mjs.map
@@ -1 +0,0 @@
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":"+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,21 +0,0 @@
1
- import { notificationTable } from "../../server/database/schema.mjs";
2
- import { InferSelectModel } from "drizzle-orm";
3
-
4
- //#region src/core/notifications/types.d.ts
5
- type Notification = InferSelectModel<typeof notificationTable>;
6
- type CreateNotificationPayload = {
7
- title: string;
8
- content?: string;
9
- type?: string;
10
- target?: string;
11
- userId: string;
12
- resourceId?: string;
13
- resourceType?: string;
14
- };
15
- type NotificationEvents = {
16
- "notification:send": CreateNotificationPayload;
17
- "notification:created": Notification;
18
- };
19
- //#endregion
20
- export { CreateNotificationPayload, Notification, NotificationEvents };
21
- //# sourceMappingURL=types.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/core/notifications/types.ts"],"mappings":";;;;KAGY,YAAA,GAAe,gBAAA,QAAwB,iBAAA;AAAA,KAEvC,yBAAA;EACV,KAAA;EACA,OAAA;EACA,IAAA;EACA,MAAA;EACA,MAAA;EACA,UAAA;EACA,YAAA;AAAA;AAAA,KAGU,kBAAA;EACV,mBAAA,EAAqB,yBAAA;EACrB,sBAAA,EAAwB,YAAA;AAAA"}
@@ -1,9 +0,0 @@
1
- //#region src/core/setup.d.ts
2
- /**
3
- * Checks if the system is installed.
4
- * A system is considered installed if at least one user exists in the database.
5
- */
6
- declare function isSystemInstalled(): Promise<boolean>;
7
- //#endregion
8
- export { isSystemInstalled };
9
- //# sourceMappingURL=setup.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.d.mts","names":[],"sources":["../../src/core/setup.ts"],"mappings":";;AAQA;;;iBAAsB,iBAAA,CAAA,GAAqB,OAAA"}
@@ -1,2 +0,0 @@
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};
2
- //# sourceMappingURL=setup.mjs.map
@@ -1 +0,0 @@
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":"+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"}
@@ -1,13 +0,0 @@
1
- //#region src/core/types.d.ts
2
- type UserRole = "user" | "admin" | string;
3
- type UserPermission = string;
4
- interface SystemEvent<T = any> {
5
- type: string;
6
- payload: T;
7
- timestamp: number;
8
- source: string;
9
- }
10
- type EventHandler<T = any> = (event: SystemEvent<T>) => Promise<void> | void;
11
- //#endregion
12
- export { EventHandler, SystemEvent, UserPermission, UserRole };
13
- //# sourceMappingURL=types.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/core/types.ts"],"mappings":";KAAY,QAAA;AAAA,KACA,cAAA;AAAA,UAEK,WAAA;EACf,IAAA;EACA,OAAA,EAAS,CAAA;EACT,SAAA;EACA,MAAA;AAAA;AAAA,KAGU,YAAA,aACV,KAAA,EAAO,WAAA,CAAY,CAAA,MAChB,OAAA"}
package/dist/index.d.mts DELETED
@@ -1,8 +0,0 @@
1
- import { DatabaseSchema, coreSchema, emailVerificationTable, notificationTable, passwordResetSessionTable, permissionsTable, relations, rolesTable, rolesToPermissionsTable, sessionTable, systemModulesTable, userTable, usersToPermissionsTable, usersToRolesTable } from "./server/database/schema.mjs";
2
- import { EventHandler, SystemEvent, UserPermission, UserRole } from "./core/types.mjs";
3
- import { AuthResponse, AuthSession, FullUser, PasswordResetAuthSession, PasswordResetSession, Session, SessionFlags, User, UserSession } from "./core/auth/types.mjs";
4
- import { ForgotPasswordInput, LoginInput, PasskeysSetupInput, RecoveryVerifyInput, RegisterInput, ResetPasswordInput, TOTPSetupInput, TOTPVerifyInput, VerifyEmailInput, forgotPasswordSchema, loginSchema, passkeysSetupSchema, recoveryCodeVerifySchema, registerSchema, resetPasswordSchema, totpSetupSchema, totpVerifySchema, verifyEmailSchema } from "./core/auth/validation.mjs";
5
- import { eventBus } from "./core/event-bus.mjs";
6
- import { notificationService } from "./core/notifications/service.mjs";
7
- import { CreateNotificationPayload, Notification, NotificationEvents } from "./core/notifications/types.mjs";
8
- export { AuthResponse, AuthSession, CreateNotificationPayload, DatabaseSchema, EventHandler, ForgotPasswordInput, FullUser, LoginInput, Notification, NotificationEvents, PasskeysSetupInput, PasswordResetAuthSession, PasswordResetSession, RecoveryVerifyInput, RegisterInput, ResetPasswordInput, Session, SessionFlags, SystemEvent, TOTPSetupInput, TOTPVerifyInput, User, UserPermission, UserRole, UserSession, VerifyEmailInput, coreSchema, emailVerificationTable, eventBus, forgotPasswordSchema, loginSchema, notificationService, notificationTable, passkeysSetupSchema, passwordResetSessionTable, permissionsTable, recoveryCodeVerifySchema, registerSchema, relations, resetPasswordSchema, rolesTable, rolesToPermissionsTable, sessionTable, systemModulesTable, totpSetupSchema, totpVerifySchema, userTable, usersToPermissionsTable, usersToRolesTable, verifyEmailSchema };
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
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,13 +0,0 @@
1
- //#region src/server/auth/email.d.ts
2
- /**
3
- * Validates the email format and length.
4
- */
5
- declare function verifyEmailInput(email: string): boolean;
6
- /**
7
- * Checks if an email address is already in use.
8
- * @returns True if the email is available, false otherwise.
9
- */
10
- declare function checkEmailAvailability(email: string): Promise<boolean>;
11
- //#endregion
12
- export { checkEmailAvailability, verifyEmailInput };
13
- //# sourceMappingURL=email.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"email.d.mts","names":[],"sources":["../../../src/server/auth/email.ts"],"mappings":";;AAOA;;iBAAgB,gBAAA,CAAiB,KAAA;;;AAQjC;;iBAAsB,sBAAA,CAAuB,KAAA,WAAgB,OAAA"}
@@ -1,2 +0,0 @@
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};
2
- //# sourceMappingURL=email.mjs.map
@@ -1 +0,0 @@
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":"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 +0,0 @@
1
- {"version":3,"file":"password.d.mts","names":[],"sources":["../../../src/server/auth/password.ts"],"mappings":";;AASA;;;;iBAAsB,YAAA,CAAa,QAAA,WAAmB,OAAA;AAYtD;;;;;;AAAA,iBAAsB,kBAAA,CACpB,IAAA,UACA,QAAA,WACC,OAAA;;;AAUH;;;iBAAsB,sBAAA,CACpB,QAAA,WACC,OAAA"}
@@ -1,2 +0,0 @@
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};
2
- //# sourceMappingURL=password.mjs.map
@@ -1 +0,0 @@
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,58 +0,0 @@
1
- import { User } from "../../core/auth/types.mjs";
2
-
3
- //#region src/server/auth/user.d.ts
4
- /**
5
- * Validates the username input.
6
- */
7
- declare function verifyUsernameInput(username: string): Promise<boolean>;
8
- /**
9
- * Creates a new user with an initial recovery code and default 'user' role.
10
- */
11
- declare function createUser(email: string, username: string, password: string): Promise<User>;
12
- /**
13
- * Creates a new user from an OAuth provider.
14
- */
15
- declare function createOAuthUser(email: string, name: string, image?: string): Promise<User>;
16
- /**
17
- * Returns a user by ID.
18
- */
19
- declare function getUserById(userId: string): Promise<User | null>;
20
- /**
21
- * Decrypts and returns the user's recovery code.
22
- */
23
- declare function getUserRecoverCode(userId: string): Promise<string>;
24
- /**
25
- * Generates and sets a new recovery code for the user.
26
- */
27
- declare function resetUserRecoveryCode(userId: string): Promise<string>;
28
- /**
29
- * Updates the user's password.
30
- */
31
- declare function updateUserPassword(userId: string, password: string): Promise<void>;
32
- /**
33
- * Updates the user's name.
34
- */
35
- declare function updateUserName(userId: string, name: string): Promise<void>;
36
- /**
37
- * Updates the user's image.
38
- */
39
- declare function updateUserAwatar(userId: string, image: string): Promise<void>;
40
- /**
41
- * Updates the user's email and marks it as verified.
42
- */
43
- declare function updateUserEmailAndSetEmailAsVerified(userId: string, email: string): Promise<void>;
44
- /**
45
- * Sets the user as email verified if the provided email matches.
46
- */
47
- declare function setUserAsEmailVerifiedIfEmailMatches(userId: string, email: string): Promise<boolean>;
48
- /**
49
- * Returns the user's password hash.
50
- */
51
- declare function getUserPasswordHash(userId: string): Promise<string | null>;
52
- /**
53
- * Returns a user by email.
54
- */
55
- declare function getUserFromEmail(email: string): Promise<User | null>;
56
- //#endregion
57
- export { createOAuthUser, createUser, getUserById, getUserFromEmail, getUserPasswordHash, getUserRecoverCode, resetUserRecoveryCode, setUserAsEmailVerifiedIfEmailMatches, updateUserAwatar, updateUserEmailAndSetEmailAsVerified, updateUserName, updateUserPassword, verifyUsernameInput };
58
- //# sourceMappingURL=user.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.d.mts","names":[],"sources":["../../../src/server/auth/user.ts"],"mappings":";;;;;AAiBA;iBAAsB,mBAAA,CAAoB,QAAA,WAAmB,OAAA;;;;iBASvC,UAAA,CACpB,KAAA,UACA,QAAA,UACA,QAAA,WACC,OAAA,CAAQ,IAAA;;;;iBA+CW,eAAA,CACpB,KAAA,UACA,IAAA,UACA,KAAA,YACC,OAAA,CAAQ,IAAA;;;;iBAyCW,WAAA,CAAY,MAAA,WAAiB,OAAA,CAAQ,IAAA;;;AA7C3D;iBA2DsB,kBAAA,CAAmB,MAAA,WAAiB,OAAA;;;;iBAkBpC,qBAAA,CAAsB,MAAA,WAAiB,OAAA;;;;iBAuBvC,kBAAA,CACpB,MAAA,UACA,QAAA,WACC,OAAA;;AA1DH;;iBAwEsB,cAAA,CACpB,MAAA,UACA,IAAA,WACC,OAAA;;;;iBAWmB,gBAAA,CACpB,MAAA,UACA,KAAA,WACC,OAAA;;;AA3EH;iBAuFsB,oCAAA,CACpB,MAAA,UACA,KAAA,WACC,OAAA;;;;iBAamB,oCAAA,CACpB,MAAA,UACA,KAAA,WACC,OAAA;;;;iBAemB,mBAAA,CACpB,MAAA,WACC,OAAA;AAlFH;;;AAAA,iBAoGsB,gBAAA,CAAiB,KAAA,WAAgB,OAAA,CAAQ,IAAA"}
@@ -1,2 +0,0 @@
1
- "use server";import{db as e}from"../database/inject.mjs";import{rolesTable as t,userTable as n,usersToRolesTable as r}from"../database/schema.mjs";import{hashPassword as i}from"./password.mjs";import{generateRandomRecoveryCode as a}from"../../core/auth/utils/encode.mjs";import{decryptToString as o,encryptString as s}from"../../core/auth/utils/encryption.mjs";import{sendRecoveryCode as c}from"../emails/index.mjs";import{and as l,eq as u}from"drizzle-orm";async function d(e){return e.length>3&&e.length<32&&e.trim()===e}async function f(o,l,d){let f=await i(d),p=a(),m=s(p);return await e.transaction(async e=>{let[i]=await e.insert(n).values({email:o,name:l,password:f,recovery_code:Buffer.from(m)}).returning();if(!i)throw Error(`Failed to create user`);let[a]=await e.select().from(t).where(u(t.name,`user`));return a||([a]=await e.insert(t).values({name:`user`,description:`Default user role`}).returning()),await e.insert(r).values({userId:i.id,roleId:a.id}),await c(i.email,p),i})}async function p(i,o,c){let l=s(a());return await e.transaction(async e=>{let[a]=await e.insert(n).values({email:i,name:o,image:c,emailVerifiedAt:new Date,recovery_code:Buffer.from(l)}).returning(),[s]=await e.select().from(t).where(u(t.name,`user`));return s||([s]=await e.insert(t).values({name:`user`,description:`Default user role`}).returning()),await e.insert(r).values({userId:a.id,roleId:s.id}),a})}async function m(t){let[r]=await e.select().from(n).where(u(n.id,t));if(!r)return null;let{password:i,recovery_code:a,...o}=r;return o}async function h(t){let[r]=await e.select({recovery_code:n.recovery_code}).from(n).where(u(n.id,t));if(!r||!r.recovery_code)throw Error(`Recovery code not found for user`);return o(r.recovery_code)}async function g(t){let r=a(),i=s(r),[o]=await e.update(n).set({recovery_code:Buffer.from(i)}).where(u(n.id,t)).returning();if(!o)throw Error(`User not found`);return await c(o.email,r),r}async function _(t,r){let a=await i(r);await e.update(n).set({password:a}).where(u(n.id,t))}async function v(t,r){await e.update(n).set({name:r}).where(u(n.id,t))}async function y(t,r){await e.update(n).set({image:r}).where(u(n.id,t))}async function b(t,r){await e.update(n).set({email:r,emailVerifiedAt:new Date}).where(u(n.id,t))}async function x(t,r){return(await e.update(n).set({emailVerifiedAt:new Date}).where(l(u(n.id,t),u(n.email,r))).returning({id:n.id})).length>0}async function S(t){let[r]=await e.select({password:n.password}).from(n).where(u(n.id,t));if(!r)throw Error(`User not found`);return r.password}async function C(t){let[r]=await e.select().from(n).where(u(n.email,t));if(!r)return null;let{password:i,recovery_code:a,...o}=r;return o}export{p as createOAuthUser,f as createUser,m as getUserById,C as getUserFromEmail,S as getUserPasswordHash,h as getUserRecoverCode,g as resetUserRecoveryCode,x as setUserAsEmailVerifiedIfEmailMatches,y as updateUserAwatar,b as updateUserEmailAndSetEmailAsVerified,v as updateUserName,_ as updateUserPassword,d as verifyUsernameInput};
2
- //# sourceMappingURL=user.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.mjs","names":[],"sources":["../../../src/server/auth/user.ts"],"sourcesContent":["\"use server\";\n\nimport { and, eq } from \"drizzle-orm\";\nimport type { User } from \"../../core/auth/types\";\nimport { generateRandomRecoveryCode } from \"../../core/auth/utils/encode\";\nimport {\n decryptToString,\n encryptString,\n} from \"../../core/auth/utils/encryption\";\nimport { db } from \"../database/inject\";\nimport { rolesTable, usersToRolesTable, userTable } from \"../database/schema\";\nimport { sendRecoveryCode } from \"../emails/index\";\nimport { hashPassword } from \"./password\";\n\n/**\n * Validates the username input.\n */\nexport async function verifyUsernameInput(username: string): Promise<boolean> {\n return (\n username.length > 3 && username.length < 32 && username.trim() === username\n );\n}\n\n/**\n * Creates a new user with an initial recovery code and default 'user' role.\n */\nexport async function createUser(\n email: string,\n username: string,\n password: string,\n): Promise<User> {\n const passwordHash = await hashPassword(password);\n const recoveryCode = generateRandomRecoveryCode();\n const encryptedRecoveryCode = encryptString(recoveryCode);\n\n return await db.transaction(async (tx) => {\n const [row] = await tx\n .insert(userTable)\n .values({\n email: email,\n name: username,\n password: passwordHash,\n recovery_code: Buffer.from(encryptedRecoveryCode),\n })\n .returning();\n\n if (!row) {\n throw new Error(\"Failed to create user\");\n }\n\n // Assign default 'user' role\n let [role] = await tx\n .select()\n .from(rolesTable)\n .where(eq(rolesTable.name, \"user\"));\n\n if (!role) {\n [role] = await tx\n .insert(rolesTable)\n .values({ name: \"user\", description: \"Default user role\" })\n .returning();\n }\n\n await tx.insert(usersToRolesTable).values({\n userId: row.id,\n roleId: role.id,\n });\n\n await sendRecoveryCode(row.email, recoveryCode);\n\n return row;\n });\n}\n\n/**\n * Creates a new user from an OAuth provider.\n */\nexport async function createOAuthUser(\n email: string,\n name: string,\n image?: string,\n): Promise<User> {\n const recoveryCode = generateRandomRecoveryCode();\n const encryptedRecoveryCode = encryptString(recoveryCode);\n\n return await db.transaction(async (tx) => {\n const [row] = await tx\n .insert(userTable)\n .values({\n email: email,\n name: name,\n image: image,\n emailVerifiedAt: new Date(),\n recovery_code: Buffer.from(encryptedRecoveryCode),\n })\n .returning();\n\n // Assign default 'user' role\n let [role] = await tx\n .select()\n .from(rolesTable)\n .where(eq(rolesTable.name, \"user\"));\n\n if (!role) {\n [role] = await tx\n .insert(rolesTable)\n .values({ name: \"user\", description: \"Default user role\" })\n .returning();\n }\n\n await tx.insert(usersToRolesTable).values({\n userId: row.id,\n roleId: role.id,\n });\n\n return row;\n });\n}\n\n/**\n * Returns a user by ID.\n */\nexport async function getUserById(userId: string): Promise<User | null> {\n const [user] = await db\n .select()\n .from(userTable)\n .where(eq(userTable.id, userId));\n\n if (!user) return null;\n const { password, recovery_code, ...safeUser } = user;\n return safeUser as User;\n}\n\n/**\n * Decrypts and returns the user's recovery code.\n */\nexport async function getUserRecoverCode(userId: string): Promise<string> {\n const [user] = await db\n .select({\n recovery_code: userTable.recovery_code,\n })\n .from(userTable)\n .where(eq(userTable.id, userId));\n\n if (!user || !user.recovery_code) {\n throw new Error(\"Recovery code not found for user\");\n }\n\n return decryptToString(user.recovery_code);\n}\n\n/**\n * Generates and sets a new recovery code for the user.\n */\nexport async function resetUserRecoveryCode(userId: string): Promise<string> {\n const recoveryCode = generateRandomRecoveryCode();\n const encrypted = encryptString(recoveryCode);\n const [currentUser] = await db\n .update(userTable)\n .set({\n recovery_code: Buffer.from(encrypted),\n })\n .where(eq(userTable.id, userId))\n .returning();\n\n if (!currentUser) {\n throw new Error(\"User not found\");\n }\n\n await sendRecoveryCode(currentUser.email, recoveryCode);\n\n return recoveryCode;\n}\n\n/**\n * Updates the user's password.\n */\nexport async function updateUserPassword(\n userId: string,\n password: string,\n): Promise<void> {\n const passwordHash = await hashPassword(password);\n\n await db\n .update(userTable)\n .set({\n password: passwordHash,\n })\n .where(eq(userTable.id, userId));\n}\n\n/**\n * Updates the user's name.\n */\nexport async function updateUserName(\n userId: string,\n name: string,\n): Promise<void> {\n await db\n .update(userTable)\n .set({\n name: name,\n })\n .where(eq(userTable.id, userId));\n}\n/**\n * Updates the user's image.\n */\nexport async function updateUserAwatar(\n userId: string,\n image: string,\n): Promise<void> {\n await db\n .update(userTable)\n .set({\n image,\n })\n .where(eq(userTable.id, userId));\n}\n\n/**\n * Updates the user's email and marks it as verified.\n */\nexport async function updateUserEmailAndSetEmailAsVerified(\n userId: string,\n email: string,\n): Promise<void> {\n await db\n .update(userTable)\n .set({\n email: email,\n emailVerifiedAt: new Date(),\n })\n .where(eq(userTable.id, userId));\n}\n\n/**\n * Sets the user as email verified if the provided email matches.\n */\nexport async function setUserAsEmailVerifiedIfEmailMatches(\n userId: string,\n email: string,\n): Promise<boolean> {\n const result = await db\n .update(userTable)\n .set({\n emailVerifiedAt: new Date(),\n })\n .where(and(eq(userTable.id, userId), eq(userTable.email, email)))\n .returning({ id: userTable.id });\n\n return result.length > 0;\n}\n\n/**\n * Returns the user's password hash.\n */\nexport async function getUserPasswordHash(\n userId: string,\n): Promise<string | null> {\n const [user] = await db\n .select({\n password: userTable.password,\n })\n .from(userTable)\n .where(eq(userTable.id, userId));\n\n if (!user) {\n throw new Error(\"User not found\");\n }\n\n return user.password;\n}\n\n/**\n * Returns a user by email.\n */\nexport async function getUserFromEmail(email: string): Promise<User | null> {\n const [user] = await db\n .select()\n .from(userTable)\n .where(eq(userTable.email, email));\n\n if (!user) return null;\n const { password, recovery_code, ...safeUser } = user;\n return safeUser as User;\n}\n"],"mappings":"0cAiBA,eAAsB,EAAoB,EAAoC,CAC5E,OACE,EAAS,OAAS,GAAK,EAAS,OAAS,IAAM,EAAS,MAAM,GAAK,EAOvE,eAAsB,EACpB,EACA,EACA,EACe,CACf,IAAM,EAAe,MAAM,EAAa,EAAS,CAC3C,EAAe,GAA4B,CAC3C,EAAwB,EAAc,EAAa,CAEzD,OAAO,MAAM,EAAG,YAAY,KAAO,IAAO,CACxC,GAAM,CAAC,GAAO,MAAM,EACjB,OAAO,EAAU,CACjB,OAAO,CACC,QACP,KAAM,EACN,SAAU,EACV,cAAe,OAAO,KAAK,EAAsB,CAClD,CAAC,CACD,WAAW,CAEd,GAAI,CAAC,EACH,MAAU,MAAM,wBAAwB,CAI1C,GAAI,CAAC,GAAQ,MAAM,EAChB,QAAQ,CACR,KAAK,EAAW,CAChB,MAAM,EAAG,EAAW,KAAM,OAAO,CAAC,CAgBrC,OAdK,IACH,CAAC,GAAQ,MAAM,EACZ,OAAO,EAAW,CAClB,OAAO,CAAE,KAAM,OAAQ,YAAa,oBAAqB,CAAC,CAC1D,WAAW,EAGhB,MAAM,EAAG,OAAO,EAAkB,CAAC,OAAO,CACxC,OAAQ,EAAI,GACZ,OAAQ,EAAK,GACd,CAAC,CAEF,MAAM,EAAiB,EAAI,MAAO,EAAa,CAExC,GACP,CAMJ,eAAsB,EACpB,EACA,EACA,EACe,CAEf,IAAM,EAAwB,EADT,GAA4B,CACQ,CAEzD,OAAO,MAAM,EAAG,YAAY,KAAO,IAAO,CACxC,GAAM,CAAC,GAAO,MAAM,EACjB,OAAO,EAAU,CACjB,OAAO,CACC,QACD,OACC,QACP,gBAAiB,IAAI,KACrB,cAAe,OAAO,KAAK,EAAsB,CAClD,CAAC,CACD,WAAW,CAGV,CAAC,GAAQ,MAAM,EAChB,QAAQ,CACR,KAAK,EAAW,CAChB,MAAM,EAAG,EAAW,KAAM,OAAO,CAAC,CAcrC,OAZK,IACH,CAAC,GAAQ,MAAM,EACZ,OAAO,EAAW,CAClB,OAAO,CAAE,KAAM,OAAQ,YAAa,oBAAqB,CAAC,CAC1D,WAAW,EAGhB,MAAM,EAAG,OAAO,EAAkB,CAAC,OAAO,CACxC,OAAQ,EAAI,GACZ,OAAQ,EAAK,GACd,CAAC,CAEK,GACP,CAMJ,eAAsB,EAAY,EAAsC,CACtE,GAAM,CAAC,GAAQ,MAAM,EAClB,QAAQ,CACR,KAAK,EAAU,CACf,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAElC,GAAI,CAAC,EAAM,OAAO,KAClB,GAAM,CAAE,WAAU,gBAAe,GAAG,GAAa,EACjD,OAAO,EAMT,eAAsB,EAAmB,EAAiC,CACxE,GAAM,CAAC,GAAQ,MAAM,EAClB,OAAO,CACN,cAAe,EAAU,cAC1B,CAAC,CACD,KAAK,EAAU,CACf,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAElC,GAAI,CAAC,GAAQ,CAAC,EAAK,cACjB,MAAU,MAAM,mCAAmC,CAGrD,OAAO,EAAgB,EAAK,cAAc,CAM5C,eAAsB,EAAsB,EAAiC,CAC3E,IAAM,EAAe,GAA4B,CAC3C,EAAY,EAAc,EAAa,CACvC,CAAC,GAAe,MAAM,EACzB,OAAO,EAAU,CACjB,IAAI,CACH,cAAe,OAAO,KAAK,EAAU,CACtC,CAAC,CACD,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAC/B,WAAW,CAEd,GAAI,CAAC,EACH,MAAU,MAAM,iBAAiB,CAKnC,OAFA,MAAM,EAAiB,EAAY,MAAO,EAAa,CAEhD,EAMT,eAAsB,EACpB,EACA,EACe,CACf,IAAM,EAAe,MAAM,EAAa,EAAS,CAEjD,MAAM,EACH,OAAO,EAAU,CACjB,IAAI,CACH,SAAU,EACX,CAAC,CACD,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAMpC,eAAsB,EACpB,EACA,EACe,CACf,MAAM,EACH,OAAO,EAAU,CACjB,IAAI,CACG,OACP,CAAC,CACD,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAKpC,eAAsB,EACpB,EACA,EACe,CACf,MAAM,EACH,OAAO,EAAU,CACjB,IAAI,CACH,QACD,CAAC,CACD,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAMpC,eAAsB,EACpB,EACA,EACe,CACf,MAAM,EACH,OAAO,EAAU,CACjB,IAAI,CACI,QACP,gBAAiB,IAAI,KACtB,CAAC,CACD,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAMpC,eAAsB,EACpB,EACA,EACkB,CASlB,OARe,MAAM,EAClB,OAAO,EAAU,CACjB,IAAI,CACH,gBAAiB,IAAI,KACtB,CAAC,CACD,MAAM,EAAI,EAAG,EAAU,GAAI,EAAO,CAAE,EAAG,EAAU,MAAO,EAAM,CAAC,CAAC,CAChE,UAAU,CAAE,GAAI,EAAU,GAAI,CAAC,EAEpB,OAAS,EAMzB,eAAsB,EACpB,EACwB,CACxB,GAAM,CAAC,GAAQ,MAAM,EAClB,OAAO,CACN,SAAU,EAAU,SACrB,CAAC,CACD,KAAK,EAAU,CACf,MAAM,EAAG,EAAU,GAAI,EAAO,CAAC,CAElC,GAAI,CAAC,EACH,MAAU,MAAM,iBAAiB,CAGnC,OAAO,EAAK,SAMd,eAAsB,EAAiB,EAAqC,CAC1E,GAAM,CAAC,GAAQ,MAAM,EAClB,QAAQ,CACR,KAAK,EAAU,CACf,MAAM,EAAG,EAAU,MAAO,EAAM,CAAC,CAEpC,GAAI,CAAC,EAAM,OAAO,KAClB,GAAM,CAAE,WAAU,gBAAe,GAAG,GAAa,EACjD,OAAO"}
@@ -1,15 +0,0 @@
1
- import { schema_d_exports } from "./schema.mjs";
2
- import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
-
4
- //#region src/server/database/inject.d.ts
5
- type KryoDatabase = NodePgDatabase<typeof schema_d_exports>;
6
- declare function injectDb(db: KryoDatabase): void;
7
- /**
8
- * Shared 'db' proxy.
9
- * Resolves to globalThis.__KRYO_DB__ on every property access.
10
- * Safe to import statically at top-level.
11
- */
12
- declare const db: KryoDatabase;
13
- //#endregion
14
- export { KryoDatabase, db, injectDb };
15
- //# sourceMappingURL=inject.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inject.d.mts","names":[],"sources":["../../../src/server/database/inject.ts"],"mappings":";;;;KAGY,YAAA,GAAe,cAAA,QAAsB,gBAAA;AAAA,iBAKjC,QAAA,CAAS,EAAA,EAAI,YAAA;AAL7B;;;;;AAAA,cAgBa,EAAA,EAAE,YAAA"}
@@ -1,2 +0,0 @@
1
- const e=globalThis;function t(t){e.__KRYO_DB__||=(console.log(`[Kryo:Core] >>> DATABASE INJECTED <<<`),t)}const n=new Proxy({},{get(t,n){if(n===`then`)return;if(typeof n==`symbol`||n===`inspect`||n===`toString`)return e.__KRYO_DB__?.[n];let r=e.__KRYO_DB__;if(!r)throw Error(`[Kryo:Core] Database access error: tried to use "db.${String(n)}" but database is not injected yet. Ensure you call "ensureSystemInitialized()" before using the database.`);return r[n]}});export{n as db,t as injectDb};
2
- //# sourceMappingURL=inject.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inject.mjs","names":[],"sources":["../../../src/server/database/inject.ts"],"sourcesContent":["import type { NodePgDatabase } from \"drizzle-orm/node-postgres\";\nimport type * as schema from \"./schema\";\n\nexport type KryoDatabase = NodePgDatabase<typeof schema>;\n\n// Use globalThis to persist the DB across multiple bundles/instances\nconst globalForDb = globalThis as any;\n\nexport function injectDb(db: KryoDatabase) {\n if (globalForDb.__KRYO_DB__) return;\n console.log(\"[Kryo:Core] >>> DATABASE INJECTED <<<\");\n globalForDb.__KRYO_DB__ = db;\n}\n\n/**\n * Shared 'db' proxy.\n * Resolves to globalThis.__KRYO_DB__ on every property access.\n * Safe to import statically at top-level.\n */\nexport const db = new Proxy({} as KryoDatabase, {\n get(_, prop) {\n if (prop === \"then\") return undefined;\n\n // Internal Drizzle/Node/Debug checks\n if (typeof prop === \"symbol\" || prop === \"inspect\" || prop === \"toString\") {\n return (globalForDb.__KRYO_DB__ as any)?.[prop];\n }\n\n const database = globalForDb.__KRYO_DB__;\n\n if (!database) {\n throw new Error(\n `[Kryo:Core] Database access error: tried to use \"db.${String(prop)}\" but database is not injected yet. Ensure you call \"ensureSystemInitialized()\" before using the database.`,\n );\n }\n\n return (database as any)[prop];\n },\n});\n"],"mappings":"AAMA,MAAM,EAAc,WAEpB,SAAgB,EAAS,EAAkB,CACrC,AAEJ,EAAY,eADZ,QAAQ,IAAI,wCAAwC,CAC1B,GAQ5B,MAAa,EAAK,IAAI,MAAM,EAAE,CAAkB,CAC9C,IAAI,EAAG,EAAM,CACX,GAAI,IAAS,OAAQ,OAGrB,GAAI,OAAO,GAAS,UAAY,IAAS,WAAa,IAAS,WAC7D,OAAQ,EAAY,cAAsB,GAG5C,IAAM,EAAW,EAAY,YAE7B,GAAI,CAAC,EACH,MAAU,MACR,uDAAuD,OAAO,EAAK,CAAC,4GACrE,CAGH,OAAQ,EAAiB,IAE5B,CAAC"}