iboot-http-client 1.2.4 → 1.2.6

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";
1
+ import R from "pino";
2
2
  import U from "pino-pretty";
3
- import M from "js-md5";
4
- import E from "crypto-js";
5
- const F = {
3
+ import B 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 = U({
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,74 @@ 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
+ if (s.set)
187
+ 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);
188
+ else
189
+ throw new Error("The set method of IStorage has not been implemented.");
190
+ }, Q = (s) => {
191
+ if (s.get) {
192
+ 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 = {};
193
+ 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;
194
+ }
195
+ throw new Error("The get method of ICookies has not been implemented.");
196
+ }, Z = (s, e) => {
197
+ if (s.set)
198
+ 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);
199
+ else
200
+ throw new Error("The set method of ICookies has not been implemented.");
201
+ }, ee = (s) => {
202
+ if (s.get) {
203
+ const e = s.get(f.IBOOT_USER);
204
+ if (e && e.length > 0)
205
+ return JSON.parse(e);
190
206
  }
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);
207
+ }, te = (s) => {
208
+ if (s.get) {
209
+ const e = s.get(f.IBOOT_USER);
210
+ if (e && e.length > 0) {
211
+ const t = JSON.parse(e), n = t.username, r = t.userType.toString(), o = s.get(f.IBOOT_TOKEN);
196
212
  if (o)
197
213
  return {
198
- username: r,
199
- utype: s,
214
+ username: n,
215
+ utype: r,
200
216
  token: o
201
217
  };
202
218
  }
203
219
  }
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,
220
+ }, se = (s, e) => {
221
+ const { id: t, name: n, username: r, nickname: o, headImg: i, token: a, lastLoginTime: c, deviceId: l, userType: h, mustChangePwd: E } = s, u = {
222
+ id: t,
223
+ name: n,
224
+ username: r,
225
+ nickname: o || n,
210
226
  headImg: i,
211
227
  lastLoginTime: c,
212
228
  deviceId: l,
@@ -214,34 +230,34 @@ const F = {
214
230
  accountType: 0,
215
231
  needToReview: !1,
216
232
  socketOnline: !1,
217
- mustChangePwd: g
233
+ mustChangePwd: E
218
234
  };
219
- if (!t.set)
235
+ if (!e.set)
220
236
  throw new Error("cookies set function is undefined");
221
- t.set(m.IBOOT_TOKEN, a, {
237
+ e.set(f.IBOOT_TOKEN, a, {
222
238
  path: "/",
223
239
  secure: process.env.APP_ENV === "production",
224
240
  httpOnly: !0,
225
241
  sameSite: "strict"
226
- }), t.set(m.IBOOT_USER, JSON.stringify(u));
227
- }, ee = (n) => {
228
- if (!n.set)
242
+ }), e.set(f.IBOOT_USER, JSON.stringify(u));
243
+ }, re = (s) => {
244
+ if (!s.set)
229
245
  throw new Error("cookies set function is undefined");
230
- if (n.set(m.IBOOT_TOKEN, "", {
246
+ if (s.set(f.IBOOT_TOKEN, "", {
231
247
  maxAge: -1,
232
248
  //设置为 -1表示立即过期
233
249
  httpOnly: !0,
234
250
  path: "/"
235
- }), n.set(m.IBOOT_USER, "", {
251
+ }), s.set(f.IBOOT_USER, "", {
236
252
  maxAge: -1,
237
253
  //设置为 -1表示立即过期
238
254
  httpOnly: !0,
239
255
  path: "/"
240
- }), !n.delete)
256
+ }), !s.delete)
241
257
  throw new Error("cookies delete function is undefined");
242
- n.delete(m.IBOOT_TOKEN), n.delete(m.IBOOT_USER);
258
+ s.delete(f.IBOOT_TOKEN), s.delete(f.IBOOT_USER);
243
259
  };
244
- class te {
260
+ class ne {
245
261
  baseUrl;
246
262
  helloMethod;
247
263
  apiKey;
@@ -252,141 +268,141 @@ class te {
252
268
  lang;
253
269
  websiteId;
254
270
  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;
271
+ constructor(e) {
272
+ 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
273
  }
258
- encrypt(t) {
259
- const e = E.enc.Utf8.parse(this.apiKey);
260
- return E.AES.encrypt(t, e).toString();
274
+ encrypt(e) {
275
+ const t = I.enc.Utf8.parse(this.apiKey);
276
+ return I.AES.encrypt(e, t).toString();
261
277
  }
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);
278
+ decrypt(e) {
279
+ const t = I.enc.Utf8.parse(this.apiKey);
280
+ return I.AES.decrypt(e, t, {
281
+ mode: I.mode.ECB
282
+ }).toString(I.enc.Utf8);
267
283
  }
268
284
  //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)
285
+ convertUrlParameter(e) {
286
+ const t = [];
287
+ for (const n in e) {
288
+ let r = e[n];
289
+ if (r && typeof r == "string")
290
+ r = r.trim();
291
+ else if (r && typeof r == "object") {
292
+ if (O(r)) {
293
+ if (r.length === 0)
278
294
  continue;
279
- for (let o = 0; o < s.length; o++) {
280
- const i = s[o];
295
+ for (let o = 0; o < r.length; o++) {
296
+ const i = r[o];
281
297
  for (const a in i) {
282
298
  const c = i[a] ?? void 0;
283
299
  if (c) {
284
300
  if (typeof c == "object")
285
301
  O(c) && c.forEach((l, h) => {
286
302
  if (l)
287
- for (const g in l) {
288
- const u = l[g];
303
+ for (const E in l) {
304
+ const u = l[E];
289
305
  if (u && u.toString().length > 0) {
290
- const f = `[${o.toString()}].${a + `[${h.toString()}].${g}`}=${p(u)}`;
291
- e.push(r + f);
306
+ const g = `[${o.toString()}].${a + `[${h.toString()}].${E}`}=${T(u)}`;
307
+ t.push(n + g);
292
308
  }
293
309
  }
294
310
  });
295
311
  else if (c.toString().length > 0) {
296
- const l = `[${o.toString()}].${a}=${p(c.toString())}`;
297
- e.push(r + l);
312
+ const l = `[${o.toString()}].${a}=${T(c.toString())}`;
313
+ t.push(n + l);
298
314
  }
299
315
  }
300
316
  }
301
317
  }
302
318
  } else
303
- for (const o in s) {
304
- const i = s[o];
319
+ for (const o in r) {
320
+ const i = r[o];
305
321
  if (i != null && i != "" && i.length != 0) {
306
- const a = `.${o}=${p(i)}`;
307
- e.push(r + a);
322
+ const a = `.${o}=${T(i)}`;
323
+ t.push(n + a);
308
324
  }
309
325
  }
310
326
  continue;
311
- } else s && typeof s == "function" && (s = null);
312
- s != null && s != "" && s.length != 0 && e.push(r + "=" + p(s));
327
+ } else r && typeof r == "function" && (r = null);
328
+ r != null && r != "" && r.length != 0 && t.push(n + "=" + T(r));
313
329
  }
314
- return e && e.join("&");
330
+ return t && t.join("&");
315
331
  }
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);
332
+ async sign(e) {
333
+ const t = "&key=" + await this.helloIboot(), n = [];
334
+ for (const c in e)
335
+ n.push(c);
336
+ n.sort((c, l) => c.toLowerCase().localeCompare(l.toLowerCase()));
337
+ const r = [];
338
+ n.forEach((c) => {
339
+ let l = e[c];
340
+ typeof l == "object" && (l = JSON.stringify(l)), r.push(c + "=" + l);
325
341
  });
326
- const o = s.join("&"), i = M.md5((o + e).toLocaleUpperCase()), a = {
342
+ const o = r.join("&"), i = B.md5((o + t).toLocaleUpperCase()), a = {
327
343
  params: o,
328
344
  md5: i
329
345
  };
330
346
  return d.debug(a, "API_SIGN"), i;
331
347
  }
332
348
  //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;
349
+ assemblyParameter(e, t) {
350
+ const n = e ?? {};
351
+ 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
352
  }
337
- async assemblyHeader({ urlParams: t, token: e }) {
338
- const r = {
353
+ async assemblyHeader({ urlParams: e, token: t }) {
354
+ const n = {
339
355
  "Content-Type": "application/x-www-form-urlencoded",
340
356
  "Res-Type": "json",
341
357
  "Device-Id": this.deviceId,
342
- "User-Type": e?.utype.toString() ?? this.userType.toString(),
358
+ "User-Type": t?.utype.toString() ?? this.userType.toString(),
343
359
  "User-From": this.userFrom,
344
360
  "Api-Key": this.apiKey
345
361
  };
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;
362
+ 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));
363
+ const r = L(e), o = await this.sign(r);
364
+ return n.Sign = o, n;
349
365
  }
350
366
  async helloIboot() {
351
367
  if (this.helloMethod.length <= 0)
352
368
  return this.apiKey;
353
- const t = this.getApiUrl(this.helloMethod), e = {
369
+ const e = this.getApiUrl(this.helloMethod), t = {
354
370
  "Content-Type": "application/x-www-form-urlencoded",
355
371
  "Res-Type": "json",
356
372
  "Api-Key": this.apiKey
357
- }, r = {
358
- url: t,
359
- headers: e
373
+ }, n = {
374
+ url: e,
375
+ headers: t
360
376
  };
361
- d.debug(r, "HELLO");
362
- const s = await fetch(t, {
377
+ d.debug(n, "HELLO");
378
+ const r = await fetch(e, {
363
379
  method: "GET",
364
- headers: e,
380
+ headers: t,
365
381
  credentials: "include",
366
382
  cache: "force-cache"
367
383
  });
368
- if (s.ok) {
369
- const o = await s.json();
384
+ if (r.ok) {
385
+ const o = await r.json();
370
386
  return d.debug(o.data, "HELLO RESULT"), o.data;
371
387
  }
372
388
  throw new Error("hello iBoot error!");
373
389
  }
374
- getApiUrl(t) {
375
- return `${this.baseUrl}/${t}`;
390
+ getApiUrl(e) {
391
+ return `${this.baseUrl}/${e}`;
376
392
  }
377
393
  async csrf() {
378
- const t = await this.get({
394
+ const e = await this.get({
379
395
  url: "guest/csrf"
380
396
  });
381
- if (t.success) {
382
- const e = t.data;
383
- if (e)
384
- return e.csrfToken.toString();
397
+ if (e.success) {
398
+ const t = e.data;
399
+ if (t)
400
+ return t.csrfToken.toString();
385
401
  }
386
402
  }
387
403
  // 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 = {
404
+ async get({ url: e, data: t, token: n, cache: r = "default" }) {
405
+ 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
406
  url: c,
391
407
  headers: a
392
408
  };
@@ -395,78 +411,78 @@ class te {
395
411
  method: "GET",
396
412
  headers: a,
397
413
  credentials: "include",
398
- cache: s
414
+ cache: r
399
415
  });
400
416
  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;
417
+ const u = Object.fromEntries(h.headers.entries()), g = { ...await h.json(), headers: u };
418
+ return d.debug(g, "GET_RESULT"), g;
403
419
  }
404
- const g = {
420
+ const E = {
405
421
  code: h.status,
406
422
  success: !1,
407
423
  msg: h.statusText
408
424
  };
409
- return d.error(g), g;
425
+ return d.error(E), E;
410
426
  }
411
427
  // 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 });
428
+ async post({ url: e, data: t, token: n, cache: r = "default" }) {
429
+ t = t ? { ...t } : {};
430
+ const o = t.buffer ?? void 0, i = t.boundary ?? void 0;
431
+ o && delete t.buffer, i && delete t.boundary;
432
+ const a = this.assemblyParameter(t), c = this.convertUrlParameter(a), l = await this.assemblyHeader({ urlParams: c, token: n });
417
433
  o && i && (l["Content-Type"] = `multipart/form-data; boundary=${i}`);
418
- const h = this.getApiUrl(t), g = {
434
+ const h = this.getApiUrl(e), E = {
419
435
  url: h,
420
436
  headers: l,
421
437
  params: a
422
438
  };
423
- d.info(g, "POST");
424
- const u = o ? `${h}?${c}` : h, f = await fetch(u, {
439
+ d.info(E, "POST");
440
+ const u = o ? `${h}?${c}` : h, g = await fetch(u, {
425
441
  method: "POST",
426
442
  headers: l,
427
443
  body: o || c.toString(),
428
444
  credentials: "include",
429
- cache: s
445
+ cache: r
430
446
  });
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;
447
+ if (g.ok) {
448
+ const A = Object.fromEntries(g.headers.entries()), y = { ...await g.json(), headers: A };
449
+ return d.debug(y, "POST_RESULT"), y;
434
450
  }
435
- const w = {
436
- code: f.status,
451
+ const p = {
452
+ code: g.status,
437
453
  success: !1,
438
- msg: f.statusText
454
+ msg: g.statusText
439
455
  };
440
- return d.error(w), w;
456
+ return d.error(p), p;
441
457
  }
442
458
  // 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);
459
+ async stream({ url: e, data: t, token: n }) {
460
+ t = t ? { ...t } : {};
461
+ const r = t.buffer ?? void 0, o = t.boundary ?? void 0;
462
+ r && delete t.buffer, o && delete t.boundary;
463
+ const i = this.assemblyParameter(t), a = this.convertUrlParameter(i), c = await this.assemblyHeader({ urlParams: a, token: n });
464
+ r && o && (c["Content-Type"] = `multipart/form-data; boundary=${o}`), c.Connection = "keep-alive", c["X-Accel-Buffering"] = "no", c["Cache-Control"] = "no-cache";
465
+ const l = this.getApiUrl(e);
450
466
  try {
451
- const h = s ? `${l}?${a}` : l, g = {
467
+ const h = r ? `${l}?${a}` : l, E = {
452
468
  url: l,
453
469
  headers: c,
454
470
  params: i
455
471
  };
456
- d.info(g, "STREAM");
472
+ d.info(E, "STREAM");
457
473
  const u = await fetch(h, {
458
474
  method: "POST",
459
475
  headers: c,
460
- body: s || a.toString(),
476
+ body: r || a.toString(),
461
477
  credentials: "include"
462
478
  });
463
479
  if (!u.ok)
464
480
  throw new Error(`HTTP error! status: ${u.status}`);
465
481
  if (!u.body)
466
482
  throw new Error("No response body");
467
- const f = Object.fromEntries(u.headers.entries());
483
+ const g = Object.fromEntries(u.headers.entries());
468
484
  return new Response(u.body, {
469
- headers: f
485
+ headers: g
470
486
  });
471
487
  } catch (h) {
472
488
  throw h;
@@ -474,32 +490,30 @@ class te {
474
490
  }
475
491
  }
476
492
  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,
493
+ K as ACCOUNT_TYPE_MAP,
494
+ ne as HttpClient,
495
+ G as USER_FORM_MAP,
496
+ F as USER_SEX_MAP,
486
497
  C as USER_TYPE_MAP,
487
- ee as cleanToken,
498
+ re as cleanToken,
488
499
  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,
500
+ H as get,
501
+ ee as getLoginUser,
502
+ Q as getServerHttpCookies,
503
+ q as getServerHttpOpts,
504
+ te as getToken,
505
+ Y as iGet,
506
+ J as iPost,
495
507
  X as iPostSuccess,
496
508
  O as isArray,
497
509
  d as logger,
498
- A as post,
499
- S as randomString,
500
- Y as setDefaultRequestHeader,
501
- Z as setToken,
502
- p as urlEncode,
510
+ v as post,
511
+ b as randomString,
512
+ V as setClientRequestHeader,
513
+ Z as setServerHttpCookies,
514
+ z as setServerHttpHeaders,
515
+ se as setToken,
516
+ T as urlEncode,
503
517
  L as urlParamToJson
504
518
  };
505
519
  //# sourceMappingURL=iboot-http-client.es.js.map