@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/account/index.d.ts +2 -0
- package/dist/account/index.js +1 -0
- package/dist/account/relay-login-error.d.ts +32 -0
- package/dist/account/relay-login-error.js +34 -0
- package/dist/account/session.js +8 -5
- package/dist/admin-api/admin-client.d.ts +16 -2
- package/dist/admin-api/admin-client.js +18 -3
- package/dist/admin-api/admin-types.d.ts +8 -0
- package/dist/admin-api/redeem-invitation.js +6 -0
- package/dist/errors/classify.js +9 -13
- package/dist/http-client/index.d.ts +1 -1
- package/dist/http-client/index.js +1 -1
- package/dist/http-client/web-client.d.ts +13 -0
- package/dist/http-client/web-client.js +20 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +66 -5
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +66 -5
- package/dist/index.mjs.map +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -69,11 +69,13 @@ __export(index_exports, {
|
|
|
69
69
|
RELAY_NODE_KEY_RETRY_MS: () => RELAY_NODE_KEY_RETRY_MS,
|
|
70
70
|
REQUEST_PROOF_HEADER: () => REQUEST_PROOF_HEADER,
|
|
71
71
|
RelayClient: () => RelayClient,
|
|
72
|
+
RelayLoginError: () => RelayLoginError,
|
|
72
73
|
RelayNotDialableError: () => RelayNotDialableError,
|
|
73
74
|
RelayObserver: () => RelayObserver,
|
|
74
75
|
RelayPresenceClient: () => RelayPresenceClient,
|
|
75
76
|
RelayTransport: () => RelayTransport,
|
|
76
77
|
RelaysUnavailableError: () => RelaysUnavailableError,
|
|
78
|
+
RequestAuthError: () => RequestAuthError,
|
|
77
79
|
RpcClient: () => RpcClient,
|
|
78
80
|
RpcError: () => RpcError,
|
|
79
81
|
SEALED_CONTENT_TYPE: () => SEALED_CONTENT_TYPE,
|
|
@@ -613,6 +615,12 @@ var AuthRevokedError = class extends HTTPError {
|
|
|
613
615
|
this.message = `Authentication revoked (${reason}): HTTP ${status} ${statusText}`;
|
|
614
616
|
}
|
|
615
617
|
};
|
|
618
|
+
var RequestAuthError = class extends Error {
|
|
619
|
+
constructor() {
|
|
620
|
+
super(...arguments);
|
|
621
|
+
this.name = "RequestAuthError";
|
|
622
|
+
}
|
|
623
|
+
};
|
|
616
624
|
function headersToRecord(headers) {
|
|
617
625
|
const record = {};
|
|
618
626
|
headers.forEach((value, key) => {
|
|
@@ -940,6 +948,7 @@ var WebHttpClient = class {
|
|
|
940
948
|
headers.Authorization = `Bearer ${token}`;
|
|
941
949
|
}
|
|
942
950
|
} catch (error) {
|
|
951
|
+
if (error instanceof RequestAuthError) throw error;
|
|
943
952
|
}
|
|
944
953
|
}
|
|
945
954
|
if (initHeaders) {
|
|
@@ -1375,6 +1384,30 @@ function withoutCap(mask, cap) {
|
|
|
1375
1384
|
return (mask & ~cap) >>> 0;
|
|
1376
1385
|
}
|
|
1377
1386
|
|
|
1387
|
+
// src/account/relay-login-error.ts
|
|
1388
|
+
var RelayLoginError = class extends RequestAuthError {
|
|
1389
|
+
constructor(relayUrl, cause) {
|
|
1390
|
+
const kind = relayLoginFailureKind(cause);
|
|
1391
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
1392
|
+
super(
|
|
1393
|
+
kind === "signed-out" ? `the relay ${relayUrl} refused this device's credential (${detail}); sign in again` : `could not log in to the relay ${relayUrl}: ${detail}`
|
|
1394
|
+
);
|
|
1395
|
+
this.name = "RelayLoginError";
|
|
1396
|
+
this.cause = cause;
|
|
1397
|
+
this.relayUrl = relayUrl;
|
|
1398
|
+
this.kind = kind;
|
|
1399
|
+
this.loginStatus = loginStatusOf(cause);
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
function relayLoginFailureKind(cause) {
|
|
1403
|
+
const status = loginStatusOf(cause);
|
|
1404
|
+
return status === 401 || status === 403 ? "signed-out" : "unavailable";
|
|
1405
|
+
}
|
|
1406
|
+
function loginStatusOf(cause) {
|
|
1407
|
+
const status = cause?.status;
|
|
1408
|
+
return typeof status === "number" && Number.isFinite(status) ? status : void 0;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1378
1411
|
// src/errors/classify.ts
|
|
1379
1412
|
var RETRYABLE = {
|
|
1380
1413
|
invalid: false,
|
|
@@ -1445,6 +1478,11 @@ function messageOf(err, fallback = "Request failed") {
|
|
|
1445
1478
|
return fallback;
|
|
1446
1479
|
}
|
|
1447
1480
|
function classifyError(err) {
|
|
1481
|
+
if (err instanceof RelayLoginError) {
|
|
1482
|
+
const status2 = err.loginStatus;
|
|
1483
|
+
const kind2 = err.kind === "signed-out" ? "unauthorized" : status2 ? kindForStatus(status2) : "unreachable";
|
|
1484
|
+
return { kind: kind2, status: status2, retryable: RETRYABLE[kind2], message: messageOf(err) };
|
|
1485
|
+
}
|
|
1448
1486
|
const status = statusOf(err);
|
|
1449
1487
|
let kind;
|
|
1450
1488
|
if (status !== void 0) {
|
|
@@ -1499,6 +1537,9 @@ function reasonFromMessage(message) {
|
|
|
1499
1537
|
}
|
|
1500
1538
|
var FINAL_FROM_TEXT = /* @__PURE__ */ new Set(["already-used", "removed"]);
|
|
1501
1539
|
function classifyJoinFailure(err, message) {
|
|
1540
|
+
if (err instanceof RelayLoginError) {
|
|
1541
|
+
return { reason: err.kind === "signed-out" ? "signed-out" : "node-unreachable", retryable: true };
|
|
1542
|
+
}
|
|
1502
1543
|
const { kind, status } = classifyError(err);
|
|
1503
1544
|
const fromText = reasonFromMessage(message);
|
|
1504
1545
|
const code = refusalCodeOf(err);
|
|
@@ -2089,6 +2130,21 @@ var AdminApiClient = class {
|
|
|
2089
2130
|
}
|
|
2090
2131
|
return data;
|
|
2091
2132
|
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Bring back a namespace the user removed from this node while the account
|
|
2135
|
+
* stayed a member (POST /admin-api/namespaces/:namespace_id/join, no
|
|
2136
|
+
* invitation). Such namespaces are the `forgotten` ones in
|
|
2137
|
+
* {@link listNamespacesForApplication}.
|
|
2138
|
+
*/
|
|
2139
|
+
async restoreNamespace(namespaceId) {
|
|
2140
|
+
return unwrap(
|
|
2141
|
+
await this.httpClient.post(
|
|
2142
|
+
`/admin-api/namespaces/${pathSegment(namespaceId)}/join`,
|
|
2143
|
+
{},
|
|
2144
|
+
{ timeoutMs: 65e3 }
|
|
2145
|
+
)
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2092
2148
|
/**
|
|
2093
2149
|
* Join the namespace an invitation grants, and say what happened — including
|
|
2094
2150
|
* when the request failed but the join landed anyway.
|
|
@@ -2777,9 +2833,15 @@ var AdminApiClient = class {
|
|
|
2777
2833
|
async leaveContext(contextId) {
|
|
2778
2834
|
await this.httpClient.post(`/admin-api/contexts/${pathSegment(contextId)}/leave`, {});
|
|
2779
2835
|
}
|
|
2780
|
-
/**
|
|
2781
|
-
|
|
2782
|
-
|
|
2836
|
+
/**
|
|
2837
|
+
* Leave a namespace (POST /admin-api/namespaces/:namespace_id/leave).
|
|
2838
|
+
*
|
|
2839
|
+
* With `purge`, every device of the account also takes the namespace off its
|
|
2840
|
+
* disk. Core reads `purge` from the query string, so it is not in the body.
|
|
2841
|
+
*/
|
|
2842
|
+
async leaveNamespace(namespaceId, options = {}) {
|
|
2843
|
+
const query = options.purge ? "?purge=true" : "";
|
|
2844
|
+
await this.httpClient.post(`/admin-api/namespaces/${pathSegment(namespaceId)}/leave${query}`, {});
|
|
2783
2845
|
}
|
|
2784
2846
|
/** Issue a group ownership proof (POST /admin-api/groups/:group_id/issue-ownership-proof). */
|
|
2785
2847
|
async issueOwnershipProof(groupId, request) {
|
|
@@ -9702,9 +9764,8 @@ function relaySession(s, nodeKey) {
|
|
|
9702
9764
|
token = minted.accessToken;
|
|
9703
9765
|
return token;
|
|
9704
9766
|
}).catch((e) => {
|
|
9705
|
-
console.warn("[mero-js] relay login failed", e);
|
|
9706
9767
|
token = null;
|
|
9707
|
-
|
|
9768
|
+
throw new RelayLoginError(s.relayUrl, e);
|
|
9708
9769
|
}).finally(() => {
|
|
9709
9770
|
inflight = null;
|
|
9710
9771
|
});
|