Overview & Quick Start
Payload CMS cache revalidation
@nexload-sdk/payload-revalidate
v1.0.0 ReleasedPer-transaction Payload CMS cache revalidation hooks and Next.js route handler.
Examples follow workspace source. Check pending Changesets against your installed version.
SDK dependencies: @nexload-sdk/logger, @nexload-sdk/payload-hooks
@nexload-sdk/payload-revalidate wires per-transaction Payload CMS collection and global hooks (hooks(), globalHooks()), bulk skipRevalidate + send() jobs, and a Next.js App Router route handler (createRevalidateHandler). It ships dual ESM and CJS builds; the root entry never imports next, and ./next runs in the Next.js Node.js runtime.
Installation
Section titled “Installation”pnpm add @nexload-sdk/payload-revalidate @nexload-sdk/logger payloadnpm install @nexload-sdk/payload-revalidate @nexload-sdk/logger payloadyarn add @nexload-sdk/payload-revalidate @nexload-sdk/logger payloadbun add @nexload-sdk/payload-revalidate @nexload-sdk/logger payloadPeer dependencies: payload >=3.85.0 <4.0.0, next >=16.0.0 <17 (optional, ./next only)
Quick Start
Section titled “Quick Start”Create a single shared revalidator on your Payload server, compose its hooks onto collections or globals, and mount createRevalidateHandler in Next.js:
// lib/revalidator.ts (Payload CMS server)import { createRevalidator } from "@nexload-sdk/payload-revalidate";
const secret = process.env.WEB_REVALIDATION_SECRET;if (!secret) { throw new Error("WEB_REVALIDATION_SECRET is required");}
export const revalidator = createRevalidator({ url: process.env.WEB_URL, secret,});// collections/Products.ts (Payload CMS server)import type { CollectionConfig } from "payload";import { revalidator } from "../lib/revalidator";
const productHooks = revalidator.hooks("products", { tags: ({ doc }) => ["products", `product:${doc.slug}`], paths: ({ doc }) => [`/shop/${doc.slug}`],});
export const Products: CollectionConfig = { slug: "products", hooks: { afterChange: [...productHooks.afterChange], afterDelete: [...productHooks.afterDelete], }, // ...fields};// app/api/revalidate/route.ts (Next.js App Router, Node.js runtime)import { createRevalidateHandler } from "@nexload-sdk/payload-revalidate/next";
export const POST = createRevalidateHandler({ secret: process.env.WEB_REVALIDATION_SECRET!,});See guides for hook composition, visibility rules, batching, proxy blocking, and testing, and the API reference for exports and wire limits.