From 51b8bb7665be2fcc8e95370334632e2fcb1ff652 Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Mon, 6 Nov 2023 13:03:59 +0530 Subject: [PATCH] fix: add validation for event Name type and update function name --- src/v0/destinations/customerio/transform.js | 2 ++ src/v0/destinations/customerio/util.js | 2 -- src/v0/destinations/freshsales/transform.js | 7 ++++--- src/v0/destinations/monday/transform.js | 4 ++-- src/v0/util/index.js | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/v0/destinations/customerio/transform.js b/src/v0/destinations/customerio/transform.js index 948d7ecf30..984fb7e67f 100644 --- a/src/v0/destinations/customerio/transform.js +++ b/src/v0/destinations/customerio/transform.js @@ -12,6 +12,7 @@ const { adduserIdFromExternalId, getFieldValueFromMessage, handleRtTfSingleEventError, + validateEventName, } = require('../../util'); const logger = require('../../../logger'); @@ -101,6 +102,7 @@ function processSingleMessage(message, destination) { break; case EventType.TRACK: evType = 'event'; + validateEventName(message.event); evName = message.event; break; case EventType.ALIAS: diff --git a/src/v0/destinations/customerio/util.js b/src/v0/destinations/customerio/util.js index 2e7f000fba..6b4dbc0e11 100644 --- a/src/v0/destinations/customerio/util.js +++ b/src/v0/destinations/customerio/util.js @@ -10,7 +10,6 @@ const { defaultDeleteRequestConfig, isAppleFamily, validateEmail, - validateEventType, } = require('../../util'); const { EventType, SpecedTraits, TraitsMapping } = require('../../../constants'); @@ -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 diff --git a/src/v0/destinations/freshsales/transform.js b/src/v0/destinations/freshsales/transform.js index 0007106d92..2d6bd91b8f 100644 --- a/src/v0/destinations/freshsales/transform.js +++ b/src/v0/destinations/freshsales/transform.js @@ -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'); @@ -67,7 +67,7 @@ const identifyResponseBuilder = (message, { Config }) => { * @returns */ const trackResponseBuilder = async (message, { Config }, event) => { - validateEventType(event); + validateEventName(event); let payload; const response = defaultRequestConfig(); @@ -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(); @@ -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); } }); diff --git a/src/v0/destinations/monday/transform.js b/src/v0/destinations/monday/transform.js index 34ada34780..37ee835e50 100644 --- a/src/v0/destinations/monday/transform.js +++ b/src/v0/destinations/monday/transform.js @@ -8,7 +8,7 @@ const { removeUndefinedAndNullValues, simpleProcessRouterDest, getDestinationExternalID, - validateEventType, + validateEventName, } = require('../../util'); const { ConfigurationError, @@ -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; } diff --git a/src/v0/util/index.js b/src/v0/util/index.js index e5ec1642b4..d6f6621220 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -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'); } @@ -2177,7 +2177,7 @@ module.exports = { getDestAuthCacheInstance, refinePayload, validateEmail, - validateEventType, + validateEventName, validatePhoneWithCountryCode, getEventReqMetadata, isHybridModeEnabled,