StepCondition

Conditions determine whether a step should execute based on the output of previous steps or trigger data.

Usage

There are three ways to specify conditions: function, query object, and simple path comparison.

1. Function Condition

workflow.step(processOrder, {
  when: async ({ context }) => {
    const auth = context?.getStepPayload<{status: string}>("auth");
    return auth?.status === "authenticated";
  }
});

2. Query Object

workflow.step(processOrder, {
  when: {
    ref: { step: 'auth', path: 'status' },
    query: { $eq: 'authenticated' }
  }
});

3. Simple Path Comparison

workflow.step(processOrder, {
  when: {
    "auth.status": "authenticated"
  }
});

Based on the type of condition, the workflow runner will try to match the condition to one of these types.

  1. Simple Path Condition (when there’s a dot in the key)
  2. Base/Query Condition (when there’s a ‘ref’ property)
  3. Function Condition (when it’s an async function)

StepCondition

ref:

{ stepId: string | 'trigger'; path: string }
Reference to step output value. stepId can be a step ID or 'trigger' for initial data. path specifies location of value in step result

query:

Query<any>
MongoDB-style query using sift operators ($eq, $gt, etc)

Query

The Query object provides MongoDB-style query operators for comparing values from previous steps or trigger data. It supports basic comparison operators like $eq, $gt, $lt as well as array operators like $in and $nin, and can be combined with and/or operators for complex conditions.

This query syntax allows for readable conditional logic for determining whether a step should execute.

$eq:

any
Equal to value

$ne:

any
Not equal to value

$gt:

number
Greater than value

$gte:

number
Greater than or equal to value

$lt:

number
Less than value

$lte:

number
Less than or equal to value

$in:

any[]
Value exists in array

$nin:

any[]
Value does not exist in array

and:

StepCondition[]
Array of conditions that must all be true

or:

StepCondition[]
Array of conditions where at least one must be true

MIT 2025 © Nextra.