@rudderstack/integrations-lib
Version:
A comprehensive TypeScript library providing shared utilities, SDKs, and tools for RudderStack integrations and destinations.
128 lines • 4.46 kB
TypeScript
import { AxiosRequestConfig, AxiosResponseHeaders, RawAxiosResponseHeaders } from 'axios';
type ResponseHeaders = RawAxiosResponseHeaders | AxiosResponseHeaders | undefined;
export type ResponseParser<T> = (responseData: unknown) => T;
export type SuccessfulApiResponse<T> = {
type: 'success';
statusCode: number;
responseBody: T;
headers: ResponseHeaders;
};
export type ClientErrorApiResponse = {
type: 'client-error';
statusCode: number;
message: string;
};
export type ApplicationErrorApiResponse = {
type: 'application-error';
statusCode: number;
message: string;
responseBody: unknown;
headers: ResponseHeaders;
};
export type ApiResponse<T> = SuccessfulApiResponse<T> | ClientErrorApiResponse | ApplicationErrorApiResponse;
export type RequestConfig = AxiosRequestConfig & {
statTags?: StatTags;
};
/**
* HTTP Logger interface compatible with transformer's logger pattern
* Provides request/response logging capabilities for HTTP wrapper
*/
export type Metadata = {
destinationId?: string;
sourceId?: string;
workspaceId?: string;
destType?: string;
destinationType?: string;
module?: string;
implementation?: string;
feature?: string;
};
export type RequestLogParams = {
metadata?: Metadata | Metadata[] | undefined;
requestDetails: {
url?: string;
body?: unknown;
method?: string;
[key: string]: unknown;
};
};
export type ResponseLogParams = {
metadata?: Metadata | Metadata[] | undefined;
responseDetails: {
body?: unknown;
status?: number;
headers?: Record<string, string> | unknown;
[key: string]: unknown;
};
};
export interface IHttpLogger {
requestLog(message: string, data?: RequestLogParams): void;
responseLog(message: string, data?: ResponseLogParams): void;
error?(message: string, data?: unknown): void;
warn?(message: string, data?: unknown): void;
info?(message: string, data?: unknown): void;
debug?(message: string, data?: unknown): void;
}
/**
* HTTP Stats Client interface compatible with transformer's stats pattern
* Provides metrics collection capabilities for HTTP wrapper
*/
export interface IHttpStatsClient {
timing(name: string, value: Date, tags?: Record<string, unknown>): void;
increment(name: string, value?: number, tags?: Record<string, unknown>): void;
counter(name: string, value: number, tags?: Record<string, unknown>): void;
}
/**
* StatTags interface for metadata and metrics tagging
* Compatible with transformer's statTags structure
*/
export interface StatTags {
[key: string]: unknown;
cluster?: string;
namespace?: string;
instanceName?: string;
destType?: string;
destinationId?: string;
workspaceId?: string;
sourceId?: string;
feature?: string;
endpointPath?: string;
requestMethod?: string;
module?: string;
statusCode?: number;
implementation?: string;
success?: boolean;
metadata?: Metadata | Metadata[];
}
/**
* HTTP Client Configuration interface with optional dependencies
* Enables flexible configuration for different usage scenarios
*/
export interface HttpClientConfig {
logger?: IHttpLogger;
statsClient?: IHttpStatsClient;
defaultTimeout?: number;
defaultStatTags?: Record<string, unknown>;
}
/**
* AxiosClient Observability Configuration interface for optional metrics and logging
*/
export interface AxiosClientObservabilityConfig {
statsClient?: IHttpStatsClient;
logger?: IHttpLogger;
defaultStatTags?: Record<string, unknown>;
}
/**
* @deprecated Use AxiosClientObservabilityConfig instead
*/
export interface AxiosClientConfig extends AxiosClientObservabilityConfig {
}
export interface HttpClient {
post: <T>(url: string, data: unknown, options?: RequestConfig, responseParser?: ResponseParser<T>) => Promise<ApiResponse<T>>;
get: <T>(url: string, options?: RequestConfig, responseParser?: ResponseParser<T>) => Promise<ApiResponse<T>>;
put: <T>(url: string, data: unknown, options?: RequestConfig, responseParser?: ResponseParser<T>) => Promise<ApiResponse<T>>;
patch: <T>(url: string, data: unknown, options?: RequestConfig, responseParser?: ResponseParser<T>) => Promise<ApiResponse<T>>;
delete: <T>(url: string, options?: RequestConfig, responseParser?: ResponseParser<T>) => Promise<ApiResponse<T>>;
}
export {};
//# sourceMappingURL=types.d.ts.map