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

@dudousxd/nestjs-client

v0.7.0

Published

Framework-neutral runtime for nestjs-codegen output: typed fetcher with optional superjson transformer. No Inertia dependency.

Readme

@dudousxd/nestjs-client

The framework-neutral runtime for @dudousxd/nestjs-codegen output: a typed fetcher with pluggable transports and an optional superjson transformer. No Inertia dependency.

npm

The code generated by @dudousxd/nestjs-codegen (api.ts) imports the Fetcher type from this package and runs on a Fetcher instance you pass into createApi(fetcher). This package provides that fetcher: it owns URL building, headers, error mapping (ApiHttpError), and the payload transformer, while the actual network call goes through a pluggable transport (native fetch by default).

Because the generated client calls into it at runtime, this is a normal dependency — not a devDependency. The Fetcher interface is fully generic (get<T>(path, opts?): Promise<T>), and that typed surface is what lets the generated client and query options infer response types. A missing or any-typed fetcher silently degrades the whole generated client to any.

Install

pnpm add @dudousxd/nestjs-client

Usage

Create a fetcher, then hand it to the createApi exported by your generated api.ts:

import { createFetcher } from '@dudousxd/nestjs-client';
import { createApi } from './api'; // generated by @dudousxd/nestjs-codegen

const fetcher = createFetcher({
  baseUrl: '/api',
  headers: () => ({ authorization: `Bearer ${getToken()}` }),
});

const api = createApi(fetcher);

The default transport is native fetch. The headers function is called once per request, so dynamic auth tokens always stay current.

Bring your own axios instance

Pass axiosTransport(http) to reuse an existing axios instance with its own interceptors, auth, and withCredentials:

import axios from 'axios';
import { createFetcher, axiosTransport } from '@dudousxd/nestjs-client';

const http = axios.create({ baseURL: '/api', withCredentials: true });

const fetcher = createFetcher({ transport: axiosTransport(http) });

Set the base URL on the axios instance (not createFetcher's baseUrl) so it isn't prefixed twice.

Global headers

setGlobalHeaders registers a function applied to every request across all fetchers — handy for app-wide auth or tracing headers:

import { setGlobalHeaders } from '@dudousxd/nestjs-client';

setGlobalHeaders(() => ({ authorization: `Bearer ${getToken()}` }));

superjson & transformer pipelines

A transformer is a { stringify, parse } pair. Pass superjson to round-trip rich types (Date, Map, Set, BigInt) — the server must use the same transformer:

import superjson from 'superjson';
import { createFetcher } from '@dudousxd/nestjs-client';

const fetcher = createFetcher({ transformer: superjson });

Pass an array to compose a pipeline with composeTransformers: a base value↔string serializer first, then string↔string wrappers (compression, encryption) applied left-to-right on stringify and unwound right-to-left on parse:

import superjson from 'superjson';
import { createFetcher } from '@dudousxd/nestjs-client';
import { compress } from './my-compress'; // { stringify, parse } over strings

const fetcher = createFetcher({ transformer: [superjson, compress] });

Errors

Non-2xx responses reject with an ApiHttpError carrying status, statusText, and the parsed body, plus isUnauthorized / isForbidden / isNotFound / isClient / isServer helpers:

import { ApiHttpError } from '@dudousxd/nestjs-client';

try {
  await api.users.get({ params: { id } });
} catch (err) {
  if (err instanceof ApiHttpError && err.isNotFound) {
    // handle 404
  }
}

The Fetcher contract

The generated client depends on this typed surface — keep T generic so response types flow through:

interface Fetcher {
  get<T>(path: string, opts?: RequestOpts): Promise<T>;
  post<T>(path: string, opts?: RequestOpts): Promise<T>;
  put<T>(path: string, opts?: RequestOpts): Promise<T>;
  patch<T>(path: string, opts?: RequestOpts): Promise<T>;
  delete<T>(path: string, opts?: RequestOpts): Promise<T>;
}

createFetcher returns a value of this exact shape. Any object that satisfies the Fetcher interface works — which is why frameworks with their own client can supply a compatible createFetcher (see below).

How it fits with @dudousxd/nestjs-codegen

@dudousxd/nestjs-codegen is the codegen half — it runs in dev/CI and emits a fully typed api.ts from your NestJS controllers. That generated file imports the Fetcher type from this package and exposes a createApi(fetcher) factory.

@dudousxd/nestjs-client is the runtime half — the dependency the generated client actually executes against. You install it in your app, build a fetcher with createFetcher, and pass it to createApi.

Frameworks that ship their own client (for example @dudousxd/nestjs-inertia-client) expose a compatible createFetcher that produces a Fetcher-shaped object, so the same generated client runs unchanged on top of them.

Documentation

License

MIT