@@ -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 * Search and extract information from multiple web sources using AI.
@@ -13,10 +15,23 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
1315 * Credit calculation: 30 base + 10 per additional website beyond 3.
1416 * @param {Object } [schema] - Optional schema object defining the output structure
1517 * @param {String } userAgent - the user agent like "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
18+ * @param {Object } options - Optional configuration options
19+ * @param {boolean } options.mock - Override mock mode for this request
1620 * @returns {Promise<string> } Extracted data in JSON format matching the provided schema
1721 * @throws - Will throw an error in case of an HTTP failure.
1822 */
19- export async function searchScraper ( apiKey , prompt , numResults = 3 , schema = null , userAgent = null ) {
23+ export async function searchScraper ( apiKey , prompt , numResults = 3 , schema = null , userAgent = null , options = { } ) {
24+ const { mock = null } = options ;
25+
26+ // Check if mock mode is enabled
27+ const useMock = mock !== null ? mock : isMockEnabled ( ) ;
28+
29+ if ( useMock ) {
30+ console . log ( '🧪 Mock mode active. Returning stub for searchScraper request' ) ;
31+ const mockConfig = getMockConfig ( ) ;
32+ const mockData = getMockResponse ( 'POST' , 'https://api.scrapegraphai.com/v1/searchscraper' , mockConfig . customResponses , mockConfig . customHandler ) ;
33+ return mockData ;
34+ }
2035 const endpoint = 'https://api.scrapegraphai.com/v1/searchscraper' ;
2136 const headers = {
2237 'accept' : 'application/json' ,
@@ -92,7 +107,19 @@ export async function searchScraper(apiKey, prompt, numResults = 3, schema = nul
92107 * information based on the original search query. The results are structured according to
93108 * the schema provided in the original searchScraper call, if any.
94109 */
95- export async function getSearchScraperRequest ( apiKey , requestId ) {
110+ export async function getSearchScraperRequest ( apiKey , requestId , options = { } ) {
111+ const { mock = null } = options ;
112+
113+ // Check if mock mode is enabled
114+ const useMock = mock !== null ? mock : isMockEnabled ( ) ;
115+
116+ if ( useMock ) {
117+ console . log ( '🧪 Mock mode active. Returning stub for getSearchScraperRequest' ) ;
118+ const mockConfig = getMockConfig ( ) ;
119+ const mockData = getMockResponse ( 'GET' , `https://api.scrapegraphai.com/v1/searchscraper/${ requestId } ` , mockConfig . customResponses , mockConfig . customHandler ) ;
120+ return mockData ;
121+ }
122+
96123 const endpoint = 'https://api.scrapegraphai.com/v1/searchscraper/' + requestId ;
97124 const headers = {
98125 'accept' : 'application/json' ,
0 commit comments