@calimero-network/mero-js 26.5.0 → 26.7.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.ts CHANGED
@@ -28,8 +28,8 @@ export { signerFromSecret, signerFromCryptoKey } from "./signer/index.js";
28
28
  export type { Signer } from "./signer/index.js";
29
29
  export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, createAccountRootSigner, accountRootSignerFromPhrase, signAccountLink, signAccountLogin, resolveRoot, resolveRootPair, } from "./account/index.js";
30
30
  export type { AccountRoot, RecoverableAccountRoot, AccountRootSigner, NewAccountRootSigner, AccountLinkInput, AccountLoginInput, RootSource, ResolvedRoot, } from "./account/index.js";
31
- export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, RelaysUnavailableError, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, createNodeAdmin, } from "./account/index.js";
32
- export type { DelegatedCredential, DelegatedAccountSession, RelayMap, RelayNodeKeyAttempt, RelayListingFailure, RelayResolutionStep, RelayResolutionFailure, ResolvedInvitationRelay, ResolveRelayResult, ResolveRelayFromInvitationInput, JoinWithNodeInput, JoinWithNodeResult, JoinWithNodeSuccess, JoinWithNodeFailure, JoinWithNodeStep, BootstrapStep, BootstrapResult, BootstrapSuccess, BootstrapFailure, BootstrapFromInvitationInput, CreateDelegatedContextRequest, FoundedDelegatedNamespace, RegistryBundle, ResolvedApplication, AccountAdminDeps, NodeAdminDeps, } from "./account/index.js";
31
+ export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, RelaysUnavailableError, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, RelayLoginError, createNodeAdmin, } from "./account/index.js";
32
+ export type { DelegatedCredential, DelegatedAccountSession, RelayMap, RelayNodeKeyAttempt, RelayLoginFailureKind, RelayListingFailure, RelayResolutionStep, RelayResolutionFailure, ResolvedInvitationRelay, ResolveRelayResult, ResolveRelayFromInvitationInput, JoinWithNodeInput, JoinWithNodeResult, JoinWithNodeSuccess, JoinWithNodeFailure, JoinWithNodeStep, BootstrapStep, BootstrapResult, BootstrapSuccess, BootstrapFailure, BootstrapFromInvitationInput, CreateDelegatedContextRequest, FoundedDelegatedNamespace, RegistryBundle, ResolvedApplication, AccountAdminDeps, NodeAdminDeps, } from "./account/index.js";
33
33
  export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, accountForRootPublicKey, parseDeviceCredential, verifyDeviceCredential, } from "./device-cert/index.js";
34
34
  export type { DeviceCertInput, DeviceCredential } from "./device-cert/index.js";
35
35
  export { signDeviceScope, deviceScopePayload } from "./device-cert/index.js";
package/dist/index.js CHANGED
@@ -52,7 +52,7 @@ resolveRoot, resolveRootPair, } from "./account/index.js";
52
52
  // Framework-free; mero-react re-exports every one of these under the same name
53
53
  // (its `DelegatedSession` is `DelegatedAccountSession` here: the login module
54
54
  // already owns the bare name for the session `login()` mints).
55
- export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, RelaysUnavailableError, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, createNodeAdmin, } from "./account/index.js";
55
+ export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, RelaysUnavailableError, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, RelayLoginError, createNodeAdmin, } from "./account/index.js";
56
56
  export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, accountForRootPublicKey, parseDeviceCredential, verifyDeviceCredential, } from "./device-cert/index.js";
57
57
  // A device's scope — signed by the root beside its certificate, and what a relay
58
58
  // needs with it to bind the device of an account that has no node.
package/dist/index.mjs CHANGED
@@ -317,6 +317,12 @@ var AuthRevokedError = class extends HTTPError {
317
317
  this.message = `Authentication revoked (${reason}): HTTP ${status} ${statusText}`;
318
318
  }
319
319
  };
320
+ var RequestAuthError = class extends Error {
321
+ constructor() {
322
+ super(...arguments);
323
+ this.name = "RequestAuthError";
324
+ }
325
+ };
320
326
  function headersToRecord(headers) {
321
327
  const record = {};
322
328
  headers.forEach((value, key) => {
@@ -644,6 +650,7 @@ var WebHttpClient = class {
644
650
  headers.Authorization = `Bearer ${token}`;
645
651
  }
646
652
  } catch (error) {
653
+ if (error instanceof RequestAuthError) throw error;
647
654
  }
648
655
  }
649
656
  if (initHeaders) {
@@ -1079,6 +1086,30 @@ function withoutCap(mask, cap) {
1079
1086
  return (mask & ~cap) >>> 0;
1080
1087
  }
1081
1088
 
1089
+ // src/account/relay-login-error.ts
1090
+ var RelayLoginError = class extends RequestAuthError {
1091
+ constructor(relayUrl, cause) {
1092
+ const kind = relayLoginFailureKind(cause);
1093
+ const detail = cause instanceof Error ? cause.message : String(cause);
1094
+ super(
1095
+ kind === "signed-out" ? `the relay ${relayUrl} refused this device's credential (${detail}); sign in again` : `could not log in to the relay ${relayUrl}: ${detail}`
1096
+ );
1097
+ this.name = "RelayLoginError";
1098
+ this.cause = cause;
1099
+ this.relayUrl = relayUrl;
1100
+ this.kind = kind;
1101
+ this.loginStatus = loginStatusOf(cause);
1102
+ }
1103
+ };
1104
+ function relayLoginFailureKind(cause) {
1105
+ const status = loginStatusOf(cause);
1106
+ return status === 401 || status === 403 ? "signed-out" : "unavailable";
1107
+ }
1108
+ function loginStatusOf(cause) {
1109
+ const status = cause?.status;
1110
+ return typeof status === "number" && Number.isFinite(status) ? status : void 0;
1111
+ }
1112
+
1082
1113
  // src/errors/classify.ts
1083
1114
  var RETRYABLE = {
1084
1115
  invalid: false,
@@ -1149,6 +1180,11 @@ function messageOf(err, fallback = "Request failed") {
1149
1180
  return fallback;
1150
1181
  }
1151
1182
  function classifyError(err) {
1183
+ if (err instanceof RelayLoginError) {
1184
+ const status2 = err.loginStatus;
1185
+ const kind2 = err.kind === "signed-out" ? "unauthorized" : status2 ? kindForStatus(status2) : "unreachable";
1186
+ return { kind: kind2, status: status2, retryable: RETRYABLE[kind2], message: messageOf(err) };
1187
+ }
1152
1188
  const status = statusOf(err);
1153
1189
  let kind;
1154
1190
  if (status !== void 0) {
@@ -1203,6 +1239,9 @@ function reasonFromMessage(message) {
1203
1239
  }
1204
1240
  var FINAL_FROM_TEXT = /* @__PURE__ */ new Set(["already-used", "removed"]);
1205
1241
  function classifyJoinFailure(err, message) {
1242
+ if (err instanceof RelayLoginError) {
1243
+ return { reason: err.kind === "signed-out" ? "signed-out" : "node-unreachable", retryable: true };
1244
+ }
1206
1245
  const { kind, status } = classifyError(err);
1207
1246
  const fromText = reasonFromMessage(message);
1208
1247
  const code = refusalCodeOf(err);
@@ -1793,6 +1832,21 @@ var AdminApiClient = class {
1793
1832
  }
1794
1833
  return data;
1795
1834
  }
1835
+ /**
1836
+ * Bring back a namespace the user removed from this node while the account
1837
+ * stayed a member (POST /admin-api/namespaces/:namespace_id/join, no
1838
+ * invitation). Such namespaces are the `forgotten` ones in
1839
+ * {@link listNamespacesForApplication}.
1840
+ */
1841
+ async restoreNamespace(namespaceId) {
1842
+ return unwrap(
1843
+ await this.httpClient.post(
1844
+ `/admin-api/namespaces/${pathSegment(namespaceId)}/join`,
1845
+ {},
1846
+ { timeoutMs: 65e3 }
1847
+ )
1848
+ );
1849
+ }
1796
1850
  /**
1797
1851
  * Join the namespace an invitation grants, and say what happened — including
1798
1852
  * when the request failed but the join landed anyway.
@@ -2481,9 +2535,15 @@ var AdminApiClient = class {
2481
2535
  async leaveContext(contextId) {
2482
2536
  await this.httpClient.post(`/admin-api/contexts/${pathSegment(contextId)}/leave`, {});
2483
2537
  }
2484
- /** Leave a namespace (POST /admin-api/namespaces/:namespace_id/leave). */
2485
- async leaveNamespace(namespaceId) {
2486
- await this.httpClient.post(`/admin-api/namespaces/${pathSegment(namespaceId)}/leave`, {});
2538
+ /**
2539
+ * Leave a namespace (POST /admin-api/namespaces/:namespace_id/leave).
2540
+ *
2541
+ * With `purge`, every device of the account also takes the namespace off its
2542
+ * disk. Core reads `purge` from the query string, so it is not in the body.
2543
+ */
2544
+ async leaveNamespace(namespaceId, options = {}) {
2545
+ const query = options.purge ? "?purge=true" : "";
2546
+ await this.httpClient.post(`/admin-api/namespaces/${pathSegment(namespaceId)}/leave${query}`, {});
2487
2547
  }
2488
2548
  /** Issue a group ownership proof (POST /admin-api/groups/:group_id/issue-ownership-proof). */
2489
2549
  async issueOwnershipProof(groupId, request) {
@@ -9406,9 +9466,8 @@ function relaySession(s, nodeKey) {
9406
9466
  token = minted.accessToken;
9407
9467
  return token;
9408
9468
  }).catch((e) => {
9409
- console.warn("[mero-js] relay login failed", e);
9410
9469
  token = null;
9411
- return void 0;
9470
+ throw new RelayLoginError(s.relayUrl, e);
9412
9471
  }).finally(() => {
9413
9472
  inflight = null;
9414
9473
  });
@@ -13165,11 +13224,13 @@ export {
13165
13224
  RELAY_NODE_KEY_RETRY_MS,
13166
13225
  REQUEST_PROOF_HEADER,
13167
13226
  RelayClient,
13227
+ RelayLoginError,
13168
13228
  RelayNotDialableError,
13169
13229
  RelayObserver,
13170
13230
  RelayPresenceClient,
13171
13231
  RelayTransport,
13172
13232
  RelaysUnavailableError,
13233
+ RequestAuthError,
13173
13234
  RpcClient,
13174
13235
  RpcError,
13175
13236
  SEALED_CONTENT_TYPE,