appium-ios-remotexpc 0.0.3 → 0.0.4

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 (192) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/src/base-plist-service.d.ts +51 -0
  3. package/build/src/base-plist-service.d.ts.map +1 -0
  4. package/build/src/base-plist-service.js +61 -0
  5. package/build/src/base-socket-service.d.ts +15 -0
  6. package/build/src/base-socket-service.d.ts.map +1 -0
  7. package/build/src/base-socket-service.js +46 -0
  8. package/build/src/index.d.ts +9 -0
  9. package/build/src/index.d.ts.map +1 -0
  10. package/build/src/index.js +7 -0
  11. package/build/src/lib/apple-tv/constants.d.ts +49 -0
  12. package/build/src/lib/apple-tv/constants.d.ts.map +1 -0
  13. package/build/src/lib/apple-tv/constants.js +71 -0
  14. package/build/src/lib/apple-tv/errors.d.ts +17 -0
  15. package/build/src/lib/apple-tv/errors.d.ts.map +1 -0
  16. package/build/src/lib/apple-tv/errors.js +30 -0
  17. package/build/src/lib/apple-tv/tlv/decoder.d.ts +19 -0
  18. package/build/src/lib/apple-tv/tlv/decoder.d.ts.map +1 -0
  19. package/build/src/lib/apple-tv/tlv/decoder.js +49 -0
  20. package/build/src/lib/apple-tv/tlv/encoder.d.ts +10 -0
  21. package/build/src/lib/apple-tv/tlv/encoder.d.ts.map +1 -0
  22. package/build/src/lib/apple-tv/tlv/encoder.js +20 -0
  23. package/build/src/lib/apple-tv/tlv/index.d.ts +4 -0
  24. package/build/src/lib/apple-tv/tlv/index.d.ts.map +1 -0
  25. package/build/src/lib/apple-tv/tlv/index.js +3 -0
  26. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts +14 -0
  27. package/build/src/lib/apple-tv/tlv/pairing-tlv.d.ts.map +1 -0
  28. package/build/src/lib/apple-tv/tlv/pairing-tlv.js +27 -0
  29. package/build/src/lib/apple-tv/types.d.ts +36 -0
  30. package/build/src/lib/apple-tv/types.d.ts.map +1 -0
  31. package/build/src/lib/apple-tv/types.js +1 -0
  32. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts +40 -0
  33. package/build/src/lib/apple-tv/utils/buffer-utils.d.ts.map +1 -0
  34. package/build/src/lib/apple-tv/utils/buffer-utils.js +76 -0
  35. package/build/src/lib/apple-tv/utils/index.d.ts +3 -0
  36. package/build/src/lib/apple-tv/utils/index.d.ts.map +1 -0
  37. package/build/src/lib/apple-tv/utils/index.js +2 -0
  38. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts +9 -0
  39. package/build/src/lib/apple-tv/utils/uuid-generator.d.ts.map +1 -0
  40. package/build/src/lib/apple-tv/utils/uuid-generator.js +36 -0
  41. package/build/src/lib/lockdown/index.d.ts +87 -0
  42. package/build/src/lib/lockdown/index.d.ts.map +1 -0
  43. package/build/src/lib/lockdown/index.js +324 -0
  44. package/build/src/lib/pair-record/index.d.ts +3 -0
  45. package/build/src/lib/pair-record/index.d.ts.map +1 -0
  46. package/build/src/lib/pair-record/index.js +2 -0
  47. package/build/src/lib/pair-record/pair-record.d.ts +48 -0
  48. package/build/src/lib/pair-record/pair-record.d.ts.map +1 -0
  49. package/build/src/lib/pair-record/pair-record.js +85 -0
  50. package/build/src/lib/plist/binary-plist-creator.d.ts +14 -0
  51. package/build/src/lib/plist/binary-plist-creator.d.ts.map +1 -0
  52. package/build/src/lib/plist/binary-plist-creator.js +475 -0
  53. package/build/src/lib/plist/binary-plist-parser.d.ts +14 -0
  54. package/build/src/lib/plist/binary-plist-parser.d.ts.map +1 -0
  55. package/build/src/lib/plist/binary-plist-parser.js +449 -0
  56. package/build/src/lib/plist/constants.d.ts +36 -0
  57. package/build/src/lib/plist/constants.d.ts.map +1 -0
  58. package/build/src/lib/plist/constants.js +43 -0
  59. package/build/src/lib/plist/index.d.ts +14 -0
  60. package/build/src/lib/plist/index.d.ts.map +1 -0
  61. package/build/src/lib/plist/index.js +16 -0
  62. package/build/src/lib/plist/length-based-splitter.d.ts +43 -0
  63. package/build/src/lib/plist/length-based-splitter.d.ts.map +1 -0
  64. package/build/src/lib/plist/length-based-splitter.js +228 -0
  65. package/build/src/lib/plist/plist-creator.d.ts +8 -0
  66. package/build/src/lib/plist/plist-creator.d.ts.map +1 -0
  67. package/build/src/lib/plist/plist-creator.js +33 -0
  68. package/build/src/lib/plist/plist-decoder.d.ts +25 -0
  69. package/build/src/lib/plist/plist-decoder.d.ts.map +1 -0
  70. package/build/src/lib/plist/plist-decoder.js +103 -0
  71. package/build/src/lib/plist/plist-encoder.d.ts +10 -0
  72. package/build/src/lib/plist/plist-encoder.d.ts.map +1 -0
  73. package/build/src/lib/plist/plist-encoder.js +27 -0
  74. package/build/src/lib/plist/plist-parser.d.ts +9 -0
  75. package/build/src/lib/plist/plist-parser.d.ts.map +1 -0
  76. package/build/src/lib/plist/plist-parser.js +109 -0
  77. package/build/src/lib/plist/plist-service.d.ts +86 -0
  78. package/build/src/lib/plist/plist-service.d.ts.map +1 -0
  79. package/build/src/lib/plist/plist-service.js +180 -0
  80. package/build/src/lib/plist/unified-plist-creator.d.ts +9 -0
  81. package/build/src/lib/plist/unified-plist-creator.d.ts.map +1 -0
  82. package/build/src/lib/plist/unified-plist-creator.js +14 -0
  83. package/build/src/lib/plist/unified-plist-parser.d.ts +8 -0
  84. package/build/src/lib/plist/unified-plist-parser.d.ts.map +1 -0
  85. package/build/src/lib/plist/unified-plist-parser.js +23 -0
  86. package/build/src/lib/plist/utils.d.ts +97 -0
  87. package/build/src/lib/plist/utils.d.ts.map +1 -0
  88. package/build/src/lib/plist/utils.js +287 -0
  89. package/build/src/lib/remote-xpc/constants.d.ts +20 -0
  90. package/build/src/lib/remote-xpc/constants.d.ts.map +1 -0
  91. package/build/src/lib/remote-xpc/constants.js +21 -0
  92. package/build/src/lib/remote-xpc/handshake-frames.d.ts +74 -0
  93. package/build/src/lib/remote-xpc/handshake-frames.d.ts.map +1 -0
  94. package/build/src/lib/remote-xpc/handshake-frames.js +285 -0
  95. package/build/src/lib/remote-xpc/handshake.d.ts +14 -0
  96. package/build/src/lib/remote-xpc/handshake.d.ts.map +1 -0
  97. package/build/src/lib/remote-xpc/handshake.js +95 -0
  98. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts +55 -0
  99. package/build/src/lib/remote-xpc/remote-xpc-connection.d.ts.map +1 -0
  100. package/build/src/lib/remote-xpc/remote-xpc-connection.js +365 -0
  101. package/build/src/lib/remote-xpc/xpc-protocol.d.ts +22 -0
  102. package/build/src/lib/remote-xpc/xpc-protocol.d.ts.map +1 -0
  103. package/build/src/lib/remote-xpc/xpc-protocol.js +368 -0
  104. package/build/src/lib/tunnel/index.d.ts +69 -0
  105. package/build/src/lib/tunnel/index.d.ts.map +1 -0
  106. package/build/src/lib/tunnel/index.js +205 -0
  107. package/build/src/lib/tunnel/packet-stream-client.d.ts +46 -0
  108. package/build/src/lib/tunnel/packet-stream-client.d.ts.map +1 -0
  109. package/build/src/lib/tunnel/packet-stream-client.js +152 -0
  110. package/build/src/lib/tunnel/packet-stream-server.d.ts +37 -0
  111. package/build/src/lib/tunnel/packet-stream-server.d.ts.map +1 -0
  112. package/build/src/lib/tunnel/packet-stream-server.js +109 -0
  113. package/build/src/lib/tunnel/tunnel-api-client.d.ts +85 -0
  114. package/build/src/lib/tunnel/tunnel-api-client.d.ts.map +1 -0
  115. package/build/src/lib/tunnel/tunnel-api-client.js +207 -0
  116. package/build/src/lib/tunnel/tunnel-registry-server.d.ts +68 -0
  117. package/build/src/lib/tunnel/tunnel-registry-server.d.ts.map +1 -0
  118. package/build/src/lib/tunnel/tunnel-registry-server.js +351 -0
  119. package/build/src/lib/types.d.ts +238 -0
  120. package/build/src/lib/types.d.ts.map +1 -0
  121. package/build/src/lib/types.js +4 -0
  122. package/build/src/lib/usbmux/index.d.ts +177 -0
  123. package/build/src/lib/usbmux/index.d.ts.map +1 -0
  124. package/build/src/lib/usbmux/index.js +490 -0
  125. package/build/src/lib/usbmux/usbmux-decoder.d.ts +19 -0
  126. package/build/src/lib/usbmux/usbmux-decoder.d.ts.map +1 -0
  127. package/build/src/lib/usbmux/usbmux-decoder.js +38 -0
  128. package/build/src/lib/usbmux/usbmux-encoder.d.ts +12 -0
  129. package/build/src/lib/usbmux/usbmux-encoder.d.ts.map +1 -0
  130. package/build/src/lib/usbmux/usbmux-encoder.js +32 -0
  131. package/build/src/service-connection.d.ts +34 -0
  132. package/build/src/service-connection.d.ts.map +1 -0
  133. package/build/src/service-connection.js +51 -0
  134. package/build/src/services/index.d.ts +6 -0
  135. package/build/src/services/index.d.ts.map +1 -0
  136. package/build/src/services/index.js +5 -0
  137. package/build/src/services/ios/base-service.d.ts +35 -0
  138. package/build/src/services/ios/base-service.d.ts.map +1 -0
  139. package/build/src/services/ios/base-service.js +55 -0
  140. package/build/src/services/ios/diagnostic-service/index.d.ts +46 -0
  141. package/build/src/services/ios/diagnostic-service/index.d.ts.map +1 -0
  142. package/build/src/services/ios/diagnostic-service/index.js +169 -0
  143. package/build/src/services/ios/diagnostic-service/keys.d.ts +5 -0
  144. package/build/src/services/ios/diagnostic-service/keys.d.ts.map +1 -0
  145. package/build/src/services/ios/diagnostic-service/keys.js +770 -0
  146. package/build/src/services/ios/syslog-service/index.d.ts +91 -0
  147. package/build/src/services/ios/syslog-service/index.d.ts.map +1 -0
  148. package/build/src/services/ios/syslog-service/index.js +323 -0
  149. package/build/src/services/ios/tunnel-service/index.d.ts +17 -0
  150. package/build/src/services/ios/tunnel-service/index.d.ts.map +1 -0
  151. package/build/src/services/ios/tunnel-service/index.js +57 -0
  152. package/build/src/services.d.ts +14 -0
  153. package/build/src/services.d.ts.map +1 -0
  154. package/build/src/services.js +48 -0
  155. package/package.json +12 -3
  156. package/.github/dependabot.yml +0 -38
  157. package/.github/workflows/format-check.yml +0 -43
  158. package/.github/workflows/lint-and-build.yml +0 -40
  159. package/.github/workflows/pr-title.yml +0 -16
  160. package/.github/workflows/publish.js.yml +0 -43
  161. package/.github/workflows/test-validation.yml +0 -40
  162. package/.mocharc.json +0 -8
  163. package/.prettierignore +0 -3
  164. package/.prettierrc +0 -17
  165. package/.releaserc +0 -48
  166. package/assets/images/ios-arch.png +0 -0
  167. package/eslint.config.js +0 -45
  168. package/npm-shrinkwrap.json +0 -2711
  169. package/test/integration/diagnostics-test.ts +0 -44
  170. package/test/integration/read-pair-record-test.ts +0 -39
  171. package/test/integration/tunnel-test.ts +0 -104
  172. package/test/unit/apple-tv/tlv/decoder.spec.ts +0 -144
  173. package/test/unit/apple-tv/tlv/encoder.spec.ts +0 -91
  174. package/test/unit/apple-tv/tlv/pairing-tlv.spec.ts +0 -101
  175. package/test/unit/apple-tv/tlv/tlv-integration.spec.ts +0 -146
  176. package/test/unit/apple-tv/utils/buffer-utils.spec.ts +0 -74
  177. package/test/unit/apple-tv/utils/uuid-generator.spec.ts +0 -39
  178. package/test/unit/fixtures/index.ts +0 -88
  179. package/test/unit/fixtures/usbmuxconnectmessage.bin +0 -0
  180. package/test/unit/fixtures/usbmuxlistdevicemessage.bin +0 -0
  181. package/test/unit/plist/error-handling.spec.ts +0 -101
  182. package/test/unit/plist/fixtures/sample.binary.plist +0 -0
  183. package/test/unit/plist/fixtures/sample.xml.plist +0 -38
  184. package/test/unit/plist/plist-parser.spec.ts +0 -283
  185. package/test/unit/plist/plist.spec.ts +0 -205
  186. package/test/unit/plist/tag-position-handling.spec.ts +0 -90
  187. package/test/unit/plist/unified-plist-parser.spec.ts +0 -227
  188. package/test/unit/plist/utils.spec.ts +0 -249
  189. package/test/unit/plist/xml-cleaning.spec.ts +0 -60
  190. package/test/unit/tunnel/tunnel-registry-server.spec.ts +0 -194
  191. package/test/unit/usbmux/usbmux-specs.ts +0 -71
  192. package/tsconfig.json +0 -36
@@ -0,0 +1,351 @@
1
+ import { logger } from '@appium/support';
2
+ import * as http from 'node:http';
3
+ import { URL } from 'node:url';
4
+ // Constants
5
+ const DEFAULT_TUNNEL_REGISTRY_PORT = 42314;
6
+ const API_BASE_PATH = '/remotexpc/tunnels';
7
+ // Logger instance
8
+ const log = logger.getLogger('TunnelRegistryServer');
9
+ // Helper functions
10
+ /**
11
+ * Parse JSON body from HTTP request
12
+ */
13
+ async function parseJSONBody(req) {
14
+ return new Promise((resolve, reject) => {
15
+ let body = '';
16
+ req.on('data', (chunk) => {
17
+ body += chunk.toString();
18
+ });
19
+ req.on('end', () => {
20
+ try {
21
+ resolve(body ? JSON.parse(body) : {});
22
+ }
23
+ catch (error) {
24
+ reject(error);
25
+ }
26
+ });
27
+ req.on('error', reject);
28
+ });
29
+ }
30
+ /**
31
+ * Send JSON response
32
+ */
33
+ function sendJSON(res, statusCode, data) {
34
+ const statusText = http.STATUS_CODES[statusCode] || '';
35
+ let responseBody;
36
+ if (data && typeof data === 'object' && data !== null) {
37
+ if ('error' in data) {
38
+ responseBody = { status: statusText, ...data };
39
+ }
40
+ else {
41
+ responseBody = { status: statusText, ...data };
42
+ }
43
+ }
44
+ else {
45
+ responseBody = { status: statusText, data };
46
+ }
47
+ res.writeHead(statusCode, { 'Content-Type': 'application/json' });
48
+ res.end(JSON.stringify(responseBody));
49
+ }
50
+ /**
51
+ * Tunnel Registry Server - provides API endpoints for tunnel registry operations
52
+ */
53
+ export class TunnelRegistryServer {
54
+ server;
55
+ port;
56
+ tunnelsInfo;
57
+ registry = {
58
+ tunnels: {},
59
+ metadata: {
60
+ lastUpdated: new Date().toISOString(),
61
+ totalTunnels: 0,
62
+ activeTunnels: 0,
63
+ },
64
+ };
65
+ /**
66
+ * Create a new TunnelRegistryServer
67
+ * @param tunnelsInfo - Registry data object
68
+ * @param port - Port to listen on
69
+ */
70
+ constructor(tunnelsInfo, port) {
71
+ this.port = port;
72
+ this.tunnelsInfo = tunnelsInfo;
73
+ }
74
+ /**
75
+ * Get tunnels from registry
76
+ */
77
+ get tunnels() {
78
+ return this.registry.tunnels;
79
+ }
80
+ /**
81
+ * Get auto-calculated metadata
82
+ */
83
+ get metadata() {
84
+ const tunnelCount = Object.keys(this.tunnels).length;
85
+ return {
86
+ lastUpdated: new Date().toISOString(),
87
+ totalTunnels: tunnelCount,
88
+ activeTunnels: tunnelCount, // Assuming all tunnels are active
89
+ };
90
+ }
91
+ /**
92
+ * Get a complete registry with tunnels and metadata
93
+ */
94
+ get fullRegistry() {
95
+ return {
96
+ tunnels: this.tunnels,
97
+ metadata: this.metadata,
98
+ };
99
+ }
100
+ /**
101
+ * Start the server
102
+ */
103
+ async start() {
104
+ try {
105
+ // Load the registry first
106
+ await this.loadRegistry();
107
+ // Create HTTP server with request handler
108
+ this.server = http.createServer(async (req, res) => {
109
+ await this.handleRequest(req, res);
110
+ });
111
+ // Start listening
112
+ await new Promise((resolve, reject) => {
113
+ this.server?.listen(this.port, () => {
114
+ log.info(`Tunnel Registry Server started on port ${this.port}`);
115
+ log.info(`API available at http://localhost:${this.port}${API_BASE_PATH}`);
116
+ resolve();
117
+ });
118
+ // Handle server errors
119
+ this.server?.on('error', (error) => {
120
+ log.error(`Server error: ${error}`);
121
+ reject(error);
122
+ });
123
+ });
124
+ }
125
+ catch (error) {
126
+ log.error(`Failed to start server: ${error}`);
127
+ throw error;
128
+ }
129
+ }
130
+ /**
131
+ * Stop the server
132
+ */
133
+ async stop() {
134
+ if (!this.server) {
135
+ log.warn('Server not running');
136
+ return;
137
+ }
138
+ try {
139
+ await new Promise((resolve, reject) => {
140
+ this.server?.close((error) => {
141
+ if (error) {
142
+ reject(error);
143
+ }
144
+ else {
145
+ resolve();
146
+ }
147
+ });
148
+ });
149
+ log.info('Tunnel Registry Server stopped');
150
+ }
151
+ catch (error) {
152
+ log.error(`Error stopping server: ${error}`);
153
+ throw error;
154
+ }
155
+ }
156
+ /**
157
+ * Main request handler
158
+ */
159
+ async handleRequest(req, res) {
160
+ const url = new URL(req.url || '', `http://localhost:${this.port}`);
161
+ const method = req.method || 'GET';
162
+ const pathname = url.pathname;
163
+ // Log the request
164
+ log.debug(`${method} ${pathname}`);
165
+ // Match routes
166
+ const basePath = API_BASE_PATH;
167
+ try {
168
+ // GET /remotexpc/tunnels - Get all tunnels
169
+ if (method === 'GET' && pathname === basePath) {
170
+ await this.getAllTunnels(res);
171
+ return;
172
+ }
173
+ // GET /remotexpc/tunnels/device/:deviceId - Get tunnel by device ID
174
+ const deviceMatch = pathname.match(new RegExp(`^${basePath}/device/(.+)$`));
175
+ if (method === 'GET' && deviceMatch) {
176
+ const deviceIdStr = deviceMatch[1];
177
+ const deviceId = parseInt(deviceIdStr, 10);
178
+ await this.getTunnelByDeviceId(res, deviceId);
179
+ return;
180
+ }
181
+ // GET /remotexpc/tunnels/:udid - Get tunnel by UDID
182
+ const udidMatch = pathname.match(new RegExp(`^${basePath}/([^/]+)$`));
183
+ if (method === 'GET' &&
184
+ udidMatch &&
185
+ !udidMatch[1].startsWith('device/')) {
186
+ const udid = udidMatch[1];
187
+ await this.getTunnelByUdid(res, udid);
188
+ return;
189
+ }
190
+ // PUT /remotexpc/tunnels/:udid - Update tunnel
191
+ if (method === 'PUT' && udidMatch) {
192
+ const udid = udidMatch[1];
193
+ await this.updateTunnel(req, res, udid);
194
+ return;
195
+ }
196
+ // No route matched
197
+ sendJSON(res, 404, { error: 'Not found' });
198
+ }
199
+ catch (error) {
200
+ log.error(`Request handling error: ${error}`);
201
+ sendJSON(res, 500, {
202
+ error: 'Internal server error',
203
+ });
204
+ }
205
+ }
206
+ /**
207
+ * Handler for getting all tunnels
208
+ */
209
+ async getAllTunnels(res) {
210
+ try {
211
+ await this.loadRegistry();
212
+ sendJSON(res, 200, this.fullRegistry);
213
+ }
214
+ catch (error) {
215
+ log.error(`Error getting all tunnels: ${error}`);
216
+ sendJSON(res, 500, {
217
+ error: 'Failed to get tunnels',
218
+ });
219
+ }
220
+ }
221
+ /**
222
+ * Handler for getting a tunnel by UDID
223
+ */
224
+ async getTunnelByUdid(res, udid) {
225
+ try {
226
+ await this.loadRegistry();
227
+ const tunnel = this.tunnels[udid];
228
+ if (!tunnel) {
229
+ sendJSON(res, 404, {
230
+ error: `Tunnel not found for UDID: ${udid}`,
231
+ });
232
+ return;
233
+ }
234
+ sendJSON(res, 200, tunnel);
235
+ }
236
+ catch (error) {
237
+ log.error(`Error getting tunnel by UDID: ${error}`);
238
+ sendJSON(res, 500, {
239
+ error: 'Failed to get tunnel',
240
+ });
241
+ }
242
+ }
243
+ /**
244
+ * Handler for getting a tunnel by device ID
245
+ */
246
+ async getTunnelByDeviceId(res, deviceId) {
247
+ try {
248
+ await this.loadRegistry();
249
+ if (isNaN(deviceId)) {
250
+ sendJSON(res, 400, { error: 'Invalid device ID' });
251
+ return;
252
+ }
253
+ const tunnel = Object.values(this.tunnels).find((t) => t.deviceId === deviceId);
254
+ if (!tunnel) {
255
+ sendJSON(res, 404, {
256
+ error: `Tunnel not found for device ID: ${deviceId}`,
257
+ });
258
+ return;
259
+ }
260
+ sendJSON(res, 200, tunnel);
261
+ }
262
+ catch (error) {
263
+ log.error(`Error getting tunnel by device ID: ${error}`);
264
+ sendJSON(res, 500, {
265
+ error: 'Failed to get tunnel',
266
+ });
267
+ }
268
+ }
269
+ /**
270
+ * Handler for updating a tunnel
271
+ */
272
+ async updateTunnel(req, res, udid) {
273
+ try {
274
+ await this.loadRegistry();
275
+ let tunnelData = null;
276
+ try {
277
+ tunnelData = await parseJSONBody(req);
278
+ }
279
+ catch (parseError) {
280
+ const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
281
+ log.error(`Failed to parse JSON body: ${errorMessage}`);
282
+ sendJSON(res, 400, {
283
+ error: 'Malformed JSON in request body',
284
+ });
285
+ return;
286
+ }
287
+ if (!tunnelData || typeof tunnelData !== 'object') {
288
+ sendJSON(res, 400, {
289
+ error: 'Invalid tunnel data',
290
+ });
291
+ return;
292
+ }
293
+ // Ensure the UDID in the path matches the one in the body
294
+ if (tunnelData.udid !== udid) {
295
+ sendJSON(res, 400, {
296
+ error: 'UDID mismatch between path and body',
297
+ });
298
+ return;
299
+ }
300
+ // Update the tunnel
301
+ this.registry.tunnels[udid] = {
302
+ ...tunnelData,
303
+ lastUpdated: Date.now(),
304
+ };
305
+ sendJSON(res, 200, {
306
+ success: true,
307
+ tunnel: this.registry.tunnels[udid],
308
+ });
309
+ }
310
+ catch (error) {
311
+ log.error(`Error updating tunnel: ${error}`);
312
+ sendJSON(res, 500, {
313
+ error: 'Failed to update tunnel',
314
+ });
315
+ }
316
+ }
317
+ /**
318
+ * Load the registry from provided data
319
+ */
320
+ async loadRegistry() {
321
+ try {
322
+ if (this.tunnelsInfo) {
323
+ this.registry = this.tunnelsInfo;
324
+ }
325
+ // Use the provided registry object or default empty registry
326
+ }
327
+ catch (error) {
328
+ log.warn(`Failed to load registry: ${error}`);
329
+ // If there's an error, use the default empty registry
330
+ this.registry = {
331
+ tunnels: {},
332
+ metadata: {
333
+ lastUpdated: new Date().toISOString(),
334
+ totalTunnels: 0,
335
+ activeTunnels: 0,
336
+ },
337
+ };
338
+ }
339
+ }
340
+ }
341
+ /**
342
+ * Create and start a TunnelRegistryServer instance
343
+ * @param tunnelInfos - Registry data object
344
+ * @param port - Port to listen on
345
+ * @returns The started TunnelRegistryServer instance
346
+ */
347
+ export async function startTunnelRegistryServer(tunnelInfos, port = DEFAULT_TUNNEL_REGISTRY_PORT) {
348
+ const server = new TunnelRegistryServer(tunnelInfos, port);
349
+ await server.start();
350
+ return server;
351
+ }
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Common type definitions for the appium-ios-remotexpc library
3
+ */
4
+ import { EventEmitter } from 'events';
5
+ import type { PacketData } from 'tuntap-bridge';
6
+ import type { BaseService, Service } from '../services/ios/base-service.js';
7
+ import type { Device } from './usbmux/index.js';
8
+ /**
9
+ * Represents a value that can be stored in a plist
10
+ */
11
+ export type PlistValue = string | number | bigint | boolean | Date | Buffer | PlistArray | PlistDictionary | null;
12
+ /**
13
+ * Represents an array in a plist
14
+ */
15
+ export type PlistArray = Array<PlistValue>;
16
+ /**
17
+ * Represents a dictionary in a plist
18
+ */
19
+ export interface PlistDictionary {
20
+ [key: string]: PlistValue;
21
+ }
22
+ /**
23
+ * Represents a message that can be sent or received via plist
24
+ */
25
+ export type PlistMessage = PlistDictionary;
26
+ /**
27
+ * Represents a value that can be encoded in XPC protocol
28
+ */
29
+ export type XPCValue = string | number | bigint | boolean | Date | Buffer | Uint8Array | XPCArray | XPCDictionary | null;
30
+ /**
31
+ * Represents an array in XPC protocol
32
+ */
33
+ export type XPCArray = Array<XPCValue>;
34
+ /**
35
+ * Represents a dictionary in XPC protocol
36
+ */
37
+ export interface XPCDictionary {
38
+ [key: string]: XPCValue;
39
+ }
40
+ /**
41
+ * Represents a callback function for handling responses
42
+ */
43
+ export type ResponseCallback<T> = (data: T) => void;
44
+ export interface TunnelRegistryEntry {
45
+ /** Unique device identifier */
46
+ udid: string;
47
+ /** Numeric device ID */
48
+ deviceId: number;
49
+ /** IP address of the tunnel */
50
+ address: string;
51
+ /** Remote Service Discovery (RSD) port number */
52
+ rsdPort: number;
53
+ /** Packet stream port number */
54
+ packetStreamPort: number;
55
+ /** Type of connection (e.g., 'USB', 'Network') */
56
+ connectionType: string;
57
+ /** Product identifier of the device */
58
+ productId: number;
59
+ /** Timestamp when the tunnel was created (milliseconds since epoch) */
60
+ createdAt: number;
61
+ /** Timestamp when the tunnel was last updated (milliseconds since epoch) */
62
+ lastUpdated: number;
63
+ }
64
+ export interface TunnelRegistry {
65
+ /** Map of UDID to tunnel registry entries */
66
+ tunnels: Record<string, TunnelRegistryEntry>;
67
+ /** Metadata about the registry */
68
+ metadata: {
69
+ /** ISO 8601 timestamp of last registry update */
70
+ lastUpdated: string;
71
+ /** Total number of tunnels in the registry */
72
+ totalTunnels: number;
73
+ /** Number of currently active tunnels */
74
+ activeTunnels: number;
75
+ };
76
+ }
77
+ export interface SocketInfo {
78
+ /** Device server information */
79
+ server: Device;
80
+ /** Port number for the socket connection */
81
+ port: number;
82
+ /** Device-specific information */
83
+ deviceInfo: {
84
+ /** Unique device identifier */
85
+ udid: string;
86
+ /** IP address of the device */
87
+ address: string;
88
+ /** Optional Remote Service Discovery (RSD) port number */
89
+ rsdPort?: number;
90
+ };
91
+ }
92
+ export interface TunnelResult {
93
+ /** Device information */
94
+ device: Device;
95
+ /** Tunnel connection details */
96
+ tunnel: {
97
+ /** IP address of the tunnel */
98
+ Address: string;
99
+ /** Optional Remote Service Discovery (RSD) port number */
100
+ RsdPort?: number;
101
+ };
102
+ /** Optional packet stream port number */
103
+ packetStreamPort?: number;
104
+ /** Indicates whether the tunnel creation was successful */
105
+ success: boolean;
106
+ /** Error message if tunnel creation failed */
107
+ error?: string;
108
+ }
109
+ /**
110
+ * Represents the instance side of DiagnosticsService
111
+ */
112
+ export interface DiagnosticsService extends BaseService {
113
+ /**
114
+ * Restart the device
115
+ * @returns Promise that resolves when the restart request is sent
116
+ */
117
+ restart(): Promise<PlistDictionary>;
118
+ /**
119
+ * Shutdown the device
120
+ * @returns Promise that resolves when the shutdown request is sent
121
+ */
122
+ shutdown(): Promise<PlistDictionary>;
123
+ /**
124
+ * Put the device in sleep mode
125
+ * @returns Promise that resolves when the sleep request is sent
126
+ */
127
+ sleep(): Promise<PlistDictionary>;
128
+ /**
129
+ * Query IORegistry
130
+ * @param options Options for the IORegistry query
131
+ * @returns Object containing the IORegistry information
132
+ */
133
+ ioregistry(options?: {
134
+ plane?: string;
135
+ name?: string;
136
+ ioClass?: string;
137
+ returnRawJson?: boolean;
138
+ timeout?: number;
139
+ }): Promise<PlistDictionary[] | Record<string, any>>;
140
+ }
141
+ /**
142
+ * Represents the static side of DiagnosticsService
143
+ */
144
+ export interface DiagnosticsServiceConstructor {
145
+ /**
146
+ * Service name for Remote Service Discovery
147
+ */
148
+ readonly RSD_SERVICE_NAME: string;
149
+ /**
150
+ * Creates a new DiagnosticsService instance
151
+ * @param address Tuple containing [host, port]
152
+ */
153
+ new (address: [string, number]): DiagnosticsService;
154
+ }
155
+ /**
156
+ * Options for configuring syslog capture
157
+ */
158
+ export interface SyslogOptions {
159
+ /** Process ID to filter logs by */
160
+ pid?: number;
161
+ /** Whether to enable verbose logging */
162
+ enableVerboseLogging?: boolean;
163
+ }
164
+ /**
165
+ * Interface for a packet source that can provide packet data
166
+ */
167
+ export interface PacketSource {
168
+ /** Add a packet consumer to receive packets */
169
+ addPacketConsumer: (consumer: PacketConsumer) => void;
170
+ /** Remove a packet consumer */
171
+ removePacketConsumer: (consumer: PacketConsumer) => void;
172
+ }
173
+ /**
174
+ * Interface for a packet consumer that can process packets
175
+ */
176
+ export interface PacketConsumer {
177
+ /** Handler for received packets */
178
+ onPacket: (packet: PacketData) => void;
179
+ }
180
+ /**
181
+ * Represents the instance side of SyslogService
182
+ */
183
+ export interface SyslogService extends EventEmitter {
184
+ /**
185
+ * Starts capturing syslog data from the device
186
+ * @param service Service information
187
+ * @param packetSource Source of packet data (can be PacketConsumer or AsyncIterable)
188
+ * @param options Configuration options for syslog capture
189
+ * @returns Promise resolving to the initial response from the service
190
+ */
191
+ start(service: Service, packetSource: PacketSource | AsyncIterable<PacketData>, options?: SyslogOptions): Promise<void>;
192
+ /**
193
+ * Stops capturing syslog data
194
+ * @returns Promise that resolves when capture is stopped
195
+ */
196
+ stop(): Promise<void>;
197
+ /**
198
+ * Restart the device
199
+ * @param service Service information
200
+ * @returns Promise that resolves when the restart request is sent
201
+ */
202
+ restart(service: Service): Promise<void>;
203
+ /**
204
+ * Event emitter for 'start' events
205
+ */
206
+ on(event: 'start', listener: (response: any) => void): this;
207
+ /**
208
+ * Event emitter for 'stop' events
209
+ */
210
+ on(event: 'stop', listener: () => void): this;
211
+ /**
212
+ * Event emitter for 'message' events
213
+ */
214
+ on(event: 'message', listener: (message: string) => void): this;
215
+ /**
216
+ * Event emitter for 'plist' events
217
+ */
218
+ on(event: 'plist', listener: (data: any) => void): this;
219
+ /**
220
+ * Event emitter for 'error' events
221
+ */
222
+ on(event: 'error', listener: (error: Error) => void): this;
223
+ /**
224
+ * Event emitter for any events
225
+ */
226
+ on(event: string, listener: (...args: any[]) => void): this;
227
+ }
228
+ /**
229
+ * Represents the static side of SyslogService
230
+ */
231
+ export interface SyslogServiceConstructor {
232
+ /**
233
+ * Creates a new SyslogService instance
234
+ * @param address Tuple containing [host, port]
235
+ */
236
+ new (address: [string, number]): SyslogService;
237
+ }
238
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,MAAM,GACN,UAAU,GACV,eAAe,GACf,IAAI,CAAC;AAET;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,MAAM,GACN,UAAU,GACV,QAAQ,GACR,aAAa,GACb,IAAI,CAAC;AAET;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,I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