sa2kit 1.0.0 → 1.0.2
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/UniversalFileService-CEZRJ87g.d.mts +727 -0
- package/dist/UniversalFileService-CEZRJ87g.d.ts +727 -0
- package/dist/api/index.d.mts +248 -0
- package/dist/api/index.d.ts +248 -0
- package/dist/api/index.js +294 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.mjs +290 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/auth/client/index.d.mts +52 -3
- package/dist/auth/client/index.d.ts +52 -3
- package/dist/auth/components/index.d.mts +149 -4
- package/dist/auth/components/index.d.ts +149 -4
- package/dist/auth/components/index.js +243 -9
- package/dist/auth/components/index.js.map +1 -1
- package/dist/auth/components/index.mjs +237 -4
- package/dist/auth/components/index.mjs.map +1 -1
- package/dist/auth/hooks/index.d.mts +31 -2
- package/dist/auth/hooks/index.d.ts +31 -2
- package/dist/auth/index.d.mts +5 -5
- package/dist/auth/index.d.ts +5 -5
- package/dist/auth/index.js +49 -17
- package/dist/auth/index.mjs +1 -1
- package/dist/auth/routes/index.d.mts +103 -5
- package/dist/auth/routes/index.d.ts +103 -5
- package/dist/auth/routes/index.js +37 -5
- package/dist/auth/routes/index.mjs +1 -1
- package/dist/chunk-42IJ7HEI.js +573 -0
- package/dist/chunk-42IJ7HEI.js.map +1 -0
- package/dist/chunk-7XLFSPDG.mjs +31 -0
- package/dist/chunk-7XLFSPDG.mjs.map +1 -0
- package/dist/chunk-GCVOKQZP.js +36 -0
- package/dist/chunk-GCVOKQZP.js.map +1 -0
- package/dist/chunk-IBLB7ARJ.mjs +560 -0
- package/dist/chunk-IBLB7ARJ.mjs.map +1 -0
- package/dist/{chunk-6FNUWAIV.js → chunk-LX4XX6W7.js} +54 -8
- package/dist/chunk-LX4XX6W7.js.map +1 -0
- package/dist/{chunk-HXFFYNIF.mjs → chunk-T5OZHYVM.mjs} +54 -8
- package/dist/chunk-T5OZHYVM.mjs.map +1 -0
- package/dist/config/server/index.d.mts +1533 -0
- package/dist/config/server/index.d.ts +1533 -0
- package/dist/config/server/index.js +1177 -0
- package/dist/config/server/index.js.map +1 -0
- package/dist/config/server/index.mjs +1138 -0
- package/dist/config/server/index.mjs.map +1 -0
- package/dist/i18n/index.d.mts +2 -1
- package/dist/i18n/index.d.ts +2 -1
- package/dist/i18n/index.js +125 -61
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/index.mjs +126 -62
- package/dist/i18n/index.mjs.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +1 -1
- package/dist/mmd/index.d.mts +346 -0
- package/dist/mmd/index.d.ts +346 -0
- package/dist/mmd/index.js +1535 -0
- package/dist/mmd/index.js.map +1 -0
- package/dist/mmd/index.mjs +1503 -0
- package/dist/mmd/index.mjs.map +1 -0
- package/dist/storage/index.d.mts +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +9 -9
- package/dist/storage/index.mjs +1 -1
- package/dist/{index-8VoHap_4.d.mts → types-CroexXnI.d.ts} +38 -44
- package/dist/{index-8VoHap_4.d.ts → types-DmsXCWvm.d.mts} +38 -44
- package/dist/{types-DAxQ1MeY.d.ts → types-Dt0oqeFM.d.mts} +1 -1
- package/dist/{types-DT8LVCvE.d.mts → types-zK6kDzDQ.d.ts} +1 -1
- package/dist/universalExport/index.js +17 -32
- package/dist/universalExport/index.js.map +1 -1
- package/dist/universalExport/index.mjs +2 -29
- package/dist/universalExport/index.mjs.map +1 -1
- package/dist/universalExport/server/index.d.mts +849 -8
- package/dist/universalExport/server/index.d.ts +849 -8
- package/dist/universalExport/server/index.js +1382 -2
- package/dist/universalExport/server/index.js.map +1 -1
- package/dist/universalExport/server/index.mjs +1355 -3
- package/dist/universalExport/server/index.mjs.map +1 -1
- package/dist/universalFile/index.d.mts +54 -3
- package/dist/universalFile/index.d.ts +54 -3
- package/dist/universalFile/index.js +272 -0
- package/dist/universalFile/index.js.map +1 -1
- package/dist/universalFile/index.mjs +267 -1
- package/dist/universalFile/index.mjs.map +1 -1
- package/dist/universalFile/server/index.d.mts +2541 -469
- package/dist/universalFile/server/index.d.ts +2541 -469
- package/dist/universalFile/server/index.js +830 -64
- package/dist/universalFile/server/index.js.map +1 -1
- package/dist/universalFile/server/index.mjs +803 -66
- package/dist/universalFile/server/index.mjs.map +1 -1
- package/package.json +47 -23
- package/dist/chunk-6FNUWAIV.js.map +0 -1
- package/dist/chunk-APY57REU.js +0 -300
- package/dist/chunk-APY57REU.js.map +0 -1
- package/dist/chunk-C64RY2OW.mjs +0 -295
- package/dist/chunk-C64RY2OW.mjs.map +0 -1
- package/dist/chunk-HXFFYNIF.mjs.map +0 -1
- package/dist/types-CoGG1rNV.d.mts +0 -258
- package/dist/types-CoGG1rNV.d.ts +0 -258
- package/dist/types-DW9qar-w.d.mts +0 -52
- package/dist/types-DW9qar-w.d.ts +0 -52
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { S as StorageAdapter } from '../types-BaZccpvk.mjs';
|
|
2
|
+
import { R as RequestAdapter, a as RequestConfig } from '../types-CbTsi9CZ.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* API 通用类型定义
|
|
6
|
+
* Common API Types
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* API 响应类型
|
|
10
|
+
* Generic API Response Format
|
|
11
|
+
*/
|
|
12
|
+
interface ApiResponse<T = any> {
|
|
13
|
+
success: boolean;
|
|
14
|
+
data?: T;
|
|
15
|
+
error?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
meta?: {
|
|
18
|
+
pagination?: {
|
|
19
|
+
page: number;
|
|
20
|
+
limit: number;
|
|
21
|
+
total: number;
|
|
22
|
+
pages: number;
|
|
23
|
+
};
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 分页参数类型
|
|
29
|
+
* Pagination Parameters
|
|
30
|
+
*/
|
|
31
|
+
interface PaginationParams {
|
|
32
|
+
page?: number;
|
|
33
|
+
limit?: number;
|
|
34
|
+
search?: string;
|
|
35
|
+
sortBy?: string;
|
|
36
|
+
sortOrder?: 'asc' | 'desc';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 认证响应类型(泛型)
|
|
40
|
+
* Generic Auth Response
|
|
41
|
+
*/
|
|
42
|
+
interface AuthResponse<TUser = any> {
|
|
43
|
+
user: TUser;
|
|
44
|
+
token: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 默认存储键常量
|
|
48
|
+
* Default Storage Keys
|
|
49
|
+
*/
|
|
50
|
+
declare const DEFAULT_STORAGE_KEYS: {
|
|
51
|
+
readonly AUTH_TOKEN: "auth_token";
|
|
52
|
+
readonly USER_DATA: "user_data";
|
|
53
|
+
readonly REFRESH_TOKEN: "refresh_token";
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* 存储键类型(可扩展)
|
|
57
|
+
* Storage Keys Type
|
|
58
|
+
*/
|
|
59
|
+
type StorageKeys = typeof DEFAULT_STORAGE_KEYS;
|
|
60
|
+
/**
|
|
61
|
+
* API 路由配置
|
|
62
|
+
* API Routes Configuration
|
|
63
|
+
*/
|
|
64
|
+
interface ApiRoutes {
|
|
65
|
+
/** 认证相关路由 */
|
|
66
|
+
auth?: {
|
|
67
|
+
login?: string;
|
|
68
|
+
logout?: string;
|
|
69
|
+
register?: string;
|
|
70
|
+
me?: string;
|
|
71
|
+
};
|
|
72
|
+
/** 用户相关路由 */
|
|
73
|
+
users?: {
|
|
74
|
+
list?: string;
|
|
75
|
+
detail?: (id: string) => string;
|
|
76
|
+
update?: (id: string) => string;
|
|
77
|
+
delete?: (id: string) => string;
|
|
78
|
+
};
|
|
79
|
+
/** 自定义路由 */
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 默认 API 路由
|
|
84
|
+
*/
|
|
85
|
+
declare const DEFAULT_API_ROUTES: ApiRoutes;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 基础 API 客户端(泛型)
|
|
89
|
+
* Base API Client (Generic)
|
|
90
|
+
*
|
|
91
|
+
* 提供统一的 API 调用逻辑,通过适配器模式支持多平台
|
|
92
|
+
* 使用泛型 TUser 支持不同项目的用户类型
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 基础 API 客户端配置
|
|
97
|
+
*/
|
|
98
|
+
interface BaseApiClientConfig {
|
|
99
|
+
/** 基础 URL */
|
|
100
|
+
baseUrl: string;
|
|
101
|
+
/** 存储适配器 */
|
|
102
|
+
storage: StorageAdapter;
|
|
103
|
+
/** 请求适配器 */
|
|
104
|
+
request: RequestAdapter;
|
|
105
|
+
/** 自定义存储键(可选) */
|
|
106
|
+
storageKeys?: Partial<StorageKeys>;
|
|
107
|
+
/** API 路由配置(可选) */
|
|
108
|
+
routes?: ApiRoutes;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 基础 API 客户端
|
|
112
|
+
* @template TUser 用户类型(泛型)
|
|
113
|
+
*/
|
|
114
|
+
declare class BaseApiClient<TUser = any> {
|
|
115
|
+
protected token: string | null;
|
|
116
|
+
protected user: TUser | null;
|
|
117
|
+
protected baseUrl: string;
|
|
118
|
+
protected storage: StorageAdapter;
|
|
119
|
+
protected request: RequestAdapter;
|
|
120
|
+
protected storageKeys: StorageKeys;
|
|
121
|
+
protected routes: ApiRoutes;
|
|
122
|
+
constructor(config: BaseApiClientConfig);
|
|
123
|
+
/**
|
|
124
|
+
* 初始化 - 从存储中加载 token 和用户信息
|
|
125
|
+
*/
|
|
126
|
+
init(): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* 设置认证 token
|
|
129
|
+
*/
|
|
130
|
+
setToken(token: string | null): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* 设置用户信息
|
|
133
|
+
*/
|
|
134
|
+
setUser(user: TUser | null): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* 获取当前 token
|
|
137
|
+
*/
|
|
138
|
+
getToken(): string | null;
|
|
139
|
+
/**
|
|
140
|
+
* 获取当前用户
|
|
141
|
+
*/
|
|
142
|
+
getUser(): TUser | null;
|
|
143
|
+
/**
|
|
144
|
+
* 检查是否已登录
|
|
145
|
+
*/
|
|
146
|
+
isAuthenticated(): Promise<boolean>;
|
|
147
|
+
/**
|
|
148
|
+
* 清除用户数据
|
|
149
|
+
*/
|
|
150
|
+
clearUserData(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* 发送请求的通用方法
|
|
153
|
+
*/
|
|
154
|
+
protected sendRequest<T = any>(config: RequestConfig): Promise<ApiResponse<T>>;
|
|
155
|
+
/**
|
|
156
|
+
* 发送 GET 请求
|
|
157
|
+
*/
|
|
158
|
+
get<T = any>(url: string, params?: Record<string, any>): Promise<ApiResponse<T>>;
|
|
159
|
+
/**
|
|
160
|
+
* 发送 POST 请求
|
|
161
|
+
*/
|
|
162
|
+
post<T = any>(url: string, body?: any): Promise<ApiResponse<T>>;
|
|
163
|
+
/**
|
|
164
|
+
* 发送 PUT 请求
|
|
165
|
+
*/
|
|
166
|
+
put<T = any>(url: string, body?: any): Promise<ApiResponse<T>>;
|
|
167
|
+
/**
|
|
168
|
+
* 发送 PATCH 请求
|
|
169
|
+
*/
|
|
170
|
+
patch<T = any>(url: string, body?: any): Promise<ApiResponse<T>>;
|
|
171
|
+
/**
|
|
172
|
+
* 发送 DELETE 请求
|
|
173
|
+
*/
|
|
174
|
+
delete<T = any>(url: string): Promise<ApiResponse<T>>;
|
|
175
|
+
/**
|
|
176
|
+
* 用户注册
|
|
177
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
178
|
+
*/
|
|
179
|
+
register(email: string, password: string, username: string): Promise<ApiResponse<AuthResponse<TUser>>>;
|
|
180
|
+
/**
|
|
181
|
+
* 用户登录
|
|
182
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
183
|
+
*/
|
|
184
|
+
login(email: string, password: string): Promise<ApiResponse<AuthResponse<TUser>>>;
|
|
185
|
+
/**
|
|
186
|
+
* 用户退出登录
|
|
187
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
188
|
+
*/
|
|
189
|
+
logout(): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* 获取当前用户信息
|
|
192
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
193
|
+
*/
|
|
194
|
+
getCurrentUser(): Promise<ApiResponse<TUser>>;
|
|
195
|
+
/**
|
|
196
|
+
* 获取用户列表
|
|
197
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
198
|
+
*/
|
|
199
|
+
getUsers(params?: {
|
|
200
|
+
page?: number;
|
|
201
|
+
limit?: number;
|
|
202
|
+
search?: string;
|
|
203
|
+
}): Promise<ApiResponse<{
|
|
204
|
+
users: TUser[];
|
|
205
|
+
total: number;
|
|
206
|
+
}>>;
|
|
207
|
+
/**
|
|
208
|
+
* 获取用户详情
|
|
209
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
210
|
+
*/
|
|
211
|
+
getUserById(userId: string): Promise<ApiResponse<TUser>>;
|
|
212
|
+
/**
|
|
213
|
+
* 更新用户信息
|
|
214
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
215
|
+
*/
|
|
216
|
+
updateUser(userId: string, data: Partial<TUser>): Promise<ApiResponse<TUser>>;
|
|
217
|
+
/**
|
|
218
|
+
* 删除用户
|
|
219
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
220
|
+
*/
|
|
221
|
+
deleteUser(userId: string): Promise<ApiResponse<void>>;
|
|
222
|
+
/**
|
|
223
|
+
* 请求前钩子(子类可重写)
|
|
224
|
+
*/
|
|
225
|
+
protected onBeforeRequest?(config: RequestConfig): Promise<RequestConfig>;
|
|
226
|
+
/**
|
|
227
|
+
* 请求后钩子(子类可重写)
|
|
228
|
+
*/
|
|
229
|
+
protected onAfterRequest?<T>(response: ApiResponse<T>): Promise<ApiResponse<T>>;
|
|
230
|
+
/**
|
|
231
|
+
* 请求错误钩子(子类可重写)
|
|
232
|
+
*/
|
|
233
|
+
protected onRequestError?(error: Error): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* 认证成功钩子(子类可重写)
|
|
236
|
+
*/
|
|
237
|
+
protected onAuthSuccess?(user: TUser, token: string): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* 认证失败钩子(子类可重写)
|
|
240
|
+
*/
|
|
241
|
+
protected onAuthError?(error: string): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* 登出钩子(子类可重写)
|
|
244
|
+
*/
|
|
245
|
+
protected onLogout?(): Promise<void>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export { type ApiResponse, type ApiRoutes, type AuthResponse, BaseApiClient, type BaseApiClientConfig, DEFAULT_API_ROUTES, DEFAULT_STORAGE_KEYS, type PaginationParams, RequestAdapter, RequestConfig, StorageAdapter, type StorageKeys };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { S as StorageAdapter } from '../types-BaZccpvk.js';
|
|
2
|
+
import { R as RequestAdapter, a as RequestConfig } from '../types-CbTsi9CZ.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* API 通用类型定义
|
|
6
|
+
* Common API Types
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* API 响应类型
|
|
10
|
+
* Generic API Response Format
|
|
11
|
+
*/
|
|
12
|
+
interface ApiResponse<T = any> {
|
|
13
|
+
success: boolean;
|
|
14
|
+
data?: T;
|
|
15
|
+
error?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
meta?: {
|
|
18
|
+
pagination?: {
|
|
19
|
+
page: number;
|
|
20
|
+
limit: number;
|
|
21
|
+
total: number;
|
|
22
|
+
pages: number;
|
|
23
|
+
};
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 分页参数类型
|
|
29
|
+
* Pagination Parameters
|
|
30
|
+
*/
|
|
31
|
+
interface PaginationParams {
|
|
32
|
+
page?: number;
|
|
33
|
+
limit?: number;
|
|
34
|
+
search?: string;
|
|
35
|
+
sortBy?: string;
|
|
36
|
+
sortOrder?: 'asc' | 'desc';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 认证响应类型(泛型)
|
|
40
|
+
* Generic Auth Response
|
|
41
|
+
*/
|
|
42
|
+
interface AuthResponse<TUser = any> {
|
|
43
|
+
user: TUser;
|
|
44
|
+
token: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 默认存储键常量
|
|
48
|
+
* Default Storage Keys
|
|
49
|
+
*/
|
|
50
|
+
declare const DEFAULT_STORAGE_KEYS: {
|
|
51
|
+
readonly AUTH_TOKEN: "auth_token";
|
|
52
|
+
readonly USER_DATA: "user_data";
|
|
53
|
+
readonly REFRESH_TOKEN: "refresh_token";
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* 存储键类型(可扩展)
|
|
57
|
+
* Storage Keys Type
|
|
58
|
+
*/
|
|
59
|
+
type StorageKeys = typeof DEFAULT_STORAGE_KEYS;
|
|
60
|
+
/**
|
|
61
|
+
* API 路由配置
|
|
62
|
+
* API Routes Configuration
|
|
63
|
+
*/
|
|
64
|
+
interface ApiRoutes {
|
|
65
|
+
/** 认证相关路由 */
|
|
66
|
+
auth?: {
|
|
67
|
+
login?: string;
|
|
68
|
+
logout?: string;
|
|
69
|
+
register?: string;
|
|
70
|
+
me?: string;
|
|
71
|
+
};
|
|
72
|
+
/** 用户相关路由 */
|
|
73
|
+
users?: {
|
|
74
|
+
list?: string;
|
|
75
|
+
detail?: (id: string) => string;
|
|
76
|
+
update?: (id: string) => string;
|
|
77
|
+
delete?: (id: string) => string;
|
|
78
|
+
};
|
|
79
|
+
/** 自定义路由 */
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 默认 API 路由
|
|
84
|
+
*/
|
|
85
|
+
declare const DEFAULT_API_ROUTES: ApiRoutes;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 基础 API 客户端(泛型)
|
|
89
|
+
* Base API Client (Generic)
|
|
90
|
+
*
|
|
91
|
+
* 提供统一的 API 调用逻辑,通过适配器模式支持多平台
|
|
92
|
+
* 使用泛型 TUser 支持不同项目的用户类型
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 基础 API 客户端配置
|
|
97
|
+
*/
|
|
98
|
+
interface BaseApiClientConfig {
|
|
99
|
+
/** 基础 URL */
|
|
100
|
+
baseUrl: string;
|
|
101
|
+
/** 存储适配器 */
|
|
102
|
+
storage: StorageAdapter;
|
|
103
|
+
/** 请求适配器 */
|
|
104
|
+
request: RequestAdapter;
|
|
105
|
+
/** 自定义存储键(可选) */
|
|
106
|
+
storageKeys?: Partial<StorageKeys>;
|
|
107
|
+
/** API 路由配置(可选) */
|
|
108
|
+
routes?: ApiRoutes;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 基础 API 客户端
|
|
112
|
+
* @template TUser 用户类型(泛型)
|
|
113
|
+
*/
|
|
114
|
+
declare class BaseApiClient<TUser = any> {
|
|
115
|
+
protected token: string | null;
|
|
116
|
+
protected user: TUser | null;
|
|
117
|
+
protected baseUrl: string;
|
|
118
|
+
protected storage: StorageAdapter;
|
|
119
|
+
protected request: RequestAdapter;
|
|
120
|
+
protected storageKeys: StorageKeys;
|
|
121
|
+
protected routes: ApiRoutes;
|
|
122
|
+
constructor(config: BaseApiClientConfig);
|
|
123
|
+
/**
|
|
124
|
+
* 初始化 - 从存储中加载 token 和用户信息
|
|
125
|
+
*/
|
|
126
|
+
init(): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* 设置认证 token
|
|
129
|
+
*/
|
|
130
|
+
setToken(token: string | null): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* 设置用户信息
|
|
133
|
+
*/
|
|
134
|
+
setUser(user: TUser | null): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* 获取当前 token
|
|
137
|
+
*/
|
|
138
|
+
getToken(): string | null;
|
|
139
|
+
/**
|
|
140
|
+
* 获取当前用户
|
|
141
|
+
*/
|
|
142
|
+
getUser(): TUser | null;
|
|
143
|
+
/**
|
|
144
|
+
* 检查是否已登录
|
|
145
|
+
*/
|
|
146
|
+
isAuthenticated(): Promise<boolean>;
|
|
147
|
+
/**
|
|
148
|
+
* 清除用户数据
|
|
149
|
+
*/
|
|
150
|
+
clearUserData(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* 发送请求的通用方法
|
|
153
|
+
*/
|
|
154
|
+
protected sendRequest<T = any>(config: RequestConfig): Promise<ApiResponse<T>>;
|
|
155
|
+
/**
|
|
156
|
+
* 发送 GET 请求
|
|
157
|
+
*/
|
|
158
|
+
get<T = any>(url: string, params?: Record<string, any>): Promise<ApiResponse<T>>;
|
|
159
|
+
/**
|
|
160
|
+
* 发送 POST 请求
|
|
161
|
+
*/
|
|
162
|
+
post<T = any>(url: string, body?: any): Promise<ApiResponse<T>>;
|
|
163
|
+
/**
|
|
164
|
+
* 发送 PUT 请求
|
|
165
|
+
*/
|
|
166
|
+
put<T = any>(url: string, body?: any): Promise<ApiResponse<T>>;
|
|
167
|
+
/**
|
|
168
|
+
* 发送 PATCH 请求
|
|
169
|
+
*/
|
|
170
|
+
patch<T = any>(url: string, body?: any): Promise<ApiResponse<T>>;
|
|
171
|
+
/**
|
|
172
|
+
* 发送 DELETE 请求
|
|
173
|
+
*/
|
|
174
|
+
delete<T = any>(url: string): Promise<ApiResponse<T>>;
|
|
175
|
+
/**
|
|
176
|
+
* 用户注册
|
|
177
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
178
|
+
*/
|
|
179
|
+
register(email: string, password: string, username: string): Promise<ApiResponse<AuthResponse<TUser>>>;
|
|
180
|
+
/**
|
|
181
|
+
* 用户登录
|
|
182
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
183
|
+
*/
|
|
184
|
+
login(email: string, password: string): Promise<ApiResponse<AuthResponse<TUser>>>;
|
|
185
|
+
/**
|
|
186
|
+
* 用户退出登录
|
|
187
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
188
|
+
*/
|
|
189
|
+
logout(): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* 获取当前用户信息
|
|
192
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
193
|
+
*/
|
|
194
|
+
getCurrentUser(): Promise<ApiResponse<TUser>>;
|
|
195
|
+
/**
|
|
196
|
+
* 获取用户列表
|
|
197
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
198
|
+
*/
|
|
199
|
+
getUsers(params?: {
|
|
200
|
+
page?: number;
|
|
201
|
+
limit?: number;
|
|
202
|
+
search?: string;
|
|
203
|
+
}): Promise<ApiResponse<{
|
|
204
|
+
users: TUser[];
|
|
205
|
+
total: number;
|
|
206
|
+
}>>;
|
|
207
|
+
/**
|
|
208
|
+
* 获取用户详情
|
|
209
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
210
|
+
*/
|
|
211
|
+
getUserById(userId: string): Promise<ApiResponse<TUser>>;
|
|
212
|
+
/**
|
|
213
|
+
* 更新用户信息
|
|
214
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
215
|
+
*/
|
|
216
|
+
updateUser(userId: string, data: Partial<TUser>): Promise<ApiResponse<TUser>>;
|
|
217
|
+
/**
|
|
218
|
+
* 删除用户
|
|
219
|
+
* 默认实现,子类可重写以添加自定义逻辑
|
|
220
|
+
*/
|
|
221
|
+
deleteUser(userId: string): Promise<ApiResponse<void>>;
|
|
222
|
+
/**
|
|
223
|
+
* 请求前钩子(子类可重写)
|
|
224
|
+
*/
|
|
225
|
+
protected onBeforeRequest?(config: RequestConfig): Promise<RequestConfig>;
|
|
226
|
+
/**
|
|
227
|
+
* 请求后钩子(子类可重写)
|
|
228
|
+
*/
|
|
229
|
+
protected onAfterRequest?<T>(response: ApiResponse<T>): Promise<ApiResponse<T>>;
|
|
230
|
+
/**
|
|
231
|
+
* 请求错误钩子(子类可重写)
|
|
232
|
+
*/
|
|
233
|
+
protected onRequestError?(error: Error): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* 认证成功钩子(子类可重写)
|
|
236
|
+
*/
|
|
237
|
+
protected onAuthSuccess?(user: TUser, token: string): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* 认证失败钩子(子类可重写)
|
|
240
|
+
*/
|
|
241
|
+
protected onAuthError?(error: string): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* 登出钩子(子类可重写)
|
|
244
|
+
*/
|
|
245
|
+
protected onLogout?(): Promise<void>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export { type ApiResponse, type ApiRoutes, type AuthResponse, BaseApiClient, type BaseApiClientConfig, DEFAULT_API_ROUTES, DEFAULT_STORAGE_KEYS, type PaginationParams, RequestAdapter, RequestConfig, StorageAdapter, type StorageKeys };
|