UNPKG

@translated/lara

Version:

Official Lara SDK for JavaScript and Node.js

71 lines (70 loc) • 3.86 kB
import type { Readable } from "node:stream"; import type { CollectionResult } from "../../collectionResult"; import { AccessKey, AuthToken } from "../../credentials"; type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; /** @internal */ export type BaseURL = { secure: boolean; hostname: string; port: number; }; /** @internal */ export type ClientResponse<T = any> = { statusCode: number; body: T; 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 { protected readonly sdkName: string; private readonly crypto; private readonly extraHeaders; private readonly accessKey?; private authToken?; protected token?: string; protected refreshToken?: string; private authenticationPromise?; private refreshPromise?; private readonly authSessionId?; protected constructor(auth: AccessKey | AuthToken, sessionId?: string); setExtraHeader(name: string, value: string): void; get<T>(path: string, queryParams?: Record<string, any>, headers?: Record<string, string>): Promise<T>; getCollection<T>(path: string, queryParams?: Record<string, any>, headers?: Record<string, string>): Promise<CollectionResult<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>; patch<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>; private requestWithMetadata; 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; /** * Adds the session id header to the access-key authentication request. The header is only * parsed on the "/v2/auth" endpoint, so it is never attached to token refresh requests. * The value is preserved for the lifetime of the client, so every access-key * (re-)authentication carries it. */ private applySessionHeader; 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 {};