-
Notifications
You must be signed in to change notification settings - Fork 103
/
utils.js
24 lines (20 loc) · 840 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 };