# Check Consent

> 检查用户是否已同意某项活动。

Source: https://docs.sommatic.ai/zh/nodes/consent.check/

- 标识: `consent.check`
- 类别: 身份
- 版本: 1.0.0
- 状态: 实验性. 模拟实现：始终从 `yes` 端口输出；不会根据任何同意记录核对 `purpose` 或数据主体。
- 执行方式: async

检查用户是否已同意某项活动。

## 配置

- `user_id` (string, 必填)
- `purpose` (string, 必填)

## 输出端口

- `yes` (默认): 用户已同意
- `no`: 用户未同意
- `error`: 检查失败

## 输入契约

- `user_id` (string, 必填)
- `purpose` (string, 必填)

## 输出契约

- `consented` (boolean, 可选)
- `timestamp` (string, 可选)

## 在表达式中

后续节点可通过 `$("Check Consent").item.json.<路径>` 读取此节点输出中的内容（请把 `Check Consent` 换成你的节点标签）。**Editor** 标记工作流编辑器在 Previous Nodes 中提示的路径（输出契约）；**Worker** 标记 worker 实际通过 `yes` 返回的路径，依据“端口”一节所示的输出。

- `$("Check Consent").item.json.consented` (boolean) = `true`
- `$("Check Consent").item.json.timestamp` (string) = `"2026-11-26T15:04:05.000Z"`


## 工作原理

占位用的同意检查：只校验 `user_id` 已设置，并始终以 `consented: true` 从 `yes` 输出。不会查询任何同意管理平台，也不会评估 `purpose`。

1. 解析配置：`user_id` 和 `purpose` 中的表达式基于当前运行求值。
2. 当 `user_id` 为空时，以 `user_id is required` 从 `error` 输出。
3. 不查询任何同意记录：决策在代码中固定为已同意。
4. 从 `yes` 返回 `{ consented: true, timestamp }`，其中 `timestamp` 为求值时间（ISO 8601）。

## 在工作流中

### 节点

```json
{
  "node_id": "node-check-consent",
  "label": "Check marketing consent",
  "operator_slug": "consent.check",
  "operator_version": "1.0.0",
  "config": {
    "user_id": "{{ $json.customer_id }}",
    "purpose": "marketing_email"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "yes",
  "data": {
    "consented": true,
    "timestamp": "2026-11-26T15:04:05.000Z"
  }
}
```

## 输出端口 (代码中的行为)

### `yes`

只要设置了 `user_id`，始终从此端口输出。

```json
{
  "consented": true,
  "timestamp": "2026-11-26T15:04:05.000Z"
}
```

### `no`

永远不会输出：worker 中没有拒绝同意的路径。

### `error`

`user_id` 为空。

```json
{
  "error": "user_id is required"
}
```

## 代码中的行为

- `purpose`: Schema 要求填写，但运行时会忽略：任何用途得到的结果都相同。

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `user_id is required` | `error` | `user_id` 为空，或其表达式解析为空值。请对照输入项检查表达式。 |

## 说明与限制

- 不要依赖此节点执行同意管控：它从不走 `no`。在接入真实的同意数据源之前，请用显式调用（例如 `io.http`）加 `flow.if` 来检查。
- 从 `error` 端口输出不会使运行失败：引擎沿 `error` 上的连线继续；若没有连线，该分支直接结束。


## 契约（JSON Schema）

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

```json
{
  "slug": "consent.check",
  "name": "Check Consent",
  "category": "identity",
  "version": "1.0.0",
  "description": "Checks if User has consented to activity.",
  "capabilities": [
    "privacy",
    "consent"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "user_id": {
        "type": "string"
      },
      "purpose": {
        "type": "string"
      }
    },
    "required": [
      "user_id",
      "purpose"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "user_id": {
        "type": "string"
      },
      "purpose": {
        "type": "string"
      }
    },
    "required": [
      "user_id",
      "purpose"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "consented": {
        "type": "boolean"
      },
      "timestamp": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "yes",
      "label": "Consented",
      "description": "User agreed",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "no",
      "label": "Not Consented",
      "description": "User did not agree",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Check failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "identity-worker"
  ],
  "tags": [
    "privacy",
    "gdpr"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_veripass",
    "profile": {
      "name": "Veripass",
      "verified": true,
      "url": "https://me.veripass.com/veripass",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "user_id": {
      "type": "string"
    },
    "purpose": {
      "type": "string"
    }
  },
  "required": [
    "user_id",
    "purpose"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "user_id": {
      "type": "string"
    },
    "purpose": {
      "type": "string"
    }
  },
  "required": [
    "user_id",
    "purpose"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "consented": {
      "type": "boolean"
    },
    "timestamp": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "yes",
    "label": "Consented",
    "description": "User agreed",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "no",
    "label": "Not Consented",
    "description": "User did not agree",
    "is_default": false,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Check failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
