Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:rudderlabs/rudder-transformer in…
Browse files Browse the repository at this point in the history
…to fix.nw-handle-garl-gaec
  • Loading branch information
Sai Sankeerth committed Oct 11, 2023
2 parents e3c0e86 + b211840 commit c76c3a8
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 25 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) {
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
18 changes: 11 additions & 7 deletions src/v0/destinations/klaviyo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,18 @@ const processRouterDest = async (inputs, reqMetadata) => {
message?.statusCode &&
message.statusCode === HTTP_STATUS_CODES.SUPPRESS_EVENTS
) {
const { error } = message;
delete message.error;
delete message.statusCode;
return getSuccessRespEvents(
message,
[metadata],
eventDestination,
false,
HTTP_STATUS_CODES.SUPPRESS_EVENTS,
);
return {
...getSuccessRespEvents(
message,
[metadata],
eventDestination,
false,
HTTP_STATUS_CODES.SUPPRESS_EVENTS,
), error
}
}
return getSuccessRespEvents(message, [metadata], eventDestination);
});
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 @@ -2040,6 +2040,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 @@ -2133,6 +2138,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
4 changes: 2 additions & 2 deletions test/__tests__/data/klaviyo_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@
"XML": {},
"FORM": {}
},
"files": {},
"error": "{\"id\":\"01GW3PHVY0MTCDGS0A1612HARX\",\"attributes\":{}}"
"files": {}
},
"error": "{\"id\":\"01GW3PHVY0MTCDGS0A1612HARX\",\"attributes\":{}}",
"metadata": [
{
"jobId": 1
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

0 comments on commit c76c3a8

Please sign in to comment.