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:
@@ -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 {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user