From f9b401379e38b3baa37501346517b43cc493754a Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:52:23 +0530 Subject: [PATCH] fix: allow stringification for subscription properties only --- src/v0/destinations/clevertap/transform.js | 10 +- .../destinations/clevertap/processor/data.ts | 91 ++++++------------- .../destinations/clevertap/router/data.ts | 13 +-- 3 files changed, 40 insertions(+), 74 deletions(-) diff --git a/src/v0/destinations/clevertap/transform.js b/src/v0/destinations/clevertap/transform.js index 8041c8feef..b369f507f8 100644 --- a/src/v0/destinations/clevertap/transform.js +++ b/src/v0/destinations/clevertap/transform.js @@ -83,16 +83,21 @@ const responseWrapper = (payload, destination) => { } * } - * This function stringify the payload attributes if it's an array or objects. + * This function stringify the payload attributes if it's an array or objects. The keys that are not stringified are present in the `stringifyExcludeList` array. * @param {*} payload * @returns * return the final payload after converting to the relevant data-types. */ const convertObjectAndArrayToString = (payload, event) => { const finalPayload = {}; + const stringifyExcludeList = ['category-unsubscribe', 'category-resubscribe']; if (payload) { Object.keys(payload).forEach((key) => { - if (payload[key] && (Array.isArray(payload[key]) || typeof payload[key] === 'object')) { + if ( + payload[key] && + (Array.isArray(payload[key]) || typeof payload[key] === 'object') && + !stringifyExcludeList.includes(key) + ) { finalPayload[key] = JSON.stringify(payload[key]); } else { finalPayload[key] = payload[key]; @@ -225,6 +230,7 @@ const getClevertapProfile = (message, category) => { ['traits', 'context.traits'], CLEVERTAP_DEFAULT_EXCLUSION, ); + profile = convertObjectAndArrayToString(profile); // Add additional properties being passed inside overrideFields in traits or contextual traits // to be added to the profile object, to be sent into Clevertap profileData diff --git a/test/integrations/destinations/clevertap/processor/data.ts b/test/integrations/destinations/clevertap/processor/data.ts index 936f167ff4..6309c5ec8a 100644 --- a/test/integrations/destinations/clevertap/processor/data.ts +++ b/test/integrations/destinations/clevertap/processor/data.ts @@ -99,15 +99,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', 'category-unsubscribe': { email: ['Marketing', 'Transactional'] }, }, identity: 'anon_id', @@ -249,15 +244,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', }, identity: 'anon_id', }, @@ -980,15 +970,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', }, identity: 'anon_id', }, @@ -1128,15 +1113,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', }, identity: 'anon_id', }, @@ -1714,15 +1694,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', }, ts: 1615377562, identity: 'anon_id', @@ -2104,15 +2079,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', first_name: 'John', last_name: 'Doe', }, @@ -2262,15 +2232,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', first_name: 'John', last_name: 'Doe', }, diff --git a/test/integrations/destinations/clevertap/router/data.ts b/test/integrations/destinations/clevertap/router/data.ts index 4db45d43ec..5f25bbe83e 100644 --- a/test/integrations/destinations/clevertap/router/data.ts +++ b/test/integrations/destinations/clevertap/router/data.ts @@ -162,15 +162,10 @@ export const data = [ msgSms: true, msgemail: true, msgwhatsapp: false, - custom_tags: ['Test_User', 'Interested_User', 'DIY_Hobby'], - custom_mappings: { Office: 'Trastkiv', Country: 'Russia' }, - address: { - city: 'kolkata', - country: 'India', - postalCode: 789223, - state: 'WB', - street: '', - }, + address: + '{"city":"kolkata","country":"India","postalCode":789223,"state":"WB","street":""}', + custom_mappings: '{"Office":"Trastkiv","Country":"Russia"}', + custom_tags: '["Test_User","Interested_User","DIY_Hobby"]', }, objectId: 'anon_id', },