/** * @module Clients / BaseClient * @category Entities */ import { AxiosInstance, AxiosRequestConfig, RawAxiosRequestHeaders } from 'axios'; import { DropData, JwtConfig, LedgerAccessRule, LedgerIdentifier, LedgerMeta, LedgerProof, LedgerRecord, LedgerRequestHashParams } from "../../../../types/src"; import { IBaseClient } from '../interfaces/base-client.interface'; import { IMultitenantClient } from '../interfaces/multitenant-client.interface'; import { BaseRecordResponse, RecordResponseClass } from '../types/base-record-response'; import { BaseResponse, ResponseClass } from '../types/base-response'; import { DropRecordResponse } from '../types/drop-record-response'; import { BaseListParams, BaseListParamsWithoutSearch } from '../types/list-params'; import { BaseListResponse, ListResponseClass } from '../types/list-response'; export type BaseClientOptions = { apiClient: AxiosInstance; secure?: JwtConfig; ledger?: string; headers?: { [key: string]: string; }; }; /** * A base API client that contains generic functions to make * API requests compatible with the ledger API. */ export declare abstract class BaseClient implements IBaseClient, IMultitenantClient { protected apiClient: AxiosInstance; private authParams; private activeLedger; protected links: BaseClient[]; protected id: LedgerIdentifier; private parentId; protected readonly headers: RawAxiosRequestHeaders; protected readonly secure: Partial; constructor(options: BaseClientOptions); /** * Internal function for building request hash * based on HTTP request variables. * * @param requestHashParams Configuration object for request hashing * @returns request hash */ private buildRequestHash; /** * Internal function for building the bearer token * from Ledger Auth params. * * @param requestHashParams Configuration object for request hashing * @param authParams Params for building JWT * @returns the bearer token */ protected buildJwt(requestHashParams: LedgerRequestHashParams, authParams?: Partial): Promise; protected buildHeaders(token: string): { 'X-Ledger': string; Authorization: string; "Content-Length"?: import("axios").AxiosHeaderValue; "Content-Encoding"?: import("axios").AxiosHeaderValue; Accept?: import("axios").AxiosHeaderValue; "User-Agent"?: import("axios").AxiosHeaderValue; 'Content-Type'?: import("axios").AxiosHeaderValue; } | { 'X-Ledger'?: undefined; Authorization: string; "Content-Length"?: import("axios").AxiosHeaderValue; "Content-Encoding"?: import("axios").AxiosHeaderValue; Accept?: import("axios").AxiosHeaderValue; "User-Agent"?: import("axios").AxiosHeaderValue; 'Content-Type'?: import("axios").AxiosHeaderValue; } | { 'X-Ledger': string; Authorization?: import("axios").AxiosHeaderValue; "Content-Length"?: import("axios").AxiosHeaderValue; "Content-Encoding"?: import("axios").AxiosHeaderValue; Accept?: import("axios").AxiosHeaderValue; "User-Agent"?: import("axios").AxiosHeaderValue; 'Content-Type'?: import("axios").AxiosHeaderValue; } | { 'X-Ledger'?: undefined; Authorization?: import("axios").AxiosHeaderValue; "Content-Length"?: import("axios").AxiosHeaderValue; "Content-Encoding"?: import("axios").AxiosHeaderValue; Accept?: import("axios").AxiosHeaderValue; "User-Agent"?: import("axios").AxiosHeaderValue; 'Content-Type'?: import("axios").AxiosHeaderValue; }; /** * Internal function for creating new ledger records * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected createRecord, MetaType extends LedgerMeta = LedgerMeta>(path: string, ResponseClass: RecordResponseClass, record: LedgerRecord, authParams?: Partial): Promise; /** * Internal function for ledger records lookup * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected lookupRecord, M extends LedgerMeta = LedgerMeta>(path: string, ResponseClass: ListResponseClass, lookupRecord: LedgerRecord, authParams?: Partial): Promise; /** * Internal function for checking access * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected checkAccess, M extends LedgerMeta = LedgerMeta>(path: string, ResponseClass: ListResponseClass, accessCheck: LedgerRecord, authParams?: Partial): Promise; /** * Internal function for activating ledger records * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected activateRecord(path: string, ResponseClass: ResponseClass, record: LedgerRecord, authParams?: Partial): Promise; /** * Internal function for updating ledger records * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected updateRecord, M extends LedgerMeta = LedgerMeta>(path: string, ResponseClass: RecordResponseClass, record: LedgerRecord, authParams?: Partial): Promise; /** * Internal function for creating new ledger records * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected signRecord, M extends LedgerMeta = LedgerMeta>(path: string, ResponseClass: RecordResponseClass, signature: LedgerProof, authParams?: Partial): Promise; /** * Internal function for droping ledger records * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected dropRecord(path: string, deletionRecord: LedgerRecord, authParams?: Partial): Promise; /** * Internal function for fetching a single ledger record * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected getRecord, M extends LedgerMeta = LedgerMeta>(path: string, ResponseClass: RecordResponseClass, authParams?: Partial): Promise; /** * Internal function for fetching a list of ledger records * and enforcing the correct types on axios. * * @param path API path to call * @returns the API response */ protected getRecordsList, M extends LedgerMeta = LedgerMeta, ListParams extends BaseListParamsWithoutSearch = BaseListParams>(path: string, ResponseClass: ListResponseClass, params?: ListParams): Promise; /** * Resolves the path before sending the request in order * to generate the correct JWT * * @param {string} url url to be resolved * @param {AxiosRequestConfig} [config] axios request configuration * that will be used to send the request * @returns {string} resolved path */ protected createRelativeUrl(url: string, config?: AxiosRequestConfig): string; /** * Set config params to build authentication Jwt * * @param authParams jwt configuration */ setAuthParams(authParams: Partial): void; /** * Sets header * * @param key * @param value */ setHeader(key: string, value: string): void; /** * Sets active ledger * @param handle active ledger handle */ setActiveLedger(handle: string): void; /** * Gets active ledger * @returns active ledger handle */ getActiveLedger(): string; /** * Asserts the client doesn't have * an active ledger set in context * @throws {LedgerSdkError} */ protected assertSingleTenant(): void; /** * Asserts the client has * an active ledger set in context * @throws {LedgerSdkError} */ protected assertMultiTenant(): void; /** * Creates a new instance of the client and sets * the id to the context. * * @param id */ with(id: LedgerIdentifier): this; /** * Sets record identifier to context. * * This method is also responsible for updating * the parent id of their linked clients. * * @param id */ protected setId(id: LedgerIdentifier): this; /** * Sets parent client record id to context * * @param id */ protected setParentId(id: LedgerIdentifier): void; /** * Ensures parent id is set * * @returns parent id */ protected assertParentId(): LedgerIdentifier; /** * Ensures id is set * * @returns id */ protected assertId(): LedgerIdentifier; }