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