UNPKG

@translated/lara

Version:

Official Lara SDK for JavaScript and Node.js

58 lines (57 loc) 3.02 kB
import type { Readable } from "node:stream"; import { AccessKey, AuthToken } from "../../credentials"; type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"; /** @internal */ export type BaseURL = { secure: boolean; hostname: string; port: number; }; /** @internal */ export type ClientResponse = { statusCode: number; body: any; headers: Record<string, string | string[] | undefined>; }; export type BrowserMultiPartFile = File; export type NodeMultiPartFile = Readable | string; export type MultiPartFile = BrowserMultiPartFile | NodeMultiPartFile; /** @internal */ export declare abstract class LaraClient { private readonly crypto; private readonly extraHeaders; private readonly accessKey?; private authToken?; protected token?: string; protected refreshToken?: string; private authenticationPromise?; private refreshPromise?; protected constructor(auth: AccessKey | AuthToken); setExtraHeader(name: string, value: string): void; get<T>(path: string, queryParams?: Record<string, any>, headers?: Record<string, string>): Promise<T>; delete<T>(path: string, queryParams?: Record<string, any>, body?: Record<string, any>, headers?: Record<string, string>): Promise<T>; post<T>(path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>, streamResponse?: boolean): Promise<T>; postAndGetStream<T>(path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>): AsyncGenerator<T>; put<T>(path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>): Promise<T>; protected request<T>(method: HttpMethod, path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>, retryCount?: number, streamResponse?: boolean): Promise<T>; protected requestStream<T>(method: HttpMethod, path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>, retryCount?: number): AsyncGenerator<T>; private isTokenExpired; private ensureAuthenticated; private performAuthentication; private refreshOrReauthenticate; private doRefreshOrReauthenticate; private refreshTokens; private authenticateWithAccessKey; private buildPathWithQuery; private buildRequestHeaders; private buildRequestBody; private filterNullish; private isSuccessResponse; private handleAuthResponse; private createApiError; private sign; protected abstract send(method: HttpMethod, path: string, headers: Record<string, string>, body?: Record<string, any>, stream?: boolean): Promise<ClientResponse>; protected abstract sendAndGetStream(method: HttpMethod, path: string, headers: Record<string, string>, body?: Record<string, any>): AsyncGenerator<ClientResponse>; protected abstract wrapMultiPartFile(file: MultiPartFile): any; } export {};