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

zyte-api

v0.2.0

Published

Node.js TypeScript client for Zyte API /v1/extract.

Readme

zyte-api

A Node.js-only TypeScript client for Zyte API POST /v1/extract.

  • ESM-only package for Node.js >=24.15.0.
  • Development uses native Node TypeScript execution, node:test, and built-in fetch.
  • Build output is the only transpiled JavaScript.
  • No runtime dependencies.
  • Full /extract request/response type coverage generated from the official Zyte OpenAPI 3.0.3 spec.
  • Pluggable HTTP transport with native fetch as the default.

Official API reference used for the schema: https://docs.zyte.com/zyte-api/usage/reference.html.

Install

npm install zyte-api

Quick start

import { ZyteClient, decodeHttpResponseBody } from "zyte-api";

const client = new ZyteClient({ apiKey: process.env.ZYTE_API_KEY ?? "" });

const response = await client.extract({
  url: "https://example.com/",
  httpResponseBody: true,
  httpResponseHeaders: true,
});

console.log(response.statusCode, response.url);
console.log(decodeHttpResponseBody(response)?.toString("utf8"));

Custom HTTP transport

Use a custom transport to plug in your own HTTP stack, observability, retry policy, proxy handling, or test double.

import { headersToRecord, ZyteClient, type ZyteHttpTransport } from "zyte-api";

const transport: ZyteHttpTransport = async (request) => {
  const response = await fetch(request.url, {
    method: request.method,
    headers: request.headers,
    body: request.body,
    signal: request.signal,
  });

  return {
    status: response.status,
    statusText: response.statusText,
    headers: headersToRecord(response.headers),
    body: await response.text(),
  };
};

const client = new ZyteClient({ apiKey: "YOUR_ZYTE_API_KEY", transport });

API

new ZyteClient(options)

type ZyteClientOptions = {
  apiKey: string;
  baseUrl?: string | URL;
  endpoint?: string;
  transport?: ZyteHttpTransport;
  defaultHeaders?: HeaderInit;
  userAgent?: string;
  timeoutMs?: number;
  allowInsecureHttp?: boolean;
};

By default, requests go to https://api.zyte.com/v1/extract and use native fetch. Zyte Basic authentication is configured automatically with the API key as username and an empty password.

endpoint and request(path, ...) must be relative paths. Absolute URLs are rejected so the Authorization header cannot be routed to an unexpected origin. baseUrl must use HTTPS by default; set allowInsecureHttp: true only for local/test transports.

client.extract(request, options?)

Sends a typed Zyte /extract request and returns a typed response.

const product = await client.extract({
  url: "https://example.com/product/1",
  product: true,
});

Transport support utilities

The root export includes transport helper types and utilities for adapters and tests:

  • ZyteHttpTransport, ZyteHttpRequest, ZyteHttpResponse
  • createFetchTransport()
  • headersToRecord()
  • createStaticResponse()

The root export also includes configuration helpers (normalizeBaseUrl, normalizeEndpoint, validateTimeout, composeSignal) for adapter authors who need to mirror client behavior.

Errors

  • ZyteApiError: non-2xx response or invalid success JSON. Exposes status, problem, and response.
  • ZyteTransportError: underlying HTTP transport rejected.
  • ZyteConfigurationError: invalid API key, URL, endpoint, timeout, or missing native fetch.

Development

npm install
npm run generate:types -- --check
npm run typecheck
npm run lint
npm run test:coverage
npm run build
npm pack --dry-run

The coverage gate targets hand-written runtime modules. Generated OpenAPI types are checked for schema coverage and freshness, but excluded from runtime coverage thresholds.