Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// as the notification object is retrieved from database (?)
return left(
TransientError(
`Notification not found|notification=${notificationId}|message=${
message.id
}`
)
);
}
const errorOrEmailNotification = EmailNotification.decode(
maybeEmailNotification.value
);
if (isLeft(errorOrEmailNotification)) {
const error = readableReport(errorOrEmailNotification.value);
return left(
PermanentError(
`Wrong format for email notification|notification=${notificationId}|message=${
message.id
}|${error}`
)
);
}
const emailNotification = errorOrEmailNotification.value.channels.EMAIL;
const documentHtml = await generateDocumentHtml(
content.subject,
content.markdown,
senderMetadata
);
serviceVersion: userAttributes.service.version
})
);
if (isLeft(createdMessageEventOrError)) {
winston.error(
`CreateMessageHandler|Unable to decode CreatedMessageEvent|${
userService.serviceId
}|${retrievedMessage.id}|${readableReport(
createdMessageEventOrError.value
).replace(/\n/g, " / ")}`
);
return ResponseErrorValidation(
"Unable to decode CreatedMessageEvent",
readableReport(createdMessageEventOrError.value)
);
}
// queue the message to the created messages queue by setting
// the message to the output binding of this function
// tslint:disable-next-line:no-object-mutation
context.bindings.createdMessage = createdMessageEventOrError.value;
//
// generate appinsights event
//
// track the event that a message has been created
appInsightsClient.trackEvent({
measurements: {
duration: diffInMilliseconds(startRequestTime)
winston.debug(
`EmailNotificationsHandlerIndex|Dequeued email notification|${JSON.stringify(
context.bindings
)}`
);
// since this function gets triggered by a queued message that gets
// deserialized from a json object, we must first check that what we
// got is what we expect.
const errorOrNotificationEvent = NotificationEvent.decode(
context.bindings.notificationEvent
);
if (isLeft(errorOrNotificationEvent)) {
winston.error(
`EmailNotificationsHandler|Fatal! No valid message found in bindings.|${readableReport(
errorOrNotificationEvent.value
)}`
);
return stopProcessing;
}
const emailNotificationEvent = errorOrNotificationEvent.value;
const notificationStatusUpdater = getNotificationStatusUpdater(
notificationStatusModel,
NotificationChannelEnum.EMAIL,
emailNotificationEvent.message.id,
emailNotificationEvent.notificationId
);
winston.debug(`useSendgridTransport:${useSendgridTransport}`);
// as the notification object is retrieved from database (?)
return left(
TransientError(
`Notification not found|notification=${notificationId}|message=${
message.id
}`
)
);
}
const errorOrWebhookNotification = WebhookNotification.decode(
maybeWebhookNotification.value
);
if (isLeft(errorOrWebhookNotification)) {
const error = readableReport(errorOrWebhookNotification.value);
return left(
PermanentError(
`Wrong format for webhook notification|notification=${notificationId}|message=${
message.id
}|${error}`
)
);
}
const webhookNotification = errorOrWebhookNotification.value.channels.WEBHOOK;
const startWebhookCallTime = process.hrtime();
const sendResult = await sendToWebhook(
webhookNotification.url,
message,
winston.debug(
`WebhookNotificationsHandlerIndex|Dequeued webhook notification|${JSON.stringify(
context.bindings
)}`
);
// since this function gets triggered by a queued message that gets
// deserialized from a json object, we must first check that what we
// got is what we expect.
const errorOrNotificationEvent = NotificationEvent.decode(
context.bindings.notificationEvent
);
if (isLeft(errorOrNotificationEvent)) {
winston.error(
`WebhookNotificationsHandler|Fatal! No valid message found in bindings.|${readableReport(
errorOrNotificationEvent.value
)}`
);
return;
}
const webhookNotificationEvent = errorOrNotificationEvent.value;
const notificationStatusUpdater = getNotificationStatusUpdater(
notificationStatusModel,
NotificationChannelEnum.WEBHOOK,
webhookNotificationEvent.message.id,
webhookNotificationEvent.notificationId
);
const serviceId = webhookNotificationEvent.message.senderServiceId;
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|${
userService.serviceId
}|${retrievedMessage.id}|${readableReport(
createdMessageEventOrError.value
).replace(/\n/g, " / ")}`
);
return ResponseErrorValidation(
"Unable to decode CreatedMessageEvent",
readableReport(createdMessageEventOrError.value)
);
}
// queue the message to the created messages queue by setting
// the message to the output binding of this function
// tslint:disable-next-line:no-object-mutation
context.bindings.createdMessage = createdMessageEventOrError.value;
//
type.decode(parsedJson).mapLeft(errs => new Error(readableReport(errs)))
)
}).getOrElseL(errs => {
throw new Error(
"Invalid MessageContent for welcome message: " + readableReport(errs)
);
}),
(_: ExtendedProfile) =>
return RetrievedMessage.decode(result).getOrElseL(errs => {
throw new Error(
"Retrieved result wasn't a RetrievedMessage: " + readableReport(errs)
);
});
}