Fix isEventTypeLoggingEnabled bug where empty string matches eventTypeId 0 (#24804)

When BOOKING_LOGGING_EVENT_IDS is set to an empty string, the current
implementation splits it into [''] and Number('') returns 0, causing
any event type with ID 0 to incorrectly trigger debug logging.

This fix:
- Filters out empty/invalid event IDs (NaN, <=0)
- Filters out empty usernames
- Only matches valid, positive event type IDs

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Alex van Andel
2025-10-30 19:32:17 +00:00
committed by GitHub
co-authored by Devin AI
parent 3c1dfe8b74
commit 2efcfab715
@@ -9,11 +9,12 @@ export function isEventTypeLoggingEnabled({
usernameOrTeamName instanceof Array ? usernameOrTeamName : [usernameOrTeamName];
// eslint-disable-next-line turbo/no-undeclared-env-vars
const bookingLoggingEventIds = process.env.BOOKING_LOGGING_EVENT_IDS || "";
const isEnabled = bookingLoggingEventIds.split(",").some((id) => {
if (Number(id.trim()) === eventTypeId) {
return true;
}
});
const validEventIds = bookingLoggingEventIds
.split(",")
.map((id) => Number(id.trim()))
.filter((id) => !isNaN(id) && id > 0);
const isEnabled = eventTypeId && validEventIds.includes(eventTypeId);
if (isEnabled) {
return true;
@@ -21,7 +22,12 @@ export function isEventTypeLoggingEnabled({
// eslint-disable-next-line turbo/no-undeclared-env-vars
const bookingLoggingUsername = process.env.BOOKING_LOGGING_USER_OR_TEAM_NAME || "";
return bookingLoggingUsername.split(",").some((u) => {
return usernameOrTeamnamesList.some((foundUsername) => foundUsername === u.trim());
const validUsernames = bookingLoggingUsername
.split(",")
.map((u) => u.trim())
.filter((u) => u.length > 0);
return validUsernames.some((username) => {
return usernameOrTeamnamesList.some((foundUsername) => foundUsername === username);
});
}