@mendable/firecrawl-js 0.0.12 → 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 CHANGED
@@ -61,13 +61,50 @@ 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.
67
104
  * @param {Params | null} params - Additional parameters for the crawl request.
68
105
  * @param {boolean} waitUntilDone - Whether to wait for the crawl job to complete.
69
106
  * @param {number} timeout - Timeout in seconds for job status checks.
70
- * @returns {Promise<CrawlResponse>} The response from the crawl operation.
107
+ * @returns {Promise<CrawlResponse | any>} The response from the crawl operation.
71
108
  */
72
109
  crawlUrl(url_1) {
73
110
  return __awaiter(this, arguments, void 0, function* (url, params = null, waitUntilDone = true, timeout = 2) {
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@mendable/firecrawl-js",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "build/index.js",
6
6
  "types": "types/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
9
+ "build": "tsc",
10
+ "publish":"npm run build && npm publish --access public",
9
11
  "test": "echo \"Error: no test specified\" && exit 1"
10
12
  },
11
13
  "repository": {
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,13 +104,46 @@ 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.
102
143
  * @param {Params | null} params - Additional parameters for the crawl request.
103
144
  * @param {boolean} waitUntilDone - Whether to wait for the crawl job to complete.
104
145
  * @param {number} timeout - Timeout in seconds for job status checks.
105
- * @returns {Promise<CrawlResponse>} The response from the crawl operation.
146
+ * @returns {Promise<CrawlResponse | any>} The response from the crawl operation.
106
147
  */
107
148
  async crawlUrl(url: string, params: Params | null = null, waitUntilDone: boolean = true, timeout: number = 2): Promise<CrawlResponse | any> {
108
149
  const headers = this.prepareHeaders();
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
  */
@@ -27,7 +35,7 @@ export interface CrawlResponse {
27
35
  jobId?: string;
28
36
  data?: any;
29
37
  error?: string;
30
- }
38
+ }
31
39
  /**
32
40
  * Response interface for job status checks.
33
41
  */
@@ -55,15 +63,22 @@ 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.
61
76
  * @param {Params | null} params - Additional parameters for the crawl request.
62
77
  * @param {boolean} waitUntilDone - Whether to wait for the crawl job to complete.
63
78
  * @param {number} timeout - Timeout in seconds for job status checks.
64
- * @returns {Promise<CrawlResponse>} The response from the crawl operation.
79
+ * @returns {Promise<CrawlResponse | any>} The response from the crawl operation.
65
80
  */
66
- crawlUrl(url: string, params?: Params | null, waitUntilDone?: boolean, timeout?: number): Promise<CrawlResponse>;
81
+ crawlUrl(url: string, params?: Params | null, waitUntilDone?: boolean, timeout?: number): Promise<CrawlResponse | any>;
67
82
  /**
68
83
  * Checks the status of a crawl job using the Firecrawl API.
69
84
  * @param {string} jobId - The job ID of the crawl operation.