Skip to content

Commit

Permalink
feat(marketplace): initial version of a marketplace api
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Jerolimov <[email protected]>
  • Loading branch information
christoph-jerolimov committed Nov 18, 2024
1 parent e182a44 commit e1da485
Show file tree
Hide file tree
Showing 18 changed files with 576 additions and 476 deletions.
2 changes: 1 addition & 1 deletion workspaces/marketplace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"tsc:full": "tsc --skipLibCheck false --incremental false",
"build:all": "backstage-cli repo build --all",
"build:api-reports": "yarn build:api-reports:only --tsc",
"build:api-reports:only": "backstage-repo-tools api-reports -o ae-wrong-input-file-type --validate-release-tags",
"build:api-reports:only": "backstage-repo-tools api-reports -o ae-wrong-input-file-type,ae-undocumented --validate-release-tags",
"build-image": "yarn workspace backend build-image",
"clean": "backstage-cli repo clean",
"test": "backstage-cli repo test",
Expand Down
87 changes: 87 additions & 0 deletions workspaces/marketplace/plugins/marketplace-backend/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { InputError } from '@backstage/errors';
import { z } from 'zod';
import express from 'express';
import Router from 'express-promise-router';

import { MarketplacePluginEntry } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';

import { TodoListService } from './services/TodoListService/types';

export async function createRouter({
Expand All @@ -30,6 +33,90 @@ export async function createRouter({
const router = Router();
router.use(express.json());

router.get('/plugins', async (_req, res) => {
await new Promise(resolve => setTimeout(() => resolve(null), 1000));

const plugins: MarketplacePluginEntry[] = [
{
metadata: {
name: 'airbreak',
title: 'Airbreak',
developer: 'Spotify',
abstract:
'Access Airbreak error monitoring and other integrations from within...',

categories: ['Monitoring'],
},
spec: {
description:
'## Access Airbreak error monitoring and other integrations from within...',
},
},
{
metadata: {
name: 'airbreak2',
title: 'Airbreak2',
developer: 'Spotify',
abstract:
'Access Airbreak error monitoring and other integrations from within. Access Airbreak error monitoring and other integrations from within.',

categories: ['Monitoring'],
},
spec: {
description:
'## Access Airbreak error monitoring and other integrations from within...',
},
},
{
metadata: {
name: 'airbreak3',
title: 'Airbreak3',
developer: 'Spotify',
abstract:
'Access Airbreak error monitoring and other integrations from within...',

categories: ['Monitoring'],
},
spec: {
description:
'## Access Airbreak error monitoring and other integrations from within...',
},
},
{
metadata: {
name: 'airbreak4',
title: 'Airbreak4',
developer: 'Spotify',
abstract:
'Access Airbreak error monitoring and other integrations from within. Access Airbreak error monitoring and other integrations from within.',

categories: ['Monitoring'],
},
spec: {
description:
'## Access Airbreak error monitoring and other integrations from within...',
},
},
{
metadata: {
name: 'airbreak5',
title: 'Airbreak5',
developer: 'Spotify',
abstract:
'Access Airbreak error monitoring and other integrations from within...',

categories: ['Monitoring'],
},
spec: {
description:
'## Access Airbreak error monitoring and other integrations from within...',
},
},
];

res.json(plugins);
});

// TEMPLATE NOTE:
// Zod is a powerful library for data validation and recommended in particular
// for user-defined schemas. In this case we use it for input validation too.
Expand Down
61 changes: 55 additions & 6 deletions workspaces/marketplace/plugins/marketplace-common/report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,60 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
// @public
export const COMMON_CONSTANT = 1;
// @public (undocumented)
export interface MarketplacePluginEntry {
// (undocumented)
metadata: MarketplacePluginMetadata;
// (undocumented)
spec: MarketplacePluginSpec;
}

// @public
export type CommonType = {
field: string;
};
// @public (undocumented)
export interface MarketplacePluginLink {
// (undocumented)
icon?: string;
// (undocumented)
title?: string;
// (undocumented)
type?: string;
// (undocumented)
url: string;
}

// @public (undocumented)
export interface MarketplacePluginMetadata {
// (undocumented)
abstract?: string;
// (undocumented)
annotations?: Record<string, string>;
// (undocumented)
categories?: string[];
// (undocumented)
developer?: string;
// (undocumented)
icon?: string;
// (undocumented)
labels?: Record<string, string>;
// (undocumented)
links?: MarketplacePluginLink[];
// (undocumented)
name: string;
// (undocumented)
tags?: string[];
// (undocumented)
title: string;
}

// @public (undocumented)
export interface MarketplacePluginSpec {
// (undocumented)
description?: string;
// (undocumented)
highlights?: string[];
// (undocumented)
installation?: {
markdown?: string;
appconfig?: string;
};
}
```
17 changes: 1 addition & 16 deletions workspaces/marketplace/plugins/marketplace-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,4 @@
* @packageDocumentation
*/

/**
* In this package you might for example declare types that are common
* between the frontend and backend plugin packages.
*
* @public
*/
export type CommonType = {
field: string;
};

/**
* Or you might declare some common constants.
*
* @public
*/
export const COMMON_CONSTANT = 1;
export * from './types';
69 changes: 69 additions & 0 deletions workspaces/marketplace/plugins/marketplace-common/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.
*/

/**
* @public
*/
export interface MarketplacePluginEntry {
metadata: MarketplacePluginMetadata;
spec: MarketplacePluginSpec;
}

/**
* @public
*/
export interface MarketplacePluginMetadata {
// primary identifier
name: string;

// primary display name
title: string;

abstract?: string;

categories?: string[];
developer?: string;

// TODO: support for light/dark icon
icon?: string;

labels?: Record<string, string>;
annotations?: Record<string, string>;
tags?: string[];
links?: MarketplacePluginLink[];
}

/**
* @public
*/
export interface MarketplacePluginLink {
url: string;
title?: string;
icon?: string;
type?: string;
}

/**
* @public
*/
export interface MarketplacePluginSpec {
highlights?: string[];
description?: string;
installation?: {
markdown?: string;
appconfig?: string;
};
}
1 change: 1 addition & 0 deletions workspaces/marketplace/plugins/marketplace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@backstage/theme": "^0.6.0",
"@mui/material": "^5.12.2",
"@red-hat-developer-hub/backstage-plugin-marketplace-common": "workspace:^",
"@tanstack/react-query": "^5.60.5",
"react-use": "^17.2.4"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { ExampleFetchComponent } from './ExampleFetchComponent';
import { MarketplacePluginEntry } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';

/**
* @public
*/
export interface MarketplaceApi {
getPlugins(): Promise<MarketplacePluginEntry[]>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';

import { MarketplacePluginEntry } from '@red-hat-developer-hub/backstage-plugin-marketplace-common';

import { MarketplaceApi } from './MarketplaceApi';

export type Options = {
discoveryApi: DiscoveryApi;
fetchApi: FetchApi;
};

export class MarketplaceClient implements MarketplaceApi {
private readonly discoveryApi: DiscoveryApi;
private readonly fetchApi: FetchApi;

constructor(options: Options) {
this.discoveryApi = options.discoveryApi;
this.fetchApi = options.fetchApi;
}

async getPlugins(): Promise<MarketplacePluginEntry[]> {
const baseUrl = await this.discoveryApi.getBaseUrl('marketplace');
const url = `${baseUrl}/plugins`;

const response = await this.fetchApi.fetch(url);
if (!response.ok) {
throw new Error(
`Unexpected status code: ${response.status} ${response.statusText}`,
);
}

return response.json();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { ExampleComponent } from './ExampleComponent';
import { createApiRef } from '@backstage/core-plugin-api';

import { MarketplaceApi } from './MarketplaceApi';

export * from './MarketplaceClient';

export const MarketplaceApiRef = createApiRef<MarketplaceApi>({
id: 'plugin.marketplace.api-ref',
});

This file was deleted.

Loading

0 comments on commit e1da485

Please sign in to comment.