@longzai-intelligence-auth/elysia 0.0.4 → 0.0.5
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/index.d.ts +648 -25
- package/dist/index.js +1 -15
- package/package.json +12 -30
- package/dist/core/auth-strategy.d.ts +0 -14
- package/dist/core/auth-strategy.js +0 -98
- package/dist/core/error-mapper.d.ts +0 -2
- package/dist/core/error-mapper.js +0 -27
- package/dist/plugin.d.ts +0 -6
- package/dist/plugin.js +0 -39
- package/dist/plugins/audit.plugin.d.ts +0 -38
- package/dist/plugins/audit.plugin.js +0 -13
- package/dist/plugins/error-handler.plugin.d.ts +0 -46
- package/dist/plugins/error-handler.plugin.js +0 -45
- package/dist/plugins/jwt-verify.plugin.d.ts +0 -9
- package/dist/plugins/jwt-verify.plugin.js +0 -31
- package/dist/plugins/logger.plugin.d.ts +0 -33
- package/dist/plugins/logger.plugin.js +0 -16
- package/dist/plugins/rate-limit.plugin.d.ts +0 -40
- package/dist/plugins/rate-limit.plugin.js +0 -39
- package/dist/plugins/rbac.plugin.d.ts +0 -36
- package/dist/plugins/rbac.plugin.js +0 -42
- package/dist/plugins/tenant.plugin.d.ts +0 -38
- package/dist/plugins/tenant.plugin.js +0 -19
- package/dist/presets/basic-preset.d.ts +0 -11
- package/dist/presets/basic-preset.js +0 -11
- package/dist/presets/standard-preset.d.ts +0 -13
- package/dist/presets/standard-preset.js +0 -26
- package/dist/routes/auth.routes.d.ts +0 -17
- package/dist/routes/auth.routes.js +0 -145
- package/dist/types/auth-plugin-config.d.ts +0 -40
- package/dist/types/auth-plugin-config.js +0 -1
- package/dist/utils/extract-client-ip.d.ts +0 -1
- package/dist/utils/extract-client-ip.js +0 -5
- package/dist/utils/extract-user-agent.d.ts +0 -1
- package/dist/utils/extract-user-agent.js +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,648 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { DomainError } from "@longzai-intelligence/error";
|
|
2
|
+
import { JwtConfig, LoggerService, RateLimiterPort, ResourceAction, TenantValidateFn, TokenVerifierPort, UnifiedAuthContext, UnifiedAuthContext as UnifiedAuthContext$1 } from "@longzai-intelligence-auth/core";
|
|
3
|
+
import { Elysia } from "elysia";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/core/error-mapper.d.ts
|
|
7
|
+
/** 根据 DomainError 类型映射 HTTP 状态码 */
|
|
8
|
+
declare function mapDomainErrorToStatus(error: DomainError): number;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/plugins/jwt-verify.plugin.d.ts
|
|
11
|
+
/** JWT 验证插件解析后的认证上下文 */
|
|
12
|
+
type VerifiedAuthContext = {
|
|
13
|
+
/** 用户 ID(来自 payload.sub) */userId: string; /** 租户 ID(来自 payload.tenantId,默认使用 defaultTenantId) */
|
|
14
|
+
tenantId: string; /** 角色列表 */
|
|
15
|
+
roles: string[]; /** 权限列表 */
|
|
16
|
+
permissions: string[]; /** JWT ID(用于 token 黑名单检查) */
|
|
17
|
+
jti?: string;
|
|
18
|
+
};
|
|
19
|
+
type JwtVerifyPluginOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
|
|
20
|
+
/** 令牌验证器端口(用户注入,与 jwt 二选一) */verifier?: TokenVerifierPort; /** JWT 配置(与 verifier 二选一,未提供时使用默认配置) */
|
|
21
|
+
jwt?: JwtConfig; /** 默认租户 ID */
|
|
22
|
+
defaultTenantId?: string; /** 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*") */
|
|
23
|
+
publicPaths?: string[]; /** 扩展 schema,用于从 payload 中解析自定义业务字段 */
|
|
24
|
+
extendSchema?: T;
|
|
25
|
+
};
|
|
26
|
+
/** 从 extendSchema 提取额外字段类型 */
|
|
27
|
+
type ExtractExtra<T extends z.ZodTypeAny> = T extends z.ZodUndefined ? Record<string, never> : z.infer<T>;
|
|
28
|
+
/** 完整的认证上下文类型(基础字段 + 扩展字段) */
|
|
29
|
+
type AuthContextWithExtra<T extends z.ZodTypeAny = z.ZodUndefined> = VerifiedAuthContext & ExtractExtra<T>;
|
|
30
|
+
declare function createJwtVerifyPlugin<T extends z.ZodTypeAny = z.ZodUndefined>(options: JwtVerifyPluginOptions<T>): Elysia<"", {
|
|
31
|
+
decorator: {};
|
|
32
|
+
store: {};
|
|
33
|
+
derive: {};
|
|
34
|
+
resolve: {};
|
|
35
|
+
}, {
|
|
36
|
+
typebox: {};
|
|
37
|
+
error: {};
|
|
38
|
+
}, {
|
|
39
|
+
schema: {};
|
|
40
|
+
standaloneSchema: {};
|
|
41
|
+
macro: {};
|
|
42
|
+
macroFn: {};
|
|
43
|
+
parser: {};
|
|
44
|
+
response: {};
|
|
45
|
+
}, {}, {
|
|
46
|
+
derive: {
|
|
47
|
+
readonly auth: any;
|
|
48
|
+
};
|
|
49
|
+
resolve: {};
|
|
50
|
+
schema: {};
|
|
51
|
+
standaloneSchema: {};
|
|
52
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
53
|
+
readonly auth: any;
|
|
54
|
+
}>;
|
|
55
|
+
}, {
|
|
56
|
+
derive: {};
|
|
57
|
+
resolve: {};
|
|
58
|
+
schema: {};
|
|
59
|
+
standaloneSchema: {};
|
|
60
|
+
response: {};
|
|
61
|
+
}>;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/plugins/optional-jwt.plugin.d.ts
|
|
64
|
+
type OptionalJwtPluginOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
|
|
65
|
+
/** 令牌验证器端口(用户注入,与 jwt 二选一) */verifier?: TokenVerifierPort; /** JWT 配置(与 verifier 二选一,未提供时使用默认配置) */
|
|
66
|
+
jwt?: JwtConfig; /** 默认租户 ID */
|
|
67
|
+
defaultTenantId?: string; /** 扩展 schema,用于从 payload 中解析自定义业务字段 */
|
|
68
|
+
extendSchema?: T;
|
|
69
|
+
};
|
|
70
|
+
/** 可选认证上下文,auth 为 null 表示未认证 */
|
|
71
|
+
type OptionalAuthContext<T extends z.ZodTypeAny = z.ZodUndefined> = {
|
|
72
|
+
auth: (UnifiedAuthContext$1 & (T extends z.ZodUndefined ? Record<string, never> : z.infer<T>)) | null;
|
|
73
|
+
};
|
|
74
|
+
declare function createOptionalJwtPlugin<T extends z.ZodTypeAny = z.ZodUndefined>(options: OptionalJwtPluginOptions<T>): Elysia<"", {
|
|
75
|
+
decorator: {};
|
|
76
|
+
store: {};
|
|
77
|
+
derive: {};
|
|
78
|
+
resolve: {};
|
|
79
|
+
}, {
|
|
80
|
+
typebox: {};
|
|
81
|
+
error: {};
|
|
82
|
+
}, {
|
|
83
|
+
schema: {};
|
|
84
|
+
standaloneSchema: {};
|
|
85
|
+
macro: {};
|
|
86
|
+
macroFn: {};
|
|
87
|
+
parser: {};
|
|
88
|
+
response: {};
|
|
89
|
+
}, {}, {
|
|
90
|
+
derive: {
|
|
91
|
+
readonly auth: any;
|
|
92
|
+
};
|
|
93
|
+
resolve: {};
|
|
94
|
+
schema: {};
|
|
95
|
+
standaloneSchema: {};
|
|
96
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
97
|
+
readonly auth: any;
|
|
98
|
+
}>;
|
|
99
|
+
}, {
|
|
100
|
+
derive: {};
|
|
101
|
+
resolve: {};
|
|
102
|
+
schema: {};
|
|
103
|
+
standaloneSchema: {};
|
|
104
|
+
response: {};
|
|
105
|
+
}>;
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/plugins/rbac.plugin.d.ts
|
|
108
|
+
/** 用户角色策略接口,用于数据库查询权限 */
|
|
109
|
+
type UserRoleStrategy = {
|
|
110
|
+
/** 查询用户在指定租户下的所有权限 */findPermissionsByUserId(userId: string, tenantId: string): Promise<ResourceAction[]>;
|
|
111
|
+
};
|
|
112
|
+
type RbacPluginOptions = {
|
|
113
|
+
/** 用户角色策略(用于数据库查询权限,优先于上下文权限) */userRole?: UserRoleStrategy;
|
|
114
|
+
};
|
|
115
|
+
declare function createRbacPlugin(options?: RbacPluginOptions): Elysia<"", {
|
|
116
|
+
decorator: {};
|
|
117
|
+
store: {};
|
|
118
|
+
derive: {
|
|
119
|
+
readonly requirePermission: (resource: string, action: string) => Promise<void>;
|
|
120
|
+
};
|
|
121
|
+
resolve: {};
|
|
122
|
+
}, {
|
|
123
|
+
typebox: {};
|
|
124
|
+
error: {};
|
|
125
|
+
}, {
|
|
126
|
+
schema: {};
|
|
127
|
+
standaloneSchema: {};
|
|
128
|
+
macro: {};
|
|
129
|
+
macroFn: {};
|
|
130
|
+
parser: {};
|
|
131
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
132
|
+
readonly requirePermission: (resource: string, action: string) => Promise<void>;
|
|
133
|
+
}>;
|
|
134
|
+
}, {}, {
|
|
135
|
+
derive: {};
|
|
136
|
+
resolve: {};
|
|
137
|
+
schema: {};
|
|
138
|
+
standaloneSchema: {};
|
|
139
|
+
response: {};
|
|
140
|
+
}, {
|
|
141
|
+
derive: {};
|
|
142
|
+
resolve: {};
|
|
143
|
+
schema: {};
|
|
144
|
+
standaloneSchema: {};
|
|
145
|
+
response: {};
|
|
146
|
+
}>;
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/plugins/api-key.plugin.d.ts
|
|
149
|
+
/** API Key 认证的主体信息 */
|
|
150
|
+
type ApiKeyPrincipal = {
|
|
151
|
+
/** 主体标识 */principalId: string; /** 租户 ID */
|
|
152
|
+
tenantId?: string; /** 角色列表 */
|
|
153
|
+
roles: string[]; /** 权限列表 */
|
|
154
|
+
permissions: string[];
|
|
155
|
+
};
|
|
156
|
+
type ApiKeyPluginOptions = {
|
|
157
|
+
/** API Key 所在的请求头名称(默认 "x-api-key") */header?: string; /** API Key 验证器,返回 null 表示无效 */
|
|
158
|
+
validator: (key: string) => Promise<ApiKeyPrincipal | null>;
|
|
159
|
+
};
|
|
160
|
+
declare function createApiKeyPlugin(options: ApiKeyPluginOptions): Elysia<"", {
|
|
161
|
+
decorator: {};
|
|
162
|
+
store: {};
|
|
163
|
+
derive: {};
|
|
164
|
+
resolve: {};
|
|
165
|
+
}, {
|
|
166
|
+
typebox: {};
|
|
167
|
+
error: {};
|
|
168
|
+
}, {
|
|
169
|
+
schema: {};
|
|
170
|
+
standaloneSchema: {};
|
|
171
|
+
macro: {};
|
|
172
|
+
macroFn: {};
|
|
173
|
+
parser: {};
|
|
174
|
+
response: {};
|
|
175
|
+
}, {}, {
|
|
176
|
+
derive: {
|
|
177
|
+
auth: UnifiedAuthContext$1;
|
|
178
|
+
};
|
|
179
|
+
resolve: {};
|
|
180
|
+
schema: {};
|
|
181
|
+
standaloneSchema: {};
|
|
182
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
183
|
+
auth: UnifiedAuthContext$1;
|
|
184
|
+
}>;
|
|
185
|
+
}, {
|
|
186
|
+
derive: {};
|
|
187
|
+
resolve: {};
|
|
188
|
+
schema: {};
|
|
189
|
+
standaloneSchema: {};
|
|
190
|
+
response: {};
|
|
191
|
+
}>;
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/plugins/in-memory-api-key-validator.d.ts
|
|
194
|
+
/** 内存 API Key 映射条目 */
|
|
195
|
+
type InMemoryApiKeyEntry = {
|
|
196
|
+
/** 主体标识 */principalId: string; /** 租户ID(可选) */
|
|
197
|
+
tenantId?: string; /** 角色列表 */
|
|
198
|
+
roles: string[]; /** 权限列表 */
|
|
199
|
+
permissions: string[];
|
|
200
|
+
};
|
|
201
|
+
/** 内存 API Key 映射表 */
|
|
202
|
+
type InMemoryApiKeyMap = Record<string, InMemoryApiKeyEntry>;
|
|
203
|
+
/**
|
|
204
|
+
* 创建内存 API Key 验证器
|
|
205
|
+
* 接受静态 API Key 映射,返回符合 createApiKeyPlugin 的 validator 函数
|
|
206
|
+
* @param keyMap - API Key 到主体信息的映射
|
|
207
|
+
* @returns validator 函数
|
|
208
|
+
*/
|
|
209
|
+
declare function createInMemoryApiKeyValidator(keyMap: InMemoryApiKeyMap): (key: string) => Promise<ApiKeyPrincipal | null>;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/plugins/composite-auth.plugin.d.ts
|
|
212
|
+
type CompositeAuthPluginOptions = {
|
|
213
|
+
/** 令牌验证器端口(用户注入,与 jwt 二选一) */verifier?: TokenVerifierPort; /** JWT 配置(与 verifier 二选一,未提供时使用默认配置) */
|
|
214
|
+
jwt?: JwtConfig; /** 默认租户 ID */
|
|
215
|
+
defaultTenantId?: string; /** API Key 验证器 */
|
|
216
|
+
apiKeyValidator?: (key: string) => Promise<ApiKeyPrincipal | null>; /** API Key 所在的请求头名称(默认 "x-api-key") */
|
|
217
|
+
apiKeyHeader?: string; /** 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*") */
|
|
218
|
+
publicPaths?: string[];
|
|
219
|
+
};
|
|
220
|
+
/** 组合认证上下文(向后兼容,内部使用 UnifiedAuthContext) */
|
|
221
|
+
type CompositeAuthContext = UnifiedAuthContext$1;
|
|
222
|
+
declare function createCompositeAuthPlugin(options: CompositeAuthPluginOptions): Elysia<"", {
|
|
223
|
+
decorator: {};
|
|
224
|
+
store: {};
|
|
225
|
+
derive: {};
|
|
226
|
+
resolve: {};
|
|
227
|
+
}, {
|
|
228
|
+
typebox: {};
|
|
229
|
+
error: {};
|
|
230
|
+
}, {
|
|
231
|
+
schema: {};
|
|
232
|
+
standaloneSchema: {};
|
|
233
|
+
macro: {};
|
|
234
|
+
macroFn: {};
|
|
235
|
+
parser: {};
|
|
236
|
+
response: {};
|
|
237
|
+
}, {}, {
|
|
238
|
+
derive: {
|
|
239
|
+
auth: UnifiedAuthContext$1 | null;
|
|
240
|
+
};
|
|
241
|
+
resolve: {};
|
|
242
|
+
schema: {};
|
|
243
|
+
standaloneSchema: {};
|
|
244
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
245
|
+
auth: UnifiedAuthContext$1 | null;
|
|
246
|
+
}>;
|
|
247
|
+
}, {
|
|
248
|
+
derive: {};
|
|
249
|
+
resolve: {};
|
|
250
|
+
schema: {};
|
|
251
|
+
standaloneSchema: {};
|
|
252
|
+
response: {};
|
|
253
|
+
}>;
|
|
254
|
+
/** 创建要求认证的组合认证插件(未认证时抛出异常) */
|
|
255
|
+
declare function createRequiredCompositeAuthPlugin(options: CompositeAuthPluginOptions): Elysia<"", {
|
|
256
|
+
decorator: {};
|
|
257
|
+
store: {};
|
|
258
|
+
derive: {};
|
|
259
|
+
resolve: {};
|
|
260
|
+
}, {
|
|
261
|
+
typebox: {};
|
|
262
|
+
error: {};
|
|
263
|
+
}, {
|
|
264
|
+
schema: {};
|
|
265
|
+
standaloneSchema: {};
|
|
266
|
+
macro: {};
|
|
267
|
+
macroFn: {};
|
|
268
|
+
parser: {};
|
|
269
|
+
response: {};
|
|
270
|
+
}, {}, {
|
|
271
|
+
derive: {
|
|
272
|
+
auth: UnifiedAuthContext$1;
|
|
273
|
+
};
|
|
274
|
+
resolve: {};
|
|
275
|
+
schema: {};
|
|
276
|
+
standaloneSchema: {};
|
|
277
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
278
|
+
auth: UnifiedAuthContext$1;
|
|
279
|
+
}>;
|
|
280
|
+
}, {
|
|
281
|
+
derive: {};
|
|
282
|
+
resolve: {};
|
|
283
|
+
schema: {};
|
|
284
|
+
standaloneSchema: {};
|
|
285
|
+
response: {};
|
|
286
|
+
}>;
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/plugins/tenant.plugin.d.ts
|
|
289
|
+
type TenantPluginOptions = {
|
|
290
|
+
/** 默认租户 ID */defaultTenantId?: string; /** 租户验证函数 */
|
|
291
|
+
validateFn?: TenantValidateFn;
|
|
292
|
+
};
|
|
293
|
+
declare function createTenantPlugin(options?: TenantPluginOptions): Elysia<"", {
|
|
294
|
+
decorator: {};
|
|
295
|
+
store: {};
|
|
296
|
+
derive: {
|
|
297
|
+
tenantId: string;
|
|
298
|
+
};
|
|
299
|
+
resolve: {};
|
|
300
|
+
}, {
|
|
301
|
+
typebox: {};
|
|
302
|
+
error: {};
|
|
303
|
+
}, {
|
|
304
|
+
schema: {};
|
|
305
|
+
standaloneSchema: {};
|
|
306
|
+
macro: {};
|
|
307
|
+
macroFn: {};
|
|
308
|
+
parser: {};
|
|
309
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
310
|
+
tenantId: string;
|
|
311
|
+
}> & {};
|
|
312
|
+
}, {}, {
|
|
313
|
+
derive: {};
|
|
314
|
+
resolve: {};
|
|
315
|
+
schema: {};
|
|
316
|
+
standaloneSchema: {};
|
|
317
|
+
response: {};
|
|
318
|
+
}, {
|
|
319
|
+
derive: {};
|
|
320
|
+
resolve: {};
|
|
321
|
+
schema: {};
|
|
322
|
+
standaloneSchema: {};
|
|
323
|
+
response: {};
|
|
324
|
+
}>;
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/plugins/rate-limit.plugin.d.ts
|
|
327
|
+
type RateLimitPluginOptions = {
|
|
328
|
+
/** 速率限制器端口(用户注入) */limiter: RateLimiterPort; /** 日志服务 */
|
|
329
|
+
logger?: LoggerService; /** 键生成器(用于从请求中提取限制键) */
|
|
330
|
+
keyGenerator?: (request: Request) => string;
|
|
331
|
+
};
|
|
332
|
+
declare function createRateLimitPlugin(options: RateLimitPluginOptions): Elysia<"", {
|
|
333
|
+
decorator: {};
|
|
334
|
+
store: {};
|
|
335
|
+
derive: {
|
|
336
|
+
readonly clientIp: string;
|
|
337
|
+
} & {
|
|
338
|
+
readonly rateLimitRemaining: number;
|
|
339
|
+
};
|
|
340
|
+
resolve: {};
|
|
341
|
+
}, {
|
|
342
|
+
typebox: {};
|
|
343
|
+
error: {};
|
|
344
|
+
}, {
|
|
345
|
+
schema: {};
|
|
346
|
+
standaloneSchema: {};
|
|
347
|
+
macro: {};
|
|
348
|
+
macroFn: {};
|
|
349
|
+
parser: {};
|
|
350
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
351
|
+
readonly rateLimitRemaining: number;
|
|
352
|
+
}>;
|
|
353
|
+
}, {}, {
|
|
354
|
+
derive: {};
|
|
355
|
+
resolve: {};
|
|
356
|
+
schema: {};
|
|
357
|
+
standaloneSchema: {};
|
|
358
|
+
response: {};
|
|
359
|
+
}, {
|
|
360
|
+
derive: {};
|
|
361
|
+
resolve: {};
|
|
362
|
+
schema: {};
|
|
363
|
+
standaloneSchema: {};
|
|
364
|
+
response: {};
|
|
365
|
+
}>;
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/plugins/error-handler.plugin.d.ts
|
|
368
|
+
type ErrorHandlerPluginOptions = {
|
|
369
|
+
logger?: LoggerService;
|
|
370
|
+
};
|
|
371
|
+
declare function createErrorHandlerPlugin(options?: ErrorHandlerPluginOptions): Elysia<"", {
|
|
372
|
+
decorator: {};
|
|
373
|
+
store: {};
|
|
374
|
+
derive: {};
|
|
375
|
+
resolve: {};
|
|
376
|
+
}, {
|
|
377
|
+
typebox: {};
|
|
378
|
+
error: {};
|
|
379
|
+
}, {
|
|
380
|
+
schema: {};
|
|
381
|
+
standaloneSchema: {};
|
|
382
|
+
macro: {};
|
|
383
|
+
macroFn: {};
|
|
384
|
+
parser: {};
|
|
385
|
+
response: {
|
|
386
|
+
200: {
|
|
387
|
+
details?: Record<string, unknown> | undefined;
|
|
388
|
+
code: string;
|
|
389
|
+
message: string;
|
|
390
|
+
} | {
|
|
391
|
+
code: string;
|
|
392
|
+
message: string;
|
|
393
|
+
details: {
|
|
394
|
+
path: string;
|
|
395
|
+
message: string | undefined;
|
|
396
|
+
}[];
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
}, {}, {
|
|
400
|
+
derive: {};
|
|
401
|
+
resolve: {};
|
|
402
|
+
schema: {};
|
|
403
|
+
standaloneSchema: {};
|
|
404
|
+
response: {};
|
|
405
|
+
}, {
|
|
406
|
+
derive: {};
|
|
407
|
+
resolve: {};
|
|
408
|
+
schema: {};
|
|
409
|
+
standaloneSchema: {};
|
|
410
|
+
response: {};
|
|
411
|
+
}>;
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/plugins/logger.plugin.d.ts
|
|
414
|
+
type LoggerPluginOptions = {
|
|
415
|
+
logger: LoggerService;
|
|
416
|
+
};
|
|
417
|
+
declare function createLoggerPlugin(options: LoggerPluginOptions): Elysia<"", {
|
|
418
|
+
decorator: {};
|
|
419
|
+
store: {};
|
|
420
|
+
derive: {};
|
|
421
|
+
resolve: {};
|
|
422
|
+
}, {
|
|
423
|
+
typebox: {};
|
|
424
|
+
error: {};
|
|
425
|
+
}, {
|
|
426
|
+
schema: {};
|
|
427
|
+
standaloneSchema: {};
|
|
428
|
+
macro: {};
|
|
429
|
+
macroFn: {};
|
|
430
|
+
parser: {};
|
|
431
|
+
response: {};
|
|
432
|
+
}, {}, {
|
|
433
|
+
derive: {};
|
|
434
|
+
resolve: {};
|
|
435
|
+
schema: {};
|
|
436
|
+
standaloneSchema: {};
|
|
437
|
+
response: {};
|
|
438
|
+
}, {
|
|
439
|
+
derive: {};
|
|
440
|
+
resolve: {};
|
|
441
|
+
schema: {};
|
|
442
|
+
standaloneSchema: {};
|
|
443
|
+
response: {};
|
|
444
|
+
}>;
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/presets/basic-preset.d.ts
|
|
447
|
+
type BasicPresetOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
|
|
448
|
+
/** 令牌验证器端口(用户注入) */tokenVerifier: TokenVerifierPort; /** 默认租户 ID */
|
|
449
|
+
defaultTenantId?: string; /** 日志服务 */
|
|
450
|
+
logger?: LoggerService; /** 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*") */
|
|
451
|
+
publicPaths?: string[]; /** 扩展 schema,用于从 payload 中解析自定义业务字段 */
|
|
452
|
+
extendSchema?: T;
|
|
453
|
+
};
|
|
454
|
+
declare function createBasicPreset<T extends z.ZodTypeAny = z.ZodUndefined>(options: BasicPresetOptions<T>): Elysia<"", {
|
|
455
|
+
decorator: {};
|
|
456
|
+
store: {};
|
|
457
|
+
derive: {};
|
|
458
|
+
resolve: {};
|
|
459
|
+
}, {
|
|
460
|
+
typebox: {};
|
|
461
|
+
error: {};
|
|
462
|
+
}, {
|
|
463
|
+
schema: {};
|
|
464
|
+
standaloneSchema: {};
|
|
465
|
+
macro: {};
|
|
466
|
+
macroFn: {};
|
|
467
|
+
parser: {};
|
|
468
|
+
response: {};
|
|
469
|
+
} & {
|
|
470
|
+
schema: {};
|
|
471
|
+
standaloneSchema: {};
|
|
472
|
+
macro: {};
|
|
473
|
+
macroFn: {};
|
|
474
|
+
parser: {};
|
|
475
|
+
response: {
|
|
476
|
+
200: {
|
|
477
|
+
details?: Record<string, unknown> | undefined;
|
|
478
|
+
code: string;
|
|
479
|
+
message: string;
|
|
480
|
+
} | {
|
|
481
|
+
code: string;
|
|
482
|
+
message: string;
|
|
483
|
+
details: {
|
|
484
|
+
path: string;
|
|
485
|
+
message: string | undefined;
|
|
486
|
+
}[];
|
|
487
|
+
};
|
|
488
|
+
};
|
|
489
|
+
}, {}, {
|
|
490
|
+
derive: {};
|
|
491
|
+
resolve: {};
|
|
492
|
+
schema: {};
|
|
493
|
+
standaloneSchema: {};
|
|
494
|
+
response: {};
|
|
495
|
+
}, {
|
|
496
|
+
derive: {};
|
|
497
|
+
resolve: {};
|
|
498
|
+
schema: {};
|
|
499
|
+
standaloneSchema: {};
|
|
500
|
+
response: {};
|
|
501
|
+
} & {
|
|
502
|
+
derive: {
|
|
503
|
+
readonly auth: any;
|
|
504
|
+
};
|
|
505
|
+
resolve: {};
|
|
506
|
+
schema: {};
|
|
507
|
+
standaloneSchema: {};
|
|
508
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
509
|
+
readonly auth: any;
|
|
510
|
+
}>;
|
|
511
|
+
} & {
|
|
512
|
+
derive: {};
|
|
513
|
+
resolve: {};
|
|
514
|
+
schema: {};
|
|
515
|
+
standaloneSchema: {};
|
|
516
|
+
response: {};
|
|
517
|
+
}>;
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/presets/standard-preset.d.ts
|
|
520
|
+
type StandardPresetOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
|
|
521
|
+
/** 令牌验证器端口(用户注入) */tokenVerifier: TokenVerifierPort; /** 速率限制器端口(可选,用户注入) */
|
|
522
|
+
rateLimiter?: RateLimiterPort; /** 默认租户 ID */
|
|
523
|
+
defaultTenantId?: string; /** 租户验证函数 */
|
|
524
|
+
validateFn?: TenantValidateFn; /** 用户角色策略 */
|
|
525
|
+
userRole?: UserRoleStrategy; /** 日志服务 */
|
|
526
|
+
logger?: LoggerService; /** 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*") */
|
|
527
|
+
publicPaths?: string[]; /** 扩展 schema,用于从 payload 中解析自定义业务字段(仅在未使用 apiKeyValidator 时生效) */
|
|
528
|
+
extendSchema?: T; /** API Key 验证器(提供后使用组合认证插件替代 JWT 验证插件) */
|
|
529
|
+
apiKeyValidator?: (key: string) => Promise<ApiKeyPrincipal | null>;
|
|
530
|
+
};
|
|
531
|
+
declare function createStandardPreset<T extends z.ZodTypeAny = z.ZodUndefined>(options: StandardPresetOptions<T>): Elysia<"", {
|
|
532
|
+
decorator: {};
|
|
533
|
+
store: {};
|
|
534
|
+
derive: {
|
|
535
|
+
readonly requirePermission: (resource: string, action: string) => Promise<void>;
|
|
536
|
+
} & {
|
|
537
|
+
tenantId: string;
|
|
538
|
+
};
|
|
539
|
+
resolve: {};
|
|
540
|
+
}, {
|
|
541
|
+
typebox: {};
|
|
542
|
+
error: {};
|
|
543
|
+
}, {
|
|
544
|
+
schema: {};
|
|
545
|
+
standaloneSchema: {};
|
|
546
|
+
macro: {};
|
|
547
|
+
macroFn: {};
|
|
548
|
+
parser: {};
|
|
549
|
+
response: {};
|
|
550
|
+
} & {
|
|
551
|
+
schema: {};
|
|
552
|
+
standaloneSchema: {};
|
|
553
|
+
macro: {};
|
|
554
|
+
macroFn: {};
|
|
555
|
+
parser: {};
|
|
556
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
557
|
+
readonly requirePermission: (resource: string, action: string) => Promise<void>;
|
|
558
|
+
}>;
|
|
559
|
+
} & {
|
|
560
|
+
schema: {};
|
|
561
|
+
standaloneSchema: {};
|
|
562
|
+
macro: {};
|
|
563
|
+
macroFn: {};
|
|
564
|
+
parser: {};
|
|
565
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
566
|
+
tenantId: string;
|
|
567
|
+
}> & {};
|
|
568
|
+
} & {
|
|
569
|
+
schema: {};
|
|
570
|
+
standaloneSchema: {};
|
|
571
|
+
macro: {};
|
|
572
|
+
macroFn: {};
|
|
573
|
+
parser: {};
|
|
574
|
+
response: {
|
|
575
|
+
200: {
|
|
576
|
+
details?: Record<string, unknown> | undefined;
|
|
577
|
+
code: string;
|
|
578
|
+
message: string;
|
|
579
|
+
} | {
|
|
580
|
+
code: string;
|
|
581
|
+
message: string;
|
|
582
|
+
details: {
|
|
583
|
+
path: string;
|
|
584
|
+
message: string | undefined;
|
|
585
|
+
}[];
|
|
586
|
+
};
|
|
587
|
+
};
|
|
588
|
+
}, {}, {
|
|
589
|
+
derive: {};
|
|
590
|
+
resolve: {};
|
|
591
|
+
schema: {};
|
|
592
|
+
standaloneSchema: {};
|
|
593
|
+
response: {};
|
|
594
|
+
}, ({
|
|
595
|
+
derive: {};
|
|
596
|
+
resolve: {};
|
|
597
|
+
schema: {};
|
|
598
|
+
standaloneSchema: {};
|
|
599
|
+
response: {};
|
|
600
|
+
} & {
|
|
601
|
+
derive: {
|
|
602
|
+
auth: import("@longzai-intelligence-auth/core").UnifiedAuthContext;
|
|
603
|
+
};
|
|
604
|
+
resolve: {};
|
|
605
|
+
schema: {};
|
|
606
|
+
standaloneSchema: {};
|
|
607
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
608
|
+
auth: import("@longzai-intelligence-auth/core").UnifiedAuthContext;
|
|
609
|
+
}>;
|
|
610
|
+
} & {
|
|
611
|
+
derive: {};
|
|
612
|
+
resolve: {};
|
|
613
|
+
schema: {};
|
|
614
|
+
standaloneSchema: {};
|
|
615
|
+
response: {};
|
|
616
|
+
}) | ({
|
|
617
|
+
derive: {};
|
|
618
|
+
resolve: {};
|
|
619
|
+
schema: {};
|
|
620
|
+
standaloneSchema: {};
|
|
621
|
+
response: {};
|
|
622
|
+
} & {
|
|
623
|
+
derive: {
|
|
624
|
+
readonly auth: any;
|
|
625
|
+
};
|
|
626
|
+
resolve: {};
|
|
627
|
+
schema: {};
|
|
628
|
+
standaloneSchema: {};
|
|
629
|
+
response: import("elysia").ExtractErrorFromHandle<{
|
|
630
|
+
readonly auth: any;
|
|
631
|
+
}>;
|
|
632
|
+
} & {
|
|
633
|
+
derive: {};
|
|
634
|
+
resolve: {};
|
|
635
|
+
schema: {};
|
|
636
|
+
standaloneSchema: {};
|
|
637
|
+
response: {};
|
|
638
|
+
})>;
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/utils/extract-client-ip.d.ts
|
|
641
|
+
/** 从请求中提取客户端 IP 地址 */
|
|
642
|
+
declare function extractClientIp(request: Request): string | undefined;
|
|
643
|
+
//#endregion
|
|
644
|
+
//#region src/utils/extract-user-agent.d.ts
|
|
645
|
+
/** 从请求中提取用户代理 */
|
|
646
|
+
declare function extractUserAgent(request: Request): string | undefined;
|
|
647
|
+
//#endregion
|
|
648
|
+
export { type ApiKeyPluginOptions, type ApiKeyPrincipal, type AuthContextWithExtra, type BasicPresetOptions, type CompositeAuthContext, type CompositeAuthPluginOptions, type ErrorHandlerPluginOptions, type ExtractExtra, type InMemoryApiKeyEntry, type InMemoryApiKeyMap, type JwtVerifyPluginOptions, type LoggerPluginOptions, type OptionalAuthContext, type OptionalJwtPluginOptions, type RateLimitPluginOptions, type RbacPluginOptions, type StandardPresetOptions, type TenantPluginOptions, type UnifiedAuthContext, type UserRoleStrategy, type VerifiedAuthContext, createApiKeyPlugin, createBasicPreset, createCompositeAuthPlugin, createErrorHandlerPlugin, createInMemoryApiKeyValidator, createJwtVerifyPlugin, createLoggerPlugin, createOptionalJwtPlugin, createRateLimitPlugin, createRbacPlugin, createRequiredCompositeAuthPlugin, createStandardPreset, createTenantPlugin, extractClientIp, extractUserAgent, mapDomainErrorToStatus };
|