TypeScript SDK
Install @querydeck/sdk, a zero-dependency typed client for the QueryDeck REST API with automatic retries for rate limits and server errors.
@querydeck/sdk wraps the REST API with
types for every report. It has no dependencies and runs anywhere fetch
exists: Node.js 18+, Bun, Deno, and edge runtimes.
Install
npm install @querydeck/sdkCreate a client
import { QueryDeck } from '@querydeck/sdk'
const qd = new QueryDeck({ apiKey: process.env.QUERYDECK_KEY! })| Option | Default | |
|---|---|---|
apiKey | Required. An API key | |
baseUrl | https://api.querydeck.si | API origin; /v1/public is added for you |
maxRetries | 2 | Retries for 429, 5xx and network errors |
fetch | global fetch | Your own fetch, for tests or proxies |
Methods
properties.list()
const properties = await qd.properties.list()
// [{ id, siteUrl, ga4PropertyId }]performance.query()
Runs a Search Console report.
const { rows } = await qd.performance.query({
property: 'sc-domain:example.com',
report: 'top_performing_keywords',
days: 28,
})ga4.report()
Runs a GA4 report.
const { rows } = await qd.ga4.report({
property: 'sc-domain:example.com',
report: 'llm_referrals',
})Rows are Record<string, unknown> by default. Pass your own row type for
stronger typing:
type KeywordRow = { phrase: string; clicks: number; impressions: number; position: number; ctr: number }
const { rows } = await qd.performance.query<KeywordRow>({ property, report: 'top_performing_keywords' })Errors and retries
Failed calls throw QueryDeckError:
import { QueryDeck, QueryDeckError } from '@querydeck/sdk'
try {
await qd.properties.list()
} catch (error) {
if (error instanceof QueryDeckError) {
console.error(error.status, error.message, error.retryAfter)
}
}| Field | |
|---|---|
status | HTTP status, or 0 when the request never got a response |
message | The API's error message |
retryAfter | Seconds the server asked to wait on a 429, or null |
429 and 5xx responses and network failures are retried up to maxRetries
times. The client honours Retry-After, and otherwise backs off exponentially
from 500 ms. Other 4xx errors throw immediately. See Errors.