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

@dloizides/api-client-base

v1.0.0

Published

Realm-agnostic, product-agnostic HTTP plumbing for the dloizides.com portfolio: fetch wrapper with bearer-token injection via callback, error envelope mapping, declarative error registry, typed event bus. Pairs with @dloizides/auth-client by composition,

Readme

@dloizides/api-client-base

Realm-agnostic, product-agnostic HTTP plumbing for the dloizides.com portfolio.

Built for the Questioner / OnlineMenu product split (and any future products): a single fetch wrapper, a uniform error envelope shape, a typed event bus for bridging interceptor-layer signals to UI components, and a declarative error registry that maps HTTP statuses + body codes to UI actions.

This package never references a specific product, realm, or hardcoded URL. Consumers supply their own baseUrl and pair the client with @dloizides/auth-client through the getAccessToken callback — the two packages compose without importing each other.

Install

npm install @dloizides/api-client-base

Quick start

import { ApiClient, ApiError } from '@dloizides/api-client-base';
import { AuthClient } from '@dloizides/auth-client';

const auth = new AuthClient(
  { baseUrl: 'https://identity.example.com', realm: 'questioner', clientId: 'web' },
  storage,
);

const api = new ApiClient({
  baseUrl: 'https://api.questioner.com',
  defaultHeaders: { 'X-Tenant-Id': tenantId },
  getAccessToken: () => auth.getAccessToken(),
});

try {
  const user = await api.get<{ id: string }>('/users/me');
} catch (err) {
  if (err instanceof ApiError && err.status === 401) {
    // token expired — your interceptor or refresh layer handles it
  }
}

What's in the box

| Surface | Purpose | |---|---| | ApiClient | fetch-based client. JSON-by-default, throws ApiError on non-2xx. | | ApiError / ApiErrorEnvelope | uniform error shape (status, code, message, details). | | apiEventBus / ApiEventBus | typed pub/sub bridging interceptor layer to UI. | | ErrorActionType / ErrorSeverity | enums for the registry's UI actions. | | getErrorRules / registerErrorRule / resetErrorRules | mutable, priority-sorted rule registry. | | setLoginRedirectPath / resetLoginRedirectPath | override the session-expired redirect target. | | matchError / matchesRule / matchesStatus / matchesPath / matchesMethod | matcher engine. | | classifyAxiosError | pure classifier on a duck-typed AxiosErrorLike. No axios dependency. | | extractErrorCode / extractErrorMessage / extractRequestId | pure helpers for FastEndpoints / ProblemDetails envelopes. |

Composition with @dloizides/auth-client

The getAccessToken callback is the only contract — this package never imports auth-client, and auth-client never imports this package. Wire them up at the application bootstrap:

const auth = new AuthClient({ baseUrl, realm, clientId }, new BrowserStorageTokenStorage());
const api = new ApiClient({
  baseUrl: API_BASE_URL,
  getAccessToken: () => auth.getAccessToken(),
});

Custom error rules

The default registry covers the common HTTP errors (401 session-expired, 402 payment-required modal, 403 forbidden toast, 422 validation, 5xx server errors, etc.). Add app-specific rules at any time:

import {
  registerErrorRule,
  ErrorActionType,
  ErrorSeverity,
  PRIORITY_ROUTE_SPECIFIC,
} from '@dloizides/api-client-base';

registerErrorRule({
  name: 'team-deleted',
  match: { status: 410, path: '/teams' },
  action: {
    type: ErrorActionType.Modal,
    severity: ErrorSeverity.Warning,
    modalComponent: 'TeamDeletedModal',
  },
  messageKey: 'errors.teamDeleted',
  priority: PRIORITY_ROUTE_SPECIFIC,
});

License

MIT © dloizides.com