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