firecrawl 1.3.0 → 1.4.3

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
@@ -271,8 +271,16 @@ var FirecrawlApp = class {
271
271
  * @param headers - The headers for the request.
272
272
  * @returns The response from the GET request.
273
273
  */
274
- getRequest(url, headers) {
275
- return import_axios.default.get(url, { headers });
274
+ async getRequest(url, headers) {
275
+ try {
276
+ return await import_axios.default.get(url, { headers });
277
+ } catch (error) {
278
+ if (error instanceof import_axios.AxiosError && error.response) {
279
+ return error.response;
280
+ } else {
281
+ throw error;
282
+ }
283
+ }
276
284
  }
277
285
  /**
278
286
  * Monitors the status of a crawl job until completion or failure.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosRequestHeaders, AxiosResponse } from 'axios';
2
- import { ZodSchema } from 'zod';
2
+ import * as zt from 'zod';
3
3
  import { TypedEventTarget } from 'typescript-event-target';
4
4
 
5
5
  /**
@@ -54,13 +54,13 @@ interface FirecrawlDocumentMetadata {
54
54
  * Document interface for Firecrawl.
55
55
  * Represents a document retrieved or processed by Firecrawl.
56
56
  */
57
- interface FirecrawlDocument {
57
+ interface FirecrawlDocument<T> {
58
58
  url?: string;
59
59
  markdown?: string;
60
60
  html?: string;
61
61
  rawHtml?: string;
62
62
  links?: string[];
63
- extract?: Record<any, any>;
63
+ extract?: T;
64
64
  screenshot?: string;
65
65
  metadata?: FirecrawlDocumentMetadata;
66
66
  }
@@ -68,25 +68,27 @@ interface FirecrawlDocument {
68
68
  * Parameters for scraping operations.
69
69
  * Defines the options and configurations available for scraping web content.
70
70
  */
71
- interface ScrapeParams {
71
+ interface CrawlScrapeOptions {
72
72
  formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "extract" | "full@scrennshot")[];
73
73
  headers?: Record<string, string>;
74
74
  includeTags?: string[];
75
75
  excludeTags?: string[];
76
76
  onlyMainContent?: boolean;
77
+ waitFor?: number;
78
+ timeout?: number;
79
+ }
80
+ interface ScrapeParams<LLMSchema extends zt.ZodSchema> extends CrawlScrapeOptions {
77
81
  extract?: {
78
82
  prompt?: string;
79
- schema?: ZodSchema | any;
83
+ schema?: LLMSchema;
80
84
  systemPrompt?: string;
81
85
  };
82
- waitFor?: number;
83
- timeout?: number;
84
86
  }
85
87
  /**
86
88
  * Response interface for scraping operations.
87
89
  * Defines the structure of the response received after a scraping operation.
88
90
  */
89
- interface ScrapeResponse extends FirecrawlDocument {
91
+ interface ScrapeResponse<LLMResult> extends FirecrawlDocument<LLMResult> {
90
92
  success: true;
91
93
  warning?: string;
92
94
  error?: string;
@@ -103,7 +105,7 @@ interface CrawlParams {
103
105
  allowBackwardLinks?: boolean;
104
106
  allowExternalLinks?: boolean;
105
107
  ignoreSitemap?: boolean;
106
- scrapeOptions?: ScrapeParams;
108
+ scrapeOptions?: CrawlScrapeOptions;
107
109
  webhook?: string;
108
110
  }
109
111
  /**
@@ -128,7 +130,7 @@ interface CrawlStatusResponse {
128
130
  creditsUsed: number;
129
131
  expiresAt: Date;
130
132
  next?: string;
131
- data: FirecrawlDocument[];
133
+ data: FirecrawlDocument<undefined>[];
132
134
  }
133
135
  /**
134
136
  * Parameters for mapping operations.
@@ -175,7 +177,7 @@ declare class FirecrawlApp {
175
177
  * @param params - Additional parameters for the scrape request.
176
178
  * @returns The response from the scrape operation.
177
179
  */
178
- scrapeUrl(url: string, params?: ScrapeParams): Promise<ScrapeResponse | ErrorResponse>;
180
+ scrapeUrl<T extends zt.ZodSchema>(url: string, params?: ScrapeParams<T>): Promise<ScrapeResponse<zt.infer<T>> | ErrorResponse>;
179
181
  /**
180
182
  * 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
183
  * @param query - The search query string.
@@ -240,23 +242,23 @@ declare class FirecrawlApp {
240
242
  handleError(response: AxiosResponse, action: string): void;
241
243
  }
242
244
  interface CrawlWatcherEvents {
243
- document: CustomEvent<FirecrawlDocument>;
245
+ document: CustomEvent<FirecrawlDocument<undefined>>;
244
246
  done: CustomEvent<{
245
247
  status: CrawlStatusResponse["status"];
246
- data: FirecrawlDocument[];
248
+ data: FirecrawlDocument<undefined>[];
247
249
  }>;
248
250
  error: CustomEvent<{
249
251
  status: CrawlStatusResponse["status"];
250
- data: FirecrawlDocument[];
252
+ data: FirecrawlDocument<undefined>[];
251
253
  error: string;
252
254
  }>;
253
255
  }
254
256
  declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
255
257
  private ws;
256
- data: FirecrawlDocument[];
258
+ data: FirecrawlDocument<undefined>[];
257
259
  status: CrawlStatusResponse["status"];
258
260
  constructor(id: string, app: FirecrawlApp);
259
261
  close(): void;
260
262
  }
261
263
 
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 };
264
+ export { type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AxiosRequestHeaders, AxiosResponse } from 'axios';
2
- import { ZodSchema } from 'zod';
2
+ import * as zt from 'zod';
3
3
  import { TypedEventTarget } from 'typescript-event-target';
4
4
 
5
5
  /**
@@ -54,13 +54,13 @@ interface FirecrawlDocumentMetadata {
54
54
  * Document interface for Firecrawl.
55
55
  * Represents a document retrieved or processed by Firecrawl.
56
56
  */
57
- interface FirecrawlDocument {
57
+ interface FirecrawlDocument<T> {
58
58
  url?: string;
59
59
  markdown?: string;
60
60
  html?: string;
61
61
  rawHtml?: string;
62
62
  links?: string[];
63
- extract?: Record<any, any>;
63
+ extract?: T;
64
64
  screenshot?: string;
65
65
  metadata?: FirecrawlDocumentMetadata;
66
66
  }
@@ -68,25 +68,27 @@ interface FirecrawlDocument {
68
68
  * Parameters for scraping operations.
69
69
  * Defines the options and configurations available for scraping web content.
70
70
  */
71
- interface ScrapeParams {
71
+ interface CrawlScrapeOptions {
72
72
  formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "extract" | "full@scrennshot")[];
73
73
  headers?: Record<string, string>;
74
74
  includeTags?: string[];
75
75
  excludeTags?: string[];
76
76
  onlyMainContent?: boolean;
77
+ waitFor?: number;
78
+ timeout?: number;
79
+ }
80
+ interface ScrapeParams<LLMSchema extends zt.ZodSchema> extends CrawlScrapeOptions {
77
81
  extract?: {
78
82
  prompt?: string;
79
- schema?: ZodSchema | any;
83
+ schema?: LLMSchema;
80
84
  systemPrompt?: string;
81
85
  };
82
- waitFor?: number;
83
- timeout?: number;
84
86
  }
85
87
  /**
86
88
  * Response interface for scraping operations.
87
89
  * Defines the structure of the response received after a scraping operation.
88
90
  */
89
- interface ScrapeResponse extends FirecrawlDocument {
91
+ interface ScrapeResponse<LLMResult> extends FirecrawlDocument<LLMResult> {
90
92
  success: true;
91
93
  warning?: string;
92
94
  error?: string;
@@ -103,7 +105,7 @@ interface CrawlParams {
103
105
  allowBackwardLinks?: boolean;
104
106
  allowExternalLinks?: boolean;
105
107
  ignoreSitemap?: boolean;
106
- scrapeOptions?: ScrapeParams;
108
+ scrapeOptions?: CrawlScrapeOptions;
107
109
  webhook?: string;
108
110
  }
109
111
  /**
@@ -128,7 +130,7 @@ interface CrawlStatusResponse {
128
130
  creditsUsed: number;
129
131
  expiresAt: Date;
130
132
  next?: string;
131
- data: FirecrawlDocument[];
133
+ data: FirecrawlDocument<undefined>[];
132
134
  }
133
135
  /**
134
136
  * Parameters for mapping operations.
@@ -175,7 +177,7 @@ declare class FirecrawlApp {
175
177
  * @param params - Additional parameters for the scrape request.
176
178
  * @returns The response from the scrape operation.
177
179
  */
178
- scrapeUrl(url: string, params?: ScrapeParams): Promise<ScrapeResponse | ErrorResponse>;
180
+ scrapeUrl<T extends zt.ZodSchema>(url: string, params?: ScrapeParams<T>): Promise<ScrapeResponse<zt.infer<T>> | ErrorResponse>;
179
181
  /**
180
182
  * 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
183
  * @param query - The search query string.
@@ -240,23 +242,23 @@ declare class FirecrawlApp {
240
242
  handleError(response: AxiosResponse, action: string): void;
241
243
  }
242
244
  interface CrawlWatcherEvents {
243
- document: CustomEvent<FirecrawlDocument>;
245
+ document: CustomEvent<FirecrawlDocument<undefined>>;
244
246
  done: CustomEvent<{
245
247
  status: CrawlStatusResponse["status"];
246
- data: FirecrawlDocument[];
248
+ data: FirecrawlDocument<undefined>[];
247
249
  }>;
248
250
  error: CustomEvent<{
249
251
  status: CrawlStatusResponse["status"];
250
- data: FirecrawlDocument[];
252
+ data: FirecrawlDocument<undefined>[];
251
253
  error: string;
252
254
  }>;
253
255
  }
254
256
  declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
255
257
  private ws;
256
- data: FirecrawlDocument[];
258
+ data: FirecrawlDocument<undefined>[];
257
259
  status: CrawlStatusResponse["status"];
258
260
  constructor(id: string, app: FirecrawlApp);
259
261
  close(): void;
260
262
  }
261
263
 
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 };
264
+ export { type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import axios from "axios";
2
+ import axios, { AxiosError } from "axios";
3
3
  import { zodToJsonSchema } from "zod-to-json-schema";
4
4
  import { WebSocket } from "isows";
5
5
  import { TypedEventTarget } from "typescript-event-target";
@@ -236,8 +236,16 @@ var FirecrawlApp = class {
236
236
  * @param headers - The headers for the request.
237
237
  * @returns The response from the GET request.
238
238
  */
239
- getRequest(url, headers) {
240
- return axios.get(url, { headers });
239
+ async getRequest(url, headers) {
240
+ try {
241
+ return await axios.get(url, { headers });
242
+ } catch (error) {
243
+ if (error instanceof AxiosError && error.response) {
244
+ return error.response;
245
+ } else {
246
+ throw error;
247
+ }
248
+ }
241
249
  }
242
250
  /**
243
251
  * Monitors the status of a crawl job until completion or failure.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firecrawl",
3
- "version": "1.3.0",
3
+ "version": "1.4.3",
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
@@ -1,5 +1,5 @@
1
- import axios, { type AxiosResponse, type AxiosRequestHeaders } from "axios";
2
- import type { ZodSchema } from "zod";
1
+ import axios, { type AxiosResponse, type AxiosRequestHeaders, AxiosError } from "axios";
2
+ import type * as zt from "zod";
3
3
  import { zodToJsonSchema } from "zod-to-json-schema";
4
4
  import { WebSocket } from "isows";
5
5
  import { TypedEventTarget } from "typescript-event-target";
@@ -58,13 +58,13 @@ export interface FirecrawlDocumentMetadata {
58
58
  * Document interface for Firecrawl.
59
59
  * Represents a document retrieved or processed by Firecrawl.
60
60
  */
61
- export interface FirecrawlDocument {
61
+ export interface FirecrawlDocument<T> {
62
62
  url?: string;
63
63
  markdown?: string;
64
64
  html?: string;
65
65
  rawHtml?: string;
66
66
  links?: string[];
67
- extract?: Record<any, any>;
67
+ extract?: T;
68
68
  screenshot?: string;
69
69
  metadata?: FirecrawlDocumentMetadata;
70
70
  }
@@ -73,26 +73,29 @@ export interface FirecrawlDocument {
73
73
  * Parameters for scraping operations.
74
74
  * Defines the options and configurations available for scraping web content.
75
75
  */
76
- export interface ScrapeParams {
76
+ export interface CrawlScrapeOptions {
77
77
  formats: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "extract" | "full@scrennshot")[];
78
78
  headers?: Record<string, string>;
79
79
  includeTags?: string[];
80
80
  excludeTags?: string[];
81
81
  onlyMainContent?: boolean;
82
+ waitFor?: number;
83
+ timeout?: number;
84
+ }
85
+
86
+ export interface ScrapeParams<LLMSchema extends zt.ZodSchema> extends CrawlScrapeOptions {
82
87
  extract?: {
83
88
  prompt?: string;
84
- schema?: ZodSchema | any;
89
+ schema?: LLMSchema;
85
90
  systemPrompt?: string;
86
91
  };
87
- waitFor?: number;
88
- timeout?: number;
89
92
  }
90
93
 
91
94
  /**
92
95
  * Response interface for scraping operations.
93
96
  * Defines the structure of the response received after a scraping operation.
94
97
  */
95
- export interface ScrapeResponse extends FirecrawlDocument {
98
+ export interface ScrapeResponse<LLMResult> extends FirecrawlDocument<LLMResult> {
96
99
  success: true;
97
100
  warning?: string;
98
101
  error?: string;
@@ -110,7 +113,7 @@ export interface CrawlParams {
110
113
  allowBackwardLinks?: boolean;
111
114
  allowExternalLinks?: boolean;
112
115
  ignoreSitemap?: boolean;
113
- scrapeOptions?: ScrapeParams;
116
+ scrapeOptions?: CrawlScrapeOptions;
114
117
  webhook?: string;
115
118
  }
116
119
 
@@ -137,7 +140,7 @@ export interface CrawlStatusResponse {
137
140
  creditsUsed: number;
138
141
  expiresAt: Date;
139
142
  next?: string;
140
- data: FirecrawlDocument[];
143
+ data: FirecrawlDocument<undefined>[];
141
144
  };
142
145
 
143
146
  /**
@@ -197,10 +200,10 @@ export default class FirecrawlApp {
197
200
  * @param params - Additional parameters for the scrape request.
198
201
  * @returns The response from the scrape operation.
199
202
  */
200
- async scrapeUrl(
203
+ async scrapeUrl<T extends zt.ZodSchema>(
201
204
  url: string,
202
- params?: ScrapeParams
203
- ): Promise<ScrapeResponse | ErrorResponse> {
205
+ params?: ScrapeParams<T>
206
+ ): Promise<ScrapeResponse<zt.infer<T>> | ErrorResponse> {
204
207
  const headers: AxiosRequestHeaders = {
205
208
  "Content-Type": "application/json",
206
209
  Authorization: `Bearer ${this.apiKey}`,
@@ -449,11 +452,19 @@ export default class FirecrawlApp {
449
452
  * @param headers - The headers for the request.
450
453
  * @returns The response from the GET request.
451
454
  */
452
- getRequest(
455
+ async getRequest(
453
456
  url: string,
454
457
  headers: AxiosRequestHeaders
455
458
  ): Promise<AxiosResponse> {
456
- return axios.get(url, { headers });
459
+ try {
460
+ return await axios.get(url, { headers });
461
+ } catch (error) {
462
+ if (error instanceof AxiosError && error.response) {
463
+ return error.response as AxiosResponse;
464
+ } else {
465
+ throw error;
466
+ }
467
+ }
457
468
  }
458
469
 
459
470
  /**
@@ -528,21 +539,21 @@ export default class FirecrawlApp {
528
539
  }
529
540
 
530
541
  interface CrawlWatcherEvents {
531
- document: CustomEvent<FirecrawlDocument>,
542
+ document: CustomEvent<FirecrawlDocument<undefined>>,
532
543
  done: CustomEvent<{
533
544
  status: CrawlStatusResponse["status"];
534
- data: FirecrawlDocument[];
545
+ data: FirecrawlDocument<undefined>[];
535
546
  }>,
536
547
  error: CustomEvent<{
537
548
  status: CrawlStatusResponse["status"],
538
- data: FirecrawlDocument[],
549
+ data: FirecrawlDocument<undefined>[],
539
550
  error: string,
540
551
  }>,
541
552
  }
542
553
 
543
554
  export class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
544
555
  private ws: WebSocket;
545
- public data: FirecrawlDocument[];
556
+ public data: FirecrawlDocument<undefined>[];
546
557
  public status: CrawlStatusResponse["status"];
547
558
 
548
559
  constructor(id: string, app: FirecrawlApp) {
@@ -563,7 +574,7 @@ export class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
563
574
 
564
575
  type DocumentMessage = {
565
576
  type: "document",
566
- data: FirecrawlDocument,
577
+ data: FirecrawlDocument<undefined>,
567
578
  }
568
579
 
569
580
  type DoneMessage = { type: "done" }