@@ -2,6 +2,8 @@ import axios from 'axios';
22import handleError from './utils/handleError.js' ;
33import { ZodType } from 'zod' ;
44import { zodToJsonSchema } from 'zod-to-json-schema' ;
5+ import { isMockEnabled , getMockConfig } from './utils/mockConfig.js' ;
6+ import { getMockResponse } from './utils/mockResponse.js' ;
57
68/**
79 * Start a crawl job using the ScrapeGraphAI API.
@@ -18,6 +20,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
1820 * @param {boolean } [options.sameDomainOnly=true] - Whether to only crawl pages from the same domain
1921 * @param {boolean } [options.sitemap] - Whether to use sitemap for better page discovery
2022 * @param {number } [options.batchSize=1] - Batch size for processing pages (1-10)
23+ * @param {boolean } [options.mock] - Override mock mode for this request
2124 * @returns {Promise<Object> } The crawl job response
2225 * @throws {Error } Throws an error if the HTTP request fails
2326 */
@@ -28,6 +31,17 @@ export async function crawl(
2831 schema ,
2932 options = { }
3033) {
34+ const { mock = null } = options ;
35+
36+ // Check if mock mode is enabled
37+ const useMock = mock !== null ? mock : isMockEnabled ( ) ;
38+
39+ if ( useMock ) {
40+ console . log ( '🧪 Mock mode active. Returning stub for crawl request' ) ;
41+ const mockConfig = getMockConfig ( ) ;
42+ const mockData = getMockResponse ( 'POST' , 'https://api.scrapegraphai.com/v1/crawl' , mockConfig . customResponses , mockConfig . customHandler ) ;
43+ return mockData ;
44+ }
3145 const endpoint = 'https://api.scrapegraphai.com/v1/crawl' ;
3246 const headers = {
3347 'accept' : 'application/json' ,
@@ -81,7 +95,19 @@ export async function crawl(
8195 * @returns {Promise<Object> } The crawl result
8296 * @throws {Error } Throws an error if the HTTP request fails
8397 */
84- export async function getCrawlRequest ( apiKey , crawlId ) {
98+ export async function getCrawlRequest ( apiKey , crawlId , options = { } ) {
99+ const { mock = null } = options ;
100+
101+ // Check if mock mode is enabled
102+ const useMock = mock !== null ? mock : isMockEnabled ( ) ;
103+
104+ if ( useMock ) {
105+ console . log ( '🧪 Mock mode active. Returning stub for getCrawlRequest' ) ;
106+ const mockConfig = getMockConfig ( ) ;
107+ const mockData = getMockResponse ( 'GET' , `https://api.scrapegraphai.com/v1/crawl/${ crawlId } ` , mockConfig . customResponses , mockConfig . customHandler ) ;
108+ return mockData ;
109+ }
110+
85111 const endpoint = `https://api.scrapegraphai.com/v1/crawl/${ crawlId } ` ;
86112 const headers = {
87113 'accept' : 'application/json' ,
0 commit comments