feat: some tweaks to the actions registry and implementing some of the actions client

Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
benjdlambert
2025-05-27 11:52:39 +02:00
parent 04592af953
commit 4e8f01357e
14 changed files with 348 additions and 76 deletions
@@ -23,25 +23,6 @@ export type ActionsRegistryActionContext<TInputSchema extends ZodType> = {
credentials: BackstageCredentials;
};
// todo: opaque type?
export type ActionsRegistryAction<
TInputSchema extends ZodType,
TOutputSchema extends ZodType,
> = {
id: string;
name: string;
title: string;
description: string;
// todo: what about additional metadata?
schema?: {
input?: TInputSchema;
output?: TOutputSchema;
};
action: (
context: ActionsRegistryActionContext<TInputSchema>,
) => Promise<TOutputSchema extends ZodType ? z.infer<TOutputSchema> : void>;
};
export type ActionsRegistryActionOptions<
TInputSchema extends ZodType,
TOutputSchema extends ZodType,
@@ -49,14 +30,15 @@ export type ActionsRegistryActionOptions<
name: string;
title: string;
description: string;
// todo: what about additional metadata?
schema?: {
input?: (zod: typeof z) => TInputSchema;
output?: (zod: typeof z) => TOutputSchema;
};
action: (
context: ActionsRegistryActionContext<TInputSchema>,
) => Promise<TOutputSchema extends ZodType ? z.infer<TOutputSchema> : void>;
) => Promise<
TOutputSchema extends ZodType ? { output: z.infer<TOutputSchema> } : void
>;
};
export interface ActionsRegistryService {
@@ -0,0 +1,36 @@
/*
* Copyright 2025 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 { JsonObject, JsonValue } from '@backstage/types';
import { JSONSchema7 } from 'json-schema';
export type ActionsServiceAction = {
id: string;
name: string;
title: string;
description: string;
schema?: {
input?: JSONSchema7;
output?: JSONSchema7;
};
};
export interface ActionsService {
listActions: () => Promise<{ actions: ActionsServiceAction[] }>;
invokeAction(opts: {
id: string;
input?: JsonObject;
}): Promise<{ output: JsonValue }>;
}
@@ -36,7 +36,22 @@ export namespace coreServices {
});
/**
* Service for registering and managing actions.
* 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.
*
* @public
*/
export const actions = createServiceRef<
import('./ActionsService').ActionsService
>({
id: 'core.actions',
});
/**
* 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}
@@ -18,8 +18,9 @@ export type {
ActionsRegistryService,
ActionsRegistryActionOptions,
ActionsRegistryActionContext,
ActionsRegistryAction,
} from './ActionsRegistryService';
export type { ActionsService, ActionsServiceAction } from './ActionsService';
export type {
AuditorService,
AuditorServiceCreateEventOptions,