firecrawl 1.2.0 → 1.3.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/dist/index.cjs ADDED
@@ -0,0 +1,410 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ CrawlWatcher: () => CrawlWatcher,
34
+ default: () => FirecrawlApp
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+ var import_axios = __toESM(require("axios"), 1);
38
+ var import_zod_to_json_schema = require("zod-to-json-schema");
39
+ var import_isows = require("isows");
40
+ var import_typescript_event_target = require("typescript-event-target");
41
+ var FirecrawlApp = class {
42
+ apiKey;
43
+ apiUrl;
44
+ /**
45
+ * Initializes a new instance of the FirecrawlApp class.
46
+ * @param config - Configuration options for the FirecrawlApp instance.
47
+ */
48
+ constructor({ apiKey = null, apiUrl = null }) {
49
+ if (typeof apiKey !== "string") {
50
+ throw new Error("No API key provided");
51
+ }
52
+ this.apiKey = apiKey;
53
+ this.apiUrl = apiUrl || "https://api.firecrawl.dev";
54
+ }
55
+ /**
56
+ * Scrapes a URL using the Firecrawl API.
57
+ * @param url - The URL to scrape.
58
+ * @param params - Additional parameters for the scrape request.
59
+ * @returns The response from the scrape operation.
60
+ */
61
+ async scrapeUrl(url, params) {
62
+ const headers = {
63
+ "Content-Type": "application/json",
64
+ Authorization: `Bearer ${this.apiKey}`
65
+ };
66
+ let jsonData = { url, ...params };
67
+ if (jsonData?.extract?.schema) {
68
+ let schema = jsonData.extract.schema;
69
+ try {
70
+ schema = (0, import_zod_to_json_schema.zodToJsonSchema)(schema);
71
+ } catch (error) {
72
+ }
73
+ jsonData = {
74
+ ...jsonData,
75
+ extract: {
76
+ ...jsonData.extract,
77
+ schema
78
+ }
79
+ };
80
+ }
81
+ try {
82
+ const response = await import_axios.default.post(
83
+ this.apiUrl + `/v1/scrape`,
84
+ jsonData,
85
+ { headers }
86
+ );
87
+ if (response.status === 200) {
88
+ const responseData = response.data;
89
+ if (responseData.success) {
90
+ return {
91
+ success: true,
92
+ warning: responseData.warning,
93
+ error: responseData.error,
94
+ ...responseData.data
95
+ };
96
+ } else {
97
+ throw new Error(`Failed to scrape URL. Error: ${responseData.error}`);
98
+ }
99
+ } else {
100
+ this.handleError(response, "scrape URL");
101
+ }
102
+ } catch (error) {
103
+ throw new Error(error.message);
104
+ }
105
+ return { success: false, error: "Internal server error." };
106
+ }
107
+ /**
108
+ * This method is intended to search for a query using the Firecrawl API. However, it is not supported in version 1 of the API.
109
+ * @param query - The search query string.
110
+ * @param params - Additional parameters for the search.
111
+ * @returns Throws an error advising to use version 0 of the API.
112
+ */
113
+ async search(query, params) {
114
+ throw new Error("Search is not supported in v1, please update FirecrawlApp() initialization to use v0.");
115
+ }
116
+ /**
117
+ * Initiates a crawl job for a URL using the Firecrawl API.
118
+ * @param url - The URL to crawl.
119
+ * @param params - Additional parameters for the crawl request.
120
+ * @param pollInterval - Time in seconds for job status checks.
121
+ * @param idempotencyKey - Optional idempotency key for the request.
122
+ * @returns The response from the crawl operation.
123
+ */
124
+ async crawlUrl(url, params, pollInterval = 2, idempotencyKey) {
125
+ const headers = this.prepareHeaders(idempotencyKey);
126
+ let jsonData = { url, ...params };
127
+ try {
128
+ const response = await this.postRequest(
129
+ this.apiUrl + `/v1/crawl`,
130
+ jsonData,
131
+ headers
132
+ );
133
+ if (response.status === 200) {
134
+ const id = response.data.id;
135
+ return this.monitorJobStatus(id, headers, pollInterval);
136
+ } else {
137
+ this.handleError(response, "start crawl job");
138
+ }
139
+ } catch (error) {
140
+ if (error.response?.data?.error) {
141
+ throw new Error(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`);
142
+ } else {
143
+ throw new Error(error.message);
144
+ }
145
+ }
146
+ return { success: false, error: "Internal server error." };
147
+ }
148
+ async asyncCrawlUrl(url, params, idempotencyKey) {
149
+ const headers = this.prepareHeaders(idempotencyKey);
150
+ let jsonData = { url, ...params };
151
+ try {
152
+ const response = await this.postRequest(
153
+ this.apiUrl + `/v1/crawl`,
154
+ jsonData,
155
+ headers
156
+ );
157
+ if (response.status === 200) {
158
+ return response.data;
159
+ } else {
160
+ this.handleError(response, "start crawl job");
161
+ }
162
+ } catch (error) {
163
+ if (error.response?.data?.error) {
164
+ throw new Error(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`);
165
+ } else {
166
+ throw new Error(error.message);
167
+ }
168
+ }
169
+ return { success: false, error: "Internal server error." };
170
+ }
171
+ /**
172
+ * Checks the status of a crawl job using the Firecrawl API.
173
+ * @param id - The ID of the crawl operation.
174
+ * @param getAllData - Paginate through all the pages of documents, returning the full list of all documents. (default: `false`)
175
+ * @returns The response containing the job status.
176
+ */
177
+ async checkCrawlStatus(id, getAllData = false) {
178
+ if (!id) {
179
+ throw new Error("No crawl ID provided");
180
+ }
181
+ const headers = this.prepareHeaders();
182
+ try {
183
+ const response = await this.getRequest(
184
+ `${this.apiUrl}/v1/crawl/${id}`,
185
+ headers
186
+ );
187
+ if (response.status === 200) {
188
+ let allData = response.data.data;
189
+ if (getAllData && response.data.status === "completed") {
190
+ let statusData = response.data;
191
+ if ("data" in statusData) {
192
+ let data = statusData.data;
193
+ while ("next" in statusData) {
194
+ statusData = (await this.getRequest(statusData.next, headers)).data;
195
+ data = data.concat(statusData.data);
196
+ }
197
+ allData = data;
198
+ }
199
+ }
200
+ return {
201
+ success: response.data.success,
202
+ status: response.data.status,
203
+ total: response.data.total,
204
+ completed: response.data.completed,
205
+ creditsUsed: response.data.creditsUsed,
206
+ expiresAt: new Date(response.data.expiresAt),
207
+ next: response.data.next,
208
+ data: allData,
209
+ error: response.data.error
210
+ };
211
+ } else {
212
+ this.handleError(response, "check crawl status");
213
+ }
214
+ } catch (error) {
215
+ throw new Error(error.message);
216
+ }
217
+ return { success: false, error: "Internal server error." };
218
+ }
219
+ async crawlUrlAndWatch(url, params, idempotencyKey) {
220
+ const crawl = await this.asyncCrawlUrl(url, params, idempotencyKey);
221
+ if (crawl.success && crawl.id) {
222
+ const id = crawl.id;
223
+ return new CrawlWatcher(id, this);
224
+ }
225
+ throw new Error("Crawl job failed to start");
226
+ }
227
+ async mapUrl(url, params) {
228
+ const headers = this.prepareHeaders();
229
+ let jsonData = { url, ...params };
230
+ try {
231
+ const response = await this.postRequest(
232
+ this.apiUrl + `/v1/map`,
233
+ jsonData,
234
+ headers
235
+ );
236
+ if (response.status === 200) {
237
+ return response.data;
238
+ } else {
239
+ this.handleError(response, "map");
240
+ }
241
+ } catch (error) {
242
+ throw new Error(error.message);
243
+ }
244
+ return { success: false, error: "Internal server error." };
245
+ }
246
+ /**
247
+ * Prepares the headers for an API request.
248
+ * @param idempotencyKey - Optional key to ensure idempotency.
249
+ * @returns The prepared headers.
250
+ */
251
+ prepareHeaders(idempotencyKey) {
252
+ return {
253
+ "Content-Type": "application/json",
254
+ Authorization: `Bearer ${this.apiKey}`,
255
+ ...idempotencyKey ? { "x-idempotency-key": idempotencyKey } : {}
256
+ };
257
+ }
258
+ /**
259
+ * Sends a POST request to the specified URL.
260
+ * @param url - The URL to send the request to.
261
+ * @param data - The data to send in the request.
262
+ * @param headers - The headers for the request.
263
+ * @returns The response from the POST request.
264
+ */
265
+ postRequest(url, data, headers) {
266
+ return import_axios.default.post(url, data, { headers });
267
+ }
268
+ /**
269
+ * Sends a GET request to the specified URL.
270
+ * @param url - The URL to send the request to.
271
+ * @param headers - The headers for the request.
272
+ * @returns The response from the GET request.
273
+ */
274
+ getRequest(url, headers) {
275
+ return import_axios.default.get(url, { headers });
276
+ }
277
+ /**
278
+ * Monitors the status of a crawl job until completion or failure.
279
+ * @param id - The ID of the crawl operation.
280
+ * @param headers - The headers for the request.
281
+ * @param checkInterval - Interval in seconds for job status checks.
282
+ * @param checkUrl - Optional URL to check the status (used for v1 API)
283
+ * @returns The final job status or data.
284
+ */
285
+ async monitorJobStatus(id, headers, checkInterval) {
286
+ while (true) {
287
+ let statusResponse = await this.getRequest(
288
+ `${this.apiUrl}/v1/crawl/${id}`,
289
+ headers
290
+ );
291
+ if (statusResponse.status === 200) {
292
+ let statusData = statusResponse.data;
293
+ if (statusData.status === "completed") {
294
+ if ("data" in statusData) {
295
+ let data = statusData.data;
296
+ while ("next" in statusData) {
297
+ statusResponse = await this.getRequest(statusData.next, headers);
298
+ statusData = statusResponse.data;
299
+ data = data.concat(statusData.data);
300
+ }
301
+ statusData.data = data;
302
+ return statusData;
303
+ } else {
304
+ throw new Error("Crawl job completed but no data was returned");
305
+ }
306
+ } else if (["active", "paused", "pending", "queued", "waiting", "scraping"].includes(statusData.status)) {
307
+ checkInterval = Math.max(checkInterval, 2);
308
+ await new Promise(
309
+ (resolve) => setTimeout(resolve, checkInterval * 1e3)
310
+ );
311
+ } else {
312
+ throw new Error(
313
+ `Crawl job failed or was stopped. Status: ${statusData.status}`
314
+ );
315
+ }
316
+ } else {
317
+ this.handleError(statusResponse, "check crawl status");
318
+ }
319
+ }
320
+ }
321
+ /**
322
+ * Handles errors from API responses.
323
+ * @param {AxiosResponse} response - The response from the API.
324
+ * @param {string} action - The action being performed when the error occurred.
325
+ */
326
+ handleError(response, action) {
327
+ if ([402, 408, 409, 500].includes(response.status)) {
328
+ const errorMessage = response.data.error || "Unknown error occurred";
329
+ throw new Error(
330
+ `Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}`
331
+ );
332
+ } else {
333
+ throw new Error(
334
+ `Unexpected error occurred while trying to ${action}. Status code: ${response.status}`
335
+ );
336
+ }
337
+ }
338
+ };
339
+ var CrawlWatcher = class extends import_typescript_event_target.TypedEventTarget {
340
+ ws;
341
+ data;
342
+ status;
343
+ constructor(id, app) {
344
+ super();
345
+ this.ws = new import_isows.WebSocket(`${app.apiUrl}/v1/crawl/${id}`, app.apiKey);
346
+ this.status = "scraping";
347
+ this.data = [];
348
+ const messageHandler = (msg) => {
349
+ if (msg.type === "done") {
350
+ this.status = "completed";
351
+ this.dispatchTypedEvent("done", new CustomEvent("done", {
352
+ detail: {
353
+ status: this.status,
354
+ data: this.data
355
+ }
356
+ }));
357
+ } else if (msg.type === "error") {
358
+ this.status = "failed";
359
+ this.dispatchTypedEvent("error", new CustomEvent("error", {
360
+ detail: {
361
+ status: this.status,
362
+ data: this.data,
363
+ error: msg.error
364
+ }
365
+ }));
366
+ } else if (msg.type === "catchup") {
367
+ this.status = msg.data.status;
368
+ this.data.push(...msg.data.data ?? []);
369
+ for (const doc of this.data) {
370
+ this.dispatchTypedEvent("document", new CustomEvent("document", {
371
+ detail: doc
372
+ }));
373
+ }
374
+ } else if (msg.type === "document") {
375
+ this.dispatchTypedEvent("document", new CustomEvent("document", {
376
+ detail: msg.data
377
+ }));
378
+ }
379
+ };
380
+ this.ws.onmessage = ((ev) => {
381
+ if (typeof ev.data !== "string") {
382
+ this.ws.close();
383
+ return;
384
+ }
385
+ const msg = JSON.parse(ev.data);
386
+ messageHandler(msg);
387
+ }).bind(this);
388
+ this.ws.onclose = ((ev) => {
389
+ const msg = JSON.parse(ev.reason);
390
+ messageHandler(msg);
391
+ }).bind(this);
392
+ this.ws.onerror = ((_) => {
393
+ this.status = "failed";
394
+ this.dispatchTypedEvent("error", new CustomEvent("error", {
395
+ detail: {
396
+ status: this.status,
397
+ data: this.data,
398
+ error: "WebSocket error"
399
+ }
400
+ }));
401
+ }).bind(this);
402
+ }
403
+ close() {
404
+ this.ws.close();
405
+ }
406
+ };
407
+ // Annotate the CommonJS export names for ESM import in node:
408
+ 0 && (module.exports = {
409
+ CrawlWatcher
410
+ });
@@ -0,0 +1,262 @@
1
+ import { AxiosRequestHeaders, AxiosResponse } from 'axios';
2
+ import { ZodSchema } from 'zod';
3
+ import { TypedEventTarget } from 'typescript-event-target';
4
+
5
+ /**
6
+ * Configuration interface for FirecrawlApp.
7
+ * @param apiKey - Optional API key for authentication.
8
+ * @param apiUrl - Optional base URL of the API; defaults to 'https://api.firecrawl.dev'.
9
+ */
10
+ interface FirecrawlAppConfig {
11
+ apiKey?: string | null;
12
+ apiUrl?: string | null;
13
+ }
14
+ /**
15
+ * Metadata for a Firecrawl document.
16
+ * Includes various optional properties for document metadata.
17
+ */
18
+ interface FirecrawlDocumentMetadata {
19
+ title?: string;
20
+ description?: string;
21
+ language?: string;
22
+ keywords?: string;
23
+ robots?: string;
24
+ ogTitle?: string;
25
+ ogDescription?: string;
26
+ ogUrl?: string;
27
+ ogImage?: string;
28
+ ogAudio?: string;
29
+ ogDeterminer?: string;
30
+ ogLocale?: string;
31
+ ogLocaleAlternate?: string[];
32
+ ogSiteName?: string;
33
+ ogVideo?: string;
34
+ dctermsCreated?: string;
35
+ dcDateCreated?: string;
36
+ dcDate?: string;
37
+ dctermsType?: string;
38
+ dcType?: string;
39
+ dctermsAudience?: string;
40
+ dctermsSubject?: string;
41
+ dcSubject?: string;
42
+ dcDescription?: string;
43
+ dctermsKeywords?: string;
44
+ modifiedTime?: string;
45
+ publishedTime?: string;
46
+ articleTag?: string;
47
+ articleSection?: string;
48
+ sourceURL?: string;
49
+ statusCode?: number;
50
+ error?: string;
51
+ [key: string]: any;
52
+ }
53
+ /**
54
+ * Document interface for Firecrawl.
55
+ * Represents a document retrieved or processed by Firecrawl.
56
+ */
57
+ interface FirecrawlDocument {
58
+ url?: string;
59
+ markdown?: string;
60
+ html?: string;
61
+ rawHtml?: string;
62
+ links?: string[];
63
+ extract?: Record<any, any>;
64
+ screenshot?: string;
65
+ metadata?: FirecrawlDocumentMetadata;
66
+ }
67
+ /**
68
+ * Parameters for scraping operations.
69
+ * Defines the options and configurations available for scraping web content.
70
+ */
71
+ interface ScrapeParams {
72
+ formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "extract" | "full@scrennshot")[];
73
+ headers?: Record<string, string>;
74
+ includeTags?: string[];
75
+ excludeTags?: string[];
76
+ onlyMainContent?: boolean;
77
+ extract?: {
78
+ prompt?: string;
79
+ schema?: ZodSchema | any;
80
+ systemPrompt?: string;
81
+ };
82
+ waitFor?: number;
83
+ timeout?: number;
84
+ }
85
+ /**
86
+ * Response interface for scraping operations.
87
+ * Defines the structure of the response received after a scraping operation.
88
+ */
89
+ interface ScrapeResponse extends FirecrawlDocument {
90
+ success: true;
91
+ warning?: string;
92
+ error?: string;
93
+ }
94
+ /**
95
+ * Parameters for crawling operations.
96
+ * Includes options for both scraping and mapping during a crawl.
97
+ */
98
+ interface CrawlParams {
99
+ includePaths?: string[];
100
+ excludePaths?: string[];
101
+ maxDepth?: number;
102
+ limit?: number;
103
+ allowBackwardLinks?: boolean;
104
+ allowExternalLinks?: boolean;
105
+ ignoreSitemap?: boolean;
106
+ scrapeOptions?: ScrapeParams;
107
+ webhook?: string;
108
+ }
109
+ /**
110
+ * Response interface for crawling operations.
111
+ * Defines the structure of the response received after initiating a crawl.
112
+ */
113
+ interface CrawlResponse {
114
+ id?: string;
115
+ url?: string;
116
+ success: true;
117
+ error?: string;
118
+ }
119
+ /**
120
+ * Response interface for job status checks.
121
+ * Provides detailed status of a crawl job including progress and results.
122
+ */
123
+ interface CrawlStatusResponse {
124
+ success: true;
125
+ status: "scraping" | "completed" | "failed" | "cancelled";
126
+ completed: number;
127
+ total: number;
128
+ creditsUsed: number;
129
+ expiresAt: Date;
130
+ next?: string;
131
+ data: FirecrawlDocument[];
132
+ }
133
+ /**
134
+ * Parameters for mapping operations.
135
+ * Defines options for mapping URLs during a crawl.
136
+ */
137
+ interface MapParams {
138
+ search?: string;
139
+ ignoreSitemap?: boolean;
140
+ includeSubdomains?: boolean;
141
+ limit?: number;
142
+ }
143
+ /**
144
+ * Response interface for mapping operations.
145
+ * Defines the structure of the response received after a mapping operation.
146
+ */
147
+ interface MapResponse {
148
+ success: true;
149
+ links?: string[];
150
+ error?: string;
151
+ }
152
+ /**
153
+ * Error response interface.
154
+ * Defines the structure of the response received when an error occurs.
155
+ */
156
+ interface ErrorResponse {
157
+ success: false;
158
+ error: string;
159
+ }
160
+ /**
161
+ * Main class for interacting with the Firecrawl API.
162
+ * Provides methods for scraping, searching, crawling, and mapping web content.
163
+ */
164
+ declare class FirecrawlApp {
165
+ apiKey: string;
166
+ apiUrl: string;
167
+ /**
168
+ * Initializes a new instance of the FirecrawlApp class.
169
+ * @param config - Configuration options for the FirecrawlApp instance.
170
+ */
171
+ constructor({ apiKey, apiUrl }: FirecrawlAppConfig);
172
+ /**
173
+ * Scrapes a URL using the Firecrawl API.
174
+ * @param url - The URL to scrape.
175
+ * @param params - Additional parameters for the scrape request.
176
+ * @returns The response from the scrape operation.
177
+ */
178
+ scrapeUrl(url: string, params?: ScrapeParams): Promise<ScrapeResponse | ErrorResponse>;
179
+ /**
180
+ * This method is intended to search for a query using the Firecrawl API. However, it is not supported in version 1 of the API.
181
+ * @param query - The search query string.
182
+ * @param params - Additional parameters for the search.
183
+ * @returns Throws an error advising to use version 0 of the API.
184
+ */
185
+ search(query: string, params?: any): Promise<any>;
186
+ /**
187
+ * Initiates a crawl job for a URL using the Firecrawl API.
188
+ * @param url - The URL to crawl.
189
+ * @param params - Additional parameters for the crawl request.
190
+ * @param pollInterval - Time in seconds for job status checks.
191
+ * @param idempotencyKey - Optional idempotency key for the request.
192
+ * @returns The response from the crawl operation.
193
+ */
194
+ crawlUrl(url: string, params?: CrawlParams, pollInterval?: number, idempotencyKey?: string): Promise<CrawlStatusResponse | ErrorResponse>;
195
+ asyncCrawlUrl(url: string, params?: CrawlParams, idempotencyKey?: string): Promise<CrawlResponse | ErrorResponse>;
196
+ /**
197
+ * Checks the status of a crawl job using the Firecrawl API.
198
+ * @param id - The ID of the crawl operation.
199
+ * @param getAllData - Paginate through all the pages of documents, returning the full list of all documents. (default: `false`)
200
+ * @returns The response containing the job status.
201
+ */
202
+ checkCrawlStatus(id?: string, getAllData?: boolean): Promise<CrawlStatusResponse | ErrorResponse>;
203
+ crawlUrlAndWatch(url: string, params?: CrawlParams, idempotencyKey?: string): Promise<CrawlWatcher>;
204
+ mapUrl(url: string, params?: MapParams): Promise<MapResponse | ErrorResponse>;
205
+ /**
206
+ * Prepares the headers for an API request.
207
+ * @param idempotencyKey - Optional key to ensure idempotency.
208
+ * @returns The prepared headers.
209
+ */
210
+ prepareHeaders(idempotencyKey?: string): AxiosRequestHeaders;
211
+ /**
212
+ * Sends a POST request to the specified URL.
213
+ * @param url - The URL to send the request to.
214
+ * @param data - The data to send in the request.
215
+ * @param headers - The headers for the request.
216
+ * @returns The response from the POST request.
217
+ */
218
+ postRequest(url: string, data: any, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
219
+ /**
220
+ * Sends a GET request to the specified URL.
221
+ * @param url - The URL to send the request to.
222
+ * @param headers - The headers for the request.
223
+ * @returns The response from the GET request.
224
+ */
225
+ getRequest(url: string, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
226
+ /**
227
+ * Monitors the status of a crawl job until completion or failure.
228
+ * @param id - The ID of the crawl operation.
229
+ * @param headers - The headers for the request.
230
+ * @param checkInterval - Interval in seconds for job status checks.
231
+ * @param checkUrl - Optional URL to check the status (used for v1 API)
232
+ * @returns The final job status or data.
233
+ */
234
+ monitorJobStatus(id: string, headers: AxiosRequestHeaders, checkInterval: number): Promise<CrawlStatusResponse | ErrorResponse>;
235
+ /**
236
+ * Handles errors from API responses.
237
+ * @param {AxiosResponse} response - The response from the API.
238
+ * @param {string} action - The action being performed when the error occurred.
239
+ */
240
+ handleError(response: AxiosResponse, action: string): void;
241
+ }
242
+ interface CrawlWatcherEvents {
243
+ document: CustomEvent<FirecrawlDocument>;
244
+ done: CustomEvent<{
245
+ status: CrawlStatusResponse["status"];
246
+ data: FirecrawlDocument[];
247
+ }>;
248
+ error: CustomEvent<{
249
+ status: CrawlStatusResponse["status"];
250
+ data: FirecrawlDocument[];
251
+ error: string;
252
+ }>;
253
+ }
254
+ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
255
+ private ws;
256
+ data: FirecrawlDocument[];
257
+ status: CrawlStatusResponse["status"];
258
+ constructor(id: string, app: FirecrawlApp);
259
+ close(): void;
260
+ }
261
+
262
+ export { type CrawlParams, type CrawlResponse, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };