firecrawl 1.5.3 → 1.6.1

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/dist/index.cjs CHANGED
@@ -108,7 +108,7 @@ var FirecrawlApp = class {
108
108
  this.handleError(response, "scrape URL");
109
109
  }
110
110
  } catch (error) {
111
- throw new FirecrawlError(error.message, 500);
111
+ this.handleError(error.response, "scrape URL");
112
112
  }
113
113
  return { success: false, error: "Internal server error." };
114
114
  }
@@ -224,6 +224,35 @@ var FirecrawlApp = class {
224
224
  }
225
225
  return { success: false, error: "Internal server error." };
226
226
  }
227
+ /**
228
+ * Cancels a crawl job using the Firecrawl API.
229
+ * @param id - The ID of the crawl operation.
230
+ * @returns The response from the cancel crawl operation.
231
+ */
232
+ async cancelCrawl(id) {
233
+ const headers = this.prepareHeaders();
234
+ try {
235
+ const response = await this.deleteRequest(
236
+ `${this.apiUrl}/v1/crawl/${id}`,
237
+ headers
238
+ );
239
+ if (response.status === 200) {
240
+ return response.data;
241
+ } else {
242
+ this.handleError(response, "cancel crawl job");
243
+ }
244
+ } catch (error) {
245
+ throw new FirecrawlError(error.message, 500);
246
+ }
247
+ return { success: false, error: "Internal server error." };
248
+ }
249
+ /**
250
+ * Initiates a crawl job and returns a CrawlWatcher to monitor the job via WebSocket.
251
+ * @param url - The URL to crawl.
252
+ * @param params - Additional parameters for the crawl request.
253
+ * @param idempotencyKey - Optional idempotency key for the request.
254
+ * @returns A CrawlWatcher instance to monitor the crawl job.
255
+ */
227
256
  async crawlUrlAndWatch(url, params, idempotencyKey) {
228
257
  const crawl = await this.asyncCrawlUrl(url, params, idempotencyKey);
229
258
  if (crawl.success && crawl.id) {
@@ -232,6 +261,12 @@ var FirecrawlApp = class {
232
261
  }
233
262
  throw new FirecrawlError("Crawl job failed to start", 400);
234
263
  }
264
+ /**
265
+ * Maps a URL using the Firecrawl API.
266
+ * @param url - The URL to map.
267
+ * @param params - Additional parameters for the map request.
268
+ * @returns The response from the map operation.
269
+ */
235
270
  async mapUrl(url, params) {
236
271
  const headers = this.prepareHeaders();
237
272
  let jsonData = { url, ...params };
@@ -290,6 +325,23 @@ var FirecrawlApp = class {
290
325
  }
291
326
  }
292
327
  }
328
+ /**
329
+ * Sends a DELETE request to the specified URL.
330
+ * @param url - The URL to send the request to.
331
+ * @param headers - The headers for the request.
332
+ * @returns The response from the DELETE request.
333
+ */
334
+ async deleteRequest(url, headers) {
335
+ try {
336
+ return await import_axios.default.delete(url, { headers });
337
+ } catch (error) {
338
+ if (error instanceof import_axios.AxiosError && error.response) {
339
+ return error.response;
340
+ } else {
341
+ throw error;
342
+ }
343
+ }
344
+ }
293
345
  /**
294
346
  * Monitors the status of a crawl job until completion or failure.
295
347
  * @param id - The ID of the crawl operation.
package/dist/index.d.cts CHANGED
@@ -234,7 +234,26 @@ declare class FirecrawlApp {
234
234
  * @returns The response containing the job status.
235
235
  */
236
236
  checkCrawlStatus(id?: string, getAllData?: boolean): Promise<CrawlStatusResponse | ErrorResponse>;
237
+ /**
238
+ * Cancels a crawl job using the Firecrawl API.
239
+ * @param id - The ID of the crawl operation.
240
+ * @returns The response from the cancel crawl operation.
241
+ */
242
+ cancelCrawl(id: string): Promise<ErrorResponse>;
243
+ /**
244
+ * Initiates a crawl job and returns a CrawlWatcher to monitor the job via WebSocket.
245
+ * @param url - The URL to crawl.
246
+ * @param params - Additional parameters for the crawl request.
247
+ * @param idempotencyKey - Optional idempotency key for the request.
248
+ * @returns A CrawlWatcher instance to monitor the crawl job.
249
+ */
237
250
  crawlUrlAndWatch(url: string, params?: CrawlParams, idempotencyKey?: string): Promise<CrawlWatcher>;
251
+ /**
252
+ * Maps a URL using the Firecrawl API.
253
+ * @param url - The URL to map.
254
+ * @param params - Additional parameters for the map request.
255
+ * @returns The response from the map operation.
256
+ */
238
257
  mapUrl(url: string, params?: MapParams): Promise<MapResponse | ErrorResponse>;
239
258
  /**
240
259
  * Prepares the headers for an API request.
@@ -257,6 +276,13 @@ declare class FirecrawlApp {
257
276
  * @returns The response from the GET request.
258
277
  */
259
278
  getRequest(url: string, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
279
+ /**
280
+ * Sends a DELETE request to the specified URL.
281
+ * @param url - The URL to send the request to.
282
+ * @param headers - The headers for the request.
283
+ * @returns The response from the DELETE request.
284
+ */
285
+ deleteRequest(url: string, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
260
286
  /**
261
287
  * Monitors the status of a crawl job until completion or failure.
262
288
  * @param id - The ID of the crawl operation.
package/dist/index.d.ts CHANGED
@@ -234,7 +234,26 @@ declare class FirecrawlApp {
234
234
  * @returns The response containing the job status.
235
235
  */
236
236
  checkCrawlStatus(id?: string, getAllData?: boolean): Promise<CrawlStatusResponse | ErrorResponse>;
237
+ /**
238
+ * Cancels a crawl job using the Firecrawl API.
239
+ * @param id - The ID of the crawl operation.
240
+ * @returns The response from the cancel crawl operation.
241
+ */
242
+ cancelCrawl(id: string): Promise<ErrorResponse>;
243
+ /**
244
+ * Initiates a crawl job and returns a CrawlWatcher to monitor the job via WebSocket.
245
+ * @param url - The URL to crawl.
246
+ * @param params - Additional parameters for the crawl request.
247
+ * @param idempotencyKey - Optional idempotency key for the request.
248
+ * @returns A CrawlWatcher instance to monitor the crawl job.
249
+ */
237
250
  crawlUrlAndWatch(url: string, params?: CrawlParams, idempotencyKey?: string): Promise<CrawlWatcher>;
251
+ /**
252
+ * Maps a URL using the Firecrawl API.
253
+ * @param url - The URL to map.
254
+ * @param params - Additional parameters for the map request.
255
+ * @returns The response from the map operation.
256
+ */
238
257
  mapUrl(url: string, params?: MapParams): Promise<MapResponse | ErrorResponse>;
239
258
  /**
240
259
  * Prepares the headers for an API request.
@@ -257,6 +276,13 @@ declare class FirecrawlApp {
257
276
  * @returns The response from the GET request.
258
277
  */
259
278
  getRequest(url: string, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
279
+ /**
280
+ * Sends a DELETE request to the specified URL.
281
+ * @param url - The URL to send the request to.
282
+ * @param headers - The headers for the request.
283
+ * @returns The response from the DELETE request.
284
+ */
285
+ deleteRequest(url: string, headers: AxiosRequestHeaders): Promise<AxiosResponse>;
260
286
  /**
261
287
  * Monitors the status of a crawl job until completion or failure.
262
288
  * @param id - The ID of the crawl operation.
package/dist/index.js CHANGED
@@ -72,7 +72,7 @@ var FirecrawlApp = class {
72
72
  this.handleError(response, "scrape URL");
73
73
  }
74
74
  } catch (error) {
75
- throw new FirecrawlError(error.message, 500);
75
+ this.handleError(error.response, "scrape URL");
76
76
  }
77
77
  return { success: false, error: "Internal server error." };
78
78
  }
@@ -188,6 +188,35 @@ var FirecrawlApp = class {
188
188
  }
189
189
  return { success: false, error: "Internal server error." };
190
190
  }
191
+ /**
192
+ * Cancels a crawl job using the Firecrawl API.
193
+ * @param id - The ID of the crawl operation.
194
+ * @returns The response from the cancel crawl operation.
195
+ */
196
+ async cancelCrawl(id) {
197
+ const headers = this.prepareHeaders();
198
+ try {
199
+ const response = await this.deleteRequest(
200
+ `${this.apiUrl}/v1/crawl/${id}`,
201
+ headers
202
+ );
203
+ if (response.status === 200) {
204
+ return response.data;
205
+ } else {
206
+ this.handleError(response, "cancel crawl job");
207
+ }
208
+ } catch (error) {
209
+ throw new FirecrawlError(error.message, 500);
210
+ }
211
+ return { success: false, error: "Internal server error." };
212
+ }
213
+ /**
214
+ * Initiates a crawl job and returns a CrawlWatcher to monitor the job via WebSocket.
215
+ * @param url - The URL to crawl.
216
+ * @param params - Additional parameters for the crawl request.
217
+ * @param idempotencyKey - Optional idempotency key for the request.
218
+ * @returns A CrawlWatcher instance to monitor the crawl job.
219
+ */
191
220
  async crawlUrlAndWatch(url, params, idempotencyKey) {
192
221
  const crawl = await this.asyncCrawlUrl(url, params, idempotencyKey);
193
222
  if (crawl.success && crawl.id) {
@@ -196,6 +225,12 @@ var FirecrawlApp = class {
196
225
  }
197
226
  throw new FirecrawlError("Crawl job failed to start", 400);
198
227
  }
228
+ /**
229
+ * Maps a URL using the Firecrawl API.
230
+ * @param url - The URL to map.
231
+ * @param params - Additional parameters for the map request.
232
+ * @returns The response from the map operation.
233
+ */
199
234
  async mapUrl(url, params) {
200
235
  const headers = this.prepareHeaders();
201
236
  let jsonData = { url, ...params };
@@ -254,6 +289,23 @@ var FirecrawlApp = class {
254
289
  }
255
290
  }
256
291
  }
292
+ /**
293
+ * Sends a DELETE request to the specified URL.
294
+ * @param url - The URL to send the request to.
295
+ * @param headers - The headers for the request.
296
+ * @returns The response from the DELETE request.
297
+ */
298
+ async deleteRequest(url, headers) {
299
+ try {
300
+ return await axios.delete(url, { headers });
301
+ } catch (error) {
302
+ if (error instanceof AxiosError && error.response) {
303
+ return error.response;
304
+ } else {
305
+ throw error;
306
+ }
307
+ }
308
+ }
257
309
  /**
258
310
  * Monitors the status of a crawl job until completion or failure.
259
311
  * @param id - The ID of the crawl operation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firecrawl",
3
- "version": "1.5.3",
3
+ "version": "1.6.1",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -287,7 +287,7 @@ export default class FirecrawlApp {
287
287
  this.handleError(response, "scrape URL");
288
288
  }
289
289
  } catch (error: any) {
290
- throw new FirecrawlError(error.message, 500);
290
+ this.handleError(error.response, "scrape URL");
291
291
  }
292
292
  return { success: false, error: "Internal server error." };
293
293
  }
@@ -421,6 +421,36 @@ export default class FirecrawlApp {
421
421
  return { success: false, error: "Internal server error." };
422
422
  }
423
423
 
424
+ /**
425
+ * Cancels a crawl job using the Firecrawl API.
426
+ * @param id - The ID of the crawl operation.
427
+ * @returns The response from the cancel crawl operation.
428
+ */
429
+ async cancelCrawl(id: string): Promise<ErrorResponse> {
430
+ const headers = this.prepareHeaders();
431
+ try {
432
+ const response: AxiosResponse = await this.deleteRequest(
433
+ `${this.apiUrl}/v1/crawl/${id}`,
434
+ headers
435
+ );
436
+ if (response.status === 200) {
437
+ return response.data;
438
+ } else {
439
+ this.handleError(response, "cancel crawl job");
440
+ }
441
+ } catch (error: any) {
442
+ throw new FirecrawlError(error.message, 500);
443
+ }
444
+ return { success: false, error: "Internal server error." };
445
+ }
446
+
447
+ /**
448
+ * Initiates a crawl job and returns a CrawlWatcher to monitor the job via WebSocket.
449
+ * @param url - The URL to crawl.
450
+ * @param params - Additional parameters for the crawl request.
451
+ * @param idempotencyKey - Optional idempotency key for the request.
452
+ * @returns A CrawlWatcher instance to monitor the crawl job.
453
+ */
424
454
  async crawlUrlAndWatch(
425
455
  url: string,
426
456
  params?: CrawlParams,
@@ -436,6 +466,12 @@ export default class FirecrawlApp {
436
466
  throw new FirecrawlError("Crawl job failed to start", 400);
437
467
  }
438
468
 
469
+ /**
470
+ * Maps a URL using the Firecrawl API.
471
+ * @param url - The URL to map.
472
+ * @param params - Additional parameters for the map request.
473
+ * @returns The response from the map operation.
474
+ */
439
475
  async mapUrl(url: string, params?: MapParams): Promise<MapResponse | ErrorResponse> {
440
476
  const headers = this.prepareHeaders();
441
477
  let jsonData: { url: string } & MapParams = { url, ...params };
@@ -506,6 +542,27 @@ export default class FirecrawlApp {
506
542
  }
507
543
  }
508
544
 
545
+ /**
546
+ * Sends a DELETE request to the specified URL.
547
+ * @param url - The URL to send the request to.
548
+ * @param headers - The headers for the request.
549
+ * @returns The response from the DELETE request.
550
+ */
551
+ async deleteRequest(
552
+ url: string,
553
+ headers: AxiosRequestHeaders
554
+ ): Promise<AxiosResponse> {
555
+ try {
556
+ return await axios.delete(url, { headers });
557
+ } catch (error) {
558
+ if (error instanceof AxiosError && error.response) {
559
+ return error.response as AxiosResponse;
560
+ } else {
561
+ throw error;
562
+ }
563
+ }
564
+ }
565
+
509
566
  /**
510
567
  * Monitors the status of a crawl job until completion or failure.
511
568
  * @param id - The ID of the crawl operation.