From 2f9e2d243715210bd1cad93ea951ea49beb9930d Mon Sep 17 00:00:00 2001 From: yyaskriloff <69407772+yyaskriloff@users.noreply.github.com> Date: Sun, 22 Sep 2024 16:09:55 +0300 Subject: [PATCH 1/3] feat(wip): add identity notification --- platform/src/components/aws/email.ts | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/platform/src/components/aws/email.ts b/platform/src/components/aws/email.ts index ff0a4f571..e03d3f686 100644 --- a/platform/src/components/aws/email.ts +++ b/platform/src/components/aws/email.ts @@ -9,6 +9,7 @@ import { Component, Transform, transform } from "../component"; import { Link } from "../link"; import { Input } from "../input"; import { Dns } from "../dns"; +import { SnsTopic } from "./sns-topic"; import { dns as awsDns } from "./dns.js"; import { ses, sesv2 } from "@pulumi/aws"; import { permission } from "./permission"; @@ -105,6 +106,27 @@ export interface EmailArgs { * ``` */ dmarc?: Input; + + /** + * The SNS topics to publish bounce, complaint, and delivery notifications to. + * + * @example + * + * ```js + * { + * publishers: { + * Bounce: topic, + * Complaint: topic, + * Delivery: topic, + * } + * } + * ``` + */ + + publishers?: Partial< + Record<"Bounce" | "Complaint" | "Delivery", Input> + >; + /** * [Transform](/docs/components#transform) how this component creates its underlying * resources. @@ -227,6 +249,8 @@ export class Email extends Component implements Link.Linkable { waitForVerification(); }); + createIdentityPublishers(); + this._sender = output(args.sender); this.identity = identity; @@ -303,6 +327,27 @@ export class Email extends Component implements Link.Linkable { }); } + function createIdentityPublishers() { + all([args.publishers, identity]).apply(([topic, identity]) => { + if (!topic) return; + + const types = Array.from(Object.keys(topic)) as Array< + "Bounce" | "Complaint" | "Delivery" + >; + + if (types.length === 0) return; + // i used map because i saw it above but shouldn't you use forEach? + types.map( + (event) => + new ses.IdentityNotificationTopic(`${event}-Notification`, { + identity: identity.arn, + notificationType: event, + topicArn: topic[event]?.arn, + }), + ); + }); + } + function waitForVerification() { new ses.DomainIdentityVerification( `${name}Verification`, From 33282e747114d983d91f617288de876df9c7a9dc Mon Sep 17 00:00:00 2001 From: yyaskriloff <69407772+yyaskriloff@users.noreply.github.com> Date: Sun, 22 Sep 2024 16:10:21 +0300 Subject: [PATCH 2/3] add example --- examples/aws-email/sst.config.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/aws-email/sst.config.ts b/examples/aws-email/sst.config.ts index bd9602537..ef4d0bc16 100644 --- a/examples/aws-email/sst.config.ts +++ b/examples/aws-email/sst.config.ts @@ -9,8 +9,13 @@ export default $config({ }; }, async run() { + const topic = new sst.aws.SnsTopic("MyTopic"); + const email = new sst.aws.Email("MyEmail", { sender: "email@example.com", + publishers: { + Bounce: topic, + }, }); const api = new sst.aws.Function("MyApi", { From 9dc03b6fe61525270befefae618fe8d2800aff20 Mon Sep 17 00:00:00 2001 From: yyaskriloff <69407772+yyaskriloff@users.noreply.github.com> Date: Sun, 22 Sep 2024 16:34:08 +0300 Subject: [PATCH 3/3] add link --- platform/src/components/aws/email.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/src/components/aws/email.ts b/platform/src/components/aws/email.ts index e03d3f686..7780ee771 100644 --- a/platform/src/components/aws/email.ts +++ b/platform/src/components/aws/email.ts @@ -108,7 +108,7 @@ export interface EmailArgs { dmarc?: Input; /** - * The SNS topics to publish bounce, complaint, and delivery notifications to. + * The SNS topics to publish bounce, complaint, and delivery notifications to. To see how to properly proccess bounces and complaints please read [Setting up event notifications for Amazon SES]{@link https://docs.aws.amazon.com/ses/latest/dg/monitor-sending-activity-using-notifications.html} * * @example *