feat: marca Uriel Jareth Consulting, API segura para agentes, aprobacion humana y webhooks HMAC

This commit is contained in:
urieljareth
2026-11-25 00:55:18 -06:00
parent 75180b0fe4
commit 0d4f19f35d
111 changed files with 7167 additions and 1272 deletions
+27 -3
View File
@@ -18,6 +18,7 @@ import {
type PagoPorCobrar,
} from "@/lib/cobros";
import type { PagoRecurrente } from "@/generated/prisma/client";
import { emitirWebhook } from "@/lib/webhooks";
// Orquestacion de avisos al cliente: correo SMTP + Web Push. Todo es
// best-effort: un fallo de correo/push jamas revienta el flujo que lo llamo
@@ -53,16 +54,16 @@ function formatoMoneda(monto: number, moneda: string): string {
function plantilla(titulo: string, cuerpo: string, boton?: { texto: string; url: string }): string {
const botonHtml = boton
? `<p style="margin:24px 0"><a href="${boton.url}" style="background:#0f172a;color:#fff;padding:12px 20px;border-radius:8px;text-decoration:none;font-weight:600">${boton.texto}</a></p>`
? `<p style="margin:24px 0"><a href="${boton.url}" style="background:#0400c4;color:#fff;padding:12px 20px;border-radius:8px;text-decoration:none;font-weight:600">${boton.texto}</a></p>`
: "";
return `<!doctype html><html><body style="margin:0;background:#f4f4f5;font-family:Arial,Helvetica,sans-serif">
<div style="max-width:560px;margin:0 auto;padding:32px 16px">
<div style="background:#fff;border:1px solid #e4e4e7;border-radius:12px;padding:32px">
<p style="font-size:13px;color:#71717a;margin:0 0 4px">COTIZADOR E3</p>
<p style="font-size:13px;color:#64748b;margin:0 0 4px">URIEL JARETH CONSULTING</p>
<h1 style="font-size:20px;color:#18181b;margin:0 0 16px">${esc(titulo)}</h1>
<div style="font-size:15px;color:#3f3f46;line-height:1.6">${cuerpo}</div>
${botonHtml}
<p style="font-size:12px;color:#a1a1aa;margin:24px 0 0">Consultoría E3 · Querétaro, México</p>
<p style="font-size:12px;color:#a1a1aa;margin:24px 0 0">Uriel Jareth Consulting · urieljareth.com</p>
</div>
</div></body></html>`;
}
@@ -422,6 +423,29 @@ export async function enviarRecordatoriosPendientes(
console.error("[notificaciones] fallo el recordatorio del cliente", clienteId, e);
resultado.correo = "error";
}
// Emision best-effort del webhook pago.vencido sin alterar ni duplicar correos/push.
void emitirWebhook("pago.vencido", {
clienteId,
cliente: {
id: clienteId,
nombre: cliente.nombre,
empresa: cliente.empresa ?? null,
email: cliente.usuario?.email || cliente.email || null,
},
totales: resultado.totales,
pagos: lista.map((p) => ({
id: p.id,
programaId: p.programaId,
concepto: p.programa.concepto,
fecha: p.fecha.toISOString().slice(0, 10),
monto: p.monto,
moneda: p.programa.moneda,
estado: p.estado,
diasAtraso: diasDeAtraso(p.fecha, hoy),
})),
recordatorioEntregado: resultado.entregado,
});
resultados.push(resultado);
}