Files
wmailhub/docs/05_DATA_MODEL.md
T
bigcode e2c3c353cf refactor: v2.2.0 移除本地 sim 模式,Cloudflare OAuth 只走真实授权
- 删除 SimCFApi / WMAILHUB_SIM_CF / isRealOAuth / POST /api/oauth/cloudflare/sim/approve
- 删除前端 OAuthSim 模拟授权页与 /oauth/sim/authorize 路由;账号页「添加账号」整页跳 Cloudflare
- 迁移 0005 删除 cf_sim_resources 表
- 未配置 CF_OAUTH_CLIENT_ID/SECRET 时 start/callback 一律 503(不再降级出假账号假资源)
- 修 OAuth 回调端点:跨站重定向不携带 SameSite=Strict 会话 cookie,改为由一次性 state 承担 CSRF 防护
- 测试改用 tests/cf-mock.ts 在 fetch 层拦截 Cloudflare API,断言真实 HTTP 调用(72/72 通过)
- 本地 dev 无账号时只拉起 Console 并提示人工授权,不再自动造账号
2026-09-30 15:33:58 +08:00

83 lines
2.8 KiB
Markdown

# 数据模型(v2,docs/11 §13)
核心实体:CloudflareAccount、Domain、Mailbox、Email、EmailAttachment、Webhook(三级配置)、WebhookDelivery、OAuthConnection、WorkerCredential。
Node 作为邮件链路核心模型已删除(旧 nodes / node_credentials 表由迁移 0003 移除,
账号实体更名为 cloudflare_accounts,凭据更换为 worker_credentials)。
## cloudflare_accounts
```text
id, name, cloudflare_account_id, worker_id, status, provision_steps, created_at, updated_at
```
status:pending_oauth | provisioning | active | error | revoked。
worker_id 同时是 Email Worker 脚本名与 Worker -> Console 的身份 ID。
## domains
```text
id, cloudflare_account_id, account_id, name, status, worker_id, zone_id,
webhook_url, webhook_headers, webhook_key_enc, setup_error, created_at, updated_at
```
status:pending(未配置 Email Workers)| active | error。
## mailboxes
```text
id, domain_id, address, status, retention_seconds, is_catch_all,
webhook_url, webhook_headers, webhook_key_enc, created_at, updated_at
```
## emails
```text
id, account_id, mailbox_id nullable, message_id, from_address, to_addresses,
cc_addresses, subject, text_body, html_body, markdown_body(v2.1.0:正文 Markdown,
入库时从 HTML/纯文本转换), raw_storage_key, size,
received_at, expires_at, created_at
```
Console 收到邮件后根据收件人/内容与自身配置关联 mailbox。
## email_attachments
```text
id, email_id, filename, content_type, size, storage_key, content_id
```
## Webhook(三级:邮箱 -> 域名 -> 全局)
域名/邮箱行内配置(webhook_url / webhook_headers / webhook_key_enc),
全局配置存 settings.global_webhook;独立 webhooks 实体已移除。
```text
webhook_deliveries: id, email_id, target_type(mailbox|domain|global),
url, headers, key_enc, status, attempt_count, next_retry_at, last_error, delivered_at, created_at
```
投递行在入队时冻结解析出的配置,重试不受后续配置变更影响。
## oauth_connections
```text
id, provider, account_id, encrypted_access_token, refresh_token, expires_at, created_at, updated_at
```
OAuth token 必须加密存储。所有 Email 必须有 expires_at,默认 retention 为 86400 秒。
## worker_credentials
```text
id, cloudflare_account_id, worker_id, secret_hash, secret_enc, secret_last4,
status(active | revoked), created_at, revoked_at
```
用于 Email Worker 与 Console 内部认证:secret_hash 为摘要,secret_enc 为 AES-GCM 密文
(HMAC 验签需要原文,加密存储防拖库泄露);明文 secret 仅在签发/轮换时返回一次。
## 其它
users、settings(全局 Webhook、单一 API/MCP Key:api_key_hash/api_key_last4/api_key_created_at)、nonces、oauth_states。v2.1.0 起 api_credentials 表已删除(Key 合并为单一 Key 存 settings);v2.2.0 起 cf_sim_resources 表已删除(移除本地 sim 模式,接入链路只有真实 Cloudflare OAuth)。