Skip to content

Commit a6a5f2a

Browse files
committed
Removes hardcoded event blocking logic
Introduces dynamic location-based blacklist parsing using environment variables. This replaces hardcoded blocking logic, allowing greater flexibility and configurability for event handling.
1 parent a83b8bd commit a6a5f2a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/util/oncehub-custom-transformer.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
const { EventType } = require('../constants');
22

3+
const getLocationWiseBlacklist = () => {
4+
try {
5+
return JSON.parse(process.env.BLOCKED_EVENTS_DESTINATIONS || '{}');
6+
} catch (error) {
7+
console.error('Error parsing BLOCKED_EVENTS_DESTINATIONS:', error);
8+
return {};
9+
}
10+
};
11+
312
const getPIIDestinationList = () => {
413
return (process.env.WHITELIST_PII_DESTINATION || 'customerio').trim().split(',');
514
};
@@ -63,8 +72,12 @@ const oncehubTransformer = (destination, event) => {
6372
// eslint-disable-next-line no-param-reassign
6473
return null;
6574
}
66-
67-
if (event.message.type === EventType.TRACK && event.message.event === 'Email sent to guest' && destination === "mp") {
75+
// Check if event should be blocked based on location-wise blacklist
76+
const blacklist = getLocationWiseBlacklist();
77+
if (
78+
event.message.type === EventType.TRACK &&
79+
blacklist[destination]?.includes(event.message.event)
80+
) {
6881
// eslint-disable-next-line no-param-reassign
6982
return null;
7083
}
@@ -105,7 +118,7 @@ const oncehubTransformer = (destination, event) => {
105118

106119
// eslint-disable-next-line no-console
107120
// if(doesEventContainsTraits(event)) console.log("event log=>destination : ", JSON.stringify(destination), " , ==> event traits : ", JSON.stringify(event.message.traits), " , ==> event here : ",JSON.stringify(event));
108-
121+
109122
return event;
110123
};
111124

0 commit comments

Comments
 (0)