Skip to content

Commit 1e3e183

Browse files
committed
chore: [AB#17076] create configuration sets for each email type
1 parent c2b0869 commit 1e3e183

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

api/.dependency-cruiser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ module.exports = {
269269
from: { path: "src/domain" },
270270
to: { path: "src/api" },
271271
},
272+
{
273+
from: { path: "src/domain/types" },
274+
to: { path: "src/libs/constants" },
275+
},
272276
{
273277
from: { path: "src/domain" },
274278
to: { path: "src/client" },

api/cdk/lib/apiStack.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { API_SERVICE_NAME } from "@businessnjgovnavigator/api/src/libs/constants";
1+
import {
2+
API_SERVICE_NAME,
3+
REMINDER_EMAIL_CONFIG_SET_NAME,
4+
WELCOME_EMAIL_CONFIG_SET_NAME,
5+
} from "@businessnjgovnavigator/api/src/libs/constants";
26
import { CfnOutput, Stack, StackProps } from "aws-cdk-lib";
37
import * as apigateway from "aws-cdk-lib/aws-apigateway";
48
import * as cognito from "aws-cdk-lib/aws-cognito";
59
import { IFunction } from "aws-cdk-lib/aws-lambda";
610
import { Construct } from "constructs";
7-
import { applyStandardTags, attachLambdaToResource } from "./stackUtils";
11+
import { applyStandardTags, attachLambdaToResource, createSesConfigSet } from "./stackUtils";
812

913
interface LambdaConfig {
1014
lambda?: IFunction;
@@ -92,6 +96,9 @@ export class ApiStack extends Stack {
9296
value: this.restApi.restApiId,
9397
exportName: `${API_SERVICE_NAME}-${props.stage}-ApiGatewayId`,
9498
});
99+
100+
createSesConfigSet(this, WELCOME_EMAIL_CONFIG_SET_NAME);
101+
createSesConfigSet(this, REMINDER_EMAIL_CONFIG_SET_NAME);
95102
}
96103

97104
private addGatewayResponses() {

api/cdk/lib/iamStack.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ export class IamStack extends Stack {
9393
const sendEmailPolicy = new iam.PolicyStatement({
9494
effect: iam.Effect.ALLOW,
9595
actions: ["ses:sendEmail", "ses:sendRawEmail"],
96-
resources: [`arn:aws:ses:${this.region}:${this.account}:identity/business.nj.gov`],
96+
resources: [
97+
`arn:aws:ses:${this.region}:${this.account}:identity/business.nj.gov`,
98+
`arn:aws:ses:${this.region}:${this.account}:configuration-set/*`,
99+
],
97100
});
98101

99102
const kmsEncryptPolicy = new iam.PolicyStatement({

api/cdk/lib/stackUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Role } from "aws-cdk-lib/aws-iam";
1212
import { IFunction, Runtime } from "aws-cdk-lib/aws-lambda";
1313
import { NodejsFunction, NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";
1414
import * as logs from "aws-cdk-lib/aws-logs";
15+
import { ConfigurationSet } from "aws-cdk-lib/aws-ses";
1516
import { Construct, IConstruct } from "constructs";
1617
import path from "node:path";
1718

@@ -163,3 +164,9 @@ export const exportLambdaArn = (
163164
exportName: `${id}LambdaArn-${stage}`,
164165
});
165166
};
167+
168+
export function createSesConfigSet(scope: Construct, name: string) {
169+
return new ConfigurationSet(scope, name, {
170+
configurationSetName: name,
171+
});
172+
}

api/src/domain/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
XrayRegistrationEntry,
1010
XrayRegistrationStatusResponse,
1111
} from "@businessnjgovnavigator/shared";
12+
import { REMINDER_EMAIL_CONFIG_SET_NAME, WELCOME_EMAIL_CONFIG_SET_NAME } from "@libs/constants";
1213
import { NameAvailability, NameAvailabilityResponse } from "@shared/businessNameSearch";
1314
import { BusinessUser, NewsletterResponse, UserTestingResponse } from "@shared/businessUser";
1415
import { TaxFilingCalendarEvent } from "@shared/calendarEvent";
@@ -50,6 +51,9 @@ import * as https from "node:https";
5051
export type MessageChannel = "email" | "sms" | "tts" | "whatsapp";
5152
export type MessageTemplateId = "welcome_version-B" | "test-reminder-v1";
5253
export type MessageTopic = "welcome" | "reminder";
54+
export type EmailType =
55+
| typeof WELCOME_EMAIL_CONFIG_SET_NAME
56+
| typeof REMINDER_EMAIL_CONFIG_SET_NAME;
5357

5458
export interface MessageData {
5559
taskId: string;

api/src/functions/messagingService/app.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createDynamoDbClient } from "@db/config/dynamoDbConfig";
55
import { DynamoMessagesDataClient } from "@db/DynamoMessagesDataClient";
66
import { DynamoUserDataClient } from "@db/DynamoUserDataClient";
77
import {
8+
EmailType,
89
MessageData,
910
type MessageChannel,
1011
type MessageTemplateId,
@@ -21,6 +22,7 @@ import {
2122
STAGE,
2223
USERS_TABLE,
2324
} from "@functions/config";
25+
import { REMINDER_EMAIL_CONFIG_SET_NAME, WELCOME_EMAIL_CONFIG_SET_NAME } from "@libs/constants";
2426
import { LogWriter, LogWriterType } from "@libs/logWriter";
2527
import { getConfigValue, USER_MESSAGING_CONFIG_VARS } from "@libs/ssmUtils";
2628
import { v4 as uuidv4 } from "uuid";
@@ -159,7 +161,7 @@ export const handler = async (
159161
const buildWelcomeEmail = (props: { toEmail: string }): SendEmailCommand => {
160162
return buildSesEmailCommand({
161163
toEmail: props.toEmail,
162-
emailType: "welcome-email",
164+
emailType: WELCOME_EMAIL_CONFIG_SET_NAME,
163165
subject: "Welcome to Business.NJ.gov",
164166
htmlBody: welcomeEmailShortVersionTemplate,
165167
fallbackText: welcomeEmailShortVersionPlaintext,
@@ -169,7 +171,7 @@ const buildWelcomeEmail = (props: { toEmail: string }): SendEmailCommand => {
169171
const buildReminderEmail = (props: { toEmail: string }): SendEmailCommand => {
170172
return buildSesEmailCommand({
171173
toEmail: props.toEmail,
172-
emailType: "test-reminder-email",
174+
emailType: REMINDER_EMAIL_CONFIG_SET_NAME,
173175
subject: "Incomplete Tasks Reminder - Business.NJ.gov",
174176
htmlBody: testReminderHtmlTemplate,
175177
});
@@ -199,7 +201,7 @@ const buildMessageRecord = (props: {
199201

200202
const buildSesEmailCommand = (props: {
201203
toEmail: string;
202-
emailType: string;
204+
emailType: EmailType;
203205
subject: string;
204206
fallbackText?: string;
205207
htmlBody: string;
@@ -234,6 +236,7 @@ const buildSesEmailCommand = (props: {
234236
Value: props.emailType,
235237
},
236238
],
239+
ConfigurationSetName: props.emailType,
237240
};
238241
return new SendEmailCommand(input);
239242
};

api/src/libs/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export const API_SERVICE_NAME = "businessnjgov-api-v2";
2+
export const WELCOME_EMAIL_CONFIG_SET_NAME = "welcome-email";
3+
export const REMINDER_EMAIL_CONFIG_SET_NAME = "reminder-email";

0 commit comments

Comments
 (0)