Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bugsnag event sent as an object for track call #2681

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
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) {
throw new InstrumentationError('Event name is required for track call.');
}
validateEventType(event);
let payload;

const response = defaultRequestConfig();
Expand Down
9 changes: 3 additions & 6 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,18 +41,14 @@ const responseBuilder = (payload, endpoint, apiToken) => {
const trackResponseBuilder = async (message, { Config }) => {
const { apiToken } = Config;
let boardId = getDestinationExternalID(message, 'boardId');
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) {
throw new InstrumentationError('event is not present in the input payloads');
}

if (!checkAllowedEventNameFromUI(event, Config)) {
throw new ConfigurationError('Event Discarded. To allow this event, add this in Allowlist');
}
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/monday/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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");
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
}
}
// ========================================================================
// EXPORTS
// ========================================================================
Expand Down Expand Up @@ -2118,6 +2123,7 @@ module.exports = {
getDestAuthCacheInstance,
refinePayload,
validateEmail,
validateEventType,
validatePhoneWithCountryCode,
getEventReqMetadata,
isHybridModeEnabled,
Expand Down
66 changes: 66 additions & 0 deletions test/__tests__/data/customerio_input.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/data/customerio_output.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[
{
"message": "Event is a required field and should be a string"
},
{
"body": {
"XML": {},
Expand Down
85 changes: 85 additions & 0 deletions test/__tests__/data/freshsales.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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": "Event is a required field and should be a string",
"statTags": {
"errorAt": "proc",
"destType": "FRESHMARKETER",
"stage": "transform",
"scope": "exception"
}
}
},
{
"description": "Identify call for creating new user",
"input": {
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 is not present in the input payloads"
"error": "Event is a required field and should be a string"
}
},
{
Expand Down
Loading