Catalog npm
Back to packageRELEASE DETAILS

0.4.0

npm

@021.is/spine-actions

Type-safe server-action helper: zod input validation + auth check + audit + auto revalidatePath, returning ResponseDto.

Published28 May 2026
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

@021.is/spine-actions

Type-safe server-action helper. Bakes zod input validation + auth + audit + revalidatePath into one wrapper. Always returns ResponseDto<T | null>.

Use

"use server";
import { defineAction } from "@021.is/spine-actions";
import { z } from "zod";
import { requireUser } from "@/lib/auth";
import { publishEvent } from "@/feature/event";

export const publishEventAction = defineAction({
  input: z.object({ eventId: z.string().min(1) }),
  auth: requireUser,
  audit: (input, principal) => ({
    action: "event.publish",
    targetId: input.eventId,
    actorId: principal.sub,
  }),
  auditor: async (row) => db.audit.create({ data: row }),
  revalidate: (input) => [`/events/${input.eventId}`, "/events"],
  onRevalidate: revalidatePath,
  handler: async ({ input, principal }) => publishEvent(input, { userId: principal.sub }),
}).run;

What the wrapper does in order: parse zod → run auth → run handler → audit on success → call onRevalidate for every returned path → wrap result in ok(...). Any thrown spine-errors exception (BadRequestException, ForbiddenException, etc.) maps to the correct ResponseDto envelope.

Why

  • One pattern for every server action across your app
  • Zod parsing failures become 400 BadRequest with translation keys, not raw stack traces
  • Audit happens only on success (no half-states)
  • Revalidation hook makes "force-dynamic" pages refresh after writes
  • Tested in isolation: await action.run({ ... }) returns a typed ResponseDto, no Next.js context needed

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
zod
Environment
{
  "local_name": "zod",
  "alias": false,
  "peer_metadata": null
}
^3.23.8runtime
@021.is/spine-errors
Environment
{
  "local_name": "@021.is/spine-errors",
  "alias": false,
  "peer_metadata": null
}
^0.4.0runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "fc6b57d3078b675b2ae9a5753e1ee518c5e9d008",
  "tarball": "https://registry.npmjs.org/@021.is/spine-actions/-/spine-actions-0.4.0.tgz",
  "fileCount": 4,
  "integrity": "sha512-OTE8ytBwrJWKm3SC9GUxQ2Scgh+igwZI6yagzL0kPM8rZq5/hGDJ56fsaw8ZsTRgkTlflgccbXFtkJg1IvX0ww==",
  "signatures": [
    {
      "sig": "MEYCIQCsJC5r8zklZGkVbMvRB55Z9F4b4mvsYB/TKrVzXidg1wIhAIiGP7rZ9m4HVES5X7WFgQiEK6dg7u2K5RH2qDENm3gK",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 5986
}

Repository

PENDING
021is/spine-ts

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:00 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:cc07b07f63e0b747b6140e967ffdf01789ae1f66d5a809c8d6679b0d7f3abf0e

Other collected versions

0.4.328 MayView all collected versions →