UNPKG

gpudeploy

Version:

Utilities for creating APIs

50 lines (49 loc) 1.38 kB
export type APIBaseParams = { baseURL?: string; reauthenticate?: boolean; }; export type RequestParams = { data?: any; method?: "DELETE" | "GET" | "POST" | "PUT"; path: string; unauthenticated?: boolean; }; export type RequestParams_ = RequestParams & { reauthenticate?: boolean; }; export type AuthenticateParams = { email: string; token: string; }; export type AuthenticateReturn = { accessToken: string; created: boolean; refreshToken: string; }; export type ReauthenticateParams = { refreshToken?: string; }; export type ReauthenticateReturn = { accessToken: string; refreshToken: string; }; declare class APIBase { accessToken: string | null; refreshToken: string | null; autoReauth: boolean; private baseURL; /** * @param param0 * @param param0.baseURL - The base URL for the API * @param param0.reauthenticate - Whether or not to reauthenticate automatically when the access token expires */ constructor({ baseURL, reauthenticate }: APIBaseParams); private request_; request<T = any>(params: RequestParams): Promise<T>; authenticate(data: AuthenticateParams): Promise<AuthenticateReturn>; reauthenticate({ refreshToken }?: ReauthenticateParams): Promise<ReauthenticateReturn>; } export type APIAdapterParams = { api: APIBase; }; export default APIBase;