1
1
import encryptionSDK from "@aws-crypto/client-node" ;
2
2
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" ;
5
4
6
5
const KEY_ARN = process . env . KEY_ARN ;
7
6
const KEY_ALIAS = process . env . KEY_ALIAS ;
@@ -15,17 +14,6 @@ if (!KEY_ARN || !KEY_ALIAS || !TEMPLATE_ID) {
15
14
) ;
16
15
}
17
16
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
-
29
17
export const handler : Handler = async ( event ) => {
30
18
// setup the encryptionSDK's key ring
31
19
const { decrypt } = encryptionSDK . buildDecrypt (
@@ -65,7 +53,9 @@ export const handler: Handler = async (event) => {
65
53
) {
66
54
// attempt to send the code to the user through Notify
67
55
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 , {
69
59
passwordReset : event . triggerSource === "CustomEmailSender_ForgotPassword" ,
70
60
// Keeping `accountVerification` and `resendCode` variables in case we need them in the future. They were removed when we implemented 2FA.
71
61
accountVerification : false ,
@@ -77,12 +67,12 @@ export const handler: Handler = async (event) => {
77
67
console . error (
78
68
JSON . stringify ( {
79
69
level : "error" ,
80
- msg : `Failed to send password reset email to ${ userEmail } ` ,
70
+ msg : `Failed to send password reset email to ${ userEmail } . ` ,
81
71
error : ( error as Error ) . message ,
82
72
} )
83
73
) ;
84
74
85
- throw new Error ( "Notify failed to send the code" ) ;
75
+ throw new Error ( `Failed to send password reset email to ${ userEmail } .` ) ;
86
76
}
87
77
}
88
78
} ;
0 commit comments