iboot-http-client 1.2.4 → 1.2.6
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 +265 -251
- 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 -2
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import R from "pino";
|
|
2
2
|
import U from "pino-pretty";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
3
|
+
import B 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 = U({
|
|
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,74 @@ 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
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
throw new Error("The get method of IStorage has not been implemented.");
|
|
185
|
+
}, z = (s, e) => {
|
|
186
|
+
if (s.set)
|
|
187
|
+
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);
|
|
188
|
+
else
|
|
189
|
+
throw new Error("The set method of IStorage has not been implemented.");
|
|
190
|
+
}, Q = (s) => {
|
|
191
|
+
if (s.get) {
|
|
192
|
+
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 = {};
|
|
193
|
+
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;
|
|
194
|
+
}
|
|
195
|
+
throw new Error("The get method of ICookies has not been implemented.");
|
|
196
|
+
}, Z = (s, e) => {
|
|
197
|
+
if (s.set)
|
|
198
|
+
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);
|
|
199
|
+
else
|
|
200
|
+
throw new Error("The set method of ICookies has not been implemented.");
|
|
201
|
+
}, ee = (s) => {
|
|
202
|
+
if (s.get) {
|
|
203
|
+
const e = s.get(f.IBOOT_USER);
|
|
204
|
+
if (e && e.length > 0)
|
|
205
|
+
return JSON.parse(e);
|
|
190
206
|
}
|
|
191
|
-
},
|
|
192
|
-
if (
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
207
|
+
}, te = (s) => {
|
|
208
|
+
if (s.get) {
|
|
209
|
+
const e = s.get(f.IBOOT_USER);
|
|
210
|
+
if (e && e.length > 0) {
|
|
211
|
+
const t = JSON.parse(e), n = t.username, r = t.userType.toString(), o = s.get(f.IBOOT_TOKEN);
|
|
196
212
|
if (o)
|
|
197
213
|
return {
|
|
198
|
-
username:
|
|
199
|
-
utype:
|
|
214
|
+
username: n,
|
|
215
|
+
utype: r,
|
|
200
216
|
token: o
|
|
201
217
|
};
|
|
202
218
|
}
|
|
203
219
|
}
|
|
204
|
-
},
|
|
205
|
-
const { id:
|
|
206
|
-
id:
|
|
207
|
-
name:
|
|
208
|
-
username:
|
|
209
|
-
nickname: o ||
|
|
220
|
+
}, se = (s, e) => {
|
|
221
|
+
const { id: t, name: n, username: r, nickname: o, headImg: i, token: a, lastLoginTime: c, deviceId: l, userType: h, mustChangePwd: E } = s, u = {
|
|
222
|
+
id: t,
|
|
223
|
+
name: n,
|
|
224
|
+
username: r,
|
|
225
|
+
nickname: o || n,
|
|
210
226
|
headImg: i,
|
|
211
227
|
lastLoginTime: c,
|
|
212
228
|
deviceId: l,
|
|
@@ -214,34 +230,34 @@ const F = {
|
|
|
214
230
|
accountType: 0,
|
|
215
231
|
needToReview: !1,
|
|
216
232
|
socketOnline: !1,
|
|
217
|
-
mustChangePwd:
|
|
233
|
+
mustChangePwd: E
|
|
218
234
|
};
|
|
219
|
-
if (!
|
|
235
|
+
if (!e.set)
|
|
220
236
|
throw new Error("cookies set function is undefined");
|
|
221
|
-
|
|
237
|
+
e.set(f.IBOOT_TOKEN, a, {
|
|
222
238
|
path: "/",
|
|
223
239
|
secure: process.env.APP_ENV === "production",
|
|
224
240
|
httpOnly: !0,
|
|
225
241
|
sameSite: "strict"
|
|
226
|
-
}),
|
|
227
|
-
},
|
|
228
|
-
if (!
|
|
242
|
+
}), e.set(f.IBOOT_USER, JSON.stringify(u));
|
|
243
|
+
}, re = (s) => {
|
|
244
|
+
if (!s.set)
|
|
229
245
|
throw new Error("cookies set function is undefined");
|
|
230
|
-
if (
|
|
246
|
+
if (s.set(f.IBOOT_TOKEN, "", {
|
|
231
247
|
maxAge: -1,
|
|
232
248
|
//设置为 -1表示立即过期
|
|
233
249
|
httpOnly: !0,
|
|
234
250
|
path: "/"
|
|
235
|
-
}),
|
|
251
|
+
}), s.set(f.IBOOT_USER, "", {
|
|
236
252
|
maxAge: -1,
|
|
237
253
|
//设置为 -1表示立即过期
|
|
238
254
|
httpOnly: !0,
|
|
239
255
|
path: "/"
|
|
240
|
-
}), !
|
|
256
|
+
}), !s.delete)
|
|
241
257
|
throw new Error("cookies delete function is undefined");
|
|
242
|
-
|
|
258
|
+
s.delete(f.IBOOT_TOKEN), s.delete(f.IBOOT_USER);
|
|
243
259
|
};
|
|
244
|
-
class
|
|
260
|
+
class ne {
|
|
245
261
|
baseUrl;
|
|
246
262
|
helloMethod;
|
|
247
263
|
apiKey;
|
|
@@ -252,141 +268,141 @@ class te {
|
|
|
252
268
|
lang;
|
|
253
269
|
websiteId;
|
|
254
270
|
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 =
|
|
271
|
+
constructor(e) {
|
|
272
|
+
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
273
|
}
|
|
258
|
-
encrypt(
|
|
259
|
-
const
|
|
260
|
-
return
|
|
274
|
+
encrypt(e) {
|
|
275
|
+
const t = I.enc.Utf8.parse(this.apiKey);
|
|
276
|
+
return I.AES.encrypt(e, t).toString();
|
|
261
277
|
}
|
|
262
|
-
decrypt(
|
|
263
|
-
const
|
|
264
|
-
return
|
|
265
|
-
mode:
|
|
266
|
-
}).toString(
|
|
278
|
+
decrypt(e) {
|
|
279
|
+
const t = I.enc.Utf8.parse(this.apiKey);
|
|
280
|
+
return I.AES.decrypt(e, t, {
|
|
281
|
+
mode: I.mode.ECB
|
|
282
|
+
}).toString(I.enc.Utf8);
|
|
267
283
|
}
|
|
268
284
|
//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 (
|
|
285
|
+
convertUrlParameter(e) {
|
|
286
|
+
const t = [];
|
|
287
|
+
for (const n in e) {
|
|
288
|
+
let r = e[n];
|
|
289
|
+
if (r && typeof r == "string")
|
|
290
|
+
r = r.trim();
|
|
291
|
+
else if (r && typeof r == "object") {
|
|
292
|
+
if (O(r)) {
|
|
293
|
+
if (r.length === 0)
|
|
278
294
|
continue;
|
|
279
|
-
for (let o = 0; o <
|
|
280
|
-
const i =
|
|
295
|
+
for (let o = 0; o < r.length; o++) {
|
|
296
|
+
const i = r[o];
|
|
281
297
|
for (const a in i) {
|
|
282
298
|
const c = i[a] ?? void 0;
|
|
283
299
|
if (c) {
|
|
284
300
|
if (typeof c == "object")
|
|
285
301
|
O(c) && c.forEach((l, h) => {
|
|
286
302
|
if (l)
|
|
287
|
-
for (const
|
|
288
|
-
const u = l[
|
|
303
|
+
for (const E in l) {
|
|
304
|
+
const u = l[E];
|
|
289
305
|
if (u && u.toString().length > 0) {
|
|
290
|
-
const
|
|
291
|
-
|
|
306
|
+
const g = `[${o.toString()}].${a + `[${h.toString()}].${E}`}=${T(u)}`;
|
|
307
|
+
t.push(n + g);
|
|
292
308
|
}
|
|
293
309
|
}
|
|
294
310
|
});
|
|
295
311
|
else if (c.toString().length > 0) {
|
|
296
|
-
const l = `[${o.toString()}].${a}=${
|
|
297
|
-
|
|
312
|
+
const l = `[${o.toString()}].${a}=${T(c.toString())}`;
|
|
313
|
+
t.push(n + l);
|
|
298
314
|
}
|
|
299
315
|
}
|
|
300
316
|
}
|
|
301
317
|
}
|
|
302
318
|
} else
|
|
303
|
-
for (const o in
|
|
304
|
-
const i =
|
|
319
|
+
for (const o in r) {
|
|
320
|
+
const i = r[o];
|
|
305
321
|
if (i != null && i != "" && i.length != 0) {
|
|
306
|
-
const a = `.${o}=${
|
|
307
|
-
|
|
322
|
+
const a = `.${o}=${T(i)}`;
|
|
323
|
+
t.push(n + a);
|
|
308
324
|
}
|
|
309
325
|
}
|
|
310
326
|
continue;
|
|
311
|
-
} else
|
|
312
|
-
|
|
327
|
+
} else r && typeof r == "function" && (r = null);
|
|
328
|
+
r != null && r != "" && r.length != 0 && t.push(n + "=" + T(r));
|
|
313
329
|
}
|
|
314
|
-
return
|
|
330
|
+
return t && t.join("&");
|
|
315
331
|
}
|
|
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)),
|
|
332
|
+
async sign(e) {
|
|
333
|
+
const t = "&key=" + await this.helloIboot(), n = [];
|
|
334
|
+
for (const c in e)
|
|
335
|
+
n.push(c);
|
|
336
|
+
n.sort((c, l) => c.toLowerCase().localeCompare(l.toLowerCase()));
|
|
337
|
+
const r = [];
|
|
338
|
+
n.forEach((c) => {
|
|
339
|
+
let l = e[c];
|
|
340
|
+
typeof l == "object" && (l = JSON.stringify(l)), r.push(c + "=" + l);
|
|
325
341
|
});
|
|
326
|
-
const o =
|
|
342
|
+
const o = r.join("&"), i = B.md5((o + t).toLocaleUpperCase()), a = {
|
|
327
343
|
params: o,
|
|
328
344
|
md5: i
|
|
329
345
|
};
|
|
330
346
|
return d.debug(a, "API_SIGN"), i;
|
|
331
347
|
}
|
|
332
348
|
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
333
|
-
assemblyParameter(
|
|
334
|
-
const
|
|
335
|
-
return
|
|
349
|
+
assemblyParameter(e, t) {
|
|
350
|
+
const n = e ?? {};
|
|
351
|
+
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
352
|
}
|
|
337
|
-
async assemblyHeader({ urlParams:
|
|
338
|
-
const
|
|
353
|
+
async assemblyHeader({ urlParams: e, token: t }) {
|
|
354
|
+
const n = {
|
|
339
355
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
340
356
|
"Res-Type": "json",
|
|
341
357
|
"Device-Id": this.deviceId,
|
|
342
|
-
"User-Type":
|
|
358
|
+
"User-Type": t?.utype.toString() ?? this.userType.toString(),
|
|
343
359
|
"User-From": this.userFrom,
|
|
344
360
|
"Api-Key": this.apiKey
|
|
345
361
|
};
|
|
346
|
-
this.lang && this.lang.length > 0 && (
|
|
347
|
-
const
|
|
348
|
-
return
|
|
362
|
+
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));
|
|
363
|
+
const r = L(e), o = await this.sign(r);
|
|
364
|
+
return n.Sign = o, n;
|
|
349
365
|
}
|
|
350
366
|
async helloIboot() {
|
|
351
367
|
if (this.helloMethod.length <= 0)
|
|
352
368
|
return this.apiKey;
|
|
353
|
-
const
|
|
369
|
+
const e = this.getApiUrl(this.helloMethod), t = {
|
|
354
370
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
355
371
|
"Res-Type": "json",
|
|
356
372
|
"Api-Key": this.apiKey
|
|
357
|
-
},
|
|
358
|
-
url:
|
|
359
|
-
headers:
|
|
373
|
+
}, n = {
|
|
374
|
+
url: e,
|
|
375
|
+
headers: t
|
|
360
376
|
};
|
|
361
|
-
d.debug(
|
|
362
|
-
const
|
|
377
|
+
d.debug(n, "HELLO");
|
|
378
|
+
const r = await fetch(e, {
|
|
363
379
|
method: "GET",
|
|
364
|
-
headers:
|
|
380
|
+
headers: t,
|
|
365
381
|
credentials: "include",
|
|
366
382
|
cache: "force-cache"
|
|
367
383
|
});
|
|
368
|
-
if (
|
|
369
|
-
const o = await
|
|
384
|
+
if (r.ok) {
|
|
385
|
+
const o = await r.json();
|
|
370
386
|
return d.debug(o.data, "HELLO RESULT"), o.data;
|
|
371
387
|
}
|
|
372
388
|
throw new Error("hello iBoot error!");
|
|
373
389
|
}
|
|
374
|
-
getApiUrl(
|
|
375
|
-
return `${this.baseUrl}/${
|
|
390
|
+
getApiUrl(e) {
|
|
391
|
+
return `${this.baseUrl}/${e}`;
|
|
376
392
|
}
|
|
377
393
|
async csrf() {
|
|
378
|
-
const
|
|
394
|
+
const e = await this.get({
|
|
379
395
|
url: "guest/csrf"
|
|
380
396
|
});
|
|
381
|
-
if (
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
return
|
|
397
|
+
if (e.success) {
|
|
398
|
+
const t = e.data;
|
|
399
|
+
if (t)
|
|
400
|
+
return t.csrfToken.toString();
|
|
385
401
|
}
|
|
386
402
|
}
|
|
387
403
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
388
|
-
async get({ url:
|
|
389
|
-
const o = this.assemblyParameter(
|
|
404
|
+
async get({ url: e, data: t, token: n, cache: r = "default" }) {
|
|
405
|
+
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
406
|
url: c,
|
|
391
407
|
headers: a
|
|
392
408
|
};
|
|
@@ -395,78 +411,78 @@ class te {
|
|
|
395
411
|
method: "GET",
|
|
396
412
|
headers: a,
|
|
397
413
|
credentials: "include",
|
|
398
|
-
cache:
|
|
414
|
+
cache: r
|
|
399
415
|
});
|
|
400
416
|
if (h.ok) {
|
|
401
|
-
const u = Object.fromEntries(h.headers.entries()),
|
|
402
|
-
return d.debug(
|
|
417
|
+
const u = Object.fromEntries(h.headers.entries()), g = { ...await h.json(), headers: u };
|
|
418
|
+
return d.debug(g, "GET_RESULT"), g;
|
|
403
419
|
}
|
|
404
|
-
const
|
|
420
|
+
const E = {
|
|
405
421
|
code: h.status,
|
|
406
422
|
success: !1,
|
|
407
423
|
msg: h.statusText
|
|
408
424
|
};
|
|
409
|
-
return d.error(
|
|
425
|
+
return d.error(E), E;
|
|
410
426
|
}
|
|
411
427
|
// 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(
|
|
428
|
+
async post({ url: e, data: t, token: n, cache: r = "default" }) {
|
|
429
|
+
t = t ? { ...t } : {};
|
|
430
|
+
const o = t.buffer ?? void 0, i = t.boundary ?? void 0;
|
|
431
|
+
o && delete t.buffer, i && delete t.boundary;
|
|
432
|
+
const a = this.assemblyParameter(t), c = this.convertUrlParameter(a), l = await this.assemblyHeader({ urlParams: c, token: n });
|
|
417
433
|
o && i && (l["Content-Type"] = `multipart/form-data; boundary=${i}`);
|
|
418
|
-
const h = this.getApiUrl(
|
|
434
|
+
const h = this.getApiUrl(e), E = {
|
|
419
435
|
url: h,
|
|
420
436
|
headers: l,
|
|
421
437
|
params: a
|
|
422
438
|
};
|
|
423
|
-
d.info(
|
|
424
|
-
const u = o ? `${h}?${c}` : h,
|
|
439
|
+
d.info(E, "POST");
|
|
440
|
+
const u = o ? `${h}?${c}` : h, g = await fetch(u, {
|
|
425
441
|
method: "POST",
|
|
426
442
|
headers: l,
|
|
427
443
|
body: o || c.toString(),
|
|
428
444
|
credentials: "include",
|
|
429
|
-
cache:
|
|
445
|
+
cache: r
|
|
430
446
|
});
|
|
431
|
-
if (
|
|
432
|
-
const
|
|
433
|
-
return d.debug(
|
|
447
|
+
if (g.ok) {
|
|
448
|
+
const A = Object.fromEntries(g.headers.entries()), y = { ...await g.json(), headers: A };
|
|
449
|
+
return d.debug(y, "POST_RESULT"), y;
|
|
434
450
|
}
|
|
435
|
-
const
|
|
436
|
-
code:
|
|
451
|
+
const p = {
|
|
452
|
+
code: g.status,
|
|
437
453
|
success: !1,
|
|
438
|
-
msg:
|
|
454
|
+
msg: g.statusText
|
|
439
455
|
};
|
|
440
|
-
return d.error(
|
|
456
|
+
return d.error(p), p;
|
|
441
457
|
}
|
|
442
458
|
// 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(
|
|
459
|
+
async stream({ url: e, data: t, token: n }) {
|
|
460
|
+
t = t ? { ...t } : {};
|
|
461
|
+
const r = t.buffer ?? void 0, o = t.boundary ?? void 0;
|
|
462
|
+
r && delete t.buffer, o && delete t.boundary;
|
|
463
|
+
const i = this.assemblyParameter(t), a = this.convertUrlParameter(i), c = await this.assemblyHeader({ urlParams: a, token: n });
|
|
464
|
+
r && o && (c["Content-Type"] = `multipart/form-data; boundary=${o}`), c.Connection = "keep-alive", c["X-Accel-Buffering"] = "no", c["Cache-Control"] = "no-cache";
|
|
465
|
+
const l = this.getApiUrl(e);
|
|
450
466
|
try {
|
|
451
|
-
const h =
|
|
467
|
+
const h = r ? `${l}?${a}` : l, E = {
|
|
452
468
|
url: l,
|
|
453
469
|
headers: c,
|
|
454
470
|
params: i
|
|
455
471
|
};
|
|
456
|
-
d.info(
|
|
472
|
+
d.info(E, "STREAM");
|
|
457
473
|
const u = await fetch(h, {
|
|
458
474
|
method: "POST",
|
|
459
475
|
headers: c,
|
|
460
|
-
body:
|
|
476
|
+
body: r || a.toString(),
|
|
461
477
|
credentials: "include"
|
|
462
478
|
});
|
|
463
479
|
if (!u.ok)
|
|
464
480
|
throw new Error(`HTTP error! status: ${u.status}`);
|
|
465
481
|
if (!u.body)
|
|
466
482
|
throw new Error("No response body");
|
|
467
|
-
const
|
|
483
|
+
const g = Object.fromEntries(u.headers.entries());
|
|
468
484
|
return new Response(u.body, {
|
|
469
|
-
headers:
|
|
485
|
+
headers: g
|
|
470
486
|
});
|
|
471
487
|
} catch (h) {
|
|
472
488
|
throw h;
|
|
@@ -474,32 +490,30 @@ class te {
|
|
|
474
490
|
}
|
|
475
491
|
}
|
|
476
492
|
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,
|
|
493
|
+
K as ACCOUNT_TYPE_MAP,
|
|
494
|
+
ne as HttpClient,
|
|
495
|
+
G as USER_FORM_MAP,
|
|
496
|
+
F as USER_SEX_MAP,
|
|
486
497
|
C as USER_TYPE_MAP,
|
|
487
|
-
|
|
498
|
+
re as cleanToken,
|
|
488
499
|
k as dateFormat,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
500
|
+
H as get,
|
|
501
|
+
ee as getLoginUser,
|
|
502
|
+
Q as getServerHttpCookies,
|
|
503
|
+
q as getServerHttpOpts,
|
|
504
|
+
te as getToken,
|
|
505
|
+
Y as iGet,
|
|
506
|
+
J as iPost,
|
|
495
507
|
X as iPostSuccess,
|
|
496
508
|
O as isArray,
|
|
497
509
|
d as logger,
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
Z as
|
|
502
|
-
|
|
510
|
+
v as post,
|
|
511
|
+
b as randomString,
|
|
512
|
+
V as setClientRequestHeader,
|
|
513
|
+
Z as setServerHttpCookies,
|
|
514
|
+
z as setServerHttpHeaders,
|
|
515
|
+
se as setToken,
|
|
516
|
+
T as urlEncode,
|
|
503
517
|
L as urlParamToJson
|
|
504
518
|
};
|
|
505
519
|
//# sourceMappingURL=iboot-http-client.es.js.map
|