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