@flatfile/safe-api
Version:
Flatfile Safe API client with streaming capabilities
54 lines (53 loc) • 1.98 kB
TypeScript
import { RetryConfig } from "../config";
export type RetryOptions = Partial<RetryConfig>;
export type ValidQuery = string | number | boolean | undefined;
export declare abstract class SafeRequest<T> implements PromiseLike<T> {
params: string | string[];
query?: Record<string, ValidQuery> | undefined;
abstract readonly path: string;
protected payload?: Record<string, any>;
private rateLimitManager;
private config;
private retryOptions?;
constructor(params: string | string[], query?: Record<string, ValidQuery> | undefined, options?: RetryOptions);
/**
* prefix url with the API base if this is true
*/
isApiRequest: boolean;
/**
* This request can fail safely in the event of an error or rate limit hit
* and doesn't need to be retried. Useful for things like progress reporting.
*
* @default false
*/
canMiss: boolean;
isRaw: boolean;
private attempts;
private nextAttemptDelay;
private _isRun;
protected abstract execute(): Promise<T>;
protected _headers: Record<string, string>;
setHeaders(headers: Record<string, string>): this;
protected fetch(method: HttpMethods): Promise<T>;
protected parseBody(body?: Record<string, any>): Promise<T>;
protected afterSuccess(): void;
protected serializeBody(input?: any): string | Uint8Array | Promise<string | Uint8Array>;
protected handleResponseCodes(res: Response): Promise<true>;
private _run;
run(): Promise<T>;
defaultQuery(): Record<string, ValidQuery>;
buildQuery(): URLSearchParams;
/**
* @todo handle mismatched params
*/
buildPath(): string;
buildUrl(): string;
then(resolve: (val: T) => any, reject?: (err: any) => any): Promise<any>;
}
export interface Revertable {
revertEffects(): Promise<boolean>;
}
export interface Verifiable {
verifyEffects(): Promise<boolean>;
}
export type HttpMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";