mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
FEAT: terms of use
This commit is contained in:
Generated
+7
-7
@@ -36,7 +36,7 @@
|
||||
"passport-hubspot-oauth2": "^1.0.3",
|
||||
"passport-mailchimp": "^1.1.0",
|
||||
"protospack": "2.5.1",
|
||||
"protospack-v2": "3.0.0",
|
||||
"protospack-v2": "3.1.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.5.5",
|
||||
@@ -8997,9 +8997,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/protospack-v2": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.0.0.tgz",
|
||||
"integrity": "sha512-GEFbf8+vVaq/lA28K4nFf7bOSlghQJn/aeVnrYzh4YJUaa1+ccNz3uQs9p5OGbfjt2u/fFE5rHGEBUtueAA8KA==",
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.1.0.tgz",
|
||||
"integrity": "sha512-Y4WL0PqU2L2mU6SIGMTMEKP0gj4cT2No3AYFEWMiiTfaR7u3WHQAZxk6alIkOexotaQT9YiLKBXghMwDmlh40g==",
|
||||
"dependencies": {
|
||||
"rxjs": "^7.5.5",
|
||||
"ts-proto": "^1.112.2"
|
||||
@@ -17198,9 +17198,9 @@
|
||||
}
|
||||
},
|
||||
"protospack-v2": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.0.0.tgz",
|
||||
"integrity": "sha512-GEFbf8+vVaq/lA28K4nFf7bOSlghQJn/aeVnrYzh4YJUaa1+ccNz3uQs9p5OGbfjt2u/fFE5rHGEBUtueAA8KA==",
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.1.0.tgz",
|
||||
"integrity": "sha512-Y4WL0PqU2L2mU6SIGMTMEKP0gj4cT2No3AYFEWMiiTfaR7u3WHQAZxk6alIkOexotaQT9YiLKBXghMwDmlh40g==",
|
||||
"requires": {
|
||||
"rxjs": "^7.5.5",
|
||||
"ts-proto": "^1.112.2"
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@
|
||||
"passport-hubspot-oauth2": "^1.0.3",
|
||||
"passport-mailchimp": "^1.1.0",
|
||||
"protospack": "2.5.1",
|
||||
"protospack-v2": "3.0.0",
|
||||
"protospack-v2": "3.1.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.5.5",
|
||||
|
||||
@@ -40,6 +40,7 @@ import { SalesforceStrategy } from './modules/oauth/passport-strategies/salesfor
|
||||
import { ConnectorClientConfiguration } from './clients/connector/client.config';
|
||||
import { ConnectorController } from './modules/connector/connector.controller';
|
||||
import { ConnectorClientService } from './clients/connector/client.service';
|
||||
import { TermsOfUseModule } from './modules/termsOfUse/termsOfUse.module';
|
||||
|
||||
const inputClient = new InputsClientConfiguration();
|
||||
const outputClient = new OutputsClientConfiguration();
|
||||
@@ -88,6 +89,7 @@ const connectorClient = new ConnectorClientConfiguration();
|
||||
}),
|
||||
AuthModule,
|
||||
PermissionsModule,
|
||||
TermsOfUseModule,
|
||||
|
||||
ClientsModule.register([
|
||||
{
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Post,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Headers,
|
||||
UseFilters,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { TermsOfUseAcceptRequest } from 'protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||
|
||||
import { TermsOfUseClientService } from './termsOfUse.service';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
|
||||
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
|
||||
|
||||
@ApiTags('TermsOfUse')
|
||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||
@Controller('terms-of-use')
|
||||
export class TermsOfUseController {
|
||||
logger: any;
|
||||
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
dadosferaLogger: DadosferaLogger,
|
||||
private termsOfUseClient: TermsOfUseClientService,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
@Post('accept')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async accept(@Body() body: TermsOfUseAcceptRequest, @Headers() headers) {
|
||||
this.logger.info('/terms-of-use - accept');
|
||||
|
||||
const { token } = body;
|
||||
const fingerprint = {
|
||||
ip: process.env.ENV === 'local' ? headers['x-forwarded-for'] : '0.0.0.0',
|
||||
port: process.env.ENV === 'local' ? headers['x-forwarded-port'] : '00000',
|
||||
userAgent: headers['user-agent'],
|
||||
};
|
||||
|
||||
return this.termsOfUseClient.accept({ token, fingerprint });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ClientsModule } from '@nestjs/microservices';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
|
||||
import { TermsOfUseController } from './termsOfUse.controller';
|
||||
import { TermsOfUseClientService } from './termsOfUse.service';
|
||||
|
||||
import { DucClient } from '../../clients/duc/client.config';
|
||||
const ducClient = new DucClient();
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ClientsModule.register([
|
||||
{
|
||||
name: 'DUC_PACKAGE',
|
||||
...ducClient.config(),
|
||||
},
|
||||
]),
|
||||
],
|
||||
controllers: [TermsOfUseController],
|
||||
providers: [TermsOfUseClientService, DadosferaLogger],
|
||||
exports: [TermsOfUseClientService],
|
||||
})
|
||||
export class TermsOfUseModule {}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { OnModuleInit, Inject, Injectable } from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
import { ProtoServices } from 'protospack-v2/dist/lib/Duc';
|
||||
import { TermsOfUseProtoService as TermsOfUseServiceInterface } from 'protospack-v2/dist/lib/Duc/interfaces/write-service';
|
||||
import { TermsOfUseAcceptRequest } from 'protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||
|
||||
@Injectable()
|
||||
export class TermsOfUseClientService implements OnModuleInit {
|
||||
logger: any;
|
||||
|
||||
private termsOfUseService: TermsOfUseServiceInterface;
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
dadosferaLogger: DadosferaLogger,
|
||||
@Inject('DUC_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
onModuleInit() {
|
||||
this.termsOfUseService =
|
||||
this.grpcClient.getService<TermsOfUseServiceInterface>(
|
||||
ProtoServices.TermsOfUseProtoService,
|
||||
);
|
||||
}
|
||||
|
||||
async accept(data: TermsOfUseAcceptRequest) {
|
||||
return lastValueFrom(this.termsOfUseService.TermsOfUseAccept(data));
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,14 @@ export function EnrichErrorCode(code: string) {
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.TERMS_OF_USE.REQUIRED:
|
||||
return {
|
||||
statusCode: HttpStatus.FORBIDDEN,
|
||||
error: 'Não autorizado',
|
||||
message: 'É necessário aceitar os termos de uso para prosseguir',
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.RATE_LIMIT:
|
||||
return {
|
||||
statusCode: HttpStatus.TOO_MANY_REQUESTS,
|
||||
|
||||
@@ -14,11 +14,16 @@ export const AUTH = {
|
||||
WEAK_NEW_PASSWORD: 'AUTH.WEAK_NEW_PASSWORD',
|
||||
};
|
||||
|
||||
const TERMS_OF_USE = {
|
||||
REQUIRED: 'TERMS_OF_USE.REQUIRED',
|
||||
};
|
||||
|
||||
const ErrorCodes = {
|
||||
UNKNOWN: 'UNKNOWN',
|
||||
RATE_LIMIT: 'RATE_LIMIT',
|
||||
INTERNAL: 'INTERNAL',
|
||||
AUTH,
|
||||
TERMS_OF_USE,
|
||||
};
|
||||
|
||||
export default ErrorCodes;
|
||||
|
||||
Reference in New Issue
Block a user