feat(semi-auto): 新增履约历史与全链路报文留痕

运营端历史抽屉展示状态流转与全链路报文:客户/运营接口入站 + 虎牙 WUP/livelink、外部 Connector 出站;轮询按状态变化采样,Cookie/Token/短信验证码不落库,报文保留 180 天。同步收敛登录/绑定事件,避免轮询重复写时间线。
This commit is contained in:
2026-11-16 17:26:35 +08:00
parent f371cc2c8d
commit 08e753ec94
13 changed files with 1648 additions and 101 deletions
@@ -16,6 +16,7 @@ import {
huyaNativeConnector,
type HuyaStoredCredential,
} from './huya-native/huya-native-connector.js'
import { recordSemiAutoTrace, traceFingerprint } from './semi-auto-trace.js'
export type ConnectorLoginSession = {
sessionId: string
@@ -204,9 +205,11 @@ async function callConnector<T>(
const timeoutMs = Math.max(1000, Number(runtimeConfig.semiAuto?.connectorTimeoutMs || 15_000))
const controller = new AbortController()
const timer = setTimeout(() => controller.abort(), timeoutMs)
const method = String(options.method || 'GET').toUpperCase()
const startedAt = Date.now()
try {
const requestInit: RequestInit = {
method: options.method || 'GET',
method,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
@@ -223,6 +226,20 @@ async function callConnector<T>(
} catch {
payload = null
}
recordSemiAutoTrace({
direction: 'outbound',
channel: 'external_connector',
action: `${method} ${path}`,
status: response.ok ? 'ok' : 'error',
httpStatus: response.status,
durationMs: Date.now() - startedAt,
requestSummary: { baseUrl: endpoint.baseUrl },
requestBody: options.body,
responseSummary: { bodyBytes: text.length },
responseBody: payload ?? text,
always: method !== 'GET',
fingerprint: method === 'GET' ? traceFingerprint(payload) : undefined,
})
if (!response.ok) {
const detail =
payload && typeof payload === 'object'
@@ -235,6 +252,19 @@ async function callConnector<T>(
}
return payload as T
} catch (error) {
if (!(error && typeof error === 'object' && 'statusCode' in error)) {
recordSemiAutoTrace({
direction: 'outbound',
channel: 'external_connector',
action: `${method} ${path}`,
status: 'error',
durationMs: Date.now() - startedAt,
requestSummary: { baseUrl: endpoint.baseUrl },
requestBody: options.body,
always: true,
errorMessage: error instanceof Error ? error.message : String(error),
})
}
if (error && typeof error === 'object' && 'statusCode' in error) throw error
if (error instanceof Error && error.name === 'AbortError') {
throw createHttpError('半自动履约 Connector 请求超时', {