@backstage/plugin-notifications-backend-module-slack 0.4.0-next.1 → 0.4.1-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 +30 -0
- package/dist/index.cjs.js +0 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/lib/SlackNotificationProcessor.cjs.js +7 -6
- package/dist/lib/SlackNotificationProcessor.cjs.js.map +1 -1
- package/dist/module.cjs.js +5 -2
- package/dist/module.cjs.js.map +1 -1
- package/package.json +9 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @backstage/plugin-notifications-backend-module-slack
|
|
2
2
|
|
|
3
|
+
## 0.4.1-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/backend-plugin-api@1.8.1-next.0
|
|
9
|
+
- @backstage/plugin-catalog-node@2.1.1-next.0
|
|
10
|
+
- @backstage/plugin-notifications-node@0.2.25-next.0
|
|
11
|
+
- @backstage/catalog-model@1.7.7
|
|
12
|
+
- @backstage/config@1.3.6
|
|
13
|
+
- @backstage/errors@1.2.7
|
|
14
|
+
- @backstage/types@1.2.2
|
|
15
|
+
- @backstage/plugin-notifications-common@0.2.1
|
|
16
|
+
|
|
17
|
+
## 0.4.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- cd62d78: **BREAKING**: Only send direct messages to user entity recipients. Notifications sent to non-user entities no longer send Slack direct messages to resolved users.
|
|
22
|
+
- 749ba60: Add an extension for custom Slack message layouts
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- e7c6c32: The Slack notification processor now uses the `MetricsService` to create metrics, providing plugin-scoped attribution. `{message}` unit has also been added.
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @backstage/backend-plugin-api@1.8.0
|
|
29
|
+
- @backstage/plugin-catalog-node@2.1.0
|
|
30
|
+
- @backstage/catalog-model@1.7.7
|
|
31
|
+
- @backstage/plugin-notifications-node@0.2.24
|
|
32
|
+
|
|
3
33
|
## 0.4.0-next.1
|
|
4
34
|
|
|
5
35
|
### Minor Changes
|
package/dist/index.cjs.js
CHANGED
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
|
@@ -4,7 +4,6 @@ var catalogModel = require('@backstage/catalog-model');
|
|
|
4
4
|
var config = require('@backstage/config');
|
|
5
5
|
var errors = require('@backstage/errors');
|
|
6
6
|
var types = require('@backstage/types');
|
|
7
|
-
var api = require('@opentelemetry/api');
|
|
8
7
|
var webApi = require('@slack/web-api');
|
|
9
8
|
var DataLoader = require('dataloader');
|
|
10
9
|
var pThrottle = require('p-throttle');
|
|
@@ -62,6 +61,7 @@ class SlackNotificationProcessor {
|
|
|
62
61
|
auth,
|
|
63
62
|
catalog,
|
|
64
63
|
logger,
|
|
64
|
+
metrics,
|
|
65
65
|
slack,
|
|
66
66
|
broadcastChannels,
|
|
67
67
|
broadcastRoutes,
|
|
@@ -101,17 +101,18 @@ class SlackNotificationProcessor {
|
|
|
101
101
|
batchScheduleFn: (cb) => setTimeout(cb, types.durationToMilliseconds({ milliseconds: 10 }))
|
|
102
102
|
}
|
|
103
103
|
);
|
|
104
|
-
|
|
105
|
-
this.messagesSent = meter.createCounter(
|
|
104
|
+
this.messagesSent = metrics.createCounter(
|
|
106
105
|
"notifications.processors.slack.sent.count",
|
|
107
106
|
{
|
|
108
|
-
description: "Number of messages sent to Slack successfully"
|
|
107
|
+
description: "Number of messages sent to Slack successfully",
|
|
108
|
+
unit: "{message}"
|
|
109
109
|
}
|
|
110
110
|
);
|
|
111
|
-
this.messagesFailed =
|
|
111
|
+
this.messagesFailed = metrics.createCounter(
|
|
112
112
|
"notifications.processors.slack.error.count",
|
|
113
113
|
{
|
|
114
|
-
description: "Number of messages that failed to send to Slack"
|
|
114
|
+
description: "Number of messages that failed to send to Slack",
|
|
115
|
+
unit: "{message}"
|
|
115
116
|
}
|
|
116
117
|
);
|
|
117
118
|
const throttle = pThrottle__default.default({
|
|
@@ -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 stringifyEntityRef,\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 const explicitUserEntityRefs = entityRefs\n .filter(entityRef => parseEntityRef(entityRef).kind === 'user')\n .map(entityRef => stringifyEntityRef(parseEntityRef(entityRef)));\n const normalizedUserRef = stringifyEntityRef(\n parseEntityRef(notification.user),\n );\n\n if (!explicitUserEntityRefs.includes(normalizedUserRef)) {\n // This user was resolved from a non-user entity. Skip sending 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","stringifyEntityRef","NotFoundError","isUserEntity"],"mappings":";;;;;;;;;;;;;;;;;;AA0CO,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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AqB;AACvB,MAAA,OAAO,mBAAA,CAAoB,QAAA;AAAA,IAC7B;AAGA,IAAA,MAAM,eAAA,GAAkB,KAAK,eAAA,CAAgB,IAAA;AAAA,MAC3C,CAAA,KAAA,KACE,MAAM,MAAA,KAAW,MAAA,IACjB,MAAM,KAAA,KAAU,MAAA,IAChB,MAAM,MAAA,KAAW;AAAA,KACrB;AAEA,IAAA,IAAI,eAAA,EAAiB;AACnB,MAAA,OAAO,eAAA,CAAgB,QAAA;AAAA,IACzB;AAGA,IAAA,MAAM,cAAA,GAAiB,KAAK,eAAA,CAAgB,IAAA;AAAA,MAC1C,CAAA,KAAA,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 MetricsService,\n MetricsServiceCounter,\n} from '@backstage/backend-plugin-api/alpha';\nimport {\n Entity,\n isUserEntity,\n parseEntityRef,\n stringifyEntityRef,\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 { 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: MetricsServiceCounter;\n private readonly messagesFailed: MetricsServiceCounter;\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 metrics: MetricsService;\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 metrics: MetricsService;\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 metrics,\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 this.messagesSent = metrics.createCounter(\n 'notifications.processors.slack.sent.count',\n {\n description: 'Number of messages sent to Slack successfully',\n unit: '{message}',\n },\n );\n this.messagesFailed = metrics.createCounter(\n 'notifications.processors.slack.error.count',\n {\n description: 'Number of messages that failed to send to Slack',\n unit: '{message}',\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 const explicitUserEntityRefs = entityRefs\n .filter(entityRef => parseEntityRef(entityRef).kind === 'user')\n .map(entityRef => stringifyEntityRef(parseEntityRef(entityRef)));\n const normalizedUserRef = stringifyEntityRef(\n parseEntityRef(notification.user),\n );\n\n if (!explicitUserEntityRefs.includes(normalizedUserRef)) {\n // This user was resolved from a non-user entity. Skip sending 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","pThrottle","parseEntityRef","toChatPostMessageArgs","stringifyEntityRef","NotFoundError","isUserEntity"],"mappings":";;;;;;;;;;;;;;;;;AA6CO,MAAM,0BAAA,CAA4D;AAAA,EACtD,MAAA;AAAA,EACA,OAAA;AAAA,EACA,IAAA;AAAA,EACA,KAAA;AAAA,EACA,iBAAA;AAAA,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
+
var alpha = require('@backstage/backend-plugin-api/alpha');
|
|
4
5
|
var pluginNotificationsNode = require('@backstage/plugin-notifications-node');
|
|
5
6
|
var SlackNotificationProcessor = require('./lib/SlackNotificationProcessor.cjs.js');
|
|
6
7
|
var pluginCatalogNode = require('@backstage/plugin-catalog-node');
|
|
@@ -25,14 +26,16 @@ const notificationsModuleSlack = backendPluginApi.createBackendModule({
|
|
|
25
26
|
config: backendPluginApi.coreServices.rootConfig,
|
|
26
27
|
logger: backendPluginApi.coreServices.logger,
|
|
27
28
|
catalog: pluginCatalogNode.catalogServiceRef,
|
|
28
|
-
notifications: pluginNotificationsNode.notificationsProcessingExtensionPoint
|
|
29
|
+
notifications: pluginNotificationsNode.notificationsProcessingExtensionPoint,
|
|
30
|
+
metrics: alpha.metricsServiceRef
|
|
29
31
|
},
|
|
30
|
-
async init({ auth, config, logger, catalog, notifications }) {
|
|
32
|
+
async init({ auth, config, logger, catalog, notifications, metrics }) {
|
|
31
33
|
notifications.addProcessor(
|
|
32
34
|
SlackNotificationProcessor.SlackNotificationProcessor.fromConfig(config, {
|
|
33
35
|
auth,
|
|
34
36
|
logger,
|
|
35
37
|
catalog,
|
|
38
|
+
metrics,
|
|
36
39
|
blockKitRenderer
|
|
37
40
|
})
|
|
38
41
|
);
|
package/dist/module.cjs.js.map
CHANGED
|
@@ -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';\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":"
|
|
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 { metricsServiceRef } from '@backstage/backend-plugin-api/alpha';\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 metrics: metricsServiceRef,\n },\n async init({ auth, config, logger, catalog, notifications, metrics }) {\n notifications.addProcessor(\n SlackNotificationProcessor.fromConfig(config, {\n auth,\n logger,\n catalog,\n metrics,\n blockKitRenderer,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendModule","notificationsSlackBlockKitExtensionPoint","coreServices","catalogServiceRef","notificationsProcessingExtensionPoint","metricsServiceRef","SlackNotificationProcessor"],"mappings":";;;;;;;;;AAkCO,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,6DAAA;AAAA,QACf,OAAA,EAASC;AAAA,OACX;AAAA,MACA,MAAM,KAAK,EAAE,IAAA,EAAM,QAAQ,MAAA,EAAQ,OAAA,EAAS,aAAA,EAAe,OAAA,EAAQ,EAAG;AACpE,QAAA,aAAA,CAAc,YAAA;AAAA,UACZC,qDAAA,CAA2B,WAAW,MAAA,EAAQ;AAAA,YAC5C,IAAA;AAAA,YACA,MAAA;AAAA,YACA,OAAA;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.4.
|
|
3
|
+
"version": "0.4.1-next.0",
|
|
4
4
|
"description": "The slack backend module for the notifications plugin.",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -37,15 +37,14 @@
|
|
|
37
37
|
"test": "backstage-cli package test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@backstage/backend-plugin-api": "1.8.
|
|
41
|
-
"@backstage/catalog-model": "1.7.
|
|
40
|
+
"@backstage/backend-plugin-api": "1.8.1-next.0",
|
|
41
|
+
"@backstage/catalog-model": "1.7.7",
|
|
42
42
|
"@backstage/config": "1.3.6",
|
|
43
43
|
"@backstage/errors": "1.2.7",
|
|
44
|
-
"@backstage/plugin-catalog-node": "2.1.
|
|
44
|
+
"@backstage/plugin-catalog-node": "2.1.1-next.0",
|
|
45
45
|
"@backstage/plugin-notifications-common": "0.2.1",
|
|
46
|
-
"@backstage/plugin-notifications-node": "0.2.
|
|
46
|
+
"@backstage/plugin-notifications-node": "0.2.25-next.0",
|
|
47
47
|
"@backstage/types": "1.2.2",
|
|
48
|
-
"@opentelemetry/api": "^1.9.0",
|
|
49
48
|
"@slack/bolt": "^3.21.4",
|
|
50
49
|
"@slack/types": "^2.14.0",
|
|
51
50
|
"@slack/web-api": "^7.5.0",
|
|
@@ -53,10 +52,10 @@
|
|
|
53
52
|
"p-throttle": "^4.1.1"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@backstage/backend-test-utils": "1.11.
|
|
57
|
-
"@backstage/cli": "0.36.
|
|
58
|
-
"@backstage/plugin-catalog-node": "2.1.
|
|
59
|
-
"@backstage/test-utils": "1.7.
|
|
55
|
+
"@backstage/backend-test-utils": "1.11.2-next.0",
|
|
56
|
+
"@backstage/cli": "0.36.1-next.0",
|
|
57
|
+
"@backstage/plugin-catalog-node": "2.1.1-next.0",
|
|
58
|
+
"@backstage/test-utils": "1.7.17-next.0",
|
|
60
59
|
"@faker-js/faker": "^10.0.0",
|
|
61
60
|
"msw": "^2.0.0"
|
|
62
61
|
},
|