@seayoo-web/request 4.0.3 → 4.0.5
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.js +3 -3
- package/dist/node.js +3 -3
- package/dist/{request.fetch-D-T4XbBr.js → request.fetch-zzHMZXfR.js} +1 -1
- package/dist/{retry-CQEDKWe8.js → retry-LYfsjIVg.js} +28 -28
- package/dist/wx.js +2 -2
- package/package.json +1 -1
- package/types/inc/main.d.ts +1 -0
- package/types/index.d.ts +3 -3
- package/types/node.d.ts +3 -3
- package/types/wx.d.ts +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
2
|
-
import { g as W } from "./retry-
|
|
3
|
-
import { f as S } from "./request.fetch-
|
|
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-LYfsjIVg.js";
|
|
2
|
+
import { g as W } from "./retry-LYfsjIVg.js";
|
|
3
|
+
import { f as S } from "./request.fetch-zzHMZXfR.js";
|
|
4
4
|
const j = async function(n, a, t) {
|
|
5
5
|
return h(await E(m, n, a, t), n, a, t);
|
|
6
6
|
};
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { h as w, r as R, c as y, e as b, f as q, R as s, N as h, X as g } from "./retry-
|
|
2
|
-
import { g as S } from "./retry-
|
|
3
|
-
import { f as x } from "./request.fetch-
|
|
1
|
+
import { h as w, r as R, c as y, e as b, f as q, R as s, N as h, X as g } from "./retry-LYfsjIVg.js";
|
|
2
|
+
import { g as S } from "./retry-LYfsjIVg.js";
|
|
3
|
+
import { f as x } from "./request.fetch-zzHMZXfR.js";
|
|
4
4
|
import N from "node:http";
|
|
5
5
|
import C from "node:https";
|
|
6
6
|
const E = async function(o, n, a) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as f, r as h, c as m, i as b, f as y, e as T, R as u } from "./retry-
|
|
1
|
+
import { h as f, r as h, c as m, i as b, f as y, e as T, R as u } from "./retry-LYfsjIVg.js";
|
|
2
2
|
const x = async function(o, a, s) {
|
|
3
3
|
return f(await h(w, o, a, s), o, a, s);
|
|
4
4
|
}, w = async function(o, a, s) {
|
|
@@ -8,22 +8,22 @@ function y(e) {
|
|
|
8
8
|
function U(e) {
|
|
9
9
|
return typeof e == "object" && e !== null;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function O() {
|
|
12
12
|
return "wx" in f && U(f.wx) && "getSystemInfo" in f.wx && y(f.wx.getSystemInfo);
|
|
13
13
|
}
|
|
14
14
|
function we() {
|
|
15
15
|
return "fetch" in f && y(f.fetch);
|
|
16
16
|
}
|
|
17
17
|
function be() {
|
|
18
|
-
return "window" in f && U(f.window) && !
|
|
18
|
+
return "window" in f && U(f.window) && !O();
|
|
19
19
|
}
|
|
20
20
|
function R() {
|
|
21
21
|
return "Blob" in f && y(f.Blob);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function F() {
|
|
24
24
|
return "FormData" in f && y(f.FormData);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function M() {
|
|
27
27
|
return "TextDecoder" in f && y(f.TextDecoder);
|
|
28
28
|
}
|
|
29
29
|
function Ee() {
|
|
@@ -52,15 +52,15 @@ const I = /^(?:https?:)?\/\/.+$/i, G = /^https?:\/\/.+$/i, K = /^\{[\d\D]*\}$/,
|
|
|
52
52
|
function $(e, t = !1) {
|
|
53
53
|
return t ? I.test(e) : G.test(e);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function A(e) {
|
|
56
56
|
return e == null;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function S(e, ...t) {
|
|
59
59
|
if (!e || typeof e != "object") return !1;
|
|
60
60
|
const r = Object.getPrototypeOf(e);
|
|
61
61
|
return r !== Object.prototype && r !== null ? !1 : t.every((s) => s in e);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function L(e) {
|
|
64
64
|
return K.test(e) || _.test(e);
|
|
65
65
|
}
|
|
66
66
|
function E(e, t) {
|
|
@@ -235,7 +235,7 @@ const g = {
|
|
|
235
235
|
NotSupport: "NotSupport"
|
|
236
236
|
};
|
|
237
237
|
function ee(e, t, r, s) {
|
|
238
|
-
if (t.ok && !
|
|
238
|
+
if (t.ok && !A(t.data) && s) {
|
|
239
239
|
const { guard: n, message: o } = J(s, r.get("defaultTypeGuardMessage"));
|
|
240
240
|
return n(t.data) || (t.code = g.UnexpectResponse, r.showMessage(!0, `${e} ${o}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = o), t;
|
|
241
241
|
}
|
|
@@ -337,21 +337,21 @@ function se(e) {
|
|
|
337
337
|
n && (t[r] = n);
|
|
338
338
|
}), t;
|
|
339
339
|
}
|
|
340
|
-
function
|
|
341
|
-
return
|
|
340
|
+
function B(e) {
|
|
341
|
+
return A(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && M() ? new TextDecoder().decode(e) : JSON.stringify(e);
|
|
342
342
|
}
|
|
343
343
|
function re(e) {
|
|
344
|
-
return e instanceof Error ? e : new Error(
|
|
344
|
+
return e instanceof Error ? e : new Error(B(e));
|
|
345
345
|
}
|
|
346
346
|
async function Re(e) {
|
|
347
|
-
if (
|
|
347
|
+
if (M())
|
|
348
348
|
return new TextEncoder().encode(e).buffer;
|
|
349
349
|
if (R())
|
|
350
350
|
return await new Blob([e]).arrayBuffer();
|
|
351
351
|
throw new Error("cannot convert string to ArrayBuffer");
|
|
352
352
|
}
|
|
353
353
|
function ne(e, t) {
|
|
354
|
-
if ("URL" in C()) {
|
|
354
|
+
if ("URL" in C() && !O()) {
|
|
355
355
|
const s = new URL(e);
|
|
356
356
|
return Object.keys(t).forEach((n) => s.searchParams.set(n, t[n])), s.toString();
|
|
357
357
|
}
|
|
@@ -369,7 +369,7 @@ function ce({ status: e, headers: t, error: r }) {
|
|
|
369
369
|
return r === g.NetworkError ? !0 : t?.server === "TencentEdgeOne" ? e === 522 || e === 552 : !1;
|
|
370
370
|
}
|
|
371
371
|
async function $e(e, t, r) {
|
|
372
|
-
const s = { ...r, method: r?.method || "GET" }, n =
|
|
372
|
+
const s = { ...r, method: r?.method || "GET" }, n = F() ? s.body instanceof FormData : !1, o = n && s.method !== "POST" && s.method !== "PUT" ? "POST" : s.method, a = o === "GET" || o === "HEAD" || o === "DELETE";
|
|
373
373
|
a && s.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete s.body);
|
|
374
374
|
const u = n || a ? { ...s.headers } : {
|
|
375
375
|
"Content-Type": R() && s.body instanceof Blob ? s.body.type || "application/octet-stream" : "application/json;charset=utf-8",
|
|
@@ -392,11 +392,11 @@ async function $e(e, t, r) {
|
|
|
392
392
|
}
|
|
393
393
|
function ie(e) {
|
|
394
394
|
if (e)
|
|
395
|
-
return typeof e == "string" || q() && e instanceof URLSearchParams || e instanceof ArrayBuffer || R() && e instanceof Blob ||
|
|
395
|
+
return typeof e == "string" || q() && e instanceof URLSearchParams || e instanceof ArrayBuffer || R() && e instanceof Blob || F() && e instanceof FormData ? e : JSON.stringify(e);
|
|
396
396
|
}
|
|
397
|
-
const
|
|
397
|
+
const D = "data", w = "message";
|
|
398
398
|
function ue(e, t, r) {
|
|
399
|
-
return
|
|
399
|
+
return P(e.status) ? fe(r?.ok || t.ok, e) : he(r?.failed || t.failed, e);
|
|
400
400
|
}
|
|
401
401
|
function fe(e, { statusText: t, body: r }) {
|
|
402
402
|
const s = {
|
|
@@ -410,17 +410,17 @@ function fe(e, { statusText: t, body: r }) {
|
|
|
410
410
|
if (typeof r != "string")
|
|
411
411
|
return s.data = r, s;
|
|
412
412
|
if (e.resolve === "body")
|
|
413
|
-
return s.data =
|
|
413
|
+
return s.data = L(r) ? k(E(r), e.converter) : r, s;
|
|
414
414
|
const n = E(r);
|
|
415
415
|
if (!n)
|
|
416
416
|
return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法解析为 json", s;
|
|
417
417
|
const o = k(n, e.converter);
|
|
418
|
-
if (!o || !
|
|
418
|
+
if (!o || !S(o))
|
|
419
419
|
return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法格式化为 object", s;
|
|
420
420
|
const a = e.statusField;
|
|
421
421
|
if (a && !(a in o))
|
|
422
422
|
return s.ok = !1, s.code = "ResponseFieldMissing", s.message = `响应内容找不到状态字段 ${a}`, s;
|
|
423
|
-
const u = e.statusOKValue || "", c = e.dataField ||
|
|
423
|
+
const u = e.statusOKValue || "", c = e.dataField || D, l = e.messageField || w, i = a ? String(o[a] ?? "") : "";
|
|
424
424
|
return s.ok = a ? i === u : !0, s.code = i || s.code, s.data = c === !0 ? o : c in o ? o[c] : null, s.message = T(o, l), e.ignoreMessage && s.message && (Array.isArray(e.ignoreMessage) ? e.ignoreMessage.includes(s.message) : e.ignoreMessage === s.message) && (s.message = ""), s;
|
|
425
425
|
}
|
|
426
426
|
function he(e, { statusText: t, body: r, error: s }) {
|
|
@@ -455,7 +455,7 @@ function he(e, { statusText: t, body: r, error: s }) {
|
|
|
455
455
|
}
|
|
456
456
|
return o;
|
|
457
457
|
}
|
|
458
|
-
function
|
|
458
|
+
function P(e) {
|
|
459
459
|
return e >= 200 && e < 400;
|
|
460
460
|
}
|
|
461
461
|
function k(e, t) {
|
|
@@ -478,7 +478,7 @@ const xe = function(e) {
|
|
|
478
478
|
break;
|
|
479
479
|
case "json":
|
|
480
480
|
t.push(
|
|
481
|
-
" 将响应解析为 json,读取 " + (s.dataField ||
|
|
481
|
+
" 将响应解析为 json,读取 " + (s.dataField || D) + " 作为响应数据,读取 " + (s.messageField || w) + " 作为提示消息"
|
|
482
482
|
), s.statusField && t.push(
|
|
483
483
|
" 当 " + s.statusField + " 为 " + (s.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
|
|
484
484
|
), s.ignoreMessage && t.push(" 并忽略以下消息:" + s.ignoreMessage);
|
|
@@ -488,10 +488,10 @@ const xe = function(e) {
|
|
|
488
488
|
`);
|
|
489
489
|
};
|
|
490
490
|
function le(e, t, r, s = w) {
|
|
491
|
-
if (!
|
|
491
|
+
if (!L(e))
|
|
492
492
|
return { message: "" };
|
|
493
493
|
const n = k(E(e), t);
|
|
494
|
-
return !n || !
|
|
494
|
+
return !n || !S(n) ? { message: e } : {
|
|
495
495
|
code: r ? T(n, r) : "",
|
|
496
496
|
message: T(n, s) || e
|
|
497
497
|
};
|
|
@@ -500,7 +500,7 @@ function T(e, t) {
|
|
|
500
500
|
const r = Array.isArray(t) ? t : [t];
|
|
501
501
|
for (const s of r)
|
|
502
502
|
if (s in e)
|
|
503
|
-
return
|
|
503
|
+
return B(e[s]);
|
|
504
504
|
return "";
|
|
505
505
|
}
|
|
506
506
|
const de = [/<title>([^<]+)<\/title>/i, /<message>([^<]+)<\/message>/i];
|
|
@@ -549,7 +549,7 @@ function ve(e, t, r, s) {
|
|
|
549
549
|
const n = e.status, o = e.method, a = te(
|
|
550
550
|
Object.entries(e.headers || {}).map(([d, m]) => [d.toLowerCase(), m])
|
|
551
551
|
), { ok: u, code: c, data: l, message: i } = ue(e, r.get("responseRule"), s?.responseRule);
|
|
552
|
-
if (!
|
|
552
|
+
if (!P(n)) {
|
|
553
553
|
const d = me({
|
|
554
554
|
url: e.url,
|
|
555
555
|
method: e.method,
|
|
@@ -634,7 +634,7 @@ async function ye(e, t, r, s, n) {
|
|
|
634
634
|
), await ye(e, t, r, s, o + 1);
|
|
635
635
|
}
|
|
636
636
|
export {
|
|
637
|
-
|
|
637
|
+
O as E,
|
|
638
638
|
Z as G,
|
|
639
639
|
z as H,
|
|
640
640
|
Te as N,
|
|
@@ -650,6 +650,6 @@ export {
|
|
|
650
650
|
ve as h,
|
|
651
651
|
Ee as i,
|
|
652
652
|
ye as r,
|
|
653
|
-
|
|
653
|
+
B as t,
|
|
654
654
|
ke as v
|
|
655
655
|
};
|
package/dist/wx.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as l, r as p, c as y, E as R, R as u, f as x, a as h, t as c, N as w } from "./retry-
|
|
2
|
-
import { g as O } from "./retry-
|
|
1
|
+
import { h as l, r as p, c as y, E as R, R as u, f as x, a as h, t as c, N as w } from "./retry-LYfsjIVg.js";
|
|
2
|
+
import { g as O } from "./retry-LYfsjIVg.js";
|
|
3
3
|
const m = async function(s, o, n) {
|
|
4
4
|
return l(await p(q, s, o, n), s, o, n);
|
|
5
5
|
}, q = async function(s, o, n) {
|
package/package.json
CHANGED
package/types/inc/main.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type URLPlus = string | {
|
|
|
7
7
|
export type BufferRequestOptions = RequestOptions & {
|
|
8
8
|
asBuffer: true;
|
|
9
9
|
};
|
|
10
|
+
export type INetRequestHandler = Pick<NetRequestHandler, keyof NetRequestHandler>;
|
|
10
11
|
/** 工具函数主类 */
|
|
11
12
|
export declare class NetRequestHandler {
|
|
12
13
|
private agent;
|
package/types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INetRequestHandler } from "./inc/main";
|
|
2
2
|
import { xhrUpload } from "./inc/request.xhr";
|
|
3
3
|
import type { RequestGlobalConfig } from "./inc/type";
|
|
4
4
|
export { jsonp, jsonx } from "./inc/jsonp";
|
|
5
5
|
export { getResponseRulesDescription } from "./inc/rule";
|
|
6
6
|
export { RequestInternalError } from "./inc/type";
|
|
7
|
-
export type { NetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
7
|
+
export type { NetRequestHandler, INetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
8
8
|
export type { RequestOptions, RequestGlobalConfig, ResponseRule, ResponseResult, RequestLog, RequestMethod, RequestQueryParams, } from "./inc/type";
|
|
9
9
|
/**
|
|
10
10
|
* 基于 xhr 模块的上传工具,支持上传进度
|
|
@@ -15,7 +15,7 @@ export type NetRequestFactory = typeof NetRequest;
|
|
|
15
15
|
/**
|
|
16
16
|
* 创建新的实例空间,配置和缓存跟全局默认实例是隔离的,仅支持在浏览器环境使用
|
|
17
17
|
*/
|
|
18
|
-
export declare function NetRequest(config?: RequestGlobalConfig):
|
|
18
|
+
export declare function NetRequest(config?: RequestGlobalConfig): INetRequestHandler;
|
|
19
19
|
/**
|
|
20
20
|
* 设置全局默认的 Request Config
|
|
21
21
|
*/
|
package/types/node.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INetRequestHandler } from "./inc/main";
|
|
2
2
|
import type { RequestGlobalConfig } from "./inc/type";
|
|
3
3
|
export { getResponseRulesDescription } from "./inc/rule";
|
|
4
4
|
export { RequestInternalError } from "./inc/type";
|
|
5
|
-
export type { NetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
5
|
+
export type { NetRequestHandler, INetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
6
6
|
export type { RequestOptions, RequestGlobalConfig, ResponseRule, ResponseResult, RequestLog, RequestMethod, RequestQueryParams, } from "./inc/type";
|
|
7
7
|
/**
|
|
8
8
|
* 创建新的实例空间,配置和缓存跟全局默认实例是隔离的
|
|
9
9
|
*/
|
|
10
|
-
export declare function NetRequest(config?: RequestGlobalConfig):
|
|
10
|
+
export declare function NetRequest(config?: RequestGlobalConfig): INetRequestHandler;
|
|
11
11
|
/**
|
|
12
12
|
* 设置全局默认的 Request Config
|
|
13
13
|
*/
|
package/types/wx.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INetRequestHandler } from "./inc/main";
|
|
2
2
|
import type { RequestGlobalConfig } from "./inc/type";
|
|
3
3
|
export { getResponseRulesDescription } from "./inc/rule";
|
|
4
4
|
export { RequestInternalError } from "./inc/type";
|
|
5
|
-
export type { NetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
5
|
+
export type { NetRequestHandler, INetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
6
6
|
export type { RequestOptions, RequestGlobalConfig, ResponseRule, ResponseResult, RequestLog, RequestMethod, RequestQueryParams, } from "./inc/type";
|
|
7
7
|
/**
|
|
8
8
|
* 创建新的实例空间,配置和缓存跟全局默认实例是隔离的
|
|
9
9
|
*/
|
|
10
|
-
export declare function NetRequest(config?: RequestGlobalConfig):
|
|
10
|
+
export declare function NetRequest(config?: RequestGlobalConfig): INetRequestHandler;
|
|
11
11
|
/**
|
|
12
12
|
* 设置全局默认的 Request Config
|
|
13
13
|
*/
|