@seed-hypermedia/client 0.0.42 → 0.0.44

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/change.d.ts CHANGED
@@ -29,12 +29,12 @@ export type DocumentOperation = {
29
29
  export type CreateChangeOpsInput = {
30
30
  /** Native CBOR ops */
31
31
  ops: DocumentOperation[];
32
- /** CID of the genesis change blob */
33
- genesisCid: CID;
34
- /** CIDs of dependency changes */
35
- deps: CID[];
36
- /** Depth of the change (max depth of deps + 1) */
37
- depth: number;
32
+ /** CID of the genesis change blob. Omit when creating the first content change for a document. */
33
+ genesisCid?: CID;
34
+ /** CIDs of dependency changes. Omit when creating the first content change for a document. */
35
+ deps?: CID[];
36
+ /** Depth of the change (max depth of deps + 1). Omit when creating the first content change for a document. */
37
+ depth?: number;
38
38
  /** Timestamp (defaults to Date.now()) */
39
39
  ts?: bigint;
40
40
  };
@@ -68,7 +68,7 @@ export declare const signPreparedChange: (unsignedBytes: Uint8Array, signer: HMS
68
68
  }>;
69
69
  /**
70
70
  * Create a signed genesis Change blob (empty, ts=0).
71
- * This is the bootstrap blob for a new document, matching the web pattern.
71
+ * This deterministic sentinel is only intended for home documents.
72
72
  */
73
73
  export declare function createGenesisChange(signer: HMSigner): Promise<{
74
74
  bytes: Uint8Array;
package/dist/client.d.ts CHANGED
@@ -19,13 +19,17 @@ export type SeedClientOptions = {
19
19
  fetch?: typeof globalThis.fetch;
20
20
  headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
21
21
  };
22
+ /** Options that control an individual Seed API request. */
23
+ export type SeedClientRequestOptions = {
24
+ signal?: AbortSignal;
25
+ };
22
26
  type PublishBlobsRequest = Extract<HMRequest, {
23
27
  key: 'PublishBlobs';
24
28
  }>;
25
29
  export type SeedClient = {
26
30
  request<K extends HMRequest['key']>(key: K, input: Extract<HMRequest, {
27
31
  key: K;
28
- }>['input']): Promise<Extract<HMRequest, {
32
+ }>['input'], options?: SeedClientRequestOptions): Promise<Extract<HMRequest, {
29
33
  key: K;
30
34
  }>['output']>;
31
35
  publish(input: PublishBlobsRequest['input']): Promise<PublishBlobsRequest['output']>;
package/dist/index.mjs CHANGED
@@ -209,11 +209,13 @@ function createChangeOps(input) {
209
209
  },
210
210
  signer: null,
211
211
  ts,
212
- sig: null,
213
- genesis: input.genesisCid,
214
- deps: input.deps,
215
- depth: input.depth
212
+ sig: null
216
213
  };
214
+ if (input.genesisCid) {
215
+ unsigned.genesis = input.genesisCid;
216
+ unsigned.deps = input.deps ?? [];
217
+ unsigned.depth = input.depth ?? 1;
218
+ }
217
219
  return { unsignedBytes: cborEncode4(unsigned), ts };
218
220
  }
219
221
  async function createChange(unsignedBytes, signer) {
@@ -373,7 +375,7 @@ function createSeedClient(baseUrl, options) {
373
375
  const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
374
376
  const fetchFn = (options == null ? void 0 : options.fetch) ?? globalThis.fetch;
375
377
  const getDefaultHeaders = async () => typeof (options == null ? void 0 : options.headers) === "function" ? await options.headers() : (options == null ? void 0 : options.headers) ?? {};
376
- async function request(key, input) {
378
+ async function request(key, input, options2) {
377
379
  const requestSchema = HMRequestSchema.options.find((schema) => schema.shape.key.value === key);
378
380
  if (!requestSchema) {
379
381
  throw new SeedValidationError(`Unknown request key: ${key}`);
@@ -397,9 +399,11 @@ function createSeedClient(baseUrl, options) {
397
399
  "Content-Type": "application/cbor",
398
400
  ...defaultHeaders
399
401
  },
400
- body: new Uint8Array(cborEncode5(stripUndefined(validatedInput)))
402
+ body: new Uint8Array(cborEncode5(stripUndefined(validatedInput))),
403
+ signal: options2 == null ? void 0 : options2.signal
401
404
  });
402
405
  } catch (err) {
406
+ if (isAbortError(err)) throw err;
403
407
  throw new SeedNetworkError(
404
408
  `Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`,
405
409
  { cause: err }
@@ -424,9 +428,11 @@ function createSeedClient(baseUrl, options) {
424
428
  headers: {
425
429
  Accept: "application/json",
426
430
  ...defaultHeaders
427
- }
431
+ },
432
+ signal: options2 == null ? void 0 : options2.signal
428
433
  });
429
434
  } catch (err) {
435
+ if (isAbortError(err)) throw err;
430
436
  throw new SeedNetworkError(
431
437
  `Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`,
432
438
  { cause: err }
@@ -515,6 +521,9 @@ function createSeedClient(baseUrl, options) {
515
521
  publishDocument
516
522
  };
517
523
  }
524
+ function isAbortError(err) {
525
+ return typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError";
526
+ }
518
527
  function stripUndefined(obj) {
519
528
  if (obj === null || obj === void 0 || typeof obj !== "object") return obj;
520
529
  if (ArrayBuffer.isView(obj) || obj instanceof ArrayBuffer) return obj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-hypermedia/client",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",