用途:帮助开发者搭建 Commerce Layer Webhook 接收端点,验证签名并处理订单、客户、发货等事件。
主要能力:Commerce Layer 用 webhook 的 shared_secret 对原始请求体做 HMAC-SHA256,摘要以 base64 放在 X-CommerceLayer-Signature 头,触发主题在 X-CommerceLayer-Topic。shared_secret 仅在创建 webhook(POST /api/webhooks)的响应中返回一次,与 API 凭证不同。必须读取原始请求体而非解析后的 JSON,重新序列化会改变字节导致校验失败;Commerce Layer 无 SDK 校验助手,需手动校验。技能提供 Node 与 Python 校验示例,以及 express、nextjs、fastapi 完整处理器示例。
事件主题:格式为 {resource}.{trigger},如 orders.place、orders.approve、orders.cancel、orders.pay、orders.refund、customers.create、shipments.ship、shipments.deliver,共支持 100+ 主题。载荷为 JSON:API 格式,与 REST API 获取资源一致;.destroy 主题仅填充 data.id。
使用方式:设置环境变量 COMMERCELAYER_SHARED_SECRET;本地开发可用 npx hookdeck-cli listen 3000 commercelayer --path /webhooks/commercelayer 启动隧道。
限制与可靠性:端点须在 5 秒内返回 2xx;失败最多重试 10 次,连续 5 次失败通知组织管理员,连续 30 次失败触发熔断(circuit_state 变为 open,需手动重置)。建议先快速校验,再异步处理耗时逻辑。生成文件时按要求添加注释。可搭配 webhook-handler-patterns 技能处理幂等与重试。