Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: onboard cordial source #3593

Merged
merged 9 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/v1/sources/cordial/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const eventsMapping = {
crdl_app_install: 'Application Installed',
crdl_app_open: 'Application Opened',
};

module.exports = { eventsMapping };
22 changes: 22 additions & 0 deletions src/v1/sources/cordial/mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"sourceKeys": "event._id",
"destKeys": "properties.event_id"
},
{
"sourceKeys": "contact._id",
"destKeys": ["context.traits.userId", "userId"]
},
{
"sourceKeys": ["event.ts", "event.ats"],
"destKeys": ["timestamp", "sentAt", "originalTimestamp"]
},
{
"sourceKeys": "event.d",
"destKeys": "context.device"
utsabc marked this conversation as resolved.
Show resolved Hide resolved
},
{
"sourceKeys": "contact.channels.email.address",
"destKeys": ["context.traits.email", "properties.email"]
aanshi07 marked this conversation as resolved.
Show resolved Hide resolved
}
]
44 changes: 44 additions & 0 deletions src/v1/sources/cordial/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const Message = require('../../../v0/sources/message');
const { CommonUtils } = require('../../../util/common');
const { generateUUID, isDefinedAndNotNull } = require('../../../v0/util');
const { eventsMapping } = require('./config');

const mapping = require('./mapping.json');

utsabc marked this conversation as resolved.
Show resolved Hide resolved
const processEvent = (event) => {
aanshi07 marked this conversation as resolved.
Show resolved Hide resolved
const message = new Message(`Cordial`);
let eventName = event.event?.a || event.event?.action;
if (eventName in eventsMapping) {
eventName = eventsMapping[eventName];

Check warning on line 12 in src/v1/sources/cordial/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/cordial/transform.js#L12

Added line #L12 was not covered by tests
}
message.setEventType('track');
message.setEventName(eventName);
message.setPropertiesV2(event, mapping);

const externalId = [];
// setting up cordial contact_id to externalId
if (event.cID) {
Gauravudia marked this conversation as resolved.
Show resolved Hide resolved
externalId.push({

Check warning on line 21 in src/v1/sources/cordial/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/cordial/transform.js#L21

Added line #L21 was not covered by tests
type: 'cordialContactId',
id: event.cID,
Gauravudia marked this conversation as resolved.
Show resolved Hide resolved
});
}
message.context.externalId = externalId;

if (!isDefinedAndNotNull(message.userId)) {
message.anonymousId = generateUUID();

Check warning on line 29 in src/v1/sources/cordial/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/cordial/transform.js#L29

Added line #L29 was not covered by tests
utsabc marked this conversation as resolved.
Show resolved Hide resolved
}
// Due to multiple mappings to the same destination path object some are not showing up due to which we are doing the following
aanshi07 marked this conversation as resolved.
Show resolved Hide resolved
message.context.traits = { ...message.context.traits, ...event.contact };
message.properties = { ...message.properties, ...event.event.properties, ...event.event };
delete message.properties.properties;
return message;
};

const process = (inputEvent) => {
const { event: events } = inputEvent;
const eventsArray = CommonUtils.toArray(events);
return eventsArray.map(processEvent);
};

exports.process = process;
Loading
Loading