🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@fiado/http-client

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fiado/http-client - npm Package Compare versions

Comparing version
1.0.5
to
1.0.6
+5
-0
bin/AxiosHttpRequest.d.ts
import { AxiosRequestConfig } from 'axios';
import { IHttpRequest } from './IHttpRequest';
export declare class AxiosHttpRequest implements IHttpRequest {
/**
* Obtiene el valor de timeout de la variable de entorno HTTP_CLIENT_REQUEST_TIMEOUT
* @returns El valor de timeout en milisegundos o undefined si no está configurado
*/
private getTimeoutConfig;
get<T>(url: string, params?: Record<string, any>, headers?: Record<string, string>, basicAuth?: {

@@ -5,0 +10,0 @@ username: string;

+36
-5

@@ -16,8 +16,19 @@ "use strict";

let AxiosHttpRequest = class AxiosHttpRequest {
/**
* Obtiene el valor de timeout de la variable de entorno HTTP_CLIENT_REQUEST_TIMEOUT
* @returns El valor de timeout en milisegundos o undefined si no está configurado
*/
getTimeoutConfig() {
const timeout = process.env.HTTP_CLIENT_REQUEST_TIMEOUT_MILISECONDS;
// El valor debe estar en milisegundos para axios
return timeout ? parseInt(timeout, 10) : undefined;
}
async get(url, params = {}, headers = {}, basicAuth, extraConfig) {
const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const timeout = this.getTimeoutConfig();
const config = {
params,
headers: { ...headers, ...authHeaders },
...extraConfig && { extraConfig }
...(timeout !== undefined && { timeout }),
...extraConfig
};

@@ -29,3 +40,8 @@ const response = await axios_1.default.get(url, config);

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const response = await axios_1.default.post(url, data, { headers: { ...headers, ...authHeaders } });
const timeout = this.getTimeoutConfig();
const config = {
headers: { ...headers, ...authHeaders },
...(timeout !== undefined && { timeout })
};
const response = await axios_1.default.post(url, data, config);
return response.data;

@@ -35,3 +51,8 @@ }

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const response = await axios_1.default.put(url, data, { headers: { ...headers, ...authHeaders } });
const timeout = this.getTimeoutConfig();
const config = {
headers: { ...headers, ...authHeaders },
...(timeout !== undefined && { timeout })
};
const response = await axios_1.default.put(url, data, config);
return response.data;

@@ -41,3 +62,8 @@ }

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const response = await axios_1.default.patch(url, data, { headers: { ...headers, ...authHeaders } });
const timeout = this.getTimeoutConfig();
const config = {
headers: { ...headers, ...authHeaders },
...(timeout !== undefined && { timeout })
};
const response = await axios_1.default.patch(url, data, config);
return response.data;

@@ -47,3 +73,8 @@ }

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const config = { params, headers: { ...headers, ...authHeaders } };
const timeout = this.getTimeoutConfig();
const config = {
params,
headers: { ...headers, ...authHeaders },
...(timeout !== undefined && { timeout })
};
const response = await axios_1.default.delete(url, config);

@@ -50,0 +81,0 @@ return response.data;

+1
-1
{
"name": "@fiado/http-client",
"version": "1.0.5",
"version": "1.0.6",
"description": "Herramienta para realizar solicitudes http",

@@ -5,0 +5,0 @@ "main": "bin/index.js",

@@ -8,2 +8,11 @@ import axios, {AxiosRequestConfig} from 'axios';

/**
* Obtiene el valor de timeout de la variable de entorno HTTP_CLIENT_REQUEST_TIMEOUT
* @returns El valor de timeout en milisegundos o undefined si no está configurado
*/
private getTimeoutConfig(): number | undefined {
const timeout = process.env.HTTP_CLIENT_REQUEST_TIMEOUT_MILISECONDS;
// El valor debe estar en milisegundos para axios
return timeout ? parseInt(timeout, 10) : undefined;
}

@@ -15,6 +24,8 @@ async get<T>(url: string, params: Record<string, any> = {}, headers: Record<string, string> = {}, basicAuth?: {

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const timeout = this.getTimeoutConfig();
const config: AxiosRequestConfig = {
params,
headers: {...headers, ...authHeaders},
...extraConfig && {extraConfig}
...(timeout !== undefined && { timeout }),
...extraConfig
};

@@ -30,3 +41,8 @@ const response = await axios.get<T>(url, config);

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const response = await axios.post<T>(url, data, {headers: {...headers, ...authHeaders}});
const timeout = this.getTimeoutConfig();
const config: AxiosRequestConfig = {
headers: {...headers, ...authHeaders},
...(timeout !== undefined && { timeout })
};
const response = await axios.post<T>(url, data, config);
return response.data;

@@ -40,3 +56,8 @@ }

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const response = await axios.put<T>(url, data, {headers: {...headers, ...authHeaders}});
const timeout = this.getTimeoutConfig();
const config: AxiosRequestConfig = {
headers: {...headers, ...authHeaders},
...(timeout !== undefined && { timeout })
};
const response = await axios.put<T>(url, data, config);
return response.data;

@@ -50,3 +71,8 @@ }

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const response = await axios.patch<T>(url, data, {headers: {...headers, ...authHeaders}});
const timeout = this.getTimeoutConfig();
const config: AxiosRequestConfig = {
headers: {...headers, ...authHeaders},
...(timeout !== undefined && { timeout })
};
const response = await axios.patch<T>(url, data, config);
return response.data;

@@ -60,3 +86,8 @@ }

const authHeaders = basicAuth ? this.getBasicAuthHeaders(basicAuth.username, basicAuth.password) : {};
const config: AxiosRequestConfig = {params, headers: {...headers, ...authHeaders}};
const timeout = this.getTimeoutConfig();
const config: AxiosRequestConfig = {
params,
headers: {...headers, ...authHeaders},
...(timeout !== undefined && { timeout })
};
const response = await axios.delete<T>(url, config);

@@ -63,0 +94,0 @@ return response.data;