Merge pull request #26049 from backstage/nbs10/remove-depedency-on-commons
[NBS 1.0]: Stop using `backend-common` in user-settings plugin
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-user-settings-backend': patch
|
||||
---
|
||||
|
||||
In preparation to stop supporting to the legacy backend system, the `createRouter` function is now deprecated and we strongly recommend you [migrate](https://backstage.io/docs/backend-system/building-backends/migrating) your backend to the new system.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-test-utils': patch
|
||||
---
|
||||
|
||||
There is a new `mockErrorHandler` utility to help in mocking the error middleware in tests.
|
||||
@@ -3,8 +3,10 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
/// <reference types="express" />
|
||||
/// <reference types="jest" />
|
||||
/// <reference types="node" />
|
||||
/// <reference types="qs" />
|
||||
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { Backend } from '@backstage/backend-app-api';
|
||||
@@ -18,6 +20,7 @@ import { BackstageUserPrincipal } from '@backstage/backend-plugin-api';
|
||||
import { CacheService } from '@backstage/backend-plugin-api';
|
||||
import { DatabaseService } from '@backstage/backend-plugin-api';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { ErrorRequestHandler } from 'express';
|
||||
import { EventsService } from '@backstage/plugin-events-node';
|
||||
import { ExtendedHttpServer } from '@backstage/backend-defaults/rootHttpRouter';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
@@ -28,6 +31,8 @@ import Keyv from 'keyv';
|
||||
import { Knex } from 'knex';
|
||||
import { LifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { ParamsDictionary } from 'express-serve-static-core';
|
||||
import { ParsedQs } from 'qs';
|
||||
import { PermissionsService } from '@backstage/backend-plugin-api';
|
||||
import { RootConfigService } from '@backstage/backend-plugin-api';
|
||||
import { RootHealthService } from '@backstage/backend-plugin-api';
|
||||
@@ -137,6 +142,15 @@ export interface MockDirectoryContentOptions {
|
||||
shouldReadAsText?: boolean | ((path: string, buffer: Buffer) => boolean);
|
||||
}
|
||||
|
||||
// @public
|
||||
export function mockErrorHandler(): ErrorRequestHandler<
|
||||
ParamsDictionary,
|
||||
any,
|
||||
any,
|
||||
ParsedQs,
|
||||
Record<string, any>
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export namespace mockServices {
|
||||
// (undocumented)
|
||||
|
||||
@@ -55,7 +55,10 @@
|
||||
"@backstage/types": "workspace:^",
|
||||
"@keyv/memcache": "^1.3.5",
|
||||
"@keyv/redis": "^2.5.3",
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/express-serve-static-core": "^4.17.5",
|
||||
"@types/keyv": "^4.2.0",
|
||||
"@types/qs": "^6.9.6",
|
||||
"better-sqlite3": "^11.0.0",
|
||||
"cookie": "^0.6.0",
|
||||
"express": "^4.17.1",
|
||||
|
||||
@@ -25,3 +25,4 @@ export * from './database';
|
||||
export * from './msw';
|
||||
export * from './filesystem';
|
||||
export * from './next';
|
||||
export { mockErrorHandler } from './util';
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';
|
||||
import { mockServices } from '../next';
|
||||
|
||||
/**
|
||||
* A mock for error handler middleware that can be used in router tests.
|
||||
* @public
|
||||
*/
|
||||
export function mockErrorHandler() {
|
||||
return MiddlewareFactory.create({
|
||||
config: mockServices.rootConfig(),
|
||||
logger: mockServices.rootLogger(),
|
||||
}).error();
|
||||
}
|
||||
@@ -14,4 +14,5 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { mockErrorHandler } from './errorHandler';
|
||||
export { isDockerDisabledForTests } from './isDockerDisabledForTests';
|
||||
|
||||
@@ -8,18 +8,15 @@ import express from 'express';
|
||||
import { IdentityApi } from '@backstage/plugin-auth-node';
|
||||
import { SignalsService } from '@backstage/plugin-signals-node';
|
||||
|
||||
// @public
|
||||
// @public @deprecated
|
||||
export function createRouter(options: RouterOptions): Promise<express.Router>;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface RouterOptions {
|
||||
// (undocumented)
|
||||
// @public @deprecated
|
||||
export type RouterOptions = {
|
||||
database: DatabaseService;
|
||||
// (undocumented)
|
||||
identity: IdentityApi;
|
||||
// (undocumented)
|
||||
signals?: SignalsService;
|
||||
}
|
||||
};
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
"test": "backstage-cli package test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
"@backstage/backend-defaults": "workspace:^",
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/config": "workspace:^",
|
||||
"@backstage/errors": "workspace:^",
|
||||
@@ -64,7 +64,6 @@
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"knex": "^3.0.0",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PluginDatabaseManager } from '@backstage/backend-common';
|
||||
import { resolvePackagePath } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
resolvePackagePath,
|
||||
DatabaseService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { NotFoundError } from '@backstage/errors';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { Knex } from 'knex';
|
||||
@@ -43,7 +45,7 @@ export type RawDbUserSettingsRow = {
|
||||
*/
|
||||
export class DatabaseUserSettingsStore implements UserSettingsStore {
|
||||
static async create(options: {
|
||||
database: PluginDatabaseManager;
|
||||
database: DatabaseService;
|
||||
}): Promise<DatabaseUserSettingsStore> {
|
||||
const { database } = options;
|
||||
const client = await database.getClient();
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
import { DatabaseService } from '@backstage/backend-plugin-api';
|
||||
import { SignalsService } from '@backstage/plugin-signals-node';
|
||||
|
||||
import { createRouter as internalCreateRouter } from './service';
|
||||
import { IdentityApi } from '@backstage/plugin-auth-node';
|
||||
|
||||
/**
|
||||
* Type for the options passed to the "createRouter" function.
|
||||
*
|
||||
* @public
|
||||
* @deprecated This type is only exported for legacy reasons and will be removed in the future.
|
||||
*/
|
||||
export type RouterOptions = {
|
||||
database: DatabaseService;
|
||||
identity: IdentityApi;
|
||||
signals?: SignalsService;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the user settings backend routes.
|
||||
*
|
||||
* @public
|
||||
* @deprecated This function is only exported for legacy reasons and will be removed in the future.
|
||||
* Please {@link https://backstage.io/docs/backend-system/building-backends/migrating | migrate } to use the new backend system and follow these {@link https://github.com/backstage/backstage/tree/master/plugins/user-settings-backend#new-backend | instructions } to install the user settings backend plugin.
|
||||
*/
|
||||
export async function createRouter(
|
||||
options: RouterOptions,
|
||||
): Promise<express.Router> {
|
||||
return await internalCreateRouter(options);
|
||||
}
|
||||
@@ -14,5 +14,5 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './service';
|
||||
export * from './deprecated';
|
||||
export * from './database';
|
||||
|
||||
@@ -19,7 +19,11 @@ import request from 'supertest';
|
||||
import { UserSettingsStore } from '../database/UserSettingsStore';
|
||||
import { createRouterInternal } from './router';
|
||||
import { SignalsService } from '@backstage/plugin-signals-node';
|
||||
import { mockCredentials, mockServices } from '@backstage/backend-test-utils';
|
||||
import {
|
||||
mockCredentials,
|
||||
mockServices,
|
||||
mockErrorHandler,
|
||||
} from '@backstage/backend-test-utils';
|
||||
|
||||
describe('createRouter', () => {
|
||||
const userSettingsStore: jest.Mocked<UserSettingsStore> = {
|
||||
@@ -40,7 +44,7 @@ describe('createRouter', () => {
|
||||
signals: signalService as SignalsService,
|
||||
});
|
||||
|
||||
app = express().use(router);
|
||||
app = express().use(router).use(mockErrorHandler());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { errorHandler } from '@backstage/backend-common';
|
||||
import { AuthenticationError, InputError } from '@backstage/errors';
|
||||
import { IdentityApi } from '@backstage/plugin-auth-node';
|
||||
import express, { Request } from 'express';
|
||||
@@ -156,7 +155,5 @@ export async function createRouterInternal(
|
||||
res.status(204).end();
|
||||
});
|
||||
|
||||
router.use(errorHandler());
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -3821,7 +3821,10 @@ __metadata:
|
||||
"@backstage/types": "workspace:^"
|
||||
"@keyv/memcache": ^1.3.5
|
||||
"@keyv/redis": ^2.5.3
|
||||
"@types/express": ^4.17.6
|
||||
"@types/express-serve-static-core": ^4.17.5
|
||||
"@types/keyv": ^4.2.0
|
||||
"@types/qs": ^6.9.6
|
||||
"@types/supertest": ^2.0.8
|
||||
better-sqlite3: ^11.0.0
|
||||
cookie: ^0.6.0
|
||||
@@ -7766,7 +7769,6 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@backstage/plugin-user-settings-backend@workspace:plugins/user-settings-backend"
|
||||
dependencies:
|
||||
"@backstage/backend-common": "workspace:^"
|
||||
"@backstage/backend-defaults": "workspace:^"
|
||||
"@backstage/backend-plugin-api": "workspace:^"
|
||||
"@backstage/backend-test-utils": "workspace:^"
|
||||
@@ -7783,7 +7785,6 @@ __metadata:
|
||||
express-promise-router: ^4.1.0
|
||||
knex: ^3.0.0
|
||||
supertest: ^6.1.3
|
||||
winston: ^3.2.1
|
||||
yn: ^4.0.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -18484,10 +18485,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/qs@npm:*":
|
||||
version: 6.9.6
|
||||
resolution: "@types/qs@npm:6.9.6"
|
||||
checksum: 01871b1cf7062717ec76fcb9b29ddae1e04fcfadc1c76d86ec2571e72f27bf09ff31b094b295be8d4ca664aeec9b8965563680b31fcab7aba1ed93afac5181cd
|
||||
"@types/qs@npm:*, @types/qs@npm:^6.9.6":
|
||||
version: 6.9.15
|
||||
resolution: "@types/qs@npm:6.9.15"
|
||||
checksum: 97d8208c2b82013b618e7a9fc14df6bd40a73e1385ac479b6896bafc7949a46201c15f42afd06e86a05e914f146f495f606b6fb65610cc60cf2e0ff743ec38a2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user