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

@better-webhook/nextjs

v1.1.0

Published

Next.js framework adapter for Better Webhook

Downloads

179

Readme

@better-webhook/nextjs

Turn a Next.js Route Handler into a Better Webhook endpoint without losing the raw request bytes required for provider signature verification.

@better-webhook/nextjs is the framework adapter for Next.js App Router route handlers. It translates a Fetch-style Request into the Raw Delivery Request contract expected by @better-webhook/core, then converts the core response back into a standard Response.

Why use this package?

  • Keep signature verification inside the Better Webhook pipeline.
  • Read request.arrayBuffer() before any JSON parsing changes the body.
  • Preserve signature-relevant Fetch header values.
  • Return provider-friendly HTTP responses from core's response policy.
  • Keep framework request objects out of event handlers.

Installation

Install the Next.js adapter with core and a provider package:

pnpm add @better-webhook/core @better-webhook/nextjs @better-webhook/stripe

Getting started

Create a Next.js route handler that delegates the POST request to a Better Webhook endpoint:

import { createWebhookEndpoint } from "@better-webhook/core";
import { createNextRouteHandler } from "@better-webhook/nextjs";
import { stripe } from "@better-webhook/stripe";

const endpoint = createWebhookEndpoint({
  provider: stripe({ signingSecret: process.env.STRIPE_WEBHOOK_SECRET! }),
  handlers: {
    "checkout.session.completed": async ({ event }) => {
      event.payload.payment_status;
    },
    "invoice.paid": async ({ event }) => {
      event.payload.status;
    },
  },
});

export const runtime = "nodejs";
export const POST = createNextRouteHandler(endpoint);

Configure your provider to send webhook deliveries to this route, for example https://example.com/api/webhooks/stripe.

How it fits with Better Webhook

@better-webhook/nextjs is a Framework Adapter. It does not implement provider verification, replay protection, idempotency, event parsing, or handler dispatch. Those stay in @better-webhook/core and the selected provider package.

This package only adapts:

  • Next.js route handler requests to core Raw Delivery Requests.
  • Core Webhook Responses to Fetch Response objects.

Behavior and safety notes

The adapter reads request.arrayBuffer() and passes those bytes to core without JSON parsing or reserialization. That matters because providers such as Stripe sign the exact raw request body.

Next.js route handlers expose Fetch Headers. Fetch headers preserve signature-relevant values, but they do not expose duplicate raw header lines. The exported nextjsRawHeaderCapabilities value records that capability limit.

Event handlers receive Better Webhook's framework-neutral Handler Context. They do not receive the Next.js request object.

API summary

  • createNextRouteHandler(endpoint): returns a Next.js-compatible POST handler.
  • toRawDeliveryRequest(request): converts a Fetch-style request into a core Raw Delivery Request.
  • toNextResponse(response): converts a core Webhook Response into Response.
  • nextjsRawHeaderCapabilities: describes raw body and raw header preservation.
  • NextWebhookRequest: minimal request shape accepted by the adapter.

Runtime support and limits

  • Node.js 18 or newer.
  • ESM-only package with TypeScript declarations.
  • Use the Next.js Node.js runtime for the initial SDK release.
  • Edge runtime support is out of scope for now.