@mendable/firecrawl-js 1.18.0-beta.8 → 1.18.1
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 +22 -286
- package/dist/index.d.cts +5 -148
- package/dist/index.d.ts +5 -148
- package/dist/index.js +22 -286
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/dump.rdb +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -61,7 +61,6 @@ interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult | neve
|
|
|
61
61
|
rawHtml?: string;
|
|
62
62
|
links?: string[];
|
|
63
63
|
extract?: T;
|
|
64
|
-
json?: T;
|
|
65
64
|
screenshot?: string;
|
|
66
65
|
metadata?: FirecrawlDocumentMetadata;
|
|
67
66
|
actions: ActionsSchema;
|
|
@@ -73,7 +72,7 @@ interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult | neve
|
|
|
73
72
|
* Defines the options and configurations available for scraping web content.
|
|
74
73
|
*/
|
|
75
74
|
interface CrawlScrapeOptions {
|
|
76
|
-
formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract"
|
|
75
|
+
formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract")[];
|
|
77
76
|
headers?: Record<string, string>;
|
|
78
77
|
includeTags?: string[];
|
|
79
78
|
excludeTags?: string[];
|
|
@@ -87,7 +86,6 @@ interface CrawlScrapeOptions {
|
|
|
87
86
|
mobile?: boolean;
|
|
88
87
|
skipTlsVerification?: boolean;
|
|
89
88
|
removeBase64Images?: boolean;
|
|
90
|
-
blockAds?: boolean;
|
|
91
89
|
}
|
|
92
90
|
type Action = {
|
|
93
91
|
type: "wait";
|
|
@@ -121,11 +119,6 @@ interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchema exten
|
|
|
121
119
|
schema?: LLMSchema;
|
|
122
120
|
systemPrompt?: string;
|
|
123
121
|
};
|
|
124
|
-
jsonOptions?: {
|
|
125
|
-
prompt?: string;
|
|
126
|
-
schema?: LLMSchema;
|
|
127
|
-
systemPrompt?: string;
|
|
128
|
-
};
|
|
129
122
|
actions?: ActionsSchema;
|
|
130
123
|
}
|
|
131
124
|
interface ActionsResult {
|
|
@@ -157,7 +150,6 @@ interface CrawlParams {
|
|
|
157
150
|
url: string;
|
|
158
151
|
headers?: Record<string, string>;
|
|
159
152
|
metadata?: Record<string, string>;
|
|
160
|
-
events?: ["completed", "failed", "page", "started"][number][];
|
|
161
153
|
};
|
|
162
154
|
deduplicateSimilarURLs?: boolean;
|
|
163
155
|
ignoreQueryParameters?: boolean;
|
|
@@ -221,7 +213,6 @@ interface MapParams {
|
|
|
221
213
|
includeSubdomains?: boolean;
|
|
222
214
|
sitemapOnly?: boolean;
|
|
223
215
|
limit?: number;
|
|
224
|
-
timeout?: number;
|
|
225
216
|
}
|
|
226
217
|
/**
|
|
227
218
|
* Response interface for mapping operations.
|
|
@@ -241,10 +232,7 @@ interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
|
|
|
241
232
|
schema?: LLMSchema | object;
|
|
242
233
|
systemPrompt?: string;
|
|
243
234
|
allowExternalLinks?: boolean;
|
|
244
|
-
enableWebSearch?: boolean;
|
|
245
235
|
includeSubdomains?: boolean;
|
|
246
|
-
origin?: string;
|
|
247
|
-
showSources?: boolean;
|
|
248
236
|
}
|
|
249
237
|
/**
|
|
250
238
|
* Response interface for extracting information from URLs.
|
|
@@ -255,7 +243,6 @@ interface ExtractResponse<LLMSchema extends zt.ZodSchema = any> {
|
|
|
255
243
|
data: LLMSchema;
|
|
256
244
|
error?: string;
|
|
257
245
|
warning?: string;
|
|
258
|
-
sources?: string[];
|
|
259
246
|
}
|
|
260
247
|
/**
|
|
261
248
|
* Error response interface.
|
|
@@ -271,8 +258,7 @@ interface ErrorResponse {
|
|
|
271
258
|
*/
|
|
272
259
|
declare class FirecrawlError extends Error {
|
|
273
260
|
statusCode: number;
|
|
274
|
-
|
|
275
|
-
constructor(message: string, statusCode: number, details?: any);
|
|
261
|
+
constructor(message: string, statusCode: number);
|
|
276
262
|
}
|
|
277
263
|
/**
|
|
278
264
|
* Parameters for search operations.
|
|
@@ -299,85 +285,6 @@ interface SearchResponse {
|
|
|
299
285
|
warning?: string;
|
|
300
286
|
error?: string;
|
|
301
287
|
}
|
|
302
|
-
/**
|
|
303
|
-
* Response interface for crawl/batch scrape error monitoring.
|
|
304
|
-
*/
|
|
305
|
-
interface CrawlErrorsResponse {
|
|
306
|
-
/**
|
|
307
|
-
* Scrapes that errored out + error details
|
|
308
|
-
*/
|
|
309
|
-
errors: {
|
|
310
|
-
id: string;
|
|
311
|
-
timestamp?: string;
|
|
312
|
-
url: string;
|
|
313
|
-
error: string;
|
|
314
|
-
}[];
|
|
315
|
-
/**
|
|
316
|
-
* URLs blocked by robots.txt
|
|
317
|
-
*/
|
|
318
|
-
robotsBlocked: string[];
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Parameters for deep research operations.
|
|
322
|
-
* Defines options for conducting deep research on a topic.
|
|
323
|
-
*/
|
|
324
|
-
interface DeepResearchParams {
|
|
325
|
-
/**
|
|
326
|
-
* Maximum depth of research iterations (1-10)
|
|
327
|
-
* @default 7
|
|
328
|
-
*/
|
|
329
|
-
maxDepth?: number;
|
|
330
|
-
/**
|
|
331
|
-
* Time limit in seconds (30-300)
|
|
332
|
-
* @default 270
|
|
333
|
-
*/
|
|
334
|
-
timeLimit?: number;
|
|
335
|
-
/**
|
|
336
|
-
* Experimental flag for streaming steps
|
|
337
|
-
*/
|
|
338
|
-
__experimental_streamSteps?: boolean;
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Response interface for deep research operations.
|
|
342
|
-
*/
|
|
343
|
-
interface DeepResearchResponse {
|
|
344
|
-
success: boolean;
|
|
345
|
-
id: string;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Status response interface for deep research operations.
|
|
349
|
-
*/
|
|
350
|
-
interface DeepResearchStatusResponse {
|
|
351
|
-
success: boolean;
|
|
352
|
-
data: {
|
|
353
|
-
findings: Array<{
|
|
354
|
-
text: string;
|
|
355
|
-
source: string;
|
|
356
|
-
}>;
|
|
357
|
-
finalAnalysis: string;
|
|
358
|
-
analysis: string;
|
|
359
|
-
completedSteps: number;
|
|
360
|
-
totalSteps: number;
|
|
361
|
-
};
|
|
362
|
-
status: "processing" | "completed" | "failed";
|
|
363
|
-
error?: string;
|
|
364
|
-
expiresAt: string;
|
|
365
|
-
currentDepth: number;
|
|
366
|
-
maxDepth: number;
|
|
367
|
-
activities: Array<{
|
|
368
|
-
type: string;
|
|
369
|
-
status: string;
|
|
370
|
-
message: string;
|
|
371
|
-
timestamp: string;
|
|
372
|
-
depth: number;
|
|
373
|
-
}>;
|
|
374
|
-
sources: Array<{
|
|
375
|
-
url: string;
|
|
376
|
-
title: string;
|
|
377
|
-
description: string;
|
|
378
|
-
}>;
|
|
379
|
-
summaries: string[];
|
|
380
|
-
}
|
|
381
288
|
/**
|
|
382
289
|
* Main class for interacting with the Firecrawl API.
|
|
383
290
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -419,18 +326,9 @@ declare class FirecrawlApp {
|
|
|
419
326
|
* Checks the status of a crawl job using the Firecrawl API.
|
|
420
327
|
* @param id - The ID of the crawl operation.
|
|
421
328
|
* @param getAllData - Paginate through all the pages of documents, returning the full list of all documents. (default: `false`)
|
|
422
|
-
* @param nextURL - The `next` URL from the previous crawl status. Only required if you're not manually increasing `skip`. Only used when `getAllData = false`.
|
|
423
|
-
* @param skip - How many entries to skip to paginate. Only required if you're not providing `nextURL`. Only used when `getAllData = false`.
|
|
424
|
-
* @param limit - How many entries to return. Only used when `getAllData = false`.
|
|
425
329
|
* @returns The response containing the job status.
|
|
426
330
|
*/
|
|
427
|
-
checkCrawlStatus(id?: string, getAllData?: boolean
|
|
428
|
-
/**
|
|
429
|
-
* Returns information about crawl errors.
|
|
430
|
-
* @param id - The ID of the crawl operation.
|
|
431
|
-
* @returns Information about crawl errors.
|
|
432
|
-
*/
|
|
433
|
-
checkCrawlErrors(id: string): Promise<CrawlErrorsResponse | ErrorResponse>;
|
|
331
|
+
checkCrawlStatus(id?: string, getAllData?: boolean): Promise<CrawlStatusResponse | ErrorResponse>;
|
|
434
332
|
/**
|
|
435
333
|
* Cancels a crawl job using the Firecrawl API.
|
|
436
334
|
* @param id - The ID of the crawl operation.
|
|
@@ -475,18 +373,9 @@ declare class FirecrawlApp {
|
|
|
475
373
|
* Checks the status of a batch scrape job using the Firecrawl API.
|
|
476
374
|
* @param id - The ID of the batch scrape operation.
|
|
477
375
|
* @param getAllData - Paginate through all the pages of documents, returning the full list of all documents. (default: `false`)
|
|
478
|
-
* @param nextURL - The `next` URL from the previous batch scrape status. Only required if you're not manually increasing `skip`. Only used when `getAllData = false`.
|
|
479
|
-
* @param skip - How many entries to skip to paginate. Only used when `getAllData = false`.
|
|
480
|
-
* @param limit - How many entries to return. Only used when `getAllData = false`.
|
|
481
376
|
* @returns The response containing the job status.
|
|
482
377
|
*/
|
|
483
|
-
checkBatchScrapeStatus(id?: string, getAllData?: boolean
|
|
484
|
-
/**
|
|
485
|
-
* Returns information about batch scrape errors.
|
|
486
|
-
* @param id - The ID of the batch scrape operation.
|
|
487
|
-
* @returns Information about batch scrape errors.
|
|
488
|
-
*/
|
|
489
|
-
checkBatchScrapeErrors(id: string): Promise<CrawlErrorsResponse | ErrorResponse>;
|
|
378
|
+
checkBatchScrapeStatus(id?: string, getAllData?: boolean): Promise<BatchScrapeStatusResponse | ErrorResponse>;
|
|
490
379
|
/**
|
|
491
380
|
* Extracts information from URLs using the Firecrawl API.
|
|
492
381
|
* Currently in Beta. Expect breaking changes on future minor versions.
|
|
@@ -495,20 +384,6 @@ declare class FirecrawlApp {
|
|
|
495
384
|
* @returns The response from the extract operation.
|
|
496
385
|
*/
|
|
497
386
|
extract<T extends zt.ZodSchema = any>(urls: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse>;
|
|
498
|
-
/**
|
|
499
|
-
* Initiates an asynchronous extract job for a URL using the Firecrawl API.
|
|
500
|
-
* @param url - The URL to extract data from.
|
|
501
|
-
* @param params - Additional parameters for the extract request.
|
|
502
|
-
* @param idempotencyKey - Optional idempotency key for the request.
|
|
503
|
-
* @returns The response from the extract operation.
|
|
504
|
-
*/
|
|
505
|
-
asyncExtract(urls: string[], params?: ExtractParams, idempotencyKey?: string): Promise<ExtractResponse | ErrorResponse>;
|
|
506
|
-
/**
|
|
507
|
-
* Retrieves the status of an extract job.
|
|
508
|
-
* @param jobId - The ID of the extract job.
|
|
509
|
-
* @returns The status of the extract job.
|
|
510
|
-
*/
|
|
511
|
-
getExtractStatus(jobId: string): Promise<any>;
|
|
512
387
|
/**
|
|
513
388
|
* Prepares the headers for an API request.
|
|
514
389
|
* @param idempotencyKey - Optional key to ensure idempotency.
|
|
@@ -552,24 +427,6 @@ declare class FirecrawlApp {
|
|
|
552
427
|
* @param {string} action - The action being performed when the error occurred.
|
|
553
428
|
*/
|
|
554
429
|
handleError(response: AxiosResponse, action: string): void;
|
|
555
|
-
/**
|
|
556
|
-
* Initiates a deep research operation on a given topic and polls until completion.
|
|
557
|
-
* @param params - Parameters for the deep research operation.
|
|
558
|
-
* @returns The final research results.
|
|
559
|
-
*/
|
|
560
|
-
__deepResearch(topic: string, params: DeepResearchParams): Promise<DeepResearchStatusResponse | ErrorResponse>;
|
|
561
|
-
/**
|
|
562
|
-
* Initiates a deep research operation on a given topic without polling.
|
|
563
|
-
* @param params - Parameters for the deep research operation.
|
|
564
|
-
* @returns The response containing the research job ID.
|
|
565
|
-
*/
|
|
566
|
-
__asyncDeepResearch(topic: string, params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
|
|
567
|
-
/**
|
|
568
|
-
* Checks the status of a deep research operation.
|
|
569
|
-
* @param id - The ID of the deep research operation.
|
|
570
|
-
* @returns The current status and results of the research operation.
|
|
571
|
-
*/
|
|
572
|
-
__checkDeepResearchStatus(id: string): Promise<DeepResearchStatusResponse | ErrorResponse>;
|
|
573
430
|
}
|
|
574
431
|
interface CrawlWatcherEvents {
|
|
575
432
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -592,4 +449,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
592
449
|
close(): void;
|
|
593
450
|
}
|
|
594
451
|
|
|
595
|
-
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type
|
|
452
|
+
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type ExtractParams, type ExtractResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, type SearchParams, type SearchResponse, FirecrawlApp as default };
|
package/dist/index.js
CHANGED
|
@@ -6,11 +6,9 @@ import { WebSocket } from "isows";
|
|
|
6
6
|
import { TypedEventTarget } from "typescript-event-target";
|
|
7
7
|
var FirecrawlError = class extends Error {
|
|
8
8
|
statusCode;
|
|
9
|
-
|
|
10
|
-
constructor(message, statusCode, details) {
|
|
9
|
+
constructor(message, statusCode) {
|
|
11
10
|
super(message);
|
|
12
11
|
this.statusCode = statusCode;
|
|
13
|
-
this.details = details;
|
|
14
12
|
}
|
|
15
13
|
};
|
|
16
14
|
var FirecrawlApp = class {
|
|
@@ -57,20 +55,6 @@ var FirecrawlApp = class {
|
|
|
57
55
|
}
|
|
58
56
|
};
|
|
59
57
|
}
|
|
60
|
-
if (jsonData?.jsonOptions?.schema) {
|
|
61
|
-
let schema = jsonData.jsonOptions.schema;
|
|
62
|
-
try {
|
|
63
|
-
schema = zodToJsonSchema(schema);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
}
|
|
66
|
-
jsonData = {
|
|
67
|
-
...jsonData,
|
|
68
|
-
jsonOptions: {
|
|
69
|
-
...jsonData.jsonOptions,
|
|
70
|
-
schema
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
58
|
try {
|
|
75
59
|
const response = await axios.post(
|
|
76
60
|
this.apiUrl + `/v1/scrape`,
|
|
@@ -225,26 +209,16 @@ var FirecrawlApp = class {
|
|
|
225
209
|
* Checks the status of a crawl job using the Firecrawl API.
|
|
226
210
|
* @param id - The ID of the crawl operation.
|
|
227
211
|
* @param getAllData - Paginate through all the pages of documents, returning the full list of all documents. (default: `false`)
|
|
228
|
-
* @param nextURL - The `next` URL from the previous crawl status. Only required if you're not manually increasing `skip`. Only used when `getAllData = false`.
|
|
229
|
-
* @param skip - How many entries to skip to paginate. Only required if you're not providing `nextURL`. Only used when `getAllData = false`.
|
|
230
|
-
* @param limit - How many entries to return. Only used when `getAllData = false`.
|
|
231
212
|
* @returns The response containing the job status.
|
|
232
213
|
*/
|
|
233
|
-
async checkCrawlStatus(id, getAllData = false
|
|
214
|
+
async checkCrawlStatus(id, getAllData = false) {
|
|
234
215
|
if (!id) {
|
|
235
216
|
throw new FirecrawlError("No crawl ID provided", 400);
|
|
236
217
|
}
|
|
237
218
|
const headers = this.prepareHeaders();
|
|
238
|
-
const targetURL = new URL(nextURL ?? `${this.apiUrl}/v1/crawl/${id}`);
|
|
239
|
-
if (skip !== void 0) {
|
|
240
|
-
targetURL.searchParams.set("skip", skip.toString());
|
|
241
|
-
}
|
|
242
|
-
if (limit !== void 0) {
|
|
243
|
-
targetURL.searchParams.set("limit", limit.toString());
|
|
244
|
-
}
|
|
245
219
|
try {
|
|
246
220
|
const response = await this.getRequest(
|
|
247
|
-
|
|
221
|
+
`${this.apiUrl}/v1/crawl/${id}`,
|
|
248
222
|
headers
|
|
249
223
|
);
|
|
250
224
|
if (response.status === 200) {
|
|
@@ -269,7 +243,6 @@ var FirecrawlApp = class {
|
|
|
269
243
|
total: response.data.total,
|
|
270
244
|
completed: response.data.completed,
|
|
271
245
|
creditsUsed: response.data.creditsUsed,
|
|
272
|
-
next: getAllData ? void 0 : response.data.next,
|
|
273
246
|
expiresAt: new Date(response.data.expiresAt),
|
|
274
247
|
data: allData
|
|
275
248
|
};
|
|
@@ -292,28 +265,6 @@ var FirecrawlApp = class {
|
|
|
292
265
|
}
|
|
293
266
|
return { success: false, error: "Internal server error." };
|
|
294
267
|
}
|
|
295
|
-
/**
|
|
296
|
-
* Returns information about crawl errors.
|
|
297
|
-
* @param id - The ID of the crawl operation.
|
|
298
|
-
* @returns Information about crawl errors.
|
|
299
|
-
*/
|
|
300
|
-
async checkCrawlErrors(id) {
|
|
301
|
-
const headers = this.prepareHeaders();
|
|
302
|
-
try {
|
|
303
|
-
const response = await this.deleteRequest(
|
|
304
|
-
`${this.apiUrl}/v1/crawl/${id}/errors`,
|
|
305
|
-
headers
|
|
306
|
-
);
|
|
307
|
-
if (response.status === 200) {
|
|
308
|
-
return response.data;
|
|
309
|
-
} else {
|
|
310
|
-
this.handleError(response, "check crawl errors");
|
|
311
|
-
}
|
|
312
|
-
} catch (error) {
|
|
313
|
-
throw new FirecrawlError(error.message, 500);
|
|
314
|
-
}
|
|
315
|
-
return { success: false, error: "Internal server error." };
|
|
316
|
-
}
|
|
317
268
|
/**
|
|
318
269
|
* Cancels a crawl job using the Firecrawl API.
|
|
319
270
|
* @param id - The ID of the crawl operation.
|
|
@@ -402,20 +353,6 @@ var FirecrawlApp = class {
|
|
|
402
353
|
}
|
|
403
354
|
};
|
|
404
355
|
}
|
|
405
|
-
if (jsonData?.jsonOptions?.schema) {
|
|
406
|
-
let schema = jsonData.jsonOptions.schema;
|
|
407
|
-
try {
|
|
408
|
-
schema = zodToJsonSchema(schema);
|
|
409
|
-
} catch (error) {
|
|
410
|
-
}
|
|
411
|
-
jsonData = {
|
|
412
|
-
...jsonData,
|
|
413
|
-
jsonOptions: {
|
|
414
|
-
...jsonData.jsonOptions,
|
|
415
|
-
schema
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
356
|
try {
|
|
420
357
|
const response = await this.postRequest(
|
|
421
358
|
this.apiUrl + `/v1/batch/scrape`,
|
|
@@ -479,26 +416,16 @@ var FirecrawlApp = class {
|
|
|
479
416
|
* Checks the status of a batch scrape job using the Firecrawl API.
|
|
480
417
|
* @param id - The ID of the batch scrape operation.
|
|
481
418
|
* @param getAllData - Paginate through all the pages of documents, returning the full list of all documents. (default: `false`)
|
|
482
|
-
* @param nextURL - The `next` URL from the previous batch scrape status. Only required if you're not manually increasing `skip`. Only used when `getAllData = false`.
|
|
483
|
-
* @param skip - How many entries to skip to paginate. Only used when `getAllData = false`.
|
|
484
|
-
* @param limit - How many entries to return. Only used when `getAllData = false`.
|
|
485
419
|
* @returns The response containing the job status.
|
|
486
420
|
*/
|
|
487
|
-
async checkBatchScrapeStatus(id, getAllData = false
|
|
421
|
+
async checkBatchScrapeStatus(id, getAllData = false) {
|
|
488
422
|
if (!id) {
|
|
489
423
|
throw new FirecrawlError("No batch scrape ID provided", 400);
|
|
490
424
|
}
|
|
491
425
|
const headers = this.prepareHeaders();
|
|
492
|
-
const targetURL = new URL(nextURL ?? `${this.apiUrl}/v1/batch/scrape/${id}`);
|
|
493
|
-
if (skip !== void 0) {
|
|
494
|
-
targetURL.searchParams.set("skip", skip.toString());
|
|
495
|
-
}
|
|
496
|
-
if (limit !== void 0) {
|
|
497
|
-
targetURL.searchParams.set("limit", limit.toString());
|
|
498
|
-
}
|
|
499
426
|
try {
|
|
500
427
|
const response = await this.getRequest(
|
|
501
|
-
|
|
428
|
+
`${this.apiUrl}/v1/batch/scrape/${id}`,
|
|
502
429
|
headers
|
|
503
430
|
);
|
|
504
431
|
if (response.status === 200) {
|
|
@@ -523,7 +450,6 @@ var FirecrawlApp = class {
|
|
|
523
450
|
total: response.data.total,
|
|
524
451
|
completed: response.data.completed,
|
|
525
452
|
creditsUsed: response.data.creditsUsed,
|
|
526
|
-
next: getAllData ? void 0 : response.data.next,
|
|
527
453
|
expiresAt: new Date(response.data.expiresAt),
|
|
528
454
|
data: allData
|
|
529
455
|
};
|
|
@@ -546,28 +472,6 @@ var FirecrawlApp = class {
|
|
|
546
472
|
}
|
|
547
473
|
return { success: false, error: "Internal server error." };
|
|
548
474
|
}
|
|
549
|
-
/**
|
|
550
|
-
* Returns information about batch scrape errors.
|
|
551
|
-
* @param id - The ID of the batch scrape operation.
|
|
552
|
-
* @returns Information about batch scrape errors.
|
|
553
|
-
*/
|
|
554
|
-
async checkBatchScrapeErrors(id) {
|
|
555
|
-
const headers = this.prepareHeaders();
|
|
556
|
-
try {
|
|
557
|
-
const response = await this.deleteRequest(
|
|
558
|
-
`${this.apiUrl}/v1/batch/scrape/${id}/errors`,
|
|
559
|
-
headers
|
|
560
|
-
);
|
|
561
|
-
if (response.status === 200) {
|
|
562
|
-
return response.data;
|
|
563
|
-
} else {
|
|
564
|
-
this.handleError(response, "check batch scrape errors");
|
|
565
|
-
}
|
|
566
|
-
} catch (error) {
|
|
567
|
-
throw new FirecrawlError(error.message, 500);
|
|
568
|
-
}
|
|
569
|
-
return { success: false, error: "Internal server error." };
|
|
570
|
-
}
|
|
571
475
|
/**
|
|
572
476
|
* Extracts information from URLs using the Firecrawl API.
|
|
573
477
|
* Currently in Beta. Expect breaking changes on future minor versions.
|
|
@@ -590,66 +494,6 @@ var FirecrawlApp = class {
|
|
|
590
494
|
} catch (error) {
|
|
591
495
|
throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400);
|
|
592
496
|
}
|
|
593
|
-
try {
|
|
594
|
-
const response = await this.postRequest(
|
|
595
|
-
this.apiUrl + `/v1/extract`,
|
|
596
|
-
{ ...jsonData, schema: jsonSchema, origin: params?.origin || "api-sdk" },
|
|
597
|
-
headers
|
|
598
|
-
);
|
|
599
|
-
if (response.status === 200) {
|
|
600
|
-
const jobId = response.data.id;
|
|
601
|
-
let extractStatus;
|
|
602
|
-
do {
|
|
603
|
-
const statusResponse = await this.getRequest(
|
|
604
|
-
`${this.apiUrl}/v1/extract/${jobId}`,
|
|
605
|
-
headers
|
|
606
|
-
);
|
|
607
|
-
extractStatus = statusResponse.data;
|
|
608
|
-
if (extractStatus.status === "completed") {
|
|
609
|
-
if (extractStatus.success) {
|
|
610
|
-
return {
|
|
611
|
-
success: true,
|
|
612
|
-
data: extractStatus.data,
|
|
613
|
-
warning: extractStatus.warning,
|
|
614
|
-
error: extractStatus.error,
|
|
615
|
-
sources: extractStatus?.sources || void 0
|
|
616
|
-
};
|
|
617
|
-
} else {
|
|
618
|
-
throw new FirecrawlError(`Failed to extract data. Error: ${extractStatus.error}`, statusResponse.status);
|
|
619
|
-
}
|
|
620
|
-
} else if (extractStatus.status === "failed" || extractStatus.status === "cancelled") {
|
|
621
|
-
throw new FirecrawlError(`Extract job ${extractStatus.status}. Error: ${extractStatus.error}`, statusResponse.status);
|
|
622
|
-
}
|
|
623
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
624
|
-
} while (extractStatus.status !== "completed");
|
|
625
|
-
} else {
|
|
626
|
-
this.handleError(response, "extract");
|
|
627
|
-
}
|
|
628
|
-
} catch (error) {
|
|
629
|
-
throw new FirecrawlError(error.message, 500, error.response?.data?.details);
|
|
630
|
-
}
|
|
631
|
-
return { success: false, error: "Internal server error." };
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Initiates an asynchronous extract job for a URL using the Firecrawl API.
|
|
635
|
-
* @param url - The URL to extract data from.
|
|
636
|
-
* @param params - Additional parameters for the extract request.
|
|
637
|
-
* @param idempotencyKey - Optional idempotency key for the request.
|
|
638
|
-
* @returns The response from the extract operation.
|
|
639
|
-
*/
|
|
640
|
-
async asyncExtract(urls, params, idempotencyKey) {
|
|
641
|
-
const headers = this.prepareHeaders(idempotencyKey);
|
|
642
|
-
let jsonData = { urls, ...params };
|
|
643
|
-
let jsonSchema;
|
|
644
|
-
try {
|
|
645
|
-
if (params?.schema instanceof zt.ZodType) {
|
|
646
|
-
jsonSchema = zodToJsonSchema(params.schema);
|
|
647
|
-
} else {
|
|
648
|
-
jsonSchema = params?.schema;
|
|
649
|
-
}
|
|
650
|
-
} catch (error) {
|
|
651
|
-
throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400);
|
|
652
|
-
}
|
|
653
497
|
try {
|
|
654
498
|
const response = await this.postRequest(
|
|
655
499
|
this.apiUrl + `/v1/extract`,
|
|
@@ -657,34 +501,24 @@ var FirecrawlApp = class {
|
|
|
657
501
|
headers
|
|
658
502
|
);
|
|
659
503
|
if (response.status === 200) {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
* @param jobId - The ID of the extract job.
|
|
672
|
-
* @returns The status of the extract job.
|
|
673
|
-
*/
|
|
674
|
-
async getExtractStatus(jobId) {
|
|
675
|
-
try {
|
|
676
|
-
const response = await this.getRequest(
|
|
677
|
-
`${this.apiUrl}/v1/extract/${jobId}`,
|
|
678
|
-
this.prepareHeaders()
|
|
679
|
-
);
|
|
680
|
-
if (response.status === 200) {
|
|
681
|
-
return response.data;
|
|
504
|
+
const responseData = response.data;
|
|
505
|
+
if (responseData.success) {
|
|
506
|
+
return {
|
|
507
|
+
success: true,
|
|
508
|
+
data: responseData.data,
|
|
509
|
+
warning: responseData.warning,
|
|
510
|
+
error: responseData.error
|
|
511
|
+
};
|
|
512
|
+
} else {
|
|
513
|
+
throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
|
|
514
|
+
}
|
|
682
515
|
} else {
|
|
683
|
-
this.handleError(response, "
|
|
516
|
+
this.handleError(response, "extract");
|
|
684
517
|
}
|
|
685
518
|
} catch (error) {
|
|
686
519
|
throw new FirecrawlError(error.message, 500);
|
|
687
520
|
}
|
|
521
|
+
return { success: false, error: "Internal server error." };
|
|
688
522
|
}
|
|
689
523
|
/**
|
|
690
524
|
* Prepares the headers for an API request.
|
|
@@ -800,13 +634,11 @@ var FirecrawlApp = class {
|
|
|
800
634
|
* @param {string} action - The action being performed when the error occurred.
|
|
801
635
|
*/
|
|
802
636
|
handleError(response, action) {
|
|
803
|
-
if ([
|
|
637
|
+
if ([402, 408, 409, 500].includes(response.status)) {
|
|
804
638
|
const errorMessage = response.data.error || "Unknown error occurred";
|
|
805
|
-
const details = response.data.details ? ` - ${JSON.stringify(response.data.details)}` : "";
|
|
806
639
|
throw new FirecrawlError(
|
|
807
|
-
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}
|
|
808
|
-
response.status
|
|
809
|
-
response?.data?.details
|
|
640
|
+
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}`,
|
|
641
|
+
response.status
|
|
810
642
|
);
|
|
811
643
|
} else {
|
|
812
644
|
throw new FirecrawlError(
|
|
@@ -815,101 +647,6 @@ var FirecrawlApp = class {
|
|
|
815
647
|
);
|
|
816
648
|
}
|
|
817
649
|
}
|
|
818
|
-
/**
|
|
819
|
-
* Initiates a deep research operation on a given topic and polls until completion.
|
|
820
|
-
* @param params - Parameters for the deep research operation.
|
|
821
|
-
* @returns The final research results.
|
|
822
|
-
*/
|
|
823
|
-
async __deepResearch(topic, params) {
|
|
824
|
-
try {
|
|
825
|
-
const response = await this.__asyncDeepResearch(topic, params);
|
|
826
|
-
if (!response.success || "error" in response) {
|
|
827
|
-
return { success: false, error: "error" in response ? response.error : "Unknown error" };
|
|
828
|
-
}
|
|
829
|
-
if (!response.id) {
|
|
830
|
-
throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
|
|
831
|
-
}
|
|
832
|
-
const jobId = response.id;
|
|
833
|
-
let researchStatus;
|
|
834
|
-
while (true) {
|
|
835
|
-
researchStatus = await this.__checkDeepResearchStatus(jobId);
|
|
836
|
-
if ("error" in researchStatus && !researchStatus.success) {
|
|
837
|
-
return researchStatus;
|
|
838
|
-
}
|
|
839
|
-
if (researchStatus.status === "completed") {
|
|
840
|
-
return researchStatus;
|
|
841
|
-
}
|
|
842
|
-
if (researchStatus.status === "failed") {
|
|
843
|
-
throw new FirecrawlError(
|
|
844
|
-
`Research job ${researchStatus.status}. Error: ${researchStatus.error}`,
|
|
845
|
-
500
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
if (researchStatus.status !== "processing") {
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
852
|
-
}
|
|
853
|
-
return { success: false, error: "Research job terminated unexpectedly" };
|
|
854
|
-
} catch (error) {
|
|
855
|
-
throw new FirecrawlError(error.message, 500, error.response?.data?.details);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Initiates a deep research operation on a given topic without polling.
|
|
860
|
-
* @param params - Parameters for the deep research operation.
|
|
861
|
-
* @returns The response containing the research job ID.
|
|
862
|
-
*/
|
|
863
|
-
async __asyncDeepResearch(topic, params) {
|
|
864
|
-
const headers = this.prepareHeaders();
|
|
865
|
-
try {
|
|
866
|
-
const response = await this.postRequest(
|
|
867
|
-
`${this.apiUrl}/v1/deep-research`,
|
|
868
|
-
{ topic, ...params },
|
|
869
|
-
headers
|
|
870
|
-
);
|
|
871
|
-
if (response.status === 200) {
|
|
872
|
-
return response.data;
|
|
873
|
-
} else {
|
|
874
|
-
this.handleError(response, "start deep research");
|
|
875
|
-
}
|
|
876
|
-
} catch (error) {
|
|
877
|
-
if (error.response?.data?.error) {
|
|
878
|
-
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
879
|
-
} else {
|
|
880
|
-
throw new FirecrawlError(error.message, 500);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
return { success: false, error: "Internal server error." };
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* Checks the status of a deep research operation.
|
|
887
|
-
* @param id - The ID of the deep research operation.
|
|
888
|
-
* @returns The current status and results of the research operation.
|
|
889
|
-
*/
|
|
890
|
-
async __checkDeepResearchStatus(id) {
|
|
891
|
-
const headers = this.prepareHeaders();
|
|
892
|
-
try {
|
|
893
|
-
const response = await this.getRequest(
|
|
894
|
-
`${this.apiUrl}/v1/deep-research/${id}`,
|
|
895
|
-
headers
|
|
896
|
-
);
|
|
897
|
-
if (response.status === 200) {
|
|
898
|
-
return response.data;
|
|
899
|
-
} else if (response.status === 404) {
|
|
900
|
-
throw new FirecrawlError("Deep research job not found", 404);
|
|
901
|
-
} else {
|
|
902
|
-
this.handleError(response, "check deep research status");
|
|
903
|
-
}
|
|
904
|
-
} catch (error) {
|
|
905
|
-
if (error.response?.data?.error) {
|
|
906
|
-
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
907
|
-
} else {
|
|
908
|
-
throw new FirecrawlError(error.message, 500);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
return { success: false, error: "Internal server error." };
|
|
912
|
-
}
|
|
913
650
|
};
|
|
914
651
|
var CrawlWatcher = class extends TypedEventTarget {
|
|
915
652
|
ws;
|
|
@@ -919,8 +656,7 @@ var CrawlWatcher = class extends TypedEventTarget {
|
|
|
919
656
|
constructor(id, app) {
|
|
920
657
|
super();
|
|
921
658
|
this.id = id;
|
|
922
|
-
|
|
923
|
-
this.ws = new WebSocket(`${wsUrl}/v1/crawl/${id}`, app.apiKey);
|
|
659
|
+
this.ws = new WebSocket(`${app.apiUrl}/v1/crawl/${id}`, app.apiKey);
|
|
924
660
|
this.status = "scraping";
|
|
925
661
|
this.data = [];
|
|
926
662
|
const messageHandler = (msg) => {
|