From dd672421b9f052d255b1a255253c1a6639032a29 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Wed, 4 Oct 2023 09:55:37 +0530 Subject: [PATCH 1/4] fix: bugsnag customerIo wrong event format --- src/v0/destinations/customerio/util.js | 2 +- test/__tests__/data/customerio_input.json | 66 ++++++++++++++++++++++ test/__tests__/data/customerio_output.json | 3 + 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/v0/destinations/customerio/util.js b/src/v0/destinations/customerio/util.js index 735b6a73d9..3b9f269e76 100644 --- a/src/v0/destinations/customerio/util.js +++ b/src/v0/destinations/customerio/util.js @@ -288,7 +288,7 @@ const defaultResponseBuilder = (message, evName, userId, evType, destination, me // 100 - len(`Viewed Screen`) = 86 trimmedEvName = `Viewed ${truncate(message.event || message.properties.name, 86)} Screen`; } else { - if (!evName) { + if (!evName || typeof evName !== 'string') { logger.error(`Could not determine event name`); throw new InstrumentationError(`Could not determine event name`); } diff --git a/test/__tests__/data/customerio_input.json b/test/__tests__/data/customerio_input.json index e2d987fc5a..f1f2774163 100644 --- a/test/__tests__/data/customerio_input.json +++ b/test/__tests__/data/customerio_input.json @@ -1,4 +1,70 @@ [ + { + "message": { + "type": "track", + "event": { + "Phone": "123456677", + "Lead ID": "abc", + "Lead URL": "https://simplisafe.com/admin/store/leads/19635101/view", + "firstName": "david tenenbaum", + "Pro Install": "Yes", + "Property Type": "Home", + "Last Lead Source": "uyfasauya ", + "Saved System URL": "ihguwivkbjc" + }, + "userId": "", + "channel": "web", + "context": { + "os": { + "name": "", + "version": "" + }, + "app": { + "name": "RudderLabs JavaScript SDK", + "version": "x.x.x", + "namespace": "com.rudderlabs.javascript" + }, + "page": { + "path": "/rudderstack-sample-site/", + "title": "Keyboard Site", + "search": "", + "referrer": "$direct", + "initial_referrer": "$direct", + "referring_domain": "", + "initial_referring_domain": "" + }, + "locale": "en-US", + "screen": { + "width": 1512, + "height": 982, + "density": 2, + "innerWidth": 347, + "innerHeight": 778 + }, + "traits": { + "name": "john ", + "lead_id": "abc", + "firstName": "doe " + }, + "campaign": {}, + "sessionId": 123456 + }, + "rudderId": "rudder_id", + "timestamp": "2022-12-03T18:37:57.755Z", + "properties": {}, + "receivedAt": "2022-12-03T18:37:57.758Z", + "request_ip": "62.59.170.125", + "anonymousId": "149a7c9f-0778-45f6-b071-d92523cc8738", + "originalTimestamp": "2022-12-03T18:37:57.614Z" + }, + "destination": { + "Config": { + "datacenter": "US", + "siteID": "46be54768e7d49ab2628", + "apiKey": "dummyApiKey" + } + } + }, { "message": { "channel": "web", diff --git a/test/__tests__/data/customerio_output.json b/test/__tests__/data/customerio_output.json index 42ed0a5cb4..8b782faafd 100644 --- a/test/__tests__/data/customerio_output.json +++ b/test/__tests__/data/customerio_output.json @@ -1,4 +1,7 @@ [ + { + "message": "Could not determine event name" + }, { "body": { "XML": {}, From dcfe11811adb7f74f052d98bfa27fbfeeb9a44c5 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Wed, 4 Oct 2023 10:16:23 +0530 Subject: [PATCH 2/4] fix: bugsnag monday wrong event format --- src/v0/destinations/monday/transform.js | 7 +++++-- src/v0/destinations/monday/util.js | 2 +- test/__tests__/data/monday.json | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/v0/destinations/monday/transform.js b/src/v0/destinations/monday/transform.js index a702f26602..e7bb383918 100644 --- a/src/v0/destinations/monday/transform.js +++ b/src/v0/destinations/monday/transform.js @@ -40,6 +40,9 @@ const responseBuilder = (payload, endpoint, apiToken) => { const trackResponseBuilder = async (message, { Config }) => { const { apiToken } = Config; let boardId = getDestinationExternalID(message, 'boardId'); + if (!message?.event || typeof message.event !== 'string') { + throw new InstrumentationError('Event name is required and it should be string'); + } if (!boardId) { boardId = Config.boardId; } @@ -48,8 +51,8 @@ const trackResponseBuilder = async (message, { Config }) => { } const event = get(message, 'event'); - if (!event) { - throw new InstrumentationError('event is not present in the input payloads'); + if (!event || typeof event !== 'string') { + throw new InstrumentationError('Event name is required and it should be string'); } if (!checkAllowedEventNameFromUI(event, Config)) { diff --git a/src/v0/destinations/monday/util.js b/src/v0/destinations/monday/util.js index dbd7b149d9..5f260aabae 100644 --- a/src/v0/destinations/monday/util.js +++ b/src/v0/destinations/monday/util.js @@ -253,7 +253,7 @@ const checkAllowedEventNameFromUI = (event, Config) => { let allowEvent; if (whitelistedEvents && whitelistedEvents.length > 0) { allowEvent = whitelistedEvents.some( - (whiteListedEvent) => whiteListedEvent.eventName.toLowerCase() === event.toLowerCase(), + (whiteListedEvent) => whiteListedEvent?.eventName?.toLowerCase() === event.toLowerCase(), ); } return !!allowEvent; diff --git a/test/__tests__/data/monday.json b/test/__tests__/data/monday.json index a3af2364a8..4470db5c78 100644 --- a/test/__tests__/data/monday.json +++ b/test/__tests__/data/monday.json @@ -428,7 +428,7 @@ } }, "output": { - "error": "event is not present in the input payloads" + "error": "Event name is required and it should be string" } }, { From 71a454a9df799aba8dce92b98b111e9353be7e7f Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Wed, 4 Oct 2023 10:24:13 +0530 Subject: [PATCH 3/4] fix: bugsnag freshsales wrong event format --- src/v0/destinations/freshsales/transform.js | 4 +- test/__tests__/data/freshsales.json | 85 +++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/v0/destinations/freshsales/transform.js b/src/v0/destinations/freshsales/transform.js index 46a9e8c500..bd2a91febb 100644 --- a/src/v0/destinations/freshsales/transform.js +++ b/src/v0/destinations/freshsales/transform.js @@ -66,8 +66,8 @@ const identifyResponseBuilder = (message, { Config }) => { * @returns */ const trackResponseBuilder = async (message, { Config }, event) => { - if (!event) { - throw new InstrumentationError('Event name is required for track call.'); + if (!event || typeof event !== 'string') { + throw new InstrumentationError('String Event name is required for track call.'); } let payload; diff --git a/test/__tests__/data/freshsales.json b/test/__tests__/data/freshsales.json index a9070d5bfe..11553e799b 100644 --- a/test/__tests__/data/freshsales.json +++ b/test/__tests__/data/freshsales.json @@ -1,4 +1,89 @@ [ + { + "description": "Track call, event is not supported.", + "input": { + "message": { + "channel": "web", + "context": { + "app": { + "build": "1.0.0", + "name": "RudderLabs JavaScript SDK", + "namespace": "com.rudderlabs.javascript", + "version": "1.1.5" + }, + "traits": { + "name": "Shehan Study", + "category": "SampleIdentify", + "email": "test@rudderstack.com", + "plan": "Open source", + "logins": 5, + "createdAt": 1599264000 + }, + "library": { + "name": "RudderLabs JavaScript SDK", + "version": "1.1.5" + }, + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36", + "locale": "en-US", + "os": { + "name": "", + "version": "" + }, + "screen": { + "density": 0.8999999761581421 + }, + "campaign": { + "source": "google", + "medium": "medium", + "term": "keyword", + "content": "some content", + "name": "some campaign", + "test": "other value" + }, + "page": { + "path": "/destinations/amplitude", + "referrer": "", + "search": "", + "title": "", + "url": "https://docs.rudderstack.com/destinations/amplitude", + "category": "destination", + "initial_referrer": "https://docs.rudderstack.com", + "initial_referring_domain": "docs.rudderstack.com" + } + }, + "type": "track", + "messageId": "dd46338d-5f83-493b-bd28-3b48f55d0be8", + "originalTimestamp": "2020-10-20T08:14:28.778Z", + "anonymousId": "my-anonymous-id-new", + "userId": "newUserIdAlias", + "properties": { + "product_name": "Shirt", + "brand": "Wrogn" + }, + "event": { + "name": "Add to Cart" + }, + "previousId": "sampleusrRudder3", + "sentAt": "2020-10-20T08:14:28.778Z" + }, + "destination": { + "Config": { + "apiKey": "dummyApiKey", + "domain": "domain-rudder" + } + } + }, + "output": { + "statusCode": 400, + "error": "String Event name is required for track call.", + "statTags": { + "errorAt": "proc", + "destType": "FRESHMARKETER", + "stage": "transform", + "scope": "exception" + } + } + }, { "description": "Identify call for creating new user", "input": { From d1a98be29235023d143e459f6cccf890b7ca0f41 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Wed, 4 Oct 2023 21:30:27 +0530 Subject: [PATCH 4/4] chore:comment addresed --- src/v0/destinations/customerio/util.js | 7 ++----- src/v0/destinations/freshsales/transform.js | 5 ++--- src/v0/destinations/monday/transform.js | 12 +++--------- src/v0/util/index.js | 6 ++++++ test/__tests__/data/customerio_output.json | 2 +- test/__tests__/data/freshsales.json | 2 +- test/__tests__/data/monday.json | 2 +- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/v0/destinations/customerio/util.js b/src/v0/destinations/customerio/util.js index 3b9f269e76..2e7f000fba 100644 --- a/src/v0/destinations/customerio/util.js +++ b/src/v0/destinations/customerio/util.js @@ -2,7 +2,6 @@ const get = require('get-value'); const set = require('set-value'); const truncate = require('truncate-utf8-bytes'); const { MAX_BATCH_SIZE, configFieldsToCheck } = require('./config'); -const logger = require('../../../logger'); const { constructPayload, defaultPutRequestConfig, @@ -11,6 +10,7 @@ const { defaultDeleteRequestConfig, isAppleFamily, validateEmail, + validateEventType, } = require('../../util'); const { EventType, SpecedTraits, TraitsMapping } = require('../../../constants'); @@ -288,10 +288,7 @@ const defaultResponseBuilder = (message, evName, userId, evType, destination, me // 100 - len(`Viewed Screen`) = 86 trimmedEvName = `Viewed ${truncate(message.event || message.properties.name, 86)} Screen`; } else { - if (!evName || typeof evName !== 'string') { - logger.error(`Could not determine event name`); - throw new InstrumentationError(`Could not determine event name`); - } + 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 bd2a91febb..cd7518a101 100644 --- a/src/v0/destinations/freshsales/transform.js +++ b/src/v0/destinations/freshsales/transform.js @@ -8,6 +8,7 @@ const { defaultPostRequestConfig, getValidDynamicFormConfig, simpleProcessRouterDest, + validateEventType, } = require('../../util'); const { InstrumentationError, TransformationError } = require('../../util/errorTypes'); const { CONFIG_CATEGORIES, MAPPING_CONFIG } = require('./config'); @@ -66,9 +67,7 @@ const identifyResponseBuilder = (message, { Config }) => { * @returns */ const trackResponseBuilder = async (message, { Config }, event) => { - if (!event || typeof event !== 'string') { - throw new InstrumentationError('String Event name is required for track call.'); - } + validateEventType(event); let payload; const response = defaultRequestConfig(); diff --git a/src/v0/destinations/monday/transform.js b/src/v0/destinations/monday/transform.js index e7bb383918..34ada34780 100644 --- a/src/v0/destinations/monday/transform.js +++ b/src/v0/destinations/monday/transform.js @@ -8,6 +8,7 @@ const { removeUndefinedAndNullValues, simpleProcessRouterDest, getDestinationExternalID, + validateEventType, } = require('../../util'); const { ConfigurationError, @@ -40,21 +41,14 @@ const responseBuilder = (payload, endpoint, apiToken) => { const trackResponseBuilder = async (message, { Config }) => { const { apiToken } = Config; let boardId = getDestinationExternalID(message, 'boardId'); - if (!message?.event || typeof message.event !== 'string') { - throw new InstrumentationError('Event name is required and it should be string'); - } + const event = get(message, 'event'); + validateEventType(event); if (!boardId) { boardId = Config.boardId; } if (!boardId) { throw new ConfigurationError('boardId is a required field'); } - const event = get(message, 'event'); - - if (!event || typeof event !== 'string') { - throw new InstrumentationError('Event name is required and it should be string'); - } - if (!checkAllowedEventNameFromUI(event, Config)) { throw new ConfigurationError('Event Discarded. To allow this event, add this in Allowlist'); } diff --git a/src/v0/util/index.js b/src/v0/util/index.js index 42a4100510..e6f7fccc27 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -2025,6 +2025,11 @@ const getAuthErrCategoryFromStCode = (status) => { return ''; }; +const validateEventType = event => { + if(!event || typeof event !== "string"){ + throw new InstrumentationError("Event is a required field and should be a string"); + } +} // ======================================================================== // EXPORTS // ======================================================================== @@ -2118,6 +2123,7 @@ module.exports = { getDestAuthCacheInstance, refinePayload, validateEmail, + validateEventType, validatePhoneWithCountryCode, getEventReqMetadata, isHybridModeEnabled, diff --git a/test/__tests__/data/customerio_output.json b/test/__tests__/data/customerio_output.json index 8b782faafd..3a0b45ebb6 100644 --- a/test/__tests__/data/customerio_output.json +++ b/test/__tests__/data/customerio_output.json @@ -1,6 +1,6 @@ [ { - "message": "Could not determine event name" + "message": "Event is a required field and should be a string" }, { "body": { diff --git a/test/__tests__/data/freshsales.json b/test/__tests__/data/freshsales.json index 11553e799b..2527e37b90 100644 --- a/test/__tests__/data/freshsales.json +++ b/test/__tests__/data/freshsales.json @@ -75,7 +75,7 @@ }, "output": { "statusCode": 400, - "error": "String Event name is required for track call.", + "error": "Event is a required field and should be a string", "statTags": { "errorAt": "proc", "destType": "FRESHMARKETER", diff --git a/test/__tests__/data/monday.json b/test/__tests__/data/monday.json index 4470db5c78..cec99959da 100644 --- a/test/__tests__/data/monday.json +++ b/test/__tests__/data/monday.json @@ -428,7 +428,7 @@ } }, "output": { - "error": "Event name is required and it should be string" + "error": "Event is a required field and should be a string" } }, {