@guren/server 1.0.0-rc.9 → 1.1.0

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 (70) hide show
  1. package/dist/{Application-DtWDHXr1.d.ts → Application-BnsyCKXY.d.ts} +79 -8
  2. package/dist/AuthManager-SfhCNkAU.d.ts +79 -0
  3. package/dist/{BroadcastManager-AkIWUGJo.d.ts → BroadcastManager-CGWl9rUO.d.ts} +5 -0
  4. package/dist/{ConsoleKernel-CqCVrdZs.d.ts → ConsoleKernel-BDtBETjm.d.ts} +1 -1
  5. package/dist/{Gate-CNkBYf8m.d.ts → Gate-CynjZCtS.d.ts} +5 -0
  6. package/dist/{I18nManager-Dtgzsf5n.d.ts → I18nManager-BiSoczfV.d.ts} +6 -1
  7. package/dist/McpServiceProvider-JW6PDVMD.js +7 -0
  8. package/dist/api-token-BSSCLlFW.d.ts +541 -0
  9. package/dist/auth/index.d.ts +9 -327
  10. package/dist/auth/index.js +59 -6684
  11. package/dist/authorization/index.d.ts +2 -2
  12. package/dist/authorization/index.js +19 -604
  13. package/dist/broadcasting/index.d.ts +2 -2
  14. package/dist/broadcasting/index.js +12 -895
  15. package/dist/cache/index.js +8 -809
  16. package/dist/chunk-2T6JN4VR.js +1563 -0
  17. package/dist/chunk-44F7JQ7I.js +950 -0
  18. package/dist/chunk-74HTZG3V.js +331 -0
  19. package/dist/chunk-A3ISJVEV.js +598 -0
  20. package/dist/chunk-CSDKWLFD.js +652 -0
  21. package/dist/chunk-CSRQTEQA.js +839 -0
  22. package/dist/chunk-DAQKYKLH.js +182 -0
  23. package/dist/chunk-EDRGAM6G.js +647 -0
  24. package/dist/chunk-EGU5KB7V.js +818 -0
  25. package/dist/chunk-H32L2NE3.js +372 -0
  26. package/dist/chunk-HKQSAFSN.js +837 -0
  27. package/dist/chunk-IOTWFHZU.js +558 -0
  28. package/dist/chunk-ONSDE37A.js +125 -0
  29. package/dist/chunk-QH4NUKSV.js +255 -0
  30. package/dist/chunk-QQKTH5KX.js +114 -0
  31. package/dist/chunk-R2TCP7D7.js +409 -0
  32. package/dist/chunk-SIP34GBE.js +380 -0
  33. package/dist/chunk-THSX7OOR.js +454 -0
  34. package/dist/chunk-UY3AZSYL.js +14 -0
  35. package/dist/chunk-VT5KRDPH.js +134 -0
  36. package/dist/chunk-WJJ5CTNI.js +907 -0
  37. package/dist/chunk-WVY45EIW.js +359 -0
  38. package/dist/chunk-ZRBLZY3M.js +462 -0
  39. package/dist/client-CKXJLsTe.d.ts +232 -0
  40. package/dist/email-verification-CAeArjui.d.ts +327 -0
  41. package/dist/encryption/index.js +48 -556
  42. package/dist/errors-JOOPDDQ6.js +34 -0
  43. package/dist/events/index.js +14 -316
  44. package/dist/health/index.js +12 -367
  45. package/dist/i18n/index.d.ts +2 -2
  46. package/dist/i18n/index.js +14 -583
  47. package/dist/index.d.ts +37 -239
  48. package/dist/index.js +2931 -19222
  49. package/dist/lambda/index.d.ts +9 -7
  50. package/dist/lambda/index.js +4 -9
  51. package/dist/logging/index.js +12 -545
  52. package/dist/mail/index.d.ts +29 -1
  53. package/dist/mail/index.js +15 -684
  54. package/dist/mcp/index.d.ts +7 -5
  55. package/dist/mcp/index.js +5 -378
  56. package/dist/notifications/index.d.ts +8 -6
  57. package/dist/notifications/index.js +13 -730
  58. package/dist/queue/index.d.ts +37 -7
  59. package/dist/queue/index.js +22 -940
  60. package/dist/redis/index.d.ts +366 -0
  61. package/dist/redis/index.js +597 -0
  62. package/dist/runtime/index.d.ts +8 -6
  63. package/dist/runtime/index.js +26 -244
  64. package/dist/scheduling/index.js +14 -822
  65. package/dist/storage/index.d.ts +1 -0
  66. package/dist/storage/index.js +6 -824
  67. package/dist/vite/index.d.ts +2 -2
  68. package/dist/vite/index.js +5 -1
  69. package/package.json +15 -7
  70. package/dist/api-token-JOif2CtG.d.ts +0 -1792
@@ -0,0 +1,327 @@
1
+ import { A as Authenticatable, U as UserProvider } from './api-token-BSSCLlFW.js';
2
+
3
+ /**
4
+ * Hash a token using SHA-256 or SHA-512.
5
+ */
6
+ declare function hashToken(token: string, algorithm?: 'sha256' | 'sha512'): string;
7
+ /**
8
+ * Generate a secure random token.
9
+ */
10
+ declare function generateToken(length?: number): string;
11
+ /**
12
+ * Generate a random ID (16 bytes = 32 hex chars).
13
+ */
14
+ declare function generateId(): string;
15
+ /**
16
+ * Securely compare two hex strings using timing-safe comparison.
17
+ */
18
+ declare function secureCompare(a: string, b: string): boolean;
19
+ /**
20
+ * Securely compare two arbitrary strings using timing-safe comparison.
21
+ * Unlike secureCompare, this works with any string encoding (UUIDs, tokens, etc.).
22
+ */
23
+ declare function secureStringCompare(a: string, b: string): boolean;
24
+ /**
25
+ * Build a URL with token and optional email parameters.
26
+ */
27
+ declare function buildTokenUrl(baseUrl: string, token: string, email?: string): string;
28
+ /**
29
+ * Parse a URL to extract token and email parameters.
30
+ */
31
+ declare function parseTokenUrl(url: string): {
32
+ token: string | null;
33
+ email: string | null;
34
+ };
35
+
36
+ /**
37
+ * Configuration for password reset tokens.
38
+ */
39
+ interface PasswordResetConfig {
40
+ /** Token expiration time in milliseconds (default: 1 hour) */
41
+ expiresIn?: number;
42
+ /** Token byte length before encoding (default: 32) */
43
+ tokenLength?: number;
44
+ }
45
+ /**
46
+ * Storage interface for password reset tokens.
47
+ */
48
+ interface PasswordResetTokenStore {
49
+ /** Store a token ID with associated email and expiration */
50
+ store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
51
+ /** Find email by token ID, returns null if not found or expired */
52
+ find(tokenId: string): Promise<{
53
+ email: string;
54
+ expiresAt: Date;
55
+ } | null>;
56
+ /** Delete a token ID from storage */
57
+ delete(tokenId: string): Promise<void>;
58
+ /** Delete all tokens for an email */
59
+ deleteForEmail(email: string): Promise<void>;
60
+ }
61
+ /**
62
+ * In-memory token store for testing and development.
63
+ */
64
+ declare class MemoryPasswordResetStore implements PasswordResetTokenStore {
65
+ private tokens;
66
+ store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
67
+ find(tokenId: string): Promise<{
68
+ email: string;
69
+ expiresAt: Date;
70
+ } | null>;
71
+ delete(tokenId: string): Promise<void>;
72
+ deleteForEmail(email: string): Promise<void>;
73
+ /** Clear all tokens (useful for testing) */
74
+ clear(): void;
75
+ }
76
+ /**
77
+ * Result of creating a password reset token.
78
+ */
79
+ interface PasswordResetTokenResult {
80
+ /** The plain-text token to send to the user (via email) */
81
+ token: string;
82
+ /** The token ID stored in the backing store */
83
+ tokenId: string;
84
+ /** When the token expires */
85
+ expiresAt: Date;
86
+ }
87
+ /**
88
+ * Create a password reset token for a user.
89
+ *
90
+ * @param email - The user's email address
91
+ * @param store - The token storage implementation
92
+ * @param config - Optional configuration
93
+ * @returns The token result containing plain token and hash
94
+ */
95
+ declare function createPasswordResetToken(email: string, store: PasswordResetTokenStore, config?: PasswordResetConfig): Promise<PasswordResetTokenResult>;
96
+ /**
97
+ * Verify a password reset token.
98
+ *
99
+ * @param token - The plain-text token from the reset URL
100
+ * @param store - The token storage implementation
101
+ * @param config - Optional configuration (must match createPasswordResetToken config)
102
+ * @returns The email if token is valid, null otherwise
103
+ */
104
+ declare function verifyPasswordResetToken(token: string, store: PasswordResetTokenStore, _config?: PasswordResetConfig): Promise<string | null>;
105
+ /**
106
+ * Complete a password reset by updating the user's password and invalidating the token.
107
+ *
108
+ * @param token - The plain-text token from the reset URL
109
+ * @param newPassword - The new password (should be validated by caller)
110
+ * @param store - The token storage implementation
111
+ * @param provider - The user provider to look up and update the user
112
+ * @param updatePassword - Function to update the user's password
113
+ * @param config - Optional configuration
114
+ * @returns The user if reset was successful, null if token is invalid
115
+ */
116
+ declare function completePasswordReset<T extends Authenticatable>(token: string, newPassword: string, store: PasswordResetTokenStore, provider: UserProvider<T>, updatePassword: (user: T, password: string) => Promise<void>, _config?: PasswordResetConfig): Promise<T | null>;
117
+ /**
118
+ * Build a password reset URL from a base URL and token.
119
+ */
120
+ declare const buildPasswordResetUrl: typeof buildTokenUrl;
121
+ /**
122
+ * Parse a password reset URL to extract the token and optional email.
123
+ */
124
+ declare const parsePasswordResetUrl: typeof parseTokenUrl;
125
+
126
+ /**
127
+ * Email verification token data stored in the backing store.
128
+ * Only the hashed token is stored for security.
129
+ */
130
+ interface EmailVerificationToken {
131
+ email: string;
132
+ tokenId: string;
133
+ expiresAt: Date;
134
+ createdAt: Date;
135
+ }
136
+ /**
137
+ * Store interface for email verification tokens.
138
+ * Implement this to use database-backed storage.
139
+ */
140
+ interface EmailVerificationTokenStore {
141
+ /**
142
+ * Store a new verification token.
143
+ */
144
+ store(token: EmailVerificationToken): Promise<void>;
145
+ /**
146
+ * Find a token by its opaque token ID.
147
+ */
148
+ findByTokenId(tokenId: string): Promise<EmailVerificationToken | null>;
149
+ /**
150
+ * Delete a token by its opaque token ID.
151
+ */
152
+ delete(tokenId: string): Promise<void>;
153
+ /**
154
+ * Delete all tokens for a given email.
155
+ */
156
+ deleteForEmail(email: string): Promise<void>;
157
+ }
158
+ /**
159
+ * In-memory store for testing purposes.
160
+ * Do NOT use in production - tokens will be lost on restart.
161
+ */
162
+ declare class MemoryEmailVerificationStore implements EmailVerificationTokenStore {
163
+ private tokens;
164
+ store(token: EmailVerificationToken): Promise<void>;
165
+ findByTokenId(tokenId: string): Promise<EmailVerificationToken | null>;
166
+ delete(tokenId: string): Promise<void>;
167
+ deleteForEmail(email: string): Promise<void>;
168
+ /**
169
+ * Clear all tokens (useful for testing).
170
+ */
171
+ clear(): void;
172
+ /**
173
+ * Get the count of stored tokens (useful for testing).
174
+ */
175
+ get size(): number;
176
+ }
177
+ /**
178
+ * Configuration options for email verification.
179
+ */
180
+ interface EmailVerificationConfig {
181
+ /**
182
+ * Token expiration time in milliseconds.
183
+ * @default 86400000 (24 hours)
184
+ */
185
+ expiresIn?: number;
186
+ /**
187
+ * Token byte length (before hex encoding).
188
+ * @default 32
189
+ */
190
+ tokenLength?: number;
191
+ }
192
+ /**
193
+ * Result of creating an email verification token.
194
+ */
195
+ interface EmailVerificationTokenResult {
196
+ /**
197
+ * The raw token to send to the user via email.
198
+ * This is NOT stored - only the hash is stored.
199
+ */
200
+ token: string;
201
+ /**
202
+ * When the token expires.
203
+ */
204
+ expiresAt: Date;
205
+ }
206
+ /**
207
+ * Create a new email verification token.
208
+ *
209
+ * @param email - The email address to verify
210
+ * @param store - Token store implementation
211
+ * @param config - Optional configuration
212
+ * @returns The raw token to send via email
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * const { token, expiresAt } = await createEmailVerificationToken(
217
+ * user.email,
218
+ * verificationStore
219
+ * )
220
+ *
221
+ * // Send email with verification link
222
+ * await sendEmail({
223
+ * to: user.email,
224
+ * subject: 'Verify your email',
225
+ * html: `<a href="${buildVerificationUrl(baseUrl, token)}">Verify Email</a>`,
226
+ * })
227
+ * ```
228
+ */
229
+ declare function createEmailVerificationToken(email: string, store: EmailVerificationTokenStore, config?: EmailVerificationConfig): Promise<EmailVerificationTokenResult>;
230
+ /**
231
+ * Verify an email verification token.
232
+ *
233
+ * @param token - The raw token from the verification link
234
+ * @param store - Token store implementation
235
+ * @param config - Optional configuration (not currently used, reserved for future)
236
+ * @returns The email address if valid, null if invalid or expired
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * const email = await verifyEmailToken(token, verificationStore)
241
+ *
242
+ * if (!email) {
243
+ * return ctx.json({ error: 'Invalid or expired token' }, 400)
244
+ * }
245
+ *
246
+ * // Mark user as verified
247
+ * await User.update({ email }, { emailVerifiedAt: new Date() })
248
+ * ```
249
+ */
250
+ declare function verifyEmailToken(token: string, store: EmailVerificationTokenStore, _config?: EmailVerificationConfig): Promise<string | null>;
251
+ /**
252
+ * Complete email verification by consuming the token.
253
+ *
254
+ * @param token - The raw token from the verification link
255
+ * @param store - Token store implementation
256
+ * @param markVerified - Function to mark the user as verified
257
+ * @returns The result of markVerified if successful, null if token invalid
258
+ *
259
+ * @example
260
+ * ```ts
261
+ * const result = await completeEmailVerification(
262
+ * token,
263
+ * verificationStore,
264
+ * async (email) => {
265
+ * await User.update({ email }, { emailVerifiedAt: new Date() })
266
+ * return User.findByEmail(email)
267
+ * }
268
+ * )
269
+ *
270
+ * if (!result) {
271
+ * return ctx.json({ error: 'Invalid or expired token' }, 400)
272
+ * }
273
+ *
274
+ * return ctx.redirect('/dashboard')
275
+ * ```
276
+ */
277
+ declare function completeEmailVerification<T>(token: string, store: EmailVerificationTokenStore, markVerified: (email: string) => Promise<T>): Promise<T | null>;
278
+ /**
279
+ * Build a verification URL.
280
+ */
281
+ declare const buildVerificationUrl: typeof buildTokenUrl;
282
+ /**
283
+ * Parse a verification URL to extract token and email.
284
+ */
285
+ declare const parseVerificationUrl: typeof parseTokenUrl;
286
+ /**
287
+ * Check if a user's email is verified.
288
+ * Helper function for use with User models.
289
+ *
290
+ * @param user - User object with emailVerifiedAt field
291
+ * @returns true if verified, false otherwise
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * if (!isEmailVerified(user)) {
296
+ * return ctx.redirect('/verify-email')
297
+ * }
298
+ * ```
299
+ */
300
+ declare function isEmailVerified(user: {
301
+ emailVerifiedAt?: Date | null;
302
+ } | null): boolean;
303
+ /**
304
+ * Middleware factory to require verified email.
305
+ *
306
+ * @param options - Configuration options
307
+ * @returns Middleware function
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * router.get('/dashboard', [DashboardController, 'index'],
312
+ * requireAuthenticated(),
313
+ * requireVerifiedEmail({ redirectTo: '/verify-email' })
314
+ * )
315
+ * ```
316
+ */
317
+ declare function requireVerifiedEmail(options?: {
318
+ redirectTo?: string;
319
+ getUser?: (ctx: unknown) => Promise<{
320
+ emailVerifiedAt?: Date | null;
321
+ } | null>;
322
+ }): (ctx: {
323
+ get: (key: string) => unknown;
324
+ redirect: (url: string) => Response;
325
+ }, next: () => Promise<void>) => Promise<Response | undefined>;
326
+
327
+ export { type EmailVerificationTokenStore as E, MemoryEmailVerificationStore as M, type PasswordResetTokenStore as P, type EmailVerificationToken as a, type EmailVerificationConfig as b, type EmailVerificationTokenResult as c, MemoryPasswordResetStore as d, type PasswordResetConfig as e, type PasswordResetTokenResult as f, buildPasswordResetUrl as g, buildVerificationUrl as h, completeEmailVerification as i, completePasswordReset as j, createEmailVerificationToken as k, createPasswordResetToken as l, isEmailVerified as m, parseVerificationUrl as n, verifyPasswordResetToken as o, parsePasswordResetUrl as p, buildTokenUrl as q, requireVerifiedEmail as r, generateId as s, generateToken as t, hashToken as u, verifyEmailToken as v, parseTokenUrl as w, secureCompare as x, secureStringCompare as y };