Skip to content

Commit

Permalink
Insider | SD-107645 | Products ingesting incorrectly (#2148)
Browse files Browse the repository at this point in the history
* new workflow added

* SECURITY | Add SECURITY.MD

* SD-107645 | Products ingesting incorrectly

* SD-107645 | Products ingesting incorrectly

* SD-107645 | Products ingesting incorrectly

* SD-107645 | Products ingesting incorrectly

* SD-107645 | Products ingesting incorrectly

* SD-107645 | Products ingesting incorrectly

* SD-107645 | Products ingesting incorrectly

---------

Co-authored-by: insider-automation <117348511+insider-automation@users.noreply.github.com>
Co-authored-by: Sezer Güven <70070685+esezerguven@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent a93fe13 commit 042ea5d
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 174 deletions.
206 changes: 62 additions & 144 deletions packages/destination-actions/src/destinations/insider/insider-helpers.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -44,14 +84,10 @@ export function userProfilePayload(data: UserPayload) {
}

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
}

Expand Down Expand Up @@ -121,16 +157,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]
}

Expand All @@ -152,81 +182,31 @@ export function sendTrackEvent(
}

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]
}
Expand All @@ -236,32 +216,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 {
Expand All @@ -285,14 +265,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
}

Expand Down Expand Up @@ -373,16 +349,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]
}

Expand All @@ -404,121 +374,69 @@ export function sendBulkTrackEvents(
}

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 {
Expand Down
Loading

0 comments on commit 042ea5d

Please sign in to comment.