@guren/server 1.4.0 → 2.0.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.
- package/dist/{AuthManager-C84xF5ks.d.ts → AuthManager-DBP4KYsx.d.ts} +1 -1
- package/dist/ConsoleKernel-DlK9j2Lu.d.ts +101 -0
- package/dist/DocsViewerServiceProvider-D7RGJPGM.js +75 -0
- package/dist/{I18nManager-CmUqj6bU.d.ts → I18nManager-BiSoczfV.d.ts} +1 -1
- package/dist/McpServiceProvider-7BB5FPF3.js +8 -0
- package/dist/auth/index.d.ts +39 -29
- package/dist/auth/index.js +2 -2
- package/dist/broadcasting/index.js +2 -2
- package/dist/cache/index.js +2 -2
- package/dist/chunk-2V3YID4H.js +20 -0
- package/dist/{chunk-JIT7QVMJ.js → chunk-4DW4GRWF.js} +3 -3
- package/dist/{chunk-R2TCP7D7.js → chunk-6J6B5KOB.js} +18 -2
- package/dist/chunk-AZOYI43J.js +18 -0
- package/dist/{chunk-DCYKSYAT.js → chunk-B5E5VBDI.js} +54 -2
- package/dist/{chunk-NYQGAWDN.js → chunk-BZMZEFRG.js} +7 -11
- package/dist/{chunk-4SBGSJNT.js → chunk-CWI4AJ47.js} +2 -1
- package/dist/{chunk-NQCZQAJL.js → chunk-DSDX3ASM.js} +21 -2
- package/dist/{chunk-MC752CQT.js → chunk-EI5GYMAT.js} +2 -1
- package/dist/{chunk-AUXQISW5.js → chunk-HONCNQXZ.js} +38 -5
- package/dist/{chunk-CSRQTEQA.js → chunk-HWEWL6TE.js} +6 -1
- package/dist/chunk-JBG4AR24.js +18 -0
- package/dist/{chunk-EDRGAM6G.js → chunk-K6CUBJX6.js} +11 -16
- package/dist/{chunk-WJJ5CTNI.js → chunk-KTNJG7R7.js} +6 -2
- package/dist/{chunk-74HTZG3V.js → chunk-LAJQCSSF.js} +24 -0
- package/dist/{chunk-H32L2NE3.js → chunk-LVJCZCAV.js} +20 -13
- package/dist/{chunk-CSDKWLFD.js → chunk-N7PLD7MB.js} +120 -43
- package/dist/{chunk-ONSDE37A.js → chunk-SFQP6O52.js} +1 -0
- package/dist/{chunk-XMQZENBP.js → chunk-TVY72CLV.js} +3 -1
- package/dist/chunk-WIXGT4TN.js +18 -0
- package/dist/{email-verification-H_WlpsVH.d.ts → email-verification-D8N7P6Pu.d.ts} +1 -1
- package/dist/encryption/index.js +2 -2
- package/dist/events/index.js +1 -1
- package/dist/i18n/index.d.ts +2 -2
- package/dist/index.d.ts +348 -330
- package/dist/index.js +332 -110
- package/dist/lambda/index.d.ts +5 -5
- package/dist/lambda/index.js +1 -1
- package/dist/mail/index.js +4 -3
- package/dist/mcp/index.d.ts +14 -4
- package/dist/mcp/index.js +3 -2
- package/dist/notifications/index.d.ts +55 -6
- package/dist/notifications/index.js +12 -3
- package/dist/queue/index.d.ts +5 -5
- package/dist/queue/index.js +4 -2
- package/dist/redis/index.d.ts +4 -4
- package/dist/redis/index.js +7 -0
- package/dist/runtime/index.d.ts +5 -5
- package/dist/runtime/index.js +24 -9
- package/dist/scheduling/index.js +2 -2
- package/dist/storage/index.js +2 -1
- package/dist/{Application-BvBqgc2k.d.ts → validation-CDR7lRE8.d.ts} +873 -654
- package/package.json +3 -3
- package/dist/ConsoleKernel-Dw9X9qZY.d.ts +0 -207
- package/dist/McpServiceProvider-TZWQWXCT.js +0 -7
- package/dist/{api-token-COQHXyM_.d.ts → api-token-D24VPr_E.d.ts} +101 -101
- package/dist/{client-BQwF2b9Y.d.ts → rate-limit-D9J2b4S1.d.ts} +36 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
"test": "bun test"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@guren/orm": "^
|
|
113
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
112
|
+
"@guren/orm": "^2.0.0",
|
|
113
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
114
114
|
"chalk": "^5.3.0",
|
|
115
115
|
"consola": "^3.4.2",
|
|
116
116
|
"figlet": "^1.7.0",
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { C as Container } from './Application-BvBqgc2k.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Parsed argument definition.
|
|
5
|
-
*/
|
|
6
|
-
interface ArgumentDefinition {
|
|
7
|
-
name: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
array: boolean;
|
|
11
|
-
defaultValue?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Parsed option definition.
|
|
15
|
-
*/
|
|
16
|
-
interface OptionDefinition {
|
|
17
|
-
name: string;
|
|
18
|
-
shortcut?: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
requiresValue: boolean;
|
|
21
|
-
defaultValue?: string | boolean;
|
|
22
|
-
array: boolean;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Parsed signature.
|
|
26
|
-
*/
|
|
27
|
-
interface ParsedSignature {
|
|
28
|
-
name: string;
|
|
29
|
-
arguments: ArgumentDefinition[];
|
|
30
|
-
options: OptionDefinition[];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Command class type.
|
|
34
|
-
*/
|
|
35
|
-
interface CommandClass {
|
|
36
|
-
signature: string;
|
|
37
|
-
description: string;
|
|
38
|
-
new (container?: Container): CommandInstance;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Command instance type.
|
|
42
|
-
*/
|
|
43
|
-
interface CommandInstance {
|
|
44
|
-
setInput(argv: string[]): void;
|
|
45
|
-
setOutput(output: OutputInterface): void;
|
|
46
|
-
setKernel(kernel: {
|
|
47
|
-
handle(argv: string[]): Promise<number>;
|
|
48
|
-
}): void;
|
|
49
|
-
run(): Promise<number>;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Output interface.
|
|
53
|
-
*/
|
|
54
|
-
interface OutputInterface {
|
|
55
|
-
info(message: string): void;
|
|
56
|
-
error(message: string): void;
|
|
57
|
-
warn(message: string): void;
|
|
58
|
-
success(message: string): void;
|
|
59
|
-
line(message: string): void;
|
|
60
|
-
newLine(count?: number): void;
|
|
61
|
-
table(headers: string[], rows: string[][]): void;
|
|
62
|
-
write(message: string): void;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Input interface.
|
|
66
|
-
*/
|
|
67
|
-
interface InputInterface {
|
|
68
|
-
argument<T = string>(name: string): T;
|
|
69
|
-
arguments(): Record<string, string | string[]>;
|
|
70
|
-
option<T = string | boolean>(name: string): T | undefined;
|
|
71
|
-
options(): Record<string, string | boolean | string[]>;
|
|
72
|
-
hasOption(name: string): boolean;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Console kernel options.
|
|
76
|
-
*/
|
|
77
|
-
interface ConsoleKernelOptions {
|
|
78
|
-
container?: Container;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Schedule definition for a command.
|
|
82
|
-
*/
|
|
83
|
-
interface ScheduledCommand {
|
|
84
|
-
command: string;
|
|
85
|
-
args?: string[];
|
|
86
|
-
expression: string;
|
|
87
|
-
timezone?: string;
|
|
88
|
-
description?: string;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Interactive prompt types.
|
|
92
|
-
*/
|
|
93
|
-
interface PromptInterface {
|
|
94
|
-
ask(question: string, defaultValue?: string): Promise<string>;
|
|
95
|
-
confirm(question: string, defaultValue?: boolean): Promise<boolean>;
|
|
96
|
-
choice<T extends string>(question: string, choices: T[], defaultValue?: T): Promise<T>;
|
|
97
|
-
secret(question: string): Promise<string>;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Progress bar interface.
|
|
101
|
-
*/
|
|
102
|
-
interface ProgressInterface {
|
|
103
|
-
start(total: number): void;
|
|
104
|
-
advance(step?: number): void;
|
|
105
|
-
finish(): void;
|
|
106
|
-
setProgress(current: number): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Console kernel for managing and executing commands.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* const kernel = new ConsoleKernel()
|
|
115
|
-
*
|
|
116
|
-
* kernel.register(CreateUserCommand)
|
|
117
|
-
* kernel.register(SendNotificationsCommand)
|
|
118
|
-
*
|
|
119
|
-
* // Execute command
|
|
120
|
-
* const exitCode = await kernel.handle(['users:create', 'john@example.com', '--admin'])
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
declare class ConsoleKernel {
|
|
124
|
-
/**
|
|
125
|
-
* Registered commands.
|
|
126
|
-
*/
|
|
127
|
-
protected commands: Map<string, CommandClass>;
|
|
128
|
-
/**
|
|
129
|
-
* Service container.
|
|
130
|
-
*/
|
|
131
|
-
protected container?: Container;
|
|
132
|
-
/**
|
|
133
|
-
* Output instance.
|
|
134
|
-
*/
|
|
135
|
-
protected output: OutputInterface;
|
|
136
|
-
constructor(options?: ConsoleKernelOptions);
|
|
137
|
-
/**
|
|
138
|
-
* Register a command.
|
|
139
|
-
*/
|
|
140
|
-
register(command: CommandClass): this;
|
|
141
|
-
/**
|
|
142
|
-
* Register multiple commands.
|
|
143
|
-
*/
|
|
144
|
-
registerMany(commands: CommandClass[]): this;
|
|
145
|
-
/**
|
|
146
|
-
* Get all registered commands.
|
|
147
|
-
*/
|
|
148
|
-
getCommands(): Map<string, CommandClass>;
|
|
149
|
-
/**
|
|
150
|
-
* Get a command by name.
|
|
151
|
-
*/
|
|
152
|
-
getCommand(name: string): CommandClass | undefined;
|
|
153
|
-
/**
|
|
154
|
-
* Check if a command is registered.
|
|
155
|
-
*/
|
|
156
|
-
hasCommand(name: string): boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Set the output instance.
|
|
159
|
-
*/
|
|
160
|
-
setOutput(output: OutputInterface): this;
|
|
161
|
-
/**
|
|
162
|
-
* Get the output instance.
|
|
163
|
-
*/
|
|
164
|
-
getOutput(): OutputInterface;
|
|
165
|
-
/**
|
|
166
|
-
* Handle command execution.
|
|
167
|
-
*/
|
|
168
|
-
handle(argv?: string[]): Promise<number>;
|
|
169
|
-
/**
|
|
170
|
-
* Run a command.
|
|
171
|
-
*/
|
|
172
|
-
protected runCommand(CommandClass: CommandClass, args: string[]): Promise<number>;
|
|
173
|
-
/**
|
|
174
|
-
* Show help.
|
|
175
|
-
*/
|
|
176
|
-
protected showHelp(): void;
|
|
177
|
-
/**
|
|
178
|
-
* Show help for a specific command.
|
|
179
|
-
*/
|
|
180
|
-
protected showCommandHelp(commandName: string): void;
|
|
181
|
-
/**
|
|
182
|
-
* List all commands.
|
|
183
|
-
*/
|
|
184
|
-
protected listCommands(): void;
|
|
185
|
-
/**
|
|
186
|
-
* Group commands by namespace.
|
|
187
|
-
*/
|
|
188
|
-
protected groupCommands(): Map<string, Map<string, CommandClass>>;
|
|
189
|
-
/**
|
|
190
|
-
* Suggest similar commands.
|
|
191
|
-
*/
|
|
192
|
-
protected suggestCommands(input: string): void;
|
|
193
|
-
/**
|
|
194
|
-
* Calculate string similarity (simple Dice coefficient).
|
|
195
|
-
*/
|
|
196
|
-
protected similarity(a: string, b: string): number;
|
|
197
|
-
/**
|
|
198
|
-
* Call a command programmatically.
|
|
199
|
-
*/
|
|
200
|
-
call(commandName: string, args?: string[], silent?: boolean): Promise<number>;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Create a console kernel.
|
|
204
|
-
*/
|
|
205
|
-
declare function createConsoleKernel(options?: ConsoleKernelOptions): ConsoleKernel;
|
|
206
|
-
|
|
207
|
-
export { type ArgumentDefinition as A, ConsoleKernel as C, type InputInterface as I, type OptionDefinition as O, type ParsedSignature as P, type ScheduledCommand as S, type CommandInstance as a, type OutputInterface as b, type CommandClass as c, type ConsoleKernelOptions as d, type ProgressInterface as e, type PromptInterface as f, createConsoleKernel as g };
|
|
@@ -75,107 +75,6 @@ declare function getSessionFromContext<T extends Session = Session>(ctx: {
|
|
|
75
75
|
get: (key: string) => unknown;
|
|
76
76
|
}): T | undefined;
|
|
77
77
|
|
|
78
|
-
type AuthCredentials = Record<string, unknown>;
|
|
79
|
-
interface Authenticatable {
|
|
80
|
-
getAuthIdentifier(): unknown;
|
|
81
|
-
getAuthPassword(): string | null | undefined;
|
|
82
|
-
getRememberToken?(): string | null | undefined;
|
|
83
|
-
setRememberToken?(token: string | null): void | Promise<void>;
|
|
84
|
-
}
|
|
85
|
-
interface Guard<User = Authenticatable> {
|
|
86
|
-
check(): Promise<boolean>;
|
|
87
|
-
guest(): Promise<boolean>;
|
|
88
|
-
user<T = User>(): Promise<T | null>;
|
|
89
|
-
id(): Promise<unknown>;
|
|
90
|
-
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
91
|
-
logout(): Promise<void>;
|
|
92
|
-
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
93
|
-
validate(credentials: AuthCredentials): Promise<User | null>;
|
|
94
|
-
session<T extends Session = Session>(): T | undefined;
|
|
95
|
-
}
|
|
96
|
-
interface UserProvider<User = Authenticatable> {
|
|
97
|
-
retrieveById(identifier: unknown): Promise<User | null>;
|
|
98
|
-
retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
99
|
-
validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
100
|
-
getId(user: User): unknown;
|
|
101
|
-
setRememberToken?(user: User, token: string | null): Promise<void> | void;
|
|
102
|
-
getRememberToken?(user: User): Promise<string | null> | string | null;
|
|
103
|
-
/**
|
|
104
|
-
* Strip fields that must never leave the auth layer (password hashes,
|
|
105
|
-
* remember tokens, model `hidden` fields) from a user record before it
|
|
106
|
-
* is cached or handed to application code via guard.user().
|
|
107
|
-
*/
|
|
108
|
-
sanitize?(user: User): User;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* The conventional names for the credential columns that
|
|
112
|
-
* `ModelUserProvider.sanitize()` strips: the password column (`password`
|
|
113
|
-
* by default, commonly configured as `passwordHash`/`password_hash`) and
|
|
114
|
-
* the remember-token column (`remember_token` by default, commonly
|
|
115
|
-
* `rememberToken`).
|
|
116
|
-
*/
|
|
117
|
-
type DefaultSanitizedKeys = 'password' | 'passwordHash' | 'password_hash' | 'rememberToken' | 'remember_token';
|
|
118
|
-
/**
|
|
119
|
-
* The shape of a user record after auth-layer sanitization — what
|
|
120
|
-
* `auth.user()` returns at runtime when the provider's column names
|
|
121
|
-
* follow the {@link DefaultSanitizedKeys} conventions. Removes those
|
|
122
|
-
* conventional credential keys plus any extra keys passed as `Hidden`.
|
|
123
|
-
*
|
|
124
|
-
* The runtime strips exactly the *configured* password/remember-token
|
|
125
|
-
* columns plus the model's `static hidden` — a static type cannot see
|
|
126
|
-
* that configuration. If your columns use other names, or the model
|
|
127
|
-
* hides additional fields, list them in `Hidden` explicitly. Only
|
|
128
|
-
* meaningful for concrete record types (index-signature records like
|
|
129
|
-
* `Record<string, string>` cannot have individual keys removed).
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* const user = await this.auth.userOrFail<Sanitized<UserRecord>>()
|
|
134
|
-
* user.passwordHash // compile error — stripped at runtime
|
|
135
|
-
*
|
|
136
|
-
* // With additional hidden fields or custom column names:
|
|
137
|
-
* type SafeUser = Sanitized<UserRecord, 'twoFactorSecret' | 'credentialDigest'>
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
type Sanitized<User, Hidden extends string = never> = User extends unknown ? Omit<User, Extract<keyof User, DefaultSanitizedKeys | Hidden>> : never;
|
|
141
|
-
interface GuardContext {
|
|
142
|
-
ctx: Context;
|
|
143
|
-
session: Session | undefined;
|
|
144
|
-
manager: AuthManagerContract;
|
|
145
|
-
}
|
|
146
|
-
type GuardFactory<User = Authenticatable> = (context: GuardContext) => Guard<User>;
|
|
147
|
-
interface ProviderFactory<User = Authenticatable> {
|
|
148
|
-
(manager: AuthManagerContract): UserProvider<User>;
|
|
149
|
-
}
|
|
150
|
-
interface AuthManagerOptions {
|
|
151
|
-
defaultGuard?: string;
|
|
152
|
-
}
|
|
153
|
-
interface AttachContextOptions {
|
|
154
|
-
guard?: string;
|
|
155
|
-
}
|
|
156
|
-
interface AuthContext<User = Authenticatable> {
|
|
157
|
-
check(): Promise<boolean>;
|
|
158
|
-
guest(): Promise<boolean>;
|
|
159
|
-
user<T = User>(): Promise<T | null>;
|
|
160
|
-
userOrFail<T = User>(): Promise<T>;
|
|
161
|
-
id(): Promise<unknown>;
|
|
162
|
-
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
163
|
-
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
164
|
-
logout(): Promise<void>;
|
|
165
|
-
guard<T = User>(name?: string): Guard<T>;
|
|
166
|
-
session<T extends Session = Session>(): T | undefined;
|
|
167
|
-
}
|
|
168
|
-
interface AuthManagerContract {
|
|
169
|
-
registerGuard<User = Authenticatable>(name: string, factory: GuardFactory<User>): void;
|
|
170
|
-
registerProvider<User = Authenticatable>(name: string, factory: ProviderFactory<User>): void;
|
|
171
|
-
getProvider<User = Authenticatable>(name: string): UserProvider<User>;
|
|
172
|
-
createGuard<User = Authenticatable>(name: string, context: GuardContext): Guard<User>;
|
|
173
|
-
guardNames(): string[];
|
|
174
|
-
setDefaultGuard(name: string): void;
|
|
175
|
-
getDefaultGuard(): string;
|
|
176
|
-
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
78
|
interface OAuthProviderConfig {
|
|
180
79
|
clientId: string;
|
|
181
80
|
clientSecret: string;
|
|
@@ -361,6 +260,107 @@ declare function parseOAuthRedirectUrl(url: string): {
|
|
|
361
260
|
email: string | null;
|
|
362
261
|
};
|
|
363
262
|
|
|
263
|
+
type AuthCredentials = Record<string, unknown>;
|
|
264
|
+
interface Authenticatable {
|
|
265
|
+
getAuthIdentifier(): unknown;
|
|
266
|
+
getAuthPassword(): string | null | undefined;
|
|
267
|
+
getRememberToken?(): string | null | undefined;
|
|
268
|
+
setRememberToken?(token: string | null): void | Promise<void>;
|
|
269
|
+
}
|
|
270
|
+
interface Guard<User = Authenticatable> {
|
|
271
|
+
check(): Promise<boolean>;
|
|
272
|
+
guest(): Promise<boolean>;
|
|
273
|
+
user<T = User>(): Promise<T | null>;
|
|
274
|
+
id(): Promise<unknown>;
|
|
275
|
+
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
276
|
+
logout(): Promise<void>;
|
|
277
|
+
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
278
|
+
validate(credentials: AuthCredentials): Promise<User | null>;
|
|
279
|
+
session<T extends Session = Session>(): T | undefined;
|
|
280
|
+
}
|
|
281
|
+
interface UserProvider<User = Authenticatable> {
|
|
282
|
+
retrieveById(identifier: unknown): Promise<User | null>;
|
|
283
|
+
retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
|
|
284
|
+
validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
|
|
285
|
+
getId(user: User): unknown;
|
|
286
|
+
setRememberToken?(user: User, token: string | null): Promise<void> | void;
|
|
287
|
+
getRememberToken?(user: User): Promise<string | null> | string | null;
|
|
288
|
+
/**
|
|
289
|
+
* Strip fields that must never leave the auth layer (password hashes,
|
|
290
|
+
* remember tokens, model `hidden` fields) from a user record before it
|
|
291
|
+
* is cached or handed to application code via guard.user().
|
|
292
|
+
*/
|
|
293
|
+
sanitize?(user: User): User;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The conventional names for the credential columns that
|
|
297
|
+
* `ModelUserProvider.sanitize()` strips: the password column (`password`
|
|
298
|
+
* by default, commonly configured as `passwordHash`/`password_hash`) and
|
|
299
|
+
* the remember-token column (`remember_token` by default, commonly
|
|
300
|
+
* `rememberToken`).
|
|
301
|
+
*/
|
|
302
|
+
type DefaultSanitizedKeys = 'password' | 'passwordHash' | 'password_hash' | 'rememberToken' | 'remember_token';
|
|
303
|
+
/**
|
|
304
|
+
* The shape of a user record after auth-layer sanitization — what
|
|
305
|
+
* `auth.user()` returns at runtime when the provider's column names
|
|
306
|
+
* follow the {@link DefaultSanitizedKeys} conventions. Removes those
|
|
307
|
+
* conventional credential keys plus any extra keys passed as `Hidden`.
|
|
308
|
+
*
|
|
309
|
+
* The runtime strips exactly the *configured* password/remember-token
|
|
310
|
+
* columns plus the model's `static hidden` — a static type cannot see
|
|
311
|
+
* that configuration. If your columns use other names, or the model
|
|
312
|
+
* hides additional fields, list them in `Hidden` explicitly. Only
|
|
313
|
+
* meaningful for concrete record types (index-signature records like
|
|
314
|
+
* `Record<string, string>` cannot have individual keys removed).
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* const user = await this.auth.userOrFail<Sanitized<UserRecord>>()
|
|
319
|
+
* user.passwordHash // compile error — stripped at runtime
|
|
320
|
+
*
|
|
321
|
+
* // With additional hidden fields or custom column names:
|
|
322
|
+
* type SafeUser = Sanitized<UserRecord, 'twoFactorSecret' | 'credentialDigest'>
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
type Sanitized<User, Hidden extends string = never> = User extends unknown ? Omit<User, Extract<keyof User, DefaultSanitizedKeys | Hidden>> : never;
|
|
326
|
+
interface GuardContext {
|
|
327
|
+
ctx: Context;
|
|
328
|
+
session: Session | undefined;
|
|
329
|
+
manager: AuthManagerContract;
|
|
330
|
+
}
|
|
331
|
+
type GuardFactory<User = Authenticatable> = (context: GuardContext) => Guard<User>;
|
|
332
|
+
interface ProviderFactory<User = Authenticatable> {
|
|
333
|
+
(manager: AuthManagerContract): UserProvider<User>;
|
|
334
|
+
}
|
|
335
|
+
interface AuthManagerOptions {
|
|
336
|
+
defaultGuard?: string;
|
|
337
|
+
}
|
|
338
|
+
interface AttachContextOptions {
|
|
339
|
+
guard?: string;
|
|
340
|
+
}
|
|
341
|
+
interface AuthContext<User = Authenticatable> {
|
|
342
|
+
check(): Promise<boolean>;
|
|
343
|
+
guest(): Promise<boolean>;
|
|
344
|
+
user<T = User>(): Promise<T | null>;
|
|
345
|
+
userOrFail<T = User>(): Promise<T>;
|
|
346
|
+
id(): Promise<unknown>;
|
|
347
|
+
login<T = User>(user: T, remember?: boolean): Promise<void>;
|
|
348
|
+
attempt(credentials: AuthCredentials, remember?: boolean): Promise<boolean>;
|
|
349
|
+
logout(): Promise<void>;
|
|
350
|
+
guard<T = User>(name?: string): Guard<T>;
|
|
351
|
+
session<T extends Session = Session>(): T | undefined;
|
|
352
|
+
}
|
|
353
|
+
interface AuthManagerContract {
|
|
354
|
+
registerGuard<User = Authenticatable>(name: string, factory: GuardFactory<User>): void;
|
|
355
|
+
registerProvider<User = Authenticatable>(name: string, factory: ProviderFactory<User>): void;
|
|
356
|
+
getProvider<User = Authenticatable>(name: string): UserProvider<User>;
|
|
357
|
+
createGuard<User = Authenticatable>(name: string, context: GuardContext): Guard<User>;
|
|
358
|
+
guardNames(): string[];
|
|
359
|
+
setDefaultGuard(name: string): void;
|
|
360
|
+
getDefaultGuard(): string;
|
|
361
|
+
createAuthContext(ctx: Context, options?: AttachContextOptions): AuthContext;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
364
|
/**
|
|
365
365
|
* API token data stored in the backing store.
|
|
366
366
|
*/
|
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
import { Context, MiddlewareHandler } from 'hono';
|
|
2
1
|
import Redis, { RedisOptions } from 'ioredis';
|
|
2
|
+
import { Context, MiddlewareHandler } from 'hono';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for creating a Redis client.
|
|
6
|
+
*/
|
|
7
|
+
interface RedisClientOptions extends RedisOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Redis connection URL (e.g., 'redis://localhost:6379').
|
|
10
|
+
* If provided, overrides host/port/password.
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Key prefix for all operations.
|
|
15
|
+
* @default ''
|
|
16
|
+
*/
|
|
17
|
+
keyPrefix?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a Redis client with the given options.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // Using URL
|
|
25
|
+
* const redis = createRedisClient({ url: 'redis://localhost:6379' })
|
|
26
|
+
*
|
|
27
|
+
* // Using host/port
|
|
28
|
+
* const redis = createRedisClient({ host: 'localhost', port: 6379 })
|
|
29
|
+
*
|
|
30
|
+
* // With key prefix
|
|
31
|
+
* const redis = createRedisClient({
|
|
32
|
+
* url: process.env.REDIS_URL,
|
|
33
|
+
* keyPrefix: 'myapp:',
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function createRedisClient(options?: RedisClientOptions): Redis;
|
|
3
38
|
|
|
4
39
|
/**
|
|
5
40
|
* Rate limit entry stored in the backing store.
|
|
@@ -201,39 +236,4 @@ declare class SlidingWindowRateLimitStore extends BaseMemoryStore {
|
|
|
201
236
|
get size(): number;
|
|
202
237
|
}
|
|
203
238
|
|
|
204
|
-
/**
|
|
205
|
-
* Options for creating a Redis client.
|
|
206
|
-
*/
|
|
207
|
-
interface RedisClientOptions extends RedisOptions {
|
|
208
|
-
/**
|
|
209
|
-
* Redis connection URL (e.g., 'redis://localhost:6379').
|
|
210
|
-
* If provided, overrides host/port/password.
|
|
211
|
-
*/
|
|
212
|
-
url?: string;
|
|
213
|
-
/**
|
|
214
|
-
* Key prefix for all operations.
|
|
215
|
-
* @default ''
|
|
216
|
-
*/
|
|
217
|
-
keyPrefix?: string;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Create a Redis client with the given options.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```ts
|
|
224
|
-
* // Using URL
|
|
225
|
-
* const redis = createRedisClient({ url: 'redis://localhost:6379' })
|
|
226
|
-
*
|
|
227
|
-
* // Using host/port
|
|
228
|
-
* const redis = createRedisClient({ host: 'localhost', port: 6379 })
|
|
229
|
-
*
|
|
230
|
-
* // With key prefix
|
|
231
|
-
* const redis = createRedisClient({
|
|
232
|
-
* url: process.env.REDIS_URL,
|
|
233
|
-
* keyPrefix: 'myapp:',
|
|
234
|
-
* })
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
declare function createRedisClient(options?: RedisClientOptions): Redis;
|
|
238
|
-
|
|
239
239
|
export { MemoryRateLimitStore as M, type RateLimitStore as R, SlidingWindowRateLimitStore as S, type RateLimitEntry as a, type RedisClientOptions as b, createRedisClient as c, type RateLimitInfo as d, type RateLimitOptions as e, createRateLimitMiddleware as f, getRateLimitInfo as g, resetRateLimit as r };
|