@mendable/firecrawl 3.1.0 → 3.3.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/dist/{chunk-WNGXI3ZW.js → chunk-Y3QF4XAJ.js} +1 -1
- package/dist/index.cjs +6 -2
- package/dist/index.d.cts +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +7 -3
- package/dist/{package-KMFB7KZD.js → package-LI2S3JCZ.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/e2e/v2/scrape.test.ts +33 -0
- package/src/__tests__/unit/v2/clientOptions.test.ts +55 -0
- package/src/__tests__/unit/v2/validation.test.ts +12 -5
- package/src/index.ts +10 -4
- package/src/v2/methods/search.ts +1 -0
- package/src/v2/types.ts +25 -2
|
@@ -8,7 +8,7 @@ var require_package = __commonJS({
|
|
|
8
8
|
"package.json"(exports, module) {
|
|
9
9
|
module.exports = {
|
|
10
10
|
name: "@mendable/firecrawl-js",
|
|
11
|
-
version: "3.
|
|
11
|
+
version: "3.3.0",
|
|
12
12
|
description: "JavaScript SDK for Firecrawl API",
|
|
13
13
|
main: "dist/index.js",
|
|
14
14
|
types: "dist/index.d.ts",
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var require_package = __commonJS({
|
|
|
35
35
|
"package.json"(exports2, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "@mendable/firecrawl-js",
|
|
38
|
-
version: "3.
|
|
38
|
+
version: "3.3.0",
|
|
39
39
|
description: "JavaScript SDK for Firecrawl API",
|
|
40
40
|
main: "dist/index.js",
|
|
41
41
|
types: "dist/index.d.ts",
|
|
@@ -316,6 +316,7 @@ function prepareSearchPayload(req) {
|
|
|
316
316
|
query: req.query
|
|
317
317
|
};
|
|
318
318
|
if (req.sources) payload.sources = req.sources;
|
|
319
|
+
if (req.categories) payload.categories = req.categories;
|
|
319
320
|
if (req.limit != null) payload.limit = req.limit;
|
|
320
321
|
if (req.tbs != null) payload.tbs = req.tbs;
|
|
321
322
|
if (req.location != null) payload.location = req.location;
|
|
@@ -2347,7 +2348,10 @@ var Firecrawl = class extends FirecrawlClient {
|
|
|
2347
2348
|
/** @param opts API credentials and base URL. */
|
|
2348
2349
|
constructor(opts = {}) {
|
|
2349
2350
|
super(opts);
|
|
2350
|
-
this._v1Opts =
|
|
2351
|
+
this._v1Opts = {
|
|
2352
|
+
apiKey: opts.apiKey,
|
|
2353
|
+
apiUrl: opts.apiUrl
|
|
2354
|
+
};
|
|
2351
2355
|
}
|
|
2352
2356
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
2353
2357
|
get v1() {
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { AxiosResponse, AxiosRequestHeaders } from 'axios';
|
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import { TypedEventTarget } from 'typescript-event-target';
|
|
6
6
|
|
|
7
|
-
type FormatString = "markdown" | "html" | "rawHtml" | "links" | "screenshot" | "summary" | "changeTracking" | "json";
|
|
7
|
+
type FormatString = "markdown" | "html" | "rawHtml" | "links" | "images" | "screenshot" | "summary" | "changeTracking" | "json" | "attributes";
|
|
8
8
|
interface Viewport {
|
|
9
9
|
width: number;
|
|
10
10
|
height: number;
|
|
@@ -33,7 +33,14 @@ interface ChangeTrackingFormat extends Format {
|
|
|
33
33
|
prompt?: string;
|
|
34
34
|
tag?: string;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
interface AttributesFormat extends Format {
|
|
37
|
+
type: "attributes";
|
|
38
|
+
selectors: Array<{
|
|
39
|
+
selector: string;
|
|
40
|
+
attribute: string;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
type FormatOption = FormatString | Format | JsonFormat | ChangeTrackingFormat | ScreenshotFormat | AttributesFormat;
|
|
37
44
|
interface LocationConfig {
|
|
38
45
|
country?: string;
|
|
39
46
|
languages?: string[];
|
|
@@ -133,7 +140,13 @@ interface Document {
|
|
|
133
140
|
summary?: string;
|
|
134
141
|
metadata?: DocumentMetadata;
|
|
135
142
|
links?: string[];
|
|
143
|
+
images?: string[];
|
|
136
144
|
screenshot?: string;
|
|
145
|
+
attributes?: Array<{
|
|
146
|
+
selector: string;
|
|
147
|
+
attribute: string;
|
|
148
|
+
values: string[];
|
|
149
|
+
}>;
|
|
137
150
|
actions?: Record<string, unknown>;
|
|
138
151
|
warning?: string;
|
|
139
152
|
changeTracking?: Record<string, unknown>;
|
|
@@ -142,6 +155,7 @@ interface SearchResultWeb {
|
|
|
142
155
|
url: string;
|
|
143
156
|
title?: string;
|
|
144
157
|
description?: string;
|
|
158
|
+
category?: string;
|
|
145
159
|
}
|
|
146
160
|
interface SearchResultNews {
|
|
147
161
|
title?: string;
|
|
@@ -150,6 +164,7 @@ interface SearchResultNews {
|
|
|
150
164
|
date?: string;
|
|
151
165
|
imageUrl?: string;
|
|
152
166
|
position?: number;
|
|
167
|
+
category?: string;
|
|
153
168
|
}
|
|
154
169
|
interface SearchResultImages {
|
|
155
170
|
title?: string;
|
|
@@ -164,11 +179,15 @@ interface SearchData {
|
|
|
164
179
|
news?: Array<SearchResultNews | Document>;
|
|
165
180
|
images?: Array<SearchResultImages | Document>;
|
|
166
181
|
}
|
|
182
|
+
interface CategoryOption {
|
|
183
|
+
type: "github" | "research";
|
|
184
|
+
}
|
|
167
185
|
interface SearchRequest {
|
|
168
186
|
query: string;
|
|
169
187
|
sources?: Array<"web" | "news" | "images" | {
|
|
170
188
|
type: "web" | "news" | "images";
|
|
171
189
|
}>;
|
|
190
|
+
categories?: Array<"github" | "research" | CategoryOption>;
|
|
172
191
|
limit?: number;
|
|
173
192
|
tbs?: string;
|
|
174
193
|
location?: string;
|
|
@@ -1337,9 +1356,9 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1337
1356
|
private _v1?;
|
|
1338
1357
|
private _v1Opts;
|
|
1339
1358
|
/** @param opts API credentials and base URL. */
|
|
1340
|
-
constructor(opts?:
|
|
1359
|
+
constructor(opts?: FirecrawlClientOptions);
|
|
1341
1360
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
1342
1361
|
get v1(): FirecrawlApp;
|
|
1343
1362
|
}
|
|
1344
1363
|
|
|
1345
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
1364
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { AxiosResponse, AxiosRequestHeaders } from 'axios';
|
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import { TypedEventTarget } from 'typescript-event-target';
|
|
6
6
|
|
|
7
|
-
type FormatString = "markdown" | "html" | "rawHtml" | "links" | "screenshot" | "summary" | "changeTracking" | "json";
|
|
7
|
+
type FormatString = "markdown" | "html" | "rawHtml" | "links" | "images" | "screenshot" | "summary" | "changeTracking" | "json" | "attributes";
|
|
8
8
|
interface Viewport {
|
|
9
9
|
width: number;
|
|
10
10
|
height: number;
|
|
@@ -33,7 +33,14 @@ interface ChangeTrackingFormat extends Format {
|
|
|
33
33
|
prompt?: string;
|
|
34
34
|
tag?: string;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
interface AttributesFormat extends Format {
|
|
37
|
+
type: "attributes";
|
|
38
|
+
selectors: Array<{
|
|
39
|
+
selector: string;
|
|
40
|
+
attribute: string;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
type FormatOption = FormatString | Format | JsonFormat | ChangeTrackingFormat | ScreenshotFormat | AttributesFormat;
|
|
37
44
|
interface LocationConfig {
|
|
38
45
|
country?: string;
|
|
39
46
|
languages?: string[];
|
|
@@ -133,7 +140,13 @@ interface Document {
|
|
|
133
140
|
summary?: string;
|
|
134
141
|
metadata?: DocumentMetadata;
|
|
135
142
|
links?: string[];
|
|
143
|
+
images?: string[];
|
|
136
144
|
screenshot?: string;
|
|
145
|
+
attributes?: Array<{
|
|
146
|
+
selector: string;
|
|
147
|
+
attribute: string;
|
|
148
|
+
values: string[];
|
|
149
|
+
}>;
|
|
137
150
|
actions?: Record<string, unknown>;
|
|
138
151
|
warning?: string;
|
|
139
152
|
changeTracking?: Record<string, unknown>;
|
|
@@ -142,6 +155,7 @@ interface SearchResultWeb {
|
|
|
142
155
|
url: string;
|
|
143
156
|
title?: string;
|
|
144
157
|
description?: string;
|
|
158
|
+
category?: string;
|
|
145
159
|
}
|
|
146
160
|
interface SearchResultNews {
|
|
147
161
|
title?: string;
|
|
@@ -150,6 +164,7 @@ interface SearchResultNews {
|
|
|
150
164
|
date?: string;
|
|
151
165
|
imageUrl?: string;
|
|
152
166
|
position?: number;
|
|
167
|
+
category?: string;
|
|
153
168
|
}
|
|
154
169
|
interface SearchResultImages {
|
|
155
170
|
title?: string;
|
|
@@ -164,11 +179,15 @@ interface SearchData {
|
|
|
164
179
|
news?: Array<SearchResultNews | Document>;
|
|
165
180
|
images?: Array<SearchResultImages | Document>;
|
|
166
181
|
}
|
|
182
|
+
interface CategoryOption {
|
|
183
|
+
type: "github" | "research";
|
|
184
|
+
}
|
|
167
185
|
interface SearchRequest {
|
|
168
186
|
query: string;
|
|
169
187
|
sources?: Array<"web" | "news" | "images" | {
|
|
170
188
|
type: "web" | "news" | "images";
|
|
171
189
|
}>;
|
|
190
|
+
categories?: Array<"github" | "research" | CategoryOption>;
|
|
172
191
|
limit?: number;
|
|
173
192
|
tbs?: string;
|
|
174
193
|
location?: string;
|
|
@@ -1337,9 +1356,9 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1337
1356
|
private _v1?;
|
|
1338
1357
|
private _v1Opts;
|
|
1339
1358
|
/** @param opts API credentials and base URL. */
|
|
1340
|
-
constructor(opts?:
|
|
1359
|
+
constructor(opts?: FirecrawlClientOptions);
|
|
1341
1360
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
1342
1361
|
get v1(): FirecrawlApp;
|
|
1343
1362
|
}
|
|
1344
1363
|
|
|
1345
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
1364
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
require_package
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Y3QF4XAJ.js";
|
|
4
4
|
|
|
5
5
|
// src/v2/utils/httpClient.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -200,6 +200,7 @@ function prepareSearchPayload(req) {
|
|
|
200
200
|
query: req.query
|
|
201
201
|
};
|
|
202
202
|
if (req.sources) payload.sources = req.sources;
|
|
203
|
+
if (req.categories) payload.categories = req.categories;
|
|
203
204
|
if (req.limit != null) payload.limit = req.limit;
|
|
204
205
|
if (req.tbs != null) payload.tbs = req.tbs;
|
|
205
206
|
if (req.location != null) payload.location = req.location;
|
|
@@ -932,7 +933,7 @@ var FirecrawlApp = class {
|
|
|
932
933
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
933
934
|
return process.env.npm_package_version;
|
|
934
935
|
}
|
|
935
|
-
const packageJson = await import("./package-
|
|
936
|
+
const packageJson = await import("./package-LI2S3JCZ.js");
|
|
936
937
|
return packageJson.default.version;
|
|
937
938
|
} catch (error) {
|
|
938
939
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
|
@@ -2231,7 +2232,10 @@ var Firecrawl = class extends FirecrawlClient {
|
|
|
2231
2232
|
/** @param opts API credentials and base URL. */
|
|
2232
2233
|
constructor(opts = {}) {
|
|
2233
2234
|
super(opts);
|
|
2234
|
-
this._v1Opts =
|
|
2235
|
+
this._v1Opts = {
|
|
2236
|
+
apiKey: opts.apiKey,
|
|
2237
|
+
apiUrl: opts.apiUrl
|
|
2238
|
+
};
|
|
2235
2239
|
}
|
|
2236
2240
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
2237
2241
|
get v1() {
|
package/package.json
CHANGED
|
@@ -121,6 +121,39 @@ describe("v2.scrape e2e", () => {
|
|
|
121
121
|
}
|
|
122
122
|
}, 90_000);
|
|
123
123
|
|
|
124
|
+
test("images format: extract all images from webpage", async () => {
|
|
125
|
+
if (!client) throw new Error();
|
|
126
|
+
const doc = await client.scrape("https://firecrawl.dev", {
|
|
127
|
+
formats: ["images"],
|
|
128
|
+
});
|
|
129
|
+
expect(doc.images).toBeTruthy();
|
|
130
|
+
expect(Array.isArray(doc.images)).toBe(true);
|
|
131
|
+
expect(doc.images.length).toBeGreaterThan(0);
|
|
132
|
+
// Should find firecrawl logo/branding images
|
|
133
|
+
expect(doc.images.some(img => img.includes("firecrawl") || img.includes("logo"))).toBe(true);
|
|
134
|
+
}, 60_000);
|
|
135
|
+
|
|
136
|
+
test("images format: works with multiple formats", async () => {
|
|
137
|
+
if (!client) throw new Error();
|
|
138
|
+
const doc = await client.scrape("https://github.com", {
|
|
139
|
+
formats: ["markdown", "links", "images"],
|
|
140
|
+
});
|
|
141
|
+
expect(doc.markdown).toBeTruthy();
|
|
142
|
+
expect(doc.links).toBeTruthy();
|
|
143
|
+
expect(doc.images).toBeTruthy();
|
|
144
|
+
expect(Array.isArray(doc.images)).toBe(true);
|
|
145
|
+
expect(doc.images.length).toBeGreaterThan(0);
|
|
146
|
+
|
|
147
|
+
// Images should find things not available in links format
|
|
148
|
+
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg', '.ico'];
|
|
149
|
+
const linkImages = doc.links?.filter(link =>
|
|
150
|
+
imageExtensions.some(ext => link.toLowerCase().includes(ext))
|
|
151
|
+
) || [];
|
|
152
|
+
|
|
153
|
+
// Should discover additional images beyond those with obvious extensions
|
|
154
|
+
expect(doc.images.length).toBeGreaterThanOrEqual(linkImages.length);
|
|
155
|
+
}, 60_000);
|
|
156
|
+
|
|
124
157
|
test("invalid url should throw", async () => {
|
|
125
158
|
if (!client) throw new Error();
|
|
126
159
|
await expect(client.scrape("")).rejects.toThrow("URL cannot be empty");
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Firecrawl, type FirecrawlClientOptions } from '../../../index';
|
|
2
|
+
|
|
3
|
+
describe('Firecrawl v2 Client Options', () => {
|
|
4
|
+
it('should accept v2 options including timeoutMs, maxRetries, and backoffFactor', () => {
|
|
5
|
+
const options: FirecrawlClientOptions = {
|
|
6
|
+
apiKey: 'test-key',
|
|
7
|
+
timeoutMs: 300,
|
|
8
|
+
maxRetries: 5,
|
|
9
|
+
backoffFactor: 0.5,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// Should not throw any type errors
|
|
13
|
+
const client = new Firecrawl(options);
|
|
14
|
+
|
|
15
|
+
expect(client).toBeDefined();
|
|
16
|
+
expect(client).toBeInstanceOf(Firecrawl);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should work with minimal options', () => {
|
|
20
|
+
const options: FirecrawlClientOptions = {
|
|
21
|
+
apiKey: 'test-key',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const client = new Firecrawl(options);
|
|
25
|
+
|
|
26
|
+
expect(client).toBeDefined();
|
|
27
|
+
expect(client).toBeInstanceOf(Firecrawl);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should work with all v2 options', () => {
|
|
31
|
+
const options: FirecrawlClientOptions = {
|
|
32
|
+
apiKey: 'test-key',
|
|
33
|
+
apiUrl: 'https://custom-api.firecrawl.dev',
|
|
34
|
+
timeoutMs: 60000,
|
|
35
|
+
maxRetries: 3,
|
|
36
|
+
backoffFactor: 1.0,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const client = new Firecrawl(options);
|
|
40
|
+
|
|
41
|
+
expect(client).toBeDefined();
|
|
42
|
+
expect(client).toBeInstanceOf(Firecrawl);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should export FirecrawlClientOptions type', () => {
|
|
46
|
+
// This test ensures the type is properly exported
|
|
47
|
+
const options: FirecrawlClientOptions = {
|
|
48
|
+
apiKey: 'test-key',
|
|
49
|
+
timeoutMs: 300,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
expect(options.timeoutMs).toBe(300);
|
|
53
|
+
expect(options.apiKey).toBe('test-key');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -9,11 +9,18 @@ describe("v2 utils: validation", () => {
|
|
|
9
9
|
expect(() => ensureValidFormats(formats)).toThrow(/json format must be an object/i);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
test("ensureValidFormats: json format requires prompt
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
test("ensureValidFormats: json format requires prompt or schema", () => {
|
|
13
|
+
// Valid cases - should not throw
|
|
14
|
+
const valid1: FormatOption[] = [{ type: "json", prompt: "p" } as any];
|
|
15
|
+
const valid2: FormatOption[] = [{ type: "json", schema: {} } as any];
|
|
16
|
+
const valid3: FormatOption[] = [{ type: "json", prompt: "p", schema: {} } as any];
|
|
17
|
+
expect(() => ensureValidFormats(valid1)).not.toThrow();
|
|
18
|
+
expect(() => ensureValidFormats(valid2)).not.toThrow();
|
|
19
|
+
expect(() => ensureValidFormats(valid3)).not.toThrow();
|
|
20
|
+
|
|
21
|
+
// Invalid case - should throw when both are missing
|
|
22
|
+
const bad: FormatOption[] = [{ type: "json" } as any];
|
|
23
|
+
expect(() => ensureValidFormats(bad)).toThrow(/requires either 'prompt' or 'schema'/i);
|
|
17
24
|
});
|
|
18
25
|
|
|
19
26
|
test("ensureValidFormats: converts zod schema to JSON schema", () => {
|
package/src/index.ts
CHANGED
|
@@ -13,9 +13,12 @@ export * from "./v2/types";
|
|
|
13
13
|
export { default as FirecrawlAppV1 } from "./v1";
|
|
14
14
|
|
|
15
15
|
import V1 from "./v1";
|
|
16
|
-
import { FirecrawlClient as V2 } from "./v2/client";
|
|
16
|
+
import { FirecrawlClient as V2, type FirecrawlClientOptions } from "./v2/client";
|
|
17
17
|
import type { FirecrawlAppConfig } from "./v1";
|
|
18
18
|
|
|
19
|
+
// Re-export v2 client options for convenience
|
|
20
|
+
export type { FirecrawlClientOptions } from "./v2/client";
|
|
21
|
+
|
|
19
22
|
/** Unified client: extends v2 and adds `.v1` for backward compatibility. */
|
|
20
23
|
export class Firecrawl extends V2 {
|
|
21
24
|
/** Feature‑frozen v1 client (lazy). */
|
|
@@ -23,9 +26,12 @@ export class Firecrawl extends V2 {
|
|
|
23
26
|
private _v1Opts: FirecrawlAppConfig;
|
|
24
27
|
|
|
25
28
|
/** @param opts API credentials and base URL. */
|
|
26
|
-
constructor(opts:
|
|
27
|
-
super(opts
|
|
28
|
-
this._v1Opts =
|
|
29
|
+
constructor(opts: FirecrawlClientOptions = {}) {
|
|
30
|
+
super(opts);
|
|
31
|
+
this._v1Opts = {
|
|
32
|
+
apiKey: opts.apiKey,
|
|
33
|
+
apiUrl: opts.apiUrl,
|
|
34
|
+
};
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
/** Access the legacy v1 client (instantiated on first access). */
|
package/src/v2/methods/search.ts
CHANGED
|
@@ -11,6 +11,7 @@ function prepareSearchPayload(req: SearchRequest): Record<string, unknown> {
|
|
|
11
11
|
query: req.query,
|
|
12
12
|
};
|
|
13
13
|
if (req.sources) payload.sources = req.sources;
|
|
14
|
+
if (req.categories) payload.categories = req.categories;
|
|
14
15
|
if (req.limit != null) payload.limit = req.limit;
|
|
15
16
|
if (req.tbs != null) payload.tbs = req.tbs;
|
|
16
17
|
if (req.location != null) payload.location = req.location;
|
package/src/v2/types.ts
CHANGED
|
@@ -6,10 +6,12 @@ export type FormatString =
|
|
|
6
6
|
| "html"
|
|
7
7
|
| "rawHtml"
|
|
8
8
|
| "links"
|
|
9
|
+
| "images"
|
|
9
10
|
| "screenshot"
|
|
10
11
|
| "summary"
|
|
11
12
|
| "changeTracking"
|
|
12
|
-
| "json"
|
|
13
|
+
| "json"
|
|
14
|
+
| "attributes";
|
|
13
15
|
|
|
14
16
|
export interface Viewport {
|
|
15
17
|
width: number;
|
|
@@ -40,13 +42,21 @@ export interface ChangeTrackingFormat extends Format {
|
|
|
40
42
|
prompt?: string;
|
|
41
43
|
tag?: string;
|
|
42
44
|
}
|
|
45
|
+
export interface AttributesFormat extends Format {
|
|
46
|
+
type: "attributes";
|
|
47
|
+
selectors: Array<{
|
|
48
|
+
selector: string;
|
|
49
|
+
attribute: string;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
43
52
|
|
|
44
53
|
export type FormatOption =
|
|
45
54
|
| FormatString
|
|
46
55
|
| Format
|
|
47
56
|
| JsonFormat
|
|
48
57
|
| ChangeTrackingFormat
|
|
49
|
-
| ScreenshotFormat
|
|
58
|
+
| ScreenshotFormat
|
|
59
|
+
| AttributesFormat;
|
|
50
60
|
|
|
51
61
|
export interface LocationConfig {
|
|
52
62
|
country?: string;
|
|
@@ -167,7 +177,13 @@ export interface Document {
|
|
|
167
177
|
summary?: string;
|
|
168
178
|
metadata?: DocumentMetadata;
|
|
169
179
|
links?: string[];
|
|
180
|
+
images?: string[];
|
|
170
181
|
screenshot?: string;
|
|
182
|
+
attributes?: Array<{
|
|
183
|
+
selector: string;
|
|
184
|
+
attribute: string;
|
|
185
|
+
values: string[];
|
|
186
|
+
}>;
|
|
171
187
|
actions?: Record<string, unknown>;
|
|
172
188
|
warning?: string;
|
|
173
189
|
changeTracking?: Record<string, unknown>;
|
|
@@ -177,6 +193,7 @@ export interface SearchResultWeb {
|
|
|
177
193
|
url: string;
|
|
178
194
|
title?: string;
|
|
179
195
|
description?: string;
|
|
196
|
+
category?: string;
|
|
180
197
|
}
|
|
181
198
|
|
|
182
199
|
export interface SearchResultNews {
|
|
@@ -186,6 +203,7 @@ export interface SearchResultNews {
|
|
|
186
203
|
date?: string;
|
|
187
204
|
imageUrl?: string;
|
|
188
205
|
position?: number;
|
|
206
|
+
category?: string;
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
export interface SearchResultImages {
|
|
@@ -203,9 +221,14 @@ export interface SearchData {
|
|
|
203
221
|
images?: Array<SearchResultImages | Document>;
|
|
204
222
|
}
|
|
205
223
|
|
|
224
|
+
export interface CategoryOption {
|
|
225
|
+
type: "github" | "research";
|
|
226
|
+
}
|
|
227
|
+
|
|
206
228
|
export interface SearchRequest {
|
|
207
229
|
query: string;
|
|
208
230
|
sources?: Array<"web" | "news" | "images" | { type: "web" | "news" | "images" }>;
|
|
231
|
+
categories?: Array<"github" | "research" | CategoryOption>;
|
|
209
232
|
limit?: number;
|
|
210
233
|
tbs?: string;
|
|
211
234
|
location?: string;
|