// Code by Zapier Input Data: response = MCP Content Text; domain and service = current loop values. // The thresholds below are illustrative rules chosen by the seller. const data = JSON.parse(inputData.response); const checked = new Date().toISOString(); const result = (state, score, evidence) => ({state, score, evidence, checked_at: checked}); if (data.status === "pending") { return result("awaiting_result", "Pending", "The company analysis is still running."); } if (data.status !== "done") { return result("needs_review", "Needs review", data.error || "The analysis did not finish successfully."); } const expected = String(inputData.domain || "").trim().toLowerCase(); const service = String(inputData.service || "").trim().toLowerCase(); if (!expected || data.company?.domain !== expected) { return result("needs_review", "Needs review", "The returned company does not match the requested company domain."); } if (!service) { return result("needs_review", "Needs review", "Provide the canonical domain of the service you want to score."); } const observation = Date.parse(data.dataDate || ""); const age = Date.now() - observation; if (data.stale !== false || data.partial !== false || !Number.isFinite(observation) || age < 0 || age >= 30 * 24 * 60 * 60 * 1000) { return result("needs_review", "Needs review", "Review the analysis date, freshness and coverage before scoring."); } const match = Array.isArray(data.services) && data.services.find(item => item.domain === service); if (!match) { return result("needs_review", "Needs review", `No finding for ${service} in this analysis; coverage varies and absence does not prove non-use.`); } const headcount = data.company.headcount; const adoption = match.adoptionPercent; const validSize = typeof headcount === "number" && Number.isFinite(headcount) && headcount > 0; const validAdoption = typeof adoption === "number" && Number.isFinite(adoption) && adoption >= 0 && adoption <= 100; const evidence = `${service} found. Analysis data date: ${data.dataDate}. `; if (!validSize || !validAdoption) { const missing = [!validSize && "headcount", !validAdoption && "adoption estimate"].filter(Boolean).join(" and "); return result("needs_review", "Incomplete", evidence + `Missing ${missing}; unknown inputs are not scored as zero.`); } const sizePoint = headcount >= 51 && headcount <= 500 ? 1 : 0; const adoptionPoint = adoption >= 20 ? 1 : 0; const score = 1 + sizePoint + adoptionPoint; return result("complete", `${score} / 3`, evidence + `Relevant service: 1; size 51–500: ${sizePoint}; estimated adoption at least 20%: ${adoptionPoint}. ` + "Illustrative research priority, not buying probability.");