Skip to content

Commit 570a7e0

Browse files
refactor: leverage new connectors package (#953)
Co-authored-by: Bryan Robitaille <bryan.robitaille@cds-snc.ca>
1 parent 598c8d9 commit 570a7e0

19 files changed

+2052
-1427
lines changed

lambda-code/cognito-email-sender/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ COPY package.json yarn.lock ./
88

99
RUN yarn install --frozen-lockfile
1010

11-
COPY lib ./lib
1211
COPY main.ts tsconfig.json ./
1312

1413
RUN yarn build

lambda-code/cognito-email-sender/lib/gc-notify-client.ts

-73
This file was deleted.

lambda-code/cognito-email-sender/main.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import encryptionSDK from "@aws-crypto/client-node";
22
import { Handler } from "aws-lambda";
3-
import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";
4-
import { GCNotifyClient } from "./lib/gc-notify-client.js";
3+
import { GCNotifyConnector } from "@gcforms/connectors";
54

65
const KEY_ARN = process.env.KEY_ARN;
76
const KEY_ALIAS = process.env.KEY_ALIAS;
@@ -15,17 +14,6 @@ if (!KEY_ARN || !KEY_ALIAS || !TEMPLATE_ID) {
1514
);
1615
}
1716

18-
const client = new SecretsManagerClient();
19-
const command = new GetSecretValueCommand({ SecretId: process.env.NOTIFY_API_KEY });
20-
console.log("Retrieving Notify API Key from Secrets Manager");
21-
const notifyApiKey = await client.send(command);
22-
23-
if (notifyApiKey.SecretString === undefined) {
24-
throw new Error("GCNotify API key is undefined");
25-
}
26-
27-
const gcNotifyClient = GCNotifyClient.default(notifyApiKey.SecretString);
28-
2917
export const handler: Handler = async (event) => {
3018
// setup the encryptionSDK's key ring
3119
const { decrypt } = encryptionSDK.buildDecrypt(
@@ -65,7 +53,9 @@ export const handler: Handler = async (event) => {
6553
) {
6654
// attempt to send the code to the user through Notify
6755
try {
68-
await gcNotifyClient.sendEmail(userEmail, TEMPLATE_ID, {
56+
const gcNotifyConnector = await GCNotifyConnector.defaultUsingApiKeyFromAwsSecret(process.env.NOTIFY_API_KEY ?? "");
57+
58+
await gcNotifyConnector.sendEmail(userEmail, TEMPLATE_ID, {
6959
passwordReset: event.triggerSource === "CustomEmailSender_ForgotPassword",
7060
// Keeping `accountVerification` and `resendCode` variables in case we need them in the future. They were removed when we implemented 2FA.
7161
accountVerification: false,
@@ -77,12 +67,12 @@ export const handler: Handler = async (event) => {
7767
console.error(
7868
JSON.stringify({
7969
level: "error",
80-
msg: `Failed to send password reset email to ${userEmail}`,
70+
msg: `Failed to send password reset email to ${userEmail}.`,
8171
error: (error as Error).message,
8272
})
8373
);
8474

85-
throw new Error("Notify failed to send the code");
75+
throw new Error(`Failed to send password reset email to ${userEmail}.`);
8676
}
8777
}
8878
};

lambda-code/cognito-email-sender/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
},
1313
"dependencies": {
1414
"@aws-crypto/client-node": "4.0.0",
15-
"@aws-sdk/client-secrets-manager": "^3.478.0",
16-
"axios": "^1.6.8"
15+
"@gcforms/connectors": "^1.0.0"
1716
},
1817
"devDependencies": {
1918
"@types/aws-lambda": "^8.10.126",
2019
"@types/node": "^20.9.0",
2120
"typescript": "^5.2.2"
22-
}
21+
},
22+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
2323
}

0 commit comments

Comments
 (0)