mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-30 03:50:04 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a83f91a720 | ||
|
|
ccef7628f9 | ||
|
|
a5e424c854 | ||
|
|
7dfa10d5ee | ||
|
|
c87ceec77b | ||
|
|
3b95032554 | ||
|
|
a0089b5d5d | ||
|
|
1eb76d4b1c | ||
|
|
314bc5a562 | ||
|
|
d01b0357ed | ||
|
|
a206aad8db | ||
|
|
9d10e58b1b | ||
|
|
6dec2c1e56 | ||
|
|
23a65d18a6 | ||
|
|
13072978f5 | ||
|
|
e7b37629a1 | ||
|
|
5b6994b247 | ||
|
|
f383cf49d5 | ||
|
|
db78ee3d8b | ||
|
|
04e1e1ff2b | ||
|
|
d309c20cbf | ||
|
|
03d42df3fd | ||
|
|
395db05b05 | ||
|
|
2d69e6db70 | ||
|
|
9514134db1 | ||
|
|
0c69cebca1 | ||
|
|
9791b8bdb0 | ||
|
|
6803ab3420 | ||
|
|
6aa7be98d2 | ||
|
|
8d23eaeea2 |
Binary file not shown.
Binary file not shown.
Generated
+16
-14
@@ -35,8 +35,8 @@
|
|||||||
"passport-google-oauth20": "^2.0.0",
|
"passport-google-oauth20": "^2.0.0",
|
||||||
"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.2",
|
||||||
"protospack-v2": "3.0.0",
|
"protospack-v2": "3.4.0",
|
||||||
"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",
|
||||||
@@ -8989,18 +8989,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/protospack": {
|
"node_modules/protospack": {
|
||||||
"version": "2.5.1",
|
"version": "2.5.2",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack/-/protospack-2.5.1.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack/-/protospack-2.5.2.tgz",
|
||||||
"integrity": "sha512-4JTx7B7WxpC1G3S8T7SUEAEgVM9UjdYrOG37fr42wKxl9y6wOyCZJYjG/lXeAqFXOEPj9KSlM+MqBfLIMHWHeA==",
|
"integrity": "sha512-t7NyWE4WDuAVixjL10SDUXHu8iW4H0azndTC3n/w335D/IodPgN47ebm3iMXbvoQTlQcCbjjc+HblaRa9oR8bA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"rxjs": "^7.5.5"
|
"rxjs": "^7.5.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/protospack-v2": {
|
"node_modules/protospack-v2": {
|
||||||
"version": "3.0.0",
|
"version": "3.4.0",
|
||||||
"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.4.0.tgz",
|
||||||
"integrity": "sha512-GEFbf8+vVaq/lA28K4nFf7bOSlghQJn/aeVnrYzh4YJUaa1+ccNz3uQs9p5OGbfjt2u/fFE5rHGEBUtueAA8KA==",
|
"integrity": "sha512-KJZR0HtzUaBQnsdWzn4J6IqMUtceeO5gV41hdLrS1EbTKwn2A2EsbcOGQRm4/8kPzU2i4pe9o6zKTR3xCvWavw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
"ts-proto": "^1.112.2"
|
"ts-proto": "^1.112.2"
|
||||||
}
|
}
|
||||||
@@ -17190,18 +17191,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"protospack": {
|
"protospack": {
|
||||||
"version": "2.5.1",
|
"version": "2.5.2",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack/-/protospack-2.5.1.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack/-/protospack-2.5.2.tgz",
|
||||||
"integrity": "sha512-4JTx7B7WxpC1G3S8T7SUEAEgVM9UjdYrOG37fr42wKxl9y6wOyCZJYjG/lXeAqFXOEPj9KSlM+MqBfLIMHWHeA==",
|
"integrity": "sha512-t7NyWE4WDuAVixjL10SDUXHu8iW4H0azndTC3n/w335D/IodPgN47ebm3iMXbvoQTlQcCbjjc+HblaRa9oR8bA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"rxjs": "^7.5.5"
|
"rxjs": "^7.5.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"protospack-v2": {
|
"protospack-v2": {
|
||||||
"version": "3.0.0",
|
"version": "3.4.0",
|
||||||
"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.4.0.tgz",
|
||||||
"integrity": "sha512-GEFbf8+vVaq/lA28K4nFf7bOSlghQJn/aeVnrYzh4YJUaa1+ccNz3uQs9p5OGbfjt2u/fFE5rHGEBUtueAA8KA==",
|
"integrity": "sha512-KJZR0HtzUaBQnsdWzn4J6IqMUtceeO5gV41hdLrS1EbTKwn2A2EsbcOGQRm4/8kPzU2i4pe9o6zKTR3xCvWavw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
"ts-proto": "^1.112.2"
|
"ts-proto": "^1.112.2"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -50,8 +50,8 @@
|
|||||||
"passport-google-oauth20": "^2.0.0",
|
"passport-google-oauth20": "^2.0.0",
|
||||||
"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.2",
|
||||||
"protospack-v2": "3.0.0",
|
"protospack-v2": "3.4.0",
|
||||||
"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",
|
||||||
|
|||||||
+10
-14
@@ -1,12 +1,11 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ClientsModule } from '@nestjs/microservices';
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { DadosferaLogger } from 'dadosfera-logs';
|
|
||||||
|
|
||||||
import { InputsController } from './modules/inputs/inputs.controller';
|
import { InputsController } from './modules/inputs/inputs.controller';
|
||||||
import { TransformationsController } from './modules/transformations/transformations.controller';
|
import { TransformationsController } from './modules/transformations/transformations.controller';
|
||||||
import { OutputsController } from './modules/outputs/outputs.controllers';
|
import { OutputsController } from './modules/outputs/outputs.controllers';
|
||||||
import { PipelinesController } from './modules/pipelines/pipelines.controller';
|
import { PipelinesController } from './modules/pipelines/pipelines.controller';
|
||||||
|
import { AuthController } from './modules/auth/auth.controller';
|
||||||
import { HealthController } from './modules/health/health.controller';
|
import { HealthController } from './modules/health/health.controller';
|
||||||
|
|
||||||
import { InputsService } from './modules/inputs/inputs.service';
|
import { InputsService } from './modules/inputs/inputs.service';
|
||||||
@@ -15,12 +14,10 @@ import { OutputsService } from './modules/outputs/outputs.service';
|
|||||||
import { PipelinesService } from './modules/pipelines/pipelines.service';
|
import { PipelinesService } from './modules/pipelines/pipelines.service';
|
||||||
import { HealthService } from './modules/health/health.service';
|
import { HealthService } from './modules/health/health.service';
|
||||||
|
|
||||||
import { AuthModule } from './modules/auth/auth.module';
|
|
||||||
import { InputsClientService } from './clients/inputs/client.service';
|
import { InputsClientService } from './clients/inputs/client.service';
|
||||||
import { TransformationsClientService } from './clients/transformations/client.service';
|
import { TransformationsClientService } from './clients/transformations/client.service';
|
||||||
import { OutputsClientService } from './clients/outputs/client.service';
|
import { OutputsClientService } from './clients/outputs/client.service';
|
||||||
import { PipelinesClientService } from './clients/pipelines/client.service';
|
import { PipelinesClientService } from './clients/pipelines/client.service';
|
||||||
import { PermissionsModule } from './modules/permissions/permissions.module';
|
|
||||||
|
|
||||||
import { OutputsClientConfiguration } from './clients/outputs/client.config';
|
import { OutputsClientConfiguration } from './clients/outputs/client.config';
|
||||||
import { TransformationsClientConfiguration } from './clients/transformations/client.config';
|
import { TransformationsClientConfiguration } from './clients/transformations/client.config';
|
||||||
@@ -37,15 +34,18 @@ import { APP_GUARD } from '@nestjs/core';
|
|||||||
import { GoogleStrategy } from './modules/oauth/passport-strategies/google-strategy';
|
import { GoogleStrategy } from './modules/oauth/passport-strategies/google-strategy';
|
||||||
import { MailChimpStrategy } from './modules/oauth/passport-strategies/mailchimp-strategy';
|
import { MailChimpStrategy } from './modules/oauth/passport-strategies/mailchimp-strategy';
|
||||||
import { SalesforceStrategy } from './modules/oauth/passport-strategies/salesforce-strategy';
|
import { SalesforceStrategy } from './modules/oauth/passport-strategies/salesforce-strategy';
|
||||||
import { ConnectorClientConfiguration } from './clients/connector/client.config';
|
|
||||||
import { ConnectorController } from './modules/connector/connector.controller';
|
import { ConnectorModule } from './modules/connector/connector.module';
|
||||||
import { ConnectorClientService } from './clients/connector/client.service';
|
import { AuthModule } from './modules/auth/auth.module';
|
||||||
|
import { PermissionsModule } from './modules/permissions/permissions.module';
|
||||||
|
|
||||||
|
import { DadosferaLogger } from 'dadosfera-logs';
|
||||||
|
import { TermsOfUseModule } from './modules/termsOfUse/termsOfUse.module';
|
||||||
|
|
||||||
const inputClient = new InputsClientConfiguration();
|
const inputClient = new InputsClientConfiguration();
|
||||||
const outputClient = new OutputsClientConfiguration();
|
const outputClient = new OutputsClientConfiguration();
|
||||||
const pipelineClient = new PipelinesClientConfiguration();
|
const pipelineClient = new PipelinesClientConfiguration();
|
||||||
const transformationClient = new TransformationsClientConfiguration();
|
const transformationClient = new TransformationsClientConfiguration();
|
||||||
const connectorClient = new ConnectorClientConfiguration();
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [
|
controllers: [
|
||||||
@@ -56,7 +56,6 @@ const connectorClient = new ConnectorClientConfiguration();
|
|||||||
HealthController,
|
HealthController,
|
||||||
CatalogController,
|
CatalogController,
|
||||||
OauthController,
|
OauthController,
|
||||||
ConnectorController,
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
DadosferaLogger,
|
DadosferaLogger,
|
||||||
@@ -65,7 +64,6 @@ const connectorClient = new ConnectorClientConfiguration();
|
|||||||
TransformationsService,
|
TransformationsService,
|
||||||
OutputsService,
|
OutputsService,
|
||||||
PipelinesService,
|
PipelinesService,
|
||||||
ConnectorClientService,
|
|
||||||
HealthService,
|
HealthService,
|
||||||
InputsClientService,
|
InputsClientService,
|
||||||
TransformationsClientService,
|
TransformationsClientService,
|
||||||
@@ -86,8 +84,10 @@ const connectorClient = new ConnectorClientConfiguration();
|
|||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
}),
|
}),
|
||||||
|
ConnectorModule,
|
||||||
AuthModule,
|
AuthModule,
|
||||||
PermissionsModule,
|
PermissionsModule,
|
||||||
|
TermsOfUseModule,
|
||||||
|
|
||||||
ClientsModule.register([
|
ClientsModule.register([
|
||||||
{
|
{
|
||||||
@@ -106,10 +106,6 @@ const connectorClient = new ConnectorClientConfiguration();
|
|||||||
name: 'PIPELINES_PACKAGE',
|
name: 'PIPELINES_PACKAGE',
|
||||||
...pipelineClient.config(),
|
...pipelineClient.config(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'CONNECTOR_PACKAGE',
|
|
||||||
...connectorClient.config(),
|
|
||||||
},
|
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,307 +0,0 @@
|
|||||||
import {
|
|
||||||
OnModuleInit,
|
|
||||||
Inject,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { DadosferaLogger } from 'dadosfera-logs';
|
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
|
||||||
import { ConnectorManager } from 'protospack-v2';
|
|
||||||
import { from } from 'rxjs';
|
|
||||||
|
|
||||||
export class ConnectorClientService implements OnModuleInit {
|
|
||||||
private connectorServiceRead: ConnectorManager.ReadService.ConnectorManagerReadServices;
|
|
||||||
private connectorServiceWrite: ConnectorManager.WriteService.ConnectorManagerWriteServices;
|
|
||||||
logger: any;
|
|
||||||
constructor(
|
|
||||||
@Inject(DadosferaLogger)
|
|
||||||
dadosferaLogger: DadosferaLogger,
|
|
||||||
@Inject('CONNECTOR_PACKAGE') private readonly grpcClient: ClientGrpc,
|
|
||||||
) {
|
|
||||||
this.logger = dadosferaLogger.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
onModuleInit() {
|
|
||||||
this.connectorServiceWrite =
|
|
||||||
this.grpcClient.getService<ConnectorManager.WriteService.ConnectorManagerWriteServices>(
|
|
||||||
ConnectorManager.ProtoServices.ConnectorManagerWriteServices,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.connectorServiceRead =
|
|
||||||
this.grpcClient.getService<ConnectorManager.ReadService.ConnectorManagerReadServices>(
|
|
||||||
ConnectorManager.ProtoServices.ConnectorManagerReadServices,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async uploadConnector(uploadConnector) {
|
|
||||||
const connector: ConnectorManager.Entities.ConnectorCreateRequest = {
|
|
||||||
file: {
|
|
||||||
buffer: uploadConnector.file.buffer,
|
|
||||||
mimetypes: uploadConnector.file.mimetype,
|
|
||||||
},
|
|
||||||
connector: JSON.stringify(uploadConnector.connector),
|
|
||||||
};
|
|
||||||
const serviceBody: ConnectorManager.Messages.RegisterConnectorRequest = {
|
|
||||||
connector,
|
|
||||||
};
|
|
||||||
|
|
||||||
const observable = from(
|
|
||||||
this.connectorServiceWrite.RegisterConnector(serviceBody),
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
observable.subscribe({
|
|
||||||
next(x) {
|
|
||||||
resolve(x);
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
//console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err.details);
|
|
||||||
this.logger.error(err);
|
|
||||||
throw new HttpException(
|
|
||||||
err.details,
|
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('ConnectorClientService - Upload');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async uploadFile(uploadFile) {
|
|
||||||
const body: ConnectorManager.Messages.UploadFileRequest = {
|
|
||||||
file: {
|
|
||||||
buffer: uploadFile.file.buffer,
|
|
||||||
mimetypes: uploadFile.file.mimetype,
|
|
||||||
},
|
|
||||||
name: uploadFile.name,
|
|
||||||
};
|
|
||||||
|
|
||||||
const observable = from(this.connectorServiceWrite.UploadFile(body));
|
|
||||||
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
observable.subscribe({
|
|
||||||
next(x) {
|
|
||||||
resolve(x);
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
//console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err.details);
|
|
||||||
this.logger.error(err);
|
|
||||||
throw new HttpException(
|
|
||||||
err.details,
|
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('ConnectorClientService - Upload');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getAllConnectors(body) {
|
|
||||||
const observable = from(
|
|
||||||
this.connectorServiceRead.GetAllConnectors({
|
|
||||||
search: body.search,
|
|
||||||
filters: JSON.stringify(body.filters),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
observable.subscribe({
|
|
||||||
next(x) {
|
|
||||||
resolve(x);
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
//console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err);
|
|
||||||
throw new HttpException(
|
|
||||||
err.details,
|
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('ConnectorClientService - getAllConnectors');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getConnectorDetails(plugin: string) {
|
|
||||||
const observable = from(
|
|
||||||
this.connectorServiceRead.GetConnectorDetails({
|
|
||||||
plugin,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
observable.subscribe({
|
|
||||||
next(x) {
|
|
||||||
resolve(x);
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
//console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err);
|
|
||||||
throw new HttpException(
|
|
||||||
err.details,
|
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('ConnectorClientService - getAllConnectors');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getConnector(plugin: string) {
|
|
||||||
const observable = from(
|
|
||||||
this.connectorServiceRead.GetConnector({
|
|
||||||
plugin,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
observable.subscribe({
|
|
||||||
next(x) {
|
|
||||||
resolve(x);
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
//console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err);
|
|
||||||
throw new HttpException(
|
|
||||||
err.details,
|
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('ConnectorClientService - getAllConnectors');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteConnector(plugin: string, version: string) {
|
|
||||||
const observable = from(
|
|
||||||
this.connectorServiceWrite.DeleteConnector({
|
|
||||||
version,
|
|
||||||
plugin,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
observable.subscribe({
|
|
||||||
next(x) {
|
|
||||||
resolve(x);
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
//console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err);
|
|
||||||
throw new HttpException(
|
|
||||||
err.details,
|
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('ConnectorClientService - getAllConnectors');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateConnector({ plugin, changes }) {
|
|
||||||
const observable = from(
|
|
||||||
this.connectorServiceWrite.UpdateConnector({
|
|
||||||
plugin,
|
|
||||||
changes,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const result = await new Promise((resolve, reject) => {
|
|
||||||
observable.subscribe({
|
|
||||||
next(x) {
|
|
||||||
resolve(x);
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
//console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err);
|
|
||||||
throw new HttpException(
|
|
||||||
err.details,
|
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('ConnectorClientService - getAllConnectors');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
import { credentials } from '@grpc/grpc-js';
|
import { credentials } from '@grpc/grpc-js';
|
||||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||||
import {
|
import { ProtoPackages, ProtoPaths } from 'protospack-v2/dist/lib/Duc';
|
||||||
ProtoPackages,
|
|
||||||
ProtoPaths,
|
|
||||||
} from 'protospack-v2/dist/lib/Duc';
|
|
||||||
|
|
||||||
export class DucClient {
|
export class DucClient {
|
||||||
config(): ClientOptions {
|
config(): ClientOptions {
|
||||||
@@ -12,6 +9,7 @@ export class DucClient {
|
|||||||
options: {
|
options: {
|
||||||
url: process.env.DUC_URL,
|
url: process.env.DUC_URL,
|
||||||
package: ProtoPackages.WritePackage,
|
package: ProtoPackages.WritePackage,
|
||||||
|
// credentials: credentials.createSsl(),
|
||||||
credentials: process.env.LOCAL_ENV
|
credentials: process.env.LOCAL_ENV
|
||||||
? undefined
|
? undefined
|
||||||
: credentials.createSsl(),
|
: credentials.createSsl(),
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ export class ConnectorClientConfiguration {
|
|||||||
ConnectorManager.ProtoPackages.WritePackage,
|
ConnectorManager.ProtoPackages.WritePackage,
|
||||||
ConnectorManager.ProtoPackages.ReadPackage,
|
ConnectorManager.ProtoPackages.ReadPackage,
|
||||||
],
|
],
|
||||||
credentials:
|
// credentials: undefined,
|
||||||
process.env.LOCAL_ENV === 'local'
|
credentials: process.env.LOCAL_ENV
|
||||||
? undefined
|
? undefined
|
||||||
: credentials.createSsl(),
|
: credentials.createSsl(),
|
||||||
protoPath: [
|
protoPath: [
|
||||||
ConnectorManager.ProtoPaths.WriteFilePath,
|
ConnectorManager.ProtoPaths.WriteFilePath,
|
||||||
ConnectorManager.ProtoPaths.ReadFilePath,
|
ConnectorManager.ProtoPaths.ReadFilePath,
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
import {
|
||||||
|
OnModuleInit,
|
||||||
|
Inject,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
|
import { ConnectorManager } from 'protospack-v2';
|
||||||
|
import { lastValueFrom } from 'rxjs';
|
||||||
|
|
||||||
|
export class ConnectorClientService implements OnModuleInit {
|
||||||
|
private connectorServiceRead: ConnectorManager.ReadService.ConnectorManagerReadServices;
|
||||||
|
private connectorServiceWrite: ConnectorManager.WriteService.ConnectorManagerWriteServices;
|
||||||
|
constructor(
|
||||||
|
@Inject('CONNECTOR_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
onModuleInit() {
|
||||||
|
this.connectorServiceWrite =
|
||||||
|
this.grpcClient.getService<ConnectorManager.WriteService.ConnectorManagerWriteServices>(
|
||||||
|
ConnectorManager.ProtoServices.ConnectorManagerWriteServices,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.connectorServiceRead =
|
||||||
|
this.grpcClient.getService<ConnectorManager.ReadService.ConnectorManagerReadServices>(
|
||||||
|
ConnectorManager.ProtoServices.ConnectorManagerReadServices,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadConnector(uploadConnector) {
|
||||||
|
const connector: ConnectorManager.Entities.ConnectorCreateRequest = {
|
||||||
|
file: {
|
||||||
|
buffer: uploadConnector.file.buffer,
|
||||||
|
mimetypes: uploadConnector.file.mimetype,
|
||||||
|
},
|
||||||
|
connector: JSON.stringify(uploadConnector.connector),
|
||||||
|
};
|
||||||
|
const serviceBody: ConnectorManager.Messages.RegisterConnectorRequest = {
|
||||||
|
connector,
|
||||||
|
};
|
||||||
|
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectorServiceWrite.RegisterConnector(serviceBody),
|
||||||
|
).catch((err) => {
|
||||||
|
console.log(err.details);
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadFile(uploadFile) {
|
||||||
|
const body: ConnectorManager.Messages.UploadFileRequest = {
|
||||||
|
file: {
|
||||||
|
buffer: uploadFile.file.buffer,
|
||||||
|
mimetypes: uploadFile.file.mimetype,
|
||||||
|
},
|
||||||
|
name: uploadFile.name,
|
||||||
|
};
|
||||||
|
|
||||||
|
return lastValueFrom(this.connectorServiceWrite.UploadFile(body)).catch(
|
||||||
|
(err) => {
|
||||||
|
console.log(err.details);
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadConnectorsFile(uploadFile) {
|
||||||
|
const connectors = JSON.parse(uploadFile.file.buffer.toString('utf8'));
|
||||||
|
|
||||||
|
const body = connectors.map((connector) => {
|
||||||
|
return JSON.stringify(connector);
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = {
|
||||||
|
connectors: body,
|
||||||
|
};
|
||||||
|
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectorServiceWrite.RegisterMultipleConnectorsWithoutImage(
|
||||||
|
request,
|
||||||
|
),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllConnectors(body) {
|
||||||
|
const meta = new Metadata();
|
||||||
|
meta.add('Language', body.language);
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectorServiceRead.GetAllConnectors(
|
||||||
|
{
|
||||||
|
search: body.search,
|
||||||
|
filters: JSON.stringify(body.filters),
|
||||||
|
language: body.language,
|
||||||
|
page: body.page,
|
||||||
|
size: body.size,
|
||||||
|
},
|
||||||
|
meta,
|
||||||
|
),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getConnectorDetails(plugin: string, language: string) {
|
||||||
|
const meta = new Metadata();
|
||||||
|
meta.add('Language', language);
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectorServiceRead.GetConnectorDetails(
|
||||||
|
{
|
||||||
|
plugin,
|
||||||
|
},
|
||||||
|
meta,
|
||||||
|
),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getConnector(plugin: string, language: string) {
|
||||||
|
const meta = new Metadata();
|
||||||
|
meta.add('Language', language);
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectorServiceRead.GetConnector(
|
||||||
|
{
|
||||||
|
plugin,
|
||||||
|
},
|
||||||
|
meta,
|
||||||
|
),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getConnectorsTags() {
|
||||||
|
return lastValueFrom(this.connectorServiceRead.GetConnectorsTags({})).catch(
|
||||||
|
(err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteConnector(plugin: string, version: string) {
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectorServiceWrite.DeleteConnector({
|
||||||
|
version,
|
||||||
|
plugin,
|
||||||
|
}),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateConnector({ plugin, changes }) {
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectorServiceWrite.UpdateConnector({
|
||||||
|
plugin,
|
||||||
|
changes,
|
||||||
|
}),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,21 +11,29 @@ import {
|
|||||||
UploadedFile,
|
UploadedFile,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
Inject,
|
Inject,
|
||||||
|
Headers,
|
||||||
|
UploadedFiles,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
|
||||||
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
||||||
import { ConnectorClientService } from 'src/clients/connector/client.service';
|
import { ConnectorClientService } from './client.service';
|
||||||
import { AddTagDto } from './dtos/add-tag';
|
import { AddTagDto } from './dtos/add-tag';
|
||||||
import { CreateConnectorDto } from './dtos/create-connector';
|
import { CreateConnectorDto } from './dtos/create-connector';
|
||||||
|
import { UploadConnectorsFileDto } from './dtos/create-multiple-connector';
|
||||||
import { DeleteConnectorDto } from './dtos/delete-connector';
|
import { DeleteConnectorDto } from './dtos/delete-connector';
|
||||||
import { GetAllDto } from './dtos/get-all';
|
import { GetAllDto } from './dtos/get-all';
|
||||||
import { RemoveTagDto } from './dtos/remove-tag';
|
import { RemoveTagDto } from './dtos/remove-tag';
|
||||||
import { UpdateDto } from './dtos/update';
|
import { UpdateDto } from './dtos/update';
|
||||||
import { UploadFileDto } from './dtos/upload-file';
|
|
||||||
import { DadosferaLogger } from 'dadosfera-logs';
|
import { DadosferaLogger } from 'dadosfera-logs';
|
||||||
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/authentication/authentication.decorator';
|
||||||
|
import { Permissions } from 'src/authentication/permissions.enum';
|
||||||
|
|
||||||
@ApiTags('connectors')
|
@ApiTags('connectors')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
|
@Authenticated()
|
||||||
@Controller('connectors')
|
@Controller('connectors')
|
||||||
export class ConnectorController {
|
export class ConnectorController {
|
||||||
logger: any;
|
logger: any;
|
||||||
@@ -38,6 +46,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
async uploadConnector(
|
async uploadConnector(
|
||||||
@@ -54,29 +63,53 @@ export class ConnectorController {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/upload')
|
@Post('/uploads')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.CREATE)
|
||||||
|
@ApiConsumes('multipart/form-data')
|
||||||
|
@UseInterceptors(FilesInterceptor('files'))
|
||||||
|
async uploadFile(@UploadedFiles() files) {
|
||||||
|
this.logger.info('/upload - Upload Connector Route');
|
||||||
|
const promises = files.map(async (file) => {
|
||||||
|
return await this.connectorClientService.uploadFile({
|
||||||
|
file,
|
||||||
|
name: file.originalname.split('.')[0],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await Promise.all(promises);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('/multiple-connectors-upload')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
async uploadFile(@UploadedFile() file, @Body() { name }: UploadFileDto) {
|
async uploadConnectorsFile(@UploadedFile() file: UploadConnectorsFileDto) {
|
||||||
this.logger.info('/upload - Upload Connector Route');
|
console.log(`/upload`, 'Upload Connector Route');
|
||||||
|
|
||||||
const response = await this.connectorClientService.uploadFile({
|
const response = await this.connectorClientService.uploadConnectorsFile({
|
||||||
file,
|
file,
|
||||||
name,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async getAllConnectors(@Query() queries: GetAllDto) {
|
@RequireAllPermissions(Permissions.CONNECTORS.GET)
|
||||||
|
async getAllConnectors(
|
||||||
|
@Headers('dadosfera-lang') language,
|
||||||
|
@Query() queries: GetAllDto,
|
||||||
|
) {
|
||||||
this.logger.info('/upload - Upload Connector Route');
|
this.logger.info('/upload - Upload Connector Route');
|
||||||
|
|
||||||
const { search, ...filters } = queries;
|
const { search, size, page, ...filters } = queries;
|
||||||
|
|
||||||
const response: any = await this.connectorClientService.getAllConnectors({
|
const response: any = await this.connectorClientService.getAllConnectors({
|
||||||
filters: filters || {},
|
filters: filters || {},
|
||||||
search: search || '',
|
search: search || '',
|
||||||
|
language: language || 'pt-br',
|
||||||
|
size: size || 10,
|
||||||
|
page: page || 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
const connectors = JSON.parse(response.connectors).connectors;
|
const connectors = JSON.parse(response.connectors).connectors;
|
||||||
@@ -87,8 +120,16 @@ export class ConnectorController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/tags')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.GET)
|
||||||
|
async getConnectorsTags() {
|
||||||
|
return await this.connectorClientService.getConnectorsTags();
|
||||||
|
}
|
||||||
|
|
||||||
@Get('/:plugin')
|
@Get('/:plugin')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.GET)
|
||||||
async getConnector(
|
async getConnector(
|
||||||
|
@Headers('dadosfera-lang') language,
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Query('version') version: string,
|
@Query('version') version: string,
|
||||||
) {
|
) {
|
||||||
@@ -98,6 +139,7 @@ export class ConnectorController {
|
|||||||
|
|
||||||
const response: any = await this.connectorClientService.getConnector(
|
const response: any = await this.connectorClientService.getConnector(
|
||||||
pluginId,
|
pluginId,
|
||||||
|
language,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -107,7 +149,9 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:plugin/details')
|
@Get('/:plugin/details')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.GET)
|
||||||
async getConnectorDetails(
|
async getConnectorDetails(
|
||||||
|
@Headers('dadosfera-lang') language,
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Query('version') version: string,
|
@Query('version') version: string,
|
||||||
) {
|
) {
|
||||||
@@ -117,6 +161,7 @@ export class ConnectorController {
|
|||||||
|
|
||||||
const response: any = await this.connectorClientService.getConnectorDetails(
|
const response: any = await this.connectorClientService.getConnectorDetails(
|
||||||
pluginId,
|
pluginId,
|
||||||
|
language || 'pt-br',
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -126,6 +171,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:plugin')
|
@Put('/:plugin')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.UPDATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
async updateConnector(
|
async updateConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@@ -147,6 +193,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:plugin/add-tag')
|
@Put('/:plugin/add-tag')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.UPDATE)
|
||||||
async addTagOnConnector(
|
async addTagOnConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() body: AddTagDto,
|
@Body() body: AddTagDto,
|
||||||
@@ -173,6 +220,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:plugin/remove-tag')
|
@Put('/:plugin/remove-tag')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.UPDATE)
|
||||||
async removeTagOnConnector(
|
async removeTagOnConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() body: RemoveTagDto,
|
@Body() body: RemoveTagDto,
|
||||||
@@ -200,6 +248,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete('/:plugin')
|
@Delete('/:plugin')
|
||||||
|
@RequireAllPermissions(Permissions.CONNECTORS.DELETE)
|
||||||
async deleteConnector(
|
async deleteConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() { version }: DeleteConnectorDto,
|
@Body() { version }: DeleteConnectorDto,
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
|
import { ConnectorClientService } from './client.service';
|
||||||
|
import { ConnectorClientConfiguration } from './client.config';
|
||||||
|
import { ConnectorController } from './connector.controller';
|
||||||
|
import { DadosferaLogger } from 'dadosfera-logs';
|
||||||
|
|
||||||
|
const connectorClient = new ConnectorClientConfiguration();
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [ConnectorController],
|
||||||
|
providers: [ConnectorClientService, DadosferaLogger],
|
||||||
|
imports: [
|
||||||
|
ClientsModule.register([
|
||||||
|
{
|
||||||
|
name: 'CONNECTOR_PACKAGE',
|
||||||
|
...connectorClient.config(),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
export class ConnectorModule {}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class UploadConnectorsFileDto {
|
||||||
|
@ApiProperty({ format: 'binary' })
|
||||||
|
file: string;
|
||||||
|
}
|
||||||
@@ -4,6 +4,15 @@ export class GetAllDto {
|
|||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
search: string;
|
search: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
language: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
size: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
page: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
filters: any;
|
filters: any;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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