firecrawl 4.24.1 → 4.25.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-F3RFBUTZ.js → chunk-46XQC2QL.js} +2 -2
- package/dist/index.cjs +76 -12
- package/dist/index.d.cts +46 -5
- package/dist/index.d.ts +46 -5
- package/dist/index.js +76 -12
- package/dist/{package-B3VSS5SY.js → package-MW3GMNCL.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/unit/v2/clientOptions.test.ts +29 -1
- package/src/__tests__/unit/v2/prototype-discoverability.test.ts +45 -0
- package/src/__tests__/unit/v2/search-data-property.test.ts +66 -0
- package/src/__tests__/unit/v2/v1-aliases.test.ts +32 -0
- package/src/index.ts +20 -7
- package/src/v2/client.ts +63 -7
- package/src/v2/methods/search.ts +14 -0
- package/src/v2/types.ts +14 -0
|
@@ -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: "4.
|
|
11
|
+
version: "4.25.0",
|
|
12
12
|
description: "JavaScript SDK for Firecrawl API",
|
|
13
13
|
main: "dist/index.js",
|
|
14
14
|
types: "dist/index.d.ts",
|
|
@@ -77,7 +77,7 @@ var require_package = __commonJS({
|
|
|
77
77
|
"rollup@<4.59.0": ">=4.59.0",
|
|
78
78
|
"picomatch@<4.0.4": ">=4.0.4",
|
|
79
79
|
handlebars: ">=4.7.9",
|
|
80
|
-
"brace-expansion": ">=5.0.
|
|
80
|
+
"brace-expansion": ">=5.0.6",
|
|
81
81
|
"axios@<1.15.2": "1.15.2",
|
|
82
82
|
"follow-redirects@<1.16.0": ">=1.16.0 <2.0.0"
|
|
83
83
|
}
|
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: "4.
|
|
38
|
+
version: "4.25.0",
|
|
39
39
|
description: "JavaScript SDK for Firecrawl API",
|
|
40
40
|
main: "dist/index.js",
|
|
41
41
|
types: "dist/index.d.ts",
|
|
@@ -104,7 +104,7 @@ var require_package = __commonJS({
|
|
|
104
104
|
"rollup@<4.59.0": ">=4.59.0",
|
|
105
105
|
"picomatch@<4.0.4": ">=4.0.4",
|
|
106
106
|
handlebars: ">=4.7.9",
|
|
107
|
-
"brace-expansion": ">=5.0.
|
|
107
|
+
"brace-expansion": ">=5.0.6",
|
|
108
108
|
"axios@<1.15.2": "1.15.2",
|
|
109
109
|
"follow-redirects@<1.16.0": ">=1.16.0 <2.0.0"
|
|
110
110
|
}
|
|
@@ -746,6 +746,20 @@ async function search(http, request) {
|
|
|
746
746
|
if (data.news) out.news = transformArray(data.news);
|
|
747
747
|
if (data.images)
|
|
748
748
|
out.images = transformArray(data.images);
|
|
749
|
+
Object.defineProperty(out, "data", {
|
|
750
|
+
get() {
|
|
751
|
+
const parts = [];
|
|
752
|
+
if (out.web?.length) parts.push(`.web (${out.web.length} results)`);
|
|
753
|
+
if (out.news?.length) parts.push(`.news (${out.news.length} results)`);
|
|
754
|
+
if (out.images?.length) parts.push(`.images (${out.images.length} results)`);
|
|
755
|
+
const available = parts.length ? parts.join(", ") : ".web, .news, or .images";
|
|
756
|
+
throw new Error(
|
|
757
|
+
`SearchData has no '.data'. Results are grouped by source: ${available}`
|
|
758
|
+
);
|
|
759
|
+
},
|
|
760
|
+
enumerable: false,
|
|
761
|
+
configurable: true
|
|
762
|
+
});
|
|
749
763
|
return out;
|
|
750
764
|
} catch (err) {
|
|
751
765
|
if (err?.isAxiosError) return normalizeAxiosError(err, "search");
|
|
@@ -1781,20 +1795,21 @@ var FirecrawlClient = class {
|
|
|
1781
1795
|
}
|
|
1782
1796
|
/**
|
|
1783
1797
|
* Create a v2 client.
|
|
1784
|
-
* @param options
|
|
1798
|
+
* @param options API key string or transport configuration object.
|
|
1785
1799
|
*/
|
|
1786
1800
|
constructor(options = {}) {
|
|
1787
|
-
const
|
|
1788
|
-
const
|
|
1801
|
+
const opts = typeof options === "string" ? { apiKey: options } : options;
|
|
1802
|
+
const apiKey = (opts.apiKey ?? process.env.FIRECRAWL_API_KEY ?? "").trim();
|
|
1803
|
+
const apiUrl = (opts.apiUrl ?? process.env.FIRECRAWL_API_URL ?? "https://api.firecrawl.dev").replace(/\/$/, "");
|
|
1789
1804
|
if (this.isCloudService(apiUrl) && !apiKey) {
|
|
1790
1805
|
throw new Error("API key is required for the cloud API. Set FIRECRAWL_API_KEY env or pass apiKey.");
|
|
1791
1806
|
}
|
|
1792
1807
|
this.http = new HttpClient({
|
|
1793
1808
|
apiKey,
|
|
1794
1809
|
apiUrl,
|
|
1795
|
-
timeoutMs:
|
|
1796
|
-
maxRetries:
|
|
1797
|
-
backoffFactor:
|
|
1810
|
+
timeoutMs: opts.timeoutMs,
|
|
1811
|
+
maxRetries: opts.maxRetries,
|
|
1812
|
+
backoffFactor: opts.backoffFactor
|
|
1798
1813
|
});
|
|
1799
1814
|
}
|
|
1800
1815
|
async scrape(url, options) {
|
|
@@ -2131,6 +2146,46 @@ var FirecrawlClient = class {
|
|
|
2131
2146
|
watcher(jobId, opts = {}) {
|
|
2132
2147
|
return new Watcher(this.http, jobId, opts);
|
|
2133
2148
|
}
|
|
2149
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer scrape(). */
|
|
2150
|
+
async scrapeUrl(url, options) {
|
|
2151
|
+
return this.scrape(url, options);
|
|
2152
|
+
}
|
|
2153
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer crawl(). */
|
|
2154
|
+
async crawlUrl(url, req = {}) {
|
|
2155
|
+
return this.crawl(url, req);
|
|
2156
|
+
}
|
|
2157
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startCrawl(). */
|
|
2158
|
+
async asyncCrawlUrl(url, req = {}) {
|
|
2159
|
+
return this.startCrawl(url, req);
|
|
2160
|
+
}
|
|
2161
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlStatus(). */
|
|
2162
|
+
async checkCrawlStatus(jobId, pagination) {
|
|
2163
|
+
return this.getCrawlStatus(jobId, pagination);
|
|
2164
|
+
}
|
|
2165
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlErrors(). */
|
|
2166
|
+
async checkCrawlErrors(crawlId) {
|
|
2167
|
+
return this.getCrawlErrors(crawlId);
|
|
2168
|
+
}
|
|
2169
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer map(). */
|
|
2170
|
+
async mapUrl(url, options) {
|
|
2171
|
+
return this.map(url, options);
|
|
2172
|
+
}
|
|
2173
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer batchScrape(). */
|
|
2174
|
+
async batchScrapeUrls(urls, opts) {
|
|
2175
|
+
return this.batchScrape(urls, opts);
|
|
2176
|
+
}
|
|
2177
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startBatchScrape(). */
|
|
2178
|
+
async asyncBatchScrapeUrls(urls, opts) {
|
|
2179
|
+
return this.startBatchScrape(urls, opts);
|
|
2180
|
+
}
|
|
2181
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeStatus(). */
|
|
2182
|
+
async checkBatchScrapeStatus(jobId, pagination) {
|
|
2183
|
+
return this.getBatchScrapeStatus(jobId, pagination);
|
|
2184
|
+
}
|
|
2185
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeErrors(). */
|
|
2186
|
+
async checkBatchScrapeErrors(jobId) {
|
|
2187
|
+
return this.getBatchScrapeErrors(jobId);
|
|
2188
|
+
}
|
|
2134
2189
|
};
|
|
2135
2190
|
|
|
2136
2191
|
// src/v1/index.ts
|
|
@@ -3534,12 +3589,13 @@ var Firecrawl = class extends FirecrawlClient {
|
|
|
3534
3589
|
/** Feature‑frozen v1 client (lazy). */
|
|
3535
3590
|
_v1;
|
|
3536
3591
|
_v1Opts;
|
|
3537
|
-
/** @param opts API
|
|
3592
|
+
/** @param opts API key string or credentials object. */
|
|
3538
3593
|
constructor(opts = {}) {
|
|
3539
|
-
|
|
3594
|
+
const resolved = typeof opts === "string" ? { apiKey: opts } : opts;
|
|
3595
|
+
super(resolved);
|
|
3540
3596
|
this._v1Opts = {
|
|
3541
|
-
apiKey:
|
|
3542
|
-
apiUrl:
|
|
3597
|
+
apiKey: resolved.apiKey,
|
|
3598
|
+
apiUrl: resolved.apiUrl
|
|
3543
3599
|
};
|
|
3544
3600
|
}
|
|
3545
3601
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
@@ -3548,6 +3604,14 @@ var Firecrawl = class extends FirecrawlClient {
|
|
|
3548
3604
|
return this._v1;
|
|
3549
3605
|
}
|
|
3550
3606
|
};
|
|
3607
|
+
(function exposeV2MethodsOnTopLevel() {
|
|
3608
|
+
for (const name of Object.getOwnPropertyNames(FirecrawlClient.prototype)) {
|
|
3609
|
+
if (name === "constructor") continue;
|
|
3610
|
+
if (Object.prototype.hasOwnProperty.call(Firecrawl.prototype, name)) continue;
|
|
3611
|
+
const desc = Object.getOwnPropertyDescriptor(FirecrawlClient.prototype, name);
|
|
3612
|
+
if (desc) Object.defineProperty(Firecrawl.prototype, name, desc);
|
|
3613
|
+
}
|
|
3614
|
+
})();
|
|
3551
3615
|
var index_default = Firecrawl;
|
|
3552
3616
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3553
3617
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -552,6 +552,8 @@ interface CreateMonitorRequest {
|
|
|
552
552
|
notification?: MonitorNotification;
|
|
553
553
|
targets: MonitorTarget[];
|
|
554
554
|
retentionDays?: number;
|
|
555
|
+
goal?: string;
|
|
556
|
+
judgeEnabled?: boolean;
|
|
555
557
|
}
|
|
556
558
|
interface UpdateMonitorRequest {
|
|
557
559
|
name?: string;
|
|
@@ -561,6 +563,8 @@ interface UpdateMonitorRequest {
|
|
|
561
563
|
notification?: MonitorNotification | null;
|
|
562
564
|
targets?: MonitorTarget[];
|
|
563
565
|
retentionDays?: number;
|
|
566
|
+
goal?: string | null;
|
|
567
|
+
judgeEnabled?: boolean;
|
|
564
568
|
}
|
|
565
569
|
interface MonitorSummary {
|
|
566
570
|
totalPages: number;
|
|
@@ -584,9 +588,17 @@ interface Monitor {
|
|
|
584
588
|
retentionDays: number;
|
|
585
589
|
estimatedCreditsPerMonth?: number | null;
|
|
586
590
|
lastCheckSummary?: MonitorSummary | null;
|
|
591
|
+
goal?: string | null;
|
|
592
|
+
judgeEnabled?: boolean;
|
|
587
593
|
createdAt: string;
|
|
588
594
|
updatedAt: string;
|
|
589
595
|
}
|
|
596
|
+
interface MonitorPageJudgment {
|
|
597
|
+
meaningful: boolean;
|
|
598
|
+
confidence: "high" | "medium" | "low";
|
|
599
|
+
reason: string;
|
|
600
|
+
fields: string[];
|
|
601
|
+
}
|
|
590
602
|
interface MonitorCheck {
|
|
591
603
|
id: string;
|
|
592
604
|
monitorId: string;
|
|
@@ -650,6 +662,7 @@ interface MonitorCheckPage {
|
|
|
650
662
|
metadata?: unknown;
|
|
651
663
|
diff?: MonitorPageDiff | null;
|
|
652
664
|
snapshot?: MonitorPageSnapshot | null;
|
|
665
|
+
judgment?: MonitorPageJudgment | null;
|
|
653
666
|
createdAt: string;
|
|
654
667
|
}
|
|
655
668
|
interface MonitorCheckDetail extends MonitorCheck {
|
|
@@ -960,6 +973,8 @@ interface FirecrawlClientOptions {
|
|
|
960
973
|
/** Exponential backoff factor for retries (optional). */
|
|
961
974
|
backoffFactor?: number;
|
|
962
975
|
}
|
|
976
|
+
/** Accepts a plain API key string or a full options object. */
|
|
977
|
+
type FirecrawlClientInput = FirecrawlClientOptions | string;
|
|
963
978
|
/**
|
|
964
979
|
* Firecrawl v2 client. Provides typed access to all v2 endpoints and utilities.
|
|
965
980
|
*/
|
|
@@ -968,9 +983,9 @@ declare class FirecrawlClient {
|
|
|
968
983
|
private isCloudService;
|
|
969
984
|
/**
|
|
970
985
|
* Create a v2 client.
|
|
971
|
-
* @param options
|
|
986
|
+
* @param options API key string or transport configuration object.
|
|
972
987
|
*/
|
|
973
|
-
constructor(options?:
|
|
988
|
+
constructor(options?: FirecrawlClientInput);
|
|
974
989
|
/**
|
|
975
990
|
* Scrape a single URL.
|
|
976
991
|
* @param url Target URL.
|
|
@@ -1234,6 +1249,32 @@ declare class FirecrawlClient {
|
|
|
1234
1249
|
* @param opts Watcher options (kind, pollInterval, timeout seconds).
|
|
1235
1250
|
*/
|
|
1236
1251
|
watcher(jobId: string, opts?: WatcherOptions): Watcher;
|
|
1252
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer scrape(). */
|
|
1253
|
+
scrapeUrl(url: string, options?: ScrapeOptions): Promise<Document>;
|
|
1254
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer crawl(). */
|
|
1255
|
+
crawlUrl(url: string, req?: CrawlOptions & {
|
|
1256
|
+
pollInterval?: number;
|
|
1257
|
+
timeout?: number;
|
|
1258
|
+
}): Promise<CrawlJob>;
|
|
1259
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startCrawl(). */
|
|
1260
|
+
asyncCrawlUrl(url: string, req?: CrawlOptions): Promise<CrawlResponse$1>;
|
|
1261
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlStatus(). */
|
|
1262
|
+
checkCrawlStatus(jobId: string, pagination?: PaginationConfig): Promise<CrawlJob>;
|
|
1263
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlErrors(). */
|
|
1264
|
+
checkCrawlErrors(crawlId: string): Promise<CrawlErrorsResponse$1>;
|
|
1265
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer map(). */
|
|
1266
|
+
mapUrl(url: string, options?: MapOptions): Promise<MapData>;
|
|
1267
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer batchScrape(). */
|
|
1268
|
+
batchScrapeUrls(urls: string[], opts?: BatchScrapeOptions & {
|
|
1269
|
+
pollInterval?: number;
|
|
1270
|
+
timeout?: number;
|
|
1271
|
+
}): Promise<BatchScrapeJob>;
|
|
1272
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startBatchScrape(). */
|
|
1273
|
+
asyncBatchScrapeUrls(urls: string[], opts?: BatchScrapeOptions): Promise<BatchScrapeResponse$1>;
|
|
1274
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeStatus(). */
|
|
1275
|
+
checkBatchScrapeStatus(jobId: string, pagination?: PaginationConfig): Promise<BatchScrapeJob>;
|
|
1276
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeErrors(). */
|
|
1277
|
+
checkBatchScrapeErrors(jobId: string): Promise<CrawlErrorsResponse$1>;
|
|
1237
1278
|
}
|
|
1238
1279
|
|
|
1239
1280
|
/**
|
|
@@ -2156,10 +2197,10 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
2156
2197
|
/** Feature‑frozen v1 client (lazy). */
|
|
2157
2198
|
private _v1?;
|
|
2158
2199
|
private _v1Opts;
|
|
2159
|
-
/** @param opts API
|
|
2160
|
-
constructor(opts?:
|
|
2200
|
+
/** @param opts API key string or credentials object. */
|
|
2201
|
+
constructor(opts?: FirecrawlClientInput);
|
|
2161
2202
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
2162
2203
|
get v1(): FirecrawlApp;
|
|
2163
2204
|
}
|
|
2164
2205
|
|
|
2165
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreateMonitorRequest, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, 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 GetMonitorCheckOptions, type HighlightsFormat, JobTimeoutError, type JsonFormat, type ListMonitorChecksOptions, type ListMonitorsOptions, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorEmailNotification, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorSummary, type MonitorTarget, type MonitorWebhookConfig, type PDFAction, type PaginationConfig, type ParseFile, type ParseFileData, type ParseFormat, type ParseFormatOption, type ParseFormatString, type ParseOptions, type PressAction, type QueryFormat, type QuestionFormat, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeBrowserDeleteResponse, type ScrapeExecuteRequest, type ScrapeExecuteResponse, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type UpdateMonitorRequest, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
2206
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreateMonitorRequest, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientInput, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type GetMonitorCheckOptions, type HighlightsFormat, JobTimeoutError, type JsonFormat, type ListMonitorChecksOptions, type ListMonitorsOptions, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorEmailNotification, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageJudgment, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorSummary, type MonitorTarget, type MonitorWebhookConfig, type PDFAction, type PaginationConfig, type ParseFile, type ParseFileData, type ParseFormat, type ParseFormatOption, type ParseFormatString, type ParseOptions, type PressAction, type QueryFormat, type QuestionFormat, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeBrowserDeleteResponse, type ScrapeExecuteRequest, type ScrapeExecuteResponse, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type UpdateMonitorRequest, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -552,6 +552,8 @@ interface CreateMonitorRequest {
|
|
|
552
552
|
notification?: MonitorNotification;
|
|
553
553
|
targets: MonitorTarget[];
|
|
554
554
|
retentionDays?: number;
|
|
555
|
+
goal?: string;
|
|
556
|
+
judgeEnabled?: boolean;
|
|
555
557
|
}
|
|
556
558
|
interface UpdateMonitorRequest {
|
|
557
559
|
name?: string;
|
|
@@ -561,6 +563,8 @@ interface UpdateMonitorRequest {
|
|
|
561
563
|
notification?: MonitorNotification | null;
|
|
562
564
|
targets?: MonitorTarget[];
|
|
563
565
|
retentionDays?: number;
|
|
566
|
+
goal?: string | null;
|
|
567
|
+
judgeEnabled?: boolean;
|
|
564
568
|
}
|
|
565
569
|
interface MonitorSummary {
|
|
566
570
|
totalPages: number;
|
|
@@ -584,9 +588,17 @@ interface Monitor {
|
|
|
584
588
|
retentionDays: number;
|
|
585
589
|
estimatedCreditsPerMonth?: number | null;
|
|
586
590
|
lastCheckSummary?: MonitorSummary | null;
|
|
591
|
+
goal?: string | null;
|
|
592
|
+
judgeEnabled?: boolean;
|
|
587
593
|
createdAt: string;
|
|
588
594
|
updatedAt: string;
|
|
589
595
|
}
|
|
596
|
+
interface MonitorPageJudgment {
|
|
597
|
+
meaningful: boolean;
|
|
598
|
+
confidence: "high" | "medium" | "low";
|
|
599
|
+
reason: string;
|
|
600
|
+
fields: string[];
|
|
601
|
+
}
|
|
590
602
|
interface MonitorCheck {
|
|
591
603
|
id: string;
|
|
592
604
|
monitorId: string;
|
|
@@ -650,6 +662,7 @@ interface MonitorCheckPage {
|
|
|
650
662
|
metadata?: unknown;
|
|
651
663
|
diff?: MonitorPageDiff | null;
|
|
652
664
|
snapshot?: MonitorPageSnapshot | null;
|
|
665
|
+
judgment?: MonitorPageJudgment | null;
|
|
653
666
|
createdAt: string;
|
|
654
667
|
}
|
|
655
668
|
interface MonitorCheckDetail extends MonitorCheck {
|
|
@@ -960,6 +973,8 @@ interface FirecrawlClientOptions {
|
|
|
960
973
|
/** Exponential backoff factor for retries (optional). */
|
|
961
974
|
backoffFactor?: number;
|
|
962
975
|
}
|
|
976
|
+
/** Accepts a plain API key string or a full options object. */
|
|
977
|
+
type FirecrawlClientInput = FirecrawlClientOptions | string;
|
|
963
978
|
/**
|
|
964
979
|
* Firecrawl v2 client. Provides typed access to all v2 endpoints and utilities.
|
|
965
980
|
*/
|
|
@@ -968,9 +983,9 @@ declare class FirecrawlClient {
|
|
|
968
983
|
private isCloudService;
|
|
969
984
|
/**
|
|
970
985
|
* Create a v2 client.
|
|
971
|
-
* @param options
|
|
986
|
+
* @param options API key string or transport configuration object.
|
|
972
987
|
*/
|
|
973
|
-
constructor(options?:
|
|
988
|
+
constructor(options?: FirecrawlClientInput);
|
|
974
989
|
/**
|
|
975
990
|
* Scrape a single URL.
|
|
976
991
|
* @param url Target URL.
|
|
@@ -1234,6 +1249,32 @@ declare class FirecrawlClient {
|
|
|
1234
1249
|
* @param opts Watcher options (kind, pollInterval, timeout seconds).
|
|
1235
1250
|
*/
|
|
1236
1251
|
watcher(jobId: string, opts?: WatcherOptions): Watcher;
|
|
1252
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer scrape(). */
|
|
1253
|
+
scrapeUrl(url: string, options?: ScrapeOptions): Promise<Document>;
|
|
1254
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer crawl(). */
|
|
1255
|
+
crawlUrl(url: string, req?: CrawlOptions & {
|
|
1256
|
+
pollInterval?: number;
|
|
1257
|
+
timeout?: number;
|
|
1258
|
+
}): Promise<CrawlJob>;
|
|
1259
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startCrawl(). */
|
|
1260
|
+
asyncCrawlUrl(url: string, req?: CrawlOptions): Promise<CrawlResponse$1>;
|
|
1261
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlStatus(). */
|
|
1262
|
+
checkCrawlStatus(jobId: string, pagination?: PaginationConfig): Promise<CrawlJob>;
|
|
1263
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlErrors(). */
|
|
1264
|
+
checkCrawlErrors(crawlId: string): Promise<CrawlErrorsResponse$1>;
|
|
1265
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer map(). */
|
|
1266
|
+
mapUrl(url: string, options?: MapOptions): Promise<MapData>;
|
|
1267
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer batchScrape(). */
|
|
1268
|
+
batchScrapeUrls(urls: string[], opts?: BatchScrapeOptions & {
|
|
1269
|
+
pollInterval?: number;
|
|
1270
|
+
timeout?: number;
|
|
1271
|
+
}): Promise<BatchScrapeJob>;
|
|
1272
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startBatchScrape(). */
|
|
1273
|
+
asyncBatchScrapeUrls(urls: string[], opts?: BatchScrapeOptions): Promise<BatchScrapeResponse$1>;
|
|
1274
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeStatus(). */
|
|
1275
|
+
checkBatchScrapeStatus(jobId: string, pagination?: PaginationConfig): Promise<BatchScrapeJob>;
|
|
1276
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeErrors(). */
|
|
1277
|
+
checkBatchScrapeErrors(jobId: string): Promise<CrawlErrorsResponse$1>;
|
|
1237
1278
|
}
|
|
1238
1279
|
|
|
1239
1280
|
/**
|
|
@@ -2156,10 +2197,10 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
2156
2197
|
/** Feature‑frozen v1 client (lazy). */
|
|
2157
2198
|
private _v1?;
|
|
2158
2199
|
private _v1Opts;
|
|
2159
|
-
/** @param opts API
|
|
2160
|
-
constructor(opts?:
|
|
2200
|
+
/** @param opts API key string or credentials object. */
|
|
2201
|
+
constructor(opts?: FirecrawlClientInput);
|
|
2161
2202
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
2162
2203
|
get v1(): FirecrawlApp;
|
|
2163
2204
|
}
|
|
2164
2205
|
|
|
2165
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreateMonitorRequest, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, 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 GetMonitorCheckOptions, type HighlightsFormat, JobTimeoutError, type JsonFormat, type ListMonitorChecksOptions, type ListMonitorsOptions, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorEmailNotification, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorSummary, type MonitorTarget, type MonitorWebhookConfig, type PDFAction, type PaginationConfig, type ParseFile, type ParseFileData, type ParseFormat, type ParseFormatOption, type ParseFormatString, type ParseOptions, type PressAction, type QueryFormat, type QuestionFormat, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeBrowserDeleteResponse, type ScrapeExecuteRequest, type ScrapeExecuteResponse, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type UpdateMonitorRequest, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
2206
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreateMonitorRequest, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientInput, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type GetMonitorCheckOptions, type HighlightsFormat, JobTimeoutError, type JsonFormat, type ListMonitorChecksOptions, type ListMonitorsOptions, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorEmailNotification, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageJudgment, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorSummary, type MonitorTarget, type MonitorWebhookConfig, type PDFAction, type PaginationConfig, type ParseFile, type ParseFileData, type ParseFormat, type ParseFormatOption, type ParseFormatString, type ParseOptions, type PressAction, type QueryFormat, type QuestionFormat, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeBrowserDeleteResponse, type ScrapeExecuteRequest, type ScrapeExecuteResponse, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type UpdateMonitorRequest, type Viewport, type WaitAction, Watcher, type WatcherOptions, 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-46XQC2QL.js";
|
|
4
4
|
|
|
5
5
|
// src/v2/utils/httpClient.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -622,6 +622,20 @@ async function search(http, request) {
|
|
|
622
622
|
if (data.news) out.news = transformArray(data.news);
|
|
623
623
|
if (data.images)
|
|
624
624
|
out.images = transformArray(data.images);
|
|
625
|
+
Object.defineProperty(out, "data", {
|
|
626
|
+
get() {
|
|
627
|
+
const parts = [];
|
|
628
|
+
if (out.web?.length) parts.push(`.web (${out.web.length} results)`);
|
|
629
|
+
if (out.news?.length) parts.push(`.news (${out.news.length} results)`);
|
|
630
|
+
if (out.images?.length) parts.push(`.images (${out.images.length} results)`);
|
|
631
|
+
const available = parts.length ? parts.join(", ") : ".web, .news, or .images";
|
|
632
|
+
throw new Error(
|
|
633
|
+
`SearchData has no '.data'. Results are grouped by source: ${available}`
|
|
634
|
+
);
|
|
635
|
+
},
|
|
636
|
+
enumerable: false,
|
|
637
|
+
configurable: true
|
|
638
|
+
});
|
|
625
639
|
return out;
|
|
626
640
|
} catch (err) {
|
|
627
641
|
if (err?.isAxiosError) return normalizeAxiosError(err, "search");
|
|
@@ -1657,20 +1671,21 @@ var FirecrawlClient = class {
|
|
|
1657
1671
|
}
|
|
1658
1672
|
/**
|
|
1659
1673
|
* Create a v2 client.
|
|
1660
|
-
* @param options
|
|
1674
|
+
* @param options API key string or transport configuration object.
|
|
1661
1675
|
*/
|
|
1662
1676
|
constructor(options = {}) {
|
|
1663
|
-
const
|
|
1664
|
-
const
|
|
1677
|
+
const opts = typeof options === "string" ? { apiKey: options } : options;
|
|
1678
|
+
const apiKey = (opts.apiKey ?? process.env.FIRECRAWL_API_KEY ?? "").trim();
|
|
1679
|
+
const apiUrl = (opts.apiUrl ?? process.env.FIRECRAWL_API_URL ?? "https://api.firecrawl.dev").replace(/\/$/, "");
|
|
1665
1680
|
if (this.isCloudService(apiUrl) && !apiKey) {
|
|
1666
1681
|
throw new Error("API key is required for the cloud API. Set FIRECRAWL_API_KEY env or pass apiKey.");
|
|
1667
1682
|
}
|
|
1668
1683
|
this.http = new HttpClient({
|
|
1669
1684
|
apiKey,
|
|
1670
1685
|
apiUrl,
|
|
1671
|
-
timeoutMs:
|
|
1672
|
-
maxRetries:
|
|
1673
|
-
backoffFactor:
|
|
1686
|
+
timeoutMs: opts.timeoutMs,
|
|
1687
|
+
maxRetries: opts.maxRetries,
|
|
1688
|
+
backoffFactor: opts.backoffFactor
|
|
1674
1689
|
});
|
|
1675
1690
|
}
|
|
1676
1691
|
async scrape(url, options) {
|
|
@@ -2007,6 +2022,46 @@ var FirecrawlClient = class {
|
|
|
2007
2022
|
watcher(jobId, opts = {}) {
|
|
2008
2023
|
return new Watcher(this.http, jobId, opts);
|
|
2009
2024
|
}
|
|
2025
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer scrape(). */
|
|
2026
|
+
async scrapeUrl(url, options) {
|
|
2027
|
+
return this.scrape(url, options);
|
|
2028
|
+
}
|
|
2029
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer crawl(). */
|
|
2030
|
+
async crawlUrl(url, req = {}) {
|
|
2031
|
+
return this.crawl(url, req);
|
|
2032
|
+
}
|
|
2033
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startCrawl(). */
|
|
2034
|
+
async asyncCrawlUrl(url, req = {}) {
|
|
2035
|
+
return this.startCrawl(url, req);
|
|
2036
|
+
}
|
|
2037
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlStatus(). */
|
|
2038
|
+
async checkCrawlStatus(jobId, pagination) {
|
|
2039
|
+
return this.getCrawlStatus(jobId, pagination);
|
|
2040
|
+
}
|
|
2041
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlErrors(). */
|
|
2042
|
+
async checkCrawlErrors(crawlId) {
|
|
2043
|
+
return this.getCrawlErrors(crawlId);
|
|
2044
|
+
}
|
|
2045
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer map(). */
|
|
2046
|
+
async mapUrl(url, options) {
|
|
2047
|
+
return this.map(url, options);
|
|
2048
|
+
}
|
|
2049
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer batchScrape(). */
|
|
2050
|
+
async batchScrapeUrls(urls, opts) {
|
|
2051
|
+
return this.batchScrape(urls, opts);
|
|
2052
|
+
}
|
|
2053
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startBatchScrape(). */
|
|
2054
|
+
async asyncBatchScrapeUrls(urls, opts) {
|
|
2055
|
+
return this.startBatchScrape(urls, opts);
|
|
2056
|
+
}
|
|
2057
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeStatus(). */
|
|
2058
|
+
async checkBatchScrapeStatus(jobId, pagination) {
|
|
2059
|
+
return this.getBatchScrapeStatus(jobId, pagination);
|
|
2060
|
+
}
|
|
2061
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeErrors(). */
|
|
2062
|
+
async checkBatchScrapeErrors(jobId) {
|
|
2063
|
+
return this.getBatchScrapeErrors(jobId);
|
|
2064
|
+
}
|
|
2010
2065
|
};
|
|
2011
2066
|
|
|
2012
2067
|
// src/v1/index.ts
|
|
@@ -2042,7 +2097,7 @@ var FirecrawlApp = class {
|
|
|
2042
2097
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
2043
2098
|
return process.env.npm_package_version;
|
|
2044
2099
|
}
|
|
2045
|
-
const packageJson = await import("./package-
|
|
2100
|
+
const packageJson = await import("./package-MW3GMNCL.js");
|
|
2046
2101
|
return packageJson.default.version;
|
|
2047
2102
|
} catch (error) {
|
|
2048
2103
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
|
@@ -3410,12 +3465,13 @@ var Firecrawl = class extends FirecrawlClient {
|
|
|
3410
3465
|
/** Feature‑frozen v1 client (lazy). */
|
|
3411
3466
|
_v1;
|
|
3412
3467
|
_v1Opts;
|
|
3413
|
-
/** @param opts API
|
|
3468
|
+
/** @param opts API key string or credentials object. */
|
|
3414
3469
|
constructor(opts = {}) {
|
|
3415
|
-
|
|
3470
|
+
const resolved = typeof opts === "string" ? { apiKey: opts } : opts;
|
|
3471
|
+
super(resolved);
|
|
3416
3472
|
this._v1Opts = {
|
|
3417
|
-
apiKey:
|
|
3418
|
-
apiUrl:
|
|
3473
|
+
apiKey: resolved.apiKey,
|
|
3474
|
+
apiUrl: resolved.apiUrl
|
|
3419
3475
|
};
|
|
3420
3476
|
}
|
|
3421
3477
|
/** Access the legacy v1 client (instantiated on first access). */
|
|
@@ -3424,6 +3480,14 @@ var Firecrawl = class extends FirecrawlClient {
|
|
|
3424
3480
|
return this._v1;
|
|
3425
3481
|
}
|
|
3426
3482
|
};
|
|
3483
|
+
(function exposeV2MethodsOnTopLevel() {
|
|
3484
|
+
for (const name of Object.getOwnPropertyNames(FirecrawlClient.prototype)) {
|
|
3485
|
+
if (name === "constructor") continue;
|
|
3486
|
+
if (Object.prototype.hasOwnProperty.call(Firecrawl.prototype, name)) continue;
|
|
3487
|
+
const desc = Object.getOwnPropertyDescriptor(FirecrawlClient.prototype, name);
|
|
3488
|
+
if (desc) Object.defineProperty(Firecrawl.prototype, name, desc);
|
|
3489
|
+
}
|
|
3490
|
+
})();
|
|
3427
3491
|
var index_default = Firecrawl;
|
|
3428
3492
|
export {
|
|
3429
3493
|
Firecrawl,
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Firecrawl, type FirecrawlClientOptions } from '../../../index';
|
|
1
|
+
import { Firecrawl, FirecrawlClient, type FirecrawlClientOptions } from '../../../index';
|
|
2
2
|
|
|
3
3
|
describe('Firecrawl v2 Client Options', () => {
|
|
4
4
|
it('should accept v2 options including timeoutMs, maxRetries, and backoffFactor', () => {
|
|
@@ -52,4 +52,32 @@ describe('Firecrawl v2 Client Options', () => {
|
|
|
52
52
|
expect(options.timeoutMs).toBe(300);
|
|
53
53
|
expect(options.apiKey).toBe('test-key');
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
it('should accept a string API key in Firecrawl constructor', () => {
|
|
57
|
+
const client = new Firecrawl('test-key');
|
|
58
|
+
|
|
59
|
+
expect(client).toBeDefined();
|
|
60
|
+
expect(client).toBeInstanceOf(Firecrawl);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should accept a string API key in FirecrawlClient constructor', () => {
|
|
64
|
+
const client = new FirecrawlClient('test-key');
|
|
65
|
+
|
|
66
|
+
expect(client).toBeDefined();
|
|
67
|
+
expect(client).toBeInstanceOf(FirecrawlClient);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should throw for empty string API key on cloud', () => {
|
|
71
|
+
expect(() => new Firecrawl('')).toThrow('API key is required');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should throw for whitespace-only string API key on cloud', () => {
|
|
75
|
+
expect(() => new Firecrawl(' ')).toThrow('API key is required');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should provide v1 accessor when constructed with string', () => {
|
|
79
|
+
const client = new Firecrawl('test-key');
|
|
80
|
+
|
|
81
|
+
expect(client.v1).toBeDefined();
|
|
82
|
+
});
|
|
55
83
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Firecrawl, FirecrawlClient } from "../../../index";
|
|
2
|
+
|
|
3
|
+
describe("V2 prototype discoverability", () => {
|
|
4
|
+
const app = new Firecrawl({ apiKey: "fc-test", apiUrl: "http://localhost:9" });
|
|
5
|
+
|
|
6
|
+
it("exposes V2 methods on immediate Firecrawl prototype", () => {
|
|
7
|
+
const names = Object.getOwnPropertyNames(Object.getPrototypeOf(app));
|
|
8
|
+
|
|
9
|
+
expect(names).toEqual(
|
|
10
|
+
expect.arrayContaining([
|
|
11
|
+
"scrape",
|
|
12
|
+
"search",
|
|
13
|
+
"map",
|
|
14
|
+
"crawl",
|
|
15
|
+
"startCrawl",
|
|
16
|
+
"getCrawlStatus",
|
|
17
|
+
"batchScrape",
|
|
18
|
+
"v1",
|
|
19
|
+
])
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("preserves v1 getter on Firecrawl prototype", () => {
|
|
24
|
+
const desc = Object.getOwnPropertyDescriptor(
|
|
25
|
+
Object.getPrototypeOf(app),
|
|
26
|
+
"v1"
|
|
27
|
+
);
|
|
28
|
+
expect(desc).toBeDefined();
|
|
29
|
+
expect(desc!.get).toBeDefined();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("copied descriptors are identical to V2 prototype originals", () => {
|
|
33
|
+
for (const name of ["scrape", "search", "crawl", "map", "startCrawl"]) {
|
|
34
|
+
const firecrawlDesc = Object.getOwnPropertyDescriptor(Firecrawl.prototype, name);
|
|
35
|
+
const v2Desc = Object.getOwnPropertyDescriptor(FirecrawlClient.prototype, name);
|
|
36
|
+
expect(firecrawlDesc).toBeDefined();
|
|
37
|
+
expect(firecrawlDesc!.value).toBe(v2Desc!.value);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("copied method resolves this to the Firecrawl instance", async () => {
|
|
42
|
+
const method = Object.getOwnPropertyDescriptor(Firecrawl.prototype, "scrape")!.value;
|
|
43
|
+
await expect(method.call(app, "https://example.com")).rejects.toThrow();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { search } from "../../../v2/methods/search";
|
|
2
|
+
|
|
3
|
+
const fakeHttp = {
|
|
4
|
+
post: jest.fn(),
|
|
5
|
+
} as any;
|
|
6
|
+
|
|
7
|
+
describe("SearchData .data helpful error", () => {
|
|
8
|
+
beforeEach(() => jest.clearAllMocks());
|
|
9
|
+
|
|
10
|
+
it("throws with available sources when .data is accessed", async () => {
|
|
11
|
+
fakeHttp.post.mockResolvedValue({
|
|
12
|
+
status: 200,
|
|
13
|
+
data: {
|
|
14
|
+
success: true,
|
|
15
|
+
data: {
|
|
16
|
+
web: [{ title: "Test", url: "http://a.com" }],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const result = await search(fakeHttp, { query: "test" });
|
|
22
|
+
expect(result.web).toHaveLength(1);
|
|
23
|
+
expect(() => (result as any).data).toThrow(
|
|
24
|
+
/SearchData has no '\.data'.*\.web \(1 results\)/,
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("throws with multiple sources listed", async () => {
|
|
29
|
+
fakeHttp.post.mockResolvedValue({
|
|
30
|
+
status: 200,
|
|
31
|
+
data: {
|
|
32
|
+
success: true,
|
|
33
|
+
data: {
|
|
34
|
+
web: [{ title: "W", url: "http://a.com" }],
|
|
35
|
+
news: [{ title: "N", url: "http://b.com" }],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const result = await search(fakeHttp, { query: "test" });
|
|
41
|
+
expect(() => (result as any).data).toThrow(/\.web.*\.news/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("throws with generic message when empty", async () => {
|
|
45
|
+
fakeHttp.post.mockResolvedValue({
|
|
46
|
+
status: 200,
|
|
47
|
+
data: { success: true, data: {} },
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const result = await search(fakeHttp, { query: "test" });
|
|
51
|
+
expect(() => (result as any).data).toThrow("grouped by source");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("does not show .data in Object.keys", async () => {
|
|
55
|
+
fakeHttp.post.mockResolvedValue({
|
|
56
|
+
status: 200,
|
|
57
|
+
data: {
|
|
58
|
+
success: true,
|
|
59
|
+
data: { web: [{ title: "T", url: "http://a.com" }] },
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const result = await search(fakeHttp, { query: "test" });
|
|
64
|
+
expect(Object.keys(result)).not.toContain("data");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FirecrawlClient } from "../../../v2/client";
|
|
2
|
+
|
|
3
|
+
const ALIAS_MAP: Record<string, string> = {
|
|
4
|
+
scrapeUrl: "scrape",
|
|
5
|
+
crawlUrl: "crawl",
|
|
6
|
+
asyncCrawlUrl: "startCrawl",
|
|
7
|
+
checkCrawlStatus: "getCrawlStatus",
|
|
8
|
+
checkCrawlErrors: "getCrawlErrors",
|
|
9
|
+
mapUrl: "map",
|
|
10
|
+
batchScrapeUrls: "batchScrape",
|
|
11
|
+
asyncBatchScrapeUrls: "startBatchScrape",
|
|
12
|
+
checkBatchScrapeStatus: "getBatchScrapeStatus",
|
|
13
|
+
checkBatchScrapeErrors: "getBatchScrapeErrors",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe("V1 deprecated aliases", () => {
|
|
17
|
+
const app = new FirecrawlClient({
|
|
18
|
+
apiKey: "fc-test",
|
|
19
|
+
apiUrl: "http://localhost:9",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
for (const [alias, target] of Object.entries(ALIAS_MAP)) {
|
|
23
|
+
it(`${alias} delegates to ${target}`, async () => {
|
|
24
|
+
const spy = jest
|
|
25
|
+
.spyOn(app, target as any)
|
|
26
|
+
.mockResolvedValue({ ok: true } as any);
|
|
27
|
+
await (app as any)[alias]("https://example.com");
|
|
28
|
+
expect(spy).toHaveBeenCalled();
|
|
29
|
+
spy.mockRestore();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -15,11 +15,11 @@ export { Watcher, type WatcherOptions } from "./v2/watcher";
|
|
|
15
15
|
export { default as FirecrawlAppV1 } from "./v1";
|
|
16
16
|
|
|
17
17
|
import V1 from "./v1";
|
|
18
|
-
import { FirecrawlClient as V2, type FirecrawlClientOptions } from "./v2/client";
|
|
18
|
+
import { FirecrawlClient as V2, type FirecrawlClientOptions, type FirecrawlClientInput } from "./v2/client";
|
|
19
19
|
import type { FirecrawlAppConfig } from "./v1";
|
|
20
20
|
|
|
21
21
|
// Re-export v2 client options for convenience
|
|
22
|
-
export type { FirecrawlClientOptions } from "./v2/client";
|
|
22
|
+
export type { FirecrawlClientOptions, FirecrawlClientInput } from "./v2/client";
|
|
23
23
|
|
|
24
24
|
/** Unified client: extends v2 and adds `.v1` for backward compatibility. */
|
|
25
25
|
export class Firecrawl extends V2 {
|
|
@@ -27,12 +27,14 @@ export class Firecrawl extends V2 {
|
|
|
27
27
|
private _v1?: V1;
|
|
28
28
|
private _v1Opts: FirecrawlAppConfig;
|
|
29
29
|
|
|
30
|
-
/** @param opts API
|
|
31
|
-
constructor(opts:
|
|
32
|
-
|
|
30
|
+
/** @param opts API key string or credentials object. */
|
|
31
|
+
constructor(opts: FirecrawlClientInput = {}) {
|
|
32
|
+
const resolved: FirecrawlClientOptions =
|
|
33
|
+
typeof opts === "string" ? { apiKey: opts } : opts;
|
|
34
|
+
super(resolved);
|
|
33
35
|
this._v1Opts = {
|
|
34
|
-
apiKey:
|
|
35
|
-
apiUrl:
|
|
36
|
+
apiKey: resolved.apiKey,
|
|
37
|
+
apiUrl: resolved.apiUrl,
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -43,5 +45,16 @@ export class Firecrawl extends V2 {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
// Copy V2 method descriptors onto Firecrawl.prototype so that
|
|
49
|
+
// Object.getOwnPropertyNames(Object.getPrototypeOf(app)) includes them.
|
|
50
|
+
(function exposeV2MethodsOnTopLevel() {
|
|
51
|
+
for (const name of Object.getOwnPropertyNames(V2.prototype)) {
|
|
52
|
+
if (name === "constructor") continue;
|
|
53
|
+
if (Object.prototype.hasOwnProperty.call(Firecrawl.prototype, name)) continue;
|
|
54
|
+
const desc = Object.getOwnPropertyDescriptor(V2.prototype, name);
|
|
55
|
+
if (desc) Object.defineProperty(Firecrawl.prototype, name, desc);
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
|
|
46
59
|
export default Firecrawl;
|
|
47
60
|
|
package/src/v2/client.ts
CHANGED
|
@@ -110,6 +110,9 @@ export interface FirecrawlClientOptions {
|
|
|
110
110
|
backoffFactor?: number;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/** Accepts a plain API key string or a full options object. */
|
|
114
|
+
export type FirecrawlClientInput = FirecrawlClientOptions | string;
|
|
115
|
+
|
|
113
116
|
/**
|
|
114
117
|
* Firecrawl v2 client. Provides typed access to all v2 endpoints and utilities.
|
|
115
118
|
*/
|
|
@@ -123,11 +126,14 @@ export class FirecrawlClient {
|
|
|
123
126
|
|
|
124
127
|
/**
|
|
125
128
|
* Create a v2 client.
|
|
126
|
-
* @param options
|
|
129
|
+
* @param options API key string or transport configuration object.
|
|
127
130
|
*/
|
|
128
|
-
constructor(options:
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
+
constructor(options: FirecrawlClientInput = {}) {
|
|
132
|
+
const opts: FirecrawlClientOptions =
|
|
133
|
+
typeof options === "string" ? { apiKey: options } : options;
|
|
134
|
+
|
|
135
|
+
const apiKey = (opts.apiKey ?? process.env.FIRECRAWL_API_KEY ?? "").trim();
|
|
136
|
+
const apiUrl = (opts.apiUrl ?? process.env.FIRECRAWL_API_URL ?? "https://api.firecrawl.dev").replace(/\/$/, "");
|
|
131
137
|
|
|
132
138
|
if (this.isCloudService(apiUrl) && !apiKey) {
|
|
133
139
|
throw new Error("API key is required for the cloud API. Set FIRECRAWL_API_KEY env or pass apiKey.");
|
|
@@ -136,9 +142,9 @@ export class FirecrawlClient {
|
|
|
136
142
|
this.http = new HttpClient({
|
|
137
143
|
apiKey,
|
|
138
144
|
apiUrl,
|
|
139
|
-
timeoutMs:
|
|
140
|
-
maxRetries:
|
|
141
|
-
backoffFactor:
|
|
145
|
+
timeoutMs: opts.timeoutMs,
|
|
146
|
+
maxRetries: opts.maxRetries,
|
|
147
|
+
backoffFactor: opts.backoffFactor,
|
|
142
148
|
});
|
|
143
149
|
}
|
|
144
150
|
|
|
@@ -547,6 +553,56 @@ export class FirecrawlClient {
|
|
|
547
553
|
watcher(jobId: string, opts: WatcherOptions = {}): Watcher {
|
|
548
554
|
return new Watcher(this.http, jobId, opts);
|
|
549
555
|
}
|
|
556
|
+
|
|
557
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer scrape(). */
|
|
558
|
+
async scrapeUrl(url: string, options?: ScrapeOptions): Promise<Document> {
|
|
559
|
+
return this.scrape(url, options);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer crawl(). */
|
|
563
|
+
async crawlUrl(url: string, req: CrawlOptions & { pollInterval?: number; timeout?: number } = {}): Promise<CrawlJob> {
|
|
564
|
+
return this.crawl(url, req);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startCrawl(). */
|
|
568
|
+
async asyncCrawlUrl(url: string, req: CrawlOptions = {}): Promise<CrawlResponse> {
|
|
569
|
+
return this.startCrawl(url, req);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlStatus(). */
|
|
573
|
+
async checkCrawlStatus(jobId: string, pagination?: PaginationConfig): Promise<CrawlJob> {
|
|
574
|
+
return this.getCrawlStatus(jobId, pagination);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getCrawlErrors(). */
|
|
578
|
+
async checkCrawlErrors(crawlId: string): Promise<CrawlErrorsResponse> {
|
|
579
|
+
return this.getCrawlErrors(crawlId);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer map(). */
|
|
583
|
+
async mapUrl(url: string, options?: MapOptions): Promise<MapData> {
|
|
584
|
+
return this.map(url, options);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer batchScrape(). */
|
|
588
|
+
async batchScrapeUrls(urls: string[], opts?: BatchScrapeOptions & { pollInterval?: number; timeout?: number }): Promise<BatchScrapeJob> {
|
|
589
|
+
return this.batchScrape(urls, opts);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer startBatchScrape(). */
|
|
593
|
+
async asyncBatchScrapeUrls(urls: string[], opts?: BatchScrapeOptions): Promise<BatchScrapeResponse> {
|
|
594
|
+
return this.startBatchScrape(urls, opts);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeStatus(). */
|
|
598
|
+
async checkBatchScrapeStatus(jobId: string, pagination?: PaginationConfig): Promise<BatchScrapeJob> {
|
|
599
|
+
return this.getBatchScrapeStatus(jobId, pagination);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** @deprecated V1 compatibility alias for agent recovery. Prefer getBatchScrapeErrors(). */
|
|
603
|
+
async checkBatchScrapeErrors(jobId: string): Promise<CrawlErrorsResponse> {
|
|
604
|
+
return this.getBatchScrapeErrors(jobId);
|
|
605
|
+
}
|
|
550
606
|
}
|
|
551
607
|
|
|
552
608
|
export default FirecrawlClient;
|
package/src/v2/methods/search.ts
CHANGED
|
@@ -98,6 +98,20 @@ export async function search(
|
|
|
98
98
|
if (data.news) out.news = transformArray<SearchResultNews>(data.news);
|
|
99
99
|
if (data.images)
|
|
100
100
|
out.images = transformArray<SearchResultImages>(data.images);
|
|
101
|
+
Object.defineProperty(out, "data", {
|
|
102
|
+
get() {
|
|
103
|
+
const parts: string[] = [];
|
|
104
|
+
if (out.web?.length) parts.push(`.web (${out.web.length} results)`);
|
|
105
|
+
if (out.news?.length) parts.push(`.news (${out.news.length} results)`);
|
|
106
|
+
if (out.images?.length) parts.push(`.images (${out.images.length} results)`);
|
|
107
|
+
const available = parts.length ? parts.join(", ") : ".web, .news, or .images";
|
|
108
|
+
throw new Error(
|
|
109
|
+
`SearchData has no '.data'. Results are grouped by source: ${available}`,
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
enumerable: false,
|
|
113
|
+
configurable: true,
|
|
114
|
+
});
|
|
101
115
|
return out;
|
|
102
116
|
} catch (err: any) {
|
|
103
117
|
if (err?.isAxiosError) return normalizeAxiosError(err, "search");
|
package/src/v2/types.ts
CHANGED
|
@@ -695,6 +695,8 @@ export interface CreateMonitorRequest {
|
|
|
695
695
|
notification?: MonitorNotification;
|
|
696
696
|
targets: MonitorTarget[];
|
|
697
697
|
retentionDays?: number;
|
|
698
|
+
goal?: string;
|
|
699
|
+
judgeEnabled?: boolean;
|
|
698
700
|
}
|
|
699
701
|
|
|
700
702
|
export interface UpdateMonitorRequest {
|
|
@@ -705,6 +707,8 @@ export interface UpdateMonitorRequest {
|
|
|
705
707
|
notification?: MonitorNotification | null;
|
|
706
708
|
targets?: MonitorTarget[];
|
|
707
709
|
retentionDays?: number;
|
|
710
|
+
goal?: string | null;
|
|
711
|
+
judgeEnabled?: boolean;
|
|
708
712
|
}
|
|
709
713
|
|
|
710
714
|
export interface MonitorSummary {
|
|
@@ -730,10 +734,19 @@ export interface Monitor {
|
|
|
730
734
|
retentionDays: number;
|
|
731
735
|
estimatedCreditsPerMonth?: number | null;
|
|
732
736
|
lastCheckSummary?: MonitorSummary | null;
|
|
737
|
+
goal?: string | null;
|
|
738
|
+
judgeEnabled?: boolean;
|
|
733
739
|
createdAt: string;
|
|
734
740
|
updatedAt: string;
|
|
735
741
|
}
|
|
736
742
|
|
|
743
|
+
export interface MonitorPageJudgment {
|
|
744
|
+
meaningful: boolean;
|
|
745
|
+
confidence: "high" | "medium" | "low";
|
|
746
|
+
reason: string;
|
|
747
|
+
fields: string[];
|
|
748
|
+
}
|
|
749
|
+
|
|
737
750
|
export interface MonitorCheck {
|
|
738
751
|
id: string;
|
|
739
752
|
monitorId: string;
|
|
@@ -807,6 +820,7 @@ export interface MonitorCheckPage {
|
|
|
807
820
|
metadata?: unknown;
|
|
808
821
|
diff?: MonitorPageDiff | null;
|
|
809
822
|
snapshot?: MonitorPageSnapshot | null;
|
|
823
|
+
judgment?: MonitorPageJudgment | null;
|
|
810
824
|
createdAt: string;
|
|
811
825
|
}
|
|
812
826
|
|