Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onResponse hook on XeroClient config that will be called every response #620

Open
aprilmintacpineda opened this issue Dec 8, 2022 · 0 comments

Comments

@aprilmintacpineda
Copy link

aprilmintacpineda commented Dec 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants