@calimero-network/mero-js 7.0.4 → 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.cjs CHANGED
@@ -749,23 +749,61 @@ function unwrap(response) {
749
749
  return response?.data;
750
750
  }
751
751
  function compareSemver(a, b) {
752
- const pa = a.split(".");
753
- const pb = b.split(".");
754
- const n = Math.max(pa.length, pb.length);
752
+ const [coreA, preA] = splitVersion(a);
753
+ const [coreB, preB] = splitVersion(b);
754
+ const na = coreA.split(".");
755
+ const nb = coreB.split(".");
756
+ const n = Math.max(na.length, nb.length);
755
757
  for (let i = 0; i < n; i++) {
756
- const sa = pa[i] ?? "0";
757
- const sb = pb[i] ?? "0";
758
- const na = Number.parseInt(sa, 10);
759
- const nb = Number.parseInt(sb, 10);
760
- if (Number.isNaN(na) || Number.isNaN(nb)) {
761
- const c = sa.localeCompare(sb);
762
- if (c !== 0) return c;
763
- } else if (na !== nb) {
764
- return na - nb;
765
- }
758
+ const c = compareSemverId(na[i] ?? "0", nb[i] ?? "0");
759
+ if (c !== 0) return c;
760
+ }
761
+ if (preA === void 0 && preB === void 0) return 0;
762
+ if (preA === void 0) return 1;
763
+ if (preB === void 0) return -1;
764
+ const pa = preA.split(".");
765
+ const pb = preB.split(".");
766
+ const m = Math.max(pa.length, pb.length);
767
+ for (let i = 0; i < m; i++) {
768
+ if (i >= pa.length) return -1;
769
+ if (i >= pb.length) return 1;
770
+ const c = compareSemverId(pa[i], pb[i]);
771
+ if (c !== 0) return c;
766
772
  }
767
773
  return 0;
768
774
  }
775
+ function splitVersion(v) {
776
+ const core = v.split("+", 1)[0];
777
+ const dash = core.indexOf("-");
778
+ return dash === -1 ? [core, void 0] : [core.slice(0, dash), core.slice(dash + 1)];
779
+ }
780
+ function compareSemverId(a, b) {
781
+ const na = /^\d+$/.test(a);
782
+ const nb = /^\d+$/.test(b);
783
+ if (na && nb) {
784
+ const d = Number(a) - Number(b);
785
+ return d < 0 ? -1 : d > 0 ? 1 : 0;
786
+ }
787
+ if (na) return -1;
788
+ if (nb) return 1;
789
+ return a < b ? -1 : a > b ? 1 : 0;
790
+ }
791
+ async function fetchRegistry(url, kind, context) {
792
+ return withRetry(
793
+ async () => {
794
+ const resp = await fetch(url, { signal: AbortSignal.timeout(1e4) });
795
+ if (!resp.ok) {
796
+ const err = new Error(
797
+ `registry ${kind} fetch failed (${resp.status}) for ${context}`
798
+ );
799
+ err.status = resp.status;
800
+ throw err;
801
+ }
802
+ return resp;
803
+ },
804
+ { attempts: 3 }
805
+ );
806
+ }
769
807
  var AdminApiClient = class {
770
808
  constructor(httpClient) {
771
809
  this.httpClient = httpClient;
@@ -795,12 +833,7 @@ var AdminApiClient = class {
795
833
  `/api/v2/bundles/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}`,
796
834
  base
797
835
  ).toString();
798
- const resp = await fetch(manifestUrl);
799
- if (!resp.ok) {
800
- throw new Error(
801
- `registry manifest fetch failed (${resp.status}) for ${packageName}@${version}`
802
- );
803
- }
836
+ const resp = await fetchRegistry(manifestUrl, "manifest", `${packageName}@${version}`);
804
837
  const bundle = await resp.json();
805
838
  const pkg = encodeURIComponent(bundle.package);
806
839
  const ver = encodeURIComponent(bundle.appVersion);
@@ -823,12 +856,7 @@ var AdminApiClient = class {
823
856
  async getRegistryVersions(registryUrl, packageName) {
824
857
  const url = new URL("/api/v2/bundles", new URL(registryUrl).origin);
825
858
  url.searchParams.set("package", packageName);
826
- const resp = await fetch(url.toString());
827
- if (!resp.ok) {
828
- throw new Error(
829
- `registry versions fetch failed (${resp.status}) for ${packageName}`
830
- );
831
- }
859
+ const resp = await fetchRegistry(url.toString(), "versions", packageName);
832
860
  const bundles = await resp.json();
833
861
  return (Array.isArray(bundles) ? bundles : []).map((b) => b.appVersion).filter((v) => typeof v === "string").sort((a, b) => compareSemver(b, a));
834
862
  }