7.0 KiB
Class: NotificationService
Provides layer to manipulate orchestrate notifications.
Hierarchy
-
"medusa-interfaces"↳
NotificationService
Constructors
constructor
• new NotificationService(container)
Parameters
| Name | Type |
|---|---|
container |
any |
Overrides
BaseService.constructor
Defined in
Properties
attachmentGenerator_
• attachmentGenerator_: any
Defined in
container_
• container_: any
Defined in
logger_
• logger_: any
Defined in
notificationProviderRepository_
• notificationProviderRepository_: any
Defined in
subscribers_
• subscribers_: Object
Defined in
Methods
handleEvent
▸ handleEvent(eventName, data): Promise<any>
Handles an event by relaying the event data to the subscribing providers. The result of the notification send will be persisted in the database in order to allow for resends. Will log any errors that are encountered.
Parameters
| Name | Type | Description |
|---|---|---|
eventName |
string |
the event to handle |
data |
any |
the data the event was sent with |
Returns
Promise<any>
- the result of notification subscribed
Defined in
list
▸ list(selector, config?): Notification[]
Retrieves a list of notifications.
Parameters
| Name | Type | Description |
|---|---|---|
selector |
any |
the params to select the notifications by. |
config |
any |
the configuration to apply to the query |
Returns
Notification[]
the notifications that satisfy the query.
Defined in
registerAttachmentGenerator
▸ registerAttachmentGenerator(service): void
Registers an attachment generator to the service. The generator can be used to generate on demand invoices or other documents.
Parameters
| Name | Type |
|---|---|
service |
any |
Returns
void
Defined in
registerInstalledProviders
▸ registerInstalledProviders(providers): Promise<void>
Takes a list of notification provider ids and persists them in the database.
Parameters
| Name | Type | Description |
|---|---|---|
providers |
string[] |
a list of provider ids |
Returns
Promise<void>
Defined in
resend
▸ resend(id, config?): Notification
Resends a notification by retrieving a prior notification and calling the underlying provider's resendNotification method.
Parameters
| Name | Type | Description |
|---|---|---|
id |
string |
the id of the notification |
config |
any |
any configuration that might override the previous send |
Returns
Notification
the newly created notification
Defined in
retrieve
▸ retrieve(id, config?): Notification
Retrieves a notification with a given id
Parameters
| Name | Type | Description |
|---|---|---|
id |
string |
the id of the notification |
config |
any |
the configuration to apply to the query |
Returns
Notification
the notification
Defined in
retrieveProvider_
▸ retrieveProvider_(id): NotificationProvider
Finds a provider with a given id. Will throw a NOT_FOUND error if the resolution fails.
Parameters
| Name | Type | Description |
|---|---|---|
id |
string |
the id of the provider |
Returns
NotificationProvider
the notification provider
Defined in
send
▸ send(event, eventData, providerId): Notification
Sends a notification, by calling the given provider's sendNotification method. Persists the Notification in the database.
Parameters
| Name | Type | Description |
|---|---|---|
event |
string |
the name of the event |
eventData |
any |
the data the event was sent with |
providerId |
string |
the provider that should hande the event. |
Returns
Notification
the created notification
Defined in
subscribe
▸ subscribe(eventName, providerId): void
Subscribes a given provider to an event.
Parameters
| Name | Type | Description |
|---|---|---|
eventName |
string |
the event to subscribe to |
providerId |
string |
the provider that the event will be sent to |
Returns
void
Defined in
withTransaction
▸ withTransaction(transactionManager): NotificationService
Sets the service's manager to a given transaction manager.
Parameters
| Name | Type | Description |
|---|---|---|
transactionManager |
EntityManager |
the manager to use |
Returns
a cloned notification service