Skip to content

Commit

Permalink
fix: add validation for event Name type and update function name
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ab committed Nov 6, 2023
1 parent 16d608c commit 51b8bb7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/v0/destinations/customerio/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
adduserIdFromExternalId,
getFieldValueFromMessage,
handleRtTfSingleEventError,
validateEventName,
} = require('../../util');

const logger = require('../../../logger');
Expand Down Expand Up @@ -101,6 +102,7 @@ function processSingleMessage(message, destination) {
break;
case EventType.TRACK:
evType = 'event';
validateEventName(message.event);
evName = message.event;
break;
case EventType.ALIAS:
Expand Down
2 changes: 0 additions & 2 deletions src/v0/destinations/customerio/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
defaultDeleteRequestConfig,
isAppleFamily,
validateEmail,
validateEventType,
} = require('../../util');

const { EventType, SpecedTraits, TraitsMapping } = require('../../../constants');
Expand Down Expand Up @@ -288,7 +287,6 @@ const defaultResponseBuilder = (message, evName, userId, evType, destination, me
// 100 - len(`Viewed Screen`) = 86
trimmedEvName = `Viewed ${truncate(message.event || message.properties.name, 86)} Screen`;
} else {
validateEventType(evName);
trimmedEvName = truncate(evName, 100);
}
// anonymous_id needs to be sent for anon track calls to provide information on which anon user is being tracked
Expand Down
7 changes: 4 additions & 3 deletions src/v0/destinations/freshsales/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
defaultPostRequestConfig,
getValidDynamicFormConfig,
simpleProcessRouterDest,
validateEventType,
validateEventName,
} = require('../../util');
const { InstrumentationError, TransformationError } = require('../../util/errorTypes');
const { CONFIG_CATEGORIES, MAPPING_CONFIG } = require('./config');
Expand Down Expand Up @@ -67,7 +67,7 @@ const identifyResponseBuilder = (message, { Config }) => {
* @returns
*/
const trackResponseBuilder = async (message, { Config }, event) => {
validateEventType(event);
validateEventName(event);
let payload;

const response = defaultRequestConfig();
Expand Down Expand Up @@ -128,6 +128,7 @@ function eventMappingHandler(message, destination) {
if (!event) {
throw new InstrumentationError('Event name is required');
}
validateEventName(event);

let { rudderEventsToFreshsalesEvents } = destination.Config;
const mappedEvents = new Set();
Expand All @@ -141,7 +142,7 @@ function eventMappingHandler(message, destination) {
destination.ID,
);
rudderEventsToFreshsalesEvents.forEach((mapping) => {
if (mapping.from.toLowerCase() === String(event).toLowerCase()) {
if (mapping.from.toLowerCase() === event.toLowerCase()) {
mappedEvents.add(mapping.to);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/monday/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
removeUndefinedAndNullValues,
simpleProcessRouterDest,
getDestinationExternalID,
validateEventType,
validateEventName,
} = require('../../util');
const {
ConfigurationError,
Expand Down Expand Up @@ -42,7 +42,7 @@ const trackResponseBuilder = async (message, { Config }) => {
const { apiToken } = Config;
let boardId = getDestinationExternalID(message, 'boardId');
const event = get(message, 'event');
validateEventType(event);
validateEventName(event);
if (!boardId) {
boardId = Config.boardId;
}
Expand Down
4 changes: 2 additions & 2 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ const isValidInteger = (value) => {
// Use a regular expression to check if the string is a valid integer or a valid floating-point number
return typeof value === 'string' ? /^-?\d+$/.test(value) : false;
};
const validateEventType = (event) => {
const validateEventName = (event) => {
if (!event || typeof event !== 'string') {
throw new InstrumentationError('Event is a required field and should be a string');
}
Expand Down Expand Up @@ -2177,7 +2177,7 @@ module.exports = {
getDestAuthCacheInstance,
refinePayload,
validateEmail,
validateEventType,
validateEventName,
validatePhoneWithCountryCode,
getEventReqMetadata,
isHybridModeEnabled,
Expand Down

0 comments on commit 51b8bb7

Please sign in to comment.