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

@clientpad/server

v0.2.0

Published

Fetch-standard ClientPad public API server for PostgreSQL-backed apps.

Readme

ClientPad Server

Fetch-standard server handlers for ClientPad public APIs.

Install

pnpm add @clientpad/server

Install the optional WhatsApp package when you want the same handler to receive Meta WhatsApp Cloud API webhooks:

pnpm add @clientpad/whatsapp

Basic Usage

import { createClientPadHandler } from "@clientpad/server";

export const handler = createClientPadHandler({
  databaseUrl: process.env.DATABASE_URL!,
  apiKeyPepper: process.env.API_KEY_PEPPER!,
});

The handler accepts a standard Request and returns a standard Response.

Next.js Route Handler

import { createClientPadHandler } from "@clientpad/server";

const handler = createClientPadHandler({
  databaseUrl: process.env.DATABASE_URL!,
  apiKeyPepper: process.env.API_KEY_PEPPER!,
});

export const GET = handler;
export const POST = handler;

Mount it under routes that forward to:

/api/public/v1/leads
/api/public/v1/clients
/api/public/v1/usage

WhatsApp Webhooks

Add the optional whatsapp config to enable GET /whatsapp/webhook for Meta verification and POST /whatsapp/webhook for inbound WhatsApp Cloud API messages. Full public API paths also work, so /api/public/v1/whatsapp/webhook is equivalent.

import { createClientPadHandler } from "@clientpad/server";

export const handler = createClientPadHandler({
  databaseUrl: process.env.DATABASE_URL!,
  apiKeyPepper: process.env.API_KEY_PEPPER!,
  whatsapp: {
    verifyToken: process.env.WHATSAPP_VERIFY_TOKEN!,
    accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
    phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
    clientpadBaseUrl: "https://your-app.com/api/public/v1",
    clientpadApiKey: process.env.CLIENTPAD_API_KEY!,
    appSecret: process.env.WHATSAPP_APP_SECRET,
    defaultCountryCode: "+234",
    flow: {
      // Service/business pipeline flow config consumed by @clientpad/whatsapp.
    },
  },
});

When appSecret is set, the server validates Meta's X-Hub-Signature-256 HMAC before dispatching the webhook. The WhatsApp integration normalizes inbound phone numbers to +234 by default, upserts ClientPad-compatible leads, stores raw messages in the WhatsApp tables, maps button/list replies to pipeline updates, and sends native WhatsApp interactive responses.

Express example

import express from "express";
import { createClientPadHandler } from "@clientpad/server";

const app = express();
const clientpad = createClientPadHandler({
  databaseUrl: process.env.DATABASE_URL!,
  apiKeyPepper: process.env.API_KEY_PEPPER!,
  whatsapp: {
    verifyToken: process.env.WHATSAPP_VERIFY_TOKEN!,
    accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
    phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
    clientpadBaseUrl: "https://your-app.com/api/public/v1",
    clientpadApiKey: process.env.CLIENTPAD_API_KEY!,
    appSecret: process.env.WHATSAPP_APP_SECRET,
    defaultCountryCode: "+234",
  },
});

app.all(["/api/public/v1/*path", "/whatsapp/webhook"], async (req, res) => {
  const url = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
  const body = req.method === "GET" || req.method === "HEAD" ? undefined : req;
  const response = await clientpad(new Request(url, { method: req.method, headers: req.headers as HeadersInit, body }));

  res.status(response.status);
  response.headers.forEach((value, key) => res.setHeader(key, value));
  res.send(Buffer.from(await response.arrayBuffer()));
});

Hono example

import { Hono } from "hono";
import { createClientPadHandler } from "@clientpad/server";

const app = new Hono();
const clientpad = createClientPadHandler({
  databaseUrl: process.env.DATABASE_URL!,
  apiKeyPepper: process.env.API_KEY_PEPPER!,
  whatsapp: {
    verifyToken: process.env.WHATSAPP_VERIFY_TOKEN!,
    accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
    phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
    clientpadBaseUrl: "https://your-app.com/api/public/v1",
    clientpadApiKey: process.env.CLIENTPAD_API_KEY!,
    appSecret: process.env.WHATSAPP_APP_SECRET,
    defaultCountryCode: "+234",
  },
});

app.all("/api/public/v1/*", (c) => clientpad(c.req.raw));
app.all("/whatsapp/webhook", (c) => clientpad(c.req.raw));

Supported Routes

  • GET /leads
  • POST /leads
  • GET /clients
  • POST /clients
  • GET /usage
  • GET /whatsapp/webhook when WhatsApp is configured
  • POST /whatsapp/webhook when WhatsApp is configured

The handler also accepts full public API paths such as /api/public/v1/leads.

Usage Metering

The server records API key usage in PostgreSQL and enforces optional limits:

  • monthly_request_limit
  • rate_limit_per_minute
  • billing_mode

Leaving limits empty keeps self-hosted deployments unlimited. Hosted ClientPad Cloud deployments can set limits on API keys and return 429 when a key exceeds quota.