Skip to content

Commit

Permalink
Merge branch 'develop' into fix.snapchat
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 authored Oct 11, 2023
2 parents 57d323f + d681d5e commit 02a22ba
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 43 deletions.
18 changes: 18 additions & 0 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,24 @@ class Prometheus {
type: 'gauge',
labelNames: ['destType', 'feature'],
},
{
name: 'braze_batch_attributes_pack_size',
help: 'braze_batch_attributes_pack_size',
type: 'gauge',
labelNames: ['destination_id'],
},
{
name: 'braze_batch_events_pack_size',
help: 'braze_batch_events_pack_size',
type: 'gauge',
labelNames: ['destination_id'],
},
{
name: 'braze_batch_purchase_pack_size',
help: 'braze_batch_purchase_pack_size',
type: 'gauge',
labelNames: ['destination_id'],
},

// Histograms
{
Expand Down
17 changes: 17 additions & 0 deletions src/v0/destinations/braze/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,23 @@ const processBatch = (transformedEvents) => {
const attributes = attributeArrayChunks[i];
const events = eventsArrayChunks[i];
const purchases = purchaseArrayChunks[i];

if (attributes) {
stats.gauge('braze_batch_attributes_pack_size', attributes.length, {
destination_id: destination.ID,
});
}
if (events) {
stats.gauge('braze_batch_events_pack_size', events.length, {
destination_id: destination.ID,
});
}
if (purchases) {
stats.gauge('braze_batch_purchase_pack_size', purchases.length, {
destination_id: destination.ID,
});
}

const response = defaultRequestConfig();
response.endpoint = endpoint;
response.body.JSON = removeUndefinedAndNullValues({
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const { get, set } = require('lodash');
const sha256 = require('sha256');
const { prepareProxyRequest, handleHttpRequest } = require('../../../adapters/network');
const {
isHttpStatusSuccess,
getAuthErrCategoryFromErrDetailsAndStCode,
} = require('../../util/index');
const { isHttpStatusSuccess, getAuthErrCategoryFromStCode } = require('../../util/index');
const { CONVERSION_ACTION_ID_CACHE_TTL } = require('./config');
const Cache = require('../../util/cache');

Expand Down Expand Up @@ -60,10 +57,7 @@ const getConversionActionId = async (method, headers, params) => {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(gaecConversionActionIdResponse.status),
},
gaecConversionActionIdResponse.response,
getAuthErrCategoryFromErrDetailsAndStCode(
get(gaecConversionActionIdResponse, 'status'),
get(gaecConversionActionIdResponse, ERROR_MSG_PATH),
),
getAuthErrCategoryFromStCode(gaecConversionActionIdResponse.status),
);
}
const conversionActionId = get(
Expand Down Expand Up @@ -142,7 +136,7 @@ const responseHandler = (destinationResponse) => {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
response,
getAuthErrCategoryFromErrDetailsAndStCode(status, response),
getAuthErrCategoryFromStCode(status),
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const { httpSend, prepareProxyRequest } = require('../../../adapters/network');
const {
isHttpStatusSuccess,
getAuthErrCategoryFromErrDetailsAndStCode,
} = require('../../util/index');
const { isHttpStatusSuccess, getAuthErrCategoryFromStCode } = require('../../util/index');

const {
processAxiosResponse,
Expand Down Expand Up @@ -144,7 +141,7 @@ const gaAudienceRespHandler = (destResponse, stageMsg) => {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
response,
getAuthErrCategoryFromErrDetailsAndStCode(status, response),
getAuthErrCategoryFromStCode(status),
);
};

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
3 changes: 2 additions & 1 deletion src/v0/destinations/snapchat_conversion/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const eventNameMapping = {
custom_event_4: 'CUSTOM_EVENT_4',
custom_event_5: 'CUSTOM_EVENT_5',
};

const pageTypeToTrackEvent = 'page_view';
const mappingConfig = getMappingConfig(ConfigCategory, __dirname);

module.exports = {
Expand All @@ -82,4 +82,5 @@ module.exports = {
mappingConfig,
trackCommonConfig: mappingConfig[ConfigCategory.COMMON.name],
MAX_BATCH_SIZE,
pageTypeToTrackEvent
};
7 changes: 5 additions & 2 deletions src/v0/destinations/snapchat_conversion/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
mappingConfig,
ConfigCategory,
MAX_BATCH_SIZE,
pageTypeToTrackEvent,
} = require('./config');
const {
msUnixTimestamp,
Expand Down Expand Up @@ -306,14 +307,16 @@ function eventMappingHandler(message, destination) {

function process(event) {
const { message, destination } = event;

// const message = { ...incomingMessage };
if (!message.type) {
throw new InstrumentationError('Event type is required');
}

const messageType = message.type.toLowerCase();
let response;
if (messageType === EventType.TRACK) {
if (messageType === EventType.PAGE) {
response = trackResponseBuilder(message, destination, pageTypeToTrackEvent);
} else if (messageType === EventType.TRACK) {
const mappedEvents = eventMappingHandler(message, destination);
if (mappedEvents.length > 0) {
response = [];
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
Loading

0 comments on commit 02a22ba

Please sign in to comment.