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