Skip to content

Commit

Permalink
Merge branch 'feat.slack-source' of https://github.com/rudderlabs/rud…
Browse files Browse the repository at this point in the history
…der-transformer into feat.slack-source
  • Loading branch information
gitcommitshow committed Mar 4, 2024
2 parents d0c5942 + a73f578 commit 4514a73
Show file tree
Hide file tree
Showing 36 changed files with 2,572 additions and 711 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.57.0](https://github.com/rudderlabs/rudder-transformer/compare/v1.56.1...v1.57.0) (2024-02-29)


### Features

* add event mapping support for branch destination ([#3135](https://github.com/rudderlabs/rudder-transformer/issues/3135)) ([cc94bba](https://github.com/rudderlabs/rudder-transformer/commit/cc94bba682f667877a721f63627adc6ff6a7386a))


### Bug Fixes

* marketo bulk upload zero and null value allowed ([#3134](https://github.com/rudderlabs/rudder-transformer/issues/3134)) ([4dcbf8f](https://github.com/rudderlabs/rudder-transformer/commit/4dcbf8fb189a39bb40b950742425a0b9da2d8d7c))

### [1.56.1](https://github.com/rudderlabs/rudder-transformer/compare/v1.56.0...v1.56.1) (2024-02-21)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-transformer",
"version": "1.56.1",
"version": "1.57.0",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
6 changes: 5 additions & 1 deletion src/services/destination/nativeIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ export class NativeIntegrationDestinationService implements DestinationService {
const jobStates = (deliveryRequest as ProxyV1Request).metadata.map(
(metadata) =>
({
error: JSON.stringify(v0Response.destinationResponse?.response),
error: JSON.stringify(
v0Response.destinationResponse?.response === undefined
? v0Response.destinationResponse
: v0Response.destinationResponse?.response,
),
statusCode: v0Response.status,
metadata,
}) as DeliveryJobState,
Expand Down
16 changes: 7 additions & 9 deletions src/v0/destinations/branch/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
simpleProcessRouterDest,
} = require('../../util');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { getMappedEventNameFromConfig } = require('./utils');

function responseBuilder(payload, message, destination, category) {
const response = defaultRequestConfig();
Expand Down Expand Up @@ -213,24 +214,21 @@ function getCommonPayload(message, category, evName) {
return rawPayload;
}

// function getTrackPayload(message) {
// const rawPayload = {};
// const { name, category } = getCategoryAndName(message.event);
// rawPayload.name = name;
//
// return commonPayload(message, rawPayload, category);
// }

function processMessage(message, destination) {
let evName;
let category;
switch (message.type) {
case EventType.TRACK:
case EventType.TRACK: {
if (!message.event) {
throw new InstrumentationError('Event name is required');
}
({ evName, category } = getCategoryAndName(message.event));
const eventNameFromConfig = getMappedEventNameFromConfig(message, destination);
if (eventNameFromConfig) {
evName = eventNameFromConfig;
}
break;
}
case EventType.IDENTIFY:
({ evName, category } = getCategoryAndName(message.userId));
break;
Expand Down
24 changes: 24 additions & 0 deletions src/v0/destinations/branch/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { getHashFromArray } = require('../../util');

/**
* Retrieves the mapped event name from the given config.
*
* @param {object} message - The message object containing the event.
* @param {object} destination - The destination object containing the events mapping configuration.
* @returns {string} - The mapped event name, or undefined if not found.
*/
const getMappedEventNameFromConfig = (message, destination) => {
let eventName;
const { event } = message;
const { eventsMapping } = destination.Config;

// if event is mapped on dashboard, use the mapped event name
if (Array.isArray(eventsMapping) && eventsMapping.length > 0) {
const keyMap = getHashFromArray(eventsMapping, 'from', 'to', false);
eventName = keyMap[event];
}

return eventName;
};

module.exports = { getMappedEventNameFromConfig };
18 changes: 18 additions & 0 deletions src/v0/destinations/branch/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { getMappedEventNameFromConfig } = require('./utils');
describe('getMappedEventNameFromConfig', () => {
it('should return the mapped event name when it exists in the events mapping configuration', () => {
const message = { event: 'Order Completed' };
const destination = {
Config: { eventsMapping: [{ from: 'Order Completed', to: 'PURCHASE' }] },
};
const result = getMappedEventNameFromConfig(message, destination);
expect(result).toBe('PURCHASE');
});

it('should return undefined when the event mapping is not created', () => {
const message = { event: 'Order Completed' };
const destination = { Config: {} };
const result = getMappedEventNameFromConfig(message, destination);
expect(result).toBeUndefined();
});
});
48 changes: 25 additions & 23 deletions src/v0/destinations/facebook_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,26 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
);

const contentCategory = eventTypeCustomData.content_category;
let contentType;
let defaultContentType;
if (contentIds.length > 0) {
contentType = 'product';
defaultContentType = 'product';
} else if (contentCategory) {
contentIds.push(contentCategory);
contents.push({
id: contentCategory,
quantity: 1,
});
contentType = 'product_group';
defaultContentType = 'product_group';
}
const contentType =
message.properties?.content_type ||
getContentType(message, defaultContentType, categoryToContent, DESTINATION.toLowerCase());

eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds,
contents,
content_type: getContentType(
message,
contentType,
categoryToContent,
DESTINATION.toLowerCase(),
),
content_type: contentType,
content_category: getContentCategory(contentCategory),
};
break;
Expand All @@ -125,18 +123,20 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
case 'payment info entered':
case 'product added to wishlist': {
const contentCategory = eventTypeCustomData.content_category;
const contentType = eventTypeCustomData.content_type;
const contentType =
message.properties?.content_type ||
getContentType(
message,
eventTypeCustomData.content_type,
categoryToContent,
DESTINATION.toLowerCase(),
);
const { contentIds, contents } = populateContentsAndContentIDs([message.properties]);
eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds,
contents,
content_type: getContentType(
message,
contentType,
categoryToContent,
DESTINATION.toLowerCase(),
),
content_type: contentType,
content_category: getContentCategory(contentCategory),
};
validateProductSearchedData(eventTypeCustomData);
Expand All @@ -151,18 +151,20 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
);

const contentCategory = eventTypeCustomData.content_category;
const contentType = eventTypeCustomData.content_type;
const contentType =
message.properties?.content_type ||
getContentType(
message,
eventTypeCustomData.content_type,
categoryToContent,
DESTINATION.toLowerCase(),
);

eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds,
contents,
content_type: getContentType(
message,
contentType,
categoryToContent,
DESTINATION.toLowerCase(),
),
content_type: contentType,
content_category: getContentCategory(contentCategory),
num_items: contentIds.length,
};
Expand Down
34 changes: 22 additions & 12 deletions src/v0/destinations/facebook_pixel/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@ const getActionSource = (payload, channel) => {
* Handles order completed and checkout started types of specific events
*/
const handleOrder = (message, categoryToContent) => {
const { products, revenue } = message.properties;
const value = formatRevenue(revenue);

const contentType = getContentType(message, 'product', categoryToContent);
const contentIds = [];
const contents = [];
const {
products,
revenue,
category,
quantity,
price,
currency,
contentName,
delivery_category: deliveryCategory,
} = message.properties;
const value = formatRevenue(revenue);
let { content_type: contentType } = message.properties;
contentType = contentType || getContentType(message, 'product', categoryToContent);
const contentIds = [];
const contents = [];

if (products) {
if (products.length > 0 && Array.isArray(products)) {
products.forEach((singleProduct) => {
Expand Down Expand Up @@ -109,10 +111,17 @@ const handleOrder = (message, categoryToContent) => {
* Handles product list viewed
*/
const handleProductListViewed = (message, categoryToContent) => {
let contentType;
let defaultContentType;
const contentIds = [];
const contents = [];
const { products, category, quantity, value, contentName } = message.properties;
const {
products,
category,
quantity,
value,
contentName,
content_type: contentType,
} = message.properties;
if (products && products.length > 0 && Array.isArray(products)) {
products.forEach((product, index) => {
if (isObject(product)) {
Expand All @@ -132,20 +141,20 @@ const handleProductListViewed = (message, categoryToContent) => {
}

if (contentIds.length > 0) {
contentType = 'product';
defaultContentType = 'product';
// for viewContent event content_ids and content arrays are not mandatory
} else if (category) {
contentIds.push(category);
contents.push({
id: category,
quantity: 1,
});
contentType = 'product_group';
defaultContentType = 'product_group';
}

return {
content_ids: contentIds,
content_type: getContentType(message, contentType, categoryToContent),
content_type: contentType || getContentType(message, defaultContentType, categoryToContent),
contents,
content_category: getContentCategory(category),
content_name: contentName,
Expand All @@ -165,7 +174,8 @@ const handleProduct = (message, categoryToContent, valueFieldIdentifier) => {
const useValue = valueFieldIdentifier === 'properties.value';
const contentId =
message.properties?.product_id || message.properties?.sku || message.properties?.id;
const contentType = getContentType(message, 'product', categoryToContent);
const contentType =
message.properties?.content_type || getContentType(message, 'product', categoryToContent);
const contentName = message.properties.product_name || message.properties.name || '';
const contentCategory = message.properties.category || '';
const currency = message.properties.currency || 'USD';
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/marketo_bulk_upload/transform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { InstrumentationError, isDefined } = require('@rudderstack/integrations-lib');
const {
getHashFromArray,
getFieldValueFromMessage,
Expand Down Expand Up @@ -34,7 +34,7 @@ function responseBuilderSimple(message, destination) {
// columnNames with trait's values from rudder payload
Object.keys(fieldHashmap).forEach((key) => {
const val = traits[fieldHashmap[key]];
if (val) {
if (isDefined(val)) {
payload[key] = val;
}
});
Expand Down
26 changes: 23 additions & 3 deletions src/v0/destinations/mp/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
groupEventsByEndpoint,
batchEvents,
trimTraits,
generatePageOrScreenCustomEventName,
} = require('./util');
const { CommonUtils } = require('../../../util/common');

Expand Down Expand Up @@ -297,17 +298,25 @@ const processIdentifyEvents = async (message, type, destination) => {
};

const processPageOrScreenEvents = (message, type, destination) => {
const {
token,
identityMergeApi,
useUserDefinedPageEventName,
userDefinedPageEventTemplate,
useUserDefinedScreenEventName,
userDefinedScreenEventTemplate,
} = destination.Config;
const mappedProperties = constructPayload(message, mPEventPropertiesConfigJson);
let properties = {
...get(message, 'context.traits'),
...message.properties,
...mappedProperties,
token: destination.Config.token,
token,
distinct_id: message.userId || message.anonymousId,
time: toUnixTimestampInMS(message.timestamp || message.originalTimestamp),
...buildUtmParams(message.context?.campaign),
};
if (destination.Config?.identityMergeApi === 'simplified') {
if (identityMergeApi === 'simplified') {
properties = {
...properties,
distinct_id: message.userId || `$device:${message.anonymousId}`,
Expand All @@ -326,7 +335,18 @@ const processPageOrScreenEvents = (message, type, destination) => {
properties.$browser = browser.name;
properties.$browser_version = browser.version;
}
const eventName = type === 'page' ? 'Loaded a Page' : 'Loaded a Screen';

let eventName;
if (type === 'page') {
eventName = useUserDefinedPageEventName
? generatePageOrScreenCustomEventName(message, userDefinedPageEventTemplate)
: 'Loaded a Page';
} else {
eventName = useUserDefinedScreenEventName
? generatePageOrScreenCustomEventName(message, userDefinedScreenEventTemplate)
: 'Loaded a Screen';
}

const payload = {
event: eventName,
properties,
Expand Down
Loading

0 comments on commit 4514a73

Please sign in to comment.