diff --git a/src/cdk/v2/destinations/the_trade_desk/config.js b/src/cdk/v2/destinations/the_trade_desk/config.js index fb7271a916..0e2bbb4c69 100644 --- a/src/cdk/v2/destinations/the_trade_desk/config.js +++ b/src/cdk/v2/destinations/the_trade_desk/config.js @@ -61,17 +61,6 @@ const CONFIG_CATEGORIES = { ITEM_CONFIGS: { name: 'TTDItemConfig' }, }; -const ITEM_EXCLUSION_LIST = [ - 'product_id', - 'sku', - 'name', - 'price', - 'quantity', - 'cat', - 'category_id', - 'categoryId', -]; - const MAPPING_CONFIG = getMappingConfig(CONFIG_CATEGORIES, __dirname); module.exports = { @@ -86,5 +75,4 @@ module.exports = { ITEM_CONFIGS: MAPPING_CONFIG[CONFIG_CATEGORIES.ITEM_CONFIGS.name], ECOMM_EVENT_MAP, REAL_TIME_CONVERSION_ENDPOINT, - ITEM_EXCLUSION_LIST, }; diff --git a/src/cdk/v2/destinations/the_trade_desk/utils.js b/src/cdk/v2/destinations/the_trade_desk/utils.js index 5ba4060afd..64c5f2b78a 100644 --- a/src/cdk/v2/destinations/the_trade_desk/utils.js +++ b/src/cdk/v2/destinations/the_trade_desk/utils.js @@ -9,6 +9,7 @@ const { isAppleFamily, getIntegrationsObj, extractCustomFields, + generateExclusionList, } = require('../../../../v0/util'); const { DATA_SERVERS_BASE_ENDPOINTS_MAP, @@ -16,7 +17,6 @@ const { COMMON_CONFIGS, ITEM_CONFIGS, ECOMM_EVENT_MAP, - ITEM_EXCLUSION_LIST, } = require('./config'); const getTTLInMin = (ttl) => parseInt(ttl, 10) * 1440; @@ -97,7 +97,8 @@ const prepareItemsFromProducts = (message) => { const items = []; products.forEach((product) => { const item = constructPayload(product, ITEM_CONFIGS); - extractCustomFields(product, item, 'root', ITEM_EXCLUSION_LIST); + const itemExclusionList = generateExclusionList(ITEM_CONFIGS); + extractCustomFields(product, item, 'root', itemExclusionList); items.push(item); }); return items; @@ -301,7 +302,8 @@ const enrichTrackPayload = (message, payload) => { const eventsMapInfo = ECOMM_EVENT_MAP[message.event.toLowerCase()]; // checking if event is an ecomm one and itemsArray/products support is not present. e.g Product Added event if (eventsMapInfo && !eventsMapInfo.itemsArray) { - rawPayload = extractCustomFields(message, rawPayload, ['properties'], ITEM_EXCLUSION_LIST); + const itemExclusionList = generateExclusionList(ITEM_CONFIGS); + rawPayload = extractCustomFields(message, rawPayload, ['properties'], itemExclusionList); } else { // for custom events rawPayload = extractCustomFields( diff --git a/src/v0/util/index.js b/src/v0/util/index.js index c7a26b6a2f..5080b1f95d 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -1279,6 +1279,31 @@ function getFullName(message) { return fullName; } +/** + * Generates an exclusion list from mapping config. + * + * @param {Array} mappingConfig - The mapping config. + * [ + * { + * "destKey": "item_code", + * "sourceKeys": [ + * "product_id", + * "sku" + * ] + * }, + * { + * "destKey": "name", + * "sourceKeys": "name" + * } + * ] + * @returns {Array} - The generated exclusion list. + * ["product_id", "sku", "name"] + */ +const generateExclusionList = (mappingConfig) => + mappingConfig.flatMap((mapping) => + Array.isArray(mapping.sourceKeys) ? [...mapping.sourceKeys] : [mapping.sourceKeys], + ); + /** * Extract fileds from message with exclusions * Pass the keys of message for extraction and @@ -2132,6 +2157,7 @@ module.exports = { defaultPutRequestConfig, defaultRequestConfig, deleteObjectProperty, + generateExclusionList, extractCustomFields, flattenJson, flattenMap,