Skip to content

Commit

Permalink
feat: braze source event mapping (#3527)
Browse files Browse the repository at this point in the history
* feat: braze source event mapping

* feat: delete unnecessary code

* fix: removing the duplicate code from  v0 route

* fix: shortened the test cases
  • Loading branch information
shrouti1507 authored Jul 22, 2024
1 parent fbcdcd6 commit e357141
Show file tree
Hide file tree
Showing 9 changed files with 1,297 additions and 576 deletions.
1 change: 0 additions & 1 deletion src/v0/sources/braze/eventMapping.json

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@ const get = require('get-value');
const path = require('path');
const fs = require('fs');
const { TransformationError } = require('@rudderstack/integrations-lib');
const { formatTimeStamp, removeUndefinedAndNullValues } = require('../../util');
const Message = require('../message');
const {
formatTimeStamp,
removeUndefinedAndNullValues,
getHashFromArray,
} = require('../../../v0/util');
const Message = require('../../../v0/sources/message');

// import mapping json using JSON.parse to preserve object key order
const mapping = JSON.parse(fs.readFileSync(path.resolve(__dirname, './mapping.json'), 'utf-8'));

// if we need to map braze event name to something else. blank as of now
const eventNameMap = JSON.parse(
fs.readFileSync(path.resolve(__dirname, './eventMapping.json'), 'utf-8'),
);

// ignored properties
// to be deleted from the field `event.properties` as already mapped
// using mapping.json
const ignoredProperties = JSON.parse(
fs.readFileSync(path.resolve(__dirname, './ignore.json'), 'utf-8'),
);

const processEvent = (event) => {
const processEvent = (event, eventMapping) => {
const messageType = 'track';

if (event.event_type) {
Expand All @@ -32,7 +30,7 @@ const processEvent = (event) => {
message.setEventType(messageType);

// set event name
const eventName = eventNameMap[eventType] || eventType;
const eventName = eventMapping[eventType] || eventType;
message.setEventName(eventName);

// map event properties based on mapping.json
Expand Down Expand Up @@ -68,14 +66,17 @@ const processEvent = (event) => {
throw new TransformationError('Unknown event type from Braze');
};

const process = (events) => {
const process = (inputEvent) => {
const { event, source } = inputEvent;
const { customMapping } = source.Config;
const eventMapping = getHashFromArray(customMapping, 'from', 'to', false);
const responses = [];

// Ref: Custom Currents Connector Partner Dev Documentation.pdf
const eventList = Array.isArray(events) && events.length > 0 ? events[0].events : events.events;
eventList.forEach((event) => {
const eventList = Array.isArray(event) && event.length > 0 ? event[0].events : event.events;
eventList.forEach((singleEvent) => {
try {
const resp = processEvent(event);
const resp = processEvent(singleEvent, eventMapping);
if (resp) {
responses.push(removeUndefinedAndNullValues(resp));
}
Expand Down
30 changes: 0 additions & 30 deletions test/__tests__/braze_source.test.js

This file was deleted.

243 changes: 0 additions & 243 deletions test/__tests__/data/braze_source_input.json

This file was deleted.

Loading

0 comments on commit e357141

Please sign in to comment.