firecrawl 1.8.4 → 1.9.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 +34 -0
- package/dist/index.d.cts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +34 -0
- package/package.json +1 -1
- package/src/index.ts +60 -1
package/dist/index.cjs
CHANGED
|
@@ -405,6 +405,40 @@ var FirecrawlApp = class {
|
|
|
405
405
|
}
|
|
406
406
|
return { success: false, error: "Internal server error." };
|
|
407
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* Extracts information from URLs using the Firecrawl API.
|
|
410
|
+
* @param url - The URL to extract information from.
|
|
411
|
+
* @param params - Additional parameters for the extract request.
|
|
412
|
+
* @returns The response from the extract operation.
|
|
413
|
+
*/
|
|
414
|
+
async extract(urls, params) {
|
|
415
|
+
const headers = this.prepareHeaders();
|
|
416
|
+
if (!params?.prompt) {
|
|
417
|
+
throw new FirecrawlError("Prompt is required", 400);
|
|
418
|
+
}
|
|
419
|
+
let jsonData = { urls, ...params };
|
|
420
|
+
let jsonSchema;
|
|
421
|
+
try {
|
|
422
|
+
jsonSchema = params?.schema ? (0, import_zod_to_json_schema.zodToJsonSchema)(params.schema) : void 0;
|
|
423
|
+
} catch (error) {
|
|
424
|
+
throw new FirecrawlError("Invalid schema. Use a valid Zod schema.", 400);
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
const response = await this.postRequest(
|
|
428
|
+
this.apiUrl + `/v1/extract`,
|
|
429
|
+
{ ...jsonData, schema: jsonSchema },
|
|
430
|
+
headers
|
|
431
|
+
);
|
|
432
|
+
if (response.status === 200) {
|
|
433
|
+
return response.data;
|
|
434
|
+
} else {
|
|
435
|
+
this.handleError(response, "extract");
|
|
436
|
+
}
|
|
437
|
+
} catch (error) {
|
|
438
|
+
throw new FirecrawlError(error.message, 500);
|
|
439
|
+
}
|
|
440
|
+
return { success: false, error: "Internal server error." };
|
|
441
|
+
}
|
|
408
442
|
/**
|
|
409
443
|
* Prepares the headers for an API request.
|
|
410
444
|
* @param idempotencyKey - Optional key to ensure idempotency.
|
package/dist/index.d.cts
CHANGED
|
@@ -81,6 +81,7 @@ interface CrawlScrapeOptions {
|
|
|
81
81
|
country?: string;
|
|
82
82
|
languages?: string[];
|
|
83
83
|
};
|
|
84
|
+
mobile?: boolean;
|
|
84
85
|
skipTlsVerification?: boolean;
|
|
85
86
|
removeBase64Images?: boolean;
|
|
86
87
|
}
|
|
@@ -218,6 +219,25 @@ interface MapResponse {
|
|
|
218
219
|
links?: string[];
|
|
219
220
|
error?: string;
|
|
220
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Parameters for extracting information from URLs.
|
|
224
|
+
* Defines options for extracting information from URLs.
|
|
225
|
+
*/
|
|
226
|
+
interface ExtractParams {
|
|
227
|
+
prompt: string;
|
|
228
|
+
schema?: zt.ZodSchema;
|
|
229
|
+
systemPrompt?: string;
|
|
230
|
+
allowExternalLinks?: boolean;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Response interface for extracting information from URLs.
|
|
234
|
+
* Defines the structure of the response received after extracting information from URLs.
|
|
235
|
+
*/
|
|
236
|
+
interface ExtractResponse {
|
|
237
|
+
success: true;
|
|
238
|
+
data: zt.infer<zt.ZodSchema>;
|
|
239
|
+
error?: string;
|
|
240
|
+
}
|
|
221
241
|
/**
|
|
222
242
|
* Error response interface.
|
|
223
243
|
* Defines the structure of the response received when an error occurs.
|
|
@@ -324,6 +344,13 @@ declare class FirecrawlApp {
|
|
|
324
344
|
* @returns The response containing the job status.
|
|
325
345
|
*/
|
|
326
346
|
checkBatchScrapeStatus(id?: string, getAllData?: boolean): Promise<BatchScrapeStatusResponse | ErrorResponse>;
|
|
347
|
+
/**
|
|
348
|
+
* Extracts information from URLs using the Firecrawl API.
|
|
349
|
+
* @param url - The URL to extract information from.
|
|
350
|
+
* @param params - Additional parameters for the extract request.
|
|
351
|
+
* @returns The response from the extract operation.
|
|
352
|
+
*/
|
|
353
|
+
extract(urls: string[], params?: ExtractParams): Promise<ExtractResponse | ErrorResponse>;
|
|
327
354
|
/**
|
|
328
355
|
* Prepares the headers for an API request.
|
|
329
356
|
* @param idempotencyKey - Optional key to ensure idempotency.
|
|
@@ -388,4 +415,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
388
415
|
close(): void;
|
|
389
416
|
}
|
|
390
417
|
|
|
391
|
-
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
|
|
418
|
+
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, FirecrawlApp as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ interface CrawlScrapeOptions {
|
|
|
81
81
|
country?: string;
|
|
82
82
|
languages?: string[];
|
|
83
83
|
};
|
|
84
|
+
mobile?: boolean;
|
|
84
85
|
skipTlsVerification?: boolean;
|
|
85
86
|
removeBase64Images?: boolean;
|
|
86
87
|
}
|
|
@@ -218,6 +219,25 @@ interface MapResponse {
|
|
|
218
219
|
links?: string[];
|
|
219
220
|
error?: string;
|
|
220
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Parameters for extracting information from URLs.
|
|
224
|
+
* Defines options for extracting information from URLs.
|
|
225
|
+
*/
|
|
226
|
+
interface ExtractParams {
|
|
227
|
+
prompt: string;
|
|
228
|
+
schema?: zt.ZodSchema;
|
|
229
|
+
systemPrompt?: string;
|
|
230
|
+
allowExternalLinks?: boolean;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Response interface for extracting information from URLs.
|
|
234
|
+
* Defines the structure of the response received after extracting information from URLs.
|
|
235
|
+
*/
|
|
236
|
+
interface ExtractResponse {
|
|
237
|
+
success: true;
|
|
238
|
+
data: zt.infer<zt.ZodSchema>;
|
|
239
|
+
error?: string;
|
|
240
|
+
}
|
|
221
241
|
/**
|
|
222
242
|
* Error response interface.
|
|
223
243
|
* Defines the structure of the response received when an error occurs.
|
|
@@ -324,6 +344,13 @@ declare class FirecrawlApp {
|
|
|
324
344
|
* @returns The response containing the job status.
|
|
325
345
|
*/
|
|
326
346
|
checkBatchScrapeStatus(id?: string, getAllData?: boolean): Promise<BatchScrapeStatusResponse | ErrorResponse>;
|
|
347
|
+
/**
|
|
348
|
+
* Extracts information from URLs using the Firecrawl API.
|
|
349
|
+
* @param url - The URL to extract information from.
|
|
350
|
+
* @param params - Additional parameters for the extract request.
|
|
351
|
+
* @returns The response from the extract operation.
|
|
352
|
+
*/
|
|
353
|
+
extract(urls: string[], params?: ExtractParams): Promise<ExtractResponse | ErrorResponse>;
|
|
327
354
|
/**
|
|
328
355
|
* Prepares the headers for an API request.
|
|
329
356
|
* @param idempotencyKey - Optional key to ensure idempotency.
|
|
@@ -388,4 +415,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
388
415
|
close(): void;
|
|
389
416
|
}
|
|
390
417
|
|
|
391
|
-
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
|
|
418
|
+
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, FirecrawlApp as default };
|
package/dist/index.js
CHANGED
|
@@ -369,6 +369,40 @@ var FirecrawlApp = class {
|
|
|
369
369
|
}
|
|
370
370
|
return { success: false, error: "Internal server error." };
|
|
371
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Extracts information from URLs using the Firecrawl API.
|
|
374
|
+
* @param url - The URL to extract information from.
|
|
375
|
+
* @param params - Additional parameters for the extract request.
|
|
376
|
+
* @returns The response from the extract operation.
|
|
377
|
+
*/
|
|
378
|
+
async extract(urls, params) {
|
|
379
|
+
const headers = this.prepareHeaders();
|
|
380
|
+
if (!params?.prompt) {
|
|
381
|
+
throw new FirecrawlError("Prompt is required", 400);
|
|
382
|
+
}
|
|
383
|
+
let jsonData = { urls, ...params };
|
|
384
|
+
let jsonSchema;
|
|
385
|
+
try {
|
|
386
|
+
jsonSchema = params?.schema ? zodToJsonSchema(params.schema) : void 0;
|
|
387
|
+
} catch (error) {
|
|
388
|
+
throw new FirecrawlError("Invalid schema. Use a valid Zod schema.", 400);
|
|
389
|
+
}
|
|
390
|
+
try {
|
|
391
|
+
const response = await this.postRequest(
|
|
392
|
+
this.apiUrl + `/v1/extract`,
|
|
393
|
+
{ ...jsonData, schema: jsonSchema },
|
|
394
|
+
headers
|
|
395
|
+
);
|
|
396
|
+
if (response.status === 200) {
|
|
397
|
+
return response.data;
|
|
398
|
+
} else {
|
|
399
|
+
this.handleError(response, "extract");
|
|
400
|
+
}
|
|
401
|
+
} catch (error) {
|
|
402
|
+
throw new FirecrawlError(error.message, 500);
|
|
403
|
+
}
|
|
404
|
+
return { success: false, error: "Internal server error." };
|
|
405
|
+
}
|
|
372
406
|
/**
|
|
373
407
|
* Prepares the headers for an API request.
|
|
374
408
|
* @param idempotencyKey - Optional key to ensure idempotency.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -86,6 +86,7 @@ export interface CrawlScrapeOptions {
|
|
|
86
86
|
country?: string;
|
|
87
87
|
languages?: string[];
|
|
88
88
|
};
|
|
89
|
+
mobile?: boolean;
|
|
89
90
|
skipTlsVerification?: boolean;
|
|
90
91
|
removeBase64Images?: boolean;
|
|
91
92
|
}
|
|
@@ -235,6 +236,27 @@ export interface MapResponse {
|
|
|
235
236
|
error?: string;
|
|
236
237
|
}
|
|
237
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Parameters for extracting information from URLs.
|
|
241
|
+
* Defines options for extracting information from URLs.
|
|
242
|
+
*/
|
|
243
|
+
export interface ExtractParams {
|
|
244
|
+
prompt: string;
|
|
245
|
+
schema?: zt.ZodSchema;
|
|
246
|
+
systemPrompt?: string;
|
|
247
|
+
allowExternalLinks?: boolean;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Response interface for extracting information from URLs.
|
|
252
|
+
* Defines the structure of the response received after extracting information from URLs.
|
|
253
|
+
*/
|
|
254
|
+
export interface ExtractResponse {
|
|
255
|
+
success: true;
|
|
256
|
+
data: zt.infer<zt.ZodSchema>;
|
|
257
|
+
error?: string;
|
|
258
|
+
}
|
|
259
|
+
|
|
238
260
|
/**
|
|
239
261
|
* Error response interface.
|
|
240
262
|
* Defines the structure of the response received when an error occurs.
|
|
@@ -244,7 +266,6 @@ export interface ErrorResponse {
|
|
|
244
266
|
error: string;
|
|
245
267
|
}
|
|
246
268
|
|
|
247
|
-
|
|
248
269
|
/**
|
|
249
270
|
* Custom error class for Firecrawl.
|
|
250
271
|
* Extends the built-in Error class to include a status code.
|
|
@@ -678,6 +699,44 @@ export default class FirecrawlApp {
|
|
|
678
699
|
return { success: false, error: "Internal server error." };
|
|
679
700
|
}
|
|
680
701
|
|
|
702
|
+
/**
|
|
703
|
+
* Extracts information from URLs using the Firecrawl API.
|
|
704
|
+
* @param url - The URL to extract information from.
|
|
705
|
+
* @param params - Additional parameters for the extract request.
|
|
706
|
+
* @returns The response from the extract operation.
|
|
707
|
+
*/
|
|
708
|
+
async extract(urls: string[], params?: ExtractParams): Promise<ExtractResponse | ErrorResponse> {
|
|
709
|
+
const headers = this.prepareHeaders();
|
|
710
|
+
|
|
711
|
+
if (!params?.prompt) {
|
|
712
|
+
throw new FirecrawlError("Prompt is required", 400);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
let jsonData: { urls: string[] } & ExtractParams= { urls, ...params };
|
|
716
|
+
let jsonSchema: any;
|
|
717
|
+
try {
|
|
718
|
+
jsonSchema = params?.schema ? zodToJsonSchema(params.schema) : undefined;
|
|
719
|
+
} catch (error: any) {
|
|
720
|
+
throw new FirecrawlError("Invalid schema. Use a valid Zod schema.", 400);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
try {
|
|
724
|
+
const response: AxiosResponse = await this.postRequest(
|
|
725
|
+
this.apiUrl + `/v1/extract`,
|
|
726
|
+
{ ...jsonData, schema: jsonSchema },
|
|
727
|
+
headers
|
|
728
|
+
);
|
|
729
|
+
if (response.status === 200) {
|
|
730
|
+
return response.data as ExtractResponse;
|
|
731
|
+
} else {
|
|
732
|
+
this.handleError(response, "extract");
|
|
733
|
+
}
|
|
734
|
+
} catch (error: any) {
|
|
735
|
+
throw new FirecrawlError(error.message, 500);
|
|
736
|
+
}
|
|
737
|
+
return { success: false, error: "Internal server error." };
|
|
738
|
+
}
|
|
739
|
+
|
|
681
740
|
/**
|
|
682
741
|
* Prepares the headers for an API request.
|
|
683
742
|
* @param idempotencyKey - Optional key to ensure idempotency.
|