@mendable/firecrawl-js 0.0.13 → 0.0.14
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/build/index.js +37 -0
- package/package.json +1 -1
- package/src/index.ts +41 -0
- package/types/index.d.ts +15 -0
package/build/index.js
CHANGED
|
@@ -61,6 +61,43 @@ export default class FirecrawlApp {
|
|
|
61
61
|
return { success: false, error: 'Internal server error.' };
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Searches for a query using the Firecrawl API.
|
|
66
|
+
* @param {string} query - The query to search for.
|
|
67
|
+
* @param {Params | null} params - Additional parameters for the search request.
|
|
68
|
+
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
69
|
+
*/
|
|
70
|
+
search(query_1) {
|
|
71
|
+
return __awaiter(this, arguments, void 0, function* (query, params = null) {
|
|
72
|
+
const headers = {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
75
|
+
};
|
|
76
|
+
let jsonData = { query };
|
|
77
|
+
if (params) {
|
|
78
|
+
jsonData = Object.assign(Object.assign({}, jsonData), params);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const response = yield axios.post('https://api.firecrawl.dev/v0/search', jsonData, { headers });
|
|
82
|
+
if (response.status === 200) {
|
|
83
|
+
const responseData = response.data;
|
|
84
|
+
if (responseData.success) {
|
|
85
|
+
return responseData;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new Error(`Failed to search. Error: ${responseData.error}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.handleError(response, 'search');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw new Error(error.message);
|
|
97
|
+
}
|
|
98
|
+
return { success: false, error: 'Internal server error.' };
|
|
99
|
+
});
|
|
100
|
+
}
|
|
64
101
|
/**
|
|
65
102
|
* Initiates a crawl job for a URL using the Firecrawl API.
|
|
66
103
|
* @param {string} url - The URL to crawl.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,6 +25,14 @@ export interface ScrapeResponse {
|
|
|
25
25
|
error?: string;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Response interface for searching operations.
|
|
30
|
+
*/
|
|
31
|
+
export interface SearchResponse {
|
|
32
|
+
success: boolean;
|
|
33
|
+
data?: any;
|
|
34
|
+
error?: string;
|
|
35
|
+
}
|
|
28
36
|
/**
|
|
29
37
|
* Response interface for crawling operations.
|
|
30
38
|
*/
|
|
@@ -96,6 +104,39 @@ export default class FirecrawlApp {
|
|
|
96
104
|
return { success: false, error: 'Internal server error.' };
|
|
97
105
|
}
|
|
98
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Searches for a query using the Firecrawl API.
|
|
109
|
+
* @param {string} query - The query to search for.
|
|
110
|
+
* @param {Params | null} params - Additional parameters for the search request.
|
|
111
|
+
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
112
|
+
*/
|
|
113
|
+
async search(query: string, params: Params | null = null): Promise<ScrapeResponse> {
|
|
114
|
+
const headers: AxiosRequestHeaders = {
|
|
115
|
+
'Content-Type': 'application/json',
|
|
116
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
117
|
+
} as AxiosRequestHeaders;
|
|
118
|
+
let jsonData: Params = { query };
|
|
119
|
+
if (params) {
|
|
120
|
+
jsonData = { ...jsonData, ...params };
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const response: AxiosResponse = await axios.post('https://api.firecrawl.dev/v0/search', jsonData, { headers });
|
|
124
|
+
if (response.status === 200) {
|
|
125
|
+
const responseData = response.data;
|
|
126
|
+
if (responseData.success) {
|
|
127
|
+
return responseData;
|
|
128
|
+
} else {
|
|
129
|
+
throw new Error(`Failed to search. Error: ${responseData.error}`);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
this.handleError(response, 'search');
|
|
133
|
+
}
|
|
134
|
+
} catch (error: any) {
|
|
135
|
+
throw new Error(error.message);
|
|
136
|
+
}
|
|
137
|
+
return { success: false, error: 'Internal server error.' };
|
|
138
|
+
}
|
|
139
|
+
|
|
99
140
|
/**
|
|
100
141
|
* Initiates a crawl job for a URL using the Firecrawl API.
|
|
101
142
|
* @param {string} url - The URL to crawl.
|
package/types/index.d.ts
CHANGED
|
@@ -19,6 +19,14 @@ export interface ScrapeResponse {
|
|
|
19
19
|
data?: any;
|
|
20
20
|
error?: string;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Response interface for searching operations.
|
|
24
|
+
*/
|
|
25
|
+
export interface SearchResponse {
|
|
26
|
+
success: boolean;
|
|
27
|
+
data?: any;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
22
30
|
/**
|
|
23
31
|
* Response interface for crawling operations.
|
|
24
32
|
*/
|
|
@@ -55,6 +63,13 @@ export default class FirecrawlApp {
|
|
|
55
63
|
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
56
64
|
*/
|
|
57
65
|
scrapeUrl(url: string, params?: Params | null): Promise<ScrapeResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Searches for a query using the Firecrawl API.
|
|
68
|
+
* @param {string} query - The query to search for.
|
|
69
|
+
* @param {Params | null} params - Additional parameters for the search request.
|
|
70
|
+
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
71
|
+
*/
|
|
72
|
+
search(query: string, params?: Params | null): Promise<ScrapeResponse>;
|
|
58
73
|
/**
|
|
59
74
|
* Initiates a crawl job for a URL using the Firecrawl API.
|
|
60
75
|
* @param {string} url - The URL to crawl.
|