/* eslint-disable */ /* © 2026 K2B NETWORK SOLUTIONS LLC. All rights reserved. Proprietary and confidential. Unauthorized copying, distribution, or use of this file, via any medium, is strictly prohibited. Original work product. */ // JBREWS DMS — Carfax integration (shared). // One Carfax service used everywhere: VIN Decoder, Service, Sales/Inventory. // • window.jbCarfax — VIN decode, in-house history, report URL, open(vin). // • — drop-in button: opens the dealer report in // the shared Carfax tab (add `panel` for the in-DMS history panel). // • — event-driven modal (mounted once in app.jsx); open from // anywhere with window.jbCarfaxOpen(vin, ctx). // NO API KEY. The full report opens in the dealer's own Carfax for Dealers // session: window.K2BApps opens carfaxonline.com in one named browser tab, the // user signs in once, and every CARFAX button afterwards lands straight on the // report for that VIN (ConnectedApps.jsx.txt). The panel here still shows the // real decoded VIN and the dealer's own internal service history for that VIN. // getKey/setKey/getEndpoint/setEndpoint remain as harmless no-ops so older // callers keep working — nothing is stored. (function () { const LINK_KEY = "jbrews-carfax-link"; // legacy template store (used only when K2BApps is absent) const cache = {}; try { localStorage.removeItem("jbrews-carfax-key"); localStorage.removeItem("jbrews-carfax-endpoint"); } catch (e) {} // WMI → make (representative; GM-focused for a Chevrolet store) const WMI = { "1G1": "Chevrolet (car)", "1GC": "Chevrolet (truck)", "1GN": "Chevrolet (SUV)", "1GB": "Chevrolet (van/truck)", "3GC": "Chevrolet (truck, Mexico)", "2G1": "Chevrolet (car, Canada)", "1GT": "GMC (truck)", "1GK": "GMC (SUV)", "1G4": "Buick", "1G6": "Cadillac", "KL7": "Chevrolet (Korea)", "JF1": "Subaru", "1FA": "Ford", "1HG": "Honda", "5YJ": "Tesla", "WBA": "BMW", "WDD": "Mercedes-Benz", }; const YEAR_CODE = { A:2010,B:2011,C:2012,D:2013,E:2014,F:2015,G:2016,H:2017,J:2018,K:2019,L:2020,M:2021,N:2022,P:2023,R:2024,S:2025,T:2026,V:2027,W:2028,X:2029,Y:2030, 1:2001,2:2002,3:2003,4:2004,5:2005,6:2006,7:2007,8:2008,9:2009 }; function decodeVin(vinRaw) { const vin = String(vinRaw || "").toUpperCase().replace(/[^A-Z0-9]/g, ""); if (vin.length < 11) return { vin, valid: false }; const wmi = vin.slice(0, 3); const make = WMI[wmi] || WMI[vin.slice(0, 2)] || "Unknown (WMI " + wmi + ")"; const yearChar = vin[9]; const year = YEAR_CODE[yearChar] || null; const plant = vin[10]; return { vin, valid: vin.length === 17, wmi, make, year, plant, serial: vin.slice(11) }; } const cf = { // Compatibility no-ops — the DMS no longer holds Carfax API keys anywhere. getKey() { return ""; }, setKey() {}, getEndpoint() { return ""; }, setEndpoint() {}, // "configured" now means: signed in to Carfax for Dealers in the named tab. configured() { return !!(window.K2BApps && window.K2BApps.isConnected("carfax")); }, decodeVin, // Public Carfax page for a VIN (what a customer would see; no sign-in). reportUrl(vin) { return "https://www.carfax.com/vehicle/" + encodeURIComponent(String(vin || "").toUpperCase()); }, // Dealer DIRECT LINK — the Carfax for Dealers report URL with {vin} where // the VIN goes. Stored on the Connected App (K2BApps carfax → vin link); // the legacy LINK_KEY store is only used when ConnectedApps isn't loaded. getLinkTemplate() { if (window.K2BApps) { const a = window.K2BApps.get("carfax"); return (a && a.launch && a.launch.vin) || ""; } try { return localStorage.getItem(LINK_KEY) || ""; } catch (e) { return ""; } }, setLinkTemplate(t) { if (window.K2BApps) { window.K2BApps.setTemplate("carfax", "vin", t || ""); return; } try { localStorage.setItem(LINK_KEY, t || ""); } catch (e) {} }, directUrl(vin) { if (window.K2BApps) { const b = window.K2BApps.buildUrl("carfax", { vin: String(vin || "").toUpperCase() }); if (b && b.url) return b.url; } const v = encodeURIComponent(String(vin || "").toUpperCase()); const t = cf.getLinkTemplate(); if (t) return /\{vin\}/i.test(t) ? t.replace(/\{vin\}/gi, v) : t + (t.includes("?") ? "&" : "?") + "vin=" + v; return cf.reportUrl(v); }, // Open the dealer report in the shared Carfax tab (signed-in session reused). open(vin, ctx) { if (window.K2BApps) return window.K2BApps.open("carfax", { vin: String(vin || "").toUpperCase(), ctx }); const w = window.open(cf.directUrl(vin), "k2b-app-carfax"); if (w) { try { w.focus(); } catch (e) {} } return w; }, // Dealer Vehicle History Report (VHR) deep link (legacy helper). dealerReportUrl(vin) { return "https://www.carfaxonline.com/vhrs/" + encodeURIComponent(String(vin || "").toUpperCase()); }, // The dealership's OWN service history for this VIN, straight from the ledger. internalHistory(vin) { const v = String(vin || "").toUpperCase(); const D = window.DMS; if (!D || !v) return []; const ros = (D.repairOrders ? D.repairOrders() : []).filter(r => String(r.vin || "").toUpperCase() === v); const body = (D.bodyShopROs ? D.bodyShopROs() : []).filter(r => String(r.vin || "").toUpperCase() === v); return [...ros.map(r => ({ kind: "Service", id: r.id, date: r.closed || r.opened, desc: r.concern || (r.ops && r.ops[0] && r.ops[0].desc) || "Repair order", status: r.status })), ...body.map(r => ({ kind: "Body Shop", id: r.id, date: r.closed || r.created, desc: r.claimNo ? ("Claim " + r.claimNo) : "Body repair", status: r.status }))] .sort((a, b) => new Date(b.date || 0) - new Date(a.date || 0)); }, // What the DMS knows on its own: decoded VIN + in-house history. The // nationwide report is never fetched here — it opens in the dealer's own // Carfax for Dealers tab (cf.open). No API call, no key, nothing fabricated. async lookup(vin) { const v = String(vin || "").toUpperCase().replace(/[^A-Z0-9]/g, ""); if (!v) return { ok: false, error: "No VIN supplied." }; if (cache[v]) return cache[v]; const decode = decodeVin(v); const internal = cf.internalHistory(v); const res = { ok: true, vin: v, decode, internal, live: null, error: null, configured: cf.configured(), hasEndpoint: false }; cache[v] = res; return res; }, clearCache() { Object.keys(cache).forEach(k => delete cache[k]); }, }; window.jbCarfax = cf; })(); // ── Shared button ──────────────────────────────────────────────────────── // Opens the dealer's Carfax report for the VIN in the shared signed-in tab // (window.K2BApps.open("carfax", {vin})). Pass `panel` to open the in-DMS // panel (decoded VIN + in-house history) instead. Hidden when the Carfax app // is turned off under Integrations. const CarfaxButton = ({ vin, ctx, small, style, panel }) => { const A = window.K2BApps; if (A && !A.isEnabled("carfax")) return null; const launch = () => { if (panel || !A) { window.jbCarfaxOpen && window.jbCarfaxOpen(vin, ctx); return; } A.open("carfax", { vin, ctx }); }; return ( ); }; // ── Event-driven modal host (mount once) ────────────────────────────────── const CarfaxHost = () => { const [open, setOpen] = React.useState(null); // { vin, ctx } React.useEffect(() => { window.jbCarfaxOpen = (vin, ctx) => setOpen({ vin: String(vin || "").toUpperCase(), ctx: ctx || "" }); return () => { delete window.jbCarfaxOpen; }; }, []); if (!open || !open.vin) return null; return setOpen(null)} />; }; const CarfaxModal = ({ vin, ctx, onClose }) => { const cf = window.jbCarfax; const [data, setData] = React.useState(null); const [loading, setLoading] = React.useState(true); const [linkCfg, setLinkCfg] = React.useState(false); const [tpl, setTpl] = React.useState(() => cf.getLinkTemplate()); React.useEffect(() => { let on = true; setLoading(true); cf.lookup(vin).then(r => { if (on) { setData(r); setLoading(false); } }); return () => { on = false; }; }, [vin]); const decode = data && data.decode; const internal = (data && data.internal) || []; const fmtDate = (d) => d ? new Date(d).toLocaleDateString() : "—"; return ( setLinkCfg(v => !v)}>⚙ Direct Link cf.open(vin, ctx)}>Open Carfax Report ▸ Close }> {linkCfg && (
Carfax direct link (from your Carfax for Dealers account)
Open any report in Carfax Online, copy its address and paste it here with {"{vin}"} where the VIN goes — every CARFAX button in the DMS then opens the full dealer report in your signed-in Carfax tab. Same setting as Integrations → Carfax → Link settings.
setTpl(e.target.value)} placeholder="https://www.carfaxonline.com/…?vin={vin}" style={{ flex: 1, fontSize: 12, fontFamily: "var(--jb-mono, monospace)", padding: "6px 8px", border: "1px solid #C8CCD2", borderRadius: 4 }} /> { cf.setLinkTemplate(tpl.trim()); window.k2bToast && window.k2bToast(tpl.trim() ? "Carfax direct link saved — report buttons now use it." : "Direct link cleared — using the public report page.", "ok", 3600); setLinkCfg(false); }}>Save
{tpl.trim() &&
Opens: {/\{vin\}/i.test(tpl) ? tpl.replace(/\{vin\}/gi, vin) : tpl.trim() + (tpl.includes("?") ? "&" : "?") + "vin=" + vin}
}
)}
CARFAX {vin} {ctx && · {ctx}}
{/* connection status — no API key; the report opens in the dealer's own Carfax tab */}
{data && data.configured ? "🔗" : "↗"} {data && data.configured ? "Opens your Carfax for Dealers report — signed in (the DMS reuses your Carfax tab)." : "Opens your Carfax for Dealers report (sign in once) — the DMS keeps that tab and reuses it for every VIN. No API key needed."}
{/* decoded VIN (real) */}
Decoded from VIN
{loading ?
Decoding…
: (
Year
{decode && decode.year || "—"}
Make
{decode && decode.make || "—"}
Plant / Serial
{decode ? (decode.plant + " · " + decode.serial) : "—"}
VIN valid {decode && decode.valid ? "✓ 17-char" : "⚠ check length"}
)}
{/* internal service history (real, from ledger) */}
This dealership's service records for this VIN ({internal.length})
{internal.length === 0 ? (
No in-house service or body records on file for this VIN. The full Carfax report covers nationwide history.
) : ( {internal.map((h, i) => ( ))}
{fmtDate(h.date)} {h.kind} {h.desc} {h.status}
)}
CARFAX is a registered trademark of Carfax, Inc. Live nationwide history (owners, accidents, title, odometer) is provided by Carfax under your dealer subscription.
); }; Object.assign(window, { CarfaxButton, CarfaxHost, CarfaxModal });