@seayoo-web/request 4.0.1 → 4.0.2

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,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-b0Etywu_.js";
2
- import { g as W } from "./retry-b0Etywu_.js";
3
- import { f as S } from "./request.fetch-U2PiTmEn.js";
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--akoKQtX.js";
2
+ import { g as W } from "./retry--akoKQtX.js";
3
+ import { f as S } from "./request.fetch-U42cahT4.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-b0Etywu_.js";
2
- import { g as S } from "./retry-b0Etywu_.js";
3
- import { f as x } from "./request.fetch-U2PiTmEn.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--akoKQtX.js";
2
+ import { g as S } from "./retry--akoKQtX.js";
3
+ import { f as x } from "./request.fetch-U42cahT4.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-b0Etywu_.js";
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--akoKQtX.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) {
@@ -5,25 +5,25 @@ function C() {
5
5
  function m(e) {
6
6
  return typeof e == "function";
7
7
  }
8
- function O(e) {
8
+ function U(e) {
9
9
  return typeof e == "object" && e !== null;
10
10
  }
11
11
  function P() {
12
- return "wx" in f && O(f.wx) && "getSystemInfo" in f.wx && m(f.wx.getSystemInfo);
12
+ return "wx" in f && U(f.wx) && "getSystemInfo" in f.wx && m(f.wx.getSystemInfo);
13
13
  }
14
14
  function we() {
15
15
  return "fetch" in f && m(f.fetch);
16
16
  }
17
17
  function be() {
18
- return "window" in f && O(f.window) && !P();
18
+ return "window" in f && U(f.window) && !P();
19
19
  }
20
20
  function R() {
21
21
  return "Blob" in f && m(f.Blob);
22
22
  }
23
- function U() {
23
+ function M() {
24
24
  return "FormData" in f && m(f.FormData);
25
25
  }
26
- function M() {
26
+ function O() {
27
27
  return "TextDecoder" in f && m(f.TextDecoder);
28
28
  }
29
29
  function Ee() {
@@ -91,9 +91,9 @@ function J(e, t = "数据未能正确识别") {
91
91
  };
92
92
  }
93
93
  function V(e, t = "") {
94
- return !t || $(e, !0) ? j(e) : (j(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
94
+ return !t || $(e, !0) ? x(e) : (x(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
95
95
  }
96
- function j(e) {
96
+ function x(e) {
97
97
  const t = C();
98
98
  return $(e, !0) ? e.startsWith("http") ? e : ("location" in t ? location.protocol : "https:") + e : ("location" in t ? location.origin : "http://127.0.0.1") + "/" + e.replace(/^\/+/, "");
99
99
  }
@@ -308,7 +308,7 @@ class ke {
308
308
  return s ? this.request({ ...o, guard: s }) : this.request(o);
309
309
  }
310
310
  async post(t, n, s, r) {
311
- const o = this.gen(t, "POST", null, n, r);
311
+ const o = this.gen(t, "POST", null, n || {}, r);
312
312
  return s ? this.request({ ...o, guard: s }) : this.request(o);
313
313
  }
314
314
  async del(t, n, s, r) {
@@ -316,11 +316,11 @@ class ke {
316
316
  return s ? this.request({ ...o, guard: s }) : this.request(o);
317
317
  }
318
318
  async put(t, n, s, r) {
319
- const o = this.gen(t, "PUT", null, n, r);
319
+ const o = this.gen(t, "PUT", null, n || {}, r);
320
320
  return s ? this.request({ ...o, guard: s }) : this.request(o);
321
321
  }
322
322
  async patch(t, n, s, r) {
323
- const o = this.gen(t, "PATCH", null, n, r);
323
+ const o = this.gen(t, "PATCH", null, n || {}, r);
324
324
  return s ? this.request({ ...o, guard: s }) : this.request(o);
325
325
  }
326
326
  }
@@ -338,13 +338,13 @@ function se(e) {
338
338
  }), t;
339
339
  }
340
340
  function L(e) {
341
- return F(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && M() ? new TextDecoder().decode(e) : JSON.stringify(e);
341
+ return F(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && O() ? new TextDecoder().decode(e) : JSON.stringify(e);
342
342
  }
343
343
  function ne(e) {
344
344
  return e instanceof Error ? e : new Error(L(e));
345
345
  }
346
346
  async function Re(e) {
347
- if (M())
347
+ if (O())
348
348
  return new TextEncoder().encode(e).buffer;
349
349
  if (R())
350
350
  return await new Blob([e]).arrayBuffer();
@@ -369,14 +369,12 @@ function ce({ status: e, headers: t, error: n }) {
369
369
  return n === y.NetworkError ? !0 : t?.server === "TencentEdgeOne" ? e === 522 || e === 552 : !1;
370
370
  }
371
371
  async function $e(e, t, n) {
372
- const s = Object.assign({ method: "GET" }, n), r = U() ? s.body instanceof FormData : !1, o = r && s.method !== "POST" && s.method !== "PUT" ? "POST" : s.method, a = o === "GET" || o === "HEAD" || o === "DELETE";
372
+ const s = { ...n, method: n?.method || "GET" }, r = M() ? s.body instanceof FormData : !1, o = r && 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
- const i = Object.assign(
375
- r || a ? {} : {
376
- "Content-Type": R() && s.body instanceof Blob ? s.body.type || "application/octet-stream" : "application/json;charset=utf-8"
377
- },
378
- s.headers
379
- ), c = t.getFullUrl(e), l = se(s.params), u = ie(s.body), h = s.timeout || t.get("timeout"), p = await (async function() {
374
+ const i = r || a ? { ...s.headers } : {
375
+ "Content-Type": R() && s.body instanceof Blob ? s.body.type || "application/octet-stream" : "application/json;charset=utf-8",
376
+ ...s.headers
377
+ }, c = t.getFullUrl(e), l = se(s.params), u = ie(s.body), h = s.timeout || t.get("timeout"), p = await (async function() {
380
378
  const g = t.get("requestTransformer");
381
379
  if (g)
382
380
  return await g({ headers: i, params: l, method: o, url: c, body: u });
@@ -394,7 +392,7 @@ async function $e(e, t, n) {
394
392
  }
395
393
  function ie(e) {
396
394
  if (e)
397
- return typeof e == "string" || q() && e instanceof URLSearchParams || e instanceof ArrayBuffer || R() && e instanceof Blob || U() && e instanceof FormData ? e : JSON.stringify(e);
395
+ return typeof e == "string" || q() && e instanceof URLSearchParams || e instanceof ArrayBuffer || R() && e instanceof Blob || M() && e instanceof FormData ? e : JSON.stringify(e);
398
396
  }
399
397
  const B = "data", w = "message";
400
398
  function ue(e, t, n) {
@@ -434,11 +432,11 @@ function he(e, { statusText: t, body: n, error: s }) {
434
432
  };
435
433
  switch (e.resolve) {
436
434
  case "body":
437
- o.message = x(r) || r;
435
+ o.message = j(r) || r;
438
436
  break;
439
437
  case "json":
440
438
  const { code: a, message: i } = le(r, e.converter, e.statusField, e.messageField);
441
- o.code = a || s || t, o.message = x(r) || i;
439
+ o.code = a || s || t, o.message = j(r) || i;
442
440
  break;
443
441
  }
444
442
  return o;
@@ -449,7 +447,7 @@ function D(e) {
449
447
  function T(e, t) {
450
448
  return t && typeof t == "function" ? t(e) : e;
451
449
  }
452
- const je = function(e) {
450
+ const xe = function(e) {
453
451
  const t = [], n = e.failed || { resolve: "json" };
454
452
  switch (t.push("- 当http状态码 <200 或者 >=400 时"), n.resolve) {
455
453
  case "body":
@@ -492,7 +490,7 @@ function k(e, t) {
492
490
  return "";
493
491
  }
494
492
  const de = [/<title>([^<]+)<\/title>/i, /<message>([^<]+)<\/message>/i];
495
- function x(e) {
493
+ function j(e) {
496
494
  for (const t of de) {
497
495
  const n = e.match(t);
498
496
  if (n)
@@ -523,7 +521,7 @@ function pe(e) {
523
521
  }
524
522
  };
525
523
  }
526
- async function xe(e, t) {
524
+ async function je(e, t) {
527
525
  if (e.method === "HEAD" || e.status === 204)
528
526
  return e.body = null, e;
529
527
  try {
@@ -635,8 +633,8 @@ export {
635
633
  $e as c,
636
634
  be as d,
637
635
  te as e,
638
- xe as f,
639
- je as g,
636
+ je as f,
637
+ xe as g,
640
638
  ve as h,
641
639
  Ee as i,
642
640
  ye as r,
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-b0Etywu_.js";
2
- import { g as O } from "./retry-b0Etywu_.js";
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--akoKQtX.js";
2
+ import { g as O } from "./retry--akoKQtX.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/request",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "request tools for seayoo web",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",