@arch-cadre/core 0.0.38 → 0.0.40

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 (110) 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 +53 -0
  4. package/dist/core/auth/email-verification.d.mts +2 -2
  5. package/dist/core/auth/email-verification.d.ts +58 -0
  6. package/dist/core/auth/email-verification.d.ts.map +1 -0
  7. package/dist/core/auth/email-verification.js +115 -0
  8. package/dist/core/auth/events.d.ts +53 -0
  9. package/dist/core/auth/events.d.ts.map +1 -0
  10. package/dist/core/auth/events.js +2 -0
  11. package/dist/core/auth/logic.d.mts +6 -6
  12. package/dist/core/auth/logic.d.ts +106 -0
  13. package/dist/core/auth/logic.d.ts.map +1 -0
  14. package/dist/core/auth/logic.js +264 -0
  15. package/dist/core/auth/password-reset.d.ts +35 -0
  16. package/dist/core/auth/password-reset.d.ts.map +1 -0
  17. package/dist/core/auth/password-reset.js +132 -0
  18. package/dist/core/auth/rbac.d.mts +2 -2
  19. package/dist/core/auth/rbac.d.ts +56 -0
  20. package/dist/core/auth/rbac.d.ts.map +1 -0
  21. package/dist/core/auth/rbac.js +151 -0
  22. package/dist/core/auth/session.d.ts +50 -0
  23. package/dist/core/auth/session.d.ts.map +1 -0
  24. package/dist/core/auth/session.js +167 -0
  25. package/dist/core/auth/types.d.ts +52 -0
  26. package/dist/core/auth/types.d.ts.map +1 -0
  27. package/dist/core/auth/types.js +2 -0
  28. package/dist/core/auth/utils/encode.d.ts +12 -0
  29. package/dist/core/auth/utils/encode.d.ts.map +1 -0
  30. package/dist/core/auth/utils/encode.js +24 -0
  31. package/dist/core/auth/utils/encryption.d.ts +25 -0
  32. package/dist/core/auth/utils/encryption.d.ts.map +1 -0
  33. package/dist/core/auth/utils/encryption.js +68 -0
  34. package/dist/core/auth/validation.d.ts +44 -0
  35. package/dist/core/auth/validation.d.ts.map +1 -0
  36. package/dist/core/auth/validation.js +44 -0
  37. package/dist/core/bootstrap.d.ts +2 -0
  38. package/dist/core/bootstrap.d.ts.map +1 -0
  39. package/dist/core/bootstrap.js +54 -0
  40. package/dist/core/config.d.ts +9 -0
  41. package/dist/core/config.d.ts.map +1 -0
  42. package/dist/core/config.js +6 -0
  43. package/dist/core/config.server.d.ts +12 -0
  44. package/dist/core/config.server.d.ts.map +1 -0
  45. package/dist/core/config.server.js +101 -0
  46. package/dist/core/event-bus.d.ts +14 -0
  47. package/dist/core/event-bus.d.ts.map +1 -0
  48. package/dist/core/event-bus.js +54 -0
  49. package/dist/core/filesystem/index.d.ts +4 -0
  50. package/dist/core/filesystem/index.d.ts.map +1 -0
  51. package/dist/core/filesystem/index.js +27 -0
  52. package/dist/core/filesystem/providers/local.d.ts +8 -0
  53. package/dist/core/filesystem/providers/local.d.ts.map +1 -0
  54. package/dist/core/filesystem/providers/local.js +49 -0
  55. package/dist/core/filesystem/service.d.ts +16 -0
  56. package/dist/core/filesystem/service.d.ts.map +1 -0
  57. package/dist/core/filesystem/service.js +54 -0
  58. package/dist/core/filesystem/types.d.ts +19 -0
  59. package/dist/core/filesystem/types.d.ts.map +1 -0
  60. package/dist/core/filesystem/types.js +2 -0
  61. package/dist/core/notifications/actions.d.mts +1 -1
  62. package/dist/core/notifications/actions.d.ts +54 -0
  63. package/dist/core/notifications/actions.d.ts.map +1 -0
  64. package/dist/core/notifications/actions.js +49 -0
  65. package/dist/core/notifications/index.d.ts +4 -0
  66. package/dist/core/notifications/index.d.ts.map +1 -0
  67. package/dist/core/notifications/index.js +19 -0
  68. package/dist/core/notifications/service.d.ts +7 -0
  69. package/dist/core/notifications/service.d.ts.map +1 -0
  70. package/dist/core/notifications/service.js +35 -0
  71. package/dist/core/notifications/types.d.ts +17 -0
  72. package/dist/core/notifications/types.d.ts.map +1 -0
  73. package/dist/core/notifications/types.js +2 -0
  74. package/dist/core/setup.d.ts +6 -0
  75. package/dist/core/setup.d.ts.map +1 -0
  76. package/dist/core/setup.js +28 -0
  77. package/dist/core/types.d.ts +10 -0
  78. package/dist/core/types.d.ts.map +1 -0
  79. package/dist/core/types.js +2 -0
  80. package/dist/index.d.ts +8 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +32 -0
  83. package/dist/server/auth/email.d.ts +10 -0
  84. package/dist/server/auth/email.d.ts.map +1 -0
  85. package/dist/server/auth/email.js +24 -0
  86. package/dist/server/auth/password.d.ts +20 -0
  87. package/dist/server/auth/password.d.ts.map +1 -0
  88. package/dist/server/auth/password.js +38 -0
  89. package/dist/server/auth/types.d.ts +13 -0
  90. package/dist/server/auth/types.d.ts.map +1 -0
  91. package/dist/server/auth/types.js +17 -0
  92. package/dist/server/auth/user.d.ts +54 -0
  93. package/dist/server/auth/user.d.ts.map +1 -0
  94. package/dist/server/auth/user.js +237 -0
  95. package/dist/server/database/inject.d.ts +11 -0
  96. package/dist/server/database/inject.d.ts.map +1 -0
  97. package/dist/server/database/inject.js +33 -0
  98. package/dist/server/database/schema.d.ts +2953 -0
  99. package/dist/server/database/schema.d.ts.map +1 -0
  100. package/dist/server/database/schema.js +195 -0
  101. package/dist/server/database/types.d.ts +12 -0
  102. package/dist/server/database/types.d.ts.map +1 -0
  103. package/dist/server/database/types.js +2 -0
  104. package/dist/server/emails/index.d.ts +23 -0
  105. package/dist/server/emails/index.d.ts.map +1 -0
  106. package/dist/server/emails/index.js +73 -0
  107. package/dist/server.d.ts +25 -0
  108. package/dist/server.d.ts.map +1 -0
  109. package/dist/server.js +48 -0
  110. package/package.json +7 -6
@@ -0,0 +1,50 @@
1
+ import type { AuthSession, Session, SessionFlags, UserSession } from "./types";
2
+ /**
3
+ * Returns the user's IP address.
4
+ */
5
+ export declare function getIPAddress(): Promise<string | null>;
6
+ /**
7
+ * Validates the session token.
8
+ */
9
+ export declare function validateSessionToken(token: string): Promise<AuthSession>;
10
+ /**
11
+ * Returns the current user session from cookies.
12
+ */
13
+ export declare const getCurrentSession: () => Promise<AuthSession>;
14
+ /**
15
+ * Invalidates a single session.
16
+ */
17
+ export declare function invalidateSession(sessionId: string): Promise<void>;
18
+ /**
19
+ * Invalidates all user sessions.
20
+ */
21
+ export declare function invalidateUserSessions(userId: string): Promise<void>;
22
+ /**
23
+ * Sets the session token in a cookie.
24
+ */
25
+ export declare function setSessionTokenCookie(token: string, expiresAt: Date): Promise<void>;
26
+ /**
27
+ * Removes the session token cookie.
28
+ */
29
+ export declare function deleteSessionTokenCookie(): Promise<void>;
30
+ /**
31
+ * Generates a new random session token.
32
+ */
33
+ export declare function generateSessionToken(): Promise<string>;
34
+ /**
35
+ * Creates a new session in the database.
36
+ */
37
+ export declare function createSession(token: string, userId: string, flags: SessionFlags): Promise<Session>;
38
+ /**
39
+ * Signs the user out and redirects to the sign-in page.
40
+ */
41
+ export declare function sessionSignOut(): Promise<void>;
42
+ /**
43
+ * Get all active sessions for a user.
44
+ */
45
+ export declare function getUserSessions(userId: string, currentSessionId: string): Promise<UserSession[]>;
46
+ /**
47
+ * Invalidate all sessions for a user except the specified current one.
48
+ */
49
+ export declare function invalidateOtherSessions(userId: string, currentSessionId: string): Promise<void>;
50
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/core/auth/session.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACP,YAAY,EAEZ,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE3D;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,WAAW,CAAC,CAoCtB;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,WAAW,CAS7D,CAAC;AAEF;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExE;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1E;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,IAAI,GACd,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;GAEG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC,CAG9D;AAED;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAI5D;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,OAAO,CAAC,CAclB;AAED;;GAEG;AACH,wBAAsB,cAAc,kBASnC;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,WAAW,EAAE,CAAC,CAYxB;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ "use server";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getCurrentSession = void 0;
5
+ exports.getIPAddress = getIPAddress;
6
+ exports.validateSessionToken = validateSessionToken;
7
+ exports.invalidateSession = invalidateSession;
8
+ exports.invalidateUserSessions = invalidateUserSessions;
9
+ exports.setSessionTokenCookie = setSessionTokenCookie;
10
+ exports.deleteSessionTokenCookie = deleteSessionTokenCookie;
11
+ exports.generateSessionToken = generateSessionToken;
12
+ exports.createSession = createSession;
13
+ exports.sessionSignOut = sessionSignOut;
14
+ exports.getUserSessions = getUserSessions;
15
+ exports.invalidateOtherSessions = invalidateOtherSessions;
16
+ const sha2_1 = require("@oslojs/crypto/sha2");
17
+ const encoding_1 = require("@oslojs/encoding");
18
+ const date_fns_1 = require("date-fns");
19
+ const drizzle_orm_1 = require("drizzle-orm");
20
+ const headers_1 = require("next/headers");
21
+ const navigation_1 = require("next/navigation");
22
+ const inject_1 = require("../../server/database/inject");
23
+ const schema_1 = require("../../server/database/schema");
24
+ const augment_1 = require("./augment");
25
+ const logic_1 = require("./logic");
26
+ /**
27
+ * Returns the user's IP address.
28
+ */
29
+ async function getIPAddress() {
30
+ return (await (0, headers_1.headers)()).get("x-forwarded-for");
31
+ }
32
+ /**
33
+ * Validates the session token.
34
+ */
35
+ async function validateSessionToken(token) {
36
+ const sessionId = (0, encoding_1.encodeHexLowerCase)((0, sha2_1.sha256)(new TextEncoder().encode(token)));
37
+ const [row] = await inject_1.db
38
+ .select({
39
+ session: schema_1.sessionTable,
40
+ user: schema_1.userTable,
41
+ })
42
+ .from(schema_1.sessionTable)
43
+ .innerJoin(schema_1.userTable, (0, drizzle_orm_1.eq)(schema_1.sessionTable.userId, schema_1.userTable.id))
44
+ .where((0, drizzle_orm_1.eq)(schema_1.sessionTable.id, sessionId));
45
+ if (!row || !row.user) {
46
+ return { session: null, user: null };
47
+ }
48
+ const { session: baseSession, user: baseUser } = row;
49
+ // STRICTLY remove non-serializable and sensitive fields
50
+ const { password, recovery_code, ...safeUser } = baseUser;
51
+ // Check if session is expired
52
+ if (new Date() > baseSession.expiresAt) {
53
+ await inject_1.db.delete(schema_1.sessionTable).where((0, drizzle_orm_1.eq)(schema_1.sessionTable.id, baseSession.id));
54
+ return { session: null, user: null };
55
+ }
56
+ // AUGMENT (EXTENSIBILITY POINTS)
57
+ const augmentedUser = await (0, logic_1.performFullUserAugmentation)(safeUser);
58
+ const augmentedSession = await (0, augment_1.augmentSession)(baseSession);
59
+ // ENSURE PLAIN OBJECTS for Client Components
60
+ return {
61
+ session: augmentedSession ? { ...augmentedSession } : null,
62
+ user: augmentedUser ? { ...augmentedUser } : null,
63
+ };
64
+ }
65
+ /**
66
+ * Returns the current user session from cookies.
67
+ */
68
+ const getCurrentSession = async () => {
69
+ var _a, _b;
70
+ const cookieStore = await (0, headers_1.cookies)();
71
+ const token = (_b = (_a = cookieStore.get("session")) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
72
+ if (token === null) {
73
+ return { session: null, user: null };
74
+ }
75
+ return await validateSessionToken(token);
76
+ };
77
+ exports.getCurrentSession = getCurrentSession;
78
+ /**
79
+ * Invalidates a single session.
80
+ */
81
+ async function invalidateSession(sessionId) {
82
+ await inject_1.db.delete(schema_1.sessionTable).where((0, drizzle_orm_1.eq)(schema_1.sessionTable.id, sessionId));
83
+ }
84
+ /**
85
+ * Invalidates all user sessions.
86
+ */
87
+ async function invalidateUserSessions(userId) {
88
+ await inject_1.db.delete(schema_1.sessionTable).where((0, drizzle_orm_1.eq)(schema_1.sessionTable.userId, userId));
89
+ }
90
+ /**
91
+ * Sets the session token in a cookie.
92
+ */
93
+ async function setSessionTokenCookie(token, expiresAt) {
94
+ const cookieStore = await (0, headers_1.cookies)();
95
+ cookieStore.set("session", token, {
96
+ httpOnly: true,
97
+ path: "/",
98
+ secure: process.env.NODE_ENV === "production",
99
+ sameSite: "lax",
100
+ expires: expiresAt,
101
+ });
102
+ }
103
+ /**
104
+ * Removes the session token cookie.
105
+ */
106
+ async function deleteSessionTokenCookie() {
107
+ const cookieStore = await (0, headers_1.cookies)();
108
+ cookieStore.delete("session");
109
+ }
110
+ /**
111
+ * Generates a new random session token.
112
+ */
113
+ async function generateSessionToken() {
114
+ const tokenBytes = new Uint8Array(20);
115
+ crypto.getRandomValues(tokenBytes);
116
+ return (0, encoding_1.encodeBase32LowerCaseNoPadding)(tokenBytes).toLowerCase();
117
+ }
118
+ /**
119
+ * Creates a new session in the database.
120
+ */
121
+ async function createSession(token, userId, flags) {
122
+ const sessionId = (0, encoding_1.encodeHexLowerCase)((0, sha2_1.sha256)(new TextEncoder().encode(token)));
123
+ const [session] = await inject_1.db
124
+ .insert(schema_1.sessionTable)
125
+ .values({
126
+ id: sessionId,
127
+ expiresAt: new Date((0, date_fns_1.addDays)(new Date(), 7)),
128
+ active_organization_id: flags.activeOrganizationId,
129
+ userId: userId,
130
+ })
131
+ .returning();
132
+ return session;
133
+ }
134
+ /**
135
+ * Signs the user out and redirects to the sign-in page.
136
+ */
137
+ async function sessionSignOut() {
138
+ const { session } = await (0, exports.getCurrentSession)();
139
+ if (session) {
140
+ await invalidateSession(session.id);
141
+ await deleteSessionTokenCookie();
142
+ }
143
+ (0, navigation_1.redirect)("/signin");
144
+ }
145
+ /**
146
+ * Get all active sessions for a user.
147
+ */
148
+ async function getUserSessions(userId, currentSessionId) {
149
+ const sessions = await inject_1.db
150
+ .select()
151
+ .from(schema_1.sessionTable)
152
+ .where((0, drizzle_orm_1.eq)(schema_1.sessionTable.userId, userId));
153
+ return sessions.map((session) => ({
154
+ id: session.id,
155
+ createdAt: session.createdAt,
156
+ expiresAt: session.expiresAt,
157
+ isCurrent: session.id === currentSessionId,
158
+ }));
159
+ }
160
+ /**
161
+ * Invalidate all sessions for a user except the specified current one.
162
+ */
163
+ async function invalidateOtherSessions(userId, currentSessionId) {
164
+ await inject_1.db
165
+ .delete(schema_1.sessionTable)
166
+ .where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(schema_1.sessionTable.userId, userId), (0, drizzle_orm_1.ne)(schema_1.sessionTable.id, currentSessionId)));
167
+ }
@@ -0,0 +1,52 @@
1
+ import type { passwordResetSessionTable, sessionTable, userTable } from "../../server/database/schema";
2
+ import type { UserPermission, UserRole } from "../types";
3
+ export type { UserRole, UserPermission };
4
+ export type User = typeof userTable.$inferSelect;
5
+ export type Session = typeof sessionTable.$inferSelect & Record<string, any>;
6
+ export type PasswordResetSession = typeof passwordResetSessionTable.$inferSelect & Record<string, any>;
7
+ /**
8
+ * Represents a user with all potential extensions.
9
+ * Use this type in UI components that require data added by modules.
10
+ */
11
+ export type FullUser = User & Record<string, any> & {
12
+ roles: UserRole[];
13
+ permissions: UserPermission[];
14
+ };
15
+ /**
16
+ * Basic session context.
17
+ */
18
+ export interface AuthSession {
19
+ session: Session | null;
20
+ user: FullUser | null;
21
+ }
22
+ export interface SessionFlags {
23
+ [key: string]: any;
24
+ }
25
+ export type UserSession = {
26
+ id: string;
27
+ createdAt: Date;
28
+ expiresAt: Date;
29
+ isCurrent: boolean;
30
+ [key: string]: any;
31
+ };
32
+ export type AuthResponse = {
33
+ status: "SUCCESS";
34
+ session: Session;
35
+ user: FullUser;
36
+ redirect?: string;
37
+ } | {
38
+ status: "CHALLENGE_REQUIRED";
39
+ type: string;
40
+ userId: string;
41
+ tempToken?: string;
42
+ redirect?: string;
43
+ } | {
44
+ status: "ERROR";
45
+ message: string;
46
+ redirect?: string;
47
+ };
48
+ export interface PasswordResetAuthSession {
49
+ session: PasswordResetSession | null;
50
+ user: FullUser | null;
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACV,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzD,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;AAEzC,MAAM,MAAM,IAAI,GAAG,OAAO,SAAS,CAAC,YAAY,CAAC;AACjD,MAAM,MAAM,OAAO,GAAG,OAAO,YAAY,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7E,MAAM,MAAM,oBAAoB,GAC9B,OAAO,yBAAyB,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACpB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,WAAW,EAAE,cAAc,EAAE,CAAC;CAC/B,CAAC;AAEJ;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1E;IACA,MAAM,EAAE,oBAAoB,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACrC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generates a random one-time code (OTP).
3
+ * @param length Length of the generated code (default 6).
4
+ * @returns A random uppercase base32 string.
5
+ */
6
+ export declare function generateRandomOTP(length?: number): string;
7
+ /**
8
+ * Generates a random recovery code.
9
+ * @returns A random uppercase base32 string.
10
+ */
11
+ export declare function generateRandomRecoveryCode(): string;
12
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../../src/core/auth/utils/encode.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,SAAI,GAAG,MAAM,CAIpD;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAInD"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateRandomOTP = generateRandomOTP;
4
+ exports.generateRandomRecoveryCode = generateRandomRecoveryCode;
5
+ const encoding_1 = require("@oslojs/encoding");
6
+ /**
7
+ * Generates a random one-time code (OTP).
8
+ * @param length Length of the generated code (default 6).
9
+ * @returns A random uppercase base32 string.
10
+ */
11
+ function generateRandomOTP(length = 6) {
12
+ const bytes = new Uint8Array(5);
13
+ crypto.getRandomValues(bytes);
14
+ return (0, encoding_1.encodeBase32UpperCaseNoPadding)(bytes).substring(0, length);
15
+ }
16
+ /**
17
+ * Generates a random recovery code.
18
+ * @returns A random uppercase base32 string.
19
+ */
20
+ function generateRandomRecoveryCode() {
21
+ const recoveryCodeBytes = new Uint8Array(10);
22
+ crypto.getRandomValues(recoveryCodeBytes);
23
+ return (0, encoding_1.encodeBase32UpperCaseNoPadding)(recoveryCodeBytes);
24
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Encrypts data using AES-128-GCM.
3
+ * @param data Data to be encrypted.
4
+ * @returns Encrypted data including IV and auth tag.
5
+ */
6
+ export declare function encrypt(data: Uint8Array): Uint8Array;
7
+ /**
8
+ * Encrypts a string.
9
+ * @param data String to be encrypted.
10
+ * @returns Encrypted data as Uint8Array.
11
+ */
12
+ export declare function encryptString(data: string): Uint8Array;
13
+ /**
14
+ * Decrypts data using AES-128-GCM.
15
+ * @param encrypted Encrypted data (IV + content + auth tag).
16
+ * @returns Decrypted data.
17
+ */
18
+ export declare function decrypt(encrypted: Uint8Array): Uint8Array;
19
+ /**
20
+ * Decrypts data to a string.
21
+ * @param data Encrypted data.
22
+ * @returns Odszyfrowany ciąg znaków.
23
+ */
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,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encrypt = encrypt;
4
+ exports.encryptString = encryptString;
5
+ exports.decrypt = decrypt;
6
+ exports.decryptToString = decryptToString;
7
+ const node_crypto_1 = require("node:crypto");
8
+ const binary_1 = require("@oslojs/binary");
9
+ const encoding_1 = require("@oslojs/encoding");
10
+ const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY;
11
+ if (!ENCRYPTION_KEY) {
12
+ throw new Error("ENCRYPTION_KEY environment variable is not set");
13
+ }
14
+ /**
15
+ * The encryption key decoded from base64.
16
+ */
17
+ const key = (0, encoding_1.decodeBase64)(ENCRYPTION_KEY);
18
+ /**
19
+ * Encrypts data using AES-128-GCM.
20
+ * @param data Data to be encrypted.
21
+ * @returns Encrypted data including IV and auth tag.
22
+ */
23
+ function encrypt(data) {
24
+ const iv = new Uint8Array(16);
25
+ crypto.getRandomValues(iv);
26
+ const cipher = (0, node_crypto_1.createCipheriv)("aes-128-gcm", key, iv);
27
+ const encrypted = new binary_1.DynamicBuffer(0);
28
+ encrypted.write(iv);
29
+ encrypted.write(cipher.update(data));
30
+ encrypted.write(cipher.final());
31
+ encrypted.write(cipher.getAuthTag());
32
+ return encrypted.bytes();
33
+ }
34
+ /**
35
+ * Encrypts a string.
36
+ * @param data String to be encrypted.
37
+ * @returns Encrypted data as Uint8Array.
38
+ */
39
+ function encryptString(data) {
40
+ return encrypt(new TextEncoder().encode(data));
41
+ }
42
+ /**
43
+ * Decrypts data using AES-128-GCM.
44
+ * @param encrypted Encrypted data (IV + content + auth tag).
45
+ * @returns Decrypted data.
46
+ */
47
+ function decrypt(encrypted) {
48
+ if (encrypted.byteLength < 33) {
49
+ throw new Error("Invalid encrypted data length");
50
+ }
51
+ const iv = encrypted.slice(0, 16);
52
+ const authTag = encrypted.slice(encrypted.byteLength - 16);
53
+ const content = encrypted.slice(16, encrypted.byteLength - 16);
54
+ const decipher = (0, node_crypto_1.createDecipheriv)("aes-128-gcm", key, iv);
55
+ decipher.setAuthTag(authTag);
56
+ const decrypted = new binary_1.DynamicBuffer(0);
57
+ decrypted.write(decipher.update(content));
58
+ decrypted.write(decipher.final());
59
+ return decrypted.bytes();
60
+ }
61
+ /**
62
+ * Decrypts data to a string.
63
+ * @param data Encrypted data.
64
+ * @returns Odszyfrowany ciąg znaków.
65
+ */
66
+ function decryptToString(data) {
67
+ return new TextDecoder().decode(decrypt(data));
68
+ }
@@ -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,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.recoveryCodeVerifySchema = exports.passkeysSetupSchema = exports.totpVerifySchema = exports.totpSetupSchema = exports.verifyEmailSchema = exports.resetPasswordSchema = exports.forgotPasswordSchema = exports.registerSchema = exports.loginSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ // Auth validation schemas - CLEAN (No DB dependencies for client-side)
6
+ exports.loginSchema = zod_1.z.object({
7
+ email: zod_1.z.string().email("Invalid email address"),
8
+ password: zod_1.z.string().min(8),
9
+ remember: zod_1.z.boolean().optional(),
10
+ });
11
+ exports.registerSchema = zod_1.z.object({
12
+ username: zod_1.z.string().min(2, "Name must be at least 2 characters"),
13
+ email: zod_1.z.string().email("Invalid email address"),
14
+ password: zod_1.z.string().min(8, "Password must be at least 8 characters"),
15
+ terms: zod_1.z.boolean().refine((val) => val === true, "You must accept the terms"),
16
+ });
17
+ exports.forgotPasswordSchema = zod_1.z.object({
18
+ email: zod_1.z.string().email("Invalid email address"),
19
+ });
20
+ exports.resetPasswordSchema = zod_1.z
21
+ .object({
22
+ password: zod_1.z.string().min(8, "Password must be at least 8 characters"),
23
+ confirm: zod_1.z.string(),
24
+ })
25
+ .refine((data) => data.password === data.confirm, {
26
+ message: "Passwords do not match",
27
+ path: ["confirm"],
28
+ });
29
+ exports.verifyEmailSchema = zod_1.z.object({
30
+ code: zod_1.z.string().min(6).max(6),
31
+ });
32
+ // mfa validation schemas
33
+ exports.totpSetupSchema = zod_1.z.object({
34
+ code: zod_1.z.string().regex(/^\d{6}$/, "Code must be 6 digits"),
35
+ });
36
+ exports.totpVerifySchema = zod_1.z.object({
37
+ code: zod_1.z.string().regex(/^\d{6}$/, "Code must be 6 digits"),
38
+ });
39
+ exports.passkeysSetupSchema = zod_1.z.object({
40
+ name: zod_1.z.string().min(1, "Passkey name is required"),
41
+ });
42
+ exports.recoveryCodeVerifySchema = zod_1.z.object({
43
+ code: zod_1.z.string().min(16, "Recovery code is required").max(16),
44
+ });
@@ -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,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureSystemInitialized = ensureSystemInitialized;
4
+ const inject_1 = require("../server/database/inject");
5
+ const email_verification_1 = require("./auth/email-verification");
6
+ const event_bus_1 = require("./event-bus");
7
+ const index_1 = require("./filesystem/index");
8
+ const local_1 = require("./filesystem/providers/local");
9
+ const service_1 = require("./notifications/service");
10
+ const setup_1 = require("./setup");
11
+ async function ensureSystemInitialized(providedDb) {
12
+ if (typeof window !== "undefined")
13
+ return;
14
+ const g = globalThis;
15
+ // 1. Immediate injection if provided
16
+ if (providedDb) {
17
+ (0, inject_1.injectDb)(providedDb);
18
+ }
19
+ // 2. Prevent infinite recursion and double initialization
20
+ if (g.__KRYO_INITIALIZED__)
21
+ return;
22
+ if (g.__KRYO_INITIALIZING__)
23
+ return; // Already in progress, don't block/deadlock
24
+ g.__KRYO_INITIALIZING__ = true;
25
+ try {
26
+ console.log("[Kryo:Bootstrap] Starting system initialization...");
27
+ // Check if we have DB after any possible injection
28
+ if (!g.__KRYO_DB__) {
29
+ console.warn("[Kryo:Bootstrap] DB not detected during bootstrap start. Trying to continue...");
30
+ }
31
+ // Check if system is installed before initializing modules
32
+ if (await (0, setup_1.isSystemInstalled)()) {
33
+ // Order matters: services first, then modules (which use services)
34
+ service_1.notificationService.init();
35
+ await (0, email_verification_1.initEmailVerification)();
36
+ // Auto-register local filesystem provider as a fallback
37
+ const local = new local_1.LocalFileProvider();
38
+ index_1.filesystemService.registerProvider(local);
39
+ index_1.filesystemService.setDefaultProvider(local.id);
40
+ }
41
+ else {
42
+ console.log("[Kryo:Bootstrap] System not installed. Skipping module initialization.");
43
+ }
44
+ await event_bus_1.eventBus.publish("system:start", { runtime: "nodejs" });
45
+ console.log("[Kryo:Bootstrap] System initialized successfully.");
46
+ g.__KRYO_INITIALIZED__ = true;
47
+ }
48
+ catch (error) {
49
+ console.error("[Kryo:Bootstrap] Initialization failed:", error);
50
+ }
51
+ finally {
52
+ g.__KRYO_INITIALIZING__ = false;
53
+ }
54
+ }
@@ -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,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_CONFIG = void 0;
4
+ exports.DEFAULT_CONFIG = {
5
+ modulesDirectory: "modules",
6
+ };
@@ -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"}