@mendable/firecrawl-js 0.0.17-beta.1 → 0.0.17-beta.3

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 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.17-beta.1",
3
+ "version": "0.0.17-beta.3",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "build/index.js",
6
6
  "types": "types/index.d.ts",
@@ -8,7 +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
+ "publish-beta": "npm run build && npm publish --access public --tag beta",
12
12
  "test": "jest src/**/*.test.ts"
13
13
  },
14
14
  "repository": {
@@ -18,7 +18,9 @@
18
18
  "author": "Mendable.ai",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "axios": "^1.6.8"
21
+ "axios": "^1.6.8",
22
+ "zod-to-json-schema": "^3.23.0",
23
+ "zod": "^3.23.8"
22
24
  },
23
25
  "bugs": {
24
26
  "url": "https://github.com/mendableai/firecrawl/issues"
@@ -31,6 +33,7 @@
31
33
  "jest": "^29.7.0",
32
34
  "ts-jest": "^29.1.2",
33
35
  "typescript": "^5.4.5"
36
+
34
37
  },
35
38
  "keywords": [
36
39
  "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
  */
@@ -19,7 +20,7 @@ export interface Params {
19
20
  */
20
21
  export interface ScrapeResponse {
21
22
  success: boolean;
22
- data?: Document;
23
+ data?: any;
23
24
  error?: string;
24
25
  }
25
26
 
@@ -28,7 +29,7 @@ export interface ScrapeResponse {
28
29
  */
29
30
  export interface SearchResponse {
30
31
  success: boolean;
31
- data?: Document[] | { url: string, title: string, description: string }[];
32
+ data?: any;
32
33
  error?: string;
33
34
  }
34
35
  /**
@@ -37,7 +38,7 @@ export interface SearchResponse {
37
38
  export interface CrawlResponse {
38
39
  success: boolean;
39
40
  jobId?: string;
40
- data?: Document[];
41
+ data?: any;
41
42
  error?: string;
42
43
  }
43
44
 
@@ -52,27 +53,6 @@ export interface JobStatusResponse {
52
53
  error?: string;
53
54
  }
54
55
 
55
- /**
56
- * Return type for scraping, crawling and search operations.
57
- */
58
- export interface Document{
59
- id?: string;
60
- content: string;
61
- markdown?: string;
62
- html?: string;
63
- llm_extraction?: Record<string, any>;
64
- createdAt?: Date;
65
- updatedAt?: Date;
66
- type?: string;
67
- metadata: {
68
- sourceURL?: string;
69
- [key: string]: any;
70
- };
71
- childrenLinks?: string[];
72
- provider?: string;
73
- url?: string; // Used only in /search for now
74
- }
75
-
76
56
  /**
77
57
  * Main class for interacting with the Firecrawl API.
78
58
  */
@@ -96,7 +76,7 @@ export default class FirecrawlApp {
96
76
  * @param {Params | null} params - Additional parameters for the scrape request.
97
77
  * @returns {Promise<ScrapeResponse>} The response from the scrape operation.
98
78
  */
99
- 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> {
100
80
  const headers: AxiosRequestHeaders = {
101
81
  'Content-Type': 'application/json',
102
82
  'Authorization': `Bearer ${this.apiKey}`,
@@ -105,6 +85,10 @@ export default class FirecrawlApp {
105
85
  if (params) {
106
86
  jsonData = { ...jsonData, ...params };
107
87
  }
88
+ if (extractorOptions?.schema) {
89
+ const schema = zodToJsonSchema(extractorOptions.schema);
90
+ jsonData = { ...jsonData, extractorOptions: { ...extractorOptions, schema } };
91
+ }
108
92
  try {
109
93
  const response: AxiosResponse = await axios.post('https://api.firecrawl.dev/v0/scrape', jsonData, { headers });
110
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
  */
@@ -16,7 +17,7 @@ export interface Params {
16
17
  */
17
18
  export interface ScrapeResponse {
18
19
  success: boolean;
19
- data?: Document;
20
+ data?: any;
20
21
  error?: string;
21
22
  }
22
23
  /**
@@ -24,11 +25,7 @@ export interface ScrapeResponse {
24
25
  */
25
26
  export interface SearchResponse {
26
27
  success: boolean;
27
- data?: Document[] | {
28
- url: string;
29
- title: string;
30
- description: string;
31
- }[];
28
+ data?: any;
32
29
  error?: string;
33
30
  }
34
31
  /**
@@ -37,7 +34,7 @@ export interface SearchResponse {
37
34
  export interface CrawlResponse {
38
35
  success: boolean;
39
36
  jobId?: string;
40
- data?: Document[];
37
+ data?: any;
41
38
  error?: string;
42
39
  }
43
40
  /**
@@ -50,26 +47,6 @@ export interface JobStatusResponse {
50
47
  data?: any;
51
48
  error?: string;
52
49
  }
53
- /**
54
- * Return type for scraping, crawling and search operations.
55
- */
56
- export interface Document {
57
- id?: string;
58
- content: string;
59
- markdown?: string;
60
- html?: string;
61
- llm_extraction?: Record<string, any>;
62
- createdAt?: Date;
63
- updatedAt?: Date;
64
- type?: string;
65
- metadata: {
66
- sourceURL?: string;
67
- [key: string]: any;
68
- };
69
- childrenLinks?: string[];
70
- provider?: string;
71
- url?: string;
72
- }
73
50
  /**
74
51
  * Main class for interacting with the Firecrawl API.
75
52
  */
@@ -86,7 +63,9 @@ export default class FirecrawlApp {
86
63
  * @param {Params | null} params - Additional parameters for the scrape request.
87
64
  * @returns {Promise<ScrapeResponse>} The response from the scrape operation.
88
65
  */
89
- scrapeUrl(url: string, params?: Params | null): Promise<ScrapeResponse>;
66
+ scrapeUrl(url: string, params?: Params | null, extractorOptions?: {
67
+ schema?: z.ZodType<any, any>;
68
+ }): Promise<ScrapeResponse>;
90
69
  /**
91
70
  * Searches for a query using the Firecrawl API.
92
71
  * @param {string} query - The query to search for.