Ajustando definicao de tipos nas funcoes

This commit is contained in:
Leandro Costa 2023-01-26 22:21:28 -03:00
parent 241726ed2f
commit 05f4e4c1e6

View file

@ -4,6 +4,7 @@ import axios, { AxiosRequestConfig } from 'axios';
import {
AccessToken, ContentType, defaultAuthContentType,
defaultAuthHeaderName,
defaultTokenHeaderName,
ExecutarRequestParams,
GrantType, LhispOauthClientConstructorParams,
} from "./lhisp-oauth-client.t";
@ -14,6 +15,7 @@ export default class LhispOauthClient {
protected clientId: string;
protected clientSecret: string;
protected authHeaderName: string;
protected tokenHeaderName: string;
protected authContentType: ContentType;
protected certificado?: string;
protected senhaCertificado?: string;
@ -49,6 +51,7 @@ export default class LhispOauthClient {
this.clientId = params.clientId;
this.clientSecret = params.clientSecret;
this.authHeaderName = params.authHeaderName || defaultAuthHeaderName;
this.tokenHeaderName = params.tokenHeaderName || defaultTokenHeaderName;
this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody;
}
@ -112,7 +115,7 @@ export default class LhispOauthClient {
return this.accessToken;
}
getRequestAuthToken(){
getAuthToken(){
return `${this.accessToken?.token_type} ${this.accessToken?.access_token}`;
}
@ -124,8 +127,8 @@ export default class LhispOauthClient {
let headers = {
'Content-Type': contentType,
[this.authRequestHeader]: this.getRequestAuthToken(),
...this.headers
[this.tokenHeaderName]: this.getAuthToken(),
// ...this.headers
};
const response = await axios({
@ -140,19 +143,19 @@ export default class LhispOauthClient {
return response.data;
}
async get({ path, contentType = 'application/json', params }) {
async get({ path, contentType = ContentType.APPLICATION_JSON, params }: ExecutarRequestParams) {
return this.executarRequest({ method: 'GET', path, contentType, params });
}
async put({ path, data, contentType = 'application/json' }) {
async put({ path, data, contentType = ContentType.APPLICATION_JSON }: ExecutarRequestParams) {
return this.executarRequest({ method: 'PUT', path, data, contentType });
}
async post({ path, data, contentType = 'application/json' }) {
async post({ path, data, contentType = ContentType.APPLICATION_JSON }: ExecutarRequestParams) {
return this.executarRequest({ method: 'POST', path, data, contentType });
}
async delete({ path, contentType = 'application/json' }) {
async delete({ path, contentType = ContentType.APPLICATION_JSON }: ExecutarRequestParams) {
return this.executarRequest({ method: 'DELETE', path, contentType });
}
}