@drawcall/market 0.8.1 → 0.8.2

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.
@@ -8,7 +8,7 @@ export interface MarketV1ClientOptions {
8
8
  }
9
9
  /**
10
10
  * A typed client for the v1 REST surface (`/api/v1`). Same call shapes as the legacy RPC client —
11
- * `client.asset.exact({ name })` — but speaking plain HTTP: reads are GETs on resource URLs, so
11
+ * `client.asset.search({ refs })` — but speaking plain HTTP: reads are GETs on resource URLs, so
12
12
  * they are curl-able, shareable and cacheable.
13
13
  */
14
14
  export declare function createClient(opts?: MarketV1ClientOptions): MarketV1Client;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/v1/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,eAAe,CAAA;AAEzD,MAAM,MAAM,cAAc,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAA;AAI7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,qBAA0B,GAAG,cAAc,CAO7E"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/v1/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,eAAe,CAAA;AAEzD,MAAM,MAAM,cAAc,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAA;AAQ7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AA2BD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,qBAA0B,GAAG,cAAc,CAO7E"}
package/dist/v1/client.js CHANGED
@@ -2,15 +2,44 @@ import { createORPCClient } from '@orpc/client';
2
2
  import { OpenAPILink } from '@orpc/openapi-client/fetch';
3
3
  import { contract } from './contract.js';
4
4
  const DEFAULT_BASE_URL = 'https://market.drawcall.ai';
5
+ /** A read that is silent this long is a stalled connection, not a slow answer. */
6
+ const READ_TIMEOUT_MS = 10_000;
7
+ const READ_ATTEMPTS = 3;
8
+ /**
9
+ * GETs are idempotent, so a stalled connection is retried on a fresh one with a
10
+ * bounded timeout — an unbounded hang in one read would otherwise hang whole
11
+ * installs. Writes (uploads run to a gigabyte) keep the caller's fetch as-is.
12
+ */
13
+ function resilientReads(baseFetch) {
14
+ return async (input, init) => {
15
+ const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase();
16
+ if (method !== 'GET' && method !== 'HEAD')
17
+ return baseFetch(input, init);
18
+ let lastError;
19
+ for (let attempt = 1; attempt <= READ_ATTEMPTS; attempt++) {
20
+ const timeout = AbortSignal.timeout(READ_TIMEOUT_MS);
21
+ const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
22
+ try {
23
+ return await baseFetch(input, { ...init, signal });
24
+ }
25
+ catch (error) {
26
+ lastError = error;
27
+ if (init?.signal?.aborted || attempt === READ_ATTEMPTS)
28
+ throw error;
29
+ }
30
+ }
31
+ throw lastError;
32
+ };
33
+ }
5
34
  /**
6
35
  * A typed client for the v1 REST surface (`/api/v1`). Same call shapes as the legacy RPC client —
7
- * `client.asset.exact({ name })` — but speaking plain HTTP: reads are GETs on resource URLs, so
36
+ * `client.asset.search({ refs })` — but speaking plain HTTP: reads are GETs on resource URLs, so
8
37
  * they are curl-able, shareable and cacheable.
9
38
  */
10
39
  export function createClient(opts = {}) {
11
40
  const link = new OpenAPILink(contract, {
12
41
  url: new URL('/api/v1', opts.baseUrl ?? DEFAULT_BASE_URL).href,
13
- fetch: opts.fetch,
42
+ fetch: resilientReads(opts.fetch ?? ((input, init) => globalThis.fetch(input, init))),
14
43
  headers: opts.authToken ? { authorization: `Bearer ${opts.authToken}` } : undefined,
15
44
  });
16
45
  return createORPCClient(link);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/v1/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAA;AAIzD,MAAM,gBAAgB,GAAG,4BAA4B,CAAA;AAQrD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAA8B,EAAE;IAC3D,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,QAAQ,EAAE;QACrC,GAAG,EAAE,IAAI,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,IAAI;QAC9D,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;KACpF,CAAC,CAAA;IACF,OAAO,gBAAgB,CAAiB,IAAI,CAAC,CAAA;AAC/C,CAAC"}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/v1/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAA;AAIzD,MAAM,gBAAg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,OAA8B,EAAE;IAC3D,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,QAAQ,EAAE;QACrC,GAAG,EAAE,IAAI,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,IAAI;QAC9D,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACrF,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;KACpF,CAAC,CAAA;IACF,OAAO,gBAAgB,CAAiB,IAAI,CAAC,CAAA;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawcall/market",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/drawcall-ai/market",
package/src/v1/client.ts CHANGED
@@ -7,21 +7,50 @@ export type MarketV1Client = ContractRouterClient<V1Contract>
7
7
 
8
8
  const DEFAULT_BASE_URL = 'https://market.drawcall.ai'
9
9
 
10
+ /** A read that is silent this long is a stalled connection, not a slow answer. */
11
+ const READ_TIMEOUT_MS = 10_000
12
+ const READ_ATTEMPTS = 3
13
+
10
14
  export interface MarketV1ClientOptions {
11
15
  baseUrl?: string
12
16
  fetch?: typeof globalThis.fetch
13
17
  authToken?: string
14
18
  }
15
19
 
20
+ /**
21
+ * GETs are idempotent, so a stalled connection is retried on a fresh one with a
22
+ * bounded timeout — an unbounded hang in one read would otherwise hang whole
23
+ * installs. Writes (uploads run to a gigabyte) keep the caller's fetch as-is.
24
+ */
25
+ function resilientReads(baseFetch: typeof globalThis.fetch): typeof globalThis.fetch {
26
+ return async (input, init) => {
27
+ const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase()
28
+ if (method !== 'GET' && method !== 'HEAD') return baseFetch(input, init)
29
+
30
+ let lastError: unknown
31
+ for (let attempt = 1; attempt <= READ_ATTEMPTS; attempt++) {
32
+ const timeout = AbortSignal.timeout(READ_TIMEOUT_MS)
33
+ const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout
34
+ try {
35
+ return await baseFetch(input, { ...init, signal })
36
+ } catch (error) {
37
+ lastError = error
38
+ if (init?.signal?.aborted || attempt === READ_ATTEMPTS) throw error
39
+ }
40
+ }
41
+ throw lastError
42
+ }
43
+ }
44
+
16
45
  /**
17
46
  * A typed client for the v1 REST surface (`/api/v1`). Same call shapes as the legacy RPC client —
18
- * `client.asset.exact({ name })` — but speaking plain HTTP: reads are GETs on resource URLs, so
47
+ * `client.asset.search({ refs })` — but speaking plain HTTP: reads are GETs on resource URLs, so
19
48
  * they are curl-able, shareable and cacheable.
20
49
  */
21
50
  export function createClient(opts: MarketV1ClientOptions = {}): MarketV1Client {
22
51
  const link = new OpenAPILink(contract, {
23
52
  url: new URL('/api/v1', opts.baseUrl ?? DEFAULT_BASE_URL).href,
24
- fetch: opts.fetch,
53
+ fetch: resilientReads(opts.fetch ?? ((input, init) => globalThis.fetch(input, init))),
25
54
  headers: opts.authToken ? { authorization: `Bearer ${opts.authToken}` } : undefined,
26
55
  })
27
56
  return createORPCClient<MarketV1Client>(link)