recker 1.0.2-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/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/cache/file-storage.d.ts +13 -0
- package/dist/cache/file-storage.d.ts.map +1 -0
- package/dist/cache/file-storage.js +50 -0
- package/dist/cache/memory-storage.d.ts +10 -0
- package/dist/cache/memory-storage.d.ts.map +1 -0
- package/dist/cache/memory-storage.js +29 -0
- package/dist/cache/redis-storage.d.ts +16 -0
- package/dist/cache/redis-storage.d.ts.map +1 -0
- package/dist/cache/redis-storage.js +25 -0
- package/dist/constants.d.ts +19 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +18 -0
- package/dist/contract/index.d.ts +32 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +67 -0
- package/dist/core/client.d.ts +107 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +475 -0
- package/dist/core/errors.d.ts +19 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +34 -0
- package/dist/core/request-promise.d.ts +24 -0
- package/dist/core/request-promise.d.ts.map +1 -0
- package/dist/core/request-promise.js +77 -0
- package/dist/core/request.d.ts +15 -0
- package/dist/core/request.d.ts.map +1 -0
- package/dist/core/request.js +44 -0
- package/dist/core/response.d.ts +33 -0
- package/dist/core/response.d.ts.map +1 -0
- package/dist/core/response.js +154 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/mcp/client.d.ts +59 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +195 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/types.d.ts +151 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +1 -0
- package/dist/plugins/cache.d.ts +10 -0
- package/dist/plugins/cache.d.ts.map +1 -0
- package/dist/plugins/cache.js +72 -0
- package/dist/plugins/circuit-breaker.d.ts +14 -0
- package/dist/plugins/circuit-breaker.d.ts.map +1 -0
- package/dist/plugins/circuit-breaker.js +100 -0
- package/dist/plugins/compression.d.ts +5 -0
- package/dist/plugins/compression.d.ts.map +1 -0
- package/dist/plugins/compression.js +128 -0
- package/dist/plugins/cookie-jar.d.ts +6 -0
- package/dist/plugins/cookie-jar.d.ts.map +1 -0
- package/dist/plugins/cookie-jar.js +72 -0
- package/dist/plugins/dedup.d.ts +6 -0
- package/dist/plugins/dedup.d.ts.map +1 -0
- package/dist/plugins/dedup.js +34 -0
- package/dist/plugins/graphql.d.ts +13 -0
- package/dist/plugins/graphql.d.ts.map +1 -0
- package/dist/plugins/graphql.js +39 -0
- package/dist/plugins/har-player.d.ts +7 -0
- package/dist/plugins/har-player.d.ts.map +1 -0
- package/dist/plugins/har-player.js +53 -0
- package/dist/plugins/har-recorder.d.ts +7 -0
- package/dist/plugins/har-recorder.d.ts.map +1 -0
- package/dist/plugins/har-recorder.js +67 -0
- package/dist/plugins/logger.d.ts +11 -0
- package/dist/plugins/logger.d.ts.map +1 -0
- package/dist/plugins/logger.js +72 -0
- package/dist/plugins/pagination.d.ts +17 -0
- package/dist/plugins/pagination.d.ts.map +1 -0
- package/dist/plugins/pagination.js +105 -0
- package/dist/plugins/proxy-rotator.d.ts +8 -0
- package/dist/plugins/proxy-rotator.d.ts.map +1 -0
- package/dist/plugins/proxy-rotator.js +35 -0
- package/dist/plugins/rate-limit.d.ts +8 -0
- package/dist/plugins/rate-limit.d.ts.map +1 -0
- package/dist/plugins/rate-limit.js +57 -0
- package/dist/plugins/retry.d.ts +14 -0
- package/dist/plugins/retry.d.ts.map +1 -0
- package/dist/plugins/retry.js +92 -0
- package/dist/plugins/server-timing.d.ts +8 -0
- package/dist/plugins/server-timing.d.ts.map +1 -0
- package/dist/plugins/server-timing.js +24 -0
- package/dist/plugins/xsrf.d.ts +10 -0
- package/dist/plugins/xsrf.d.ts.map +1 -0
- package/dist/plugins/xsrf.js +48 -0
- package/dist/runner/request-runner.d.ts +47 -0
- package/dist/runner/request-runner.d.ts.map +1 -0
- package/dist/runner/request-runner.js +89 -0
- package/dist/transport/fetch.d.ts +6 -0
- package/dist/transport/fetch.d.ts.map +1 -0
- package/dist/transport/fetch.js +153 -0
- package/dist/transport/undici.d.ts +23 -0
- package/dist/transport/undici.d.ts.map +1 -0
- package/dist/transport/undici.js +218 -0
- package/dist/types/index.d.ts +251 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/agent-manager.d.ts +29 -0
- package/dist/utils/agent-manager.d.ts.map +1 -0
- package/dist/utils/agent-manager.js +133 -0
- package/dist/utils/body.d.ts +11 -0
- package/dist/utils/body.d.ts.map +1 -0
- package/dist/utils/body.js +136 -0
- package/dist/utils/cert.d.ts +12 -0
- package/dist/utils/cert.d.ts.map +1 -0
- package/dist/utils/cert.js +32 -0
- package/dist/utils/concurrency.d.ts +21 -0
- package/dist/utils/concurrency.d.ts.map +1 -0
- package/dist/utils/concurrency.js +116 -0
- package/dist/utils/dns.d.ts +7 -0
- package/dist/utils/dns.d.ts.map +1 -0
- package/dist/utils/dns.js +26 -0
- package/dist/utils/doh.d.ts +3 -0
- package/dist/utils/doh.d.ts.map +1 -0
- package/dist/utils/doh.js +35 -0
- package/dist/utils/header-parser.d.ts +81 -0
- package/dist/utils/header-parser.d.ts.map +1 -0
- package/dist/utils/header-parser.js +457 -0
- package/dist/utils/html-cleaner.d.ts +2 -0
- package/dist/utils/html-cleaner.d.ts.map +1 -0
- package/dist/utils/html-cleaner.js +21 -0
- package/dist/utils/logger.d.ts +33 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +160 -0
- package/dist/utils/progress.d.ts +4 -0
- package/dist/utils/progress.d.ts.map +1 -0
- package/dist/utils/progress.js +49 -0
- package/dist/utils/request-pool.d.ts +23 -0
- package/dist/utils/request-pool.d.ts.map +1 -0
- package/dist/utils/request-pool.js +100 -0
- package/dist/utils/sse.d.ts +8 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +62 -0
- package/dist/utils/streaming.d.ts +18 -0
- package/dist/utils/streaming.d.ts.map +1 -0
- package/dist/utils/streaming.js +83 -0
- package/dist/utils/task-pool.d.ts +38 -0
- package/dist/utils/task-pool.js +104 -0
- package/dist/utils/try-fn.d.ts +4 -0
- package/dist/utils/try-fn.d.ts.map +1 -0
- package/dist/utils/try-fn.js +53 -0
- package/dist/utils/upload.d.ts +10 -0
- package/dist/utils/upload.d.ts.map +1 -0
- package/dist/utils/upload.js +45 -0
- package/dist/utils/user-agent.d.ts +45 -0
- package/dist/utils/user-agent.d.ts.map +1 -0
- package/dist/utils/user-agent.js +100 -0
- package/dist/utils/whois.d.ts +15 -0
- package/dist/utils/whois.d.ts.map +1 -0
- package/dist/utils/whois.js +159 -0
- package/dist/websocket/client.d.ts +38 -0
- package/dist/websocket/client.d.ts.map +1 -0
- package/dist/websocket/client.js +184 -0
- package/package.json +100 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class HttpRequest {
|
|
2
|
+
url;
|
|
3
|
+
method;
|
|
4
|
+
headers;
|
|
5
|
+
body;
|
|
6
|
+
signal;
|
|
7
|
+
throwHttpErrors;
|
|
8
|
+
onUploadProgress;
|
|
9
|
+
onDownloadProgress;
|
|
10
|
+
constructor(url, options = {}) {
|
|
11
|
+
this.url = url;
|
|
12
|
+
this.method = options.method || 'GET';
|
|
13
|
+
this.headers = new Headers(options.headers);
|
|
14
|
+
this.body = options.body || null;
|
|
15
|
+
this.signal = options.signal;
|
|
16
|
+
this.throwHttpErrors = options.throwHttpErrors !== undefined ? options.throwHttpErrors : true;
|
|
17
|
+
this.onUploadProgress = options.onUploadProgress;
|
|
18
|
+
this.onDownloadProgress = options.onDownloadProgress;
|
|
19
|
+
}
|
|
20
|
+
withHeader(name, value) {
|
|
21
|
+
const newHeaders = new Headers(this.headers);
|
|
22
|
+
newHeaders.set(name, value);
|
|
23
|
+
return new HttpRequest(this.url, {
|
|
24
|
+
method: this.method,
|
|
25
|
+
headers: newHeaders,
|
|
26
|
+
body: this.body,
|
|
27
|
+
signal: this.signal,
|
|
28
|
+
throwHttpErrors: this.throwHttpErrors,
|
|
29
|
+
onUploadProgress: this.onUploadProgress,
|
|
30
|
+
onDownloadProgress: this.onDownloadProgress,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
withBody(body) {
|
|
34
|
+
return new HttpRequest(this.url, {
|
|
35
|
+
method: this.method,
|
|
36
|
+
headers: this.headers,
|
|
37
|
+
body: body,
|
|
38
|
+
signal: this.signal,
|
|
39
|
+
throwHttpErrors: this.throwHttpErrors,
|
|
40
|
+
onUploadProgress: this.onUploadProgress,
|
|
41
|
+
onDownloadProgress: this.onDownloadProgress,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ConnectionInfo, ReckerResponse, Timings, SSEEvent, ProgressEvent } from '../types/index.js';
|
|
2
|
+
import { Dispatcher } from 'undici';
|
|
3
|
+
import { type HeaderInfo, type CacheInfo, type RateLimitInfo } from '../utils/header-parser.js';
|
|
4
|
+
import type { Readable } from 'node:stream';
|
|
5
|
+
export declare class HttpResponse<T = unknown> implements ReckerResponse<T> {
|
|
6
|
+
readonly timings?: Timings;
|
|
7
|
+
readonly connection?: ConnectionInfo;
|
|
8
|
+
readonly raw: Response;
|
|
9
|
+
constructor(undiciRawResponse: Response | Dispatcher.ResponseData, options?: {
|
|
10
|
+
timings?: Timings;
|
|
11
|
+
connection?: ConnectionInfo;
|
|
12
|
+
});
|
|
13
|
+
get status(): number;
|
|
14
|
+
get statusText(): string;
|
|
15
|
+
get headers(): Headers;
|
|
16
|
+
get ok(): boolean;
|
|
17
|
+
get url(): string;
|
|
18
|
+
get cache(): CacheInfo;
|
|
19
|
+
get rateLimit(): RateLimitInfo;
|
|
20
|
+
get headerInfo(): HeaderInfo;
|
|
21
|
+
json<R = T>(): Promise<R>;
|
|
22
|
+
text(): Promise<string>;
|
|
23
|
+
cleanText(): Promise<string>;
|
|
24
|
+
blob(): Promise<Blob>;
|
|
25
|
+
read(): ReadableStream<Uint8Array> | null;
|
|
26
|
+
toNodeStream(): Readable | null;
|
|
27
|
+
pipe(destination: NodeJS.WritableStream): Promise<void>;
|
|
28
|
+
clone(): ReckerResponse<T>;
|
|
29
|
+
sse(): AsyncGenerator<SSEEvent>;
|
|
30
|
+
download(): AsyncGenerator<ProgressEvent>;
|
|
31
|
+
[Symbol.asyncIterator](): AsyncGenerator<Uint8Array>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/core/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAKpC,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC9G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,qBAAa,YAAY,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,cAAc,CAAC,CAAC,CAAC;IACjE,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClC,SAAgB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5C,SAAgB,GAAG,EAAE,QAAQ,CAAC;gBAG5B,iBAAiB,EAAE,QAAQ,GAAG,UAAU,CAAC,YAAY,EACrD,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,cAAc,CAAA;KAAO;IAkBlE,IAAI,MAAM,WAET;IAED,IAAI,UAAU,WAEb;IAED,IAAI,OAAO,YAEV;IAED,IAAI,EAAE,YAEL;IAED,IAAI,GAAG,WAEN;IAMD,IAAI,KAAK,IAAI,SAAS,CAErB;IAMD,IAAI,SAAS,IAAI,aAAa,CAE7B;IAKD,IAAI,UAAU,IAAI,UAAU,CAE3B;IAEK,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;IAIzB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAK5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI;IAqBzC,YAAY,IAAI,QAAQ,GAAG,IAAI;IAmBzB,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAc7D,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC;IAO1B,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC;IAQxB,QAAQ,IAAI,cAAc,CAAC,aAAa,CAAC;IAoDzC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,UAAU,CAAC;CAe5D"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { parseSSE } from '../utils/sse.js';
|
|
2
|
+
import { cleanHtml } from '../utils/html-cleaner.js';
|
|
3
|
+
import { webToNodeStream } from '../utils/streaming.js';
|
|
4
|
+
import { parseHeaders } from '../utils/header-parser.js';
|
|
5
|
+
export class HttpResponse {
|
|
6
|
+
timings;
|
|
7
|
+
connection;
|
|
8
|
+
raw;
|
|
9
|
+
constructor(undiciRawResponse, options = {}) {
|
|
10
|
+
this.timings = options.timings;
|
|
11
|
+
this.connection = options.connection;
|
|
12
|
+
if (undiciRawResponse instanceof Response) {
|
|
13
|
+
this.raw = undiciRawResponse;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.raw = new Response(undiciRawResponse.body, {
|
|
17
|
+
status: undiciRawResponse.statusCode,
|
|
18
|
+
statusText: String(undiciRawResponse.statusCode),
|
|
19
|
+
headers: undiciRawResponse.headers,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get status() {
|
|
24
|
+
return this.raw.status;
|
|
25
|
+
}
|
|
26
|
+
get statusText() {
|
|
27
|
+
return this.raw.statusText;
|
|
28
|
+
}
|
|
29
|
+
get headers() {
|
|
30
|
+
return this.raw.headers;
|
|
31
|
+
}
|
|
32
|
+
get ok() {
|
|
33
|
+
return this.raw.ok;
|
|
34
|
+
}
|
|
35
|
+
get url() {
|
|
36
|
+
return this.raw.url;
|
|
37
|
+
}
|
|
38
|
+
get cache() {
|
|
39
|
+
return parseHeaders(this.headers, this.status).cache;
|
|
40
|
+
}
|
|
41
|
+
get rateLimit() {
|
|
42
|
+
return parseHeaders(this.headers, this.status).rateLimit;
|
|
43
|
+
}
|
|
44
|
+
get headerInfo() {
|
|
45
|
+
return parseHeaders(this.headers, this.status);
|
|
46
|
+
}
|
|
47
|
+
async json() {
|
|
48
|
+
return (await this.raw.json());
|
|
49
|
+
}
|
|
50
|
+
async text() {
|
|
51
|
+
return this.raw.text();
|
|
52
|
+
}
|
|
53
|
+
async cleanText() {
|
|
54
|
+
const rawText = await this.text();
|
|
55
|
+
return cleanHtml(rawText);
|
|
56
|
+
}
|
|
57
|
+
async blob() {
|
|
58
|
+
return this.raw.blob();
|
|
59
|
+
}
|
|
60
|
+
read() {
|
|
61
|
+
return this.raw.body;
|
|
62
|
+
}
|
|
63
|
+
toNodeStream() {
|
|
64
|
+
if (!this.raw.body) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return webToNodeStream(this.raw.body);
|
|
68
|
+
}
|
|
69
|
+
async pipe(destination) {
|
|
70
|
+
const nodeStream = this.toNodeStream();
|
|
71
|
+
if (!nodeStream) {
|
|
72
|
+
throw new Error('Response has no body to pipe');
|
|
73
|
+
}
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
nodeStream.pipe(destination);
|
|
76
|
+
nodeStream.on('end', resolve);
|
|
77
|
+
nodeStream.on('error', reject);
|
|
78
|
+
destination.on('error', reject);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
clone() {
|
|
82
|
+
return new HttpResponse(this.raw.clone(), {
|
|
83
|
+
timings: this.timings,
|
|
84
|
+
connection: this.connection
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
sse() {
|
|
88
|
+
return parseSSE(this.raw);
|
|
89
|
+
}
|
|
90
|
+
async *download() {
|
|
91
|
+
if (!this.raw.body) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const contentLength = this.headers.get('content-length');
|
|
95
|
+
const total = contentLength ? parseInt(contentLength, 10) : undefined;
|
|
96
|
+
let loaded = 0;
|
|
97
|
+
const startTime = Date.now();
|
|
98
|
+
let lastUpdate = startTime;
|
|
99
|
+
const reader = this.raw.body.getReader();
|
|
100
|
+
try {
|
|
101
|
+
while (true) {
|
|
102
|
+
const { done, value } = await reader.read();
|
|
103
|
+
if (done) {
|
|
104
|
+
const elapsed = (Date.now() - startTime) / 1000;
|
|
105
|
+
const rate = elapsed > 0 ? loaded / elapsed : 0;
|
|
106
|
+
yield {
|
|
107
|
+
loaded,
|
|
108
|
+
total,
|
|
109
|
+
percent: total ? 100 : undefined,
|
|
110
|
+
rate,
|
|
111
|
+
};
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (value) {
|
|
115
|
+
loaded += value.byteLength;
|
|
116
|
+
const now = Date.now();
|
|
117
|
+
const elapsed = (now - startTime) / 1000;
|
|
118
|
+
const rate = elapsed > 0 ? loaded / elapsed : 0;
|
|
119
|
+
if (now - lastUpdate > 100) {
|
|
120
|
+
yield {
|
|
121
|
+
loaded,
|
|
122
|
+
total,
|
|
123
|
+
percent: total ? (loaded / total) * 100 : undefined,
|
|
124
|
+
rate,
|
|
125
|
+
estimated: total && rate > 0 ? ((total - loaded) / rate) * 1000 : undefined,
|
|
126
|
+
};
|
|
127
|
+
lastUpdate = now;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
reader.releaseLock();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async *[Symbol.asyncIterator]() {
|
|
137
|
+
if (!this.raw.body) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const reader = this.raw.body.getReader();
|
|
141
|
+
try {
|
|
142
|
+
while (true) {
|
|
143
|
+
const { done, value } = await reader.read();
|
|
144
|
+
if (done)
|
|
145
|
+
break;
|
|
146
|
+
if (value)
|
|
147
|
+
yield value;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
reader.releaseLock();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export * from './core/request-promise.js';
|
|
2
|
+
export * from './transport/undici.js';
|
|
3
|
+
export * from './transport/fetch.js';
|
|
4
|
+
export * from './types/index.js';
|
|
5
|
+
export * from './core/errors.js';
|
|
6
|
+
export * from './core/client.js';
|
|
7
|
+
export * from './core/request.js';
|
|
8
|
+
export * from './core/response.js';
|
|
9
|
+
export * from './plugins/retry.js';
|
|
10
|
+
export * from './plugins/cache.js';
|
|
11
|
+
export * from './plugins/dedup.js';
|
|
12
|
+
export * from './plugins/logger.js';
|
|
13
|
+
export * from './plugins/circuit-breaker.js';
|
|
14
|
+
export * from './plugins/cookie-jar.js';
|
|
15
|
+
export * from './runner/request-runner.js';
|
|
16
|
+
export * from './contract/index.js';
|
|
17
|
+
export * from './cache/memory-storage.js';
|
|
18
|
+
export * from './cache/file-storage.js';
|
|
19
|
+
export * from './utils/body.js';
|
|
20
|
+
export * from './plugins/xsrf.js';
|
|
21
|
+
export * from './plugins/compression.js';
|
|
22
|
+
export * from './utils/streaming.js';
|
|
23
|
+
export * from './utils/request-pool.js';
|
|
24
|
+
export * from './utils/header-parser.js';
|
|
25
|
+
export * from './websocket/client.js';
|
|
26
|
+
export * from './utils/whois.js';
|
|
27
|
+
export * from './utils/dns.js';
|
|
28
|
+
export * from './utils/cert.js';
|
|
29
|
+
export * from './utils/doh.js';
|
|
30
|
+
export * from './utils/upload.js';
|
|
31
|
+
export * from './utils/user-agent.js';
|
|
32
|
+
export * from './plugins/har-recorder.js';
|
|
33
|
+
export * from './plugins/har-player.js';
|
|
34
|
+
export * from './plugins/graphql.js';
|
|
35
|
+
export * from './plugins/server-timing.js';
|
|
36
|
+
export * from './plugins/proxy-rotator.js';
|
|
37
|
+
export * from './cache/redis-storage.js';
|
|
38
|
+
export * from './mcp/index.js';
|
|
39
|
+
export { Client as Recker } from './core/client.js';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAG/B,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * from './core/request-promise.js';
|
|
2
|
+
export * from './transport/undici.js';
|
|
3
|
+
export * from './transport/fetch.js';
|
|
4
|
+
export * from './types/index.js';
|
|
5
|
+
export * from './core/errors.js';
|
|
6
|
+
export * from './core/client.js';
|
|
7
|
+
export * from './core/request.js';
|
|
8
|
+
export * from './core/response.js';
|
|
9
|
+
export * from './plugins/retry.js';
|
|
10
|
+
export * from './plugins/cache.js';
|
|
11
|
+
export * from './plugins/dedup.js';
|
|
12
|
+
export * from './plugins/logger.js';
|
|
13
|
+
export * from './plugins/circuit-breaker.js';
|
|
14
|
+
export * from './plugins/cookie-jar.js';
|
|
15
|
+
export * from './runner/request-runner.js';
|
|
16
|
+
export * from './contract/index.js';
|
|
17
|
+
export * from './cache/memory-storage.js';
|
|
18
|
+
export * from './cache/file-storage.js';
|
|
19
|
+
export * from './utils/body.js';
|
|
20
|
+
export * from './plugins/xsrf.js';
|
|
21
|
+
export * from './plugins/compression.js';
|
|
22
|
+
export * from './utils/streaming.js';
|
|
23
|
+
export * from './utils/request-pool.js';
|
|
24
|
+
export * from './utils/header-parser.js';
|
|
25
|
+
export * from './websocket/client.js';
|
|
26
|
+
export * from './utils/whois.js';
|
|
27
|
+
export * from './utils/dns.js';
|
|
28
|
+
export * from './utils/cert.js';
|
|
29
|
+
export * from './utils/doh.js';
|
|
30
|
+
export * from './utils/upload.js';
|
|
31
|
+
export * from './utils/user-agent.js';
|
|
32
|
+
export * from './plugins/har-recorder.js';
|
|
33
|
+
export * from './plugins/har-player.js';
|
|
34
|
+
export * from './plugins/graphql.js';
|
|
35
|
+
export * from './plugins/server-timing.js';
|
|
36
|
+
export * from './plugins/proxy-rotator.js';
|
|
37
|
+
export * from './cache/redis-storage.js';
|
|
38
|
+
export * from './mcp/index.js';
|
|
39
|
+
export { Client as Recker } from './core/client.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import type { MCPServerInfo, MCPTool, MCPToolResult, MCPResource, MCPResourceContent, MCPPrompt, MCPPromptMessage } from './types.js';
|
|
3
|
+
export interface MCPClientOptions {
|
|
4
|
+
endpoint: string;
|
|
5
|
+
clientName?: string;
|
|
6
|
+
clientVersion?: string;
|
|
7
|
+
protocolVersion?: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
retries?: number;
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
transport?: any;
|
|
13
|
+
}
|
|
14
|
+
interface ResolvedMCPClientOptions {
|
|
15
|
+
endpoint: string;
|
|
16
|
+
clientName: string;
|
|
17
|
+
clientVersion: string;
|
|
18
|
+
protocolVersion: string;
|
|
19
|
+
headers: Record<string, string>;
|
|
20
|
+
timeout: number;
|
|
21
|
+
retries: number;
|
|
22
|
+
debug: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare class MCPClient extends EventEmitter {
|
|
25
|
+
private client;
|
|
26
|
+
private endpoint;
|
|
27
|
+
private requestId;
|
|
28
|
+
private serverInfo?;
|
|
29
|
+
private initialized;
|
|
30
|
+
private sseConnection?;
|
|
31
|
+
readonly options: ResolvedMCPClientOptions;
|
|
32
|
+
constructor(options: MCPClientOptions);
|
|
33
|
+
connect(): Promise<MCPServerInfo>;
|
|
34
|
+
disconnect(): Promise<void>;
|
|
35
|
+
readonly tools: {
|
|
36
|
+
list: () => Promise<MCPTool[]>;
|
|
37
|
+
call: (name: string, args?: Record<string, unknown>) => Promise<MCPToolResult>;
|
|
38
|
+
get: (name: string) => Promise<MCPTool | undefined>;
|
|
39
|
+
};
|
|
40
|
+
readonly resources: {
|
|
41
|
+
list: () => Promise<MCPResource[]>;
|
|
42
|
+
read: (uri: string) => Promise<MCPResourceContent[]>;
|
|
43
|
+
subscribe: (uri: string) => Promise<void>;
|
|
44
|
+
unsubscribe: (uri: string) => Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
readonly prompts: {
|
|
47
|
+
list: () => Promise<MCPPrompt[]>;
|
|
48
|
+
get: (name: string, args?: Record<string, unknown>) => Promise<MCPPromptMessage[]>;
|
|
49
|
+
};
|
|
50
|
+
ping(): Promise<void>;
|
|
51
|
+
getServerInfo(): MCPServerInfo | undefined;
|
|
52
|
+
isConnected(): boolean;
|
|
53
|
+
private request;
|
|
54
|
+
private connectSSE;
|
|
55
|
+
private handleSSEEvent;
|
|
56
|
+
}
|
|
57
|
+
export declare function createMCPClient(options: MCPClientOptions): MCPClient;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EAGV,aAAa,EACb,OAAO,EAEP,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAYjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,GAAG,CAAC;CACjB;AAED,UAAU,wBAAwB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB;AA2BD,qBAAa,SAAU,SAAQ,YAAY;IACzC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAC,CAAgB;IACnC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAC,CAAkB;IAExC,SAAgB,OAAO,EAAE,wBAAwB,CAAC;gBAEtC,OAAO,EAAE,gBAAgB;IAwC/B,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IA2BjC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAYjC,SAAgB,KAAK;oBAIH,OAAO,CAAC,OAAO,EAAE,CAAC;qBAQf,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,OAAO,CAAC,aAAa,CAAC;oBAWhE,MAAM,KAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;MAIvD;IAKF,SAAgB,SAAS;oBAIP,OAAO,CAAC,WAAW,EAAE,CAAC;oBAQpB,MAAM,KAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;yBAUjC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;2BAOpB,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;MAG/C;IAKF,SAAgB,OAAO;oBAIL,OAAO,CAAC,SAAS,EAAE,CAAC;oBAQlB,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;MAOtF;IAKI,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,aAAa,IAAI,aAAa,GAAG,SAAS;IAO1C,WAAW,IAAI,OAAO;YAMR,OAAO;YA8BP,UAAU;IAmBxB,OAAO,CAAC,cAAc;CAiCvB;AAYD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAEpE"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { createClient } from '../core/client.js';
|
|
3
|
+
export class MCPClient extends EventEmitter {
|
|
4
|
+
client;
|
|
5
|
+
endpoint;
|
|
6
|
+
requestId = 0;
|
|
7
|
+
serverInfo;
|
|
8
|
+
initialized = false;
|
|
9
|
+
sseConnection;
|
|
10
|
+
options;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super();
|
|
13
|
+
this.options = {
|
|
14
|
+
endpoint: options.endpoint,
|
|
15
|
+
clientName: options.clientName || 'recker-mcp-client',
|
|
16
|
+
clientVersion: options.clientVersion || '1.0.0',
|
|
17
|
+
protocolVersion: options.protocolVersion || '2024-11-05',
|
|
18
|
+
headers: options.headers || {},
|
|
19
|
+
timeout: options.timeout || 30000,
|
|
20
|
+
retries: options.retries || 3,
|
|
21
|
+
debug: options.debug || false,
|
|
22
|
+
};
|
|
23
|
+
this.endpoint = this.options.endpoint;
|
|
24
|
+
this.client = createClient({
|
|
25
|
+
baseUrl: this.endpoint,
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
...this.options.headers,
|
|
29
|
+
},
|
|
30
|
+
retry: {
|
|
31
|
+
maxAttempts: this.options.retries,
|
|
32
|
+
backoff: 'exponential',
|
|
33
|
+
},
|
|
34
|
+
transport: options.transport,
|
|
35
|
+
});
|
|
36
|
+
if (this.options.debug) {
|
|
37
|
+
this.on('request', (req) => console.log('[MCP Request]', req));
|
|
38
|
+
this.on('response', (res) => console.log('[MCP Response]', res));
|
|
39
|
+
this.on('notification', (notif) => console.log('[MCP Notification]', notif));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async connect() {
|
|
43
|
+
const response = await this.request('initialize', {
|
|
44
|
+
protocolVersion: this.options.protocolVersion,
|
|
45
|
+
capabilities: {
|
|
46
|
+
tools: {},
|
|
47
|
+
resources: { subscribe: true },
|
|
48
|
+
prompts: {},
|
|
49
|
+
},
|
|
50
|
+
clientInfo: {
|
|
51
|
+
name: this.options.clientName,
|
|
52
|
+
version: this.options.clientVersion,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
this.serverInfo = response.serverInfo;
|
|
56
|
+
this.initialized = true;
|
|
57
|
+
await this.connectSSE();
|
|
58
|
+
this.emit('connected', this.serverInfo);
|
|
59
|
+
return this.serverInfo;
|
|
60
|
+
}
|
|
61
|
+
async disconnect() {
|
|
62
|
+
if (this.sseConnection) {
|
|
63
|
+
this.sseConnection.abort();
|
|
64
|
+
this.sseConnection = undefined;
|
|
65
|
+
}
|
|
66
|
+
this.initialized = false;
|
|
67
|
+
this.emit('disconnected');
|
|
68
|
+
}
|
|
69
|
+
tools = {
|
|
70
|
+
list: async () => {
|
|
71
|
+
const response = await this.request('tools/list');
|
|
72
|
+
return response.tools;
|
|
73
|
+
},
|
|
74
|
+
call: async (name, args) => {
|
|
75
|
+
const response = await this.request('tools/call', {
|
|
76
|
+
name,
|
|
77
|
+
arguments: args,
|
|
78
|
+
});
|
|
79
|
+
return response;
|
|
80
|
+
},
|
|
81
|
+
get: async (name) => {
|
|
82
|
+
const tools = await this.tools.list();
|
|
83
|
+
return tools.find(t => t.name === name);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
resources = {
|
|
87
|
+
list: async () => {
|
|
88
|
+
const response = await this.request('resources/list');
|
|
89
|
+
return response.resources;
|
|
90
|
+
},
|
|
91
|
+
read: async (uri) => {
|
|
92
|
+
const response = await this.request('resources/read', {
|
|
93
|
+
uri,
|
|
94
|
+
});
|
|
95
|
+
return response.contents;
|
|
96
|
+
},
|
|
97
|
+
subscribe: async (uri) => {
|
|
98
|
+
await this.request('resources/subscribe', { uri });
|
|
99
|
+
},
|
|
100
|
+
unsubscribe: async (uri) => {
|
|
101
|
+
await this.request('resources/unsubscribe', { uri });
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
prompts = {
|
|
105
|
+
list: async () => {
|
|
106
|
+
const response = await this.request('prompts/list');
|
|
107
|
+
return response.prompts;
|
|
108
|
+
},
|
|
109
|
+
get: async (name, args) => {
|
|
110
|
+
const response = await this.request('prompts/get', {
|
|
111
|
+
name,
|
|
112
|
+
arguments: args,
|
|
113
|
+
});
|
|
114
|
+
return response.messages;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
async ping() {
|
|
118
|
+
await this.request('ping');
|
|
119
|
+
}
|
|
120
|
+
getServerInfo() {
|
|
121
|
+
return this.serverInfo;
|
|
122
|
+
}
|
|
123
|
+
isConnected() {
|
|
124
|
+
return this.initialized;
|
|
125
|
+
}
|
|
126
|
+
async request(method, params) {
|
|
127
|
+
if (!this.initialized && method !== 'initialize') {
|
|
128
|
+
throw new Error('MCP client not initialized. Call connect() first.');
|
|
129
|
+
}
|
|
130
|
+
const request = {
|
|
131
|
+
jsonrpc: '2.0',
|
|
132
|
+
id: ++this.requestId,
|
|
133
|
+
method,
|
|
134
|
+
params: params,
|
|
135
|
+
};
|
|
136
|
+
this.emit('request', request);
|
|
137
|
+
const response = await this.client
|
|
138
|
+
.post('/', { json: request })
|
|
139
|
+
.json();
|
|
140
|
+
this.emit('response', response);
|
|
141
|
+
if (response.error) {
|
|
142
|
+
const error = new Error(response.error.message);
|
|
143
|
+
error.code = response.error.code;
|
|
144
|
+
error.data = response.error.data;
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
return response.result;
|
|
148
|
+
}
|
|
149
|
+
async connectSSE() {
|
|
150
|
+
this.sseConnection = new AbortController();
|
|
151
|
+
try {
|
|
152
|
+
const response = await this.client.get('/sse', {
|
|
153
|
+
signal: this.sseConnection.signal,
|
|
154
|
+
});
|
|
155
|
+
for await (const event of response.sse()) {
|
|
156
|
+
this.handleSSEEvent(event);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (error.name !== 'AbortError') {
|
|
161
|
+
this.emit('error', error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
handleSSEEvent(event) {
|
|
166
|
+
try {
|
|
167
|
+
const data = JSON.parse(event.data);
|
|
168
|
+
switch (data.method) {
|
|
169
|
+
case 'notifications/progress':
|
|
170
|
+
this.emit('progress', data.params);
|
|
171
|
+
break;
|
|
172
|
+
case 'notifications/resources/updated':
|
|
173
|
+
this.emit('resource:updated', data.params);
|
|
174
|
+
break;
|
|
175
|
+
case 'notifications/resources/list_changed':
|
|
176
|
+
this.emit('resources:changed');
|
|
177
|
+
break;
|
|
178
|
+
case 'notifications/tools/list_changed':
|
|
179
|
+
this.emit('tools:changed');
|
|
180
|
+
break;
|
|
181
|
+
case 'notifications/prompts/list_changed':
|
|
182
|
+
this.emit('prompts:changed');
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
this.emit('notification', data);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
this.emit('error', error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
export function createMCPClient(options) {
|
|
194
|
+
return new MCPClient(options);
|
|
195
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAKA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|