@seayoo-web/request 3.3.3 → 3.4.0

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 CHANGED
@@ -1,18 +1,18 @@
1
- import { h as m, r as x, R as T, c as C, p as R, a as w, b as q, S as E, N as H } from "./retry-BXoyQlSJ.js";
2
- import { g as K } from "./retry-BXoyQlSJ.js";
3
- import { f as L } from "./request.fetch-CHbeHmeX.js";
4
- const S = async function(t, o, e) {
5
- return m(await x(y, t, o, e), t, o, e);
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);
6
6
  };
7
- async function k(t, o, e, n) {
8
- const r = e?.body, l = e?.method === "PUT" ? "PUT" : "POST";
7
+ async function S(e, o, t, n) {
8
+ const r = t?.body, l = t?.method === "PUT" ? "PUT" : "POST";
9
9
  if (o instanceof Blob) {
10
- const i = new T(n), u = await y(t, i, {
11
- ...e,
10
+ const i = new T(n), u = await y(e, i, {
11
+ ...t,
12
12
  method: l,
13
13
  body: o
14
14
  });
15
- return m(u, t, i, e);
15
+ return m(u, e, i, t);
16
16
  }
17
17
  const a = new FormData(), d = { ...o };
18
18
  r instanceof Object && Object.entries(r).forEach(([i, u]) => {
@@ -22,19 +22,19 @@ async function k(t, o, e, n) {
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, {
26
- ...e,
25
+ const b = new T(n), p = await y(e, b, {
26
+ ...t,
27
27
  method: l,
28
28
  body: a
29
29
  });
30
- return m(h, t, b, e);
30
+ return m(p, e, b, t);
31
31
  }
32
- const y = async function(t, o, e) {
33
- const n = await C(t, o, e), r = n.method, l = e?.onUploadProgress, a = R(n.url, n.params);
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);
34
34
  return await new Promise((d) => {
35
- let b = null, h = !1;
35
+ let b = null, p = !1;
36
36
  const i = function() {
37
- h || (s.abort(), h = !0);
37
+ p || (s.abort(), p = !0);
38
38
  };
39
39
  function u() {
40
40
  b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", i);
@@ -43,8 +43,8 @@ const y = async function(t, o, e) {
43
43
  let g = !1;
44
44
  if (s.open(r, a, !0), l) {
45
45
  let f = 1;
46
- s.upload.addEventListener("progress", (p) => {
47
- f = p.total, l({ total: p.total, loaded: p.loaded });
46
+ s.upload.addEventListener("progress", (h) => {
47
+ f = h.total, l({ total: h.total, loaded: h.loaded });
48
48
  }), s.addEventListener("load", () => {
49
49
  l({ loaded: f, total: f });
50
50
  });
@@ -81,19 +81,19 @@ const y = async function(t, o, e) {
81
81
  statusText: g ? w.Timeout : w.Aborted,
82
82
  body: ""
83
83
  });
84
- }), Object.entries(n.headers).forEach(([f, p]) => {
85
- s.setRequestHeader(f, p);
84
+ }), Object.entries(n.headers).forEach(([f, h]) => {
85
+ s.setRequestHeader(f, h);
86
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() {
87
87
  g = !0, i();
88
88
  }, n.timeout));
89
89
  });
90
90
  };
91
- function U(t) {
91
+ function U(e) {
92
92
  const o = {};
93
- if (!t)
93
+ if (!e)
94
94
  return o;
95
- const e = t.getAllResponseHeaders();
96
- return e && e !== "null" && e.replace(/\r/g, "").split(`
95
+ const t = e.getAllResponseHeaders();
96
+ return t && t !== "null" && t.replace(/\r/g, "").split(`
97
97
  `).forEach((n) => {
98
98
  const r = n.trim();
99
99
  if (!r)
@@ -102,32 +102,32 @@ function U(t) {
102
102
  a && (o[a] = (l[1] || "").trim());
103
103
  }), o;
104
104
  }
105
- async function O(t, o, e = {}) {
105
+ async function O(e, o, t = {}) {
106
106
  const n = window;
107
- "callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
108
- const r = e.callback + "";
109
- if (!t)
107
+ "callback" in t || (t.callback = "jsonxData" + Math.random().toString(16).slice(2));
108
+ const r = t.callback + "";
109
+ if (!e)
110
110
  return null;
111
- const l = R(t, e, !0);
111
+ const l = R(e, t, !0);
112
112
  return new Promise((a) => {
113
113
  n[r] = function(d) {
114
114
  if (r in window && delete n[r], o(d))
115
115
  return d;
116
- console.warn("response type check failed", t, d), a(null);
117
- }, q(l).catch(function() {
116
+ console.warn("response type check failed", e, d), a(null);
117
+ }, H(l).catch(function() {
118
118
  a(null), delete n[r];
119
119
  });
120
120
  });
121
121
  }
122
- async function P(t, o, e = {}) {
122
+ async function A(e, o, t = {}) {
123
123
  const n = window;
124
- return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await q(R(t, e, !0)).then(() => {
125
- const r = n[e.var + ""];
126
- return o(r) ? r : (console.warn("response type check failed", t, r), null);
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);
127
127
  }).catch(() => null) : null;
128
128
  }
129
- const A = async function(t, o, e) {
130
- return await k(t, o, e, {
129
+ const M = async function(e, o, t) {
130
+ return await S(e, o, t, {
131
131
  baseURL: c.getConfig("baseURL"),
132
132
  logHandler: c.getConfig("logHandler"),
133
133
  errorHandler: c.getConfig("errorHandler"),
@@ -136,25 +136,25 @@ const A = async function(t, o, e) {
136
136
  responseHandler: c.getConfig("responseHandler")
137
137
  });
138
138
  };
139
- function j(t) {
140
- if (!E.window)
139
+ function j(e) {
140
+ if (!C())
141
141
  throw new Error("Default Module Only Support In Browser");
142
- return E.fetch ? new H(L, t) : new H(S, t);
142
+ return L() ? new E(k, e) : new E(P, e);
143
143
  }
144
- const c = j(), M = c.setConfig, N = c.request, B = c.head, X = c.get, F = c.post, G = c.del, I = c.put, $ = c.patch;
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;
145
145
  export {
146
146
  j as NetRequest,
147
147
  w as RequestInternalError,
148
- G as del,
149
- X as get,
150
- K as getResponseRulesDescription,
151
- B as head,
148
+ I as del,
149
+ F as get,
150
+ z as getResponseRulesDescription,
151
+ X as head,
152
152
  O as jsonp,
153
- P as jsonx,
154
- $ as patch,
155
- F as post,
156
- I as put,
157
- N as request,
158
- M as setGlobalConfig,
159
- A as upload
153
+ A as jsonx,
154
+ V as patch,
155
+ G as post,
156
+ Q as put,
157
+ B as request,
158
+ N as setGlobalConfig,
159
+ M as upload
160
160
  };
package/dist/node.js CHANGED
@@ -1,11 +1,11 @@
1
- import { h as b, r as q, c as w, A as g, a as d, f as E, N as f, S as x } from "./retry-BXoyQlSJ.js";
2
- import { g as J } from "./retry-BXoyQlSJ.js";
3
- import { f as S } from "./request.fetch-CHbeHmeX.js";
4
- import A from "node:http";
5
- import C from "node:https";
6
- const N = async function(o, a, u) {
7
- return b(await q(T, o, a, u), o, a, u);
8
- }, T = async function(o, a, u) {
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";
4
+ import N from "node:http";
5
+ import T from "node:https";
6
+ const j = async function(o, a, u) {
7
+ return b(await q(L, o, a, u), o, a, u);
8
+ }, L = async function(o, a, u) {
9
9
  const t = await w(o, a, u);
10
10
  if (!g(t.url))
11
11
  return {
@@ -16,7 +16,7 @@ const N = async function(o, a, u) {
16
16
  headers: {},
17
17
  body: ""
18
18
  };
19
- const R = /^https:\/\//i.test(t.url) ? C : A, n = new URL(t.url), i = t.params;
19
+ const R = /^https:\/\//i.test(t.url) ? T : N, n = new URL(t.url), i = t.params;
20
20
  i instanceof Object && Object.keys(i).forEach((r) => n.searchParams.set(r, i[r]));
21
21
  const l = t.method === "HEAD";
22
22
  return new Promise((r) => {
@@ -64,19 +64,19 @@ const N = async function(o, a, u) {
64
64
  }), t.body && c.write(t.body), c.end();
65
65
  });
66
66
  };
67
- function j(o) {
68
- return x.fetch ? new f(S, o) : new f(N, o);
67
+ function O(o) {
68
+ return x() ? new f(C, o) : new f(j, o);
69
69
  }
70
- const s = j(), k = s.setConfig, B = s.head, D = s.get, P = s.post, F = s.del, G = s.put, I = s.patch;
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;
71
71
  export {
72
- j as NetRequest,
72
+ O as NetRequest,
73
73
  d as RequestInternalError,
74
- F as del,
74
+ Q as del,
75
75
  D as get,
76
- J as getResponseRulesDescription,
76
+ z as getResponseRulesDescription,
77
77
  B as head,
78
- I as patch,
78
+ G as patch,
79
79
  P as post,
80
- G as put,
80
+ F as put,
81
81
  k as setGlobalConfig
82
82
  };
@@ -1,16 +1,16 @@
1
- import { h as w, r as y, c as E, S as T, f as R, a as c } from "./retry-BXoyQlSJ.js";
1
+ import { h as w, r as y, c as E, o as T, f as R, a as c } from "./retry-CdUkYrFw.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) {
5
5
  const t = await E(a, s, n), i = new URL(t.url), u = t.params;
6
6
  u instanceof Object && Object.keys(u).forEach((e) => i.searchParams.set(e, u[e]));
7
- const r = T.AbortController ? new AbortController() : null;
7
+ const r = T() ? new AbortController() : null;
8
8
  function d() {
9
9
  r && !r.signal.aborted && r.abort();
10
10
  }
11
11
  t.abort && t.abort.addEventListener("abort", d);
12
12
  let l = !1;
13
- const h = t.timeout > 0 ? setTimeout(function() {
13
+ const b = t.timeout > 0 ? setTimeout(function() {
14
14
  l = !0, d();
15
15
  }, t.timeout) : null, f = t.method === "HEAD";
16
16
  return await fetch(i, {
@@ -27,8 +27,8 @@ const x = async function(a, s, n) {
27
27
  status: e.status,
28
28
  statusText: e.statusText,
29
29
  headers: R([...e.headers.entries()])
30
- }, b = f || e.status === 204 ? "" : await e.text().catch((m) => m);
31
- return b instanceof Error ? { ...o, body: "", statusText: c.Unknown, rawError: b } : { ...o, body: b };
30
+ }, h = f || e.status === 204 ? "" : await e.text().catch((m) => m);
31
+ return h instanceof Error ? { ...o, body: "", statusText: c.Unknown, rawError: h } : { ...o, body: h };
32
32
  }).catch((e) => {
33
33
  const o = r?.signal.aborted;
34
34
  return {
@@ -41,7 +41,7 @@ const x = async function(a, s, n) {
41
41
  rawError: e
42
42
  };
43
43
  }).finally(() => {
44
- h !== null && clearTimeout(h), t.abort && t.abort.removeEventListener("abort", d);
44
+ b !== null && clearTimeout(b), t.abort && t.abort.removeEventListener("abort", d);
45
45
  });
46
46
  };
47
47
  export {