UNPKG

apisix-sdk

Version:

Apache APISIX SDK - Complete TypeScript/JavaScript client for APISIX Admin API and Control API with APISIX 3.0+ support

1,826 lines (1,815 loc) 72.4 kB
interface ApisixResponse<T> { node?: { key: string; value: T; createdIndex?: number; modifiedIndex?: number; }; key?: string; value?: T; createdIndex?: number; modifiedIndex?: number; action?: string; } interface ApisixListResponse<T> { total?: number; list?: Array<{ key: string; value: T; createdIndex?: number; modifiedIndex?: number; }>; has_more?: boolean; node?: { key: string; nodes: Array<{ key: string; value: T; createdIndex?: number; modifiedIndex?: number; }>; dir?: boolean; }; count?: number; action?: string; } interface ListOptions { page?: number; page_size?: number; name?: string; label?: string; uri?: string; search?: string; sort?: string; order?: "asc" | "desc"; status?: 0 | 1; method?: string | string[]; host?: string; plugin?: string; upstream_id?: string; service_id?: string; consumer_id?: string; created_after?: number; created_before?: number; updated_after?: number; updated_before?: number; fields?: string[]; exclude_fields?: string[]; with_count?: boolean; [key: string]: string | number | boolean | string[] | undefined; } interface ErrorResponse { error_msg: string; } interface Route { id?: string; name?: string; desc?: string; uri?: string; uris?: string[]; methods?: string[]; host?: string; hosts?: string[]; remote_addr?: string; remote_addrs?: string[]; vars?: Array<[string, string, string]>; filter_func?: string; plugins?: Record<string, unknown>; upstream?: Upstream; upstream_id?: string; service_id?: string; plugin_config_id?: string; priority?: number; enable_websocket?: boolean; timeout?: { connect?: number; send?: number; read?: number; }; status?: 0 | 1; labels?: Record<string, string>; create_time?: number; update_time?: number; } interface Service { id?: string; name?: string; desc?: string; upstream?: Upstream; upstream_id?: string; plugins?: Record<string, unknown>; plugin_config_id?: string; hosts?: string[]; enable_websocket?: boolean; labels?: Record<string, string>; create_time?: number; update_time?: number; } type UpstreamType = "roundrobin" | "chash" | "ewma" | "least_conn"; type HashOn = "vars" | "header" | "cookie" | "consumer"; type HealthCheckType = "http" | "https" | "tcp"; type UpstreamScheme = "http" | "https" | "grpc" | "grpcs" | "tcp" | "udp" | "tls"; type PassHost = "pass" | "node" | "rewrite"; interface UpstreamNode { host: string; port: number; weight: number; priority?: number; metadata?: Record<string, unknown>; } interface HealthCheck { active?: { type?: HealthCheckType; timeout?: number; concurrency?: number; http_path?: string; https_verify_certificate?: boolean; req_headers?: string[]; healthy?: { interval?: number; http_statuses?: number[]; successes?: number; }; unhealthy?: { interval?: number; http_statuses?: number[]; http_failures?: number; tcp_failures?: number; timeouts?: number; }; }; passive?: { type?: HealthCheckType; healthy?: { http_statuses?: number[]; successes?: number; }; unhealthy?: { http_statuses?: number[]; http_failures?: number; tcp_failures?: number; timeouts?: number; }; }; } interface KeepalivePool { size?: number; idle_timeout?: number; requests?: number; } interface UpstreamTLS { client_cert?: string; client_key?: string; client_cert_id?: string; } interface Upstream { id?: string; name?: string; desc?: string; type?: UpstreamType; nodes?: Record<string, number> | UpstreamNode[]; service_name?: string; discovery_type?: string; hash_on?: HashOn; key?: string; checks?: HealthCheck; retries?: number; retry_timeout?: number; timeout?: { connect?: number; send?: number; read?: number; }; keepalive_pool?: KeepalivePool; scheme?: UpstreamScheme; pass_host?: PassHost; upstream_host?: string; tls?: UpstreamTLS; labels?: Record<string, string>; create_time?: number; update_time?: number; } interface Consumer { id?: string; username: string; desc?: string; plugins?: Record<string, unknown>; group_id?: string; labels?: Record<string, string>; create_time?: number; update_time?: number; } interface Credential { id?: string; plugins: Record<string, unknown>; desc?: string; labels?: Record<string, string>; create_time?: number; update_time?: number; } interface SSL { id?: string; cert: string; key: string; certs?: string[]; keys?: string[]; snis?: string[]; client?: { ca?: string; depth?: number; skip_mtls_uri_regex?: string[]; }; labels?: Record<string, string>; status?: 0 | 1; type?: "server" | "client"; ssl_protocols?: string[]; validity_start?: number; validity_end?: number; create_time?: number; update_time?: number; } interface GlobalRule { id?: string; plugins?: Record<string, unknown>; create_time?: number; update_time?: number; } interface ConsumerGroup { id?: string; desc?: string; plugins?: Record<string, unknown>; labels?: Record<string, string>; create_time?: number; update_time?: number; } interface PluginConfig { id?: string; desc?: string; plugins?: Record<string, unknown>; labels?: Record<string, string>; create_time?: number; update_time?: number; } interface StreamRoute { id?: string; desc?: string; remote_addr?: string; remote_addrs?: string[]; server_addr?: string; server_port?: number; sni?: string; upstream?: Upstream; upstream_id?: string; service_id?: string; plugins?: Record<string, unknown>; protocol?: { name?: string; conf?: Record<string, unknown>; }; create_time?: number; update_time?: number; } interface VaultSecret { id?: string; uri: string; prefix: string; token: string; namespace?: string; create_time?: number; update_time?: number; } interface AWSSecret { id?: string; access_key_id: string; secret_access_key: string; session_token?: string; region?: string; endpoint_url?: string; create_time?: number; update_time?: number; } interface GCPAuthConfig { client_email: string; private_key: string; project_id: string; token_uri?: string; entries_uri?: string; scope?: string[]; } interface GCPSecret { id?: string; auth_config?: GCPAuthConfig; auth_file?: string; ssl_verify?: boolean; create_time?: number; update_time?: number; } type Secret = VaultSecret | AWSSecret | GCPSecret; interface Plugin { name: string; version?: string; priority?: number; schema?: object; consumer_schema?: object; metadata_schema?: object; type?: string; disable?: boolean; } interface PluginInfo { name: string; version?: string; priority?: number; type?: string; status?: "enabled" | "disabled"; [key: string]: unknown; } interface PluginList { [key: string]: boolean; } interface PluginMetadata { id?: string; [key: string]: unknown; } interface HealthCheckStatus { status: "ok" | "error"; info?: { version: string; hostname: string; up_time: number; }; } interface UpstreamHealthNode { host: string; port: number; status: "healthy" | "unhealthy" | "mostly_healthy" | "mostly_unhealthy"; counter: { http_failure: number; tcp_failure: number; timeout_failure: number; success: number; }; } interface UpstreamHealth { name: string; type: "http" | "https" | "tcp"; nodes: UpstreamHealthNode[]; } interface ServerInfo { hostname: string; version: string; up_time: number; boot_time: number; last_report_time: number; etcd_version: string; } interface SchemaInfo { main: { route: { properties: object; }; upstream: { properties: object; }; service: { properties: object; }; consumer: { properties: object; }; ssl: { properties: object; }; [key: string]: { properties: object; }; }; plugins: Record<string, { consumer_schema?: object; metadata_schema?: object; schema?: object; type?: string; priority?: number; version?: number; }>; "stream-plugins": Record<string, object>; } interface DiscoveryServices { services: Record<string, Array<{ host: string; port: number; weight: number; }>>; expire: number; last_update: number; } interface ApisixSDKConfig { adminAPI: { baseURL: string; apiKey?: string; timeout?: number; headers?: Record<string, string>; }; controlAPI?: { baseURL: string; timeout?: number; headers?: Record<string, string>; }; } type CreateInput<T> = Omit<T, "id" | "create_time" | "update_time">; type UpdateInput<T> = Partial<Omit<T, "id" | "create_time" | "update_time">>; interface ForceDeleteOptions { force?: boolean; } interface TTLOptions { ttl?: number; } interface FilterOptions extends ListOptions { name?: string; label?: string; uri?: string; } interface Proto { id?: string; desc?: string; content: string; labels?: Record<string, string>; create_time?: number; update_time?: number; } interface PrometheusMetrics { metrics: string; } interface RequestStatistics { total_requests: number; requests_per_second: number; average_response_time: number; error_rate: number; } interface ConnectionStatistics { active_connections: number; total_connections: number; requests_per_connection: number; } interface ConsumerCredential { id?: string; plugins: Record<string, unknown>; desc?: string; create_time?: number; update_time?: number; } interface DiscoveryDumpNode { host: string; port: number; weight: number; default_weight: number; id: string; client: Record<string, unknown>; service: { host: string; port: number; proto: string; enable_ipv6: boolean; }; } interface DiscoveryDump { endpoints: Array<{ endpoints: Array<{ value: string; name: string; }>; id: string; }>; config: Array<{ default_weight: number; id: string; client: Record<string, unknown>; service: { host: string; port: string; schema: string; }; shared_size: string; }>; } interface DiscoveryDump { services: Record<string, DiscoveryDumpNode[]>; } interface DiscoveryDumpFile { path: string; size: number; last_modified: string; } interface VersionConfig { version: string; supportsCredentials: boolean; supportsSecrets: boolean; supportsNewResponseFormat: boolean; supportsStreamRoutes: boolean; supportedPlugins: string[]; deprecatedFeatures: string[]; } interface MigrationRecommendations { newFeatures: string[]; deprecatedFeatures: string[]; breakingChanges: string[]; } interface ValidationResult { valid: boolean; errors: string[]; warnings: string[]; } interface BatchOperation<T> { operation: "create" | "update" | "delete"; id?: string; data?: T; } interface BatchResult<T> { success: boolean; id?: string; data?: T; error?: string; } interface BatchResponse<T> { total: number; successful: number; failed: number; results: BatchResult<T>[]; } interface ImportOptions { strategy?: "replace" | "merge" | "skip_existing"; validate?: boolean; dry_run?: boolean; } interface ExportOptions { format?: "json" | "yaml" | "openapi"; include?: string[]; exclude?: string[]; pretty?: boolean; } interface ImportResult { total: number; created: number; updated: number; skipped: number; errors: Array<{ id?: string; error: string; }>; } interface OpenAPIRoute { operationId?: string; summary?: string; description?: string; tags?: string[]; security?: Array<Record<string, string[]>>; parameters?: Array<{ name: string; in: "path" | "query" | "header" | "cookie"; required?: boolean; schema?: object; description?: string; }>; requestBody?: { content: Record<string, { schema?: object; example?: unknown; }>; required?: boolean; }; responses?: Record<string, { description: string; content?: Record<string, { schema?: object; example?: unknown; }>; }>; "x-apisix-upstream"?: Upstream; "x-apisix-plugins"?: Record<string, unknown>; "x-apisix-service_id"?: string; "x-apisix-status"?: 0 | 1; "x-apisix-priority"?: number; "x-apisix-enableWebsocket"?: boolean; "x-apisix-labels"?: Record<string, string>; "x-apisix-vars"?: Array<[string, string, string]>; } interface OpenAPISpec { openapi: string; info: { title: string; version: string; description?: string; license?: { name: string; url?: string; }; }; servers?: Array<{ url: string; description?: string; }>; paths: Record<string, Record<string, OpenAPIRoute>>; components?: { securitySchemes?: Record<string, { type: string; scheme?: string; bearerFormat?: string; in?: string; name?: string; }>; schemas?: Record<string, object>; }; security?: Array<Record<string, string[]>>; } declare class ApisixClient { private adminBaseURL; private controlBaseURL; private apiKey?; private adminTimeout; private controlTimeout; private adminHeaders; private controlHeaders; private _serverInfo?; private _apiVersion?; private connectionPool; private retryAttempts; private retryDelay; private queryCache; private cacheTTL; constructor(config: ApisixSDKConfig); /** * Get cached server information or fetch if not available */ getServerInfo(): Promise<ServerInfo>; /** * Get APISIX version */ getVersion(): Promise<string>; /** * Check if current APISIX version is compatible with specified version */ isVersionCompatible(minVersion: string): Promise<boolean>; /** * Compare two version strings (returns -1, 0, or 1) */ private compareVersions; /** * Check if APISIX version is 3.0 or later */ isVersion3OrLater(): Promise<boolean>; /** * Get API version-specific configuration */ getApiVersionConfig(): Promise<{ supportsCredentials: boolean; supportsSecrets: boolean; supportsNewResponseFormat: boolean; supportsStreamRoutes: boolean; supportsPagination: boolean; }>; /** * Get or create connection from pool */ private getConnection; /** * Generate cache key for request */ private getCacheKey; /** * Get cached response if available and not expired */ private getCachedResponse; /** * Cache response data */ private cacheResponse; /** * Smart retry with exponential backoff */ private retryRequest; /** * Check if error should not be retried */ private isNonRetryableError; /** * Make HTTP request with proper authentication and error handling */ protected request<T>(endpoint: string, options?: { method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD"; headers?: Record<string, string>; body?: Record<string, unknown> | string; params?: Record<string, string | number | boolean | string[] | undefined>; signal?: AbortSignal; skipCache?: boolean; }): Promise<T>; /** * Get error message with suggestions */ private getErrorMessage; /** * GET request */ get<T>(endpoint: string, params?: Record<string, string | number | boolean | string[] | undefined>): Promise<T>; /** * POST request with optional cancellation support */ post<T>(endpoint: string, body?: Record<string, unknown> | string, options?: { signal?: AbortSignal; }): Promise<T>; /** * PUT request */ put<T>(endpoint: string, body?: Record<string, unknown> | string): Promise<T>; /** * PATCH request */ protected patch<T>(endpoint: string, body?: Record<string, unknown> | string): Promise<T>; /** * DELETE request */ protected delete<T>(endpoint: string): Promise<T>; /** * Check if current APISIX version supports pagination */ supportsPagination(): Promise<boolean>; /** * List resources with optional pagination and filtering * Automatically handles version compatibility */ list<T>(endpoint: string, options?: ListOptions): Promise<ApisixListResponse<T>>; /** * Get single resource */ getOne<T>(endpoint: string, id: string): Promise<ApisixResponse<T>>; /** * Create resource */ create<T>(endpoint: string, data: Record<string, unknown>, id?: string): Promise<ApisixResponse<T>>; /** * Update resource */ update<T>(endpoint: string, id: string, data: Record<string, unknown>): Promise<ApisixResponse<T>>; /** * Partially update resource */ partialUpdate<T>(endpoint: string, id: string, data: Record<string, unknown>): Promise<ApisixResponse<T>>; /** * Delete resource */ remove<T>(endpoint: string, id: string): Promise<ApisixResponse<T>>; /** * Delete resource with query parameters (e.g., force delete) */ removeWithQuery<T>(endpoint: string, id: string, queryParams?: Record<string, string | number | boolean | undefined>): Promise<ApisixResponse<T>>; /** * Extract value from APISIX response format (version-aware) */ extractValue<T>(response: ApisixResponse<T>): Promise<T>; /** * Extract list data from response, handling both v2.x and v3.x formats */ extractList<T>(response: unknown): T[]; /** * Extract pagination info from response */ extractPaginationInfo(response: unknown): { total: number; hasMore: boolean; }; /** * Get configuration for admin API endpoints */ getAdminEndpoint(path: string): string; /** * Get configuration for control API endpoints */ getControlEndpoint(path: string): string; /** * Make Control API request (convenience method) */ controlRequest<T>(endpoint: string, options?: { method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD"; headers?: Record<string, string>; body?: Record<string, unknown> | string; params?: Record<string, string | number | boolean | string[] | undefined>; }): Promise<T>; /** * Execute batch operations */ batch<T>(endpoint: string, operations: Array<{ operation: "create" | "update" | "delete"; id?: string; data?: Record<string, unknown>; }>, options?: { continueOnError?: boolean; validateBeforeExecution?: boolean; }): Promise<{ total: number; successful: number; failed: number; results: Array<{ success: boolean; id?: string; data?: T; error?: string; }>; }>; /** * Import data from various formats */ importData<T>(endpoint: string, data: T[] | string, options?: { strategy?: "replace" | "merge" | "skip_existing"; validate?: boolean; dryRun?: boolean; }): Promise<{ total: number; created: number; updated: number; skipped: number; errors: Array<{ id?: string; error: string; }>; }>; /** * Export data in various formats */ exportData<T>(endpoint: string, options?: { format?: "json" | "yaml"; include?: string[]; exclude?: string[]; pretty?: boolean; }): Promise<string>; /** * Simple YAML serialization (basic implementation) */ private toYaml; /** * Check if resource exists */ private checkExists; /** * Validate data (placeholder for actual validation logic) */ private validateData; /** * Clear query cache */ clearCache(): void; /** * Clear cache for specific endpoint */ clearCacheForEndpoint(endpoint: string): void; /** * Get cache statistics */ getCacheStats(): { totalEntries: number; expiredEntries: number; sizeInBytes: number; }; /** * Clear connection pool */ clearConnectionPool(): void; /** * Get connection pool statistics */ getConnectionPoolStats(): { adminConnections: number; controlConnections: number; totalConnections: number; maxPoolSize: number; ttl: number; }; /** * Configure retry settings */ configureRetry(options: { maxAttempts?: number; baseDelay?: number; }): void; /** * Configure cache settings */ configureCache(options: { ttl?: number; maxSize?: number; }): void; /** * Create AbortController for request cancellation */ createAbortController(): AbortController; } declare class ConsumerGroups { private readonly endpoint; private client; constructor(client: ApisixClient); /** * List all consumer groups with optional pagination and filtering */ list(options?: ListOptions): Promise<ConsumerGroup[]>; /** * Get a specific consumer group by ID */ get(id: string): Promise<ConsumerGroup>; /** * Create a new consumer group */ create(consumerGroup: CreateInput<ConsumerGroup>, id?: string): Promise<ConsumerGroup>; /** * Update an existing consumer group */ update(id: string, consumerGroup: UpdateInput<ConsumerGroup>): Promise<ConsumerGroup>; /** * Partially update an existing consumer group */ patch(id: string, consumerGroup: UpdateInput<ConsumerGroup>): Promise<ConsumerGroup>; /** * Delete a consumer group */ delete(id: string, options?: { force?: boolean; }): Promise<boolean>; /** * Check if consumer group exists */ exists(id: string): Promise<boolean>; /** * List consumer groups with pagination support (v3 API) */ listPaginated(page?: number, pageSize?: number, filters?: Record<string, string | number | boolean | undefined>): Promise<{ consumerGroups: ConsumerGroup[]; total?: number; hasMore?: boolean; }>; /** * Find consumer groups by label */ findByLabel(key: string, value?: string): Promise<ConsumerGroup[]>; /** * Find consumer groups by plugin name */ findByPlugin(pluginName: string): Promise<ConsumerGroup[]>; /** * Add plugin to consumer group */ addPlugin(id: string, pluginName: string, config: Record<string, unknown>): Promise<ConsumerGroup>; /** * Remove plugin from consumer group */ removePlugin(id: string, pluginName: string): Promise<ConsumerGroup>; /** * Update plugin configuration in consumer group */ updatePlugin(id: string, pluginName: string, config: Record<string, unknown>): Promise<ConsumerGroup>; /** * Add label to consumer group */ addLabel(id: string, key: string, value: string): Promise<ConsumerGroup>; /** * Remove label from consumer group */ removeLabel(id: string, key: string): Promise<ConsumerGroup>; /** * Clone a consumer group with optional modifications */ clone(sourceId: string, modifications?: Partial<ConsumerGroup>, newId?: string): Promise<ConsumerGroup>; /** * Get consumer group statistics */ getStatistics(): Promise<{ total: number; pluginUsage: Record<string, number>; labelUsage: Record<string, number>; topPlugins: Array<{ plugin: string; count: number; }>; topLabels: Array<{ label: string; count: number; }>; }>; } declare class Consumers { private readonly endpoint; private client; constructor(client: ApisixClient); /** * List all consumers with optional pagination and filtering */ list(options?: ListOptions): Promise<Consumer[]>; /** * Get a specific consumer by username */ get(username: string): Promise<Consumer>; /** * Create a new consumer */ create(consumer: CreateInput<Consumer>): Promise<Consumer>; /** * Update an existing consumer */ update(username: string, consumer: UpdateInput<Consumer>): Promise<Consumer>; /** * Partially update an existing consumer */ patch(username: string, consumer: UpdateInput<Consumer>): Promise<Consumer>; /** * Delete a consumer */ delete(username: string, options?: { force?: boolean; }): Promise<boolean>; /** * Check if consumer exists */ exists(username: string): Promise<boolean>; /** * List consumers with pagination support (v3 API) */ listPaginated(page?: number, pageSize?: number, filters?: Record<string, string | number | boolean | undefined>): Promise<{ consumers: Consumer[]; total?: number; hasMore?: boolean; }>; /** * Find consumers by label */ findByLabel(key: string, value?: string): Promise<Consumer[]>; /** * List credentials for a consumer */ listCredentials(username: string): Promise<ConsumerCredential[]>; /** * Get a specific credential for a consumer */ getCredential(username: string, credentialId: string): Promise<ConsumerCredential>; /** * Create or update a credential for a consumer */ createCredential(username: string, credentialId: string, credential: Omit<ConsumerCredential, "id" | "create_time" | "update_time">): Promise<ConsumerCredential>; /** * Update a credential for a consumer */ updateCredential(username: string, credentialId: string, credential: Partial<Omit<ConsumerCredential, "id" | "create_time" | "update_time">>): Promise<ConsumerCredential>; /** * Delete a credential for a consumer */ deleteCredential(username: string, credentialId: string): Promise<boolean>; /** * Add key-auth credential to consumer */ addKeyAuth(username: string, key: string, credentialId?: string): Promise<ConsumerCredential>; /** * Add basic-auth credential to consumer */ addBasicAuth(username: string, authUsername: string, password: string, credentialId?: string): Promise<ConsumerCredential>; /** * Add JWT auth credential to consumer */ addJwtAuth(username: string, key: string, secret?: string, credentialId?: string): Promise<ConsumerCredential>; /** * Add HMAC auth credential to consumer */ addHmacAuth(username: string, accessKey: string, secretKey: string, credentialId?: string): Promise<ConsumerCredential>; } declare class Control { private client; constructor(client: ApisixClient); /** * Get runtime upstreams information */ getUpstreams(): Promise<Record<string, unknown>[]>; /** * Get specific upstream runtime information */ getUpstream(upstreamId: string): Promise<Record<string, unknown>>; /** * Get all available schemas */ getSchemas(): Promise<SchemaInfo>; /** * Get schema for a specific resource type */ getSchema(resourceType: string): Promise<Record<string, unknown>>; /** * Get schema for a specific plugin */ getPluginSchema(pluginName: string): Promise<Record<string, unknown>>; /** * Check if Control API is healthy */ isHealthy(): Promise<boolean>; /** * Get server information */ getServerInfo(): Promise<ServerInfo>; /** * Get all available plugins information * Note: This endpoint is not available via Control API, use Admin API instead */ getPlugins(): Promise<PluginInfo[]>; /** * Get upstream health check status * Note: APISIX requires specific upstream ID for health check queries */ getUpstreamHealth(upstreamName?: string): Promise<UpstreamHealth[]>; /** * Check if specific service discovery is available */ hasDiscovery(service: string): Promise<boolean>; /** * Get available service discovery types */ listDiscoveries(): Promise<string[]>; /** * Get services dump for service discovery * Note: Requires service discovery to be configured */ getDiscoveryDump(service?: string): Promise<unknown>; /** * Get discovery dump files list * Note: Requires service discovery to be configured */ getDiscoveryDumpFiles(service?: string): Promise<DiscoveryDumpFile[]>; /** * Get discovery dump file content */ getDiscoveryDumpFile(filename: string): Promise<string>; /** * Get all plugin metadata */ getPluginMetadata(): Promise<Array<{ id: string; [key: string]: unknown; }>>; /** * Get specific plugin metadata */ getPluginMetadataById(pluginName: string): Promise<{ id: string; [key: string]: unknown; }>; /** * Get current APISIX configuration */ getConfig(): Promise<Record<string, unknown>>; /** * Get active routes */ getRoutes(): Promise<Record<string, unknown>[]>; /** * Get specific route runtime information */ getRoute(routeId: string): Promise<Record<string, unknown>>; /** * Get active services */ getServices(): Promise<Record<string, unknown>[]>; /** * Get specific service runtime information */ getService(serviceId: string): Promise<Record<string, unknown>>; /** * Get active consumers */ getConsumers(): Promise<Record<string, unknown>[]>; /** * Get specific consumer runtime information */ getConsumer(consumerId: string): Promise<Record<string, unknown>>; /** * Get SSL certificates */ getSSLCertificates(): Promise<Record<string, unknown>[]>; /** * Get specific SSL certificate */ getSSLCertificate(certId: string): Promise<Record<string, unknown>>; /** * Get global rules */ getGlobalRules(): Promise<Record<string, unknown>[]>; /** * Get specific global rule */ getGlobalRule(ruleId: string): Promise<Record<string, unknown>>; /** * Get consumer groups */ getConsumerGroups(): Promise<Record<string, unknown>[]>; /** * Get specific consumer group */ getConsumerGroup(groupId: string): Promise<Record<string, unknown>>; /** * Trigger garbage collection */ triggerGC(): Promise<{ message: string; }>; /** * Get system overview with proper error handling for unavailable endpoints */ getSystemOverview(): Promise<{ server: ServerInfo; schemas: SchemaInfo; health: boolean; upstreamHealth: UpstreamHealth[]; discoveryServices?: Record<string, unknown>; }>; /** * Get memory usage statistics */ getMemoryStats(): Promise<Record<string, unknown>>; /** * Get Prometheus metrics (from Prometheus export server on port 9091) * Note: Prometheus metrics are NOT available via Control API port 9090 */ getPrometheusMetrics(): Promise<string>; /** * Health check endpoint */ healthCheck(): Promise<HealthCheckStatus>; /** * Trigger plugins reload */ reloadPlugins(): Promise<{ message: string; }>; /** * Validate data against APISIX schemas */ validateSchema(entityType: "route" | "service" | "upstream" | "consumer" | "ssl" | "plugin", data: Record<string, unknown>, options?: { pluginName?: string; validatePlugins?: boolean; }): Promise<{ valid: boolean; errors: string[]; warnings: string[]; }>; /** * Validate multiple plugins configuration */ private validatePlugins; /** * Basic validation logic (placeholder for proper JSON schema validation) */ private performBasicValidation; /** * Get configuration validation recommendations */ getValidationRecommendations(): Promise<{ schemaVersion: string; availablePlugins: string[]; deprecatedPlugins: string[]; recommendedSettings: Array<{ category: string; setting: string; description: string; recommended: unknown; }>; }>; /** * Get schema compatibility information */ getSchemaCompatibility(targetVersion?: string): Promise<{ currentVersion: string; targetVersion: string; compatible: boolean; breaking_changes: string[]; new_features: string[]; deprecated_features: string[]; }>; /** * Compare version strings */ private compareVersions; } declare class Credentials { private client; constructor(client: ApisixClient); /** * Create a new credential for a consumer * @param consumerId The consumer ID * @param credential The credential data * @param credentialId Optional credential ID */ create(consumerId: string, credential: CreateInput<Credential>, credentialId?: string): Promise<Credential>; /** * Get a specific credential by consumer ID and credential ID */ get(consumerId: string, credentialId: string): Promise<Credential>; /** * List all credentials for a consumer */ list(consumerId: string, options?: ListOptions): Promise<Credential[]>; /** * Update an existing credential */ update(consumerId: string, credentialId: string, credential: UpdateInput<Credential>): Promise<Credential>; /** * Partially update an existing credential * Note: PATCH method is not supported for credentials in APISIX * This method will fall back to using PUT method */ patch(consumerId: string, credentialId: string, credential: UpdateInput<Credential>): Promise<Credential>; /** * Delete a credential */ delete(consumerId: string, credentialId: string): Promise<boolean>; /** * Check if credential exists */ exists(consumerId: string, credentialId: string): Promise<boolean>; /** * List credentials with pagination support */ listPaginated(consumerId: string, page?: number, pageSize?: number, filters?: Record<string, string | number | boolean | undefined>): Promise<{ credentials: Credential[]; total?: number; hasMore?: boolean; }>; /** * Find credentials by plugin type for a consumer */ findByPlugin(consumerId: string, pluginName: string): Promise<Credential[]>; /** * Find credentials matching a pattern for a consumer */ findByPattern(consumerId: string, pattern: RegExp): Promise<Credential[]>; /** * Clone a credential with optional modifications for a consumer */ clone(sourceConsumerId: string, sourceCredentialId: string, targetConsumerId: string, modifications?: Partial<Credential>, newCredentialId?: string): Promise<Credential>; /** * Get credential statistics for a consumer */ getStatistics(consumerId?: string): Promise<{ total: number; byPlugin: Array<{ plugin: string; count: number; }>; byConsumer: Array<{ consumer: string; count: number; }>; }>; } declare class GlobalRules { private readonly endpoint; private client; constructor(client: ApisixClient); /** * List all global rules with optional pagination and filtering */ list(options?: ListOptions): Promise<GlobalRule[]>; /** * Get a specific global rule by ID */ get(id: string): Promise<GlobalRule>; /** * Create a new global rule */ create(globalRule: CreateInput<GlobalRule>, id?: string): Promise<GlobalRule>; /** * Update an existing global rule */ update(id: string, globalRule: UpdateInput<GlobalRule>): Promise<GlobalRule>; /** * Partially update an existing global rule */ patch(id: string, globalRule: UpdateInput<GlobalRule>): Promise<GlobalRule>; /** * Delete a global rule */ delete(id: string, options?: { force?: boolean; }): Promise<boolean>; /** * Check if global rule exists */ exists(id: string): Promise<boolean>; /** * List global rules with pagination support (v3 API) */ listPaginated(page?: number, pageSize?: number, filters?: Record<string, string | number | boolean | undefined>): Promise<{ globalRules: GlobalRule[]; total?: number; hasMore?: boolean; }>; /** * Find global rules by plugin name */ findByPlugin(pluginName: string): Promise<GlobalRule[]>; /** * Add plugin to global rule */ addPlugin(id: string, pluginName: string, config: Record<string, unknown>): Promise<GlobalRule>; /** * Remove plugin from global rule */ removePlugin(id: string, pluginName: string): Promise<GlobalRule>; /** * Update plugin configuration in global rule */ updatePlugin(id: string, pluginName: string, config: Record<string, unknown>): Promise<GlobalRule>; /** * Clone a global rule with optional modifications */ clone(sourceId: string, modifications?: Partial<GlobalRule>, newId?: string): Promise<GlobalRule>; /** * Get global rule statistics */ getStatistics(): Promise<{ total: number; pluginUsage: Record<string, number>; topPlugins: Array<{ plugin: string; count: number; }>; }>; } declare class PluginConfigs { private client; constructor(client: ApisixClient); /** * List all plugin configs */ list(options?: { page?: number; page_size?: number; name?: string; label?: string; }): Promise<PluginConfig[]>; /** * Get plugin config by id */ get(id: string): Promise<PluginConfig>; /** * Create plugin config */ create(data: Omit<PluginConfig, "id" | "create_time" | "update_time">, id?: string): Promise<PluginConfig>; /** * Update plugin config */ update(id: string, data: Partial<Omit<PluginConfig, "id" | "create_time" | "update_time">>): Promise<PluginConfig>; /** * Delete plugin config */ delete(id: string): Promise<boolean>; /** * Add plugin to config */ addPlugin(id: string, pluginName: string, config: Record<string, unknown>): Promise<PluginConfig>; /** * Remove plugin from config */ removePlugin(id: string, pluginName: string): Promise<PluginConfig>; /** * Update plugin configuration in plugin config */ updatePlugin(id: string, pluginName: string, config: Record<string, unknown>): Promise<PluginConfig>; /** * Enable/disable plugin in config */ togglePlugin(id: string, pluginName: string, enabled: boolean): Promise<PluginConfig>; /** * Get plugin configs by label */ getByLabel(label: string, value?: string): Promise<PluginConfig[]>; /** * Clone plugin config */ clone(sourceId: string, newId: string, overrides?: Partial<Omit<PluginConfig, "id" | "create_time" | "update_time">>): Promise<PluginConfig>; /** * Validate plugin config */ validate(config: PluginConfig): Promise<{ valid: boolean; errors?: string[]; }>; /** * Get plugin config template with common plugins */ getTemplate(type: "basic" | "security" | "observability" | "traffic"): Partial<PluginConfig>; /** * Batch operations for plugin configs */ batchCreate(configs: Array<{ id?: string; data: Omit<PluginConfig, "id" | "create_time" | "update_time">; }>): Promise<PluginConfig[]>; /** * Export plugin config to JSON */ export(id: string): Promise<string>; /** * Import plugin config from JSON */ import(jsonString: string, newId?: string): Promise<PluginConfig>; } declare class Plugins { private client; private pluginCache; constructor(client: ApisixClient); /** * List all available plugins */ list(): Promise<string[]>; /** * Get plugin schema */ getSchema(pluginName: string): Promise<Record<string, unknown>>; /** * Set plugin global state (enable/disable globally) * Note: This feature may not be available in all APISIX versions */ setGlobalState(pluginName: string, enabled: boolean): Promise<boolean>; /** * Enable plugin globally */ enable(pluginName: string): Promise<boolean>; /** * Disable plugin globally */ disable(pluginName: string): Promise<boolean>; /** * Get plugin metadata */ getMetadata(pluginName: string): Promise<PluginMetadata>; /** * Update plugin metadata */ updateMetadata(pluginName: string, metadata: Omit<PluginMetadata, "id">): Promise<PluginMetadata>; /** * Delete plugin metadata */ deleteMetadata(pluginName: string): Promise<boolean>; /** * List all plugin metadata */ listMetadata(): Promise<PluginMetadata[]>; /** * Check if plugin is available */ isAvailable(pluginName: string): Promise<boolean>; /** * Validate plugin configuration */ validateConfig(pluginName: string, config: Record<string, unknown>): Promise<{ valid: boolean; errors?: string[]; }>; /** * Get plugin configuration template */ getConfigTemplate(pluginName: string): Promise<Record<string, unknown>>; /** * Get plugins by category */ getPluginCategories(): Record<string, string[]>; /** * Get plugins by category */ getPluginsByCategory(category: string): Promise<string[]>; /** * Get plugin documentation URL */ getPluginDocUrl(pluginName: string): string; /** * Get comprehensive plugin information */ getPluginInfo(pluginName: string): Promise<{ name: string; available: boolean; schema?: Record<string, unknown>; metadata?: PluginMetadata; category?: string; docUrl: string; }>; /** * Clear plugin cache (useful when plugins are reloaded) */ clearCache(): void; /** * Get list of available plugins with caching */ getAvailablePlugins(): Promise<string[]>; } declare class Protos { private readonly endpoint; private client; constructor(client: ApisixClient); /** * List all proto definitions with optional pagination and filtering */ list(options?: ListOptions): Promise<Proto[]>; /** * Get a specific proto by ID */ get(id: string): Promise<Proto>; /** * Create a new proto definition */ create(proto: CreateInput<Proto>, id?: string): Promise<Proto>; /** * Update an existing proto definition */ update(id: string, proto: UpdateInput<Proto>): Promise<Proto>; /** * Partially update an existing proto definition */ patch(id: string, proto: UpdateInput<Proto>): Promise<Proto>; /** * Delete a proto definition */ delete(id: string, options?: { force?: boolean; }): Promise<boolean>; /** * Check if proto exists */ exists(id: string): Promise<boolean>; /** * List protos with pagination support (v3 API) */ listPaginated(page?: number, pageSize?: number, filters?: Record<string, string | number | boolean | undefined>): Promise<{ protos: Proto[]; total?: number; hasMore?: boolean; }>; /** * Find protos by label */ findByLabel(label: string, value?: string): Promise<Proto[]>; /** * Clone a proto with optional modifications */ clone(sourceId: string, modifications?: Partial<Proto>, newId?: string): Promise<Proto>; /** * Validate protobuf content */ validateProtobufContent(content: string): { valid: boolean; errors?: string[]; }; /** * Create proto with validation */ createWithValidation(proto: CreateInput<Proto>, id?: string): Promise<Proto>; /** * Get statistics for proto definitions */ getStatistics(): Promise<{ total: number; labelUsage: Record<string, number>; topLabels: Array<{ label: string; count: number; }>; }>; } declare class Routes { private readonly endpoint; private client; constructor(client: ApisixClient); private getString; private getNumber; private getBoolean; private getStatus; private getObject; private getUpstream; private getStringRecord; private getVars; /** * List all routes with optional pagination and filtering */ list(options?: ListOptions): Promise<Route[]>; /** * Get a specific route by ID */ get(id: string): Promise<Route>; /** * Create a new route */ create(route: CreateInput<Route>, id?: string): Promise<Route>; /** * Update an existing route */ update(id: string, route: UpdateInput<Route>): Promise<Route>; /** * Partially update an existing route */ patch(id: string, route: UpdateInput<Route>): Promise<Route>; /** * Delete a route */ delete(id: string, options?: { force?: boolean; }): Promise<boolean>; /** * Check if route exists */ exists(id: string): Promise<boolean>; /** * List routes with pagination support (v3 API) */ listPaginated(page?: number, pageSize?: number, filters?: Record<string, string | number | boolean | undefined>): Promise<{ routes: Route[]; total?: number; hasMore?: boolean; }>; /** * Find routes by URI pattern */ findByUri(uriPattern: string): Promise<Route[]>; /** * Find routes by method */ findByMethod(method: string): Promise<Route[]>; /** * Find routes by host */ findByHost(host: string): Promise<Route[]>; /** * Enable a route */ enable(id: string): Promise<Route>; /** * Disable a route */ disable(id: string): Promise<Route>; /** * Clone a route with optional modifications */ clone(sourceId: string, modifications?: Partial<Route>, newId?: string): Promise<Route>; /** * Get route statistics */ getStatistics(): Promise<{ total: number; enabledCount: number; disabledCount: number; methodDistribution: Array<{ method: string; count: number; }>; topPlugins: Array<{ plugin: string; count: number; }>; hostCount: number; serviceRoutes: number; upstreamRoutes: number; }>; /** * Batch operations on routes */ batchOperations(operations: Array<{ operation: "create" | "update" | "delete"; id?: string; data?: CreateInput<Route> | UpdateInput<Route>; }>): Promise<{ total: number; successful: number; failed: number; results: Array<{ success: boolean; id?: string; data?: Route; error?: string; }>; }>; /** * Advanced search with multiple criteria */ search(criteria: { uri?: string; uriPattern?: string; methods?: string[]; hosts?: string[]; plugins?: string[]; status?: 0 | 1; hasUpstream?: boolean; hasService?: boolean; labels?: Record<string, string>; createdAfter?: Date; createdBefore?: Date; }): Promise<Route[]>; /** * Import routes from OpenAPI specification */ importFromOpenAPI(spec: { openapi: string; info: { title: string; version: string; description?: string; }; paths: Record<string, Record<string, Record<string, unknown>>>; }, options?: { strategy?: "replace" | "merge" | "skip_existing"; defaultUpstream?: Upstream;