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 closeCRM source #3467

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/v1/sources/close_crm/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const excludedFieldList = ['changed_fields', 'previous_data'];

module.exports = { excludedFieldList };
57 changes: 57 additions & 0 deletions src/v1/sources/close_crm/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const moment = require('moment');
const {
removeUndefinedAndNullValues,
removeUndefinedAndNullRecurse,
generateUUID,
formatTimeStamp,
} = require('../../../v0/util');
const { excludedFieldList } = require('./config');
const Message = require('../../../v0/sources/message');

function processEvent(inputEvent) {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { event, subscription_id } = inputEvent;

const message = new Message('CloseCRM');

// Set event type track
message.setEventType('track');

// Set event name
const eventName = `${event.object_type} ${event.action}`;
message.setEventName(eventName);

// Set userId
if (event.lead_id) {
message.setProperty('userId', event.lead_id);
} else {
message.setProperty('anonymousId', generateUUID());
}

// Set messageId
message.setProperty('messageId', event.id);

// Set Timestamp
const timestamp = moment.utc(event.date_updated);
message.setProperty('originalTimestamp', formatTimeStamp(timestamp, 'yyyy-MM-ddTHH:mm:ss.SSSZ'));

// Set properties
removeUndefinedAndNullRecurse(event);
message.setProperty('properties', event);
message.setProperty('properties.subscription_id', subscription_id);

// Remove excluding fields
excludedFieldList.forEach((field) => {
delete message.properties[field];
});

return message;
}

function process(inputEvent) {
const { event } = inputEvent;
const response = processEvent(event);
return removeUndefinedAndNullValues(response);
}

exports.process = process;
Loading
Loading