@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.cjs
CHANGED
|
@@ -10475,14 +10475,15 @@ async function resolveRelayFromInvitation(input) {
|
|
|
10475
10475
|
const addressable = candidates.filter(
|
|
10476
10476
|
(n) => typeof n.relayUrl === "string" && n.relayUrl.length > 0
|
|
10477
10477
|
);
|
|
10478
|
-
|
|
10478
|
+
const [firstAddressable] = addressable;
|
|
10479
|
+
if (firstAddressable === void 0) {
|
|
10479
10480
|
return {
|
|
10480
10481
|
ok: false,
|
|
10481
10482
|
step: "no-relay-url",
|
|
10482
10483
|
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."
|
|
10483
10484
|
};
|
|
10484
10485
|
}
|
|
10485
|
-
const chosen = addressable.find((n) => n.canExecute) ?? addressable.find((n) => n.fresh) ??
|
|
10486
|
+
const chosen = addressable.find((n) => n.canExecute) ?? addressable.find((n) => n.fresh) ?? firstAddressable;
|
|
10486
10487
|
return {
|
|
10487
10488
|
ok: true,
|
|
10488
10489
|
relayUrl: chosen.relayUrl,
|
|
@@ -10847,7 +10848,10 @@ function newer(a, b) {
|
|
|
10847
10848
|
return false;
|
|
10848
10849
|
}
|
|
10849
10850
|
function selectLatestBundle(bundles) {
|
|
10850
|
-
return bundles.filter((b) => !b.yanked && typeof b.appVersion === "string" && b.appVersion.length > 0).reduce(
|
|
10851
|
+
return bundles.filter((b) => !b.yanked && typeof b.appVersion === "string" && b.appVersion.length > 0).reduce(
|
|
10852
|
+
(best, b) => !best || newer(b.appVersion, best.appVersion) ? b : best,
|
|
10853
|
+
void 0
|
|
10854
|
+
);
|
|
10851
10855
|
}
|
|
10852
10856
|
async function fetchRegistryBundles(registryUrl, pkg, fetchFn = globalThis.fetch) {
|
|
10853
10857
|
const url = `${registryUrl.replace(/\/+$/, "")}/api/v2/bundles?package=${encodeURIComponent(pkg)}`;
|
|
@@ -12358,6 +12362,14 @@ function getLockManager() {
|
|
|
12358
12362
|
const locks = nav?.locks;
|
|
12359
12363
|
return locks && typeof locks.request === "function" ? locks : null;
|
|
12360
12364
|
}
|
|
12365
|
+
function nodeKeyOf(baseUrl) {
|
|
12366
|
+
try {
|
|
12367
|
+
const { origin: origin2, pathname } = new URL(baseUrl);
|
|
12368
|
+
return origin2 === "null" ? baseUrl : origin2 + pathname.replace(/\/+$/, "");
|
|
12369
|
+
} catch {
|
|
12370
|
+
return baseUrl;
|
|
12371
|
+
}
|
|
12372
|
+
}
|
|
12361
12373
|
function expiresAtFromJwt(token, fallbackMs) {
|
|
12362
12374
|
try {
|
|
12363
12375
|
const parts = token.split(".");
|
|
@@ -12393,8 +12405,9 @@ var MeroJs = class {
|
|
|
12393
12405
|
...config
|
|
12394
12406
|
};
|
|
12395
12407
|
this.tokenStore = config.tokenStore ?? null;
|
|
12408
|
+
this.nodeKey = nodeKeyOf(config.baseUrl);
|
|
12409
|
+
this.tokenData = this.readStoredTokens();
|
|
12396
12410
|
if (this.tokenStore) {
|
|
12397
|
-
this.tokenData = this.tokenStore.getTokens();
|
|
12398
12411
|
this.storeHoldsTokens = this.tokenData !== null;
|
|
12399
12412
|
if (typeof window !== "undefined") window.addEventListener("storage", this.onStorage);
|
|
12400
12413
|
}
|
|
@@ -12415,7 +12428,7 @@ var MeroJs = class {
|
|
|
12415
12428
|
onTokenRefresh: async (newToken) => {
|
|
12416
12429
|
if (this.tokenData) {
|
|
12417
12430
|
this.tokenData.access_token = newToken;
|
|
12418
|
-
this.persistTokens(
|
|
12431
|
+
this.persistTokens();
|
|
12419
12432
|
}
|
|
12420
12433
|
},
|
|
12421
12434
|
onAuthRevoked: async () => {
|
|
@@ -12561,7 +12574,7 @@ var MeroJs = class {
|
|
|
12561
12574
|
refresh_token: response.data.refresh_token,
|
|
12562
12575
|
expires_at: expiresAtFromJwt(accessToken, Date.now() + 36e5)
|
|
12563
12576
|
};
|
|
12564
|
-
this.persistTokens(
|
|
12577
|
+
this.persistTokens();
|
|
12565
12578
|
return this.tokenData;
|
|
12566
12579
|
} catch (error) {
|
|
12567
12580
|
throw new Error(
|
|
@@ -12569,11 +12582,21 @@ var MeroJs = class {
|
|
|
12569
12582
|
);
|
|
12570
12583
|
}
|
|
12571
12584
|
}
|
|
12572
|
-
persistTokens(
|
|
12573
|
-
if (!this.tokenStore) return;
|
|
12574
|
-
this.tokenStore.setTokens(
|
|
12585
|
+
persistTokens() {
|
|
12586
|
+
if (!this.tokenStore || !this.tokenData) return;
|
|
12587
|
+
this.tokenStore.setTokens({ ...this.tokenData, node_origin: this.nodeKey });
|
|
12575
12588
|
this.storeHoldsTokens = this.tokenStore.getTokens() !== null;
|
|
12576
12589
|
}
|
|
12590
|
+
/** The stored bundle, only if this node issued it; a legacy or foreign entry reads as empty. */
|
|
12591
|
+
readStoredTokens() {
|
|
12592
|
+
const stored = this.tokenStore?.getTokens();
|
|
12593
|
+
if (!stored || stored.node_origin !== this.nodeKey) return null;
|
|
12594
|
+
return {
|
|
12595
|
+
access_token: stored.access_token,
|
|
12596
|
+
refresh_token: stored.refresh_token,
|
|
12597
|
+
expires_at: stored.expires_at
|
|
12598
|
+
};
|
|
12599
|
+
}
|
|
12577
12600
|
// Raw store read: an empty store is a logout, another node's bundle is not.
|
|
12578
12601
|
signedOutElsewhere() {
|
|
12579
12602
|
return this.storeHoldsTokens && !this.tokenStore?.getTokens();
|
|
@@ -12641,7 +12664,7 @@ var MeroJs = class {
|
|
|
12641
12664
|
this.dropLocalTokens();
|
|
12642
12665
|
throw new Error("Signed out in another tab");
|
|
12643
12666
|
}
|
|
12644
|
-
const stored = this.
|
|
12667
|
+
const stored = this.readStoredTokens();
|
|
12645
12668
|
if (stored?.refresh_token) {
|
|
12646
12669
|
this.storeHoldsTokens = true;
|
|
12647
12670
|
this.tokenData = stored;
|
|
@@ -12674,7 +12697,7 @@ var MeroJs = class {
|
|
|
12674
12697
|
refresh_token: response.data.refresh_token,
|
|
12675
12698
|
expires_at: expiresAtFromJwt(accessToken, Date.now() + 36e5)
|
|
12676
12699
|
};
|
|
12677
|
-
this.persistTokens(
|
|
12700
|
+
this.persistTokens();
|
|
12678
12701
|
return this.tokenData;
|
|
12679
12702
|
} catch (error) {
|
|
12680
12703
|
throw new Error(
|
|
@@ -12703,7 +12726,7 @@ var MeroJs = class {
|
|
|
12703
12726
|
setTokenData(data) {
|
|
12704
12727
|
const expiresAt = data.expires_at || expiresAtFromJwt(data.access_token, Date.now() + 36e5);
|
|
12705
12728
|
this.tokenData = { ...data, expires_at: expiresAt };
|
|
12706
|
-
this.persistTokens(
|
|
12729
|
+
this.persistTokens();
|
|
12707
12730
|
}
|
|
12708
12731
|
/**
|
|
12709
12732
|
* Get the current token data (for debugging)
|
|
@@ -12766,7 +12789,8 @@ var LocalStorageTokenStore = class {
|
|
|
12766
12789
|
return {
|
|
12767
12790
|
access_token: parsed.access_token,
|
|
12768
12791
|
refresh_token: parsed.refresh_token,
|
|
12769
|
-
expires_at: typeof parsed.expires_at === "number" ? parsed.expires_at : Date.now() + 36e5
|
|
12792
|
+
expires_at: typeof parsed.expires_at === "number" ? parsed.expires_at : Date.now() + 36e5,
|
|
12793
|
+
...typeof parsed.node_origin === "string" && { node_origin: parsed.node_origin }
|
|
12770
12794
|
};
|
|
12771
12795
|
}
|
|
12772
12796
|
return null;
|