Ship CRM health, cohort CAC, GHL/Shopify sync, and agency alerts.

Add WooCommerce health monitoring, 60d cohort CAC in CRM and portfolio,
incremental GHL upsert, Shopify orders→deals, and daily health-alert cron.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-10-08 12:28:38 +02:00
parent 4baf256750
commit 71110915af
19 changed files with 1177 additions and 76 deletions

View File

@@ -9,6 +9,8 @@ import {
} from '@/lib/superhuman-docs';
import { syncAllClientifyTenants } from '@/lib/clientify-sync';
import { syncAllGhlTenants } from '@/lib/gohighlevel-sync';
import { syncAllShopifyTenants } from '@/lib/shopify-sync';
import { runAgencyHealthAlerts } from '@/lib/agency-health';
import { processDuePipelinePublishes } from '@/lib/pipeline-publish-worker';
export const dynamic = 'force-dynamic';
@@ -92,13 +94,25 @@ export async function GET(req: NextRequest) {
};
}
// 4) Clientify CRM → leads/deals (prefer dedicated /api/cron/clientify-sync)
// 4) CRM + Shopify (prefer dedicated crons; safety net here)
try {
const [clientify, gohighlevel] = await Promise.all([
syncAllClientifyTenants({ lookbackDays: Math.max(days * 2, 30) }),
syncAllGhlTenants(),
const lookback = Math.max(days * 2, 30);
const [clientify, gohighlevel, shopify] = await Promise.all([
syncAllClientifyTenants({ lookbackDays: lookback }),
syncAllGhlTenants({ lookbackDays: lookback }),
syncAllShopifyTenants({ lookbackDays: lookback }),
]);
const results = [...clientify.results, ...gohighlevel.results];
const results = [
...clientify.results,
...gohighlevel.results,
...shopify.results.map((r) => ({
tenantId: r.tenantId,
tenantSlug: r.tenantSlug,
leads: 0,
deals: r.orders,
error: r.error,
})),
];
out.crm = {
ok: true,
synced: results.filter((r) => !r.error).length,
@@ -122,6 +136,16 @@ export async function GET(req: NextRequest) {
};
}
// 6) Health alerts (stale sync / ecommerce drop)
try {
out.healthAlerts = await runAgencyHealthAlerts();
} catch (e) {
out.healthAlerts = {
ok: false,
error: e instanceof Error ? e.message : 'health-alerts failed',
};
}
const failed = ['organic', 'ads', 'superhuman', 'crm'].some(
(k) => (out[k] as { ok?: boolean } | undefined)?.ok === false
);