Configuration Guide
Comprehensive guide to configuring the Wildberries TypeScript SDK for different environments and use cases.
Table of Contents
- Overview
- Basic Configuration
- Environment-Specific Configuration
- Advanced Configuration
- Timeout Configuration
- Rate Limiting Configuration
- Retry Configuration
- Logging Configuration
- Configuration Best Practices
Overview
The SDK provides flexible configuration options to adapt to different environments, performance requirements, and operational needs.
Configuration Interface
interface SDKConfig {
// Required
apiKey: string;
// Optional overrides
baseUrls?: Partial<Record<string, string>>;
timeout?: number;
retryConfig?: RetryConfig;
rateLimitConfig?: RateLimitConfig;
logLevel?: 'debug' | 'info' | 'warn' | 'error';
}API Reference: See SDKConfig for complete configuration interface documentation with all available options.
Basic Configuration
Minimal Setup
import { WildberriesSDK } from 'daytona-wildberries-typescript-sdk';
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!
});Standard Setup
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
timeout: 30000, // 30 seconds
logLevel: 'warn'
});Full Configuration
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
// Timeout configuration
timeout: 30000,
// Retry configuration
retryConfig: {
maxRetries: 3,
retryDelay: 1000,
exponentialBackoff: true,
},
// Rate limiting
rateLimitConfig: {
requestsPerSecond: 10,
requestsPerMinute: 100,
},
// Logging
logLevel: process.env.NODE_ENV === 'production' ? 'warn' : 'debug',
});Environment-Specific Configuration
Development Environment
// config/development.ts
export const developmentConfig = {
apiKey: process.env.WB_API_KEY!,
timeout: 60000, // Longer timeout for debugging
logLevel: 'debug' as const,
retryConfig: {
maxRetries: 1, // Fail fast in development
retryDelay: 500,
exponentialBackoff: false,
}
};Production Environment
// config/production.ts
export const productionConfig = {
apiKey: process.env.WB_API_KEY!,
timeout: 30000,
logLevel: 'warn' as const,
retryConfig: {
maxRetries: 5,
retryDelay: 2000,
exponentialBackoff: true,
},
rateLimitConfig: {
requestsPerSecond: 8, // Conservative limit
requestsPerMinute: 80,
}
};Testing Environment
// config/test.ts
export const testConfig = {
apiKey: 'test-api-key',
timeout: 5000, // Short timeout for tests
logLevel: 'error' as const,
retryConfig: {
maxRetries: 0, // No retries in tests
retryDelay: 0,
exponentialBackoff: false,
}
};Configuration Factory
// config/index.ts
import { developmentConfig } from './development';
import { productionConfig } from './production';
import { testConfig } from './test';
export function getConfig() {
const env = process.env.NODE_ENV || 'development';
switch (env) {
case 'production':
return productionConfig;
case 'test':
return testConfig;
default:
return developmentConfig;
}
}
// Usage
import { getConfig } from './config';
const sdk = new WildberriesSDK(getConfig());Advanced Configuration
Dynamic Configuration
class ConfigurableSDK {
private sdk: WildberriesSDK;
private config: SDKConfig;
constructor(initialConfig: SDKConfig) {
this.config = initialConfig;
this.sdk = new WildberriesSDK(this.config);
}
updateConfig(updates: Partial<SDKConfig>) {
this.config = { ...this.config, ...updates };
this.sdk = new WildberriesSDK(this.config);
}
getSDK(): WildberriesSDK {
return this.sdk;
}
}
// Usage
const configurableSDK = new ConfigurableSDK({
apiKey: process.env.WB_API_KEY!,
timeout: 30000
});
// Later, update configuration
configurableSDK.updateConfig({
timeout: 60000,
logLevel: 'debug'
});Feature Flags
interface FeatureFlags {
enableCaching: boolean;
enableMetrics: boolean;
enableRetry: boolean;
enableRateLimiting: boolean;
}
class FeatureFlagSDK {
private sdk: WildberriesSDK;
private flags: FeatureFlags;
constructor(config: SDKConfig, flags: FeatureFlags) {
this.flags = flags;
this.sdk = new WildberriesSDK({
...config,
retryConfig: flags.enableRetry ? config.retryConfig : {
maxRetries: 0,
retryDelay: 0,
exponentialBackoff: false,
}
});
}
async getWithFeatures<T>(
operation: () => Promise<T>
): Promise<T> {
if (this.flags.enableCaching) {
// Check cache first
}
if (this.flags.enableMetrics) {
// Track metrics
}
return operation();
}
}Multi-Tenant Configuration
class MultiTenantSDK {
private sdkInstances = new Map<string, WildberriesSDK>();
getSDK(tenantId: string): WildberriesSDK {
if (!this.sdkInstances.has(tenantId)) {
const config = this.getConfigForTenant(tenantId);
this.sdkInstances.set(
tenantId,
new WildberriesSDK(config)
);
}
return this.sdkInstances.get(tenantId)!;
}
private getConfigForTenant(tenantId: string): SDKConfig {
return {
apiKey: process.env[`WB_API_KEY_${tenantId}`]!,
timeout: 30000,
logLevel: 'warn',
};
}
}Timeout Configuration
Global Timeout
Set a default timeout for all requests:
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
timeout: 60000, // 60 seconds for all requests
});The default timeout is 30 seconds (30000ms). Increase it for environments with slow network or when working with large datasets.
Per-Request Timeout
Override the global timeout for individual requests that need more (or less) time:
// For long-running operations, increase the global timeout:
const sdkForReports = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
timeout: 120000, // 2 minutes for report generation
});
// Download a generated analytics report file
const reportFile = await sdkForReports.analytics.getDownloadsFile(downloadId);The timeout in SDKConfig applies to all requests made by that SDK instance. Each retry attempt uses the timeout individually (not cumulative).
Timeout and Retry Interaction
When a request times out, the SDK automatically retries it (up to maxRetries times). Each retry attempt gets the full timeout duration:
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
timeout: 30000, // 30s per attempt
retryConfig: {
maxRetries: 3, // Up to 3 retries after initial attempt
retryDelay: 1000, // 1s base delay between retries
exponentialBackoff: true,
},
});
// Worst case: 30s + 1s + 30s + 2s + 30s + 4s + 30s = ~127 seconds totalTip: If you see
ETIMEDOUTerrors, increase the global timeout or use per-request timeout for specific slow operations. SetlogLevel: 'info'to see retry attempts in the console.
Rate Limiting Configuration
The SDK provides flexible rate limiting configuration to prevent API quota exhaustion and ensure reliable operation.
API Reference: See RateLimitConfig for complete rate limiting configuration options.
Global Rate Limits
The rateLimitConfig accepts two flat options that apply globally across all endpoints. Per-endpoint rate limits are automatically enforced by the SDK based on the OpenAPI specifications.
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
rateLimitConfig: {
requestsPerSecond: 10,
requestsPerMinute: 100,
}
});Note: Per-endpoint rate limits (e.g., 3 requests/minute for product creation) are extracted from the OpenAPI specs and enforced automatically via
rateLimitKeyin each module method. The globalrateLimitConfigsets an upper bound across all endpoints.
Custom Rate Limiter
import { RateLimiter } from 'daytona-wildberries-typescript-sdk/client';
const customLimiter = new RateLimiter({
requestsPerMinute: 60,
intervalSeconds: 10,
burstLimit: 10,
});
// Use with SDK operations
await customLimiter.waitForSlot('custom');
const result = await sdk.products.getProductList({ limit: 100 });Retry Configuration
Configure automatic retry behavior for failed API requests with exponential backoff support.
API Reference: See RetryConfig and RetryHandler for complete retry mechanism documentation.
Basic Retry Setup
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
retryConfig: {
maxRetries: 3,
retryDelay: 1000, // 1 second base delay
exponentialBackoff: true, // 1s, 2s, 4s, 8s...
}
});Custom Retry Logic
The SDK's retryConfig supports three fields: maxRetries, retryDelay, and exponentialBackoff. The SDK automatically retries on transient failures (network errors, 5xx, 429) and never retries on authentication (401/403) or validation errors (400/422).
interface RetryConfig {
maxRetries: number;
retryDelay: number;
exponentialBackoff: boolean;
}
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
retryConfig: {
maxRetries: 5,
retryDelay: 2000,
exponentialBackoff: true,
}
});Note: Set
logLevel: 'info'to see retry attempts in the console, orlogLevel: 'debug'for full retry context including error type and status code.
Conditional Retry
class SmartRetrySDK {
private sdk: WildberriesSDK;
async executeWithSmartRetry<T>(
operation: () => Promise<T>,
options: {
critical: boolean;
maxRetries?: number;
}
): Promise<T> {
const maxRetries = options.critical ? 10 : 3;
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
return await operation();
} catch (error) {
if (attempt === maxRetries) throw error;
// Don't retry on auth errors
if (error instanceof AuthenticationError) throw error;
// Longer delay for critical operations
const delay = options.critical
? 5000 * Math.pow(2, attempt)
: 1000 * Math.pow(2, attempt);
await sleep(delay);
}
}
throw new Error('Max retries exceeded');
}
}Logging Configuration
Log Levels
// debug: All SDK operations, full retry context
// info: Retry attempts, important operations
// warn: Timeouts, retries exhausted, warnings (recommended for production)
// error: Errors only
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
logLevel: process.env.LOG_LEVEL as 'debug' | 'info' | 'warn' | 'error' || 'warn'
});What Each Log Level Shows
| Event | debug | info | warn | error |
|---|---|---|---|---|
| Retry attempt (URL, attempt #, delay) | Yes | Yes | — | — |
| Full retry context (error type, status code, isTimeout) | Yes | — | — | — |
| Request timed out (URL, timeout duration) | Yes | Yes | Yes | — |
| All retries exhausted | Yes | Yes | Yes | — |
| Network errors | Yes | Yes | Yes | Yes |
Tip: Use
logLevel: 'info'to see retry attempts and timeout warnings without the noise of debug-level output. UselogLevel: 'debug'when troubleshootingETIMEDOUTerrors to see the full error context for each retry.
Logging Integration
The SDK uses its own internal Axios instance managed by BaseClient. Use the logLevel option to control SDK logging output:
const sdk = new WildberriesSDK({
apiKey: process.env.WB_API_KEY!,
logLevel: 'debug', // See all requests, responses, and retry context
});Note: The SDK does not support injecting a custom
httpClient.BaseClientmanages its own Axios instance internally. UselogLevelfor observability into SDK operations.
HTTP Client
The SDK manages its own internal Axios instance via BaseClient. There is no httpClient option on SDKConfig -- the HTTP client is not user-replaceable. The SDK handles connection management, authentication headers, timeout, retry, and rate limiting internally.
Note: If you need proxy support or custom TLS configuration, configure it at the OS/environment level (e.g.,
HTTP_PROXY/HTTPS_PROXYenvironment variables) rather than via the SDK.
Configuration Best Practices
✅ Do
- Store API keys in environment variables
- Use different configurations for different environments
- Set appropriate timeouts for your use case
- Enable retry logic for production
- Use conservative rate limits
- Log at appropriate levels (warn/error in production)
- Validate configuration on startup
- Document custom configurations
❌ Don't
- Hardcode API keys in configuration
- Use development config in production
- Disable retry logic to "improve speed"
- Set timeouts too low (causes false failures)
- Ignore rate limits
- Enable debug logging in production
- Share configuration files containing secrets
- Modify SDK defaults without understanding implications
Configuration Validation
import { z } from 'zod';
const ConfigSchema = z.object({
apiKey: z.string().min(10),
timeout: z.number().min(1000).max(120000),
retryConfig: z.object({
maxRetries: z.number().min(0).max(10),
retryDelay: z.number().min(100).max(10000),
exponentialBackoff: z.boolean(),
}).optional(),
logLevel: z.enum(['debug', 'info', 'warn', 'error']).optional(),
});
function createSDK(config: unknown): WildberriesSDK {
const validatedConfig = ConfigSchema.parse(config);
return new WildberriesSDK(validatedConfig);
}Environment Variables Reference
# Required
WB_API_KEY=your_api_key_here
# Optional
WB_API_TIMEOUT=30000
WB_API_MAX_RETRIES=3
WB_API_RETRY_DELAY=1000
WB_API_LOG_LEVEL=warn
# Rate Limiting
WB_RATE_LIMIT_PER_SECOND=10
WB_RATE_LIMIT_PER_MINUTE=100Related Documentation
- API Reference - Complete SDK documentation
- SDKConfig - Main configuration interface
- RetryConfig - Retry configuration
- RateLimitConfig - Rate limiting configuration
- WildberriesSDK - Main SDK class
- Best Practices Guide - Production deployment patterns
- Security Guide - Secure configuration practices
- Performance Guide - Performance optimization
- Getting Started - Initial setup guide
Support
For configuration questions: