recker 1.0.79 → 1.0.80-next.70ea84d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/browser/mini.d.ts +2 -2
- package/dist/browser/browser/recker-mini.d.ts +8 -8
- package/dist/browser/browser/recker.d.ts +11 -8
- package/dist/browser/browser/recker.js +54 -6
- package/dist/browser/core/client.d.ts +15 -10
- package/dist/browser/core/client.js +54 -38
- package/dist/browser/index.iife.min.js +129 -130
- package/dist/browser/index.min.js +129 -130
- package/dist/browser/index.mini.iife.js +5697 -636
- package/dist/browser/index.mini.iife.min.js +47 -48
- package/dist/browser/index.mini.min.js +47 -48
- package/dist/browser/index.mini.umd.js +5697 -636
- package/dist/browser/index.mini.umd.min.js +47 -48
- package/dist/browser/index.umd.min.js +129 -130
- package/dist/browser/mini.d.ts +2 -2
- package/dist/browser/plugins/proxy-rotator.d.ts +2 -2
- package/dist/browser/plugins/proxy-rotator.js +6 -28
- package/dist/browser/recker-mini.d.ts +8 -8
- package/dist/browser/recker.d.ts +11 -8
- package/dist/browser/recker.js +54 -6
- package/dist/browser/scrape/document.js +2 -2
- package/dist/browser/scrape/element.js +7 -1
- package/dist/browser/scrape/parser/nodes/html.js +1 -1
- package/dist/browser/scrape/spider.d.ts +52 -0
- package/dist/browser/scrape/spider.js +620 -38
- package/dist/browser/scrape/types.d.ts +2 -0
- package/dist/browser/search/google.d.ts +26 -1
- package/dist/browser/search/google.js +427 -45
- package/dist/browser/seo/analyzer.d.ts +1 -0
- package/dist/browser/seo/analyzer.js +144 -1
- package/dist/browser/seo/index.d.ts +1 -1
- package/dist/browser/seo/keyword-campaign-analyzer.d.ts +2 -0
- package/dist/browser/seo/keyword-campaign-analyzer.js +538 -0
- package/dist/browser/seo/keyword-campaign-seed-advanced.d.ts +17 -0
- package/dist/browser/seo/keyword-campaign-seed-advanced.js +269 -0
- package/dist/browser/seo/keyword-campaign-seed-core.d.ts +29 -0
- package/dist/browser/seo/keyword-campaign-seed-core.js +525 -0
- package/dist/browser/seo/keyword-campaign-shared.d.ts +165 -0
- package/dist/browser/seo/keyword-campaign-shared.js +59 -0
- package/dist/browser/seo/keyword-campaign.d.ts +4 -107
- package/dist/browser/seo/keyword-campaign.js +2 -380
- package/dist/browser/seo/keywords.js +5 -22
- package/dist/browser/seo/types.d.ts +19 -0
- package/dist/browser/transport/curl.d.ts +5 -1
- package/dist/browser/transport/curl.js +207 -50
- package/dist/browser/transport/undici.d.ts +4 -3
- package/dist/browser/transport/undici.js +123 -49
- package/dist/browser/types/index.d.ts +9 -3
- package/dist/browser/utils/binary-manager.js +26 -3
- package/dist/browser/utils/block-detector.d.ts +8 -0
- package/dist/browser/utils/block-detector.js +542 -7
- package/dist/cli/commands/hls-runner.js +5 -4
- package/dist/cli/commands/live-runner.js +5 -4
- package/dist/cli/commands/loadtest-runner.js +3 -2
- package/dist/cli/commands/search.d.ts +2 -0
- package/dist/cli/commands/search.js +105 -0
- package/dist/cli/commands/seo-runner.js +9 -7
- package/dist/cli/commands/seo.js +140 -1
- package/dist/cli/commands/serve.js +75 -131
- package/dist/cli/commands/server-runner.js +59 -82
- package/dist/cli/commands/spider-runner.d.ts +37 -1
- package/dist/cli/commands/spider-runner.js +134 -10
- package/dist/cli/commands/spider.d.ts +18 -1
- package/dist/cli/commands/spider.js +457 -27
- package/dist/cli/events/handlers/cli.js +30 -1
- package/dist/cli/events/handlers/tui.js +26 -0
- package/dist/cli/events/types.d.ts +27 -0
- package/dist/cli/handler.d.ts +2 -12
- package/dist/cli/handler.js +20 -15
- package/dist/cli/handlers/protocols.js +39 -12
- package/dist/cli/handlers/search.d.ts +2 -0
- package/dist/cli/handlers/search.js +171 -0
- package/dist/cli/handlers/seo-analyze.d.ts +1 -0
- package/dist/cli/handlers/seo-analyze.js +666 -0
- package/dist/cli/handlers/seo-robots.d.ts +1 -0
- package/dist/cli/handlers/seo-robots.js +76 -0
- package/dist/cli/handlers/seo-serp.d.ts +54 -0
- package/dist/cli/handlers/seo-serp.js +243 -0
- package/dist/cli/handlers/seo-sitemap.d.ts +1 -0
- package/dist/cli/handlers/seo-sitemap.js +55 -0
- package/dist/cli/handlers/seo-spider.d.ts +1 -0
- package/dist/cli/handlers/seo-spider.js +334 -0
- package/dist/cli/handlers/seo.d.ts +8 -4
- package/dist/cli/handlers/seo.js +294 -442
- package/dist/cli/handlers/spider.js +94 -17
- package/dist/cli/handlers/streaming.js +5 -1
- package/dist/cli/index.js +11 -2
- package/dist/cli/presets.d.ts +1 -1
- package/dist/cli/presets.js +15 -4
- package/dist/cli/tui/app.js +6 -1
- package/dist/cli/tui/components/rich-response.d.ts +72 -0
- package/dist/cli/tui/components/rich-response.js +117 -0
- package/dist/cli/tui/executor-commands/background.js +30 -24
- package/dist/cli/tui/executor-commands/testing.js +3 -2
- package/dist/cli/tui/hooks/useDomains.d.ts +17 -0
- package/dist/cli/tui/hooks/useHelp.js +15 -2
- package/dist/cli/tui/job-manager.d.ts +4 -4
- package/dist/cli/tui/job-manager.js +5 -1
- package/dist/cli/tui/spider-tui.d.ts +63 -0
- package/dist/cli/tui/spider-tui.js +120 -2
- package/dist/cli/types.d.ts +12 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/utils/option-helpers.d.ts +10 -0
- package/dist/cli/utils/option-helpers.js +63 -0
- package/dist/cli/utils/score-color.d.ts +11 -0
- package/dist/cli/utils/score-color.js +11 -0
- package/dist/cli/utils/serp-campaign.d.ts +53 -0
- package/dist/cli/utils/serp-campaign.js +53 -0
- package/dist/cli/utils/serp-config.d.ts +26 -0
- package/dist/cli/utils/serp-config.js +125 -0
- package/dist/core/client.d.ts +15 -10
- package/dist/core/client.js +54 -38
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/cli.js +35 -34
- package/dist/mcp/client.d.ts +2 -2
- package/dist/mcp/client.js +20 -2
- package/dist/mcp/contract.d.ts +1 -1
- package/dist/mcp/profiles.js +5 -1
- package/dist/mcp/prompts/index.js +8 -4
- package/dist/mcp/resources/index.js +46 -23
- package/dist/mcp/server.js +9 -6
- package/dist/mcp/tools/protocols.js +9 -2
- package/dist/mcp/tools/registry.js +13 -3
- package/dist/mcp/tools/seo.js +427 -2
- package/dist/mcp/types.d.ts +5 -1
- package/dist/plugins/proxy-rotator.d.ts +2 -2
- package/dist/plugins/proxy-rotator.js +6 -28
- package/dist/raffel/client.d.ts +38 -0
- package/dist/raffel/client.js +282 -0
- package/dist/raffel/index.d.ts +2 -0
- package/dist/raffel/index.js +2 -0
- package/dist/raffel/types.d.ts +40 -0
- package/dist/raffel/types.js +14 -0
- package/dist/recker.d.ts +13 -7
- package/dist/recker.js +58 -6
- package/dist/scrape/document.js +2 -2
- package/dist/scrape/element.js +7 -1
- package/dist/scrape/parser/nodes/html.js +1 -1
- package/dist/scrape/spider.d.ts +52 -0
- package/dist/scrape/spider.js +620 -38
- package/dist/scrape/types.d.ts +2 -0
- package/dist/search/google.d.ts +26 -1
- package/dist/search/google.js +427 -45
- package/dist/search/index.d.ts +1 -1
- package/dist/seo/analyzer.d.ts +1 -0
- package/dist/seo/analyzer.js +144 -1
- package/dist/seo/index.d.ts +1 -1
- package/dist/seo/keyword-campaign-analyzer.d.ts +2 -0
- package/dist/seo/keyword-campaign-analyzer.js +538 -0
- package/dist/seo/keyword-campaign-seed-advanced.d.ts +17 -0
- package/dist/seo/keyword-campaign-seed-advanced.js +269 -0
- package/dist/seo/keyword-campaign-seed-core.d.ts +29 -0
- package/dist/seo/keyword-campaign-seed-core.js +525 -0
- package/dist/seo/keyword-campaign-shared.d.ts +165 -0
- package/dist/seo/keyword-campaign-shared.js +59 -0
- package/dist/seo/keyword-campaign.d.ts +4 -107
- package/dist/seo/keyword-campaign.js +2 -380
- package/dist/seo/keywords.js +5 -22
- package/dist/seo/types.d.ts +19 -0
- package/dist/template/index.d.ts +1 -1
- package/dist/template/types.d.ts +0 -2
- package/dist/testing/index.d.ts +1 -22
- package/dist/testing/index.js +1 -11
- package/dist/transport/curl.d.ts +5 -1
- package/dist/transport/curl.js +207 -50
- package/dist/transport/undici.d.ts +4 -3
- package/dist/transport/undici.js +123 -49
- package/dist/types/index.d.ts +9 -3
- package/dist/utils/binary-manager.js +26 -3
- package/dist/utils/block-detector.d.ts +8 -0
- package/dist/utils/block-detector.js +542 -7
- package/dist/version.js +1 -1
- package/package.json +12 -1
- package/dist/testing/mock-dns-server.d.ts +0 -69
- package/dist/testing/mock-dns-server.js +0 -269
- package/dist/testing/mock-ftp-server.d.ts +0 -89
- package/dist/testing/mock-ftp-server.js +0 -562
- package/dist/testing/mock-hls-server.d.ts +0 -80
- package/dist/testing/mock-hls-server.js +0 -381
- package/dist/testing/mock-http-server.d.ts +0 -124
- package/dist/testing/mock-http-server.js +0 -343
- package/dist/testing/mock-proxy-server.d.ts +0 -108
- package/dist/testing/mock-proxy-server.js +0 -615
- package/dist/testing/mock-sse-server.d.ts +0 -76
- package/dist/testing/mock-sse-server.js +0 -291
- package/dist/testing/mock-telnet-server.d.ts +0 -59
- package/dist/testing/mock-telnet-server.js +0 -274
- package/dist/testing/mock-udp-server.d.ts +0 -43
- package/dist/testing/mock-udp-server.js +0 -188
- package/dist/testing/mock-websocket-server.d.ts +0 -76
- package/dist/testing/mock-websocket-server.js +0 -334
- package/dist/testing/mock-whois-server.d.ts +0 -56
- package/dist/testing/mock-whois-server.js +0 -234
- package/dist/testing/proxy-certs.d.ts +0 -19
- package/dist/testing/proxy-certs.js +0 -208
|
@@ -107,6 +107,30 @@ export class CLIHandler {
|
|
|
107
107
|
if (this.context.verbose && Object.keys(event.summary).length > 0) {
|
|
108
108
|
console.log(c.dim(` Summary: ${JSON.stringify(event.summary)}`));
|
|
109
109
|
}
|
|
110
|
+
if (this.context.verbose) {
|
|
111
|
+
const summary = event.summary;
|
|
112
|
+
const security = summary.security;
|
|
113
|
+
if (security) {
|
|
114
|
+
console.log(c.bold(' Anti-bot summary:'));
|
|
115
|
+
const blockedPages = security.blockedPages ?? 0;
|
|
116
|
+
const captchaPages = security.captchaPages ?? 0;
|
|
117
|
+
const attempts = security.avgAttempts;
|
|
118
|
+
const avgTtfb = security.avgTtfbMs;
|
|
119
|
+
const transportUsage = security.transportUsage;
|
|
120
|
+
const captchaProviders = security.captchaProviders;
|
|
121
|
+
console.log(c.dim(` blocked=${blockedPages} captcha=${captchaPages} avgAttempts=${attempts ?? 'n/a'} avgTTFB=${avgTtfb ?? 'n/a'}ms`));
|
|
122
|
+
if (transportUsage) {
|
|
123
|
+
const usage = transportUsage;
|
|
124
|
+
console.log(c.dim(` transport usage: curl=${usage.curl || 0} undici=${usage.undici || 0}`));
|
|
125
|
+
}
|
|
126
|
+
if (captchaProviders && Object.keys(captchaProviders).length > 0) {
|
|
127
|
+
const providerList = Object.entries(captchaProviders)
|
|
128
|
+
.map(([provider, count]) => `${provider}: ${count}`)
|
|
129
|
+
.join(', ');
|
|
130
|
+
console.log(c.dim(` captcha providers: ${providerList}`));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
110
134
|
}
|
|
111
135
|
handleError(event) {
|
|
112
136
|
this.clearProgress();
|
|
@@ -121,7 +145,12 @@ export class CLIHandler {
|
|
|
121
145
|
handleSpiderPage(event) {
|
|
122
146
|
if (this.context.verbose) {
|
|
123
147
|
const status = event.status < 400 ? c.success(String(event.status)) : c.error(String(event.status));
|
|
124
|
-
|
|
148
|
+
const depthInfo = c.dim(`[${event.depth}]`);
|
|
149
|
+
const security = event.security
|
|
150
|
+
? ` ${c.dim(event.security.blocked ? '[blocked]' : event.security.captchaDetected ? '[captcha]' : '')}`
|
|
151
|
+
: '';
|
|
152
|
+
const timing = event.timings?.ttfb ? ` ${c.dim(`ttfb=${event.timings.ttfb}ms`)}` : '';
|
|
153
|
+
console.log(` ${status} ${depthInfo} ${event.url}${security}${timing}`);
|
|
125
154
|
}
|
|
126
155
|
}
|
|
127
156
|
handleSpiderQueue(event) {
|
|
@@ -175,6 +175,7 @@ export class TUIHandler {
|
|
|
175
175
|
case 'complete': {
|
|
176
176
|
const completeEvent = event;
|
|
177
177
|
const summary = completeEvent.summary;
|
|
178
|
+
const securitySummary = summary.security;
|
|
178
179
|
if (event.command === 'spider' && summary.url) {
|
|
179
180
|
const domain = this.extractDomain(summary.url);
|
|
180
181
|
if (domain) {
|
|
@@ -186,6 +187,31 @@ export class TUIHandler {
|
|
|
186
187
|
scripts: summary.scripts || 0,
|
|
187
188
|
stylesheets: summary.stylesheets || 0,
|
|
188
189
|
errors: summary.errors || 0,
|
|
190
|
+
security: securitySummary
|
|
191
|
+
? {
|
|
192
|
+
pages: Number(securitySummary.pages ?? 0),
|
|
193
|
+
blockedPages: Number(securitySummary.blockedPages ?? 0),
|
|
194
|
+
captchaPages: Number(securitySummary.captchaPages ?? 0),
|
|
195
|
+
captchaProviders: typeof securitySummary.captchaProviders === 'object'
|
|
196
|
+
? securitySummary.captchaProviders
|
|
197
|
+
: undefined,
|
|
198
|
+
attempts: Number(securitySummary.attempts ?? 0),
|
|
199
|
+
retries: Number(securitySummary.retries ?? 0),
|
|
200
|
+
transportUsage: securitySummary.transportUsage,
|
|
201
|
+
avgAttempts: typeof securitySummary.avgAttempts === 'number'
|
|
202
|
+
? securitySummary.avgAttempts
|
|
203
|
+
: undefined,
|
|
204
|
+
avgTtfbMs: typeof securitySummary.avgTtfbMs === 'number'
|
|
205
|
+
? securitySummary.avgTtfbMs
|
|
206
|
+
: undefined,
|
|
207
|
+
avgTotalMs: typeof securitySummary.avgTotalMs === 'number'
|
|
208
|
+
? securitySummary.avgTotalMs
|
|
209
|
+
: undefined,
|
|
210
|
+
avgDownloadMs: typeof securitySummary.avgDownloadMs === 'number'
|
|
211
|
+
? securitySummary.avgDownloadMs
|
|
212
|
+
: undefined,
|
|
213
|
+
}
|
|
214
|
+
: undefined,
|
|
189
215
|
});
|
|
190
216
|
}
|
|
191
217
|
}
|
|
@@ -42,6 +42,33 @@ export interface SpiderPageEvent extends BaseEvent {
|
|
|
42
42
|
title?: string;
|
|
43
43
|
links: number;
|
|
44
44
|
duration: number;
|
|
45
|
+
security?: {
|
|
46
|
+
blocked?: boolean;
|
|
47
|
+
reason?: string;
|
|
48
|
+
confidence?: number;
|
|
49
|
+
captchaDetected?: boolean;
|
|
50
|
+
captchaProvider?: string;
|
|
51
|
+
attempts?: number;
|
|
52
|
+
retryCount?: number;
|
|
53
|
+
retryAfterMs?: number;
|
|
54
|
+
transport?: 'auto' | 'undici' | 'curl';
|
|
55
|
+
blockedByCaptcha?: boolean;
|
|
56
|
+
lastStatus?: number;
|
|
57
|
+
lastTransport?: 'auto' | 'undici' | 'curl';
|
|
58
|
+
};
|
|
59
|
+
timings?: {
|
|
60
|
+
dns?: number;
|
|
61
|
+
tcp?: number;
|
|
62
|
+
tls?: number;
|
|
63
|
+
ttfb?: number;
|
|
64
|
+
download?: number;
|
|
65
|
+
total?: number;
|
|
66
|
+
};
|
|
67
|
+
resources?: {
|
|
68
|
+
images: number;
|
|
69
|
+
scripts: number;
|
|
70
|
+
stylesheets: number;
|
|
71
|
+
};
|
|
45
72
|
}
|
|
46
73
|
export interface SpiderQueueEvent extends BaseEvent {
|
|
47
74
|
type: 'spider:queue';
|
package/dist/cli/handler.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
url: string;
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
body?: any;
|
|
6
|
-
verbose?: boolean;
|
|
7
|
-
quiet?: boolean;
|
|
8
|
-
output?: string;
|
|
9
|
-
clientOptions?: any;
|
|
10
|
-
}
|
|
11
|
-
export declare function handleRequest(options: RequestOptions): Promise<void>;
|
|
12
|
-
export {};
|
|
1
|
+
import type { CliRequestOptions } from './types.js';
|
|
2
|
+
export declare function handleRequest(options: CliRequestOptions): Promise<void>;
|
package/dist/cli/handler.js
CHANGED
|
@@ -29,9 +29,9 @@ export async function handleRequest(options) {
|
|
|
29
29
|
}).start();
|
|
30
30
|
const start = performance.now();
|
|
31
31
|
try {
|
|
32
|
-
let client;
|
|
33
32
|
const finalClientOptions = options.clientOptions || {};
|
|
34
|
-
|
|
33
|
+
const legacyBase = 'base' in finalClientOptions ? finalClientOptions.base : undefined;
|
|
34
|
+
if (!finalClientOptions.baseUrl && !legacyBase) {
|
|
35
35
|
try {
|
|
36
36
|
const urlObj = new URL(options.url);
|
|
37
37
|
finalClientOptions.baseUrl = urlObj.origin;
|
|
@@ -39,34 +39,39 @@ export async function handleRequest(options) {
|
|
|
39
39
|
catch {
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const requestHeaders = {
|
|
43
|
+
...finalClientOptions.headers,
|
|
44
|
+
...options.headers,
|
|
45
|
+
};
|
|
46
|
+
finalClientOptions.headers = requestHeaders;
|
|
47
|
+
const client = createClient(finalClientOptions);
|
|
48
|
+
let requestBody;
|
|
49
|
+
const headers = { ...requestHeaders };
|
|
46
50
|
if (options.body) {
|
|
47
51
|
if (typeof options.body === 'string') {
|
|
48
52
|
requestBody = options.body;
|
|
49
|
-
if (!
|
|
53
|
+
if (!headers['Content-Type'] && !headers['content-type']) {
|
|
50
54
|
try {
|
|
51
55
|
JSON.parse(options.body);
|
|
52
|
-
|
|
56
|
+
headers['Content-Type'] = 'application/json';
|
|
53
57
|
}
|
|
54
58
|
catch {
|
|
55
|
-
|
|
59
|
+
headers['Content-Type'] = 'text/plain';
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
else {
|
|
60
64
|
requestBody = JSON.stringify(options.body);
|
|
61
|
-
if (!
|
|
62
|
-
|
|
65
|
+
if (!headers['Content-Type'] && !headers['content-type']) {
|
|
66
|
+
headers['Content-Type'] = 'application/json';
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
}
|
|
70
|
+
const method = options.method;
|
|
66
71
|
const response = await client.request(options.url, {
|
|
67
|
-
method
|
|
68
|
-
headers
|
|
69
|
-
body: requestBody
|
|
72
|
+
method,
|
|
73
|
+
headers,
|
|
74
|
+
...(requestBody === undefined ? {} : { body: requestBody }),
|
|
70
75
|
});
|
|
71
76
|
const duration = Math.round(performance.now() - start);
|
|
72
77
|
spinner?.stop();
|
|
@@ -93,7 +98,7 @@ export async function handleRequest(options) {
|
|
|
93
98
|
if (options.verbose) {
|
|
94
99
|
console.log(colors.gray('\n--- Request ---'));
|
|
95
100
|
console.log(`${colors.bold(options.method)} ${options.url}`);
|
|
96
|
-
Object.entries(
|
|
101
|
+
Object.entries(headers).forEach(([k, v]) => {
|
|
97
102
|
console.log(`${colors.blue(k)}: ${v}`);
|
|
98
103
|
});
|
|
99
104
|
if (options.body) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { withHandler, createEnhancedOutput, getString, getNumber, getBoolean, colors, } from '../output.js';
|
|
2
|
+
import { ConnectionError, ValidationError } from '../../core/errors.js';
|
|
2
3
|
export const ftpLsHandler = withHandler({ loading: true }, async (ctx, out, extCtx) => {
|
|
3
4
|
const host = getString(ctx.result.positional.host);
|
|
4
5
|
const remotePath = getString(ctx.result.positional.path, '/');
|
|
@@ -17,14 +18,22 @@ export const ftpLsHandler = withHandler({ loading: true }, async (ctx, out, extC
|
|
|
17
18
|
out.log(colors.gray(`Connecting to ${host}...`));
|
|
18
19
|
}
|
|
19
20
|
const connectResult = await client.connect();
|
|
20
|
-
if (!connectResult.success)
|
|
21
|
-
throw new
|
|
21
|
+
if (!connectResult.success) {
|
|
22
|
+
throw new ConnectionError(connectResult.message ?? 'Connection failed', {
|
|
23
|
+
host,
|
|
24
|
+
port,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
22
27
|
if (!extCtx && !jsonOutput) {
|
|
23
28
|
out.success('Connected');
|
|
24
29
|
}
|
|
25
30
|
const result = await client.list(remotePath);
|
|
26
|
-
if (!result.success || !result.data)
|
|
27
|
-
throw new
|
|
31
|
+
if (!result.success || !result.data) {
|
|
32
|
+
throw new ValidationError(result.message ?? 'Operation failed', {
|
|
33
|
+
field: 'path',
|
|
34
|
+
value: remotePath,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
28
37
|
await client.close();
|
|
29
38
|
if (extCtx) {
|
|
30
39
|
out.response({
|
|
@@ -78,8 +87,13 @@ export const ftpGetHandler = withHandler({ loading: true }, async (ctx, out, ext
|
|
|
78
87
|
if (!extCtx) {
|
|
79
88
|
out.log(colors.gray(`Connecting to ${host}...`));
|
|
80
89
|
}
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
const connectResult = await client.connect();
|
|
91
|
+
if (!connectResult.success) {
|
|
92
|
+
throw new ConnectionError(connectResult.message ?? 'Connection failed', {
|
|
93
|
+
host,
|
|
94
|
+
port,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
83
97
|
if (!extCtx) {
|
|
84
98
|
out.log(colors.gray(`Downloading ${remote} -> ${local}...`));
|
|
85
99
|
}
|
|
@@ -95,8 +109,12 @@ export const ftpGetHandler = withHandler({ loading: true }, async (ctx, out, ext
|
|
|
95
109
|
const result = await client.download(remote, local);
|
|
96
110
|
if (!extCtx)
|
|
97
111
|
out.log('');
|
|
98
|
-
if (!result.success)
|
|
99
|
-
throw new
|
|
112
|
+
if (!result.success) {
|
|
113
|
+
throw new ValidationError(result.message ?? 'Operation failed', {
|
|
114
|
+
field: 'remote',
|
|
115
|
+
value: remote,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
100
118
|
await client.close();
|
|
101
119
|
if (extCtx) {
|
|
102
120
|
out.response({
|
|
@@ -128,8 +146,13 @@ export const ftpPutHandler = withHandler({ loading: true }, async (ctx, out, ext
|
|
|
128
146
|
if (!extCtx) {
|
|
129
147
|
out.log(colors.gray(`Connecting to ${host}...`));
|
|
130
148
|
}
|
|
131
|
-
|
|
132
|
-
|
|
149
|
+
const connectResult = await client.connect();
|
|
150
|
+
if (!connectResult.success) {
|
|
151
|
+
throw new ConnectionError(connectResult.message ?? 'Connection failed', {
|
|
152
|
+
host,
|
|
153
|
+
port,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
133
156
|
if (!extCtx) {
|
|
134
157
|
out.log(colors.gray(`Uploading ${local} -> ${remote}...`));
|
|
135
158
|
}
|
|
@@ -145,8 +168,12 @@ export const ftpPutHandler = withHandler({ loading: true }, async (ctx, out, ext
|
|
|
145
168
|
const result = await client.upload(local, remote);
|
|
146
169
|
if (!extCtx)
|
|
147
170
|
out.log('');
|
|
148
|
-
if (!result.success)
|
|
149
|
-
throw new
|
|
171
|
+
if (!result.success) {
|
|
172
|
+
throw new ValidationError(result.message ?? 'Operation failed', {
|
|
173
|
+
field: 'local',
|
|
174
|
+
value: local,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
150
177
|
await client.close();
|
|
151
178
|
if (extCtx) {
|
|
152
179
|
out.response({
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { withHandler, getString, getNumber, getBoolean, colors } from '../output.js';
|
|
2
|
+
import { searchGoogleAdvanced } from '../../search/google.js';
|
|
3
|
+
function normalizeSerpTransport(value) {
|
|
4
|
+
const raw = getString(value).toLowerCase();
|
|
5
|
+
if (raw === 'undici' || raw === 'curl' || raw === 'auto') {
|
|
6
|
+
return raw;
|
|
7
|
+
}
|
|
8
|
+
return 'curl';
|
|
9
|
+
}
|
|
10
|
+
function normalizeTransportInput(value) {
|
|
11
|
+
const raw = getString(value).trim().toLowerCase();
|
|
12
|
+
if (!raw)
|
|
13
|
+
return '';
|
|
14
|
+
return raw;
|
|
15
|
+
}
|
|
16
|
+
function normalizeSerpSource(value) {
|
|
17
|
+
const raw = getString(value).trim().toLowerCase();
|
|
18
|
+
return raw === 'google' || raw.length === 0 ? 'google' : 'google';
|
|
19
|
+
}
|
|
20
|
+
function toQueryResults(value) {
|
|
21
|
+
const parsed = getNumber(value);
|
|
22
|
+
if (!Number.isFinite(parsed))
|
|
23
|
+
return 10;
|
|
24
|
+
const normalized = Math.floor(parsed);
|
|
25
|
+
if (!Number.isFinite(normalized))
|
|
26
|
+
return 10;
|
|
27
|
+
return Math.min(100, Math.max(10, normalized));
|
|
28
|
+
}
|
|
29
|
+
function toQueryStart(value) {
|
|
30
|
+
const parsed = getNumber(value);
|
|
31
|
+
if (!Number.isFinite(parsed))
|
|
32
|
+
return 0;
|
|
33
|
+
const normalized = Math.floor(parsed);
|
|
34
|
+
if (!Number.isFinite(normalized))
|
|
35
|
+
return 0;
|
|
36
|
+
return Math.max(0, normalized);
|
|
37
|
+
}
|
|
38
|
+
function toResultRows(result) {
|
|
39
|
+
return result.map((item) => ({
|
|
40
|
+
rank: item.rank,
|
|
41
|
+
title: item.title.slice(0, 75),
|
|
42
|
+
url: item.displayedUrl || item.url,
|
|
43
|
+
placement: item.placement ?? 'organic',
|
|
44
|
+
snippet: item.snippet ? item.snippet.slice(0, 120) : '',
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
export const searchHandler = withHandler({ loading: 'Running search...' }, async (ctx, out, extCtx) => {
|
|
48
|
+
const query = getString(ctx.result.positional.query);
|
|
49
|
+
const jsonOutput = getBoolean(ctx.result.options.json);
|
|
50
|
+
const country = getString(ctx.result.options.country);
|
|
51
|
+
const gl = getString(ctx.result.options.gl || ctx.result.options.country);
|
|
52
|
+
const hl = getString(ctx.result.options.hl);
|
|
53
|
+
const site = getString(ctx.result.options.site);
|
|
54
|
+
const transport = normalizeSerpTransport(ctx.result.options.transport);
|
|
55
|
+
const source = normalizeSerpSource(ctx.result.options.source);
|
|
56
|
+
const timeout = getQueryNumber(ctx.result.options.timeout, 15000);
|
|
57
|
+
const num = toQueryResults(ctx.result.options.num);
|
|
58
|
+
const start = toQueryStart(ctx.result.options.start);
|
|
59
|
+
const includeRawHtml = getBoolean(ctx.result.options.includeRawHtml);
|
|
60
|
+
const humanProfile = normalizeTransportInput(ctx.result.options.humanProfile) || 'chrome';
|
|
61
|
+
const asSiteSearch = site || getString(ctx.result.options.asSiteSearch);
|
|
62
|
+
const asExactPhrase = getString(ctx.result.options.exactPhrase);
|
|
63
|
+
if (!query) {
|
|
64
|
+
out.error('Search query is required');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!extCtx) {
|
|
68
|
+
out.log(colors.gray(`Searching Google for: ${colors.bold(query)}`));
|
|
69
|
+
}
|
|
70
|
+
const result = await searchGoogleAdvanced(query, {
|
|
71
|
+
asSitesearch: asSiteSearch,
|
|
72
|
+
asEpq: asExactPhrase,
|
|
73
|
+
num,
|
|
74
|
+
start,
|
|
75
|
+
country: country || undefined,
|
|
76
|
+
gl: gl || undefined,
|
|
77
|
+
hl: hl || undefined,
|
|
78
|
+
source,
|
|
79
|
+
transport,
|
|
80
|
+
timeout,
|
|
81
|
+
humanProfile: humanProfile === 'off' ? 'off' : 'chrome',
|
|
82
|
+
includeRawHtml,
|
|
83
|
+
});
|
|
84
|
+
const outputPayload = {
|
|
85
|
+
query: result.query,
|
|
86
|
+
source: result.source,
|
|
87
|
+
searchUrl: result.searchUrl,
|
|
88
|
+
results: toResultRows(result.results),
|
|
89
|
+
resultStats: result.resultStats,
|
|
90
|
+
nextPageStart: result.nextPageStart,
|
|
91
|
+
nextPageUrl: result.nextPageUrl,
|
|
92
|
+
status: result.status,
|
|
93
|
+
transport: {
|
|
94
|
+
requested: transport,
|
|
95
|
+
used: result.transport.used,
|
|
96
|
+
fallbackUsed: result.transport.fallbackUsed,
|
|
97
|
+
impersonateAvailable: result.transport.impersonateAvailable,
|
|
98
|
+
},
|
|
99
|
+
timings: result.timings,
|
|
100
|
+
block: result.block ? {
|
|
101
|
+
detected: Boolean(result.block.blocked),
|
|
102
|
+
reason: result.block.reason,
|
|
103
|
+
confidence: result.block.confidence,
|
|
104
|
+
} : undefined,
|
|
105
|
+
captcha: result.captcha ? {
|
|
106
|
+
detected: result.captcha.detected,
|
|
107
|
+
provider: result.captcha.provider,
|
|
108
|
+
confidence: result.captcha.confidence,
|
|
109
|
+
} : undefined,
|
|
110
|
+
};
|
|
111
|
+
if (extCtx) {
|
|
112
|
+
out.response(outputPayload, { responseType: 'search' });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (jsonOutput) {
|
|
116
|
+
out.json({
|
|
117
|
+
...outputPayload,
|
|
118
|
+
searchUrl: result.searchUrl,
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const totalResults = outputPayload.results.length;
|
|
123
|
+
const usedTransport = `${outputPayload.transport.used} (requested: ${outputPayload.transport.requested})`;
|
|
124
|
+
out.title('Google Search', '🔍');
|
|
125
|
+
out.keyValue([
|
|
126
|
+
{ key: 'Query', value: outputPayload.query },
|
|
127
|
+
{ key: 'Source', value: outputPayload.source },
|
|
128
|
+
{ key: 'Search URL', value: outputPayload.searchUrl },
|
|
129
|
+
{ key: 'Results', value: totalResults },
|
|
130
|
+
{ key: 'Transport', value: usedTransport },
|
|
131
|
+
{ key: 'Country', value: country || '(inferred)' },
|
|
132
|
+
{ key: 'Locale', value: hl || '(default)' },
|
|
133
|
+
{ key: 'Status', value: outputPayload.status ?? 'n/a' },
|
|
134
|
+
]);
|
|
135
|
+
if (outputPayload.block?.detected || outputPayload.captcha?.detected) {
|
|
136
|
+
const warnings = [];
|
|
137
|
+
if (outputPayload.block?.detected) {
|
|
138
|
+
warnings.push(`Block detected (${outputPayload.block.reason || 'unknown'})`);
|
|
139
|
+
}
|
|
140
|
+
if (outputPayload.captcha?.detected) {
|
|
141
|
+
warnings.push(`CAPTCHA detected${outputPayload.captcha.provider ? ` (${outputPayload.captcha.provider})` : ''}`);
|
|
142
|
+
}
|
|
143
|
+
out.blank();
|
|
144
|
+
out.warn(warnings.join(' | '));
|
|
145
|
+
}
|
|
146
|
+
if (totalResults === 0) {
|
|
147
|
+
out.warn('No results found (or blocked/captcha response without organic snippets).');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
out.blank();
|
|
151
|
+
out.subtitle('Top results');
|
|
152
|
+
out.table(outputPayload.results.map((item) => ({
|
|
153
|
+
Rank: `#${item.rank}`,
|
|
154
|
+
Title: item.title,
|
|
155
|
+
URL: item.url,
|
|
156
|
+
Placement: item.placement ?? 'organic',
|
|
157
|
+
Snippet: item.snippet ?? '',
|
|
158
|
+
})), [
|
|
159
|
+
{ key: 'Rank', label: 'Rank', width: 6 },
|
|
160
|
+
{ key: 'Title', label: 'Title', width: 36 },
|
|
161
|
+
{ key: 'URL', label: 'URL', width: 44 },
|
|
162
|
+
{ key: 'Placement', label: 'Type', width: 10 },
|
|
163
|
+
{ key: 'Snippet', label: 'Snippet', width: 45 },
|
|
164
|
+
]);
|
|
165
|
+
});
|
|
166
|
+
function getQueryNumber(value, fallback) {
|
|
167
|
+
const num = getNumber(value, fallback);
|
|
168
|
+
if (!Number.isFinite(num))
|
|
169
|
+
return fallback;
|
|
170
|
+
return Math.floor(num);
|
|
171
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const seoAnalyzeHandler: (ctx: import("../handler-types.js").ExecutionContext) => Promise<void>;
|