@backstage/plugin-events-node 0.3.4-next.1 → 0.3.4-next.2
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 +6 -0
- package/alpha/package.json +1 -1
- package/dist/index.cjs.js +15 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @backstage/plugin-events-node
|
|
2
2
|
|
|
3
|
+
## 0.3.4-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7e5a50d: added `eventsServiceFactory` to `defaultServiceFactories` to resolve issue where different instances of the EventsServices could be used
|
|
8
|
+
|
|
3
9
|
## 0.3.4-next.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -132,24 +132,25 @@ class SubTopicEventRouter extends EventRouter {
|
|
|
132
132
|
|
|
133
133
|
const eventsServiceRef = backendPluginApi.createServiceRef({
|
|
134
134
|
id: "events.service",
|
|
135
|
-
scope: "plugin"
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
135
|
+
scope: "plugin"
|
|
136
|
+
});
|
|
137
|
+
const eventsServiceFactory = backendPluginApi.createServiceFactory({
|
|
138
|
+
service: eventsServiceRef,
|
|
139
|
+
deps: {
|
|
140
|
+
pluginMetadata: backendPluginApi.coreServices.pluginMetadata,
|
|
141
|
+
rootLogger: backendPluginApi.coreServices.rootLogger
|
|
142
|
+
},
|
|
143
|
+
async createRootContext({ rootLogger }) {
|
|
144
|
+
return DefaultEventsService.create({ logger: rootLogger });
|
|
145
|
+
},
|
|
146
|
+
async factory({ pluginMetadata }, eventsService) {
|
|
147
|
+
return eventsService.forPlugin(pluginMetadata.getId());
|
|
148
|
+
}
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
exports.DefaultEventsService = DefaultEventsService;
|
|
152
152
|
exports.EventRouter = EventRouter;
|
|
153
153
|
exports.SubTopicEventRouter = SubTopicEventRouter;
|
|
154
|
+
exports.eventsServiceFactory = eventsServiceFactory;
|
|
154
155
|
exports.eventsServiceRef = eventsServiceRef;
|
|
155
156
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -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;A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pBC,qCAAqB,CAAA;AAAA,IACnB,OAAA;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,gBAAgBC,6BAAa,CAAA,cAAA;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;;;;;;;"}
|
|
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});\n\n/** @public */\nexport const eventsServiceFactory = createServiceFactory({\n service: eventsServiceRef,\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"],"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,IA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AmBC,iCAAgC,CAAA;AAAA,EAC9D,EAAI,EAAA,gBAAA;AAAA,EACJ,KAAO,EAAA,QAAA;AACT,CAAC,EAAA;AAGM,MAAM,uBAAuBC,qCAAqB,CAAA;AAAA,EACvD,OAAS,EAAA,gBAAA;AAAA,EACT,IAAM,EAAA;AAAA,IACJ,gBAAgBC,6BAAa,CAAA,cAAA;AAAA,IAC7B,YAAYA,6BAAa,CAAA,UAAA;AAAA,GAC3B;AAAA,EACA,MAAM,iBAAA,CAAkB,EAAE,UAAA,EAAc,EAAA;AACtC,IAAA,OAAO,oBAAqB,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,YAAY,CAAA,CAAA;AAAA,GAC3D;AAAA,EACA,MAAM,OAAA,CAAQ,EAAE,cAAA,IAAkB,aAAe,EAAA;AAC/C,IAAA,OAAO,aAAc,CAAA,SAAA,CAAU,cAAe,CAAA,KAAA,EAAO,CAAA,CAAA;AAAA,GACvD;AACF,CAAC;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -257,5 +257,7 @@ interface EventPublisher {
|
|
|
257
257
|
* @public
|
|
258
258
|
*/
|
|
259
259
|
declare const eventsServiceRef: _backstage_backend_plugin_api.ServiceRef<EventsService, "plugin">;
|
|
260
|
+
/** @public */
|
|
261
|
+
declare const eventsServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<EventsService, "plugin">;
|
|
260
262
|
|
|
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 };
|
|
263
|
+
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, eventsServiceFactory, eventsServiceRef };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-events-node",
|
|
3
|
-
"version": "0.3.4-next.
|
|
3
|
+
"version": "0.3.4-next.2",
|
|
4
4
|
"description": "The plugin-events-node module for @backstage/plugin-events-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@backstage/backend-plugin-api": "^0.6.18-next.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@backstage/backend-common": "^0.22.0-next.
|
|
51
|
-
"@backstage/cli": "^0.26.5-next.
|
|
50
|
+
"@backstage/backend-common": "^0.22.0-next.2",
|
|
51
|
+
"@backstage/cli": "^0.26.5-next.1"
|
|
52
52
|
}
|
|
53
53
|
}
|