@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
@@ -1,5 +1,9 @@
1
- import { g as Authenticatable, G as Guard, U as UserProvider, S as Session, e as AuthCredentials, a7 as PasswordHasher, a8 as PlainObject, a9 as Model } from '../api-token-JOif2CtG.js';
2
- export { c as API_TOKEN_KEY, b as ApiToken, d as ApiTokenStore, aa as AttachContextOptions, a as AuthContext, A as AuthManager, ab as AuthManagerContract, f as AuthManagerOptions, B as BaseUserProvider, h as BearerTokenMiddlewareOptions, i as CreateApiTokenOptions, j as CreateApiTokenResult, k as GuardContext, l as GuardFactory, M as MemoryApiTokenStore, m as MemoryOAuthStateStore, o as ModelUserProvider, p as OAuthAuthorizeOptions, q as OAuthCallbackPayload, O as OAuthManager, r as OAuthManagerOptions, s as OAuthProviderConfig, t as OAuthProviderFactoryInput, u as OAuthStateConfig, v as OAuthStatePayload, w as OAuthStateStore, x as OAuthTokenResult, y as OAuthUserProfile, P as ProviderFactory, E as buildOAuthAuthorizeUrl, F as buildOAuthRedirectUrl, H as createApiToken, I as createBearerTokenMiddleware, J as createDiscordOAuthProviderConfig, K as createGitHubOAuthProviderConfig, L as createGoogleOAuthProviderConfig, N as createOAuthManager, Q as createOAuthState, T as exchangeOAuthCode, V as fetchOAuthUserProfile, W as getApiToken, X as getApiTokenOrFail, Z as getUserApiTokens, _ as parseApiToken, $ as parseOAuthRedirectUrl, a0 as revokeAllApiTokens, a1 as revokeApiToken, a2 as tokenCan, a3 as tokenCanAll, a4 as tokenCanAny, a5 as verifyApiToken, a6 as verifyOAuthState } from '../api-token-JOif2CtG.js';
1
+ import { P as PasswordHasher } from '../AuthManager-SfhCNkAU.js';
2
+ export { A as AuthManager, B as BaseUserProvider, M as ModelUserProvider } from '../AuthManager-SfhCNkAU.js';
3
+ import { A as Authenticatable, e as Guard, U as UserProvider, z as Session, a as AuthCredentials } from '../api-token-BSSCLlFW.js';
4
+ export { m as API_TOKEN_KEY, j as ApiToken, i as ApiTokenStore, f as AttachContextOptions, g as AuthContext, b as AuthManagerContract, c as AuthManagerOptions, B as BearerTokenMiddlewareOptions, n as CreateApiTokenOptions, o as CreateApiTokenResult, d as GuardContext, G as GuardFactory, M as MemoryApiTokenStore, p as MemoryOAuthStateStore, r as OAuthAuthorizeOptions, s as OAuthCallbackPayload, l as OAuthManager, t as OAuthManagerOptions, u as OAuthProviderConfig, v as OAuthProviderFactoryInput, w as OAuthStateConfig, k as OAuthStatePayload, O as OAuthStateStore, x as OAuthTokenResult, y as OAuthUserProfile, P as ProviderFactory, D as buildOAuthAuthorizeUrl, E as buildOAuthRedirectUrl, F as createApiToken, H as createBearerTokenMiddleware, I as createDiscordOAuthProviderConfig, J as createGitHubOAuthProviderConfig, K as createGoogleOAuthProviderConfig, L as createOAuthManager, N as createOAuthState, R as exchangeOAuthCode, T as fetchOAuthUserProfile, V as getApiToken, W as getApiTokenOrFail, Y as getUserApiTokens, Z as parseApiToken, _ as parseOAuthRedirectUrl, $ as revokeAllApiTokens, a0 as revokeApiToken, a1 as tokenCan, a2 as tokenCanAll, a3 as tokenCanAny, a4 as verifyApiToken, a5 as verifyOAuthState } from '../api-token-BSSCLlFW.js';
5
+ import { PlainObject, Model } from '@guren/orm';
6
+ export { b as EmailVerificationConfig, a as EmailVerificationToken, c as EmailVerificationTokenResult, E as EmailVerificationTokenStore, M as MemoryEmailVerificationStore, d as MemoryPasswordResetStore, e as PasswordResetConfig, f as PasswordResetTokenResult, P as PasswordResetTokenStore, g as buildPasswordResetUrl, q as buildTokenUrl, h as buildVerificationUrl, i as completeEmailVerification, j as completePasswordReset, k as createEmailVerificationToken, l as createPasswordResetToken, s as generateId, t as generateToken, u as hashToken, m as isEmailVerified, p as parsePasswordResetUrl, w as parseTokenUrl, n as parseVerificationUrl, r as requireVerifiedEmail, x as secureCompare, y as secureStringCompare, v as verifyEmailToken, o as verifyPasswordResetToken } from '../email-verification-CAeArjui.js';
3
7
  import 'hono';
4
8
 
5
9
  interface SessionGuardOptions {
@@ -17,6 +21,8 @@ declare class SessionGuard<User extends Authenticatable = Authenticatable> imple
17
21
  private sessionKey;
18
22
  private rememberSessionKey;
19
23
  private loadRememberedUser;
24
+ /** Strip auth-internal fields before a record is cached or exposed. */
25
+ private sanitizeUser;
20
26
  private resolveUser;
21
27
  check(): Promise<boolean>;
22
28
  guest(): Promise<boolean>;
@@ -91,328 +97,4 @@ declare abstract class AuthenticatableModel<TRecord extends PlainObject = PlainO
91
97
  protected static preparePersistencePayload(data: PlainObject): Promise<PlainObject>;
92
98
  }
93
99
 
94
- /**
95
- * Hash a token using SHA-256 or SHA-512.
96
- */
97
- declare function hashToken(token: string, algorithm?: 'sha256' | 'sha512'): string;
98
- /**
99
- * Generate a secure random token.
100
- */
101
- declare function generateToken(length?: number): string;
102
- /**
103
- * Generate a random ID (16 bytes = 32 hex chars).
104
- */
105
- declare function generateId(): string;
106
- /**
107
- * Securely compare two hex strings using timing-safe comparison.
108
- */
109
- declare function secureCompare(a: string, b: string): boolean;
110
- /**
111
- * Securely compare two arbitrary strings using timing-safe comparison.
112
- * Unlike secureCompare, this works with any string encoding (UUIDs, tokens, etc.).
113
- */
114
- declare function secureStringCompare(a: string, b: string): boolean;
115
- /**
116
- * Build a URL with token and optional email parameters.
117
- */
118
- declare function buildTokenUrl(baseUrl: string, token: string, email?: string): string;
119
- /**
120
- * Parse a URL to extract token and email parameters.
121
- */
122
- declare function parseTokenUrl(url: string): {
123
- token: string | null;
124
- email: string | null;
125
- };
126
-
127
- /**
128
- * Configuration for password reset tokens.
129
- */
130
- interface PasswordResetConfig {
131
- /** Token expiration time in milliseconds (default: 1 hour) */
132
- expiresIn?: number;
133
- /** Token byte length before encoding (default: 32) */
134
- tokenLength?: number;
135
- }
136
- /**
137
- * Storage interface for password reset tokens.
138
- */
139
- interface PasswordResetTokenStore {
140
- /** Store a token ID with associated email and expiration */
141
- store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
142
- /** Find email by token ID, returns null if not found or expired */
143
- find(tokenId: string): Promise<{
144
- email: string;
145
- expiresAt: Date;
146
- } | null>;
147
- /** Delete a token ID from storage */
148
- delete(tokenId: string): Promise<void>;
149
- /** Delete all tokens for an email */
150
- deleteForEmail(email: string): Promise<void>;
151
- }
152
- /**
153
- * In-memory token store for testing and development.
154
- */
155
- declare class MemoryPasswordResetStore implements PasswordResetTokenStore {
156
- private tokens;
157
- store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
158
- find(tokenId: string): Promise<{
159
- email: string;
160
- expiresAt: Date;
161
- } | null>;
162
- delete(tokenId: string): Promise<void>;
163
- deleteForEmail(email: string): Promise<void>;
164
- /** Clear all tokens (useful for testing) */
165
- clear(): void;
166
- }
167
- /**
168
- * Result of creating a password reset token.
169
- */
170
- interface PasswordResetTokenResult {
171
- /** The plain-text token to send to the user (via email) */
172
- token: string;
173
- /** The token ID stored in the backing store */
174
- tokenId: string;
175
- /** When the token expires */
176
- expiresAt: Date;
177
- }
178
- /**
179
- * Create a password reset token for a user.
180
- *
181
- * @param email - The user's email address
182
- * @param store - The token storage implementation
183
- * @param config - Optional configuration
184
- * @returns The token result containing plain token and hash
185
- */
186
- declare function createPasswordResetToken(email: string, store: PasswordResetTokenStore, config?: PasswordResetConfig): Promise<PasswordResetTokenResult>;
187
- /**
188
- * Verify a password reset token.
189
- *
190
- * @param token - The plain-text token from the reset URL
191
- * @param store - The token storage implementation
192
- * @param config - Optional configuration (must match createPasswordResetToken config)
193
- * @returns The email if token is valid, null otherwise
194
- */
195
- declare function verifyPasswordResetToken(token: string, store: PasswordResetTokenStore, _config?: PasswordResetConfig): Promise<string | null>;
196
- /**
197
- * Complete a password reset by updating the user's password and invalidating the token.
198
- *
199
- * @param token - The plain-text token from the reset URL
200
- * @param newPassword - The new password (should be validated by caller)
201
- * @param store - The token storage implementation
202
- * @param provider - The user provider to look up and update the user
203
- * @param updatePassword - Function to update the user's password
204
- * @param config - Optional configuration
205
- * @returns The user if reset was successful, null if token is invalid
206
- */
207
- 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>;
208
- /**
209
- * Build a password reset URL from a base URL and token.
210
- */
211
- declare const buildPasswordResetUrl: typeof buildTokenUrl;
212
- /**
213
- * Parse a password reset URL to extract the token and optional email.
214
- */
215
- declare const parsePasswordResetUrl: typeof parseTokenUrl;
216
-
217
- /**
218
- * Email verification token data stored in the backing store.
219
- * Only the hashed token is stored for security.
220
- */
221
- interface EmailVerificationToken {
222
- email: string;
223
- tokenId: string;
224
- expiresAt: Date;
225
- createdAt: Date;
226
- }
227
- /**
228
- * Store interface for email verification tokens.
229
- * Implement this to use database-backed storage.
230
- */
231
- interface EmailVerificationTokenStore {
232
- /**
233
- * Store a new verification token.
234
- */
235
- store(token: EmailVerificationToken): Promise<void>;
236
- /**
237
- * Find a token by its opaque token ID.
238
- */
239
- findByTokenId(tokenId: string): Promise<EmailVerificationToken | null>;
240
- /**
241
- * Delete a token by its opaque token ID.
242
- */
243
- delete(tokenId: string): Promise<void>;
244
- /**
245
- * Delete all tokens for a given email.
246
- */
247
- deleteForEmail(email: string): Promise<void>;
248
- }
249
- /**
250
- * In-memory store for testing purposes.
251
- * Do NOT use in production - tokens will be lost on restart.
252
- */
253
- declare class MemoryEmailVerificationStore implements EmailVerificationTokenStore {
254
- private tokens;
255
- store(token: EmailVerificationToken): Promise<void>;
256
- findByTokenId(tokenId: string): Promise<EmailVerificationToken | null>;
257
- delete(tokenId: string): Promise<void>;
258
- deleteForEmail(email: string): Promise<void>;
259
- /**
260
- * Clear all tokens (useful for testing).
261
- */
262
- clear(): void;
263
- /**
264
- * Get the count of stored tokens (useful for testing).
265
- */
266
- get size(): number;
267
- }
268
- /**
269
- * Configuration options for email verification.
270
- */
271
- interface EmailVerificationConfig {
272
- /**
273
- * Token expiration time in milliseconds.
274
- * @default 86400000 (24 hours)
275
- */
276
- expiresIn?: number;
277
- /**
278
- * Token byte length (before hex encoding).
279
- * @default 32
280
- */
281
- tokenLength?: number;
282
- }
283
- /**
284
- * Result of creating an email verification token.
285
- */
286
- interface EmailVerificationTokenResult {
287
- /**
288
- * The raw token to send to the user via email.
289
- * This is NOT stored - only the hash is stored.
290
- */
291
- token: string;
292
- /**
293
- * When the token expires.
294
- */
295
- expiresAt: Date;
296
- }
297
- /**
298
- * Create a new email verification token.
299
- *
300
- * @param email - The email address to verify
301
- * @param store - Token store implementation
302
- * @param config - Optional configuration
303
- * @returns The raw token to send via email
304
- *
305
- * @example
306
- * ```ts
307
- * const { token, expiresAt } = await createEmailVerificationToken(
308
- * user.email,
309
- * verificationStore
310
- * )
311
- *
312
- * // Send email with verification link
313
- * await sendEmail({
314
- * to: user.email,
315
- * subject: 'Verify your email',
316
- * html: `<a href="${buildVerificationUrl(baseUrl, token)}">Verify Email</a>`,
317
- * })
318
- * ```
319
- */
320
- declare function createEmailVerificationToken(email: string, store: EmailVerificationTokenStore, config?: EmailVerificationConfig): Promise<EmailVerificationTokenResult>;
321
- /**
322
- * Verify an email verification token.
323
- *
324
- * @param token - The raw token from the verification link
325
- * @param store - Token store implementation
326
- * @param config - Optional configuration (not currently used, reserved for future)
327
- * @returns The email address if valid, null if invalid or expired
328
- *
329
- * @example
330
- * ```ts
331
- * const email = await verifyEmailToken(token, verificationStore)
332
- *
333
- * if (!email) {
334
- * return ctx.json({ error: 'Invalid or expired token' }, 400)
335
- * }
336
- *
337
- * // Mark user as verified
338
- * await User.update({ email }, { emailVerifiedAt: new Date() })
339
- * ```
340
- */
341
- declare function verifyEmailToken(token: string, store: EmailVerificationTokenStore, _config?: EmailVerificationConfig): Promise<string | null>;
342
- /**
343
- * Complete email verification by consuming the token.
344
- *
345
- * @param token - The raw token from the verification link
346
- * @param store - Token store implementation
347
- * @param markVerified - Function to mark the user as verified
348
- * @returns The result of markVerified if successful, null if token invalid
349
- *
350
- * @example
351
- * ```ts
352
- * const result = await completeEmailVerification(
353
- * token,
354
- * verificationStore,
355
- * async (email) => {
356
- * await User.update({ email }, { emailVerifiedAt: new Date() })
357
- * return User.findByEmail(email)
358
- * }
359
- * )
360
- *
361
- * if (!result) {
362
- * return ctx.json({ error: 'Invalid or expired token' }, 400)
363
- * }
364
- *
365
- * return ctx.redirect('/dashboard')
366
- * ```
367
- */
368
- declare function completeEmailVerification<T>(token: string, store: EmailVerificationTokenStore, markVerified: (email: string) => Promise<T>): Promise<T | null>;
369
- /**
370
- * Build a verification URL.
371
- */
372
- declare const buildVerificationUrl: typeof buildTokenUrl;
373
- /**
374
- * Parse a verification URL to extract token and email.
375
- */
376
- declare const parseVerificationUrl: typeof parseTokenUrl;
377
- /**
378
- * Check if a user's email is verified.
379
- * Helper function for use with User models.
380
- *
381
- * @param user - User object with emailVerifiedAt field
382
- * @returns true if verified, false otherwise
383
- *
384
- * @example
385
- * ```ts
386
- * if (!isEmailVerified(user)) {
387
- * return ctx.redirect('/verify-email')
388
- * }
389
- * ```
390
- */
391
- declare function isEmailVerified(user: {
392
- emailVerifiedAt?: Date | null;
393
- } | null): boolean;
394
- /**
395
- * Middleware factory to require verified email.
396
- *
397
- * @param options - Configuration options
398
- * @returns Middleware function
399
- *
400
- * @example
401
- * ```ts
402
- * router.get('/dashboard', [DashboardController, 'index'],
403
- * requireAuthenticated(),
404
- * requireVerifiedEmail({ redirectTo: '/verify-email' })
405
- * )
406
- * ```
407
- */
408
- declare function requireVerifiedEmail(options?: {
409
- redirectTo?: string;
410
- getUser?: (ctx: unknown) => Promise<{
411
- emailVerifiedAt?: Date | null;
412
- } | null>;
413
- }): (ctx: {
414
- get: (key: string) => unknown;
415
- redirect: (url: string) => Response;
416
- }, next: () => Promise<void>) => Promise<Response | undefined>;
417
-
418
- export { AuthCredentials, Authenticatable, AuthenticatableModel, type EmailVerificationConfig, type EmailVerificationToken, type EmailVerificationTokenResult, type EmailVerificationTokenStore, Guard, MemoryEmailVerificationStore, MemoryPasswordResetStore, NodeHasher, PasswordHasher, type PasswordResetConfig, type PasswordResetTokenResult, type PasswordResetTokenStore, ScryptHasher, SessionGuard, UserProvider, buildPasswordResetUrl, buildTokenUrl, buildVerificationUrl, completeEmailVerification, completePasswordReset, createEmailVerificationToken, createPasswordResetToken, generateId, generateToken, hashToken, isEmailVerified, parsePasswordResetUrl, parseTokenUrl, parseVerificationUrl, requireVerifiedEmail, secureCompare, secureStringCompare, verifyEmailToken, verifyPasswordResetToken };
100
+ export { AuthCredentials, Authenticatable, AuthenticatableModel, Guard, NodeHasher, PasswordHasher, ScryptHasher, SessionGuard, UserProvider };