@calimero-network/mero-react 10.2.1 → 10.3.0
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 +18 -1
- package/dist/index.cjs +29 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +29 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -140,6 +140,8 @@ interface MeroContextValue {
|
|
|
140
140
|
* and events only for contexts it is a member of.
|
|
141
141
|
*/
|
|
142
142
|
isDelegated: boolean;
|
|
143
|
+
/** True when the node serves this page from the app's own origin (see `MeroProviderConfig.servedByNode`). */
|
|
144
|
+
servedByNode?: boolean;
|
|
143
145
|
/**
|
|
144
146
|
* What this connection may do, so an app asks WHAT IS ALLOWED instead of
|
|
145
147
|
* which transport it runs on. A node login can do everything; an account on
|
|
@@ -200,6 +202,13 @@ interface MeroProviderConfig {
|
|
|
200
202
|
* rejected and a security error is logged.
|
|
201
203
|
*/
|
|
202
204
|
allowedNodeUrls?: string[];
|
|
205
|
+
/**
|
|
206
|
+
* Set when a node serves this page from the app's own origin
|
|
207
|
+
* (`{label}.localhost:2428`). The node is then `window.location.origin`: the
|
|
208
|
+
* client talks to it there whatever the callback's `node_url` says, and
|
|
209
|
+
* `ConnectButton` skips the node dialog and goes straight to login.
|
|
210
|
+
*/
|
|
211
|
+
servedByNode?: boolean;
|
|
203
212
|
/**
|
|
204
213
|
* Token store for access/refresh tokens. Defaults to a localStorage-backed
|
|
205
214
|
* store that persists across reloads.
|
|
@@ -261,7 +270,7 @@ declare function getPermissionsForMode(mode: AppMode): string[];
|
|
|
261
270
|
interface MeroProviderProps extends MeroProviderConfig {
|
|
262
271
|
children: React__default.ReactNode;
|
|
263
272
|
}
|
|
264
|
-
declare function MeroProvider({ children, mode, packageName, packageVersion, registryUrl, cloudBaseUrl, timeoutMs, allowedNodeUrls, tokenStore: tokenStoreProp, }: MeroProviderProps): react_jsx_runtime.JSX.Element;
|
|
273
|
+
declare function MeroProvider({ children, mode, packageName, packageVersion, registryUrl, cloudBaseUrl, timeoutMs, allowedNodeUrls, servedByNode, tokenStore: tokenStoreProp, }: MeroProviderProps): react_jsx_runtime.JSX.Element;
|
|
265
274
|
declare function useMero(): MeroContextValue;
|
|
266
275
|
|
|
267
276
|
/**
|
|
@@ -342,8 +351,9 @@ declare function cssVar(theme: ResolvedMeroTheme, key: keyof MeroTheme): string;
|
|
|
342
351
|
interface ConnectButtonProps {
|
|
343
352
|
/**
|
|
344
353
|
* Connection behaviour. `Custom` (object form) connects straight to the
|
|
345
|
-
* given URL, skipping the modal; every other value opens the LoginModal
|
|
346
|
-
*
|
|
354
|
+
* given URL, skipping the modal; every other value opens the LoginModal
|
|
355
|
+
* (local node discovery + manual URL entry). A page the node serves
|
|
356
|
+
* (`servedByNode`) skips the modal and logs in at its own origin.
|
|
347
357
|
*/
|
|
348
358
|
connectionType?: ConnectionType | CustomConnectionConfig;
|
|
349
359
|
/** Custom class name */
|
package/dist/index.d.ts
CHANGED
|
@@ -140,6 +140,8 @@ interface MeroContextValue {
|
|
|
140
140
|
* and events only for contexts it is a member of.
|
|
141
141
|
*/
|
|
142
142
|
isDelegated: boolean;
|
|
143
|
+
/** True when the node serves this page from the app's own origin (see `MeroProviderConfig.servedByNode`). */
|
|
144
|
+
servedByNode?: boolean;
|
|
143
145
|
/**
|
|
144
146
|
* What this connection may do, so an app asks WHAT IS ALLOWED instead of
|
|
145
147
|
* which transport it runs on. A node login can do everything; an account on
|
|
@@ -200,6 +202,13 @@ interface MeroProviderConfig {
|
|
|
200
202
|
* rejected and a security error is logged.
|
|
201
203
|
*/
|
|
202
204
|
allowedNodeUrls?: string[];
|
|
205
|
+
/**
|
|
206
|
+
* Set when a node serves this page from the app's own origin
|
|
207
|
+
* (`{label}.localhost:2428`). The node is then `window.location.origin`: the
|
|
208
|
+
* client talks to it there whatever the callback's `node_url` says, and
|
|
209
|
+
* `ConnectButton` skips the node dialog and goes straight to login.
|
|
210
|
+
*/
|
|
211
|
+
servedByNode?: boolean;
|
|
203
212
|
/**
|
|
204
213
|
* Token store for access/refresh tokens. Defaults to a localStorage-backed
|
|
205
214
|
* store that persists across reloads.
|
|
@@ -261,7 +270,7 @@ declare function getPermissionsForMode(mode: AppMode): string[];
|
|
|
261
270
|
interface MeroProviderProps extends MeroProviderConfig {
|
|
262
271
|
children: React__default.ReactNode;
|
|
263
272
|
}
|
|
264
|
-
declare function MeroProvider({ children, mode, packageName, packageVersion, registryUrl, cloudBaseUrl, timeoutMs, allowedNodeUrls, tokenStore: tokenStoreProp, }: MeroProviderProps): react_jsx_runtime.JSX.Element;
|
|
273
|
+
declare function MeroProvider({ children, mode, packageName, packageVersion, registryUrl, cloudBaseUrl, timeoutMs, allowedNodeUrls, servedByNode, tokenStore: tokenStoreProp, }: MeroProviderProps): react_jsx_runtime.JSX.Element;
|
|
265
274
|
declare function useMero(): MeroContextValue;
|
|
266
275
|
|
|
267
276
|
/**
|
|
@@ -342,8 +351,9 @@ declare function cssVar(theme: ResolvedMeroTheme, key: keyof MeroTheme): string;
|
|
|
342
351
|
interface ConnectButtonProps {
|
|
343
352
|
/**
|
|
344
353
|
* Connection behaviour. `Custom` (object form) connects straight to the
|
|
345
|
-
* given URL, skipping the modal; every other value opens the LoginModal
|
|
346
|
-
*
|
|
354
|
+
* given URL, skipping the modal; every other value opens the LoginModal
|
|
355
|
+
* (local node discovery + manual URL entry). A page the node serves
|
|
356
|
+
* (`servedByNode`) skips the modal and logs in at its own origin.
|
|
347
357
|
*/
|
|
348
358
|
connectionType?: ConnectionType | CustomConnectionConfig;
|
|
349
359
|
/** Custom class name */
|
package/dist/index.js
CHANGED
|
@@ -346,8 +346,10 @@ function MeroProvider({
|
|
|
346
346
|
cloudBaseUrl,
|
|
347
347
|
timeoutMs = 3e4,
|
|
348
348
|
allowedNodeUrls,
|
|
349
|
+
servedByNode,
|
|
349
350
|
tokenStore: tokenStoreProp
|
|
350
351
|
}) {
|
|
352
|
+
const ownOrigin = servedByNode && isBrowser ? window.location.origin : null;
|
|
351
353
|
const tokenStore = useMemo(
|
|
352
354
|
() => tokenStoreProp ?? new LocalStorageTokenStore(),
|
|
353
355
|
[tokenStoreProp]
|
|
@@ -359,7 +361,7 @@ function MeroProvider({
|
|
|
359
361
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
360
362
|
const [isOnline, setIsOnline] = useState(true);
|
|
361
363
|
const [isLoading, setIsLoading] = useState(true);
|
|
362
|
-
const [nodeUrl, setNodeUrlState] = useState(() => getNodeUrl());
|
|
364
|
+
const [nodeUrl, setNodeUrlState] = useState(() => ownOrigin ?? getNodeUrl());
|
|
363
365
|
const [applicationId, setApplicationIdState] = useState(
|
|
364
366
|
() => getApplicationId() || null
|
|
365
367
|
);
|
|
@@ -377,14 +379,14 @@ function MeroProvider({
|
|
|
377
379
|
meroRef.current.close();
|
|
378
380
|
}
|
|
379
381
|
const instance = new MeroJs({
|
|
380
|
-
baseUrl: url,
|
|
382
|
+
baseUrl: ownOrigin ?? url,
|
|
381
383
|
tokenStore,
|
|
382
384
|
timeoutMs
|
|
383
385
|
});
|
|
384
386
|
meroRef.current = instance;
|
|
385
387
|
return instance;
|
|
386
388
|
},
|
|
387
|
-
[timeoutMs, tokenStore]
|
|
389
|
+
[timeoutMs, tokenStore, ownOrigin]
|
|
388
390
|
);
|
|
389
391
|
const checkAuth = useCallback(
|
|
390
392
|
async (instance) => {
|
|
@@ -442,12 +444,12 @@ function MeroProvider({
|
|
|
442
444
|
setDelegated(null);
|
|
443
445
|
setMero(null);
|
|
444
446
|
setIsAuthenticated(false);
|
|
445
|
-
setNodeUrlState(
|
|
447
|
+
setNodeUrlState(ownOrigin);
|
|
446
448
|
setApplicationIdState(null);
|
|
447
449
|
setContextIdState(null);
|
|
448
450
|
setContextIdentityState(null);
|
|
449
451
|
meroRef.current = null;
|
|
450
|
-
}, [tokenStore]);
|
|
452
|
+
}, [tokenStore, ownOrigin]);
|
|
451
453
|
useEffect(() => {
|
|
452
454
|
if (!delegated) return;
|
|
453
455
|
const relayUrl = (contextId ? relayForContext(delegated.account, contextId) : null) ?? delegated.relayUrl;
|
|
@@ -514,7 +516,7 @@ function MeroProvider({
|
|
|
514
516
|
if (callback) {
|
|
515
517
|
const initiatedNodeUrl = getNodeUrl();
|
|
516
518
|
const tokenNodeUrl = getTokenNodeUrl() ?? initiatedNodeUrl;
|
|
517
|
-
const { url, rejected } = resolveTrustedNodeUrl({
|
|
519
|
+
const { url, rejected } = ownOrigin ? { url: ownOrigin, rejected: false } : resolveTrustedNodeUrl({
|
|
518
520
|
candidate: callback.nodeUrl,
|
|
519
521
|
initiated: initiatedNodeUrl,
|
|
520
522
|
allowedNodeUrls
|
|
@@ -558,7 +560,7 @@ function MeroProvider({
|
|
|
558
560
|
nodeFromCallback = url;
|
|
559
561
|
}
|
|
560
562
|
}
|
|
561
|
-
const savedUrl = nodeFromCallback || getNodeUrl();
|
|
563
|
+
const savedUrl = nodeFromCallback || ownOrigin || getNodeUrl();
|
|
562
564
|
if (!savedUrl) {
|
|
563
565
|
if (active) setIsLoading(false);
|
|
564
566
|
return;
|
|
@@ -582,7 +584,7 @@ function MeroProvider({
|
|
|
582
584
|
return () => {
|
|
583
585
|
active = false;
|
|
584
586
|
};
|
|
585
|
-
}, [createMeroInstance, checkAuth, allowedNodeUrls, delegated]);
|
|
587
|
+
}, [createMeroInstance, checkAuth, allowedNodeUrls, delegated, ownOrigin]);
|
|
586
588
|
useEffect(() => {
|
|
587
589
|
if (!isAuthenticated || !meroRef.current) return;
|
|
588
590
|
let active = true;
|
|
@@ -673,6 +675,7 @@ function MeroProvider({
|
|
|
673
675
|
connectToNode,
|
|
674
676
|
connectWithAccount,
|
|
675
677
|
isDelegated: delegated !== null,
|
|
678
|
+
servedByNode: ownOrigin !== null,
|
|
676
679
|
admin,
|
|
677
680
|
can: delegated !== null ? { createNamespace: Boolean(packageName), createContext: true, invite: true, upgrade: false } : { createNamespace: true, createContext: true, invite: true, upgrade: true },
|
|
678
681
|
app: { packageName, packageVersion, registryUrl },
|
|
@@ -680,7 +683,7 @@ function MeroProvider({
|
|
|
680
683
|
logout,
|
|
681
684
|
isLoading
|
|
682
685
|
}),
|
|
683
|
-
[mero, admin, isAuthenticated, isOnline, nodeUrl, applicationId, contextId, contextIdentity, connectToNode, connectWithAccount, delegated, logout, isLoading, packageName, packageVersion, registryUrl, cloudBaseUrl]
|
|
686
|
+
[mero, admin, isAuthenticated, isOnline, nodeUrl, applicationId, contextId, contextIdentity, connectToNode, connectWithAccount, delegated, ownOrigin, logout, isLoading, packageName, packageVersion, registryUrl, cloudBaseUrl]
|
|
684
687
|
);
|
|
685
688
|
return /* @__PURE__ */ jsx(MeroContext.Provider, { value: contextValue, children });
|
|
686
689
|
}
|
|
@@ -1332,7 +1335,8 @@ function LoginModal({
|
|
|
1332
1335
|
cloudOnDesktop = false,
|
|
1333
1336
|
initialTab: initialTabProp
|
|
1334
1337
|
}) {
|
|
1335
|
-
const
|
|
1338
|
+
const servedByNode = useContext(MeroContext)?.servedByNode ?? false;
|
|
1339
|
+
const cloudAllowed = !servedByNode && (cloudOnDesktop || !isDesktopWindow());
|
|
1336
1340
|
const ownCloud = cloud === void 0 && cloudAllowed;
|
|
1337
1341
|
const own = useAccountEnrolment({ enabled: ownCloud });
|
|
1338
1342
|
const cloudTab = useMemo(
|
|
@@ -1374,10 +1378,13 @@ function LoginModal({
|
|
|
1374
1378
|
setCustomUrl(savedUrl);
|
|
1375
1379
|
}
|
|
1376
1380
|
}, []);
|
|
1381
|
+
useEffect(() => {
|
|
1382
|
+
if (isOpen && servedByNode) onConnect(window.location.origin);
|
|
1383
|
+
}, [isOpen, servedByNode]);
|
|
1377
1384
|
const [scanNonce, setScanNonce] = useState(0);
|
|
1378
1385
|
const portsKey = useMemo(() => localNodePorts.join(","), [localNodePorts]);
|
|
1379
1386
|
useEffect(() => {
|
|
1380
|
-
if (!isOpen) {
|
|
1387
|
+
if (!isOpen || servedByNode) {
|
|
1381
1388
|
return;
|
|
1382
1389
|
}
|
|
1383
1390
|
const controller2 = new AbortController();
|
|
@@ -1398,7 +1405,7 @@ function LoginModal({
|
|
|
1398
1405
|
active = false;
|
|
1399
1406
|
controller2.abort();
|
|
1400
1407
|
};
|
|
1401
|
-
}, [isOpen, portsKey, scanNonce]);
|
|
1408
|
+
}, [isOpen, servedByNode, portsKey, scanNonce]);
|
|
1402
1409
|
const isCustom = selected === CUSTOM_SELECTION;
|
|
1403
1410
|
const hasDiscovered = discovered.length > 0;
|
|
1404
1411
|
const canConnect = !loading && !discovering && (isCustom ? isValidUrl(customUrl) : true);
|
|
@@ -1433,7 +1440,7 @@ function LoginModal({
|
|
|
1433
1440
|
setLoading(false);
|
|
1434
1441
|
}
|
|
1435
1442
|
}, [selected, customUrl, onConnect]);
|
|
1436
|
-
if (!isOpen) {
|
|
1443
|
+
if (!isOpen || servedByNode) {
|
|
1437
1444
|
return null;
|
|
1438
1445
|
}
|
|
1439
1446
|
const showManualInput = isCustom;
|
|
@@ -1711,8 +1718,8 @@ function ConnectButton({
|
|
|
1711
1718
|
cloud: cloudProp,
|
|
1712
1719
|
accountDefaults
|
|
1713
1720
|
}) {
|
|
1714
|
-
const
|
|
1715
|
-
const
|
|
1721
|
+
const { isAuthenticated, connectToNode, logout, nodeUrl, isOnline, isDelegated, servedByNode } = useMero();
|
|
1722
|
+
const cloud = !servedByNode && (cloudProp ?? !isDesktopWindow());
|
|
1716
1723
|
const enrolment = useAccountEnrolment({
|
|
1717
1724
|
walletUrl: accountDefaults?.walletUrl,
|
|
1718
1725
|
enabled: cloud
|
|
@@ -1755,6 +1762,10 @@ function ConnectButton({
|
|
|
1755
1762
|
}, [label]);
|
|
1756
1763
|
const buttonClassName = logoOnly ? "mero-logo-only" : "";
|
|
1757
1764
|
const handleConnect = () => {
|
|
1765
|
+
if (servedByNode) {
|
|
1766
|
+
connectToNode(window.location.origin);
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1758
1769
|
if (typeof connectionType === "object" && connectionType.type === "custom" /* Custom */) {
|
|
1759
1770
|
connectToNode(connectionType.url);
|
|
1760
1771
|
return;
|
|
@@ -1893,8 +1904,8 @@ function ConnectButtonAccount({
|
|
|
1893
1904
|
defaults = {},
|
|
1894
1905
|
cloud: cloudProp
|
|
1895
1906
|
}) {
|
|
1896
|
-
const
|
|
1897
|
-
const
|
|
1907
|
+
const { isAuthenticated, isOnline, nodeUrl, isDelegated, connectToNode, logout, servedByNode } = useMero();
|
|
1908
|
+
const cloud = !servedByNode && (cloudProp ?? !isDesktopWindow());
|
|
1898
1909
|
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
1899
1910
|
const [isNodeModalOpen, setIsNodeModalOpen] = useState(false);
|
|
1900
1911
|
const [isAccountOpen, setIsAccountOpen] = useState(false);
|
|
@@ -1988,7 +1999,7 @@ function ConnectButtonAccount({
|
|
|
1988
1999
|
{
|
|
1989
2000
|
className: ["mero-connect-button", className].filter(Boolean).join(" "),
|
|
1990
2001
|
style,
|
|
1991
|
-
onClick: () => setIsNodeModalOpen(true),
|
|
2002
|
+
onClick: () => servedByNode ? connectToNode(window.location.origin) : setIsNodeModalOpen(true),
|
|
1992
2003
|
children: [
|
|
1993
2004
|
/* @__PURE__ */ jsx(CalimeroLogo, { size: 18, className: "mero-logo" }),
|
|
1994
2005
|
"I run a node"
|