@backstage/plugin-events-backend 0.2.5-next.1 → 0.2.5-next.3

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,29 @@
1
1
  # @backstage/plugin-events-backend
2
2
 
3
+ ## 0.2.5-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 3538d9ad2c4: Export `DefaultEventBroker` to allow decoupling of the catalog and events backends in the `example-backend`.
8
+
9
+ Please look at `plugins/events-backend/README.md` for the currently advised way to set up the event backend and catalog providers.
10
+
11
+ - Updated dependencies
12
+ - @backstage/backend-common@0.18.4-next.2
13
+ - @backstage/backend-plugin-api@0.5.1-next.2
14
+ - @backstage/config@1.0.7
15
+ - @backstage/plugin-events-node@0.2.5-next.2
16
+
17
+ ## 0.2.5-next.2
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+ - @backstage/backend-common@0.18.4-next.2
23
+ - @backstage/backend-plugin-api@0.5.1-next.2
24
+ - @backstage/config@1.0.7
25
+ - @backstage/plugin-events-node@0.2.5-next.2
26
+
3
27
  ## 0.2.5-next.1
4
28
 
5
29
  ### Patch Changes
package/README.md CHANGED
@@ -6,7 +6,7 @@ This plugin provides the wiring of all extension points
6
6
  for managing events as defined by [plugin-events-node](../events-node)
7
7
  including backend plugin `EventsPlugin` and `EventsBackend`.
8
8
 
9
- Additionally, it uses a simple in-memory implementation for
9
+ Additionally, it uses a simple in-process implementation for
10
10
  the `EventBroker` by default which you can replace with a more sophisticated
11
11
  implementation of your choice as you need (e.g., via module).
12
12
 
@@ -24,68 +24,104 @@ to the used event broker.
24
24
  yarn add --cwd packages/backend @backstage/plugin-events-backend
25
25
  ```
26
26
 
27
- Add a file [`packages/backend/src/plugins/events.ts`](../../packages/backend/src/plugins/events.ts)
28
- to your Backstage project.
27
+ ### Event Broker
29
28
 
30
- There, you can add all publishers, subscribers, etc. you want.
29
+ First you will need to add and implementation of the `EventBroker` interface to the backend plugin environment.
30
+ This will allow event broker instance any backend plugins to publish and subscribe to events in order to communicate
31
+ between them.
31
32
 
32
- Additionally, add the events plugin to your backend.
33
+ Add the following to `makeCreateEnv`
33
34
 
34
35
  ```diff
35
36
  // packages/backend/src/index.ts
36
- // [...]
37
- +import events from './plugins/events';
38
- // [...]
39
- + const eventsEnv = useHotMemoize(module, () => createEnv('events'));
40
- // [...]
41
- + apiRouter.use('/events', await events(eventsEnv, []));
42
- // [...]
37
+ + const eventBroker = new DefaultEventBroker(root.child({ type: 'plugin' }));
43
38
  ```
44
39
 
45
- ### With Event-based Entity Providers
46
-
47
- In case you use event-based `EntityProviders`,
48
- you may need something like the following:
40
+ Then update plugin environment to include the event broker.
49
41
 
50
42
  ```diff
51
- // packages/backend/src/index.ts
52
- - apiRouter.use('/events', await events(eventsEnv, []));
53
- + apiRouter.use('/events', await events(eventsEnv, eventBasedEntityProviders));
43
+ // packages/backend/src/types.ts
44
+ + eventBroker: EventBroker;
54
45
  ```
55
46
 
56
- as well as a file
57
- [`packages/backend/src/plugins/catalogEventBasedProviders.ts`](../../packages/backend/src/plugins/catalogEventBasedProviders.ts)
58
- which contains event-based entity providers.
47
+ ### Publishing and Subscribing to events with the broker
59
48
 
60
- In case you don't have this dependency added yet:
49
+ Backend plugins are passed the event broker in the plugin environment at startup of the application. The plugin can
50
+ make use of this to communicate between parts of the application.
61
51
 
62
- ```bash
63
- # From your Backstage root directory
64
- yarn add --cwd packages/backend @backstage/plugin-events-backend
52
+ Here is an example of a plugin publishing a payload to a topic.
53
+
54
+ ```typescript jsx
55
+ export default async function createPlugin(
56
+ env: PluginEnvironment,
57
+ ): Promise<Router> {
58
+ env.eventBroker.publish({
59
+ topic: 'publish.example',
60
+ eventPayload: { message: 'Hello, World!' },
61
+ metadata: {},
62
+ });
63
+ }
65
64
  ```
66
65
 
67
- ```diff
68
- // packages/backend/src/plugins/catalog.ts
69
- import { CatalogBuilder } from '@backstage/plugin-catalog-backend';
70
- +import { EntityProvider } from '@backstage/plugin-catalog-node';
71
- import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend';
72
- import { Router } from 'express';
73
- import { PluginEnvironment } from '../types';
66
+ Here is an example of a plugin subscribing to a topic.
67
+
68
+ ```typescript jsx
69
+ export default async function createPlugin(
70
+ env: PluginEnvironment,
71
+ ): Promise<Router> {
72
+ env.eventBroker.subscribe([
73
+ {
74
+ supportsEventTopics: ['publish.example'],
75
+ onEvent: async (params: EventParams) => {
76
+ env.logger.info(`receieved ${params.topic} event`);
77
+ },
78
+ },
79
+ ]);
80
+ }
81
+ ```
74
82
 
75
- export default async function createPlugin(
76
- env: PluginEnvironment,
77
- + providers?: Array<EntityProvider>,
78
- ): Promise<Router> {
79
- const builder = await CatalogBuilder.create(env);
80
- builder.addProcessor(new ScaffolderEntitiesProcessor());
81
- + builder.addEntityProvider(providers ?? []);
82
- const { processingEngine, router } = await builder.build();
83
- await processingEngine.start();
84
- return router;
85
- }
83
+ ### Implementing an `EventSubscriber` class
84
+
85
+ More complex solutions might need the creation of a class that implements the `EventSubscriber` interface. e.g.
86
+
87
+ ```typescript jsx
88
+ import { EventSubscriber } from "./EventSubscriber";
89
+
90
+ class ExampleSubscriber implements EventSubscriber {
91
+ ...
92
+
93
+ supportsEventTopics() {
94
+ return ['publish.example']
95
+ }
96
+
97
+ async onEvent(params: EventParams) {
98
+ env.logger.info(`receieved ${params.topic} event`)
99
+ }
100
+ }
86
101
  ```
87
102
 
88
- ## Configuration
103
+ ### Events Backend
104
+
105
+ The events backend plugin provides a router to handler http events and publish the http requests onto the event
106
+ broker.
107
+
108
+ To configure it add a file [`packages/backend/src/plugins/events.ts`](../../packages/backend/src/plugins/events.ts)
109
+ to your Backstage project.
110
+
111
+ Additionally, add the events plugin to your backend.
112
+
113
+ ```diff
114
+ // packages/backend/src/index.ts
115
+ // [...]
116
+ +import events from './plugins/events';
117
+ // [...]
118
+ + const eventsEnv = useHotMemoize(module, () => createEnv('events'));
119
+ // [...]
120
+ + apiRouter.use('/events', await events(eventsEnv));
121
+ // [...]
122
+ ```
123
+
124
+ #### Configuration
89
125
 
90
126
  In order to create HTTP endpoints to receive events for a certain
91
127
  topic, you need to add them at your configuration:
@@ -115,6 +151,34 @@ in combination with suitable event subscribers.
115
151
 
116
152
  However, it is not limited to these use cases.
117
153
 
154
+ ### Event-based Entity Providers
155
+
156
+ You can implement the `EventSubscriber` interface on an `EntityProviders` to allow it to handle events from other plugins e.g. the event backend plugin
157
+ mentioned above.
158
+
159
+ Assuming you have configured the `eventBroker` into the `PluginEnvironment` you can pass the broker to the entity provider for it to subscribe.
160
+
161
+ ```diff
162
+ // packages/backend/src/plugins/catalog.ts
163
+ import { CatalogBuilder } from '@backstage/plugin-catalog-backend';
164
+ +import { DemoEventBasedEntityProvider } from './DemoEventBasedEntityProvider';
165
+ import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend';
166
+ import { Router } from 'express';
167
+ import { PluginEnvironment } from '../types';
168
+
169
+ export default async function createPlugin(
170
+ env: PluginEnvironment,
171
+ ): Promise<Router> {
172
+ const builder = await CatalogBuilder.create(env);
173
+ builder.addProcessor(new ScaffolderEntitiesProcessor());
174
+ + const demoProvider = new DemoEventBasedEntityProvider({ logger: env.logger, topics: ['example'], eventBroker: env.eventBroker });
175
+ + builder.addEntityProvider(demoProvider);
176
+ const { processingEngine, router } = await builder.build();
177
+ await processingEngine.start();
178
+ return router;
179
+ }
180
+ ```
181
+
118
182
  ## Use Cases
119
183
 
120
184
  ### Custom Event Broker
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend",
3
- "version": "0.2.5-next.1",
3
+ "version": "0.2.5-next.3",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
6
  var backendCommon = require('@backstage/backend-common');
7
7
  var alpha = require('@backstage/plugin-events-node/alpha');
8
- var HttpPostIngressEventPublisher = require('./cjs/HttpPostIngressEventPublisher-5c827dfa.cjs.js');
8
+ var HttpPostIngressEventPublisher = require('./cjs/HttpPostIngressEventPublisher-747e2764.cjs.js');
9
9
  var Router = require('express-promise-router');
10
10
  require('express');
11
11
 
@@ -96,7 +96,7 @@ const eventsPlugin = backendPluginApi.createBackendPlugin({
96
96
  const eventsRouter = Router__default["default"]();
97
97
  http.bind(eventsRouter);
98
98
  router.use(eventsRouter);
99
- const eventBroker = (_a = extensionPoint.eventBroker) != null ? _a : new HttpPostIngressEventPublisher.InMemoryEventBroker(winstonLogger);
99
+ const eventBroker = (_a = extensionPoint.eventBroker) != null ? _a : new HttpPostIngressEventPublisher.DefaultEventBroker(winstonLogger);
100
100
  eventBroker.subscribe(extensionPoint.subscribers);
101
101
  [extensionPoint.publishers, http].flat().forEach((publisher) => publisher.setEventBroker(eventBroker));
102
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/service/EventsPlugin.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 {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport {\n eventsExtensionPoint,\n EventsExtensionPoint,\n} from '@backstage/plugin-events-node/alpha';\nimport {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\nimport { InMemoryEventBroker } from './InMemoryEventBroker';\nimport Router from 'express-promise-router';\nimport { HttpPostIngressEventPublisher } from './http';\n\nclass EventsExtensionPointImpl implements EventsExtensionPoint {\n #eventBroker: EventBroker | undefined;\n #httpPostIngresses: HttpPostIngressOptions[] = [];\n #publishers: EventPublisher[] = [];\n #subscribers: EventSubscriber[] = [];\n\n setEventBroker(eventBroker: EventBroker): void {\n this.#eventBroker = eventBroker;\n }\n\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): void {\n this.#publishers.push(...publishers.flat());\n }\n\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void {\n this.#subscribers.push(...subscribers.flat());\n }\n\n addHttpPostIngress(options: HttpPostIngressOptions) {\n this.#httpPostIngresses.push(options);\n }\n\n get eventBroker() {\n return this.#eventBroker;\n }\n\n get publishers() {\n return this.#publishers;\n }\n\n get subscribers() {\n return this.#subscribers;\n }\n\n get httpPostIngresses() {\n return this.#httpPostIngresses;\n }\n}\n\n/**\n * Events plugin\n *\n * @alpha\n */\nexport const eventsPlugin = createBackendPlugin({\n pluginId: 'events',\n register(env) {\n const extensionPoint = new EventsExtensionPointImpl();\n env.registerExtensionPoint(eventsExtensionPoint, extensionPoint);\n\n env.registerInit({\n deps: {\n config: coreServices.config,\n logger: coreServices.logger,\n router: coreServices.httpRouter,\n },\n async init({ config, logger, router }) {\n const winstonLogger = loggerToWinstonLogger(logger);\n\n const ingresses = Object.fromEntries(\n extensionPoint.httpPostIngresses.map(ingress => [\n ingress.topic,\n ingress as Omit<HttpPostIngressOptions, 'topic'>,\n ]),\n );\n\n const http = HttpPostIngressEventPublisher.fromConfig({\n config,\n ingresses,\n logger: winstonLogger,\n });\n const eventsRouter = Router();\n http.bind(eventsRouter);\n router.use(eventsRouter);\n\n const eventBroker =\n extensionPoint.eventBroker ?? new InMemoryEventBroker(winstonLogger);\n\n eventBroker.subscribe(extensionPoint.subscribers);\n [extensionPoint.publishers, http]\n .flat()\n .forEach(publisher => publisher.setEventBroker(eventBroker));\n },\n });\n },\n});\n"],"names":["createBackendPlugin","eventsExtensionPoint","coreServices","loggerToWinstonLogger","HttpPostIngressEventPublisher","Router","InMemoryEventBroker"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,YAAA,EAAA,kBAAA,EAAA,WAAA,EAAA,YAAA,CAAA;AAmCA,MAAM,wBAAyD,CAAA;AAAA,EAA/D,WAAA,GAAA;AACE,IAAA,YAAA,CAAA,IAAA,EAAA,YAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AACA,IAAA,YAAA,CAAA,IAAA,EAAA,kBAAA,EAA+C,EAAC,CAAA,CAAA;AAChD,IAAA,YAAA,CAAA,IAAA,EAAA,WAAA,EAAgC,EAAC,CAAA,CAAA;AACjC,IAAA,YAAA,CAAA,IAAA,EAAA,YAAA,EAAkC,EAAC,CAAA,CAAA;AAAA,GAAA;AAAA,EAEnC,eAAe,WAAgC,EAAA;AAC7C,IAAA,YAAA,CAAA,IAAA,EAAK,YAAe,EAAA,WAAA,CAAA,CAAA;AAAA,GACtB;AAAA,EAEA,iBACK,UACG,EAAA;AACN,IAAA,YAAA,CAAA,IAAA,EAAK,WAAY,CAAA,CAAA,IAAA,CAAK,GAAG,UAAA,CAAW,MAAM,CAAA,CAAA;AAAA,GAC5C;AAAA,EAEA,kBACK,WACG,EAAA;AACN,IAAA,YAAA,CAAA,IAAA,EAAK,YAAa,CAAA,CAAA,IAAA,CAAK,GAAG,WAAA,CAAY,MAAM,CAAA,CAAA;AAAA,GAC9C;AAAA,EAEA,mBAAmB,OAAiC,EAAA;AAClD,IAAK,YAAA,CAAA,IAAA,EAAA,kBAAA,CAAA,CAAmB,KAAK,OAAO,CAAA,CAAA;AAAA,GACtC;AAAA,EAEA,IAAI,WAAc,GAAA;AAChB,IAAA,OAAO,YAAK,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AAAA,GACd;AAAA,EAEA,IAAI,UAAa,GA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AAM,MAAA,IAAA,GAAOC,4DAA8B,UAAW,CAAA;AAAA,UACpD,MAAA;AAAA,UACA,SAAA;AAAA,UACA,MAAQ,EAAA,aAAA;AAAA,SACT,CAAA,CAAA;AACD,QAAA,MAAM,eAAeC,0BAAO,EAAA,CAAA;AAC5B,QAAA,IAAA,CAAK,KAAK,YAAY,CAAA,CAAA;AACtB,QAAA,MAAA,CAAO,IAAI,YAAY,CAAA,CAAA;AAEvB,QAAA,MAAM,eACJ,EAAe,GAAA,cAAA,CAAA,WAAA,KAAf,IAA8B,GAAA,EAAA,GAAA,IAAIC,kDAAoB,aAAa,CAAA,CAAA;AAErE,QAAY,WAAA,CAAA,SAAA,CAAU,eAAe,WAAW,CAAA,CAAA;AAChD,QAAC,CAAA,cAAA,CAAe,UAAY,EAAA,IAAI,CAC7B,CAAA,IAAA,EACA,CAAA,OAAA,CAAQ,CAAa,SAAA,KAAA,SAAA,CAAU,cAAe,CAAA,WAAW,CAAC,CAAA,CAAA;AAAA,OAC/D;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/service/EventsPlugin.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 {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport {\n eventsExtensionPoint,\n EventsExtensionPoint,\n} from '@backstage/plugin-events-node/alpha';\nimport {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\nimport { DefaultEventBroker } from './DefaultEventBroker';\nimport Router from 'express-promise-router';\nimport { HttpPostIngressEventPublisher } from './http';\n\nclass EventsExtensionPointImpl implements EventsExtensionPoint {\n #eventBroker: EventBroker | undefined;\n #httpPostIngresses: HttpPostIngressOptions[] = [];\n #publishers: EventPublisher[] = [];\n #subscribers: EventSubscriber[] = [];\n\n setEventBroker(eventBroker: EventBroker): void {\n this.#eventBroker = eventBroker;\n }\n\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): void {\n this.#publishers.push(...publishers.flat());\n }\n\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void {\n this.#subscribers.push(...subscribers.flat());\n }\n\n addHttpPostIngress(options: HttpPostIngressOptions) {\n this.#httpPostIngresses.push(options);\n }\n\n get eventBroker() {\n return this.#eventBroker;\n }\n\n get publishers() {\n return this.#publishers;\n }\n\n get subscribers() {\n return this.#subscribers;\n }\n\n get httpPostIngresses() {\n return this.#httpPostIngresses;\n }\n}\n\n/**\n * Events plugin\n *\n * @alpha\n */\nexport const eventsPlugin = createBackendPlugin({\n pluginId: 'events',\n register(env) {\n const extensionPoint = new EventsExtensionPointImpl();\n env.registerExtensionPoint(eventsExtensionPoint, extensionPoint);\n\n env.registerInit({\n deps: {\n config: coreServices.config,\n logger: coreServices.logger,\n router: coreServices.httpRouter,\n },\n async init({ config, logger, router }) {\n const winstonLogger = loggerToWinstonLogger(logger);\n\n const ingresses = Object.fromEntries(\n extensionPoint.httpPostIngresses.map(ingress => [\n ingress.topic,\n ingress as Omit<HttpPostIngressOptions, 'topic'>,\n ]),\n );\n\n const http = HttpPostIngressEventPublisher.fromConfig({\n config,\n ingresses,\n logger: winstonLogger,\n });\n const eventsRouter = Router();\n http.bind(eventsRouter);\n router.use(eventsRouter);\n\n const eventBroker =\n extensionPoint.eventBroker ?? new DefaultEventBroker(winstonLogger);\n\n eventBroker.subscribe(extensionPoint.subscribers);\n [extensionPoint.publishers, http]\n .flat()\n .forEach(publisher => publisher.setEventBroker(eventBroker));\n },\n });\n },\n});\n"],"names":["createBackendPlugin","eventsExtensionPoint","coreServices","loggerToWinstonLogger","HttpPostIngressEventPublisher","Router","DefaultEventBroker"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,YAAA,EAAA,kBAAA,EAAA,WAAA,EAAA,YAAA,CAAA;AAmCA,MAAM,wBAAyD,CAAA;AAAA,EAA/D,WAAA,GAAA;AACE,IAAA,YAAA,CAAA,IAAA,EAAA,YAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AACA,IAAA,YAAA,CAAA,IAAA,EAAA,kBAAA,EAA+C,EAAC,CAAA,CAAA;AAChD,IAAA,YAAA,CAAA,IAAA,EAAA,WAAA,EAAgC,EAAC,CAAA,CAAA;AACjC,IAAA,YAAA,CAAA,IAAA,EAAA,YAAA,EAAkC,EAAC,CAAA,CAAA;AAAA,GAAA;AAAA,EAEnC,eAAe,WAAgC,EAAA;AAC7C,IAAA,YAAA,CAAA,IAAA,EAAK,YAAe,EAAA,WAAA,CAAA,CAAA;AAAA,GACtB;AAAA,EAEA,iBACK,UACG,EAAA;AACN,IAAA,YAAA,CAAA,IAAA,EAAK,WAAY,CAAA,CAAA,IAAA,CAAK,GAAG,UAAA,CAAW,MAAM,CAAA,CAAA;AAAA,GAC5C;AAAA,EAEA,kBACK,WACG,EAAA;AACN,IAAA,YAAA,CAAA,IAAA,EAAK,YAAa,CAAA,CAAA,IAAA,CAAK,GAAG,WAAA,CAAY,MAAM,CAAA,CAAA;AAAA,GAC9C;AAAA,EAEA,mBAAmB,OAAiC,EAAA;AAClD,IAAK,YAAA,CAAA,IAAA,EAAA,kBAAA,CAAA,CAAmB,KAAK,OAAO,CAAA,CAAA;AAAA,GACtC;AAAA,EAEA,IAAI,WAAc,GAAA;AAChB,IAAA,OAAO,YAAK,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AAAA,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,CAAA;AAAA,SACH,CAAA;AAEA,QAAM,MAAA,IAAA,GAAOC,4DAA8B,UAAW,CAAA;AAAA,UACpD,MAAA;AAAA,UACA,SAAA;AAAA,UACA,MAAQ,EAAA,aAAA;AAAA,SACT,CAAA,CAAA;AACD,QAAA,MAAM,eAAeC,0BAAO,EAAA,CAAA;AAC5B,QAAA,IAAA,CAAK,KAAK,YAAY,CAAA,CAAA;AACtB,QAAA,MAAA,CAAO,IAAI,YAAY,CAAA,CAAA;AAEvB,QAAA,MAAM,eACJ,EAAe,GAAA,cAAA,CAAA,WAAA,KAAf,IAA8B,GAAA,EAAA,GAAA,IAAIC,iDAAmB,aAAa,CAAA,CAAA;AAEpE,QAAY,WAAA,CAAA,SAAA,CAAU,eAAe,WAAW,CAAA,CAAA;AAChD,QAAC,CAAA,cAAA,CAAe,UAAY,EAAA,IAAI,CAC7B,CAAA,IAAA,EACA,CAAA,OAAA,CAAQ,CAAa,SAAA,KAAA,SAAA,CAAU,cAAe,CAAA,WAAW,CAAC,CAAA,CAAA;AAAA,OAC/D;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
@@ -9,7 +9,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
9
9
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
10
10
  var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
11
11
 
12
- class InMemoryEventBroker {
12
+ class DefaultEventBroker {
13
13
  constructor(logger) {
14
14
  this.logger = logger;
15
15
  this.subscribers = {};
@@ -141,6 +141,6 @@ class HttpPostIngressEventPublisher {
141
141
  }
142
142
  }
143
143
 
144
+ exports.DefaultEventBroker = DefaultEventBroker;
144
145
  exports.HttpPostIngressEventPublisher = HttpPostIngressEventPublisher;
145
- exports.InMemoryEventBroker = InMemoryEventBroker;
146
- //# sourceMappingURL=HttpPostIngressEventPublisher-5c827dfa.cjs.js.map
146
+ //# sourceMappingURL=HttpPostIngressEventPublisher-747e2764.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpPostIngressEventPublisher-747e2764.cjs.js","sources":["../../src/service/DefaultEventBroker.ts","../../src/service/http/validation/RequestValidationContextImpl.ts","../../src/service/http/HttpPostIngressEventPublisher.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 {\n EventBroker,\n EventParams,\n EventSubscriber,\n} from '@backstage/plugin-events-node';\nimport { Logger } from 'winston';\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 *\n * @public\n */\n// TODO(pjungermann): add prom metrics? (see plugins/catalog-backend/src/util/metrics.ts, etc.)\nexport class DefaultEventBroker implements EventBroker {\n constructor(private readonly logger: Logger) {}\n\n private readonly subscribers: {\n [topic: string]: EventSubscriber[];\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 const subscribed = this.subscribers[params.topic] ?? [];\n await Promise.all(\n subscribed.map(async subscriber => {\n try {\n await subscriber.onEvent(params);\n } catch (error) {\n this.logger.error(\n `Subscriber \"${subscriber.constructor.name}\" failed to process event`,\n error,\n );\n }\n }),\n );\n }\n\n subscribe(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void {\n subscribers.flat().forEach(subscriber => {\n subscriber.supportsEventTopics().forEach(topic => {\n this.subscribers[topic] = this.subscribers[topic] ?? [];\n this.subscribers[topic].push(subscriber);\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 {\n RequestRejectionDetails,\n RequestValidationContext,\n} from '@backstage/plugin-events-node';\n\nexport class RequestValidationContextImpl implements RequestValidationContext {\n #rejectionDetails: RequestRejectionDetails | undefined;\n\n reject(details?: Partial<RequestRejectionDetails>): void {\n this.#rejectionDetails = {\n status: details?.status ?? 403,\n payload: details?.payload ?? {},\n };\n }\n\n wasRejected(): boolean {\n return this.#rejectionDetails !== undefined;\n }\n\n get rejectionDetails() {\n return this.#rejectionDetails;\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 { errorHandler } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport {\n EventBroker,\n EventPublisher,\n HttpPostIngressOptions,\n RequestValidator,\n} from '@backstage/plugin-events-node';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { Logger } from 'winston';\nimport { RequestValidationContextImpl } from './validation';\n\n/**\n * Publishes events received from their origin (e.g., webhook events from an SCM system)\n * via HTTP POST endpoint and passes the request body as event payload to the registered subscribers.\n *\n * @public\n */\n// TODO(pjungermann): add prom metrics? (see plugins/catalog-backend/src/util/metrics.ts, etc.)\nexport class HttpPostIngressEventPublisher implements EventPublisher {\n private eventBroker?: EventBroker;\n\n static fromConfig(env: {\n config: Config;\n ingresses?: { [topic: string]: Omit<HttpPostIngressOptions, 'topic'> };\n logger: Logger;\n }): HttpPostIngressEventPublisher {\n const topics =\n env.config.getOptionalStringArray('events.http.topics') ?? [];\n\n const ingresses = env.ingresses ?? {};\n topics.forEach(topic => {\n // don't overwrite topic settings\n // (e.g., added at the config as well as argument)\n if (!ingresses[topic]) {\n ingresses[topic] = {};\n }\n });\n\n return new HttpPostIngressEventPublisher(env.logger, ingresses);\n }\n\n private constructor(\n private readonly logger: Logger,\n private readonly ingresses: {\n [topic: string]: Omit<HttpPostIngressOptions, 'topic'>;\n },\n ) {}\n\n bind(router: express.Router): void {\n router.use('/http', this.createRouter(this.ingresses));\n }\n\n async setEventBroker(eventBroker: EventBroker): Promise<void> {\n this.eventBroker = eventBroker;\n }\n\n private createRouter(ingresses: {\n [topic: string]: Omit<HttpPostIngressOptions, 'topic'>;\n }): express.Router {\n const router = Router();\n router.use(express.json());\n\n Object.keys(ingresses).forEach(topic =>\n this.addRouteForTopic(router, topic, ingresses[topic].validator),\n );\n\n router.use(errorHandler());\n return router;\n }\n\n private addRouteForTopic(\n router: express.Router,\n topic: string,\n validator?: RequestValidator,\n ): void {\n const path = `/${topic}`;\n\n router.post(path, async (request, response) => {\n const requestDetails = {\n body: request.body,\n headers: request.headers,\n };\n const context = new RequestValidationContextImpl();\n await validator?.(requestDetails, context);\n if (context.wasRejected()) {\n response\n .status(context.rejectionDetails!.status)\n .json(context.rejectionDetails!.payload);\n return;\n }\n\n const eventPayload = request.body;\n await this.eventBroker!.publish({\n topic,\n eventPayload,\n metadata: request.headers,\n });\n\n response.status(202).json({ status: 'accepted' });\n });\n\n // TODO(pjungermann): We don't really know the externally defined path prefix here,\n // however it is more useful for users to have it. Is there a better way?\n this.logger.info(`Registered /api/events/http${path} to receive events`);\n }\n}\n"],"names":["Router","express","errorHandler"],"mappings":";;;;;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 -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var HttpPostIngressEventPublisher = require('./cjs/HttpPostIngressEventPublisher-5c827dfa.cjs.js');
5
+ var HttpPostIngressEventPublisher = require('./cjs/HttpPostIngressEventPublisher-747e2764.cjs.js');
6
6
  require('@backstage/backend-common');
7
7
  require('express');
8
8
  require('express-promise-router');
@@ -11,7 +11,7 @@ class EventsBackend {
11
11
  constructor(logger) {
12
12
  this.publishers = [];
13
13
  this.subscribers = [];
14
- this.eventBroker = new HttpPostIngressEventPublisher.InMemoryEventBroker(logger);
14
+ this.eventBroker = new HttpPostIngressEventPublisher.DefaultEventBroker(logger);
15
15
  }
16
16
  setEventBroker(eventBroker) {
17
17
  this.eventBroker = eventBroker;
@@ -36,6 +36,7 @@ class EventsBackend {
36
36
  }
37
37
  }
38
38
 
39
+ exports.DefaultEventBroker = HttpPostIngressEventPublisher.DefaultEventBroker;
39
40
  exports.HttpPostIngressEventPublisher = HttpPostIngressEventPublisher.HttpPostIngressEventPublisher;
40
41
  exports.EventsBackend = EventsBackend;
41
42
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/service/EventsBackend.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 {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n} from '@backstage/plugin-events-node';\nimport { Logger } from 'winston';\nimport { InMemoryEventBroker } from './InMemoryEventBroker';\n\n/**\n * A builder that helps wire up all component parts of the event management.\n *\n * @public\n */\nexport class EventsBackend {\n private eventBroker: EventBroker;\n private publishers: EventPublisher[] = [];\n private subscribers: EventSubscriber[] = [];\n\n constructor(logger: Logger) {\n this.eventBroker = new InMemoryEventBroker(logger);\n }\n\n setEventBroker(eventBroker: EventBroker): EventsBackend {\n this.eventBroker = eventBroker;\n return this;\n }\n\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): EventsBackend {\n this.publishers.push(...publishers.flat());\n return this;\n }\n\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): EventsBackend {\n this.subscribers.push(...subscribers.flat());\n return this;\n }\n\n /**\n * Wires up and returns all component parts of the event management.\n */\n async start(): Promise<void> {\n this.eventBroker.subscribe(this.subscribers);\n this.publishers.forEach(publisher =>\n publisher.setEventBroker(this.eventBroker),\n );\n }\n}\n"],"names":["InMemoryEventBroker"],"mappings":";;;;;;;;;AA6BO,MAAM,aAAc,CAAA;AAAA,EAKzB,YAAY,MAAgB,EAAA;AAH5B,IAAA,IAAA,CAAQ,aAA+B,EAAC,CAAA;AACxC,IAAA,IAAA,CAAQ,cAAiC,EAAC,CAAA;AAGxC,IAAK,IAAA,CAAA,WAAA,GAAc,IAAIA,iDAAA,CAAoB,MAAM,CAAA,CAAA;AAAA,GACnD;AAAA,EAEA,eAAe,WAAyC,EAAA;AACtD,IAAA,IAAA,CAAK,WAAc,GAAA,WAAA,CAAA;AACnB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EAEA,iBACK,UACY,EAAA;AACf,IAAA,IAAA,CAAK,UAAW,CAAA,IAAA,CAAK,GAAG,UAAA,CAAW,MAAM,CAAA,CAAA;AACzC,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EAEA,kBACK,WACY,EAAA;AACf,IAAA,IAAA,CAAK,WAAY,CAAA,IAAA,CAAK,GAAG,WAAA,CAAY,MAAM,CAAA,CAAA;AAC3C,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAuB,GAAA;AAC3B,IAAK,IAAA,CAAA,WAAA,CAAY,SAAU,CAAA,IAAA,CAAK,WAAW,CAAA,CAAA;AAC3C,IAAA,IAAA,CAAK,UAAW,CAAA,OAAA;AAAA,MAAQ,CACtB,SAAA,KAAA,SAAA,CAAU,cAAe,CAAA,IAAA,CAAK,WAAW,CAAA;AAAA,KAC3C,CAAA;AAAA,GACF;AACF;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/service/EventsBackend.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 {\n EventBroker,\n EventPublisher,\n EventSubscriber,\n} from '@backstage/plugin-events-node';\nimport { Logger } from 'winston';\nimport { DefaultEventBroker } from './DefaultEventBroker';\n\n/**\n * A builder that helps wire up all component parts of the event management.\n *\n * @public\n */\nexport class EventsBackend {\n private eventBroker: EventBroker;\n private publishers: EventPublisher[] = [];\n private subscribers: EventSubscriber[] = [];\n\n constructor(logger: Logger) {\n this.eventBroker = new DefaultEventBroker(logger);\n }\n\n setEventBroker(eventBroker: EventBroker): EventsBackend {\n this.eventBroker = eventBroker;\n return this;\n }\n\n addPublishers(\n ...publishers: Array<EventPublisher | Array<EventPublisher>>\n ): EventsBackend {\n this.publishers.push(...publishers.flat());\n return this;\n }\n\n addSubscribers(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): EventsBackend {\n this.subscribers.push(...subscribers.flat());\n return this;\n }\n\n /**\n * Wires up and returns all component parts of the event management.\n */\n async start(): Promise<void> {\n this.eventBroker.subscribe(this.subscribers);\n this.publishers.forEach(publisher =>\n publisher.setEventBroker(this.eventBroker),\n );\n }\n}\n"],"names":["DefaultEventBroker"],"mappings":";;;;;;;;;AA6BO,MAAM,aAAc,CAAA;AAAA,EAKzB,YAAY,MAAgB,EAAA;AAH5B,IAAA,IAAA,CAAQ,aAA+B,EAAC,CAAA;AACxC,IAAA,IAAA,CAAQ,cAAiC,EAAC,CAAA;AAGxC,IAAK,IAAA,CAAA,WAAA,GAAc,IAAIA,gDAAA,CAAmB,MAAM,CAAA,CAAA;AAAA,GAClD;AAAA,EAEA,eAAe,WAAyC,EAAA;AACtD,IAAA,IAAA,CAAK,WAAc,GAAA,WAAA,CAAA;AACnB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EAEA,iBACK,UACY,EAAA;AACf,IAAA,IAAA,CAAK,UAAW,CAAA,IAAA,CAAK,GAAG,UAAA,CAAW,MAAM,CAAA,CAAA;AACzC,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EAEA,kBACK,WACY,EAAA;AACf,IAAA,IAAA,CAAK,WAAY,CAAA,IAAA,CAAK,GAAG,WAAA,CAAY,MAAM,CAAA,CAAA;AAC3C,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAuB,GAAA;AAC3B,IAAK,IAAA,CAAA,WAAA,CAAY,SAAU,CAAA,IAAA,CAAK,WAAW,CAAA,CAAA;AAC3C,IAAA,IAAA,CAAK,UAAW,CAAA,OAAA;AAAA,MAAQ,CACtB,SAAA,KAAA,SAAA,CAAU,cAAe,CAAA,IAAA,CAAK,WAAW,CAAA;AAAA,KAC3C,CAAA;AAAA,GACF;AACF;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EventBroker, EventPublisher, EventSubscriber, HttpPostIngressOptions } from '@backstage/plugin-events-node';
1
+ import { EventBroker, EventPublisher, EventSubscriber, HttpPostIngressOptions, EventParams } from '@backstage/plugin-events-node';
2
2
  import { Logger } from 'winston';
3
3
  import { Config } from '@backstage/config';
4
4
  import express from 'express';
@@ -46,4 +46,19 @@ declare class HttpPostIngressEventPublisher implements EventPublisher {
46
46
  private addRouteForTopic;
47
47
  }
48
48
 
49
- export { EventsBackend, HttpPostIngressEventPublisher };
49
+ /**
50
+ * In process event broker which will pass the event to all registered subscribers
51
+ * interested in it.
52
+ * Events will not be persisted in any form.
53
+ *
54
+ * @public
55
+ */
56
+ declare class DefaultEventBroker implements EventBroker {
57
+ private readonly logger;
58
+ constructor(logger: Logger);
59
+ private readonly subscribers;
60
+ publish(params: EventParams): Promise<void>;
61
+ subscribe(...subscribers: Array<EventSubscriber | Array<EventSubscriber>>): void;
62
+ }
63
+
64
+ export { DefaultEventBroker, EventsBackend, HttpPostIngressEventPublisher };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend",
3
- "version": "0.2.5-next.1",
3
+ "version": "0.2.5-next.3",
4
4
  "main": "./dist/index.cjs.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -33,20 +33,20 @@
33
33
  "postpack": "backstage-cli package postpack"
34
34
  },
35
35
  "dependencies": {
36
- "@backstage/backend-common": "^0.18.4-next.1",
37
- "@backstage/backend-plugin-api": "^0.5.1-next.1",
36
+ "@backstage/backend-common": "^0.18.4-next.2",
37
+ "@backstage/backend-plugin-api": "^0.5.1-next.2",
38
38
  "@backstage/config": "^1.0.7",
39
- "@backstage/plugin-events-node": "^0.2.5-next.1",
39
+ "@backstage/plugin-events-node": "^0.2.5-next.2",
40
40
  "@types/express": "^4.17.6",
41
41
  "express": "^4.17.1",
42
42
  "express-promise-router": "^4.1.0",
43
43
  "winston": "^3.2.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@backstage/backend-common": "^0.18.4-next.1",
47
- "@backstage/backend-test-utils": "^0.1.36-next.1",
48
- "@backstage/cli": "^0.22.6-next.1",
49
- "@backstage/plugin-events-backend-test-utils": "^0.1.6-next.1",
46
+ "@backstage/backend-common": "^0.18.4-next.2",
47
+ "@backstage/backend-test-utils": "^0.1.36-next.2",
48
+ "@backstage/cli": "^0.22.6-next.3",
49
+ "@backstage/plugin-events-backend-test-utils": "^0.1.6-next.2",
50
50
  "supertest": "^6.1.3"
51
51
  },
52
52
  "files": [
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpPostIngressEventPublisher-5c827dfa.cjs.js","sources":["../../src/service/InMemoryEventBroker.ts","../../src/service/http/validation/RequestValidationContextImpl.ts","../../src/service/http/HttpPostIngressEventPublisher.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 {\n EventBroker,\n EventParams,\n EventSubscriber,\n} from '@backstage/plugin-events-node';\nimport { Logger } from 'winston';\n\n/**\n * In-memory 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 */\n// TODO(pjungermann): add prom metrics? (see plugins/catalog-backend/src/util/metrics.ts, etc.)\nexport class InMemoryEventBroker implements EventBroker {\n constructor(private readonly logger: Logger) {}\n\n private readonly subscribers: {\n [topic: string]: EventSubscriber[];\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 const subscribed = this.subscribers[params.topic] ?? [];\n await Promise.all(\n subscribed.map(async subscriber => {\n try {\n await subscriber.onEvent(params);\n } catch (error) {\n this.logger.error(\n `Subscriber \"${subscriber.constructor.name}\" failed to process event`,\n error,\n );\n }\n }),\n );\n }\n\n subscribe(\n ...subscribers: Array<EventSubscriber | Array<EventSubscriber>>\n ): void {\n subscribers.flat().forEach(subscriber => {\n subscriber.supportsEventTopics().forEach(topic => {\n this.subscribers[topic] = this.subscribers[topic] ?? [];\n this.subscribers[topic].push(subscriber);\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 {\n RequestRejectionDetails,\n RequestValidationContext,\n} from '@backstage/plugin-events-node';\n\nexport class RequestValidationContextImpl implements RequestValidationContext {\n #rejectionDetails: RequestRejectionDetails | undefined;\n\n reject(details?: Partial<RequestRejectionDetails>): void {\n this.#rejectionDetails = {\n status: details?.status ?? 403,\n payload: details?.payload ?? {},\n };\n }\n\n wasRejected(): boolean {\n return this.#rejectionDetails !== undefined;\n }\n\n get rejectionDetails() {\n return this.#rejectionDetails;\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 { errorHandler } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport {\n EventBroker,\n EventPublisher,\n HttpPostIngressOptions,\n RequestValidator,\n} from '@backstage/plugin-events-node';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { Logger } from 'winston';\nimport { RequestValidationContextImpl } from './validation';\n\n/**\n * Publishes events received from their origin (e.g., webhook events from an SCM system)\n * via HTTP POST endpoint and passes the request body as event payload to the registered subscribers.\n *\n * @public\n */\n// TODO(pjungermann): add prom metrics? (see plugins/catalog-backend/src/util/metrics.ts, etc.)\nexport class HttpPostIngressEventPublisher implements EventPublisher {\n private eventBroker?: EventBroker;\n\n static fromConfig(env: {\n config: Config;\n ingresses?: { [topic: string]: Omit<HttpPostIngressOptions, 'topic'> };\n logger: Logger;\n }): HttpPostIngressEventPublisher {\n const topics =\n env.config.getOptionalStringArray('events.http.topics') ?? [];\n\n const ingresses = env.ingresses ?? {};\n topics.forEach(topic => {\n // don't overwrite topic settings\n // (e.g., added at the config as well as argument)\n if (!ingresses[topic]) {\n ingresses[topic] = {};\n }\n });\n\n return new HttpPostIngressEventPublisher(env.logger, ingresses);\n }\n\n private constructor(\n private readonly logger: Logger,\n private readonly ingresses: {\n [topic: string]: Omit<HttpPostIngressOptions, 'topic'>;\n },\n ) {}\n\n bind(router: express.Router): void {\n router.use('/http', this.createRouter(this.ingresses));\n }\n\n async setEventBroker(eventBroker: EventBroker): Promise<void> {\n this.eventBroker = eventBroker;\n }\n\n private createRouter(ingresses: {\n [topic: string]: Omit<HttpPostIngressOptions, 'topic'>;\n }): express.Router {\n const router = Router();\n router.use(express.json());\n\n Object.keys(ingresses).forEach(topic =>\n this.addRouteForTopic(router, topic, ingresses[topic].validator),\n );\n\n router.use(errorHandler());\n return router;\n }\n\n private addRouteForTopic(\n router: express.Router,\n topic: string,\n validator?: RequestValidator,\n ): void {\n const path = `/${topic}`;\n\n router.post(path, async (request, response) => {\n const requestDetails = {\n body: request.body,\n headers: request.headers,\n };\n const context = new RequestValidationContextImpl();\n await validator?.(requestDetails, context);\n if (context.wasRejected()) {\n response\n .status(context.rejectionDetails!.status)\n .json(context.rejectionDetails!.payload);\n return;\n }\n\n const eventPayload = request.body;\n await this.eventBroker!.publish({\n topic,\n eventPayload,\n metadata: request.headers,\n });\n\n response.status(202).json({ status: 'accepted' });\n });\n\n // TODO(pjungermann): We don't really know the externally defined path prefix here,\n // however it is more useful for users to have it. Is there a better way?\n this.logger.info(`Registered /api/events/http${path} to receive events`);\n }\n}\n"],"names":["Router","express","errorHandler"],"mappings":";;;;;;;;;;;AA6BO,MAAM,mBAA2C,CAAA;AAAA,EACtD,YAA6B,MAAgB,EAAA;AAAhB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAE7B,IAAA,IAAA,CAAiB,cAEb,EAAC,CAAA;AAAA,GAJyC;AAAA,EAM9C,MAAM,QAAQ,MAAoC,EAAA;AApCpD,IAAA,IAAA,EAAA,CAAA;AAqCI,IAAA,IAAA,CAAK,MAAO,CAAA,KAAA;AAAA,MACV,CAAA,sBAAA,EAAyB,MAAO,CAAA,KAAA,CAAA,WAAA,EAAmB,IAAK,CAAA,SAAA;AAAA,QACtD,MAAO,CAAA,QAAA;AAAA,OACK,CAAA,UAAA,EAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,YAAY,CAAA,CAAA,CAAA;AAAA,KAClD,CAAA;AAEA,IAAA,MAAM,cAAa,EAAK,GAAA,IAAA,CAAA,WAAA,CAAY,OAAO,KAAK,CAAA,KAA7B,YAAkC,EAAC,CAAA;AACtD,IAAA,MAAM,OAAQ,CAAA,GAAA;AAAA,MACZ,UAAA,CAAW,GAAI,CAAA,OAAM,UAAc,KAAA;AACjC,QAAI,IAAA;AACF,UAAM,MAAA,UAAA,CAAW,QAAQ,MAAM,CAAA,CAAA;AAAA,iBACxB,KAAP,EAAA;AACA,UAAA,IAAA,CAAK,MAAO,CAAA,KAAA;AAAA,YACV,CAAA,YAAA,EAAe,WAAW,WAAY,CAAA,IAAA,CAAA,yBAAA,CAAA;AAAA,YACtC,KAAA;AAAA,WACF,CAAA;AAAA,SACF;AAAA,OACD,CAAA;AAAA,KACH,CAAA;A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