|
1
|
import { |
|
2
|
LocalNotificationServiceOptions, |
|
3
|
Logger, |
|
4
|
NotificationTypes, |
|
5
|
} from "@medusajs/framework/types" |
|
6
|
import { |
|
7
|
AbstractNotificationProviderService, |
|
8
|
MedusaError, |
|
9
|
} from "@medusajs/framework/utils" |
|
10
|
|
|
11
|
type InjectedDependencies = { |
|
12
|
logger: Logger |
|
13
|
} |
|
14
|
|
|
15
|
interface LocalServiceConfig {} |
|
16
|
|
|
17
|
export class LocalNotificationService extends AbstractNotificationProviderService { |
|
18
|
static identifier = "notification-local" |
|
19
|
protected config_: LocalServiceConfig |
|
20
|
protected logger_: Logger |
|
21
|
|
|
22
|
constructor( |
|
23
|
{ logger }: InjectedDependencies, |
|
24
|
options: LocalNotificationServiceOptions |
|
25
|
) { |
|
26
|
super() |
|
27
|
this.config_ = options |
|
28
|
this.logger_ = logger |
|
29
|
} |
|
30
|
|
|
31
|
async send( |
|
32
|
notification: NotificationTypes.ProviderSendNotificationDTO |
|
33
|
): Promise<NotificationTypes.ProviderSendNotificationResultsDTO> { |
|
34
|
if (!notification) { |
|
35
|
throw new MedusaError( |
|
36
|
MedusaError.Types.INVALID_DATA, |
|
37
|
`No notification information provided` |
|
38
|
) |
|
39
|
} |
|
40
|
|
|
41
|
const message = |
|
42
|
`Attempting to send a notification to: '${notification.to}'` + |
|
43
|
` on the channel: '${notification.channel}' with template: '${notification.template}'` + |
|
44
|
` and data: '${JSON.stringify(notification.data)}'` |
|
45
|
|
|
46
|
this.logger_.info(message) |
|
47
|
return {} |
|
48
|
} |
|
49
|
} |