@seayoo-web/request 3.5.2 → 4.0.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/README.md +58 -56
- package/dist/index.js +136 -122
- package/dist/node.js +58 -58
- package/dist/request.fetch-U2PiTmEn.js +54 -0
- package/dist/retry-b0Etywu_.js +645 -0
- package/dist/wx.js +58 -49
- package/package.json +1 -1
- package/types/inc/cache.d.ts +2 -2
- package/types/inc/config.d.ts +5 -5
- package/types/inc/guard.d.ts +3 -3
- package/types/inc/jsonp.d.ts +3 -2
- package/types/inc/main.d.ts +51 -34
- package/types/inc/option.d.ts +6 -7
- package/types/inc/request.xhr.d.ts +4 -4
- package/types/inc/response.d.ts +8 -3
- package/types/inc/retry.d.ts +3 -3
- package/types/inc/rule.d.ts +5 -5
- package/types/inc/sentry.d.ts +4 -4
- package/types/inc/type.d.ts +55 -50
- package/types/inc/utils.d.ts +7 -2
- package/types/index.d.ts +37 -25
- package/types/node.d.ts +26 -24
- package/types/wx.d.ts +22 -20
- package/dist/request.fetch-Jj3A4PnG.js +0 -48
- package/dist/retry-Cxkf8ke1.js +0 -624
package/README.md
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
## 特性
|
|
13
13
|
|
|
14
|
-
1. 默认基于 fetch
|
|
14
|
+
1. 默认基于 fetch,请求和响应解析默认基于 json
|
|
15
15
|
2. 支持重试配置 maxRetry / retryResolve / retryInterval
|
|
16
16
|
3. 支持响应结果处理策略 responseRule 和通用提示配置
|
|
17
17
|
4. 支持类型守卫 typeGuard
|
|
18
18
|
5. 支持多实例,多端(浏览器,nodejs,微信小程序)
|
|
19
|
-
6. get
|
|
19
|
+
6. get 请求支持并发缓存(默认缓存 500ms)
|
|
20
20
|
7. 函数永不抛错,返回固定解析结构 { ok, data, status, headers, code, message }
|
|
21
21
|
8. 提供格式化良好的 sentry 信息用于错误上报
|
|
22
22
|
9. 提供 jsonp / jsonx 函数,支持带上传进度的 upload 函数
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
```js
|
|
27
27
|
import { get } from "@seayoo-web/request"
|
|
28
28
|
|
|
29
|
-
interface
|
|
29
|
+
interface User {
|
|
30
30
|
name: string,
|
|
31
31
|
id: string
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function isUserList(data: unknown): data is
|
|
34
|
+
function isUserList(data: unknown): data is User[] {
|
|
35
35
|
return Array.isArray(data)
|
|
36
36
|
&& data.every(item => !!item && typeof item === "object" && "name" in item && "id" in item)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export async function getUserList(): Promise<
|
|
39
|
+
export async function getUserList(): Promise<User[]> {
|
|
40
40
|
const { data } = await get("/api/user", isUserList)
|
|
41
41
|
return data || []
|
|
42
42
|
}
|
|
@@ -111,7 +111,7 @@ setConfig({ timeout: 10000 });
|
|
|
111
111
|
|
|
112
112
|
类型:string
|
|
113
113
|
|
|
114
|
-
说明:需要以
|
|
114
|
+
说明:需要以 `/` 开头或者是一个完整的 url 地址;此设置会给所有请求的 url 增加 baseURL 作为前缀,但以下情况除外
|
|
115
115
|
|
|
116
116
|
1. 请求时传入的 url 为完整 url,即以 http:// 或 https:// 开头
|
|
117
117
|
|
|
@@ -129,24 +129,24 @@ setConfig({ timeout: 10000 });
|
|
|
129
129
|
|
|
130
130
|
类型:number
|
|
131
131
|
|
|
132
|
-
说明:请求超时设置,单位 ms,默认 10000
|
|
132
|
+
说明:请求超时设置,单位 ms,默认 `10000`,即 10 秒
|
|
133
133
|
|
|
134
134
|
### cacheTTL
|
|
135
135
|
|
|
136
136
|
类型:number
|
|
137
137
|
|
|
138
|
-
说明:用于控制全局请求的缓冲时长,单位 ms,默认 500
|
|
138
|
+
说明:用于控制全局请求的缓冲时长,单位 ms,默认 `500`,设置为 `0` 则全局禁用缓冲。默认仅仅对 get 请求做缓冲处理。
|
|
139
139
|
|
|
140
140
|
### defaultTypeGuardMessage
|
|
141
141
|
|
|
142
142
|
类型:string
|
|
143
143
|
|
|
144
|
-
说明:默认的类型守卫错误提示,仅支持全局配置,默认
|
|
144
|
+
说明:默认的类型守卫错误提示,仅支持全局配置,默认 `响应数据未能正确识别`,单个 api 可通过传入完整的类型守卫({ guard, message })来定制提示消息。
|
|
145
145
|
|
|
146
146
|
### message
|
|
147
147
|
|
|
148
148
|
类型:false | ((
|
|
149
|
-
result:
|
|
149
|
+
result: ResponseResult,
|
|
150
150
|
method: string,
|
|
151
151
|
url: string,
|
|
152
152
|
defaultMessage: string
|
|
@@ -222,21 +222,21 @@ defaultMessage: string
|
|
|
222
222
|
|
|
223
223
|
类型:number
|
|
224
224
|
|
|
225
|
-
说明:当请求发生错误时重试的次数,默认
|
|
225
|
+
说明:当请求发生错误时重试的次数,默认 `1`,最大为 `10`
|
|
226
226
|
|
|
227
227
|
### retryResolve
|
|
228
228
|
|
|
229
|
-
类型:"default" | "network" | number[] | ((result:
|
|
229
|
+
类型:"default" | "network" | number[] | ((result: RequestBaseResponse, count: number) => boolean)
|
|
230
230
|
|
|
231
|
-
说明:重试判断方法,默认是 default
|
|
231
|
+
说明:重试判断方法,默认是 `default`
|
|
232
232
|
|
|
233
|
-
default 在 network 基础之上,如果是 Tencent EO 响应的 552/522 错误码,则重试;
|
|
233
|
+
- `default`: 在 `network` 基础之上,如果是 Tencent EO 响应的 552/522 错误码,则重试;
|
|
234
234
|
|
|
235
|
-
network
|
|
235
|
+
- `network`: 表示仅仅当网络错误时(不含 aborted/timeout)才重试;
|
|
236
236
|
|
|
237
|
-
|
|
237
|
+
- `number[]`:当设置为 number[] 时,将检查 http 状态码,匹配则重试;
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
- 自定义函数:也可以设置为一个重试检查函数,返回 true 则进行重试;
|
|
240
240
|
|
|
241
241
|
> 如果需要收集错误的重试信息,可以通过设置 retryResolve 为一个函数来检查或上报请求结果
|
|
242
242
|
|
|
@@ -244,11 +244,11 @@ network 表示仅仅当网络错误时才重试,如果请求被取消或超时
|
|
|
244
244
|
|
|
245
245
|
类型:number | "2EB" | ((retryIndex: number, { url, method, status }) => number)
|
|
246
246
|
|
|
247
|
-
说明:两次重试的间隔策略,设置为数字(单位 ms)表示固定间隔,设置为函数则可以自定义间隔;默认是
|
|
247
|
+
说明:两次重试的间隔策略,设置为数字(单位 ms)表示固定间隔,设置为函数则可以自定义间隔;默认是 `200`,即 200ms;
|
|
248
248
|
|
|
249
249
|
其中 retryIndex 从 1 开始,最大为 10;最小时间间隔为 100ms;
|
|
250
250
|
|
|
251
|
-
特殊值 2EB 表示以 2 为底的[指数退避策略](https://en.wikipedia.org/wiki/Exponential_backoff),即首次重试等待 0.1 秒,后续分别是 0.2秒,0.4秒,0.8秒 ...
|
|
251
|
+
特殊值 `2EB` 表示以 2 为底的[指数退避策略](https://en.wikipedia.org/wiki/Exponential_backoff),即首次重试等待 0.1 秒,后续分别是 0.2秒,0.4秒,0.8秒 ...
|
|
252
252
|
|
|
253
253
|
### requestTransformer
|
|
254
254
|
|
|
@@ -257,7 +257,7 @@ headers: Record<string, string>,
|
|
|
257
257
|
params: Record<string, string>,
|
|
258
258
|
method: string,
|
|
259
259
|
url: string,
|
|
260
|
-
body:
|
|
260
|
+
body: BaseRequestBody
|
|
261
261
|
}) => MaybePromise<void | string>)
|
|
262
262
|
|
|
263
263
|
说明:可用于发送前修改请求相关数据
|
|
@@ -275,7 +275,6 @@ method: string,
|
|
|
275
275
|
url: string,
|
|
276
276
|
headers: Record<string, string>,
|
|
277
277
|
rawError?: Error | ProgressEvent,
|
|
278
|
-
responseBody: string,
|
|
279
278
|
sentryError: Error,
|
|
280
279
|
sentryTags: Record<string, string | number>,
|
|
281
280
|
sentryExtra: Record<string, unknown>
|
|
@@ -285,7 +284,7 @@ sentryExtra: Record<string, unknown>
|
|
|
285
284
|
|
|
286
285
|
### responseHandler
|
|
287
286
|
|
|
288
|
-
类型:null | ((result:
|
|
287
|
+
类型:null | ((result: ResponseResult, method: string, url: string) => void)
|
|
289
288
|
|
|
290
289
|
说明:请求完成后用于统一检查响应结果,非网络错误时触发,入参的数据均为副本,仅仅可读
|
|
291
290
|
|
|
@@ -297,13 +296,13 @@ sentryExtra: Record<string, unknown>
|
|
|
297
296
|
|
|
298
297
|
### logHandler
|
|
299
298
|
|
|
300
|
-
类型:null | ((data:
|
|
299
|
+
类型:null | ((data: RequestLog) => void)
|
|
301
300
|
|
|
302
301
|
说明:全局日志打印函数,具体日志信息可参考源码类型声明;
|
|
303
302
|
|
|
304
303
|
## 网络请求参数
|
|
305
304
|
|
|
306
|
-
类型:
|
|
305
|
+
类型:RequestOptions
|
|
307
306
|
|
|
308
307
|
说明:网络请求参数,对于每个最终工具函数都提供有可选的请求参数,且每个字段均可选
|
|
309
308
|
|
|
@@ -313,7 +312,7 @@ sentryExtra: Record<string, unknown>
|
|
|
313
312
|
|
|
314
313
|
### params
|
|
315
314
|
|
|
316
|
-
类型:Record<string,
|
|
315
|
+
类型:Record<string, string | number | boolean>
|
|
317
316
|
|
|
318
317
|
### headers
|
|
319
318
|
|
|
@@ -349,6 +348,10 @@ sentryExtra: Record<string, unknown>
|
|
|
349
348
|
|
|
350
349
|
同全局配置,设定的解析规则仅本次请求有效,默认跟随全局设置
|
|
351
350
|
|
|
351
|
+
### asBuffer
|
|
352
|
+
|
|
353
|
+
是否将响应内容作为 ArrayBuffer 返回,默认 `false`,当设置为 `true` 时,将会忽略 `responseRule`
|
|
354
|
+
|
|
352
355
|
### maxRetry
|
|
353
356
|
|
|
354
357
|
同全局配置,仅本次请求有效,设置最大重试次数,默认跟随全局设置
|
|
@@ -391,17 +394,18 @@ sentryExtra: Record<string, unknown>
|
|
|
391
394
|
|
|
392
395
|
类型:string
|
|
393
396
|
|
|
394
|
-
|
|
397
|
+
说明:表示当前请求的状态信息,其可能值按照优先级从高到低:
|
|
398
|
+
|
|
399
|
+
- `responseRule` 中自定义的错误码字段所传递的值
|
|
400
|
+
- `RequestInternalError` 网络错误或取消等异常情况
|
|
395
401
|
|
|
396
|
-
-
|
|
397
|
-
- responseRule 中自定义的错误码字段所传递的值
|
|
398
|
-
- "Aborted" 或 "Unknown" 网络错误或取消等异常情况,详细参见 `RequestInternalError`
|
|
402
|
+
- `Http StatusText` 当请求完成且无自定义错误码时
|
|
399
403
|
|
|
400
404
|
### message
|
|
401
405
|
|
|
402
406
|
类型:string
|
|
403
407
|
|
|
404
|
-
说明:响应结果的提示消息,不受
|
|
408
|
+
说明:响应结果的提示消息,不受 RequestOptions.message 影响
|
|
405
409
|
|
|
406
410
|
### headers
|
|
407
411
|
|
|
@@ -415,9 +419,10 @@ sentryExtra: Record<string, unknown>
|
|
|
415
419
|
|
|
416
420
|
说明:响应的数据内容,其可能值为:
|
|
417
421
|
|
|
418
|
-
- unknown
|
|
419
|
-
- null
|
|
420
|
-
-
|
|
422
|
+
- `unknown`:如果不提供类型守卫,则返回 unknown
|
|
423
|
+
- `null`:网络请求错误、类型守卫检查失败、服务器没有返回预期的数据,则返回 null
|
|
424
|
+
- `ArrayBuffer`:如果设置请求参数中 `asBuffer` 为 `true` 且没有提供类型守卫函数,在服务器成功响应时返回 arrayBuffer
|
|
425
|
+
- `T`: 如果成功返回并通过类型守卫检查,则返回类型守卫对应的类型
|
|
421
426
|
|
|
422
427
|
## 类型守卫
|
|
423
428
|
|
|
@@ -432,54 +437,51 @@ type TypeGuard<T> = {
|
|
|
432
437
|
type TypeGuardParam<T> = TypeGuard<T> | TypeGuardFn<T>
|
|
433
438
|
```
|
|
434
439
|
|
|
435
|
-
##
|
|
440
|
+
## 请求函数
|
|
436
441
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
底层实现的 request 工具函数,未绑定类型守卫处理,返回的数据类型固定为 unknown;同时也未对请求做任何缓存处理;通常情况推荐使用以下的包装函数:get / post / head / del / put / patch
|
|
440
|
-
|
|
441
|
-
### get\<T\>(url: string, typeGard?: TypeGuardParam\<T\> | null, options?: IRequestOptions)
|
|
442
|
+
### get(url, params?, guard?, options?)
|
|
442
443
|
|
|
443
444
|
- **url**: 请求的资源路径,如果需要跳过全局 baseURL 设置,可以传递完整 url 地址
|
|
444
|
-
- **
|
|
445
|
-
- **
|
|
445
|
+
- **params**: 请求的 url query 参数,会强制覆盖 options.params
|
|
446
|
+
- **guard**: 可选类型守卫,如果设置为 null,则返回的内容为 unknown,否则就是经过类型守卫检查后的类型化数据,推荐传递类型守卫
|
|
447
|
+
- **options**: 其他可选请求配置参数
|
|
446
448
|
|
|
447
|
-
> 注意,get 请求默认设置 500ms 缓存,即对同一个请求(url+params)在 500ms 内不再重复发起请求,而是直接返回上一次的结果,其中 params
|
|
449
|
+
> 注意,get 请求默认设置 500ms 缓存,即对同一个请求(url+params)在 500ms 内不再重复发起请求,而是直接返回上一次的结果,其中 params 会包含 url 中带有的参数
|
|
448
450
|
|
|
449
|
-
### post(url
|
|
451
|
+
### post(url, body, guard?, options?)
|
|
450
452
|
|
|
451
|
-
- **url**: 请求的资源路径,如果需要跳过全局 baseURL 设置,可以传递完整 url
|
|
452
|
-
- **
|
|
453
|
-
- **
|
|
454
|
-
- **options**:
|
|
453
|
+
- **url**: 请求的资源路径,如果需要跳过全局 baseURL 设置,可以传递完整 url 地址,另外可以设置为 `{ url, params }` 对象来传递 url query 参数(当然也可以通过末尾的 options 参数传递 params)
|
|
454
|
+
- **body**: 请求发送的 body 数据,会强制覆盖 options.body
|
|
455
|
+
- **guard**: 可选类型守卫,如果设置为 null,则返回的内容为 unknown,否则就是经过类型守卫检查后的类型化数据,推荐传递类型守卫,除非对响应内容不关心(比如 httpStatus 为 204 或 202)
|
|
456
|
+
- **options**: 其他可选请求配置参数
|
|
455
457
|
|
|
456
458
|
### Other
|
|
457
459
|
|
|
458
|
-
**head(url, options?)**
|
|
460
|
+
**head(url, params?, options?)**
|
|
459
461
|
|
|
460
|
-
**del(url,
|
|
462
|
+
**del(url, params?, guard?, options?)**
|
|
461
463
|
|
|
462
|
-
**put(url,
|
|
464
|
+
**put(url, body, guard?, options?)**
|
|
463
465
|
|
|
464
|
-
**patch(url,
|
|
466
|
+
**patch(url, body, guard?, options?)**
|
|
465
467
|
|
|
466
468
|
## 特殊函数
|
|
467
469
|
|
|
468
470
|
工具还提供了三个特殊函数以应对不同的场景需求,且限于浏览器环境使用:
|
|
469
471
|
|
|
470
|
-
### upload(url
|
|
472
|
+
### upload(url, files: Record<string, Blob>, options?)
|
|
471
473
|
|
|
472
|
-
因为 fetch 不支持上传进度信息,故使用 xhr
|
|
474
|
+
因为 `fetch` 不支持上传进度信息,故使用 xhr 实现带有上传进度信息的 upload 函数,以满足特定场景下的大文件上传需求;
|
|
473
475
|
|
|
474
|
-
其可选 options 不支持重试,其 body 类型限制为 Record<string, unknown>,并且随着 formData 发送;同时新增进度信息配置:
|
|
476
|
+
其可选 options 不支持重试,其 request body 类型限制为 Record<string, unknown>,并且随着 formData 发送;同时新增进度信息配置:
|
|
475
477
|
|
|
476
478
|
**onUploadProgress?: (progress: { total: number; loaded: number }) => void**
|
|
477
479
|
|
|
478
|
-
### jsonp
|
|
480
|
+
### jsonp(url, guard, params?)
|
|
479
481
|
|
|
480
482
|
以 script 方式加载远程资源,并通过 callback 回调接收远程数据,必须提供类型守卫;
|
|
481
483
|
|
|
482
|
-
### jsonx
|
|
484
|
+
### jsonx(url, guard, params?)
|
|
483
485
|
|
|
484
486
|
以 script 方式加载远程资源,并通过 var(全局变量)接收远程数据,必须提供类型守卫;
|
|
485
487
|
|
package/dist/index.js
CHANGED
|
@@ -1,160 +1,174 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { g as
|
|
3
|
-
import { f as
|
|
4
|
-
const j = async function(
|
|
5
|
-
return
|
|
1
|
+
import { h, r as E, G as y, c as q, f as v, a as C, R as w, H as R, b as H, v as x, d as L, N as T, X as k } from "./retry-b0Etywu_.js";
|
|
2
|
+
import { g as W } from "./retry-b0Etywu_.js";
|
|
3
|
+
import { f as S } from "./request.fetch-U2PiTmEn.js";
|
|
4
|
+
const j = async function(n, a, t) {
|
|
5
|
+
return h(await E(m, n, a, t), n, a, t);
|
|
6
6
|
};
|
|
7
|
-
async function
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
const
|
|
11
|
-
...
|
|
12
|
-
method:
|
|
13
|
-
body:
|
|
7
|
+
async function B(n, a, t, r) {
|
|
8
|
+
const o = t?.body, u = t?.method === "PUT" ? "PUT" : "POST";
|
|
9
|
+
if (a instanceof Blob) {
|
|
10
|
+
const l = new y(r), e = await m(n, l, {
|
|
11
|
+
...t,
|
|
12
|
+
method: u,
|
|
13
|
+
body: a
|
|
14
14
|
});
|
|
15
|
-
return
|
|
15
|
+
return h(e, n, l, t);
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}) :
|
|
17
|
+
const c = new FormData(), d = { ...a };
|
|
18
|
+
o instanceof Object && Object.entries(o).forEach(([l, e]) => {
|
|
19
|
+
e instanceof Blob ? d[l] = e : Array.isArray(e) ? e.forEach((g, s) => {
|
|
20
|
+
c.append(`${l}[${s}]`, String(g));
|
|
21
|
+
}) : c.append(l, String(e));
|
|
22
22
|
});
|
|
23
|
-
for (const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
...
|
|
27
|
-
method:
|
|
28
|
-
body:
|
|
23
|
+
for (const l in d)
|
|
24
|
+
c.append(l, d[l]);
|
|
25
|
+
const f = new y(r), p = await m(n, f, {
|
|
26
|
+
...t,
|
|
27
|
+
method: u,
|
|
28
|
+
body: c
|
|
29
29
|
});
|
|
30
|
-
return
|
|
30
|
+
return h(p, n, f, t);
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
return await new Promise((
|
|
35
|
-
let
|
|
36
|
-
const
|
|
37
|
-
|
|
32
|
+
const m = async function(n, a, t) {
|
|
33
|
+
const r = await q(n, a, t), o = r.method, u = t?.onUploadProgress;
|
|
34
|
+
return await new Promise((c) => {
|
|
35
|
+
let d = null, f = !1;
|
|
36
|
+
const p = function() {
|
|
37
|
+
f || (e.abort(), f = !0);
|
|
38
38
|
};
|
|
39
|
-
function
|
|
40
|
-
|
|
39
|
+
function l() {
|
|
40
|
+
d !== null && clearTimeout(d), r.abort && r.abort.removeEventListener("abort", p);
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}),
|
|
49
|
-
|
|
42
|
+
const e = new XMLHttpRequest();
|
|
43
|
+
let g = !1;
|
|
44
|
+
if (e.open(o, r.url, !0), u) {
|
|
45
|
+
let s = 1;
|
|
46
|
+
e.upload.addEventListener("progress", (b) => {
|
|
47
|
+
s = b.total, u({ total: b.total, loaded: b.loaded });
|
|
48
|
+
}), e.addEventListener("load", () => {
|
|
49
|
+
u({ loaded: s, total: s });
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
e.addEventListener("load", async () => {
|
|
53
|
+
l();
|
|
54
|
+
const s = e.responseType;
|
|
55
|
+
c(
|
|
56
|
+
await v(
|
|
57
|
+
{
|
|
58
|
+
url: r.url,
|
|
59
|
+
method: o,
|
|
60
|
+
status: e.status,
|
|
61
|
+
statusText: e.statusText,
|
|
62
|
+
headers: P(e),
|
|
63
|
+
body: null
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
asBuffer: r.asBuffer,
|
|
67
|
+
text: () => s === "" || s === "text" || s === "json" || s === "document" ? e.responseText : "",
|
|
68
|
+
buffer: async () => s === "arraybuffer" ? e.response : s === "blob" ? await e.response.arrayBuffer() : await C(e.responseText)
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
}), e.addEventListener(
|
|
63
73
|
"error",
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
url:
|
|
67
|
-
method:
|
|
68
|
-
status:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
(s) => {
|
|
75
|
+
l(), c({
|
|
76
|
+
url: r.url,
|
|
77
|
+
method: o,
|
|
78
|
+
status: e.status || -1,
|
|
79
|
+
error: e.status ? void 0 : w.NetworkError,
|
|
80
|
+
statusText: e.statusText || w.NetworkError,
|
|
81
|
+
body: null,
|
|
82
|
+
rawError: s
|
|
72
83
|
});
|
|
73
84
|
},
|
|
74
85
|
!0
|
|
75
|
-
),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
), e.addEventListener("abort", () => {
|
|
87
|
+
l();
|
|
88
|
+
const s = g ? w.Timeout : w.Aborted;
|
|
89
|
+
c({
|
|
90
|
+
url: r.url,
|
|
91
|
+
method: o,
|
|
79
92
|
status: -1,
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
error: s,
|
|
94
|
+
statusText: s,
|
|
95
|
+
body: null
|
|
82
96
|
});
|
|
83
|
-
}), Object.entries(
|
|
84
|
-
|
|
85
|
-
}),
|
|
86
|
-
|
|
87
|
-
},
|
|
97
|
+
}), Object.entries(r.headers).forEach(([s, b]) => {
|
|
98
|
+
e.setRequestHeader(s, b);
|
|
99
|
+
}), r.credentials === "include" && (e.withCredentials = !0), e.send(r.body || void 0), r.abort && r.abort.addEventListener("abort", p), r.timeout > 0 && (d = setTimeout(function() {
|
|
100
|
+
g = !0, p();
|
|
101
|
+
}, r.timeout));
|
|
88
102
|
});
|
|
89
103
|
};
|
|
90
|
-
function
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
93
|
-
return
|
|
94
|
-
const
|
|
95
|
-
return
|
|
96
|
-
`).forEach((
|
|
97
|
-
const
|
|
98
|
-
if (!
|
|
104
|
+
function P(n) {
|
|
105
|
+
const a = {};
|
|
106
|
+
if (!n)
|
|
107
|
+
return a;
|
|
108
|
+
const t = n.getAllResponseHeaders();
|
|
109
|
+
return t && t !== "null" && t.replace(/\r/g, "").split(`
|
|
110
|
+
`).forEach((r) => {
|
|
111
|
+
const o = r.trim();
|
|
112
|
+
if (!o)
|
|
99
113
|
return;
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
}),
|
|
114
|
+
const u = o.split(":"), c = u[0].trim();
|
|
115
|
+
c && (a[c] = (u[1] || "").trim());
|
|
116
|
+
}), a;
|
|
103
117
|
}
|
|
104
|
-
async function
|
|
105
|
-
const
|
|
106
|
-
"callback" in
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
118
|
+
async function O(n, a, t = {}) {
|
|
119
|
+
const r = window;
|
|
120
|
+
"callback" in t || (t.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
121
|
+
const o = t.callback + "";
|
|
122
|
+
if (!n)
|
|
109
123
|
return null;
|
|
110
|
-
const
|
|
111
|
-
return new Promise((
|
|
112
|
-
|
|
113
|
-
if (
|
|
124
|
+
const u = R(n, H(t), !0);
|
|
125
|
+
return new Promise((c) => {
|
|
126
|
+
r[o] = function(d) {
|
|
127
|
+
if (o in window && delete r[o], a(d))
|
|
114
128
|
return d;
|
|
115
|
-
console.warn("response type check failed",
|
|
116
|
-
},
|
|
117
|
-
|
|
129
|
+
console.warn("response type check failed", n, d), c(null);
|
|
130
|
+
}, x(u).catch(function() {
|
|
131
|
+
c(null), delete r[o];
|
|
118
132
|
});
|
|
119
133
|
});
|
|
120
134
|
}
|
|
121
|
-
async function A(
|
|
122
|
-
const
|
|
123
|
-
return "var" in
|
|
124
|
-
const
|
|
125
|
-
return
|
|
135
|
+
async function A(n, a, t = {}) {
|
|
136
|
+
const r = window;
|
|
137
|
+
return "var" in t || (t.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await x(R(n, H(t), !0)).then(() => {
|
|
138
|
+
const o = r[t.var + ""];
|
|
139
|
+
return a(o) ? o : (console.warn("response type check failed", n, o), null);
|
|
126
140
|
}).catch(() => null) : null;
|
|
127
141
|
}
|
|
128
|
-
const M = async function(
|
|
129
|
-
return await
|
|
130
|
-
baseURL:
|
|
131
|
-
logHandler:
|
|
132
|
-
errorHandler:
|
|
133
|
-
requestTransformer:
|
|
134
|
-
messageHandler:
|
|
135
|
-
responseHandler:
|
|
142
|
+
const M = async function(n, a, t) {
|
|
143
|
+
return await B(n, a, t, {
|
|
144
|
+
baseURL: i.getConfig("baseURL"),
|
|
145
|
+
logHandler: i.getConfig("logHandler"),
|
|
146
|
+
errorHandler: i.getConfig("errorHandler"),
|
|
147
|
+
requestTransformer: i.getConfig("requestTransformer"),
|
|
148
|
+
messageHandler: i.getConfig("messageHandler"),
|
|
149
|
+
responseHandler: i.getConfig("responseHandler")
|
|
136
150
|
});
|
|
137
151
|
};
|
|
138
152
|
// @__NO_SIDE_EFFECTS__
|
|
139
|
-
function U(
|
|
140
|
-
if (!
|
|
153
|
+
function U(n) {
|
|
154
|
+
if (!L())
|
|
141
155
|
throw new Error("Default Module Only Support In Browser");
|
|
142
|
-
return
|
|
156
|
+
return k() ? new T(S, n) : new T(j, n);
|
|
143
157
|
}
|
|
144
|
-
const
|
|
158
|
+
const i = /* @__PURE__ */ U(), X = i.setConfig, G = i.request, F = i.head, I = i.get, $ = i.post, z = i.del, J = i.put, K = i.patch;
|
|
145
159
|
export {
|
|
146
160
|
U as NetRequest,
|
|
147
161
|
w as RequestInternalError,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
z as del,
|
|
163
|
+
I as get,
|
|
164
|
+
W as getResponseRulesDescription,
|
|
165
|
+
F as head,
|
|
166
|
+
O as jsonp,
|
|
153
167
|
A as jsonx,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
168
|
+
K as patch,
|
|
169
|
+
$ as post,
|
|
170
|
+
J as put,
|
|
171
|
+
G as request,
|
|
172
|
+
X as setGlobalConfig,
|
|
159
173
|
M as upload
|
|
160
174
|
};
|