@seayoo-web/request 3.4.0 → 3.4.4

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
@@ -141,7 +141,7 @@ setConfig({ timeout: 10000 });
141
141
 
142
142
  类型:string
143
143
 
144
- 说明:默认的类型守卫错误提示,仅支持全局配置,默认 “响应数据未能正确识别“,单个 api 可通过传入完整的类型守卫({ guard, message })来定制提示消息。
144
+ 说明:默认的类型守卫错误提示,仅支持全局配置,默认 “响应数据未能正确识别”,单个 api 可通过传入完整的类型守卫({ guard, message })来定制提示消息。
145
145
 
146
146
  ### message
147
147
 
@@ -180,11 +180,11 @@ defaultMessage: string
180
180
 
181
181
  **statusField**: string
182
182
 
183
- 解析错误消息的状态字段,仅在 resolve 为 json 时有效,有值的话会替换 response 的 code
183
+ 解析状态的字段,仅在 resolve 为 json 时有效,有值的话会替换 response 的 code
184
184
 
185
185
  **messageField**: string | string[]
186
186
 
187
- 错误消息解析字段,仅在 resolve 为 json 时有效,默认值 "message"
187
+ 解析错误消息的字段,仅在 resolve 为 json 时有效,默认值 "message"
188
188
 
189
189
  - **OKRule**: { resolve, converter?, statusField?, statusOKValue?, dataField?, messageField?, ignoreMessage? }
190
190
 
package/dist/index.js CHANGED
@@ -1,78 +1,78 @@
1
- import { h as m, r as q, R as T, c as x, W as R, a as w, P as H, V as C, N as E, Q as L } from "./retry-CdUkYrFw.js";
2
- import { g as z } from "./retry-CdUkYrFw.js";
3
- import { f as k } from "./request.fetch-B3ED8nRu.js";
4
- const P = async function(e, o, t) {
5
- return m(await q(y, e, o, t), e, o, t);
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) {
5
+ return m(await q(y, t, s, e), t, s, e);
6
6
  };
7
- async function S(e, o, t, n) {
8
- const r = t?.body, l = t?.method === "PUT" ? "PUT" : "POST";
9
- if (o instanceof Blob) {
10
- const i = new T(n), u = await y(e, i, {
11
- ...t,
7
+ async function S(t, s, e, n) {
8
+ const r = e?.body, l = e?.method === "PUT" ? "PUT" : "POST";
9
+ if (s instanceof Blob) {
10
+ const i = new T(n), u = await y(t, i, {
11
+ ...e,
12
12
  method: l,
13
- body: o
13
+ body: s
14
14
  });
15
- return m(u, e, i, t);
15
+ return m(u, t, i, e);
16
16
  }
17
- const a = new FormData(), d = { ...o };
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((s, g) => {
20
- a.append(`${i}[${g}]`, String(s));
19
+ u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o, g) => {
20
+ a.append(`${i}[${g}]`, 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), p = await y(e, b, {
26
- ...t,
25
+ const b = new T(n), h = await y(t, b, {
26
+ ...e,
27
27
  method: l,
28
28
  body: a
29
29
  });
30
- return m(p, e, b, t);
30
+ return m(h, t, b, e);
31
31
  }
32
- const y = async function(e, o, t) {
33
- const n = await x(e, o, t), r = n.method, l = t?.onUploadProgress, a = R(n.url, n.params);
32
+ const y = async function(t, s, e) {
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, p = !1;
35
+ let b = null, h = !1;
36
36
  const i = function() {
37
- p || (s.abort(), p = !0);
37
+ h || (o.abort(), h = !0);
38
38
  };
39
39
  function u() {
40
40
  b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", i);
41
41
  }
42
- const s = new XMLHttpRequest();
42
+ const o = new XMLHttpRequest();
43
43
  let g = !1;
44
- if (s.open(r, a, !0), l) {
44
+ if (o.open(r, a, !0), l) {
45
45
  let f = 1;
46
- s.upload.addEventListener("progress", (h) => {
47
- f = h.total, l({ total: h.total, loaded: h.loaded });
48
- }), s.addEventListener("load", () => {
46
+ o.upload.addEventListener("progress", (p) => {
47
+ f = p.total, l({ total: p.total, loaded: p.loaded });
48
+ }), o.addEventListener("load", () => {
49
49
  l({ loaded: f, total: f });
50
50
  });
51
51
  }
52
- s.addEventListener("load", () => {
53
- const f = s.status;
52
+ o.addEventListener("load", () => {
53
+ const f = o.status, p = o.responseType;
54
54
  u(), d({
55
55
  url: a,
56
56
  method: r,
57
57
  status: f,
58
- statusText: s.statusText,
59
- headers: U(s),
60
- body: r === "HEAD" || f === 204 ? "" : s.responseText
58
+ statusText: o.statusText,
59
+ headers: U(o),
60
+ body: r === "HEAD" || f === 204 ? "" : p === "" || p === "text" || p === "json" || p === "document" ? o.responseText : ""
61
61
  });
62
- }), s.addEventListener(
62
+ }), o.addEventListener(
63
63
  "error",
64
64
  (f) => {
65
65
  u(), d({
66
66
  url: a,
67
67
  method: r,
68
- status: s.status || -1,
69
- statusText: s.statusText || w.NetworkError,
68
+ status: o.status || -1,
69
+ statusText: o.statusText || w.NetworkError,
70
70
  body: "",
71
71
  rawError: f
72
72
  });
73
73
  },
74
74
  !0
75
- ), s.addEventListener("abort", () => {
75
+ ), o.addEventListener("abort", () => {
76
76
  u(), d({
77
77
  url: a,
78
78
  method: r,
@@ -81,53 +81,53 @@ const y = async function(e, o, t) {
81
81
  statusText: g ? w.Timeout : w.Aborted,
82
82
  body: ""
83
83
  });
84
- }), Object.entries(n.headers).forEach(([f, h]) => {
85
- s.setRequestHeader(f, h);
86
- }), n.credentials === "include" && (s.withCredentials = !0), s.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", i), n.timeout > 0 && (b = setTimeout(function() {
84
+ }), Object.entries(n.headers).forEach(([f, p]) => {
85
+ o.setRequestHeader(f, p);
86
+ }), 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
87
  g = !0, i();
88
88
  }, n.timeout));
89
89
  });
90
90
  };
91
- function U(e) {
92
- const o = {};
93
- if (!e)
94
- return o;
95
- const t = e.getAllResponseHeaders();
96
- return t && t !== "null" && t.replace(/\r/g, "").split(`
91
+ function U(t) {
92
+ const s = {};
93
+ if (!t)
94
+ return s;
95
+ const e = t.getAllResponseHeaders();
96
+ return e && e !== "null" && e.replace(/\r/g, "").split(`
97
97
  `).forEach((n) => {
98
98
  const r = n.trim();
99
99
  if (!r)
100
100
  return;
101
101
  const l = r.split(":"), a = l[0].trim();
102
- a && (o[a] = (l[1] || "").trim());
103
- }), o;
102
+ a && (s[a] = (l[1] || "").trim());
103
+ }), s;
104
104
  }
105
- async function O(e, o, t = {}) {
105
+ async function P(t, s, e = {}) {
106
106
  const n = window;
107
- "callback" in t || (t.callback = "jsonxData" + Math.random().toString(16).slice(2));
108
- const r = t.callback + "";
109
- if (!e)
107
+ "callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
108
+ const r = e.callback + "";
109
+ if (!t)
110
110
  return null;
111
- const l = R(e, t, !0);
111
+ const l = R(t, e, !0);
112
112
  return new Promise((a) => {
113
113
  n[r] = function(d) {
114
- if (r in window && delete n[r], o(d))
114
+ if (r in window && delete n[r], s(d))
115
115
  return d;
116
- console.warn("response type check failed", e, d), a(null);
116
+ console.warn("response type check failed", t, d), a(null);
117
117
  }, H(l).catch(function() {
118
118
  a(null), delete n[r];
119
119
  });
120
120
  });
121
121
  }
122
- async function A(e, o, t = {}) {
122
+ async function A(t, s, e = {}) {
123
123
  const n = window;
124
- return "var" in t || (t.var = "jsonxData" + Math.random().toString(16).slice(2)), e ? await H(R(e, t, !0)).then(() => {
125
- const r = n[t.var + ""];
126
- return o(r) ? r : (console.warn("response type check failed", e, r), null);
124
+ return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await H(R(t, e, !0)).then(() => {
125
+ const r = n[e.var + ""];
126
+ return s(r) ? r : (console.warn("response type check failed", t, r), null);
127
127
  }).catch(() => null) : null;
128
128
  }
129
- const M = async function(e, o, t) {
130
- return await S(e, o, t, {
129
+ const M = async function(t, s, e) {
130
+ return await S(t, s, e, {
131
131
  baseURL: c.getConfig("baseURL"),
132
132
  logHandler: c.getConfig("logHandler"),
133
133
  errorHandler: c.getConfig("errorHandler"),
@@ -136,22 +136,22 @@ const M = async function(e, o, t) {
136
136
  responseHandler: c.getConfig("responseHandler")
137
137
  });
138
138
  };
139
- function j(e) {
139
+ function v(t) {
140
140
  if (!C())
141
141
  throw new Error("Default Module Only Support In Browser");
142
- return L() ? new E(k, e) : new E(P, e);
142
+ return L() ? new E(j, t) : new E(k, t);
143
143
  }
144
- const c = j(), N = c.setConfig, B = c.request, X = c.head, F = c.get, G = c.post, I = c.del, Q = c.put, V = c.patch;
144
+ const c = 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;
145
145
  export {
146
- j as NetRequest,
146
+ v as NetRequest,
147
147
  w as RequestInternalError,
148
148
  I as del,
149
149
  F as get,
150
150
  z as getResponseRulesDescription,
151
151
  X as head,
152
- O as jsonp,
152
+ P as jsonp,
153
153
  A as jsonx,
154
- V as patch,
154
+ Z as patch,
155
155
  G as post,
156
156
  Q as put,
157
157
  B as request,
package/dist/node.js CHANGED
@@ -1,10 +1,10 @@
1
- import { h as b, r as q, c as w, e as g, a as d, f as E, N as f, Q as x } from "./retry-CdUkYrFw.js";
2
- import { g as z } from "./retry-CdUkYrFw.js";
3
- import { f as C } from "./request.fetch-B3ED8nRu.js";
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";
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 b(await q(L, o, a, u), o, a, u);
7
+ return y(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(([y, h]) => [y.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
34
+ Object.entries(e.headers).map(([b, h]) => [b.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
35
35
  );
36
36
  r({
37
37
  url: n.toString(),
@@ -67,11 +67,11 @@ const j = async function(o, a, u) {
67
67
  function O(o) {
68
68
  return x() ? new f(C, o) : new f(j, o);
69
69
  }
70
- const s = O(), k = s.setConfig, B = s.head, D = s.get, P = s.post, Q = s.del, F = s.put, G = s.patch;
70
+ const s = O(), k = s.setConfig, B = s.head, D = s.get, P = s.post, Z = s.del, F = s.put, G = s.patch;
71
71
  export {
72
72
  O as NetRequest,
73
73
  d as RequestInternalError,
74
- Q as del,
74
+ Z as del,
75
75
  D as get,
76
76
  z as getResponseRulesDescription,
77
77
  B as head,
@@ -1,4 +1,4 @@
1
- import { h as w, r as y, c as E, o as T, f as R, a as c } from "./retry-CdUkYrFw.js";
1
+ import { h as w, r as y, c as E, u as T, f as R, a as c } from "./retry-BjOxSyvC.js";
2
2
  const x = async function(a, s, n) {
3
3
  return w(await y(g, a, s, n), a, s, n);
4
4
  }, g = async function(a, s, n) {