chore: move notification processor filters to common package
Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -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[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user