Skip to content

Commit

Permalink
feat: adding custom properties support to bluecore (#3282)
Browse files Browse the repository at this point in the history
* feat: adding custom properties support to bluecore

* Update src/cdk/v2/destinations/bluecore/utils.js

Co-authored-by: Sankeerth <[email protected]>

* fix: small fix

---------

Co-authored-by: Sankeerth <[email protected]>
  • Loading branch information
shrouti1507 and sanpj2292 authored Apr 17, 2024
1 parent 0b57204 commit 8592e66
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 20 deletions.
22 changes: 21 additions & 1 deletion src/cdk/v2/destinations/bluecore/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { getMappingConfig } = require('../../../../v0/util');

const BASE_URL = 'https://api.bluecore.com/api/track/mobile/v1';
const BASE_URL = 'https://api.bluecore.app/api/track/mobile/v1';

const CONFIG_CATEGORIES = {
IDENTIFY: {
Expand Down Expand Up @@ -46,11 +46,31 @@ const EVENT_NAME_MAPPING = [

const BLUECORE_EXCLUSION_FIELDS = ['query', 'order_id', 'total'];

const IDENTIFY_EXCLUSION_LIST = [
'name',
'firstName',
'first_name',
'firstname',
'lastName',
'last_name',
'lastname',
'email',
'age',
'sex',
'address',
'action',
'event',
];

const TRACK_EXCLUSION_LIST = [...IDENTIFY_EXCLUSION_LIST, 'query', 'order_id', 'total', 'products'];

const MAPPING_CONFIG = getMappingConfig(CONFIG_CATEGORIES, __dirname);
module.exports = {
CONFIG_CATEGORIES,
MAPPING_CONFIG,
EVENT_NAME_MAPPING,
BASE_URL,
BLUECORE_EXCLUSION_FIELDS,
IDENTIFY_EXCLUSION_LIST,
TRACK_EXCLUSION_LIST,
};
6 changes: 3 additions & 3 deletions src/cdk/v2/destinations/bluecore/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ steps:
condition: $.outputs.messageType === {{$.EventType.IDENTIFY}}
template: |
const payload = $.constructProperties(.message);
payload.token = .destination.Config.bluecoreNamespace;
payload.properties.token = .destination.Config.bluecoreNamespace;
$.verifyPayload(payload, .message);
payload.event = payload.event ?? 'customer_patch';
payload.properties.distinct_id = $.populateAccurateDistinctId(payload, .message);
Expand All @@ -50,7 +50,7 @@ steps:
const temporaryProductArray = newPayload.properties.products ?? $.createProductForStandardEcommEvent(^.message, eventName);
newPayload.properties.products = $.normalizeProductArray(temporaryProductArray);
newPayload.event = eventName;
newPayload.token = ^.destination.Config.bluecoreNamespace;
newPayload.properties.token = ^.destination.Config.bluecoreNamespace;
$.verifyPayload(newPayload, ^.message);
$.removeUndefinedNullValuesAndEmptyObjectArray(newPayload)
)[];
Expand All @@ -61,7 +61,7 @@ steps:
const response = $.defaultRequestConfig();
response.body.JSON = .;
response.method = "POST";
response.endpoint = "https://api.bluecore.com/api/track/mobile/v1";
response.endpoint = "https://api.bluecore.app/api/track/mobile/v1";
response.headers = {
"Content-Type": "application/json"
};
Expand Down
45 changes: 43 additions & 2 deletions src/cdk/v2/destinations/bluecore/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const {
validateEventName,
constructPayload,
getDestinationExternalID,
extractCustomFields,
} = require('../../../../v0/util');
const { CommonUtils } = require('../../../../util/common');
const { EVENT_NAME_MAPPING } = require('./config');
const { EVENT_NAME_MAPPING, IDENTIFY_EXCLUSION_LIST, TRACK_EXCLUSION_LIST } = require('./config');
const { EventType } = require('../../../../constants');
const { MAPPING_CONFIG, CONFIG_CATEGORIES } = require('./config');

Expand Down Expand Up @@ -167,6 +168,41 @@ const normalizeProductArray = (products) => {
return finalProductArray;
};

const mapCustomProperties = (message) => {
let customerProperties;
const customProperties = { properties: {} };
const messageType = message.type.toUpperCase();
switch (messageType) {
case 'IDENTIFY':
customerProperties = extractCustomFields(
message,
{},
['traits', 'context.traits'],
IDENTIFY_EXCLUSION_LIST,
);
customProperties.properties.customer = customerProperties;
break;
case 'TRACK':
customerProperties = extractCustomFields(
message,
{},
['traits', 'context.traits'],
IDENTIFY_EXCLUSION_LIST,
);
customProperties.properties = extractCustomFields(
message,
{},
['properties'],
TRACK_EXCLUSION_LIST,
);
customProperties.properties.customer = customerProperties;
break;
default:
break;
}
return customProperties;
};

/**
* Constructs properties based on the given message.
*
Expand All @@ -178,7 +214,12 @@ const constructProperties = (message) => {
const commonPayload = constructPayload(message, MAPPING_CONFIG[commonCategory.name]);
const category = CONFIG_CATEGORIES[message.type.toUpperCase()];
const typeSpecificPayload = constructPayload(message, MAPPING_CONFIG[category.name]);
const finalPayload = lodash.merge(commonPayload, typeSpecificPayload);
const typeSpecificCustomProperties = mapCustomProperties(message);
const finalPayload = lodash.merge(
commonPayload,
typeSpecificPayload,
typeSpecificCustomProperties,
);
return finalPayload;
};

Expand Down
24 changes: 20 additions & 4 deletions test/integrations/destinations/bluecore/ecommTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const commonOutputHeaders = {
'Content-Type': 'application/json',
};

const eventEndPoint = 'https://api.bluecore.com/api/track/mobile/v1';
const eventEndPoint = 'https://api.bluecore.app/api/track/mobile/v1';

export const ecomTestData = [
{
Expand Down Expand Up @@ -296,17 +296,23 @@ export const ecomTestData = [
customer: {
age: '22',
email: '[email protected]',
anonymousId: '9c6bd77ea9da3e68',
id: 'user@1',
phone: '9112340375',
},
product_id: '123',
products: [
{
id: '123',
property1: 'value1',
property2: 'value2',
},
],
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
},
event: 'viewed_product',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -379,8 +385,11 @@ export const ecomTestData = [
JSON: {
properties: {
distinct_id: 'user@1',
product_id: '123',
customer: {
age: '22',
anonymousId: '9c6bd77ea9da3e68',
id: 'user@1',
},
products: [
{
Expand All @@ -389,9 +398,11 @@ export const ecomTestData = [
property2: 'value2',
},
],
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
},
event: 'wishlist',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand All @@ -406,8 +417,11 @@ export const ecomTestData = [
JSON: {
properties: {
distinct_id: 'user@1',
product_id: '123',
customer: {
age: '22',
anonymousId: '9c6bd77ea9da3e68',
id: 'user@1',
},
products: [
{
Expand All @@ -416,9 +430,11 @@ export const ecomTestData = [
property2: 'value2',
},
],
token: 'dummy_sandbox',
property1: 'value1',
property2: 'value2',
},
event: 'add_to_cart',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down
13 changes: 9 additions & 4 deletions test/integrations/destinations/bluecore/identifyTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const commonOutputCustomerProperties = {
first_name: 'Test',
last_name: 'Rudderlabs',
sex: 'non-binary',
anonymousId: '50be5c78-6c3f-4b60-be84-97805a316fb1',
db: '19950715',
gender: 'non-binary',
phone: '+1234589947',
address: {
city: 'Kolkata',
state: 'WB',
Expand All @@ -71,7 +75,7 @@ const anonymousId = '97c46c81-3140-456d-b2a9-690d70aaca35';
const userId = 'user@1';
const sentAt = '2021-01-03T17:02:53.195Z';
const originalTimestamp = '2021-01-03T17:02:53.193Z';
const commonEndpoint = 'https://api.bluecore.com/api/track/mobile/v1';
const commonEndpoint = 'https://api.bluecore.app/api/track/mobile/v1';

export const identifyData = [
{
Expand Down Expand Up @@ -118,8 +122,8 @@ export const identifyData = [
properties: {
distinct_id: '[email protected]',
customer: { ...commonOutputCustomerProperties, email: '[email protected]' },
token: 'dummy_sandbox',
},
token: 'dummy_sandbox',
event: 'customer_patch',
},
}),
Expand Down Expand Up @@ -302,8 +306,9 @@ export const identifyData = [
properties: {
distinct_id: 'user@1',
customer: { ...commonOutputCustomerProperties, email: '[email protected]' },
token: 'dummy_sandbox',
},
token: 'dummy_sandbox',

event: 'identify',
},
}),
Expand Down Expand Up @@ -361,8 +366,8 @@ export const identifyData = [
properties: {
distinct_id: '54321',
customer: { ...commonOutputCustomerProperties, email: '[email protected]' },
token: 'dummy_sandbox',
},
token: 'dummy_sandbox',
event: 'customer_patch',
},
}),
Expand Down
39 changes: 33 additions & 6 deletions test/integrations/destinations/bluecore/trackTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const commonOutputHeaders = {
'Content-Type': 'application/json',
};

const eventEndPoint = 'https://api.bluecore.com/api/track/mobile/v1';
const eventEndPoint = 'https://api.bluecore.app/api/track/mobile/v1';

export const trackTestData = [
{
Expand Down Expand Up @@ -140,6 +140,9 @@ export const trackTestData = [
customer: {
age: '22',
email: '[email protected]',
anonymousId: '9c6bd77ea9da3e68',
id: 'user@1',
phone: '9112340375',
},
products: [
{
Expand All @@ -155,9 +158,11 @@ export const trackTestData = [
quantity: 3,
},
],
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
},
event: 'TestEven001',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -216,13 +221,19 @@ export const trackTestData = [
JSON: {
properties: {
distinct_id: '[email protected]',
product_id: '123',
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
customer: {
age: '22',
email: '[email protected]',
anonymousId: '9c6bd77ea9da3e68',
id: 'user@1',
phone: '9112340375',
},
},
event: 'TestEven001',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -283,11 +294,17 @@ export const trackTestData = [
distinct_id: '[email protected]',
customer: {
age: '22',
anonymousId: '9c6bd77ea9da3e68',
email: '[email protected]',
id: 'user@1',
phone: '9112340375',
},
product_id: '123',
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
},
event: 'optin',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -346,13 +363,19 @@ export const trackTestData = [
JSON: {
properties: {
distinct_id: '[email protected]',
product_id: '123',
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
customer: {
age: '22',
anonymousId: '9c6bd77ea9da3e68',
id: 'user@1',
email: '[email protected]',
phone: '9112340375',
},
},
event: 'unsubscribe',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -405,9 +428,12 @@ export const trackTestData = [
JSON: {
properties: {
distinct_id: '54321',
token: 'dummy_sandbox',
customer: {
age: '22',
email: '[email protected]',
anonymousId: '9c6bd77ea9da3e68',
id: 'user@1',
},
products: [
{
Expand All @@ -423,9 +449,10 @@ export const trackTestData = [
quantity: 3,
},
],
property1: 'value1',
property2: 'value2',
},
event: 'TestEven001',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down

0 comments on commit 8592e66

Please sign in to comment.