import assert from "assert"; import { RawEvent, NormalizedEvent } from "../../types"; export default (event: RawEvent): NormalizedEvent<"customer_io"> => { assert(event, `Customer.io:Customers null event: ${event}`); assert( event.id, `Customer.io:Customers event is missing the required field id ${JSON.stringify( event )}` ); //NOTE: All of the data grabbed from attributes is speculative but works for speicific teams. We can do this with confidence because if the data doesn't exist the field will be null. // //TODO: In the future we should build a more general system which looks for common fields return { id: `customer_io|${event.id}`, ts: 1000 * (parseInt(event.attributes.created_at) || 0), user_info: { source_user_id: null, user_id: event.id || event.attributes.id || null, name: event.attributes.name || (event.attributes.firstName && event.attributes.lastName && `${event.attributes.firstName} ${event.attributes.lastName}`) || event.attributes.firstName || event.attributes.lastName || null, email: event.attributes.email || null, ip: null, avatar: event.attributes.avatar || null, nickname: null, phone: event.attributes.phone || null, city: null, continent_code: null, country: null, postal_code: event.attributes.zipCode || null, region: null, timezone: null, country_code: null, address_line1: null, address_line2: null, user_agent: null, is_employee: null, title: null, birthday: null, company: { name: null, id: null, industry: null, employee_count: null, plan: null }, created_at: 1000 * parseInt(event.attributes.created_at) || null, age: null, gender: null, website: null, custom_attributes: null }, text: `Customer Created`, href: `https://fly.customer.io/env/1/people/${event.id || event.attributes.id}`, is_bad: false, direction: null, source: "customer_io", stream: "customers" }; };