auth/cell_actions.ts

Generic cell RPC action handlers.

The generic request_response actions bound to the specs in auth/cell_action_specs.ts:

  • Mutations: cell_create, cell_update, cell_delete, cell_clone, cell_moderate, cell_policy_set.
  • Reads: cell_get, cell_list.

Authorization model:

  • cell_create is authenticated at the spec level. The handler stamps created_by from auth.actor.id. path writes are admin-only — non-admin callers supplying path get ERROR_CELL_PATH_ADMIN_ONLY.
  • cell_get is optional auth at the spec level. Per-row authorization via can_view_cell(auth, cell). Misses + unauthorized reads both 404, so private-cell existence doesn't leak through the wire. Bundled relations are filtered to viewable targets (strict target-visibility).
  • cell_update / cell_delete are authenticated at the spec level with per-row can_edit_cell enforcement. path writes on update are admin-only; visibility writes require the manage tier (can_manage_cell).
  • cell_policy_set is the one writer of a root's contribution policy past its create — manage-tier, root-only, and validated by the mounted authorize_create (the authorizer that interprets the policy is what accepts one; none mounted refuses every non-null policy). cell_update never touches it.
  • cell_list is optional auth at the spec level. The SQL-side visibility predicate in query_cell_list admits null auth to public-only rows and authed callers to owned + public + grant-admitted rows; admin sees all. SQL-side because post-filtering in JS would silently truncate pages. The handler rejects the created_by filter for null auth (account-id enumeration guard).
  • cell_create, cell_update, and cell_clone gate the fact refs their data introduces on possession: a non-admin write may add a ref only to a fact its acting actor holds, else 403 ERROR_CELL_REF_NOT_HELD — answered from fact_holder rows alone, so it says nothing about whether a fact exists. Refs a cell (or a clone's source row) already carries stay admitted. The last gate before the write; see auth/cell_ref_admission.ts.

Mutations emit cell_create / cell_update / cell_delete audit events via deps.audit.emit(...). The AuditLogConfig threaded through the consumer's audit_factory (see create_app_backend) must declare the cell event types (see auth/cell_audit_metadata.ts).

App vocabulary (e.g., collection / entry kinds) lives in client-side helpers and per-app validate_data deps — this layer is generic-only by construction.

view source

Declarations
#

6 declarations

CellActionDeps
#

auth/cell_actions.ts view source

CellActionDeps

type ActionFactoryDeps & { validate_data?: ((kind: string | null, data: Readonly<{ label?: string | undefined; summary?: string | undefined; } & Record<string, unknown>>) => void) | undefined; authorize_create?: CellCreateAuthorize | undefined; }

import type {CellActionDeps} from '@fuzdev/fuz_app/auth/cell_actions.js';

Dependencies for create_cell_actions.

validate_data is the optional sub-API hook for per-kind shape validation (e.g., a collection/entry registry), the TS twin of the Rust CellDataValidator. It is called as (kind, data) — kind is the cell's top-level kind column, so it dispatches on it: the input's on create, the existing cell's on an update carrying data (kind is write-once), the source's for every row a clone writes (on the merged data). It accepts or throws, never rewrites: the handler stores the caller's data as sent, and it must not mutate it. A thrown SchemaError (parse_or_throw) becomes the standard invalid_params JSON-RPC error so per-kind validation failures surface to clients with code -32602 (not -32603 / internal); throw a JsonrpcError (jsonrpc_errors.invalid_params with a reason) to choose the reason. When omitted, payloads pass through as-is.

authorize_create is the optional creation-gate hook (see CellCreateAuthorize). When omitted, create is open, and every non-null root policy write is refused.

log

Structured logger instance.

type Logger

audit

Bound audit emitter for audit writes.

type AuditEmitter

validate_data?

type (kind: string | null, data: Readonly<{ label?: string | undefined; summary?: string | undefined; } & Record<string, unknown>>): void

kind

type string | null

data

type Readonly<CellData>
returns void

authorize_create?

type CellCreateAuthorize

CellCreateAuthorize
#

auth/cell_actions.ts view source

CellCreateAuthorize import type {CellCreateAuthorize} from '@fuzdev/fuz_app/auth/cell_actions.js';

Opt-in, parent-aware creation authorizer — the TS twin of the Rust CellCreateAuthorize trait, its two members the trait's two methods. Omitted = open create, and every non-null policy write refused ERROR_CELL_POLICY_UNSUPPORTED.

  • authorize gates both roots (parent_id = null) and contributions; answers "may *this actor* create *this kind* here?" and returns a CellCreateVerdict. Runs in cell_create after validate_data and after the handler resolves root_id and root_policy from the parent (an unviewable parent or a missing or soft-deleted root already 404-masks before this runs). ctx is the request's: cell_create and cell_clone have side effects, so ctx.db is the request transaction, and an impl needing more than root_policy (a content pre-screen, say) reads through it. Read-only — the authorizer decides, it never writes; a write would commit or roll back with the create, and nothing enforces this but the impl.
  • validate_policy accepts or refuses a root policy before it is written (a root's cell_create, cell_policy_set) — the shape authorize reads. It runs after the manage and root-only gates, so it decides validity, never authority: throw jsonrpc_errors.invalid_params with ERROR_CELL_POLICY_INVALID (or a reason of the consumer's), or a SchemaError, which the handler turns into invalid_params. Omitted refuses every policy (ERROR_CELL_POLICY_UNSUPPORTED, the Rust trait's default): an authorizer that reads no policy stores none.

authorize

type (auth: RequestActorContext, input: CellCreateAuthorizeInput, ctx: ActionContext): CellCreateVerdict | Promise<...>

auth

input

ctx

validate_policy?

type (policy: {} & Record<string, unknown>): void

policy

returns void

CellCreateAuthorizeInput
#

auth/cell_actions.ts view source

CellCreateAuthorizeInput import type {CellCreateAuthorizeInput} from '@fuzdev/fuz_app/auth/cell_actions.js';

Input to CellCreateAuthorize.authorize — the TS twin of the Rust CellCreateAuthorizeInput. Parent-aware: it carries the directory context (parent_id / the handler-resolved root_id) and the governing root's policy, so the authorizer resolves the rule that applies.

kind

The cell's kind (the top-level cell.kind value); null for a typeless cell.

type string | null

data

The cell data (kind-free — a kind key is rejected upstream). For richer M3-era policies (e.g. content pre-screen).

type CellData

parent_id

The immediate container the create targets. null = a root creation; otherwise a contribution under that parent.

type Branded | null

parent_kind

The immediate container's kind column, read by the handler with the parent — so an authorizer checks the parent → child edge (which kinds may sit under which) without a read of its own. null for a root creation and for a typeless parent.

type string | null

root_id

The governing root of the directory subtree, resolved by the handler from the parent (parent.root_id ?? parent.id). null for a root creation.

type Branded | null

root_policy

The governing root's contribution policy column — the handler reads the root in-tx and hands its policy over, so a directory-aware authorizer resolves root_policy[kind] without a DB read of its own. null for a root creation and for a root carrying no policy (the authorizer's floor governs); a missing or soft-deleted root answers cell_not_found before the authorizer runs. Never the root's data: an editor grant can rewrite data, so a policy read from it would be the editor's to loosen.

type CellPolicy | null

CellCreateVerdict
#

auth/cell_actions.ts view source

CellCreateVerdict

type { allow: false; } | { allow: true; moderation_required: boolean; }

import type {CellCreateVerdict} from '@fuzdev/fuz_app/auth/cell_actions.js';

An authorizer's decision for a cell_create — the TS twin of the Rust Verdict. Folds the moderation outcome into the authority decision (one policy resolution, not two): {allow: false} denies (the handler surfaces a 403 forbidden for a viewable parent / a root creation), `{allow: true, moderation_required} admits — true → born pending + private, false` → born approved at the author's visibility.

create_cell_actions
#

to_cell_json
#

auth/cell_actions.ts view source

(row: CellRow): { kind: string | null; data: { label?: string | undefined; summary?: string | undefined; } & Record<string, unknown>; id: Branded<string, "Uuid">; ... 12 more ...; grant_count: number; } import {to_cell_json} from '@fuzdev/fuz_app/auth/cell_actions.js';

row

type CellRow

returns

CellJson

Depends on
#

Imported by
#