diff --git a/api/src/routes/dot-lookup.ts b/api/src/routes/dot-lookup.ts index 374c79a..75adb4e 100644 --- a/api/src/routes/dot-lookup.ts +++ b/api/src/routes/dot-lookup.ts @@ -13,6 +13,7 @@ import { pool } from "../db.js"; const router = Router(); const FMCSA_API_KEY = process.env.FMCSA_API_KEY || ""; +const WORKER_URL = process.env.WORKER_URL || "http://workers:8090"; const FMCSA_BASE = "https://mobile.fmcsa.dot.gov/qc/services/carriers"; // ── Helpers ───────────────────────────────────────────────────────── @@ -441,15 +442,74 @@ router.get("/api/v1/dot/lookup", async (req, res) => { const isFormalEntity = isLLC || isCorp || isLTD || isLP; const state = carrier?.phyState || census?.phy_state || ""; - if (isFormalEntity) { + if (isFormalEntity && state) { + const entityType = isLLC ? "LLC" : isCorp ? "Corporation" : isLTD ? "Ltd" : "LP/LLP"; + + // Live SOS lookup via workers /entity-status endpoint + let sosStatus: { found?: boolean; status?: string; error?: string } | null = null; + try { + const sosResp = await fetch(`${WORKER_URL}/entity-status`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ entity_name: name, state_code: state }), + signal: AbortSignal.timeout(12000), + }); + if (sosResp.ok) { + sosStatus = (await sosResp.json()) as { found?: boolean; status?: string; error?: string }; + } + } catch { + // SOS lookup timed out or failed — fall back to informational + } + + if (sosStatus?.found && sosStatus.status === "ACTIVE") { + checks.push({ + id: "corporate_compliance", + label: "Corporate / Entity Compliance", + status: "green", + detail: `${entityType} in ${state} — ACTIVE and in good standing. ` + + `Make sure your annual report and registered agent are current. ` + + `Performance West can handle your annual filings and serve as your registered agent.`, + }); + } else if (sosStatus?.found && sosStatus.status !== "ACTIVE") { + checks.push({ + id: "corporate_compliance", + label: "Corporate / Entity Compliance", + status: "red", + detail: `${entityType} in ${state} — status: ${sosStatus.status || "NOT ACTIVE"}. ` + + `Your entity may be administratively dissolved, revoked, or delinquent. ` + + `This can affect your USDOT registration and operating authority. ` + + `Performance West can reinstate your entity and bring it back into compliance.`, + }); + } else if (sosStatus && !sosStatus.found) { + checks.push({ + id: "corporate_compliance", + label: "Corporate / Entity Compliance", + status: "yellow", + detail: `${entityType} — could not locate entity record in ${state} Secretary of State database. ` + + `This may mean the entity is registered under a different name or in a different state. ` + + `Performance West can verify your entity status and handle any needed filings.`, + }); + } else { + // Lookup failed/timed out — informational only + checks.push({ + id: "corporate_compliance", + label: "Corporate / Entity Compliance", + status: "yellow", + detail: `${entityType} registered in ${state} — most states require annual reports, ` + + `franchise tax filings, and a registered agent. Failure to file can result in ` + + `administrative dissolution and loss of liability protection. ` + + `Performance West can handle your annual filings and registered agent service.`, + }); + } + } else if (isFormalEntity) { + // No state to check against const entityType = isLLC ? "LLC" : isCorp ? "Corporation" : isLTD ? "Ltd" : "LP/LLP"; checks.push({ id: "corporate_compliance", label: "Corporate / Entity Compliance", status: "yellow", - detail: `${entityType} registered in ${state || "your state"} — most states require annual reports, ` - + `franchise tax filings, and a registered agent. Failure to file can result in ` - + `administrative dissolution and loss of liability protection. ` + detail: `${entityType} — most states require annual reports, ` + + `franchise tax filings, and a registered agent. ` + `Performance West can handle your annual filings and registered agent service.`, }); } else {