Skip to content

Commit 5e9c010

Browse files
authored
Merge pull request #119 from devtron-labs/release-candidate-v0.29.0
release: Release candidate v0.29.0
2 parents 81f97d2 + e1cbf52 commit 5e9c010

File tree

2 files changed

+84
-43
lines changed

2 files changed

+84
-43
lines changed

src/destination/destinationHandlers/sesHandler.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ export class SESService implements Handler {
6464
const providersSet = new Set(providerObjects);
6565
this.sesConfig = null
6666
for (const element of providersSet) {
67-
if (element['dest'] === "ses") {
67+
if ((element['dest'] === "ses") && (element['configId'] != 0)) {
68+
await this.getConfigById(element['configId'], providersSet, event, sesTemplate, setting, destinationMap, configsMap)
69+
break
70+
} else if (element['dest'] === "ses") {
6871
await this.getDefaultConfig(providersSet, event, sesTemplate, setting, destinationMap, configsMap)
6972
break
7073
}
@@ -84,16 +87,13 @@ export class SESService implements Handler {
8487
if(this.sesConfig && this.sesConfig.from_email){
8588
for (const p of providersSet) {
8689
if (p['dest'] == "ses") {
87-
let userId = p['configId']
8890
let recipient = p['recipient']
8991
let configKey = '';
9092
if(recipient) {
9193
configKey = p['dest'] + '-' + recipient
92-
}else{
93-
configKey = p['dest'] + '-' + userId
9494
}
9595
if (!configsMap.get(configKey)) {
96-
await this.processNotification(userId, recipient, event, sesTemplate, setting, p, emailMap)
96+
await this.processNotification(recipient, event, sesTemplate, setting, p, emailMap)
9797
configsMap.set(configKey, true)
9898
}
9999
}
@@ -105,6 +105,36 @@ export class SESService implements Handler {
105105
}
106106
}
107107

108+
private async getConfigById(id,providersSet, event: Event, sesTemplate: NotificationTemplates, setting: NotificationSettings, emailMap: Map<string, boolean>, configsMap: Map<string, boolean> ){
109+
try {
110+
const config = await this.sesConfigRepository.findBySESConfigId(id)
111+
this.sesConfig = {
112+
region: config['region'],
113+
access_key: config['access_key'],
114+
secret_access_key: config['secret_access_key'],
115+
from_email: config['from_email']
116+
}
117+
if(this.sesConfig && this.sesConfig.from_email){
118+
for (const p of providersSet) {
119+
if (p['dest'] == "ses") {
120+
let recipient = p['recipient']
121+
let configKey = '';
122+
if(recipient) {
123+
configKey = p['dest'] + '-' + recipient
124+
}
125+
if (!configsMap.get(configKey)) {
126+
await this.processNotification(recipient, event, sesTemplate, setting, p, emailMap)
127+
configsMap.set(configKey, true)
128+
}
129+
}
130+
};
131+
}
132+
} catch (error) {
133+
this.logger.error('getDefaultConfig', error)
134+
throw new CustomError("Unable to send SES notification",500);
135+
}
136+
}
137+
108138
private async preparePayloadAndSend(event: Event, sesTemplate: NotificationTemplates, setting: NotificationSettings, p: string){
109139
let sdk: NotifmeSdk = new NotifmeSdk({
110140
channels: {
@@ -163,22 +193,12 @@ export class SESService implements Handler {
163193
}
164194
}
165195

166-
private async processNotification(userId: number, recipient: string, event: Event, sesTemplate: NotificationTemplates, setting: NotificationSettings, p: string, emailMap: Map<string, boolean>) {
167-
if(userId) {
168-
const user = await this.usersRepository.findByUserId(userId)
169-
if (!user) {
170-
this.logger.info('no user found for id - ' + userId)
171-
this.logger.info(event.correlationId)
172-
return
173-
}
174-
await this.sendEmailIfNotDuplicate(user['email_id'], event, sesTemplate, setting, p, emailMap)
175-
}else{
176-
if (!recipient) {
177-
this.logger.error('recipient is blank')
178-
return
179-
}
180-
await this.sendEmailIfNotDuplicate(recipient, event, sesTemplate, setting, p, emailMap)
196+
private async processNotification(recipient: string, event: Event, sesTemplate: NotificationTemplates, setting: NotificationSettings, p: string, emailMap: Map<string, boolean>) {
197+
if (!recipient) {
198+
this.logger.error('recipient is blank')
199+
return
181200
}
201+
await this.sendEmailIfNotDuplicate(recipient, event, sesTemplate, setting, p, emailMap)
182202
}
183203

184204
private async sendEmailIfNotDuplicate(recipient : string, event: Event, sesTemplate: NotificationTemplates, setting: NotificationSettings, p: string, emailMap: Map<string, boolean>) {

src/destination/destinationHandlers/smtpHandler.ts

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ export class SMTPService implements Handler {
6464
const providersSet = new Set(providerObjects);
6565
this.smtpConfig = null
6666
for (const element of providersSet) {
67-
if (element['dest'] === "smtp") {
67+
if ((element['dest'] === "smtp") && (element['configId'] != 0)) {
68+
await this.getConfigById(element['configId'], providersSet, event, sesTemplate, setting, destinationMap, configsMap)
69+
break
70+
} else if (element['dest'] === "smtp") {
6871
await this.getDefaultConfig(providersSet, event, sesTemplate, setting, destinationMap, configsMap)
6972
break
7073
}
@@ -85,20 +88,48 @@ export class SMTPService implements Handler {
8588
if(this.smtpConfig && this.smtpConfig.from_email){
8689
for (const p of providersSet) {
8790
if (p['dest'] == "smtp") {
88-
let userId = p['configId']
8991
let recipient = p['recipient']
9092
let configKey = '';
9193
if(recipient) {
9294
configKey = p['dest'] + '-' + recipient
93-
}else{
94-
configKey = p['dest'] + '-' + userId
9595
}
9696
if (!configsMap.get(configKey)) {
97-
await this.processNotification(userId, recipient, event, sesTemplate, setting, p, emailMap)
97+
await this.processNotification(recipient, event, sesTemplate, setting, p, emailMap)
9898
configsMap.set(configKey, true)
9999
}
100100
}
101-
};
101+
}
102+
}
103+
} catch (error) {
104+
this.logger.error('getDefaultConfig', error)
105+
throw new CustomError("Unable to send SMTP notification",500);
106+
}
107+
}
108+
109+
private async getConfigById(id,providersSet, event: Event, sesTemplate: NotificationTemplates, setting: NotificationSettings, emailMap: Map<string, boolean>, configsMap: Map<string, boolean> ){
110+
try {
111+
const config = await this.smtpConfigRepository.findBySMTPConfigId(id)
112+
this.smtpConfig = {
113+
port: config['port'],
114+
host: config['host'],
115+
auth_user: config['auth_user'],
116+
auth_password: config['auth_password'],
117+
from_email: config['from_email']
118+
}
119+
if(this.smtpConfig && this.smtpConfig.from_email){
120+
for (const p of providersSet) {
121+
if (p['dest'] == "smtp") {
122+
let recipient = p['recipient']
123+
let configKey = '';
124+
if(recipient) {
125+
configKey = p['dest'] + '-' + recipient
126+
}
127+
if (!configsMap.get(configKey)) {
128+
await this.processNotification(recipient, event, sesTemplate, setting, p, emailMap)
129+
configsMap.set(configKey, true)
130+
}
131+
}
132+
}
102133
}
103134
} catch (error) {
104135
this.logger.error('getDefaultConfig', error)
@@ -150,34 +181,24 @@ export class SMTPService implements Handler {
150181
catch(error: any) {
151182
this.logger.error(error.message);
152183
await this.saveNotificationEventFailureLog(event, p, setting);
153-
};
184+
}
154185
} else {
155186
try {
156187
const result = this.sendNotification(event, sdk, smtpTemplate.template_payload)
157188
await this.saveNotificationEventSuccessLog(result, event, p, setting);}
158189
catch(error: any) {
159190
this.logger.error(error.message);
160191
await this.saveNotificationEventFailureLog(event, p, setting);
161-
};
192+
}
162193
}
163194
}
164195

165-
private async processNotification(userId: number, recipient: string, event: Event, smtpTemplate: NotificationTemplates, setting: NotificationSettings, p: string, emailMap: Map<string, boolean>) {
166-
if(userId) {
167-
const user = await this.usersRepository.findByUserId(userId)
168-
if (!user) {
169-
this.logger.info('no user found for id - ' + userId)
170-
this.logger.info(event.correlationId)
171-
return
172-
}
173-
await this.sendEmailIfNotDuplicate(user['email_id'], event, smtpTemplate, setting, p, emailMap)
174-
}else{
175-
if (!recipient) {
176-
this.logger.error('recipient is blank')
177-
return
178-
}
179-
await this.sendEmailIfNotDuplicate(recipient, event, smtpTemplate, setting, p, emailMap)
196+
private async processNotification(recipient: string, event: Event, smtpTemplate: NotificationTemplates, setting: NotificationSettings, p: string, emailMap: Map<string, boolean>) {
197+
if (!recipient) {
198+
this.logger.error('recipient is blank')
199+
return
180200
}
201+
await this.sendEmailIfNotDuplicate(recipient, event, smtpTemplate, setting, p, emailMap)
181202
}
182203

183204
private async sendEmailIfNotDuplicate(recipient : string, event: Event, smtpTemplate: NotificationTemplates, setting: NotificationSettings, p: string, emailMap: Map<string, boolean>) {

0 commit comments

Comments
 (0)