@guren/server 1.0.0-rc.24 → 1.0.0-rc.26
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.
- package/dist/{Application-D4_90raL.d.ts → Application-BnsyCKXY.d.ts} +3 -2
- package/dist/AuthManager-SfhCNkAU.d.ts +79 -0
- package/dist/{ConsoleKernel-BPYcP-2f.d.ts → ConsoleKernel-BDtBETjm.d.ts} +1 -1
- package/dist/{api-token-BGOsfuI9.d.ts → api-token-BSSCLlFW.d.ts} +12 -69
- package/dist/auth/index.d.ts +8 -327
- package/dist/auth/index.js +1 -1
- package/dist/{chunk-F3664MFN.js → chunk-2T6JN4VR.js} +52 -6
- package/dist/{chunk-IM6XKMP5.js → chunk-NRLZJILN.js} +12 -5
- package/dist/chunk-UY3AZSYL.js +14 -0
- package/dist/client-CKXJLsTe.d.ts +232 -0
- package/dist/email-verification-CAeArjui.d.ts +327 -0
- package/dist/index.d.ts +27 -238
- package/dist/index.js +25 -20
- package/dist/lambda/index.d.ts +4 -3
- package/dist/mcp/index.d.ts +3 -2
- package/dist/notifications/index.d.ts +4 -3
- package/dist/queue/index.d.ts +4 -3
- package/dist/redis/index.d.ts +366 -0
- package/dist/redis/index.js +597 -0
- package/dist/runtime/index.d.ts +4 -3
- package/dist/runtime/index.js +5 -3
- package/package.json +12 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as hono from 'hono';
|
|
2
2
|
import { Context, MiddlewareHandler, Hono, Next, ExecutionContext } from 'hono';
|
|
3
|
-
import {
|
|
3
|
+
import { l as OAuthManager, g as AuthContext, j as ApiToken, C as CreateSessionMiddlewareOptions } from './api-token-BSSCLlFW.js';
|
|
4
|
+
import { A as AuthManager } from './AuthManager-SfhCNkAU.js';
|
|
4
5
|
import { InlineConfig, ViteDevServer } from 'vite';
|
|
5
6
|
import { E as EventManager } from './EventManager-CmIoLt7r.js';
|
|
6
7
|
import { C as CacheManager } from './CacheManager-BkvHEOZX.js';
|
|
@@ -2177,4 +2178,4 @@ declare class Application {
|
|
|
2177
2178
|
}
|
|
2178
2179
|
declare function createApp(options?: ApplicationOptions): Application;
|
|
2179
2180
|
|
|
2180
|
-
export { type
|
|
2181
|
+
export { type NotificationAttachment as $, Application as A, type InertiaPagePayload as B, Container as C, type DevBannerOptions as D, type ErrorResponse as E, type FailedJob as F, GUREN_ASCII_ART as G, type HostAuthorizationOptions as H, type InertiaOptions as I, type InertiaResponse as J, type InertiaSharedProps as K, type InertiaSsrContext as L, type InertiaSsrOptions as M, NotificationManager as N, type InertiaSsrRenderer as O, type Provider as P, QueueManager as Q, type InertiaSsrResult as R, ServiceProvider as S, type InferInertiaProps as T, Job as U, type JobClass as V, type JobFailureHandler as W, type JobHandler as X, type JobOptions as Y, type Notifiable as Z, Notification as _, type StartViteDevServerOptions as a, setExceptionHandler as a$, type NotificationChannel as a0, type NotificationChannelFactory as a1, type NotificationClass as a2, type NotificationMailMessage as a3, type NotificationManagerOptions as a4, ProviderManager as a5, type QueueConfig as a6, type QueueDriver as a7, type QueueDriverFactory as a8, type QueuedJob as a9, abortIf as aA, abortUnless as aB, clearJobRegistry as aC, createApp as aD, createContainer as aE, createCsrfMiddleware as aF, createExceptionHandler as aG, createHostAuthorizationMiddleware as aH, createNotificationManager as aI, createQueueManager as aJ, createSecurityHeaders as aK, csrfField as aL, formatValidationErrors as aM, getContainer as aN, getCsrfToken as aO, getExceptionHandler as aP, getInertiaSharedPropsResolver as aQ, getJob as aR, getNotificationManager as aS, getQueueDriver as aT, getRegisteredJobs as aU, getValidatedData as aV, inertia as aW, parseRequestPayload as aX, registerJob as aY, resolve as aZ, setContainer as a_, type RendererRegistration as aa, type ResolvedSharedInertiaProps as ab, type ResourceRouteOptions as ac, type RouteBuilder as ad, type RouteContractOptions as ae, type RouteDefinition as af, type RouteOpenApiMetadata as ag, type ResourceAction as ah, Router as ai, type SecurityHeadersOptions as aj, type SentNotification as ak, type ServiceBinding as al, type ServiceClass as am, type ServiceFactory as an, type ServiceProviderClass as ao, type ServiceProviderConstructor as ap, type ServiceProviderOptions as aq, type SharedInertiaPropsResolver as ar, type SlackAttachment as as, type SlackBlock as at, type SlackMessage as au, VALIDATED_DATA_KEY as av, type ValidateRequestOptions as aw, type ValidationSchema as ax, type WorkerOptions as ay, abort as az, type StartedViteDevServer as b, setInertiaSharedProps as b0, setNotificationManager as b1, setQueueDriver as b2, shareInertiaProps as b3, validate as b4, validateRequest as b5, validateRequestWith as b6, validateSafe as b7, verifyCsrfToken as b8, type ServiceBindings as c, type ApplicationListenOptions as d, type ApplicationOptions as e, type AuthPayload as f, type AuthPluginOptions as g, CSRF_FORM_FIELD as h, CSRF_HEADER_NAME as i, CSRF_TOKEN_KEY as j, type ContextualBinding as k, logDevServerBanner as l, type ContextualBindingBuilder as m, type ContextualNeedsBuilder as n, Controller as o, type ControllerInertiaProps as p, type CsrfOptions as q, type DatabaseChannelOptions as r, startViteDevServer as s, type DatabaseNotification as t, type ExceptionClass as u, ExceptionHandler as v, type ExceptionHandlerOptions as w, type ExceptionRenderer as x, type ExceptionReporter as y, type HstsOptions as z };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Context } from 'hono';
|
|
2
|
+
import { Model } from '@guren/orm';
|
|
3
|
+
import { A as Authenticatable, U as UserProvider, a as AuthCredentials, b as AuthManagerContract, c as AuthManagerOptions, G as GuardFactory, P as ProviderFactory, d as GuardContext, e as Guard, f as AttachContextOptions, g as AuthContext } from './api-token-BSSCLlFW.js';
|
|
4
|
+
|
|
5
|
+
interface PasswordHasher {
|
|
6
|
+
hash(plain: string): Promise<string>;
|
|
7
|
+
verify(hashed: string, plain: string): Promise<boolean>;
|
|
8
|
+
needsRehash?(hashed: string): boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare abstract class BaseUserProvider<User extends Authenticatable = Authenticatable> implements UserProvider<User> {
|
|
12
|
+
abstract retrieveById(identifier: unknown): Promise<User | null>;
|
|
13
|
+
abstract retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
14
|
+
abstract validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
15
|
+
abstract getId(user: User): unknown;
|
|
16
|
+
setRememberToken(user: User, token: string | null): Promise<void>;
|
|
17
|
+
getRememberToken(user: User): Promise<string | null>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ModelUserProviderOptions {
|
|
21
|
+
idColumn?: string;
|
|
22
|
+
usernameColumn?: string;
|
|
23
|
+
passwordColumn?: string;
|
|
24
|
+
rememberTokenColumn?: string;
|
|
25
|
+
hasher?: PasswordHasher;
|
|
26
|
+
credentialsPasswordField?: string;
|
|
27
|
+
}
|
|
28
|
+
declare class ModelUserProvider<User extends Authenticatable = Authenticatable> extends BaseUserProvider<User> {
|
|
29
|
+
private readonly model;
|
|
30
|
+
private readonly idColumn;
|
|
31
|
+
private readonly usernameColumn;
|
|
32
|
+
private readonly passwordColumn;
|
|
33
|
+
private readonly rememberTokenColumn;
|
|
34
|
+
private readonly hasher;
|
|
35
|
+
private readonly credentialsPasswordField;
|
|
36
|
+
constructor(model: typeof Model, options?: ModelUserProviderOptions);
|
|
37
|
+
private cast;
|
|
38
|
+
retrieveById(identifier: unknown): Promise<User | null>;
|
|
39
|
+
retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
40
|
+
validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
41
|
+
getId(user: User): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Strip the password hash, remember token, and the model's `hidden`
|
|
44
|
+
* fields before the record leaves the auth layer. Credential
|
|
45
|
+
* validation happens on the raw record before sanitizing, so this
|
|
46
|
+
* never affects login — only what `auth.user()` exposes.
|
|
47
|
+
*/
|
|
48
|
+
sanitize(user: User): User;
|
|
49
|
+
setRememberToken(user: User, token: string | null): Promise<void>;
|
|
50
|
+
getRememberToken(user: User): Promise<string | null>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare class AuthManager implements AuthManagerContract {
|
|
54
|
+
private readonly guards;
|
|
55
|
+
private readonly providers;
|
|
56
|
+
private defaultGuard;
|
|
57
|
+
constructor(options?: AuthManagerOptions);
|
|
58
|
+
registerGuard<User>(name: string, factory: GuardFactory<User>): void;
|
|
59
|
+
registerProvider<User>(name: string, factory: ProviderFactory<User>): void;
|
|
60
|
+
getProvider<User>(name: string): UserProvider<User>;
|
|
61
|
+
createGuard<User>(name: string, context: GuardContext): Guard<User>;
|
|
62
|
+
guardNames(): string[];
|
|
63
|
+
setDefaultGuard(name: string): void;
|
|
64
|
+
getDefaultGuard(): string;
|
|
65
|
+
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
66
|
+
attempt(name: string, ctx: Context, credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Shorthand method to register a model-based authentication provider and session guard.
|
|
69
|
+
* This simplifies the common case of authenticating users via a database model.
|
|
70
|
+
*
|
|
71
|
+
* @param model - The model class to use for user authentication
|
|
72
|
+
* @param options - Options for the ModelUserProvider (partial, with defaults)
|
|
73
|
+
* @param providerName - Name for the provider (defaults to 'users')
|
|
74
|
+
* @param guardName - Name for the guard (defaults to 'web')
|
|
75
|
+
*/
|
|
76
|
+
useModel(model: typeof Model<PlainObject>, options?: Partial<ModelUserProviderOptions>, providerName?: string, guardName?: string): void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { AuthManager as A, BaseUserProvider as B, ModelUserProvider as M, type PasswordHasher as P };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MiddlewareHandler, Context } from 'hono';
|
|
2
|
-
import { Model } from '@guren/orm';
|
|
3
2
|
|
|
4
3
|
type SessionData = Record<string, unknown>;
|
|
5
4
|
interface SessionStore {
|
|
@@ -84,6 +83,12 @@ interface UserProvider<User = Authenticatable> {
|
|
|
84
83
|
getId(user: User): unknown;
|
|
85
84
|
setRememberToken?(user: User, token: string | null): Promise<void> | void;
|
|
86
85
|
getRememberToken?(user: User): Promise<string | null> | string | null;
|
|
86
|
+
/**
|
|
87
|
+
* Strip fields that must never leave the auth layer (password hashes,
|
|
88
|
+
* remember tokens, model `hidden` fields) from a user record before it
|
|
89
|
+
* is cached or handed to application code via guard.user().
|
|
90
|
+
*/
|
|
91
|
+
sanitize?(user: User): User;
|
|
87
92
|
}
|
|
88
93
|
interface GuardContext {
|
|
89
94
|
ctx: Context;
|
|
@@ -123,73 +128,6 @@ interface AuthManagerContract {
|
|
|
123
128
|
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
124
129
|
}
|
|
125
130
|
|
|
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
131
|
interface OAuthProviderConfig {
|
|
194
132
|
clientId: string;
|
|
195
133
|
clientSecret: string;
|
|
@@ -249,7 +187,12 @@ interface OAuthManagerOptions {
|
|
|
249
187
|
}
|
|
250
188
|
declare class MemoryOAuthStateStore implements OAuthStateStore {
|
|
251
189
|
private readonly states;
|
|
190
|
+
private readonly maxEntries;
|
|
191
|
+
constructor(options?: {
|
|
192
|
+
maxEntries?: number;
|
|
193
|
+
});
|
|
252
194
|
store(stateHash: string, payload: OAuthStatePayload): Promise<void>;
|
|
195
|
+
private sweepExpired;
|
|
253
196
|
find(stateHash: string): Promise<OAuthStatePayload | null>;
|
|
254
197
|
delete(stateHash: string): Promise<void>;
|
|
255
198
|
clear(): void;
|
|
@@ -595,4 +538,4 @@ declare function getApiTokenOrFail(ctx: Context): {
|
|
|
595
538
|
abilities: string[];
|
|
596
539
|
};
|
|
597
540
|
|
|
598
|
-
export {
|
|
541
|
+
export { revokeAllApiTokens as $, type Authenticatable as A, type BearerTokenMiddlewareOptions as B, type CreateSessionMiddlewareOptions as C, buildOAuthAuthorizeUrl as D, buildOAuthRedirectUrl as E, createApiToken as F, type GuardFactory as G, createBearerTokenMiddleware as H, createDiscordOAuthProviderConfig as I, createGitHubOAuthProviderConfig as J, createGoogleOAuthProviderConfig as K, createOAuthManager as L, MemoryApiTokenStore as M, createOAuthState as N, type OAuthStateStore as O, type ProviderFactory as P, createSessionMiddleware as Q, exchangeOAuthCode as R, type SessionStore as S, fetchOAuthUserProfile as T, type UserProvider as U, getApiToken as V, getApiTokenOrFail as W, getSessionFromContext as X, getUserApiTokens as Y, parseApiToken as Z, parseOAuthRedirectUrl as _, type AuthCredentials as a, revokeApiToken as a0, tokenCan as a1, tokenCanAll as a2, tokenCanAny as a3, verifyApiToken as a4, verifyOAuthState as a5, type AuthManagerContract as b, type AuthManagerOptions as c, type GuardContext as d, type Guard as e, type AttachContextOptions as f, type AuthContext as g, type SessionData as h, type ApiTokenStore as i, type ApiToken as j, type OAuthStatePayload as k, OAuthManager as l, API_TOKEN_KEY as m, type CreateApiTokenOptions as n, type CreateApiTokenResult as o, MemoryOAuthStateStore as p, MemorySessionStore as q, type OAuthAuthorizeOptions as r, type OAuthCallbackPayload as s, type OAuthManagerOptions as t, type OAuthProviderConfig as u, type OAuthProviderFactoryInput as v, type OAuthStateConfig as w, type OAuthTokenResult as x, type OAuthUserProfile as y, type Session as z };
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
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';
|
|
3
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';
|
|
4
7
|
import 'hono';
|
|
5
8
|
|
|
6
9
|
interface SessionGuardOptions {
|
|
@@ -18,6 +21,8 @@ declare class SessionGuard<User extends Authenticatable = Authenticatable> imple
|
|
|
18
21
|
private sessionKey;
|
|
19
22
|
private rememberSessionKey;
|
|
20
23
|
private loadRememberedUser;
|
|
24
|
+
/** Strip auth-internal fields before a record is cached or exposed. */
|
|
25
|
+
private sanitizeUser;
|
|
21
26
|
private resolveUser;
|
|
22
27
|
check(): Promise<boolean>;
|
|
23
28
|
guest(): Promise<boolean>;
|
|
@@ -92,328 +97,4 @@ declare abstract class AuthenticatableModel<TRecord extends PlainObject = PlainO
|
|
|
92
97
|
protected static preparePersistencePayload(data: PlainObject): Promise<PlainObject>;
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
|
|
96
|
-
* Hash a token using SHA-256 or SHA-512.
|
|
97
|
-
*/
|
|
98
|
-
declare function hashToken(token: string, algorithm?: 'sha256' | 'sha512'): string;
|
|
99
|
-
/**
|
|
100
|
-
* Generate a secure random token.
|
|
101
|
-
*/
|
|
102
|
-
declare function generateToken(length?: number): string;
|
|
103
|
-
/**
|
|
104
|
-
* Generate a random ID (16 bytes = 32 hex chars).
|
|
105
|
-
*/
|
|
106
|
-
declare function generateId(): string;
|
|
107
|
-
/**
|
|
108
|
-
* Securely compare two hex strings using timing-safe comparison.
|
|
109
|
-
*/
|
|
110
|
-
declare function secureCompare(a: string, b: string): boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Securely compare two arbitrary strings using timing-safe comparison.
|
|
113
|
-
* Unlike secureCompare, this works with any string encoding (UUIDs, tokens, etc.).
|
|
114
|
-
*/
|
|
115
|
-
declare function secureStringCompare(a: string, b: string): boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Build a URL with token and optional email parameters.
|
|
118
|
-
*/
|
|
119
|
-
declare function buildTokenUrl(baseUrl: string, token: string, email?: string): string;
|
|
120
|
-
/**
|
|
121
|
-
* Parse a URL to extract token and email parameters.
|
|
122
|
-
*/
|
|
123
|
-
declare function parseTokenUrl(url: string): {
|
|
124
|
-
token: string | null;
|
|
125
|
-
email: string | null;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Configuration for password reset tokens.
|
|
130
|
-
*/
|
|
131
|
-
interface PasswordResetConfig {
|
|
132
|
-
/** Token expiration time in milliseconds (default: 1 hour) */
|
|
133
|
-
expiresIn?: number;
|
|
134
|
-
/** Token byte length before encoding (default: 32) */
|
|
135
|
-
tokenLength?: number;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Storage interface for password reset tokens.
|
|
139
|
-
*/
|
|
140
|
-
interface PasswordResetTokenStore {
|
|
141
|
-
/** Store a token ID with associated email and expiration */
|
|
142
|
-
store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
|
|
143
|
-
/** Find email by token ID, returns null if not found or expired */
|
|
144
|
-
find(tokenId: string): Promise<{
|
|
145
|
-
email: string;
|
|
146
|
-
expiresAt: Date;
|
|
147
|
-
} | null>;
|
|
148
|
-
/** Delete a token ID from storage */
|
|
149
|
-
delete(tokenId: string): Promise<void>;
|
|
150
|
-
/** Delete all tokens for an email */
|
|
151
|
-
deleteForEmail(email: string): Promise<void>;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* In-memory token store for testing and development.
|
|
155
|
-
*/
|
|
156
|
-
declare class MemoryPasswordResetStore implements PasswordResetTokenStore {
|
|
157
|
-
private tokens;
|
|
158
|
-
store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
|
|
159
|
-
find(tokenId: string): Promise<{
|
|
160
|
-
email: string;
|
|
161
|
-
expiresAt: Date;
|
|
162
|
-
} | null>;
|
|
163
|
-
delete(tokenId: string): Promise<void>;
|
|
164
|
-
deleteForEmail(email: string): Promise<void>;
|
|
165
|
-
/** Clear all tokens (useful for testing) */
|
|
166
|
-
clear(): void;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Result of creating a password reset token.
|
|
170
|
-
*/
|
|
171
|
-
interface PasswordResetTokenResult {
|
|
172
|
-
/** The plain-text token to send to the user (via email) */
|
|
173
|
-
token: string;
|
|
174
|
-
/** The token ID stored in the backing store */
|
|
175
|
-
tokenId: string;
|
|
176
|
-
/** When the token expires */
|
|
177
|
-
expiresAt: Date;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Create a password reset token for a user.
|
|
181
|
-
*
|
|
182
|
-
* @param email - The user's email address
|
|
183
|
-
* @param store - The token storage implementation
|
|
184
|
-
* @param config - Optional configuration
|
|
185
|
-
* @returns The token result containing plain token and hash
|
|
186
|
-
*/
|
|
187
|
-
declare function createPasswordResetToken(email: string, store: PasswordResetTokenStore, config?: PasswordResetConfig): Promise<PasswordResetTokenResult>;
|
|
188
|
-
/**
|
|
189
|
-
* Verify a password reset token.
|
|
190
|
-
*
|
|
191
|
-
* @param token - The plain-text token from the reset URL
|
|
192
|
-
* @param store - The token storage implementation
|
|
193
|
-
* @param config - Optional configuration (must match createPasswordResetToken config)
|
|
194
|
-
* @returns The email if token is valid, null otherwise
|
|
195
|
-
*/
|
|
196
|
-
declare function verifyPasswordResetToken(token: string, store: PasswordResetTokenStore, _config?: PasswordResetConfig): Promise<string | null>;
|
|
197
|
-
/**
|
|
198
|
-
* Complete a password reset by updating the user's password and invalidating the token.
|
|
199
|
-
*
|
|
200
|
-
* @param token - The plain-text token from the reset URL
|
|
201
|
-
* @param newPassword - The new password (should be validated by caller)
|
|
202
|
-
* @param store - The token storage implementation
|
|
203
|
-
* @param provider - The user provider to look up and update the user
|
|
204
|
-
* @param updatePassword - Function to update the user's password
|
|
205
|
-
* @param config - Optional configuration
|
|
206
|
-
* @returns The user if reset was successful, null if token is invalid
|
|
207
|
-
*/
|
|
208
|
-
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>;
|
|
209
|
-
/**
|
|
210
|
-
* Build a password reset URL from a base URL and token.
|
|
211
|
-
*/
|
|
212
|
-
declare const buildPasswordResetUrl: typeof buildTokenUrl;
|
|
213
|
-
/**
|
|
214
|
-
* Parse a password reset URL to extract the token and optional email.
|
|
215
|
-
*/
|
|
216
|
-
declare const parsePasswordResetUrl: typeof parseTokenUrl;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Email verification token data stored in the backing store.
|
|
220
|
-
* Only the hashed token is stored for security.
|
|
221
|
-
*/
|
|
222
|
-
interface EmailVerificationToken {
|
|
223
|
-
email: string;
|
|
224
|
-
tokenId: string;
|
|
225
|
-
expiresAt: Date;
|
|
226
|
-
createdAt: Date;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Store interface for email verification tokens.
|
|
230
|
-
* Implement this to use database-backed storage.
|
|
231
|
-
*/
|
|
232
|
-
interface EmailVerificationTokenStore {
|
|
233
|
-
/**
|
|
234
|
-
* Store a new verification token.
|
|
235
|
-
*/
|
|
236
|
-
store(token: EmailVerificationToken): Promise<void>;
|
|
237
|
-
/**
|
|
238
|
-
* Find a token by its opaque token ID.
|
|
239
|
-
*/
|
|
240
|
-
findByTokenId(tokenId: string): Promise<EmailVerificationToken | null>;
|
|
241
|
-
/**
|
|
242
|
-
* Delete a token by its opaque token ID.
|
|
243
|
-
*/
|
|
244
|
-
delete(tokenId: string): Promise<void>;
|
|
245
|
-
/**
|
|
246
|
-
* Delete all tokens for a given email.
|
|
247
|
-
*/
|
|
248
|
-
deleteForEmail(email: string): Promise<void>;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* In-memory store for testing purposes.
|
|
252
|
-
* Do NOT use in production - tokens will be lost on restart.
|
|
253
|
-
*/
|
|
254
|
-
declare class MemoryEmailVerificationStore implements EmailVerificationTokenStore {
|
|
255
|
-
private tokens;
|
|
256
|
-
store(token: EmailVerificationToken): Promise<void>;
|
|
257
|
-
findByTokenId(tokenId: string): Promise<EmailVerificationToken | null>;
|
|
258
|
-
delete(tokenId: string): Promise<void>;
|
|
259
|
-
deleteForEmail(email: string): Promise<void>;
|
|
260
|
-
/**
|
|
261
|
-
* Clear all tokens (useful for testing).
|
|
262
|
-
*/
|
|
263
|
-
clear(): void;
|
|
264
|
-
/**
|
|
265
|
-
* Get the count of stored tokens (useful for testing).
|
|
266
|
-
*/
|
|
267
|
-
get size(): number;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Configuration options for email verification.
|
|
271
|
-
*/
|
|
272
|
-
interface EmailVerificationConfig {
|
|
273
|
-
/**
|
|
274
|
-
* Token expiration time in milliseconds.
|
|
275
|
-
* @default 86400000 (24 hours)
|
|
276
|
-
*/
|
|
277
|
-
expiresIn?: number;
|
|
278
|
-
/**
|
|
279
|
-
* Token byte length (before hex encoding).
|
|
280
|
-
* @default 32
|
|
281
|
-
*/
|
|
282
|
-
tokenLength?: number;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Result of creating an email verification token.
|
|
286
|
-
*/
|
|
287
|
-
interface EmailVerificationTokenResult {
|
|
288
|
-
/**
|
|
289
|
-
* The raw token to send to the user via email.
|
|
290
|
-
* This is NOT stored - only the hash is stored.
|
|
291
|
-
*/
|
|
292
|
-
token: string;
|
|
293
|
-
/**
|
|
294
|
-
* When the token expires.
|
|
295
|
-
*/
|
|
296
|
-
expiresAt: Date;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Create a new email verification token.
|
|
300
|
-
*
|
|
301
|
-
* @param email - The email address to verify
|
|
302
|
-
* @param store - Token store implementation
|
|
303
|
-
* @param config - Optional configuration
|
|
304
|
-
* @returns The raw token to send via email
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* ```ts
|
|
308
|
-
* const { token, expiresAt } = await createEmailVerificationToken(
|
|
309
|
-
* user.email,
|
|
310
|
-
* verificationStore
|
|
311
|
-
* )
|
|
312
|
-
*
|
|
313
|
-
* // Send email with verification link
|
|
314
|
-
* await sendEmail({
|
|
315
|
-
* to: user.email,
|
|
316
|
-
* subject: 'Verify your email',
|
|
317
|
-
* html: `<a href="${buildVerificationUrl(baseUrl, token)}">Verify Email</a>`,
|
|
318
|
-
* })
|
|
319
|
-
* ```
|
|
320
|
-
*/
|
|
321
|
-
declare function createEmailVerificationToken(email: string, store: EmailVerificationTokenStore, config?: EmailVerificationConfig): Promise<EmailVerificationTokenResult>;
|
|
322
|
-
/**
|
|
323
|
-
* Verify an email verification token.
|
|
324
|
-
*
|
|
325
|
-
* @param token - The raw token from the verification link
|
|
326
|
-
* @param store - Token store implementation
|
|
327
|
-
* @param config - Optional configuration (not currently used, reserved for future)
|
|
328
|
-
* @returns The email address if valid, null if invalid or expired
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* ```ts
|
|
332
|
-
* const email = await verifyEmailToken(token, verificationStore)
|
|
333
|
-
*
|
|
334
|
-
* if (!email) {
|
|
335
|
-
* return ctx.json({ error: 'Invalid or expired token' }, 400)
|
|
336
|
-
* }
|
|
337
|
-
*
|
|
338
|
-
* // Mark user as verified
|
|
339
|
-
* await User.update({ email }, { emailVerifiedAt: new Date() })
|
|
340
|
-
* ```
|
|
341
|
-
*/
|
|
342
|
-
declare function verifyEmailToken(token: string, store: EmailVerificationTokenStore, _config?: EmailVerificationConfig): Promise<string | null>;
|
|
343
|
-
/**
|
|
344
|
-
* Complete email verification by consuming the token.
|
|
345
|
-
*
|
|
346
|
-
* @param token - The raw token from the verification link
|
|
347
|
-
* @param store - Token store implementation
|
|
348
|
-
* @param markVerified - Function to mark the user as verified
|
|
349
|
-
* @returns The result of markVerified if successful, null if token invalid
|
|
350
|
-
*
|
|
351
|
-
* @example
|
|
352
|
-
* ```ts
|
|
353
|
-
* const result = await completeEmailVerification(
|
|
354
|
-
* token,
|
|
355
|
-
* verificationStore,
|
|
356
|
-
* async (email) => {
|
|
357
|
-
* await User.update({ email }, { emailVerifiedAt: new Date() })
|
|
358
|
-
* return User.findByEmail(email)
|
|
359
|
-
* }
|
|
360
|
-
* )
|
|
361
|
-
*
|
|
362
|
-
* if (!result) {
|
|
363
|
-
* return ctx.json({ error: 'Invalid or expired token' }, 400)
|
|
364
|
-
* }
|
|
365
|
-
*
|
|
366
|
-
* return ctx.redirect('/dashboard')
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
declare function completeEmailVerification<T>(token: string, store: EmailVerificationTokenStore, markVerified: (email: string) => Promise<T>): Promise<T | null>;
|
|
370
|
-
/**
|
|
371
|
-
* Build a verification URL.
|
|
372
|
-
*/
|
|
373
|
-
declare const buildVerificationUrl: typeof buildTokenUrl;
|
|
374
|
-
/**
|
|
375
|
-
* Parse a verification URL to extract token and email.
|
|
376
|
-
*/
|
|
377
|
-
declare const parseVerificationUrl: typeof parseTokenUrl;
|
|
378
|
-
/**
|
|
379
|
-
* Check if a user's email is verified.
|
|
380
|
-
* Helper function for use with User models.
|
|
381
|
-
*
|
|
382
|
-
* @param user - User object with emailVerifiedAt field
|
|
383
|
-
* @returns true if verified, false otherwise
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```ts
|
|
387
|
-
* if (!isEmailVerified(user)) {
|
|
388
|
-
* return ctx.redirect('/verify-email')
|
|
389
|
-
* }
|
|
390
|
-
* ```
|
|
391
|
-
*/
|
|
392
|
-
declare function isEmailVerified(user: {
|
|
393
|
-
emailVerifiedAt?: Date | null;
|
|
394
|
-
} | null): boolean;
|
|
395
|
-
/**
|
|
396
|
-
* Middleware factory to require verified email.
|
|
397
|
-
*
|
|
398
|
-
* @param options - Configuration options
|
|
399
|
-
* @returns Middleware function
|
|
400
|
-
*
|
|
401
|
-
* @example
|
|
402
|
-
* ```ts
|
|
403
|
-
* router.get('/dashboard', [DashboardController, 'index'],
|
|
404
|
-
* requireAuthenticated(),
|
|
405
|
-
* requireVerifiedEmail({ redirectTo: '/verify-email' })
|
|
406
|
-
* )
|
|
407
|
-
* ```
|
|
408
|
-
*/
|
|
409
|
-
declare function requireVerifiedEmail(options?: {
|
|
410
|
-
redirectTo?: string;
|
|
411
|
-
getUser?: (ctx: unknown) => Promise<{
|
|
412
|
-
emailVerifiedAt?: Date | null;
|
|
413
|
-
} | null>;
|
|
414
|
-
}): (ctx: {
|
|
415
|
-
get: (key: string) => unknown;
|
|
416
|
-
redirect: (url: string) => Response;
|
|
417
|
-
}, next: () => Promise<void>) => Promise<Response | undefined>;
|
|
418
|
-
|
|
419
|
-
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 };
|
package/dist/auth/index.js
CHANGED