@seayoo-web/request 2.1.0 → 2.1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 网络请求工具库
2
2
 
3
- ## 为什么
3
+ ## 为什么
4
4
 
5
5
  市面上流行的网络请求工具有以下一些限制或不足:
6
6
 
@@ -47,65 +47,65 @@ export async function getUserList(): Promise<IUser[]> {
47
47
 
48
48
  ```js
49
49
  // 浏览器环境
50
- import { setGlobalConfig } from "@seayoo-web/request"
50
+ import { setGlobalConfig } from "@seayoo-web/request";
51
51
  // nodejs 环境
52
- import { setGlobalConfig } from "@seayoo-web/request/node"
52
+ import { setGlobalConfig } from "@seayoo-web/request/node";
53
53
  // 或在某些编译配置或编辑器中无法识别上述路径,可以改用实际的 dist 路径导入
54
- import { setGlobalConfig } from "@seayoo-web/request/dist/node"
54
+ import { setGlobalConfig } from "@seayoo-web/request/dist/node";
55
55
 
56
56
  // 以下是默认的全局配置(更多介绍请参考下方全局配置)
57
57
  setGlobalConfig({
58
- // api 基础路径,默认根目录,通常可以设置为 /api
59
- baseURL: "",
60
- // 响应解析规则
61
- responseRule: {
62
- // status 成功时解析策略:将 body 作为响应数据
63
- ok: { resolve: "body" },
64
- // status 失败时解析策略:将响应体解析为 json 并读取 message 字段作为错误消息
65
- failed: { resolve: "json", messageField: "message" }
66
- },
67
- // 更多全局配置参考下方介绍
68
- })
58
+ // api 基础路径,默认根目录
59
+ baseURL: "/",
60
+ // 响应解析规则
61
+ responseRule: {
62
+ // status 成功时解析策略:将 body 作为响应数据
63
+ ok: { resolve: "body" },
64
+ // status 失败时解析策略:将响应体解析为 json 并读取 message 字段作为错误消息
65
+ failed: { resolve: "json", messageField: "message" },
66
+ },
67
+ // 更多全局配置参考下方介绍
68
+ });
69
69
  ```
70
70
 
71
71
  ## 全局函数和自定义实例
72
72
 
73
73
  ```js
74
74
  // 以下为浏览器环境全局默认导出的工具函数
75
- import { get, post, put, patch, del, head } from "@seayoo-web/request"
75
+ import { get, post, put, patch, del, head } from "@seayoo-web/request";
76
76
  // 以下是 nodejs 环境全局默认导出的工具函数
77
- import { get, post, put, patch, del, head } from "@seayoo-web/request/node"
77
+ import { get, post, put, patch, del, head } from "@seayoo-web/request/node";
78
78
  // 以下是 微信小程序 环境全局默认导出的工具函数
79
79
  // 注意,微信不支持 patch 方法
80
- import { get, post, put, del, head } from "@seayoo-web/request/wx"
80
+ import { get, post, put, del, head } from "@seayoo-web/request/wx";
81
81
 
82
82
  // 浏览器环境自定义创建实例
83
- import { NetRequest } from "@seayoo-web/request"
84
- const { get, post, put, patch, del, head, setConfig } = NetRequest()
83
+ import { NetRequest } from "@seayoo-web/request";
84
+ const { get, post, put, patch, del, head, setConfig } = NetRequest();
85
85
 
86
86
  // nodejs环境自定义创建实例
87
- import { NetRequest } from "@seayoo-web/request/node"
88
- const { get, post, put, patch, del, head, setConfig } = NetRequest()
87
+ import { NetRequest } from "@seayoo-web/request/node";
88
+ const { get, post, put, patch, del, head, setConfig } = NetRequest();
89
89
 
90
90
  // 微信小程序自定义创建实例
91
- import { NetRequest } from "@seayoo-web/request/wx"
92
- const { get, post, put, del, head, setConfig } = NetRequest()
91
+ import { NetRequest } from "@seayoo-web/request/wx";
92
+ const { get, post, put, del, head, setConfig } = NetRequest();
93
93
  ```
94
94
 
95
95
  ## 全局配置参数
96
96
 
97
97
  ```js
98
- import { setGlobalConfig } from "@seayoo-web/request"
98
+ import { setGlobalConfig } from "@seayoo-web/request";
99
99
  // 全局配置字段说明见下,所有字段均可选
100
- // 全局配置仅仅影响全局导出函数,比如 get, post 等,对于自定义实例没有影响
101
- setGlobalConfig({ baseURL: "/api" })
100
+ // 全局配置仅仅影响全局导出函数,比如直接导出的 get, post 等,对于自定义实例没有影响
101
+ setGlobalConfig({ baseURL: "/api" });
102
102
 
103
- // 自定义实例全局配置是独立的
104
- import { NetRequest } from "@seayoo-web/request"
103
+ // 自定义实例和全局配置是独立的
104
+ import { NetRequest } from "@seayoo-web/request";
105
105
  // 可以创建时传递
106
- const { get, post, setConfig } = NetRequest({ baseURL: "/api" })
106
+ const { get, post, setConfig } = NetRequest({ baseURL: "/api" });
107
107
  // 也可以随时修改
108
- setConfig({ timeout: 10000 })
108
+ setConfig({ timeout: 10000 });
109
109
  ```
110
110
 
111
111
  ### baseURL
@@ -122,7 +122,7 @@ setConfig({ timeout: 10000 })
122
122
 
123
123
  类型:"omit" | "same-origin" | "include"
124
124
 
125
- 说明:是否携带用户认证信息(cookie, basic http auth 等),默认 "same-orgin",当需要跨域发送 cookie 时可以设置为 include;当需要明确忽略 cookie(比如认证信息已经放入自定义 header 头)时,可以设置为 omit;
125
+ 说明:是否携带用户认证信息(cookie, basic http auth 等),默认 "same-orgin",当需要跨域发送 cookie 时可以设置为 include;当需要明确忽略 cookie(比如认证信息已经放入自定义 header 头)时,可以设置为 omit;
126
126
 
127
127
  仅浏览器环境有效;如果运行环境不支持 fetch 则 omit 无效;
128
128
 
@@ -130,7 +130,7 @@ setConfig({ timeout: 10000 })
130
130
 
131
131
  类型:number
132
132
 
133
- 说明:请求超时设置,单位 ms,默认 10000
133
+ 说明:请求超时设置,单位 ms,默认 10000,即 10 秒
134
134
 
135
135
  ### cacheTTL
136
136
 
@@ -147,11 +147,11 @@ setConfig({ timeout: 10000 })
147
147
  ### message
148
148
 
149
149
  类型:false | ((
150
- result: IResponseResult,
151
- method: string,
152
- url: string,
153
- defaultMessage: string
154
- ) => string | false | Error | {message: string})
150
+ result: IResponseResult,
151
+ method: string,
152
+ url: string,
153
+ defaultMessage: string
154
+ ) => string | false | Error | {message: string})
155
155
 
156
156
  说明:默认情况下,工具函数会输出 message 消息用于提示,当不需要提示时可以设置为 false;
157
157
 
@@ -167,57 +167,57 @@ setConfig({ timeout: 10000 })
167
167
 
168
168
  说明:用于指定如何解析响应体内容
169
169
 
170
- - **FailedRule**: { resolve, converter?, statusField?, messageField? }
170
+ - **FailedRule**: { resolve, converter?, statusField?, messageField? }
171
171
 
172
172
  http失败时 (status <200 || status >= 400) 解析策略
173
173
 
174
174
  **resolve**: "json" | "body"
175
175
 
176
- 解析方式,设置为 json(默认),则可以进一步指定错误消息字段;设置为 body 则将整个 body 解析为错误信息;
176
+ 解析方式,设置为 json(默认),则可以进一步指定错误消息字段;设置为 body 则将整个 body 解析为错误信息;
177
177
 
178
178
  **converter**: "camelize" | "snakify"
179
179
 
180
- 内容转化方式,默认不转化;设置 "camelize" 则所有字段转成驼峰格式,设置 "snakify" 则所有字段转成蛇形格式
180
+ 内容转化方式,默认不转化;设置 "camelize" 则所有字段转成驼峰格式,设置 "snakify" 则所有字段转成蛇形格式
181
181
 
182
182
  **statusField**: string
183
183
 
184
- 解析错误消息的状态字段,仅在 resolve 为 json 时有效,有值的话会替换 response 的 code
184
+ 解析错误消息的状态字段,仅在 resolve 为 json 时有效,有值的话会替换 response 的 code
185
185
 
186
186
  **messageField**: string | string[]
187
187
 
188
- 错误消息解析字段,仅在 resolve 为 json 时有效,默认值 "message"
188
+ 错误消息解析字段,仅在 resolve 为 json 时有效,默认值 "message"
189
189
 
190
- - **OKRule**: { resolve, statusField?, statusOKValue?, dataField?, messageField?, ignoreMessage? }
190
+ - **OKRule**: { resolve, converter?, statusField?, statusOKValue?, dataField?, messageField?, ignoreMessage? }
191
191
 
192
192
  http成功时 (200 <= status < 400) 解析策略
193
193
 
194
194
  **resolve**: "json" | "body"
195
195
 
196
- 解析方式,若设置为 json,则可以进一步指定更多字段;若设置为 body(默认),则把整个响应体作为接口返回的数据使用,如果格式化失败,则返回响应的字符串;
196
+ 解析方式,若设置为 json,则可以进一步指定更多字段;若设置为 body(默认),则把整个响应体作为接口返回的数据使用,如果格式化失败,则返回响应的字符串;
197
197
 
198
198
  **converter**: "camelize" | "snakify"
199
199
 
200
- 内容转化方式,默认不转化;设置 "camelize" 则所有字段转成驼峰格式,设置 "snakify" 则所有字段转成蛇形格式
200
+ 内容转化方式,默认不转化;设置 "camelize" 则所有字段转成驼峰格式,设置 "snakify" 则所有字段转成蛇形格式
201
201
 
202
202
  **statusField**: string
203
-
204
- 指定表示自定义状态的字段名,默认是 "code"
203
+
204
+ 指定表示自定义状态的字段名,默认是 "code"
205
205
 
206
206
  **statusOKValue**: string
207
207
 
208
- 指定表示自定义状态成功时的 value,默认是 "0",如果响应值为数字,则会被转化为字符串进行处理
208
+ 指定表示自定义状态成功时的 value,默认是 "0",如果响应值为数字,则会被转化为字符串进行处理
209
209
 
210
210
  **dataField**: string | true
211
211
 
212
- 指定表示响应数据的字段,默认是 "data",如果设置为 true,则将整个 json body 作为数据内容返回
212
+ 指定表示响应数据的字段,默认是 "data",如果设置为 true,则将整个 json body 作为数据内容返回
213
213
 
214
214
  **messageField**: string | string[]
215
215
 
216
- 指定表示提示消息的字段,提示消息可以包括错误消息和成功消息,默认是 "message"
216
+ 指定表示提示消息的字段,提示消息可以包括错误消息和成功消息,默认是 "message"
217
217
 
218
218
  **ignoreMessage**: string | string[]
219
219
 
220
- 指定忽略的消息,比如 ok 等,可以设置多个忽略消息,区分大小写
220
+ 指定忽略的消息,比如 ok 等,可以设置多个忽略消息,区分大小写
221
221
 
222
222
  ### maxRetry
223
223
 
@@ -231,9 +231,9 @@ setConfig({ timeout: 10000 })
231
231
 
232
232
  说明:重试判断方法,默认是 network
233
233
 
234
- network 表示仅仅当网络错误时才重试;
234
+ network 表示仅仅当网络错误时才重试,如果请求被取消(aborted)则不重试;
235
235
 
236
- status 表示网络错误或者http 状态码错误时重试;
236
+ status 表示网络错误或者http 状态码错误时(<200 || >=400)重试;
237
237
 
238
238
  当设置为 number[] 时,将检查 http 状态码,匹配则重试;
239
239
 
@@ -245,23 +245,23 @@ status 表示网络错误或者http 状态码错误时重试;
245
245
 
246
246
  类型:number | "2EB" | ((retryIndex: number) => number)
247
247
 
248
- 说明:两次重试的间隔策略,设置为数字(单位 ms)表示固定间隔,设置为函数则可以自定义间隔;
248
+ 说明:两次重试的间隔策略,设置为数字(单位 ms)表示固定间隔,设置为函数则可以自定义间隔;默认是 100ms;
249
249
 
250
250
  其中 retryIndex 从 1 开始,最大为 10;最小时间间隔为 100ms;
251
251
 
252
- 特殊值 2EB 表示以 2 为底的[指数退避策略](https://en.wikipedia.org/wiki/Exponential_backoff),即首次重试等待 1 秒,后续分别是 2秒,4秒,8秒 ...
252
+ 特殊值 2EB 表示以 2 为底的[指数退避策略](https://en.wikipedia.org/wiki/Exponential_backoff),即首次重试等待 0.1 秒,后续分别是 0.2秒,0.4秒,0.8秒 ...
253
253
 
254
254
  ### requestTransformer
255
255
 
256
256
  类型:null | ((data: {
257
- headers: Record<string, string>,
258
- params: Record<string, string>,
259
- method: string,
260
- url: string,
261
- body: IBaseRequestBody
262
- }) => MaybePromise<void | string>)
257
+ headers: Record<string, string>,
258
+ params: Record<string, string>,
259
+ method: string,
260
+ url: string,
261
+ body: IBaseRequestBody
262
+ }) => MaybePromise<void | string>)
263
263
 
264
- 说明:可用于发送前修改请求相关数据,通常用于追加认证信息或签名信息
264
+ 说明:可用于发送前修改请求相关数据
265
265
 
266
266
  - 发送前用于修改 headers 或 params 的函数,headers 和 params 为引用数据,可以直接修改或追加内容;
267
267
  - 函数如果返回一个非空字符串,则当作 url 地址使用,原有的 url 地址将被替换;
@@ -270,19 +270,19 @@ status 表示网络错误或者http 状态码错误时重试;
270
270
  ### errorHandler
271
271
 
272
272
  类型:null | ((data: {
273
- status: number,
274
- code: string,
275
- method: string,
276
- url: string,
277
- headers: Record<string, string>,
278
- rawError?: Error | ProgressEvent,
279
- responseBody: string,
280
- sentryError: Error,
281
- sentryTags: Record<string, string | number>,
282
- sentryExtra: Record<string, unknown>
283
- }) => void)
284
-
285
- 说明:全局错误处理函数,仅仅在 http status 错误时触发,通常用于检查 401 未登录状态进行跳转登录,其中 sentryError / sentryTags / sentryExtra 可用以进行 Sentry 信息上报;
273
+ status: number,
274
+ code: string,
275
+ method: string,
276
+ url: string,
277
+ headers: Record<string, string>,
278
+ rawError?: Error | ProgressEvent,
279
+ responseBody: string,
280
+ sentryError: Error,
281
+ sentryTags: Record<string, string | number>,
282
+ sentryExtra: Record<string, unknown>
283
+ }) => void)
284
+
285
+ 说明:全局错误处理函数,仅仅在 http status 错误时触发,通常用于检查 401 未登录状态进行跳转登录,其中 sentryError / sentryTags / sentryExtra 可用以进行 Sentry 信息上报(示例代码见下);
286
286
 
287
287
  ### responseHandler
288
288
 
@@ -328,11 +328,11 @@ status 表示网络错误或者http 状态码错误时重试;
328
328
 
329
329
  ### credentials
330
330
 
331
- 同全局配置,仅本次请求有效,可选 "omit" | "same-origin" | "include",默认 same-origin,如果跨域需要携带 cookie,可以设置为 include
331
+ 同全局配置,仅本次请求有效,可选 "omit" | "same-origin" | "include",如果跨域需要携带 cookie,可以设置为 include。默认跟随全局设置
332
332
 
333
333
  ### timeout
334
334
 
335
- 同全局配置,仅本次请求有效,默认 10000
335
+ 同全局配置,仅本次请求有效,默认跟随全局设置
336
336
 
337
337
  ### abort
338
338
 
@@ -344,23 +344,23 @@ status 表示网络错误或者http 状态码错误时重试;
344
344
 
345
345
  ### message
346
346
 
347
- 同全局配置,仅本次请求有效,可以设定 false 关闭消息提示,也可以传递函数自定义消息内容;
347
+ 同全局配置,仅本次请求有效,默认跟随全局设置
348
348
 
349
349
  ### responseRule
350
350
 
351
- 同全局配置,设定的解析规则仅本次请求有效
351
+ 同全局配置,设定的解析规则仅本次请求有效,默认跟随全局设置
352
352
 
353
353
  ### maxRetry
354
354
 
355
- 同全局配置,仅本次请求有效,设置最大重试次数,默认 0,即不重试
355
+ 同全局配置,仅本次请求有效,设置最大重试次数,默认跟随全局设置
356
356
 
357
357
  ### retryResolve
358
358
 
359
- 同全局配置,仅本次请求有效,设置重试判断策略,默认 network
359
+ 同全局配置,仅本次请求有效,设置重试判断策略,默认跟随全局设置
360
360
 
361
361
  ### retryInterval
362
362
 
363
- 同全局配置,仅本次请求有效,默认 1000ms
363
+ 同全局配置,仅本次请求有效,默认跟随全局设置
364
364
 
365
365
  ## 响应内容
366
366
 
@@ -376,7 +376,7 @@ status 表示网络错误或者http 状态码错误时重试;
376
376
 
377
377
  类型:number
378
378
 
379
- 说明:表示响应的 http 状态码,网络错误或其他异常情况返回负数(具体数值无含义)
379
+ 说明:表示响应的 http 状态码,请求被取消返回 0,网络错误或其他异常情况返回负数(具体数值无含义)
380
380
 
381
381
  ### code
382
382
 
@@ -384,9 +384,9 @@ status 表示网络错误或者http 状态码错误时重试;
384
384
 
385
385
  说明:表示当前请求的状态信息,其可能值有
386
386
 
387
- - http statusText 当请求完成且无自定义错误码时,可能为空字符串
387
+ - http statusText 当请求完成且无自定义错误码时,可能为空字符串
388
388
  - responseRule 中自定义的错误码字段所传递的值
389
- - "Aborted" 或 "Unknown" 网络错误或取消等异常情况
389
+ - "Aborted" 或 "Unknown" 网络错误或取消等异常情况,详细参见 `RequestInteralError`
390
390
 
391
391
  ### message
392
392
 
@@ -408,7 +408,7 @@ status 表示网络错误或者http 状态码错误时重试;
408
408
 
409
409
  - unknown:如果不提供类型守卫,则返回 unknown
410
410
  - null:网络请求错误、类型守卫检查失败、服务器没有返回正确格式的 json 数据,则返回 null
411
- - T: 如果成功返回并通过类型守卫检查,则返回类型守卫对应的类型
411
+ - T: 如果成功返回并通过类型守卫检查,则返回类型守卫对应的类型
412
412
 
413
413
  ## 类型守卫
414
414
 
@@ -481,15 +481,15 @@ type TypeGuardParam<T> = TypeGuard<T> | TypeGuardFn<T>
481
481
  使用 `form` 发送数据(所有数据均可以序列化为字符串)
482
482
 
483
483
  ```typescript
484
- const encodeFormData: string[]
485
- for(const key in data) {
486
- encodeFormData.push(`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`);
484
+ const encodeFormData: string[];
485
+ for (const key in data) {
486
+ encodeFormData.push(`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`);
487
487
  }
488
488
  // 需要手工指定Content-Type
489
489
  const { ok, data } = await post(url, encodeFormData.join("&"), typeGuard, {
490
- headers: {
491
- "Content-Type": "application/x-www-form-urlencoded"
492
- }
490
+ headers: {
491
+ "Content-Type": "application/x-www-form-urlencoded",
492
+ },
493
493
  });
494
494
  ```
495
495
 
@@ -497,8 +497,8 @@ const { ok, data } = await post(url, encodeFormData.join("&"), typeGuard, {
497
497
 
498
498
  ```typescript
499
499
  const formData = new FormData();
500
- for(const key in data) {
501
- formData.append(key, data[key]);
500
+ for (const key in data) {
501
+ formData.append(key, data[key]);
502
502
  }
503
503
  // 传递 FormData 实例时,无须手工指定 Content-Type
504
504
  const { ok, data } = await post(url, formData, typeGuard);
@@ -508,22 +508,22 @@ const { ok, data } = await post(url, formData, typeGuard);
508
508
 
509
509
  ```typescript
510
510
  setGlobalConfig({
511
- message: function({ code, status, message }, method, url, defaultMsg){
512
- if(status === 401) {
513
- return ""
514
- }
515
- if(status === 404) {
516
- return `${method} ${url} 接口未定义`;
517
- }
518
- if(status >= 500 && status <= 599) {
519
- return "🚨 服务器错误,请稍候再试";
520
- }
521
- if(code === "Unknown" || code === "Aborted") {
522
- return `⛔ ${url} 出现未知错误,请稍候再试`;
523
- }
524
- return message;
511
+ message: function ({ code, status, message }, method, url, defaultMsg) {
512
+ if (status === 401) {
513
+ return "";
514
+ }
515
+ if (status === 404) {
516
+ return `${method} ${url} 接口未定义`;
517
+ }
518
+ if (status >= 500 && status <= 599) {
519
+ return "🚨 服务器错误,请稍候再试";
525
520
  }
526
- })
521
+ if (code === "Unknown") {
522
+ return `⛔ ${url} 出现未知错误,请稍候再试`;
523
+ }
524
+ return message;
525
+ },
526
+ });
527
527
  ```
528
528
 
529
529
  Sentry 信息上报
@@ -532,15 +532,14 @@ Sentry 信息上报
532
532
  import { captureException } from "@sentry/vue";
533
533
 
534
534
  setGlobalConfig({
535
- errorHandler({ status, sentryError, sentryTags, sentryExtra }) {
536
- if(status === 401) {
537
- return
538
- }
539
- captureException(sentryError, {
540
- tags: sentryTags,
541
- extra: sentryExtra,
542
- })
535
+ errorHandler({ status, sentryError, sentryTags, sentryExtra }) {
536
+ if (status === 401) {
537
+ return;
543
538
  }
544
- })
539
+ captureException(sentryError, {
540
+ tags: sentryTags,
541
+ extra: sentryExtra,
542
+ });
543
+ },
544
+ });
545
545
  ```
546
-
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./retry-CRrgnQtP.cjs"),q=require("./request.fetch-YPs3rgIZ.cjs"),y=async function(t,s,e){return o.handleResponse(await o.retryRequest(R,t,s,e),t,s,e)};async function m(t,s,e,n){const r=e==null?void 0:e.body,u=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const i=new o.RequestGlobalConfig(n),f=await R(t,i,{...e,method:u,body:s});return o.handleResponse(f,t,i,e)}const c=new FormData,d={...s};r instanceof Object&&Object.entries(r).forEach(([i,f])=>{f instanceof Blob?d[i]=f:Array.isArray(f)?f.forEach((a,g)=>{c.append(`${i}[${g}]`,String(a))}):c.append(i,String(f))});for(const i in d)c.append(i,d[i]);const b=new o.RequestGlobalConfig(n),w=await R(t,b,{...e,method:u,body:c});return o.handleResponse(w,t,b,e)}const R=async function(t,s,e){const n=await o.convertOptions(t,s,e),r=n.method,u=e==null?void 0:e.onUploadProgress,c=o.Ht(n.url,n.params);return await new Promise(d=>{let b=null,w=!1;const i=function(){w||(a.abort(),w=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",i)}const a=new XMLHttpRequest;if(a.open(r,c,!0),u){let g=1;a.upload.addEventListener("progress",h=>{g=h.total,u({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{u({loaded:g,total:g})})}a.addEventListener("load",()=>{f(),d({url:c,method:r,status:a.status,statusText:a.statusText,headers:H(a),body:r==="HEAD"?"":a.responseText})}),a.addEventListener("error",g=>{f(),d({url:c,method:r,status:-1,statusText:o.RequestInteralError.Unknown,body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),d({url:c,method:r,status:-1,statusText:o.RequestInteralError.Aborted,body:""})}),Object.entries(n.headers).forEach(([g,h])=>{a.setRequestHeader(g,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",i),n.timeout>0&&(b=setTimeout(i,n.timeout))})};function H(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
- `).forEach(n=>{const r=n.trim();if(!r)return;const u=r.split(":"),c=u[0].trim();c&&(s[c]=(u[1]||"").trim())}),s}async function E(t,s,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const r=e.callback+"";if(!t)return null;const u=o.Ht(t,e,!0);return new Promise(c=>{n[r]=function(d){if(r in window&&delete n[r],s(d))return d;console.warn("response type check faild",t,d),c(null)},o.Oe(u).catch(function(){c(null),delete n[r]})})}async function T(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await o.Oe(o.Ht(t,e,!0)).then(()=>{const r=n[e.var+""];return s(r)?r:(console.warn("response type check faild",t,r),null)}).catch(()=>null):null}const C=async function(t,s,e){return await m(t,s,e,{baseURL:l.getConfig("baseURL"),logHandler:l.getConfig("logHandler"),errorHandler:l.getConfig("errorHandler"),requestTransformer:l.getConfig("requestTransformer"),messageHandler:l.getConfig("messageHandler"),responseHandler:l.getConfig("responseHandler")})};function p(t){if(!o.ee.window)throw new Error("Default Module Only Support In Browser");return o.ee.fetch?new o.NetRequestHandler(q.fetchRequest,t):new o.NetRequestHandler(y,t)}const l=p(),x=l.setConfig,j=l.request,L=l.head,S=l.get,O=l.post,U=l.del,k=l.put,v=l.patch;exports.RequestInteralError=o.RequestInteralError;exports.getResponseRulesDescription=o.getResponseRulesDescription;exports.NetRequest=p;exports.del=U;exports.get=S;exports.head=L;exports.jsonp=E;exports.jsonx=T;exports.patch=v;exports.post=O;exports.put=k;exports.request=j;exports.setGlobalConfig=x;exports.upload=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./retry-B9vBp2mw.cjs"),q=require("./request.fetch-rPuFhiKx.cjs"),y=async function(t,s,e){return o.handleResponse(await o.retryRequest(R,t,s,e),t,s,e)};async function m(t,s,e,n){const r=e==null?void 0:e.body,d=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const u=new o.RequestGlobalConfig(n),g=await R(t,u,{...e,method:d,body:s});return o.handleResponse(g,t,u,e)}const c=new FormData,f={...s};r instanceof Object&&Object.entries(r).forEach(([u,g])=>{g instanceof Blob?f[u]=g:Array.isArray(g)?g.forEach((a,i)=>{c.append(`${u}[${i}]`,String(a))}):c.append(u,String(g))});for(const u in f)c.append(u,f[u]);const b=new o.RequestGlobalConfig(n),w=await R(t,b,{...e,method:d,body:c});return o.handleResponse(w,t,b,e)}const R=async function(t,s,e){const n=await o.convertOptions(t,s,e),r=n.method,d=e==null?void 0:e.onUploadProgress,c=o.Zt(n.url,n.params);return await new Promise(f=>{let b=null,w=!1;const u=function(){w||(a.abort(),w=!0)};function g(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",u)}const a=new XMLHttpRequest;if(a.open(r,c,!0),d){let i=1;a.upload.addEventListener("progress",h=>{i=h.total,d({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{d({loaded:i,total:i})})}a.addEventListener("load",()=>{const i=a.status;g(),f({url:c,method:r,status:i,statusText:a.statusText,headers:E(a),body:r==="HEAD"||i===204?"":a.responseText})}),a.addEventListener("error",i=>{g(),f({url:c,method:r,status:a.status||-1,statusText:a.statusText||o.RequestInteralError.NetworkError,body:"",rawError:i})},!0),a.addEventListener("abort",()=>{g(),f({url:c,method:r,status:0,statusText:o.RequestInteralError.Aborted,body:""})}),Object.entries(n.headers).forEach(([i,h])=>{a.setRequestHeader(i,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",u),n.timeout>0&&(b=setTimeout(u,n.timeout))})};function E(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
+ `).forEach(n=>{const r=n.trim();if(!r)return;const d=r.split(":"),c=d[0].trim();c&&(s[c]=(d[1]||"").trim())}),s}async function H(t,s,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const r=e.callback+"";if(!t)return null;const d=o.Zt(t,e,!0);return new Promise(c=>{n[r]=function(f){if(r in window&&delete n[r],s(f))return f;console.warn("response type check faild",t,f),c(null)},o.Ie(d).catch(function(){c(null),delete n[r]})})}async function T(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await o.Ie(o.Zt(t,e,!0)).then(()=>{const r=n[e.var+""];return s(r)?r:(console.warn("response type check faild",t,r),null)}).catch(()=>null):null}const x=async function(t,s,e){return await m(t,s,e,{baseURL:l.getConfig("baseURL"),logHandler:l.getConfig("logHandler"),errorHandler:l.getConfig("errorHandler"),requestTransformer:l.getConfig("requestTransformer"),messageHandler:l.getConfig("messageHandler"),responseHandler:l.getConfig("responseHandler")})};function p(t){if(!o.lt.window)throw new Error("Default Module Only Support In Browser");return o.lt.fetch?new o.NetRequestHandler(q.fetchRequest,t):new o.NetRequestHandler(y,t)}const l=p(),C=l.setConfig,j=l.request,L=l.head,S=l.get,k=l.post,v=l.del,D=l.put,U=l.patch;exports.RequestInteralError=o.RequestInteralError;exports.getResponseRulesDescription=o.getResponseRulesDescription;exports.NetRequest=p;exports.del=v;exports.get=S;exports.head=L;exports.jsonp=H;exports.jsonx=T;exports.patch=U;exports.post=k;exports.put=D;exports.request=j;exports.setGlobalConfig=C;exports.upload=x;