iboot-http-client 1.2.3 → 1.2.5

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.
@@ -1,8 +1,8 @@
1
- import N from "pino";
2
- import U from "pino-pretty";
3
- import M from "js-md5";
4
- import E from "crypto-js";
5
- const F = {
1
+ import R from "pino";
2
+ import B from "pino-pretty";
3
+ import U from "js-md5";
4
+ import I from "crypto-js";
5
+ const K = {
6
6
  GENERAL: 0,
7
7
  PHONE: 1,
8
8
  EMAIL: 2
@@ -10,7 +10,7 @@ const F = {
10
10
  TYPE_MGT: 0,
11
11
  TYPE_C: 1,
12
12
  TYPE_B: 2
13
- }, W = {
13
+ }, G = {
14
14
  FROM_WEB: 1,
15
15
  FROM_PC: 2,
16
16
  FROM_WX_MINI_PRO: 3,
@@ -18,132 +18,132 @@ const F = {
18
18
  FROM_WX_E: 5,
19
19
  FROM_APP: 6,
20
20
  FROM_DEVICE: 7
21
- }, G = {
21
+ }, F = {
22
22
  unknown: 0,
23
23
  male: 1,
24
24
  female: 2
25
- }, B = U({
25
+ }, M = B({
26
26
  colorize: !0,
27
27
  destination: process.stdout,
28
28
  translateTime: "SYS:yyyy-mm-dd HH:MM:ss",
29
29
  ignore: "pid,hostname",
30
30
  messageFormat: "{msg}",
31
31
  singleLine: !0
32
- }), d = N({
32
+ }), d = R({
33
33
  name: process.env.APP_NAME ?? "iBoot",
34
34
  level: process.env.APP_ENV === "production" ? "info" : "debug",
35
35
  nestedKey: "payload"
36
- }, B), O = (n) => Array.isArray(n) || typeof n == "object" && Object.prototype.toString.call(n) === "[object Array]", S = (n) => {
37
- const t = n || 32, e = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", r = e.length;
38
- let s = "";
39
- for (let o = 0; o < t; o++)
40
- s += e.charAt(Math.floor(Math.random() * r));
41
- return s;
42
- }, L = (n, t) => {
43
- const e = {};
44
- return n.split("&").forEach((s) => {
45
- const o = s.split("=");
46
- o[1] && (!t || t.indexOf(o[0]) == -1) && (e[o[0]] = o[1]);
47
- }), e;
48
- }, p = (n) => !n || n == "" || n.length == 0 ? "" : encodeURIComponent(n).replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\'/g, "%27").replace(/\!/g, "%21").replace(/\~/g, "%7E"), k = (n, t) => {
49
- const e = {
50
- "M+": n.getMonth() + 1,
36
+ }, M), O = (s) => Array.isArray(s) || typeof s == "object" && Object.prototype.toString.call(s) === "[object Array]", b = (s) => {
37
+ const e = s || 32, t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", n = t.length;
38
+ let r = "";
39
+ for (let o = 0; o < e; o++)
40
+ r += t.charAt(Math.floor(Math.random() * n));
41
+ return r;
42
+ }, L = (s, e) => {
43
+ const t = {};
44
+ return s.split("&").forEach((r) => {
45
+ const o = r.split("=");
46
+ o[1] && (!e || e.indexOf(o[0]) == -1) && (t[o[0]] = o[1]);
47
+ }), t;
48
+ }, T = (s) => !s || s == "" || s.length == 0 ? "" : encodeURIComponent(s).replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\'/g, "%27").replace(/\!/g, "%21").replace(/\~/g, "%7E"), k = (s, e) => {
49
+ const t = {
50
+ "M+": s.getMonth() + 1,
51
51
  //月份
52
- "d+": n.getDate(),
52
+ "d+": s.getDate(),
53
53
  //日
54
- "h+": n.getHours(),
54
+ "h+": s.getHours(),
55
55
  //小时
56
- "m+": n.getMinutes(),
56
+ "m+": s.getMinutes(),
57
57
  //分
58
- "s+": n.getSeconds(),
58
+ "s+": s.getSeconds(),
59
59
  //秒
60
- "q+": Math.floor((n.getMonth() + 3) / 3),
60
+ "q+": Math.floor((s.getMonth() + 3) / 3),
61
61
  //季度
62
- S: n.getMilliseconds()
62
+ S: s.getMilliseconds()
63
63
  //毫秒
64
64
  };
65
- if (/(y+)/.test(t)) {
66
- const s = new RegExp(/(y+)/).exec(t);
65
+ if (/(y+)/.test(e)) {
66
+ const r = new RegExp(/(y+)/).exec(e);
67
67
  let o = 0;
68
- s && s.length > 0 && (o = s[0].length), t = t.replace(/(y+)/, n.getFullYear() + "").substring(4 - o);
68
+ r && r.length > 0 && (o = r[0].length), e = e.replace(/(y+)/, s.getFullYear() + "").substring(4 - o);
69
69
  }
70
- for (const r in e) {
71
- const s = "(" + r + ")", o = new RegExp(s);
72
- if (o.test(t)) {
73
- const i = o.exec(t);
70
+ for (const n in t) {
71
+ const r = "(" + n + ")", o = new RegExp(r);
72
+ if (o.test(e)) {
73
+ const i = o.exec(e);
74
74
  let a = 0;
75
- i && i.length > 0 && (a = i[0].length), t = t.replace(o, a == 1 ? e[r].toString() : ("00" + e[r]).substring(e[r].toString().length));
75
+ i && i.length > 0 && (a = i[0].length), e = e.replace(o, a == 1 ? t[n].toString() : ("00" + t[n]).substring(t[n].toString().length));
76
76
  }
77
77
  }
78
- return t;
79
- }, j = "zh-CN", I = "_device_id_key", P = "_current_website_key", _ = "Get request error!", T = "Post request error!", m = {
78
+ return e;
79
+ }, D = "zh-CN", S = "_device_id_key", P = "_current_website_key", _ = "Get request error!", w = "Post request error!", f = {
80
80
  IBOOT_DEVICE_ID: "dvid",
81
81
  IBOOT_LANG: "lang",
82
82
  IBOOT_WEBSITE_ID: "wid",
83
83
  IBOOT_WEBSITE_NO: "wno",
84
84
  IBOOT_TOKEN: "token",
85
85
  IBOOT_USER: "user"
86
- }, y = {
86
+ }, m = {
87
87
  DEVICE_ID: "Device-Id",
88
88
  LANG: "Lang",
89
89
  WEBSITE_ID: "Website-Id",
90
90
  WEBSITE_NO: "Website-No"
91
- }, R = (n) => {
92
- if (!n.get)
91
+ }, N = (s) => {
92
+ if (!s.get)
93
93
  throw new Error("The get method of IStorage has not been implemented.");
94
- const t = n.get(I) ?? "", e = n.get(P), r = e != null ? JSON.parse(e) : null, s = {};
95
- return t.length > 0 && (s["Device-Id"] = t), r && (s.Lang = r.language, r.websiteId && (s["Website-Id"] = r.websiteId), r.websiteNo && (s["Website-No"] = r.websiteNo)), s;
96
- }, Y = ({ deviceId: n, website: t }, e) => {
97
- if (!e.set)
94
+ const e = s.get(S) ?? "", t = s.get(P), n = t != null ? JSON.parse(t) : null, r = {};
95
+ return e.length > 0 && (r["Device-Id"] = e), n && (r.Lang = n.language, n.websiteId && (r["Website-Id"] = n.websiteId), n.websiteNo && (r["Website-No"] = n.websiteNo)), r;
96
+ }, V = ({ deviceId: s, website: e }, t) => {
97
+ if (!t.set)
98
98
  throw new Error("The set method of IStorage has not been implemented.");
99
- e.set(I, n), t && e.set(P, JSON.stringify(t));
100
- }, $ = async (n, t) => {
101
- if (t?.data) {
102
- const i = new URLSearchParams(t.data);
103
- n.indexOf("?") != -1 ? n += `&${i}` : n += `?${i}`;
99
+ t.set(S, s), e && t.set(P, JSON.stringify(e));
100
+ }, H = async (s, e) => {
101
+ if (e?.data) {
102
+ const i = new URLSearchParams(e.data);
103
+ s.indexOf("?") != -1 ? s += `&${i}` : s += `?${i}`;
104
104
  }
105
- const e = t && t.storage && t.storage.get ? R(t.storage) : {}, r = t?.headers;
106
- if (r)
107
- for (const i in r) {
108
- const a = r[i];
109
- a && (e[i] = a);
105
+ const t = e && e.storage && e.storage.get ? N(e.storage) : {}, n = e?.headers;
106
+ if (n)
107
+ for (const i in n) {
108
+ const a = n[i];
109
+ a && (t[i] = a);
110
110
  }
111
111
  d.info({
112
- url: n,
113
- headers: e
112
+ url: s,
113
+ headers: t
114
114
  }, "GET");
115
- const s = await fetch(n, {
115
+ const r = await fetch(s, {
116
116
  method: "GET",
117
- headers: e,
118
- cache: t?.useCache ? "force-cache" : "default"
117
+ headers: t,
118
+ cache: e?.useCache ? "force-cache" : "default"
119
119
  });
120
- if (s.ok) {
121
- const i = Object.fromEntries(s.headers.entries()), a = { ...await s.json(), headers: i };
120
+ if (r.ok) {
121
+ const i = Object.fromEntries(r.headers.entries()), a = { ...await r.json(), headers: i };
122
122
  return d.debug(a, "GET_RESULT"), a;
123
123
  }
124
124
  const o = {
125
- code: s.status,
125
+ code: r.status,
126
126
  success: !1,
127
- msg: s.statusText
127
+ msg: r.statusText
128
128
  };
129
129
  return d.error(o), o;
130
- }, A = async (n, t) => {
131
- const e = t?.data ?? {}, r = t?.headers;
132
- let s;
133
- const o = t && t.storage && t.storage.get ? R(t.storage) : {}, i = new Headers(o);
134
- if (e instanceof FormData ? s = e : (s = JSON.stringify(e), i.set("Content-Type", "application/json")), r)
135
- for (let l in r) {
136
- const h = r[l];
130
+ }, v = async (s, e) => {
131
+ const t = e?.data ?? {}, n = e?.headers;
132
+ let r;
133
+ const o = e && e.storage && e.storage.get ? N(e.storage) : {}, i = new Headers(o);
134
+ if (t instanceof FormData ? r = t : (r = JSON.stringify(t), i.set("Content-Type", "application/json")), n)
135
+ for (let l in n) {
136
+ const h = n[l];
137
137
  h && i.set(l, h);
138
138
  }
139
139
  d.info({
140
- url: n,
140
+ url: s,
141
141
  headers: i
142
142
  }, "POST");
143
- const a = await fetch(n, {
143
+ const a = await fetch(s, {
144
144
  method: "POST",
145
145
  headers: i,
146
- body: s
146
+ body: r
147
147
  });
148
148
  if (a.ok) {
149
149
  const l = Object.fromEntries(a.headers.entries()), h = { ...await a.json(), headers: l };
@@ -155,58 +155,68 @@ const F = {
155
155
  msg: a.statusText
156
156
  };
157
157
  return d.error(c), c;
158
- }, J = async (n, t) => {
159
- const e = await $(n, t);
160
- if (e.success)
161
- return e.data;
162
- if (t?.showError) {
163
- t.showError(e.msg ?? _);
158
+ }, Y = async (s, e) => {
159
+ const t = await H(s, e);
160
+ if (t.success)
161
+ return t.data;
162
+ if (e?.showError) {
163
+ e.showError(t.msg ?? _);
164
164
  return;
165
165
  }
166
- throw Error(e.msg ?? _);
167
- }, V = async (n, t) => {
168
- const e = await A(n, t);
169
- if (e.success)
170
- return e.data;
171
- if (t?.showError) {
172
- t.showError(e.msg ?? T);
166
+ throw Error(t.msg ?? _);
167
+ }, J = async (s, e) => {
168
+ const t = await v(s, e);
169
+ if (t.success)
170
+ return t.data;
171
+ if (e?.showError) {
172
+ e.showError(t.msg ?? w);
173
173
  return;
174
174
  }
175
- throw Error(e.msg ?? T);
176
- }, X = async (n, t) => {
177
- const e = await A(n, t);
178
- return e.success ? (t?.showSuccess && t.showSuccess(e.msg ?? "SUCCESS"), !0) : (t?.showError && t.showError(e.msg ?? T), !1);
179
- }, q = (n) => {
180
- if (n.get) {
181
- const t = n.get(y.DEVICE_ID), e = n.get(y.LANG), r = n.get(y.WEBSITE_ID), s = n.get(y.WEBSITE_NO), o = {};
182
- return t && t.length > 0 && (o.deviceId = t), e && e.length > 0 && (o.lang = e), r && r.length > 0 && (o.websiteId = r), s && s.length > 0 && (o.websiteNo = s), o;
175
+ throw Error(t.msg ?? w);
176
+ }, X = async (s, e) => {
177
+ const t = await v(s, e);
178
+ return t.success ? (e?.showSuccess && e.showSuccess(t.msg ?? "SUCCESS"), !0) : (e?.showError && e.showError(t.msg ?? w), !1);
179
+ }, q = (s) => {
180
+ if (s.get) {
181
+ const e = s.get(m.DEVICE_ID), t = s.get(m.LANG), n = s.get(m.WEBSITE_ID), r = s.get(m.WEBSITE_NO), o = {};
182
+ return e && e.length > 0 && (o.deviceId = e), t && t.length > 0 && (o.lang = t), n && n.length > 0 && (o.websiteId = n), r && r.length > 0 && (o.websiteNo = r), o;
183
183
  }
184
- throw new Error("The set method of IStorage has not been implemented.");
185
- }, z = (n) => {
186
- if (n.get) {
187
- const t = n.get(m.IBOOT_USER);
188
- if (t && t.length > 0)
189
- return JSON.parse(t);
184
+ throw new Error("The get method of IStorage has not been implemented.");
185
+ }, z = (s, e) => {
186
+ throw s.set && (e.deviceId && s.set(m.DEVICE_ID, e.deviceId), e.lang && s.set(m.LANG, e.lang), e.websiteId && s.set(m.WEBSITE_ID, e.websiteId), e.websiteNo && s.set(m.WEBSITE_NO, e.websiteNo)), new Error("The set method of IStorage has not been implemented.");
187
+ }, Q = (s) => {
188
+ if (s.get) {
189
+ const e = s.get(f.IBOOT_DEVICE_ID), t = s.get(f.IBOOT_LANG), n = s.get(f.IBOOT_WEBSITE_ID), r = s.get(f.IBOOT_WEBSITE_NO), o = {};
190
+ return e && e.length > 0 && (o.deviceId = e), t && t.length > 0 && (o.lang = t), n && n.length > 0 && (o.websiteId = n), r && r.length > 0 && (o.websiteNo = r), o;
190
191
  }
191
- }, Q = (n) => {
192
- if (n.get) {
193
- const t = n.get(m.IBOOT_USER);
194
- if (t && t.length > 0) {
195
- const e = JSON.parse(t), r = e.username, s = e.userType.toString(), o = n.get(m.IBOOT_TOKEN);
192
+ throw new Error("The get method of ICookies has not been implemented.");
193
+ }, Z = (s, e) => {
194
+ throw s.set && (e.deviceId && s.set(f.IBOOT_DEVICE_ID, e.deviceId), e.lang && s.set(f.IBOOT_LANG, e.lang), e.websiteId && s.set(f.IBOOT_WEBSITE_ID, e.websiteId), e.websiteNo && s.set(f.IBOOT_WEBSITE_NO, e.websiteNo)), new Error("The set method of ICookies has not been implemented.");
195
+ }, ee = (s) => {
196
+ if (s.get) {
197
+ const e = s.get(f.IBOOT_USER);
198
+ if (e && e.length > 0)
199
+ return JSON.parse(e);
200
+ }
201
+ }, te = (s) => {
202
+ if (s.get) {
203
+ const e = s.get(f.IBOOT_USER);
204
+ if (e && e.length > 0) {
205
+ const t = JSON.parse(e), n = t.username, r = t.userType.toString(), o = s.get(f.IBOOT_TOKEN);
196
206
  if (o)
197
207
  return {
198
- username: r,
199
- utype: s,
208
+ username: n,
209
+ utype: r,
200
210
  token: o
201
211
  };
202
212
  }
203
213
  }
204
- }, Z = (n, t) => {
205
- const { id: e, name: r, username: s, nickname: o, headImg: i, token: a, lastLoginTime: c, deviceId: l, userType: h, mustChangePwd: g } = n, u = {
206
- id: e,
207
- name: r,
208
- username: s,
209
- nickname: o || r,
214
+ }, se = (s, e) => {
215
+ const { id: t, name: n, username: r, nickname: o, headImg: i, token: a, lastLoginTime: c, deviceId: l, userType: h, mustChangePwd: E } = s, u = {
216
+ id: t,
217
+ name: n,
218
+ username: r,
219
+ nickname: o || n,
210
220
  headImg: i,
211
221
  lastLoginTime: c,
212
222
  deviceId: l,
@@ -214,34 +224,34 @@ const F = {
214
224
  accountType: 0,
215
225
  needToReview: !1,
216
226
  socketOnline: !1,
217
- mustChangePwd: g
227
+ mustChangePwd: E
218
228
  };
219
- if (!t.set)
229
+ if (!e.set)
220
230
  throw new Error("cookies set function is undefined");
221
- t.set(m.IBOOT_TOKEN, a, {
231
+ e.set(f.IBOOT_TOKEN, a, {
222
232
  path: "/",
223
233
  secure: process.env.APP_ENV === "production",
224
234
  httpOnly: !0,
225
235
  sameSite: "strict"
226
- }), t.set(m.IBOOT_USER, JSON.stringify(u));
227
- }, ee = (n) => {
228
- if (!n.set)
236
+ }), e.set(f.IBOOT_USER, JSON.stringify(u));
237
+ }, re = (s) => {
238
+ if (!s.set)
229
239
  throw new Error("cookies set function is undefined");
230
- if (n.set(m.IBOOT_TOKEN, "", {
240
+ if (s.set(f.IBOOT_TOKEN, "", {
231
241
  maxAge: -1,
232
242
  //设置为 -1表示立即过期
233
243
  httpOnly: !0,
234
244
  path: "/"
235
- }), n.set(m.IBOOT_USER, "", {
245
+ }), s.set(f.IBOOT_USER, "", {
236
246
  maxAge: -1,
237
247
  //设置为 -1表示立即过期
238
248
  httpOnly: !0,
239
249
  path: "/"
240
- }), !n.delete)
250
+ }), !s.delete)
241
251
  throw new Error("cookies delete function is undefined");
242
- n.delete(m.IBOOT_TOKEN), n.delete(m.IBOOT_USER);
252
+ s.delete(f.IBOOT_TOKEN), s.delete(f.IBOOT_USER);
243
253
  };
244
- class te {
254
+ class ne {
245
255
  baseUrl;
246
256
  helloMethod;
247
257
  apiKey;
@@ -252,141 +262,141 @@ class te {
252
262
  lang;
253
263
  websiteId;
254
264
  websiteNo;
255
- constructor(t) {
256
- process.env.APP_ENV === "production" || d.warn("This is currently a development environment!"), this.baseUrl = process.env.APP_BASEURL, this.apiKey = process.env.APP_APIKEY, this.userFrom = process.env.APP_USERFROM ?? "1", this.helloMethod = t.helloURL ?? "", this.userType = t.userType ?? C.TYPE_MGT, this.deviceId = t.deviceId ?? S(10), this.lang = t.lang ?? j, this.websiteId = t.websiteId, this.websiteNo = t.websiteNo;
265
+ constructor(e) {
266
+ process.env.APP_ENV === "production" || d.warn("This is currently a development environment!"), this.baseUrl = process.env.APP_BASEURL, this.apiKey = process.env.APP_APIKEY, this.userFrom = process.env.APP_USERFROM ?? "1", this.helloMethod = e.helloURL ?? "", this.userType = e.userType ?? C.TYPE_MGT, this.deviceId = e.deviceId ?? b(10), this.lang = e.lang ?? D, this.websiteId = e.websiteId, this.websiteNo = e.websiteNo;
257
267
  }
258
- encrypt(t) {
259
- const e = E.enc.Utf8.parse(this.apiKey);
260
- return E.AES.encrypt(t, e).toString();
268
+ encrypt(e) {
269
+ const t = I.enc.Utf8.parse(this.apiKey);
270
+ return I.AES.encrypt(e, t).toString();
261
271
  }
262
- decrypt(t) {
263
- const e = E.enc.Utf8.parse(this.apiKey);
264
- return E.AES.decrypt(t, e, {
265
- mode: E.mode.ECB
266
- }).toString(E.enc.Utf8);
272
+ decrypt(e) {
273
+ const t = I.enc.Utf8.parse(this.apiKey);
274
+ return I.AES.decrypt(e, t, {
275
+ mode: I.mode.ECB
276
+ }).toString(I.enc.Utf8);
267
277
  }
268
278
  //eslint-disable-next-line @typescript-eslint/no-explicit-any
269
- convertUrlParameter(t) {
270
- const e = [];
271
- for (const r in t) {
272
- let s = t[r];
273
- if (s && typeof s == "string")
274
- s = s.trim();
275
- else if (s && typeof s == "object") {
276
- if (O(s)) {
277
- if (s.length === 0)
279
+ convertUrlParameter(e) {
280
+ const t = [];
281
+ for (const n in e) {
282
+ let r = e[n];
283
+ if (r && typeof r == "string")
284
+ r = r.trim();
285
+ else if (r && typeof r == "object") {
286
+ if (O(r)) {
287
+ if (r.length === 0)
278
288
  continue;
279
- for (let o = 0; o < s.length; o++) {
280
- const i = s[o];
289
+ for (let o = 0; o < r.length; o++) {
290
+ const i = r[o];
281
291
  for (const a in i) {
282
292
  const c = i[a] ?? void 0;
283
293
  if (c) {
284
294
  if (typeof c == "object")
285
295
  O(c) && c.forEach((l, h) => {
286
296
  if (l)
287
- for (const g in l) {
288
- const u = l[g];
297
+ for (const E in l) {
298
+ const u = l[E];
289
299
  if (u && u.toString().length > 0) {
290
- const f = `[${o.toString()}].${a + `[${h.toString()}].${g}`}=${p(u)}`;
291
- e.push(r + f);
300
+ const g = `[${o.toString()}].${a + `[${h.toString()}].${E}`}=${T(u)}`;
301
+ t.push(n + g);
292
302
  }
293
303
  }
294
304
  });
295
305
  else if (c.toString().length > 0) {
296
- const l = `[${o.toString()}].${a}=${p(c.toString())}`;
297
- e.push(r + l);
306
+ const l = `[${o.toString()}].${a}=${T(c.toString())}`;
307
+ t.push(n + l);
298
308
  }
299
309
  }
300
310
  }
301
311
  }
302
312
  } else
303
- for (const o in s) {
304
- const i = s[o];
313
+ for (const o in r) {
314
+ const i = r[o];
305
315
  if (i != null && i != "" && i.length != 0) {
306
- const a = `.${o}=${p(i)}`;
307
- e.push(r + a);
316
+ const a = `.${o}=${T(i)}`;
317
+ t.push(n + a);
308
318
  }
309
319
  }
310
320
  continue;
311
- } else s && typeof s == "function" && (s = null);
312
- s != null && s != "" && s.length != 0 && e.push(r + "=" + p(s));
321
+ } else r && typeof r == "function" && (r = null);
322
+ r != null && r != "" && r.length != 0 && t.push(n + "=" + T(r));
313
323
  }
314
- return e && e.join("&");
324
+ return t && t.join("&");
315
325
  }
316
- async sign(t) {
317
- const e = "&key=" + await this.helloIboot(), r = [];
318
- for (const c in t)
319
- r.push(c);
320
- r.sort((c, l) => c.toLowerCase().localeCompare(l.toLowerCase()));
321
- const s = [];
322
- r.forEach((c) => {
323
- let l = t[c];
324
- typeof l == "object" && (l = JSON.stringify(l)), s.push(c + "=" + l);
326
+ async sign(e) {
327
+ const t = "&key=" + await this.helloIboot(), n = [];
328
+ for (const c in e)
329
+ n.push(c);
330
+ n.sort((c, l) => c.toLowerCase().localeCompare(l.toLowerCase()));
331
+ const r = [];
332
+ n.forEach((c) => {
333
+ let l = e[c];
334
+ typeof l == "object" && (l = JSON.stringify(l)), r.push(c + "=" + l);
325
335
  });
326
- const o = s.join("&"), i = M.md5((o + e).toLocaleUpperCase()), a = {
336
+ const o = r.join("&"), i = U.md5((o + t).toLocaleUpperCase()), a = {
327
337
  params: o,
328
338
  md5: i
329
339
  };
330
340
  return d.debug(a, "API_SIGN"), i;
331
341
  }
332
342
  //eslint-disable-next-line @typescript-eslint/no-explicit-any
333
- assemblyParameter(t, e) {
334
- const r = t ?? {};
335
- return r.timestamp = Date.now() + "", r.echostr = S(10), r.version = this.version, r.deviceId = this.deviceId, r.webid = this.websiteId, r.apiKey = this.apiKey, e && e.length > 0 && (r.username = e), r;
343
+ assemblyParameter(e, t) {
344
+ const n = e ?? {};
345
+ return n.timestamp = Date.now() + "", n.echostr = b(10), n.version = this.version, n.deviceId = this.deviceId, n.webid = this.websiteId, n.apiKey = this.apiKey, t && t.length > 0 && (n.username = t), n;
336
346
  }
337
- async assemblyHeader({ urlParams: t, token: e }) {
338
- const r = {
347
+ async assemblyHeader({ urlParams: e, token: t }) {
348
+ const n = {
339
349
  "Content-Type": "application/x-www-form-urlencoded",
340
350
  "Res-Type": "json",
341
351
  "Device-Id": this.deviceId,
342
- "User-Type": e?.utype.toString() ?? this.userType.toString(),
352
+ "User-Type": t?.utype.toString() ?? this.userType.toString(),
343
353
  "User-From": this.userFrom,
344
354
  "Api-Key": this.apiKey
345
355
  };
346
- this.lang && this.lang.length > 0 && (r.Lang = this.lang), this.websiteId && this.websiteId.length > 0 && (r["Web-Id"] = this.websiteId), this.websiteNo && this.websiteNo.length > 0 && (r["Web-No"] = this.websiteNo), e && (e.token && e.token.length > 0 && e.username && e.username.length > 0 && (r.Authorization = e.token, r.Username = e.username), e.xcsrf && (r[e.xcsrf.csrfHeader] = e.xcsrf.csrfToken));
347
- const s = L(t), o = await this.sign(s);
348
- return r.Sign = o, r;
356
+ this.lang && this.lang.length > 0 && (n.Lang = this.lang), this.websiteId && this.websiteId.length > 0 && (n["Web-Id"] = this.websiteId), this.websiteNo && this.websiteNo.length > 0 && (n["Web-No"] = this.websiteNo), t && (t.token && t.token.length > 0 && t.username && t.username.length > 0 && (n.Authorization = t.token, n.Username = t.username), t.xcsrf && (n[t.xcsrf.csrfHeader] = t.xcsrf.csrfToken));
357
+ const r = L(e), o = await this.sign(r);
358
+ return n.Sign = o, n;
349
359
  }
350
360
  async helloIboot() {
351
361
  if (this.helloMethod.length <= 0)
352
362
  return this.apiKey;
353
- const t = this.getApiUrl(this.helloMethod), e = {
363
+ const e = this.getApiUrl(this.helloMethod), t = {
354
364
  "Content-Type": "application/x-www-form-urlencoded",
355
365
  "Res-Type": "json",
356
366
  "Api-Key": this.apiKey
357
- }, r = {
358
- url: t,
359
- headers: e
367
+ }, n = {
368
+ url: e,
369
+ headers: t
360
370
  };
361
- d.debug(r, "HELLO");
362
- const s = await fetch(t, {
371
+ d.debug(n, "HELLO");
372
+ const r = await fetch(e, {
363
373
  method: "GET",
364
- headers: e,
374
+ headers: t,
365
375
  credentials: "include",
366
376
  cache: "force-cache"
367
377
  });
368
- if (s.ok) {
369
- const o = await s.json();
378
+ if (r.ok) {
379
+ const o = await r.json();
370
380
  return d.debug(o.data, "HELLO RESULT"), o.data;
371
381
  }
372
382
  throw new Error("hello iBoot error!");
373
383
  }
374
- getApiUrl(t) {
375
- return `${this.baseUrl}/${t}`;
384
+ getApiUrl(e) {
385
+ return `${this.baseUrl}/${e}`;
376
386
  }
377
387
  async csrf() {
378
- const t = await this.get({
388
+ const e = await this.get({
379
389
  url: "guest/csrf"
380
390
  });
381
- if (t.success) {
382
- const e = t.data;
383
- if (e)
384
- return e.csrfToken.toString();
391
+ if (e.success) {
392
+ const t = e.data;
393
+ if (t)
394
+ return t.csrfToken.toString();
385
395
  }
386
396
  }
387
397
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
388
- async get({ url: t, data: e, token: r, cache: s = "default" }) {
389
- const o = this.assemblyParameter(e), i = this.convertUrlParameter(o), a = await this.assemblyHeader({ urlParams: i, token: r }), c = `${this.getApiUrl(t)}?${i.toString()}`, l = {
398
+ async get({ url: e, data: t, token: n, cache: r = "default" }) {
399
+ const o = this.assemblyParameter(t), i = this.convertUrlParameter(o), a = await this.assemblyHeader({ urlParams: i, token: n }), c = `${this.getApiUrl(e)}?${i.toString()}`, l = {
390
400
  url: c,
391
401
  headers: a
392
402
  };
@@ -395,78 +405,78 @@ class te {
395
405
  method: "GET",
396
406
  headers: a,
397
407
  credentials: "include",
398
- cache: s
408
+ cache: r
399
409
  });
400
410
  if (h.ok) {
401
- const u = Object.fromEntries(h.headers.entries()), f = { ...await h.json(), headers: u };
402
- return d.debug(f, "GET_RESULT"), f;
411
+ const u = Object.fromEntries(h.headers.entries()), g = { ...await h.json(), headers: u };
412
+ return d.debug(g, "GET_RESULT"), g;
403
413
  }
404
- const g = {
414
+ const E = {
405
415
  code: h.status,
406
416
  success: !1,
407
417
  msg: h.statusText
408
418
  };
409
- return d.error(g), g;
419
+ return d.error(E), E;
410
420
  }
411
421
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
412
- async post({ url: t, data: e, token: r, cache: s = "default" }) {
413
- e = e ? { ...e } : {};
414
- const o = e.buffer ?? void 0, i = e.boundary ?? void 0;
415
- o && delete e.buffer, i && delete e.boundary;
416
- const a = this.assemblyParameter(e), c = this.convertUrlParameter(a), l = await this.assemblyHeader({ urlParams: c, token: r });
422
+ async post({ url: e, data: t, token: n, cache: r = "default" }) {
423
+ t = t ? { ...t } : {};
424
+ const o = t.buffer ?? void 0, i = t.boundary ?? void 0;
425
+ o && delete t.buffer, i && delete t.boundary;
426
+ const a = this.assemblyParameter(t), c = this.convertUrlParameter(a), l = await this.assemblyHeader({ urlParams: c, token: n });
417
427
  o && i && (l["Content-Type"] = `multipart/form-data; boundary=${i}`);
418
- const h = this.getApiUrl(t), g = {
428
+ const h = this.getApiUrl(e), E = {
419
429
  url: h,
420
430
  headers: l,
421
431
  params: a
422
432
  };
423
- d.info(g, "POST");
424
- const u = o ? `${h}?${c}` : h, f = await fetch(u, {
433
+ d.info(E, "POST");
434
+ const u = o ? `${h}?${c}` : h, g = await fetch(u, {
425
435
  method: "POST",
426
436
  headers: l,
427
437
  body: o || c.toString(),
428
438
  credentials: "include",
429
- cache: s
439
+ cache: r
430
440
  });
431
- if (f.ok) {
432
- const v = Object.fromEntries(f.headers.entries()), b = { ...await f.json(), headers: v };
433
- return d.debug(b, "POST_RESULT"), b;
441
+ if (g.ok) {
442
+ const A = Object.fromEntries(g.headers.entries()), y = { ...await g.json(), headers: A };
443
+ return d.debug(y, "POST_RESULT"), y;
434
444
  }
435
- const w = {
436
- code: f.status,
445
+ const p = {
446
+ code: g.status,
437
447
  success: !1,
438
- msg: f.statusText
448
+ msg: g.statusText
439
449
  };
440
- return d.error(w), w;
450
+ return d.error(p), p;
441
451
  }
442
452
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
443
- async stream({ url: t, data: e, token: r }) {
444
- e = e ? { ...e } : {};
445
- const s = e.buffer ?? void 0, o = e.boundary ?? void 0;
446
- s && delete e.buffer, o && delete e.boundary;
447
- const i = this.assemblyParameter(e), a = this.convertUrlParameter(i), c = await this.assemblyHeader({ urlParams: a, token: r });
448
- s && o && (c["Content-Type"] = `multipart/form-data; boundary=${o}`), c.Connection = "keep-alive", c["X-Accel-Buffering"] = "no", c["Cache-Control"] = "no-cache";
449
- const l = this.getApiUrl(t);
453
+ async stream({ url: e, data: t, token: n }) {
454
+ t = t ? { ...t } : {};
455
+ const r = t.buffer ?? void 0, o = t.boundary ?? void 0;
456
+ r && delete t.buffer, o && delete t.boundary;
457
+ const i = this.assemblyParameter(t), a = this.convertUrlParameter(i), c = await this.assemblyHeader({ urlParams: a, token: n });
458
+ r && o && (c["Content-Type"] = `multipart/form-data; boundary=${o}`), c.Connection = "keep-alive", c["X-Accel-Buffering"] = "no", c["Cache-Control"] = "no-cache";
459
+ const l = this.getApiUrl(e);
450
460
  try {
451
- const h = s ? `${l}?${a}` : l, g = {
461
+ const h = r ? `${l}?${a}` : l, E = {
452
462
  url: l,
453
463
  headers: c,
454
464
  params: i
455
465
  };
456
- d.info(g, "STREAM");
466
+ d.info(E, "STREAM");
457
467
  const u = await fetch(h, {
458
468
  method: "POST",
459
469
  headers: c,
460
- body: s || a.toString(),
470
+ body: r || a.toString(),
461
471
  credentials: "include"
462
472
  });
463
473
  if (!u.ok)
464
474
  throw new Error(`HTTP error! status: ${u.status}`);
465
475
  if (!u.body)
466
476
  throw new Error("No response body");
467
- const f = Object.fromEntries(u.headers.entries());
477
+ const g = Object.fromEntries(u.headers.entries());
468
478
  return new Response(u.body, {
469
- headers: f
479
+ headers: g
470
480
  });
471
481
  } catch (h) {
472
482
  throw h;
@@ -474,32 +484,30 @@ class te {
474
484
  }
475
485
  }
476
486
  export {
477
- F as ACCOUNT_TYPE_MAP,
478
- m as COOKIE_NAMES,
479
- P as CURRENT_WEBSITE_KEY,
480
- j as DEFAULT_LOCALE,
481
- I as DEVICE_ID_KEY,
482
- y as HEADER_NAMES,
483
- te as HttpClient,
484
- W as USER_FORM_MAP,
485
- G as USER_SEX_MAP,
487
+ K as ACCOUNT_TYPE_MAP,
488
+ ne as HttpClient,
489
+ G as USER_FORM_MAP,
490
+ F as USER_SEX_MAP,
486
491
  C as USER_TYPE_MAP,
487
- ee as cleanToken,
492
+ re as cleanToken,
488
493
  k as dateFormat,
489
- $ as get,
490
- q as getHttpOpts,
491
- z as getLoginUser,
492
- Q as getToken,
493
- J as iGet,
494
- V as iPost,
494
+ H as get,
495
+ Q as getHttpOptsByCookies,
496
+ ee as getLoginUser,
497
+ q as getServerHttpOpts,
498
+ te as getToken,
499
+ Y as iGet,
500
+ J as iPost,
495
501
  X as iPostSuccess,
496
502
  O as isArray,
497
503
  d as logger,
498
- A as post,
499
- S as randomString,
500
- Y as setDefaultRequestHeader,
501
- Z as setToken,
502
- p as urlEncode,
504
+ v as post,
505
+ b as randomString,
506
+ V as setClientRequestHeader,
507
+ Z as setServerHttpCookies,
508
+ z as setServerHttpHeaders,
509
+ se as setToken,
510
+ T as urlEncode,
503
511
  L as urlParamToJson
504
512
  };
505
513
  //# sourceMappingURL=iboot-http-client.es.js.map