@mendable/firecrawl-js 1.18.0-beta.4 → 1.18.0-beta.7

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
@@ -862,23 +862,28 @@ var FirecrawlApp = class {
862
862
  if (!response.success || "error" in response) {
863
863
  return { success: false, error: "error" in response ? response.error : "Unknown error" };
864
864
  }
865
- if (response.id) {
866
- const jobId = response.id;
867
- let researchStatus;
868
- do {
869
- researchStatus = await this.__checkDeepResearchStatus(jobId);
870
- if ("error" in researchStatus && !researchStatus.success) {
871
- return researchStatus;
872
- }
873
- if (researchStatus.status === "completed" && researchStatus.data) {
874
- return researchStatus;
875
- } else if (researchStatus.status === "failed") {
876
- throw new FirecrawlError(`Research job failed. Error: ${researchStatus.error}`, 500);
877
- }
878
- await new Promise((resolve) => setTimeout(resolve, 1e3));
879
- } while (researchStatus.status !== "completed");
865
+ if (!response.id) {
866
+ throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
880
867
  }
881
- throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
868
+ const jobId = response.id;
869
+ let researchStatus;
870
+ do {
871
+ researchStatus = await this.__checkDeepResearchStatus(jobId);
872
+ if ("error" in researchStatus && !researchStatus.success) {
873
+ return researchStatus;
874
+ }
875
+ if (researchStatus.status === "completed") {
876
+ return researchStatus;
877
+ }
878
+ if (researchStatus.status === "failed") {
879
+ throw new FirecrawlError(
880
+ `Research job ${researchStatus.status}. Error: ${researchStatus.error}`,
881
+ 500
882
+ );
883
+ }
884
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
885
+ } while (researchStatus.status === "processing");
886
+ return { success: false, error: "Research job terminated unexpectedly" };
882
887
  } catch (error) {
883
888
  throw new FirecrawlError(error.message, 500, error.response?.data?.details);
884
889
  }
package/dist/index.js CHANGED
@@ -826,23 +826,28 @@ var FirecrawlApp = class {
826
826
  if (!response.success || "error" in response) {
827
827
  return { success: false, error: "error" in response ? response.error : "Unknown error" };
828
828
  }
829
- if (response.id) {
830
- const jobId = response.id;
831
- let researchStatus;
832
- do {
833
- researchStatus = await this.__checkDeepResearchStatus(jobId);
834
- if ("error" in researchStatus && !researchStatus.success) {
835
- return researchStatus;
836
- }
837
- if (researchStatus.status === "completed" && researchStatus.data) {
838
- return researchStatus;
839
- } else if (researchStatus.status === "failed") {
840
- throw new FirecrawlError(`Research job failed. Error: ${researchStatus.error}`, 500);
841
- }
842
- await new Promise((resolve) => setTimeout(resolve, 1e3));
843
- } while (researchStatus.status !== "completed");
844
- }
845
- throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
829
+ if (!response.id) {
830
+ throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
831
+ }
832
+ const jobId = response.id;
833
+ let researchStatus;
834
+ do {
835
+ researchStatus = await this.__checkDeepResearchStatus(jobId);
836
+ if ("error" in researchStatus && !researchStatus.success) {
837
+ return researchStatus;
838
+ }
839
+ if (researchStatus.status === "completed") {
840
+ return researchStatus;
841
+ }
842
+ if (researchStatus.status === "failed") {
843
+ throw new FirecrawlError(
844
+ `Research job ${researchStatus.status}. Error: ${researchStatus.error}`,
845
+ 500
846
+ );
847
+ }
848
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
849
+ } while (researchStatus.status === "processing");
850
+ return { success: false, error: "Research job terminated unexpectedly" };
846
851
  } catch (error) {
847
852
  throw new FirecrawlError(error.message, 500, error.response?.data?.details);
848
853
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mendable/firecrawl-js",
3
- "version": "1.18.0-beta.4",
3
+ "version": "1.18.0-beta.7",
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
@@ -1362,25 +1362,38 @@ export default class FirecrawlApp {
1362
1362
  return { success: false, error: 'error' in response ? response.error : 'Unknown error' };
1363
1363
  }
1364
1364
 
1365
- if (response.id) {
1366
- const jobId = response.id;
1367
- let researchStatus;
1368
- do {
1369
- researchStatus = await this.__checkDeepResearchStatus(jobId);
1370
-
1371
- if ('error' in researchStatus && !researchStatus.success) {
1372
- return researchStatus;
1373
- }
1374
-
1375
- if (researchStatus.status === "completed" && researchStatus.data) {
1376
- return researchStatus;
1377
- } else if (researchStatus.status === "failed") {
1378
- throw new FirecrawlError(`Research job failed. Error: ${researchStatus.error}`, 500);
1379
- }
1380
- await new Promise(resolve => setTimeout(resolve, 1000)); // Polling interval
1381
- } while (researchStatus.status !== "completed");
1365
+ if (!response.id) {
1366
+ throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
1382
1367
  }
1383
- throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
1368
+
1369
+ const jobId = response.id;
1370
+ let researchStatus;
1371
+
1372
+ do {
1373
+ // console.log("Checking research status...");
1374
+ researchStatus = await this.__checkDeepResearchStatus(jobId);
1375
+ // console.log("Research status:", researchStatus);
1376
+
1377
+ if ('error' in researchStatus && !researchStatus.success) {
1378
+ return researchStatus;
1379
+ }
1380
+
1381
+ if (researchStatus.status === "completed") {
1382
+ return researchStatus;
1383
+ }
1384
+
1385
+ if (researchStatus.status === "failed") {
1386
+ throw new FirecrawlError(
1387
+ `Research job ${researchStatus.status}. Error: ${researchStatus.error}`,
1388
+ 500
1389
+ );
1390
+ }
1391
+
1392
+ await new Promise(resolve => setTimeout(resolve, 1000));
1393
+ } while (researchStatus.status === "processing");
1394
+ // console.log("Research status finished:", researchStatus);
1395
+
1396
+ return { success: false, error: "Research job terminated unexpectedly" };
1384
1397
  } catch (error: any) {
1385
1398
  throw new FirecrawlError(error.message, 500, error.response?.data?.details);
1386
1399
  }