mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-11 07:59:02 +08:00
Pass along current, total, current_step, and current_url in js sdk
This commit is contained in:
parent
fcc67a3c9e
commit
68828a5b5c
@ -157,8 +157,14 @@ export default class FirecrawlApp {
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
status: response.data.status,
|
status: response.data.status,
|
||||||
|
current: response.data.current,
|
||||||
|
current_url: response.data.current_url,
|
||||||
|
current_step: response.data.current_step,
|
||||||
|
total: response.data.total,
|
||||||
data: response.data.data,
|
data: response.data.data,
|
||||||
partial_data: !response.data.data ? response.data.partial_data : undefined,
|
partial_data: !response.data.data
|
||||||
|
? response.data.partial_data
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -171,6 +177,10 @@ export default class FirecrawlApp {
|
|||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
status: "unknown",
|
status: "unknown",
|
||||||
|
current: 0,
|
||||||
|
current_url: "",
|
||||||
|
current_step: "",
|
||||||
|
total: 0,
|
||||||
error: "Internal server error.",
|
error: "Internal server error.",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -180,7 +190,7 @@ export default class FirecrawlApp {
|
|||||||
* @returns {AxiosRequestHeaders} The prepared headers.
|
* @returns {AxiosRequestHeaders} The prepared headers.
|
||||||
*/
|
*/
|
||||||
prepareHeaders(idempotencyKey) {
|
prepareHeaders(idempotencyKey) {
|
||||||
return Object.assign({ 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}` }, (idempotencyKey ? { 'x-idempotency-key': idempotencyKey } : {}));
|
return Object.assign({ "Content-Type": "application/json", Authorization: `Bearer ${this.apiKey}` }, (idempotencyKey ? { "x-idempotency-key": idempotencyKey } : {}));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Sends a POST request to the specified URL.
|
* Sends a POST request to the specified URL.
|
||||||
|
4
apps/js-sdk/firecrawl/package-lock.json
generated
4
apps/js-sdk/firecrawl/package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@mendable/firecrawl-js",
|
"name": "@mendable/firecrawl-js",
|
||||||
"version": "0.0.28",
|
"version": "0.0.29",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@mendable/firecrawl-js",
|
"name": "@mendable/firecrawl-js",
|
||||||
"version": "0.0.28",
|
"version": "0.0.29",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.8",
|
"axios": "^1.6.8",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mendable/firecrawl-js",
|
"name": "@mendable/firecrawl-js",
|
||||||
"version": "0.0.28",
|
"version": "0.0.29",
|
||||||
"description": "JavaScript SDK for Firecrawl API",
|
"description": "JavaScript SDK for Firecrawl API",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"types": "types/index.d.ts",
|
"types": "types/index.d.ts",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import FirecrawlApp from '../../index';
|
import FirecrawlApp from '../../index';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import { describe, test, expect } from '@jest/globals';
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ const TEST_API_KEY = process.env.TEST_API_KEY;
|
|||||||
const API_URL = "http://127.0.0.1:3002";
|
const API_URL = "http://127.0.0.1:3002";
|
||||||
|
|
||||||
describe('FirecrawlApp E2E Tests', () => {
|
describe('FirecrawlApp E2E Tests', () => {
|
||||||
test.concurrent('should throw error for no API key', () => {
|
test.concurrent('should throw error for no API key', async () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new FirecrawlApp({ apiKey: null, apiUrl: API_URL });
|
new FirecrawlApp({ apiKey: null, apiUrl: API_URL });
|
||||||
}).toThrow("No API key provided");
|
}).toThrow("No API key provided");
|
||||||
@ -107,12 +107,16 @@ describe('FirecrawlApp E2E Tests', () => {
|
|||||||
while (statusResponse.status === 'active' && checks < maxChecks) {
|
while (statusResponse.status === 'active' && checks < maxChecks) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
expect(statusResponse.partial_data).not.toBeNull();
|
expect(statusResponse.partial_data).not.toBeNull();
|
||||||
|
expect(statusResponse.current).toBeGreaterThanOrEqual(1);
|
||||||
statusResponse = await app.checkCrawlStatus(response.jobId);
|
statusResponse = await app.checkCrawlStatus(response.jobId);
|
||||||
checks++;
|
checks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(statusResponse).not.toBeNull();
|
expect(statusResponse).not.toBeNull();
|
||||||
|
expect(statusResponse.success).toBe(true);
|
||||||
expect(statusResponse.status).toBe('completed');
|
expect(statusResponse.status).toBe('completed');
|
||||||
|
expect(statusResponse.total).toEqual(statusResponse.current);
|
||||||
|
expect(statusResponse.current_step).not.toBeNull();
|
||||||
expect(statusResponse?.data?.length).toBeGreaterThan(0);
|
expect(statusResponse?.data?.length).toBeGreaterThan(0);
|
||||||
}, 35000); // 35 seconds timeout
|
}, 35000); // 35 seconds timeout
|
||||||
|
|
||||||
|
@ -100,6 +100,10 @@ export interface CrawlResponse {
|
|||||||
export interface JobStatusResponse {
|
export interface JobStatusResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
status: string;
|
status: string;
|
||||||
|
current?: number;
|
||||||
|
current_url?: string;
|
||||||
|
current_step?: string;
|
||||||
|
total?: number;
|
||||||
jobId?: string;
|
jobId?: string;
|
||||||
data?: FirecrawlDocument[];
|
data?: FirecrawlDocument[];
|
||||||
partial_data?: FirecrawlDocument[];
|
partial_data?: FirecrawlDocument[];
|
||||||
@ -287,6 +291,10 @@ export default class FirecrawlApp {
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
status: response.data.status,
|
status: response.data.status,
|
||||||
|
current: response.data.current,
|
||||||
|
current_url: response.data.current_url,
|
||||||
|
current_step: response.data.current_step,
|
||||||
|
total: response.data.total,
|
||||||
data: response.data.data,
|
data: response.data.data,
|
||||||
partial_data: !response.data.data
|
partial_data: !response.data.data
|
||||||
? response.data.partial_data
|
? response.data.partial_data
|
||||||
@ -301,6 +309,10 @@ export default class FirecrawlApp {
|
|||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
status: "unknown",
|
status: "unknown",
|
||||||
|
current: 0,
|
||||||
|
current_url: "",
|
||||||
|
current_step: "",
|
||||||
|
total: 0,
|
||||||
error: "Internal server error.",
|
error: "Internal server error.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user