@blocklet/ui-react 2.9.51 → 2.9.53

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 (112) hide show
  1. package/es/@types/index.d.ts +3 -5
  2. package/es/Dashboard/index.d.ts +5 -6
  3. package/es/Dashboard/index.js +5 -5
  4. package/es/Footer/index.js +2 -2
  5. package/es/Header/index.js +5 -5
  6. package/es/UserCenter/components/notification.js +1 -1
  7. package/es/UserCenter/components/passport.js +1 -2
  8. package/es/UserCenter/components/privacy.js +1 -1
  9. package/es/UserCenter/components/settings.js +9 -1
  10. package/es/UserCenter/components/storage/connect-to.d.ts +1 -1
  11. package/es/UserCenter/components/storage/connect-to.js +9 -3
  12. package/es/UserCenter/components/storage/connected.d.ts +1 -1
  13. package/es/UserCenter/components/storage/connected.js +5 -2
  14. package/es/UserCenter/components/storage/delete.d.ts +1 -1
  15. package/es/UserCenter/components/storage/delete.js +4 -1
  16. package/es/UserCenter/components/storage/index.js +4 -2
  17. package/es/UserCenter/components/storage/item.js +7 -12
  18. package/es/UserCenter/components/user-center.d.ts +2 -2
  19. package/es/UserCenter/components/user-center.js +15 -6
  20. package/es/UserCenter/libs/locales.d.ts +54 -0
  21. package/es/UserCenter/libs/locales.js +56 -2
  22. package/es/UserSessions/components/user-session-info.d.ts +6 -0
  23. package/es/UserSessions/components/user-session-info.js +58 -0
  24. package/es/UserSessions/components/user-sessions.d.ts +9 -0
  25. package/es/UserSessions/components/user-sessions.js +255 -0
  26. package/es/UserSessions/index.d.ts +1 -0
  27. package/es/UserSessions/index.js +1 -0
  28. package/es/UserSessions/libs/locales.d.ts +52 -0
  29. package/es/UserSessions/libs/locales.js +52 -0
  30. package/es/UserSessions/libs/utils.d.ts +2 -0
  31. package/es/UserSessions/libs/utils.js +73 -0
  32. package/es/blocklets.js +6 -6
  33. package/es/common/header-addons.d.ts +3 -4
  34. package/es/common/header-addons.js +4 -4
  35. package/es/contexts/config-user-space.js +2 -2
  36. package/es/index.d.ts +1 -0
  37. package/es/index.js +1 -0
  38. package/es/types.d.ts +2 -2
  39. package/es/types.js +2 -2
  40. package/lib/@types/index.d.ts +3 -5
  41. package/lib/Dashboard/index.d.ts +5 -6
  42. package/lib/Dashboard/index.js +4 -4
  43. package/lib/Footer/index.js +1 -1
  44. package/lib/Header/index.js +4 -4
  45. package/lib/UserCenter/components/notification.js +1 -1
  46. package/lib/UserCenter/components/passport.js +1 -2
  47. package/lib/UserCenter/components/privacy.js +1 -1
  48. package/lib/UserCenter/components/settings.js +10 -1
  49. package/lib/UserCenter/components/storage/connect-to.d.ts +1 -1
  50. package/lib/UserCenter/components/storage/connect-to.js +3 -3
  51. package/lib/UserCenter/components/storage/connected.d.ts +1 -1
  52. package/lib/UserCenter/components/storage/connected.js +1 -1
  53. package/lib/UserCenter/components/storage/delete.d.ts +1 -1
  54. package/lib/UserCenter/components/storage/index.js +22 -17
  55. package/lib/UserCenter/components/storage/item.js +1 -13
  56. package/lib/UserCenter/components/user-center.d.ts +2 -2
  57. package/lib/UserCenter/components/user-center.js +20 -10
  58. package/lib/UserCenter/libs/locales.d.ts +54 -0
  59. package/lib/UserCenter/libs/locales.js +56 -2
  60. package/lib/UserSessions/components/user-session-info.d.ts +6 -0
  61. package/lib/UserSessions/components/user-session-info.js +68 -0
  62. package/lib/UserSessions/components/user-sessions.d.ts +9 -0
  63. package/lib/UserSessions/components/user-sessions.js +282 -0
  64. package/lib/UserSessions/index.d.ts +1 -0
  65. package/lib/UserSessions/index.js +13 -0
  66. package/lib/UserSessions/libs/locales.d.ts +52 -0
  67. package/lib/UserSessions/libs/locales.js +58 -0
  68. package/lib/UserSessions/libs/utils.d.ts +2 -0
  69. package/lib/UserSessions/libs/utils.js +80 -0
  70. package/lib/blocklets.js +6 -6
  71. package/lib/common/header-addons.d.ts +3 -4
  72. package/lib/common/header-addons.js +3 -3
  73. package/lib/contexts/config-user-space.js +1 -1
  74. package/lib/index.d.ts +1 -0
  75. package/lib/index.js +12 -0
  76. package/lib/types.d.ts +2 -2
  77. package/lib/types.js +3 -3
  78. package/package.json +14 -6
  79. package/src/@types/index.ts +3 -5
  80. package/src/Dashboard/index.jsx +7 -3
  81. package/src/Footer/index.jsx +2 -2
  82. package/src/Header/index.jsx +5 -3
  83. package/src/Icon/index.jsx +1 -0
  84. package/src/UserCenter/components/notification.tsx +2 -2
  85. package/src/UserCenter/components/passport.tsx +1 -2
  86. package/src/UserCenter/components/privacy.tsx +1 -1
  87. package/src/UserCenter/components/settings.tsx +15 -2
  88. package/src/UserCenter/components/storage/connect-to.tsx +17 -11
  89. package/src/UserCenter/components/storage/connected.tsx +9 -3
  90. package/src/UserCenter/components/storage/delete.tsx +8 -2
  91. package/src/UserCenter/components/storage/index.tsx +17 -13
  92. package/src/UserCenter/components/storage/item.tsx +8 -15
  93. package/src/UserCenter/components/storage/preview-nft.tsx +1 -1
  94. package/src/UserCenter/components/user-center.tsx +21 -14
  95. package/src/UserCenter/components/webhook-item.tsx +1 -1
  96. package/src/UserCenter/libs/locales.ts +54 -0
  97. package/src/UserSessions/components/user-session-info.tsx +52 -0
  98. package/src/UserSessions/components/user-sessions.tsx +276 -0
  99. package/src/UserSessions/index.tsx +1 -0
  100. package/src/UserSessions/libs/locales.ts +52 -0
  101. package/src/UserSessions/libs/utils.ts +82 -0
  102. package/src/blocklets.js +6 -6
  103. package/src/common/header-addons.jsx +2 -2
  104. package/src/contexts/config-user-space.tsx +12 -11
  105. package/src/index.ts +1 -0
  106. package/src/{UserCenter/libs → libs}/client.ts +1 -0
  107. package/src/libs/spaces.tsx +2 -2
  108. package/src/types.js +2 -2
  109. /package/es/{UserCenter/libs → libs}/client.d.ts +0 -0
  110. /package/es/{UserCenter/libs → libs}/client.js +0 -0
  111. /package/lib/{UserCenter/libs → libs}/client.d.ts +0 -0
  112. /package/lib/{UserCenter/libs → libs}/client.js +0 -0
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = UserSessions;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _Datatable = _interopRequireDefault(require("@arcblock/ux/lib/Datatable"));
9
+ var _ahooks = require("ahooks");
10
+ var _util = require("@arcblock/ux/lib/Locale/util");
11
+ var _context = require("@arcblock/ux/lib/Locale/context");
12
+ var _RelativeTime = _interopRequireDefault(require("@arcblock/ux/lib/RelativeTime"));
13
+ var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
14
+ var _uaParserJs = _interopRequireDefault(require("ua-parser-js"));
15
+ var _Util = require("@arcblock/ux/lib/Util");
16
+ var _Dialog = require("@arcblock/ux/lib/Dialog");
17
+ var _pAll = _interopRequireDefault(require("p-all"));
18
+ var _material = require("@mui/material");
19
+ var _userSessionInfo = _interopRequireDefault(require("./user-session-info"));
20
+ var _client = require("../../libs/client");
21
+ var _locales = require("../libs/locales");
22
+ var _utils = require("../libs/utils");
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+ const parseUa = ua => {
25
+ const parser = new _uaParserJs.default(ua, {
26
+ // eslint-disable-next-line no-useless-escape
27
+ browser: [[/(ArcWallet)\/([\w\.]+)/i], [_uaParserJs.default.BROWSER.NAME, _uaParserJs.default.BROWSER.VERSION]]
28
+ });
29
+ const result = parser.getResult();
30
+ return result;
31
+ };
32
+ function UserSessions({
33
+ user,
34
+ showAction = true,
35
+ showUser = true
36
+ }) {
37
+ const currentVisitorId = (0, _Util.getVisitorId)();
38
+ const {
39
+ locale
40
+ } = (0, _context.useLocaleContext)();
41
+ const {
42
+ confirmApi,
43
+ confirmHolder
44
+ } = (0, _Dialog.useConfirm)();
45
+ const t = (0, _ahooks.useMemoizedFn)((key, data = {}) => {
46
+ return (0, _util.translate)(_locales.translations, key, locale, "en", data);
47
+ });
48
+ const getData = (0, _ahooks.useMemoizedFn)(async () => {
49
+ let data = user?.userSessions;
50
+ if (!data) {
51
+ data = await _client.client.userSession.getUserSessions({
52
+ did: user.did
53
+ });
54
+ }
55
+ try {
56
+ const ipIndexList = data?.map((x, index) => [index, x.lastLoginIp]).filter(x => !!x[1]);
57
+ const ipList = ipIndexList?.map(x => x[1]);
58
+ const result = await (0, _utils.batchIp2Region)(ipList);
59
+ for (let index = 0; index < result.length; index++) {
60
+ const x = result[index];
61
+ const ipIndexItem = ipIndexList[index];
62
+ const dataItem = data[ipIndexItem[0]];
63
+ dataItem.ipRegion = x;
64
+ }
65
+ } catch (e) {
66
+ console.warn("Failed to convert ip to region");
67
+ console.error(e);
68
+ }
69
+ const now = /* @__PURE__ */new Date().getTime();
70
+ return (0, _sortBy.default)(data, x => {
71
+ if (x.visitorId === currentVisitorId) {
72
+ return -1;
73
+ }
74
+ return now - new Date(x.updatedAt).getTime();
75
+ });
76
+ });
77
+ const pageState = (0, _ahooks.useRequest)(getData);
78
+ const safeData = (0, _ahooks.useCreation)(() => {
79
+ return pageState.data || [];
80
+ }, [pageState.data]);
81
+ const ipRegionMap = (0, _ahooks.useCreation)(() => {
82
+ return safeData.reduce((acc, x) => {
83
+ acc[x.lastLoginIp] = x.ipRegion;
84
+ return acc;
85
+ }, {});
86
+ }, [safeData]);
87
+ const logout = (0, _ahooks.useMemoizedFn)(({
88
+ visitorId
89
+ }) => {
90
+ confirmApi.open({
91
+ title: t("logoutThisSession"),
92
+ content: t("logoutThisSessionConfirm"),
93
+ confirmButtonText: t("confirm"),
94
+ cancelButtonText: t("cancel"),
95
+ onConfirm: async () => {
96
+ await _client.client.user.logout({
97
+ visitorId
98
+ });
99
+ pageState.refresh();
100
+ confirmApi.close();
101
+ }
102
+ });
103
+ });
104
+ const otherUserSessions = (0, _ahooks.useCreation)(() => {
105
+ const list = safeData.filter(x => x.visitorId !== currentVisitorId);
106
+ return list;
107
+ }, [safeData]);
108
+ const logoutAll = (0, _ahooks.useMemoizedFn)(() => {
109
+ confirmApi.open({
110
+ title: t("logoutAllSession"),
111
+ content: t("logoutAllSessionConfirm"),
112
+ confirmButtonText: t("confirm"),
113
+ cancelButtonText: t("cancel"),
114
+ onConfirm: async () => {
115
+ const list = otherUserSessions.map(x => {
116
+ return () => _client.client.user.logout({
117
+ visitorId: x.visitorId
118
+ });
119
+ });
120
+ await (0, _pAll.default)(list, {
121
+ concurrency: 3,
122
+ stopOnError: false
123
+ });
124
+ pageState.refresh();
125
+ confirmApi.close();
126
+ }
127
+ });
128
+ });
129
+ const customButtons = [];
130
+ if (showAction) {
131
+ customButtons.push( /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Tooltip, {
132
+ title: t("logoutAllTips"),
133
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
134
+ sx: {
135
+ ml: 0.5
136
+ },
137
+ size: "small",
138
+ variant: "contained",
139
+ color: "error",
140
+ onClick: logoutAll,
141
+ disabled: otherUserSessions.length === 0,
142
+ children: t("logoutAll")
143
+ })
144
+ }, "logoutAll"));
145
+ }
146
+ const tableOptions = (0, _ahooks.useCreation)(() => {
147
+ return {
148
+ // viewColumns: false,
149
+ search: false,
150
+ sort: false,
151
+ download: false,
152
+ filter: false,
153
+ print: false,
154
+ expandableRowsOnClick: false,
155
+ searchDebounceTime: 600
156
+ };
157
+ }, []);
158
+ const columns = [{
159
+ label: t("platform"),
160
+ name: "platform",
161
+ options: {
162
+ customBodyRenderLite: rawIndex => {
163
+ const x = safeData[rawIndex];
164
+ const result = parseUa(x.ua);
165
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
166
+ children: [result.os?.name, result.os?.version].filter(Boolean).join("/") || t("unknown")
167
+ });
168
+ }
169
+ }
170
+ }, {
171
+ label: t("deviceType"),
172
+ name: "deviceType",
173
+ options: {
174
+ customBodyRenderLite: rawIndex => {
175
+ const x = safeData[rawIndex];
176
+ const result = parseUa(x.ua);
177
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
178
+ children: [result.browser?.name, result.browser?.version].filter(Boolean).join("/") || t("unknown")
179
+ });
180
+ }
181
+ }
182
+ }, {
183
+ label: t("walletOS"),
184
+ name: "walletOS",
185
+ options: {
186
+ customBodyRenderLite: rawIndex => {
187
+ const x = safeData[rawIndex];
188
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
189
+ children: x.extra?.walletOS || t("unknown")
190
+ });
191
+ }
192
+ }
193
+ }, showUser && {
194
+ label: t("user"),
195
+ name: "user",
196
+ options: {
197
+ customBodyRenderLite: rawIndex => {
198
+ const x = safeData[rawIndex];
199
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_userSessionInfo.default, {
200
+ sessionUser: x.user,
201
+ user
202
+ });
203
+ }
204
+ }
205
+ }, {
206
+ label: t("updatedAt"),
207
+ name: "updatedAt",
208
+ options: {
209
+ customBodyRenderLite: rawIndex => {
210
+ const x = safeData[rawIndex];
211
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_RelativeTime.default, {
212
+ value: x.updatedAt,
213
+ relativeRange: 3 * 86400 * 1e3,
214
+ locale
215
+ });
216
+ }
217
+ }
218
+ }, {
219
+ label: t("lastLoginIp"),
220
+ name: "lastLoginIp",
221
+ options: {
222
+ customBodyRenderLite: rawIndex => {
223
+ const x = safeData[rawIndex];
224
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
225
+ children: ipRegionMap[x.lastLoginIp] ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
226
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
227
+ variant: "body2",
228
+ children: ipRegionMap[x.lastLoginIp]
229
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
230
+ variant: "body2",
231
+ color: "grey",
232
+ children: x.lastLoginIp || t("unknown")
233
+ })]
234
+ }) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
235
+ children: x.lastLoginIp || t("unknown")
236
+ })
237
+ });
238
+ }
239
+ }
240
+ }, showAction && {
241
+ label: t("actions"),
242
+ name: "actions",
243
+ options: {
244
+ customBodyRenderLite: rawIndex => {
245
+ const x = safeData[rawIndex];
246
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
247
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
248
+ sx: {
249
+ whiteSpace: "nowrap",
250
+ fontSize: "12px",
251
+ px: 1
252
+ },
253
+ disabled: currentVisitorId === x.visitorId,
254
+ variant: "outlined",
255
+ size: "small",
256
+ color: "error",
257
+ onClick: () => logout({
258
+ visitorId: x.visitorId
259
+ }),
260
+ children: currentVisitorId === x.visitorId ? t("currentSession") : t("logout")
261
+ })
262
+ });
263
+ }
264
+ }
265
+ }].filter(Boolean);
266
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
267
+ sx: {
268
+ ".MuiTableCell-head": {
269
+ whiteSpace: "nowrap",
270
+ fontWeight: "bold"
271
+ }
272
+ },
273
+ children: [confirmHolder, /* @__PURE__ */(0, _jsxRuntime.jsx)(_Datatable.default, {
274
+ locale,
275
+ data: safeData,
276
+ columns,
277
+ customButtons,
278
+ options: tableOptions,
279
+ loading: pageState.loading
280
+ })]
281
+ });
282
+ }
@@ -0,0 +1 @@
1
+ export { default as UserSessions } from './components/user-sessions';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "UserSessions", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _userSessions.default;
10
+ }
11
+ });
12
+ var _userSessions = _interopRequireDefault(require("./components/user-sessions"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,52 @@
1
+ export declare const translations: {
2
+ zh: {
3
+ confirm: string;
4
+ cancel: string;
5
+ visitorId: string;
6
+ deviceType: string;
7
+ platform: string;
8
+ walletOS: string;
9
+ role: string;
10
+ fullname: string;
11
+ email: string;
12
+ avatar: string;
13
+ user: string;
14
+ updatedAt: string;
15
+ lastLoginIp: string;
16
+ actions: string;
17
+ logoutAll: string;
18
+ logoutAllTips: string;
19
+ logout: string;
20
+ currentSession: string;
21
+ unknown: string;
22
+ logoutThisSession: string;
23
+ logoutThisSessionConfirm: string;
24
+ logoutAllSession: string;
25
+ logoutAllSessionConfirm: string;
26
+ };
27
+ en: {
28
+ confirm: string;
29
+ cancel: string;
30
+ visitorId: string;
31
+ deviceType: string;
32
+ platform: string;
33
+ walletOS: string;
34
+ role: string;
35
+ fullname: string;
36
+ email: string;
37
+ avatar: string;
38
+ user: string;
39
+ updatedAt: string;
40
+ actions: string;
41
+ lastLoginIp: string;
42
+ logoutAll: string;
43
+ logoutAllTips: string;
44
+ logout: string;
45
+ currentSession: string;
46
+ unknown: string;
47
+ logoutThisSession: string;
48
+ logoutThisSessionConfirm: string;
49
+ logoutAllSession: string;
50
+ logoutAllSessionConfirm: string;
51
+ };
52
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.translations = void 0;
7
+ const translations = exports.translations = {
8
+ zh: {
9
+ confirm: "\u786E\u8BA4",
10
+ cancel: "\u53D6\u6D88",
11
+ visitorId: "\u8BBE\u5907\u6807\u8BC6",
12
+ deviceType: "\u8BBE\u5907\u7C7B\u578B",
13
+ platform: "\u64CD\u4F5C\u7CFB\u7EDF",
14
+ walletOS: "\u94B1\u5305\u7C7B\u578B",
15
+ role: "\u89D2\u8272",
16
+ fullname: "\u59D3\u540D",
17
+ email: "\u90AE\u7BB1",
18
+ avatar: "\u5934\u50CF",
19
+ user: "\u7528\u6237",
20
+ updatedAt: "\u6700\u8FD1\u6D3B\u52A8\u65F6\u95F4",
21
+ lastLoginIp: "\u6700\u8FD1\u6D3B\u52A8\u5730\u5740",
22
+ actions: "\u64CD\u4F5C",
23
+ logoutAll: "\u6CE8\u9500\u6240\u6709\u4F1A\u8BDD",
24
+ logoutAllTips: "\u4E0D\u4F1A\u6CE8\u9500\u5F53\u524D\u4F1A\u8BDD",
25
+ logout: "\u6CE8\u9500",
26
+ currentSession: "\u5F53\u524D\u4F1A\u8BDD",
27
+ unknown: "\u672A\u77E5",
28
+ logoutThisSession: "\u6CE8\u9500\u6307\u5B9A\u4F1A\u8BDD",
29
+ logoutThisSessionConfirm: "\u786E\u5B9A\u8981\u6CE8\u9500\u6B64\u4F1A\u8BDD\u5417?",
30
+ logoutAllSession: "\u6CE8\u9500\u6240\u6709\u4F1A\u8BDD",
31
+ logoutAllSessionConfirm: "\u786E\u5B9A\u8981\u6CE8\u9500\u6240\u6709\u4F1A\u8BDD\u5417?"
32
+ },
33
+ en: {
34
+ confirm: "Confirm",
35
+ cancel: "Cancel",
36
+ visitorId: "Device ID",
37
+ deviceType: "Device Type",
38
+ platform: "Platform",
39
+ walletOS: "Wallet OS",
40
+ role: "Role",
41
+ fullname: "Fullname",
42
+ email: "Email",
43
+ avatar: "Avatar",
44
+ user: "User",
45
+ updatedAt: "Last Active Time",
46
+ actions: "Actions",
47
+ lastLoginIp: "Last Login IP",
48
+ logoutAll: "Logout all",
49
+ logoutAllTips: "Will not logout current session",
50
+ logout: "Logout",
51
+ currentSession: "Current Session",
52
+ unknown: "Unknown",
53
+ logoutThisSession: "Logout this session",
54
+ logoutThisSessionConfirm: "Are you sure to logout this session?",
55
+ logoutAllSession: "Logout all sessions",
56
+ logoutAllSessionConfirm: "Are you sure to logout all sessions?"
57
+ }
58
+ };
@@ -0,0 +1,2 @@
1
+ export declare function ip2Region(ip: string): Promise<string>;
2
+ export declare function batchIp2Region(ips: string[]): Promise<string[]>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.batchIp2Region = batchIp2Region;
7
+ exports.ip2Region = ip2Region;
8
+ const RESERVED_IP = "Reserved IP";
9
+ const IP_REGION_CACHE = "ip-region-cache";
10
+ async function getIpRegionFromIpApi(ip) {
11
+ const url = `https://ipapi.co/${ip}/json/`;
12
+ const result = await fetch(url);
13
+ const data = await result.json();
14
+ let region = "";
15
+ if (data.error) {
16
+ if (data.reserved) {
17
+ region = RESERVED_IP;
18
+ }
19
+ } else {
20
+ region = [data.country_name, data.region, data.city].filter(Boolean).join("/");
21
+ }
22
+ return region;
23
+ }
24
+ async function getIpRegionFromIpSb(ip) {
25
+ const url = `https://api.ip.sb/geoip/${ip}`;
26
+ const result = await fetch(url);
27
+ const data = await result.json();
28
+ let region = "";
29
+ if (data.error) {
30
+ if (data.reserved) {
31
+ region = RESERVED_IP;
32
+ }
33
+ } else {
34
+ region = [data.country, data.region, data.city].filter(Boolean).join("/");
35
+ }
36
+ return region;
37
+ }
38
+ async function ip2Region(ip) {
39
+ let region = "";
40
+ let ipRegionCache = {};
41
+ try {
42
+ const tmpCache = localStorage.getItem(IP_REGION_CACHE);
43
+ if (tmpCache) {
44
+ ipRegionCache = JSON.parse(tmpCache);
45
+ }
46
+ } catch {
47
+ ipRegionCache = {};
48
+ }
49
+ if (ipRegionCache[ip]) {
50
+ region = ipRegionCache[ip];
51
+ } else {
52
+ try {
53
+ region = await getIpRegionFromIpSb(ip);
54
+ } catch {
55
+ console.warn("Fail to get ip region from ip.sb");
56
+ }
57
+ if (!region) {
58
+ try {
59
+ region = await getIpRegionFromIpApi(ip);
60
+ } catch {
61
+ console.warn("Fail to get ip region from ip-api.co");
62
+ }
63
+ }
64
+ }
65
+ if (region) {
66
+ const ipList = Object.keys(ipRegionCache);
67
+ if (ipList.length > 100) {
68
+ delete ipRegionCache[ipList[0]];
69
+ }
70
+ if (ipRegionCache[ip]) {
71
+ delete ipRegionCache[ip];
72
+ }
73
+ ipRegionCache[ip] = region;
74
+ localStorage.setItem(IP_REGION_CACHE, JSON.stringify(ipRegionCache));
75
+ }
76
+ return region;
77
+ }
78
+ async function batchIp2Region(ips) {
79
+ return Promise.all(ips.map(ip => ip2Region(ip)));
80
+ }
package/lib/blocklets.js CHANGED
@@ -40,30 +40,30 @@ const getLocalizedNavigation = (navigation, locale = 'en') => {
40
40
  return navigation;
41
41
  }
42
42
  // eslint-disable-next-line no-shadow
43
- const getTitle = (title, locale) => {
43
+ const getTitle = (title, _locale) => {
44
44
  if (typeof title === 'string') {
45
45
  return title;
46
46
  }
47
47
  if (typeof title === 'object') {
48
- return title[locale] || title?.en || title?.zh;
48
+ return title[_locale] || title?.en || title?.zh;
49
49
  }
50
50
  return title;
51
51
  };
52
52
  // eslint-disable-next-line no-shadow
53
- const getLink = (link, locale) => {
53
+ const getLink = (link, _locale) => {
54
54
  if (typeof link === 'string') {
55
55
  // http[s] 开头的 url
56
56
  if ((0, _utils.isUrl)(link)) {
57
57
  const url = new URL(link);
58
- url.searchParams.set('locale', locale);
58
+ url.searchParams.set('locale', _locale);
59
59
  return url.href;
60
60
  }
61
61
  const url = new URL(link, window.location.origin);
62
- url.searchParams.set('locale', locale);
62
+ url.searchParams.set('locale', _locale);
63
63
  return url.pathname + url.search;
64
64
  }
65
65
  if (typeof link === 'object') {
66
- return link[locale] || link?.en || link?.zh;
66
+ return link[_locale] || link?.en || link?.zh;
67
67
  }
68
68
  return link;
69
69
  };
@@ -7,16 +7,15 @@ declare namespace HeaderAddons {
7
7
  namespace propTypes {
8
8
  export let formattedBlocklet: any;
9
9
  export let addons: any;
10
- export { sessionManagerProps };
10
+ export { SessionManagerProps as sessionManagerProps };
11
11
  }
12
12
  namespace defaultProps {
13
13
  let addons_1: null;
14
14
  export { addons_1 as addons };
15
- export namespace sessionManagerProps_1 {
15
+ export namespace sessionManagerProps {
16
16
  let showRole: boolean;
17
17
  }
18
- export { sessionManagerProps_1 as sessionManagerProps };
19
18
  }
20
19
  }
21
20
  export default HeaderAddons;
22
- import { sessionManagerProps } from '../types';
21
+ import { SessionManagerProps } from '../types';
@@ -19,7 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
  function HeaderAddons({
20
20
  formattedBlocklet,
21
21
  addons,
22
- sessionManagerProps: sessionManagerProps2
22
+ sessionManagerProps
23
23
  }) {
24
24
  const sessionCtx = (0, _react.useContext)(_Session.SessionContext);
25
25
  const {
@@ -71,7 +71,7 @@ function HeaderAddons({
71
71
  locale,
72
72
  menu,
73
73
  showRole: true,
74
- ...sessionManagerProps2
74
+ ...sessionManagerProps
75
75
  }, "session-user"));
76
76
  }
77
77
  if (typeof addons === "function") {
@@ -89,7 +89,7 @@ HeaderAddons.propTypes = {
89
89
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
90
90
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
91
91
  addons: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
92
- sessionManagerProps: _types.sessionManagerProps
92
+ sessionManagerProps: _types.SessionManagerProps
93
93
  };
94
94
  HeaderAddons.defaultProps = {
95
95
  addons: null,
@@ -35,12 +35,12 @@ function ConfigUserSpaceProvider({
35
35
  const deleteSpaceGateway = async () => {
36
36
  setSpaceGateway(void 0);
37
37
  };
38
+ const settingStorageEndpoint = endpoint => {};
38
39
  const updateSpaceGateway = async x => {
39
40
  setSpaceGateway(x);
40
41
  session.refresh();
41
42
  await settingStorageEndpoint(x.endpoint);
42
43
  };
43
- const settingStorageEndpoint = endpoint => {};
44
44
  const hasStorageEndpoint = Boolean(storageEndpoint && spaceGateway);
45
45
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(Provider, {
46
46
  value: {
package/lib/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { default as Icon } from './Icon';
5
5
  export { default as ComponentInstaller } from './ComponentInstaller';
6
6
  export { default as useComponentInstaller } from './ComponentInstaller/use-component-installed';
7
7
  export * from './UserCenter';
8
+ export * from './UserSessions';
package/lib/index.js CHANGED
@@ -65,4 +65,16 @@ Object.keys(_UserCenter).forEach(function (key) {
65
65
  }
66
66
  });
67
67
  });
68
+ var _UserSessions = require("./UserSessions");
69
+ Object.keys(_UserSessions).forEach(function (key) {
70
+ if (key === "default" || key === "__esModule") return;
71
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
72
+ if (key in exports && exports[key] === _UserSessions[key]) return;
73
+ Object.defineProperty(exports, key, {
74
+ enumerable: true,
75
+ get: function () {
76
+ return _UserSessions[key];
77
+ }
78
+ });
79
+ });
68
80
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/lib/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const blockletMetaProps: any;
2
- export const sessionManagerProps: any;
1
+ export const BlockletMetaProps: any;
2
+ export const SessionManagerProps: any;
package/lib/types.js CHANGED
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.sessionManagerProps = exports.blockletMetaProps = void 0;
6
+ exports.SessionManagerProps = exports.BlockletMetaProps = void 0;
7
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  /* eslint-disable import/prefer-default-export */
10
10
 
11
- const blockletMetaProps = exports.blockletMetaProps = _propTypes.default.shape({
11
+ const BlockletMetaProps = exports.BlockletMetaProps = _propTypes.default.shape({
12
12
  appLogo: _propTypes.default.node,
13
13
  appName: _propTypes.default.string,
14
14
  theme: _propTypes.default.shape({
@@ -26,7 +26,7 @@ const blockletMetaProps = exports.blockletMetaProps = _propTypes.default.shape({
26
26
  }))
27
27
  }))
28
28
  });
29
- const sessionManagerProps = exports.sessionManagerProps = _propTypes.default.shape({
29
+ const SessionManagerProps = exports.SessionManagerProps = _propTypes.default.shape({
30
30
  showText: _propTypes.default.bool,
31
31
  showRole: _propTypes.default.bool,
32
32
  switchDid: _propTypes.default.bool,