Skip to content

Commit

Permalink
feat: added generate exclusion list utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Feb 1, 2024
1 parent 13fd161 commit ed04829
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
12 changes: 0 additions & 12 deletions src/cdk/v2/destinations/the_trade_desk/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
};
8 changes: 5 additions & 3 deletions src/cdk/v2/destinations/the_trade_desk/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const {
isAppleFamily,
getIntegrationsObj,
extractCustomFields,
generateExclusionList,
} = require('../../../../v0/util');
const {
DATA_SERVERS_BASE_ENDPOINTS_MAP,
CONVERSION_SUPPORTED_ID_TYPES,
COMMON_CONFIGS,
ITEM_CONFIGS,
ECOMM_EVENT_MAP,
ITEM_EXCLUSION_LIST,
} = require('./config');

const getTTLInMin = (ttl) => parseInt(ttl, 10) * 1440;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2132,6 +2157,7 @@ module.exports = {
defaultPutRequestConfig,
defaultRequestConfig,
deleteObjectProperty,
generateExclusionList,
extractCustomFields,
flattenJson,
flattenMap,
Expand Down

0 comments on commit ed04829

Please sign in to comment.