feat: sync Clientify CRM + botón Sincronizar por pestaña

El CRM solo vivía de webhooks; ahora hay pull Clientify, cron daily-sync incluye CRM, y cada módulo de Agencia tiene sync manual.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-30 15:34:40 +02:00
parent c11ec20f26
commit e3180ceb51
13 changed files with 749 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ import {
syncAllSuperhumanTenants,
superhumanConfigured,
} from '@/lib/superhuman-docs';
import { syncAllClientifyTenants } from '@/lib/clientify-sync';
export const dynamic = 'force-dynamic';
export const maxDuration = 300;
@@ -89,7 +90,23 @@ export async function GET(req: NextRequest) {
};
}
const failed = ['organic', 'ads', 'superhuman'].some(
// 4) Clientify CRM → leads/deals
try {
const crm = await syncAllClientifyTenants();
out.crm = {
ok: true,
synced: crm.results.filter((r) => !r.error).length,
withErrors: crm.results.filter((r) => r.error).length,
results: crm.results,
};
} catch (e) {
out.crm = {
ok: false,
error: e instanceof Error ? e.message : 'crm failed',
};
}
const failed = ['organic', 'ads', 'superhuman', 'crm'].some(
(k) => (out[k] as { ok?: boolean } | undefined)?.ok === false
);
return NextResponse.json(out, { status: failed ? 207 : 200 });