@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.cjs
CHANGED
|
@@ -41,6 +41,7 @@ __export(index_exports, {
|
|
|
41
41
|
accountForRoot: () => accountForRoot,
|
|
42
42
|
accountRootFromPhrase: () => accountRootFromPhrase,
|
|
43
43
|
accountRootFromSecret: () => accountRootFromSecret,
|
|
44
|
+
admitterAddrsFromNetworkStatus: () => admitterAddrsFromNetworkStatus,
|
|
44
45
|
buildAuthLoginUrl: () => buildAuthLoginUrl,
|
|
45
46
|
callerProof: () => callerProof,
|
|
46
47
|
combineSignals: () => combineSignals,
|
|
@@ -517,9 +518,9 @@ function createHttpClient(transport) {
|
|
|
517
518
|
}
|
|
518
519
|
function createBrowserHttpClient(options) {
|
|
519
520
|
const transport = {
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
fetch: (url, init) => globalThis.fetch(url, init),
|
|
521
|
+
// globalThis.fetch must be called as a method on globalThis, not through a
|
|
522
|
+
// variable, or browsers throw "Illegal invocation".
|
|
523
|
+
fetch: (url, init) => options.fetch ? options.fetch(url, init) : globalThis.fetch(url, init),
|
|
523
524
|
baseUrl: options.baseUrl,
|
|
524
525
|
getAuthToken: options.getAuthToken,
|
|
525
526
|
getProof: options.getProof,
|
|
@@ -2285,6 +2286,7 @@ var SseClient = class {
|
|
|
2285
2286
|
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
2286
2287
|
this.getAuthToken = opts.getAuthToken;
|
|
2287
2288
|
this.reconnectDelayMs = opts.reconnectDelayMs ?? 3e3;
|
|
2289
|
+
this.fetchImpl = (url, init) => opts.fetch ? opts.fetch(url, init) : globalThis.fetch(url, init);
|
|
2288
2290
|
}
|
|
2289
2291
|
on(event, handler) {
|
|
2290
2292
|
const key = event;
|
|
@@ -2351,7 +2353,7 @@ var SseClient = class {
|
|
|
2351
2353
|
try {
|
|
2352
2354
|
const token = await this.getAuthToken();
|
|
2353
2355
|
const url = `${this.baseUrl}/sse`;
|
|
2354
|
-
const response = await
|
|
2356
|
+
const response = await this.fetchImpl(url, {
|
|
2355
2357
|
headers: {
|
|
2356
2358
|
"Authorization": `Bearer ${token}`,
|
|
2357
2359
|
"Accept": "text/event-stream"
|
|
@@ -2510,7 +2512,7 @@ var SseClient = class {
|
|
|
2510
2512
|
const params = {};
|
|
2511
2513
|
if (ids.contextIds && ids.contextIds.length > 0) params.contextIds = ids.contextIds;
|
|
2512
2514
|
if (ids.groupIds && ids.groupIds.length > 0) params.groupIds = ids.groupIds;
|
|
2513
|
-
const response = await
|
|
2515
|
+
const response = await this.fetchImpl(`${this.baseUrl}/sse/subscription`, {
|
|
2514
2516
|
method: "POST",
|
|
2515
2517
|
headers: {
|
|
2516
2518
|
"Authorization": `Bearer ${token}`,
|
|
@@ -5500,17 +5502,27 @@ var CloudClient = class {
|
|
|
5500
5502
|
* Ask the fleet to host a claimed namespace — the step that gets a relay
|
|
5501
5503
|
* assigned.
|
|
5502
5504
|
*
|
|
5503
|
-
*
|
|
5504
|
-
* this is the separate "now host it" half. Idempotent.
|
|
5505
|
+
* Carries no proof: {@link claimNamespace} already established ownership,
|
|
5506
|
+
* and this is the separate "now host it" half. Idempotent.
|
|
5507
|
+
*
|
|
5508
|
+
* `admitterAddrs` is where the owner's own node can be dialed — take it from
|
|
5509
|
+
* that node's network status with {@link admitterAddrsFromNetworkStatus}.
|
|
5510
|
+
* The first fleet node placed on a namespace has nobody but the owner to ask
|
|
5511
|
+
* for admission, and without these it can only broadcast and hope the
|
|
5512
|
+
* owner's node — often a laptop behind a relay — hears it. They are a dial
|
|
5513
|
+
* hint, not a grant: the owner's node admits by its own policy. Omit them to
|
|
5514
|
+
* leave whatever the cloud already holds; pass them again when the node's
|
|
5515
|
+
* relay address changes, and they replace the stored ones.
|
|
5505
5516
|
*
|
|
5506
5517
|
* Not to be confused with {@link enableHA}, which opens the cloud's web flow
|
|
5507
5518
|
* in a browser tab for a user to complete by hand. This is the API call.
|
|
5508
5519
|
*/
|
|
5509
|
-
async enableNamespaceHa(namespaceId) {
|
|
5520
|
+
async enableNamespaceHa(namespaceId, options = {}) {
|
|
5521
|
+
const body = options.admitterAddrs === void 0 ? {} : { admitter_addrs: [...options.admitterAddrs] };
|
|
5510
5522
|
return this.request(
|
|
5511
5523
|
"POST",
|
|
5512
5524
|
`/api/cloud/namespaces/${encodeURIComponent(namespaceId)}/enable-ha`,
|
|
5513
|
-
{ body
|
|
5525
|
+
{ body }
|
|
5514
5526
|
);
|
|
5515
5527
|
}
|
|
5516
5528
|
/**
|
|
@@ -5834,6 +5846,23 @@ var CloudClient = class {
|
|
|
5834
5846
|
void this.notifySession(this.session);
|
|
5835
5847
|
}
|
|
5836
5848
|
};
|
|
5849
|
+
function admitterAddrsFromNetworkStatus(status) {
|
|
5850
|
+
const record = status && typeof status === "object" ? status.data ?? status : void 0;
|
|
5851
|
+
if (!record || typeof record !== "object") return [];
|
|
5852
|
+
const peerId = record.localPeerId;
|
|
5853
|
+
const external = record.externalAddrs;
|
|
5854
|
+
if (typeof peerId !== "string" || !peerId || !Array.isArray(external)) return [];
|
|
5855
|
+
const suffix = `/p2p/${peerId}`;
|
|
5856
|
+
const out = [];
|
|
5857
|
+
for (const entry of external) {
|
|
5858
|
+
if (typeof entry !== "string") continue;
|
|
5859
|
+
const addr = entry.trim();
|
|
5860
|
+
if (!addr.startsWith("/")) continue;
|
|
5861
|
+
const dialable = addr.endsWith(suffix) ? addr : `${addr}${suffix}`;
|
|
5862
|
+
if (!out.includes(dialable)) out.push(dialable);
|
|
5863
|
+
}
|
|
5864
|
+
return out;
|
|
5865
|
+
}
|
|
5837
5866
|
|
|
5838
5867
|
// src/mero-js.ts
|
|
5839
5868
|
function resolveProofSigner(config) {
|
|
@@ -5881,6 +5910,7 @@ var MeroJs = class {
|
|
|
5881
5910
|
const getProof = resolveProofSigner(this.config.requestProof);
|
|
5882
5911
|
this.httpClient = createBrowserHttpClient({
|
|
5883
5912
|
baseUrl: this.config.baseUrl,
|
|
5913
|
+
fetch: this.config.fetch,
|
|
5884
5914
|
getProof,
|
|
5885
5915
|
getAuthToken: async () => {
|
|
5886
5916
|
const token = await this.getValidToken();
|
|
@@ -5951,6 +5981,7 @@ var MeroJs = class {
|
|
|
5951
5981
|
if (!this.sseClient) {
|
|
5952
5982
|
this.sseClient = new SseClient({
|
|
5953
5983
|
baseUrl: this.config.baseUrl,
|
|
5984
|
+
fetch: this.config.fetch,
|
|
5954
5985
|
getAuthToken: async () => {
|
|
5955
5986
|
const token = await this.getValidToken();
|
|
5956
5987
|
return token?.access_token || "";
|