import type { CmsContext as BaseContext, CmsEntryListParams, CmsEntryMeta, CmsModel } from "@webiny/api-headless-cms/types/index.js"; import type { IResponseError } from "../api/response/abstractions/index.js"; import type { GenericRecord } from "@webiny/api/types.js"; import type { IStepFunctionServiceFetchResult } from "../api/service/StepFunctionServicePlugin.js"; import type { SecurityPermission } from "@webiny/api-core/types/security.js"; import type { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js"; import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js"; import { BaseError, Result } from "@webiny/feature/api"; import type { IdInterfaceGenerator, NumericInterfaceGenerator } from "@webiny/api"; import "./features/TaskController/augmentation.js"; export * from "./handler/types.js"; export * from "./response/abstractions/index.js"; export * from "./runner/abstractions/index.js"; export type ITaskDataInput = GenericRecord; export declare enum TaskLogItemType { INFO = "info", ERROR = "error" } export interface ITaskLogItemData { [key: string]: any; } export interface ITaskLogItemBase { message: string; createdOn: string; type: TaskLogItemType; data?: ITaskLogItemData; } export interface ITaskLogItemInfo extends ITaskLogItemBase { type: TaskLogItemType.INFO; } export interface ITaskLogItemError extends ITaskLogItemBase { type: TaskLogItemType.ERROR; error?: IResponseError; } export type ITaskLogItem = ITaskLogItemInfo | ITaskLogItemError; export interface ITaskLog { /** * ID without the revision number (for example: #0001). */ id: string; createdOn: string; createdBy: ITaskIdentity; executionName: string; task: string; iteration: number; items: ITaskLogItem[]; } export declare enum TaskDataStatus { PENDING = "pending", RUNNING = "running", FAILED = "failed", SUCCESS = "success", ABORTED = "aborted" } export interface ITaskIdentity { id: string; displayName: string; type: string; } export type IGetTaskResponse = ITask | null; export interface IListTasksResponse { items: ITask[]; meta: CmsEntryMeta; } export interface IListTaskLogsResponse { items: ITaskLog[]; meta: CmsEntryMeta; } export type ICreateTaskResponse = ITask; export type IUpdateTaskResponse = ITask; export type IDeleteTaskResponse = boolean; export interface IListTaskParamsWhere extends IdInterfaceGenerator<"id">, IdInterfaceGenerator<"parentId">, IdInterfaceGenerator<"definitionId">, IdInterfaceGenerator<"taskStatus"> { } export interface IListTaskParams extends Omit { where?: IListTaskParamsWhere; } export interface IListTaskLogParamsWhere extends IdInterfaceGenerator<"id">, IdInterfaceGenerator<"task">, NumericInterfaceGenerator<"iteration"> { } export interface IListTaskLogParams extends Omit { where?: IListTaskLogParamsWhere; } export interface ITaskCreateData { definitionId: string; name: string; input: T; parentId?: string; } export interface ITaskUpdateData { name?: string; input?: I; output?: O; taskStatus?: TaskDataStatus; executionName?: string; startedOn?: string; finishedOn?: string; eventResponse?: GenericRecord; iterations?: number; } export interface ITaskLogCreateInput { executionName: string; iteration: number; } export interface ITaskLogUpdateInput { items?: ITaskLogItem[]; } export interface ITasksContextCrudObject { /** * Models */ getTaskModel(): Promise; getLogModel(): Promise; /** * Tasks */ getTask(id: string): Promise | null>; listTasks(params?: IListTaskParams): Promise>; createTask(task: ITaskCreateData): Promise>; updateTask(id: string, data: Partial>): Promise>; deleteTask(id: string): Promise; /** * Recursively delete a task, its logs (if any were written), and its entire * descendant subtree. Best-effort: per-record failures are logged and swallowed, * the method never throws. */ cleanupTaskSubtree(id: string): Promise; /** * Logs */ createLog(task: Pick, data: ITaskLogCreateInput): Promise; updateLog(id: string, data: ITaskLogUpdateInput): Promise; deleteLog(id: string): Promise; getLog(id: string): Promise; getLatestLog(taskId: string): Promise; listLogs(params: IListTaskLogParams): Promise; } export interface ITasksContextDefinitionObject { getDefinition: (id: string) => TaskDefinition.Runnable | null; listDefinitions: () => TaskDefinition.Interface[]; } export interface ITaskTriggerParams { parent?: Pick; definition: string; name?: string; input?: I; delay?: number; } export interface ITaskAbortParams { id: string; message?: string; } export interface ITasksContextServiceObject { trigger: (params: ITaskTriggerParams) => Promise, BaseError>>; abort: (params: ITaskAbortParams) => Promise, BaseError>>; fetchServiceInfo: (input: ITask | string) => Promise>; } export interface ITasksContextObject extends ITasksContextCrudObject, ITasksContextDefinitionObject, ITasksContextServiceObject { } export interface Context extends BaseContext { tasks: ITasksContextObject; } export interface TaskPermission extends SecurityPermission { name: "task"; rwd?: string; } export type ITask = TaskService.Task; export type SelfCleanup = TaskDefinition.SelfCleanup; export type SelfCleanupEvent = TaskDefinition.SelfCleanupEvent;