import { type IConstruct } from "constructs"; import { type AlarmName } from "../alarm-name.js"; import { type AlarmMatchContext, type AlarmRuleScope } from "./policy-matcher.js"; /** Context passed to {@link AlarmNameRule.transform}. */ export interface AlarmNameTransformContext extends AlarmMatchContext { /** * The alarm name as it stands at the moment this rule's transform runs: * the original alarm name plus any prefix/suffix decorations contributed * by `defaults` and earlier matched rules. */ readonly currentName: string; } /** * A rule for {@link alarmNamePolicy}. A rule matches when **any** supplied * matcher matches. * * - `prefix` / `suffix` decorate the current name. * - `transform` produces a new name from scratch and wins over `prefix`/`suffix` * when both are set on the same rule. * - Multiple matched rules layer in declaration order. */ export interface AlarmNameRule extends AlarmRuleScope { /** Prepended to the current name with the configured separator. */ prefix?: string; /** Appended to the current name with the configured separator. */ suffix?: string; /** Full transform — wins over `prefix`/`suffix` on the same rule. */ transform?: (ctx: AlarmNameTransformContext) => AlarmName; /** When `true`, this rule's `prefix`/`suffix` replace `defaults` rather than layering on top. */ replaceDefaults?: boolean; } /** Configuration for {@link alarmNamePolicy}. */ export interface AlarmNamePolicyConfig { /** Decorations applied to every alarm unless a matching rule sets `replaceDefaults: true`. */ defaults?: Pick; /** Ordered list of rules. All matching rules contribute. */ rules?: AlarmNameRule[]; /** * Separator between prefix / current-name / suffix segments. * @default "-" */ separator?: string; } /** * Decorates CloudWatch alarm names across an entire scope. * * Installs a CDK * {@link https://docs.aws.amazon.com/cdk/v2/guide/aspects.html | Aspect} * that fires during the synth prepare phase. For every `AWS::CloudWatch::Alarm` * (and `AWS::CloudWatch::CompositeAlarm`) found beneath `scope`: * * 1. The alarm's existing name is read (set by the library default or the * consumer's per-alarm override). * 2. `defaults.prefix` / `defaults.suffix` decorate it, unless a matched * rule sets `replaceDefaults: true`. * 3. Each matching rule contributes in declaration order — `transform` * replaces the current name; otherwise `prefix`/`suffix` decorate. * 4. The final value is validated via {@link alarmName} and written back to * `cfn.alarmName`. * * Use cases: stage prefixing (`prod-…`), severity tagging (`…-critical`), * team scoping. Composes with per-alarm `alarmName` overrides — those run * first, the policy decorates the result. * * @example * ```ts * alarmNamePolicy(app, { * defaults: { prefix: "prod" }, * rules: [ * { match: /Errors$/, suffix: "critical" }, * { match: "throttles", suffix: "warning" }, * ], * }); * ``` */ export declare function alarmNamePolicy(scope: IConstruct, config: AlarmNamePolicyConfig): void; //# sourceMappingURL=alarm-name-policy.d.ts.map