@guren/server 1.0.0-rc.14 → 1.0.0-rc.15

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.
@@ -1,6 +1,6 @@
1
1
  import * as hono from 'hono';
2
2
  import { Context, MiddlewareHandler, Hono, ExecutionContext } from 'hono';
3
- import { A as AuthManager, O as OAuthManager, a as AuthContext, b as ApiToken, C as CreateSessionMiddlewareOptions } from './api-token-JOif2CtG.js';
3
+ import { A as AuthManager, O as OAuthManager, a as AuthContext, b as ApiToken, C as CreateSessionMiddlewareOptions } from './api-token-BGOsfuI9.js';
4
4
  import { InlineConfig, ViteDevServer } from 'vite';
5
5
  import { E as EventManager } from './EventManager-CmIoLt7r.js';
6
6
  import { C as CacheManager } from './CacheManager-BkvHEOZX.js';
@@ -1,4 +1,4 @@
1
- import { C as Container } from './Application-CsylYL26.js';
1
+ import { C as Container } from './Application-CddorcPa.js';
2
2
 
3
3
  /**
4
4
  * Parsed argument definition.
@@ -0,0 +1,598 @@
1
+ import { MiddlewareHandler, Context } from 'hono';
2
+ import { Model } from '@guren/orm';
3
+
4
+ type SessionData = Record<string, unknown>;
5
+ interface SessionStore {
6
+ /**
7
+ * Read a session by its opaque identifier.
8
+ * Returns undefined when the session does not exist or has expired.
9
+ */
10
+ read(id: string): Promise<SessionData | undefined>;
11
+ /**
12
+ * Persist a session using upsert semantics for the given opaque identifier.
13
+ */
14
+ write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
15
+ /**
16
+ * Destroy a session. Implementations must treat repeated calls as safe.
17
+ */
18
+ destroy(id: string): Promise<void>;
19
+ }
20
+ declare class MemorySessionStore implements SessionStore {
21
+ private readonly now;
22
+ private readonly store;
23
+ constructor(now?: () => number);
24
+ read(id: string): Promise<SessionData | undefined>;
25
+ write(id: string, data: SessionData, ttlSeconds: number): Promise<void>;
26
+ destroy(id: string): Promise<void>;
27
+ }
28
+ interface SessionOptions {
29
+ cookieName?: string;
30
+ cookiePath?: string;
31
+ cookieDomain?: string;
32
+ cookieSecure?: boolean;
33
+ cookieSameSite?: 'Strict' | 'Lax' | 'None';
34
+ cookieHttpOnly?: boolean;
35
+ cookieMaxAgeSeconds?: number;
36
+ ttlSeconds?: number;
37
+ store?: SessionStore;
38
+ }
39
+ interface Session {
40
+ readonly id: string;
41
+ readonly isNew: boolean;
42
+ get<T = unknown>(key: string): T | undefined;
43
+ set<T = unknown>(key: string, value: T): void;
44
+ has(key: string): boolean;
45
+ forget(key: string): void;
46
+ flush(): void;
47
+ all(): SessionData;
48
+ regenerate(): void;
49
+ invalidate(): void;
50
+ flash(key: string, value: unknown): void;
51
+ getFlash<T = unknown>(key: string): T | undefined;
52
+ reflash(): void;
53
+ keep(...keys: string[]): void;
54
+ }
55
+ interface CreateSessionMiddlewareOptions extends SessionOptions {
56
+ }
57
+ declare function createSessionMiddleware(options?: CreateSessionMiddlewareOptions): MiddlewareHandler;
58
+ declare function getSessionFromContext<T extends Session = Session>(ctx: {
59
+ get: (key: string) => unknown;
60
+ }): T | undefined;
61
+
62
+ type AuthCredentials = Record<string, unknown>;
63
+ interface Authenticatable {
64
+ getAuthIdentifier(): unknown;
65
+ getAuthPassword(): string | null | undefined;
66
+ getRememberToken?(): string | null | undefined;
67
+ setRememberToken?(token: string | null): void | Promise<void>;
68
+ }
69
+ interface Guard<User = Authenticatable> {
70
+ check(): Promise<boolean>;
71
+ guest(): Promise<boolean>;
72
+ user<T = User>(): Promise<T | null>;
73
+ id(): Promise<unknown>;
74
+ login<T = User>(user: T, remember?: boolean): Promise<void>;
75
+ logout(): Promise<void>;
76
+ attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
77
+ validate(credentials: AuthCredentials): Promise<User | null>;
78
+ session<T extends Session = Session>(): T | undefined;
79
+ }
80
+ interface UserProvider<User = Authenticatable> {
81
+ retrieveById(identifier: unknown): Promise<User | null>;
82
+ retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
83
+ validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
84
+ getId(user: User): unknown;
85
+ setRememberToken?(user: User, token: string | null): Promise<void> | void;
86
+ getRememberToken?(user: User): Promise<string | null> | string | null;
87
+ }
88
+ interface GuardContext {
89
+ ctx: Context;
90
+ session: Session | undefined;
91
+ manager: AuthManagerContract;
92
+ }
93
+ type GuardFactory<User = Authenticatable> = (context: GuardContext) => Guard<User>;
94
+ interface ProviderFactory<User = Authenticatable> {
95
+ (manager: AuthManagerContract): UserProvider<User>;
96
+ }
97
+ interface AuthManagerOptions {
98
+ defaultGuard?: string;
99
+ }
100
+ interface AttachContextOptions {
101
+ guard?: string;
102
+ }
103
+ interface AuthContext<User = Authenticatable> {
104
+ check(): Promise<boolean>;
105
+ guest(): Promise<boolean>;
106
+ user<T = User>(): Promise<T | null>;
107
+ userOrFail<T = User>(): Promise<T>;
108
+ id(): Promise<unknown>;
109
+ login<T = User>(user: T, remember?: boolean): Promise<void>;
110
+ attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
111
+ logout(): Promise<void>;
112
+ guard<T = User>(name?: string): Guard<T>;
113
+ session<T extends Session = Session>(): T | undefined;
114
+ }
115
+ interface AuthManagerContract {
116
+ registerGuard<User = Authenticatable>(name: string, factory: GuardFactory<User>): void;
117
+ registerProvider<User = Authenticatable>(name: string, factory: ProviderFactory<User>): void;
118
+ getProvider<User = Authenticatable>(name: string): UserProvider<User>;
119
+ createGuard<User = Authenticatable>(name: string, context: GuardContext): Guard<User>;
120
+ guardNames(): string[];
121
+ setDefaultGuard(name: string): void;
122
+ getDefaultGuard(): string;
123
+ createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
124
+ }
125
+
126
+ interface PasswordHasher {
127
+ hash(plain: string): Promise<string>;
128
+ verify(hashed: string, plain: string): Promise<boolean>;
129
+ needsRehash?(hashed: string): boolean;
130
+ }
131
+
132
+ declare abstract class BaseUserProvider<User extends Authenticatable = Authenticatable> implements UserProvider<User> {
133
+ abstract retrieveById(identifier: unknown): Promise<User | null>;
134
+ abstract retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
135
+ abstract validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
136
+ abstract getId(user: User): unknown;
137
+ setRememberToken(user: User, token: string | null): Promise<void>;
138
+ getRememberToken(user: User): Promise<string | null>;
139
+ }
140
+
141
+ interface ModelUserProviderOptions {
142
+ idColumn?: string;
143
+ usernameColumn?: string;
144
+ passwordColumn?: string;
145
+ rememberTokenColumn?: string;
146
+ hasher?: PasswordHasher;
147
+ credentialsPasswordField?: string;
148
+ }
149
+ declare class ModelUserProvider<User extends Authenticatable = Authenticatable> extends BaseUserProvider<User> {
150
+ private readonly model;
151
+ private readonly idColumn;
152
+ private readonly usernameColumn;
153
+ private readonly passwordColumn;
154
+ private readonly rememberTokenColumn;
155
+ private readonly hasher;
156
+ private readonly credentialsPasswordField;
157
+ constructor(model: typeof Model, options?: ModelUserProviderOptions);
158
+ private cast;
159
+ retrieveById(identifier: unknown): Promise<User | null>;
160
+ retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
161
+ validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
162
+ getId(user: User): unknown;
163
+ setRememberToken(user: User, token: string | null): Promise<void>;
164
+ getRememberToken(user: User): Promise<string | null>;
165
+ }
166
+
167
+ declare class AuthManager implements AuthManagerContract {
168
+ private readonly guards;
169
+ private readonly providers;
170
+ private defaultGuard;
171
+ constructor(options?: AuthManagerOptions);
172
+ registerGuard<User>(name: string, factory: GuardFactory<User>): void;
173
+ registerProvider<User>(name: string, factory: ProviderFactory<User>): void;
174
+ getProvider<User>(name: string): UserProvider<User>;
175
+ createGuard<User>(name: string, context: GuardContext): Guard<User>;
176
+ guardNames(): string[];
177
+ setDefaultGuard(name: string): void;
178
+ getDefaultGuard(): string;
179
+ createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
180
+ attempt(name: string, ctx: Context, credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
181
+ /**
182
+ * Shorthand method to register a model-based authentication provider and session guard.
183
+ * This simplifies the common case of authenticating users via a database model.
184
+ *
185
+ * @param model - The model class to use for user authentication
186
+ * @param options - Options for the ModelUserProvider (partial, with defaults)
187
+ * @param providerName - Name for the provider (defaults to 'users')
188
+ * @param guardName - Name for the guard (defaults to 'web')
189
+ */
190
+ useModel(model: typeof Model<PlainObject>, options?: Partial<ModelUserProviderOptions>, providerName?: string, guardName?: string): void;
191
+ }
192
+
193
+ interface OAuthProviderConfig {
194
+ clientId: string;
195
+ clientSecret: string;
196
+ redirectUri: string;
197
+ authorizeUrl: string;
198
+ tokenUrl: string;
199
+ userInfoUrl: string;
200
+ scopes?: string[];
201
+ tokenAuthMethod?: 'client_secret_post' | 'client_secret_basic';
202
+ userInfoMethod?: 'GET' | 'POST';
203
+ mapProfile?: (raw: Record<string, unknown>, token: OAuthTokenResult) => OAuthUserProfile;
204
+ }
205
+ interface OAuthTokenResult {
206
+ accessToken: string;
207
+ tokenType?: string;
208
+ refreshToken?: string;
209
+ expiresIn?: number;
210
+ scope?: string;
211
+ raw: Record<string, unknown>;
212
+ }
213
+ interface OAuthUserProfile {
214
+ id: string;
215
+ email?: string;
216
+ name?: string;
217
+ avatar?: string;
218
+ token: OAuthTokenResult;
219
+ raw: Record<string, unknown>;
220
+ }
221
+ interface OAuthStatePayload {
222
+ provider: string;
223
+ redirectTo?: string;
224
+ expiresAt: Date;
225
+ }
226
+ interface OAuthStateStore {
227
+ store(stateHash: string, payload: OAuthStatePayload): Promise<void>;
228
+ find(stateHash: string): Promise<OAuthStatePayload | null>;
229
+ delete(stateHash: string): Promise<void>;
230
+ }
231
+ interface OAuthStateConfig {
232
+ expiresIn?: number;
233
+ stateLength?: number;
234
+ hashAlgorithm?: 'sha256' | 'sha512';
235
+ }
236
+ interface OAuthAuthorizeOptions {
237
+ scope?: string[];
238
+ redirectTo?: string;
239
+ state?: string;
240
+ extraParams?: Record<string, string>;
241
+ }
242
+ interface OAuthCallbackPayload {
243
+ code: string;
244
+ state: string;
245
+ }
246
+ interface OAuthManagerOptions {
247
+ stateStore?: OAuthStateStore;
248
+ stateConfig?: OAuthStateConfig;
249
+ }
250
+ declare class MemoryOAuthStateStore implements OAuthStateStore {
251
+ private readonly states;
252
+ store(stateHash: string, payload: OAuthStatePayload): Promise<void>;
253
+ find(stateHash: string): Promise<OAuthStatePayload | null>;
254
+ delete(stateHash: string): Promise<void>;
255
+ clear(): void;
256
+ }
257
+ declare class OAuthManager {
258
+ private readonly providers;
259
+ private readonly stateStore;
260
+ private readonly stateConfig;
261
+ constructor(options?: OAuthManagerOptions);
262
+ registerProvider(name: string, config: OAuthProviderConfig): void;
263
+ providerNames(): string[];
264
+ getProvider(name: string): OAuthProviderConfig;
265
+ authorize(providerName: string, options?: OAuthAuthorizeOptions): Promise<{
266
+ url: string;
267
+ state: string;
268
+ expiresAt: Date;
269
+ }>;
270
+ user(providerName: string, payload: OAuthCallbackPayload): Promise<OAuthUserProfile>;
271
+ }
272
+ declare function createOAuthManager(options?: OAuthManagerOptions): OAuthManager;
273
+ declare function createOAuthState(provider: string, store: OAuthStateStore, config?: OAuthStateConfig, redirectTo?: string, fixedState?: string): Promise<{
274
+ state: string;
275
+ expiresAt: Date;
276
+ }>;
277
+ declare function verifyOAuthState(state: string, provider: string, store: OAuthStateStore, config?: OAuthStateConfig): Promise<OAuthStatePayload | null>;
278
+ declare function buildOAuthAuthorizeUrl(provider: OAuthProviderConfig, state: string, options?: {
279
+ scope?: string[];
280
+ extraParams?: Record<string, string>;
281
+ }): string;
282
+ declare function exchangeOAuthCode(provider: OAuthProviderConfig, code: string): Promise<OAuthTokenResult>;
283
+ declare function fetchOAuthUserProfile(provider: OAuthProviderConfig, token: OAuthTokenResult): Promise<OAuthUserProfile>;
284
+ interface OAuthProviderFactoryInput {
285
+ clientId: string;
286
+ clientSecret: string;
287
+ redirectUri: string;
288
+ scopes?: string[];
289
+ }
290
+ declare function createGitHubOAuthProviderConfig(input: OAuthProviderFactoryInput): OAuthProviderConfig;
291
+ declare function createGoogleOAuthProviderConfig(input: OAuthProviderFactoryInput): OAuthProviderConfig;
292
+ declare function createDiscordOAuthProviderConfig(input: OAuthProviderFactoryInput): OAuthProviderConfig;
293
+ declare function buildOAuthRedirectUrl(baseUrl: string, token: string, email?: string): string;
294
+ declare function parseOAuthRedirectUrl(url: string): {
295
+ token: string | null;
296
+ email: string | null;
297
+ };
298
+
299
+ /**
300
+ * API token data stored in the backing store.
301
+ */
302
+ interface ApiToken {
303
+ id: string;
304
+ name: string;
305
+ hashedToken: string;
306
+ userId: string | number;
307
+ abilities: string[];
308
+ lastUsedAt: Date | null;
309
+ expiresAt: Date | null;
310
+ createdAt: Date;
311
+ }
312
+ /**
313
+ * Store interface for API tokens.
314
+ * Implement this for database-backed storage.
315
+ */
316
+ interface ApiTokenStore {
317
+ /**
318
+ * Store a new API token.
319
+ */
320
+ store(token: ApiToken): Promise<void>;
321
+ /**
322
+ * Find a token by its hashed value.
323
+ */
324
+ findByHashedToken(hashedToken: string): Promise<ApiToken | null>;
325
+ /**
326
+ * Find all tokens for a user.
327
+ */
328
+ findByUserId(userId: string | number): Promise<ApiToken[]>;
329
+ /**
330
+ * Delete a token by its ID.
331
+ */
332
+ delete(id: string): Promise<void>;
333
+ /**
334
+ * Delete all tokens for a user.
335
+ */
336
+ deleteForUser(userId: string | number): Promise<void>;
337
+ /**
338
+ * Update the last used timestamp.
339
+ */
340
+ updateLastUsed(id: string, timestamp: Date): Promise<void>;
341
+ }
342
+ /**
343
+ * In-memory token store for testing.
344
+ * Do NOT use in production - tokens will be lost on restart.
345
+ */
346
+ declare class MemoryApiTokenStore implements ApiTokenStore {
347
+ private tokens;
348
+ private byHash;
349
+ store(token: ApiToken): Promise<void>;
350
+ findByHashedToken(hashedToken: string): Promise<ApiToken | null>;
351
+ findByUserId(userId: string | number): Promise<ApiToken[]>;
352
+ delete(id: string): Promise<void>;
353
+ deleteForUser(userId: string | number): Promise<void>;
354
+ updateLastUsed(id: string, timestamp: Date): Promise<void>;
355
+ /**
356
+ * Clear all tokens (useful for testing).
357
+ */
358
+ clear(): void;
359
+ /**
360
+ * Get the number of stored tokens.
361
+ */
362
+ get size(): number;
363
+ }
364
+ /**
365
+ * Configuration for API token creation.
366
+ */
367
+ interface CreateApiTokenOptions {
368
+ /**
369
+ * Human-readable name for the token.
370
+ */
371
+ name: string;
372
+ /**
373
+ * User ID the token belongs to.
374
+ */
375
+ userId: string | number;
376
+ /**
377
+ * Token abilities/scopes.
378
+ * @default ['*'] (all abilities)
379
+ */
380
+ abilities?: string[];
381
+ /**
382
+ * Token expiration time in milliseconds from now.
383
+ * @default null (never expires)
384
+ */
385
+ expiresIn?: number | null;
386
+ /**
387
+ * Token byte length (before encoding).
388
+ * @default 32
389
+ */
390
+ tokenLength?: number;
391
+ }
392
+ /**
393
+ * Result of creating an API token.
394
+ */
395
+ interface CreateApiTokenResult {
396
+ /**
397
+ * The full token to give to the user.
398
+ * Format: {id}|{plainToken}
399
+ * This is the ONLY time the plain token is available.
400
+ */
401
+ plainTextToken: string;
402
+ /**
403
+ * The token record (without the plain token).
404
+ */
405
+ token: ApiToken;
406
+ }
407
+ /**
408
+ * Create a new API token.
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * const { plainTextToken, token } = await createApiToken(store, {
413
+ * name: 'My App Token',
414
+ * userId: user.id,
415
+ * abilities: ['read', 'write'],
416
+ * expiresIn: 30 * 24 * 60 * 60 * 1000, // 30 days
417
+ * })
418
+ *
419
+ * // Return plainTextToken to user - this is the only time it's available
420
+ * return ctx.json({ token: plainTextToken })
421
+ * ```
422
+ */
423
+ declare function createApiToken(store: ApiTokenStore, options: CreateApiTokenOptions): Promise<CreateApiTokenResult>;
424
+ /**
425
+ * Parse a plain text token into its components.
426
+ */
427
+ declare function parseApiToken(plainTextToken: string): {
428
+ id: string;
429
+ token: string;
430
+ } | null;
431
+ /**
432
+ * Verify an API token and return the associated user ID.
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * const result = await verifyApiToken(plainTextToken, store)
437
+ *
438
+ * if (!result) {
439
+ * return ctx.json({ error: 'Invalid token' }, 401)
440
+ * }
441
+ *
442
+ * console.log(`User ${result.userId} authenticated with abilities:`, result.abilities)
443
+ * ```
444
+ */
445
+ declare function verifyApiToken(plainTextToken: string, store: ApiTokenStore, options?: {
446
+ updateLastUsed?: boolean;
447
+ }): Promise<{
448
+ token: ApiToken;
449
+ userId: string | number;
450
+ abilities: string[];
451
+ } | null>;
452
+ /**
453
+ * Check if a token has a specific ability.
454
+ */
455
+ declare function tokenCan(token: ApiToken | {
456
+ abilities: string[];
457
+ }, ability: string): boolean;
458
+ /**
459
+ * Check if a token has all specified abilities.
460
+ */
461
+ declare function tokenCanAll(token: ApiToken | {
462
+ abilities: string[];
463
+ }, abilities: string[]): boolean;
464
+ /**
465
+ * Check if a token has any of the specified abilities.
466
+ */
467
+ declare function tokenCanAny(token: ApiToken | {
468
+ abilities: string[];
469
+ }, abilities: string[]): boolean;
470
+ /**
471
+ * Revoke (delete) an API token.
472
+ *
473
+ * @example
474
+ * ```ts
475
+ * await revokeApiToken(tokenId, store)
476
+ * ```
477
+ */
478
+ declare function revokeApiToken(id: string, store: ApiTokenStore): Promise<void>;
479
+ /**
480
+ * Revoke all API tokens for a user.
481
+ *
482
+ * @example
483
+ * ```ts
484
+ * // Revoke all tokens when user changes password
485
+ * await revokeAllApiTokens(user.id, store)
486
+ * ```
487
+ */
488
+ declare function revokeAllApiTokens(userId: string | number, store: ApiTokenStore): Promise<void>;
489
+ /**
490
+ * Get all API tokens for a user.
491
+ *
492
+ * @example
493
+ * ```ts
494
+ * const tokens = await getUserApiTokens(user.id, store)
495
+ * // Returns tokens without the plain text (only metadata)
496
+ * ```
497
+ */
498
+ declare function getUserApiTokens(userId: string | number, store: ApiTokenStore): Promise<ApiToken[]>;
499
+ /**
500
+ * Context key for storing the authenticated token.
501
+ */
502
+ declare const API_TOKEN_KEY = "guren:api-token";
503
+ /**
504
+ * Options for the bearer token middleware.
505
+ */
506
+ interface BearerTokenMiddlewareOptions {
507
+ /**
508
+ * Token store implementation.
509
+ */
510
+ store: ApiTokenStore;
511
+ /**
512
+ * Function to load the user from the user ID.
513
+ */
514
+ loadUser?: (userId: string | number) => Promise<unknown>;
515
+ /**
516
+ * Required abilities for this route.
517
+ * If not specified, any valid token is accepted.
518
+ */
519
+ abilities?: string[];
520
+ /**
521
+ * Custom handler when authentication fails.
522
+ */
523
+ onUnauthorized?: (ctx: Context) => Response | Promise<Response>;
524
+ /**
525
+ * Custom handler when token lacks required abilities.
526
+ */
527
+ onForbidden?: (ctx: Context, required: string[]) => Response | Promise<Response>;
528
+ /**
529
+ * Header name to extract the token from.
530
+ * @default 'Authorization'
531
+ */
532
+ headerName?: string;
533
+ /**
534
+ * Whether to update the token's lastUsedAt timestamp.
535
+ * @default true
536
+ */
537
+ updateLastUsed?: boolean;
538
+ }
539
+ /**
540
+ * Create middleware that authenticates requests using Bearer tokens.
541
+ *
542
+ * @example
543
+ * ```ts
544
+ * // Basic usage
545
+ * app.use('/api/*', createBearerTokenMiddleware({ store }))
546
+ *
547
+ * // With ability requirement
548
+ * router.delete('/api/posts/:id', [PostController, 'destroy'],
549
+ * createBearerTokenMiddleware({
550
+ * store,
551
+ * abilities: ['posts:delete'],
552
+ * })
553
+ * )
554
+ *
555
+ * // With user loading
556
+ * app.use('/api/*', createBearerTokenMiddleware({
557
+ * store,
558
+ * loadUser: async (userId) => User.find(userId),
559
+ * }))
560
+ * ```
561
+ */
562
+ declare function createBearerTokenMiddleware(options: BearerTokenMiddlewareOptions): MiddlewareHandler;
563
+ /**
564
+ * Get the authenticated API token from the request context.
565
+ *
566
+ * @example
567
+ * ```ts
568
+ * router.get('/api/me', async (ctx) => {
569
+ * const { token, userId, abilities } = getApiToken(ctx)!
570
+ * return ctx.json({ userId, tokenName: token.name, abilities })
571
+ * })
572
+ * ```
573
+ */
574
+ declare function getApiToken(ctx: Context): {
575
+ token: ApiToken;
576
+ userId: string | number;
577
+ abilities: string[];
578
+ } | null;
579
+ /**
580
+ * Get the authenticated API token from the request context, or throw.
581
+ *
582
+ * @throws {AuthenticationException} When no token is present in the context.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * router.get('/api/me', async (ctx) => {
587
+ * const { token, userId, abilities } = getApiTokenOrFail(ctx)
588
+ * return ctx.json({ userId, tokenName: token.name, abilities })
589
+ * })
590
+ * ```
591
+ */
592
+ declare function getApiTokenOrFail(ctx: Context): {
593
+ token: ApiToken;
594
+ userId: string | number;
595
+ abilities: string[];
596
+ };
597
+
598
+ export { parseOAuthRedirectUrl as $, AuthManager as A, BaseUserProvider as B, type CreateSessionMiddlewareOptions as C, type SessionStore as D, buildOAuthAuthorizeUrl as E, buildOAuthRedirectUrl as F, type Guard as G, createApiToken as H, createBearerTokenMiddleware as I, createDiscordOAuthProviderConfig as J, createGitHubOAuthProviderConfig as K, createGoogleOAuthProviderConfig as L, MemoryApiTokenStore as M, createOAuthManager as N, OAuthManager as O, type ProviderFactory as P, createOAuthState as Q, createSessionMiddleware as R, type Session as S, exchangeOAuthCode as T, type UserProvider as U, fetchOAuthUserProfile as V, getApiToken as W, getApiTokenOrFail as X, getSessionFromContext as Y, getUserApiTokens as Z, parseApiToken as _, type AuthContext as a, revokeAllApiTokens as a0, revokeApiToken as a1, tokenCan as a2, tokenCanAll as a3, tokenCanAny as a4, verifyApiToken as a5, verifyOAuthState as a6, type PasswordHasher as a7, type AttachContextOptions as a8, type AuthManagerContract as a9, type ApiToken as b, API_TOKEN_KEY as c, type ApiTokenStore as d, type AuthCredentials as e, type AuthManagerOptions as f, type Authenticatable as g, type BearerTokenMiddlewareOptions as h, type CreateApiTokenOptions as i, type CreateApiTokenResult as j, type GuardContext as k, type GuardFactory as l, MemoryOAuthStateStore as m, MemorySessionStore as n, ModelUserProvider as o, type OAuthAuthorizeOptions as p, type OAuthCallbackPayload as q, type OAuthManagerOptions as r, type OAuthProviderConfig as s, type OAuthProviderFactoryInput as t, type OAuthStateConfig as u, type OAuthStatePayload as v, type OAuthStateStore as w, type OAuthTokenResult as x, type OAuthUserProfile as y, type SessionData as z };
@@ -1,5 +1,6 @@
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 { g as Authenticatable, G as Guard, U as UserProvider, S as Session, e as AuthCredentials, a7 as PasswordHasher } from '../api-token-BGOsfuI9.js';
2
+ export { c as API_TOKEN_KEY, b as ApiToken, d as ApiTokenStore, a8 as AttachContextOptions, a as AuthContext, A as AuthManager, a9 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-BGOsfuI9.js';
3
+ import { PlainObject, Model } from '@guren/orm';
3
4
  import 'hono';
4
5
 
5
6
  interface SessionGuardOptions {