iboot-http-client 1.1.0 → 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,12 +1,12 @@
1
1
  import N from "pino";
2
- import A from "koffi";
3
- import U from "js-md5";
2
+ import R from "pino-pretty";
3
+ import A from "js-md5";
4
4
  import m from "crypto-js";
5
- const F = {
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,77 +18,97 @@ 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
+ }, 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({
34
33
  name: process.env.APP_NAME ?? "iBoot",
35
34
  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;
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;
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
+ }, k = (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
+ }, D = "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
107
  h.debug({
88
- url: n,
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"
@@ -97,51 +117,51 @@ const h = N({
97
117
  const i = await r.json();
98
118
  return h.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 h.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
135
  h.debug({
116
- url: n,
117
- headers: o
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
146
  return h.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 h.error(c), c;
154
+ }, Y = 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
+ }, J = 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,8 +191,8 @@ 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({ 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";
176
196
  }
177
197
  isDebug() {
178
198
  return this._isDebug;
@@ -201,35 +221,35 @@ class X {
201
221
  if (_(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)}`;
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)}`;
216
236
  e.push(s + p);
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,17 +262,17 @@ 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 h.debug(c, "API_SIGN"), i;
256
276
  }
257
277
  //eslint-disable-next-line @typescript-eslint/no-explicit-any
258
278
  assemblyParameter(t, e) {
@@ -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 = k(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)
@@ -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 h.debug(n.data, "HELLO RESULT"), n.data;
296
316
  }
297
317
  throw new Error("hello iBoot error!");
298
318
  }
@@ -311,45 +331,45 @@ 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");
338
+ h.info(l, "GET");
319
339
  const u = await fetch(a, {
320
340
  method: "GET",
321
- headers: l,
341
+ headers: c,
322
342
  credentials: "include",
323
343
  cache: r
324
344
  });
325
345
  if (u.ok) {
326
- const d = await u.json();
327
- return h.debug(d, "GET_RESULT"), d;
346
+ const g = await u.json();
347
+ return h.debug(g, "GET_RESULT"), g;
328
348
  }
329
- const g = {
349
+ const f = {
330
350
  code: u.status,
331
351
  success: !1,
332
352
  msg: u.statusText
333
353
  };
334
- return h.error(g), g;
354
+ return h.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 = {
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 = {
344
364
  url: u,
345
- headers: c,
346
- params: l
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
+ h.info(f, "POST");
369
+ const g = n ? `${u}?${a}` : u, p = 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
  });
@@ -367,29 +387,29 @@ class X {
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 u = 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
+ h.info(f, "STREAM");
402
+ const g = await fetch(u, {
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",
@@ -401,47 +421,47 @@ class X {
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: u, tokenExpired: f, deviceId: g, userType: p, 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
462
  lastLoginTime: u,
443
- tokenExpired: g,
444
- deviceId: d,
463
+ tokenExpired: f,
464
+ deviceId: g,
445
465
  userType: p,
446
466
  status: 0,
447
467
  accountType: 0,
@@ -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,42 +480,43 @@ 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
+ D 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,
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,
494
515
  _ as isArray,
495
516
  h as logger,
496
- v as post,
517
+ C as post,
497
518
  w as randomString,
498
- x as setDefaultRequestHeader,
519
+ G as setDefaultRequestHeader,
499
520
  b as urlEncode,
500
521
  k as urlParamToJson
501
522
  };