@qontinui/ui-bridge-native 0.3.2 → 0.5.1

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 (112) hide show
  1. package/dist/control/{index.d.mts → action-executor.d.ts} +6 -10
  2. package/dist/control/action-executor.d.ts.map +1 -0
  3. package/dist/control/index.d.ts +5 -95
  4. package/dist/control/index.d.ts.map +1 -0
  5. package/dist/{types-CjEKTDYT.d.ts → control/types.d.ts} +17 -20
  6. package/dist/control/types.d.ts.map +1 -0
  7. package/dist/core/element-identifier.d.ts +41 -0
  8. package/dist/core/element-identifier.d.ts.map +1 -0
  9. package/dist/core/index.d.ts +6 -43
  10. package/dist/core/index.d.ts.map +1 -0
  11. package/dist/{registry-pAUpQq2O.d.ts → core/registry.d.ts} +10 -13
  12. package/dist/core/registry.d.ts.map +1 -0
  13. package/dist/{types-CGVut7mc.d.mts → core/types.d.ts} +41 -41
  14. package/dist/core/types.d.ts.map +1 -0
  15. package/dist/debug/index.d.ts +4 -44
  16. package/dist/debug/index.d.ts.map +1 -0
  17. package/dist/debug/index.js +1 -1
  18. package/dist/debug/index.js.map +1 -1
  19. package/dist/debug/index.mjs +2 -2
  20. package/dist/debug/index.mjs.map +1 -1
  21. package/dist/debug/{index.d.mts → inspector.d.ts} +3 -6
  22. package/dist/debug/inspector.d.ts.map +1 -0
  23. package/dist/design/{index.d.mts → design-inspector-native.d.ts} +7 -11
  24. package/dist/design/design-inspector-native.d.ts.map +1 -0
  25. package/dist/{design-types-BHr6Q1FX.d.mts → design/design-types.d.ts} +10 -11
  26. package/dist/design/design-types.d.ts.map +1 -0
  27. package/dist/design/index.d.ts +5 -60
  28. package/dist/design/index.d.ts.map +1 -0
  29. package/dist/index.d.ts +37 -86
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +60 -4
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +61 -5
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/modal/index.d.ts +2 -0
  36. package/dist/modal/index.d.ts.map +1 -0
  37. package/dist/modal/modal-detector.d.ts +29 -0
  38. package/dist/modal/modal-detector.d.ts.map +1 -0
  39. package/dist/react/StateAnnotation.d.ts +30 -0
  40. package/dist/react/StateAnnotation.d.ts.map +1 -0
  41. package/dist/react/UIBridgeNativeProvider.d.ts +163 -0
  42. package/dist/react/UIBridgeNativeProvider.d.ts.map +1 -0
  43. package/dist/react/index.d.ts +14 -69
  44. package/dist/react/index.d.ts.map +1 -0
  45. package/dist/react/index.js +60 -4
  46. package/dist/react/index.js.map +1 -1
  47. package/dist/react/index.mjs +61 -5
  48. package/dist/react/index.mjs.map +1 -1
  49. package/dist/react/{index.d.mts → useAutoRegister.d.ts} +7 -15
  50. package/dist/react/useAutoRegister.d.ts.map +1 -0
  51. package/dist/react/useUIBridge.d.ts +103 -0
  52. package/dist/react/useUIBridge.d.ts.map +1 -0
  53. package/dist/react/useUIBridgeModal.d.ts +14 -0
  54. package/dist/react/useUIBridgeModal.d.ts.map +1 -0
  55. package/dist/react/useUIBridgeToast.d.ts +25 -0
  56. package/dist/react/useUIBridgeToast.d.ts.map +1 -0
  57. package/dist/react/useUIComponent.d.ts +112 -0
  58. package/dist/react/useUIComponent.d.ts.map +1 -0
  59. package/dist/react/useUIElement.d.ts +162 -0
  60. package/dist/react/useUIElement.d.ts.map +1 -0
  61. package/dist/server/design-handlers.d.ts +47 -0
  62. package/dist/server/design-handlers.d.ts.map +1 -0
  63. package/dist/server/handlers.d.ts +25 -0
  64. package/dist/server/handlers.d.ts.map +1 -0
  65. package/dist/server/http-server.d.ts +269 -0
  66. package/dist/server/http-server.d.ts.map +1 -0
  67. package/dist/server/index.d.ts +14 -176
  68. package/dist/server/index.d.ts.map +1 -0
  69. package/dist/server/index.js +51 -1
  70. package/dist/server/index.js.map +1 -1
  71. package/dist/server/index.mjs +51 -1
  72. package/dist/server/index.mjs.map +1 -1
  73. package/dist/server/observability.d.ts +55 -0
  74. package/dist/server/observability.d.ts.map +1 -0
  75. package/dist/server/types.d.ts +377 -0
  76. package/dist/server/types.d.ts.map +1 -0
  77. package/dist/server/ws-connection.d.ts +48 -0
  78. package/dist/server/ws-connection.d.ts.map +1 -0
  79. package/dist/server/ws-event-bridge.d.ts +113 -0
  80. package/dist/server/ws-event-bridge.d.ts.map +1 -0
  81. package/dist/server/ws-protocol.d.ts +48 -0
  82. package/dist/server/ws-protocol.d.ts.map +1 -0
  83. package/dist/server/ws-types.d.ts +65 -0
  84. package/dist/server/ws-types.d.ts.map +1 -0
  85. package/dist/toast/index.d.ts +2 -0
  86. package/dist/toast/index.d.ts.map +1 -0
  87. package/dist/toast/toast-capture.d.ts +27 -0
  88. package/dist/toast/toast-capture.d.ts.map +1 -0
  89. package/dist/transport/CloudRelayClient.d.ts +51 -0
  90. package/dist/transport/CloudRelayClient.d.ts.map +1 -0
  91. package/dist/transport/DeviceAnnouncer.d.ts +75 -0
  92. package/dist/transport/DeviceAnnouncer.d.ts.map +1 -0
  93. package/dist/transport/index.d.ts +3 -0
  94. package/dist/transport/index.d.ts.map +1 -0
  95. package/dist/transport/logger.d.ts +23 -0
  96. package/dist/transport/logger.d.ts.map +1 -0
  97. package/dist/undo/index.d.ts +3 -0
  98. package/dist/undo/index.d.ts.map +1 -0
  99. package/dist/undo/undo-tracker.d.ts +59 -0
  100. package/dist/undo/undo-tracker.d.ts.map +1 -0
  101. package/package.json +3 -3
  102. package/dist/StateAnnotation--zm0Jfqj.d.ts +0 -755
  103. package/dist/StateAnnotation-BgFoVWFy.d.mts +0 -755
  104. package/dist/core/index.d.mts +0 -46
  105. package/dist/design-types-BHr6Q1FX.d.ts +0 -205
  106. package/dist/http-server--550eD1F.d.mts +0 -805
  107. package/dist/http-server-C9NaNBEP.d.ts +0 -805
  108. package/dist/index.d.mts +0 -89
  109. package/dist/registry-B5JadBN9.d.mts +0 -300
  110. package/dist/server/index.d.mts +0 -178
  111. package/dist/types-B0XA4vOF.d.mts +0 -197
  112. package/dist/types-CGVut7mc.d.ts +0 -567
@@ -0,0 +1,269 @@
1
+ /**
2
+ * UI Bridge Native HTTP Server
3
+ *
4
+ * Abstract HTTP server implementation for React Native.
5
+ * This provides a framework-agnostic server interface that can be
6
+ * implemented using various React Native HTTP server libraries.
7
+ *
8
+ * Supported libraries:
9
+ * - react-native-http-bridge (recommended)
10
+ * - @aspect/react-native-http-server
11
+ * - Custom implementations
12
+ */
13
+ import type { NativeUIBridgeRegistry } from '../core/registry';
14
+ import type { NativeActionExecutor } from '../control/types';
15
+ import type { NativeServerConfig, NavigationProvider, RouteProvider, ScreenshotProvider, KeepAwakeProvider } from './types';
16
+ import type { WebSocketEventBridge } from './ws-event-bridge';
17
+ import type { JsonRpcRequest, JsonRpcResponse } from './ws-types';
18
+ /**
19
+ * HTTP Request interface (library-agnostic)
20
+ */
21
+ export interface HTTPRequest {
22
+ method: string;
23
+ path: string;
24
+ headers: Record<string, string>;
25
+ query: Record<string, string>;
26
+ body?: unknown;
27
+ }
28
+ /**
29
+ * HTTP Response interface (library-agnostic)
30
+ */
31
+ export interface HTTPResponse {
32
+ status: number;
33
+ headers: Record<string, string>;
34
+ body: string;
35
+ }
36
+ /**
37
+ * Request handler type
38
+ */
39
+ export type RequestHandler = (request: HTTPRequest) => Promise<HTTPResponse>;
40
+ /**
41
+ * Server adapter interface
42
+ *
43
+ * Implement this interface to integrate with your chosen HTTP server library.
44
+ */
45
+ export interface ServerAdapter {
46
+ /** Start the server */
47
+ start(port: number, handler: RequestHandler): Promise<void>;
48
+ /** Stop the server */
49
+ stop(): Promise<void>;
50
+ /** Check if server is running */
51
+ isRunning(): boolean;
52
+ }
53
+ /**
54
+ * WebSocket-aware server adapter interface.
55
+ *
56
+ * Extends ServerAdapter with callbacks for WebSocket connections.
57
+ * The adapter manages the raw TCP/WS layer; these callbacks let the
58
+ * UI Bridge server handle message routing and event broadcasting.
59
+ */
60
+ export interface WebSocketServerAdapter extends ServerAdapter {
61
+ /** Called when a JSON text frame is received from a WS client. Returns response string or null. */
62
+ onWebSocketMessage?: (connId: string, message: string) => Promise<string | null>;
63
+ /** Called when a new WS connection is established after the HTTP 101 upgrade. */
64
+ onWebSocketConnect?: (connId: string) => void;
65
+ /** Called when a WS connection is closed or drops. */
66
+ onWebSocketDisconnect?: (connId: string) => void;
67
+ /** Send a message to a specific WS connection by ID. */
68
+ sendToConnection?: (connId: string, message: string) => void;
69
+ /** Send a message to all connected WS clients. */
70
+ broadcast?: (message: string) => void;
71
+ }
72
+ /**
73
+ * Native UI Bridge HTTP Server
74
+ */
75
+ export declare class NativeUIBridgeServer {
76
+ private registry;
77
+ private executor;
78
+ private config;
79
+ private handlers;
80
+ private adapter?;
81
+ private running;
82
+ private keepAwakeProvider?;
83
+ /**
84
+ * Per-connection cleanup thunks for in-flight waiters (waitForElement,
85
+ * waitForCondition, ...). Aborted when a client disconnects so the
86
+ * underlying timers/listeners don't leak.
87
+ */
88
+ private pendingWaiters;
89
+ /**
90
+ * Observability ring buffers backing `/control/console-errors` and
91
+ * `/sdk/network-requests`. Allocated unconditionally so the handler can
92
+ * always read them, but the global patches (`install()`) only fire on
93
+ * `start()` when `testHooks` is set — production builds don't monkey-patch.
94
+ */
95
+ private consoleErrorBuffer;
96
+ private networkRequestBuffer;
97
+ constructor(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig);
98
+ /**
99
+ * Set the server adapter
100
+ */
101
+ setAdapter(adapter: ServerAdapter): void;
102
+ /**
103
+ * Set a navigation provider for programmatic route navigation.
104
+ * This enables `control/page/navigate` and `control/page/back` on native.
105
+ */
106
+ setNavigationProvider(provider: NavigationProvider): void;
107
+ /**
108
+ * Set a route provider for reporting the current navigation route.
109
+ * When set, `control/snapshot` responses include `currentRoute` and `segments`.
110
+ *
111
+ * Also forwards the provider into the registry so the *default*
112
+ * `getSnapshot` handler (and any other call site of
113
+ * `registry.createSnapshot`) reads the route too — without this the
114
+ * cloud-relay/bare-server path returned `currentRoute: null` even when
115
+ * a `RouteTracker` was wired, because that path never installed the
116
+ * server-level handler override below.
117
+ */
118
+ setRouteProvider(provider: RouteProvider): void;
119
+ /**
120
+ * Set a screenshot provider for native screen capture.
121
+ * This enables `control/screenshot` on native.
122
+ */
123
+ setScreenshotProvider(provider: ScreenshotProvider): void;
124
+ /**
125
+ * Set a keep-awake provider for native screen-wake control.
126
+ * This enables `control/keep-awake` and arms the auto-arm hook in
127
+ * handleRequest (every request keeps the screen alive for 60s).
128
+ */
129
+ setKeepAwakeProvider(provider: KeepAwakeProvider): void;
130
+ /**
131
+ * Start the HTTP server
132
+ */
133
+ start(): Promise<void>;
134
+ /**
135
+ * Stop the HTTP server
136
+ */
137
+ stop(): Promise<void>;
138
+ /**
139
+ * Check if server is running
140
+ */
141
+ isRunning(): boolean;
142
+ private eventBridge?;
143
+ /**
144
+ * Set the event bridge for WebSocket event broadcasting and subscriptions.
145
+ */
146
+ setEventBridge(bridge: WebSocketEventBridge): void;
147
+ /**
148
+ * Handle a JSON-RPC message from a WebSocket client.
149
+ * Parses the message, routes to the appropriate handler, and returns
150
+ * a JSON string response (or null for events that need no response).
151
+ */
152
+ handleWebSocketMessage(connId: string, rawMessage: string): Promise<string | null>;
153
+ /**
154
+ * Execute a batch of JSON-RPC requests concurrently.
155
+ */
156
+ handleBatchRequest(batch: JsonRpcRequest[]): Promise<JsonRpcResponse[]>;
157
+ /**
158
+ * Register an in-flight waiter's cleanup thunk under the given connection.
159
+ * Returns an `unregister` thunk that the natural-resolution path should
160
+ * call so the cleanup isn't re-invoked on disconnect.
161
+ */
162
+ private registerWaiter;
163
+ /**
164
+ * Abort all pending waiters associated with a connection. Called by the
165
+ * provider's WS disconnect handler so timers/listeners don't leak after
166
+ * the client goes away.
167
+ */
168
+ abortWaitersForConnection(connId: string): void;
169
+ /**
170
+ * Wait for an element to be registered, or resolve immediately if it already exists.
171
+ * Returns a JsonRpcResponse JSON string.
172
+ */
173
+ private handleWaitForElement;
174
+ /**
175
+ * Wait for an arbitrary element-state predicate to become true.
176
+ *
177
+ * Supported `condition` shapes:
178
+ * {field: "mounted"|"visible"|"enabled"|"focused", equals: boolean}
179
+ * {field: "layout", exists: true}
180
+ * {field: string, equals: unknown} // generic: state[field] === equals
181
+ *
182
+ * Resolves immediately with `waited:false` if the predicate already
183
+ * holds. Otherwise subscribes to `element:registered` and
184
+ * `element:stateChanged` until the predicate matches or timeout fires.
185
+ */
186
+ private handleWaitForCondition;
187
+ /**
188
+ * Execute a sequence of JSON-RPC steps in order, stopping on first failure.
189
+ * Returns a JsonRpcResponse JSON string with per-step results.
190
+ */
191
+ private handleSequence;
192
+ /**
193
+ * Route a JSON-RPC method string to the appropriate handler using path-style matching.
194
+ *
195
+ * Method strings mirror HTTP routes but without the /ui-bridge/ prefix.
196
+ * Path params are extracted from :name placeholders in the route pattern.
197
+ *
198
+ * Examples:
199
+ * "health" → handlers.health
200
+ * "control/snapshot" → handlers.getSnapshot
201
+ * "control/element/tab-runs/action" → handlers.executeAction ({id:'tab-runs'})
202
+ * "control/component/my-comp/action/submit" → handlers.executeComponentAction
203
+ */
204
+ private routeMethodToHandler;
205
+ /**
206
+ * Handle incoming HTTP request
207
+ *
208
+ * Exposed as public so that CloudRelayClient can call it directly (without
209
+ * loopback TCP overhead) when processing tunneled requests.
210
+ */
211
+ handleRequest(request: HTTPRequest): Promise<HTTPResponse>;
212
+ /**
213
+ * Route an HTTP request to the appropriate handler using WS_ROUTES.
214
+ *
215
+ * Strips the `/ui-bridge/` prefix from the path, then iterates the shared
216
+ * WS_ROUTES table. Each route's `pattern` is matched against the stripped
217
+ * path via the module-level `parsePath` helper; path params are merged
218
+ * with the request body into a HandlerContext.
219
+ *
220
+ * `httpMethods` disambiguates routes that share a pattern but differ
221
+ * by verb (e.g. GET vs DELETE on `design/style-guide`). A route without
222
+ * `httpMethods` is WS-only and will not be matched on HTTP.
223
+ */
224
+ private routeRequest;
225
+ }
226
+ /**
227
+ * Create a UI Bridge Native server
228
+ */
229
+ export declare function createNativeServer(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig): NativeUIBridgeServer;
230
+ /**
231
+ * Example adapter using react-native-http-bridge
232
+ *
233
+ * To use this adapter:
234
+ * 1. Install: npm install react-native-http-bridge
235
+ * 2. Link native modules
236
+ * 3. Create adapter and pass to server
237
+ *
238
+ * ```tsx
239
+ * import httpBridge from 'react-native-http-bridge';
240
+ *
241
+ * const adapter: ServerAdapter = {
242
+ * start: async (port, handler) => {
243
+ * httpBridge.start(port, 'ui-bridge', async (request) => {
244
+ * const response = await handler({
245
+ * method: request.type,
246
+ * path: request.url,
247
+ * headers: request.headers || {},
248
+ * query: parseQuery(request.url),
249
+ * body: request.postData ? JSON.parse(request.postData) : undefined,
250
+ * });
251
+ * httpBridge.respond(
252
+ * request.requestId,
253
+ * response.status,
254
+ * response.headers['Content-Type'],
255
+ * response.body
256
+ * );
257
+ * });
258
+ * },
259
+ * stop: async () => {
260
+ * httpBridge.stop();
261
+ * },
262
+ * isRunning: () => true,
263
+ * };
264
+ *
265
+ * server.setAdapter(adapter);
266
+ * await server.start();
267
+ * ```
268
+ */
269
+ //# sourceMappingURL=http-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../../src/server/http-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAA0B,MAAM,kBAAkB,CAAC;AACrF,OAAO,KAAK,EACV,kBAAkB,EAElB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAIjB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAiTlE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,M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AAC,MAAM,GAAG,IAAI,CAAC;IA4IxF;;OAEG;IACG,kBAAkB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAwB7E;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAetB;;;;OAIG;IACH,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAa/C;;;OAGG;YACW,oBAAoB;IAwHlC;;;;;;;;;;;OAWG;YACW,sBAAsB;IAmJpC;;;OAGG;YACW,cAAc;IA6E5B;;;;;;;;;;;OAWG;YACW,oBAAoB;IAgClC;;;;;OAKG;IACG,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAuDhE;;;;;;;;;;;OAWG;YACW,YAAY;CAuE3B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,sBAAsB,EAChC,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,CAAC,EAAE,kBAAkB,GAC1B,oBAAoB,CAEtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG"}
@@ -1,178 +1,16 @@
1
- import { C as ConsoleErrorEntry, u as NetworkRequestEntry, k as NativeServerHandlers, e as HandlerContext, A as APIResponse } from '../http-server-C9NaNBEP.js';
2
- export { v as ConsoleErrorsResponse, D as DismissModalResponse, F as FillFormFieldInput, a as FillFormFieldResult, b as FillFormRequest, c as FillFormResponse, H as HTTPRequest, d as HTTPResponse, f as HandlerFunction, J as JsonRpcBatchRequest, g as JsonRpcBatchResponse, w as JsonRpcClientMessage, h as JsonRpcEvent, i as JsonRpcRequest, j as JsonRpcResponse, x as JsonRpcServerMessage, y as JsonRpcSubscribe, z as JsonRpcUnsubscribe, N as NativeServerConfig, l as NativeUIBridgeServer, m as NavigationProvider, B as NetworkRequestsResponse, P as PushModalRequest, E as PushModalResponse, R as RequestHandler, n as RouteDefinition, o as RouteProvider, S as ScreenshotProvider, p as ServerAdapter, T as TapAtRequest, G as TapAtResponse, U as UI_BRIDGE_NATIVE_ROUTES, W as WebSocketConnection, q as WebSocketEventBridge, r as WebSocketMessageHandler, s as WebSocketServerAdapter, t as createNativeServer, I as isBatchRequest, K as isSubscribe, L as isUnsubscribe } from '../http-server-C9NaNBEP.js';
3
- import { a as NativeUIBridgeRegistry } from '../registry-pAUpQq2O.js';
4
- import { N as NativeActionExecutor } from '../types-CjEKTDYT.js';
5
- import { E as ElementDesignData, S as StateStyles, R as ResponsiveSnapshot } from '../design-types-BHr6Q1FX.js';
6
- import '../types-CGVut7mc.js';
7
-
8
1
  /**
9
- * UI Bridge Native — observability ring buffers.
2
+ * UI Bridge Native - Server
10
3
  *
11
- * Two small last-N buffers backing the `/control/console-errors` and
12
- * `/sdk/network-requests` endpoints. Each buffer monkey-patches the relevant
13
- * global on `install()` and restores the original on `uninstall()`, so they
14
- * can be installed/torn-down with the server's lifecycle.
15
- *
16
- * Both buffers are gated behind `features.testHooks` by the caller (see
17
- * NativeUIBridgeServer). Production builds default to `testHooks: false`,
18
- * so these patches never run on real users' devices.
19
- *
20
- * Implementation notes:
21
- * - Buffers default to capacity 100 entries and drop oldest on overflow.
22
- * - Patches are idempotent: `install()` is a no-op when already installed;
23
- * `uninstall()` is a no-op when not installed.
24
- * - Patches only restore the *original* function captured at install time;
25
- * if other code wraps `console.error` / `fetch` between install and
26
- * uninstall, those wrappers will be lost. Acceptable for test hooks.
27
- */
28
-
29
- declare class ConsoleErrorBuffer {
30
- private buffer;
31
- private installed;
32
- private originalError?;
33
- private originalWarn?;
34
- constructor(capacity?: number);
35
- install(): void;
36
- uninstall(): void;
37
- entries(opts?: {
38
- since?: number;
39
- limit?: number;
40
- }): ConsoleErrorEntry[];
41
- size(): number;
42
- clear(): void;
43
- isInstalled(): boolean;
44
- }
45
- declare class NetworkRequestBuffer {
46
- private buffer;
47
- private installed;
48
- private originalFetch?;
49
- private originalXhrOpen?;
50
- private originalXhrSend?;
51
- constructor(capacity?: number);
52
- install(): void;
53
- uninstall(): void;
54
- entries(opts?: {
55
- since?: number;
56
- limit?: number;
57
- }): NetworkRequestEntry[];
58
- size(): number;
59
- clear(): void;
60
- isInstalled(): boolean;
61
- }
62
-
63
- /**
64
- * UI Bridge Native Server Handlers
65
- *
66
- * Request handlers for the HTTP API endpoints.
67
- */
68
-
69
- /**
70
- * Create server handlers
71
- */
72
- declare function createServerHandlers(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: {
73
- appInfo?: {
74
- appId: string;
75
- appName: string;
76
- appType: string;
77
- framework?: string;
78
- };
79
- /** Optional console-error ring buffer powering `GET /control/console-errors`. */
80
- consoleErrorBuffer?: ConsoleErrorBuffer;
81
- /** Optional network-request ring buffer powering `GET /sdk/network-requests`. */
82
- networkRequestBuffer?: NetworkRequestBuffer;
83
- }): NativeServerHandlers;
84
-
85
- /**
86
- * Pure-JS RFC 6455 WebSocket protocol implementation.
87
- *
88
- * Provides frame encoding/decoding and handshake utilities for running
89
- * a WebSocket server on react-native-tcp-socket without native crypto deps.
90
- */
91
- declare const OPCODE_CONTINUATION = 0;
92
- declare const OPCODE_TEXT = 1;
93
- declare const OPCODE_BINARY = 2;
94
- declare const OPCODE_CLOSE = 8;
95
- declare const OPCODE_PING = 9;
96
- declare const OPCODE_PONG = 10;
97
- interface DecodedFrame {
98
- opcode: number;
99
- fin: boolean;
100
- payload: Uint8Array;
101
- masked: boolean;
102
- }
103
- interface DecodeResult {
104
- frames: DecodedFrame[];
105
- remainder: Uint8Array<any>;
106
- }
107
- /**
108
- * Compute the Sec-WebSocket-Accept value from the client's Sec-WebSocket-Key.
109
- */
110
- declare function computeAcceptKey(clientKey: string): string;
111
- /**
112
- * Build the HTTP 101 Switching Protocols response for a WebSocket upgrade.
113
- */
114
- declare function buildUpgradeResponse(clientKey: string): string;
115
- /** Encode a text message as a WebSocket frame. */
116
- declare function encodeTextFrame(text: string): Uint8Array;
117
- /** Encode a PING frame with optional payload. */
118
- declare function encodePingFrame(payload?: Uint8Array): Uint8Array;
119
- /** Encode a PONG frame with the payload from the PING. */
120
- declare function encodePongFrame(payload: Uint8Array): Uint8Array;
121
- /** Encode a CLOSE frame with optional status code and reason. */
122
- declare function encodeCloseFrame(code?: number, reason?: string): Uint8Array;
123
- /**
124
- * Decode one or more WebSocket frames from a byte buffer.
125
- * Returns decoded frames and any unconsumed bytes (for partial frames).
126
- */
127
- declare function decodeFrames(buffer: Uint8Array): DecodeResult;
128
- /**
129
- * Decode a text payload from a Uint8Array.
130
- */
131
- declare function decodeTextPayload(payload: Uint8Array): string;
132
-
133
- /**
134
- * UI Bridge Native Design Review Handlers
135
- *
136
- * HTTP handlers for the 8 design review endpoints.
137
- * Maps registered element styles to the web SDK's design data format.
138
- */
139
-
140
- /**
141
- * Design handler interface (subset of NativeServerHandlers)
142
- */
143
- interface NativeDesignHandlers {
144
- getElementStyles: (ctx: HandlerContext) => Promise<APIResponse<ElementDesignData>>;
145
- getElementStateStyles: (ctx: HandlerContext) => Promise<APIResponse<{
146
- elementId: string;
147
- stateStyles: StateStyles[];
148
- }>>;
149
- getDesignSnapshot: (ctx: HandlerContext) => Promise<APIResponse<{
150
- elements: ElementDesignData[];
151
- timestamp: number;
152
- }>>;
153
- getResponsiveSnapshots: (ctx: HandlerContext) => Promise<APIResponse<ResponsiveSnapshot[]>>;
154
- runDesignAudit: (ctx: HandlerContext) => Promise<APIResponse<unknown>>;
155
- loadStyleGuide: (ctx: HandlerContext) => Promise<APIResponse<{
156
- loaded: boolean;
157
- }>>;
158
- getStyleGuide: (ctx: HandlerContext) => Promise<APIResponse<unknown>>;
159
- clearStyleGuide: (ctx: HandlerContext) => Promise<APIResponse<{
160
- cleared: boolean;
161
- }>>;
162
- evaluateQuality: (ctx: HandlerContext) => Promise<APIResponse<unknown>>;
163
- getQualityContexts: (ctx: HandlerContext) => Promise<APIResponse<Array<{
164
- name: string;
165
- description: string;
166
- }>>>;
167
- saveBaseline: (ctx: HandlerContext) => Promise<APIResponse<{
168
- saved: boolean;
169
- elementCount: number;
170
- }>>;
171
- diffBaseline: (ctx: HandlerContext) => Promise<APIResponse<unknown>>;
172
- }
173
- /**
174
- * Create design review handlers.
175
- */
176
- declare function createDesignHandlers(registry: NativeUIBridgeRegistry): NativeDesignHandlers;
177
-
178
- export { APIResponse, ConsoleErrorBuffer, ConsoleErrorEntry, type DecodeResult, type DecodedFrame, HandlerContext, type NativeDesignHandlers, NativeServerHandlers, NetworkRequestBuffer, NetworkRequestEntry, OPCODE_BINARY, OPCODE_CLOSE, OPCODE_CONTINUATION, OPCODE_PING, OPCODE_PONG, OPCODE_TEXT, buildUpgradeResponse, computeAcceptKey, createDesignHandlers, createServerHandlers, decodeFrames, decodeTextPayload, encodeCloseFrame, encodePingFrame, encodePongFrame, encodeTextFrame };
4
+ * HTTP and WebSocket server for external control of native apps.
5
+ */
6
+ export * from './types';
7
+ export * from './handlers';
8
+ export * from './design-handlers';
9
+ export * from './http-server';
10
+ export * from './ws-protocol';
11
+ export * from './ws-types';
12
+ export { WebSocketConnection } from './ws-connection';
13
+ export type { WebSocketMessageHandler } from './ws-connection';
14
+ export { WebSocketEventBridge } from './ws-event-bridge';
15
+ export { ConsoleErrorBuffer, NetworkRequestBuffer } from './observability';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1117,6 +1117,14 @@ function createServerHandlers(registry, executor, config) {
1117
1117
  "NOT_SUPPORTED"
1118
1118
  );
1119
1119
  },
1120
+ // Keep-awake (stub — apps should override via setKeepAwakeProvider, which
1121
+ // the provider wires when a keepAwakeProvider prop is supplied)
1122
+ keepAwake: async () => {
1123
+ return error2(
1124
+ "keep-awake not configured. Provide a keepAwakeProvider to UIBridgeNativeProvider.",
1125
+ "NOT_SUPPORTED"
1126
+ );
1127
+ },
1120
1128
  // Meta / Introspection (stub — server constructor overrides with real route table)
1121
1129
  getMethods: async () => {
1122
1130
  return error2("Methods introspection not configured", "NOT_SUPPORTED");
@@ -1790,6 +1798,12 @@ var WS_ROUTES = [
1790
1798
  httpMethods: ["POST"],
1791
1799
  requiresTestHooks: true
1792
1800
  },
1801
+ {
1802
+ pattern: "control/keep-awake",
1803
+ handler: "keepAwake",
1804
+ httpMethods: ["POST"],
1805
+ requiresTestHooks: true
1806
+ },
1793
1807
  // Observability — last-N console errors + network requests. testHooks-gated
1794
1808
  // because patching `console.error` / `fetch` is invasive in production.
1795
1809
  {
@@ -1842,7 +1856,8 @@ var HANDLER_DESCRIPTIONS = {
1842
1856
  getConsoleErrors: "TEST HOOK \u2014 last-N console.error/console.warn entries; ?since=<ms>&limit=<n>",
1843
1857
  getNetworkRequests: "TEST HOOK \u2014 last-N fetch/XHR entries with status + duration; ?since=<ms>&limit=<n>",
1844
1858
  pushModal: "TEST HOOK \u2014 push a modal onto the snapshot.modalStack via the registry ModalDetector",
1845
- dismissModal: "TEST HOOK \u2014 dismiss a modal by id from the snapshot.modalStack via the registry ModalDetector"
1859
+ dismissModal: "TEST HOOK \u2014 dismiss a modal by id from the snapshot.modalStack via the registry ModalDetector",
1860
+ keepAwake: "TEST HOOK \u2014 keep the device screen awake via the injected keepAwakeProvider: body { enabled: boolean, durationMs?: number }"
1846
1861
  };
1847
1862
  var ACTION_REFERENCE = [
1848
1863
  { name: "press", aliases: ["click"], params: "PressActionParams (optional position)" },
@@ -2110,6 +2125,35 @@ var NativeUIBridgeServer = class {
2110
2125
  }
2111
2126
  };
2112
2127
  }
2128
+ /**
2129
+ * Set a keep-awake provider for native screen-wake control.
2130
+ * This enables `control/keep-awake` and arms the auto-arm hook in
2131
+ * handleRequest (every request keeps the screen alive for 60s).
2132
+ */
2133
+ setKeepAwakeProvider(provider) {
2134
+ this.keepAwakeProvider = provider;
2135
+ this.handlers.keepAwake = async (ctx) => {
2136
+ const { enabled, durationMs } = ctx.body ?? {};
2137
+ if (typeof enabled !== "boolean") {
2138
+ return {
2139
+ success: false,
2140
+ error: "enabled must be boolean",
2141
+ code: "INVALID_REQUEST",
2142
+ timestamp: Date.now()
2143
+ };
2144
+ }
2145
+ if (enabled) {
2146
+ provider.request("ui-bridge", typeof durationMs === "number" ? durationMs : void 0);
2147
+ } else {
2148
+ provider.release("ui-bridge");
2149
+ }
2150
+ return {
2151
+ success: true,
2152
+ data: { enabled, durationMs: typeof durationMs === "number" ? durationMs : null },
2153
+ timestamp: Date.now()
2154
+ };
2155
+ };
2156
+ }
2113
2157
  /**
2114
2158
  * Start the HTTP server
2115
2159
  */
@@ -2702,6 +2746,12 @@ var NativeUIBridgeServer = class {
2702
2746
  if (request.method === "OPTIONS") {
2703
2747
  return { status: 204, headers, body: "" };
2704
2748
  }
2749
+ if (this.config.testHooks === true && this.keepAwakeProvider) {
2750
+ try {
2751
+ this.keepAwakeProvider.request("auto-arm", 6e4);
2752
+ } catch {
2753
+ }
2754
+ }
2705
2755
  try {
2706
2756
  const response = await this.routeRequest(request);
2707
2757
  return {