recker 1.0.2-0 → 1.0.4
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,356 @@
|
|
|
1
|
+
function resolveUrl(url, baseUrl) {
|
|
2
|
+
if (!url)
|
|
3
|
+
return '';
|
|
4
|
+
if (!baseUrl)
|
|
5
|
+
return url;
|
|
6
|
+
try {
|
|
7
|
+
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) {
|
|
8
|
+
return url;
|
|
9
|
+
}
|
|
10
|
+
return new URL(url, baseUrl).href;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function classifyLinkType(href, baseUrl) {
|
|
17
|
+
if (!href)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (href.startsWith('mailto:'))
|
|
20
|
+
return 'mailto';
|
|
21
|
+
if (href.startsWith('tel:'))
|
|
22
|
+
return 'tel';
|
|
23
|
+
if (href.startsWith('#'))
|
|
24
|
+
return 'anchor';
|
|
25
|
+
if (baseUrl) {
|
|
26
|
+
try {
|
|
27
|
+
const base = new URL(baseUrl);
|
|
28
|
+
const link = new URL(href, baseUrl);
|
|
29
|
+
return link.hostname === base.hostname ? 'internal' : 'external';
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (href.startsWith('http://') || href.startsWith('https://') || href.startsWith('//')) {
|
|
36
|
+
return 'external';
|
|
37
|
+
}
|
|
38
|
+
return 'internal';
|
|
39
|
+
}
|
|
40
|
+
export function extractLinks($, options) {
|
|
41
|
+
const selector = options?.selector || 'a[href]';
|
|
42
|
+
const links = [];
|
|
43
|
+
$(selector).each((_, element) => {
|
|
44
|
+
const $el = $(element);
|
|
45
|
+
let href = $el.attr('href') || '';
|
|
46
|
+
if (options?.absolute && options?.baseUrl) {
|
|
47
|
+
href = resolveUrl(href, options.baseUrl);
|
|
48
|
+
}
|
|
49
|
+
links.push({
|
|
50
|
+
href,
|
|
51
|
+
text: $el.text().trim(),
|
|
52
|
+
rel: $el.attr('rel'),
|
|
53
|
+
target: $el.attr('target'),
|
|
54
|
+
title: $el.attr('title'),
|
|
55
|
+
type: classifyLinkType(href, options?.baseUrl),
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return links;
|
|
59
|
+
}
|
|
60
|
+
export function extractImages($, options) {
|
|
61
|
+
const selector = options?.selector || 'img[src]';
|
|
62
|
+
const images = [];
|
|
63
|
+
$(selector).each((_, element) => {
|
|
64
|
+
const $el = $(element);
|
|
65
|
+
let src = $el.attr('src') || '';
|
|
66
|
+
if (options?.absolute && options?.baseUrl) {
|
|
67
|
+
src = resolveUrl(src, options.baseUrl);
|
|
68
|
+
}
|
|
69
|
+
const width = $el.attr('width');
|
|
70
|
+
const height = $el.attr('height');
|
|
71
|
+
images.push({
|
|
72
|
+
src,
|
|
73
|
+
alt: $el.attr('alt'),
|
|
74
|
+
title: $el.attr('title'),
|
|
75
|
+
width: width ? parseInt(width, 10) : undefined,
|
|
76
|
+
height: height ? parseInt(height, 10) : undefined,
|
|
77
|
+
srcset: $el.attr('srcset'),
|
|
78
|
+
loading: $el.attr('loading'),
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return images;
|
|
82
|
+
}
|
|
83
|
+
export function extractMeta($) {
|
|
84
|
+
const meta = {};
|
|
85
|
+
meta.title = $('title').first().text().trim() || undefined;
|
|
86
|
+
const charsetMeta = $('meta[charset]').attr('charset');
|
|
87
|
+
if (charsetMeta) {
|
|
88
|
+
meta.charset = charsetMeta;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const contentType = $('meta[http-equiv="Content-Type"]').attr('content');
|
|
92
|
+
if (contentType) {
|
|
93
|
+
const charsetMatch = contentType.match(/charset=([^;]+)/i);
|
|
94
|
+
if (charsetMatch) {
|
|
95
|
+
meta.charset = charsetMatch[1].trim();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const canonical = $('link[rel="canonical"]').attr('href');
|
|
100
|
+
if (canonical) {
|
|
101
|
+
meta.canonical = canonical;
|
|
102
|
+
}
|
|
103
|
+
$('meta[name]').each((_, element) => {
|
|
104
|
+
const $el = $(element);
|
|
105
|
+
const name = $el.attr('name')?.toLowerCase();
|
|
106
|
+
const content = $el.attr('content');
|
|
107
|
+
if (!name || !content)
|
|
108
|
+
return;
|
|
109
|
+
switch (name) {
|
|
110
|
+
case 'description':
|
|
111
|
+
meta.description = content;
|
|
112
|
+
break;
|
|
113
|
+
case 'keywords':
|
|
114
|
+
meta.keywords = content.split(',').map((k) => k.trim()).filter(Boolean);
|
|
115
|
+
break;
|
|
116
|
+
case 'author':
|
|
117
|
+
meta.author = content;
|
|
118
|
+
break;
|
|
119
|
+
case 'robots':
|
|
120
|
+
meta.robots = content;
|
|
121
|
+
break;
|
|
122
|
+
case 'viewport':
|
|
123
|
+
meta.viewport = content;
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
meta[name] = content;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return meta;
|
|
130
|
+
}
|
|
131
|
+
export function extractOpenGraph($) {
|
|
132
|
+
const og = {};
|
|
133
|
+
const images = [];
|
|
134
|
+
$('meta[property^="og:"]').each((_, element) => {
|
|
135
|
+
const $el = $(element);
|
|
136
|
+
const property = $el.attr('property');
|
|
137
|
+
const content = $el.attr('content');
|
|
138
|
+
if (!property || !content)
|
|
139
|
+
return;
|
|
140
|
+
const key = property.replace('og:', '');
|
|
141
|
+
switch (key) {
|
|
142
|
+
case 'title':
|
|
143
|
+
og.title = content;
|
|
144
|
+
break;
|
|
145
|
+
case 'type':
|
|
146
|
+
og.type = content;
|
|
147
|
+
break;
|
|
148
|
+
case 'url':
|
|
149
|
+
og.url = content;
|
|
150
|
+
break;
|
|
151
|
+
case 'image':
|
|
152
|
+
images.push(content);
|
|
153
|
+
break;
|
|
154
|
+
case 'description':
|
|
155
|
+
og.description = content;
|
|
156
|
+
break;
|
|
157
|
+
case 'site_name':
|
|
158
|
+
og.siteName = content;
|
|
159
|
+
break;
|
|
160
|
+
case 'locale':
|
|
161
|
+
og.locale = content;
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
og[key.replace(/_([a-z])/g, (_, c) => c.toUpperCase())] = content;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
if (images.length === 1) {
|
|
168
|
+
og.image = images[0];
|
|
169
|
+
}
|
|
170
|
+
else if (images.length > 1) {
|
|
171
|
+
og.image = images;
|
|
172
|
+
}
|
|
173
|
+
return og;
|
|
174
|
+
}
|
|
175
|
+
export function extractTwitterCard($) {
|
|
176
|
+
const twitter = {};
|
|
177
|
+
$('meta[name^="twitter:"]').each((_, element) => {
|
|
178
|
+
const $el = $(element);
|
|
179
|
+
const name = $el.attr('name');
|
|
180
|
+
const content = $el.attr('content');
|
|
181
|
+
if (!name || !content)
|
|
182
|
+
return;
|
|
183
|
+
const key = name.replace('twitter:', '');
|
|
184
|
+
switch (key) {
|
|
185
|
+
case 'card':
|
|
186
|
+
twitter.card = content;
|
|
187
|
+
break;
|
|
188
|
+
case 'site':
|
|
189
|
+
twitter.site = content;
|
|
190
|
+
break;
|
|
191
|
+
case 'creator':
|
|
192
|
+
twitter.creator = content;
|
|
193
|
+
break;
|
|
194
|
+
case 'title':
|
|
195
|
+
twitter.title = content;
|
|
196
|
+
break;
|
|
197
|
+
case 'description':
|
|
198
|
+
twitter.description = content;
|
|
199
|
+
break;
|
|
200
|
+
case 'image':
|
|
201
|
+
twitter.image = content;
|
|
202
|
+
break;
|
|
203
|
+
default:
|
|
204
|
+
twitter[key] = content;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return twitter;
|
|
208
|
+
}
|
|
209
|
+
export function extractJsonLd($) {
|
|
210
|
+
const results = [];
|
|
211
|
+
$('script[type="application/ld+json"]').each((_, element) => {
|
|
212
|
+
const content = $(element).html();
|
|
213
|
+
if (!content)
|
|
214
|
+
return;
|
|
215
|
+
try {
|
|
216
|
+
const data = JSON.parse(content);
|
|
217
|
+
if (data['@graph'] && Array.isArray(data['@graph'])) {
|
|
218
|
+
results.push(...data['@graph']);
|
|
219
|
+
}
|
|
220
|
+
else if (Array.isArray(data)) {
|
|
221
|
+
results.push(...data);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
results.push(data);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
return results;
|
|
231
|
+
}
|
|
232
|
+
export function extractForms($, selector) {
|
|
233
|
+
const forms = [];
|
|
234
|
+
const formSelector = selector || 'form';
|
|
235
|
+
$(formSelector).each((_, formElement) => {
|
|
236
|
+
const $form = $(formElement);
|
|
237
|
+
const fields = [];
|
|
238
|
+
$form.find('input, select, textarea').each((_, fieldElement) => {
|
|
239
|
+
const $field = $(fieldElement);
|
|
240
|
+
const tagName = fieldElement.tagName?.toLowerCase();
|
|
241
|
+
const type = $field.attr('type') || (tagName === 'textarea' ? 'textarea' : tagName === 'select' ? 'select' : 'text');
|
|
242
|
+
const field = {
|
|
243
|
+
name: $field.attr('name'),
|
|
244
|
+
type,
|
|
245
|
+
value: $field.val(),
|
|
246
|
+
placeholder: $field.attr('placeholder'),
|
|
247
|
+
required: $field.attr('required') !== undefined,
|
|
248
|
+
};
|
|
249
|
+
if (tagName === 'select') {
|
|
250
|
+
field.options = [];
|
|
251
|
+
$field.find('option').each((_, optionElement) => {
|
|
252
|
+
const $option = $(optionElement);
|
|
253
|
+
field.options.push({
|
|
254
|
+
value: $option.attr('value') || $option.text(),
|
|
255
|
+
text: $option.text().trim(),
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
fields.push(field);
|
|
260
|
+
});
|
|
261
|
+
forms.push({
|
|
262
|
+
action: $form.attr('action'),
|
|
263
|
+
method: $form.attr('method')?.toUpperCase(),
|
|
264
|
+
name: $form.attr('name'),
|
|
265
|
+
id: $form.attr('id'),
|
|
266
|
+
fields,
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
return forms;
|
|
270
|
+
}
|
|
271
|
+
export function extractTables($, selector) {
|
|
272
|
+
const tables = [];
|
|
273
|
+
const tableSelector = selector || 'table';
|
|
274
|
+
$(tableSelector).each((_, tableElement) => {
|
|
275
|
+
const $table = $(tableElement);
|
|
276
|
+
const headers = [];
|
|
277
|
+
const rows = [];
|
|
278
|
+
const caption = $table.find('caption').first().text().trim() || undefined;
|
|
279
|
+
const $headerCells = $table.find('thead th, thead td, tr:first-child th');
|
|
280
|
+
if ($headerCells.length > 0) {
|
|
281
|
+
$headerCells.each((_, th) => {
|
|
282
|
+
headers.push($(th).text().trim());
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
const $rows = $table.find('tbody tr, tr').not(':has(th):not(:first-child)');
|
|
286
|
+
$rows.each((_, tr) => {
|
|
287
|
+
const row = [];
|
|
288
|
+
$(tr).find('td').each((_, td) => {
|
|
289
|
+
row.push($(td).text().trim());
|
|
290
|
+
});
|
|
291
|
+
if (row.length > 0) {
|
|
292
|
+
rows.push(row);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
if (headers.length === 0 && rows.length > 0) {
|
|
296
|
+
const $firstRowCells = $table.find('tr:first-child td, tr:first-child th');
|
|
297
|
+
if ($firstRowCells.length > 0) {
|
|
298
|
+
$firstRowCells.each((_, cell) => {
|
|
299
|
+
headers.push($(cell).text().trim());
|
|
300
|
+
});
|
|
301
|
+
if ($table.find('tr:first-child th').length > 0) {
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
const firstRow = [];
|
|
305
|
+
$table.find('tr:first-child td').each((_, td) => {
|
|
306
|
+
firstRow.push($(td).text().trim());
|
|
307
|
+
});
|
|
308
|
+
if (firstRow.length > 0 && !rows.some(r => r.join('') === firstRow.join(''))) {
|
|
309
|
+
rows.unshift(firstRow);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
tables.push({ headers, rows, caption });
|
|
315
|
+
});
|
|
316
|
+
return tables;
|
|
317
|
+
}
|
|
318
|
+
export function extractScripts($) {
|
|
319
|
+
const scripts = [];
|
|
320
|
+
$('script').each((_, element) => {
|
|
321
|
+
const $el = $(element);
|
|
322
|
+
const src = $el.attr('src');
|
|
323
|
+
const inline = !src ? $el.html()?.trim() : undefined;
|
|
324
|
+
if (!src && !inline)
|
|
325
|
+
return;
|
|
326
|
+
scripts.push({
|
|
327
|
+
src,
|
|
328
|
+
type: $el.attr('type'),
|
|
329
|
+
async: $el.attr('async') !== undefined,
|
|
330
|
+
defer: $el.attr('defer') !== undefined,
|
|
331
|
+
inline,
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
return scripts;
|
|
335
|
+
}
|
|
336
|
+
export function extractStyles($) {
|
|
337
|
+
const styles = [];
|
|
338
|
+
$('link[rel="stylesheet"]').each((_, element) => {
|
|
339
|
+
const $el = $(element);
|
|
340
|
+
styles.push({
|
|
341
|
+
href: $el.attr('href'),
|
|
342
|
+
media: $el.attr('media'),
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
$('style').each((_, element) => {
|
|
346
|
+
const $el = $(element);
|
|
347
|
+
const inline = $el.html()?.trim();
|
|
348
|
+
if (inline) {
|
|
349
|
+
styles.push({
|
|
350
|
+
media: $el.attr('media'),
|
|
351
|
+
inline,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
return styles;
|
|
356
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ScrapeDocument } from './document.js';
|
|
2
|
+
export { ScrapeElement } from './element.js';
|
|
3
|
+
export { extractLinks, extractImages, extractMeta, extractOpenGraph, extractTwitterCard, extractJsonLd, extractForms, extractTables, extractScripts, extractStyles, } from './extractors.js';
|
|
4
|
+
export type { ExtractedLink, ExtractedImage, ExtractedMeta, OpenGraphData, TwitterCardData, JsonLdData, ExtractedForm, ExtractedFormField, ExtractedTable, ExtractedScript, ExtractedStyle, ExtractionSchema, ExtractionSchemaField, ScrapeOptions, LinkExtractionOptions, ImageExtractionOptions, } from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scrape/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,eAAe,EACf,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ScrapeDocument } from './document.js';
|
|
2
|
+
export { ScrapeElement } from './element.js';
|
|
3
|
+
export { extractLinks, extractImages, extractMeta, extractOpenGraph, extractTwitterCard, extractJsonLd, extractForms, extractTables, extractScripts, extractStyles, } from './extractors.js';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export interface ExtractedLink {
|
|
2
|
+
href: string;
|
|
3
|
+
text: string;
|
|
4
|
+
rel?: string;
|
|
5
|
+
target?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
type?: 'internal' | 'external' | 'anchor' | 'mailto' | 'tel';
|
|
8
|
+
}
|
|
9
|
+
export interface ExtractedImage {
|
|
10
|
+
src: string;
|
|
11
|
+
alt?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
srcset?: string;
|
|
16
|
+
loading?: 'lazy' | 'eager';
|
|
17
|
+
}
|
|
18
|
+
export interface ExtractedMeta {
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
keywords?: string[];
|
|
22
|
+
author?: string;
|
|
23
|
+
robots?: string;
|
|
24
|
+
canonical?: string;
|
|
25
|
+
viewport?: string;
|
|
26
|
+
charset?: string;
|
|
27
|
+
[key: string]: string | string[] | undefined;
|
|
28
|
+
}
|
|
29
|
+
export interface OpenGraphData {
|
|
30
|
+
title?: string;
|
|
31
|
+
type?: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
image?: string | string[];
|
|
34
|
+
description?: string;
|
|
35
|
+
siteName?: string;
|
|
36
|
+
locale?: string;
|
|
37
|
+
[key: string]: string | string[] | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface TwitterCardData {
|
|
40
|
+
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
41
|
+
site?: string;
|
|
42
|
+
creator?: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
image?: string;
|
|
46
|
+
[key: string]: string | undefined;
|
|
47
|
+
}
|
|
48
|
+
export interface JsonLdData {
|
|
49
|
+
'@context'?: string;
|
|
50
|
+
'@type'?: string;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
export interface ExtractedForm {
|
|
54
|
+
action?: string;
|
|
55
|
+
method?: string;
|
|
56
|
+
name?: string;
|
|
57
|
+
id?: string;
|
|
58
|
+
fields: ExtractedFormField[];
|
|
59
|
+
}
|
|
60
|
+
export interface ExtractedFormField {
|
|
61
|
+
name?: string;
|
|
62
|
+
type?: string;
|
|
63
|
+
value?: string;
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
required?: boolean;
|
|
66
|
+
options?: {
|
|
67
|
+
value: string;
|
|
68
|
+
text: string;
|
|
69
|
+
}[];
|
|
70
|
+
}
|
|
71
|
+
export interface ExtractedTable {
|
|
72
|
+
headers: string[];
|
|
73
|
+
rows: string[][];
|
|
74
|
+
caption?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface ExtractedScript {
|
|
77
|
+
src?: string;
|
|
78
|
+
type?: string;
|
|
79
|
+
async?: boolean;
|
|
80
|
+
defer?: boolean;
|
|
81
|
+
inline?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface ExtractedStyle {
|
|
84
|
+
href?: string;
|
|
85
|
+
media?: string;
|
|
86
|
+
inline?: string;
|
|
87
|
+
}
|
|
88
|
+
export type ExtractionSchemaField = string | {
|
|
89
|
+
selector: string;
|
|
90
|
+
attribute?: string;
|
|
91
|
+
multiple?: boolean;
|
|
92
|
+
transform?: (value: string) => unknown;
|
|
93
|
+
};
|
|
94
|
+
export interface ExtractionSchema {
|
|
95
|
+
[key: string]: ExtractionSchemaField;
|
|
96
|
+
}
|
|
97
|
+
export interface ScrapeOptions {
|
|
98
|
+
baseUrl?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface LinkExtractionOptions {
|
|
101
|
+
selector?: string;
|
|
102
|
+
absolute?: boolean;
|
|
103
|
+
}
|
|
104
|
+
export interface ImageExtractionOptions {
|
|
105
|
+
selector?: string;
|
|
106
|
+
absolute?: boolean;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/scrape/types.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAE5B,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;CAC9D;AAGD,MAAM,WAAW,cAAc;IAE7B,GAAG,EAAE,MAAM,CAAC;IAEZ,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AAGD,MAAM,WAAW,aAAa;IAE5B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;CAC9C;AAGD,MAAM,WAAW,aAAa;I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QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAqCA,OAAO,EACL,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GACV,MAAM,WAAW,CAAC;AAEnB,YAAY,EACV,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MockClient, MockTransport, createMockClient, installGlobalMock, uninstallGlobalMock, MockAgent, } from './mock.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MockAgent } from 'undici';
|
|
2
|
+
import type { ReckerRequest, ReckerResponse, Transport } from '../types/index.js';
|
|
3
|
+
export interface MockResponseOptions {
|
|
4
|
+
status?: number;
|
|
5
|
+
body?: any;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
times?: number;
|
|
8
|
+
delay?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface MockInterceptOptions {
|
|
11
|
+
path: string | RegExp;
|
|
12
|
+
method?: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
body?: string | RegExp;
|
|
15
|
+
}
|
|
16
|
+
export declare class MockClient {
|
|
17
|
+
private responses;
|
|
18
|
+
private callHistory;
|
|
19
|
+
private pendingIntercept?;
|
|
20
|
+
get(path: string | RegExp, options?: Omit<MockInterceptOptions, 'path' | 'method'>): this;
|
|
21
|
+
post(path: string | RegExp, options?: Omit<MockInterceptOptions, 'path' | 'method'>): this;
|
|
22
|
+
put(path: string | RegExp, options?: Omit<MockInterceptOptions, 'path' | 'method'>): this;
|
|
23
|
+
patch(path: string | RegExp, options?: Omit<MockInterceptOptions, 'path' | 'method'>): this;
|
|
24
|
+
delete(path: string | RegExp, options?: Omit<MockInterceptOptions, 'path' | 'method'>): this;
|
|
25
|
+
intercept(options: MockInterceptOptions): this;
|
|
26
|
+
reply(status: number, body?: any, headers?: Record<string, string>): this;
|
|
27
|
+
replyOnce(status: number, body?: any, headers?: Record<string, string>): this;
|
|
28
|
+
replyWithDelay(delay: number, status: number, body?: any, headers?: Record<string, string>): this;
|
|
29
|
+
replyWithError(error: Error | string): this;
|
|
30
|
+
history(): {
|
|
31
|
+
method: string;
|
|
32
|
+
url: string;
|
|
33
|
+
body?: any;
|
|
34
|
+
headers: Headers;
|
|
35
|
+
}[];
|
|
36
|
+
called(method: string, pathPattern?: string | RegExp): boolean;
|
|
37
|
+
callCount(method?: string, pathPattern?: string | RegExp): number;
|
|
38
|
+
reset(): void;
|
|
39
|
+
resetHistory(): void;
|
|
40
|
+
private makeKey;
|
|
41
|
+
_findResponse(method: string, url: string, body?: any, headers?: Headers): MockResponseOptions | undefined;
|
|
42
|
+
}
|
|
43
|
+
export declare class MockTransport implements Transport {
|
|
44
|
+
private mock;
|
|
45
|
+
constructor(mock?: MockClient);
|
|
46
|
+
getMock(): MockClient;
|
|
47
|
+
dispatch(req: ReckerRequest): Promise<ReckerResponse>;
|
|
48
|
+
}
|
|
49
|
+
export declare function createMockClient(): {
|
|
50
|
+
mock: MockClient;
|
|
51
|
+
transport: MockTransport;
|
|
52
|
+
};
|
|
53
|
+
export declare function installGlobalMock(options?: {
|
|
54
|
+
throwOnUnmocked?: boolean;
|
|
55
|
+
}): MockAgent;
|
|
56
|
+
export declare function uninstallGlobalMock(): void;
|
|
57
|
+
export { MockAgent } from 'undici';
|
|
58
|
+
//# sourceMappingURL=mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../src/testing/mock.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAwD,MAAM,QAAQ,CAAC;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,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