@blocklet/did-space-react 0.5.76 → 0.5.78

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.
@@ -17,7 +17,7 @@ function PreviewSpaceNft({
17
17
  const handleClose = () => setOpen(false);
18
18
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
19
19
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, onClick: handleOpen, children: [
20
- /* @__PURE__ */ jsxRuntime.jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsxRuntime.jsx(emptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width: "64px", height: "64px" } }) }),
20
+ /* @__PURE__ */ jsxRuntime.jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsxRuntime.jsx(emptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width, height } }) }),
21
21
  /* @__PURE__ */ jsxRuntime.jsx(
22
22
  "div",
23
23
  {
@@ -10,6 +10,8 @@ const Theme = require('@arcblock/ux/lib/Theme');
10
10
  const React = require('react');
11
11
  const axios = require('axios');
12
12
  const ahooks = require('ahooks');
13
+ const compareVersions = require('compare-versions');
14
+ const _package = require('../../package.json.js');
13
15
  const constants = require('../../libs/constants.js');
14
16
  const useMobile = require('../../hooks/use-mobile.js');
15
17
  const useSpaceInfo = require('../../hooks/use-space-info.js');
@@ -22,6 +24,7 @@ const spaceConnected = require('../../icons/space-connected.svg.js');
22
24
  const spaceDisconnect = require('../../icons/space-disconnect.svg.js');
23
25
  const spaceConnectError = require('../../icons/space-connect-error.svg.js');
24
26
 
27
+ const expectVersion = `^${_package.version}`;
25
28
  function Status({
26
29
  spaceUrl,
27
30
  status,
@@ -84,6 +87,17 @@ function Status({
84
87
  [constants.SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED]: {
85
88
  icon: /* @__PURE__ */ jsxRuntime.jsx(spaceConnectError, { style: iconStyle }),
86
89
  text: /* @__PURE__ */ jsxRuntime.jsx(ErrorLink, { title: t("storage.spaces.error.corsBlocked"), url: ufo.withQuery(constants.fixCorsErrorPageUrl, { locale }) })
90
+ },
91
+ // Space 版本不兼容
92
+ [constants.SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE]: {
93
+ icon: /* @__PURE__ */ jsxRuntime.jsx(spaceConnectError, { style: iconStyle }),
94
+ text: /* @__PURE__ */ jsxRuntime.jsx(
95
+ ErrorLink,
96
+ {
97
+ title: t("storage.spaces.error.incompatible"),
98
+ url: ufo.joinURL(new URL(spaceUrl).origin, ".well-known/service/admin/components")
99
+ }
100
+ )
87
101
  }
88
102
  }),
89
103
  [locale]
@@ -140,8 +154,8 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
140
154
  if (isUndefined(isCompact)) {
141
155
  isCompact = isMobile;
142
156
  }
143
- const spaceDid = util.getDIDSpaceDidFromEndpoint(endpoint);
144
- const spaceUrl = util.getDIDSpaceUrlFromEndpoint(endpoint);
157
+ const spaceDid = util.getSpaceDidFromEndpoint(endpoint);
158
+ const spaceUrl = util.getSpaceUrlFromEndpoint(endpoint);
145
159
  const gatewayUrl = util.getSpaceGatewayUrlFromEndpoint(endpoint);
146
160
  const [refreshSpaceInfo, setRefreshSpaceInfo] = React.useState(false);
147
161
  const refresh = () => setRefreshSpaceInfo((p) => !p);
@@ -161,8 +175,13 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
161
175
  spaceStatus.current = index.SpaceStatus.LOADING;
162
176
  spaceName = /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { variant: "text", sx: { width: "180px", fontSize: "1rem" } });
163
177
  } else if (spaceInfo) {
164
- spaceName = spaceInfo.spaceName;
165
- if (!isAvailable) {
178
+ spaceName = spaceInfo.name;
179
+ const spaceVersion = spaceInfo.version;
180
+ const isIncompatible = !spaceVersion || !compareVersions.satisfies(spaceVersion, expectVersion);
181
+ if (isIncompatible) {
182
+ spaceStatus.current = index.SpaceStatus.UNAVAILABLE;
183
+ errorCode = constants.SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE;
184
+ } else if (!isAvailable) {
166
185
  spaceStatus.current = index.SpaceStatus.UNAVAILABLE;
167
186
  errorCode = spaceInfo.errorCode;
168
187
  if (errorCode === constants.SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED) {
@@ -187,7 +206,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
187
206
  return action({
188
207
  spaceGateway: {
189
208
  did: spaceDid,
190
- name: spaceInfo?.spaceName ?? "",
209
+ name: spaceInfo?.name ?? "",
191
210
  url: gatewayUrl,
192
211
  endpoint,
193
212
  ownerDid: spaceInfo?.ownerDid ?? ""
@@ -1,11 +1,13 @@
1
+ type SpaceInfo = {
2
+ version: string;
3
+ name: string;
4
+ subscriptionId: string;
5
+ ownerDid: string;
6
+ isAvailable: boolean;
7
+ errorCode: number;
8
+ };
1
9
  export default function useSpaceInfo({ endpoint, deps }: {
2
10
  endpoint: string;
3
11
  deps?: any[];
4
- }): import("ahooks/lib/useRequest/src/types").Result<{
5
- spaceName: string;
6
- subscriptionId: any;
7
- ownerDid: any;
8
- isAvailable: boolean;
9
- errorMessage: string;
10
- errorCode: number;
11
- } | undefined, []>;
12
+ }): import("ahooks/lib/useRequest/src/types").Result<SpaceInfo | undefined, any[]>;
13
+ export {};
@@ -2,6 +2,7 @@
2
2
 
3
3
  const isUrl = require('is-url');
4
4
  const ahooks = require('ahooks');
5
+ const constants = require('../libs/constants.js');
5
6
  const api = require('../libs/api.js');
6
7
 
7
8
  function useSpaceInfo({ endpoint, deps = [] }) {
@@ -16,14 +17,47 @@ function useSpaceInfo({ endpoint, deps = [] }) {
16
17
  withExtras: true
17
18
  }
18
19
  });
19
- const spaceName = headers["x-space-name"];
20
+ const [
21
+ rawName,
22
+ rawSubscriptionId,
23
+ isListable,
24
+ isReadable,
25
+ isWriteable,
26
+ rawVersion,
27
+ rawOwnerDid,
28
+ rawAvailable,
29
+ rawErrorCode
30
+ ] = [
31
+ headers["x-space-name"],
32
+ headers["x-subscription-id"],
33
+ headers["x-listable"] === "true",
34
+ headers["x-readable"] === "true",
35
+ headers["x-writeable"] === "true",
36
+ // 新版 headers
37
+ headers["x-space-version"],
38
+ headers["x-space-owner-did"],
39
+ headers["x-space-is-available"],
40
+ headers["x-error-code"]
41
+ ];
42
+ const name = rawName ? decodeURIComponent(rawName) : "";
43
+ if (rawAvailable === void 0 || rawErrorCode === void 0) {
44
+ const isAvailable = isListable && isReadable && isWriteable;
45
+ return {
46
+ version: rawVersion || "",
47
+ name,
48
+ subscriptionId: rawSubscriptionId,
49
+ ownerDid: rawOwnerDid || "",
50
+ isAvailable,
51
+ errorCode: isAvailable ? 0 : constants.SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED
52
+ };
53
+ }
20
54
  return {
21
- spaceName: spaceName ? decodeURIComponent(spaceName) : "",
22
- subscriptionId: headers["x-subscription-id"],
23
- ownerDid: headers["x-space-owner-did"],
24
- isAvailable: headers["x-space-is-available"] === "true",
25
- errorMessage: decodeURIComponent(headers["x-error-message"]),
26
- errorCode: parseInt(headers["x-error-code"], 10)
55
+ version: rawVersion || "",
56
+ name,
57
+ subscriptionId: rawSubscriptionId,
58
+ ownerDid: rawOwnerDid,
59
+ isAvailable: rawAvailable === "true",
60
+ errorCode: parseInt(rawErrorCode, 10)
27
61
  };
28
62
  },
29
63
  {
package/dist/cjs/index.js CHANGED
@@ -41,12 +41,11 @@ exports.fixCorsErrorPageUrl = constants.fixCorsErrorPageUrl;
41
41
  exports.classNames = util.classNames;
42
42
  exports.decryptSpaceGateway = util.decryptSpaceGateway;
43
43
  exports.extraDIDSpacesCoreUrl = util.extraDIDSpacesCoreUrl;
44
- exports.getDIDSpaceDidFromEndpoint = util.getDIDSpaceDidFromEndpoint;
45
- exports.getDIDSpaceUrlFromEndpoint = util.getDIDSpaceUrlFromEndpoint;
46
44
  exports.getSpaceDidFromEndpoint = util.getSpaceDidFromEndpoint;
47
45
  exports.getSpaceDidFromSpaceUrl = util.getSpaceDidFromSpaceUrl;
48
46
  exports.getSpaceGatewayUrlFromEndpoint = util.getSpaceGatewayUrlFromEndpoint;
49
47
  exports.getSpaceNftDisplayUrlFromEndpoint = util.getSpaceNftDisplayUrlFromEndpoint;
48
+ exports.getSpaceUrlFromEndpoint = util.getSpaceUrlFromEndpoint;
50
49
  exports.isCorsBlockedError = util.isCorsBlockedError;
51
50
  exports.t = util.t;
52
51
  exports.getSpaceGatewayUrl = gateway.getSpaceGatewayUrl;
@@ -13,6 +13,8 @@ export declare const SPACE_CONNECT_ERROR_CODE: {
13
13
  UNIT_LIMIT: number;
14
14
  /** 跨域限制 */
15
15
  CORS_BLOCKED: number;
16
+ /** Space 版本不兼容 */
17
+ INCOMPATIBLE: number;
16
18
  };
17
19
  export declare const AUTHORIZE: {
18
20
  DEFAULT_SCOPE: string;
@@ -14,7 +14,9 @@ const SPACE_CONNECT_ERROR_CODE = {
14
14
  /** 用量不足 */
15
15
  UNIT_LIMIT: 1006,
16
16
  /** 跨域限制 */
17
- CORS_BLOCKED: 1007
17
+ CORS_BLOCKED: 1007,
18
+ /** Space 版本不兼容 */
19
+ INCOMPATIBLE: 1008
18
20
  };
19
21
  const AUTHORIZE = {
20
22
  DEFAULT_SCOPE: "list:object read:object write:object"
@@ -11,10 +11,9 @@ type ClassStr = string | undefined | null;
11
11
  * classNames(['foo', 'bar']); // => 'foo bar'
12
12
  */
13
13
  export declare function classNames(...classes: (ClassStr | Record<string, boolean> | Array<ClassStr | Record<string, boolean>>)[]): string;
14
- export declare function getDIDSpaceDidFromEndpoint(endpoint: string): string | undefined;
15
- export declare function getDIDSpaceUrlFromEndpoint(endpoint: string): string;
16
- export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
17
14
  export declare function getSpaceDidFromEndpoint(endpoint: string): string | undefined;
15
+ export declare function getSpaceUrlFromEndpoint(endpoint: string): string;
16
+ export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
18
17
  export declare function getSpaceGatewayUrlFromEndpoint(endpoint: string): string;
19
18
  export declare function extraDIDSpacesCoreUrl(url: string): string;
20
19
  export declare function getSpaceDidFromSpaceUrl(url: string): string | undefined;
@@ -24,12 +24,12 @@ function classNames(...classes) {
24
24
  });
25
25
  return result.join(" ");
26
26
  }
27
- function getDIDSpaceDidFromEndpoint(endpoint) {
27
+ function getSpaceDidFromEndpoint(endpoint) {
28
28
  const strArray = endpoint.replace(/\/$/, "").split("/");
29
29
  const spaceDid = strArray.at(-4);
30
30
  return spaceDid;
31
31
  }
32
- function getDIDSpaceUrlFromEndpoint(endpoint) {
32
+ function getSpaceUrlFromEndpoint(endpoint) {
33
33
  const prefix = endpoint.replace(/\/api\/space\/.+/, "");
34
34
  const strArray = endpoint.replace(/\/$/, "").split("/");
35
35
  const spaceDid = strArray.at(-4);
@@ -41,13 +41,8 @@ function getSpaceNftDisplayUrlFromEndpoint(endpoint) {
41
41
  const spaceDid = strArray.at(-4);
42
42
  return ufo.joinURL(prefix, `/api/space/nft/display?spaceDid=${spaceDid}`);
43
43
  }
44
- function getSpaceDidFromEndpoint(endpoint) {
45
- const strArray = endpoint.replace(/\/$/, "").split("/");
46
- const spaceDid = strArray.at(-4);
47
- return spaceDid;
48
- }
49
44
  function getSpaceGatewayUrlFromEndpoint(endpoint) {
50
- const spaceUrl = getDIDSpaceUrlFromEndpoint(endpoint);
45
+ const spaceUrl = getSpaceUrlFromEndpoint(endpoint);
51
46
  return spaceUrl.split("/space/")[0];
52
47
  }
53
48
  function extraDIDSpacesCoreUrl(url) {
@@ -87,11 +82,10 @@ function t(key, localeOrData, data = {}) {
87
82
  exports.classNames = classNames;
88
83
  exports.decryptSpaceGateway = decryptSpaceGateway;
89
84
  exports.extraDIDSpacesCoreUrl = extraDIDSpacesCoreUrl;
90
- exports.getDIDSpaceDidFromEndpoint = getDIDSpaceDidFromEndpoint;
91
- exports.getDIDSpaceUrlFromEndpoint = getDIDSpaceUrlFromEndpoint;
92
85
  exports.getSpaceDidFromEndpoint = getSpaceDidFromEndpoint;
93
86
  exports.getSpaceDidFromSpaceUrl = getSpaceDidFromSpaceUrl;
94
87
  exports.getSpaceGatewayUrlFromEndpoint = getSpaceGatewayUrlFromEndpoint;
95
88
  exports.getSpaceNftDisplayUrlFromEndpoint = getSpaceNftDisplayUrlFromEndpoint;
89
+ exports.getSpaceUrlFromEndpoint = getSpaceUrlFromEndpoint;
96
90
  exports.isCorsBlockedError = isCorsBlockedError;
97
91
  exports.t = t;
@@ -10,7 +10,8 @@ const en = flat.flatten({
10
10
  error: "Error",
11
11
  open: "Open",
12
12
  unknown: "Unknown",
13
- invalidUrl: "Invalid url: {url}"
13
+ invalidUrl: "Invalid url: {url}",
14
+ upgrade: "Upgrade"
14
15
  },
15
16
  storage: {
16
17
  spaces: {
@@ -40,7 +41,8 @@ const en = flat.flatten({
40
41
  invalid: "DID Spaces subscription anomaly, click this link to check",
41
42
  unitLimit: "DID Spaces free quota has been used up, click this link to pay for the upgrade",
42
43
  corsBlocked: "The connection request may fail due to CORS restrictions:\n1. Please contact the DID Space administrator to verify the relevant configuration.\n2. If you are the administrator, click the link below to view the detailed setup guide and resolve the issue.",
43
- networkError: "Network error"
44
+ networkError: "Network error",
45
+ incompatible: "The current DID Spaces version is incompatible. Please contact your administrator to make adjustments. \nIf you are the administrator, click the link below to proceed."
44
46
  },
45
47
  gateway: {
46
48
  add: {
@@ -10,7 +10,8 @@ const zh = flat.flatten({
10
10
  error: "\u9519\u8BEF",
11
11
  open: "\u6253\u5F00",
12
12
  unknown: "\u672A\u77E5",
13
- invalidUrl: "\u65E0\u6548\u7684 url: {url}"
13
+ invalidUrl: "\u65E0\u6548\u7684 url: {url}",
14
+ upgrade: "\u5347\u7EA7"
14
15
  },
15
16
  storage: {
16
17
  spaces: {
@@ -40,7 +41,8 @@ const zh = flat.flatten({
40
41
  invalid: "DID Spaces \u8BA2\u9605\u5F02\u5E38\uFF0C\u70B9\u51FB\u6B64\u94FE\u63A5\u68C0\u67E5",
41
42
  unitLimit: "DID Spaces \u514D\u8D39\u989D\u5EA6\u5DF2\u7528\u5B8C\uFF0C\u70B9\u51FB\u6B64\u94FE\u63A5\u4ED8\u8D39\u5347\u7EA7",
42
43
  corsBlocked: "\u8FDE\u63A5\u8BF7\u6C42\u53EF\u80FD\u56E0 CORS \u9650\u5236\u800C\u5931\u8D25\uFF1A\n1. \u8BF7\u8054\u7CFB DID Space \u7BA1\u7406\u5458\u786E\u8BA4\u76F8\u5173\u914D\u7F6E\u662F\u5426\u6B63\u786E\u3002\n2. \u5982\u679C\u60A8\u662F\u7BA1\u7406\u5458\uFF0C\u53EF\u4EE5\u70B9\u51FB\u4E0B\u65B9\u94FE\u63A5\uFF0C\u67E5\u770B\u8BE6\u7EC6\u7684\u914D\u7F6E\u6307\u5357\u5E76\u89E3\u51B3\u95EE\u9898\u3002",
43
- networkError: "\u7F51\u7EDC\u9519\u8BEF"
44
+ networkError: "\u7F51\u7EDC\u9519\u8BEF",
45
+ incompatible: "\u5F53\u524D DID Spaces \u7248\u672C\u4E0D\u517C\u5BB9\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u8FDB\u884C\u8C03\u6574\u3002\n\u5982\u679C\u60A8\u662F\u7BA1\u7406\u5458\uFF0C\u53EF\u4EE5\u5355\u51FB\u4E0B\u9762\u7684\u94FE\u63A5\u8FDB\u884C\u64CD\u4F5C\u3002"
44
46
  },
45
47
  gateway: {
46
48
  add: {
@@ -53,6 +55,9 @@ const zh = flat.flatten({
53
55
  title: "\u8BF7\u4E3A {appName} \u51FA\u793A DID Spaces NFT",
54
56
  scan: "\u4F7F\u7528\u4F60\u7684 DID Wallet \u626B\u63CF\u4E0B\u9762\u7684\u4E8C\u7EF4\u7801\u4E3A\u5E94\u7528 {appName} \u51FA\u793A DID Spaces NFT",
55
57
  success: "\u8FDE\u63A5\u6210\u529F"
58
+ },
59
+ helperText: {
60
+ fixCorsError: "\u4FEE\u590D\u8FDE\u63A5 DID Spaces \u65F6\u7684 CORS \u9519\u8BEF"
56
61
  }
57
62
  }
58
63
  }
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const version = "0.5.78";
4
+
5
+ exports.version = version;
@@ -15,7 +15,7 @@ function PreviewSpaceNft({
15
15
  const handleClose = () => setOpen(false);
16
16
  return /* @__PURE__ */ jsxs(Fragment, { children: [
17
17
  /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, onClick: handleOpen, children: [
18
- /* @__PURE__ */ jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsx(SvgEmptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width: "64px", height: "64px" } }) }),
18
+ /* @__PURE__ */ jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsx(SvgEmptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width, height } }) }),
19
19
  /* @__PURE__ */ jsx(
20
20
  "div",
21
21
  {
@@ -8,11 +8,13 @@ import { styled } from '@arcblock/ux/lib/Theme';
8
8
  import { useState, useRef, useEffect } from 'react';
9
9
  import { AxiosError } from 'axios';
10
10
  import { useCreation } from 'ahooks';
11
+ import { satisfies } from 'compare-versions';
12
+ import { version } from '../../package.json.js';
11
13
  import { SPACE_CONNECT_ERROR_CODE, fixCorsErrorPageUrl } from '../../libs/constants.js';
12
14
  import useMobile from '../../hooks/use-mobile.js';
13
15
  import useSpaceInfo from '../../hooks/use-space-info.js';
14
16
  import useLocale from '../../hooks/use-locale.js';
15
- import { getDIDSpaceDidFromEndpoint, getDIDSpaceUrlFromEndpoint, getSpaceGatewayUrlFromEndpoint, isCorsBlockedError, classNames, getSpaceNftDisplayUrlFromEndpoint } from '../../libs/util.js';
17
+ import { getSpaceDidFromEndpoint, getSpaceUrlFromEndpoint, getSpaceGatewayUrlFromEndpoint, isCorsBlockedError, classNames, getSpaceNftDisplayUrlFromEndpoint } from '../../libs/util.js';
16
18
  import { SpaceStatus } from '../../types/index.js';
17
19
  import '../../icons/index.js';
18
20
  import { PreviewSpaceNft } from '../preview-space-nft/index.js';
@@ -20,6 +22,7 @@ import SvgSpaceConnected from '../../icons/space-connected.svg.js';
20
22
  import SvgSpaceDisconnect from '../../icons/space-disconnect.svg.js';
21
23
  import SvgSpaceConnectError from '../../icons/space-connect-error.svg.js';
22
24
 
25
+ const expectVersion = `^${version}`;
23
26
  function Status({
24
27
  spaceUrl,
25
28
  status,
@@ -82,6 +85,17 @@ function Status({
82
85
  [SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED]: {
83
86
  icon: /* @__PURE__ */ jsx(SvgSpaceConnectError, { style: iconStyle }),
84
87
  text: /* @__PURE__ */ jsx(ErrorLink, { title: t("storage.spaces.error.corsBlocked"), url: withQuery(fixCorsErrorPageUrl, { locale }) })
88
+ },
89
+ // Space 版本不兼容
90
+ [SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE]: {
91
+ icon: /* @__PURE__ */ jsx(SvgSpaceConnectError, { style: iconStyle }),
92
+ text: /* @__PURE__ */ jsx(
93
+ ErrorLink,
94
+ {
95
+ title: t("storage.spaces.error.incompatible"),
96
+ url: joinURL(new URL(spaceUrl).origin, ".well-known/service/admin/components")
97
+ }
98
+ )
85
99
  }
86
100
  }),
87
101
  [locale]
@@ -138,8 +152,8 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
138
152
  if (isUndefined(isCompact)) {
139
153
  isCompact = isMobile;
140
154
  }
141
- const spaceDid = getDIDSpaceDidFromEndpoint(endpoint);
142
- const spaceUrl = getDIDSpaceUrlFromEndpoint(endpoint);
155
+ const spaceDid = getSpaceDidFromEndpoint(endpoint);
156
+ const spaceUrl = getSpaceUrlFromEndpoint(endpoint);
143
157
  const gatewayUrl = getSpaceGatewayUrlFromEndpoint(endpoint);
144
158
  const [refreshSpaceInfo, setRefreshSpaceInfo] = useState(false);
145
159
  const refresh = () => setRefreshSpaceInfo((p) => !p);
@@ -159,8 +173,13 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
159
173
  spaceStatus.current = SpaceStatus.LOADING;
160
174
  spaceName = /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { width: "180px", fontSize: "1rem" } });
161
175
  } else if (spaceInfo) {
162
- spaceName = spaceInfo.spaceName;
163
- if (!isAvailable) {
176
+ spaceName = spaceInfo.name;
177
+ const spaceVersion = spaceInfo.version;
178
+ const isIncompatible = !spaceVersion || !satisfies(spaceVersion, expectVersion);
179
+ if (isIncompatible) {
180
+ spaceStatus.current = SpaceStatus.UNAVAILABLE;
181
+ errorCode = SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE;
182
+ } else if (!isAvailable) {
164
183
  spaceStatus.current = SpaceStatus.UNAVAILABLE;
165
184
  errorCode = spaceInfo.errorCode;
166
185
  if (errorCode === SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED) {
@@ -185,7 +204,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
185
204
  return action({
186
205
  spaceGateway: {
187
206
  did: spaceDid,
188
- name: spaceInfo?.spaceName ?? "",
207
+ name: spaceInfo?.name ?? "",
189
208
  url: gatewayUrl,
190
209
  endpoint,
191
210
  ownerDid: spaceInfo?.ownerDid ?? ""
@@ -1,11 +1,13 @@
1
+ type SpaceInfo = {
2
+ version: string;
3
+ name: string;
4
+ subscriptionId: string;
5
+ ownerDid: string;
6
+ isAvailable: boolean;
7
+ errorCode: number;
8
+ };
1
9
  export default function useSpaceInfo({ endpoint, deps }: {
2
10
  endpoint: string;
3
11
  deps?: any[];
4
- }): import("ahooks/lib/useRequest/src/types").Result<{
5
- spaceName: string;
6
- subscriptionId: any;
7
- ownerDid: any;
8
- isAvailable: boolean;
9
- errorMessage: string;
10
- errorCode: number;
11
- } | undefined, []>;
12
+ }): import("ahooks/lib/useRequest/src/types").Result<SpaceInfo | undefined, any[]>;
13
+ export {};
@@ -1,5 +1,6 @@
1
1
  import isUrl from 'is-url';
2
2
  import { useRequest } from 'ahooks';
3
+ import { SPACE_CONNECT_ERROR_CODE } from '../libs/constants.js';
3
4
  import api from '../libs/api.js';
4
5
 
5
6
  function useSpaceInfo({ endpoint, deps = [] }) {
@@ -14,14 +15,47 @@ function useSpaceInfo({ endpoint, deps = [] }) {
14
15
  withExtras: true
15
16
  }
16
17
  });
17
- const spaceName = headers["x-space-name"];
18
+ const [
19
+ rawName,
20
+ rawSubscriptionId,
21
+ isListable,
22
+ isReadable,
23
+ isWriteable,
24
+ rawVersion,
25
+ rawOwnerDid,
26
+ rawAvailable,
27
+ rawErrorCode
28
+ ] = [
29
+ headers["x-space-name"],
30
+ headers["x-subscription-id"],
31
+ headers["x-listable"] === "true",
32
+ headers["x-readable"] === "true",
33
+ headers["x-writeable"] === "true",
34
+ // 新版 headers
35
+ headers["x-space-version"],
36
+ headers["x-space-owner-did"],
37
+ headers["x-space-is-available"],
38
+ headers["x-error-code"]
39
+ ];
40
+ const name = rawName ? decodeURIComponent(rawName) : "";
41
+ if (rawAvailable === void 0 || rawErrorCode === void 0) {
42
+ const isAvailable = isListable && isReadable && isWriteable;
43
+ return {
44
+ version: rawVersion || "",
45
+ name,
46
+ subscriptionId: rawSubscriptionId,
47
+ ownerDid: rawOwnerDid || "",
48
+ isAvailable,
49
+ errorCode: isAvailable ? 0 : SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED
50
+ };
51
+ }
18
52
  return {
19
- spaceName: spaceName ? decodeURIComponent(spaceName) : "",
20
- subscriptionId: headers["x-subscription-id"],
21
- ownerDid: headers["x-space-owner-did"],
22
- isAvailable: headers["x-space-is-available"] === "true",
23
- errorMessage: decodeURIComponent(headers["x-error-message"]),
24
- errorCode: parseInt(headers["x-error-code"], 10)
53
+ version: rawVersion || "",
54
+ name,
55
+ subscriptionId: rawSubscriptionId,
56
+ ownerDid: rawOwnerDid,
57
+ isAvailable: rawAvailable === "true",
58
+ errorCode: parseInt(rawErrorCode, 10)
25
59
  };
26
60
  },
27
61
  {
package/dist/es/index.js CHANGED
@@ -8,7 +8,7 @@ export { BaseConnectTo } from './components/base-connect-to/index.js';
8
8
  export { AuthConnectTo } from './components/auth-connect-to/index.js';
9
9
  export { SessionConnectTo } from './components/session-connect-to/index.js';
10
10
  export { AUTHORIZE, SPACE_CONNECT_ERROR_CODE, copyGatewayPageUrl, fixCorsErrorPageUrl } from './libs/constants.js';
11
- export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getDIDSpaceDidFromEndpoint, getDIDSpaceUrlFromEndpoint, getSpaceDidFromEndpoint, getSpaceDidFromSpaceUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, isCorsBlockedError, t } from './libs/util.js';
11
+ export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getSpaceDidFromEndpoint, getSpaceDidFromSpaceUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, getSpaceUrlFromEndpoint, isCorsBlockedError, t } from './libs/util.js';
12
12
  export { getSpaceGatewayUrl, verifySpaceUrl } from './libs/gateway.js';
13
13
  export { translations } from './locales/index.js';
14
14
  export { SpaceStatus } from './types/index.js';
@@ -13,6 +13,8 @@ export declare const SPACE_CONNECT_ERROR_CODE: {
13
13
  UNIT_LIMIT: number;
14
14
  /** 跨域限制 */
15
15
  CORS_BLOCKED: number;
16
+ /** Space 版本不兼容 */
17
+ INCOMPATIBLE: number;
16
18
  };
17
19
  export declare const AUTHORIZE: {
18
20
  DEFAULT_SCOPE: string;
@@ -12,7 +12,9 @@ const SPACE_CONNECT_ERROR_CODE = {
12
12
  /** 用量不足 */
13
13
  UNIT_LIMIT: 1006,
14
14
  /** 跨域限制 */
15
- CORS_BLOCKED: 1007
15
+ CORS_BLOCKED: 1007,
16
+ /** Space 版本不兼容 */
17
+ INCOMPATIBLE: 1008
16
18
  };
17
19
  const AUTHORIZE = {
18
20
  DEFAULT_SCOPE: "list:object read:object write:object"
@@ -11,10 +11,9 @@ type ClassStr = string | undefined | null;
11
11
  * classNames(['foo', 'bar']); // => 'foo bar'
12
12
  */
13
13
  export declare function classNames(...classes: (ClassStr | Record<string, boolean> | Array<ClassStr | Record<string, boolean>>)[]): string;
14
- export declare function getDIDSpaceDidFromEndpoint(endpoint: string): string | undefined;
15
- export declare function getDIDSpaceUrlFromEndpoint(endpoint: string): string;
16
- export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
17
14
  export declare function getSpaceDidFromEndpoint(endpoint: string): string | undefined;
15
+ export declare function getSpaceUrlFromEndpoint(endpoint: string): string;
16
+ export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
18
17
  export declare function getSpaceGatewayUrlFromEndpoint(endpoint: string): string;
19
18
  export declare function extraDIDSpacesCoreUrl(url: string): string;
20
19
  export declare function getSpaceDidFromSpaceUrl(url: string): string | undefined;
@@ -22,12 +22,12 @@ function classNames(...classes) {
22
22
  });
23
23
  return result.join(" ");
24
24
  }
25
- function getDIDSpaceDidFromEndpoint(endpoint) {
25
+ function getSpaceDidFromEndpoint(endpoint) {
26
26
  const strArray = endpoint.replace(/\/$/, "").split("/");
27
27
  const spaceDid = strArray.at(-4);
28
28
  return spaceDid;
29
29
  }
30
- function getDIDSpaceUrlFromEndpoint(endpoint) {
30
+ function getSpaceUrlFromEndpoint(endpoint) {
31
31
  const prefix = endpoint.replace(/\/api\/space\/.+/, "");
32
32
  const strArray = endpoint.replace(/\/$/, "").split("/");
33
33
  const spaceDid = strArray.at(-4);
@@ -39,13 +39,8 @@ function getSpaceNftDisplayUrlFromEndpoint(endpoint) {
39
39
  const spaceDid = strArray.at(-4);
40
40
  return joinURL(prefix, `/api/space/nft/display?spaceDid=${spaceDid}`);
41
41
  }
42
- function getSpaceDidFromEndpoint(endpoint) {
43
- const strArray = endpoint.replace(/\/$/, "").split("/");
44
- const spaceDid = strArray.at(-4);
45
- return spaceDid;
46
- }
47
42
  function getSpaceGatewayUrlFromEndpoint(endpoint) {
48
- const spaceUrl = getDIDSpaceUrlFromEndpoint(endpoint);
43
+ const spaceUrl = getSpaceUrlFromEndpoint(endpoint);
49
44
  return spaceUrl.split("/space/")[0];
50
45
  }
51
46
  function extraDIDSpacesCoreUrl(url) {
@@ -82,4 +77,4 @@ function t(key, localeOrData, data = {}) {
82
77
  return translate(translations, key, locale, "en", finalData);
83
78
  }
84
79
 
85
- export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getDIDSpaceDidFromEndpoint, getDIDSpaceUrlFromEndpoint, getSpaceDidFromEndpoint, getSpaceDidFromSpaceUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, isCorsBlockedError, t };
80
+ export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getSpaceDidFromEndpoint, getSpaceDidFromSpaceUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, getSpaceUrlFromEndpoint, isCorsBlockedError, t };
@@ -8,7 +8,8 @@ const en = flatten({
8
8
  error: "Error",
9
9
  open: "Open",
10
10
  unknown: "Unknown",
11
- invalidUrl: "Invalid url: {url}"
11
+ invalidUrl: "Invalid url: {url}",
12
+ upgrade: "Upgrade"
12
13
  },
13
14
  storage: {
14
15
  spaces: {
@@ -38,7 +39,8 @@ const en = flatten({
38
39
  invalid: "DID Spaces subscription anomaly, click this link to check",
39
40
  unitLimit: "DID Spaces free quota has been used up, click this link to pay for the upgrade",
40
41
  corsBlocked: "The connection request may fail due to CORS restrictions:\n1. Please contact the DID Space administrator to verify the relevant configuration.\n2. If you are the administrator, click the link below to view the detailed setup guide and resolve the issue.",
41
- networkError: "Network error"
42
+ networkError: "Network error",
43
+ incompatible: "The current DID Spaces version is incompatible. Please contact your administrator to make adjustments. \nIf you are the administrator, click the link below to proceed."
42
44
  },
43
45
  gateway: {
44
46
  add: {
@@ -8,7 +8,8 @@ const zh = flatten({
8
8
  error: "\u9519\u8BEF",
9
9
  open: "\u6253\u5F00",
10
10
  unknown: "\u672A\u77E5",
11
- invalidUrl: "\u65E0\u6548\u7684 url: {url}"
11
+ invalidUrl: "\u65E0\u6548\u7684 url: {url}",
12
+ upgrade: "\u5347\u7EA7"
12
13
  },
13
14
  storage: {
14
15
  spaces: {
@@ -38,7 +39,8 @@ const zh = flatten({
38
39
  invalid: "DID Spaces \u8BA2\u9605\u5F02\u5E38\uFF0C\u70B9\u51FB\u6B64\u94FE\u63A5\u68C0\u67E5",
39
40
  unitLimit: "DID Spaces \u514D\u8D39\u989D\u5EA6\u5DF2\u7528\u5B8C\uFF0C\u70B9\u51FB\u6B64\u94FE\u63A5\u4ED8\u8D39\u5347\u7EA7",
40
41
  corsBlocked: "\u8FDE\u63A5\u8BF7\u6C42\u53EF\u80FD\u56E0 CORS \u9650\u5236\u800C\u5931\u8D25\uFF1A\n1. \u8BF7\u8054\u7CFB DID Space \u7BA1\u7406\u5458\u786E\u8BA4\u76F8\u5173\u914D\u7F6E\u662F\u5426\u6B63\u786E\u3002\n2. \u5982\u679C\u60A8\u662F\u7BA1\u7406\u5458\uFF0C\u53EF\u4EE5\u70B9\u51FB\u4E0B\u65B9\u94FE\u63A5\uFF0C\u67E5\u770B\u8BE6\u7EC6\u7684\u914D\u7F6E\u6307\u5357\u5E76\u89E3\u51B3\u95EE\u9898\u3002",
41
- networkError: "\u7F51\u7EDC\u9519\u8BEF"
42
+ networkError: "\u7F51\u7EDC\u9519\u8BEF",
43
+ incompatible: "\u5F53\u524D DID Spaces \u7248\u672C\u4E0D\u517C\u5BB9\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u8FDB\u884C\u8C03\u6574\u3002\n\u5982\u679C\u60A8\u662F\u7BA1\u7406\u5458\uFF0C\u53EF\u4EE5\u5355\u51FB\u4E0B\u9762\u7684\u94FE\u63A5\u8FDB\u884C\u64CD\u4F5C\u3002"
42
44
  },
43
45
  gateway: {
44
46
  add: {
@@ -51,6 +53,9 @@ const zh = flatten({
51
53
  title: "\u8BF7\u4E3A {appName} \u51FA\u793A DID Spaces NFT",
52
54
  scan: "\u4F7F\u7528\u4F60\u7684 DID Wallet \u626B\u63CF\u4E0B\u9762\u7684\u4E8C\u7EF4\u7801\u4E3A\u5E94\u7528 {appName} \u51FA\u793A DID Spaces NFT",
53
55
  success: "\u8FDE\u63A5\u6210\u529F"
56
+ },
57
+ helperText: {
58
+ fixCorsError: "\u4FEE\u590D\u8FDE\u63A5 DID Spaces \u65F6\u7684 CORS \u9519\u8BEF"
54
59
  }
55
60
  }
56
61
  }
@@ -0,0 +1,3 @@
1
+ const version = "0.5.78";
2
+
3
+ export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/did-space-react",
3
- "version": "0.5.76",
3
+ "version": "0.5.78",
4
4
  "description": "Reusable react components for did space",
5
5
  "keywords": [
6
6
  "react",
@@ -85,8 +85,8 @@
85
85
  },
86
86
  "dependencies": {
87
87
  "@arcblock/did": "^1.18.152",
88
- "@arcblock/did-connect": "^2.10.75",
89
- "@arcblock/ux": "^2.10.75",
88
+ "@arcblock/did-connect": "^2.10.76",
89
+ "@arcblock/ux": "^2.10.76",
90
90
  "@blocklet/js-sdk": "^1.16.34-beta-20241129-100152-679bd732",
91
91
  "@blocklet/sdk": "^1.16.34-beta-20241129-100152-679bd732",
92
92
  "@mui/icons-material": "^5.16.8",
@@ -95,6 +95,7 @@
95
95
  "@mui/system": "^5.16.8",
96
96
  "ahooks": "^3.8.1",
97
97
  "axios": "^1.7.8",
98
+ "compare-versions": "^6.1.1",
98
99
  "flat": "^5.0.2",
99
100
  "is-url": "^1.2.4",
100
101
  "lodash": "^4.17.21",
@@ -127,7 +128,7 @@
127
128
  "@types/react": "^18.3.12",
128
129
  "@types/react-dom": "^18.3.1",
129
130
  "@vitejs/plugin-legacy": "^5.4.3",
130
- "@vitest/coverage-v8": "^2.1.6",
131
+ "@vitest/coverage-v8": "^2.1.8",
131
132
  "babel-plugin-inline-react-svg": "^2.0.2",
132
133
  "copyfiles": "^2.4.1",
133
134
  "eslint": "^8.57.1",
@@ -137,13 +138,13 @@
137
138
  "react-dom": "^18.3.1",
138
139
  "rollup-plugin-node-builtins": "^2.1.2",
139
140
  "storybook": "^7.6.20",
140
- "type-fest": "^4.29.1",
141
+ "type-fest": "^4.30.0",
141
142
  "typescript": "~5.5.4",
142
143
  "unbuild": "^2.0.0",
143
144
  "vite": "^5.4.11",
144
145
  "vite-plugin-babel": "^1.2.0",
145
146
  "vite-plugin-node-polyfills": "^0.22.0",
146
- "vitest": "^2.1.6"
147
+ "vitest": "^2.1.8"
147
148
  },
148
- "gitHead": "4df393e520450f2eacab119c125ba34af1629d5d"
149
+ "gitHead": "a78e40b323dff7d1dd378b6b2ef8fd805df4df4d"
149
150
  }