Skip to content
Snippets Groups Projects
Unverified Commit aff4cf76 authored by Konstantin Tsabolov's avatar Konstantin Tsabolov
Browse files

chore: apply new ESLint config to attestation-manager

parent 30b44adb
No related branches found
No related tags found
No related merge requests found
Showing
with 125 additions and 136 deletions
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2021,
},
env: {
node: true,
},
plugins: ['prettier', '@typescript-eslint/eslint-plugin', 'jest'],
extends: [
'prettier',
'plugin:@typescript-eslint/recommended',
'plugin:jest/recommended',
],
ignorePatterns: ['.eslintrc.js'],
overrides: [],
settings: {
jest: {
version: '29',
},
},
rules: {
'no-unused-vars': 0,
'@typescript-eslint/no-unused-vars': [1, { argsIgnorePattern: '^_' }],
},
overrides: [
{
files: [
'*.spec.ts',
'*.e2e-spec.ts',
'__mocks__/*.ts',
'__mocks__/**/*.ts',
],
rules: {
'@typescript-eslint/no-explicit-any': 0,
'jest/no-mocks-import': 0,
},
},
],
};
......@@ -38,6 +38,7 @@
"@prisma/client": "^5.6.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"express": "^4.17.3",
"joi": "^17.11.0",
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^3.1.0",
......@@ -63,13 +64,8 @@
"@types/jsonwebtoken": "^9.0.5",
"@types/node": "^20.9.0",
"@types/supertest": "^2.0.16",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"dotenv-cli": "^7.3.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"node-mocks-http": "^1.13.0",
......
import {
MiddlewareConsumer,
Module,
NestModule,
RequestMethod,
type MiddlewareConsumer,
type NestModule,
} from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_FILTER } from '@nestjs/core';
import { TerminusModule } from '@nestjs/terminus';
import ExceptionHandler from './common/exception.handler.js';
import config from './config/config.js';
import validationSchema from './config/validation.js';
......@@ -39,7 +40,7 @@ import UserInfoModule from './userInfo/module.js';
],
})
export default class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
public configure(consumer: MiddlewareConsumer) {
// eslint-disable-line
consumer
.apply(AuthMiddleware)
......
import { Inject, Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { lastValueFrom } from 'rxjs';
import { Connection, NATSServices } from '../common/constants.js';
@Injectable()
export default class NatsClientService {
constructor(
public constructor(
@Inject(NATSServices.SERVICE_NAME) private natsClient: ClientProxy,
) {}
getConnectionById(connectionId: string) {
public getConnectionById(connectionId: string) {
const pattern = {
endpoint: `${Connection.NATS_ENDPOINT}/${Connection.GET_CONNECTION_BY_ID}`,
};
......@@ -17,7 +18,7 @@ export default class NatsClientService {
return lastValueFrom(this.natsClient.send(pattern, payload));
}
connectionTrusted(connectionId: string) {
public connectionTrusted(connectionId: string) {
const pattern = {
endpoint: `${Connection.NATS_ENDPOINT}/${Connection.MAKE_CONNECTION_TRUSTED}`,
};
......@@ -25,7 +26,7 @@ export default class NatsClientService {
return lastValueFrom(this.natsClient.send(pattern, payload));
}
getReceivedConnections() {
public getReceivedConnections() {
const pattern = {
endpoint: `${Connection.NATS_ENDPOINT}/${Connection.GET_RECEIVED_CONNECTIONS}`,
};
......
......@@ -4,15 +4,15 @@ import { lastValueFrom, map } from 'rxjs';
@Injectable()
export default class RestClientService {
constructor(private readonly httpService: HttpService) {}
public constructor(private readonly httpService: HttpService) {}
async delete(url: string) {
public async delete(url: string) {
return lastValueFrom(
this.httpService.delete(url).pipe(map((response) => response.data)),
);
}
async post(url: string, payload: object) {
public async post(url: string, payload: object) {
return lastValueFrom(
this.httpService
.post(url, payload)
......@@ -20,7 +20,7 @@ export default class RestClientService {
);
}
async get(url: string) {
public async get(url: string) {
return lastValueFrom(
this.httpService.get(url).pipe(map((response) => response.data)),
);
......
import type { PolicyReturnType } from '../../tsa.client.js';
import { TSAService } from '../../../common/constants.js';
import { PolicyReturnType } from '../../tsa.client.js';
const TSAClientServiceMock = jest.fn().mockReturnValue({
getPolicy: jest.fn().mockImplementation((url: string) => {
......
import type { TestingModule } from '@nestjs/testing';
import { HttpModule, HttpService } from '@nestjs/axios';
import { Test, TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import HttpServiceMock from '../../tests/__mocks__/http-service.js';
import RestClientService from '../rest.client.js';
......@@ -25,7 +28,7 @@ describe('RestClientService', () => {
});
describe('post()', () => {
let restClientResponse: any;
let restClientResponse: unknown;
beforeEach(async () => {
restClientResponse = await restClient.post('test_url', {});
......
import type { ResponseType } from '../../../common/response.js';
import AttestationService from '../../../issue-credential/services/service.js';
const natsAgentResponse: ResponseType = {
......
import { Injectable } from '@nestjs/common';
import RestClientService from './rest.client.js';
export interface PolicyReturnType {
......@@ -13,9 +14,9 @@ export interface PolicyResult {
@Injectable()
export default class TSAClientService {
constructor(private readonly restClient: RestClientService) {}
public constructor(private readonly restClient: RestClientService) {}
async getPolicy(policyUrl: string) {
public async getPolicy(policyUrl: string) {
try {
const policyResponse: PolicyResult = await this.restClient.get(policyUrl);
......
import type { ResponseType } from './response.js';
import {
ArgumentsHost,
Catch,
ExceptionFilter,
HttpException,
HttpStatus,
type ArgumentsHost,
type ExceptionFilter,
} from '@nestjs/common';
import { HttpAdapterHost } from '@nestjs/core';
import { ResponseType } from './response.js';
@Catch()
export default class ExceptionHandler implements ExceptionFilter {
constructor(private readonly httpAdapterHost: HttpAdapterHost) {}
public constructor(private readonly httpAdapterHost: HttpAdapterHost) {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
catch(exception: any, host: ArgumentsHost): void {
public catch(exception: any, host: ArgumentsHost): void {
// In certain situations `httpAdapter` might not be available in the
// constructor method, thus we should resolve it here.
const { httpAdapter } = this.httpAdapterHost;
......
import type { ResponseType } from '../../common/response.js';
import type CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js';
import {
Body,
Controller,
......@@ -19,17 +22,18 @@ import {
ApiTags,
} from '@nestjs/swagger';
import { Prisma } from '@prisma/client';
import type { Response } from 'express';
import { ResponseType } from '../../common/response.js';
import { Response } from 'express';
import logger from '../../utils/logger.js';
import CredentialDefDto from '../entities/credentialDef-entity.js';
import CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js';
import CredentialDefService from '../services/service.js';
@ApiTags('Credential Definitions')
@Controller('credentialDef')
export default class CredentialDefController {
constructor(private readonly credentialDefService: CredentialDefService) {}
public constructor(
private readonly credentialDefService: CredentialDefService,
) {}
@Version(['1'])
@ApiQuery({ name: 'page', required: false })
......@@ -124,7 +128,7 @@ export default class CredentialDefController {
},
},
})
async findCredentialDef(
public async findCredentialDef(
@Query()
query: {
pageSize: string;
......@@ -244,7 +248,7 @@ export default class CredentialDefController {
},
},
})
async findCredentialDefById(
public async findCredentialDefById(
@Param('id') id: string,
@Res() response: Response,
) {
......@@ -390,7 +394,7 @@ export default class CredentialDefController {
},
},
})
async createCredentialDef(
public async createCredentialDef(
@Body() credentialDefDto: CredentialDefDto,
@Res() response: Response,
) {
......
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsNotEmpty, IsBoolean } from 'class-validator';
import { IsBoolean, IsNotEmpty, IsString } from 'class-validator';
export default class CredentialDefDto {
@IsString()
id: string;
public id: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
schemaID: string;
public schemaID: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
name: string;
public name: string;
@IsString()
credDefId: string;
public credDefId: string;
@IsBoolean()
supportRevocation?: boolean;
public supportRevocation?: boolean;
@IsBoolean()
@ApiProperty()
isRevokable: boolean;
public isRevokable: boolean;
@IsBoolean()
@ApiProperty()
isAutoIssue: boolean;
public isAutoIssue: boolean;
@IsString()
@ApiProperty()
// Number of hours of Credential validity
expiryHours: string;
public expiryHours: string;
@IsString()
@ApiProperty()
createdBy: string;
public createdBy: string;
@IsString()
createdDate: Date;
public createdDate: Date;
@IsString()
updatedBy: string;
public updatedBy: string;
@IsString()
updatedDate: Date;
public updatedDate: Date;
@IsString()
tag?: string;
public tag?: string;
@IsString()
@ApiPropertyOptional()
type?: string;
public type?: string;
}
......@@ -2,11 +2,11 @@ import { IsString, IsBoolean } from 'class-validator';
export default class CredentialDefLedgerDto {
@IsString()
schemaId: string;
public schemaId: string;
@IsBoolean()
supportRevocation?: boolean;
public supportRevocation?: boolean;
@IsString()
tag?: string;
public tag?: string;
}
......@@ -3,50 +3,50 @@ import { IsString, IsNotEmpty, IsBoolean } from 'class-validator';
export default class CredentialDefReqDto {
@IsString()
id: string;
public id: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
schemaID: string;
public schemaID: string;
@IsString()
@IsNotEmpty()
@ApiProperty()
name: string;
public name: string;
@IsString()
credDefId: string;
public credDefId: string;
@IsBoolean()
supportRevocation?: boolean;
public supportRevocation?: boolean;
@IsBoolean()
@ApiProperty()
isRevokable: boolean;
public isRevokable: boolean;
@IsBoolean()
@ApiProperty()
isAutoIssue: boolean;
public isAutoIssue: boolean;
@IsString()
@ApiProperty()
// Number of hours of Credential validity
expiryHours: string;
public expiryHours: string;
@IsString()
@ApiProperty()
createdBy: string;
public createdBy: string;
@IsString()
createdDate: Date;
public createdDate: Date;
@IsString()
updatedBy: string;
public updatedBy: string;
@IsString()
updatedDate: Date;
public updatedDate: Date;
@IsString()
tag?: string;
public tag?: string;
}
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import NatsClientService from '../client/nats.client.js';
import RestClientService from '../client/rest.client.js';
import { NATSServices } from '../common/constants.js';
import config from '../config/config.js';
import PrismaService from '../prisma/prisma.service.js';
import SchemasService from '../schemas/services/service.js';
import CredentialDefController from './controller/controller.js';
import CredentialDefService from './services/service.js';
......
import type { Prisma } from '@prisma/client';
import { Injectable } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import PrismaService from '../../prisma/prisma.service.js';
@Injectable()
export default class CredentialDefRepository {
constructor(private readonly prismaService: PrismaService) {}
public constructor(private readonly prismaService: PrismaService) {}
async createCredDef(data: Prisma.CredentialDefCreateInput) {
public async createCredDef(data: Prisma.CredentialDefCreateInput) {
const credDef = await this.prismaService.credentialDef.create({
data,
});
......@@ -27,7 +29,7 @@ export default class CredentialDefRepository {
return credDef;
}
async findCredentialDef(params: {
public async findCredentialDef(params: {
skip?: number;
take?: number;
cursor?: Prisma.CredentialDefWhereUniqueInput;
......@@ -49,7 +51,7 @@ export default class CredentialDefRepository {
]);
}
async findUniqueCredentialDef(params: {
public async findUniqueCredentialDef(params: {
where: Prisma.CredentialDefWhereUniqueInput;
}) {
const { where } = params;
......
import type SchemaDto from '../../schemas/entities/schema-entity.js';
import type CredentialDefDto from '../entities/credentialDef-entity.js';
import type CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js';
import type { Prisma } from '@prisma/client';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Prisma } from '@prisma/client';
import RestClientService from '../../client/rest.client.js';
import CredentialTypeRepository from '../../issue-credential/repository/credentialType.repository.js';
import PrismaService from '../../prisma/prisma.service.js';
import SchemaDto from '../../schemas/entities/schema-entity.js';
import SchemasService from '../../schemas/services/service.js';
import logger from '../../utils/logger.js';
import pagination from '../../utils/pagination.js';
import CredentialDefDto from '../entities/credentialDef-entity.js';
import CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js';
import CredentialDefRepository from '../repository/credentialDef.respository.js';
import CredentialTypeRepository from '../../issue-credential/repository/credentialType.repository.js';
@Injectable()
export default class CredentialDefService {
......@@ -18,7 +20,7 @@ export default class CredentialDefService {
private credentialTypeRepository: CredentialTypeRepository;
constructor(
public constructor(
private readonly prismaService: PrismaService,
private readonly restClient: RestClientService,
private readonly configService: ConfigService,
......@@ -33,7 +35,7 @@ export default class CredentialDefService {
);
}
async createCredDef(credentialDefDtoPar: CredentialDefDto) {
public async createCredDef(credentialDefDtoPar: CredentialDefDto) {
const credentialDefDto: CredentialDefDto = credentialDefDtoPar;
const schema = await this.schemaService.findBySchemaId(
credentialDefDto.schemaID,
......@@ -73,7 +75,11 @@ export default class CredentialDefService {
return this.credentialDefRepository.createCredDef(credentialDefDto);
}
async findCredentialDef(pageSize: number, page: number, getSchemaID: string) {
public async findCredentialDef(
pageSize: number,
page: number,
getSchemaID: string,
) {
let query: {
skip?: number;
take?: number;
......@@ -90,7 +96,7 @@ export default class CredentialDefService {
return this.credentialDefRepository.findCredentialDef(query);
}
async findCredentialDefBySchemaIdAndCredDefId(data: {
public async findCredentialDefBySchemaIdAndCredDefId(data: {
schemaID: string;
credDefId: string;
}) {
......@@ -99,7 +105,7 @@ export default class CredentialDefService {
});
}
async findCredentialDefBySchemaIdDesc(data: { schemaID: string }) {
public async findCredentialDefBySchemaIdDesc(data: { schemaID: string }) {
return this.credentialDefRepository.findCredentialDef({
where: data,
orderBy: {
......@@ -108,13 +114,13 @@ export default class CredentialDefService {
});
}
async findCredentialDefById(id: string) {
public async findCredentialDefById(id: string) {
return this.credentialDefRepository.findCredentialDef({
where: { credDefId: id },
});
}
async checkCredDefByNameAndSchemaID(createSchema: CredentialDefDto) {
public async checkCredDefByNameAndSchemaID(createSchema: CredentialDefDto) {
return this.credentialDefRepository.findCredentialDef({
where: {
schemaID: {
......@@ -127,7 +133,7 @@ export default class CredentialDefService {
});
}
async createCredDefOnLedger(credentialDefDto: CredentialDefLedgerDto) {
public async createCredDefOnLedger(credentialDefDto: CredentialDefLedgerDto) {
const agentUrl = this.configService.get('agent.AGENT_URL');
return this.restClient.post(
`${agentUrl}/credential-definitions/`,
......
import type { TestingModule } from '@nestjs/testing';
import type { Response } from 'express';
import { HttpStatus } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { Response } from 'express';
import httpMocks from 'node-mocks-http';
import { Test } from '@nestjs/testing';
import { createResponse } from 'node-mocks-http';
import CredentialDefController from '../controller/controller.js';
import CredentialDefService from '../services/service.js';
import CredentialDefServiceMock from './__mocks__/service.js';
import credDefStub from './stubs/credDef.stub.js';
......@@ -41,7 +45,7 @@ describe('CredentialDefController', () => {
page: string;
schemaID: string;
};
let credDefResponse: Response<string, Record<string, any>>;
let credDefResponse: Response<string, Record<string, unknown>>;
beforeEach(async () => {
query = {
......@@ -50,7 +54,7 @@ describe('CredentialDefController', () => {
schemaID: credDefStub().schemaID,
};
const response = httpMocks.createResponse();
const response = createResponse();
credDefResponse = await credentialDefController.findCredentialDef(
query,
response,
......@@ -78,12 +82,12 @@ describe('CredentialDefController', () => {
describe('findCredentialDefById()', () => {
let credDefID: string;
let credDef: Response<string, Record<string, any>>;
let credDef: Response<string, Record<string, unknown>>;
beforeEach(async () => {
credDefID = credDefStub().id;
const response = httpMocks.createResponse();
const response = createResponse();
credDef = await credentialDefController.findCredentialDefById(
credDefID,
response,
......@@ -107,10 +111,10 @@ describe('CredentialDefController', () => {
});
describe('createCredDef()', () => {
let credDef: Response<string, Record<string, any>>;
let credDef: Response<string, Record<string, unknown>>;
beforeEach(async () => {
const response = httpMocks.createResponse();
const response = createResponse();
credDef = await credentialDefController.createCredentialDef(
credDefStub(),
response,
......
import type { TestingModule } from '@nestjs/testing';
import { HttpModule } from '@nestjs/axios';
import { Test, TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import NatsClientService from '../../client/nats.client.js';
import RestClientService from '../../client/rest.client.js';
import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js';
......@@ -8,6 +11,7 @@ import PrismaService from '../../prisma/prisma.service.js';
import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js';
import CredentialDefModule from '../module.js';
import CredentialDefService from '../services/service.js';
import CredentialDefServiceMock from './__mocks__/service.js';
describe('CredentialDefModule', () => {
......
import type { TestingModule } from '@nestjs/testing';
import type { CredentialDef } from '@prisma/client';
import { HttpModule } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { CredentialDef } from '@prisma/client';
import { Test } from '@nestjs/testing';
import NatsClientService from '../../client/nats.client.js';
import RestClientService from '../../client/rest.client.js';
import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js';
......@@ -11,6 +14,7 @@ import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js';
import SchemasService from '../../schemas/services/service.js';
import SchemasServiceMock from '../../schemas/tests/__mocks__/service.js';
import CredentialDefService from '../services/service.js';
import credDefStub from './stubs/credDef.stub.js';
describe('CredentialDefService', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment