@backstage/plugin-notifications-backend 0.5.8 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/database/DatabaseNotificationsStore.cjs.js.map +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/service/NotificationCleaner.cjs.js.map +1 -1
- package/dist/service/getUsersForEntityRef.cjs.js.map +1 -1
- package/dist/service/parseEntityOrderFieldParams.cjs.js.map +1 -1
- package/dist/service/router.cjs.js.map +1 -1
- package/package.json +15 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @backstage/plugin-notifications-backend
|
|
2
2
|
|
|
3
|
+
## 0.5.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9152ba8: Add an optional generic object `metadata` field to `NotificationPayload`. Metadata can be used to store additional unstructured data for the notification and are available to use by processors.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-catalog-node@1.18.0
|
|
10
|
+
- @backstage/plugin-notifications-common@0.1.0
|
|
11
|
+
- @backstage/plugin-auth-node@0.6.6
|
|
12
|
+
- @backstage/plugin-notifications-node@0.2.18
|
|
13
|
+
- @backstage/backend-plugin-api@1.4.2
|
|
14
|
+
- @backstage/plugin-events-node@0.4.14
|
|
15
|
+
- @backstage/plugin-signals-node@0.1.23
|
|
16
|
+
|
|
17
|
+
## 0.5.9-next.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @backstage/plugin-catalog-node@1.18.0-next.0
|
|
23
|
+
- @backstage/plugin-auth-node@0.6.6-next.0
|
|
24
|
+
- @backstage/plugin-notifications-node@0.2.18-next.0
|
|
25
|
+
- @backstage/backend-plugin-api@1.4.2-next.0
|
|
26
|
+
- @backstage/plugin-events-node@0.4.14-next.0
|
|
27
|
+
- @backstage/catalog-model@1.7.5
|
|
28
|
+
- @backstage/config@1.3.3
|
|
29
|
+
- @backstage/errors@1.2.7
|
|
30
|
+
- @backstage/types@1.2.1
|
|
31
|
+
- @backstage/plugin-notifications-common@0.0.10
|
|
32
|
+
- @backstage/plugin-signals-node@0.1.23-next.0
|
|
33
|
+
|
|
3
34
|
## 0.5.8
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseNotificationsStore.cjs.js","sources":["../../src/database/DatabaseNotificationsStore.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n DatabaseService,\n resolvePackagePath,\n} from '@backstage/backend-plugin-api';\nimport {\n NotificationGetOptions,\n NotificationModifyOptions,\n NotificationsStore,\n TopicGetOptions,\n} from './NotificationsStore';\nimport {\n Notification,\n NotificationSettings,\n notificationSeverities,\n NotificationSeverity,\n} from '@backstage/plugin-notifications-common';\nimport { Knex } from 'knex';\nimport crypto from 'crypto';\nimport { durationToMilliseconds, HumanDuration } from '@backstage/types';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-notifications-backend',\n 'migrations',\n);\n\nconst NOTIFICATION_COLUMNS = [\n 'id',\n 'title',\n 'description',\n 'severity',\n 'link',\n 'origin',\n 'scope',\n 'topic',\n 'icon',\n 'created',\n 'updated',\n 'user',\n 'read',\n 'saved',\n];\n\ntype NotificationRowType = {\n id: string;\n user: string;\n title: string;\n description?: string | null;\n severity: string;\n link: string | null;\n origin: string;\n scope: string | null;\n topic: string | null;\n created: Date;\n updated: Date | null;\n read: Date | null;\n saved: Date | null;\n icon: string | null;\n};\n\ntype BroadcastRowType = {\n id: string;\n title: string;\n description: string | null;\n link: string | null;\n origin: string;\n scope: string | null;\n topic: string | null;\n created: Date;\n updated: Date | null;\n icon: string | null;\n};\n\ntype BroadcastUserStatusRowType = {\n broadcast_id: string;\n user: string;\n read: Date | null;\n saved: Date | null;\n};\n\ntype UserSettingsRowType = {\n user: string;\n channel: string;\n origin: string;\n enabled: boolean;\n};\n\nexport const normalizeSeverity = (input?: string): NotificationSeverity => {\n let lower = (input ?? 'normal').toLowerCase() as NotificationSeverity;\n if (notificationSeverities.indexOf(lower) < 0) {\n lower = 'normal';\n }\n return lower;\n};\n\nexport const generateSettingsHash = (\n user: string,\n channel: string,\n origin: string,\n topic: string | null,\n): string => {\n const rawKey = `${user}|${channel}|${origin}|${topic ?? ''}`;\n return crypto.createHash('sha256').update(rawKey).digest('hex');\n};\n\n/** @internal */\nexport class DatabaseNotificationsStore implements NotificationsStore {\n private readonly isSQLite = false;\n\n private constructor(private readonly db: Knex) {\n this.isSQLite = this.db.client.config.client.includes('sqlite3');\n }\n\n static async create({\n database,\n skipMigrations,\n }: {\n database: DatabaseService;\n skipMigrations?: boolean;\n }): Promise<DatabaseNotificationsStore> {\n const client = await database.getClient();\n\n if (!database.migrations?.skip && !skipMigrations) {\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new DatabaseNotificationsStore(client);\n }\n\n private mapToInteger = (val: string | number | undefined): number => {\n return typeof val === 'string' ? Number.parseInt(val, 10) : val ?? 0;\n };\n\n private mapToNotifications = (rows: any[]): Notification[] => {\n return rows.map(row => ({\n id: row.id,\n user: row.type === 'broadcast' ? null : row.user,\n created: new Date(row.created),\n saved: row.saved,\n read: row.read,\n updated: row.updated,\n origin: row.origin,\n payload: {\n title: row.title,\n description: row.description,\n link: row.link,\n topic: row.topic,\n severity: row.severity,\n scope: row.scope,\n icon: row.icon,\n },\n }));\n };\n\n private mapToNotificationSettings = (rows: any[]): NotificationSettings => {\n return rows.reduce(\n (acc, row) => {\n let chan = acc.channels.find(\n (channel: { id: string }) => channel.id === row.channel,\n );\n if (!chan) {\n acc.channels.push({\n id: row.channel,\n origins: [],\n });\n chan = acc.channels[acc.channels.length - 1];\n }\n let origin = chan.origins.find(\n (ori: { id: string }) => ori.id === row.origin,\n );\n if (!origin) {\n origin = {\n id: row.origin,\n enabled: true,\n topics: [],\n };\n chan.origins.push(origin);\n }\n if (row.topic === null) {\n origin.enabled = Boolean(row.enabled);\n } else {\n let topic = origin.topics.find(\n (top: { id: string }) => top.id === row.topic,\n );\n if (!topic) {\n topic = {\n id: row.topic,\n enabled: Boolean(row.enabled),\n };\n origin.topics.push(topic);\n }\n }\n return acc;\n },\n { channels: [] },\n );\n };\n\n private mapNotificationToDbRow = (notification: Notification) => {\n return {\n id: notification.id,\n user: notification.user,\n origin: notification.origin,\n created: notification.created,\n topic: notification.payload?.topic,\n link: notification.payload?.link,\n title: notification.payload?.title,\n description: notification.payload?.description,\n severity: normalizeSeverity(notification.payload?.severity),\n scope: notification.payload?.scope,\n icon: notification.payload.icon,\n saved: notification.saved,\n read: notification.read,\n };\n };\n\n private mapBroadcastToDbRow = (notification: Notification) => {\n return {\n id: notification.id,\n origin: notification.origin,\n created: notification.created,\n topic: notification.payload?.topic,\n link: notification.payload?.link,\n title: notification.payload?.title,\n description: notification.payload?.description,\n severity: normalizeSeverity(notification.payload?.severity),\n icon: notification.payload.icon,\n scope: notification.payload?.scope,\n };\n };\n\n private getBroadcastUnion = (user?: string | null) => {\n return this.db<BroadcastRowType>('broadcast')\n .leftJoin('broadcast_user_status', function clause() {\n const join = this.on('id', '=', 'broadcast_user_status.broadcast_id');\n if (user !== null && user !== undefined) {\n join.andOnVal('user', '=', user);\n }\n })\n .select([...NOTIFICATION_COLUMNS, this.db.raw(\"'broadcast' as type\")]);\n };\n\n private getNotificationsBaseQuery = (\n options: NotificationGetOptions | NotificationModifyOptions,\n ) => {\n const { user, orderField } = options;\n\n const subQuery = this.db<NotificationRowType>('notification')\n .select([...NOTIFICATION_COLUMNS, this.db.raw(\"'entity' as type\")])\n .unionAll([this.getBroadcastUnion(user)])\n .as('notifications');\n\n const query = this.db.from(subQuery).where(q => {\n q.where('user', user).orWhereNull('user');\n });\n\n if (orderField && orderField.length > 0) {\n orderField.forEach(orderBy => {\n query.orderBy(orderBy.field, orderBy.order);\n });\n } else if (!orderField) {\n query.orderBy('created', 'desc');\n }\n\n if (options.createdAfter) {\n if (this.isSQLite) {\n query.where('created', '>=', options.createdAfter.valueOf());\n } else {\n query.where('created', '>=', options.createdAfter.toISOString());\n }\n }\n\n if (options.limit) {\n query.limit(options.limit);\n }\n\n if (options.offset) {\n query.offset(options.offset);\n }\n\n if (options.search) {\n query.whereRaw(\n `(LOWER(title) LIKE LOWER(?) OR LOWER(description) LIKE LOWER(?))`,\n [`%${options.search}%`, `%${options.search}%`],\n );\n }\n\n if (options.ids) {\n query.whereIn('id', options.ids);\n }\n\n if (options.read) {\n query.whereNotNull('read');\n } else if (options.read === false) {\n query.whereNull('read');\n } // or match both if undefined\n\n if (options.topic) {\n query.where('topic', '=', options.topic);\n }\n\n if (options.saved) {\n query.whereNotNull('saved');\n } else if (options.saved === false) {\n query.whereNull('saved');\n } // or match both if undefined\n\n if (options.minimumSeverity !== undefined) {\n const idx = notificationSeverities.indexOf(options.minimumSeverity);\n const equalOrHigher = notificationSeverities.slice(0, idx + 1);\n query.whereIn('severity', equalOrHigher);\n }\n\n return query;\n };\n\n async getNotifications(options: NotificationGetOptions) {\n const notificationQuery = this.getNotificationsBaseQuery(options);\n const notifications = await notificationQuery.select([\n ...NOTIFICATION_COLUMNS,\n 'type',\n ]);\n return this.mapToNotifications(notifications);\n }\n\n async getNotificationsCount(options: NotificationGetOptions) {\n const countOptions: NotificationGetOptions = { ...options };\n countOptions.limit = undefined;\n countOptions.offset = undefined;\n countOptions.orderField = [];\n const notificationQuery = this.getNotificationsBaseQuery(countOptions);\n const response = await notificationQuery.count('id as CNT');\n return Number(response[0].CNT);\n }\n\n async saveNotification(notification: Notification) {\n await this.db\n .insert(this.mapNotificationToDbRow(notification))\n .into('notification');\n }\n\n async saveBroadcast(notification: Notification) {\n await this.db\n .insert(this.mapBroadcastToDbRow(notification))\n .into('broadcast');\n if (notification.saved || notification.read) {\n await this.db\n .insert({\n user: notification.user,\n broadcast_id: notification.id,\n saved: notification.saved,\n read: notification.read,\n })\n .into('broadcast_user_status');\n }\n }\n\n async getStatus(options: NotificationGetOptions) {\n const notificationQuery = this.getNotificationsBaseQuery({\n ...options,\n orderField: [],\n });\n const readSubQuery = notificationQuery\n .clone()\n .count('id')\n .whereNotNull('read')\n .as('READ');\n const unreadSubQuery = notificationQuery\n .clone()\n .count('id')\n .whereNull('read')\n .as('UNREAD');\n\n const query = await notificationQuery\n .select(readSubQuery, unreadSubQuery)\n .first();\n\n return {\n unread: this.mapToInteger((query as any)?.UNREAD),\n read: this.mapToInteger((query as any)?.READ),\n };\n }\n\n async getExistingScopeNotification(options: {\n user: string;\n scope: string;\n origin: string;\n }) {\n const query = this.db<NotificationRowType>('notification')\n .where('user', options.user)\n .where('scope', options.scope)\n .where('origin', options.origin)\n .limit(1);\n\n const rows = await query;\n if (!rows || rows.length === 0) {\n return null;\n }\n return this.mapToNotifications(rows)[0];\n }\n\n async getExistingScopeBroadcast(options: { scope: string; origin: string }) {\n const query = this.db<BroadcastRowType>('broadcast')\n .where('scope', options.scope)\n .where('origin', options.origin)\n .limit(1);\n\n const rows = await query;\n if (!rows || rows.length === 0) {\n return null;\n }\n return this.mapToNotifications(rows)[0];\n }\n\n async restoreExistingNotification({\n id,\n notification,\n }: {\n id: string;\n notification: Notification;\n }) {\n const updateColumns = {\n title: notification.payload.title,\n description: notification.payload.description,\n link: notification.payload.link,\n topic: notification.payload.topic,\n updated: new Date(),\n severity: normalizeSeverity(notification.payload?.severity),\n read: null,\n };\n\n const notificationQuery = this.db('notification')\n .where('id', id)\n .where('user', notification.user);\n const broadcastQuery = this.db('broadcast').where('id', id);\n\n await Promise.all([\n notificationQuery.update(updateColumns),\n broadcastQuery.update({ ...updateColumns, read: undefined }),\n ]);\n\n return await this.getNotification({ id, user: notification.user });\n }\n\n async getNotification(options: {\n id: string;\n user?: string | null;\n }): Promise<Notification | null> {\n const rows = await this.db\n .select('*')\n .from(\n this.db<NotificationRowType>('notification')\n .select([...NOTIFICATION_COLUMNS, this.db.raw(\"'entity' as type\")])\n .unionAll([this.getBroadcastUnion(options.user)])\n .as('notifications'),\n )\n .where('id', options.id)\n .limit(1);\n if (!rows || rows.length === 0) {\n return null;\n }\n return this.mapToNotifications(rows)[0];\n }\n\n private markReadSaved = async (\n ids: string[],\n user: string,\n read?: Date | null,\n saved?: Date | null,\n ) => {\n await this.db<NotificationRowType>('notification')\n .whereIn('id', ids)\n .where('user', user)\n .update({ read, saved });\n\n const broadcasts = this.mapToNotifications(\n await this.db('broadcast').whereIn('id', ids).select(),\n );\n\n if (broadcasts.length > 0)\n if (!this.isSQLite) {\n await this.db<BroadcastUserStatusRowType>('broadcast_user_status')\n .insert(\n broadcasts.map(b => ({\n broadcast_id: b.id,\n user,\n read,\n saved,\n })),\n )\n .onConflict(['broadcast_id', 'user'])\n .merge(['read', 'saved']);\n } else {\n // SQLite does not support upsert so fall back to this (mostly for tests and local dev)\n for (const b of broadcasts) {\n const baseQuery = this.db<BroadcastUserStatusRowType>(\n 'broadcast_user_status',\n )\n .where('broadcast_id', b.id)\n .where('user', user);\n const exists = await baseQuery.clone().limit(1).select().first();\n if (exists) {\n await baseQuery.clone().update({ read, saved });\n } else {\n await baseQuery\n .clone()\n .insert({ broadcast_id: b.id, user, read, saved });\n }\n }\n }\n };\n\n async markRead(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, new Date(), undefined);\n }\n\n async markUnread(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, null, undefined);\n }\n\n async markSaved(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, undefined, new Date());\n }\n\n async markUnsaved(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, undefined, null);\n }\n\n async getUserNotificationOrigins(options: {\n user: string;\n }): Promise<{ origins: string[] }> {\n const rows: { origin: string }[] = await this.db<NotificationRowType>(\n 'notification',\n )\n .where('user', options.user)\n .select('origin')\n .distinct();\n return { origins: rows.map(row => row.origin) };\n }\n\n async getUserNotificationTopics(options: {\n user: string;\n }): Promise<{ topics: { origin: string; topic: string }[] }> {\n const rows: { topic: string; origin: string }[] =\n await this.db<NotificationRowType>('notification')\n .where('user', options.user)\n .select('topic', 'origin')\n .whereNotNull('topic')\n .distinct();\n\n return {\n topics: rows.map(row => ({ origin: row.origin, topic: row.topic })),\n };\n }\n\n async getNotificationSettings(options: {\n user: string;\n origin?: string;\n channel?: string;\n topic?: string;\n }): Promise<NotificationSettings> {\n const settingsQuery = this.db<UserSettingsRowType>('user_settings').where(\n 'user',\n options.user,\n );\n if (options.origin) {\n settingsQuery.where('origin', options.origin);\n }\n\n if (options.channel) {\n settingsQuery.where('channel', options.channel);\n }\n\n if (options.topic) {\n settingsQuery.where('topic', options.topic);\n }\n const settings = await settingsQuery.select();\n return this.mapToNotificationSettings(settings);\n }\n\n async saveNotificationSettings(options: {\n user: string;\n settings: NotificationSettings;\n }): Promise<void> {\n const rows: {\n settings_key_hash: string;\n user: string;\n channel: string;\n origin: string;\n topic: string | null;\n enabled: boolean;\n }[] = [];\n\n options.settings.channels.forEach(channel => {\n channel.origins.forEach(origin => {\n rows.push({\n settings_key_hash: generateSettingsHash(\n options.user,\n channel.id,\n origin.id,\n null,\n ),\n user: options.user,\n channel: channel.id,\n origin: origin.id,\n topic: null,\n enabled: origin.enabled,\n });\n\n origin.topics?.forEach(topic => {\n rows.push({\n settings_key_hash: generateSettingsHash(\n options.user,\n channel.id,\n origin.id,\n topic.id,\n ),\n user: options.user,\n channel: channel.id,\n origin: origin.id,\n topic: topic.id,\n enabled: origin.enabled && topic.enabled,\n });\n });\n });\n });\n\n await this.db<UserSettingsRowType>('user_settings')\n .where('user', options.user)\n .delete();\n await this.db<UserSettingsRowType>('user_settings').insert(rows);\n }\n\n async getTopics(options: TopicGetOptions): Promise<{ topics: string[] }> {\n const notificationQuery = this.getNotificationsBaseQuery({\n ...options,\n orderField: [{ field: 'topic', order: 'asc' }],\n });\n const topics = await notificationQuery\n .whereNotNull('topic')\n .distinct(['topic']);\n return { topics: topics.map(row => row.topic) };\n }\n\n async clearNotifications(options: {\n maxAge: HumanDuration;\n }): Promise<{ deletedCount: number }> {\n const ms = durationToMilliseconds(options.maxAge);\n const now = new Date(new Date().getTime() - ms);\n const notificationsCount = await this.db('notification')\n .where(builder => {\n builder.where('created', '<=', now).whereNull('updated');\n })\n .orWhere('updated', '<=', now)\n .delete();\n const broadcastsCount = await this.db('broadcast')\n .where(builder => {\n builder.where('created', '<=', now).whereNull('updated');\n })\n .orWhere('updated', '<=', now)\n .delete();\n return { deletedCount: notificationsCount + broadcastsCount };\n }\n}\n"],"names":["resolvePackagePath","notificationSeverities","crypto","durationToMilliseconds"],"mappings":";;;;;;;;;;;AAmCA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,yCAAA;AAAA,EACA;AACF,CAAA;AAEA,MAAM,oBAAuB,GAAA;AAAA,EAC3B,IAAA;AAAA,EACA,OAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA;AA8Ca,MAAA,iBAAA,GAAoB,CAAC,KAAyC,KAAA;AACzE,EAAI,IAAA,KAAA,GAAA,CAAS,KAAS,IAAA,QAAA,EAAU,WAAY,EAAA;AAC5C,EAAA,IAAIC,gDAAuB,CAAA,OAA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["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n DatabaseService,\n resolvePackagePath,\n} from '@backstage/backend-plugin-api';\nimport {\n NotificationGetOptions,\n NotificationModifyOptions,\n NotificationsStore,\n TopicGetOptions,\n} from './NotificationsStore';\nimport {\n Notification,\n NotificationSettings,\n notificationSeverities,\n NotificationSeverity,\n} from '@backstage/plugin-notifications-common';\nimport { Knex } from 'knex';\nimport crypto from 'crypto';\nimport { durationToMilliseconds, HumanDuration } from '@backstage/types';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-notifications-backend',\n 'migrations',\n);\n\nconst NOTIFICATION_COLUMNS = [\n 'id',\n 'title',\n 'description',\n 'severity',\n 'link',\n 'origin',\n 'scope',\n 'topic',\n 'icon',\n 'created',\n 'updated',\n 'user',\n 'read',\n 'saved',\n];\n\ntype NotificationRowType = {\n id: string;\n user: string;\n title: string;\n description?: string | null;\n severity: string;\n link: string | null;\n origin: string;\n scope: string | null;\n topic: string | null;\n created: Date;\n updated: Date | null;\n read: Date | null;\n saved: Date | null;\n icon: string | null;\n};\n\ntype BroadcastRowType = {\n id: string;\n title: string;\n description: string | null;\n link: string | null;\n origin: string;\n scope: string | null;\n topic: string | null;\n created: Date;\n updated: Date | null;\n icon: string | null;\n};\n\ntype BroadcastUserStatusRowType = {\n broadcast_id: string;\n user: string;\n read: Date | null;\n saved: Date | null;\n};\n\ntype UserSettingsRowType = {\n user: string;\n channel: string;\n origin: string;\n enabled: boolean;\n};\n\nexport const normalizeSeverity = (input?: string): NotificationSeverity => {\n let lower = (input ?? 'normal').toLowerCase() as NotificationSeverity;\n if (notificationSeverities.indexOf(lower) < 0) {\n lower = 'normal';\n }\n return lower;\n};\n\nexport const generateSettingsHash = (\n user: string,\n channel: string,\n origin: string,\n topic: string | null,\n): string => {\n const rawKey = `${user}|${channel}|${origin}|${topic ?? ''}`;\n return crypto.createHash('sha256').update(rawKey).digest('hex');\n};\n\n/** @internal */\nexport class DatabaseNotificationsStore implements NotificationsStore {\n private readonly isSQLite = false;\n\n private constructor(private readonly db: Knex) {\n this.isSQLite = this.db.client.config.client.includes('sqlite3');\n }\n\n static async create({\n database,\n skipMigrations,\n }: {\n database: DatabaseService;\n skipMigrations?: boolean;\n }): Promise<DatabaseNotificationsStore> {\n const client = await database.getClient();\n\n if (!database.migrations?.skip && !skipMigrations) {\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new DatabaseNotificationsStore(client);\n }\n\n private mapToInteger = (val: string | number | undefined): number => {\n return typeof val === 'string' ? Number.parseInt(val, 10) : val ?? 0;\n };\n\n private mapToNotifications = (rows: any[]): Notification[] => {\n return rows.map(row => ({\n id: row.id,\n user: row.type === 'broadcast' ? null : row.user,\n created: new Date(row.created),\n saved: row.saved,\n read: row.read,\n updated: row.updated,\n origin: row.origin,\n payload: {\n title: row.title,\n description: row.description,\n link: row.link,\n topic: row.topic,\n severity: row.severity,\n scope: row.scope,\n icon: row.icon,\n },\n }));\n };\n\n private mapToNotificationSettings = (rows: any[]): NotificationSettings => {\n return rows.reduce(\n (acc, row) => {\n let chan = acc.channels.find(\n (channel: { id: string }) => channel.id === row.channel,\n );\n if (!chan) {\n acc.channels.push({\n id: row.channel,\n origins: [],\n });\n chan = acc.channels[acc.channels.length - 1];\n }\n let origin = chan.origins.find(\n (ori: { id: string }) => ori.id === row.origin,\n );\n if (!origin) {\n origin = {\n id: row.origin,\n enabled: true,\n topics: [],\n };\n chan.origins.push(origin);\n }\n if (row.topic === null) {\n origin.enabled = Boolean(row.enabled);\n } else {\n let topic = origin.topics.find(\n (top: { id: string }) => top.id === row.topic,\n );\n if (!topic) {\n topic = {\n id: row.topic,\n enabled: Boolean(row.enabled),\n };\n origin.topics.push(topic);\n }\n }\n return acc;\n },\n { channels: [] },\n );\n };\n\n private mapNotificationToDbRow = (notification: Notification) => {\n return {\n id: notification.id,\n user: notification.user,\n origin: notification.origin,\n created: notification.created,\n topic: notification.payload?.topic,\n link: notification.payload?.link,\n title: notification.payload?.title,\n description: notification.payload?.description,\n severity: normalizeSeverity(notification.payload?.severity),\n scope: notification.payload?.scope,\n icon: notification.payload.icon,\n saved: notification.saved,\n read: notification.read,\n };\n };\n\n private mapBroadcastToDbRow = (notification: Notification) => {\n return {\n id: notification.id,\n origin: notification.origin,\n created: notification.created,\n topic: notification.payload?.topic,\n link: notification.payload?.link,\n title: notification.payload?.title,\n description: notification.payload?.description,\n severity: normalizeSeverity(notification.payload?.severity),\n icon: notification.payload.icon,\n scope: notification.payload?.scope,\n };\n };\n\n private getBroadcastUnion = (user?: string | null) => {\n return this.db<BroadcastRowType>('broadcast')\n .leftJoin('broadcast_user_status', function clause() {\n const join = this.on('id', '=', 'broadcast_user_status.broadcast_id');\n if (user !== null && user !== undefined) {\n join.andOnVal('user', '=', user);\n }\n })\n .select([...NOTIFICATION_COLUMNS, this.db.raw(\"'broadcast' as type\")]);\n };\n\n private getNotificationsBaseQuery = (\n options: NotificationGetOptions | NotificationModifyOptions,\n ) => {\n const { user, orderField } = options;\n\n const subQuery = this.db<NotificationRowType>('notification')\n .select([...NOTIFICATION_COLUMNS, this.db.raw(\"'entity' as type\")])\n .unionAll([this.getBroadcastUnion(user)])\n .as('notifications');\n\n const query = this.db.from(subQuery).where(q => {\n q.where('user', user).orWhereNull('user');\n });\n\n if (orderField && orderField.length > 0) {\n orderField.forEach(orderBy => {\n query.orderBy(orderBy.field, orderBy.order);\n });\n } else if (!orderField) {\n query.orderBy('created', 'desc');\n }\n\n if (options.createdAfter) {\n if (this.isSQLite) {\n query.where('created', '>=', options.createdAfter.valueOf());\n } else {\n query.where('created', '>=', options.createdAfter.toISOString());\n }\n }\n\n if (options.limit) {\n query.limit(options.limit);\n }\n\n if (options.offset) {\n query.offset(options.offset);\n }\n\n if (options.search) {\n query.whereRaw(\n `(LOWER(title) LIKE LOWER(?) OR LOWER(description) LIKE LOWER(?))`,\n [`%${options.search}%`, `%${options.search}%`],\n );\n }\n\n if (options.ids) {\n query.whereIn('id', options.ids);\n }\n\n if (options.read) {\n query.whereNotNull('read');\n } else if (options.read === false) {\n query.whereNull('read');\n } // or match both if undefined\n\n if (options.topic) {\n query.where('topic', '=', options.topic);\n }\n\n if (options.saved) {\n query.whereNotNull('saved');\n } else if (options.saved === false) {\n query.whereNull('saved');\n } // or match both if undefined\n\n if (options.minimumSeverity !== undefined) {\n const idx = notificationSeverities.indexOf(options.minimumSeverity);\n const equalOrHigher = notificationSeverities.slice(0, idx + 1);\n query.whereIn('severity', equalOrHigher);\n }\n\n return query;\n };\n\n async getNotifications(options: NotificationGetOptions) {\n const notificationQuery = this.getNotificationsBaseQuery(options);\n const notifications = await notificationQuery.select([\n ...NOTIFICATION_COLUMNS,\n 'type',\n ]);\n return this.mapToNotifications(notifications);\n }\n\n async getNotificationsCount(options: NotificationGetOptions) {\n const countOptions: NotificationGetOptions = { ...options };\n countOptions.limit = undefined;\n countOptions.offset = undefined;\n countOptions.orderField = [];\n const notificationQuery = this.getNotificationsBaseQuery(countOptions);\n const response = await notificationQuery.count('id as CNT');\n return Number(response[0].CNT);\n }\n\n async saveNotification(notification: Notification) {\n await this.db\n .insert(this.mapNotificationToDbRow(notification))\n .into('notification');\n }\n\n async saveBroadcast(notification: Notification) {\n await this.db\n .insert(this.mapBroadcastToDbRow(notification))\n .into('broadcast');\n if (notification.saved || notification.read) {\n await this.db\n .insert({\n user: notification.user,\n broadcast_id: notification.id,\n saved: notification.saved,\n read: notification.read,\n })\n .into('broadcast_user_status');\n }\n }\n\n async getStatus(options: NotificationGetOptions) {\n const notificationQuery = this.getNotificationsBaseQuery({\n ...options,\n orderField: [],\n });\n const readSubQuery = notificationQuery\n .clone()\n .count('id')\n .whereNotNull('read')\n .as('READ');\n const unreadSubQuery = notificationQuery\n .clone()\n .count('id')\n .whereNull('read')\n .as('UNREAD');\n\n const query = await notificationQuery\n .select(readSubQuery, unreadSubQuery)\n .first();\n\n return {\n unread: this.mapToInteger((query as any)?.UNREAD),\n read: this.mapToInteger((query as any)?.READ),\n };\n }\n\n async getExistingScopeNotification(options: {\n user: string;\n scope: string;\n origin: string;\n }) {\n const query = this.db<NotificationRowType>('notification')\n .where('user', options.user)\n .where('scope', options.scope)\n .where('origin', options.origin)\n .limit(1);\n\n const rows = await query;\n if (!rows || rows.length === 0) {\n return null;\n }\n return this.mapToNotifications(rows)[0];\n }\n\n async getExistingScopeBroadcast(options: { scope: string; origin: string }) {\n const query = this.db<BroadcastRowType>('broadcast')\n .where('scope', options.scope)\n .where('origin', options.origin)\n .limit(1);\n\n const rows = await query;\n if (!rows || rows.length === 0) {\n return null;\n }\n return this.mapToNotifications(rows)[0];\n }\n\n async restoreExistingNotification({\n id,\n notification,\n }: {\n id: string;\n notification: Notification;\n }) {\n const updateColumns = {\n title: notification.payload.title,\n description: notification.payload.description,\n link: notification.payload.link,\n topic: notification.payload.topic,\n updated: new Date(),\n severity: normalizeSeverity(notification.payload?.severity),\n read: null,\n };\n\n const notificationQuery = this.db('notification')\n .where('id', id)\n .where('user', notification.user);\n const broadcastQuery = this.db('broadcast').where('id', id);\n\n await Promise.all([\n notificationQuery.update(updateColumns),\n broadcastQuery.update({ ...updateColumns, read: undefined }),\n ]);\n\n return await this.getNotification({ id, user: notification.user });\n }\n\n async getNotification(options: {\n id: string;\n user?: string | null;\n }): Promise<Notification | null> {\n const rows = await this.db\n .select('*')\n .from(\n this.db<NotificationRowType>('notification')\n .select([...NOTIFICATION_COLUMNS, this.db.raw(\"'entity' as type\")])\n .unionAll([this.getBroadcastUnion(options.user)])\n .as('notifications'),\n )\n .where('id', options.id)\n .limit(1);\n if (!rows || rows.length === 0) {\n return null;\n }\n return this.mapToNotifications(rows)[0];\n }\n\n private markReadSaved = async (\n ids: string[],\n user: string,\n read?: Date | null,\n saved?: Date | null,\n ) => {\n await this.db<NotificationRowType>('notification')\n .whereIn('id', ids)\n .where('user', user)\n .update({ read, saved });\n\n const broadcasts = this.mapToNotifications(\n await this.db('broadcast').whereIn('id', ids).select(),\n );\n\n if (broadcasts.length > 0)\n if (!this.isSQLite) {\n await this.db<BroadcastUserStatusRowType>('broadcast_user_status')\n .insert(\n broadcasts.map(b => ({\n broadcast_id: b.id,\n user,\n read,\n saved,\n })),\n )\n .onConflict(['broadcast_id', 'user'])\n .merge(['read', 'saved']);\n } else {\n // SQLite does not support upsert so fall back to this (mostly for tests and local dev)\n for (const b of broadcasts) {\n const baseQuery = this.db<BroadcastUserStatusRowType>(\n 'broadcast_user_status',\n )\n .where('broadcast_id', b.id)\n .where('user', user);\n const exists = await baseQuery.clone().limit(1).select().first();\n if (exists) {\n await baseQuery.clone().update({ read, saved });\n } else {\n await baseQuery\n .clone()\n .insert({ broadcast_id: b.id, user, read, saved });\n }\n }\n }\n };\n\n async markRead(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, new Date(), undefined);\n }\n\n async markUnread(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, null, undefined);\n }\n\n async markSaved(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, undefined, new Date());\n }\n\n async markUnsaved(options: NotificationModifyOptions): Promise<void> {\n await this.markReadSaved(options.ids, options.user, undefined, null);\n }\n\n async getUserNotificationOrigins(options: {\n user: string;\n }): Promise<{ origins: string[] }> {\n const rows: { origin: string }[] = await this.db<NotificationRowType>(\n 'notification',\n )\n .where('user', options.user)\n .select('origin')\n .distinct();\n return { origins: rows.map(row => row.origin) };\n }\n\n async getUserNotificationTopics(options: {\n user: string;\n }): Promise<{ topics: { origin: string; topic: string }[] }> {\n const rows: { topic: string; origin: string }[] =\n await this.db<NotificationRowType>('notification')\n .where('user', options.user)\n .select('topic', 'origin')\n .whereNotNull('topic')\n .distinct();\n\n return {\n topics: rows.map(row => ({ origin: row.origin, topic: row.topic })),\n };\n }\n\n async getNotificationSettings(options: {\n user: string;\n origin?: string;\n channel?: string;\n topic?: string;\n }): Promise<NotificationSettings> {\n const settingsQuery = this.db<UserSettingsRowType>('user_settings').where(\n 'user',\n options.user,\n );\n if (options.origin) {\n settingsQuery.where('origin', options.origin);\n }\n\n if (options.channel) {\n settingsQuery.where('channel', options.channel);\n }\n\n if (options.topic) {\n settingsQuery.where('topic', options.topic);\n }\n const settings = await settingsQuery.select();\n return this.mapToNotificationSettings(settings);\n }\n\n async saveNotificationSettings(options: {\n user: string;\n settings: NotificationSettings;\n }): Promise<void> {\n const rows: {\n settings_key_hash: string;\n user: string;\n channel: string;\n origin: string;\n topic: string | null;\n enabled: boolean;\n }[] = [];\n\n options.settings.channels.forEach(channel => {\n channel.origins.forEach(origin => {\n rows.push({\n settings_key_hash: generateSettingsHash(\n options.user,\n channel.id,\n origin.id,\n null,\n ),\n user: options.user,\n channel: channel.id,\n origin: origin.id,\n topic: null,\n enabled: origin.enabled,\n });\n\n origin.topics?.forEach(topic => {\n rows.push({\n settings_key_hash: generateSettingsHash(\n options.user,\n channel.id,\n origin.id,\n topic.id,\n ),\n user: options.user,\n channel: channel.id,\n origin: origin.id,\n topic: topic.id,\n enabled: origin.enabled && topic.enabled,\n });\n });\n });\n });\n\n await this.db<UserSettingsRowType>('user_settings')\n .where('user', options.user)\n .delete();\n await this.db<UserSettingsRowType>('user_settings').insert(rows);\n }\n\n async getTopics(options: TopicGetOptions): Promise<{ topics: string[] }> {\n const notificationQuery = this.getNotificationsBaseQuery({\n ...options,\n orderField: [{ field: 'topic', order: 'asc' }],\n });\n const topics = await notificationQuery\n .whereNotNull('topic')\n .distinct(['topic']);\n return { topics: topics.map(row => row.topic) };\n }\n\n async clearNotifications(options: {\n maxAge: HumanDuration;\n }): Promise<{ deletedCount: number }> {\n const ms = durationToMilliseconds(options.maxAge);\n const now = new Date(new Date().getTime() - ms);\n const notificationsCount = await this.db('notification')\n .where(builder => {\n builder.where('created', '<=', now).whereNull('updated');\n })\n .orWhere('updated', '<=', now)\n .delete();\n const broadcastsCount = await this.db('broadcast')\n .where(builder => {\n builder.where('created', '<=', now).whereNull('updated');\n })\n .orWhere('updated', '<=', now)\n .delete();\n return { deletedCount: notificationsCount + broadcastsCount };\n }\n}\n"],"names":["resolvePackagePath","notificationSeverities","crypto","durationToMilliseconds"],"mappings":";;;;;;;;;;;AAmCA,MAAM,aAAA,GAAgBA,mCAAA;AAAA,EACpB,yCAAA;AAAA,EACA;AACF,CAAA;AAEA,MAAM,oBAAA,GAAuB;AAAA,EAC3B,IAAA;AAAA,EACA,OAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA;AA8CO,MAAM,iBAAA,GAAoB,CAAC,KAAA,KAAyC;AACzE,EAAA,IAAI,KAAA,GAAA,CAAS,KAAA,IAAS,QAAA,EAAU,WAAA,EAAY;AAC5C,EAAA,IAAIC,gDAAA,CAAuB,OAAA,CAAQ,KAAK,CAAA,GAAI,CAAA,EAAG;AAC7C,IAAA,KAAA,GAAQ,QAAA;AAAA,EACV;AACA,EAAA,OAAO,KAAA;AACT;AAEO,MAAM,oBAAA,GAAuB,CAClC,IAAA,EACA,OAAA,EACA,QACA,KAAA,KACW;AACX,EAAA,MAAM,MAAA,GAAS,GAAG,IAAI,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA,EAAI,KAAA,IAAS,EAAE,CAAA,CAAA;AAC1D,EAAA,OAAOC,uBAAA,CAAO,WAAW,QAAQ,CAA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ources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './service/router';\nimport { signalsServiceRef } from '@backstage/plugin-signals-node';\nimport {\n NotificationProcessor,\n notificationsProcessingExtensionPoint,\n NotificationsProcessingExtensionPoint,\n} from '@backstage/plugin-notifications-node';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\nimport { DatabaseNotificationsStore } from './database';\nimport { NotificationCleaner } from './service/NotificationCleaner.ts';\n\nclass NotificationsProcessingExtensionPointImpl\n implements NotificationsProcessingExtensionPoint\n{\n #processors = new Array<NotificationProcessor>();\n\n addProcessor(\n ...processors: Array<NotificationProcessor | Array<NotificationProcessor>>\n ): void {\n this.#processors.push(...processors.flat());\n }\n\n get processors() {\n return this.#processors;\n }\n}\n\n/**\n * Notifications backend plugin\n *\n * @public\n */\nexport const notificationsPlugin = createBackendPlugin({\n pluginId: 'notifications',\n register(env) {\n const processingExtensions =\n new NotificationsProcessingExtensionPointImpl();\n env.registerExtensionPoint(\n notificationsProcessingExtensionPoint,\n processingExtensions,\n );\n\n env.registerInit({\n deps: {\n auth: coreServices.auth,\n httpAuth: coreServices.httpAuth,\n userInfo: coreServices.userInfo,\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n database: coreServices.database,\n signals: signalsServiceRef,\n config: coreServices.rootConfig,\n catalog: catalogServiceRef,\n scheduler: coreServices.scheduler,\n },\n async init({\n auth,\n httpAuth,\n userInfo,\n httpRouter,\n logger,\n database,\n signals,\n config,\n catalog,\n scheduler,\n }) {\n const store = await DatabaseNotificationsStore.create({ database });\n\n httpRouter.use(\n await createRouter({\n auth,\n httpAuth,\n userInfo,\n logger,\n config,\n store,\n catalog,\n signals,\n processors: processingExtensions.processors,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n\n const cleaner = new NotificationCleaner(\n config,\n scheduler,\n logger,\n store,\n );\n await cleaner.initTaskRunner();\n },\n });\n },\n});\n"],"names":["createBackendPlugin","notificationsProcessingExtensionPoint","coreServices","signalsServiceRef","catalogServiceRef","DatabaseNotificationsStore","createRouter","NotificationCleaner"],"mappings":";;;;;;;;;;AA+BA,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './service/router';\nimport { signalsServiceRef } from '@backstage/plugin-signals-node';\nimport {\n NotificationProcessor,\n notificationsProcessingExtensionPoint,\n NotificationsProcessingExtensionPoint,\n} from '@backstage/plugin-notifications-node';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\nimport { DatabaseNotificationsStore } from './database';\nimport { NotificationCleaner } from './service/NotificationCleaner.ts';\n\nclass NotificationsProcessingExtensionPointImpl\n implements NotificationsProcessingExtensionPoint\n{\n #processors = new Array<NotificationProcessor>();\n\n addProcessor(\n ...processors: Array<NotificationProcessor | Array<NotificationProcessor>>\n ): void {\n this.#processors.push(...processors.flat());\n }\n\n get processors() {\n return this.#processors;\n }\n}\n\n/**\n * Notifications backend plugin\n *\n * @public\n */\nexport const notificationsPlugin = createBackendPlugin({\n pluginId: 'notifications',\n register(env) {\n const processingExtensions =\n new NotificationsProcessingExtensionPointImpl();\n env.registerExtensionPoint(\n notificationsProcessingExtensionPoint,\n processingExtensions,\n );\n\n env.registerInit({\n deps: {\n auth: coreServices.auth,\n httpAuth: coreServices.httpAuth,\n userInfo: coreServices.userInfo,\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n database: coreServices.database,\n signals: signalsServiceRef,\n config: coreServices.rootConfig,\n catalog: catalogServiceRef,\n scheduler: coreServices.scheduler,\n },\n async init({\n auth,\n httpAuth,\n userInfo,\n httpRouter,\n logger,\n database,\n signals,\n config,\n catalog,\n scheduler,\n }) {\n const store = await DatabaseNotificationsStore.create({ database });\n\n httpRouter.use(\n await createRouter({\n auth,\n httpAuth,\n userInfo,\n logger,\n config,\n store,\n catalog,\n signals,\n processors: processingExtensions.processors,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n\n const cleaner = new NotificationCleaner(\n config,\n scheduler,\n logger,\n store,\n );\n await cleaner.initTaskRunner();\n },\n });\n },\n});\n"],"names":["createBackendPlugin","notificationsProcessingExtensionPoint","coreServices","signalsServiceRef","catalogServiceRef","DatabaseNotificationsStore","createRouter","NotificationCleaner"],"mappings":";;;;;;;;;;AA+BA,MAAM,yCAAA,CAEN;AAAA,EACE,WAAA,GAAc,IAAI,KAAA,EAA6B;AAAA,EAE/C,gBACK,UAAA,EACG;AACN,IAAA,IAAA,CAAK,WAAA,CAAY,IAAA,CAAK,GAAG,UAAA,CAAW,MAAM,CAAA;AAAA,EAC5C;AAAA,EAEA,IAAI,UAAA,GAAa;AACf,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACd;AACF;AAOO,MAAM,sBAAsBA,oCAAA,CAAoB;AAAA,EACrD,QAAA,EAAU,eAA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ED,QAAA,MAAM,UAAU,IAAIC,uCAAA;AAAA,UAClB,MAAA;AAAA,UACA,SAAA;AAAA,UACA,MAAA;AAAA,UACA;AAAA,SACF;AACA,QAAA,MAAM,QAAQ,cAAA,EAAe;AAAA,MAC/B;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationCleaner.cjs.js","sources":["../../src/service/NotificationCleaner.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskScheduleDefinition,\n} from '@backstage/backend-plugin-api';\nimport { Config, readDurationFromConfig } from '@backstage/config';\nimport { NotificationsStore } from '../database';\nimport { HumanDuration } from '@backstage/types';\nimport { ForwardedError } from '@backstage/errors';\n\nexport class NotificationCleaner {\n private readonly retention: HumanDuration = { years: 1 };\n private readonly enabled: boolean = true;\n\n constructor(\n config: Config,\n private readonly scheduler: SchedulerService,\n private readonly logger: LoggerService,\n private readonly database: NotificationsStore,\n ) {\n if (config.has('notifications.retention')) {\n const retentionConfig = config.get('notifications.retention');\n if (typeof retentionConfig === 'boolean' && !retentionConfig) {\n logger.info(\n 'Notification retention is disabled, skipping notification cleaner task',\n );\n this.enabled = false;\n return;\n }\n this.retention = readDurationFromConfig(config, {\n key: 'notifications.retention',\n });\n }\n }\n\n async initTaskRunner() {\n if (!this.enabled) {\n return;\n }\n\n const schedule: SchedulerServiceTaskScheduleDefinition = {\n frequency: { cron: '0 0 * * *' },\n timeout: { hours: 1 },\n initialDelay: { hours: 1 },\n scope: 'global',\n };\n\n const taskRunner = this.scheduler.createScheduledTaskRunner(schedule);\n await taskRunner.run({\n id: 'notification-cleaner',\n fn: async () => {\n await this.clearNotifications(\n this.logger,\n this.database,\n this.retention,\n );\n },\n });\n }\n\n private async clearNotifications(\n logger: LoggerService,\n database: NotificationsStore,\n retention: HumanDuration,\n ) {\n logger.info('Starting notification cleaner task');\n try {\n const result = await database.clearNotifications({ maxAge: retention });\n logger.info(\n `Notification cleaner task completed successfully, deleted ${result.deletedCount} notifications`,\n );\n } catch (error) {\n throw new ForwardedError('Notification cleaner task failed', error);\n }\n }\n}\n"],"names":["config","readDurationFromConfig","ForwardedError"],"mappings":";;;;;AAyBO,MAAM,
|
|
1
|
+
{"version":3,"file":"NotificationCleaner.cjs.js","sources":["../../src/service/NotificationCleaner.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskScheduleDefinition,\n} from '@backstage/backend-plugin-api';\nimport { Config, readDurationFromConfig } from '@backstage/config';\nimport { NotificationsStore } from '../database';\nimport { HumanDuration } from '@backstage/types';\nimport { ForwardedError } from '@backstage/errors';\n\nexport class NotificationCleaner {\n private readonly retention: HumanDuration = { years: 1 };\n private readonly enabled: boolean = true;\n\n constructor(\n config: Config,\n private readonly scheduler: SchedulerService,\n private readonly logger: LoggerService,\n private readonly database: NotificationsStore,\n ) {\n if (config.has('notifications.retention')) {\n const retentionConfig = config.get('notifications.retention');\n if (typeof retentionConfig === 'boolean' && !retentionConfig) {\n logger.info(\n 'Notification retention is disabled, skipping notification cleaner task',\n );\n this.enabled = false;\n return;\n }\n this.retention = readDurationFromConfig(config, {\n key: 'notifications.retention',\n });\n }\n }\n\n async initTaskRunner() {\n if (!this.enabled) {\n return;\n }\n\n const schedule: SchedulerServiceTaskScheduleDefinition = {\n frequency: { cron: '0 0 * * *' },\n timeout: { hours: 1 },\n initialDelay: { hours: 1 },\n scope: 'global',\n };\n\n const taskRunner = this.scheduler.createScheduledTaskRunner(schedule);\n await taskRunner.run({\n id: 'notification-cleaner',\n fn: async () => {\n await this.clearNotifications(\n this.logger,\n this.database,\n this.retention,\n );\n },\n });\n }\n\n private async clearNotifications(\n logger: LoggerService,\n database: NotificationsStore,\n retention: HumanDuration,\n ) {\n logger.info('Starting notification cleaner task');\n try {\n const result = await database.clearNotifications({ maxAge: retention });\n logger.info(\n `Notification cleaner task completed successfully, deleted ${result.deletedCount} notifications`,\n );\n } catch (error) {\n throw new ForwardedError('Notification cleaner task failed', error);\n }\n }\n}\n"],"names":["config","readDurationFromConfig","ForwardedError"],"mappings":";;;;;AAyBO,MAAM,mBAAA,CAAoB;AAAA,EAI/B,WAAA,CACEA,QAAA,EACiB,SAAA,EACA,MAAA,EACA,QAAA,EACjB;AAHiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAEjB,IAAA,IAAIA,QAAA,CAAO,GAAA,CAAI,yBAAyB,CAAA,EAAG;AACzC,MAAA,MAAM,eAAA,GAAkBA,QAAA,CAAO,GAAA,CAAI,yBAAyB,CAAA;AAC5D,MAAA,IAAI,OAAO,eAAA,KAAoB,SAAA,IAAa,CAAC,eAAA,EAAiB;AAC5D,QAAA,MAAA,CAAO,IAAA;AAAA,UACL;AAAA,SACF;AACA,QAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AACf,QAAA;AAAA,MACF;AACA,MAAA,IAAA,CA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AAA,EAAoC,KAAK,CAAA;AAAA,IACpE;AAAA,EACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUsersForEntityRef.cjs.js","sources":["../../src/service/getUsersForEntityRef.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Entity,\n isGroupEntity,\n isUserEntity,\n parseEntityRef,\n RELATION_HAS_MEMBER,\n RELATION_OWNED_BY,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nconst isUserEntityRef = (ref: string) =>\n parseEntityRef(ref).kind.toLocaleLowerCase() === 'user';\n\n// Partitions array of entity references to two arrays; user entity refs and other entity refs\nconst partitionEntityRefs = (refs: string[]): string[][] =>\n refs.reduce(\n ([userEntityRefs, otherEntityRefs]: string[][], ref: string) => {\n return isUserEntityRef(ref)\n ? [[...userEntityRefs, ref], otherEntityRefs]\n : [userEntityRefs, [...otherEntityRefs, ref]];\n },\n [[], []],\n );\n\nexport const getUsersForEntityRef = async (\n entityRef: string | string[] | null,\n excludeEntityRefs: string | string[],\n options: {\n auth: AuthService;\n catalog: CatalogService;\n },\n): Promise<string[]> => {\n const { auth, catalog } = options;\n\n if (entityRef === null) {\n return [];\n }\n\n const excluded = Array.isArray(excludeEntityRefs)\n ? excludeEntityRefs\n : [excludeEntityRefs];\n\n const refsArr = Array.isArray(entityRef) ? entityRef : [entityRef];\n const [userEntityRefs, otherEntityRefs] = partitionEntityRefs(refsArr);\n const users: string[] = userEntityRefs.filter(ref => !excluded.includes(ref));\n const entityRefs = otherEntityRefs.filter(ref => !excluded.includes(ref));\n\n const fields = ['kind', 'metadata.name', 'metadata.namespace', 'relations'];\n let entities: Array<Entity | undefined> = [];\n if (entityRefs.length > 0) {\n const fetchedEntities = await catalog.getEntitiesByRefs(\n {\n entityRefs,\n fields,\n },\n { credentials: await auth.getOwnServiceCredentials() },\n );\n entities = fetchedEntities.items;\n }\n\n const mapEntity = async (entity: Entity | undefined): Promise<string[]> => {\n if (!entity) {\n return [];\n }\n\n const currentEntityRef = stringifyEntityRef(entity);\n if (excluded.includes(currentEntityRef)) {\n return [];\n }\n\n if (isUserEntity(entity)) {\n return [currentEntityRef];\n }\n\n if (isGroupEntity(entity)) {\n if (!entity.relations?.length) {\n return [];\n }\n\n const groupUsers = entity.relations\n .filter(\n relation =>\n relation.type === RELATION_HAS_MEMBER &&\n isUserEntityRef(relation.targetRef),\n )\n .map(r => r.targetRef);\n\n const childGroupRefs = entity.relations\n .filter(relation => relation.type === RELATION_PARENT_OF)\n .map(r => r.targetRef);\n\n let childGroupUsers: string[][] = [];\n if (childGroupRefs.length > 0) {\n const childGroups = await catalog.getEntitiesByRefs(\n {\n entityRefs: childGroupRefs,\n fields,\n },\n { credentials: await auth.getOwnServiceCredentials() },\n );\n childGroupUsers = await Promise.all(childGroups.items.map(mapEntity));\n }\n\n return [...groupUsers, ...childGroupUsers.flat(2)].filter(\n ref => !excluded.includes(ref),\n );\n }\n\n if (entity.relations?.length) {\n const ownerRef = entity.relations.find(\n relation => relation.type === RELATION_OWNED_BY,\n )?.targetRef;\n\n if (!ownerRef) {\n return [];\n }\n\n if (isUserEntityRef(ownerRef)) {\n if (excluded.includes(ownerRef)) {\n return [];\n }\n return [ownerRef];\n }\n\n const owner = await catalog.getEntityByRef(ownerRef, {\n credentials: await auth.getOwnServiceCredentials(),\n });\n return mapEntity(owner);\n }\n\n return [];\n };\n\n for (const entity of entities) {\n const u = await mapEntity(entity);\n users.push(...u);\n }\n\n return [...new Set(users)].filter(Boolean);\n};\n"],"names":["parseEntityRef","stringifyEntityRef","isUserEntity","isGroupEntity","RELATION_HAS_MEMBER","RELATION_PARENT_OF","RELATION_OWNED_BY"],"mappings":";;;;AA6BA,MAAM,eAAA,GAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"getUsersForEntityRef.cjs.js","sources":["../../src/service/getUsersForEntityRef.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Entity,\n isGroupEntity,\n isUserEntity,\n parseEntityRef,\n RELATION_HAS_MEMBER,\n RELATION_OWNED_BY,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nconst isUserEntityRef = (ref: string) =>\n parseEntityRef(ref).kind.toLocaleLowerCase() === 'user';\n\n// Partitions array of entity references to two arrays; user entity refs and other entity refs\nconst partitionEntityRefs = (refs: string[]): string[][] =>\n refs.reduce(\n ([userEntityRefs, otherEntityRefs]: string[][], ref: string) => {\n return isUserEntityRef(ref)\n ? [[...userEntityRefs, ref], otherEntityRefs]\n : [userEntityRefs, [...otherEntityRefs, ref]];\n },\n [[], []],\n );\n\nexport const getUsersForEntityRef = async (\n entityRef: string | string[] | null,\n excludeEntityRefs: string | string[],\n options: {\n auth: AuthService;\n catalog: CatalogService;\n },\n): Promise<string[]> => {\n const { auth, catalog } = options;\n\n if (entityRef === null) {\n return [];\n }\n\n const excluded = Array.isArray(excludeEntityRefs)\n ? excludeEntityRefs\n : [excludeEntityRefs];\n\n const refsArr = Array.isArray(entityRef) ? entityRef : [entityRef];\n const [userEntityRefs, otherEntityRefs] = partitionEntityRefs(refsArr);\n const users: string[] = userEntityRefs.filter(ref => !excluded.includes(ref));\n const entityRefs = otherEntityRefs.filter(ref => !excluded.includes(ref));\n\n const fields = ['kind', 'metadata.name', 'metadata.namespace', 'relations'];\n let entities: Array<Entity | undefined> = [];\n if (entityRefs.length > 0) {\n const fetchedEntities = await catalog.getEntitiesByRefs(\n {\n entityRefs,\n fields,\n },\n { credentials: await auth.getOwnServiceCredentials() },\n );\n entities = fetchedEntities.items;\n }\n\n const mapEntity = async (entity: Entity | undefined): Promise<string[]> => {\n if (!entity) {\n return [];\n }\n\n const currentEntityRef = stringifyEntityRef(entity);\n if (excluded.includes(currentEntityRef)) {\n return [];\n }\n\n if (isUserEntity(entity)) {\n return [currentEntityRef];\n }\n\n if (isGroupEntity(entity)) {\n if (!entity.relations?.length) {\n return [];\n }\n\n const groupUsers = entity.relations\n .filter(\n relation =>\n relation.type === RELATION_HAS_MEMBER &&\n isUserEntityRef(relation.targetRef),\n )\n .map(r => r.targetRef);\n\n const childGroupRefs = entity.relations\n .filter(relation => relation.type === RELATION_PARENT_OF)\n .map(r => r.targetRef);\n\n let childGroupUsers: string[][] = [];\n if (childGroupRefs.length > 0) {\n const childGroups = await catalog.getEntitiesByRefs(\n {\n entityRefs: childGroupRefs,\n fields,\n },\n { credentials: await auth.getOwnServiceCredentials() },\n );\n childGroupUsers = await Promise.all(childGroups.items.map(mapEntity));\n }\n\n return [...groupUsers, ...childGroupUsers.flat(2)].filter(\n ref => !excluded.includes(ref),\n );\n }\n\n if (entity.relations?.length) {\n const ownerRef = entity.relations.find(\n relation => relation.type === RELATION_OWNED_BY,\n )?.targetRef;\n\n if (!ownerRef) {\n return [];\n }\n\n if (isUserEntityRef(ownerRef)) {\n if (excluded.includes(ownerRef)) {\n return [];\n }\n return [ownerRef];\n }\n\n const owner = await catalog.getEntityByRef(ownerRef, {\n credentials: await auth.getOwnServiceCredentials(),\n });\n return mapEntity(owner);\n }\n\n return [];\n };\n\n for (const entity of entities) {\n const u = await mapEntity(entity);\n users.push(...u);\n }\n\n return [...new Set(users)].filter(Boolean);\n};\n"],"names":["parseEntityRef","stringifyEntityRef","isUserEntity","isGroupEntity","RELATION_HAS_MEMBER","RELATION_PARENT_OF","RELATION_OWNED_BY"],"mappings":";;;;AA6BA,MAAM,eAAA,GAAkB,CAAC,GAAA,KACvBA,2BAAA,CAAe,GAAG,CAAA,CAAE,IAAA,CAAK,mBAAkB,KAAM,MAAA;AAGnD,MAAM,mBAAA,GAAsB,CAAC,IAAA,KAC3B,IAAA,CAAK,MAAA;AAAA,EACH,CAAC,CAAC,cAAA,EAAgB,eAAe,GAAe,GAAA,KAAgB;AAC9D,IAAA,OAAO,gBAAgB,GAAG,CAAA,GACtB,CAAC,CAAC,GAAG,cAAA,EAAgB,GAAG,CAAA,EAAG,eAAe,IAC1C,CAAC,cAAA,EAAgB,CAAC,GAAG,eAAA,EAAiB,GAAG,CAAC,CAAA;AAAA,EAChD,CAAA;AAAA,EACA,CAAC,EAAC,EAAG,EAAE;AACT,CAAA;AAEK,MAAM,oBAAA,GAAuB,OAClC,SAAA,EACA,iBAAA,EACA,OAAA,KAIsB;AACtB,EAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAQ,GAAI,OAAA;AAE1B,EAAA,IAAI,cAAc,IAAA,EAAM;AACtB,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,iBAAiB,CAAA,GAC5C,iBAAA,GACA,CAAC,iBAAiB,CAAA;AAEtB,EAAA,MAAM,UAAU,KAAA,CAAM,OAAA,CAAQ,SAAS,CAAA,GAAI,SAAA,GAAY,CAAC,SAAS,CAAA;AACjE,EAAA,MAAM,CAAC,cAAA,EAAgB,eAAe,CAAA,GAAI,oB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AAA,CAAS,QAAQ,CAAA,EAAG;AAC/B,UAAA,OAAO,EAAC;AAAA,QACV;AACA,QAAA,OAAO,CAAC,QAAQ,CAAA;AAAA,MAClB;AAEA,MAAA,MAAM,KAAA,GAAQ,MAAM,OAAA,CAAQ,cAAA,CAAe,QAAA,EAAU;AAAA,QACnD,WAAA,EAAa,MAAM,IAAA,CAAK,wBAAA;AAAyB,OAClD,CAAA;AACD,MAAA,OAAO,UAAU,KAAK,CAAA;AAAA,IACxB;AAEA,IAAA,OAAO,EAAC;AAAA,EACV,CAAA;AAEA,EAAA,KAAA,MAAW,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,CAAA,GAAI,MAAM,SAAA,CAAU,MAAM,CAAA;AAChC,IAAA,KAAA,CAAM,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,EACjB;AAEA,EAAA,OAAO,CAAC,GAAG,IAAI,GAAA,CAAI,KAAK,CAAC,CAAA,CAAE,OAAO,OAAO,CAAA;AAC3C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEntityOrderFieldParams.cjs.js","sources":["../../src/service/parseEntityOrderFieldParams.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// This file is based on the plugins/catalog-backend\n\nimport { InputError } from '@backstage/errors';\nimport { EntityOrder } from '../database';\n\n/**\n * Takes a single unknown parameter and makes sure that it's a single string or\n * an array of strings, and returns as an array.\n */\nexport function parseStringsParam(\n param: unknown,\n ctx: string,\n): string[] | undefined {\n if (param === undefined) {\n return undefined;\n }\n\n const array = [param].flat();\n if (array.some(p => typeof p !== 'string')) {\n throw new InputError(`Invalid ${ctx}, not a string`);\n }\n\n return array as string[];\n}\n\nexport function parseEntityOrderFieldParams(\n params: Record<string, unknown>,\n): EntityOrder[] | undefined {\n const orderFieldStrings = parseStringsParam(params.orderField, 'orderField');\n if (!orderFieldStrings) {\n return undefined;\n }\n\n return orderFieldStrings.map(orderFieldString => {\n const [field, order] = orderFieldString.split(',');\n\n if (order !== undefined && !isOrder(order)) {\n throw new InputError('Invalid order field order, must be asc or desc');\n }\n return { field, order };\n });\n}\n\nexport function isOrder(order: string): order is 'asc' | 'desc' {\n return ['asc', 'desc'].includes(order);\n}\n"],"names":["InputError"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"parseEntityOrderFieldParams.cjs.js","sources":["../../src/service/parseEntityOrderFieldParams.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// This file is based on the plugins/catalog-backend\n\nimport { InputError } from '@backstage/errors';\nimport { EntityOrder } from '../database';\n\n/**\n * Takes a single unknown parameter and makes sure that it's a single string or\n * an array of strings, and returns as an array.\n */\nexport function parseStringsParam(\n param: unknown,\n ctx: string,\n): string[] | undefined {\n if (param === undefined) {\n return undefined;\n }\n\n const array = [param].flat();\n if (array.some(p => typeof p !== 'string')) {\n throw new InputError(`Invalid ${ctx}, not a string`);\n }\n\n return array as string[];\n}\n\nexport function parseEntityOrderFieldParams(\n params: Record<string, unknown>,\n): EntityOrder[] | undefined {\n const orderFieldStrings = parseStringsParam(params.orderField, 'orderField');\n if (!orderFieldStrings) {\n return undefined;\n }\n\n return orderFieldStrings.map(orderFieldString => {\n const [field, order] = orderFieldString.split(',');\n\n if (order !== undefined && !isOrder(order)) {\n throw new InputError('Invalid order field order, must be asc or desc');\n }\n return { field, order };\n });\n}\n\nexport function isOrder(order: string): order is 'asc' | 'desc' {\n return ['asc', 'desc'].includes(order);\n}\n"],"names":["InputError"],"mappings":";;;;AAyBO,SAAS,iBAAA,CACd,OACA,GAAA,EACsB;AACtB,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,KAAA,GAAQ,CAAC,KAAK,CAAA,CAAE,IAAA,EAAK;AAC3B,EAAA,IAAI,MAAM,IAAA,CAAK,CAAA,CAAA,KAAK,OAAO,CAAA,KAAM,QAAQ,CAAA,EAAG;AAC1C,IAAA,MAAM,IAAIA,iBAAA,CAAW,CAAA,QAAA,EAAW,GAAG,CAAA,cAAA,CAAgB,CAAA;AAAA,EACrD;AAEA,EAAA,OAAO,KAAA;AACT;AAEO,SAAS,4BACd,MAAA,EAC2B;AAC3B,EAAA,MAAM,iBAAA,GAAoB,iBAAA,CAAkB,MAAA,CAAO,UAAA,EAAY,YAAY,CAAA;AAC3E,EAAA,IAAI,CAAC,iBAAA,EAAmB;AACtB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAO,iBAAA,CAAkB,IAAI,CAAA,gBAAA,KAAoB;AAC/C,IAAA,MAAM,CAAC,KAAA,EAAO,KAAK,CAAA,GAAI,gBAAA,CAAiB,MAAM,GAAG,CAAA;AAEjD,IAAA,IAAI,KAAA,KAAU,MAAA,IAAa,CAAC,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC1C,MAAA,MAAM,IAAIA,kBAAW,gDAAgD,CAAA;AAAA,IACvE;AACA,IAAA,OAAO,EAAE,OAAO,KAAA,EAAM;AAAA,EACxB,CAAC,CAAA;AACH;AAEO,SAAS,QAAQ,KAAA,EAAwC;AAC9D,EAAA,OAAO,CAAC,KAAA,EAAO,MAAM,CAAA,CAAE,SAAS,KAAK,CAAA;AACvC;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.cjs.js","sources":["../../src/service/router.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport express, { Request, Response } from 'express';\nimport Router from 'express-promise-router';\nimport {\n normalizeSeverity,\n NotificationGetOptions,\n NotificationsStore,\n TopicGetOptions,\n} from '../database';\nimport { v4 as uuid } from 'uuid';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\nimport {\n NotificationProcessor,\n NotificationSendOptions,\n} from '@backstage/plugin-notifications-node';\nimport { InputError, NotFoundError } from '@backstage/errors';\nimport {\n AuthService,\n HttpAuthService,\n LoggerService,\n UserInfoService,\n} from '@backstage/backend-plugin-api';\nimport { SignalsService } from '@backstage/plugin-signals-node';\nimport {\n ChannelSetting,\n isNotificationsEnabledFor,\n NewNotificationSignal,\n Notification,\n NotificationReadSignal,\n NotificationSettings,\n notificationSeverities,\n NotificationStatus,\n OriginSetting,\n} from '@backstage/plugin-notifications-common';\nimport { parseEntityOrderFieldParams } from './parseEntityOrderFieldParams';\nimport { getUsersForEntityRef } from './getUsersForEntityRef';\nimport { Config, readDurationFromConfig } from '@backstage/config';\nimport { durationToMilliseconds } from '@backstage/types';\nimport pThrottle from 'p-throttle';\n\n/** @internal */\nexport interface RouterOptions {\n logger: LoggerService;\n config: Config;\n store: NotificationsStore;\n auth: AuthService;\n httpAuth: HttpAuthService;\n userInfo: UserInfoService;\n signals?: SignalsService;\n catalog: CatalogService;\n processors?: NotificationProcessor[];\n}\n\n/** @internal */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const {\n config,\n logger,\n store,\n auth,\n httpAuth,\n userInfo,\n catalog,\n processors = [],\n signals,\n } = options;\n\n const WEB_NOTIFICATION_CHANNEL = 'Web';\n const frontendBaseUrl = config.getString('app.baseUrl');\n const concurrencyLimit =\n config.getOptionalNumber('notifications.concurrencyLimit') ?? 10;\n const throttleInterval = config.has('notifications.throttleInterval')\n ? durationToMilliseconds(\n readDurationFromConfig(config, {\n key: 'notifications.throttleInterval',\n }),\n )\n : 50;\n const throttle = pThrottle({\n limit: concurrencyLimit,\n interval: throttleInterval,\n });\n const defaultNotificationSettings: NotificationSettings | undefined =\n config.getOptional<NotificationSettings>('notifications.defaultSettings');\n\n const getUser = async (req: Request<unknown>) => {\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n const info = await userInfo.getUserInfo(credentials);\n return info.userEntityRef;\n };\n\n const getNotificationChannels = () => {\n return [WEB_NOTIFICATION_CHANNEL, ...processors.map(p => p.getName())];\n };\n\n const getTopicSettings = (\n topic: any,\n existingOrigin: OriginSetting | undefined,\n defaultOriginSettings: OriginSetting | undefined,\n defaultEnabled: boolean,\n ) => {\n const existingTopic = existingOrigin?.topics?.find(\n t => t.id.toLowerCase() === topic.topic.toLowerCase(),\n );\n const defaultTopicSettings = defaultOriginSettings?.topics?.find(\n t => t.id.toLowerCase() === topic.topic.toLowerCase(),\n );\n\n return {\n id: topic.topic,\n enabled: existingTopic\n ? existingTopic.enabled\n : defaultTopicSettings?.enabled ?? defaultEnabled,\n };\n };\n\n const getOriginSettings = (\n originId: string,\n existingChannel: ChannelSetting | undefined,\n defaultChannelSettings: ChannelSetting | undefined,\n topics: { origin: string; topic: string }[],\n ) => {\n const existingOrigin = existingChannel?.origins?.find(\n o => o.id.toLowerCase() === originId.toLowerCase(),\n );\n\n const defaultOriginSettings = defaultChannelSettings?.origins?.find(\n c => c.id.toLowerCase() === originId.toLowerCase(),\n );\n\n const defaultEnabled = existingOrigin\n ? existingOrigin.enabled\n : defaultOriginSettings?.enabled ?? true;\n\n return {\n id: originId,\n enabled: defaultEnabled,\n topics: topics\n .filter(t => t.origin === originId)\n .map(t =>\n getTopicSettings(\n t,\n existingOrigin,\n defaultOriginSettings,\n defaultEnabled,\n ),\n ),\n };\n };\n\n const getChannelSettings = (\n channelId: string,\n settings: NotificationSettings,\n origins: string[],\n topics: { origin: string; topic: string }[],\n ) => {\n const existingChannel = settings.channels.find(\n c => c.id.toLowerCase() === channelId.toLowerCase(),\n );\n const defaultChannelSettings = defaultNotificationSettings?.channels?.find(\n c => c.id.toLowerCase() === channelId.toLowerCase(),\n );\n\n return {\n id: channelId,\n origins: origins.map(originId =>\n getOriginSettings(\n originId,\n existingChannel,\n defaultChannelSettings,\n topics,\n ),\n ),\n };\n };\n\n const getNotificationSettings = async (\n user: string,\n ): Promise<NotificationSettings> => {\n const { origins } = await store.getUserNotificationOrigins({ user });\n const { topics } = await store.getUserNotificationTopics({ user });\n const settings = await store.getNotificationSettings({ user });\n const channels = getNotificationChannels();\n\n return {\n channels: channels.map(channelId =>\n getChannelSettings(channelId, settings, origins, topics),\n ),\n };\n };\n\n const isNotificationsEnabled = async (opts: {\n user: string;\n channel: string;\n origin: string;\n topic: string | null;\n }) => {\n const settings = await getNotificationSettings(opts.user);\n return isNotificationsEnabledFor(\n settings,\n opts.channel,\n opts.origin,\n opts.topic,\n );\n };\n\n const filterProcessors = async (\n notification:\n | Notification\n | ({ origin: string; user: null } & NotificationSendOptions),\n ) => {\n const result: NotificationProcessor[] = [];\n const { payload, user, origin } = notification;\n\n for (const processor of processors) {\n if (user) {\n const enabled = await isNotificationsEnabled({\n user,\n origin,\n channel: processor.getName(),\n topic: payload.topic ?? null,\n });\n if (!enabled) {\n continue;\n }\n }\n\n if (processor.getNotificationFilters) {\n const filters = processor.getNotificationFilters();\n if (filters.minSeverity) {\n if (\n notificationSeverities.indexOf(payload.severity ?? 'normal') >\n notificationSeverities.indexOf(filters.minSeverity)\n ) {\n continue;\n }\n }\n\n if (filters.maxSeverity) {\n if (\n notificationSeverities.indexOf(payload.severity ?? 'normal') <\n notificationSeverities.indexOf(filters.maxSeverity)\n ) {\n continue;\n }\n }\n\n if (filters.excludedTopics && payload.topic) {\n if (filters.excludedTopics.includes(payload.topic)) {\n continue;\n }\n }\n }\n result.push(processor);\n }\n\n return result;\n };\n\n const processOptions = async (\n opts: NotificationSendOptions,\n origin: string,\n ): Promise<NotificationSendOptions> => {\n const filtered = await filterProcessors({ ...opts, origin, user: null });\n let ret = opts;\n for (const processor of filtered) {\n try {\n ret = processor.processOptions\n ? await processor.processOptions(ret)\n : ret;\n } catch (e) {\n logger.error(\n `Error while processing notification options with ${processor.getName()}: ${e}`,\n );\n }\n }\n return ret;\n };\n\n const preProcessNotification = async (\n notification: Notification,\n opts: NotificationSendOptions,\n ) => {\n const filtered = await filterProcessors(notification);\n let ret = notification;\n for (const processor of filtered) {\n try {\n ret = processor.preProcess\n ? await processor.preProcess(ret, opts)\n : ret;\n } catch (e) {\n logger.error(\n `Error while pre processing notification with ${processor.getName()}: ${e}`,\n );\n }\n }\n return ret;\n };\n\n const postProcessNotification = async (\n notification: Notification,\n opts: NotificationSendOptions,\n ) => {\n const filtered = await filterProcessors(notification);\n for (const processor of filtered) {\n if (processor.postProcess) {\n try {\n await processor.postProcess(notification, opts);\n } catch (e) {\n logger.error(\n `Error while post processing notification with ${processor.getName()}: ${e}`,\n );\n }\n }\n }\n };\n\n const validateLink = (link: string) => {\n const stripLeadingSlash = (s: string) => s.replace(/^\\//, '');\n const ensureTrailingSlash = (s: string) => s.replace(/\\/?$/, '/');\n const url = new URL(\n stripLeadingSlash(link),\n ensureTrailingSlash(frontendBaseUrl),\n );\n if (url.protocol !== 'https:' && url.protocol !== 'http:') {\n throw new Error('Only HTTP/HTTPS links are allowed');\n }\n };\n\n const appendCommonOptions = (\n req: Request,\n opts: NotificationGetOptions | TopicGetOptions,\n ) => {\n if (req.query.search) {\n opts.search = req.query.search.toString();\n }\n if (req.query.read === 'true') {\n opts.read = true;\n } else if (req.query.read === 'false') {\n opts.read = false;\n // or keep undefined\n }\n\n if (req.query.saved === 'true') {\n opts.saved = true;\n } else if (req.query.saved === 'false') {\n opts.saved = false;\n // or keep undefined\n }\n if (req.query.createdAfter) {\n const sinceEpoch = Date.parse(String(req.query.createdAfter));\n if (isNaN(sinceEpoch)) {\n throw new InputError('Unexpected date format');\n }\n opts.createdAfter = new Date(sinceEpoch);\n }\n if (req.query.minimumSeverity) {\n opts.minimumSeverity = normalizeSeverity(\n req.query.minimumSeverity.toString(),\n );\n }\n };\n\n // TODO: Move to use OpenAPI router instead\n const router = Router();\n router.use(express.json());\n\n const listNotificationsHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const opts: NotificationGetOptions = {\n user: user,\n };\n if (req.query.offset) {\n opts.offset = Number.parseInt(req.query.offset.toString(), 10);\n }\n if (req.query.limit) {\n opts.limit = Number.parseInt(req.query.limit.toString(), 10);\n }\n if (req.query.orderField) {\n opts.orderField = parseEntityOrderFieldParams(req.query);\n }\n\n if (req.query.topic) {\n opts.topic = req.query.topic.toString();\n }\n\n appendCommonOptions(req, opts);\n\n const [notifications, totalCount] = await Promise.all([\n store.getNotifications(opts),\n store.getNotificationsCount(opts),\n ]);\n res.json({\n totalCount,\n notifications,\n });\n };\n\n router.get('/', listNotificationsHandler); // Deprecated endpoint\n router.get('/notifications', listNotificationsHandler);\n\n router.get('/status', async (req: Request<any, NotificationStatus>, res) => {\n const user = await getUser(req);\n const status = await store.getStatus({ user });\n res.json(status);\n });\n\n router.get(\n '/settings',\n async (req: Request<any, NotificationSettings>, res) => {\n const user = await getUser(req);\n const response = await getNotificationSettings(user);\n res.json(response);\n },\n );\n\n router.post(\n '/settings',\n async (\n req: Request<any, NotificationSettings, NotificationSettings>,\n res,\n ) => {\n const user = await getUser(req);\n const channels = getNotificationChannels();\n const settings: NotificationSettings = req.body;\n if (settings.channels.some(c => !channels.includes(c.id))) {\n throw new InputError('Invalid channel');\n }\n await store.saveNotificationSettings({ user, settings });\n const response = await getNotificationSettings(user);\n res.json(response);\n },\n );\n\n const getNotificationHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const opts: NotificationGetOptions = {\n user: user,\n limit: 1,\n ids: [req.params.id],\n };\n const notifications = await store.getNotifications(opts);\n if (notifications.length !== 1) {\n throw new NotFoundError('Not found');\n }\n res.json(notifications[0]);\n };\n\n // Get topics\n const listTopicsHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const opts: TopicGetOptions = {\n user: user,\n };\n\n appendCommonOptions(req, opts);\n\n const topics = await store.getTopics(opts);\n res.json(topics);\n };\n\n router.get('/topics', listTopicsHandler);\n\n // Make sure this is the last \"GET\" handler\n router.get('/:id', getNotificationHandler); // Deprecated endpoint\n router.get('/notifications/:id', getNotificationHandler);\n\n const updateNotificationsHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const { ids, read, saved } = req.body;\n if (!ids || !Array.isArray(ids)) {\n throw new InputError();\n }\n\n if (read === true) {\n await store.markRead({ user, ids });\n\n if (signals) {\n await signals.publish<NotificationReadSignal>({\n recipients: { type: 'user', entityRef: [user] },\n message: { action: 'notification_read', notification_ids: ids },\n channel: 'notifications',\n });\n }\n } else if (read === false) {\n await store.markUnread({ user: user, ids });\n\n if (signals) {\n await signals.publish<NotificationReadSignal>({\n recipients: { type: 'user', entityRef: [user] },\n message: { action: 'notification_unread', notification_ids: ids },\n channel: 'notifications',\n });\n }\n }\n\n if (saved === true) {\n await store.markSaved({ user: user, ids });\n } else if (saved === false) {\n await store.markUnsaved({ user: user, ids });\n }\n\n const notifications = await store.getNotifications({ ids, user: user });\n res.json(notifications);\n };\n\n router.post('/update', updateNotificationsHandler); // Deprecated endpoint\n router.post('/notifications/update', updateNotificationsHandler);\n\n const sendBroadcastNotification = async (\n baseNotification: Omit<Notification, 'user' | 'id'>,\n opts: NotificationSendOptions,\n origin: string,\n ) => {\n const { scope } = opts.payload;\n const broadcastNotification = {\n ...baseNotification,\n user: null,\n id: uuid(),\n };\n const notification = await preProcessNotification(\n broadcastNotification,\n opts,\n );\n let existingNotification;\n if (scope) {\n existingNotification = await store.getExistingScopeBroadcast({\n scope,\n origin,\n });\n }\n\n let ret = notification;\n if (existingNotification) {\n const restored = await store.restoreExistingNotification({\n id: existingNotification.id,\n notification: { ...notification, user: '' },\n });\n ret = restored ?? notification;\n } else {\n await store.saveBroadcast(notification);\n }\n\n if (signals) {\n await signals.publish<NewNotificationSignal>({\n recipients: { type: 'broadcast' },\n message: {\n action: 'new_notification',\n notification_id: ret.id,\n },\n channel: 'notifications',\n });\n }\n postProcessNotification(ret, opts);\n return notification;\n };\n\n const sendUserNotification = async (\n baseNotification: Omit<Notification, 'user' | 'id'>,\n user: string,\n opts: NotificationSendOptions,\n origin: string,\n scope?: string,\n ): Promise<Notification | undefined> => {\n const userNotification = {\n ...baseNotification,\n id: uuid(),\n user,\n };\n const notification = await preProcessNotification(userNotification, opts);\n\n const enabled = await isNotificationsEnabled({\n user,\n channel: WEB_NOTIFICATION_CHANNEL,\n origin: userNotification.origin,\n topic: userNotification.payload.topic ?? null,\n });\n\n let ret = notification;\n\n if (!enabled) {\n postProcessNotification(ret, opts);\n return undefined;\n }\n\n let existingNotification;\n if (scope) {\n existingNotification = await store.getExistingScopeNotification({\n user,\n scope,\n origin,\n });\n }\n\n if (existingNotification) {\n const restored = await store.restoreExistingNotification({\n id: existingNotification.id,\n notification,\n });\n ret = restored ?? notification;\n } else {\n await store.saveNotification(notification);\n }\n\n if (signals) {\n await signals.publish<NewNotificationSignal>({\n recipients: { type: 'user', entityRef: [user] },\n message: {\n action: 'new_notification',\n notification_id: ret.id,\n },\n channel: 'notifications',\n });\n }\n postProcessNotification(ret, opts);\n return ret;\n };\n\n const sendUserNotifications = async (\n baseNotification: Omit<Notification, 'user' | 'id'>,\n users: string[],\n opts: NotificationSendOptions,\n origin: string,\n ): Promise<Notification[]> => {\n const { scope } = opts.payload;\n const uniqueUsers = [...new Set(users)];\n const throttled = throttle((user: string) =>\n sendUserNotification(baseNotification, user, opts, origin, scope),\n );\n const sent = await Promise.all(uniqueUsers.map(user => throttled(user)));\n return sent.filter(n => n !== undefined);\n };\n\n const createNotificationHandler = async (\n req: Request<any, Notification[], NotificationSendOptions>,\n res: Response,\n ) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n\n const origin = credentials.principal.subject;\n const opts = await processOptions(req.body, origin);\n const { recipients, payload } = opts;\n const { title, link } = payload;\n const notifications: Notification[] = [];\n let users = [];\n\n if (!recipients || !title) {\n const missing = [\n !title ? 'title' : null,\n !recipients ? 'recipients' : null,\n ].filter(Boolean);\n const err = `Invalid notification request received: missing ${missing.join(\n ', ',\n )}`;\n throw new InputError(err);\n }\n\n if (link) {\n try {\n validateLink(link);\n } catch (e) {\n throw new InputError('Invalid link provided', e);\n }\n }\n\n const baseNotification = {\n payload: {\n ...payload,\n severity: payload.severity ?? 'normal',\n },\n origin,\n created: new Date(),\n };\n\n if (recipients.type === 'broadcast') {\n const broadcast = await sendBroadcastNotification(\n baseNotification,\n opts,\n origin,\n );\n notifications.push(broadcast);\n } else if (recipients.type === 'entity') {\n const entityRef = recipients.entityRef;\n\n try {\n users = await getUsersForEntityRef(\n entityRef,\n recipients.excludeEntityRef ?? [],\n { auth, catalog },\n );\n } catch (e) {\n throw new InputError('Failed to resolve notification receivers', e);\n }\n\n const userNotifications = await sendUserNotifications(\n baseNotification,\n users,\n opts,\n origin,\n );\n notifications.push(...userNotifications);\n } else {\n throw new InputError(\n `Invalid recipients type, please use either 'broadcast' or 'entity'`,\n );\n }\n\n res.json(notifications);\n };\n\n // Add new notification\n router.post('/', createNotificationHandler);\n router.post('/notifications', createNotificationHandler);\n\n return router;\n}\n"],"names":["config","durationToMilliseconds","readDurationFromConfig","pThrottle","isNotificationsEnabledFor","notificationSeverities","InputError","normalizeSeverity","Router","express","parseE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AAoB,MAAM,qBAAA;AAAA,QAC9B,gBAAA;AAAA,QACA,KAAA;AAAA,QACA,IAAA;AAAA,QACA;AAAA,OACF;AACA,MAAc,aAAA,CAAA,IAAA,CAAK,GAAG,iBAAiB,CAAA;AAAA,KAClC,MAAA;AACL,MAAA,MAAM,IAAIA,iBAAA;AAAA,QACR,CAAA,kEAAA;AAAA,OACF;AAAA;AAGF,IAAA,GAAA,CAAI,KAAK,aAAa,CAAA;AAAA,GACxB;AAGA,EAAO,MAAA,CAAA,IAAA,CAAK,KAAK,yBAAyB,CAAA;AAC1C,EAAO,MAAA,CAAA,IAAA,CAAK,kBAAkB,yBAAyB,CAAA;AAEvD,EAAO,OAAA,MAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../../src/service/router.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport express, { Request, Response } from 'express';\nimport Router from 'express-promise-router';\nimport {\n normalizeSeverity,\n NotificationGetOptions,\n NotificationsStore,\n TopicGetOptions,\n} from '../database';\nimport { v4 as uuid } from 'uuid';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\nimport {\n NotificationProcessor,\n NotificationSendOptions,\n} from '@backstage/plugin-notifications-node';\nimport { InputError, NotFoundError } from '@backstage/errors';\nimport {\n AuthService,\n HttpAuthService,\n LoggerService,\n UserInfoService,\n} from '@backstage/backend-plugin-api';\nimport { SignalsService } from '@backstage/plugin-signals-node';\nimport {\n ChannelSetting,\n isNotificationsEnabledFor,\n NewNotificationSignal,\n Notification,\n NotificationReadSignal,\n NotificationSettings,\n notificationSeverities,\n NotificationStatus,\n OriginSetting,\n} from '@backstage/plugin-notifications-common';\nimport { parseEntityOrderFieldParams } from './parseEntityOrderFieldParams';\nimport { getUsersForEntityRef } from './getUsersForEntityRef';\nimport { Config, readDurationFromConfig } from '@backstage/config';\nimport { durationToMilliseconds } from '@backstage/types';\nimport pThrottle from 'p-throttle';\n\n/** @internal */\nexport interface RouterOptions {\n logger: LoggerService;\n config: Config;\n store: NotificationsStore;\n auth: AuthService;\n httpAuth: HttpAuthService;\n userInfo: UserInfoService;\n signals?: SignalsService;\n catalog: CatalogService;\n processors?: NotificationProcessor[];\n}\n\n/** @internal */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const {\n config,\n logger,\n store,\n auth,\n httpAuth,\n userInfo,\n catalog,\n processors = [],\n signals,\n } = options;\n\n const WEB_NOTIFICATION_CHANNEL = 'Web';\n const frontendBaseUrl = config.getString('app.baseUrl');\n const concurrencyLimit =\n config.getOptionalNumber('notifications.concurrencyLimit') ?? 10;\n const throttleInterval = config.has('notifications.throttleInterval')\n ? durationToMilliseconds(\n readDurationFromConfig(config, {\n key: 'notifications.throttleInterval',\n }),\n )\n : 50;\n const throttle = pThrottle({\n limit: concurrencyLimit,\n interval: throttleInterval,\n });\n const defaultNotificationSettings: NotificationSettings | undefined =\n config.getOptional<NotificationSettings>('notifications.defaultSettings');\n\n const getUser = async (req: Request<unknown>) => {\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n const info = await userInfo.getUserInfo(credentials);\n return info.userEntityRef;\n };\n\n const getNotificationChannels = () => {\n return [WEB_NOTIFICATION_CHANNEL, ...processors.map(p => p.getName())];\n };\n\n const getTopicSettings = (\n topic: any,\n existingOrigin: OriginSetting | undefined,\n defaultOriginSettings: OriginSetting | undefined,\n defaultEnabled: boolean,\n ) => {\n const existingTopic = existingOrigin?.topics?.find(\n t => t.id.toLowerCase() === topic.topic.toLowerCase(),\n );\n const defaultTopicSettings = defaultOriginSettings?.topics?.find(\n t => t.id.toLowerCase() === topic.topic.toLowerCase(),\n );\n\n return {\n id: topic.topic,\n enabled: existingTopic\n ? existingTopic.enabled\n : defaultTopicSettings?.enabled ?? defaultEnabled,\n };\n };\n\n const getOriginSettings = (\n originId: string,\n existingChannel: ChannelSetting | undefined,\n defaultChannelSettings: ChannelSetting | undefined,\n topics: { origin: string; topic: string }[],\n ) => {\n const existingOrigin = existingChannel?.origins?.find(\n o => o.id.toLowerCase() === originId.toLowerCase(),\n );\n\n const defaultOriginSettings = defaultChannelSettings?.origins?.find(\n c => c.id.toLowerCase() === originId.toLowerCase(),\n );\n\n const defaultEnabled = existingOrigin\n ? existingOrigin.enabled\n : defaultOriginSettings?.enabled ?? true;\n\n return {\n id: originId,\n enabled: defaultEnabled,\n topics: topics\n .filter(t => t.origin === originId)\n .map(t =>\n getTopicSettings(\n t,\n existingOrigin,\n defaultOriginSettings,\n defaultEnabled,\n ),\n ),\n };\n };\n\n const getChannelSettings = (\n channelId: string,\n settings: NotificationSettings,\n origins: string[],\n topics: { origin: string; topic: string }[],\n ) => {\n const existingChannel = settings.channels.find(\n c => c.id.toLowerCase() === channelId.toLowerCase(),\n );\n const defaultChannelSettings = defaultNotificationSettings?.channels?.find(\n c => c.id.toLowerCase() === channelId.toLowerCase(),\n );\n\n return {\n id: channelId,\n origins: origins.map(originId =>\n getOriginSettings(\n originId,\n existingChannel,\n defaultChannelSettings,\n topics,\n ),\n ),\n };\n };\n\n const getNotificationSettings = async (\n user: string,\n ): Promise<NotificationSettings> => {\n const { origins } = await store.getUserNotificationOrigins({ user });\n const { topics } = await store.getUserNotificationTopics({ user });\n const settings = await store.getNotificationSettings({ user });\n const channels = getNotificationChannels();\n\n return {\n channels: channels.map(channelId =>\n getChannelSettings(channelId, settings, origins, topics),\n ),\n };\n };\n\n const isNotificationsEnabled = async (opts: {\n user: string;\n channel: string;\n origin: string;\n topic: string | null;\n }) => {\n const settings = await getNotificationSettings(opts.user);\n return isNotificationsEnabledFor(\n settings,\n opts.channel,\n opts.origin,\n opts.topic,\n );\n };\n\n const filterProcessors = async (\n notification:\n | Notification\n | ({ origin: string; user: null } & NotificationSendOptions),\n ) => {\n const result: NotificationProcessor[] = [];\n const { payload, user, origin } = notification;\n\n for (const processor of processors) {\n if (user) {\n const enabled = await isNotificationsEnabled({\n user,\n origin,\n channel: processor.getName(),\n topic: payload.topic ?? null,\n });\n if (!enabled) {\n continue;\n }\n }\n\n if (processor.getNotificationFilters) {\n const filters = processor.getNotificationFilters();\n if (filters.minSeverity) {\n if (\n notificationSeverities.indexOf(payload.severity ?? 'normal') >\n notificationSeverities.indexOf(filters.minSeverity)\n ) {\n continue;\n }\n }\n\n if (filters.maxSeverity) {\n if (\n notificationSeverities.indexOf(payload.severity ?? 'normal') <\n notificationSeverities.indexOf(filters.maxSeverity)\n ) {\n continue;\n }\n }\n\n if (filters.excludedTopics && payload.topic) {\n if (filters.excludedTopics.includes(payload.topic)) {\n continue;\n }\n }\n }\n result.push(processor);\n }\n\n return result;\n };\n\n const processOptions = async (\n opts: NotificationSendOptions,\n origin: string,\n ): Promise<NotificationSendOptions> => {\n const filtered = await filterProcessors({ ...opts, origin, user: null });\n let ret = opts;\n for (const processor of filtered) {\n try {\n ret = processor.processOptions\n ? await processor.processOptions(ret)\n : ret;\n } catch (e) {\n logger.error(\n `Error while processing notification options with ${processor.getName()}: ${e}`,\n );\n }\n }\n return ret;\n };\n\n const preProcessNotification = async (\n notification: Notification,\n opts: NotificationSendOptions,\n ) => {\n const filtered = await filterProcessors(notification);\n let ret = notification;\n for (const processor of filtered) {\n try {\n ret = processor.preProcess\n ? await processor.preProcess(ret, opts)\n : ret;\n } catch (e) {\n logger.error(\n `Error while pre processing notification with ${processor.getName()}: ${e}`,\n );\n }\n }\n return ret;\n };\n\n const postProcessNotification = async (\n notification: Notification,\n opts: NotificationSendOptions,\n ) => {\n const filtered = await filterProcessors(notification);\n for (const processor of filtered) {\n if (processor.postProcess) {\n try {\n await processor.postProcess(notification, opts);\n } catch (e) {\n logger.error(\n `Error while post processing notification with ${processor.getName()}: ${e}`,\n );\n }\n }\n }\n };\n\n const validateLink = (link: string) => {\n const stripLeadingSlash = (s: string) => s.replace(/^\\//, '');\n const ensureTrailingSlash = (s: string) => s.replace(/\\/?$/, '/');\n const url = new URL(\n stripLeadingSlash(link),\n ensureTrailingSlash(frontendBaseUrl),\n );\n if (url.protocol !== 'https:' && url.protocol !== 'http:') {\n throw new Error('Only HTTP/HTTPS links are allowed');\n }\n };\n\n const appendCommonOptions = (\n req: Request,\n opts: NotificationGetOptions | TopicGetOptions,\n ) => {\n if (req.query.search) {\n opts.search = req.query.search.toString();\n }\n if (req.query.read === 'true') {\n opts.read = true;\n } else if (req.query.read === 'false') {\n opts.read = false;\n // or keep undefined\n }\n\n if (req.query.saved === 'true') {\n opts.saved = true;\n } else if (req.query.saved === 'false') {\n opts.saved = false;\n // or keep undefined\n }\n if (req.query.createdAfter) {\n const sinceEpoch = Date.parse(String(req.query.createdAfter));\n if (isNaN(sinceEpoch)) {\n throw new InputError('Unexpected date format');\n }\n opts.createdAfter = new Date(sinceEpoch);\n }\n if (req.query.minimumSeverity) {\n opts.minimumSeverity = normalizeSeverity(\n req.query.minimumSeverity.toString(),\n );\n }\n };\n\n // TODO: Move to use OpenAPI router instead\n const router = Router();\n router.use(express.json());\n\n const listNotificationsHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const opts: NotificationGetOptions = {\n user: user,\n };\n if (req.query.offset) {\n opts.offset = Number.parseInt(req.query.offset.toString(), 10);\n }\n if (req.query.limit) {\n opts.limit = Number.parseInt(req.query.limit.toString(), 10);\n }\n if (req.query.orderField) {\n opts.orderField = parseEntityOrderFieldParams(req.query);\n }\n\n if (req.query.topic) {\n opts.topic = req.query.topic.toString();\n }\n\n appendCommonOptions(req, opts);\n\n const [notifications, totalCount] = await Promise.all([\n store.getNotifications(opts),\n store.getNotificationsCount(opts),\n ]);\n res.json({\n totalCount,\n notifications,\n });\n };\n\n router.get('/', listNotificationsHandler); // Deprecated endpoint\n router.get('/notifications', listNotificationsHandler);\n\n router.get('/status', async (req: Request<any, NotificationStatus>, res) => {\n const user = await getUser(req);\n const status = await store.getStatus({ user });\n res.json(status);\n });\n\n router.get(\n '/settings',\n async (req: Request<any, NotificationSettings>, res) => {\n const user = await getUser(req);\n const response = await getNotificationSettings(user);\n res.json(response);\n },\n );\n\n router.post(\n '/settings',\n async (\n req: Request<any, NotificationSettings, NotificationSettings>,\n res,\n ) => {\n const user = await getUser(req);\n const channels = getNotificationChannels();\n const settings: NotificationSettings = req.body;\n if (settings.channels.some(c => !channels.includes(c.id))) {\n throw new InputError('Invalid channel');\n }\n await store.saveNotificationSettings({ user, settings });\n const response = await getNotificationSettings(user);\n res.json(response);\n },\n );\n\n const getNotificationHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const opts: NotificationGetOptions = {\n user: user,\n limit: 1,\n ids: [req.params.id],\n };\n const notifications = await store.getNotifications(opts);\n if (notifications.length !== 1) {\n throw new NotFoundError('Not found');\n }\n res.json(notifications[0]);\n };\n\n // Get topics\n const listTopicsHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const opts: TopicGetOptions = {\n user: user,\n };\n\n appendCommonOptions(req, opts);\n\n const topics = await store.getTopics(opts);\n res.json(topics);\n };\n\n router.get('/topics', listTopicsHandler);\n\n // Make sure this is the last \"GET\" handler\n router.get('/:id', getNotificationHandler); // Deprecated endpoint\n router.get('/notifications/:id', getNotificationHandler);\n\n const updateNotificationsHandler = async (req: Request, res: Response) => {\n const user = await getUser(req);\n const { ids, read, saved } = req.body;\n if (!ids || !Array.isArray(ids)) {\n throw new InputError();\n }\n\n if (read === true) {\n await store.markRead({ user, ids });\n\n if (signals) {\n await signals.publish<NotificationReadSignal>({\n recipients: { type: 'user', entityRef: [user] },\n message: { action: 'notification_read', notification_ids: ids },\n channel: 'notifications',\n });\n }\n } else if (read === false) {\n await store.markUnread({ user: user, ids });\n\n if (signals) {\n await signals.publish<NotificationReadSignal>({\n recipients: { type: 'user', entityRef: [user] },\n message: { action: 'notification_unread', notification_ids: ids },\n channel: 'notifications',\n });\n }\n }\n\n if (saved === true) {\n await store.markSaved({ user: user, ids });\n } else if (saved === false) {\n await store.markUnsaved({ user: user, ids });\n }\n\n const notifications = await store.getNotifications({ ids, user: user });\n res.json(notifications);\n };\n\n router.post('/update', updateNotificationsHandler); // Deprecated endpoint\n router.post('/notifications/update', updateNotificationsHandler);\n\n const sendBroadcastNotification = async (\n baseNotification: Omit<Notification, 'user' | 'id'>,\n opts: NotificationSendOptions,\n origin: string,\n ) => {\n const { scope } = opts.payload;\n const broadcastNotification = {\n ...baseNotification,\n user: null,\n id: uuid(),\n };\n const notification = await preProcessNotification(\n broadcastNotification,\n opts,\n );\n let existingNotification;\n if (scope) {\n existingNotification = await store.getExistingScopeBroadcast({\n scope,\n origin,\n });\n }\n\n let ret = notification;\n if (existingNotification) {\n const restored = await store.restoreExistingNotification({\n id: existingNotification.id,\n notification: { ...notification, user: '' },\n });\n ret = restored ?? notification;\n } else {\n await store.saveBroadcast(notification);\n }\n\n if (signals) {\n await signals.publish<NewNotificationSignal>({\n recipients: { type: 'broadcast' },\n message: {\n action: 'new_notification',\n notification_id: ret.id,\n },\n channel: 'notifications',\n });\n }\n postProcessNotification(ret, opts);\n return notification;\n };\n\n const sendUserNotification = async (\n baseNotification: Omit<Notification, 'user' | 'id'>,\n user: string,\n opts: NotificationSendOptions,\n origin: string,\n scope?: string,\n ): Promise<Notification | undefined> => {\n const userNotification = {\n ...baseNotification,\n id: uuid(),\n user,\n };\n const notification = await preProcessNotification(userNotification, opts);\n\n const enabled = await isNotificationsEnabled({\n user,\n channel: WEB_NOTIFICATION_CHANNEL,\n origin: userNotification.origin,\n topic: userNotification.payload.topic ?? null,\n });\n\n let ret = notification;\n\n if (!enabled) {\n postProcessNotification(ret, opts);\n return undefined;\n }\n\n let existingNotification;\n if (scope) {\n existingNotification = await store.getExistingScopeNotification({\n user,\n scope,\n origin,\n });\n }\n\n if (existingNotification) {\n const restored = await store.restoreExistingNotification({\n id: existingNotification.id,\n notification,\n });\n ret = restored ?? notification;\n } else {\n await store.saveNotification(notification);\n }\n\n if (signals) {\n await signals.publish<NewNotificationSignal>({\n recipients: { type: 'user', entityRef: [user] },\n message: {\n action: 'new_notification',\n notification_id: ret.id,\n },\n channel: 'notifications',\n });\n }\n postProcessNotification(ret, opts);\n return ret;\n };\n\n const sendUserNotifications = async (\n baseNotification: Omit<Notification, 'user' | 'id'>,\n users: string[],\n opts: NotificationSendOptions,\n origin: string,\n ): Promise<Notification[]> => {\n const { scope } = opts.payload;\n const uniqueUsers = [...new Set(users)];\n const throttled = throttle((user: string) =>\n sendUserNotification(baseNotification, user, opts, origin, scope),\n );\n const sent = await Promise.all(uniqueUsers.map(user => throttled(user)));\n return sent.filter(n => n !== undefined);\n };\n\n const createNotificationHandler = async (\n req: Request<any, Notification[], NotificationSendOptions>,\n res: Response,\n ) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n\n const origin = credentials.principal.subject;\n const opts = await processOptions(req.body, origin);\n const { recipients, payload } = opts;\n const { title, link } = payload;\n const notifications: Notification[] = [];\n let users = [];\n\n if (!recipients || !title) {\n const missing = [\n !title ? 'title' : null,\n !recipients ? 'recipients' : null,\n ].filter(Boolean);\n const err = `Invalid notification request received: missing ${missing.join(\n ', ',\n )}`;\n throw new InputError(err);\n }\n\n if (link) {\n try {\n validateLink(link);\n } catch (e) {\n throw new InputError('Invalid link provided', e);\n }\n }\n\n const baseNotification = {\n payload: {\n ...payload,\n severity: payload.severity ?? 'normal',\n },\n origin,\n created: new Date(),\n };\n\n if (recipients.type === 'broadcast') {\n const broadcast = await sendBroadcastNotification(\n baseNotification,\n opts,\n origin,\n );\n notifications.push(broadcast);\n } else if (recipients.type === 'entity') {\n const entityRef = recipients.entityRef;\n\n try {\n users = await getUsersForEntityRef(\n entityRef,\n recipients.excludeEntityRef ?? [],\n { auth, catalog },\n );\n } catch (e) {\n throw new InputError('Failed to resolve notification receivers', e);\n }\n\n const userNotifications = await sendUserNotifications(\n baseNotification,\n users,\n opts,\n origin,\n );\n notifications.push(...userNotifications);\n } else {\n throw new InputError(\n `Invalid recipients type, please use either 'broadcast' or 'entity'`,\n );\n }\n\n res.json(notifications);\n };\n\n // Add new notification\n router.post('/', createNotificationHandler);\n router.post('/notifications', createNotificationHandler);\n\n return router;\n}\n"],"names":["config","durationToMilliseconds","readDurationFromConfig","pThrottle","isNotificationsEnabledFor","notificationSeverities","InputError","normalizeSeverity","Router","express","parseEntityOrderFieldParams","NotFoundError","uuid","getUsersForEntityRef"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqEA,eAAsB,aACpB,OAAA,EACyB;AACzB,EAAA,MAAM;AAAA,YACJA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA;AAAA,IACA,aAAa,EAAC;AAAA,IACd;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,wBAAA,GAA2B,KAAA;AACjC,EAAA,MAAM,eAAA,GAAkBA,QAAA,CAAO,SAAA,CAAU,aAAa,CAAA;AACtD,EAAA,MAAM,gBAAA,GACJA,QAAA,CAAO,iBAAA,CAAkB,gCAAgC,CAAA,IAAK,EAAA;AAChE,EAAA,MAAM,gBAAA,GAAmBA,QAAA,CAAO,GAAA,CAAI,gCAAgC,CAAA,GAChEC,4BAAA;AAAA,IACEC,8BAAuBF,QAAA,EAAQ;AAAA,MAC7B,GAAA,EAAK;AAAA,KACN;AAAA,GACH,GACA,EAAA;AACJ,EAAA,MAAM,WAAWG,0BAAA,CAAU;AAAA,IACzB,KAAA,EAAO,gBAAA;AAAA,IACP,QAAA,EAAU;AAAA,GACX,CAAA;AACD,EAAA,MAAM,2BAAA,GACJH,QAAA,CAAO,WAAA,CAAkC,+BAA+B,CAAA;AAE1E,EAAA,MAAM,OAAA,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AO,MAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-notifications-backend",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "backend-plugin",
|
|
6
6
|
"pluginId": "notifications",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"test": "backstage-cli package test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@backstage/backend-plugin-api": "^1.4.
|
|
45
|
+
"@backstage/backend-plugin-api": "^1.4.2",
|
|
46
46
|
"@backstage/catalog-model": "^1.7.5",
|
|
47
47
|
"@backstage/config": "^1.3.3",
|
|
48
48
|
"@backstage/errors": "^1.2.7",
|
|
49
|
-
"@backstage/plugin-auth-node": "^0.6.
|
|
50
|
-
"@backstage/plugin-catalog-node": "^1.
|
|
51
|
-
"@backstage/plugin-events-node": "^0.4.
|
|
52
|
-
"@backstage/plugin-notifications-common": "^0.0
|
|
53
|
-
"@backstage/plugin-notifications-node": "^0.2.
|
|
54
|
-
"@backstage/plugin-signals-node": "^0.1.
|
|
49
|
+
"@backstage/plugin-auth-node": "^0.6.6",
|
|
50
|
+
"@backstage/plugin-catalog-node": "^1.18.0",
|
|
51
|
+
"@backstage/plugin-events-node": "^0.4.14",
|
|
52
|
+
"@backstage/plugin-notifications-common": "^0.1.0",
|
|
53
|
+
"@backstage/plugin-notifications-node": "^0.2.18",
|
|
54
|
+
"@backstage/plugin-signals-node": "^0.1.23",
|
|
55
55
|
"@backstage/types": "^1.2.1",
|
|
56
56
|
"express": "^4.17.1",
|
|
57
57
|
"express-promise-router": "^4.1.0",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"yn": "^4.0.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@backstage/backend-defaults": "^0.
|
|
66
|
-
"@backstage/backend-test-utils": "^1.
|
|
67
|
-
"@backstage/cli": "^0.
|
|
68
|
-
"@backstage/plugin-auth-backend": "^0.25.
|
|
69
|
-
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.
|
|
70
|
-
"@backstage/plugin-events-backend": "^0.5.
|
|
71
|
-
"@backstage/plugin-signals-backend": "^0.3.
|
|
65
|
+
"@backstage/backend-defaults": "^0.12.0",
|
|
66
|
+
"@backstage/backend-test-utils": "^1.8.0",
|
|
67
|
+
"@backstage/cli": "^0.34.0",
|
|
68
|
+
"@backstage/plugin-auth-backend": "^0.25.3",
|
|
69
|
+
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.11",
|
|
70
|
+
"@backstage/plugin-events-backend": "^0.5.5",
|
|
71
|
+
"@backstage/plugin-signals-backend": "^0.3.7",
|
|
72
72
|
"@types/express": "^4.17.6",
|
|
73
73
|
"@types/supertest": "^2.0.8",
|
|
74
74
|
"msw": "^1.0.0",
|