import assert from "assert"; import { RawEvent, NormalizedEvent, Direction } from "../../types"; export default (event: RawEvent): NormalizedEvent<"hubspot"> => { assert(event, `Hubspot:email_events null event: ${event}`); assert( event.id, `Hubspot:email_events event is missing the required field id ${event}` ); assert( event.created, `Hubspot:created event is missing the required field created ${event}` ); let email = event.recipient; let text = ""; let is_bad = false; let direction: Direction = null; switch (event.type) { case "SENT": text = "Attempting to Send Email"; direction = "outbound"; break; case "DROPPED": text = "Email Dropped"; is_bad = true; break; case "PROCESSED": text = "Email Processed"; direction = "outbound"; break; case "DELIVERED": text = "Email Delivered"; direction = "outbound"; break; case "DEFERRED": text = "Email Deffered. It will be retried"; is_bad = true; break; case "BOUNCE": text = "Email Bounced"; is_bad = true; break; case "OPEN": text = "Email Opened"; break; case "CLICK": text = "Link Clicked"; direction = "inbound"; break; case "STATUSCHANGE": text = "Email subscription status changed"; is_bad = true; direction = "inbound"; break; case "SPAMREPORT": text = "Email was reported as spam"; is_bad = true; direction = "inbound"; break; case "UNBOUNCE": text = "Email was unbounced"; is_bad = true; email = event.user; break; default: text = `Unknown Hubspot Email Event - ${event.type}`; break; } return { id: `hubspot|${event.id}`, ts: Date.parse(event.created), user_info: { source_user_id: null, user_id: null, name: null, email: email || null, title: null, birthday: null, company: { name: null, id: null, industry: null, employee_count: null, plan: null }, created_at: null, age: null, gender: null, website: null, ip: null, avatar: null, nickname: null, phone: null, city: null, country: null, postal_code: null, region: null, address_line1: null, continent_code: null, address_line2: null, country_code: null, timezone: null, user_agent: null, is_employee: null, custom_attributes: null }, text, href: null, is_bad, direction, source: "hubspot", stream: "email_events" }; };