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

@nogg-aholic/nrpc-api-kit

v0.1.0

Published

Shared helpers for nRPC 0.4.0 service transport and code generation

Downloads

85

Readme

nRPC API Kit

@nogg-aholic/nrpc-api-kit provides reusable server-side helpers for building nRPC services.

It packages the common pieces used across services in this repo:

  • fetch handler wiring for nRPC POST endpoints
  • optional health endpoint and custom HTTP routes
  • websocket dispatcher for method calls
  • Bun server bootstrap
  • artifact generation wrapper for contract/docs output

Install

With Bun:

bun add @nogg-aholic/nrpc-api-kit @nogg-aholic/nrpc

With npm:

npm install @nogg-aholic/nrpc-api-kit @nogg-aholic/nrpc

Quick Start (HTTP RPC)

import { createRpcMethodInvoker } from '@nogg-aholic/nrpc/web-runtime';
import { createServiceFetchHandler } from '@nogg-aholic/nrpc-api-kit';

import { createMyService } from './rpc-service.js';
import { myApiCodecRegistry } from './generated/my-api.contract.js';

const service = createMyService();
const invokeMethod = createRpcMethodInvoker(service);

export const createFetchHandler = () =>
  createServiceFetchHandler({
    service,
    codecResolver: myApiCodecRegistry,
    rpcPath: '/rpc',
    healthPath: '/health',
  });

export const createRpcInvoker = () => invokeMethod;

The fetch handler behavior is:

  • POST /rpc (or your rpcPath) is routed to the nRPC request handler
  • GET /health (or your healthPath) returns service.health.status() when available
  • unmatched routes return a JSON 404 response

Add Custom HTTP Routes

import { createServiceFetchHandler, RpcServiceError, jsonError } from '@nogg-aholic/nrpc-api-kit';

const fetchHandler = createServiceFetchHandler({
  service,
  codecResolver: myApiCodecRegistry,
  routes: [
    {
      method: 'GET',
      path: '/v1/models',
      handler: async ({ service }) => Response.json(await service.models.list()),
    },
    {
      method: 'GET',
      path: '/v1/active-credential',
      handler: async ({ service, url }) => {
        const accountId = url.searchParams.get('account_id') ?? undefined;

        try {
          return Response.json(await service.accounts.activeCredential({ accountId }));
        } catch (error) {
          if (error instanceof RpcServiceError) {
            return jsonError(error.status, error.message, 'invalid_request_error');
          }
          throw error;
        }
      },
    },
  ],
});

Start a Bun Server

import { startBunRpcServer } from '@nogg-aholic/nrpc-api-kit';

startBunRpcServer({
  config: {
    port: 4000,
    serviceName: 'my-nrpc-service',
    websocketEnabled: true,
  },
  fetchHandler: createFetchHandler(),
  invokeRpcMethod: createRpcInvoker(),
});

startBunRpcServer exposes:

  • HTTP RPC endpoint at /rpc by default
  • websocket endpoint at /rpc/ws when websocketEnabled is true

Override paths with rpcPath and websocketPath in startBunRpcServer options.

Config Helper

import { loadServiceConfig } from '@nogg-aholic/nrpc-api-kit';

const config = loadServiceConfig({
  defaultPort: 4000,
  serviceName: 'my-nrpc-service',
});

Environment variables:

  • PORT: server port (falls back to defaultPort)
  • NRPC_ENABLE_WS: enables websocket mode when set to 1, true, yes, or on

Generate Service Artifacts

Use the build export to generate contract and docs artifacts.

import { fileURLToPath } from 'node:url';
import { generateServiceArtifacts } from '@nogg-aholic/nrpc-api-kit/build';

await generateServiceArtifacts({
  entryFile: fileURLToPath(new URL('../src/rpc-service.ts', import.meta.url)),
  rootType: 'MyServiceContract',
  outFile: fileURLToPath(new URL('../src/generated/my-api.surface.ts', import.meta.url)),
  rootPath: [],
  globalName: 'myApi',
  docsInfo: {
    title: 'My Service nRPC API',
    version: '0.1.0',
    description: 'Generated nRPC contract artifacts for My Service.',
  },
});

Exports

Main export (@nogg-aholic/nrpc-api-kit):

  • constants: RPC_AWAIT_EVENT, RPC_RETURN_EVENT, isWebsocketEnabled
  • errors: RpcServiceError, isRpcServiceError, defaultTransformError
  • config: loadServiceConfig, ServiceConfig
  • responses: jsonError, notFoundJson, createRpcBinaryErrorResponse
  • server: createServiceFetchHandler, handleRpcWebSocketMessage, startBunRpcServer
  • build: generateServiceArtifacts

Build export (@nogg-aholic/nrpc-api-kit/build):

  • generateServiceArtifacts

Runtime Notes

  • startBunRpcServer and generateServiceArtifacts rely on Bun APIs.
  • createServiceFetchHandler is runtime-agnostic and returns a standard (request: Request) => Promise<Response> handler.