Move database function to backend
Signed-off-by: Billy Stalnaker <bstalnaker@roadie.com>
This commit is contained in:
@@ -24,13 +24,13 @@ import {
|
||||
TopicGetOptions,
|
||||
} from './NotificationsStore';
|
||||
import {
|
||||
generateSettingsHash,
|
||||
Notification,
|
||||
NotificationSettings,
|
||||
notificationSeverities,
|
||||
NotificationSeverity,
|
||||
} from '@backstage/plugin-notifications-common';
|
||||
import { Knex } from 'knex';
|
||||
import crypto from 'crypto';
|
||||
|
||||
const migrationsDir = resolvePackagePath(
|
||||
'@backstage/plugin-notifications-backend',
|
||||
@@ -106,6 +106,16 @@ export const normalizeSeverity = (input?: string): NotificationSeverity => {
|
||||
return lower;
|
||||
};
|
||||
|
||||
export const generateSettingsHash = (
|
||||
user: string,
|
||||
channel: string,
|
||||
origin: string,
|
||||
topic: string | null,
|
||||
): string => {
|
||||
const rawKey = `${user}|${channel}|${origin}|${topic ?? ''}`;
|
||||
return crypto.createHash('sha256').update(rawKey).digest('hex');
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export class DatabaseNotificationsStore implements NotificationsStore {
|
||||
private readonly isSQLite = false;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { NotificationSettings } from './types';
|
||||
import crypto from 'crypto';
|
||||
|
||||
/** @public */
|
||||
export const isNotificationsEnabledFor = (
|
||||
@@ -41,14 +40,3 @@ export const isNotificationsEnabledFor = (
|
||||
}
|
||||
return topic.enabled;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export const generateSettingsHash = (
|
||||
user: string,
|
||||
channel: string,
|
||||
origin: string,
|
||||
topic: string | null,
|
||||
): string => {
|
||||
const rawKey = `${user}|${channel}|${origin}|${topic ?? ''}`;
|
||||
return crypto.createHash('sha256').update(rawKey).digest('hex');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user