@seayoo-web/request 3.0.1 → 3.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.
@@ -0,0 +1,1119 @@
1
+ var ht = Object.defineProperty;
2
+ var ct = (e, t, s) => t in e ? ht(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var v = (e, t, s) => ct(e, typeof t != "symbol" ? t + "" : t, s);
4
+ var ft = Object.defineProperty, dt = (e, t, s) => t in e ? ft(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, o = (e, t, s) => dt(e, typeof t != "symbol" ? t + "" : t, s);
5
+ const u = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), j = {
6
+ wx: "wx" in u && O(u.wx) && "getSystemInfo" in u.wx && _(u.wx.getSystemInfo),
7
+ fetch: "fetch" in u && _(u.fetch),
8
+ window: "window" in u && O(u.window),
9
+ requestAnimationFrame: "requestAnimationFrame" in u && _(u.requestAnimationFrame),
10
+ localStorage: "localStorage" in u && O(u.localStorage) && "getItem" in u.localStorage && _(u.localStorage.getItem),
11
+ sessionStorage: "sessionStorage" in u && O(u.sessionStorage) && "getItem" in u.sessionStorage && _(u.sessionStorage.getItem),
12
+ File: "File" in u && _(u.File),
13
+ Blob: "Blob" in u && _(u.Blob),
14
+ Proxy: "Proxy" in u && _(u.Proxy),
15
+ Request: "Request" in u && _(u.Request),
16
+ FormData: "FormData" in u && _(u.FormData),
17
+ TextDecoder: "TextDecoder" in u && _(u.TextDecoder),
18
+ ResizeObserver: "ResizeObserver" in u && _(u.ResizeObserver),
19
+ AbortController: "AbortController" in u && _(u.AbortController)
20
+ };
21
+ function _(e) {
22
+ return typeof e == "function";
23
+ }
24
+ function O(e) {
25
+ return typeof e == "object" && e !== null;
26
+ }
27
+ function _t(e) {
28
+ return new Promise((t) => setTimeout(t, Math.max(0, e)));
29
+ }
30
+ function D() {
31
+ }
32
+ function nt(e, t) {
33
+ const s = {
34
+ log: console.log.bind(console),
35
+ error: console.error.bind(console),
36
+ warn: console.warn.bind(console)
37
+ }, r = `[${e}]`;
38
+ return ["log", "error", "warn"].forEach((n) => {
39
+ const i = console[n];
40
+ s[n] = (...a) => {
41
+ i.apply(console, [r, ...a]);
42
+ };
43
+ }), s;
44
+ }
45
+ function mt(e) {
46
+ const t = e || "CustomError";
47
+ return class extends Error {
48
+ constructor(s) {
49
+ super(s), Object.defineProperty(this, "name", {
50
+ value: t,
51
+ enumerable: !1,
52
+ configurable: !0
53
+ }), "setPrototypeOf" in Object && Object.setPrototypeOf(this, new.target.prototype), "captureStackTrace" in Error && typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, this.constructor);
54
+ }
55
+ };
56
+ }
57
+ const gt = /^(?:https?:)?\/\/.+$/i, pt = /^https?:\/\/.+$/i, bt = /^\{[\d\D]*\}$/, yt = /^\[[\d\D]*\]$/;
58
+ function wt(e) {
59
+ return typeof e == "string";
60
+ }
61
+ function I(e, t = !1) {
62
+ return t ? gt.test(e) : pt.test(e);
63
+ }
64
+ function kt(e) {
65
+ return e == null;
66
+ }
67
+ function it(e, ...t) {
68
+ return e !== null && typeof e == "object" && !(e instanceof Map) && !(e instanceof Set) && !(e instanceof WeakMap) && !(e instanceof WeakSet) && !Array.isArray(e) && t.every((s) => s in e);
69
+ }
70
+ function b(e, ...t) {
71
+ if (!e || typeof e != "object") return !1;
72
+ const s = Object.getPrototypeOf(e);
73
+ return s !== Object.prototype && s !== null ? !1 : t.every((r) => r in e);
74
+ }
75
+ function B(e, t) {
76
+ return Array.isArray(e) && e.every((s) => t(s));
77
+ }
78
+ function T(e) {
79
+ if (typeof e != "number" || Number.isNaN(e) || !Number.isFinite(e) || Number.isInteger(e) && !Number.isSafeInteger(e))
80
+ return !1;
81
+ if (e === 0)
82
+ return !0;
83
+ const t = Math.abs(e);
84
+ return t >= Number.EPSILON && t <= Number.MAX_SAFE_INTEGER;
85
+ }
86
+ function ot(e) {
87
+ return bt.test(e) || yt.test(e);
88
+ }
89
+ function R(e) {
90
+ return e ? e[0].toLowerCase() + e.slice(1) : "";
91
+ }
92
+ const at = /_\w*/, lt = /-\w*/;
93
+ function Z(e) {
94
+ const t = at.test(e) ? e.replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (s, r) => r.toUpperCase()) : lt.test(e) ? e.replace(/(?:^-*|-*$)/g, "").replace(/-+(\w)/g, (s, r) => r.toUpperCase()) : e;
95
+ return R(t);
96
+ }
97
+ function Y(e) {
98
+ return at.test(e) ? R(e).replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (t, s) => "_" + s.toLowerCase()) : lt.test(e) ? R(e.replace(/(?:^-*|-*$)/g, "")).replace(/-+(\w)/g, (t, s) => "_" + s.toLowerCase()) : R(e).replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
99
+ }
100
+ function vt(e, t = 20) {
101
+ const s = Math.max(t, 10);
102
+ return e.length <= s ? e : e.slice(0, s - 3) + "...";
103
+ }
104
+ function M(e, t) {
105
+ try {
106
+ const s = JSON.parse(e);
107
+ return t ? t(s) ? s : null : s;
108
+ } catch {
109
+ return null;
110
+ }
111
+ }
112
+ "" + Math.random().toString(32).slice(2);
113
+ function A(e, t = !1) {
114
+ return typeof e == "string" ? Z(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? A(s) : typeof s == "object" && s ? A(s, !0) : s) : b(e) ? Object.keys(e).reduce(
115
+ (s, r) => {
116
+ const n = Z(String(r)), i = n.charAt(0).toLowerCase() + n.slice(1);
117
+ return s[i] = t ? e[r] : A(e[r]), s;
118
+ },
119
+ {}
120
+ ) : e;
121
+ }
122
+ function F(e, t = !1) {
123
+ return typeof e == "string" ? Y(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? F(s) : typeof s == "object" && s ? F(s, t) : s) : b(e) ? Object.keys(e).reduce(
124
+ (s, r) => {
125
+ const n = Y(String(r));
126
+ return s[n] = t ? e[r] : F(e[r]), s;
127
+ },
128
+ {}
129
+ ) : e;
130
+ }
131
+ nt("LoadUtils");
132
+ async function Jt(e) {
133
+ return await new Promise(function(t) {
134
+ const s = document.getElementsByTagName("head")[0], r = document.createElement("script");
135
+ r.setAttribute("type", "text/javascript"), r.setAttribute("charset", "utf-8"), r.onload = function() {
136
+ s.removeChild(r), t(!0);
137
+ }, r.onerror = function() {
138
+ s.removeChild(r), t(!1);
139
+ }, r.setAttribute("src", e), s.appendChild(r);
140
+ });
141
+ }
142
+ function tt(e) {
143
+ return Object.getOwnPropertyNames(e).forEach(function(t) {
144
+ delete e[t];
145
+ }), e;
146
+ }
147
+ const g = nt("Validator");
148
+ function E(e) {
149
+ return e ? `"${vt(e).replace(/"/g, '\\"')}"` : "empty string";
150
+ }
151
+ function C(e) {
152
+ return typeof e == "object" && e && "constructor" in e && typeof e.constructor == "function" ? e.constructor.name || "ClassInstance" : Object.prototype.toString.call(e).replace(/(?:.+ |]$)/g, "");
153
+ }
154
+ function U(e) {
155
+ return typeof e == "bigint";
156
+ }
157
+ function l(e) {
158
+ return new Error(`${e ? `${e}()` : "method"} is not allowed after locked`);
159
+ }
160
+ class q {
161
+ constructor() {
162
+ o(this, "_ps", {}), o(this, "_allow", []), o(this, "_reject", []), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
163
+ }
164
+ /**
165
+ * 设置一个自定义正则校验,设置 name 以用以日志输出
166
+ */
167
+ pattern(t, s) {
168
+ if (this._locked) throw l("pattern");
169
+ return this._ps[`#${t || "custom"}`] = s, this;
170
+ }
171
+ /**
172
+ * 允许 url 格式,设置 allowFlexProto 以允许动态协议前缀格式,比如 `//some.site.com`
173
+ */
174
+ url(t = !1) {
175
+ if (this._locked) throw l("url");
176
+ return this._ps.url = t ? /^(?:https?:)?\/\/.+$/i : /^https?:\/\/.+$/i, this;
177
+ }
178
+ /**
179
+ * 允许 dataUri 格式,正则为 `^data:[a-z]+\/[a-z]+;base64,[\w+/=]+$`
180
+ */
181
+ dataUri() {
182
+ if (this._locked) throw l("dataUri");
183
+ return this._ps.dataUri = /^data:[a-z]+\/[a-z]+;base64,[\w+/=]+$/, this;
184
+ }
185
+ enum(...t) {
186
+ if (this._locked) throw l("enum");
187
+ const s = t[0];
188
+ return B(t, wt) ? (this._allow = t, tt(this._ps)) : b(s) && (this._allow = Object.values(s).map((r) => `${r}`), tt(this._ps)), this;
189
+ }
190
+ disallow(...t) {
191
+ return this._reject.push(...t), this;
192
+ }
193
+ optional() {
194
+ if (this._locked) throw l("optional");
195
+ return this._opt = !0, this;
196
+ }
197
+ maybeNull() {
198
+ if (this._locked) throw l("maybeNull");
199
+ return this._null = !0, this;
200
+ }
201
+ lock() {
202
+ return this._locked = !0, this;
203
+ }
204
+ clone() {
205
+ const t = new q();
206
+ return t._ps = { ...this._ps }, t._allow = [...this._allow], t._reject = [...this._reject], t._locked = !1, t;
207
+ }
208
+ validate(t, s = g.warn) {
209
+ if (t === void 0)
210
+ return this._opt || (s("should be a string, but got undefined"), !1);
211
+ if (t === null)
212
+ return this._null || (s("should be a string, but got null"), !1);
213
+ if (typeof t != "string")
214
+ return s(`should be a string, but got ${typeof t}`), !1;
215
+ if (this._allow.length > 0)
216
+ return this._allow.includes(t) || (s(`${E(t)} is not allowed, just support ${this._allow.map(E).join(", ")}`), !1);
217
+ if (this._reject.length > 0 && this._reject.some((n) => typeof n == "string" ? n === t : n.test(t)))
218
+ return s(`${E(t)} is not allowed`), !1;
219
+ const r = Object.keys(this._ps);
220
+ return r.length > 0 && !r.some((n) => {
221
+ const i = this._ps[n];
222
+ return i instanceof RegExp ? i.test(t) : i(t);
223
+ }) ? (s(`${E(t)} is not match pattern ${r.join(" | ")}`), !1) : !0;
224
+ }
225
+ }
226
+ class H {
227
+ constructor() {
228
+ o(this, "_int", !1), o(this, "_min", -1 / 0), o(this, "_max", 1 / 0), o(this, "_allow", []), o(this, "_reject", []), o(this, "_infinite", !1), o(this, "_unsafe", !1), o(this, "_nan", !1), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
229
+ }
230
+ int() {
231
+ if (this._locked) throw l("int");
232
+ return this._int = !0, this;
233
+ }
234
+ min(t) {
235
+ if (this._locked) throw l("min");
236
+ return Number.isNaN(t) || (this._min = t), this;
237
+ }
238
+ max(t) {
239
+ if (this._locked) throw l("max");
240
+ return Number.isNaN(t) || (this._max = t), this;
241
+ }
242
+ /** 允许 NaN */
243
+ allowNaN() {
244
+ if (this._locked) throw l("allowNaN");
245
+ return this._nan = !0, this;
246
+ }
247
+ /** 允许无限大或无限小,同时会 allowUnsafe */
248
+ allowInfinity() {
249
+ if (this._locked) throw l("allowInfinity");
250
+ return this._infinite = !0, this._unsafe = !0, this;
251
+ }
252
+ /** 允许精度不安全的数字,安全精度在 [-2^53 + 1 到 2^53 - 1] */
253
+ unsafe() {
254
+ if (this._locked) throw l("unsafe");
255
+ return this._unsafe = !0, this;
256
+ }
257
+ enum(...t) {
258
+ if (this._locked) throw l("enum");
259
+ const s = t[0];
260
+ return B(t, T) ? (this._allow = t, this._reject = []) : b(s) && (this._allow = Object.values(s).map((r) => T(r) ? r : null).filter((r) => r !== null), this._reject = []), this;
261
+ }
262
+ disallow(...t) {
263
+ if (this._locked) throw l("disallow");
264
+ return this._reject.push(...t), this;
265
+ }
266
+ optional() {
267
+ if (this._locked) throw l("optional");
268
+ return this._opt = !0, this;
269
+ }
270
+ maybeNull() {
271
+ if (this._locked) throw l("maybeNull");
272
+ return this._null = !0, this;
273
+ }
274
+ lock() {
275
+ return this._locked = !0, this;
276
+ }
277
+ clone() {
278
+ const t = new H();
279
+ return t._int = this._int, t._min = this._min, t._max = this._max, t._allow = [...this._allow], t._reject = [...this._reject], t._infinite = this._infinite, t._unsafe = this._unsafe, t._nan = this._nan, t._locked = !1, t;
280
+ }
281
+ validate(t, s = g.warn) {
282
+ return t === void 0 ? this._opt || (s("should be a number, but got undefined"), !1) : t === null ? this._null || (s("should be a number, but got null"), !1) : typeof t != "number" ? (s(`should be a number, but got ${typeof t}`), !1) : Number.isNaN(t) ? this._nan || (s("should be a number, but got NaN"), !1) : !Number.isFinite(t) && !this._infinite ? (s("should be a number, but got Infinity"), !1) : this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : this._int && Math.ceil(t) !== t ? (s(`${t} is not an integer`), !1) : !T(t) && !this._unsafe ? (s(`${t} is not a safe number`), !1) : t >= this._min && t <= this._max || (s(`${t} is not in range [${this._min}, ${this._max}]`), !1);
283
+ }
284
+ }
285
+ class G {
286
+ constructor() {
287
+ o(this, "_min", null), o(this, "_max", null), o(this, "_allow", []), o(this, "_reject", []), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
288
+ }
289
+ min(t) {
290
+ if (this._locked) throw l("min");
291
+ return this._min = t, this;
292
+ }
293
+ max(t) {
294
+ if (this._locked) throw l("max");
295
+ return this._max = t, this;
296
+ }
297
+ enum(...t) {
298
+ if (this._locked) throw l("enum");
299
+ const s = t[0];
300
+ return B(t, U) ? (this._allow = t, this._reject = []) : b(s) && (this._allow = Object.values(s).map((r) => U(r) ? r : null).filter((r) => r !== null), this._reject = []), this;
301
+ }
302
+ disallow(...t) {
303
+ if (this._locked) throw l("disallow");
304
+ return this._reject.push(...t), this;
305
+ }
306
+ optional() {
307
+ if (this._locked) throw l("optional");
308
+ return this._opt = !0, this;
309
+ }
310
+ maybeNull() {
311
+ if (this._locked) throw l("maybeNull");
312
+ return this._null = !0, this;
313
+ }
314
+ lock() {
315
+ return this._locked = !0, this;
316
+ }
317
+ clone() {
318
+ const t = new G();
319
+ return t._min = this._min, t._max = this._max, t._allow = [...this._allow], t._reject = [...this._reject], t._locked = !1, t;
320
+ }
321
+ validate(t, s = g.warn) {
322
+ return t === void 0 ? this._opt || (s("should be a bigint, but got undefined"), !1) : t === null ? this._null || (s("should be a bigint, but got null"), !1) : U(t) ? this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : (this._min !== null ? t >= this._min : !0) && (this._max !== null ? t <= this._max : !0) || (s(
323
+ `${t} is not in range [${this._min === null ? -1 / 0 : this._min}, ${this._max === null ? 1 / 0 : this._max}]`
324
+ ), !1) : (s(`should be a bigint, but got ${typeof t}`), !1);
325
+ }
326
+ }
327
+ class K {
328
+ constructor() {
329
+ o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
330
+ }
331
+ optional() {
332
+ if (this._locked) throw l("optional");
333
+ return this._opt = !0, this;
334
+ }
335
+ maybeNull() {
336
+ if (this._locked) throw l("maybeNull");
337
+ return this._null = !0, this;
338
+ }
339
+ lock() {
340
+ return this._locked = !0, this;
341
+ }
342
+ clone() {
343
+ return new K();
344
+ }
345
+ validate(t, s = g.warn) {
346
+ return t === void 0 ? this._opt || (s("should be a boolean, but got undefined"), !1) : t === null ? this._null || (s("should be a boolean, but got null"), !1) : typeof t != "boolean" ? (s(`should be a boolean, but got ${typeof t}`), !1) : !0;
347
+ }
348
+ }
349
+ class N {
350
+ constructor(t) {
351
+ o(this, "_shape"), o(this, "_plain", !1), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._shape = t;
352
+ }
353
+ plain() {
354
+ if (this._locked) throw l("plain");
355
+ return this._plain = !0, this;
356
+ }
357
+ optional() {
358
+ if (this._locked) throw l("optional");
359
+ return this._opt = !0, this;
360
+ }
361
+ maybeNull() {
362
+ if (this._locked) throw l("maybeNull");
363
+ return this._null = !0, this;
364
+ }
365
+ lock() {
366
+ return this._locked = !0, this;
367
+ }
368
+ /**
369
+ * 返回初始时的 ObjectShape 配置对象的浅层副本
370
+ */
371
+ get shape() {
372
+ return { ...this._shape };
373
+ }
374
+ clone() {
375
+ const t = new N(this._shape);
376
+ return t._plain = this._plain, t._locked = !1, t;
377
+ }
378
+ /**
379
+ * 检查指定的 field / value 是否可以通过校验
380
+ */
381
+ match(t, s) {
382
+ return t in this._shape ? this._shape[t].validate(s, D) : !1;
383
+ }
384
+ validate(t, s = g.warn) {
385
+ return t === void 0 ? this._opt || (s("should be a object, but got undefined"), !1) : t === null ? this._null || (s("should be a object, but got null"), !1) : it(t) ? this._plain && !b(t) ? (s(`should be a plain object, but got ${C(t)}`), !1) : Object.keys(this._shape).every((r) => this._shape[r].validate(t[r], (...n) => {
386
+ s(`[.${String(r)}]`, ...n);
387
+ })) : (s(`should be a object, but got ${C(t)}`), !1);
388
+ }
389
+ }
390
+ class z {
391
+ constructor(t) {
392
+ o(this, "_val"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._val = t;
393
+ }
394
+ optional() {
395
+ if (this._locked) throw l("optional");
396
+ return this._opt = !0, this;
397
+ }
398
+ maybeNull() {
399
+ if (this._locked) throw l("maybeNull");
400
+ return this._null = !0, this;
401
+ }
402
+ lock() {
403
+ return this._locked = !0, this;
404
+ }
405
+ clone() {
406
+ return new z(this._val);
407
+ }
408
+ validate(t, s = g.warn) {
409
+ return t === void 0 ? this._opt || (s("should be a record, but got undefined"), !1) : t === null ? this._null || (s("should be a record, but got null"), !1) : b(t) ? Object.keys(t).every(
410
+ (r) => this._val.validate(t[r], (...n) => {
411
+ s(`[:${r}]`, ...n);
412
+ })
413
+ ) : (s(`should be a record, but got ${C(t)}`), !1);
414
+ }
415
+ }
416
+ class V {
417
+ constructor(t) {
418
+ o(this, "_val"), o(this, "_min", 0), o(this, "_max", 1 / 0), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._val = t;
419
+ }
420
+ min(t) {
421
+ if (this._locked) throw l("min");
422
+ return this._min = t, this;
423
+ }
424
+ max(t) {
425
+ if (this._locked) throw l("max");
426
+ return this._max = t, this;
427
+ }
428
+ optional() {
429
+ if (this._locked) throw l("optional");
430
+ return this._opt = !0, this;
431
+ }
432
+ maybeNull() {
433
+ if (this._locked) throw l("maybeNull");
434
+ return this._null = !0, this;
435
+ }
436
+ lock() {
437
+ return this._locked = !0, this;
438
+ }
439
+ clone() {
440
+ const t = new V(this._val);
441
+ return t._min = this._min, t._max = this._max, t._locked = !1, t;
442
+ }
443
+ validate(t, s = g.warn) {
444
+ return t === void 0 ? this._opt || (s("should be a array, but got undefined"), !1) : t === null ? this._null || (s("should be a array, but got null"), !1) : Array.isArray(t) ? t.length < this._min || t.length > this._max ? (this._min === this._max ? s(`should be a array with length ${this._min}`) : s(`should be a array with length between ${this._min} and ${this._max}`), !1) : t.every(
445
+ (r, n) => this._val.validate(r, (...i) => {
446
+ s(`[${n}]`, ...i);
447
+ })
448
+ ) : (s(`should be a array, but got ${typeof t}`), !1);
449
+ }
450
+ }
451
+ class W {
452
+ constructor(...t) {
453
+ o(this, "_vs"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._vs = t;
454
+ }
455
+ optional() {
456
+ if (this._locked) throw l("optional");
457
+ return this._opt = !0, this;
458
+ }
459
+ maybeNull() {
460
+ if (this._locked) throw l("maybeNull");
461
+ return this._null = !0, this;
462
+ }
463
+ lock() {
464
+ return this._locked = !0, this;
465
+ }
466
+ clone() {
467
+ return new W(...this._vs);
468
+ }
469
+ validate(t, s = g.warn) {
470
+ return t === void 0 ? this._opt || (s("should be a tuple, but got undefined"), !1) : t === null ? this._null || (s("should be a tuple, but got null"), !1) : Array.isArray(t) ? t.length !== this._vs.length ? (s(`should be a tuple with length ${this._vs.length}, but got ${t.length}`), !1) : this._vs.every(
471
+ (r, n) => r.validate(t[n], (...i) => {
472
+ s(`[idx:${n}]`, ...i);
473
+ })
474
+ ) : (s(`should be a tuple, but got ${typeof t}`), !1);
475
+ }
476
+ }
477
+ class J {
478
+ constructor(...t) {
479
+ o(this, "_vs"), o(this, "_key", ""), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._vs = t;
480
+ }
481
+ optional() {
482
+ if (this._locked) throw l("optional");
483
+ return this._opt = !0, this;
484
+ }
485
+ maybeNull() {
486
+ if (this._locked) throw l("maybeNull");
487
+ return this._null = !0, this;
488
+ }
489
+ /**
490
+ * 设置联合类型中的关键字段判断,用以提高联合类型校验的效率
491
+ *
492
+ * 仅仅对于所有联合类型元素都是 object 时有效,指定的 key 对应的值应该具有唯一性
493
+ */
494
+ key(t) {
495
+ if (this._locked) throw l("key");
496
+ return this._vs.every((s) => s instanceof N) ? this._key = t : g.warn("union type key can only be used when all validators are ObjectValidator"), this;
497
+ }
498
+ satisfies() {
499
+ return this;
500
+ }
501
+ lock() {
502
+ return this._locked = !0, this;
503
+ }
504
+ get validators() {
505
+ return [...this._vs];
506
+ }
507
+ clone() {
508
+ const t = new J(...this._vs);
509
+ return t._key = this._key, t._locked = !1, t;
510
+ }
511
+ validate(t, s = g.warn) {
512
+ if (t === void 0)
513
+ return this._opt || (s("should be a union, but got undefined"), !1);
514
+ if (t === null)
515
+ return this._null || (s("should be a union, but got null"), !1);
516
+ if (this._key && it(t) && t) {
517
+ const n = t[this._key];
518
+ if (n === void 0)
519
+ return s(`key field "${this._key}" is not found`, t), !1;
520
+ const i = this._vs.find(
521
+ (a) => a instanceof N && a.match(this._key, n)
522
+ );
523
+ return i ? i.validate(t, s) : (s(`key field "${this._key}" value is match union definition`, n), !1);
524
+ }
525
+ const r = this._vs.some((n) => n.validate(t, D));
526
+ return r || s("value is not match union definition", t), r;
527
+ }
528
+ }
529
+ class S {
530
+ constructor(t, s) {
531
+ o(this, "_name", ""), o(this, "_guard"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._name = t, this._guard = s;
532
+ }
533
+ optional() {
534
+ if (this._locked) throw l("optional");
535
+ return this._opt = !0, this;
536
+ }
537
+ maybeNull() {
538
+ if (this._locked) throw l("maybeNull");
539
+ return this._null = !0, this;
540
+ }
541
+ lock() {
542
+ return this._locked = !0, this;
543
+ }
544
+ clone() {
545
+ return new S(this._name, this._guard);
546
+ }
547
+ validate(t, s = g.warn) {
548
+ const r = this._name || "custom type";
549
+ return t === void 0 ? this._opt || (s(`should be ${r}, but got undefined`), !1) : t === null ? this._null || (s(`should be ${r}, but got null`), !1) : this._guard(t) || (s(`custom validation${this._name ? `(${this._name})` : ""} failed`), !1);
550
+ }
551
+ }
552
+ function $t(e, t) {
553
+ if (typeof e == "string") {
554
+ if (!t)
555
+ throw new Error("custom type guard must be defined");
556
+ return new S(e, t);
557
+ }
558
+ return new S("", e);
559
+ }
560
+ const jt = {
561
+ /**
562
+ * object shape 的定义辅助函数
563
+ */
564
+ shape(e) {
565
+ return e;
566
+ },
567
+ /**
568
+ * validator 定义辅助函数
569
+ */
570
+ define(e) {
571
+ return e;
572
+ },
573
+ /**
574
+ * 按照类型定义生成一个类型守卫
575
+ */
576
+ guard(e) {
577
+ return function(t) {
578
+ return e.validate(t);
579
+ };
580
+ },
581
+ /** 对象结构验证 */
582
+ object(e) {
583
+ return new N(e);
584
+ },
585
+ /**
586
+ * record 数据验证,不指定 key 即 string Record。
587
+ *
588
+ * 如果需要指定 key 类型,使用 define 辅助工具
589
+ */
590
+ record(e) {
591
+ return new z(e);
592
+ },
593
+ /** 数组类型验证 */
594
+ array(e) {
595
+ return new V(e);
596
+ },
597
+ /** 元组类型验证 */
598
+ tuple(...e) {
599
+ return new W(...e);
600
+ },
601
+ /** 联合类型验证 */
602
+ union(...e) {
603
+ return new J(...e);
604
+ },
605
+ /** 字符串类型验证 */
606
+ string() {
607
+ return new q();
608
+ },
609
+ /** 布尔型类型验证 */
610
+ bool() {
611
+ return new K();
612
+ },
613
+ /** 数字验证 */
614
+ number() {
615
+ return new H();
616
+ },
617
+ /** bigint 验证 */
618
+ bigint() {
619
+ return new G();
620
+ },
621
+ /** 自定义验证 */
622
+ custom: $t,
623
+ /**
624
+ * 允许一个 unknown 类型,validate 总是返回 true
625
+ */
626
+ unknown() {
627
+ return {
628
+ validate(e) {
629
+ return !0;
630
+ }
631
+ };
632
+ },
633
+ /**
634
+ * 检测一个 never 类型,validate 总是返回 false
635
+ */
636
+ never() {
637
+ return {
638
+ validate(e) {
639
+ return !1;
640
+ }
641
+ };
642
+ }
643
+ }, Nt = (e) => b(e) && Object.keys(e).length === 0;
644
+ jt.custom("EmptyObject", Nt);
645
+ function xt(e, t = "数据未能正确识别") {
646
+ return typeof e == "function" ? {
647
+ guard: e,
648
+ message: t
649
+ } : {
650
+ guard: e.guard,
651
+ message: e.message || t
652
+ };
653
+ }
654
+ function Ot(e, t = "") {
655
+ return !t || I(e, !0) ? et(e) : (et(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
656
+ }
657
+ function et(e) {
658
+ return I(e, !0) ? e.startsWith("http") ? e : ("location" in globalThis ? location.protocol : "https:") + e : ("location" in globalThis ? location.origin : "http://127.0.0.1") + "/" + e.replace(/^\/+/, "");
659
+ }
660
+ function Et(e, t) {
661
+ const s = {};
662
+ return (e.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(r) {
663
+ const n = r.split("="), i = n[0], a = decodeURIComponent(n[1] || "");
664
+ s[i] !== void 0 ? s[i] += "," + a : s[i] = a;
665
+ }), t !== !0 ? s[t] || "" : s;
666
+ }
667
+ function Rt(e, t) {
668
+ if (t) {
669
+ if (t === !0)
670
+ return e.replace(/\?[^#]*/, "");
671
+ } else return e;
672
+ const s = e.split("#"), r = s[0].split("?"), n = r[0], i = r.length > 1 ? r[1] : "", a = s.length > 1 ? "#" + s[1] : "", h = typeof t == "string" ? [t] : Array.isArray(t) ? t : [];
673
+ return !h.length || !i ? s[0] + a : (h.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (n + "?" + i.replace(new RegExp("(?:^|&)(?:" + h.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + a);
674
+ }
675
+ function Qt(e, t, s = !1) {
676
+ const r = typeof t == "string" ? t : Object.keys(t).map((a) => `${a}=${encodeURIComponent(t[a])}`).join("&");
677
+ if (!r)
678
+ return e;
679
+ const n = e.split("#");
680
+ s && (n[0] = Rt(
681
+ n[0],
682
+ (r.match(/([^=&#?]+)=[^&#]+/g) || []).map((a) => a.replace(/=.+$/, ""))
683
+ ));
684
+ const i = n[0].indexOf("?") + 1 ? "&" : "?";
685
+ return (n[0] + i + r + (n.length > 1 ? "#" + n[1] : "")).replace(/\?&/, "?");
686
+ }
687
+ function At(e) {
688
+ const t = e.match(/(?:\?|&)([^=]+)(?:&|$)/g);
689
+ return t ? t.join("").replace(/(?:\?|^&+|&+$)/g, "").replace(/&{2}/g, "&").split("&").sort() : [];
690
+ }
691
+ class Ft {
692
+ constructor(t = 500) {
693
+ v(this, "ttl");
694
+ v(this, "cache");
695
+ this.cache = {}, this.ttl = Math.max(t, 0);
696
+ }
697
+ getKey(t, s) {
698
+ const r = t.replace(/#.+/, ""), n = r.replace(/\?.+/g, ""), i = Object.assign(Et(r, !0), s), a = At(r), h = Object.keys(i).sort().map((c) => `${c}#${i[c]}`);
699
+ return `${n}_${h.join(",")}_${a.join(",")}`;
700
+ }
701
+ updateTTL(t) {
702
+ this.ttl = Math.max(t, 0);
703
+ }
704
+ get(t) {
705
+ if (this.ttl === 0)
706
+ return null;
707
+ const s = this.cache[t];
708
+ return s ? s.ttl < Date.now() ? (delete this.cache[t], null) : s.res : null;
709
+ }
710
+ set(t, s) {
711
+ this.ttl !== 0 && (this.cache[t] = {
712
+ ttl: Date.now() + this.ttl,
713
+ res: s
714
+ });
715
+ }
716
+ }
717
+ class St {
718
+ constructor(t) {
719
+ // 保存的配置需要部分字段强制设置默认值
720
+ v(this, "config", {
721
+ baseURL: "/",
722
+ maxRetry: 0,
723
+ retryInterval: 100,
724
+ retryResolve: "network",
725
+ timeout: 1e4,
726
+ cacheTTL: 500,
727
+ credentials: "same-origin",
728
+ defaultTypeGuardMessage: "响应数据未能正确识别",
729
+ responseRule: {
730
+ ok: {
731
+ resolve: "body"
732
+ },
733
+ failed: {
734
+ resolve: "json",
735
+ messageField: "message"
736
+ }
737
+ }
738
+ });
739
+ t && this.set(t);
740
+ }
741
+ set(t) {
742
+ if (t.baseURL && !/^\/.+/.test(t.baseURL) && !I(t.baseURL))
743
+ throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"), new Error("BaseURLError");
744
+ Object.assign(this.config, t);
745
+ }
746
+ get(t) {
747
+ return this.config[t];
748
+ }
749
+ /** 基于 baseURL 返回完整的 url 地址 */
750
+ getFullUrl(t) {
751
+ return Ot(t, this.config.baseURL);
752
+ }
753
+ /** 提示消息 */
754
+ showMessage(t, s, r, n) {
755
+ this.config.messageHandler && s && this.config.messageHandler(t, s, r, n);
756
+ }
757
+ }
758
+ var Q = /* @__PURE__ */ ((e) => (e.UnexpectResponse = "UnexpectResponse", e.Aborted = "Aborted", e.Unknown = "Unknown", e.NetworkError = "NetworkError", e.Timeout = "Timeout", e.NotSupport = "NotSupport", e.URLFormatError = "URLFormatError", e))(Q || {});
759
+ function Tt(e, t, s, r) {
760
+ if (t.ok && !kt(t.data) && r) {
761
+ const n = xt(r, s.get("defaultTypeGuardMessage"));
762
+ return n.guard(t.data) || (t.code = Q.UnexpectResponse, s.showMessage(!0, `${e} ${n.message}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = n.message), t;
763
+ }
764
+ return t;
765
+ }
766
+ class Xt {
767
+ constructor(t, s) {
768
+ v(this, "agent");
769
+ v(this, "config");
770
+ v(this, "cache");
771
+ this.config = new St(s), this.agent = t, this.cache = new Ft(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);
772
+ }
773
+ /**
774
+ * 执行网络请求
775
+ */
776
+ async request(t, s) {
777
+ try {
778
+ return await this.agent(t, this.config, s);
779
+ } catch (r) {
780
+ return console.error("RequestError", r), {
781
+ ok: !1,
782
+ status: -9,
783
+ code: Q.Unknown,
784
+ message: r instanceof Error ? `${r.message}
785
+ ${r.stack || ""}` : String(r),
786
+ headers: {},
787
+ data: null
788
+ };
789
+ }
790
+ }
791
+ /**
792
+ * 检查响应的数据类型
793
+ */
794
+ async guard(t, s, r) {
795
+ return Tt(t, s, this.config, r);
796
+ }
797
+ /**
798
+ * 修改默认请求配置: baseURL / timeout / credentials / errorHandler / messageHandler / responseHandler / logHandler / responseRule
799
+ */
800
+ setConfig(t) {
801
+ this.config.set(t), this.cache.updateTTL(this.config.get("cacheTTL"));
802
+ }
803
+ /**
804
+ * 读取默认的请求配置
805
+ */
806
+ getConfig(t) {
807
+ return this.config.get(t);
808
+ }
809
+ /**
810
+ * 发送一个 HEAD 请求,并且不处理响应 body
811
+ */
812
+ async head(t, s) {
813
+ const r = Object.assign({}, s || null);
814
+ return r.method = "HEAD", this.guard(t, await this.request(t, r), null);
815
+ }
816
+ async get(t, s, r) {
817
+ const n = Object.assign({}, r || null);
818
+ n.method = "GET";
819
+ const i = this.cache.getKey(t, n.params), a = this.cache.get(i);
820
+ if (a)
821
+ return this.guard(t, await a, s || null);
822
+ const h = this.request(t, n);
823
+ return this.cache.set(i, h), this.guard(t, await h, s || null);
824
+ }
825
+ async post(t, s, r, n) {
826
+ const i = Object.assign({}, n || null);
827
+ return i.method = "POST", i.body = s || {}, this.guard(t, await this.request(t, i), r || null);
828
+ }
829
+ async del(t, s, r) {
830
+ const n = Object.assign({}, r || null);
831
+ return n.method = "DELETE", this.guard(t, await this.request(t, n), s || null);
832
+ }
833
+ async put(t, s, r, n) {
834
+ const i = Object.assign({}, n || null);
835
+ return i.method = "PUT", i.body = s || {}, this.guard(t, await this.request(t, i), r || null);
836
+ }
837
+ async patch(t, s, r, n) {
838
+ const i = Object.assign({}, n || null);
839
+ return i.method = "PATCH", i.body = s || {}, this.guard(t, await this.request(t, i), r || null);
840
+ }
841
+ }
842
+ async function Zt(e, t, s) {
843
+ var w;
844
+ const r = Object.assign({ method: "GET" }, s), n = j.FormData ? r.body instanceof FormData : !1, i = n && r.method !== "POST" && r.method !== "PUT" ? "POST" : r.method, a = i === "GET" || i === "HEAD" || i === "DELETE";
845
+ a && r.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete r.body);
846
+ const h = Object.assign(
847
+ n || a ? {} : {
848
+ "Content-Type": j.Blob && r.body instanceof Blob ? r.body.type || "application/octet-stream" : "application/json;charset=utf-8"
849
+ },
850
+ r.headers
851
+ ), c = r.params || {}, m = {};
852
+ Object.keys(c).forEach(($) => {
853
+ c[$] !== void 0 && (m[$] = Ut(c[$]));
854
+ });
855
+ const f = t.getFullUrl(e), d = Mt(r.body), p = r.timeout || t.get("timeout"), y = await async function() {
856
+ const $ = t.get("requestTransformer");
857
+ if ($)
858
+ return await $({ headers: h, params: m, method: i, url: f, body: d });
859
+ }(), k = typeof y == "string" && y ? y : f;
860
+ return (w = t.get("logHandler")) == null || w({ type: "ready", url: k, method: i, headers: h, timeout: p, body: d }), {
861
+ url: k,
862
+ method: i,
863
+ body: d,
864
+ params: m,
865
+ headers: h,
866
+ timeout: p,
867
+ abort: r.abort,
868
+ credentials: r.credentials || t.get("credentials")
869
+ };
870
+ }
871
+ function Ut(e) {
872
+ return typeof e == "string" ? e : Array.isArray(e) ? e.join(",") : e + "";
873
+ }
874
+ function Mt(e) {
875
+ if (e)
876
+ return typeof e == "string" || j.window && e instanceof URLSearchParams || e instanceof ArrayBuffer || j.Blob && e instanceof Blob || j.FormData && e instanceof FormData ? e : JSON.stringify(e);
877
+ }
878
+ const ut = "data", x = "message";
879
+ function Ct(e, t, s, r, n) {
880
+ const i = n || r;
881
+ return X(e) ? qt(i.ok || r.ok, e, t, s) : Lt(i.failed || r.failed, t, s);
882
+ }
883
+ const Yt = function(e) {
884
+ const t = [], s = e.failed || { resolve: "json" };
885
+ switch (t.push("- 当http状态码 <200 或者 >=400 时"), s.resolve) {
886
+ case "body":
887
+ t.push(" 将响应内容格式化为字符串并作为错误消息");
888
+ break;
889
+ case "json":
890
+ t.push(" 将响应解析为json,并读取 " + (s.messageField || x) + " 作为错误消息");
891
+ break;
892
+ }
893
+ const r = e.ok || { resolve: "body" };
894
+ switch (t.push("- 当http状态码 >=200 并且 <400 时"), r.resolve) {
895
+ case "body":
896
+ t.push(" 将响应尝试解析为 json,并作为数据内容返回");
897
+ break;
898
+ case "json":
899
+ t.push(
900
+ " 将响应解析为 json,读取 " + (r.dataField || ut) + " 作为响应数据,读取 " + (r.messageField || x) + " 作为提示消息"
901
+ ), r.statusField && t.push(
902
+ " 当 " + r.statusField + " 为 " + (r.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
903
+ ), r.ignoreMessage && t.push(" 并忽略以下消息:" + r.ignoreMessage);
904
+ break;
905
+ }
906
+ return t.join(`
907
+ `);
908
+ };
909
+ function Lt(e, t, s) {
910
+ const r = e || { resolve: "json", messageField: x }, n = {
911
+ ok: !1,
912
+ code: t,
913
+ message: s,
914
+ data: null
915
+ };
916
+ switch (r.resolve) {
917
+ case "body":
918
+ n.message = st(s) || s;
919
+ break;
920
+ case "json":
921
+ const { code: i, message: a } = Pt(s, r.converter, r.statusField, r.messageField);
922
+ n.code = i || t, n.message = st(s) || a;
923
+ break;
924
+ }
925
+ return n;
926
+ }
927
+ function Pt(e, t, s, r = x) {
928
+ if (!ot(e))
929
+ return { message: "" };
930
+ const n = P(M(e), t);
931
+ return !n || !b(n) ? { message: e } : {
932
+ code: s ? L(n, s) : "",
933
+ message: L(n, r) || e
934
+ };
935
+ }
936
+ function L(e, t) {
937
+ const s = Array.isArray(t) ? t : [t];
938
+ for (const r of s)
939
+ if (r in e)
940
+ return Dt(e[r]);
941
+ return "";
942
+ }
943
+ function Dt(e) {
944
+ return e ? typeof e == "string" ? e : JSON.stringify(e) : "";
945
+ }
946
+ const It = /<title>([^<]+)<\/title>/i, Bt = /<message>([^<]+)<\/message>/i;
947
+ function st(e) {
948
+ const t = e.match(It);
949
+ if (t)
950
+ return t[1];
951
+ const s = e.match(Bt);
952
+ return s ? s[1] : "";
953
+ }
954
+ function qt(e, t, s, r) {
955
+ const n = e || { resolve: "body" }, i = {
956
+ ok: !0,
957
+ code: s,
958
+ message: "",
959
+ data: null
960
+ };
961
+ if (t === 204 || !r)
962
+ return i;
963
+ if (n.resolve === "body")
964
+ return i.data = ot(r) ? P(M(r), e.converter) : r, i;
965
+ const a = P(M(r), e.converter);
966
+ if (!a || !b(a))
967
+ return i.ok = !1, i.code = "ResponseFormatError", i.message = "响应内容无法格式化为 Object", i;
968
+ const h = n.statusField, c = n.statusOKValue || "", m = n.dataField || ut, f = n.messageField || x, d = n.ignoreMessage || "";
969
+ if (h && !(h in a))
970
+ return i.ok = !1, i.code = "ResponseFieldMissing", i.message = "响应内容找不到状态字段 " + h, i;
971
+ const p = h ? a[h] + "" : "";
972
+ return i.ok = h ? p === c : !0, i.code = p || s, i.data = m === !0 ? a : m in a ? a[m] : null, i.message = L(a, f), d && i.message && (Array.isArray(d) && d.includes(i.message) || typeof d == "string" && i.message === d) && (i.message = ""), i;
973
+ }
974
+ function X(e) {
975
+ return e >= 200 && e < 400;
976
+ }
977
+ function P(e, t) {
978
+ return t === "camelize" ? A(e) : t === "snakify" ? F(e) : e;
979
+ }
980
+ const Ht = mt("APIError");
981
+ function Gt(e) {
982
+ const t = {};
983
+ for (const n in e.headers)
984
+ (n.startsWith("x-") || n.includes("trace") || n.includes("server") || /\b(?:id|uuid)\b/.test(n)) && (t[n] = e.headers[n]);
985
+ const s = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), r = e.status < 0 ? "unknown" : e.status;
986
+ return {
987
+ sentryError: new Ht(`${s} | ${r}${e.code ? ` | ${e.code}` : ""}`),
988
+ sentryTags: {
989
+ ...t,
990
+ status: r,
991
+ method: e.method,
992
+ code: e.code || "unknown",
993
+ message: e.message || "empty"
994
+ },
995
+ sentryExtra: {
996
+ url: e.url,
997
+ responseBody: e.body || "empty",
998
+ responseHeaders: e.headers,
999
+ rawError: e.error
1000
+ }
1001
+ };
1002
+ }
1003
+ function Kt(e) {
1004
+ return e.reduce(
1005
+ (t, [s, r]) => (s && (t[s] = r || ""), t),
1006
+ {}
1007
+ );
1008
+ }
1009
+ function te(e, t, s, r) {
1010
+ var y;
1011
+ const n = e.status, i = e.method, a = Kt(
1012
+ Object.entries(e.headers || {}).map(([k, w]) => [k.toLowerCase(), w])
1013
+ ), { ok: h, code: c, data: m, message: f } = Ct(
1014
+ n,
1015
+ e.statusText,
1016
+ e.body,
1017
+ s.get("responseRule"),
1018
+ r == null ? void 0 : r.responseRule
1019
+ );
1020
+ if (!X(n)) {
1021
+ const k = Gt({
1022
+ url: e.url,
1023
+ method: e.method,
1024
+ status: n,
1025
+ code: c,
1026
+ message: f,
1027
+ body: e.body,
1028
+ headers: a,
1029
+ error: e.rawError
1030
+ });
1031
+ (s.get("errorHandler") || zt)({
1032
+ url: t,
1033
+ method: i,
1034
+ status: n,
1035
+ code: c,
1036
+ message: f,
1037
+ headers: a,
1038
+ rawError: e.rawError,
1039
+ responseBody: e.body,
1040
+ ...k
1041
+ });
1042
+ }
1043
+ if (n < 0)
1044
+ return rt(
1045
+ { ok: !1, status: n, code: e.statusText, headers: {}, message: "", data: null },
1046
+ `${i} ${t} ${e.statusText}`,
1047
+ i,
1048
+ t,
1049
+ s,
1050
+ r
1051
+ );
1052
+ const d = { ok: h, data: m, code: c, message: f, status: n, headers: a };
1053
+ (y = s.get("responseHandler")) == null || y({ ...d }, i, t);
1054
+ const p = h ? f : f || e.statusText;
1055
+ return rt(d, p, i, t, s, r);
1056
+ }
1057
+ function rt(e, t, s, r, n, i) {
1058
+ const a = n.get("message"), h = a === !1 || (i == null ? void 0 : i.message) === !1 ? !1 : (i == null ? void 0 : i.message) || a;
1059
+ if (h !== !1) {
1060
+ const c = typeof h == "function" ? h(e, s, r, t) : t;
1061
+ c instanceof Error ? n.showMessage(!0, c.message, e.code, e.status) : c && typeof c == "object" && "message" in c ? n.showMessage(!1, c.message, e.code, e.status) : n.showMessage(!e.ok, c, e.code, e.status);
1062
+ }
1063
+ return e;
1064
+ }
1065
+ function zt(e) {
1066
+ const t = {};
1067
+ for (const s in e)
1068
+ s.startsWith("sentry") || (t[s] = e[s]);
1069
+ console.error("RequestError", t);
1070
+ }
1071
+ async function Vt(e, t, s, r, n) {
1072
+ const i = n || 0, a = Math.max(0, Math.min(10, (r == null ? void 0 : r.maxRetry) ?? s.get("maxRetry") ?? 0)), h = (r == null ? void 0 : r.retryResolve) ?? s.get("retryResolve"), c = s.get("logHandler") || D;
1073
+ c({
1074
+ type: "prepare",
1075
+ url: t,
1076
+ method: (r == null ? void 0 : r.method) || "GET",
1077
+ retry: i,
1078
+ maxRetry: a,
1079
+ message: i === 0 ? "start" : `retry ${i}/${a} start`,
1080
+ headers: r == null ? void 0 : r.headers,
1081
+ options: r
1082
+ });
1083
+ const m = Date.now(), f = await e(t, s, r), d = f.status, p = Date.now() - m, y = `[cost ${p}][${d}] ${d < 0 ? f.body : ""}`;
1084
+ c({
1085
+ type: "finished",
1086
+ url: t,
1087
+ method: f.method,
1088
+ retry: i,
1089
+ maxRetry: a,
1090
+ message: i === 0 ? `finish ${y}` : `retry ${i}/${a} finish ${y}`,
1091
+ response: f,
1092
+ headers: f.headers,
1093
+ cost: p
1094
+ });
1095
+ const k = X(d);
1096
+ if (!a || h === "network" && d > 0 || h === "status" && k || Array.isArray(h) && !h.includes(d) || typeof h == "function" && h(f, i) !== !0 || i >= a)
1097
+ return f;
1098
+ const w = (r == null ? void 0 : r.retryInterval) ?? s.get("retryInterval") ?? 100;
1099
+ return await _t(
1100
+ Math.max(
1101
+ 100,
1102
+ w === "2EB" ? Math.pow(2, i) * 100 : typeof w == "function" ? w(i + 1) || 0 : w
1103
+ )
1104
+ ), await Vt(e, t, s, r, i + 1);
1105
+ }
1106
+ export {
1107
+ I as $,
1108
+ Xt as N,
1109
+ j as O,
1110
+ Jt as Q,
1111
+ St as R,
1112
+ Q as a,
1113
+ Zt as c,
1114
+ Kt as f,
1115
+ Yt as g,
1116
+ te as h,
1117
+ Vt as r,
1118
+ Qt as u
1119
+ };