@blocklet/ui-react 3.5.1 → 3.5.2
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/Dashboard/index.d.ts +2 -2
- package/lib/Footer/links.d.ts +1 -1
- package/lib/Notifications/utils.js +1 -1
- package/lib/UserCenter/components/config-inviter.js +1 -1
- package/lib/UserCenter/components/config-profile.js +1 -1
- package/lib/UserCenter/components/notification.js +1 -1
- package/lib/UserCenter/components/privacy.js +1 -1
- package/lib/UserCenter/components/settings.js +1 -1
- package/lib/UserCenter/components/user-center.js +1 -1
- package/lib/UserCenter/components/user-info/user-basic-info.js +1 -1
- package/lib/UserSessions/components/user-sessions.js +1 -1
- package/lib/blocklets.d.ts +1 -1
- package/lib/common/header-addons.d.ts +1 -1
- package/lib/common/org-switch/use-org.d.ts +4 -4
- package/lib/common/org-switch/use-org.js +1 -1
- package/lib/hooks/use-follow.js +1 -1
- package/lib/node_modules/@blocklet/js-sdk/dist/index.js +495 -0
- package/package.json +10 -10
package/lib/Dashboard/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddon
|
|
|
15
15
|
showRole: boolean;
|
|
16
16
|
onLogout: () => void;
|
|
17
17
|
} | undefined;
|
|
18
|
-
links?:
|
|
18
|
+
links?: any[] | undefined;
|
|
19
19
|
showDomainWarningDialog?: boolean | undefined;
|
|
20
20
|
appPath?: undefined;
|
|
21
21
|
appTab?: undefined;
|
|
@@ -27,7 +27,7 @@ declare namespace Dashboard {
|
|
|
27
27
|
export { BlockletMetaProps as meta };
|
|
28
28
|
export let fallbackUrl: PropTypes.Requireable<string>;
|
|
29
29
|
export let invalidPathFallback: PropTypes.Requireable<(...args: any[]) => any>;
|
|
30
|
-
export let headerAddons: PropTypes.Requireable<NonNullable<
|
|
30
|
+
export let headerAddons: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.ReactNodeLike>>;
|
|
31
31
|
export { SessionManagerProps as sessionManagerProps };
|
|
32
32
|
export let links: PropTypes.Requireable<NonNullable<any[] | ((...args: any[]) => any) | null | undefined>>;
|
|
33
33
|
export let showDomainWarningDialog: PropTypes.Requireable<boolean>;
|
package/lib/Footer/links.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { default as PropTypes } from 'prop-types';
|
|
|
4
4
|
*/
|
|
5
5
|
declare function Links({ links, flowLayout, minColumns, maxColumns, ...rest }: {
|
|
6
6
|
[x: string]: any;
|
|
7
|
-
links?:
|
|
7
|
+
links?: any[] | undefined;
|
|
8
8
|
flowLayout?: boolean | undefined;
|
|
9
9
|
minColumns?: number | undefined;
|
|
10
10
|
maxColumns?: number | undefined;
|
|
@@ -2,7 +2,7 @@ import h from "lodash/isEmpty";
|
|
|
2
2
|
import m from "dompurify";
|
|
3
3
|
import { toTextList as v, Link as f, getLink as p } from "@abtnode/util/lib/notification-preview/highlight";
|
|
4
4
|
import { isSameAddr as d } from "@abtnode/util/lib/notification-preview/func";
|
|
5
|
-
import { getBlockletSDK as T } from "
|
|
5
|
+
import { getBlockletSDK as T } from "../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
6
6
|
const b = (t) => {
|
|
7
7
|
if (!t || !t.length)
|
|
8
8
|
return [];
|
|
@@ -2,7 +2,7 @@ import { jsx as r } from "react/jsx-runtime";
|
|
|
2
2
|
import { Box as l, TextField as s } from "@mui/material";
|
|
3
3
|
import { useReactive as f, useMemoizedFn as c } from "ahooks";
|
|
4
4
|
import v from "@arcblock/ux/lib/Toast";
|
|
5
|
-
import { getBlockletSDK as m } from "
|
|
5
|
+
import { getBlockletSDK as m } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
6
6
|
import { formatAxiosError as d } from "../libs/utils.js";
|
|
7
7
|
function C({ user: i }) {
|
|
8
8
|
const e = f({
|
|
@@ -5,7 +5,7 @@ import { translate as v } from "@arcblock/ux/lib/Locale/util";
|
|
|
5
5
|
import { useLocaleContext as w } from "@arcblock/ux/lib/Locale/context";
|
|
6
6
|
import C from "@arcblock/ux/lib/Toast";
|
|
7
7
|
import y from "@arcblock/icons/lib/ArrowDown";
|
|
8
|
-
import { getBlockletSDK as I } from "
|
|
8
|
+
import { getBlockletSDK as I } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
9
9
|
import { translations as b } from "../libs/locales.js";
|
|
10
10
|
import { formatAxiosError as S } from "../libs/utils.js";
|
|
11
11
|
const z = [
|
|
@@ -10,7 +10,7 @@ import { getWalletDid as C } from "@arcblock/ux/lib/SessionUser/libs/utils";
|
|
|
10
10
|
import { translate as M } from "@arcblock/ux/lib/Locale/util";
|
|
11
11
|
import { useLocaleContext as P } from "@arcblock/ux/lib/Locale/context";
|
|
12
12
|
import U from "@arcblock/ux/lib/DID";
|
|
13
|
-
import { getBlockletSDK as _ } from "
|
|
13
|
+
import { getBlockletSDK as _ } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
14
14
|
import { translations as $ } from "../libs/locales.js";
|
|
15
15
|
import S from "./webhook-item.js";
|
|
16
16
|
import { formatAxiosError as b } from "../libs/utils.js";
|
|
@@ -6,7 +6,7 @@ import { useMemoizedFn as l } from "ahooks";
|
|
|
6
6
|
import { translate as S } from "@arcblock/ux/lib/Locale/util";
|
|
7
7
|
import { useLocaleContext as g } from "@arcblock/ux/lib/Locale/context";
|
|
8
8
|
import c from "@arcblock/ux/lib/Toast";
|
|
9
|
-
import { getBlockletSDK as v } from "
|
|
9
|
+
import { getBlockletSDK as v } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
10
10
|
import { translations as b } from "../libs/locales.js";
|
|
11
11
|
import { formatAxiosError as k } from "../libs/utils.js";
|
|
12
12
|
function A({
|
|
@@ -7,7 +7,7 @@ import { translate as C } from "@arcblock/ux/lib/Locale/util";
|
|
|
7
7
|
import { useLocaleContext as w } from "@arcblock/ux/lib/Locale/context";
|
|
8
8
|
import { mergeSx as L } from "@arcblock/ux/lib/Util/style";
|
|
9
9
|
import D from "@arcblock/react-hooks/lib/useBrowser";
|
|
10
|
-
import { getBlockletSDK as P } from "
|
|
10
|
+
import { getBlockletSDK as P } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
11
11
|
import { translations as T } from "../libs/locales.js";
|
|
12
12
|
import B from "./notification.js";
|
|
13
13
|
import E from "./privacy.js";
|
|
@@ -16,7 +16,7 @@ import { ErrorFallback as Ne } from "@arcblock/ux/lib/ErrorBoundary";
|
|
|
16
16
|
import { styled as me } from "@arcblock/ux/lib/Theme";
|
|
17
17
|
import je from "lodash/cloneDeep";
|
|
18
18
|
import { joinURL as M, getQuery as He, parseURL as le, withoutTrailingSlash as ae, withQuery as ue } from "ufo";
|
|
19
|
-
import { getBlockletSDK as Ee } from "
|
|
19
|
+
import { getBlockletSDK as Ee } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
20
20
|
import { isSupportFollow as Re } from "@arcblock/ux/lib/Util";
|
|
21
21
|
import { PROFILE_URL as D } from "@arcblock/ux/lib/Util/constant";
|
|
22
22
|
import _e from "../../Footer/index.js";
|
|
@@ -10,7 +10,7 @@ import { lazy as G, useState as C, useEffect as j } from "react";
|
|
|
10
10
|
import I from "@arcblock/ux/lib/Toast";
|
|
11
11
|
import { parseURL as H, joinURL as J } from "ufo";
|
|
12
12
|
import { KeyboardArrowUp as X, KeyboardArrowDown as Z } from "@mui/icons-material";
|
|
13
|
-
import { getBlockletSDK as _ } from "
|
|
13
|
+
import { getBlockletSDK as _ } from "../../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
14
14
|
import { translations as P } from "../../libs/locales.js";
|
|
15
15
|
import { formatAxiosError as R } from "../../libs/utils.js";
|
|
16
16
|
import { currentTimezone as M, getStatusDuration as tt, isValidUrl as rt, isDuplicateUrl as et } from "./utils.js";
|
|
@@ -11,7 +11,7 @@ import _ from "@arcblock/ux/lib/DID";
|
|
|
11
11
|
import ee from "p-queue";
|
|
12
12
|
import { Box as d, Typography as a, CircularProgress as te, useMediaQuery as oe, Tooltip as ne, Button as P, RadioGroup as re, FormControlLabel as B, Radio as C } from "@mui/material";
|
|
13
13
|
import { memo as ie, useEffect as se } from "react";
|
|
14
|
-
import { getBlockletSDK as ae } from "
|
|
14
|
+
import { getBlockletSDK as ae } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
15
15
|
import { mergeSx as M } from "@arcblock/ux/lib/Util/style";
|
|
16
16
|
import le from "../../hooks/use-mobile.js";
|
|
17
17
|
import ce from "./user-session-info.js";
|
package/lib/blocklets.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export function getLocalizedNavigation({ navigation, locale, defaultLocale, sect
|
|
|
11
11
|
}>;
|
|
12
12
|
locale: string;
|
|
13
13
|
defaultLocale: string;
|
|
14
|
-
section?: "
|
|
14
|
+
section?: "footer" | "header" | undefined;
|
|
15
15
|
}): any[];
|
|
16
16
|
export function formatNavigation(navigation: any): any;
|
|
17
17
|
export function parseNavigation(navigation: any): {
|
|
@@ -11,7 +11,7 @@ declare function HeaderAddons({ formattedBlocklet, addons, showDomainWarningDial
|
|
|
11
11
|
declare namespace HeaderAddons {
|
|
12
12
|
namespace propTypes {
|
|
13
13
|
export let formattedBlocklet: PropTypes.Validator<object>;
|
|
14
|
-
export let addons: PropTypes.Requireable<NonNullable<
|
|
14
|
+
export let addons: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.ReactNodeLike>>;
|
|
15
15
|
export { SessionManagerProps as sessionManagerProps };
|
|
16
16
|
export let showDomainWarningDialog: PropTypes.Requireable<boolean>;
|
|
17
17
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function useOrg(session: any): {
|
|
2
|
-
getOrgs: (this: any, args_0
|
|
3
|
-
createOrg: (this: any, args_0
|
|
4
|
-
updateOrg: (this: any, orgId
|
|
5
|
-
getCurrentOrg: (this: any, roleName
|
|
2
|
+
getOrgs: (this: any, args_0?: any) => Promise<any>;
|
|
3
|
+
createOrg: (this: any, args_0?: any) => Promise<any>;
|
|
4
|
+
updateOrg: (this: any, orgId?: any, args_1?: any) => Promise<any>;
|
|
5
|
+
getCurrentOrg: (this: any, roleName?: any) => Promise<any>;
|
|
6
6
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemoizedFn as s } from "ahooks";
|
|
2
2
|
import c from "@arcblock/ux/lib/Toast";
|
|
3
|
-
import { getBlockletSDK as y } from "
|
|
3
|
+
import { getBlockletSDK as y } from "../../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
4
4
|
import { formatAxiosError as u } from "../../UserCenter/libs/utils.js";
|
|
5
5
|
function x(g) {
|
|
6
6
|
const n = y(), l = s(async ({ search: t, page: r = 1, pageSize: o = 20 }) => {
|
package/lib/hooks/use-follow.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState as p, useEffect as F } from "react";
|
|
2
2
|
import { useMemoizedFn as n } from "ahooks";
|
|
3
3
|
import c from "@arcblock/ux/lib/Toast";
|
|
4
|
-
import { getBlockletSDK as U } from "
|
|
4
|
+
import { getBlockletSDK as U } from "../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
5
5
|
import { formatAxiosError as u } from "../UserCenter/libs/utils.js";
|
|
6
6
|
function _({
|
|
7
7
|
userDid: r,
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { SESSION_TOKEN_STORAGE_KEY as h, REFRESH_TOKEN_STORAGE_KEY as y, WELLKNOWN_SERVICE_PATH_PREFIX as k } from "@abtnode/constant";
|
|
2
|
+
import { withQuery as S, joinURL as w } from "ufo";
|
|
3
|
+
import p from "js-cookie";
|
|
4
|
+
import I from "quick-lru";
|
|
5
|
+
import L from "lodash/isEmpty";
|
|
6
|
+
import C from "axios";
|
|
7
|
+
import B from "keyv";
|
|
8
|
+
import { KeyvLocalStorage as E } from "keyv-browser";
|
|
9
|
+
import x from "lodash/isNumber";
|
|
10
|
+
import A from "lodash/omit";
|
|
11
|
+
import F from "lodash/isObject";
|
|
12
|
+
import j from "json-stable-stringify";
|
|
13
|
+
import "is-url";
|
|
14
|
+
var N = class {
|
|
15
|
+
constructor({ api: e, token: t }) {
|
|
16
|
+
this.api = e, this.token = t;
|
|
17
|
+
}
|
|
18
|
+
async getUserPublicInfo({ did: e, name: t }) {
|
|
19
|
+
const { data: o } = await this.api.get("/api/user", { params: {
|
|
20
|
+
did: e,
|
|
21
|
+
name: t
|
|
22
|
+
} });
|
|
23
|
+
return o;
|
|
24
|
+
}
|
|
25
|
+
async getUserPrivacyConfig({ did: e, name: t }) {
|
|
26
|
+
const { data: o } = await this.api.get("/api/user/privacy/config", { params: {
|
|
27
|
+
did: e,
|
|
28
|
+
name: t
|
|
29
|
+
} });
|
|
30
|
+
return o;
|
|
31
|
+
}
|
|
32
|
+
async saveUserPrivacyConfig(e) {
|
|
33
|
+
const { data: t } = await this.api.post("/api/user/privacy/config", e);
|
|
34
|
+
return t;
|
|
35
|
+
}
|
|
36
|
+
async getUserNotificationConfig() {
|
|
37
|
+
const { data: e } = await this.api.get("/api/user/notification/config");
|
|
38
|
+
return e;
|
|
39
|
+
}
|
|
40
|
+
async saveUserNotificationConfig(e) {
|
|
41
|
+
const { data: t } = await this.api.post("/api/user/notification/config", e);
|
|
42
|
+
return t;
|
|
43
|
+
}
|
|
44
|
+
async testNotificationWebhook(e) {
|
|
45
|
+
const { data: t } = await this.api.put("/api/user/notification/webhook", e);
|
|
46
|
+
return t;
|
|
47
|
+
}
|
|
48
|
+
async getProfileUrl({ did: e, locale: t }) {
|
|
49
|
+
return S(`${k}/user`, {
|
|
50
|
+
did: e,
|
|
51
|
+
locale: t
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async getProfile() {
|
|
55
|
+
const { data: e } = await this.api.get("/api/user/profile");
|
|
56
|
+
return e;
|
|
57
|
+
}
|
|
58
|
+
async refreshProfile() {
|
|
59
|
+
await this.api.put("/api/user/refreshProfile");
|
|
60
|
+
}
|
|
61
|
+
async followUser({ userDid: e }) {
|
|
62
|
+
await this.api.post(`/api/user/follow/${e}`);
|
|
63
|
+
}
|
|
64
|
+
async unfollowUser({ userDid: e }) {
|
|
65
|
+
await this.api.delete(`/api/user/follow/${e}`);
|
|
66
|
+
}
|
|
67
|
+
async isFollowingUser({ userDid: e }) {
|
|
68
|
+
const { data: t } = await this.api.get(`/api/user/follow/${e}`);
|
|
69
|
+
return t.isFollowing;
|
|
70
|
+
}
|
|
71
|
+
async saveProfile({ locale: e, inviter: t, metadata: o, address: r }) {
|
|
72
|
+
const { data: s } = await this.api.put("/api/user/profile", {
|
|
73
|
+
locale: e,
|
|
74
|
+
inviter: t,
|
|
75
|
+
metadata: o,
|
|
76
|
+
address: r
|
|
77
|
+
});
|
|
78
|
+
return s;
|
|
79
|
+
}
|
|
80
|
+
async updateDidSpace({ spaceGateway: e }) {
|
|
81
|
+
await this.api.put("/api/user/updateDidSpace", { spaceGateway: e });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 指定要退出登录的设备 id
|
|
85
|
+
* 指定要退出登录的会话状态
|
|
86
|
+
* @param {{ visitorId: string, status: string }} { visitorId, status }
|
|
87
|
+
* @return {Promise<void>}
|
|
88
|
+
*/
|
|
89
|
+
async logout({ visitorId: e, status: t, includeFederated: o }) {
|
|
90
|
+
const r = this.token.getRefreshToken(), { data: s } = await this.api.post("/api/user/logout", {
|
|
91
|
+
visitorId: e,
|
|
92
|
+
status: t,
|
|
93
|
+
includeFederated: o,
|
|
94
|
+
refreshToken: r
|
|
95
|
+
});
|
|
96
|
+
return s;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 删除当前登录用户
|
|
100
|
+
* @return {Promise<{did: string}>}
|
|
101
|
+
*/
|
|
102
|
+
async destroyMyself() {
|
|
103
|
+
const { data: e } = await this.api.delete("/api/user");
|
|
104
|
+
return e;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* org 相关
|
|
108
|
+
*/
|
|
109
|
+
async getOrgs({ search: e = "", type: t = "", page: o = 1, pageSize: r = 20 }) {
|
|
110
|
+
const { data: s } = await this.api.get("/api/user/orgs", { params: {
|
|
111
|
+
search: e,
|
|
112
|
+
page: o,
|
|
113
|
+
pageSize: r,
|
|
114
|
+
type: t
|
|
115
|
+
} });
|
|
116
|
+
return s;
|
|
117
|
+
}
|
|
118
|
+
async getOrg(e) {
|
|
119
|
+
const { data: t } = await this.api.get(`/api/user/orgs/${e}`);
|
|
120
|
+
return t;
|
|
121
|
+
}
|
|
122
|
+
async createOrg(e) {
|
|
123
|
+
const { data: t } = await this.api.post("/api/user/orgs", { org: e });
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
async getRole(e) {
|
|
127
|
+
const { data: t } = await this.api.get("/api/user/role", { params: { name: e } });
|
|
128
|
+
return t;
|
|
129
|
+
}
|
|
130
|
+
async addResourceToOrg({ orgId: e, resourceId: t, type: o, metadata: r }) {
|
|
131
|
+
const { data: s } = await this.api.post(`/api/user/orgs/${e}/resources`, {
|
|
132
|
+
resourceId: t,
|
|
133
|
+
type: o,
|
|
134
|
+
metadata: r
|
|
135
|
+
});
|
|
136
|
+
return s;
|
|
137
|
+
}
|
|
138
|
+
async migrateResourceToOrg({ form: e, to: t, resourceId: o }) {
|
|
139
|
+
const { data: r } = await this.api.put(`/api/user/orgs/${e}/resources`, {
|
|
140
|
+
to: t,
|
|
141
|
+
resourceId: o
|
|
142
|
+
});
|
|
143
|
+
return r;
|
|
144
|
+
}
|
|
145
|
+
}, $ = class {
|
|
146
|
+
getSessionToken(e) {
|
|
147
|
+
return p.get(h) ? p.get(h) : e.sessionTokenKey ? window.localStorage.getItem(e.sessionTokenKey) : "";
|
|
148
|
+
}
|
|
149
|
+
setSessionToken(e) {
|
|
150
|
+
p.set(h, e);
|
|
151
|
+
}
|
|
152
|
+
removeSessionToken() {
|
|
153
|
+
p.remove(h);
|
|
154
|
+
}
|
|
155
|
+
getRefreshToken() {
|
|
156
|
+
return localStorage.getItem(y);
|
|
157
|
+
}
|
|
158
|
+
setRefreshToken(e) {
|
|
159
|
+
localStorage.setItem(y, e);
|
|
160
|
+
}
|
|
161
|
+
removeRefreshToken() {
|
|
162
|
+
localStorage.removeItem(y);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
let T;
|
|
166
|
+
function K() {
|
|
167
|
+
return T || (T = new I({
|
|
168
|
+
maxSize: 30,
|
|
169
|
+
maxAge: 60 * 1e3
|
|
170
|
+
})), T;
|
|
171
|
+
}
|
|
172
|
+
var R = class {
|
|
173
|
+
getBlocklet(e, t = !1) {
|
|
174
|
+
if (!e) {
|
|
175
|
+
if (typeof window > "u" || typeof document > "u") throw new Error("Cannot get blocklet in server side without baseUrl");
|
|
176
|
+
return window.blocklet;
|
|
177
|
+
}
|
|
178
|
+
const o = K();
|
|
179
|
+
if (!t && o.has(e)) return o.get(e);
|
|
180
|
+
const r = S(w(e, "__blocklet__.js"), {
|
|
181
|
+
type: "json",
|
|
182
|
+
t: Date.now()
|
|
183
|
+
});
|
|
184
|
+
return new Promise(async (s) => {
|
|
185
|
+
const n = await (await fetch(r)).json();
|
|
186
|
+
o.set(e, n), s(n);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
loadBlocklet() {
|
|
190
|
+
return new Promise((e, t) => {
|
|
191
|
+
if (typeof window > "u" || typeof document > "u") {
|
|
192
|
+
t();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const o = document.createElement("script");
|
|
196
|
+
let r = "/";
|
|
197
|
+
window.blocklet && window.blocklet.prefix && (r = window.blocklet.prefix), o.src = S(w(r, "__blocklet__.js"), { t: Date.now() }), o.onload = () => {
|
|
198
|
+
e();
|
|
199
|
+
}, o.onerror = () => {
|
|
200
|
+
t();
|
|
201
|
+
}, document.head.append(o);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
getPrefix(e) {
|
|
205
|
+
return e ? e?.prefix || "/" : typeof window > "u" || typeof document > "u" ? null : window.blocklet?.prefix || "/";
|
|
206
|
+
}
|
|
207
|
+
}, O = class {
|
|
208
|
+
constructor({ api: e, blocklet: t }) {
|
|
209
|
+
this.api = e, this.blocklet = t || new R();
|
|
210
|
+
}
|
|
211
|
+
getBaseUrl(e) {
|
|
212
|
+
return e ? w(e, k) : void 0;
|
|
213
|
+
}
|
|
214
|
+
async getUserSessions({ did: e, appUrl: t }) {
|
|
215
|
+
const o = this.getBaseUrl(t), r = await this.blocklet.getBlocklet(), { data: s } = await this.api.get("/api/user-session", {
|
|
216
|
+
baseURL: o,
|
|
217
|
+
params: {
|
|
218
|
+
userDid: e,
|
|
219
|
+
appPid: r.appPid
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return s;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 获取个人的所有登录会话
|
|
226
|
+
*/
|
|
227
|
+
async getMyLoginSessions({ appUrl: e } = {}, t = {
|
|
228
|
+
page: 1,
|
|
229
|
+
pageSize: 10
|
|
230
|
+
}) {
|
|
231
|
+
const o = this.getBaseUrl(e), { data: r } = await this.api.get("/api/user-session/myself", {
|
|
232
|
+
baseURL: o,
|
|
233
|
+
params: t
|
|
234
|
+
});
|
|
235
|
+
return r;
|
|
236
|
+
}
|
|
237
|
+
async loginByUserSession({ id: e, appPid: t, userDid: o, passportId: r, appUrl: s }) {
|
|
238
|
+
const n = this.getBaseUrl(s), { data: d } = await this.api.post("/api/user-session/login", {
|
|
239
|
+
id: e,
|
|
240
|
+
appPid: t,
|
|
241
|
+
userDid: o,
|
|
242
|
+
passportId: r
|
|
243
|
+
}, { baseURL: n });
|
|
244
|
+
return d;
|
|
245
|
+
}
|
|
246
|
+
}, M = class {
|
|
247
|
+
constructor({ blocklet: e = window?.blocklet } = {}) {
|
|
248
|
+
this.blocklet = e;
|
|
249
|
+
}
|
|
250
|
+
getComponent(e) {
|
|
251
|
+
return (this.blocklet?.componentMountPoints || []).find((t) => [
|
|
252
|
+
t.title,
|
|
253
|
+
t.name,
|
|
254
|
+
t.did
|
|
255
|
+
].includes(e));
|
|
256
|
+
}
|
|
257
|
+
getComponentMountPoint(e) {
|
|
258
|
+
return this.getComponent(e)?.mountPoint || "";
|
|
259
|
+
}
|
|
260
|
+
getUrl(e, ...t) {
|
|
261
|
+
const o = this.getComponentMountPoint(e);
|
|
262
|
+
return w(this.blocklet?.appUrl || "", o, ...t);
|
|
263
|
+
}
|
|
264
|
+
}, z = class {
|
|
265
|
+
constructor({ api: e, blocklet: t }) {
|
|
266
|
+
this.blockletDataCache = {}, this.api = e, this.blocklet = t || new R();
|
|
267
|
+
}
|
|
268
|
+
async getTrustedDomains() {
|
|
269
|
+
const { data: e } = await this.api.get("/api/federated/getTrustedDomains");
|
|
270
|
+
return e;
|
|
271
|
+
}
|
|
272
|
+
getMaster(e = this.blocklet.getBlocklet()) {
|
|
273
|
+
return e?.settings?.federated?.master;
|
|
274
|
+
}
|
|
275
|
+
getConfig(e = this.blocklet.getBlocklet()) {
|
|
276
|
+
return e?.settings?.federated?.config;
|
|
277
|
+
}
|
|
278
|
+
getFederatedEnabled(e = this.blocklet.getBlocklet()) {
|
|
279
|
+
return this.getConfig(e)?.status === "approved";
|
|
280
|
+
}
|
|
281
|
+
getSourceAppPid(e = this.blocklet.getBlocklet()) {
|
|
282
|
+
return this.getMaster(e)?.appPid;
|
|
283
|
+
}
|
|
284
|
+
getFederatedApp(e = this.blocklet.getBlocklet()) {
|
|
285
|
+
const t = this.getMaster(e);
|
|
286
|
+
return L(t) ? null : {
|
|
287
|
+
appId: t.appId,
|
|
288
|
+
appName: t.appName,
|
|
289
|
+
appDescription: t.appDescription,
|
|
290
|
+
appLogo: t.appLogo,
|
|
291
|
+
appPid: t.appPid,
|
|
292
|
+
appUrl: t.appUrl,
|
|
293
|
+
version: t.version,
|
|
294
|
+
sourceAppPid: t.appPid,
|
|
295
|
+
provider: "wallet"
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
getCurrentApp(e = this.blocklet.getBlocklet()) {
|
|
299
|
+
if (e) return {
|
|
300
|
+
appId: e.appId,
|
|
301
|
+
appName: e.appName,
|
|
302
|
+
appDescription: e.appDescription,
|
|
303
|
+
appLogo: e.appLogo,
|
|
304
|
+
appPid: e.appPid,
|
|
305
|
+
appUrl: e.appUrl,
|
|
306
|
+
version: e.version,
|
|
307
|
+
sourceAppPid: null,
|
|
308
|
+
provider: "wallet"
|
|
309
|
+
};
|
|
310
|
+
if (window.env) {
|
|
311
|
+
const t = window.env;
|
|
312
|
+
return {
|
|
313
|
+
appId: t.appId,
|
|
314
|
+
appName: t.appName,
|
|
315
|
+
appDescription: t.appDescription,
|
|
316
|
+
appUrl: t.baseUrl,
|
|
317
|
+
sourceAppPid: null,
|
|
318
|
+
provider: "wallet",
|
|
319
|
+
type: "server"
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
getApps(e = this.blocklet.getBlocklet()) {
|
|
325
|
+
const t = [], o = this.getFederatedApp(e), r = this.getCurrentApp(e), s = this.getFederatedEnabled(e);
|
|
326
|
+
return r && t.push(r), o && o?.appId !== r?.appId && s && t.push(o), t.reverse();
|
|
327
|
+
}
|
|
328
|
+
async getBlockletData(e, t = !1) {
|
|
329
|
+
if (!t && this.blockletDataCache[e]) return this.blockletDataCache[e];
|
|
330
|
+
try {
|
|
331
|
+
const o = new URL("__blocklet__.js", e);
|
|
332
|
+
o.searchParams.set("type", "json");
|
|
333
|
+
const r = await (await fetch(o.href)).json();
|
|
334
|
+
return this.blockletDataCache[e] = r, r;
|
|
335
|
+
} catch (o) {
|
|
336
|
+
return console.error(`Failed to get blocklet data: ${e}`, o), null;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}, W = "1.17.8";
|
|
340
|
+
const q = (e = 0) => new Promise((t) => {
|
|
341
|
+
setTimeout(() => {
|
|
342
|
+
t();
|
|
343
|
+
}, e);
|
|
344
|
+
}), D = (e) => `Bearer ${encodeURIComponent(e)}`, G = "vid", H = "__visitor_id", Q = () => p.get(G) || localStorage.getItem(H), V = async (e, t, o) => {
|
|
345
|
+
if (F(e.data) && e.status >= 200 && e.status < 300 && typeof window < "u" && window.blocklet?.appId && window.blocklet?.appPk) {
|
|
346
|
+
if (!o) return e;
|
|
347
|
+
if (!e.data.$signature)
|
|
348
|
+
throw t(), new Error("Invalid response");
|
|
349
|
+
const { appId: r, appPk: s } = window.blocklet;
|
|
350
|
+
if (await o(j(A(e.data, ["$signature"])), e.data.$signature, s, r) === !1)
|
|
351
|
+
throw t(), new Error("Invalid response");
|
|
352
|
+
}
|
|
353
|
+
return e;
|
|
354
|
+
};
|
|
355
|
+
function b() {
|
|
356
|
+
return p.get("x-csrf-token");
|
|
357
|
+
}
|
|
358
|
+
function U() {
|
|
359
|
+
return p.get("login_token");
|
|
360
|
+
}
|
|
361
|
+
async function Y() {
|
|
362
|
+
const e = b();
|
|
363
|
+
try {
|
|
364
|
+
const t = w(window.location.origin, k, "/api/did/csrfToken"), { data: o } = await C.get(t, { headers: { "x-csrf-token": e } });
|
|
365
|
+
return o;
|
|
366
|
+
} catch (t) {
|
|
367
|
+
return console.error(t), {
|
|
368
|
+
loginToken: U(),
|
|
369
|
+
csrfToken: null
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
let v;
|
|
374
|
+
function X() {
|
|
375
|
+
if (!v) {
|
|
376
|
+
const e = window?.blocklet?.settings?.session?.cacheTtl;
|
|
377
|
+
v = new B({
|
|
378
|
+
store: new E(),
|
|
379
|
+
ttl: x(e) ? e * 1e3 : 1e3 * 60 * 60
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return v;
|
|
383
|
+
}
|
|
384
|
+
async function P(e, t = 300) {
|
|
385
|
+
e.metaData.endTime = +/* @__PURE__ */ new Date();
|
|
386
|
+
const { startTime: o, endTime: r } = e.metaData, s = r - o;
|
|
387
|
+
s < t && await q(t - s), delete e.metaData;
|
|
388
|
+
}
|
|
389
|
+
const _ = (e, t) => {
|
|
390
|
+
const o = {
|
|
391
|
+
...e?.headers,
|
|
392
|
+
"x-blocklet-js-sdk-version": W
|
|
393
|
+
}, r = new M(), s = C.create({
|
|
394
|
+
...e,
|
|
395
|
+
headers: o
|
|
396
|
+
});
|
|
397
|
+
return t?.lazy && (s.interceptors.request.use((n) => (n.metaData = { startTime: +/* @__PURE__ */ new Date() }, n), (n) => Promise.reject(n)), s.interceptors.response.use(async (n) => (n.config && await P(n.config, t?.lazyTime), n), async (n) => (n.response && await P(n.response.config, t?.lazyTime), Promise.reject(n)))), s.interceptors.request.use(async (n) => {
|
|
398
|
+
const d = t?.componentDid ?? window.blocklet?.componentId?.split("/").pop();
|
|
399
|
+
n.baseURL = n.baseURL || r.getComponentMountPoint(d), n.timeout = n.timeout || 20 * 1e3;
|
|
400
|
+
const f = U(), m = b();
|
|
401
|
+
if (f && m) {
|
|
402
|
+
const l = f.slice(-32), u = X(), i = await u.get(l);
|
|
403
|
+
if (i) n.headers["x-csrf-token"] = i;
|
|
404
|
+
else {
|
|
405
|
+
const { loginToken: a, csrfToken: c } = await Y();
|
|
406
|
+
c ? (await u.set(a.slice(-32), c), n.headers["x-csrf-token"] = c) : n.headers["x-csrf-token"] = m;
|
|
407
|
+
}
|
|
408
|
+
n.headers["x-csrf-token"] && n.headers["x-csrf-token"] !== b() && p.set("x-csrf-token", n.headers["x-csrf-token"], {
|
|
409
|
+
sameSite: "strict",
|
|
410
|
+
secure: !0
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
const g = Q();
|
|
414
|
+
return [void 0, null].includes(g) || (n.headers["x-blocklet-visitor-id"] = g), n;
|
|
415
|
+
}, (n) => Promise.reject(n)), s;
|
|
416
|
+
};
|
|
417
|
+
async function J(e) {
|
|
418
|
+
if (!e) throw new Error("Refresh token not found");
|
|
419
|
+
const { data: t } = await _({
|
|
420
|
+
baseURL: k,
|
|
421
|
+
timeout: 10 * 1e3,
|
|
422
|
+
secure: !0,
|
|
423
|
+
headers: { authorization: D(e) }
|
|
424
|
+
}).post("/api/did/refreshSession");
|
|
425
|
+
return t;
|
|
426
|
+
}
|
|
427
|
+
function Z({ getSessionToken: e, setSessionToken: t, removeSessionToken: o, getRefreshToken: r, setRefreshToken: s, removeRefreshToken: n, onRefreshTokenError: d, onRefreshTokenSuccess: f }, m, g) {
|
|
428
|
+
let l = null;
|
|
429
|
+
const u = _({
|
|
430
|
+
timeout: 30 * 1e3,
|
|
431
|
+
...m
|
|
432
|
+
}, g);
|
|
433
|
+
return u.interceptors.request.use(async (i) => {
|
|
434
|
+
if (!p.get(h)) {
|
|
435
|
+
const a = e(i);
|
|
436
|
+
a && (i.headers.authorization = D(a));
|
|
437
|
+
}
|
|
438
|
+
return l && await l, i;
|
|
439
|
+
}, (i) => Promise.reject(i)), u.interceptors.response.use(async (i) => i.config?.secure ? await V(i, () => {
|
|
440
|
+
o(), n();
|
|
441
|
+
}, g?.verifyFn) : i, async (i) => {
|
|
442
|
+
const a = i.config;
|
|
443
|
+
if (a && (a.headers = a?.headers ? { ...a.headers } : {}, i?.response?.status === 401 && !a._retry)) {
|
|
444
|
+
a._retry = !0;
|
|
445
|
+
try {
|
|
446
|
+
l || (l = J(r()));
|
|
447
|
+
const c = await l;
|
|
448
|
+
return t(c.nextToken), s(c.nextRefreshToken), typeof f == "function" && f(c), u(a);
|
|
449
|
+
} catch (c) {
|
|
450
|
+
return o(), n(), typeof d == "function" && d(c), Promise.reject(i);
|
|
451
|
+
} finally {
|
|
452
|
+
l = null;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return Promise.reject(i);
|
|
456
|
+
}), u;
|
|
457
|
+
}
|
|
458
|
+
var ee = class {
|
|
459
|
+
constructor(e) {
|
|
460
|
+
const t = new $(), o = Z({
|
|
461
|
+
getSessionToken: t.getSessionToken,
|
|
462
|
+
setSessionToken: t.setSessionToken,
|
|
463
|
+
removeSessionToken: t.removeSessionToken,
|
|
464
|
+
getRefreshToken: t.getRefreshToken,
|
|
465
|
+
setRefreshToken: t.setRefreshToken,
|
|
466
|
+
removeRefreshToken: t.removeRefreshToken,
|
|
467
|
+
onRefreshTokenError: () => {
|
|
468
|
+
console.error("Failed to refresh token");
|
|
469
|
+
},
|
|
470
|
+
onRefreshTokenSuccess: () => {
|
|
471
|
+
}
|
|
472
|
+
}, { baseURL: k }, { verifyFn: e?.verifyFn }), r = new R();
|
|
473
|
+
this.user = new N({
|
|
474
|
+
api: o,
|
|
475
|
+
token: t
|
|
476
|
+
}), this.federated = new z({
|
|
477
|
+
api: o,
|
|
478
|
+
blocklet: r
|
|
479
|
+
}), this.userSession = new O({
|
|
480
|
+
api: o,
|
|
481
|
+
blocklet: r
|
|
482
|
+
}), this.token = t, this.blocklet = r, this.api = o;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
const ge = /* @__PURE__ */ (() => {
|
|
486
|
+
let e;
|
|
487
|
+
return (t) => (e || (e = new ee(t)), e);
|
|
488
|
+
})();
|
|
489
|
+
export {
|
|
490
|
+
ee as BlockletSDK,
|
|
491
|
+
ge as getBlockletSDK,
|
|
492
|
+
b as getCSRFToken,
|
|
493
|
+
Y as getCSRFTokenByLoginToken,
|
|
494
|
+
U as getLoginToken
|
|
495
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.2",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@abtnode/constant": "^1.17.
|
|
38
|
-
"@abtnode/util": "^1.17.
|
|
39
|
-
"@arcblock/bridge": "3.5.
|
|
40
|
-
"@arcblock/icons": "3.5.
|
|
41
|
-
"@arcblock/react-hooks": "3.5.
|
|
42
|
-
"@arcblock/ws": "^1.29.
|
|
43
|
-
"@blocklet/did-space-react": "^1.2.
|
|
37
|
+
"@abtnode/constant": "^1.17.9",
|
|
38
|
+
"@abtnode/util": "^1.17.9",
|
|
39
|
+
"@arcblock/bridge": "3.5.2",
|
|
40
|
+
"@arcblock/icons": "3.5.2",
|
|
41
|
+
"@arcblock/react-hooks": "3.5.2",
|
|
42
|
+
"@arcblock/ws": "^1.29.8",
|
|
43
|
+
"@blocklet/did-space-react": "^1.2.16",
|
|
44
44
|
"@blocklet/uploader": "^0.3.19",
|
|
45
45
|
"@iconify-icons/logos": "^1.2.36",
|
|
46
46
|
"@iconify-icons/material-symbols": "^1.2.58",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"access": "public"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@arcblock/did-connect-react": "3.5.
|
|
90
|
+
"@arcblock/did-connect-react": "3.5.2",
|
|
91
91
|
"@babel/preset-env": "^7.28.0",
|
|
92
92
|
"@babel/preset-react": "^7.27.1",
|
|
93
93
|
"@babel/preset-typescript": "^7.27.1",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"typescript": "~5.5.4",
|
|
102
102
|
"unbuild": "^2.0.0"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "2f6a2770fb95e0b8202de2973d9753be080260af"
|
|
105
105
|
}
|