@calimero-network/mero-js 25.0.5 → 25.0.7
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/application-id.d.ts +3 -1
- package/dist/account/relay-from-invitation.js +3 -2
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +37 -13
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +37 -13
- package/dist/index.mjs.map +3 -3
- package/dist/mero-js.d.ts +5 -0
- package/dist/mero-js.js +31 -9
- package/dist/token-store/index.js +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10190,14 +10190,15 @@ async function resolveRelayFromInvitation(input) {
|
|
|
10190
10190
|
const addressable = candidates.filter(
|
|
10191
10191
|
(n) => typeof n.relayUrl === "string" && n.relayUrl.length > 0
|
|
10192
10192
|
);
|
|
10193
|
-
|
|
10193
|
+
const [firstAddressable] = addressable;
|
|
10194
|
+
if (firstAddressable === void 0) {
|
|
10194
10195
|
return {
|
|
10195
10196
|
ok: false,
|
|
10196
10197
|
step: "no-relay-url",
|
|
10197
10198
|
reason: "A node your invitation names can admit you, but the cloud knows no address for it yet, so there would be nothing to connect through afterwards. Try again shortly."
|
|
10198
10199
|
};
|
|
10199
10200
|
}
|
|
10200
|
-
const chosen = addressable.find((n) => n.canExecute) ?? addressable.find((n) => n.fresh) ??
|
|
10201
|
+
const chosen = addressable.find((n) => n.canExecute) ?? addressable.find((n) => n.fresh) ?? firstAddressable;
|
|
10201
10202
|
return {
|
|
10202
10203
|
ok: true,
|
|
10203
10204
|
relayUrl: chosen.relayUrl,
|
|
@@ -10562,7 +10563,10 @@ function newer(a, b) {
|
|
|
10562
10563
|
return false;
|
|
10563
10564
|
}
|
|
10564
10565
|
function selectLatestBundle(bundles) {
|
|
10565
|
-
return bundles.filter((b) => !b.yanked && typeof b.appVersion === "string" && b.appVersion.length > 0).reduce(
|
|
10566
|
+
return bundles.filter((b) => !b.yanked && typeof b.appVersion === "string" && b.appVersion.length > 0).reduce(
|
|
10567
|
+
(best, b) => !best || newer(b.appVersion, best.appVersion) ? b : best,
|
|
10568
|
+
void 0
|
|
10569
|
+
);
|
|
10566
10570
|
}
|
|
10567
10571
|
async function fetchRegistryBundles(registryUrl, pkg, fetchFn = globalThis.fetch) {
|
|
10568
10572
|
const url = `${registryUrl.replace(/\/+$/, "")}/api/v2/bundles?package=${encodeURIComponent(pkg)}`;
|
|
@@ -12073,6 +12077,14 @@ function getLockManager() {
|
|
|
12073
12077
|
const locks = nav?.locks;
|
|
12074
12078
|
return locks && typeof locks.request === "function" ? locks : null;
|
|
12075
12079
|
}
|
|
12080
|
+
function nodeKeyOf(baseUrl) {
|
|
12081
|
+
try {
|
|
12082
|
+
const { origin: origin2, pathname } = new URL(baseUrl);
|
|
12083
|
+
return origin2 === "null" ? baseUrl : origin2 + pathname.replace(/\/+$/, "");
|
|
12084
|
+
} catch {
|
|
12085
|
+
return baseUrl;
|
|
12086
|
+
}
|
|
12087
|
+
}
|
|
12076
12088
|
function expiresAtFromJwt(token, fallbackMs) {
|
|
12077
12089
|
try {
|
|
12078
12090
|
const parts = token.split(".");
|
|
@@ -12108,8 +12120,9 @@ var MeroJs = class {
|
|
|
12108
12120
|
...config
|
|
12109
12121
|
};
|
|
12110
12122
|
this.tokenStore = config.tokenStore ?? null;
|
|
12123
|
+
this.nodeKey = nodeKeyOf(config.baseUrl);
|
|
12124
|
+
this.tokenData = this.readStoredTokens();
|
|
12111
12125
|
if (this.tokenStore) {
|
|
12112
|
-
this.tokenData = this.tokenStore.getTokens();
|
|
12113
12126
|
this.storeHoldsTokens = this.tokenData !== null;
|
|
12114
12127
|
if (typeof window !== "undefined") window.addEventListener("storage", this.onStorage);
|
|
12115
12128
|
}
|
|
@@ -12130,7 +12143,7 @@ var MeroJs = class {
|
|
|
12130
12143
|
onTokenRefresh: async (newToken) => {
|
|
12131
12144
|
if (this.tokenData) {
|
|
12132
12145
|
this.tokenData.access_token = newToken;
|
|
12133
|
-
this.persistTokens(
|
|
12146
|
+
this.persistTokens();
|
|
12134
12147
|
}
|
|
12135
12148
|
},
|
|
12136
12149
|
onAuthRevoked: async () => {
|
|
@@ -12276,7 +12289,7 @@ var MeroJs = class {
|
|
|
12276
12289
|
refresh_token: response.data.refresh_token,
|
|
12277
12290
|
expires_at: expiresAtFromJwt(accessToken, Date.now() + 36e5)
|
|
12278
12291
|
};
|
|
12279
|
-
this.persistTokens(
|
|
12292
|
+
this.persistTokens();
|
|
12280
12293
|
return this.tokenData;
|
|
12281
12294
|
} catch (error) {
|
|
12282
12295
|
throw new Error(
|
|
@@ -12284,11 +12297,21 @@ var MeroJs = class {
|
|
|
12284
12297
|
);
|
|
12285
12298
|
}
|
|
12286
12299
|
}
|
|
12287
|
-
persistTokens(
|
|
12288
|
-
if (!this.tokenStore) return;
|
|
12289
|
-
this.tokenStore.setTokens(
|
|
12300
|
+
persistTokens() {
|
|
12301
|
+
if (!this.tokenStore || !this.tokenData) return;
|
|
12302
|
+
this.tokenStore.setTokens({ ...this.tokenData, node_origin: this.nodeKey });
|
|
12290
12303
|
this.storeHoldsTokens = this.tokenStore.getTokens() !== null;
|
|
12291
12304
|
}
|
|
12305
|
+
/** The stored bundle, only if this node issued it; a legacy or foreign entry reads as empty. */
|
|
12306
|
+
readStoredTokens() {
|
|
12307
|
+
const stored = this.tokenStore?.getTokens();
|
|
12308
|
+
if (!stored || stored.node_origin !== this.nodeKey) return null;
|
|
12309
|
+
return {
|
|
12310
|
+
access_token: stored.access_token,
|
|
12311
|
+
refresh_token: stored.refresh_token,
|
|
12312
|
+
expires_at: stored.expires_at
|
|
12313
|
+
};
|
|
12314
|
+
}
|
|
12292
12315
|
// Raw store read: an empty store is a logout, another node's bundle is not.
|
|
12293
12316
|
signedOutElsewhere() {
|
|
12294
12317
|
return this.storeHoldsTokens && !this.tokenStore?.getTokens();
|
|
@@ -12356,7 +12379,7 @@ var MeroJs = class {
|
|
|
12356
12379
|
this.dropLocalTokens();
|
|
12357
12380
|
throw new Error("Signed out in another tab");
|
|
12358
12381
|
}
|
|
12359
|
-
const stored = this.
|
|
12382
|
+
const stored = this.readStoredTokens();
|
|
12360
12383
|
if (stored?.refresh_token) {
|
|
12361
12384
|
this.storeHoldsTokens = true;
|
|
12362
12385
|
this.tokenData = stored;
|
|
@@ -12389,7 +12412,7 @@ var MeroJs = class {
|
|
|
12389
12412
|
refresh_token: response.data.refresh_token,
|
|
12390
12413
|
expires_at: expiresAtFromJwt(accessToken, Date.now() + 36e5)
|
|
12391
12414
|
};
|
|
12392
|
-
this.persistTokens(
|
|
12415
|
+
this.persistTokens();
|
|
12393
12416
|
return this.tokenData;
|
|
12394
12417
|
} catch (error) {
|
|
12395
12418
|
throw new Error(
|
|
@@ -12418,7 +12441,7 @@ var MeroJs = class {
|
|
|
12418
12441
|
setTokenData(data) {
|
|
12419
12442
|
const expiresAt = data.expires_at || expiresAtFromJwt(data.access_token, Date.now() + 36e5);
|
|
12420
12443
|
this.tokenData = { ...data, expires_at: expiresAt };
|
|
12421
|
-
this.persistTokens(
|
|
12444
|
+
this.persistTokens();
|
|
12422
12445
|
}
|
|
12423
12446
|
/**
|
|
12424
12447
|
* Get the current token data (for debugging)
|
|
@@ -12481,7 +12504,8 @@ var LocalStorageTokenStore = class {
|
|
|
12481
12504
|
return {
|
|
12482
12505
|
access_token: parsed.access_token,
|
|
12483
12506
|
refresh_token: parsed.refresh_token,
|
|
12484
|
-
expires_at: typeof parsed.expires_at === "number" ? parsed.expires_at : Date.now() + 36e5
|
|
12507
|
+
expires_at: typeof parsed.expires_at === "number" ? parsed.expires_at : Date.now() + 36e5,
|
|
12508
|
+
...typeof parsed.node_origin === "string" && { node_origin: parsed.node_origin }
|
|
12485
12509
|
};
|
|
12486
12510
|
}
|
|
12487
12511
|
return null;
|