@backstage/plugin-notifications-backend 0.6.8-next.0 → 0.6.8

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,26 @@
1
1
  # @backstage/plugin-notifications-backend
2
2
 
3
+ ## 0.6.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 3222945: Fixed notification recipient resolution to safely handle cyclic group relationships during group traversal, preventing endless recursion.
8
+ - Updated dependencies
9
+ - @backstage/catalog-model@1.10.0
10
+ - @backstage/backend-plugin-api@1.10.0
11
+ - @backstage/backend-openapi-utils@0.7.1
12
+ - @backstage/plugin-catalog-node@2.2.4
13
+ - @backstage/plugin-notifications-node@0.2.29
14
+ - @backstage/plugin-signals-node@0.2.4
15
+
16
+ ## 0.6.8-next.1
17
+
18
+ ### Patch Changes
19
+
20
+ - 3222945: Fixed notification recipient resolution to safely handle cyclic group relationships during group traversal, preventing endless recursion.
21
+ - Updated dependencies
22
+ - @backstage/backend-plugin-api@1.10.0-next.1
23
+
3
24
  ## 0.6.8-next.0
4
25
 
5
26
  ### Patch Changes
@@ -23,90 +23,59 @@ class DefaultNotificationRecipientResolver {
23
23
  }
24
24
  async resolveNotificationRecipients(options) {
25
25
  const { entityRefs, excludedEntityRefs = [] } = options;
26
- const [userEntityRefs, otherEntityRefs] = partitionEntityRefs(entityRefs);
27
- const users = userEntityRefs.filter(
28
- (ref) => !excludedEntityRefs.includes(ref)
29
- );
30
- const filtered = otherEntityRefs.filter(
31
- (ref) => !excludedEntityRefs.includes(ref)
32
- );
26
+ const users = /* @__PURE__ */ new Set();
27
+ const seen = /* @__PURE__ */ new Set();
28
+ const todo = [...new Set(entityRefs)];
29
+ todo.forEach((ref) => seen.add(ref));
33
30
  const fields = ["kind", "metadata.name", "metadata.namespace", "relations"];
34
- let entities = [];
35
- if (filtered.length > 0) {
36
- const fetchedEntities = await this.catalog.getEntitiesByRefs(
37
- {
38
- entityRefs: filtered,
39
- fields
40
- },
41
- { credentials: await this.auth.getOwnServiceCredentials() }
31
+ while (todo.length) {
32
+ const [userEntityRefs, otherEntityRefs] = partitionEntityRefs(todo);
33
+ todo.length = 0;
34
+ userEntityRefs.forEach((user) => users.add(user));
35
+ const filtered = otherEntityRefs.filter(
36
+ (ref) => !excludedEntityRefs.includes(ref)
42
37
  );
43
- entities = fetchedEntities.items;
44
- }
45
- const cachedEntityRefs = /* @__PURE__ */ new Map();
46
- const mapEntity = async (entity) => {
47
- if (!entity) {
48
- return [];
49
- }
50
- const currentEntityRef = catalogModel.stringifyEntityRef(entity);
51
- if (excludedEntityRefs.includes(currentEntityRef)) {
52
- return [];
53
- }
54
- if (cachedEntityRefs.has(currentEntityRef)) {
55
- return cachedEntityRefs.get(currentEntityRef);
38
+ let entities = [];
39
+ if (filtered.length > 0) {
40
+ const fetchedEntities = await this.catalog.getEntitiesByRefs(
41
+ {
42
+ entityRefs: filtered,
43
+ fields
44
+ },
45
+ { credentials: await this.auth.getOwnServiceCredentials() }
46
+ );
47
+ entities = fetchedEntities.items.filter(
48
+ (entity) => entity !== void 0
49
+ );
56
50
  }
57
- if (catalogModel.isUserEntity(entity)) {
58
- return [currentEntityRef];
59
- }
60
- if (catalogModel.isGroupEntity(entity)) {
61
- if (!entity.relations?.length) {
62
- return [];
51
+ entities.forEach((entity) => {
52
+ const currentEntityRef = catalogModel.stringifyEntityRef(entity);
53
+ if (excludedEntityRefs.includes(currentEntityRef)) {
54
+ return;
63
55
  }
64
- const groupUsers = entity.relations.filter(
65
- (relation) => relation.type === catalogModel.RELATION_HAS_MEMBER && isUserEntityRef(relation.targetRef)
66
- ).map((r) => r.targetRef);
67
- const childGroupRefs = entity.relations.filter((relation) => relation.type === catalogModel.RELATION_PARENT_OF).map((r) => r.targetRef);
68
- let childGroupUsers = [];
69
- if (childGroupRefs.length > 0) {
70
- const childGroups = await this.catalog.getEntitiesByRefs(
71
- {
72
- entityRefs: childGroupRefs,
73
- fields
74
- },
75
- { credentials: await this.auth.getOwnServiceCredentials() }
76
- );
77
- childGroupUsers = await Promise.all(childGroups.items.map(mapEntity));
56
+ if (catalogModel.isUserEntity(entity)) {
57
+ users.add(currentEntityRef);
58
+ return;
78
59
  }
79
- const ret = [
80
- .../* @__PURE__ */ new Set([...groupUsers, ...childGroupUsers.flat(2)])
81
- ].filter((ref) => !excludedEntityRefs.includes(ref));
82
- cachedEntityRefs.set(currentEntityRef, ret);
83
- return ret;
84
- }
85
- if (entity.relations?.length) {
86
- const ownerRef = entity.relations.find(
60
+ if (catalogModel.isGroupEntity(entity)) {
61
+ for (const relation of entity.relations ?? []) {
62
+ if (relation.type === catalogModel.RELATION_HAS_MEMBER && isUserEntityRef(relation.targetRef)) {
63
+ users.add(relation.targetRef);
64
+ } else if (relation.type === catalogModel.RELATION_PARENT_OF && !seen.has(relation.targetRef)) {
65
+ seen.add(relation.targetRef);
66
+ todo.push(relation.targetRef);
67
+ }
68
+ }
69
+ return;
70
+ }
71
+ const ownerRef = entity.relations?.find(
87
72
  (relation) => relation.type === catalogModel.RELATION_OWNED_BY
88
73
  )?.targetRef;
89
- if (!ownerRef) {
90
- return [];
91
- }
92
- if (isUserEntityRef(ownerRef)) {
93
- if (excludedEntityRefs.includes(ownerRef)) {
94
- return [];
95
- }
96
- return [ownerRef];
74
+ if (ownerRef && !seen.has(ownerRef)) {
75
+ seen.add(ownerRef);
76
+ todo.push(ownerRef);
97
77
  }
98
- const owner = await this.catalog.getEntityByRef(ownerRef, {
99
- credentials: await this.auth.getOwnServiceCredentials()
100
- });
101
- const ret = await mapEntity(owner);
102
- cachedEntityRefs.set(currentEntityRef, ret);
103
- return ret;
104
- }
105
- return [];
106
- };
107
- for (const entity of entities) {
108
- const u = await mapEntity(entity);
109
- users.push(...u);
78
+ });
110
79
  }
111
80
  return {
112
81
  userEntityRefs: [...new Set(users)].filter(Boolean).filter((ref) => !excludedEntityRefs.includes(ref))
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultNotificationRecipientResolver.cjs.js","sources":["../../src/service/DefaultNotificationRecipientResolver.ts"],"sourcesContent":["/*\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 Entity,\n isGroupEntity,\n isUserEntity,\n parseEntityRef,\n RELATION_HAS_MEMBER,\n RELATION_OWNED_BY,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\nimport { NotificationRecipientResolver } from '@backstage/plugin-notifications-node';\n\nconst isUserEntityRef = (ref: string) =>\n parseEntityRef(ref).kind.toLocaleLowerCase() === 'user';\n\n// Partitions array of entity references to two arrays; user entity refs and other entity refs\nconst partitionEntityRefs = (refs: string[]): string[][] => {\n const ret = [[], []] as string[][];\n for (const ref of refs) {\n if (isUserEntityRef(ref)) {\n ret[0].push(ref);\n } else {\n ret[1].push(ref);\n }\n }\n return ret;\n};\n\nexport class DefaultNotificationRecipientResolver\n implements NotificationRecipientResolver\n{\n private readonly auth: AuthService;\n private readonly catalog: CatalogService;\n\n constructor(auth: AuthService, catalog: CatalogService) {\n this.auth = auth;\n this.catalog = catalog;\n }\n\n async resolveNotificationRecipients(options: {\n entityRefs: string[];\n excludedEntityRefs?: string[];\n }): Promise<{ userEntityRefs: string[] }> {\n const { entityRefs, excludedEntityRefs = [] } = options;\n\n const [userEntityRefs, otherEntityRefs] = partitionEntityRefs(entityRefs);\n const users: string[] = userEntityRefs.filter(\n ref => !excludedEntityRefs.includes(ref),\n );\n const filtered = otherEntityRefs.filter(\n ref => !excludedEntityRefs.includes(ref),\n );\n\n const fields = ['kind', 'metadata.name', 'metadata.namespace', 'relations'];\n let entities: Array<Entity | undefined> = [];\n if (filtered.length > 0) {\n const fetchedEntities = await this.catalog.getEntitiesByRefs(\n {\n entityRefs: filtered,\n fields,\n },\n { credentials: await this.auth.getOwnServiceCredentials() },\n );\n entities = fetchedEntities.items;\n }\n\n const cachedEntityRefs = new Map<string, string[]>();\n\n const mapEntity = async (entity: Entity | undefined): Promise<string[]> => {\n if (!entity) {\n return [];\n }\n\n const currentEntityRef = stringifyEntityRef(entity);\n if (excludedEntityRefs.includes(currentEntityRef)) {\n return [];\n }\n\n if (cachedEntityRefs.has(currentEntityRef)) {\n return cachedEntityRefs.get(currentEntityRef)!;\n }\n\n if (isUserEntity(entity)) {\n return [currentEntityRef];\n }\n\n if (isGroupEntity(entity)) {\n if (!entity.relations?.length) {\n return [];\n }\n\n const groupUsers = entity.relations\n .filter(\n relation =>\n relation.type === RELATION_HAS_MEMBER &&\n isUserEntityRef(relation.targetRef),\n )\n .map(r => r.targetRef);\n\n const childGroupRefs = entity.relations\n .filter(relation => relation.type === RELATION_PARENT_OF)\n .map(r => r.targetRef);\n\n let childGroupUsers: string[][] = [];\n if (childGroupRefs.length > 0) {\n const childGroups = await this.catalog.getEntitiesByRefs(\n {\n entityRefs: childGroupRefs,\n fields,\n },\n { credentials: await this.auth.getOwnServiceCredentials() },\n );\n childGroupUsers = await Promise.all(childGroups.items.map(mapEntity));\n }\n\n const ret = [\n ...new Set([...groupUsers, ...childGroupUsers.flat(2)]),\n ].filter(ref => !excludedEntityRefs.includes(ref));\n cachedEntityRefs.set(currentEntityRef, ret);\n return ret;\n }\n\n if (entity.relations?.length) {\n const ownerRef = entity.relations.find(\n relation => relation.type === RELATION_OWNED_BY,\n )?.targetRef;\n\n if (!ownerRef) {\n return [];\n }\n\n if (isUserEntityRef(ownerRef)) {\n if (excludedEntityRefs.includes(ownerRef)) {\n return [];\n }\n return [ownerRef];\n }\n\n const owner = await this.catalog.getEntityByRef(ownerRef, {\n credentials: await this.auth.getOwnServiceCredentials(),\n });\n const ret = await mapEntity(owner);\n cachedEntityRefs.set(currentEntityRef, ret);\n return ret;\n }\n\n return [];\n };\n\n for (const entity of entities) {\n const u = await mapEntity(entity);\n users.push(...u);\n }\n\n return {\n userEntityRefs: [...new Set(users)]\n .filter(Boolean)\n // Need to filter again after resolving users\n .filter(ref => !excludedEntityRefs.includes(ref)),\n };\n }\n}\n"],"names":["parseEntityRef","stringifyEntityRef","isUserEntity","isGroupEntity","RELATION_HAS_MEMBER","RELATION_PARENT_OF","RELATION_OWNED_BY"],"mappings":";;;;AA8BA,MAAM,eAAA,GAAkB,CAAC,GAAA,KACvBA,2BAAA,CAAe,GAAG,CAAA,CAAE,IAAA,CAAK,mBAAkB,KAAM,MAAA;AAGnD,MAAM,mBAAA,GAAsB,CAAC,IAAA,KAA+B;AAC1D,EAAA,MAAM,GAAA,GAAM,CAAC,EAAC,EAAG,EAAE,CAAA;AACnB,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,IAAA,IAAI,eAAA,CAAgB,GAAG,CAAA,EAAG;AACxB,MAAA,GAAA,CAAI,CAAC,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,GAAA,CAAI,CAAC,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAAA,IACjB;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT,CAAA;AAEO,MAAM,oCAAA,CAEb;AAAA,EACmB,IAAA;AAAA,EACA,OAAA;AAAA,EAEjB,WAAA,CAAY,MAAmB,OAAA,EAAyB;AACtD,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AAAA,EAEA,MAAM,8BAA8B,OAAA,EAGM;AACxC,IAAA,MAAM,EAAE,UAAA,EAAY,kBAAA,GAAqB,IAAG,GAAI,OAAA;A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,GAAA,KAAO,CAAC,kBAAA,CAAmB,QAAA,CAAS,GAAG,CAAC;AAAA,KACpD;AAAA,EACF;AACF;;;;"}
1
+ {"version":3,"file":"DefaultNotificationRecipientResolver.cjs.js","sources":["../../src/service/DefaultNotificationRecipientResolver.ts"],"sourcesContent":["/*\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 Entity,\n isGroupEntity,\n isUserEntity,\n parseEntityRef,\n RELATION_HAS_MEMBER,\n RELATION_OWNED_BY,\n RELATION_PARENT_OF,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\nimport { NotificationRecipientResolver } from '@backstage/plugin-notifications-node';\n\nconst isUserEntityRef = (ref: string) =>\n parseEntityRef(ref).kind.toLocaleLowerCase() === 'user';\n\n// Partitions array of entity references to two arrays; user entity refs and other entity refs\nconst partitionEntityRefs = (refs: string[]): string[][] => {\n const ret = [[], []] as string[][];\n for (const ref of refs) {\n if (isUserEntityRef(ref)) {\n ret[0].push(ref);\n } else {\n ret[1].push(ref);\n }\n }\n return ret;\n};\n\nexport class DefaultNotificationRecipientResolver\n implements NotificationRecipientResolver\n{\n private readonly auth: AuthService;\n private readonly catalog: CatalogService;\n\n constructor(auth: AuthService, catalog: CatalogService) {\n this.auth = auth;\n this.catalog = catalog;\n }\n\n async resolveNotificationRecipients(options: {\n entityRefs: string[];\n excludedEntityRefs?: string[];\n }): Promise<{ userEntityRefs: string[] }> {\n const { entityRefs, excludedEntityRefs = [] } = options;\n\n const users = new Set<string>();\n const seen = new Set<string>();\n\n const todo = [...new Set(entityRefs)];\n todo.forEach(ref => seen.add(ref));\n\n const fields = ['kind', 'metadata.name', 'metadata.namespace', 'relations'];\n\n while (todo.length) {\n const [userEntityRefs, otherEntityRefs] = partitionEntityRefs(todo);\n todo.length = 0;\n\n userEntityRefs.forEach(user => users.add(user));\n\n // Filter excluded refs to avoid unnecessary catalog lookups\n const filtered = otherEntityRefs.filter(\n ref => !excludedEntityRefs.includes(ref),\n );\n let entities: Array<Entity> = [];\n if (filtered.length > 0) {\n const fetchedEntities = await this.catalog.getEntitiesByRefs(\n {\n entityRefs: filtered,\n fields,\n },\n { credentials: await this.auth.getOwnServiceCredentials() },\n );\n entities = fetchedEntities.items.filter(\n (entity): entity is Entity => entity !== undefined,\n );\n }\n\n entities.forEach(entity => {\n const currentEntityRef = stringifyEntityRef(entity);\n if (excludedEntityRefs.includes(currentEntityRef)) {\n return;\n }\n\n if (isUserEntity(entity)) {\n users.add(currentEntityRef);\n return;\n }\n\n if (isGroupEntity(entity)) {\n for (const relation of entity.relations ?? []) {\n if (\n relation.type === RELATION_HAS_MEMBER &&\n isUserEntityRef(relation.targetRef)\n ) {\n users.add(relation.targetRef);\n } else if (\n relation.type === RELATION_PARENT_OF &&\n !seen.has(relation.targetRef)\n ) {\n seen.add(relation.targetRef);\n todo.push(relation.targetRef);\n }\n }\n return;\n }\n\n // Any other kind (component, template, ...): route to its owner and\n // let the next pass classify and expand it.\n const ownerRef = entity.relations?.find(\n relation => relation.type === RELATION_OWNED_BY,\n )?.targetRef;\n\n if (ownerRef && !seen.has(ownerRef)) {\n seen.add(ownerRef);\n todo.push(ownerRef);\n }\n });\n }\n return {\n userEntityRefs: [...new Set(users)]\n .filter(Boolean)\n // Need to filter again after resolving users\n .filter(ref => !excludedEntityRefs.includes(ref)),\n };\n }\n}\n"],"names":["parseEntityRef","stringifyEntityRef","isUserEntity","isGroupEntity","RELATION_HAS_MEMBER","RELATION_PARENT_OF","RELATION_OWN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AA,CAAgB,QAAA,CAAS,SAAS,CAAA,EAClC;AACA,cAAA,KAAA,CAAM,GAAA,CAAI,SAAS,SAAS,CAAA;AAAA,YAC9B,CAAA,MAAA,IACE,SAAS,IAAA,KAASC,+BAAA,IAClB,CAAC,IAAA,CAAK,GAAA,CAAI,QAAA,CAAS,SAAS,CAAA,EAC5B;AACA,cAAA,IAAA,CAAK,GAAA,CAAI,SAAS,SAAS,CAAA;AAC3B,cAAA,IAAA,CAAK,IAAA,CAAK,SAAS,SAAS,CAAA;AAAA,YAC9B;AAAA,UACF;AACA,UAAA;AAAA,QACF;AAIA,QAAA,MAAM,QAAA,GAAW,OAAO,SAAA,EAAW,IAAA;AAAA,UACjC,CAAA,QAAA,KAAY,SAAS,IAAA,KAASC;AAAA,SAChC,EAAG,SAAA;AAEH,QAAA,IAAI,QAAA,IAAY,CAAC,IAAA,CAAK,GAAA,CAAI,QAAQ,CAAA,EAAG;AACnC,UAAA,IAAA,CAAK,IAAI,QAAQ,CAAA;AACjB,UAAA,IAAA,CAAK,KAAK,QAAQ,CAAA;AAAA,QACpB;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AACA,IAAA,OAAO;AAAA,MACL,gBAAgB,CAAC,GAAG,IAAI,GAAA,CAAI,KAAK,CAAC,CAAA,CAC/B,MAAA,CAAO,OAAO,EAEd,MAAA,CAAO,CAAA,GAAA,KAAO,CAAC,kBAAA,CAAmB,QAAA,CAAS,GAAG,CAAC;AAAA,KACpD;AAAA,EACF;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-notifications-backend",
3
- "version": "0.6.8-next.0",
3
+ "version": "0.6.8",
4
4
  "backstage": {
5
5
  "role": "backend-plugin",
6
6
  "pluginId": "notifications",
@@ -46,30 +46,30 @@
46
46
  "test": "backstage-cli package test"
47
47
  },
48
48
  "dependencies": {
49
- "@backstage/backend-openapi-utils": "0.7.1-next.0",
50
- "@backstage/backend-plugin-api": "1.10.0-next.0",
51
- "@backstage/catalog-model": "1.9.0",
52
- "@backstage/config": "1.3.8",
53
- "@backstage/errors": "1.3.1",
54
- "@backstage/plugin-catalog-node": "2.2.4-next.0",
55
- "@backstage/plugin-notifications-common": "0.2.3",
56
- "@backstage/plugin-notifications-node": "0.2.29-next.0",
57
- "@backstage/plugin-signals-node": "0.2.4-next.0",
58
- "@backstage/types": "1.2.2",
49
+ "@backstage/backend-openapi-utils": "^0.7.1",
50
+ "@backstage/backend-plugin-api": "^1.10.0",
51
+ "@backstage/catalog-model": "^1.10.0",
52
+ "@backstage/config": "^1.3.8",
53
+ "@backstage/errors": "^1.3.1",
54
+ "@backstage/plugin-catalog-node": "^2.2.4",
55
+ "@backstage/plugin-notifications-common": "^0.2.3",
56
+ "@backstage/plugin-notifications-node": "^0.2.29",
57
+ "@backstage/plugin-signals-node": "^0.2.4",
58
+ "@backstage/types": "^1.2.2",
59
59
  "express": "^4.22.0",
60
60
  "express-promise-router": "^4.1.0",
61
61
  "knex": "^3.0.0",
62
62
  "p-throttle": "^4.1.1"
63
63
  },
64
64
  "devDependencies": {
65
- "@backstage/backend-defaults": "0.17.6-next.0",
66
- "@backstage/backend-test-utils": "1.11.6-next.0",
67
- "@backstage/cli": "0.36.4",
68
- "@backstage/plugin-auth-backend": "0.30.0-next.0",
69
- "@backstage/plugin-auth-backend-module-guest-provider": "0.2.22-next.0",
70
- "@backstage/plugin-events-backend": "0.6.5-next.0",
71
- "@backstage/plugin-signals-backend": "0.3.18-next.0",
72
- "@backstage/repo-tools": "0.18.1-next.0",
65
+ "@backstage/backend-defaults": "^0.17.7",
66
+ "@backstage/backend-test-utils": "^1.11.6",
67
+ "@backstage/cli": "^0.36.5",
68
+ "@backstage/plugin-auth-backend": "^0.30.0",
69
+ "@backstage/plugin-auth-backend-module-guest-provider": "^0.2.22",
70
+ "@backstage/plugin-events-backend": "^0.6.5",
71
+ "@backstage/plugin-signals-backend": "^0.3.18",
72
+ "@backstage/repo-tools": "^0.19.0",
73
73
  "@types/express": "^4.17.6",
74
74
  "@types/supertest": "^2.0.8",
75
75
  "supertest": "^7.0.0"