Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const notificationEvent = errorOrNotificationEvent.value;
// output notification events (one for each channel)
const outputBindings: OutputBindings = {
emailNotification: maybeAllowedEmailNotification
.map(() => notificationEvent)
.toUndefined(),
webhookNotification: maybeAllowedWebhookNotification
.map(() => notificationEvent)
.toUndefined()
};
// avoid to enqueue messages for non existing notifications
return right(
withoutUndefinedValues(outputBindings)
);
}
`handleMessage|No channels configured for the user ${
newMessageWithoutContent.fiscalCode
} and no default address provided`
);
// return no notifications
return right({});
}
// create and save notification object
const newNotification: NewNotification = {
...createNewNotification(
ulidGenerator,
newMessageWithoutContent.fiscalCode,
newMessageWithoutContent.id
),
channels: withoutUndefinedValues({
[NotificationChannelEnum.EMAIL]: maybeAllowedEmailNotification.toUndefined(),
[NotificationChannelEnum.WEBHOOK]: maybeAllowedWebhookNotification.toUndefined()
})
};
const errorOrNotificationEvent = await createNotification(
lNotificationModel,
senderMetadata,
newMessageWithoutContent,
createdMessageEvent.content,
newNotification
);
if (isLeft(errorOrNotificationEvent)) {
return left(errorOrNotificationEvent.value);
}
winston.debug(
`CreateMessageHandler|message created|${userService.serviceId}|${
retrievedMessage.id
}`
);
//
// emit created message event to the output queue
//
// prepare the created message event
// we filter out undefined values as they are
// deserialized to null(s) when enqueued
const createdMessageEventOrError = CreatedMessageEvent.decode(
withoutUndefinedValues({
content: messagePayload.content,
defaultAddresses: messagePayload.default_addresses,
message: newMessageWithoutContent,
senderMetadata: {
departmentName: userAttributes.service.departmentName,
organizationFiscalCode: userAttributes.service.organizationFiscalCode,
organizationName: userAttributes.service.organizationName,
serviceName: userAttributes.service.serviceName
},
serviceVersion: userAttributes.service.version
})
);
if (isLeft(createdMessageEventOrError)) {
winston.error(
`CreateMessageHandler|Unable to decode CreatedMessageEvent|${
);
if (isLeft(errorOrMaybeContent)) {
winston.error(
`GetMessageHandler|${JSON.stringify(errorOrMaybeContent.value)}`
);
return ResponseErrorInternal(
`${errorOrMaybeContent.value.name}: ${
errorOrMaybeContent.value.message
}`
);
}
const message:
| CreatedMessageWithContent
| CreatedMessageWithoutContent = withoutUndefinedValues({
content: errorOrMaybeContent.value.toUndefined(),
...retrievedMessageToPublic(retrievedMessage)
});
const errorOrNotificationStatuses = await getMessageNotificationStatuses(
notificationModel,
notificationStatusModel,
retrievedMessage.id
);
if (isLeft(errorOrNotificationStatuses)) {
return ResponseErrorInternal(
`Error retrieving NotificationStatus: ${
errorOrNotificationStatuses.value.name
}|${errorOrNotificationStatuses.value.message}`
);