Documentation Index
Fetch the complete documentation index at: https://kubo-47e69177.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Middleware
beforeAction
Use beforeAction for authorization checks, audit prep, or guard clauses.
import { defineAction } from "@zapaction/core";
import { z } from "zod";
type AppContext = { userId: string; role: "admin" | "user" };
export const archiveTodo = defineAction<
{ id: string },
{ ok: true },
AppContext
>({
input: z.object({ id: z.string() }),
output: z.object({ ok: z.literal(true) }),
beforeAction: async ({ ctx }) => {
if (ctx.role !== "admin") {
throw new Error("Forbidden");
}
},
handler: async () => ({ ok: true })
});
afterAction
Use afterAction to sanitize or shape the final response.
import { defineAction } from "@zapaction/core";
import { z } from "zod";
export const getUser = defineAction({
input: z.object({ id: z.string() }),
output: z.object({ id: z.string(), email: z.string() }),
afterAction: async ({ result }) => ({
...result,
email: result.email.toLowerCase()
}),
handler: async ({ input }) => ({
id: input.id,
email: "USER@EXAMPLE.COM"
})
});
Order of execution
input.parse
resolveActionContext
beforeAction
handler
afterAction
output.parse
revalidateTags