/** * AgentMeter SDK TypeScript Type Definitions * Contains all interfaces and types for the AgentMeter API integration */ /** * Standard API response wrapper used by all AgentMeter endpoints */ interface ApiResponse { success: boolean; data?: T; error?: { code: string; message: string; details?: any; }; meta?: { page?: number; limit?: number; total?: number; }; } /** * Application entity representing a registered app in AgentMeter */ interface App { id: string; merchant_id: string; name: string; description?: string; api_key: string; webhook_url?: string; created_at: string; updated_at: string; status: 'active' | 'inactive'; meters?: { count: number; }[]; app_users?: { count: number; }[]; } /** * Meter entity defining how events are aggregated and billed */ interface Meter { id: string; app_id: string; name: string; description?: string; event_name: string; aggregation_method: 'SUM' | 'COUNT' | 'UNIQUE_COUNT' | 'AVG' | 'MAX' | 'MIN'; aggregation_key?: string; group_by?: string[]; price_per_unit: number; currency: 'USD' | 'EUR' | 'GBP' | 'CNY'; billing_cycle: 'hourly' | 'daily' | 'weekly' | 'monthly'; created_at: string; updated_at: string; status: 'active' | 'inactive'; } /** * Event entity representing a tracked user action or API call */ interface Event { id: string; app_id: string; event_name: string; user_id?: string; properties: Record; value?: number; timestamp: string; created_at: string; } /** * Usage entity representing aggregated usage data for billing */ interface Usage { id: string; meter_id: string; app_id: string; user_id?: string; period_start: string; period_end: string; aggregated_value: number; group_values?: Record; cost: number; created_at: string; } /** * Usage summary providing comprehensive billing overview */ interface UsageSummary { app_id: string; meters: { meter: Meter; total_usage: number; total_cost: number; usage_records: number; }[]; summary: { total_cost: number; total_meters: number; active_users: number; total_events: number; }; } /** * Time series usage data for charts and analytics */ interface UsageTimeSeries { meter_id: string; interval: 'hour' | 'day' | 'week' | 'month'; data_points: { timestamp: string; value: number; cost: number; user_count?: number; }[]; } /** * Request payload for creating a new application */ interface CreateAppRequest { name: string; description?: string; webhook_url?: string; } /** * Request payload for updating an existing application */ interface UpdateAppRequest { name?: string; description?: string; webhook_url?: string; status?: 'active' | 'inactive'; } /** * Request payload for creating a new meter */ interface CreateMeterRequest { name: string; description?: string; event_name: string; aggregation_method: 'SUM' | 'COUNT' | 'UNIQUE_COUNT' | 'AVG' | 'MAX' | 'MIN'; aggregation_key?: string; group_by?: string[]; price_per_unit: number; currency: 'USD' | 'EUR' | 'GBP' | 'CNY'; billing_cycle: 'hourly' | 'daily' | 'weekly' | 'monthly'; app_id?: string; } /** * Request payload for updating an existing meter */ interface UpdateMeterRequest { name?: string; description?: string; aggregation_method?: 'SUM' | 'COUNT' | 'UNIQUE_COUNT' | 'AVG' | 'MAX' | 'MIN'; aggregation_key?: string; group_by?: string[]; price_per_unit?: number; currency?: 'USD' | 'EUR' | 'GBP' | 'CNY'; billing_cycle?: 'hourly' | 'daily' | 'weekly' | 'monthly'; status?: 'active' | 'inactive'; } /** * Request payload for tracking a single event */ interface CreateEventRequest { event_name: string; user_id?: string; properties?: Record; value?: number; timestamp?: string; } /** * Query parameters for fetching events */ interface EventsQueryParams { app_id?: string; event_name?: string; user_id?: string; start_date?: string; end_date?: string; page?: number; limit?: number; } /** * Query parameters for fetching usage data */ interface UsageQueryParams { app_id: string; meter_id?: string; user_id?: string; period_start?: string; period_end?: string; group_by?: string; } /** * Query parameters for fetching usage timeseries */ interface UsageTimeSeriesParams { meter_id: string; interval?: 'hour' | 'day' | 'week' | 'month'; start_date?: string; end_date?: string; } /** * SDK configuration options */ interface AgentMeterConfig { apiKey: string; baseUrl?: string; timeout?: number; retryAttempts?: number; retryDelay?: number; debug?: boolean; } /** * Custom error class for AgentMeter API errors */ declare class AgentMeterError extends Error { readonly code: string; readonly statusCode?: number; readonly details?: any; constructor(message: string, code: string, statusCode?: number, details?: any); } /** * Validation error for request parameters */ declare class ValidationError extends AgentMeterError { constructor(message: string, details?: any); } /** * Network error for connection issues */ declare class NetworkError extends AgentMeterError { constructor(message: string, details?: any); } /** * AgentMeter SDK Main Client * Main client class providing all AgentMeter API functionality */ /** * Main AgentMeter SDK client */ declare class AgentMeterClient { private httpClient; private config; /** * Create a new AgentMeter client instance * * @param config - Configuration object containing API key and optional settings */ constructor(config: AgentMeterConfig); /** * Create a new application */ createApp(request: CreateAppRequest): Promise>; /** * Get all applications */ getApps(): Promise>; /** * Get a specific application by ID */ getApp(id: string): Promise>; /** * Update an existing application */ updateApp(id: string, request: UpdateAppRequest): Promise>; /** * Delete an application */ deleteApp(id: string): Promise>; /** * Create a new meter */ createMeter(request: CreateMeterRequest): Promise>; /** * Get meters for a specific app */ getMeters(appId: string): Promise>; /** * Get a specific meter by ID with statistics */ getMeter(id: string): Promise>; /** * Update an existing meter */ updateMeter(id: string, request: UpdateMeterRequest): Promise>; /** * Delete a meter */ deleteMeter(id: string): Promise>; /** * Track a single event */ trackEvent(request: CreateEventRequest): Promise>; /** * Track multiple events in batch */ trackEvents(events: CreateEventRequest[]): Promise>; /** * Query events with filters */ getEvents(params?: EventsQueryParams): Promise>; /** * Get usage summary for billing */ getUsage(params: UsageQueryParams): Promise>; /** * Get usage data over time for analytics */ getUsageTimeSeries(params: UsageTimeSeriesParams): Promise>; /** * Quick method to track API calls with user info */ trackApiCall(userId: string, endpoint: string, method?: string, properties?: Record): Promise>; /** * Quick method to track feature usage */ trackFeatureUsage(userId: string, featureName: string, value?: number, properties?: Record): Promise>; /** * Get billing summary for a specific period */ getBillingSummary(appId: string, periodStart: string, periodEnd: string, groupByUser?: boolean): Promise>; /** * Get current configuration */ getConfig(): Readonly>; /** * Update API key */ updateApiKey(newApiKey: string): void; } /** * Validation utilities for AgentMeter SDK */ /** * Validates that a value is a non-empty string */ declare function validateRequiredString(value: any, fieldName: string): void; /** * Validates that a value is a positive number */ declare function validatePositiveNumber(value: any, fieldName: string): void; /** * Validates an email format */ declare function validateEmail(email: string): boolean; /** * Validates a URL format */ declare function validateUrl(url: string): boolean; /** * Validates ISO date string format */ declare function validateISODate(date: string): boolean; /** * Validates API key format */ declare function validateApiKey(apiKey: string): void; /** * Validates pagination parameters */ declare function validatePaginationParams(page?: number, limit?: number): void; /** * HTTP utilities for AgentMeter SDK * HTTP request utilities with retry logic and error handling */ /** * HTTP client configuration */ interface HttpConfig { baseUrl: string; apiKey: string; timeout: number; retryAttempts: number; retryDelay: number; debug: boolean; } /** * HTTP response interface */ interface HttpResponse { data: T; status: number; statusText: string; headers: Record; } /** * HTTP client with automatic retries and error handling */ declare class HttpClient { private config; constructor(config: HttpConfig); /** * Make HTTP request with retries */ request(endpoint: string, options?: RequestInit): Promise>; /** * Make a single HTTP request */ private makeRequest; /** * Helper method for GET requests */ get(endpoint: string, params?: Record): Promise>; /** * Helper method for POST requests */ post(endpoint: string, body?: any): Promise>; /** * Helper method for PUT requests */ put(endpoint: string, body?: any): Promise>; /** * Helper method for DELETE requests */ delete(endpoint: string): Promise>; } /** * AgentMeter SDK for TypeScript * TypeScript SDK for AgentMeter usage-based billing API integration */ /** * Create a new AgentMeter client instance with API key * * @param apiKey - Your AgentMeter API key * @param options - Optional configuration settings * @returns Configured AgentMeter client */ declare function createClient(apiKey: string, options?: Omit): AgentMeterClient; declare const SDK_VERSION = "1.0.0"; declare const SDK_NAME = "agentmeter"; /** * SDK Information */ declare const SDK_INFO: { readonly name: "agentmeter"; readonly version: "1.0.0"; readonly description: "TypeScript SDK for AgentMeter usage-based billing API"; readonly repository: "https://github.com/agentmeter/agentmeter-sdk-typescript"; readonly documentation: "https://docs.agentmeter.com"; }; export { AgentMeterClient, AgentMeterConfig, AgentMeterError, ApiResponse, App, CreateAppRequest, CreateEventRequest, CreateMeterRequest, Event, EventsQueryParams, HttpClient, HttpConfig, HttpResponse, Meter, NetworkError, SDK_INFO, SDK_NAME, SDK_VERSION, UpdateAppRequest, UpdateMeterRequest, Usage, UsageQueryParams, UsageSummary, UsageTimeSeries, UsageTimeSeriesParams, ValidationError, createClient, AgentMeterClient as default, validateApiKey, validateEmail, validateISODate, validatePaginationParams, validatePositiveNumber, validateRequiredString, validateUrl };