Comparativas WoW/MoM/YoY muestran prev/Δ además del %; sync ads admite histórico desde 2025; tabla ads↔CRM añade cierres, ventas y ROAS. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { assertCronAuth } from '@/lib/cron-auth';
|
|
import {
|
|
syncAllSuperhumanTenants,
|
|
superhumanConfigured,
|
|
} from '@/lib/superhuman-docs';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
export const maxDuration = 300;
|
|
|
|
/**
|
|
* Daily Superhuman / Seguimiento sync for all tenants.
|
|
* Auth: Authorization: Bearer $CRON_SECRET
|
|
*/
|
|
export async function GET(req: NextRequest) {
|
|
const denied = assertCronAuth(req);
|
|
if (denied) return denied;
|
|
|
|
if (!superhumanConfigured()) {
|
|
return NextResponse.json({
|
|
ok: false,
|
|
warning: 'SUPERHUMAN_DOCS_API_KEY no configurado',
|
|
});
|
|
}
|
|
|
|
try {
|
|
const result = await syncAllSuperhumanTenants({
|
|
maxEntries: 100,
|
|
exportBodies: true,
|
|
});
|
|
return NextResponse.json({
|
|
ok: true,
|
|
...result,
|
|
at: new Date().toISOString(),
|
|
});
|
|
} catch (e) {
|
|
return NextResponse.json(
|
|
{ ok: false, error: e instanceof Error ? e.message : 'sync failed' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function POST(req: NextRequest) {
|
|
return GET(req);
|
|
}
|