@red-hat-developer-hub/backstage-plugin-adoption-insights-backend 0.1.0 → 0.2.0

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,16 @@
1
1
  # @red-hat-developer-hub/backstage-plugin-adoption-insights-backend
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3a80c30: Backstage version bump to v1.39.1
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [3a80c30]
12
+ - @red-hat-developer-hub/backstage-plugin-adoption-insights-common@0.3.0
13
+
3
14
  ## 0.1.0
4
15
 
5
16
  ### Minor Changes
package/README.md CHANGED
@@ -86,7 +86,7 @@ The Adoption Insights Backend plugin has support for the permission framework.
86
86
  }
87
87
  ```
88
88
 
89
- 3. start the application by running `yarn dev` from `workspaces/adoption-insights` directory.
89
+ 3. start the application by running `yarn start` from `workspaces/adoption-insights` directory.
90
90
 
91
91
  ## Development
92
92
 
@@ -94,7 +94,7 @@ This plugin backend can be started in a standalone mode from directly in this
94
94
  package with `yarn start`. It is a limited setup that is most convenient when
95
95
  developing the plugin backend itself.
96
96
 
97
- If you want to run the entire project, including the frontend, run `yarn dev` from the root directory.
97
+ If you want to run the entire project, including the frontend, run `yarn start` from the root directory.
98
98
 
99
99
  # Events API
100
100
 
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var backstagePluginAdoptionInsightsCommon = require('@red-hat-developer-hub/backstage-plugin-adoption-insights-common');
4
5
  var router = require('./router.cjs.js');
5
6
  var migration = require('./database/migration.cjs.js');
6
7
  var DatabaseFactory = require('./database/DatabaseFactory.cjs.js');
@@ -20,7 +21,8 @@ const adoptionInsightsPlugin = backendPluginApi.createBackendPlugin({
20
21
  httpRouter: backendPluginApi.coreServices.httpRouter,
21
22
  database: backendPluginApi.coreServices.database,
22
23
  scheduler: backendPluginApi.coreServices.scheduler,
23
- permissions: backendPluginApi.coreServices.permissions
24
+ permissions: backendPluginApi.coreServices.permissions,
25
+ permissionsRegistry: backendPluginApi.coreServices.permissionsRegistry
24
26
  },
25
27
  async init({
26
28
  config: config$1,
@@ -29,8 +31,12 @@ const adoptionInsightsPlugin = backendPluginApi.createBackendPlugin({
29
31
  httpRouter,
30
32
  database,
31
33
  scheduler,
32
- permissions
34
+ permissions,
35
+ permissionsRegistry
33
36
  }) {
37
+ permissionsRegistry.addPermissions([
38
+ backstagePluginAdoptionInsightsCommon.adoptionInsightsEventsReadPermission
39
+ ]);
34
40
  const options = config.getConfigurationOptions(config$1);
35
41
  const client = await database.getClient();
36
42
  const db = DatabaseFactory.DatabaseFactory.getDatabase(client, logger);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 */\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './router';\nimport { migrate } from './database/migration';\nimport { DatabaseFactory } from './database/DatabaseFactory';\nimport { EventBatchProcessor } from './domain/EventBatchProcessor';\nimport EventApiController from './controllers/EventApiController';\nimport { schedulePartition } from './database/partition';\nimport { getConfigurationOptions } from './utils/config';\n\n/**\n * adoptionInsightsPlugin backend plugin\n *\n * @public\n */\nexport const adoptionInsightsPlugin = createBackendPlugin({\n pluginId: 'adoption-insights',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n database: coreServices.database,\n scheduler: coreServices.scheduler,\n permissions: coreServices.permissions,\n },\n async init({\n config,\n logger,\n httpAuth,\n httpRouter,\n database,\n scheduler,\n permissions,\n }) {\n // Queue configuration\n const options = getConfigurationOptions(config);\n const client = await database.getClient();\n const db = DatabaseFactory.getDatabase(client, logger);\n const processor = new EventBatchProcessor(db, logger, options);\n const eventApiController = new EventApiController(\n db,\n processor,\n config,\n );\n\n // Migrate database\n await migrate(database);\n\n // Schedule partition creation\n if (db.isPartitionSupported()) {\n schedulePartition(client, { logger, scheduler });\n }\n\n httpRouter.use(\n await createRouter({\n httpAuth,\n permissions,\n eventApiController,\n }),\n );\n\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","config","getConfigurationOptions","DatabaseFactory","EventBatchProcessor","EventApiController","migrate","schedulePartition","createRouter"],"mappings":";;;;;;;;;;;AAgCO,MAAM,yBAAyBA,oCAAoB,CAAA;AAAA,EACxD,QAAU,EAAA,mBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,UAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,aAAaA,6BAAa,CAAA;AAAA,OAC5B;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,gBACTC,QAAA;AAAA,QACA,MAAA;AAAA,QACA,QAAA;AAAA,QACA,UAAA;AAAA,QACA,QAAA;AAAA,QACA,SAAA;AAAA,QACA;AAAA,OACC,EAAA;AAED,QAAM,MAAA,OAAA,GAAUC,+BAAwBD,QAAM,CAAA;AAC9C,QAAM,MAAA,MAAA,GAAS,MAAM,QAAA,CAAS,SAAU,EAAA;AACxC,QAAA,MAAM,EAAK,GAAAE,+BAAA,CAAgB,WAAY,CAAA,MAAA,EAAQ,MAAM,CAAA;AACrD,QAAA,MAAM,SAAY,GAAA,IAAIC,uCAAoB,CAAA,EAAA,EAAI,QAAQ,OAAO,CAAA;AAC7D,QAAA,MAAM,qBAAqB,IAAIC,0BAAA;AAAA,UAC7B,EAAA;AAAA,UACA,SAAA;AAAA,UACAJ;AAAA,SACF;AAGA,QAAA,MAAMK,kBAAQ,QAAQ,CAAA;AAGtB,QAAI,IAAA,EAAA,CAAG,sBAAwB,EAAA;AAC7B,UAAAC,2BAAA,CAAkB,MAAQ,EAAA,EAAE,MAAQ,EAAA,SAAA,EAAW,CAAA;AAAA;AAGjD,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMC,mBAAa,CAAA;AAAA,YACjB,QAAA;AAAA,YACA,WAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAEA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,IAAM,EAAA,SAAA;AAAA,UACN,KAAO,EAAA;AAAA,SACR,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 */\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { adoptionInsightsEventsReadPermission } from '@red-hat-developer-hub/backstage-plugin-adoption-insights-common';\nimport { createRouter } from './router';\nimport { migrate } from './database/migration';\nimport { DatabaseFactory } from './database/DatabaseFactory';\nimport { EventBatchProcessor } from './domain/EventBatchProcessor';\nimport EventApiController from './controllers/EventApiController';\nimport { schedulePartition } from './database/partition';\nimport { getConfigurationOptions } from './utils/config';\n\n/**\n * adoptionInsightsPlugin backend plugin\n *\n * @public\n */\nexport const adoptionInsightsPlugin = createBackendPlugin({\n pluginId: 'adoption-insights',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n database: coreServices.database,\n scheduler: coreServices.scheduler,\n permissions: coreServices.permissions,\n permissionsRegistry: coreServices.permissionsRegistry,\n },\n async init({\n config,\n logger,\n httpAuth,\n httpRouter,\n database,\n scheduler,\n permissions,\n permissionsRegistry,\n }) {\n // Register plugin permission\n permissionsRegistry.addPermissions([\n adoptionInsightsEventsReadPermission,\n ]);\n\n // Queue configuration\n const options = getConfigurationOptions(config);\n const client = await database.getClient();\n const db = DatabaseFactory.getDatabase(client, logger);\n const processor = new EventBatchProcessor(db, logger, options);\n const eventApiController = new EventApiController(\n db,\n processor,\n config,\n );\n\n // Migrate database\n await migrate(database);\n\n // Schedule partition creation\n if (db.isPartitionSupported()) {\n schedulePartition(client, { logger, scheduler });\n }\n\n httpRouter.use(\n await createRouter({\n httpAuth,\n permissions,\n eventApiController,\n }),\n );\n\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","config","adoptionInsightsEventsReadPermission","getConfigurationOptions","DatabaseFactory","EventBatchProcessor","EventApiController","migrate","schedulePartition","createRouter"],"mappings":";;;;;;;;;;;;AAiCO,MAAM,yBAAyBA,oCAAoB,CAAA;AAAA,EACxD,QAAU,EAAA,mBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ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AAAA,YACjB,QAAA;AAAA,YACA,WAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAEA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,IAAM,EAAA,SAAA;AAAA,UACN,KAAO,EAAA;AAAA,SACR,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var express = require('express');
4
- var Router = require('express-promise-router');
5
3
  var errors = require('@backstage/errors');
6
4
  var pluginPermissionCommon = require('@backstage/plugin-permission-common');
7
5
  var backstagePluginAdoptionInsightsCommon = require('@red-hat-developer-hub/backstage-plugin-adoption-insights-common');
8
- var pluginPermissionNode = require('@backstage/plugin-permission-node');
6
+ var express = require('express');
7
+ var Router = require('express-promise-router');
9
8
 
10
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
10
 
@@ -18,10 +17,6 @@ async function createRouter({
18
17
  eventApiController
19
18
  }) {
20
19
  const router = Router__default.default();
21
- const permissionIntegrationRouter = pluginPermissionNode.createPermissionIntegrationRouter({
22
- permissions: [backstagePluginAdoptionInsightsCommon.adoptionInsightsEventsReadPermission]
23
- });
24
- router.use(permissionIntegrationRouter);
25
20
  router.use(express__default.default.json());
26
21
  const authorizeUser = async (req) => {
27
22
  const credentials = await httpAuth.credentials(req, { allow: ["user"] });
@@ -1 +1 @@
1
- {"version":3,"file":"router.cjs.js","sources":["../src/router.ts"],"sourcesContent":["import express, { Request, Response } from 'express';\nimport Router from 'express-promise-router';\n/*\n * Copyright Red Hat, Inc.\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 */\nimport {\n HttpAuthService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport { NotAllowedError } from '@backstage/errors';\nimport { AuthorizeResult } from '@backstage/plugin-permission-common';\nimport { adoptionInsightsEventsReadPermission } from '@red-hat-developer-hub/backstage-plugin-adoption-insights-common';\nimport EventApiController from './controllers/EventApiController';\nimport { QueryParams } from './types/event-request';\nimport { createPermissionIntegrationRouter } from '@backstage/plugin-permission-node';\n\nexport async function createRouter({\n httpAuth,\n permissions,\n eventApiController,\n}: {\n httpAuth: HttpAuthService;\n permissions: PermissionsService;\n eventApiController: EventApiController;\n}): Promise<express.Router> {\n const router = Router();\n\n const permissionIntegrationRouter = createPermissionIntegrationRouter({\n permissions: [adoptionInsightsEventsReadPermission],\n });\n\n router.use(permissionIntegrationRouter);\n router.use(express.json());\n\n const authorizeUser = async (\n req: Request<{}, {}, {}, QueryParams>,\n ): Promise<void> => {\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n const decision = (\n await permissions.authorize(\n [{ permission: adoptionInsightsEventsReadPermission }],\n { credentials },\n )\n )[0];\n\n if (decision.result === AuthorizeResult.DENY) {\n throw new NotAllowedError('Unauthorized');\n }\n };\n const getUserEntityRef = async (req: Request): Promise<string> => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['user'],\n });\n return credentials.principal.userEntityRef;\n };\n router.use(async (req, _, next) => {\n await getUserEntityRef(req);\n next();\n });\n\n router.get(\n '/events',\n async (req: Request<{}, {}, {}, QueryParams>, res: Response) => {\n await authorizeUser(req);\n return eventApiController.getInsights(req, res);\n },\n );\n\n router.post('/events', async (req, res) => {\n return eventApiController.trackEvents(req, res);\n });\n\n router.get('/health', (_, response) => {\n response.json({ status: 'ok' });\n });\n\n return router;\n}\n"],"names":["Router","createPermissionIntegrationRouter","adoptionInsightsEventsReadPermission","express","AuthorizeResult","NotAllowedError"],"mappings":";;;;;;;;;;;;;;AA4BA,eAAsB,YAAa,CAAA;AAAA,EAC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AuC,GAAkB,KAAA;AAC9D,MAAA,MAAM,cAAc,GAAG,CAAA;AACvB,MAAO,OAAA,kBAAA,CAAmB,WAAY,CAAA,GAAA,EAAK,GAAG,CAAA;AAAA;AAChD,GACF;AAEA,EAAA,MAAA,CAAO,IAAK,CAAA,SAAA,EAAW,OAAO,GAAA,EAAK,GAAQ,KAAA;AACzC,IAAO,OAAA,kBAAA,CAAmB,WAAY,CAAA,GAAA,EAAK,GAAG,CAAA;AAAA,GAC/C,CAAA;AAED,EAAA,MAAA,CAAO,GAAI,CAAA,SAAA,EAAW,CAAC,CAAA,EAAG,QAAa,KAAA;AACrC,IAAA,QAAA,CAAS,IAAK,CAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA;AAAA,GAC/B,CAAA;AAED,EAAO,OAAA,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"router.cjs.js","sources":["../src/router.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 */\nimport {\n HttpAuthService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport { NotAllowedError } from '@backstage/errors';\nimport { AuthorizeResult } from '@backstage/plugin-permission-common';\nimport { adoptionInsightsEventsReadPermission } from '@red-hat-developer-hub/backstage-plugin-adoption-insights-common';\nimport express, { Request, Response } from 'express';\nimport Router from 'express-promise-router';\n\nimport EventApiController from './controllers/EventApiController';\nimport { QueryParams } from './types/event-request';\n\nexport async function createRouter({\n httpAuth,\n permissions,\n eventApiController,\n}: {\n httpAuth: HttpAuthService;\n permissions: PermissionsService;\n eventApiController: EventApiController;\n}): Promise<express.Router> {\n const router = Router();\n\n router.use(express.json());\n\n const authorizeUser = async (\n req: Request<{}, {}, {}, QueryParams>,\n ): Promise<void> => {\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n const decision = (\n await permissions.authorize(\n [{ permission: adoptionInsightsEventsReadPermission }],\n { credentials },\n )\n )[0];\n\n if (decision.result === AuthorizeResult.DENY) {\n throw new NotAllowedError('Unauthorized');\n }\n };\n const getUserEntityRef = async (req: Request): Promise<string> => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['user'],\n });\n return credentials.principal.userEntityRef;\n };\n router.use(async (req, _, next) => {\n await getUserEntityRef(req);\n next();\n });\n\n router.get(\n '/events',\n async (req: Request<{}, {}, {}, QueryParams>, res: Response) => {\n await authorizeUser(req);\n return eventApiController.getInsights(req, res);\n },\n );\n\n router.post('/events', async (req, res) => {\n return eventApiController.trackEvents(req, res);\n });\n\n router.get('/health', (_, response) => {\n response.json({ status: 'ok' });\n });\n\n return router;\n}\n"],"names":["Router","express","adoptionInsightsEventsReadPermission","AuthorizeResult","NotAllowedError"],"mappings":";;;;;;;;;;;;;AA4BA,eAAsB,YAAa,CAAA;AAAA,EACjC,QAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAI4B,EAAA;AAC1B,EAAA,MAAM,SAASA,uBAAO,EAAA;AAEtB,EAAO,MAAA,CAAA,GAAA,CAAIC,wBAAQ,CAAA,IAAA,EAAM,CAAA;AAEzB,EAAM,MAAA,aAAA,GAAgB,OACpB,GACkB,KAAA;AAClB,IAAM,MAAA,WAAA,GAAc,MAAM,QAAA,CAAS,WAAY,CAAA,GAAA,EAAK,EAAE,KAAO,EAAA,CAAC,MAAM,CAAA,EAAG,CAAA;AACvE,IAAM,MAAA,QAAA,GAAA,CACJ,MAAM,WAAY,CAAA,SAAA;AAAA,MAChB,CAAC,EAAE,UAAY,EAAAC,0EAAA,EAAsC,CAAA;AAAA,MACrD,EAAE,WAAY;AAAA,OAEhB,CAAC,CAAA;AAEH,IAAI,IAAA,QAAA,CAAS,MAAW,KAAAC,sCAAA,CAAgB,IAAM,EAAA;AAC5C,MAAM,MAAA,IAAIC,uBAAgB,cAAc,CAAA;AAAA;AAC1C,GACF;AACA,EAAM,MAAA,gBAAA,GAAmB,OAAO,GAAkC,KAAA;AAChE,IAAA,MAAM,WAAc,GAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAK,EAAA;AAAA,MAClD,KAAA,EAAO,CAAC,MAAM;AAAA,KACf,CAAA;AACD,IAAA,OAAO,YAAY,SAAU,CAAA,aAAA;AAAA,GAC/B;AACA,EAAA,MAAA,CAAO,GAAI,CAAA,OAAO,GAAK,EAAA,CAAA,EAAG,IAAS,KAAA;AACjC,IAAA,MAAM,iBAAiB,GAAG,CAAA;AAC1B,IAAK,IAAA,EAAA;AAAA,GACN,CAAA;AAED,EAAO,MAAA,CAAA,GAAA;AAAA,IACL,SAAA;AAAA,IACA,OAAO,KAAuC,GAAkB,KAAA;AAC9D,MAAA,MAAM,cAAc,GAAG,CAAA;AACvB,MAAO,OAAA,kBAAA,CAAmB,WAAY,CAAA,GAAA,EAAK,GAAG,CAAA;AAAA;AAChD,GACF;AAEA,EAAA,MAAA,CAAO,IAAK,CAAA,SAAA,EAAW,OAAO,GAAA,EAAK,GAAQ,KAAA;AACzC,IAAO,OAAA,kBAAA,CAAmB,WAAY,CAAA,GAAA,EAAK,GAAG,CAAA;AAAA,GAC/C,CAAA;AAED,EAAA,MAAA,CAAO,GAAI,CAAA,SAAA,EAAW,CAAC,CAAA,EAAG,QAAa,KAAA;AACrC,IAAA,QAAA,CAAS,IAAK,CAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA;AAAA,GAC/B,CAAA;AAED,EAAO,OAAA,MAAA;AACT;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@red-hat-developer-hub/backstage-plugin-adoption-insights-backend",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,13 +36,13 @@
36
36
  "postpack": "backstage-cli package postpack"
37
37
  },
38
38
  "dependencies": {
39
- "@backstage/backend-defaults": "^0.8.1",
40
- "@backstage/backend-plugin-api": "^1.2.0",
41
- "@backstage/core-plugin-api": "^1.10.4",
39
+ "@backstage/backend-defaults": "^0.10.0",
40
+ "@backstage/backend-plugin-api": "^1.3.1",
41
+ "@backstage/core-plugin-api": "^1.10.7",
42
42
  "@backstage/errors": "^1.2.7",
43
- "@backstage/plugin-catalog-node": "^1.15.1",
44
- "@backstage/plugin-permission-common": "^0.8.4",
45
- "@red-hat-developer-hub/backstage-plugin-adoption-insights-common": "^0.2.0",
43
+ "@backstage/plugin-catalog-node": "^1.17.0",
44
+ "@backstage/plugin-permission-common": "^0.9.0",
45
+ "@red-hat-developer-hub/backstage-plugin-adoption-insights-common": "^0.3.0",
46
46
  "express": "^4.17.1",
47
47
  "express-promise-router": "^4.1.0",
48
48
  "json-2-csv": "^5.5.8",
@@ -52,8 +52,8 @@
52
52
  "zod": "^3.22.4"
53
53
  },
54
54
  "devDependencies": {
55
- "@backstage/backend-test-utils": "^1.3.0",
56
- "@backstage/cli": "^0.30.0",
55
+ "@backstage/backend-test-utils": "^1.5.0",
56
+ "@backstage/cli": "^0.32.1",
57
57
  "@types/express": "^4.17.6",
58
58
  "@types/supertest": "^2.0.12",
59
59
  "supertest": "^6.2.4"
@@ -66,8 +66,8 @@
66
66
  "configSchema": "config.d.ts",
67
67
  "typesVersions": {
68
68
  "*": {
69
- "index": [
70
- "dist/index.d.ts"
69
+ "package.json": [
70
+ "package.json"
71
71
  ]
72
72
  }
73
73
  }