onResponse hook on XeroClient config that will be called every response

未关闭
#620 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
nodejs, typescript
领域
api

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
TypeScript
星标
264
派生
177
平均合并
10 小时 5 分钟
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

XeroAPI/xero-node 的其他 Issue

查看 XeroAPI/xero-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。