From 3cdb8a8932d9fc77818fc821a7e3f56a7ed1ee6a Mon Sep 17 00:00:00 2001 From: Saurav Lal Date: Mon, 7 Nov 2022 13:55:13 +0530 Subject: [PATCH 1/7] stringify the Object and Array from payload --- v0/destinations/clevertap/transform.js | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/v0/destinations/clevertap/transform.js b/v0/destinations/clevertap/transform.js index 66fa883faab..632b5291961 100644 --- a/v0/destinations/clevertap/transform.js +++ b/v0/destinations/clevertap/transform.js @@ -58,6 +58,46 @@ const responseWrapper = (payload, destination) => { return response; }; +/** + * Expected behaviours: + payload = { "finalPayload": { + "device": { "device": "{\"browser\":{\"name\":\"Chrome121\",\"version\":\"106.0.0.0\"},\"os\":{\"version\":\"10.15.7\"}}", + "browser": { "name": "macOS", + "name": "Chrome121", "platform": "web" + "version": "106.0.0.0" } + }, + "os": { + "version": "10.15.7" + } + }, + "name": "macOS", + "platform": "web" + } + * + } + * This function stringify the payload attributes if it's an array or objects. + * @param {*} payload + * @returns + * return the final payload after converting to the relevant data-types. + */ +const convertObjectAndArrayToString = payload => { + const finalPayload = {}; + if (payload) { + const category = Object.keys(payload); + category.forEach(key => { + if ( + payload[key] && + (Array.isArray(payload[key]) || typeof payload[key] === "object") + ) { + finalPayload[key] = JSON.stringify(payload[key]); + } else { + finalPayload[key] = payload[key]; + } + }); + } + return finalPayload; +}; + // generates clevertap identify payload with both objectId and identity const mapIdentifyPayloadWithObjectId = (message, profile) => { const userId = getFieldValueFromMessage(message, "userIdOnly"); @@ -172,6 +212,7 @@ const getClevertapProfile = (message, category) => { ["traits", "context.traits"], CLEVERTAP_DEFAULT_EXCLUSION ); + profile = convertObjectAndArrayToString(profile); return removeUndefinedAndNullValues(profile); }; @@ -267,6 +308,12 @@ const responseBuilderSimple = (message, category, destination) => { eventPayload = constructPayload(message, MAPPING_CONFIG[category.name]); } eventPayload.type = "event"; + // stringify the evtData if it's an Object or array. + if (eventPayload.evtData) { + eventPayload.evtData = convertObjectAndArrayToString( + eventPayload.evtData + ); + } // setting identification for tracking payload here based on destination config if (destination.Config.enableObjectIdMapping) { From d053dbd6b448c26d25a76ab2a7260384f8bb9a20 Mon Sep 17 00:00:00 2001 From: Saurav Lal Date: Tue, 8 Nov 2022 13:38:54 +0530 Subject: [PATCH 2/7] update testcase --- __tests__/data/clevertap_output.json | 110 ++++++++++----------------- 1 file changed, 41 insertions(+), 69 deletions(-) diff --git a/__tests__/data/clevertap_output.json b/__tests__/data/clevertap_output.json index 7c7d2f9a8b6..8670f46d3f0 100644 --- a/__tests__/data/clevertap_output.json +++ b/__tests__/data/clevertap_output.json @@ -1,13 +1,19 @@ [ { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://api.clevertap.com/1/upload", + "headers": { + "X-CleverTap-Account-Id": "476550467", + "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", + "Content-Type": "application/json" + }, + "params": {}, "body": { - "XML": {}, - "JSON_ARRAY": {}, - "FORM": {}, "JSON": { "d": [ { - "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -20,38 +26,23 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msgSms": true, "msg_push": true, + "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" + }, + "identity": "anon_id" } ] - } - }, - "type": "REST", - "files": {}, - "method": "POST", - "params": {}, - "headers": { - "X-CleverTap-Account-Id": "476550467", - "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", - "Content-Type": "application/json" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} }, - "version": "1", - "endpoint": "https://api.clevertap.com/1/upload" + "files": {} }, { "body": { @@ -152,64 +143,45 @@ "error": "Message type not supported" }, { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://api.clevertap.com/1/upload", + "headers": { + "X-CleverTap-Account-Id": "476550467", + "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", + "Content-Type": "application/json" + }, + "params": {}, "body": { - "XML": {}, - "JSON_ARRAY": {}, - "FORM": {}, "JSON": { "d": [ { - "type": "event", + "evtName": "Charged", "evtData": { + "Charged ID": "12345", + "Amount": 15, + "Items": "[{\"sku\":\"G-32\",\"url\":\"https://www.website.com/product/path\",\"name\":\"Monopoly\",\"price\":14,\"category\":\"Games\",\"quantity\":1,\"image_url\":\"https://www.website.com/product/path.jpg\",\"product_id\":\"123\"},{\"sku\":\"F-32\",\"name\":\"UNO\",\"price\":3.45,\"category\":\"Games\",\"quantity\":2,\"product_id\":\"345\"}]", "tax": 1, - "Items": [ - { - "sku": "G-32", - "url": "https://www.website.com/product/path", - "name": "Monopoly", - "price": 14, - "category": "Games", - "quantity": 1, - "image_url": "https://www.website.com/product/path.jpg", - "product_id": "123" - }, - { - "sku": "F-32", - "name": "UNO", - "price": 3.45, - "category": "Games", - "quantity": 2, - "product_id": "345" - } - ], "total": 20, - "Amount": 15, "coupon": "ImagePro", "currency": "USD", "discount": 1.5, "order_id": "1234", "shipping": 22, - "Charged ID": "12345", "affiliation": "Apple Store" }, "ts": 1615377562, - "evtName": "Charged", + "type": "event", "identity": "riverjohn" } ] - } - }, - "type": "REST", - "files": {}, - "method": "POST", - "params": {}, - "headers": { - "Content-Type": "application/json", - "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", - "X-CleverTap-Account-Id": "476550467" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} }, - "version": "1", - "endpoint": "https://api.clevertap.com/1/upload" + "files": {} }, { "error": "userId, not present cannot track anonymous user" From 0d1906680d34f7ef862c0619579a61444fecf340 Mon Sep 17 00:00:00 2001 From: Saurav Lal Date: Tue, 8 Nov 2022 15:47:24 +0530 Subject: [PATCH 3/7] update testcase --- __tests__/data/clevertap_output.json | 112 +++++++++++---------------- 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/__tests__/data/clevertap_output.json b/__tests__/data/clevertap_output.json index 8670f46d3f0..35fbb0fd376 100644 --- a/__tests__/data/clevertap_output.json +++ b/__tests__/data/clevertap_output.json @@ -187,14 +187,20 @@ "error": "userId, not present cannot track anonymous user" }, { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://api.clevertap.com/1/upload", + "headers": { + "X-CleverTap-Account-Id": "476550467", + "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", + "Content-Type": "application/json" + }, + "params": {}, "body": { - "XML": {}, - "JSON_ARRAY": {}, - "FORM": {}, "JSON": { "d": [ { - "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -207,48 +213,40 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msgSms": true, "msg_push": true, + "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" + }, + "identity": "anon_id" } ] - } + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} }, - "type": "REST", "files": {}, + "userId": "" + }, + { + "version": "1", + "type": "REST", "method": "POST", - "params": {}, + "endpoint": "https://api.clevertap.com/1/upload", "headers": { "X-CleverTap-Account-Id": "476550467", "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", "Content-Type": "application/json" }, - "version": "1", - "endpoint": "https://api.clevertap.com/1/upload" - }, - { + "params": {}, "body": { - "XML": {}, - "JSON_ARRAY": {}, - "FORM": {}, "JSON": { "d": [ { - "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -260,38 +258,24 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msgSms": true, "msg_push": true, + "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" + }, + "identity": "anon_id" } ] - } + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} }, - "type": "REST", "files": {}, - "method": "POST", - "params": {}, - "headers": { - "X-CleverTap-Account-Id": "476550467", - "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", - "Content-Type": "application/json" - }, - "version": "1", - "endpoint": "https://api.clevertap.com/1/upload" + "userId": "" }, [ { @@ -481,29 +465,21 @@ "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" }, "ts": 1615377562, "identity": "anon_id" } ] }, - "XML": {}, "JSON_ARRAY": {}, + "XML": {}, "FORM": {} }, - "files": {} + "files": {}, + "userId": "" }, [ { From 9099b6d6c7843375bc82ae72cb6d73b5823aff16 Mon Sep 17 00:00:00 2001 From: Saurav Lal Date: Tue, 8 Nov 2022 16:06:56 +0530 Subject: [PATCH 4/7] update testcase --- __tests__/data/clevertap_output.json | 9 +++------ __tests__/data/clevertap_router_output.json | 15 +++------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/__tests__/data/clevertap_output.json b/__tests__/data/clevertap_output.json index 35fbb0fd376..a5874981fa5 100644 --- a/__tests__/data/clevertap_output.json +++ b/__tests__/data/clevertap_output.json @@ -229,8 +229,7 @@ "XML": {}, "FORM": {} }, - "files": {}, - "userId": "" + "files": {} }, { "version": "1", @@ -274,8 +273,7 @@ "XML": {}, "FORM": {} }, - "files": {}, - "userId": "" + "files": {} }, [ { @@ -478,8 +476,7 @@ "XML": {}, "FORM": {} }, - "files": {}, - "userId": "" + "files": {} }, [ { diff --git a/__tests__/data/clevertap_router_output.json b/__tests__/data/clevertap_router_output.json index a4c81e770fe..3c84223d2c6 100644 --- a/__tests__/data/clevertap_router_output.json +++ b/__tests__/data/clevertap_router_output.json @@ -32,18 +32,9 @@ "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" } } ] From 6dd7e89452192cc7f24fc1ff81cd05ddf53095dd Mon Sep 17 00:00:00 2001 From: Saurav Lal Date: Wed, 9 Nov 2022 15:30:51 +0530 Subject: [PATCH 5/7] update identify and testcase --- __tests__/data/clevertap_output.json | 158 ++++++++++++-------- __tests__/data/clevertap_router_output.json | 15 +- v0/destinations/clevertap/transform.js | 1 - 3 files changed, 109 insertions(+), 65 deletions(-) diff --git a/__tests__/data/clevertap_output.json b/__tests__/data/clevertap_output.json index a5874981fa5..cb06364cdd5 100644 --- a/__tests__/data/clevertap_output.json +++ b/__tests__/data/clevertap_output.json @@ -1,19 +1,13 @@ [ { - "version": "1", - "type": "REST", - "method": "POST", - "endpoint": "https://api.clevertap.com/1/upload", - "headers": { - "X-CleverTap-Account-Id": "476550467", - "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", - "Content-Type": "application/json" - }, - "params": {}, "body": { + "XML": {}, + "JSON_ARRAY": {}, + "FORM": {}, "JSON": { "d": [ { + "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -26,23 +20,38 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msg_push": true, "msgSms": true, + "msg_push": 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\":\"\"}" - }, - "identity": "anon_id" + "custom_tags": ["Test_User", "Interested_User", "DIY_Hobby"], + "custom_mappings": { + "Office": "Trastkiv", + "Country": "Russia" + }, + "address": { + "city": "kolkata", + "country": "India", + "postalCode": 789223, + "state": "WB", + "street": "" + } + } } ] - }, - "JSON_ARRAY": {}, - "XML": {}, - "FORM": {} + } }, - "files": {} + "type": "REST", + "files": {}, + "method": "POST", + "params": {}, + "headers": { + "X-CleverTap-Account-Id": "476550467", + "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", + "Content-Type": "application/json" + }, + "version": "1", + "endpoint": "https://api.clevertap.com/1/upload" }, { "body": { @@ -187,20 +196,14 @@ "error": "userId, not present cannot track anonymous user" }, { - "version": "1", - "type": "REST", - "method": "POST", - "endpoint": "https://api.clevertap.com/1/upload", - "headers": { - "X-CleverTap-Account-Id": "476550467", - "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", - "Content-Type": "application/json" - }, - "params": {}, "body": { + "XML": {}, + "JSON_ARRAY": {}, + "FORM": {}, "JSON": { "d": [ { + "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -213,39 +216,48 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msg_push": true, "msgSms": true, + "msg_push": 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\":\"\"}" - }, - "identity": "anon_id" + "custom_tags": ["Test_User", "Interested_User", "DIY_Hobby"], + "custom_mappings": { + "Office": "Trastkiv", + "Country": "Russia" + }, + "address": { + "city": "kolkata", + "country": "India", + "postalCode": 789223, + "state": "WB", + "street": "" + } + } } ] - }, - "JSON_ARRAY": {}, - "XML": {}, - "FORM": {} + } }, - "files": {} - }, - { - "version": "1", "type": "REST", + "files": {}, "method": "POST", - "endpoint": "https://api.clevertap.com/1/upload", + "params": {}, "headers": { "X-CleverTap-Account-Id": "476550467", "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", "Content-Type": "application/json" }, - "params": {}, + "version": "1", + "endpoint": "https://api.clevertap.com/1/upload" + }, + { "body": { + "XML": {}, + "JSON_ARRAY": {}, + "FORM": {}, "JSON": { "d": [ { + "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -257,23 +269,38 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msg_push": true, "msgSms": true, + "msg_push": 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\":\"\"}" - }, - "identity": "anon_id" + "custom_tags": ["Test_User", "Interested_User", "DIY_Hobby"], + "custom_mappings": { + "Office": "Trastkiv", + "Country": "Russia" + }, + "address": { + "city": "kolkata", + "country": "India", + "postalCode": 789223, + "state": "WB", + "street": "" + } + } } ] - }, - "JSON_ARRAY": {}, - "XML": {}, - "FORM": {} + } }, - "files": {} + "type": "REST", + "files": {}, + "method": "POST", + "params": {}, + "headers": { + "X-CleverTap-Account-Id": "476550467", + "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", + "Content-Type": "application/json" + }, + "version": "1", + "endpoint": "https://api.clevertap.com/1/upload" }, [ { @@ -463,9 +490,18 @@ "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_tags": ["Test_User", "Interested_User", "DIY_Hobby"], + "custom_mappings": { + "Office": "Trastkiv", + "Country": "Russia" + }, + "address": { + "city": "kolkata", + "country": "India", + "postalCode": 789223, + "state": "WB", + "street": "" + } }, "ts": 1615377562, "identity": "anon_id" diff --git a/__tests__/data/clevertap_router_output.json b/__tests__/data/clevertap_router_output.json index 3c84223d2c6..a4c81e770fe 100644 --- a/__tests__/data/clevertap_router_output.json +++ b/__tests__/data/clevertap_router_output.json @@ -32,9 +32,18 @@ "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_tags": ["Test_User", "Interested_User", "DIY_Hobby"], + "custom_mappings": { + "Office": "Trastkiv", + "Country": "Russia" + }, + "address": { + "city": "kolkata", + "country": "India", + "postalCode": 789223, + "state": "WB", + "street": "" + } } } ] diff --git a/v0/destinations/clevertap/transform.js b/v0/destinations/clevertap/transform.js index 632b5291961..fcf8e770d3e 100644 --- a/v0/destinations/clevertap/transform.js +++ b/v0/destinations/clevertap/transform.js @@ -212,7 +212,6 @@ const getClevertapProfile = (message, category) => { ["traits", "context.traits"], CLEVERTAP_DEFAULT_EXCLUSION ); - profile = convertObjectAndArrayToString(profile); return removeUndefinedAndNullValues(profile); }; From ee91c307eb7766fbc8fd0250f1e3e77e98841210 Mon Sep 17 00:00:00 2001 From: Saurav Lal Date: Wed, 9 Nov 2022 16:13:45 +0530 Subject: [PATCH 6/7] update identify and testcase --- __tests__/data/clevertap_output.json | 158 ++++++++------------ __tests__/data/clevertap_router_output.json | 15 +- v0/destinations/clevertap/transform.js | 2 +- 3 files changed, 65 insertions(+), 110 deletions(-) diff --git a/__tests__/data/clevertap_output.json b/__tests__/data/clevertap_output.json index cb06364cdd5..a5874981fa5 100644 --- a/__tests__/data/clevertap_output.json +++ b/__tests__/data/clevertap_output.json @@ -1,13 +1,19 @@ [ { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://api.clevertap.com/1/upload", + "headers": { + "X-CleverTap-Account-Id": "476550467", + "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", + "Content-Type": "application/json" + }, + "params": {}, "body": { - "XML": {}, - "JSON_ARRAY": {}, - "FORM": {}, "JSON": { "d": [ { - "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -20,38 +26,23 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msgSms": true, "msg_push": true, + "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" + }, + "identity": "anon_id" } ] - } - }, - "type": "REST", - "files": {}, - "method": "POST", - "params": {}, - "headers": { - "X-CleverTap-Account-Id": "476550467", - "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", - "Content-Type": "application/json" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} }, - "version": "1", - "endpoint": "https://api.clevertap.com/1/upload" + "files": {} }, { "body": { @@ -196,14 +187,20 @@ "error": "userId, not present cannot track anonymous user" }, { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://api.clevertap.com/1/upload", + "headers": { + "X-CleverTap-Account-Id": "476550467", + "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", + "Content-Type": "application/json" + }, + "params": {}, "body": { - "XML": {}, - "JSON_ARRAY": {}, - "FORM": {}, "JSON": { "d": [ { - "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -216,48 +213,39 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msgSms": true, "msg_push": true, + "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" + }, + "identity": "anon_id" } ] - } + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} }, + "files": {} + }, + { + "version": "1", "type": "REST", - "files": {}, "method": "POST", - "params": {}, + "endpoint": "https://api.clevertap.com/1/upload", "headers": { "X-CleverTap-Account-Id": "476550467", "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", "Content-Type": "application/json" }, - "version": "1", - "endpoint": "https://api.clevertap.com/1/upload" - }, - { + "params": {}, "body": { - "XML": {}, - "JSON_ARRAY": {}, - "FORM": {}, "JSON": { "d": [ { - "identity": "anon_id", "type": "profile", "profileData": { "Email": "jamesDoe@gmail.com", @@ -269,38 +257,23 @@ "Married": true, "Customer Type": "Prime", "graduate": true, - "msgSms": true, "msg_push": true, + "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" + }, + "identity": "anon_id" } ] - } - }, - "type": "REST", - "files": {}, - "method": "POST", - "params": {}, - "headers": { - "X-CleverTap-Account-Id": "476550467", - "X-CleverTap-Passcode": "fbee74a147828e2932c701d19dc1f2dcfa4ac0048be3aa3a88d427090a59dc1c0fa002f1", - "Content-Type": "application/json" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} }, - "version": "1", - "endpoint": "https://api.clevertap.com/1/upload" + "files": {} }, [ { @@ -490,18 +463,9 @@ "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" }, "ts": 1615377562, "identity": "anon_id" diff --git a/__tests__/data/clevertap_router_output.json b/__tests__/data/clevertap_router_output.json index a4c81e770fe..3c84223d2c6 100644 --- a/__tests__/data/clevertap_router_output.json +++ b/__tests__/data/clevertap_router_output.json @@ -32,18 +32,9 @@ "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_tags": "[\"Test_User\",\"Interested_User\",\"DIY_Hobby\"]", + "custom_mappings": "{\"Office\":\"Trastkiv\",\"Country\":\"Russia\"}", + "address": "{\"city\":\"kolkata\",\"country\":\"India\",\"postalCode\":789223,\"state\":\"WB\",\"street\":\"\"}" } } ] diff --git a/v0/destinations/clevertap/transform.js b/v0/destinations/clevertap/transform.js index fcf8e770d3e..a94a75e8e01 100644 --- a/v0/destinations/clevertap/transform.js +++ b/v0/destinations/clevertap/transform.js @@ -212,7 +212,7 @@ const getClevertapProfile = (message, category) => { ["traits", "context.traits"], CLEVERTAP_DEFAULT_EXCLUSION ); - + profile = convertObjectAndArrayToString(profile); return removeUndefinedAndNullValues(profile); }; From ae07b52d36846e54d4b699f8c6321d48731404b2 Mon Sep 17 00:00:00 2001 From: Saurav Lal Date: Wed, 9 Nov 2022 16:15:27 +0530 Subject: [PATCH 7/7] update function --- v0/destinations/clevertap/transform.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/v0/destinations/clevertap/transform.js b/v0/destinations/clevertap/transform.js index a94a75e8e01..897f46933d9 100644 --- a/v0/destinations/clevertap/transform.js +++ b/v0/destinations/clevertap/transform.js @@ -83,8 +83,7 @@ const responseWrapper = (payload, destination) => { const convertObjectAndArrayToString = payload => { const finalPayload = {}; if (payload) { - const category = Object.keys(payload); - category.forEach(key => { + Object.keys(payload).forEach(key => { if ( payload[key] && (Array.isArray(payload[key]) || typeof payload[key] === "object")