@backstage/backend-plugin-api
Version:
Core API used by Backstage backend plugins
115 lines (109 loc) • 3.44 kB
TypeScript
import { AnyZodObject, z } from 'zod';
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
import { LoggerService, BackstageCredentials } from '@backstage/backend-plugin-api';
import { JsonObject, JsonValue } from '@backstage/types';
import { JSONSchema7 } from 'json-schema';
/** @public */
interface RootSystemMetadataServicePluginInfo {
readonly pluginId: string;
}
/** @public */
interface RootSystemMetadataService {
getInstalledPlugins: () => Promise<ReadonlyArray<RootSystemMetadataServicePluginInfo>>;
}
/**
* @alpha
*/
type ActionsRegistryActionContext<TInputSchema extends AnyZodObject> = {
input: z.infer<TInputSchema>;
logger: LoggerService;
credentials: BackstageCredentials;
};
/**
* @alpha
*/
type ActionsRegistryActionOptions<TInputSchema extends AnyZodObject, TOutputSchema extends AnyZodObject> = {
name: string;
title: string;
description: string;
schema: {
input: (zod: typeof z) => TInputSchema;
output: (zod: typeof z) => TOutputSchema;
};
attributes?: {
destructive?: boolean;
idempotent?: boolean;
readOnly?: boolean;
};
action: (context: ActionsRegistryActionContext<TInputSchema>) => Promise<z.infer<TOutputSchema> extends void ? void : {
output: z.infer<TOutputSchema>;
}>;
};
/**
* @alpha
*/
interface ActionsRegistryService {
register<TInputSchema extends AnyZodObject, TOutputSchema extends AnyZodObject>(options: ActionsRegistryActionOptions<TInputSchema, TOutputSchema>): void;
}
/**
* @alpha
*/
type ActionsServiceAction = {
id: string;
name: string;
title: string;
description: string;
schema: {
input: JSONSchema7;
output: JSONSchema7;
};
attributes: {
readOnly: boolean;
destructive: boolean;
idempotent: boolean;
};
};
/**
* @alpha
*/
interface ActionsService {
list: (opts: {
credentials: BackstageCredentials;
}) => Promise<{
actions: ActionsServiceAction[];
}>;
invoke(opts: {
id: string;
input?: JsonObject;
credentials: BackstageCredentials;
}): Promise<{
output: JsonValue;
}>;
}
/**
* Service for calling distributed actions
*
* See {@link ActionsService}
* and {@link https://backstage.io/docs/backend-system/core-services/actions | the service docs}
* for more information.
*
* @alpha
*/
declare const actionsServiceRef: _backstage_backend_plugin_api.ServiceRef<ActionsService, "plugin", "singleton">;
/**
* Service for registering and managing distributed actions.
*
* See {@link ActionsRegistryService}
* and {@link https://backstage.io/docs/backend-system/core-services/actions-registry | the service docs}
* for more information.
*
* @alpha
*/
declare const actionsRegistryServiceRef: _backstage_backend_plugin_api.ServiceRef<ActionsRegistryService, "plugin", "singleton">;
/**
* Read information about your current Backstage deployment.
* @alpha
*/
declare const rootSystemMetadataServiceRef: _backstage_backend_plugin_api.ServiceRef<RootSystemMetadataService, "root", "singleton">;
export { actionsRegistryServiceRef, actionsServiceRef, rootSystemMetadataServiceRef };
export type { ActionsRegistryActionContext, ActionsRegistryActionOptions, ActionsRegistryService, ActionsService, ActionsServiceAction, RootSystemMetadataService, RootSystemMetadataServicePluginInfo };