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.
- 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 +223 -202
- 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 +2 -2
- package/dist/types/types/http.d.ts +5 -0
- package/dist/types/utils.d.ts +1 -0
- package/package.json +3 -4
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import N from "pino";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
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
|
-
},
|
|
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
|
-
},
|
|
21
|
+
}, F = {
|
|
22
22
|
unknown: 0,
|
|
23
23
|
male: 1,
|
|
24
24
|
female: 2
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
36
|
-
nestedKey: "payload"
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
39
|
+
for (let n = 0; n < t; n++)
|
|
51
40
|
r += e.charAt(Math.floor(Math.random() * s));
|
|
52
41
|
return r;
|
|
53
|
-
},
|
|
42
|
+
}, M = (o, t) => {
|
|
54
43
|
const e = {};
|
|
55
|
-
return
|
|
56
|
-
const
|
|
57
|
-
|
|
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 = (
|
|
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
|
-
},
|
|
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
|
-
},
|
|
72
|
-
const
|
|
73
|
-
return
|
|
74
|
-
},
|
|
75
|
-
localStorage.setItem(
|
|
76
|
-
},
|
|
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
|
-
|
|
99
|
+
o.indexOf("?") != -1 ? o += `&${i}` : o += `?${i}`;
|
|
80
100
|
}
|
|
81
|
-
const e =
|
|
101
|
+
const e = P(), s = t?.headers;
|
|
82
102
|
if (s)
|
|
83
103
|
for (const i in s) {
|
|
84
|
-
const
|
|
85
|
-
|
|
104
|
+
const c = s[i];
|
|
105
|
+
c && (e[i] = c);
|
|
86
106
|
}
|
|
87
|
-
|
|
88
|
-
url:
|
|
107
|
+
u.debug({
|
|
108
|
+
url: o,
|
|
89
109
|
headers: e
|
|
90
110
|
}, "GET");
|
|
91
|
-
const r = await fetch(
|
|
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
|
|
118
|
+
return u.debug(i, "GET_RESULT"), i;
|
|
99
119
|
}
|
|
100
|
-
const
|
|
120
|
+
const n = {
|
|
101
121
|
code: r.status,
|
|
102
122
|
success: !1,
|
|
103
123
|
msg: r.statusText
|
|
104
124
|
};
|
|
105
|
-
return
|
|
106
|
-
},
|
|
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
|
|
110
|
-
if (e instanceof FormData ? r = e : (r = JSON.stringify(e),
|
|
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
|
|
113
|
-
|
|
132
|
+
const l = s[a];
|
|
133
|
+
l && n.set(a, l);
|
|
114
134
|
}
|
|
115
|
-
|
|
116
|
-
url:
|
|
117
|
-
headers:
|
|
135
|
+
u.debug({
|
|
136
|
+
url: o,
|
|
137
|
+
headers: n
|
|
118
138
|
}, "POST");
|
|
119
|
-
const i = await fetch(
|
|
139
|
+
const i = await fetch(o, {
|
|
120
140
|
method: "POST",
|
|
121
|
-
headers:
|
|
141
|
+
headers: n,
|
|
122
142
|
body: r
|
|
123
143
|
});
|
|
124
144
|
if (i.ok) {
|
|
125
145
|
const a = await i.json();
|
|
126
|
-
return
|
|
146
|
+
return u.debug(a, "POST_RESULT"), a;
|
|
127
147
|
}
|
|
128
|
-
const
|
|
148
|
+
const c = {
|
|
129
149
|
code: i.status,
|
|
130
150
|
success: !1,
|
|
131
151
|
msg: i.statusText
|
|
132
152
|
};
|
|
133
|
-
return
|
|
134
|
-
},
|
|
135
|
-
const e = await
|
|
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 ??
|
|
159
|
+
t.showError(e.msg ?? S);
|
|
140
160
|
return;
|
|
141
161
|
}
|
|
142
|
-
throw Error(e.msg ??
|
|
143
|
-
},
|
|
144
|
-
const e = await
|
|
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
|
-
},
|
|
153
|
-
const e = await
|
|
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
|
-
},
|
|
156
|
-
const t =
|
|
157
|
-
return t && t.length > 0 && (
|
|
158
|
-
},
|
|
159
|
-
const t = {}, e =
|
|
160
|
-
return e && e.length > 0 && (t.deviceId = e), s && s.length > 0 && (t.lang = s), r && r.length > 0 && (t.websiteId = r),
|
|
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
|
|
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(
|
|
175
|
-
this.
|
|
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 =
|
|
182
|
-
return
|
|
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 =
|
|
186
|
-
return
|
|
187
|
-
mode:
|
|
188
|
-
}).toString(
|
|
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 (
|
|
221
|
+
if (w(r)) {
|
|
202
222
|
if (r.length === 0)
|
|
203
223
|
continue;
|
|
204
|
-
for (let
|
|
205
|
-
const i = r[
|
|
206
|
-
for (const
|
|
207
|
-
const a = i[
|
|
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
|
-
|
|
211
|
-
if (
|
|
212
|
-
for (const
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
215
|
-
const
|
|
216
|
-
e.push(s +
|
|
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
|
|
222
|
-
e.push(s +
|
|
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
|
|
229
|
-
const i = r[
|
|
248
|
+
for (const n in r) {
|
|
249
|
+
const i = r[n];
|
|
230
250
|
if (i != null && i != "" && i.length != 0) {
|
|
231
|
-
const
|
|
232
|
-
e.push(s +
|
|
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,
|
|
265
|
+
s.sort((a, l) => a.toLowerCase().localeCompare(l.toLowerCase()));
|
|
246
266
|
const r = [];
|
|
247
267
|
s.forEach((a) => {
|
|
248
|
-
let
|
|
249
|
-
typeof
|
|
268
|
+
let l = t[a];
|
|
269
|
+
typeof l == "object" && (l = JSON.stringify(l)), r.push(a + "=" + l);
|
|
250
270
|
});
|
|
251
|
-
const
|
|
252
|
-
params:
|
|
271
|
+
const n = r.join("&"), i = A.md5((n + e).toLocaleUpperCase()), c = {
|
|
272
|
+
params: n,
|
|
253
273
|
md5: i
|
|
254
274
|
};
|
|
255
|
-
return
|
|
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 =
|
|
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 =
|
|
273
|
-
return s.Sign =
|
|
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
|
-
|
|
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
|
|
295
|
-
return
|
|
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
|
|
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:
|
|
336
|
+
headers: c
|
|
317
337
|
};
|
|
318
|
-
|
|
319
|
-
const
|
|
338
|
+
u.info(l, "GET");
|
|
339
|
+
const h = await fetch(a, {
|
|
320
340
|
method: "GET",
|
|
321
|
-
headers:
|
|
341
|
+
headers: c,
|
|
322
342
|
credentials: "include",
|
|
323
343
|
cache: r
|
|
324
344
|
});
|
|
325
|
-
if (
|
|
326
|
-
const
|
|
327
|
-
return
|
|
345
|
+
if (h.ok) {
|
|
346
|
+
const g = await h.json();
|
|
347
|
+
return u.debug(g, "GET_RESULT"), g;
|
|
328
348
|
}
|
|
329
|
-
const
|
|
330
|
-
code:
|
|
349
|
+
const f = {
|
|
350
|
+
code: h.status,
|
|
331
351
|
success: !1,
|
|
332
|
-
msg:
|
|
352
|
+
msg: h.statusText
|
|
333
353
|
};
|
|
334
|
-
return
|
|
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
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
const
|
|
344
|
-
url:
|
|
345
|
-
headers:
|
|
346
|
-
params:
|
|
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
|
-
|
|
349
|
-
const
|
|
368
|
+
u.info(f, "POST");
|
|
369
|
+
const g = n ? `${h}?${a}` : h, m = await fetch(g, {
|
|
350
370
|
method: "POST",
|
|
351
|
-
headers:
|
|
352
|
-
body:
|
|
371
|
+
headers: l,
|
|
372
|
+
body: n || a.toString(),
|
|
353
373
|
credentials: "include",
|
|
354
374
|
cache: r
|
|
355
375
|
});
|
|
356
|
-
if (
|
|
357
|
-
const E = await
|
|
358
|
-
return
|
|
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:
|
|
381
|
+
code: m.status,
|
|
362
382
|
success: !1,
|
|
363
|
-
msg:
|
|
383
|
+
msg: m.statusText
|
|
364
384
|
};
|
|
365
|
-
return
|
|
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,
|
|
371
|
-
r && delete e.buffer,
|
|
372
|
-
const i = this.assemblyParameter(e),
|
|
373
|
-
r &&
|
|
374
|
-
const
|
|
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
|
|
377
|
-
url:
|
|
396
|
+
const h = r ? `${l}?${c}` : l, f = {
|
|
397
|
+
url: l,
|
|
378
398
|
headers: a,
|
|
379
399
|
params: i
|
|
380
400
|
};
|
|
381
|
-
|
|
382
|
-
const
|
|
401
|
+
u.info(f, "STREAM");
|
|
402
|
+
const g = await fetch(h, {
|
|
383
403
|
method: "POST",
|
|
384
404
|
headers: a,
|
|
385
|
-
body: r ||
|
|
405
|
+
body: r || c.toString(),
|
|
386
406
|
credentials: "include"
|
|
387
407
|
});
|
|
388
|
-
if (!
|
|
389
|
-
throw new Error(`HTTP error! status: ${
|
|
390
|
-
if (!
|
|
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(
|
|
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 (
|
|
400
|
-
throw
|
|
419
|
+
} catch (h) {
|
|
420
|
+
throw h;
|
|
401
421
|
}
|
|
402
422
|
}
|
|
403
423
|
getUserInfo(t) {
|
|
404
|
-
const e = t.get(
|
|
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
|
|
412
|
-
s =
|
|
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(
|
|
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
|
|
425
|
-
s =
|
|
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(
|
|
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:
|
|
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:
|
|
458
|
+
username: n,
|
|
439
459
|
nickname: i,
|
|
440
|
-
sex:
|
|
460
|
+
sex: c,
|
|
441
461
|
headImg: a,
|
|
442
|
-
lastLoginTime:
|
|
443
|
-
tokenExpired:
|
|
444
|
-
deviceId:
|
|
445
|
-
userType:
|
|
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(
|
|
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(
|
|
483
|
+
}), e.cookies.set(d.user, JSON.stringify(E)), e;
|
|
464
484
|
}
|
|
465
485
|
cleanToken(t) {
|
|
466
|
-
return t.cookies.set(
|
|
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(
|
|
491
|
+
}), t.cookies.set(d.user, "", {
|
|
472
492
|
maxAge: -1,
|
|
473
493
|
//设置为 -1表示立即过期
|
|
474
494
|
httpOnly: !0,
|
|
475
495
|
path: "/"
|
|
476
|
-
}), t.cookies.delete(
|
|
496
|
+
}), t.cookies.delete(d.token), t.cookies.delete(d.user), t;
|
|
477
497
|
}
|
|
478
498
|
}
|
|
479
499
|
export {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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
|
-
|
|
521
|
+
M as urlParamToJson
|
|
501
522
|
};
|
|
502
523
|
//# sourceMappingURL=iboot-http-client.es.js.map
|