@ts-pf/client-http 0.1.0-beta.0
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/README.md +27 -0
- package/dist/fetch-link.d.ts +21 -0
- package/dist/fetch-link.d.ts.map +1 -0
- package/dist/fetch-link.js +112 -0
- package/dist/fetch-link.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors.d.ts +6 -0
- package/dist/interceptors.d.ts.map +1 -0
- package/dist/interceptors.js +14 -0
- package/dist/interceptors.js.map +1 -0
- package/package.json +54 -0
- package/skills/ts-pf-client-http/SKILL.md +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @ts-pf/client-http
|
|
2
|
+
|
|
3
|
+
`FetchLink` and Fetch `Interceptor`s. Implements `Link` from [`@ts-pf/client`](../client). Analog of [`@ts-pf/message-client`](../message-client).
|
|
4
|
+
|
|
5
|
+
Agent skill: [`skills/ts-pf-client-http/`](skills/ts-pf-client-http/). Sync with `npx skills experimental_sync -y`.
|
|
6
|
+
|
|
7
|
+
Fetch interceptors wrap `Request` / `Response` inside `FetchLink` (headers, raw HTTP). They do not see structured RPC input or mapped `PFError`. Retry, cache, and in-flight dedupe belong on `createClient` as call interceptors / `CallPlugin`s (`RetryPlugin`, `DedupePlugin`, `CachePlugin`).
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createClient, RetryPlugin } from '@ts-pf/client'
|
|
11
|
+
import { FetchLink } from '@ts-pf/client-http'
|
|
12
|
+
|
|
13
|
+
const client = createClient<typeof contract>(
|
|
14
|
+
new FetchLink({
|
|
15
|
+
url: '/rpc',
|
|
16
|
+
interceptors: [
|
|
17
|
+
async ({ request, next }) => {
|
|
18
|
+
request.headers.set('x-trace', '1')
|
|
19
|
+
return next(request)
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
}),
|
|
23
|
+
{ plugins: [new RetryPlugin()] },
|
|
24
|
+
)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Do not import this package from `@ts-pf/server-http` (prod).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Link } from '@ts-pf/client';
|
|
2
|
+
import { type RpcCodec } from '@ts-pf/http';
|
|
3
|
+
import { PFError, type PFResultPromise } from '@ts-pf/protocol';
|
|
4
|
+
import { type Interceptor } from './interceptors.js';
|
|
5
|
+
export declare class FetchLink implements Link {
|
|
6
|
+
private readonly url;
|
|
7
|
+
private readonly headers;
|
|
8
|
+
private readonly fetchFn;
|
|
9
|
+
private readonly interceptors;
|
|
10
|
+
private readonly codec;
|
|
11
|
+
constructor(opts: {
|
|
12
|
+
url: string;
|
|
13
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
interceptors?: Interceptor[];
|
|
16
|
+
codec?: RpcCodec;
|
|
17
|
+
});
|
|
18
|
+
call(path: string[], input: unknown, signal?: AbortSignal): PFResultPromise<unknown, PFError>;
|
|
19
|
+
private callInner;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=fetch-link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-link.d.ts","sourceRoot":"","sources":["../src/fetch-link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAIL,KAAK,QAAQ,EAEd,MAAM,aAAa,CAAA;AACpB,OAAO,EAGL,OAAO,EACP,KAAK,eAAe,EAGrB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,mBAAmB,CAAA;AAErE,qBAAa,SAAU,YAAW,IAAI;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAGX;IACb,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;gBAEpB,IAAI,EAAE;QAChB,GAAG,EAAE,MAAM,CAAA;QACX,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAA;QAClE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;QACpB,YAAY,CAAC,EAAE,WAAW,EAAE,CAAA;QAC5B,KAAK,CAAC,EAAE,QAAQ,CAAA;KACjB;IAQD,IAAI,CACF,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC;YAOtB,SAAS;CA0ExB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { JSONCodec, PROTOCOL_HEADER, } from '@ts-pf/http';
|
|
2
|
+
import { isPFError, localFailure, PFError, PROTOCOL_VERSION, } from '@ts-pf/protocol';
|
|
3
|
+
import { runInterceptors } from './interceptors.js';
|
|
4
|
+
export class FetchLink {
|
|
5
|
+
url;
|
|
6
|
+
headers;
|
|
7
|
+
fetchFn;
|
|
8
|
+
interceptors;
|
|
9
|
+
codec;
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.url = opts.url;
|
|
12
|
+
this.headers = opts.headers;
|
|
13
|
+
this.fetchFn = (opts.fetch ?? globalThis.fetch).bind(globalThis);
|
|
14
|
+
this.interceptors = opts.interceptors ?? [];
|
|
15
|
+
this.codec = opts.codec ?? new JSONCodec();
|
|
16
|
+
}
|
|
17
|
+
call(path, input, signal) {
|
|
18
|
+
return this.callInner(path, input, signal);
|
|
19
|
+
}
|
|
20
|
+
async callInner(path, input, signal) {
|
|
21
|
+
const url = joinUrl(this.url, path);
|
|
22
|
+
const headers = new Headers(typeof this.headers === 'function' ? await this.headers() : this.headers);
|
|
23
|
+
headers.set(PROTOCOL_HEADER, PROTOCOL_VERSION);
|
|
24
|
+
const encoded = await this.codec.encodeRequest({ input });
|
|
25
|
+
applyEncodedHeaders(headers, encoded);
|
|
26
|
+
const init = {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers,
|
|
29
|
+
body: encoded.body,
|
|
30
|
+
};
|
|
31
|
+
if (signal) {
|
|
32
|
+
init.signal = signal;
|
|
33
|
+
}
|
|
34
|
+
if (encoded.body instanceof ReadableStream) {
|
|
35
|
+
init.duplex = 'half';
|
|
36
|
+
}
|
|
37
|
+
const request = new Request(url, init);
|
|
38
|
+
let response;
|
|
39
|
+
try {
|
|
40
|
+
response = await runInterceptors(this.interceptors, request, (req) => this.fetchFn(req));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error instanceof PFError) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
if (isAbortFailure(error, signal)) {
|
|
47
|
+
throw localFailure('Request aborted', error);
|
|
48
|
+
}
|
|
49
|
+
throw localFailure(error instanceof Error ? error.message : 'Network error', error);
|
|
50
|
+
}
|
|
51
|
+
let decoded;
|
|
52
|
+
try {
|
|
53
|
+
decoded = await this.codec.decodeResponse(bodySource(response));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (isPFError(error) && isProtocolResponse(response)) {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
throw new PFError({
|
|
60
|
+
code: 'INTERNAL',
|
|
61
|
+
status: response.status,
|
|
62
|
+
message: isProtocolResponse(response)
|
|
63
|
+
? 'Invalid response'
|
|
64
|
+
: `Non-RPC response (HTTP ${response.status})`,
|
|
65
|
+
cause: error,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (!decoded.ok) {
|
|
69
|
+
throw new PFError({
|
|
70
|
+
code: decoded.error.code,
|
|
71
|
+
status: response.status,
|
|
72
|
+
message: decoded.error.message,
|
|
73
|
+
...(decoded.error.data !== undefined
|
|
74
|
+
? { data: decoded.error.data }
|
|
75
|
+
: {}),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return decoded.output;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function joinUrl(base, segments) {
|
|
82
|
+
const trimmed = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
83
|
+
if (segments.length === 0) {
|
|
84
|
+
return trimmed;
|
|
85
|
+
}
|
|
86
|
+
return `${trimmed}/${segments.join('/')}`;
|
|
87
|
+
}
|
|
88
|
+
function bodySource(response) {
|
|
89
|
+
return {
|
|
90
|
+
contentType: response.headers.get('content-type'),
|
|
91
|
+
text: () => response.text(),
|
|
92
|
+
formData: () => response.formData(),
|
|
93
|
+
body: () => response.body,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function applyEncodedHeaders(headers, encoded) {
|
|
97
|
+
if (encoded.body instanceof FormData) {
|
|
98
|
+
headers.delete('content-type');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
headers.set('content-type', encoded.contentType);
|
|
102
|
+
}
|
|
103
|
+
function isAbortFailure(error, signal) {
|
|
104
|
+
if (signal?.aborted) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return error instanceof Error && error.name === 'AbortError';
|
|
108
|
+
}
|
|
109
|
+
function isProtocolResponse(response) {
|
|
110
|
+
return response.headers.get(PROTOCOL_HEADER) != null;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=fetch-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-link.js","sourceRoot":"","sources":["../src/fetch-link.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,eAAe,GAIhB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,OAAO,EAEP,gBAAgB,GAEjB,MAAM,iBAAiB,CAAA;AACxB,OAAO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CAAC;QACjD,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE;QAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACnC,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI;KAC1B,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAgB,EAAE,OAAuB;IACpE,IAAI,OAAO,CAAC,IAAI,YAAY,QAAQ,EAAE,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;QAC9B,OAAM;IACR,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;AAClD,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,MAAoB;IAC1D,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAA;AAC9D,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAkB;IAC5C,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAA;AACtD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Interceptor = (ctx: {
|
|
2
|
+
request: Request;
|
|
3
|
+
next: (request?: Request) => Promise<Response>;
|
|
4
|
+
}) => Promise<Response>;
|
|
5
|
+
export declare function runInterceptors(interceptors: Interceptor[], request: Request, send: (request: Request) => Promise<Response>): Promise<Response>;
|
|
6
|
+
//# sourceMappingURL=interceptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC/C,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEvB,wBAAsB,eAAe,CACnC,YAAY,EAAE,WAAW,EAAE,EAC3B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAC5C,OAAO,CAAC,QAAQ,CAAC,CAYnB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function runInterceptors(interceptors, request, send) {
|
|
2
|
+
const run = (index, current) => {
|
|
3
|
+
const interceptor = interceptors[index];
|
|
4
|
+
if (!interceptor) {
|
|
5
|
+
return send(current);
|
|
6
|
+
}
|
|
7
|
+
return interceptor({
|
|
8
|
+
request: current,
|
|
9
|
+
next: (nextRequest) => run(index + 1, nextRequest ?? current),
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
return run(0, request);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=interceptors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,YAA2B,EAC3B,OAAgB,EAChB,IAA6C;IAE7C,MAAM,GAAG,GAAG,CAAC,KAAa,EAAE,OAAgB,EAAqB,EAAE;QACjE,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;QACvC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAA;QACtB,CAAC;QACD,OAAO,WAAW,CAAC;YACjB,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,WAAW,IAAI,OAAO,CAAC;SAC9D,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,OAAO,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AACxB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-pf/client-http",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "FetchLink and Fetch interceptors",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/crobinson42/ts-pf.git",
|
|
9
|
+
"directory": "packages/client-http"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/crobinson42/ts-pf/tree/main/packages/client-http#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/crobinson42/ts-pf/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./src/index.ts",
|
|
20
|
+
"import": "./src/index.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"skills"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"type-check": "tsc --noEmit",
|
|
40
|
+
"lint": "biome check src tests"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@ts-pf/client": "0.1.0-beta.0",
|
|
44
|
+
"@ts-pf/http": "0.1.0-beta.0",
|
|
45
|
+
"@ts-pf/protocol": "0.1.0-beta.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@ts-pf/contract": "0.1.0-beta.0",
|
|
49
|
+
"@ts-pf/server": "0.1.0-beta.0",
|
|
50
|
+
"@ts-pf/server-http": "0.1.0-beta.0",
|
|
51
|
+
"typebox": "^1.3.24",
|
|
52
|
+
"zod": "^4.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ts-pf-client-http
|
|
3
|
+
description: Use when calling ts-pf over Fetch with FetchLink or Fetch Interceptors for headers. Triggers: @ts-pf/client-http, FetchLink, Interceptor.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @ts-pf/client-http
|
|
7
|
+
|
|
8
|
+
`FetchLink` and Fetch `Interceptor`s. Implements `Link`.
|
|
9
|
+
|
|
10
|
+
Install: `npm i @ts-pf/client-http@beta`
|
|
11
|
+
|
|
12
|
+
Link for agents: `npx skills experimental_sync -y`
|
|
13
|
+
|
|
14
|
+
## Do
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createClient, RetryPlugin } from '@ts-pf/client'
|
|
18
|
+
import { FetchLink } from '@ts-pf/client-http'
|
|
19
|
+
|
|
20
|
+
const client = createClient<typeof contract>(
|
|
21
|
+
new FetchLink({
|
|
22
|
+
url: '/rpc',
|
|
23
|
+
interceptors: [
|
|
24
|
+
async ({ request, next }) => {
|
|
25
|
+
request.headers.set('x-trace', '1')
|
|
26
|
+
return next(request)
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
{ plugins: [new RetryPlugin()] },
|
|
31
|
+
)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Fetch interceptors see raw `Request` / `Response` / fetch throws, not mapped `PFError`. Retry, cache, and dedupe belong on `createClient`.
|
|
35
|
+
|
|
36
|
+
## API
|
|
37
|
+
|
|
38
|
+
- `FetchLink`
|
|
39
|
+
- `Interceptor`
|
|
40
|
+
|
|
41
|
+
## Pair with
|
|
42
|
+
|
|
43
|
+
- Client: `ts-pf-client`
|
|
44
|
+
- Server: `ts-pf-server-http`
|
|
45
|
+
- Codecs: `ts-pf-file` / `ts-pf-stream` / `ts-pf-sse` via `{ codec }`
|
|
46
|
+
|
|
47
|
+
## Don't
|
|
48
|
+
|
|
49
|
+
- Retry / cache / dedupe here (`RetryPlugin` / `DedupePlugin` / `CachePlugin` on `createClient`).
|
|
50
|
+
- `isLocalFailure` inside Fetch interceptors.
|