onResponse hook on XeroClient config that will be called every response

Abierto
#620 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
nodejs, typescript
Área
api

Línea de trabajo

The request is for an onResponse option on the XeroClient config, which would receive the raw response headers on every API call. Start from the XeroClient constructor and its config type, then find where requests are sent to see where a response callback could be invoked. The issue's example headers (X-DayLimit-Remaining and related) show the data the hook must expose. Done means the callback fires on each response with the headers available, and the README documents it.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Type: Enhancement Type: Feature Request

SDK you're using (please complete the following information):

  • Version: 4.29.0

Is your feature request related to a problem? Please describe.

Yes.Xero API's enforces the following rate limits:

  • 5 concurrent request (per tenant)
  • 60 requests per minute (per tenant)
  • 5,000 request per day (per tenant)
  • 10,000 requests per day (hard limit on the app level)

I'm currently creating a solution that works with these constraints.

Describe the solution you'd like

We want to be able to specify a hook on the XeroClient level like so:

import { XeroClient } from 'xero-node';

const client = new XeroClient({
  clientId: process.env.XERO_CLIENT_ID,
  clientSecret: process.env.XERO_CLIENT_SECRET,
  redirectUris: [process.env.XERO_REDIRECT_URI],
  scopes: [
    'openid',
    'profile',
    'email',
    'accounting.settings',
    'payroll.employees',
    'payroll.payruns',
    'offline_access'
  ],
  onResponse: (response: IncomingMessage) => {
    const dayRemaining = response.headers['X-DayLimit-Remaining'];
    const minuteRemaining = response.headers['X-MinLimit-Remaining'];
    const AppMinLimit = response.headers['X-AppMinLimit-Remaining'];
    // do something
  }
});

Describe alternatives you've considered

No alternatives available other than to write your own helper function that handles these everytime you make a request which isn't as good and causes a lot of code repetition.

Additional context

N/A

Lenguaje dominante
TypeScript
Estrellas
264
Forks
177
Merge medio
10 h 5 min
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de XeroAPI/xero-node

Todos los issues de XeroAPI/xero-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.