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

@safeform/next

v4.1.0

Published

Next.js App Router adapter for safeform

Readme

@safeform/next

Next.js App Router adapter for @safeform/core.

npm install @safeform/core @safeform/next

Peer dependencies: Next.js 14+, Zod 3+


Table of Contents


Usage

Mount a safeform action as a Next.js App Router route handler with a single line:

// app/api/employees/route.ts
import { createAction } from '@safeform/core'
import { createRouteHandler } from '@safeform/next'
import { upsertEmployeeSchema } from './schema'

const upsertEmployeeAction = authedAction.create({ schema: upsertEmployeeSchema }, async (data, ctx) => {
  return { success: true as const, data: { employeeId: 'emp-1' } }
})

export type UpsertEmployeeAction = typeof upsertEmployeeAction
export const POST = createRouteHandler(upsertEmployeeAction)

The route handler takes care of:

  • Parsing and validating the JSON request body against your action's schema
  • Running the middleware chain (auth, logging, etc.)
  • Parsing and validating the payload if your action defines one
  • Returning structured JSON responses the client can consume
  • Catching unexpected errors and returning a safe 500 response

Request Format

The client (useForm from @safeform/core) posts JSON in this shape:

{ "data": { ...formValues }, "payload": { ...payloadValues } }

payload is omitted if the action has no payload schema.


Response Format

All responses are JSON:

// Success
{ "success": true, "data": { ...handlerReturnData } }

// Validation failure
{ "success": false, "fieldErrors": { "fieldName": ["error message"] } }

// Global error
{ "success": false, "error": "error message" }

// Unexpected server error
{ "success": false, "error": "Internal server error" }

Multi-Step Forms

createRouteHandler handles both unnamed (tuple) and named (createSteps) multi-step schemas automatically. No extra configuration needed.


Full Example

// app/api/employees/schema.ts
import { z } from 'zod'

export const upsertEmployeeSchema = z.object({
  firstName: z.string().min(1),
  lastName: z.string().min(1),
  role: z.enum(['Admin', 'Cashier', 'Janitor']),
})

// app/api/employees/route.ts
import { createAction } from '@safeform/core'
import { createRouteHandler } from '@safeform/next'
import { upsertEmployeeSchema } from './schema'
import { z } from 'zod'

const authedAction = createAction().use(async (ctx) => {
  const session = await getSession()
  if (!session) throw new Error('Unauthorized')
  return { ...ctx, user: session.user }
})

const upsertEmployeeAction = authedAction.create({
  schema: upsertEmployeeSchema,
  payload: z.object({ employeeId: z.string().optional() }),
}, async (data, payload, ctx) => {
  const employee = await db.employee.upsert({ ... })
  return { success: true as const, data: { employeeId: employee.id } }
})

export type UpsertEmployeeAction = typeof upsertEmployeeAction
export const POST = createRouteHandler(upsertEmployeeAction)

License

MIT