Skip to content

Commit fdbfc39

Browse files
authored
Merge pull request #11 from ScrapeGraphAI/feat/typed-api-responses
feat: migrate to scrapegraph-js SDK
2 parents dc3eb79 + 433ee74 commit fdbfc39

21 files changed

+57
-1004
lines changed

README.md

Lines changed: 3 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
@@ -64,6 +58,7 @@ pnpm add -g just-scrape # pnpm
6458
yarn global add just-scrape # yarn
6559
bun add -g just-scrape # bun
6660
npx just-scrape --help # or run without installing
61+
bunx just-scrape --help # bun equivalent
6762
```
6863

6964
Package: [just-scrape](https://www.npmjs.com/package/just-scrape) on npm.
@@ -397,10 +392,9 @@ bun run dev --help
397392
| CLI Framework | **citty** (unjs) |
398393
| Prompts | **@clack/prompts** |
399394
| Styling | **chalk** v5 (ESM) |
400-
| Validation | **zod** v4 |
395+
| SDK | **scrapegraph-js** |
401396
| Env | **dotenv** |
402397
| Lint / Format | **Biome** |
403-
| Testing | **Bun test** (built-in) |
404398
| Target | **Node.js 22+**, ESM-only |
405399

406400
### Scripts
@@ -410,16 +404,9 @@ bun run dev # Run CLI from TS source
410404
bun run build # Bundle ESM to dist/cli.mjs
411405
bun run lint # Lint + format check
412406
bun run format # Auto-format
413-
bun test # Run tests
414407
bun run check # Type-check + lint
415408
```
416409

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

425412
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "just-scrape",
3-
"version": "0.1.9",
3+
"version": "0.2.0",
44
"description": "ScrapeGraph AI CLI tool",
55
"type": "module",
66
"main": "dist/cli.mjs",
@@ -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)