@fintalk.ai/axios-interceptor
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Axios Interceptor

Essa lib intercepta requisições acrescentando duration e gerando logs úteis para monitoramento.

Instalação

npm install @fintalk.ai/axios-interceptor

Como utilizar

No typescript:

import { axiosFactory, AxiosResponseWithMetadata } from "@fintalk.ai/axios-interceptor";
const axios = axiosFactory(logger, {
  timeout: 50000,
  httpsAgent: new https.Agent({
    keepAlive: true,
    rejectUnauthorized: false,
  }),
});
const response = await axios.request<
  {},
  AxiosResponseWithMetadata<BalanceOperation[]>
>(options);

No node:

const { axiosFactory } = require("@fintalk.ai/axios-interceptor");
const axios = axiosFactory(logger, {
  timeout: 50000,
  httpsAgent: new https.Agent({
    keepAlive: true,
    rejectUnauthorized: false,
  }),
});
const response = await axios.get("url", { headers: {} });

Se timeout e httpsAgent não forem passados serão usados timeout 30000, keepAlive true e rejectUnauthorized false.

Parâmetros

Para suprimir logs desnecessários (autenticação em API, pré-requests, OPTIONS requests), envie o parâmetro log com valor false

const response = await axios.get("url", { headers: {}, log: false });

Para habilitar logs completos de DEBUG (request/response), adicione uma variável de ambiente com a chave DEBUG como true ⚠️ Só utilize para análises, não deixe habilitado ⚠️

Para contribuir

Instalar dependências

npm install

Testes unitários

npm run test
npm run test:coverage

Lint

npm run lint

Build

npm run build

Readme

Keywords

none

Package Sidebar

Install

npm i @fintalk.ai/axios-interceptor

Weekly Downloads

6

Version

1.0.5

License

MIT

Unpacked Size

20.5 kB

Total Files

23

Last publish

Collaborators

  • eduardofintalk
  • eduardocalazansjr