diff --git a/src/services/userTransform.ts b/src/services/userTransform.ts index d54c105b02..5104418f6d 100644 --- a/src/services/userTransform.ts +++ b/src/services/userTransform.ts @@ -7,6 +7,7 @@ import { ProcessorTransformationResponse, UserTransformationResponse, UserTransformationServiceResponse, + MessageIdMetadataMap, } from '../types/index'; import { RespStatusError, @@ -49,8 +50,15 @@ export default class UserTransformService { const eventsToProcess = destEvents as ProcessorTransformationRequest[]; const transformationVersionId = eventsToProcess[0]?.destination?.Transformations[0]?.VersionID; - const messageIds = eventsToProcess.map((ev) => ev.metadata?.messageId); - const messageIdsSet = new Set(messageIds); + const messageIds: string[] = []; + const messageIdsSet = new Set(); + const messageIdMetadataMap: MessageIdMetadataMap = {}; + eventsToProcess.forEach((ev) => { + messageIds.push(ev.metadata?.messageId); + messageIdsSet.add(ev.metadata?.messageId); + messageIdMetadataMap[ev.metadata?.messageId] = ev.metadata; + }); + const messageIdsInOutputSet = new Set(); const commonMetadata = { @@ -125,7 +133,7 @@ export default class UserTransformService { const droppedEvents = messageIdsNotInOutput.map((id) => ({ statusCode: HTTP_CUSTOM_STATUS_CODES.FILTERED, metadata: { - ...commonMetadata, + ...(isEmpty(messageIdMetadataMap[id]) ? commonMetadata : messageIdMetadataMap[id]), messageId: id, messageIds: null, }, diff --git a/src/types/index.ts b/src/types/index.ts index ff0c1f88b9..5a35b697d6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -52,6 +52,10 @@ type Metadata = { transformationId: string; }; +type MessageIdMetadataMap = { + [key: string]: Metadata; +}; + type UserTransformationInput = { VersionID: string; ID: string; @@ -223,6 +227,7 @@ type ComparatorInput = { export { Metadata, + MessageIdMetadataMap, UserTransformationLibrary, ProcessorTransformationRequest, ProcessorTransformationResponse,