/** * Well-known scope action defaults. * * SDK provides default metadata for standard action slugs. * Plugins override or extend by declaring their own metadata in the schema. */ export interface ActionDefaults { name: string; type: string; retryable: boolean; lifecycle: boolean; /** The parameters the platform sends the action, as every scope type declares them (the scope, the deployment, the traffic). */ parameters?: { schema: Record }; } const str = { type: "string" } as const; /** `parameters.schema` naming the platform-owned keys an action receives; every scope template declares the same. */ const params = (...keys: Array<"scope_id" | "deployment_id" | "desired_traffic" | "instance_id" | "desired_instances">) => ({ schema: { type: "object", required: [...keys], properties: Object.fromEntries( keys.map((k) => [k, k === "desired_traffic" || k === "desired_instances" ? { type: "number" } : str]) ), }, }); const SCOPE = params("scope_id"); const DEPLOYMENT = params("scope_id", "deployment_id"); export const WELL_KNOWN_ACTIONS: Record = { "create-scope": { name: "Create Scope", type: "create", retryable: true, lifecycle: true, parameters: SCOPE, }, "delete-scope": { name: "Delete Scope", type: "custom", retryable: true, lifecycle: true, parameters: SCOPE, }, "update-scope": { name: "Update Scope", type: "custom", retryable: true, lifecycle: true, parameters: SCOPE, }, "start-initial": { name: "Start Initial Deployment", type: "custom", retryable: true, lifecycle: true, parameters: DEPLOYMENT, }, "start-blue-green": { name: "Start Blue-Green Deployment", type: "custom", retryable: true, lifecycle: true, parameters: DEPLOYMENT, }, "switch-traffic": { name: "Switch Traffic", type: "custom", retryable: false, lifecycle: true, parameters: params("scope_id", "deployment_id", "desired_traffic"), }, "finalize-deployment": { name: "Finalize Deployment", type: "custom", retryable: false, lifecycle: true, parameters: DEPLOYMENT, }, "finalize-blue-green": { name: "Finalize Blue-Green", type: "custom", retryable: false, lifecycle: true, parameters: DEPLOYMENT, }, "rollback-deployment": { name: "Rollback Deployment", type: "custom", retryable: true, lifecycle: true, parameters: DEPLOYMENT, }, "delete-deployment": { name: "Delete Deployment", type: "custom", retryable: true, lifecycle: true, parameters: DEPLOYMENT, }, "diagnose-scope": { name: "Diagnose Scope", type: "diagnose", retryable: false, lifecycle: true, parameters: SCOPE, }, "diagnose-deployment": { name: "Diagnose Deployment", type: "diagnose", retryable: false, lifecycle: true, parameters: DEPLOYMENT, }, "kill-instances": { name: "Kill Instances", type: "custom", retryable: false, lifecycle: true, parameters: params("scope_id", "instance_id", "deployment_id"), }, "set-desired-instance-count": { name: "Set Instance Count", type: "custom", retryable: false, lifecycle: true, parameters: params("desired_instances"), }, "pause-autoscaling": { name: "Pause Autoscaling", type: "custom", retryable: false, lifecycle: true, }, "resume-autoscaling": { name: "Resume Autoscaling", type: "custom", retryable: false, lifecycle: true, }, "restart-pods": { name: "Restart Pods", type: "custom", retryable: false, lifecycle: true, }, }; /** Actions that skip lifecycle management (no PATCH status). */ const EPHEMERAL_PREFIXES = ["log:", "metric:", "parameter:", "instance:"]; export function getActionDefaults(slug: string): ActionDefaults { if (WELL_KNOWN_ACTIONS[slug]) { return WELL_KNOWN_ACTIONS[slug]; } const isEphemeral = EPHEMERAL_PREFIXES.some((p) => slug.startsWith(p)); return { name: slug, type: "custom", retryable: false, lifecycle: !isEphemeral, }; }