feat: notification processor improvements

Notification processor functions are now renamed to `preProcess` and `postProcess`.
Additionally, processor name is now required to be returned by `getName`.
A new processor functionality `processOptions` was added to process options before sending the notification.

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-04-08 08:15:13 +03:00
parent 0d60f65572
commit 0d99528300
6 changed files with 178 additions and 75 deletions
+12 -2
View File
@@ -22,8 +22,18 @@ export class DefaultNotificationService implements NotificationService {
// @public (undocumented)
export interface NotificationProcessor {
decorate?(notification: Notification_2): Promise<Notification_2>;
send?(notification: Notification_2): Promise<void>;
getName(): string;
postProcess?(
notification: Notification_2,
options: NotificationSendOptions,
): Promise<void>;
preProcess?(
notification: Notification_2,
options: NotificationSendOptions,
): Promise<Notification_2>;
processOptions?(
options: NotificationSendOptions,
): Promise<NotificationSendOptions>;
}
// @public (undocumented)
+40 -7
View File
@@ -15,25 +15,58 @@
*/
import { createExtensionPoint } from '@backstage/backend-plugin-api';
import { Notification } from '@backstage/plugin-notifications-common';
import { NotificationSendOptions } from './service';
/**
* @public
*/
export interface NotificationProcessor {
/**
* Decorate notification before sending it
*
* @param notification - The notification to decorate
* @returns The same notification or a modified version of it
* Human-readable name of this processor like Email, Slack, etc.
*/
decorate?(notification: Notification): Promise<Notification>;
getName(): string;
/**
* Send notification using this processor.
* Process the notification options.
*
* This can be used to modify the options before sending the notification or even sending the notification to
* external services. This function is called only once for each notification before processing it.
*
* @param options - The original options to send the notification
*/
processOptions?(
options: NotificationSendOptions,
): Promise<NotificationSendOptions>;
/**
* Pre-process notification before sending it to Backstage UI.
*
* Can be used to send the notification to external services or to decorate the notification with additional
* information. This function is called for each notification recipient individually or once for broadcast
* notification.
*
* @param notification - The notification to decorate
* @param options - The options to send the notification
* @returns The same notification or a modified version of it
*/
preProcess?(
notification: Notification,
options: NotificationSendOptions,
): Promise<Notification>;
/**
* Post process notification after sending it to Backstage UI.
*
* Can be used to send the notification to external services. This function is called for each notification
* recipient individually or once for broadcast notification.
*
* @param notification - The notification to send
* @param options - The options to send the notification
*/
send?(notification: Notification): Promise<void>;
postProcess?(
notification: Notification,
options: NotificationSendOptions,
): Promise<void>;
}
/**