Skip to content

Commit

Permalink
Merge branch 'develop' into chore.add-latency-labels-endpoint-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip authored Dec 29, 2023
2 parents b690406 + 66a5390 commit aafddf8
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 81 deletions.
34 changes: 15 additions & 19 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

Write a brief explainer on your code changes.

## Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, **mandatorily** mention them here

### Type of change
## What is the related Linear task?

If the pull request is a **bug-fix**, **enhancement** or a **refactor**, please fill in the details on the changes made.
Resolves INT-XXX

- Existing capabilities/behavior

- New capabilities/behavior
## Please explain the objectives of your changes below

If the pull request is a **new feature**,
Put down any required details on the broader aspect of your changes. If there are any dependent changes, **mandatorily** mention them here

### Any technical or performance related pointers to consider with the change?
### Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Expand All @@ -28,25 +22,27 @@ N/A

N/A

### If the PR has changes in more than 10 files, please mention why the changes were not split into multiple PRs.

N/A

### If multiple linear tasks are associated with the PR changes, please elaborate on the reason:
### Any technical or performance related pointers to consider with the change?

N/A

<hr>

### Developer checklist

- [ ] My code follows the style guidelines of this project

- [ ] **No breaking changes are being introduced.**

- [ ] Are all related docs linked with the PR?
- [ ] All related docs linked with the PR?

- [ ] All changes manually tested?

- [ ] Any documentation changes needed with this change?

- [ ] Are all changes manually tested?
- [ ] Is the PR limited to 10 file changes?

- [ ] Does this change require any documentation changes?
- [ ] Is the PR limited to one linear task?

- [ ] Are relevant unit and component test-cases added?

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.16.0
18.19.0
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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.52.4](https://github.com/rudderlabs/rudder-transformer/compare/v1.52.3...v1.52.4) (2023-12-27)


### Bug Fixes

* send empty string instead of null when the schema data is undefined ([#2955](https://github.com/rudderlabs/rudder-transformer/issues/2955)) ([511741e](https://github.com/rudderlabs/rudder-transformer/commit/511741ed356b365f52e0335ce6a1fc953ccbc465))

### [1.52.3](https://github.com/rudderlabs/rudder-transformer/compare/v1.52.2...v1.52.3) (2023-12-18)


Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1.4
FROM node:18.17-alpine3.17 AS base
FROM node:18.19.0-alpine3.18 AS base
ENV HUSKY 0

RUN apk update
Expand Down
39 changes: 2 additions & 37 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.52.3",
"version": "1.52.4",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
11 changes: 10 additions & 1 deletion src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ const identifyBuilder = (message, destination, rawPayload) => {
}
});
}
// update identify call request with unset fields
// AM docs https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#keys-for-the-event-argument:~:text=exceed%2040%20layers.-,user_properties,-Optional.%20Object.%20A
const unsetObject = AMUtils.getUnsetObj(message);
if (unsetObject) {
// Example unsetObject = {
// "testObj.del1": "-"
// }
set(rawPayload, `user_properties.$unset`, unsetObject);
}
return rawPayload;
};

Expand Down Expand Up @@ -334,7 +343,7 @@ const getResponseData = (evType, destination, rawPayload, message, groupInfo) =>
case EventType.IDENTIFY:
// event_type for identify event is $identify
rawPayload.event_type = IDENTIFY_AM;
identifyBuilder(message, destination, rawPayload);
rawPayload = identifyBuilder(message, destination, rawPayload);
break;
case EventType.GROUP:
// event_type for identify event is $identify
Expand Down
66 changes: 66 additions & 0 deletions src/v0/destinations/am/util.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { getUnsetObj } = require('./utils');

describe('getUnsetObj', () => {
it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is not array", () => {
const message = {
integrations: {
Amplitude: { fieldsToUnset: 'field_name' },
},
};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});
it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is undefined", () => {
const message = {
integrations: {
Amplitude: {},
},
};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});

it("should return an empty objecty when 'message.integrations.Amplitude.fieldsToUnset' is an empty array", () => {
const message = {
integrations: {
Amplitude: { fieldsToUnset: [] },
},
};
const result = getUnsetObj(message);
expect(result).toEqual({});
});

it("should return an object with keys and values set to '-' when 'message.integrations.Amplitude.fieldsToUnset' is an array of strings", () => {
const message = {
integrations: {
Amplitude: { fieldsToUnset: ['Unset1', 'Unset2'] },
},
};
const result = getUnsetObj(message);
expect(result).toEqual({
Unset1: '-',
Unset2: '-',
});
});

it("should handle missing 'message' parameter", () => {
const result = getUnsetObj();
expect(result).toBeUndefined();
});

// Should handle missing 'integrations' property in 'message' parameter
it("should handle missing 'integrations' property in 'message' parameter", () => {
const message = {};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});

// Should handle missing 'Amplitude' property in 'message.integrations' parameter
it("should handle missing 'Amplitude' property in 'message.integrations' parameter", () => {
const message = {
integrations: {},
};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});
});
27 changes: 27 additions & 0 deletions src/v0/destinations/am/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ const getEventId = (payload, sourceKey) => {
return undefined;
};

/**
* generates the unsetObject and returns it
* @param {*} message
* @returns
*
* Example message = {
integrations: {
Amplitude: { fieldsToUnset: ['Unset1', 'Unset2'] },
All: true,
},
};
return unsetObj = {
"Unset1": "-",
"Unset2": "-"
}
AM docs: https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#keys-for-the-event-argument:~:text=exceed%2040%20layers.-,user_properties,-Optional.%20Object.%20A
*/
const getUnsetObj = (message) => {
const fieldsToUnset = get(message, 'integrations.Amplitude.fieldsToUnset');
let unsetObject;
if (Array.isArray(fieldsToUnset)) {
unsetObject = Object.fromEntries(fieldsToUnset.map((field) => [field, '-']));
}

return unsetObject;
};
module.exports = {
getOSName,
getOSVersion,
Expand All @@ -90,4 +116,5 @@ module.exports = {
getPlatform,
getBrand,
getEventId,
getUnsetObj,
};
10 changes: 5 additions & 5 deletions src/v0/destinations/fb_custom_audience/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,21 @@ const getUpdatedDataElement = (dataElement, isHashRequired, eachProperty, update
/**
* hash the original value for the properties apart from 'MADID' && 'EXTERN_ID as hashing is not required for them
* ref: https://developers.facebook.com/docs/marketing-api/audiences/guides/custom-audiences#hash
* sending null values for the properties for which user hasn't provided any value
* sending empty string for the properties for which user hasn't provided any value
*/
if (isHashRequired && eachProperty !== 'MADID' && eachProperty !== 'EXTERN_ID') {
if (tmpUpdatedProperty) {
tmpUpdatedProperty = `${tmpUpdatedProperty}`;
dataElement.push(sha256(tmpUpdatedProperty));
} else {
dataElement.push(null);
dataElement.push('');
}
}
// if property name is MADID or EXTERN_ID if the value is undefined send null
// if property name is MADID or EXTERN_ID if the value is undefined send empty string
else if (!tmpUpdatedProperty && (eachProperty === 'MADID' || eachProperty === 'EXTERN_ID')) {
dataElement.push(null);
dataElement.push('');
} else {
dataElement.push(tmpUpdatedProperty);
dataElement.push(tmpUpdatedProperty || '');
}
return dataElement;
};
Expand Down
14 changes: 11 additions & 3 deletions test/integrations/destinations/am/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ export const data = [
{
message: {
channel: 'web',
integrations: {
Amplitude: { fieldsToUnset: ['email'] },
All: true,
},
context: {
externalId: [
{
Expand Down Expand Up @@ -562,9 +566,6 @@ export const data = [
originalTimestamp: '2019-10-14T09:03:17.562Z',
anonymousId: '123456',
userId: '123456',
integrations: {
All: true,
},
sentAt: '2019-10-14T09:03:22.563Z',
},
metadata: {
Expand Down Expand Up @@ -616,6 +617,9 @@ export const data = [
insert_id: '84e26acc-56a5-4835-8233-591137fca468',
ip: '0.0.0.0',
user_properties: {
$unset: {
email: '-',
},
initial_referrer: 'https://docs.rudderstack.com',
initial_referring_domain: 'docs.rudderstack.com',
anonymousId: '123456',
Expand Down Expand Up @@ -743,6 +747,7 @@ export const data = [
anonymousId: '123456',
userId: '123456',
integrations: {
Amplitude: { fieldsToUnset: ['testObj.unsetField1'] },
All: true,
},
sentAt: '2019-10-14T09:03:22.563Z',
Expand Down Expand Up @@ -791,6 +796,9 @@ export const data = [
insert_id: '84e26acc-56a5-4835-8233-591137fca468',
ip: '0.0.0.0',
user_properties: {
$unset: {
'testObj.unsetField1': '-',
},
initial_referrer: 'https://docs.rudderstack.com',
initial_referring_domain: 'docs.rudderstack.com',
anonymousId: '123456',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ export const data = [
'a953f09a1b6b6725b81956e9ad0b1eb49e3ad40004c04307ef8af6246a054116',
'3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278',
'7931aa2a1bed855457d1ddf6bc06ab4406a9fba0579045a4d6ff78f9c07c440f',
null,
'',
'252f10c83610ebca1a059c0bae8255eba2f95be4d1d7bcfa89d7248a82d9f111',
'db0683221aebc02cc034b65ebcf7d1bddd1eb199e33fd23a31931947d13a11bc',
'abc',
Expand Down Expand Up @@ -2123,7 +2123,7 @@ export const data = [
'ST',
'COUNTRY',
],
data: [[null, null, null, null, null, null, null, null, null, null, null]],
data: [['', '', '', '', '', '', '', '', '', '', '']],
},
},
body: {
Expand Down Expand Up @@ -2256,7 +2256,7 @@ export const data = [
'a953f09a1b6b6725b81956e9ad0b1eb49e3ad40004c04307ef8af6246a054116',
'3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278',
'7931aa2a1bed855457d1ddf6bc06ab4406a9fba0579045a4d6ff78f9c07c440f',
null,
'',
'252f10c83610ebca1a059c0bae8255eba2f95be4d1d7bcfa89d7248a82d9f111',
'db0683221aebc02cc034b65ebcf7d1bddd1eb199e33fd23a31931947d13a11bc',
'abc',
Expand Down
Loading

0 comments on commit aafddf8

Please sign in to comment.