onResponse hook on XeroClient config that will be called every response

オープン
#620 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

XeroAPI/xero-node のほかの issue

XeroAPI/xero-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。