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/gcp-functions

v0.2.0

Published

GCP Cloud Functions integration for better-webhook

Readme

@better-webhook/gcp-functions

npm npm monthly

GCP Cloud Functions webhooks in one line.

Turn any better-webhook handler into a GCP Cloud Functions HTTP handler. Zero configuration required.

// index.ts
import { http } from "@google-cloud/functions-framework";
import { ragie } from "@better-webhook/ragie";
import { toGCPFunction } from "@better-webhook/gcp-functions";

const webhook = ragie().event("document_status_updated", async (payload) => {
  console.log(`Document ${payload.document_id} is now ${payload.status}`);
});

http("webhookHandler", toGCPFunction(webhook));

That's it. Your webhook endpoint is ready.

Features

  • ⚡ Zero config — Works out of the box with Cloud Functions
  • 🔒 Automatic verification — Signatures verified before your handler runs
  • 📝 Type safe — Full TypeScript support
  • 🎯 Clean API — One function, one line
  • ☁️ Gen 1 & Gen 2 — Supports both Cloud Functions generations
  • 📦 Functions Framework v3 & v4 — Compatible with latest @google-cloud/functions-framework

Installation

npm install @better-webhook/gcp-functions @better-webhook/core
# or
pnpm add @better-webhook/gcp-functions @better-webhook/core
# or
yarn add @better-webhook/gcp-functions @better-webhook/core

Quick Start

1. Install a provider

npm install @better-webhook/ragie

2. Create your Cloud Function

2nd Generation (recommended):

// index.ts
import { http } from "@google-cloud/functions-framework";
import { ragie } from "@better-webhook/ragie";
import { toGCPFunction } from "@better-webhook/gcp-functions";

const webhook = ragie({ secret: process.env.RAGIE_WEBHOOK_SECRET })
  .event("document_status_updated", async (payload) => {
    if (payload.status === "ready") {
      await notifyDocumentReady(payload.document_id);
    }
  })
  .event("connection_sync_finished", async (payload) => {
    console.log(`Sync ${payload.sync_id} completed`);
  });

http("webhookHandler", toGCPFunction(webhook));

1st Generation (exports style):

// index.ts
import { ragie } from "@better-webhook/ragie";
import { toGCPFunction } from "@better-webhook/gcp-functions";

const webhook = ragie({ secret: process.env.RAGIE_WEBHOOK_SECRET }).event(
  "document_status_updated",
  async (payload) => {
    console.log(`Document ${payload.document_id} status: ${payload.status}`);
  }
);

export const webhookHandler = toGCPFunction(webhook);

3. Set your secret

Add the secret to your Cloud Function environment variables:

gcloud functions deploy webhookHandler \
  --runtime nodejs20 \
  --trigger-http \
  --set-env-vars RAGIE_WEBHOOK_SECRET=your-secret-here

Done! Point your webhook provider to your Cloud Function URL.

Handler Context

Every handler receives a second parameter with metadata about the webhook request:

const webhook = ragie().event(
  "document_status_updated",
  async (payload, context) => {
    // Access provider info
    console.log(`Provider: ${context.provider}`); // "ragie"
    console.log(`Event: ${context.eventType}`); // "document_status_updated"

    // Access headers
    console.log(`Content-Type: ${context.headers["content-type"]}`);

    // Timestamp when webhook was received
    console.log(`Received at: ${context.receivedAt.toISOString()}`);

    await processDocument(payload);
  }
);

http("webhookHandler", toGCPFunction(webhook));

Context Properties

| Property | Type | Description | | ------------ | --------- | ---------------------------------------------------- | | eventType | string | Event type (e.g., "document_status_updated") | | provider | string | Provider name (e.g., "ragie") | | headers | Headers | Request headers (lowercase keys) | | rawBody | string | Raw request body | | receivedAt | Date | Timestamp when webhook was received |

Error Handling

Handle errors gracefully:

const webhook = ragie()
  .event("document_status_updated", async (payload, context) => {
    console.log(`[${context.eventType}] Processing document...`);
    await processDocument(payload);
  })
  .onError((error, context) => {
    // Log to your error tracking service
    console.error(`Webhook failed: ${context.eventType}`, error);
  })
  .onVerificationFailed((reason, headers) => {
    // Signature verification failed
    console.warn("Verification failed:", reason);
  });

http("webhookHandler", toGCPFunction(webhook));

Configuration Options

Custom Secret

Override the environment variable:

http(
  "webhookHandler",
  toGCPFunction(webhook, {
    secret: process.env.MY_CUSTOM_SECRET,
  })
);

Success Callback

Track successful webhook processing:

http(
  "webhookHandler",
  toGCPFunction(webhook, {
    onSuccess: async (eventType) => {
      // Log to analytics
      await analytics.track("webhook_processed", {
        provider: "ragie",
        event: eventType,
      });
    },
  })
);

Raw Body for Signature Verification

For signature verification to work correctly, the raw request body must be available. GCP Cloud Functions with the Functions Framework provide req.rawBody automatically.

If you're using a custom setup, ensure raw body is preserved:

// The adapter checks for raw body in this order:
// 1. req.rawBody (Functions Framework default)
// 2. Buffer body
// 3. String body
// 4. JSON.stringify(req.body) as fallback (may not match original for signature verification)

Response Status Codes

The adapter returns appropriate HTTP status codes:

| Code | Meaning | | ----- | --------------------------------------------- | | 200 | Webhook processed successfully | | 204 | No handler registered for this event type | | 400 | Invalid JSON body or schema validation failed | | 401 | Signature verification failed | | 405 | Method not allowed (non-POST request) | | 500 | Handler threw an error |

Custom Providers

Works with any better-webhook provider:

import { customWebhook, z } from "@better-webhook/core";
import { toGCPFunction } from "@better-webhook/gcp-functions";
import { http } from "@google-cloud/functions-framework";

const webhook = customWebhook({
  name: "my-service",
  schemas: {
    "user.created": z.object({
      userId: z.string(),
      email: z.string().email(),
    }),
  },
  getEventType: (headers) => headers["x-event-type"],
}).event("user.created", async (payload, context) => {
  console.log(`[${context.eventType}] New user: ${payload.userId}`);
  await sendWelcomeEmail(payload.email);
});

http("webhookHandler", toGCPFunction(webhook));

Deployment

Using gcloud CLI

gcloud functions deploy webhookHandler \
  --gen2 \
  --runtime nodejs20 \
  --trigger-http \
  --allow-unauthenticated \
  --entry-point webhookHandler \
  --set-env-vars RAGIE_WEBHOOK_SECRET=your-secret

Using Terraform

resource "google_cloudfunctions2_function" "webhook" {
  name     = "webhook-handler"
  location = "us-central1"

  build_config {
    runtime     = "nodejs20"
    entry_point = "webhookHandler"
    source {
      storage_source {
        bucket = google_storage_bucket.source.name
        object = google_storage_bucket_object.source.name
      }
    }
  }

  service_config {
    max_instance_count = 10
    available_memory   = "256M"
    timeout_seconds    = 60
    environment_variables = {
      RAGIE_WEBHOOK_SECRET = var.ragie_webhook_secret
    }
  }
}

License

MIT