@dplugin/core 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,60 +22,60 @@ const _ = {
22
22
  // 原生能力体检:'warn' 只告警 / 'error' 直接抛错 / 'off' 不检查
23
23
  nativeGuard: "warn"
24
24
  };
25
- function Ke(e) {
26
- return e && Object.keys(_).forEach((t) => {
27
- e[t] !== void 0 && (_[t] = e[t]);
28
- }), _;
25
+ function xt(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 m = xe();
34
- function Z(e, t) {
35
- if (typeof e != "function")
33
+ const E = At();
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(e);
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] === t : /\[native code\]/.test(n) && !/^function\s*\(\s*\)\s*\{\s*\[native code\]\s*\}$/.test(n);
44
+ return o ? o[1] === e : /\[native code\]/.test(n) && !/^function\s*\(\s*\)\s*\{\s*\[native code\]\s*\}$/.test(n);
45
45
  }
46
- function Ae(e) {
46
+ function Kt(t) {
47
47
  try {
48
- const t = e();
49
- return t && typeof t.then == "function" && Promise.resolve(t).catch(() => {
48
+ const e = t();
49
+ return e && typeof e.then == "function" && Promise.resolve(e).catch(() => {
50
50
  }), !1;
51
- } catch (t) {
52
- const n = String(t && t.message || "");
53
- return !!t && t.name === "TypeError" && /argument|required|参数/i.test(n);
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 xe() {
57
- const e = globalThis, t = typeof e.window != "undefined" && e.window && typeof e.window.document != "undefined", n = {
56
+ function At() {
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 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;
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 || Kt(() => 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;
68
68
  r.forEach((c) => {
69
- typeof o[c] == "function" && (s[c] = o[c].bind(o), a = a && Z(o[c], c));
69
+ typeof o[c] == "function" && (s[c] = o[c].bind(o), a = a && $(o[c], c));
70
70
  }), n.subtle = s, n.pristine.subtle = a;
71
71
  }
72
72
  return n;
73
73
  }
74
- function ke() {
74
+ function Ct() {
75
75
  if (typeof window == "undefined" || typeof window.document == "undefined")
76
76
  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;
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",
@@ -87,74 +87,74 @@ const u = {
87
87
  NETWORK: "NETWORK",
88
88
  TIMEOUT: "TIMEOUT"
89
89
  };
90
- class E extends Error {
91
- constructor(t, n) {
92
- super(n || "请求失败"), this.name = "BizError", this.code = t;
90
+ class m extends Error {
91
+ constructor(e, n) {
92
+ super(n || "请求失败"), this.name = "BizError", this.code = e;
93
93
  }
94
94
  }
95
- class O extends E {
96
- constructor(t) {
97
- super(u.AUTH_EXPIRED, t || "登录已失效"), this.name = "AuthError";
95
+ class O extends m {
96
+ constructor(e) {
97
+ super(u.AUTH_EXPIRED, e || "登录已失效"), this.name = "AuthError";
98
98
  }
99
99
  }
100
- function yt(e) {
101
- return e instanceof O || e && e.code === u.AUTH_EXPIRED;
100
+ function Ee(t) {
101
+ return t instanceof O || t && t.code === u.AUTH_EXPIRED;
102
102
  }
103
- const $ = "dplugin.access", q = "dplugin.sid", le = "dplugin.ds", J = "dplugin.exp", Q = "dplugin.cookie", Ce = "token";
104
- function _e(e) {
103
+ const q = "dplugin.access", z = "dplugin.sid", lt = "dplugin.ds", J = "dplugin.exp", Q = "dplugin.cookie";
104
+ function _t(t) {
105
105
  try {
106
- return localStorage.getItem(e);
107
- } catch (t) {
106
+ return localStorage.getItem(t);
107
+ } catch (e) {
108
108
  return null;
109
109
  }
110
110
  }
111
- function he(e, t) {
111
+ function ht(t, e) {
112
112
  try {
113
- t == null || t === "" ? localStorage.removeItem(e) : localStorage.setItem(e, t);
113
+ e == null || e === "" ? localStorage.removeItem(t) : localStorage.setItem(t, e);
114
114
  } catch (n) {
115
115
  }
116
116
  }
117
- const G = {};
118
- function x(e) {
119
- const t = _e(e);
120
- return t === null ? G[e] === void 0 ? null : G[e] : t;
117
+ const H = {};
118
+ function A(t) {
119
+ const e = _t(t);
120
+ return e === null ? H[t] === void 0 ? null : H[t] : e;
121
121
  }
122
- function k(e, t) {
123
- G[e] = t, he(e, t);
122
+ function C(t, e) {
123
+ H[t] = e, ht(t, e);
124
124
  }
125
125
  const i = {
126
126
  get access() {
127
- return x($);
127
+ return A(q);
128
128
  },
129
- set access(e) {
130
- k($, e);
129
+ set access(t) {
130
+ C(q, t);
131
131
  },
132
132
  get sid() {
133
- return x(q);
133
+ return A(z);
134
134
  },
135
- set sid(e) {
136
- k(q, e);
135
+ set sid(t) {
136
+ C(z, t);
137
137
  },
138
138
  get ds() {
139
- return x(le);
139
+ return A(lt);
140
140
  },
141
- set ds(e) {
142
- k(le, e);
141
+ set ds(t) {
142
+ C(lt, t);
143
143
  },
144
144
  /** access 的到期时间(毫秒时间戳)。仅用于界面判断,不要拿它做提前续期 */
145
145
  get exp() {
146
- const e = x(J);
147
- return e ? Number(e) : 0;
146
+ const t = A(J);
147
+ return t ? Number(t) : 0;
148
148
  },
149
- set exp(e) {
150
- k(J, e ? String(e) : null);
149
+ set exp(t) {
150
+ C(J, t ? String(t) : null);
151
151
  },
152
152
  /** cookie 模式:本地只记「可能已登录」,实际有效性由第一次请求的结果决定 */
153
153
  get cookie() {
154
- return x(Q) === "1";
154
+ return A(Q) === "1";
155
155
  },
156
- set cookie(e) {
157
- k(Q, e ? "1" : null);
156
+ set cookie(t) {
157
+ C(Q, t ? "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, J, Q, Ce].forEach((e) => {
167
- G[e] = null, he(e, null);
166
+ [q, z, J, Q].forEach((t) => {
167
+ H[t] = null, ht(t, null);
168
168
  });
169
169
  }
170
170
  };
171
- function g(e, t) {
171
+ function w(t, e) {
172
172
  const n = I().apiBase || "";
173
- let o = e;
174
- return /^https?:\/\//i.test(e) || (o = (n ? n.replace(/\/+$/, "") : "") + (e.startsWith("/") ? e : "/" + e)), t && (o += (o.includes("?") ? "&" : "?") + t), o;
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 B(e) {
177
- const t = g(e);
178
- if (/^https?:\/\//i.test(t))
176
+ function V(t) {
177
+ const e = w(t);
178
+ if (/^https?:\/\//i.test(e))
179
179
  try {
180
- return new URL(t).pathname;
180
+ return new URL(e).pathname;
181
181
  } catch (n) {
182
- return t.split("?")[0];
182
+ return e.split("?")[0];
183
183
  }
184
184
  try {
185
- return new URL(t, "http://localhost").pathname;
185
+ return new URL(e, "http://localhost").pathname;
186
186
  } catch (n) {
187
- return t.split("?")[0];
187
+ return e.split("?")[0];
188
188
  }
189
189
  }
190
- let S = null;
191
- function Ue(e) {
190
+ let b = null;
191
+ function kt(t) {
192
192
  try {
193
- const t = typeof location != "undefined" ? location.href : void 0;
194
- return new URL(e || "", t).origin;
195
- } catch (t) {
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 Me() {
200
- S = null;
199
+ function Ut() {
200
+ b = null;
201
201
  }
202
- function pe() {
203
- if (S)
204
- return S;
205
- const e = I();
206
- if (e.mode === "sign" || e.mode === "cookie")
207
- return S = e.mode, S;
208
- const t = typeof location != "undefined" ? location.origin : null;
209
- if (!t)
210
- return S = "sign", S;
211
- const n = Ue(e.apiBase || t);
212
- return S = n && n === t ? "cookie" : "sign", S;
213
- }
214
- function b() {
215
- return pe() === "cookie";
216
- }
217
- async function h(e, t, n) {
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 = kt(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: b() ? "same-origin" : "omit",
221
+ credentials: S() ? "same-origin" : "omit",
222
222
  signal: s ? s.signal : void 0
223
223
  };
224
- if (typeof FormData != "undefined" && t instanceof FormData ? c.body = t : t != null && (c.headers = { "Content-Type": "text/plain" }, c.body = JSON.stringify(t)), !m.fetch)
225
- throw new E(u.NETWORK, "当前环境不支持 fetch");
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
+ throw new m(u.NETWORK, "当前环境不支持 fetch");
226
226
  let f;
227
227
  try {
228
- f = await m.fetch(e, c);
228
+ f = await E.fetch(t, c);
229
229
  } catch (y) {
230
- throw a && clearTimeout(a), y && y.name === "AbortError" ? new E(u.TIMEOUT, "请求超时,请重试") : new E(u.NETWORK, "网络异常,请检查网络后重试");
230
+ throw a && clearTimeout(a), y && y.name === "AbortError" ? new m(u.TIMEOUT, "请求超时,请重试") : new m(u.NETWORK, "网络异常,请检查网络后重试");
231
231
  }
232
232
  a && clearTimeout(a);
233
233
  const d = await f.text();
@@ -239,44 +239,44 @@ async function h(e, t, n) {
239
239
  l = null;
240
240
  }
241
241
  if (!f.ok)
242
- throw new E(String(f.status), l && l.message || d || "请求失败");
242
+ throw new m(String(f.status), l && l.message || d || "请求失败");
243
243
  if (!l || l.code === null || l.code === void 0)
244
- throw new E("500", "响应格式异常");
244
+ throw new m("500", "响应格式异常");
245
245
  return l.code = String(l.code), l;
246
246
  }
247
- const Le = "dplugin-auth", Fe = 1, Y = "keys", re = "sso", ie = "domain", ve = { name: "ECDSA", namedCurve: "P-256" }, je = { name: "ECDSA", hash: "SHA-256" }, v = /* @__PURE__ */ new Map();
248
- let L = null;
249
- function V() {
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);
247
+ const Mt = "dplugin-auth", vt = 1, Y = "keys", rt = "sso", it = "domain", Lt = { name: "ECDSA", namedCurve: "P-256" }, Ft = { name: "ECDSA", hash: "SHA-256" }, F = /* @__PURE__ */ new Map();
248
+ let v = null;
249
+ function j() {
250
+ if (!E.subtle) {
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
- return m.subtle;
254
+ return E.subtle;
255
255
  }
256
- function Ge() {
257
- return L || (L = new Promise((e) => {
258
- if (!m.idbOpen) {
259
- e(null);
256
+ function Gt() {
257
+ return v || (v = new Promise((t) => {
258
+ if (!E.idbOpen) {
259
+ t(null);
260
260
  return;
261
261
  }
262
- let t;
262
+ let e;
263
263
  try {
264
- t = m.idbOpen(Le, Fe);
264
+ e = E.idbOpen(Mt, vt);
265
265
  } catch (n) {
266
- e(null);
266
+ t(null);
267
267
  return;
268
268
  }
269
- t.onupgradeneeded = () => {
270
- const n = t.result;
269
+ e.onupgradeneeded = () => {
270
+ const n = e.result;
271
271
  n.objectStoreNames.contains(Y) || n.createObjectStore(Y);
272
- }, t.onsuccess = () => e(t.result), t.onerror = () => e(null), t.onblocked = () => e(null);
273
- }), L);
272
+ }, e.onsuccess = () => t(e.result), e.onerror = () => t(null), e.onblocked = () => t(null);
273
+ }), v);
274
274
  }
275
- function me(e, t) {
276
- return Ge().then((n) => n ? new Promise((o) => {
275
+ function Et(t, e) {
276
+ return Gt().then((n) => n ? new Promise((o) => {
277
277
  let r;
278
278
  try {
279
- r = n.transaction(Y, e);
279
+ r = n.transaction(Y, t);
280
280
  } catch (c) {
281
281
  o(null);
282
282
  return;
@@ -284,7 +284,7 @@ function me(e, t) {
284
284
  const s = r.objectStore(Y);
285
285
  let a = null;
286
286
  try {
287
- const c = t(s);
287
+ const c = e(s);
288
288
  c && (c.onsuccess = () => {
289
289
  a = c.result;
290
290
  }, c.onerror = () => {
@@ -296,169 +296,169 @@ function me(e, t) {
296
296
  r.oncomplete = () => o(a), r.onerror = () => o(null), r.onabort = () => o(null);
297
297
  }) : null);
298
298
  }
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));
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 Oe(e, t) {
303
- return v.set(e, t), me("readwrite", (n) => n.put(t, e)).then(() => t);
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 se(e) {
306
- const n = await V().generateKey(ve, !1, ["sign", "verify"]);
307
- return Oe(e, n);
305
+ async function st(t) {
306
+ const n = await j().generateKey(Lt, !1, ["sign", "verify"]);
307
+ return Ot(t, n);
308
308
  }
309
- async function ye(e) {
310
- return Ee(e);
309
+ async function yt(t) {
310
+ return mt(t);
311
311
  }
312
- async function ge(e, t) {
313
- return t ? Oe(e, t) : null;
312
+ async function wt(t, e) {
313
+ return e ? Ot(t, e) : null;
314
314
  }
315
- async function Ye(e) {
316
- return await Ee(e) || se(e);
315
+ async function Ht(t) {
316
+ return await mt(t) || st(t);
317
317
  }
318
- function He() {
319
- return se(re);
318
+ function Yt() {
319
+ return st(rt);
320
320
  }
321
- function Be() {
322
- return se(ie);
321
+ function Bt() {
322
+ return st(it);
323
323
  }
324
- function ce() {
325
- return ye(re);
324
+ function ct() {
325
+ return yt(rt);
326
326
  }
327
- function be() {
328
- return ye(ie);
327
+ function St() {
328
+ return yt(it);
329
329
  }
330
- async function ee(e) {
331
- const n = await V().exportKey("spki", e.publicKey);
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 Se(e) {
339
- const t = new Uint8Array(e);
338
+ function bt(t) {
339
+ const e = new Uint8Array(t);
340
340
  let n = "";
341
- for (let o = 0; o < t.length; o++)
342
- n += String.fromCharCode(t[o]);
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 Ve(e, t) {
346
- const o = await V().sign(je, e.privateKey, new TextEncoder().encode(t));
347
- return Se(o);
345
+ async function Vt(t, e) {
346
+ const o = await j().sign(Ft, t.privateKey, new TextEncoder().encode(e));
347
+ return bt(o);
348
348
  }
349
- async function Ie(e) {
350
- const t = V(), n = await t.exportKey("spki", e.publicKey), o = await t.digest("SHA-256", n);
351
- return Se(o);
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 te = {
354
- SSO: re,
355
- DOMAIN: ie
356
- }, ne = "-", Xe = "POST", N = {
353
+ const et = {
354
+ SSO: rt,
355
+ DOMAIN: it
356
+ }, nt = "-", jt = "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(e) {
363
- return e == null || e === "" ? ne : String(e);
362
+ function p(t) {
363
+ return t == null || t === "" ? nt : String(t);
364
364
  }
365
- function We(e, t) {
366
- const n = p(t.origin);
365
+ function Xt(t, e) {
366
+ const n = p(e.origin);
367
367
  return [
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)
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 ze(e, t, n) {
381
- return [p(e), p(t.subject), p(t.ds), p(t.ts), n].join(".");
380
+ function Wt(t, e, n) {
381
+ return [p(t), p(e.subject), p(e.ds), p(e.ts), n].join(".");
382
382
  }
383
- async function K(e, t, n) {
384
- const o = n === "sso" ? await ce() : await be();
383
+ async function x(t, e, n) {
384
+ const o = n === "sso" ? await ct() : await St();
385
385
  if (!o)
386
- throw Te(n === "sso" ? "缺少登录签名密钥" : "缺少业务签名密钥");
387
- const r = await Ve(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: B(e),
396
- origin: A(),
386
+ throw Tt(n === "sso" ? "缺少登录签名密钥" : "缺少业务签名密钥");
387
+ const r = await Vt(o, Xt(t, e));
388
+ return Wt(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: jt,
395
+ path: V(t),
396
+ origin: K(),
397
397
  ds: n,
398
398
  ts: Date.now(),
399
- subject: t
399
+ subject: e
400
400
  }, "domain");
401
401
  return "dsign=" + encodeURIComponent(o);
402
402
  }
403
- function A() {
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 (e) {
410
+ } catch (t) {
411
411
  return "";
412
412
  }
413
413
  }
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)
414
+ function Tt(t) {
415
+ const e = new Error(t);
416
+ return e.code = "KEY_MISSING", e;
417
+ }
418
+ function Zt() {
419
+ const t = typeof navigator != "undefined" && navigator.userAgent || "", e = {
420
+ device_brand: $t(t),
421
+ device_model: qt(t),
422
+ browser_name: zt(t),
423
+ browser_version: Jt(t),
424
+ os_name: Qt(t),
425
+ os_version: te(t)
426
426
  }, n = i.ds;
427
- return n && (t.device_id = n), t;
427
+ return n && (e.device_id = n), e;
428
428
  }
429
- function T(e, t) {
430
- const n = e.match(t);
429
+ function T(t, e) {
430
+ const n = t.match(e);
431
431
  return n ? n[1] : "";
432
432
  }
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" : "";
433
+ function $t(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 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" : "";
436
+ function qt(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 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" : "";
442
+ function zt(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 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.]+)/) : "";
445
+ function Jt(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 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" : "";
448
+ function Qt(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 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+)?)/);
451
+ function te(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
- const w = {
461
+ const g = {
462
462
  SIGN: {
463
463
  VERIFY: "/api/unsafe/dplugin/login/s/verify",
464
464
  TOKEN: "/api/unsafe/dplugin/login/s/token",
@@ -470,122 +470,115 @@ const w = {
470
470
  REFRESH: "/api/unsafe/dplugin/login/c/refresh"
471
471
  },
472
472
  LOGOUT: "/api/safe/dplugin/login/logout"
473
- }, nt = "dp_dvt", ue = 1800 * 1e3;
474
- let C = null, F = null, D = null, H = !1;
473
+ }, ee = "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(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
- }
478
+ function U(t) {
479
+ return new Promise((e) => setTimeout(e, t));
486
480
  }
487
481
  function W() {
488
- ot();
489
- const e = I();
490
- typeof e.onLogin == "function" && e.onLogin(z());
482
+ const t = I();
483
+ typeof t.onLogin == "function" && t.onLogin(Z());
491
484
  }
492
- function P(e, t) {
493
- return new E(e.code, e.message || t);
485
+ function P(t, e) {
486
+ return new m(t.code, t.message || e);
494
487
  }
495
- function rt(e, t, n) {
488
+ function ne(t, e, n) {
496
489
  if (typeof document == "undefined")
497
490
  return;
498
- let o = e + "=" + encodeURIComponent(t) + "; path=/; SameSite=Lax";
491
+ let o = t + "=" + encodeURIComponent(e) + "; path=/; SameSite=Lax";
499
492
  o += "; max-age=" + n, document.cookie = o;
500
493
  }
501
- function z() {
494
+ function Z() {
502
495
  return {
503
- mode: pe(),
504
- loggedIn: fe(),
496
+ mode: pt(),
497
+ loggedIn: ft(),
505
498
  hasAccess: !!i.access,
506
499
  sid: i.sid,
507
500
  ds: i.ds
508
501
  };
509
502
  }
510
- function fe() {
511
- return b() ? !!i.cookie : !!(i.access || i.sid);
503
+ function ft() {
504
+ return S() ? !!i.cookie : !!(i.access || i.sid);
512
505
  }
513
- function Pe() {
506
+ function Pt() {
514
507
  i.clear();
515
508
  }
516
- function R(e) {
517
- const t = fe();
518
- Pe();
509
+ function R(t) {
510
+ const e = ft();
511
+ Pt();
519
512
  const n = I();
520
- if (t && typeof n.onLogout == "function" && n.onLogout(e || "expired"), H || !n.enableAuth || !n.loginUrl || typeof location == "undefined")
513
+ if (e && typeof n.onLogout == "function" && n.onLogout(t || "expired"), B || !n.enableAuth || !n.loginUrl || typeof location == "undefined")
521
514
  return;
522
- H = !0;
515
+ B = !0;
523
516
  const o = n.loginUrl.includes("?") ? "&" : "?";
524
517
  location.href = n.loginUrl + o + "referer=" + encodeURIComponent(location.href);
525
518
  }
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;
519
+ function oe(t, e) {
520
+ return D || (D = ie(t, e).then((n) => (D = null, n), (n) => {
521
+ throw D = null, re(n), n;
529
522
  }), D);
530
523
  }
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
524
+ function re(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
537
530
  });
538
531
  }
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();
532
+ async function ie(t, e) {
533
+ const n = I(), o = Zt();
534
+ if (S())
535
+ return ae(t, e, o, n);
536
+ const r = await ct(), s = await St();
544
537
  try {
545
- return await at(e, t, o, n);
538
+ return await se(t, e, o, n);
546
539
  } catch (a) {
547
- throw await ge(te.SSO, r), await ge(te.DOMAIN, s), a;
540
+ throw await wt(et.SSO, r), await wt(et.DOMAIN, s), a;
548
541
  }
549
542
  }
550
- async function at(e, t, n, o) {
551
- const r = await He(), s = await ee(r), a = await h(g(e), Object.assign({}, t, { device: n, pk: s }));
543
+ async function se(t, e, n, o) {
544
+ const r = await Yt(), s = await tt(r), a = await h(w(t), Object.assign({}, e, { device: n, pk: s }));
552
545
  if (a.code !== u.OK)
553
546
  throw P(a, "登录失败");
554
547
  const c = a.data && a.data.token;
555
548
  if (!c)
556
549
  throw P(a, "登录失败");
557
- const f = await Be(), 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: A(),
550
+ const f = await Bt(), d = await It(f), l = await ce(c, o, d), y = await h(w(g.SIGN.TOKEN), {
551
+ dsign: await x(N.TOKEN, {
552
+ origin: K(),
560
553
  ts: Date.now(),
561
554
  subject: l.code,
562
555
  dna: d
563
556
  }, "domain"),
564
- pk: await ee(f)
557
+ pk: await tt(f)
565
558
  });
566
559
  if (y.code !== u.OK || !y.data)
567
560
  throw P(y, "登录失败");
568
- return i.sid = l.sid, i.ds = y.data.ds || l.ds, i.access = y.data.token, i.exp = Date.now() + ue, H = !1, W(), z();
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();
569
562
  }
570
- async function ut(e, t, n) {
571
- const o = X(), r = Math.max(1, Number(t.pollMax) || 5);
563
+ async function ce(t, e, n) {
564
+ const o = X(), r = Math.max(1, Number(e.pollMax) || 5);
572
565
  for (let s = 1; s <= r; s++) {
573
- const a = i.ds || null, c = Date.now(), f = await K(N.VERIFY, {
566
+ const a = i.ds || null, c = Date.now(), f = await x(N.VERIFY, {
574
567
  method: "POST",
575
- path: B(w.SIGN.VERIFY),
576
- origin: A(),
568
+ path: V(g.SIGN.VERIFY),
569
+ origin: K(),
577
570
  ds: a,
578
571
  ts: c,
579
- subject: e,
572
+ subject: t,
580
573
  dna: n,
581
574
  redirect: o
582
575
  }, "sso");
583
576
  let d;
584
577
  try {
585
- d = await h(g(w.SIGN.VERIFY), { dsign: f, dna: n, redirect: o });
578
+ d = await h(w(g.SIGN.VERIFY), { dsign: f, dna: n, redirect: o });
586
579
  } catch (l) {
587
580
  if ((l.code === u.NETWORK || l.code === u.TIMEOUT) && s < r) {
588
- await U(t.pollInterval);
581
+ await U(e.pollInterval);
589
582
  continue;
590
583
  }
591
584
  throw l;
@@ -594,33 +587,33 @@ async function ut(e, t, n) {
594
587
  return d.data;
595
588
  if (d.code === u.PENDING) {
596
589
  if (s < r) {
597
- await U(t.pollInterval);
590
+ await U(e.pollInterval);
598
591
  continue;
599
592
  }
600
593
  break;
601
594
  }
602
595
  throw P(d, "登录失败");
603
596
  }
604
- throw new E(u.AUTH_EXPIRED, "登录超时,请重试");
597
+ throw new m(u.AUTH_EXPIRED, "登录超时,请重试");
605
598
  }
606
- async function ft(e, t, n, o) {
607
- const r = await h(g(e), Object.assign({}, t, { device: n }));
599
+ async function ae(t, e, n, o) {
600
+ const r = await h(w(t), Object.assign({}, e, { device: n }));
608
601
  if (r.code !== u.OK)
609
602
  throw P(r, "登录失败");
610
603
  const s = r.data && r.data.token;
611
604
  if (!s)
612
605
  throw P(r, "登录失败");
613
- return rt(nt, s, 300), await dt(o), await Re(), i.cookie = !0, H = !1, W(), z();
606
+ return ne(ee, s, 300), await ue(o), await Rt(), i.cookie = !0, B = !1, W(), Z();
614
607
  }
615
- async function dt(e) {
616
- const t = X(), n = Math.max(1, Number(e.pollMax) || 5);
608
+ async function ue(t) {
609
+ const e = X(), n = Math.max(1, Number(t.pollMax) || 5);
617
610
  for (let o = 1; o <= n; o++) {
618
611
  let r;
619
612
  try {
620
- r = await h(g(w.COOKIE.VERIFY), { redirect: t });
613
+ r = await h(w(g.COOKIE.VERIFY), { redirect: e });
621
614
  } catch (s) {
622
615
  if ((s.code === u.NETWORK || s.code === u.TIMEOUT) && o < n) {
623
- await U(e.pollInterval);
616
+ await U(t.pollInterval);
624
617
  continue;
625
618
  }
626
619
  throw s;
@@ -629,107 +622,107 @@ async function dt(e) {
629
622
  return r.data;
630
623
  if (r.code === u.PENDING) {
631
624
  if (o < n) {
632
- await U(e.pollInterval);
625
+ await U(t.pollInterval);
633
626
  continue;
634
627
  }
635
628
  break;
636
629
  }
637
630
  throw P(r, "登录失败");
638
631
  }
639
- throw new E(u.AUTH_EXPIRED, "登录超时,请重试");
632
+ throw new m(u.AUTH_EXPIRED, "登录超时,请重试");
640
633
  }
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;
634
+ async function Rt() {
635
+ const t = await h(w(g.COOKIE.TOKEN));
636
+ if (t.code !== u.OK)
637
+ throw P(t, "登录失败");
638
+ return t;
646
639
  }
647
- async function M(e) {
648
- const t = !!(e && e.force);
649
- return F || (F = (async () => {
640
+ async function M(t) {
641
+ const e = !!(t && t.force);
642
+ return L || (L = (async () => {
650
643
  try {
651
- return b() ? await lt(t) : await wt(t);
644
+ return S() ? await fe(e) : await le(e);
652
645
  } catch (n) {
653
646
  if (n && (n.code === u.NETWORK || n.code === u.TIMEOUT))
654
647
  throw n;
655
648
  return !1;
656
649
  } finally {
657
- F = null;
650
+ L = null;
658
651
  }
659
- })()), F;
652
+ })()), L;
660
653
  }
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);
654
+ async function fe(t) {
655
+ return !t && i.cookie ? !0 : (await h(w(g.COOKIE.VERIFY), { redirect: X() })).code !== u.OK || (await Rt()).code !== u.OK ? (i.cookie = !1, !1) : (i.cookie = !0, W(), !0);
663
656
  }
664
- async function gt() {
665
- if (!i.sid || !i.ds || !await ce())
657
+ async function de() {
658
+ if (!i.sid || !i.ds || !await ct())
666
659
  return !1;
667
- const t = i.ds, n = await Ye(te.DOMAIN), o = await Ie(n), r = X(), s = await K(N.VERIFY_SID, {
660
+ const e = i.ds, n = await Ht(et.DOMAIN), o = await It(n), r = X(), s = await x(N.VERIFY_SID, {
668
661
  method: "POST",
669
- path: B(w.SIGN.VERIFY),
670
- origin: A(),
671
- ds: t,
662
+ path: V(g.SIGN.VERIFY),
663
+ origin: K(),
664
+ ds: e,
672
665
  ts: Date.now(),
673
666
  subject: i.sid,
674
667
  dna: o,
675
668
  redirect: r
676
- }, "sso"), a = await h(g(w.SIGN.VERIFY), { dsign: s, dna: o, redirect: r });
669
+ }, "sso"), a = await h(w(g.SIGN.VERIFY), { dsign: s, dna: o, redirect: r });
677
670
  if (a.code !== u.OK || !a.data)
678
671
  return !1;
679
- const c = await h(g(w.SIGN.TOKEN), {
680
- dsign: await K(N.TOKEN, {
681
- origin: A(),
672
+ const c = await h(w(g.SIGN.TOKEN), {
673
+ dsign: await x(N.TOKEN, {
674
+ origin: K(),
682
675
  ts: Date.now(),
683
676
  subject: a.data.code,
684
677
  dna: o
685
678
  }, "domain"),
686
- pk: await ee(n)
679
+ pk: await tt(n)
687
680
  });
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);
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() + ut, W(), !0);
689
682
  }
690
- async function wt(e) {
691
- return !e && i.access ? !0 : gt();
683
+ async function le(t) {
684
+ return !t && i.access ? !0 : de();
692
685
  }
693
- function de() {
694
- return C || (C = (b() ? ht() : pt()).then((e) => (C = null, e), (e) => {
695
- throw C = null, e;
696
- })), C;
686
+ function dt() {
687
+ return _ || (_ = (S() ? we() : ge()).then((t) => (_ = null, t), (t) => {
688
+ throw _ = null, t;
689
+ })), _;
697
690
  }
698
- async function ht() {
699
- const e = await h(g(w.COOKIE.REFRESH));
700
- if (e.code === u.OK)
691
+ async function we() {
692
+ const t = await h(w(g.COOKIE.REFRESH));
693
+ if (t.code === u.OK)
701
694
  return !0;
702
- if (e.code === u.AUTH_EXPIRED)
703
- throw new O(e.message);
704
- if (e.code === "500" && /重复/.test(e.message || ""))
695
+ if (t.code === u.AUTH_EXPIRED)
696
+ throw new O(t.message);
697
+ if (t.code === "500" && /重复/.test(t.message || ""))
705
698
  return await U(800), !0;
706
- throw new E(e.code, e.message);
699
+ throw new m(t.code, t.message);
707
700
  }
708
- async function pt() {
709
- const e = i.access, t = i.ds;
710
- if (!e || !t)
701
+ async function ge() {
702
+ const t = i.access, e = i.ds;
703
+ if (!t || !e)
711
704
  throw new O();
712
- const n = await K(N.BIZ, {
705
+ const n = await x(N.BIZ, {
713
706
  method: "POST",
714
- path: B(w.SIGN.REFRESH),
715
- origin: A(),
716
- ds: t,
707
+ path: V(g.SIGN.REFRESH),
708
+ origin: K(),
709
+ ds: e,
717
710
  ts: Date.now(),
718
- subject: e
719
- }, "domain"), o = await h(g(w.SIGN.REFRESH, "dsign=" + encodeURIComponent(n)));
711
+ subject: t
712
+ }, "domain"), o = await h(w(g.SIGN.REFRESH, "dsign=" + encodeURIComponent(n)));
720
713
  if (o.code === u.OK && o.data)
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);
714
+ return i.access = o.data.token, o.data.ds && (i.ds = o.data.ds), i.exp = Date.now() + ut, i.access;
715
+ const r = await he(t, 1200);
723
716
  if (r)
724
717
  return r;
725
- throw o.code === u.AUTH_EXPIRED ? new O(o.message) : new E(o.code, o.message);
718
+ throw o.code === u.AUTH_EXPIRED ? new O(o.message) : new m(o.code, o.message);
726
719
  }
727
- function mt(e, t) {
728
- const n = Date.now() + t;
720
+ function he(t, e) {
721
+ const n = Date.now() + e;
729
722
  return new Promise((o) => {
730
723
  const r = () => {
731
724
  const s = i.access;
732
- if (s && s !== e) {
725
+ if (s && s !== t) {
733
726
  o(s);
734
727
  return;
735
728
  }
@@ -742,36 +735,28 @@ function mt(e, t) {
742
735
  r();
743
736
  });
744
737
  }
745
- async function Et() {
738
+ async function pe() {
746
739
  try {
747
- let t = await we();
748
- t.code === u.AUTH_EXPIRED && (await de(), t = await we());
749
- } catch (t) {
740
+ let e = await gt();
741
+ e.code === u.AUTH_EXPIRED && (await dt(), e = await gt());
742
+ } catch (e) {
750
743
  }
751
- Pe();
752
- const e = I();
753
- typeof e.onLogout == "function" && e.onLogout("logout");
744
+ Pt();
745
+ const t = I();
746
+ typeof t.onLogout == "function" && t.onLogout("logout");
754
747
  }
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(), j(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()) {
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);
757
+ }
758
+ async function Dt() {
759
+ if (S()) {
775
760
  if (i.cookie || await M())
776
761
  return;
777
762
  throw R("expired"), new O();
@@ -779,118 +764,106 @@ async function De() {
779
764
  if (!i.access && !await M())
780
765
  throw R("expired"), new O();
781
766
  }
782
- async function j(e, t, n, o) {
783
- const r = n.auth !== !1 && n.noToken !== !0, s = r && !b();
767
+ async function G(t, e, n, o) {
768
+ const r = n.auth !== !1, s = r && !S();
784
769
  let a = "", c = null;
785
770
  if (s) {
786
771
  c = i.access;
787
772
  try {
788
- a = await ae(e, c, i.ds);
773
+ a = await at(t, c, i.ds);
789
774
  } catch (d) {
790
775
  if (!o && await M({ force: !0 }))
791
- return j(e, t, n, !0);
776
+ return G(t, e, n, !0);
792
777
  throw R("expired"), new O();
793
778
  }
794
779
  }
795
- const f = await h(g(e, a), t, n.timeout);
780
+ const f = await h(w(t, a), e, n.timeout);
796
781
  if (f.code === u.OK)
797
- return f;
782
+ return f.data;
798
783
  if (r && f.code === u.AUTH_EXPIRED && !o) {
799
784
  if (s && c && i.access !== c)
800
- return j(e, t, n, !0);
785
+ return G(t, e, n, !0);
801
786
  try {
802
- await de();
787
+ await dt();
803
788
  } catch (d) {
804
789
  throw d instanceof O && R("expired"), d;
805
790
  }
806
- return j(e, t, n, !0);
791
+ return G(t, e, n, !0);
807
792
  }
808
- throw r && f.code === u.AUTH_EXPIRED ? (R("expired"), new O(f.message)) : Ne(f);
793
+ throw r && f.code === u.AUTH_EXPIRED ? (R("expired"), new O(f.message)) : Nt(f);
809
794
  }
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;
795
+ function Nt(t) {
796
+ const e = new m(t.code, t.message), n = I();
797
+ return n.onError && n.onError({ code: t.code, message: t.message, error: e }), e;
813
798
  }
814
- async function St(e, t, n, o) {
815
- return (b() ? !i.cookie : !i.access) && await De(), oe(e, t, n, o || {}, !1);
799
+ async function Oe(t, e, n, o) {
800
+ return (S() ? !i.cookie : !i.access) && await Dt(), ot(t, e, n, o || {}, !1);
816
801
  }
817
- async function oe(e, t, n, o, r) {
802
+ async function ot(t, e, n, o, r) {
818
803
  let s = "";
819
- if (!b())
804
+ if (!S())
820
805
  try {
821
- s = await ae(e, i.access, i.ds);
806
+ s = await at(t, i.access, i.ds);
822
807
  } catch (f) {
823
808
  if (!r && await M({ force: !0 }))
824
- return oe(e, t, n, o, !0);
809
+ return ot(t, e, n, o, !0);
825
810
  throw R("expired"), new O();
826
811
  }
827
812
  const a = new FormData();
828
813
  Object.keys(n || {}).forEach((f) => {
829
814
  const d = n[f];
830
815
  d != null && a.append(f, d);
831
- }), a.append("file", t);
832
- const c = await h(g(e, s), a, o.timeout);
816
+ }), a.append("file", e);
817
+ const c = await h(w(t, s), a, o.timeout);
833
818
  if (c.code === u.OK)
834
- return c;
819
+ return c.data;
835
820
  if (c.code === u.AUTH_EXPIRED && !r) {
836
821
  try {
837
- await de();
822
+ await dt();
838
823
  } catch (f) {
839
824
  throw f instanceof O && R("expired"), f;
840
825
  }
841
- return oe(e, t, n, o, !0);
826
+ return ot(t, e, n, o, !0);
842
827
  }
843
- throw Ne(c);
828
+ throw Nt(c);
844
829
  }
845
- function It(e) {
846
- const t = Ke(e);
847
- if (Me(), t.nativeGuard !== "off") {
848
- const n = ke();
830
+ function ye(t) {
831
+ const e = xt(t);
832
+ if (Ut(), e.nativeGuard !== "off") {
833
+ const n = Ct();
849
834
  if (n.length) {
850
835
  const o = "[dplugin/core] 这些原生能力在模块加载前已被替换:" + n.join(", ") + "(签名/请求可能被中间人截获,检查是否有脚本抢跑)";
851
- if (t.nativeGuard === "error")
836
+ if (e.nativeGuard === "error")
852
837
  throw new Error(o);
853
838
  typeof console != "undefined" && console.warn(o);
854
839
  }
855
840
  }
856
841
  }
857
- const Tt = {
858
- login: it,
859
- logout: Et,
860
- isLogin: fe,
861
- getState: z,
842
+ const Se = {
843
+ login: oe,
844
+ logout: pe,
845
+ isLogin: ft,
846
+ getState: Z,
862
847
  /** 页面加载时恢复登录态;返回是否已登录 */
863
- restore: M,
864
- // ---------------- 兼容旧应用,不要在新代码里用 ----------------
865
- /** 老代码在登录回调里调它落库;现在 login() 已经处理,这里空实现 */
866
- setAuthData() {
867
- },
868
- /** 老协议跨域交接,后端接口已下线 */
869
- jump() {
870
- return Promise.reject(new Error("[dplugin/core] jump 已下线,请改为同源部署"));
871
- },
872
- /** 同上 */
873
- jumpGenerate() {
874
- return Promise.reject(new Error("[dplugin/core] jumpGenerate 已下线"));
875
- }
848
+ restore: M
876
849
  };
877
850
  export {
878
851
  O as AuthError,
879
- E as BizError,
852
+ m as BizError,
880
853
  u as CODE,
881
- Tt as auth,
882
- Pe as clear,
854
+ Se as auth,
855
+ Pt as clear,
883
856
  R as expire,
884
- pe as getMode,
885
- z as getState,
886
- yt as isAuthError,
887
- fe as isLogin,
888
- it as login,
889
- Et as logout,
890
- bt as request,
891
- It as setup,
857
+ pt as getMode,
858
+ Z as getState,
859
+ Ee as isAuthError,
860
+ ft as isLogin,
861
+ oe as login,
862
+ pe as logout,
863
+ me as request,
864
+ ye as setup,
892
865
  i as store,
893
- St as upload,
866
+ Oe as upload,
894
867
  M as verifyLogin
895
868
  };
896
869
  //# sourceMappingURL=index.mjs.map