iboot-http-client 1.0.9 → 1.1.1

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