@djvlc/openapi-client-core 1.2.0 → 1.2.1

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.mts CHANGED
@@ -1,274 +1,2718 @@
1
- import { ErrorCode, ApiErrorResponse, RequestContext, ApiSuccessResponse } from '@djvlc/contracts-types';
2
1
  import { AxiosInstance } from 'axios';
3
- export { AxiosError, AxiosInstance, InternalAxiosRequestConfig } from 'axios';
2
+ export { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
4
3
 
5
4
  /**
6
- * 错误类型定义
5
+ * 认证配置类型定义
6
+ *
7
+ * @packageDocumentation
7
8
  */
8
-
9
9
  /**
10
- * API 错误
10
+ * 认证类型
11
11
  */
12
- declare class ApiError extends Error {
13
- /** 错误码 */
14
- readonly code: ErrorCode | string;
15
- /** HTTP 状态码 */
16
- readonly statusCode: number;
17
- /** 错误详情 */
18
- readonly details?: {
19
- field?: string;
20
- message: string;
21
- code?: string;
22
- }[];
23
- /** 请求 ID */
24
- readonly requestId: string;
25
- /** 链路追踪 ID */
26
- readonly traceId?: string;
27
- /** 是否可重试 */
28
- readonly retryable: boolean;
29
- constructor(response: ApiErrorResponse, statusCode: number);
30
- private isRetryable;
12
+ type AuthType = 'bearer' | 'api-key' | 'basic' | 'custom' | 'none';
13
+ /**
14
+ * Bearer Token 认证配置
15
+ */
16
+ interface BearerAuthConfig {
17
+ readonly type: 'bearer';
18
+ /**
19
+ * 获取 Token 的函数
20
+ * 可以是同步或异步函数
21
+ */
22
+ readonly getToken: () => string | null | Promise<string | null>;
23
+ /**
24
+ * Token 头部名称
25
+ * @default 'Authorization'
26
+ */
27
+ readonly headerName?: string;
28
+ /**
29
+ * Token 前缀
30
+ * @default 'Bearer'
31
+ */
32
+ readonly prefix?: string;
31
33
  }
32
34
  /**
33
- * 网络错误
35
+ * API Key 认证配置
34
36
  */
35
- declare class NetworkError extends Error {
36
- readonly cause?: Error | undefined;
37
- readonly retryable = true;
38
- constructor(message: string, cause?: Error | undefined);
37
+ interface ApiKeyAuthConfig {
38
+ readonly type: 'api-key';
39
+ /**
40
+ * API Key
41
+ */
42
+ readonly apiKey: string;
43
+ /**
44
+ * API Key 头部名称
45
+ * @default 'X-API-Key'
46
+ */
47
+ readonly headerName?: string;
39
48
  }
40
49
  /**
41
- * 超时错误
50
+ * Basic Auth 认证配置
42
51
  */
43
- declare class TimeoutError extends Error {
44
- readonly retryable = true;
45
- constructor(timeout: number);
52
+ interface BasicAuthConfig {
53
+ readonly type: 'basic';
54
+ /**
55
+ * 用户名
56
+ */
57
+ readonly username: string;
58
+ /**
59
+ * 密码
60
+ */
61
+ readonly password: string;
46
62
  }
47
-
48
63
  /**
49
- * 客户端配置和类型定义
64
+ * 自定义认证配置
50
65
  */
51
-
66
+ interface CustomAuthConfig {
67
+ readonly type: 'custom';
68
+ /**
69
+ * 自定义认证函数
70
+ * 接收请求头对象,修改后返回
71
+ */
72
+ readonly authenticate: (headers: Record<string, string>) => void | Promise<void>;
73
+ }
52
74
  /**
53
- * 客户端配置
75
+ * 无认证配置
54
76
  */
55
- interface ClientConfig {
56
- /** 基础 URL */
57
- baseUrl: string;
58
- /** 默认超时时间(毫秒) */
59
- timeout?: number;
60
- /** 默认请求头 */
61
- headers?: Record<string, string>;
62
- /** 认证配置 */
63
- auth?: AuthConfig;
64
- /** 重试配置 */
65
- retry?: RetryConfig;
66
- /** 请求拦截器 */
67
- onRequest?: RequestInterceptor[];
68
- /** 响应拦截器 */
69
- onResponse?: ResponseInterceptor[];
70
- /** 错误拦截器 */
71
- onError?: ErrorInterceptor[];
72
- }
73
- /**
74
- * 认证配置
75
- */
76
- interface AuthConfig {
77
- /** 认证类型 */
78
- type: 'bearer' | 'api-key' | 'basic' | 'custom';
79
- /** Token 获取函数 */
80
- getToken?: () => Promise<string | null> | string | null;
81
- /** API Key */
82
- apiKey?: string;
83
- /** API Key 头部名称 */
84
- apiKeyHeader?: string;
85
- /** Basic Auth 用户名 */
86
- username?: string;
87
- /** Basic Auth 密码 */
88
- password?: string;
89
- /** 自定义认证函数 */
90
- customAuth?: (headers: Record<string, string>) => Promise<void> | void;
77
+ interface NoAuthConfig {
78
+ readonly type: 'none';
91
79
  }
92
80
  /**
93
- * 重试配置
81
+ * 认证配置联合类型
94
82
  */
95
- interface RetryConfig {
96
- /** 最大重试次数 */
97
- maxRetries: number;
98
- /** 初始延迟(毫秒) */
99
- initialDelay: number;
100
- /** 最大延迟(毫秒) */
101
- maxDelay: number;
102
- /** 退避策略 */
103
- backoff: 'fixed' | 'exponential' | 'linear';
104
- /** 可重试的 HTTP 状态码 */
105
- retryableStatusCodes?: number[];
106
- /** 是否重试网络错误 */
107
- retryOnNetworkError?: boolean;
83
+ type AuthConfig = BearerAuthConfig | ApiKeyAuthConfig | BasicAuthConfig | CustomAuthConfig | NoAuthConfig;
84
+ /**
85
+ * Token 刷新配置
86
+ */
87
+ interface TokenRefreshConfig {
88
+ /**
89
+ * 刷新 Token 的函数
90
+ * 返回新的 Token,如果刷新失败则抛出异常
91
+ */
92
+ readonly refreshToken: () => Promise<string>;
93
+ /**
94
+ * 触发刷新的 HTTP 状态码
95
+ * @default [401]
96
+ */
97
+ readonly triggerStatusCodes?: readonly number[];
98
+ /**
99
+ * 最大刷新重试次数
100
+ * @default 1
101
+ */
102
+ readonly maxRetries?: number;
103
+ /**
104
+ * 刷新失败时的回调
105
+ */
106
+ readonly onRefreshFailed?: (error: Error) => void;
108
107
  }
108
+
109
109
  /**
110
- * 请求选项
110
+ * 重试配置类型定义
111
+ *
112
+ * @packageDocumentation
111
113
  */
112
- interface RequestOptions {
113
- /** HTTP 方法 */
114
- method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
115
- /** 请求路径 */
116
- path: string;
117
- /** 查询参数 */
118
- query?: Record<string, string | number | boolean | undefined>;
119
- /** 请求体 */
120
- body?: unknown;
121
- /** 请求头 */
122
- headers?: Record<string, string>;
123
- /** 超时时间 */
124
- timeout?: number;
125
- /** 是否跳过认证 */
126
- skipAuth?: boolean;
127
- /** 请求上下文 */
128
- context?: Partial<RequestContext>;
114
+ /**
115
+ * 退避策略类型
116
+ */
117
+ type BackoffStrategy = 'fixed' | 'linear' | 'exponential';
118
+ /**
119
+ * 重试配置
120
+ */
121
+ interface RetryConfig {
122
+ /**
123
+ * 最大重试次数
124
+ * @default 3
125
+ */
126
+ readonly maxRetries: number;
127
+ /**
128
+ * 初始延迟(毫秒)
129
+ * @default 1000
130
+ */
131
+ readonly initialDelayMs: number;
132
+ /**
133
+ * 最大延迟(毫秒)
134
+ * @default 30000
135
+ */
136
+ readonly maxDelayMs: number;
137
+ /**
138
+ * 退避策略
139
+ * - fixed: 固定延迟
140
+ * - linear: 线性增长 (initialDelay * (attempt + 1))
141
+ * - exponential: 指数增长 (initialDelay * 2^attempt)
142
+ * @default 'exponential'
143
+ */
144
+ readonly backoffStrategy: BackoffStrategy;
145
+ /**
146
+ * 可重试的 HTTP 状态码
147
+ * @default [429, 500, 502, 503, 504]
148
+ */
149
+ readonly retryableStatusCodes?: readonly number[];
150
+ /**
151
+ * 是否重试网络错误
152
+ * @default true
153
+ */
154
+ readonly retryOnNetworkError?: boolean;
155
+ /**
156
+ * 是否重试超时错误
157
+ * @default true
158
+ */
159
+ readonly retryOnTimeout?: boolean;
160
+ /**
161
+ * 是否尊重 Retry-After 响应头
162
+ * @default true
163
+ */
164
+ readonly respectRetryAfter?: boolean;
165
+ /**
166
+ * 重试时的回调函数
167
+ */
168
+ readonly onRetry?: RetryCallback;
169
+ /**
170
+ * 自定义判断是否应该重试的函数
171
+ * 如果提供,将覆盖默认的重试逻辑
172
+ */
173
+ readonly shouldRetry?: ShouldRetryFn;
174
+ /**
175
+ * 抖动系数(0-1 之间)
176
+ * 用于添加随机延迟,防止惊群效应
177
+ * @default 0.1
178
+ */
179
+ readonly jitterFactor?: number;
129
180
  }
130
181
  /**
131
- * 请求拦截器
182
+ * 重试回调函数
132
183
  */
133
- type RequestInterceptor = (options: RequestOptions) => Promise<RequestOptions>;
184
+ type RetryCallback = (info: RetryInfo) => void;
134
185
  /**
135
- * 响应拦截器
186
+ * 重试信息
136
187
  */
137
- type ResponseInterceptor = <T>(response: ApiSuccessResponse<T>, options: RequestOptions) => Promise<ApiSuccessResponse<T>>;
188
+ interface RetryInfo {
189
+ /**
190
+ * 当前重试次数(从 1 开始)
191
+ */
192
+ readonly attempt: number;
193
+ /**
194
+ * 最大重试次数
195
+ */
196
+ readonly maxRetries: number;
197
+ /**
198
+ * 下次重试延迟(毫秒)
199
+ */
200
+ readonly delayMs: number;
201
+ /**
202
+ * 导致重试的错误
203
+ */
204
+ readonly error: Error;
205
+ /**
206
+ * 请求 URL
207
+ */
208
+ readonly url: string;
209
+ /**
210
+ * 请求方法
211
+ */
212
+ readonly method: string;
213
+ }
138
214
  /**
139
- * 错误拦截器
215
+ * 自定义重试判断函数
140
216
  */
141
- type ErrorInterceptor = (error: ApiError, options: RequestOptions) => Promise<void>;
142
-
217
+ type ShouldRetryFn = (error: Error, attempt: number, context: RetryContext) => boolean;
143
218
  /**
144
- * Axios 实例创建
145
- *
146
- * 用于注入到 openapi-generator 生成的客户端
219
+ * 重试上下文
147
220
  */
148
-
149
- declare module 'axios' {
150
- interface InternalAxiosRequestConfig {
151
- __retryCount?: number;
152
- }
221
+ interface RetryContext {
222
+ /**
223
+ * 请求 URL
224
+ */
225
+ readonly url: string;
226
+ /**
227
+ * 请求方法
228
+ */
229
+ readonly method: string;
230
+ /**
231
+ * HTTP 状态码(如果有响应)
232
+ */
233
+ readonly statusCode?: number;
234
+ /**
235
+ * Retry-After 头的值(秒)
236
+ */
237
+ readonly retryAfter?: number;
153
238
  }
154
-
155
239
  /**
156
- * 创建配置好的 Axios 实例
157
- *
158
- * 用于注入到 openapi-generator 生成的 API 类中
159
- *
160
- * @example
161
- * ```typescript
162
- * import { createAxiosInstance } from '@djvlc/openapi-client-core';
163
- * import { PagesApi, Configuration } from './generated';
164
- *
165
- * const axiosInstance = createAxiosInstance({
166
- * baseUrl: '/api/admin',
167
- * auth: { type: 'bearer', getToken: () => localStorage.getItem('token') },
168
- * retry: { maxRetries: 2, initialDelay: 1000, maxDelay: 10000, backoff: 'exponential' },
169
- * });
170
- *
171
- * const config = new Configuration();
172
- * const pagesApi = new PagesApi(config, undefined, axiosInstance);
173
- * ```
240
+ * 默认重试配置
174
241
  */
175
- declare function createAxiosInstance(config: ClientConfig): AxiosInstance;
242
+ declare const DEFAULT_RETRY_CONFIG: Readonly<RetryConfig>;
176
243
 
177
244
  /**
178
- * 原生 fetch HTTP 客户端
245
+ * 拦截器类型定义
179
246
  *
180
- * 保留兼容性,供不使用 axios 的场景使用
247
+ * @packageDocumentation
181
248
  */
182
249
 
183
250
  /**
184
- * 基础 HTTP 客户端
251
+ * 请求拦截器
252
+ *
253
+ * 在请求发送前执行,可以修改请求选项
185
254
  */
186
- declare class HttpClient {
187
- private readonly config;
188
- constructor(config: ClientConfig);
255
+ interface RequestInterceptor {
189
256
  /**
190
- * 发起请求
257
+ * 拦截器名称(用于调试和日志)
191
258
  */
192
- request<T>(options: RequestOptions): Promise<T>;
259
+ readonly name: string;
193
260
  /**
194
- * GET 请求
261
+ * 执行顺序(数字越小越先执行)
262
+ * @default 0
195
263
  */
196
- get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
264
+ readonly order?: number;
197
265
  /**
198
- * POST 请求
266
+ * 拦截函数
267
+ * @param context - 请求上下文
268
+ * @returns 修改后的请求选项,或 Promise
199
269
  */
200
- post<T>(path: string, body?: unknown, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
270
+ intercept(context: RequestContext$1): MutableRequestOptions | Promise<MutableRequestOptions>;
271
+ }
272
+ /**
273
+ * 响应拦截器
274
+ *
275
+ * 在收到响应后执行,可以修改响应数据
276
+ */
277
+ interface ResponseInterceptor {
201
278
  /**
202
- * PUT 请求
279
+ * 拦截器名称(用于调试和日志)
203
280
  */
204
- put<T>(path: string, body?: unknown): Promise<T>;
281
+ readonly name: string;
205
282
  /**
206
- * PATCH 请求
283
+ * 执行顺序(数字越小越先执行)
284
+ * @default 0
207
285
  */
208
- patch<T>(path: string, body?: unknown): Promise<T>;
286
+ readonly order?: number;
209
287
  /**
210
- * DELETE 请求
288
+ * 拦截函数
289
+ * @param response - 响应数据
290
+ * @param context - 请求上下文
291
+ * @returns 修改后的响应数据,或 Promise
211
292
  */
212
- delete<T>(path: string): Promise<T>;
293
+ intercept<T>(response: ResponseData<T>, context: RequestContext$1): ResponseData<T> | Promise<ResponseData<T>>;
294
+ }
295
+ /**
296
+ * 错误拦截器
297
+ *
298
+ * 在发生错误时执行,可以处理、转换或重新抛出错误
299
+ */
300
+ interface ErrorInterceptor {
213
301
  /**
214
- * 构建完整 URL
302
+ * 拦截器名称(用于调试和日志)
215
303
  */
216
- private buildUrl;
304
+ readonly name: string;
217
305
  /**
218
- * 构建请求头
306
+ * 执行顺序(数字越小越先执行)
307
+ * @default 0
219
308
  */
220
- private buildHeaders;
309
+ readonly order?: number;
221
310
  /**
222
- * 带重试的请求执行
311
+ * 拦截函数
312
+ *
313
+ * @param error - 错误对象
314
+ * @param context - 请求上下文
315
+ * @returns 如果返回 void,错误将继续传播;如果返回 ResponseData,将作为成功响应返回
316
+ * @throws 可以抛出新的错误来替换原错误
223
317
  */
224
- private executeWithRetry;
318
+ intercept<T>(error: Error, context: RequestContext$1): void | ResponseData<T> | Promise<void | ResponseData<T>>;
319
+ }
320
+ /**
321
+ * 拦截器集合
322
+ */
323
+ interface Interceptors {
225
324
  /**
226
- * 执行单次请求
325
+ * 请求拦截器列表
227
326
  */
228
- private execute;
327
+ readonly request: readonly RequestInterceptor[];
229
328
  /**
230
- * 判断是否应该重试
329
+ * 响应拦截器列表
231
330
  */
232
- private shouldRetry;
331
+ readonly response: readonly ResponseInterceptor[];
332
+ /**
333
+ * 错误拦截器列表
334
+ */
335
+ readonly error: readonly ErrorInterceptor[];
233
336
  }
234
337
  /**
235
- * 创建 HTTP 客户端
338
+ * 拦截器工厂函数类型
236
339
  */
237
- declare function createClient(config: ClientConfig): HttpClient;
238
-
340
+ type RequestInterceptorFactory<TConfig = void> = (config: TConfig) => RequestInterceptor;
341
+ type ResponseInterceptorFactory<TConfig = void> = (config: TConfig) => ResponseInterceptor;
342
+ type ErrorInterceptorFactory<TConfig = void> = (config: TConfig) => ErrorInterceptor;
239
343
  /**
240
- * 工具函数
344
+ * 拦截器链执行结果
241
345
  */
346
+ interface InterceptorChainResult<T> {
347
+ /**
348
+ * 是否成功
349
+ */
350
+ readonly success: boolean;
351
+ /**
352
+ * 响应数据(成功时)
353
+ */
354
+ readonly data?: ResponseData<T>;
355
+ /**
356
+ * 错误(失败时)
357
+ */
358
+ readonly error?: Error;
359
+ /**
360
+ * 是否被拦截器处理
361
+ */
362
+ readonly handled: boolean;
363
+ }
242
364
 
243
365
  /**
244
- * 生成请求 ID
366
+ * 日志类型定义
367
+ *
368
+ * @packageDocumentation
245
369
  */
246
- declare function generateRequestId(): string;
247
370
  /**
248
- * 延迟执行
371
+ * 日志级别
249
372
  */
250
- declare function sleep(ms: number): Promise<void>;
373
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
374
+ /**
375
+ * 日志器接口
376
+ */
377
+ interface Logger {
378
+ /**
379
+ * 调试日志
380
+ */
381
+ debug(message: string, ...args: unknown[]): void;
382
+ /**
383
+ * 信息日志
384
+ */
385
+ info(message: string, ...args: unknown[]): void;
386
+ /**
387
+ * 警告日志
388
+ */
389
+ warn(message: string, ...args: unknown[]): void;
390
+ /**
391
+ * 错误日志
392
+ */
393
+ error(message: string, ...args: unknown[]): void;
394
+ }
395
+ /**
396
+ * 控制台日志器配置
397
+ */
398
+ interface ConsoleLoggerConfig {
399
+ /**
400
+ * 日志前缀
401
+ * @default '[DJV-API]'
402
+ */
403
+ readonly prefix?: string;
404
+ /**
405
+ * 最低日志级别
406
+ * @default 'info'
407
+ */
408
+ readonly level?: LogLevel;
409
+ /**
410
+ * 是否显示时间戳
411
+ * @default true
412
+ */
413
+ readonly timestamp?: boolean;
414
+ /**
415
+ * 是否使用颜色(仅在 Node.js 环境有效)
416
+ * @default true
417
+ */
418
+ readonly colors?: boolean;
419
+ }
251
420
  /**
252
- * 计算重试延迟
421
+ * 日志级别优先级映射
253
422
  */
254
- declare function calculateRetryDelay(retry: RetryConfig, attempt: number): number;
423
+ declare const LOG_LEVEL_PRIORITY: Readonly<Record<LogLevel, number>>;
255
424
 
256
425
  /**
257
- * @djvlc/openapi-client-core
258
- *
259
- * OpenAPI 客户端公共运行时
260
- *
261
- * 提供:
262
- * - Axios 实例创建(用于注入 openapi-generator 生成的客户端)
263
- * - 原生 fetch HTTP 客户端
264
- * - 认证处理(bearer/api-key/basic/custom)
265
- * - 错误处理
266
- * - 重试机制
267
- * - 请求/响应拦截器
426
+ * 客户端配置类型定义
268
427
  *
269
428
  * @packageDocumentation
270
429
  */
271
430
 
272
- declare const VERSION = "2.0.0";
431
+ /**
432
+ * 客户端基础配置
433
+ */
434
+ interface ClientConfig {
435
+ /**
436
+ * 基础 URL
437
+ * @example 'https://api.example.com'
438
+ */
439
+ readonly baseUrl: string;
440
+ /**
441
+ * 默认超时时间(毫秒)
442
+ * @default 30000
443
+ */
444
+ readonly timeout?: number;
445
+ /**
446
+ * 默认请求头
447
+ */
448
+ readonly headers?: Readonly<Record<string, string>>;
449
+ /**
450
+ * 认证配置
451
+ */
452
+ readonly auth?: AuthConfig;
453
+ /**
454
+ * 重试配置
455
+ */
456
+ readonly retry?: RetryConfig;
457
+ /**
458
+ * 请求拦截器列表
459
+ */
460
+ readonly requestInterceptors?: readonly RequestInterceptor[];
461
+ /**
462
+ * 响应拦截器列表
463
+ */
464
+ readonly responseInterceptors?: readonly ResponseInterceptor[];
465
+ /**
466
+ * 错误拦截器列表
467
+ */
468
+ readonly errorInterceptors?: readonly ErrorInterceptor[];
469
+ /**
470
+ * 日志器
471
+ */
472
+ readonly logger?: Logger;
473
+ /**
474
+ * 是否开启调试模式
475
+ * @default false
476
+ */
477
+ readonly debug?: boolean;
478
+ }
479
+ /**
480
+ * HTTP 方法类型
481
+ */
482
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
483
+ /**
484
+ * 请求选项
485
+ */
486
+ interface RequestOptions {
487
+ /**
488
+ * HTTP 方法
489
+ */
490
+ readonly method: HttpMethod;
491
+ /**
492
+ * 请求路径
493
+ */
494
+ readonly path: string;
495
+ /**
496
+ * 查询参数
497
+ */
498
+ readonly query?: Readonly<Record<string, string | number | boolean | undefined | null>>;
499
+ /**
500
+ * 请求体
501
+ */
502
+ readonly body?: unknown;
503
+ /**
504
+ * 请求头
505
+ */
506
+ readonly headers?: Readonly<Record<string, string>>;
507
+ /**
508
+ * 超时时间(毫秒)
509
+ */
510
+ readonly timeout?: number;
511
+ /**
512
+ * 是否跳过认证
513
+ * @default false
514
+ */
515
+ readonly skipAuth?: boolean;
516
+ /**
517
+ * AbortSignal 用于取消请求
518
+ */
519
+ readonly signal?: AbortSignal;
520
+ /**
521
+ * 请求元数据(用于拦截器间传递数据)
522
+ */
523
+ readonly metadata?: Readonly<Record<string, unknown>>;
524
+ }
525
+ /**
526
+ * 可变的请求选项(用于拦截器修改)
527
+ */
528
+ interface MutableRequestOptions {
529
+ method: HttpMethod;
530
+ path: string;
531
+ query?: Record<string, string | number | boolean | undefined | null>;
532
+ body?: unknown;
533
+ headers: Record<string, string>;
534
+ timeout?: number;
535
+ skipAuth?: boolean;
536
+ signal?: AbortSignal;
537
+ metadata: Record<string, unknown>;
538
+ }
539
+ /**
540
+ * 响应数据结构
541
+ */
542
+ interface ResponseData<T = unknown> {
543
+ /**
544
+ * 响应数据
545
+ */
546
+ readonly data: T;
547
+ /**
548
+ * HTTP 状态码
549
+ */
550
+ readonly status: number;
551
+ /**
552
+ * HTTP 状态文本
553
+ */
554
+ readonly statusText: string;
555
+ /**
556
+ * 响应头
557
+ */
558
+ readonly headers: Readonly<Record<string, string>>;
559
+ /**
560
+ * 请求 ID
561
+ */
562
+ readonly requestId: string;
563
+ /**
564
+ * 追踪 ID
565
+ */
566
+ readonly traceId?: string;
567
+ }
568
+ /**
569
+ * 请求上下文(拦截器使用)
570
+ */
571
+ interface RequestContext$1 {
572
+ /**
573
+ * 请求 ID
574
+ */
575
+ readonly requestId: string;
576
+ /**
577
+ * 追踪 ID
578
+ */
579
+ readonly traceId?: string;
580
+ /**
581
+ * 请求开始时间戳
582
+ */
583
+ readonly startTime: number;
584
+ /**
585
+ * 重试次数
586
+ */
587
+ retryCount: number;
588
+ /**
589
+ * 原始请求选项
590
+ */
591
+ readonly originalOptions: Readonly<RequestOptions>;
592
+ /**
593
+ * 当前请求选项(可能被拦截器修改)
594
+ */
595
+ options: MutableRequestOptions;
596
+ /**
597
+ * 完整 URL
598
+ */
599
+ readonly url: string;
600
+ /**
601
+ * 元数据存储
602
+ */
603
+ metadata: Record<string, unknown>;
604
+ }
605
+
606
+ /**
607
+ * 指标类型定义
608
+ *
609
+ * @packageDocumentation
610
+ */
611
+ /**
612
+ * 请求指标
613
+ */
614
+ interface RequestMetrics {
615
+ /**
616
+ * 请求 ID
617
+ */
618
+ readonly requestId: string;
619
+ /**
620
+ * 完整 URL
621
+ */
622
+ readonly url: string;
623
+ /**
624
+ * 请求路径(不含查询参数)
625
+ */
626
+ readonly path: string;
627
+ /**
628
+ * HTTP 方法
629
+ */
630
+ readonly method: string;
631
+ /**
632
+ * 开始时间戳(毫秒)
633
+ */
634
+ readonly startTime: number;
635
+ /**
636
+ * 结束时间戳(毫秒)
637
+ */
638
+ readonly endTime: number;
639
+ /**
640
+ * 耗时(毫秒)
641
+ */
642
+ readonly durationMs: number;
643
+ /**
644
+ * HTTP 状态码
645
+ */
646
+ readonly status?: number;
647
+ /**
648
+ * 是否成功(2xx)
649
+ */
650
+ readonly success: boolean;
651
+ /**
652
+ * 重试次数
653
+ */
654
+ readonly retryCount: number;
655
+ /**
656
+ * 追踪 ID
657
+ */
658
+ readonly traceId?: string;
659
+ /**
660
+ * 错误信息(如果失败)
661
+ */
662
+ readonly error?: string;
663
+ /**
664
+ * 请求体大小(字节)
665
+ */
666
+ readonly requestSize?: number;
667
+ /**
668
+ * 响应体大小(字节)
669
+ */
670
+ readonly responseSize?: number;
671
+ }
672
+ /**
673
+ * 指标摘要
674
+ */
675
+ interface MetricsSummary {
676
+ /**
677
+ * 总请求数
678
+ */
679
+ readonly totalRequests: number;
680
+ /**
681
+ * 成功请求数
682
+ */
683
+ readonly successfulRequests: number;
684
+ /**
685
+ * 失败请求数
686
+ */
687
+ readonly failedRequests: number;
688
+ /**
689
+ * 成功率(0-1)
690
+ */
691
+ readonly successRate: number;
692
+ /**
693
+ * 平均耗时(毫秒)
694
+ */
695
+ readonly avgDurationMs: number;
696
+ /**
697
+ * P50 耗时(毫秒)
698
+ */
699
+ readonly p50Ms: number;
700
+ /**
701
+ * P90 耗时(毫秒)
702
+ */
703
+ readonly p90Ms: number;
704
+ /**
705
+ * P95 耗时(毫秒)
706
+ */
707
+ readonly p95Ms: number;
708
+ /**
709
+ * P99 耗时(毫秒)
710
+ */
711
+ readonly p99Ms: number;
712
+ /**
713
+ * 最小耗时(毫秒)
714
+ */
715
+ readonly minDurationMs: number;
716
+ /**
717
+ * 最大耗时(毫秒)
718
+ */
719
+ readonly maxDurationMs: number;
720
+ /**
721
+ * 总重试次数
722
+ */
723
+ readonly totalRetries: number;
724
+ /**
725
+ * 按状态码分布
726
+ */
727
+ readonly statusCodeDistribution: Readonly<Record<number, number>>;
728
+ /**
729
+ * 按路径分布
730
+ */
731
+ readonly pathDistribution: Readonly<Record<string, PathMetrics>>;
732
+ }
733
+ /**
734
+ * 路径指标
735
+ */
736
+ interface PathMetrics {
737
+ /**
738
+ * 请求数
739
+ */
740
+ readonly count: number;
741
+ /**
742
+ * 成功数
743
+ */
744
+ readonly successCount: number;
745
+ /**
746
+ * 平均耗时(毫秒)
747
+ */
748
+ readonly avgDurationMs: number;
749
+ }
750
+ /**
751
+ * 指标收集器配置
752
+ */
753
+ interface MetricsCollectorConfig {
754
+ /**
755
+ * 最大保留的指标数量
756
+ * @default 1000
757
+ */
758
+ readonly maxMetrics?: number;
759
+ /**
760
+ * 指标过期时间(毫秒)
761
+ * @default 3600000 (1 hour)
762
+ */
763
+ readonly ttlMs?: number;
764
+ /**
765
+ * 每次请求完成时的回调
766
+ */
767
+ readonly onMetrics?: (metrics: RequestMetrics) => void;
768
+ /**
769
+ * 是否启用详细指标(包括请求/响应大小)
770
+ * @default false
771
+ */
772
+ readonly detailed?: boolean;
773
+ }
774
+ /**
775
+ * 指标收集器接口
776
+ */
777
+ interface MetricsCollector {
778
+ /**
779
+ * 记录请求指标
780
+ */
781
+ record(metrics: RequestMetrics): void;
782
+ /**
783
+ * 获取指标摘要
784
+ */
785
+ summary(): MetricsSummary;
786
+ /**
787
+ * 获取所有指标
788
+ */
789
+ getAll(): readonly RequestMetrics[];
790
+ /**
791
+ * 按路径获取指标
792
+ */
793
+ getByPath(path: string): readonly RequestMetrics[];
794
+ /**
795
+ * 清空所有指标并返回
796
+ */
797
+ flush(): readonly RequestMetrics[];
798
+ /**
799
+ * 清空所有指标
800
+ */
801
+ clear(): void;
802
+ }
803
+
804
+ /**
805
+ * 基础错误类
806
+ *
807
+ * @packageDocumentation
808
+ */
809
+ /**
810
+ * 客户端基础错误类
811
+ *
812
+ * 所有自定义错误的基类,提供统一的错误处理能力
813
+ */
814
+ declare abstract class BaseClientError extends Error {
815
+ /**
816
+ * 错误类型标识符
817
+ */
818
+ abstract readonly type: string;
819
+ /**
820
+ * 是否可重试
821
+ */
822
+ abstract readonly retryable: boolean;
823
+ /**
824
+ * 错误发生时间
825
+ */
826
+ readonly timestamp: Date;
827
+ constructor(message: string);
828
+ /**
829
+ * 转换为 JSON 对象(用于日志和序列化)
830
+ */
831
+ toJSON(): Record<string, unknown>;
832
+ /**
833
+ * 转换为字符串
834
+ */
835
+ toString(): string;
836
+ }
837
+
838
+ /**
839
+ * API 错误类
840
+ *
841
+ * @packageDocumentation
842
+ */
843
+
844
+ /**
845
+ * 错误详情
846
+ */
847
+ interface ApiErrorDetail {
848
+ /**
849
+ * 字段名
850
+ */
851
+ readonly field?: string;
852
+ /**
853
+ * 错误消息
854
+ */
855
+ readonly message: string;
856
+ /**
857
+ * 错误码
858
+ */
859
+ readonly code?: string;
860
+ }
861
+ /**
862
+ * API 错误配置
863
+ */
864
+ interface ApiErrorConfig {
865
+ /**
866
+ * 错误消息
867
+ */
868
+ readonly message: string;
869
+ /**
870
+ * 业务错误码
871
+ */
872
+ readonly code: string;
873
+ /**
874
+ * HTTP 状态码
875
+ */
876
+ readonly statusCode: number;
877
+ /**
878
+ * 错误详情
879
+ */
880
+ readonly details?: readonly ApiErrorDetail[];
881
+ /**
882
+ * 请求 ID
883
+ */
884
+ readonly requestId: string;
885
+ /**
886
+ * 追踪 ID
887
+ */
888
+ readonly traceId?: string;
889
+ /**
890
+ * Retry-After 头的值(秒)
891
+ */
892
+ readonly retryAfter?: number;
893
+ /**
894
+ * 原始响应数据
895
+ */
896
+ readonly rawResponse?: unknown;
897
+ }
898
+ /**
899
+ * API 业务错误
900
+ *
901
+ * 表示服务器返回的业务错误响应(HTTP 非 2xx)
902
+ */
903
+ declare class ApiError extends BaseClientError {
904
+ readonly type: "API_ERROR";
905
+ /**
906
+ * 业务错误码
907
+ */
908
+ readonly code: string;
909
+ /**
910
+ * HTTP 状态码
911
+ */
912
+ readonly statusCode: number;
913
+ /**
914
+ * 错误详情
915
+ */
916
+ readonly details?: readonly ApiErrorDetail[];
917
+ /**
918
+ * 请求 ID
919
+ */
920
+ readonly requestId: string;
921
+ /**
922
+ * 追踪 ID
923
+ */
924
+ readonly traceId?: string;
925
+ /**
926
+ * Retry-After 头的值(秒)
927
+ */
928
+ readonly retryAfterSeconds?: number;
929
+ /**
930
+ * 原始响应数据
931
+ */
932
+ readonly rawResponse?: unknown;
933
+ constructor(config: ApiErrorConfig);
934
+ /**
935
+ * 是否可重试
936
+ *
937
+ * 5xx 和 429 错误通常可重试
938
+ */
939
+ get retryable(): boolean;
940
+ /**
941
+ * 是否为未授权错误 (401)
942
+ */
943
+ isUnauthorized(): boolean;
944
+ /**
945
+ * 是否为禁止访问错误 (403)
946
+ */
947
+ isForbidden(): boolean;
948
+ /**
949
+ * 是否为认证相关错误 (401/403)
950
+ */
951
+ isAuthError(): boolean;
952
+ /**
953
+ * 是否为未找到错误 (404)
954
+ */
955
+ isNotFound(): boolean;
956
+ /**
957
+ * 是否为冲突错误 (409)
958
+ */
959
+ isConflict(): boolean;
960
+ /**
961
+ * 是否为验证错误 (400/422)
962
+ */
963
+ isValidationError(): boolean;
964
+ /**
965
+ * 是否为限流错误 (429)
966
+ */
967
+ isRateLimited(): boolean;
968
+ /**
969
+ * 是否为客户端错误 (4xx)
970
+ */
971
+ isClientError(): boolean;
972
+ /**
973
+ * 是否为服务端错误 (5xx)
974
+ */
975
+ isServerError(): boolean;
976
+ /**
977
+ * 获取 Retry-After 值(秒)
978
+ */
979
+ getRetryAfter(): number | undefined;
980
+ /**
981
+ * 获取推荐的重试延迟(毫秒)
982
+ *
983
+ * @param defaultMs - 默认延迟(毫秒)
984
+ */
985
+ getRetryDelayMs(defaultMs?: number): number;
986
+ toJSON(): Record<string, unknown>;
987
+ /**
988
+ * 类型守卫:判断是否为 ApiError
989
+ */
990
+ static is(error: unknown): error is ApiError;
991
+ /**
992
+ * 从响应数据创建 ApiError
993
+ */
994
+ static fromResponse(data: {
995
+ code?: string;
996
+ message?: string;
997
+ details?: ApiErrorDetail[];
998
+ requestId?: string;
999
+ traceId?: string;
1000
+ }, statusCode: number, retryAfter?: number): ApiError;
1001
+ }
1002
+
1003
+ /**
1004
+ * 网络错误类
1005
+ *
1006
+ * @packageDocumentation
1007
+ */
1008
+
1009
+ /**
1010
+ * 网络错误
1011
+ *
1012
+ * 表示网络层面的错误,如 DNS 解析失败、连接被拒绝等
1013
+ */
1014
+ declare class NetworkError extends BaseClientError {
1015
+ readonly type: "NETWORK_ERROR";
1016
+ readonly retryable = true;
1017
+ /**
1018
+ * 原始错误
1019
+ */
1020
+ readonly cause?: Error;
1021
+ constructor(message: string, cause?: Error);
1022
+ toJSON(): Record<string, unknown>;
1023
+ /**
1024
+ * 类型守卫:判断是否为 NetworkError
1025
+ */
1026
+ static is(error: unknown): error is NetworkError;
1027
+ /**
1028
+ * 从原生 fetch 错误创建 NetworkError
1029
+ */
1030
+ static fromFetchError(error: Error): NetworkError;
1031
+ }
1032
+
1033
+ /**
1034
+ * 超时错误类
1035
+ *
1036
+ * @packageDocumentation
1037
+ */
1038
+
1039
+ /**
1040
+ * 超时错误
1041
+ *
1042
+ * 表示请求超时
1043
+ */
1044
+ declare class TimeoutError extends BaseClientError {
1045
+ readonly type: "TIMEOUT_ERROR";
1046
+ readonly retryable = true;
1047
+ /**
1048
+ * 超时时间(毫秒)
1049
+ */
1050
+ readonly timeoutMs: number;
1051
+ constructor(timeoutMs: number);
1052
+ toJSON(): Record<string, unknown>;
1053
+ /**
1054
+ * 类型守卫:判断是否为 TimeoutError
1055
+ */
1056
+ static is(error: unknown): error is TimeoutError;
1057
+ }
1058
+
1059
+ /**
1060
+ * 取消错误类
1061
+ *
1062
+ * @packageDocumentation
1063
+ */
1064
+
1065
+ /**
1066
+ * 取消错误
1067
+ *
1068
+ * 表示请求被主动取消
1069
+ */
1070
+ declare class AbortError extends BaseClientError {
1071
+ readonly type: "ABORT_ERROR";
1072
+ readonly retryable = false;
1073
+ /**
1074
+ * 取消原因
1075
+ */
1076
+ readonly reason?: string;
1077
+ constructor(reason?: string);
1078
+ toJSON(): Record<string, unknown>;
1079
+ /**
1080
+ * 类型守卫:判断是否为 AbortError
1081
+ */
1082
+ static is(error: unknown): error is AbortError;
1083
+ /**
1084
+ * 从原生 AbortError 创建
1085
+ */
1086
+ static fromNative(error: Error): AbortError;
1087
+ }
1088
+
1089
+ /**
1090
+ * 错误模块
1091
+ *
1092
+ * @packageDocumentation
1093
+ */
1094
+
1095
+ /**
1096
+ * 判断错误是否可重试
1097
+ */
1098
+ declare function isRetryableError(error: unknown): boolean;
1099
+ /**
1100
+ * 获取错误的推荐重试延迟(毫秒)
1101
+ *
1102
+ * @param error - 错误对象
1103
+ * @param defaultMs - 默认延迟
1104
+ */
1105
+ declare function getRetryDelay(error: unknown, defaultMs?: number): number;
1106
+ /**
1107
+ * 判断是否为客户端错误类型
1108
+ */
1109
+ declare function isClientError(error: unknown): error is ApiError | NetworkError | TimeoutError | AbortError;
1110
+ /**
1111
+ * 获取错误类型标识符
1112
+ */
1113
+ declare function getErrorType(error: unknown): string;
1114
+
1115
+ /**
1116
+ * 认证器接口
1117
+ *
1118
+ * @packageDocumentation
1119
+ */
1120
+ /**
1121
+ * 认证器接口
1122
+ *
1123
+ * 定义了认证器的基本行为
1124
+ */
1125
+ interface Authenticator {
1126
+ /**
1127
+ * 认证类型
1128
+ */
1129
+ readonly type: string;
1130
+ /**
1131
+ * 向请求头添加认证信息
1132
+ *
1133
+ * @param headers - 请求头对象(可变)
1134
+ * @returns Promise<void> 或 void
1135
+ */
1136
+ authenticate(headers: Record<string, string>): Promise<void> | void;
1137
+ }
1138
+ /**
1139
+ * 认证器工厂函数类型
1140
+ */
1141
+ type AuthenticatorFactory<TConfig> = (config: TConfig) => Authenticator;
1142
+
1143
+ /**
1144
+ * Bearer Token 认证器
1145
+ *
1146
+ * @packageDocumentation
1147
+ */
1148
+
1149
+ /**
1150
+ * Bearer Token 认证器
1151
+ *
1152
+ * 将 Bearer Token 添加到 Authorization 头
1153
+ */
1154
+ declare class BearerAuthenticator implements Authenticator {
1155
+ readonly type: "bearer";
1156
+ private readonly getToken;
1157
+ private readonly headerName;
1158
+ private readonly prefix;
1159
+ constructor(config: Omit<BearerAuthConfig, 'type'>);
1160
+ authenticate(headers: Record<string, string>): Promise<void>;
1161
+ }
1162
+ /**
1163
+ * 创建 Bearer Token 认证器
1164
+ */
1165
+ declare function createBearerAuthenticator(config: Omit<BearerAuthConfig, 'type'>): BearerAuthenticator;
1166
+
1167
+ /**
1168
+ * API Key 认证器
1169
+ *
1170
+ * @packageDocumentation
1171
+ */
1172
+
1173
+ /**
1174
+ * API Key 认证器
1175
+ *
1176
+ * 将 API Key 添加到指定的请求头
1177
+ */
1178
+ declare class ApiKeyAuthenticator implements Authenticator {
1179
+ readonly type: "api-key";
1180
+ private readonly apiKey;
1181
+ private readonly headerName;
1182
+ constructor(config: Omit<ApiKeyAuthConfig, 'type'>);
1183
+ authenticate(headers: Record<string, string>): void;
1184
+ }
1185
+ /**
1186
+ * 创建 API Key 认证器
1187
+ */
1188
+ declare function createApiKeyAuthenticator(config: Omit<ApiKeyAuthConfig, 'type'>): ApiKeyAuthenticator;
1189
+
1190
+ /**
1191
+ * Basic Auth 认证器
1192
+ *
1193
+ * @packageDocumentation
1194
+ */
1195
+
1196
+ /**
1197
+ * Basic Auth 认证器
1198
+ *
1199
+ * 将用户名和密码以 Base64 编码添加到 Authorization 头
1200
+ */
1201
+ declare class BasicAuthenticator implements Authenticator {
1202
+ readonly type: "basic";
1203
+ private readonly encodedCredentials;
1204
+ constructor(config: Omit<BasicAuthConfig, 'type'>);
1205
+ authenticate(headers: Record<string, string>): void;
1206
+ }
1207
+ /**
1208
+ * 创建 Basic Auth 认证器
1209
+ */
1210
+ declare function createBasicAuthenticator(config: Omit<BasicAuthConfig, 'type'>): BasicAuthenticator;
1211
+
1212
+ /**
1213
+ * 自定义认证器
1214
+ *
1215
+ * @packageDocumentation
1216
+ */
1217
+
1218
+ /**
1219
+ * 自定义认证器
1220
+ *
1221
+ * 允许用户自定义认证逻辑
1222
+ */
1223
+ declare class CustomAuthenticator implements Authenticator {
1224
+ readonly type: "custom";
1225
+ private readonly authenticateFn;
1226
+ constructor(config: Omit<CustomAuthConfig, 'type'>);
1227
+ authenticate(headers: Record<string, string>): Promise<void>;
1228
+ }
1229
+ /**
1230
+ * 创建自定义认证器
1231
+ */
1232
+ declare function createCustomAuthenticator(config: Omit<CustomAuthConfig, 'type'>): CustomAuthenticator;
1233
+
1234
+ /**
1235
+ * 无认证器
1236
+ *
1237
+ * @packageDocumentation
1238
+ */
1239
+
1240
+ /**
1241
+ * 无认证器
1242
+ *
1243
+ * 不进行任何认证操作
1244
+ */
1245
+ declare class NoAuthenticator implements Authenticator {
1246
+ readonly type: "none";
1247
+ authenticate(_headers: Record<string, string>): void;
1248
+ }
1249
+ /**
1250
+ * 创建无认证器
1251
+ */
1252
+ declare function createNoAuthenticator(): NoAuthenticator;
1253
+ /**
1254
+ * 无认证器单例
1255
+ */
1256
+ declare const noAuthenticator: NoAuthenticator;
1257
+
1258
+ /**
1259
+ * 认证模块
1260
+ *
1261
+ * @packageDocumentation
1262
+ */
1263
+
1264
+ /**
1265
+ * 从配置创建认证器
1266
+ *
1267
+ * @param config - 认证配置
1268
+ * @returns 认证器实例
1269
+ */
1270
+ declare function createAuthenticatorFromConfig(config: AuthConfig): Authenticator;
1271
+
1272
+ /**
1273
+ * 拦截器管理器
1274
+ *
1275
+ * 管理拦截器的注册、排序和执行
1276
+ *
1277
+ * @packageDocumentation
1278
+ */
1279
+
1280
+ /**
1281
+ * 拦截器管理器
1282
+ *
1283
+ * 负责:
1284
+ * 1. 管理拦截器的注册和移除
1285
+ * 2. 按优先级排序拦截器
1286
+ * 3. 顺序执行拦截器链
1287
+ */
1288
+ declare class InterceptorManager {
1289
+ private readonly requestInterceptors;
1290
+ private readonly responseInterceptors;
1291
+ private readonly errorInterceptors;
1292
+ /**
1293
+ * 获取所有拦截器
1294
+ */
1295
+ get interceptors(): Interceptors;
1296
+ /**
1297
+ * 添加请求拦截器
1298
+ *
1299
+ * @param interceptor - 请求拦截器
1300
+ * @returns 返回自身,支持链式调用
1301
+ */
1302
+ addRequestInterceptor(interceptor: RequestInterceptor): this;
1303
+ /**
1304
+ * 添加响应拦截器
1305
+ *
1306
+ * @param interceptor - 响应拦截器
1307
+ * @returns 返回自身,支持链式调用
1308
+ */
1309
+ addResponseInterceptor(interceptor: ResponseInterceptor): this;
1310
+ /**
1311
+ * 添加错误拦截器
1312
+ *
1313
+ * @param interceptor - 错误拦截器
1314
+ * @returns 返回自身,支持链式调用
1315
+ */
1316
+ addErrorInterceptor(interceptor: ErrorInterceptor): this;
1317
+ /**
1318
+ * 批量添加拦截器
1319
+ *
1320
+ * @param interceptors - 拦截器配置
1321
+ * @returns 返回自身,支持链式调用
1322
+ */
1323
+ addInterceptors(interceptors: Partial<Interceptors>): this;
1324
+ /**
1325
+ * 移除请求拦截器
1326
+ *
1327
+ * @param name - 拦截器名称
1328
+ * @returns 是否移除成功
1329
+ */
1330
+ removeRequestInterceptor(name: string): boolean;
1331
+ /**
1332
+ * 移除响应拦截器
1333
+ *
1334
+ * @param name - 拦截器名称
1335
+ * @returns 是否移除成功
1336
+ */
1337
+ removeResponseInterceptor(name: string): boolean;
1338
+ /**
1339
+ * 移除错误拦截器
1340
+ *
1341
+ * @param name - 拦截器名称
1342
+ * @returns 是否移除成功
1343
+ */
1344
+ removeErrorInterceptor(name: string): boolean;
1345
+ /**
1346
+ * 清除所有拦截器
1347
+ */
1348
+ clear(): void;
1349
+ /**
1350
+ * 执行请求拦截器链
1351
+ *
1352
+ * @param context - 请求上下文
1353
+ * @returns 修改后的请求选项
1354
+ */
1355
+ executeRequestInterceptors(context: RequestContext$1): Promise<MutableRequestOptions>;
1356
+ /**
1357
+ * 执行响应拦截器链
1358
+ *
1359
+ * @param response - 响应数据
1360
+ * @param context - 请求上下文
1361
+ * @returns 修改后的响应数据
1362
+ */
1363
+ executeResponseInterceptors<T>(response: ResponseData<T>, context: RequestContext$1): Promise<ResponseData<T>>;
1364
+ /**
1365
+ * 执行错误拦截器链
1366
+ *
1367
+ * @param error - 错误对象
1368
+ * @param context - 请求上下文
1369
+ * @returns 如果返回 ResponseData,则表示错误被恢复;否则错误继续传播
1370
+ * @throws 如果拦截器抛出新错误,则使用新错误
1371
+ */
1372
+ executeErrorInterceptors<T>(error: Error, context: RequestContext$1): Promise<ResponseData<T> | void>;
1373
+ /**
1374
+ * 按 order 排序拦截器
1375
+ */
1376
+ private sortInterceptors;
1377
+ /**
1378
+ * 按名称移除拦截器
1379
+ */
1380
+ private removeByName;
1381
+ }
1382
+ /**
1383
+ * 创建拦截器管理器
1384
+ */
1385
+ declare function createInterceptorManager(): InterceptorManager;
1386
+
1387
+ /**
1388
+ * 认证拦截器
1389
+ *
1390
+ * 自动向请求添加认证信息
1391
+ *
1392
+ * @packageDocumentation
1393
+ */
1394
+
1395
+ /**
1396
+ * 认证拦截器配置
1397
+ */
1398
+ interface AuthInterceptorConfig {
1399
+ /**
1400
+ * 认证器实例
1401
+ */
1402
+ readonly authenticator: Authenticator;
1403
+ /**
1404
+ * 执行顺序
1405
+ * @default -100 (优先执行)
1406
+ */
1407
+ readonly order?: number;
1408
+ }
1409
+ /**
1410
+ * 认证拦截器
1411
+ *
1412
+ * 在请求发送前添加认证信息
1413
+ */
1414
+ declare class AuthInterceptor implements RequestInterceptor {
1415
+ readonly name = "auth";
1416
+ readonly order: number;
1417
+ private readonly authenticator;
1418
+ constructor(config: AuthInterceptorConfig);
1419
+ intercept(context: RequestContext$1): Promise<MutableRequestOptions>;
1420
+ }
1421
+ /**
1422
+ * 创建认证拦截器
1423
+ */
1424
+ declare function createAuthInterceptor(config: AuthInterceptorConfig): AuthInterceptor;
1425
+
1426
+ /**
1427
+ * 请求 ID 拦截器
1428
+ *
1429
+ * 自动生成并添加请求 ID
1430
+ *
1431
+ * @packageDocumentation
1432
+ */
1433
+
1434
+ /**
1435
+ * 请求 ID 拦截器配置
1436
+ */
1437
+ interface RequestIdInterceptorConfig {
1438
+ /**
1439
+ * 请求 ID 头名称
1440
+ * @default 'X-Request-ID'
1441
+ */
1442
+ readonly headerName?: string;
1443
+ /**
1444
+ * 自定义 ID 生成函数
1445
+ */
1446
+ readonly generateId?: () => string;
1447
+ /**
1448
+ * 执行顺序
1449
+ * @default -90
1450
+ */
1451
+ readonly order?: number;
1452
+ }
1453
+ /**
1454
+ * 请求 ID 拦截器
1455
+ *
1456
+ * 为每个请求自动生成唯一的请求 ID
1457
+ */
1458
+ declare class RequestIdInterceptor implements RequestInterceptor {
1459
+ readonly name = "request-id";
1460
+ readonly order: number;
1461
+ private readonly headerName;
1462
+ private readonly generateId;
1463
+ constructor(config?: RequestIdInterceptorConfig);
1464
+ intercept(context: RequestContext$1): MutableRequestOptions;
1465
+ }
1466
+ /**
1467
+ * 创建请求 ID 拦截器
1468
+ */
1469
+ declare function createRequestIdInterceptor(config?: RequestIdInterceptorConfig): RequestIdInterceptor;
1470
+
1471
+ /**
1472
+ * 追踪上下文拦截器
1473
+ *
1474
+ * 自动添加追踪 ID 和 OpenTelemetry 上下文
1475
+ *
1476
+ * @packageDocumentation
1477
+ */
1478
+
1479
+ /**
1480
+ * 追踪拦截器配置
1481
+ */
1482
+ interface TraceInterceptorConfig {
1483
+ /**
1484
+ * 追踪 ID 头名称
1485
+ * @default 'X-Trace-ID'
1486
+ */
1487
+ readonly traceIdHeader?: string;
1488
+ /**
1489
+ * 是否添加 traceparent 头(W3C Trace Context)
1490
+ * @default false
1491
+ */
1492
+ readonly addTraceparent?: boolean;
1493
+ /**
1494
+ * 获取追踪 ID 的函数
1495
+ * 如果未提供,将自动生成
1496
+ */
1497
+ readonly getTraceId?: () => string | undefined;
1498
+ /**
1499
+ * 获取 traceparent 的函数
1500
+ */
1501
+ readonly getTraceparent?: () => string | undefined;
1502
+ /**
1503
+ * 执行顺序
1504
+ * @default -80
1505
+ */
1506
+ readonly order?: number;
1507
+ }
1508
+ /**
1509
+ * 追踪上下文拦截器
1510
+ *
1511
+ * 为请求添加追踪信息,支持分布式追踪
1512
+ */
1513
+ declare class TraceInterceptor implements RequestInterceptor {
1514
+ readonly name = "trace";
1515
+ readonly order: number;
1516
+ private readonly traceIdHeader;
1517
+ private readonly addTraceparent;
1518
+ private readonly getTraceId?;
1519
+ private readonly getTraceparent?;
1520
+ constructor(config?: TraceInterceptorConfig);
1521
+ intercept(context: RequestContext$1): MutableRequestOptions;
1522
+ }
1523
+ /**
1524
+ * 创建追踪拦截器
1525
+ */
1526
+ declare function createTraceInterceptor(config?: TraceInterceptorConfig): TraceInterceptor;
1527
+
1528
+ /**
1529
+ * 超时拦截器
1530
+ *
1531
+ * 根据请求类型自动设置超时时间
1532
+ *
1533
+ * @packageDocumentation
1534
+ */
1535
+
1536
+ /**
1537
+ * 超时拦截器配置
1538
+ */
1539
+ interface TimeoutInterceptorConfig {
1540
+ /**
1541
+ * 默认超时时间(毫秒)
1542
+ * @default 30000
1543
+ */
1544
+ readonly defaultTimeout?: number;
1545
+ /**
1546
+ * 按方法设置超时时间
1547
+ * 例如: { GET: 10000, POST: 60000 }
1548
+ */
1549
+ readonly methodTimeouts?: Partial<Record<HttpMethod, number>>;
1550
+ /**
1551
+ * 按路径模式设置超时时间
1552
+ * 使用正则表达式匹配路径
1553
+ */
1554
+ readonly pathTimeouts?: ReadonlyArray<{
1555
+ pattern: RegExp;
1556
+ timeout: number;
1557
+ }>;
1558
+ /**
1559
+ * 执行顺序
1560
+ * @default -70
1561
+ */
1562
+ readonly order?: number;
1563
+ }
1564
+ /**
1565
+ * 超时拦截器
1566
+ *
1567
+ * 智能设置请求超时时间
1568
+ */
1569
+ declare class TimeoutInterceptor implements RequestInterceptor {
1570
+ readonly name = "timeout";
1571
+ readonly order: number;
1572
+ private readonly defaultTimeout;
1573
+ private readonly methodTimeouts;
1574
+ private readonly pathTimeouts;
1575
+ constructor(config?: TimeoutInterceptorConfig);
1576
+ intercept(context: RequestContext$1): MutableRequestOptions;
1577
+ }
1578
+ /**
1579
+ * 创建超时拦截器
1580
+ */
1581
+ declare function createTimeoutInterceptor(config?: TimeoutInterceptorConfig): TimeoutInterceptor;
1582
+
1583
+ /**
1584
+ * 重试拦截器
1585
+ *
1586
+ * 处理请求失败时的自动重试
1587
+ *
1588
+ * @packageDocumentation
1589
+ */
1590
+
1591
+ /**
1592
+ * 重试拦截器配置
1593
+ */
1594
+ interface RetryInterceptorConfig extends Partial<RetryConfig> {
1595
+ /**
1596
+ * 执行重试请求的函数
1597
+ * 由客户端注入
1598
+ */
1599
+ readonly executeRequest: <T>(context: RequestContext$1) => Promise<ResponseData<T>>;
1600
+ /**
1601
+ * 执行顺序
1602
+ * @default 100 (最后执行)
1603
+ */
1604
+ readonly order?: number;
1605
+ }
1606
+ /**
1607
+ * 重试拦截器
1608
+ *
1609
+ * 在发生可重试错误时自动重试请求
1610
+ *
1611
+ * 注意:这个拦截器应该注册为错误拦截器,而不是响应拦截器
1612
+ */
1613
+ declare class RetryInterceptor implements ErrorInterceptor {
1614
+ readonly name = "retry";
1615
+ readonly order: number;
1616
+ private readonly config;
1617
+ private readonly executeRequest;
1618
+ constructor(config: RetryInterceptorConfig);
1619
+ intercept<T>(error: Error, context: RequestContext$1): Promise<ResponseData<T> | void>;
1620
+ /**
1621
+ * 判断是否应该重试
1622
+ */
1623
+ private shouldRetry;
1624
+ }
1625
+ /**
1626
+ * 创建重试拦截器
1627
+ */
1628
+ declare function createRetryInterceptor(config: RetryInterceptorConfig): RetryInterceptor;
1629
+
1630
+ /**
1631
+ * Token 刷新拦截器
1632
+ *
1633
+ * 在收到 401 响应时自动刷新 Token 并重试
1634
+ *
1635
+ * @packageDocumentation
1636
+ */
1637
+
1638
+ /**
1639
+ * Token 刷新拦截器配置
1640
+ */
1641
+ interface TokenRefreshInterceptorConfig extends TokenRefreshConfig {
1642
+ /**
1643
+ * 执行重试请求的函数
1644
+ * 由客户端注入
1645
+ */
1646
+ readonly executeRequest: <T>(context: RequestContext$1) => Promise<ResponseData<T>>;
1647
+ /**
1648
+ * Token 刷新后的回调
1649
+ * 用于更新存储的 Token
1650
+ */
1651
+ readonly onTokenRefreshed?: (newToken: string) => void;
1652
+ /**
1653
+ * 执行顺序
1654
+ * @default 50 (在重试拦截器之前)
1655
+ */
1656
+ readonly order?: number;
1657
+ }
1658
+ /**
1659
+ * Token 刷新拦截器
1660
+ *
1661
+ * 功能:
1662
+ * 1. 在收到 401 响应时自动刷新 Token
1663
+ * 2. 合并并发的 Token 刷新请求,避免重复刷新
1664
+ * 3. 刷新成功后自动重试原请求
1665
+ * 4. 刷新失败时触发回调
1666
+ */
1667
+ declare class TokenRefreshInterceptor implements ErrorInterceptor {
1668
+ readonly name = "token-refresh";
1669
+ readonly order: number;
1670
+ private readonly refreshToken;
1671
+ private readonly executeRequest;
1672
+ private readonly triggerStatusCodes;
1673
+ private readonly maxRetries;
1674
+ private readonly onTokenRefreshed?;
1675
+ private readonly onRefreshFailed?;
1676
+ private readonly state;
1677
+ constructor(config: TokenRefreshInterceptorConfig);
1678
+ intercept<T>(error: Error, context: RequestContext$1): Promise<ResponseData<T> | void>;
1679
+ /**
1680
+ * 判断是否应该刷新 Token
1681
+ */
1682
+ private shouldRefresh;
1683
+ /**
1684
+ * 执行 Token 刷新
1685
+ *
1686
+ * 合并并发请求,确保同一时间只有一个刷新请求
1687
+ */
1688
+ private doRefresh;
1689
+ /**
1690
+ * 重置状态(用于测试或手动重置)
1691
+ */
1692
+ reset(): void;
1693
+ }
1694
+ /**
1695
+ * 创建 Token 刷新拦截器
1696
+ */
1697
+ declare function createTokenRefreshInterceptor(config: TokenRefreshInterceptorConfig): TokenRefreshInterceptor;
1698
+
1699
+ /**
1700
+ * 错误转换拦截器
1701
+ *
1702
+ * 将原始响应错误转换为结构化的错误对象
1703
+ *
1704
+ * @packageDocumentation
1705
+ */
1706
+
1707
+ /**
1708
+ * 错误转换拦截器配置
1709
+ */
1710
+ interface ErrorTransformInterceptorConfig {
1711
+ /**
1712
+ * 是否在响应中包含原始数据
1713
+ * @default false
1714
+ */
1715
+ readonly includeRawResponse?: boolean;
1716
+ /**
1717
+ * 自定义错误消息提取函数
1718
+ */
1719
+ readonly extractErrorMessage?: (data: unknown) => string | undefined;
1720
+ /**
1721
+ * 自定义错误码提取函数
1722
+ */
1723
+ readonly extractErrorCode?: (data: unknown) => string | undefined;
1724
+ /**
1725
+ * 执行顺序
1726
+ * @default 0
1727
+ */
1728
+ readonly order?: number;
1729
+ }
1730
+ /**
1731
+ * 错误转换拦截器
1732
+ *
1733
+ * 处理响应数据,提取错误信息
1734
+ * 注意:这个拦截器主要用于标准化响应格式
1735
+ */
1736
+ declare class ErrorTransformInterceptor implements ResponseInterceptor {
1737
+ readonly name = "error-transform";
1738
+ readonly order: number;
1739
+ private readonly includeRawResponse;
1740
+ private readonly extractErrorMessage?;
1741
+ private readonly extractErrorCode?;
1742
+ constructor(config?: ErrorTransformInterceptorConfig);
1743
+ intercept<T>(response: ResponseData<T>, _context: RequestContext$1): ResponseData<T>;
1744
+ }
1745
+ /**
1746
+ * 创建错误转换拦截器
1747
+ */
1748
+ declare function createErrorTransformInterceptor(config?: ErrorTransformInterceptorConfig): ErrorTransformInterceptor;
1749
+
1750
+ /**
1751
+ * 错误日志拦截器
1752
+ *
1753
+ * 记录所有请求错误
1754
+ *
1755
+ * @packageDocumentation
1756
+ */
1757
+
1758
+ /**
1759
+ * 错误日志拦截器配置
1760
+ */
1761
+ interface LoggingInterceptorConfig {
1762
+ /**
1763
+ * 日志器
1764
+ */
1765
+ readonly logger: Logger;
1766
+ /**
1767
+ * 是否记录详细信息(包括请求体、响应体等)
1768
+ * @default false
1769
+ */
1770
+ readonly verbose?: boolean;
1771
+ /**
1772
+ * 是否记录取消的请求
1773
+ * @default false
1774
+ */
1775
+ readonly logAborted?: boolean;
1776
+ /**
1777
+ * 错误过滤器
1778
+ * 返回 true 表示记录该错误
1779
+ */
1780
+ readonly filter?: (error: Error, context: RequestContext$1) => boolean;
1781
+ /**
1782
+ * 执行顺序
1783
+ * @default -100 (优先执行,确保先记录日志)
1784
+ */
1785
+ readonly order?: number;
1786
+ }
1787
+ /**
1788
+ * 错误日志拦截器
1789
+ *
1790
+ * 记录错误信息用于调试和监控
1791
+ */
1792
+ declare class LoggingInterceptor implements ErrorInterceptor {
1793
+ readonly name = "logging";
1794
+ readonly order: number;
1795
+ private readonly logger;
1796
+ private readonly verbose;
1797
+ private readonly logAborted;
1798
+ private readonly filter?;
1799
+ constructor(config: LoggingInterceptorConfig);
1800
+ intercept<T>(error: Error, context: RequestContext$1): void | ResponseData<T>;
1801
+ /**
1802
+ * 构建日志信息
1803
+ */
1804
+ private buildLogInfo;
1805
+ }
1806
+ /**
1807
+ * 创建错误日志拦截器
1808
+ */
1809
+ declare function createLoggingInterceptor(config: LoggingInterceptorConfig): LoggingInterceptor;
1810
+
1811
+ /**
1812
+ * 错误上报拦截器
1813
+ *
1814
+ * 将错误上报到监控系统(如 Sentry)
1815
+ *
1816
+ * @packageDocumentation
1817
+ */
1818
+
1819
+ /**
1820
+ * 错误上报器接口
1821
+ */
1822
+ interface ErrorReporter {
1823
+ /**
1824
+ * 上报错误
1825
+ *
1826
+ * @param error - 错误对象
1827
+ * @param context - 错误上下文
1828
+ */
1829
+ report(error: Error, context: Record<string, unknown>): void;
1830
+ }
1831
+ /**
1832
+ * 错误严重程度
1833
+ */
1834
+ type ErrorSeverity = 'fatal' | 'error' | 'warning' | 'info' | 'debug';
1835
+ /**
1836
+ * 错误上报拦截器配置
1837
+ */
1838
+ interface ReportingInterceptorConfig {
1839
+ /**
1840
+ * 错误上报器
1841
+ */
1842
+ readonly reporter: ErrorReporter;
1843
+ /**
1844
+ * 获取错误严重程度
1845
+ * @default 根据错误类型自动判断
1846
+ */
1847
+ readonly getSeverity?: (error: Error) => ErrorSeverity;
1848
+ /**
1849
+ * 是否上报客户端错误(4xx)
1850
+ * @default false
1851
+ */
1852
+ readonly reportClientErrors?: boolean;
1853
+ /**
1854
+ * 是否上报取消的请求
1855
+ * @default false
1856
+ */
1857
+ readonly reportAborted?: boolean;
1858
+ /**
1859
+ * 是否上报网络错误
1860
+ * @default true
1861
+ */
1862
+ readonly reportNetworkErrors?: boolean;
1863
+ /**
1864
+ * 采样率(0-1)
1865
+ * 用于减少上报量
1866
+ * @default 1 (100% 上报)
1867
+ */
1868
+ readonly sampleRate?: number;
1869
+ /**
1870
+ * 自定义上下文提取器
1871
+ */
1872
+ readonly extractContext?: (error: Error, context: RequestContext$1) => Record<string, unknown>;
1873
+ /**
1874
+ * 执行顺序
1875
+ * @default -50 (在日志之后)
1876
+ */
1877
+ readonly order?: number;
1878
+ }
1879
+ /**
1880
+ * 错误上报拦截器
1881
+ *
1882
+ * 将错误上报到外部监控系统
1883
+ */
1884
+ declare class ReportingInterceptor implements ErrorInterceptor {
1885
+ readonly name = "reporting";
1886
+ readonly order: number;
1887
+ private readonly reporter;
1888
+ private readonly getSeverity;
1889
+ private readonly reportClientErrors;
1890
+ private readonly reportAborted;
1891
+ private readonly reportNetworkErrors;
1892
+ private readonly sampleRate;
1893
+ private readonly extractContext?;
1894
+ constructor(config: ReportingInterceptorConfig);
1895
+ intercept<T>(error: Error, context: RequestContext$1): void | ResponseData<T>;
1896
+ /**
1897
+ * 判断是否应该上报
1898
+ */
1899
+ private shouldReport;
1900
+ /**
1901
+ * 构建上报上下文
1902
+ */
1903
+ private buildReportContext;
1904
+ /**
1905
+ * 默认的严重程度判断
1906
+ */
1907
+ private defaultGetSeverity;
1908
+ }
1909
+ /**
1910
+ * 创建错误上报拦截器
1911
+ */
1912
+ declare function createReportingInterceptor(config: ReportingInterceptorConfig): ReportingInterceptor;
1913
+
1914
+ /**
1915
+ * 请求去重插件
1916
+ *
1917
+ * 避免相同请求并发执行多次
1918
+ *
1919
+ * @packageDocumentation
1920
+ */
1921
+ /**
1922
+ * 请求去重器配置
1923
+ */
1924
+ interface DeduplicationConfig {
1925
+ /**
1926
+ * 是否只对 GET 请求去重
1927
+ * @default true
1928
+ */
1929
+ readonly getOnly?: boolean;
1930
+ /**
1931
+ * 自定义请求键生成函数
1932
+ * 默认使用 method + url
1933
+ */
1934
+ readonly generateKey?: (method: string, url: string) => string;
1935
+ /**
1936
+ * 最大缓存数量
1937
+ * @default 100
1938
+ */
1939
+ readonly maxSize?: number;
1940
+ }
1941
+ /**
1942
+ * 请求去重器
1943
+ *
1944
+ * 功能:
1945
+ * 1. 相同的并发请求只执行一次
1946
+ * 2. 结果共享给所有等待者
1947
+ * 3. 请求完成后自动清理
1948
+ */
1949
+ declare class RequestDeduper {
1950
+ private readonly getOnly;
1951
+ private readonly generateKey;
1952
+ private readonly maxSize;
1953
+ private readonly inflightRequests;
1954
+ constructor(config?: DeduplicationConfig);
1955
+ /**
1956
+ * 执行请求(带去重)
1957
+ *
1958
+ * @param method - HTTP 方法
1959
+ * @param url - 请求 URL
1960
+ * @param execute - 实际执行请求的函数
1961
+ * @returns 请求结果
1962
+ */
1963
+ execute<T>(method: string, url: string, execute: () => Promise<T>): Promise<T>;
1964
+ /**
1965
+ * 包装 fetch 函数
1966
+ *
1967
+ * @param fetch - 原始 fetch 函数
1968
+ * @returns 去重的 fetch 函数
1969
+ */
1970
+ wrap(fetch: (url: string, init?: RequestInit) => Promise<Response>): (url: string, init?: RequestInit) => Promise<Response>;
1971
+ /**
1972
+ * 获取当前飞行中的请求数量
1973
+ */
1974
+ get inflightCount(): number;
1975
+ /**
1976
+ * 清空所有飞行中的请求
1977
+ */
1978
+ clear(): void;
1979
+ /**
1980
+ * 判断是否应该去重
1981
+ */
1982
+ private shouldDeduplicate;
1983
+ /**
1984
+ * 默认的键生成函数
1985
+ */
1986
+ private defaultGenerateKey;
1987
+ /**
1988
+ * 清理过期的请求
1989
+ */
1990
+ private cleanup;
1991
+ }
1992
+ /**
1993
+ * 创建请求去重器
1994
+ */
1995
+ declare function createRequestDeduper(config?: DeduplicationConfig): RequestDeduper;
1996
+
1997
+ /**
1998
+ * 指标收集插件
1999
+ *
2000
+ * 收集请求级别的性能指标
2001
+ *
2002
+ * @packageDocumentation
2003
+ */
2004
+
2005
+ /**
2006
+ * 默认指标收集器实现
2007
+ */
2008
+ declare class DefaultMetricsCollector implements MetricsCollector {
2009
+ private metrics;
2010
+ private readonly maxMetrics;
2011
+ private readonly ttlMs;
2012
+ private readonly onMetrics?;
2013
+ constructor(config?: MetricsCollectorConfig);
2014
+ record(metrics: RequestMetrics): void;
2015
+ summary(): MetricsSummary;
2016
+ getAll(): readonly RequestMetrics[];
2017
+ getByPath(path: string): readonly RequestMetrics[];
2018
+ flush(): readonly RequestMetrics[];
2019
+ clear(): void;
2020
+ private cleanup;
2021
+ private emptySummary;
2022
+ }
2023
+ /**
2024
+ * 创建指标收集器
2025
+ */
2026
+ declare function createMetricsCollector(config?: MetricsCollectorConfig): MetricsCollector;
2027
+ /**
2028
+ * 指标请求拦截器
2029
+ *
2030
+ * 在请求开始时记录时间戳
2031
+ */
2032
+ declare class MetricsRequestInterceptor implements RequestInterceptor {
2033
+ readonly name = "metrics-request";
2034
+ readonly order = -1000;
2035
+ intercept(context: RequestContext$1): MutableRequestOptions;
2036
+ }
2037
+ /**
2038
+ * 指标响应拦截器
2039
+ *
2040
+ * 在请求成功时记录指标
2041
+ */
2042
+ declare class MetricsResponseInterceptor implements ResponseInterceptor {
2043
+ private readonly collector;
2044
+ readonly name = "metrics-response";
2045
+ readonly order = 1000;
2046
+ constructor(collector: MetricsCollector);
2047
+ intercept<T>(response: ResponseData<T>, context: RequestContext$1): ResponseData<T>;
2048
+ }
2049
+ /**
2050
+ * 指标错误拦截器
2051
+ *
2052
+ * 在请求失败时记录指标
2053
+ */
2054
+ declare class MetricsErrorInterceptor implements ErrorInterceptor {
2055
+ private readonly collector;
2056
+ readonly name = "metrics-error";
2057
+ readonly order = 1000;
2058
+ constructor(collector: MetricsCollector);
2059
+ intercept<T>(error: Error, context: RequestContext$1): void | ResponseData<T>;
2060
+ }
2061
+ /**
2062
+ * 创建指标拦截器集合
2063
+ */
2064
+ declare function createMetricsInterceptors(collector: MetricsCollector): {
2065
+ request: MetricsRequestInterceptor;
2066
+ response: MetricsResponseInterceptor;
2067
+ error: MetricsErrorInterceptor;
2068
+ };
2069
+
2070
+ /**
2071
+ * 日志插件
2072
+ *
2073
+ * 提供可配置的日志器实现
2074
+ *
2075
+ * @packageDocumentation
2076
+ */
2077
+
2078
+ /**
2079
+ * 控制台日志器
2080
+ *
2081
+ * 将日志输出到控制台
2082
+ */
2083
+ declare class ConsoleLogger implements Logger {
2084
+ private readonly prefix;
2085
+ private readonly level;
2086
+ private readonly timestamp;
2087
+ private readonly levelPriority;
2088
+ constructor(config?: ConsoleLoggerConfig);
2089
+ debug(message: string, ...args: unknown[]): void;
2090
+ info(message: string, ...args: unknown[]): void;
2091
+ warn(message: string, ...args: unknown[]): void;
2092
+ error(message: string, ...args: unknown[]): void;
2093
+ private log;
2094
+ private formatMessage;
2095
+ }
2096
+ /**
2097
+ * 创建控制台日志器
2098
+ */
2099
+ declare function createConsoleLogger(config?: ConsoleLoggerConfig): ConsoleLogger;
2100
+ /**
2101
+ * 静默日志器
2102
+ *
2103
+ * 不输出任何日志
2104
+ */
2105
+ declare class SilentLogger implements Logger {
2106
+ debug(_message: string, ..._args: unknown[]): void;
2107
+ info(_message: string, ..._args: unknown[]): void;
2108
+ warn(_message: string, ..._args: unknown[]): void;
2109
+ error(_message: string, ..._args: unknown[]): void;
2110
+ }
2111
+ /**
2112
+ * 创建静默日志器
2113
+ */
2114
+ declare function createSilentLogger(): SilentLogger;
2115
+ /**
2116
+ * 静默日志器单例
2117
+ */
2118
+ declare const silentLogger: SilentLogger;
2119
+ /**
2120
+ * 缓冲日志器
2121
+ *
2122
+ * 将日志存储在内存中,用于测试
2123
+ */
2124
+ declare class BufferLogger implements Logger {
2125
+ private readonly buffer;
2126
+ private readonly maxSize;
2127
+ constructor(maxSize?: number);
2128
+ debug(message: string, ...args: unknown[]): void;
2129
+ info(message: string, ...args: unknown[]): void;
2130
+ warn(message: string, ...args: unknown[]): void;
2131
+ error(message: string, ...args: unknown[]): void;
2132
+ /**
2133
+ * 获取所有日志
2134
+ */
2135
+ getLogs(): ReadonlyArray<{
2136
+ level: LogLevel;
2137
+ message: string;
2138
+ args: unknown[];
2139
+ timestamp: Date;
2140
+ }>;
2141
+ /**
2142
+ * 获取指定级别的日志
2143
+ */
2144
+ getLogsByLevel(level: LogLevel): ReadonlyArray<{
2145
+ level: LogLevel;
2146
+ message: string;
2147
+ args: unknown[];
2148
+ timestamp: Date;
2149
+ }>;
2150
+ /**
2151
+ * 清空日志
2152
+ */
2153
+ clear(): void;
2154
+ /**
2155
+ * 获取日志数量
2156
+ */
2157
+ get size(): number;
2158
+ private add;
2159
+ }
2160
+ /**
2161
+ * 创建缓冲日志器
2162
+ */
2163
+ declare function createBufferLogger(maxSize?: number): BufferLogger;
2164
+
2165
+ /**
2166
+ * 基础客户端抽象类
2167
+ *
2168
+ * 定义 HTTP 客户端的基本接口和生命周期
2169
+ *
2170
+ * @packageDocumentation
2171
+ */
2172
+
2173
+ /**
2174
+ * 基础客户端抽象类
2175
+ *
2176
+ * 提供:
2177
+ * 1. 配置管理
2178
+ * 2. 拦截器管理
2179
+ * 3. 认证管理
2180
+ * 4. 请求上下文创建
2181
+ */
2182
+ declare abstract class BaseClient {
2183
+ protected readonly config: ClientConfig;
2184
+ protected readonly interceptorManager: InterceptorManager;
2185
+ protected readonly authenticator: Authenticator;
2186
+ constructor(config: ClientConfig);
2187
+ /**
2188
+ * 发起请求(子类实现)
2189
+ */
2190
+ abstract request<T>(options: RequestOptions): Promise<T>;
2191
+ /**
2192
+ * GET 请求
2193
+ */
2194
+ get<T>(path: string, query?: Record<string, string | number | boolean | undefined | null>): Promise<T>;
2195
+ /**
2196
+ * POST 请求
2197
+ */
2198
+ post<T>(path: string, body?: unknown, query?: Record<string, string | number | boolean | undefined | null>): Promise<T>;
2199
+ /**
2200
+ * PUT 请求
2201
+ */
2202
+ put<T>(path: string, body?: unknown): Promise<T>;
2203
+ /**
2204
+ * PATCH 请求
2205
+ */
2206
+ patch<T>(path: string, body?: unknown): Promise<T>;
2207
+ /**
2208
+ * DELETE 请求
2209
+ */
2210
+ delete<T>(path: string): Promise<T>;
2211
+ /**
2212
+ * 获取拦截器管理器
2213
+ */
2214
+ get interceptors(): InterceptorManager;
2215
+ /**
2216
+ * 创建请求上下文
2217
+ */
2218
+ protected createRequestContext(options: RequestOptions): RequestContext$1;
2219
+ /**
2220
+ * 执行请求拦截器
2221
+ */
2222
+ protected runRequestInterceptors(context: RequestContext$1): Promise<MutableRequestOptions>;
2223
+ /**
2224
+ * 执行响应拦截器
2225
+ */
2226
+ protected runResponseInterceptors<T>(response: ResponseData<T>, context: RequestContext$1): Promise<ResponseData<T>>;
2227
+ /**
2228
+ * 执行错误拦截器
2229
+ */
2230
+ protected runErrorInterceptors<T>(error: Error, context: RequestContext$1): Promise<ResponseData<T> | void>;
2231
+ /**
2232
+ * 注册配置中的拦截器
2233
+ */
2234
+ private registerConfigInterceptors;
2235
+ }
2236
+
2237
+ /**
2238
+ * Fetch 客户端实现
2239
+ *
2240
+ * 基于原生 fetch API 的 HTTP 客户端
2241
+ *
2242
+ * @packageDocumentation
2243
+ */
2244
+
2245
+ /**
2246
+ * Fetch 客户端配置
2247
+ */
2248
+ interface FetchClientConfig extends ClientConfig {
2249
+ /**
2250
+ * 是否启用自动重试
2251
+ * @default true
2252
+ */
2253
+ readonly enableRetry?: boolean;
2254
+ }
2255
+ /**
2256
+ * Fetch 客户端
2257
+ *
2258
+ * 特点:
2259
+ * 1. 基于原生 fetch API
2260
+ * 2. 支持完整的拦截器链
2261
+ * 3. 自动错误转换
2262
+ * 4. 超时和取消支持
2263
+ * 5. 自动重试
2264
+ * 6. 调试日志
2265
+ */
2266
+ declare class FetchClient extends BaseClient {
2267
+ private readonly enableRetry;
2268
+ constructor(config: FetchClientConfig);
2269
+ /**
2270
+ * 发起请求
2271
+ */
2272
+ request<T>(options: RequestOptions): Promise<T>;
2273
+ /**
2274
+ * 带重试的请求执行
2275
+ */
2276
+ private executeWithRetry;
2277
+ /**
2278
+ * 判断是否应该重试
2279
+ */
2280
+ private shouldRetry;
2281
+ /**
2282
+ * 执行单次请求
2283
+ */
2284
+ private executeRequest;
2285
+ /**
2286
+ * 构建完整 URL
2287
+ */
2288
+ private buildFullUrl;
2289
+ /**
2290
+ * 构建 fetch init 对象
2291
+ */
2292
+ private buildFetchInit;
2293
+ /**
2294
+ * 创建超时信号
2295
+ */
2296
+ private createTimeoutSignal;
2297
+ /**
2298
+ * 解析响应
2299
+ */
2300
+ private parseResponse;
2301
+ /**
2302
+ * 转换错误
2303
+ */
2304
+ private transformError;
2305
+ /**
2306
+ * 调试日志
2307
+ */
2308
+ private logDebug;
2309
+ /**
2310
+ * 错误日志
2311
+ */
2312
+ private logError;
2313
+ }
2314
+ /**
2315
+ * 创建 Fetch 客户端
2316
+ */
2317
+ declare function createFetchClient(config: FetchClientConfig): FetchClient;
2318
+
2319
+ /**
2320
+ * Axios 客户端实现
2321
+ *
2322
+ * 基于 Axios 的 HTTP 客户端,用于与 openapi-generator 生成的代码集成
2323
+ *
2324
+ * @packageDocumentation
2325
+ */
2326
+
2327
+ declare module 'axios' {
2328
+ interface InternalAxiosRequestConfig {
2329
+ __retryCount?: number;
2330
+ __startTime?: number;
2331
+ __requestId?: string;
2332
+ __traceId?: string;
2333
+ }
2334
+ }
2335
+ /**
2336
+ * Axios 客户端配置
2337
+ *
2338
+ * 继承 ClientConfig 并添加 Axios 特有的选项
2339
+ */
2340
+ interface AxiosClientConfig extends ClientConfig {
2341
+ /**
2342
+ * 是否启用自动重试
2343
+ * @default true
2344
+ */
2345
+ readonly enableRetry?: boolean;
2346
+ }
2347
+ /**
2348
+ * 创建配置好的 Axios 实例
2349
+ *
2350
+ * 用于注入到 openapi-generator 生成的 API 类中
2351
+ *
2352
+ * @example
2353
+ * ```typescript
2354
+ * import { createAxiosInstance, createConsoleLogger } from '@djvlc/openapi-client-core';
2355
+ * import { PagesApi, Configuration } from './generated';
2356
+ *
2357
+ * const axiosInstance = createAxiosInstance({
2358
+ * baseUrl: '/api/admin',
2359
+ * auth: { type: 'bearer', getToken: () => localStorage.getItem('token') },
2360
+ * retry: { maxRetries: 2, initialDelayMs: 1000, maxDelayMs: 10000, backoff: 'exponential' },
2361
+ * logger: createConsoleLogger({ prefix: '[Admin API]' }),
2362
+ * debug: true,
2363
+ * });
2364
+ *
2365
+ * const config = new Configuration();
2366
+ * const pagesApi = new PagesApi(config, undefined, axiosInstance);
2367
+ * ```
2368
+ */
2369
+ declare function createAxiosInstance(config: AxiosClientConfig): AxiosInstance;
2370
+
2371
+ /**
2372
+ * Middleware 工厂
2373
+ *
2374
+ * 将 openapi-client-core 的功能转换为 typescript-fetch 生成代码的 Middleware 格式
2375
+ *
2376
+ * 生成代码的 Middleware 接口:
2377
+ * - pre(context): 发请求前,可修改 url/init
2378
+ * - post(context): 收到响应后,可读/替换 Response
2379
+ * - onError(context): 网络错误时,可吞掉错误并返回兜底 Response
2380
+ *
2381
+ * @packageDocumentation
2382
+ */
2383
+
2384
+ /**
2385
+ * FetchAPI 类型(与生成代码兼容)
2386
+ */
2387
+ type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
2388
+ /**
2389
+ * 请求上下文(生成代码格式)
2390
+ */
2391
+ interface RequestContext {
2392
+ fetch: FetchAPI;
2393
+ url: string;
2394
+ init: RequestInit;
2395
+ }
2396
+ /**
2397
+ * 响应上下文(生成代码格式)
2398
+ */
2399
+ interface ResponseContext {
2400
+ fetch: FetchAPI;
2401
+ url: string;
2402
+ init: RequestInit;
2403
+ response: Response;
2404
+ }
2405
+ /**
2406
+ * 错误上下文(生成代码格式)
2407
+ */
2408
+ interface ErrorContext {
2409
+ fetch: FetchAPI;
2410
+ url: string;
2411
+ init: RequestInit;
2412
+ error: unknown;
2413
+ response?: Response;
2414
+ }
2415
+ /**
2416
+ * Fetch 参数
2417
+ */
2418
+ interface FetchParams {
2419
+ url: string;
2420
+ init: RequestInit;
2421
+ }
2422
+ /**
2423
+ * Middleware 接口(与生成代码兼容)
2424
+ */
2425
+ interface Middleware {
2426
+ pre?(context: RequestContext): Promise<FetchParams | void>;
2427
+ post?(context: ResponseContext): Promise<Response | void>;
2428
+ onError?(context: ErrorContext): Promise<Response | void>;
2429
+ }
2430
+ /**
2431
+ * Middleware 工厂配置
2432
+ */
2433
+ interface MiddlewareConfig {
2434
+ /** 认证配置 */
2435
+ auth?: AuthConfig;
2436
+ /** 重试配置 */
2437
+ retry?: RetryConfig;
2438
+ /** 是否启用重试 */
2439
+ enableRetry?: boolean;
2440
+ /** 日志器 */
2441
+ logger?: Logger;
2442
+ /** 是否开启调试模式 */
2443
+ debug?: boolean;
2444
+ /** 超时时间(毫秒) */
2445
+ timeout?: number;
2446
+ /** 额外的请求头 */
2447
+ headers?: Record<string, string>;
2448
+ /** 自定义 pre 中间件 */
2449
+ preMiddlewares?: Array<(context: RequestContext) => Promise<FetchParams | void>>;
2450
+ /** 自定义 post 中间件 */
2451
+ postMiddlewares?: Array<(context: ResponseContext) => Promise<Response | void>>;
2452
+ /** 自定义 onError 中间件 */
2453
+ errorMiddlewares?: Array<(context: ErrorContext) => Promise<Response | void>>;
2454
+ }
2455
+ /**
2456
+ * 创建 Middleware 数组
2457
+ *
2458
+ * 将 openapi-client-core 的功能转换为生成代码兼容的 Middleware 格式
2459
+ *
2460
+ * @param config - 配置选项
2461
+ * @returns Middleware 数组,可直接传给 Configuration
2462
+ *
2463
+ * @example
2464
+ * ```typescript
2465
+ * import { createMiddlewares, createConsoleLogger } from '@djvlc/openapi-client-core';
2466
+ * import { Configuration, PagesApi } from '@djvlc/openapi-admin-client';
2467
+ *
2468
+ * const middlewares = createMiddlewares({
2469
+ * auth: { type: 'bearer', getToken: () => token },
2470
+ * retry: { maxRetries: 3, backoffStrategy: 'exponential' },
2471
+ * logger: createConsoleLogger({ prefix: '[API]' }),
2472
+ * debug: true,
2473
+ * });
2474
+ *
2475
+ * const config = new Configuration({
2476
+ * basePath: '/api/admin',
2477
+ * middleware: middlewares,
2478
+ * });
2479
+ *
2480
+ * const api = new PagesApi(config);
2481
+ * ```
2482
+ */
2483
+ declare function createMiddlewares(config?: MiddlewareConfig): Middleware[];
2484
+ /**
2485
+ * 创建认证中间件
2486
+ */
2487
+ declare function createAuthMiddleware(authConfig: AuthConfig): Middleware;
2488
+ /**
2489
+ * 创建请求追踪中间件
2490
+ */
2491
+ declare function createTrackingMiddleware(): Middleware;
2492
+
2493
+ /**
2494
+ * 请求 ID 生成工具
2495
+ *
2496
+ * @packageDocumentation
2497
+ */
2498
+ /**
2499
+ * 生成请求 ID
2500
+ *
2501
+ * 格式: req_{timestamp}_{random}
2502
+ * 例如: req_m5abc123_k7def456
2503
+ *
2504
+ * @returns 唯一的请求 ID
2505
+ */
2506
+ declare function generateRequestId(): string;
2507
+ /**
2508
+ * 生成追踪 ID
2509
+ *
2510
+ * 格式: trace_{timestamp}_{random}_{random}
2511
+ * 例如: trace_m5abc123_k7def456_x8ghi789
2512
+ *
2513
+ * @returns 唯一的追踪 ID
2514
+ */
2515
+ declare function generateTraceId(): string;
2516
+ /**
2517
+ * 验证请求 ID 格式
2518
+ *
2519
+ * @param id - 待验证的 ID
2520
+ * @returns 是否为有效的请求 ID
2521
+ */
2522
+ declare function isValidRequestId(id: string): boolean;
2523
+ /**
2524
+ * 验证追踪 ID 格式
2525
+ *
2526
+ * @param id - 待验证的 ID
2527
+ * @returns 是否为有效的追踪 ID
2528
+ */
2529
+ declare function isValidTraceId(id: string): boolean;
2530
+
2531
+ /**
2532
+ * 重试延迟计算工具
2533
+ *
2534
+ * @packageDocumentation
2535
+ */
2536
+
2537
+ /**
2538
+ * 计算重试延迟(毫秒)
2539
+ *
2540
+ * @param config - 重试配置
2541
+ * @param attempt - 当前重试次数(从 0 开始)
2542
+ * @returns 延迟时间(毫秒)
2543
+ */
2544
+ declare function calculateRetryDelay(config: RetryConfig, attempt: number): number;
2545
+ /**
2546
+ * 解析 Retry-After 响应头
2547
+ *
2548
+ * 支持两种格式:
2549
+ * 1. 秒数: "120"
2550
+ * 2. HTTP 日期: "Wed, 21 Oct 2015 07:28:00 GMT"
2551
+ *
2552
+ * @param retryAfter - Retry-After 头的值
2553
+ * @returns 延迟时间(秒),如果解析失败则返回 undefined
2554
+ */
2555
+ declare function parseRetryAfter(retryAfter: string | null | undefined): number | undefined;
2556
+ /**
2557
+ * 获取推荐的重试延迟
2558
+ *
2559
+ * 优先使用 Retry-After 头的值
2560
+ *
2561
+ * @param config - 重试配置
2562
+ * @param attempt - 当前重试次数
2563
+ * @param retryAfterSeconds - Retry-After 头的值(秒)
2564
+ * @returns 延迟时间(毫秒)
2565
+ */
2566
+ declare function getRecommendedRetryDelay(config: RetryConfig, attempt: number, retryAfterSeconds?: number): number;
2567
+
2568
+ /**
2569
+ * 延迟执行工具
2570
+ *
2571
+ * @packageDocumentation
2572
+ */
2573
+ /**
2574
+ * 延迟执行
2575
+ *
2576
+ * @param ms - 延迟时间(毫秒)
2577
+ * @returns Promise,在指定时间后 resolve
2578
+ */
2579
+ declare function sleep(ms: number): Promise<void>;
2580
+ /**
2581
+ * 可取消的延迟执行
2582
+ *
2583
+ * @param ms - 延迟时间(毫秒)
2584
+ * @param signal - AbortSignal,用于取消延迟
2585
+ * @returns Promise,在指定时间后 resolve,或在取消时 reject
2586
+ */
2587
+ declare function sleepWithAbort(ms: number, signal?: AbortSignal): Promise<void>;
2588
+
2589
+ /**
2590
+ * URL 处理工具
2591
+ *
2592
+ * @packageDocumentation
2593
+ */
2594
+ /**
2595
+ * 查询参数值类型
2596
+ */
2597
+ type QueryParamValue = string | number | boolean | undefined | null;
2598
+ /**
2599
+ * 查询参数对象类型
2600
+ */
2601
+ type QueryParams = Record<string, QueryParamValue>;
2602
+ /**
2603
+ * 构建完整 URL
2604
+ *
2605
+ * @param baseUrl - 基础 URL
2606
+ * @param path - 路径
2607
+ * @param query - 查询参数
2608
+ * @returns 完整 URL
2609
+ */
2610
+ declare function buildUrl(baseUrl: string, path: string, query?: QueryParams): string;
2611
+ /**
2612
+ * 从 URL 提取路径(不含查询参数)
2613
+ *
2614
+ * @param url - 完整 URL
2615
+ * @returns 路径
2616
+ */
2617
+ declare function extractPath(url: string): string;
2618
+ /**
2619
+ * 解析查询字符串
2620
+ *
2621
+ * @param queryString - 查询字符串(可以包含或不包含 ?)
2622
+ * @returns 解析后的参数对象
2623
+ */
2624
+ declare function parseQueryString(queryString: string): Record<string, string>;
2625
+ /**
2626
+ * 合并两个 URL 路径
2627
+ *
2628
+ * @param base - 基础路径
2629
+ * @param path - 要追加的路径
2630
+ * @returns 合并后的路径
2631
+ */
2632
+ declare function joinPaths(base: string, path: string): string;
2633
+
2634
+ /**
2635
+ * 请求头处理工具
2636
+ *
2637
+ * @packageDocumentation
2638
+ */
2639
+ /**
2640
+ * 默认请求头
2641
+ */
2642
+ declare const DEFAULT_HEADERS: Readonly<Record<string, string>>;
2643
+ /**
2644
+ * 合并请求头
2645
+ *
2646
+ * 后面的头会覆盖前面的同名头(大小写不敏感)
2647
+ *
2648
+ * @param headersList - 要合并的请求头列表
2649
+ * @returns 合并后的请求头
2650
+ */
2651
+ declare function mergeHeaders(...headersList: (Record<string, string> | undefined)[]): Record<string, string>;
2652
+ /**
2653
+ * 获取请求头值(大小写不敏感)
2654
+ *
2655
+ * @param headers - 请求头对象
2656
+ * @param name - 头名称
2657
+ * @returns 头的值,不存在则返回 undefined
2658
+ */
2659
+ declare function getHeader(headers: Record<string, string>, name: string): string | undefined;
2660
+ /**
2661
+ * 设置请求头(大小写不敏感,会替换同名头)
2662
+ *
2663
+ * @param headers - 请求头对象(会被修改)
2664
+ * @param name - 头名称
2665
+ * @param value - 头的值
2666
+ */
2667
+ declare function setHeader(headers: Record<string, string>, name: string, value: string): void;
2668
+ /**
2669
+ * 删除请求头(大小写不敏感)
2670
+ *
2671
+ * @param headers - 请求头对象(会被修改)
2672
+ * @param name - 头名称
2673
+ * @returns 是否删除成功
2674
+ */
2675
+ declare function removeHeader(headers: Record<string, string>, name: string): boolean;
2676
+ /**
2677
+ * 从 Response 对象提取请求头
2678
+ *
2679
+ * @param response - Response 对象
2680
+ * @returns 请求头对象
2681
+ */
2682
+ declare function extractResponseHeaders(response: Response): Record<string, string>;
2683
+ /**
2684
+ * 检查是否包含指定的 Content-Type
2685
+ *
2686
+ * @param headers - 请求头对象
2687
+ * @param contentType - 要检查的内容类型
2688
+ * @returns 是否匹配
2689
+ */
2690
+ declare function hasContentType(headers: Record<string, string>, contentType: string): boolean;
2691
+
2692
+ /**
2693
+ * @djvlc/openapi-client-core
2694
+ *
2695
+ * OpenAPI 客户端公共运行时
2696
+ *
2697
+ * 提供模块化的 HTTP 客户端能力:
2698
+ * - 类型定义(types/)
2699
+ * - 错误处理(errors/)
2700
+ * - 认证(auth/)
2701
+ * - 拦截器(interceptors/)
2702
+ * - 插件(plugins/)
2703
+ * - 客户端(clients/)
2704
+ * - 工具函数(utils/)
2705
+ *
2706
+ * @packageDocumentation
2707
+ */
2708
+ declare const VERSION = "2.0.0";
2709
+ declare const SDK_NAME = "@djvlc/openapi-client-core";
2710
+ /**
2711
+ * 获取 SDK 信息
2712
+ */
2713
+ declare function getSdkInfo(): {
2714
+ name: string;
2715
+ version: string;
2716
+ };
273
2717
 
274
- export { ApiError, type AuthConfig, type ClientConfig, type ErrorInterceptor, HttpClient, NetworkError, type RequestInterceptor, type RequestOptions, type ResponseInterceptor, type RetryConfig, TimeoutError, VERSION, calculateRetryDelay, createAxiosInstance, createClient, generateRequestId, sleep };
2718
+ export { AbortError, ApiError, type ApiErrorConfig, type ApiErrorDetail, type ApiKeyAuthConfig, ApiKeyAuthenticator, type AuthConfig, AuthInterceptor, type AuthInterceptorConfig, type AuthType, type Authenticator, type AuthenticatorFactory, type AxiosClientConfig, type BackoffStrategy, BaseClient, BaseClientError, type BasicAuthConfig, BasicAuthenticator, type BearerAuthConfig, BearerAuthenticator, BufferLogger, type ClientConfig, ConsoleLogger, type ConsoleLoggerConfig, type CustomAuthConfig, CustomAuthenticator, DEFAULT_HEADERS, DEFAULT_RETRY_CONFIG, type DeduplicationConfig, DefaultMetricsCollector, type ErrorInterceptor, type ErrorInterceptorFactory, type ErrorReporter, type ErrorSeverity, ErrorTransformInterceptor, type ErrorTransformInterceptorConfig, FetchClient, type FetchClientConfig, type HttpMethod, type InterceptorChainResult, InterceptorManager, type Interceptors, LOG_LEVEL_PRIORITY, type LogLevel, type Logger, LoggingInterceptor, type LoggingInterceptorConfig, type MetricsCollector, type MetricsCollectorConfig, MetricsErrorInterceptor, MetricsRequestInterceptor, MetricsResponseInterceptor, type MetricsSummary, type MiddlewareConfig, type MutableRequestOptions, NetworkError, type NoAuthConfig, NoAuthenticator, type PathMetrics, type QueryParamValue, type QueryParams, ReportingInterceptor, type ReportingInterceptorConfig, type RequestContext$1 as RequestContext, RequestDeduper, RequestIdInterceptor, type RequestIdInterceptorConfig, type RequestInterceptor, type RequestInterceptorFactory, type RequestMetrics, type RequestOptions, type ResponseData, type ResponseInterceptor, type ResponseInterceptorFactory, type RetryCallback, type RetryConfig, type RetryContext, type RetryInfo, RetryInterceptor, type RetryInterceptorConfig, SDK_NAME, type ShouldRetryFn, SilentLogger, TimeoutError, TimeoutInterceptor, type TimeoutInterceptorConfig, type TokenRefreshConfig, TokenRefreshInterceptor, type TokenRefreshInterceptorConfig, TraceInterceptor, type TraceInterceptorConfig, VERSION, buildUrl, calculateRetryDelay, createApiKeyAuthenticator, createAuthInterceptor, createAuthMiddleware, createAuthenticatorFromConfig, createAxiosInstance, createBasicAuthenticator, createBearerAuthenticator, createBufferLogger, createConsoleLogger, createCustomAuthenticator, createErrorTransformInterceptor, createFetchClient, createInterceptorManager, createLoggingInterceptor, createMetricsCollector, createMetricsInterceptors, createMiddlewares, createNoAuthenticator, createReportingInterceptor, createRequestDeduper, createRequestIdInterceptor, createRetryInterceptor, createSilentLogger, createTimeoutInterceptor, createTokenRefreshInterceptor, createTraceInterceptor, createTrackingMiddleware, extractPath, extractResponseHeaders, generateRequestId, generateTraceId, getErrorType, getHeader, getRecommendedRetryDelay, getRetryDelay, getSdkInfo, hasContentType, isClientError, isRetryableError, isValidRequestId, isValidTraceId, joinPaths, mergeHeaders, noAuthenticator, parseQueryString, parseRetryAfter, removeHeader, setHeader, silentLogger, sleep, sleepWithAbort };