From cc94bba682f667877a721f63627adc6ff6a7386a Mon Sep 17 00:00:00 2001 From: Gauravudia <60897972+Gauravudia@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:34:15 +0530 Subject: [PATCH 1/3] feat: add event mapping support for branch destination (#3135) * feat: add event mapping support for branch destination * refactor: address review comments --- src/v0/destinations/branch/transform.js | 16 +- src/v0/destinations/branch/utils.js | 24 +++ src/v0/destinations/branch/utils.test.js | 18 ++ .../destinations/branch/processor/data.ts | 156 ++++++++++++++++++ 4 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 src/v0/destinations/branch/utils.js create mode 100644 src/v0/destinations/branch/utils.test.js diff --git a/src/v0/destinations/branch/transform.js b/src/v0/destinations/branch/transform.js index 23dcd6c8db..2626d8aa81 100644 --- a/src/v0/destinations/branch/transform.js +++ b/src/v0/destinations/branch/transform.js @@ -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(); @@ -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; diff --git a/src/v0/destinations/branch/utils.js b/src/v0/destinations/branch/utils.js new file mode 100644 index 0000000000..1415f0de39 --- /dev/null +++ b/src/v0/destinations/branch/utils.js @@ -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 }; diff --git a/src/v0/destinations/branch/utils.test.js b/src/v0/destinations/branch/utils.test.js new file mode 100644 index 0000000000..e7da007d89 --- /dev/null +++ b/src/v0/destinations/branch/utils.test.js @@ -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(); + }); +}); diff --git a/test/integrations/destinations/branch/processor/data.ts b/test/integrations/destinations/branch/processor/data.ts index 9fed354235..dc1bdd33bc 100644 --- a/test/integrations/destinations/branch/processor/data.ts +++ b/test/integrations/destinations/branch/processor/data.ts @@ -1490,4 +1490,160 @@ export const data = [ }, }, }, + { + name: 'branch', + description: 'Map event name to branch standard event name in track call', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: { + Config: { + branchKey: 'test_branch_key', + eventsMapping: [ + { + from: 'Order Completed', + to: 'PURCHASE', + }, + ], + useNativeSDK: false, + }, + DestinationDefinition: { + DisplayName: 'Branch Metrics', + ID: '1WTpBSTiL3iAUHUdW7rHT4sawgU', + Name: 'BRANCH', + }, + Enabled: true, + ID: '1WTpIHpH7NTBgjeiUPW1kCUgZGI', + Name: 'branch test', + Transformations: [], + }, + message: { + anonymousId: 'anonId123', + channel: 'web', + context: { + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.0.0', + }, + device: { + adTrackingEnabled: true, + advertisingId: '3f034872-5e28-45a1-9eda-ce22a3e36d1a', + id: '3f034872-5e28-45a1-9eda-ce22a3e36d1a', + manufacturer: 'Google', + model: 'AOSP on IA Emulator', + name: 'generic_x86_arm', + type: 'ios', + attTrackingStatus: 3, + }, + ip: '0.0.0.0', + library: { + name: 'RudderLabs JavaScript SDK', + version: '1.0.0', + }, + locale: 'en-US', + os: { + name: 'iOS', + version: '14.4.1', + }, + screen: { + density: 2, + }, + traits: { + anonymousId: 'anonId123', + email: 'test_user@gmail.com', + }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', + }, + event: 'Order Completed', + integrations: { + All: true, + }, + messageId: 'ea5cfab2-3961-4d8a-8187-3d1858c90a9f', + originalTimestamp: '2020-01-17T04:53:51.185Z', + properties: { + name: 't-shirt', + revenue: '10', + currency: 'USD', + key1: 'value1', + key2: 'value2', + order_id: 'order123', + }, + receivedAt: '2020-01-17T10:23:52.688+05:30', + request_ip: '[::1]:64059', + sentAt: '2020-01-17T04:53:52.667Z', + timestamp: '2020-01-17T10:23:51.206+05:30', + type: 'track', + userId: 'userId123', + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://api2.branch.io/v2/event/standard', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + params: {}, + body: { + JSON: { + branch_key: 'test_branch_key', + name: 'PURCHASE', + content_items: [ + { + $product_name: 't-shirt', + }, + ], + event_data: { + revenue: '10', + currency: 'USD', + }, + custom_data: { + key1: 'value1', + key2: 'value2', + order_id: 'order123', + }, + user_data: { + os: 'iOS', + os_version: '14.4.1', + app_version: '1.0.0', + screen_dpi: 2, + developer_identity: 'userId123', + idfa: '3f034872-5e28-45a1-9eda-ce22a3e36d1a', + idfv: '3f034872-5e28-45a1-9eda-ce22a3e36d1a', + limit_ad_tracking: false, + model: 'AOSP on IA Emulator', + user_agent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', + }, + }, + XML: {}, + JSON_ARRAY: {}, + FORM: {}, + }, + files: {}, + userId: 'anonId123', + }, + statusCode: 200, + }, + ], + }, + }, + }, ]; From 4dcbf8fb189a39bb40b950742425a0b9da2d8d7c Mon Sep 17 00:00:00 2001 From: shrouti1507 <60211312+shrouti1507@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:44:25 +0530 Subject: [PATCH 2/3] fix: marketo bulk upload zero and null value allowed (#3134) --- .../marketo_bulk_upload/transform.js | 4 +- .../marketo_bulk_upload/processor/data.ts | 93 +++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/v0/destinations/marketo_bulk_upload/transform.js b/src/v0/destinations/marketo_bulk_upload/transform.js index 5431e67d38..1943d817cd 100644 --- a/src/v0/destinations/marketo_bulk_upload/transform.js +++ b/src/v0/destinations/marketo_bulk_upload/transform.js @@ -1,4 +1,4 @@ -const { InstrumentationError } = require('@rudderstack/integrations-lib'); +const { InstrumentationError, isDefined } = require('@rudderstack/integrations-lib'); const { getHashFromArray, getFieldValueFromMessage, @@ -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; } }); diff --git a/test/integrations/destinations/marketo_bulk_upload/processor/data.ts b/test/integrations/destinations/marketo_bulk_upload/processor/data.ts index f1b162ad28..90a3ca8584 100644 --- a/test/integrations/destinations/marketo_bulk_upload/processor/data.ts +++ b/test/integrations/destinations/marketo_bulk_upload/processor/data.ts @@ -502,4 +502,97 @@ export const data = [ }, }, }, + { + name: 'marketo_bulk_upload', + description: 'Test 5: Any null or zero value will be passed through transform payload', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + type: 'identify', + traits: { + name: 'Carlo Lombard', + plan: 0, + id: null, + }, + userId: 476335, + context: { + ip: '14.0.2.238', + page: { + url: 'enuffsaid.proposify.com', + path: '/settings', + method: 'POST', + referrer: 'https://enuffsaid.proposify.com/login', + }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36', + }, + rudderId: '786dfec9-jfh', + messageId: '5d9bc6e2-ekjh', + }, + destination: { + ID: '1mMy5cqbtfuaKZv1IhVQKnBdVwe', + Config: { + munchkinId: 'XXXX', + clientId: 'YYYY', + clientSecret: 'ZZZZ', + columnFieldsMapping: [ + { + to: 'name__c', + from: 'name', + }, + { + to: 'email__c', + from: 'email', + }, + { + to: 'plan__c', + from: 'plan', + }, + { + to: 'id', + from: 'id', + }, + ], + }, + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: '/fileUpload', + headers: {}, + params: {}, + body: { + JSON: { + name__c: 'Carlo Lombard', + plan__c: 0, + id: null, + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + }, + ], + }, + }, + }, ]; From 2a68c4573d92274908b26082ec3ad2b4c7f7776e Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 29 Feb 2024 07:26:41 +0000 Subject: [PATCH 3/3] chore(release): 1.57.0 --- CHANGELOG.md | 12 ++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 902d797301..7c526b8051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package-lock.json b/package-lock.json index 2d4f32bd5a..dfed6e2397 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rudder-transformer", - "version": "1.56.1", + "version": "1.57.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rudder-transformer", - "version": "1.56.1", + "version": "1.57.0", "license": "ISC", "dependencies": { "@amplitude/ua-parser-js": "0.7.24", diff --git a/package.json b/package.json index a1053c0496..f241515ffc 100644 --- a/package.json +++ b/package.json @@ -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": {