Skip to content

eNotify × Vikunja 集成(后端):入站 webhook 适配 + 管理接口 + 迁移 - #173

Merged
todosdev[bot] merged 5 commits into
mainfrom
tds/conv-01a1a962-e46c-7dec-9304-043080f4259d
Nov 5, 2026
Merged

todosdev[bot] merged 5 commits into
mainfrom
tds/conv-01a1a962-e46c-7dec-9304-043080f4259d

Conversation

@todosdev

@todosdev todosdev Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

概要

  • 新增 Vikunja 入站 webhook 适配:自托管 Vikunja 的任务提醒与逾期事件经 eNotify 默认渠道推送,并以 trigger_source = "vikunja" 记入通知历史。
  • 本 PR 只含后端:{prefix}vikunja_integrations 新表与 schema_v4 迁移、HMAC 验签入站端点、每用户管理接口、日志脱敏、文档与测试;前端「集成」页签由并行单交付。
  • 冻结设计不变:hookToken 定位用户、secret 验签(原始 body 的 HMAC-SHA256,常量时间比对)、未知事件忽略、不建事项、不做通知时段门控与去重。

改动

  • 数据层与迁移(worker/src/types.ts、worker/src/db/schema.sql、worker/src/lib/migrations.ts、worker/src/db/queries/vikunja-integrations.ts):新表每用户一行,hook_token 唯一、secret 明文存储(HMAC 需要原始密钥)、base_url 默认空串、enabled 数值;schema_v4 纯新增 IF NOT EXISTS 并带命名唯一索引;查询模块提供按 token/用户查询、创建、更新、删除。
  • 入站端点(worker/src/routes/integrations.ts、worker/src/services/vikunja-webhook.ts):POST /api/integrations/vikunja/:hookToken,按 token 限流 60 次/分钟;顺序为查 token → 查启用 → 只读一次原始 body 做 crypto.subtle.verify 常量时间验签 → 解析 JSON → 事件映射 → sendNotifications(不传 channels,triggerSource: "vikunja"、itemId: null,发送完成后才回响应)。支持 task.reminder.fired、task.overdue、tasks.overdue;截止时间按接收用户时区格式化,tasks.overdue 汇总最多 10 行。未知事件与残缺数据返回 200 {ignored:true},其余状态码按规格表实现。
  • 管理接口(worker/src/routes/me.ts):创建(201 返回一次性 secret;已存在 409)、查询(永不回明文,只回 secret_configured:true)、修改 enabled/base_url(仅 http(s)、去尾斜杠、空串合法)、轮换 secret(一次性明文)、删除(未创建 404);沿用 authMiddleware + getEffectiveUserId。
  • 日志脱敏(worker/src/index.ts):路由挂在 SPA fallback 之前;请求日志正则扩展到 /api/integrations/vikunja/<token>。
  • 文档(README.md、README.en.md、CLAUDE.md、docs/migration-ledger-cutover-runbook.md):集成说明(端点、管理方式、事件、验签约定)、Vikunja webhooks.enabled 前置与 schema_v4 升级步骤;CLAUDE.md 补新表与新路由;生产切换 runbook 补新表改名、索引名释放/重建与回滚顺序。
  • 测试:验签与事件映射单测、入站路由与管理接口用例、schema_v4 全新安装/从 v3 升级/幂等测试;既有迁移列表断言同步到 v4。

测试

  • pnpm typecheck、pnpm build、pnpm test(26 个测试文件 / 349 项)与 pnpm format:check 全部通过;pnpm lint 仅剩仓库既有的 worker/src/routes/items.ts 未用导入告警(非本 PR 引入)。
  • 覆盖要点:错 secret、body 被改、签名缺失与非 64 位 hex 一律拒绝;三个事件的截止时区与 10 行截断;入站 404/403/401/400/200-ignored;合法 reminder 只发默认渠道一次且历史落 trigger_source='vikunja';轮换后旧签名 401、新签名通过;DELETE 后入站 404;重复创建 409;迁移的全新安装、v3 升级与重复执行无变化。

Todos added 5 commits November 5, 2026 09:59
Add the vikunja_integrations table (schema_v4), HMAC-verified inbound
webhook route, per-user management endpoints, log redaction, docs and tests.

Checkpoint: WIQCMHrEuGb0bV4Wn24_8
Refresh the stale schema_v1-only expectations to schema_v1–schema_v4, document
the schema_v4 activation step, and return the GET view plus the one-time secret
from the integration create endpoint.

Checkpoint: YrQ6lRZKMDTcWHK7IOw1d
Release the canonical index name before the fresh install, assert the live
unique index in step 3, and correct the cascade wording and rollback drop order.

Checkpoint: OGWvZhyCIMJn7kg6sKKIy
Release the five core index names alongside the Vikunja unique index, verify
and rebuild them on both rollback paths, and replace the ineffective recovery
guidance with live-table index recreation.

Checkpoint: 9D35Uuzb1ePVZssNId0q_
Drop the index names before recreating them in the recovery path, make the
Vikunja rollback statements conditional, and distinguish core-table from
integration-snapshot indexes.

Checkpoint: p7n4kjIX5hWhTno85SnxY
@todosdev
todosdev Bot merged commit 3f2d4c7 into main Nov 5, 2026
1 check passed
@mapxn
mapxn deleted the tds/conv-01a1a962-e46c-7dec-9304-043080f4259d branch November 8, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants