@shopkit/webhooks
v0.1.1
Published
Webhook utilities for Shopify storefront applications
Downloads
313
Readme
@shopkit/webhooks
Webhook utilities for Shopify storefront applications. Handles webhook verification, cache invalidation, and Next.js page revalidation.
Installation
bun add @shopkit/webhooksQuick Start
import { handleShopifyWebhook } from "@shopkit/webhooks";
// In your Next.js API route
export async function POST(request: Request) {
const response = await handleShopifyWebhook(request, {
secret: process.env.SHOPIFY_WEBHOOK_SECRET!,
});
return Response.json(response, {
status: response.success ? 200 : 400,
});
}Features
- HMAC Verification: Validates Shopify webhook signatures (SHA-256)
- Cache Invalidation: Automatically determines which caches to invalidate based on entity type
- Page Revalidation: Triggers Next.js ISR revalidation for affected pages
- Entity Support: Products, collections, and inventory updates
Supported Webhooks
| Entity | Events | Revalidation Path |
|--------|--------|-------------------|
| Product | create, update, delete | /products/{handle} |
| Collection | create, update, delete | /collections/{handle} |
| Inventory | update | Requires product context |
Configuration
handleShopifyWebhook(request, {
secret: process.env.SHOPIFY_WEBHOOK_SECRET!,
// Additional options as needed
});Environment Variables
| Variable | Description |
|----------|-------------|
| SHOPIFY_WEBHOOK_SECRET | Shopify webhook HMAC secret for signature verification |
Peer Dependencies
next>= 14.0.0
Architecture
See ARCHITECTURE.md for detailed system design.
