import { EResourceType } from '../../enums/Resource'; import { RettiwtConfig } from '../../models/RettiwtConfig'; import { IFetchArgs } from '../../types/args/FetchArgs'; import { IPostArgs } from '../../types/args/PostArgs'; /** * The base service that handles all HTTP requests. * * @public */ export declare class FetcherService { /** The AuthService instance to use. */ private readonly _auth; /** The delay/delay function to use (ms). */ private readonly _delay?; /** The service used to handle HTTP and API errors */ private readonly _errorHandler; /** Service responsible for generating the `x-client-transaction-id` header. */ private readonly _tidProvider; /** The max wait time for a response. */ private readonly _timeout; /** The config object. */ protected readonly config: RettiwtConfig; /** * @param config - The config object for configuring the Rettiwt instance. */ constructor(config: RettiwtConfig); /** * Checks the authorization status based on the requested resource. * * @param resource - The requested resource. * * @throws An error if not authorized to access the requested resource. */ private checkAuthorization; /** * Returns the AuthCredentials based on the type of key present. * * @returns The generated AuthCredential */ private getCredential; /** * Generates the header for the transaction ID. * * @param method - The target method. * @param url - The target URL. * * @returns The header containing the transaction ID. */ private getTransactionHeader; /** * Validates the given args against the given resource. * * @param resource - The resource against which validation is to be done. * @param args - The args to be validated. * * @returns The validated args. */ private validateArgs; /** * Introduces a delay using the configured delay/delay function. */ private wait; /** * Makes an HTTP request according to the given parameters. * * @param resource - The requested resource. * @param config - The request configuration. * * @typeParam T - The type of the returned response data. * * @returns The raw data response received. * * @example * Fetching the raw details of a user with username 'user1' * ``` * import { FetcherService, EResourceType } from 'rettiwt-api'; * * // Creating a new FetcherService instance using the given 'API_KEY' * const fetcher = new FetcherService({ apiKey: API_KEY }); * * // Fetching the details of the User with username 'user1' * fetcher.request(EResourceType.USER_DETAILS_BY_USERNAME, { id: 'user1' }) * .then(res => { * console.log(res); * }) * .catch(err => { * console.log(err); * }) * ``` */ request(resource: EResourceType, args: IFetchArgs | IPostArgs): Promise; }