export interface NexaBaseConfig { baseURL: string; apiKey?: string; token?: string; tenant?: string; timeout?: number; customHeaders?: Record; debug?: boolean; idempotencyKey?: string; /** * ✅ Keep-alive de conexiones en Node/Bun: reutiliza sockets TCP+TLS entre * llamadas en vez de hacer handshake completo por request (~400ms ahorrados). * En browser se ignora (el navegador ya reutiliza conexiones). Default: true. */ keepAlive?: boolean; /** * ✅ Reintentos automáticos ante HTTP 429 (rate limit). * El backend rechaza con 429 ANTES de ejecutar lógica de negocio, así que * reintentar es seguro incluso para escrituras. Default: 3. */ maxRetries?: number; /** * Delay base del backoff exponencial cuando no hay header Retry-After. * Default: 500ms (500 -> 1000 -> 2000...). */ retryBaseDelayMs?: number; /** * Tope del delay entre reintentos. Si el backend envía Retry-After mayor * que este valor, la petición falla inmediatamente en vez de colgar al * consumidor esperando la ventana completa. Default: 10000ms. */ maxRetryDelayMs?: number; } export interface NexaBaseError { code: string; message: string; statusCode: number; details?: Record; } export interface AuthResponse { access_token: string; refresh_token: string; expires_in: number; token_type: string; user: User; } export interface User { id: string; email: string; name?: string; avatar?: string; created_at: string; updated_at: string; [key: string]: any; } export interface CreateUser { email: string; password?: string; first_name: string; last_name: string; role?: string; tenantId?: string; status?: string; } export interface UpdateUser { email?: string; password?: string; first_name?: string; last_name?: string; role?: string; status?: string; is_active?: boolean; } export interface NexaResponse { success: boolean; statusCode: number; data: T; meta?: { total: number; page: number; per_page: number; total_pages: number; limit?: number; totalPages?: number; hasNext?: boolean; hasPrev?: boolean; }; timestamp: string; } export interface StandardResponse extends NexaResponse { links?: { self: string; next?: string; prev?: string; first: string; last: string; }; } export type PaginatedResponse = NexaResponse; export interface Collection { id: string; name: string; description?: string; record_count: number; is_active: boolean; schema?: Record; created_at: string; updated_at: string; } export interface CollectionSchema { collection: string; schema: Record; fields: Record; created_at?: string; updated_at?: string; } export interface Document { id: string; created_at: string; updated_at: string; [key: string]: any; } export interface CollectionQueryOptions { page?: number; per_page?: number; sort?: string; fields?: string; search?: string; filter?: Record; logical?: 'AND' | 'OR'; include?: string; } export declare enum AggregateFunction { COUNT = "count", SUM = "sum", AVG = "avg", MIN = "min", MAX = "max", MONTH = "month", YEAR = "year", DAY = "day" } export interface AggregateDto { function: AggregateFunction | string; field: string; alias?: string; } export interface IDTOFilter { field?: string; operator?: string; value?: any; logical?: 'AND' | 'OR'; filters?: IDTOFilter[]; } export interface DocumentQueryOptions { page?: number; per_page?: number; sort?: string; fields?: string; search?: string; filter?: Record; filters?: IDTOFilter[]; logical?: 'AND' | 'OR'; include?: string; group_by?: string; aggregate?: Record; aggregates?: AggregateDto[]; } export interface CreateDocumentData { [key: string]: any; } export interface UpdateDocumentData { [key: string]: any; } /** * Opciones para operaciones de documentos (v2.12.0+) */ export interface DocumentOptions { idempotencyKey?: string; customHeaders?: Record; } export interface QueryOptions { page?: number; limit?: number; sort?: string; select?: string; filter?: Record; q?: string; } /** * Información de archivo almacenado */ export interface StorageFile { id: string; url: string; filename: string; original_name: string; mime_type: string; size: number; } /** * Respuesta de crear/actualizar documento con archivo */ export interface DocumentWithFileResponse { data: Document; file_uploaded?: boolean; file_updated?: boolean; timestamp: string; } export interface TenantInfo { id: string; name: string; subdomain: string; plan: string; config: TenantConfig; created_at: string; updated_at: string; } export interface TenantConfig { custom_domain?: string; branding?: { logo?: string; primary_color?: string; secondary_color?: string; }; features?: { realtime_enabled: boolean; file_upload_enabled: boolean; webhooks_enabled: boolean; }; limits?: { max_collections: number; max_records_per_collection: number; max_file_size_mb: number; }; } export interface Plan { id: string; name: string; description?: string; price_monthly: number; price_yearly: number; features: PlanFeatures; limits: PlanLimits; is_popular?: boolean; is_enterprise?: boolean; } export interface PlanFeatures { collections: boolean; realtime: boolean; file_storage: boolean; custom_domain: boolean; webhooks: boolean; api_access: boolean; advanced_auth: boolean; priority_support: boolean; } export interface PlanLimits { database_rows: number; storage_gb: number; bandwidth_gb: number; api_requests: number; collections: number; webhooks: number; } export interface TenantSubscription { id: string; tenant_id: string; plan: Plan; status: "active" | "inactive" | "cancelled" | "past_due"; current_period_start: string; current_period_end: string; cancel_at_period_end: boolean; created_at: string; updated_at: string; current_usage: { database_rows_count: number; storage_used_gb: number; bandwidth_used_gb: number; api_requests_count: number; collections_count: number; webhooks_count: number; }; } export interface UsageStats { tenant_id: string; plan: Plan; current_usage: { database_rows_count: number; storage_used_gb: number; bandwidth_used_gb: number; api_requests_count: number; collections_count: number; webhooks_count: number; }; limits: PlanLimits; usage_percentages: { database_rows: number; storage: number; bandwidth: number; api_requests: number; collections: number; webhooks: number; }; period_start: string; period_end: string; } export interface PlanUpgradeRequest { billing_cycle: "monthly" | "yearly"; payment_method_id?: string; coupon_code?: string; } export type NexaBaseEvents = "auth:signin" | "auth:signup" | "auth:signout" | "auth:token-expired" | "auth:token-refreshed" | "ratelimit:retry" | "document:created" | "document:updated" | "document:replaced" | "document:deleted" | "documents:bulk_created" | "documents:bulk_deleted" | "collection:created" | "collection:updated" | "collection:deleted" | "api:key-created" | "api:key-deleted" | "profile:updated" | "profile:password-changed" | "error" | "connection:open" | "connection:close" | "connection:error"; export type EventCallback = (data: any) => void; export type RealtimeEvents = "insert" | "update" | "delete" | "presence" | "broadcast" | "*"; export interface RealtimeMessage { event: RealtimeEvents; collection?: string; record?: Document; old_record?: Document; user_id?: string; timestamp: string; } export interface RealtimeSubscription { id: string; collection: string; events: RealtimeEvents[]; filters?: Record; callback: (message: RealtimeMessage) => void; } export interface RealtimeConfig { baseURL: string; apiKey?: string; token?: string; reconnect?: boolean; maxReconnectAttempts?: number; reconnectInterval?: number; heartbeatInterval?: number; /** * Wire protocol to speak with the realtime endpoint. * - "websocket" (default): plain WebSocket frames — required for backend-v2 (Rust/Axum, native ws). * - "socketio": Socket.IO/Engine.IO framing — required for backend-v1 (NestJS, @nestjs/websockets * over socket.io). backend-v1's /realtime gateway does not speak plain WebSocket, so a client * connecting with "websocket" against it will fail to connect at all. */ transport?: "websocket" | "socketio"; } export interface RealtimeConnection { id: string; status: "connecting" | "connected" | "disconnected" | "error"; subscriptions: Map; reconnectAttempts: number; lastHeartbeat?: Date; } export interface RealtimeEvent { type: RealtimeEvents; collection: string; data?: any; old_data?: any; user_id?: string; timestamp: string; } export interface RealtimeSubscriptionOptions { events?: RealtimeEvents[]; filters?: Record; } export interface FunctionInvokeOptions { method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; headers?: Record; timeout?: number; } export interface FunctionResponse { success: boolean; data: T; execution_time: number; timestamp: string; } export interface Webhook { id: string; name: string; url: string; events: string[]; is_active: boolean; secret?: string; created_at: string; updated_at: string; } export interface CreateWebhookData { name: string; url: string; events: string[]; is_active?: boolean; } export declare enum NexaBaseErrorCodes { UNAUTHORIZED = "UNAUTHORIZED", FORBIDDEN = "FORBIDDEN", NOT_FOUND = "NOT_FOUND", VALIDATION_ERROR = "VALIDATION_ERROR", PLAN_LIMIT_REACHED = "PLAN_LIMIT_REACHED", TENANT_NOT_FOUND = "TENANT_NOT_FOUND", COLLECTION_NOT_FOUND = "COLLECTION_NOT_FOUND", DOCUMENT_NOT_FOUND = "DOCUMENT_NOT_FOUND", FUNCTION_NOT_FOUND = "FUNCTION_NOT_FOUND",// ✅ AGREGADO FUNCTION_EXECUTION_ERROR = "FUNCTION_EXECUTION_ERROR",// ✅ AGREGADO INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR", NETWORK_ERROR = "NETWORK_ERROR", TIMEOUT_ERROR = "TIMEOUT_ERROR", REALTIME_CONNECTION_ERROR = "REALTIME_CONNECTION_ERROR", REALTIME_SUBSCRIPTION_ERROR = "REALTIME_SUBSCRIPTION_ERROR" } /** * Definition of a report for creation/update */ export interface ReportDefinition { name: string; definition: any; is_active?: boolean; } /** * Full Report entity */ export interface Report extends ReportDefinition { id: string; tenant_id: string; created_at: string; updated_at: string; created_by?: string; updated_by?: string; }