@seayoo-web/request 3.5.2 → 4.0.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/dist/node.js CHANGED
@@ -1,83 +1,83 @@
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-Cxkf8ke1.js";
2
- import { g as z } from "./retry-Cxkf8ke1.js";
3
- import { f as C } from "./request.fetch-Jj3A4PnG.js";
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-b0Etywu_.js";
2
+ import { g as S } from "./retry-b0Etywu_.js";
3
+ import { f as x } from "./request.fetch-U2PiTmEn.js";
4
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
- const t = await w(o, a, u);
10
- if (!g(t.url))
11
- return {
12
- url: t.url,
13
- method: t.method,
14
- status: -1,
15
- statusText: d.URLFormatError,
16
- headers: {},
17
- body: ""
18
- };
19
- const R = /^https:\/\//i.test(t.url) ? T : N, n = new URL(t.url), i = t.params;
20
- i instanceof Object && Object.keys(i).forEach((r) => n.searchParams.set(r, i[r]));
21
- const l = t.method === "HEAD";
22
- return new Promise((r) => {
23
- const c = R.request(
24
- n,
5
+ import C from "node:https";
6
+ const E = async function(o, n, a) {
7
+ return w(await R(T, o, n, a), o, n, a);
8
+ }, T = async function(o, n, a) {
9
+ const t = await y(o, n, a), p = /^https:\/\//i.test(t.url) ? C : N;
10
+ return new Promise((d) => {
11
+ const u = p.request(
12
+ t.url,
25
13
  {
26
14
  headers: t.headers,
27
15
  method: t.method,
28
16
  timeout: t.timeout > 0 ? t.timeout : void 0
29
17
  },
30
18
  function(e) {
31
- const p = [];
32
- e.on("data", (m) => p.push(m)), e.on("end", () => {
33
- const m = E(
34
- Object.entries(e.headers).map(([y, h]) => [y.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
19
+ const f = [];
20
+ e.on("data", (c) => f.push(c)), e.on("end", async () => {
21
+ const c = b(
22
+ Object.entries(e.headers).map(([l, i]) => [l.toLowerCase(), Array.isArray(i) ? i.join(",") : i])
23
+ ), m = Buffer.concat(f);
24
+ d(
25
+ await q(
26
+ {
27
+ url: t.url,
28
+ method: t.method,
29
+ status: e.statusCode || -1,
30
+ error: e.statusCode ? void 0 : s.Unknown,
31
+ statusText: e.statusMessage || s.Unknown,
32
+ headers: c,
33
+ body: null
34
+ },
35
+ {
36
+ asBuffer: t.asBuffer,
37
+ text: () => m.toString("utf-8"),
38
+ buffer: () => m.buffer
39
+ }
40
+ )
35
41
  );
36
- r({
37
- url: n.toString(),
38
- method: t.method,
39
- status: e.statusCode || -1,
40
- statusText: e.statusMessage || d.Unknown,
41
- headers: m,
42
- body: l || e.statusCode === 204 ? "" : Buffer.concat(p).toString("utf-8")
43
- });
44
42
  });
45
43
  }
46
44
  );
47
- c.on("error", (e) => {
48
- r({
49
- url: n.toString(),
45
+ u.on("error", (e) => {
46
+ d({
47
+ url: t.url,
50
48
  method: t.method,
51
49
  status: -1,
52
- statusText: d.NetworkError,
53
- body: "",
50
+ error: s.NetworkError,
51
+ statusText: s.NetworkError,
52
+ body: null,
54
53
  rawError: e
55
54
  });
56
- }), c.on("timeout", () => {
57
- r({
58
- url: n.toString(),
55
+ }), u.on("timeout", () => {
56
+ d({
57
+ url: t.url,
59
58
  method: t.method,
60
59
  status: -1,
61
- statusText: d.Timeout,
62
- body: ""
60
+ error: s.Timeout,
61
+ statusText: s.Timeout,
62
+ body: null
63
63
  });
64
- }), t.body && c.write(t.body), c.end();
64
+ }), t.body && u.write(t.body), u.end();
65
65
  });
66
66
  };
67
67
  // @__NO_SIDE_EFFECTS__
68
- function O(o) {
69
- return x() ? new f(C, o) : new f(j, o);
68
+ function k(o) {
69
+ return g() ? new h(x, o) : new h(E, o);
70
70
  }
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;
71
+ const r = /* @__PURE__ */ k(), U = r.setConfig, X = r.head, D = r.get, G = r.post, H = r.del, I = r.put, L = r.patch;
72
72
  export {
73
- O as NetRequest,
74
- d as RequestInternalError,
75
- X as del,
73
+ k as NetRequest,
74
+ s as RequestInternalError,
75
+ H as del,
76
76
  D as get,
77
- z as getResponseRulesDescription,
78
- B as head,
79
- G as patch,
80
- P as post,
81
- F as put,
82
- k as setGlobalConfig
77
+ S as getResponseRulesDescription,
78
+ X as head,
79
+ L as patch,
80
+ G as post,
81
+ I as put,
82
+ U as setGlobalConfig
83
83
  };
@@ -0,0 +1,54 @@
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-b0Etywu_.js";
2
+ const x = async function(o, a, s) {
3
+ return f(await h(w, o, a, s), o, a, s);
4
+ }, w = async function(o, a, s) {
5
+ const t = await m(o, a, s), r = b() ? new AbortController() : null;
6
+ function n(e) {
7
+ r && !r.signal.aborted && r.abort(e);
8
+ }
9
+ t.abort?.addEventListener("abort", n);
10
+ let i = !1;
11
+ const l = t.timeout > 0 ? setTimeout(function() {
12
+ i = !0, n("TimeoutTriggered");
13
+ }, t.timeout) : null;
14
+ return await fetch(t.url, {
15
+ method: t.method,
16
+ headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
17
+ body: t.body,
18
+ credentials: t.credentials,
19
+ signal: r?.signal,
20
+ redirect: "follow"
21
+ }).then(
22
+ async (e) => y(
23
+ {
24
+ url: t.url,
25
+ method: t.method,
26
+ status: e.status,
27
+ statusText: e.statusText,
28
+ headers: T([...e.headers.entries()]),
29
+ body: null
30
+ },
31
+ {
32
+ asBuffer: t.asBuffer,
33
+ text: () => e.text(),
34
+ buffer: () => e.arrayBuffer()
35
+ }
36
+ )
37
+ ).catch((e) => {
38
+ const c = r?.signal.aborted, d = i ? u.Timeout : c ? u.Aborted : u.NetworkError;
39
+ return {
40
+ url: t.url,
41
+ method: t.method,
42
+ status: -1,
43
+ error: d,
44
+ statusText: d,
45
+ body: null,
46
+ rawError: e
47
+ };
48
+ }).finally(() => {
49
+ l !== null && clearTimeout(l), t.abort && t.abort.removeEventListener("abort", n);
50
+ });
51
+ };
52
+ export {
53
+ x as f
54
+ };