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

chore: cordial #3587

Closed
wants to merge 14 commits into from
15 changes: 11 additions & 4 deletions src/cdk/v2/destinations/cordial/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ steps:
template: |
$.context.messageType = .message.type.toLowerCase();

- name: validateInput
- name: validateConfig
template: |
$.assertConfig(.destination.Config.apiKey, "API Key is not present. Aborting");
$.assertConfig(.destination.Config.apiBaseUrl, "API Base URl is not present. Aborting");

- name: validateMessageType
template: |
let messageType = $.context.messageType;
$.assert(messageType, "message Type is not present. Aborting");
$.assert(messageType in {{$.EventType.([.TRACK, .IDENTIFY])}}, "message type " + messageType + " is not supported");
$.assertConfig(.destination.Config.apiKey, "API Key is not present. Aborting");
$.assertConfig(.destination.Config.apiBaseUrl, "API Base URl is not present. Aborting");

- name: getContactId
template: |
$.getDestinationExternalID(.message,'cordialContactId');

- name: getContactEmail
template: |
.message.().({{{{$.getGenericPaths("email")}}}};);
.message.().({{{{$.getGenericPaths("emailOnly")}}}});

- name: validateEventPayload
template: |
$.assert($.outputs.getContactId || $.outputs.getContactEmail, "Either one of cordial contact id or email is required. Aborting");

- name: buildIdentifyPayload
condition: $.context.messageType in [{{$.EventType.IDENTIFY}}]
Expand Down
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"
},
{
"sourceKeys": "contact.channels.email.address",
"destKeys": ["context.traits.email"]
}
]
51 changes: 51 additions & 0 deletions src/v1/sources/cordial/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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');

const processEvent = (inputPaylaod) => {
const message = new Message(`Cordial`);
let eventName = inputPaylaod.event?.a || inputPaylaod.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(inputPaylaod, mapping);

const externalId = [];
// setting up cordial contact_id to externalId
if (inputPaylaod.contact.cID) {
externalId.push({
type: 'cordialContactId',
id: inputPaylaod.contact.cID,
});
}
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
}
// Due to multiple mappings to the same destination path object some are not showing up due to which we are doing the following
message.context.traits = { ...message.context.traits, ...inputPaylaod.contact };
message.properties = {
...message.properties,
...inputPaylaod.event.properties,
...inputPaylaod.event,
};
delete message.properties.properties;
delete message.properties.d;
// eslint-disable-next-line no-underscore-dangle
delete message.properties._id;
return message;
};

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

exports.process = process;
43 changes: 42 additions & 1 deletion test/integrations/destinations/cordial/processor/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@ import { generateMetadata } from '../../../testUtils';
import { destType, destination, processorInstrumentationErrorStatTags } from '../common';

export const validation: ProcessorTestData[] = [
{
id: 'cordial-validation-test-1',
name: destType,
description: 'All of the required fields — cordial contact id, email — are missing.',
scenario: 'Framework',
successCriteria: 'Instrumentation Error',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: {
type: 'identify',
integrations: {
All: true,
},
originalTimestamp: '2024-03-04T15:32:56.409Z',
},
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
error:
'Either one of cordial contact id or email is required. Aborting: Workflow: procWorkflow, Step: validateEventPayload, ChildStep: undefined, OriginalError: Either one of cordial contact id or email is required. Aborting',
metadata: generateMetadata(1),
statTags: processorInstrumentationErrorStatTags,
statusCode: 400,
},
],
},
},
},
{
id: 'cordial-validation-test-2',
name: destType,
Expand Down Expand Up @@ -38,7 +79,7 @@ export const validation: ProcessorTestData[] = [
body: [
{
error:
'message type group is not supported: Workflow: procWorkflow, Step: validateInput, ChildStep: undefined, OriginalError: message type group is not supported',
'message type group is not supported: Workflow: procWorkflow, Step: validateMessageType, ChildStep: undefined, OriginalError: message type group is not supported',
metadata: generateMetadata(1),
statTags: processorInstrumentationErrorStatTags,
statusCode: 400,
Expand Down
Loading
Loading