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

chore: apply eslint rules to ssi-abstraction files

parent d9eb3687
No related branches found
No related tags found
No related merge requests found
Showing
with 95 additions and 126 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.cjs', 'dist'],
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,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-unused-vars': 0,
'jest/no-mocks-import': 0,
'jest/expect-expect': 0,
},
},
],
};
import { Controller } from '@nestjs/common'; import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices'; import { MessagePattern } from '@nestjs/microservices';
import { AgentService } from './agent.service.js'; import { AgentService } from './agent.service.js';
@Controller('agent') @Controller('agent')
...@@ -7,7 +8,7 @@ export class AgentController { ...@@ -7,7 +8,7 @@ export class AgentController {
public constructor(private agent: AgentService) {} public constructor(private agent: AgentService) {}
@MessagePattern('info.publicDid') @MessagePattern('info.publicDid')
async publicDid() { public async publicDid() {
return { return {
id: 'test', id: 'test',
}; };
......
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { AgentController } from './agent.controller.js'; import { AgentController } from './agent.controller.js';
import { AgentService } from './agent.service.js'; import { AgentService } from './agent.service.js';
......
import type {
LedgerIds} from './utils/ledgerConfig.js';
import type {
InitConfig} from '@aries-framework/core';
import type {
IndyVdrPoolConfig} from '@aries-framework/indy-vdr';
import { AnonCredsModule } from '@aries-framework/anoncreds';
import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs';
import { AskarModule } from '@aries-framework/askar';
import { import {
Agent, Agent,
ConnectionsModule, ConnectionsModule,
CredentialsModule, CredentialsModule,
DidsModule, DidsModule,
HttpOutboundTransport, HttpOutboundTransport,
InitConfig,
KeyDidRegistrar, KeyDidRegistrar,
KeyDidResolver, KeyDidResolver,
KeyType, KeyType,
...@@ -13,30 +22,28 @@ import { ...@@ -13,30 +22,28 @@ import {
PeerDidResolver, PeerDidResolver,
TypedArrayEncoder, TypedArrayEncoder,
} from '@aries-framework/core'; } from '@aries-framework/core';
import { agentDependencies, HttpInboundTransport } from '@aries-framework/node';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs';
import { anoncreds } from '@hyperledger/anoncreds-nodejs';
import { AnonCredsModule } from '@aries-framework/anoncreds';
import { ariesAskar } from '@hyperledger/aries-askar-nodejs';
import { AskarModule } from '@aries-framework/askar';
import { indyVdr } from '@hyperledger/indy-vdr-nodejs';
import { import {
IndyVdrAnonCredsRegistry, IndyVdrAnonCredsRegistry,
IndyVdrIndyDidResolver, IndyVdrIndyDidResolver,
IndyVdrModule, IndyVdrModule,
IndyVdrPoolConfig,
IndyVdrSovDidResolver, IndyVdrSovDidResolver,
} from '@aries-framework/indy-vdr'; } from '@aries-framework/indy-vdr';
import { agentDependencies, HttpInboundTransport } from '@aries-framework/node';
import { anoncreds } from '@hyperledger/anoncreds-nodejs';
import { ariesAskar } from '@hyperledger/aries-askar-nodejs';
import { indyVdr } from '@hyperledger/indy-vdr-nodejs';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { logger } from '../globalUtils/logger.js';
import { registerPublicDids } from './ledger/register.js';
import { import {
LedgerIds,
ledgerNamespaces, ledgerNamespaces,
LEDGER_GENESIS, LEDGER_GENESIS,
} from './utils/ledgerConfig.js'; } from './utils/ledgerConfig.js';
import { AgentLogger } from './utils/logger.js'; import { AgentLogger } from './utils/logger.js';
import { registerPublicDids } from './ledger/register.js';
import { logger } from '../globalUtils/logger.js';
export type AppAgent = Agent<AgentService['modules']>; export type AppAgent = Agent<AgentService['modules']>;
......
import { Controller } from '@nestjs/common'; import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices'; import { MessagePattern } from '@nestjs/microservices';
import { ConnectionService } from './connection.service.js'; import { ConnectionService } from './connection.service.js';
@Controller('connection') @Controller('connection')
...@@ -7,7 +8,7 @@ export class ConnectionController { ...@@ -7,7 +8,7 @@ export class ConnectionController {
public constructor(private connectionService: ConnectionService) {} public constructor(private connectionService: ConnectionService) {}
@MessagePattern('connection.getAll') @MessagePattern('connection.getAll')
async getAll() { public async getAll() {
return await this.connectionService.getAll(); return this.connectionService.getAll();
} }
} }
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { AgentModule } from '../agent.module.js'; import { AgentModule } from '../agent.module.js';
import { ConnectionController } from './connection.controller.js'; import { ConnectionController } from './connection.controller.js';
import { ConnectionService } from './connection.service.js'; import { ConnectionService } from './connection.service.js';
......
import { ConnectionRecord } from '@aries-framework/core'; import type { AppAgent } from '../agent.service.js';
import type { ConnectionRecord } from '@aries-framework/core';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { AgentService, AppAgent } from '../agent.service.js';
import { AgentService } from '../agent.service.js';
@Injectable() @Injectable()
export class ConnectionService { export class ConnectionService {
......
import { logger } from '../../globalUtils/logger.js'; import type { LedgerIds } from '../utils/ledgerConfig.js';
import axios from 'axios'; import axios from 'axios';
import { logger } from '../../globalUtils/logger.js';
import { logAxiosError } from '../utils/helperFunctions.js'; import { logAxiosError } from '../utils/helperFunctions.js';
import { LedgerIds, ledgerNamespaces, NYM_URL } from '../utils/ledgerConfig.js'; import { ledgerNamespaces, NYM_URL } from '../utils/ledgerConfig.js';
type RegisterPublicDidOptions = { type RegisterPublicDidOptions = {
alias: string; alias: string;
......
import { AxiosError } from 'axios'; import type { AxiosError } from 'axios';
import { logger } from '../../globalUtils/logger.js'; import { logger } from '../../globalUtils/logger.js';
export function logAxiosError(err: AxiosError) { export function logAxiosError(err: AxiosError) {
......
import { BaseLogger, LogLevel } from '@aries-framework/core'; import { BaseLogger, LogLevel } from '@aries-framework/core';
import { logger } from '../../globalUtils/logger.js'; import { logger } from '../../globalUtils/logger.js';
export class AgentLogger extends BaseLogger { export class AgentLogger extends BaseLogger {
......
import { APP_FILTER } from '@nestjs/core';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { TerminusModule } from '@nestjs/terminus'; import { TerminusModule } from '@nestjs/terminus';
import { AgentModule } from './agent/agent.module.js';
import { ConnectionModule } from './agent/connection/connection.module.js';
import { config } from './config/config.js'; import { config } from './config/config.js';
import { validationSchema } from './config/validation.js'; import { validationSchema } from './config/validation.js';
import { HealthController } from './health/health.controller.js'; import { HealthController } from './health/health.controller.js';
import { ExceptionHandler } from './globalUtils/exception.handler.js';
import { AgentModule } from './agent/agent.module.js';
import { ConnectionModule } from './agent/connection/connection.module.js';
@Module({ @Module({
imports: [ imports: [
...@@ -21,11 +20,5 @@ import { ConnectionModule } from './agent/connection/connection.module.js'; ...@@ -21,11 +20,5 @@ import { ConnectionModule } from './agent/connection/connection.module.js';
ConnectionModule, ConnectionModule,
], ],
controllers: [HealthController], controllers: [HealthController],
// providers: [
// {
// provide: APP_FILTER,
// useClass: ExceptionHandler,
// },
// ],
}) })
export class AppModule {} export class AppModule {}
import { AutoAcceptCredential } from '@aries-framework/core'; import type { AutoAcceptCredential } from '@aries-framework/core';
import * as process from 'process';
interface Config { interface Config {
agentHost: string; agentHost: string;
......
import { Catch, RpcExceptionFilter, ArgumentsHost } from '@nestjs/common'; import type { RpcExceptionFilter } from '@nestjs/common';
import { Observable, throwError } from 'rxjs'; import type { RpcException } from '@nestjs/microservices';
import { RpcException } from '@nestjs/microservices';
import { Catch } from '@nestjs/common';
import { throwError } from 'rxjs';
@Catch() @Catch()
export class ExceptionHandler implements RpcExceptionFilter<RpcException> { export class ExceptionHandler implements RpcExceptionFilter<RpcException> {
catch(exception: RpcException, host: ArgumentsHost): Observable<any> { public catch(exception: RpcException) {
return throwError(() => exception.getError()); return throwError(() => exception.getError());
} }
} }
import winston, { Logger } from 'winston'; import type { Logger} from 'winston';
import ecsFormat from '@elastic/ecs-winston-format';
export const logger: Logger = winston.createLogger({ import { ecsFormat } from '@elastic/ecs-winston-format';
import { createLogger, transports } from 'winston';
export const logger: Logger = createLogger({
format: ecsFormat({ convertReqRes: true }), format: ecsFormat({ convertReqRes: true }),
transports: [new winston.transports.Console()], transports: [new transports.Console()],
}); });
logger.on('error', (error: Error) => { logger.on('error', (error: Error) => {
// eslint-disable-next-line no-console
console.error('Error in logger caught', error); console.error('Error in logger caught', error);
}); });
...@@ -8,7 +8,7 @@ export class HealthController { ...@@ -8,7 +8,7 @@ export class HealthController {
* @returns - OK (200) if app is running * @returns - OK (200) if app is running
*/ */
@Get() @Get()
getHealth() { public getHealth() {
return { return {
statusCode: HttpStatus.OK, statusCode: HttpStatus.OK,
message: `${new Date()}`, message: `${new Date()}`,
......
import type { MicroserviceOptions} from '@nestjs/microservices';
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions, Transport } from '@nestjs/microservices'; import { Transport } from '@nestjs/microservices';
import { AppModule } from './app.module.js'; import { AppModule } from './app.module.js';
import { config } from './config/config.js'; import { config } from './config/config.js';
async function bootstrap() { const app = await NestFactory.createMicroservice<MicroserviceOptions>(
const app = await NestFactory.createMicroservice<MicroserviceOptions>( AppModule,
AppModule, {
{ transport: Transport.NATS,
transport: Transport.NATS, options: {
options: { servers: [config().nats.url],
servers: [config().nats.url],
},
}, },
); },
);
await app.listen();
}
bootstrap(); await app.listen();
import { Injectable, NestMiddleware, HttpStatus } from '@nestjs/common'; import type { NestMiddleware} from '@nestjs/common';
import { Request, NextFunction, Response } from 'express'; import type { Request, NextFunction, Response } from 'express';
import { Injectable, HttpStatus } from '@nestjs/common';
/** /**
* Middleware that checks validity of provided params and body * Middleware that checks validity of provided params and body
...@@ -7,23 +9,13 @@ import { Request, NextFunction, Response } from 'express'; ...@@ -7,23 +9,13 @@ import { Request, NextFunction, Response } from 'express';
*/ */
@Injectable() @Injectable()
export class AgentMid implements NestMiddleware { export class AgentMid implements NestMiddleware {
use(req: Request, res: Response, next: NextFunction) { public use(req: Request, res: Response, next: NextFunction) {
const [, prop] = req.url.split('/'); const [, prop] = req.url.split('/');
if (prop === 'info') { if (prop === 'info') {
next(); next();
return; return;
} }
// const whiteListErrors = checkAll(prop, method, req.body);
// if (whiteListErrors && !whiteListErrors.success) {
// res.send({
// statusCode: HttpStatus.BAD_REQUEST,
// error: whiteListErrors.messages,
// });
// res.end();
// return;
// }
if (req.body.subMethod && !req.body.subMethod.name) { if (req.body.subMethod && !req.body.subMethod.name) {
res.send({ res.send({
statusCode: HttpStatus.BAD_REQUEST, statusCode: HttpStatus.BAD_REQUEST,
......
import { Test, TestingModule } from '@nestjs/testing'; import type { INestApplication } from '@nestjs/common';
import { INestApplication } from '@nestjs/common'; import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import request from 'supertest'; import request from 'supertest';
import AppModule from '../src/app.module';
import { AppModule } from '../src/app.module.js';
describe('DidCommController (e2e)', () => { describe('DidCommController (e2e)', () => {
let app: INestApplication; let app: INestApplication;
...@@ -18,13 +21,13 @@ describe('DidCommController (e2e)', () => { ...@@ -18,13 +21,13 @@ describe('DidCommController (e2e)', () => {
await app.close(); await app.close();
}); });
it('/v1/agent/connections/createConnection (POST)', () => { it('/v1/agent/connections/createConnection (POST)', async () => {
request(app.getHttpServer()) await request(app.getHttpServer())
.post('v1/agent/connections/createConnection') .post('v1/agent/connections/createConnection')
.expect(200); .expect(200);
}); });
it('/v1/agent/info (GET)', () => { it('/v1/agent/info (GET)', async () => {
request(app.getHttpServer()).post('v1/agent/info').expect(200); await request(app.getHttpServer()).post('v1/agent/info').expect(200);
}); });
}); });
import { Test, TestingModule } from '@nestjs/testing'; import type { INestApplication } from '@nestjs/common';
import { INestApplication } from '@nestjs/common'; import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import request from 'supertest'; import request from 'supertest';
import AppModule from '@src/app.module';
import { AppModule } from '../src/app.module.js';
describe('HealthController (e2e)', () => { describe('HealthController (e2e)', () => {
let app: INestApplication; let app: INestApplication;
......
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