JavaScript & TypeScript SDK
A small, typed client for Node.js 22+ and modern browsers. It handles dataset requests, pagination, retries and typed errors without a runtime dependency.
@zoniboy/gzw-data-client on npm ↗, latest release 0.9.0.
The generated TypeScript autocomplete list is only a snapshot. New API datasets stay usable without an npm update.
Install and fetch a page#
npm install @zoniboy/gzw-data-clientimport { GzwDataClient } from "@zoniboy/gzw-data-client";
const gzw = new GzwDataClient();
const page = await gzw.dataset("weapons").list({
page: 1,
perPage: 20,
});
console.log(page.data);
console.log(page.total);The SDK uses camelCase options such as perPage. Direct REST requests use the API's query spelling, per_page.
Discover datasets at runtime#
Use metadata() when an application needs the current dataset names. Newly added datasets can be passed to dataset(name) immediately.
const registry = await gzw.metadata();
const datasetNames = registry.datasets.map((dataset) => dataset.name);
const selectedName: string = datasetNames[0] ?? "weapons";
const selectedDataset = gzw.dataset(selectedName);
const info = await selectedDataset.info();
const records = await selectedDataset.list({ page: 1, perPage: 20 });For a newly discovered dataset, TypeScript uses the generic GzwRecord fallback: fields stay accessible, but fields without a curated model have type unknown.
List, filter, search and fetch#
Each dataset resource provides the same core operations. Filters and pagination can be combined.
const keys = gzw.dataset("keys");
const keycards = await keys.filter(
{ type: "Keycard" },
{ page: 1, perPage: 25 },
);
const akWeapons = await gzw.dataset("weapons").search("AK", {
page: 1,
perPage: 10,
});
const weapon = await gzw.dataset("weapons").get("ak-12");
if (weapon) console.log(weapon.name);A missing record from get(id) returns undefined. Other API errors throw GzwApiError.
Cross-dataset search#
const results = await gzw.search("AK-12", {
datasets: ["weapons"],
fields: ["name"],
fuzzy: true,
limit: 5,
});Iterate and batch-load#
iterate() yields records page by page. getMany() loads known IDs with bounded concurrency. dataset.export({ limit }) is still capped by the API's server-side maximum.
for await (const weapon of gzw.dataset("weapons").iterate({ perPage: 50 })) {
console.log(weapon.name);
}
const records = await gzw.dataset("weapons").getMany(
["ak-12", "ak-74"],
{ concurrency: 4 },
);Helpers are also available for stats(), health(), ready(), version(), metadata(), schema(), changes(), images() and spec().
Types and autocomplete#
The KnownGzwDataset union gives editor suggestions for names in the published SDK snapshot. Autocomplete is computed from local declarations, so it cannot query the API while you type. For a live picker inside your app, populate it from gzw.metadata().
GzwDataset also accepts arbitrary strings, so a name returned by the API works even if it is absent from the snapshot. Strongly typed models exist for selected stable datasets; unknown records use GzwRecord.
The SDK repository can refresh its generated names with npm run generate-types. Consumers receive new suggestions only when a later package version is published and installed. Routine dataset or count changes never trigger an npm release.
Errors, retries and cancellation#
HTTP failures are exposed as GzwApiError with status, stable code, request URL and retry information. The client retries eligible rate-limit, server, transient network and invalid-response failures by default. It respects Retry-After and does not retry caller-aborted requests.
import { GzwApiError } from "@zoniboy/gzw-data-client";
try {
await gzw.dataset("weapons").list();
} catch (error) {
if (error instanceof GzwApiError) {
console.error(error.status, error.code, error.retryAfter);
}
}Pass an AbortSignal as the final method argument to cancel a request. A configured timeoutMs bounds each network attempt.
Configure retries, timeout and cache#
Defaults work for a small app. The response cache is off unless you configure a positive TTL, and it is in-memory per process, not persistent storage.
const gzw = new GzwDataClient({
retries: 2,
timeoutMs: 15_000,
cache: { ttlMs: 30_000, maxEntries: 100 },
});Only successful GET responses are cached. Use clearCache() to clear all entries, or pass a path to invalidate one route's cached query variants.
Runtime, freshness and limits#
- Release 0.9.0 targets Node.js 22+ and modern browsers with native
fetch. Node.js 18 consumers can keep using 0.7.3. Browser projects should use a bundler such as Vite. - The API is public, read-only and keyless, with a best-effort limit of 100 requests per minute per IP. See rate limits.
- Data is refreshed by the scraper workflow and served through a CDN cache window, so new data may not appear immediately. Use
gzw.version()or the responsedataVersionto inspect the current snapshot. A data refresh is not an SDK release.
SDK behaviour goes to the client repository. Missing or wrong game data goes to the feedback page.
