@metamask-previews/core-backend 4.1.0-preview-fa19a4d3 → 4.1.0-preview-96f3a4d7
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.
- package/dist/BackendWebSocketService-method-action-types.cjs.map +1 -1
- package/dist/BackendWebSocketService-method-action-types.d.cts +20 -106
- package/dist/BackendWebSocketService-method-action-types.d.cts.map +1 -1
- package/dist/BackendWebSocketService-method-action-types.d.mts +20 -106
- package/dist/BackendWebSocketService-method-action-types.d.mts.map +1 -1
- package/dist/BackendWebSocketService-method-action-types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendWebSocketService-method-action-types.cjs","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { BackendWebSocketService } from './BackendWebSocketService';\n\n/**\n * Establishes WebSocket connection with smart reconnection behavior\n *\n * Connection Requirements (all must be true):\n * 1. Feature enabled (isEnabled() = true)\n * 2. Wallet unlocked (checked by getBearerToken)\n * 3. User signed in (checked by getBearerToken)\n *\n * Platform code should call this when app opens/foregrounds.\n * Automatically called on KeyringController:unlock event.\n *\n * @returns Promise that resolves when connection is established\n */\nexport type BackendWebSocketServiceConnectAction = {\n type: `BackendWebSocketService:connect`;\n handler: BackendWebSocketService['connect'];\n};\n\n/**\n * Closes WebSocket connection\n */\nexport type BackendWebSocketServiceDisconnectAction = {\n type: `BackendWebSocketService:disconnect`;\n handler: BackendWebSocketService['disconnect'];\n};\n\n/**\n * Forces a WebSocket reconnection to clean up subscription state\n *\n * This method is useful when subscription state may be out of sync and needs to be reset.\n * It performs a controlled disconnect-then-reconnect sequence:\n * - Disconnects cleanly to trigger subscription cleanup\n * - Schedules reconnection with exponential backoff to prevent rapid loops\n * - All subscriptions will be cleaned up automatically on disconnect\n *\n * Use cases:\n * - Recovering from subscription/unsubscription issues\n * - Cleaning up orphaned subscriptions\n * - Forcing a fresh subscription state\n *\n * @returns Promise that resolves when disconnection is complete (reconnection is scheduled)\n */\nexport type BackendWebSocketServiceForceReconnectionAction = {\n type: `BackendWebSocketService:forceReconnection`;\n handler: BackendWebSocketService['forceReconnection'];\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 */\nexport type BackendWebSocketServiceSendMessageAction = {\n type: `BackendWebSocketService:sendMessage`;\n handler: BackendWebSocketService['sendMessage'];\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 */\nexport type BackendWebSocketServiceSendRequestAction = {\n type: `BackendWebSocketService:sendRequest`;\n handler: BackendWebSocketService['sendRequest'];\n};\n\n/**\n * Gets current connection information\n *\n * @returns Current connection status and details\n */\nexport type BackendWebSocketServiceGetConnectionInfoAction = {\n type: `BackendWebSocketService:getConnectionInfo`;\n handler: BackendWebSocketService['getConnectionInfo'];\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 */\nexport type BackendWebSocketServiceGetSubscriptionsByChannelAction = {\n type: `BackendWebSocketService:getSubscriptionsByChannel`;\n handler: BackendWebSocketService['getSubscriptionsByChannel'];\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 */\nexport type BackendWebSocketServiceChannelHasSubscriptionAction = {\n type: `BackendWebSocketService:channelHasSubscription`;\n handler: BackendWebSocketService['channelHasSubscription'];\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 */\nexport type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {\n type: `BackendWebSocketService:findSubscriptionsByChannelPrefix`;\n handler: BackendWebSocketService['findSubscriptionsByChannelPrefix'];\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 */\nexport type BackendWebSocketServiceAddChannelCallbackAction = {\n type: `BackendWebSocketService:addChannelCallback`;\n handler: BackendWebSocketService['addChannelCallback'];\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 */\nexport type BackendWebSocketServiceRemoveChannelCallbackAction = {\n type: `BackendWebSocketService:removeChannelCallback`;\n handler: BackendWebSocketService['removeChannelCallback'];\n};\n\n/**\n * Get all registered channel callbacks (for debugging)\n *\n * @returns Array of all registered channel callbacks\n */\nexport type BackendWebSocketServiceGetChannelCallbacksAction = {\n type: `BackendWebSocketService:getChannelCallbacks`;\n handler: BackendWebSocketService['getChannelCallbacks'];\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 * @param options.channelType - Channel type identifier\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 */\nexport type BackendWebSocketServiceSubscribeAction = {\n type: `BackendWebSocketService:subscribe`;\n handler: BackendWebSocketService['subscribe'];\n};\n\n/**\n * Union of all BackendWebSocketService action types.\n */\nexport type BackendWebSocketServiceMethodActions =\n | BackendWebSocketServiceConnectAction\n | BackendWebSocketServiceDisconnectAction\n | BackendWebSocketServiceForceReconnectionAction\n | BackendWebSocketServiceSendMessageAction\n | BackendWebSocketServiceSendRequestAction\n | BackendWebSocketServiceGetConnectionInfoAction\n | BackendWebSocketServiceGetSubscriptionsByChannelAction\n | BackendWebSocketServiceChannelHasSubscriptionAction\n | BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction\n | BackendWebSocketServiceAddChannelCallbackAction\n | BackendWebSocketServiceRemoveChannelCallbackAction\n | BackendWebSocketServiceGetChannelCallbacksAction\n | BackendWebSocketServiceSubscribeAction;\n"]}
|
|
1
|
+
{"version":3,"file":"BackendWebSocketService-method-action-types.cjs","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { BackendWebSocketService } from './BackendWebSocketService';\n\n/**\n * Establishes WebSocket connection\n *\n * @returns Promise that resolves when connection is established\n */\nexport type BackendWebSocketServiceConnectAction = {\n type: `BackendWebSocketService:connect`;\n handler: BackendWebSocketService['connect'];\n};\n\n/**\n * Closes WebSocket connection\n *\n * @returns Promise that resolves when disconnection is complete\n */\nexport type BackendWebSocketServiceDisconnectAction = {\n type: `BackendWebSocketService:disconnect`;\n handler: BackendWebSocketService['disconnect'];\n};\n\n/**\n * Forces a WebSocket reconnection to clean up subscription state\n *\n * This method is useful when subscription state may be out of sync and needs to be reset.\n * It performs a controlled disconnect-then-reconnect sequence:\n * - Disconnects cleanly to trigger subscription cleanup\n * - Schedules reconnection with exponential backoff to prevent rapid loops\n * - All subscriptions will be cleaned up automatically on disconnect\n *\n * Use cases:\n * - Recovering from subscription/unsubscription issues\n * - Cleaning up orphaned subscriptions\n * - Forcing a fresh subscription state\n *\n * @returns Promise that resolves when disconnection is complete (reconnection is scheduled)\n */\nexport type BackendWebSocketServiceForceReconnectionAction = {\n type: `BackendWebSocketService:forceReconnection`;\n handler: BackendWebSocketService['forceReconnection'];\n};\n\n/**\n * Sends a message through the WebSocket\n *\n * @param message - The message to send\n * @returns Promise that resolves when message is sent\n */\nexport type BackendWebSocketServiceSendMessageAction = {\n type: `BackendWebSocketService:sendMessage`;\n handler: BackendWebSocketService['sendMessage'];\n};\n\n/**\n * Sends a request and waits for a correlated response\n *\n * @param message - The request message\n * @returns Promise that resolves with the response data\n */\nexport type BackendWebSocketServiceSendRequestAction = {\n type: `BackendWebSocketService:sendRequest`;\n handler: BackendWebSocketService['sendRequest'];\n};\n\n/**\n * Gets current connection information\n *\n * @returns Current connection status and details\n */\nexport type BackendWebSocketServiceGetConnectionInfoAction = {\n type: `BackendWebSocketService:getConnectionInfo`;\n handler: BackendWebSocketService['getConnectionInfo'];\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 */\nexport type BackendWebSocketServiceGetSubscriptionsByChannelAction = {\n type: `BackendWebSocketService:getSubscriptionsByChannel`;\n handler: BackendWebSocketService['getSubscriptionsByChannel'];\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 */\nexport type BackendWebSocketServiceChannelHasSubscriptionAction = {\n type: `BackendWebSocketService:channelHasSubscription`;\n handler: BackendWebSocketService['channelHasSubscription'];\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 */\nexport type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {\n type: `BackendWebSocketService:findSubscriptionsByChannelPrefix`;\n handler: BackendWebSocketService['findSubscriptionsByChannelPrefix'];\n};\n\n/**\n * Register a callback for specific channels\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 specific account activity channel\n * webSocketService.addChannelCallback({\n * channelName: 'account-activity.v1.eip155:0:0x1234...',\n * callback: (notification) => {\n * console.log('Account activity:', notification.data);\n * }\n * });\n *\n * // Listen to system notifications channel\n * webSocketService.addChannelCallback({\n * channelName: 'system-notifications.v1',\n * callback: (notification) => {\n * console.log('System notification:', notification.data);\n * }\n * });\n * ```\n */\nexport type BackendWebSocketServiceAddChannelCallbackAction = {\n type: `BackendWebSocketService:addChannelCallback`;\n handler: BackendWebSocketService['addChannelCallback'];\n};\n\n/**\n * Remove a channel callback\n *\n * @param channelName - The channel name to remove callback for\n * @returns True if callback was found and removed, false otherwise\n */\nexport type BackendWebSocketServiceRemoveChannelCallbackAction = {\n type: `BackendWebSocketService:removeChannelCallback`;\n handler: BackendWebSocketService['removeChannelCallback'];\n};\n\n/**\n * Get all registered channel callbacks (for debugging)\n */\nexport type BackendWebSocketServiceGetChannelCallbacksAction = {\n type: `BackendWebSocketService:getChannelCallbacks`;\n handler: BackendWebSocketService['getChannelCallbacks'];\n};\n\n/**\n * Create and manage a subscription with direct callback routing\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 * @returns Promise that resolves with subscription object containing unsubscribe method\n */\nexport type BackendWebSocketServiceSubscribeAction = {\n type: `BackendWebSocketService:subscribe`;\n handler: BackendWebSocketService['subscribe'];\n};\n\n/**\n * Union of all BackendWebSocketService action types.\n */\nexport type BackendWebSocketServiceMethodActions =\n | BackendWebSocketServiceConnectAction\n | BackendWebSocketServiceDisconnectAction\n | BackendWebSocketServiceForceReconnectionAction\n | BackendWebSocketServiceSendMessageAction\n | BackendWebSocketServiceSendRequestAction\n | BackendWebSocketServiceGetConnectionInfoAction\n | BackendWebSocketServiceGetSubscriptionsByChannelAction\n | BackendWebSocketServiceChannelHasSubscriptionAction\n | BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction\n | BackendWebSocketServiceAddChannelCallbackAction\n | BackendWebSocketServiceRemoveChannelCallbackAction\n | BackendWebSocketServiceGetChannelCallbacksAction\n | BackendWebSocketServiceSubscribeAction;\n"]}
|
|
@@ -4,15 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { BackendWebSocketService } from "./BackendWebSocketService.cjs";
|
|
6
6
|
/**
|
|
7
|
-
* Establishes WebSocket connection
|
|
8
|
-
*
|
|
9
|
-
* Connection Requirements (all must be true):
|
|
10
|
-
* 1. Feature enabled (isEnabled() = true)
|
|
11
|
-
* 2. Wallet unlocked (checked by getBearerToken)
|
|
12
|
-
* 3. User signed in (checked by getBearerToken)
|
|
13
|
-
*
|
|
14
|
-
* Platform code should call this when app opens/foregrounds.
|
|
15
|
-
* Automatically called on KeyringController:unlock event.
|
|
7
|
+
* Establishes WebSocket connection
|
|
16
8
|
*
|
|
17
9
|
* @returns Promise that resolves when connection is established
|
|
18
10
|
*/
|
|
@@ -22,6 +14,8 @@ export type BackendWebSocketServiceConnectAction = {
|
|
|
22
14
|
};
|
|
23
15
|
/**
|
|
24
16
|
* Closes WebSocket connection
|
|
17
|
+
*
|
|
18
|
+
* @returns Promise that resolves when disconnection is complete
|
|
25
19
|
*/
|
|
26
20
|
export type BackendWebSocketServiceDisconnectAction = {
|
|
27
21
|
type: `BackendWebSocketService:disconnect`;
|
|
@@ -48,41 +42,20 @@ export type BackendWebSocketServiceForceReconnectionAction = {
|
|
|
48
42
|
handler: BackendWebSocketService['forceReconnection'];
|
|
49
43
|
};
|
|
50
44
|
/**
|
|
51
|
-
* Sends a message through the WebSocket
|
|
52
|
-
*
|
|
53
|
-
* This is a low-level method for sending messages without waiting for a response.
|
|
54
|
-
* Most consumers should use `sendRequest()` instead, which handles request-response
|
|
55
|
-
* correlation and provides proper error handling with timeouts.
|
|
56
|
-
*
|
|
57
|
-
* Use this method only when:
|
|
58
|
-
* - You don't need a response from the server
|
|
59
|
-
* - You're implementing custom message protocols
|
|
60
|
-
* - You need fine-grained control over message timing
|
|
45
|
+
* Sends a message through the WebSocket
|
|
61
46
|
*
|
|
62
47
|
* @param message - The message to send
|
|
63
|
-
* @
|
|
64
|
-
*
|
|
65
|
-
* @see sendRequest for request-response pattern with automatic correlation
|
|
48
|
+
* @returns Promise that resolves when message is sent
|
|
66
49
|
*/
|
|
67
50
|
export type BackendWebSocketServiceSendMessageAction = {
|
|
68
51
|
type: `BackendWebSocketService:sendMessage`;
|
|
69
52
|
handler: BackendWebSocketService['sendMessage'];
|
|
70
53
|
};
|
|
71
54
|
/**
|
|
72
|
-
* Sends a request and waits for a correlated response
|
|
73
|
-
*
|
|
74
|
-
* This is the recommended high-level method for request-response communication.
|
|
75
|
-
* It automatically handles:
|
|
76
|
-
* - Request ID generation and correlation
|
|
77
|
-
* - Response matching with timeout protection
|
|
78
|
-
* - Automatic reconnection on timeout
|
|
79
|
-
* - Proper cleanup of pending requests
|
|
55
|
+
* Sends a request and waits for a correlated response
|
|
80
56
|
*
|
|
81
|
-
* @param message - The request message
|
|
57
|
+
* @param message - The request message
|
|
82
58
|
* @returns Promise that resolves with the response data
|
|
83
|
-
* @throws Error if WebSocket is not connected, request times out, or response indicates failure
|
|
84
|
-
*
|
|
85
|
-
* @see sendMessage for fire-and-forget messaging without response handling
|
|
86
59
|
*/
|
|
87
60
|
export type BackendWebSocketServiceSendRequestAction = {
|
|
88
61
|
type: `BackendWebSocketService:sendRequest`;
|
|
@@ -128,26 +101,7 @@ export type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {
|
|
|
128
101
|
handler: BackendWebSocketService['findSubscriptionsByChannelPrefix'];
|
|
129
102
|
};
|
|
130
103
|
/**
|
|
131
|
-
* Register a callback for specific channels
|
|
132
|
-
*
|
|
133
|
-
* **Key Difference from `subscribe()`:**
|
|
134
|
-
* - `addChannelCallback()`: Registers a local callback without creating a server-side subscription.
|
|
135
|
-
* The callback triggers on ANY message matching the channel name, regardless of subscriptionId.
|
|
136
|
-
* Useful for system-wide notifications or when you don't control the subscription lifecycle.
|
|
137
|
-
*
|
|
138
|
-
* - `subscribe()`: Creates a proper server-side subscription with a subscriptionId.
|
|
139
|
-
* The callback only triggers for messages with the matching subscriptionId.
|
|
140
|
-
* Includes proper lifecycle management (unsubscribe, automatic cleanup on disconnect).
|
|
141
|
-
*
|
|
142
|
-
* **When to use `addChannelCallback()`:**
|
|
143
|
-
* - Listening to system-wide notifications (e.g., 'system-notifications.v1')
|
|
144
|
-
* - Monitoring channels where subscriptions are managed elsewhere
|
|
145
|
-
* - Debug/logging scenarios where you want to observe all channel messages
|
|
146
|
-
*
|
|
147
|
-
* **When to use `subscribe()` instead:**
|
|
148
|
-
* - Creating new subscriptions that need server-side registration
|
|
149
|
-
* - When you need proper cleanup via unsubscribe
|
|
150
|
-
* - Most application use cases (recommended approach)
|
|
104
|
+
* Register a callback for specific channels
|
|
151
105
|
*
|
|
152
106
|
* @param options - Channel callback configuration
|
|
153
107
|
* @param options.channelName - Channel name to match exactly
|
|
@@ -155,22 +109,22 @@ export type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {
|
|
|
155
109
|
*
|
|
156
110
|
* @example
|
|
157
111
|
* ```typescript
|
|
158
|
-
* // Listen to
|
|
112
|
+
* // Listen to specific account activity channel
|
|
113
|
+
* webSocketService.addChannelCallback({
|
|
114
|
+
* channelName: 'account-activity.v1.eip155:0:0x1234...',
|
|
115
|
+
* callback: (notification) => {
|
|
116
|
+
* console.log('Account activity:', notification.data);
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Listen to system notifications channel
|
|
159
121
|
* webSocketService.addChannelCallback({
|
|
160
122
|
* channelName: 'system-notifications.v1',
|
|
161
123
|
* callback: (notification) => {
|
|
162
124
|
* console.log('System notification:', notification.data);
|
|
163
125
|
* }
|
|
164
126
|
* });
|
|
165
|
-
*
|
|
166
|
-
* // For account-specific subscriptions, use subscribe() instead:
|
|
167
|
-
* // const sub = await webSocketService.subscribe({
|
|
168
|
-
* // channels: ['account-activity.v1.eip155:0:0x1234...'],
|
|
169
|
-
* // callback: (notification) => { ... }
|
|
170
|
-
* // });
|
|
171
127
|
* ```
|
|
172
|
-
*
|
|
173
|
-
* @see subscribe for creating proper server-side subscriptions with lifecycle management
|
|
174
128
|
*/
|
|
175
129
|
export type BackendWebSocketServiceAddChannelCallbackAction = {
|
|
176
130
|
type: `BackendWebSocketService:addChannelCallback`;
|
|
@@ -179,7 +133,7 @@ export type BackendWebSocketServiceAddChannelCallbackAction = {
|
|
|
179
133
|
/**
|
|
180
134
|
* Remove a channel callback
|
|
181
135
|
*
|
|
182
|
-
* @param channelName - The channel name
|
|
136
|
+
* @param channelName - The channel name to remove callback for
|
|
183
137
|
* @returns True if callback was found and removed, false otherwise
|
|
184
138
|
*/
|
|
185
139
|
export type BackendWebSocketServiceRemoveChannelCallbackAction = {
|
|
@@ -188,58 +142,18 @@ export type BackendWebSocketServiceRemoveChannelCallbackAction = {
|
|
|
188
142
|
};
|
|
189
143
|
/**
|
|
190
144
|
* Get all registered channel callbacks (for debugging)
|
|
191
|
-
*
|
|
192
|
-
* @returns Array of all registered channel callbacks
|
|
193
145
|
*/
|
|
194
146
|
export type BackendWebSocketServiceGetChannelCallbacksAction = {
|
|
195
147
|
type: `BackendWebSocketService:getChannelCallbacks`;
|
|
196
148
|
handler: BackendWebSocketService['getChannelCallbacks'];
|
|
197
149
|
};
|
|
198
150
|
/**
|
|
199
|
-
* Create and manage a subscription with
|
|
200
|
-
*
|
|
201
|
-
* This is the recommended subscription API for high-level services. It creates a proper
|
|
202
|
-
* server-side subscription and routes notifications based on subscriptionId.
|
|
203
|
-
*
|
|
204
|
-
* **Key Features:**
|
|
205
|
-
* - Creates server-side subscription with unique subscriptionId
|
|
206
|
-
* - Callback triggered only for messages with matching subscriptionId
|
|
207
|
-
* - Automatic lifecycle management (cleanup on disconnect)
|
|
208
|
-
* - Includes unsubscribe method for proper cleanup
|
|
209
|
-
* - Request-response pattern with error handling
|
|
210
|
-
*
|
|
211
|
-
* **When to use `subscribe()`:**
|
|
212
|
-
* - Creating new subscriptions (account activity, price updates, etc.)
|
|
213
|
-
* - When you need proper cleanup/unsubscribe functionality
|
|
214
|
-
* - Most application use cases
|
|
215
|
-
*
|
|
216
|
-
* **When to use `addChannelCallback()` instead:**
|
|
217
|
-
* - System-wide notifications without server-side subscription
|
|
218
|
-
* - Observing channels managed elsewhere
|
|
219
|
-
* - Debug/logging scenarios
|
|
151
|
+
* Create and manage a subscription with direct callback routing
|
|
220
152
|
*
|
|
221
153
|
* @param options - Subscription configuration
|
|
222
154
|
* @param options.channels - Array of channel names to subscribe to
|
|
223
155
|
* @param options.callback - Callback function for handling notifications
|
|
224
|
-
* @
|
|
225
|
-
* @param options.channelType - Channel type identifier
|
|
226
|
-
* @returns Subscription object with unsubscribe method
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```typescript
|
|
230
|
-
* // AccountActivityService usage
|
|
231
|
-
* const subscription = await webSocketService.subscribe({
|
|
232
|
-
* channels: ['account-activity.v1.eip155:0:0x1234...'],
|
|
233
|
-
* callback: (notification) => {
|
|
234
|
-
* this.handleAccountActivity(notification.data);
|
|
235
|
-
* }
|
|
236
|
-
* });
|
|
237
|
-
*
|
|
238
|
-
* // Later, clean up
|
|
239
|
-
* await subscription.unsubscribe();
|
|
240
|
-
* ```
|
|
241
|
-
*
|
|
242
|
-
* @see addChannelCallback for local callbacks without server-side subscription
|
|
156
|
+
* @returns Promise that resolves with subscription object containing unsubscribe method
|
|
243
157
|
*/
|
|
244
158
|
export type BackendWebSocketServiceSubscribeAction = {
|
|
245
159
|
type: `BackendWebSocketService:subscribe`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendWebSocketService-method-action-types.d.cts","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAkC;AAEzE
|
|
1
|
+
{"version":3,"file":"BackendWebSocketService-method-action-types.d.cts","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAkC;AAEzE;;;;GAIG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,uBAAuB,CAAC,YAAY,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,uBAAuB,CAAC,aAAa,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,uBAAuB,CAAC,aAAa,CAAC,CAAC;CACjD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sDAAsD,GAAG;IACnE,IAAI,EAAE,mDAAmD,CAAC;IAC1D,OAAO,EAAE,uBAAuB,CAAC,2BAA2B,CAAC,CAAC;CAC/D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mDAAmD,GAAG;IAChE,IAAI,EAAE,gDAAgD,CAAC;IACvD,OAAO,EAAE,uBAAuB,CAAC,wBAAwB,CAAC,CAAC;CAC5D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,6DAA6D,GAAG;IAC1E,IAAI,EAAE,0DAA0D,CAAC;IACjE,OAAO,EAAE,uBAAuB,CAAC,kCAAkC,CAAC,CAAC;CACtE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,uBAAuB,CAAC,oBAAoB,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,uBAAuB,CAAC,uBAAuB,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,uBAAuB,CAAC,WAAW,CAAC,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAC5C,oCAAoC,GACpC,uCAAuC,GACvC,8CAA8C,GAC9C,wCAAwC,GACxC,wCAAwC,GACxC,8CAA8C,GAC9C,sDAAsD,GACtD,mDAAmD,GACnD,6DAA6D,GAC7D,+CAA+C,GAC/C,kDAAkD,GAClD,gDAAgD,GAChD,sCAAsC,CAAC"}
|
|
@@ -4,15 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { BackendWebSocketService } from "./BackendWebSocketService.mjs";
|
|
6
6
|
/**
|
|
7
|
-
* Establishes WebSocket connection
|
|
8
|
-
*
|
|
9
|
-
* Connection Requirements (all must be true):
|
|
10
|
-
* 1. Feature enabled (isEnabled() = true)
|
|
11
|
-
* 2. Wallet unlocked (checked by getBearerToken)
|
|
12
|
-
* 3. User signed in (checked by getBearerToken)
|
|
13
|
-
*
|
|
14
|
-
* Platform code should call this when app opens/foregrounds.
|
|
15
|
-
* Automatically called on KeyringController:unlock event.
|
|
7
|
+
* Establishes WebSocket connection
|
|
16
8
|
*
|
|
17
9
|
* @returns Promise that resolves when connection is established
|
|
18
10
|
*/
|
|
@@ -22,6 +14,8 @@ export type BackendWebSocketServiceConnectAction = {
|
|
|
22
14
|
};
|
|
23
15
|
/**
|
|
24
16
|
* Closes WebSocket connection
|
|
17
|
+
*
|
|
18
|
+
* @returns Promise that resolves when disconnection is complete
|
|
25
19
|
*/
|
|
26
20
|
export type BackendWebSocketServiceDisconnectAction = {
|
|
27
21
|
type: `BackendWebSocketService:disconnect`;
|
|
@@ -48,41 +42,20 @@ export type BackendWebSocketServiceForceReconnectionAction = {
|
|
|
48
42
|
handler: BackendWebSocketService['forceReconnection'];
|
|
49
43
|
};
|
|
50
44
|
/**
|
|
51
|
-
* Sends a message through the WebSocket
|
|
52
|
-
*
|
|
53
|
-
* This is a low-level method for sending messages without waiting for a response.
|
|
54
|
-
* Most consumers should use `sendRequest()` instead, which handles request-response
|
|
55
|
-
* correlation and provides proper error handling with timeouts.
|
|
56
|
-
*
|
|
57
|
-
* Use this method only when:
|
|
58
|
-
* - You don't need a response from the server
|
|
59
|
-
* - You're implementing custom message protocols
|
|
60
|
-
* - You need fine-grained control over message timing
|
|
45
|
+
* Sends a message through the WebSocket
|
|
61
46
|
*
|
|
62
47
|
* @param message - The message to send
|
|
63
|
-
* @
|
|
64
|
-
*
|
|
65
|
-
* @see sendRequest for request-response pattern with automatic correlation
|
|
48
|
+
* @returns Promise that resolves when message is sent
|
|
66
49
|
*/
|
|
67
50
|
export type BackendWebSocketServiceSendMessageAction = {
|
|
68
51
|
type: `BackendWebSocketService:sendMessage`;
|
|
69
52
|
handler: BackendWebSocketService['sendMessage'];
|
|
70
53
|
};
|
|
71
54
|
/**
|
|
72
|
-
* Sends a request and waits for a correlated response
|
|
73
|
-
*
|
|
74
|
-
* This is the recommended high-level method for request-response communication.
|
|
75
|
-
* It automatically handles:
|
|
76
|
-
* - Request ID generation and correlation
|
|
77
|
-
* - Response matching with timeout protection
|
|
78
|
-
* - Automatic reconnection on timeout
|
|
79
|
-
* - Proper cleanup of pending requests
|
|
55
|
+
* Sends a request and waits for a correlated response
|
|
80
56
|
*
|
|
81
|
-
* @param message - The request message
|
|
57
|
+
* @param message - The request message
|
|
82
58
|
* @returns Promise that resolves with the response data
|
|
83
|
-
* @throws Error if WebSocket is not connected, request times out, or response indicates failure
|
|
84
|
-
*
|
|
85
|
-
* @see sendMessage for fire-and-forget messaging without response handling
|
|
86
59
|
*/
|
|
87
60
|
export type BackendWebSocketServiceSendRequestAction = {
|
|
88
61
|
type: `BackendWebSocketService:sendRequest`;
|
|
@@ -128,26 +101,7 @@ export type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {
|
|
|
128
101
|
handler: BackendWebSocketService['findSubscriptionsByChannelPrefix'];
|
|
129
102
|
};
|
|
130
103
|
/**
|
|
131
|
-
* Register a callback for specific channels
|
|
132
|
-
*
|
|
133
|
-
* **Key Difference from `subscribe()`:**
|
|
134
|
-
* - `addChannelCallback()`: Registers a local callback without creating a server-side subscription.
|
|
135
|
-
* The callback triggers on ANY message matching the channel name, regardless of subscriptionId.
|
|
136
|
-
* Useful for system-wide notifications or when you don't control the subscription lifecycle.
|
|
137
|
-
*
|
|
138
|
-
* - `subscribe()`: Creates a proper server-side subscription with a subscriptionId.
|
|
139
|
-
* The callback only triggers for messages with the matching subscriptionId.
|
|
140
|
-
* Includes proper lifecycle management (unsubscribe, automatic cleanup on disconnect).
|
|
141
|
-
*
|
|
142
|
-
* **When to use `addChannelCallback()`:**
|
|
143
|
-
* - Listening to system-wide notifications (e.g., 'system-notifications.v1')
|
|
144
|
-
* - Monitoring channels where subscriptions are managed elsewhere
|
|
145
|
-
* - Debug/logging scenarios where you want to observe all channel messages
|
|
146
|
-
*
|
|
147
|
-
* **When to use `subscribe()` instead:**
|
|
148
|
-
* - Creating new subscriptions that need server-side registration
|
|
149
|
-
* - When you need proper cleanup via unsubscribe
|
|
150
|
-
* - Most application use cases (recommended approach)
|
|
104
|
+
* Register a callback for specific channels
|
|
151
105
|
*
|
|
152
106
|
* @param options - Channel callback configuration
|
|
153
107
|
* @param options.channelName - Channel name to match exactly
|
|
@@ -155,22 +109,22 @@ export type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {
|
|
|
155
109
|
*
|
|
156
110
|
* @example
|
|
157
111
|
* ```typescript
|
|
158
|
-
* // Listen to
|
|
112
|
+
* // Listen to specific account activity channel
|
|
113
|
+
* webSocketService.addChannelCallback({
|
|
114
|
+
* channelName: 'account-activity.v1.eip155:0:0x1234...',
|
|
115
|
+
* callback: (notification) => {
|
|
116
|
+
* console.log('Account activity:', notification.data);
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Listen to system notifications channel
|
|
159
121
|
* webSocketService.addChannelCallback({
|
|
160
122
|
* channelName: 'system-notifications.v1',
|
|
161
123
|
* callback: (notification) => {
|
|
162
124
|
* console.log('System notification:', notification.data);
|
|
163
125
|
* }
|
|
164
126
|
* });
|
|
165
|
-
*
|
|
166
|
-
* // For account-specific subscriptions, use subscribe() instead:
|
|
167
|
-
* // const sub = await webSocketService.subscribe({
|
|
168
|
-
* // channels: ['account-activity.v1.eip155:0:0x1234...'],
|
|
169
|
-
* // callback: (notification) => { ... }
|
|
170
|
-
* // });
|
|
171
127
|
* ```
|
|
172
|
-
*
|
|
173
|
-
* @see subscribe for creating proper server-side subscriptions with lifecycle management
|
|
174
128
|
*/
|
|
175
129
|
export type BackendWebSocketServiceAddChannelCallbackAction = {
|
|
176
130
|
type: `BackendWebSocketService:addChannelCallback`;
|
|
@@ -179,7 +133,7 @@ export type BackendWebSocketServiceAddChannelCallbackAction = {
|
|
|
179
133
|
/**
|
|
180
134
|
* Remove a channel callback
|
|
181
135
|
*
|
|
182
|
-
* @param channelName - The channel name
|
|
136
|
+
* @param channelName - The channel name to remove callback for
|
|
183
137
|
* @returns True if callback was found and removed, false otherwise
|
|
184
138
|
*/
|
|
185
139
|
export type BackendWebSocketServiceRemoveChannelCallbackAction = {
|
|
@@ -188,58 +142,18 @@ export type BackendWebSocketServiceRemoveChannelCallbackAction = {
|
|
|
188
142
|
};
|
|
189
143
|
/**
|
|
190
144
|
* Get all registered channel callbacks (for debugging)
|
|
191
|
-
*
|
|
192
|
-
* @returns Array of all registered channel callbacks
|
|
193
145
|
*/
|
|
194
146
|
export type BackendWebSocketServiceGetChannelCallbacksAction = {
|
|
195
147
|
type: `BackendWebSocketService:getChannelCallbacks`;
|
|
196
148
|
handler: BackendWebSocketService['getChannelCallbacks'];
|
|
197
149
|
};
|
|
198
150
|
/**
|
|
199
|
-
* Create and manage a subscription with
|
|
200
|
-
*
|
|
201
|
-
* This is the recommended subscription API for high-level services. It creates a proper
|
|
202
|
-
* server-side subscription and routes notifications based on subscriptionId.
|
|
203
|
-
*
|
|
204
|
-
* **Key Features:**
|
|
205
|
-
* - Creates server-side subscription with unique subscriptionId
|
|
206
|
-
* - Callback triggered only for messages with matching subscriptionId
|
|
207
|
-
* - Automatic lifecycle management (cleanup on disconnect)
|
|
208
|
-
* - Includes unsubscribe method for proper cleanup
|
|
209
|
-
* - Request-response pattern with error handling
|
|
210
|
-
*
|
|
211
|
-
* **When to use `subscribe()`:**
|
|
212
|
-
* - Creating new subscriptions (account activity, price updates, etc.)
|
|
213
|
-
* - When you need proper cleanup/unsubscribe functionality
|
|
214
|
-
* - Most application use cases
|
|
215
|
-
*
|
|
216
|
-
* **When to use `addChannelCallback()` instead:**
|
|
217
|
-
* - System-wide notifications without server-side subscription
|
|
218
|
-
* - Observing channels managed elsewhere
|
|
219
|
-
* - Debug/logging scenarios
|
|
151
|
+
* Create and manage a subscription with direct callback routing
|
|
220
152
|
*
|
|
221
153
|
* @param options - Subscription configuration
|
|
222
154
|
* @param options.channels - Array of channel names to subscribe to
|
|
223
155
|
* @param options.callback - Callback function for handling notifications
|
|
224
|
-
* @
|
|
225
|
-
* @param options.channelType - Channel type identifier
|
|
226
|
-
* @returns Subscription object with unsubscribe method
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```typescript
|
|
230
|
-
* // AccountActivityService usage
|
|
231
|
-
* const subscription = await webSocketService.subscribe({
|
|
232
|
-
* channels: ['account-activity.v1.eip155:0:0x1234...'],
|
|
233
|
-
* callback: (notification) => {
|
|
234
|
-
* this.handleAccountActivity(notification.data);
|
|
235
|
-
* }
|
|
236
|
-
* });
|
|
237
|
-
*
|
|
238
|
-
* // Later, clean up
|
|
239
|
-
* await subscription.unsubscribe();
|
|
240
|
-
* ```
|
|
241
|
-
*
|
|
242
|
-
* @see addChannelCallback for local callbacks without server-side subscription
|
|
156
|
+
* @returns Promise that resolves with subscription object containing unsubscribe method
|
|
243
157
|
*/
|
|
244
158
|
export type BackendWebSocketServiceSubscribeAction = {
|
|
245
159
|
type: `BackendWebSocketService:subscribe`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendWebSocketService-method-action-types.d.mts","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAkC;AAEzE
|
|
1
|
+
{"version":3,"file":"BackendWebSocketService-method-action-types.d.mts","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAkC;AAEzE;;;;GAIG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,uBAAuB,CAAC,YAAY,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,uBAAuB,CAAC,aAAa,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,uBAAuB,CAAC,aAAa,CAAC,CAAC;CACjD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sDAAsD,GAAG;IACnE,IAAI,EAAE,mDAAmD,CAAC;IAC1D,OAAO,EAAE,uBAAuB,CAAC,2BAA2B,CAAC,CAAC;CAC/D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mDAAmD,GAAG;IAChE,IAAI,EAAE,gDAAgD,CAAC;IACvD,OAAO,EAAE,uBAAuB,CAAC,wBAAwB,CAAC,CAAC;CAC5D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,6DAA6D,GAAG;IAC1E,IAAI,EAAE,0DAA0D,CAAC;IACjE,OAAO,EAAE,uBAAuB,CAAC,kCAAkC,CAAC,CAAC;CACtE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,uBAAuB,CAAC,oBAAoB,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,uBAAuB,CAAC,uBAAuB,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,uBAAuB,CAAC,WAAW,CAAC,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAC5C,oCAAoC,GACpC,uCAAuC,GACvC,8CAA8C,GAC9C,wCAAwC,GACxC,wCAAwC,GACxC,8CAA8C,GAC9C,sDAAsD,GACtD,mDAAmD,GACnD,6DAA6D,GAC7D,+CAA+C,GAC/C,kDAAkD,GAClD,gDAAgD,GAChD,sCAAsC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendWebSocketService-method-action-types.mjs","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { BackendWebSocketService } from './BackendWebSocketService';\n\n/**\n * Establishes WebSocket connection with smart reconnection behavior\n *\n * Connection Requirements (all must be true):\n * 1. Feature enabled (isEnabled() = true)\n * 2. Wallet unlocked (checked by getBearerToken)\n * 3. User signed in (checked by getBearerToken)\n *\n * Platform code should call this when app opens/foregrounds.\n * Automatically called on KeyringController:unlock event.\n *\n * @returns Promise that resolves when connection is established\n */\nexport type BackendWebSocketServiceConnectAction = {\n type: `BackendWebSocketService:connect`;\n handler: BackendWebSocketService['connect'];\n};\n\n/**\n * Closes WebSocket connection\n */\nexport type BackendWebSocketServiceDisconnectAction = {\n type: `BackendWebSocketService:disconnect`;\n handler: BackendWebSocketService['disconnect'];\n};\n\n/**\n * Forces a WebSocket reconnection to clean up subscription state\n *\n * This method is useful when subscription state may be out of sync and needs to be reset.\n * It performs a controlled disconnect-then-reconnect sequence:\n * - Disconnects cleanly to trigger subscription cleanup\n * - Schedules reconnection with exponential backoff to prevent rapid loops\n * - All subscriptions will be cleaned up automatically on disconnect\n *\n * Use cases:\n * - Recovering from subscription/unsubscription issues\n * - Cleaning up orphaned subscriptions\n * - Forcing a fresh subscription state\n *\n * @returns Promise that resolves when disconnection is complete (reconnection is scheduled)\n */\nexport type BackendWebSocketServiceForceReconnectionAction = {\n type: `BackendWebSocketService:forceReconnection`;\n handler: BackendWebSocketService['forceReconnection'];\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 */\nexport type BackendWebSocketServiceSendMessageAction = {\n type: `BackendWebSocketService:sendMessage`;\n handler: BackendWebSocketService['sendMessage'];\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 */\nexport type BackendWebSocketServiceSendRequestAction = {\n type: `BackendWebSocketService:sendRequest`;\n handler: BackendWebSocketService['sendRequest'];\n};\n\n/**\n * Gets current connection information\n *\n * @returns Current connection status and details\n */\nexport type BackendWebSocketServiceGetConnectionInfoAction = {\n type: `BackendWebSocketService:getConnectionInfo`;\n handler: BackendWebSocketService['getConnectionInfo'];\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 */\nexport type BackendWebSocketServiceGetSubscriptionsByChannelAction = {\n type: `BackendWebSocketService:getSubscriptionsByChannel`;\n handler: BackendWebSocketService['getSubscriptionsByChannel'];\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 */\nexport type BackendWebSocketServiceChannelHasSubscriptionAction = {\n type: `BackendWebSocketService:channelHasSubscription`;\n handler: BackendWebSocketService['channelHasSubscription'];\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 */\nexport type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {\n type: `BackendWebSocketService:findSubscriptionsByChannelPrefix`;\n handler: BackendWebSocketService['findSubscriptionsByChannelPrefix'];\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 */\nexport type BackendWebSocketServiceAddChannelCallbackAction = {\n type: `BackendWebSocketService:addChannelCallback`;\n handler: BackendWebSocketService['addChannelCallback'];\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 */\nexport type BackendWebSocketServiceRemoveChannelCallbackAction = {\n type: `BackendWebSocketService:removeChannelCallback`;\n handler: BackendWebSocketService['removeChannelCallback'];\n};\n\n/**\n * Get all registered channel callbacks (for debugging)\n *\n * @returns Array of all registered channel callbacks\n */\nexport type BackendWebSocketServiceGetChannelCallbacksAction = {\n type: `BackendWebSocketService:getChannelCallbacks`;\n handler: BackendWebSocketService['getChannelCallbacks'];\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 * @param options.channelType - Channel type identifier\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 */\nexport type BackendWebSocketServiceSubscribeAction = {\n type: `BackendWebSocketService:subscribe`;\n handler: BackendWebSocketService['subscribe'];\n};\n\n/**\n * Union of all BackendWebSocketService action types.\n */\nexport type BackendWebSocketServiceMethodActions =\n | BackendWebSocketServiceConnectAction\n | BackendWebSocketServiceDisconnectAction\n | BackendWebSocketServiceForceReconnectionAction\n | BackendWebSocketServiceSendMessageAction\n | BackendWebSocketServiceSendRequestAction\n | BackendWebSocketServiceGetConnectionInfoAction\n | BackendWebSocketServiceGetSubscriptionsByChannelAction\n | BackendWebSocketServiceChannelHasSubscriptionAction\n | BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction\n | BackendWebSocketServiceAddChannelCallbackAction\n | BackendWebSocketServiceRemoveChannelCallbackAction\n | BackendWebSocketServiceGetChannelCallbacksAction\n | BackendWebSocketServiceSubscribeAction;\n"]}
|
|
1
|
+
{"version":3,"file":"BackendWebSocketService-method-action-types.mjs","sourceRoot":"","sources":["../src/BackendWebSocketService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { BackendWebSocketService } from './BackendWebSocketService';\n\n/**\n * Establishes WebSocket connection\n *\n * @returns Promise that resolves when connection is established\n */\nexport type BackendWebSocketServiceConnectAction = {\n type: `BackendWebSocketService:connect`;\n handler: BackendWebSocketService['connect'];\n};\n\n/**\n * Closes WebSocket connection\n *\n * @returns Promise that resolves when disconnection is complete\n */\nexport type BackendWebSocketServiceDisconnectAction = {\n type: `BackendWebSocketService:disconnect`;\n handler: BackendWebSocketService['disconnect'];\n};\n\n/**\n * Forces a WebSocket reconnection to clean up subscription state\n *\n * This method is useful when subscription state may be out of sync and needs to be reset.\n * It performs a controlled disconnect-then-reconnect sequence:\n * - Disconnects cleanly to trigger subscription cleanup\n * - Schedules reconnection with exponential backoff to prevent rapid loops\n * - All subscriptions will be cleaned up automatically on disconnect\n *\n * Use cases:\n * - Recovering from subscription/unsubscription issues\n * - Cleaning up orphaned subscriptions\n * - Forcing a fresh subscription state\n *\n * @returns Promise that resolves when disconnection is complete (reconnection is scheduled)\n */\nexport type BackendWebSocketServiceForceReconnectionAction = {\n type: `BackendWebSocketService:forceReconnection`;\n handler: BackendWebSocketService['forceReconnection'];\n};\n\n/**\n * Sends a message through the WebSocket\n *\n * @param message - The message to send\n * @returns Promise that resolves when message is sent\n */\nexport type BackendWebSocketServiceSendMessageAction = {\n type: `BackendWebSocketService:sendMessage`;\n handler: BackendWebSocketService['sendMessage'];\n};\n\n/**\n * Sends a request and waits for a correlated response\n *\n * @param message - The request message\n * @returns Promise that resolves with the response data\n */\nexport type BackendWebSocketServiceSendRequestAction = {\n type: `BackendWebSocketService:sendRequest`;\n handler: BackendWebSocketService['sendRequest'];\n};\n\n/**\n * Gets current connection information\n *\n * @returns Current connection status and details\n */\nexport type BackendWebSocketServiceGetConnectionInfoAction = {\n type: `BackendWebSocketService:getConnectionInfo`;\n handler: BackendWebSocketService['getConnectionInfo'];\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 */\nexport type BackendWebSocketServiceGetSubscriptionsByChannelAction = {\n type: `BackendWebSocketService:getSubscriptionsByChannel`;\n handler: BackendWebSocketService['getSubscriptionsByChannel'];\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 */\nexport type BackendWebSocketServiceChannelHasSubscriptionAction = {\n type: `BackendWebSocketService:channelHasSubscription`;\n handler: BackendWebSocketService['channelHasSubscription'];\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 */\nexport type BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction = {\n type: `BackendWebSocketService:findSubscriptionsByChannelPrefix`;\n handler: BackendWebSocketService['findSubscriptionsByChannelPrefix'];\n};\n\n/**\n * Register a callback for specific channels\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 specific account activity channel\n * webSocketService.addChannelCallback({\n * channelName: 'account-activity.v1.eip155:0:0x1234...',\n * callback: (notification) => {\n * console.log('Account activity:', notification.data);\n * }\n * });\n *\n * // Listen to system notifications channel\n * webSocketService.addChannelCallback({\n * channelName: 'system-notifications.v1',\n * callback: (notification) => {\n * console.log('System notification:', notification.data);\n * }\n * });\n * ```\n */\nexport type BackendWebSocketServiceAddChannelCallbackAction = {\n type: `BackendWebSocketService:addChannelCallback`;\n handler: BackendWebSocketService['addChannelCallback'];\n};\n\n/**\n * Remove a channel callback\n *\n * @param channelName - The channel name to remove callback for\n * @returns True if callback was found and removed, false otherwise\n */\nexport type BackendWebSocketServiceRemoveChannelCallbackAction = {\n type: `BackendWebSocketService:removeChannelCallback`;\n handler: BackendWebSocketService['removeChannelCallback'];\n};\n\n/**\n * Get all registered channel callbacks (for debugging)\n */\nexport type BackendWebSocketServiceGetChannelCallbacksAction = {\n type: `BackendWebSocketService:getChannelCallbacks`;\n handler: BackendWebSocketService['getChannelCallbacks'];\n};\n\n/**\n * Create and manage a subscription with direct callback routing\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 * @returns Promise that resolves with subscription object containing unsubscribe method\n */\nexport type BackendWebSocketServiceSubscribeAction = {\n type: `BackendWebSocketService:subscribe`;\n handler: BackendWebSocketService['subscribe'];\n};\n\n/**\n * Union of all BackendWebSocketService action types.\n */\nexport type BackendWebSocketServiceMethodActions =\n | BackendWebSocketServiceConnectAction\n | BackendWebSocketServiceDisconnectAction\n | BackendWebSocketServiceForceReconnectionAction\n | BackendWebSocketServiceSendMessageAction\n | BackendWebSocketServiceSendRequestAction\n | BackendWebSocketServiceGetConnectionInfoAction\n | BackendWebSocketServiceGetSubscriptionsByChannelAction\n | BackendWebSocketServiceChannelHasSubscriptionAction\n | BackendWebSocketServiceFindSubscriptionsByChannelPrefixAction\n | BackendWebSocketServiceAddChannelCallbackAction\n | BackendWebSocketServiceRemoveChannelCallbackAction\n | BackendWebSocketServiceGetChannelCallbacksAction\n | BackendWebSocketServiceSubscribeAction;\n"]}
|