@calimero-network/mero-js 19.17.0 → 19.19.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/cloud/cloud-client.d.ts +26 -3
- package/dist/cloud/cloud-client.js +51 -4
- package/dist/cloud/index.d.ts +1 -1
- package/dist/cloud/index.js +1 -1
- package/dist/events/sse.d.ts +2 -0
- package/dist/events/sse.js +5 -2
- package/dist/http-client/http-factory.d.ts +1 -0
- package/dist/http-client/http-factory.js +3 -3
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +40 -9
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +40 -9
- package/dist/index.mjs.map +2 -2
- package/dist/mero-js.d.ts +2 -0
- package/dist/mero-js.js +2 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -420,9 +420,9 @@ function createHttpClient(transport) {
|
|
|
420
420
|
}
|
|
421
421
|
function createBrowserHttpClient(options) {
|
|
422
422
|
const transport = {
|
|
423
|
-
//
|
|
424
|
-
//
|
|
425
|
-
fetch: (url, init) => globalThis.fetch(url, init),
|
|
423
|
+
// globalThis.fetch must be called as a method on globalThis, not through a
|
|
424
|
+
// variable, or browsers throw "Illegal invocation".
|
|
425
|
+
fetch: (url, init) => options.fetch ? options.fetch(url, init) : globalThis.fetch(url, init),
|
|
426
426
|
baseUrl: options.baseUrl,
|
|
427
427
|
getAuthToken: options.getAuthToken,
|
|
428
428
|
getProof: options.getProof,
|
|
@@ -2188,6 +2188,7 @@ var SseClient = class {
|
|
|
2188
2188
|
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
2189
2189
|
this.getAuthToken = opts.getAuthToken;
|
|
2190
2190
|
this.reconnectDelayMs = opts.reconnectDelayMs ?? 3e3;
|
|
2191
|
+
this.fetchImpl = (url, init) => opts.fetch ? opts.fetch(url, init) : globalThis.fetch(url, init);
|
|
2191
2192
|
}
|
|
2192
2193
|
on(event, handler) {
|
|
2193
2194
|
const key = event;
|
|
@@ -2254,7 +2255,7 @@ var SseClient = class {
|
|
|
2254
2255
|
try {
|
|
2255
2256
|
const token = await this.getAuthToken();
|
|
2256
2257
|
const url = `${this.baseUrl}/sse`;
|
|
2257
|
-
const response = await
|
|
2258
|
+
const response = await this.fetchImpl(url, {
|
|
2258
2259
|
headers: {
|
|
2259
2260
|
"Authorization": `Bearer ${token}`,
|
|
2260
2261
|
"Accept": "text/event-stream"
|
|
@@ -2413,7 +2414,7 @@ var SseClient = class {
|
|
|
2413
2414
|
const params = {};
|
|
2414
2415
|
if (ids.contextIds && ids.contextIds.length > 0) params.contextIds = ids.contextIds;
|
|
2415
2416
|
if (ids.groupIds && ids.groupIds.length > 0) params.groupIds = ids.groupIds;
|
|
2416
|
-
const response = await
|
|
2417
|
+
const response = await this.fetchImpl(`${this.baseUrl}/sse/subscription`, {
|
|
2417
2418
|
method: "POST",
|
|
2418
2419
|
headers: {
|
|
2419
2420
|
"Authorization": `Bearer ${token}`,
|
|
@@ -5403,17 +5404,27 @@ var CloudClient = class {
|
|
|
5403
5404
|
* Ask the fleet to host a claimed namespace — the step that gets a relay
|
|
5404
5405
|
* assigned.
|
|
5405
5406
|
*
|
|
5406
|
-
*
|
|
5407
|
-
* this is the separate "now host it" half. Idempotent.
|
|
5407
|
+
* Carries no proof: {@link claimNamespace} already established ownership,
|
|
5408
|
+
* and this is the separate "now host it" half. Idempotent.
|
|
5409
|
+
*
|
|
5410
|
+
* `admitterAddrs` is where the owner's own node can be dialed — take it from
|
|
5411
|
+
* that node's network status with {@link admitterAddrsFromNetworkStatus}.
|
|
5412
|
+
* The first fleet node placed on a namespace has nobody but the owner to ask
|
|
5413
|
+
* for admission, and without these it can only broadcast and hope the
|
|
5414
|
+
* owner's node — often a laptop behind a relay — hears it. They are a dial
|
|
5415
|
+
* hint, not a grant: the owner's node admits by its own policy. Omit them to
|
|
5416
|
+
* leave whatever the cloud already holds; pass them again when the node's
|
|
5417
|
+
* relay address changes, and they replace the stored ones.
|
|
5408
5418
|
*
|
|
5409
5419
|
* Not to be confused with {@link enableHA}, which opens the cloud's web flow
|
|
5410
5420
|
* in a browser tab for a user to complete by hand. This is the API call.
|
|
5411
5421
|
*/
|
|
5412
|
-
async enableNamespaceHa(namespaceId) {
|
|
5422
|
+
async enableNamespaceHa(namespaceId, options = {}) {
|
|
5423
|
+
const body = options.admitterAddrs === void 0 ? {} : { admitter_addrs: [...options.admitterAddrs] };
|
|
5413
5424
|
return this.request(
|
|
5414
5425
|
"POST",
|
|
5415
5426
|
`/api/cloud/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`,
|
|
5416
|
-
{ body
|
|
5427
|
+
{ body }
|
|
5417
5428
|
);
|
|
5418
5429
|
}
|
|
5419
5430
|
/**
|
|
@@ -5737,6 +5748,23 @@ var CloudClient = class {
|
|
|
5737
5748
|
void this.notifySession(this.session);
|
|
5738
5749
|
}
|
|
5739
5750
|
};
|
|
5751
|
+
function admitterAddrsFromNetworkStatus(status) {
|
|
5752
|
+
const record = status && typeof status === "object" ? status.data ?? status : void 0;
|
|
5753
|
+
if (!record || typeof record !== "object") return [];
|
|
5754
|
+
const peerId = record.localPeerId;
|
|
5755
|
+
const external = record.externalAddrs;
|
|
5756
|
+
if (typeof peerId !== "string" || !peerId || !Array.isArray(external)) return [];
|
|
5757
|
+
const suffix = `/p2p/${peerId}`;
|
|
5758
|
+
const out = [];
|
|
5759
|
+
for (const entry of external) {
|
|
5760
|
+
if (typeof entry !== "string") continue;
|
|
5761
|
+
const addr = entry.trim();
|
|
5762
|
+
if (!addr.startsWith("/")) continue;
|
|
5763
|
+
const dialable = addr.endsWith(suffix) ? addr : `${addr}${suffix}`;
|
|
5764
|
+
if (!out.includes(dialable)) out.push(dialable);
|
|
5765
|
+
}
|
|
5766
|
+
return out;
|
|
5767
|
+
}
|
|
5740
5768
|
|
|
5741
5769
|
// src/mero-js.ts
|
|
5742
5770
|
function resolveProofSigner(config) {
|
|
@@ -5784,6 +5812,7 @@ var MeroJs = class {
|
|
|
5784
5812
|
const getProof = resolveProofSigner(this.config.requestProof);
|
|
5785
5813
|
this.httpClient = createBrowserHttpClient({
|
|
5786
5814
|
baseUrl: this.config.baseUrl,
|
|
5815
|
+
fetch: this.config.fetch,
|
|
5787
5816
|
getProof,
|
|
5788
5817
|
getAuthToken: async () => {
|
|
5789
5818
|
const token = await this.getValidToken();
|
|
@@ -5854,6 +5883,7 @@ var MeroJs = class {
|
|
|
5854
5883
|
if (!this.sseClient) {
|
|
5855
5884
|
this.sseClient = new SseClient({
|
|
5856
5885
|
baseUrl: this.config.baseUrl,
|
|
5886
|
+
fetch: this.config.fetch,
|
|
5857
5887
|
getAuthToken: async () => {
|
|
5858
5888
|
const token = await this.getValidToken();
|
|
5859
5889
|
return token?.access_token || "";
|
|
@@ -6799,6 +6829,7 @@ export {
|
|
|
6799
6829
|
accountForRoot,
|
|
6800
6830
|
accountRootFromPhrase,
|
|
6801
6831
|
accountRootFromSecret,
|
|
6832
|
+
admitterAddrsFromNetworkStatus,
|
|
6802
6833
|
buildAuthLoginUrl,
|
|
6803
6834
|
callerProof,
|
|
6804
6835
|
combineSignals,
|