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