Finbud Data TypeScript API Library
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
This library provides convenient access to the Finbud Data REST API from server-side TypeScript or JavaScript.
The full API of this library can be found in api.md.
It is generated with Stainless.
Installation
Usage
The full API of this library can be found in api.md.
Request & Response types
This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
Handling errors
When the library is unable to connect to the API,
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
a subclass of APIError will be thrown:
Error codes are as followed:
| Status Code | Error Type |
| ----------- | -------------------------- |
| 400 | BadRequestError |
| 401 | AuthenticationError |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 422 | UnprocessableEntityError |
| 429 | RateLimitError |
| >=500 | InternalServerError |
| N/A | APIConnectionError |
Retries
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
429 Rate Limit, and >=500 Internal errors will all be retried by default.
You can use the maxRetries option to configure or disable this:
Timeouts
Requests time out after 1 minute by default. You can configure this with a timeout option:
On timeout, an APIConnectionTimeoutError is thrown.
Note that requests which time out will be retried twice by default.
Advanced Usage
Accessing raw Response data (e.g., headers)
The "raw" Response returned by fetch() can be accessed through the .asResponse() method on the APIPromise type that all methods return.
This method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or streaming logic.
You can also use the .withResponse() method to get the raw Response along with the parsed data.
Unlike .asResponse() this method consumes the body, returning once it is parsed.
Logging
> [!IMPORTANT]
> All log messages are intended for debugging only. The format and content of log messages
> may change between releases.
Log levels
The log level can be configured in two ways:
1. Via the FINBUD_DATA_LOG environment variable
2. Using the logLevel client option (overrides the environment variable if set)
Available log levels, from most to least verbose:
- 'debug' - Show debug messages, info, warnings, and errors
- 'info' - Show info messages, warnings, and errors
- 'warn' - Show warnings and errors (default)
- 'error' - Show only errors
- 'off' - Disable all logging
At the 'debug' level, all HTTP requests and responses are logged, including headers and bodies.
Some authentication-related headers are redacted, but sensitive data in request and response bodies
may still be visible.
Custom logger
By default, this library logs to globalThis.console. You can also provide a custom logger.
Most logging libraries are supported, including pino, winston, bunyan, consola, signale, and @std/log. If your logger doesn't work, please open an issue.
When providing a custom logger, the logLevel option still controls which messages are emitted, messages