Skip to content

Commit 6a3f1ef

Browse files
committed
fix: add screenshot get request
1 parent ab57ed0 commit 6a3f1ef

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const status = await client.waitForJob(job.job_id)
4949
// Screenshot job
5050
const sJob = await client.createScreenshotJob({ url: 'https://example.com', device: 'desktop', full_page: true })
5151

52+
// Wait and fetch a fresh signed URL (recommended)
53+
const signed = await client.waitForScreenshot(sJob.job_id)
54+
console.log('screenshot:', signed.screenshot)
55+
5256
// Watch create/pause/resume/check/delete
5357
const watch = await client.watchCreate({ url: 'https://example.com/pricing', frequency: 'daily', notify_email: '[email protected]' })
5458
await client.watchPause(watch.watch_id)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@supacrawler/js",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Typed TypeScript/JavaScript SDK for Supacrawler API (scrape, jobs, screenshots, watch)",
55
"type": "module",
66
"main": "dist/index.js",

src/client.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
JobStatusResponse,
77
ScreenshotRequest,
88
ScreenshotCreateResponse,
9+
ScreenshotGetResponse,
910
WatchCreateRequest,
1011
WatchCreateResponse,
1112
WatchGetResponse,
@@ -39,7 +40,9 @@ export class SupacrawlerClient {
3940

4041
constructor(options: ClientOptions) {
4142
this.apiKey = options.apiKey
42-
this.baseUrl = (options.baseUrl ?? 'https://api.supacrawler.com/api/v1').replace(/\/$/, '')
43+
// Allow passing engine root (e.g., http://localhost:8081/v1) or hosted API root
44+
const defaultBase = 'https://api.supacrawler.com/api/v1'
45+
this.baseUrl = (options.baseUrl ?? defaultBase).replace(/\/$/, '')
4346
this.fetchFn = options.fetchFn ?? fetch
4447
this.timeoutMs = options.timeoutMs ?? 30000
4548
}
@@ -118,6 +121,19 @@ export class SupacrawlerClient {
118121
})
119122
}
120123

124+
async getScreenshot(jobId: string): Promise<ScreenshotGetResponse> {
125+
const qs = new URLSearchParams({ job_id: jobId })
126+
return this.request<ScreenshotGetResponse>(`/screenshots?${qs.toString()}`, {
127+
headers: { Authorization: `Bearer ${this.apiKey}` },
128+
})
129+
}
130+
131+
async waitForScreenshot(jobId: string, opts: { intervalMs?: number; timeoutMs?: number } = {}): Promise<ScreenshotGetResponse> {
132+
const status = await this.waitForJob(jobId, opts)
133+
if (status.status !== 'completed') throw new SupacrawlerError(`Job ${jobId} did not complete`)
134+
return this.getScreenshot(jobId)
135+
}
136+
121137
// ------------- Watch -------------
122138
async watchCreate(req: WatchCreateRequest): Promise<WatchCreateResponse> {
123139
return this.request<WatchCreateResponse>(`/watch`, {

src/examples/screenshots.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ async function main() {
2525
console.log('Screenshot status:', status.status)
2626
if (status.status === 'completed' && status.data && 'screenshot' in status.data) {
2727
console.log('Screenshot URL:', (status.data as any).screenshot)
28+
// Example: Renew signed URL
29+
const renewed = await client.getScreenshot(job.job_id)
30+
console.log('Renewed screenshot URL:', renewed.screenshot)
2831
}
2932
}
3033

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ export interface ScreenshotCreateResponse {
143143
metadata?: ScreenshotMetadata
144144
}
145145

146+
export interface ScreenshotGetResponse {
147+
success: boolean
148+
job_id: string
149+
url: string
150+
screenshot: string
151+
metadata?: ScreenshotMetadata
152+
}
153+
146154
export type Frequency = 'hourly' | 'daily' | 'weekly' | 'monthly' | 'custom'
147155

148156
export interface WatchCreateRequest {

0 commit comments

Comments
 (0)