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

nextjs-github-webhooks

v1.1.0

Published

Lightweight integration for GitHub webhooks in Next.js

Readme

nextjs-github-webhooks

A lightweight integration for handling GitHub webhooks in your Next.js App Router application.

Installation

pnpm add nextjs-github-webhooks
# or
npm install nextjs-github-webhooks
# or
yarn add nextjs-github-webhooks

Setup

1. Create a webhook route

Create a route handler (e.g. app/api/webhooks/github/route.ts) and use createGitHubWebhookHandler:

import { createGitHubWebhookHandler } from "nextjs-github-webhooks";
import type { WebhookContext, PushPayload } from "nextjs-github-webhooks";

const handler = createGitHubWebhookHandler({
  secret: process.env.GITHUB_WEBHOOK_SECRET!,
  handlers: {
    push: async (ctx: WebhookContext<"push">) => {
      const { id, payload } = ctx;
      const pushPayload = payload as PushPayload;
      console.log(`Push to ${pushPayload.repository.full_name}: ${pushPayload.ref}`);
      // Handle your logic here
    },
  },
});

export const POST = handler;

2. Environment variable

Add your GitHub webhook secret to .env.local:

GITHUB_WEBHOOK_SECRET=your_webhook_secret_here

Payload validation

This library verifies the HMAC signature (X-Hub-Signature-256) against the raw request body so only requests that match your GitHub webhook secret are accepted. It does not run runtime schema validation on the parsed JSON (for example with Zod or similar).

Why: A schema layer would add dependencies and ongoing maintenance beyond what @octokit/webhooks already provides as TypeScript types. For signed webhooks, the practical trust boundary is authenticity: the payload is what GitHub sent for that delivery.

If you want to be extra defensive—for example strict checks before branching on nested fields, compliance requirements, or guarding against unexpected shapes—validate ctx.payload inside your own handlers using whatever fits your project (Zod, manual guards, etc.). That stays optional and avoids pulling validation libraries into every consumer.

API

createGitHubWebhookHandler(options)

Creates an async request handler compatible with Next.js Route Handlers.

| Option | Type | Description | | ----------- | ------------------------------------------------ | ---------------------------------- | | secret | string | Webhook secret from GitHub | | handlers | Partial<Record<EmitterWebhookEventName, WebhookHandler>> | Event name → handler mapping |

Returns an async (req: Request) => Response function.

Handler events

You can register handlers for any GitHub webhook event, for example:

  • push
  • issues
  • issue_comment
  • pull_request
  • star
  • workflow_run
  • …and many more

Example with multiple events:

handlers: {
  push: async (ctx) => {
    console.log("Push received", ctx.payload);
  },
  issues: async (ctx) => {
    console.log("Issue event", ctx.payload);
  },
  pull_request: async (ctx) => {
    console.log("PR event", ctx.payload);
  },
}

Types

  • WebhookContext<E> – Context passed to handlers: { id: string; payload: T }. Use WebhookContext<"push"> for typed payloads.
  • PushPayload – Typed payload for push events.
  • WebhookHandler – Handler signature: (context) => Promise<void>.
  • EmitterWebhookEventName – All supported event names from @octokit/webhooks.

Responses

| Status | Condition | | ------ | --------- | | 400 | Missing required headers (x-hub-signature-256, x-github-event, or x-github-delivery), or body is not valid JSON | | 401 | Invalid signature | | 500 | A registered handler threw or rejected | | 200 | Webhook processed successfully |

License

MIT