@seayoo-web/request 3.4.5 → 3.5.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 CHANGED
@@ -226,13 +226,13 @@ defaultMessage: string
226
226
 
227
227
  ### retryResolve
228
228
 
229
- 类型:"network" | "status" | number[] | ((result: IRequestBaseResponse, count: number) => boolean)
229
+ 类型:"default" | "network" | number[] | ((result: IRequestBaseResponse, count: number) => boolean)
230
230
 
231
- 说明:重试判断方法,默认是 network
231
+ 说明:重试判断方法,默认是 default
232
232
 
233
- network 表示仅仅当网络错误时才重试,如果请求被取消(aborted)则不重试;
233
+ default 在 network 基础之上,如果是 Tencent EO 响应的 552/522 错误码,则重试;
234
234
 
235
- status 表示网络错误或者http 状态码错误时(<200 || >=400)重试;
235
+ network 表示仅仅当网络错误时才重试,如果请求被取消或超时(aborted/timeout)则不重试;
236
236
 
237
237
  当设置为 number[] 时,将检查 http 状态码,匹配则重试;
238
238
 
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { h as m, r as q, R as T, c as x, Q as R, a as w, _ as H, l as C, N as E, Z as L } from "./retry-BjOxSyvC.js";
2
- import { g as z } from "./retry-BjOxSyvC.js";
3
- import { f as j } from "./request.fetch-6HUu6_l5.js";
4
- const k = async function(t, s, e) {
1
+ import { h as m, r as q, R as T, c as x, H as R, a as w, v as E, b as C, N as H, X as L } from "./retry-DodVI8cA.js";
2
+ import { g as Q } from "./retry-DodVI8cA.js";
3
+ import { f as v } from "./request.fetch-BHmmkAon.js";
4
+ const j = async function(t, s, e) {
5
5
  return m(await q(y, t, s, e), t, s, e);
6
6
  };
7
- async function S(t, s, e, n) {
7
+ async function k(t, s, e, n) {
8
8
  const r = e?.body, l = e?.method === "PUT" ? "PUT" : "POST";
9
9
  if (s instanceof Blob) {
10
10
  const i = new T(n), u = await y(t, i, {
@@ -16,31 +16,31 @@ async function S(t, s, e, n) {
16
16
  }
17
17
  const a = new FormData(), d = { ...s };
18
18
  r instanceof Object && Object.entries(r).forEach(([i, u]) => {
19
- u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o, g) => {
20
- a.append(`${i}[${g}]`, String(o));
19
+ u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o, h) => {
20
+ a.append(`${i}[${h}]`, String(o));
21
21
  }) : a.append(i, String(u));
22
22
  });
23
23
  for (const i in d)
24
24
  a.append(i, d[i]);
25
- const b = new T(n), h = await y(t, b, {
25
+ const b = new T(n), g = await y(t, b, {
26
26
  ...e,
27
27
  method: l,
28
28
  body: a
29
29
  });
30
- return m(h, t, b, e);
30
+ return m(g, t, b, e);
31
31
  }
32
32
  const y = async function(t, s, e) {
33
33
  const n = await x(t, s, e), r = n.method, l = e?.onUploadProgress, a = R(n.url, n.params);
34
34
  return await new Promise((d) => {
35
- let b = null, h = !1;
35
+ let b = null, g = !1;
36
36
  const i = function() {
37
- h || (o.abort(), h = !0);
37
+ g || (o.abort(), g = !0);
38
38
  };
39
39
  function u() {
40
40
  b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", i);
41
41
  }
42
42
  const o = new XMLHttpRequest();
43
- let g = !1;
43
+ let h = !1;
44
44
  if (o.open(r, a, !0), l) {
45
45
  let f = 1;
46
46
  o.upload.addEventListener("progress", (p) => {
@@ -56,7 +56,7 @@ const y = async function(t, s, e) {
56
56
  method: r,
57
57
  status: f,
58
58
  statusText: o.statusText,
59
- headers: U(o),
59
+ headers: S(o),
60
60
  body: r === "HEAD" || f === 204 ? "" : p === "" || p === "text" || p === "json" || p === "document" ? o.responseText : ""
61
61
  });
62
62
  }), o.addEventListener(
@@ -76,19 +76,18 @@ const y = async function(t, s, e) {
76
76
  u(), d({
77
77
  url: a,
78
78
  method: r,
79
- status: g ? -1 : 0,
80
- // 设置为 0 可以防止自动重试的默认策略
81
- statusText: g ? w.Timeout : w.Aborted,
79
+ status: -1,
80
+ statusText: h ? w.Timeout : w.Aborted,
82
81
  body: ""
83
82
  });
84
83
  }), Object.entries(n.headers).forEach(([f, p]) => {
85
84
  o.setRequestHeader(f, p);
86
85
  }), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", i), n.timeout > 0 && (b = setTimeout(function() {
87
- g = !0, i();
86
+ h = !0, i();
88
87
  }, n.timeout));
89
88
  });
90
89
  };
91
- function U(t) {
90
+ function S(t) {
92
91
  const s = {};
93
92
  if (!t)
94
93
  return s;
@@ -114,20 +113,20 @@ async function P(t, s, e = {}) {
114
113
  if (r in window && delete n[r], s(d))
115
114
  return d;
116
115
  console.warn("response type check failed", t, d), a(null);
117
- }, H(l).catch(function() {
116
+ }, E(l).catch(function() {
118
117
  a(null), delete n[r];
119
118
  });
120
119
  });
121
120
  }
122
121
  async function A(t, s, e = {}) {
123
122
  const n = window;
124
- return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await H(R(t, e, !0)).then(() => {
123
+ return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await E(R(t, e, !0)).then(() => {
125
124
  const r = n[e.var + ""];
126
125
  return s(r) ? r : (console.warn("response type check failed", t, r), null);
127
126
  }).catch(() => null) : null;
128
127
  }
129
128
  const M = async function(t, s, e) {
130
- return await S(t, s, e, {
129
+ return await k(t, s, e, {
131
130
  baseURL: c.getConfig("baseURL"),
132
131
  logHandler: c.getConfig("logHandler"),
133
132
  errorHandler: c.getConfig("errorHandler"),
@@ -137,25 +136,25 @@ const M = async function(t, s, e) {
137
136
  });
138
137
  };
139
138
  // @__NO_SIDE_EFFECTS__
140
- function v(t) {
139
+ function U(t) {
141
140
  if (!C())
142
141
  throw new Error("Default Module Only Support In Browser");
143
- return L() ? new E(j, t) : new E(k, t);
142
+ return L() ? new H(v, t) : new H(j, t);
144
143
  }
145
- const c = /* @__PURE__ */ v(), N = c.setConfig, B = c.request, X = c.head, F = c.get, G = c.post, I = c.del, Q = c.put, Z = c.patch;
144
+ const c = /* @__PURE__ */ U(), N = c.setConfig, X = c.request, B = c.head, F = c.get, G = c.post, I = c.del, $ = c.put, z = c.patch;
146
145
  export {
147
- v as NetRequest,
146
+ U as NetRequest,
148
147
  w as RequestInternalError,
149
148
  I as del,
150
149
  F as get,
151
- z as getResponseRulesDescription,
152
- X as head,
150
+ Q as getResponseRulesDescription,
151
+ B as head,
153
152
  P as jsonp,
154
153
  A as jsonx,
155
- Z as patch,
154
+ z as patch,
156
155
  G as post,
157
- Q as put,
158
- B as request,
156
+ $ as put,
157
+ X as request,
159
158
  N as setGlobalConfig,
160
159
  M as upload
161
160
  };
package/dist/node.js CHANGED
@@ -1,10 +1,10 @@
1
- import { h as y, r as q, c as w, b as g, a as d, f as E, N as f, Z as x } from "./retry-BjOxSyvC.js";
2
- import { g as z } from "./retry-BjOxSyvC.js";
3
- import { f as C } from "./request.fetch-6HUu6_l5.js";
1
+ import { h as b, r as q, c as w, n as g, a as d, f as E, N as f, X as x } from "./retry-DodVI8cA.js";
2
+ import { g as z } from "./retry-DodVI8cA.js";
3
+ import { f as C } from "./request.fetch-BHmmkAon.js";
4
4
  import N from "node:http";
5
5
  import T from "node:https";
6
6
  const j = async function(o, a, u) {
7
- return y(await q(L, o, a, u), o, a, u);
7
+ return b(await q(L, o, a, u), o, a, u);
8
8
  }, L = async function(o, a, u) {
9
9
  const t = await w(o, a, u);
10
10
  if (!g(t.url))
@@ -31,7 +31,7 @@ const j = async function(o, a, u) {
31
31
  const p = [];
32
32
  e.on("data", (m) => p.push(m)), e.on("end", () => {
33
33
  const m = E(
34
- Object.entries(e.headers).map(([b, h]) => [b.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
34
+ Object.entries(e.headers).map(([y, h]) => [y.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
35
35
  );
36
36
  r({
37
37
  url: n.toString(),
@@ -68,11 +68,11 @@ const j = async function(o, a, u) {
68
68
  function O(o) {
69
69
  return x() ? new f(C, o) : new f(j, o);
70
70
  }
71
- const s = /* @__PURE__ */ O(), k = s.setConfig, B = s.head, D = s.get, P = s.post, Z = s.del, F = s.put, G = s.patch;
71
+ const s = /* @__PURE__ */ O(), k = s.setConfig, B = s.head, D = s.get, P = s.post, X = s.del, F = s.put, G = s.patch;
72
72
  export {
73
73
  O as NetRequest,
74
74
  d as RequestInternalError,
75
- Z as del,
75
+ X as del,
76
76
  D as get,
77
77
  z as getResponseRulesDescription,
78
78
  B as head,
@@ -0,0 +1,48 @@
1
+ import { h as w, r as y, c as E, d as T, f as g, a as c } from "./retry-DodVI8cA.js";
2
+ const x = async function(o, a, s) {
3
+ return w(await y(R, o, a, s), o, a, s);
4
+ }, R = async function(o, a, s) {
5
+ const t = await E(o, a, s), n = new URL(t.url), u = t.params;
6
+ u instanceof Object && Object.keys(u).forEach((e) => n.searchParams.set(e, u[e]));
7
+ const r = T() ? new AbortController() : null;
8
+ function d(e) {
9
+ r && !r.signal.aborted && r.abort(e);
10
+ }
11
+ t.abort && t.abort.addEventListener("abort", d);
12
+ let h = !1;
13
+ const b = t.timeout > 0 ? setTimeout(function() {
14
+ h = !0, d("TimeoutTriggered");
15
+ }, t.timeout) : null, m = t.method === "HEAD";
16
+ return await fetch(n, {
17
+ method: t.method,
18
+ headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
19
+ body: t.body,
20
+ credentials: t.credentials,
21
+ signal: r?.signal,
22
+ redirect: "follow"
23
+ }).then(async (e) => {
24
+ const i = {
25
+ url: n.toString(),
26
+ method: t.method,
27
+ status: e.status,
28
+ statusText: e.statusText,
29
+ headers: g([...e.headers.entries()])
30
+ }, l = m || e.status === 204 ? "" : await e.text().catch((f) => f);
31
+ return l instanceof Error ? { ...i, body: "", statusText: c.Unknown, rawError: l } : { ...i, body: l };
32
+ }).catch((e) => {
33
+ const i = r?.signal.aborted;
34
+ return {
35
+ url: n.toString(),
36
+ method: t.method,
37
+ status: -1,
38
+ statusText: h ? c.Timeout : i ? c.Aborted : c.NetworkError,
39
+ body: "",
40
+ rawError: e
41
+ };
42
+ }).finally(() => {
43
+ b !== null && clearTimeout(b), t.abort && t.abort.removeEventListener("abort", d);
44
+ });
45
+ };
46
+ export {
47
+ x as f
48
+ };