Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-consumer-concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitij-k-osmosys authored Jan 31, 2025
2 parents 247b2b9 + c14ba9b commit 21b5d5f
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 47 deletions.
12 changes: 6 additions & 6 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ MAX_RETRY_COUNT=3 # Max retry count, default is 3
ARCHIVE_LIMIT=1000 # Max notifications to archive, default is 1000
ARCHIVE_INTERVAL=3600 # Interval (in seconds) for archiving notifications, default 3600 (every 1 hour)

# Slogger configuration
SLOGGER_LOG_TYPE=
SLOGGER_LOG_LEVEL=error #Log level, default is error
SLOGERR_API_ENDPOINT= #Slogger log api url
SLOGERR_API_TOKEN= #Slogger api token
ENABLE_SLOGERR=false #default set to false
# Dhilog configuration
DHILOG_LOG_TYPE= # Custom "Log types" value defined on Dhilog portal
DHILOG_LOG_LEVEL=error # Log level, default is error
DHILOG_API_ENDPOINT= # Dhilog log api url
DHILOG_API_TOKEN= # Dhilog api token
ENABLE_DHILOG=false # Default set to false

# Logger configuration
LOG_LEVEL=info # Log level, default is info
Expand Down
13 changes: 7 additions & 6 deletions apps/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osmox",
"version": "4.2.1",
"version": "4.3.0",
"description": "Centralized multi-channel notification management component for streamlined communication across email, SMS, WhatsApp, and push notifications.",
"author": "Osmosys Software Solutions Private Limited",
"license": "MIT",
Expand Down Expand Up @@ -51,6 +51,7 @@
"bullmq": "^5.25.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"flatted": "^3.3.2",
"graphql": "^16.9.0",
"graphql-type-json": "^0.3.2",
"mailgun.js": "^10.2.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/common/decorators/is-data-valid.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { SmsSnsDataDto } from 'src/modules/notifications/dtos/providers/smsSns-d
export class IsDataValidConstraint implements ValidatorConstraintInterface {
constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(IsDataValidConstraint.name),
) {}

async validate(value: object, args: ValidationArguments): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/common/guards/api-key/api-key.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ApiKeyGuard implements CanActivate {
constructor(
private readonly serverApiKeysService: ServerApiKeysService,
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(ApiKeyGuard.name),
) {}

canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TransportStreamOptions } from 'winston-transport';
import { ConfigService } from '@nestjs/config';
import { Logger } from '@nestjs/common/services/logger.service';
import { firstValueFrom } from 'rxjs';
import { stringify } from 'flatted';

interface CustomTransportOptions extends TransportStreamOptions {
httpService: HttpService;
Expand All @@ -19,10 +20,10 @@ interface LogInfo {
severity: string;
}

export class SlogerrTransport extends TransportStream {
export class DhilogTransport extends TransportStream {
private readonly httpService: HttpService;
private readonly configService: ConfigService;
private readonly logger = new Logger(SlogerrTransport.name);
private readonly logger = new Logger(DhilogTransport.name);

constructor(options: CustomTransportOptions) {
super(options);
Expand All @@ -31,16 +32,16 @@ export class SlogerrTransport extends TransportStream {
}

async log(info: LogInfo, callback: () => void): Promise<void> {
const allowedLevels = (this.configService.get<string>('SLOGGER_LOG_LEVEL') || 'error')
const allowedLevels = (this.configService.get<string>('DHILOG_LOG_LEVEL') || 'error')
.split(',')
.map((level) => level.trim());
const logType = this.configService.get<string>('SLOGGER_LOG_TYPE') || 'Exceptions';
const logType = this.configService.get<string>('DHILOG_LOG_TYPE') || 'Exceptions';

if (allowedLevels.includes(info.level)) {
const apiEndpoint = this.configService.get<string>('SLOGERR_API_ENDPOINT');
const apiKey = this.configService.get<string>('SLOGERR_API_TOKEN');
const apiEndpoint = this.configService.get<string>('DHILOG_API_ENDPOINT');
const apiKey = this.configService.get<string>('DHILOG_API_TOKEN');

this.logger.log(`Log Info: ${JSON.stringify(info)}`);
this.logger.log(`Log Info: ${stringify(info)}`);

const logCreatedOn = info.timestamp || new Date().toISOString();

Expand All @@ -65,14 +66,14 @@ export class SlogerrTransport extends TransportStream {
);

if (response.status !== 200) {
this.logger.error(
`Failed to send log to Slogerr. Status: ${response.status}, Message: ${response.statusText}`,
this.logger.warn(
`Failed to send log to Dhilog. Status: ${response.status}, Message: ${response.statusText}`,
);
} else {
this.logger.log('Error log successfully sent to Slogerr', response);
this.logger.log('Error log successfully sent to Dhilog', response);
}
} catch (error) {
this.logger.error('Failed to send log to Slogerr', error.message);
this.logger.warn('Failed to send log to Dhilog', error.message);
}
}

Expand Down
11 changes: 6 additions & 5 deletions apps/api/src/config/logger.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'winston-daily-rotate-file';
import { ConfigService } from '@nestjs/config';
import { name as applicationName } from 'package.json';
import DailyRotateFile from 'winston-daily-rotate-file';
import { SlogerrTransport } from 'src/common/logger/slogerr.transport';
import { DhilogTransport } from 'src/common/logger/dhilog.transport';
import { stringify } from 'flatted';

const configService = new ConfigService();
const httpService = new HttpService();
Expand All @@ -18,7 +19,7 @@ const logDir = 'logs';
const combinedLogMaxSize = configService.get<string>('COMBINED_LOG_MAX_SIZE');
const errorLogMaxSize = configService.get<string>('ERROR_LOG_MAX_SIZE');

const enableSlogger = configService.get<string>('ENABLE_SLOGERR') || 'false';
const enableDhilog = configService.get<string>('ENABLE_DHILOG') || 'false';

const logFormat = format.combine(
format.timestamp(),
Expand All @@ -39,7 +40,7 @@ const logFormat = format.combine(
message,
stackTrace: stack,
};
return JSON.stringify(logObject);
return stringify(logObject);
}),
);

Expand Down Expand Up @@ -82,7 +83,7 @@ if (errorLogMaxSize === '0') {
errorLogOptions.maxSize = '20m';
}

const slogerrTransport = new SlogerrTransport({
const dhilogTransport = new DhilogTransport({
httpService,
configService,
});
Expand All @@ -97,7 +98,7 @@ const transportsConfig = [
}),
new transports.DailyRotateFile(combinedLogOptions),
new transports.DailyRotateFile(errorLogOptions),
...(enableSlogger === 'true' ? [slogerrTransport] : []),
...(enableDhilog === 'true' ? [dhilogTransport] : []),
];

export const loggerConfig = WinstonModule.createLogger({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class NotificationsController {
constructor(
private readonly notificationService: NotificationsService,
private readonly jsend: JsendFormatter,
private logger: Logger,
private logger: Logger = new Logger(NotificationsController.name),
) {}

@Post('queue')
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/providers/aws-ses/aws-ses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface AwsSesData {
export class AwsSesService {
constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(AwsSesService.name),
) {}

private async getSesClient(providerId: number): Promise<aws.SES> {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/providers/mailgun/mailgun.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class MailgunService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(MailgunService.name),
) {
this.mailgun = new Mailgun(FormData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class PushSnsService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(PushSnsService.name),
) {}

async assignSnsConfig(providerId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SmsKapsystemService {
constructor(
private httpService: HttpService,
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(SmsKapsystemService.name),
) {}

async assignKAPSystemValues(providerId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class SmsPlivoService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(SmsPlivoService.name),
) {}

async assignTransport(providerId: number): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/providers/sms-sns/sms-sns.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SmsSnsService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(SmsSnsService.name),
) {}

async assignSnsConfig(providerId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class SmsTwilioService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(SmsTwilioService.name),
) {}

async assignTransport(providerId: number): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/providers/smtp/smtp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class SmtpService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(SmtpService.name),
) {}

async assignTransport(providerId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class VcTwilioService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(VcTwilioService.name),
) {}

async assignTransport(providerId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class WaTwilioBusinessService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(WaTwilioBusinessService.name),
) {}

async assignTransport(providerId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class WaTwilioService {

constructor(
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(WaTwilioService.name),
) {}

async assignTransport(providerId: number): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Wa360dialogService {
constructor(
private httpService: HttpService,
private readonly providersService: ProvidersService,
private logger: Logger,
private logger: Logger = new Logger(Wa360dialogService.name),
) {}

async assignWA360Values(providerId: number): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions apps/portal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/portal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osmox-portal",
"version": "4.2.1",
"version": "4.3.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down

0 comments on commit 21b5d5f

Please sign in to comment.