import { type HygieneCommonOptions } from "../shared.js"; export interface CleanupFindReplaceOptions extends HygieneCommonOptions { /** Required. Pattern to find. */ pattern: string; /** Required. Replacement string. Supports regex backreferences (`$1`, `$&`). */ replacement: string; literal?: boolean; ignoreCase?: boolean; flags?: string; /** Field-name filter. */ fields?: string[]; includeSystemFields?: boolean; /** Content root. Default `/sitecore/content`. */ root?: string; index?: string; limit?: number; includeSystem?: boolean; language?: string; batchSize?: number; concurrency?: number; pageParallelism?: number; cache?: boolean; whatIf?: boolean; allowWrite?: boolean; /** * Maximum number of items to mutate per run. Default 100 — defends * against runaway pattern matches. Set higher when you've validated * the audit output and want to apply at scale. */ maxMutations?: number; } export interface FindReplaceAction { itemId: string; path: string; templateName: string | null; language: string | null; fieldsChanged: Array<{ fieldName: string; matchCount: number; /** Up to 3 before/after pairs for the report. */ samples: Array<{ before: string; after: string; }>; }>; status: "applied" | "what-if" | "failed" | "skipped-cap"; error?: string; } /** * Apply a find-replace operation across content fields. * * Strategy: * 1. Use `scanItemsAndFields` to crawl items and load fields. * 2. Compile the pattern once; for each field, run `.replace` to * compute the new value and count matches. * 3. Apply via `updateItemFields(itemId, [{name, value}])` per item. * 4. Stop when `--max-mutations` items have been touched. * * Safety rails: * - `--what-if` reports the planned changes without calling the API. * - `--allow-write` (or env `allowWrite`) required outside `--what-if`. * - `--max-mutations` caps the change blast-radius. Default 100. * - `__`-prefixed system fields are excluded by default. Operators * who want to touch them must pass `--include-system-fields` AND * know what they're doing — replacing a `__Renderings` value via * regex will mangle the XML. * * Notes: * - The `replacement` string supports JS RegExp backreferences * (`$1`, `$&`, `$`), same as `String.replace()`. Operators * who want literal `$` use `$$$$`. * - Each item is mutated in a single `updateItem` call regardless * of how many fields change on it. Per-language updates aren't * supported in this round — the Authoring API treats the update * as latest-version on the item's primary language. */ export declare const runCleanupFindReplace: (options: CleanupFindReplaceOptions) => Promise;