@mendable/firecrawl-js 4.20.0 → 4.20.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.
|
@@ -8,7 +8,7 @@ var require_package = __commonJS({
|
|
|
8
8
|
"package.json"(exports, module) {
|
|
9
9
|
module.exports = {
|
|
10
10
|
name: "@mendable/firecrawl-js",
|
|
11
|
-
version: "4.20.
|
|
11
|
+
version: "4.20.1",
|
|
12
12
|
description: "JavaScript SDK for Firecrawl API",
|
|
13
13
|
main: "dist/index.js",
|
|
14
14
|
types: "dist/index.d.ts",
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var require_package = __commonJS({
|
|
|
35
35
|
"package.json"(exports2, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "@mendable/firecrawl-js",
|
|
38
|
-
version: "4.20.
|
|
38
|
+
version: "4.20.1",
|
|
39
39
|
description: "JavaScript SDK for Firecrawl API",
|
|
40
40
|
main: "dist/index.js",
|
|
41
41
|
types: "dist/index.d.ts",
|
|
@@ -1418,23 +1418,41 @@ var Watcher = class extends import_events.EventEmitter {
|
|
|
1418
1418
|
return `${wsBase}${path}`;
|
|
1419
1419
|
}
|
|
1420
1420
|
async start() {
|
|
1421
|
-
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1421
|
+
return new Promise((resolve, reject) => {
|
|
1422
|
+
const onDone = () => {
|
|
1423
|
+
cleanup();
|
|
1424
|
+
resolve();
|
|
1425
|
+
};
|
|
1426
|
+
const onError = (err) => {
|
|
1427
|
+
cleanup();
|
|
1428
|
+
resolve();
|
|
1429
|
+
};
|
|
1430
|
+
const cleanup = () => {
|
|
1431
|
+
this.removeListener("done", onDone);
|
|
1432
|
+
this.removeListener("error", onError);
|
|
1433
|
+
};
|
|
1434
|
+
this.on("done", onDone);
|
|
1435
|
+
this.on("error", onError);
|
|
1436
|
+
(async () => {
|
|
1437
|
+
try {
|
|
1438
|
+
const url = this.buildWsUrl();
|
|
1439
|
+
const wsCtor = await getWebSocketCtor();
|
|
1440
|
+
if (!wsCtor) {
|
|
1441
|
+
this.pollLoop();
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
this.ws = new wsCtor(url, this.http.getApiKey());
|
|
1445
|
+
if (this.ws && "binaryType" in this.ws) {
|
|
1446
|
+
this.ws.binaryType = "arraybuffer";
|
|
1447
|
+
}
|
|
1448
|
+
if (this.ws) {
|
|
1449
|
+
this.attachWsHandlers(this.ws);
|
|
1450
|
+
}
|
|
1451
|
+
} catch (err) {
|
|
1452
|
+
this.pollLoop();
|
|
1453
|
+
}
|
|
1454
|
+
})();
|
|
1455
|
+
});
|
|
1438
1456
|
}
|
|
1439
1457
|
attachWsHandlers(ws) {
|
|
1440
1458
|
let startTs = Date.now();
|
|
@@ -1457,14 +1475,14 @@ var Watcher = class extends import_events.EventEmitter {
|
|
|
1457
1475
|
}
|
|
1458
1476
|
if (type === "document") {
|
|
1459
1477
|
const doc = body.data;
|
|
1460
|
-
if (doc) this.
|
|
1478
|
+
if (doc) this.emitDocuments([doc]);
|
|
1461
1479
|
return;
|
|
1462
1480
|
}
|
|
1463
1481
|
if (type === "done") {
|
|
1464
1482
|
const payload2 = body.data || body;
|
|
1465
1483
|
const data = payload2.data || [];
|
|
1466
1484
|
if (data.length) this.emitDocuments(data);
|
|
1467
|
-
this.emit("done", { status: "completed", data, id: this.jobId });
|
|
1485
|
+
this.emit("done", { status: "completed", data, id: this.jobId, total: payload2.total, completed: payload2.completed, creditsUsed: payload2.creditsUsed });
|
|
1468
1486
|
this.close();
|
|
1469
1487
|
return;
|
|
1470
1488
|
}
|
|
@@ -1472,7 +1490,10 @@ var Watcher = class extends import_events.EventEmitter {
|
|
|
1472
1490
|
if (payload && payload.status) this.emitSnapshot(payload);
|
|
1473
1491
|
} catch {
|
|
1474
1492
|
}
|
|
1475
|
-
if (timeoutMs && Date.now() - startTs > timeoutMs)
|
|
1493
|
+
if (timeoutMs && Date.now() - startTs > timeoutMs) {
|
|
1494
|
+
this.emit("error", { status: "failed", data: [], error: "Watcher timeout", id: this.jobId });
|
|
1495
|
+
this.close();
|
|
1496
|
+
}
|
|
1476
1497
|
};
|
|
1477
1498
|
ws.onerror = () => {
|
|
1478
1499
|
this.emit("error", { status: "failed", data: [], error: "WebSocket error", id: this.jobId });
|
|
@@ -1528,7 +1549,7 @@ var Watcher = class extends import_events.EventEmitter {
|
|
|
1528
1549
|
};
|
|
1529
1550
|
this.emit("snapshot", snap);
|
|
1530
1551
|
if (["completed", "failed", "cancelled"].includes(status)) {
|
|
1531
|
-
this.emit("done", { status, data, id: this.jobId });
|
|
1552
|
+
this.emit("done", { status, data, id: this.jobId, total: payload.total ?? 0, completed: payload.completed ?? 0, creditsUsed: payload.creditsUsed });
|
|
1532
1553
|
this.close();
|
|
1533
1554
|
}
|
|
1534
1555
|
}
|
|
@@ -1541,13 +1562,17 @@ var Watcher = class extends import_events.EventEmitter {
|
|
|
1541
1562
|
this.emitDocuments(snap.data || []);
|
|
1542
1563
|
this.emit("snapshot", snap);
|
|
1543
1564
|
if (["completed", "failed", "cancelled"].includes(snap.status)) {
|
|
1544
|
-
this.emit("done", { status: snap.status, data: snap.data, id: this.jobId });
|
|
1565
|
+
this.emit("done", { status: snap.status, data: snap.data, id: this.jobId, total: snap.total ?? 0, completed: snap.completed ?? 0, creditsUsed: snap.creditsUsed });
|
|
1545
1566
|
this.close();
|
|
1546
1567
|
break;
|
|
1547
1568
|
}
|
|
1548
1569
|
} catch {
|
|
1549
1570
|
}
|
|
1550
|
-
if (timeoutMs && Date.now() - startTs > timeoutMs)
|
|
1571
|
+
if (timeoutMs && Date.now() - startTs > timeoutMs) {
|
|
1572
|
+
this.emit("error", { status: "failed", data: [], error: "Watcher timeout", id: this.jobId });
|
|
1573
|
+
this.close();
|
|
1574
|
+
break;
|
|
1575
|
+
}
|
|
1551
1576
|
await new Promise((r) => setTimeout(r, Math.max(1e3, this.pollInterval * 1e3)));
|
|
1552
1577
|
}
|
|
1553
1578
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
require_package
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OVLAEYRZ.js";
|
|
4
4
|
|
|
5
5
|
// src/v2/utils/httpClient.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -1294,23 +1294,41 @@ var Watcher = class extends EventEmitter {
|
|
|
1294
1294
|
return `${wsBase}${path}`;
|
|
1295
1295
|
}
|
|
1296
1296
|
async start() {
|
|
1297
|
-
|
|
1298
|
-
const
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1297
|
+
return new Promise((resolve, reject) => {
|
|
1298
|
+
const onDone = () => {
|
|
1299
|
+
cleanup();
|
|
1300
|
+
resolve();
|
|
1301
|
+
};
|
|
1302
|
+
const onError = (err) => {
|
|
1303
|
+
cleanup();
|
|
1304
|
+
resolve();
|
|
1305
|
+
};
|
|
1306
|
+
const cleanup = () => {
|
|
1307
|
+
this.removeListener("done", onDone);
|
|
1308
|
+
this.removeListener("error", onError);
|
|
1309
|
+
};
|
|
1310
|
+
this.on("done", onDone);
|
|
1311
|
+
this.on("error", onError);
|
|
1312
|
+
(async () => {
|
|
1313
|
+
try {
|
|
1314
|
+
const url = this.buildWsUrl();
|
|
1315
|
+
const wsCtor = await getWebSocketCtor();
|
|
1316
|
+
if (!wsCtor) {
|
|
1317
|
+
this.pollLoop();
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
this.ws = new wsCtor(url, this.http.getApiKey());
|
|
1321
|
+
if (this.ws && "binaryType" in this.ws) {
|
|
1322
|
+
this.ws.binaryType = "arraybuffer";
|
|
1323
|
+
}
|
|
1324
|
+
if (this.ws) {
|
|
1325
|
+
this.attachWsHandlers(this.ws);
|
|
1326
|
+
}
|
|
1327
|
+
} catch (err) {
|
|
1328
|
+
this.pollLoop();
|
|
1329
|
+
}
|
|
1330
|
+
})();
|
|
1331
|
+
});
|
|
1314
1332
|
}
|
|
1315
1333
|
attachWsHandlers(ws) {
|
|
1316
1334
|
let startTs = Date.now();
|
|
@@ -1333,14 +1351,14 @@ var Watcher = class extends EventEmitter {
|
|
|
1333
1351
|
}
|
|
1334
1352
|
if (type === "document") {
|
|
1335
1353
|
const doc = body.data;
|
|
1336
|
-
if (doc) this.
|
|
1354
|
+
if (doc) this.emitDocuments([doc]);
|
|
1337
1355
|
return;
|
|
1338
1356
|
}
|
|
1339
1357
|
if (type === "done") {
|
|
1340
1358
|
const payload2 = body.data || body;
|
|
1341
1359
|
const data = payload2.data || [];
|
|
1342
1360
|
if (data.length) this.emitDocuments(data);
|
|
1343
|
-
this.emit("done", { status: "completed", data, id: this.jobId });
|
|
1361
|
+
this.emit("done", { status: "completed", data, id: this.jobId, total: payload2.total, completed: payload2.completed, creditsUsed: payload2.creditsUsed });
|
|
1344
1362
|
this.close();
|
|
1345
1363
|
return;
|
|
1346
1364
|
}
|
|
@@ -1348,7 +1366,10 @@ var Watcher = class extends EventEmitter {
|
|
|
1348
1366
|
if (payload && payload.status) this.emitSnapshot(payload);
|
|
1349
1367
|
} catch {
|
|
1350
1368
|
}
|
|
1351
|
-
if (timeoutMs && Date.now() - startTs > timeoutMs)
|
|
1369
|
+
if (timeoutMs && Date.now() - startTs > timeoutMs) {
|
|
1370
|
+
this.emit("error", { status: "failed", data: [], error: "Watcher timeout", id: this.jobId });
|
|
1371
|
+
this.close();
|
|
1372
|
+
}
|
|
1352
1373
|
};
|
|
1353
1374
|
ws.onerror = () => {
|
|
1354
1375
|
this.emit("error", { status: "failed", data: [], error: "WebSocket error", id: this.jobId });
|
|
@@ -1404,7 +1425,7 @@ var Watcher = class extends EventEmitter {
|
|
|
1404
1425
|
};
|
|
1405
1426
|
this.emit("snapshot", snap);
|
|
1406
1427
|
if (["completed", "failed", "cancelled"].includes(status)) {
|
|
1407
|
-
this.emit("done", { status, data, id: this.jobId });
|
|
1428
|
+
this.emit("done", { status, data, id: this.jobId, total: payload.total ?? 0, completed: payload.completed ?? 0, creditsUsed: payload.creditsUsed });
|
|
1408
1429
|
this.close();
|
|
1409
1430
|
}
|
|
1410
1431
|
}
|
|
@@ -1417,13 +1438,17 @@ var Watcher = class extends EventEmitter {
|
|
|
1417
1438
|
this.emitDocuments(snap.data || []);
|
|
1418
1439
|
this.emit("snapshot", snap);
|
|
1419
1440
|
if (["completed", "failed", "cancelled"].includes(snap.status)) {
|
|
1420
|
-
this.emit("done", { status: snap.status, data: snap.data, id: this.jobId });
|
|
1441
|
+
this.emit("done", { status: snap.status, data: snap.data, id: this.jobId, total: snap.total ?? 0, completed: snap.completed ?? 0, creditsUsed: snap.creditsUsed });
|
|
1421
1442
|
this.close();
|
|
1422
1443
|
break;
|
|
1423
1444
|
}
|
|
1424
1445
|
} catch {
|
|
1425
1446
|
}
|
|
1426
|
-
if (timeoutMs && Date.now() - startTs > timeoutMs)
|
|
1447
|
+
if (timeoutMs && Date.now() - startTs > timeoutMs) {
|
|
1448
|
+
this.emit("error", { status: "failed", data: [], error: "Watcher timeout", id: this.jobId });
|
|
1449
|
+
this.close();
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1427
1452
|
await new Promise((r) => setTimeout(r, Math.max(1e3, this.pollInterval * 1e3)));
|
|
1428
1453
|
}
|
|
1429
1454
|
}
|
|
@@ -1778,7 +1803,7 @@ var FirecrawlApp = class {
|
|
|
1778
1803
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
1779
1804
|
return process.env.npm_package_version;
|
|
1780
1805
|
}
|
|
1781
|
-
const packageJson = await import("./package-
|
|
1806
|
+
const packageJson = await import("./package-4Q7WA3UI.js");
|
|
1782
1807
|
return packageJson.default.version;
|
|
1783
1808
|
} catch (error) {
|
|
1784
1809
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
package/package.json
CHANGED
package/src/v2/watcher.ts
CHANGED
|
@@ -109,24 +109,37 @@ export class Watcher extends EventEmitter {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
async start(): Promise<void> {
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
this.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
return new Promise<void>((resolve, reject) => {
|
|
113
|
+
const onDone = () => { cleanup(); resolve(); };
|
|
114
|
+
const onError = (err: any) => { cleanup(); resolve(); };
|
|
115
|
+
const cleanup = () => {
|
|
116
|
+
this.removeListener("done", onDone);
|
|
117
|
+
this.removeListener("error", onError);
|
|
118
|
+
};
|
|
119
|
+
this.on("done", onDone);
|
|
120
|
+
this.on("error", onError);
|
|
121
|
+
|
|
122
|
+
(async () => {
|
|
123
|
+
try {
|
|
124
|
+
const url = this.buildWsUrl();
|
|
125
|
+
const wsCtor = await getWebSocketCtor();
|
|
126
|
+
if (!wsCtor) {
|
|
127
|
+
this.pollLoop();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.ws = new wsCtor(url, this.http.getApiKey()) as any;
|
|
131
|
+
if (this.ws && "binaryType" in this.ws) {
|
|
132
|
+
(this.ws as any).binaryType = "arraybuffer";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (this.ws) {
|
|
136
|
+
this.attachWsHandlers(this.ws);
|
|
137
|
+
}
|
|
138
|
+
} catch (err) {
|
|
139
|
+
this.pollLoop();
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
});
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
private attachWsHandlers(ws: WebSocket) {
|
|
@@ -150,14 +163,14 @@ export class Watcher extends EventEmitter {
|
|
|
150
163
|
}
|
|
151
164
|
if (type === "document") {
|
|
152
165
|
const doc = body.data;
|
|
153
|
-
if (doc) this.
|
|
166
|
+
if (doc) this.emitDocuments([doc]);
|
|
154
167
|
return;
|
|
155
168
|
}
|
|
156
169
|
if (type === "done") {
|
|
157
170
|
const payload = body.data || body;
|
|
158
171
|
const data = (payload.data || []) as Document[];
|
|
159
172
|
if (data.length) this.emitDocuments(data);
|
|
160
|
-
this.emit("done", { status: "completed", data, id: this.jobId });
|
|
173
|
+
this.emit("done", { status: "completed", data, id: this.jobId, total: payload.total, completed: payload.completed, creditsUsed: payload.creditsUsed });
|
|
161
174
|
this.close();
|
|
162
175
|
return;
|
|
163
176
|
}
|
|
@@ -166,7 +179,10 @@ export class Watcher extends EventEmitter {
|
|
|
166
179
|
} catch {
|
|
167
180
|
// ignore
|
|
168
181
|
}
|
|
169
|
-
if (timeoutMs && Date.now() - startTs > timeoutMs)
|
|
182
|
+
if (timeoutMs && Date.now() - startTs > timeoutMs) {
|
|
183
|
+
this.emit("error", { status: "failed", data: [], error: "Watcher timeout", id: this.jobId });
|
|
184
|
+
this.close();
|
|
185
|
+
}
|
|
170
186
|
};
|
|
171
187
|
ws.onerror = () => {
|
|
172
188
|
this.emit("error", { status: "failed", data: [], error: "WebSocket error", id: this.jobId });
|
|
@@ -227,7 +243,7 @@ export class Watcher extends EventEmitter {
|
|
|
227
243
|
};
|
|
228
244
|
this.emit("snapshot", snap);
|
|
229
245
|
if (["completed", "failed", "cancelled"].includes(status)) {
|
|
230
|
-
this.emit("done", { status, data, id: this.jobId });
|
|
246
|
+
this.emit("done", { status, data, id: this.jobId, total: payload.total ?? 0, completed: payload.completed ?? 0, creditsUsed: payload.creditsUsed });
|
|
231
247
|
this.close();
|
|
232
248
|
}
|
|
233
249
|
}
|
|
@@ -243,14 +259,18 @@ export class Watcher extends EventEmitter {
|
|
|
243
259
|
this.emitDocuments((snap.data || []) as Document[]);
|
|
244
260
|
this.emit("snapshot", snap);
|
|
245
261
|
if (["completed", "failed", "cancelled"].includes(snap.status)) {
|
|
246
|
-
this.emit("done", { status: snap.status, data: snap.data, id: this.jobId });
|
|
262
|
+
this.emit("done", { status: snap.status, data: snap.data, id: this.jobId, total: (snap as any).total ?? 0, completed: (snap as any).completed ?? 0, creditsUsed: (snap as any).creditsUsed });
|
|
247
263
|
this.close();
|
|
248
264
|
break;
|
|
249
265
|
}
|
|
250
266
|
} catch {
|
|
251
267
|
// ignore polling errors
|
|
252
268
|
}
|
|
253
|
-
if (timeoutMs && Date.now() - startTs > timeoutMs)
|
|
269
|
+
if (timeoutMs && Date.now() - startTs > timeoutMs) {
|
|
270
|
+
this.emit("error", { status: "failed", data: [], error: "Watcher timeout", id: this.jobId });
|
|
271
|
+
this.close();
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
254
274
|
await new Promise((r) => setTimeout(r, Math.max(1000, this.pollInterval * 1000)));
|
|
255
275
|
}
|
|
256
276
|
}
|