@mendable/firecrawl-js 4.19.0 → 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.
- package/audit-ci.jsonc +5 -2
- package/dist/{chunk-JJY4NJXL.js → chunk-UXVHRV2G.js} +1 -1
- package/dist/index.cjs +118 -47
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +119 -48
- package/dist/{package-HMEPZJ3J.js → package-ELM7Z5VP.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/unit/v2/scrape-browser.unit.test.ts +39 -12
- package/src/v2/methods/batch.ts +89 -28
- package/src/v2/methods/browser.ts +19 -11
- package/src/v2/methods/map.ts +36 -9
- package/src/v2/methods/parse.ts +15 -9
- package/src/v2/methods/scrape.ts +32 -13
- package/src/v2/methods/search.ts +38 -10
- package/src/v2/utils/httpClient.ts +36 -16
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import 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>(
|
|
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 = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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(
|
|
113
|
+
return new Promise(r => setTimeout(r, seconds * 1000));
|
|
102
114
|
}
|
|
103
115
|
|
|
104
|
-
post<T = any>(
|
|
105
|
-
|
|
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
|
-
|
|
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
|
-
|