Skip to content

Commit

Permalink
refactor: remove cdk v1 imports
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip committed May 2, 2024
1 parent 04bf32c commit 608469b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/cdk/v2/destinations/emarsys/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { EVENT_TYPE } from 'rudder-transformer-cdk/build/constants';

const lodash = require('lodash');
const crypto = require('crypto');

const {
InstrumentationError,
ConfigurationError,
Expand All @@ -13,10 +10,11 @@ const {
getHashFromArray,
} = require('@rudderstack/integrations-lib');
const {
getIntegrationsObj,
validateEventName,
getValueFromMessage,
getFieldValueFromMessage,
} = require('rudder-transformer-cdk/build/utils');
const { getIntegrationsObj, validateEventName } = require('../../../../v0/util');
} = require('../../../../v0/util');
const {
EMAIL_FIELD_ID,
MAX_BATCH_SIZE,
Expand All @@ -25,6 +23,8 @@ const {
MAX_BATCH_SIZE_BYTES,
groupedSuccessfulPayload,
} = require('./config');
const { SUPPORTED_EVENT_TYPE } = require('../the_trade_desk_real_time_conversions/config');
const { EventType } = require('../../../../constants');

const base64Sha = (str) => {
const hexDigest = crypto.createHash('sha1').update(str).digest('hex');
Expand Down Expand Up @@ -194,14 +194,14 @@ const deduceEndPoint = (finalPayload) => {
let contactListId;
const { eventType, destinationPayload } = finalPayload;
switch (eventType) {
case EVENT_TYPE.IDENTIFY:
case EventType.IDENTIFY:
endPoint = 'https://api.emarsys.net/api/v2/contact/?create_if_not_exists=1';
break;
case EVENT_TYPE.GROUP:
case SUPPORTED_EVENT_TYPE.GROUP:
contactListId = destinationPayload.contactListId;
endPoint = `https://api.emarsys.net/api/v2/contactlist/${contactListId}/add`;
break;
case EVENT_TYPE.TRACK:
case EventType.TRACK:
eventId = destinationPayload.eventId;
endPoint = `https://api.emarsys.net/api/v2/event/${eventId}/trigger`;
break;
Expand Down Expand Up @@ -353,17 +353,17 @@ const batchResponseBuilder = (successfulEvents) => {
);
Object.keys(typedEventGroups).forEach((eachEventGroup) => {
switch (eachEventGroup) {
case EVENT_TYPE.IDENTIFY:
case EventType.IDENTIFY:
batchesOfIdentifyEvents = createIdentifyBatches(eachEventGroup);
groupedSuccessfulPayload.identify.batches = formatIdentifyPayloadsWithEndpoint(
batchesOfIdentifyEvents,
'https://api.emarsys.net/api/v2/contact/?create_if_not_exists=1',
);
break;
case EVENT_TYPE.GROUP:
case EventType.GROUP:
groupedSuccessfulPayload.group.batches = createGroupBatches(eachEventGroup);
break;
case EVENT_TYPE.TRACK:
case EventType.TRACK:
groupedSuccessfulPayload.track.batches = createTrackBatches(eachEventGroup);
break;
default:
Expand Down Expand Up @@ -403,6 +403,7 @@ const batchResponseBuilder = (successfulEvents) => {

return finaloutput;
};

module.exports = {
buildIdentifyPayload,
buildGroupPayload,
Expand Down

0 comments on commit 608469b

Please sign in to comment.