Skip to content

Commit

Permalink
feat: adding custom properties support to bluecore
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Apr 16, 2024
1 parent 0b57204 commit e0eb9a0
Show file tree
Hide file tree
Showing 6 changed files with 105 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
42 changes: 40 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,38 @@ const normalizeProductArray = (products) => {
return finalProductArray;
};

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

Check warning on line 198 in src/cdk/v2/destinations/bluecore/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/bluecore/utils.js#L197-L198

Added lines #L197 - L198 were not covered by tests
}
return customProperties;
};

/**
* Constructs properties based on the given message.
*
Expand All @@ -178,7 +211,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
17 changes: 13 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 @@ -297,16 +297,19 @@ export const ecomTestData = [
age: '22',
email: '[email protected]',
},
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,6 +382,7 @@ export const ecomTestData = [
JSON: {
properties: {
distinct_id: 'user@1',
product_id: '123',
customer: {
age: '22',
},
Expand All @@ -389,9 +393,11 @@ export const ecomTestData = [
property2: 'value2',
},
],
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
},
event: 'wishlist',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand All @@ -406,6 +412,7 @@ export const ecomTestData = [
JSON: {
properties: {
distinct_id: 'user@1',
product_id: '123',
customer: {
age: '22',
},
Expand All @@ -416,9 +423,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
25 changes: 19 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 @@ -155,9 +155,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 +218,16 @@ 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]',
},
},
event: 'TestEven001',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -285,9 +290,12 @@ export const trackTestData = [
age: '22',
email: '[email protected]',
},
product_id: '123',
property1: 'value1',
property2: 'value2',
token: 'dummy_sandbox',
},
event: 'optin',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -346,13 +354,16 @@ 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]',
},
},
event: 'unsubscribe',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down Expand Up @@ -405,6 +416,7 @@ export const trackTestData = [
JSON: {
properties: {
distinct_id: '54321',
token: 'dummy_sandbox',
customer: {
age: '22',
email: '[email protected]',
Expand All @@ -423,9 +435,10 @@ export const trackTestData = [
quantity: 3,
},
],
property1: 'value1',
property2: 'value2',
},
event: 'TestEven001',
token: 'dummy_sandbox',
},
userId: '',
}),
Expand Down

0 comments on commit e0eb9a0

Please sign in to comment.