@mendable/firecrawl-js 0.0.19 → 0.0.21

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/README.md CHANGED
@@ -77,6 +77,42 @@ To scrape a single URL with error handling, use the `scrapeUrl` method. It takes
77
77
  scrapeExample();
78
78
  ```
79
79
 
80
+ ### Extracting structured data from a URL
81
+
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
+
84
+ ```js
85
+ import { z } from "zod";
86
+
87
+ const zodSchema = z.object({
88
+ top: z
89
+ .array(
90
+ z.object({
91
+ title: z.string(),
92
+ points: z.number(),
93
+ by: z.string(),
94
+ commentsURL: z.string(),
95
+ })
96
+ )
97
+ .length(5)
98
+ .describe("Top 5 stories on Hacker News"),
99
+ });
100
+
101
+ let llmExtractionResult = await app.scrapeUrl("https://news.ycombinator.com", {
102
+ extractorOptions: { extractionSchema: zodSchema },
103
+ });
104
+
105
+ console.log(llmExtractionResult.data.llm_extraction);
106
+ ```
107
+
108
+ ### Search for a query
109
+
110
+ Used to search the web, get the most relevant results, scrap each page and return the markdown.
111
+
112
+ ```js
113
+ query = 'what is mendable?'
114
+ searchResult = app.search(query)
115
+ ```
80
116
 
81
117
  ### Crawling a Website
82
118
 
package/build/index.js CHANGED
@@ -240,7 +240,7 @@ export default class FirecrawlApp {
240
240
  * @param {string} action - The action being performed when the error occurred.
241
241
  */
242
242
  handleError(response, action) {
243
- if ([402, 409, 500].includes(response.status)) {
243
+ if ([402, 408, 409, 500].includes(response.status)) {
244
244
  const errorMessage = response.data.error || "Unknown error occurred";
245
245
  throw new Error(`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}`);
246
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mendable/firecrawl-js",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "build/index.js",
6
6
  "types": "types/index.d.ts",
package/src/index.ts CHANGED
@@ -109,7 +109,7 @@ export default class FirecrawlApp {
109
109
  const response: AxiosResponse = await axios.post(
110
110
  "https://api.firecrawl.dev/v0/scrape",
111
111
  jsonData,
112
- { headers }
112
+ { headers },
113
113
  );
114
114
  if (response.status === 200) {
115
115
  const responseData = response.data;
@@ -324,7 +324,7 @@ export default class FirecrawlApp {
324
324
  * @param {string} action - The action being performed when the error occurred.
325
325
  */
326
326
  handleError(response: AxiosResponse, action: string): void {
327
- if ([402, 409, 500].includes(response.status)) {
327
+ if ([402, 408, 409, 500].includes(response.status)) {
328
328
  const errorMessage: string =
329
329
  response.data.error || "Unknown error occurred";
330
330
  throw new Error(