iboot-http-client 1.2.3 → 1.2.5
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 +260 -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 +7 -21
- package/dist/types/types/http.d.ts +30 -3
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
1
|
+
import R from "pino";
|
|
2
|
+
import B from "pino-pretty";
|
|
3
|
+
import U from "js-md5";
|
|
4
|
+
import I from "crypto-js";
|
|
5
|
+
const K = {
|
|
6
6
|
GENERAL: 0,
|
|
7
7
|
PHONE: 1,
|
|
8
8
|
EMAIL: 2
|
|
@@ -10,7 +10,7 @@ const F = {
|
|
|
10
10
|
TYPE_MGT: 0,
|
|
11
11
|
TYPE_C: 1,
|
|
12
12
|
TYPE_B: 2
|
|
13
|
-
},
|
|
13
|
+
}, G = {
|
|
14
14
|
FROM_WEB: 1,
|
|
15
15
|
FROM_PC: 2,
|
|
16
16
|
FROM_WX_MINI_PRO: 3,
|
|
@@ -18,132 +18,132 @@ 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
|
-
},
|
|
25
|
+
}, M = B({
|
|
26
26
|
colorize: !0,
|
|
27
27
|
destination: process.stdout,
|
|
28
28
|
translateTime: "SYS:yyyy-mm-dd HH:MM:ss",
|
|
29
29
|
ignore: "pid,hostname",
|
|
30
30
|
messageFormat: "{msg}",
|
|
31
31
|
singleLine: !0
|
|
32
|
-
}), d =
|
|
32
|
+
}), d = R({
|
|
33
33
|
name: process.env.APP_NAME ?? "iBoot",
|
|
34
34
|
level: process.env.APP_ENV === "production" ? "info" : "debug",
|
|
35
35
|
nestedKey: "payload"
|
|
36
|
-
},
|
|
37
|
-
const
|
|
38
|
-
let
|
|
39
|
-
for (let o = 0; o <
|
|
40
|
-
|
|
41
|
-
return
|
|
42
|
-
}, L = (
|
|
43
|
-
const
|
|
44
|
-
return
|
|
45
|
-
const o =
|
|
46
|
-
o[1] && (!
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
const
|
|
50
|
-
"M+":
|
|
36
|
+
}, M), O = (s) => Array.isArray(s) || typeof s == "object" && Object.prototype.toString.call(s) === "[object Array]", b = (s) => {
|
|
37
|
+
const e = s || 32, t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", n = t.length;
|
|
38
|
+
let r = "";
|
|
39
|
+
for (let o = 0; o < e; o++)
|
|
40
|
+
r += t.charAt(Math.floor(Math.random() * n));
|
|
41
|
+
return r;
|
|
42
|
+
}, L = (s, e) => {
|
|
43
|
+
const t = {};
|
|
44
|
+
return s.split("&").forEach((r) => {
|
|
45
|
+
const o = r.split("=");
|
|
46
|
+
o[1] && (!e || e.indexOf(o[0]) == -1) && (t[o[0]] = o[1]);
|
|
47
|
+
}), t;
|
|
48
|
+
}, T = (s) => !s || s == "" || s.length == 0 ? "" : encodeURIComponent(s).replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\'/g, "%27").replace(/\!/g, "%21").replace(/\~/g, "%7E"), k = (s, e) => {
|
|
49
|
+
const t = {
|
|
50
|
+
"M+": s.getMonth() + 1,
|
|
51
51
|
//月份
|
|
52
|
-
"d+":
|
|
52
|
+
"d+": s.getDate(),
|
|
53
53
|
//日
|
|
54
|
-
"h+":
|
|
54
|
+
"h+": s.getHours(),
|
|
55
55
|
//小时
|
|
56
|
-
"m+":
|
|
56
|
+
"m+": s.getMinutes(),
|
|
57
57
|
//分
|
|
58
|
-
"s+":
|
|
58
|
+
"s+": s.getSeconds(),
|
|
59
59
|
//秒
|
|
60
|
-
"q+": Math.floor((
|
|
60
|
+
"q+": Math.floor((s.getMonth() + 3) / 3),
|
|
61
61
|
//季度
|
|
62
|
-
S:
|
|
62
|
+
S: s.getMilliseconds()
|
|
63
63
|
//毫秒
|
|
64
64
|
};
|
|
65
|
-
if (/(y+)/.test(
|
|
66
|
-
const
|
|
65
|
+
if (/(y+)/.test(e)) {
|
|
66
|
+
const r = new RegExp(/(y+)/).exec(e);
|
|
67
67
|
let o = 0;
|
|
68
|
-
|
|
68
|
+
r && r.length > 0 && (o = r[0].length), e = e.replace(/(y+)/, s.getFullYear() + "").substring(4 - o);
|
|
69
69
|
}
|
|
70
|
-
for (const
|
|
71
|
-
const
|
|
72
|
-
if (o.test(
|
|
73
|
-
const i = o.exec(
|
|
70
|
+
for (const n in t) {
|
|
71
|
+
const r = "(" + n + ")", o = new RegExp(r);
|
|
72
|
+
if (o.test(e)) {
|
|
73
|
+
const i = o.exec(e);
|
|
74
74
|
let a = 0;
|
|
75
|
-
i && i.length > 0 && (a = i[0].length),
|
|
75
|
+
i && i.length > 0 && (a = i[0].length), e = e.replace(o, a == 1 ? t[n].toString() : ("00" + t[n]).substring(t[n].toString().length));
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
return
|
|
79
|
-
},
|
|
78
|
+
return e;
|
|
79
|
+
}, D = "zh-CN", S = "_device_id_key", P = "_current_website_key", _ = "Get request error!", w = "Post request error!", f = {
|
|
80
80
|
IBOOT_DEVICE_ID: "dvid",
|
|
81
81
|
IBOOT_LANG: "lang",
|
|
82
82
|
IBOOT_WEBSITE_ID: "wid",
|
|
83
83
|
IBOOT_WEBSITE_NO: "wno",
|
|
84
84
|
IBOOT_TOKEN: "token",
|
|
85
85
|
IBOOT_USER: "user"
|
|
86
|
-
},
|
|
86
|
+
}, m = {
|
|
87
87
|
DEVICE_ID: "Device-Id",
|
|
88
88
|
LANG: "Lang",
|
|
89
89
|
WEBSITE_ID: "Website-Id",
|
|
90
90
|
WEBSITE_NO: "Website-No"
|
|
91
|
-
},
|
|
92
|
-
if (!
|
|
91
|
+
}, N = (s) => {
|
|
92
|
+
if (!s.get)
|
|
93
93
|
throw new Error("The get method of IStorage has not been implemented.");
|
|
94
|
-
const
|
|
95
|
-
return
|
|
96
|
-
},
|
|
97
|
-
if (!
|
|
94
|
+
const e = s.get(S) ?? "", t = s.get(P), n = t != null ? JSON.parse(t) : null, r = {};
|
|
95
|
+
return e.length > 0 && (r["Device-Id"] = e), n && (r.Lang = n.language, n.websiteId && (r["Website-Id"] = n.websiteId), n.websiteNo && (r["Website-No"] = n.websiteNo)), r;
|
|
96
|
+
}, V = ({ deviceId: s, website: e }, t) => {
|
|
97
|
+
if (!t.set)
|
|
98
98
|
throw new Error("The set method of IStorage has not been implemented.");
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
if (
|
|
102
|
-
const i = new URLSearchParams(
|
|
103
|
-
|
|
99
|
+
t.set(S, s), e && t.set(P, JSON.stringify(e));
|
|
100
|
+
}, H = async (s, e) => {
|
|
101
|
+
if (e?.data) {
|
|
102
|
+
const i = new URLSearchParams(e.data);
|
|
103
|
+
s.indexOf("?") != -1 ? s += `&${i}` : s += `?${i}`;
|
|
104
104
|
}
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
for (const i in
|
|
108
|
-
const a =
|
|
109
|
-
a && (
|
|
105
|
+
const t = e && e.storage && e.storage.get ? N(e.storage) : {}, n = e?.headers;
|
|
106
|
+
if (n)
|
|
107
|
+
for (const i in n) {
|
|
108
|
+
const a = n[i];
|
|
109
|
+
a && (t[i] = a);
|
|
110
110
|
}
|
|
111
111
|
d.info({
|
|
112
|
-
url:
|
|
113
|
-
headers:
|
|
112
|
+
url: s,
|
|
113
|
+
headers: t
|
|
114
114
|
}, "GET");
|
|
115
|
-
const
|
|
115
|
+
const r = await fetch(s, {
|
|
116
116
|
method: "GET",
|
|
117
|
-
headers:
|
|
118
|
-
cache:
|
|
117
|
+
headers: t,
|
|
118
|
+
cache: e?.useCache ? "force-cache" : "default"
|
|
119
119
|
});
|
|
120
|
-
if (
|
|
121
|
-
const i = Object.fromEntries(
|
|
120
|
+
if (r.ok) {
|
|
121
|
+
const i = Object.fromEntries(r.headers.entries()), a = { ...await r.json(), headers: i };
|
|
122
122
|
return d.debug(a, "GET_RESULT"), a;
|
|
123
123
|
}
|
|
124
124
|
const o = {
|
|
125
|
-
code:
|
|
125
|
+
code: r.status,
|
|
126
126
|
success: !1,
|
|
127
|
-
msg:
|
|
127
|
+
msg: r.statusText
|
|
128
128
|
};
|
|
129
129
|
return d.error(o), o;
|
|
130
|
-
},
|
|
131
|
-
const
|
|
132
|
-
let
|
|
133
|
-
const o =
|
|
134
|
-
if (
|
|
135
|
-
for (let l in
|
|
136
|
-
const h =
|
|
130
|
+
}, v = async (s, e) => {
|
|
131
|
+
const t = e?.data ?? {}, n = e?.headers;
|
|
132
|
+
let r;
|
|
133
|
+
const o = e && e.storage && e.storage.get ? N(e.storage) : {}, i = new Headers(o);
|
|
134
|
+
if (t instanceof FormData ? r = t : (r = JSON.stringify(t), i.set("Content-Type", "application/json")), n)
|
|
135
|
+
for (let l in n) {
|
|
136
|
+
const h = n[l];
|
|
137
137
|
h && i.set(l, h);
|
|
138
138
|
}
|
|
139
139
|
d.info({
|
|
140
|
-
url:
|
|
140
|
+
url: s,
|
|
141
141
|
headers: i
|
|
142
142
|
}, "POST");
|
|
143
|
-
const a = await fetch(
|
|
143
|
+
const a = await fetch(s, {
|
|
144
144
|
method: "POST",
|
|
145
145
|
headers: i,
|
|
146
|
-
body:
|
|
146
|
+
body: r
|
|
147
147
|
});
|
|
148
148
|
if (a.ok) {
|
|
149
149
|
const l = Object.fromEntries(a.headers.entries()), h = { ...await a.json(), headers: l };
|
|
@@ -155,58 +155,68 @@ const F = {
|
|
|
155
155
|
msg: a.statusText
|
|
156
156
|
};
|
|
157
157
|
return d.error(c), c;
|
|
158
|
-
},
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
return
|
|
162
|
-
if (
|
|
163
|
-
|
|
158
|
+
}, Y = async (s, e) => {
|
|
159
|
+
const t = await H(s, e);
|
|
160
|
+
if (t.success)
|
|
161
|
+
return t.data;
|
|
162
|
+
if (e?.showError) {
|
|
163
|
+
e.showError(t.msg ?? _);
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
throw Error(
|
|
167
|
-
},
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
170
|
-
return
|
|
171
|
-
if (
|
|
172
|
-
|
|
166
|
+
throw Error(t.msg ?? _);
|
|
167
|
+
}, J = async (s, e) => {
|
|
168
|
+
const t = await v(s, e);
|
|
169
|
+
if (t.success)
|
|
170
|
+
return t.data;
|
|
171
|
+
if (e?.showError) {
|
|
172
|
+
e.showError(t.msg ?? w);
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
175
|
-
throw Error(
|
|
176
|
-
}, X = async (
|
|
177
|
-
const
|
|
178
|
-
return
|
|
179
|
-
}, q = (
|
|
180
|
-
if (
|
|
181
|
-
const
|
|
182
|
-
return
|
|
175
|
+
throw Error(t.msg ?? w);
|
|
176
|
+
}, X = async (s, e) => {
|
|
177
|
+
const t = await v(s, e);
|
|
178
|
+
return t.success ? (e?.showSuccess && e.showSuccess(t.msg ?? "SUCCESS"), !0) : (e?.showError && e.showError(t.msg ?? w), !1);
|
|
179
|
+
}, q = (s) => {
|
|
180
|
+
if (s.get) {
|
|
181
|
+
const e = s.get(m.DEVICE_ID), t = s.get(m.LANG), n = s.get(m.WEBSITE_ID), r = s.get(m.WEBSITE_NO), o = {};
|
|
182
|
+
return e && e.length > 0 && (o.deviceId = e), t && t.length > 0 && (o.lang = t), n && n.length > 0 && (o.websiteId = n), r && r.length > 0 && (o.websiteNo = r), o;
|
|
183
183
|
}
|
|
184
|
-
throw new Error("The
|
|
185
|
-
}, z = (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
throw new Error("The get method of IStorage has not been implemented.");
|
|
185
|
+
}, z = (s, e) => {
|
|
186
|
+
throw s.set && (e.deviceId && s.set(m.DEVICE_ID, e.deviceId), e.lang && s.set(m.LANG, e.lang), e.websiteId && s.set(m.WEBSITE_ID, e.websiteId), e.websiteNo && s.set(m.WEBSITE_NO, e.websiteNo)), new Error("The set method of IStorage has not been implemented.");
|
|
187
|
+
}, Q = (s) => {
|
|
188
|
+
if (s.get) {
|
|
189
|
+
const e = s.get(f.IBOOT_DEVICE_ID), t = s.get(f.IBOOT_LANG), n = s.get(f.IBOOT_WEBSITE_ID), r = s.get(f.IBOOT_WEBSITE_NO), o = {};
|
|
190
|
+
return e && e.length > 0 && (o.deviceId = e), t && t.length > 0 && (o.lang = t), n && n.length > 0 && (o.websiteId = n), r && r.length > 0 && (o.websiteNo = r), o;
|
|
190
191
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
throw new Error("The get method of ICookies has not been implemented.");
|
|
193
|
+
}, Z = (s, e) => {
|
|
194
|
+
throw s.set && (e.deviceId && s.set(f.IBOOT_DEVICE_ID, e.deviceId), e.lang && s.set(f.IBOOT_LANG, e.lang), e.websiteId && s.set(f.IBOOT_WEBSITE_ID, e.websiteId), e.websiteNo && s.set(f.IBOOT_WEBSITE_NO, e.websiteNo)), new Error("The set method of ICookies has not been implemented.");
|
|
195
|
+
}, ee = (s) => {
|
|
196
|
+
if (s.get) {
|
|
197
|
+
const e = s.get(f.IBOOT_USER);
|
|
198
|
+
if (e && e.length > 0)
|
|
199
|
+
return JSON.parse(e);
|
|
200
|
+
}
|
|
201
|
+
}, te = (s) => {
|
|
202
|
+
if (s.get) {
|
|
203
|
+
const e = s.get(f.IBOOT_USER);
|
|
204
|
+
if (e && e.length > 0) {
|
|
205
|
+
const t = JSON.parse(e), n = t.username, r = t.userType.toString(), o = s.get(f.IBOOT_TOKEN);
|
|
196
206
|
if (o)
|
|
197
207
|
return {
|
|
198
|
-
username:
|
|
199
|
-
utype:
|
|
208
|
+
username: n,
|
|
209
|
+
utype: r,
|
|
200
210
|
token: o
|
|
201
211
|
};
|
|
202
212
|
}
|
|
203
213
|
}
|
|
204
|
-
},
|
|
205
|
-
const { id:
|
|
206
|
-
id:
|
|
207
|
-
name:
|
|
208
|
-
username:
|
|
209
|
-
nickname: o ||
|
|
214
|
+
}, se = (s, e) => {
|
|
215
|
+
const { id: t, name: n, username: r, nickname: o, headImg: i, token: a, lastLoginTime: c, deviceId: l, userType: h, mustChangePwd: E } = s, u = {
|
|
216
|
+
id: t,
|
|
217
|
+
name: n,
|
|
218
|
+
username: r,
|
|
219
|
+
nickname: o || n,
|
|
210
220
|
headImg: i,
|
|
211
221
|
lastLoginTime: c,
|
|
212
222
|
deviceId: l,
|
|
@@ -214,34 +224,34 @@ const F = {
|
|
|
214
224
|
accountType: 0,
|
|
215
225
|
needToReview: !1,
|
|
216
226
|
socketOnline: !1,
|
|
217
|
-
mustChangePwd:
|
|
227
|
+
mustChangePwd: E
|
|
218
228
|
};
|
|
219
|
-
if (!
|
|
229
|
+
if (!e.set)
|
|
220
230
|
throw new Error("cookies set function is undefined");
|
|
221
|
-
|
|
231
|
+
e.set(f.IBOOT_TOKEN, a, {
|
|
222
232
|
path: "/",
|
|
223
233
|
secure: process.env.APP_ENV === "production",
|
|
224
234
|
httpOnly: !0,
|
|
225
235
|
sameSite: "strict"
|
|
226
|
-
}),
|
|
227
|
-
},
|
|
228
|
-
if (!
|
|
236
|
+
}), e.set(f.IBOOT_USER, JSON.stringify(u));
|
|
237
|
+
}, re = (s) => {
|
|
238
|
+
if (!s.set)
|
|
229
239
|
throw new Error("cookies set function is undefined");
|
|
230
|
-
if (
|
|
240
|
+
if (s.set(f.IBOOT_TOKEN, "", {
|
|
231
241
|
maxAge: -1,
|
|
232
242
|
//设置为 -1表示立即过期
|
|
233
243
|
httpOnly: !0,
|
|
234
244
|
path: "/"
|
|
235
|
-
}),
|
|
245
|
+
}), s.set(f.IBOOT_USER, "", {
|
|
236
246
|
maxAge: -1,
|
|
237
247
|
//设置为 -1表示立即过期
|
|
238
248
|
httpOnly: !0,
|
|
239
249
|
path: "/"
|
|
240
|
-
}), !
|
|
250
|
+
}), !s.delete)
|
|
241
251
|
throw new Error("cookies delete function is undefined");
|
|
242
|
-
|
|
252
|
+
s.delete(f.IBOOT_TOKEN), s.delete(f.IBOOT_USER);
|
|
243
253
|
};
|
|
244
|
-
class
|
|
254
|
+
class ne {
|
|
245
255
|
baseUrl;
|
|
246
256
|
helloMethod;
|
|
247
257
|
apiKey;
|
|
@@ -252,141 +262,141 @@ class te {
|
|
|
252
262
|
lang;
|
|
253
263
|
websiteId;
|
|
254
264
|
websiteNo;
|
|
255
|
-
constructor(
|
|
256
|
-
process.env.APP_ENV === "production" || d.warn("This is currently a development environment!"), this.baseUrl = process.env.APP_BASEURL, this.apiKey = process.env.APP_APIKEY, this.userFrom = process.env.APP_USERFROM ?? "1", this.helloMethod =
|
|
265
|
+
constructor(e) {
|
|
266
|
+
process.env.APP_ENV === "production" || d.warn("This is currently a development environment!"), this.baseUrl = process.env.APP_BASEURL, this.apiKey = process.env.APP_APIKEY, this.userFrom = process.env.APP_USERFROM ?? "1", this.helloMethod = e.helloURL ?? "", this.userType = e.userType ?? C.TYPE_MGT, this.deviceId = e.deviceId ?? b(10), this.lang = e.lang ?? D, this.websiteId = e.websiteId, this.websiteNo = e.websiteNo;
|
|
257
267
|
}
|
|
258
|
-
encrypt(
|
|
259
|
-
const
|
|
260
|
-
return
|
|
268
|
+
encrypt(e) {
|
|
269
|
+
const t = I.enc.Utf8.parse(this.apiKey);
|
|
270
|
+
return I.AES.encrypt(e, t).toString();
|
|
261
271
|
}
|
|
262
|
-
decrypt(
|
|
263
|
-
const
|
|
264
|
-
return
|
|
265
|
-
mode:
|
|
266
|
-
}).toString(
|
|
272
|
+
decrypt(e) {
|
|
273
|
+
const t = I.enc.Utf8.parse(this.apiKey);
|
|
274
|
+
return I.AES.decrypt(e, t, {
|
|
275
|
+
mode: I.mode.ECB
|
|
276
|
+
}).toString(I.enc.Utf8);
|
|
267
277
|
}
|
|
268
278
|
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
269
|
-
convertUrlParameter(
|
|
270
|
-
const
|
|
271
|
-
for (const
|
|
272
|
-
let
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
else if (
|
|
276
|
-
if (O(
|
|
277
|
-
if (
|
|
279
|
+
convertUrlParameter(e) {
|
|
280
|
+
const t = [];
|
|
281
|
+
for (const n in e) {
|
|
282
|
+
let r = e[n];
|
|
283
|
+
if (r && typeof r == "string")
|
|
284
|
+
r = r.trim();
|
|
285
|
+
else if (r && typeof r == "object") {
|
|
286
|
+
if (O(r)) {
|
|
287
|
+
if (r.length === 0)
|
|
278
288
|
continue;
|
|
279
|
-
for (let o = 0; o <
|
|
280
|
-
const i =
|
|
289
|
+
for (let o = 0; o < r.length; o++) {
|
|
290
|
+
const i = r[o];
|
|
281
291
|
for (const a in i) {
|
|
282
292
|
const c = i[a] ?? void 0;
|
|
283
293
|
if (c) {
|
|
284
294
|
if (typeof c == "object")
|
|
285
295
|
O(c) && c.forEach((l, h) => {
|
|
286
296
|
if (l)
|
|
287
|
-
for (const
|
|
288
|
-
const u = l[
|
|
297
|
+
for (const E in l) {
|
|
298
|
+
const u = l[E];
|
|
289
299
|
if (u && u.toString().length > 0) {
|
|
290
|
-
const
|
|
291
|
-
|
|
300
|
+
const g = `[${o.toString()}].${a + `[${h.toString()}].${E}`}=${T(u)}`;
|
|
301
|
+
t.push(n + g);
|
|
292
302
|
}
|
|
293
303
|
}
|
|
294
304
|
});
|
|
295
305
|
else if (c.toString().length > 0) {
|
|
296
|
-
const l = `[${o.toString()}].${a}=${
|
|
297
|
-
|
|
306
|
+
const l = `[${o.toString()}].${a}=${T(c.toString())}`;
|
|
307
|
+
t.push(n + l);
|
|
298
308
|
}
|
|
299
309
|
}
|
|
300
310
|
}
|
|
301
311
|
}
|
|
302
312
|
} else
|
|
303
|
-
for (const o in
|
|
304
|
-
const i =
|
|
313
|
+
for (const o in r) {
|
|
314
|
+
const i = r[o];
|
|
305
315
|
if (i != null && i != "" && i.length != 0) {
|
|
306
|
-
const a = `.${o}=${
|
|
307
|
-
|
|
316
|
+
const a = `.${o}=${T(i)}`;
|
|
317
|
+
t.push(n + a);
|
|
308
318
|
}
|
|
309
319
|
}
|
|
310
320
|
continue;
|
|
311
|
-
} else
|
|
312
|
-
|
|
321
|
+
} else r && typeof r == "function" && (r = null);
|
|
322
|
+
r != null && r != "" && r.length != 0 && t.push(n + "=" + T(r));
|
|
313
323
|
}
|
|
314
|
-
return
|
|
324
|
+
return t && t.join("&");
|
|
315
325
|
}
|
|
316
|
-
async sign(
|
|
317
|
-
const
|
|
318
|
-
for (const c in
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
let l =
|
|
324
|
-
typeof l == "object" && (l = JSON.stringify(l)),
|
|
326
|
+
async sign(e) {
|
|
327
|
+
const t = "&key=" + await this.helloIboot(), n = [];
|
|
328
|
+
for (const c in e)
|
|
329
|
+
n.push(c);
|
|
330
|
+
n.sort((c, l) => c.toLowerCase().localeCompare(l.toLowerCase()));
|
|
331
|
+
const r = [];
|
|
332
|
+
n.forEach((c) => {
|
|
333
|
+
let l = e[c];
|
|
334
|
+
typeof l == "object" && (l = JSON.stringify(l)), r.push(c + "=" + l);
|
|
325
335
|
});
|
|
326
|
-
const o =
|
|
336
|
+
const o = r.join("&"), i = U.md5((o + t).toLocaleUpperCase()), a = {
|
|
327
337
|
params: o,
|
|
328
338
|
md5: i
|
|
329
339
|
};
|
|
330
340
|
return d.debug(a, "API_SIGN"), i;
|
|
331
341
|
}
|
|
332
342
|
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
333
|
-
assemblyParameter(
|
|
334
|
-
const
|
|
335
|
-
return
|
|
343
|
+
assemblyParameter(e, t) {
|
|
344
|
+
const n = e ?? {};
|
|
345
|
+
return n.timestamp = Date.now() + "", n.echostr = b(10), n.version = this.version, n.deviceId = this.deviceId, n.webid = this.websiteId, n.apiKey = this.apiKey, t && t.length > 0 && (n.username = t), n;
|
|
336
346
|
}
|
|
337
|
-
async assemblyHeader({ urlParams:
|
|
338
|
-
const
|
|
347
|
+
async assemblyHeader({ urlParams: e, token: t }) {
|
|
348
|
+
const n = {
|
|
339
349
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
340
350
|
"Res-Type": "json",
|
|
341
351
|
"Device-Id": this.deviceId,
|
|
342
|
-
"User-Type":
|
|
352
|
+
"User-Type": t?.utype.toString() ?? this.userType.toString(),
|
|
343
353
|
"User-From": this.userFrom,
|
|
344
354
|
"Api-Key": this.apiKey
|
|
345
355
|
};
|
|
346
|
-
this.lang && this.lang.length > 0 && (
|
|
347
|
-
const
|
|
348
|
-
return
|
|
356
|
+
this.lang && this.lang.length > 0 && (n.Lang = this.lang), this.websiteId && this.websiteId.length > 0 && (n["Web-Id"] = this.websiteId), this.websiteNo && this.websiteNo.length > 0 && (n["Web-No"] = this.websiteNo), t && (t.token && t.token.length > 0 && t.username && t.username.length > 0 && (n.Authorization = t.token, n.Username = t.username), t.xcsrf && (n[t.xcsrf.csrfHeader] = t.xcsrf.csrfToken));
|
|
357
|
+
const r = L(e), o = await this.sign(r);
|
|
358
|
+
return n.Sign = o, n;
|
|
349
359
|
}
|
|
350
360
|
async helloIboot() {
|
|
351
361
|
if (this.helloMethod.length <= 0)
|
|
352
362
|
return this.apiKey;
|
|
353
|
-
const
|
|
363
|
+
const e = this.getApiUrl(this.helloMethod), t = {
|
|
354
364
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
355
365
|
"Res-Type": "json",
|
|
356
366
|
"Api-Key": this.apiKey
|
|
357
|
-
},
|
|
358
|
-
url:
|
|
359
|
-
headers:
|
|
367
|
+
}, n = {
|
|
368
|
+
url: e,
|
|
369
|
+
headers: t
|
|
360
370
|
};
|
|
361
|
-
d.debug(
|
|
362
|
-
const
|
|
371
|
+
d.debug(n, "HELLO");
|
|
372
|
+
const r = await fetch(e, {
|
|
363
373
|
method: "GET",
|
|
364
|
-
headers:
|
|
374
|
+
headers: t,
|
|
365
375
|
credentials: "include",
|
|
366
376
|
cache: "force-cache"
|
|
367
377
|
});
|
|
368
|
-
if (
|
|
369
|
-
const o = await
|
|
378
|
+
if (r.ok) {
|
|
379
|
+
const o = await r.json();
|
|
370
380
|
return d.debug(o.data, "HELLO RESULT"), o.data;
|
|
371
381
|
}
|
|
372
382
|
throw new Error("hello iBoot error!");
|
|
373
383
|
}
|
|
374
|
-
getApiUrl(
|
|
375
|
-
return `${this.baseUrl}/${
|
|
384
|
+
getApiUrl(e) {
|
|
385
|
+
return `${this.baseUrl}/${e}`;
|
|
376
386
|
}
|
|
377
387
|
async csrf() {
|
|
378
|
-
const
|
|
388
|
+
const e = await this.get({
|
|
379
389
|
url: "guest/csrf"
|
|
380
390
|
});
|
|
381
|
-
if (
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
return
|
|
391
|
+
if (e.success) {
|
|
392
|
+
const t = e.data;
|
|
393
|
+
if (t)
|
|
394
|
+
return t.csrfToken.toString();
|
|
385
395
|
}
|
|
386
396
|
}
|
|
387
397
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
388
|
-
async get({ url:
|
|
389
|
-
const o = this.assemblyParameter(
|
|
398
|
+
async get({ url: e, data: t, token: n, cache: r = "default" }) {
|
|
399
|
+
const o = this.assemblyParameter(t), i = this.convertUrlParameter(o), a = await this.assemblyHeader({ urlParams: i, token: n }), c = `${this.getApiUrl(e)}?${i.toString()}`, l = {
|
|
390
400
|
url: c,
|
|
391
401
|
headers: a
|
|
392
402
|
};
|
|
@@ -395,78 +405,78 @@ class te {
|
|
|
395
405
|
method: "GET",
|
|
396
406
|
headers: a,
|
|
397
407
|
credentials: "include",
|
|
398
|
-
cache:
|
|
408
|
+
cache: r
|
|
399
409
|
});
|
|
400
410
|
if (h.ok) {
|
|
401
|
-
const u = Object.fromEntries(h.headers.entries()),
|
|
402
|
-
return d.debug(
|
|
411
|
+
const u = Object.fromEntries(h.headers.entries()), g = { ...await h.json(), headers: u };
|
|
412
|
+
return d.debug(g, "GET_RESULT"), g;
|
|
403
413
|
}
|
|
404
|
-
const
|
|
414
|
+
const E = {
|
|
405
415
|
code: h.status,
|
|
406
416
|
success: !1,
|
|
407
417
|
msg: h.statusText
|
|
408
418
|
};
|
|
409
|
-
return d.error(
|
|
419
|
+
return d.error(E), E;
|
|
410
420
|
}
|
|
411
421
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
412
|
-
async post({ url:
|
|
413
|
-
|
|
414
|
-
const o =
|
|
415
|
-
o && delete
|
|
416
|
-
const a = this.assemblyParameter(
|
|
422
|
+
async post({ url: e, data: t, token: n, cache: r = "default" }) {
|
|
423
|
+
t = t ? { ...t } : {};
|
|
424
|
+
const o = t.buffer ?? void 0, i = t.boundary ?? void 0;
|
|
425
|
+
o && delete t.buffer, i && delete t.boundary;
|
|
426
|
+
const a = this.assemblyParameter(t), c = this.convertUrlParameter(a), l = await this.assemblyHeader({ urlParams: c, token: n });
|
|
417
427
|
o && i && (l["Content-Type"] = `multipart/form-data; boundary=${i}`);
|
|
418
|
-
const h = this.getApiUrl(
|
|
428
|
+
const h = this.getApiUrl(e), E = {
|
|
419
429
|
url: h,
|
|
420
430
|
headers: l,
|
|
421
431
|
params: a
|
|
422
432
|
};
|
|
423
|
-
d.info(
|
|
424
|
-
const u = o ? `${h}?${c}` : h,
|
|
433
|
+
d.info(E, "POST");
|
|
434
|
+
const u = o ? `${h}?${c}` : h, g = await fetch(u, {
|
|
425
435
|
method: "POST",
|
|
426
436
|
headers: l,
|
|
427
437
|
body: o || c.toString(),
|
|
428
438
|
credentials: "include",
|
|
429
|
-
cache:
|
|
439
|
+
cache: r
|
|
430
440
|
});
|
|
431
|
-
if (
|
|
432
|
-
const
|
|
433
|
-
return d.debug(
|
|
441
|
+
if (g.ok) {
|
|
442
|
+
const A = Object.fromEntries(g.headers.entries()), y = { ...await g.json(), headers: A };
|
|
443
|
+
return d.debug(y, "POST_RESULT"), y;
|
|
434
444
|
}
|
|
435
|
-
const
|
|
436
|
-
code:
|
|
445
|
+
const p = {
|
|
446
|
+
code: g.status,
|
|
437
447
|
success: !1,
|
|
438
|
-
msg:
|
|
448
|
+
msg: g.statusText
|
|
439
449
|
};
|
|
440
|
-
return d.error(
|
|
450
|
+
return d.error(p), p;
|
|
441
451
|
}
|
|
442
452
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
443
|
-
async stream({ url:
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
const i = this.assemblyParameter(
|
|
448
|
-
|
|
449
|
-
const l = this.getApiUrl(
|
|
453
|
+
async stream({ url: e, data: t, token: n }) {
|
|
454
|
+
t = t ? { ...t } : {};
|
|
455
|
+
const r = t.buffer ?? void 0, o = t.boundary ?? void 0;
|
|
456
|
+
r && delete t.buffer, o && delete t.boundary;
|
|
457
|
+
const i = this.assemblyParameter(t), a = this.convertUrlParameter(i), c = await this.assemblyHeader({ urlParams: a, token: n });
|
|
458
|
+
r && o && (c["Content-Type"] = `multipart/form-data; boundary=${o}`), c.Connection = "keep-alive", c["X-Accel-Buffering"] = "no", c["Cache-Control"] = "no-cache";
|
|
459
|
+
const l = this.getApiUrl(e);
|
|
450
460
|
try {
|
|
451
|
-
const h =
|
|
461
|
+
const h = r ? `${l}?${a}` : l, E = {
|
|
452
462
|
url: l,
|
|
453
463
|
headers: c,
|
|
454
464
|
params: i
|
|
455
465
|
};
|
|
456
|
-
d.info(
|
|
466
|
+
d.info(E, "STREAM");
|
|
457
467
|
const u = await fetch(h, {
|
|
458
468
|
method: "POST",
|
|
459
469
|
headers: c,
|
|
460
|
-
body:
|
|
470
|
+
body: r || a.toString(),
|
|
461
471
|
credentials: "include"
|
|
462
472
|
});
|
|
463
473
|
if (!u.ok)
|
|
464
474
|
throw new Error(`HTTP error! status: ${u.status}`);
|
|
465
475
|
if (!u.body)
|
|
466
476
|
throw new Error("No response body");
|
|
467
|
-
const
|
|
477
|
+
const g = Object.fromEntries(u.headers.entries());
|
|
468
478
|
return new Response(u.body, {
|
|
469
|
-
headers:
|
|
479
|
+
headers: g
|
|
470
480
|
});
|
|
471
481
|
} catch (h) {
|
|
472
482
|
throw h;
|
|
@@ -474,32 +484,30 @@ class te {
|
|
|
474
484
|
}
|
|
475
485
|
}
|
|
476
486
|
export {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
I as DEVICE_ID_KEY,
|
|
482
|
-
y as HEADER_NAMES,
|
|
483
|
-
te as HttpClient,
|
|
484
|
-
W as USER_FORM_MAP,
|
|
485
|
-
G as USER_SEX_MAP,
|
|
487
|
+
K as ACCOUNT_TYPE_MAP,
|
|
488
|
+
ne as HttpClient,
|
|
489
|
+
G as USER_FORM_MAP,
|
|
490
|
+
F as USER_SEX_MAP,
|
|
486
491
|
C as USER_TYPE_MAP,
|
|
487
|
-
|
|
492
|
+
re as cleanToken,
|
|
488
493
|
k as dateFormat,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
494
|
+
H as get,
|
|
495
|
+
Q as getHttpOptsByCookies,
|
|
496
|
+
ee as getLoginUser,
|
|
497
|
+
q as getServerHttpOpts,
|
|
498
|
+
te as getToken,
|
|
499
|
+
Y as iGet,
|
|
500
|
+
J as iPost,
|
|
495
501
|
X as iPostSuccess,
|
|
496
502
|
O as isArray,
|
|
497
503
|
d as logger,
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
Z as
|
|
502
|
-
|
|
504
|
+
v as post,
|
|
505
|
+
b as randomString,
|
|
506
|
+
V as setClientRequestHeader,
|
|
507
|
+
Z as setServerHttpCookies,
|
|
508
|
+
z as setServerHttpHeaders,
|
|
509
|
+
se as setToken,
|
|
510
|
+
T as urlEncode,
|
|
503
511
|
L as urlParamToJson
|
|
504
512
|
};
|
|
505
513
|
//# sourceMappingURL=iboot-http-client.es.js.map
|