@seayoo-web/request 4.0.0 → 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,10 +1,10 @@
1
- import { h, r as x, G as y, c as E, f as q, a as v, R as w, H as R, v as H, b as C, N as T, X as L } from "./retry-DRbCcUt8.js";
2
- import { g as V } from "./retry-DRbCcUt8.js";
3
- import { f as k } from "./request.fetch-BNCxK4Wq.js";
4
- const S = async function(n, a, t) {
5
- return h(await x(m, n, a, t), n, a, t);
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
+ const j = async function(n, a, t) {
5
+ return h(await E(m, n, a, t), n, a, t);
6
6
  };
7
- async function j(n, a, t, r) {
7
+ async function B(n, a, t, r) {
8
8
  const o = t?.body, u = t?.method === "PUT" ? "PUT" : "POST";
9
9
  if (a instanceof Blob) {
10
10
  const l = new y(r), e = await m(n, l, {
@@ -30,7 +30,7 @@ async function j(n, a, t, r) {
30
30
  return h(p, n, f, t);
31
31
  }
32
32
  const m = async function(n, a, t) {
33
- const r = await E(n, a, t), o = r.method, u = t?.onUploadProgress;
33
+ const r = await q(n, a, t), o = r.method, u = t?.onUploadProgress;
34
34
  return await new Promise((c) => {
35
35
  let d = null, f = !1;
36
36
  const p = function() {
@@ -53,19 +53,19 @@ const m = async function(n, a, t) {
53
53
  l();
54
54
  const s = e.responseType;
55
55
  c(
56
- await q(
56
+ await v(
57
57
  {
58
58
  url: r.url,
59
59
  method: o,
60
60
  status: e.status,
61
61
  statusText: e.statusText,
62
- headers: B(e),
62
+ headers: P(e),
63
63
  body: null
64
64
  },
65
65
  {
66
66
  asBuffer: r.asBuffer,
67
67
  text: () => s === "" || s === "text" || s === "json" || s === "document" ? e.responseText : "",
68
- buffer: async () => s === "arraybuffer" ? e.response : s === "blob" ? await e.response.arrayBuffer() : await v(e.responseText)
68
+ buffer: async () => s === "arraybuffer" ? e.response : s === "blob" ? await e.response.arrayBuffer() : await C(e.responseText)
69
69
  }
70
70
  )
71
71
  );
@@ -101,7 +101,7 @@ const m = async function(n, a, t) {
101
101
  }, r.timeout));
102
102
  });
103
103
  };
104
- function B(n) {
104
+ function P(n) {
105
105
  const a = {};
106
106
  if (!n)
107
107
  return a;
@@ -121,26 +121,26 @@ async function O(n, a, t = {}) {
121
121
  const o = t.callback + "";
122
122
  if (!n)
123
123
  return null;
124
- const u = R(n, t, !0);
124
+ const u = R(n, H(t), !0);
125
125
  return new Promise((c) => {
126
126
  r[o] = function(d) {
127
127
  if (o in window && delete r[o], a(d))
128
128
  return d;
129
129
  console.warn("response type check failed", n, d), c(null);
130
- }, H(u).catch(function() {
130
+ }, x(u).catch(function() {
131
131
  c(null), delete r[o];
132
132
  });
133
133
  });
134
134
  }
135
- async function P(n, a, t = {}) {
135
+ async function A(n, a, t = {}) {
136
136
  const r = window;
137
- return "var" in t || (t.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await H(R(n, t, !0)).then(() => {
137
+ return "var" in t || (t.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await x(R(n, H(t), !0)).then(() => {
138
138
  const o = r[t.var + ""];
139
139
  return a(o) ? o : (console.warn("response type check failed", n, o), null);
140
140
  }).catch(() => null) : null;
141
141
  }
142
- const A = async function(n, a, t) {
143
- return await j(n, a, t, {
142
+ const M = async function(n, a, t) {
143
+ return await B(n, a, t, {
144
144
  baseURL: i.getConfig("baseURL"),
145
145
  logHandler: i.getConfig("logHandler"),
146
146
  errorHandler: i.getConfig("errorHandler"),
@@ -151,24 +151,24 @@ const A = async function(n, a, t) {
151
151
  };
152
152
  // @__NO_SIDE_EFFECTS__
153
153
  function U(n) {
154
- if (!C())
154
+ if (!L())
155
155
  throw new Error("Default Module Only Support In Browser");
156
- return L() ? new T(k, n) : new T(S, n);
156
+ return k() ? new T(S, n) : new T(j, n);
157
157
  }
158
- const i = /* @__PURE__ */ U(), M = i.setConfig, X = i.request, G = i.head, F = i.get, I = i.post, $ = i.del, z = i.put, J = i.patch;
158
+ const i = /* @__PURE__ */ U(), X = i.setConfig, G = i.request, F = i.head, I = i.get, $ = i.post, z = i.del, J = i.put, K = i.patch;
159
159
  export {
160
160
  U as NetRequest,
161
161
  w as RequestInternalError,
162
- $ as del,
163
- F as get,
164
- V as getResponseRulesDescription,
165
- G as head,
162
+ z as del,
163
+ I as get,
164
+ W as getResponseRulesDescription,
165
+ F as head,
166
166
  O as jsonp,
167
- P as jsonx,
168
- J as patch,
169
- I as post,
170
- z as put,
171
- X as request,
172
- M as setGlobalConfig,
173
- A as upload
167
+ A as jsonx,
168
+ K as patch,
169
+ $ as post,
170
+ J as put,
171
+ G as request,
172
+ X as setGlobalConfig,
173
+ M as upload
174
174
  };
package/dist/node.js CHANGED
@@ -1,6 +1,6 @@
1
- import { h as w, r as R, c as y, d as b, f as q, R as s, N as h, X as g } from "./retry-DRbCcUt8.js";
2
- import { g as S } from "./retry-DRbCcUt8.js";
3
- import { f as x } from "./request.fetch-BNCxK4Wq.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, e as b, f as y, d as T, R as u } from "./retry-DRbCcUt8.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) {
@@ -1,46 +1,46 @@
1
1
  const f = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")();
2
- function U() {
2
+ function C() {
3
3
  return f;
4
4
  }
5
5
  function m(e) {
6
6
  return typeof e == "function";
7
7
  }
8
- function M(e) {
8
+ function U(e) {
9
9
  return typeof e == "object" && e !== null;
10
10
  }
11
- function q() {
12
- return "wx" in f && M(f.wx) && "getSystemInfo" in f.wx && m(f.wx.getSystemInfo);
11
+ function P() {
12
+ return "wx" in f && U(f.wx) && "getSystemInfo" in f.wx && m(f.wx.getSystemInfo);
13
13
  }
14
- function be() {
14
+ function we() {
15
15
  return "fetch" in f && m(f.fetch);
16
16
  }
17
- function Ee() {
18
- return "window" in f && M(f.window) && !q();
17
+ function be() {
18
+ return "window" in f && U(f.window) && !P();
19
19
  }
20
- function j() {
20
+ function R() {
21
21
  return "Blob" in f && m(f.Blob);
22
22
  }
23
- function F() {
23
+ function M() {
24
24
  return "FormData" in f && m(f.FormData);
25
25
  }
26
- function S() {
26
+ function O() {
27
27
  return "TextDecoder" in f && m(f.TextDecoder);
28
28
  }
29
- function Te() {
29
+ function Ee() {
30
30
  return "AbortController" in f && m(f.AbortController);
31
31
  }
32
- function H() {
32
+ function q() {
33
33
  return "URLSearchParams" in f && m(f.URLSearchParams);
34
34
  }
35
- function N(e) {
35
+ function H(e) {
36
36
  return new Promise((t) => setTimeout(t, Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, e))));
37
37
  }
38
38
  // @__NO_SIDE_EFFECTS__
39
- function I(e) {
39
+ function N(e) {
40
40
  const t = e || "CustomError";
41
41
  return class extends Error {
42
- constructor(r) {
43
- super(r), Object.defineProperty(this, "name", {
42
+ constructor(n) {
43
+ super(n), Object.defineProperty(this, "name", {
44
44
  value: t,
45
45
  enumerable: !1,
46
46
  configurable: !0
@@ -48,40 +48,40 @@ function I(e) {
48
48
  }
49
49
  };
50
50
  }
51
- const G = /^(?:https?:)?\/\/.+$/i, K = /^https?:\/\/.+$/i, _ = /^\{[\d\D]*\}$/, J = /^\[[\d\D]*\]$/;
51
+ const I = /^(?:https?:)?\/\/.+$/i, G = /^https?:\/\/.+$/i, K = /^\{[\d\D]*\}$/, _ = /^\[[\d\D]*\]$/;
52
52
  function $(e, t = !1) {
53
- return t ? G.test(e) : K.test(e);
53
+ return t ? I.test(e) : G.test(e);
54
54
  }
55
- function x(e) {
55
+ function F(e) {
56
56
  return e == null;
57
57
  }
58
- function v(e, ...t) {
58
+ function A(e, ...t) {
59
59
  if (!e || typeof e != "object") return !1;
60
- const r = Object.getPrototypeOf(e);
61
- return r !== Object.prototype && r !== null ? !1 : t.every((s) => s in e);
60
+ const n = Object.getPrototypeOf(e);
61
+ return n !== Object.prototype && n !== null ? !1 : t.every((s) => s in e);
62
62
  }
63
- function L(e) {
64
- return _.test(e) || J.test(e);
63
+ function S(e) {
64
+ return K.test(e) || _.test(e);
65
65
  }
66
- function T(e, t) {
66
+ function E(e, t) {
67
67
  try {
68
- const r = JSON.parse(e);
69
- return t ? t(r) ? r : null : r;
68
+ const n = JSON.parse(e);
69
+ return t ? t(n) ? n : null : n;
70
70
  } catch {
71
71
  return null;
72
72
  }
73
73
  }
74
- async function ke(e) {
74
+ async function Te(e) {
75
75
  return await new Promise(function(t) {
76
- const r = document.getElementsByTagName("head")[0], s = document.createElement("script");
76
+ const n = document.getElementsByTagName("head")[0], s = document.createElement("script");
77
77
  s.setAttribute("type", "text/javascript"), s.setAttribute("charset", "utf-8"), s.onload = function() {
78
- r.removeChild(s), t(!0);
78
+ n.removeChild(s), t(!0);
79
79
  }, s.onerror = function() {
80
- r.removeChild(s), t(!1);
81
- }, s.setAttribute("src", e), r.appendChild(s);
80
+ n.removeChild(s), t(!1);
81
+ }, s.setAttribute("src", e), n.appendChild(s);
82
82
  });
83
83
  }
84
- function V(e, t = "数据未能正确识别") {
84
+ function J(e, t = "数据未能正确识别") {
85
85
  return typeof e == "function" ? {
86
86
  guard: e,
87
87
  message: t
@@ -90,52 +90,52 @@ function V(e, t = "数据未能正确识别") {
90
90
  message: e.message || t
91
91
  };
92
92
  }
93
- function W(e, t = "") {
94
- return !t || $(e, !0) ? C(e) : (C(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
93
+ function V(e, t = "") {
94
+ return !t || $(e, !0) ? x(e) : (x(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
95
95
  }
96
- function C(e) {
97
- const t = U();
96
+ function x(e) {
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
  }
100
- function X(e, t) {
101
- const r = {};
100
+ function W(e, t) {
101
+ const n = {};
102
102
  return (e.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(s) {
103
- const n = s.split("="), o = n[0], a = decodeURIComponent(n[1] || "");
104
- r[o] !== void 0 ? r[o] += "," + a : r[o] = a;
105
- }), t !== !0 ? r[t] || "" : r;
103
+ const r = s.split("="), o = r[0], a = decodeURIComponent(r[1] || "");
104
+ n[o] !== void 0 ? n[o] += "," + a : n[o] = a;
105
+ }), t !== !0 ? n[t] || "" : n;
106
106
  }
107
- function z(e, t) {
107
+ function X(e, t) {
108
108
  if (t) {
109
109
  if (t === !0)
110
110
  return e.replace(/\?[^#]*/, "");
111
111
  } else return e;
112
- const r = e.split("#"), s = r[0].split("?"), n = s[0], o = s.length > 1 ? s[1] : "", a = r.length > 1 ? "#" + r[1] : "", i = typeof t == "string" ? [t] : Array.isArray(t) ? t : [];
113
- return !i.length || !o ? r[0] + a : (i.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (n + "?" + o.replace(new RegExp("(?:^|&)(?:" + i.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + a);
112
+ const n = e.split("#"), s = n[0].split("?"), r = s[0], o = s.length > 1 ? s[1] : "", a = n.length > 1 ? "#" + n[1] : "", i = typeof t == "string" ? [t] : Array.isArray(t) ? t : [];
113
+ return !i.length || !o ? n[0] + a : (i.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (r + "?" + o.replace(new RegExp("(?:^|&)(?:" + i.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + a);
114
114
  }
115
- function Q(e, t, r = !1) {
115
+ function z(e, t, n = !1) {
116
116
  const s = typeof t == "string" ? t : Object.keys(t).map((a) => `${a}=${encodeURIComponent(t[a])}`).join("&");
117
117
  if (!s)
118
118
  return e;
119
- const n = e.split("#");
120
- r && (n[0] = z(
121
- n[0],
119
+ const r = e.split("#");
120
+ n && (r[0] = X(
121
+ r[0],
122
122
  (s.match(/([^=&#?]+)=[^&#]+/g) || []).map((a) => a.replace(/=.+$/, ""))
123
123
  ));
124
- const o = n[0].indexOf("?") + 1 ? "&" : "?";
125
- return (n[0] + o + s + (n.length > 1 ? "#" + n[1] : "")).replace(/\?&/, "?");
124
+ const o = r[0].indexOf("?") + 1 ? "&" : "?";
125
+ return (r[0] + o + s + (r.length > 1 ? "#" + r[1] : "")).replace(/\?&/, "?");
126
126
  }
127
- function Y(e) {
127
+ function Q(e) {
128
128
  const t = e.match(/(?:\?|&)([^=]+)(?:&|$)/g);
129
129
  return t ? t.join("").replace(/(?:\?|^&+|&+$)/g, "").replace(/&{2}/g, "&").split("&").sort() : [];
130
130
  }
131
- class Z {
131
+ class Y {
132
132
  ttl;
133
133
  cache;
134
134
  timer = null;
135
135
  // 定时循环以清理缓存
136
136
  loopCheck() {
137
- if (Object.keys(this.cache).forEach((r) => {
138
- this.cache[r].ttl < Date.now() && delete this.cache[r];
137
+ if (Object.keys(this.cache).forEach((n) => {
138
+ this.cache[n].ttl < Date.now() && delete this.cache[n];
139
139
  }), Object.keys(this.cache).length === 0) {
140
140
  this.timer = null;
141
141
  return;
@@ -145,41 +145,41 @@ class Z {
145
145
  constructor(t = 500) {
146
146
  this.cache = {}, this.ttl = Math.max(t, 0), this.loopCheck = this.loopCheck.bind(this);
147
147
  }
148
- getKey(t, r, s, n) {
149
- if (t.toLowerCase() !== "get" && !n)
148
+ getKey(t, n, s, r) {
149
+ if (t.toLowerCase() !== "get" && !r)
150
150
  return "";
151
- const o = t.toLowerCase(), a = r.replace(/#.+/, ""), i = a.replace(/\?.+/g, "");
152
- if (n)
151
+ const o = t.toLowerCase(), a = n.replace(/#.+/, ""), i = a.replace(/\?.+/g, "");
152
+ if (r)
153
153
  try {
154
- const h = n() || "";
154
+ const h = r() || "";
155
155
  return h ? `${i}_${o}_${h}` : "";
156
156
  } catch (h) {
157
- return console.warn("[RequestCache] cacheResolve error", r, s, h), "";
157
+ return console.warn("[RequestCache] cacheResolve error", n, s, h), "";
158
158
  }
159
- const c = Object.assign(X(a, !0), s), l = Y(a), u = Object.keys(c).sort().map((h) => `${h}#${c[h]}`);
159
+ const c = Object.assign(W(a, !0), s), l = Q(a), u = Object.keys(c).sort().map((h) => `${h}#${c[h]}`);
160
160
  return `${i}_${o}_${u.join(",")}_${l.join(",")}`;
161
161
  }
162
162
  updateTTL(t) {
163
163
  this.ttl = Math.max(t, 0);
164
164
  }
165
- get(t, r) {
166
- if (Math.max(r ?? this.ttl, 0) === 0)
165
+ get(t, n) {
166
+ if (Math.max(n ?? this.ttl, 0) === 0)
167
167
  return null;
168
- const n = this.cache[t];
169
- return n ? n.ttl < Date.now() ? (delete this.cache[t], null) : n.res : null;
170
- }
171
- set(t, r, s) {
172
- const n = Math.max(s ?? this.ttl, 0);
173
- n !== 0 && (this.cache[t] = {
174
- ttl: Date.now() + n,
175
- res: r
168
+ const r = this.cache[t];
169
+ return r ? r.ttl < Date.now() ? (delete this.cache[t], null) : r.res : null;
170
+ }
171
+ set(t, n, s) {
172
+ const r = Math.max(s ?? this.ttl, 0);
173
+ r !== 0 && (this.cache[t] = {
174
+ ttl: Date.now() + r,
175
+ res: n
176
176
  }, this.timer === null && (this.timer = setTimeout(this.loopCheck, 5e3)));
177
177
  }
178
178
  del(t) {
179
179
  this.cache[t] && delete this.cache[t];
180
180
  }
181
181
  }
182
- class ee {
182
+ class Z {
183
183
  // 保存的配置需要部分字段强制设置默认值
184
184
  config = {
185
185
  baseURL: "/",
@@ -213,14 +213,14 @@ class ee {
213
213
  }
214
214
  /** 基于 baseURL 返回完整的 url 地址 */
215
215
  getFullUrl(t) {
216
- return W(t, this.config.baseURL);
216
+ return V(t, this.config.baseURL);
217
217
  }
218
218
  /** 提示消息 */
219
- showMessage(t, r, s, n) {
220
- this.config.messageHandler && r && this.config.messageHandler(t, r, s, n);
219
+ showMessage(t, n, s, r) {
220
+ this.config.messageHandler && n && this.config.messageHandler(t, n, s, r);
221
221
  }
222
222
  }
223
- const w = {
223
+ const y = {
224
224
  /** 响应数据校验失败 */
225
225
  UnexpectResponse: "UnexpectResponse",
226
226
  /** 请求被取消 */
@@ -234,53 +234,53 @@ const w = {
234
234
  /** 请求方法不被支持,在微信小程序环境下有效 */
235
235
  NotSupport: "NotSupport"
236
236
  };
237
- function te(e, t, r, s) {
238
- if (t.ok && !x(t.data) && s) {
239
- const { guard: n, message: o } = V(s, r.get("defaultTypeGuardMessage"));
240
- return n(t.data) || (t.code = w.UnexpectResponse, r.showMessage(!0, `${e} ${o}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = o), t;
237
+ function ee(e, t, n, s) {
238
+ if (t.ok && !F(t.data) && s) {
239
+ const { guard: r, message: o } = J(s, n.get("defaultTypeGuardMessage"));
240
+ return r(t.data) || (t.code = y.UnexpectResponse, n.showMessage(!0, `${e} ${o}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = o), t;
241
241
  }
242
242
  return t;
243
243
  }
244
- class Re {
244
+ class ke {
245
245
  agent;
246
246
  config;
247
247
  cache;
248
- constructor(t, r) {
249
- this.config = new ee(r), this.agent = t, this.cache = new Z(this.config.get("cacheTTL")), this.setConfig = this.setConfig.bind(this), this.getConfig = this.getConfig.bind(this), this.request = this.request.bind(this), this.get = this.get.bind(this), this.post = this.post.bind(this), this.del = this.del.bind(this), this.patch = this.patch.bind(this), this.put = this.put.bind(this), this.head = this.head.bind(this);
248
+ constructor(t, n) {
249
+ this.config = new Z(n), this.agent = t, this.cache = new Y(this.config.get("cacheTTL")), this.setConfig = this.setConfig.bind(this), this.getConfig = this.getConfig.bind(this), this.request = this.request.bind(this), this.get = this.get.bind(this), this.post = this.post.bind(this), this.del = this.del.bind(this), this.patch = this.patch.bind(this), this.put = this.put.bind(this), this.head = this.head.bind(this);
250
250
  }
251
251
  /** 发送网络请求,含有缓存控制逻辑,不含有 guard 逻辑 */
252
- async send(t, r) {
253
- const s = this.cache.getKey(r?.method || "GET", t, r?.params, r?.cacheResolve);
252
+ async send(t, n) {
253
+ const s = this.cache.getKey(n?.method || "GET", t, n?.params, n?.cacheResolve);
254
254
  if (s) {
255
- const n = this.cache.get(s, r?.cacheTTL);
256
- if (n)
257
- return await n;
255
+ const r = this.cache.get(s, n?.cacheTTL);
256
+ if (r)
257
+ return await r;
258
258
  }
259
259
  try {
260
- const n = this.agent(t, this.config, r);
261
- s && this.cache.set(s, n, r?.cacheTTL);
262
- const o = await n;
260
+ const r = this.agent(t, this.config, n);
261
+ s && this.cache.set(s, r, n?.cacheTTL);
262
+ const o = await r;
263
263
  return (!o.ok || o.status < 0) && this.cache.del(s), o;
264
- } catch (n) {
265
- return console.error("RequestError", n), {
264
+ } catch (r) {
265
+ return console.error("RequestError", r), {
266
266
  ok: !1,
267
267
  status: -1,
268
- code: w.Unknown,
269
- message: n instanceof Error ? n.message : String(n),
268
+ code: y.Unknown,
269
+ message: r instanceof Error ? r.message : String(r),
270
270
  headers: {},
271
271
  data: null
272
272
  };
273
273
  }
274
274
  }
275
275
  async request(t) {
276
- const r = await this.send(t.url, t.options);
277
- return te(t.url, r, this.config, t.guard ?? null);
276
+ const n = await this.send(t.url, t.options);
277
+ return ee(t.url, n, this.config, t.guard ?? null);
278
278
  }
279
279
  /** 整理合并通用参数 */
280
- gen(t, r, s, n, o) {
280
+ gen(t, n, s, r, o) {
281
281
  const a = Object.assign(
282
- o ? { ...o, method: r } : { method: r },
283
- n ? { body: n } : null,
282
+ o ? { ...o, method: n } : { method: n },
283
+ r ? { body: r } : null,
284
284
  s ? { params: s } : null
285
285
  );
286
286
  return typeof t == "object" ? (a.params = t.params, { options: a, url: t.url }) : { options: a, url: t };
@@ -300,55 +300,62 @@ class Re {
300
300
  /**
301
301
  * 发送一个 HEAD 请求,并且不处理响应 body
302
302
  */
303
- async head(t, r, s) {
304
- return this.request(this.gen(t, "HEAD", r, null, s));
303
+ async head(t, n, s) {
304
+ return this.request(this.gen(t, "HEAD", n, null, s));
305
305
  }
306
- async get(t, r, s, n) {
307
- const o = this.gen(t, "GET", r, null, n);
306
+ async get(t, n, s, r) {
307
+ const o = this.gen(t, "GET", n, null, r);
308
308
  return s ? this.request({ ...o, guard: s }) : this.request(o);
309
309
  }
310
- async post(t, r, s, n) {
311
- const o = this.gen(t, "POST", null, r, n);
310
+ async post(t, n, s, 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
- async del(t, r, s, n) {
315
- const o = this.gen(t, "DELETE", r, null, n);
314
+ async del(t, n, s, r) {
315
+ const o = this.gen(t, "DELETE", n, null, r);
316
316
  return s ? this.request({ ...o, guard: s }) : this.request(o);
317
317
  }
318
- async put(t, r, s, n) {
319
- const o = this.gen(t, "PUT", null, r, n);
318
+ async put(t, n, s, 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
- async patch(t, r, s, n) {
323
- const o = this.gen(t, "PATCH", null, r, n);
322
+ async patch(t, n, s, 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
  }
327
- function se(e) {
327
+ function te(e) {
328
328
  const t = {};
329
- for (const [r, s] of e)
330
- r && typeof r == "string" && (t[r] = s || "");
329
+ for (const [n, s] of e)
330
+ n && typeof n == "string" && (t[n] = s || "");
331
331
  return t;
332
332
  }
333
- function B(e) {
334
- return x(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && S() ? new TextDecoder().decode(e) : JSON.stringify(e);
333
+ function se(e) {
334
+ const t = {};
335
+ return e && Object.keys(e).forEach((n) => {
336
+ const s = e[n], r = s == null ? "" : typeof s == "boolean" || typeof s == "number" ? String(s) : s;
337
+ r && (t[n] = r);
338
+ }), t;
335
339
  }
336
- function re(e) {
337
- return e instanceof Error ? e : new Error(B(e));
340
+ function L(e) {
341
+ return F(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && O() ? new TextDecoder().decode(e) : JSON.stringify(e);
338
342
  }
339
- async function je(e) {
340
- if (S())
343
+ function ne(e) {
344
+ return e instanceof Error ? e : new Error(L(e));
345
+ }
346
+ async function Re(e) {
347
+ if (O())
341
348
  return new TextEncoder().encode(e).buffer;
342
- if (j())
349
+ if (R())
343
350
  return await new Blob([e]).arrayBuffer();
344
351
  throw new Error("cannot convert string to ArrayBuffer");
345
352
  }
346
- function ne(e, t) {
347
- if ("URL" in U()) {
353
+ function re(e, t) {
354
+ if ("URL" in C()) {
348
355
  const s = new URL(e);
349
- return Object.keys(t).forEach((n) => s.searchParams.set(n, t[n])), s.toString();
356
+ return Object.keys(t).forEach((r) => s.searchParams.set(r, t[r])), s.toString();
350
357
  }
351
- return Q(e, t);
358
+ return z(e, t);
352
359
  }
353
360
  function oe(e) {
354
361
  return typeof e == "function" ? e : Array.isArray(e) && e.length > 0 ? function(t) {
@@ -356,109 +363,98 @@ function oe(e) {
356
363
  } : e === "network" ? ae : ce;
357
364
  }
358
365
  function ae({ error: e }) {
359
- return e === w.NetworkError;
366
+ return e === y.NetworkError;
360
367
  }
361
- function ce({ status: e, headers: t, error: r }) {
362
- return r === w.NetworkError ? !0 : t?.server === "TencentEdgeOne" ? e === 522 || e === 552 : !1;
368
+ function ce({ status: e, headers: t, error: n }) {
369
+ return n === y.NetworkError ? !0 : t?.server === "TencentEdgeOne" ? e === 522 || e === 552 : !1;
363
370
  }
364
- async function $e(e, t, r) {
365
- const s = Object.assign({ method: "GET" }, r), n = F() ? s.body instanceof FormData : !1, o = n && s.method !== "POST" && s.method !== "PUT" ? "POST" : s.method, a = o === "GET" || o === "HEAD" || o === "DELETE";
371
+ async function $e(e, t, n) {
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";
366
373
  a && s.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete s.body);
367
- const i = Object.assign(
368
- n || a ? {} : {
369
- "Content-Type": j() && s.body instanceof Blob ? s.body.type || "application/octet-stream" : "application/json;charset=utf-8"
370
- },
371
- s.headers
372
- ), c = s.params || {}, l = {};
373
- Object.keys(c).forEach((y) => {
374
- c[y] !== void 0 && (l[y] = ie(c[y]));
375
- });
376
- const u = t.getFullUrl(e), h = ue(s.body), p = s.timeout || t.get("timeout"), d = await (async function() {
377
- const y = t.get("requestTransformer");
378
- if (y)
379
- return await y({ headers: i, params: l, method: o, url: u, body: h });
380
- })(), g = ne(typeof d == "string" && d ? d : u, l);
381
- return t.get("logHandler")?.({ type: "ready", url: g, method: o, headers: i, timeout: p, body: h }), {
382
- url: g,
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() {
378
+ const g = t.get("requestTransformer");
379
+ if (g)
380
+ return await g({ headers: i, params: l, method: o, url: c, body: u });
381
+ })(), d = re(typeof p == "string" && p ? p : c, l);
382
+ return t.get("logHandler")?.({ type: "ready", url: d, method: o, headers: i, timeout: h, body: u }), {
383
+ url: d,
383
384
  method: o,
384
- body: h,
385
+ body: u,
385
386
  headers: i,
386
- timeout: p,
387
+ timeout: h,
387
388
  abort: s.abort,
388
389
  asBuffer: !!s.asBuffer,
389
390
  credentials: s.credentials || t.get("credentials")
390
391
  };
391
392
  }
392
393
  function ie(e) {
393
- return x(e) ? "" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : Array.isArray(e) ? e.filter(
394
- (r) => r != null && typeof r != "object" && typeof r != "function"
395
- ).join(",") : (console.warn("参数类型不支持,已被过滤", typeof e, e), "");
396
- }
397
- function ue(e) {
398
394
  if (e)
399
- return typeof e == "string" || H() && e instanceof URLSearchParams || e instanceof ArrayBuffer || j() && e instanceof Blob || F() && 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);
400
396
  }
401
- const D = "data", b = "message";
402
- function fe(e, t, r) {
403
- return P(e.status) ? he(r?.ok || t.ok, e) : le(r?.failed || t.failed, e);
397
+ const B = "data", w = "message";
398
+ function ue(e, t, n) {
399
+ return D(e.status) ? fe(n?.ok || t.ok, e) : he(n?.failed || t.failed, e);
404
400
  }
405
- function he(e, { statusText: t, body: r }) {
401
+ function fe(e, { statusText: t, body: n }) {
406
402
  const s = {
407
403
  ok: !0,
408
404
  code: t,
409
405
  message: "",
410
406
  data: null
411
407
  };
412
- if (!r)
408
+ if (!n)
413
409
  return s;
414
- if (typeof r != "string")
415
- return s.data = r, s;
410
+ if (typeof n != "string")
411
+ return s.data = n, s;
416
412
  if (e.resolve === "body")
417
- return s.data = L(r) ? k(T(r), e.converter) : r, s;
418
- const n = T(r);
419
- if (!n)
413
+ return s.data = S(n) ? T(E(n), e.converter) : n, s;
414
+ const r = E(n);
415
+ if (!r)
420
416
  return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法解析为 json", s;
421
- const o = k(n, e.converter);
422
- if (!o || !v(o))
417
+ const o = T(r, e.converter);
418
+ if (!o || !A(o))
423
419
  return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法格式化为 object", s;
424
420
  const a = e.statusField;
425
421
  if (a && !(a in o))
426
422
  return s.ok = !1, s.code = "ResponseFieldMissing", s.message = `响应内容找不到状态字段 ${a}`, s;
427
- const i = e.statusOKValue || "", c = e.dataField || D, l = e.messageField || b, u = a ? String(o[a] ?? "") : "";
428
- return s.ok = a ? u === i : !0, s.code = u || s.code, s.data = c === !0 ? o : c in o ? o[c] : null, s.message = R(o, l), e.ignoreMessage && s.message && (Array.isArray(e.ignoreMessage) ? e.ignoreMessage.includes(s.message) : e.ignoreMessage === s.message) && (s.message = ""), s;
423
+ const i = e.statusOKValue || "", c = e.dataField || B, l = e.messageField || w, u = a ? String(o[a] ?? "") : "";
424
+ return s.ok = a ? u === i : !0, s.code = u || s.code, s.data = c === !0 ? o : c in o ? o[c] : null, s.message = k(o, l), e.ignoreMessage && s.message && (Array.isArray(e.ignoreMessage) ? e.ignoreMessage.includes(s.message) : e.ignoreMessage === s.message) && (s.message = ""), s;
429
425
  }
430
- function le(e, { statusText: t, body: r, error: s }) {
431
- const n = typeof r == "string" ? r : "", o = {
426
+ function he(e, { statusText: t, body: n, error: s }) {
427
+ const r = typeof n == "string" ? n : "", o = {
432
428
  ok: !1,
433
429
  code: s || t,
434
- message: n,
430
+ message: r,
435
431
  data: null
436
432
  };
437
433
  switch (e.resolve) {
438
434
  case "body":
439
- o.message = O(n) || n;
435
+ o.message = j(r) || r;
440
436
  break;
441
437
  case "json":
442
- const { code: a, message: i } = de(n, e.converter, e.statusField, e.messageField);
443
- o.code = a || s || t, o.message = O(n) || i;
438
+ const { code: a, message: i } = le(r, e.converter, e.statusField, e.messageField);
439
+ o.code = a || s || t, o.message = j(r) || i;
444
440
  break;
445
441
  }
446
442
  return o;
447
443
  }
448
- function P(e) {
444
+ function D(e) {
449
445
  return e >= 200 && e < 400;
450
446
  }
451
- function k(e, t) {
447
+ function T(e, t) {
452
448
  return t && typeof t == "function" ? t(e) : e;
453
449
  }
454
450
  const xe = function(e) {
455
- const t = [], r = e.failed || { resolve: "json" };
456
- switch (t.push("- 当http状态码 <200 或者 >=400 时"), r.resolve) {
451
+ const t = [], n = e.failed || { resolve: "json" };
452
+ switch (t.push("- 当http状态码 <200 或者 >=400 时"), n.resolve) {
457
453
  case "body":
458
454
  t.push(" 将响应内容格式化为字符串并作为错误消息");
459
455
  break;
460
456
  case "json":
461
- t.push(" 将响应解析为json,并读取 " + (r.messageField || b) + " 作为错误消息");
457
+ t.push(" 将响应解析为json,并读取 " + (n.messageField || w) + " 作为错误消息");
462
458
  break;
463
459
  }
464
460
  const s = e.ok || { resolve: "body" };
@@ -468,7 +464,7 @@ const xe = function(e) {
468
464
  break;
469
465
  case "json":
470
466
  t.push(
471
- " 将响应解析为 json,读取 " + (s.dataField || D) + " 作为响应数据,读取 " + (s.messageField || b) + " 作为提示消息"
467
+ " 将响应解析为 json,读取 " + (s.dataField || B) + " 作为响应数据,读取 " + (s.messageField || w) + " 作为提示消息"
472
468
  ), s.statusField && t.push(
473
469
  " 当 " + s.statusField + " 为 " + (s.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
474
470
  ), s.ignoreMessage && t.push(" 并忽略以下消息:" + s.ignoreMessage);
@@ -477,39 +473,39 @@ const xe = function(e) {
477
473
  return t.join(`
478
474
  `);
479
475
  };
480
- function de(e, t, r, s = b) {
481
- if (!L(e))
476
+ function le(e, t, n, s = w) {
477
+ if (!S(e))
482
478
  return { message: "" };
483
- const n = k(T(e), t);
484
- return !n || !v(n) ? { message: e } : {
485
- code: r ? R(n, r) : "",
486
- message: R(n, s) || e
479
+ const r = T(E(e), t);
480
+ return !r || !A(r) ? { message: e } : {
481
+ code: n ? k(r, n) : "",
482
+ message: k(r, s) || e
487
483
  };
488
484
  }
489
- function R(e, t) {
490
- const r = Array.isArray(t) ? t : [t];
491
- for (const s of r)
485
+ function k(e, t) {
486
+ const n = Array.isArray(t) ? t : [t];
487
+ for (const s of n)
492
488
  if (s in e)
493
- return B(e[s]);
489
+ return L(e[s]);
494
490
  return "";
495
491
  }
496
- const ge = [/<title>([^<]+)<\/title>/i, /<message>([^<]+)<\/message>/i];
497
- function O(e) {
498
- for (const t of ge) {
499
- const r = e.match(t);
500
- if (r)
501
- return r[1];
492
+ const de = [/<title>([^<]+)<\/title>/i, /<message>([^<]+)<\/message>/i];
493
+ function j(e) {
494
+ for (const t of de) {
495
+ const n = e.match(t);
496
+ if (n)
497
+ return n[1];
502
498
  }
503
499
  return "";
504
500
  }
505
- const pe = /* @__PURE__ */ I("APIError");
506
- function me(e) {
501
+ const ge = /* @__PURE__ */ N("APIError");
502
+ function pe(e) {
507
503
  const t = {};
508
- for (const n in e.headers)
509
- (n.startsWith("x-") || n.includes("trace") || n.includes("server") || n.includes("status") || /\b(?:id|uuid)\b/.test(n)) && (t[n] = e.headers[n]);
510
- const r = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), s = e.status < 0 ? "unknown" : e.status;
504
+ for (const r in e.headers)
505
+ (r.startsWith("x-") || r.includes("trace") || r.includes("server") || r.includes("status") || /\b(?:id|uuid)\b/.test(r)) && (t[r] = e.headers[r]);
506
+ const n = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), s = e.status < 0 ? "unknown" : e.status;
511
507
  return {
512
- sentryError: new pe(`${r}${s === "unknown" ? "" : ` | ${s}`} | ${e.code}`),
508
+ sentryError: new ge(`${n}${s === "unknown" ? "" : ` | ${s}`} | ${e.code}`),
513
509
  sentryTags: {
514
510
  ...t,
515
511
  status: s,
@@ -525,35 +521,35 @@ function me(e) {
525
521
  }
526
522
  };
527
523
  }
528
- async function Ce(e, t) {
524
+ async function je(e, t) {
529
525
  if (e.method === "HEAD" || e.status === 204)
530
526
  return e.body = null, e;
531
527
  try {
532
528
  e.body = t.asBuffer ? await t.buffer() : await t.text();
533
- } catch (r) {
534
- e.body = null, e.error = w.Unknown, e.rawError = re(r);
529
+ } catch (n) {
530
+ e.body = null, e.error = y.Unknown, e.rawError = ne(n);
535
531
  }
536
532
  return e;
537
533
  }
538
- function Oe(e, t, r, s) {
539
- const n = e.status, o = e.method, a = se(
534
+ function ve(e, t, n, s) {
535
+ const r = e.status, o = e.method, a = te(
540
536
  Object.entries(e.headers || {}).map(([d, g]) => [d.toLowerCase(), g])
541
- ), { ok: i, code: c, data: l, message: u } = fe(e, r.get("responseRule"), s?.responseRule);
542
- if (!P(n)) {
543
- const d = me({
537
+ ), { ok: i, code: c, data: l, message: u } = ue(e, n.get("responseRule"), s?.responseRule);
538
+ if (!D(r)) {
539
+ const d = pe({
544
540
  url: e.url,
545
541
  method: e.method,
546
- status: n,
542
+ status: r,
547
543
  code: c,
548
544
  message: u,
549
545
  body: e.body,
550
546
  headers: a,
551
547
  error: e.rawError
552
548
  });
553
- (r.get("errorHandler") || ye)({
549
+ (n.get("errorHandler") || me)({
554
550
  url: t,
555
551
  method: o,
556
- status: n,
552
+ status: r,
557
553
  code: c,
558
554
  message: u,
559
555
  headers: a,
@@ -561,39 +557,39 @@ function Oe(e, t, r, s) {
561
557
  ...d
562
558
  });
563
559
  }
564
- if (n < 0)
565
- return A(
566
- { ok: !1, status: n, code: e.statusText, headers: {}, message: "", data: null },
560
+ if (r < 0)
561
+ return v(
562
+ { ok: !1, status: r, code: e.statusText, headers: {}, message: "", data: null },
567
563
  `${o} ${t} ${e.statusText}`,
568
564
  o,
569
565
  t,
570
- r,
566
+ n,
571
567
  s
572
568
  );
573
- const h = { ok: i, data: l, code: c, message: u, status: n, headers: a };
574
- r.get("responseHandler")?.({ ...h }, o, t);
569
+ const h = { ok: i, data: l, code: c, message: u, status: r, headers: a };
570
+ n.get("responseHandler")?.({ ...h }, o, t);
575
571
  const p = i ? u : u || e.statusText;
576
- return A(h, p, o, t, r, s);
572
+ return v(h, p, o, t, n, s);
577
573
  }
578
- function A(e, t, r, s, n, o) {
579
- const a = n.get("message"), i = a === !1 || o?.message === !1 ? !1 : o?.message || a;
574
+ function v(e, t, n, s, r, o) {
575
+ const a = r.get("message"), i = a === !1 || o?.message === !1 ? !1 : o?.message || a;
580
576
  if (i !== !1) {
581
- const c = typeof i == "function" ? i(e, r, s, t) : t;
582
- c instanceof Error ? n.showMessage(!0, E(c.message), e.code, e.status) : c && typeof c == "object" && "message" in c && typeof c.message == "string" ? n.showMessage(!1, E(c.message), e.code, e.status) : c && n.showMessage(!e.ok, E(String(c)), e.code, e.status);
577
+ const c = typeof i == "function" ? i(e, n, s, t) : t;
578
+ c instanceof Error ? r.showMessage(!0, b(c.message), e.code, e.status) : c && typeof c == "object" && "message" in c && typeof c.message == "string" ? r.showMessage(!1, b(c.message), e.code, e.status) : c && r.showMessage(!e.ok, b(String(c)), e.code, e.status);
583
579
  }
584
580
  return e;
585
581
  }
586
- function ye(e) {
582
+ function me(e) {
587
583
  const t = {};
588
- for (const r in e)
589
- r.startsWith("sentry") || (t[r] = e[r]);
584
+ for (const n in e)
585
+ n.startsWith("sentry") || (t[n] = e[n]);
590
586
  console.error("RequestError", t);
591
587
  }
592
- function E(e) {
588
+ function b(e) {
593
589
  return e.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").trim();
594
590
  }
595
- async function we(e, t, r, s, n) {
596
- const o = n || 0, a = Math.max(0, Math.min(10, s?.maxRetry ?? r.get("maxRetry") ?? 0)), i = oe(s?.retryResolve ?? r.get("retryResolve")), c = r.get("logHandler");
591
+ async function ye(e, t, n, s, r) {
592
+ const o = r || 0, a = Math.max(0, Math.min(10, s?.maxRetry ?? n.get("maxRetry") ?? 0)), i = oe(s?.retryResolve ?? n.get("retryResolve")), c = n.get("logHandler");
597
593
  c?.({
598
594
  type: "prepare",
599
595
  url: t,
@@ -604,7 +600,7 @@ async function we(e, t, r, s, n) {
604
600
  headers: s?.headers,
605
601
  options: s
606
602
  });
607
- const l = Date.now(), u = await e(t, r, s), h = u.status, p = Date.now() - l, d = `[cost ${p}][${h}] ${h < 0 ? u.body : ""}`;
603
+ const l = Date.now(), u = await e(t, n, s), h = u.status, p = Date.now() - l, d = `[cost ${p}][${h}] ${h < 0 ? u.body : ""}`;
608
604
  if (c?.({
609
605
  type: "finished",
610
606
  url: t,
@@ -617,30 +613,31 @@ async function we(e, t, r, s, n) {
617
613
  cost: p
618
614
  }), !a || o >= a || i(u, o) !== !0)
619
615
  return u;
620
- const g = s?.retryInterval ?? r.get("retryInterval") ?? 100;
621
- return await N(
616
+ const g = s?.retryInterval ?? n.get("retryInterval") ?? 100;
617
+ return await H(
622
618
  Math.max(
623
619
  100,
624
620
  g === "2EB" ? Math.pow(2, o) * 100 : typeof g == "function" ? g(o + 1, { url: t, status: h, method: u.method }) || 0 : g
625
621
  )
626
- ), await we(e, t, r, s, o + 1);
622
+ ), await ye(e, t, n, s, o + 1);
627
623
  }
628
624
  export {
629
- q as E,
630
- ee as G,
631
- Q as H,
632
- Re as N,
633
- w as R,
634
- be as X,
635
- je as a,
636
- Ee as b,
625
+ P as E,
626
+ Z as G,
627
+ z as H,
628
+ ke as N,
629
+ y as R,
630
+ we as X,
631
+ Re as a,
632
+ se as b,
637
633
  $e as c,
638
- se as d,
639
- Te as e,
640
- Ce as f,
634
+ be as d,
635
+ te as e,
636
+ je as f,
641
637
  xe as g,
642
- Oe as h,
643
- we as r,
644
- B as t,
645
- ke as v
638
+ ve as h,
639
+ Ee as i,
640
+ ye as r,
641
+ L as t,
642
+ Te as v
646
643
  };
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-DRbCcUt8.js";
2
- import { g as O } from "./retry-DRbCcUt8.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.0",
3
+ "version": "4.0.2",
4
4
  "description": "request tools for seayoo web",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -17,7 +17,7 @@ export declare const RequestInternalError: {
17
17
  };
18
18
  export type RequestInternalError = (typeof RequestInternalError)[keyof typeof RequestInternalError];
19
19
  export type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
20
- export type RequestQueryParams = Record<string, string | number | boolean>;
20
+ export type RequestQueryParams = Record<string, string | number | boolean | null | undefined>;
21
21
  /** 通用网络请求工具的基本配置 */
22
22
  export interface BaseRequestOptions {
23
23
  /** 网络请求方法,默认 GET */
@@ -1,6 +1,7 @@
1
- import { RetryResolve, RetryResolveFunc } from "./type";
1
+ import { RetryResolve, RetryResolveFunc, RequestQueryParams } from "./type";
2
2
  /** 简版 Object.fromEntries 以处理某些低版本浏览器和 webview 的问题 */
3
3
  export declare function fromEntries(kv: [string, string | undefined][]): Record<string, string>;
4
+ export declare function convertParams(params?: RequestQueryParams): Record<string, string>;
4
5
  export declare function toString(data: unknown): string;
5
6
  export declare function convertError(e: unknown): Error;
6
7
  export declare function convertStringToArrayBuffer(content: string): Promise<ArrayBuffer>;