firecrawl 1.9.0 → 1.9.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 CHANGED
@@ -407,6 +407,7 @@ var FirecrawlApp = class {
407
407
  }
408
408
  /**
409
409
  * Extracts information from URLs using the Firecrawl API.
410
+ * Currently in Beta. Expect breaking changes on future minor versions.
410
411
  * @param url - The URL to extract information from.
411
412
  * @param params - Additional parameters for the extract request.
412
413
  * @returns The response from the extract operation.
@@ -430,7 +431,17 @@ var FirecrawlApp = class {
430
431
  headers
431
432
  );
432
433
  if (response.status === 200) {
433
- return response.data;
434
+ const responseData = response.data;
435
+ if (responseData.success) {
436
+ return {
437
+ success: true,
438
+ data: responseData.data,
439
+ warning: responseData.warning,
440
+ error: responseData.error
441
+ };
442
+ } else {
443
+ throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
444
+ }
434
445
  } else {
435
446
  this.handleError(response, "extract");
436
447
  }
package/dist/index.d.cts CHANGED
@@ -223,9 +223,9 @@ interface MapResponse {
223
223
  * Parameters for extracting information from URLs.
224
224
  * Defines options for extracting information from URLs.
225
225
  */
226
- interface ExtractParams {
226
+ interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
227
227
  prompt: string;
228
- schema?: zt.ZodSchema;
228
+ schema?: LLMSchema;
229
229
  systemPrompt?: string;
230
230
  allowExternalLinks?: boolean;
231
231
  }
@@ -233,10 +233,11 @@ interface ExtractParams {
233
233
  * Response interface for extracting information from URLs.
234
234
  * Defines the structure of the response received after extracting information from URLs.
235
235
  */
236
- interface ExtractResponse {
237
- success: true;
238
- data: zt.infer<zt.ZodSchema>;
236
+ interface ExtractResponse<LLMSchema extends zt.ZodSchema = any> {
237
+ success: boolean;
238
+ data: LLMSchema;
239
239
  error?: string;
240
+ warning?: string;
240
241
  }
241
242
  /**
242
243
  * Error response interface.
@@ -346,11 +347,12 @@ declare class FirecrawlApp {
346
347
  checkBatchScrapeStatus(id?: string, getAllData?: boolean): Promise<BatchScrapeStatusResponse | ErrorResponse>;
347
348
  /**
348
349
  * Extracts information from URLs using the Firecrawl API.
350
+ * Currently in Beta. Expect breaking changes on future minor versions.
349
351
  * @param url - The URL to extract information from.
350
352
  * @param params - Additional parameters for the extract request.
351
353
  * @returns The response from the extract operation.
352
354
  */
353
- extract(urls: string[], params?: ExtractParams): Promise<ExtractResponse | ErrorResponse>;
355
+ extract<T extends zt.ZodSchema = any>(urls: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse>;
354
356
  /**
355
357
  * Prepares the headers for an API request.
356
358
  * @param idempotencyKey - Optional key to ensure idempotency.
package/dist/index.d.ts CHANGED
@@ -223,9 +223,9 @@ interface MapResponse {
223
223
  * Parameters for extracting information from URLs.
224
224
  * Defines options for extracting information from URLs.
225
225
  */
226
- interface ExtractParams {
226
+ interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
227
227
  prompt: string;
228
- schema?: zt.ZodSchema;
228
+ schema?: LLMSchema;
229
229
  systemPrompt?: string;
230
230
  allowExternalLinks?: boolean;
231
231
  }
@@ -233,10 +233,11 @@ interface ExtractParams {
233
233
  * Response interface for extracting information from URLs.
234
234
  * Defines the structure of the response received after extracting information from URLs.
235
235
  */
236
- interface ExtractResponse {
237
- success: true;
238
- data: zt.infer<zt.ZodSchema>;
236
+ interface ExtractResponse<LLMSchema extends zt.ZodSchema = any> {
237
+ success: boolean;
238
+ data: LLMSchema;
239
239
  error?: string;
240
+ warning?: string;
240
241
  }
241
242
  /**
242
243
  * Error response interface.
@@ -346,11 +347,12 @@ declare class FirecrawlApp {
346
347
  checkBatchScrapeStatus(id?: string, getAllData?: boolean): Promise<BatchScrapeStatusResponse | ErrorResponse>;
347
348
  /**
348
349
  * Extracts information from URLs using the Firecrawl API.
350
+ * Currently in Beta. Expect breaking changes on future minor versions.
349
351
  * @param url - The URL to extract information from.
350
352
  * @param params - Additional parameters for the extract request.
351
353
  * @returns The response from the extract operation.
352
354
  */
353
- extract(urls: string[], params?: ExtractParams): Promise<ExtractResponse | ErrorResponse>;
355
+ extract<T extends zt.ZodSchema = any>(urls: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse>;
354
356
  /**
355
357
  * Prepares the headers for an API request.
356
358
  * @param idempotencyKey - Optional key to ensure idempotency.
package/dist/index.js CHANGED
@@ -371,6 +371,7 @@ var FirecrawlApp = class {
371
371
  }
372
372
  /**
373
373
  * Extracts information from URLs using the Firecrawl API.
374
+ * Currently in Beta. Expect breaking changes on future minor versions.
374
375
  * @param url - The URL to extract information from.
375
376
  * @param params - Additional parameters for the extract request.
376
377
  * @returns The response from the extract operation.
@@ -394,7 +395,17 @@ var FirecrawlApp = class {
394
395
  headers
395
396
  );
396
397
  if (response.status === 200) {
397
- return response.data;
398
+ const responseData = response.data;
399
+ if (responseData.success) {
400
+ return {
401
+ success: true,
402
+ data: responseData.data,
403
+ warning: responseData.warning,
404
+ error: responseData.error
405
+ };
406
+ } else {
407
+ throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
408
+ }
398
409
  } else {
399
410
  this.handleError(response, "extract");
400
411
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firecrawl",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -240,9 +240,9 @@ export interface MapResponse {
240
240
  * Parameters for extracting information from URLs.
241
241
  * Defines options for extracting information from URLs.
242
242
  */
243
- export interface ExtractParams {
243
+ export interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
244
244
  prompt: string;
245
- schema?: zt.ZodSchema;
245
+ schema?: LLMSchema;
246
246
  systemPrompt?: string;
247
247
  allowExternalLinks?: boolean;
248
248
  }
@@ -251,10 +251,11 @@ export interface ExtractParams {
251
251
  * Response interface for extracting information from URLs.
252
252
  * Defines the structure of the response received after extracting information from URLs.
253
253
  */
254
- export interface ExtractResponse {
255
- success: true;
256
- data: zt.infer<zt.ZodSchema>;
254
+ export interface ExtractResponse<LLMSchema extends zt.ZodSchema = any> {
255
+ success: boolean;
256
+ data: LLMSchema;
257
257
  error?: string;
258
+ warning?: string;
258
259
  }
259
260
 
260
261
  /**
@@ -701,18 +702,19 @@ export default class FirecrawlApp {
701
702
 
702
703
  /**
703
704
  * Extracts information from URLs using the Firecrawl API.
705
+ * Currently in Beta. Expect breaking changes on future minor versions.
704
706
  * @param url - The URL to extract information from.
705
707
  * @param params - Additional parameters for the extract request.
706
708
  * @returns The response from the extract operation.
707
709
  */
708
- async extract(urls: string[], params?: ExtractParams): Promise<ExtractResponse | ErrorResponse> {
710
+ async extract<T extends zt.ZodSchema = any>(urls: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse> {
709
711
  const headers = this.prepareHeaders();
710
712
 
711
713
  if (!params?.prompt) {
712
714
  throw new FirecrawlError("Prompt is required", 400);
713
715
  }
714
716
 
715
- let jsonData: { urls: string[] } & ExtractParams= { urls, ...params };
717
+ let jsonData: { urls: string[] } & ExtractParams<T> = { urls, ...params };
716
718
  let jsonSchema: any;
717
719
  try {
718
720
  jsonSchema = params?.schema ? zodToJsonSchema(params.schema) : undefined;
@@ -727,7 +729,17 @@ export default class FirecrawlApp {
727
729
  headers
728
730
  );
729
731
  if (response.status === 200) {
730
- return response.data as ExtractResponse;
732
+ const responseData = response.data as ExtractResponse<T>;
733
+ if (responseData.success) {
734
+ return {
735
+ success: true,
736
+ data: responseData.data,
737
+ warning: responseData.warning,
738
+ error: responseData.error
739
+ };
740
+ } else {
741
+ throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
742
+ }
731
743
  } else {
732
744
  this.handleError(response, "extract");
733
745
  }