UNPKG

mercadopago

Version:
50 lines (49 loc) 2.22 kB
import type { Options } from '../../types'; /** * Merged configuration for a single REST call. * * Combines the global SDK {@link Options} with per-request overrides * such as query parameters and retry count. */ interface RestClientConfig extends Options { /** Key-value pairs appended to the URL as query-string parameters. */ queryParams?: Record<string, string | number>; /** Number of retry attempts for HTTP 5xx errors (default: {@link AppConfig.DEFAULT_RETRIES}). */ retries?: number; } declare class RestClient { /** Generates a UUID v4 idempotency key for write operations. */ private static generateIdempotencyKey; /** * Appends query-string parameters to a URL. * * Skips `undefined` values so callers don't need to pre-filter. * Handles URLs that already contain a `?` by appending with `&`. * * @param url - Base URL (may already include a query string). * @param queryParams - Key-value pairs to append. * @returns The URL with the encoded query string. */ static appendQueryParamsToUrl(url: string, queryParams?: Record<string, string | number>): string; private static computeDelay; private static parseRetryAfterMs; private static retryWithExponentialBackoff; /** * Performs an HTTP request against the MercadoPago API. * * This is the single exit point for all network I/O in the SDK. * It merges SDK defaults with caller-provided overrides, injects * required headers, and normalises the JSON response. * * - **204 No Content** → returns `{ api_response }` with no body. * - **2xx with body** → returns the parsed JSON with `api_response` appended. * - **Non-2xx** → throws a typed {@link MercadoPagoError} subtype. * * @typeParam T - Expected shape of the parsed JSON response. * @param endpoint - API path relative to the base URL (e.g. `/v1/payments`). * @param config - Merged request settings (headers, body, method, options, etc.). * @returns Parsed API response with an `api_response` envelope. */ static fetch<T>(endpoint: string, config?: RestClientConfig & RequestInit): Promise<T>; } export { RestClient };