Skip to content

Commit 58c2d47

Browse files
feat(marketplace): add more API endpoints in marketplace (#268)
* add more APIs in marketplace * move marketplace client to common package * generate api and knip reports * chore(marketplace): move tests, added some todos Signed-off-by: Christoph Jerolimov <[email protected]> --------- Signed-off-by: Christoph Jerolimov <[email protected]> Co-authored-by: Christoph Jerolimov <[email protected]>
1 parent 6a8d21e commit 58c2d47

37 files changed

+839
-334
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-catalog-backend-module-marketplace': patch
3+
'@red-hat-developer-hub/backstage-plugin-marketplace-backend': patch
4+
'@red-hat-developer-hub/backstage-plugin-marketplace-common': patch
5+
'@red-hat-developer-hub/backstage-plugin-marketplace': patch
6+
---
7+
8+
Add new endpoints in marketplace.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Knip report
22

3-
## Unused dependencies (11)
3+
## Unused dependencies (12)
44

5-
| Name | Location | Severity |
6-
| :---------------------------------------------------------- | :----------- | :------- |
7-
| @red-hat-developer-hub/backstage-plugin-marketplace-backend | package.json | error |
8-
| @backstage/plugin-auth-backend-module-github-provider | package.json | error |
9-
| @backstage/plugin-search-backend-node | package.json | error |
10-
| @backstage/plugin-permission-common | package.json | error |
11-
| @backstage/plugin-permission-node | package.json | error |
12-
| @backstage/plugin-auth-node | package.json | error |
13-
| @backstage/config | package.json | error |
14-
| better-sqlite3 | package.json | error |
15-
| node-gyp | package.json | error |
16-
| app | package.json | error |
17-
| pg | package.json | error |
5+
| Name | Location | Severity |
6+
| :------------------------------------------------------------------------- | :----------- | :------- |
7+
| @red-hat-developer-hub/backstage-plugin-catalog-backend-module-marketplace | package.json | error |
8+
| @red-hat-developer-hub/backstage-plugin-marketplace-backend | package.json | error |
9+
| @backstage/plugin-auth-backend-module-github-provider | package.json | error |
10+
| @backstage/plugin-search-backend-node | package.json | error |
11+
| @backstage/plugin-permission-common | package.json | error |
12+
| @backstage/plugin-permission-node | package.json | error |
13+
| @backstage/plugin-auth-node | package.json | error |
14+
| @backstage/config | package.json | error |
15+
| better-sqlite3 | package.json | error |
16+
| node-gyp | package.json | error |
17+
| app | package.json | error |
18+
| pg | package.json | error |
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
# Knip report
2+
3+
## Unused dependencies (1)
4+
5+
| Name | Location | Severity |
6+
| :--------------------------------------------------------- | :----------- | :------- |
7+
| @red-hat-developer-hub/backstage-plugin-marketplace-common | package.json | error |

workspaces/marketplace/plugins/catalog-backend-module-marketplace/report.api.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-node';
1212
import { DiscoveryService } from '@backstage/backend-plugin-api';
1313
import { Entity } from '@backstage/catalog-model';
1414
import { LocationSpec } from '@backstage/plugin-catalog-common';
15-
import { MarketplacePluginEntry } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
15+
import { MarketplacePlugin } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
1616

1717
// @public (undocumented)
1818
export type CachedData = {
@@ -35,7 +35,7 @@ export class DynamicPluginInstallStatusProcessor implements CatalogProcessor {
3535
// (undocumented)
3636
getProcessorName(): string;
3737
// (undocumented)
38-
preProcessEntity(entity: Entity, _location: LocationSpec, _emit: CatalogProcessorEmit, _originLocation: LocationSpec, cache: CatalogProcessorCache): Promise<MarketplacePluginEntry>;
38+
preProcessEntity(entity: Entity, _location: LocationSpec, _emit: CatalogProcessorEmit, _originLocation: LocationSpec, cache: CatalogProcessorCache): Promise<MarketplacePlugin>;
3939
}
4040

4141
// @public (undocumented)
@@ -48,7 +48,7 @@ export class LocalPluginInstallStatusProcessor implements CatalogProcessor {
4848
// (undocumented)
4949
isJSON(str: string): boolean;
5050
// (undocumented)
51-
preProcessEntity(entity: MarketplacePluginEntry): Promise<Entity>;
51+
preProcessEntity(entity: MarketplacePlugin): Promise<Entity>;
5252
}
5353

5454
// @public (undocumented)

workspaces/marketplace/plugins/catalog-backend-module-marketplace/src/module.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
createBackendModule,
2020
} from '@backstage/backend-plugin-api';
2121
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
22+
2223
import { MarketplacePluginProcessor } from './processors/MarketplacePluginProcessor';
2324
import { MarketplacePluginListProcessor } from './processors/MarketplacePluginListProcessor';
2425
import { DynamicPluginInstallStatusProcessor } from './processors/DynamicPluginInstallStatusProcessor';
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*/
1616

1717
import { mockServices } from '@backstage/backend-test-utils';
18-
import { DynamicPluginInstallStatusProcessor } from '../DynamicPluginInstallStatusProcessor';
18+
import { CatalogProcessorCache } from '@backstage/plugin-catalog-node';
1919
import {
2020
InstallStatus,
21-
MarketplacePluginEntry,
21+
MarketplacePlugin,
2222
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
23-
import { CatalogProcessorCache } from '@backstage/plugin-catalog-node';
2423

25-
const pluginEntity: MarketplacePluginEntry = {
24+
import { DynamicPluginInstallStatusProcessor } from './DynamicPluginInstallStatusProcessor';
25+
26+
const pluginEntity: MarketplacePlugin = {
2627
apiVersion: 'marketplace.backstage.io/v1alpha1',
2728
metadata: {
2829
name: 'testplugin',
@@ -217,7 +218,7 @@ describe('DynamicPluginInstallStatusProcessor', () => {
217218
});
218219

219220
it('should set installStatus to NotInstalled if the plugin is not found', async () => {
220-
const entity: MarketplacePluginEntry = {
221+
const entity: MarketplacePlugin = {
221222
apiVersion: 'marketplace.backstage.io/v1alpha1',
222223
kind: 'Plugin',
223224
metadata: { name: 'unknown-plugin' },
@@ -244,7 +245,7 @@ describe('DynamicPluginInstallStatusProcessor', () => {
244245
});
245246

246247
it('should return the entity unchanged for non-plugin entities', async () => {
247-
const entity: MarketplacePluginEntry = {
248+
const entity: MarketplacePlugin = {
248249
apiVersion: 'other-api/v1',
249250
kind: 'Component',
250251
metadata: { name: 'component1' },

workspaces/marketplace/plugins/catalog-backend-module-marketplace/src/processors/DynamicPluginInstallStatusProcessor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
InstallStatus,
2828
MARKETPLACE_API_VERSION,
2929
MarketplaceKinds,
30-
MarketplacePluginEntry,
30+
MarketplacePlugin,
3131
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
3232

3333
/**
@@ -115,7 +115,7 @@ export class DynamicPluginInstallStatusProcessor implements CatalogProcessor {
115115
_emit: CatalogProcessorEmit,
116116
_originLocation: LocationSpec,
117117
cache: CatalogProcessorCache,
118-
): Promise<MarketplacePluginEntry> {
118+
): Promise<MarketplacePlugin> {
119119
if (
120120
entity.apiVersion === MARKETPLACE_API_VERSION &&
121121
entity.kind === MarketplaceKinds.plugin
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
import {
1818
InstallStatus,
19-
MarketplacePluginEntry,
19+
MarketplacePlugin,
2020
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
21-
import { LocalPluginInstallStatusProcessor } from '../LocalPluginInstallStatusProcessor';
2221

23-
const pluginEntity: MarketplacePluginEntry = {
22+
import { LocalPluginInstallStatusProcessor } from './LocalPluginInstallStatusProcessor';
23+
24+
const pluginEntity: MarketplacePlugin = {
2425
apiVersion: 'marketplace.backstage.io/v1alpha1',
2526
metadata: {
2627
name: 'testplugin',

workspaces/marketplace/plugins/catalog-backend-module-marketplace/src/processors/LocalPluginInstallStatusProcessor.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
InstallStatus,
2424
MARKETPLACE_API_VERSION,
2525
MarketplaceKinds,
26-
MarketplacePluginEntry,
26+
MarketplacePlugin,
2727
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
2828

2929
/**
@@ -44,6 +44,7 @@ export class LocalPluginInstallStatusProcessor implements CatalogProcessor {
4444
cpath => `${this.workspacesPath}/${cpath}/package.json`,
4545
);
4646
}
47+
4748
getProcessorName(): string {
4849
return 'LocalPluginInstallStatusProcessor';
4950
}
@@ -137,7 +138,7 @@ export class LocalPluginInstallStatusProcessor implements CatalogProcessor {
137138
}
138139
}
139140

140-
async preProcessEntity(entity: MarketplacePluginEntry): Promise<Entity> {
141+
async preProcessEntity(entity: MarketplacePlugin): Promise<Entity> {
141142
if (
142143
entity.apiVersion === MARKETPLACE_API_VERSION &&
143144
entity.kind === MarketplaceKinds.plugin
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616

1717
import { MarketplacePluginList } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
18-
import { MarketplacePluginListProcessor } from '../MarketplacePluginListProcessor';
18+
19+
import { MarketplacePluginListProcessor } from './MarketplacePluginListProcessor';
1920

2021
const pluginListEntity: MarketplacePluginList = {
2122
apiVersion: 'marketplace.backstage.io/v1alpha1',
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { MarketplacePluginEntry } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
18-
import { MarketplacePluginProcessor } from '../MarketplacePluginProcessor';
17+
import { MarketplacePlugin } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
1918

20-
const pluginEntity: MarketplacePluginEntry = {
19+
import { MarketplacePluginProcessor } from './MarketplacePluginProcessor';
20+
21+
const pluginEntity: MarketplacePlugin = {
2122
apiVersion: 'marketplace.backstage.io/v1alpha1',
2223
metadata: {
2324
name: 'testplugin',

workspaces/marketplace/plugins/catalog-backend-module-marketplace/src/processors/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
export { MarketplacePluginProcessor } from './MarketplacePluginProcessor';
18-
export { MarketplacePluginListProcessor } from './MarketplacePluginListProcessor';
17+
export * from './MarketplacePluginProcessor';
18+
export * from './MarketplacePluginListProcessor';
1919
export * from './DynamicPluginInstallStatusProcessor';
20-
export { LocalPluginInstallStatusProcessor as LocalPluginInstallStatusProcessor } from './LocalPluginInstallStatusProcessor';
20+
export * from './LocalPluginInstallStatusProcessor';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { MarketplaceKinds } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
17+
18+
export const mockPlugins = [
19+
{
20+
apiVersion: 'marketplace.backstage.io/v1alpha1',
21+
kind: MarketplaceKinds.plugin,
22+
metadata: { name: 'plugin1' },
23+
},
24+
{
25+
apiVersion: 'marketplace.backstage.io/v1alpha1',
26+
kind: MarketplaceKinds.plugin,
27+
metadata: { name: 'plugin2' },
28+
},
29+
];
30+
31+
export const mockPluginList = [
32+
{
33+
apiVersion: 'marketplace.backstage.io/v1alpha1',
34+
kind: MarketplaceKinds.pluginList,
35+
metadata: { name: 'test-featured-plugins' },
36+
spec: {
37+
plugins: ['plugin1', 'plugin2'],
38+
},
39+
},
40+
];
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
11
# Knip report
2-
3-
## Unused dependencies (2)
4-
5-
| Name | Location | Severity |
6-
| :--------------------------------------------------------- | :----------- | :------- |
7-
| @red-hat-developer-hub/backstage-plugin-marketplace-common | package.json | error |
8-
| @backstage/catalog-client | package.json | error |

workspaces/marketplace/plugins/marketplace-backend/package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@
3737
"@backstage/backend-plugin-api": "^1.0.1",
3838
"@backstage/catalog-client": "^1.8.0",
3939
"@backstage/errors": "^1.2.4",
40+
"@backstage/plugin-catalog-node": "^1.13.1",
4041
"@red-hat-developer-hub/backstage-plugin-marketplace-common": "workspace:^",
4142
"express": "^4.17.1",
42-
"express-promise-router": "^4.1.0",
43-
"glob": "^10.4.5",
44-
"yaml": "^2.6.0",
45-
"zod": "^3.22.4"
43+
"express-promise-router": "^4.1.0"
4644
},
4745
"devDependencies": {
4846
"@backstage/backend-test-utils": "^1.0.2",
4947
"@backstage/cli": "^0.28.0",
5048
"@backstage/plugin-catalog-node": "^1.15.0",
5149
"@types/express": "*",
5250
"@types/supertest": "^2.0.12",
51+
"msw": "^1.0.0",
5352
"supertest": "^6.2.4"
5453
},
5554
"files": [

workspaces/marketplace/plugins/marketplace-backend/src/plugin.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ import {
1818
coreServices,
1919
createBackendPlugin,
2020
} from '@backstage/backend-plugin-api';
21-
import { createRouter } from './router';
22-
import { MarketplaceCatalogService } from './services/MarketplaceCatalogService';
2321
import { CatalogClient } from '@backstage/catalog-client';
22+
23+
import {
24+
MarketplaceApi,
25+
MarketplaceCatalogClient,
26+
} from '@red-hat-developer-hub/backstage-plugin-marketplace-common';
27+
28+
import { createRouter } from './router';
29+
2430
/**
2531
* marketplacePlugin backend plugin
2632
*
@@ -31,26 +37,22 @@ export const marketplacePlugin = createBackendPlugin({
3137
register(env) {
3238
env.registerInit({
3339
deps: {
34-
logger: coreServices.logger,
3540
auth: coreServices.auth,
36-
config: coreServices.rootConfig,
3741
httpAuth: coreServices.httpAuth,
3842
httpRouter: coreServices.httpRouter,
3943
discovery: coreServices.discovery,
4044
},
41-
async init({ logger, auth, config, httpAuth, httpRouter, discovery }) {
45+
async init({ auth, httpAuth, httpRouter, discovery }) {
4246
const catalogApi = new CatalogClient({ discoveryApi: discovery });
43-
const marketplaceService = new MarketplaceCatalogService({
44-
logger,
47+
const marketplaceApi: MarketplaceApi = new MarketplaceCatalogClient({
4548
auth,
46-
config,
4749
catalogApi,
4850
});
4951

5052
httpRouter.use(
5153
await createRouter({
5254
httpAuth,
53-
marketplaceService,
55+
marketplaceApi,
5456
}),
5557
);
5658
},

0 commit comments

Comments
 (0)