@vettly/nextjs
v0.1.15
Published
Next.js integration for Vettly decision infrastructure. Content decisions with policy governance.
Maintainers
Readme
@vettly/nextjs
Next.js integration for Vettly decision infrastructure. Policy-governed decisions for App Router, Pages Router, and Middleware.
Installation
npm install @vettly/nextjsQuick Start - Middleware
Protect multiple routes at once:
// middleware.ts
import { moderateMiddleware } from '@vettly/nextjs'
export default moderateMiddleware({
apiKey: process.env.VETTLY_API_KEY!,
policy: 'community-safe',
field: async (req) => {
const body = await req.json()
return body.content
}
})
export const config = {
matcher: '/api/comments/:path*'
}Quick Start - Route Handler
Protect a single endpoint:
// app/api/comments/route.ts
import { moderateRoute } from '@vettly/nextjs'
export const POST = moderateRoute({
apiKey: process.env.VETTLY_API_KEY!,
policy: 'community-safe',
field: 'content',
handler: async (req) => {
const body = await req.json()
await db.comments.create({ data: body })
return NextResponse.json({ success: true })
}
})Custom Block Handling
export const POST = moderateRoute({
apiKey: process.env.VETTLY_API_KEY!,
policy: 'community-safe',
field: 'content',
handler: async (req) => {
// Content is safe
return NextResponse.json({ success: true })
},
onBlock: (req, result) => {
return NextResponse.json(
{ error: 'Content blocked', categories: result.categories },
{ status: 403 }
)
}
})Links
- vettly.dev - Sign up
- docs.vettly.dev - Documentation
