@arcblock/ux 3.5.0 → 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/Dialog/dialog.d.ts +27 -0
- package/lib/Img/index.d.ts +6 -0
- package/lib/OrgTransfer/selector.js +1 -1
- package/lib/UserCard/use-follow.js +1 -1
- package/lib/UserCard/utils.js +1 -1
- package/lib/Util/constant.d.ts +1 -9
- package/lib/Util/index.js +1 -1
- package/lib/node_modules/@blocklet/js-sdk/dist/index.js +495 -0
- package/lib/{package.json.js → packages/ux/package.json.js} +1 -1
- package/package.json +10 -10
package/lib/Dialog/dialog.d.ts
CHANGED
|
@@ -6,34 +6,58 @@ export type PaperStyle = import('@mui/material').PaperProps & {
|
|
|
6
6
|
minHeight?: number | string;
|
|
7
7
|
};
|
|
8
8
|
export type UxDialogProps = {
|
|
9
|
+
/**
|
|
10
|
+
* - The content of the dialog.
|
|
11
|
+
*/
|
|
9
12
|
/**
|
|
10
13
|
* - The content of the dialog.
|
|
11
14
|
*/
|
|
12
15
|
children: React.ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* - The title of the dialog.
|
|
18
|
+
*/
|
|
13
19
|
/**
|
|
14
20
|
* - The title of the dialog.
|
|
15
21
|
*/
|
|
16
22
|
title?: React.ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* - Content to be displayed before the dialog title.
|
|
25
|
+
*/
|
|
17
26
|
/**
|
|
18
27
|
* - Content to be displayed before the dialog title.
|
|
19
28
|
*/
|
|
20
29
|
prepend?: React.ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* - Content to be displayed in the top toolbar of the dialog.
|
|
32
|
+
*/
|
|
21
33
|
/**
|
|
22
34
|
* - Content to be displayed in the top toolbar of the dialog.
|
|
23
35
|
*/
|
|
24
36
|
toolbar?: React.ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* - Content to be displayed in the bottom actions toolbar of the dialog.
|
|
39
|
+
*/
|
|
25
40
|
/**
|
|
26
41
|
* - Content to be displayed in the bottom actions toolbar of the dialog.
|
|
27
42
|
*/
|
|
28
43
|
actions?: React.ReactNode;
|
|
44
|
+
/**
|
|
45
|
+
* - Whether or not to show the close button.
|
|
46
|
+
*/
|
|
29
47
|
/**
|
|
30
48
|
* - Whether or not to show the close button.
|
|
31
49
|
*/
|
|
32
50
|
showCloseButton?: boolean | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* - The position of the actions toolbar.
|
|
53
|
+
*/
|
|
33
54
|
/**
|
|
34
55
|
* - The position of the actions toolbar.
|
|
35
56
|
*/
|
|
36
57
|
actionsPosition?: "left" | "right" | "center" | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* - Props to be passed down to the dialog paper.
|
|
60
|
+
*/
|
|
37
61
|
/**
|
|
38
62
|
* - Props to be passed down to the dialog paper.
|
|
39
63
|
*/
|
|
@@ -41,6 +65,9 @@ export type UxDialogProps = {
|
|
|
41
65
|
slotProps?: {
|
|
42
66
|
content: object;
|
|
43
67
|
} | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* - Callback function fired when the dialog is closed.
|
|
70
|
+
*/
|
|
44
71
|
/**
|
|
45
72
|
* - Callback function fired when the dialog is closed.
|
|
46
73
|
*/
|
package/lib/Img/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { default as PropTypes } from 'prop-types';
|
|
2
2
|
export default Img;
|
|
3
3
|
export type ImgExProps = {
|
|
4
|
+
/**
|
|
5
|
+
* - required
|
|
6
|
+
*/
|
|
4
7
|
/**
|
|
5
8
|
* - required
|
|
6
9
|
*/
|
|
@@ -16,6 +19,9 @@ export type ImgExProps = {
|
|
|
16
19
|
lazy?: boolean | undefined;
|
|
17
20
|
placeholder?: string | undefined;
|
|
18
21
|
fallback?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* - 是否使用代理 fallback, 用于解决 CSP 的问题
|
|
24
|
+
*/
|
|
19
25
|
/**
|
|
20
26
|
* - 是否使用代理 fallback, 用于解决 CSP 的问题
|
|
21
27
|
*/
|
|
@@ -2,7 +2,7 @@ import { jsx as n, jsxs as i, Fragment as y } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState as F, useImperativeHandle as _, createElement as b } from "react";
|
|
3
3
|
import { useMemoizedFn as p, useReactive as q, useDebounce as G, useInfiniteScroll as H } from "ahooks";
|
|
4
4
|
import { Box as l, Typography as a, Autocomplete as N, CircularProgress as v, TextField as K, Button as w } from "@mui/material";
|
|
5
|
-
import { getBlockletSDK as Q } from "
|
|
5
|
+
import { getBlockletSDK as Q } from "../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
6
6
|
import T from "../Toast/index.js";
|
|
7
7
|
import Z from "../Dialog/dialog.js";
|
|
8
8
|
import "../Dialog/confirm.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState as y, useMemo as u, useEffect as F } from "react";
|
|
2
2
|
import { useMemoizedFn as f } from "ahooks";
|
|
3
3
|
import U from "lodash/isNil";
|
|
4
|
-
import { getBlockletSDK as D } from "
|
|
4
|
+
import { getBlockletSDK as D } from "../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
5
5
|
import a from "../Toast/index.js";
|
|
6
6
|
import { formatAxiosError as d } from "../Util/index.js";
|
|
7
7
|
function K({
|
package/lib/UserCard/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toTypeInfo as c } from "@arcblock/did";
|
|
2
2
|
import { types as i } from "@ocap/mcrypto";
|
|
3
|
-
import { getBlockletSDK as l } from "
|
|
3
|
+
import { getBlockletSDK as l } from "../node_modules/@blocklet/js-sdk/dist/index.js";
|
|
4
4
|
let s = null;
|
|
5
5
|
const n = "ux_user_", u = 60 * 60 * 1e3, f = (e) => {
|
|
6
6
|
if (typeof sessionStorage > "u") return null;
|
package/lib/Util/constant.d.ts
CHANGED
|
@@ -26,15 +26,7 @@ export declare const LOGIN_PROVIDER: {
|
|
|
26
26
|
TWITTER: string;
|
|
27
27
|
};
|
|
28
28
|
export declare const LOGIN_PROVIDER_NAME: {
|
|
29
|
-
[
|
|
30
|
-
[LOGIN_PROVIDER.AUTH0]: string;
|
|
31
|
-
[LOGIN_PROVIDER.APPLE]: string;
|
|
32
|
-
[LOGIN_PROVIDER.GITHUB]: string;
|
|
33
|
-
[LOGIN_PROVIDER.GOOGLE]: string;
|
|
34
|
-
[LOGIN_PROVIDER.WALLET]: string;
|
|
35
|
-
[LOGIN_PROVIDER.NFT]: string;
|
|
36
|
-
[LOGIN_PROVIDER.PASSKEY]: string;
|
|
37
|
-
[LOGIN_PROVIDER.TWITTER]: string;
|
|
29
|
+
[x: string]: string;
|
|
38
30
|
federated: string;
|
|
39
31
|
};
|
|
40
32
|
export declare const LOGIN_PROVIDER_ICON_SIZE = 16;
|
package/lib/Util/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import W from "dayjs/plugin/updateLocale";
|
|
|
17
17
|
import P from "dayjs/plugin/localizedFormat";
|
|
18
18
|
import L from "semver";
|
|
19
19
|
import { DID_PREFIX as C, BLOCKLET_SERVICE_PATH_PREFIX as M } from "./constant.js";
|
|
20
|
-
import b from "../package.json.js";
|
|
20
|
+
import b from "../packages/ux/package.json.js";
|
|
21
21
|
import { getFederatedEnabled as _ } from "./federated.js";
|
|
22
22
|
let u = null;
|
|
23
23
|
const N = /^(\d{1,3}\.){3}\d{1,3}(:\d+)?$/, z = /* @__PURE__ */ new Set(["co", "com", "net", "org", "gov", "edu", "ac"]), B = /* @__PURE__ */ new Set(["uk", "au", "cn", "nz", "za", "in", "br", "mx", "fr", "it", "ca"]);
|
|
@@ -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": "@arcblock/ux",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.2",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -77,16 +77,16 @@
|
|
|
77
77
|
"react": "^19.0.0",
|
|
78
78
|
"react-router-dom": "^6.22.3"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "2f6a2770fb95e0b8202de2973d9753be080260af",
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@arcblock/bridge": "3.5.
|
|
83
|
-
"@arcblock/did": "^1.29.
|
|
82
|
+
"@arcblock/bridge": "3.5.2",
|
|
83
|
+
"@arcblock/did": "^1.29.8",
|
|
84
84
|
"@arcblock/did-motif": "^1.1.14",
|
|
85
|
-
"@arcblock/icons": "3.5.
|
|
86
|
-
"@arcblock/nft-display": "3.5.
|
|
87
|
-
"@arcblock/react-hooks": "3.5.
|
|
88
|
-
"@blocklet/js-sdk": "^1.17.
|
|
89
|
-
"@blocklet/theme": "3.5.
|
|
85
|
+
"@arcblock/icons": "3.5.2",
|
|
86
|
+
"@arcblock/nft-display": "3.5.2",
|
|
87
|
+
"@arcblock/react-hooks": "3.5.2",
|
|
88
|
+
"@blocklet/js-sdk": "^1.17.9",
|
|
89
|
+
"@blocklet/theme": "3.5.2",
|
|
90
90
|
"@fontsource/roboto": "~5.1.1",
|
|
91
91
|
"@fontsource/ubuntu-mono": "^5.2.6",
|
|
92
92
|
"@iconify-icons/logos": "^1.2.36",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@iconify-icons/mdi": "^1.2.48",
|
|
95
95
|
"@iconify-icons/tabler": "^1.2.95",
|
|
96
96
|
"@iconify/react": "^5.2.1",
|
|
97
|
-
"@ocap/mcrypto": "^1.29.
|
|
97
|
+
"@ocap/mcrypto": "^1.29.8",
|
|
98
98
|
"@solana/qr-code-styling": "^1.6.0",
|
|
99
99
|
"@types/dompurify": "^3.2.0",
|
|
100
100
|
"@types/mui-datatables": "^4.3.12",
|