@backstage/plugin-events-node 0.3.4 → 0.3.5-next.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 +15 -0
- package/alpha/package.json +1 -1
- package/dist/index.cjs.js +5 -18
- package/dist/index.cjs.js.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @backstage/plugin-events-node
|
|
2
2
|
|
|
3
|
+
## 0.3.5-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/backend-plugin-api@0.6.19-next.2
|
|
9
|
+
|
|
10
|
+
## 0.3.5-next.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 6a576dc: Replace the usage of `getVoidLogger` with `mockServices.logger.mock` in order to remove the dependency with the soon-to-be-deprecated `backend-common` package.
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @backstage/backend-plugin-api@0.6.19-next.0
|
|
17
|
+
|
|
3
18
|
## 0.3.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -2,17 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
4
|
|
|
5
|
-
var __defProp$1 = Object.defineProperty;
|
|
6
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField$1 = (obj, key, value) => {
|
|
8
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
return value;
|
|
10
|
-
};
|
|
11
5
|
class EventRouter {
|
|
6
|
+
events;
|
|
7
|
+
topics;
|
|
8
|
+
subscribed = false;
|
|
12
9
|
constructor(options) {
|
|
13
|
-
__publicField$1(this, "events");
|
|
14
|
-
__publicField$1(this, "topics");
|
|
15
|
-
__publicField$1(this, "subscribed", false);
|
|
16
10
|
this.events = options.events;
|
|
17
11
|
this.topics = options.topics;
|
|
18
12
|
}
|
|
@@ -44,17 +38,11 @@ class EventRouter {
|
|
|
44
38
|
}
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
var __defProp = Object.defineProperty;
|
|
48
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
49
|
-
var __publicField = (obj, key, value) => {
|
|
50
|
-
__defNormalProp(obj, key + "" , value);
|
|
51
|
-
return value;
|
|
52
|
-
};
|
|
53
41
|
class DefaultEventsService {
|
|
54
42
|
constructor(logger) {
|
|
55
43
|
this.logger = logger;
|
|
56
|
-
__publicField(this, "subscribers", /* @__PURE__ */ new Map());
|
|
57
44
|
}
|
|
45
|
+
subscribers = /* @__PURE__ */ new Map();
|
|
58
46
|
static create(options) {
|
|
59
47
|
return new DefaultEventsService(options.logger);
|
|
60
48
|
}
|
|
@@ -78,7 +66,6 @@ class DefaultEventsService {
|
|
|
78
66
|
};
|
|
79
67
|
}
|
|
80
68
|
async publish(params) {
|
|
81
|
-
var _a;
|
|
82
69
|
this.logger.debug(
|
|
83
70
|
`Event received: topic=${params.topic}, metadata=${JSON.stringify(
|
|
84
71
|
params.metadata
|
|
@@ -88,7 +75,7 @@ class DefaultEventsService {
|
|
|
88
75
|
return;
|
|
89
76
|
}
|
|
90
77
|
const onEventPromises = [];
|
|
91
|
-
|
|
78
|
+
this.subscribers.get(params.topic)?.forEach((subscription) => {
|
|
92
79
|
onEventPromises.push(
|
|
93
80
|
(async () => {
|
|
94
81
|
try {
|
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});\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,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,CAAK,OAAO,SAAU,CAAA;AAAA,MAC1B,EAAA,EAAI,KAAK,eAAgB,EAAA;AAAA,MACzB,QAAQ,IAAK,CAAA,MAAA;AAAA,MACb,OAAS,EAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,KAChC,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAM,QAAQ,MAAoC,EAAA;AAChD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AAA;AAAA,GACvD;AACF,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":["createServiceRef","createServiceFactory","coreServices"],"mappings":";;;;AA0BO,MAAe,WAAY,CAAA;AAAA,EACf,MAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACT,UAAsB,GAAA,KAAA,CAAA;AAAA,EAEpB,YAAY,OAAsD,EAAA;AAC1E,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,CAAK,OAAO,SAAU,CAAA;AAAA,MAC1B,EAAA,EAAI,KAAK,eAAgB,EAAA;AAAA,MACzB,QAAQ,IAAK,CAAA,MAAA;AAAA,MACb,OAAS,EAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,KAChC,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAM,QAAQ,MAAoC,EAAA;AAChD,I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-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5-next.1",
|
|
4
4
|
"description": "The plugin-events-node module for @backstage/plugin-events-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -44,10 +44,11 @@
|
|
|
44
44
|
"test": "backstage-cli package test"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
47
|
+
"@backstage/backend-plugin-api": "^0.6.19-next.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@backstage/backend-common": "^0.
|
|
51
|
-
"@backstage/
|
|
50
|
+
"@backstage/backend-common": "^0.23.0-next.2",
|
|
51
|
+
"@backstage/backend-test-utils": "^0.4.0-next.2",
|
|
52
|
+
"@backstage/cli": "^0.26.7-next.2"
|
|
52
53
|
}
|
|
53
54
|
}
|