@metamask-previews/core-backend 0.0.0-preview-bc80f5a1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +20 -0
  3. package/README.md +360 -0
  4. package/dist/AccountActivityService-method-action-types.cjs +7 -0
  5. package/dist/AccountActivityService-method-action-types.cjs.map +1 -0
  6. package/dist/AccountActivityService-method-action-types.d.cts +30 -0
  7. package/dist/AccountActivityService-method-action-types.d.cts.map +1 -0
  8. package/dist/AccountActivityService-method-action-types.d.mts +30 -0
  9. package/dist/AccountActivityService-method-action-types.d.mts.map +1 -0
  10. package/dist/AccountActivityService-method-action-types.mjs +6 -0
  11. package/dist/AccountActivityService-method-action-types.mjs.map +1 -0
  12. package/dist/AccountActivityService.cjs +380 -0
  13. package/dist/AccountActivityService.cjs.map +1 -0
  14. package/dist/AccountActivityService.d.cts +148 -0
  15. package/dist/AccountActivityService.d.cts.map +1 -0
  16. package/dist/AccountActivityService.d.mts +148 -0
  17. package/dist/AccountActivityService.d.mts.map +1 -0
  18. package/dist/AccountActivityService.mjs +376 -0
  19. package/dist/AccountActivityService.mjs.map +1 -0
  20. package/dist/BackendWebSocketService-method-action-types.cjs +7 -0
  21. package/dist/BackendWebSocketService-method-action-types.cjs.map +1 -0
  22. package/dist/BackendWebSocketService-method-action-types.d.cts +146 -0
  23. package/dist/BackendWebSocketService-method-action-types.d.cts.map +1 -0
  24. package/dist/BackendWebSocketService-method-action-types.d.mts +146 -0
  25. package/dist/BackendWebSocketService-method-action-types.d.mts.map +1 -0
  26. package/dist/BackendWebSocketService-method-action-types.mjs +6 -0
  27. package/dist/BackendWebSocketService-method-action-types.mjs.map +1 -0
  28. package/dist/BackendWebSocketService.cjs +841 -0
  29. package/dist/BackendWebSocketService.cjs.map +1 -0
  30. package/dist/BackendWebSocketService.d.cts +366 -0
  31. package/dist/BackendWebSocketService.d.cts.map +1 -0
  32. package/dist/BackendWebSocketService.d.mts +366 -0
  33. package/dist/BackendWebSocketService.d.mts.map +1 -0
  34. package/dist/BackendWebSocketService.mjs +836 -0
  35. package/dist/BackendWebSocketService.mjs.map +1 -0
  36. package/dist/index.cjs +14 -0
  37. package/dist/index.cjs.map +1 -0
  38. package/dist/index.d.cts +10 -0
  39. package/dist/index.d.cts.map +1 -0
  40. package/dist/index.d.mts +10 -0
  41. package/dist/index.d.mts.map +1 -0
  42. package/dist/index.mjs +7 -0
  43. package/dist/index.mjs.map +1 -0
  44. package/dist/logger.cjs +7 -0
  45. package/dist/logger.cjs.map +1 -0
  46. package/dist/logger.d.cts +5 -0
  47. package/dist/logger.d.cts.map +1 -0
  48. package/dist/logger.d.mts +5 -0
  49. package/dist/logger.d.mts.map +1 -0
  50. package/dist/logger.mjs +4 -0
  51. package/dist/logger.mjs.map +1 -0
  52. package/dist/types.cjs +3 -0
  53. package/dist/types.cjs.map +1 -0
  54. package/dist/types.d.cts +71 -0
  55. package/dist/types.d.cts.map +1 -0
  56. package/dist/types.d.mts +71 -0
  57. package/dist/types.d.mts.map +1 -0
  58. package/dist/types.mjs +2 -0
  59. package/dist/types.mjs.map +1 -0
  60. package/package.json +80 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackendWebSocketService.cjs","sourceRoot":"","sources":["../src/BackendWebSocketService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,2CAAkD;AAClD,+BAAoC;AAGpC,yCAA6D;AAE7D,MAAM,YAAY,GAAG,yBAAkC,CAAC;AAExD,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,YAAY,CAAC,CAAC;AAE5D,MAAM,yBAAyB,GAAG;IAChC,SAAS;IACT,YAAY;IACZ,aAAa;IACb,aAAa;IACb,WAAW;IACX,mBAAmB;IACnB,2BAA2B;IAC3B,wBAAwB;IACxB,kCAAkC;IAClC,oBAAoB;IACpB,uBAAuB;IACvB,qBAAqB;CACb,CAAC;AAEX;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I,kDAAmB,CAAC,CAAC;QACtC,uBAAA,IAAI,8CAAsB,IAAI,MAAA,CAAC;KAChC;AACH,CAAC,yGAOqB,KAAY;IAChC,KAAK,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,uBAAA,IAAI,gDAAiB,EAAE;QAC/C,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KACvB;IACD,uBAAA,IAAI,gDAAiB,CAAC,KAAK,EAAE,CAAC;AAChC,CAAC;IAMC,uBAAA,IAAI,8CAAe,CAAC,KAAK,EAAE,CAAC;AAC9B,CAAC,iFAOS,QAAwB;IAChC,MAAM,QAAQ,GAAG,uBAAA,IAAI,sCAAO,CAAC;IAC7B,uBAAA,IAAI,kCAAU,QAAQ,MAAA,CAAC;IAEvB,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACzB,GAAG,CAAC,yBAAyB,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEvD,wCAAwC;QACxC,sEAAsE;QACtE,uBAAA,IAAI,0CAAW,CAAC,OAAO,CACrB,gDAAgD,EAChD,IAAI,CAAC,iBAAiB,EAAE,CACzB,CAAC;KACH;AACH,CAAC,6GAYuB,IAAY;IAClC,6DAA6D;IAC7D,OAAO,IAAI,KAAK,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { RestrictedMessenger } from '@metamask/base-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport { getErrorMessage } from '@metamask/utils';\nimport { v4 as uuidV4 } from 'uuid';\n\nimport type { BackendWebSocketServiceMethodActions } from './BackendWebSocketService-method-action-types';\nimport { projectLogger, createModuleLogger } from './logger';\n\nconst SERVICE_NAME = 'BackendWebSocketService' as const;\n\nconst log = createModuleLogger(projectLogger, SERVICE_NAME);\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'connect',\n 'disconnect',\n 'sendMessage',\n 'sendRequest',\n 'subscribe',\n 'getConnectionInfo',\n 'getSubscriptionsByChannel',\n 'channelHasSubscription',\n 'findSubscriptionsByChannelPrefix',\n 'addChannelCallback',\n 'removeChannelCallback',\n 'getChannelCallbacks',\n] as const;\n\n/**\n * Gets human-readable close reason from RFC 6455 close code\n *\n * @param code - WebSocket close code\n * @returns Human-readable close reason\n */\nexport function getCloseReason(code: number): string {\n switch (code) {\n case 1000:\n return 'Normal Closure';\n case 1001:\n return 'Going Away';\n case 1002:\n return 'Protocol Error';\n case 1003:\n return 'Unsupported Data';\n case 1004:\n return 'Reserved';\n case 1005:\n return 'No Status Received';\n case 1006:\n return 'Abnormal Closure';\n case 1007:\n return 'Invalid frame payload data';\n case 1008:\n return 'Policy Violation';\n case 1009:\n return 'Message Too Big';\n case 1010:\n return 'Mandatory Extension';\n case 1011:\n return 'Internal Server Error';\n case 1012:\n return 'Service Restart';\n case 1013:\n return 'Try Again Later';\n case 1014:\n return 'Bad Gateway';\n case 1015:\n return 'TLS Handshake';\n default:\n if (code >= 3000 && code <= 3999) {\n return 'Library/Framework Error';\n }\n if (code >= 4000 && code <= 4999) {\n return 'Application Error';\n }\n return 'Unknown';\n }\n}\n\n/**\n * WebSocket connection states\n */\nexport enum WebSocketState {\n CONNECTING = 'connecting',\n CONNECTED = 'connected',\n DISCONNECTING = 'disconnecting',\n DISCONNECTED = 'disconnected',\n ERROR = 'error',\n}\n\n/**\n * WebSocket event types\n */\nexport enum WebSocketEventType {\n CONNECTED = 'connected',\n DISCONNECTED = 'disconnected',\n MESSAGE = 'message',\n ERROR = 'error',\n RECONNECTING = 'reconnecting',\n RECONNECTED = 'reconnected',\n}\n\n/**\n * Configuration options for the WebSocket service\n */\nexport type BackendWebSocketServiceOptions = {\n /** The WebSocket URL to connect to */\n url: string;\n\n /** The messenger for inter-service communication */\n messenger: BackendWebSocketServiceMessenger;\n\n /** Connection timeout in milliseconds (default: 10000) */\n timeout?: number;\n\n /** Initial reconnection delay in milliseconds (default: 500) */\n reconnectDelay?: number;\n\n /** Maximum reconnection delay in milliseconds (default: 5000) */\n maxReconnectDelay?: number;\n\n /** Request timeout in milliseconds (default: 30000) */\n requestTimeout?: number;\n\n /** Optional callback to determine if connection should be enabled (default: always enabled) */\n isEnabled?: () => boolean;\n};\n\n/**\n * Client Request message\n * Used when client sends a request to the server\n */\nexport type ClientRequestMessage = {\n event: string;\n data: {\n requestId: string;\n channels?: string[];\n [key: string]: unknown;\n };\n};\n\n/**\n * Server Response message\n * Used when server responds to a client request\n */\nexport type ServerResponseMessage = {\n event: string;\n data: {\n requestId: string;\n subscriptionId?: string;\n succeeded?: string[];\n failed?: string[];\n [key: string]: unknown;\n };\n};\n\n/**\n * Server Notification message\n * Used when server sends unsolicited data to client\n * subscriptionId is optional for system-wide notifications\n */\nexport type ServerNotificationMessage = {\n event: string;\n subscriptionId?: string;\n channel: string;\n data: Record<string, unknown>;\n};\n\n/**\n * Union type for all WebSocket messages\n */\nexport type WebSocketMessage =\n | ClientRequestMessage\n | ServerResponseMessage\n | ServerNotificationMessage;\n\n/**\n * Channel-based callback configuration\n */\nexport type ChannelCallback = {\n /** Channel name to match (also serves as the unique identifier) */\n channelName: string;\n /** Callback function */\n callback: (notification: ServerNotificationMessage) => void;\n};\n\n/**\n * Unified WebSocket subscription object used for both internal storage and external API\n */\nexport type WebSocketSubscription = {\n /** The subscription ID from the server */\n subscriptionId: string;\n /** Channel names for this subscription */\n channels: string[];\n /** Callback function for handling notifications (optional for external use) */\n callback?: (notification: ServerNotificationMessage) => void;\n /** Function to unsubscribe and clean up */\n unsubscribe: (requestId?: string) => Promise<void>;\n};\n\n/**\n * WebSocket connection info\n */\nexport type WebSocketConnectionInfo = {\n state: WebSocketState;\n url: string;\n reconnectAttempts: number;\n connectedAt?: number;\n};\n\n// Action types for the messaging system - using generated method actions\nexport type BackendWebSocketServiceActions =\n BackendWebSocketServiceMethodActions;\n\nexport type BackendWebSocketServiceAllowedActions =\n | AuthenticationController.AuthenticationControllerGetBearerToken\n | BackendWebSocketServiceMethodActions;\n\nexport type BackendWebSocketServiceAllowedEvents =\n | AuthenticationController.AuthenticationControllerStateChangeEvent\n | BackendWebSocketServiceConnectionStateChangedEvent;\n\n// Event types for WebSocket connection state changes\nexport type BackendWebSocketServiceConnectionStateChangedEvent = {\n type: 'BackendWebSocketService:connectionStateChanged';\n payload: [WebSocketConnectionInfo];\n};\n\nexport type BackendWebSocketServiceEvents =\n BackendWebSocketServiceConnectionStateChangedEvent;\n\nexport type BackendWebSocketServiceMessenger = RestrictedMessenger<\n typeof SERVICE_NAME,\n BackendWebSocketServiceActions | BackendWebSocketServiceAllowedActions,\n BackendWebSocketServiceEvents | BackendWebSocketServiceAllowedEvents,\n BackendWebSocketServiceAllowedActions['type'],\n BackendWebSocketServiceAllowedEvents['type']\n>;\n\n/**\n * WebSocket Service with automatic reconnection, session management and direct callback routing\n *\n * Real-Time Performance Optimizations:\n * - Fast path message routing (zero allocations)\n * - Production mode removes try-catch overhead\n * - Optimized JSON parsing with fail-fast\n * - Direct callback routing bypasses event emitters\n * - Memory cleanup and resource management\n *\n * Mobile Integration:\n * Mobile apps should handle lifecycle events (background/foreground) by:\n * 1. Calling disconnect() when app goes to background\n * 2. Calling connect() when app returns to foreground\n * 3. Calling destroy() on app termination\n */\nexport class BackendWebSocketService {\n /**\n * The name of the service.\n */\n readonly name = SERVICE_NAME;\n\n readonly #messenger: BackendWebSocketServiceMessenger;\n\n readonly #options: Required<\n Omit<BackendWebSocketServiceOptions, 'messenger' | 'isEnabled'>\n >;\n\n readonly #isEnabled: (() => boolean) | undefined;\n\n #ws: WebSocket | undefined;\n\n #state: WebSocketState = WebSocketState.DISCONNECTED;\n\n #reconnectAttempts = 0;\n\n #reconnectTimer: NodeJS.Timeout | null = null;\n\n #connectionTimeout: NodeJS.Timeout | null = null;\n\n // Track the current connection promise to handle concurrent connection attempts\n #connectionPromise: Promise<void> | null = null;\n\n readonly #pendingRequests = new Map<\n string,\n {\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n timeout: NodeJS.Timeout;\n }\n >();\n\n #connectedAt: number | null = null;\n\n // Simplified subscription storage (single flat map)\n // Key: subscription ID string (e.g., 'sub_abc123def456')\n // Value: WebSocketSubscription object with channels, callback and metadata\n readonly #subscriptions = new Map<string, WebSocketSubscription>();\n\n // Channel-based callback storage\n // Key: channel name (serves as unique identifier)\n // Value: ChannelCallback configuration\n readonly #channelCallbacks = new Map<string, ChannelCallback>();\n\n // =============================================================================\n // 1. CONSTRUCTOR & INITIALIZATION\n // =============================================================================\n\n /**\n * Creates a new WebSocket service instance\n *\n * @param options - Configuration options for the WebSocket service\n */\n constructor(options: BackendWebSocketServiceOptions) {\n this.#messenger = options.messenger;\n this.#isEnabled = options.isEnabled;\n\n this.#options = {\n url: options.url,\n timeout: options.timeout ?? 10000,\n reconnectDelay: options.reconnectDelay ?? 500,\n maxReconnectDelay: options.maxReconnectDelay ?? 5000,\n requestTimeout: options.requestTimeout ?? 30000,\n };\n\n // Setup authentication (always enabled)\n this.#setupAuthentication();\n\n // Register action handlers using the method actions pattern\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Setup authentication event handling - simplified approach using AuthenticationController\n * AuthenticationController.isSignedIn includes both wallet unlock AND identity provider auth.\n * App lifecycle (AppStateWebSocketManager) handles WHEN to connect/disconnect for resources.\n *\n */\n #setupAuthentication(): void {\n try {\n // Subscribe to authentication state changes - this includes wallet unlock state\n // AuthenticationController can only be signed in if wallet is unlocked\n // Using selector to only listen for isSignedIn property changes for better performance\n this.#messenger.subscribe(\n 'AuthenticationController:stateChange',\n (isSignedIn: boolean) => {\n if (isSignedIn) {\n // User signed in (wallet unlocked + authenticated) - try to connect\n // Clear any pending reconnection timer since we're attempting connection\n this.#clearTimers();\n this.connect().catch((error) => {\n log('Failed to connect after sign-in', { error });\n });\n } else {\n // User signed out (wallet locked OR signed out) - disconnect and stop reconnection attempts\n this.#clearTimers();\n this.#reconnectAttempts = 0;\n this.disconnect().catch((error) => {\n log('Failed to disconnect after sign-out', { error });\n });\n }\n },\n (state: AuthenticationController.AuthenticationControllerState) =>\n state.isSignedIn,\n );\n } catch (error) {\n throw new Error(`Authentication setup failed: ${getErrorMessage(error)}`);\n }\n }\n\n // =============================================================================\n // 2. PUBLIC API METHODS\n // =============================================================================\n\n /**\n * Establishes WebSocket connection with smart reconnection behavior\n *\n * Simplified Priority System (using AuthenticationController):\n * 1. App closed/backgrounded → Stop all attempts (save resources)\n * 2. User not signed in (wallet locked OR not authenticated) → Keep retrying\n * 3. User signed in (wallet unlocked + authenticated) → Connect successfully\n *\n * @returns Promise that resolves when connection is established\n */\n async connect(): Promise<void> {\n // Priority 1: Check if connection is enabled via callback (app lifecycle check)\n // If app is closed/backgrounded, stop all connection attempts to save resources\n if (this.#isEnabled && !this.#isEnabled()) {\n // Clear any pending reconnection attempts since app is disabled\n this.#clearTimers();\n this.#reconnectAttempts = 0;\n return;\n }\n\n // If already connected, return immediately\n if (this.#state === WebSocketState.CONNECTED) {\n return;\n }\n\n // If already connecting, wait for the existing connection attempt to complete\n if (this.#state === WebSocketState.CONNECTING && this.#connectionPromise) {\n await this.#connectionPromise;\n return;\n }\n\n // Priority 2: Check authentication requirements (simplified - just check if signed in)\n let bearerToken: string;\n try {\n // AuthenticationController.getBearerToken() handles wallet unlock checks internally\n const token = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!token) {\n this.#scheduleReconnect();\n return;\n }\n bearerToken = token;\n } catch (error) {\n log('Failed to check authentication requirements', { error });\n\n // If we can't connect for ANY reason, schedule a retry\n this.#scheduleReconnect();\n return;\n }\n\n this.#setState(WebSocketState.CONNECTING);\n\n // Create and store the connection promise\n this.#connectionPromise = this.#establishConnection(bearerToken);\n\n try {\n await this.#connectionPromise;\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n log('Connection attempt failed', { errorMessage, error });\n this.#setState(WebSocketState.ERROR);\n\n throw new Error(`Failed to connect to WebSocket: ${errorMessage}`);\n } finally {\n // Clear the connection promise when done (success or failure)\n this.#connectionPromise = null;\n }\n }\n\n /**\n * Closes WebSocket connection\n *\n * @returns Promise that resolves when disconnection is complete\n */\n async disconnect(): Promise<void> {\n if (\n this.#state === WebSocketState.DISCONNECTED ||\n this.#state === WebSocketState.DISCONNECTING\n ) {\n return;\n }\n\n this.#setState(WebSocketState.DISCONNECTING);\n this.#clearTimers();\n this.#clearPendingRequests(new Error('WebSocket disconnected'));\n\n // Clear any pending connection promise\n this.#connectionPromise = null;\n\n if (this.#ws) {\n this.#ws.close(1000, 'Normal closure');\n }\n\n this.#setState(WebSocketState.DISCONNECTED);\n log('WebSocket manually disconnected');\n }\n\n /**\n * Sends a message through the WebSocket (fire-and-forget, no response expected)\n *\n * This is a low-level method for sending messages without waiting for a response.\n * Most consumers should use `sendRequest()` instead, which handles request-response\n * correlation and provides proper error handling with timeouts.\n *\n * Use this method only when:\n * - You don't need a response from the server\n * - You're implementing custom message protocols\n * - You need fine-grained control over message timing\n *\n * @param message - The message to send\n * @throws Error if WebSocket is not connected or send fails\n *\n * @see sendRequest for request-response pattern with automatic correlation\n */\n sendMessage(message: ClientRequestMessage): void {\n if (this.#state !== WebSocketState.CONNECTED || !this.#ws) {\n throw new Error(`Cannot send message: WebSocket is ${this.#state}`);\n }\n\n try {\n this.#ws.send(JSON.stringify(message));\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n this.#handleError(new Error(errorMessage));\n throw new Error(errorMessage);\n }\n }\n\n /**\n * Sends a request and waits for a correlated response (recommended for most use cases)\n *\n * This is the recommended high-level method for request-response communication.\n * It automatically handles:\n * - Request ID generation and correlation\n * - Response matching with timeout protection\n * - Automatic reconnection on timeout\n * - Proper cleanup of pending requests\n *\n * @param message - The request message (can include optional requestId for testing)\n * @returns Promise that resolves with the response data\n * @throws Error if WebSocket is not connected, request times out, or response indicates failure\n *\n * @see sendMessage for fire-and-forget messaging without response handling\n */\n async sendRequest<T = ServerResponseMessage['data']>(\n message: Omit<ClientRequestMessage, 'data'> & {\n data?: Omit<ClientRequestMessage['data'], 'requestId'> & {\n requestId?: string;\n };\n },\n ): Promise<T> {\n if (this.#state !== WebSocketState.CONNECTED) {\n throw new Error(`Cannot send request: WebSocket is ${this.#state}`);\n }\n\n // Use provided requestId if available, otherwise generate a new one\n const requestId = message.data?.requestId ?? uuidV4();\n const requestMessage: ClientRequestMessage = {\n event: message.event,\n data: {\n ...message.data,\n requestId, // Set after spread to ensure it's not overwritten by undefined\n },\n };\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.#pendingRequests.delete(requestId);\n log('Request timeout - triggering reconnection', {\n timeout: this.#options.requestTimeout,\n });\n\n // Trigger reconnection on request timeout as it may indicate stale connection\n if (this.#state === WebSocketState.CONNECTED && this.#ws) {\n // Force close the current connection to trigger reconnection logic\n this.#ws.close(3000, 'Request timeout - forcing reconnect');\n }\n\n reject(\n new Error(`Request timeout after ${this.#options.requestTimeout}ms`),\n );\n }, this.#options.requestTimeout);\n\n // Store in pending requests for response correlation\n this.#pendingRequests.set(requestId, {\n resolve: resolve as (value: unknown) => void,\n reject,\n timeout,\n });\n\n // Send the request\n try {\n this.sendMessage(requestMessage);\n } catch (error) {\n this.#pendingRequests.delete(requestId);\n clearTimeout(timeout);\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n }\n\n /**\n * Gets current connection information\n *\n * @returns Current connection status and details\n */\n getConnectionInfo(): WebSocketConnectionInfo {\n return {\n state: this.#state,\n url: this.#options.url,\n reconnectAttempts: this.#reconnectAttempts,\n connectedAt: this.#connectedAt ?? undefined,\n };\n }\n\n /**\n * Gets all subscription information for a specific channel\n *\n * @param channel - The channel name to look up\n * @returns Array of subscription details for all subscriptions containing the channel\n */\n getSubscriptionsByChannel(channel: string): WebSocketSubscription[] {\n const matchingSubscriptions: WebSocketSubscription[] = [];\n for (const [subscriptionId, subscription] of this.#subscriptions) {\n if (subscription.channels.includes(channel)) {\n matchingSubscriptions.push({\n subscriptionId,\n channels: subscription.channels,\n unsubscribe: subscription.unsubscribe,\n });\n }\n }\n return matchingSubscriptions;\n }\n\n /**\n * Checks if a channel has a subscription\n *\n * @param channel - The channel name to check\n * @returns True if the channel has a subscription, false otherwise\n */\n channelHasSubscription(channel: string): boolean {\n for (const subscription of this.#subscriptions.values()) {\n if (subscription.channels.includes(channel)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Finds all subscriptions that have channels starting with the specified prefix\n *\n * @param channelPrefix - The channel prefix to search for (e.g., \"account-activity.v1\")\n * @returns Array of subscription info for matching subscriptions\n */\n findSubscriptionsByChannelPrefix(\n channelPrefix: string,\n ): WebSocketSubscription[] {\n const matchingSubscriptions: WebSocketSubscription[] = [];\n\n for (const [subscriptionId, subscription] of this.#subscriptions) {\n // Check if any channel in this subscription starts with the prefix\n const hasMatchingChannel = subscription.channels.some((channel) =>\n channel.startsWith(channelPrefix),\n );\n\n if (hasMatchingChannel) {\n matchingSubscriptions.push({\n subscriptionId,\n channels: subscription.channels,\n unsubscribe: subscription.unsubscribe,\n });\n }\n }\n\n return matchingSubscriptions;\n }\n\n /**\n * Register a callback for specific channels (local callback only, no server subscription)\n *\n * **Key Difference from `subscribe()`:**\n * - `addChannelCallback()`: Registers a local callback without creating a server-side subscription.\n * The callback triggers on ANY message matching the channel name, regardless of subscriptionId.\n * Useful for system-wide notifications or when you don't control the subscription lifecycle.\n *\n * - `subscribe()`: Creates a proper server-side subscription with a subscriptionId.\n * The callback only triggers for messages with the matching subscriptionId.\n * Includes proper lifecycle management (unsubscribe, automatic cleanup on disconnect).\n *\n * **When to use `addChannelCallback()`:**\n * - Listening to system-wide notifications (e.g., 'system-notifications.v1')\n * - Monitoring channels where subscriptions are managed elsewhere\n * - Debug/logging scenarios where you want to observe all channel messages\n *\n * **When to use `subscribe()` instead:**\n * - Creating new subscriptions that need server-side registration\n * - When you need proper cleanup via unsubscribe\n * - Most application use cases (recommended approach)\n *\n * @param options - Channel callback configuration\n * @param options.channelName - Channel name to match exactly\n * @param options.callback - Function to call when channel matches\n *\n * @example\n * ```typescript\n * // Listen to system notifications (no server subscription needed)\n * webSocketService.addChannelCallback({\n * channelName: 'system-notifications.v1',\n * callback: (notification) => {\n * console.log('System notification:', notification.data);\n * }\n * });\n *\n * // For account-specific subscriptions, use subscribe() instead:\n * // const sub = await webSocketService.subscribe({\n * // channels: ['account-activity.v1.eip155:0:0x1234...'],\n * // callback: (notification) => { ... }\n * // });\n * ```\n *\n * @see subscribe for creating proper server-side subscriptions with lifecycle management\n */\n addChannelCallback(options: {\n channelName: string;\n callback: (notification: ServerNotificationMessage) => void;\n }): void {\n const channelCallback: ChannelCallback = {\n channelName: options.channelName,\n callback: options.callback,\n };\n\n // Check if callback already exists for this channel\n if (this.#channelCallbacks.has(options.channelName)) {\n return;\n }\n\n this.#channelCallbacks.set(options.channelName, channelCallback);\n }\n\n /**\n * Remove a channel callback\n *\n * @param channelName - The channel name returned from addChannelCallback\n * @returns True if callback was found and removed, false otherwise\n */\n removeChannelCallback(channelName: string): boolean {\n return this.#channelCallbacks.delete(channelName);\n }\n\n /**\n * Get all registered channel callbacks (for debugging)\n *\n * @returns Array of all registered channel callbacks\n */\n getChannelCallbacks(): ChannelCallback[] {\n return Array.from(this.#channelCallbacks.values());\n }\n\n /**\n * Destroy the service and clean up resources\n * Called when service is being destroyed or app is terminating\n */\n destroy(): void {\n this.#clearTimers();\n this.#clearSubscriptions();\n\n // Clear any pending connection promise\n this.#connectionPromise = null;\n\n // Clear all pending requests\n this.#clearPendingRequests(new Error('Service cleanup'));\n\n if (this.#ws && this.#ws.readyState === WebSocket.OPEN) {\n this.#ws.close(1000, 'Service cleanup');\n }\n }\n\n /**\n * Create and manage a subscription with server-side registration (recommended for most use cases)\n *\n * This is the recommended subscription API for high-level services. It creates a proper\n * server-side subscription and routes notifications based on subscriptionId.\n *\n * **Key Features:**\n * - Creates server-side subscription with unique subscriptionId\n * - Callback triggered only for messages with matching subscriptionId\n * - Automatic lifecycle management (cleanup on disconnect)\n * - Includes unsubscribe method for proper cleanup\n * - Request-response pattern with error handling\n *\n * **When to use `subscribe()`:**\n * - Creating new subscriptions (account activity, price updates, etc.)\n * - When you need proper cleanup/unsubscribe functionality\n * - Most application use cases\n *\n * **When to use `addChannelCallback()` instead:**\n * - System-wide notifications without server-side subscription\n * - Observing channels managed elsewhere\n * - Debug/logging scenarios\n *\n * @param options - Subscription configuration\n * @param options.channels - Array of channel names to subscribe to\n * @param options.callback - Callback function for handling notifications\n * @param options.requestId - Optional request ID for testing (will generate UUID if not provided)\n * @returns Subscription object with unsubscribe method\n *\n * @example\n * ```typescript\n * // AccountActivityService usage\n * const subscription = await webSocketService.subscribe({\n * channels: ['account-activity.v1.eip155:0:0x1234...'],\n * callback: (notification) => {\n * this.handleAccountActivity(notification.data);\n * }\n * });\n *\n * // Later, clean up\n * await subscription.unsubscribe();\n * ```\n *\n * @see addChannelCallback for local callbacks without server-side subscription\n */\n async subscribe(options: {\n /** Channel names to subscribe to */\n channels: string[];\n /** Handler for incoming notifications */\n callback: (notification: ServerNotificationMessage) => void;\n /** Optional request ID for testing (will generate UUID if not provided) */\n requestId?: string;\n }): Promise<WebSocketSubscription> {\n const { channels, callback, requestId } = options;\n\n if (this.#state !== WebSocketState.CONNECTED) {\n throw new Error(\n `Cannot create subscription(s) ${channels.join(', ')}: WebSocket is ${this.#state}`,\n );\n }\n\n // Send subscription request and wait for response\n const subscriptionResponse = await this.sendRequest({\n event: 'subscribe',\n data: { channels, requestId },\n });\n\n if (!subscriptionResponse?.subscriptionId) {\n throw new Error('Invalid subscription response: missing subscription ID');\n }\n\n const { subscriptionId } = subscriptionResponse;\n\n // Check for failures\n if (subscriptionResponse.failed && subscriptionResponse.failed.length > 0) {\n throw new Error(\n `Subscription failed for channels: ${subscriptionResponse.failed.join(', ')}`,\n );\n }\n\n // Create unsubscribe function\n const unsubscribe = async (unsubRequestId?: string): Promise<void> => {\n // Send unsubscribe request first\n await this.sendRequest({\n event: 'unsubscribe',\n data: {\n subscription: subscriptionId,\n channels,\n requestId: unsubRequestId,\n },\n });\n\n // Clean up subscription mapping\n this.#subscriptions.delete(subscriptionId);\n };\n\n const subscription = {\n subscriptionId,\n channels: [...channels],\n unsubscribe,\n };\n\n // Store subscription with subscription ID as key\n this.#subscriptions.set(subscriptionId, {\n subscriptionId,\n channels: [...channels], // Store copy of channels\n callback,\n unsubscribe,\n });\n\n return subscription;\n }\n\n // =============================================================================\n // 3. CONNECTION MANAGEMENT (PRIVATE)\n // =============================================================================\n\n /**\n * Builds an authenticated WebSocket URL with bearer token as query parameter.\n * Uses query parameter for WebSocket authentication since native WebSocket\n * doesn't support custom headers during handshake.\n *\n * @param bearerToken - The bearer token to use for authentication\n * @returns The authenticated WebSocket URL\n */\n #buildAuthenticatedUrl(bearerToken: string): string {\n const baseUrl = this.#options.url;\n\n // Add token as query parameter to the WebSocket URL\n const url = new URL(baseUrl);\n url.searchParams.set('token', bearerToken);\n\n return url.toString();\n }\n\n /**\n * Establishes the actual WebSocket connection\n *\n * @param bearerToken - The bearer token to use for authentication\n * @returns Promise that resolves when connection is established\n */\n async #establishConnection(bearerToken: string): Promise<void> {\n const wsUrl = this.#buildAuthenticatedUrl(bearerToken);\n\n return new Promise((resolve, reject) => {\n const ws = new WebSocket(wsUrl);\n this.#connectionTimeout = setTimeout(() => {\n log('WebSocket connection timeout - forcing close', {\n timeout: this.#options.timeout,\n });\n ws.close();\n reject(\n new Error(`Connection timeout after ${this.#options.timeout}ms`),\n );\n }, this.#options.timeout);\n\n ws.onopen = () => {\n if (this.#connectionTimeout) {\n clearTimeout(this.#connectionTimeout);\n this.#connectionTimeout = null;\n }\n this.#ws = ws;\n this.#setState(WebSocketState.CONNECTED);\n this.#connectedAt = Date.now();\n\n // Reset reconnect attempts on successful connection\n this.#reconnectAttempts = 0;\n\n resolve();\n };\n\n ws.onerror = (event: Event) => {\n log('WebSocket onerror event triggered', { event });\n if (this.#state === WebSocketState.CONNECTING) {\n // Handle connection-phase errors\n if (this.#connectionTimeout) {\n clearTimeout(this.#connectionTimeout);\n this.#connectionTimeout = null;\n }\n const error = new Error(`WebSocket connection error to ${wsUrl}`);\n reject(error);\n } else {\n // Handle runtime errors\n this.#handleError(new Error(`WebSocket error: ${event.type}`));\n }\n };\n\n ws.onclose = (event: CloseEvent) => {\n log('WebSocket onclose event triggered', {\n code: event.code,\n reason: event.reason || 'none',\n wasClean: event.wasClean,\n });\n if (this.#state === WebSocketState.CONNECTING) {\n // Handle connection-phase close events\n if (this.#connectionTimeout) {\n clearTimeout(this.#connectionTimeout);\n this.#connectionTimeout = null;\n }\n reject(\n new Error(\n `WebSocket connection closed during connection: ${event.code} ${event.reason}`,\n ),\n );\n } else {\n this.#handleClose(event);\n }\n };\n\n // Set up message handler immediately - no need to wait for connection\n ws.onmessage = (event: MessageEvent) => {\n try {\n const message = this.#parseMessage(event.data);\n this.#handleMessage(message);\n } catch {\n // Silently ignore invalid JSON messages\n }\n };\n });\n }\n\n // =============================================================================\n // 4. MESSAGE HANDLING (PRIVATE)\n // =============================================================================\n\n /**\n * Handles incoming WebSocket messages\n *\n * @param message - The WebSocket message to handle\n */\n #handleMessage(message: WebSocketMessage): void {\n // Handle server responses (correlated with requests) first\n if (this.#isServerResponse(message)) {\n this.#handleServerResponse(message);\n return;\n }\n\n // Handle subscription notifications with valid subscriptionId\n if (this.#isSubscriptionNotification(message)) {\n const handled = this.#handleSubscriptionNotification(\n message as ServerNotificationMessage,\n );\n // If subscription notification wasn't handled (falsy subscriptionId), fall through to channel handling\n if (handled) {\n return;\n }\n }\n\n // Trigger channel callbacks for any message with a channel property\n if (this.#isChannelMessage(message)) {\n this.#handleChannelMessage(message);\n }\n }\n\n /**\n * Checks if a message is a server response (correlated with client requests)\n *\n * @param message - The message to check\n * @returns True if the message is a server response\n */\n #isServerResponse(\n message: WebSocketMessage,\n ): message is ServerResponseMessage {\n return (\n 'data' in message &&\n message.data &&\n typeof message.data === 'object' &&\n 'requestId' in message.data\n );\n }\n\n /**\n * Checks if a message is a subscription notification (has subscriptionId)\n *\n * @param message - The message to check\n * @returns True if the message is a subscription notification with subscriptionId\n */\n #isSubscriptionNotification(message: WebSocketMessage): boolean {\n return 'subscriptionId' in message && !this.#isServerResponse(message);\n }\n\n /**\n * Checks if a message has a channel property (system or subscription notification)\n *\n * @param message - The message to check\n * @returns True if the message has a channel property\n */\n #isChannelMessage(\n message: WebSocketMessage,\n ): message is ServerNotificationMessage {\n return 'channel' in message;\n }\n\n /**\n * Handles server response messages (correlated with client requests)\n *\n * @param message - The server response message to handle\n */\n #handleServerResponse(message: ServerResponseMessage): void {\n const { requestId } = message.data;\n\n const request = this.#pendingRequests.get(requestId);\n if (!request) {\n return;\n }\n\n this.#pendingRequests.delete(requestId);\n clearTimeout(request.timeout);\n\n // Check if the response indicates failure\n if (message.data.failed && message.data.failed.length > 0) {\n request.reject(\n new Error(`Request failed: ${message.data.failed.join(', ')}`),\n );\n } else {\n request.resolve(message.data);\n }\n }\n\n /**\n * Handles messages with channel properties by triggering channel callbacks\n *\n * @param message - The message with channel property to handle\n */\n #handleChannelMessage(message: ServerNotificationMessage): void {\n if (this.#channelCallbacks.size === 0) {\n return;\n }\n\n // Direct lookup for exact channel match\n this.#channelCallbacks.get(message.channel)?.callback(message);\n }\n\n /**\n * Handles server notifications with subscription IDs\n *\n * @param message - The server notification message to handle\n * @returns True if the message was handled, false if it should fall through to channel handling\n */\n #handleSubscriptionNotification(message: ServerNotificationMessage): boolean {\n const { subscriptionId } = message;\n\n // Only handle if subscriptionId is defined and not null (allows \"0\" as valid ID)\n if (subscriptionId !== null && subscriptionId !== undefined) {\n this.#subscriptions.get(subscriptionId)?.callback?.(message);\n return true;\n }\n\n return false;\n }\n\n /**\n * Parse WebSocket message data\n *\n * @param data - The raw message data to parse\n * @returns Parsed message\n */\n #parseMessage(data: string): WebSocketMessage {\n return JSON.parse(data);\n }\n\n // =============================================================================\n // 5. EVENT HANDLERS (PRIVATE)\n // =============================================================================\n\n /**\n * Handles WebSocket close events (mobile optimized)\n *\n * @param event - The WebSocket close event\n */\n #handleClose(event: CloseEvent): void {\n this.#clearTimers();\n this.#connectedAt = null;\n\n // Clear any pending connection promise\n this.#connectionPromise = null;\n\n // Clear subscriptions and pending requests on any disconnect\n // This ensures clean state for reconnection\n this.#clearPendingRequests(new Error('WebSocket connection closed'));\n this.#clearSubscriptions();\n\n if (this.#state === WebSocketState.DISCONNECTING) {\n // Manual disconnect\n this.#setState(WebSocketState.DISCONNECTED);\n return;\n }\n\n // For unexpected disconnects, update the state to reflect that we're disconnected\n this.#setState(WebSocketState.DISCONNECTED);\n\n // Check if we should attempt reconnection based on close code\n const shouldReconnect = this.#shouldReconnectOnClose(event.code);\n\n if (shouldReconnect) {\n log('Connection lost unexpectedly, will attempt reconnection', {\n code: event.code,\n });\n this.#scheduleReconnect();\n }\n }\n\n /**\n * Handles WebSocket errors\n *\n * @param _error - Error that occurred (unused)\n */\n #handleError(_error: Error): void {\n // Placeholder for future error handling logic\n }\n\n // =============================================================================\n // 6. STATE MANAGEMENT (PRIVATE)\n // =============================================================================\n\n /**\n * Schedules a reconnection attempt with exponential backoff\n */\n #scheduleReconnect(): void {\n this.#reconnectAttempts += 1;\n\n const rawDelay =\n this.#options.reconnectDelay * Math.pow(1.5, this.#reconnectAttempts - 1);\n const delay = Math.min(rawDelay, this.#options.maxReconnectDelay);\n\n log('Scheduling reconnection attempt', {\n attempt: this.#reconnectAttempts,\n delayMs: delay,\n });\n\n this.#reconnectTimer = setTimeout(() => {\n // Clear timer reference first\n this.#reconnectTimer = null;\n\n // Check if connection is still enabled before reconnecting\n if (this.#isEnabled && !this.#isEnabled()) {\n log('Reconnection disabled by isEnabled - stopping all attempts');\n this.#reconnectAttempts = 0;\n return;\n }\n\n // Attempt to reconnect - if it fails, schedule another attempt\n this.connect().catch(() => {\n this.#scheduleReconnect();\n });\n }, delay);\n }\n\n /**\n * Clears all active timers\n */\n #clearTimers(): void {\n if (this.#reconnectTimer) {\n clearTimeout(this.#reconnectTimer);\n this.#reconnectTimer = null;\n }\n if (this.#connectionTimeout) {\n clearTimeout(this.#connectionTimeout);\n this.#connectionTimeout = null;\n }\n }\n\n /**\n * Clears all pending requests and rejects them with the given error\n *\n * @param error - Error to reject with\n */\n #clearPendingRequests(error: Error): void {\n for (const [, request] of this.#pendingRequests) {\n clearTimeout(request.timeout);\n request.reject(error);\n }\n this.#pendingRequests.clear();\n }\n\n /**\n * Clears all active subscriptions\n */\n #clearSubscriptions(): void {\n this.#subscriptions.clear();\n }\n\n /**\n * Sets the connection state and emits state change events\n *\n * @param newState - The new WebSocket state\n */\n #setState(newState: WebSocketState): void {\n const oldState = this.#state;\n this.#state = newState;\n\n if (oldState !== newState) {\n log('WebSocket state changed', { oldState, newState });\n\n // Publish connection state change event\n // Messenger handles listener errors internally, no need for try-catch\n this.#messenger.publish(\n 'BackendWebSocketService:connectionStateChanged',\n this.getConnectionInfo(),\n );\n }\n }\n\n // =============================================================================\n // 7. UTILITY METHODS (PRIVATE)\n // =============================================================================\n\n /**\n * Determines if reconnection should be attempted based on close code\n *\n * @param code - WebSocket close code\n * @returns True if reconnection should be attempted\n */\n #shouldReconnectOnClose(code: number): boolean {\n // Don't reconnect only on normal closure (manual disconnect)\n return code !== 1000;\n }\n}\n"]}
@@ -0,0 +1,366 @@
1
+ import type { RestrictedMessenger } from "@metamask/base-controller";
2
+ import type { AuthenticationController } from "@metamask/profile-sync-controller";
3
+ import type { BackendWebSocketServiceMethodActions } from "./BackendWebSocketService-method-action-types.cjs";
4
+ declare const SERVICE_NAME: "BackendWebSocketService";
5
+ /**
6
+ * Gets human-readable close reason from RFC 6455 close code
7
+ *
8
+ * @param code - WebSocket close code
9
+ * @returns Human-readable close reason
10
+ */
11
+ export declare function getCloseReason(code: number): string;
12
+ /**
13
+ * WebSocket connection states
14
+ */
15
+ export declare enum WebSocketState {
16
+ CONNECTING = "connecting",
17
+ CONNECTED = "connected",
18
+ DISCONNECTING = "disconnecting",
19
+ DISCONNECTED = "disconnected",
20
+ ERROR = "error"
21
+ }
22
+ /**
23
+ * WebSocket event types
24
+ */
25
+ export declare enum WebSocketEventType {
26
+ CONNECTED = "connected",
27
+ DISCONNECTED = "disconnected",
28
+ MESSAGE = "message",
29
+ ERROR = "error",
30
+ RECONNECTING = "reconnecting",
31
+ RECONNECTED = "reconnected"
32
+ }
33
+ /**
34
+ * Configuration options for the WebSocket service
35
+ */
36
+ export type BackendWebSocketServiceOptions = {
37
+ /** The WebSocket URL to connect to */
38
+ url: string;
39
+ /** The messenger for inter-service communication */
40
+ messenger: BackendWebSocketServiceMessenger;
41
+ /** Connection timeout in milliseconds (default: 10000) */
42
+ timeout?: number;
43
+ /** Initial reconnection delay in milliseconds (default: 500) */
44
+ reconnectDelay?: number;
45
+ /** Maximum reconnection delay in milliseconds (default: 5000) */
46
+ maxReconnectDelay?: number;
47
+ /** Request timeout in milliseconds (default: 30000) */
48
+ requestTimeout?: number;
49
+ /** Optional callback to determine if connection should be enabled (default: always enabled) */
50
+ isEnabled?: () => boolean;
51
+ };
52
+ /**
53
+ * Client Request message
54
+ * Used when client sends a request to the server
55
+ */
56
+ export type ClientRequestMessage = {
57
+ event: string;
58
+ data: {
59
+ requestId: string;
60
+ channels?: string[];
61
+ [key: string]: unknown;
62
+ };
63
+ };
64
+ /**
65
+ * Server Response message
66
+ * Used when server responds to a client request
67
+ */
68
+ export type ServerResponseMessage = {
69
+ event: string;
70
+ data: {
71
+ requestId: string;
72
+ subscriptionId?: string;
73
+ succeeded?: string[];
74
+ failed?: string[];
75
+ [key: string]: unknown;
76
+ };
77
+ };
78
+ /**
79
+ * Server Notification message
80
+ * Used when server sends unsolicited data to client
81
+ * subscriptionId is optional for system-wide notifications
82
+ */
83
+ export type ServerNotificationMessage = {
84
+ event: string;
85
+ subscriptionId?: string;
86
+ channel: string;
87
+ data: Record<string, unknown>;
88
+ };
89
+ /**
90
+ * Union type for all WebSocket messages
91
+ */
92
+ export type WebSocketMessage = ClientRequestMessage | ServerResponseMessage | ServerNotificationMessage;
93
+ /**
94
+ * Channel-based callback configuration
95
+ */
96
+ export type ChannelCallback = {
97
+ /** Channel name to match (also serves as the unique identifier) */
98
+ channelName: string;
99
+ /** Callback function */
100
+ callback: (notification: ServerNotificationMessage) => void;
101
+ };
102
+ /**
103
+ * Unified WebSocket subscription object used for both internal storage and external API
104
+ */
105
+ export type WebSocketSubscription = {
106
+ /** The subscription ID from the server */
107
+ subscriptionId: string;
108
+ /** Channel names for this subscription */
109
+ channels: string[];
110
+ /** Callback function for handling notifications (optional for external use) */
111
+ callback?: (notification: ServerNotificationMessage) => void;
112
+ /** Function to unsubscribe and clean up */
113
+ unsubscribe: (requestId?: string) => Promise<void>;
114
+ };
115
+ /**
116
+ * WebSocket connection info
117
+ */
118
+ export type WebSocketConnectionInfo = {
119
+ state: WebSocketState;
120
+ url: string;
121
+ reconnectAttempts: number;
122
+ connectedAt?: number;
123
+ };
124
+ export type BackendWebSocketServiceActions = BackendWebSocketServiceMethodActions;
125
+ export type BackendWebSocketServiceAllowedActions = AuthenticationController.AuthenticationControllerGetBearerToken | BackendWebSocketServiceMethodActions;
126
+ export type BackendWebSocketServiceAllowedEvents = AuthenticationController.AuthenticationControllerStateChangeEvent | BackendWebSocketServiceConnectionStateChangedEvent;
127
+ export type BackendWebSocketServiceConnectionStateChangedEvent = {
128
+ type: 'BackendWebSocketService:connectionStateChanged';
129
+ payload: [WebSocketConnectionInfo];
130
+ };
131
+ export type BackendWebSocketServiceEvents = BackendWebSocketServiceConnectionStateChangedEvent;
132
+ export type BackendWebSocketServiceMessenger = RestrictedMessenger<typeof SERVICE_NAME, BackendWebSocketServiceActions | BackendWebSocketServiceAllowedActions, BackendWebSocketServiceEvents | BackendWebSocketServiceAllowedEvents, BackendWebSocketServiceAllowedActions['type'], BackendWebSocketServiceAllowedEvents['type']>;
133
+ /**
134
+ * WebSocket Service with automatic reconnection, session management and direct callback routing
135
+ *
136
+ * Real-Time Performance Optimizations:
137
+ * - Fast path message routing (zero allocations)
138
+ * - Production mode removes try-catch overhead
139
+ * - Optimized JSON parsing with fail-fast
140
+ * - Direct callback routing bypasses event emitters
141
+ * - Memory cleanup and resource management
142
+ *
143
+ * Mobile Integration:
144
+ * Mobile apps should handle lifecycle events (background/foreground) by:
145
+ * 1. Calling disconnect() when app goes to background
146
+ * 2. Calling connect() when app returns to foreground
147
+ * 3. Calling destroy() on app termination
148
+ */
149
+ export declare class BackendWebSocketService {
150
+ #private;
151
+ /**
152
+ * The name of the service.
153
+ */
154
+ readonly name: "BackendWebSocketService";
155
+ /**
156
+ * Creates a new WebSocket service instance
157
+ *
158
+ * @param options - Configuration options for the WebSocket service
159
+ */
160
+ constructor(options: BackendWebSocketServiceOptions);
161
+ /**
162
+ * Establishes WebSocket connection with smart reconnection behavior
163
+ *
164
+ * Simplified Priority System (using AuthenticationController):
165
+ * 1. App closed/backgrounded → Stop all attempts (save resources)
166
+ * 2. User not signed in (wallet locked OR not authenticated) → Keep retrying
167
+ * 3. User signed in (wallet unlocked + authenticated) → Connect successfully
168
+ *
169
+ * @returns Promise that resolves when connection is established
170
+ */
171
+ connect(): Promise<void>;
172
+ /**
173
+ * Closes WebSocket connection
174
+ *
175
+ * @returns Promise that resolves when disconnection is complete
176
+ */
177
+ disconnect(): Promise<void>;
178
+ /**
179
+ * Sends a message through the WebSocket (fire-and-forget, no response expected)
180
+ *
181
+ * This is a low-level method for sending messages without waiting for a response.
182
+ * Most consumers should use `sendRequest()` instead, which handles request-response
183
+ * correlation and provides proper error handling with timeouts.
184
+ *
185
+ * Use this method only when:
186
+ * - You don't need a response from the server
187
+ * - You're implementing custom message protocols
188
+ * - You need fine-grained control over message timing
189
+ *
190
+ * @param message - The message to send
191
+ * @throws Error if WebSocket is not connected or send fails
192
+ *
193
+ * @see sendRequest for request-response pattern with automatic correlation
194
+ */
195
+ sendMessage(message: ClientRequestMessage): void;
196
+ /**
197
+ * Sends a request and waits for a correlated response (recommended for most use cases)
198
+ *
199
+ * This is the recommended high-level method for request-response communication.
200
+ * It automatically handles:
201
+ * - Request ID generation and correlation
202
+ * - Response matching with timeout protection
203
+ * - Automatic reconnection on timeout
204
+ * - Proper cleanup of pending requests
205
+ *
206
+ * @param message - The request message (can include optional requestId for testing)
207
+ * @returns Promise that resolves with the response data
208
+ * @throws Error if WebSocket is not connected, request times out, or response indicates failure
209
+ *
210
+ * @see sendMessage for fire-and-forget messaging without response handling
211
+ */
212
+ sendRequest<T = ServerResponseMessage['data']>(message: Omit<ClientRequestMessage, 'data'> & {
213
+ data?: Omit<ClientRequestMessage['data'], 'requestId'> & {
214
+ requestId?: string;
215
+ };
216
+ }): Promise<T>;
217
+ /**
218
+ * Gets current connection information
219
+ *
220
+ * @returns Current connection status and details
221
+ */
222
+ getConnectionInfo(): WebSocketConnectionInfo;
223
+ /**
224
+ * Gets all subscription information for a specific channel
225
+ *
226
+ * @param channel - The channel name to look up
227
+ * @returns Array of subscription details for all subscriptions containing the channel
228
+ */
229
+ getSubscriptionsByChannel(channel: string): WebSocketSubscription[];
230
+ /**
231
+ * Checks if a channel has a subscription
232
+ *
233
+ * @param channel - The channel name to check
234
+ * @returns True if the channel has a subscription, false otherwise
235
+ */
236
+ channelHasSubscription(channel: string): boolean;
237
+ /**
238
+ * Finds all subscriptions that have channels starting with the specified prefix
239
+ *
240
+ * @param channelPrefix - The channel prefix to search for (e.g., "account-activity.v1")
241
+ * @returns Array of subscription info for matching subscriptions
242
+ */
243
+ findSubscriptionsByChannelPrefix(channelPrefix: string): WebSocketSubscription[];
244
+ /**
245
+ * Register a callback for specific channels (local callback only, no server subscription)
246
+ *
247
+ * **Key Difference from `subscribe()`:**
248
+ * - `addChannelCallback()`: Registers a local callback without creating a server-side subscription.
249
+ * The callback triggers on ANY message matching the channel name, regardless of subscriptionId.
250
+ * Useful for system-wide notifications or when you don't control the subscription lifecycle.
251
+ *
252
+ * - `subscribe()`: Creates a proper server-side subscription with a subscriptionId.
253
+ * The callback only triggers for messages with the matching subscriptionId.
254
+ * Includes proper lifecycle management (unsubscribe, automatic cleanup on disconnect).
255
+ *
256
+ * **When to use `addChannelCallback()`:**
257
+ * - Listening to system-wide notifications (e.g., 'system-notifications.v1')
258
+ * - Monitoring channels where subscriptions are managed elsewhere
259
+ * - Debug/logging scenarios where you want to observe all channel messages
260
+ *
261
+ * **When to use `subscribe()` instead:**
262
+ * - Creating new subscriptions that need server-side registration
263
+ * - When you need proper cleanup via unsubscribe
264
+ * - Most application use cases (recommended approach)
265
+ *
266
+ * @param options - Channel callback configuration
267
+ * @param options.channelName - Channel name to match exactly
268
+ * @param options.callback - Function to call when channel matches
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * // Listen to system notifications (no server subscription needed)
273
+ * webSocketService.addChannelCallback({
274
+ * channelName: 'system-notifications.v1',
275
+ * callback: (notification) => {
276
+ * console.log('System notification:', notification.data);
277
+ * }
278
+ * });
279
+ *
280
+ * // For account-specific subscriptions, use subscribe() instead:
281
+ * // const sub = await webSocketService.subscribe({
282
+ * // channels: ['account-activity.v1.eip155:0:0x1234...'],
283
+ * // callback: (notification) => { ... }
284
+ * // });
285
+ * ```
286
+ *
287
+ * @see subscribe for creating proper server-side subscriptions with lifecycle management
288
+ */
289
+ addChannelCallback(options: {
290
+ channelName: string;
291
+ callback: (notification: ServerNotificationMessage) => void;
292
+ }): void;
293
+ /**
294
+ * Remove a channel callback
295
+ *
296
+ * @param channelName - The channel name returned from addChannelCallback
297
+ * @returns True if callback was found and removed, false otherwise
298
+ */
299
+ removeChannelCallback(channelName: string): boolean;
300
+ /**
301
+ * Get all registered channel callbacks (for debugging)
302
+ *
303
+ * @returns Array of all registered channel callbacks
304
+ */
305
+ getChannelCallbacks(): ChannelCallback[];
306
+ /**
307
+ * Destroy the service and clean up resources
308
+ * Called when service is being destroyed or app is terminating
309
+ */
310
+ destroy(): void;
311
+ /**
312
+ * Create and manage a subscription with server-side registration (recommended for most use cases)
313
+ *
314
+ * This is the recommended subscription API for high-level services. It creates a proper
315
+ * server-side subscription and routes notifications based on subscriptionId.
316
+ *
317
+ * **Key Features:**
318
+ * - Creates server-side subscription with unique subscriptionId
319
+ * - Callback triggered only for messages with matching subscriptionId
320
+ * - Automatic lifecycle management (cleanup on disconnect)
321
+ * - Includes unsubscribe method for proper cleanup
322
+ * - Request-response pattern with error handling
323
+ *
324
+ * **When to use `subscribe()`:**
325
+ * - Creating new subscriptions (account activity, price updates, etc.)
326
+ * - When you need proper cleanup/unsubscribe functionality
327
+ * - Most application use cases
328
+ *
329
+ * **When to use `addChannelCallback()` instead:**
330
+ * - System-wide notifications without server-side subscription
331
+ * - Observing channels managed elsewhere
332
+ * - Debug/logging scenarios
333
+ *
334
+ * @param options - Subscription configuration
335
+ * @param options.channels - Array of channel names to subscribe to
336
+ * @param options.callback - Callback function for handling notifications
337
+ * @param options.requestId - Optional request ID for testing (will generate UUID if not provided)
338
+ * @returns Subscription object with unsubscribe method
339
+ *
340
+ * @example
341
+ * ```typescript
342
+ * // AccountActivityService usage
343
+ * const subscription = await webSocketService.subscribe({
344
+ * channels: ['account-activity.v1.eip155:0:0x1234...'],
345
+ * callback: (notification) => {
346
+ * this.handleAccountActivity(notification.data);
347
+ * }
348
+ * });
349
+ *
350
+ * // Later, clean up
351
+ * await subscription.unsubscribe();
352
+ * ```
353
+ *
354
+ * @see addChannelCallback for local callbacks without server-side subscription
355
+ */
356
+ subscribe(options: {
357
+ /** Channel names to subscribe to */
358
+ channels: string[];
359
+ /** Handler for incoming notifications */
360
+ callback: (notification: ServerNotificationMessage) => void;
361
+ /** Optional request ID for testing (will generate UUID if not provided) */
362
+ requestId?: string;
363
+ }): Promise<WebSocketSubscription>;
364
+ }
365
+ export {};
366
+ //# sourceMappingURL=BackendWebSocketService.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackendWebSocketService.d.cts","sourceRoot":"","sources":["../src/BackendWebSocketService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AACrE,OAAO,KAAK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