@mendable/firecrawl-js 4.18.5 → 4.20.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.
@@ -1,4 +1,8 @@
1
- import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from "axios";
1
+ import axios, {
2
+ type AxiosInstance,
3
+ type AxiosRequestConfig,
4
+ type AxiosResponse,
5
+ } from "axios";
2
6
  import { getVersion } from "./getVersion";
3
7
 
4
8
  export interface HttpClientOptions {
@@ -9,6 +13,11 @@ export interface HttpClientOptions {
9
13
  backoffFactor?: number; // seconds factor for 0.5, 1, 2...
10
14
  }
11
15
 
16
+ export interface RequestOptions {
17
+ headers?: Record<string, string>;
18
+ timeoutMs?: number;
19
+ }
20
+
12
21
  export class HttpClient {
13
22
  private instance: AxiosInstance;
14
23
  private readonly apiKey: string;
@@ -39,7 +48,9 @@ export class HttpClient {
39
48
  return this.apiKey;
40
49
  }
41
50
 
42
- private async request<T = any>(config: AxiosRequestConfig): Promise<AxiosResponse<T>> {
51
+ private async request<T = any>(
52
+ config: AxiosRequestConfig,
53
+ ): Promise<AxiosResponse<T>> {
43
54
  const version = getVersion();
44
55
  config.headers = {
45
56
  ...(config.headers || {}),
@@ -64,12 +75,13 @@ export class HttpClient {
64
75
  ["post", "put", "patch"].includes(cfg.method.toLowerCase())
65
76
  ) {
66
77
  const data = (cfg.data ?? {}) as Record<string, unknown>;
67
- cfg.data = { ...data, origin: typeof data.origin === "string" && data.origin.includes("mcp") ? data.origin : `js-sdk@${version}` };
68
-
69
- // If timeout is specified in the body, use it to override the request timeout
70
- if (typeof data.timeout === "number") {
71
- cfg.timeout = data.timeout + 5000;
72
- }
78
+ cfg.data = {
79
+ ...data,
80
+ origin:
81
+ typeof data.origin === "string" && data.origin.includes("mcp")
82
+ ? data.origin
83
+ : `js-sdk@${version}`,
84
+ };
73
85
  }
74
86
 
75
87
  if (isFormDataBody) {
@@ -98,25 +110,34 @@ export class HttpClient {
98
110
  }
99
111
 
100
112
  private sleep(seconds: number): Promise<void> {
101
- return new Promise((r) => setTimeout(r, seconds * 1000));
113
+ return new Promise(r => setTimeout(r, seconds * 1000));
102
114
  }
103
115
 
104
- post<T = any>(endpoint: string, body: Record<string, unknown>, headers?: Record<string, string>) {
105
- return this.request<T>({ method: "post", url: endpoint, data: body, headers });
116
+ post<T = any>(
117
+ endpoint: string,
118
+ body: Record<string, unknown>,
119
+ options?: RequestOptions,
120
+ ) {
121
+ return this.request<T>({
122
+ method: "post",
123
+ url: endpoint,
124
+ data: body,
125
+ headers: options?.headers,
126
+ timeout: options?.timeoutMs,
127
+ });
106
128
  }
107
129
 
108
130
  postMultipart<T = any>(
109
131
  endpoint: string,
110
132
  formData: FormData,
111
- headers?: Record<string, string>,
112
- timeoutMs?: number,
133
+ options?: RequestOptions,
113
134
  ) {
114
135
  return this.request<T>({
115
136
  method: "post",
116
137
  url: endpoint,
117
138
  data: formData,
118
- headers,
119
- timeout: timeoutMs,
139
+ headers: options?.headers,
140
+ timeout: options?.timeoutMs,
120
141
  });
121
142
  }
122
143
 
@@ -134,4 +155,3 @@ export class HttpClient {
134
155
  return headers;
135
156
  }
136
157
  }
137
-
@@ -139,7 +139,12 @@ export function ensureValidParseOptions(options?: ParseOptions): void {
139
139
  if (raw.mobile !== undefined) {
140
140
  throw new Error("parse does not support mobile rendering");
141
141
  }
142
- if (raw.maxAge !== undefined || raw.minAge !== undefined || raw.storeInCache !== undefined) {
142
+ if (
143
+ raw.maxAge !== undefined ||
144
+ raw.minAge !== undefined ||
145
+ raw.storeInCache !== undefined ||
146
+ raw.lockdown !== undefined
147
+ ) {
143
148
  throw new Error("parse does not support cache/index options");
144
149
  }
145
150
  if (raw.proxy !== undefined && raw.proxy !== "basic" && raw.proxy !== "auto") {