npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nz-open-data-connectors/stats-nz

v0.1.1

Published

Shared client for the [Aotearoa Data Explorer (ADE) API](https://www.stats.govt.nz/tools/aotearoa-data-explorer/ade-api-user-guide/) - the current Stats NZ data API (the old `api.stats.govt.nz` open data API closed 30 August 2024). SDMX 2.1 REST, base URL

Downloads

647

Readme

@nz-open-data-connectors/stats-nz

Shared client for the Aotearoa Data Explorer (ADE) API - the current Stats NZ data API (the old api.stats.govt.nz open data API closed 30 August 2024). SDMX 2.1 REST, base URL https://api.data.stats.govt.nz/rest/.

Server-side only (SDMX responses can be large; never call this from the browser).

Quick start

import { createStatsNzClient } from '@nz-open-data-connectors/stats-nz';

const client = createStatsNzClient({
  subscriptionKey: process.env.STATS_NZ_SUBSCRIPTION_KEY, // optional, see below
});

// Every table in ADE, with titles: 911 dataflows, keyless.
const catalogue = await client.getDataflowCatalogue();

// Data as typed rows. Works keyless for agriculture tables (e.g. AGR_AGR_003).
const rows = await client.getData({ dataflowId: 'AGR_AGR_003', format: 'csv' });
// rows: [{ dimensions: { LIVESTOCK: '6731', AREA: '20', YEAR: '2024' }, value: 23583001, ... }]

// Codelists (dimension code -> label) need a subscription key.
const codelist = await client.getCodelist('CL_LIVESTOCK_AGR_AGR_003', { version: '1.0' });

Access levels (verified live 2025-08-17)

| Endpoint | Without key | With key | | ------------------------------------------ | ---------------------------- | ---------- | | getDataflowCatalogue() | yes | yes | | getData({ format: 'csv' }) | agriculture tables (AGR_*) | all tables | | getData({ format: 'csvfilewithlabels' }) | no | yes | | getData({ format: 'jsondata' }) | no | yes | | getCodelist() / structure endpoints | no | yes |

Keyless requests must use the explicit published version. The client defaults to 1.0 (every one of the 911 current dataflows is version 1.0); pass version: 'latest' only with a key.

Subscription key

Free signup at portal.apis.stats.govt.nz. Set STATS_NZ_SUBSCRIPTION_KEY in the app env (server-only). Sent as the Ocp-Apim-Subscription-Key header; never exposed to the browser.

Formats

  • csv - codes only, keyless for AGR_* tables. Fast to parse, verified against the real API.
  • csvfilewithlabels - code + label columns, requires a key.
  • jsondata - SDMX-JSON, requires a key. Parser implemented against the SDMX-JSON 1.0 spec; not yet live-verified (needs a subscription key).

serializeStatsNzRowsToCsv(rows) turns typed observations back into CSV (dimension columns, then value, then status when present) for language-agnostic output.

Errors

All failures throw StatsNzError subclasses: StatsNzApiError (HTTP status, retryable flag for 429/5xx) and StatsNzParseError (malformed response).

Tests

npm run test -w @nz-open-data-connectors/stats-nz        # unit + integration (local stub server) + perf + security
RUN_SMOKE=1 npm run test:smoke -w @nz-open-data-connectors/stats-nz   # live smoke tests against api.data.stats.govt.nz

Fixtures in src/fixtures/ are real snapshots pulled from the ADE API (format=csv and the dataflow catalogue), dated in their filenames. The smoke tests are skipped by default and must be run explicitly.