Conversation
src/client.ts
Outdated
| import { DEFAULT_BASE_URL } from "./types/index.js"; | ||
| import { toJsonSchema } from "./zod.js"; | ||
|
|
||
| /** Create a ScrapeGraphAI client. All methods return `{ data, _requestId }`. */ |
There was a problem hiding this comment.
Why requestId private?
There was a problem hiding this comment.
Changed this to requestId and updated the docs/tests to match. The response shape is now { data, requestId }.
src/client.ts
Outdated
|
|
||
| return { | ||
| async scrape( | ||
| targetUrl: string, |
There was a problem hiding this comment.
TatgetUrl? Java shit -> url you have the zod api schemas from the main repo; match them 100%
There was a problem hiding this comment.
Renamed targetUrl to url. I also copied the shared contract layer from sgai-stack into src/schemas.ts / src/models.ts / src/url.ts so the request types are derived from the same schema source.
src/client.ts
Outdated
| return { | ||
| async scrape( | ||
| targetUrl: string, | ||
| options?: { format?: string; fetchConfig?: Record<string, unknown> }, |
There was a problem hiding this comment.
This is forbitten; inline types are shit. Match the ones in the main repo. @lorenzo have u prompt it to use the types of the main repo?
There was a problem hiding this comment.
Removed the inline method types. src/types/index.ts now uses named types inferred from the copied shared schemas from sgai-stack instead of ad hoc shapes in client.ts.
src/client.ts
Outdated
| }, | ||
|
|
||
| async extract( | ||
| targetUrl: string, |
There was a problem hiding this comment.
Same shit and wtf is ro???
There was a problem hiding this comment.
Renamed ro to requestOptions throughout client.ts.
src/client.ts
Outdated
| async extract( | ||
| targetUrl: string, | ||
| options: { prompt: string; schema?: unknown; llmConfig?: Record<string, unknown> }, | ||
| ro?: RequestOptions, |
There was a problem hiding this comment.
You have options and requestOption? What in tjis world is thir garbage. USE THE TYPES FROM SGAI STACK
There was a problem hiding this comment.
Updated this to use named types from the copied sgai-stack contract layer. src/schemas.ts / src/models.ts / src/url.ts are now ported over, and src/types/index.ts infers the request types from those schemas. The only SDK-specific adaptation left is keeping extract.schema widened at the SDK boundary so Zod input can still flow through toJsonSchema.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Align the CLI with ScrapeGraphAI/scrapegraph-js#11 (v2 SDK migration): - Rename smart-scraper → extract, search-scraper → search - Remove commands dropped from the API: agentic-scraper, generate-schema, sitemap, validate - Add client factory (src/lib/client.ts) using the new scrapegraphai({ apiKey }) pattern - Update scrape command with --format flag (markdown, html, screenshot, branding) - Update crawl to use crawl.start/status polling lifecycle - Update history to use v2 service names and parameters - All commands now use try/catch (v2 throws on error) and self-timed elapsed BREAKING CHANGE: CLI commands have been renamed and removed to match the v2 API surface. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
sgai-stackfeat/sdk-v2scrapegraphai(config)factory/api/v2/*endpoints and addcrawl/monitornamespacesBreaking Changes
smartScraper,searchScraper,markdownify,agenticScraper,sitemap,generateSchema,getCredits,checkHealthare removed from the public APIscrapegraphai({ apiKey, ...config })crawlandmonitorare now namespaced methods on the client (crawl.start,crawl.status,crawl.stop,monitor.create,monitor.delete, etc.)/api/v2surfaceUnit Tests
14 tests run with
bun testagainst local mock HTTP servers (no real API calls).tests/http.test.ts— request layer{ data, requestId }Authorization,SGAI-APIKEY, andX-SDK-Versionheaderstests/client.test.ts— client methodsscrape()returns markdown + requestIdextract()sends prompt + schema in bodysearch()sends query in bodycredits()returns balancecrawl.start()returns job idcrawl.status()returns statuscrawl.stop()sends POSTmonitor.create()sends bodymonitor.delete()sends DELETE methodhistory()appends query params (page, limit, service)Integration Tests (Dev Server)
22 tests total, 22 pass, 0 failures — tested against
https://sgai-api-dev-v2.onrender.com/api/v21. Scrape — 7/7 ✅
sgai.scrape("https://example.com")sgai.scrape("https://news.ycombinator.com")sgai.scrape(url, { format: "html" })sgai.scrape(url, { format: "screenshot" }){ fetchConfig: { mock: true } }{ fetchConfig: { stealth: true, wait: 500 } }sgai.scrape("https://en.wikipedia.org/wiki/Web_scraping")2. Extract — 5/5 ✅
sgai.extract(url, { prompt: "Extract title and description" }){ schema: { type: "object", properties: {...} } }{ fetchConfig: { mock: true } }{ llmConfig: { temperature: 0 } }3. Search — 4/4 ✅
sgai.search("what is web scraping")sgai.search("Python SDK", { numResults: 3 })sgai.search("ScrapeGraph AI", { numResults: 10 }){ llmConfig: { temperature: 0 } }4. History — 4/4 ✅
sgai.history()sgai.history({ limit: 5 })sgai.history({ service: "scrape", limit: 3 })sgai.history({ service: "extract", limit: 3 })5. Credits — 1/1 ✅
{"remaining": 249347, "used": 651, "plan": "Pro Plan"}6. Error Handling — 1/1 ✅
Invalid or deprecated API keySummary
scrape(markdown, html, screenshot, mock, stealth)extract(basic, schema, complex, fetchConfig, llmConfig)search(basic, numResults, llmConfig)history(no filters, limit, service filter)creditsValidation
🤖 Generated with Claude Code