Skip to content

Commit e830a1a

Browse files
feat: replace internal API layer with scrapegraph-js SDK
Remove zod, schemas, types, and the hand-rolled API client in favor of the official scrapegraph-js SDK. All commands now import directly from the package. env.ts bridges JUST_SCRAPE_* vars to SGAI_* so the SDK picks up CLI-specific config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dd567e5 commit e830a1a

21 files changed

Lines changed: 55 additions & 1003 deletions

README.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ just-scrape/
2424
├── src/
2525
│ ├── cli.ts # Entry point, citty main command + subcommands
2626
│ ├── lib/
27-
│ │ ├── env.ts # Zod-parsed env config (API key, debug, timeout)
27+
│ │ ├── env.ts # Env config (API key, JUST_SCRAPE_* → SGAI_* bridge)
2828
│ │ ├── folders.ts # API key resolution + interactive prompt
29-
│ │ ├── scrapegraphai.ts # SDK layer — all API functions (typed responses)
30-
│ │ ├── schemas.ts # Zod validation schemas
3129
│ │ └── log.ts # Logger factory + syntax-highlighted JSON output
32-
│ ├── types/
33-
│ │ └── index.ts # Zod-derived types + ApiResult + response types
3430
│ ├── commands/
3531
│ │ ├── smart-scraper.ts
3632
│ │ ├── search-scraper.ts
@@ -45,8 +41,6 @@ just-scrape/
4541
│ │ └── validate.ts
4642
│ └── utils/
4743
│ └── banner.ts # ASCII banner + version from package.json
48-
├── tests/
49-
│ └── scrapegraphai.test.ts # SDK layer tests (mocked fetch)
5044
├── dist/ # Build output (git-ignored)
5145
│ └── cli.mjs # Bundled ESM with shebang
5246
├── package.json
@@ -396,10 +390,9 @@ bun run dev --help
396390
| CLI Framework | **citty** (unjs) |
397391
| Prompts | **@clack/prompts** |
398392
| Styling | **chalk** v5 (ESM) |
399-
| Validation | **zod** v4 |
393+
| SDK | **scrapegraph-js** |
400394
| Env | **dotenv** |
401395
| Lint / Format | **Biome** |
402-
| Testing | **Bun test** (built-in) |
403396
| Target | **Node.js 22+**, ESM-only |
404397

405398
### Scripts
@@ -409,16 +402,9 @@ bun run dev # Run CLI from TS source
409402
bun run build # Bundle ESM to dist/cli.mjs
410403
bun run lint # Lint + format check
411404
bun run format # Auto-format
412-
bun test # Run tests
413405
bun run check # Type-check + lint
414406
```
415407

416-
### Testing
417-
418-
Tests mock all API calls via `spyOn(globalThis, "fetch")` — no network, no API key needed.
419-
420-
Covers: success paths, polling, HTTP error mapping (401/402/422/429/500), Zod validation, timeouts, and network failures.
421-
422408
## License
423409

424410
ISC

bun.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"chalk": "^5.4.1",
2929
"citty": "^0.1.6",
3030
"dotenv": "^17.2.4",
31-
"zod": "^4.3.6"
31+
"scrapegraph-js": "^1.0.0"
3232
},
3333
"devDependencies": {
3434
"@biomejs/biome": "^1.9.4",

src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "dotenv/config";
2+
import "./lib/env.js";
23
import { defineCommand, runMain } from "citty";
34
import { getVersion, showBanner } from "./utils/banner.js";
45

src/commands/agentic-scraper.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineCommand } from "citty";
2+
import * as scrapegraphai from "scrapegraph-js";
23
import { resolveApiKey } from "../lib/folders.js";
34
import * as log from "../lib/log.js";
4-
import * as scrapegraphai from "../lib/scrapegraphai.js";
55

66
export default defineCommand({
77
meta: {
@@ -34,9 +34,8 @@ export default defineCommand({
3434
out.docs("https://docs.scrapegraphai.com/services/agenticscraper");
3535
const key = await resolveApiKey(!!args.json);
3636

37-
const params: scrapegraphai.AgenticScraperParams = { url: args.url };
38-
39-
if (args.steps) params.steps = args.steps.split(",").map((s) => s.trim());
37+
const steps = args.steps ? args.steps.split(",").map((s) => s.trim()) : [];
38+
const params: scrapegraphai.AgenticScraperParams = { url: args.url, steps };
4039
if (args.prompt) params.user_prompt = args.prompt;
4140
if (args.schema) params.output_schema = JSON.parse(args.schema);
4241
if (args["ai-extraction"]) params.ai_extraction = true;

src/commands/crawl.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineCommand } from "citty";
2+
import * as scrapegraphai from "scrapegraph-js";
23
import { resolveApiKey } from "../lib/folders.js";
34
import * as log from "../lib/log.js";
4-
import * as scrapegraphai from "../lib/scrapegraphai.js";
55

66
export default defineCommand({
77
meta: {
@@ -36,16 +36,21 @@ export default defineCommand({
3636
out.docs("https://docs.scrapegraphai.com/services/smartcrawler");
3737
const key = await resolveApiKey(!!args.json);
3838

39-
const params: scrapegraphai.CrawlParams = { url: args.url };
39+
const base: Record<string, unknown> = { url: args.url };
40+
if (args["max-pages"]) base.max_pages = Number(args["max-pages"]);
41+
if (args.depth) base.depth = Number(args.depth);
42+
if (args.rules) base.rules = JSON.parse(args.rules);
43+
if (args["no-sitemap"]) base.sitemap = false;
44+
if (args.stealth) base.stealth = true;
4045

41-
if (args.prompt) params.prompt = args.prompt;
42-
if (args["no-extraction"]) params.extraction_mode = false;
43-
if (args["max-pages"]) params.max_pages = Number(args["max-pages"]);
44-
if (args.depth) params.depth = Number(args.depth);
45-
if (args.schema) params.schema = JSON.parse(args.schema);
46-
if (args.rules) params.rules = JSON.parse(args.rules);
47-
if (args["no-sitemap"]) params.sitemap = false;
48-
if (args.stealth) params.stealth = true;
46+
if (args["no-extraction"]) {
47+
base.extraction_mode = false;
48+
} else {
49+
if (args.prompt) base.prompt = args.prompt;
50+
if (args.schema) base.schema = JSON.parse(args.schema);
51+
}
52+
53+
const params = base as scrapegraphai.CrawlParams;
4954

5055
out.start("Crawling");
5156
const result = await scrapegraphai.crawl(key, params, out.poll);

src/commands/credits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineCommand } from "citty";
2+
import * as scrapegraphai from "scrapegraph-js";
23
import { resolveApiKey } from "../lib/folders.js";
34
import * as log from "../lib/log.js";
4-
import * as scrapegraphai from "../lib/scrapegraphai.js";
55

66
export default defineCommand({
77
meta: {

src/commands/generate-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineCommand } from "citty";
2+
import * as scrapegraphai from "scrapegraph-js";
23
import { resolveApiKey } from "../lib/folders.js";
34
import * as log from "../lib/log.js";
4-
import * as scrapegraphai from "../lib/scrapegraphai.js";
55

66
export default defineCommand({
77
meta: {

src/commands/history.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as p from "@clack/prompts";
22
import chalk from "chalk";
33
import { defineCommand } from "citty";
4+
import { HISTORY_SERVICES } from "scrapegraph-js";
5+
import * as scrapegraphai from "scrapegraph-js";
46
import { resolveApiKey } from "../lib/folders.js";
57
import * as log from "../lib/log.js";
6-
import { HISTORY_SERVICES } from "../lib/schemas.js";
7-
import * as scrapegraphai from "../lib/scrapegraphai.js";
88

99
const VALID = HISTORY_SERVICES.join(", ");
1010
const LOAD_MORE = "__load_more__";

src/commands/markdownify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineCommand } from "citty";
2+
import * as scrapegraphai from "scrapegraph-js";
23
import { resolveApiKey } from "../lib/folders.js";
34
import * as log from "../lib/log.js";
4-
import * as scrapegraphai from "../lib/scrapegraphai.js";
55

66
export default defineCommand({
77
meta: {

0 commit comments

Comments
 (0)