@drawcall/market 0.8.1 → 0.8.3
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/v1/client.d.ts +1 -1
- package/dist/v1/client.d.ts.map +1 -1
- package/dist/v1/client.js +34 -2
- package/dist/v1/client.js.map +1 -1
- package/package.json +1 -1
- package/src/v1/client.ts +34 -2
package/dist/v1/client.d.ts
CHANGED
|
@@ -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.
|
|
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;
|
package/dist/v1/client.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAW7D,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,47 @@ 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
|
+
/** Reads answer in well under a second; silence this long is a stalled
|
|
6
|
+
* connection (observed in bursts between Fly and Cloudflare), not a slow
|
|
7
|
+
* answer. Three attempts bound the worst case at ~9s while keeping one
|
|
8
|
+
* stall to a ~3s detour. */
|
|
9
|
+
const READ_TIMEOUT_MS = 3_000;
|
|
10
|
+
const READ_ATTEMPTS = 3;
|
|
11
|
+
/**
|
|
12
|
+
* GETs are idempotent, so a stalled connection is retried on a fresh one with a
|
|
13
|
+
* bounded timeout — an unbounded hang in one read would otherwise hang whole
|
|
14
|
+
* installs. Writes (uploads run to a gigabyte) keep the caller's fetch as-is.
|
|
15
|
+
*/
|
|
16
|
+
function resilientReads(baseFetch) {
|
|
17
|
+
return async (input, init) => {
|
|
18
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase();
|
|
19
|
+
if (method !== 'GET' && method !== 'HEAD')
|
|
20
|
+
return baseFetch(input, init);
|
|
21
|
+
let lastError;
|
|
22
|
+
for (let attempt = 1; attempt <= READ_ATTEMPTS; attempt++) {
|
|
23
|
+
const timeout = AbortSignal.timeout(READ_TIMEOUT_MS);
|
|
24
|
+
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
25
|
+
try {
|
|
26
|
+
return await baseFetch(input, { ...init, signal });
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
lastError = error;
|
|
30
|
+
if (init?.signal?.aborted || attempt === READ_ATTEMPTS)
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
throw lastError;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
5
37
|
/**
|
|
6
38
|
* A typed client for the v1 REST surface (`/api/v1`). Same call shapes as the legacy RPC client —
|
|
7
|
-
* `client.asset.
|
|
39
|
+
* `client.asset.search({ refs })` — but speaking plain HTTP: reads are GETs on resource URLs, so
|
|
8
40
|
* they are curl-able, shareable and cacheable.
|
|
9
41
|
*/
|
|
10
42
|
export function createClient(opts = {}) {
|
|
11
43
|
const link = new OpenAPILink(contract, {
|
|
12
44
|
url: new URL('/api/v1', opts.baseUrl ?? DEFAULT_BASE_URL).href,
|
|
13
|
-
fetch: opts.fetch,
|
|
45
|
+
fetch: resilientReads(opts.fetch ?? ((input, init) => globalThis.fetch(input, init))),
|
|
14
46
|
headers: opts.authToken ? { authorization: `Bearer ${opts.authToken}` } : undefined,
|
|
15
47
|
});
|
|
16
48
|
return createORPCClient(link);
|
package/dist/v1/client.js.map
CHANGED
|
@@ -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;
|
|
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;AAEr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AAM,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
package/src/v1/client.ts
CHANGED
|
@@ -7,21 +7,53 @@ export type MarketV1Client = ContractRouterClient<V1Contract>
|
|
|
7
7
|
|
|
8
8
|
const DEFAULT_BASE_URL = 'https://market.drawcall.ai'
|
|
9
9
|
|
|
10
|
+
/** Reads answer in well under a second; silence this long is a stalled
|
|
11
|
+
* connection (observed in bursts between Fly and Cloudflare), not a slow
|
|
12
|
+
* answer. Three attempts bound the worst case at ~9s while keeping one
|
|
13
|
+
* stall to a ~3s detour. */
|
|
14
|
+
const READ_TIMEOUT_MS = 3_000
|
|
15
|
+
const READ_ATTEMPTS = 3
|
|
16
|
+
|
|
10
17
|
export interface MarketV1ClientOptions {
|
|
11
18
|
baseUrl?: string
|
|
12
19
|
fetch?: typeof globalThis.fetch
|
|
13
20
|
authToken?: string
|
|
14
21
|
}
|
|
15
22
|
|
|
23
|
+
/**
|
|
24
|
+
* GETs are idempotent, so a stalled connection is retried on a fresh one with a
|
|
25
|
+
* bounded timeout — an unbounded hang in one read would otherwise hang whole
|
|
26
|
+
* installs. Writes (uploads run to a gigabyte) keep the caller's fetch as-is.
|
|
27
|
+
*/
|
|
28
|
+
function resilientReads(baseFetch: typeof globalThis.fetch): typeof globalThis.fetch {
|
|
29
|
+
return async (input, init) => {
|
|
30
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase()
|
|
31
|
+
if (method !== 'GET' && method !== 'HEAD') return baseFetch(input, init)
|
|
32
|
+
|
|
33
|
+
let lastError: unknown
|
|
34
|
+
for (let attempt = 1; attempt <= READ_ATTEMPTS; attempt++) {
|
|
35
|
+
const timeout = AbortSignal.timeout(READ_TIMEOUT_MS)
|
|
36
|
+
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout
|
|
37
|
+
try {
|
|
38
|
+
return await baseFetch(input, { ...init, signal })
|
|
39
|
+
} catch (error) {
|
|
40
|
+
lastError = error
|
|
41
|
+
if (init?.signal?.aborted || attempt === READ_ATTEMPTS) throw error
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw lastError
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
16
48
|
/**
|
|
17
49
|
* A typed client for the v1 REST surface (`/api/v1`). Same call shapes as the legacy RPC client —
|
|
18
|
-
* `client.asset.
|
|
50
|
+
* `client.asset.search({ refs })` — but speaking plain HTTP: reads are GETs on resource URLs, so
|
|
19
51
|
* they are curl-able, shareable and cacheable.
|
|
20
52
|
*/
|
|
21
53
|
export function createClient(opts: MarketV1ClientOptions = {}): MarketV1Client {
|
|
22
54
|
const link = new OpenAPILink(contract, {
|
|
23
55
|
url: new URL('/api/v1', opts.baseUrl ?? DEFAULT_BASE_URL).href,
|
|
24
|
-
fetch: opts.fetch,
|
|
56
|
+
fetch: resilientReads(opts.fetch ?? ((input, init) => globalThis.fetch(input, init))),
|
|
25
57
|
headers: opts.authToken ? { authorization: `Bearer ${opts.authToken}` } : undefined,
|
|
26
58
|
})
|
|
27
59
|
return createORPCClient<MarketV1Client>(link)
|