Feature: Receptor de webhooks interno para debug
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m3s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m3s
- Endpoint POST /api/debug/webhook-receiver para recibir webhooks - Almacenamiento en memoria de ultimos 100 eventos - Endpoint GET/DELETE para consultar/limpiar eventos - Nueva tab Webhooks en seccion Debug con polling cada 5s
This commit is contained in:
16
server/api/debug/webhook-events.delete.ts
Normal file
16
server/api/debug/webhook-events.delete.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* DELETE /api/debug/webhook-events
|
||||
* Clear all stored debug webhook events
|
||||
*/
|
||||
import { debugWebhookStore } from '../../services/debug/webhook-store'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const username = getHeader(event, 'x-authentik-username')
|
||||
if (!username) {
|
||||
throw createError({ statusCode: 401, message: 'Unauthorized' })
|
||||
}
|
||||
|
||||
debugWebhookStore.clear()
|
||||
|
||||
return { success: true, message: 'Events cleared' }
|
||||
})
|
||||
23
server/api/debug/webhook-events.get.ts
Normal file
23
server/api/debug/webhook-events.get.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* GET /api/debug/webhook-events
|
||||
* Get stored debug webhook events
|
||||
*/
|
||||
import { debugWebhookStore } from '../../services/debug/webhook-store'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const username = getHeader(event, 'x-authentik-username')
|
||||
if (!username) {
|
||||
throw createError({ statusCode: 401, message: 'Unauthorized' })
|
||||
}
|
||||
|
||||
const query = getQuery(event)
|
||||
const limit = parseInt(query.limit as string) || 50
|
||||
|
||||
const events = debugWebhookStore.getEvents(limit)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
count: events.length,
|
||||
events
|
||||
}
|
||||
})
|
||||
32
server/api/debug/webhook-receiver.post.ts
Normal file
32
server/api/debug/webhook-receiver.post.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* POST /api/debug/webhook-receiver
|
||||
* Internal endpoint to receive webhooks for debugging
|
||||
* Stores events in memory and emits via SSE
|
||||
*/
|
||||
import { debugWebhookStore } from '../../services/debug/webhook-store'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
const headers = getHeaders(event)
|
||||
|
||||
const webhookEvent = {
|
||||
id: crypto.randomUUID(),
|
||||
receivedAt: new Date().toISOString(),
|
||||
event: body.event || 'unknown',
|
||||
timestamp: body.timestamp,
|
||||
data: body.data || body,
|
||||
headers: {
|
||||
'x-webhook-event': headers['x-webhook-event'],
|
||||
'x-webhook-timestamp': headers['x-webhook-timestamp'],
|
||||
'x-webhook-signature': headers['x-webhook-signature'],
|
||||
'content-type': headers['content-type'],
|
||||
}
|
||||
}
|
||||
|
||||
// Store the event
|
||||
debugWebhookStore.addEvent(webhookEvent)
|
||||
|
||||
console.log(`[Debug Webhook] Received event: ${webhookEvent.event}`)
|
||||
|
||||
return { success: true, message: 'Event received' }
|
||||
})
|
||||
41
server/services/debug/webhook-store.ts
Normal file
41
server/services/debug/webhook-store.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Debug Webhook Store
|
||||
* Stores webhook events in memory for debugging
|
||||
*/
|
||||
|
||||
interface WebhookEvent {
|
||||
id: string
|
||||
receivedAt: string
|
||||
event: string
|
||||
timestamp?: string
|
||||
data: any
|
||||
headers: Record<string, string | undefined>
|
||||
}
|
||||
|
||||
class DebugWebhookStore {
|
||||
private events: WebhookEvent[] = []
|
||||
private maxEvents = 100
|
||||
|
||||
addEvent(event: WebhookEvent) {
|
||||
this.events.unshift(event)
|
||||
|
||||
// Keep only the last N events
|
||||
if (this.events.length > this.maxEvents) {
|
||||
this.events = this.events.slice(0, this.maxEvents)
|
||||
}
|
||||
}
|
||||
|
||||
getEvents(limit: number = 50): WebhookEvent[] {
|
||||
return this.events.slice(0, limit)
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.events = []
|
||||
}
|
||||
|
||||
getCount(): number {
|
||||
return this.events.length
|
||||
}
|
||||
}
|
||||
|
||||
export const debugWebhookStore = new DebugWebhookStore()
|
||||
Reference in New Issue
Block a user