Initial commit: sap-test-legacy-webhook
Receptor de prueba para sap-legacy-webhook-emulator sin depender de sap-webhook-api: recibe el POST con el CloudEvent y guarda cada notificacion en data/events/. Sin framework, HTTP o HTTPS autodetectado. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
commit
9016dc87bd
7 files changed
+1158
No files matched your search
@@ -0,0 +1,78 @@
|
||||
# sap-test-legacy-webhook
|
||||
|
||||
Receptor de prueba para probar [`sap-legacy-webhook-emulator`](../sap-legacy-webhook-emulator)
|
||||
sin necesitar una instancia real de `sap-webhook-api` — mismo comportamiento
|
||||
núcleo (recibe el `POST` con el CloudEvent, guarda cada notificación como
|
||||
`.json` en `data/events/`), pero sin framework y **sin autenticación por
|
||||
ahora**.
|
||||
|
||||
✅ Verificado de punta a punta contra un SAP Business One sobre HANA real:
|
||||
capturó y guardó correctamente un evento real de `Items`
|
||||
(`sap.b1.Items.Updated.v1`), tanto en HTTP como en HTTPS con certificado
|
||||
autofirmado.
|
||||
|
||||
## Quick start
|
||||
|
||||
```bash
|
||||
npm install
|
||||
cp .env.example .env # PORT, default 4100
|
||||
npm start
|
||||
```
|
||||
|
||||
Después, dar de alta una suscripción en `sap-legacy-webhook-emulator`
|
||||
apuntando acá:
|
||||
|
||||
```bash
|
||||
cd ../sap-legacy-webhook-emulator
|
||||
npx tsx scripts/manage-subscriptions.ts subscription:add <webhookId> http://127.0.0.1:4100/webhooks/sap
|
||||
npx tsx scripts/manage-subscriptions.ts filter:add <webhookId> <BizObject> <TransType> <ObjectType>
|
||||
npm run run-once
|
||||
```
|
||||
|
||||
Los eventos recibidos quedan en `data/events/<id>.json` (uno por
|
||||
notificación, nombrado por el `id` del CloudEvent).
|
||||
|
||||
## HTTP / HTTPS
|
||||
|
||||
```bash
|
||||
npm start # autodetecta: HTTPS si existen certs/*.pem, si no HTTP
|
||||
npm run start:http # fuerza HTTP, ignora los certs aunque existan
|
||||
npm run start:https # fuerza HTTPS — error claro si faltan los certs
|
||||
```
|
||||
|
||||
HTTPS usa un certificado autofirmado. Sirve para probar el caso real (SAP
|
||||
suele usar certificados autofirmados) y confirmar que el dispatcher los
|
||||
acepta bien (ya ignora la validación de certificado —
|
||||
`rejectUnauthorized: false`, ver
|
||||
`sap-legacy-webhook-emulator/src/dispatcher/send-webhook.ts`).
|
||||
|
||||
Regenerar el certificado:
|
||||
|
||||
```bash
|
||||
openssl req -x509 -newkey rsa:2048 -keyout certs/key.pem -out certs/cert.pem \
|
||||
-days 3650 -nodes -subj "/CN=127.0.0.1" \
|
||||
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
|
||||
```
|
||||
|
||||
Con HTTPS activo, la suscripción apunta a `https://127.0.0.1:4100/webhooks/sap`
|
||||
en vez de `http://...`. Para cambiar la URL de una suscripción que ya
|
||||
existe (sin recrearla) al pasar de HTTP a HTTPS o viceversa:
|
||||
|
||||
```bash
|
||||
cd ../sap-legacy-webhook-emulator
|
||||
npx tsx scripts/manage-subscriptions.ts subscription:update-url <webhookId> https://127.0.0.1:4100/webhooks/sap
|
||||
```
|
||||
|
||||
## Pendiente (a propósito, no es un olvido)
|
||||
|
||||
Sin autenticación por ahora. Si más adelante hace falta probar HMAC,
|
||||
agregar en `src/server.ts` la misma verificación que ya tiene
|
||||
`sap-webhook-api/src/webhooks/webhooks.controller.ts` (`X-B1-Webhook-Signature`,
|
||||
HMAC-SHA256 sobre el body crudo, activada solo si existe
|
||||
`HMAC_SECRET_KEY`).
|
||||
|
||||
## Stack
|
||||
|
||||
Node/TypeScript puro (`node:http`, sin framework), ejecutado con `tsx` —
|
||||
mismo criterio de simplicidad que el resto de los proyectos de prueba de
|
||||
este workspace.
|
||||
Reference in new issue
Block a user