/** * AsyncAPI Discovery Module (D-005) * * Automatically discovers AsyncAPI specifications for event-driven APIs * including WebSocket, MQTT, Kafka, AMQP, and other message-based protocols. * * This module: * 1. Probes common AsyncAPI spec locations * 2. Parses AsyncAPI 2.x and 3.x specifications * 3. Extracts channels, servers, and message schemas * 4. Generates API patterns for discovered endpoints * 5. Integrates with the Discovery Orchestrator */ import type { LearnedApiPattern } from '../types/api-patterns.js'; /** * AsyncAPI protocol types */ export type AsyncAPIProtocol = 'ws' | 'wss' | 'mqtt' | 'mqtts' | 'amqp' | 'amqps' | 'kafka' | 'kafka-secure' | 'http' | 'https' | 'jms' | 'sns' | 'sqs' | 'stomp' | 'redis' | 'nats' | 'pulsar'; /** * AsyncAPI specification version */ export type AsyncAPIVersion = '2.0' | '2.1' | '2.2' | '2.3' | '2.4' | '2.5' | '2.6' | '3.0'; /** * AsyncAPI server definition */ export interface AsyncAPIServer { /** Server URL (may contain variables) */ url: string; /** Protocol used by this server */ protocol: AsyncAPIProtocol; /** Protocol version if applicable */ protocolVersion?: string; /** Human-readable description */ description?: string; /** Server variables for URL templating */ variables?: Record; /** Security requirements */ security?: Array>; /** Server bindings (protocol-specific config) */ bindings?: Record; } /** * AsyncAPI message definition */ export interface AsyncAPIMessage { /** Message name/identifier */ name?: string; /** Human-readable title */ title?: string; /** Message description */ description?: string; /** Content type (e.g., 'application/json') */ contentType?: string; /** Message payload schema */ payload?: Record; /** Message headers schema */ headers?: Record; /** Correlation ID configuration */ correlationId?: { location: string; description?: string; }; /** Message bindings (protocol-specific) */ bindings?: Record; /** Example messages */ examples?: Array<{ name?: string; summary?: string; payload?: unknown; headers?: Record; }>; } /** * AsyncAPI channel operation (publish/subscribe) */ export interface AsyncAPIOperation { /** Operation ID */ operationId?: string; /** Human-readable summary */ summary?: string; /** Description */ description?: string; /** Security requirements for this operation */ security?: Array>; /** Tags for categorization */ tags?: Array<{ name: string; description?: string; }>; /** Message(s) for this operation */ message?: AsyncAPIMessage | { oneOf: AsyncAPIMessage[]; }; /** Protocol bindings */ bindings?: Record; } /** * AsyncAPI channel definition */ export interface AsyncAPIChannel { /** Channel address/topic */ address: string; /** Human-readable description */ description?: string; /** Publish operation (client sends to server) */ publish?: AsyncAPIOperation; /** Subscribe operation (client receives from server) */ subscribe?: AsyncAPIOperation; /** Channel parameters (variables in address) */ parameters?: Record; location?: string; }>; /** Channel bindings (protocol-specific) */ bindings?: Record; /** Servers this channel is available on (v3.0) */ servers?: string[]; } /** * AsyncAPI security scheme */ export interface AsyncAPISecurityScheme { /** Security scheme type */ type: 'userPassword' | 'apiKey' | 'X509' | 'symmetricEncryption' | 'asymmetricEncryption' | 'httpApiKey' | 'http' | 'oauth2' | 'openIdConnect' | 'plain' | 'scramSha256' | 'scramSha512' | 'gssapi'; /** Description */ description?: string; /** API key location (for apiKey/httpApiKey) */ in?: 'user' | 'password' | 'query' | 'header' | 'cookie'; /** API key name */ name?: string; /** HTTP scheme (for http type) */ scheme?: string; /** Bearer format */ bearerFormat?: string; /** OAuth2 flows */ flows?: { implicit?: { authorizationUrl: string; scopes: Record; }; password?: { tokenUrl: string; scopes: Record; }; clientCredentials?: { tokenUrl: string; scopes: Record; }; authorizationCode?: { authorizationUrl: string; tokenUrl: string; scopes: Record; }; }; /** OpenID Connect URL */ openIdConnectUrl?: string; } /** * Parsed AsyncAPI specification */ export interface ParsedAsyncAPISpec { /** AsyncAPI version */ asyncapiVersion: AsyncAPIVersion; /** API title */ title: string; /** API version */ version?: string; /** API description */ description?: string; /** Available servers by name */ servers: Record; /** Available channels */ channels: AsyncAPIChannel[]; /** Default content type for messages */ defaultContentType?: string; /** Security schemes */ securitySchemes?: Record; /** When the spec was discovered */ discoveredAt: number; /** URL where the spec was found */ specUrl: string; } /** * Result of AsyncAPI discovery attempt */ export interface AsyncAPIDiscoveryResult { /** Whether an AsyncAPI spec was found */ found: boolean; /** The parsed spec if found */ spec?: ParsedAsyncAPISpec; /** URL where the spec was found */ specUrl?: string; /** Locations that were probed */ probedLocations: string[]; /** Time taken to discover (ms) */ discoveryTime: number; /** Error message if discovery failed */ error?: string; } /** * Options for AsyncAPI discovery */ export interface AsyncAPIDiscoveryOptions { /** Maximum time to spend probing (ms) */ timeout?: number; /** Only probe these specific locations */ probeLocations?: string[]; /** Skip locations that match these patterns */ skipPatterns?: string[]; /** Headers to send with probe requests */ headers?: Record; /** Custom fetch function */ fetchFn?: (url: string, init?: RequestInit) => Promise; } /** * Generated AsyncAPI pattern */ export interface AsyncAPIPattern { /** Unique identifier */ id: string; /** Channel address */ channel: string; /** Protocol type */ protocol: AsyncAPIProtocol; /** Server URL */ serverUrl: string; /** Operation type */ operationType: 'publish' | 'subscribe'; /** Operation ID */ operationId?: string; /** Message schema */ messageSchema?: Record; /** Confidence score (0-1) */ confidence: number; } /** * Common locations to probe for AsyncAPI specifications */ export declare const ASYNCAPI_PROBE_LOCATIONS: readonly ["/asyncapi.json", "/asyncapi.yaml", "/asyncapi.yml", "/api/asyncapi.json", "/api/asyncapi.yaml", "/api/asyncapi.yml", "/docs/asyncapi.json", "/docs/asyncapi.yaml", "/.well-known/asyncapi.json", "/.well-known/asyncapi.yaml", "/v1/asyncapi.json", "/v2/asyncapi.json", "/spec/asyncapi.json", "/spec/asyncapi.yaml"]; /** * Discover AsyncAPI specification for a domain */ export declare function discoverAsyncAPI(domain: string, options?: AsyncAPIDiscoveryOptions): Promise; /** * Generate AsyncAPI patterns from a parsed spec */ export declare function generateAsyncAPIPatterns(spec: ParsedAsyncAPISpec): AsyncAPIPattern[]; /** * Generate LearnedApiPattern objects from AsyncAPI patterns * These are used by the Discovery Orchestrator */ export declare function generatePatternsFromAsyncAPI(spec: ParsedAsyncAPISpec, domain: string): LearnedApiPattern[]; /** * Get cached discovery result or discover anew * Uses unified discovery cache with tenant isolation and failed domain tracking */ export declare function discoverAsyncAPICached(domain: string, options?: AsyncAPIDiscoveryOptions): Promise; /** * Clear the spec cache * @param domain - Optional domain to clear, or all if not specified */ export declare function clearAsyncAPICache(domain?: string): Promise; /** * Get cache statistics */ export declare function getAsyncAPICacheStats(): Promise<{ size: number; domains: string[]; }>; //# sourceMappingURL=asyncapi-discovery.d.ts.map