firecrawl-cli 0.0.5 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +426 -6
- package/dist/__tests__/commands/scrape.test.js +21 -6
- package/dist/__tests__/commands/scrape.test.js.map +1 -1
- package/dist/commands/config.d.ts +13 -4
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +42 -53
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/login.d.ts +15 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +81 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +9 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +33 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/scrape.d.ts.map +1 -1
- package/dist/commands/scrape.js +15 -8
- package/dist/commands/scrape.js.map +1 -1
- package/dist/commands/search.d.ts +13 -0
- package/dist/commands/search.d.ts.map +1 -0
- package/dist/commands/search.js +241 -0
- package/dist/commands/search.js.map +1 -0
- package/dist/index.js +219 -30
- package/dist/index.js.map +1 -1
- package/dist/types/scrape.d.ts +2 -2
- package/dist/types/scrape.d.ts.map +1 -1
- package/dist/types/search.d.ts +103 -0
- package/dist/types/search.d.ts.map +1 -0
- package/dist/types/search.js +6 -0
- package/dist/types/search.js.map +1 -0
- package/dist/utils/auth.d.ts +55 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +346 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/options.d.ts +7 -1
- package/dist/utils/options.d.ts.map +1 -1
- package/dist/utils/options.js +55 -1
- package/dist/utils/options.js.map +1 -1
- package/dist/utils/output.d.ts +7 -5
- package/dist/utils/output.d.ts.map +1 -1
- package/dist/utils/output.js +83 -48
- package/dist/utils/output.js.map +1 -1
- package/package.json +4 -2
package/dist/commands/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Config command implementation
|
|
4
|
-
*
|
|
4
|
+
* Handles configuration and authentication
|
|
5
5
|
*/
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
@@ -38,67 +38,56 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
38
38
|
})();
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.configure = configure;
|
|
41
|
-
|
|
41
|
+
exports.viewConfig = viewConfig;
|
|
42
42
|
const credentials_1 = require("../utils/credentials");
|
|
43
43
|
const config_1 = require("../utils/config");
|
|
44
|
-
const
|
|
44
|
+
const auth_1 = require("../utils/auth");
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Configure/login - triggers login flow when not authenticated
|
|
47
47
|
*/
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
rl.close();
|
|
59
|
-
resolve(answer.trim() || defaultValue || '');
|
|
48
|
+
async function configure(options = {}) {
|
|
49
|
+
// If not authenticated, trigger the login flow
|
|
50
|
+
if (!(0, auth_1.isAuthenticated)() || options.apiKey || options.method) {
|
|
51
|
+
// Import handleLoginCommand to avoid circular dependency
|
|
52
|
+
const { handleLoginCommand } = await Promise.resolve().then(() => __importStar(require('./login')));
|
|
53
|
+
await handleLoginCommand({
|
|
54
|
+
apiKey: options.apiKey,
|
|
55
|
+
apiUrl: options.apiUrl,
|
|
56
|
+
webUrl: options.webUrl,
|
|
57
|
+
method: options.method,
|
|
60
58
|
});
|
|
61
|
-
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Already authenticated - show config and offer to re-authenticate
|
|
62
|
+
await viewConfig();
|
|
63
|
+
console.log('To re-authenticate, run: firecrawl logout && firecrawl config\n');
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
|
-
*
|
|
65
|
-
* Asks for API URL and API key
|
|
66
|
+
* View current configuration (read-only)
|
|
66
67
|
*/
|
|
67
|
-
async function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
console.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const normalizedUrl = url.trim().replace(/\/$/, '');
|
|
85
|
-
try {
|
|
86
|
-
(0, credentials_1.saveCredentials)({
|
|
87
|
-
apiKey: key.trim(),
|
|
88
|
-
apiUrl: normalizedUrl,
|
|
89
|
-
});
|
|
90
|
-
console.log('\n✓ Configuration saved successfully');
|
|
91
|
-
console.log(` API URL: ${normalizedUrl}`);
|
|
92
|
-
console.log(` Stored in: ${(0, credentials_1.getConfigDirectoryPath)()}`);
|
|
93
|
-
// Update global config
|
|
94
|
-
(0, config_1.updateConfig)({
|
|
95
|
-
apiKey: key.trim(),
|
|
96
|
-
apiUrl: normalizedUrl,
|
|
97
|
-
});
|
|
68
|
+
async function viewConfig() {
|
|
69
|
+
const credentials = (0, credentials_1.loadCredentials)();
|
|
70
|
+
const config = (0, config_1.getConfig)();
|
|
71
|
+
console.log('\n┌─────────────────────────────────────────┐');
|
|
72
|
+
console.log('│ Firecrawl Configuration │');
|
|
73
|
+
console.log('└─────────────────────────────────────────┘\n');
|
|
74
|
+
if ((0, auth_1.isAuthenticated)()) {
|
|
75
|
+
const maskedKey = credentials?.apiKey
|
|
76
|
+
? `${credentials.apiKey.substring(0, 6)}...${credentials.apiKey.slice(-4)}`
|
|
77
|
+
: 'Not set';
|
|
78
|
+
console.log('Status: ✓ Authenticated\n');
|
|
79
|
+
console.log(`API Key: ${maskedKey}`);
|
|
80
|
+
console.log(`API URL: ${config.apiUrl || 'https://api.firecrawl.dev'}`);
|
|
81
|
+
console.log(`Config: ${(0, credentials_1.getConfigDirectoryPath)()}`);
|
|
82
|
+
console.log('\nCommands:');
|
|
83
|
+
console.log(' firecrawl logout Clear credentials');
|
|
84
|
+
console.log(' firecrawl config Re-authenticate');
|
|
98
85
|
}
|
|
99
|
-
|
|
100
|
-
console.
|
|
101
|
-
|
|
86
|
+
else {
|
|
87
|
+
console.log('Status: Not authenticated\n');
|
|
88
|
+
console.log('Run any command to start authentication, or use:');
|
|
89
|
+
console.log(' firecrawl config Authenticate with browser or API key');
|
|
102
90
|
}
|
|
91
|
+
console.log('');
|
|
103
92
|
}
|
|
104
93
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBH,8BAmBC;AAKD,gCA0BC;AAhED,sDAA+E;AAC/E,4CAA4C;AAC5C,wCAAqE;AASrE;;GAEG;AACI,KAAK,UAAU,SAAS,CAAC,UAA4B,EAAE;IAC5D,+CAA+C;IAC/C,IAAI,CAAC,IAAA,sBAAe,GAAE,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QAC3D,yDAAyD;QACzD,MAAM,EAAE,kBAAkB,EAAE,GAAG,wDAAa,SAAS,GAAC,CAAC;QACvD,MAAM,kBAAkB,CAAC;YACvB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;QACH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AChE,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Login command implementation
|
|
3
|
+
* Handles both manual API key entry and browser-based authentication
|
|
4
|
+
*/
|
|
5
|
+
export interface LoginOptions {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
apiUrl?: string;
|
|
8
|
+
webUrl?: string;
|
|
9
|
+
method?: 'browser' | 'manual';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Main login command handler
|
|
13
|
+
*/
|
|
14
|
+
export declare function handleLoginCommand(options?: LoginOptions): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CA6Ef"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Login command implementation
|
|
4
|
+
* Handles both manual API key entry and browser-based authentication
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.handleLoginCommand = handleLoginCommand;
|
|
8
|
+
const credentials_1 = require("../utils/credentials");
|
|
9
|
+
const config_1 = require("../utils/config");
|
|
10
|
+
const auth_1 = require("../utils/auth");
|
|
11
|
+
const DEFAULT_API_URL = 'https://api.firecrawl.dev';
|
|
12
|
+
const WEB_URL = 'https://firecrawl.dev';
|
|
13
|
+
/**
|
|
14
|
+
* Main login command handler
|
|
15
|
+
*/
|
|
16
|
+
async function handleLoginCommand(options = {}) {
|
|
17
|
+
const apiUrl = options.apiUrl?.replace(/\/$/, '') || DEFAULT_API_URL;
|
|
18
|
+
const webUrl = options.webUrl?.replace(/\/$/, '') || WEB_URL;
|
|
19
|
+
// If already authenticated, let them know
|
|
20
|
+
if ((0, auth_1.isAuthenticated)() && !options.apiKey && !options.method) {
|
|
21
|
+
console.log('You are already logged in.');
|
|
22
|
+
console.log(`Credentials stored at: ${(0, credentials_1.getConfigDirectoryPath)()}`);
|
|
23
|
+
console.log('\nTo login with a different account, run:');
|
|
24
|
+
console.log(' firecrawl logout');
|
|
25
|
+
console.log(' firecrawl login');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// If API key provided directly, save it
|
|
29
|
+
if (options.apiKey) {
|
|
30
|
+
if (!options.apiKey.startsWith('fc-')) {
|
|
31
|
+
console.error('Error: Invalid API key format. API keys should start with "fc-"');
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
(0, credentials_1.saveCredentials)({
|
|
36
|
+
apiKey: options.apiKey,
|
|
37
|
+
apiUrl: apiUrl,
|
|
38
|
+
});
|
|
39
|
+
console.log('✓ Login successful!');
|
|
40
|
+
(0, config_1.updateConfig)({
|
|
41
|
+
apiKey: options.apiKey,
|
|
42
|
+
apiUrl: apiUrl,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('Error saving credentials:', error instanceof Error ? error.message : 'Unknown error');
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
let result;
|
|
53
|
+
if (options.method === 'manual') {
|
|
54
|
+
result = await (0, auth_1.manualLogin)();
|
|
55
|
+
}
|
|
56
|
+
else if (options.method === 'browser') {
|
|
57
|
+
result = await (0, auth_1.browserLogin)(webUrl);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
result = await (0, auth_1.interactiveLogin)(webUrl);
|
|
61
|
+
}
|
|
62
|
+
// Save credentials
|
|
63
|
+
(0, credentials_1.saveCredentials)({
|
|
64
|
+
apiKey: result.apiKey,
|
|
65
|
+
apiUrl: result.apiUrl || apiUrl,
|
|
66
|
+
});
|
|
67
|
+
console.log('\n✓ Login successful!');
|
|
68
|
+
if (result.teamName) {
|
|
69
|
+
console.log(` Team: ${result.teamName}`);
|
|
70
|
+
}
|
|
71
|
+
(0, config_1.updateConfig)({
|
|
72
|
+
apiKey: result.apiKey,
|
|
73
|
+
apiUrl: result.apiUrl || apiUrl,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('\nError:', error instanceof Error ? error.message : 'Unknown error');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAwBH,gDA+EC;AArGD,sDAA+E;AAC/E,4CAA+C;AAC/C,wCAKuB;AAEvB,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACpD,MAAM,OAAO,GAAG,uBAAuB,CAAC;AASxC;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,UAAwB,EAAE;IAE1B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC;IACrE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC;IAE7D,0CAA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|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logout command implementation
|
|
4
|
+
* Clears stored credentials
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.handleLogoutCommand = handleLogoutCommand;
|
|
8
|
+
const credentials_1 = require("../utils/credentials");
|
|
9
|
+
const config_1 = require("../utils/config");
|
|
10
|
+
/**
|
|
11
|
+
* Main logout command handler
|
|
12
|
+
*/
|
|
13
|
+
async function handleLogoutCommand() {
|
|
14
|
+
const credentials = (0, credentials_1.loadCredentials)();
|
|
15
|
+
if (!credentials || !credentials.apiKey) {
|
|
16
|
+
console.log('No credentials found. You are not logged in.');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
(0, credentials_1.deleteCredentials)();
|
|
21
|
+
// Clear the global config
|
|
22
|
+
(0, config_1.updateConfig)({
|
|
23
|
+
apiKey: '',
|
|
24
|
+
apiUrl: '',
|
|
25
|
+
});
|
|
26
|
+
console.log('✓ Logged out successfully');
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Error logging out:', error instanceof Error ? error.message : 'Unknown error');
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAYH,kDAwBC;AAlCD,sDAI8B;AAC9B,4CAA+C;AAE/C;;GAEG;AACI,KAAK,UAAU,mBAAmB;IACvC,MAAM,WAAW,GAAG,IAAA,6BAAe,GAAE,CAAC;IAEtC,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,IAAA,+BAAiB,GAAE,CAAC;QACpB,0BAA0B;QAC1B,IAAA,qBAAY,EAAC;YACX,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,oBAAoB,EACpB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CACzD,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrape.d.ts","sourceRoot":"","sources":["../../src/commands/scrape.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"scrape.d.ts","sourceRoot":"","sources":["../../src/commands/scrape.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EAEb,MAAM,iBAAiB,CAAC;AAoCzB;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAqEvB;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAef"}
|
package/dist/commands/scrape.js
CHANGED
|
@@ -33,14 +33,13 @@ async function executeScrape(options) {
|
|
|
33
33
|
const app = (0, client_1.getClient)({ apiKey: options.apiKey });
|
|
34
34
|
// Build scrape options
|
|
35
35
|
const formats = [];
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
// Add requested formats
|
|
37
|
+
if (options.formats && options.formats.length > 0) {
|
|
38
|
+
formats.push(...options.formats);
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
formats.push('screenshot');
|
|
43
|
-
}
|
|
40
|
+
// Add screenshot format if requested and not already included
|
|
41
|
+
if (options.screenshot && !formats.includes('screenshot')) {
|
|
42
|
+
formats.push('screenshot');
|
|
44
43
|
}
|
|
45
44
|
// If no formats specified, default to markdown
|
|
46
45
|
if (formats.length === 0) {
|
|
@@ -86,6 +85,14 @@ async function executeScrape(options) {
|
|
|
86
85
|
*/
|
|
87
86
|
async function handleScrapeCommand(options) {
|
|
88
87
|
const result = await executeScrape(options);
|
|
89
|
-
|
|
88
|
+
// Determine effective formats for output handling
|
|
89
|
+
const effectiveFormats = options.formats && options.formats.length > 0
|
|
90
|
+
? [...options.formats]
|
|
91
|
+
: ['markdown'];
|
|
92
|
+
// Add screenshot to effective formats if it was requested separately
|
|
93
|
+
if (options.screenshot && !effectiveFormats.includes('screenshot')) {
|
|
94
|
+
effectiveFormats.push('screenshot');
|
|
95
|
+
}
|
|
96
|
+
(0, output_1.handleScrapeOutput)(result, effectiveFormats, options.output, options.pretty);
|
|
90
97
|
}
|
|
91
98
|
//# sourceMappingURL=scrape.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrape.js","sourceRoot":"","sources":["../../src/commands/scrape.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"scrape.js","sourceRoot":"","sources":["../../src/commands/scrape.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA8CH,sCAuEC;AAKD,kDAiBC;AAnID,4CAA4C;AAC5C,4CAAqD;AAErD;;GAEG;AACH,SAAS,YAAY,CACnB,OAAsB,EACtB,gBAAwB,EACxB,cAAsB,EACtB,KAAuB;IAEvB,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO;IAE5B,MAAM,eAAe,GAAG,cAAc,GAAG,gBAAgB,CAAC;IAC1D,MAAM,UAAU,GAMZ;QACF,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,WAAW,EAAE,IAAI,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I,KAAK,UAAU,mBAAmB,CACvC,OAAsB;IAEtB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAE5C,kDAAkD;IAClD,MAAM,gBAAgB,GACpB,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAC3C,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;QACtB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAEnB,qEAAqE;IACrE,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QACnE,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;IAED,IAAA,2BAAkB,EAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search command implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { SearchOptions, SearchResult } from '../types/search';
|
|
5
|
+
/**
|
|
6
|
+
* Execute search command
|
|
7
|
+
*/
|
|
8
|
+
export declare function executeSearch(options: SearchOptions): Promise<SearchResult>;
|
|
9
|
+
/**
|
|
10
|
+
* Handle search command output
|
|
11
|
+
*/
|
|
12
|
+
export declare function handleSearchCommand(options: SearchOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EAKb,MAAM,iBAAiB,CAAC;AAIzB;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAmHvB;AA+FD;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Search command implementation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.executeSearch = executeSearch;
|
|
7
|
+
exports.handleSearchCommand = handleSearchCommand;
|
|
8
|
+
const client_1 = require("../utils/client");
|
|
9
|
+
const output_1 = require("../utils/output");
|
|
10
|
+
/**
|
|
11
|
+
* Execute search command
|
|
12
|
+
*/
|
|
13
|
+
async function executeSearch(options) {
|
|
14
|
+
try {
|
|
15
|
+
const app = (0, client_1.getClient)({ apiKey: options.apiKey });
|
|
16
|
+
// Build search options for the SDK
|
|
17
|
+
const searchParams = {
|
|
18
|
+
limit: options.limit,
|
|
19
|
+
};
|
|
20
|
+
// Add sources if specified
|
|
21
|
+
if (options.sources && options.sources.length > 0) {
|
|
22
|
+
searchParams.sources = options.sources.map((source) => ({
|
|
23
|
+
type: source,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
// Add categories if specified
|
|
27
|
+
if (options.categories && options.categories.length > 0) {
|
|
28
|
+
searchParams.categories = options.categories.map((category) => ({
|
|
29
|
+
type: category,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
// Add time-based search parameter
|
|
33
|
+
if (options.tbs) {
|
|
34
|
+
searchParams.tbs = options.tbs;
|
|
35
|
+
}
|
|
36
|
+
// Add location parameter
|
|
37
|
+
if (options.location) {
|
|
38
|
+
searchParams.location = options.location;
|
|
39
|
+
}
|
|
40
|
+
// Add country parameter
|
|
41
|
+
if (options.country) {
|
|
42
|
+
searchParams.country = options.country;
|
|
43
|
+
}
|
|
44
|
+
// Add timeout parameter
|
|
45
|
+
if (options.timeout !== undefined) {
|
|
46
|
+
searchParams.timeout = options.timeout;
|
|
47
|
+
}
|
|
48
|
+
// Add ignoreInvalidURLs parameter
|
|
49
|
+
if (options.ignoreInvalidUrls !== undefined) {
|
|
50
|
+
searchParams.ignoreInvalidURLs = options.ignoreInvalidUrls;
|
|
51
|
+
}
|
|
52
|
+
// Add scrape options if scraping is enabled
|
|
53
|
+
if (options.scrape) {
|
|
54
|
+
const scrapeOptions = {};
|
|
55
|
+
// Add formats
|
|
56
|
+
if (options.scrapeFormats && options.scrapeFormats.length > 0) {
|
|
57
|
+
scrapeOptions.formats = options.scrapeFormats.map((format) => ({
|
|
58
|
+
type: format,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Default to markdown if scraping is enabled but no formats specified
|
|
63
|
+
scrapeOptions.formats = [{ type: 'markdown' }];
|
|
64
|
+
}
|
|
65
|
+
// Add onlyMainContent if specified
|
|
66
|
+
if (options.onlyMainContent !== undefined) {
|
|
67
|
+
scrapeOptions.onlyMainContent = options.onlyMainContent;
|
|
68
|
+
}
|
|
69
|
+
searchParams.scrapeOptions = scrapeOptions;
|
|
70
|
+
}
|
|
71
|
+
// Execute search
|
|
72
|
+
const result = await app.search(options.query, searchParams);
|
|
73
|
+
// Handle the response - the SDK returns the data directly or wrapped
|
|
74
|
+
const data = {};
|
|
75
|
+
// Check if result has the expected structure
|
|
76
|
+
if (result) {
|
|
77
|
+
// Handle web results
|
|
78
|
+
if (result.web || result.data?.web) {
|
|
79
|
+
data.web = (result.web ||
|
|
80
|
+
result.data?.web);
|
|
81
|
+
}
|
|
82
|
+
// Handle image results
|
|
83
|
+
if (result.images || result.data?.images) {
|
|
84
|
+
data.images = (result.images ||
|
|
85
|
+
result.data?.images);
|
|
86
|
+
}
|
|
87
|
+
// Handle news results
|
|
88
|
+
if (result.news || result.data?.news) {
|
|
89
|
+
data.news = (result.news ||
|
|
90
|
+
result.data?.news);
|
|
91
|
+
}
|
|
92
|
+
// If result is an array (legacy format), treat as web results
|
|
93
|
+
if (Array.isArray(result)) {
|
|
94
|
+
data.web = result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
success: true,
|
|
99
|
+
data,
|
|
100
|
+
warning: result?.warning,
|
|
101
|
+
id: result?.id,
|
|
102
|
+
creditsUsed: result?.creditsUsed,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Format search data in human-readable way
|
|
114
|
+
*/
|
|
115
|
+
function formatSearchReadable(data, options) {
|
|
116
|
+
const lines = [];
|
|
117
|
+
// Format web results
|
|
118
|
+
if (data.web && data.web.length > 0) {
|
|
119
|
+
if (options.sources && options.sources.length > 1) {
|
|
120
|
+
lines.push('=== Web Results ===');
|
|
121
|
+
lines.push('');
|
|
122
|
+
}
|
|
123
|
+
for (const result of data.web) {
|
|
124
|
+
lines.push(`${result.title || 'Untitled'}`);
|
|
125
|
+
lines.push(` URL: ${result.url}`);
|
|
126
|
+
if (result.description) {
|
|
127
|
+
lines.push(` ${result.description}`);
|
|
128
|
+
}
|
|
129
|
+
if (result.category) {
|
|
130
|
+
lines.push(` Category: ${result.category}`);
|
|
131
|
+
}
|
|
132
|
+
if (result.markdown) {
|
|
133
|
+
lines.push('');
|
|
134
|
+
lines.push(' --- Content ---');
|
|
135
|
+
// Indent markdown content
|
|
136
|
+
const indentedMarkdown = result.markdown
|
|
137
|
+
.split('\n')
|
|
138
|
+
.map((line) => ` ${line}`)
|
|
139
|
+
.join('\n');
|
|
140
|
+
lines.push(indentedMarkdown);
|
|
141
|
+
lines.push(' --- End Content ---');
|
|
142
|
+
}
|
|
143
|
+
lines.push('');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Format image results
|
|
147
|
+
if (data.images && data.images.length > 0) {
|
|
148
|
+
if (lines.length > 0) {
|
|
149
|
+
lines.push('');
|
|
150
|
+
}
|
|
151
|
+
lines.push('=== Image Results ===');
|
|
152
|
+
lines.push('');
|
|
153
|
+
for (const result of data.images) {
|
|
154
|
+
lines.push(`${result.title || 'Untitled'}`);
|
|
155
|
+
lines.push(` Image URL: ${result.imageUrl}`);
|
|
156
|
+
lines.push(` Source: ${result.url}`);
|
|
157
|
+
if (result.imageWidth && result.imageHeight) {
|
|
158
|
+
lines.push(` Size: ${result.imageWidth}x${result.imageHeight}`);
|
|
159
|
+
}
|
|
160
|
+
lines.push('');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Format news results
|
|
164
|
+
if (data.news && data.news.length > 0) {
|
|
165
|
+
if (lines.length > 0) {
|
|
166
|
+
lines.push('');
|
|
167
|
+
}
|
|
168
|
+
lines.push('=== News Results ===');
|
|
169
|
+
lines.push('');
|
|
170
|
+
for (const result of data.news) {
|
|
171
|
+
lines.push(`${result.title || 'Untitled'}`);
|
|
172
|
+
lines.push(` URL: ${result.url}`);
|
|
173
|
+
if (result.date) {
|
|
174
|
+
lines.push(` Date: ${result.date}`);
|
|
175
|
+
}
|
|
176
|
+
if (result.snippet) {
|
|
177
|
+
lines.push(` ${result.snippet}`);
|
|
178
|
+
}
|
|
179
|
+
if (result.markdown) {
|
|
180
|
+
lines.push('');
|
|
181
|
+
lines.push(' --- Content ---');
|
|
182
|
+
const indentedMarkdown = result.markdown
|
|
183
|
+
.split('\n')
|
|
184
|
+
.map((line) => ` ${line}`)
|
|
185
|
+
.join('\n');
|
|
186
|
+
lines.push(indentedMarkdown);
|
|
187
|
+
lines.push(' --- End Content ---');
|
|
188
|
+
}
|
|
189
|
+
lines.push('');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return lines.join('\n');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Handle search command output
|
|
196
|
+
*/
|
|
197
|
+
async function handleSearchCommand(options) {
|
|
198
|
+
const result = await executeSearch(options);
|
|
199
|
+
if (!result.success) {
|
|
200
|
+
console.error('Error:', result.error);
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
if (!result.data) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// Check if there are any results
|
|
207
|
+
const hasResults = (result.data.web && result.data.web.length > 0) ||
|
|
208
|
+
(result.data.images && result.data.images.length > 0) ||
|
|
209
|
+
(result.data.news && result.data.news.length > 0);
|
|
210
|
+
if (!hasResults) {
|
|
211
|
+
console.log('No results found.');
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
let outputContent;
|
|
215
|
+
// Use JSON format if --json or --pretty flag is set
|
|
216
|
+
// --pretty implies JSON output
|
|
217
|
+
if (options.json || options.pretty) {
|
|
218
|
+
const jsonOutput = {
|
|
219
|
+
success: true,
|
|
220
|
+
data: result.data,
|
|
221
|
+
};
|
|
222
|
+
if (result.warning) {
|
|
223
|
+
jsonOutput.warning = result.warning;
|
|
224
|
+
}
|
|
225
|
+
if (result.id) {
|
|
226
|
+
jsonOutput.id = result.id;
|
|
227
|
+
}
|
|
228
|
+
if (result.creditsUsed !== undefined) {
|
|
229
|
+
jsonOutput.creditsUsed = result.creditsUsed;
|
|
230
|
+
}
|
|
231
|
+
outputContent = options.pretty
|
|
232
|
+
? JSON.stringify(jsonOutput, null, 2)
|
|
233
|
+
: JSON.stringify(jsonOutput);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Default to human-readable format
|
|
237
|
+
outputContent = formatSearchReadable(result.data, options);
|
|
238
|
+
}
|
|
239
|
+
(0, output_1.writeOutput)(outputContent, options.output, !!options.output);
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAiBH,sCAqHC;AAkGD,kDAsDC;AAnRD,4CAA4C;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