Skip to content

The open alternative to Salesforce, designed for AI.

1.9 KB
Raw Blame
import { z } from 'zod';
import { baseTriggerSchema } from './base-trigger-schema';
import { stepFilterGroupSchema } from './step-filter-group-schema';
import { stepFilterSchema } from './step-filter-schema';

export const workflowDatabaseEventTriggerSchema = baseTriggerSchema
  .extend({
    type: z.literal('DATABASE_EVENT'),
    settings: z.object({
      eventName: z
        .string()
        .regex(
          /^[a-z][a-zA-Z0-9_]*\.(created|updated|deleted|upserted)$/,
          'Event name must follow the pattern: objectName.action (e.g., "company.created", "person.updated", "company.upserted")',
        )
        .describe(
          'Event name in format: objectName.action (e.g., "company.created", "person.updated", "task.deleted", "company.upserted"). Use lowercase object names.',
        ),
      input: z.looseObject({}).optional(),
      outputSchema: z
        .looseObject({})
        .describe(
          'Schema defining the output data structure. For database events, the record that triggered the workflow is under properties.after (properties.before for deleted events) and is accessible via {{trigger.properties.after.fieldName}}.',
        ),
      objectType: z.string().optional(),
      fields: z.array(z.string()).optional().nullable(),
      filter: z
        .object({
          stepFilterGroups: z.array(stepFilterGroupSchema),
          stepFilters: z.array(stepFilterSchema),
        })
        .optional()
        .describe(
          'Optional condition evaluated against the triggering record. The workflow only runs when the record matches; non-matching events are skipped before a run is created.',
        ),
    }),
  })
  .describe(
    'Database event trigger that fires when a record is created, updated, deleted, or upserted. The triggered record is accessible in workflow steps via {{trigger.properties.after.fieldName}}, or {{trigger.properties.before.fieldName}} for deleted events.',
  );