UNPKG

@backstage/backend-plugin-api

Version:

Core API used by Backstage backend plugins

118 lines (112 loc) 3.39 kB
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'; /** @alpha */ type BackendFeatureMeta = { type: 'plugin'; pluginId: string; } | { type: 'module'; pluginId: string; moduleId: string; }; /** @alpha */ interface InstanceMetadataService { getInstalledFeatures: () => BackendFeatureMeta[]; } /** * @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; }>; } /** * @alpha */ declare const instanceMetadataServiceRef: _backstage_backend_plugin_api.ServiceRef<InstanceMetadataService, "plugin", "singleton">; /** * 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">; export { type ActionsRegistryActionContext, type ActionsRegistryActionOptions, type ActionsRegistryService, type ActionsService, type ActionsServiceAction, type BackendFeatureMeta, type InstanceMetadataService, actionsRegistryServiceRef, actionsServiceRef, instanceMetadataServiceRef };