@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,28 +1,25 @@
1
- //#region src/core/auth/utils/encryption.d.ts
2
1
  /**
3
2
  * Encrypts data using AES-128-GCM.
4
3
  * @param data Data to be encrypted.
5
4
  * @returns Encrypted data including IV and auth tag.
6
5
  */
7
- declare function encrypt(data: Uint8Array): Uint8Array;
6
+ export declare function encrypt(data: Uint8Array): Uint8Array;
8
7
  /**
9
8
  * Encrypts a string.
10
9
  * @param data String to be encrypted.
11
10
  * @returns Encrypted data as Uint8Array.
12
11
  */
13
- declare function encryptString(data: string): Uint8Array;
12
+ export declare function encryptString(data: string): Uint8Array;
14
13
  /**
15
14
  * Decrypts data using AES-128-GCM.
16
15
  * @param encrypted Encrypted data (IV + content + auth tag).
17
16
  * @returns Decrypted data.
18
17
  */
19
- declare function decrypt(encrypted: Uint8Array): Uint8Array;
18
+ export declare function decrypt(encrypted: Uint8Array): Uint8Array;
20
19
  /**
21
20
  * Decrypts data to a string.
22
21
  * @param data Encrypted data.
23
22
  * @returns Odszyfrowany ciąg znaków.
24
23
  */
25
- declare function decryptToString(data: Uint8Array): string;
26
- //#endregion
27
- export { decrypt, decryptToString, encrypt, encryptString };
28
- //# sourceMappingURL=encryption.d.mts.map
24
+ export declare function decryptToString(data: Uint8Array): string;
25
+ //# sourceMappingURL=encryption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../../src/core/auth/utils/encryption.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAUpD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,UAAU,GAAG,UAAU,CAezD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAExD"}
@@ -0,0 +1,62 @@
1
+ import { createCipheriv, createDecipheriv } from "node:crypto";
2
+ import { DynamicBuffer } from "@oslojs/binary";
3
+ import { decodeBase64 } from "@oslojs/encoding";
4
+ const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY;
5
+ if (!ENCRYPTION_KEY) {
6
+ throw new Error("ENCRYPTION_KEY environment variable is not set");
7
+ }
8
+ /**
9
+ * The encryption key decoded from base64.
10
+ */
11
+ const key = decodeBase64(ENCRYPTION_KEY);
12
+ /**
13
+ * Encrypts data using AES-128-GCM.
14
+ * @param data Data to be encrypted.
15
+ * @returns Encrypted data including IV and auth tag.
16
+ */
17
+ export function encrypt(data) {
18
+ const iv = new Uint8Array(16);
19
+ crypto.getRandomValues(iv);
20
+ const cipher = createCipheriv("aes-128-gcm", key, iv);
21
+ const encrypted = new DynamicBuffer(0);
22
+ encrypted.write(iv);
23
+ encrypted.write(cipher.update(data));
24
+ encrypted.write(cipher.final());
25
+ encrypted.write(cipher.getAuthTag());
26
+ return encrypted.bytes();
27
+ }
28
+ /**
29
+ * Encrypts a string.
30
+ * @param data String to be encrypted.
31
+ * @returns Encrypted data as Uint8Array.
32
+ */
33
+ export function encryptString(data) {
34
+ return encrypt(new TextEncoder().encode(data));
35
+ }
36
+ /**
37
+ * Decrypts data using AES-128-GCM.
38
+ * @param encrypted Encrypted data (IV + content + auth tag).
39
+ * @returns Decrypted data.
40
+ */
41
+ export function decrypt(encrypted) {
42
+ if (encrypted.byteLength < 33) {
43
+ throw new Error("Invalid encrypted data length");
44
+ }
45
+ const iv = encrypted.slice(0, 16);
46
+ const authTag = encrypted.slice(encrypted.byteLength - 16);
47
+ const content = encrypted.slice(16, encrypted.byteLength - 16);
48
+ const decipher = createDecipheriv("aes-128-gcm", key, iv);
49
+ decipher.setAuthTag(authTag);
50
+ const decrypted = new DynamicBuffer(0);
51
+ decrypted.write(decipher.update(content));
52
+ decrypted.write(decipher.final());
53
+ return decrypted.bytes();
54
+ }
55
+ /**
56
+ * Decrypts data to a string.
57
+ * @param data Encrypted data.
58
+ * @returns Odszyfrowany ciąg znaków.
59
+ */
60
+ export function decryptToString(data) {
61
+ return new TextDecoder().decode(decrypt(data));
62
+ }
@@ -0,0 +1,44 @@
1
+ import { z } from "zod";
2
+ export declare const loginSchema: z.ZodObject<{
3
+ email: z.ZodString;
4
+ password: z.ZodString;
5
+ remember: z.ZodOptional<z.ZodBoolean>;
6
+ }, z.core.$strip>;
7
+ export declare const registerSchema: z.ZodObject<{
8
+ username: z.ZodString;
9
+ email: z.ZodString;
10
+ password: z.ZodString;
11
+ terms: z.ZodBoolean;
12
+ }, z.core.$strip>;
13
+ export declare const forgotPasswordSchema: z.ZodObject<{
14
+ email: z.ZodString;
15
+ }, z.core.$strip>;
16
+ export declare const resetPasswordSchema: z.ZodObject<{
17
+ password: z.ZodString;
18
+ confirm: z.ZodString;
19
+ }, z.core.$strip>;
20
+ export declare const verifyEmailSchema: z.ZodObject<{
21
+ code: z.ZodString;
22
+ }, z.core.$strip>;
23
+ export declare const totpSetupSchema: z.ZodObject<{
24
+ code: z.ZodString;
25
+ }, z.core.$strip>;
26
+ export declare const totpVerifySchema: z.ZodObject<{
27
+ code: z.ZodString;
28
+ }, z.core.$strip>;
29
+ export declare const passkeysSetupSchema: z.ZodObject<{
30
+ name: z.ZodString;
31
+ }, z.core.$strip>;
32
+ export declare const recoveryCodeVerifySchema: z.ZodObject<{
33
+ code: z.ZodString;
34
+ }, z.core.$strip>;
35
+ export type LoginInput = z.infer<typeof loginSchema>;
36
+ export type RegisterInput = z.infer<typeof registerSchema>;
37
+ export type ForgotPasswordInput = z.infer<typeof forgotPasswordSchema>;
38
+ export type ResetPasswordInput = z.infer<typeof resetPasswordSchema>;
39
+ export type TOTPSetupInput = z.infer<typeof totpSetupSchema>;
40
+ export type TOTPVerifyInput = z.infer<typeof totpVerifySchema>;
41
+ export type PasskeysSetupInput = z.infer<typeof passkeysSetupSchema>;
42
+ export type VerifyEmailInput = z.infer<typeof verifyEmailSchema>;
43
+ export type RecoveryVerifyInput = z.infer<typeof recoveryCodeVerifySchema>;
44
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/core/auth/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,WAAW;;;;iBAItB,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;iBAKzB,CAAC;AAEH,eAAO,MAAM,oBAAoB;;iBAE/B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;iBAQ5B,CAAC;AAEL,eAAO,MAAM,iBAAiB;;iBAE5B,CAAC;AAGH,eAAO,MAAM,eAAe;;iBAE1B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;iBAE3B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;iBAE9B,CAAC;AAEH,eAAO,MAAM,wBAAwB;;iBAEnC,CAAC;AAGH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC3D,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACvE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACrE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC/D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACrE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACjE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ // Auth validation schemas - CLEAN (No DB dependencies for client-side)
3
+ export const loginSchema = z.object({
4
+ email: z.string().email("Invalid email address"),
5
+ password: z.string().min(8),
6
+ remember: z.boolean().optional(),
7
+ });
8
+ export const registerSchema = z.object({
9
+ username: z.string().min(2, "Name must be at least 2 characters"),
10
+ email: z.string().email("Invalid email address"),
11
+ password: z.string().min(8, "Password must be at least 8 characters"),
12
+ terms: z.boolean().refine((val) => val === true, "You must accept the terms"),
13
+ });
14
+ export const forgotPasswordSchema = z.object({
15
+ email: z.string().email("Invalid email address"),
16
+ });
17
+ export const resetPasswordSchema = z
18
+ .object({
19
+ password: z.string().min(8, "Password must be at least 8 characters"),
20
+ confirm: z.string(),
21
+ })
22
+ .refine((data) => data.password === data.confirm, {
23
+ message: "Passwords do not match",
24
+ path: ["confirm"],
25
+ });
26
+ export const verifyEmailSchema = z.object({
27
+ code: z.string().min(6).max(6),
28
+ });
29
+ // mfa validation schemas
30
+ export const totpSetupSchema = z.object({
31
+ code: z.string().regex(/^\d{6}$/, "Code must be 6 digits"),
32
+ });
33
+ export const totpVerifySchema = z.object({
34
+ code: z.string().regex(/^\d{6}$/, "Code must be 6 digits"),
35
+ });
36
+ export const passkeysSetupSchema = z.object({
37
+ name: z.string().min(1, "Passkey name is required"),
38
+ });
39
+ export const recoveryCodeVerifySchema = z.object({
40
+ code: z.string().min(16, "Recovery code is required").max(16),
41
+ });
@@ -0,0 +1,2 @@
1
+ export declare function ensureSystemInitialized(providedDb?: any): Promise<void>;
2
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/core/bootstrap.ts"],"names":[],"mappings":"AAQA,wBAAsB,uBAAuB,CAAC,UAAU,CAAC,EAAE,GAAG,iBAoD7D"}
@@ -0,0 +1,51 @@
1
+ import { injectDb } from "../server/database/inject";
2
+ import { initEmailVerification } from "./auth/email-verification";
3
+ import { eventBus } from "./event-bus";
4
+ import { filesystemService } from "./filesystem/index";
5
+ import { LocalFileProvider } from "./filesystem/providers/local";
6
+ import { notificationService } from "./notifications/service";
7
+ import { isSystemInstalled } from "./setup";
8
+ export async function ensureSystemInitialized(providedDb) {
9
+ if (typeof window !== "undefined")
10
+ return;
11
+ const g = globalThis;
12
+ // 1. Immediate injection if provided
13
+ if (providedDb) {
14
+ injectDb(providedDb);
15
+ }
16
+ // 2. Prevent infinite recursion and double initialization
17
+ if (g.__KRYO_INITIALIZED__)
18
+ return;
19
+ if (g.__KRYO_INITIALIZING__)
20
+ return; // Already in progress, don't block/deadlock
21
+ g.__KRYO_INITIALIZING__ = true;
22
+ try {
23
+ console.log("[Kryo:Bootstrap] Starting system initialization...");
24
+ // Check if we have DB after any possible injection
25
+ if (!g.__KRYO_DB__) {
26
+ console.warn("[Kryo:Bootstrap] DB not detected during bootstrap start. Trying to continue...");
27
+ }
28
+ // Check if system is installed before initializing modules
29
+ if (await isSystemInstalled()) {
30
+ // Order matters: services first, then modules (which use services)
31
+ notificationService.init();
32
+ await initEmailVerification();
33
+ // Auto-register local filesystem provider as a fallback
34
+ const local = new LocalFileProvider();
35
+ filesystemService.registerProvider(local);
36
+ filesystemService.setDefaultProvider(local.id);
37
+ }
38
+ else {
39
+ console.log("[Kryo:Bootstrap] System not installed. Skipping module initialization.");
40
+ }
41
+ await eventBus.publish("system:start", { runtime: "nodejs" });
42
+ console.log("[Kryo:Bootstrap] System initialized successfully.");
43
+ g.__KRYO_INITIALIZED__ = true;
44
+ }
45
+ catch (error) {
46
+ console.error("[Kryo:Bootstrap] Initialization failed:", error);
47
+ }
48
+ finally {
49
+ g.__KRYO_INITIALIZING__ = false;
50
+ }
51
+ }
@@ -0,0 +1,9 @@
1
+ export interface KryoConfig {
2
+ /**
3
+ * Path to the directory with local modules.
4
+ * Default: "./modules"
5
+ */
6
+ modulesDirectory?: string;
7
+ }
8
+ export declare const DEFAULT_CONFIG: KryoConfig;
9
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,cAAc,EAAE,UAE5B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const DEFAULT_CONFIG = {
2
+ modulesDirectory: "modules",
3
+ };
@@ -0,0 +1,12 @@
1
+ import { type KryoConfig } from "./config";
2
+ /**
3
+ * Loads the Kryo configuration from kryo.config.ts or kryo.config in the current working directory.
4
+ * SERVER ONLY.
5
+ */
6
+ export declare function getKryoConfig(): Promise<KryoConfig>;
7
+ /**
8
+ * Helper returning the absolute path to the modules directory.
9
+ * SERVER ONLY.
10
+ */
11
+ export declare function getModulesDir(): Promise<string>;
12
+ //# sourceMappingURL=config.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.server.d.ts","sourceRoot":"","sources":["../../src/core/config.server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAI3D;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,CAsDzD;AAED;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAKrD"}
@@ -0,0 +1,61 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { DEFAULT_CONFIG } from "./config";
4
+ let cachedConfig = null;
5
+ /**
6
+ * Loads the Kryo configuration from kryo.config.ts or kryo.config in the current working directory.
7
+ * SERVER ONLY.
8
+ */
9
+ export async function getKryoConfig() {
10
+ // Prevent this from ever running on the client even if imported
11
+ if (typeof window !== "undefined") {
12
+ throw new Error("getKryoConfig can only be called on the server.");
13
+ }
14
+ // Use memory cache in production
15
+ if (process.env.NODE_ENV === "production" && cachedConfig) {
16
+ return cachedConfig;
17
+ }
18
+ const cwd = process.cwd();
19
+ const configPathTS = path.join(cwd, "kryo.config.ts");
20
+ const configPathJS = path.join(cwd, "kryo.config");
21
+ const configPathMJS = path.join(cwd, "kryo.config.mjs");
22
+ let loadedConfig = {};
23
+ try {
24
+ // Dynamic import jiti only on server to avoid bundling issues
25
+ const { createJiti } = await import("jiti");
26
+ const jiti = createJiti(cwd, {
27
+ fsCache: false,
28
+ moduleCache: false,
29
+ });
30
+ if (fs.existsSync(configPathTS)) {
31
+ const cacheBuster = `?t=${Date.now()}`;
32
+ const imported = await jiti.import(`file://${configPathTS}${cacheBuster}`, { default: true });
33
+ loadedConfig = imported.default || imported;
34
+ }
35
+ else if (fs.existsSync(configPathMJS)) {
36
+ const imported = await jiti.import(configPathMJS, { default: true });
37
+ loadedConfig = imported.default || imported;
38
+ }
39
+ else if (fs.existsSync(configPathJS)) {
40
+ const imported = await jiti.import(configPathJS, { default: true });
41
+ loadedConfig = imported.default || imported;
42
+ }
43
+ }
44
+ catch (error) {
45
+ console.warn("[Kryo:Config] Could not load kryo.config.ts, using defaults.", error);
46
+ }
47
+ const finalConfig = { ...DEFAULT_CONFIG, ...loadedConfig };
48
+ if (process.env.NODE_ENV === "production") {
49
+ cachedConfig = finalConfig;
50
+ }
51
+ return finalConfig;
52
+ }
53
+ /**
54
+ * Helper returning the absolute path to the modules directory.
55
+ * SERVER ONLY.
56
+ */
57
+ export async function getModulesDir() {
58
+ const config = await getKryoConfig();
59
+ const dir = config.modulesDirectory || "modules";
60
+ return path.isAbsolute(dir) ? dir : path.join(process.cwd(), dir);
61
+ }
@@ -0,0 +1,14 @@
1
+ import type { EventHandler } from "./types";
2
+ /**
3
+ * EventBus (Pub/Sub) - Global Singleton Pattern.
4
+ */
5
+ declare class EventBus {
6
+ private handlers;
7
+ subscribe<T>(eventType: string, subscriberId: string, handler: EventHandler<T>): void;
8
+ unsubscribe(eventType: string, subscriberId: string): void;
9
+ clearAll(): void;
10
+ publish<T>(eventType: string, payload: T, source?: string): Promise<void>;
11
+ }
12
+ export declare const eventBus: EventBus;
13
+ export {};
14
+ //# sourceMappingURL=event-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/core/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,SAAS,CAAC;AAEzD;;GAEG;AACH,cAAM,QAAQ;IACZ,OAAO,CAAC,QAAQ,CAAqD;IAE9D,SAAS,CAAC,CAAC,EAChB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,IAAI;IAWA,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAO1D,QAAQ,IAAI,IAAI;IAKV,OAAO,CAAC,CAAC,EACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,EACV,MAAM,GAAE,MAAiB,GACxB,OAAO,CAAC,IAAI,CAAC;CA2BjB;AAOD,eAAO,MAAM,QAAQ,UAAyD,CAAC"}
@@ -0,0 +1,51 @@
1
+ var _a;
2
+ /**
3
+ * EventBus (Pub/Sub) - Global Singleton Pattern.
4
+ */
5
+ class EventBus {
6
+ constructor() {
7
+ this.handlers = new Map();
8
+ }
9
+ subscribe(eventType, subscriberId, handler) {
10
+ if (!this.handlers.has(eventType)) {
11
+ this.handlers.set(eventType, new Map());
12
+ }
13
+ const eventHandlers = this.handlers.get(eventType);
14
+ eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.set(subscriberId, handler);
15
+ console.log(`[Event Bus] Subscriber "${subscriberId}" added for "${eventType}"`);
16
+ }
17
+ unsubscribe(eventType, subscriberId) {
18
+ var _a;
19
+ (_a = this.handlers.get(eventType)) === null || _a === void 0 ? void 0 : _a.delete(subscriberId);
20
+ console.log(`[Event Bus] Subscriber "${subscriberId}" removed from "${eventType}"`);
21
+ }
22
+ clearAll() {
23
+ console.log("[Event Bus] Resetting all listeners...");
24
+ this.handlers.clear();
25
+ }
26
+ async publish(eventType, payload, source = "system") {
27
+ const eventHandlers = this.handlers.get(eventType);
28
+ if (!eventHandlers)
29
+ return;
30
+ const handlers = Array.from(eventHandlers.values());
31
+ console.log(`[Event Bus] Publishing "${eventType}" to ${handlers.length} subscribers`);
32
+ const event = {
33
+ type: eventType,
34
+ payload,
35
+ timestamp: Date.now(),
36
+ source,
37
+ };
38
+ await Promise.all(handlers.map(async (handler) => {
39
+ try {
40
+ await handler(event);
41
+ }
42
+ catch (error) {
43
+ console.error(`[Event Bus] Handler Error for ${eventType}:`, error);
44
+ }
45
+ }));
46
+ }
47
+ }
48
+ // Ensure global singleton
49
+ const globalForEventBus = globalThis;
50
+ export const eventBus = (_a = globalForEventBus.__KRYO_EVENT_BUS__) !== null && _a !== void 0 ? _a : new EventBus();
51
+ globalForEventBus.__KRYO_EVENT_BUS__ = eventBus;
@@ -0,0 +1,4 @@
1
+ import { filesystemService } from "./service";
2
+ export * from "./types";
3
+ export { filesystemService };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/filesystem/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { LocalFileProvider } from "./providers/local";
2
+ import { filesystemService } from "./service";
3
+ export * from "./types";
4
+ export { filesystemService };
5
+ // Auto-register local provider
6
+ if (typeof window === "undefined") {
7
+ const local = new LocalFileProvider();
8
+ filesystemService.registerProvider(local);
9
+ filesystemService.setDefaultProvider(local.id);
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { IStorageProvider, StorageResult } from "../types";
2
+ export declare class LocalFileProvider implements IStorageProvider {
3
+ id: string;
4
+ name: string;
5
+ private generateUniqueImageName;
6
+ upload(file: File): Promise<StorageResult>;
7
+ }
8
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../../src/core/filesystem/providers/local.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEhE,qBAAa,iBAAkB,YAAW,gBAAgB;IACjD,EAAE,SAAW;IACb,IAAI,SAAsB;IAEjC,OAAO,CAAC,uBAAuB;IAUlB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC;CA4BxD"}
@@ -0,0 +1,42 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ export class LocalFileProvider {
4
+ constructor() {
5
+ this.id = "local";
6
+ this.name = "Local Filesystem";
7
+ }
8
+ generateUniqueImageName(name) {
9
+ const cleanName = name.replace(/\s+/g, "-").toLowerCase();
10
+ const suffix = Math.floor(Math.random() * Date.now()).toString(36);
11
+ const index = cleanName.lastIndexOf(".");
12
+ return index < 0
13
+ ? `${cleanName}-${suffix}`
14
+ : `${cleanName.slice(0, index)}-${suffix}${cleanName.slice(index)}`;
15
+ }
16
+ async upload(file) {
17
+ var _a;
18
+ try {
19
+ const storageFolder = (_a = process.env.FILE_STORAGE_FOLDER) !== null && _a !== void 0 ? _a : "public/storage";
20
+ if (!fs.existsSync(storageFolder)) {
21
+ fs.mkdirSync(storageFolder, { recursive: true });
22
+ }
23
+ const name = this.generateUniqueImageName(file.name);
24
+ const filePath = path.join(storageFolder, name);
25
+ const buffer = await file.arrayBuffer();
26
+ fs.writeFileSync(filePath, Buffer.from(buffer));
27
+ const url = `${storageFolder}/${name}`.replace("public", "");
28
+ return {
29
+ name: name,
30
+ url,
31
+ type: file.type,
32
+ size: file.size,
33
+ service: "local",
34
+ serviceId: filePath,
35
+ };
36
+ }
37
+ catch (error) {
38
+ console.error("Error uploading file", error);
39
+ return { error: "Error uploading file" };
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ import type { IStorageProvider, StorageResult } from "./types";
2
+ declare class FilesystemService {
3
+ private providers;
4
+ private defaultProviderId;
5
+ registerProvider(provider: IStorageProvider): void;
6
+ unregisterProvider(id: string): void;
7
+ setDefaultProvider(id: string): void;
8
+ upload(file: File, providerId?: string): Promise<StorageResult>;
9
+ getProviders(): {
10
+ id: string;
11
+ name: string;
12
+ }[];
13
+ }
14
+ export declare const filesystemService: FilesystemService;
15
+ export {};
16
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/core/filesystem/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE/D,cAAM,iBAAiB;IACrB,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,iBAAiB,CAAuB;IAEzC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB;IAQ3C,kBAAkB,CAAC,EAAE,EAAE,MAAM;IAU7B,kBAAkB,CAAC,EAAE,EAAE,MAAM;IAOvB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBrE,YAAY;;;;CAMpB;AAOD,eAAO,MAAM,iBAAiB,mBAC8C,CAAC"}
@@ -0,0 +1,51 @@
1
+ var _a;
2
+ class FilesystemService {
3
+ constructor() {
4
+ this.providers = new Map();
5
+ this.defaultProviderId = null;
6
+ }
7
+ registerProvider(provider) {
8
+ this.providers.set(provider.id, provider);
9
+ if (!this.defaultProviderId || this.defaultProviderId === "local") {
10
+ this.defaultProviderId = provider.id;
11
+ }
12
+ console.log(`[Filesystem] Provider registered: ${provider.id}`);
13
+ }
14
+ unregisterProvider(id) {
15
+ this.providers.delete(id);
16
+ if (this.defaultProviderId === id) {
17
+ this.defaultProviderId = this.providers.has("local")
18
+ ? "local"
19
+ : Array.from(this.providers.keys())[0] || null;
20
+ }
21
+ console.log(`[Filesystem] Provider unregistered: ${id}`);
22
+ }
23
+ setDefaultProvider(id) {
24
+ if (this.providers.has(id)) {
25
+ this.defaultProviderId = id;
26
+ console.log(`[Filesystem] Default provider set to: ${id}`);
27
+ }
28
+ }
29
+ async upload(file, providerId) {
30
+ let id = providerId || this.defaultProviderId;
31
+ // Fallback logic
32
+ if (!id || !this.providers.has(id)) {
33
+ id = "local";
34
+ }
35
+ const provider = this.providers.get(id);
36
+ if (!provider) {
37
+ return { error: "No storage provider available (local fallback failed)" };
38
+ }
39
+ return await provider.upload(file);
40
+ }
41
+ getProviders() {
42
+ return Array.from(this.providers.values()).map((p) => ({
43
+ id: p.id,
44
+ name: p.name,
45
+ }));
46
+ }
47
+ }
48
+ // Global Singleton Pattern
49
+ const globalForFilesystem = globalThis;
50
+ export const filesystemService = (_a = globalForFilesystem.__KRYO_FILESYSTEM_SERVICE__) !== null && _a !== void 0 ? _a : new FilesystemService();
51
+ globalForFilesystem.__KRYO_FILESYSTEM_SERVICE__ = filesystemService;
@@ -0,0 +1,19 @@
1
+ export interface StorageData {
2
+ name: string;
3
+ url: string;
4
+ type: string;
5
+ size: number;
6
+ service: string;
7
+ serviceId: string;
8
+ }
9
+ export interface StorageError {
10
+ error: string;
11
+ }
12
+ export type StorageResult = StorageData | StorageError;
13
+ export interface IStorageProvider {
14
+ id: string;
15
+ name: string;
16
+ upload(file: File, options?: any): Promise<StorageResult>;
17
+ delete?(serviceId: string): Promise<boolean>;
18
+ }
19
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/filesystem/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,YAAY,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1D,MAAM,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ import type { CreateNotificationPayload } from "./types";
2
+ export declare function getUserNotifications(): Promise<{
3
+ id: string;
4
+ title: string;
5
+ content: string | null;
6
+ target: string | null;
7
+ type: string | null;
8
+ isRead: boolean;
9
+ resourceId: string | null;
10
+ resourceType: string | null;
11
+ userId: string;
12
+ createdAt: Date;
13
+ updatedAt: Date | null;
14
+ }[] | null>;
15
+ export declare function createNotification(data: CreateNotificationPayload): Promise<{
16
+ id: string;
17
+ createdAt: Date;
18
+ updatedAt: Date | null;
19
+ userId: string;
20
+ title: string;
21
+ content: string | null;
22
+ target: string | null;
23
+ type: string | null;
24
+ isRead: boolean;
25
+ resourceId: string | null;
26
+ resourceType: string | null;
27
+ }>;
28
+ export declare function markNotificationAsRead(id: string): Promise<{
29
+ id: string;
30
+ title: string;
31
+ content: string | null;
32
+ target: string | null;
33
+ type: string | null;
34
+ isRead: boolean;
35
+ resourceId: string | null;
36
+ resourceType: string | null;
37
+ userId: string;
38
+ createdAt: Date;
39
+ updatedAt: Date | null;
40
+ }>;
41
+ export declare function markAllNotificationsAsRead(): Promise<{
42
+ id: string;
43
+ title: string;
44
+ content: string | null;
45
+ target: string | null;
46
+ type: string | null;
47
+ isRead: boolean;
48
+ resourceId: string | null;
49
+ resourceType: string | null;
50
+ userId: string;
51
+ createdAt: Date;
52
+ updatedAt: Date | null;
53
+ }[] | null>;
54
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/core/notifications/actions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEzD,wBAAsB,oBAAoB;;;;;;;;;;;;YASzC;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,yBAAyB;;;;;;;;;;;;GAUvE;AAED,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;;;GAQtD;AAED,wBAAsB,0BAA0B;;;;;;;;;;;;YAS/C"}