@be-link/request 1.45.1-beta.8 → 1.45.1-beta.9
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/README.md +288 -365
- package/dist/BeLinkRequest.d.ts +207 -0
- package/dist/BeLinkRequest.d.ts.map +1 -0
- package/dist/index.cjs.js +721 -5356
- package/dist/index.d.ts +88 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +717 -5331
- package/dist/interceptors/index.d.ts +10 -0
- package/dist/interceptors/index.d.ts.map +1 -0
- package/dist/interceptors/request.d.ts +50 -0
- package/dist/interceptors/request.d.ts.map +1 -0
- package/dist/interceptors/response.d.ts +52 -0
- package/dist/interceptors/response.d.ts.map +1 -0
- package/dist/services/EncryptionService.d.ts +120 -0
- package/dist/services/EncryptionService.d.ts.map +1 -0
- package/dist/services/TimeSyncService.d.ts +117 -0
- package/dist/services/TimeSyncService.d.ts.map +1 -0
- package/dist/services/index.d.ts +10 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/types.d.ts +268 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -2
- package/dist/application/clients/BeLinkClient.d.ts +0 -82
- package/dist/application/clients/BeLinkClient.d.ts.map +0 -1
- package/dist/application/clients/HttpClient.d.ts +0 -64
- package/dist/application/clients/HttpClient.d.ts.map +0 -1
- package/dist/application/clients/LiveClient.d.ts +0 -52
- package/dist/application/clients/LiveClient.d.ts.map +0 -1
- package/dist/application/interceptors/AuthInterceptor.d.ts +0 -23
- package/dist/application/interceptors/AuthInterceptor.d.ts.map +0 -1
- package/dist/application/interceptors/TimeInterceptor.d.ts +0 -21
- package/dist/application/interceptors/TimeInterceptor.d.ts.map +0 -1
- package/dist/application/interceptors/TokenInterceptor.d.ts +0 -26
- package/dist/application/interceptors/TokenInterceptor.d.ts.map +0 -1
- package/dist/application/services/UserInfoService.d.ts +0 -33
- package/dist/application/services/UserInfoService.d.ts.map +0 -1
- package/dist/cloudbase/index.d.ts +0 -27
- package/dist/cloudbase/index.d.ts.map +0 -1
- package/dist/cloudbase/types.d.ts +0 -63
- package/dist/cloudbase/types.d.ts.map +0 -1
- package/dist/core/constants/index.d.ts +0 -64
- package/dist/core/constants/index.d.ts.map +0 -1
- package/dist/core/errors/index.d.ts +0 -42
- package/dist/core/errors/index.d.ts.map +0 -1
- package/dist/core/interfaces/IConfigManager.d.ts +0 -31
- package/dist/core/interfaces/IConfigManager.d.ts.map +0 -1
- package/dist/core/interfaces/IEncryptionService.d.ts +0 -28
- package/dist/core/interfaces/IEncryptionService.d.ts.map +0 -1
- package/dist/core/interfaces/IHttpClient.d.ts +0 -43
- package/dist/core/interfaces/IHttpClient.d.ts.map +0 -1
- package/dist/core/interfaces/index.d.ts +0 -4
- package/dist/core/interfaces/index.d.ts.map +0 -1
- package/dist/core/types/config.types.d.ts +0 -65
- package/dist/core/types/config.types.d.ts.map +0 -1
- package/dist/core/types/index.d.ts +0 -5
- package/dist/core/types/index.d.ts.map +0 -1
- package/dist/core/types/interceptor.types.d.ts +0 -45
- package/dist/core/types/interceptor.types.d.ts.map +0 -1
- package/dist/core/types/request.types.d.ts +0 -65
- package/dist/core/types/request.types.d.ts.map +0 -1
- package/dist/core/types/response.types.d.ts +0 -29
- package/dist/core/types/response.types.d.ts.map +0 -1
- package/dist/infrastructure/adapters/AxiosAdapter.d.ts +0 -51
- package/dist/infrastructure/adapters/AxiosAdapter.d.ts.map +0 -1
- package/dist/infrastructure/services/ConfigManager.d.ts +0 -52
- package/dist/infrastructure/services/ConfigManager.d.ts.map +0 -1
- package/dist/infrastructure/services/EncryptionService.d.ts +0 -34
- package/dist/infrastructure/services/EncryptionService.d.ts.map +0 -1
- package/dist/infrastructure/services/TimeSyncService.d.ts +0 -43
- package/dist/infrastructure/services/TimeSyncService.d.ts.map +0 -1
- package/dist/infrastructure/utils/env.utils.d.ts +0 -13
- package/dist/infrastructure/utils/env.utils.d.ts.map +0 -1
- package/dist/presets/belink.preset.d.ts +0 -4
- package/dist/presets/belink.preset.d.ts.map +0 -1
- package/dist/presets/index.d.ts +0 -4
- package/dist/presets/index.d.ts.map +0 -1
- package/dist/presets/live.preset.d.ts +0 -4
- package/dist/presets/live.preset.d.ts.map +0 -1
- package/dist/presets/request.preset.d.ts +0 -9
- package/dist/presets/request.preset.d.ts.map +0 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BeLinkRequest 请求客户端
|
|
3
|
+
*
|
|
4
|
+
* 单例模式的 HTTP 请求客户端
|
|
5
|
+
* 支持时间同步和 Token 加密
|
|
6
|
+
*
|
|
7
|
+
* @module BeLinkRequest
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { beLinkRequest } from '@be-link/request';
|
|
12
|
+
*
|
|
13
|
+
* // 初始化
|
|
14
|
+
* beLinkRequest.init({
|
|
15
|
+
* baseURL: 'https://api.example.com',
|
|
16
|
+
* timeSync: { syncUrl: 'https://api.example.com/api/time' },
|
|
17
|
+
* encryption: { key: '...', iv: '...' },
|
|
18
|
+
* getToken: () => localStorage.getItem('token'),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // 发起请求
|
|
22
|
+
* const data = await beLinkRequest.get('/api/users');
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
26
|
+
import type { RequestOptions } from './types';
|
|
27
|
+
import { TimeSyncService } from './services/TimeSyncService';
|
|
28
|
+
import { EncryptionService } from './services/EncryptionService';
|
|
29
|
+
/**
|
|
30
|
+
* BeLinkRequest 单例类
|
|
31
|
+
*
|
|
32
|
+
* 提供统一的 HTTP 请求接口,支持:
|
|
33
|
+
* - 时间同步
|
|
34
|
+
* - Token 加密
|
|
35
|
+
* - 请求/响应拦截
|
|
36
|
+
*/
|
|
37
|
+
declare class BeLinkRequest {
|
|
38
|
+
/** Axios 实例 */
|
|
39
|
+
private instance;
|
|
40
|
+
/** 时间同步服务 */
|
|
41
|
+
private timeSyncService;
|
|
42
|
+
/** 加密服务 */
|
|
43
|
+
private encryptionService;
|
|
44
|
+
/** 是否已初始化 */
|
|
45
|
+
private initialized;
|
|
46
|
+
/**
|
|
47
|
+
* 初始化请求客户端
|
|
48
|
+
*
|
|
49
|
+
* 必须在使用其他方法之前调用此方法进行初始化
|
|
50
|
+
*
|
|
51
|
+
* @param options - 请求配置选项
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* beLinkRequest.init({
|
|
56
|
+
* baseURL: 'https://api.example.com',
|
|
57
|
+
* timeout: 30000,
|
|
58
|
+
* timeSync: {
|
|
59
|
+
* syncUrl: 'https://api.example.com/api/time',
|
|
60
|
+
* },
|
|
61
|
+
* encryption: {
|
|
62
|
+
* key: 'your-aes-key-16ch',
|
|
63
|
+
* iv: 'your-aes-iv-16ch',
|
|
64
|
+
* },
|
|
65
|
+
* getToken: () => localStorage.getItem('token'),
|
|
66
|
+
* getUserId: () => localStorage.getItem('userId'),
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
init(options: RequestOptions): void;
|
|
71
|
+
/**
|
|
72
|
+
* 检查是否已初始化
|
|
73
|
+
*/
|
|
74
|
+
private checkInitialized;
|
|
75
|
+
/**
|
|
76
|
+
* GET 请求
|
|
77
|
+
*
|
|
78
|
+
* @param url - 请求 URL
|
|
79
|
+
* @param config - 可选的 Axios 请求配置
|
|
80
|
+
* @returns Promise 响应数据
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const users = await beLinkRequest.get('/api/users');
|
|
85
|
+
* const user = await beLinkRequest.get('/api/users/1', { params: { include: 'profile' } });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* POST 请求
|
|
91
|
+
*
|
|
92
|
+
* @param url - 请求 URL
|
|
93
|
+
* @param data - 请求体数据
|
|
94
|
+
* @param config - 可选的 Axios 请求配置
|
|
95
|
+
* @returns Promise 响应数据
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const result = await beLinkRequest.post('/api/users', { name: '张三', age: 25 });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
103
|
+
/**
|
|
104
|
+
* PUT 请求
|
|
105
|
+
*
|
|
106
|
+
* @param url - 请求 URL
|
|
107
|
+
* @param data - 请求体数据
|
|
108
|
+
* @param config - 可选的 Axios 请求配置
|
|
109
|
+
* @returns Promise 响应数据
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const result = await beLinkRequest.put('/api/users/1', { name: '李四' });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
117
|
+
/**
|
|
118
|
+
* PATCH 请求
|
|
119
|
+
*
|
|
120
|
+
* @param url - 请求 URL
|
|
121
|
+
* @param data - 请求体数据
|
|
122
|
+
* @param config - 可选的 Axios 请求配置
|
|
123
|
+
* @returns Promise 响应数据
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const result = await beLinkRequest.patch('/api/users/1', { age: 26 });
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
131
|
+
/**
|
|
132
|
+
* DELETE 请求
|
|
133
|
+
*
|
|
134
|
+
* @param url - 请求 URL
|
|
135
|
+
* @param config - 可选的 Axios 请求配置
|
|
136
|
+
* @returns Promise 响应数据
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* await beLinkRequest.delete('/api/users/1');
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
144
|
+
/**
|
|
145
|
+
* 通用请求方法
|
|
146
|
+
*
|
|
147
|
+
* @param config - Axios 请求配置
|
|
148
|
+
* @returns Promise 响应数据
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const result = await beLinkRequest.request({
|
|
153
|
+
* method: 'post',
|
|
154
|
+
* url: '/api/users',
|
|
155
|
+
* data: { name: '张三' },
|
|
156
|
+
* headers: { 'X-Custom': 'value' },
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
request<T = any>(config: AxiosRequestConfig): Promise<T>;
|
|
161
|
+
/**
|
|
162
|
+
* 获取时间同步服务实例
|
|
163
|
+
*
|
|
164
|
+
* @returns 时间同步服务实例,未初始化时返回 null
|
|
165
|
+
*/
|
|
166
|
+
getTimeSyncService(): TimeSyncService | null;
|
|
167
|
+
/**
|
|
168
|
+
* 获取加密服务实例
|
|
169
|
+
*
|
|
170
|
+
* @returns 加密服务实例,未初始化时返回 null
|
|
171
|
+
*/
|
|
172
|
+
getEncryptionService(): EncryptionService | null;
|
|
173
|
+
/**
|
|
174
|
+
* 获取 Axios 实例
|
|
175
|
+
*
|
|
176
|
+
* @returns Axios 实例,未初始化时返回 null
|
|
177
|
+
*/
|
|
178
|
+
getAxiosInstance(): AxiosInstance | null;
|
|
179
|
+
/**
|
|
180
|
+
* 重置客户端
|
|
181
|
+
*
|
|
182
|
+
* 清除所有配置和实例,需要重新调用 init() 初始化
|
|
183
|
+
*/
|
|
184
|
+
reset(): void;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* BeLinkRequest 单例实例
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { beLinkRequest } from '@be-link/request';
|
|
192
|
+
*
|
|
193
|
+
* // 初始化
|
|
194
|
+
* beLinkRequest.init({
|
|
195
|
+
* baseURL: 'https://api.example.com',
|
|
196
|
+
* });
|
|
197
|
+
*
|
|
198
|
+
* // 使用
|
|
199
|
+
* const data = await beLinkRequest.get('/api/users');
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export declare const beLinkRequest: BeLinkRequest;
|
|
203
|
+
/**
|
|
204
|
+
* 导出类,用于创建多个实例(如需要)
|
|
205
|
+
*/
|
|
206
|
+
export { BeLinkRequest };
|
|
207
|
+
//# sourceMappingURL=BeLinkRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BeLinkRequest.d.ts","sourceRoot":"","sources":["../src/BeLinkRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE;;;;;;;GAOG;AACH,cAAM,aAAa;IACjB,eAAe;IACf,OAAO,CAAC,QAAQ,CAA8B;IAE9C,aAAa;IACb,OAAO,CAAC,eAAe,CAAgC;IAEvD,WAAW;IACX,OAAO,CAAC,iBAAiB,CAAkC;IAE3D,aAAa;IACb,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACI,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAmC1C;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAMxB;;;;;;;;;;;;OAYG;IACU,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO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