@dplugin/core 2.0.3 → 2.0.4
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 +427 -412
- 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 _ = {
|
|
2
2
|
// 接口前缀。'' = 同源;也可以是 https://api.company.com
|
|
3
3
|
apiBase: "",
|
|
4
4
|
// 运行模式:'auto' 按同源自动判定;'cookie' 强制同域 Cookie;'sign' 强制跨域签名
|
|
@@ -22,60 +22,60 @@ const k = {
|
|
|
22
22
|
// 原生能力体检:'warn' 只告警 / 'error' 直接抛错 / 'off' 不检查
|
|
23
23
|
nativeGuard: "warn"
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
return
|
|
27
|
-
t
|
|
28
|
-
}),
|
|
25
|
+
function Ke(e) {
|
|
26
|
+
return e && Object.keys(_).forEach((t) => {
|
|
27
|
+
e[t] !== void 0 && (_[t] = e[t]);
|
|
28
|
+
}), _;
|
|
29
29
|
}
|
|
30
30
|
function I() {
|
|
31
|
-
return
|
|
31
|
+
return _;
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
function
|
|
35
|
-
if (typeof
|
|
33
|
+
const m = Ae();
|
|
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 xe(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 Ae() {
|
|
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 || xe(() => 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 ke() {
|
|
75
75
|
if (typeof window == "undefined" || typeof window.document == "undefined")
|
|
76
76
|
return [];
|
|
77
|
-
const
|
|
78
|
-
return
|
|
77
|
+
const e = [];
|
|
78
|
+
return m.fetch && !m.pristine.fetch && e.push("fetch"), m.idbOpen && !m.pristine.idbOpen && e.push("indexedDB.open"), m.subtle && !m.pristine.subtle && e.push("crypto.subtle"), e;
|
|
79
79
|
}
|
|
80
80
|
const u = {
|
|
81
81
|
OK: "200",
|
|
@@ -87,74 +87,74 @@ const u = {
|
|
|
87
87
|
NETWORK: "NETWORK",
|
|
88
88
|
TIMEOUT: "TIMEOUT"
|
|
89
89
|
};
|
|
90
|
-
class
|
|
91
|
-
constructor(
|
|
92
|
-
super(n || "请求失败"), this.name = "BizError", this.code =
|
|
90
|
+
class E extends Error {
|
|
91
|
+
constructor(t, n) {
|
|
92
|
+
super(n || "请求失败"), this.name = "BizError", this.code = t;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
class O extends
|
|
96
|
-
constructor(
|
|
97
|
-
super(u.AUTH_EXPIRED,
|
|
95
|
+
class O extends E {
|
|
96
|
+
constructor(t) {
|
|
97
|
+
super(u.AUTH_EXPIRED, t || "登录已失效"), this.name = "AuthError";
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
100
|
+
function yt(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", J = "dplugin.exp", Q = "dplugin.cookie", Ce = "token";
|
|
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
|
-
const
|
|
118
|
-
function A(
|
|
119
|
-
const
|
|
120
|
-
return
|
|
117
|
+
const G = {};
|
|
118
|
+
function A(e) {
|
|
119
|
+
const t = _e(e);
|
|
120
|
+
return t === null ? G[e] === void 0 ? null : G[e] : t;
|
|
121
121
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
122
|
+
function k(e, t) {
|
|
123
|
+
G[e] = t, he(e, t);
|
|
124
124
|
}
|
|
125
125
|
const i = {
|
|
126
126
|
get access() {
|
|
127
|
-
return A(
|
|
127
|
+
return A($);
|
|
128
128
|
},
|
|
129
|
-
set access(
|
|
130
|
-
|
|
129
|
+
set access(e) {
|
|
130
|
+
k($, e);
|
|
131
131
|
},
|
|
132
132
|
get sid() {
|
|
133
|
-
return A(
|
|
133
|
+
return A(q);
|
|
134
134
|
},
|
|
135
|
-
set sid(
|
|
136
|
-
|
|
135
|
+
set sid(e) {
|
|
136
|
+
k(q, e);
|
|
137
137
|
},
|
|
138
138
|
get ds() {
|
|
139
|
-
return A(
|
|
139
|
+
return A(le);
|
|
140
140
|
},
|
|
141
|
-
set ds(
|
|
142
|
-
|
|
141
|
+
set ds(e) {
|
|
142
|
+
k(le, e);
|
|
143
143
|
},
|
|
144
144
|
/** access 的到期时间(毫秒时间戳)。仅用于界面判断,不要拿它做提前续期 */
|
|
145
145
|
get exp() {
|
|
146
|
-
const
|
|
147
|
-
return
|
|
146
|
+
const e = A(J);
|
|
147
|
+
return e ? Number(e) : 0;
|
|
148
148
|
},
|
|
149
|
-
set exp(
|
|
150
|
-
|
|
149
|
+
set exp(e) {
|
|
150
|
+
k(J, e ? String(e) : null);
|
|
151
151
|
},
|
|
152
152
|
/** cookie 模式:本地只记「可能已登录」,实际有效性由第一次请求的结果决定 */
|
|
153
153
|
get cookie() {
|
|
154
154
|
return A(Q) === "1";
|
|
155
155
|
},
|
|
156
|
-
set cookie(
|
|
157
|
-
|
|
156
|
+
set cookie(e) {
|
|
157
|
+
k(Q, e ? "1" : null);
|
|
158
158
|
},
|
|
159
159
|
/**
|
|
160
160
|
* 清登录态。
|
|
@@ -163,71 +163,71 @@ const i = {
|
|
|
163
163
|
* 下次登录后端就会新建一条设备记录(common_login_device 无限膨胀)。
|
|
164
164
|
*/
|
|
165
165
|
clear() {
|
|
166
|
-
[q,
|
|
167
|
-
|
|
166
|
+
[$, q, J, Q, Ce].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
|
-
let
|
|
191
|
-
function
|
|
190
|
+
let S = null;
|
|
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
|
|
200
|
-
|
|
199
|
+
function Me() {
|
|
200
|
+
S = 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 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
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: b() ? "same-origin" : "omit",
|
|
222
222
|
signal: s ? s.signal : void 0
|
|
223
223
|
};
|
|
224
|
-
if (typeof FormData != "undefined" &&
|
|
225
|
-
throw new
|
|
224
|
+
if (typeof FormData != "undefined" && t instanceof FormData ? c.body = t : t != null && (c.headers = { "Content-Type": "text/plain" }, c.body = JSON.stringify(t)), !m.fetch)
|
|
225
|
+
throw new E(u.NETWORK, "当前环境不支持 fetch");
|
|
226
226
|
let f;
|
|
227
227
|
try {
|
|
228
|
-
f = await
|
|
228
|
+
f = await m.fetch(e, c);
|
|
229
229
|
} catch (y) {
|
|
230
|
-
throw a && clearTimeout(a), y && y.name === "AbortError" ? new
|
|
230
|
+
throw a && clearTimeout(a), y && y.name === "AbortError" ? new E(u.TIMEOUT, "请求超时,请重试") : new E(u.NETWORK, "网络异常,请检查网络后重试");
|
|
231
231
|
}
|
|
232
232
|
a && clearTimeout(a);
|
|
233
233
|
const d = await f.text();
|
|
@@ -239,52 +239,52 @@ async function h(t, e, n) {
|
|
|
239
239
|
l = null;
|
|
240
240
|
}
|
|
241
241
|
if (!f.ok)
|
|
242
|
-
throw new
|
|
242
|
+
throw new E(String(f.status), l && l.message || d || "请求失败");
|
|
243
243
|
if (!l || l.code === null || l.code === void 0)
|
|
244
|
-
throw new
|
|
244
|
+
throw new E("500", "响应格式异常");
|
|
245
245
|
return l.code = String(l.code), l;
|
|
246
246
|
}
|
|
247
|
-
const
|
|
248
|
-
let
|
|
247
|
+
const Le = "dplugin-auth", Fe = 1, H = "keys", re = "sso", ie = "domain", ve = { name: "ECDSA", namedCurve: "P-256" }, Ye = { name: "ECDSA", hash: "SHA-256" }, v = /* @__PURE__ */ new Map();
|
|
248
|
+
let L = null;
|
|
249
249
|
function j() {
|
|
250
|
-
if (!
|
|
251
|
-
const
|
|
252
|
-
throw new Error("[dplugin/core] crypto.subtle 不存在:浏览器只在**安全上下文**里提供它(https、http://localhost、http://127.0.0.1、http://[::1]、file://);当前 origin=" +
|
|
250
|
+
if (!m.subtle) {
|
|
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
|
-
return
|
|
254
|
+
return m.subtle;
|
|
255
255
|
}
|
|
256
|
-
function
|
|
257
|
-
return
|
|
258
|
-
if (!
|
|
259
|
-
|
|
256
|
+
function Ge() {
|
|
257
|
+
return L || (L = new Promise((e) => {
|
|
258
|
+
if (!m.idbOpen) {
|
|
259
|
+
e(null);
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
|
-
let
|
|
262
|
+
let t;
|
|
263
263
|
try {
|
|
264
|
-
|
|
264
|
+
t = m.idbOpen(Le, Fe);
|
|
265
265
|
} catch (n) {
|
|
266
|
-
|
|
266
|
+
e(null);
|
|
267
267
|
return;
|
|
268
268
|
}
|
|
269
|
-
|
|
270
|
-
const n =
|
|
271
|
-
n.objectStoreNames.contains(
|
|
272
|
-
},
|
|
273
|
-
}),
|
|
274
|
-
}
|
|
275
|
-
function
|
|
276
|
-
return
|
|
269
|
+
t.onupgradeneeded = () => {
|
|
270
|
+
const n = t.result;
|
|
271
|
+
n.objectStoreNames.contains(H) || n.createObjectStore(H);
|
|
272
|
+
}, t.onsuccess = () => e(t.result), t.onerror = () => e(null), t.onblocked = () => e(null);
|
|
273
|
+
}), L);
|
|
274
|
+
}
|
|
275
|
+
function me(e, t) {
|
|
276
|
+
return Ge().then((n) => n ? new Promise((o) => {
|
|
277
277
|
let r;
|
|
278
278
|
try {
|
|
279
|
-
r = n.transaction(
|
|
279
|
+
r = n.transaction(H, e);
|
|
280
280
|
} catch (c) {
|
|
281
281
|
o(null);
|
|
282
282
|
return;
|
|
283
283
|
}
|
|
284
|
-
const s = r.objectStore(
|
|
284
|
+
const s = r.objectStore(H);
|
|
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,169 +296,169 @@ 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
|
|
299
|
+
function Ee(e) {
|
|
300
|
+
return v.has(e) ? Promise.resolve(v.get(e)) : me("readonly", (t) => t.get(e)).then((t) => (t && v.set(e, t), t || null));
|
|
301
301
|
}
|
|
302
|
-
function
|
|
303
|
-
return
|
|
302
|
+
function Oe(e, t) {
|
|
303
|
+
return v.set(e, t), me("readwrite", (n) => n.put(t, e)).then(() => t);
|
|
304
304
|
}
|
|
305
|
-
async function
|
|
306
|
-
const n = await j().generateKey(
|
|
307
|
-
return
|
|
305
|
+
async function se(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 Ee(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 He(e) {
|
|
316
|
+
return await Ee(e) || se(e);
|
|
317
317
|
}
|
|
318
|
-
function
|
|
319
|
-
return
|
|
318
|
+
function Be() {
|
|
319
|
+
return se(re);
|
|
320
320
|
}
|
|
321
|
-
function
|
|
322
|
-
return
|
|
321
|
+
function Ve() {
|
|
322
|
+
return se(ie);
|
|
323
323
|
}
|
|
324
|
-
function
|
|
325
|
-
return
|
|
324
|
+
function ce() {
|
|
325
|
+
return ye(re);
|
|
326
326
|
}
|
|
327
|
-
function
|
|
328
|
-
return
|
|
327
|
+
function be() {
|
|
328
|
+
return ye(ie);
|
|
329
329
|
}
|
|
330
|
-
async function
|
|
331
|
-
const n = await j().exportKey("spki",
|
|
330
|
+
async function ee(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 je(e, t) {
|
|
346
|
+
const o = await j().sign(Ye, 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 te = {
|
|
354
|
+
SSO: re,
|
|
355
|
+
DOMAIN: ie
|
|
356
|
+
}, ne = "-", Xe = "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 === "" ? ne : String(e);
|
|
364
364
|
}
|
|
365
|
-
function
|
|
366
|
-
const n = p(
|
|
365
|
+
function We(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 === ne ? ne : 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 ze(e, t, n) {
|
|
381
|
+
return [p(e), p(t.subject), p(t.ds), p(t.ts), n].join(".");
|
|
382
382
|
}
|
|
383
|
-
async function
|
|
384
|
-
const o = n === "sso" ? await
|
|
383
|
+
async function K(e, t, n) {
|
|
384
|
+
const o = n === "sso" ? await ce() : await be();
|
|
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 Te(n === "sso" ? "缺少登录签名密钥" : "缺少业务签名密钥");
|
|
387
|
+
const r = await je(o, We(e, t));
|
|
388
|
+
return ze(e, t, r);
|
|
389
|
+
}
|
|
390
|
+
async function ae(e, t, n) {
|
|
391
|
+
if (!t || !n)
|
|
392
|
+
throw Te("缺少 access 或 ds,无法签名");
|
|
393
|
+
const o = await K(N.BIZ, {
|
|
394
|
+
method: Xe,
|
|
395
|
+
path: V(e),
|
|
396
|
+
origin: x(),
|
|
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
|
}
|
|
403
|
-
function
|
|
403
|
+
function x() {
|
|
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 (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: Je(e),
|
|
423
|
+
browser_version: Qe(e),
|
|
424
|
+
os_name: et(e),
|
|
425
|
+
os_version: tt(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 Je(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 Qe(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 et(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 tt(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,115 +470,122 @@ const g = {
|
|
|
470
470
|
REFRESH: "/api/unsafe/dplugin/login/c/refresh"
|
|
471
471
|
},
|
|
472
472
|
LOGOUT: "/api/safe/dplugin/login/logout"
|
|
473
|
-
},
|
|
474
|
-
let
|
|
473
|
+
}, nt = "dp_dvt", ue = 1800 * 1e3;
|
|
474
|
+
let C = null, F = 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(e) {
|
|
479
|
+
return new Promise((t) => setTimeout(t, e));
|
|
480
|
+
}
|
|
481
|
+
function ot() {
|
|
482
|
+
try {
|
|
483
|
+
localStorage.setItem("token", i.access || "cookie");
|
|
484
|
+
} catch (e) {
|
|
485
|
+
}
|
|
480
486
|
}
|
|
481
487
|
function W() {
|
|
482
|
-
|
|
483
|
-
|
|
488
|
+
ot();
|
|
489
|
+
const e = I();
|
|
490
|
+
typeof e.onLogin == "function" && e.onLogin(z());
|
|
484
491
|
}
|
|
485
|
-
function P(
|
|
486
|
-
return new
|
|
492
|
+
function P(e, t) {
|
|
493
|
+
return new E(e.code, e.message || t);
|
|
487
494
|
}
|
|
488
|
-
function
|
|
495
|
+
function rt(e, t, n) {
|
|
489
496
|
if (typeof document == "undefined")
|
|
490
497
|
return;
|
|
491
|
-
let o =
|
|
498
|
+
let o = e + "=" + encodeURIComponent(t) + "; path=/; SameSite=Lax";
|
|
492
499
|
o += "; max-age=" + n, document.cookie = o;
|
|
493
500
|
}
|
|
494
|
-
function
|
|
501
|
+
function z() {
|
|
495
502
|
return {
|
|
496
|
-
mode:
|
|
497
|
-
loggedIn:
|
|
503
|
+
mode: pe(),
|
|
504
|
+
loggedIn: fe(),
|
|
498
505
|
hasAccess: !!i.access,
|
|
499
506
|
sid: i.sid,
|
|
500
507
|
ds: i.ds
|
|
501
508
|
};
|
|
502
509
|
}
|
|
503
|
-
function
|
|
504
|
-
return
|
|
510
|
+
function fe() {
|
|
511
|
+
return b() ? !!i.cookie : !!(i.access || i.sid);
|
|
505
512
|
}
|
|
506
|
-
function
|
|
513
|
+
function Pe() {
|
|
507
514
|
i.clear();
|
|
508
515
|
}
|
|
509
|
-
function R(
|
|
510
|
-
const
|
|
511
|
-
|
|
516
|
+
function R(e) {
|
|
517
|
+
const t = fe();
|
|
518
|
+
Pe();
|
|
512
519
|
const n = I();
|
|
513
|
-
if (
|
|
520
|
+
if (t && typeof n.onLogout == "function" && n.onLogout(e || "expired"), B || !n.enableAuth || !n.loginUrl || typeof location == "undefined")
|
|
514
521
|
return;
|
|
515
522
|
B = !0;
|
|
516
523
|
const o = n.loginUrl.includes("?") ? "&" : "?";
|
|
517
524
|
location.href = n.loginUrl + o + "referer=" + encodeURIComponent(location.href);
|
|
518
525
|
}
|
|
519
|
-
function
|
|
520
|
-
return D || (D =
|
|
521
|
-
throw D = null,
|
|
526
|
+
function it(e, t) {
|
|
527
|
+
return D || (D = ct(e, t).then((n) => (D = null, n), (n) => {
|
|
528
|
+
throw D = null, st(n), n;
|
|
522
529
|
}), D);
|
|
523
530
|
}
|
|
524
|
-
function
|
|
525
|
-
const
|
|
526
|
-
typeof
|
|
527
|
-
code:
|
|
528
|
-
message:
|
|
529
|
-
error:
|
|
531
|
+
function st(e) {
|
|
532
|
+
const t = I();
|
|
533
|
+
typeof t.onError == "function" && t.onError({
|
|
534
|
+
code: e && e.code,
|
|
535
|
+
message: e && e.message,
|
|
536
|
+
error: e
|
|
530
537
|
});
|
|
531
538
|
}
|
|
532
|
-
async function
|
|
533
|
-
const n = I(), o =
|
|
534
|
-
if (
|
|
535
|
-
return
|
|
536
|
-
const r = await
|
|
539
|
+
async function ct(e, t) {
|
|
540
|
+
const n = I(), o = Ze();
|
|
541
|
+
if (b())
|
|
542
|
+
return ft(e, t, o, n);
|
|
543
|
+
const r = await ce(), s = await be();
|
|
537
544
|
try {
|
|
538
|
-
return await
|
|
545
|
+
return await at(e, t, o, n);
|
|
539
546
|
} catch (a) {
|
|
540
|
-
throw await
|
|
547
|
+
throw await ge(te.SSO, r), await ge(te.DOMAIN, s), a;
|
|
541
548
|
}
|
|
542
549
|
}
|
|
543
|
-
async function
|
|
544
|
-
const r = await
|
|
550
|
+
async function at(e, t, n, o) {
|
|
551
|
+
const r = await Be(), s = await ee(r), a = await h(g(e), Object.assign({}, t, { device: n, pk: s }));
|
|
545
552
|
if (a.code !== u.OK)
|
|
546
553
|
throw P(a, "登录失败");
|
|
547
554
|
const c = a.data && a.data.token;
|
|
548
555
|
if (!c)
|
|
549
556
|
throw P(a, "登录失败");
|
|
550
|
-
const f = await
|
|
551
|
-
dsign: await
|
|
552
|
-
origin:
|
|
557
|
+
const f = await Ve(), d = await Ie(f), l = await ut(c, o, d), y = await h(g(w.SIGN.TOKEN), {
|
|
558
|
+
dsign: await K(N.TOKEN, {
|
|
559
|
+
origin: x(),
|
|
553
560
|
ts: Date.now(),
|
|
554
561
|
subject: l.code,
|
|
555
562
|
dna: d
|
|
556
563
|
}, "domain"),
|
|
557
|
-
pk: await
|
|
564
|
+
pk: await ee(f)
|
|
558
565
|
});
|
|
559
566
|
if (y.code !== u.OK || !y.data)
|
|
560
567
|
throw P(y, "登录失败");
|
|
561
|
-
return i.sid = l.sid, i.ds = y.data.ds || l.ds, i.access = y.data.token, i.exp = Date.now() +
|
|
568
|
+
return i.sid = l.sid, i.ds = y.data.ds || l.ds, i.access = y.data.token, i.exp = Date.now() + ue, B = !1, W(), z();
|
|
562
569
|
}
|
|
563
|
-
async function
|
|
564
|
-
const o = X(), r = Math.max(1, Number(
|
|
570
|
+
async function ut(e, t, n) {
|
|
571
|
+
const o = X(), r = Math.max(1, Number(t.pollMax) || 5);
|
|
565
572
|
for (let s = 1; s <= r; s++) {
|
|
566
|
-
const a = i.ds || null, c = Date.now(), f = await
|
|
573
|
+
const a = i.ds || null, c = Date.now(), f = await K(N.VERIFY, {
|
|
567
574
|
method: "POST",
|
|
568
|
-
path: V(
|
|
569
|
-
origin:
|
|
575
|
+
path: V(w.SIGN.VERIFY),
|
|
576
|
+
origin: x(),
|
|
570
577
|
ds: a,
|
|
571
578
|
ts: c,
|
|
572
|
-
subject:
|
|
579
|
+
subject: e,
|
|
573
580
|
dna: n,
|
|
574
581
|
redirect: o
|
|
575
582
|
}, "sso");
|
|
576
583
|
let d;
|
|
577
584
|
try {
|
|
578
|
-
d = await h(w
|
|
585
|
+
d = await h(g(w.SIGN.VERIFY), { dsign: f, dna: n, redirect: o });
|
|
579
586
|
} catch (l) {
|
|
580
587
|
if ((l.code === u.NETWORK || l.code === u.TIMEOUT) && s < r) {
|
|
581
|
-
await U(
|
|
588
|
+
await U(t.pollInterval);
|
|
582
589
|
continue;
|
|
583
590
|
}
|
|
584
591
|
throw l;
|
|
@@ -587,33 +594,33 @@ async function ce(t, e, n) {
|
|
|
587
594
|
return d.data;
|
|
588
595
|
if (d.code === u.PENDING) {
|
|
589
596
|
if (s < r) {
|
|
590
|
-
await U(
|
|
597
|
+
await U(t.pollInterval);
|
|
591
598
|
continue;
|
|
592
599
|
}
|
|
593
600
|
break;
|
|
594
601
|
}
|
|
595
602
|
throw P(d, "登录失败");
|
|
596
603
|
}
|
|
597
|
-
throw new
|
|
604
|
+
throw new E(u.AUTH_EXPIRED, "登录超时,请重试");
|
|
598
605
|
}
|
|
599
|
-
async function
|
|
600
|
-
const r = await h(
|
|
606
|
+
async function ft(e, t, n, o) {
|
|
607
|
+
const r = await h(g(e), Object.assign({}, t, { device: n }));
|
|
601
608
|
if (r.code !== u.OK)
|
|
602
609
|
throw P(r, "登录失败");
|
|
603
610
|
const s = r.data && r.data.token;
|
|
604
611
|
if (!s)
|
|
605
612
|
throw P(r, "登录失败");
|
|
606
|
-
return
|
|
613
|
+
return rt(nt, s, 300), await dt(o), await Re(), i.cookie = !0, B = !1, W(), z();
|
|
607
614
|
}
|
|
608
|
-
async function
|
|
609
|
-
const
|
|
615
|
+
async function dt(e) {
|
|
616
|
+
const t = X(), n = Math.max(1, Number(e.pollMax) || 5);
|
|
610
617
|
for (let o = 1; o <= n; o++) {
|
|
611
618
|
let r;
|
|
612
619
|
try {
|
|
613
|
-
r = await h(w
|
|
620
|
+
r = await h(g(w.COOKIE.VERIFY), { redirect: t });
|
|
614
621
|
} catch (s) {
|
|
615
622
|
if ((s.code === u.NETWORK || s.code === u.TIMEOUT) && o < n) {
|
|
616
|
-
await U(
|
|
623
|
+
await U(e.pollInterval);
|
|
617
624
|
continue;
|
|
618
625
|
}
|
|
619
626
|
throw s;
|
|
@@ -622,107 +629,107 @@ async function ue(t) {
|
|
|
622
629
|
return r.data;
|
|
623
630
|
if (r.code === u.PENDING) {
|
|
624
631
|
if (o < n) {
|
|
625
|
-
await U(
|
|
632
|
+
await U(e.pollInterval);
|
|
626
633
|
continue;
|
|
627
634
|
}
|
|
628
635
|
break;
|
|
629
636
|
}
|
|
630
637
|
throw P(r, "登录失败");
|
|
631
638
|
}
|
|
632
|
-
throw new
|
|
639
|
+
throw new E(u.AUTH_EXPIRED, "登录超时,请重试");
|
|
633
640
|
}
|
|
634
|
-
async function
|
|
635
|
-
const
|
|
636
|
-
if (
|
|
637
|
-
throw P(
|
|
638
|
-
return
|
|
641
|
+
async function Re() {
|
|
642
|
+
const e = await h(g(w.COOKIE.TOKEN));
|
|
643
|
+
if (e.code !== u.OK)
|
|
644
|
+
throw P(e, "登录失败");
|
|
645
|
+
return e;
|
|
639
646
|
}
|
|
640
|
-
async function M(
|
|
641
|
-
const
|
|
642
|
-
return
|
|
647
|
+
async function M(e) {
|
|
648
|
+
const t = !!(e && e.force);
|
|
649
|
+
return F || (F = (async () => {
|
|
643
650
|
try {
|
|
644
|
-
return
|
|
651
|
+
return b() ? await lt(t) : await wt(t);
|
|
645
652
|
} catch (n) {
|
|
646
653
|
if (n && (n.code === u.NETWORK || n.code === u.TIMEOUT))
|
|
647
654
|
throw n;
|
|
648
655
|
return !1;
|
|
649
656
|
} finally {
|
|
650
|
-
|
|
657
|
+
F = null;
|
|
651
658
|
}
|
|
652
|
-
})()),
|
|
659
|
+
})()), F;
|
|
653
660
|
}
|
|
654
|
-
async function
|
|
655
|
-
return !
|
|
661
|
+
async function lt(e) {
|
|
662
|
+
return !e && i.cookie ? !0 : (await h(g(w.COOKIE.VERIFY), { redirect: X() })).code !== u.OK || (await Re()).code !== u.OK ? (i.cookie = !1, !1) : (i.cookie = !0, W(), !0);
|
|
656
663
|
}
|
|
657
|
-
async function
|
|
658
|
-
if (!i.sid || !i.ds || !await
|
|
664
|
+
async function gt() {
|
|
665
|
+
if (!i.sid || !i.ds || !await ce())
|
|
659
666
|
return !1;
|
|
660
|
-
const
|
|
667
|
+
const t = i.ds, n = await He(te.DOMAIN), o = await Ie(n), r = X(), s = await K(N.VERIFY_SID, {
|
|
661
668
|
method: "POST",
|
|
662
|
-
path: V(
|
|
663
|
-
origin:
|
|
664
|
-
ds:
|
|
669
|
+
path: V(w.SIGN.VERIFY),
|
|
670
|
+
origin: x(),
|
|
671
|
+
ds: t,
|
|
665
672
|
ts: Date.now(),
|
|
666
673
|
subject: i.sid,
|
|
667
674
|
dna: o,
|
|
668
675
|
redirect: r
|
|
669
|
-
}, "sso"), a = await h(w
|
|
676
|
+
}, "sso"), a = await h(g(w.SIGN.VERIFY), { dsign: s, dna: o, redirect: r });
|
|
670
677
|
if (a.code !== u.OK || !a.data)
|
|
671
678
|
return !1;
|
|
672
|
-
const c = await h(w
|
|
673
|
-
dsign: await
|
|
674
|
-
origin:
|
|
679
|
+
const c = await h(g(w.SIGN.TOKEN), {
|
|
680
|
+
dsign: await K(N.TOKEN, {
|
|
681
|
+
origin: x(),
|
|
675
682
|
ts: Date.now(),
|
|
676
683
|
subject: a.data.code,
|
|
677
684
|
dna: o
|
|
678
685
|
}, "domain"),
|
|
679
|
-
pk: await
|
|
686
|
+
pk: await ee(n)
|
|
680
687
|
});
|
|
681
|
-
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() +
|
|
688
|
+
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() + ue, W(), !0);
|
|
682
689
|
}
|
|
683
|
-
async function
|
|
684
|
-
return !
|
|
690
|
+
async function wt(e) {
|
|
691
|
+
return !e && i.access ? !0 : gt();
|
|
685
692
|
}
|
|
686
|
-
function
|
|
687
|
-
return
|
|
688
|
-
throw
|
|
689
|
-
})),
|
|
693
|
+
function de() {
|
|
694
|
+
return C || (C = (b() ? ht() : pt()).then((e) => (C = null, e), (e) => {
|
|
695
|
+
throw C = null, e;
|
|
696
|
+
})), C;
|
|
690
697
|
}
|
|
691
|
-
async function
|
|
692
|
-
const
|
|
693
|
-
if (
|
|
698
|
+
async function ht() {
|
|
699
|
+
const e = await h(g(w.COOKIE.REFRESH));
|
|
700
|
+
if (e.code === u.OK)
|
|
694
701
|
return !0;
|
|
695
|
-
if (
|
|
696
|
-
throw new O(
|
|
697
|
-
if (
|
|
702
|
+
if (e.code === u.AUTH_EXPIRED)
|
|
703
|
+
throw new O(e.message);
|
|
704
|
+
if (e.code === "500" && /重复/.test(e.message || ""))
|
|
698
705
|
return await U(800), !0;
|
|
699
|
-
throw new
|
|
706
|
+
throw new E(e.code, e.message);
|
|
700
707
|
}
|
|
701
|
-
async function
|
|
702
|
-
const
|
|
703
|
-
if (!
|
|
708
|
+
async function pt() {
|
|
709
|
+
const e = i.access, t = i.ds;
|
|
710
|
+
if (!e || !t)
|
|
704
711
|
throw new O();
|
|
705
|
-
const n = await
|
|
712
|
+
const n = await K(N.BIZ, {
|
|
706
713
|
method: "POST",
|
|
707
|
-
path: V(
|
|
708
|
-
origin:
|
|
709
|
-
ds:
|
|
714
|
+
path: V(w.SIGN.REFRESH),
|
|
715
|
+
origin: x(),
|
|
716
|
+
ds: t,
|
|
710
717
|
ts: Date.now(),
|
|
711
|
-
subject:
|
|
712
|
-
}, "domain"), o = await h(w
|
|
718
|
+
subject: e
|
|
719
|
+
}, "domain"), o = await h(g(w.SIGN.REFRESH, "dsign=" + encodeURIComponent(n)));
|
|
713
720
|
if (o.code === u.OK && o.data)
|
|
714
|
-
return i.access = o.data.token, o.data.ds && (i.ds = o.data.ds), i.exp = Date.now() +
|
|
715
|
-
const r = await
|
|
721
|
+
return i.access = o.data.token, o.data.ds && (i.ds = o.data.ds), i.exp = Date.now() + ue, i.access;
|
|
722
|
+
const r = await mt(e, 1200);
|
|
716
723
|
if (r)
|
|
717
724
|
return r;
|
|
718
|
-
throw o.code === u.AUTH_EXPIRED ? new O(o.message) : new
|
|
725
|
+
throw o.code === u.AUTH_EXPIRED ? new O(o.message) : new E(o.code, o.message);
|
|
719
726
|
}
|
|
720
|
-
function
|
|
721
|
-
const n = Date.now() +
|
|
727
|
+
function mt(e, t) {
|
|
728
|
+
const n = Date.now() + t;
|
|
722
729
|
return new Promise((o) => {
|
|
723
730
|
const r = () => {
|
|
724
731
|
const s = i.access;
|
|
725
|
-
if (s && s !==
|
|
732
|
+
if (s && s !== e) {
|
|
726
733
|
o(s);
|
|
727
734
|
return;
|
|
728
735
|
}
|
|
@@ -735,28 +742,36 @@ function he(t, e) {
|
|
|
735
742
|
r();
|
|
736
743
|
});
|
|
737
744
|
}
|
|
738
|
-
async function
|
|
745
|
+
async function Et() {
|
|
739
746
|
try {
|
|
740
|
-
let
|
|
741
|
-
|
|
742
|
-
} catch (
|
|
747
|
+
let t = await we();
|
|
748
|
+
t.code === u.AUTH_EXPIRED && (await de(), t = await we());
|
|
749
|
+
} catch (t) {
|
|
743
750
|
}
|
|
744
|
-
|
|
745
|
-
const
|
|
746
|
-
typeof
|
|
747
|
-
}
|
|
748
|
-
async function gt() {
|
|
749
|
-
if (S())
|
|
750
|
-
return h(w(g.LOGOUT));
|
|
751
|
-
const t = await at(g.LOGOUT, i.access, i.ds);
|
|
752
|
-
return h(w(g.LOGOUT, t));
|
|
753
|
-
}
|
|
754
|
-
async function me(t, e, n) {
|
|
755
|
-
const o = n || {};
|
|
756
|
-
return o.auth !== !1 && await Dt(), G(t, e || {}, o, !1);
|
|
751
|
+
Pe();
|
|
752
|
+
const e = I();
|
|
753
|
+
typeof e.onLogout == "function" && e.onLogout("logout");
|
|
757
754
|
}
|
|
758
|
-
async function
|
|
759
|
-
if (
|
|
755
|
+
async function we() {
|
|
756
|
+
if (b())
|
|
757
|
+
return h(g(w.LOGOUT));
|
|
758
|
+
const e = await ae(w.LOGOUT, i.access, i.ds);
|
|
759
|
+
return h(g(w.LOGOUT, e));
|
|
760
|
+
}
|
|
761
|
+
async function bt(e, t, n) {
|
|
762
|
+
const o = Ot(t, n);
|
|
763
|
+
return o.authed && await De(), Y(e, o.body, o.options, !1);
|
|
764
|
+
}
|
|
765
|
+
function Ot(e, t) {
|
|
766
|
+
const n = t || {};
|
|
767
|
+
return !(typeof FormData != "undefined" && e instanceof FormData) && e !== null && typeof e == "object" && !Array.isArray(e) && ("data" in e || "noToken" in e || "loading" in e || "error" in e) ? {
|
|
768
|
+
body: e.data,
|
|
769
|
+
options: Object.assign({}, e, n),
|
|
770
|
+
authed: e.noToken !== !0 && n.auth !== !1
|
|
771
|
+
} : { body: e, options: n, authed: n.auth !== !1 };
|
|
772
|
+
}
|
|
773
|
+
async function De() {
|
|
774
|
+
if (b()) {
|
|
760
775
|
if (i.cookie || await M())
|
|
761
776
|
return;
|
|
762
777
|
throw R("expired"), new O();
|
|
@@ -764,106 +779,106 @@ async function Dt() {
|
|
|
764
779
|
if (!i.access && !await M())
|
|
765
780
|
throw R("expired"), new O();
|
|
766
781
|
}
|
|
767
|
-
async function
|
|
768
|
-
const r = n.auth !== !1, s = r && !
|
|
782
|
+
async function Y(e, t, n, o) {
|
|
783
|
+
const r = n.auth !== !1 && n.noToken !== !0, s = r && !b();
|
|
769
784
|
let a = "", c = null;
|
|
770
785
|
if (s) {
|
|
771
786
|
c = i.access;
|
|
772
787
|
try {
|
|
773
|
-
a = await
|
|
788
|
+
a = await ae(e, c, i.ds);
|
|
774
789
|
} catch (d) {
|
|
775
790
|
if (!o && await M({ force: !0 }))
|
|
776
|
-
return
|
|
791
|
+
return Y(e, t, n, !0);
|
|
777
792
|
throw R("expired"), new O();
|
|
778
793
|
}
|
|
779
794
|
}
|
|
780
|
-
const f = await h(
|
|
795
|
+
const f = await h(g(e, a), t, n.timeout);
|
|
781
796
|
if (f.code === u.OK)
|
|
782
|
-
return f
|
|
797
|
+
return f;
|
|
783
798
|
if (r && f.code === u.AUTH_EXPIRED && !o) {
|
|
784
799
|
if (s && c && i.access !== c)
|
|
785
|
-
return
|
|
800
|
+
return Y(e, t, n, !0);
|
|
786
801
|
try {
|
|
787
|
-
await
|
|
802
|
+
await de();
|
|
788
803
|
} catch (d) {
|
|
789
804
|
throw d instanceof O && R("expired"), d;
|
|
790
805
|
}
|
|
791
|
-
return
|
|
806
|
+
return Y(e, t, n, !0);
|
|
792
807
|
}
|
|
793
|
-
throw r && f.code === u.AUTH_EXPIRED ? (R("expired"), new O(f.message)) :
|
|
808
|
+
throw r && f.code === u.AUTH_EXPIRED ? (R("expired"), new O(f.message)) : Ne(f);
|
|
794
809
|
}
|
|
795
|
-
function
|
|
796
|
-
const
|
|
797
|
-
return n.onError && n.onError({ code:
|
|
810
|
+
function Ne(e) {
|
|
811
|
+
const t = new E(e.code, e.message), n = I();
|
|
812
|
+
return n.onError && n.onError({ code: e.code, message: e.message, error: t }), t;
|
|
798
813
|
}
|
|
799
|
-
async function
|
|
800
|
-
return (
|
|
814
|
+
async function St(e, t, n, o) {
|
|
815
|
+
return (b() ? !i.cookie : !i.access) && await De(), oe(e, t, n, o || {}, !1);
|
|
801
816
|
}
|
|
802
|
-
async function
|
|
817
|
+
async function oe(e, t, n, o, r) {
|
|
803
818
|
let s = "";
|
|
804
|
-
if (!
|
|
819
|
+
if (!b())
|
|
805
820
|
try {
|
|
806
|
-
s = await
|
|
821
|
+
s = await ae(e, i.access, i.ds);
|
|
807
822
|
} catch (f) {
|
|
808
823
|
if (!r && await M({ force: !0 }))
|
|
809
|
-
return
|
|
824
|
+
return oe(e, t, n, o, !0);
|
|
810
825
|
throw R("expired"), new O();
|
|
811
826
|
}
|
|
812
827
|
const a = new FormData();
|
|
813
828
|
Object.keys(n || {}).forEach((f) => {
|
|
814
829
|
const d = n[f];
|
|
815
830
|
d != null && a.append(f, d);
|
|
816
|
-
}), a.append("file",
|
|
817
|
-
const c = await h(
|
|
831
|
+
}), a.append("file", t);
|
|
832
|
+
const c = await h(g(e, s), a, o.timeout);
|
|
818
833
|
if (c.code === u.OK)
|
|
819
|
-
return c
|
|
834
|
+
return c;
|
|
820
835
|
if (c.code === u.AUTH_EXPIRED && !r) {
|
|
821
836
|
try {
|
|
822
|
-
await
|
|
837
|
+
await de();
|
|
823
838
|
} catch (f) {
|
|
824
839
|
throw f instanceof O && R("expired"), f;
|
|
825
840
|
}
|
|
826
|
-
return
|
|
841
|
+
return oe(e, t, n, o, !0);
|
|
827
842
|
}
|
|
828
|
-
throw
|
|
843
|
+
throw Ne(c);
|
|
829
844
|
}
|
|
830
|
-
function
|
|
831
|
-
const
|
|
832
|
-
if (
|
|
833
|
-
const n =
|
|
845
|
+
function It(e) {
|
|
846
|
+
const t = Ke(e);
|
|
847
|
+
if (Me(), t.nativeGuard !== "off") {
|
|
848
|
+
const n = ke();
|
|
834
849
|
if (n.length) {
|
|
835
850
|
const o = "[dplugin/core] 这些原生能力在模块加载前已被替换:" + n.join(", ") + "(签名/请求可能被中间人截获,检查是否有脚本抢跑)";
|
|
836
|
-
if (
|
|
851
|
+
if (t.nativeGuard === "error")
|
|
837
852
|
throw new Error(o);
|
|
838
853
|
typeof console != "undefined" && console.warn(o);
|
|
839
854
|
}
|
|
840
855
|
}
|
|
841
856
|
}
|
|
842
|
-
const
|
|
843
|
-
login:
|
|
844
|
-
logout:
|
|
845
|
-
isLogin:
|
|
846
|
-
getState:
|
|
857
|
+
const Tt = {
|
|
858
|
+
login: it,
|
|
859
|
+
logout: Et,
|
|
860
|
+
isLogin: fe,
|
|
861
|
+
getState: z,
|
|
847
862
|
/** 页面加载时恢复登录态;返回是否已登录 */
|
|
848
863
|
restore: M
|
|
849
864
|
};
|
|
850
865
|
export {
|
|
851
866
|
O as AuthError,
|
|
852
|
-
|
|
867
|
+
E as BizError,
|
|
853
868
|
u as CODE,
|
|
854
|
-
|
|
855
|
-
|
|
869
|
+
Tt as auth,
|
|
870
|
+
Pe as clear,
|
|
856
871
|
R as expire,
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
872
|
+
pe as getMode,
|
|
873
|
+
z as getState,
|
|
874
|
+
yt as isAuthError,
|
|
875
|
+
fe as isLogin,
|
|
876
|
+
it as login,
|
|
877
|
+
Et as logout,
|
|
878
|
+
bt as request,
|
|
879
|
+
It as setup,
|
|
865
880
|
i as store,
|
|
866
|
-
|
|
881
|
+
St as upload,
|
|
867
882
|
M as verifyLogin
|
|
868
883
|
};
|
|
869
884
|
//# sourceMappingURL=index.mjs.map
|