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
66 lines (65 loc) • 2.05 kB
TypeScript
/**
* @see https://www.smartsuite.com/pricing
*/
type PlanName = 'Free' | 'Team' | 'Professional' | 'Enterprise';
export interface RateLimiterOptions {
plan: PlanName;
/**
* This disables throttling when the full speed limit is reach for the current plan
* In practical terms, when this option is enabled, the only function of the rate limiter is to keep
* the total number of requests per second at a max of 5/sec.
*
* @see https://help.smartsuite.com/en/articles/4856710-api-limits#h_4c1fef3f43
*/
enableApiAddOns?: boolean;
/**
* 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;
/**
* @see {@link StorageHook}
*/
storageHook?: StorageHook;
}
/**
* Optional interface to allow custom persistence of API usage count.
* Useful if you want to store usage in a database or memory. Note that this will possibly
* be queried a lot depending on your API usage.
*
* @see {@link FileStorage} if you want to use the default storage, but with your own path
*/
interface StorageHook {
/**
* Saves the current usage count.
* @param count - The number of API requests made this month.
*/
save(count: number): void;
/**
* Loads the previously saved usage count.
* @returns The number of API requests made this month.
*/
load(): number;
}
export declare class RateLimiter {
private readonly fullSpeedLimit;
private readonly monthlyLimit;
private readonly useApiAddOns;
private readonly logger;
private readonly storageHook;
private requestTimestamps;
private requestCount;
constructor(options: RateLimiterOptions);
private log;
private saveCount;
throttle(): Promise<void>;
trackRequest(): void;
undoRequest(): void;
private checkQuota;
getUsage(): {
used: number;
remaining: string | number;
};
}
export {};