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