/** * API Client for Astra SDK */ import type { RequestOptions, ApiResponse } from '../types'; import { makeRequest, retryRequest } from '../utils/http'; import type { AstraSDKConfig } from '../types'; export class ApiClient { private config: Required; constructor(config: Required) { this.config = config; } /** * Make a GET request */ async get( endpoint: string, options?: Omit ): Promise> { return this.request(endpoint, { ...options, method: 'GET' }); } /** * Make a POST request */ async post( endpoint: string, body?: unknown, options?: Omit ): Promise> { return this.request(endpoint, { ...options, method: 'POST', body }); } /** * Make a PUT request */ async put( endpoint: string, body?: unknown, options?: Omit ): Promise> { return this.request(endpoint, { ...options, method: 'PUT', body }); } /** * Make a PATCH request */ async patch( endpoint: string, body?: unknown, options?: Omit ): Promise> { return this.request(endpoint, { ...options, method: 'PATCH', body }); } /** * Make a DELETE request */ async delete( endpoint: string, options?: Omit ): Promise> { return this.request(endpoint, { ...options, method: 'DELETE' }); } /** * Make a generic request */ async request( endpoint: string, options: RequestOptions = {} ): Promise> { const requestFn = () => makeRequest(endpoint, options, { apiKey: this.config.apiKey, baseURL: this.config.baseURL, timeout: this.config.timeout, headers: this.config.headers, }); if (this.config.retries > 0) { return retryRequest(requestFn, this.config.retries, this.config.retryDelay); } return requestFn(); } /** * Update configuration */ updateConfig(config: Partial): void { this.config = { ...this.config, ...config, headers: { ...this.config.headers, ...config.headers, }, }; } /** * Get current configuration */ getConfig(): Required { return { ...this.config }; } }