feat: Add support for sendgrid and logger notification providers (#7290)

* feat: Add support for sendgrid and logger notification providers

* fix: changes based on PR review
This commit is contained in:
Stevche Radevski
2024-05-11 17:40:03 +02:00
committed by GitHub
parent 1a68f4602c
commit 79758c46b6
24 changed files with 631 additions and 1 deletions
@@ -0,0 +1,10 @@
import { ModuleProviderExports } from "@medusajs/types"
import { LocalNotificationService } from "./services/local"
const services = [LocalNotificationService]
const providerExport: ModuleProviderExports = {
services,
}
export default providerExport
@@ -0,0 +1,48 @@
import {
Logger,
NotificationTypes,
LocalNotificationServiceOptions,
} from "@medusajs/types"
import {
AbstractNotificationProviderService,
MedusaError,
} from "@medusajs/utils"
type InjectedDependencies = {
logger: Logger
}
interface LocalServiceConfig {}
export class LocalNotificationService extends AbstractNotificationProviderService {
protected config_: LocalServiceConfig
protected logger_: Logger
constructor(
{ logger }: InjectedDependencies,
options: LocalNotificationServiceOptions
) {
super()
this.config_ = options
this.logger_ = logger
}
async send(
notification: NotificationTypes.ProviderSendNotificationDTO
): Promise<NotificationTypes.ProviderSendNotificationResultsDTO> {
if (!notification) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`No notification information provided`
)
}
const message =
`Attempting to send a notification to: ${notification.to}` +
` on the channel: ${notification.channel} with template: ${notification.template}` +
` and data: ${JSON.stringify(notification.data)}`
this.logger_.info(message)
return {}
}
}