@arcblock/did-connect-react 3.5.2 → 4.0.0-beta.1

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.
Files changed (171) hide show
  1. package/dist/ConnectContext.d.ts +13 -0
  2. package/dist/ConnectContext.d.ts.map +1 -0
  3. package/dist/ConnectContext.js +14 -0
  4. package/dist/ConnectContext.js.map +1 -0
  5. package/dist/ConnectProvider.d.ts +11 -0
  6. package/dist/ConnectProvider.d.ts.map +1 -0
  7. package/dist/ConnectProvider.js +23 -0
  8. package/dist/ConnectProvider.js.map +1 -0
  9. package/dist/compat/SessionProvider.d.ts +22 -0
  10. package/dist/compat/SessionProvider.d.ts.map +1 -0
  11. package/dist/compat/SessionProvider.js +17 -0
  12. package/dist/compat/SessionProvider.js.map +1 -0
  13. package/dist/compat/index.d.ts +4 -0
  14. package/dist/compat/index.d.ts.map +1 -0
  15. package/dist/compat/index.js +3 -0
  16. package/dist/compat/index.js.map +1 -0
  17. package/dist/compat/useSessionContext.d.ts +14 -0
  18. package/dist/compat/useSessionContext.d.ts.map +1 -0
  19. package/dist/compat/useSessionContext.js +20 -0
  20. package/dist/compat/useSessionContext.js.map +1 -0
  21. package/dist/components/LoginPage.d.ts +15 -0
  22. package/dist/components/LoginPage.d.ts.map +1 -0
  23. package/dist/components/LoginPage.js +33 -0
  24. package/dist/components/LoginPage.js.map +1 -0
  25. package/dist/components/UserAvatar.d.ts +19 -0
  26. package/dist/components/UserAvatar.d.ts.map +1 -0
  27. package/dist/components/UserAvatar.js +45 -0
  28. package/dist/components/UserAvatar.js.map +1 -0
  29. package/dist/hooks/index.d.ts +11 -0
  30. package/dist/hooks/index.d.ts.map +1 -0
  31. package/dist/hooks/index.js +6 -0
  32. package/dist/hooks/index.js.map +1 -0
  33. package/dist/hooks/useConnect.d.ts +15 -0
  34. package/dist/hooks/useConnect.d.ts.map +1 -0
  35. package/dist/hooks/useConnect.js +19 -0
  36. package/dist/hooks/useConnect.js.map +1 -0
  37. package/dist/hooks/useEmail.d.ts +11 -0
  38. package/dist/hooks/useEmail.d.ts.map +1 -0
  39. package/dist/hooks/useEmail.js +47 -0
  40. package/dist/hooks/useEmail.js.map +1 -0
  41. package/dist/hooks/useOAuth.d.ts +12 -0
  42. package/dist/hooks/useOAuth.d.ts.map +1 -0
  43. package/dist/hooks/useOAuth.js +75 -0
  44. package/dist/hooks/useOAuth.js.map +1 -0
  45. package/dist/hooks/usePasskey.d.ts +14 -0
  46. package/dist/hooks/usePasskey.d.ts.map +1 -0
  47. package/dist/hooks/usePasskey.js +35 -0
  48. package/dist/hooks/usePasskey.js.map +1 -0
  49. package/dist/hooks/useSession.d.ts +12 -0
  50. package/dist/hooks/useSession.d.ts.map +1 -0
  51. package/dist/hooks/useSession.js +30 -0
  52. package/dist/hooks/useSession.js.map +1 -0
  53. package/dist/index.d.ts +13 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +11 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/internals/blocklet-config.d.ts +22 -0
  58. package/dist/internals/blocklet-config.d.ts.map +1 -0
  59. package/dist/internals/blocklet-config.js +26 -0
  60. package/dist/internals/blocklet-config.js.map +1 -0
  61. package/dist/internals/local-storage-adapter.d.ts +12 -0
  62. package/dist/internals/local-storage-adapter.d.ts.map +1 -0
  63. package/dist/internals/local-storage-adapter.js +32 -0
  64. package/dist/internals/local-storage-adapter.js.map +1 -0
  65. package/dist/internals/use-sync-state.d.ts +18 -0
  66. package/dist/internals/use-sync-state.d.ts.map +1 -0
  67. package/dist/internals/use-sync-state.js +38 -0
  68. package/dist/internals/use-sync-state.js.map +1 -0
  69. package/package.json +33 -79
  70. package/LICENSE +0 -13
  71. package/README.md +0 -134
  72. package/dist/standalone/did-connect-react.css +0 -1
  73. package/dist/standalone/index.js +0 -136774
  74. package/lib/Address/index.js +0 -4
  75. package/lib/Avatar/index.js +0 -4
  76. package/lib/Button/index.js +0 -17
  77. package/lib/Connect/assets/locale.js +0 -147
  78. package/lib/Connect/assets/login-bg.png +0 -0
  79. package/lib/Connect/assets/login-slogan.js +0 -9
  80. package/lib/Connect/components/action-button.js +0 -26
  81. package/lib/Connect/components/app-tips.js +0 -132
  82. package/lib/Connect/components/auto-height.js +0 -31
  83. package/lib/Connect/components/back-button.js +0 -25
  84. package/lib/Connect/components/connect-status.js +0 -263
  85. package/lib/Connect/components/did-connect-title.js +0 -127
  86. package/lib/Connect/components/download-tips.js +0 -52
  87. package/lib/Connect/components/loading.js +0 -26
  88. package/lib/Connect/components/login-item/connect-choose-list.js +0 -257
  89. package/lib/Connect/components/login-item/connect-provider-list.js +0 -345
  90. package/lib/Connect/components/login-item/login-method-item.js +0 -147
  91. package/lib/Connect/components/login-item/mobile-login-item.js +0 -116
  92. package/lib/Connect/components/login-item/passkey-login-item.js +0 -44
  93. package/lib/Connect/components/login-item/wallet-login-options.js +0 -114
  94. package/lib/Connect/components/login-item/web-login-item.js +0 -104
  95. package/lib/Connect/components/mask-overlay.js +0 -34
  96. package/lib/Connect/components/refresh-overlay.js +0 -57
  97. package/lib/Connect/components/switch-app.js +0 -70
  98. package/lib/Connect/connect.js +0 -505
  99. package/lib/Connect/contexts/state.js +0 -156
  100. package/lib/Connect/fallback-connect.js +0 -53
  101. package/lib/Connect/fullpage.js +0 -5
  102. package/lib/Connect/hooks/auth-url.js +0 -23
  103. package/lib/Connect/hooks/method-list.js +0 -46
  104. package/lib/Connect/hooks/page-show.js +0 -17
  105. package/lib/Connect/hooks/provider-list.js +0 -69
  106. package/lib/Connect/hooks/security.js +0 -27
  107. package/lib/Connect/hooks/token.js +0 -296
  108. package/lib/Connect/hooks/use-apps.js +0 -19
  109. package/lib/Connect/hooks/use-quick-connect.js +0 -86
  110. package/lib/Connect/index.js +0 -16
  111. package/lib/Connect/landing-page.js +0 -5
  112. package/lib/Connect/plugins/email/index.js +0 -65
  113. package/lib/Connect/plugins/email/list-item.js +0 -31
  114. package/lib/Connect/plugins/email/placeholder.js +0 -284
  115. package/lib/Connect/plugins/index.js +0 -4
  116. package/lib/Connect/use-connect.js +0 -164
  117. package/lib/Connect/with-blocklet.js +0 -15
  118. package/lib/Connect/with-bridge-call.js +0 -108
  119. package/lib/Federated/context.js +0 -61
  120. package/lib/Federated/index.js +0 -7
  121. package/lib/Logo/index.js +0 -4
  122. package/lib/OAuth/bind-conflict-alert.js +0 -29
  123. package/lib/OAuth/context.js +0 -277
  124. package/lib/OAuth/guest.svg.js +0 -5
  125. package/lib/OAuth/index.js +0 -7
  126. package/lib/OAuth/passport-switcher.js +0 -5
  127. package/lib/Passkey/actions.js +0 -170
  128. package/lib/Passkey/constants.js +0 -4
  129. package/lib/Passkey/context.js +0 -281
  130. package/lib/Passkey/dialog.js +0 -280
  131. package/lib/Passkey/icon.js +0 -13
  132. package/lib/Passkey/index.js +0 -9
  133. package/lib/Service/index.js +0 -62
  134. package/lib/Session/assets/did-spaces-guide-cover.svg.js +0 -111
  135. package/lib/Session/assets/did-spaces-guide-icon.svg.js +0 -9
  136. package/lib/Session/context.js +0 -5
  137. package/lib/Session/did-spaces-guide.js +0 -136
  138. package/lib/Session/handler.js +0 -55
  139. package/lib/Session/hooks/use-federated.js +0 -64
  140. package/lib/Session/hooks/use-mobile.js +0 -8
  141. package/lib/Session/hooks/use-protected-routes.js +0 -11
  142. package/lib/Session/hooks/use-session-token.js +0 -181
  143. package/lib/Session/hooks/use-verify.js +0 -45
  144. package/lib/Session/index.js +0 -941
  145. package/lib/Session/libs/constants.js +0 -18
  146. package/lib/Session/libs/did-spaces.js +0 -10
  147. package/lib/Session/libs/federated.js +0 -42
  148. package/lib/Session/libs/index.js +0 -15
  149. package/lib/Session/libs/locales.js +0 -161
  150. package/lib/Session/libs/login-mobile.js +0 -55
  151. package/lib/Session/window-focus-aware.js +0 -17
  152. package/lib/SessionManager/index.js +0 -4
  153. package/lib/Storage/engine/cookie.js +0 -22
  154. package/lib/Storage/engine/local-storage.js +0 -37
  155. package/lib/Storage/index.js +0 -23
  156. package/lib/User/index.js +0 -6
  157. package/lib/User/use-did.js +0 -59
  158. package/lib/User/wrap-did.js +0 -13
  159. package/lib/WebWalletSWKeeper/index.js +0 -5
  160. package/lib/components/PassportSwitcher.js +0 -128
  161. package/lib/constant.js +0 -23
  162. package/lib/error.js +0 -8
  163. package/lib/hooks/use-locale.js +0 -7
  164. package/lib/index.js +0 -111
  165. package/lib/locales/en.js +0 -17
  166. package/lib/locales/index.js +0 -10
  167. package/lib/locales/zh.js +0 -17
  168. package/lib/node_modules/@blocklet/js-sdk/dist/index.js +0 -512
  169. package/lib/packages/did-connect/package.json.js +0 -7
  170. package/lib/types.d.ts +0 -355
  171. package/lib/utils.js +0 -225
@@ -1,5 +0,0 @@
1
- import "@arcblock/ux/lib/DIDConnect/landing-page";
2
- import { default as f } from "@arcblock/ux/lib/DIDConnect/landing-page";
3
- export {
4
- f as default
5
- };
@@ -1,23 +0,0 @@
1
- import { useCreation as p } from "ahooks";
2
- import { useStateContext as l } from "../contexts/state.js";
3
- import m from "./security.js";
4
- import "../../utils.js";
5
- import { getVisitorId as d } from "@arcblock/ux/lib/Util";
6
- function A({ disableSwitchApp: c, tokenState: t }) {
7
- const { appInfoList: o, connectState: s } = l(), { encryptKey: i } = m();
8
- return p(() => {
9
- if (!t.url)
10
- return "";
11
- const u = !c && o.length > 1, e = new URL(t.url || "https://www.didwallet.io"), a = e.searchParams.get("url");
12
- if (a && u) {
13
- const r = new URL(decodeURIComponent(a));
14
- r.searchParams.set("_ek_", i);
15
- const n = d();
16
- n && r.searchParams.set("vid", n), s?.sourceAppPid && r.searchParams.set("spid", s?.sourceAppPid), e.searchParams.set("url", r.toString());
17
- }
18
- return e.toString();
19
- }, [t.url, o.length, s?.sourceAppPid, i]);
20
- }
21
- export {
22
- A as default
23
- };
@@ -1,46 +0,0 @@
1
- import { useBrowser as R } from "@arcblock/react-hooks";
2
- import { detectWalletExtension as v } from "@arcblock/ux/lib/Util";
3
- import { useRequest as D, useCreation as r } from "ahooks";
4
- import W from "lodash/intersection";
5
- import { OAUTH_PROVIDER as x } from "@arcblock/ux/lib/Util/constant";
6
- import { useOAuth as C } from "../../OAuth/context.js";
7
- import "../../utils.js";
8
- import { checkSameProtocol as I, getWebWalletUrl as M } from "@arcblock/ux/lib/Util/wallet";
9
- function F({
10
- enabledConnectTypes: o = [],
11
- allowWallet: n = !0,
12
- passkeyBehavior: g = "none",
13
- webWalletUrl: L = M(),
14
- action: e,
15
- sourceAppPid: f,
16
- mode: c = "dialog",
17
- blocklet: u = globalThis.blocklet,
18
- isSmallView: d = !1
19
- }) {
20
- const s = ["login", "invite", "connect-to-did-space", "connect-to-did-domain", "destroy-self"], { getOAuthConfigList: w } = C(), i = R(), a = v(), { data: m = [] } = D(
21
- async () => await w({ sourceAppPid: f }),
22
- { refreshDeps: [f] }
23
- ), l = r(() => {
24
- const t = W(Object.keys(x), o);
25
- return m.filter((P) => t.includes(P.provider));
26
- }, [m, o]), O = r(() => s.includes(e) ? l.length > 0 : !1, [l, e]), h = r(() => {
27
- let t = n;
28
- return s.includes(e) || (t = !0), t && o.includes("mobile");
29
- }, [n, o, e]), b = I(L), p = r(() => {
30
- let t = n;
31
- return s.includes(e) || (t = !0), t && o.includes("web") && (b || a) && (!i.mobile.any || a);
32
- }, [n, o, i?.mobile?.any, e]), _ = r(() => g !== "none" && !i.wallet && !i.arcSphere, [e]), A = r(() => !s.includes(e) || !["true", void 0, null].includes(u?.DID_CONNECT_ALLOW_EMAIL) ? !1 : u?.settings?.notification?.email?.enabled ?? !1, [e, u]), E = r(() => !1);
33
- return {
34
- hideQRCode: r(() => !!(c === "drawer" || d && i.mobile.any || s.includes(e) && !h), [c, d]),
35
- hideChooseList: E,
36
- showOAuthLogin: O,
37
- showMobileLogin: h,
38
- showWebLogin: p,
39
- showPasskeyLogin: _,
40
- showEmailLogin: A,
41
- oauthProviderList: l
42
- };
43
- }
44
- export {
45
- F as default
46
- };
@@ -1,17 +0,0 @@
1
- import { useRef as c, useEffect as i } from "react";
2
- function u(e) {
3
- const t = c(e);
4
- i(() => {
5
- t.current = e;
6
- }, [e]), i(() => {
7
- const n = (r) => {
8
- !document.hidden && t.current && t.current(r);
9
- };
10
- return document.addEventListener("visibilitychange", n), () => {
11
- document.removeEventListener("visibilitychange", n);
12
- };
13
- }, []);
14
- }
15
- export {
16
- u as default
17
- };
@@ -1,69 +0,0 @@
1
- import { useBrowser as C } from "@arcblock/react-hooks";
2
- import { useRequest as D, useCreation as L } from "ahooks";
3
- import s from "lodash/isNil";
4
- import { LOGIN_PROVIDER as i, WALLET_LOGIN_METHOD as I } from "@arcblock/ux/lib/Util/constant";
5
- import { getFederatedEnabled as O, getMaster as y, getBlockletData as W } from "@arcblock/ux/lib/Util/federated";
6
- import { useState as N } from "react";
7
- const R = async ({ sourceAppPid: d }) => {
8
- const t = globalThis?.blocklet;
9
- if (!t)
10
- return {
11
- [i.WALLET]: {
12
- order: 0,
13
- enabled: !0,
14
- showQrcode: !0
15
- },
16
- [i.PASSKEY]: {
17
- order: 1,
18
- enabled: !0
19
- }
20
- };
21
- const l = O(t), e = y(t);
22
- return l && e?.appPid && d === e?.appPid ? (await W(e.appUrl))?.settings?.authentication || {} : t?.settings?.authentication || {};
23
- }, S = async ({ sourceAppPid: d } = {}) => {
24
- const t = await R({ sourceAppPid: d });
25
- return Object.entries(t).map(([e, o]) => ({ ...o, provider: e })).filter((e) => e.enabled).sort((e, o) => !s(e?.order) && !s(o?.order) ? e.order - o.order : s(e?.order) ? 1 : -1);
26
- };
27
- function q({
28
- allowWallet: d = !0,
29
- passkeyBehavior: t = "none",
30
- action: l,
31
- sourceAppPid: e,
32
- mode: o = "dialog",
33
- blocklet: P = globalThis.blocklet,
34
- isSmallView: p = !1,
35
- lastLoginMethod: a = ""
36
- }) {
37
- const [m, v] = N(!1), w = ["login", "invite", "connect-to-did-space", "connect-to-did-domain", "destroy-self"], A = ["login", "invite", "connect-to-did-space", "connect-to-did-domain", "destroy-self"], u = C(), { data: h = [] } = D(
38
- async () => {
39
- v(!0);
40
- const n = await S({ sourceAppPid: e });
41
- return v(!1), n;
42
- },
43
- { refreshDeps: [e] }
44
- ), f = L(() => {
45
- const n = globalThis?.blocklet?.DID_CONNECT_ENABLED_PROVIDERS?.split(",") || [];
46
- return h.filter((r) => n.length > 0 && !n.includes(r.provider) ? !1 : r.provider === i.WALLET ? d : r.provider === i.PASSKEY ? t !== "none" && !u.wallet && !u.arcSphere : r.provider === i.EMAIL ? A.includes(l) && (P?.settings?.notification?.email?.enabled ?? !1) : !(r.type === "oauth" && !w.includes(l))).sort((r, c) => {
47
- if (a) {
48
- const g = Object.values(I).includes(a), E = g ? r.provider === i.WALLET : r.provider === a, b = g ? c.provider === i.WALLET : c.provider === a;
49
- if (E && !b)
50
- return -1;
51
- if (!E && b)
52
- return 1;
53
- }
54
- return !s(r?.order) && !s(c?.order) ? r.order - c.order : s(r?.order) ? s(c?.order) ? 0 : 1 : -1;
55
- });
56
- }, [h, a]), T = L(() => {
57
- const n = o === "drawer" || p && u.mobile.any;
58
- return globalThis?.blocklet ? !!(f.find((r) => r.provider === i.WALLET)?.showQrcode !== !0 || n) : !!n;
59
- }, [o, p, f]);
60
- return {
61
- hideChooseList: L(() => !1),
62
- hideQRCode: T,
63
- providerList: f,
64
- loadingProviderList: m
65
- };
66
- }
67
- export {
68
- q as default
69
- };
@@ -1,27 +0,0 @@
1
- import l from "tweetnacl";
2
- import { useLocalStorageState as a } from "ahooks";
3
- import { useEffect as s } from "react";
4
- import { encodeKey as t, encrypt as d, decrypt as u } from "../../utils.js";
5
- const r = l.box.keyPair();
6
- function z() {
7
- const [c, i] = a("__encKey", {
8
- defaultValue: t(r.publicKey),
9
- deserializer: (e) => e,
10
- serializer: (e) => e
11
- }), [o, p] = a("__decKey", {
12
- defaultValue: t(r.secretKey),
13
- deserializer: (e) => e,
14
- serializer: (e) => e
15
- });
16
- return s(() => {
17
- localStorage.getItem("__encKey") || i(t(r.publicKey)), localStorage.getItem("__decKey") || p(t(r.secretKey));
18
- }, []), {
19
- encryptKey: c,
20
- decryptKey: o,
21
- decrypt: (e, y = c, n = o) => u(e, y, n),
22
- encrypt: (e, y = c) => d(e, y)
23
- };
24
- }
25
- export {
26
- z as default
27
- };
@@ -1,296 +0,0 @@
1
- import { useRef as S, useEffect as C } from "react";
2
- import W from "lodash/get";
3
- import fe from "js-cookie";
4
- import M from "lodash/omitBy";
5
- import H from "lodash/isNil";
6
- import de from "lodash/omit";
7
- import pe from "lodash/cloneDeep";
8
- import { useReactive as Q, useCreation as me, useMemoizedFn as T } from "ahooks";
9
- import ke from "@arcblock/react-hooks/lib/useInterval";
10
- import ge from "@arcblock/react-hooks/lib/useBrowser";
11
- import { getVisitorId as he, stringifyQuery as x, isUrl as be } from "@arcblock/ux/lib/Util";
12
- import { WsClient as we } from "@arcblock/ws";
13
- import { sleep as G, getExtraHeaders as v, getConnectedInfo as Se, updateConnectedInfo as Ce, parseNextWorkflow as z, createAxios as V, decodeConnectUrl as Ie, parseTokenFromConnectUrl as $e } from "../../utils.js";
14
- import X from "../assets/locale.js";
15
- import xe from "./security.js";
16
- import ve from "./page-show.js";
17
- import { RELAY_SOCKET_PREFIX as J } from "../../constant.js";
18
- function Ue(o) {
19
- const l = o || window.location.href;
20
- return new URL(l).host;
21
- }
22
- const P = {};
23
- function Ae({ action: o, prefix: l, checkFn: m, extraParams: U, baseUrl: k }) {
24
- const d = `${l}/token?${x(U)}`;
25
- return P[d] || (P[d] = async function() {
26
- const f = +/* @__PURE__ */ new Date(), g = await m(d, { headers: v(k) }), h = +/* @__PURE__ */ new Date();
27
- if (h - f < 500 && await G(500 - (h - f)), g?.data?.token)
28
- return g.data;
29
- if (g?.data?.error)
30
- throw new Error(g.data.error);
31
- const A = be(l) ? l : `${k}${l}`;
32
- throw new Error(`Error generating ${o} QR Code from: ${A}`);
33
- }), P[d];
34
- }
35
- const ye = () => {
36
- try {
37
- const l = new URL(window.location.href).searchParams.get("__connect_url__");
38
- if (!l)
39
- return null;
40
- const m = Ie(l);
41
- return {
42
- token: $e(m),
43
- url: m
44
- };
45
- } catch (o) {
46
- return {
47
- error: o
48
- };
49
- }
50
- }, Z = () => W(globalThis, "blocklet.appPid") || W(globalThis, "blocklet.appId") || W(globalThis, "env.appId") || "", Ee = () => (W(globalThis, "env.apiPrefix") || "/").replace(/\/$/, "").replace(J, ""), _ = (o) => `relay:${Z()}:${o}`, Te = () => window.location.protocol === "https:" ? "wss:" : "ws:", Y = (o) => !o || new URL(o).origin === window.location.origin, q = (o) => ["succeed", "error", "timeout", "busy"].includes(o);
51
- function Ye({
52
- action: o,
53
- checkFn: l,
54
- checkInterval: m,
55
- checkTimeout: U,
56
- extraParams: k,
57
- locale: d,
58
- prefix: F,
59
- tokenKey: f,
60
- encKey: g,
61
- onError: h,
62
- onSuccess: A,
63
- baseUrl: K,
64
- autoConnect: ee = !0,
65
- forceConnected: re = !0,
66
- saveConnect: te = !0,
67
- // FIXME: @zhanghan 将来需要设置为默认 false,仅在需要的时候进行保存 login, switch/role/profile
68
- useSocket: ne = !0,
69
- provider: oe = "wallet"
70
- }) {
71
- const e = Q({
72
- checking: !1,
73
- loading: !1,
74
- token: "",
75
- url: "",
76
- store: null,
77
- status: "created",
78
- error: "",
79
- mfaCode: 0,
80
- appInfo: null,
81
- memberAppInfo: null,
82
- connectedDid: "",
83
- saveConnect: !1,
84
- inExistingSession: !1,
85
- nextWorkflow: "",
86
- baseUrl: K,
87
- prefix: `${F}/${o}`,
88
- extraParams: M(k, H),
89
- checkFn: l,
90
- results: {},
91
- action: o,
92
- provider: oe,
93
- reset() {
94
- this.error = "", this.status = "created";
95
- }
96
- }), I = S(0), D = S(null), $ = X[d] || X.en, u = me(() => ye(), []), se = Math.ceil(U / m), c = Q({
97
- onSuccessCalled: !1,
98
- cancelWhenScannedCounter: 0,
99
- isSocketAvailable: !1
100
- }), { encryptKey: ae, decrypt: y } = xe(), O = ge(), L = he(), a = S(null), p = S(null), b = {
101
- ...e.extraParams,
102
- locale: d,
103
- [f]: e.token || u?.token,
104
- provider: e.provider
105
- }, j = async () => {
106
- if (!(u?.token && u?.token === e.token)) {
107
- try {
108
- b[f] && e.status === "created" && await e.checkFn(`${e.prefix}/timeout?${x(b)}`, {
109
- headers: v(e.baseUrl)
110
- });
111
- } catch {
112
- }
113
- try {
114
- e.token && p.current && (await a.current.unsubscribe(_(e.token)), p.current = null);
115
- } catch {
116
- }
117
- }
118
- }, ce = T((...t) => {
119
- const r = {
120
- [g]: ae,
121
- ...e.extraParams,
122
- locale: d,
123
- forceConnected: re,
124
- // - autoConnect 请求参数用于控制服务端是否给钱包应用发送自动连接通知
125
- // - 使用 connect 组件时明确传入了 autoConnect = false, 则 autoConnect 请求参数 为 false
126
- // - 如果 cancelWhenScannedCounter > 0, 说明用户进行过 cancel 操作, 则临时禁用自动连接, autoConnect 请求参数 为 false
127
- // (避免 "无限自动连接问题")
128
- // - 如果上次连接设备 (connected_wallet_os) 不是 ios/android, 则禁用自动连接
129
- autoConnect: ee && // 如果是 wallet webview 环境, 不发送通知, 避免 wallet 连续弹出 auth 窗口 2 次 (#341)
130
- !(O.wallet || O.arcSphere) && !c.cancelWhenScannedCounter && ["ios", "android"].includes(fe.get("connected_wallet_os")),
131
- provider: e.provider
132
- };
133
- L && (r.visitorId = L);
134
- const n = de(D.current || {}, ["sourceAppPid", "verbose"]);
135
- return Object.keys(n).forEach((s) => {
136
- (!r[s] || s === g && n[s]) && (r[s] = n[s]);
137
- }), u?.token && !r.sourceToken && (r.sourceToken = u?.token), Ae({
138
- action: o,
139
- prefix: e.prefix,
140
- baseUrl: e.baseUrl,
141
- checkFn: e.checkFn,
142
- extraParams: r
143
- })(...t);
144
- }), E = T(async (t = !0) => {
145
- t && j();
146
- try {
147
- e.loading = !0, e.token = "", e.url = "", e.store = null, e.extraParams = M(k, H), await G();
148
- const r = await ce(), n = r.extra || {};
149
- e.loading = !1, e.token = r.token, e.url = r.url, e.status = "created", e.error = "", I.current = 0, e.appInfo = r.appInfo, e.memberAppInfo = r.memberAppInfo, e.connectedDid = n.connectedDid, e.saveConnect = n.saveConnect;
150
- } catch (r) {
151
- e.loading = !1, e.status = "error", e.error = `${$.generateError}: ${r.message}`;
152
- }
153
- }), ie = T(() => {
154
- c.cancelWhenScannedCounter++;
155
- });
156
- C(() => {
157
- c.cancelWhenScannedCounter > 0 && (k.nw ? h(new Error($.retryForbidden)) : E());
158
- }, [c.cancelWhenScannedCounter]), C(() => (!(/^((?!chrome|android).)*safari/i.test(globalThis.navigator.userAgent) || Object.hasOwn(globalThis?.blocklet || {}, "DID_CONNECT_DISABLE_SOCKET")) && ne && Y(e.baseUrl) && Z() ? (!a.current || a.current.isConnected() === !1 || a.current.baseUrl !== e.baseUrl) && (a.current = new we(
159
- `${Te()}//${Ue(e.baseUrl)}${Ee()}${J}/relay`,
160
- {
161
- longpollerTimeout: 5e3,
162
- // connection timeout
163
- heartbeatIntervalMs: 30 * 1e3
164
- }
165
- ), a.current.baseUrl = e.baseUrl, a.current.onOpen(() => {
166
- c.isSocketAvailable = !0;
167
- }), a.current.connect()) : c.isSocketAvailable && (c.isSocketAvailable = !1), () => {
168
- a.current && (a.current.disconnect(), a.current = null);
169
- }), [e.baseUrl]);
170
- const le = () => !e.token || e.loading || q(e.status) ? null : m, N = S(null);
171
- C(() => {
172
- N.current = { state: e, params: b };
173
- }), C(() => () => {
174
- const { state: t, params: r } = N.current;
175
- t.status === "created" && r[f] && t.checkFn(`${t.prefix}/timeout?${x(r)}`, {
176
- headers: v(t.baseUrl)
177
- });
178
- }, []);
179
- const w = T(async (t = !1) => {
180
- if ((e.checking || document.hidden) && !t)
181
- return null;
182
- if (e.status === "created" && (I.current++, e.status !== "timeout" && I.current > se))
183
- return e.status = "timeout", j(), null;
184
- if (c.isSocketAvailable && !t)
185
- return null;
186
- try {
187
- e.checking = !0;
188
- const r = await e.checkFn(`${e.prefix}/status?${x(b)}`, {
189
- headers: v(e.baseUrl)
190
- }), { status: n, error: i, mfaCode: s = 0 } = r.data;
191
- if (e.store = r.data, e.mfaCode = s, e.checking = !1, e.status === "scanned" && n === "created" || (e.status = n), n === "error" && i) {
192
- const B = new Error(i);
193
- throw B.response = r, B;
194
- }
195
- return r.data;
196
- } catch (r) {
197
- const { response: n } = r;
198
- if (n?.status) {
199
- b[f] && e.checkFn(`${e.prefix}/timeout?${x(b)}`, {
200
- headers: v(e.baseUrl)
201
- });
202
- const i = n?.data?.error ? n.data.error : r.message, s = new Error(i);
203
- s.code = n.status, e.status = "error", e.checking = !1, e.error = i, h(s, e?.store, y);
204
- } else
205
- e.status = "error", e.checking = !1, e.error = $.generateError;
206
- }
207
- return null;
208
- }), ue = async () => {
209
- try {
210
- if (u.error)
211
- throw u.error;
212
- e.loading = !0, e.token = u.token, e.url = u.url, e.inExistingSession = !0;
213
- let t = await w();
214
- if ((["scanned"].includes(t?.status) || t?.sourceToken === u?.token) && (await E(!1), t = await w()), D.current = t?.extraParams || null, t?.status && !["created"].includes(t?.status))
215
- throw new Error(`${$.invalidSessionStatus} [${t.status}]`);
216
- } catch (t) {
217
- e.status = "error", e.error = t.message, h(t, e?.store, y);
218
- } finally {
219
- e.loading = !1;
220
- }
221
- };
222
- C(() => {
223
- if (!e.token && !e.store && !e.loading && !e.error)
224
- if (u)
225
- ue();
226
- else {
227
- E(!1);
228
- return;
229
- }
230
- if (e.status === "succeed" && !c.onSuccessCalled) {
231
- const t = Se({
232
- ...e.store,
233
- appInfo: e.appInfo,
234
- memberAppInfo: e.memberAppInfo
235
- });
236
- if (Y(e.baseUrl) && te && e.saveConnect && e.store.did && Ce(t, !0), e.store) {
237
- const { nextWorkflow: r } = e.store;
238
- if (r)
239
- try {
240
- const n = z(r, f);
241
- e.nextWorkflow = n?.nextWorkflow || r, Object.assign(e, n), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, I.current = 0, e.status = "scanned", e.results = {
242
- ...e.results,
243
- [e.token]: e.store
244
- }, e.checkFn = V({ baseURL: n.baseUrl, timeout: 8e3 }).get, w();
245
- } catch (n) {
246
- console.error(`Invalid nextWorkflow: ${r}`, n), e.status = "error", e.error = `Invalid nextWorkflow: ${r}: ${n.message}`;
247
- }
248
- else if (e.nextWorkflow && (e.nextWorkflow = "", e.url = ""), typeof A == "function") {
249
- const n = Object.values({ ...e.results, [e.token]: e.store });
250
- c.onSuccessCalled = !0;
251
- const i = n.length > 1 ? n : n[0], s = pe(i);
252
- A(s, y, {
253
- sourceAppPid: k?.sourceAppPid,
254
- ...t
255
- });
256
- }
257
- }
258
- return;
259
- }
260
- if (e.store?.nextWorkflow) {
261
- const { nextWorkflow: t } = e.store;
262
- try {
263
- const r = z(t, f);
264
- e.nextWorkflow = r?.nextWorkflow || t, Object.assign(e, r), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, I.current = 0, e.status = "scanned", e.results = {
265
- ...e.results,
266
- [e.token]: e.store
267
- }, e.checkFn = V({ baseURL: r.baseUrl, timeout: 8e3 }).get, w();
268
- } catch (r) {
269
- console.error(`Invalid nextWorkflow: ${t}`, r), e.status = "error", e.error = `Invalid nextWorkflow: ${t}: ${r.message}`;
270
- }
271
- }
272
- });
273
- const R = S(0);
274
- return C(() => {
275
- if (e.token && c.isSocketAvailable && a.current) {
276
- let t = !1;
277
- p.current ? p.current.token !== e.token && (a.current.unsubscribe(_(p.current.token)), t = !0) : t = !0, t && (p.current = a.current.subscribe(_(e.token)), R.current = 0, p.current.token = e.token, p.current.on("updated", ({ response: r }) => {
278
- const n = +new Date(r.updatedAt);
279
- if (n <= R.current) {
280
- console.warn("Ignore outdated message", r);
281
- return;
282
- }
283
- R.current = n;
284
- let { status: i, error: s } = r;
285
- i === "forbidden" && (s = $.forbidden, i = "error"), e.status = i, e.mfaCode = r.mfaCode || 0, e.store = r, e.error = s, s && h(new Error(s), e?.store, y);
286
- }));
287
- }
288
- }, [e.token, c.isSocketAvailable, a.current]), ke(w, le()), ve(() => {
289
- e.token && q(e.status) === !1 && (e.checking = !1, setTimeout(() => {
290
- w(!0);
291
- }, 100));
292
- }), { state: e, generate: E, cancelWhenScanned: ie };
293
- }
294
- export {
295
- Ye as default
296
- };
@@ -1,19 +0,0 @@
1
- import { useCreation as u } from "ahooks";
2
- import { getFederatedEnabled as m, getMaster as c, getApps as A } from "@arcblock/ux/lib/Util/federated";
3
- import p from "lodash/isUndefined";
4
- import { use as P } from "react";
5
- import { SessionContext as g } from "../../Session/context.js";
6
- function F({ blocklet: t, action: f, sourceAppPid: r, connectState: i, enableSwitchApp: d }) {
7
- const s = P(g), n = u(() => d === !0 ? !0 : !(d === !1 || s?.session?.user && !["login", "invite", "connect-to-did-space", "connect-to-did-domain"].includes(f)), [f, s?.session?.user]), o = u(() => {
8
- if (p(r)) {
9
- const a = m(t), e = c(t);
10
- if (a && e?.appPid)
11
- return e.appPid;
12
- }
13
- return r;
14
- }, [r, t]);
15
- return { appInfoList: u(() => A(t).filter((e) => n ? !0 : p(r) ? p(i.sourceAppPid) ? s?.session?.user ? e.sourceAppPid === s.session.user.sourceAppPid : e.sourceAppPid === o : e.sourceAppPid === i.sourceAppPid : e.sourceAppPid === r), [n, r, i.sourceAppPid, o, s?.session?.user]), autoGenerateSourceAppPid: o, canSwitchApp: n };
16
- }
17
- export {
18
- F as default
19
- };
@@ -1,86 +0,0 @@
1
- import { useCreation as i, useMemoizedFn as R, useReactive as L, useRequest as T } from "ahooks";
2
- import { joinURL as d } from "ufo";
3
- import k from "lodash/pick";
4
- import D from "lodash/unionBy";
5
- import E from "lodash/sortBy";
6
- import x from "@arcblock/ux/lib/Toast";
7
- import { BLOCKLET_SERVICE_PATH_PREFIX as A } from "../../constant.js";
8
- import { createAxios as B, logger as c } from "../../utils.js";
9
- const p = d(A, "/api/user-session");
10
- function M({
11
- appPid: m,
12
- sourceAppPid: f,
13
- loginAppPid: g,
14
- autoFetch: y = !0,
15
- baseUrl: o = "/",
16
- fetchAll: I = !1
17
- } = {}) {
18
- const u = i(() => B(
19
- {
20
- baseURL: d(o, p)
21
- },
22
- { lazy: !0, lazyTime: 500 }
23
- ), [o]), S = R(async () => {
24
- if (!window.blocklet)
25
- return [];
26
- let r = [];
27
- try {
28
- ({ data: r = [] } = await u.get(""));
29
- } catch (e) {
30
- c.error("Failed to get user-sessions", e);
31
- }
32
- return r.filter((e) => I ? !0 : !e.appUrl).map((e) => ({
33
- appUrl: o,
34
- ...e
35
- }));
36
- }), s = L({
37
- loaded: !1,
38
- loadingId: null
39
- }), t = T(S, {
40
- manual: !y,
41
- onFinally() {
42
- s.loaded = !0;
43
- },
44
- refreshDeps: [o]
45
- }), w = async (r) => {
46
- const a = k(r, ["userDid", "visitorId", "passportId", "id"]);
47
- try {
48
- s.loadingId = r.id;
49
- const { data: e } = await u.post(
50
- "login",
51
- { ...a, appPid: g },
52
- {
53
- baseURL: d(r.appUrl || "/", p)
54
- }
55
- );
56
- return e;
57
- } catch (e) {
58
- const h = e.response ? e.response?.data?.error || e.response?.data : e.message;
59
- throw x.error(h), c.error("Quick login error", e), e;
60
- } finally {
61
- s.loadingId = null;
62
- }
63
- }, l = i(() => t.data ? t.data.filter((r) => r.status !== "expired") : [], [t.data]), n = i(() => {
64
- const r = (/* @__PURE__ */ new Date()).getTime(), a = E(l, (e) => r - new Date(e.updatedAt).getTime());
65
- return D(
66
- a,
67
- (e) => [
68
- e.userDid
69
- // 暂不以用户角色来做去重的因子
70
- // x.user.role
71
- ].join("_")
72
- );
73
- }, [l, f, m]), U = i(() => !!(n && n.length > 0), [n]);
74
- return {
75
- loadingId: s.loadingId,
76
- userSessions: n,
77
- quickLoginEnabled: U,
78
- loginUserSession: w,
79
- loading: t.loading,
80
- loaded: t.loaded,
81
- refresh: t.refreshAsync
82
- };
83
- }
84
- export {
85
- M as default
86
- };
@@ -1,16 +0,0 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import { lazy as r, Suspense as e } from "react";
3
- import { withUxTheme as i, withContainer as n } from "@arcblock/ux/lib/DIDConnect";
4
- import m from "./with-blocklet.js";
5
- import a from "./with-bridge-call.js";
6
- import { default as y } from "./hooks/security.js";
7
- import c from "./fallback-connect.js";
8
- const l = r(() => import("./connect.js"));
9
- function f(o) {
10
- return /* @__PURE__ */ t(e, { fallback: /* @__PURE__ */ t(c, {}), children: /* @__PURE__ */ t(l, { ...o }) });
11
- }
12
- const w = i(a(m(n(f))));
13
- export {
14
- w as default,
15
- y as useSecurity
16
- };
@@ -1,5 +0,0 @@
1
- import "@arcblock/ux/lib/DIDConnect/landing-page";
2
- import { default as f } from "@arcblock/ux/lib/DIDConnect/landing-page";
3
- export {
4
- f as default
5
- };