@seed-hypermedia/client 0.0.42 → 0.0.43

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/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
@@ -373,7 +373,7 @@ function createSeedClient(baseUrl, options) {
373
373
  const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
374
374
  const fetchFn = (options == null ? void 0 : options.fetch) ?? globalThis.fetch;
375
375
  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) {
376
+ async function request(key, input, options2) {
377
377
  const requestSchema = HMRequestSchema.options.find((schema) => schema.shape.key.value === key);
378
378
  if (!requestSchema) {
379
379
  throw new SeedValidationError(`Unknown request key: ${key}`);
@@ -397,9 +397,11 @@ function createSeedClient(baseUrl, options) {
397
397
  "Content-Type": "application/cbor",
398
398
  ...defaultHeaders
399
399
  },
400
- body: new Uint8Array(cborEncode5(stripUndefined(validatedInput)))
400
+ body: new Uint8Array(cborEncode5(stripUndefined(validatedInput))),
401
+ signal: options2 == null ? void 0 : options2.signal
401
402
  });
402
403
  } catch (err) {
404
+ if (isAbortError(err)) throw err;
403
405
  throw new SeedNetworkError(
404
406
  `Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`,
405
407
  { cause: err }
@@ -424,9 +426,11 @@ function createSeedClient(baseUrl, options) {
424
426
  headers: {
425
427
  Accept: "application/json",
426
428
  ...defaultHeaders
427
- }
429
+ },
430
+ signal: options2 == null ? void 0 : options2.signal
428
431
  });
429
432
  } catch (err) {
433
+ if (isAbortError(err)) throw err;
430
434
  throw new SeedNetworkError(
431
435
  `Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`,
432
436
  { cause: err }
@@ -515,6 +519,9 @@ function createSeedClient(baseUrl, options) {
515
519
  publishDocument
516
520
  };
517
521
  }
522
+ function isAbortError(err) {
523
+ return typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError";
524
+ }
518
525
  function stripUndefined(obj) {
519
526
  if (obj === null || obj === void 0 || typeof obj !== "object") return obj;
520
527
  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.43",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",