mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-30 07:10:06 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a206aad8db | ||
|
|
f383cf49d5 | ||
|
|
db78ee3d8b |
Generated
+7
-7
@@ -36,7 +36,7 @@
|
|||||||
"passport-hubspot-oauth2": "^1.0.3",
|
"passport-hubspot-oauth2": "^1.0.3",
|
||||||
"passport-mailchimp": "^1.1.0",
|
"passport-mailchimp": "^1.1.0",
|
||||||
"protospack": "2.5.1",
|
"protospack": "2.5.1",
|
||||||
"protospack-v2": "3.0.0",
|
"protospack-v2": "3.1.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
@@ -8997,9 +8997,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/protospack-v2": {
|
"node_modules/protospack-v2": {
|
||||||
"version": "3.0.0",
|
"version": "3.1.1",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.0.0.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.1.1.tgz",
|
||||||
"integrity": "sha512-GEFbf8+vVaq/lA28K4nFf7bOSlghQJn/aeVnrYzh4YJUaa1+ccNz3uQs9p5OGbfjt2u/fFE5rHGEBUtueAA8KA==",
|
"integrity": "sha512-uY9hsP2oO7kar1EUUjUhVLI8VQ3seWO2+WVS0XS9vjWZPUI82k7KqB70uYB+5ws2dMSowomPjiqpQ13VNjk6ZQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
"ts-proto": "^1.112.2"
|
"ts-proto": "^1.112.2"
|
||||||
@@ -17198,9 +17198,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"protospack-v2": {
|
"protospack-v2": {
|
||||||
"version": "3.0.0",
|
"version": "3.1.1",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.0.0.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.1.1.tgz",
|
||||||
"integrity": "sha512-GEFbf8+vVaq/lA28K4nFf7bOSlghQJn/aeVnrYzh4YJUaa1+ccNz3uQs9p5OGbfjt2u/fFE5rHGEBUtueAA8KA==",
|
"integrity": "sha512-uY9hsP2oO7kar1EUUjUhVLI8VQ3seWO2+WVS0XS9vjWZPUI82k7KqB70uYB+5ws2dMSowomPjiqpQ13VNjk6ZQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
"ts-proto": "^1.112.2"
|
"ts-proto": "^1.112.2"
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@
|
|||||||
"passport-hubspot-oauth2": "^1.0.3",
|
"passport-hubspot-oauth2": "^1.0.3",
|
||||||
"passport-mailchimp": "^1.1.0",
|
"passport-mailchimp": "^1.1.0",
|
||||||
"protospack": "2.5.1",
|
"protospack": "2.5.1",
|
||||||
"protospack-v2": "3.0.0",
|
"protospack-v2": "3.1.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import { SalesforceStrategy } from './modules/oauth/passport-strategies/salesfor
|
|||||||
import { ConnectorClientConfiguration } from './clients/connector/client.config';
|
import { ConnectorClientConfiguration } from './clients/connector/client.config';
|
||||||
import { ConnectorController } from './modules/connector/connector.controller';
|
import { ConnectorController } from './modules/connector/connector.controller';
|
||||||
import { ConnectorClientService } from './clients/connector/client.service';
|
import { ConnectorClientService } from './clients/connector/client.service';
|
||||||
|
import { TermsOfUseModule } from './modules/termsOfUse/termsOfUse.module';
|
||||||
|
|
||||||
const inputClient = new InputsClientConfiguration();
|
const inputClient = new InputsClientConfiguration();
|
||||||
const outputClient = new OutputsClientConfiguration();
|
const outputClient = new OutputsClientConfiguration();
|
||||||
@@ -88,6 +89,7 @@ const connectorClient = new ConnectorClientConfiguration();
|
|||||||
}),
|
}),
|
||||||
AuthModule,
|
AuthModule,
|
||||||
PermissionsModule,
|
PermissionsModule,
|
||||||
|
TermsOfUseModule,
|
||||||
|
|
||||||
ClientsModule.register([
|
ClientsModule.register([
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Post,
|
||||||
|
Get,
|
||||||
|
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';
|
||||||
|
import { RequestUser, User } from '../../authentication/user.decorator';
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('token')
|
||||||
|
async getToken(@User({ required: true }) user: RequestUser) {
|
||||||
|
this.logger.info('/terms-of-use - get token');
|
||||||
|
|
||||||
|
return this.termsOfUseClient.getToken({ userId: user.user_id });
|
||||||
|
}
|
||||||
|
|
||||||
|
@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,40 @@
|
|||||||
|
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 {
|
||||||
|
TermsOfUseGetTokenRequest,
|
||||||
|
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 getToken(data: TermsOfUseGetTokenRequest) {
|
||||||
|
return lastValueFrom(this.termsOfUseService.TermsOfUseGetToken(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
async accept(data: TermsOfUseAcceptRequest) {
|
||||||
|
return lastValueFrom(this.termsOfUseService.TermsOfUseAccept(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,22 @@ export function EnrichErrorCode(code: string) {
|
|||||||
code,
|
code,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case ErrorCodes.TERMS_OF_USE.UP_TO_DATE:
|
||||||
|
return {
|
||||||
|
statusCode: HttpStatus.FORBIDDEN,
|
||||||
|
error: 'Não autorizado',
|
||||||
|
message: 'Você já assinou os termos de uso',
|
||||||
|
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:
|
case ErrorCodes.RATE_LIMIT:
|
||||||
return {
|
return {
|
||||||
statusCode: HttpStatus.TOO_MANY_REQUESTS,
|
statusCode: HttpStatus.TOO_MANY_REQUESTS,
|
||||||
|
|||||||
@@ -14,11 +14,17 @@ export const AUTH = {
|
|||||||
WEAK_NEW_PASSWORD: 'AUTH.WEAK_NEW_PASSWORD',
|
WEAK_NEW_PASSWORD: 'AUTH.WEAK_NEW_PASSWORD',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TERMS_OF_USE = {
|
||||||
|
UP_TO_DATE: 'TERMS_OF_USE.UP_TO_DATE',
|
||||||
|
REQUIRED: 'TERMS_OF_USE.REQUIRED',
|
||||||
|
};
|
||||||
|
|
||||||
const ErrorCodes = {
|
const ErrorCodes = {
|
||||||
UNKNOWN: 'UNKNOWN',
|
UNKNOWN: 'UNKNOWN',
|
||||||
RATE_LIMIT: 'RATE_LIMIT',
|
RATE_LIMIT: 'RATE_LIMIT',
|
||||||
INTERNAL: 'INTERNAL',
|
INTERNAL: 'INTERNAL',
|
||||||
AUTH,
|
AUTH,
|
||||||
|
TERMS_OF_USE,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ErrorCodes;
|
export default ErrorCodes;
|
||||||
|
|||||||
Reference in New Issue
Block a user