Skip to content

Commit

Permalink
Merge pull request #507 from andrechristikan/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
andrechristikan authored Feb 14, 2024
2 parents d006a7c + 8b6d4eb commit 0cedbf5
Show file tree
Hide file tree
Showing 71 changed files with 1,493 additions and 1,653 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn"
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/await-thenable": "error"
}
}
4 changes: 3 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"apikey",
"requestid",
"dtos",
"blabla"
"blabla",
"randexp",
"mediumpassword"
],
"ignorePaths": [
"node_modules/**",
Expand Down
51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ack-nestjs-boilerplate",
"version": "5.6.6",
"version": "5.7.0",
"description": "Ack NestJs Boilerplate",
"repository": {
"type": "git",
Expand Down Expand Up @@ -47,59 +47,60 @@
"rollback": "yarn rollback:email && yarn rollback:apikey && yarn rollback:user && yarn rollback:role"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.507.0",
"@aws-sdk/client-ses": "^3.507.0",
"@aws-sdk/client-s3": "^3.513.0",
"@aws-sdk/client-ses": "^3.513.0",
"@casl/ability": "^6.5.0",
"@faker-js/faker": "^8.4.0",
"@faker-js/faker": "^8.4.1",
"@joi/date": "^2.1.0",
"@nestjs/axios": "^3.0.1",
"@nestjs/common": "^10.3.1",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.3.1",
"@nestjs/axios": "^3.0.2",
"@nestjs/common": "^10.3.3",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.3.3",
"@nestjs/jwt": "^10.2.0",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/mongoose": "^10.0.4",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.3.1",
"@nestjs/schedule": "^4.0.0",
"@nestjs/swagger": "^7.2.0",
"@nestjs/terminus": "^10.2.1",
"@nestjs/throttler": "^5.1.1",
"@nestjs/platform-express": "^10.3.3",
"@nestjs/schedule": "^4.0.1",
"@nestjs/swagger": "^7.3.0",
"@nestjs/terminus": "^10.2.2",
"@nestjs/throttler": "^5.1.2",
"@ntegral/nestjs-sentry": "^4.0.1",
"@sentry/node": "^7.99.0",
"@sentry/node": "^7.101.0",
"@types/response-time": "^2.3.8",
"axios": "^1.6.7",
"bcryptjs": "^2.4.3",
"case": "^1.6.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"crypto-js": "^4.2.0",
"google-auth-library": "^9.6.2",
"google-auth-library": "^9.6.3",
"helmet": "^7.1.0",
"joi": "^17.12.1",
"moment": "^2.30.1",
"moment-timezone": "^0.5.45",
"mongoose": "^8.1.1",
"mongoose": "^8.1.2",
"nest-winston": "^1.9.4",
"nestjs-command": "^3.1.4",
"nestjs-i18n": "^10.4.0",
"passport": "^0.7.0",
"passport-headerapikey": "^1.2.2",
"passport-jwt": "^4.0.1",
"randexp": "^0.5.3",
"reflect-metadata": "^0.2.1",
"response-time": "^2.3.2",
"rotating-file-stream": "^3.2.1",
"rxjs": "^7.8.1",
"ua-parser-js": "^1.0.37",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1",
"winston-daily-rotate-file": "^5.0.0",
"xlsx": "^0.18.5",
"yargs": "^17.7.2",
"yarn": "^1.22.21"
},
"devDependencies": {
"@nestjs/cli": "^10.3.1",
"@nestjs/schematics": "^10.1.0",
"@nestjs/testing": "^10.3.1",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^10.3.3",
"@types/bcryptjs": "^2.4.6",
"@types/bytes": "^3.1.4",
"@types/cors": "^2.8.17",
Expand All @@ -110,18 +111,18 @@
"@types/lodash": "^4.14.202",
"@types/ms": "^0.7.34",
"@types/multer": "^1.4.11",
"@types/node": "^20.11.16",
"@types/node": "^20.11.17",
"@types/passport-jwt": "^4.0.1",
"@types/supertest": "^6.0.2",
"@types/ua-parser-js": "^0.7.39",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"cspell": "^8.3.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"husky": "^9.0.10",
"husky": "^9.0.11",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"supertest": "^6.3.4",
Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AppController {
userAgent,
date: newDate,
format: this.helperDateService.format(newDate),
timestamp: this.helperDateService.timestamp(newDate),
timestamp: this.helperDateService.createTimestamp(newDate),
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import {
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { HelperNumberService } from 'src/common/helper/services/helper.number.service';
import { ENUM_API_KEY_STATUS_CODE_ERROR } from 'src/common/api-key/constants/api-key.status-code.constant';
import { BadRequestError } from 'passport-headerapikey';

@Injectable()
export class ApiKeyXApiKeyGuard extends AuthGuard('x-api-key') {
constructor(private readonly helperNumberService: HelperNumberService) {
super();
}

canActivate(context: ExecutionContext) {
return super.canActivate(context);
}
Expand All @@ -35,7 +30,7 @@ export class ApiKeyXApiKeyGuard extends AuthGuard('x-api-key') {
message: 'apiKey.error.keyNeeded',
});
} else if (err) {
const statusCode: number = this.helperNumberService.create(
const statusCode: number = Number.parseInt(
err.message as string
);

Expand Down
4 changes: 2 additions & 2 deletions src/common/api-key/services/api-key.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ export class ApiKeyService implements IApiKeyService {
}

async createKey(): Promise<string> {
return this.helperStringService.random(25, {
const random: string = this.helperStringService.random(25, {
safe: false,
upperCase: true,
prefix: `${this.env}_`,
});
return `${this.env}_${random}`;
}

async createSecret(): Promise<string> {
Expand Down
2 changes: 2 additions & 0 deletions src/common/common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DATABASE_CONNECTION_NAME } from 'src/common/database/constants/database
import { ENUM_APP_ENVIRONMENT } from 'src/app/constants/app.enum.constant';
import { APP_LANGUAGE } from 'src/app/constants/app.constant';
import { PolicyModule } from 'src/common/policy/policy.module';
import { DebuggerLoggerModule } from 'src/common/debugger/debugger.logger.module';

@Module({
controllers: [],
Expand Down Expand Up @@ -149,6 +150,7 @@ import { PolicyModule } from 'src/common/policy/policy.module';
ResponseModule,
RequestModule,
PolicyModule,
DebuggerLoggerModule,
ApiKeyModule,
AuthModule.forRoot(),
],
Expand Down
17 changes: 17 additions & 0 deletions src/common/debugger/debugger.logger.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { DebuggerModule } from 'src/common/debugger/debugger.module';
import { DebuggerInterceptor } from 'src/common/debugger/interceptors/debugger.logger.interceptor';

@Module({
providers: [
{
provide: APP_INTERCEPTOR,
useClass: DebuggerInterceptor,
},
],
exports: [],
controllers: [],
imports: [DebuggerModule],
})
export class DebuggerLoggerModule {}
76 changes: 76 additions & 0 deletions src/common/debugger/interceptors/debugger.logger.interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
Injectable,
NestInterceptor,
ExecutionContext,
CallHandler,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { ConfigService } from '@nestjs/config';
import { DebuggerService } from 'src/common/debugger/services/debugger.service';
import { IRequestApp } from 'src/common/request/interfaces/request.interface';
import { Response } from 'express';

@Injectable()
export class DebuggerInterceptor implements NestInterceptor<Promise<any>> {
private readonly writeIntoFile: boolean;

constructor(
private readonly configService: ConfigService,
private readonly debuggerService: DebuggerService
) {
this.writeIntoFile = this.configService.get<boolean>(
'debugger.writeIntoFile'
);
}

async intercept(
context: ExecutionContext,
next: CallHandler
): Promise<Observable<Promise<any> | string>> {
if (context.getType() === 'http') {
const request: IRequestApp = context
.switchToHttp()
.getRequest<IRequestApp>();

console.log('aaa');

if (this.writeIntoFile) {
console.log('bbb');
this.debuggerService.info({
type: 'request',
method: request.method,
path: request.path,
originalUrl: request.originalUrl,
params: request.params,
body: request.body,
baseUrl: request.baseUrl,
query: request.query,
ip: request.ip,
hostname: request.hostname,
protocol: request.protocol,
});
}

return next.handle().pipe(
tap(() => {
console.log('ccc');
const response: Response = context
.switchToHttp()
.getResponse<Response>();

if (this.writeIntoFile) {
console.log('ddd');
this.debuggerService.info({
type: 'response',
statusCode: response.statusCode,
message: response.statusMessage,
});
}
})
);
}

return next.handle();
}
}
15 changes: 1 addition & 14 deletions src/common/debugger/services/debugger.options.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export class DebuggerOptionService implements IDebuggerOptionService {
const maxSize = this.configService.get<string>('debugger.maxSize');
const maxFiles = this.configService.get<string>('debugger.maxFiles');

const transports: Transport[] | Transport = [
new winston.transports.Console(),
];
const transports: Transport[] | Transport = [];

if (writeIntoFile) {
transports.push(
Expand All @@ -44,17 +42,6 @@ export class DebuggerOptionService implements IDebuggerOptionService {
level: 'info',
})
);
transports.push(
new DailyRotateFile({
filename: `%DATE%.log`,
dirname: `logs/${DEBUGGER_NAME}/debug`,
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: maxSize,
maxFiles: maxFiles,
level: 'debug',
})
);
}

const loggerOptions: LoggerOptions = {
Expand Down
Loading

0 comments on commit 0cedbf5

Please sign in to comment.