@backstage/plugin-events-node 0.3.0-next.2 → 0.3.1

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,123 @@
1
1
  # @backstage/plugin-events-node
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/backend-plugin-api@0.6.15
9
+
10
+ ## 0.3.0
11
+
12
+ ### Minor Changes
13
+
14
+ - eff3ca9: BREAKING CHANGE: Migrate `EventRouter` implementations from `EventBroker` to `EventsService`.
15
+
16
+ `EventRouter` uses the new `EventsService` instead of the `EventBroker` now,
17
+ causing a breaking change to its signature.
18
+
19
+ All of its extensions and implementations got adjusted accordingly.
20
+ (`SubTopicEventRouter`, `AzureDevOpsEventRouter`, `BitbucketCloudEventRouter`,
21
+ `GerritEventRouter`, `GithubEventRouter`, `GitlabEventRouter`)
22
+
23
+ Required adjustments were made to all backend modules for the new backend system,
24
+ now also making use of the `eventsServiceRef` instead of the `eventsExtensionPoint`.
25
+
26
+ **Migration:**
27
+
28
+ Example for implementations of `SubTopicEventRouter`:
29
+
30
+ ```diff
31
+ import {
32
+ EventParams,
33
+ + EventsService,
34
+ SubTopicEventRouter,
35
+ } from '@backstage/plugin-events-node';
36
+
37
+ export class GithubEventRouter extends SubTopicEventRouter {
38
+ - constructor() {
39
+ - super('github');
40
+ + constructor(options: { events: EventsService }) {
41
+ + super({
42
+ + events: options.events,
43
+ + topic: 'github',
44
+ + });
45
+ }
46
+
47
+ + protected getSubscriberId(): string {
48
+ + return 'GithubEventRouter';
49
+ + }
50
+ +
51
+ // ...
52
+ }
53
+ ```
54
+
55
+ Example for a direct extension of `EventRouter`:
56
+
57
+ ```diff
58
+ class MyEventRouter extends EventRouter {
59
+ - constructor(/* ... */) {
60
+ + constructor(options: {
61
+ + events: EventsService;
62
+ + // ...
63
+ + }) {
64
+ - super();
65
+ // ...
66
+ + super({
67
+ + events: options.events,
68
+ + topics: topics,
69
+ + });
70
+ }
71
+ +
72
+ + protected getSubscriberId(): string {
73
+ + return 'MyEventRouter';
74
+ + }
75
+ -
76
+ - supportsEventTopics(): string[] {
77
+ - return this.topics;
78
+ - }
79
+ }
80
+ ```
81
+
82
+ ### Patch Changes
83
+
84
+ - 56969b6: Add new `EventsService` as well as `eventsServiceRef` for the new backend system.
85
+
86
+ **Summary:**
87
+
88
+ - new:
89
+ `EventsService`, `eventsServiceRef`, `TestEventsService`
90
+ - deprecated:
91
+ `EventBroker`, `EventPublisher`, `EventSubscriber`, `DefaultEventBroker`, `EventsBackend`,
92
+ most parts of `EventsExtensionPoint` (alpha),
93
+ `TestEventBroker`, `TestEventPublisher`, `TestEventSubscriber`
94
+
95
+ Add the `eventsServiceRef` as dependency to your backend plugins
96
+ or backend plugin modules.
97
+
98
+ **Details:**
99
+
100
+ The previous implementation using the `EventsExtensionPoint` was added in the early stages
101
+ of the new backend system and does not respect the plugin isolation.
102
+ This made it not compatible anymore with the new backend system.
103
+
104
+ Additionally, the previous interfaces had some room for simplification,
105
+ supporting less exposure of internal concerns as well.
106
+
107
+ Hereby, this change adds a new `EventsService` interface as replacement for the now deprecated `EventBroker`.
108
+ The new interface does not require any `EventPublisher` or `EventSubscriber` interfaces anymore.
109
+ Instead, it is expected that the `EventsService` gets passed into publishers and subscribers,
110
+ and used internally. There is no need to expose anything of that at their own interfaces.
111
+
112
+ Most parts of `EventsExtensionPoint` (alpha) are deprecated as well and were not usable
113
+ (by other plugins or their modules) anyway.
114
+
115
+ The `DefaultEventBroker` implementation is deprecated and wraps the new `DefaultEventsService` implementation.
116
+ Optionally, an instance can be passed as argument to allow mixed setups to operate alongside.
117
+
118
+ - Updated dependencies
119
+ - @backstage/backend-plugin-api@0.6.14
120
+
3
121
  ## 0.3.0-next.2
4
122
 
5
123
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-node",
3
- "version": "0.3.0-next.2",
3
+ "version": "0.3.1",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
4
 
7
5
  const eventsExtensionPoint = backendPluginApi.createExtensionPoint({
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/extensions.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\n\n/**\n * @alpha\n */\nexport interface EventsExtensionPoint {\n /**\n * @deprecated use `eventsServiceRef` and `eventsServiceFactory` instead\n */\n setEventBroker(eventBroker: EventBroker): void;\n\n /**\n * @deprecated use `EventsService.publish` instead\n */\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): void;\n\n /**\n * @deprecated use `EventsService.subscribe` instead\n */\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void;\n\n addHttpPostIngress(options: HttpPostIngressOptions): void;\n}\n\n/**\n * @alpha\n */\nexport const eventsExtensionPoint = createExtensionPoint<EventsExtensionPoint>({\n id: 'events',\n});\n"],"names":["createExtensionPoint"],"mappings":";;;;;;AAqDO,MAAM,uBAAuBA,qCAA2C,CAAA;AAAA,EAC7E,EAAI,EAAA,QAAA;AACN,CAAC;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/extensions.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\n\n/**\n * @alpha\n */\nexport interface EventsExtensionPoint {\n /**\n * @deprecated use `eventsServiceRef` and `eventsServiceFactory` instead\n */\n setEventBroker(eventBroker: EventBroker): void;\n\n /**\n * @deprecated use `EventsService.publish` instead\n */\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): void;\n\n /**\n * @deprecated use `EventsService.subscribe` instead\n */\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void;\n\n addHttpPostIngress(options: HttpPostIngressOptions): void;\n}\n\n/**\n * @alpha\n */\nexport const eventsExtensionPoint = createExtensionPoint<EventsExtensionPoint>({\n id: 'events',\n});\n"],"names":["createExtensionPoint"],"mappings":";;;;AAqDO,MAAM,uBAAuBA,qCAA2C,CAAA;AAAA,EAC7E,EAAI,EAAA,QAAA;AACN,CAAC;;;;"}
package/dist/alpha.d.ts CHANGED
@@ -24,4 +24,4 @@ interface EventsExtensionPoint {
24
24
  */
25
25
  declare const eventsExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<EventsExtensionPoint>;
26
26
 
27
- export { EventsExtensionPoint, eventsExtensionPoint };
27
+ export { type EventsExtensionPoint, eventsExtensionPoint };
package/dist/index.cjs.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
4
 
7
5
  var __defProp$1 = Object.defineProperty;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/api/EventRouter.ts","../src/api/DefaultEventsService.ts","../src/api/SubTopicEventRouter.ts","../src/service.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { EventParams } from './EventParams';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to a topic and - depending on a set of conditions -\n * republishes the event to another topic.\n *\n * @see {@link https://www.enterpriseintegrationpatterns.com/MessageRouter.html | Message Router pattern}.\n * @public\n */\nexport abstract class EventRouter {\n private readonly events: EventsService;\n private readonly topics: string[];\n private subscribed: boolean = false;\n\n protected constructor(options: { events: EventsService; topics: string[] }) {\n this.events = options.events;\n this.topics = options.topics;\n }\n\n protected abstract getSubscriberId(): string;\n\n protected abstract determineDestinationTopic(\n params: EventParams,\n ): string | undefined;\n\n /**\n * Subscribes itself to the topic(s),\n * after which events potentially can be received\n * and processed by {@link EventRouter.onEvent}.\n */\n async subscribe(): Promise<void> {\n if (this.subscribed) {\n return;\n }\n\n this.subscribed = true;\n\n await this.events.subscribe({\n id: this.getSubscriberId(),\n topics: this.topics,\n onEvent: this.onEvent.bind(this),\n });\n }\n\n async onEvent(params: EventParams): Promise<void> {\n const topic = this.determineDestinationTopic(params);\n\n if (!topic) {\n return;\n }\n\n // republish to different topic\n await this.events.publish({\n ...params,\n topic,\n });\n }\n}\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { EventParams } from './EventParams';\nimport { EventsService, EventsServiceSubscribeOptions } from './EventsService';\n\n/**\n * In-process event broker which will pass the event to all registered subscribers\n * interested in it.\n * Events will not be persisted in any form.\n * Events will not be passed to subscribers at other instances of the same cluster.\n *\n * @public\n */\n// TODO(pjungermann): add opentelemetry? (see plugins/catalog-backend/src/util/opentelemetry.ts, etc.)\nexport class DefaultEventsService implements EventsService {\n private readonly subscribers = new Map<\n string,\n Omit<EventsServiceSubscribeOptions, 'topics'>[]\n >();\n\n private constructor(private readonly logger: LoggerService) {}\n\n static create(options: { logger: LoggerService }): DefaultEventsService {\n return new DefaultEventsService(options.logger);\n }\n\n /**\n * Returns a plugin-scoped context of the `EventService`\n * that ensures to prefix subscriber IDs with the plugin ID.\n *\n * @param pluginId - The plugin that the `EventService` should be created for.\n */\n forPlugin(pluginId: string): EventsService {\n return {\n publish: (params: EventParams): Promise<void> => {\n return this.publish(params);\n },\n subscribe: (options: EventsServiceSubscribeOptions): Promise<void> => {\n return this.subscribe({\n ...options,\n id: `${pluginId}.${options.id}`,\n });\n },\n };\n }\n\n async publish(params: EventParams): Promise<void> {\n this.logger.debug(\n `Event received: topic=${params.topic}, metadata=${JSON.stringify(\n params.metadata,\n )}, payload=${JSON.stringify(params.eventPayload)}`,\n );\n\n if (!this.subscribers.has(params.topic)) {\n return;\n }\n\n const onEventPromises: Promise<void>[] = [];\n this.subscribers.get(params.topic)?.forEach(subscription => {\n onEventPromises.push(\n (async () => {\n try {\n await subscription.onEvent(params);\n } catch (error) {\n this.logger.warn(\n `Subscriber \"${subscription.id}\" failed to process event for topic \"${params.topic}\"`,\n error,\n );\n }\n })(),\n );\n });\n\n await Promise.all(onEventPromises);\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n options.topics.forEach(topic => {\n if (!this.subscribers.has(topic)) {\n this.subscribers.set(topic, []);\n }\n\n this.subscribers.get(topic)!.push({\n id: options.id,\n onEvent: options.onEvent,\n });\n });\n }\n}\n","/*\n * Copyright 2022 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 { EventParams } from './EventParams';\nimport { EventRouter } from './EventRouter';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to the provided (generic) topic\n * and publishes the events under the more concrete sub-topic\n * depending on the implemented logic for determining it.\n * Implementing classes might use information from `metadata`\n * and/or properties within the payload.\n *\n * @public\n */\nexport abstract class SubTopicEventRouter extends EventRouter {\n protected constructor(options: { events: EventsService; topic: string }) {\n super({\n events: options.events,\n topics: [options.topic],\n });\n }\n\n protected abstract determineSubTopic(params: EventParams): string | undefined;\n\n protected determineDestinationTopic(params: EventParams): string | undefined {\n const subTopic = this.determineSubTopic(params);\n return subTopic ? `${params.topic}.${subTopic}` : undefined;\n }\n}\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createServiceFactory,\n createServiceRef,\n} from '@backstage/backend-plugin-api';\nimport { EventsService, DefaultEventsService } from './api';\n\n/**\n * The {@link EventsService} that allows to publish events, and subscribe to topics.\n * Uses the `root` scope so that events can be shared across all plugins, modules, and more.\n *\n * @public\n */\nexport const eventsServiceRef = createServiceRef<EventsService>({\n id: 'events.service',\n scope: 'plugin',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n pluginMetadata: coreServices.pluginMetadata,\n rootLogger: coreServices.rootLogger,\n },\n async createRootContext({ rootLogger }) {\n return DefaultEventsService.create({ logger: rootLogger });\n },\n async factory({ pluginMetadata }, eventsService) {\n return eventsService.forPlugin(pluginMetadata.getId());\n },\n }),\n});\n"],"names":["__publicField","createServiceRef","createServiceFactory","coreServices"],"mappings":";;;;;;;;;;;;AA0BO,MAAe,WAAY,CAAA;AAAA,EAKtB,YAAY,OAAsD,EAAA;AAJ5E,IAAiBA,eAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACjB,IAAAA,eAAA,CAAA,IAAA,EAAQ,YAAsB,EAAA,KAAA,CAAA,CAAA;AAG5B,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,SAA2B,GAAA;AAC/B,IAAA,IAAI,KAAK,UAAY,EAAA;AACnB,MAAA,OAAA;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA,CAAA;AAElB,IAAM,MAAA,IAAA,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AAA,EAAc,EAAA;AACtC,MAAA,OAAO,oBAAqB,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,YAAY,CAAA,CAAA;AAAA,KAC3D;AAAA,IACA,MAAM,OAAA,CAAQ,EAAE,cAAA,IAAkB,aAAe,EAAA;AAC/C,MAAA,OAAO,aAAc,CAAA,SAAA,CAAU,cAAe,CAAA,KAAA,EAAO,CAAA,CAAA;AAAA,KACvD;AAAA,GACD,CAAA;AACL,CAAC;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/api/EventRouter.ts","../src/api/DefaultEventsService.ts","../src/api/SubTopicEventRouter.ts","../src/service.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { EventParams } from './EventParams';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to a topic and - depending on a set of conditions -\n * republishes the event to another topic.\n *\n * @see {@link https://www.enterpriseintegrationpatterns.com/MessageRouter.html | Message Router pattern}.\n * @public\n */\nexport abstract class EventRouter {\n private readonly events: EventsService;\n private readonly topics: string[];\n private subscribed: boolean = false;\n\n protected constructor(options: { events: EventsService; topics: string[] }) {\n this.events = options.events;\n this.topics = options.topics;\n }\n\n protected abstract getSubscriberId(): string;\n\n protected abstract determineDestinationTopic(\n params: EventParams,\n ): string | undefined;\n\n /**\n * Subscribes itself to the topic(s),\n * after which events potentially can be received\n * and processed by {@link EventRouter.onEvent}.\n */\n async subscribe(): Promise<void> {\n if (this.subscribed) {\n return;\n }\n\n this.subscribed = true;\n\n await this.events.subscribe({\n id: this.getSubscriberId(),\n topics: this.topics,\n onEvent: this.onEvent.bind(this),\n });\n }\n\n async onEvent(params: EventParams): Promise<void> {\n const topic = this.determineDestinationTopic(params);\n\n if (!topic) {\n return;\n }\n\n // republish to different topic\n await this.events.publish({\n ...params,\n topic,\n });\n }\n}\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { EventParams } from './EventParams';\nimport { EventsService, EventsServiceSubscribeOptions } from './EventsService';\n\n/**\n * In-process event broker which will pass the event to all registered subscribers\n * interested in it.\n * Events will not be persisted in any form.\n * Events will not be passed to subscribers at other instances of the same cluster.\n *\n * @public\n */\n// TODO(pjungermann): add opentelemetry? (see plugins/catalog-backend/src/util/opentelemetry.ts, etc.)\nexport class DefaultEventsService implements EventsService {\n private readonly subscribers = new Map<\n string,\n Omit<EventsServiceSubscribeOptions, 'topics'>[]\n >();\n\n private constructor(private readonly logger: LoggerService) {}\n\n static create(options: { logger: LoggerService }): DefaultEventsService {\n return new DefaultEventsService(options.logger);\n }\n\n /**\n * Returns a plugin-scoped context of the `EventService`\n * that ensures to prefix subscriber IDs with the plugin ID.\n *\n * @param pluginId - The plugin that the `EventService` should be created for.\n */\n forPlugin(pluginId: string): EventsService {\n return {\n publish: (params: EventParams): Promise<void> => {\n return this.publish(params);\n },\n subscribe: (options: EventsServiceSubscribeOptions): Promise<void> => {\n return this.subscribe({\n ...options,\n id: `${pluginId}.${options.id}`,\n });\n },\n };\n }\n\n async publish(params: EventParams): Promise<void> {\n this.logger.debug(\n `Event received: topic=${params.topic}, metadata=${JSON.stringify(\n params.metadata,\n )}, payload=${JSON.stringify(params.eventPayload)}`,\n );\n\n if (!this.subscribers.has(params.topic)) {\n return;\n }\n\n const onEventPromises: Promise<void>[] = [];\n this.subscribers.get(params.topic)?.forEach(subscription => {\n onEventPromises.push(\n (async () => {\n try {\n await subscription.onEvent(params);\n } catch (error) {\n this.logger.warn(\n `Subscriber \"${subscription.id}\" failed to process event for topic \"${params.topic}\"`,\n error,\n );\n }\n })(),\n );\n });\n\n await Promise.all(onEventPromises);\n }\n\n async subscribe(options: EventsServiceSubscribeOptions): Promise<void> {\n options.topics.forEach(topic => {\n if (!this.subscribers.has(topic)) {\n this.subscribers.set(topic, []);\n }\n\n this.subscribers.get(topic)!.push({\n id: options.id,\n onEvent: options.onEvent,\n });\n });\n }\n}\n","/*\n * Copyright 2022 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 { EventParams } from './EventParams';\nimport { EventRouter } from './EventRouter';\nimport { EventsService } from './EventsService';\n\n/**\n * Subscribes to the provided (generic) topic\n * and publishes the events under the more concrete sub-topic\n * depending on the implemented logic for determining it.\n * Implementing classes might use information from `metadata`\n * and/or properties within the payload.\n *\n * @public\n */\nexport abstract class SubTopicEventRouter extends EventRouter {\n protected constructor(options: { events: EventsService; topic: string }) {\n super({\n events: options.events,\n topics: [options.topic],\n });\n }\n\n protected abstract determineSubTopic(params: EventParams): string | undefined;\n\n protected determineDestinationTopic(params: EventParams): string | undefined {\n const subTopic = this.determineSubTopic(params);\n return subTopic ? `${params.topic}.${subTopic}` : undefined;\n }\n}\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createServiceFactory,\n createServiceRef,\n} from '@backstage/backend-plugin-api';\nimport { EventsService, DefaultEventsService } from './api';\n\n/**\n * The {@link EventsService} that allows to publish events, and subscribe to topics.\n * Uses the `root` scope so that events can be shared across all plugins, modules, and more.\n *\n * @public\n */\nexport const eventsServiceRef = createServiceRef<EventsService>({\n id: 'events.service',\n scope: 'plugin',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n pluginMetadata: coreServices.pluginMetadata,\n rootLogger: coreServices.rootLogger,\n },\n async createRootContext({ rootLogger }) {\n return DefaultEventsService.create({ logger: rootLogger });\n },\n async factory({ pluginMetadata }, eventsService) {\n return eventsService.forPlugin(pluginMetadata.getId());\n },\n }),\n});\n"],"names":["__publicField","createServiceRef","createServiceFactory","coreServices"],"mappings":";;;;;;;;;;AA0BO,MAAe,WAAY,CAAA;AAAA,EAKtB,YAAY,OAAsD,EAAA;AAJ5E,IAAiBA,eAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACjB,IAAAA,eAAA,CAAA,IAAA,EAAQ,YAAsB,EAAA,KAAA,CAAA,CAAA;AAG5B,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAM,SAA2B,GAAA;AAC/B,IAAA,IAAI,KAAK,UAAY,EAAA;AACnB,M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A;AAAA,MAC7B,YAAYA,6BAAa,CAAA,UAAA;AAAA,KAC3B;AAAA,IACA,MAAM,iBAAA,CAAkB,EAAE,UAAA,EAAc,EAAA;AACtC,MAAA,OAAO,oBAAqB,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,YAAY,CAAA,CAAA;AAAA,KAC3D;AAAA,IACA,MAAM,OAAA,CAAQ,EAAE,cAAA,IAAkB,aAAe,EAAA;AAC/C,MAAA,OAAO,aAAc,CAAA,SAAA,CAAU,cAAe,CAAA,KAAA,EAAO,CAAA,CAAA;AAAA,KACvD;AAAA,GACD,CAAA;AACL,CAAC;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -258,4 +258,4 @@ interface EventPublisher {
258
258
  */
259
259
  declare const eventsServiceRef: _backstage_backend_plugin_api.ServiceRef<EventsService, "plugin">;
260
260
 
261
- export { DefaultEventsService, EventBroker, EventParams, EventPublisher, EventRouter, EventSubscriber, EventsService, EventsServiceEventHandler, EventsServiceSubscribeOptions, HttpPostIngressOptions, RequestDetails, RequestRejectionDetails, RequestValidationContext, RequestValidator, SubTopicEventRouter, eventsServiceRef };
261
+ export { DefaultEventsService, type EventBroker, type EventParams, type EventPublisher, EventRouter, type EventSubscriber, type EventsService, type EventsServiceEventHandler, type EventsServiceSubscribeOptions, type HttpPostIngressOptions, type RequestDetails, type RequestRejectionDetails, type RequestValidationContext, type RequestValidator, SubTopicEventRouter, eventsServiceRef };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-node",
3
3
  "description": "The plugin-events-node module for @backstage/plugin-events-backend",
4
- "version": "0.3.0-next.2",
4
+ "version": "0.3.1",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -40,11 +40,11 @@
40
40
  "postpack": "backstage-cli package postpack"
41
41
  },
42
42
  "dependencies": {
43
- "@backstage/backend-plugin-api": "^0.6.14-next.2"
43
+ "@backstage/backend-plugin-api": "^0.6.15"
44
44
  },
45
45
  "devDependencies": {
46
- "@backstage/backend-common": "^0.21.4-next.2",
47
- "@backstage/cli": "^0.25.3-next.2"
46
+ "@backstage/backend-common": "^0.21.5",
47
+ "@backstage/cli": "^0.26.1"
48
48
  },
49
49
  "files": [
50
50
  "dist",