@dplugin/core 2.0.12 → 2.1.1
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/index.cjs +2 -2
- package/dist/index.mjs +428 -699
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const I = {
|
|
2
2
|
// 接口前缀。'' = 同源;也可以是 https://api.company.com
|
|
3
3
|
apiBase: "",
|
|
4
4
|
// 运行模式:'auto' 按同源自动判定;'cookie' 强制同域 Cookie;'sign' 强制跨域签名
|
|
@@ -20,141 +20,120 @@ const U = {
|
|
|
20
20
|
// 登出或会话失效(可选),(reason) => void
|
|
21
21
|
onLogout: null,
|
|
22
22
|
// 原生能力体检:'warn' 只告警 / 'error' 直接抛错 / 'off' 不检查
|
|
23
|
-
nativeGuard: "
|
|
23
|
+
nativeGuard: "error"
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
return e && Object.keys(
|
|
27
|
-
e[
|
|
28
|
-
}),
|
|
25
|
+
function ie(e) {
|
|
26
|
+
return e && Object.keys(I).forEach((n) => {
|
|
27
|
+
e[n] !== void 0 && (I[n] = e[n]);
|
|
28
|
+
}), I;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
30
|
+
function y() {
|
|
31
|
+
return I;
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
function
|
|
33
|
+
const a = se();
|
|
34
|
+
function B(e, n) {
|
|
35
35
|
if (typeof e != "function")
|
|
36
36
|
return !1;
|
|
37
|
-
let
|
|
37
|
+
let t;
|
|
38
38
|
try {
|
|
39
|
-
|
|
40
|
-
} catch (
|
|
39
|
+
t = Function.prototype.toString.call(e);
|
|
40
|
+
} catch (o) {
|
|
41
41
|
return !1;
|
|
42
42
|
}
|
|
43
|
-
const
|
|
44
|
-
return
|
|
43
|
+
const r = /^function\s+([\w$]+)\s*\(\s*\)\s*\{\s*\[native code\]\s*\}$/.exec(t);
|
|
44
|
+
return r ? r[1] === n : /\[native code\]/.test(t) && !/^function\s*\(\s*\)\s*\{\s*\[native code\]\s*\}$/.test(t);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function oe(e) {
|
|
47
47
|
try {
|
|
48
|
-
const
|
|
49
|
-
return
|
|
48
|
+
const n = e();
|
|
49
|
+
return n && typeof n.then == "function" && Promise.resolve(n).catch(() => {
|
|
50
50
|
}), !1;
|
|
51
|
-
} catch (
|
|
52
|
-
const
|
|
53
|
-
return !!
|
|
51
|
+
} catch (n) {
|
|
52
|
+
const t = String(n && n.message || "");
|
|
53
|
+
return !!n && n.name === "TypeError" && /argument|required|参数/i.test(t);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
const e = globalThis,
|
|
56
|
+
function se() {
|
|
57
|
+
const e = globalThis, n = typeof e.window != "undefined" && e.window && typeof e.window.document != "undefined", t = {
|
|
58
58
|
fetch: null,
|
|
59
59
|
idbOpen: null,
|
|
60
60
|
subtle: null,
|
|
61
61
|
pristine: { fetch: !1, idbOpen: !1, subtle: !1 }
|
|
62
62
|
};
|
|
63
|
-
typeof e.fetch == "function" && (
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
const
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
typeof
|
|
70
|
-
}),
|
|
63
|
+
typeof e.fetch == "function" && (t.pristine.fetch = B(e.fetch, "fetch"), t.fetch = e.fetch.bind(e)), typeof e.indexedDB != "undefined" && e.indexedDB && typeof e.indexedDB.open == "function" && (t.pristine.idbOpen = B(e.indexedDB.open, "open") && (!n || oe(() => e.indexedDB.open())), t.idbOpen = e.indexedDB.open.bind(e.indexedDB));
|
|
64
|
+
const r = e.crypto && e.crypto.subtle ? e.crypto.subtle : null;
|
|
65
|
+
if (r) {
|
|
66
|
+
const o = ["generateKey", "exportKey", "importKey", "sign", "verify", "digest"], i = {};
|
|
67
|
+
let s = !0;
|
|
68
|
+
o.forEach((c) => {
|
|
69
|
+
typeof r[c] == "function" && (i[c] = r[c].bind(r), s = s && B(r[c], c));
|
|
70
|
+
}), t.subtle = i, t.pristine.subtle = s;
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return t;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function ce() {
|
|
75
75
|
if (typeof window == "undefined" || typeof window.document == "undefined")
|
|
76
76
|
return [];
|
|
77
77
|
const e = [];
|
|
78
|
-
return
|
|
78
|
+
return a.fetch && !a.pristine.fetch && e.push("fetch"), a.idbOpen && !a.pristine.idbOpen && e.push("indexedDB.open"), a.subtle && !a.pristine.subtle && e.push("crypto.subtle"), e;
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const f = {
|
|
81
81
|
OK: "200",
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
FORBIDDEN: "401001",
|
|
85
|
-
CORS_DENIED: "403",
|
|
86
|
-
API_NOT_FOUND: "404",
|
|
82
|
+
LOGIN_PENDING: "202",
|
|
83
|
+
LOGIN_TIMEOUT: "g.login.timeout",
|
|
87
84
|
NETWORK: "NETWORK",
|
|
88
85
|
TIMEOUT: "TIMEOUT"
|
|
89
86
|
};
|
|
90
|
-
class
|
|
91
|
-
constructor(
|
|
92
|
-
super(
|
|
87
|
+
class h extends Error {
|
|
88
|
+
constructor(n, t) {
|
|
89
|
+
super(t || "请求失败"), this.name = "BizError", this.code = n;
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
|
-
class
|
|
96
|
-
constructor(
|
|
97
|
-
super(
|
|
92
|
+
class ue extends h {
|
|
93
|
+
constructor(n) {
|
|
94
|
+
super(f.LOGIN_TIMEOUT, n || "登录已失效"), this.name = "AuthError";
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
const $ = "dplugin.access", q = "dplugin.sid", le = "dplugin.ds", z = "dplugin.exp", J = "dplugin.cookie";
|
|
104
|
-
function _e(e) {
|
|
97
|
+
const V = "dp.token", U = "dp.sid", Y = "dp.ds";
|
|
98
|
+
function ae(e) {
|
|
105
99
|
try {
|
|
106
100
|
return localStorage.getItem(e);
|
|
107
|
-
} catch (
|
|
101
|
+
} catch (n) {
|
|
108
102
|
return null;
|
|
109
103
|
}
|
|
110
104
|
}
|
|
111
|
-
function
|
|
105
|
+
function X(e, n) {
|
|
112
106
|
try {
|
|
113
|
-
|
|
114
|
-
} catch (
|
|
107
|
+
n == null || n === "" ? localStorage.removeItem(e) : localStorage.setItem(e, n);
|
|
108
|
+
} catch (t) {
|
|
115
109
|
}
|
|
116
110
|
}
|
|
117
|
-
const
|
|
118
|
-
function
|
|
119
|
-
const
|
|
120
|
-
return
|
|
111
|
+
const D = {};
|
|
112
|
+
function F(e) {
|
|
113
|
+
const n = ae(e);
|
|
114
|
+
return n === null ? D[e] === void 0 ? null : D[e] : n;
|
|
121
115
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
116
|
+
function H(e, n) {
|
|
117
|
+
D[e] = n, X(e, n);
|
|
124
118
|
}
|
|
125
|
-
const
|
|
126
|
-
get
|
|
127
|
-
return
|
|
119
|
+
const u = {
|
|
120
|
+
get token() {
|
|
121
|
+
return F(V);
|
|
128
122
|
},
|
|
129
|
-
set
|
|
130
|
-
|
|
123
|
+
set token(e) {
|
|
124
|
+
H(V, e);
|
|
131
125
|
},
|
|
132
126
|
get sid() {
|
|
133
|
-
return
|
|
127
|
+
return F(U);
|
|
134
128
|
},
|
|
135
129
|
set sid(e) {
|
|
136
|
-
|
|
130
|
+
H(U, e);
|
|
137
131
|
},
|
|
138
132
|
get ds() {
|
|
139
|
-
return
|
|
133
|
+
return F(Y);
|
|
140
134
|
},
|
|
141
135
|
set ds(e) {
|
|
142
|
-
|
|
143
|
-
},
|
|
144
|
-
/** access 的到期时间(毫秒时间戳)。仅用于界面判断,不要拿它做提前续期 */
|
|
145
|
-
get exp() {
|
|
146
|
-
const e = x(z);
|
|
147
|
-
return e ? Number(e) : 0;
|
|
148
|
-
},
|
|
149
|
-
set exp(e) {
|
|
150
|
-
C(z, e ? String(e) : null);
|
|
151
|
-
},
|
|
152
|
-
/** cookie 模式:本地只记「可能已登录」,实际有效性由第一次请求的结果决定 */
|
|
153
|
-
get cookie() {
|
|
154
|
-
return x(J) === "1";
|
|
155
|
-
},
|
|
156
|
-
set cookie(e) {
|
|
157
|
-
C(J, e ? "1" : null);
|
|
136
|
+
H(Y, e);
|
|
158
137
|
},
|
|
159
138
|
/**
|
|
160
139
|
* 清登录态。
|
|
@@ -163,302 +142,297 @@ const i = {
|
|
|
163
142
|
* 下次登录后端就会新建一条设备记录(common_login_device 无限膨胀)。
|
|
164
143
|
*/
|
|
165
144
|
clear() {
|
|
166
|
-
[
|
|
167
|
-
|
|
145
|
+
[V, U].forEach((e) => {
|
|
146
|
+
D[e] = null, X(e, null);
|
|
168
147
|
});
|
|
169
148
|
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return /^https?:\/\//i.test(e) || (o = (n ? n.replace(/\/+$/, "") : "") + (e.startsWith("/") ? e : "/" + e)), t && (o += (o.includes("?") ? "&" : "?") + t), o;
|
|
175
|
-
}
|
|
176
|
-
function V(e) {
|
|
177
|
-
const t = g(e);
|
|
178
|
-
if (/^https?:\/\//i.test(t))
|
|
179
|
-
try {
|
|
180
|
-
return new URL(t).pathname;
|
|
181
|
-
} catch (n) {
|
|
182
|
-
return t.split("?")[0];
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
return new URL(t, "http://localhost").pathname;
|
|
186
|
-
} catch (n) {
|
|
187
|
-
return t.split("?")[0];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
let S = null;
|
|
191
|
-
function Ue(e) {
|
|
192
|
-
try {
|
|
193
|
-
const t = typeof location != "undefined" ? location.href : void 0;
|
|
194
|
-
return new URL(e || "", t).origin;
|
|
195
|
-
} catch (t) {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function Me() {
|
|
200
|
-
S = null;
|
|
201
|
-
}
|
|
202
|
-
function pe() {
|
|
203
|
-
if (S)
|
|
204
|
-
return S;
|
|
205
|
-
const e = I();
|
|
206
|
-
if (e.mode === "sign" || e.mode === "cookie")
|
|
207
|
-
return S = e.mode, S;
|
|
208
|
-
const t = typeof location != "undefined" ? location.origin : null;
|
|
209
|
-
if (!t)
|
|
210
|
-
return S = "sign", S;
|
|
211
|
-
const n = Ue(e.apiBase || t);
|
|
212
|
-
return S = n && n === t ? "cookie" : "sign", S;
|
|
213
|
-
}
|
|
214
|
-
function b() {
|
|
215
|
-
return pe() === "cookie";
|
|
216
|
-
}
|
|
217
|
-
async function h(e, t, n) {
|
|
218
|
-
const o = I(), r = n || o.timeout, s = typeof AbortController != "undefined" ? new AbortController() : null, a = s ? setTimeout(() => s.abort(), r) : null, c = {
|
|
219
|
-
method: "POST",
|
|
220
|
-
// cookie 模式必须带上 Cookie(同源不涉及 CORS);sign 模式主动不带,减少暴露面
|
|
221
|
-
credentials: b() ? "same-origin" : "omit",
|
|
222
|
-
signal: s ? s.signal : void 0
|
|
223
|
-
};
|
|
224
|
-
if (typeof FormData != "undefined" && t instanceof FormData ? c.body = t : t != null && (c.headers = { "Content-Type": "text/plain" }, c.body = JSON.stringify(t)), !E.fetch)
|
|
225
|
-
throw new m(u.NETWORK, "当前环境不支持 fetch");
|
|
226
|
-
let f;
|
|
227
|
-
try {
|
|
228
|
-
f = await E.fetch(e, c);
|
|
229
|
-
} catch (y) {
|
|
230
|
-
throw a && clearTimeout(a), y && y.name === "AbortError" ? new m(u.TIMEOUT, "请求超时,请重试") : new m(u.NETWORK, "网络异常,请检查网络后重试");
|
|
231
|
-
}
|
|
232
|
-
a && clearTimeout(a);
|
|
233
|
-
const d = await f.text();
|
|
234
|
-
let l = null;
|
|
235
|
-
if (d)
|
|
236
|
-
try {
|
|
237
|
-
l = JSON.parse(d);
|
|
238
|
-
} catch (y) {
|
|
239
|
-
l = null;
|
|
240
|
-
}
|
|
241
|
-
if (!f.ok)
|
|
242
|
-
throw new m(String(f.status), l && l.message || d || "请求失败");
|
|
243
|
-
if (!l || l.code === null || l.code === void 0)
|
|
244
|
-
throw new m("500", "响应格式异常");
|
|
245
|
-
return l.code = String(l.code), l;
|
|
246
|
-
}
|
|
247
|
-
const ke = "dplugin-auth", Le = 1, Y = "keys", oe = "sso", re = "domain", ve = { name: "ECDSA", namedCurve: "P-256" }, Fe = { name: "ECDSA", hash: "SHA-256" }, F = /* @__PURE__ */ new Map();
|
|
248
|
-
let L = null;
|
|
249
|
-
function j() {
|
|
250
|
-
if (!E.subtle) {
|
|
149
|
+
}, fe = "dplugin", le = 1, M = "keys", de = { name: "ECDSA", namedCurve: "P-256" }, ge = { name: "ECDSA", hash: "SHA-256" }, x = /* @__PURE__ */ new Map();
|
|
150
|
+
let K = null;
|
|
151
|
+
function v() {
|
|
152
|
+
if (!a.subtle) {
|
|
251
153
|
const e = typeof location != "undefined" && location.origin ? location.origin : "(未知 origin)";
|
|
252
154
|
throw new Error("[dplugin/core] crypto.subtle 不存在:浏览器只在**安全上下文**里提供它(https、http://localhost、http://127.0.0.1、http://[::1]、file://);当前 origin=" + e);
|
|
253
155
|
}
|
|
254
|
-
return
|
|
156
|
+
return a.subtle;
|
|
255
157
|
}
|
|
256
|
-
function
|
|
257
|
-
return
|
|
258
|
-
if (!
|
|
158
|
+
function he() {
|
|
159
|
+
return K || (K = new Promise((e) => {
|
|
160
|
+
if (!a.idbOpen) {
|
|
259
161
|
e(null);
|
|
260
162
|
return;
|
|
261
163
|
}
|
|
262
|
-
let
|
|
164
|
+
let n;
|
|
263
165
|
try {
|
|
264
|
-
|
|
265
|
-
} catch (
|
|
166
|
+
n = a.idbOpen(fe, le);
|
|
167
|
+
} catch (t) {
|
|
266
168
|
e(null);
|
|
267
169
|
return;
|
|
268
170
|
}
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
},
|
|
273
|
-
}),
|
|
274
|
-
}
|
|
275
|
-
function
|
|
276
|
-
return
|
|
277
|
-
let
|
|
171
|
+
n.onupgradeneeded = () => {
|
|
172
|
+
const t = n.result;
|
|
173
|
+
t.objectStoreNames.contains(M) || t.createObjectStore(M);
|
|
174
|
+
}, n.onsuccess = () => e(n.result), n.onerror = () => e(null), n.onblocked = () => e(null);
|
|
175
|
+
}), K);
|
|
176
|
+
}
|
|
177
|
+
function q(e, n) {
|
|
178
|
+
return he().then((t) => t ? new Promise((r) => {
|
|
179
|
+
let o;
|
|
278
180
|
try {
|
|
279
|
-
|
|
181
|
+
o = t.transaction(M, e);
|
|
280
182
|
} catch (c) {
|
|
281
|
-
|
|
183
|
+
r(null);
|
|
282
184
|
return;
|
|
283
185
|
}
|
|
284
|
-
const
|
|
285
|
-
let
|
|
186
|
+
const i = o.objectStore(M);
|
|
187
|
+
let s = null;
|
|
286
188
|
try {
|
|
287
|
-
const c =
|
|
189
|
+
const c = n(i);
|
|
288
190
|
c && (c.onsuccess = () => {
|
|
289
|
-
|
|
191
|
+
s = c.result;
|
|
290
192
|
}, c.onerror = () => {
|
|
291
|
-
|
|
193
|
+
s = null;
|
|
292
194
|
});
|
|
293
195
|
} catch (c) {
|
|
294
|
-
|
|
196
|
+
s = null;
|
|
295
197
|
}
|
|
296
|
-
|
|
198
|
+
o.oncomplete = () => r(s), o.onerror = () => r(null), o.onabort = () => r(null);
|
|
297
199
|
}) : null);
|
|
298
200
|
}
|
|
299
|
-
function
|
|
300
|
-
return
|
|
301
|
-
}
|
|
302
|
-
function Oe(e, t) {
|
|
303
|
-
return F.set(e, t), Ee("readwrite", (n) => n.put(t, e)).then(() => t);
|
|
304
|
-
}
|
|
305
|
-
async function ie(e) {
|
|
306
|
-
const n = await j().generateKey(ve, !1, ["sign", "verify"]);
|
|
307
|
-
return Oe(e, n);
|
|
201
|
+
async function P(e) {
|
|
202
|
+
return x.has(e) ? Promise.resolve(x.get(e)) : q("readonly", (n) => n.get(e)).then((n) => (n && x.set(e, n), n || null));
|
|
308
203
|
}
|
|
309
|
-
|
|
310
|
-
|
|
204
|
+
function J(e) {
|
|
205
|
+
const n = new Uint8Array(e);
|
|
206
|
+
let t = "";
|
|
207
|
+
for (let r = 0; r < n.length; r++)
|
|
208
|
+
t += String.fromCharCode(n[r]);
|
|
209
|
+
return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
311
210
|
}
|
|
312
|
-
async function
|
|
313
|
-
|
|
211
|
+
async function Q(e) {
|
|
212
|
+
let n = await P(e);
|
|
213
|
+
return n || (n = await v().generateKey(de, !1, ["sign", "verify"]), x.set(e, n), q("readwrite", (r) => r.put(n, e)).then(() => n));
|
|
314
214
|
}
|
|
315
|
-
|
|
316
|
-
return
|
|
215
|
+
function pe() {
|
|
216
|
+
return Q("sso");
|
|
317
217
|
}
|
|
318
|
-
function
|
|
319
|
-
return
|
|
218
|
+
function we() {
|
|
219
|
+
return Q("domain");
|
|
320
220
|
}
|
|
321
|
-
function
|
|
322
|
-
return
|
|
221
|
+
async function me() {
|
|
222
|
+
return await P("sso");
|
|
323
223
|
}
|
|
324
|
-
function
|
|
325
|
-
return
|
|
224
|
+
async function Oe() {
|
|
225
|
+
return await P("domain");
|
|
326
226
|
}
|
|
327
|
-
function
|
|
328
|
-
|
|
227
|
+
async function ye() {
|
|
228
|
+
let e = await P("domain");
|
|
229
|
+
const n = v(), t = await n.exportKey("spki", e.publicKey), r = await n.digest("SHA-256", t);
|
|
230
|
+
return J(r);
|
|
329
231
|
}
|
|
330
|
-
async function
|
|
331
|
-
|
|
232
|
+
async function ee(e) {
|
|
233
|
+
let n = await P(e);
|
|
234
|
+
const r = await v().exportKey("spki", n.publicKey);
|
|
332
235
|
let o = "";
|
|
333
|
-
const
|
|
334
|
-
for (let s = 0; s <
|
|
335
|
-
o += String.fromCharCode(
|
|
236
|
+
const i = new Uint8Array(r);
|
|
237
|
+
for (let s = 0; s < i.length; s++)
|
|
238
|
+
o += String.fromCharCode(i[s]);
|
|
336
239
|
return btoa(o);
|
|
337
240
|
}
|
|
338
|
-
function
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return btoa(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
344
|
-
}
|
|
345
|
-
async function Ve(e, t) {
|
|
346
|
-
const o = await j().sign(Fe, e.privateKey, new TextEncoder().encode(t));
|
|
347
|
-
return Se(o);
|
|
348
|
-
}
|
|
349
|
-
async function Ie(e) {
|
|
350
|
-
const t = j(), n = await t.exportKey("spki", e.publicKey), o = await t.digest("SHA-256", n);
|
|
351
|
-
return Se(o);
|
|
352
|
-
}
|
|
353
|
-
const ee = {
|
|
354
|
-
SSO: oe,
|
|
355
|
-
DOMAIN: re
|
|
356
|
-
}, te = "-", je = "POST", N = {
|
|
241
|
+
async function Ee(e, n) {
|
|
242
|
+
const r = await v().sign(ge, e.privateKey, new TextEncoder().encode(n));
|
|
243
|
+
return J(r);
|
|
244
|
+
}
|
|
245
|
+
const Se = "-", _ = {
|
|
357
246
|
BIZ: "BIZ",
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
247
|
+
VTT: "VTT",
|
|
248
|
+
VSD: "VSD",
|
|
249
|
+
TOK: "TOK"
|
|
361
250
|
};
|
|
362
|
-
function
|
|
363
|
-
return e == null || e === "" ?
|
|
251
|
+
function O(e) {
|
|
252
|
+
return e == null || e === "" ? Se : String(e);
|
|
364
253
|
}
|
|
365
|
-
function
|
|
366
|
-
const
|
|
254
|
+
function be(e, n) {
|
|
255
|
+
const t = O(n.origin);
|
|
367
256
|
return [
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
257
|
+
e,
|
|
258
|
+
n.method,
|
|
259
|
+
n.path,
|
|
260
|
+
t.toLowerCase(),
|
|
261
|
+
O(n.ds),
|
|
262
|
+
n.ts,
|
|
263
|
+
O(n.token),
|
|
264
|
+
O(n.dna),
|
|
265
|
+
O(n.redirect)
|
|
377
266
|
].join(`
|
|
378
267
|
`);
|
|
379
268
|
}
|
|
380
|
-
function
|
|
381
|
-
return [
|
|
382
|
-
}
|
|
383
|
-
async function K(e, t, n) {
|
|
384
|
-
const o = n === "sso" ? await se() : await be();
|
|
385
|
-
if (!o)
|
|
386
|
-
throw Te(n === "sso" ? "缺少登录签名密钥" : "缺少业务签名密钥");
|
|
387
|
-
const r = await Ve(o, Xe(e, t));
|
|
388
|
-
return We(e, t, r);
|
|
389
|
-
}
|
|
390
|
-
async function ce(e, t, n) {
|
|
391
|
-
if (!t || !n)
|
|
392
|
-
throw Te("缺少 access 或 ds,无法签名");
|
|
393
|
-
const o = await K(N.BIZ, {
|
|
394
|
-
method: je,
|
|
395
|
-
path: V(e),
|
|
396
|
-
origin: A(),
|
|
397
|
-
ds: n,
|
|
398
|
-
ts: Date.now(),
|
|
399
|
-
subject: t
|
|
400
|
-
}, "domain");
|
|
401
|
-
return "dsign=" + encodeURIComponent(o);
|
|
269
|
+
function Te(e, n, t) {
|
|
270
|
+
return [e, O(n.token), O(n.ds), n.ts, t].join(".");
|
|
402
271
|
}
|
|
403
|
-
function
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
272
|
+
function ke(e) {
|
|
273
|
+
const n = new Error(e);
|
|
274
|
+
return n.code = "KEY_MISSING", n;
|
|
275
|
+
}
|
|
276
|
+
async function A(e, n, t) {
|
|
277
|
+
const r = t === "sso" ? await me() : await Oe();
|
|
278
|
+
if (!r)
|
|
279
|
+
throw ke(t === "sso" ? "缺少登录签名密钥" : "缺少业务签名密钥");
|
|
280
|
+
let o = n.path.indexOf("?");
|
|
281
|
+
o > 0 && (n.path = n.path.substring(0, o));
|
|
282
|
+
const i = await Ee(r, be(e, n));
|
|
283
|
+
return Te(e, n, i);
|
|
284
|
+
}
|
|
285
|
+
let g = null;
|
|
286
|
+
function Ie(e) {
|
|
408
287
|
try {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
288
|
+
const n = typeof location != "undefined" ? location.href : void 0;
|
|
289
|
+
return new URL(e || "", n).origin;
|
|
290
|
+
} catch (n) {
|
|
291
|
+
return null;
|
|
412
292
|
}
|
|
413
293
|
}
|
|
414
|
-
function
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
return
|
|
428
|
-
}
|
|
429
|
-
function
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
294
|
+
function Pe() {
|
|
295
|
+
g = null;
|
|
296
|
+
}
|
|
297
|
+
function Ne() {
|
|
298
|
+
if (g)
|
|
299
|
+
return g;
|
|
300
|
+
const e = y();
|
|
301
|
+
if (e.mode === "sign" || e.mode === "cookie")
|
|
302
|
+
return g = e.mode, g;
|
|
303
|
+
const n = typeof location != "undefined" ? location.origin : null;
|
|
304
|
+
if (!n)
|
|
305
|
+
return g = "sign", g;
|
|
306
|
+
const t = Ie(e.apiBase || n);
|
|
307
|
+
return g = t && t === n ? "cookie" : "sign", g;
|
|
308
|
+
}
|
|
309
|
+
function E() {
|
|
310
|
+
return Ne() === "cookie";
|
|
311
|
+
}
|
|
312
|
+
function Re(e, n) {
|
|
313
|
+
let t = y();
|
|
314
|
+
throw t.onError && n.showError && t.onError({ code: e.code, message: e.message }), new h(e.code, e.message);
|
|
315
|
+
}
|
|
316
|
+
let C, W = null;
|
|
317
|
+
function Ke() {
|
|
318
|
+
return C || (C = Promise.resolve().then(() => W()).finally(() => {
|
|
319
|
+
C = null;
|
|
320
|
+
})), C;
|
|
321
|
+
}
|
|
322
|
+
async function Ce(e, n, t, r, o) {
|
|
323
|
+
const i = y(), s = o || i.timeout, c = typeof AbortController != "undefined" ? new AbortController() : null, N = c ? setTimeout(() => c.abort(), s) : null, m = {
|
|
324
|
+
method: n
|
|
325
|
+
};
|
|
326
|
+
if (e ? m.credentials = "same-origin" : m.credentials = "omit", m.signal = c ? c.signal : void 0, typeof FormData != "undefined" && r instanceof FormData ? m.body = r : r != null && (m.headers = { "Content-Type": "text/plain" }, m.body = JSON.stringify(r)), !a.fetch)
|
|
327
|
+
throw new h(f.NETWORK, "当前环境不支持 fetch");
|
|
328
|
+
let R;
|
|
329
|
+
try {
|
|
330
|
+
R = await a.fetch(t, m);
|
|
331
|
+
} catch (L) {
|
|
332
|
+
throw N && clearTimeout(N), L && L.name === "AbortError" ? new h(f.TIMEOUT, "请求超时,请重试") : new h(f.NETWORK, "网络异常,请检查网络后重试");
|
|
333
|
+
}
|
|
334
|
+
N && clearTimeout(N);
|
|
335
|
+
const G = await R.text();
|
|
336
|
+
let d = null;
|
|
337
|
+
if (G)
|
|
338
|
+
try {
|
|
339
|
+
d = JSON.parse(G);
|
|
340
|
+
} catch (L) {
|
|
341
|
+
d = null;
|
|
342
|
+
}
|
|
343
|
+
if (!R.ok)
|
|
344
|
+
throw new h(String(R.status), d && d.message || G || "请求失败");
|
|
345
|
+
if (!d || d.code === null || d.code === void 0)
|
|
346
|
+
throw new h("500", "响应格式异常");
|
|
347
|
+
return d.code = String(d.code), d;
|
|
348
|
+
}
|
|
349
|
+
async function l(e, n = null, t = null) {
|
|
350
|
+
const r = t || {};
|
|
351
|
+
r.method || (r.method = "POST"), r.showError = r.showError !== !1;
|
|
352
|
+
let o = !0;
|
|
353
|
+
/^https?:\/\/.+$/.test(e) ? e.indexOf(y().apiBase) === -1 && (o = !1) : e = y().apiBase + e, o && !E() && (o = !1);
|
|
354
|
+
let i = e;
|
|
355
|
+
if (!o && u.ds && u.token) {
|
|
356
|
+
let c = await A(_.BIZ, {
|
|
357
|
+
method: r.method,
|
|
358
|
+
path: new URL(e, location.href).pathname,
|
|
359
|
+
ds: u.ds,
|
|
360
|
+
ts: Date.now(),
|
|
361
|
+
token: u.token
|
|
362
|
+
}, "domain");
|
|
363
|
+
i.indexOf("?") > 0 ? i = i + "&dsign=" + c : i = i + "?dsign=" + c;
|
|
364
|
+
}
|
|
365
|
+
const s = await Ce(o, r.method, i, n, r.timeout);
|
|
366
|
+
return s.code === f.LOGIN_TIMEOUT && !r.skipRefresh && W && await Ke() ? l(e, n, Object.assign({}, r, { skipRefresh: !0 })) : (/^2.+/.test(s.code) || Re(s, r), s);
|
|
367
|
+
}
|
|
368
|
+
async function Xe(e, n, t, r) {
|
|
369
|
+
const o = new FormData();
|
|
370
|
+
return Object.keys(t || {}).forEach((i) => {
|
|
371
|
+
const s = t[i];
|
|
372
|
+
s != null && o.append(i, s);
|
|
373
|
+
}), o.append("file", n), l(e, o, r);
|
|
374
|
+
}
|
|
375
|
+
function xe(e) {
|
|
376
|
+
W = e;
|
|
377
|
+
}
|
|
378
|
+
function De() {
|
|
379
|
+
const e = typeof navigator != "undefined" && navigator.userAgent || "", n = {
|
|
380
|
+
device_brand: Me(e),
|
|
381
|
+
device_model: _e(e),
|
|
382
|
+
browser_name: Ae(e),
|
|
383
|
+
browser_version: ve(e),
|
|
384
|
+
os_name: Ge(e),
|
|
385
|
+
os_version: Le(e)
|
|
386
|
+
}, t = u.ds;
|
|
387
|
+
return t && (n.device_id = t), n;
|
|
388
|
+
}
|
|
389
|
+
function w(e, n) {
|
|
390
|
+
const t = e.match(n);
|
|
391
|
+
return t ? t[1] : "";
|
|
392
|
+
}
|
|
393
|
+
function Me(e) {
|
|
434
394
|
return /iPhone|iPad|iPod/.test(e) ? "Apple" : /Huawei|HONOR/i.test(e) ? "Huawei" : /Xiaomi|Redmi|POCO/i.test(e) ? "Xiaomi" : /OPPO|realme/i.test(e) ? "OPPO" : /vivo/i.test(e) ? "vivo" : /Samsung|SM-|SAMSUNG/i.test(e) ? "Samsung" : /Macintosh|Mac OS X/.test(e) ? "Apple" : "";
|
|
435
395
|
}
|
|
436
|
-
function
|
|
396
|
+
function _e(e) {
|
|
437
397
|
if (/iPhone/.test(e)) return "iPhone";
|
|
438
398
|
if (/iPad/.test(e)) return "iPad";
|
|
439
|
-
const
|
|
440
|
-
return
|
|
399
|
+
const n = e.match(/Android[^;]*;\s*([^;)]+?)(?:\s+Build[/)]|\))/i);
|
|
400
|
+
return n ? n[1].trim() : /Macintosh/.test(e) ? "Mac" : "";
|
|
441
401
|
}
|
|
442
|
-
function
|
|
402
|
+
function Ae(e) {
|
|
443
403
|
return /MicroMessenger/i.test(e) ? "WeChat" : /Edg[A-Za-z]*\//.test(e) ? "Edge" : /OPR\/|Opera/.test(e) ? "Opera" : /Firefox\//.test(e) ? "Firefox" : /Chrome\/|CriOS\//.test(e) ? "Chrome" : /Safari\//.test(e) ? "Safari" : "";
|
|
444
404
|
}
|
|
445
|
-
function
|
|
446
|
-
return /MicroMessenger\/([\d.]+)/.test(e) ?
|
|
405
|
+
function ve(e) {
|
|
406
|
+
return /MicroMessenger\/([\d.]+)/.test(e) ? w(e, /MicroMessenger\/([\d.]+)/) : /Edg[A-Za-z]*\/([\d.]+)/.test(e) ? w(e, /Edg[A-Za-z]*\/([\d.]+)/) : /OPR\/([\d.]+)/.test(e) ? w(e, /OPR\/([\d.]+)/) : /Firefox\/([\d.]+)/.test(e) ? w(e, /Firefox\/([\d.]+)/) : /CriOS\/([\d.]+)/.test(e) ? w(e, /CriOS\/([\d.]+)/) : /Chrome\/([\d.]+)/.test(e) ? w(e, /Chrome\/([\d.]+)/) : /Version\/([\d.]+).*Safari/.test(e) ? w(e, /Version\/([\d.]+)/) : "";
|
|
447
407
|
}
|
|
448
|
-
function
|
|
408
|
+
function Ge(e) {
|
|
449
409
|
return /Windows NT/.test(e) ? "Windows" : /iPhone|iPad|iPod/.test(e) ? "iOS" : /Android/.test(e) ? "Android" : /Mac OS X|Macintosh/.test(e) ? "macOS" : /HarmonyOS/.test(e) ? "HarmonyOS" : /Linux/.test(e) ? "Linux" : "";
|
|
450
410
|
}
|
|
451
|
-
function
|
|
411
|
+
function Le(e) {
|
|
452
412
|
if (/Windows NT 10\.0/.test(e)) return "10/11";
|
|
453
413
|
if (/Windows NT 6\.3/.test(e)) return "8.1";
|
|
454
414
|
if (/Windows NT 6\.1/.test(e)) return "7";
|
|
455
|
-
const
|
|
456
|
-
if (
|
|
457
|
-
if (/Android[ _]([\d.]+)/.test(e)) return
|
|
458
|
-
const
|
|
459
|
-
return
|
|
415
|
+
const n = e.match(/(?:iPhone )?OS (\d+[_.]\d+(?:[_.]\d+)?)/);
|
|
416
|
+
if (n) return n[1].replace(/_/g, ".");
|
|
417
|
+
if (/Android[ _]([\d.]+)/.test(e)) return w(e, /Android[ _]([\d.]+)/);
|
|
418
|
+
const t = e.match(/Mac OS X (\d+[_.]\d+(?:[_.]\d+)?)/);
|
|
419
|
+
return t ? t[1].replace(/_/g, ".") : "";
|
|
460
420
|
}
|
|
461
|
-
|
|
421
|
+
function ne() {
|
|
422
|
+
if (location.origin)
|
|
423
|
+
return location.origin.toLowerCase();
|
|
424
|
+
try {
|
|
425
|
+
return new URL(location.href).origin.toLowerCase();
|
|
426
|
+
} catch (e) {
|
|
427
|
+
return "";
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
let j, $;
|
|
431
|
+
function te(e) {
|
|
432
|
+
const n = typeof location != "undefined" && location.search || "";
|
|
433
|
+
return (!j || $ !== n) && ($ = n, j = new URLSearchParams(n)), j.get(e);
|
|
434
|
+
}
|
|
435
|
+
const p = {
|
|
462
436
|
SIGN: {
|
|
463
437
|
VERIFY: "/api/unsafe/dplugin/login/s/verify",
|
|
464
438
|
TOKEN: "/api/unsafe/dplugin/login/s/token",
|
|
@@ -470,399 +444,154 @@ const w = {
|
|
|
470
444
|
REFRESH: "/api/unsafe/dplugin/login/c/refresh"
|
|
471
445
|
},
|
|
472
446
|
LOGOUT: "/api/safe/dplugin/login/logout"
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
function
|
|
476
|
-
return
|
|
477
|
-
}
|
|
478
|
-
function Pe() {
|
|
479
|
-
if (typeof location == "undefined")
|
|
480
|
-
return "";
|
|
481
|
-
try {
|
|
482
|
-
const e = new URLSearchParams(location.search).get("referer");
|
|
483
|
-
if (e)
|
|
484
|
-
return decodeURIComponent(e);
|
|
485
|
-
} catch (e) {
|
|
486
|
-
}
|
|
487
|
-
return ue();
|
|
488
|
-
}
|
|
489
|
-
function M(e) {
|
|
490
|
-
return new Promise((t) => setTimeout(t, e));
|
|
491
|
-
}
|
|
492
|
-
function X() {
|
|
493
|
-
const e = I();
|
|
494
|
-
typeof e.onLogin == "function" && e.onLogin(W());
|
|
495
|
-
}
|
|
496
|
-
function D(e, t) {
|
|
497
|
-
return new m(e.code, e.message || t);
|
|
498
|
-
}
|
|
499
|
-
function W() {
|
|
500
|
-
return {
|
|
501
|
-
mode: pe(),
|
|
502
|
-
loggedIn: fe(),
|
|
503
|
-
hasAccess: !!i.access,
|
|
504
|
-
sid: i.sid,
|
|
505
|
-
ds: i.ds
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
function fe() {
|
|
509
|
-
return b() ? !!i.cookie : !!(i.access || i.sid);
|
|
510
|
-
}
|
|
511
|
-
function Re() {
|
|
512
|
-
i.clear();
|
|
513
|
-
}
|
|
514
|
-
function P(e) {
|
|
515
|
-
const t = fe();
|
|
516
|
-
Re();
|
|
517
|
-
const n = I();
|
|
518
|
-
if (t && typeof n.onLogout == "function" && n.onLogout(e || "expired"), B || !n.enableAuth || !n.loginUrl || typeof location == "undefined")
|
|
519
|
-
return;
|
|
520
|
-
B = !0;
|
|
521
|
-
const o = n.loginUrl.includes("?") ? "&" : "?";
|
|
522
|
-
location.href = n.loginUrl + o + "referer=" + encodeURIComponent(location.href);
|
|
523
|
-
}
|
|
524
|
-
function tt(e, t) {
|
|
525
|
-
return R || (R = ot(e, t).then((n) => (R = null, n), (n) => {
|
|
526
|
-
throw R = null, nt(n), n;
|
|
527
|
-
}), R);
|
|
528
|
-
}
|
|
529
|
-
function nt(e) {
|
|
530
|
-
const t = I();
|
|
531
|
-
typeof t.onError == "function" && t.onError({
|
|
532
|
-
code: e && e.code,
|
|
533
|
-
message: e && e.message,
|
|
534
|
-
error: e
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
async function ot(e, t) {
|
|
538
|
-
const n = I(), o = Ze();
|
|
539
|
-
if (b())
|
|
540
|
-
return st(e, t, o, n);
|
|
541
|
-
const r = await se(), s = await be();
|
|
542
|
-
try {
|
|
543
|
-
return await rt(e, t, o, n);
|
|
544
|
-
} catch (a) {
|
|
545
|
-
throw await ge(ee.SSO, r), await ge(ee.DOMAIN, s), a;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
async function rt(e, t, n, o) {
|
|
549
|
-
const r = await Ye(), s = await Q(r), a = await h(g(e), Object.assign({}, t, { device: n, pk: s }));
|
|
550
|
-
if (a.code !== u.OK)
|
|
551
|
-
throw D(a, "登录失败");
|
|
552
|
-
const c = a.data && a.data.token;
|
|
553
|
-
if (!c)
|
|
554
|
-
throw D(a, "登录失败");
|
|
555
|
-
const f = await Be(), d = await Ie(f), l = await it(c, o, d), y = await h(g(w.SIGN.TOKEN), {
|
|
556
|
-
dsign: await K(N.TOKEN, {
|
|
557
|
-
origin: A(),
|
|
558
|
-
ts: Date.now(),
|
|
559
|
-
subject: l.code,
|
|
560
|
-
dna: d
|
|
561
|
-
}, "domain"),
|
|
562
|
-
pk: await Q(f)
|
|
563
|
-
});
|
|
564
|
-
if (y.code !== u.OK || !y.data)
|
|
565
|
-
throw D(y, "登录失败");
|
|
566
|
-
return i.sid = l.sid, i.ds = y.data.ds || l.ds, i.access = y.data.token, i.exp = Date.now() + ae, B = !1, X(), W();
|
|
567
|
-
}
|
|
568
|
-
async function it(e, t, n) {
|
|
569
|
-
const o = ue(), r = Math.max(1, Number(t.pollMax) || 5);
|
|
570
|
-
for (let s = 1; s <= r; s++) {
|
|
571
|
-
const a = i.ds || null, c = Date.now(), f = await K(N.VERIFY, {
|
|
572
|
-
method: "POST",
|
|
573
|
-
path: V(w.SIGN.VERIFY),
|
|
574
|
-
origin: A(),
|
|
575
|
-
ds: a,
|
|
576
|
-
ts: c,
|
|
577
|
-
subject: e,
|
|
578
|
-
dna: n,
|
|
579
|
-
redirect: o
|
|
580
|
-
}, "sso");
|
|
581
|
-
let d;
|
|
582
|
-
try {
|
|
583
|
-
d = await h(g(w.SIGN.VERIFY), { dsign: f, dna: n, redirect: o });
|
|
584
|
-
} catch (l) {
|
|
585
|
-
if ((l.code === u.NETWORK || l.code === u.TIMEOUT) && s < r) {
|
|
586
|
-
await M(t.pollInterval);
|
|
587
|
-
continue;
|
|
588
|
-
}
|
|
589
|
-
throw l;
|
|
590
|
-
}
|
|
591
|
-
if (d.code === u.OK && d.data)
|
|
592
|
-
return d.data;
|
|
593
|
-
if (d.code === u.PENDING) {
|
|
594
|
-
if (s < r) {
|
|
595
|
-
await M(t.pollInterval);
|
|
596
|
-
continue;
|
|
597
|
-
}
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
throw D(d, "登录失败");
|
|
601
|
-
}
|
|
602
|
-
throw new m(u.AUTH_EXPIRED, "登录超时,请重试");
|
|
603
|
-
}
|
|
604
|
-
async function st(e, t, n, o) {
|
|
605
|
-
const r = await h(g(e), Object.assign({}, t, { device: n }));
|
|
606
|
-
if (r.code !== u.OK)
|
|
607
|
-
throw D(r, "登录失败");
|
|
608
|
-
return await ct(o), i.cookie = !0, B = !1, X(), W();
|
|
609
|
-
}
|
|
610
|
-
async function ct(e) {
|
|
611
|
-
const t = Pe(), n = Math.max(1, Number(e.pollMax) || 5);
|
|
612
|
-
for (let o = 1; o <= n; o++) {
|
|
613
|
-
let r;
|
|
614
|
-
try {
|
|
615
|
-
r = await h(g(w.COOKIE.VERIFY), { redirect: t });
|
|
616
|
-
} catch (s) {
|
|
617
|
-
if ((s.code === u.NETWORK || s.code === u.TIMEOUT) && o < n) {
|
|
618
|
-
await M(e.pollInterval);
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
throw s;
|
|
622
|
-
}
|
|
623
|
-
if (r.code === u.OK)
|
|
624
|
-
return r.data;
|
|
625
|
-
if (r.code === u.PENDING) {
|
|
626
|
-
if (o < n) {
|
|
627
|
-
await M(e.pollInterval);
|
|
628
|
-
continue;
|
|
629
|
-
}
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
throw D(r, "登录失败");
|
|
633
|
-
}
|
|
634
|
-
throw new m(u.AUTH_EXPIRED, "登录超时,请重试");
|
|
447
|
+
};
|
|
448
|
+
xe(Ye);
|
|
449
|
+
function Be(e) {
|
|
450
|
+
return new Promise((n) => setTimeout(n, e));
|
|
635
451
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
452
|
+
let S = null;
|
|
453
|
+
async function qe(e, n) {
|
|
454
|
+
if (S)
|
|
455
|
+
return S;
|
|
456
|
+
const t = De();
|
|
457
|
+
return S = (E() ? Ve(e, n, t) : Ue(e, n, t)).finally(() => {
|
|
458
|
+
S = null;
|
|
459
|
+
}), S;
|
|
460
|
+
}
|
|
461
|
+
async function Ve(e, n, t) {
|
|
462
|
+
let r = await l(e, Object.assign({}, n, { device: t }));
|
|
463
|
+
return await re(r.data, !0, !0);
|
|
464
|
+
}
|
|
465
|
+
async function Ue(e, n, t) {
|
|
466
|
+
await pe();
|
|
467
|
+
const r = await ee("sso"), o = await l(e, Object.assign({}, n, { device: t, pk: r }));
|
|
468
|
+
return await re(o.data, !0, !0);
|
|
469
|
+
}
|
|
470
|
+
let b;
|
|
471
|
+
async function re(e, n = !1, t = !1) {
|
|
472
|
+
return b || (b = Fe(e, n, t).finally(() => {
|
|
473
|
+
b = null;
|
|
474
|
+
}), b);
|
|
475
|
+
}
|
|
476
|
+
async function Fe(e, n, t) {
|
|
477
|
+
e || (e = {});
|
|
478
|
+
let r;
|
|
479
|
+
if (t) {
|
|
480
|
+
r = te("referer");
|
|
481
|
+
let o = y(), i;
|
|
482
|
+
for (let s = 0; s < o.pollMax; s++) {
|
|
483
|
+
if (i = E() ? await z(e, r, n) : await Z(e, r, n), i.code !== f.LOGIN_PENDING)
|
|
484
|
+
return i;
|
|
485
|
+
await Be(o.pollInterval);
|
|
647
486
|
}
|
|
648
|
-
|
|
487
|
+
return i;
|
|
488
|
+
} else
|
|
489
|
+
return r = window.location.href, E() ? await z(e, r, n) : await Z(e, r, n);
|
|
649
490
|
}
|
|
650
|
-
async function
|
|
651
|
-
return
|
|
491
|
+
async function z(e, n, t) {
|
|
492
|
+
return await l(p.COOKIE.VERIFY, { redirect: n }, { skipRefresh: !0, showError: t });
|
|
652
493
|
}
|
|
653
|
-
async function
|
|
654
|
-
|
|
655
|
-
return !1;
|
|
656
|
-
const t = i.ds, n = await Ge(ee.DOMAIN), o = await Ie(n), r = ue(), s = await K(N.VERIFY_SID, {
|
|
657
|
-
method: "POST",
|
|
658
|
-
path: V(w.SIGN.VERIFY),
|
|
659
|
-
origin: A(),
|
|
660
|
-
ds: t,
|
|
661
|
-
ts: Date.now(),
|
|
662
|
-
subject: i.sid,
|
|
663
|
-
dna: o,
|
|
664
|
-
redirect: r
|
|
665
|
-
}, "sso"), a = await h(g(w.SIGN.VERIFY), { dsign: s, dna: o, redirect: r });
|
|
666
|
-
if (a.code !== u.OK || !a.data)
|
|
667
|
-
return !1;
|
|
668
|
-
const c = await h(g(w.SIGN.TOKEN), {
|
|
669
|
-
dsign: await K(N.TOKEN, {
|
|
670
|
-
origin: A(),
|
|
671
|
-
ts: Date.now(),
|
|
672
|
-
subject: a.data.code,
|
|
673
|
-
dna: o
|
|
674
|
-
}, "domain"),
|
|
675
|
-
pk: await Q(n)
|
|
676
|
-
});
|
|
677
|
-
return c.code !== u.OK || !c.data ? !1 : (i.access = c.data.token, c.data.ds && (i.ds = c.data.ds), i.exp = Date.now() + ae, X(), !0);
|
|
678
|
-
}
|
|
679
|
-
async function ft(e) {
|
|
680
|
-
return !e && i.access ? !0 : ut();
|
|
681
|
-
}
|
|
682
|
-
function de() {
|
|
683
|
-
return _ || (_ = (b() ? dt() : lt()).then((e) => (_ = null, e), (e) => {
|
|
684
|
-
throw _ = null, e;
|
|
685
|
-
})), _;
|
|
686
|
-
}
|
|
687
|
-
async function dt() {
|
|
688
|
-
const e = await h(g(w.COOKIE.TOKEN));
|
|
689
|
-
if (e.code === u.OK)
|
|
690
|
-
return !0;
|
|
691
|
-
const t = await h(g(w.COOKIE.REFRESH));
|
|
692
|
-
if (t.code === u.OK)
|
|
693
|
-
return !0;
|
|
694
|
-
if (t.code === u.AUTH_EXPIRED || e.code === u.AUTH_EXPIRED)
|
|
695
|
-
throw new O(t.message || e.message);
|
|
696
|
-
if (t.code === "500" && /重复/.test(t.message || ""))
|
|
697
|
-
return await M(800), !0;
|
|
698
|
-
throw new m(t.code, t.message);
|
|
699
|
-
}
|
|
700
|
-
async function lt() {
|
|
701
|
-
const e = i.access, t = i.ds;
|
|
702
|
-
if (!e || !t)
|
|
703
|
-
throw new O();
|
|
704
|
-
const n = await K(N.BIZ, {
|
|
494
|
+
async function Z(e, n, t) {
|
|
495
|
+
let r = {
|
|
705
496
|
method: "POST",
|
|
706
|
-
path:
|
|
707
|
-
origin:
|
|
708
|
-
ds: t,
|
|
497
|
+
path: p.SIGN.VERIFY,
|
|
498
|
+
origin: ne(),
|
|
709
499
|
ts: Date.now(),
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
const n = Date.now() + t;
|
|
721
|
-
return new Promise((o) => {
|
|
722
|
-
const r = () => {
|
|
723
|
-
const s = i.access;
|
|
724
|
-
if (s && s !== e) {
|
|
725
|
-
o(s);
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
|
-
if (Date.now() >= n) {
|
|
729
|
-
o(null);
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
setTimeout(r, 150);
|
|
733
|
-
};
|
|
734
|
-
r();
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
async function wt() {
|
|
738
|
-
try {
|
|
739
|
-
let t = await we();
|
|
740
|
-
t.code === u.AUTH_EXPIRED && (await de(), t = await we());
|
|
741
|
-
} catch (t) {
|
|
500
|
+
ds: u.ds,
|
|
501
|
+
dna: te("dna"),
|
|
502
|
+
redirect: n
|
|
503
|
+
}, o;
|
|
504
|
+
if (e && e.token)
|
|
505
|
+
r.token = e.token, o = await A(_.VTT, r, "sso");
|
|
506
|
+
else {
|
|
507
|
+
if (!u.sid || !u.ds)
|
|
508
|
+
throw new h(f.LOGIN_TIMEOUT, "未登录");
|
|
509
|
+
r.token = u.sid, o = await A(_.VSD, r, "sso");
|
|
742
510
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
typeof e.onLogout == "function" && e.onLogout("logout");
|
|
746
|
-
}
|
|
747
|
-
async function we() {
|
|
748
|
-
if (b())
|
|
749
|
-
return h(g(w.LOGOUT));
|
|
750
|
-
const e = await ce(w.LOGOUT, i.access, i.ds);
|
|
751
|
-
return h(g(w.LOGOUT, e));
|
|
752
|
-
}
|
|
753
|
-
async function pt(e, t, n) {
|
|
754
|
-
const o = n || {};
|
|
755
|
-
return o.auth !== !1 && await De(), H(e, t || {}, o, !1);
|
|
756
|
-
}
|
|
757
|
-
async function De() {
|
|
758
|
-
if (b()) {
|
|
759
|
-
if (i.cookie || await k())
|
|
760
|
-
return;
|
|
761
|
-
throw P("expired"), new O();
|
|
762
|
-
}
|
|
763
|
-
if (!i.access && !await k())
|
|
764
|
-
throw P("expired"), new O();
|
|
765
|
-
}
|
|
766
|
-
async function H(e, t, n, o) {
|
|
767
|
-
const r = n.auth !== !1, s = r && !b();
|
|
768
|
-
let a = "", c = null;
|
|
769
|
-
if (s) {
|
|
770
|
-
c = i.access;
|
|
771
|
-
try {
|
|
772
|
-
a = await ce(e, c, i.ds);
|
|
773
|
-
} catch (d) {
|
|
774
|
-
if (!o && await k({ force: !0 }))
|
|
775
|
-
return H(e, t, n, !0);
|
|
776
|
-
throw P("expired"), new O();
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
const f = await h(g(e, a), t, n.timeout);
|
|
780
|
-
if (f.code === u.OK)
|
|
781
|
-
return f.data;
|
|
782
|
-
if (r && f.code === u.AUTH_EXPIRED && !o) {
|
|
783
|
-
if (s && c && i.access !== c)
|
|
784
|
-
return H(e, t, n, !0);
|
|
785
|
-
try {
|
|
786
|
-
await de();
|
|
787
|
-
} catch (d) {
|
|
788
|
-
throw d instanceof O && P("expired"), d;
|
|
789
|
-
}
|
|
790
|
-
return H(e, t, n, !0);
|
|
791
|
-
}
|
|
792
|
-
throw r && f.code === u.AUTH_EXPIRED ? (P("expired"), new O(f.message)) : Ne(f, n);
|
|
511
|
+
const i = await l(p.SIGN.VERIFY, { dsign: o, dna: r.dna, redirect: r.redirect }, { skipRefresh: !0, showError: t });
|
|
512
|
+
return i.code === f.OK && (u.sid = i.data.sid, i.data.ds && (u.ds = i.data.ds)), i;
|
|
793
513
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
return
|
|
514
|
+
let T;
|
|
515
|
+
async function Je(e, n = !0) {
|
|
516
|
+
return T || (T = He(e, n).finally(() => {
|
|
517
|
+
T = null;
|
|
518
|
+
}), T);
|
|
797
519
|
}
|
|
798
|
-
async function
|
|
799
|
-
return (
|
|
520
|
+
async function He(e, n) {
|
|
521
|
+
return E() ? await je(e, n) : await We(e, n);
|
|
800
522
|
}
|
|
801
|
-
async function
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
523
|
+
async function je(e, n) {
|
|
524
|
+
return await l(p.COOKIE.TOKEN, null, { skipRefresh: !0, showError: n });
|
|
525
|
+
}
|
|
526
|
+
async function We(e, n) {
|
|
527
|
+
let t = {
|
|
528
|
+
method: "POST",
|
|
529
|
+
path: p.SIGN.TOKEN,
|
|
530
|
+
origin: ne(),
|
|
531
|
+
ts: Date.now(),
|
|
532
|
+
ds: u.ds
|
|
533
|
+
}, r;
|
|
534
|
+
if (e && e.code)
|
|
535
|
+
t.token = e.code, r = await A(_.TOK, t, "domain");
|
|
536
|
+
else
|
|
537
|
+
throw new h(f.LOGIN_TIMEOUT, "未登录");
|
|
538
|
+
let o = await ee("domain");
|
|
539
|
+
const i = await l(p.SIGN.TOKEN, { dsign: r, pk: o }, { skipRefresh: !0, showError: n });
|
|
540
|
+
return i.code === f.OK && (u.token = i.data.token, i.data.ds && (u.ds = i.data.ds)), i;
|
|
541
|
+
}
|
|
542
|
+
let k;
|
|
543
|
+
async function Ye() {
|
|
544
|
+
return k || (k = $e().finally(() => {
|
|
545
|
+
k = null;
|
|
546
|
+
}), k);
|
|
547
|
+
}
|
|
548
|
+
async function $e() {
|
|
549
|
+
return E() ? await ze() : await Ze();
|
|
550
|
+
}
|
|
551
|
+
async function ze() {
|
|
552
|
+
return await l(p.COOKIE.REFRESH, null, { skipRefresh: !0, showError: !1 });
|
|
553
|
+
}
|
|
554
|
+
async function Ze() {
|
|
555
|
+
const e = u.token, n = u.ds;
|
|
556
|
+
if (!e || !n)
|
|
557
|
+
throw new ue();
|
|
558
|
+
const t = await l(p.SIGN.REFRESH, null, { skipRefresh: !0, showError: !1 });
|
|
559
|
+
return t.code === f.OK && (t.data.ds && (u.ds = t.data.ds), u.token = t.data.token), t;
|
|
560
|
+
}
|
|
561
|
+
async function Qe() {
|
|
562
|
+
(await l(p.LOGOUT)).code === f.OK && u.clear();
|
|
563
|
+
}
|
|
564
|
+
async function en() {
|
|
565
|
+
let e = y(), n = encodeURIComponent(window.location.href), t = e.loginUrl + "?referer=" + n;
|
|
566
|
+
if (!E()) {
|
|
567
|
+
await we();
|
|
568
|
+
let r = await ye();
|
|
569
|
+
t += "&dna=" + r;
|
|
826
570
|
}
|
|
827
|
-
|
|
828
|
-
}
|
|
829
|
-
function
|
|
830
|
-
const
|
|
831
|
-
if (
|
|
832
|
-
const
|
|
833
|
-
if (
|
|
834
|
-
const
|
|
835
|
-
if (
|
|
836
|
-
throw new Error(
|
|
837
|
-
typeof console != "undefined" && console.warn(
|
|
571
|
+
window.location.href = t;
|
|
572
|
+
}
|
|
573
|
+
function nn(e) {
|
|
574
|
+
const n = ie(e);
|
|
575
|
+
if (Pe(), n.nativeGuard !== "off") {
|
|
576
|
+
const t = ce();
|
|
577
|
+
if (t.length) {
|
|
578
|
+
const r = "[dplugin/core] 这些原生能力在模块加载前已被替换:" + t.join(", ") + "(签名/请求可能被中间人截获,检查是否有脚本抢跑)";
|
|
579
|
+
if (n.nativeGuard === "error")
|
|
580
|
+
throw new Error(r);
|
|
581
|
+
typeof console != "undefined" && console.warn(r);
|
|
838
582
|
}
|
|
839
583
|
}
|
|
840
584
|
}
|
|
841
|
-
const Ot = {
|
|
842
|
-
login: tt,
|
|
843
|
-
logout: wt,
|
|
844
|
-
isLogin: fe,
|
|
845
|
-
getState: W,
|
|
846
|
-
/** 页面加载时恢复登录态;返回是否已登录 */
|
|
847
|
-
restore: k
|
|
848
|
-
};
|
|
849
585
|
export {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
tt as login,
|
|
861
|
-
wt as logout,
|
|
862
|
-
pt as request,
|
|
863
|
-
mt as setup,
|
|
864
|
-
i as store,
|
|
865
|
-
Et as upload,
|
|
866
|
-
k as verifyLogin
|
|
586
|
+
ye as getDna,
|
|
587
|
+
ee as getPublicKey,
|
|
588
|
+
en as gotoLoginPage,
|
|
589
|
+
qe as login,
|
|
590
|
+
Qe as logout,
|
|
591
|
+
l as request,
|
|
592
|
+
nn as setup,
|
|
593
|
+
Je as token,
|
|
594
|
+
Xe as upload,
|
|
595
|
+
re as verify
|
|
867
596
|
};
|
|
868
597
|
//# sourceMappingURL=index.mjs.map
|