优化 Webhook 列表, 优化日志系统
This commit is contained in:
@@ -382,6 +382,7 @@ export async function getAdminWebhookEvents(query = /** @type {AdminWebhookEvent
|
||||
platform: String(query.platform || '').trim(),
|
||||
platformOrderId: String(query.platformOrderId || '').trim(),
|
||||
processed: String(query.processed || '').trim(),
|
||||
visibility: String(query.visibility || '').trim() || 'important',
|
||||
relatedOrderId: String(query.relatedOrderId || '').trim(),
|
||||
dateFrom: normalizeDateQuery(query.dateFrom),
|
||||
dateTo: normalizeDateQuery(query.dateTo, true),
|
||||
|
||||
@@ -76,6 +76,7 @@ export async function mapAdminWebhookEvent(item, { includeRaw = false } = {}) {
|
||||
signatureValid: Boolean(item.signature_valid),
|
||||
processed: Boolean(item.processed),
|
||||
processError: item.process_error,
|
||||
visibilityLevel: resolveWebhookVisibilityLevel(item.process_error),
|
||||
relatedOrderId: item.related_order_id,
|
||||
createdAt: item.created_at,
|
||||
platformOrderId: resolveAgisoTradePlatformOrderId(payload),
|
||||
@@ -166,6 +167,16 @@ function extractWebhookItemSources(payload) {
|
||||
return []
|
||||
}
|
||||
|
||||
export function resolveWebhookVisibilityLevel(processError) {
|
||||
const normalized = String(processError || '').trim()
|
||||
|
||||
if (normalized.startsWith('ignored_')) {
|
||||
return 'ignored'
|
||||
}
|
||||
|
||||
return 'important'
|
||||
}
|
||||
|
||||
function normalizeRecord(value) {
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value : {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { resolveWebhookVisibilityLevel } from './admin-webhook-read-helpers.js'
|
||||
|
||||
test('resolveWebhookVisibilityLevel marks ignored process errors as ignored', () => {
|
||||
assert.equal(resolveWebhookVisibilityLevel('ignored_unconfigured_product'), 'ignored')
|
||||
assert.equal(resolveWebhookVisibilityLevel('ignored_duplicate_event'), 'ignored')
|
||||
})
|
||||
|
||||
test('resolveWebhookVisibilityLevel keeps normal and failed events as important', () => {
|
||||
assert.equal(resolveWebhookVisibilityLevel(''), 'important')
|
||||
assert.equal(resolveWebhookVisibilityLevel('invalid_signature'), 'important')
|
||||
})
|
||||
Reference in New Issue
Block a user