# Vectry Event Subscription

> Trigger workflow execution based on internal system events (Event Bus).

Source: https://docs.sommatic.ai/en/nodes/event.trigger/

- Slug: `event.trigger`
- Family: Triggers
- Version: 1.0.0
- Status: Experimental. Nothing subscribes to the event bus yet, so the trigger never starts a run by itself; `filters` and `since` are not read.
- Execution: async

Trigger workflow execution based on internal system events (Event Bus).

This trigger subscribes to the Vectry Causal Event Bus. It listens for specific business or system events (e.g., "Order Created", "User Signup") and initiates the workflow when a matching event occurs.

**Features:**
- **Filtering:** Subscribe only to events matching specific criteria (domain, entity, tag).
- **Replay:** Process historical events ("since") or only new ones.
- **Pattern Matching:** Trigger on complex event sequences (if configured).

**Use Cases:**
- Sending a Welcome Email when a 'UserCreated' event occurs.
- Auditing high-value transactions.

## Configuration

- `filters` (array<object>, required): Match criteria for events.
- `since` (string, optional): Timestamp (ISO) or "now". Default: `now`.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `out` (default): Event Received
- `error`: Error

## Output contract

- `event_id` (string, optional)
- `source` (string, optional)
- `type` (string, optional)
- `payload` (object, optional)

## In expressions

What a later node can read from this node's output with `$("Vectry Event Subscription").item.json.<path>` (write your node's label instead of `Vectry Event Subscription`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Vectry Event Subscription").item.json.event_id` (string) = `"evt_01JDX4Q8M2"`
- `$("Vectry Event Subscription").item.json.source` (string) = `"vectry"`
- `$("Vectry Event Subscription").item.json.type` (string) = `"order.created"`
- `$("Vectry Event Subscription").item.json.payload` (object) = `{…}`
- `$("Vectry Event Subscription").item.json.payload.order_id` (string) = `"ord_123"` (Not suggested by the editor)
- `$("Vectry Event Subscription").item.json.payload.total` (number) = `129.99` (Not suggested by the editor)
- `$("Vectry Event Subscription").item.json.payload.currency` (string) = `"USD"` (Not suggested by the editor)


## How it works

Entry node for event-driven workflows. It reshapes the run's input into `{ event_id, source, type, payload }`; in this version it does not subscribe to the event bus and its filters are not applied.

1. What starts it: no backend component subscribes to the event bus for this node in this version. The workflow runs when it is started explicitly (a manual run or an execution request) with an event-shaped input.
2. Reads the incoming item as is; the node config is not read or resolved.
3. Outputs `event_id` (default `unknown`), `source` (default `vectry`), `type` (default `unknown`) and `payload`: the input's `payload` field when present, otherwise the whole input.

## In a workflow

### Node

```json
{
  "node_id": "node-order-created",
  "label": "Order created",
  "operator_slug": "event.trigger",
  "operator_version": "1.0.0",
  "config": {
    "filters": [
      {
        "system_domain": "sales",
        "system_entity": "order",
        "operation": "created"
      }
    ],
    "since": "now"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "event_id": "evt_01JDX4Q8M2",
    "source": "vectry",
    "type": "order.created",
    "payload": {
      "order_id": "ord_123",
      "total": 129.99,
      "currency": "USD"
    }
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

Always, unless an unexpected exception occurs.

```json
{
  "event_id": "evt_01JDX4Q8M2",
  "source": "vectry",
  "type": "order.created",
  "payload": {
    "order_id": "ord_123",
    "total": 129.99,
    "currency": "USD"
  }
}
```

### `error`

Only on an unexpected exception while reading the input; the output is `{ error, response }`. Not reachable in normal use.

```json
{
  "error": "<exception message>",
  "response": null
}
```

## Behaviour in the code

- `filters`: Declared and required by the schema but not read: no event filtering happens. `since` is not read either.

## Notes and limits

- Treat this node as a typed entry point: start the workflow with `{ event_id, source, type, payload }` and read the event data downstream at `$json.payload`.
- With sample data the engine skips the node and passes the sample input on `out` unchanged.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "event.trigger",
  "name": "Vectry Event Subscription",
  "category": "triggers",
  "version": "1.0.0",
  "description": "Trigger workflow execution based on internal system events (Event Bus).\n\n  This trigger subscribes to the Vectry Causal Event Bus. It listens for specific business or system events (e.g., \"Order Created\", \"User Signup\") and initiates the workflow when a matching event occurs.\n\n  **Features:**\n  - **Filtering:** Subscribe only to events matching specific criteria (domain, entity, tag).\n  - **Replay:** Process historical events (\"since\") or only new ones.\n  - **Pattern Matching:** Trigger on complex event sequences (if configured).\n\n  **Use Cases:**\n  - Sending a Welcome Email when a 'UserCreated' event occurs.\n  - Auditing high-value transactions.",
  "capabilities": [
    "event-subscription",
    "internal-bus",
    "pubsub",
    "vectry"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "filters"
    ],
    "properties": {
      "filters": {
        "type": "array",
        "title": "Event Filters",
        "description": "Match criteria for events.",
        "items": {
          "type": "object",
          "properties": {
            "system_domain": {
              "type": "string",
              "title": "Domain"
            },
            "system_entity": {
              "type": "string",
              "title": "Entity"
            },
            "operation": {
              "type": "string",
              "title": "Operation"
            },
            "tags": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },
      "since": {
        "type": "string",
        "title": "Start From",
        "default": "now",
        "description": "Timestamp (ISO) or \"now\"."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": null,
  "output_contract_schema": {
    "type": "object",
    "description": "The event payload.",
    "properties": {
      "event_id": {
        "type": "string"
      },
      "source": {
        "type": "string"
      },
      "type": {
        "type": "string"
      },
      "payload": {
        "type": "object"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Event Received",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "vectry",
    "events",
    "bus",
    "reactive"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "required": [
    "filters"
  ],
  "properties": {
    "filters": {
      "type": "array",
      "title": "Event Filters",
      "description": "Match criteria for events.",
      "items": {
        "type": "object",
        "properties": {
          "system_domain": {
            "type": "string",
            "title": "Domain"
          },
          "system_entity": {
            "type": "string",
            "title": "Entity"
          },
          "operation": {
            "type": "string",
            "title": "Operation"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "since": {
      "type": "string",
      "title": "Start From",
      "default": "now",
      "description": "Timestamp (ISO) or \"now\"."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "The event payload.",
  "properties": {
    "event_id": {
      "type": "string"
    },
    "source": {
      "type": "string"
    },
    "type": {
      "type": "string"
    },
    "payload": {
      "type": "object"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Event Received",
    "is_default": true
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
