@longzai-intelligence-auth/elysia 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/index.d.ts +899 -25
  2. package/dist/index.js +1 -15
  3. package/package.json +13 -31
  4. package/dist/core/auth-strategy.d.ts +0 -14
  5. package/dist/core/auth-strategy.js +0 -98
  6. package/dist/core/error-mapper.d.ts +0 -2
  7. package/dist/core/error-mapper.js +0 -27
  8. package/dist/plugin.d.ts +0 -6
  9. package/dist/plugin.js +0 -39
  10. package/dist/plugins/audit.plugin.d.ts +0 -38
  11. package/dist/plugins/audit.plugin.js +0 -13
  12. package/dist/plugins/error-handler.plugin.d.ts +0 -46
  13. package/dist/plugins/error-handler.plugin.js +0 -45
  14. package/dist/plugins/jwt-verify.plugin.d.ts +0 -9
  15. package/dist/plugins/jwt-verify.plugin.js +0 -31
  16. package/dist/plugins/logger.plugin.d.ts +0 -33
  17. package/dist/plugins/logger.plugin.js +0 -16
  18. package/dist/plugins/rate-limit.plugin.d.ts +0 -40
  19. package/dist/plugins/rate-limit.plugin.js +0 -39
  20. package/dist/plugins/rbac.plugin.d.ts +0 -36
  21. package/dist/plugins/rbac.plugin.js +0 -42
  22. package/dist/plugins/tenant.plugin.d.ts +0 -38
  23. package/dist/plugins/tenant.plugin.js +0 -19
  24. package/dist/presets/basic-preset.d.ts +0 -11
  25. package/dist/presets/basic-preset.js +0 -11
  26. package/dist/presets/standard-preset.d.ts +0 -13
  27. package/dist/presets/standard-preset.js +0 -26
  28. package/dist/routes/auth.routes.d.ts +0 -17
  29. package/dist/routes/auth.routes.js +0 -145
  30. package/dist/types/auth-plugin-config.d.ts +0 -40
  31. package/dist/types/auth-plugin-config.js +0 -1
  32. package/dist/utils/extract-client-ip.d.ts +0 -1
  33. package/dist/utils/extract-client-ip.js +0 -5
  34. package/dist/utils/extract-user-agent.d.ts +0 -1
  35. package/dist/utils/extract-user-agent.js +0 -3
package/dist/index.d.ts CHANGED
@@ -1,25 +1,899 @@
1
- export { createAuthPlugin } from "./plugin";
2
- export type { AuthPluginConfig, AuthPluginOptions, JwtStrategyConfig, StandaloneStrategyConfig, EnvBasicStrategyConfig, StrategyName, StrategyContext, } from "./types/auth-plugin-config";
3
- export { createAuthStrategy, extractJwtConfig, extractDefaultTenantId, extractRegisterRoutes } from "./core/auth-strategy";
4
- export type { AuthStrategy } from "./core/auth-strategy";
5
- export { mapDomainErrorToStatus } from "./core/error-mapper";
6
- export { createJwtVerifyPlugin } from "./plugins/jwt-verify.plugin";
7
- export type { JwtVerifyPluginOptions } from "./plugins/jwt-verify.plugin";
8
- export { createRbacPlugin } from "./plugins/rbac.plugin";
9
- export type { RbacPluginOptions } from "./plugins/rbac.plugin";
10
- export { createTenantPlugin } from "./plugins/tenant.plugin";
11
- export type { TenantPluginOptions } from "./plugins/tenant.plugin";
12
- export { createRateLimitPlugin } from "./plugins/rate-limit.plugin";
13
- export type { RateLimitPluginOptions } from "./plugins/rate-limit.plugin";
14
- export { createAuditPlugin } from "./plugins/audit.plugin";
15
- export type { AuditPluginOptions } from "./plugins/audit.plugin";
16
- export { createErrorHandlerPlugin } from "./plugins/error-handler.plugin";
17
- export type { ErrorHandlerPluginOptions } from "./plugins/error-handler.plugin";
18
- export { createLoggerPlugin } from "./plugins/logger.plugin";
19
- export type { LoggerPluginOptions } from "./plugins/logger.plugin";
20
- export { createBasicPreset } from "./presets/basic-preset";
21
- export type { BasicPresetOptions } from "./presets/basic-preset";
22
- export { createStandardPreset } from "./presets/standard-preset";
23
- export type { StandardPresetOptions } from "./presets/standard-preset";
24
- export { extractClientIp } from "./utils/extract-client-ip";
25
- export { extractUserAgent } from "./utils/extract-user-agent";
1
+ import { DomainError } from "@longzai-intelligence/error";
2
+ import { JwtConfig, LoggerService, RateLimiterPort, ResourceAction, 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
+ /**
8
+ * 根据 DomainError 类型映射 HTTP 状态码
9
+ *
10
+ * @param error - 领域错误实例
11
+ * @returns 对应的 HTTP 状态码
12
+ */
13
+ declare function mapDomainErrorToStatus(error: DomainError): number;
14
+ //#endregion
15
+ //#region src/verifiers/static-token-verifier.d.ts
16
+ /**
17
+ * 静态令牌验证器配置
18
+ */
19
+ type StaticTokenVerifierOptions = {
20
+ /**
21
+ * 静态令牌(与 getToken 至少提供一个)
22
+ */
23
+ token?: string;
24
+ /**
25
+ * 动态获取令牌的回调,优先级高于 token
26
+ * 用于运行时从 secret manager / env 缓存等来源解析令牌
27
+ */
28
+ getToken?: () => string | null;
29
+ /**
30
+ * 验证通过后填充到 AccessTokenPayload.sub 中的主体标识
31
+ * 默认 "static"
32
+ */
33
+ subject?: string;
34
+ /**
35
+ * 验证通过后填充到 AccessTokenPayload.tenantId 中的租户标识
36
+ * 默认不设置
37
+ */
38
+ tenantId?: string;
39
+ };
40
+ /**
41
+ * 创建静态令牌验证器
42
+ *
43
+ * @param options - 静态令牌验证器配置
44
+ * @returns 实现 TokenVerifierPort 的静态令牌验证器
45
+ */
46
+ declare function createStaticTokenVerifier(options: StaticTokenVerifierOptions): TokenVerifierPort;
47
+ //#endregion
48
+ //#region src/plugins/jwt-verify.plugin.d.ts
49
+ /** JWT 验证插件解析后的认证上下文 */
50
+ type VerifiedAuthContext = {
51
+ /**
52
+ * 用户 ID(来自 payload.sub)
53
+ */
54
+ userId: string;
55
+ /**
56
+ * 租户 ID(来自 payload.tenantId,默认使用 defaultTenantId)
57
+ */
58
+ tenantId: string;
59
+ /**
60
+ * 角色列表
61
+ */
62
+ roles: string[];
63
+ /**
64
+ * 权限列表
65
+ */
66
+ permissions: string[];
67
+ /**
68
+ * JWT ID(用于 token 黑名单检查)
69
+ */
70
+ jti?: string;
71
+ };
72
+ /**
73
+ * JWT 验证插件配置选项
74
+ *
75
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
76
+ */
77
+ type JwtVerifyPluginOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
78
+ /**
79
+ * 令牌验证器端口(用户注入,与 jwt 二选一)
80
+ */
81
+ verifier?: TokenVerifierPort;
82
+ /**
83
+ * JWT 配置(与 verifier 二选一,未提供时使用默认配置)
84
+ */
85
+ jwt?: JwtConfig;
86
+ /**
87
+ * 默认租户 ID
88
+ */
89
+ defaultTenantId?: string;
90
+ /**
91
+ * 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*")
92
+ */
93
+ publicPaths?: string[];
94
+ /**
95
+ * 扩展 schema,用于从 payload 中解析自定义业务字段
96
+ */
97
+ extendSchema?: T;
98
+ };
99
+ /**
100
+ * 从 extendSchema 提取额外字段类型
101
+ *
102
+ * @typeParam T - 扩展 schema 类型,用于推断额外的业务字段类型
103
+ */
104
+ type ExtractExtra<T extends z.ZodTypeAny> = T extends z.ZodUndefined ? Record<string, never> : z.infer<T>;
105
+ /**
106
+ * 完整的认证上下文类型(基础字段 + 扩展字段)
107
+ *
108
+ * @typeParam T - 扩展 schema 类型,用于推断额外的业务字段类型
109
+ */
110
+ type AuthContextWithExtra<T extends z.ZodTypeAny = z.ZodUndefined> = VerifiedAuthContext & ExtractExtra<T>;
111
+ /**
112
+ * 创建 JWT 验证插件
113
+ *
114
+ * 该插件从请求头中提取 Bearer token 并验证,验证失败时抛出异常。
115
+ *
116
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
117
+ * @param options - 插件配置选项
118
+ * @returns Elysia 插件实例
119
+ */
120
+ declare function createJwtVerifyPlugin<T extends z.ZodTypeAny = z.ZodUndefined>(options: JwtVerifyPluginOptions<T>): Elysia<"", {
121
+ decorator: {};
122
+ store: {};
123
+ derive: {};
124
+ resolve: {};
125
+ }, {
126
+ typebox: {};
127
+ error: {};
128
+ }, {
129
+ schema: {};
130
+ standaloneSchema: {};
131
+ macro: {};
132
+ macroFn: {};
133
+ parser: {};
134
+ response: {};
135
+ }, {}, {
136
+ derive: {
137
+ readonly auth: any;
138
+ };
139
+ resolve: {};
140
+ schema: {};
141
+ standaloneSchema: {};
142
+ response: import("elysia").ExtractErrorFromHandle<{
143
+ readonly auth: any;
144
+ }>;
145
+ }, {
146
+ derive: {};
147
+ resolve: {};
148
+ schema: {};
149
+ standaloneSchema: {};
150
+ response: {};
151
+ }>;
152
+ //#endregion
153
+ //#region src/plugins/optional-jwt.plugin.d.ts
154
+ /**
155
+ * 可选 JWT 认证插件配置选项
156
+ *
157
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
158
+ */
159
+ type OptionalJwtPluginOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
160
+ /**
161
+ * 令牌验证器端口(用户注入,与 jwt 二选一)
162
+ */
163
+ verifier?: TokenVerifierPort;
164
+ /**
165
+ * JWT 配置(与 verifier 二选一,未提供时使用默认配置)
166
+ */
167
+ jwt?: JwtConfig;
168
+ /**
169
+ * 默认租户 ID
170
+ */
171
+ defaultTenantId?: string;
172
+ /**
173
+ * 扩展 schema,用于从 payload 中解析自定义业务字段
174
+ */
175
+ extendSchema?: T;
176
+ };
177
+ /**
178
+ * 可选认证上下文,auth 为 null 表示未认证
179
+ *
180
+ * @typeParam T - 扩展 schema 类型,用于推断额外的业务字段类型
181
+ */
182
+ type OptionalAuthContext<T extends z.ZodTypeAny = z.ZodUndefined> = {
183
+ auth: (UnifiedAuthContext$1 & (T extends z.ZodUndefined ? Record<string, never> : z.infer<T>)) | null;
184
+ };
185
+ /**
186
+ * 创建可选 JWT 认证插件
187
+ *
188
+ * 该插件从请求头中提取 Bearer token 并验证,如果验证失败或无 token 则返回 null 认证上下文。
189
+ *
190
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
191
+ * @param options - 插件配置选项
192
+ * @returns Elysia 插件实例
193
+ */
194
+ declare function createOptionalJwtPlugin<T extends z.ZodTypeAny = z.ZodUndefined>(options: OptionalJwtPluginOptions<T>): Elysia<"", {
195
+ decorator: {};
196
+ store: {};
197
+ derive: {};
198
+ resolve: {};
199
+ }, {
200
+ typebox: {};
201
+ error: {};
202
+ }, {
203
+ schema: {};
204
+ standaloneSchema: {};
205
+ macro: {};
206
+ macroFn: {};
207
+ parser: {};
208
+ response: {};
209
+ }, {}, {
210
+ derive: {
211
+ readonly auth: any;
212
+ };
213
+ resolve: {};
214
+ schema: {};
215
+ standaloneSchema: {};
216
+ response: import("elysia").ExtractErrorFromHandle<{
217
+ readonly auth: any;
218
+ }>;
219
+ }, {
220
+ derive: {};
221
+ resolve: {};
222
+ schema: {};
223
+ standaloneSchema: {};
224
+ response: {};
225
+ }>;
226
+ //#endregion
227
+ //#region src/plugins/rbac.plugin.d.ts
228
+ /** 用户角色策略接口,用于数据库查询权限 */
229
+ type UserRoleStrategy = {
230
+ /**
231
+ * 查询用户在指定租户下的所有权限
232
+ */
233
+ findPermissionsByUserId(userId: string, tenantId: string): Promise<ResourceAction[]>;
234
+ };
235
+ /**
236
+ * RBAC 插件配置选项
237
+ */
238
+ type RbacPluginOptions = {
239
+ /**
240
+ * 用户角色策略(用于数据库查询权限,优先于上下文权限)
241
+ */
242
+ userRole?: UserRoleStrategy;
243
+ };
244
+ /**
245
+ * 创建 RBAC 插件
246
+ *
247
+ * @param options - 插件配置选项
248
+ * @returns Elysia 插件实例
249
+ */
250
+ declare function createRbacPlugin(options?: RbacPluginOptions): Elysia<"", {
251
+ decorator: {};
252
+ store: {};
253
+ derive: {
254
+ readonly requirePermission: (resource: string, action: string) => Promise<void>;
255
+ };
256
+ resolve: {};
257
+ }, {
258
+ typebox: {};
259
+ error: {};
260
+ }, {
261
+ schema: {};
262
+ standaloneSchema: {};
263
+ macro: {};
264
+ macroFn: {};
265
+ parser: {};
266
+ response: import("elysia").ExtractErrorFromHandle<{
267
+ readonly requirePermission: (resource: string, action: string) => Promise<void>;
268
+ }>;
269
+ }, {}, {
270
+ derive: {};
271
+ resolve: {};
272
+ schema: {};
273
+ standaloneSchema: {};
274
+ response: {};
275
+ }, {
276
+ derive: {};
277
+ resolve: {};
278
+ schema: {};
279
+ standaloneSchema: {};
280
+ response: {};
281
+ }>;
282
+ //#endregion
283
+ //#region src/plugins/api-key.plugin.d.ts
284
+ /** API Key 认证的主体信息 */
285
+ type ApiKeyPrincipal = {
286
+ /**
287
+ * 主体标识
288
+ */
289
+ principalId: string;
290
+ /**
291
+ * 租户 ID
292
+ */
293
+ tenantId?: string;
294
+ /**
295
+ * 角色列表
296
+ */
297
+ roles: string[];
298
+ /**
299
+ * 权限列表
300
+ */
301
+ permissions: string[];
302
+ };
303
+ /**
304
+ * API Key 认证插件配置选项
305
+ */
306
+ type ApiKeyPluginOptions = {
307
+ /**
308
+ * API Key 所在的请求头名称(默认 "x-api-key")
309
+ */
310
+ header?: string;
311
+ /**
312
+ * API Key 验证器,返回 null 表示无效
313
+ */
314
+ validator: (key: string) => Promise<ApiKeyPrincipal | null>;
315
+ };
316
+ /**
317
+ * 创建 API Key 认证插件
318
+ *
319
+ * @param options - 插件配置选项
320
+ * @returns Elysia 插件实例
321
+ */
322
+ declare function createApiKeyPlugin(options: ApiKeyPluginOptions): Elysia<"", {
323
+ decorator: {};
324
+ store: {};
325
+ derive: {};
326
+ resolve: {};
327
+ }, {
328
+ typebox: {};
329
+ error: {};
330
+ }, {
331
+ schema: {};
332
+ standaloneSchema: {};
333
+ macro: {};
334
+ macroFn: {};
335
+ parser: {};
336
+ response: {};
337
+ }, {}, {
338
+ derive: {
339
+ auth: UnifiedAuthContext$1;
340
+ };
341
+ resolve: {};
342
+ schema: {};
343
+ standaloneSchema: {};
344
+ response: import("elysia").ExtractErrorFromHandle<{
345
+ auth: UnifiedAuthContext$1;
346
+ }>;
347
+ }, {
348
+ derive: {};
349
+ resolve: {};
350
+ schema: {};
351
+ standaloneSchema: {};
352
+ response: {};
353
+ }>;
354
+ //#endregion
355
+ //#region src/plugins/in-memory-api-key-validator.d.ts
356
+ /** 内存 API Key 映射条目 */
357
+ type InMemoryApiKeyEntry = {
358
+ /**
359
+ * 主体标识
360
+ */
361
+ principalId: string;
362
+ /**
363
+ * 租户ID(可选)
364
+ */
365
+ tenantId?: string;
366
+ /**
367
+ * 角色列表
368
+ */
369
+ roles: string[];
370
+ /**
371
+ * 权限列表
372
+ */
373
+ permissions: string[];
374
+ };
375
+ /** 内存 API Key 映射表 */
376
+ type InMemoryApiKeyMap = Record<string, InMemoryApiKeyEntry>;
377
+ /**
378
+ * 创建内存 API Key 验证器
379
+ * 接受静态 API Key 映射,返回符合 createApiKeyPlugin 的 validator 函数
380
+ *
381
+ * @param keyMap - API Key 到主体信息的映射
382
+ * @returns validator 函数
383
+ */
384
+ declare function createInMemoryApiKeyValidator(keyMap: InMemoryApiKeyMap): (key: string) => Promise<ApiKeyPrincipal | null>;
385
+ //#endregion
386
+ //#region src/plugins/composite-auth.plugin.d.ts
387
+ /**
388
+ * 组合认证插件配置选项
389
+ *
390
+ * 支持多种认证方式(JWT 和 API Key),优先尝试 JWT 认证。
391
+ */
392
+ type CompositeAuthPluginOptions = {
393
+ /**
394
+ * 令牌验证器端口(用户注入,与 jwt 二选一)
395
+ */
396
+ verifier?: TokenVerifierPort;
397
+ /**
398
+ * JWT 配置(与 verifier 二选一,未提供时使用默认配置)
399
+ */
400
+ jwt?: JwtConfig;
401
+ /**
402
+ * 默认租户 ID
403
+ */
404
+ defaultTenantId?: string;
405
+ /**
406
+ * API Key 验证器
407
+ */
408
+ apiKeyValidator?: (key: string) => Promise<ApiKeyPrincipal | null>;
409
+ /**
410
+ * API Key 所在的请求头名称(默认 "x-api-key")
411
+ */
412
+ apiKeyHeader?: string;
413
+ /**
414
+ * 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*")
415
+ */
416
+ publicPaths?: string[];
417
+ };
418
+ /** 组合认证上下文(向后兼容,内部使用 UnifiedAuthContext) */
419
+ type CompositeAuthContext = UnifiedAuthContext$1;
420
+ /**
421
+ * 创建组合认证插件
422
+ *
423
+ * 该插件支持多种认证方式(JWT 和 API Key),优先尝试 JWT 认证,
424
+ * 如果 JWT 认证失败则尝试 API Key 认证,未认证时返回 null。
425
+ *
426
+ * @param options - 插件配置选项
427
+ * @returns Elysia 插件实例
428
+ */
429
+ declare function createCompositeAuthPlugin(options: CompositeAuthPluginOptions): Elysia<"", {
430
+ decorator: {};
431
+ store: {};
432
+ derive: {};
433
+ resolve: {};
434
+ }, {
435
+ typebox: {};
436
+ error: {};
437
+ }, {
438
+ schema: {};
439
+ standaloneSchema: {};
440
+ macro: {};
441
+ macroFn: {};
442
+ parser: {};
443
+ response: {};
444
+ }, {}, {
445
+ derive: {
446
+ auth: UnifiedAuthContext$1 | null;
447
+ };
448
+ resolve: {};
449
+ schema: {};
450
+ standaloneSchema: {};
451
+ response: import("elysia").ExtractErrorFromHandle<{
452
+ auth: UnifiedAuthContext$1 | null;
453
+ }>;
454
+ }, {
455
+ derive: {};
456
+ resolve: {};
457
+ schema: {};
458
+ standaloneSchema: {};
459
+ response: {};
460
+ }>;
461
+ /**
462
+ * 创建要求认证的组合认证插件(未认证时抛出异常)
463
+ *
464
+ * @param options - 插件配置选项
465
+ * @returns Elysia 插件实例
466
+ */
467
+ declare function createRequiredCompositeAuthPlugin(options: CompositeAuthPluginOptions): Elysia<"", {
468
+ decorator: {};
469
+ store: {};
470
+ derive: {};
471
+ resolve: {};
472
+ }, {
473
+ typebox: {};
474
+ error: {};
475
+ }, {
476
+ schema: {};
477
+ standaloneSchema: {};
478
+ macro: {};
479
+ macroFn: {};
480
+ parser: {};
481
+ response: {};
482
+ }, {}, {
483
+ derive: {
484
+ auth: UnifiedAuthContext$1;
485
+ };
486
+ resolve: {};
487
+ schema: {};
488
+ standaloneSchema: {};
489
+ response: import("elysia").ExtractErrorFromHandle<{
490
+ auth: UnifiedAuthContext$1;
491
+ }>;
492
+ }, {
493
+ derive: {};
494
+ resolve: {};
495
+ schema: {};
496
+ standaloneSchema: {};
497
+ response: {};
498
+ }>;
499
+ //#endregion
500
+ //#region src/plugins/rate-limit.plugin.d.ts
501
+ /**
502
+ * 速率限制插件配置选项
503
+ */
504
+ type RateLimitPluginOptions = {
505
+ /**
506
+ * 速率限制器端口(用户注入)
507
+ */
508
+ limiter: RateLimiterPort;
509
+ /**
510
+ * 日志服务
511
+ */
512
+ logger?: LoggerService;
513
+ /**
514
+ * 键生成器(用于从请求中提取限制键)
515
+ */
516
+ keyGenerator?: (request: Request) => string;
517
+ };
518
+ /**
519
+ * 创建速率限制插件
520
+ *
521
+ * @param options - 插件配置选项
522
+ * @returns Elysia 插件实例
523
+ */
524
+ declare function createRateLimitPlugin(options: RateLimitPluginOptions): Elysia<"", {
525
+ decorator: {};
526
+ store: {};
527
+ derive: {
528
+ readonly clientIp: string;
529
+ } & {
530
+ readonly rateLimitRemaining: number;
531
+ };
532
+ resolve: {};
533
+ }, {
534
+ typebox: {};
535
+ error: {};
536
+ }, {
537
+ schema: {};
538
+ standaloneSchema: {};
539
+ macro: {};
540
+ macroFn: {};
541
+ parser: {};
542
+ response: import("elysia").ExtractErrorFromHandle<{
543
+ readonly rateLimitRemaining: number;
544
+ }>;
545
+ }, {}, {
546
+ derive: {};
547
+ resolve: {};
548
+ schema: {};
549
+ standaloneSchema: {};
550
+ response: {};
551
+ }, {
552
+ derive: {};
553
+ resolve: {};
554
+ schema: {};
555
+ standaloneSchema: {};
556
+ response: {};
557
+ }>;
558
+ //#endregion
559
+ //#region src/plugins/error-handler.plugin.d.ts
560
+ type ErrorHandlerPluginOptions = {
561
+ logger?: LoggerService;
562
+ };
563
+ declare function createErrorHandlerPlugin(options?: ErrorHandlerPluginOptions): Elysia<"", {
564
+ decorator: {};
565
+ store: {};
566
+ derive: {};
567
+ resolve: {};
568
+ }, {
569
+ typebox: {};
570
+ error: {};
571
+ }, {
572
+ schema: {};
573
+ standaloneSchema: {};
574
+ macro: {};
575
+ macroFn: {};
576
+ parser: {};
577
+ response: {
578
+ 200: {
579
+ details?: Record<string, unknown> | undefined;
580
+ code: string;
581
+ message: string;
582
+ } | {
583
+ code: string;
584
+ message: string;
585
+ details: {
586
+ path: string;
587
+ message: string | undefined;
588
+ }[];
589
+ };
590
+ };
591
+ }, {}, {
592
+ derive: {};
593
+ resolve: {};
594
+ schema: {};
595
+ standaloneSchema: {};
596
+ response: {};
597
+ }, {
598
+ derive: {};
599
+ resolve: {};
600
+ schema: {};
601
+ standaloneSchema: {};
602
+ response: {};
603
+ }>;
604
+ //#endregion
605
+ //#region src/plugins/logger.plugin.d.ts
606
+ type LoggerPluginOptions = {
607
+ logger: LoggerService;
608
+ };
609
+ declare function createLoggerPlugin(options: LoggerPluginOptions): Elysia<"", {
610
+ decorator: {};
611
+ store: {};
612
+ derive: {};
613
+ resolve: {};
614
+ }, {
615
+ typebox: {};
616
+ error: {};
617
+ }, {
618
+ schema: {};
619
+ standaloneSchema: {};
620
+ macro: {};
621
+ macroFn: {};
622
+ parser: {};
623
+ response: {};
624
+ }, {}, {
625
+ derive: {};
626
+ resolve: {};
627
+ schema: {};
628
+ standaloneSchema: {};
629
+ response: {};
630
+ }, {
631
+ derive: {};
632
+ resolve: {};
633
+ schema: {};
634
+ standaloneSchema: {};
635
+ response: {};
636
+ }>;
637
+ //#endregion
638
+ //#region src/presets/basic-preset.d.ts
639
+ /**
640
+ * 基础预设配置选项
641
+ *
642
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
643
+ */
644
+ type BasicPresetOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
645
+ /**
646
+ * 令牌验证器端口(用户注入)
647
+ */
648
+ tokenVerifier: TokenVerifierPort;
649
+ /**
650
+ * 默认租户 ID
651
+ */
652
+ defaultTenantId?: string;
653
+ /**
654
+ * 日志服务
655
+ */
656
+ logger?: LoggerService;
657
+ /**
658
+ * 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*")
659
+ */
660
+ publicPaths?: string[];
661
+ /**
662
+ * 扩展 schema,用于从 payload 中解析自定义业务字段
663
+ */
664
+ extendSchema?: T;
665
+ };
666
+ /**
667
+ * 创建基础预设插件
668
+ *
669
+ * 该预设包含 JWT 验证插件和错误处理插件,提供完整的认证功能。
670
+ *
671
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
672
+ * @param options - 预设配置选项
673
+ * @returns Elysia 插件实例
674
+ */
675
+ declare function createBasicPreset<T extends z.ZodTypeAny = z.ZodUndefined>(options: BasicPresetOptions<T>): Elysia<"", {
676
+ decorator: {};
677
+ store: {};
678
+ derive: {};
679
+ resolve: {};
680
+ }, {
681
+ typebox: {};
682
+ error: {};
683
+ }, {
684
+ schema: {};
685
+ standaloneSchema: {};
686
+ macro: {};
687
+ macroFn: {};
688
+ parser: {};
689
+ response: {};
690
+ } & {
691
+ schema: {};
692
+ standaloneSchema: {};
693
+ macro: {};
694
+ macroFn: {};
695
+ parser: {};
696
+ response: {
697
+ 200: {
698
+ details?: Record<string, unknown> | undefined;
699
+ code: string;
700
+ message: string;
701
+ } | {
702
+ code: string;
703
+ message: string;
704
+ details: {
705
+ path: string;
706
+ message: string | undefined;
707
+ }[];
708
+ };
709
+ };
710
+ }, {}, {
711
+ derive: {};
712
+ resolve: {};
713
+ schema: {};
714
+ standaloneSchema: {};
715
+ response: {};
716
+ }, {
717
+ derive: {};
718
+ resolve: {};
719
+ schema: {};
720
+ standaloneSchema: {};
721
+ response: {};
722
+ } & {
723
+ derive: {
724
+ readonly auth: any;
725
+ };
726
+ resolve: {};
727
+ schema: {};
728
+ standaloneSchema: {};
729
+ response: import("elysia").ExtractErrorFromHandle<{
730
+ readonly auth: any;
731
+ }>;
732
+ } & {
733
+ derive: {};
734
+ resolve: {};
735
+ schema: {};
736
+ standaloneSchema: {};
737
+ response: {};
738
+ }>;
739
+ //#endregion
740
+ //#region src/presets/standard-preset.d.ts
741
+ /**
742
+ * 标准预设配置选项
743
+ *
744
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
745
+ */
746
+ type StandardPresetOptions<T extends z.ZodTypeAny = z.ZodUndefined> = {
747
+ /**
748
+ * 令牌验证器端口(用户注入)
749
+ */
750
+ tokenVerifier: TokenVerifierPort;
751
+ /**
752
+ * 速率限制器端口(可选,用户注入)
753
+ */
754
+ rateLimiter?: RateLimiterPort;
755
+ /**
756
+ * 默认租户 ID
757
+ */
758
+ defaultTenantId?: string;
759
+ /**
760
+ * 用户角色策略
761
+ */
762
+ userRole?: UserRoleStrategy;
763
+ /**
764
+ * 日志服务
765
+ */
766
+ logger?: LoggerService;
767
+ /**
768
+ * 跳过认证的路径列表(精确匹配或前缀匹配,如 "/api/public/*")
769
+ */
770
+ publicPaths?: string[];
771
+ /**
772
+ * 扩展 schema,用于从 payload 中解析自定义业务字段(仅在未使用 apiKeyValidator 时生效)
773
+ */
774
+ extendSchema?: T;
775
+ /**
776
+ * API Key 验证器(提供后使用组合认证插件替代 JWT 验证插件)
777
+ */
778
+ apiKeyValidator?: (key: string) => Promise<ApiKeyPrincipal | null>;
779
+ };
780
+ /**
781
+ * 创建标准预设插件
782
+ *
783
+ * 该预设包含认证插件、RBAC 插件、可选的限流插件和错误处理插件。
784
+ *
785
+ * @typeParam T - 扩展 schema 类型,用于从 payload 中解析自定义业务字段
786
+ * @param options - 预设配置选项
787
+ * @returns Elysia 插件实例
788
+ */
789
+ declare function createStandardPreset<T extends z.ZodTypeAny = z.ZodUndefined>(options: StandardPresetOptions<T>): Elysia<"", {
790
+ decorator: {};
791
+ store: {};
792
+ derive: {
793
+ readonly requirePermission: (resource: string, action: string) => Promise<void>;
794
+ };
795
+ resolve: {};
796
+ }, {
797
+ typebox: {};
798
+ error: {};
799
+ }, {
800
+ schema: {};
801
+ standaloneSchema: {};
802
+ macro: {};
803
+ macroFn: {};
804
+ parser: {};
805
+ response: {};
806
+ } & {
807
+ schema: {};
808
+ standaloneSchema: {};
809
+ macro: {};
810
+ macroFn: {};
811
+ parser: {};
812
+ response: import("elysia").ExtractErrorFromHandle<{
813
+ readonly requirePermission: (resource: string, action: string) => Promise<void>;
814
+ }>;
815
+ } & {
816
+ schema: {};
817
+ standaloneSchema: {};
818
+ macro: {};
819
+ macroFn: {};
820
+ parser: {};
821
+ response: {
822
+ 200: {
823
+ details?: Record<string, unknown> | undefined;
824
+ code: string;
825
+ message: string;
826
+ } | {
827
+ code: string;
828
+ message: string;
829
+ details: {
830
+ path: string;
831
+ message: string | undefined;
832
+ }[];
833
+ };
834
+ };
835
+ }, {}, {
836
+ derive: {};
837
+ resolve: {};
838
+ schema: {};
839
+ standaloneSchema: {};
840
+ response: {};
841
+ }, (({
842
+ derive: {};
843
+ resolve: {};
844
+ schema: {};
845
+ standaloneSchema: {};
846
+ response: {};
847
+ } & ({
848
+ derive: {
849
+ auth: import("@longzai-intelligence-auth/core").UnifiedAuthContext;
850
+ };
851
+ resolve: {};
852
+ schema: {};
853
+ standaloneSchema: {};
854
+ response: import("elysia").ExtractErrorFromHandle<{
855
+ auth: import("@longzai-intelligence-auth/core").UnifiedAuthContext;
856
+ }>;
857
+ } | {
858
+ derive: {
859
+ readonly auth: any;
860
+ };
861
+ resolve: {};
862
+ schema: {};
863
+ standaloneSchema: {};
864
+ response: import("elysia").ExtractErrorFromHandle<{
865
+ readonly auth: any;
866
+ }>;
867
+ })) & {
868
+ derive: {};
869
+ resolve: {};
870
+ schema: {};
871
+ standaloneSchema: {};
872
+ response: {};
873
+ }) & {
874
+ derive: {};
875
+ resolve: {};
876
+ schema: {};
877
+ standaloneSchema: {};
878
+ response: {};
879
+ }>;
880
+ //#endregion
881
+ //#region src/utils/extract-client-ip.d.ts
882
+ /**
883
+ * 从请求中提取客户端 IP 地址
884
+ *
885
+ * @param request - HTTP 请求对象
886
+ * @returns 客户端 IP 地址,如果无法提取则返回 undefined
887
+ */
888
+ declare function extractClientIp(request: Request): string | undefined;
889
+ //#endregion
890
+ //#region src/utils/extract-user-agent.d.ts
891
+ /**
892
+ * 从请求中提取用户代理
893
+ *
894
+ * @param request - HTTP 请求对象
895
+ * @returns 用户代理字符串,如果无法提取则返回 undefined
896
+ */
897
+ declare function extractUserAgent(request: Request): string | undefined;
898
+ //#endregion
899
+ 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 StaticTokenVerifierOptions, type UnifiedAuthContext, type UserRoleStrategy, type VerifiedAuthContext, createApiKeyPlugin, createBasicPreset, createCompositeAuthPlugin, createErrorHandlerPlugin, createInMemoryApiKeyValidator, createJwtVerifyPlugin, createLoggerPlugin, createOptionalJwtPlugin, createRateLimitPlugin, createRbacPlugin, createRequiredCompositeAuthPlugin, createStandardPreset, createStaticTokenVerifier, extractClientIp, extractUserAgent, mapDomainErrorToStatus };