Skip to content

Commit 016ae8b

Browse files
VinciGit00claude
andcommitted
refactor(api): split fetch mode into mode + stealth toggle
Align JS SDK with sgai-stack PR #294: remove compound fetch modes (direct+stealth, js+stealth) and add separate stealth boolean field to fetchConfig. Modes are now auto|fast|js with stealth as an independent toggle. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d560d9a commit 016ae8b

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/schemas.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const apiFetchContentTypeSchema = z.enum([
2626
"text/plain",
2727
"application/x-latex",
2828
]);
29-
export const apiFetchModeSchema = z.enum(["auto", "fast", "js", "direct+stealth", "js+stealth"]);
29+
export const apiFetchModeSchema = z.enum(["auto", "fast", "js"]);
3030
export const apiUserPromptSchema = z.string().min(1).max(10_000);
3131

3232
export const apiUrlSchema = z.url().check(
@@ -52,13 +52,15 @@ export const apiUuidParamSchema = z.object({
5252

5353
export const FETCH_CONFIG_DEFAULTS = {
5454
mode: "auto",
55+
stealth: false,
5556
timeout: 30000,
5657
wait: 0,
5758
scrolls: 0,
5859
} as const;
5960

6061
export const apiFetchConfigSchema = z.object({
6162
mode: apiFetchModeSchema.default(FETCH_CONFIG_DEFAULTS.mode),
63+
stealth: z.boolean().default(FETCH_CONFIG_DEFAULTS.stealth),
6264
timeout: z.number().int().min(1000).max(60000).default(FETCH_CONFIG_DEFAULTS.timeout),
6365
wait: z.number().int().min(0).max(30000).default(FETCH_CONFIG_DEFAULTS.wait),
6466
headers: z.record(z.string(), z.string()).optional(),

tests/client.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ describe("scrapegraphai", () => {
8383
api.stop();
8484
});
8585

86+
test("scrape sends stealth and mode in fetchConfig", async () => {
87+
let body: any;
88+
const api = mockApi({
89+
"/api/v2/scrape": async (req) => {
90+
body = await req.json();
91+
return Response.json(
92+
{ results: { markdown: "# Hello" }, metadata: { url: "https://example.com" } },
93+
{ headers: { "x-request-id": "req-stealth" } },
94+
);
95+
},
96+
});
97+
const sgai = scrapegraphai({ apiKey: "test", baseUrl: api.url });
98+
await sgai.scrape("https://example.com", {
99+
fetchConfig: { mode: "fast", stealth: true, country: "us" },
100+
});
101+
expect(body.fetchConfig).toEqual({ mode: "fast", stealth: true, country: "us" });
102+
api.stop();
103+
});
104+
86105
test("extract sends prompt, schema, and fetchConfig", async () => {
87106
let body: any;
88107
const api = mockApi({

0 commit comments

Comments
 (0)