Skip to content

Commit 13578aa

Browse files
refactor: rename getHistory/getHistoryEntry to history.list/history.get
Follow namespace pattern consistent with crawl.* and monitor.* Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8f44af9 commit 13578aa

5 files changed

Lines changed: 51 additions & 43 deletions

File tree

CLAUDE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Claude Code Instructions
2+
3+
## Before completing any task
4+
5+
Always run these commands before committing or saying a task is done:
6+
7+
```bash
8+
bun run format
9+
bun run lint
10+
bunx tsc --noEmit
11+
bun run build
12+
bun test
13+
```
14+
15+
No exceptions.

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ export {
55
generateSchema,
66
getCredits,
77
checkHealth,
8-
getHistory,
9-
getHistoryEntry,
8+
history,
109
crawl,
1110
monitor,
1211
} from "./scrapegraphai.js";

src/scrapegraphai.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -186,35 +186,31 @@ export async function checkHealth(apiKey: string): Promise<ApiResult<ApiHealthRe
186186
}
187187
}
188188

189-
export async function getHistory(
190-
apiKey: string,
191-
params?: ApiHistoryFilter,
192-
): Promise<ApiResult<ApiHistoryPage>> {
193-
try {
194-
const qs = new URLSearchParams();
195-
if (params?.page) qs.set("page", String(params.page));
196-
if (params?.limit) qs.set("limit", String(params.limit));
197-
if (params?.service) qs.set("service", params.service);
198-
const query = qs.toString();
199-
const path = query ? `/history?${query}` : "/history";
200-
const { data, elapsedMs } = await request<ApiHistoryPage>("GET", path, apiKey);
201-
return ok(data, elapsedMs);
202-
} catch (err) {
203-
return fail(err);
204-
}
205-
}
189+
export const history = {
190+
async list(apiKey: string, params?: ApiHistoryFilter): Promise<ApiResult<ApiHistoryPage>> {
191+
try {
192+
const qs = new URLSearchParams();
193+
if (params?.page) qs.set("page", String(params.page));
194+
if (params?.limit) qs.set("limit", String(params.limit));
195+
if (params?.service) qs.set("service", params.service);
196+
const query = qs.toString();
197+
const path = query ? `/history?${query}` : "/history";
198+
const { data, elapsedMs } = await request<ApiHistoryPage>("GET", path, apiKey);
199+
return ok(data, elapsedMs);
200+
} catch (err) {
201+
return fail(err);
202+
}
203+
},
206204

207-
export async function getHistoryEntry(
208-
apiKey: string,
209-
id: string,
210-
): Promise<ApiResult<ApiHistoryEntry>> {
211-
try {
212-
const { data, elapsedMs } = await request<ApiHistoryEntry>("GET", `/history/${id}`, apiKey);
213-
return ok(data, elapsedMs);
214-
} catch (err) {
215-
return fail(err);
216-
}
217-
}
205+
async get(apiKey: string, id: string): Promise<ApiResult<ApiHistoryEntry>> {
206+
try {
207+
const { data, elapsedMs } = await request<ApiHistoryEntry>("GET", `/history/${id}`, apiKey);
208+
return ok(data, elapsedMs);
209+
} catch (err) {
210+
return fail(err);
211+
}
212+
},
213+
};
218214

219215
export const crawl = {
220216
async start(apiKey: string, params: ApiCrawlRequest): Promise<ApiResult<ApiCrawlResponse>> {

tests/integration.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test } from "bun:test";
2-
import { crawl, extract, getCredits, getHistory, scrape, search } from "../src/index.js";
2+
import { crawl, extract, getCredits, history, scrape, search } from "../src/index.js";
33

44
const API_KEY = process.env.SGAI_API_KEY || "sgai-669918e5-55be-4752-a684-f6da788d1384";
55

@@ -73,9 +73,9 @@ describe("integration", () => {
7373
expect(res.data?.results.length).toBeGreaterThan(0);
7474
});
7575

76-
test("getHistory", async () => {
77-
const res = await getHistory(API_KEY, { limit: 5 });
78-
console.log("getHistory:", res.status, res.data?.pagination);
76+
test("history.list", async () => {
77+
const res = await history.list(API_KEY, { limit: 5 });
78+
console.log("history.list:", res.status, res.data?.pagination);
7979
expect(res.status).toBe("success");
8080
});
8181

tests/scrapegraphai.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -765,40 +765,38 @@ describe("checkHealth", () => {
765765
});
766766
});
767767

768-
describe("getHistory", () => {
769-
test("success without params", async () => {
768+
describe("history", () => {
769+
test("list success without params", async () => {
770770
const body = {
771771
data: [],
772772
pagination: { page: 1, limit: 20, total: 0 },
773773
};
774774
fetchSpy = spyOn(globalThis, "fetch").mockResolvedValueOnce(json(body));
775775

776-
const res = await sdk.getHistory(API_KEY);
776+
const res = await sdk.history.list(API_KEY);
777777

778778
expect(res.status).toBe("success");
779779
expect(res.data).toEqual(body);
780780
expectRequest(0, "GET", "/history");
781781
});
782782

783-
test("success with params", async () => {
783+
test("list success with params", async () => {
784784
const body = {
785785
data: [],
786786
pagination: { page: 2, limit: 10, total: 50 },
787787
};
788788
fetchSpy = spyOn(globalThis, "fetch").mockResolvedValueOnce(json(body));
789789

790-
const res = await sdk.getHistory(API_KEY, { page: 2, limit: 10, service: "scrape" });
790+
const res = await sdk.history.list(API_KEY, { page: 2, limit: 10, service: "scrape" });
791791

792792
expect(res.status).toBe("success");
793793
const [url] = fetchSpy.mock.calls[0] as [string, RequestInit];
794794
expect(url).toContain("page=2");
795795
expect(url).toContain("limit=10");
796796
expect(url).toContain("service=scrape");
797797
});
798-
});
799798

800-
describe("getHistoryEntry", () => {
801-
test("success", async () => {
799+
test("get success", async () => {
802800
const body = {
803801
id: "abc-123",
804802
service: "scrape",
@@ -808,7 +806,7 @@ describe("getHistoryEntry", () => {
808806
};
809807
fetchSpy = spyOn(globalThis, "fetch").mockResolvedValueOnce(json(body));
810808

811-
const res = await sdk.getHistoryEntry(API_KEY, "abc-123");
809+
const res = await sdk.history.get(API_KEY, "abc-123");
812810

813811
expect(res.status).toBe("success");
814812
expect(res.data).toEqual(body);

0 commit comments

Comments
 (0)