# Append Audit Log

> Appends an immutable entry to the secure audit trail.

Source: https://docs.sommatic.ai/en/nodes/audit.append/

- Slug: `audit.append`
- Family: Operations
- Version: 1.0.0
- Status: Partial. Writes a structured `[AUDIT]` log line. It does not sign, hash-chain or persist the record. It returns `{ success: true }` on the default `out` port, so edges wired from the `success` port never fire; missing `action`, `actor` or `resource` throws instead of using the `error` port.
- Execution: async

Appends an immutable entry to the secure audit trail.

This operator ensures compliance and traceability by recording key decisions, data access, or modifications. Entries are signed and stored in a tamper-evident audit log.

**Fields:**
- **Actor:** Who performed the action (User/Service).
- **Action:** What happened (e.g., "Approved Loan").
- **Resource:** Target entity (e.g., "Loan #123").
- **Evidence:** JSON payload proving the action.

**Use Cases:**
- Regulatory compliance (GDPR, HIPAA).
- Debugging security incidents.
- Tracking approval chains.

## Configuration

- `action` (string, required): The specific action identifier (e.g. "ITEM_DELETED").

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

- `success` (default): Audit logged successfully.
- `error`: Failed to write audit log.

## Input contract

- `actor` (string, required): User ID or Service Name
- `resource` (string, required): Target Resource ID
- `decision` (string, optional): Outcome (e.g. Permit/Deny)
- `evidence` (object, optional): Supporting context/data

## Output contract

- `success` (boolean, optional)

## In expressions

What a later node can read from this node's output with `$("Append Audit Log").item.json.<path>`, as the workflow editor suggests it under Previous Nodes (the output contract).

- `$("Append Audit Log").item.json.success` (boolean)


## How it works

Writes one `[AUDIT] <action> by <actor> on <resource>` line to the orchestrator log and returns `{ success: true }`. The record is not signed, hash-chained or stored anywhere else.

1. Merges the input item with the resolved config (config wins).
2. Throws `Missing 'action'`, `Missing 'actor'` or `Missing 'resource'` when one of them is empty.
3. Logs `[AUDIT] <action> by <actor> on <resource>` at info level. The `audit` object passed with it (`decision`, `evidence`, `timestamp`) is not written, because the runtime logger prints only the message.
4. Returns `{ success: true }` with no port, so the engine routes through `out`.

## In a workflow

### Node

```json
{
  "node_id": "node-audit-approval",
  "label": "Audit approval",
  "operator_slug": "audit.append",
  "operator_version": "1.0.0",
  "config": {
    "action": "INVOICE_APPROVED",
    "actor": "{{ $json.approver_id }}",
    "resource": "invoice:{{ $json.invoice_id }}",
    "decision": "Permit"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "data": {
    "success": true
  }
}
```

## Output ports (behaviour in the code)

### `success`

Never emitted: the worker returns no port, so the engine routes through `out`, which this node does not declare. Edges drawn from `success` never fire.

### `error`

Never emitted: failures throw instead, which fails the run.

## Behaviour in the code

- `actor`: Not in the config schema (only in the input contract), but read from the node config or, when unset there, from the input item: `actor`, `resource`, `decision`, `evidence`.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'action'` | `error` | `action` is set neither on the node nor in the input item. Thrown: the run fails. |
| `Missing 'actor'` | `error` | `actor` is set neither on the node nor in the input item. Thrown: the run fails. |
| `Missing 'resource'` | `error` | `resource` is set neither on the node nor in the input item. Thrown: the run fails. |

## Notes and limits

- Partial: no signature, no hash chain, no tamper evidence and no database write. The only trace is a log line of the orchestrator, and its content is limited to action, actor and resource.
- Use it as the last node of a branch: nodes wired after `success` never run. The node output in the run is `{ success: true }`.
- A thrown error fails the whole run with `Node <node_id> (<slug>) failed: <message>` and edges from `error` do not fire. Inside a `flow.try` scope the engine sends it to the catch node instead.
- The `execution` settings (`retryOnFail`, `maxTries`, `waitBetweenTries`, `continueOnFail`, `timeout_ms`) are accepted, but neither this worker nor the engine applies them.


## Contracts (JSON Schema)

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

```json
{
  "slug": "audit.append",
  "name": "Append Audit Log",
  "category": "ops",
  "version": "1.0.0",
  "description": "Appends an immutable entry to the secure audit trail.\n\n  This operator ensures compliance and traceability by recording key decisions, data access, or modifications. Entries are signed and stored in a tamper-evident audit log.\n\n  **Fields:**\n  - **Actor:** Who performed the action (User/Service).\n  - **Action:** What happened (e.g., \"Approved Loan\").\n  - **Resource:** Target entity (e.g., \"Loan #123\").\n  - **Evidence:** JSON payload proving the action.\n\n  **Use Cases:**\n  - Regulatory compliance (GDPR, HIPAA).\n  - Debugging security incidents.\n  - Tracking approval chains.",
  "capabilities": [
    "audit",
    "compliance",
    "security",
    "log"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "action"
    ],
    "properties": {
      "action": {
        "type": "string",
        "title": "Action Name",
        "description": "The specific action identifier (e.g. \"ITEM_DELETED\")."
      },
      "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": {
    "type": "object",
    "properties": {
      "actor": {
        "type": "string",
        "description": "User ID or Service Name"
      },
      "resource": {
        "type": "string",
        "description": "Target Resource ID"
      },
      "decision": {
        "type": "string",
        "description": "Outcome (e.g. Permit/Deny)"
      },
      "evidence": {
        "type": "object",
        "description": "Supporting context/data"
      }
    },
    "required": [
      "actor",
      "resource"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "description": "Confirmation of audit persistence.",
    "properties": {
      "success": {
        "type": "boolean"
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Success",
      "is_default": true,
      "description": "Audit logged successfully."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Failed to write audit log."
    }
  ],
  "execution_mode": "async",
  "tags": [
    "audit",
    "compliance",
    "security"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_vectry",
    "profile": {
      "name": "Vectry Analytics",
      "verified": true,
      "url": "https://me.veripass.com/vectry",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "required": [
    "action"
  ],
  "properties": {
    "action": {
      "type": "string",
      "title": "Action Name",
      "description": "The specific action identifier (e.g. \"ITEM_DELETED\")."
    },
    "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

```json
{
  "type": "object",
  "properties": {
    "actor": {
      "type": "string",
      "description": "User ID or Service Name"
    },
    "resource": {
      "type": "string",
      "description": "Target Resource ID"
    },
    "decision": {
      "type": "string",
      "description": "Outcome (e.g. Permit/Deny)"
    },
    "evidence": {
      "type": "object",
      "description": "Supporting context/data"
    }
  },
  "required": [
    "actor",
    "resource"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "Confirmation of audit persistence.",
  "properties": {
    "success": {
      "type": "boolean"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "success",
    "label": "Success",
    "is_default": true,
    "description": "Audit logged successfully."
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Failed to write audit log."
  }
]
```
