/** * SDN Subscription Manager - Manages data type subscriptions with filtering * * Provides a high-level API for subscribing to specific SDS data types * from selected peers with optional encryption and streaming modes. */ import { SchemaName } from './schemas'; /** * Query filter for field-level filtering */ export interface QueryFilter { field: string; operator: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains' | 'startsWith' | 'endsWith' | 'in' | 'notIn'; value: unknown; } /** * Subscription configuration for data types */ export interface SubscriptionConfig { /** Data types to subscribe to, e.g., ["OMM.fbs", "CDM.fbs", "EPM.fbs"] */ dataTypes: SchemaName[]; /** Peer IDs to receive data from, or ["all"] for all peers */ sourcePeers: string[]; /** Whether to receive encrypted or plaintext data */ encrypted: boolean; /** Whether to use real-time streaming or batch mode */ streaming: boolean; /** Optional field-level filters */ filters?: QueryFilter[]; /** Optional rate limit (messages per minute) */ rateLimit?: number; /** Optional TTL for received messages (milliseconds) */ ttl?: number; } /** * Streaming mode configuration */ export declare enum StreamingMode { /** Encrypted streaming using ECIES per-message or session key */ Encrypted = "encrypted", /** Unencrypted streaming for public data like TLEs */ Unencrypted = "unencrypted", /** Hybrid mode: headers unencrypted, payload encrypted */ Hybrid = "hybrid" } /** * Routing header for message routing (mirrors FlatBuffer schema) */ export interface RoutingHeader { /** Schema type, e.g., "OMM", "CDM" (unencrypted for routing) */ schemaType: string; /** Destination peer IDs, empty for broadcast */ destinationPeers: string[]; /** Time-to-live (hop count) */ ttl: number; /** Priority level (0-255, higher is more important) */ priority: number; /** Whether the payload is encrypted */ encrypted: boolean; /** Optional session key ID for encrypted streaming */ sessionKeyId?: string; } /** * Active subscription state */ export interface ActiveSubscription { /** Unique subscription ID */ id: string; /** Subscription configuration */ config: SubscriptionConfig; /** Timestamp when subscription was created */ createdAt: number; /** Message count received */ messageCount: number; /** Last message timestamp */ lastMessageAt: number | null; /** Subscription status */ status: 'active' | 'paused' | 'error'; /** Error message if status is 'error' */ errorMessage?: string; } /** * Subscription event types */ export type SubscriptionEventType = 'message' | 'error' | 'subscribed' | 'unsubscribed' | 'paused' | 'resumed' | 'rateLimit'; /** * Subscription event payload */ export interface SubscriptionEvent { type: SubscriptionEventType; subscriptionId: string; schema?: SchemaName; data?: unknown; from?: string; header?: RoutingHeader; error?: Error; timestamp: number; } /** * Subscription event handler */ export type SubscriptionEventHandler = (event: SubscriptionEvent) => void; /** * Evaluates a query filter against a data object */ export declare function evaluateFilter(data: Record, filter: QueryFilter): boolean; /** * Evaluates all filters against data (AND logic) */ export declare function evaluateFilters(data: Record, filters: QueryFilter[]): boolean; /** * Generates a unique subscription ID */ export declare function generateSubscriptionId(): string; /** * Validates a subscription configuration */ export declare function validateSubscriptionConfig(config: SubscriptionConfig): string[]; /** * Creates a default subscription configuration */ export declare function createDefaultConfig(): SubscriptionConfig; /** * Serializes a routing header to binary format * Format: [schemaTypeLen(1)][schemaType(n)][destCount(1)][destPeers...][ttl(1)][priority(1)][flags(1)] */ export declare function serializeRoutingHeader(header: RoutingHeader): Uint8Array; /** * Deserializes a routing header from binary format */ export declare function deserializeRoutingHeader(data: Uint8Array): RoutingHeader | null; /** * Gets the topic name for schema-based routing */ export declare function getSchemaRoutingTopic(schemaType: string): string; /** * Gets the topic name for peer-based routing */ export declare function getPeerRoutingTopic(peerId: string): string; /** * Subscription Manager class for managing multiple subscriptions */ export declare class SubscriptionManager { private subscriptions; private handlers; private rateLimitCounters; /** * Creates a new subscription */ createSubscription(config: SubscriptionConfig): ActiveSubscription; /** * Gets a subscription by ID */ getSubscription(id: string): ActiveSubscription | undefined; /** * Gets all active subscriptions */ getAllSubscriptions(): ActiveSubscription[]; /** * Updates a subscription configuration */ updateSubscription(id: string, config: Partial): ActiveSubscription | undefined; /** * Removes a subscription */ removeSubscription(id: string): boolean; /** * Pauses a subscription */ pauseSubscription(id: string): boolean; /** * Resumes a subscription */ resumeSubscription(id: string): boolean; /** * Processes an incoming message against all subscriptions */ processMessage(schema: SchemaName, data: unknown, from: string, header?: RoutingHeader): void; /** * Checks rate limit for a subscription */ private checkRateLimit; /** * Adds an event handler */ addEventListener(subscriptionId: string | '*', handler: SubscriptionEventHandler): void; /** * Removes an event handler */ removeEventListener(subscriptionId: string | '*', handler: SubscriptionEventHandler): void; /** * Emits an event to all relevant handlers */ private emitEvent; /** * Gets the topics to subscribe to based on all active subscriptions */ getRequiredTopics(): Set; /** * Clears all subscriptions */ clear(): void; } /** * Default subscription manager instance */ export declare const defaultSubscriptionManager: SubscriptionManager; /** * Encryption mode for streaming payloads */ export declare enum EncryptionMode { /** No encryption */ None = 0, /** ECIES per-message encryption */ ECIES = 1, /** Session key encryption (AES-GCM with pre-shared key) */ SessionKey = 2, /** Hybrid: header unencrypted, payload encrypted */ Hybrid = 3 } /** * Stream delivery mode */ export declare enum StreamDeliveryMode { /** Single message delivery */ Single = 0, /** Real-time streaming */ Streaming = 1, /** Batch delivery */ Batch = 2 } /** * Streaming session state */ export interface StreamingSession { /** Unique session ID */ id: string; /** Associated subscription ID */ subscriptionId: string; /** Remote peer ID */ peerId: string; /** Schema types this session handles */ schemaTypes: string[]; /** Delivery mode */ mode: StreamDeliveryMode; /** Encryption mode */ encryptionMode: EncryptionMode; /** Session key ID (for session-key encryption) */ sessionKeyId?: string; /** Whether the session is active */ active: boolean; /** Messages sent count */ messagesSent: number; /** Bytes sent count */ bytesSent: number; /** Creation timestamp */ createdAt: number; /** Last activity timestamp */ lastActivity: number; } /** * Extended routing header with encryption mode and streaming support */ export interface ExtendedRoutingHeader extends RoutingHeader { /** Encryption mode for the payload */ encryptionMode: EncryptionMode; /** Source peer ID */ sourcePeer?: string; /** Sequence number for ordering */ sequence?: number; /** Timestamp (Unix milliseconds) */ timestamp: number; /** Topic override */ topicOverride?: string; /** Stream delivery mode */ streamMode?: StreamDeliveryMode; } /** * Edge relay filter configuration */ export interface EdgeRelayFilter { /** Allowed schema types (empty = all) */ allowedSchemas?: string[]; /** Allowed destination peers (empty = all) */ allowedPeers?: string[]; /** Minimum priority to forward (0 = all) */ minPriority: number; /** Maximum TTL accepted (0 = no limit) */ maxTTL: number; /** Allow encrypted messages */ allowEncrypted: boolean; /** Allow unencrypted messages */ allowUnencrypted: boolean; } /** * Creates a default edge relay filter (permissive) */ export declare function createDefaultEdgeRelayFilter(): EdgeRelayFilter; /** * Evaluates an edge relay filter against a routing header */ export declare function evaluateEdgeRelayFilter(filter: EdgeRelayFilter, header: RoutingHeader): boolean; /** * Creates an extended routing header with streaming support */ export declare function createRoutingHeader(schemaType: string, sourcePeer: string, options?: Partial): ExtendedRoutingHeader; /** * Serializes an extended routing header to binary format * Compatible with Go SerializeRoutingHeader */ export declare function serializeExtendedRoutingHeader(header: ExtendedRoutingHeader): Uint8Array; /** * Deserializes an extended routing header from binary format * Compatible with Go DeserializeRoutingHeader */ export declare function deserializeExtendedRoutingHeader(data: Uint8Array): ExtendedRoutingHeader | null; /** * Creates a message with routing header prepended (matches Go format) * Format: [headerLen(2)][header(n)][payload(m)] */ export declare function createMessageWithHeader(header: ExtendedRoutingHeader, payload: Uint8Array): Uint8Array; /** * Parses a message with routing header to extract header and payload */ export declare function parseMessageWithHeader(message: Uint8Array): { header: ExtendedRoutingHeader; payload: Uint8Array; } | null; /** * Determines the routing topic for a message based on its header */ export declare function getRoutingTopicForHeader(header: RoutingHeader | ExtendedRoutingHeader): string; /** * Desktop app subscription data model API. * Provides the data model and configuration interface for the desktop app. */ export declare class DesktopSubscriptionAPI { private manager; private streamingSessions; constructor(manager?: SubscriptionManager); /** Get the subscription manager */ getManager(): SubscriptionManager; /** Create a subscription with streaming session */ createStreamingSubscription(config: SubscriptionConfig, peerId: string, mode?: StreamDeliveryMode, encMode?: EncryptionMode): { subscription: ActiveSubscription; session: StreamingSession; }; /** Close a streaming session */ closeSession(sessionId: string): boolean; /** Get all streaming sessions */ getSessions(): StreamingSession[]; /** Get sessions for a specific peer */ getPeerSessions(peerId: string): StreamingSession[]; /** Get all required topics including streaming sessions */ getRequiredTopics(): string[]; } //# sourceMappingURL=subscription.d.ts.map