@mendable/firecrawl-js 1.0.3 → 1.1.0

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/types/index.d.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import { AxiosResponse, AxiosRequestHeaders } from "axios";
2
- import { z } from "zod";
2
+ import { TypedEventTarget } from "typescript-event-target";
3
3
  /**
4
4
  * Configuration interface for FirecrawlApp.
5
5
  * @param apiKey - Optional API key for authentication.
6
6
  * @param apiUrl - Optional base URL of the API; defaults to 'https://api.firecrawl.dev'.
7
- * @param version - API version, either 'v0' or 'v1'.
8
7
  */
9
8
  export interface FirecrawlAppConfig {
10
9
  apiKey?: string | null;
11
10
  apiUrl?: string | null;
12
- version?: "v0" | "v1";
13
11
  }
14
12
  /**
15
13
  * Metadata for a Firecrawl document.
@@ -50,15 +48,6 @@ export interface FirecrawlDocumentMetadata {
50
48
  error?: string;
51
49
  [key: string]: any;
52
50
  }
53
- /**
54
- * Metadata for a Firecrawl document on v0.
55
- * Similar to FirecrawlDocumentMetadata but includes properties specific to API version v0.
56
- */
57
- export interface FirecrawlDocumentMetadataV0 {
58
- pageStatusCode?: number;
59
- pageError?: string;
60
- [key: string]: any;
61
- }
62
51
  /**
63
52
  * Document interface for Firecrawl.
64
53
  * Represents a document retrieved or processed by Firecrawl.
@@ -70,84 +59,30 @@ export interface FirecrawlDocument {
70
59
  rawHtml?: string;
71
60
  links?: string[];
72
61
  screenshot?: string;
73
- metadata: FirecrawlDocumentMetadata;
74
- }
75
- /**
76
- * Document interface for Firecrawl on v0.
77
- * Represents a document specifically for API version v0 with additional properties.
78
- */
79
- export interface FirecrawlDocumentV0 {
80
- id?: string;
81
- url?: string;
82
- content: string;
83
- markdown?: string;
84
- html?: string;
85
- llm_extraction?: Record<string, any>;
86
- createdAt?: Date;
87
- updatedAt?: Date;
88
- type?: string;
89
- metadata: FirecrawlDocumentMetadataV0;
90
- childrenLinks?: string[];
91
- provider?: string;
92
- warning?: string;
93
- index?: number;
62
+ metadata?: FirecrawlDocumentMetadata;
94
63
  }
95
64
  /**
96
65
  * Parameters for scraping operations.
97
66
  * Defines the options and configurations available for scraping web content.
98
67
  */
99
68
  export interface ScrapeParams {
100
- formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot")[];
69
+ formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "full@scrennshot")[];
101
70
  headers?: Record<string, string>;
102
71
  includeTags?: string[];
103
72
  excludeTags?: string[];
104
73
  onlyMainContent?: boolean;
105
- screenshotMode?: "desktop" | "full-desktop" | "mobile" | "full-mobile";
106
74
  waitFor?: number;
107
75
  timeout?: number;
108
76
  }
109
- /**
110
- * Parameters for scraping operations on v0.
111
- * Includes page and extractor options specific to API version v0.
112
- */
113
- export interface ScrapeParamsV0 {
114
- pageOptions?: {
115
- headers?: Record<string, string>;
116
- includeHtml?: boolean;
117
- includeRawHtml?: boolean;
118
- onlyIncludeTags?: string[];
119
- onlyMainContent?: boolean;
120
- removeTags?: string[];
121
- replaceAllPathsWithAbsolutePaths?: boolean;
122
- screenshot?: boolean;
123
- fullPageScreenshot?: boolean;
124
- waitFor?: number;
125
- };
126
- extractorOptions?: {
127
- mode?: "markdown" | "llm-extraction" | "llm-extraction-from-raw-html" | "llm-extraction-from-markdown";
128
- extractionPrompt?: string;
129
- extractionSchema?: Record<string, any> | z.ZodSchema | any;
130
- };
131
- timeout?: number;
132
- }
133
77
  /**
134
78
  * Response interface for scraping operations.
135
79
  * Defines the structure of the response received after a scraping operation.
136
80
  */
137
81
  export interface ScrapeResponse extends FirecrawlDocument {
138
- success: boolean;
82
+ success: true;
139
83
  warning?: string;
140
84
  error?: string;
141
85
  }
142
- /**
143
- * Response interface for scraping operations on v0.
144
- * Similar to ScrapeResponse but tailored for responses from API version v0.
145
- */
146
- export interface ScrapeResponseV0 {
147
- success: boolean;
148
- data?: FirecrawlDocumentV0;
149
- error?: string;
150
- }
151
86
  /**
152
87
  * Parameters for crawling operations.
153
88
  * Includes options for both scraping and mapping during a crawl.
@@ -162,36 +97,6 @@ export interface CrawlParams {
162
97
  ignoreSitemap?: boolean;
163
98
  scrapeOptions?: ScrapeParams;
164
99
  }
165
- /**
166
- * Parameters for crawling operations on v0.
167
- * Tailored for API version v0, includes specific options for crawling.
168
- */
169
- export interface CrawlParamsV0 {
170
- crawlerOptions?: {
171
- includes?: string[];
172
- excludes?: string[];
173
- generateImgAltText?: boolean;
174
- returnOnlyUrls?: boolean;
175
- maxDepth?: number;
176
- mode?: "default" | "fast";
177
- ignoreSitemap?: boolean;
178
- limit?: number;
179
- allowBackwardCrawling?: boolean;
180
- allowExternalContentLinks?: boolean;
181
- };
182
- pageOptions?: {
183
- headers?: Record<string, string>;
184
- includeHtml?: boolean;
185
- includeRawHtml?: boolean;
186
- onlyIncludeTags?: string[];
187
- onlyMainContent?: boolean;
188
- removeTags?: string[];
189
- replaceAllPathsWithAbsolutePaths?: boolean;
190
- screenshot?: boolean;
191
- fullPageScreenshot?: boolean;
192
- waitFor?: number;
193
- };
194
- }
195
100
  /**
196
101
  * Response interface for crawling operations.
197
102
  * Defines the structure of the response received after initiating a crawl.
@@ -199,16 +104,7 @@ export interface CrawlParamsV0 {
199
104
  export interface CrawlResponse {
200
105
  id?: string;
201
106
  url?: string;
202
- success: boolean;
203
- error?: string;
204
- }
205
- /**
206
- * Response interface for crawling operations on v0.
207
- * Similar to CrawlResponse but tailored for responses from API version v0.
208
- */
209
- export interface CrawlResponseV0 {
210
- jobId?: string;
211
- success: boolean;
107
+ success: true;
212
108
  error?: string;
213
109
  }
214
110
  /**
@@ -216,7 +112,7 @@ export interface CrawlResponseV0 {
216
112
  * Provides detailed status of a crawl job including progress and results.
217
113
  */
218
114
  export interface CrawlStatusResponse {
219
- success: boolean;
115
+ success: true;
220
116
  total: number;
221
117
  completed: number;
222
118
  creditsUsed: number;
@@ -226,111 +122,77 @@ export interface CrawlStatusResponse {
226
122
  data?: FirecrawlDocument[];
227
123
  error?: string;
228
124
  }
229
- /**
230
- * Response interface for job status checks on v0.
231
- * Tailored for API version v0, provides status and partial data of a crawl job.
232
- */
233
- export interface CrawlStatusResponseV0 {
234
- success: boolean;
235
- status: string;
236
- current?: number;
237
- current_url?: string;
238
- current_step?: string;
239
- total?: number;
240
- data?: FirecrawlDocumentV0[];
241
- partial_data?: FirecrawlDocumentV0[];
242
- error?: string;
243
- }
244
125
  /**
245
126
  * Parameters for mapping operations.
246
127
  * Defines options for mapping URLs during a crawl.
247
128
  */
248
129
  export interface MapParams {
249
- includePaths?: string[];
250
- excludePaths?: string[];
251
- maxDepth?: number;
252
- limit?: number;
253
- allowBackwardLinks?: boolean;
254
- allowExternalLinks?: boolean;
130
+ search?: string;
255
131
  ignoreSitemap?: boolean;
132
+ includeSubdomains?: boolean;
133
+ limit?: number;
256
134
  }
257
135
  /**
258
136
  * Response interface for mapping operations.
259
137
  * Defines the structure of the response received after a mapping operation.
260
138
  */
261
139
  export interface MapResponse {
262
- success: boolean;
140
+ success: true;
263
141
  links?: string[];
264
142
  error?: string;
265
143
  }
266
144
  /**
267
- * Parameters for searching operations on v0.
268
- * Tailored for API version v0, includes specific options for searching content.
145
+ * Error response interface.
146
+ * Defines the structure of the response received when an error occurs.
269
147
  */
270
- export interface SearchParamsV0 {
271
- pageOptions?: {
272
- onlyMainContent?: boolean;
273
- fetchPageContent?: boolean;
274
- includeHtml?: boolean;
275
- includeRawHtml?: boolean;
276
- };
277
- searchOptions?: {
278
- limit?: number;
279
- };
280
- }
281
- /**
282
- * Response interface for searching operations on v0.
283
- * Defines the structure of the response received after a search operation on v0.
284
- */
285
- export interface SearchResponseV0 {
286
- success: boolean;
287
- data?: FirecrawlDocumentV0[];
288
- error?: string;
148
+ export interface ErrorResponse {
149
+ success: false;
150
+ error: string;
289
151
  }
290
152
  /**
291
153
  * Main class for interacting with the Firecrawl API.
292
154
  * Provides methods for scraping, searching, crawling, and mapping web content.
293
155
  */
294
- export default class FirecrawlApp<T extends "v0" | "v1"> {
295
- private apiKey;
296
- private apiUrl;
297
- version: T;
156
+ export default class FirecrawlApp {
157
+ apiKey: string;
158
+ apiUrl: string;
298
159
  /**
299
160
  * Initializes a new instance of the FirecrawlApp class.
300
161
  * @param config - Configuration options for the FirecrawlApp instance.
301
162
  */
302
- constructor({ apiKey, apiUrl, version }: FirecrawlAppConfig);
163
+ constructor({ apiKey, apiUrl }: FirecrawlAppConfig);
303
164
  /**
304
165
  * Scrapes a URL using the Firecrawl API.
305
166
  * @param url - The URL to scrape.
306
167
  * @param params - Additional parameters for the scrape request.
307
168
  * @returns The response from the scrape operation.
308
169
  */
309
- scrapeUrl(url: string, params?: ScrapeParams | ScrapeParamsV0): Promise<this['version'] extends 'v0' ? ScrapeResponseV0 : ScrapeResponse>;
170
+ scrapeUrl(url: string, params?: ScrapeParams): Promise<ScrapeResponse | ErrorResponse>;
310
171
  /**
311
- * Searches for a query using the Firecrawl API.
312
- * @param query - The query to search for.
313
- * @param params - Additional parameters for the search request.
314
- * @returns The response from the search operation.
172
+ * This method is intended to search for a query using the Firecrawl API. However, it is not supported in version 1 of the API.
173
+ * @param query - The search query string.
174
+ * @param params - Additional parameters for the search.
175
+ * @returns Throws an error advising to use version 0 of the API.
315
176
  */
316
- search(query: string, params?: SearchParamsV0): Promise<SearchResponseV0>;
177
+ search(query: string, params?: any): Promise<any>;
317
178
  /**
318
179
  * Initiates a crawl job for a URL using the Firecrawl API.
319
180
  * @param url - The URL to crawl.
320
181
  * @param params - Additional parameters for the crawl request.
321
- * @param waitUntilDone - Whether to wait for the crawl job to complete.
322
182
  * @param pollInterval - Time in seconds for job status checks.
323
183
  * @param idempotencyKey - Optional idempotency key for the request.
324
184
  * @returns The response from the crawl operation.
325
185
  */
326
- crawlUrl(url: string, params?: this['version'] extends 'v0' ? CrawlParamsV0 : CrawlParams, waitUntilDone?: boolean, pollInterval?: number, idempotencyKey?: string): Promise<this['version'] extends 'v0' ? CrawlResponseV0 | CrawlStatusResponseV0 | FirecrawlDocumentV0[] : CrawlResponse | CrawlStatusResponse>;
186
+ crawlUrl(url: string, params?: CrawlParams, pollInterval?: number, idempotencyKey?: string): Promise<CrawlStatusResponse | ErrorResponse>;
187
+ asyncCrawlUrl(url: string, params?: CrawlParams, idempotencyKey?: string): Promise<CrawlResponse | ErrorResponse>;
327
188
  /**
328
189
  * Checks the status of a crawl job using the Firecrawl API.
329
190
  * @param id - The ID of the crawl operation.
330
191
  * @returns The response containing the job status.
331
192
  */
332
- checkCrawlStatus(id?: string): Promise<this['version'] extends 'v0' ? CrawlStatusResponseV0 : CrawlStatusResponse>;
333
- mapUrl(url: string, params?: MapParams): Promise<MapResponse>;
193
+ checkCrawlStatus(id?: string): Promise<CrawlStatusResponse | ErrorResponse>;
194
+ crawlUrlAndWatch(url: string, params?: CrawlParams, idempotencyKey?: string): Promise<CrawlWatcher>;
195
+ mapUrl(url: string, params?: MapParams): Promise<MapResponse | ErrorResponse>;
334
196
  /**
335
197
  * Prepares the headers for an API request.
336
198
  * @param idempotencyKey - Optional key to ensure idempotency.
@@ -360,7 +222,7 @@ export default class FirecrawlApp<T extends "v0" | "v1"> {
360
222
  * @param checkUrl - Optional URL to check the status (used for v1 API)
361
223
  * @returns The final job status or data.
362
224
  */
363
- monitorJobStatus(id: string, headers: AxiosRequestHeaders, checkInterval: number, checkUrl?: string): Promise<this['version'] extends 'v0' ? CrawlStatusResponseV0 | FirecrawlDocumentV0[] : CrawlStatusResponse>;
225
+ monitorJobStatus(id: string, headers: AxiosRequestHeaders, checkInterval: number): Promise<CrawlStatusResponse>;
364
226
  /**
365
227
  * Handles errors from API responses.
366
228
  * @param {AxiosResponse} response - The response from the API.
@@ -368,3 +230,23 @@ export default class FirecrawlApp<T extends "v0" | "v1"> {
368
230
  */
369
231
  handleError(response: AxiosResponse, action: string): void;
370
232
  }
233
+ interface CrawlWatcherEvents {
234
+ document: CustomEvent<FirecrawlDocument>;
235
+ done: CustomEvent<{
236
+ status: CrawlStatusResponse["status"];
237
+ data: FirecrawlDocument[];
238
+ }>;
239
+ error: CustomEvent<{
240
+ status: CrawlStatusResponse["status"];
241
+ data: FirecrawlDocument[];
242
+ error: string;
243
+ }>;
244
+ }
245
+ export declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
246
+ private ws;
247
+ data: FirecrawlDocument[];
248
+ status: CrawlStatusResponse["status"];
249
+ constructor(id: string, app: FirecrawlApp);
250
+ close(): void;
251
+ }
252
+ export {};