@backstage/plugin-notifications-backend-module-slack 0.3.1-next.1 → 0.4.0-next.0

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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # @backstage/plugin-notifications-backend-module-slack
2
2
 
3
+ ## 0.4.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 749ba60: Add an extension for custom Slack message layouts
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @backstage/plugin-catalog-node@2.1.0-next.0
13
+ - @backstage/backend-plugin-api@1.7.1-next.0
14
+ - @backstage/catalog-model@1.7.6
15
+ - @backstage/config@1.3.6
16
+ - @backstage/errors@1.2.7
17
+ - @backstage/types@1.2.2
18
+ - @backstage/plugin-notifications-common@0.2.1
19
+ - @backstage/plugin-notifications-node@0.2.24-next.0
20
+
21
+ ## 0.3.1
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+ - @backstage/plugin-catalog-node@2.0.0
27
+ - @backstage/backend-plugin-api@1.7.0
28
+ - @backstage/plugin-notifications-common@0.2.1
29
+ - @backstage/plugin-notifications-node@0.2.23
30
+
3
31
  ## 0.3.1-next.1
4
32
 
5
33
  ### Patch Changes
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+
5
+ const notificationsSlackBlockKitExtensionPoint = backendPluginApi.createExtensionPoint({
6
+ id: "notifications.slack.blockkit"
7
+ });
8
+
9
+ exports.notificationsSlackBlockKitExtensionPoint = notificationsSlackBlockKitExtensionPoint;
10
+ //# sourceMappingURL=extensions.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensions.cjs.js","sources":["../src/extensions.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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport { NotificationPayload } from '@backstage/plugin-notifications-common';\nimport { KnownBlock } from '@slack/web-api';\n\n/**\n * @public\n */\nexport type SlackBlockKitRenderer = (\n payload: NotificationPayload,\n) => KnownBlock[];\n\n/**\n * @public\n *\n * Extension point for customizing how notification payloads are rendered into\n * Slack Block Kit messages before they're sent.\n */\nexport interface NotificationsSlackBlockKitExtensionPoint {\n setBlockKitRenderer(renderer: SlackBlockKitRenderer): void;\n}\n\n/**\n * @public\n */\nexport const notificationsSlackBlockKitExtensionPoint =\n createExtensionPoint<NotificationsSlackBlockKitExtensionPoint>({\n id: 'notifications.slack.blockkit',\n });\n"],"names":["createExtensionPoint"],"mappings":";;;;AAuCO,MAAM,2CACXA,qCAAA,CAA+D;AAAA,EAC7D,EAAA,EAAI;AACN,CAAC;;;;"}
package/dist/index.cjs.js CHANGED
@@ -12,9 +12,11 @@ require('dataloader');
12
12
  require('p-throttle');
13
13
  var constants = require('./lib/constants.cjs.js');
14
14
  var module$1 = require('./module.cjs.js');
15
+ var extensions = require('./extensions.cjs.js');
15
16
 
16
17
 
17
18
 
18
19
  exports.ANNOTATION_SLACK_BOT_NOTIFY = constants.ANNOTATION_SLACK_BOT_NOTIFY;
19
20
  exports.default = module$1.notificationsModuleSlack;
21
+ exports.notificationsSlackBlockKitExtensionPoint = extensions.notificationsSlackBlockKitExtensionPoint;
20
22
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,24 @@
1
1
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
+ import { NotificationPayload } from '@backstage/plugin-notifications-common';
3
+ import { KnownBlock } from '@slack/web-api';
4
+
5
+ /**
6
+ * @public
7
+ */
8
+ type SlackBlockKitRenderer = (payload: NotificationPayload) => KnownBlock[];
9
+ /**
10
+ * @public
11
+ *
12
+ * Extension point for customizing how notification payloads are rendered into
13
+ * Slack Block Kit messages before they're sent.
14
+ */
15
+ interface NotificationsSlackBlockKitExtensionPoint {
16
+ setBlockKitRenderer(renderer: SlackBlockKitRenderer): void;
17
+ }
18
+ /**
19
+ * @public
20
+ */
21
+ declare const notificationsSlackBlockKitExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<NotificationsSlackBlockKitExtensionPoint>;
2
22
 
3
23
  /**
4
24
  * @public
@@ -22,4 +42,5 @@ declare const ANNOTATION_SLACK_BOT_NOTIFY = "slack.com/bot-notify";
22
42
  */
23
43
  declare const notificationsModuleSlack: _backstage_backend_plugin_api.BackendFeature;
24
44
 
25
- export { ANNOTATION_SLACK_BOT_NOTIFY, notificationsModuleSlack as default };
45
+ export { ANNOTATION_SLACK_BOT_NOTIFY, notificationsModuleSlack as default, notificationsSlackBlockKitExtensionPoint };
46
+ export type { NotificationsSlackBlockKitExtensionPoint, SlackBlockKitRenderer };
@@ -30,6 +30,7 @@ class SlackNotificationProcessor {
30
30
  username;
31
31
  concurrencyLimit;
32
32
  throttleInterval;
33
+ blockKitRenderer;
33
34
  static fromConfig(config$1, options) {
34
35
  const slackConfig = config$1.getOptionalConfigArray("notifications.processors.slack") ?? [];
35
36
  return slackConfig.map((c) => {
@@ -66,7 +67,8 @@ class SlackNotificationProcessor {
66
67
  broadcastRoutes,
67
68
  username,
68
69
  concurrencyLimit,
69
- throttleInterval
70
+ throttleInterval,
71
+ blockKitRenderer
70
72
  } = options;
71
73
  this.logger = logger;
72
74
  this.catalog = catalog;
@@ -77,6 +79,7 @@ class SlackNotificationProcessor {
77
79
  this.username = username;
78
80
  this.concurrencyLimit = concurrencyLimit ?? 10;
79
81
  this.throttleInterval = throttleInterval ?? types.durationToMilliseconds({ minutes: 1 });
82
+ this.blockKitRenderer = blockKitRenderer;
80
83
  this.entityLoader = new DataLoader__default.default(
81
84
  async (entityRefs) => {
82
85
  return await this.catalog.getEntitiesByRefs(
@@ -174,7 +177,8 @@ class SlackNotificationProcessor {
174
177
  const payload = util.toChatPostMessageArgs({
175
178
  channel,
176
179
  payload: options.payload,
177
- username: this.username
180
+ username: this.username,
181
+ blockKitRenderer: this.blockKitRenderer
178
182
  });
179
183
  this.logger.debug(
180
184
  `Sending Slack channel notification: ${JSON.stringify(payload)}`
@@ -216,7 +220,8 @@ class SlackNotificationProcessor {
216
220
  (channel) => util.toChatPostMessageArgs({
217
221
  channel,
218
222
  payload: formattedPayload,
219
- username: this.username
223
+ username: this.username,
224
+ blockKitRenderer: this.blockKitRenderer
220
225
  })
221
226
  );
222
227
  outbound.forEach((payload) => {
@@ -1 +1 @@
1
- {"version":3,"file":"SlackNotificationProcessor.cjs.js","sources":["../../src/lib/SlackNotificationProcessor.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 */\n\nimport { AuthService, LoggerService } from '@backstage/backend-plugin-api';\nimport {\n Entity,\n isUserEntity,\n parseEntityRef,\n UserEntity,\n} from '@backstage/catalog-model';\nimport { Config, readDurationFromConfig } from '@backstage/config';\nimport { NotFoundError } from '@backstage/errors';\nimport { Notification } from '@backstage/plugin-notifications-common';\nimport {\n NotificationProcessor,\n NotificationSendOptions,\n} from '@backstage/plugin-notifications-node';\nimport { durationToMilliseconds } from '@backstage/types';\nimport { Counter, metrics } from '@opentelemetry/api';\nimport { ChatPostMessageArguments, WebClient } from '@slack/web-api';\nimport DataLoader from 'dataloader';\nimport pThrottle from 'p-throttle';\nimport { ANNOTATION_SLACK_BOT_NOTIFY } from './constants';\nimport { BroadcastRoute } from './types';\nimport { ExpiryMap, toChatPostMessageArgs } from './util';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nexport class SlackNotificationProcessor implements NotificationProcessor {\n private readonly logger: LoggerService;\n private readonly catalog: CatalogService;\n private readonly auth: AuthService;\n private readonly slack: WebClient;\n private readonly sendNotifications: (\n opts: ChatPostMessageArguments[],\n ) => Promise<void>;\n private readonly messagesSent: Counter;\n private readonly messagesFailed: Counter;\n private readonly broadcastChannels?: string[];\n private readonly broadcastRoutes?: BroadcastRoute[];\n private readonly entityLoader: DataLoader<string, Entity | undefined>;\n private readonly username?: string;\n private readonly concurrencyLimit: number;\n private readonly throttleInterval: number;\n\n static fromConfig(\n config: Config,\n options: {\n auth: AuthService;\n logger: LoggerService;\n catalog: CatalogService;\n slack?: WebClient;\n broadcastChannels?: string[];\n },\n ): SlackNotificationProcessor[] {\n const slackConfig =\n config.getOptionalConfigArray('notifications.processors.slack') ?? [];\n return slackConfig.map(c => {\n const token = c.getString('token');\n const slack = options.slack ?? new WebClient(token);\n const broadcastChannels = c.getOptionalStringArray('broadcastChannels');\n const username = c.getOptionalString('username');\n const broadcastRoutesConfig = c.getOptionalConfigArray('broadcastRoutes');\n const broadcastRoutes = broadcastRoutesConfig?.map(route =>\n this.parseBroadcastRoute(route),\n );\n const concurrencyLimit = c.getOptionalNumber('concurrencyLimit') ?? 10;\n const throttleInterval = c.has('throttleInterval')\n ? durationToMilliseconds(\n readDurationFromConfig(c, { key: 'throttleInterval' }),\n )\n : durationToMilliseconds({ minutes: 1 });\n return new SlackNotificationProcessor({\n slack,\n broadcastChannels,\n broadcastRoutes,\n username,\n concurrencyLimit,\n throttleInterval,\n ...options,\n });\n });\n }\n\n private constructor(options: {\n slack: WebClient;\n auth: AuthService;\n logger: LoggerService;\n catalog: CatalogService;\n broadcastChannels?: string[];\n broadcastRoutes?: BroadcastRoute[];\n username?: string;\n concurrencyLimit?: number;\n throttleInterval?: number;\n }) {\n const {\n auth,\n catalog,\n logger,\n slack,\n broadcastChannels,\n broadcastRoutes,\n username,\n concurrencyLimit,\n throttleInterval,\n } = options;\n this.logger = logger;\n this.catalog = catalog;\n this.auth = auth;\n this.slack = slack;\n this.broadcastChannels = broadcastChannels;\n this.broadcastRoutes = broadcastRoutes;\n this.username = username;\n this.concurrencyLimit = concurrencyLimit ?? 10;\n this.throttleInterval =\n throttleInterval ?? durationToMilliseconds({ minutes: 1 });\n\n this.entityLoader = new DataLoader<string, Entity | undefined>(\n async entityRefs => {\n return await this.catalog\n .getEntitiesByRefs(\n {\n entityRefs: entityRefs.slice(),\n fields: [\n `kind`,\n `spec.profile.email`,\n `metadata.annotations.${ANNOTATION_SLACK_BOT_NOTIFY}`,\n ],\n },\n { credentials: await this.auth.getOwnServiceCredentials() },\n )\n .then(r => r.items);\n },\n {\n name: 'SlackNotificationProcessor.entityLoader',\n cacheMap: new ExpiryMap(durationToMilliseconds({ minutes: 10 })),\n maxBatchSize: 100,\n batchScheduleFn: cb =>\n setTimeout(cb, durationToMilliseconds({ milliseconds: 10 })),\n },\n );\n\n const meter = metrics.getMeter('default');\n this.messagesSent = meter.createCounter(\n 'notifications.processors.slack.sent.count',\n {\n description: 'Number of messages sent to Slack successfully',\n },\n );\n this.messagesFailed = meter.createCounter(\n 'notifications.processors.slack.error.count',\n {\n description: 'Number of messages that failed to send to Slack',\n },\n );\n\n const throttle = pThrottle({\n limit: this.concurrencyLimit,\n interval: this.throttleInterval,\n });\n const throttled = throttle((opts: ChatPostMessageArguments) =>\n this.sendNotification(opts),\n );\n this.sendNotifications = async (opts: ChatPostMessageArguments[]) => {\n const results = await Promise.allSettled(\n opts.map(message => throttled(message)),\n );\n\n let successCount = 0;\n let failureCount = 0;\n\n results.forEach((result, index) => {\n if (result.status === 'fulfilled') {\n successCount++;\n } else {\n this.logger.error(\n `Failed to send Slack channel notification to ${opts[index].channel}: ${result.reason.message}`,\n );\n failureCount++;\n }\n });\n\n this.messagesSent.add(successCount);\n this.messagesFailed.add(failureCount);\n };\n }\n\n getName(): string {\n return 'SlackNotificationProcessor';\n }\n\n async processOptions(\n options: NotificationSendOptions,\n ): Promise<NotificationSendOptions> {\n if (options.recipients.type !== 'entity') {\n return options;\n }\n\n const entityRefs = [options.recipients.entityRef].flat();\n\n const outbound: ChatPostMessageArguments[] = [];\n await Promise.all(\n entityRefs.map(async entityRef => {\n const compoundEntityRef = parseEntityRef(entityRef);\n // skip users as they are sent direct messages\n if (compoundEntityRef.kind === 'user') {\n return;\n }\n\n let channel;\n try {\n channel = await this.getSlackNotificationTarget(entityRef);\n } catch (error) {\n this.logger.error(\n `Failed to get Slack channel for entity: ${\n (error as Error).message\n }`,\n );\n return;\n }\n\n if (!channel) {\n this.logger.debug(`No Slack channel found for entity: ${entityRef}`);\n return;\n }\n\n this.logger.debug(\n `Sending notification with payload: ${JSON.stringify(\n options.payload,\n )}`,\n );\n\n const payload = toChatPostMessageArgs({\n channel,\n payload: options.payload,\n username: this.username,\n });\n\n this.logger.debug(\n `Sending Slack channel notification: ${JSON.stringify(payload)}`,\n );\n outbound.push(payload);\n }),\n );\n\n await this.sendNotifications(outbound);\n\n return options;\n }\n\n async postProcess(\n notification: Notification,\n options: NotificationSendOptions,\n ): Promise<void> {\n const destinations: string[] = [];\n\n // Handle broadcast case\n if (notification.user === null) {\n const routedChannels = this.getBroadcastDestinations(notification);\n destinations.push(...routedChannels);\n } else if (options.recipients.type === 'entity') {\n // Handle user-specific notification\n const entityRefs = [options.recipients.entityRef].flat();\n if (entityRefs.some(e => parseEntityRef(e).kind === 'group')) {\n // We've already dispatched a slack channel message, so let's not send a DM.\n return;\n }\n\n const destination = await this.getSlackNotificationTarget(\n notification.user,\n );\n\n if (!destination) {\n this.logger.error(\n `No slack.com/bot-notify annotation found for user: ${notification.user}`,\n );\n return;\n }\n\n destinations.push(destination);\n }\n\n // If no destinations, nothing to do\n if (destinations.length === 0) {\n return;\n }\n\n // Prepare outbound messages\n const formattedPayload = await this.formatPayloadDescriptionForSlack(\n options.payload,\n );\n const outbound = destinations.map(channel =>\n toChatPostMessageArgs({\n channel,\n payload: formattedPayload,\n username: this.username,\n }),\n );\n\n // Log debug info\n outbound.forEach(payload => {\n this.logger.debug(`Sending notification: ${JSON.stringify(payload)}`);\n });\n\n // Send notifications\n await this.sendNotifications(outbound);\n }\n\n private async formatPayloadDescriptionForSlack(\n payload: Notification['payload'],\n ) {\n return {\n ...payload,\n description: await this.replaceUserRefsWithSlackIds(payload.description),\n };\n }\n\n async replaceUserRefsWithSlackIds(\n text?: string,\n ): Promise<string | undefined> {\n if (!text) return undefined;\n\n // Match user entity refs like \"<@user:default/billy>\"\n const userRefRegex = /<@(user:[^>]+)>/gi;\n const matches = [...text.matchAll(userRefRegex)];\n\n if (matches.length === 0) return text;\n\n const uniqueUserRefs = new Set(\n matches.map(match => match[1].toLowerCase()),\n );\n\n const slackIdMap = new Map<string, string>();\n\n await Promise.all(\n [...uniqueUserRefs].map(async userRef => {\n try {\n const slackId = await this.getSlackNotificationTarget(userRef);\n if (slackId) {\n slackIdMap.set(userRef, `<@${slackId}>`);\n }\n } catch (error) {\n this.logger.warn(\n `Failed to resolve Slack ID for user ref \"${userRef}\": ${error}`,\n );\n }\n }),\n );\n\n return text.replace(userRefRegex, (match, userRef) => {\n const slackId = slackIdMap.get(userRef.toLowerCase());\n return slackId ?? match;\n });\n }\n\n async getSlackNotificationTarget(\n entityRef: string,\n ): Promise<string | undefined> {\n const entity = await this.entityLoader.load(entityRef);\n if (!entity) {\n throw new NotFoundError(`Entity not found: ${entityRef}`);\n }\n\n const slackId = await this.resolveSlackId(entity);\n return slackId;\n }\n\n private async resolveSlackId(entity: Entity): Promise<string | undefined> {\n // First try to get Slack ID from annotations\n const slackId = entity.metadata?.annotations?.[ANNOTATION_SLACK_BOT_NOTIFY];\n if (slackId) {\n return slackId;\n }\n\n // If no Slack ID in annotations and entity is a User, try to find by email\n if (isUserEntity(entity)) {\n return this.findSlackIdByEmail(entity);\n }\n\n return undefined;\n }\n\n private async findSlackIdByEmail(\n entity: UserEntity,\n ): Promise<string | undefined> {\n const email = entity.spec?.profile?.email;\n if (!email) {\n return undefined;\n }\n\n try {\n const user = await this.slack.users.lookupByEmail({ email });\n return user.user?.id;\n } catch (error) {\n this.logger.warn(\n `Failed to lookup Slack user by email ${email}: ${error}`,\n );\n return undefined;\n }\n }\n\n async sendNotification(args: ChatPostMessageArguments): Promise<void> {\n const response = await this.slack.chat.postMessage(args);\n\n if (!response.ok) {\n throw new Error(`Failed to send notification: ${response.error}`);\n }\n }\n\n private static parseBroadcastRoute(route: Config): BroadcastRoute {\n const channelValue = route.getOptional('channel');\n let channels: string[];\n\n if (typeof channelValue === 'string') {\n channels = [channelValue];\n } else if (Array.isArray(channelValue)) {\n channels = channelValue as string[];\n } else {\n throw new Error(\n 'broadcastRoutes entry must have a channel property (string or string[])',\n );\n }\n\n return {\n origin: route.getOptionalString('origin'),\n topic: route.getOptionalString('topic'),\n channels,\n };\n }\n\n /**\n * Gets the destination channels for a broadcast notification based on\n * configured routes. Routes are matched by origin and/or topic.\n *\n * Matching precedence:\n * 1. Routes with both origin AND topic matching (most specific)\n * 2. Routes with only origin matching\n * 3. Routes with only topic matching\n * 4. Default broadcastChannels (least specific fallback)\n *\n * The first matching route wins within each precedence level.\n */\n private getBroadcastDestinations(notification: Notification): string[] {\n const { origin } = notification;\n const { topic } = notification.payload;\n\n if (!this.broadcastRoutes || this.broadcastRoutes.length === 0) {\n // Fall back to legacy broadcastChannels config\n return this.broadcastChannels ?? [];\n }\n\n // Find most specific match\n // Priority 1: origin AND topic match\n const originAndTopicMatch = this.broadcastRoutes.find(\n route =>\n route.origin !== undefined &&\n route.topic !== undefined &&\n route.origin === origin &&\n route.topic === topic,\n );\n\n if (originAndTopicMatch) {\n return originAndTopicMatch.channels;\n }\n\n // Priority 2: origin-only match (no topic specified in route)\n const originOnlyMatch = this.broadcastRoutes.find(\n route =>\n route.origin !== undefined &&\n route.topic === undefined &&\n route.origin === origin,\n );\n\n if (originOnlyMatch) {\n return originOnlyMatch.channels;\n }\n\n // Priority 3: topic-only match (no origin specified in route)\n const topicOnlyMatch = this.broadcastRoutes.find(\n route =>\n route.topic !== undefined &&\n route.origin === undefined &&\n route.topic === topic,\n );\n\n if (topicOnlyMatch) {\n return topicOnlyMatch.channels;\n }\n\n // No match found, fall back to legacy broadcastChannels\n return this.broadcastChannels ?? [];\n }\n}\n"],"names":["config","WebClient","durationToMilliseconds","readDurationFromConfig","DataLoader","ANNOTATION_SLACK_BOT_NOTIFY","ExpiryMap","metrics","pThrottle","parseEntityRef","toChatPostMessageArgs","NotFoundError","isUserEntity"],"mappings":";;;;;;;;;;;;;;;;;;AAwCO,MAAM,0BAAA,CAA4D;AAAA,EACtD,MAAA;AAAA,EACA,OAAA;AAAA,EACA,IAAA;AAAA,EACA,KAAA;AAAA,EACA,iBAAA;AAAA,EAGA,YAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,gBAAA;AAAA,EACA,gBAAA;AAAA,EAEjB,OAAO,UAAA,CACLA,QAAA,EACA,OAAA,EAO8B;AAC9B,IAAA,MAAM,WAAA,GACJA,QAAA,CAAO,sBAAA,CAAuB,gCAAgC,KAAK,EAAC;AACtE,IAAA,OAAO,WAAA,CAAY,IAAI,CAAA,CAAA,KAAK;AAC1B,MAAA,MAAM,KAAA,GAAQ,CAAA,CAAE,SAAA,CAAU,OAAO,CAAA;AACjC,MAAA,MAAM,KAAA,GAAQ,OAAA,CAA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KACE,MAAM,KAAA,KAAU,MAAA,IAChB,MAAM,MAAA,KAAW,MAAA,IACjB,MAAM,KAAA,KAAU;AAAA,KACpB;AAEA,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,OAAO,cAAA,CAAe,QAAA;AAAA,IACxB;AAGA,IAAA,OAAO,IAAA,CAAK,qBAAqB,EAAC;AAAA,EACpC;AACF;;;;"}
1
+ {"version":3,"file":"SlackNotificationProcessor.cjs.js","sources":["../../src/lib/SlackNotificationProcessor.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 */\n\nimport { AuthService, LoggerService } from '@backstage/backend-plugin-api';\nimport {\n Entity,\n isUserEntity,\n parseEntityRef,\n UserEntity,\n} from '@backstage/catalog-model';\nimport { Config, readDurationFromConfig } from '@backstage/config';\nimport { NotFoundError } from '@backstage/errors';\nimport { Notification } from '@backstage/plugin-notifications-common';\nimport {\n NotificationProcessor,\n NotificationSendOptions,\n} from '@backstage/plugin-notifications-node';\nimport { durationToMilliseconds } from '@backstage/types';\nimport { Counter, metrics } from '@opentelemetry/api';\nimport { ChatPostMessageArguments, WebClient } from '@slack/web-api';\nimport DataLoader from 'dataloader';\nimport pThrottle from 'p-throttle';\nimport { ANNOTATION_SLACK_BOT_NOTIFY } from './constants';\nimport { BroadcastRoute } from './types';\nimport { ExpiryMap, toChatPostMessageArgs } from './util';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\nimport { SlackBlockKitRenderer } from '../extensions';\n\nexport class SlackNotificationProcessor implements NotificationProcessor {\n private readonly logger: LoggerService;\n private readonly catalog: CatalogService;\n private readonly auth: AuthService;\n private readonly slack: WebClient;\n private readonly sendNotifications: (\n opts: ChatPostMessageArguments[],\n ) => Promise<void>;\n private readonly messagesSent: Counter;\n private readonly messagesFailed: Counter;\n private readonly broadcastChannels?: string[];\n private readonly broadcastRoutes?: BroadcastRoute[];\n private readonly entityLoader: DataLoader<string, Entity | undefined>;\n private readonly username?: string;\n private readonly concurrencyLimit: number;\n private readonly throttleInterval: number;\n private readonly blockKitRenderer?: SlackBlockKitRenderer;\n\n static fromConfig(\n config: Config,\n options: {\n auth: AuthService;\n logger: LoggerService;\n catalog: CatalogService;\n slack?: WebClient;\n broadcastChannels?: string[];\n blockKitRenderer?: SlackBlockKitRenderer;\n },\n ): SlackNotificationProcessor[] {\n const slackConfig =\n config.getOptionalConfigArray('notifications.processors.slack') ?? [];\n return slackConfig.map(c => {\n const token = c.getString('token');\n const slack = options.slack ?? new WebClient(token);\n const broadcastChannels = c.getOptionalStringArray('broadcastChannels');\n const username = c.getOptionalString('username');\n const broadcastRoutesConfig = c.getOptionalConfigArray('broadcastRoutes');\n const broadcastRoutes = broadcastRoutesConfig?.map(route =>\n this.parseBroadcastRoute(route),\n );\n const concurrencyLimit = c.getOptionalNumber('concurrencyLimit') ?? 10;\n const throttleInterval = c.has('throttleInterval')\n ? durationToMilliseconds(\n readDurationFromConfig(c, { key: 'throttleInterval' }),\n )\n : durationToMilliseconds({ minutes: 1 });\n return new SlackNotificationProcessor({\n slack,\n broadcastChannels,\n broadcastRoutes,\n username,\n concurrencyLimit,\n throttleInterval,\n ...options,\n });\n });\n }\n\n private constructor(options: {\n slack: WebClient;\n auth: AuthService;\n logger: LoggerService;\n catalog: CatalogService;\n broadcastChannels?: string[];\n broadcastRoutes?: BroadcastRoute[];\n username?: string;\n concurrencyLimit?: number;\n throttleInterval?: number;\n blockKitRenderer?: SlackBlockKitRenderer;\n }) {\n const {\n auth,\n catalog,\n logger,\n slack,\n broadcastChannels,\n broadcastRoutes,\n username,\n concurrencyLimit,\n throttleInterval,\n blockKitRenderer,\n } = options;\n this.logger = logger;\n this.catalog = catalog;\n this.auth = auth;\n this.slack = slack;\n this.broadcastChannels = broadcastChannels;\n this.broadcastRoutes = broadcastRoutes;\n this.username = username;\n this.concurrencyLimit = concurrencyLimit ?? 10;\n this.throttleInterval =\n throttleInterval ?? durationToMilliseconds({ minutes: 1 });\n this.blockKitRenderer = blockKitRenderer;\n\n this.entityLoader = new DataLoader<string, Entity | undefined>(\n async entityRefs => {\n return await this.catalog\n .getEntitiesByRefs(\n {\n entityRefs: entityRefs.slice(),\n fields: [\n `kind`,\n `spec.profile.email`,\n `metadata.annotations.${ANNOTATION_SLACK_BOT_NOTIFY}`,\n ],\n },\n { credentials: await this.auth.getOwnServiceCredentials() },\n )\n .then(r => r.items);\n },\n {\n name: 'SlackNotificationProcessor.entityLoader',\n cacheMap: new ExpiryMap(durationToMilliseconds({ minutes: 10 })),\n maxBatchSize: 100,\n batchScheduleFn: cb =>\n setTimeout(cb, durationToMilliseconds({ milliseconds: 10 })),\n },\n );\n\n const meter = metrics.getMeter('default');\n this.messagesSent = meter.createCounter(\n 'notifications.processors.slack.sent.count',\n {\n description: 'Number of messages sent to Slack successfully',\n },\n );\n this.messagesFailed = meter.createCounter(\n 'notifications.processors.slack.error.count',\n {\n description: 'Number of messages that failed to send to Slack',\n },\n );\n\n const throttle = pThrottle({\n limit: this.concurrencyLimit,\n interval: this.throttleInterval,\n });\n const throttled = throttle((opts: ChatPostMessageArguments) =>\n this.sendNotification(opts),\n );\n this.sendNotifications = async (opts: ChatPostMessageArguments[]) => {\n const results = await Promise.allSettled(\n opts.map(message => throttled(message)),\n );\n\n let successCount = 0;\n let failureCount = 0;\n\n results.forEach((result, index) => {\n if (result.status === 'fulfilled') {\n successCount++;\n } else {\n this.logger.error(\n `Failed to send Slack channel notification to ${opts[index].channel}: ${result.reason.message}`,\n );\n failureCount++;\n }\n });\n\n this.messagesSent.add(successCount);\n this.messagesFailed.add(failureCount);\n };\n }\n\n getName(): string {\n return 'SlackNotificationProcessor';\n }\n\n async processOptions(\n options: NotificationSendOptions,\n ): Promise<NotificationSendOptions> {\n if (options.recipients.type !== 'entity') {\n return options;\n }\n\n const entityRefs = [options.recipients.entityRef].flat();\n\n const outbound: ChatPostMessageArguments[] = [];\n await Promise.all(\n entityRefs.map(async entityRef => {\n const compoundEntityRef = parseEntityRef(entityRef);\n // skip users as they are sent direct messages\n if (compoundEntityRef.kind === 'user') {\n return;\n }\n\n let channel;\n try {\n channel = await this.getSlackNotificationTarget(entityRef);\n } catch (error) {\n this.logger.error(\n `Failed to get Slack channel for entity: ${\n (error as Error).message\n }`,\n );\n return;\n }\n\n if (!channel) {\n this.logger.debug(`No Slack channel found for entity: ${entityRef}`);\n return;\n }\n\n this.logger.debug(\n `Sending notification with payload: ${JSON.stringify(\n options.payload,\n )}`,\n );\n\n const payload = toChatPostMessageArgs({\n channel,\n payload: options.payload,\n username: this.username,\n blockKitRenderer: this.blockKitRenderer,\n });\n\n this.logger.debug(\n `Sending Slack channel notification: ${JSON.stringify(payload)}`,\n );\n outbound.push(payload);\n }),\n );\n\n await this.sendNotifications(outbound);\n\n return options;\n }\n\n async postProcess(\n notification: Notification,\n options: NotificationSendOptions,\n ): Promise<void> {\n const destinations: string[] = [];\n\n // Handle broadcast case\n if (notification.user === null) {\n const routedChannels = this.getBroadcastDestinations(notification);\n destinations.push(...routedChannels);\n } else if (options.recipients.type === 'entity') {\n // Handle user-specific notification\n const entityRefs = [options.recipients.entityRef].flat();\n if (entityRefs.some(e => parseEntityRef(e).kind === 'group')) {\n // We've already dispatched a slack channel message, so let's not send a DM.\n return;\n }\n\n const destination = await this.getSlackNotificationTarget(\n notification.user,\n );\n\n if (!destination) {\n this.logger.error(\n `No slack.com/bot-notify annotation found for user: ${notification.user}`,\n );\n return;\n }\n\n destinations.push(destination);\n }\n\n // If no destinations, nothing to do\n if (destinations.length === 0) {\n return;\n }\n\n // Prepare outbound messages\n const formattedPayload = await this.formatPayloadDescriptionForSlack(\n options.payload,\n );\n const outbound = destinations.map(channel =>\n toChatPostMessageArgs({\n channel,\n payload: formattedPayload,\n username: this.username,\n blockKitRenderer: this.blockKitRenderer,\n }),\n );\n\n // Log debug info\n outbound.forEach(payload => {\n this.logger.debug(`Sending notification: ${JSON.stringify(payload)}`);\n });\n\n // Send notifications\n await this.sendNotifications(outbound);\n }\n\n private async formatPayloadDescriptionForSlack(\n payload: Notification['payload'],\n ) {\n return {\n ...payload,\n description: await this.replaceUserRefsWithSlackIds(payload.description),\n };\n }\n\n async replaceUserRefsWithSlackIds(\n text?: string,\n ): Promise<string | undefined> {\n if (!text) return undefined;\n\n // Match user entity refs like \"<@user:default/billy>\"\n const userRefRegex = /<@(user:[^>]+)>/gi;\n const matches = [...text.matchAll(userRefRegex)];\n\n if (matches.length === 0) return text;\n\n const uniqueUserRefs = new Set(\n matches.map(match => match[1].toLowerCase()),\n );\n\n const slackIdMap = new Map<string, string>();\n\n await Promise.all(\n [...uniqueUserRefs].map(async userRef => {\n try {\n const slackId = await this.getSlackNotificationTarget(userRef);\n if (slackId) {\n slackIdMap.set(userRef, `<@${slackId}>`);\n }\n } catch (error) {\n this.logger.warn(\n `Failed to resolve Slack ID for user ref \"${userRef}\": ${error}`,\n );\n }\n }),\n );\n\n return text.replace(userRefRegex, (match, userRef) => {\n const slackId = slackIdMap.get(userRef.toLowerCase());\n return slackId ?? match;\n });\n }\n\n async getSlackNotificationTarget(\n entityRef: string,\n ): Promise<string | undefined> {\n const entity = await this.entityLoader.load(entityRef);\n if (!entity) {\n throw new NotFoundError(`Entity not found: ${entityRef}`);\n }\n\n const slackId = await this.resolveSlackId(entity);\n return slackId;\n }\n\n private async resolveSlackId(entity: Entity): Promise<string | undefined> {\n // First try to get Slack ID from annotations\n const slackId = entity.metadata?.annotations?.[ANNOTATION_SLACK_BOT_NOTIFY];\n if (slackId) {\n return slackId;\n }\n\n // If no Slack ID in annotations and entity is a User, try to find by email\n if (isUserEntity(entity)) {\n return this.findSlackIdByEmail(entity);\n }\n\n return undefined;\n }\n\n private async findSlackIdByEmail(\n entity: UserEntity,\n ): Promise<string | undefined> {\n const email = entity.spec?.profile?.email;\n if (!email) {\n return undefined;\n }\n\n try {\n const user = await this.slack.users.lookupByEmail({ email });\n return user.user?.id;\n } catch (error) {\n this.logger.warn(\n `Failed to lookup Slack user by email ${email}: ${error}`,\n );\n return undefined;\n }\n }\n\n async sendNotification(args: ChatPostMessageArguments): Promise<void> {\n const response = await this.slack.chat.postMessage(args);\n\n if (!response.ok) {\n throw new Error(`Failed to send notification: ${response.error}`);\n }\n }\n\n private static parseBroadcastRoute(route: Config): BroadcastRoute {\n const channelValue = route.getOptional('channel');\n let channels: string[];\n\n if (typeof channelValue === 'string') {\n channels = [channelValue];\n } else if (Array.isArray(channelValue)) {\n channels = channelValue as string[];\n } else {\n throw new Error(\n 'broadcastRoutes entry must have a channel property (string or string[])',\n );\n }\n\n return {\n origin: route.getOptionalString('origin'),\n topic: route.getOptionalString('topic'),\n channels,\n };\n }\n\n /**\n * Gets the destination channels for a broadcast notification based on\n * configured routes. Routes are matched by origin and/or topic.\n *\n * Matching precedence:\n * 1. Routes with both origin AND topic matching (most specific)\n * 2. Routes with only origin matching\n * 3. Routes with only topic matching\n * 4. Default broadcastChannels (least specific fallback)\n *\n * The first matching route wins within each precedence level.\n */\n private getBroadcastDestinations(notification: Notification): string[] {\n const { origin } = notification;\n const { topic } = notification.payload;\n\n if (!this.broadcastRoutes || this.broadcastRoutes.length === 0) {\n // Fall back to legacy broadcastChannels config\n return this.broadcastChannels ?? [];\n }\n\n // Find most specific match\n // Priority 1: origin AND topic match\n const originAndTopicMatch = this.broadcastRoutes.find(\n route =>\n route.origin !== undefined &&\n route.topic !== undefined &&\n route.origin === origin &&\n route.topic === topic,\n );\n\n if (originAndTopicMatch) {\n return originAndTopicMatch.channels;\n }\n\n // Priority 2: origin-only match (no topic specified in route)\n const originOnlyMatch = this.broadcastRoutes.find(\n route =>\n route.origin !== undefined &&\n route.topic === undefined &&\n route.origin === origin,\n );\n\n if (originOnlyMatch) {\n return originOnlyMatch.channels;\n }\n\n // Priority 3: topic-only match (no origin specified in route)\n const topicOnlyMatch = this.broadcastRoutes.find(\n route =>\n route.topic !== undefined &&\n route.origin === undefined &&\n route.topic === topic,\n );\n\n if (topicOnlyMatch) {\n return topicOnlyMatch.channels;\n }\n\n // No match found, fall back to legacy broadcastChannels\n return this.broadcastChannels ?? [];\n }\n}\n"],"names":["config","WebClient","durationToMilliseconds","readDurationFromConfig","DataLoader","ANNOTATION_SLACK_BOT_NOTIFY","ExpiryMap","metrics","pThrottle","parseEntityRef","toChatPostMessageArgs","NotFoundError","isUserEntity"],"mappings":";;;;;;;;;;;;;;;;;;AAyCO,MAAM,0BAAA,CAA4D;AAAA,EACtD,MAAA;AAAA,EACA,OAAA;AAAA,EACA,IAAA;AAAA,EACA,KAAA;AAAA,EACA,iBAAA;AAAA,EAGA,YAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA,gBAAA;AAAA,EAEjB,OAAO,UAAA,CACLA,QAAA,EACA,OAAA,EAQ8B;AAC9B,IAAA,MAAM,WAAA,GACJA,QAAA,CAAO,sBAAA,CAAuB,gCAAgC,KAAK,EAAC;AACtE,IAAA,OAAO,WAAA,CAAY,IAAI,CAAA,CAAA,KAAK;AAC1B,MAAA,MAAM,KAAA,GAAQ,CAAA,CAAE,SAAA,CAAU,OAAO,CAAA;AACjC,MAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,KAAA,IAAS,IAAIC,iBAAU,KAAK,CAAA;AAClD,MAAA,MAAM,iBAAA,GAAoB,CAAA,CAAE,sBAAA,CAAuB,mBAAmB,CAAA;AACtE,MAAA,MAAM,QAAA,GAAW,CAAA,CAAE,iBAAA,CAAkB,UAAU,CAAA;AAC/C,MAAA,MAAM,qBAAA,G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AA,KAAU;AAAA,KACpB;AAEA,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,OAAO,cAAA,CAAe,QAAA;AAAA,IACxB;AAGA,IAAA,OAAO,IAAA,CAAK,qBAAqB,EAAC;AAAA,EACpC;AACF;;;;"}
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  function toChatPostMessageArgs(options) {
4
- const { channel, payload, username } = options;
4
+ const { channel, payload, username, blockKitRenderer } = options;
5
+ const blocks = (blockKitRenderer ?? toSlackBlockKit)(payload);
5
6
  const args = {
6
7
  channel,
7
8
  text: payload.title,
@@ -9,7 +10,7 @@ function toChatPostMessageArgs(options) {
9
10
  attachments: [
10
11
  {
11
12
  color: getColor(payload.severity),
12
- blocks: toSlackBlockKit(payload),
13
+ blocks,
13
14
  fallback: payload.title
14
15
  }
15
16
  ]
@@ -1 +1 @@
1
- {"version":3,"file":"util.cjs.js","sources":["../../src/lib/util.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 */\n\nimport {\n NotificationPayload,\n NotificationSeverity,\n} from '@backstage/plugin-notifications-common';\nimport { ChatPostMessageArguments, KnownBlock } from '@slack/web-api';\n\nexport function toChatPostMessageArgs(options: {\n channel: string;\n payload: NotificationPayload;\n username?: string;\n}): ChatPostMessageArguments {\n const { channel, payload, username } = options;\n\n const args: ChatPostMessageArguments = {\n channel,\n text: payload.title,\n username,\n attachments: [\n {\n color: getColor(payload.severity),\n blocks: toSlackBlockKit(payload),\n fallback: payload.title,\n },\n ],\n };\n\n return args;\n}\n\nexport function toSlackBlockKit(payload: NotificationPayload): KnownBlock[] {\n const { description, link, severity, topic } = payload;\n return [\n {\n type: 'section',\n text: {\n type: 'mrkdwn',\n text: description ?? 'No description provided',\n },\n accessory: {\n type: 'button',\n text: {\n type: 'plain_text',\n text: 'View More',\n },\n ...(link && { url: link }),\n action_id: 'button-action',\n },\n },\n {\n type: 'context',\n elements: [\n {\n type: 'plain_text',\n text: `Severity: ${severity ?? 'normal'}`,\n emoji: true,\n },\n {\n type: 'plain_text',\n text: `Topic: ${topic ?? 'N/A'}`,\n emoji: true,\n },\n ],\n },\n ];\n}\n\nfunction getColor(severity: NotificationSeverity | undefined) {\n switch (severity) {\n case 'critical':\n return '#FF0000'; // Red\n case 'high':\n return '#FFA500'; // Orange\n case 'low':\n case 'normal':\n default:\n return '#00A699'; // Neutral color\n }\n}\n\n// Simple expiry map for the data loader, which only expects a map that implements set, get, and delete and clear\nexport class ExpiryMap<K, V> extends Map<K, V> {\n #ttlMs: number;\n #timestamps: Map<K, number> = new Map();\n\n constructor(ttlMs: number) {\n super();\n this.#ttlMs = ttlMs;\n }\n\n set(key: K, value: V) {\n const result = super.set(key, value);\n this.#timestamps.set(key, Date.now());\n return result;\n }\n\n get(key: K) {\n if (!this.has(key)) {\n return undefined;\n }\n const timestamp = this.#timestamps.get(key)!;\n if (Date.now() - timestamp > this.#ttlMs) {\n this.delete(key);\n return undefined;\n }\n return super.get(key);\n }\n\n delete(key: K) {\n this.#timestamps.delete(key);\n return super.delete(key);\n }\n\n clear() {\n this.#timestamps.clear();\n return super.clear();\n }\n}\n"],"names":[],"mappings":";;AAsBO,SAAS,sBAAsB,OAAA,EAIT;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,QAAA,EAAS,GAAI,OAAA;AAEvC,EAAA,MAAM,IAAA,GAAiC;AAAA,IACrC,OAAA;AAAA,IACA,MAAM,OAAA,CAAQ,KAAA;AAAA,IACd,QAAA;AAAA,IACA,WAAA,EAAa;AAAA,MACX;AAAA,QACE,KAAA,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s.js","sources":["../../src/lib/util.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 */\n\nimport {\n NotificationPayload,\n NotificationSeverity,\n} from '@backstage/plugin-notifications-common';\nimport { ChatPostMessageArguments, KnownBlock } from '@slack/web-api';\nimport { SlackBlockKitRenderer } from '../extensions';\n\nexport function toChatPostMessageArgs(options: {\n channel: string;\n payload: NotificationPayload;\n username?: string;\n blockKitRenderer?: SlackBlockKitRenderer;\n}): ChatPostMessageArguments {\n const { channel, payload, username, blockKitRenderer } = options;\n const blocks = (blockKitRenderer ?? toSlackBlockKit)(payload);\n\n const args: ChatPostMessageArguments = {\n channel,\n text: payload.title,\n username,\n attachments: [\n {\n color: getColor(payload.severity),\n blocks,\n fallback: payload.title,\n },\n ],\n };\n\n return args;\n}\n\nexport function toSlackBlockKit(payload: NotificationPayload): KnownBlock[] {\n const { description, link, severity, topic } = payload;\n return [\n {\n type: 'section',\n text: {\n type: 'mrkdwn',\n text: description ?? 'No description provided',\n },\n accessory: {\n type: 'button',\n text: {\n type: 'plain_text',\n text: 'View More',\n },\n ...(link && { url: link }),\n action_id: 'button-action',\n },\n },\n {\n type: 'context',\n elements: [\n {\n type: 'plain_text',\n text: `Severity: ${severity ?? 'normal'}`,\n emoji: true,\n },\n {\n type: 'plain_text',\n text: `Topic: ${topic ?? 'N/A'}`,\n emoji: true,\n },\n ],\n },\n ];\n}\n\nfunction getColor(severity: NotificationSeverity | undefined) {\n switch (severity) {\n case 'critical':\n return '#FF0000'; // Red\n case 'high':\n return '#FFA500'; // Orange\n case 'low':\n case 'normal':\n default:\n return '#00A699'; // Neutral color\n }\n}\n\n// Simple expiry map for the data loader, which only expects a map that implements set, get, and delete and clear\nexport class ExpiryMap<K, V> extends Map<K, V> {\n #ttlMs: number;\n #timestamps: Map<K, number> = new Map();\n\n constructor(ttlMs: number) {\n super();\n this.#ttlMs = ttlMs;\n }\n\n set(key: K, value: V) {\n const result = super.set(key, value);\n this.#timestamps.set(key, Date.now());\n return result;\n }\n\n get(key: K) {\n if (!this.has(key)) {\n return undefined;\n }\n const timestamp = this.#timestamps.get(key)!;\n if (Date.now() - timestamp > this.#ttlMs) {\n this.delete(key);\n return undefined;\n }\n return super.get(key);\n }\n\n delete(key: K) {\n this.#timestamps.delete(key);\n return super.delete(key);\n }\n\n clear() {\n this.#timestamps.clear();\n return super.clear();\n }\n}\n"],"names":[],"mappings":";;AAuBO,SAAS,sBAAsB,OAAA,EAKT;AAC3B,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,QAAA,EAAU,kBAAiB,GAAI,OAAA;AACzD,EAAA,MAAM,MAAA,GAAA,CAAU,gBAAA,IAAoB,eAAA,EAAiB,OAAO,CAAA;AAE5D,EAAA,MAAM,IAAA,GAAiC;AAAA,IACrC,OAAA;AAAA,IACA,MAAM,OAAA,CAAQ,KAAA;AAAA,IACd,QAAA;AAAA,IACA,WAAA,EAAa;AAAA,MACX;AAAA,QACE,KAAA,EAAO,QAAA,CAAS,OAAA,CAAQ,QAAQ,CAAA;AAAA,QAChC,MAAA;AAAA,QACA,UAAU,OAAA,CAAQ;AAAA;AACpB;AACF,GACF;AAEA,EAAA,OAAO,IAAA;AACT;AAEO,SAAS,gBAAgB,OAAA,EAA4C;AAC1E,EAAA,MAAM,EAAE,WAAA,EAAa,IAAA,EAAM,QAAA,EAAU,OAAM,GAAI,OAAA;AAC/C,EAAA,OAAO;AAAA,IACL;AAAA,MACE,IAAA,EAAM,SAAA;AAAA,MACN,IAAA,EAAM;AAAA,QACJ,IAAA,EAAM,QAAA;AAAA,QACN,M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,CAAK,WAAA,CAAY,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,KAAK,CAAA;AACpC,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAEA,IAAI,GAAA,EAAQ;AACV,IAAA,IAAI,CAAC,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA,EAAG;AAClB,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,WAAA,CAAY,GAAA,CAAI,GAAG,CAAA;AAC1C,IAAA,IAAI,IAAA,CAAK,GAAA,EAAI,GAAI,SAAA,GAAY,KAAK,MAAA,EAAQ;AACxC,MAAA,IAAA,CAAK,OAAO,GAAG,CAAA;AACf,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,OAAO,KAAA,CAAM,IAAI,GAAG,CAAA;AAAA,EACtB;AAAA,EAEA,OAAO,GAAA,EAAQ;AACb,IAAA,IAAA,CAAK,WAAA,CAAY,OAAO,GAAG,CAAA;AAC3B,IAAA,OAAO,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,EACzB;AAAA,EAEA,KAAA,GAAQ;AACN,IAAA,IAAA,CAAK,YAAY,KAAA,EAAM;AACvB,IAAA,OAAO,MAAM,KAAA,EAAM;AAAA,EACrB;AACF;;;;;;"}
@@ -4,11 +4,21 @@ var backendPluginApi = require('@backstage/backend-plugin-api');
4
4
  var pluginNotificationsNode = require('@backstage/plugin-notifications-node');
5
5
  var SlackNotificationProcessor = require('./lib/SlackNotificationProcessor.cjs.js');
6
6
  var pluginCatalogNode = require('@backstage/plugin-catalog-node');
7
+ var extensions = require('./extensions.cjs.js');
7
8
 
8
9
  const notificationsModuleSlack = backendPluginApi.createBackendModule({
9
10
  pluginId: "notifications",
10
11
  moduleId: "slack",
11
12
  register(reg) {
13
+ let blockKitRenderer;
14
+ reg.registerExtensionPoint(extensions.notificationsSlackBlockKitExtensionPoint, {
15
+ setBlockKitRenderer(renderer) {
16
+ if (blockKitRenderer) {
17
+ throw new Error(`Slack block kit renderer was already registered`);
18
+ }
19
+ blockKitRenderer = renderer;
20
+ }
21
+ });
12
22
  reg.registerInit({
13
23
  deps: {
14
24
  auth: backendPluginApi.coreServices.auth,
@@ -22,7 +32,8 @@ const notificationsModuleSlack = backendPluginApi.createBackendModule({
22
32
  SlackNotificationProcessor.SlackNotificationProcessor.fromConfig(config, {
23
33
  auth,
24
34
  logger,
25
- catalog
35
+ catalog,
36
+ blockKitRenderer
26
37
  })
27
38
  );
28
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"module.cjs.js","sources":["../src/module.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 coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { notificationsProcessingExtensionPoint } from '@backstage/plugin-notifications-node';\nimport { SlackNotificationProcessor } from './lib/SlackNotificationProcessor';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\n\n/**\n * The Slack notification processor for use with the notifications plugin.\n * This allows sending of notifications via Slack DMs or to channels.\n *\n * @public\n */\nexport const notificationsModuleSlack = createBackendModule({\n pluginId: 'notifications',\n moduleId: 'slack',\n register(reg) {\n reg.registerInit({\n deps: {\n auth: coreServices.auth,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n catalog: catalogServiceRef,\n notifications: notificationsProcessingExtensionPoint,\n },\n async init({ auth, config, logger, catalog, notifications }) {\n notifications.addProcessor(\n SlackNotificationProcessor.fromConfig(config, {\n auth,\n logger,\n catalog,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendModule","coreServices","catalogServiceRef","notificationsProcessingExtensionPoint","SlackNotificationProcessor"],"mappings":";;;;;;;AA6BO,MAAM,2BAA2BA,oCAAA,CAAoB;AAAA,EAC1D,QAAA,EAAU,eAAA;AAAA,EACV,QAAA,EAAU,OAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,MAAMC,6BAAA,CAAa,IAAA;AAAA,QACnB,QAAQA,6BAAA,CAAa,UAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,OAAA,EAASC,mCAAA;AAAA,QACT,aAAA,EAAeC;AAAA,OACjB;AAAA,MACA,MAAM,KAAK,EAAE,IAAA,EAAM,QAAQ,MAAA,EAAQ,OAAA,EAAS,eAAc,EAAG;AAC3D,QAAA,aAAA,CAAc,YAAA;AAAA,UACZC,qDAAA,CAA2B,WAAW,MAAA,EAAQ;AAAA,YAC5C,IAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.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 coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { notificationsProcessingExtensionPoint } from '@backstage/plugin-notifications-node';\nimport { SlackNotificationProcessor } from './lib/SlackNotificationProcessor';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\nimport {\n notificationsSlackBlockKitExtensionPoint,\n SlackBlockKitRenderer,\n} from './extensions';\n\n/**\n * The Slack notification processor for use with the notifications plugin.\n * This allows sending of notifications via Slack DMs or to channels.\n *\n * @public\n */\nexport const notificationsModuleSlack = createBackendModule({\n pluginId: 'notifications',\n moduleId: 'slack',\n register(reg) {\n let blockKitRenderer: SlackBlockKitRenderer | undefined;\n reg.registerExtensionPoint(notificationsSlackBlockKitExtensionPoint, {\n setBlockKitRenderer(renderer) {\n if (blockKitRenderer) {\n throw new Error(`Slack block kit renderer was already registered`);\n }\n blockKitRenderer = renderer;\n },\n });\n\n reg.registerInit({\n deps: {\n auth: coreServices.auth,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n catalog: catalogServiceRef,\n notifications: notificationsProcessingExtensionPoint,\n },\n async init({ auth, config, logger, catalog, notifications }) {\n notifications.addProcessor(\n SlackNotificationProcessor.fromConfig(config, {\n auth,\n logger,\n catalog,\n blockKitRenderer,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendModule","notificationsSlackBlockKitExtensionPoint","coreServices","catalogServiceRef","notificationsProcessingExtensionPoint","SlackNotificationProcessor"],"mappings":";;;;;;;;AAiCO,MAAM,2BAA2BA,oCAAA,CAAoB;AAAA,EAC1D,QAAA,EAAU,eAAA;AAAA,EACV,QAAA,EAAU,OAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,IAAI,gBAAA;AACJ,IAAA,GAAA,CAAI,uBAAuBC,mDAAA,EAA0C;AAAA,MACnE,oBAAoB,QAAA,EAAU;AAC5B,QAAA,IAAI,gBAAA,EAAkB;AACpB,UAAA,MAAM,IAAI,MAAM,CAAA,+CAAA,CAAiD,CAAA;AAAA,QACnE;AACA,QAAA,gBAAA,GAAmB,QAAA;AAAA,MACrB;AAAA,KACD,CAAA;AAED,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,MAAMC,6BAAA,CAAa,IAAA;AAAA,QACnB,QAAQA,6BAAA,CAAa,UAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,OAAA,EAASC,mCAAA;AAAA,QACT,aAAA,EAAeC;AAAA,OACjB;AAAA,MACA,MAAM,KAAK,EAAE,IAAA,EAAM,QAAQ,MAAA,EAAQ,OAAA,EAAS,eAAc,EAAG;AAC3D,QAAA,aAAA,CAAc,YAAA;AAAA,UACZC,qDAAA,CAA2B,WAAW,MAAA,EAAQ;AAAA,YAC5C,IAAA;AAAA,YACA,MAAA;AAAA,YACA,OAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-notifications-backend-module-slack",
3
- "version": "0.3.1-next.1",
3
+ "version": "0.4.0-next.0",
4
4
  "description": "The slack backend module for the notifications plugin.",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -37,13 +37,13 @@
37
37
  "test": "backstage-cli package test"
38
38
  },
39
39
  "dependencies": {
40
- "@backstage/backend-plugin-api": "1.7.0-next.1",
40
+ "@backstage/backend-plugin-api": "1.7.1-next.0",
41
41
  "@backstage/catalog-model": "1.7.6",
42
42
  "@backstage/config": "1.3.6",
43
43
  "@backstage/errors": "1.2.7",
44
- "@backstage/plugin-catalog-node": "2.0.0-next.1",
45
- "@backstage/plugin-notifications-common": "0.2.0",
46
- "@backstage/plugin-notifications-node": "0.2.23-next.1",
44
+ "@backstage/plugin-catalog-node": "2.1.0-next.0",
45
+ "@backstage/plugin-notifications-common": "0.2.1",
46
+ "@backstage/plugin-notifications-node": "0.2.24-next.0",
47
47
  "@backstage/types": "1.2.2",
48
48
  "@opentelemetry/api": "^1.9.0",
49
49
  "@slack/bolt": "^3.21.4",
@@ -53,10 +53,10 @@
53
53
  "p-throttle": "^4.1.1"
54
54
  },
55
55
  "devDependencies": {
56
- "@backstage/backend-test-utils": "1.11.0-next.1",
57
- "@backstage/cli": "0.35.4-next.2",
58
- "@backstage/plugin-catalog-node": "2.0.0-next.1",
59
- "@backstage/test-utils": "1.7.15-next.2",
56
+ "@backstage/backend-test-utils": "1.11.1-next.0",
57
+ "@backstage/cli": "0.35.5-next.0",
58
+ "@backstage/plugin-catalog-node": "2.1.0-next.0",
59
+ "@backstage/test-utils": "1.7.16-next.0",
60
60
  "@faker-js/faker": "^10.0.0",
61
61
  "msw": "^2.0.0"
62
62
  },