import { type TemplateDependencyReport } from "../audit/template-dependencies.js"; import { type HygieneCommonOptions } from "../shared.js"; export interface CleanupDeadTemplatesOptions extends HygieneCommonOptions { /** Template-tree root. Default `/sitecore/templates/Project`. */ root?: string; /** Cap on templates inspected. Default 5000. */ limit?: number; /** Concurrency. Default 4. */ concurrency?: number; /** Override the search index. */ index?: string; /** * Whether to recursively delete now-empty template folders after * removing dead templates. Default true. Setting false leaves the * folder structure intact even when every template inside was dead. */ cleanupEmptyFolders?: boolean; whatIf?: boolean; allowWrite?: boolean; /** * Permit operating against `/sitecore/templates/System` and other * platform template subtrees. Off by default — deleting a system * template breaks editor UIs even if it shows zero items. */ force?: boolean; } export interface DeadTemplatePurgeAction { templateId: string; name: string; fullName: string | null; status: "purged" | "what-if" | "failed" | "blocked"; error?: string; /** * Inbound structural references that blocked the delete: base-template * inheritors, insert-options hosts, branch sources, datasource * templates. Populated when status is "blocked". The cleanup ran * `audit template-dependencies` as a pre-flight; the operator can * resolve each blocker before re-running cleanup, or pass --force to * attempt delete anyway (the Authoring API may still reject). */ blockers?: TemplateDependencyReport[]; } export interface FolderCleanupAction { path: string; itemId: string; status: "deleted" | "what-if" | "failed" | "skipped"; error?: string; } /** * Delete templates that have zero items deriving from them, then * optionally clean up empty template folders left behind. * * Strategy: * 1. Run `audit dead-templates` to identify candidates. * 2. For each dead template, call `deleteItemTemplate(templateId)`. * 3. If `--cleanup-empty-folders` (default true), walk the template * tree bottom-up and delete folders that ended up empty. * * Safety rails: * - `--root` defaults to `/sitecore/templates/Project` (project-owned). * - Refuses to operate on `/sitecore/templates/System` without * `--force`. Deleting system templates breaks editor UIs even when * they show zero items in the search index. * - `--allow-write` / `allowWrite` enforced outside `--what-if`. * - Cascades not handled: the underlying mutation fails (returns * `successful: false`) if a template is still used as a base * template by another, even when no items derive from it. Those * failures surface as per-record errors with the operator's * suggested next step in the message. */ export declare const runCleanupDeadTemplates: (options: CleanupDeadTemplatesOptions) => Promise<{ templates: DeadTemplatePurgeAction[]; folders: FolderCleanupAction[]; }>;