Skip to main content

Class: NotificationService

Provides layer to manipulate orchestrate notifications.

Hierarchy

  • "medusa-interfaces"

    NotificationService

Constructors

constructor

new NotificationService(container)

Parameters

NameType
containerany

Overrides

BaseService.constructor

Defined in

services/notification.js:9

Properties

attachmentGenerator_

attachmentGenerator_: any

Defined in

services/notification.js:30


container_

container_: any

Defined in

services/notification.js:19


logger_

logger_: any

Defined in

services/notification.js:23


notificationProviderRepository_

notificationProviderRepository_: any

Defined in

services/notification.js:27


subscribers_

subscribers_: Object

Defined in

services/notification.js:29

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

NameTypeDescription
eventNamestringthe event to handle
dataanythe data the event was sent with

Returns

Promise<any>

  • the result of notification subscribed

Defined in

services/notification.js:166


list

list(selector, config?): Notification[]

Retrieves a list of notifications.

Parameters

NameTypeDescription
selectoranythe params to select the notifications by.
configanythe configuration to apply to the query

Returns

Notification[]

the notifications that satisfy the query.

Defined in

services/notification.js:84


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

NameType
serviceany

Returns

void

Defined in

services/notification.js:38


registerInstalledProviders

registerInstalledProviders(providers): Promise<void>

Takes a list of notification provider ids and persists them in the database.

Parameters

NameTypeDescription
providersstring[]a list of provider ids

Returns

Promise<void>

Defined in

services/notification.js:68


resend

resend(id, config?): Notification

Resends a notification by retrieving a prior notification and calling the underlying provider's resendNotification method.

Parameters

NameTypeDescription
idstringthe id of the notification
configanyany configuration that might override the previous send

Returns

Notification

the newly created notification

Defined in

services/notification.js:237


retrieve

retrieve(id, config?): Notification

Retrieves a notification with a given id

Parameters

NameTypeDescription
idstringthe id of the notification
configanythe configuration to apply to the query

Returns

Notification

the notification

Defined in

services/notification.js:101


retrieveProvider_

retrieveProvider_(id): NotificationProvider

Finds a provider with a given id. Will throw a NOT_FOUND error if the resolution fails.

Parameters

NameTypeDescription
idstringthe id of the provider

Returns

NotificationProvider

the notification provider

Defined in

services/notification.js:147


send

send(event, eventData, providerId): Notification

Sends a notification, by calling the given provider's sendNotification method. Persists the Notification in the database.

Parameters

NameTypeDescription
eventstringthe name of the event
eventDataanythe data the event was sent with
providerIdstringthe provider that should hande the event.

Returns

Notification

the created notification

Defined in

services/notification.js:195


subscribe

subscribe(eventName, providerId): void

Subscribes a given provider to an event.

Parameters

NameTypeDescription
eventNamestringthe event to subscribe to
providerIdstringthe provider that the event will be sent to

Returns

void

Defined in

services/notification.js:126


withTransaction

withTransaction(transactionManager): NotificationService

Sets the service's manager to a given transaction manager.

Parameters

NameTypeDescription
transactionManagerEntityManagerthe manager to use

Returns

NotificationService

a cloned notification service

Defined in

services/notification.js:47