File size: 1,294 Bytes
7200823 c6b6c96 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import { NextResponse } from 'next/server'
import { sendCustomEvent, isTorqueConfigured } from '@/lib/torque-mcp'
import { pushEvent } from '@/lib/event-store'
export async function POST(req: Request) {
const body = await req.json()
const { wallet, eventType, eventName, metadata, data, risk, score } = body
const name = eventName || eventType
const payload = data || metadata || {}
if (!wallet || !name) {
return NextResponse.json({ error: 'wallet and eventName required' }, { status: 400 })
}
const result = await sendCustomEvent(wallet, name, payload)
if (!result.success) {
const status = isTorqueConfigured() ? 502 : 503
return NextResponse.json({ success: false, error: result.error }, { status })
}
pushEvent({
ingestionId: result.eventId || 'local-' + Date.now(),
wallet,
eventName: name,
risk,
score,
firedAt: new Date().toISOString(),
source: 'manual',
})
return NextResponse.json({ success: true, eventId: result.eventId })
}
export async function GET() {
return NextResponse.json({
status: isTorqueConfigured() ? 'ok' : 'unconfigured',
events: ['churn_risk_high', 'churn_risk_medium', 'comeback_detected', 'streak_maintained', 'volume_milestone', 'referral_from_saved', 'inactivity_detected'],
})
}
|