import { SDKConfig, RequestOptions } from '../config'; /** * Base HTTP client for all Wildberries API modules * * This class provides a unified HTTP interface with: * - Automatic authentication header injection * - Configurable timeouts * - Typed error transformation * - Debug logging with PII sanitization * * All API modules receive a BaseClient instance via dependency injection * to ensure consistent behavior across the SDK. * * @example Basic usage * ```typescript * const config: SDKConfig = { * apiKey: 'your-api-key', * timeout: 30000, * logLevel: 'debug' * }; * * const client = new BaseClient(config); * * // Make GET request * const data = await client.get( * 'https://content-api.wildberries.ru/api/v1/products' * ); * ``` * * @example With custom headers * ```typescript * const data = await client.post( * 'https://content-api.wildberries.ru/api/v1/products', * { brandName: 'MyBrand', title: 'Product Title' }, * { headers: { 'X-Request-ID': '123' } } * ); * ``` */ export declare class BaseClient { private axios; private apiKey; private logLevel; private rateLimiter; private retryHandler; /** * Creates a new BaseClient instance * * @param config - SDK configuration object * * @throws {Error} If apiKey is not provided or invalid * * @example * ```typescript * const client = new BaseClient({ * apiKey: process.env.WB_API_KEY || '', * timeout: 60000, * logLevel: 'info' * }); * ``` */ constructor(config: SDKConfig); /** * Make a GET request with automatic retry on transient failures * * Automatically retries on network errors, 5xx server errors, and 429 rate limits. * Does NOT retry on authentication errors (401/403) or validation errors (400/422). * * @typeParam T - Expected response type * @param url - Full URL for the request * @param options - Optional request options * @returns Promise resolving to typed response data * * @throws {AuthenticationError} On 401/403 responses * @throws {RateLimitError} On 429 responses (after retries exhausted) * @throws {ValidationError} On 400/422 responses * @throws {NetworkError} On network failures or 5xx responses (after retries exhausted) * * @example * ```typescript * interface Product { * id: string; * name: string; * } * * const product = await client.get( * 'https://content-api.wildberries.ru/api/v1/products/123' * ); * console.log(product.name); * ``` */ get(url: string, options?: RequestOptions): Promise; /** * Make a POST request with automatic retry on transient failures * * Automatically retries on network errors, 5xx server errors, and 429 rate limits. * Does NOT retry on authentication errors (401/403) or validation errors (400/422). * * @typeParam T - Expected response type * @param url - Full URL for the request * @param data - Request body data * @param options - Optional request options * @returns Promise resolving to typed response data * * @throws {AuthenticationError} On 401/403 responses * @throws {RateLimitError} On 429 responses (after retries exhausted) * @throws {ValidationError} On 400/422 responses * @throws {NetworkError} On network failures or 5xx responses (after retries exhausted) * * @example * ```typescript * interface CreateProductRequest { * brandName: string; * title: string; * } * * interface CreateProductResponse { * id: string; * } * * const result = await client.post( * 'https://content-api.wildberries.ru/api/v1/products', * { brandName: 'MyBrand', title: 'New Product' } * ); * ``` */ post(url: string, data?: unknown, options?: RequestOptions): Promise; /** * Make a PUT request with automatic retry on transient failures * * Automatically retries on network errors, 5xx server errors, and 429 rate limits. * Does NOT retry on authentication errors (401/403) or validation errors (400/422). * * @typeParam T - Expected response type * @param url - Full URL for the request * @param data - Request body data * @param options - Optional request options * @returns Promise resolving to typed response data * * @throws {AuthenticationError} On 401/403 responses * @throws {RateLimitError} On 429 responses (after retries exhausted) * @throws {ValidationError} On 400/422 responses * @throws {NetworkError} On network failures or 5xx responses (after retries exhausted) * * @example * ```typescript * const updated = await client.put( * 'https://content-api.wildberries.ru/api/v1/products/123', * { title: 'Updated Title' } * ); * ``` */ put(url: string, data?: unknown, options?: RequestOptions): Promise; /** * Make a PATCH request with automatic retry on transient failures * * Automatically retries on network errors, 5xx server errors, and 429 rate limits. * Does NOT retry on authentication errors (401/403) or validation errors (400/422). * * @typeParam T - Expected response type * @param url - Full URL for the request * @param data - Request body data * @param options - Optional request options * @returns Promise resolving to typed response data * * @throws {AuthenticationError} On 401/403 responses * @throws {RateLimitError} On 429 responses (after retries exhausted) * @throws {ValidationError} On 400/422 responses * @throws {NetworkError} On network failures or 5xx responses (after retries exhausted) * * @example * ```typescript * const patched = await client.patch( * 'https://content-api.wildberries.ru/api/v1/products/123', * { stock: 100 } * ); * ``` */ patch(url: string, data?: unknown, options?: RequestOptions): Promise; /** * Make a DELETE request with automatic retry on transient failures * * Automatically retries on network errors, 5xx server errors, and 429 rate limits. * Does NOT retry on authentication errors (401/403) or validation errors (400/422). * * @typeParam T - Expected response type * @param url - Full URL for the request * @param data - Optional request body data (RFC 7231 allows DELETE with body) * @param options - Optional request options * @returns Promise resolving to typed response data * * @throws {AuthenticationError} On 401/403 responses * @throws {RateLimitError} On 429 responses (after retries exhausted) * @throws {ValidationError} On 400/422 responses * @throws {NetworkError} On network failures or 5xx responses (after retries exhausted) * * @example * ```typescript * // DELETE without body * await client.delete( * 'https://content-api.wildberries.ru/api/v1/products/123' * ); * * // DELETE with body (RFC 7231 allows this) * await client.delete( * 'https://marketplace-api.wildberries.ru/api/v3/stocks/123', * { skus: ['SKU123', 'SKU456'] } * ); * ``` */ delete(url: string, data?: unknown, options?: RequestOptions): Promise; /** * Set up Axios request interceptor for authentication * * Automatically injects the Authorization header on all requests * and logs request details in debug mode. * * @private */ private setupRequestInterceptor; /** * Transform Axios errors to typed SDK errors * * Maps HTTP status codes and network errors to appropriate error classes: * - 401/403 → AuthenticationError * - 429 → RateLimitError * - 400/422 → ValidationError * - 5xx → NetworkError * - Network failures → NetworkError * - All other 4xx (including **409**) → generic `WBAPIError` fallback * * **IMPORTANT — application-level error codes inside 200 OK bodies (since v3.10.2):** * * Several WB endpoints return HTTP 200 with an **application-level** error code * embedded in the response body (most notably `code: 409` with `detail: 'MetaValidationFail'` * for `ordersDBS.deliverBulk()` and `ordersFBW.deliverBulk()`). Because these arrive * as HTTP 200 the BaseClient does NOT throw — the body is returned to the caller intact. * * Consumers must inspect the per-order shape, not catch a thrown error. Canonical paths: * - `result.results[].errors[].code === 409` * - `result.results[].errors[].detail === 'MetaValidationFail'` * - `result.results[].errors[].metaDetails[]` (per-order SGTIN/IMEI/UIN validation status) * * Endpoint-level JSDoc on `deliverBulk()` and `checkMetaValidation()` documents this * pattern explicitly. Do NOT add `@throws` annotations referencing this 409 pattern * (it does not throw); use prose instead. * * If you change BaseClient to throw on HTTP 409, update every `deliverBulk()` JSDoc and * the corresponding error-path tests across `orders-dbs` and `orders-fbw` modules in lockstep. * * @param error - Error from Axios request * @throws Typed SDK error * * @private */ private transformError; /** * Parse Retry-After header to milliseconds * * @param header - Retry-After header value (in seconds) * @returns Retry delay in milliseconds * * @private */ private parseRetryAfter; /** * Extract RFC 7807 problem+json fields from response data. * * Handles both `application/problem+json` and `application/json` responses * that contain RFC 7807-shaped bodies (with title, detail, etc.). * * @param responseData - API response body * @param isProblemJson - Whether the Content-Type is application/problem+json * @returns Extracted problem fields with string-safe values * * @private */ private extractProblemJsonFields; /** * Extract field-level validation errors from API response * * @param responseData - API response data * @returns Field errors map or undefined * * @private */ private extractFieldErrors; /** * Log message with structured format and sanitization * * Only logs if message level meets or exceeds configured logLevel. * Automatically sanitizes sensitive information (API keys, PII). * * @param level - Log level * @param message - Log message * @param meta - Optional metadata * * @private */ private log; /** * Sanitize metadata to remove sensitive information * * @param meta - Raw metadata object * @returns Sanitized metadata * * @private */ private sanitizeMeta; /** * Sanitize headers for logging * * @param headers - Request headers * @returns Sanitized headers * * @private */ private sanitizeHeaders; } //# sourceMappingURL=base-client.d.ts.map