ObjectStackObjectStack

Hook Body

Hook Body protocol schemas

Capability tokens a script body may request.

The runtime sandbox enforces these — if a body uses a ctx API that requires

a capability it did not declare, the call throws at invocation time.

  • api.readctx.api.object(...).find / findOne / count / aggregate

  • api.writectx.api.object(...).insert / update / delete

  • crypto.uuidctx.crypto.randomUUID()

  • crypto.hashctx.crypto.hash(algo, data)

  • logctx.log.info / warn / error

http.fetch is intentionally absent — outbound calls go through Connector

recipes (separate spec) so they remain auditable and replayable.

Source: packages/spec/src/data/hook-body.zod.ts

TypeScript Usage

import { ExpressionBody, HookBody, HookBodyCapability, ScriptBody } from '@objectstack/spec/data';
import type { ExpressionBody, HookBody, HookBodyCapability, ScriptBody } from '@objectstack/spec/data';

// Validate data
const result = ExpressionBody.parse(data);

ExpressionBody

L1 expression body — pure formula, no IO

Properties

PropertyTypeRequiredDescription
languagestring
sourcestringFormula expression source

HookBody

Hook/Action body — expression (L1) or sandboxed JS (L2)

Union Options

This schema accepts one of the following structures:

Option 1

L1 expression body — pure formula, no IO

Properties

PropertyTypeRequiredDescription
languagestring
sourcestringFormula expression source

Option 2

L2 sandboxed JS body — runs inside an isolated VM with declared capabilities

Properties

PropertyTypeRequiredDescription
languagestring
sourcestringFunction body source
capabilitiesEnum<'api.read' | 'api.write' | 'crypto.uuid' | 'crypto.hash' | 'log'>[]Granted capability tokens
timeoutMsintegeroptionalPer-invocation timeout (ms)
memoryMbintegeroptionalPer-invocation memory cap (MB)


HookBodyCapability

Allowed Values

  • api.read
  • api.write
  • crypto.uuid
  • crypto.hash
  • log

ScriptBody

L2 sandboxed JS body — runs inside an isolated VM with declared capabilities

Properties

PropertyTypeRequiredDescription
languagestring
sourcestringFunction body source
capabilitiesEnum<'api.read' | 'api.write' | 'crypto.uuid' | 'crypto.hash' | 'log'>[]Granted capability tokens
timeoutMsintegeroptionalPer-invocation timeout (ms)
memoryMbintegeroptionalPer-invocation memory cap (MB)

On this page