feat(fulfillment): 增加事务 Outbox 同步履约状态

- 用事务 Outbox 和签名 Webhook 替换直接状态回调
- 增加 Outbox 投递 worker、重试与低频对账兜底
- 缓存客户领取页绑定状态并补充签名与迁移测试
This commit is contained in:
yml
2026-11-18 11:00:28 +08:00
parent 54b9f3251d
commit 9b2fcf1d1f
23 changed files with 1324 additions and 130 deletions
+15 -1
View File
@@ -4,6 +4,7 @@ import test from 'node:test'
import { createApp } from './app.js'
import { createDefaultRuntimeConfig } from './config/defaults.js'
import { buildWebhookSignature } from './services/integration/webhook-signature.js'
import { createStartupState } from './startup/state.js'
test('HTTP health route and explicit CORS preflight', async () => {
@@ -64,13 +65,26 @@ test('履约状态集成接口要求密钥并接受空快照', async () => {
})
assert.equal(unauthorized.status, 401)
const rawBody = JSON.stringify({
eventId: '8a8da35c-46c3-45a8-a914-3d7f28ee91ca',
eventType: 'platform_fulfillment.binding_state_changed',
items: [],
})
const timestamp = String(Math.floor(Date.now() / 1000))
const accepted = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Integration-Key': 'integration-test-key',
'X-Integration-Event-Id': '8a8da35c-46c3-45a8-a914-3d7f28ee91ca',
'X-Integration-Timestamp': timestamp,
'X-Integration-Signature': buildWebhookSignature(
'integration-test-key',
timestamp,
rawBody,
),
},
body: JSON.stringify({ items: [] }),
body: rawBody,
})
assert.equal(accepted.status, 200)
assert.deepEqual((await accepted.json()).data, { received: 0, updated: 0 })