[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationExtending

Extending

Declare your own triggers, actions and data nodes from any module through the automation interface, ship procedures as code, and start them from code.

Any module can add nodes to the automation builder. The contract lives in a separate package, @antelopejs/interface-dms-automation, which @antelopejs/dms-automation implements. A module that declares nodes depends on the interface only, never on this module.

Add the interface

Pick the dependency type by how much your module needs automation:

Dependency typeUse whenWithout the automation module
optionalDependenciesYour nodes are a bonus.Registrations wait until an implementation attaches.
dependenciesYour module needs automation to work.Automation is required.

For optional nodes, add the interface to optionalDependencies:

package.json json
{
  "optionalDependencies": {
    "@antelopejs/interface-dms-automation": ">=0.7.0 <1.0.0"
  }
}

Keep this consumer range wide, so that every module in a project shares one copy of the interface. The module implements the interface through a narrower range, listed in the compatibility table of its README.

Declare an action

Register the action in start() and unregister it in stop(). This example adds a trace marker. It does not call an external service or log its input.

src/automation.ts ts
import { RegisterActionType, UnregisterActionType } from "@antelopejs/interface-dms-automation";

const ACTION_ID = "example.trace-marker";

export function registerAutomationNodes(): void {
  RegisterActionType({
    id: ACTION_ID,
    name: "Record trace marker",
    description: "Record that this step was reached",
    icon: "i-lucide-file-text",
    inputSchema: { type: "object" },
    outputSchema: { type: "object", properties: { recorded: { type: "boolean" } } },
    async execute(_input, ctx) {
      ctx.log("info", "Trace marker reached");
      return { recorded: true };
    },
  });
}

export function unregisterAutomationNodes(): void {
  UnregisterActionType(ACTION_ID);
}

The builder lists the node in its palette under the name of the module that registered it. It builds the node's inputs from inputSchema and gives the node one output port per outputSchema property.

Make a test run safe

Test run in the builder tries a draft. To tell it what your action does outside the run, declare one of two members:

  • For an action that only reads or computes, set sideEffects: false. A test runs it as is, without asking.
  • For an action that sends, writes or calls a service, add dryRun(input, ctx). A test calls it instead of execute. It must do nothing and resolve to a plausible output in the shape of outputSchema, so the steps after it still run.
src/automation.ts ts
import { RegisterActionType } from "@antelopejs/interface-dms-automation";

declare function sendWelcome(to?: string): Promise<string>;

RegisterActionType({
  id: "example.send-welcome",
  name: "Send welcome e-mail",
  description: "E-mail a welcome message to a new member",
  icon: "i-lucide-mail",
  inputSchema: { type: "object", properties: { to: { type: "string" } } },
  outputSchema: { type: "object", properties: { messageId: { type: "string" } } },
  async dryRun(input: { to?: string }, ctx) {
    ctx.log("info", `Would e-mail ${input.to ?? "nobody"}`);
    return { messageId: "dry-run" };
  },
  async execute(input: { to?: string }) {
    return { messageId: await sendWelcome(input.to) };
  },
});

If you declare neither member, sideEffects defaults to true and the action acts for real in a test. Before the test starts, the builder lists the step and asks the user to confirm it. The API refuses the test until then. ctx.dryRun is true throughout a test run, for code that needs to tell a test from a real run. Run now, triggers and RunProcedure always call execute. An implementation without dry-run support ignores both members and runs execute.

Node kinds

Pick the node kind by the job it does:

  • A trigger starts a run.
  • An action does asynchronous I/O.
  • A data node computes values synchronously, with no side effects.

The consumer reference lists the required members, the schemas, the lifecycle and the execution context of each kind.

Trigger clustering

Set the trigger's cluster mode by where it must fire:

  • singleton activates on the leader only.
  • replicated activates on every instance.

Run a procedure from code

To run a saved procedure that has a manual trigger, call InvokeProcedure:

ts
import { InvokeProcedure } from "@antelopejs/interface-dms-automation";

const runId = await InvokeProcedure(procedureId, { orderId: "10477" });

A run ID does not prove that the run succeeded. Read the run's recorded outcome.

To run any procedure now, whatever starts it (a schedule, a webhook or a trigger your module registers), call RunProcedure. It runs the procedure as Run now does in the builder and returns how the run ended:

ts
import { RunProcedure } from "@antelopejs/interface-dms-automation";

const { runId, status, errorMessage } = await RunProcedure("reports.weekly", {
  payload: { firedAt: new Date().toISOString() },
});

Without payload, the trigger receives the payload of the newest real run that kept one (test runs excluded, among the last 50 runs), or {}. Set triggerNodeId to pick the trigger to start from. The invocation contract gives the return values, the failures and the caller's authorization duties.

Ship procedures as code

A project or a module can ship its own procedures, such as the automations a template provides, with DeclareProcedure. Call it from start():

src/automation.ts ts
import { DeclareProcedure } from "@antelopejs/interface-dms-automation";
import followUpQuotes from "./procedures/quote-follow-up.json";

export async function start(): Promise<void> {
  await DeclareProcedure({
    id: "bakery.quote-follow-up",
    name: followUpQuotes.name,
    description: followUpQuotes.description,
    graph: followUpQuotes.graph,
    enabled: true,
  });
}
  1. Design the procedure in the builder.
  2. Export it with Export JSON.
  3. Keep the file in your project and pass its fields to DeclareProcedure.

The id is yours and becomes the procedure's ID. The call creates the procedure once, when no procedure has that ID, and never touches it again. A changed declaration is not applied, and what users do in the builder stays. After storage, the module reconciles the eligible triggers, singleton triggers on the leader and replicated triggers on every instance. The declaration contract gives the validation and the creation rule.

Do not insert rows in the module's tables yourself. The module does not arm a procedure written behind its back until the next restart, and the rows tie your project to an internal schema.

Fire on changes to your own tables

The Table watch trigger of @antelopejs/dms-database (database.table-watch) starts a procedure on each insert, update or delete in any registered table, your project's included. Set schema to the ID you pass to RegisterSchema and table to the table name.

Warning

The trigger reads the database change feed, and MongoDB has one only on a replica set. On a standalone server, the procedure shows as Failing with "$changeStream is only supported on replica sets". In development, start MongoDB as a single-node replica set (mongod --replSet rs0, then rs.initiate() once) and add replicaSet=rs0 to the connection string. A hosted cluster is always a replica set.

The trigger's output carries the row before and after the change, so the procedure can read your columns, a tenantId included. The execution context of an action has no tenant. To act on tenant data from your own action, declare tenantId as an input and wire it from that output.

Nodes from other modules

These modules register nodes when the automation module is loaded:

ModuleNodes
@antelopejs/dmsTriggers: member added and removed, invite created, user registered, record created, updated and deleted. Actions: send email, send notification, invite user.
@antelopejs/dms-databaseTrigger: table watch.
@antelopejs/dms-apiTrigger: route unhealthy. Actions: get API health, query request logs.

Role permissions

The module's pages are DMS blocks around a few module components with the DmsAutomation prefix. Each block carries a .meta() name, so the DMS roles screen lists it. The pages, like every DMS module page, and the module's API under /api/automation are reserved to the platform owner.