@arcblock/did-connect-react 3.2.4 → 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.
|
@@ -1,97 +1,86 @@
|
|
|
1
|
-
import { useCreation as
|
|
2
|
-
import { joinURL as
|
|
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
|
|
5
|
-
import
|
|
4
|
+
import D from "lodash/unionBy";
|
|
5
|
+
import E from "lodash/sortBy";
|
|
6
6
|
import x from "@arcblock/ux/lib/Toast";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
18
|
+
const u = i(() => B(
|
|
20
19
|
{
|
|
21
|
-
baseURL:
|
|
20
|
+
baseURL: d(o, p)
|
|
22
21
|
},
|
|
23
22
|
{ lazy: !0, lazyTime: 500 }
|
|
24
|
-
), [
|
|
23
|
+
), [o]), S = R(async () => {
|
|
25
24
|
if (!window.blocklet)
|
|
26
25
|
return [];
|
|
27
26
|
let r = [];
|
|
28
27
|
try {
|
|
29
|
-
({ data: r = [] } = await
|
|
30
|
-
} catch (
|
|
31
|
-
|
|
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
|
|
47
|
-
|
|
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
|
-
}),
|
|
51
|
-
manual: !
|
|
39
|
+
}), t = T(S, {
|
|
40
|
+
manual: !y,
|
|
52
41
|
onFinally() {
|
|
53
|
-
|
|
42
|
+
s.loaded = !0;
|
|
54
43
|
},
|
|
55
|
-
refreshDeps: [
|
|
56
|
-
}),
|
|
57
|
-
const
|
|
44
|
+
refreshDeps: [o]
|
|
45
|
+
}), w = async (r) => {
|
|
46
|
+
const a = k(r, ["userDid", "visitorId", "passportId", "id"]);
|
|
58
47
|
try {
|
|
59
|
-
|
|
60
|
-
const { data: e } = await
|
|
48
|
+
s.loadingId = r.id;
|
|
49
|
+
const { data: e } = await u.post(
|
|
61
50
|
"login",
|
|
62
|
-
{ ...
|
|
51
|
+
{ ...a, appPid: g },
|
|
63
52
|
{
|
|
64
|
-
baseURL:
|
|
53
|
+
baseURL: d(r.appUrl || "/", p)
|
|
65
54
|
}
|
|
66
55
|
);
|
|
67
56
|
return e;
|
|
68
57
|
} catch (e) {
|
|
69
|
-
const
|
|
70
|
-
throw x.error(
|
|
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
|
-
|
|
61
|
+
s.loadingId = null;
|
|
73
62
|
}
|
|
74
|
-
},
|
|
75
|
-
const r = (/* @__PURE__ */ new Date()).getTime(),
|
|
76
|
-
return
|
|
77
|
-
|
|
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
|
-
}, [
|
|
73
|
+
}, [l, f, m]), U = i(() => !!(n && n.length > 0), [n]);
|
|
85
74
|
return {
|
|
86
|
-
loadingId:
|
|
87
|
-
userSessions:
|
|
88
|
-
quickLoginEnabled:
|
|
89
|
-
loginUserSession:
|
|
90
|
-
loading:
|
|
91
|
-
loaded:
|
|
92
|
-
refresh:
|
|
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
|
-
|
|
85
|
+
M as default
|
|
97
86
|
};
|
package/lib/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-connect-react",
|
|
3
|
-
"version": "3.2.
|
|
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.
|
|
36
|
-
"@arcblock/did": "^1.27.
|
|
37
|
-
"@arcblock/icons": "3.2.
|
|
38
|
-
"@arcblock/react-hooks": "3.2.
|
|
39
|
-
"@arcblock/ws": "^1.27.
|
|
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.
|
|
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": "
|
|
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
|
|
35
|
+
let userSessions = [];
|
|
37
36
|
try {
|
|
38
|
-
({ data:
|
|
37
|
+
({ data: userSessions = [] } = await api.get(''));
|
|
39
38
|
} catch (err) {
|
|
40
39
|
logger.error('Failed to get user-sessions', err);
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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({
|