@arcblock/did-connect-react 3.2.3 → 3.2.5

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.
@@ -7,7 +7,8 @@
7
7
  "README.md",
8
8
  "src/index.js"
9
9
  ],
10
- "parentId": ""
10
+ "parentId": "",
11
+ "icon": "lucide:book"
11
12
  },
12
13
  {
13
14
  "title": "Getting Started",
@@ -19,7 +20,8 @@
19
20
  "src/Connect/index.jsx",
20
21
  "src/Button/index.jsx"
21
22
  ],
22
- "parentId": ""
23
+ "parentId": "",
24
+ "icon": "lucide:rocket"
23
25
  },
24
26
  {
25
27
  "title": "Core Components",
@@ -29,7 +31,8 @@
29
31
  "src/Session/index.jsx",
30
32
  "src/Connect/index.jsx"
31
33
  ],
32
- "parentId": ""
34
+ "parentId": "",
35
+ "icon": "lucide:component"
33
36
  },
34
37
  {
35
38
  "title": "Session Management (SessionProvider)",
@@ -67,7 +70,8 @@
67
70
  "src/OAuth/context.jsx",
68
71
  "src/Passkey/context.jsx"
69
72
  ],
70
- "parentId": ""
73
+ "parentId": "",
74
+ "icon": "lucide:hook"
71
75
  },
72
76
  {
73
77
  "title": "useConnect",
@@ -111,7 +115,8 @@
111
115
  "src/Button/index.jsx",
112
116
  "src/Logo/index.jsx"
113
117
  ],
114
- "parentId": ""
118
+ "parentId": "",
119
+ "icon": "lucide:layout-template"
115
120
  },
116
121
  {
117
122
  "title": "Avatar",
@@ -160,7 +165,8 @@
160
165
  "src/utils.js",
161
166
  "src/error.js"
162
167
  ],
163
- "parentId": ""
168
+ "parentId": "",
169
+ "icon": "lucide:sliders-horizontal"
164
170
  },
165
171
  {
166
172
  "title": "Authentication Methods",
@@ -192,6 +198,7 @@
192
198
  "sourceIds": [
193
199
  "src/types.d.ts"
194
200
  ],
195
- "parentId": ""
201
+ "parentId": "",
202
+ "icon": "lucide:code"
196
203
  }
197
204
  ]
@@ -1,97 +1,86 @@
1
- import { useCreation as l, useMemoizedFn as E, useReactive as L, useRequest as T } from "ahooks";
2
- import { joinURL as u } from "ufo";
1
+ import { useCreation as i, useMemoizedFn as R, useReactive as L, useRequest as T } from "ahooks";
2
+ import { joinURL as d } from "ufo";
3
3
  import k from "lodash/pick";
4
- import A from "lodash/unionBy";
5
- import D from "lodash/sortBy";
4
+ import D from "lodash/unionBy";
5
+ import E from "lodash/sortBy";
6
6
  import x from "@arcblock/ux/lib/Toast";
7
- import { getFederatedEnabled as B, getMaster as C } from "@arcblock/ux/lib/Util/federated";
8
- import { BLOCKLET_SERVICE_PATH_PREFIX as P } from "../../constant.js";
9
- import { createAxios as _, logger as m } from "../../utils.js";
10
- const f = u(P, "/api/user-session");
11
- function O({
12
- appPid: y,
13
- sourceAppPid: U,
14
- loginAppPid: S,
15
- autoFetch: w = !0,
16
- baseUrl: a = "/",
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 = "/",
17
16
  fetchAll: I = !1
18
17
  } = {}) {
19
- const p = l(() => _(
18
+ const u = i(() => B(
20
19
  {
21
- baseURL: u(a, f)
20
+ baseURL: d(o, p)
22
21
  },
23
22
  { lazy: !0, lazyTime: 500 }
24
- ), [a]), h = E(async () => {
23
+ ), [o]), S = R(async () => {
25
24
  if (!window.blocklet)
26
25
  return [];
27
26
  let r = [];
28
27
  try {
29
- ({ data: r = [] } = await p.get(""));
30
- } catch (t) {
31
- m.error("Failed to get user-sessions", t);
32
- }
33
- const s = r.map((t) => ({
34
- ...t,
35
- appUrl: a
36
- })), e = B(), n = C();
37
- if (I && e && n) {
38
- let t = [];
39
- try {
40
- ({ data: t = [] } = await p.get(u(n.appUrl, f)));
41
- } catch (c) {
42
- m.error("Failed to get master user-sessions", c);
43
- }
44
- return s.concat(t.map((c) => ({ ...c, appUrl: n.appUrl })));
28
+ ({ data: r = [] } = await u.get(""));
29
+ } catch (e) {
30
+ c.error("Failed to get user-sessions", e);
45
31
  }
46
- return !e || !n ? s.filter((t) => t?.user?.sourceAppPid === null) : s;
47
- }), i = L({
32
+ return r.filter((e) => I ? !0 : !e.appUrl).map((e) => ({
33
+ appUrl: o,
34
+ ...e
35
+ }));
36
+ }), s = L({
48
37
  loaded: !1,
49
38
  loadingId: null
50
- }), o = T(h, {
51
- manual: !w,
39
+ }), t = T(S, {
40
+ manual: !y,
52
41
  onFinally() {
53
- i.loaded = !0;
42
+ s.loaded = !0;
54
43
  },
55
- refreshDeps: [a]
56
- }), F = async (r) => {
57
- const s = k(r, ["userDid", "visitorId", "passportId", "id"]);
44
+ refreshDeps: [o]
45
+ }), w = async (r) => {
46
+ const a = k(r, ["userDid", "visitorId", "passportId", "id"]);
58
47
  try {
59
- i.loadingId = r.id;
60
- const { data: e } = await p.post(
48
+ s.loadingId = r.id;
49
+ const { data: e } = await u.post(
61
50
  "login",
62
- { ...s, appPid: S },
51
+ { ...a, appPid: g },
63
52
  {
64
- baseURL: u(r.appUrl || "/", f)
53
+ baseURL: d(r.appUrl || "/", p)
65
54
  }
66
55
  );
67
56
  return e;
68
57
  } catch (e) {
69
- const n = e.response ? e.response?.data?.error || e.response?.data : e.message;
70
- throw x.error(n), m.error("Quick login error", e), 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;
71
60
  } finally {
72
- i.loadingId = null;
61
+ s.loadingId = null;
73
62
  }
74
- }, g = l(() => o.data ? o.data.filter((r) => r.status !== "expired") : [], [o.data]), d = l(() => {
75
- const r = (/* @__PURE__ */ new Date()).getTime(), s = D(g, (e) => r - new Date(e.updatedAt).getTime());
76
- return A(
77
- s,
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,
78
67
  (e) => [
79
68
  e.userDid
80
69
  // 暂不以用户角色来做去重的因子
81
70
  // x.user.role
82
71
  ].join("_")
83
72
  );
84
- }, [g, U, y]), R = l(() => !!(d && d.length > 0), [d]);
73
+ }, [l, f, m]), U = i(() => !!(n && n.length > 0), [n]);
85
74
  return {
86
- loadingId: i.loadingId,
87
- userSessions: d,
88
- quickLoginEnabled: R,
89
- loginUserSession: F,
90
- loading: o.loading,
91
- loaded: o.loaded,
92
- refresh: o.refreshAsync
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
93
82
  };
94
83
  }
95
84
  export {
96
- O as default
85
+ M as default
97
86
  };
@@ -1,4 +1,4 @@
1
- const o = "3.2.3", s = {
1
+ const o = "3.2.5", s = {
2
2
  version: o
3
3
  };
4
4
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/did-connect-react",
3
- "version": "3.2.3",
3
+ "version": "3.2.5",
4
4
  "description": "Client side library to work with DID Connect by ArcBlock.",
5
5
  "keywords": [
6
6
  "react",
@@ -32,16 +32,16 @@
32
32
  "url": "https://github.com/ArcBlock/ux/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@arcblock/bridge": "3.2.3",
36
- "@arcblock/did": "^1.27.3",
37
- "@arcblock/icons": "3.2.3",
38
- "@arcblock/react-hooks": "3.2.3",
39
- "@arcblock/ws": "^1.27.3",
35
+ "@arcblock/bridge": "3.2.5",
36
+ "@arcblock/did": "^1.27.6",
37
+ "@arcblock/icons": "3.2.5",
38
+ "@arcblock/react-hooks": "3.2.5",
39
+ "@arcblock/ws": "^1.27.6",
40
40
  "@fontsource/lexend": "^5.2.9",
41
41
  "@iconify-icons/logos": "^1.2.36",
42
42
  "@iconify-icons/material-symbols": "^1.2.58",
43
43
  "@iconify/react": "^5.2.1",
44
- "@ocap/util": "^1.27.3",
44
+ "@ocap/util": "^1.27.6",
45
45
  "@simplewebauthn/browser": "^13.1.0",
46
46
  "ahooks": "^3.8.5",
47
47
  "axios": "^1.10.0",
@@ -80,5 +80,5 @@
80
80
  "eslint-plugin-react-hooks": "^4.6.2",
81
81
  "jest": "^29.7.0"
82
82
  },
83
- "gitHead": "bbd2b3c8caecf454ee738676f1ca5fe0e71fdb6a"
83
+ "gitHead": "8fe09067fd88bc4fd7fe300c984b2b4775fcd128"
84
84
  }
@@ -4,7 +4,6 @@ import pick from 'lodash/pick';
4
4
  import unionBy from 'lodash/unionBy';
5
5
  import sortBy from 'lodash/sortBy';
6
6
  import Toast from '@arcblock/ux/lib/Toast';
7
- import { getFederatedEnabled, getMaster } from '@arcblock/ux/lib/Util/federated';
8
7
 
9
8
  import { BLOCKLET_SERVICE_PATH_PREFIX } from '../../constant';
10
9
  import { createAxios, logger } from '../../utils';
@@ -33,34 +32,24 @@ export default function useQuickConnect({
33
32
  return [];
34
33
  }
35
34
 
36
- let selfUserSessions = [];
35
+ let userSessions = [];
37
36
  try {
38
- ({ data: selfUserSessions = [] } = await api.get(''));
37
+ ({ data: userSessions = [] } = await api.get(''));
39
38
  } catch (err) {
40
39
  logger.error('Failed to get user-sessions', err);
41
40
  }
42
- const result = selfUserSessions.map((x) => ({
43
- ...x,
44
- appUrl: baseUrl,
45
- }));
46
- const enabledFederated = getFederatedEnabled();
47
- const master = getMaster();
48
- // NOTICE: 联合查询 master 中的会话列表
49
- if (fetchAll && enabledFederated) {
50
- if (master) {
51
- let masterUserSessions = [];
52
- try {
53
- ({ data: masterUserSessions = [] } = await api.get(joinURL(master.appUrl, prefix)));
54
- } catch (err) {
55
- logger.error('Failed to get master user-sessions', err);
41
+ // NOTICE: 已经包含了 federated master userSessions
42
+ const result = userSessions
43
+ .filter((x) => {
44
+ if (!fetchAll) {
45
+ return !x.appUrl;
56
46
  }
57
-
58
- return result.concat(masterUserSessions.map((x) => ({ ...x, appUrl: master.appUrl })));
59
- }
60
- }
61
- if (!enabledFederated || !master) {
62
- return result.filter((x) => x?.user?.sourceAppPid === null);
63
- }
47
+ return true;
48
+ })
49
+ .map((x) => ({
50
+ appUrl: baseUrl,
51
+ ...x,
52
+ }));
64
53
  return result;
65
54
  });
66
55
  const currentState = useReactive({