@be-link/request 1.44.0 → 1.45.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +366 -20
- package/dist/application/clients/BeLinkClient.d.ts +75 -0
- package/dist/application/clients/BeLinkClient.d.ts.map +1 -0
- package/dist/application/clients/HttpClient.d.ts +64 -0
- package/dist/application/clients/HttpClient.d.ts.map +1 -0
- package/dist/application/clients/LiveClient.d.ts +15 -0
- package/dist/application/clients/LiveClient.d.ts.map +1 -0
- package/dist/application/interceptors/AuthInterceptor.d.ts +23 -0
- package/dist/application/interceptors/AuthInterceptor.d.ts.map +1 -0
- package/dist/application/interceptors/TimeInterceptor.d.ts +21 -0
- package/dist/application/interceptors/TimeInterceptor.d.ts.map +1 -0
- package/dist/application/interceptors/TokenInterceptor.d.ts +24 -0
- package/dist/application/interceptors/TokenInterceptor.d.ts.map +1 -0
- package/dist/application/services/UserInfoService.d.ts +33 -0
- package/dist/application/services/UserInfoService.d.ts.map +1 -0
- package/dist/cloudbase/index.d.ts +27 -0
- package/dist/cloudbase/index.d.ts.map +1 -0
- package/dist/cloudbase/types.d.ts +63 -0
- package/dist/cloudbase/types.d.ts.map +1 -0
- package/dist/core/constants/index.d.ts +59 -0
- package/dist/core/constants/index.d.ts.map +1 -0
- package/dist/core/errors/index.d.ts +42 -0
- package/dist/core/errors/index.d.ts.map +1 -0
- package/dist/core/interfaces/IConfigManager.d.ts +31 -0
- package/dist/core/interfaces/IConfigManager.d.ts.map +1 -0
- package/dist/core/interfaces/IEncryptionService.d.ts +28 -0
- package/dist/core/interfaces/IEncryptionService.d.ts.map +1 -0
- package/dist/core/interfaces/IHttpClient.d.ts +43 -0
- package/dist/core/interfaces/IHttpClient.d.ts.map +1 -0
- package/dist/core/interfaces/index.d.ts +4 -0
- package/dist/core/interfaces/index.d.ts.map +1 -0
- package/dist/core/types/config.types.d.ts +57 -0
- package/dist/core/types/config.types.d.ts.map +1 -0
- package/dist/core/types/index.d.ts +5 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/interceptor.types.d.ts +48 -0
- package/dist/core/types/interceptor.types.d.ts.map +1 -0
- package/dist/core/types/request.types.d.ts +65 -0
- package/dist/core/types/request.types.d.ts.map +1 -0
- package/dist/core/types/response.types.d.ts +29 -0
- package/dist/core/types/response.types.d.ts.map +1 -0
- package/dist/index.cjs.js +6266 -0
- package/dist/index.d.ts +39 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +6235 -0
- package/dist/infrastructure/adapters/AxiosAdapter.d.ts +47 -0
- package/dist/infrastructure/adapters/AxiosAdapter.d.ts.map +1 -0
- package/dist/infrastructure/services/ConfigManager.d.ts +52 -0
- package/dist/infrastructure/services/ConfigManager.d.ts.map +1 -0
- package/dist/infrastructure/services/EncryptionService.d.ts +34 -0
- package/dist/infrastructure/services/EncryptionService.d.ts.map +1 -0
- package/dist/infrastructure/services/TimeSyncService.d.ts +44 -0
- package/dist/infrastructure/services/TimeSyncService.d.ts.map +1 -0
- package/dist/infrastructure/utils/env.utils.d.ts +13 -0
- package/dist/infrastructure/utils/env.utils.d.ts.map +1 -0
- package/dist/presets/belink.preset.d.ts +4 -0
- package/dist/presets/belink.preset.d.ts.map +1 -0
- package/dist/presets/index.d.ts +4 -0
- package/dist/presets/index.d.ts.map +1 -0
- package/dist/presets/live.preset.d.ts +4 -0
- package/dist/presets/live.preset.d.ts.map +1 -0
- package/dist/presets/request.preset.d.ts +9 -0
- package/dist/presets/request.preset.d.ts.map +1 -0
- package/package.json +37 -35
- package/dist/beLinkRequest.d.ts +0 -43
- package/dist/callFunction.d.ts +0 -36
- package/dist/config.d.ts +0 -5
- package/dist/createInit.d.ts +0 -14
- package/dist/index.js +0 -1
- package/dist/request.d.ts +0 -14
package/README.md
CHANGED
|
@@ -1,34 +1,380 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @be-link/request
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
共比邻 HTTP 请求库,提供企业级的 HTTP 请求封装和云函数调用功能。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 特性
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- 企业级 HTTP 请求客户端(认证、加密、时间同步)
|
|
8
|
+
- 云函数调用封装(腾讯云 CloudBase)
|
|
9
|
+
- 拦截器机制(请求/响应拦截)
|
|
10
|
+
- TypeScript 类型支持
|
|
11
|
+
- 多环境适配(Browser/Node.js)
|
|
8
12
|
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @be-link/request
|
|
17
|
+
# 或
|
|
18
|
+
pnpm add @be-link/request
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 快速开始
|
|
22
|
+
|
|
23
|
+
### 1. 初始化配置
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { beLinkRequest, ConfigManager } from '@be-link/request';
|
|
27
|
+
|
|
28
|
+
// 初始化客户端
|
|
29
|
+
beLinkRequest.init({
|
|
30
|
+
mode: 'production', // 'development' | 'testing' | 'production'
|
|
31
|
+
loginPath: '/login', // 401 时跳转的登录页路径,也可以是函数
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 设置 Token(通常在登录后调用)
|
|
35
|
+
beLinkRequest.setToken('your-auth-token');
|
|
36
|
+
|
|
37
|
+
// 或监听 localStorage 中的 Token 变化
|
|
38
|
+
beLinkRequest.setupTokenListener('TOKEN_KEY');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. 发起请求
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { beLinkRequest } from '@be-link/request';
|
|
45
|
+
|
|
46
|
+
// GET 请求
|
|
47
|
+
const users = await beLinkRequest.get('/api/users');
|
|
48
|
+
|
|
49
|
+
// POST 请求
|
|
50
|
+
const result = await beLinkRequest.post('/api/users', {
|
|
51
|
+
name: '张三',
|
|
52
|
+
age: 25,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// 带配置的请求
|
|
56
|
+
const data = await beLinkRequest.request({
|
|
57
|
+
url: '/api/data',
|
|
58
|
+
method: 'post',
|
|
59
|
+
data: { key: 'value' },
|
|
60
|
+
headers: { 'X-Custom-Header': 'custom-value' },
|
|
61
|
+
timeout: 10000,
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API 文档
|
|
66
|
+
|
|
67
|
+
### beLinkRequest - 企业级请求客户端
|
|
68
|
+
|
|
69
|
+
带完整认证、加密、时间同步功能的请求客户端。
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { beLinkRequest } from '@be-link/request';
|
|
73
|
+
|
|
74
|
+
// 初始化
|
|
75
|
+
beLinkRequest.init({
|
|
76
|
+
mode: 'production',
|
|
77
|
+
loginPath: '/login',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// 设置 Token
|
|
81
|
+
beLinkRequest.setToken(token: string): void
|
|
82
|
+
|
|
83
|
+
// 获取 Token
|
|
84
|
+
beLinkRequest.getToken(): string | null
|
|
85
|
+
|
|
86
|
+
// 监听 Token 变化(返回清理函数)
|
|
87
|
+
beLinkRequest.setupTokenListener(tokenKey: string | (() => string)): () => void
|
|
88
|
+
|
|
89
|
+
// HTTP 方法
|
|
90
|
+
beLinkRequest.get<T>(url: string, config?): Promise<ApiResponse<T>>
|
|
91
|
+
beLinkRequest.post<T>(url: string, data?, config?): Promise<ApiResponse<T>>
|
|
92
|
+
beLinkRequest.put<T>(url: string, data?, config?): Promise<ApiResponse<T>>
|
|
93
|
+
beLinkRequest.delete<T>(url: string, config?): Promise<ApiResponse<T>>
|
|
94
|
+
|
|
95
|
+
// 通用请求
|
|
96
|
+
beLinkRequest.request<T>(config: RequestConfig): Promise<ApiResponse<T>>
|
|
97
|
+
|
|
98
|
+
// 时间同步
|
|
99
|
+
beLinkRequest.setupRequestTime(config): Promise<void> // 设置请求时间
|
|
100
|
+
beLinkRequest.removeRequestTime(): Promise<void> // 清除请求时间
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### beLinkLiveRequest - 直播请求客户端
|
|
104
|
+
|
|
105
|
+
简化版客户端,无认证逻辑,适用于直播等场景。
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { beLinkLiveRequest } from '@be-link/request';
|
|
109
|
+
|
|
110
|
+
// 使用方式与 beLinkRequest 相同,但不包含认证功能
|
|
111
|
+
const data = await beLinkLiveRequest.post('/api/live/data', { roomId: '123' });
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### request - 基础请求
|
|
115
|
+
|
|
116
|
+
基于 Axios 的基础请求函数。
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { request } from '@be-link/request';
|
|
120
|
+
|
|
121
|
+
const result = await request({
|
|
122
|
+
url: 'https://api.example.com/data',
|
|
123
|
+
method: 'post',
|
|
124
|
+
data: { key: 'value' },
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### callFunction - 云函数调用
|
|
129
|
+
|
|
130
|
+
封装腾讯云 CloudBase 云函数调用。
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { callFunction } from '@be-link/request';
|
|
134
|
+
|
|
135
|
+
// 调用云函数
|
|
136
|
+
const result = await callFunction({
|
|
137
|
+
name: 'cloud-function-name',
|
|
138
|
+
data: {
|
|
139
|
+
moduleName: 'biz',
|
|
140
|
+
serviceName: 'main',
|
|
141
|
+
funcName: 'getUserInfo',
|
|
142
|
+
param: { userId: '123' },
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// 带操作用户信息(会自动注入)
|
|
147
|
+
const result = await callFunction({
|
|
148
|
+
name: 'cloud-function-name',
|
|
149
|
+
data: {
|
|
150
|
+
moduleName: 'biz',
|
|
151
|
+
serviceName: 'main',
|
|
152
|
+
funcName: 'createOrder',
|
|
153
|
+
param: { productId: '456' },
|
|
154
|
+
operateUser: { name: 'staffName' }, // 可选,会自动注入
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### ConfigManager - 配置管理
|
|
160
|
+
|
|
161
|
+
全局配置管理器(单例模式)。
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { ConfigManager } from '@be-link/request';
|
|
165
|
+
|
|
166
|
+
const configManager = ConfigManager.getInstance();
|
|
167
|
+
|
|
168
|
+
// 初始化配置
|
|
169
|
+
configManager.init({
|
|
170
|
+
mode: 'production',
|
|
171
|
+
timeout: 10000,
|
|
172
|
+
loginPath: '/login',
|
|
173
|
+
encryption: {
|
|
174
|
+
key: 'your-encryption-key',
|
|
175
|
+
iv: 'your-encryption-iv',
|
|
176
|
+
},
|
|
177
|
+
timeSync: {
|
|
178
|
+
enabled: true,
|
|
179
|
+
developmentUrl: 'https://dev.example.com/time',
|
|
180
|
+
productionUrl: 'https://api.example.com/time',
|
|
181
|
+
},
|
|
182
|
+
cloudbase: {
|
|
183
|
+
development: 'dev-env-id',
|
|
184
|
+
testing: 'test-env-id',
|
|
185
|
+
production: 'prod-env-id',
|
|
186
|
+
region: 'ap-shanghai',
|
|
187
|
+
timeout: 60000,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// 获取配置
|
|
192
|
+
const mode = configManager.get('mode');
|
|
193
|
+
const allConfig = configManager.getAll();
|
|
194
|
+
|
|
195
|
+
// 设置单个配置
|
|
196
|
+
configManager.set('timeout', 15000);
|
|
9
197
|
```
|
|
10
|
-
import { callFunction } from '@be-link/request'
|
|
11
198
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
199
|
+
## 请求配置
|
|
200
|
+
|
|
201
|
+
### RequestConfig
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
interface RequestConfig<D = any> {
|
|
205
|
+
url: string; // 请求 URL
|
|
206
|
+
method?: 'get' | 'post' | 'put' | 'delete' | 'patch'; // HTTP 方法
|
|
207
|
+
headers?: Record<string, string>; // 请求头
|
|
208
|
+
params?: Record<string, any>; // URL 参数
|
|
209
|
+
data?: D; // 请求体
|
|
210
|
+
timeout?: number; // 超时时间(毫秒)
|
|
211
|
+
withCredentials?: boolean; // 是否携带凭证
|
|
212
|
+
customToken?: string; // 自定义 Token
|
|
20
213
|
}
|
|
21
214
|
```
|
|
22
215
|
|
|
23
|
-
###
|
|
216
|
+
### 响应格式
|
|
24
217
|
|
|
218
|
+
```typescript
|
|
219
|
+
interface ApiResponse<T = any> {
|
|
220
|
+
data: T; // 响应数据
|
|
221
|
+
code: number; // 状态码
|
|
222
|
+
msg: string; // 消息
|
|
223
|
+
success: boolean; // 是否成功
|
|
224
|
+
}
|
|
25
225
|
```
|
|
26
|
-
import { request } from '@be-link/request'
|
|
27
226
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
227
|
+
## 拦截器
|
|
228
|
+
|
|
229
|
+
### 添加自定义拦截器
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { beLinkRequest } from '@be-link/request';
|
|
233
|
+
|
|
234
|
+
// 添加请求拦截器
|
|
235
|
+
const removeInterceptor = beLinkRequest.addRequestInterceptor({
|
|
236
|
+
name: 'CustomInterceptor',
|
|
237
|
+
priority: 10, // 数字越小优先级越高
|
|
238
|
+
onRequest: async (context) => {
|
|
239
|
+
// 修改请求配置
|
|
240
|
+
context.config.headers['X-Custom'] = 'value';
|
|
241
|
+
return context;
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// 添加响应拦截器
|
|
246
|
+
beLinkRequest.addResponseInterceptor({
|
|
247
|
+
name: 'LogInterceptor',
|
|
248
|
+
priority: 10,
|
|
249
|
+
onResponse: async (context) => {
|
|
250
|
+
console.log('Response:', context.response);
|
|
251
|
+
return context;
|
|
252
|
+
},
|
|
253
|
+
onResponseError: async (error) => {
|
|
254
|
+
console.error('Error:', error);
|
|
255
|
+
throw error;
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// 移除拦截器
|
|
260
|
+
removeInterceptor();
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## 错误处理
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { beLinkRequest, HttpError, AuthError, TimeoutError } from '@be-link/request';
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
const data = await beLinkRequest.get('/api/data');
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (error instanceof AuthError) {
|
|
272
|
+
// 401 认证错误,会自动跳转登录页
|
|
273
|
+
console.log('认证失败');
|
|
274
|
+
} else if (error instanceof TimeoutError) {
|
|
275
|
+
console.log('请求超时');
|
|
276
|
+
} else if (error instanceof HttpError) {
|
|
277
|
+
console.log('HTTP 错误:', error.status);
|
|
278
|
+
}
|
|
33
279
|
}
|
|
34
280
|
```
|
|
281
|
+
|
|
282
|
+
## 环境变量
|
|
283
|
+
|
|
284
|
+
支持通过环境变量配置加密密钥:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# Vite
|
|
288
|
+
VITE_BELINK_ENCRYPTION_KEY=your-key
|
|
289
|
+
VITE_BELINK_ENCRYPTION_IV=your-iv
|
|
290
|
+
|
|
291
|
+
# Webpack/Node
|
|
292
|
+
BELINK_ENCRYPTION_KEY=your-key
|
|
293
|
+
BELINK_ENCRYPTION_IV=your-iv
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## 类型导出
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// 请求相关
|
|
300
|
+
export type { RequestConfig, RequestContext, IConfig, HttpMethod } from '@be-link/request';
|
|
301
|
+
|
|
302
|
+
// 响应相关
|
|
303
|
+
export type { ApiResponse, ResponseContext, IApiResponse } from '@be-link/request';
|
|
304
|
+
|
|
305
|
+
// 拦截器
|
|
306
|
+
export type { RequestInterceptor, ResponseInterceptor } from '@be-link/request';
|
|
307
|
+
|
|
308
|
+
// 配置
|
|
309
|
+
export type { AppConfig, EncryptionConfig, TimeSyncConfig, CloudbaseConfig } from '@be-link/request';
|
|
310
|
+
|
|
311
|
+
// 云函数
|
|
312
|
+
export type { CloudFunctionOptions, CloudFunctionResponse, CloudFunctionData } from '@be-link/request';
|
|
313
|
+
|
|
314
|
+
// 错误类
|
|
315
|
+
export { BaseError, HttpError, AuthError, TimeoutError, ConfigError, NetworkError } from '@be-link/request';
|
|
316
|
+
|
|
317
|
+
// 工具函数
|
|
318
|
+
export { isBrowser, isNode, detectEnvironment } from '@be-link/request';
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## 完整示例
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import { beLinkRequest, ConfigManager, HttpError, AuthError } from '@be-link/request';
|
|
325
|
+
|
|
326
|
+
// 1. 初始化配置
|
|
327
|
+
const configManager = ConfigManager.getInstance();
|
|
328
|
+
configManager.init({
|
|
329
|
+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
330
|
+
loginPath: () => {
|
|
331
|
+
window.location.href = '/login';
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// 2. 初始化客户端
|
|
336
|
+
beLinkRequest.init({
|
|
337
|
+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// 3. 设置 Token(登录后)
|
|
341
|
+
const token = localStorage.getItem('token');
|
|
342
|
+
if (token) {
|
|
343
|
+
beLinkRequest.setToken(token);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// 4. 监听 Token 变化
|
|
347
|
+
beLinkRequest.setupTokenListener('token');
|
|
348
|
+
|
|
349
|
+
// 5. 发起请求
|
|
350
|
+
async function fetchUserInfo(userId: string) {
|
|
351
|
+
try {
|
|
352
|
+
const response = await beLinkRequest.get<{ name: string; age: number }>(`/api/users/${userId}`);
|
|
353
|
+
return response.data;
|
|
354
|
+
} catch (error) {
|
|
355
|
+
if (error instanceof AuthError) {
|
|
356
|
+
// 自动跳转登录页
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// 6. 调用云函数
|
|
364
|
+
async function createOrder(productId: string) {
|
|
365
|
+
const result = await callFunction({
|
|
366
|
+
name: 'order-service',
|
|
367
|
+
data: {
|
|
368
|
+
moduleName: 'order',
|
|
369
|
+
serviceName: 'main',
|
|
370
|
+
funcName: 'create',
|
|
371
|
+
param: { productId },
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## License
|
|
379
|
+
|
|
380
|
+
ISC
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { HttpClient } from './HttpClient';
|
|
2
|
+
import { RequestConfig, IConfig } from '../../core/types/request.types';
|
|
3
|
+
import { ApiResponse } from '../../core/types/response.types';
|
|
4
|
+
/**
|
|
5
|
+
* BeLink 业务请求客户端
|
|
6
|
+
* 提供完整的认证、加密、时间同步等企业级功能
|
|
7
|
+
*/
|
|
8
|
+
export declare class BeLinkClient extends HttpClient {
|
|
9
|
+
private configManager;
|
|
10
|
+
private encryptionService;
|
|
11
|
+
private timeSyncService;
|
|
12
|
+
private token;
|
|
13
|
+
private initialized;
|
|
14
|
+
private tokenListenerCleanup;
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* 初始化客户端
|
|
18
|
+
*/
|
|
19
|
+
init(config: {
|
|
20
|
+
mode: string;
|
|
21
|
+
loginPath?: string | (() => void);
|
|
22
|
+
}): void;
|
|
23
|
+
/**
|
|
24
|
+
* 设置 Token
|
|
25
|
+
*/
|
|
26
|
+
setToken(token: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* 获取当前 Token
|
|
29
|
+
*/
|
|
30
|
+
getToken(): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* 设置 Token 监听器
|
|
33
|
+
* @returns 清理函数,用于移除监听器
|
|
34
|
+
*/
|
|
35
|
+
setupTokenListener(tokenKey: string | (() => string)): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* 设置全局拦截器(向后兼容)
|
|
38
|
+
*/
|
|
39
|
+
setupInterceptors(): void;
|
|
40
|
+
/**
|
|
41
|
+
* 设置认证回调(向后兼容)
|
|
42
|
+
*/
|
|
43
|
+
setupAuthorizationCallback(path: string | (() => void)): void;
|
|
44
|
+
/**
|
|
45
|
+
* 清除请求时间
|
|
46
|
+
*/
|
|
47
|
+
removeRequestTime(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated 请使用 removeRequestTime(修正拼写后的版本)
|
|
50
|
+
* 清除请求时间(向后兼容)
|
|
51
|
+
*/
|
|
52
|
+
removeReqeustTime(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* 设置请求时间
|
|
55
|
+
*/
|
|
56
|
+
setupRequestTime(config: IConfig): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated 请使用 setupRequestTime(修正拼写后的版本)
|
|
59
|
+
* 设置请求时间(向后兼容)
|
|
60
|
+
*/
|
|
61
|
+
setupReqeustTime(config: IConfig): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* 设置 Token(向后兼容)
|
|
64
|
+
*/
|
|
65
|
+
setupToken(config: IConfig): void;
|
|
66
|
+
/**
|
|
67
|
+
* 重写请求方法(向后兼容旧版 API)
|
|
68
|
+
*/
|
|
69
|
+
request<T = unknown>(config: RequestConfig | IConfig): Promise<ApiResponse<T>>;
|
|
70
|
+
/**
|
|
71
|
+
* 设置默认拦截器
|
|
72
|
+
*/
|
|
73
|
+
private setupDefaultInterceptors;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=BeLinkClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BeLinkClient.d.ts","sourceRoot":"","sources":["../../../src/application/clients/BeLinkClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAU9D;;;GAGG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,oBAAoB,CAA6B;;IAiBzD;;OAEG;IACI,IAAI,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,CAAA;KAAE,GAAG,IAAI;IAgB9E;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpC;;OAEG;IACI,QAAQ,IAAI,MAAM,GAAG,IAAI;IAIhC;;;OAGG;IACI,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,IAAI;IAqDxE;;OAEG;IACI,iBAAiB,IAAI,IAAI;IAIhC;;OAEG;IACI,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI;IAIpE;;OAEG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/C;;;OAGG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/C;;OAEG;IACU,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D;;;OAGG;IACU,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7D;;OAEG;IACI,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAaxC;;OAEG;IACU,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAc3F;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAsBjC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { IHttpClient } from '../../core/interfaces/IHttpClient';
|
|
2
|
+
import { RequestConfig, IConfig } from '../../core/types/request.types';
|
|
3
|
+
import { ApiResponse } from '../../core/types/response.types';
|
|
4
|
+
import { RequestInterceptor, ResponseInterceptor } from '../../core/types/interceptor.types';
|
|
5
|
+
import { AxiosAdapter } from '../../infrastructure/adapters/AxiosAdapter';
|
|
6
|
+
/**
|
|
7
|
+
* HTTP 客户端实现
|
|
8
|
+
* 提供基础的 HTTP 请求功能
|
|
9
|
+
*/
|
|
10
|
+
export declare class HttpClient implements IHttpClient {
|
|
11
|
+
protected adapter: AxiosAdapter;
|
|
12
|
+
protected requestInterceptors: RequestInterceptor[];
|
|
13
|
+
protected responseInterceptors: ResponseInterceptor[];
|
|
14
|
+
constructor(adapter?: AxiosAdapter);
|
|
15
|
+
/**
|
|
16
|
+
* GET 请求
|
|
17
|
+
*/
|
|
18
|
+
get<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<ApiResponse<T>>;
|
|
19
|
+
/**
|
|
20
|
+
* POST 请求
|
|
21
|
+
*/
|
|
22
|
+
post<T = unknown, D = unknown>(url: string, data?: D, config?: Omit<RequestConfig<D>, 'url' | 'method' | 'data'>): Promise<ApiResponse<T>>;
|
|
23
|
+
/**
|
|
24
|
+
* PUT 请求
|
|
25
|
+
*/
|
|
26
|
+
put<T = unknown, D = unknown>(url: string, data?: D, config?: Omit<RequestConfig<D>, 'url' | 'method' | 'data'>): Promise<ApiResponse<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* DELETE 请求
|
|
29
|
+
*/
|
|
30
|
+
delete<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method'>): Promise<ApiResponse<T>>;
|
|
31
|
+
/**
|
|
32
|
+
* 通用请求方法
|
|
33
|
+
*/
|
|
34
|
+
request<T = unknown, D = unknown>(config: RequestConfig<D>): Promise<ApiResponse<T>>;
|
|
35
|
+
/**
|
|
36
|
+
* 添加请求拦截器
|
|
37
|
+
*/
|
|
38
|
+
addRequestInterceptor(interceptor: RequestInterceptor): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* 添加响应拦截器
|
|
41
|
+
*/
|
|
42
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): () => void;
|
|
43
|
+
/**
|
|
44
|
+
* 克隆客户端
|
|
45
|
+
* 注意:克隆会创建新的拦截器数组,但共享同一个适配器实例
|
|
46
|
+
* 如需独立的适配器,请使用 new HttpClient() 创建新实例
|
|
47
|
+
*/
|
|
48
|
+
clone(): IHttpClient;
|
|
49
|
+
/**
|
|
50
|
+
* 规范化配置
|
|
51
|
+
*/
|
|
52
|
+
protected normalizeConfig<D>(config: RequestConfig<D>): RequestConfig<D>;
|
|
53
|
+
/**
|
|
54
|
+
* 获取适配器
|
|
55
|
+
*/
|
|
56
|
+
protected getAdapter(): AxiosAdapter;
|
|
57
|
+
/**
|
|
58
|
+
* 处理旧版拦截器的请求(向后兼容)
|
|
59
|
+
* 此方法被 BeLinkClient 和 LiveClient 共享
|
|
60
|
+
* @protected 允许子类调用
|
|
61
|
+
*/
|
|
62
|
+
protected requestWithLegacyInterceptors<T>(config: IConfig): Promise<ApiResponse<T>>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../src/application/clients/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,aAAa,EAA8B,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACpG,OAAO,EAAE,WAAW,EAAmB,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAU1E;;;GAGG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC5C,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;IAChC,SAAS,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAM;IACzD,SAAS,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAAM;gBAE/C,OAAO,CAAC,EAAE,YAAY;IAIlC;;OAEG;IACU,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAInH;;OAEG;IACU,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EACxC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,CAAC,EACR,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC,GACzD,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAI1B;;OAEG;IACU,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EACvC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,CAAC,EACR,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC,GACzD,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAI1B;;OAEG;IACU,MAAM,CAAC,CAAC,GAAG,OAAO,EAC7B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,QAAQ,CAAC,GAC7C,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAI1B;;OAEG;IACU,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAkDjG;;OAEG;IACI,qBAAqB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,IAAI;IAYzE;;OAEG;IACI,sBAAsB,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM,IAAI;IAY3E;;;;OAIG;IACI,KAAK,IAAI,WAAW;IAO3B;;OAEG;IACH,SAAS,CAAC,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IASxE;;OAEG;IACH,SAAS,CAAC,UAAU,IAAI,YAAY;IAIpC;;;;OAIG;cACa,6BAA6B,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAoC3F"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpClient } from './HttpClient';
|
|
2
|
+
import { RequestConfig, IConfig } from '../../core/types/request.types';
|
|
3
|
+
import { ApiResponse } from '../../core/types/response.types';
|
|
4
|
+
/**
|
|
5
|
+
* BeLink 直播请求客户端
|
|
6
|
+
* 简化版客户端,无认证逻辑
|
|
7
|
+
*/
|
|
8
|
+
export declare class LiveClient extends HttpClient {
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* 重写请求方法(向后兼容旧版 API)
|
|
12
|
+
*/
|
|
13
|
+
request<T = unknown>(config: RequestConfig | IConfig): Promise<ApiResponse<T>>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=LiveClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveClient.d.ts","sourceRoot":"","sources":["../../../src/application/clients/LiveClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D;;;GAGG;AACH,qBAAa,UAAW,SAAQ,UAAU;;IAKxC;;OAEG;IACU,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAQ5F"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ResponseInterceptor, ResponseContext, RequestError } from '../../core/types';
|
|
2
|
+
import { IConfigManager } from '../../core/interfaces';
|
|
3
|
+
import { TimeSyncService } from '../../infrastructure/services/TimeSyncService';
|
|
4
|
+
/**
|
|
5
|
+
* 认证拦截器配置
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthInterceptorOptions {
|
|
8
|
+
priority?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 认证拦截器
|
|
12
|
+
* 负责处理 401 未授权响应
|
|
13
|
+
*/
|
|
14
|
+
export declare class AuthInterceptor implements ResponseInterceptor {
|
|
15
|
+
name: string;
|
|
16
|
+
priority: number;
|
|
17
|
+
private configManager;
|
|
18
|
+
private timeSyncService;
|
|
19
|
+
constructor(configManager: IConfigManager, timeSyncService: TimeSyncService, options?: AuthInterceptorOptions);
|
|
20
|
+
onResponse<T>(context: ResponseContext<T>): Promise<ResponseContext<T>>;
|
|
21
|
+
onResponseError(error: RequestError | Error): Promise<never>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=AuthInterceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthInterceptor.d.ts","sourceRoot":"","sources":["../../../src/application/interceptors/AuthInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,eAAgB,YAAW,mBAAmB;IAClD,IAAI,SAAqB;IACzB,QAAQ,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,eAAe,CAAkB;gBAE7B,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAMhG,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAIvE,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;CAsB1E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RequestInterceptor, RequestContext } from '../../core/types';
|
|
2
|
+
import { TimeSyncService } from '../../infrastructure/services/TimeSyncService';
|
|
3
|
+
/**
|
|
4
|
+
* 时间同步拦截器配置
|
|
5
|
+
*/
|
|
6
|
+
export interface TimeInterceptorOptions {
|
|
7
|
+
priority?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 时间同步拦截器
|
|
11
|
+
* 负责同步服务器时间并注入请求头
|
|
12
|
+
*/
|
|
13
|
+
export declare class TimeInterceptor implements RequestInterceptor {
|
|
14
|
+
name: string;
|
|
15
|
+
priority: number;
|
|
16
|
+
private timeSyncService;
|
|
17
|
+
constructor(timeSyncService: TimeSyncService, options?: TimeInterceptorOptions);
|
|
18
|
+
onRequest(context: RequestContext): Promise<RequestContext>;
|
|
19
|
+
onRequestError(error: Error): Promise<never>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=TimeInterceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeInterceptor.d.ts","sourceRoot":"","sources":["../../../src/application/interceptors/TimeInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,eAAgB,YAAW,kBAAkB;IACjD,IAAI,SAAqB;IACzB,QAAQ,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,eAAe,CAAkB;gBAE7B,eAAe,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAKjE,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAgB3D,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;CAG1D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RequestInterceptor, RequestContext } from '../../core/types';
|
|
2
|
+
import { IEncryptionService } from '../../core/interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Token 拦截器配置
|
|
5
|
+
*/
|
|
6
|
+
export interface TokenInterceptorOptions {
|
|
7
|
+
priority?: number;
|
|
8
|
+
headerName?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Token 拦截器
|
|
12
|
+
* 负责将 Token 加密后注入请求头
|
|
13
|
+
*/
|
|
14
|
+
export declare class TokenInterceptor implements RequestInterceptor {
|
|
15
|
+
name: string;
|
|
16
|
+
priority: number;
|
|
17
|
+
private tokenProvider;
|
|
18
|
+
private encryptionService;
|
|
19
|
+
private headerName;
|
|
20
|
+
constructor(tokenProvider: () => string | null, encryptionService: IEncryptionService, options?: TokenInterceptorOptions);
|
|
21
|
+
onRequest(context: RequestContext): Promise<RequestContext>;
|
|
22
|
+
onRequestError(error: Error): Promise<never>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=TokenInterceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenInterceptor.d.ts","sourceRoot":"","sources":["../../../src/application/interceptors/TokenInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG3D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,kBAAkB;IAClD,IAAI,SAAsB;IAC1B,QAAQ,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,iBAAiB,CAAqB;IAC9C,OAAO,CAAC,UAAU,CAAS;gBAGzB,aAAa,EAAE,MAAM,MAAM,GAAG,IAAI,EAClC,iBAAiB,EAAE,kBAAkB,EACrC,OAAO,CAAC,EAAE,uBAAuB;IAQtB,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAgB3D,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;CAG1D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用户信息类型
|
|
3
|
+
*/
|
|
4
|
+
interface UserInfo {
|
|
5
|
+
name: string;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 用户信息服务
|
|
10
|
+
* 单例模式,用于存储和获取当前用户信息
|
|
11
|
+
*/
|
|
12
|
+
declare class UserInfoService {
|
|
13
|
+
private userInfo;
|
|
14
|
+
/**
|
|
15
|
+
* 初始化用户信息
|
|
16
|
+
*/
|
|
17
|
+
init(userInfo: UserInfo): void;
|
|
18
|
+
/**
|
|
19
|
+
* 获取用户信息
|
|
20
|
+
*/
|
|
21
|
+
getParams(): UserInfo;
|
|
22
|
+
/**
|
|
23
|
+
* 更新用户信息
|
|
24
|
+
*/
|
|
25
|
+
update(userInfo: Partial<UserInfo>): void;
|
|
26
|
+
/**
|
|
27
|
+
* 清除用户信息
|
|
28
|
+
*/
|
|
29
|
+
clear(): void;
|
|
30
|
+
}
|
|
31
|
+
declare const beLinkUserInfo: UserInfoService;
|
|
32
|
+
export default beLinkUserInfo;
|
|
33
|
+
//# sourceMappingURL=UserInfoService.d.ts.map
|