Skip to content

Commit

Permalink
chore:comment addresed
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Oct 4, 2023
1 parent 2af5310 commit d1a98be
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
7 changes: 2 additions & 5 deletions src/v0/destinations/customerio/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -11,6 +10,7 @@ const {
defaultDeleteRequestConfig,
isAppleFamily,
validateEmail,
validateEventType,
} = require('../../util');

const { EventType, SpecedTraits, TraitsMapping } = require('../../../constants');
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/v0/destinations/freshsales/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
defaultPostRequestConfig,
getValidDynamicFormConfig,
simpleProcessRouterDest,
validateEventType,
} = require('../../util');
const { InstrumentationError, TransformationError } = require('../../util/errorTypes');
const { CONFIG_CATEGORIES, MAPPING_CONFIG } = require('./config');
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 3 additions & 9 deletions src/v0/destinations/monday/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
removeUndefinedAndNullValues,
simpleProcessRouterDest,
getDestinationExternalID,
validateEventType,
} = require('../../util');
const {
ConfigurationError,
Expand Down Expand Up @@ -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');
}
Expand Down
6 changes: 6 additions & 0 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ========================================================================
Expand Down Expand Up @@ -2118,6 +2123,7 @@ module.exports = {
getDestAuthCacheInstance,
refinePayload,
validateEmail,
validateEventType,
validatePhoneWithCountryCode,
getEventReqMetadata,
isHybridModeEnabled,
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/data/customerio_output.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "Could not determine event name"
"message": "Event is a required field and should be a string"
},
{
"body": {
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/data/freshsales.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/data/monday.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down

0 comments on commit d1a98be

Please sign in to comment.