Reconstruye el Webhook Messenger nativo de SAP B1 (FP2605) para clientes que aun no estan en esa version: captura eventos via SBO_SP_PostTransactionNotice, provisiona UserTables OEVC/EVC1/OEVN/EVN1 y despacha CloudEvents al mismo endpoint que el messenger real. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
// Listener HTTP mínimo, solo para esta prueba: simula sap-webhook-api pero
|
|
// en vez de guardar en Postgres, escribe cada POST recibido como JSON en
|
|
// tmp-test-events/ para poder inspeccionarlo. Se borra todo (este archivo
|
|
// y la carpeta) al terminar la prueba.
|
|
import { createServer } from 'node:http';
|
|
import { writeFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const outDir = fileURLToPath(new URL('../tmp-test-events/', import.meta.url));
|
|
const port = 4100;
|
|
|
|
const server = createServer((req, res) => {
|
|
let body = '';
|
|
req.on('data', (chunk) => (body += chunk));
|
|
req.on('end', () => {
|
|
console.log(`[fake-webhook] ${req.method} ${req.url}`);
|
|
if (req.method === 'POST') {
|
|
const fileName = `${Date.now()}.json`;
|
|
writeFileSync(`${outDir}${fileName}`, body);
|
|
console.log(`[fake-webhook] guardado: tmp-test-events/${fileName}`);
|
|
console.log(body);
|
|
}
|
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
res.end(JSON.stringify({ received: true }));
|
|
});
|
|
});
|
|
|
|
server.listen(port, () => console.log(`[fake-webhook] escuchando en http://127.0.0.1:${port}`));
|