chore: move notification processor filters to common package
Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-notifications-backend-module-email': patch
|
||||
'@backstage/plugin-notifications-common': patch
|
||||
'@backstage/plugin-notifications-node': patch
|
||||
---
|
||||
|
||||
Move notification processor filter parsing to common package
|
||||
+3
-27
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
import {
|
||||
NotificationProcessor,
|
||||
NotificationProcessorFilters,
|
||||
NotificationSendOptions,
|
||||
} from '@backstage/plugin-notifications-node';
|
||||
import {
|
||||
@@ -30,9 +29,9 @@ import {
|
||||
CatalogClient,
|
||||
} from '@backstage/catalog-client';
|
||||
import {
|
||||
getProcessorFiltersFromConfig,
|
||||
Notification,
|
||||
notificationSeverities,
|
||||
NotificationSeverity,
|
||||
NotificationProcessorFilters,
|
||||
} from '@backstage/plugin-notifications-common';
|
||||
import {
|
||||
createSendmailTransport,
|
||||
@@ -86,30 +85,7 @@ export class NotificationsEmailProcessor implements NotificationProcessor {
|
||||
? durationToMilliseconds(readDurationFromConfig(cacheConfig))
|
||||
: 3_600_000;
|
||||
this.frontendBaseUrl = config.getString('app.baseUrl');
|
||||
this.filter = {};
|
||||
const minSeverity = emailProcessorConfig.getOptionalString(
|
||||
'filter.minSeverity',
|
||||
) as NotificationSeverity;
|
||||
if (minSeverity) {
|
||||
if (notificationSeverities.includes(minSeverity)) {
|
||||
this.filter.minSeverity = minSeverity;
|
||||
} else {
|
||||
throw new Error(`Invalid minSeverity: ${minSeverity}`);
|
||||
}
|
||||
}
|
||||
const maxSeverity = emailProcessorConfig.getOptionalString(
|
||||
'filter.maxSeverity',
|
||||
) as NotificationSeverity;
|
||||
if (maxSeverity) {
|
||||
if (notificationSeverities.includes(maxSeverity)) {
|
||||
this.filter.maxSeverity = maxSeverity;
|
||||
} else {
|
||||
throw new Error(`Invalid maxSeverity: ${maxSeverity}`);
|
||||
}
|
||||
}
|
||||
this.filter.excludedTopics = emailProcessorConfig.getOptionalStringArray(
|
||||
'filter.excludedTopics',
|
||||
);
|
||||
this.filter = getProcessorFiltersFromConfig(emailProcessorConfig);
|
||||
}
|
||||
|
||||
private async getTransporter() {
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { Config } from '@backstage/config';
|
||||
|
||||
// @public (undocumented)
|
||||
export const getProcessorFiltersFromConfig: (
|
||||
config: Config,
|
||||
) => NotificationProcessorFilters;
|
||||
|
||||
// @public (undocumented)
|
||||
export type NewNotificationSignal = {
|
||||
action: 'new_notification';
|
||||
@@ -33,6 +40,13 @@ export type NotificationPayload = {
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export type NotificationProcessorFilters = {
|
||||
minSeverity?: NotificationSeverity;
|
||||
maxSeverity?: NotificationSeverity;
|
||||
excludedTopics?: string[];
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export type NotificationReadSignal = {
|
||||
action: 'notification_read' | 'notification_unread';
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"test": "backstage-cli package test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/config": "workspace:^",
|
||||
"@material-ui/icons": "^4.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Config } from '@backstage/config';
|
||||
import { NotificationProcessorFilters, NotificationSeverity } from './types';
|
||||
import { notificationSeverities } from './constants';
|
||||
|
||||
/** @public */
|
||||
export const getProcessorFiltersFromConfig = (config: Config) => {
|
||||
const filter: NotificationProcessorFilters = {};
|
||||
const minSeverity = config.getOptionalString(
|
||||
'filter.minSeverity',
|
||||
) as NotificationSeverity;
|
||||
if (minSeverity) {
|
||||
if (notificationSeverities.includes(minSeverity)) {
|
||||
filter.minSeverity = minSeverity;
|
||||
} else {
|
||||
throw new Error(`Invalid minSeverity: ${minSeverity}`);
|
||||
}
|
||||
}
|
||||
const maxSeverity = config.getOptionalString(
|
||||
'filter.maxSeverity',
|
||||
) as NotificationSeverity;
|
||||
if (maxSeverity) {
|
||||
if (notificationSeverities.includes(maxSeverity)) {
|
||||
filter.maxSeverity = maxSeverity;
|
||||
} else {
|
||||
throw new Error(`Invalid maxSeverity: ${maxSeverity}`);
|
||||
}
|
||||
}
|
||||
filter.excludedTopics = config.getOptionalStringArray(
|
||||
'filter.excludedTopics',
|
||||
);
|
||||
return filter;
|
||||
};
|
||||
@@ -22,3 +22,4 @@
|
||||
|
||||
export * from './types';
|
||||
export * from './constants';
|
||||
export * from './filters';
|
||||
|
||||
@@ -116,3 +116,12 @@ export type NotificationReadSignal = {
|
||||
|
||||
/** @public */
|
||||
export type NotificationSignal = NewNotificationSignal | NotificationReadSignal;
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type NotificationProcessorFilters = {
|
||||
minSeverity?: NotificationSeverity;
|
||||
maxSeverity?: NotificationSeverity;
|
||||
excludedTopics?: string[];
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { Notification as Notification_2 } from '@backstage/plugin-notifications-common';
|
||||
import { NotificationPayload } from '@backstage/plugin-notifications-common';
|
||||
import { NotificationSeverity } from '@backstage/plugin-notifications-common';
|
||||
import { NotificationProcessorFilters as NotificationProcessorFilters_2 } from '@backstage/plugin-notifications-common';
|
||||
import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @public (undocumented)
|
||||
@@ -38,12 +38,8 @@ export interface NotificationProcessor {
|
||||
): Promise<NotificationSendOptions>;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export type NotificationProcessorFilters = {
|
||||
minSeverity?: NotificationSeverity;
|
||||
maxSeverity?: NotificationSeverity;
|
||||
excludedTopics?: string[];
|
||||
};
|
||||
// @public @deprecated (undocumented)
|
||||
export type NotificationProcessorFilters = NotificationProcessorFilters_2;
|
||||
|
||||
// @public (undocumented)
|
||||
export type NotificationRecipients =
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
Notification,
|
||||
NotificationSeverity,
|
||||
NotificationProcessorFilters as NotificationProcessorFiltersCommon,
|
||||
} from '@backstage/plugin-notifications-common';
|
||||
import { NotificationSendOptions } from './service';
|
||||
|
||||
@@ -119,9 +119,6 @@ export const notificationsProcessingExtensionPoint =
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated Please import from `@backstage/plugin-notifications-common` instead
|
||||
*/
|
||||
export type NotificationProcessorFilters = {
|
||||
minSeverity?: NotificationSeverity;
|
||||
maxSeverity?: NotificationSeverity;
|
||||
excludedTopics?: string[];
|
||||
};
|
||||
export type NotificationProcessorFilters = NotificationProcessorFiltersCommon;
|
||||
|
||||
Reference in New Issue
Block a user