Skip to content

Commit

Permalink
chore(release): pull hotfix-release/v1.57.1 into main (#3160)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip authored Mar 4, 2024
2 parents 1dbde7a + 302cbe8 commit 7463891
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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.1](https://github.com/rudderlabs/rudder-transformer/compare/v1.57.0...v1.57.1) (2024-03-04)


### Bug Fixes

* amplitude fix for user operations ([7f2364e](https://github.com/rudderlabs/rudder-transformer/commit/7f2364e41167611c41003559de65cee1fece5464))
* amplitude fix for user operations ([#3153](https://github.com/rudderlabs/rudder-transformer/issues/3153)) ([31869fb](https://github.com/rudderlabs/rudder-transformer/commit/31869fb114bb141d545de01c56f57b97e5aa54a6))

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


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.57.0",
"version": "1.57.1",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
13 changes: 11 additions & 2 deletions src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const updateConfigProperty = (message, payload, mappingJson, validatePayload, Co
}
});
};
const identifyBuilder = (message, destination, rawPayload) => {
const userPropertiesHandler = (message, destination, rawPayload) => {
// update payload user_properties from userProperties/traits/context.traits/nested traits of Rudder message
// traits like address converted to top level user properties (think we can skip this extra processing as AM supports nesting upto 40 levels)
let traits = getFieldValueFromMessage(message, 'traits');
Expand Down Expand Up @@ -335,14 +335,16 @@ const getDefaultResponseData = (message, rawPayload, evType, groupInfo) => {
const groups = groupInfo && cloneDeep(groupInfo);
return { groups, rawPayload };
};


const getResponseData = (evType, destination, rawPayload, message, groupInfo) => {
let groups;

switch (evType) {
case EventType.IDENTIFY:
// event_type for identify event is $identify
rawPayload.event_type = IDENTIFY_AM;
rawPayload = identifyBuilder(message, destination, rawPayload);
rawPayload = userPropertiesHandler(message, destination, rawPayload);
break;
case EventType.GROUP:
// event_type for identify event is $identify
Expand All @@ -357,8 +359,15 @@ const getResponseData = (evType, destination, rawPayload, message, groupInfo) =>
case EventType.ALIAS:
break;
default:
if (destination.Config.enableEnhancedUserOperations) {
// handle all other events like track, page, screen for user properties
rawPayload = userPropertiesHandler(message, destination, rawPayload);

Check warning on line 364 in src/v0/destinations/am/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/transform.js#L364

Added line #L364 was not covered by tests
}
({ groups, rawPayload } = getDefaultResponseData(message, rawPayload, evType, groupInfo));
}
if (destination.Config.enableEnhancedUserOperations) {
rawPayload = AMUtils.userPropertiesPostProcess(rawPayload);

Check warning on line 369 in src/v0/destinations/am/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/transform.js#L369

Added line #L369 was not covered by tests
}
return { rawPayload, groups };
};

Expand Down
69 changes: 68 additions & 1 deletion src/v0/destinations/am/util.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getUnsetObj, validateEventType } = require('./utils');
const { getUnsetObj, validateEventType, userPropertiesPostProcess } = require('./utils');

describe('getUnsetObj', () => {
it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is not array", () => {
Expand Down Expand Up @@ -97,3 +97,70 @@ describe('validateEventType', () => {
);
});
});

describe('userPropertiesPostProcess', () => {
// The function correctly removes duplicate keys found in both operation keys and root level keys.
it('should remove duplicate keys from user_properties', () => {
// Arrange
const rawPayload = {
user_properties: {
$setOnce: {
key1: 'value1',
},
$add: {
key2: 'value2',
},
key3: 'value3',
key1: 'value4',
},
};

// Act
const result = userPropertiesPostProcess(rawPayload);

// Assert
expect(result.user_properties).toEqual({
$setOnce: {
key1: 'value1',
},
$add: {
key2: 'value2',
},
$set: {
key3: 'value3',
},
});
});

// The function correctly moves root level properties to $set operation.
it('should move root level properties to $set operation when they dont belong to any other operation', () => {
// Arrange
const rawPayload = {
user_properties: {
$setOnce: {
key1: 'value1',
},
$add: {
key2: 'value2',
},
key3: 'value3',
},
};

// Act
const result = userPropertiesPostProcess(rawPayload);

// Assert
expect(result.user_properties).toEqual({
$set: {
key3: 'value3',
},
$setOnce: {
key1: 'value1',
},
$add: {
key2: 'value2',
},
});
});
});
56 changes: 56 additions & 0 deletions src/v0/destinations/am/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,61 @@ const validateEventType = (evType) => {
);
}
};


const userPropertiesPostProcess = (rawPayload) => {
const operationList = [

Check warning on line 128 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L128

Added line #L128 was not covered by tests
'$setOnce',
'$add',
'$unset',
'$append',
'$prepend',
'$preInsert',
'$postInsert',
'$remove',
];
// eslint-disable-next-line @typescript-eslint/naming-convention
const { user_properties } = rawPayload;
const userPropertiesKeys = Object.keys(user_properties).filter(
(key) => !operationList.includes(key),

Check warning on line 141 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L139-L141

Added lines #L139 - L141 were not covered by tests
);
const duplicatekeys = new Set();

Check warning on line 143 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L143

Added line #L143 was not covered by tests
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const key of userPropertiesKeys) {

Check warning on line 145 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L145

Added line #L145 was not covered by tests
// check if any of the keys are present in the user_properties $setOnce, $add, $unset, $append, $prepend, $preInsert, $postInsert, $remove keys as well as root level

if (
operationList.some(
(operation) => user_properties[operation] && user_properties[operation][key],
)
) {
duplicatekeys.add(key);

Check warning on line 153 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L153

Added line #L153 was not covered by tests
}
}
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const key of duplicatekeys) {
delete user_properties[key];

Check warning on line 158 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L157-L158

Added lines #L157 - L158 were not covered by tests
}

// Moving root level properties that doesn't belong to any operation under $set
const setProps = {};

Check warning on line 162 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L162

Added line #L162 was not covered by tests
// eslint-disable-next-line no-restricted-syntax
for (const [key, value] of Object.entries(user_properties)) {

Check warning on line 164 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L164

Added line #L164 was not covered by tests
if (!operationList.includes(key)) {
setProps[key] = value;
delete user_properties[key];

Check warning on line 167 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L166-L167

Added lines #L166 - L167 were not covered by tests
}
}

if (Object.keys(setProps).length > 0) {
user_properties.$set = setProps;

Check warning on line 172 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L172

Added line #L172 was not covered by tests
}

// eslint-disable-next-line no-param-reassign
rawPayload.user_properties = user_properties;
return rawPayload;

Check warning on line 177 in src/v0/destinations/am/utils.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/am/utils.js#L176-L177

Added lines #L176 - L177 were not covered by tests
};

module.exports = {
getOSName,
getOSVersion,
Expand All @@ -132,4 +187,5 @@ module.exports = {
getEventId,
getUnsetObj,
validateEventType,
userPropertiesPostProcess
};

0 comments on commit 7463891

Please sign in to comment.