@arcblock/did-connect-react 3.1.33 → 3.1.35
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/lib/Session/hooks/use-session-token.js +115 -109
- package/lib/Session/index.js +300 -294
- package/lib/constant.js +13 -12
- package/lib/index.js +74 -73
- package/lib/package.json.js +1 -1
- package/package.json +5 -5
- package/src/Session/hooks/use-session-token.js +6 -1
- package/src/Session/index.jsx +8 -0
- package/src/constant.js +1 -0
package/lib/Session/index.js
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
import { jsx as g, jsxs as j, Fragment as Mo } from "react/jsx-runtime";
|
|
2
2
|
import S from "prop-types";
|
|
3
3
|
import zo from "lodash/omit";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import Vo from "lodash/pick";
|
|
5
|
+
import Te from "lodash/cloneDeep";
|
|
6
6
|
import J from "lodash/isFunction";
|
|
7
7
|
import w from "lodash/isUndefined";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { useTheme as
|
|
13
|
-
import { getVisitorId as $, isUrl as
|
|
14
|
-
import ae, { ToastProvider as
|
|
15
|
-
import
|
|
16
|
-
import { useReactive as
|
|
8
|
+
import jo from "lodash/defaultsDeep";
|
|
9
|
+
import Ko from "js-cookie";
|
|
10
|
+
import $o from "eventemitter3";
|
|
11
|
+
import qo from "p-wait-for";
|
|
12
|
+
import { useTheme as Xo, Typography as Qo, Box as K, CircularProgress as Yo } from "@mui/material";
|
|
13
|
+
import { getVisitorId as $, isUrl as Jo, ensureVisitorId as Zo, setVisitorId as ke } from "@arcblock/ux/lib/Util";
|
|
14
|
+
import ae, { ToastProvider as ye } from "@arcblock/ux/lib/Toast";
|
|
15
|
+
import ei from "@arcblock/ux/lib/Center";
|
|
16
|
+
import { useReactive as Ie, useCreation as Le, useMemoizedFn as f, usePrevious as oi, useLatest as De, useUpdateEffect as le, useMount as ii } from "ahooks";
|
|
17
17
|
import { joinURL as H } from "ufo";
|
|
18
|
-
import { Icon as
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import { getCurrentAppPid as
|
|
25
|
-
import { translate as
|
|
26
|
-
import { getBlockletSDK as
|
|
18
|
+
import { Icon as ti } from "@iconify/react";
|
|
19
|
+
import ri from "@iconify-icons/material-symbols/keyboard-double-arrow-right-rounded";
|
|
20
|
+
import ni from "@arcblock/react-hooks/lib/useBrowser";
|
|
21
|
+
import si from "@arcblock/ux/lib/Dialog/use-confirm";
|
|
22
|
+
import _e from "@arcblock/ux/lib/DID";
|
|
23
|
+
import Ee from "@arcblock/ux/lib/Avatar";
|
|
24
|
+
import { getCurrentAppPid as ci } from "@arcblock/ux/lib/SessionUser/libs/utils";
|
|
25
|
+
import { translate as ai } from "@arcblock/ux/lib/Locale/util";
|
|
26
|
+
import { getBlockletSDK as li, BlockletSDK as di } from "@blocklet/js-sdk";
|
|
27
27
|
import P from "@arcblock/bridge";
|
|
28
|
-
import { getFederatedEnabled as
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import { ReactGA as
|
|
32
|
-
import { useState as
|
|
33
|
-
import
|
|
34
|
-
import { formatCacheTtl as
|
|
35
|
-
import
|
|
36
|
-
import { OAuthContext as
|
|
37
|
-
import { PasskeyContext as
|
|
28
|
+
import { getFederatedEnabled as pi } from "@arcblock/ux/lib/Util/federated";
|
|
29
|
+
import fi from "lodash/noop";
|
|
30
|
+
import ui from "lodash/isNil";
|
|
31
|
+
import { ReactGA as wi } from "@arcblock/ux/lib/withTracker";
|
|
32
|
+
import { useState as hi, useEffect as mi } from "react";
|
|
33
|
+
import de from "../Storage/index.js";
|
|
34
|
+
import { formatCacheTtl as gi, getBrowserLang as Si, debug as m, decodeUrlParams as ve, sleep as E, updateConnectedInfo as Z, getAppId as ee, logger as Oe } from "../utils.js";
|
|
35
|
+
import xe from "./window-focus-aware.js";
|
|
36
|
+
import { OAuthContext as Ai, OAuthConsumer as Pi, OAuthProvider as Re, useOAuth as bi } from "../OAuth/context.js";
|
|
37
|
+
import { PasskeyContext as Ci, PasskeyConsumer as Ti, PasskeyProvider as Ne, usePasskey as ki } from "../Passkey/context.js";
|
|
38
38
|
import "../Passkey/actions.js";
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
import
|
|
43
|
-
import
|
|
39
|
+
import yi, { getWalletDid as Ii } from "../User/use-did.js";
|
|
40
|
+
import Li from "../User/wrap-did.js";
|
|
41
|
+
import Di from "./hooks/use-federated.js";
|
|
42
|
+
import _i from "./hooks/use-session-token.js";
|
|
43
|
+
import Ei from "./hooks/use-protected-routes.js";
|
|
44
44
|
import { SessionContext as qe } from "./context.js";
|
|
45
|
-
import
|
|
46
|
-
import { EVENTS as
|
|
45
|
+
import vi from "../Connect/use-connect.js";
|
|
46
|
+
import { EVENTS as a } from "./libs/constants.js";
|
|
47
47
|
import { translations as F } from "./libs/locales.js";
|
|
48
|
-
import { NotOpenError as
|
|
49
|
-
import { SESSION_TOKEN_STORAGE_KEY as Xe, REFRESH_TOKEN_STORAGE_KEY as Qe,
|
|
50
|
-
import { getMobileVisitorId as
|
|
51
|
-
import
|
|
48
|
+
import { NotOpenError as Oi } from "../error.js";
|
|
49
|
+
import { SESSION_TOKEN_STORAGE_KEY as Xe, REFRESH_TOKEN_STORAGE_KEY as Qe, CSRF_TOKEN_STORAGE_KEY as xi, API_DID_PREFIX as Ri, DEFAULT_TIMEOUT as Ni, BLOCKLET_SERVICE_PATH_PREFIX as G, DID_SPACES_BASE_URL as Wi } from "../constant.js";
|
|
50
|
+
import { getMobileVisitorId as Fi, checkEnableAutoLogin as Bi, login as Ui } from "./libs/login-mobile.js";
|
|
51
|
+
import Hi from "../Connect/hooks/use-quick-connect.js";
|
|
52
52
|
import { didSpacesIsRequired as We } from "./libs/did-spaces.js";
|
|
53
|
-
import
|
|
54
|
-
import { FederatedProvider as
|
|
55
|
-
import
|
|
56
|
-
import { gaLoginSuccessHandler as Fe, gaLoginFailedHandler as Be, gaSwitchPassportSuccessHandler as Ue, gaSwitchPassportFailedHandler as He, gaBindWalletSuccessHandler as
|
|
57
|
-
import { loginFederatedMaster as
|
|
58
|
-
const
|
|
53
|
+
import Gi from "./did-spaces-guide.js";
|
|
54
|
+
import { FederatedProvider as Mi, useFederatedContext as zi } from "../Federated/context.js";
|
|
55
|
+
import Vi from "./hooks/use-verify.js";
|
|
56
|
+
import { gaLoginSuccessHandler as Fe, gaLoginFailedHandler as Be, gaSwitchPassportSuccessHandler as Ue, gaSwitchPassportFailedHandler as He, gaBindWalletSuccessHandler as Ge, gaBindWalletFailedHandler as Me } from "./handler.js";
|
|
57
|
+
import { loginFederatedMaster as Yt, mountFederatedIframe as Jt } from "./libs/federated.js";
|
|
58
|
+
const ze = li(), { Provider: ji, Consumer: Ve } = qe, je = {
|
|
59
59
|
en: "DID Connect timeout, please reopen DID Connect popup",
|
|
60
60
|
zh: "DID Connect 超时, 请重新打开 DID Connect"
|
|
61
61
|
}, Ke = {
|
|
@@ -67,13 +67,13 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
67
67
|
globalThis?.blocklet?.prefix && (D = globalThis.blocklet.prefix), typeof T == "boolean" && (T = {
|
|
68
68
|
appendAuthServicePrefix: T,
|
|
69
69
|
extraParams: {}
|
|
70
|
-
}),
|
|
70
|
+
}), jo(T, {
|
|
71
71
|
rolling: !0,
|
|
72
72
|
appendAuthServicePrefix: !1,
|
|
73
73
|
extraParams: {},
|
|
74
74
|
refreshTokenStorageKey: Qe
|
|
75
75
|
});
|
|
76
|
-
function
|
|
76
|
+
function O(I) {
|
|
77
77
|
if (globalThis.blocklet)
|
|
78
78
|
if (I?.user) {
|
|
79
79
|
const r = {
|
|
@@ -84,15 +84,18 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
84
84
|
sourceAppPid: I.user.sourceAppPid,
|
|
85
85
|
fullName: I.user.fullName
|
|
86
86
|
};
|
|
87
|
-
|
|
87
|
+
m("bridge callArc: onLogin", r), P.callArc("onLogin", { ...r, user: r });
|
|
88
88
|
} else
|
|
89
|
-
P.callArc("onLogin", { error: "no user", code: 400 }),
|
|
89
|
+
P.callArc("onLogin", { error: "no user", code: 400 }), m("notifyBridge failed", { sessionState: I });
|
|
90
90
|
}
|
|
91
|
-
const Q =
|
|
92
|
-
|
|
91
|
+
const Q = de(q, X, oe), M = de(xi, "cookie", {
|
|
92
|
+
secure: !0,
|
|
93
|
+
sameSite: "strict"
|
|
94
|
+
}), Ye = de(T.refreshTokenStorageKey, "ls");
|
|
95
|
+
function pe({ ...I }) {
|
|
93
96
|
const r = Object.assign({}, I);
|
|
94
|
-
w(r.serviceHost) && (r.serviceHost = D), w(r.locale) && (r.locale = ""), w(r.action) && (r.action = "login"), w(r.prefix) && (r.prefix =
|
|
95
|
-
const { connectApi: k, connectHolder: ie } =
|
|
97
|
+
w(r.serviceHost) && (r.serviceHost = D), w(r.locale) && (r.locale = ""), w(r.action) && (r.action = "login"), w(r.prefix) && (r.prefix = Ri), w(r.appendAuthServicePrefix) && (r.appendAuthServicePrefix = !1), w(r.extraParams) && (r.extraParams = {}), w(r.options) && (r.options = {}), w(r.autoConnect) && (r.autoConnect = !1), w(r.autoDisconnect) && (r.autoDisconnect = !0), w(r.useSocket) && (r.useSocket = !0), w(r.timeout) && (r.timeout = Ni * 1e3), w(r.webWalletUrl) && (r.webWalletUrl = void 0), w(r.protectedRoutes) && (r.protectedRoutes = ["*"]), w(r.apiOptions) && (r.apiOptions = {}), w(r.lazyRefreshToken) && (r.lazyRefreshToken = !1);
|
|
98
|
+
const { connectApi: k, connectHolder: ie } = vi(), [Ze, fe] = hi(0), y = ni(), { requestStorageAccess: eo } = zi(), { palette: oo } = Xo(), B = new URLSearchParams(window.location.search), s = Ie({
|
|
96
99
|
extraParams: {},
|
|
97
100
|
options: {},
|
|
98
101
|
currentLocale: r.locale,
|
|
@@ -102,13 +105,13 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
102
105
|
return typeof r.autoConnect == "boolean" ? r.autoConnect : !!r.autoLogin;
|
|
103
106
|
},
|
|
104
107
|
get prefix() {
|
|
105
|
-
return T.appendAuthServicePrefix || r.appendAuthServicePrefix ? H(
|
|
108
|
+
return T.appendAuthServicePrefix || r.appendAuthServicePrefix ? H(G, r.prefix) : r.prefix;
|
|
106
109
|
},
|
|
107
110
|
get notificationPrefix() {
|
|
108
111
|
const e = "/api/notifications";
|
|
109
|
-
return T.appendAuthServicePrefix || r.appendAuthServicePrefix ? H(
|
|
112
|
+
return T.appendAuthServicePrefix || r.appendAuthServicePrefix ? H(G, e) : e;
|
|
110
113
|
}
|
|
111
|
-
}), t =
|
|
114
|
+
}), t = Ie({
|
|
112
115
|
action: r.action,
|
|
113
116
|
error: "",
|
|
114
117
|
initialized: !1,
|
|
@@ -120,25 +123,25 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
120
123
|
baseUrl: "",
|
|
121
124
|
unReadCount: 0
|
|
122
125
|
// 不可以直接个性 props.autoConnect (readonly)
|
|
123
|
-
}), b =
|
|
126
|
+
}), b = Le(() => r.locale || s.currentLocale || Si(), [r.locale, s.currentLocale]), { confirmApi: io, confirmHolder: to } = si(), x = f(() => {
|
|
124
127
|
if (t.open && !y.arcSphere) {
|
|
125
128
|
const e = Ke[b] || Ke.en;
|
|
126
129
|
throw ae.warning(e), new Error(e);
|
|
127
130
|
}
|
|
128
|
-
}), d =
|
|
129
|
-
|
|
130
|
-
d.off(
|
|
131
|
+
}), d = Le(() => new $o(), []);
|
|
132
|
+
mi(() => (d.on(a.LOGIN, Fe), d.on(a.LOGIN_FAILED, Be), d.on(a.SWITCH_PASSPORT, Ue), d.on(a.SWITCH_PASSPORT_FAILED, He), d.on(a.BIND_WALLET, Ge), d.on(a.BIND_WALLET_FAILED, Me), () => {
|
|
133
|
+
d.off(a.LOGIN, Fe), d.off(a.LOGIN_FAILED, Be), d.off(a.SWITCH_PASSPORT, Ue), d.off(a.SWITCH_PASSPORT_FAILED, He), d.off(a.BIND_WALLET, Ge), d.off(a.BIND_WALLET_FAILED, Me);
|
|
131
134
|
}), [d]);
|
|
132
135
|
const U = f((e, o, i) => {
|
|
133
136
|
const n = {
|
|
134
|
-
login: [
|
|
135
|
-
"bind-wallet": [
|
|
136
|
-
"switch-passport": [
|
|
137
|
-
"switch-profile": [
|
|
137
|
+
login: [a.LOGIN, a.CANCEL_LOGIN],
|
|
138
|
+
"bind-wallet": [a.BIND_WALLET, a.CANCEL_BIND_WALLET],
|
|
139
|
+
"switch-passport": [a.SWITCH_PASSPORT, a.CANCEL_SWITCH_PASSPORT],
|
|
140
|
+
"switch-profile": [a.SWITCH_PROFILE, a.CANCEL_SWITCH_PROFILE],
|
|
138
141
|
// HACK: 对于内部来说,switch-did 就是 login,所以内部的监听事件仍然是 login
|
|
139
|
-
"switch-did": [
|
|
142
|
+
"switch-did": [a.LOGIN, a.CANCEL_LOGIN],
|
|
140
143
|
// @FIXME: @zhanghan 整个事件发射的机制需要重构,目前的实现不是很优雅,对于用户来说不是很好用。 https://github.com/ArcBlock/ux/pull/1414#discussion_r1904830954
|
|
141
|
-
"did-space-connected": [
|
|
144
|
+
"did-space-connected": [a.DID_SPACE_CONNECTED]
|
|
142
145
|
};
|
|
143
146
|
if (!Object.keys(n).includes(e))
|
|
144
147
|
return;
|
|
@@ -148,29 +151,30 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
148
151
|
d.once(n[e][0], l), d.once(n[e][1], async (...u) => {
|
|
149
152
|
J(l) && d.off(n[e][0], l), J(i) && await i(...u), d.emit(`cancel-${e}`, ...u);
|
|
150
153
|
});
|
|
151
|
-
}),
|
|
152
|
-
syncSessionSate:
|
|
154
|
+
}), ro = oi(t.initialized, (e, o) => e !== o || e === !0 && o === !0), {
|
|
155
|
+
syncSessionSate: no,
|
|
153
156
|
handleRefreshUser: C,
|
|
154
|
-
handleRefreshToken:
|
|
155
|
-
renewToken:
|
|
156
|
-
clearSession:
|
|
157
|
+
handleRefreshToken: so,
|
|
158
|
+
renewToken: co,
|
|
159
|
+
clearSession: ue,
|
|
157
160
|
handleLoginResult: v,
|
|
158
161
|
decrypt: _,
|
|
159
|
-
service:
|
|
160
|
-
getSessionToken:
|
|
161
|
-
getRefreshToken:
|
|
162
|
-
setRefreshToken:
|
|
163
|
-
setSessionToken:
|
|
164
|
-
} =
|
|
162
|
+
service: ao,
|
|
163
|
+
getSessionToken: lo,
|
|
164
|
+
getRefreshToken: po,
|
|
165
|
+
setRefreshToken: fo,
|
|
166
|
+
setSessionToken: uo
|
|
167
|
+
} = _i({
|
|
165
168
|
state: t,
|
|
166
169
|
pageState: s,
|
|
167
170
|
sessionTokenStorage: Q,
|
|
168
|
-
refreshTokenStorage:
|
|
171
|
+
refreshTokenStorage: Ye,
|
|
172
|
+
csrfTokenStorage: M,
|
|
169
173
|
serviceHost: r.serviceHost,
|
|
170
174
|
apiOptions: r.apiOptions,
|
|
171
175
|
lazyRefreshToken: r.lazyRefreshToken,
|
|
172
176
|
onRefresh({ type: e, sessionToken: o, refreshToken: i, user: n }) {
|
|
173
|
-
if (
|
|
177
|
+
if (m("onRefresh", { type: e, user: n }), globalThis.blocklet) {
|
|
174
178
|
const l = {
|
|
175
179
|
did: n.did,
|
|
176
180
|
host: window.location.host,
|
|
@@ -179,28 +183,28 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
179
183
|
sourceAppPid: n.sourceAppPid,
|
|
180
184
|
fullName: n.fullName
|
|
181
185
|
};
|
|
182
|
-
e === "refreshToken" ? (
|
|
186
|
+
e === "refreshToken" ? (m("bridge callArc: onRefreshToken"), P.callArc("onRefreshToken", {
|
|
183
187
|
sessionToken: o,
|
|
184
188
|
refreshToken: i,
|
|
185
189
|
user: l
|
|
186
|
-
})) : e === "refreshUser" && (
|
|
190
|
+
})) : e === "refreshUser" && (m("bridge callArc: onRefreshUser"), P.callArc("onRefreshUser", {
|
|
187
191
|
sessionToken: o,
|
|
188
192
|
refreshToken: i,
|
|
189
193
|
user: l
|
|
190
194
|
}));
|
|
191
195
|
}
|
|
192
196
|
}
|
|
193
|
-
}),
|
|
194
|
-
|
|
197
|
+
}), wo = Vi({ state: t, connectApi: k }), we = f((e, o = {}, i = {}) => {
|
|
198
|
+
x();
|
|
195
199
|
const n = e;
|
|
196
200
|
typeof n == "object" && (e = n.onSuccess, o = n.extraParams || {}, i = n.options || {}, i.origin = n.origin || ""), (!t.user || i.origin === "switch-did") && (i.origin === "switch-did" ? U("switch-did", e, n?.onCancel) : U("login", e, n?.onCancel), s.extraParams = o, s.options = i, t.action = "login", W());
|
|
197
|
-
}),
|
|
201
|
+
}), ho = f((e, o = {}) => {
|
|
198
202
|
const i = e;
|
|
199
203
|
return function(...l) {
|
|
200
204
|
const u = this;
|
|
201
205
|
return (async () => {
|
|
202
206
|
try {
|
|
203
|
-
const p = await
|
|
207
|
+
const p = await wo(o);
|
|
204
208
|
if (!p.sessionId)
|
|
205
209
|
throw new Error("Authentication failed");
|
|
206
210
|
return await i.call(u, p, ...l);
|
|
@@ -210,24 +214,24 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
210
214
|
})();
|
|
211
215
|
};
|
|
212
216
|
}), te = f(async (e, o = {}, i = {}) => {
|
|
213
|
-
|
|
217
|
+
x();
|
|
214
218
|
const n = e;
|
|
215
219
|
typeof n == "object" && (e = n.onSuccess, o = n.extraParams || {}, i = n.options || {}), w(o?.inviter) && window.localStorage.getItem("inviter") && (o.inviter = window.localStorage.getItem("inviter"));
|
|
216
220
|
const { params: l } = await ve();
|
|
217
221
|
if (w(o?.forceConnected) && l?.forceConnected && (o.forceConnected = l.forceConnected, w(i.showQuickConnect) && (i.showQuickConnect = !1)), w(o?.sourceAppPid) && !w(l?.sourceAppPid) && (o.sourceAppPid = l.sourceAppPid), o?.openMode === "redirect") {
|
|
218
|
-
const
|
|
219
|
-
L.searchParams.set("redirect",
|
|
222
|
+
const h = o?.redirect || "/", L = new URL(`${G}/login`, window.location.origin);
|
|
223
|
+
L.searchParams.set("redirect", h), o?.forceConnected && L.searchParams.set("forceConnected", o?.forceConnected), w(o?.sourceAppPid) || L.searchParams.set("sourceAppPid", o?.sourceAppPid), w(o?.inviter) || L.searchParams.set("inviter", o?.inviter), i?.origin && L.searchParams.set("origin", i.origin), window.location.href = L.href;
|
|
220
224
|
return;
|
|
221
225
|
}
|
|
222
226
|
let u = o?.sourceAppPid;
|
|
223
|
-
w(u) && xo && (u =
|
|
224
|
-
const p =
|
|
227
|
+
w(u) && xo && (u = Ro.appPid), await qo(() => t.initialized), typeof i == "string" && (i = { origin: i });
|
|
228
|
+
const p = Te(o);
|
|
225
229
|
p.passkeyBehavior = "both", s.allowWallet = void 0;
|
|
226
|
-
const
|
|
227
|
-
w(
|
|
228
|
-
}),
|
|
230
|
+
const c = p?.openMode || r?.extraParams?.openMode;
|
|
231
|
+
w(c) ? u ? u !== globalThis.blocklet.appPid && pi(globalThis.blocklet) && (s.openMode = "window") : s.openMode = "popup" : s.openMode = c, s.openMode === "window" && !y.arcSphere && !y.wallet && await eo() && (s.openMode = "popup"), u ? t.baseUrl = globalThis.blocklet.appUrl : t.baseUrl = "", we(e, p, i);
|
|
232
|
+
}), he = f(async (e) => {
|
|
229
233
|
const o = $();
|
|
230
|
-
if (globalThis.blocklet && (
|
|
234
|
+
if (globalThis.blocklet && (ze.user.logout({ visitorId: o }).catch((i) => {
|
|
231
235
|
console.warn("Failed to logout remote", i);
|
|
232
236
|
}), await E(100)), globalThis.blocklet) {
|
|
233
237
|
const i = {
|
|
@@ -235,18 +239,18 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
235
239
|
appPid: globalThis.blocklet.appPid,
|
|
236
240
|
userDid: t.user.did
|
|
237
241
|
};
|
|
238
|
-
|
|
242
|
+
m("bridge callArc: onLogout", i), P.callArc("onLogout", i);
|
|
239
243
|
}
|
|
240
|
-
|
|
244
|
+
ue(), V(), t.user = null, t.provider = "", t.walletOS = "", t.error = "", t.loading = !1, d.emit("logout"), wi.set({
|
|
241
245
|
user_id: void 0
|
|
242
246
|
}), typeof e == "function" && e();
|
|
243
247
|
}), {
|
|
244
|
-
userSessions:
|
|
245
|
-
refresh:
|
|
246
|
-
loaded:
|
|
248
|
+
userSessions: mo,
|
|
249
|
+
refresh: go,
|
|
250
|
+
loaded: So,
|
|
247
251
|
loginUserSession: re
|
|
248
|
-
} =
|
|
249
|
-
appPid:
|
|
252
|
+
} = Hi({
|
|
253
|
+
appPid: ci(t.user),
|
|
250
254
|
loginAppPid: globalThis?.blocklet?.appPid,
|
|
251
255
|
sourceAppPid: t?.user?.sourceAppPid,
|
|
252
256
|
autoFetch: !1,
|
|
@@ -258,7 +262,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
258
262
|
});
|
|
259
263
|
});
|
|
260
264
|
}), ne = f((e, o = {}, i = {}) => {
|
|
261
|
-
|
|
265
|
+
x();
|
|
262
266
|
const n = e;
|
|
263
267
|
typeof n == "object" && (e = n.onSuccess, o = n.extraParams || {}, i = n.options || {}), typeof i == "string" && (i = { origin: i }), i?.userSession ? re(i.userSession).then((l) => {
|
|
264
268
|
Z(
|
|
@@ -270,24 +274,24 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
270
274
|
},
|
|
271
275
|
!0
|
|
272
276
|
), U("switch-did", e), v({ ...l, encrypted: !1 }), C({ showProgress: !0 }).then(async () => {
|
|
273
|
-
await E(200), d.emit(
|
|
277
|
+
await E(200), d.emit(a.LOGIN, l, _, A.current), O(A.current), await N();
|
|
274
278
|
}).catch((u) => {
|
|
275
|
-
throw d.emit(
|
|
279
|
+
throw d.emit(a.LOGIN_FAILED, u), u;
|
|
276
280
|
});
|
|
277
281
|
}) : (w(o?.forceConnected) && (o.forceConnected = !1), o.passkeyBehavior = "both", te(e, o, { ...i, origin: "switch-did" }));
|
|
278
|
-
}),
|
|
279
|
-
await
|
|
280
|
-
}),
|
|
281
|
-
await R(),
|
|
282
|
+
}), Ao = f(async () => {
|
|
283
|
+
await ze.user.refreshProfile();
|
|
284
|
+
}), Po = f(async (e, o = {}) => {
|
|
285
|
+
await R(), x();
|
|
282
286
|
const i = e;
|
|
283
287
|
typeof i == "object" && (e = i.onSuccess, o = i.extraParams || {}), U("switch-profile", e, i?.onCancel), s.extraParams = o, s.options = {}, t.action = "switch-profile", W();
|
|
284
|
-
}),
|
|
285
|
-
await R(),
|
|
288
|
+
}), bo = f(async (e, o = {}) => {
|
|
289
|
+
await R(), x();
|
|
286
290
|
const i = e;
|
|
287
291
|
typeof i == "object" && (e = i.onSuccess, o = i.extraParams || {}), U("switch-passport", e, i?.onCancel), s.extraParams = o, s.options = {}, t.action = "switch-passport", W();
|
|
288
|
-
}),
|
|
292
|
+
}), Co = f(async ({ extraParams: e = {}, onSuccess: o = () => {
|
|
289
293
|
}, ...i } = {}) => {
|
|
290
|
-
await R(),
|
|
294
|
+
await R(), x(), s.extraParams = {
|
|
291
295
|
referrer: window.location.href,
|
|
292
296
|
purpose: "authorize-for-import",
|
|
293
297
|
...e,
|
|
@@ -298,8 +302,8 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
298
302
|
onSuccess: o,
|
|
299
303
|
...i
|
|
300
304
|
});
|
|
301
|
-
}),
|
|
302
|
-
await R(),
|
|
305
|
+
}), me = f(async ({ extraParams: e = {}, onSuccess: o = {} } = {}) => {
|
|
306
|
+
await R(), Co({
|
|
303
307
|
extraParams: {
|
|
304
308
|
// service 交互
|
|
305
309
|
purpose: "authorize-for-import",
|
|
@@ -308,11 +312,11 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
308
312
|
onSuccess: o,
|
|
309
313
|
hideCloseButton: !1
|
|
310
314
|
});
|
|
311
|
-
}), { didSpacesGuideApi: Y, DidSpacesGuideView:
|
|
315
|
+
}), { didSpacesGuideApi: Y, DidSpacesGuideView: To } = Gi({
|
|
312
316
|
autoClose: !1
|
|
313
317
|
}), N = async ({ extraParams: e = {}, onSuccess: o = () => {
|
|
314
318
|
} } = {}) => {
|
|
315
|
-
await R(), await We(t?.user) && (Y.open(), Y.onConnect((i =
|
|
319
|
+
await R(), await We(t?.user) && (Y.open(), Y.onConnect((i = fi) => {
|
|
316
320
|
const n = {
|
|
317
321
|
prefix: "/connect-to-did-space",
|
|
318
322
|
custom: !0,
|
|
@@ -329,7 +333,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
329
333
|
},
|
|
330
334
|
onSuccess: async (l, u) => {
|
|
331
335
|
const p = u ? u(l.spaceGateway) : l.spaceGateway;
|
|
332
|
-
await new
|
|
336
|
+
await new di().user.updateDidSpace({ spaceGateway: p }), await C({ showProgress: !0 }), await o(l, u), await Y.close(), d.emit(a.DID_SPACE_CONNECTED, l, u), globalThis.blocklet && (m("bridge callArc: onDidSpaceConnected"), P.callArc("onDidSpaceConnected")), i(!0);
|
|
333
337
|
},
|
|
334
338
|
onError: (l) => {
|
|
335
339
|
console.error(l), ae.error(l.message), Y.close(), i(!1);
|
|
@@ -339,78 +343,78 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
339
343
|
}
|
|
340
344
|
};
|
|
341
345
|
k.openPopup(n, {
|
|
342
|
-
baseUrl:
|
|
346
|
+
baseUrl: Wi
|
|
343
347
|
});
|
|
344
348
|
}));
|
|
345
|
-
},
|
|
346
|
-
if (await R(),
|
|
349
|
+
}, ge = f(async (e, o = {}) => {
|
|
350
|
+
if (await R(), Ii(t.user)) {
|
|
347
351
|
e({}, _, A.current);
|
|
348
352
|
return;
|
|
349
353
|
}
|
|
350
|
-
|
|
354
|
+
x();
|
|
351
355
|
const i = e;
|
|
352
356
|
typeof i == "object" && (e = i.onSuccess), U("bind-wallet", e, i?.onCancel), s.extraParams = o, s.options = {}, t.action = "bind-wallet", W();
|
|
353
357
|
}), se = f(async (e) => {
|
|
354
|
-
|
|
355
|
-
}),
|
|
356
|
-
d.emit(
|
|
357
|
-
}),
|
|
358
|
+
m("onSwitchPassport", { result: e }), s.extraParams = {}, s.options = {}, v(e), t.loading = !1, await C({ showProgress: !0 }), await E(200), d.emit(a.SWITCH_PASSPORT, e, _, A.current), globalThis.blocklet && (m("bridge callArc: onSwitchPassport"), P.callArc("onSwitchPassport"));
|
|
359
|
+
}), ko = f((e) => {
|
|
360
|
+
d.emit(a.SWITCH_PASSPORT_FAILED, e);
|
|
361
|
+
}), z = f(async (e) => {
|
|
358
362
|
if (t.action === "switch-passport") {
|
|
359
363
|
se(e);
|
|
360
364
|
return;
|
|
361
365
|
}
|
|
362
|
-
|
|
363
|
-
}), ko = f((e) => {
|
|
364
|
-
d.emit(c.LOGIN_FAILED, e);
|
|
366
|
+
m("onLogin", { result: e }), s.extraParams = {}, s.options = {}, v(e), t.loading = !1, await C({ showProgress: !0 }), await E(200), t.action === "login" && (m("onLogin: emit LOGIN event", { result: e }), d.emit(a.LOGIN, e, _, A.current), O(A.current), N());
|
|
365
367
|
}), yo = f((e) => {
|
|
368
|
+
d.emit(a.LOGIN_FAILED, e);
|
|
369
|
+
}), Io = f((e) => {
|
|
366
370
|
s.extraParams = {}, s.options = {}, v(e), t.loading = !1, C({ showProgress: !0 }).then(async () => {
|
|
367
|
-
await E(100), d.emit(
|
|
371
|
+
await E(100), d.emit(a.BIND_WALLET, e, _, A.current), globalThis.blocklet && (m("bridge callArc: onBindWallet"), P.callArc("onBindWallet"));
|
|
368
372
|
});
|
|
369
|
-
}), Io = f((e) => {
|
|
370
|
-
d.emit(c.BIND_WALLET_FAILED, e, A);
|
|
371
373
|
}), Lo = f((e) => {
|
|
372
|
-
|
|
373
|
-
await E(100), d.emit(c.SWITCH_PROFILE, e, _, A.current), globalThis.blocklet && (h("bridge callArc: onSwitchProfile"), P.callArc("onSwitchProfile"));
|
|
374
|
-
});
|
|
374
|
+
d.emit(a.BIND_WALLET_FAILED, e, A);
|
|
375
375
|
}), Do = f((e) => {
|
|
376
|
+
m("onSwitchProfile", { result: e }), s.extraParams = {}, s.options = {}, t.loading = !1, C({ showProgress: !0 }).then(async () => {
|
|
377
|
+
await E(100), d.emit(a.SWITCH_PROFILE, e, _, A.current), globalThis.blocklet && (m("bridge callArc: onSwitchProfile"), P.callArc("onSwitchProfile"));
|
|
378
|
+
});
|
|
379
|
+
}), _o = f((e) => {
|
|
376
380
|
s.extraParams = {}, s.options = {}, V();
|
|
377
381
|
const o = {
|
|
378
|
-
login:
|
|
379
|
-
"switch-profile":
|
|
380
|
-
"switch-passport":
|
|
381
|
-
"bind-wallet":
|
|
382
|
+
login: a.CANCEL_LOGIN,
|
|
383
|
+
"switch-profile": a.CANCEL_SWITCH_PROFILE,
|
|
384
|
+
"switch-passport": a.CANCEL_SWITCH_PASSPORT,
|
|
385
|
+
"bind-wallet": a.CANCEL_BIND_WALLET
|
|
382
386
|
}, i = {
|
|
383
387
|
login: "offLogin",
|
|
384
388
|
"switch-profile": "offSwitchProfile",
|
|
385
389
|
"switch-passport": "offSwitchPassport",
|
|
386
390
|
"bind-wallet": "offBindWallet"
|
|
387
391
|
};
|
|
388
|
-
d.emit(o[e]), globalThis.blocklet && (
|
|
389
|
-
}),
|
|
392
|
+
d.emit(o[e]), globalThis.blocklet && (m(`bridge callArc: ${i[e]}`), P.callArc(`${i[e]}`));
|
|
393
|
+
}), Eo = f((e, ...o) => {
|
|
390
394
|
try {
|
|
391
395
|
ce[e](...o);
|
|
392
396
|
} catch (i) {
|
|
393
|
-
|
|
397
|
+
Oe.error("Catch error in onSuccess", {
|
|
394
398
|
action: e,
|
|
395
399
|
args: o,
|
|
396
400
|
err: i
|
|
397
401
|
}), ce[`${e}-failed`]?.(i, ...o);
|
|
398
402
|
}
|
|
399
|
-
}),
|
|
403
|
+
}), vo = f((e, o, ...i) => {
|
|
400
404
|
ce[`${e}-failed`]?.(o, ...i);
|
|
401
405
|
}), {
|
|
402
|
-
federatedMaster:
|
|
406
|
+
federatedMaster: Oo,
|
|
403
407
|
federatedEnabled: xo,
|
|
404
|
-
master:
|
|
405
|
-
} =
|
|
408
|
+
master: Ro
|
|
409
|
+
} = Di({
|
|
406
410
|
locale: b,
|
|
407
411
|
decrypt: _,
|
|
408
|
-
login:
|
|
412
|
+
login: we,
|
|
409
413
|
handleLoginResult: v,
|
|
410
414
|
handleRefreshUser: C,
|
|
411
|
-
setRefreshToken:
|
|
412
|
-
setSessionToken:
|
|
413
|
-
}), { checkMatch:
|
|
415
|
+
setRefreshToken: fo,
|
|
416
|
+
setSessionToken: uo
|
|
417
|
+
}), { checkMatch: No } = Ei({ protectedRoutes: r.protectedRoutes || [] }), Wo = De(mo), Se = f(async () => (So || (await go(), await E(100)), Wo.current)), V = f(() => {
|
|
414
418
|
t.open = !1, k.close();
|
|
415
419
|
}), W = async (e = {}) => {
|
|
416
420
|
let o = t.action;
|
|
@@ -423,7 +427,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
423
427
|
email: t?.user?.email
|
|
424
428
|
};
|
|
425
429
|
if (o === "switch-did" && l?.forceConnected) {
|
|
426
|
-
const p = (
|
|
430
|
+
const p = (c, h = {}) => ai(F["switch-specified-did"], c, b, "en", h);
|
|
427
431
|
n.title = p("title"), n.scan = p("scan", { did: l.forceConnected }), n.confirm = p("confirm"), n.success = p("success");
|
|
428
432
|
}
|
|
429
433
|
delete l?.openMode;
|
|
@@ -456,7 +460,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
456
460
|
"protectedRoutes"
|
|
457
461
|
]),
|
|
458
462
|
// 允许 login/switchProfile/switchDid 的时候传入自定义参数
|
|
459
|
-
...
|
|
463
|
+
...Vo(s.extraParams || {}, [
|
|
460
464
|
"autoConnect",
|
|
461
465
|
"forceConnected",
|
|
462
466
|
"saveConnect",
|
|
@@ -468,13 +472,13 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
468
472
|
prefix: s.prefix,
|
|
469
473
|
allowWallet: w(s.allowWallet) ? t.action !== "login" || ["1", "true", void 0, null].includes(globalThis.blocklet?.DID_CONNECT_ALLOW_WALLET) : s.allowWallet,
|
|
470
474
|
onSuccess: async (...p) => {
|
|
471
|
-
|
|
475
|
+
Eo(t.action, ...p), J(e?.onSuccess) && await e.onSuccess(...p), t.open = !1;
|
|
472
476
|
},
|
|
473
477
|
onClose(...p) {
|
|
474
|
-
|
|
478
|
+
_o(t.action, ...p);
|
|
475
479
|
},
|
|
476
480
|
onError(p) {
|
|
477
|
-
console.error(t.action, p),
|
|
481
|
+
console.error(t.action, p), vo(t.action, p, A.current);
|
|
478
482
|
}
|
|
479
483
|
};
|
|
480
484
|
if (t.open = !0, ["login"].includes(t.action) && s.openMode === "window" && !(y.wallet || y.arcSphere))
|
|
@@ -483,13 +487,13 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
483
487
|
...u,
|
|
484
488
|
baseUrl: window.location.origin
|
|
485
489
|
};
|
|
486
|
-
|
|
490
|
+
Jo(s.prefix) || (p.prefix = H(window.location.origin, r.serviceHost, s.prefix)), p.extraParams?.provider || (p.extraParams.provider = t?.user?.provider || "wallet"), await k.openPopup(p, { locale: b });
|
|
487
491
|
} catch (p) {
|
|
488
|
-
p instanceof
|
|
492
|
+
p instanceof Oi && V(), p.message === "Timeout" ? ae.error(je[b] || je.en) : console.error(p);
|
|
489
493
|
}
|
|
490
494
|
else
|
|
491
495
|
k.open(u);
|
|
492
|
-
},
|
|
496
|
+
}, Ae = f(async () => {
|
|
493
497
|
const { params: e, url: o } = await ve();
|
|
494
498
|
if (e) {
|
|
495
499
|
const { switchBehavior: i, forceConnected: n, sourceAppPid: l, showClose: u } = e;
|
|
@@ -499,10 +503,10 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
499
503
|
redirect: o,
|
|
500
504
|
sourceAppPid: l,
|
|
501
505
|
forceConnected: n
|
|
502
|
-
}) : i === "disabled" ? window.history.replaceState(null, "trim", o) :
|
|
506
|
+
}) : i === "disabled" ? window.history.replaceState(null, "trim", o) : io.open({
|
|
503
507
|
title: F.switchAccountDialog[b].title,
|
|
504
508
|
content: /* @__PURE__ */ j(Mo, { children: [
|
|
505
|
-
/* @__PURE__ */ g(
|
|
509
|
+
/* @__PURE__ */ g(Qo, { variant: "body1", sx: { textAlign: "center", mb: 2 }, children: F.switchAccountDialog[b].description }),
|
|
506
510
|
/* @__PURE__ */ j(K, { sx: { display: "flex", alignItems: "center", color: "grey.A700" }, children: [
|
|
507
511
|
/* @__PURE__ */ j(
|
|
508
512
|
K,
|
|
@@ -515,8 +519,8 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
515
519
|
lineHeight: 1
|
|
516
520
|
},
|
|
517
521
|
children: [
|
|
518
|
-
/* @__PURE__ */ g(
|
|
519
|
-
/* @__PURE__ */ g(
|
|
522
|
+
/* @__PURE__ */ g(Ee, { did: t.user.did, shape: "circle", variant: "circle", size: 80 }),
|
|
523
|
+
/* @__PURE__ */ g(_e, { did: t.user.did, showAvatar: !1, compact: !0, responsive: !1 }),
|
|
520
524
|
F.switchAccountDialog[b].currentAccount
|
|
521
525
|
]
|
|
522
526
|
}
|
|
@@ -524,11 +528,11 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
524
528
|
/* @__PURE__ */ g(K, { sx: { display: "flex", justifyContent: "center", px: 2 }, children: /* @__PURE__ */ g(
|
|
525
529
|
K,
|
|
526
530
|
{
|
|
527
|
-
component:
|
|
528
|
-
icon:
|
|
531
|
+
component: ti,
|
|
532
|
+
icon: ri,
|
|
529
533
|
sx: {
|
|
530
534
|
fontSize: 24,
|
|
531
|
-
color:
|
|
535
|
+
color: oo.grey[400],
|
|
532
536
|
animation: "right 2.5s linear infinite",
|
|
533
537
|
"@keyframes right": {
|
|
534
538
|
"0%": {
|
|
@@ -559,8 +563,8 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
559
563
|
fontWeight: 500
|
|
560
564
|
},
|
|
561
565
|
children: [
|
|
562
|
-
/* @__PURE__ */ g(
|
|
563
|
-
/* @__PURE__ */ g(
|
|
566
|
+
/* @__PURE__ */ g(Ee, { did: n, shape: "circle", variant: "circle", size: 80 }),
|
|
567
|
+
/* @__PURE__ */ g(_e, { did: n, showAvatar: !1, compact: !0, responsive: !1 }),
|
|
564
568
|
F.switchAccountDialog[b].nextAccount
|
|
565
569
|
]
|
|
566
570
|
}
|
|
@@ -571,21 +575,21 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
571
575
|
showCancelButton: !1,
|
|
572
576
|
confirmButtonText: F.switchAccountDialog[b].confirm,
|
|
573
577
|
async onConfirm(p) {
|
|
574
|
-
const
|
|
575
|
-
if (
|
|
576
|
-
re(
|
|
578
|
+
const h = (await Se()).find((L) => L.userDid === n);
|
|
579
|
+
if (h) {
|
|
580
|
+
re(h).then((L) => {
|
|
577
581
|
Z(
|
|
578
582
|
{
|
|
579
|
-
connected_did:
|
|
580
|
-
connected_pk:
|
|
581
|
-
connected_wallet_os:
|
|
583
|
+
connected_did: h.user.did,
|
|
584
|
+
connected_pk: h.user.pk,
|
|
585
|
+
connected_wallet_os: h.extra.walletOS,
|
|
582
586
|
connected_app: ee()
|
|
583
587
|
},
|
|
584
588
|
!0
|
|
585
589
|
), v({ ...L, encrypted: !1 }), C({ showProgress: !0 }).then(async () => {
|
|
586
|
-
await E(200), d.emit(
|
|
587
|
-
}).catch((
|
|
588
|
-
throw d.emit(
|
|
590
|
+
await E(200), d.emit(a.LOGIN, L, _, A.current), O(A.current), await N();
|
|
591
|
+
}).catch((Ce) => {
|
|
592
|
+
throw d.emit(a.LOGIN_FAILED, Ce), Ce;
|
|
589
593
|
});
|
|
590
594
|
}), p();
|
|
591
595
|
return;
|
|
@@ -600,7 +604,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
600
604
|
}
|
|
601
605
|
});
|
|
602
606
|
}
|
|
603
|
-
}),
|
|
607
|
+
}), Fo = f(async (e, o) => {
|
|
604
608
|
const i = Object.assign(
|
|
605
609
|
{
|
|
606
610
|
login: !0,
|
|
@@ -610,7 +614,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
610
614
|
o?.requirements
|
|
611
615
|
), n = o?.openMode || "popup";
|
|
612
616
|
i.login && await R(), i.bindWallet && await new Promise((l) => {
|
|
613
|
-
|
|
617
|
+
ge(() => {
|
|
614
618
|
l();
|
|
615
619
|
});
|
|
616
620
|
}), i.bindDidSpaces && (await We(t?.user) || await new Promise((l) => {
|
|
@@ -618,7 +622,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
618
622
|
onSuccess() {
|
|
619
623
|
l();
|
|
620
624
|
}
|
|
621
|
-
}) : i.bindDidSpaces === "read" &&
|
|
625
|
+
}) : i.bindDidSpaces === "read" && me({
|
|
622
626
|
onSuccess() {
|
|
623
627
|
l();
|
|
624
628
|
}
|
|
@@ -627,11 +631,11 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
627
631
|
});
|
|
628
632
|
le(() => {
|
|
629
633
|
const e = Number(t.unReadCount || 0);
|
|
630
|
-
|
|
634
|
+
fe(e);
|
|
631
635
|
}, [t.unReadCount]);
|
|
632
|
-
const
|
|
636
|
+
const Bo = f(() => {
|
|
633
637
|
B.get("magicToken") && B.delete("magicToken"), B.toString() && window.history.replaceState({}, "", `${window.location.pathname}?${B.toString()}`);
|
|
634
|
-
}),
|
|
638
|
+
}), Pe = f((e) => new Promise((o, i) => {
|
|
635
639
|
k.open({
|
|
636
640
|
action: "login",
|
|
637
641
|
locale: b,
|
|
@@ -642,44 +646,44 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
642
646
|
},
|
|
643
647
|
magicToken: e,
|
|
644
648
|
onSuccess(...n) {
|
|
645
|
-
|
|
649
|
+
z(...n), Bo(), o();
|
|
646
650
|
},
|
|
647
651
|
onError(n) {
|
|
648
|
-
d.emit(
|
|
652
|
+
d.emit(a.LOGIN_FAILED, n), i(n);
|
|
649
653
|
}
|
|
650
654
|
});
|
|
651
|
-
})),
|
|
655
|
+
})), Uo = {
|
|
652
656
|
...t,
|
|
653
657
|
loading: s.autoConnect && !t.user || t.loading,
|
|
654
|
-
openDidConnect:
|
|
658
|
+
openDidConnect: Fo,
|
|
655
659
|
login: te,
|
|
656
|
-
logout:
|
|
660
|
+
logout: he,
|
|
657
661
|
switchDid: ne,
|
|
658
|
-
autoSwitchDid:
|
|
659
|
-
refreshProfile:
|
|
660
|
-
switchProfile:
|
|
661
|
-
switchPassport:
|
|
662
|
-
connectToDidSpaceForImport:
|
|
662
|
+
autoSwitchDid: Ae,
|
|
663
|
+
refreshProfile: Ao,
|
|
664
|
+
switchProfile: Po,
|
|
665
|
+
switchPassport: bo,
|
|
666
|
+
connectToDidSpaceForImport: me,
|
|
663
667
|
connectToDidSpaceForFullAccess: N,
|
|
664
|
-
bindWallet:
|
|
668
|
+
bindWallet: ge,
|
|
665
669
|
refresh: C,
|
|
666
670
|
updateConnectedInfo: Z,
|
|
667
671
|
// federated relates
|
|
668
|
-
federatedMaster:
|
|
672
|
+
federatedMaster: Oo,
|
|
669
673
|
// oauth relates
|
|
670
|
-
useOAuth:
|
|
674
|
+
useOAuth: bi,
|
|
671
675
|
OAuthProvider: Re,
|
|
672
|
-
OAuthConsumer:
|
|
673
|
-
OAuthContext:
|
|
676
|
+
OAuthConsumer: Pi,
|
|
677
|
+
OAuthContext: Ai,
|
|
674
678
|
// passkey relates
|
|
675
|
-
usePasskey:
|
|
679
|
+
usePasskey: ki,
|
|
676
680
|
PasskeyProvider: Ne,
|
|
677
|
-
PasskeyConsumer:
|
|
678
|
-
PasskeyContext:
|
|
681
|
+
PasskeyConsumer: Ti,
|
|
682
|
+
PasskeyContext: Ci,
|
|
679
683
|
// user related
|
|
680
|
-
useDid:
|
|
681
|
-
WrapDid:
|
|
682
|
-
getUserSessions:
|
|
684
|
+
useDid: yi,
|
|
685
|
+
WrapDid: Li,
|
|
686
|
+
getUserSessions: Se,
|
|
683
687
|
async loginUserSession(e) {
|
|
684
688
|
try {
|
|
685
689
|
const o = await re(e);
|
|
@@ -691,35 +695,35 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
691
695
|
connected_app: ee()
|
|
692
696
|
},
|
|
693
697
|
!0
|
|
694
|
-
), v({ ...o, encrypted: !1 }), await C({ showProgress: !0 }), await E(200), d.emit(
|
|
698
|
+
), v({ ...o, encrypted: !1 }), await C({ showProgress: !0 }), await E(200), d.emit(a.LOGIN, o, _, A.current), O(A.current), await N();
|
|
695
699
|
} catch (o) {
|
|
696
|
-
throw d.emit(
|
|
700
|
+
throw d.emit(a.LOGIN_FAILED, o), o;
|
|
697
701
|
}
|
|
698
702
|
},
|
|
699
|
-
unReadCount:
|
|
700
|
-
setUnReadCount:
|
|
701
|
-
verifyMagicToken:
|
|
703
|
+
unReadCount: Ze,
|
|
704
|
+
setUnReadCount: fe,
|
|
705
|
+
verifyMagicToken: Pe,
|
|
702
706
|
// 二次认证相关方法
|
|
703
|
-
withSecondaryAuth:
|
|
704
|
-
}, A =
|
|
705
|
-
api:
|
|
707
|
+
withSecondaryAuth: ho
|
|
708
|
+
}, A = De(Uo), Ho = {
|
|
709
|
+
api: ao,
|
|
706
710
|
events: d,
|
|
707
711
|
storage: Q,
|
|
708
712
|
connectApi: k,
|
|
709
713
|
session: A.current
|
|
710
714
|
}, ce = {
|
|
711
|
-
login:
|
|
712
|
-
"switch-profile":
|
|
715
|
+
login: z,
|
|
716
|
+
"switch-profile": Do,
|
|
713
717
|
"switch-passport": se,
|
|
714
|
-
"switch-passport-failed":
|
|
715
|
-
"bind-wallet":
|
|
716
|
-
"bind-wallet-failed":
|
|
717
|
-
"login-failed":
|
|
718
|
+
"switch-passport-failed": ko,
|
|
719
|
+
"bind-wallet": Io,
|
|
720
|
+
"bind-wallet-failed": Lo,
|
|
721
|
+
"login-failed": yo
|
|
718
722
|
};
|
|
719
723
|
le(() => {
|
|
720
724
|
if (t.initialized) {
|
|
721
|
-
const e = !
|
|
722
|
-
if (d.emit("change", { user:
|
|
725
|
+
const e = !ro;
|
|
726
|
+
if (d.emit("change", { user: Te(t.user), isFirst: e }), t.user && globalThis.blocklet) {
|
|
723
727
|
const o = {
|
|
724
728
|
did: t.user.did,
|
|
725
729
|
host: window.location.host,
|
|
@@ -728,7 +732,7 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
728
732
|
sourceAppPid: t.user.sourceAppPid,
|
|
729
733
|
fullName: t.user.fullName
|
|
730
734
|
};
|
|
731
|
-
|
|
735
|
+
m("bridge callArc: onChange", {
|
|
732
736
|
isFirst: e,
|
|
733
737
|
user: o
|
|
734
738
|
}), P.callArc("onChange", {
|
|
@@ -739,51 +743,52 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
739
743
|
}
|
|
740
744
|
}
|
|
741
745
|
}, [t.user, t.initialized, d]), le(() => {
|
|
742
|
-
t.initialized && t.user &&
|
|
743
|
-
}, [t.initialized]),
|
|
744
|
-
const e = (
|
|
745
|
-
|
|
746
|
+
t.initialized && t.user && Ae();
|
|
747
|
+
}, [t.initialized]), ii(async () => {
|
|
748
|
+
const e = (c) => {
|
|
749
|
+
ui(c.encrypted) && (c.encrypted = !1), window.temporaryDIDConnectOnSuccess instanceof Function ? (m("bridgeOnLogin: temporaryDIDConnectOnSuccess", { result: c }), window.temporaryDIDConnectOnSuccess(c, (h) => h)) : (m("bridgeOnLogin: onLogin", { result: c }), z(c));
|
|
746
750
|
};
|
|
747
|
-
if (P.registerBlocklet("callLoginOAuth", (
|
|
748
|
-
|
|
749
|
-
...
|
|
751
|
+
if (P.registerBlocklet("callLoginOAuth", (c) => {
|
|
752
|
+
m("bridge registerBlocklet: callLoginOAuth", c), k.loginOAuth({
|
|
753
|
+
...c,
|
|
750
754
|
onLogin: e
|
|
751
755
|
});
|
|
752
|
-
}), P.registerBlocklet("logout",
|
|
753
|
-
|
|
754
|
-
}),
|
|
756
|
+
}), P.registerBlocklet("logout", he), P.registerBlocklet("login", (c) => {
|
|
757
|
+
m("bridge registerBlocklet: login", c), e(c);
|
|
758
|
+
}), Zo(), !$()) {
|
|
755
759
|
if (y.arcSphere) {
|
|
756
|
-
|
|
757
|
-
const
|
|
758
|
-
|
|
760
|
+
m("bridge callArc: getVisitorId");
|
|
761
|
+
const c = await P.callArc("getVisitorId");
|
|
762
|
+
m("bridge callArc: getVisitorId result", { walletVisitorId: c }), ke(c);
|
|
759
763
|
} else if (y.wallet) {
|
|
760
|
-
const
|
|
761
|
-
|
|
764
|
+
const c = await Fi();
|
|
765
|
+
ke(c);
|
|
762
766
|
}
|
|
763
767
|
}
|
|
764
|
-
const i =
|
|
768
|
+
const i = Ko.get("connected_app"), n = ee();
|
|
765
769
|
if (r.autoDisconnect && i && n && i !== n) {
|
|
766
|
-
|
|
770
|
+
ue(), t.initialized = !0, s.autoConnect ? W() : V();
|
|
767
771
|
return;
|
|
768
772
|
}
|
|
769
|
-
const l =
|
|
773
|
+
const l = lo();
|
|
770
774
|
if (window?.self === window?.parent) {
|
|
771
|
-
let
|
|
772
|
-
if (y.mobile.apple.device ?
|
|
775
|
+
let c = "web";
|
|
776
|
+
if (y.mobile.apple.device ? c = "ios" : y.mobile.android.device && (c = "android"), y.wallet && Bi({ version: y.walletVersion, platform: c }) && !l)
|
|
773
777
|
try {
|
|
774
778
|
t.loading = !0;
|
|
775
|
-
const
|
|
776
|
-
if (
|
|
777
|
-
await
|
|
778
|
-
sessionToken:
|
|
779
|
-
refreshToken:
|
|
780
|
-
|
|
779
|
+
const h = await Ui();
|
|
780
|
+
if (h) {
|
|
781
|
+
await z({
|
|
782
|
+
sessionToken: h.sessionToken,
|
|
783
|
+
refreshToken: h.refreshToken,
|
|
784
|
+
csrfToken: h.csrfToken,
|
|
785
|
+
visitorId: h.visitorId,
|
|
781
786
|
encrypted: !1
|
|
782
787
|
}), t.initialized = !0;
|
|
783
788
|
return;
|
|
784
789
|
}
|
|
785
|
-
} catch (
|
|
786
|
-
throw d.emit(
|
|
790
|
+
} catch (h) {
|
|
791
|
+
throw d.emit(a.LOGIN_FAILED, h), h;
|
|
787
792
|
} finally {
|
|
788
793
|
t.loading = !1;
|
|
789
794
|
}
|
|
@@ -791,48 +796,49 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
791
796
|
const u = B.get("magicToken");
|
|
792
797
|
if (u)
|
|
793
798
|
try {
|
|
794
|
-
t.initialized = !0, await
|
|
795
|
-
} catch (
|
|
796
|
-
console.error("verifyMagicToken failed",
|
|
799
|
+
t.initialized = !0, await Pe(u);
|
|
800
|
+
} catch (c) {
|
|
801
|
+
console.error("verifyMagicToken failed", c);
|
|
797
802
|
}
|
|
798
803
|
if (l) {
|
|
799
804
|
await C({ showProgress: !0 }), t.initialized = !0, t.user && await N();
|
|
800
805
|
return;
|
|
801
806
|
}
|
|
802
807
|
if (typeof window < "u") {
|
|
803
|
-
const
|
|
804
|
-
if (
|
|
805
|
-
v({ loginToken:
|
|
808
|
+
const c = new URL(window.location.href), h = c.searchParams.get("loginToken");
|
|
809
|
+
if (h) {
|
|
810
|
+
v({ loginToken: h, encrypted: !1 }), c.searchParams.delete("loginToken"), window.history.replaceState({}, window.title, c.href);
|
|
806
811
|
return;
|
|
807
812
|
}
|
|
808
813
|
}
|
|
809
|
-
if (
|
|
810
|
-
await
|
|
814
|
+
if (po()) {
|
|
815
|
+
await so(!0), t.initialized = !0;
|
|
811
816
|
return;
|
|
812
817
|
}
|
|
813
818
|
if (t.initialized = !0, s.autoConnect ? W() : V(), y.arcSphere && ![
|
|
814
819
|
// 不应该唤起自动登录的路由
|
|
815
|
-
H(
|
|
816
|
-
H(
|
|
817
|
-
H(
|
|
820
|
+
H(G, "login"),
|
|
821
|
+
H(G, "connect"),
|
|
822
|
+
H(G, "lost-passport")
|
|
818
823
|
].includes(window.location.pathname) && !l)
|
|
819
824
|
try {
|
|
820
|
-
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
sessionToken:
|
|
824
|
-
refreshToken:
|
|
825
|
-
|
|
825
|
+
m("bridge callArc: autoLogin");
|
|
826
|
+
const c = await P.callArc("autoLogin");
|
|
827
|
+
m("bridgecallArc: autoLogin result", c), c && await z({
|
|
828
|
+
sessionToken: c.sessionToken,
|
|
829
|
+
refreshToken: c.refreshToken,
|
|
830
|
+
csrfToken: c.csrfToken,
|
|
831
|
+
visitorId: c.visitorId,
|
|
826
832
|
encrypted: !1
|
|
827
833
|
});
|
|
828
|
-
} catch (
|
|
829
|
-
d.emit(
|
|
834
|
+
} catch (c) {
|
|
835
|
+
d.emit(a.LOGIN_FAILED, c), Oe.error("Failed to autoLogin ArcSphere", c);
|
|
830
836
|
}
|
|
831
837
|
});
|
|
832
|
-
const
|
|
833
|
-
if (
|
|
834
|
-
return /* @__PURE__ */ g(
|
|
835
|
-
const
|
|
838
|
+
const Go = B.has("popup");
|
|
839
|
+
if (No() && !t.initialized)
|
|
840
|
+
return /* @__PURE__ */ g(ei, { children: Go ? null : /* @__PURE__ */ g(Yo, {}) });
|
|
841
|
+
const be = {
|
|
836
842
|
locale: b,
|
|
837
843
|
onSwitchPassport: ({ sessionToken: e, refreshToken: o }) => se({ sessionToken: e, refreshToken: o, encrypted: !1 }),
|
|
838
844
|
onUnbindOAuth: () => C(),
|
|
@@ -841,16 +847,16 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
841
847
|
onRemovePasskey: () => C(),
|
|
842
848
|
session: A.current
|
|
843
849
|
};
|
|
844
|
-
return /* @__PURE__ */ g(
|
|
850
|
+
return /* @__PURE__ */ g(ji, { value: Ho, children: /* @__PURE__ */ g(Ne, { ...be, children: /* @__PURE__ */ j(Re, { ...be, children: [
|
|
845
851
|
!t.open && typeof r.children == "function" ? r.children(t) : r.children,
|
|
846
852
|
ie,
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
T.rolling && /* @__PURE__ */ g(
|
|
850
|
-
/* @__PURE__ */ g(
|
|
853
|
+
to,
|
|
854
|
+
To,
|
|
855
|
+
T.rolling && /* @__PURE__ */ g(xe, { callback: () => co() }),
|
|
856
|
+
/* @__PURE__ */ g(xe, { callback: no })
|
|
851
857
|
] }) }) });
|
|
852
858
|
}
|
|
853
|
-
|
|
859
|
+
pe.propTypes = {
|
|
854
860
|
children: S.any.isRequired,
|
|
855
861
|
serviceHost: S.string,
|
|
856
862
|
action: S.string,
|
|
@@ -871,26 +877,26 @@ function $e(q = Xe, X = "ls", oe = {}, T = {}) {
|
|
|
871
877
|
apiOptions: S.object,
|
|
872
878
|
lazyRefreshToken: S.bool
|
|
873
879
|
};
|
|
874
|
-
function
|
|
880
|
+
function Je(I) {
|
|
875
881
|
return function(k) {
|
|
876
|
-
return /* @__PURE__ */ g(
|
|
882
|
+
return /* @__PURE__ */ g(ye, { children: /* @__PURE__ */ g(Ve, { children: (ie) => /* @__PURE__ */ g(I, { ...k, ...ie }) }) });
|
|
877
883
|
};
|
|
878
884
|
}
|
|
879
885
|
return {
|
|
880
|
-
SessionProvider: (I) => /* @__PURE__ */ g(
|
|
886
|
+
SessionProvider: (I) => /* @__PURE__ */ g(ye, { children: /* @__PURE__ */ g(Mi, { children: /* @__PURE__ */ g(pe, { ...I }) }) }),
|
|
881
887
|
SessionConsumer: Ve,
|
|
882
888
|
SessionContext: qe,
|
|
883
|
-
withSession:
|
|
889
|
+
withSession: Je
|
|
884
890
|
};
|
|
885
891
|
}
|
|
886
|
-
function
|
|
892
|
+
function qt({ storageEngine: q = "cookie" } = {}) {
|
|
887
893
|
const X = Xe, oe = Qe;
|
|
888
894
|
let T = null;
|
|
889
895
|
if (typeof window < "u" && (T = (globalThis.blocklet || {}).componentId), q === "cookie") {
|
|
890
|
-
let D = "/",
|
|
896
|
+
let D = "/", O = 1;
|
|
891
897
|
if (typeof window < "u") {
|
|
892
|
-
const Q = window.env || {},
|
|
893
|
-
D = Q.groupPathPrefix ||
|
|
898
|
+
const Q = window.env || {}, M = window.blocklet || {};
|
|
899
|
+
D = Q.groupPathPrefix || M.groupPrefix || M.prefix || "", D = D.replace(/\/+$/, ""), D = D || "/", M.serverVersion && (O = gi(window.blocklet?.settings?.session?.cacheTtl, 1 / 24));
|
|
894
900
|
}
|
|
895
901
|
return $e(
|
|
896
902
|
X,
|
|
@@ -898,7 +904,7 @@ function Kt({ storageEngine: q = "cookie" } = {}) {
|
|
|
898
904
|
{
|
|
899
905
|
path: D,
|
|
900
906
|
returnDomain: !1,
|
|
901
|
-
expireInDays:
|
|
907
|
+
expireInDays: O
|
|
902
908
|
},
|
|
903
909
|
{
|
|
904
910
|
appendAuthServicePrefix: !0,
|
|
@@ -912,16 +918,16 @@ function Kt({ storageEngine: q = "cookie" } = {}) {
|
|
|
912
918
|
throw new Error("storageEngine must be cookie or localStorage");
|
|
913
919
|
}
|
|
914
920
|
export {
|
|
915
|
-
|
|
921
|
+
a as EVENTS,
|
|
916
922
|
qe as SessionContext,
|
|
917
|
-
|
|
918
|
-
|
|
923
|
+
Bi as checkEnableAutoLogin,
|
|
924
|
+
qt as createAuthServiceSessionContext,
|
|
919
925
|
$e as createSessionContext,
|
|
920
926
|
$e as default,
|
|
921
927
|
We as didSpacesIsRequired,
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
928
|
+
Fi as getMobileVisitorId,
|
|
929
|
+
Ui as login,
|
|
930
|
+
Yt as loginFederatedMaster,
|
|
931
|
+
Jt as mountFederatedIframe,
|
|
926
932
|
F as translations
|
|
927
933
|
};
|