From 11fb7c47910681833e37d25a1573d2005e62742b Mon Sep 17 00:00:00 2001 From: Ujjwal Abhishek <63387036+ujjwal-ab@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:28:51 +0530 Subject: [PATCH] fix: busgnag issues for klaviyo, freshsales, customeio (#2795) * chore(klaviyo): remove error notifier * fix(freshsales): stringify event before lowercase * fix(customerio): convert eventName to string for truncate * fix: add validation for event Name type and update function name * fix: remove unrequired validation --- src/v0/destinations/customerio/transform.js | 3 +++ src/v0/destinations/customerio/util.js | 2 -- src/v0/destinations/freshsales/transform.js | 7 ++----- src/v0/destinations/klaviyo/util.js | 6 ------ src/v0/destinations/monday/transform.js | 4 ++-- src/v0/util/index.js | 4 ++-- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/v0/destinations/customerio/transform.js b/src/v0/destinations/customerio/transform.js index 5f953ee2f0..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: @@ -113,6 +115,7 @@ function processSingleMessage(message, destination) { logger.error(`could not determine type ${messageType}`); throw new InstrumentationError(`could not determine type ${messageType}`); } + evName = evName ? String(evName) : evName; const response = responseBuilder(message, evType, evName, destination, messageType); // replace default domain with EU data center domainc for EU based account 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 cd7518a101..c1e18482ed 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,6 @@ const identifyResponseBuilder = (message, { Config }) => { * @returns */ const trackResponseBuilder = async (message, { Config }, event) => { - validateEventType(event); let payload; const response = defaultRequestConfig(); @@ -125,9 +124,6 @@ const groupResponseBuilder = async (message, { Config }) => { // Checks if there are any mapping events for the track event and returns them function eventMappingHandler(message, destination) { const event = get(message, 'event'); - if (!event) { - throw new InstrumentationError('Event name is required'); - } let { rudderEventsToFreshsalesEvents } = destination.Config; const mappedEvents = new Set(); @@ -161,6 +157,7 @@ const processEvent = async (message, destination) => { response = identifyResponseBuilder(message, destination); break; case EventType.TRACK: { + validateEventName(message.event); const mappedEvents = eventMappingHandler(message, destination); if (mappedEvents.length > 0) { const respList = await Promise.all( diff --git a/src/v0/destinations/klaviyo/util.js b/src/v0/destinations/klaviyo/util.js index 4304edd78f..b31dafd78b 100644 --- a/src/v0/destinations/klaviyo/util.js +++ b/src/v0/destinations/klaviyo/util.js @@ -17,7 +17,6 @@ const { handleHttpRequest } = require('../../../adapters/network'); const { JSON_MIME_TYPE, HTTP_STATUS_CODES } = require('../../util/constant'); const { NetworkError, InstrumentationError } = require('../../util/errorTypes'); const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils'); -const { client: errNotificationClient } = require('../../../util/errorNotifier'); const { BASE_ENDPOINT, MAPPING_CONFIG, CONFIG_CATEGORIES, MAX_BATCH_SIZE } = require('./config'); const REVISION_CONSTANT = '2023-02-22'; @@ -69,11 +68,6 @@ const getIdFromNewOrExistingProfile = async (endpoint, payload, requestOptions) let statusCode = resp.status; if (resp.status === 201 || resp.status === 409) { // retryable error if the profile id is not found in the response - errNotificationClient.notify( - new Error('Klaviyo: ProfileId not found'), - 'Profile Id not Found in the response', - JSON.stringify(resp.response), - ); statusCode = 500; } 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,