/kavo-skills:policyfrom Kavo Developer Skills
Reference for Kavo's policy authorization DSL — permission(), role(), owner(), authenticated(), filtered(), when() composed with and()/or()/not(). Use when gating operations with 403 responses or requiring authentication.
Ships in Kavo Developer Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
policy refuses a request before its handler runs. Each standard operation
on an entity can carry a rule evaluated against context.principal and,
when the rule needs it, the loaded row — a rule that fails answers 403
with KAVO_FORBIDDEN. Full detail: docs/features/policy.md and
ADR-0032/ADR-0033.
Wiring context.principal itself is the global-config/kavo-decorator
skills' territory (an app's own auth layer) — policy only ever reads it.
import { and, authenticated, filtered, or, owner, permission, role } from "@kavo/core";
@Kavo(Post, {
operations: {
createOne: { policy: authenticated() },
findMany: { policy: permission("post:read") },
findOne: { policy: or(role("admin"), owner("authorId")) },
updateOne: { policy: and(permission("post:update"), owner("authorId")) },
},
})
policy is set per operation, at operations.<id>.policy — there is no
entity-scope policy map (ADR-0033; a leftover root-level policy map
fails at bootstrap, naming this path as the replacement). An operation with
no policy entry is unrestricted — opt-in per operation, not a global
switch. policy takes a PolicyNode only — build multi-permission checks
with and(permission("a"), permission("b")) (ADR-0032, amended by #242: the
array shorthand was removed since the DSL already covers everything it
could express).
| Node | Passes when |
|---|---|
permission(name) | principal.permissions contains name |
role(name) | principal.roles contains name |
authenticated() | principal.userId is set |
owner(field = "userId") | the row's field equals principal.userId; owner("author.id") walks a nested value |
filtered(field) | context.query.filter carries a condition on field, anywhere in the AST |
when(({ context, entity, resource, operation, params }) => ...) | the predicate returns true — escape hatch for anything else |
and(...) / or(...) / not(...) | short-circuit composition; not negates its single child |
Every built-in node except filtered/when reads context.principal cast
to { userId?, roles?, permissions?, [k: string]: unknown }. Kavo never
inspects or shapes principal itself — a null principal (no auth wired
yet) makes every built-in node except filtered deny.
filtered(field) — require a query filter, not a principal check@Kavo(Post, {
operations: { findMany: { policy: and(authenticated(), filtered("userId")) } },
})
GET /posts?filter[userId][eq]=u-1 passes; a bare GET /posts 403s. Unlike
every other built-in, filtered reads context.query, not principal —
it is context-only (not entity-aware), so it is legal on createOne and
findMany where owner/when are rejected at bootstrap. context.query
is null on writes, so filtered denies unconditionally there rather than
throwing — it's meant for reads.
filtered gates whether the operation runs at all; it is not
row-scoping. A caller who supplies userId still sees every row that
filter matches, not only their own — pair it with owner/when (or an
app-level default filter you add yourself) when the requirement is "only
your own rows," not just "some filter is present."
owner/when — entity-aware, single-row operations onlyowner and when need the loaded row, so they're legal only on
findOne, updateOne, patchOne, deleteOne, restoreOne, purgeOne.
Configuring either on createOne (no row yet) or findMany (a set, not
one row) is a bootstrap ConfigurationException naming the entity and the
operations.<id>.policy path. An owner(field) whose first dotted segment names a
relation (owner("author.id")) is the same error — the pre-fetch loads no
relations, so it could never pass.
when() is the one node that can reach a relation itself, through
context.repository, since its predicate runs with the full context.
The policy stage runs after context is built, before preconditions and the
cache — a denied request never learns whether its If-Match would have
succeeded. A context-only rule (permission/role/authenticated/
filtered) costs a lookup plus a boolean check. A row-needing rule on a
write costs one extra read: the stage pre-fetches the row (including
soft-deleted, since restoreOne/purgeOne target a deleted row by
definition) before the handler runs. No row found → 404, never 403 —
the status code must not leak whether the row exists.
findOne is the exception to the pre-fetch: it already loads the row as
its own result, so a row-needing rule runs after the handler, against
what it fetched — and an entity whose findOne rule needs the row is
never cached, so a cache hit can't skip the deferred check.
findMany still returns every row its query
matches; policy decides whether the call runs, not what a passing
call sees.KavoSettings, policy
lives outside the precedence chain — no global default, and no per-call
override (a per-call parameter that could loosen a rule would let a
caller weaken its own authorization).policy entry — their handler reaches
context.principal directly and throws ForbiddenException for the same
403 KAVO_FORBIDDEN.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub kavo-labs/kavo --plugin kavo-skills15 skills in this plugin
/composite-primary-keysReference for composite primary key support in @kavo/typeorm — the compositeIdFields metadata field, the ~-delimited route-id encoding, the creatable/updatable split, and every place composite keys don't yet work (other ORM adapters, many-to-many array-mutation, @kavo/graphql). Use when an entity has more than one @PrimaryColumn, or when a route id, association, or array-mutation write on such an entity behaves unexpectedly./dto-slotsReference for Kavo's six optional schema slots (create/update/patch/query/item/list) — entity-derived defaults, the schemaShapeKeys narrowing rule, and serialization order. Use when configuring a DTO class or validator on @Kavo's schema option, or answering "why isn't my field showing/hiding" or "what shape does this response have" questions./error-handlingReference for Kavo's exception hierarchy, KAVO_* error-code catalog, and the RFC 9457 problem-details wire shape every generated route returns on failure. Use when handling/mapping a Kavo error, deciding which exception to throw from a custom handler/@Override, or answering "what does the error response look like" questions./global-configReference for Kavo's global configuration — the KavoSettings precedence chain, built-in defaults table, KavoModule.forRoot/forRootAsync options, and the operations.<id> global-default caveat (ADR-0015). Use when wiring createKavo/KavoModule.forRoot, setting app-wide defaults, or answering "what can I configure globally" questions./graphql-bindingReference for @kavo/graphql and its Nest binding — building a schema over an existing createCrud service, the raw-AST filter/sort args, multi-entity merging, the process-wide type registry, and the zero-code KavoModule graphql option. Use when exposing an entity over GraphQL, or answering "how do I add GraphQL to this entity" questions./kavo-decoratorReference for what @Kavo(Entity, config?) generates and how to configure/override it — routes table, EntityConfig shape (schema/allowed/operations), manual-method-wins, @Override, and fully custom routes. Use when writing or reviewing a @Kavo-decorated controller, or answering "how do I configure/override this route" questions.Other plugins' skills for the same job