@calimero-network/mero-js 2.3.0 → 2.4.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/admin-api/admin-client.d.ts +25 -0
- package/dist/admin-api/admin-client.d.ts.map +1 -1
- package/dist/admin-api/admin-client.js +76 -0
- package/dist/admin-api/admin-client.js.map +1 -1
- package/dist/admin-api/admin-types.d.ts +33 -1
- package/dist/admin-api/admin-types.d.ts.map +1 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +70 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +70 -0
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -638,6 +638,24 @@ function createAuthApiClientFromHttpClient(httpClient, _config) {
|
|
|
638
638
|
function unwrap(response) {
|
|
639
639
|
return response.data;
|
|
640
640
|
}
|
|
641
|
+
function compareSemver(a, b) {
|
|
642
|
+
const pa = a.split(".");
|
|
643
|
+
const pb = b.split(".");
|
|
644
|
+
const n = Math.max(pa.length, pb.length);
|
|
645
|
+
for (let i = 0; i < n; i++) {
|
|
646
|
+
const sa = pa[i] ?? "0";
|
|
647
|
+
const sb = pb[i] ?? "0";
|
|
648
|
+
const na = Number.parseInt(sa, 10);
|
|
649
|
+
const nb = Number.parseInt(sb, 10);
|
|
650
|
+
if (Number.isNaN(na) || Number.isNaN(nb)) {
|
|
651
|
+
const c = sa.localeCompare(sb);
|
|
652
|
+
if (c !== 0) return c;
|
|
653
|
+
} else if (na !== nb) {
|
|
654
|
+
return na - nb;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return 0;
|
|
658
|
+
}
|
|
641
659
|
var AdminApiClient = class {
|
|
642
660
|
constructor(httpClient) {
|
|
643
661
|
this.httpClient = httpClient;
|
|
@@ -653,6 +671,57 @@ var AdminApiClient = class {
|
|
|
653
671
|
async installApplication(request) {
|
|
654
672
|
return unwrap(await this.httpClient.post("/admin-api/install-application", request));
|
|
655
673
|
}
|
|
674
|
+
/**
|
|
675
|
+
* Resolve a `package@version` to its registry artifact URL and install it.
|
|
676
|
+
* Node install is URL-based (no node-side package+version resolution), so this
|
|
677
|
+
* fetches the bundle manifest from the registry, derives the `.mpk` artifact
|
|
678
|
+
* URL, then calls {@link installApplication}. `registryUrl` is the registry
|
|
679
|
+
* origin. This is the discrete "download" step an Updates flow pairs with a
|
|
680
|
+
* subsequent `upgradeGroup`.
|
|
681
|
+
*/
|
|
682
|
+
async installFromRegistry(registryUrl, packageName, version) {
|
|
683
|
+
const base = new URL(registryUrl).origin;
|
|
684
|
+
const manifestUrl = new URL(
|
|
685
|
+
`/api/v2/bundles/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}`,
|
|
686
|
+
base
|
|
687
|
+
).toString();
|
|
688
|
+
const resp = await fetch(manifestUrl);
|
|
689
|
+
if (!resp.ok) {
|
|
690
|
+
throw new Error(
|
|
691
|
+
`registry manifest fetch failed (${resp.status}) for ${packageName}@${version}`
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
const bundle = await resp.json();
|
|
695
|
+
const pkg = encodeURIComponent(bundle.package);
|
|
696
|
+
const ver = encodeURIComponent(bundle.appVersion);
|
|
697
|
+
const artifactUrl = `${base}/artifacts/${pkg}/${ver}/${pkg}-${ver}.mpk`;
|
|
698
|
+
return this.installApplication({
|
|
699
|
+
url: artifactUrl,
|
|
700
|
+
package: bundle.package,
|
|
701
|
+
version: bundle.appVersion,
|
|
702
|
+
metadata: []
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* List a package's published versions from the registry, newest-first by
|
|
707
|
+
* semver. Reads the registry's V2 bundle listing
|
|
708
|
+
* (`GET {registry}/api/v2/bundles?package={package}`), taking each bundle's
|
|
709
|
+
* `appVersion`. Registry-side data — distinct from the node's
|
|
710
|
+
* installed-version list — and the source an Updates view compares against
|
|
711
|
+
* the running `Context.applicationVersion` to detect "a new version exists".
|
|
712
|
+
*/
|
|
713
|
+
async getRegistryVersions(registryUrl, packageName) {
|
|
714
|
+
const url = new URL("/api/v2/bundles", new URL(registryUrl).origin);
|
|
715
|
+
url.searchParams.set("package", packageName);
|
|
716
|
+
const resp = await fetch(url.toString());
|
|
717
|
+
if (!resp.ok) {
|
|
718
|
+
throw new Error(
|
|
719
|
+
`registry versions fetch failed (${resp.status}) for ${packageName}`
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
const bundles = await resp.json();
|
|
723
|
+
return (Array.isArray(bundles) ? bundles : []).map((b) => b.appVersion).filter((v) => typeof v === "string").sort((a, b) => compareSemver(b, a));
|
|
724
|
+
}
|
|
656
725
|
async installDevApplication(request) {
|
|
657
726
|
return unwrap(await this.httpClient.post("/admin-api/install-dev-application", request));
|
|
658
727
|
}
|
|
@@ -2007,6 +2076,7 @@ export {
|
|
|
2007
2076
|
WsClient,
|
|
2008
2077
|
buildAuthLoginUrl,
|
|
2009
2078
|
combineSignals,
|
|
2079
|
+
compareSemver,
|
|
2010
2080
|
createAdminApiClient,
|
|
2011
2081
|
createAdminApiClientFromHttpClient,
|
|
2012
2082
|
createAuthApiClient,
|