import { AxiosResponse } from 'axios'; import { ResourceType } 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; /** 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; private _handleXMigration; /** * 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 args - The args to be used for the request. * * @typeParam T - The type of the returned response data. * * @returns The raw Axios response. * * @example * * #### Fetching the raw details of a single user, using their username * ```ts * import { FetcherService, ResourceType } 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(ResourceType.USER_DETAILS_BY_USERNAME, { id: 'user1' }) * .then(res => { * console.log(res); * }) * .catch(err => { * console.log(err); * }); * ``` */ request(resource: ResourceType, args: IFetchArgs | IPostArgs): Promise>; }