@hlw-uni-mp/request 1.0.5 → 1.0.8
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 +132 -190
- package/dist/index.d.ts +132 -190
- package/dist/index.js +126 -272
- package/dist/index.mjs +121 -264
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -2,52 +2,56 @@
|
|
|
2
2
|
* 设备信息定义
|
|
3
3
|
*/
|
|
4
4
|
interface DeviceInfo {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
appid: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
version: string;
|
|
8
|
+
versionCode: string;
|
|
9
|
+
channel: string;
|
|
10
|
+
deviceId: string;
|
|
11
|
+
deviceType: string;
|
|
12
|
+
deviceOrientation: 'portrait' | 'landscape';
|
|
13
|
+
brand: string;
|
|
14
|
+
model: string;
|
|
15
|
+
system: string;
|
|
16
|
+
os: string;
|
|
17
|
+
pixelRatio: number;
|
|
18
|
+
screenWidth: number;
|
|
19
|
+
screenHeight: number;
|
|
20
|
+
windowWidth: number;
|
|
21
|
+
windowHeight: number;
|
|
22
|
+
statusBarHeight: number;
|
|
23
|
+
sdkVersion: string;
|
|
24
|
+
hostName: string;
|
|
25
|
+
hostVersion: string;
|
|
26
|
+
hostLanguage: string;
|
|
27
|
+
hostTheme: string;
|
|
28
|
+
platform: string;
|
|
29
|
+
language: string;
|
|
30
|
+
networkType: string;
|
|
31
|
+
benchmarkLevel: number;
|
|
32
|
+
theme: string;
|
|
33
|
+
fontSizeSetting: number;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
35
|
declare global {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
namespace UniNamespace {
|
|
37
|
+
interface GetDeviceInfoResult {
|
|
38
|
+
benchmarkLevel?: number;
|
|
39
|
+
}
|
|
40
|
+
interface GetAppBaseInfoResult {
|
|
41
|
+
appChannel?: string;
|
|
42
|
+
appLanguage?: string;
|
|
43
|
+
fontSizeSetting?: number;
|
|
44
|
+
}
|
|
45
|
+
interface GetWindowInfoResult {
|
|
46
|
+
deviceOrientation?: 'portrait' | 'landscape';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
50
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* 采集设备信息
|
|
52
|
+
* @returns 设备参数集
|
|
53
|
+
*/
|
|
54
|
+
declare function getDevice(): DeviceInfo;
|
|
51
55
|
|
|
52
56
|
/**
|
|
53
57
|
* SHA-256 哈希计算 (基于 crypto-js)
|
|
@@ -75,31 +79,49 @@ declare function calculateSign(options: SignOptions): string;
|
|
|
75
79
|
type HttpMethod = 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT'
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
|
-
*
|
|
82
|
+
* 请求配置选项
|
|
79
83
|
*/
|
|
80
84
|
interface RequestConfig {
|
|
85
|
+
/** 请求相对路径或完整 URL */
|
|
81
86
|
url: string
|
|
87
|
+
/** 请求方法,默认 GET */
|
|
82
88
|
method?: HttpMethod | string
|
|
89
|
+
/** 请求体数据 (POST/PUT) */
|
|
83
90
|
data?: unknown
|
|
91
|
+
/** URL 查询参数 (GET/DELETE) */
|
|
84
92
|
params?: unknown
|
|
93
|
+
/** 基础接口地址 */
|
|
85
94
|
baseURL?: string
|
|
95
|
+
/** 自定义请求头 */
|
|
86
96
|
headers?: Record<string, string>
|
|
97
|
+
/** 超时时间 (毫秒),默认 15000 */
|
|
87
98
|
timeout?: number
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
/** 兼容别名 */
|
|
102
|
+
type HttpConfig = RequestConfig
|
|
103
|
+
|
|
90
104
|
/**
|
|
91
|
-
*
|
|
105
|
+
* HTTP 原始响应包
|
|
92
106
|
*/
|
|
93
|
-
interface
|
|
107
|
+
interface HttpResponse<T = unknown> {
|
|
108
|
+
/** 响应数据主体 */
|
|
94
109
|
data: T
|
|
110
|
+
/** HTTP 状态码 */
|
|
95
111
|
status: number
|
|
112
|
+
/** 状态文本 */
|
|
96
113
|
statusText: string
|
|
114
|
+
/** 响应头字典 */
|
|
97
115
|
headers: Record<string, string>
|
|
116
|
+
/** 请求配置项 */
|
|
98
117
|
config: RequestConfig
|
|
99
118
|
}
|
|
100
119
|
|
|
120
|
+
/** 兼容别名 */
|
|
121
|
+
type AxiosResponse<T = unknown> = HttpResponse<T>
|
|
122
|
+
|
|
101
123
|
/**
|
|
102
|
-
*
|
|
124
|
+
* 拦截器处理器
|
|
103
125
|
*/
|
|
104
126
|
interface InterceptorHandler<T> {
|
|
105
127
|
fulfilled?: (value: T) => T | Promise<T>
|
|
@@ -110,69 +132,43 @@ interface InterceptorHandler<T> {
|
|
|
110
132
|
* 接口业务数据扩展标记(供各业务项目通过声明合并自由扩展)
|
|
111
133
|
*/
|
|
112
134
|
interface ApiResData {
|
|
113
|
-
/**
|
|
114
|
-
* 模态弹窗配置
|
|
115
|
-
*/
|
|
135
|
+
/** 模态弹窗配置 */
|
|
116
136
|
modal?: UniApp.ShowModalOptions
|
|
117
137
|
}
|
|
118
138
|
|
|
119
139
|
/**
|
|
120
|
-
*
|
|
140
|
+
* 统一接口返回数据结构
|
|
121
141
|
*/
|
|
122
142
|
interface ApiRes<T = unknown> {
|
|
123
|
-
/**
|
|
124
|
-
* 状态码数值 (1 为成功)
|
|
125
|
-
*/
|
|
143
|
+
/** 业务状态码 (1 为成功) */
|
|
126
144
|
code: number
|
|
127
|
-
/**
|
|
128
|
-
* 提示文本串
|
|
129
|
-
*/
|
|
145
|
+
/** 提示消息文本 */
|
|
130
146
|
msg: string
|
|
131
|
-
/**
|
|
132
|
-
* 数据业务体
|
|
133
|
-
*/
|
|
147
|
+
/** 核心业务数据体 */
|
|
134
148
|
data: T & ApiResData
|
|
135
|
-
/**
|
|
136
|
-
* 是否弹窗提示
|
|
137
|
-
*/
|
|
149
|
+
/** 是否弹窗提示 */
|
|
138
150
|
modal?: boolean
|
|
139
|
-
/**
|
|
140
|
-
* 模态弹窗配置
|
|
141
|
-
*/
|
|
151
|
+
/** 模态弹窗配置项 */
|
|
142
152
|
modalOptions?: UniApp.ShowModalOptions
|
|
143
153
|
}
|
|
144
154
|
|
|
145
155
|
/**
|
|
146
|
-
*
|
|
156
|
+
* 全局网络请求配置选项
|
|
147
157
|
*/
|
|
148
158
|
interface HttpOptions {
|
|
149
|
-
/**
|
|
150
|
-
* 基础接口路由
|
|
151
|
-
*/
|
|
159
|
+
/** 接口基础 URL 地址 */
|
|
152
160
|
baseURL?: string
|
|
153
|
-
/**
|
|
154
|
-
* 超时时间数值 (ms)
|
|
155
|
-
*/
|
|
161
|
+
/** 请求超时时间 (毫秒),默认 15000 */
|
|
156
162
|
timeout?: number
|
|
157
|
-
/**
|
|
158
|
-
* 获取凭证函数
|
|
159
|
-
*/
|
|
163
|
+
/** 动态获取当前用户登录凭证 (Token) */
|
|
160
164
|
getToken?: () => string
|
|
161
|
-
/**
|
|
162
|
-
* 获取设备函数
|
|
163
|
-
*/
|
|
165
|
+
/** 动态获取设备指纹上下文信息 */
|
|
164
166
|
getDevice?: () => DeviceInfo | Record<string, unknown>
|
|
165
|
-
/**
|
|
166
|
-
* 鉴权失败回调
|
|
167
|
-
*/
|
|
167
|
+
/** 登录失效 (401/403) 统一回调处理 */
|
|
168
168
|
onUnauthorized?: (message: string) => void
|
|
169
|
-
/**
|
|
170
|
-
* RSA 公钥(用于非对称加密 X-Client-Context)
|
|
171
|
-
*/
|
|
169
|
+
/** RSA 加密公钥(用于加密 X-Client-Context) */
|
|
172
170
|
publicKey?: string
|
|
173
|
-
/**
|
|
174
|
-
* 签名密钥(用于计算 X-Client-Sign)
|
|
175
|
-
*/
|
|
171
|
+
/** 请求签名密钥(用于计算 X-Client-Sign) */
|
|
176
172
|
secret?: string
|
|
177
173
|
}
|
|
178
174
|
|
|
@@ -187,14 +183,14 @@ interface UploadSignBase {
|
|
|
187
183
|
}
|
|
188
184
|
|
|
189
185
|
/**
|
|
190
|
-
*
|
|
186
|
+
* 本地存储上传凭据
|
|
191
187
|
*/
|
|
192
188
|
interface LocalUploadSign extends UploadSignBase {
|
|
193
189
|
type: 'local'
|
|
194
190
|
}
|
|
195
191
|
|
|
196
192
|
/**
|
|
197
|
-
*
|
|
193
|
+
* 阿里云 OSS 上传凭据
|
|
198
194
|
*/
|
|
199
195
|
interface AliossUploadSign extends UploadSignBase {
|
|
200
196
|
type: 'alioss'
|
|
@@ -205,7 +201,7 @@ interface AliossUploadSign extends UploadSignBase {
|
|
|
205
201
|
}
|
|
206
202
|
|
|
207
203
|
/**
|
|
208
|
-
*
|
|
204
|
+
* 七牛云上传凭据
|
|
209
205
|
*/
|
|
210
206
|
interface QiniuUploadSign extends UploadSignBase {
|
|
211
207
|
type: 'qiniu'
|
|
@@ -213,57 +209,28 @@ interface QiniuUploadSign extends UploadSignBase {
|
|
|
213
209
|
}
|
|
214
210
|
|
|
215
211
|
/**
|
|
216
|
-
*
|
|
212
|
+
* 统一上传签名凭据联合类型
|
|
217
213
|
*/
|
|
218
214
|
type UploadSign = LocalUploadSign | AliossUploadSign | QiniuUploadSign
|
|
219
215
|
|
|
220
216
|
/**
|
|
221
|
-
*
|
|
217
|
+
* 文件直传参数配置
|
|
222
218
|
*/
|
|
223
219
|
interface UploadFileParams {
|
|
224
|
-
/** 业务场景标识 */
|
|
220
|
+
/** 业务场景标识 (如 avatar, poster 等) */
|
|
225
221
|
biz: string
|
|
226
222
|
/** 本地文件路径 */
|
|
227
223
|
filePath: string
|
|
228
|
-
/**
|
|
224
|
+
/** 文件扩展名 (如 png, jpg) */
|
|
229
225
|
ext?: string
|
|
230
|
-
/**
|
|
226
|
+
/** 文件大小 (字节) */
|
|
231
227
|
size?: number
|
|
232
|
-
/**
|
|
228
|
+
/** 获取上传签名的接口地址,默认 /api/v1.upload/sign */
|
|
233
229
|
signUrl?: string
|
|
234
230
|
/** 自定义请求头 */
|
|
235
231
|
header?: Record<string, string>
|
|
236
232
|
}
|
|
237
233
|
|
|
238
|
-
/**
|
|
239
|
-
* 阿里配置项
|
|
240
|
-
*/
|
|
241
|
-
interface OssConfig {
|
|
242
|
-
/** 对象存储键 */
|
|
243
|
-
key?: string
|
|
244
|
-
/** 上传策略串 */
|
|
245
|
-
policy?: string
|
|
246
|
-
/** 身份标识符 */
|
|
247
|
-
OSSAccessKeyId?: string
|
|
248
|
-
/** 签名密文字 */
|
|
249
|
-
signature?: string
|
|
250
|
-
/** 主机服务址 */
|
|
251
|
-
host?: string
|
|
252
|
-
/** 文件访问址 */
|
|
253
|
-
url?: string
|
|
254
|
-
/** 目标文件名 */
|
|
255
|
-
filename?: string
|
|
256
|
-
/** 成功响应状态码 */
|
|
257
|
-
successActionStatus?: string
|
|
258
|
-
[key: string]: unknown
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 采集设备信息
|
|
263
|
-
* @returns 设备参数集
|
|
264
|
-
*/
|
|
265
|
-
declare function getDevice(): DeviceInfo;
|
|
266
|
-
|
|
267
234
|
/**
|
|
268
235
|
* 纯 TypeScript 实现的 RSA-2048 公钥分段加密(PKCS#1 v1.5 填充)
|
|
269
236
|
* 零第三方外部依赖,原生兼容小程序、浏览器与 Node 环境
|
|
@@ -276,17 +243,6 @@ declare function getDevice(): DeviceInfo;
|
|
|
276
243
|
*/
|
|
277
244
|
declare function encryptRsa(plaintext: string, publicKey: string): string;
|
|
278
245
|
|
|
279
|
-
/**
|
|
280
|
-
* 直传阿里云 OSS
|
|
281
|
-
* @param oss 阿里配置项
|
|
282
|
-
* @param source 源文件路径或文件对象
|
|
283
|
-
* @returns 资源访问地址
|
|
284
|
-
*/
|
|
285
|
-
declare function uploadOss(oss: OssConfig, source: string | {
|
|
286
|
-
path?: string;
|
|
287
|
-
tempFilePath?: string;
|
|
288
|
-
}): Promise<string>;
|
|
289
|
-
|
|
290
246
|
/**
|
|
291
247
|
* 请求上传凭证
|
|
292
248
|
* @param data 签名请求参数
|
|
@@ -317,83 +273,69 @@ declare function uploadFile(params: UploadFileParams): Promise<string>;
|
|
|
317
273
|
* 统一网络请求异常类
|
|
318
274
|
*/
|
|
319
275
|
declare class HttpError<T = unknown> extends Error {
|
|
320
|
-
response?:
|
|
276
|
+
response?: HttpResponse<T>;
|
|
321
277
|
status?: number;
|
|
322
278
|
config?: RequestConfig;
|
|
323
279
|
constructor(message: string, options?: {
|
|
324
|
-
response?:
|
|
280
|
+
response?: HttpResponse<T>;
|
|
325
281
|
status?: number;
|
|
326
282
|
config?: RequestConfig;
|
|
327
283
|
});
|
|
328
284
|
}
|
|
329
|
-
/**
|
|
330
|
-
* 拦截管理器
|
|
331
|
-
*/
|
|
332
|
-
declare class InterceptorManager<T> {
|
|
333
|
-
private handlers;
|
|
334
|
-
use(fulfilled?: (value: T) => T | Promise<T>, rejected?: (error: unknown) => unknown): number;
|
|
335
|
-
eject(id: number): void;
|
|
336
|
-
forEach(fn: (handler: InterceptorHandler<T>) => void): void;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* 原生请求客户端
|
|
340
|
-
*/
|
|
341
|
-
declare class UniHttpClient {
|
|
342
|
-
defaults: {
|
|
343
|
-
baseURL: string;
|
|
344
|
-
timeout: number;
|
|
345
|
-
headers: Record<string, string>;
|
|
346
|
-
};
|
|
347
|
-
interceptors: {
|
|
348
|
-
request: InterceptorManager<RequestConfig>;
|
|
349
|
-
response: InterceptorManager<AxiosResponse<unknown>>;
|
|
350
|
-
};
|
|
351
|
-
constructor(options?: {
|
|
352
|
-
baseURL?: string;
|
|
353
|
-
timeout?: number;
|
|
354
|
-
headers?: Record<string, string>;
|
|
355
|
-
});
|
|
356
|
-
request<T = unknown>(config: RequestConfig): Promise<AxiosResponse<T>>;
|
|
357
|
-
get<T = unknown>(url: string, config?: Partial<RequestConfig>): Promise<AxiosResponse<T>>;
|
|
358
|
-
post<T = unknown>(url: string, data?: unknown, config?: Partial<RequestConfig>): Promise<AxiosResponse<T>>;
|
|
359
|
-
put<T = unknown>(url: string, data?: unknown, config?: Partial<RequestConfig>): Promise<AxiosResponse<T>>;
|
|
360
|
-
delete<T = unknown>(url: string, config?: Partial<RequestConfig>): Promise<AxiosResponse<T>>;
|
|
361
|
-
private resolveUrl;
|
|
362
|
-
private send;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* 获取请求实例
|
|
366
|
-
*/
|
|
367
|
-
declare function getClient(): UniHttpClient;
|
|
368
|
-
/**
|
|
369
|
-
* 初始化配置网络请求
|
|
370
|
-
*/
|
|
371
|
-
declare function setupHttp(options?: Partial<HttpOptions>): UniHttpClient;
|
|
372
285
|
/**
|
|
373
286
|
* 发送通用请求
|
|
374
287
|
*/
|
|
375
288
|
declare function request<T = unknown>(config: RequestConfig): Promise<ApiRes<T>>;
|
|
376
289
|
/**
|
|
377
|
-
* 发送 GET
|
|
290
|
+
* 发送 GET 请求
|
|
378
291
|
*/
|
|
379
|
-
declare function get<T = unknown>(url: string, params?: unknown): Promise<ApiRes<T>>;
|
|
292
|
+
declare function get<T = unknown>(url: string, params?: unknown, config?: Partial<RequestConfig>): Promise<ApiRes<T>>;
|
|
380
293
|
/**
|
|
381
294
|
* 发送 POST 提交请求
|
|
382
295
|
*/
|
|
383
|
-
declare function post<T = unknown>(url: string, data?: unknown): Promise<ApiRes<T>>;
|
|
296
|
+
declare function post<T = unknown>(url: string, data?: unknown, config?: Partial<RequestConfig>): Promise<ApiRes<T>>;
|
|
384
297
|
/**
|
|
385
298
|
* 发送 PUT 修改请求
|
|
386
299
|
*/
|
|
387
|
-
declare function put<T = unknown>(url: string, data?: unknown): Promise<ApiRes<T>>;
|
|
300
|
+
declare function put<T = unknown>(url: string, data?: unknown, config?: Partial<RequestConfig>): Promise<ApiRes<T>>;
|
|
388
301
|
/**
|
|
389
302
|
* 发送 DELETE 删除请求
|
|
390
303
|
*/
|
|
391
|
-
declare function del<T = unknown>(url: string, params?: unknown): Promise<ApiRes<T>>;
|
|
304
|
+
declare function del<T = unknown>(url: string, params?: unknown, config?: Partial<RequestConfig>): Promise<ApiRes<T>>;
|
|
305
|
+
/**
|
|
306
|
+
* 统一 HTTP 请求客户端门面
|
|
307
|
+
*/
|
|
308
|
+
declare const http: {
|
|
309
|
+
request: typeof request;
|
|
310
|
+
get: typeof get;
|
|
311
|
+
post: typeof post;
|
|
312
|
+
put: typeof put;
|
|
313
|
+
delete: typeof del;
|
|
314
|
+
del: typeof del;
|
|
315
|
+
setup: typeof setupHttp;
|
|
316
|
+
getOptions: typeof getHttpOptions;
|
|
317
|
+
};
|
|
318
|
+
declare const client: {
|
|
319
|
+
request: typeof request;
|
|
320
|
+
get: typeof get;
|
|
321
|
+
post: typeof post;
|
|
322
|
+
put: typeof put;
|
|
323
|
+
delete: typeof del;
|
|
324
|
+
del: typeof del;
|
|
325
|
+
setup: typeof setupHttp;
|
|
326
|
+
getOptions: typeof getHttpOptions;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* 获取请求客户端
|
|
330
|
+
*/
|
|
331
|
+
declare function getClient(): typeof http;
|
|
332
|
+
/**
|
|
333
|
+
* 初始化配置网络请求
|
|
334
|
+
*/
|
|
335
|
+
declare function setupHttp(options?: Partial<HttpOptions>): typeof http;
|
|
392
336
|
/**
|
|
393
337
|
* 获取全局网络配置
|
|
394
338
|
*/
|
|
395
339
|
declare function getHttpOptions(): HttpOptions;
|
|
396
|
-
declare const client: UniHttpClient;
|
|
397
|
-
declare const http: UniHttpClient;
|
|
398
340
|
|
|
399
|
-
export { type AliossUploadSign, type ApiRes, type ApiResData, type AxiosResponse, type DeviceInfo, HttpError, type HttpMethod, type HttpOptions, type
|
|
341
|
+
export { type AliossUploadSign, type ApiRes, type ApiResData, type AxiosResponse, type DeviceInfo, type HttpConfig, HttpError, type HttpMethod, type HttpOptions, type HttpResponse, type InterceptorHandler, type LocalUploadSign, type QiniuUploadSign, type RequestConfig, type SignOptions, type UploadFileParams, type UploadSign, type UploadSignBase, calculateSign, client, request as default, del, doUpload, encryptRsa, get, getClient, getDevice, getHttpOptions, http, post, postUploadSign, put, request, setupHttp, sha256, sortString, uploadFile };
|