Package inquiry, UAT related update

This commit is contained in:
Stephanos A
2026-06-26 13:57:26 +03:00
parent eefbe6e8ed
commit 86c7b2e4eb
23 changed files with 648 additions and 93 deletions

View File

@@ -5,6 +5,7 @@ import {
OnApplicationBootstrap,
} from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import * as sgMail from "@sendgrid/mail";
import { SendEmail } from "./dtos/email.dto";
@Injectable()
@@ -14,9 +15,15 @@ export class EmailClientService implements OnApplicationBootstrap {
constructor(
@Inject("EMAIL_SERVICE")
private readonly emailServiceClient: ClientProxy,
) {}
) {
const apiKey = process.env.SENDGRID_API_KEY;
if (apiKey) sgMail.setApiKey(apiKey);
}
private readonly enabled = process.env.RABBITMQ_ENABLED !== "false";
private get sendgridEnabled() {
return !!process.env.SENDGRID_API_KEY;
}
async onApplicationBootstrap() {
if (!this.enabled) return;
@@ -29,22 +36,38 @@ export class EmailClientService implements OnApplicationBootstrap {
}
async sendEmail(dto: SendEmail): Promise<{ queued: boolean }> {
if (!this.enabled) {
this.logger.warn(`RABBITMQ disabled — skipped EMAIL`);
return { queued: false };
if (this.enabled) {
this.emailServiceClient.emit("send-email", {
...dto,
appKey: "IFHCRS-LICENSE-MANAGEMENT",
});
this.logger.log(
`EMAIL queued to RabbitMQ [${process.env.EMAIL_QUEUE ?? "email_queue"}] pattern='send-email'`,
);
this.logger.debug(
`EMAIL payload to=${dto.to} subject="${dto.subject ?? ""}"`,
);
return { queued: true };
}
this.emailServiceClient.emit("send-email", {
...dto,
appKey: "IFHCRS-LICENSE-MANAGEMENT",
});
// Fire-and-forget enqueue: this confirms the message was handed to RabbitMQ, NOT delivered.
this.logger.log(
`EMAIL queued to RabbitMQ [${process.env.EMAIL_QUEUE ?? "email_queue"}] pattern='send-email'`,
);
// Recipient + content are PII — keep them at debug level only.
this.logger.debug(
`EMAIL payload to=${dto.to} subject="${dto.subject ?? ""}" body="${dto.text ?? dto.body ?? dto.html ?? ""}"`,
);
return { queued: true };
if (this.sendgridEnabled) {
try {
await sgMail.send({
to: dto.to,
from: process.env.SENDGRID_FROM_EMAIL ?? "noreply@edr-platform.com",
subject: dto.subject ?? "EDR Notification",
text: dto.text ?? dto.body ?? "",
...(dto.html ? { html: dto.html } : {}),
});
this.logger.log(`EMAIL sent via SendGrid to=${dto.to}`);
return { queued: true };
} catch (err: any) {
this.logger.error(`SendGrid send failed to=${dto.to}: ${err?.message}`);
return { queued: false };
}
}
this.logger.warn(`EMAIL not sent (no transport) — to=${dto.to} subject="${dto.subject ?? ""}"`);
return { queued: false };
}
}

View File

@@ -32,7 +32,7 @@ export class SmsClientService implements OnApplicationBootstrap {
async sendSms(dto: SingleMessageDto): Promise<{ queued: boolean }> {
if (!this.enabled) {
this.logger.warn(`RABBITMQ disabled — skipped SMS`);
this.logger.warn(`SMS not sent (RabbitMQ disabled)to=${dto.to} message="${dto.message}"`);
return { queued: false };
}
this.smsClient.emit("send-sms", {
@@ -51,7 +51,7 @@ export class SmsClientService implements OnApplicationBootstrap {
async sendBulkMessages(dto: BulkMessagesDto): Promise<{ queued: boolean }> {
if (!this.enabled) {
this.logger.warn(`RABBITMQ disabled — skipped BULK SMS (${dto.messages?.length ?? 0} messages)`);
this.logger.warn(`BULK SMS not sent (RabbitMQ disabled)${dto.messages?.length ?? 0} messages skipped`);
return { queued: false };
}
const messages = (dto.messages ?? []).map((m) => ({ to: m.to, text: m.message, from: m.from }));