@mendable/firecrawl-js 0.0.16 → 0.0.17-beta.2
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/build/index.js +6 -1
- package/package.json +6 -3
- package/src/index.ts +7 -2
- package/types/index.d.ts +4 -1
package/build/index.js
CHANGED
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import axios from 'axios';
|
|
11
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
11
12
|
/**
|
|
12
13
|
* Main class for interacting with the Firecrawl API.
|
|
13
14
|
*/
|
|
@@ -29,7 +30,7 @@ export default class FirecrawlApp {
|
|
|
29
30
|
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
30
31
|
*/
|
|
31
32
|
scrapeUrl(url_1) {
|
|
32
|
-
return __awaiter(this, arguments, void 0, function* (url, params = null) {
|
|
33
|
+
return __awaiter(this, arguments, void 0, function* (url, params = null, extractorOptions) {
|
|
33
34
|
const headers = {
|
|
34
35
|
'Content-Type': 'application/json',
|
|
35
36
|
'Authorization': `Bearer ${this.apiKey}`,
|
|
@@ -38,6 +39,10 @@ export default class FirecrawlApp {
|
|
|
38
39
|
if (params) {
|
|
39
40
|
jsonData = Object.assign(Object.assign({}, jsonData), params);
|
|
40
41
|
}
|
|
42
|
+
if (extractorOptions === null || extractorOptions === void 0 ? void 0 : extractorOptions.schema) {
|
|
43
|
+
const schema = zodToJsonSchema(extractorOptions.schema);
|
|
44
|
+
jsonData = Object.assign(Object.assign({}, jsonData), { extractorOptions: Object.assign(Object.assign({}, extractorOptions), { schema }) });
|
|
45
|
+
}
|
|
41
46
|
try {
|
|
42
47
|
const response = yield axios.post('https://api.firecrawl.dev/v0/scrape', jsonData, { headers });
|
|
43
48
|
if (response.status === 200) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mendable/firecrawl-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17-beta.2",
|
|
4
4
|
"description": "JavaScript SDK for Firecrawl API",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc",
|
|
10
10
|
"publish": "npm run build && npm publish --access public",
|
|
11
|
+
"publish-beta": "npm run build && npm publish --access public --tag beta",
|
|
11
12
|
"test": "jest src/**/*.test.ts"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
"author": "Mendable.ai",
|
|
18
19
|
"license": "MIT",
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"axios": "^1.6.8"
|
|
21
|
+
"axios": "^1.6.8",
|
|
22
|
+
"zod": "^3.23.8"
|
|
21
23
|
},
|
|
22
24
|
"bugs": {
|
|
23
25
|
"url": "https://github.com/mendableai/firecrawl/issues"
|
|
@@ -29,7 +31,8 @@
|
|
|
29
31
|
"@types/node": "^20.12.7",
|
|
30
32
|
"jest": "^29.7.0",
|
|
31
33
|
"ts-jest": "^29.1.2",
|
|
32
|
-
"typescript": "^5.4.5"
|
|
34
|
+
"typescript": "^5.4.5",
|
|
35
|
+
"zod-to-json-schema": "^3.23.0"
|
|
33
36
|
},
|
|
34
37
|
"keywords": [
|
|
35
38
|
"firecrawl",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosResponse, AxiosRequestHeaders } from 'axios';
|
|
2
|
-
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { zodToJsonSchema } from 'zod-to-json-schema'
|
|
3
4
|
/**
|
|
4
5
|
* Configuration interface for FirecrawlApp.
|
|
5
6
|
*/
|
|
@@ -75,7 +76,7 @@ export default class FirecrawlApp {
|
|
|
75
76
|
* @param {Params | null} params - Additional parameters for the scrape request.
|
|
76
77
|
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
77
78
|
*/
|
|
78
|
-
async scrapeUrl(url: string, params: Params | null = null): Promise<ScrapeResponse> {
|
|
79
|
+
async scrapeUrl(url: string, params: Params | null = null, extractorOptions?: { schema?: z.ZodType<any, any> }): Promise<ScrapeResponse> {
|
|
79
80
|
const headers: AxiosRequestHeaders = {
|
|
80
81
|
'Content-Type': 'application/json',
|
|
81
82
|
'Authorization': `Bearer ${this.apiKey}`,
|
|
@@ -84,6 +85,10 @@ export default class FirecrawlApp {
|
|
|
84
85
|
if (params) {
|
|
85
86
|
jsonData = { ...jsonData, ...params };
|
|
86
87
|
}
|
|
88
|
+
if (extractorOptions?.schema) {
|
|
89
|
+
const schema = zodToJsonSchema(extractorOptions.schema);
|
|
90
|
+
jsonData = { ...jsonData, extractorOptions: { ...extractorOptions, schema } };
|
|
91
|
+
}
|
|
87
92
|
try {
|
|
88
93
|
const response: AxiosResponse = await axios.post('https://api.firecrawl.dev/v0/scrape', jsonData, { headers });
|
|
89
94
|
if (response.status === 200) {
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxiosResponse, AxiosRequestHeaders } from 'axios';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
/**
|
|
3
4
|
* Configuration interface for FirecrawlApp.
|
|
4
5
|
*/
|
|
@@ -62,7 +63,9 @@ export default class FirecrawlApp {
|
|
|
62
63
|
* @param {Params | null} params - Additional parameters for the scrape request.
|
|
63
64
|
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
64
65
|
*/
|
|
65
|
-
scrapeUrl(url: string, params?: Params | null
|
|
66
|
+
scrapeUrl(url: string, params?: Params | null, extractorOptions?: {
|
|
67
|
+
schema?: z.ZodType<any, any>;
|
|
68
|
+
}): Promise<ScrapeResponse>;
|
|
66
69
|
/**
|
|
67
70
|
* Searches for a query using the Firecrawl API.
|
|
68
71
|
* @param {string} query - The query to search for.
|