@blocklet/did-domain-react 0.3.39 → 0.3.41

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/README.md CHANGED
@@ -1 +1,43 @@
1
1
  # DID Domain React Components
2
+
3
+ ## Component <Buy>
4
+
5
+ Buy and Bind Domain automatically.
6
+
7
+ ```tsx
8
+ import { Buy } from '@blocklet/did-domain-react';
9
+
10
+ function App() {
11
+ const appId = window.blocklet?.appId;
12
+ const appPk = window.blocklet?.appPk;
13
+ const didDomainURL = 'https://domain.didlabs.org/app';
14
+ const locale = 'en';
15
+
16
+ return (
17
+ <Buy
18
+ delegatee={appId}
19
+ delegateePk={appPk}
20
+ didDomainURL={didDomainURL}
21
+ onSuccess={handleSuccess}
22
+ locale={locale}
23
+ variant="outlined"
24
+ />
25
+ );
26
+ }
27
+ ```
28
+
29
+ ## Component <Domain />
30
+
31
+ Display the domain information of the domain NFT.
32
+
33
+ ```tsx
34
+ import { Domain } from '@blocklet/did-domain-react';
35
+
36
+ function App() {
37
+ const locale = 'en';
38
+ const nftDid = 'bbqa2ag5a4y57ome4quqpyclhoszb5snw6faxainddq';
39
+ const didDomainURL = 'https://domain.didlabs.org/app';
40
+
41
+ return <DomainComponent locale={locale} nftDid={nftDid} didDomainURL={didDomainURL} />;
42
+ }
43
+ ```
package/es/buy.js CHANGED
@@ -10,9 +10,8 @@ import CircularProgress from "@mui/material/CircularProgress";
10
10
  import Typography from "@mui/material/Typography";
11
11
  import { useRequest as useAHooksRequest, useMemoizedFn, useSetState, useUnmount } from "ahooks";
12
12
  import { useRef } from "react";
13
- import { joinURL } from "ufo";
14
13
  import { create } from "./libs/api.js";
15
- import { openPopup } from "./libs/util.js";
14
+ import { getDidDomainServiceURL, openPopup } from "./libs/util.js";
16
15
  import { translations } from "./locales/index.js";
17
16
  var BuyState = /* @__PURE__ */ ((BuyState2) => {
18
17
  BuyState2[BuyState2["Prepare"] = 1] = "Prepare";
@@ -27,9 +26,6 @@ function Component({ delegatee, delegateePk, didDomainURL, locale, onSuccess, ..
27
26
  currentState: 1 /* Prepare */
28
27
  });
29
28
  const popup = useRef(null);
30
- const domainURLObj = new URL(didDomainURL);
31
- domainURLObj.searchParams.set("locale", locale);
32
- const api = useMemoizedFn(() => create({ baseURL: joinURL(domainURLObj.origin, domainURLObj.pathname, "api") }))();
33
29
  const onMessage = useMemoizedFn((event) => {
34
30
  if (event.data.type === "didDomain.success") {
35
31
  onSuccess?.({ nftDid: event.data?.nftDid, domain: event.data?.domain, chainHost: event.data?.chainHost });
@@ -57,10 +53,12 @@ function Component({ delegatee, delegateePk, didDomainURL, locale, onSuccess, ..
57
53
  setState({ currentState: 2 /* InProgress */ });
58
54
  sessionRequest.run();
59
55
  });
60
- const handleCreatedSession = useMemoizedFn(({ sessionId }) => {
56
+ const handleCreatedSession = useMemoizedFn(({ sessionId, baseURL }) => {
61
57
  window.addEventListener("message", onMessage);
62
- domainURLObj.searchParams.set("sessionId", sessionId);
63
- popup.current = openPopup(domainURLObj.toString());
58
+ const urlObj = new URL(baseURL);
59
+ urlObj.searchParams.set("sessionId", sessionId);
60
+ urlObj.searchParams.set("locale", locale);
61
+ popup.current = openPopup(urlObj.toString());
64
62
  const timer = setInterval(() => {
65
63
  if (popup.current?.closed) {
66
64
  clearInterval(timer);
@@ -71,11 +69,16 @@ function Component({ delegatee, delegateePk, didDomainURL, locale, onSuccess, ..
71
69
  });
72
70
  const sessionRequest = useAHooksRequest(
73
71
  async () => {
74
- const { data } = await api.post("/payment/session", {
72
+ const serviceURL = await getDidDomainServiceURL(didDomainURL);
73
+ if (!serviceURL) {
74
+ return null;
75
+ }
76
+ const apiRequest = create({ baseURL: serviceURL.api });
77
+ const { data } = await apiRequest.post("/payment/session", {
75
78
  delegatee,
76
79
  delegateePk
77
80
  });
78
- return handleCreatedSession({ sessionId: data.sessionId });
81
+ return handleCreatedSession({ sessionId: data.sessionId, baseURL: serviceURL.base });
79
82
  },
80
83
  {
81
84
  manual: true,
package/es/domain.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare function Domain({ nftDid, didDomainURL, locale, sx, }: {
3
3
  didDomainURL: string;
4
4
  locale: string;
5
5
  sx?: any;
6
- }): import("react").JSX.Element;
6
+ }): import("react").JSX.Element | null;
7
7
  export declare namespace Domain {
8
8
  var defaultProps: {
9
9
  sx: {};
package/es/domain.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
+ import { CircularProgress } from "@mui/material";
3
4
  import Box from "@mui/material/Box";
4
5
  import Popover from "@mui/material/Popover";
5
6
  import { useTheme } from "@mui/material/styles";
6
7
  import useMediaQuery from "@mui/material/useMediaQuery";
7
8
  import { useRef } from "react";
9
+ import { useAsync } from "react-use";
8
10
  import useSetState from "react-use/lib/useSetState";
9
11
  import { joinURL } from "ufo";
10
- import { mergeSx } from "./libs/util.js";
12
+ import { getDidDomainServiceURL, mergeSx } from "./libs/util.js";
11
13
  export function Domain({
12
14
  nftDid,
13
15
  didDomainURL,
@@ -28,7 +30,20 @@ export function Domain({
28
30
  const handlePopoverClose = () => {
29
31
  setState({ popoverAnchorEl: null });
30
32
  };
31
- const iframeSrc = joinURL(didDomainURL, `/app/embed/domain?nft-did=${nftDid}&locale=${locale}`);
33
+ const urlState = useAsync(async () => {
34
+ const result = await getDidDomainServiceURL(didDomainURL);
35
+ if (!result) {
36
+ return null;
37
+ }
38
+ return result.base;
39
+ });
40
+ if (!urlState.value) {
41
+ return null;
42
+ }
43
+ if (urlState.loading) {
44
+ return /* @__PURE__ */ jsx(CircularProgress, {});
45
+ }
46
+ const iframeSrc = joinURL(urlState.value, `/embed/domain?nft-did=${nftDid}&locale=${locale}`);
32
47
  return /* @__PURE__ */ jsxs(Fragment, { children: [
33
48
  /* @__PURE__ */ jsx(
34
49
  Box,
package/es/libs/util.d.ts CHANGED
@@ -19,3 +19,7 @@ export declare const openPopup: (url: string, { width, height, name }?: {
19
19
  height?: number | undefined;
20
20
  name?: string | undefined;
21
21
  }) => Window;
22
+ export declare const getDidDomainServiceURL: (url: string) => Promise<{
23
+ base: string;
24
+ api: string;
25
+ } | null>;
package/es/libs/util.js CHANGED
@@ -1,4 +1,5 @@
1
- import { withQuery } from "ufo";
1
+ import { joinURL, withQuery } from "ufo";
2
+ import { create as createAxios } from "./api.js";
2
3
  export const SEARCH_BUTTON_WIDTH = 120;
3
4
  export const COMMON_REQUEST_OPTIONS = {
4
5
  debounceWait: 500,
@@ -71,3 +72,20 @@ export const openPopup = (url, { width = 600, height = 700, name = "did-domain:p
71
72
  });
72
73
  return popup;
73
74
  };
75
+ const DID_DOMAIN_SERVICE_DID = "z2qaGosS3rZ7m5ttP3Nd4V4qczR9TryTcRV4p";
76
+ export const getDidDomainServiceURL = async (url) => {
77
+ if (!url || !url?.trim()) {
78
+ return null;
79
+ }
80
+ const axios = createAxios();
81
+ const urlObj = new URL(url);
82
+ urlObj.pathname = "__blocklet__.js";
83
+ urlObj.searchParams.set("type", "json");
84
+ const { data } = await axios.get(urlObj.toString());
85
+ const component = data?.componentMountPoints?.find((x) => x.did === DID_DOMAIN_SERVICE_DID);
86
+ const resultUrlObj = new URL(url);
87
+ resultUrlObj.pathname = component?.mountPoint;
88
+ const baseURL = resultUrlObj.toString();
89
+ const apiURL = joinURL(baseURL, "/api");
90
+ return { base: baseURL, api: apiURL };
91
+ };
package/lib/buy.js CHANGED
@@ -16,7 +16,6 @@ var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularPr
16
16
  var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
17
17
  var _ahooks = require("ahooks");
18
18
  var _react = require("react");
19
- var _ufo = require("ufo");
20
19
  var _api = require("./libs/api");
21
20
  var _util = require("./libs/util");
22
21
  var _locales = require("./locales");
@@ -43,11 +42,6 @@ function Component({
43
42
  currentState: 1 /* Prepare */
44
43
  });
45
44
  const popup = (0, _react.useRef)(null);
46
- const domainURLObj = new URL(didDomainURL);
47
- domainURLObj.searchParams.set("locale", locale);
48
- const api = (0, _ahooks.useMemoizedFn)(() => (0, _api.create)({
49
- baseURL: (0, _ufo.joinURL)(domainURLObj.origin, domainURLObj.pathname, "api")
50
- }))();
51
45
  const onMessage = (0, _ahooks.useMemoizedFn)(event => {
52
46
  if (event.data.type === "didDomain.success") {
53
47
  onSuccess?.({
@@ -88,11 +82,14 @@ function Component({
88
82
  sessionRequest.run();
89
83
  });
90
84
  const handleCreatedSession = (0, _ahooks.useMemoizedFn)(({
91
- sessionId
85
+ sessionId,
86
+ baseURL
92
87
  }) => {
93
88
  window.addEventListener("message", onMessage);
94
- domainURLObj.searchParams.set("sessionId", sessionId);
95
- popup.current = (0, _util.openPopup)(domainURLObj.toString());
89
+ const urlObj = new URL(baseURL);
90
+ urlObj.searchParams.set("sessionId", sessionId);
91
+ urlObj.searchParams.set("locale", locale);
92
+ popup.current = (0, _util.openPopup)(urlObj.toString());
96
93
  const timer = setInterval(() => {
97
94
  if (popup.current?.closed) {
98
95
  clearInterval(timer);
@@ -102,14 +99,22 @@ function Component({
102
99
  return () => clearInterval(timer);
103
100
  });
104
101
  const sessionRequest = (0, _ahooks.useRequest)(async () => {
102
+ const serviceURL = await (0, _util.getDidDomainServiceURL)(didDomainURL);
103
+ if (!serviceURL) {
104
+ return null;
105
+ }
106
+ const apiRequest = (0, _api.create)({
107
+ baseURL: serviceURL.api
108
+ });
105
109
  const {
106
110
  data
107
- } = await api.post("/payment/session", {
111
+ } = await apiRequest.post("/payment/session", {
108
112
  delegatee,
109
113
  delegateePk
110
114
  });
111
115
  return handleCreatedSession({
112
- sessionId: data.sessionId
116
+ sessionId: data.sessionId,
117
+ baseURL: serviceURL.base
113
118
  });
114
119
  }, {
115
120
  manual: true,
package/lib/domain.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare function Domain({ nftDid, didDomainURL, locale, sx, }: {
3
3
  didDomainURL: string;
4
4
  locale: string;
5
5
  sx?: any;
6
- }): import("react").JSX.Element;
6
+ }): import("react").JSX.Element | null;
7
7
  export declare namespace Domain {
8
8
  var defaultProps: {
9
9
  sx: {};
package/lib/domain.js CHANGED
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Domain = Domain;
7
7
  var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _context = require("@arcblock/ux/lib/Locale/context");
9
+ var _material = require("@mui/material");
9
10
  var _Box = _interopRequireDefault(require("@mui/material/Box"));
10
11
  var _Popover = _interopRequireDefault(require("@mui/material/Popover"));
11
12
  var _styles = require("@mui/material/styles");
12
13
  var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
13
14
  var _react = require("react");
15
+ var _reactUse = require("react-use");
14
16
  var _useSetState = _interopRequireDefault(require("react-use/lib/useSetState"));
15
17
  var _ufo = require("ufo");
16
18
  var _util = require("./libs/util");
@@ -41,7 +43,20 @@ function Domain({
41
43
  popoverAnchorEl: null
42
44
  });
43
45
  };
44
- const iframeSrc = (0, _ufo.joinURL)(didDomainURL, `/app/embed/domain?nft-did=${nftDid}&locale=${locale}`);
46
+ const urlState = (0, _reactUse.useAsync)(async () => {
47
+ const result = await (0, _util.getDidDomainServiceURL)(didDomainURL);
48
+ if (!result) {
49
+ return null;
50
+ }
51
+ return result.base;
52
+ });
53
+ if (!urlState.value) {
54
+ return null;
55
+ }
56
+ if (urlState.loading) {
57
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {});
58
+ }
59
+ const iframeSrc = (0, _ufo.joinURL)(urlState.value, `/embed/domain?nft-did=${nftDid}&locale=${locale}`);
45
60
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
46
61
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_Box.default, {
47
62
  component: "img",
@@ -19,3 +19,7 @@ export declare const openPopup: (url: string, { width, height, name }?: {
19
19
  height?: number | undefined;
20
20
  name?: string | undefined;
21
21
  }) => Window;
22
+ export declare const getDidDomainServiceURL: (url: string) => Promise<{
23
+ base: string;
24
+ api: string;
25
+ } | null>;
package/lib/libs/util.js CHANGED
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.openPopup = exports.mergeSx = exports.getChainHost = exports.formatLocale = exports.formatError = exports.SEARCH_BUTTON_WIDTH = exports.COMMON_REQUEST_OPTIONS = void 0;
6
+ exports.openPopup = exports.mergeSx = exports.getDidDomainServiceURL = exports.getChainHost = exports.formatLocale = exports.formatError = exports.SEARCH_BUTTON_WIDTH = exports.COMMON_REQUEST_OPTIONS = void 0;
7
7
  var _ufo = require("ufo");
8
+ var _api = require("./api");
8
9
  const SEARCH_BUTTON_WIDTH = exports.SEARCH_BUTTON_WIDTH = 120;
9
10
  const COMMON_REQUEST_OPTIONS = exports.COMMON_REQUEST_OPTIONS = {
10
11
  debounceWait: 500,
@@ -80,4 +81,27 @@ const openPopup = (url, {
80
81
  });
81
82
  return popup;
82
83
  };
83
- exports.openPopup = openPopup;
84
+ exports.openPopup = openPopup;
85
+ const DID_DOMAIN_SERVICE_DID = "z2qaGosS3rZ7m5ttP3Nd4V4qczR9TryTcRV4p";
86
+ const getDidDomainServiceURL = async url => {
87
+ if (!url || !url?.trim()) {
88
+ return null;
89
+ }
90
+ const axios = (0, _api.create)();
91
+ const urlObj = new URL(url);
92
+ urlObj.pathname = "__blocklet__.js";
93
+ urlObj.searchParams.set("type", "json");
94
+ const {
95
+ data
96
+ } = await axios.get(urlObj.toString());
97
+ const component = data?.componentMountPoints?.find(x => x.did === DID_DOMAIN_SERVICE_DID);
98
+ const resultUrlObj = new URL(url);
99
+ resultUrlObj.pathname = component?.mountPoint;
100
+ const baseURL = resultUrlObj.toString();
101
+ const apiURL = (0, _ufo.joinURL)(baseURL, "/api");
102
+ return {
103
+ base: baseURL,
104
+ api: apiURL
105
+ };
106
+ };
107
+ exports.getDidDomainServiceURL = getDidDomainServiceURL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/did-domain-react",
3
- "version": "0.3.39",
3
+ "version": "0.3.41",
4
4
  "description": "Reusable react components for DID Domain",
5
5
  "keywords": [
6
6
  "react",
@@ -54,13 +54,6 @@
54
54
  }
55
55
  },
56
56
  "dependencies": {
57
- "@arcblock/did-connect": "^2.10.69",
58
- "@arcblock/ux": "^2.10.68",
59
- "@blocklet/js-sdk": "^1.16.33",
60
- "@mui/icons-material": "^5.16.7",
61
- "@mui/lab": "^5.0.0-alpha.173",
62
- "@mui/material": "^5.16.7",
63
- "@mui/system": "^5.16.7",
64
57
  "ahooks": "^3.8.1",
65
58
  "axios": "^1.7.8",
66
59
  "flat": "^5.0.2",
@@ -70,6 +63,13 @@
70
63
  "ufo": "^1.5.4"
71
64
  },
72
65
  "peerDependencies": {
66
+ "@arcblock/did-connect": "^2.10.0",
67
+ "@arcblock/ux": "^2.10.0",
68
+ "@blocklet/js-sdk": "^1.16.0",
69
+ "@mui/icons-material": "^5.16.7",
70
+ "@mui/lab": "^5.0.0-alpha.173",
71
+ "@mui/material": "^5.16.7",
72
+ "@mui/system": "^5.16.7",
73
73
  "react": ">=18.1.0"
74
74
  },
75
75
  "publishConfig": {
@@ -102,5 +102,5 @@
102
102
  "vite-plugin-babel": "^1.2.0",
103
103
  "vite-plugin-node-polyfills": "^0.21.0"
104
104
  },
105
- "gitHead": "55d08a148486bcc6edac3080778b0654cba171d9"
105
+ "gitHead": "b7a8de92dd2d2ddc4af3b068a3cff1fe2af01e68"
106
106
  }
package/src/buy.tsx CHANGED
@@ -11,10 +11,9 @@ import CircularProgress from '@mui/material/CircularProgress';
11
11
  import Typography from '@mui/material/Typography';
12
12
  import { useRequest as useAHooksRequest, useMemoizedFn, useSetState, useUnmount } from 'ahooks';
13
13
  import { useRef } from 'react';
14
- import { joinURL } from 'ufo';
15
14
 
16
15
  import { create } from './libs/api';
17
- import { openPopup } from './libs/util';
16
+ import { getDidDomainServiceURL, openPopup } from './libs/util';
18
17
  import { translations } from './locales';
19
18
 
20
19
  enum BuyState {
@@ -38,10 +37,6 @@ function Component({ delegatee, delegateePk, didDomainURL, locale, onSuccess, ..
38
37
  currentState: BuyState.Prepare,
39
38
  });
40
39
  const popup = useRef<Window | null>(null);
41
- const domainURLObj = new URL(didDomainURL);
42
- domainURLObj.searchParams.set('locale', locale);
43
-
44
- const api = useMemoizedFn(() => create({ baseURL: joinURL(domainURLObj.origin, domainURLObj.pathname, 'api') }))();
45
40
 
46
41
  const onMessage = useMemoizedFn((event: MessageEvent) => {
47
42
  if (event.data.type === 'didDomain.success') {
@@ -75,10 +70,13 @@ function Component({ delegatee, delegateePk, didDomainURL, locale, onSuccess, ..
75
70
  sessionRequest.run();
76
71
  });
77
72
 
78
- const handleCreatedSession = useMemoizedFn(({ sessionId }: { sessionId: string }) => {
73
+ const handleCreatedSession = useMemoizedFn(({ sessionId, baseURL }: { sessionId: string; baseURL: string }) => {
79
74
  window.addEventListener('message', onMessage);
80
- domainURLObj.searchParams.set('sessionId', sessionId);
81
- popup.current = openPopup(domainURLObj.toString());
75
+ const urlObj = new URL(baseURL);
76
+
77
+ urlObj.searchParams.set('sessionId', sessionId);
78
+ urlObj.searchParams.set('locale', locale);
79
+ popup.current = openPopup(urlObj.toString());
82
80
 
83
81
  const timer = setInterval(() => {
84
82
  if (popup.current?.closed) {
@@ -92,11 +90,19 @@ function Component({ delegatee, delegateePk, didDomainURL, locale, onSuccess, ..
92
90
 
93
91
  const sessionRequest = useAHooksRequest(
94
92
  async () => {
95
- const { data } = await api.post('/payment/session', {
93
+ const serviceURL = await getDidDomainServiceURL(didDomainURL);
94
+ if (!serviceURL) {
95
+ return null;
96
+ }
97
+
98
+ const apiRequest = create({ baseURL: serviceURL.api });
99
+
100
+ const { data } = await apiRequest.post('/payment/session', {
96
101
  delegatee,
97
102
  delegateePk,
98
103
  });
99
- return handleCreatedSession({ sessionId: data.sessionId });
104
+
105
+ return handleCreatedSession({ sessionId: data.sessionId, baseURL: serviceURL.base });
100
106
  },
101
107
  {
102
108
  manual: true,
package/src/domain.tsx CHANGED
@@ -1,13 +1,15 @@
1
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
+ import { CircularProgress } from '@mui/material';
2
3
  import Box from '@mui/material/Box';
3
4
  import Popover from '@mui/material/Popover';
4
5
  import { useTheme } from '@mui/material/styles';
5
6
  import useMediaQuery from '@mui/material/useMediaQuery';
6
7
  import { useRef } from 'react';
8
+ import { useAsync } from 'react-use';
7
9
  import useSetState from 'react-use/lib/useSetState';
8
10
  import { joinURL } from 'ufo';
9
11
 
10
- import { mergeSx } from './libs/util';
12
+ import { getDidDomainServiceURL, mergeSx } from './libs/util';
11
13
 
12
14
  export function Domain({
13
15
  nftDid,
@@ -37,7 +39,24 @@ export function Domain({
37
39
  setState({ popoverAnchorEl: null });
38
40
  };
39
41
 
40
- const iframeSrc = joinURL(didDomainURL, `/app/embed/domain?nft-did=${nftDid}&locale=${locale}`);
42
+ const urlState = useAsync(async () => {
43
+ const result = await getDidDomainServiceURL(didDomainURL);
44
+ if (!result) {
45
+ return null;
46
+ }
47
+
48
+ return result.base;
49
+ });
50
+
51
+ if (!urlState.value) {
52
+ return null;
53
+ }
54
+
55
+ if (urlState.loading) {
56
+ return <CircularProgress />;
57
+ }
58
+
59
+ const iframeSrc = joinURL(urlState.value, `/embed/domain?nft-did=${nftDid}&locale=${locale}`);
41
60
 
42
61
  return (
43
62
  <>
package/src/libs/util.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { withQuery } from 'ufo';
1
+ import { joinURL, withQuery } from 'ufo';
2
+
3
+ import { create as createAxios } from './api';
2
4
 
3
5
  export const SEARCH_BUTTON_WIDTH = 120;
4
6
 
@@ -98,3 +100,27 @@ export const openPopup = (url: string, { width = 600, height = 700, name = 'did-
98
100
  });
99
101
  return popup;
100
102
  };
103
+
104
+ const DID_DOMAIN_SERVICE_DID = 'z2qaGosS3rZ7m5ttP3Nd4V4qczR9TryTcRV4p';
105
+
106
+ export const getDidDomainServiceURL = async (url: string): Promise<{ base: string; api: string } | null> => {
107
+ if (!url || !url?.trim()) {
108
+ return null;
109
+ }
110
+
111
+ const axios = createAxios();
112
+ const urlObj = new URL(url);
113
+ urlObj.pathname = '__blocklet__.js';
114
+ urlObj.searchParams.set('type', 'json');
115
+ const { data } = await axios.get(urlObj.toString());
116
+
117
+ const component = data?.componentMountPoints?.find((x: any) => x.did === DID_DOMAIN_SERVICE_DID);
118
+
119
+ const resultUrlObj = new URL(url);
120
+ resultUrlObj.pathname = component?.mountPoint;
121
+
122
+ const baseURL = resultUrlObj.toString();
123
+ const apiURL = joinURL(baseURL, '/api');
124
+
125
+ return { base: baseURL, api: apiURL };
126
+ };