@@ -2,6 +2,8 @@ import axios from 'axios';
2
2
import handleError from './utils/handleError.js' ;
3
3
import { ZodType } from 'zod' ;
4
4
import { zodToJsonSchema } from 'zod-to-json-schema' ;
5
+ import { isMockEnabled , getMockConfig } from './utils/mockConfig.js' ;
6
+ import { getMockResponse } from './utils/mockResponse.js' ;
5
7
6
8
/**
7
9
* Search and extract information from multiple web sources using AI.
@@ -13,10 +15,23 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
13
15
* Credit calculation: 30 base + 10 per additional website beyond 3.
14
16
* @param {Object } [schema] - Optional schema object defining the output structure
15
17
* @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
16
20
* @returns {Promise<string> } Extracted data in JSON format matching the provided schema
17
21
* @throws - Will throw an error in case of an HTTP failure.
18
22
*/
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
+ }
20
35
const endpoint = 'https://api.scrapegraphai.com/v1/searchscraper' ;
21
36
const headers = {
22
37
'accept' : 'application/json' ,
@@ -92,7 +107,19 @@ export async function searchScraper(apiKey, prompt, numResults = 3, schema = nul
92
107
* information based on the original search query. The results are structured according to
93
108
* the schema provided in the original searchScraper call, if any.
94
109
*/
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
+
96
123
const endpoint = 'https://api.scrapegraphai.com/v1/searchscraper/' + requestId ;
97
124
const headers = {
98
125
'accept' : 'application/json' ,
0 commit comments