@mendable/firecrawl-js 1.0.4 → 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,21 +122,6 @@ 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.
@@ -256,78 +137,62 @@ export interface MapParams {
256
137
  * Defines the structure of the response received after a mapping operation.
257
138
  */
258
139
  export interface MapResponse {
259
- success: boolean;
140
+ success: true;
260
141
  links?: string[];
261
142
  error?: string;
262
143
  }
263
144
  /**
264
- * Parameters for searching operations on v0.
265
- * 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.
266
147
  */
267
- export interface SearchParamsV0 {
268
- pageOptions?: {
269
- onlyMainContent?: boolean;
270
- fetchPageContent?: boolean;
271
- includeHtml?: boolean;
272
- includeRawHtml?: boolean;
273
- };
274
- searchOptions?: {
275
- limit?: number;
276
- };
277
- }
278
- /**
279
- * Response interface for searching operations on v0.
280
- * Defines the structure of the response received after a search operation on v0.
281
- */
282
- export interface SearchResponseV0 {
283
- success: boolean;
284
- data?: FirecrawlDocumentV0[];
285
- error?: string;
148
+ export interface ErrorResponse {
149
+ success: false;
150
+ error: string;
286
151
  }
287
152
  /**
288
153
  * Main class for interacting with the Firecrawl API.
289
154
  * Provides methods for scraping, searching, crawling, and mapping web content.
290
155
  */
291
- export default class FirecrawlApp<T extends "v0" | "v1"> {
292
- private apiKey;
293
- private apiUrl;
294
- version: T;
156
+ export default class FirecrawlApp {
157
+ apiKey: string;
158
+ apiUrl: string;
295
159
  /**
296
160
  * Initializes a new instance of the FirecrawlApp class.
297
161
  * @param config - Configuration options for the FirecrawlApp instance.
298
162
  */
299
- constructor({ apiKey, apiUrl, version }: FirecrawlAppConfig);
163
+ constructor({ apiKey, apiUrl }: FirecrawlAppConfig);
300
164
  /**
301
165
  * Scrapes a URL using the Firecrawl API.
302
166
  * @param url - The URL to scrape.
303
167
  * @param params - Additional parameters for the scrape request.
304
168
  * @returns The response from the scrape operation.
305
169
  */
306
- scrapeUrl(url: string, params?: ScrapeParams | ScrapeParamsV0): Promise<this['version'] extends 'v0' ? ScrapeResponseV0 : ScrapeResponse>;
170
+ scrapeUrl(url: string, params?: ScrapeParams): Promise<ScrapeResponse | ErrorResponse>;
307
171
  /**
308
- * Searches for a query using the Firecrawl API.
309
- * @param query - The query to search for.
310
- * @param params - Additional parameters for the search request.
311
- * @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.
312
176
  */
313
- search(query: string, params?: SearchParamsV0): Promise<SearchResponseV0>;
177
+ search(query: string, params?: any): Promise<any>;
314
178
  /**
315
179
  * Initiates a crawl job for a URL using the Firecrawl API.
316
180
  * @param url - The URL to crawl.
317
181
  * @param params - Additional parameters for the crawl request.
318
- * @param waitUntilDone - Whether to wait for the crawl job to complete.
319
182
  * @param pollInterval - Time in seconds for job status checks.
320
183
  * @param idempotencyKey - Optional idempotency key for the request.
321
184
  * @returns The response from the crawl operation.
322
185
  */
323
- 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>;
324
188
  /**
325
189
  * Checks the status of a crawl job using the Firecrawl API.
326
190
  * @param id - The ID of the crawl operation.
327
191
  * @returns The response containing the job status.
328
192
  */
329
- checkCrawlStatus(id?: string): Promise<this['version'] extends 'v0' ? CrawlStatusResponseV0 : CrawlStatusResponse>;
330
- 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>;
331
196
  /**
332
197
  * Prepares the headers for an API request.
333
198
  * @param idempotencyKey - Optional key to ensure idempotency.
@@ -357,7 +222,7 @@ export default class FirecrawlApp<T extends "v0" | "v1"> {
357
222
  * @param checkUrl - Optional URL to check the status (used for v1 API)
358
223
  * @returns The final job status or data.
359
224
  */
360
- 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>;
361
226
  /**
362
227
  * Handles errors from API responses.
363
228
  * @param {AxiosResponse} response - The response from the API.
@@ -365,3 +230,23 @@ export default class FirecrawlApp<T extends "v0" | "v1"> {
365
230
  */
366
231
  handleError(response: AxiosResponse, action: string): void;
367
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 {};