@@ -31,6 +31,7 @@ function entityUrl(context: BadgeContext): string {
|
||||
return `${catalogUrl}/${entityUri}`.toLowerCase();
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export const createDefaultBadgeFactories = (): BadgeFactories => ({
|
||||
pingback: {
|
||||
createBadge: (context: BadgeContext): Badge => {
|
||||
|
||||
@@ -19,6 +19,7 @@ import { makeBadge, Format } from 'badge-maker';
|
||||
import { BadgeBuilder, BadgeInfo, BadgeOptions, BadgeSpec } from './types';
|
||||
import { Badge, BadgeFactories } from '../../types';
|
||||
|
||||
/** @public */
|
||||
export class DefaultBadgeBuilder implements BadgeBuilder {
|
||||
constructor(private readonly factories: BadgeFactories) {}
|
||||
|
||||
|
||||
@@ -16,15 +16,18 @@
|
||||
|
||||
import { Badge, BadgeContext } from '../../types';
|
||||
|
||||
/** @public */
|
||||
export type BadgeInfo = {
|
||||
id: string;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type BadgeOptions = {
|
||||
badgeInfo: BadgeInfo;
|
||||
context: BadgeContext;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type BadgeSpec = {
|
||||
/** Badge id */
|
||||
id: string;
|
||||
@@ -39,6 +42,7 @@ export type BadgeSpec = {
|
||||
markdown: string;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type BadgeBuilder = {
|
||||
getBadges(): Promise<BadgeInfo[]>;
|
||||
createBadgeJson(options: BadgeOptions): Promise<BadgeSpec>;
|
||||
|
||||
@@ -26,6 +26,7 @@ import { NotFoundError } from '@backstage/errors';
|
||||
import { BadgeBuilder, DefaultBadgeBuilder } from '../lib/BadgeBuilder';
|
||||
import { BadgeContext, BadgeFactories } from '../types';
|
||||
|
||||
/** @public */
|
||||
export interface RouterOptions {
|
||||
badgeBuilder?: BadgeBuilder;
|
||||
badgeFactories?: BadgeFactories;
|
||||
@@ -34,6 +35,7 @@ export interface RouterOptions {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export async function createRouter(
|
||||
options: RouterOptions,
|
||||
): Promise<express.Router> {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import { Config } from '@backstage/config';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
|
||||
/** @public */
|
||||
export const BADGE_STYLES = [
|
||||
'plastic',
|
||||
'flat',
|
||||
@@ -24,8 +25,11 @@ export const BADGE_STYLES = [
|
||||
'for-the-badge',
|
||||
'social',
|
||||
] as const;
|
||||
|
||||
/** @public */
|
||||
export type BadgeStyle = typeof BADGE_STYLES[number];
|
||||
|
||||
/** @public */
|
||||
export interface Badge {
|
||||
/** Badge message background color. */
|
||||
color?: string;
|
||||
@@ -48,16 +52,19 @@ export interface Badge {
|
||||
style?: BadgeStyle;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface BadgeContext {
|
||||
badgeUrl: string;
|
||||
config: Config;
|
||||
entity?: Entity; // for entity badges
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface BadgeFactory {
|
||||
createBadge(context: BadgeContext): Badge;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface BadgeFactories {
|
||||
[id: string]: BadgeFactory;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user