@calimero-network/mero-js 7.0.3 → 7.0.5

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/index.mjs CHANGED
@@ -688,23 +688,61 @@ function unwrap(response) {
688
688
  return response?.data;
689
689
  }
690
690
  function compareSemver(a, b) {
691
- const pa = a.split(".");
692
- const pb = b.split(".");
693
- const n = Math.max(pa.length, pb.length);
691
+ const [coreA, preA] = splitVersion(a);
692
+ const [coreB, preB] = splitVersion(b);
693
+ const na = coreA.split(".");
694
+ const nb = coreB.split(".");
695
+ const n = Math.max(na.length, nb.length);
694
696
  for (let i = 0; i < n; i++) {
695
- const sa = pa[i] ?? "0";
696
- const sb = pb[i] ?? "0";
697
- const na = Number.parseInt(sa, 10);
698
- const nb = Number.parseInt(sb, 10);
699
- if (Number.isNaN(na) || Number.isNaN(nb)) {
700
- const c = sa.localeCompare(sb);
701
- if (c !== 0) return c;
702
- } else if (na !== nb) {
703
- return na - nb;
704
- }
697
+ const c = compareSemverId(na[i] ?? "0", nb[i] ?? "0");
698
+ if (c !== 0) return c;
699
+ }
700
+ if (preA === void 0 && preB === void 0) return 0;
701
+ if (preA === void 0) return 1;
702
+ if (preB === void 0) return -1;
703
+ const pa = preA.split(".");
704
+ const pb = preB.split(".");
705
+ const m = Math.max(pa.length, pb.length);
706
+ for (let i = 0; i < m; i++) {
707
+ if (i >= pa.length) return -1;
708
+ if (i >= pb.length) return 1;
709
+ const c = compareSemverId(pa[i], pb[i]);
710
+ if (c !== 0) return c;
705
711
  }
706
712
  return 0;
707
713
  }
714
+ function splitVersion(v) {
715
+ const core = v.split("+", 1)[0];
716
+ const dash = core.indexOf("-");
717
+ return dash === -1 ? [core, void 0] : [core.slice(0, dash), core.slice(dash + 1)];
718
+ }
719
+ function compareSemverId(a, b) {
720
+ const na = /^\d+$/.test(a);
721
+ const nb = /^\d+$/.test(b);
722
+ if (na && nb) {
723
+ const d = Number(a) - Number(b);
724
+ return d < 0 ? -1 : d > 0 ? 1 : 0;
725
+ }
726
+ if (na) return -1;
727
+ if (nb) return 1;
728
+ return a < b ? -1 : a > b ? 1 : 0;
729
+ }
730
+ async function fetchRegistry(url, kind, context) {
731
+ return withRetry(
732
+ async () => {
733
+ const resp = await fetch(url, { signal: AbortSignal.timeout(1e4) });
734
+ if (!resp.ok) {
735
+ const err = new Error(
736
+ `registry ${kind} fetch failed (${resp.status}) for ${context}`
737
+ );
738
+ err.status = resp.status;
739
+ throw err;
740
+ }
741
+ return resp;
742
+ },
743
+ { attempts: 3 }
744
+ );
745
+ }
708
746
  var AdminApiClient = class {
709
747
  constructor(httpClient) {
710
748
  this.httpClient = httpClient;
@@ -734,12 +772,7 @@ var AdminApiClient = class {
734
772
  `/api/v2/bundles/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}`,
735
773
  base
736
774
  ).toString();
737
- const resp = await fetch(manifestUrl);
738
- if (!resp.ok) {
739
- throw new Error(
740
- `registry manifest fetch failed (${resp.status}) for ${packageName}@${version}`
741
- );
742
- }
775
+ const resp = await fetchRegistry(manifestUrl, "manifest", `${packageName}@${version}`);
743
776
  const bundle = await resp.json();
744
777
  const pkg = encodeURIComponent(bundle.package);
745
778
  const ver = encodeURIComponent(bundle.appVersion);
@@ -762,12 +795,7 @@ var AdminApiClient = class {
762
795
  async getRegistryVersions(registryUrl, packageName) {
763
796
  const url = new URL("/api/v2/bundles", new URL(registryUrl).origin);
764
797
  url.searchParams.set("package", packageName);
765
- const resp = await fetch(url.toString());
766
- if (!resp.ok) {
767
- throw new Error(
768
- `registry versions fetch failed (${resp.status}) for ${packageName}`
769
- );
770
- }
798
+ const resp = await fetchRegistry(url.toString(), "versions", packageName);
771
799
  const bundles = await resp.json();
772
800
  return (Array.isArray(bundles) ? bundles : []).map((b) => b.appVersion).filter((v) => typeof v === "string").sort((a, b) => compareSemver(b, a));
773
801
  }