新增 affiliate_dash 回调路由与幂等去重(阶段 5)

- POST /api/v1/open/affiliate-dash:验签 → 查任务(404 重试) → webhook_events 幂等闸门 → 状态同步
- migration 013:webhook_events(provider+event_id 唯一)
- task-repo findAffiliateDashTaskByOrder(仿 feifei 同构 SQL)
- notify-service:去重闸门在找到任务之后,任务未匹配不被 eventId 永久拦截
- typecheck + 212 测试通过;前置错误分支脚本验证通过
This commit is contained in:
yml2213
2026-08-05 16:07:33 +08:00
parent 00d490a2cd
commit 7fc3d60588
7 changed files with 294 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
import { Router } from 'express'
import { createRateLimitMiddleware } from '../middleware/rate-limit.js'
import { handleAffiliateDashNotify } from '../services/platforms/affiliate-dash/notify-service.js'
import { sendRouteError } from '../utils/http.js'
import { createRequestId, logIntegration } from '../utils/logger.js'
const router = Router()
const notifyRateLimit = createRateLimitMiddleware({
scope: 'affiliateDashNotify',
windowMs: 60_000,
max: 300,
})
router.post('/', notifyRateLimit, async (req, res) => {
const requestId = createRequestId('adn')
const startedAt = Date.now()
logIntegration('[affiliate-dash/notify]', '收到 affiliate-dash 订单回调', {
requestId,
method: req.method,
originalUrl: req.originalUrl,
ip: req.ip,
headers: {
'content-type': req.headers['content-type'],
'x-event-id': req.headers['x-event-id'],
'x-timestamp': req.headers['x-timestamp'],
'x-sign': req.headers['x-sign'],
},
rawBody: req.rawBody,
})
try {
const result = await handleAffiliateDashNotify({
body: req.body,
headers: req.headers,
rawBody: req.rawBody,
})
logIntegration('[affiliate-dash/notify]', '订单回调处理完成', {
requestId,
durationMs: Date.now() - startedAt,
result,
})
res.status(200).json({ code: 0 })
} catch (error) {
logIntegration('[affiliate-dash/notify]', '订单回调处理失败', {
requestId,
durationMs: Date.now() - startedAt,
error,
}, { level: 'error' })
sendRouteError(res, error, 'affiliate-dash 回调处理失败', '[affiliate-dash/notify]')
}
})
export default router