@mendable/firecrawl-js 1.0.1 → 1.0.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -131
  3. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Sideguide Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Firecrawl JavaScript SDK
1
+ # Firecrawl Node SDK
2
2
 
3
- The Firecrawl JavaScript SDK is a library that allows you to easily scrape and crawl websites, and output the data in a format ready for use with language models (LLMs). It provides a simple and intuitive interface for interacting with the Firecrawl API.
3
+ The Firecrawl Node SDK is a library that allows you to easily scrape and crawl websites, and output the data in a format ready for use with language models (LLMs). It provides a simple and intuitive interface for interacting with the Firecrawl API.
4
4
 
5
5
  ## Installation
6
6
 
7
- To install the Firecrawl JavaScript SDK, you can use npm:
7
+ To install the Firecrawl Node SDK, you can use npm:
8
8
 
9
9
  ```bash
10
10
  npm install @mendable/firecrawl-js
@@ -15,44 +15,33 @@ npm install @mendable/firecrawl-js
15
15
  1. Get an API key from [firecrawl.dev](https://firecrawl.dev)
16
16
  2. Set the API key as an environment variable named `FIRECRAWL_API_KEY` or pass it as a parameter to the `FirecrawlApp` class.
17
17
 
18
-
19
18
  Here's an example of how to use the SDK with error handling:
20
19
 
21
20
  ```js
22
- import FirecrawlApp from '@mendable/firecrawl-js';
23
-
24
- async function main() {
25
- try {
26
- // Initialize the FirecrawlApp with your API key
27
- const app = new FirecrawlApp({ apiKey: "YOUR_API_KEY" });
28
-
29
- // Scrape a single URL
30
- const url = 'https://mendable.ai';
31
- const scrapedData = await app.scrapeUrl(url);
32
- console.log(scrapedData);
33
-
34
- // Crawl a website
35
- const crawlUrl = 'https://mendable.ai';
36
- const params = {
37
- crawlerOptions: {
38
- excludes: ['blog/'],
39
- includes: [], // leave empty for all pages
40
- limit: 1000,
41
- },
42
- pageOptions: {
43
- onlyMainContent: true
44
- }
45
- };
46
-
47
- const crawlResult = await app.crawlUrl(crawlUrl, params);
48
- console.log(crawlResult);
49
-
50
- } catch (error) {
51
- console.error('An error occurred:', error.message);
52
- }
21
+ import FirecrawlApp, { CrawlParams, CrawlStatusResponse } from '@mendable/firecrawl-js';
22
+
23
+ const app = new FirecrawlApp({apiKey: "fc-YOUR_API_KEY"});
24
+
25
+ // Scrape a website
26
+ const scrapeResponse = await app.scrapeUrl('https://firecrawl.dev', {
27
+ formats: ['markdown', 'html'],
28
+ });
29
+
30
+ if (scrapeResponse) {
31
+ console.log(scrapeResponse)
32
+ }
33
+
34
+ // Crawl a website
35
+ const crawlResponse = await app.crawlUrl('https://firecrawl.dev', {
36
+ limit: 100,
37
+ scrapeOptions: {
38
+ formats: ['markdown', 'html'],
53
39
  }
40
+ } as CrawlParams, true, 30) as CrawlStatusResponse;
54
41
 
55
- main();
42
+ if (crawlResponse) {
43
+ console.log(crawlResponse)
44
+ }
56
45
  ```
57
46
 
58
47
  ### Scraping a URL
@@ -60,31 +49,49 @@ Here's an example of how to use the SDK with error handling:
60
49
  To scrape a single URL with error handling, use the `scrapeUrl` method. It takes the URL as a parameter and returns the scraped data as a dictionary.
61
50
 
62
51
  ```js
63
- async function scrapeExample() {
64
- try {
65
- const url = 'https://example.com';
66
- const scrapedData = await app.scrapeUrl(url);
67
- console.log(scrapedData);
68
-
69
- } catch (error) {
70
- console.error(
71
- 'Error occurred while scraping:',
72
- error.message
73
- );
74
- }
52
+ const url = "https://example.com";
53
+ const scrapedData = await app.scrapeUrl(url);
54
+ ```
55
+
56
+ ### Crawling a Website
57
+
58
+ To crawl a website with error handling, use the `crawlUrl` method. It takes the starting URL and optional parameters as arguments. The `params` argument allows you to specify additional options for the crawl job, such as the maximum number of pages to crawl, allowed domains, and the output format.
59
+
60
+ ```js
61
+ const crawlResponse = await app.crawlUrl('https://firecrawl.dev', {
62
+ limit: 100,
63
+ scrapeOptions: {
64
+ formats: ['markdown', 'html'],
75
65
  }
76
-
77
- scrapeExample();
66
+ } as CrawlParams, true, 30) as CrawlStatusResponse;
67
+
68
+ if (crawlResponse) {
69
+ console.log(crawlResponse)
70
+ }
71
+ ```
72
+
73
+ ### Checking Crawl Status
74
+
75
+ To check the status of a crawl job with error handling, use the `checkCrawlStatus` method. It takes the job ID as a parameter and returns the current status of the crawl job.
76
+
77
+ ```js
78
+ const status = await app.checkCrawlStatus(id);
78
79
  ```
79
80
 
80
81
  ### Extracting structured data from a URL
81
82
 
82
- With LLM extraction, you can easily extract structured data from any URL. We support zod schemas to make it easier for you too. Here is how you to use it:
83
+ With LLM extraction, you can easily extract structured data from any URL. We support zod schema to make it easier for you too. Here is how you to use it:
83
84
 
84
85
  ```js
86
+ import FirecrawlApp from "@mendable/firecrawl-js";
85
87
  import { z } from "zod";
86
88
 
87
- const zodSchema = z.object({
89
+ const app = new FirecrawlApp({
90
+ apiKey: "fc-YOUR_API_KEY",
91
+ });
92
+
93
+ // Define schema to extract contents into
94
+ const schema = z.object({
88
95
  top: z
89
96
  .array(
90
97
  z.object({
@@ -98,98 +105,32 @@ const zodSchema = z.object({
98
105
  .describe("Top 5 stories on Hacker News"),
99
106
  });
100
107
 
101
- let llmExtractionResult = await app.scrapeUrl("https://news.ycombinator.com", {
102
- extractorOptions: { extractionSchema: zodSchema },
108
+ const scrapeResult = await app.scrapeUrl("https://firecrawl.dev", {
109
+ extractorOptions: { extractionSchema: schema },
103
110
  });
104
111
 
105
- console.log(llmExtractionResult.data.llm_extraction);
112
+ console.log(scrapeResult.data["llm_extraction"]);
106
113
  ```
107
114
 
108
- ### Search for a query
115
+ ### Map a Website
109
116
 
110
- Used to search the web, get the most relevant results, scrap each page and return the markdown.
117
+ Use `map_url` to generate a list of URLs from a website. The `params` argument let you customize the mapping process, including options to exclude subdomains or to utilize the sitemap.
111
118
 
112
119
  ```js
113
- query = 'what is mendable?'
114
- searchResult = app.search(query)
115
- ```
116
-
117
- ### Crawling a Website
118
-
119
- To crawl a website with error handling, use the `crawlUrl` method. It takes the starting URL and optional parameters as arguments. The `params` argument allows you to specify additional options for the crawl job, such as the maximum number of pages to crawl, allowed domains, and the output format.
120
-
121
- ```js
122
- async function crawlExample() {
123
- try {
124
- const crawlUrl = 'https://example.com';
125
- const params = {
126
- crawlerOptions: {
127
- excludes: ['blog/'],
128
- includes: [], // leave empty for all pages
129
- limit: 1000,
130
- },
131
- pageOptions: {
132
- onlyMainContent: true
133
- }
134
- };
135
- const waitUntilDone = true;
136
- const timeout = 5;
137
- const crawlResult = await app.crawlUrl(
138
- crawlUrl,
139
- params,
140
- waitUntilDone,
141
- timeout
142
- );
143
-
144
- console.log(crawlResult);
145
-
146
- } catch (error) {
147
- console.error(
148
- 'Error occurred while crawling:',
149
- error.message
150
- );
151
- }
152
- }
153
-
154
- crawlExample();
155
- ```
156
-
157
-
158
- ### Checking Crawl Status
159
-
160
- To check the status of a crawl job with error handling, use the `checkCrawlStatus` method. It takes the job ID as a parameter and returns the current status of the crawl job.
161
-
162
- ```js
163
- async function checkStatusExample(jobId) {
164
- try {
165
- const status = await app.checkCrawlStatus(jobId);
166
- console.log(status);
167
-
168
- } catch (error) {
169
- console.error(
170
- 'Error occurred while checking crawl status:',
171
- error.message
172
- );
173
- }
174
- }
175
- // Example usage, assuming you have a jobId
176
- checkStatusExample('your_job_id_here');
177
- ```
178
-
179
- ## Running Locally
180
- To use the SDK when running Firecrawl locally, you can change the initial Firecrawl app instance to:
181
- ```js
182
- const app = new FirecrawlApp({ apiKey: "YOUR_API_KEY", apiUrl: "http://localhost:3002" });
120
+ const mapResult = await app.mapUrl('https://example.com') as MapResponse;
121
+ console.log(mapResult)
183
122
  ```
184
123
 
185
124
  ## Error Handling
186
125
 
187
126
  The SDK handles errors returned by the Firecrawl API and raises appropriate exceptions. If an error occurs during a request, an exception will be raised with a descriptive error message. The examples above demonstrate how to handle these errors using `try/catch` blocks.
188
127
 
189
- ## Contributing
128
+ ## License
190
129
 
191
- Contributions to the Firecrawl JavaScript SDK are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
130
+ The Firecrawl Node SDK is licensed under the MIT License. This means you are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the SDK, subject to the following conditions:
192
131
 
193
- ## License
132
+ - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
133
+
134
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
194
135
 
195
- The Firecrawl JavaScript SDK is open-source and released under the [MIT License](https://opensource.org/licenses/MIT).
136
+ Please note that while this SDK is MIT licensed, it is part of a larger project which may be under different licensing terms. Always refer to the license information in the root directory of the main project for overall licensing details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mendable/firecrawl-js",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "build/cjs/index.js",
6
6
  "types": "types/index.d.ts",