recker 1.0.2-0 → 1.0.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/LICENSE +0 -2
- package/README.md +121 -72
- package/dist/cache/memory-storage.d.ts.map +1 -1
- package/dist/cache/memory-storage.js +7 -1
- package/dist/constants/http-status.d.ts +74 -0
- package/dist/constants/http-status.d.ts.map +1 -0
- package/dist/constants/http-status.js +156 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -6
- package/dist/cookies/memory-cookie-jar.d.ts +31 -0
- package/dist/cookies/memory-cookie-jar.d.ts.map +1 -0
- package/dist/cookies/memory-cookie-jar.js +210 -0
- package/dist/core/client.d.ts +9 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +252 -53
- package/dist/core/errors.d.ts +18 -2
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +66 -5
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/core/request-promise.d.ts.map +1 -1
- package/dist/core/request-promise.js +8 -2
- package/dist/core/request.d.ts +7 -1
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/request.js +32 -0
- package/dist/core/response.d.ts +2 -0
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +44 -19
- package/dist/events/request-events.d.ts +48 -0
- package/dist/events/request-events.d.ts.map +1 -0
- package/dist/events/request-events.js +85 -0
- package/dist/index.d.ts +28 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -2
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +16 -5
- package/dist/mcp/contract.d.ts +77 -0
- package/dist/mcp/contract.d.ts.map +1 -0
- package/dist/mcp/contract.js +278 -0
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/plugins/auth.d.ts +45 -0
- package/dist/plugins/auth.d.ts.map +1 -0
- package/dist/plugins/auth.js +268 -0
- package/dist/plugins/cache.d.ts +7 -1
- package/dist/plugins/cache.d.ts.map +1 -1
- package/dist/plugins/cache.js +470 -49
- package/dist/plugins/circuit-breaker.js +1 -1
- package/dist/plugins/compression.d.ts.map +1 -1
- package/dist/plugins/compression.js +3 -3
- package/dist/plugins/dedup.d.ts.map +1 -1
- package/dist/plugins/dedup.js +2 -1
- package/dist/plugins/graphql.d.ts +4 -3
- package/dist/plugins/graphql.d.ts.map +1 -1
- package/dist/plugins/graphql.js +24 -5
- package/dist/plugins/grpc-web.d.ts +80 -0
- package/dist/plugins/grpc-web.d.ts.map +1 -0
- package/dist/plugins/grpc-web.js +261 -0
- package/dist/plugins/har-player.d.ts.map +1 -1
- package/dist/plugins/har-player.js +11 -2
- package/dist/plugins/hls.d.ts +33 -0
- package/dist/plugins/hls.d.ts.map +1 -0
- package/dist/plugins/hls.js +225 -0
- package/dist/plugins/http2-push.d.ts +64 -0
- package/dist/plugins/http2-push.d.ts.map +1 -0
- package/dist/plugins/http2-push.js +274 -0
- package/dist/plugins/http3.d.ts +76 -0
- package/dist/plugins/http3.d.ts.map +1 -0
- package/dist/plugins/http3.js +231 -0
- package/dist/plugins/interface-rotator.d.ts +10 -0
- package/dist/plugins/interface-rotator.d.ts.map +1 -0
- package/dist/plugins/interface-rotator.js +57 -0
- package/dist/plugins/jsonrpc.d.ts +76 -0
- package/dist/plugins/jsonrpc.d.ts.map +1 -0
- package/dist/plugins/jsonrpc.js +143 -0
- package/dist/plugins/logger.d.ts +8 -5
- package/dist/plugins/logger.d.ts.map +1 -1
- package/dist/plugins/logger.js +66 -30
- package/dist/plugins/odata.d.ts +182 -0
- package/dist/plugins/odata.d.ts.map +1 -0
- package/dist/plugins/odata.js +561 -0
- package/dist/plugins/retry.d.ts +1 -0
- package/dist/plugins/retry.d.ts.map +1 -1
- package/dist/plugins/retry.js +26 -2
- package/dist/plugins/scrape.d.ts +22 -0
- package/dist/plugins/scrape.d.ts.map +1 -0
- package/dist/plugins/scrape.js +87 -0
- package/dist/plugins/soap.d.ts +73 -0
- package/dist/plugins/soap.d.ts.map +1 -0
- package/dist/plugins/soap.js +347 -0
- package/dist/plugins/user-agent.d.ts +8 -0
- package/dist/plugins/user-agent.d.ts.map +1 -0
- package/dist/plugins/user-agent.js +46 -0
- package/dist/plugins/xml.d.ts +10 -0
- package/dist/plugins/xml.d.ts.map +1 -0
- package/dist/plugins/xml.js +194 -0
- package/dist/presets/anthropic.d.ts +7 -0
- package/dist/presets/anthropic.d.ts.map +1 -0
- package/dist/presets/anthropic.js +17 -0
- package/dist/presets/azure-openai.d.ts +9 -0
- package/dist/presets/azure-openai.d.ts.map +1 -0
- package/dist/presets/azure-openai.js +25 -0
- package/dist/presets/cloudflare.d.ts +13 -0
- package/dist/presets/cloudflare.d.ts.map +1 -0
- package/dist/presets/cloudflare.js +39 -0
- package/dist/presets/cohere.d.ts +6 -0
- package/dist/presets/cohere.d.ts.map +1 -0
- package/dist/presets/cohere.js +16 -0
- package/dist/presets/deepseek.d.ts +6 -0
- package/dist/presets/deepseek.d.ts.map +1 -0
- package/dist/presets/deepseek.js +16 -0
- package/dist/presets/digitalocean.d.ts +6 -0
- package/dist/presets/digitalocean.d.ts.map +1 -0
- package/dist/presets/digitalocean.js +16 -0
- package/dist/presets/discord.d.ts +7 -0
- package/dist/presets/discord.d.ts.map +1 -0
- package/dist/presets/discord.js +17 -0
- package/dist/presets/fireworks.d.ts +6 -0
- package/dist/presets/fireworks.d.ts.map +1 -0
- package/dist/presets/fireworks.js +16 -0
- package/dist/presets/gemini.d.ts +6 -0
- package/dist/presets/gemini.d.ts.map +1 -0
- package/dist/presets/gemini.js +16 -0
- package/dist/presets/github.d.ts +7 -0
- package/dist/presets/github.d.ts.map +1 -0
- package/dist/presets/github.js +17 -0
- package/dist/presets/gitlab.d.ts +7 -0
- package/dist/presets/gitlab.d.ts.map +1 -0
- package/dist/presets/gitlab.js +16 -0
- package/dist/presets/groq.d.ts +6 -0
- package/dist/presets/groq.d.ts.map +1 -0
- package/dist/presets/groq.js +16 -0
- package/dist/presets/huggingface.d.ts +6 -0
- package/dist/presets/huggingface.d.ts.map +1 -0
- package/dist/presets/huggingface.js +16 -0
- package/dist/presets/index.d.ts +28 -0
- package/dist/presets/index.d.ts.map +1 -0
- package/dist/presets/index.js +27 -0
- package/dist/presets/linear.d.ts +6 -0
- package/dist/presets/linear.d.ts.map +1 -0
- package/dist/presets/linear.js +16 -0
- package/dist/presets/mistral.d.ts +6 -0
- package/dist/presets/mistral.d.ts.map +1 -0
- package/dist/presets/mistral.js +16 -0
- package/dist/presets/notion.d.ts +7 -0
- package/dist/presets/notion.d.ts.map +1 -0
- package/dist/presets/notion.js +17 -0
- package/dist/presets/openai.d.ts +8 -0
- package/dist/presets/openai.d.ts.map +1 -0
- package/dist/presets/openai.js +23 -0
- package/dist/presets/perplexity.d.ts +6 -0
- package/dist/presets/perplexity.d.ts.map +1 -0
- package/dist/presets/perplexity.js +16 -0
- package/dist/presets/registry.d.ts +20 -0
- package/dist/presets/registry.d.ts.map +1 -0
- package/dist/presets/registry.js +311 -0
- package/dist/presets/replicate.d.ts +6 -0
- package/dist/presets/replicate.d.ts.map +1 -0
- package/dist/presets/replicate.js +16 -0
- package/dist/presets/slack.d.ts +6 -0
- package/dist/presets/slack.d.ts.map +1 -0
- package/dist/presets/slack.js +16 -0
- package/dist/presets/stripe.d.ts +8 -0
- package/dist/presets/stripe.d.ts.map +1 -0
- package/dist/presets/stripe.js +23 -0
- package/dist/presets/supabase.d.ts +7 -0
- package/dist/presets/supabase.d.ts.map +1 -0
- package/dist/presets/supabase.js +18 -0
- package/dist/presets/together.d.ts +6 -0
- package/dist/presets/together.d.ts.map +1 -0
- package/dist/presets/together.js +16 -0
- package/dist/presets/twilio.d.ts +7 -0
- package/dist/presets/twilio.d.ts.map +1 -0
- package/dist/presets/twilio.js +17 -0
- package/dist/presets/vercel.d.ts +7 -0
- package/dist/presets/vercel.d.ts.map +1 -0
- package/dist/presets/vercel.js +23 -0
- package/dist/presets/xai.d.ts +7 -0
- package/dist/presets/xai.d.ts.map +1 -0
- package/dist/presets/xai.js +17 -0
- package/dist/protocols/ftp.d.ts +63 -0
- package/dist/protocols/ftp.d.ts.map +1 -0
- package/dist/protocols/ftp.js +388 -0
- package/dist/protocols/index.d.ts +4 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/sftp.d.ts +65 -0
- package/dist/protocols/sftp.d.ts.map +1 -0
- package/dist/protocols/sftp.js +346 -0
- package/dist/protocols/telnet.d.ts +50 -0
- package/dist/protocols/telnet.d.ts.map +1 -0
- package/dist/protocols/telnet.js +139 -0
- package/dist/runner/request-runner.d.ts.map +1 -1
- package/dist/runner/request-runner.js +1 -0
- package/dist/scrape/document.d.ts +44 -0
- package/dist/scrape/document.d.ts.map +1 -0
- package/dist/scrape/document.js +198 -0
- package/dist/scrape/element.d.ts +50 -0
- package/dist/scrape/element.d.ts.map +1 -0
- package/dist/scrape/element.js +176 -0
- package/dist/scrape/extractors.d.ts +17 -0
- package/dist/scrape/extractors.d.ts.map +1 -0
- package/dist/scrape/extractors.js +356 -0
- package/dist/scrape/index.d.ts +5 -0
- package/dist/scrape/index.d.ts.map +1 -0
- package/dist/scrape/index.js +3 -0
- package/dist/scrape/types.d.ts +108 -0
- package/dist/scrape/types.d.ts.map +1 -0
- package/dist/scrape/types.js +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/mock.d.ts +58 -0
- package/dist/testing/mock.d.ts.map +1 -0
- package/dist/testing/mock.js +252 -0
- package/dist/transport/fetch.d.ts.map +1 -1
- package/dist/transport/fetch.js +12 -4
- package/dist/transport/undici.d.ts +17 -1
- package/dist/transport/undici.d.ts.map +1 -1
- package/dist/transport/undici.js +708 -47
- package/dist/types/index.d.ts +111 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/logger.d.ts +17 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logger.js +66 -0
- package/dist/utils/agent-manager.d.ts.map +1 -1
- package/dist/utils/agent-manager.js +20 -4
- package/dist/utils/body.d.ts.map +1 -1
- package/dist/utils/body.js +14 -2
- package/dist/utils/charset.d.ts +16 -0
- package/dist/utils/charset.d.ts.map +1 -0
- package/dist/utils/charset.js +169 -0
- package/dist/utils/client-pool.d.ts +21 -0
- package/dist/utils/client-pool.d.ts.map +1 -0
- package/dist/utils/client-pool.js +49 -0
- package/dist/utils/concurrency.d.ts.map +1 -1
- package/dist/utils/concurrency.js +8 -4
- package/dist/utils/dns-toolkit.d.ts +13 -0
- package/dist/utils/dns-toolkit.d.ts.map +1 -0
- package/dist/utils/dns-toolkit.js +48 -0
- package/dist/utils/doh.d.ts.map +1 -1
- package/dist/utils/doh.js +16 -3
- package/dist/utils/download.d.ts +15 -0
- package/dist/utils/download.d.ts.map +1 -0
- package/dist/utils/download.js +44 -0
- package/dist/utils/env-proxy.d.ts +13 -0
- package/dist/utils/env-proxy.d.ts.map +1 -0
- package/dist/utils/env-proxy.js +105 -0
- package/dist/utils/header-parser.d.ts +15 -1
- package/dist/utils/header-parser.d.ts.map +1 -1
- package/dist/utils/header-parser.js +161 -1
- package/dist/utils/link-header.d.ts +70 -0
- package/dist/utils/link-header.d.ts.map +1 -0
- package/dist/utils/link-header.js +190 -0
- package/dist/utils/progress.d.ts +7 -2
- package/dist/utils/progress.d.ts.map +1 -1
- package/dist/utils/progress.js +48 -15
- package/dist/utils/rdap.d.ts +17 -0
- package/dist/utils/rdap.d.ts.map +1 -0
- package/dist/utils/rdap.js +32 -0
- package/dist/utils/request-pool.d.ts.map +1 -1
- package/dist/utils/request-pool.js +4 -3
- package/dist/utils/sse.d.ts.map +1 -1
- package/dist/utils/sse.js +8 -2
- package/dist/utils/status-codes.d.ts +84 -0
- package/dist/utils/status-codes.d.ts.map +1 -0
- package/dist/utils/status-codes.js +204 -0
- package/dist/utils/streaming.d.ts.map +1 -1
- package/dist/utils/streaming.js +1 -0
- package/dist/utils/tls-inspector.d.ts +21 -0
- package/dist/utils/tls-inspector.d.ts.map +1 -0
- package/dist/utils/tls-inspector.js +39 -0
- package/dist/utils/try-fn.d.ts.map +1 -1
- package/dist/utils/try-fn.js +11 -5
- package/dist/utils/upload.d.ts +1 -0
- package/dist/utils/upload.d.ts.map +1 -1
- package/dist/utils/upload.js +20 -3
- package/dist/utils/user-agent.d.ts +9 -9
- package/dist/utils/user-agent.js +9 -9
- package/dist/utils/whois.d.ts.map +1 -1
- package/dist/utils/whois.js +11 -2
- package/dist/websocket/client.d.ts +29 -1
- package/dist/websocket/client.d.ts.map +1 -1
- package/dist/websocket/client.js +145 -13
- package/package.json +45 -8
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { MockAgent, setGlobalDispatcher, getGlobalDispatcher } from 'undici';
|
|
2
|
+
export class MockClient {
|
|
3
|
+
responses = new Map();
|
|
4
|
+
callHistory = [];
|
|
5
|
+
pendingIntercept;
|
|
6
|
+
get(path, options) {
|
|
7
|
+
this.pendingIntercept = { ...options, path, method: 'GET' };
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
post(path, options) {
|
|
11
|
+
this.pendingIntercept = { ...options, path, method: 'POST' };
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
put(path, options) {
|
|
15
|
+
this.pendingIntercept = { ...options, path, method: 'PUT' };
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
patch(path, options) {
|
|
19
|
+
this.pendingIntercept = { ...options, path, method: 'PATCH' };
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
delete(path, options) {
|
|
23
|
+
this.pendingIntercept = { ...options, path, method: 'DELETE' };
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
intercept(options) {
|
|
27
|
+
this.pendingIntercept = options;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
reply(status, body, headers) {
|
|
31
|
+
if (!this.pendingIntercept) {
|
|
32
|
+
throw new Error('No intercept defined. Call get(), post(), etc. first.');
|
|
33
|
+
}
|
|
34
|
+
const key = this.makeKey(this.pendingIntercept);
|
|
35
|
+
const responses = this.responses.get(key) || [];
|
|
36
|
+
responses.push({ status, body, headers });
|
|
37
|
+
this.responses.set(key, responses);
|
|
38
|
+
this.pendingIntercept = undefined;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
replyOnce(status, body, headers) {
|
|
42
|
+
if (!this.pendingIntercept) {
|
|
43
|
+
throw new Error('No intercept defined. Call get(), post(), etc. first.');
|
|
44
|
+
}
|
|
45
|
+
const key = this.makeKey(this.pendingIntercept);
|
|
46
|
+
const responses = this.responses.get(key) || [];
|
|
47
|
+
responses.push({ status, body, headers, times: 1 });
|
|
48
|
+
this.responses.set(key, responses);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
replyWithDelay(delay, status, body, headers) {
|
|
52
|
+
if (!this.pendingIntercept) {
|
|
53
|
+
throw new Error('No intercept defined. Call get(), post(), etc. first.');
|
|
54
|
+
}
|
|
55
|
+
const key = this.makeKey(this.pendingIntercept);
|
|
56
|
+
const responses = this.responses.get(key) || [];
|
|
57
|
+
responses.push({ status, body, headers, delay });
|
|
58
|
+
this.responses.set(key, responses);
|
|
59
|
+
this.pendingIntercept = undefined;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
replyWithError(error) {
|
|
63
|
+
if (!this.pendingIntercept) {
|
|
64
|
+
throw new Error('No intercept defined. Call get(), post(), etc. first.');
|
|
65
|
+
}
|
|
66
|
+
const key = this.makeKey(this.pendingIntercept);
|
|
67
|
+
const responses = this.responses.get(key) || [];
|
|
68
|
+
responses.push({
|
|
69
|
+
status: -1,
|
|
70
|
+
body: error instanceof Error ? error : new Error(error)
|
|
71
|
+
});
|
|
72
|
+
this.responses.set(key, responses);
|
|
73
|
+
this.pendingIntercept = undefined;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
history() {
|
|
77
|
+
return [...this.callHistory];
|
|
78
|
+
}
|
|
79
|
+
called(method, pathPattern) {
|
|
80
|
+
return this.callHistory.some(call => {
|
|
81
|
+
if (call.method !== method)
|
|
82
|
+
return false;
|
|
83
|
+
if (!pathPattern)
|
|
84
|
+
return true;
|
|
85
|
+
if (typeof pathPattern === 'string') {
|
|
86
|
+
return call.url.includes(pathPattern);
|
|
87
|
+
}
|
|
88
|
+
return pathPattern.test(call.url);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
callCount(method, pathPattern) {
|
|
92
|
+
return this.callHistory.filter(call => {
|
|
93
|
+
if (method && call.method !== method)
|
|
94
|
+
return false;
|
|
95
|
+
if (!pathPattern)
|
|
96
|
+
return true;
|
|
97
|
+
if (typeof pathPattern === 'string') {
|
|
98
|
+
return call.url.includes(pathPattern);
|
|
99
|
+
}
|
|
100
|
+
return pathPattern.test(call.url);
|
|
101
|
+
}).length;
|
|
102
|
+
}
|
|
103
|
+
reset() {
|
|
104
|
+
this.responses.clear();
|
|
105
|
+
this.callHistory = [];
|
|
106
|
+
this.pendingIntercept = undefined;
|
|
107
|
+
}
|
|
108
|
+
resetHistory() {
|
|
109
|
+
this.callHistory = [];
|
|
110
|
+
}
|
|
111
|
+
makeKey(intercept) {
|
|
112
|
+
const method = intercept.method || 'GET';
|
|
113
|
+
const path = intercept.path instanceof RegExp ? intercept.path.source : intercept.path;
|
|
114
|
+
return `${method}:${path}`;
|
|
115
|
+
}
|
|
116
|
+
_findResponse(method, url, body, headers) {
|
|
117
|
+
this.callHistory.push({ method, url, body, headers: headers || new Headers() });
|
|
118
|
+
const urlObj = new URL(url);
|
|
119
|
+
const path = urlObj.pathname + urlObj.search;
|
|
120
|
+
const exactKey = `${method}:${path}`;
|
|
121
|
+
let responses = this.responses.get(exactKey);
|
|
122
|
+
if (!responses || responses.length === 0) {
|
|
123
|
+
const pathOnlyKey = `${method}:${urlObj.pathname}`;
|
|
124
|
+
responses = this.responses.get(pathOnlyKey);
|
|
125
|
+
}
|
|
126
|
+
if (!responses || responses.length === 0) {
|
|
127
|
+
for (const [key, resps] of this.responses.entries()) {
|
|
128
|
+
const [m, pattern] = key.split(':');
|
|
129
|
+
if (m !== method)
|
|
130
|
+
continue;
|
|
131
|
+
try {
|
|
132
|
+
const regex = new RegExp(pattern);
|
|
133
|
+
if (regex.test(path) || regex.test(urlObj.pathname)) {
|
|
134
|
+
responses = resps;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!responses || responses.length === 0) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const callCount = this.callHistory.filter(c => c.method === method && c.url === url).length;
|
|
146
|
+
let cumulativeTimes = 0;
|
|
147
|
+
for (const response of responses) {
|
|
148
|
+
if (response.times === undefined) {
|
|
149
|
+
return response;
|
|
150
|
+
}
|
|
151
|
+
cumulativeTimes += response.times;
|
|
152
|
+
if (callCount <= cumulativeTimes) {
|
|
153
|
+
return response;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const lastResponse = responses[responses.length - 1];
|
|
157
|
+
if (lastResponse.times === undefined) {
|
|
158
|
+
return lastResponse;
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export class MockTransport {
|
|
164
|
+
mock;
|
|
165
|
+
constructor(mock) {
|
|
166
|
+
this.mock = mock || new MockClient();
|
|
167
|
+
}
|
|
168
|
+
getMock() {
|
|
169
|
+
return this.mock;
|
|
170
|
+
}
|
|
171
|
+
async dispatch(req) {
|
|
172
|
+
let bodyString;
|
|
173
|
+
if (req.body) {
|
|
174
|
+
if (typeof req.body === 'string') {
|
|
175
|
+
bodyString = req.body;
|
|
176
|
+
}
|
|
177
|
+
else if (req.body instanceof Blob) {
|
|
178
|
+
bodyString = await req.body.text();
|
|
179
|
+
}
|
|
180
|
+
else if (req.body instanceof ArrayBuffer) {
|
|
181
|
+
bodyString = new TextDecoder().decode(req.body);
|
|
182
|
+
}
|
|
183
|
+
else if (req.body instanceof FormData) {
|
|
184
|
+
bodyString = '[FormData]';
|
|
185
|
+
}
|
|
186
|
+
else if (req.body instanceof URLSearchParams) {
|
|
187
|
+
bodyString = req.body.toString();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const response = this.mock._findResponse(req.method, req.url, bodyString, req.headers);
|
|
191
|
+
if (!response) {
|
|
192
|
+
throw new Error(`No mock response for ${req.method} ${req.url}`);
|
|
193
|
+
}
|
|
194
|
+
if (response.status === -1) {
|
|
195
|
+
throw response.body;
|
|
196
|
+
}
|
|
197
|
+
if (response.delay) {
|
|
198
|
+
await new Promise((resolve, reject) => {
|
|
199
|
+
const timer = setTimeout(resolve, response.delay);
|
|
200
|
+
req.signal?.addEventListener('abort', () => {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
reject(new DOMException('Aborted', 'AbortError'));
|
|
203
|
+
}, { once: true });
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const status = response.status ?? 200;
|
|
207
|
+
const respHeaders = new Headers(response.headers || { 'content-type': 'application/json' });
|
|
208
|
+
const respBodyString = typeof response.body === 'string'
|
|
209
|
+
? response.body
|
|
210
|
+
: JSON.stringify(response.body ?? {});
|
|
211
|
+
const rawResponse = new Response(status === 204 || status === 304 ? null : respBodyString, { status, headers: respHeaders });
|
|
212
|
+
return {
|
|
213
|
+
status,
|
|
214
|
+
statusText: rawResponse.statusText,
|
|
215
|
+
headers: respHeaders,
|
|
216
|
+
ok: status >= 200 && status < 300,
|
|
217
|
+
url: req.url,
|
|
218
|
+
raw: rawResponse,
|
|
219
|
+
json: async () => response.body,
|
|
220
|
+
text: async () => respBodyString,
|
|
221
|
+
cleanText: async () => respBodyString,
|
|
222
|
+
blob: async () => new Blob([respBodyString]),
|
|
223
|
+
read: () => rawResponse.body,
|
|
224
|
+
clone: function () { return this; },
|
|
225
|
+
sse: async function* () { },
|
|
226
|
+
download: async function* () { },
|
|
227
|
+
[Symbol.asyncIterator]: async function* () { }
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export function createMockClient() {
|
|
232
|
+
const mock = new MockClient();
|
|
233
|
+
const transport = new MockTransport(mock);
|
|
234
|
+
return { mock, transport };
|
|
235
|
+
}
|
|
236
|
+
let originalDispatcher;
|
|
237
|
+
export function installGlobalMock(options) {
|
|
238
|
+
originalDispatcher = getGlobalDispatcher();
|
|
239
|
+
const mockAgent = new MockAgent();
|
|
240
|
+
if (options?.throwOnUnmocked !== false) {
|
|
241
|
+
mockAgent.disableNetConnect();
|
|
242
|
+
}
|
|
243
|
+
setGlobalDispatcher(mockAgent);
|
|
244
|
+
return mockAgent;
|
|
245
|
+
}
|
|
246
|
+
export function uninstallGlobalMock() {
|
|
247
|
+
if (originalDispatcher) {
|
|
248
|
+
setGlobalDispatcher(originalDispatcher);
|
|
249
|
+
originalDispatcher = undefined;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export { MockAgent } from 'undici';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/transport/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/transport/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAErG,qBAAa,cAAe,YAAW,SAAS;;IAGxC,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;CA+G5D"}
|
package/dist/transport/fetch.js
CHANGED
|
@@ -57,7 +57,7 @@ export class FetchTransport {
|
|
|
57
57
|
return;
|
|
58
58
|
const reader = response.body.getReader();
|
|
59
59
|
let loaded = 0;
|
|
60
|
-
const total = Number(response.headers.get('content-length')) ||
|
|
60
|
+
const total = Number(response.headers.get('content-length')) || undefined;
|
|
61
61
|
while (true) {
|
|
62
62
|
const { done, value } = await reader.read();
|
|
63
63
|
if (done)
|
|
@@ -65,8 +65,10 @@ export class FetchTransport {
|
|
|
65
65
|
loaded += value.length;
|
|
66
66
|
yield {
|
|
67
67
|
loaded,
|
|
68
|
+
transferred: loaded,
|
|
68
69
|
total,
|
|
69
|
-
percent: total ? (loaded / total) * 100 : undefined
|
|
70
|
+
percent: total ? (loaded / total) * 100 : undefined,
|
|
71
|
+
direction: 'download'
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
74
|
},
|
|
@@ -130,13 +132,19 @@ class FetchResponseWrapper {
|
|
|
130
132
|
return;
|
|
131
133
|
const reader = this.raw.body.getReader();
|
|
132
134
|
let loaded = 0;
|
|
133
|
-
const total = Number(this.raw.headers.get('content-length')) ||
|
|
135
|
+
const total = Number(this.raw.headers.get('content-length')) || undefined;
|
|
134
136
|
while (true) {
|
|
135
137
|
const { done, value } = await reader.read();
|
|
136
138
|
if (done)
|
|
137
139
|
break;
|
|
138
140
|
loaded += value.length;
|
|
139
|
-
yield {
|
|
141
|
+
yield {
|
|
142
|
+
loaded,
|
|
143
|
+
transferred: loaded,
|
|
144
|
+
total,
|
|
145
|
+
percent: total ? (loaded / total) * 100 : undefined,
|
|
146
|
+
direction: 'download'
|
|
147
|
+
};
|
|
140
148
|
}
|
|
141
149
|
}
|
|
142
150
|
async *[Symbol.asyncIterator]() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReckerRequest, ReckerResponse, Transport, ProxyOptions, HTTP2Options, DNSOptions } from '../types/index.js';
|
|
1
|
+
import { ReckerRequest, ReckerResponse, Transport, ProxyOptions, HTTP2Options, DNSOptions, TLSOptions } from '../types/index.js';
|
|
2
2
|
import { AgentManager } from '../utils/agent-manager.js';
|
|
3
3
|
interface UndiciTransportOptions {
|
|
4
4
|
connectTimeout?: number;
|
|
@@ -9,15 +9,31 @@ interface UndiciTransportOptions {
|
|
|
9
9
|
http2?: HTTP2Options;
|
|
10
10
|
dns?: DNSOptions;
|
|
11
11
|
agent?: AgentManager;
|
|
12
|
+
tls?: TLSOptions;
|
|
13
|
+
socketPath?: string;
|
|
14
|
+
connections?: number;
|
|
15
|
+
pipelining?: number;
|
|
16
|
+
keepAlive?: boolean;
|
|
17
|
+
keepAliveTimeout?: number;
|
|
18
|
+
keepAliveMaxTimeout?: number;
|
|
19
|
+
perDomainPooling?: boolean;
|
|
20
|
+
localAddress?: string;
|
|
21
|
+
observability?: boolean;
|
|
12
22
|
}
|
|
13
23
|
export declare class UndiciTransport implements Transport {
|
|
24
|
+
private static requestCounter;
|
|
14
25
|
private baseUrl;
|
|
15
26
|
private options;
|
|
16
27
|
private proxyAgent?;
|
|
17
28
|
private dnsAgent?;
|
|
18
29
|
private agentManager?;
|
|
30
|
+
private proxyBypassList?;
|
|
31
|
+
private tlsOptions?;
|
|
32
|
+
private socketClient?;
|
|
33
|
+
private observability;
|
|
19
34
|
constructor(baseUrl: string, options?: UndiciTransportOptions);
|
|
20
35
|
dispatch(req: ReckerRequest): Promise<ReckerResponse>;
|
|
36
|
+
private dispatchFast;
|
|
21
37
|
}
|
|
22
38
|
export {};
|
|
23
39
|
//# sourceMappingURL=undici.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../src/transport/undici.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAW,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAgB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../src/transport/undici.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAW,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAgB,UAAU,EAAkD,MAAM,mBAAmB,CAAC;AAOxN,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAwNzD,UAAU,sBAAsB;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC9B,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IAMtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAqDD,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,MAAM,CAAC,cAAc,CAAK;IAElC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,OAAO,CAAC,QAAQ,CAAC,CAAQ;IACzB,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,eAAe,CAAC,CAAW;IACnC,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,aAAa,CAAU;gBAEnB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;IAmG3D,QAAQ,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;YA4U7C,YAAY;CAkQ3B"}
|