diff --git a/apps/agent-service/test/app.e2e-spec.ts b/apps/agent-service/test/app.e2e-spec.ts index 58f95a822..0a642e6bd 100644 --- a/apps/agent-service/test/app.e2e-spec.ts +++ b/apps/agent-service/test/app.e2e-spec.ts @@ -15,10 +15,5 @@ describe('AgentServiceController (e2e)', () => { await app.init(); }); - it('/ (GET)', () => { - return request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!'); - }); + it('/ (GET)', () => request(app.getHttpServer()).get('/').expect(200).expect('Hello World!')); }); diff --git a/apps/api-gateway/src/cloud-wallet/enums/connections.enum.ts b/apps/api-gateway/src/cloud-wallet/enums/connections.enum.ts index a15929cf6..9c76afc13 100644 --- a/apps/api-gateway/src/cloud-wallet/enums/connections.enum.ts +++ b/apps/api-gateway/src/cloud-wallet/enums/connections.enum.ts @@ -1,4 +1,4 @@ export declare enum HandshakeProtocol { - Connections = "https://didcomm.org/connections/1.0", - DidExchange = "https://didcomm.org/didexchange/1.0" -} \ No newline at end of file + Connections = 'https://didcomm.org/connections/1.0', + DidExchange = 'https://didcomm.org/didexchange/1.0' +} diff --git a/apps/api-gateway/src/connection/enums/connections.enum.ts b/apps/api-gateway/src/connection/enums/connections.enum.ts index a15929cf6..9c76afc13 100644 --- a/apps/api-gateway/src/connection/enums/connections.enum.ts +++ b/apps/api-gateway/src/connection/enums/connections.enum.ts @@ -1,4 +1,4 @@ export declare enum HandshakeProtocol { - Connections = "https://didcomm.org/connections/1.0", - DidExchange = "https://didcomm.org/didexchange/1.0" -} \ No newline at end of file + Connections = 'https://didcomm.org/connections/1.0', + DidExchange = 'https://didcomm.org/didexchange/1.0' +} diff --git a/apps/api-gateway/src/connection/interfaces/index.ts b/apps/api-gateway/src/connection/interfaces/index.ts index 20f8f584b..acba5bc15 100644 --- a/apps/api-gateway/src/connection/interfaces/index.ts +++ b/apps/api-gateway/src/connection/interfaces/index.ts @@ -26,8 +26,7 @@ export interface ISelectedOrgInterface { export interface IOrganizationInterface { name: string; description: string; - org_agents: IOrgAgentInterface[] - + org_agents: IOrgAgentInterface[]; } export interface IOrgAgentInterface { @@ -40,7 +39,6 @@ export interface IOrgAgentInterface { orgId: string; } - export class IConnectionInterface { tag: object; createdAt: string; @@ -71,8 +69,8 @@ interface IOutOfBandInvitationService { } interface IOutOfBandInvitation { - "@type": string; - "@id": string; + '@type': string; + '@id': string; label: string; accept: string[]; handshake_protocols: string[]; @@ -114,4 +112,4 @@ interface IConnectionRecord { export interface IReceiveInvitationRes { outOfBandRecord: IOutOfBandRecord; connectionRecord: IConnectionRecord; -} \ No newline at end of file +} diff --git a/apps/api-gateway/src/dtos/credential-offer.dto.ts b/apps/api-gateway/src/dtos/credential-offer.dto.ts index c59e54406..39a4e2b7d 100644 --- a/apps/api-gateway/src/dtos/credential-offer.dto.ts +++ b/apps/api-gateway/src/dtos/credential-offer.dto.ts @@ -1,40 +1,39 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsArray, IsNotEmpty, IsString } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { IsArray, IsNotEmpty, IsString } from 'class-validator'; interface attributeValue { - name: string, - value: string, + name: string; + value: string; } export class IssueCredentialOffer { + @ApiProperty({ example: { protocolVersion: 'v1' } }) + @IsNotEmpty({ message: 'Please provide valid protocol-version' }) + @IsString({ message: 'protocol-version should be string' }) + protocolVersion: string; - @ApiProperty({ example: { 'protocolVersion': 'v1' } }) - @IsNotEmpty({ message: 'Please provide valid protocol-version' }) - @IsString({ message: 'protocol-version should be string' }) - protocolVersion: string; - - @ApiProperty({ example: { 'attributes': [{ 'value': 'string', 'name': 'string' }] } }) - @IsNotEmpty({ message: 'Please provide valid attributes' }) - @IsArray({ message: 'attributes should be array' }) - attributes: attributeValue[]; + @ApiProperty({ example: { attributes: [{ value: 'string', name: 'string' }] } }) + @IsNotEmpty({ message: 'Please provide valid attributes' }) + @IsArray({ message: 'attributes should be array' }) + attributes: attributeValue[]; - @ApiProperty({ example: { 'credentialDefinitionId': 'string' } }) - @IsNotEmpty({ message: 'Please provide valid credentialDefinitionId' }) - @IsString({ message: 'credentialDefinitionId should be string' }) - credentialDefinitionId: string; + @ApiProperty({ example: { credentialDefinitionId: 'string' } }) + @IsNotEmpty({ message: 'Please provide valid credentialDefinitionId' }) + @IsString({ message: 'credentialDefinitionId should be string' }) + credentialDefinitionId: string; - @ApiProperty({ example: { autoAcceptCredential: 'always' } }) - @IsNotEmpty({ message: 'Please provide valid autoAcceptCredential' }) - @IsString({ message: 'autoAcceptCredential should be string' }) - autoAcceptCredential: string; + @ApiProperty({ example: { autoAcceptCredential: 'always' } }) + @IsNotEmpty({ message: 'Please provide valid autoAcceptCredential' }) + @IsString({ message: 'autoAcceptCredential should be string' }) + autoAcceptCredential: string; - @ApiProperty({ example: { comment: 'string' } }) - @IsNotEmpty({ message: 'Please provide valid comment' }) - @IsString({ message: 'comment should be string' }) - comment: string; + @ApiProperty({ example: { comment: 'string' } }) + @IsNotEmpty({ message: 'Please provide valid comment' }) + @IsString({ message: 'comment should be string' }) + comment: string; - @ApiProperty({ example: { connectionId: '3fa85f64-5717-4562-b3fc-2c963f66afa6' } }) - @IsNotEmpty({ message: 'Please provide valid connection-id' }) - @IsString({ message: 'Connection-id should be string' }) - connectionId: string; + @ApiProperty({ example: { connectionId: '3fa85f64-5717-4562-b3fc-2c963f66afa6' } }) + @IsNotEmpty({ message: 'Please provide valid connection-id' }) + @IsString({ message: 'Connection-id should be string' }) + connectionId: string; } diff --git a/apps/api-gateway/src/dtos/credential-send-offer.dto.ts b/apps/api-gateway/src/dtos/credential-send-offer.dto.ts index 1467ef6af..94afa97ee 100644 --- a/apps/api-gateway/src/dtos/credential-send-offer.dto.ts +++ b/apps/api-gateway/src/dtos/credential-send-offer.dto.ts @@ -1,10 +1,9 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsNotEmpty, IsString } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { IsNotEmpty, IsString } from 'class-validator'; export class CredentialSendOffer { - - @ApiProperty({ example: 'string' }) - @IsNotEmpty({ message: 'Please provide valid credentialRecordId' }) - @IsString({ message: 'credentialRecordId should be string' }) - credentialRecordId: string; + @ApiProperty({ example: 'string' }) + @IsNotEmpty({ message: 'Please provide valid credentialRecordId' }) + @IsString({ message: 'credentialRecordId should be string' }) + credentialRecordId: string; } diff --git a/apps/api-gateway/src/helper-files/file-operation.helper.ts b/apps/api-gateway/src/helper-files/file-operation.helper.ts index e02d7315b..15ace62be 100644 --- a/apps/api-gateway/src/helper-files/file-operation.helper.ts +++ b/apps/api-gateway/src/helper-files/file-operation.helper.ts @@ -1,36 +1,26 @@ -import { promisify } from "util"; -import * as fs from "fs"; +import { promisify } from 'util'; +import * as fs from 'fs'; +export const createFile = async (path: string, fileName: string, data: string): Promise => { + // eslint-disable-next-line @typescript-eslint/no-use-before-define + if (!checkIfFileOrDirectoryExists(path)) { + fs.mkdirSync(path, { recursive: true }); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const writeFile = promisify(fs.writeFile); + return fs.writeFileSync(`${path}/${fileName}`, data, 'utf8'); +}; -export const createFile = async ( - path: string, - fileName: string, - data: string - ): Promise => { - // eslint-disable-next-line @typescript-eslint/no-use-before-define - if (!checkIfFileOrDirectoryExists(path)) { - - fs.mkdirSync(path); - } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const writeFile = promisify(fs.writeFile); - return fs.writeFileSync(`${path}/${fileName}`, data, 'utf8'); - }; +export const checkIfFileOrDirectoryExists = (path: string): boolean => fs.existsSync(path); - export const checkIfFileOrDirectoryExists = (path: string): boolean => fs.existsSync(path); - - export const getFile = async ( - path: string, - encoding: BufferEncoding - ): Promise => { - const readFile = promisify(fs.readFile); - - return encoding ? readFile(path, {encoding}) : readFile(path, {}); - }; +export const getFile = async (path: string, encoding: BufferEncoding): Promise => { + const readFile = promisify(fs.readFile); + return encoding ? readFile(path, { encoding }) : readFile(path, {}); +}; - export const deleteFile = async (path: string): Promise => { - const unlink = promisify(fs.unlink); - - return unlink(path); - }; \ No newline at end of file +export const deleteFile = async (path: string): Promise => { + const unlink = promisify(fs.unlink); + + return unlink(path); +}; diff --git a/apps/api-gateway/src/verification/dto/webhook-proof.dto.ts b/apps/api-gateway/src/verification/dto/webhook-proof.dto.ts index d4f150c48..1f71f5c52 100644 --- a/apps/api-gateway/src/verification/dto/webhook-proof.dto.ts +++ b/apps/api-gateway/src/verification/dto/webhook-proof.dto.ts @@ -1,83 +1,82 @@ -import { ApiPropertyOptional } from "@nestjs/swagger"; -import { IsOptional } from "class-validator"; +import { ApiPropertyOptional } from '@nestjs/swagger'; +import { IsOptional } from 'class-validator'; interface IWebhookPresentationProof { - threadId: string; - state: string; - connectionId + threadId: string; + state: string; + connectionId; } export class WebhookPresentationProofDto { + @ApiPropertyOptional() + @IsOptional() + metadata: object; - @ApiPropertyOptional() - @IsOptional() - metadata: object; - - @ApiPropertyOptional() - @IsOptional() - _tags: IWebhookPresentationProof; - - @ApiPropertyOptional() - @IsOptional() - id: string; - - @ApiPropertyOptional() - @IsOptional() - createdAt: string; - - @ApiPropertyOptional() - @IsOptional() - protocolVersion: string; - - @ApiPropertyOptional() - @IsOptional() - state: string; - - @ApiPropertyOptional() - @IsOptional() - connectionId: string; - - @ApiPropertyOptional() - @IsOptional() - threadId: string; - - @ApiPropertyOptional() - @IsOptional() - parentThreadId?: string; - - @ApiPropertyOptional() - @IsOptional() - presentationId: string; - - @ApiPropertyOptional() - @IsOptional() - autoAcceptProof: string; - - @ApiPropertyOptional() - @IsOptional() - updatedAt: string; - - @ApiPropertyOptional() - @IsOptional() - isVerified: boolean; - - @ApiPropertyOptional() - @IsOptional() - contextCorrelationId: string; - - @ApiPropertyOptional() - @IsOptional() - type: string; - - @ApiPropertyOptional() - @IsOptional() - proofData: object; - - @ApiPropertyOptional() - @IsOptional() - orgId: string; - - @ApiPropertyOptional() - @IsOptional() - errorMessage: string; -} \ No newline at end of file + @ApiPropertyOptional() + @IsOptional() + _tags: IWebhookPresentationProof; + + @ApiPropertyOptional() + @IsOptional() + id: string; + + @ApiPropertyOptional() + @IsOptional() + createdAt: string; + + @ApiPropertyOptional() + @IsOptional() + protocolVersion: string; + + @ApiPropertyOptional() + @IsOptional() + state: string; + + @ApiPropertyOptional() + @IsOptional() + connectionId: string; + + @ApiPropertyOptional() + @IsOptional() + threadId: string; + + @ApiPropertyOptional() + @IsOptional() + parentThreadId?: string; + + @ApiPropertyOptional() + @IsOptional() + presentationId: string; + + @ApiPropertyOptional() + @IsOptional() + autoAcceptProof: string; + + @ApiPropertyOptional() + @IsOptional() + updatedAt: string; + + @ApiPropertyOptional() + @IsOptional() + isVerified: boolean; + + @ApiPropertyOptional() + @IsOptional() + contextCorrelationId: string; + + @ApiPropertyOptional() + @IsOptional() + type: string; + + @ApiPropertyOptional() + @IsOptional() + proofData: object; + + @ApiPropertyOptional() + @IsOptional() + orgId: string; + + @ApiPropertyOptional() + @IsOptional() + errorMessage: string; +} diff --git a/apps/api-gateway/src/verification/interfaces/verification.interface.ts b/apps/api-gateway/src/verification/interfaces/verification.interface.ts index cac18fa67..7877821fa 100644 --- a/apps/api-gateway/src/verification/interfaces/verification.interface.ts +++ b/apps/api-gateway/src/verification/interfaces/verification.interface.ts @@ -1,92 +1,84 @@ -import { IUserRequestInterface } from "../../interfaces/IUserRequestInterface"; +import { IUserRequestInterface } from '../../interfaces/IUserRequestInterface'; export interface IProofRequestAttribute { - attributeName: string; - condition?: string; - value?: string; - credDefId: string; - credentialName: string; + attributeName: string; + condition?: string; + value?: string; + credDefId: string; + credentialName: string; } export interface IProofRequestSearchCriteria { - pageNumber: number; - pageSize: number; - sortField: string; - sortBy: string; - search: string; - user?: IUserRequestInterface + pageNumber: number; + pageSize: number; + sortField: string; + sortBy: string; + search: string; + user?: IUserRequestInterface; } export interface IProofRequest { - metadata: object; - id: string; -} + metadata: object; + id: string; +} export interface IProofPresentation { - createdAt: string; - protocolVersion: string; - state: string; - connectionId: string; - threadId: string; - autoAcceptProof: string; - updatedAt: string; - isVerified: boolean; - } + createdAt: string; + protocolVersion: string; + state: string; + connectionId: string; + threadId: string; + autoAcceptProof: string; + updatedAt: string; + isVerified: boolean; +} -export interface IPresentation { - _tags: ITags; - metadata: object; - id: string; - createdAt: string; - protocolVersion: string; - state: string; - connectionId: string; - threadId: string; - autoAcceptProof: string; - updatedAt: string; - isVerified: boolean; - } +export interface IPresentation extends IProofPresentation { + _tags: ITags; + metadata: object; + id: string; +} interface ITags { - connectionId: string; - state: string; - threadId: string; -} + connectionId: string; + state: string; + threadId: string; +} export interface IProofFormats { - indy: IndyProof + indy: IndyProof; } interface IndyProof { - name: string; - version: string; - requested_attributes: IRequestedAttributes; - requested_predicates: IRequestedPredicates; + name: string; + version: string; + requested_attributes: IRequestedAttributes; + requested_predicates: IRequestedPredicates; } interface IRequestedAttributes { - [key: string]: IRequestedAttributesName; + [key: string]: IRequestedAttributesName; } interface IRequestedAttributesName { - name?: string; - names?: string; - restrictions: IRequestedRestriction[] + name?: string; + names?: string; + restrictions: IRequestedRestriction[]; } interface IRequestedPredicates { - [key: string]: IRequestedPredicatesName; + [key: string]: IRequestedPredicatesName; } interface IRequestedPredicatesName { - name: string; - restrictions: IRequestedRestriction[] + name: string; + restrictions: IRequestedRestriction[]; } interface IRequestedRestriction { - cred_def_id?: string; - schema_id?: string; - schema_issuer_did?: string; - schema_name?: string; - issuer_did?: string; - schema_version?: string; -} \ No newline at end of file + cred_def_id?: string; + schema_id?: string; + schema_issuer_did?: string; + schema_name?: string; + issuer_did?: string; + schema_version?: string; +} diff --git a/apps/connection/src/interfaces/connection.interfaces.ts b/apps/connection/src/interfaces/connection.interfaces.ts index 020e4821d..dad9de317 100644 --- a/apps/connection/src/interfaces/connection.interfaces.ts +++ b/apps/connection/src/interfaces/connection.interfaces.ts @@ -16,7 +16,7 @@ export interface IConnection { handshakeProtocols: string[]; orgId: string; recipientKey?: string; - invitationDid?: string + invitationDid?: string; } export interface IUserRequestInterface { userId: string; @@ -130,7 +130,7 @@ export interface IConnectionSearchCriteria { sortField: string; sortBy: string; searchByText: string; - user: IUserRequestInterface + user: IUserRequestInterface; } export interface AgentConnectionSearchCriteria { @@ -143,9 +143,9 @@ export interface AgentConnectionSearchCriteria { } export interface IReceiveInvitationByUrlOrg { - user: IUserRequestInterface, - receiveInvitationUrl: IReceiveInvitationUrl, - orgId: string + user: IUserRequestInterface; + receiveInvitationUrl: IReceiveInvitationUrl; + orgId: string; } export interface IReceiveInvitationUrl extends IReceiveInvite { @@ -153,9 +153,9 @@ export interface IReceiveInvitationUrl extends IReceiveInvite { } export interface IReceiveInvitationByOrg { - user: IUserRequestInterface, - receiveInvitation: IReceiveInvitation, - orgId: string + user: IUserRequestInterface; + receiveInvitation: IReceiveInvitation; + orgId: string; } interface Service { @@ -210,8 +210,8 @@ interface OutOfBandInvitationService { } interface OutOfBandInvitation { - "@type": string; - "@id": string; + '@type': string; + '@id': string; label: string; accept: string[]; handshake_protocols: string[]; @@ -266,7 +266,7 @@ export interface ConnectionResponseDetail { lastChangedDateTime: Date; lastChangedBy: number; recordId: string; - invitationDid?: string + invitationDid?: string; } export interface ICreateConnectionInvitation { @@ -289,6 +289,6 @@ export interface ICreateConnectionInvitation { } export interface ICreateOutOfbandConnectionInvitation { - user: IUserRequestInterface, - createOutOfBandConnectionInvitation: ICreateConnectionInvitation, -} \ No newline at end of file + user: IUserRequestInterface; + createOutOfBandConnectionInvitation: ICreateConnectionInvitation; +} diff --git a/apps/issuance/src/issuance.service.ts b/apps/issuance/src/issuance.service.ts index cc1e9c71c..64ea782a5 100644 --- a/apps/issuance/src/issuance.service.ts +++ b/apps/issuance/src/issuance.service.ts @@ -1501,7 +1501,7 @@ export class IssuanceService { return schemaDetails; } - async delay(ms): Promise { + async delay(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } diff --git a/apps/user/test/app.e2e-spec.ts b/apps/user/test/app.e2e-spec.ts index ab51d4a94..ae537da6c 100644 --- a/apps/user/test/app.e2e-spec.ts +++ b/apps/user/test/app.e2e-spec.ts @@ -15,10 +15,5 @@ describe('UserController (e2e)', () => { await app.init(); }); - it('/ (GET)', () => { - return request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!'); - }); + it('/ (GET)', () => request(app.getHttpServer()).get('/').expect(200).expect('Hello World!')); }); diff --git a/apps/utility/src/utilities.repository.ts b/apps/utility/src/utilities.repository.ts index 7727d1b8e..4703af487 100644 --- a/apps/utility/src/utilities.repository.ts +++ b/apps/utility/src/utilities.repository.ts @@ -1,51 +1,46 @@ -import { PrismaService } from "@credebl/prisma-service"; -import { Injectable, Logger } from "@nestjs/common"; +import { PrismaService } from '@credebl/prisma-service'; +import { Injectable, Logger } from '@nestjs/common'; // eslint-disable-next-line camelcase -import { shortening_url } from "@prisma/client"; +import { shortening_url } from '@prisma/client'; @Injectable() export class UtilitiesRepository { - constructor( - private readonly prisma: PrismaService, - private readonly logger: Logger - ) { } - - async saveShorteningUrl( - payload - ): Promise { - - try { - - const { referenceId, invitationPayload } = payload; - const storeShorteningUrl = await this.prisma.shortening_url.upsert({ - where: { referenceId }, - update: { invitationPayload }, - create: { referenceId, invitationPayload } - }); - - this.logger.log(`[saveShorteningUrl] - shortening url details ${referenceId}`); - return storeShorteningUrl; - } catch (error) { - this.logger.error(`Error in saveShorteningUrl: ${error} `); - throw error; - } + constructor( + private readonly prisma: PrismaService, + private readonly logger: Logger + ) {} + + async saveShorteningUrl(payload): Promise { + try { + const { referenceId, invitationPayload } = payload; + const storeShorteningUrl = await this.prisma.shortening_url.upsert({ + where: { referenceId }, + update: { invitationPayload }, + create: { referenceId, invitationPayload } + }); + + this.logger.log(`[saveShorteningUrl] - shortening url details ${referenceId}`); + return storeShorteningUrl; + } catch (error) { + this.logger.error(`Error in saveShorteningUrl: ${error} `); + throw error; } - - // eslint-disable-next-line camelcase - async getShorteningUrl(referenceId): Promise { - try { - - const storeShorteningUrl = await this.prisma.shortening_url.findUnique({ - where: { - referenceId - } - }); - - this.logger.log(`[getShorteningUrl] - shortening url details ${referenceId}`); - return storeShorteningUrl; - } catch (error) { - this.logger.error(`Error in getShorteningUrl: ${error} `); - throw error; + } + + // eslint-disable-next-line camelcase + async getShorteningUrl(referenceId): Promise { + try { + const storeShorteningUrl = await this.prisma.shortening_url.findUnique({ + where: { + referenceId } + }); + + this.logger.log(`[getShorteningUrl] - shortening url details ${referenceId}`); + return storeShorteningUrl; + } catch (error) { + this.logger.error(`Error in getShorteningUrl: ${error} `); + throw error; } -} \ No newline at end of file + } +} diff --git a/libs/context/src/nestjsClsContextStorageService.ts b/libs/context/src/nestjsClsContextStorageService.ts index 00107f21e..7c5593057 100644 --- a/libs/context/src/nestjsClsContextStorageService.ts +++ b/libs/context/src/nestjsClsContextStorageService.ts @@ -3,17 +3,14 @@ import { CLS_ID, ClsService } from 'nestjs-cls'; import { Injectable } from '@nestjs/common'; @Injectable() -export default class NestjsClsContextStorageService - implements ContextStorageService -{ - constructor(private readonly cls: ClsService) { - } +export default class NestjsClsContextStorageService implements ContextStorageService { + constructor(private readonly cls: ClsService) {} public get(key: string): T | undefined { return this.cls.get(key); } - public setContextId(id: string) : void { + public setContextId(id: string): void { this.cls.set(CLS_ID, id); } @@ -24,4 +21,4 @@ export default class NestjsClsContextStorageService public set(key: string, value: T): void { this.cls.set(key, value); } -} \ No newline at end of file +} diff --git a/libs/logger/src/winstonLogger.ts b/libs/logger/src/winstonLogger.ts index d2a8b0ef8..ed8004cd0 100644 --- a/libs/logger/src/winstonLogger.ts +++ b/libs/logger/src/winstonLogger.ts @@ -9,42 +9,34 @@ export const WinstonLoggerTransportsKey = Symbol(); let esTransport; if ('true' === process.env.ELK_LOG?.toLowerCase()) { const esTransportOpts = { - level: `${process.env.LOG_LEVEL}`, - clientOpts: { node: `${process.env.ELK_LOG_PATH}`, - auth: { - username: `${process.env.ELK_USERNAME}`, - password: `${process.env.ELK_PASSWORD}` - } - } -}; -esTransport = new Elasticsearch.ElasticsearchTransport(esTransportOpts); - -esTransport.on('error', (error) => { - console.error('Error caught in logger', error); -}); - + level: `${process.env.LOG_LEVEL}`, + clientOpts: { + node: `${process.env.ELK_LOG_PATH}`, + auth: { + username: `${process.env.ELK_USERNAME}`, + password: `${process.env.ELK_PASSWORD}` + } + } + }; + esTransport = new Elasticsearch.ElasticsearchTransport(esTransportOpts); } - @Injectable() export default class WinstonLogger implements Logger { private readonly logger: winston.Logger; - public constructor( - @Inject(WinstonLoggerTransportsKey) transports: winston.transport[] - ) { - if(esTransport){ + public constructor(@Inject(WinstonLoggerTransportsKey) transports: winston.transport[]) { + if (esTransport) { transports.push(esTransport); } - - + // Create winston logger this.logger = winston.createLogger(this.getLoggerFormatOptions(transports)); - } - private getLoggerFormatOptions(transports: winston.transport[]) : winston.LoggerOptions { + private getLoggerFormatOptions(transports: winston.transport[]): winston.LoggerOptions { // Setting log levels for winston + // eslint-disable-next-line @typescript-eslint/no-explicit-any const levels: any = {}; let cont = 0; Object.values(LogLevel).forEach((level) => { @@ -55,8 +47,8 @@ export default class WinstonLogger implements Logger { return { level: LogLevel.Debug, levels, - // format: ecsFormat.ecsFormat({ convertReqRes: true }), - format: winston.format.combine( + // format: ecsFormat.ecsFormat({ convertReqRes: true }), + format: winston.format.combine( ecsFormat.ecsFormat({ convertReqRes: true }), // Add timestamp and format the date // winston.format.timestamp({ @@ -65,7 +57,8 @@ export default class WinstonLogger implements Logger { // Errors will be logged with stack trace winston.format.errors({ stack: true }), // Add custom Log fields to the log - winston.format((info, opts) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + winston.format((info, _opts) => { // Info contains an Error property if (info.error && info.error instanceof Error) { info.stack = info.error.stack; @@ -82,21 +75,16 @@ export default class WinstonLogger implements Logger { fillExcept: ['timestamp', 'level', 'message'] }), // Format the log as JSON - winston.format.json(), + winston.format.json() ), transports, exceptionHandlers: transports }; } - public log( - level: LogLevel, - message: string | Error, - data?: LogData, - profile?: string - ) : void { + public log(level: LogLevel, message: string | Error, data?: LogData, profile?: string): void { const logData = { - level: level, + level, message: message instanceof Error ? message.message : message, error: message instanceof Error ? message : undefined, ...data @@ -109,34 +97,31 @@ export default class WinstonLogger implements Logger { } } - - public debug(message: string, data?: LogData, profile?: string) : void { + public debug(message: string, data?: LogData, profile?: string): void { this.log(LogLevel.Debug, message, data, profile); } - public info(message: string, data?: LogData, profile?: string) : void { + public info(message: string, data?: LogData, profile?: string): void { this.log(LogLevel.Info, message, data, profile); } - public warn(message: string | Error, data?: LogData, profile?: string) : void { + public warn(message: string | Error, data?: LogData, profile?: string): void { this.log(LogLevel.Warn, message, data, profile); } - public error(message: string | Error, data?: LogData, profile?: string) : void { + public error(message: string | Error, data?: LogData, profile?: string): void { this.log(LogLevel.Error, message, data, profile); } - public fatal(message: string | Error, data?: LogData, profile?: string) : void { + public fatal(message: string | Error, data?: LogData, profile?: string): void { this.log(LogLevel.Fatal, message, data, profile); } - public emergency(message: string | Error, data?: LogData, profile?: string) : void { + public emergency(message: string | Error, data?: LogData, profile?: string): void { this.log(LogLevel.Emergency, message, data, profile); } - public startProfile(id: string) : void { + public startProfile(id: string): void { this.logger.profile(id); } } - -