> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Automations

> Let editors map occurrences to actions, with typed conditions, delays and review.

`@bijectionhq/library-automations` turns an occurrence into a run of one of
your mutations. Rules are facts editors save; the trigger contracts and the
actions are your code.

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label } from "@bijectionhq/bijection";
import { automations } from "@bijectionhq/library-automations";
import { approvals } from "./mounts";
import { escalate, notifyOwner } from "./actions";
import { editor, viewer } from "./roles";

export const ops = automations({
  label: label.public,
  triggers: {
    "ticket.opened": {
      priority: { type: "string", nullable: false },
      amount: { type: "decimal", nullable: true, scale: 2 },
    },
  },
  actions: { escalate, notifyOwner },
  editors: [editor],
  viewers: [viewer],
  approvals,
});

export default app({ ops, approvals, actions: { escalate, notifyOwner } });
```

* **Rules** (`ops.tables.rules`) hold a trigger kind, typed `where` clauses
  over the trigger's payload contract, an action name, an argument mapping,
  a delay, an optional review requirement and an enabled flag. Editors call
  `ops.rules.save`, `setEnabled` and `archive`. Each save is a new revision,
  checked against the revision the editor saw.
* **Offer.** Your code calls `ops.offer(ctx, { kind, key, payload })` in the
  transaction that makes the occurrence true. Each matching enabled rule
  submits its action as a function task with
  `once: ["run", rule, revision, occurrence]`, so offering the same
  occurrence again answers the original task. The rule's delay is the
  task's `due`. Clients holding `offerers` (editors by default) offer
  through `ops.occurrences.offer`.
* **Review.** A rule with `review` first [asks the Approvals app](https://docs.bijection.com/operations/review.md).
  Its continuation submits the action only when the decision is `approved`
  and the rule still stands at the reviewed revision.
* **Runs** (`ops.tables.runs`) hold one fact per run. `ops.runs.state` answers
  the run's task state: the action's, or the review's while it waits.

An action is an ordinary mutation run as a function task, at its own
`under`. It holds no roles, so its authority is its commit label. It
validates its own arguments when it runs.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.