@backstage/plugin-catalog-backend-module-unprocessed 0.0.0-nightly-20240319021037 → 0.0.0-nightly-20240322021005

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,13 +1,58 @@
1
1
  # @backstage/plugin-catalog-backend-module-unprocessed
2
2
 
3
- ## 0.0.0-nightly-20240319021037
3
+ ## 0.0.0-nightly-20240322021005
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/backend-common@0.0.0-nightly-20240322021005
9
+ - @backstage/plugin-auth-node@0.0.0-nightly-20240322021005
10
+ - @backstage/plugin-permission-node@0.0.0-nightly-20240322021005
11
+ - @backstage/backend-plugin-api@0.0.0-nightly-20240322021005
12
+ - @backstage/catalog-model@1.4.5
13
+ - @backstage/errors@1.2.4
14
+ - @backstage/plugin-catalog-unprocessed-entities-common@0.0.1
15
+ - @backstage/plugin-permission-common@0.7.13
16
+
17
+ ## 0.4.0
18
+
19
+ ### Minor Changes
20
+
21
+ - 924c1ac: **BREAKING**- the `@backstage/plugin-catalog-backend-module-unprocessed` constructor is now private, and have been moved to using the static `.create` method instead which now requires a `PermissionService` and `DiscoveryService`.
22
+
23
+ If you're using this module in the old backend system you'll need to migrate to using the `.create` method and pass in the new required parameters in `packages/backend/src/plugins/catalog.ts`.
24
+
25
+ No changes should be required if you're using the new backend system.
26
+
27
+ ```diff
28
+ - const unprocessed = new UnprocessedEntitiesModule(
29
+ - await env.database.getClient(),
30
+ - router,
31
+ - );
32
+ + const unprocessed = UnprocessedEntitiesModule.create({
33
+ + database: await env.database.getClient(),
34
+ + router,
35
+ + permissions: env.permissions,
36
+ + discovery: env.discovery,
37
+ + });
38
+
39
+ unprocessed.registerRoutes();
40
+ ```
41
+
42
+ Adds the ability to delete an unprocessed entity from the `refresh_state` table. This change requires enabling permissions for your Backstage instance.
4
43
 
5
44
  ### Patch Changes
6
45
 
7
46
  - 2bd1410: Removed unused dependencies
8
47
  - Updated dependencies
9
- - @backstage/backend-plugin-api@0.0.0-nightly-20240319021037
10
- - @backstage/catalog-model@0.0.0-nightly-20240319021037
48
+ - @backstage/backend-common@0.21.4
49
+ - @backstage/plugin-auth-node@0.4.9
50
+ - @backstage/errors@1.2.4
51
+ - @backstage/backend-plugin-api@0.6.14
52
+ - @backstage/plugin-permission-common@0.7.13
53
+ - @backstage/plugin-permission-node@0.7.25
54
+ - @backstage/plugin-catalog-unprocessed-entities-common@0.0.1
55
+ - @backstage/catalog-model@1.4.5
11
56
 
12
57
  ## 0.3.11-next.2
13
58
 
package/dist/index.cjs.js CHANGED
@@ -4,10 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
6
  var Router = require('express-promise-router');
7
+ var pluginPermissionCommon = require('@backstage/plugin-permission-common');
8
+ var pluginPermissionNode = require('@backstage/plugin-permission-node');
9
+ var pluginCatalogUnprocessedEntitiesCommon = require('@backstage/plugin-catalog-unprocessed-entities-common');
10
+ var errors = require('@backstage/errors');
11
+ var backendCommon = require('@backstage/backend-common');
7
12
 
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
9
14
 
10
- var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
15
+ var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
11
16
 
12
17
  var __defProp = Object.defineProperty;
13
18
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -16,12 +21,27 @@ var __publicField = (obj, key, value) => {
16
21
  return value;
17
22
  };
18
23
  class UnprocessedEntitiesModule {
19
- constructor(database, router) {
24
+ constructor(database, router, permissions, discovery, httpAuth) {
20
25
  this.database = database;
21
26
  this.router = router;
27
+ this.permissions = permissions;
22
28
  __publicField(this, "moduleRouter");
23
- this.moduleRouter = Router__default["default"]();
29
+ __publicField(this, "httpAuth");
30
+ this.moduleRouter = Router__default.default();
24
31
  this.router.use(this.moduleRouter);
32
+ this.httpAuth = backendCommon.createLegacyAuthAdapters({
33
+ discovery,
34
+ httpAuth
35
+ }).httpAuth;
36
+ }
37
+ static create(options) {
38
+ return new UnprocessedEntitiesModule(
39
+ options.database,
40
+ options.router,
41
+ options.permissions,
42
+ options.discovery,
43
+ options.httpAuth
44
+ );
25
45
  }
26
46
  async unprocessed(request) {
27
47
  if (request.reason === "pending") {
@@ -75,21 +95,44 @@ class UnprocessedEntitiesModule {
75
95
  return res;
76
96
  }
77
97
  registerRoutes() {
98
+ const permissionIntegrationRouter = pluginPermissionNode.createPermissionIntegrationRouter({
99
+ permissions: [pluginCatalogUnprocessedEntitiesCommon.unprocessedEntitiesDeletePermission]
100
+ });
101
+ const isRequestAuthorized = async (req, permission) => {
102
+ const decision = (await this.permissions.authorize([{ permission }], {
103
+ credentials: await this.httpAuth.credentials(req)
104
+ }))[0];
105
+ return decision.result !== pluginPermissionCommon.AuthorizeResult.DENY;
106
+ };
107
+ this.router.use(permissionIntegrationRouter);
78
108
  this.moduleRouter.get("/entities/unprocessed/failed", async (req, res) => {
79
109
  return res.json(
80
110
  await this.unprocessed({
81
111
  reason: "failed",
82
- owner: req.query.owner
112
+ owner: String(req.query.owner)
83
113
  })
84
114
  );
85
115
  }).get("/entities/unprocessed/pending", async (req, res) => {
86
116
  return res.json(
87
117
  await this.unprocessed({
88
118
  reason: "pending",
89
- owner: req.query.owner
119
+ owner: String(req.query.owner)
90
120
  })
91
121
  );
92
- });
122
+ }).delete(
123
+ "/entities/unprocessed/delete/:entity_id",
124
+ async (request, response) => {
125
+ const authorized = await isRequestAuthorized(
126
+ request,
127
+ pluginCatalogUnprocessedEntitiesCommon.unprocessedEntitiesDeletePermission
128
+ );
129
+ if (!authorized) {
130
+ throw new errors.NotAllowedError("Unauthorized");
131
+ }
132
+ await this.database("refresh_state").where({ entity_id: request.params.entity_id }).delete();
133
+ response.status(204).send();
134
+ }
135
+ );
93
136
  }
94
137
  }
95
138
 
@@ -101,13 +144,26 @@ const catalogModuleUnprocessedEntities = backendPluginApi.createBackendModule({
101
144
  deps: {
102
145
  database: backendPluginApi.coreServices.database,
103
146
  router: backendPluginApi.coreServices.httpRouter,
104
- logger: backendPluginApi.coreServices.logger
147
+ logger: backendPluginApi.coreServices.logger,
148
+ httpAuth: backendPluginApi.coreServices.httpAuth,
149
+ discovery: backendPluginApi.coreServices.discovery,
150
+ permissions: backendPluginApi.coreServices.permissions
105
151
  },
106
- async init({ database, router, logger }) {
107
- const module = new UnprocessedEntitiesModule(
108
- await database.getClient(),
109
- router
110
- );
152
+ async init({
153
+ database,
154
+ router,
155
+ logger,
156
+ permissions,
157
+ httpAuth,
158
+ discovery
159
+ }) {
160
+ const module = UnprocessedEntitiesModule.create({
161
+ database: await database.getClient(),
162
+ router,
163
+ permissions,
164
+ discovery,
165
+ httpAuth
166
+ });
111
167
  module.registerRoutes();
112
168
  logger.info(
113
169
  "registered additional routes for catalogModuleUnprocessedEntities"
@@ -118,5 +174,5 @@ const catalogModuleUnprocessedEntities = backendPluginApi.createBackendModule({
118
174
  });
119
175
 
120
176
  exports.UnprocessedEntitiesModule = UnprocessedEntitiesModule;
121
- exports["default"] = catalogModuleUnprocessedEntities;
177
+ exports.default = catalogModuleUnprocessedEntities;
122
178
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/UnprocessedEntitiesModule.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright 2023 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 HydratedRefreshState,\n RefreshState,\n UnprocessedEntitiesRequest,\n UnprocessedEntitiesResponse,\n} from './types';\nimport { Knex } from 'knex';\nimport { HttpRouterService } from '@backstage/backend-plugin-api';\nimport Router from 'express-promise-router';\n\n/**\n * Module providing Unprocessed Entities API endpoints\n *\n * @public\n */\nexport class UnprocessedEntitiesModule {\n private readonly moduleRouter;\n\n constructor(\n private readonly database: Knex,\n private readonly router: Pick<HttpRouterService, 'use'>,\n ) {\n this.moduleRouter = Router();\n this.router.use(this.moduleRouter);\n }\n\n private async unprocessed(\n request: UnprocessedEntitiesRequest,\n ): Promise<UnprocessedEntitiesResponse> {\n if (request.reason === 'pending') {\n return {\n type: 'pending',\n entities: await this.pending(request.owner),\n };\n }\n return {\n type: 'failed',\n entities: await this.failed(request.owner),\n };\n }\n\n private hydrateRefreshState(r: RefreshState): HydratedRefreshState {\n return {\n ...r,\n unprocessed_entity: JSON.parse(r.unprocessed_entity),\n ...(r.processed_entity && {\n processed_entity: JSON.parse(r.processed_entity),\n }),\n ...(r.errors && { errors: JSON.parse(r.errors) }),\n ...(r.cache && { cache: JSON.parse(r.cache) }),\n };\n }\n\n private async pending(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .leftJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.entity_id')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n private async failed(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .rightJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.final_entity')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n registerRoutes() {\n this.moduleRouter\n .get('/entities/unprocessed/failed', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'failed',\n owner: req.query.owner as string,\n }),\n );\n })\n .get('/entities/unprocessed/pending', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'pending',\n owner: req.query.owner as string,\n }),\n );\n });\n }\n}\n","/*\n * Copyright 2023 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 createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { UnprocessedEntitiesModule } from './UnprocessedEntitiesModule';\n\n/**\n * Catalog Module for Unprocessed Entities\n *\n * @public\n */\nexport const catalogModuleUnprocessedEntities = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'catalog-module-unprocessed-entities',\n register(env) {\n env.registerInit({\n deps: {\n database: coreServices.database,\n router: coreServices.httpRouter,\n logger: coreServices.logger,\n },\n async init({ database, router, logger }) {\n const module = new UnprocessedEntitiesModule(\n await database.getClient(),\n router,\n );\n\n module.registerRoutes();\n logger.info(\n 'registered additional routes for catalogModuleUnprocessedEntities',\n );\n },\n });\n },\n});\n"],"names":["Router","createBackendModule","coreServices"],"mappings":";;;;;;;;;;;;;;;;;AA+BO,MAAM,yBAA0B,CAAA;AAAA,EAGrC,WAAA,CACmB,UACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAJnB,IAAiB,aAAA,CAAA,IAA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023 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 HydratedRefreshState,\n RefreshState,\n UnprocessedEntitiesRequest,\n UnprocessedEntitiesResponse,\n} from './types';\nimport { Knex } from 'knex';\nimport {\n DiscoveryService,\n HttpAuthService,\n HttpRouterService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport Router from 'express-promise-router';\nimport type { Request } from 'express';\n\nimport {\n AuthorizeResult,\n BasicPermission,\n} from '@backstage/plugin-permission-common';\nimport { createPermissionIntegrationRouter } from '@backstage/plugin-permission-node';\nimport { unprocessedEntitiesDeletePermission } from '@backstage/plugin-catalog-unprocessed-entities-common';\nimport { NotAllowedError } from '@backstage/errors';\nimport { createLegacyAuthAdapters } from '@backstage/backend-common';\n\n/**\n * Module providing Unprocessed Entities API endpoints\n *\n * @public\n */\nexport class UnprocessedEntitiesModule {\n private readonly moduleRouter;\n\n private readonly httpAuth: HttpAuthService;\n\n private constructor(\n private readonly database: Knex,\n private readonly router: Pick<HttpRouterService, 'use'>,\n private readonly permissions: PermissionsService,\n discovery: DiscoveryService,\n httpAuth?: HttpAuthService,\n ) {\n this.moduleRouter = Router();\n this.router.use(this.moduleRouter);\n\n this.httpAuth = createLegacyAuthAdapters({\n discovery,\n httpAuth,\n }).httpAuth;\n }\n\n static create(options: {\n router: Pick<HttpRouterService, 'use'>;\n database: Knex;\n discovery: DiscoveryService;\n permissions: PermissionsService;\n httpAuth?: HttpAuthService;\n }) {\n return new UnprocessedEntitiesModule(\n options.database,\n options.router,\n options.permissions,\n options.discovery,\n options.httpAuth,\n );\n }\n\n private async unprocessed(\n request: UnprocessedEntitiesRequest,\n ): Promise<UnprocessedEntitiesResponse> {\n if (request.reason === 'pending') {\n return {\n type: 'pending',\n entities: await this.pending(request.owner),\n };\n }\n return {\n type: 'failed',\n entities: await this.failed(request.owner),\n };\n }\n\n private hydrateRefreshState(r: RefreshState): HydratedRefreshState {\n return {\n ...r,\n unprocessed_entity: JSON.parse(r.unprocessed_entity),\n ...(r.processed_entity && {\n processed_entity: JSON.parse(r.processed_entity),\n }),\n ...(r.errors && { errors: JSON.parse(r.errors) }),\n ...(r.cache && { cache: JSON.parse(r.cache) }),\n };\n }\n\n private async pending(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .leftJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.entity_id')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n private async failed(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .rightJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.final_entity')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n registerRoutes() {\n const permissionIntegrationRouter = createPermissionIntegrationRouter({\n permissions: [unprocessedEntitiesDeletePermission],\n });\n\n const isRequestAuthorized = async (\n req: Request,\n permission: BasicPermission,\n ): Promise<boolean> => {\n const decision = (\n await this.permissions.authorize([{ permission }], {\n credentials: await this.httpAuth.credentials(req),\n })\n )[0];\n\n return decision.result !== AuthorizeResult.DENY;\n };\n\n this.router.use(permissionIntegrationRouter);\n\n this.moduleRouter\n .get('/entities/unprocessed/failed', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'failed',\n owner: String(req.query.owner),\n }),\n );\n })\n .get('/entities/unprocessed/pending', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'pending',\n owner: String(req.query.owner),\n }),\n );\n })\n .delete(\n '/entities/unprocessed/delete/:entity_id',\n async (request, response) => {\n const authorized = await isRequestAuthorized(\n request,\n unprocessedEntitiesDeletePermission,\n );\n\n if (!authorized) {\n throw new NotAllowedError('Unauthorized');\n }\n\n await this.database('refresh_state')\n .where({ entity_id: request.params.entity_id })\n .delete();\n\n response.status(204).send();\n },\n );\n }\n}\n","/*\n * Copyright 2023 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 createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { UnprocessedEntitiesModule } from './UnprocessedEntitiesModule';\n\n/**\n * Catalog Module for Unprocessed Entities\n *\n * @public\n */\nexport const catalogModuleUnprocessedEntities = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'catalog-module-unprocessed-entities',\n register(env) {\n env.registerInit({\n deps: {\n database: coreServices.database,\n router: coreServices.httpRouter,\n logger: coreServices.logger,\n httpAuth: coreServices.httpAuth,\n discovery: coreServices.discovery,\n permissions: coreServices.permissions,\n },\n async init({\n database,\n router,\n logger,\n permissions,\n httpAuth,\n discovery,\n }) {\n const module = UnprocessedEntitiesModule.create({\n database: await database.getClient(),\n router,\n permissions,\n discovery,\n httpAuth,\n });\n\n module.registerRoutes();\n\n logger.info(\n 'registered additional routes for catalogModuleUnprocessedEntities',\n );\n },\n });\n },\n});\n"],"names":["Router","createLegacyAuthAdapters","createPermissionIntegrationRouter","unprocessedEntitiesDeletePermission","AuthorizeResult","NotAllowedError","create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,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,UAAUC,6BAAa,CAAA,QAAA;AAAA,QACvB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,aAAaA,6BAAa,CAAA,WAAA;AAAA,OAC5B;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,QAAA;AAAA,QACA,MAAA;AAAA,QACA,MAAA;AAAA,QACA,WAAA;AAAA,QACA,QAAA;AAAA,QACA,SAAA;AAAA,OACC,EAAA;AACD,QAAM,MAAA,MAAA,GAAS,0BAA0B,MAAO,CAAA;AAAA,UAC9C,QAAA,EAAU,MAAM,QAAA,CAAS,SAAU,EAAA;AAAA,UACnC,MAAA;AAAA,UACA,WAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,SACD,CAAA,CAAA;AAED,QAAA,MAAA,CAAO,cAAe,EAAA,CAAA;AAEtB,QAAO,MAAA,CAAA,IAAA;AAAA,UACL,mEAAA;AAAA,SACF,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
- import { HttpRouterService } from '@backstage/backend-plugin-api';
2
+ import { HttpRouterService, DiscoveryService, PermissionsService, HttpAuthService } from '@backstage/backend-plugin-api';
3
3
  import { Knex } from 'knex';
4
4
 
5
5
  /**
@@ -17,8 +17,17 @@ declare const catalogModuleUnprocessedEntities: () => _backstage_backend_plugin_
17
17
  declare class UnprocessedEntitiesModule {
18
18
  private readonly database;
19
19
  private readonly router;
20
+ private readonly permissions;
20
21
  private readonly moduleRouter;
21
- constructor(database: Knex, router: Pick<HttpRouterService, 'use'>);
22
+ private readonly httpAuth;
23
+ private constructor();
24
+ static create(options: {
25
+ router: Pick<HttpRouterService, 'use'>;
26
+ database: Knex;
27
+ discovery: DiscoveryService;
28
+ permissions: PermissionsService;
29
+ httpAuth?: HttpAuthService;
30
+ }): UnprocessedEntitiesModule;
22
31
  private unprocessed;
23
32
  private hydrateRefreshState;
24
33
  private pending;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-unprocessed",
3
3
  "description": "Backstage Catalog module to view unprocessed entities",
4
- "version": "0.0.0-nightly-20240319021037",
4
+ "version": "0.0.0-nightly-20240322021005",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -28,14 +28,21 @@
28
28
  "postpack": "backstage-cli package postpack"
29
29
  },
30
30
  "devDependencies": {
31
- "@backstage/cli": "^0.0.0-nightly-20240319021037"
31
+ "@backstage/cli": "^0.0.0-nightly-20240322021005",
32
+ "@types/express": "^4.17.6"
32
33
  },
33
34
  "files": [
34
35
  "dist"
35
36
  ],
36
37
  "dependencies": {
37
- "@backstage/backend-plugin-api": "^0.0.0-nightly-20240319021037",
38
- "@backstage/catalog-model": "^0.0.0-nightly-20240319021037",
38
+ "@backstage/backend-common": "^0.0.0-nightly-20240322021005",
39
+ "@backstage/backend-plugin-api": "^0.0.0-nightly-20240322021005",
40
+ "@backstage/catalog-model": "^1.4.5",
41
+ "@backstage/errors": "^1.2.4",
42
+ "@backstage/plugin-auth-node": "^0.0.0-nightly-20240322021005",
43
+ "@backstage/plugin-catalog-unprocessed-entities-common": "^0.0.1",
44
+ "@backstage/plugin-permission-common": "^0.7.13",
45
+ "@backstage/plugin-permission-node": "^0.0.0-nightly-20240322021005",
39
46
  "express-promise-router": "^4.1.1",
40
47
  "knex": "^3.0.0"
41
48
  }