import type { IResolvable, IResolveContext } from '../../core'; import type { IRuleRef } from '../../interfaces/generated/aws-events-interfaces.generated'; /** * The input to send to the event target * * This class abstracts over the three different ways CloudFormation lets you shape * a target's input, so you do not have to choose between them yourself: * * * `Input` - a literal value, emitted when the input does not reference the event. * * `InputPath` - a single JSONPath into the event, emitted by `fromEventPath()`. * * `InputTransformer` - an `InputPathsMap` plus an `InputTemplate`, emitted * automatically when the input references parts of the event via `EventField`. * * You pick a factory method based on the *shape* you want the target to receive, and * whether you reference `EventField` determines which of the above is synthesized. * For example, `fromObject({ foo: 'bar' })` produces a literal `Input`, while * `fromObject({ id: EventField.fromPath('$.detail.instance-id') })` produces an * `InputTransformer` with the path lifted into `InputPathsMap`. */ export declare abstract class RuleTargetInput { /** * Pass text to the event target * * May contain strings returned by `EventField.from()` to substitute in parts of the * matched event. * * The Rule Target input value will be a single string: the string you pass * here. Do not use this method to pass a complex value like a JSON object to * a Rule Target. Use `RuleTargetInput.fromObject()` instead. * * The target `Input` field must be valid JSON, so the text is JSON-encoded * when the template is synthesized. As a result a plain string is wrapped in * double quotes: `fromText('something')` renders as `Input: '"something"'`. * The quotes are part of the required JSON encoding, not an extra value added * by CDK, and cannot be removed. * * Whether those quotes are visible to the recipient depends on the target * service. Some targets deliver the JSON-encoded value as-is, so the recipient * sees the surrounding quotes (for example, an SNS topic delivering to an * email subscriber shows `"something"`). To send a structured payload, use * `RuleTargetInput.fromObject()` instead. */ static fromText(text: string): RuleTargetInput; /** * Pass text to the event target, splitting on newlines. * * This is only useful when passing to a target that does not * take a single argument. * * May contain strings returned by `EventField.from()` to substitute in parts * of the matched event. * * As with `fromText`, each line is JSON-encoded, so every line is wrapped in * double quotes in the synthesized template. Whether those quotes are visible * to the recipient depends on the target service. */ static fromMultilineText(text: string): RuleTargetInput; /** * Pass a JSON object to the event target * * May contain strings returned by `EventField.from()` to substitute in parts of the * matched event. * * @example * * declare const rule: events.Rule; * declare const topic: sns.Topic; * * // Without EventField this is a literal `Input`: * // {"source":"my-app"} * rule.addTarget(new targets.SnsTopic(topic, { * message: events.RuleTargetInput.fromObject({ source: 'my-app' }), * })); * * // Referencing the event inserts those fields from each matched event. * rule.addTarget(new targets.SnsTopic(topic, { * message: events.RuleTargetInput.fromObject({ * instance: events.EventField.fromPath('$.detail.instance-id'), * state: events.EventField.fromPath('$.detail.state'), * }), * })); * * @returns RuleTargetInput */ static fromObject(obj: any): RuleTargetInput; /** * Take the event target input from a path in the event JSON * * This emits CloudFormation's `InputPath` directly, so the target receives only * the selected fragment of the event. Use this when you want to forward part of * the event unchanged; use `fromObject()` when you need to reshape it. */ static fromEventPath(path: string): RuleTargetInput; protected constructor(); /** * Return the input properties for this input object */ abstract bind(rule: IRuleRef): RuleTargetInputProperties; } /** * The input properties for an event target */ export interface RuleTargetInputProperties { /** * Literal input to the target service (must be valid JSON) * * @default - input for the event target. If the input contains a paths map * values wil be extracted from event and inserted into the `inputTemplate`. */ readonly input?: string; /** * JsonPath to take input from the input event * * @default - None. The entire matched event is passed as input */ readonly inputPath?: string; /** * Input template to insert paths map into * * @default - None. */ readonly inputTemplate?: string; /** * Paths map to extract values from event and insert into `inputTemplate` * * @default - No values extracted from event. */ readonly inputPathsMap?: { [key: string]: string; }; } /** * Input object that can contain field replacements * * Evaluation is done in the bind() method because token resolution * requires access to the construct tree. * * Multiple tokens that use the same path will use the same substitution * key. * * One weird exception: if we're in object context, we MUST skip the quotes * around the placeholder. I assume this is so once a trivial string replace is * done later on by EventBridge, numbers are still numbers. * * So in string context: * * "this is a string with a " * * But in object context: * * "{ \"this is the\": }" * * To achieve the latter, we postprocess the JSON string to remove the surrounding * quotes by using a string replace. * * @internal */ export declare class FieldAwareEventInput extends RuleTargetInput { private readonly input; private readonly inputType; constructor(input: any, inputType: InputType); bind(rule: IRuleRef): RuleTargetInputProperties; /** * Removing surrounding quotes from any object placeholders * when key is the lone value. * * Those have been put there by JSON.stringify(), but we need to * remove them. * * Do not remove quotes when the key is part of a larger string. * * Valid: { "data": "Some string with \"quotes\"" } // key will be string * Valid: { "data": } // Key could be number, bool, obj, or string */ private unquoteKeyPlaceholders; } /** * Represents a field in the event pattern * * Each `EventField` you reference from a `RuleTargetInput` becomes an entry in the * target's `InputPathsMap`, keyed by a readable hint derived from the path, and the * place you referenced it becomes a matching placeholder in the `InputTemplate`. * Referencing the same path more than once reuses a single entry. * * Because these are string tokens, they can be embedded in template literals and * composed with other strings. * * @example * * declare const rule: events.Rule; * declare const topic: sns.Topic; * * rule.addTarget(new targets.SnsTopic(topic, { * message: events.RuleTargetInput.fromObject({ * // Named shorthands for the standard top-level event envelope fields * account: events.EventField.account, * region: events.EventField.region, * // Any other field is reachable by JSONPath * bucket: events.EventField.fromPath('$.detail.bucket.name'), * // Tokens compose with ordinary strings * summary: `Event ${events.EventField.eventId} from ${events.EventField.source}`, * }), * })); */ export declare class EventField implements IResolvable { readonly path: string; /** * Extract the event ID from the event */ static get eventId(): string; /** * Extract the detail type from the event */ static get detailType(): string; /** * Extract the source from the event */ static get source(): string; /** * Extract the account from the event */ static get account(): string; /** * Extract the time from the event */ static get time(): string; /** * Extract the region from the event */ static get region(): string; /** * Extract a custom JSON path from the event */ static fromPath(path: string): string; /** * Human readable display hint about the event pattern */ readonly displayHint: string; readonly creationStack: string[]; /** * * @param path the path to a field in the event pattern */ private constructor(); resolve(_ctx: IResolveContext): any; toString(): string; /** * Convert the path to the field in the event pattern to JSON */ toJSON(): string; } /** * @internal */ export declare enum InputType { Object = 0, Text = 1, Multiline = 2 }