@seed-hypermedia/client 0.0.94 → 0.0.96

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.
@@ -19,6 +19,9 @@ import {
19
19
 
20
20
  // src/client.ts
21
21
  import { encode as cborEncode } from "@ipld/dag-cbor";
22
+ import { blake2b } from "@noble/hashes/blake2.js";
23
+ import { CID } from "multiformats/cid";
24
+ import * as Digest from "multiformats/hashes/digest";
22
25
  import { deserialize } from "superjson";
23
26
  var PRIMITIVE_VALUE_KEY = "__value";
24
27
  function serializeQueryString(data, _schema) {
@@ -62,6 +65,8 @@ function deserializeQueryString(queryString, schema) {
62
65
  }
63
66
  return schema.parse(result);
64
67
  }
68
+ var DAG_CBOR_CODEC = 113;
69
+ var BLAKE2B_256_CODE = 45600;
65
70
  var QUERY_PARAM_SERIALIZERS = {
66
71
  Account: (input) => ({
67
72
  id: input
@@ -175,8 +180,53 @@ function createSeedClient(baseUrl, options) {
175
180
  const deserialized = rawJson && typeof rawJson === "object" && !Array.isArray(rawJson) && "json" in rawJson ? deserialize(rawJson) : rawJson;
176
181
  return requestSchema.shape.output.parse(deserialized);
177
182
  }
178
- function publish(input) {
179
- return request("PublishBlobs", input);
183
+ function daemonBlobCid(data) {
184
+ return CID.createV1(DAG_CBOR_CODEC, Digest.create(BLAKE2B_256_CODE, blake2b(data, { dkLen: 32 }))).toString();
185
+ }
186
+ async function putBlob(blob, options2) {
187
+ const url = `${normalizedBaseUrl}/ipfs/${blob.cid}`;
188
+ const defaultHeaders = await getDefaultHeaders();
189
+ let response;
190
+ try {
191
+ response = await fetchFn(url, {
192
+ method: "POST",
193
+ headers: { "Content-Type": "application/octet-stream", ...defaultHeaders },
194
+ body: new Uint8Array(blob.data),
195
+ signal: options2 == null ? void 0 : options2.signal
196
+ });
197
+ } catch (err) {
198
+ if (isAbortError(err)) throw err;
199
+ throw new SeedNetworkError(
200
+ `Network error storing blob ${blob.cid}: ${err instanceof Error ? err.message : String(err)}`,
201
+ { cause: err }
202
+ );
203
+ }
204
+ if (!response.ok) {
205
+ let errorBody;
206
+ try {
207
+ errorBody = await response.text();
208
+ } catch {
209
+ }
210
+ throw new SeedClientError(
211
+ formatHTTPErrorMessage(`PutBlob ${blob.cid}`, response.status, response.statusText, errorBody),
212
+ response.status,
213
+ errorBody
214
+ );
215
+ }
216
+ }
217
+ async function publish(input) {
218
+ try {
219
+ return await request("PublishBlobs", input);
220
+ } catch (err) {
221
+ if (!(err instanceof SeedClientError && err.status === 413)) throw err;
222
+ const cids = [];
223
+ for (const blob of input.blobs) {
224
+ const cid = blob.cid || daemonBlobCid(blob.data);
225
+ await putBlob({ cid, data: blob.data });
226
+ cids.push(cid);
227
+ }
228
+ return { cids };
229
+ }
180
230
  }
181
231
  async function publishDocument(input, signer) {
182
232
  if (!input.genesis && !input.baseVersion && !input.path) {
@@ -265,6 +315,8 @@ function createSeedClient(baseUrl, options) {
265
315
  request,
266
316
  publish,
267
317
  publishBlobs: publish,
318
+ putBlob,
319
+ daemonBlobCid,
268
320
  publishDocument
269
321
  };
270
322
  }
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-X3636TQF.mjs";
4
4
  import {
5
5
  createSeedClient
6
- } from "./chunk-HQP7SFVC.mjs";
6
+ } from "./chunk-5YWGB4XU.mjs";
7
7
  import {
8
8
  unpackHmId
9
9
  } from "./chunk-3NYKSLJ4.mjs";
@@ -6,6 +6,7 @@ import {
6
6
 
7
7
  // src/schema-engine.ts
8
8
  var LIBRARY_AUTHORITY = "hyper.media";
9
+ var LEGACY_LIBRARY_AUTHORITIES = /* @__PURE__ */ new Set(["seed.hyper.media", "example.com"]);
9
10
  var KINDS = ["null", "boolean", "integer", "float", "string", "bytes", "list", "map", "struct", "link"];
10
11
  var LIBRARY_CORE = new Set(
11
12
  [
@@ -34,7 +35,7 @@ function refToName(ref) {
34
35
  const m = /^hm:\/\/([^/]+)\/(.+)$/.exec(ref);
35
36
  if (!m) return ref.replace(/\.schema\.json$|\.json$/, "");
36
37
  const [, auth = "", name = ""] = m;
37
- return auth === LIBRARY_AUTHORITY ? name : ref;
38
+ return auth === LIBRARY_AUTHORITY || LEGACY_LIBRARY_AUTHORITIES.has(auth) ? name : ref;
38
39
  }
39
40
  function nameToUrl(name) {
40
41
  return `hm://${LIBRARY_AUTHORITY}/${name}`;
@@ -10,7 +10,7 @@ import {
10
10
  schemaForCid,
11
11
  structFields,
12
12
  validate
13
- } from "./chunk-JSNDXUPG.mjs";
13
+ } from "./chunk-FFH7G6KW.mjs";
14
14
  import {
15
15
  HM_SCHEMAS
16
16
  } from "./chunk-ZWKMAGDU.mjs";
package/dist/client.d.ts CHANGED
@@ -39,8 +39,24 @@ export type SeedClient = {
39
39
  }>['input'], options?: SeedClientRequestOptions): Promise<Extract<HMRequest, {
40
40
  key: K;
41
41
  }>['output']>;
42
+ /**
43
+ * Store blobs. Goes through the site's `PublishBlobs` API; when the site refuses the request
44
+ * body as too large (413 — a site may cap its API bodies at a few KB) and every blob names its
45
+ * CID, the blobs are stored one per request through `putBlob` instead, and the result is the same.
46
+ */
42
47
  publish(input: PublishBlobsRequest['input']): Promise<PublishBlobsRequest['output']>;
43
48
  publishBlobs(input: PublishBlobsRequest['input']): Promise<PublishBlobsRequest['output']>;
49
+ /**
50
+ * Store one blob through the daemon's raw blob endpoint, `POST /ipfs/<cid>`, which every Seed
51
+ * site routes to its daemon with a file-sized body limit. The daemon recomputes the hash and
52
+ * refuses bytes that do not match the CID; a stored blob is indexed like one from `PublishBlobs`.
53
+ */
54
+ putBlob(blob: {
55
+ cid: string;
56
+ data: Uint8Array;
57
+ }, options?: SeedClientRequestOptions): Promise<void>;
58
+ /** The CID the daemon assigns a DAG-CBOR blob published without one (blake2b-256). */
59
+ daemonBlobCid(data: Uint8Array): string;
44
60
  publishDocument(input: PublishDocumentInput, signer: AnySigner): Promise<PublishDocumentResult>;
45
61
  baseUrl: string;
46
62
  };
package/dist/client.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createSeedClient,
3
3
  deserializeQueryString
4
- } from "./chunk-HQP7SFVC.mjs";
4
+ } from "./chunk-5YWGB4XU.mjs";
5
5
  import "./chunk-CBELM7KX.mjs";
6
6
  import "./chunk-O5MHN2EO.mjs";
7
7
  import "./chunk-PJ2RFT5A.mjs";
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveIdWithClient
3
- } from "./chunk-HAHROSQH.mjs";
3
+ } from "./chunk-6JS7R6XP.mjs";
4
4
  import {
5
5
  annotationContains,
6
6
  hmBlockToEditorBlock,
@@ -49,7 +49,7 @@ import {
49
49
  } from "./chunk-X3636TQF.mjs";
50
50
  import {
51
51
  createSeedClient
52
- } from "./chunk-HQP7SFVC.mjs";
52
+ } from "./chunk-5YWGB4XU.mjs";
53
53
  import {
54
54
  SeedClientError,
55
55
  SeedNetworkError,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  resolveIdWithClient
3
- } from "./chunk-HAHROSQH.mjs";
3
+ } from "./chunk-6JS7R6XP.mjs";
4
4
  import "./chunk-X3636TQF.mjs";
5
- import "./chunk-HQP7SFVC.mjs";
5
+ import "./chunk-5YWGB4XU.mjs";
6
6
  import "./chunk-CBELM7KX.mjs";
7
7
  import "./chunk-O5MHN2EO.mjs";
8
8
  import "./chunk-PJ2RFT5A.mjs";
@@ -35,7 +35,7 @@ import {
35
35
  typeOf,
36
36
  validate,
37
37
  validateAdvisory
38
- } from "./chunk-JSNDXUPG.mjs";
38
+ } from "./chunk-FFH7G6KW.mjs";
39
39
  import {
40
40
  HM_SCHEMAS,
41
41
  HM_SCHEMA_MANIFEST
@@ -17,8 +17,8 @@ import {
17
17
  resolveSchemaRef,
18
18
  schemaDefinitionCid,
19
19
  withoutSchemaLink
20
- } from "./chunk-BBJCA2PR.mjs";
21
- import "./chunk-JSNDXUPG.mjs";
20
+ } from "./chunk-OHN5ILTT.mjs";
21
+ import "./chunk-FFH7G6KW.mjs";
22
22
  import "./chunk-ZWKMAGDU.mjs";
23
23
  import "./chunk-VWSAFDOL.mjs";
24
24
  import "./chunk-3NYKSLJ4.mjs";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  classifyRef
3
- } from "./chunk-BBJCA2PR.mjs";
3
+ } from "./chunk-OHN5ILTT.mjs";
4
4
  import {
5
5
  kindOf,
6
6
  nameForCid,
7
7
  nameToUrl,
8
8
  schemaCid
9
- } from "./chunk-JSNDXUPG.mjs";
9
+ } from "./chunk-FFH7G6KW.mjs";
10
10
  import {
11
11
  HM_SCHEMAS
12
12
  } from "./chunk-ZWKMAGDU.mjs";
@@ -5,7 +5,7 @@ import {
5
5
  literalValue,
6
6
  resolveSchema,
7
7
  structFields
8
- } from "./chunk-JSNDXUPG.mjs";
8
+ } from "./chunk-FFH7G6KW.mjs";
9
9
  import "./chunk-ZWKMAGDU.mjs";
10
10
  import {
11
11
  dagJsonToIpld,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-hypermedia/client",
3
- "version": "0.0.94",
3
+ "version": "0.0.96",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",