/** Pure shared projection of gateway profiles into the existing entity-card contract. */ export type ApolloPersonEnvelope = { person: { search_match?: { derivedFields: string[]; basis: "current_title" | "employment_title"; }; name?: string; first_name?: string; last_name?: string; email?: string; work_email?: string; personal_email?: string; photo_url?: string; linkedin_url?: string; title?: string; headline?: string; location?: string; organization?: { name?: string; domain?: string; website_url?: string; }; organization_name?: string; contact: { phone_numbers: Array<{ sanitized_number: string; raw_number?: string; }>; }; }; }; export type EnrichedPersonUpsertLike = { avatarUrl?: string; searchMatch?: { derivedFields: string[]; basis: "current_title" | "employment_title"; }; fullName?: string; firstName?: string; lastName?: string; headline?: string; /** Structured title from the person's current role (distinct from headline). */ currentTitle?: string; linkedinID?: string; location?: string; locationName?: string; currentCompanyName?: string; currentCompanyWebsite?: string; emails?: Array<{ address?: string; normalizedAddress?: string; type?: string; }>; phones?: Array<{ number?: string; normalizedNumber?: string }>; }; export function shapePersonToApolloEnvelope( u: EnrichedPersonUpsertLike, ): ApolloPersonEnvelope { const workEmail = u.emails?.find((e) => e.type === "work")?.address; const personalEmail = u.emails?.find((e) => e.type === "personal")?.address; const anyEmail = u.emails?.[0]?.address; const companyName = u.currentCompanyName; const companyWebsite = u.currentCompanyWebsite; return { person: { ...(u.searchMatch ? { search_match: u.searchMatch } : {}), name: u.fullName, first_name: u.firstName, last_name: u.lastName, email: workEmail ?? anyEmail, work_email: workEmail, personal_email: personalEmail, photo_url: u.avatarUrl, linkedin_url: u.linkedinID ? `https://www.linkedin.com/in/${u.linkedinID}` : undefined, title: u.currentTitle, headline: u.headline, location: u.location ?? u.locationName, organization: companyName || companyWebsite ? { name: companyName, domain: companyWebsite, website_url: companyWebsite, } : undefined, organization_name: companyName, contact: { phone_numbers: (u.phones ?? []).map((p) => ({ sanitized_number: p.normalizedNumber ?? p.number ?? "", raw_number: p.number, })), }, }, }; } // --------------------------------------------------------------------------- // Organization-shape envelope (preserves COMPANY_ENRICHMENT_COLUMNS paths) // --------------------------------------------------------------------------- export type ApolloCompanyEnvelope = { organization: { name?: string; domain?: string; website_url?: string; industry?: string; industry_list?: string[]; specialties?: string[]; linkedin_url?: string; founded_year?: number; headcount?: number; headcount_range?: string; total_funding?: number; description?: string; hq_city?: string; hq_country?: string; hq_country_code?: string; hq_location?: string; }; }; export type EnrichedCompanyUpsertLike = { name?: string; website?: string; industry?: string; industryList?: string[]; specialties?: string[]; linkedinUrl?: string; founded?: number; headcount?: number; headcountRange?: string; totalFunding?: number; description?: string; hqAddress?: { line1?: string; line2?: string; city?: string; region?: string; country?: string; countryCode?: string; }; }; export function shapeCompanyToApolloEnvelope( c: EnrichedCompanyUpsertLike, ): ApolloCompanyEnvelope { const hq = c.hqAddress; const city = hq?.city; const country = hq?.country ?? hq?.countryCode; const hqLocationParts = [city ?? hq?.line1, hq?.region, country].filter( (v): v is string => typeof v === "string" && v.length > 0, ); return { organization: { name: c.name, domain: c.website, website_url: c.website, industry: c.industry, industry_list: c.industryList, specialties: c.specialties, linkedin_url: c.linkedinUrl, founded_year: c.founded, headcount: c.headcount, headcount_range: c.headcountRange, total_funding: c.totalFunding, description: c.description, hq_city: city, hq_country: hq?.country, hq_country_code: hq?.countryCode, hq_location: hq?.line2?.trim() || (hqLocationParts.length > 0 ? [...new Set(hqLocationParts)].join(", ") : undefined), }, }; }