import { NexaBaseConfig, AuthResponse, User, NexaBaseEvents, EventCallback, Collection, Document, CollectionSchema, DocumentQueryOptions, CollectionQueryOptions, CreateDocumentData, UpdateDocumentData, DocumentOptions, Report, PaginatedResponse } from "./types"; import { NexaFunctions } from "./functions"; import { NexaWebhooks } from "./webhooks"; import { NexaStorage } from "./storage"; import { NexaQuery } from "./query"; import { NexaQueryBuilder } from "./query-builder"; import { NexaUsers } from "./users"; export interface ApiAuthResponse { success: boolean; access_token: string; refresh_token: string; expires_in: number; token_type: string; user: { id: string; email: string; role: string; tenant_id: string; }; organization: { id: string; name: string; slug: string; }; } export interface ApiKeyInfo { id: string; name: string; key?: string; permissions: string[]; expires_at: string | null; is_active: boolean; last_used_at: string | null; usage_count: number; created_at: string; } export declare class NexaBase { private client; private apiKey?; private accessToken?; private refreshToken?; private tokenExpiry?; private organizationInfo?; private config; private eventListeners; private _currentIdempotencyKey?; private _functions?; private _webhooks?; private _storage?; private _users?; private retryCount; private maxRetries; private retryBaseDelayMs; private maxRetryDelayMs; private refreshPromise?; private isRefreshing; constructor(config: NexaBaseConfig); private setupInterceptors; /** * Backoff exponencial con jitter: base * 2^attempt + jitter aleatorio * (evita thundering herd cuando varios clientes reintentan a la vez), * acotado por maxRetryDelayMs. */ private backoffDelay; private _unwrap; /** * ✅ Normaliza las opciones de consulta para el backend. * Convierte filtros estructurados y agregaciones al formato esperado. * Maneja discrepancias entre los formatos GET (URL) y POST (JSON). */ private _prepareQueryOptions; /** * ✅ Traduce los operadores simbólicos del SDK (>=, <=, ==) * a los nombres esperados por el backend (gte, lte, eq) en peticiones POST. */ private _normalizeFilters; private sleep; private clearTokens; private handleAxiosError; on(event: NexaBaseEvents, callback: EventCallback): this; off(event: NexaBaseEvents, callback: EventCallback): this; private emit; signInApi(email: string, password: string): Promise; signIn(email: string, password: string, useApiAuth?: boolean): Promise; refreshAccessToken(): Promise; private _performRefresh; signUp(email: string, password: string, userData?: any): Promise; signOut(): Promise; getCurrentUser(): Promise; externalLogin(configName: string, id: string, secret: string): Promise; externalLogout(): Promise; getApiKeys(): Promise; createApiKey(name: string, permissions?: string[], expiresInDays?: number): Promise; deleteApiKey(keyId: string): Promise; updateProfile(data: any): Promise; changePassword(current: string, next: string): Promise; isAuthenticated(): boolean; getConfig(): NexaBaseConfig; getOrganization(): { id: string; name: string; slug: string; } | null; getTokenInfo(): { hasToken: boolean; isValid: boolean; canRefresh: boolean; expiresIn: number; organization: { id: string; name: string; slug: string; } | undefined; }; ping(): Promise; get functions(): NexaFunctions; get webhooks(): NexaWebhooks; get storage(): NexaStorage; get users(): NexaUsers; from(collection: string): NexaQuery; createQuery(collection: string): NexaQueryBuilder; query(collection: string): NexaQueryBuilder; setApiKey(apiKey: string): void; setToken(token: string): void; withIdempotency(key: string): this; listCollections(options?: CollectionQueryOptions): Promise>; getCollection(name: string): Promise; getCollectionSchema(name: string): Promise; promoteCollection(name: string, targetTenantId: string): Promise; listDocuments(collectionName: string, options?: DocumentQueryOptions): Promise>; queryDocuments(collectionName: string, options: DocumentQueryOptions): Promise>; createDocument(collectionName: string, data: CreateDocumentData, options?: DocumentOptions): Promise; /** * Crea muchos documentos en una sola request/transacción del lado del * servidor (máximo 5000 por llamada). Usar esto en vez de llamar a * `createDocument()` en un loop para cargas de más de unas pocas * decenas de registros: cada `createDocument()` individual abre su * propia transacción y actualiza el mismo contador de la colección — * con concurrencia (incluso baja) y varios registros compartiendo el * mismo valor de un campo relacionado, Postgres puede terminar en * deadlock real del lado del servidor. */ createDocumentsBulk(collectionName: string, records: Record[]): Promise<{ success: boolean; inserted: number; ids: string[]; records: Document[]; errors: Array<{ index: number; error: string; }>; }>; /** * Borra muchos documentos por id en una sola request/transacción del * lado del servidor (máximo 5000 por llamada). Misma razón que * `createDocumentsBulk` — evita el mismo patrón de deadlock del lado * del borrado individual repetido. */ deleteDocumentsBulk(collectionName: string, ids: string[]): Promise<{ success: boolean; deleted: number; deleted_ids: string[]; not_found: string[]; }>; getDocument(collectionName: string, id: string, options?: any): Promise; updateDocument(collectionName: string, id: string, data: UpdateDocumentData, options?: DocumentOptions): Promise; replaceDocument(collectionName: string, id: string, data: UpdateDocumentData, options?: DocumentOptions): Promise; deleteDocument(collectionName: string, id: string, options?: DocumentOptions): Promise; createDocumentWithFile(collectionName: string, data: CreateDocumentData, file?: File, fieldName?: string, options?: DocumentOptions): Promise; updateDocumentWithFile(collectionName: string, id: string, data: UpdateDocumentData, file?: File, fieldName?: string, options?: DocumentOptions): Promise; listReports(): Promise; getReport(id: string): Promise; saveReport(report: Partial): Promise; deleteReport(id: string): Promise; getTenantInfo(): Promise; }