@calimero-network/mero-js 2.2.1 → 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/index.d.ts CHANGED
@@ -8,9 +8,10 @@ export type { AuthCallbackResult, AuthLoginOptions } from './auth';
8
8
  export { MemoryTokenStore, LocalStorageTokenStore } from './token-store';
9
9
  export type { TokenStore } from './token-store';
10
10
  export { RpcClient, RpcError } from './rpc';
11
+ export type { MigrateMyEntriesSummary } from './rpc';
11
12
  export type { ExecuteParams } from './rpc';
12
13
  export { SseClient, WsClient } from './events';
13
- export type { SseEventData, WsEventData } from './events';
14
+ export type { SseEventData, WsEventData, AppVersionChangedEvent } from './events';
14
15
  export * from './cloud';
15
16
  export * from './capabilities';
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGzD,cAAc,eAAe,CAAC;AAG9B,cAAc,YAAY,CAAC;AAG3B,cAAc,aAAa,CAAC;AAG5B,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC9D,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAGnE,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG1D,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGzD,cAAc,eAAe,CAAC;AAG9B,cAAc,YAAY,CAAC;AAG3B,cAAc,aAAa,CAAC;AAG5B,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC9D,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAGnE,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,YAAY,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AACrD,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAGlF,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,uEAAuE;AAEvE,iBAAiB;AACjB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGjD,2CAA2C;AAC3C,cAAc,eAAe,CAAC;AAE9B,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAE3B,mBAAmB;AACnB,cAAc,aAAa,CAAC;AAE5B,iBAAiB;AACjB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAG9D,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGzE,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAG/C,uCAAuC;AACvC,cAAc,SAAS,CAAC;AAExB,gDAAgD;AAChD,cAAc,gBAAgB,CAAC;AAE/B,YAAY"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,uEAAuE;AAEvE,iBAAiB;AACjB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGjD,2CAA2C;AAC3C,cAAc,eAAe,CAAC;AAE9B,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAE3B,mBAAmB;AACnB,cAAc,aAAa,CAAC;AAE5B,iBAAiB;AACjB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAG9D,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGzE,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAI5C,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAG/C,uCAAuC;AACvC,cAAc,SAAS,CAAC;AAExB,gDAAgD;AAChD,cAAc,gBAAgB,CAAC;AAE/B,YAAY"}
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
  }
@@ -1005,6 +1074,22 @@ var AdminApiClient = class {
1005
1074
  await this.httpClient.get(`/admin-api/groups/${groupId}/upgrade/status`)
1006
1075
  );
1007
1076
  }
1077
+ /**
1078
+ * The operator-facing "have all peers migrated?" rollup for a namespace.
1079
+ * The handler serializes the payload directly, so there is no `{ data }`
1080
+ * envelope to unwrap here (unlike most admin reads).
1081
+ */
1082
+ async getMigrationStatus(namespaceId) {
1083
+ const id = encodeURIComponent(namespaceId);
1084
+ return this.httpClient.get(`/admin-api/groups/${id}/migration-status`);
1085
+ }
1086
+ /** Per-group cascade-migration snapshots for a namespace. */
1087
+ async getCascadeStatus(namespaceId) {
1088
+ const id = encodeURIComponent(namespaceId);
1089
+ return unwrap(
1090
+ await this.httpClient.get(`/admin-api/groups/${id}/cascade-status`)
1091
+ );
1092
+ }
1008
1093
  async retryGroupUpgrade(groupId, request) {
1009
1094
  return unwrap(
1010
1095
  await this.httpClient.post(
@@ -1203,6 +1288,19 @@ var RpcClient = class {
1203
1288
  }
1204
1289
  return response.result;
1205
1290
  }
1291
+ /**
1292
+ * One-tap owner-driven convert: re-signs the caller's identity-gated entries
1293
+ * to the current schema. The export converts all of the caller's
1294
+ * below-target entries in a single sweep, so this issues one call and returns
1295
+ * the resulting summary — it does not loop.
1296
+ */
1297
+ async migrateMyEntries(contextId) {
1298
+ return this.execute({ contextId, method: "migrate_my_entries" });
1299
+ }
1300
+ /** Read-only count of the caller's entries still below the target schema. */
1301
+ async countMyPending(contextId) {
1302
+ return this.execute({ contextId, method: "count_my_pending" });
1303
+ }
1206
1304
  };
1207
1305
 
1208
1306
  // src/events/sse.ts
@@ -1233,6 +1331,20 @@ var SseClient = class {
1233
1331
  if (idx !== -1) arr.splice(idx, 1);
1234
1332
  }
1235
1333
  }
1334
+ /**
1335
+ * Typed convenience over the generic `'event'` stream: invokes `handler` only
1336
+ * for `AppVersionChanged` context events, with the payload already parsed.
1337
+ * Returns an unsubscribe closure (so callers need not retain the listener).
1338
+ */
1339
+ onAppVersionChanged(handler) {
1340
+ const listener = (ev) => {
1341
+ const d = ev.data;
1342
+ if (d?.type !== "AppVersionChanged") return;
1343
+ handler({ contextId: ev.contextId, fromVersion: d.data?.fromVersion, toVersion: d.data?.toVersion });
1344
+ };
1345
+ this.on("event", listener);
1346
+ return () => this.off("event", listener);
1347
+ }
1236
1348
  emit(event, arg) {
1237
1349
  const key = event;
1238
1350
  if (key in this.listeners) {
@@ -1964,6 +2076,7 @@ export {
1964
2076
  WsClient,
1965
2077
  buildAuthLoginUrl,
1966
2078
  combineSignals,
2079
+ compareSemver,
1967
2080
  createAdminApiClient,
1968
2081
  createAdminApiClientFromHttpClient,
1969
2082
  createAuthApiClient,