feat(creatives): implement WF4 integrations, GET include=client, asset_final check and HMAC webhook
This commit is contained in:
@@ -33,24 +33,25 @@ export function verifyWebhookSignature(payloadStr: string, signature: string, se
|
||||
}
|
||||
|
||||
/**
|
||||
* Envía un webhook firmado hacia n8n (N8N_WEBHOOK_BASE/event)
|
||||
* Envía un webhook firmado hacia n8n (/webhook/app4v/creative-event)
|
||||
*/
|
||||
export async function dispatchN8nWebhook(
|
||||
event: CreativeWebhookEvent,
|
||||
payload: Record<string, unknown>
|
||||
): Promise<WebhookDispatchResult> {
|
||||
const baseUrl = process.env.N8N_WEBHOOK_BASE?.trim() || 'https://n8n-agencia.4ventures.es/webhook';
|
||||
const baseUrl = process.env.N8N_WEBHOOK_BASE?.trim() || 'https://n8n.4ventures.es/webhook';
|
||||
const secret = process.env.N8N_WEBHOOK_SECRET?.trim() || 'whsec_4v_7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d';
|
||||
|
||||
if (!baseUrl) {
|
||||
return { sent: false, error: 'N8N_WEBHOOK_BASE is not configured' };
|
||||
}
|
||||
|
||||
const endpoint = `${baseUrl.replace(/\/$/, '')}/${event.replace('.', '-')}`;
|
||||
// WF4 listens on /webhook/app4v/creative-event
|
||||
const endpoint = `${baseUrl.replace(/\/$/, '')}/app4v/creative-event`;
|
||||
const fullBody = {
|
||||
event,
|
||||
payload,
|
||||
timestamp: new Date().toISOString(),
|
||||
data: payload,
|
||||
};
|
||||
|
||||
const bodyStr = JSON.stringify(fullBody);
|
||||
|
||||
@@ -32,6 +32,10 @@ export async function sendCreativeToClient(creativeId: string, tenantId: string,
|
||||
throw new Error('Creatividad no encontrada');
|
||||
}
|
||||
|
||||
if (!creative.asset_final) {
|
||||
throw new Error('Solo se puede enviar al cliente si cuenta con imagen final compuesta (asset_final=true)');
|
||||
}
|
||||
|
||||
const prevStatus = creative.status;
|
||||
|
||||
const { data: updated, error: updateErr } = await adminClient
|
||||
|
||||
Reference in New Issue
Block a user