firecrawl 4.22.2 → 4.24.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/src/v2/types.ts CHANGED
@@ -1,19 +1,20 @@
1
- import type { ZodTypeAny } from 'zod';
1
+ import type { ZodTypeAny } from "zod";
2
2
  // Public types for Firecrawl JS/TS SDK v2 (camelCase only)
3
3
 
4
4
  export type FormatString =
5
- | 'markdown'
6
- | 'html'
7
- | 'rawHtml'
8
- | 'links'
9
- | 'images'
10
- | 'screenshot'
11
- | 'summary'
12
- | 'changeTracking'
13
- | 'json'
14
- | 'attributes'
15
- | 'branding'
16
- | 'audio';
5
+ | "markdown"
6
+ | "html"
7
+ | "rawHtml"
8
+ | "links"
9
+ | "images"
10
+ | "screenshot"
11
+ | "summary"
12
+ | "changeTracking"
13
+ | "json"
14
+ | "attributes"
15
+ | "branding"
16
+ | "audio"
17
+ | "video";
17
18
 
18
19
  export interface Viewport {
19
20
  width: number;
@@ -25,27 +26,27 @@ export interface Format {
25
26
  }
26
27
 
27
28
  export interface JsonFormat extends Format {
28
- type: 'json';
29
+ type: "json";
29
30
  prompt?: string;
30
31
  schema?: Record<string, unknown> | ZodTypeAny;
31
32
  }
32
33
 
33
34
  export interface ScreenshotFormat {
34
- type: 'screenshot';
35
+ type: "screenshot";
35
36
  fullPage?: boolean;
36
37
  quality?: number;
37
38
  viewport?: Viewport | { width: number; height: number };
38
39
  }
39
40
 
40
41
  export interface ChangeTrackingFormat extends Format {
41
- type: 'changeTracking';
42
- modes: ('git-diff' | 'json')[];
42
+ type: "changeTracking";
43
+ modes: ("git-diff" | "json")[];
43
44
  schema?: Record<string, unknown>;
44
45
  prompt?: string;
45
46
  tag?: string;
46
47
  }
47
48
  export interface AttributesFormat extends Format {
48
- type: 'attributes';
49
+ type: "attributes";
49
50
  selectors: Array<{
50
51
  selector: string;
51
52
  attribute: string;
@@ -53,20 +54,20 @@ export interface AttributesFormat extends Format {
53
54
  }
54
55
 
55
56
  export interface QuestionFormat {
56
- type: 'question';
57
+ type: "question";
57
58
  question: string;
58
59
  }
59
60
 
60
61
  export interface HighlightsFormat {
61
- type: 'highlights';
62
+ type: "highlights";
62
63
  query: string;
63
64
  }
64
65
 
65
66
  /** @deprecated Use QuestionFormat or HighlightsFormat instead. */
66
67
  export interface QueryFormat {
67
- type: 'query';
68
+ type: "query";
68
69
  prompt: string;
69
- mode?: 'freeform' | 'directQuote';
70
+ mode?: "freeform" | "directQuote";
70
71
  }
71
72
 
72
73
  export type FormatOption =
@@ -82,7 +83,7 @@ export type FormatOption =
82
83
 
83
84
  export type ParseFormatString = Exclude<
84
85
  FormatString,
85
- 'screenshot' | 'changeTracking' | 'branding'
86
+ "screenshot" | "changeTracking" | "branding" | "audio" | "video"
86
87
  >;
87
88
 
88
89
  export interface ParseFormat {
@@ -104,62 +105,62 @@ export interface LocationConfig {
104
105
  }
105
106
 
106
107
  export interface WaitAction {
107
- type: 'wait';
108
+ type: "wait";
108
109
  milliseconds?: number;
109
110
  selector?: string;
110
111
  }
111
112
 
112
113
  export interface ScreenshotAction {
113
- type: 'screenshot';
114
+ type: "screenshot";
114
115
  fullPage?: boolean;
115
116
  quality?: number;
116
117
  viewport?: Viewport | { width: number; height: number };
117
118
  }
118
119
 
119
120
  export interface ClickAction {
120
- type: 'click';
121
+ type: "click";
121
122
  selector: string;
122
123
  }
123
124
 
124
125
  export interface WriteAction {
125
- type: 'write';
126
+ type: "write";
126
127
  text: string;
127
128
  }
128
129
 
129
130
  export interface PressAction {
130
- type: 'press';
131
+ type: "press";
131
132
  key: string;
132
133
  }
133
134
 
134
135
  export interface ScrollAction {
135
- type: 'scroll';
136
- direction: 'up' | 'down';
136
+ type: "scroll";
137
+ direction: "up" | "down";
137
138
  selector?: string;
138
139
  }
139
140
 
140
141
  export interface ScrapeAction {
141
- type: 'scrape';
142
+ type: "scrape";
142
143
  }
143
144
 
144
145
  export interface ExecuteJavascriptAction {
145
- type: 'executeJavascript';
146
+ type: "executeJavascript";
146
147
  script: string;
147
148
  }
148
149
 
149
150
  export interface PDFAction {
150
- type: 'pdf';
151
+ type: "pdf";
151
152
  format?:
152
- | 'A0'
153
- | 'A1'
154
- | 'A2'
155
- | 'A3'
156
- | 'A4'
157
- | 'A5'
158
- | 'A6'
159
- | 'Letter'
160
- | 'Legal'
161
- | 'Tabloid'
162
- | 'Ledger';
153
+ | "A0"
154
+ | "A1"
155
+ | "A2"
156
+ | "A3"
157
+ | "A4"
158
+ | "A5"
159
+ | "A6"
160
+ | "Letter"
161
+ | "Legal"
162
+ | "Tabloid"
163
+ | "Ledger";
163
164
  landscape?: boolean;
164
165
  scale?: number;
165
166
  }
@@ -184,7 +185,9 @@ export interface ScrapeOptions {
184
185
  timeout?: number;
185
186
  waitFor?: number;
186
187
  mobile?: boolean;
187
- parsers?: Array<string | { type: 'pdf'; mode?: 'fast' | 'auto' | 'ocr'; maxPages?: number }>;
188
+ parsers?: Array<
189
+ string | { type: "pdf"; mode?: "fast" | "auto" | "ocr"; maxPages?: number }
190
+ >;
188
191
  actions?: ActionOption[];
189
192
  location?: LocationConfig;
190
193
  skipTlsVerification?: boolean;
@@ -192,7 +195,7 @@ export interface ScrapeOptions {
192
195
  fastMode?: boolean;
193
196
  useMock?: string;
194
197
  blockAds?: boolean;
195
- proxy?: 'basic' | 'stealth' | 'enhanced' | 'auto' | string;
198
+ proxy?: "basic" | "stealth" | "enhanced" | "auto" | string;
196
199
  maxAge?: number;
197
200
  minAge?: number;
198
201
  storeInCache?: boolean;
@@ -221,30 +224,35 @@ export interface ParseFile {
221
224
 
222
225
  export type ParseOptions = Omit<
223
226
  ScrapeOptions,
224
- | 'formats'
225
- | 'waitFor'
226
- | 'mobile'
227
- | 'actions'
228
- | 'location'
229
- | 'maxAge'
230
- | 'minAge'
231
- | 'storeInCache'
232
- | 'lockdown'
233
- | 'proxy'
227
+ | "formats"
228
+ | "waitFor"
229
+ | "mobile"
230
+ | "actions"
231
+ | "location"
232
+ | "maxAge"
233
+ | "minAge"
234
+ | "storeInCache"
235
+ | "lockdown"
236
+ | "proxy"
234
237
  > & {
235
238
  formats?: ParseFormatOption[];
236
- proxy?: 'basic' | 'auto';
239
+ proxy?: "basic" | "auto";
237
240
  };
238
241
 
239
242
  export interface WebhookConfig {
240
243
  url: string;
241
244
  headers?: Record<string, string>;
242
245
  metadata?: Record<string, string>;
243
- events?: Array<'completed' | 'failed' | 'page' | 'started'>;
246
+ events?: Array<"completed" | "failed" | "page" | "started">;
244
247
  }
245
248
 
246
249
  // Agent webhook events differ from crawl: has 'action' and 'cancelled', no 'page'
247
- export type AgentWebhookEvent = 'started' | 'action' | 'completed' | 'failed' | 'cancelled';
250
+ export type AgentWebhookEvent =
251
+ | "started"
252
+ | "action"
253
+ | "completed"
254
+ | "failed"
255
+ | "cancelled";
248
256
 
249
257
  export interface AgentWebhookConfig {
250
258
  url: string;
@@ -254,7 +262,7 @@ export interface AgentWebhookConfig {
254
262
  }
255
263
 
256
264
  export interface BrandingProfile {
257
- colorScheme?: 'light' | 'dark';
265
+ colorScheme?: "light" | "dark";
258
266
  logo?: string | null;
259
267
  fonts?: Array<{
260
268
  family: string;
@@ -376,13 +384,13 @@ export interface BrandingProfile {
376
384
  };
377
385
  personality?: {
378
386
  tone:
379
- | 'professional'
380
- | 'playful'
381
- | 'modern'
382
- | 'traditional'
383
- | 'minimalist'
384
- | 'bold';
385
- energy: 'low' | 'medium' | 'high';
387
+ | "professional"
388
+ | "playful"
389
+ | "modern"
390
+ | "traditional"
391
+ | "minimalist"
392
+ | "bold";
393
+ energy: "low" | "medium" | "high";
386
394
  targetAudience: string;
387
395
  };
388
396
  [key: string]: unknown;
@@ -434,8 +442,8 @@ export interface DocumentMetadata {
434
442
  numPages?: number;
435
443
  contentType?: string;
436
444
  timezone?: string;
437
- proxyUsed?: 'basic' | 'stealth';
438
- cacheState?: 'hit' | 'miss';
445
+ proxyUsed?: "basic" | "stealth";
446
+ cacheState?: "hit" | "miss";
439
447
  cachedAt?: string;
440
448
  creditsUsed?: number;
441
449
  concurrencyLimited?: boolean;
@@ -458,6 +466,7 @@ export interface Document {
458
466
  images?: string[];
459
467
  screenshot?: string;
460
468
  audio?: string;
469
+ video?: string;
461
470
  attributes?: Array<{
462
471
  selector: string;
463
472
  attribute: string;
@@ -516,15 +525,15 @@ export interface SearchData {
516
525
  }
517
526
 
518
527
  export interface CategoryOption {
519
- type: 'github' | 'research' | 'pdf';
528
+ type: "github" | "research" | "pdf";
520
529
  }
521
530
 
522
531
  export interface SearchRequest {
523
532
  query: string;
524
533
  sources?: Array<
525
- 'web' | 'news' | 'images' | { type: 'web' | 'news' | 'images' }
534
+ "web" | "news" | "images" | { type: "web" | "news" | "images" }
526
535
  >;
527
- categories?: Array<'github' | 'research' | 'pdf' | CategoryOption>;
536
+ categories?: Array<"github" | "research" | "pdf" | CategoryOption>;
528
537
  includeDomains?: string[];
529
538
  excludeDomains?: string[];
530
539
  limit?: number;
@@ -542,7 +551,7 @@ export interface CrawlOptions {
542
551
  excludePaths?: string[] | null;
543
552
  includePaths?: string[] | null;
544
553
  maxDiscoveryDepth?: number | null;
545
- sitemap?: 'skip' | 'include' | 'only';
554
+ sitemap?: "skip" | "include" | "only";
546
555
  ignoreQueryParameters?: boolean;
547
556
  deduplicateSimilarURLs?: boolean;
548
557
  limit?: number | null;
@@ -568,7 +577,7 @@ export interface CrawlResponse {
568
577
 
569
578
  export interface CrawlJob {
570
579
  id: string;
571
- status: 'scraping' | 'completed' | 'failed' | 'cancelled';
580
+ status: "scraping" | "completed" | "failed" | "cancelled";
572
581
  total: number;
573
582
  completed: number;
574
583
  creditsUsed?: number;
@@ -597,7 +606,7 @@ export interface BatchScrapeResponse {
597
606
 
598
607
  export interface BatchScrapeJob {
599
608
  id: string;
600
- status: 'scraping' | 'completed' | 'failed' | 'cancelled';
609
+ status: "scraping" | "completed" | "failed" | "cancelled";
601
610
  completed: number;
602
611
  total: number;
603
612
  creditsUsed?: number;
@@ -612,7 +621,7 @@ export interface MapData {
612
621
 
613
622
  export interface MapOptions {
614
623
  search?: string;
615
- sitemap?: 'only' | 'include' | 'skip';
624
+ sitemap?: "only" | "include" | "skip";
616
625
  includeSubdomains?: boolean;
617
626
  ignoreQueryParameters?: boolean;
618
627
  limit?: number;
@@ -646,14 +655,14 @@ export interface MonitorWebhookConfig {
646
655
 
647
656
  export interface MonitorScrapeTarget {
648
657
  id?: string;
649
- type: 'scrape';
658
+ type: "scrape";
650
659
  urls: string[];
651
660
  scrapeOptions?: ScrapeOptions;
652
661
  }
653
662
 
654
663
  export interface MonitorCrawlTarget {
655
664
  id?: string;
656
- type: 'crawl';
665
+ type: "crawl";
657
666
  url: string;
658
667
  crawlOptions?: CrawlOptions;
659
668
  scrapeOptions?: ScrapeOptions;
@@ -672,7 +681,7 @@ export interface CreateMonitorRequest {
672
681
 
673
682
  export interface UpdateMonitorRequest {
674
683
  name?: string;
675
- status?: 'active' | 'paused';
684
+ status?: "active" | "paused";
676
685
  schedule?: MonitorSchedule;
677
686
  webhook?: MonitorWebhookConfig | null;
678
687
  notification?: MonitorNotification | null;
@@ -692,7 +701,7 @@ export interface MonitorSummary {
692
701
  export interface Monitor {
693
702
  id: string;
694
703
  name: string;
695
- status: 'active' | 'paused' | 'deleted';
704
+ status: "active" | "paused" | "deleted";
696
705
  schedule: MonitorSchedule;
697
706
  nextRunAt?: string | null;
698
707
  lastRunAt?: string | null;
@@ -711,13 +720,13 @@ export interface MonitorCheck {
711
720
  id: string;
712
721
  monitorId: string;
713
722
  status:
714
- | 'queued'
715
- | 'running'
716
- | 'completed'
717
- | 'failed'
718
- | 'partial'
719
- | 'skipped_overlap';
720
- trigger: 'scheduled' | 'manual';
723
+ | "queued"
724
+ | "running"
725
+ | "completed"
726
+ | "failed"
727
+ | "partial"
728
+ | "skipped_overlap";
729
+ trigger: "scheduled" | "manual";
721
730
  scheduledFor?: string | null;
722
731
  startedAt?: string | null;
723
732
  finishedAt?: string | null;
@@ -725,11 +734,11 @@ export interface MonitorCheck {
725
734
  reservedCredits?: number | null;
726
735
  actualCredits?: number | null;
727
736
  billingStatus:
728
- | 'not_applicable'
729
- | 'reserved'
730
- | 'confirmed'
731
- | 'released'
732
- | 'failed';
737
+ | "not_applicable"
738
+ | "reserved"
739
+ | "confirmed"
740
+ | "released"
741
+ | "failed";
733
742
  summary: MonitorSummary;
734
743
  targetResults?: unknown;
735
744
  notificationStatus?: unknown;
@@ -738,17 +747,48 @@ export interface MonitorCheck {
738
747
  updatedAt: string;
739
748
  }
740
749
 
750
+ /** Per-field diff for monitors that requested JSON extraction. */
751
+ export interface MonitorJsonFieldDiff {
752
+ [field: string]: { previous: unknown; current: unknown };
753
+ }
754
+
755
+ /**
756
+ * Diff payload returned alongside a monitor page when its scrape produced
757
+ * a change. The shape depends on what the monitor's formats asked for:
758
+ *
759
+ * - markdown-only monitors → `{ text, json }` where `json` is the
760
+ * `parseDiff` AST (a `{ files: [...] }` object).
761
+ * - JSON-extraction monitors → `{ json }` where `json` is the per-field
762
+ * `{ previous, current }` map.
763
+ * - Mixed (JSON + git-diff) monitors → both `text` (markdown sidecar)
764
+ * and `json` (field-level diff) are present.
765
+ */
766
+ export interface MonitorPageDiff {
767
+ text?: string;
768
+ /** Markdown variants: parseDiff AST. JSON variants: per-field diff. */
769
+ json?: MonitorJsonFieldDiff | { files: unknown[] };
770
+ }
771
+
772
+ /**
773
+ * Snapshot of the current JSON extraction at this run. Present on JSON
774
+ * and mixed-mode monitors; absent for markdown-only.
775
+ */
776
+ export interface MonitorPageSnapshot {
777
+ json?: Record<string, unknown>;
778
+ }
779
+
741
780
  export interface MonitorCheckPage {
742
781
  id: string;
743
782
  targetId: string;
744
783
  url: string;
745
- status: 'same' | 'new' | 'changed' | 'removed' | 'error';
784
+ status: "same" | "new" | "changed" | "removed" | "error";
746
785
  previousScrapeId?: string | null;
747
786
  currentScrapeId?: string | null;
748
787
  statusCode?: number | null;
749
788
  error?: string | null;
750
789
  metadata?: unknown;
751
- diff?: unknown;
790
+ diff?: MonitorPageDiff | null;
791
+ snapshot?: MonitorPageSnapshot | null;
752
792
  createdAt: string;
753
793
  }
754
794
 
@@ -773,7 +813,7 @@ export type GetMonitorCheckOptions = PaginationConfig & {
773
813
  export interface ExtractResponse {
774
814
  success?: boolean;
775
815
  id?: string;
776
- status?: 'processing' | 'completed' | 'failed' | 'cancelled';
816
+ status?: "processing" | "completed" | "failed" | "cancelled";
777
817
  data?: unknown;
778
818
  error?: string;
779
819
  warning?: string;
@@ -792,16 +832,16 @@ export interface AgentResponse {
792
832
 
793
833
  export interface AgentStatusResponse {
794
834
  success: boolean;
795
- status: 'processing' | 'completed' | 'failed';
835
+ status: "processing" | "completed" | "failed";
796
836
  error?: string;
797
837
  data?: unknown;
798
- model?: 'spark-1-pro' | 'spark-1-mini';
838
+ model?: "spark-1-pro" | "spark-1-mini";
799
839
  expiresAt: string;
800
840
  creditsUsed?: number;
801
841
  }
802
842
 
803
843
  export interface AgentOptions {
804
- model: 'FIRE-1' | 'v3-beta';
844
+ model: "FIRE-1" | "v3-beta";
805
845
  }
806
846
 
807
847
  export interface ConcurrencyCheck {
@@ -887,10 +927,10 @@ export class SdkError extends Error {
887
927
  status?: number,
888
928
  code?: string,
889
929
  details?: unknown,
890
- jobId?: string
930
+ jobId?: string,
891
931
  ) {
892
932
  super(message);
893
- this.name = 'FirecrawlSdkError';
933
+ this.name = "FirecrawlSdkError";
894
934
  this.status = status;
895
935
  this.code = code;
896
936
  this.details = details;
@@ -900,16 +940,20 @@ export class SdkError extends Error {
900
940
 
901
941
  export class JobTimeoutError extends SdkError {
902
942
  timeoutSeconds: number;
903
- constructor(jobId: string, timeoutSeconds: number, jobType: 'batch' | 'crawl' = 'batch') {
904
- const jobTypeLabel = jobType === 'batch' ? 'batch scrape' : 'crawl';
943
+ constructor(
944
+ jobId: string,
945
+ timeoutSeconds: number,
946
+ jobType: "batch" | "crawl" = "batch",
947
+ ) {
948
+ const jobTypeLabel = jobType === "batch" ? "batch scrape" : "crawl";
905
949
  super(
906
950
  `${jobTypeLabel.charAt(0).toUpperCase() + jobTypeLabel.slice(1)} job ${jobId} did not complete within ${timeoutSeconds} seconds`,
907
951
  undefined,
908
- 'JOB_TIMEOUT',
952
+ "JOB_TIMEOUT",
909
953
  undefined,
910
- jobId
954
+ jobId,
911
955
  );
912
- this.name = 'JobTimeoutError';
956
+ this.name = "JobTimeoutError";
913
957
  this.timeoutSeconds = timeoutSeconds;
914
958
  }
915
959
  }
@@ -114,6 +114,9 @@ export function ensureValidParseFormats(formats?: ParseFormatOption[]): void {
114
114
  if (fmt === "branding") {
115
115
  throw new Error("parse does not support branding format");
116
116
  }
117
+ if (fmt === "audio" || fmt === "video") {
118
+ throw new Error(`parse does not support ${fmt} format`);
119
+ }
117
120
  continue;
118
121
  }
119
122
 
@@ -127,6 +130,9 @@ export function ensureValidParseFormats(formats?: ParseFormatOption[]): void {
127
130
  if (type === "branding") {
128
131
  throw new Error("parse does not support branding format");
129
132
  }
133
+ if (type === "audio" || type === "video") {
134
+ throw new Error(`parse does not support ${type} format`);
135
+ }
130
136
 
131
137
  if ((fmt as JsonFormat).type === "json") {
132
138
  const j = fmt as JsonFormat;