TypeScript SDK
Zero-dependency TypeScript client with typed methods, auto-retry on rate limits, and error handling.
Installation
npm install @liquichart/sdk
Usage
import { LiquiChart } from '@liquichart/sdk';
const lc = new LiquiChart({
apiKey: process.env.LIQUICHART_API_KEY!,
// baseUrl: 'https://www.liquichart.com' (default)
});
// Charts
const { data: chart } = await lc.charts.get('abc12345');
const { data: charts } = await lc.charts.list({ limit: 20, status: 'published' });
await lc.charts.create({ title: 'Revenue', chartType: 'line', manualData: [...] });
await lc.charts.publish('abc12345');
// Polls
const { data: poll } = await lc.polls.get('xyz98765');
await lc.polls.create({ title: 'Survey', questions: [{ text: '...', options: ['A', 'B'] }] });
await lc.polls.close('xyz98765');
// Living Content (self-updating)
const { data: block } = await lc.livingContent.get('my-block');
// block.content auto-updates when underlying data changes
// Webhooks
await lc.webhooks.create({
url: 'https://example.com/hook',
events: ['chart.published', 'poll.vote.received'],
});Error Handling
import {
LiquiChartNotFoundError,
LiquiChartRateLimitError,
LiquiChartAuthError,
} from '@liquichart/sdk';
try {
const { data } = await lc.charts.get('nonexistent');
} catch (err) {
if (err instanceof LiquiChartNotFoundError) {
// Chart doesn't exist
}
if (err instanceof LiquiChartRateLimitError) {
// Auto-retried twice already; err.retryAfter has seconds
}
if (err instanceof LiquiChartAuthError) {
// Invalid API key
}
}The SDK automatically retries on 429 (rate limit) up to 2 times with Retry-After backoff.
TypeScript Support
Full type definitions included. Every method returns typed responses:
import type { Chart, Poll, ChartDataPoint } from '@liquichart/sdk';
const { data: chart } = await lc.charts.get('abc12345');
// chart is typed as Chart — autocomplete works for:
// chart.title, chart.data, chart.config, chart.insight, chart._links, etc.