import axios, { AxiosPromise } from 'axios'; import { CommonRequestConfig, BaseUrlGad } from '@quarks/gluon-form/lib/typings'; // TODO: Retirar import { connectors } from '../../common/mock/mock-connectors'; // import { connectors as quarksConnectors } from '../../common/mock/new-mock-connectors'; import { VoyagerBackend } from '@quarks/voyager-sdk-nodejs'; export class API { private clientVoyagerBackend = null; constructor( private readonly HOST_GAD_REPOSITORY: string, private readonly HOST_GAD_FS: string, private readonly HOST_GAD: string ) { this.init(); } async init() { } public initializerVoyagerBackend(url: string, token: string): void { if(!this.clientVoyagerBackend) { this.clientVoyagerBackend = new VoyagerBackend({url, token}); } } distinctBaseUrl(base: BaseUrlGad): string { switch (base) { case 'HOST_GAD': return this.HOST_GAD; case 'HOST_GAD_REPOSITORY': return this.HOST_GAD_REPOSITORY; case 'HOST_GAD_FS': return this.HOST_GAD_FS; default: return base; } } getMethod(request: CommonRequestConfig): AxiosPromise { const url: string = this.distinctBaseUrl(request.base) + request.endpoint; const options = { headers: request.header}; return axios.get(url, options); } postMethod(request: CommonRequestConfig): AxiosPromise { const url: string = this.distinctBaseUrl(request.base) + request.endpoint; const options = { headers: request.header}; return axios.post(url, request.data, options); } deleteMethod(request: CommonRequestConfig): AxiosPromise { const url: string = this.distinctBaseUrl(request.base) + request.endpoint; const options = { headers: request.header}; return axios.delete(url, options); } async fetchConnectors(origin : string): Promise { switch (origin) { case 'QuarksConnector': return connectors; case 'newQuarksConnector': return this.clientVoyagerBackend ? this.clientVoyagerBackend.services.list({query: 'typeGroup=connector'}): []; } } }