smartsuite-typescript-api
Version:
Typescript type generator and wrapper for the REST API provided by SmartSuite. Currently in pre 1.0 so no semver guarantees are given
51 lines (50 loc) • 2.25 kB
TypeScript
import { RateLimiterOptions } from './ratelimit.js';
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
export interface HttpsClientOptions {
/**
* @see https://help.smartsuite.com/en/articles/4855681-generating-an-api-key
*/
apiKey: string;
/**
* From the SmartSuite documentation:
*
* "Note: Your Workspace ID can be found in the URL after logging into SmartSuite.
* Example: https://app.smartsuite.com/sv25cxf2/"
*
* In this example, "sv25cxf2" would be the Workspace ID
*/
workspaceId: string;
/**
* If present, a rate limiter will be used to throttle requests to avoid 429s as much as possible.
* If a 429 is replied anyway, the httpClient will retry 3 times (30 sec delays each retry).
* @default If a 429 is replied, the httpClient will retry 3 times (30 sec delays each retry).
* @see {@link HttpsClient} for logic if all retries fail
*/
rateLimitOptions?: RateLimiterOptions;
/**
* If this is provided, logging will be done through the provided function
* @default no logging will be done
* @param log will be the text to be logged
*/
logger?: (log: string) => void;
}
/**
* A simple class for handling all https logic when querying the API.
*
* Regarding {@link https://help.smartsuite.com/en/articles/4856710-api-limits API limits}:
*
* - Optionally, if {@link RateLimiterOptions} are provided in the options the httpClient will try to
* limit itself to prevent spamming over the requests per second limit as described in the SmartSuite
* {@link https://help.smartsuite.com/en/articles/4856710-api-limits documentation}
* - If a 429 is replied by the API, the httpClient will retry 3 times staggered 30 sec each retry, if all
* retries fail the httpClient will throw an Error, all future attempts will also throw Errors until month change
*/
export declare class HttpsClient {
private readonly baseUrl;
private readonly headers;
private readonly logger;
private readonly rateLimiter?;
private monthQuotaReached;
constructor(options: HttpsClientOptions);
request<ResponseType = any>(method: HttpMethod, route: string, body?: any): Promise<ResponseType>;
}