firecrawl 1.8.5 → 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 +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +34 -0
- package/package.json +1 -1
- package/src/index.ts +59 -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
|
@@ -219,6 +219,25 @@ interface MapResponse {
|
|
|
219
219
|
links?: string[];
|
|
220
220
|
error?: string;
|
|
221
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
|
+
}
|
|
222
241
|
/**
|
|
223
242
|
* Error response interface.
|
|
224
243
|
* Defines the structure of the response received when an error occurs.
|
|
@@ -325,6 +344,13 @@ declare class FirecrawlApp {
|
|
|
325
344
|
* @returns The response containing the job status.
|
|
326
345
|
*/
|
|
327
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>;
|
|
328
354
|
/**
|
|
329
355
|
* Prepares the headers for an API request.
|
|
330
356
|
* @param idempotencyKey - Optional key to ensure idempotency.
|
|
@@ -389,4 +415,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
389
415
|
close(): void;
|
|
390
416
|
}
|
|
391
417
|
|
|
392
|
-
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
|
@@ -219,6 +219,25 @@ interface MapResponse {
|
|
|
219
219
|
links?: string[];
|
|
220
220
|
error?: string;
|
|
221
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
|
+
}
|
|
222
241
|
/**
|
|
223
242
|
* Error response interface.
|
|
224
243
|
* Defines the structure of the response received when an error occurs.
|
|
@@ -325,6 +344,13 @@ declare class FirecrawlApp {
|
|
|
325
344
|
* @returns The response containing the job status.
|
|
326
345
|
*/
|
|
327
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>;
|
|
328
354
|
/**
|
|
329
355
|
* Prepares the headers for an API request.
|
|
330
356
|
* @param idempotencyKey - Optional key to ensure idempotency.
|
|
@@ -389,4 +415,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
389
415
|
close(): void;
|
|
390
416
|
}
|
|
391
417
|
|
|
392
|
-
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
|
@@ -236,6 +236,27 @@ export interface MapResponse {
|
|
|
236
236
|
error?: string;
|
|
237
237
|
}
|
|
238
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
|
+
|
|
239
260
|
/**
|
|
240
261
|
* Error response interface.
|
|
241
262
|
* Defines the structure of the response received when an error occurs.
|
|
@@ -245,7 +266,6 @@ export interface ErrorResponse {
|
|
|
245
266
|
error: string;
|
|
246
267
|
}
|
|
247
268
|
|
|
248
|
-
|
|
249
269
|
/**
|
|
250
270
|
* Custom error class for Firecrawl.
|
|
251
271
|
* Extends the built-in Error class to include a status code.
|
|
@@ -679,6 +699,44 @@ export default class FirecrawlApp {
|
|
|
679
699
|
return { success: false, error: "Internal server error." };
|
|
680
700
|
}
|
|
681
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
|
+
|
|
682
740
|
/**
|
|
683
741
|
* Prepares the headers for an API request.
|
|
684
742
|
* @param idempotencyKey - Optional key to ensure idempotency.
|