@calimero-network/mero-react 10.1.1 → 10.2.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/dist/index.d.cts CHANGED
@@ -459,13 +459,13 @@ interface LoginModalProps {
459
459
  * the modal is open. Nothing to wire; the modal must be inside a
460
460
  * `MeroProvider`.
461
461
  * - **`false`**: no Cloud tab and no tabs at all — the node dialog as it was.
462
- * - **omitted inside a Calimero Desktop window**: as `false` — the window is
463
- * already bound to the desktop's node. Pass a `cloud` object to override.
464
- * The modal reads no enrolment callback, leaving it to whichever component
465
- * does.
466
462
  * - **An object**: the caller's own enrolment, used verbatim; the modal reads
467
463
  * none itself. The values are `useAccountEnrolment`'s, as `ConnectButton`
468
464
  * passes them.
465
+ *
466
+ * Inside a Calimero Desktop window every form is as `false` — the window is
467
+ * already bound to the desktop's node, so there is no relay and no passkey to
468
+ * go through. `cloudOnDesktop` turns that off.
469
469
  */
470
470
  cloud?: false | {
471
471
  /** Start enrolment — normally `useAccountEnrolment().goToWallet`. */
@@ -477,6 +477,12 @@ interface LoginModalProps {
477
477
  /** Whether `walletUrl` is an override rather than the hosted wallet. */
478
478
  customWallet?: boolean;
479
479
  };
480
+ /**
481
+ * Show the Cloud tab inside a Calimero Desktop window too. Default false:
482
+ * the desktop logs in to its own node, so `cloud` — omitted or an object —
483
+ * is ignored there (see `isDesktopWindow`).
484
+ */
485
+ cloudOnDesktop?: boolean;
480
486
  /**
481
487
  * The tab selected when the modal opens. Ignored with `cloud={false}`.
482
488
  *
@@ -492,7 +498,7 @@ type LoginModalTab = 'node' | 'cloud';
492
498
  /**
493
499
  * LoginModal - Connection modal component
494
500
  */
495
- declare function LoginModal({ onConnect, onClose, isOpen, theme, localNodePorts, cloud, initialTab: initialTabProp, }: LoginModalProps): React.ReactPortal | null;
501
+ declare function LoginModal({ onConnect, onClose, isOpen, theme, localNodePorts, cloud, cloudOnDesktop, initialTab: initialTabProp, }: LoginModalProps): React.ReactPortal | null;
496
502
 
497
503
  interface AccountSignInPanelProps {
498
504
  /** Start enrolment — normally `useAccountEnrolment().goToWallet`. */
@@ -1062,7 +1068,9 @@ interface UseAccountEnrolmentOptions {
1062
1068
  /**
1063
1069
  * When false, the hook reads no callback and completes nothing, so a
1064
1070
  * component that has the account path switched off leaves the fragment for
1065
- * whichever component does handle it. Default true.
1071
+ * whichever component does handle it. Default true, except inside a
1072
+ * Calimero Desktop window (see `isDesktopWindow`), whose app is already
1073
+ * bound to the desktop's node and has no wallet callback to complete.
1066
1074
  */
1067
1075
  enabled?: boolean;
1068
1076
  }
@@ -1836,8 +1844,8 @@ declare function clearAllStorage(): void;
1836
1844
  * navigate the app window off to another origin.
1837
1845
  *
1838
1846
  * Two signals, either is enough:
1839
- * - `__TAURI_INTERNALS__`, which Tauri injects natively into every webview it
1840
- * creates, remote URLs included — what mero-js's own Tauri check reads;
1847
+ * - `__TAURI_INTERNALS__` with a callable `invoke`, which Tauri injects natively
1848
+ * into every webview it creates, remote URLs included;
1841
1849
  * - `__TAURI_FETCH_PROXY_INJECTED__`, the marker the desktop's app-window
1842
1850
  * init script sets, in case a future Tauri stops exposing the former there.
1843
1851
  *
package/dist/index.d.ts CHANGED
@@ -459,13 +459,13 @@ interface LoginModalProps {
459
459
  * the modal is open. Nothing to wire; the modal must be inside a
460
460
  * `MeroProvider`.
461
461
  * - **`false`**: no Cloud tab and no tabs at all — the node dialog as it was.
462
- * - **omitted inside a Calimero Desktop window**: as `false` — the window is
463
- * already bound to the desktop's node. Pass a `cloud` object to override.
464
- * The modal reads no enrolment callback, leaving it to whichever component
465
- * does.
466
462
  * - **An object**: the caller's own enrolment, used verbatim; the modal reads
467
463
  * none itself. The values are `useAccountEnrolment`'s, as `ConnectButton`
468
464
  * passes them.
465
+ *
466
+ * Inside a Calimero Desktop window every form is as `false` — the window is
467
+ * already bound to the desktop's node, so there is no relay and no passkey to
468
+ * go through. `cloudOnDesktop` turns that off.
469
469
  */
470
470
  cloud?: false | {
471
471
  /** Start enrolment — normally `useAccountEnrolment().goToWallet`. */
@@ -477,6 +477,12 @@ interface LoginModalProps {
477
477
  /** Whether `walletUrl` is an override rather than the hosted wallet. */
478
478
  customWallet?: boolean;
479
479
  };
480
+ /**
481
+ * Show the Cloud tab inside a Calimero Desktop window too. Default false:
482
+ * the desktop logs in to its own node, so `cloud` — omitted or an object —
483
+ * is ignored there (see `isDesktopWindow`).
484
+ */
485
+ cloudOnDesktop?: boolean;
480
486
  /**
481
487
  * The tab selected when the modal opens. Ignored with `cloud={false}`.
482
488
  *
@@ -492,7 +498,7 @@ type LoginModalTab = 'node' | 'cloud';
492
498
  /**
493
499
  * LoginModal - Connection modal component
494
500
  */
495
- declare function LoginModal({ onConnect, onClose, isOpen, theme, localNodePorts, cloud, initialTab: initialTabProp, }: LoginModalProps): React.ReactPortal | null;
501
+ declare function LoginModal({ onConnect, onClose, isOpen, theme, localNodePorts, cloud, cloudOnDesktop, initialTab: initialTabProp, }: LoginModalProps): React.ReactPortal | null;
496
502
 
497
503
  interface AccountSignInPanelProps {
498
504
  /** Start enrolment — normally `useAccountEnrolment().goToWallet`. */
@@ -1062,7 +1068,9 @@ interface UseAccountEnrolmentOptions {
1062
1068
  /**
1063
1069
  * When false, the hook reads no callback and completes nothing, so a
1064
1070
  * component that has the account path switched off leaves the fragment for
1065
- * whichever component does handle it. Default true.
1071
+ * whichever component does handle it. Default true, except inside a
1072
+ * Calimero Desktop window (see `isDesktopWindow`), whose app is already
1073
+ * bound to the desktop's node and has no wallet callback to complete.
1066
1074
  */
1067
1075
  enabled?: boolean;
1068
1076
  }
@@ -1836,8 +1844,8 @@ declare function clearAllStorage(): void;
1836
1844
  * navigate the app window off to another origin.
1837
1845
  *
1838
1846
  * Two signals, either is enough:
1839
- * - `__TAURI_INTERNALS__`, which Tauri injects natively into every webview it
1840
- * creates, remote URLs included — what mero-js's own Tauri check reads;
1847
+ * - `__TAURI_INTERNALS__` with a callable `invoke`, which Tauri injects natively
1848
+ * into every webview it creates, remote URLs included;
1841
1849
  * - `__TAURI_FETCH_PROXY_INJECTED__`, the marker the desktop's app-window
1842
1850
  * init script sets, in case a future Tauri stops exposing the former there.
1843
1851
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createContext, useMemo, useState, useRef, useCallback, useEffect, useContext, useReducer, useId, useSyncExternalStore } from 'react';
2
- import { LocalStorageTokenStore, readDelegatedSession, parseAuthCallback, MeroJs, buildAuthLoginUrl, saveDelegatedSession, saveDelegatedCredential, clearDelegatedSession, clearDelegatedCredential, relayForContext, buildDelegatedClient, readPinnedRelayNodeKey, learnRelayNodeKey, resolveApplicationIdFromRegistry, listDelegatedContexts, createAccountAdmin, createNodeAdmin, readEnrolmentCallback, completeDeviceEnrolment, CloudClient, deviceEnrolmentUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, createDelegatedContext, createDelegatedPrivateContext, governRoot, memberJoinedOpenOp, signerFromSecret, compareSemver, readDelegatedCredential, bootstrapFromInvitation, rememberRelay, carryExecutorAccount, shouldRetain, redeemInvitation, listDelegatedNamespaces, AuthRevokedError, HTTPError, foundDelegatedNamespace, joinAsAccount, classifyError } from '@calimero-network/mero-js';
2
+ import { LocalStorageTokenStore, readDelegatedSession, MeroJs, buildAuthLoginUrl, saveDelegatedSession, saveDelegatedCredential, clearDelegatedSession, clearDelegatedCredential, relayForContext, buildDelegatedClient, readPinnedRelayNodeKey, learnRelayNodeKey, resolveApplicationIdFromRegistry, listDelegatedContexts, createAccountAdmin, createNodeAdmin, readEnrolmentCallback, completeDeviceEnrolment, CloudClient, deviceEnrolmentUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, createDelegatedContext, createDelegatedPrivateContext, governRoot, memberJoinedOpenOp, signerFromSecret, compareSemver, readDelegatedCredential, bootstrapFromInvitation, rememberRelay, carryExecutorAccount, shouldRetain, redeemInvitation, listDelegatedNamespaces, AuthRevokedError, HTTPError, foundDelegatedNamespace, joinAsAccount, parseAuthCallback, classifyError } from '@calimero-network/mero-js';
3
3
  export * from '@calimero-network/mero-js';
4
4
  export { CAPABILITIES, DEFAULT_LOCAL_NODE_PORTS, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, InvitationNotClaimableError, NoRelayError, NotForAccountError, applicationIdForBundle, bootstrapFromInvitation, clearDelegatedCredential, createAccountAdmin, createDelegatedContext, createNodeAdmin, discoverLocalNodes, hasCap, joinWithNode, listDelegatedContexts, localNodeUrl, nodeEndpoint, normaliseAccount, pinRelayNodeKey, probeNodeHealth, readDelegatedCredential, readPinnedRelayNodeKey, readRelayMap, relayForContext, rememberRelay, resolveApplicationIdFromRegistry, resolveRelayFromInvitation, saveDelegatedCredential, selectLatestBundle, withCap, withoutCap } from '@calimero-network/mero-js';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -133,6 +133,15 @@ function resolveTokenAdoption(params) {
133
133
  return { adopt: false, reason: "stale" };
134
134
  }
135
135
 
136
+ // src/utils/desktop.ts
137
+ function isDesktopWindow() {
138
+ if (typeof window === "undefined") return false;
139
+ const w = window;
140
+ const internals = w.__TAURI_INTERNALS__;
141
+ const tauri = typeof internals === "object" && internals !== null && !(typeof Node !== "undefined" && internals instanceof Node) && typeof internals.invoke === "function";
142
+ return tauri || w.__TAURI_FETCH_PROXY_INJECTED__ === true;
143
+ }
144
+
136
145
  // src/storage/index.ts
137
146
  var STORAGE_KEYS = {
138
147
  ACCESS_TOKEN: "mero:access_token",
@@ -283,6 +292,21 @@ function clearAllStorage() {
283
292
  var MeroContext = createContext(null);
284
293
  var DEFAULT_REGISTRY_URL = "https://apps.calimero.network";
285
294
  var isBrowser = typeof window !== "undefined";
295
+ var DESKTOP_HOST = isDesktopWindow();
296
+ var parsedCallback = null;
297
+ function readAuthCallback() {
298
+ const href = window.location.href;
299
+ if (parsedCallback?.href !== href) {
300
+ parsedCallback = { href, result: parseAuthCallback(href, { allowUnsolicited: DESKTOP_HOST }) };
301
+ }
302
+ return parsedCallback.result;
303
+ }
304
+ function clearAuthCallbackFromUrl() {
305
+ if (!new URLSearchParams(window.location.hash.slice(1)).has("access_token")) return;
306
+ const url = new URL(window.location.href);
307
+ url.searchParams.delete("auth_state");
308
+ window.history.replaceState({}, "", url.pathname + url.search);
309
+ }
286
310
  function getPermissionsForMode(mode) {
287
311
  switch (mode) {
288
312
  case "single-context" /* SingleContext */:
@@ -345,7 +369,7 @@ function MeroProvider({
345
369
  const recoveringRef = useRef(false);
346
370
  const callbackRef = useRef(void 0);
347
371
  if (callbackRef.current === void 0 && isBrowser) {
348
- callbackRef.current = parseAuthCallback(window.location.href);
372
+ callbackRef.current = readAuthCallback();
349
373
  }
350
374
  const createMeroInstance = useCallback(
351
375
  (url) => {
@@ -478,6 +502,7 @@ function MeroProvider({
478
502
  };
479
503
  }, [delegated, contextId, packageName, registryUrl]);
480
504
  useEffect(() => {
505
+ if (isBrowser) clearAuthCallbackFromUrl();
481
506
  if (delegated) return;
482
507
  let active = true;
483
508
  const init = async () => {
@@ -492,9 +517,6 @@ function MeroProvider({
492
517
  initiated: initiatedNodeUrl,
493
518
  allowedNodeUrls
494
519
  });
495
- if (isBrowser) {
496
- window.history.replaceState({}, "", window.location.pathname + window.location.search);
497
- }
498
520
  callbackRef.current = null;
499
521
  if (rejected) {
500
522
  console.error(
@@ -927,7 +949,7 @@ function isReturningFromWallet(location = typeof window === "undefined" ? void 0
927
949
  }
928
950
  function useAccountEnrolment({
929
951
  walletUrl: walletOverride,
930
- enabled = true
952
+ enabled = !isDesktopWindow()
931
953
  } = {}) {
932
954
  const { connectWithAccount, cloudBaseUrl } = useMero();
933
955
  const [note, setNote] = useState(null);
@@ -1019,13 +1041,6 @@ function useAccountEnrolment({
1019
1041
  customWallet: walletOverride !== void 0
1020
1042
  };
1021
1043
  }
1022
-
1023
- // src/utils/desktop.ts
1024
- function isDesktopWindow() {
1025
- if (typeof window === "undefined") return false;
1026
- const w = window;
1027
- return "__TAURI_INTERNALS__" in w || w.__TAURI_FETCH_PROXY_INJECTED__ === true;
1028
- }
1029
1044
  var CUSTOM_SELECTION = "__custom__";
1030
1045
  var TABS = [
1031
1046
  { id: "node", label: "Node" },
@@ -1312,9 +1327,11 @@ function LoginModal({
1312
1327
  theme,
1313
1328
  localNodePorts = DEFAULT_LOCAL_NODE_PORTS,
1314
1329
  cloud,
1330
+ cloudOnDesktop = false,
1315
1331
  initialTab: initialTabProp
1316
1332
  }) {
1317
- const ownCloud = cloud === void 0 && !isDesktopWindow();
1333
+ const cloudAllowed = cloudOnDesktop || !isDesktopWindow();
1334
+ const ownCloud = cloud === void 0 && cloudAllowed;
1318
1335
  const own = useAccountEnrolment({ enabled: ownCloud });
1319
1336
  const cloudTab = useMemo(
1320
1337
  () => ownCloud ? {
@@ -1324,8 +1341,8 @@ function LoginModal({
1324
1341
  note: own.note,
1325
1342
  walletUrl: own.walletUrl,
1326
1343
  customWallet: own.customWallet
1327
- } : cloud || null,
1328
- [cloud, ownCloud, own.goToWallet, own.note, own.walletUrl, own.customWallet]
1344
+ } : cloudAllowed && cloud || null,
1345
+ [cloud, cloudAllowed, ownCloud, own.goToWallet, own.note, own.walletUrl, own.customWallet]
1329
1346
  );
1330
1347
  const initialTab = initialTabProp ?? (ownCloud && own.returning ? "cloud" : "node");
1331
1348
  const [tab, setTab] = useState(initialTab);
@@ -1859,6 +1876,7 @@ function ConnectButton({
1859
1876
  walletUrl: enrolment.walletUrl,
1860
1877
  customWallet: enrolment.customWallet
1861
1878
  } : false,
1879
+ cloudOnDesktop: cloud,
1862
1880
  initialTab: cloud && enrolment.returning ? "cloud" : "node"
1863
1881
  }
1864
1882
  )