UNPKG

iracing-api

Version:

Javascript client for iracing API

52 lines (51 loc) 2.59 kB
import { RateLimiter } from '../rate-limiter'; import { type FetchCookie, type Options } from '../types'; /** * Base class for iRacing API endpoints. * Provides common functionality for making requests, handling rate limits, and processing responses. * @internal */ export declare class API { fetchCookie: FetchCookie; options: Options; rateLimiter: RateLimiter; /** * Initializes the base API class. * @param fetchCookie - The fetch instance with cookie support. * @param options - Client configuration options. */ constructor(fetchCookie: FetchCookie, options: Options); /** * Internal method to fetch data from a specified API endpoint. * Handles rate limiting, URL construction, and optionally fetching data from a returned link. * * @template Data - The expected type of the primary data payload. * @template Parameters - The type of the query parameters object. * @param endpoint - The specific API endpoint path (e.g., 'data/car/get'). * @param [params] - Optional query parameters for the request. * @param [getLinkData=true] - If true and the response contains a 'link', fetch data from that link. * @returns A promise resolving to the fetched data (type Data) or undefined if an error occurs or no data is found. * @internal */ _getData: <Data = Record<string, unknown>, Parameters_1 = void>(endpoint: string, params?: Parameters_1 | Record<string, unknown> | undefined, getLinkData?: boolean) => Promise<Data | undefined>; /** * Internal method to fetch data from a secondary URL (often an S3 link) provided in an initial API response. * Converts keys in the fetched JSON data to camelCase. * * @template Data - The expected type of the data payload from the link. * @param link - The URL to fetch data from. * @returns A promise resolving to the fetched and camelCased data (type Data) or undefined if the link is invalid or fetching fails. * @internal */ _getLinkData: <Data>(link: string | undefined) => Promise<Data | undefined>; /** * Internal method to construct the full API URL including the base path and query parameters. * * @template Parameters - The type of the query parameters object. * @param endpoint - The specific API endpoint path. * @param [params] - Optional query parameters. * @returns The fully constructed URL string. * @internal */ _getUrl: <Parameters_1 = Record<string, unknown>>(endpoint: string, params?: Parameters_1 | undefined) => string; }