@corralimited/snapdiff
v0.3.1
Published
Typed TypeScript client for the SnapDiff REST API. Visual diffs, screenshots, project baselines. Generated from the official OpenAPI spec — every method is fully typed end-to-end.
Maintainers
Readme
@corralimited/snapdiff
Typed TypeScript client for the SnapDiff REST API. Visual diffs, screenshots, project baselines.
npm install @corralimited/snapdiffQuickstart
import { Snapdiff } from '@corralimited/snapdiff';
const sd = new Snapdiff({ apiKey: process.env.SNAPDIFF_API_KEY! });
// Ad-hoc visual diff between two URLs
const result = await sd.diff({
before: 'https://example.com',
after: 'https://staging.example.com',
});
console.log(`${result.diff_percentage}% changed`);
console.log(result.diff_image_url);
// Compare against a stored project baseline
const baseline = await sd.diffBaseline({
project: 'acme-marketing',
page_name: 'pricing',
after: 'https://staging.acme.com/pricing',
});
// Single screenshot
const shot = await sd.screenshot({ url: 'https://example.com', full_page: true });
// Project management
const projects = await sd.projects.list();
const project = await sd.projects.get('prj_xxx');Errors
Non-2xx responses throw SnapdiffError:
import { Snapdiff, SnapdiffError } from '@corralimited/snapdiff';
try {
await sd.diffBaseline({ project: 'unknown', page_name: 'home', after: '...' });
} catch (err) {
if (err instanceof SnapdiffError) {
console.error(err.status, err.message); // 404 'Project "unknown" not found'
}
}Escape hatch
For operations without an ergonomic helper, every endpoint is reachable through the typed
openapi-fetch client:
const { data, error } = await sd.client.POST(
'/projects/{projectId}/builds/{buildId}/approve',
{ params: { path: { projectId: 'prj_xxx', buildId: 'bld_xxx' } } },
);Path, query, body, and response types are all inferred from the OpenAPI spec.
Configuration
| Option | Default | Notes |
|---|---|---|
| apiKey | — | Required. Get one at https://snapdiff.ai/dashboard |
| baseUrl | https://api.snapdiff.ai/v1 | Override for self-hosted or testing. |
| fetch | globalThis.fetch | Inject a custom fetch (Node 18+, undici, polyfill). |
License
MIT — see LICENSE.
