diff --git a/packages/destination-actions/src/destinations/insider/insider-helpers.ts b/packages/destination-actions/src/destinations/insider/insider-helpers.ts index 23235dc79c..1869e70451 100644 --- a/packages/destination-actions/src/destinations/insider/insider-helpers.ts +++ b/packages/destination-actions/src/destinations/insider/insider-helpers.ts @@ -1,3 +1,5 @@ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck import { Payload as UserPayload } from './updateUserProfile/generated-types' import { Payload as TrackEventPayload } from './trackEvent/generated-types' import { Payload as CartViewedEventPayload } from './cartViewedEvent/generated-types' @@ -28,6 +30,44 @@ export interface upsertUserPayload { events: insiderEvent[] } +const defaultAttributes = [ + 'email', + 'phone', + 'age', + 'birthday', + 'name', + 'gender', + 'surname', + 'city', + 'country', + 'app_version', + 'idfa', + 'model', + 'last_ip', + 'carrier', + 'os_version', + 'platform', + 'timezone', + 'locale' +] +const defaultEvents = [ + 'campaign_id', + 'campaign_name', + 'url', + 'product_id', + 'user_agent', + 'taxonomy', + 'name', + 'variant_id', + 'unit_sale_price', + 'unit_price', + 'quantity', + 'product_image_url', + 'event_group_id', + 'referrer', + 'currency' +] + export function userProfilePayload(data: UserPayload) { const identifiers = { uuid: data.uuid, @@ -36,22 +76,11 @@ export function userProfilePayload(data: UserPayload) { } } - if (data.custom_identifiers) { - identifiers.custom = { - ...identifiers.custom, - ...data.custom_identifiers - } - } - if (data.email_as_identifier) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['email'] = data.email } if (data.phone_number_as_identifier) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['phone_number'] = data.phone } @@ -121,16 +150,10 @@ export function sendTrackEvent( parameter = parameter.toString().toLowerCase().trim().split(' ').join('_') if (parameter === 'taxonomy') { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event.event_params[parameter] = [data[parameter]] } else if (defaultEvents.indexOf(parameter) > -1) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event.event_params[parameter] = data[parameter] } else if (data) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event.event_params.custom[parameter] = data[parameter] } @@ -144,89 +167,32 @@ export function sendTrackEvent( } } - if (data.custom_identifiers) { - identifiers.custom = { - ...identifiers.custom, - ...data.custom_identifiers - } - } - if (data.email_as_identifier && data?.attributes?.email) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['email'] = data?.attributes?.email } if (data.phone_number_as_identifier && data?.attributes?.phone) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['phone_number'] = data?.attributes?.phone } const payload: upsertUserPayload = { identifiers, attributes: { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore custom: {} }, events: [] } - const defaultAttributes = [ - 'email', - 'phone', - 'age', - 'birthday', - 'name', - 'gender', - 'surname', - 'city', - 'country', - 'app_version', - 'idfa', - 'model', - 'last_ip', - 'carrier', - 'os_version', - 'platform', - 'timezone', - 'locale' - ] - const defaultEvents = [ - 'campaign_id', - 'campaign_name', - 'url', - 'product_id', - 'user_agent', - 'taxonomy', - 'name', - 'variant_id', - 'unit_sale_price', - 'unit_price', - 'quantity', - 'product_image_url', - 'event_group_id', - 'referrer', - 'currency' - ] - for (const key of Object.keys(data.attributes || {})) { const attributeName: string = key.toString().toLowerCase().trim().split(' ').join('_').toString() if (attributeName === 'locale' && data.attributes) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore payload.attributes[attributeName as keyof typeof payload.attributes] = data.attributes[attributeName] ?.split('-') .join('_') } else if (defaultAttributes.indexOf(attributeName) > -1 && data.attributes) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore payload.attributes[attributeName as keyof typeof payload.attributes] = data.attributes[attributeName] } else if (data.attributes) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore payload.attributes.custom[attributeName as keyof typeof payload.attributes.custom] = data.attributes[attributeName] } @@ -236,32 +202,32 @@ export function sendTrackEvent( event_name, timestamp: data.timestamp.toString(), event_params: { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore custom: {} } } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore for (const key of Object.keys(data.parameters || {})) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event = addEventParameters(event, data.parameters, key) } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore if (data.products) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore for (const product of data.products) { - let productEvent = event + let productEvent: insiderEvent = { + event_name, + timestamp: data.timestamp.toString(), + event_params: { + custom: {} + } + } for (const key of Object.keys(product || {})) { productEvent = addEventParameters(productEvent, product, key) } + for (const key of Object.keys(data.parameters || {})) { + productEvent = addEventParameters(productEvent, data.parameters, key) + } + payload.events.push(productEvent) } } else { @@ -285,14 +251,10 @@ export function bulkUserProfilePayload(data: UserPayload[]) { } if (userPayload.email_as_identifier) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['email'] = userPayload.email } if (userPayload.phone_number_as_identifier) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['phone_number'] = userPayload.phone } @@ -373,16 +335,10 @@ export function sendBulkTrackEvents( parameter = parameter.toString().toLowerCase().trim().split(' ').join('_') if (parameter === 'taxonomy') { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event.event_params[parameter] = [data[parameter]] } else if (defaultEvents.indexOf(parameter) > -1) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event.event_params[parameter] = data[parameter] } else if (data) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event.event_params.custom[parameter] = data[parameter] } @@ -396,129 +352,70 @@ export function sendBulkTrackEvents( } } - if (data.custom_identifiers) { - identifiers.custom = { - ...identifiers.custom, - ...data.custom_identifiers - } - } - if (data.email_as_identifier && data?.attributes?.email) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['email'] = data?.attributes?.email } if (data.phone_number_as_identifier && data?.attributes?.phone) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore identifiers['phone_number'] = data?.attributes?.phone } const payload: upsertUserPayload = { identifiers, attributes: { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore custom: {} }, not_append: true, events: [] } - const defaultAttributes = [ - 'email', - 'phone', - 'age', - 'birthday', - 'name', - 'gender', - 'surname', - 'city', - 'country', - 'app_version', - 'idfa', - 'model', - 'last_ip', - 'carrier', - 'os_version', - 'platform', - 'timezone', - 'locale' - ] - const defaultEvents = [ - 'campaign_id', - 'campaign_name', - 'url', - 'product_id', - 'user_agent', - 'taxonomy', - 'name', - 'variant_id', - 'unit_sale_price', - 'unit_price', - 'quantity', - 'product_image_url', - 'event_group_id', - 'referrer', - 'currency' - ] - for (const key of Object.keys(data.attributes || {})) { const attributeName: string = key.toString().toLowerCase().trim().split(' ').join('_').toString() if (attributeName === 'locale' && data.attributes) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore payload.attributes[attributeName as keyof typeof payload.attributes] = data.attributes[attributeName] ?.split('-') .join('_') } else if (defaultAttributes.indexOf(attributeName) > -1 && data.attributes) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore payload.attributes[attributeName as keyof typeof payload.attributes] = data.attributes[attributeName] } else if (data.attributes) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore payload.attributes.custom[attributeName as keyof typeof payload.attributes.custom] = data.attributes[attributeName] } } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore const eventName = event_name || data.event_name.toString().toLowerCase().trim().split(' ').join('_').toString() let event: insiderEvent = { event_name: eventName, timestamp: data.timestamp.toString(), event_params: { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore custom: {} } } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore for (const key of Object.keys(data.parameters || {})) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore event = addEventParameters(event, data.parameters, key) } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore if (data.products) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore for (const product of data.products) { - let productEvent = event + let productEvent: insiderEvent = { + event_name: eventName, + timestamp: data.timestamp.toString(), + event_params: { + custom: {} + } + } for (const key of Object.keys(product || {})) { productEvent = addEventParameters(productEvent, product, key) } + for (const key of Object.keys(data.parameters || {})) { + productEvent = addEventParameters(productEvent, data.parameters, key) + } + payload.events.push(productEvent) } } else { diff --git a/packages/destination-actions/src/destinations/insider/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/insider/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap index 5735360a36..47285c986d 100644 --- a/packages/destination-actions/src/destinations/insider/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/insider/trackEvent/__tests__/__snapshots__/snapshot.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Testing snapshot for Insider's trackEvent destination action: all fields 1`] = `"{\\"users\\":[{\\"identifiers\\":{\\"uuid\\":\\"Ef*GhBp7kEUO\\",\\"custom\\":{\\"segment_anonymous_id\\":\\"Ef*GhBp7kEUO\\"},\\"email\\":\\"tuoc@giciwco.net\\",\\"phone_number\\":\\"Ef*GhBp7kEUO\\"},\\"attributes\\":{\\"custom\\":{},\\"email\\":\\"tuoc@giciwco.net\\",\\"phone\\":\\"Ef*GhBp7kEUO\\",\\"age\\":-10845372872130.56,\\"birthday\\":\\"Ef*GhBp7kEUO\\",\\"name\\":\\"Ef*GhBp7kEUO\\",\\"gender\\":\\"Ef*GhBp7kEUO\\",\\"surname\\":\\"Ef*GhBp7kEUO\\",\\"app_version\\":\\"Ef*GhBp7kEUO\\",\\"idfa\\":\\"Ef*GhBp7kEUO\\",\\"model\\":\\"Ef*GhBp7kEUO\\",\\"last_ip\\":\\"Ef*GhBp7kEUO\\",\\"city\\":\\"Ef*GhBp7kEUO\\",\\"country\\":\\"Ef*GhBp7kEUO\\",\\"carrier\\":\\"Ef*GhBp7kEUO\\",\\"os_version\\":\\"Ef*GhBp7kEUO\\",\\"platform\\":\\"Ef*GhBp7kEUO\\",\\"timezone\\":\\"Ef*GhBp7kEUO\\",\\"locale\\":\\"Ef*GhBp7kEUO\\"},\\"events\\":[{\\"event_name\\":\\"ef*ghbp7keuo\\",\\"timestamp\\":\\"2021-02-01T00:00:00.000Z\\",\\"event_params\\":{\\"custom\\":{},\\"url\\":\\"Ef*GhBp7kEUO\\",\\"currency\\":\\"LTL\\",\\"product_id\\":\\"Ef*GhBp7kEUO\\",\\"taxonomy\\":[\\"Ef*GhBp7kEUO\\"],\\"name\\":\\"Ef*GhBp7kEUO\\",\\"variant_id\\":-10845372872130.56,\\"unit_sale_price\\":-10845372872130.56,\\"unit_price\\":-10845372872130.56,\\"quantity\\":-1084537287213056,\\"product_image_url\\":\\"Ef*GhBp7kEUO\\",\\"event_group_id\\":\\"Ef*GhBp7kEUO\\",\\"referrer\\":\\"Ef*GhBp7kEUO\\",\\"user_agent\\":\\"Ef*GhBp7kEUO\\"}}],\\"not_append\\":false}],\\"platform\\":\\"segment\\"}"`; +exports[`Testing snapshot for Insider's trackEvent destination action: all fields 1`] = `"{\\"users\\":[{\\"identifiers\\":{\\"uuid\\":\\"Ef*GhBp7kEUO\\",\\"custom\\":{\\"segment_anonymous_id\\":\\"Ef*GhBp7kEUO\\"},\\"email\\":\\"tuoc@giciwco.net\\",\\"phone_number\\":\\"Ef*GhBp7kEUO\\"},\\"attributes\\":{\\"custom\\":{},\\"email\\":\\"tuoc@giciwco.net\\",\\"phone\\":\\"Ef*GhBp7kEUO\\",\\"age\\":-10845372872130.56,\\"birthday\\":\\"Ef*GhBp7kEUO\\",\\"name\\":\\"Ef*GhBp7kEUO\\",\\"gender\\":\\"Ef*GhBp7kEUO\\",\\"surname\\":\\"Ef*GhBp7kEUO\\",\\"app_version\\":\\"Ef*GhBp7kEUO\\",\\"idfa\\":\\"Ef*GhBp7kEUO\\",\\"model\\":\\"Ef*GhBp7kEUO\\",\\"last_ip\\":\\"Ef*GhBp7kEUO\\",\\"city\\":\\"Ef*GhBp7kEUO\\",\\"country\\":\\"Ef*GhBp7kEUO\\",\\"carrier\\":\\"Ef*GhBp7kEUO\\",\\"os_version\\":\\"Ef*GhBp7kEUO\\",\\"platform\\":\\"Ef*GhBp7kEUO\\",\\"timezone\\":\\"Ef*GhBp7kEUO\\",\\"locale\\":\\"Ef*GhBp7kEUO\\"},\\"events\\":[{\\"event_name\\":\\"ef*ghbp7keuo\\",\\"timestamp\\":\\"2021-02-01T00:00:00.000Z\\",\\"event_params\\":{\\"custom\\":{},\\"product_id\\":\\"Ef*GhBp7kEUO\\",\\"taxonomy\\":[\\"Ef*GhBp7kEUO\\"],\\"name\\":\\"Ef*GhBp7kEUO\\",\\"unit_sale_price\\":-10845372872130.56,\\"unit_price\\":-10845372872130.56,\\"quantity\\":-1084537287213056,\\"url\\":\\"Ef*GhBp7kEUO\\",\\"product_image_url\\":\\"Ef*GhBp7kEUO\\",\\"currency\\":\\"LTL\\",\\"variant_id\\":-10845372872130.56,\\"event_group_id\\":\\"Ef*GhBp7kEUO\\",\\"referrer\\":\\"Ef*GhBp7kEUO\\",\\"user_agent\\":\\"Ef*GhBp7kEUO\\"}}],\\"not_append\\":false}],\\"platform\\":\\"segment\\"}"`; exports[`Testing snapshot for Insider's trackEvent destination action: required fields 1`] = `"{\\"users\\":[{\\"identifiers\\":{\\"uuid\\":\\"Ef*GhBp7kEUO\\",\\"custom\\":{\\"segment_anonymous_id\\":\\"Ef*GhBp7kEUO\\"}},\\"attributes\\":{\\"custom\\":{}},\\"events\\":[{\\"event_name\\":\\"ef*ghbp7keuo\\",\\"timestamp\\":\\"2021-02-01T00:00:00.000Z\\",\\"event_params\\":{\\"custom\\":{}}}],\\"not_append\\":true}],\\"platform\\":\\"segment\\"}"`;