email sent when personal information changed
This commit is contained in:
@@ -11,8 +11,16 @@ const { htmlToPlainText } = require("./emailUtils");
|
||||
*/
|
||||
class EmailClient {
|
||||
constructor() {
|
||||
// Singleton pattern - return existing instance if already created
|
||||
if (EmailClient.instance) {
|
||||
return EmailClient.instance;
|
||||
}
|
||||
|
||||
this.sesClient = null;
|
||||
this.initialized = false;
|
||||
this.initializationPromise = null;
|
||||
|
||||
EmailClient.instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,19 +28,30 @@ class EmailClient {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async initialize() {
|
||||
// If already initialized, return immediately
|
||||
if (this.initialized) return;
|
||||
|
||||
try {
|
||||
// Use centralized AWS configuration with credential profiles
|
||||
const awsConfig = getAWSConfig();
|
||||
this.sesClient = new SESClient(awsConfig);
|
||||
|
||||
this.initialized = true;
|
||||
console.log("AWS SES Email Client initialized successfully");
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize AWS SES Email Client:", error);
|
||||
throw error;
|
||||
// If initialization is in progress, wait for it
|
||||
if (this.initializationPromise) {
|
||||
return this.initializationPromise;
|
||||
}
|
||||
|
||||
// Start initialization and store the promise
|
||||
this.initializationPromise = (async () => {
|
||||
try {
|
||||
// Use centralized AWS configuration with credential profiles
|
||||
const awsConfig = getAWSConfig();
|
||||
this.sesClient = new SESClient(awsConfig);
|
||||
|
||||
this.initialized = true;
|
||||
console.log("AWS SES Email Client initialized successfully");
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize AWS SES Email Client:", error);
|
||||
throw error;
|
||||
}
|
||||
})();
|
||||
|
||||
return this.initializationPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user