UNPKG

@rudderstack/integrations-lib

Version:

A comprehensive TypeScript library providing shared utilities, SDKs, and tools for RudderStack integrations and destinations.

64 lines 2.88 kB
import { ApiResponse, HttpClient, StatTags } from '../../network/clients/types'; import { BaseSDKConfig } from './types'; export type { BaseSDKConfig }; /** * Abstract base class for all SDKs * Provides common functionality including HTTP client management, request execution, * retry logic, and enhanced features when configured */ export declare abstract class BaseSDK<TAuthObject, TConfig extends BaseSDKConfig = BaseSDKConfig> { protected authObject: TAuthObject; protected httpClient: HttpClient; protected config?: TConfig; constructor(authObject: TAuthObject, config?: TConfig); validateAuthObject(_authObject: unknown): void; protected abstract buildRequestUrl(endpoint: string): string; protected getHeaders(): Record<string, string>; shouldRetryOnError(_response: ApiResponse<unknown>): boolean; protected refreshToken?(): Promise<void>; /** * Initialize HTTP client based on configuration * Uses enhanced client with metrics/logging if config provided, otherwise basic client * No baseURL is set - SDKs will use buildRequestUrl() to construct full URLs */ private initializeHttpClient; /** * Execute HTTP request - single attempt, no retry logic */ protected executeRequest<T>(method: 'get' | 'post' | 'put' | 'delete' | 'patch', endpoint: string, data?: unknown, statTags?: StatTags): Promise<ApiResponse<T>>; /** * Execute HTTP request with configurable token refresh attempts * For SDKs that need more control over retry behavior */ protected executeRequestWithTokenRefreshAttempts<T>(method: 'get' | 'post' | 'put' | 'delete' | 'patch', endpoint: string, data?: unknown, statTags?: StatTags, maxRetries?: number): Promise<ApiResponse<T>>; /** * Internal recursive method for retry attempts */ private executeRequestWithRetryAttempt; /** * Make HTTP request based on method - eliminates code duplication * Passes statTags to HTTP client for metrics and logging */ private makeHttpRequest; /** * Convenience method for GET requests */ protected get<T>(endpoint: string, statTags?: StatTags): Promise<ApiResponse<T>>; /** * Convenience method for POST requests */ protected post<T>(endpoint: string, data: unknown, statTags?: StatTags): Promise<ApiResponse<T>>; /** * Convenience method for PUT requests */ protected put<T>(endpoint: string, data: unknown, statTags?: StatTags): Promise<ApiResponse<T>>; /** * Convenience method for DELETE requests */ protected delete<T>(endpoint: string, statTags?: StatTags): Promise<ApiResponse<T>>; /** * Convenience method for PATCH requests */ protected patch<T>(endpoint: string, data: unknown, statTags?: StatTags): Promise<ApiResponse<T>>; } //# sourceMappingURL=base-sdk.d.ts.map