From b7c7291b0e889731159cafdabda3dc727b2508c1 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 25 Apr 2024 12:49:10 -0700 Subject: [PATCH] Nick: v15 --- apps/js-sdk/firecrawl/build/index.js | 37 +++++++++++++++++++++++ apps/js-sdk/firecrawl/package.json | 2 +- apps/js-sdk/firecrawl/src/index.ts | 41 ++++++++++++++++++++++++++ apps/js-sdk/firecrawl/types/index.d.ts | 15 ++++++++++ apps/js-sdk/package-lock.json | 8 ++--- apps/js-sdk/package.json | 2 +- 6 files changed, 99 insertions(+), 6 deletions(-) diff --git a/apps/js-sdk/firecrawl/build/index.js b/apps/js-sdk/firecrawl/build/index.js index 1b23bb5..9d8237b 100644 --- a/apps/js-sdk/firecrawl/build/index.js +++ b/apps/js-sdk/firecrawl/build/index.js @@ -61,6 +61,43 @@ export default class FirecrawlApp { return { success: false, error: 'Internal server error.' }; }); } + /** + * Searches for a query using the Firecrawl API. + * @param {string} query - The query to search for. + * @param {Params | null} params - Additional parameters for the search request. + * @returns {Promise} The response from the search operation. + */ + search(query_1) { + return __awaiter(this, arguments, void 0, function* (query, params = null) { + const headers = { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.apiKey}`, + }; + let jsonData = { query }; + if (params) { + jsonData = Object.assign(Object.assign({}, jsonData), params); + } + try { + const response = yield axios.post('https://api.firecrawl.dev/v0/search', jsonData, { headers }); + if (response.status === 200) { + const responseData = response.data; + if (responseData.success) { + return responseData; + } + else { + throw new Error(`Failed to search. Error: ${responseData.error}`); + } + } + else { + this.handleError(response, 'search'); + } + } + catch (error) { + throw new Error(error.message); + } + return { success: false, error: 'Internal server error.' }; + }); + } /** * Initiates a crawl job for a URL using the Firecrawl API. * @param {string} url - The URL to crawl. diff --git a/apps/js-sdk/firecrawl/package.json b/apps/js-sdk/firecrawl/package.json index 566fdde..c35a93b 100644 --- a/apps/js-sdk/firecrawl/package.json +++ b/apps/js-sdk/firecrawl/package.json @@ -1,6 +1,6 @@ { "name": "@mendable/firecrawl-js", - "version": "0.0.13", + "version": "0.0.15", "description": "JavaScript SDK for Firecrawl API", "main": "build/index.js", "types": "types/index.d.ts", diff --git a/apps/js-sdk/firecrawl/src/index.ts b/apps/js-sdk/firecrawl/src/index.ts index 6545600..54e4e23 100644 --- a/apps/js-sdk/firecrawl/src/index.ts +++ b/apps/js-sdk/firecrawl/src/index.ts @@ -25,6 +25,14 @@ export interface ScrapeResponse { error?: string; } +/** + * Response interface for searching operations. + */ +export interface SearchResponse { + success: boolean; + data?: any; + error?: string; +} /** * Response interface for crawling operations. */ @@ -96,6 +104,39 @@ export default class FirecrawlApp { return { success: false, error: 'Internal server error.' }; } + /** + * Searches for a query using the Firecrawl API. + * @param {string} query - The query to search for. + * @param {Params | null} params - Additional parameters for the search request. + * @returns {Promise} The response from the search operation. + */ + async search(query: string, params: Params | null = null): Promise { + const headers: AxiosRequestHeaders = { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.apiKey}`, + } as AxiosRequestHeaders; + let jsonData: Params = { query }; + if (params) { + jsonData = { ...jsonData, ...params }; + } + try { + const response: AxiosResponse = await axios.post('https://api.firecrawl.dev/v0/search', jsonData, { headers }); + if (response.status === 200) { + const responseData = response.data; + if (responseData.success) { + return responseData; + } else { + throw new Error(`Failed to search. Error: ${responseData.error}`); + } + } else { + this.handleError(response, 'search'); + } + } catch (error: any) { + throw new Error(error.message); + } + return { success: false, error: 'Internal server error.' }; + } + /** * Initiates a crawl job for a URL using the Firecrawl API. * @param {string} url - The URL to crawl. diff --git a/apps/js-sdk/firecrawl/types/index.d.ts b/apps/js-sdk/firecrawl/types/index.d.ts index be960f7..7f79d64 100644 --- a/apps/js-sdk/firecrawl/types/index.d.ts +++ b/apps/js-sdk/firecrawl/types/index.d.ts @@ -19,6 +19,14 @@ export interface ScrapeResponse { data?: any; error?: string; } +/** + * Response interface for searching operations. + */ +export interface SearchResponse { + success: boolean; + data?: any; + error?: string; +} /** * Response interface for crawling operations. */ @@ -55,6 +63,13 @@ export default class FirecrawlApp { * @returns {Promise} The response from the scrape operation. */ scrapeUrl(url: string, params?: Params | null): Promise; + /** + * Searches for a query using the Firecrawl API. + * @param {string} query - The query to search for. + * @param {Params | null} params - Additional parameters for the search request. + * @returns {Promise} The response from the search operation. + */ + search(query: string, params?: Params | null): Promise; /** * Initiates a crawl job for a URL using the Firecrawl API. * @param {string} url - The URL to crawl. diff --git a/apps/js-sdk/package-lock.json b/apps/js-sdk/package-lock.json index a73272f..363f301 100644 --- a/apps/js-sdk/package-lock.json +++ b/apps/js-sdk/package-lock.json @@ -9,14 +9,14 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@mendable/firecrawl-js": "^0.0.8", + "@mendable/firecrawl-js": "^0.0.15", "axios": "^1.6.8" } }, "node_modules/@mendable/firecrawl-js": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/@mendable/firecrawl-js/-/firecrawl-js-0.0.8.tgz", - "integrity": "sha512-dD7eA5X6UT8CM3z7qCqHgA4YbCsdwmmlaT/L0/ozM6gGvb0PnJMoB+e51+n4lAW8mxXOvHGbq9nrgBT1wEhhhw==", + "version": "0.0.15", + "resolved": "https://registry.npmjs.org/@mendable/firecrawl-js/-/firecrawl-js-0.0.15.tgz", + "integrity": "sha512-e3iCCrLIiEh+jEDerGV9Uhdkn8ymo+sG+k3osCwPg51xW1xUdAnmlcHrcJoR43RvKXdvD/lqoxg8odUEsqyH+w==", "dependencies": { "axios": "^1.6.8", "dotenv": "^16.4.5" diff --git a/apps/js-sdk/package.json b/apps/js-sdk/package.json index 9bb5c4f..563e1e3 100644 --- a/apps/js-sdk/package.json +++ b/apps/js-sdk/package.json @@ -11,7 +11,7 @@ "author": "", "license": "ISC", "dependencies": { - "@mendable/firecrawl-js": "^0.0.8", + "@mendable/firecrawl-js": "^0.0.15", "axios": "^1.6.8" } }