Skip to content

Commit

Permalink
feat: onboard closeCRM source (#3467)
Browse files Browse the repository at this point in the history
* feat: onboard closeCRM source

* fix: fixed timestamp issue

* fix: fixed minor issues

* fix: fixed payload

* fix: test case
  • Loading branch information
manish339k authored Jun 24, 2024
1 parent 11ce96b commit bba1a3b
Show file tree
Hide file tree
Showing 3 changed files with 455 additions and 0 deletions.
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

0 comments on commit bba1a3b

Please sign in to comment.