@mendable/firecrawl-js 0.0.10 → 0.0.12
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/package.json +2 -1
- package/src/index.ts +1 -1
- package/tsconfig.json +5 -3
- package/types/index.d.ts +107 -0
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mendable/firecrawl-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "JavaScript SDK for Firecrawl API",
|
|
5
5
|
"main": "build/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/index.ts
CHANGED
|
@@ -104,7 +104,7 @@ export default class FirecrawlApp {
|
|
|
104
104
|
* @param {number} timeout - Timeout in seconds for job status checks.
|
|
105
105
|
* @returns {Promise<CrawlResponse>} The response from the crawl operation.
|
|
106
106
|
*/
|
|
107
|
-
async crawlUrl(url: string, params: Params | null = null, waitUntilDone: boolean = true, timeout: number = 2): Promise<CrawlResponse> {
|
|
107
|
+
async crawlUrl(url: string, params: Params | null = null, waitUntilDone: boolean = true, timeout: number = 2): Promise<CrawlResponse | any> {
|
|
108
108
|
const headers = this.prepareHeaders();
|
|
109
109
|
let jsonData: Params = { url };
|
|
110
110
|
if (params) {
|
package/tsconfig.json
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
50
50
|
|
|
51
51
|
/* Emit */
|
|
52
|
-
|
|
52
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
53
|
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
54
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
55
|
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
71
71
|
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
72
72
|
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
73
|
-
|
|
73
|
+
"declarationDir": "./types", /* Specify the output directory for generated declaration files. */
|
|
74
74
|
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
75
75
|
|
|
76
76
|
/* Interop Constraints */
|
|
@@ -105,5 +105,7 @@
|
|
|
105
105
|
/* Completeness */
|
|
106
106
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
107
107
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
108
|
-
}
|
|
108
|
+
},
|
|
109
|
+
"include": ["src/**/*"],
|
|
110
|
+
"exclude": ["node_modules", "dist", "**/__tests__/*"]
|
|
109
111
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AxiosResponse, AxiosRequestHeaders } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration interface for FirecrawlApp.
|
|
4
|
+
*/
|
|
5
|
+
export interface FirecrawlAppConfig {
|
|
6
|
+
apiKey?: string | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generic parameter interface.
|
|
10
|
+
*/
|
|
11
|
+
export interface Params {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Response interface for scraping operations.
|
|
16
|
+
*/
|
|
17
|
+
export interface ScrapeResponse {
|
|
18
|
+
success: boolean;
|
|
19
|
+
data?: any;
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Response interface for crawling operations.
|
|
24
|
+
*/
|
|
25
|
+
export interface CrawlResponse {
|
|
26
|
+
success: boolean;
|
|
27
|
+
jobId?: string;
|
|
28
|
+
data?: any;
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Response interface for job status checks.
|
|
33
|
+
*/
|
|
34
|
+
export interface JobStatusResponse {
|
|
35
|
+
success: boolean;
|
|
36
|
+
status: string;
|
|
37
|
+
jobId?: string;
|
|
38
|
+
data?: any;
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Main class for interacting with the Firecrawl API.
|
|
43
|
+
*/
|
|
44
|
+
export default class FirecrawlApp {
|
|
45
|
+
private apiKey;
|
|
46
|
+
/**
|
|
47
|
+
* Initializes a new instance of the FirecrawlApp class.
|
|
48
|
+
* @param {FirecrawlAppConfig} config - Configuration options for the FirecrawlApp instance.
|
|
49
|
+
*/
|
|
50
|
+
constructor({ apiKey }: FirecrawlAppConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Scrapes a URL using the Firecrawl API.
|
|
53
|
+
* @param {string} url - The URL to scrape.
|
|
54
|
+
* @param {Params | null} params - Additional parameters for the scrape request.
|
|
55
|
+
* @returns {Promise<ScrapeResponse>} The response from the scrape operation.
|
|
56
|
+
*/
|
|
57
|
+
scrapeUrl(url: string, params?: Params | null): Promise<ScrapeResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Initiates a crawl job for a URL using the Firecrawl API.
|
|
60
|
+
* @param {string} url - The URL to crawl.
|
|
61
|
+
* @param {Params | null} params - Additional parameters for the crawl request.
|
|
62
|
+
* @param {boolean} waitUntilDone - Whether to wait for the crawl job to complete.
|
|
63
|
+
* @param {number} timeout - Timeout in seconds for job status checks.
|
|
64
|
+
* @returns {Promise<CrawlResponse>} The response from the crawl operation.
|
|
65
|
+
*/
|
|
66
|
+
crawlUrl(url: string, params?: Params | null, waitUntilDone?: boolean, timeout?: number): Promise<CrawlResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Checks the status of a crawl job using the Firecrawl API.
|
|
69
|
+
* @param {string} jobId - The job ID of the crawl operation.
|
|
70
|
+
* @returns {Promise<JobStatusResponse>} The response containing the job status.
|
|
71
|
+
*/
|
|
72
|
+
checkCrawlStatus(jobId: string): Promise<JobStatusResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Prepares the headers for an API request.
|
|
75
|
+
* @returns {AxiosRequestHeaders} The prepared headers.
|
|
76
|
+
*/
|
|
77
|
+
prepareHeaders(): AxiosRequestHeaders;
|
|
78
|
+
/**
|
|
79
|
+
* Sends a POST request to the specified URL.
|
|
80
|
+
* @param {string} url - The URL to send the request to.
|
|
81
|
+
* @param {Params} data - The data to send in the request.
|
|
82
|
+
* @param {AxiosRequestHeaders} headers - The headers for the request.
|
|
83
|
+
* @returns {Promise<AxiosResponse>} The response from the POST request.
|
|
84
|
+
*/
|
|
85
|
+
postRequest(url: string, data: Params, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Sends a GET request to the specified URL.
|
|
88
|
+
* @param {string} url - The URL to send the request to.
|
|
89
|
+
* @param {AxiosRequestHeaders} headers - The headers for the request.
|
|
90
|
+
* @returns {Promise<AxiosResponse>} The response from the GET request.
|
|
91
|
+
*/
|
|
92
|
+
getRequest(url: string, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Monitors the status of a crawl job until completion or failure.
|
|
95
|
+
* @param {string} jobId - The job ID of the crawl operation.
|
|
96
|
+
* @param {AxiosRequestHeaders} headers - The headers for the request.
|
|
97
|
+
* @param {number} timeout - Timeout in seconds for job status checks.
|
|
98
|
+
* @returns {Promise<any>} The final job status or data.
|
|
99
|
+
*/
|
|
100
|
+
monitorJobStatus(jobId: string, headers: AxiosRequestHeaders, timeout: number): Promise<any>;
|
|
101
|
+
/**
|
|
102
|
+
* Handles errors from API responses.
|
|
103
|
+
* @param {AxiosResponse} response - The response from the API.
|
|
104
|
+
* @param {string} action - The action being performed when the error occurred.
|
|
105
|
+
*/
|
|
106
|
+
handleError(response: AxiosResponse, action: string): void;
|
|
107
|
+
}
|