Files
medusa-store/packages/modules/providers/notification-local/src/services/local.ts
Stevche Radevski ee924b1b28 feat: Add a simple configurable notifications subscriber (#7331)
* feat: Add a simple configurable notifications subscriber that is configurable

* Proposal on awaiting all subscribers to run

* fix: Clean up wait subscribers util and notifications test

---------

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
2024-05-16 13:36:09 +02:00

49 lines
1.2 KiB
TypeScript

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 {}
}
}