@calimero-network/mero-js 19.0.0 → 19.1.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.mjs CHANGED
@@ -949,13 +949,30 @@ var AdminApiClient = class {
949
949
  );
950
950
  return { blobs: res.blobs.map((b) => ({ blobId: b.blob_id, size: b.size })) };
951
951
  }
952
+ /**
953
+ * Blob-read query params. `context_id` is the same snake_case param
954
+ * {@link uploadBlob} announces with; building it in one place keeps the read
955
+ * side from drifting from the write side.
956
+ */
957
+ blobPath(blobId, options) {
958
+ if (!options?.contextId) return `/admin-api/blobs/${blobId}`;
959
+ const params = new URLSearchParams({ context_id: options.contextId });
960
+ return `/admin-api/blobs/${blobId}?${params.toString()}`;
961
+ }
952
962
  /**
953
963
  * Download a blob's raw bytes. `GET /admin-api/blobs/:id` streams the blob
954
964
  * content (e.g. `application/gzip`), NOT JSON — so fetch it as an ArrayBuffer.
955
965
  * Use {@link listBlobs} for `{ blobId, size }` metadata.
966
+ *
967
+ * Without `contextId` the read is local-only: the node answers from its own
968
+ * blob store and returns immediately, or 404s. Passing `contextId` opts into
969
+ * network discovery — the node probes that context's peers (availability
970
+ * nodes first) for a holder, then transfers the bytes. Budget for it: core
971
+ * bounds discovery by a ~30s deadline, and the transfer is on top of that, so
972
+ * the worst case is well past what a UI should block on unhinted.
956
973
  */
957
- async getBlob(blobId) {
958
- return this.httpClient.get(`/admin-api/blobs/${blobId}`, {
974
+ async getBlob(blobId, options) {
975
+ return this.httpClient.get(this.blobPath(blobId, options), {
959
976
  parse: "arrayBuffer"
960
977
  });
961
978
  }
@@ -963,15 +980,26 @@ var AdminApiClient = class {
963
980
  * Fetch a blob's metadata without downloading it. `HEAD /admin-api/blobs/:id`
964
981
  * returns the info in response headers (size via `content-length`, plus
965
982
  * `x-blob-id`/`x-blob-hash`/`x-blob-mime-type`).
983
+ *
984
+ * Without `contextId` this is a local-only presence check that returns
985
+ * immediately. Passing `contextId` opts into the same network discovery
986
+ * {@link getBlob} uses — presence and size answered by probing the context's
987
+ * peers, with no transfer — so it inherits core's ~30s discovery deadline as
988
+ * its worst case. A probe only carries `found` and `size`, so a peer-sourced
989
+ * answer has no `hash`/`mimeType`; read `source` to tell the two apart.
966
990
  */
967
- async getBlobInfo(blobId) {
968
- const { headers } = await this.httpClient.head(`/admin-api/blobs/${blobId}`);
991
+ async getBlobInfo(blobId, options) {
992
+ const { headers } = await this.httpClient.head(this.blobPath(blobId, options));
969
993
  const size = Number(headers["content-length"]);
970
994
  return {
971
995
  blobId: headers["x-blob-id"] ?? blobId,
972
996
  size: Number.isFinite(size) ? size : 0,
973
997
  hash: headers["x-blob-hash"],
974
- mimeType: headers["x-blob-mime-type"]
998
+ mimeType: headers["x-blob-mime-type"],
999
+ // Nodes that predate the context-aware HEAD omit this header entirely, so
1000
+ // it stays undefined rather than being defaulted to 'local' — absent means
1001
+ // "the node didn't say", which is not the same claim as "served locally".
1002
+ source: headers["x-blob-source"]
975
1003
  };
976
1004
  }
977
1005
  // ---- Alias Management ----