eas-cli 27.4.0 → 27.5.0
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/README.md +369 -198
- package/build/build/simulatorsLaunchHint.js +1 -1
- package/build/commands/simulator/availability.d.ts +1 -0
- package/build/commands/simulator/availability.js +3 -1
- package/build/commands/simulator/control/connection.d.ts +19 -0
- package/build/commands/simulator/control/connection.js +93 -0
- package/build/commands/simulator/control.d.ts +7 -0
- package/build/commands/simulator/control.js +249 -110
- package/build/commands/simulator/egress.d.ts +1 -0
- package/build/commands/simulator/egress.js +3 -1
- package/build/commands/simulator/events.d.ts +1 -0
- package/build/commands/simulator/events.js +3 -1
- package/build/commands/simulator/exec.d.ts +1 -0
- package/build/commands/simulator/exec.js +3 -1
- package/build/commands/simulator/get.d.ts +1 -0
- package/build/commands/simulator/get.js +3 -1
- package/build/commands/simulator/index.d.ts +2 -0
- package/build/commands/simulator/index.js +286 -76
- package/build/commands/simulator/list.d.ts +1 -0
- package/build/commands/simulator/list.js +3 -1
- package/build/commands/simulator/logs.d.ts +1 -0
- package/build/commands/simulator/logs.js +3 -1
- package/build/commands/simulator/stop.d.ts +1 -0
- package/build/commands/simulator/stop.js +3 -1
- package/build/commands/workflow/ssh.d.ts +0 -1
- package/build/commands/workflow/ssh.js +0 -1
- package/build/graphql/generated.d.ts +8 -0
- package/build/graphql/types/Actor.js +3 -0
- package/build/help.js +2 -1
- package/build/project/accountSelection.js +5 -8
- package/build/simulator/commandAliases.d.ts +10 -0
- package/build/simulator/commandAliases.js +24 -0
- package/build/simulator/controlActions.d.ts +32 -0
- package/build/simulator/controlActions.js +128 -0
- package/build/simulator/controlConfig.d.ts +43 -0
- package/build/simulator/controlConfig.js +156 -0
- package/build/simulator/controlConnection.d.ts +28 -0
- package/build/simulator/controlConnection.js +337 -0
- package/build/simulator/controlConnectionProtocol.d.ts +64 -0
- package/build/simulator/controlConnectionProtocol.js +155 -0
- package/build/simulator/controlConnectionWorker.d.ts +7 -0
- package/build/simulator/controlConnectionWorker.js +278 -0
- package/build/simulator/controlSession.d.ts +3 -0
- package/build/simulator/controlSession.js +28 -0
- package/build/simulator/hostActions.d.ts +22 -3
- package/build/simulator/hostActions.js +78 -19
- package/build/simulator/sessionConfig.d.ts +16 -0
- package/build/simulator/sessionConfig.js +36 -0
- package/build/simulator/startConfig.d.ts +7 -0
- package/build/simulator/startConfig.js +89 -0
- package/build/simulator/startSetup.d.ts +7 -0
- package/build/simulator/startSetup.js +17 -0
- package/build/user/User.d.ts +9 -1
- package/build/user/User.js +25 -3
- package/build/user/accountPermissions.js +3 -1
- package/oclif.manifest.json +575 -384
- package/package.json +8 -6
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertControlKeepAliveSupported = assertControlKeepAliveSupported;
|
|
4
|
+
exports.createControlConnectionIdentityAsync = createControlConnectionIdentityAsync;
|
|
5
|
+
exports.assertControlConnectionCredentialAsync = assertControlConnectionCredentialAsync;
|
|
6
|
+
exports.ensureControlConnectionDirectoryAsync = ensureControlConnectionDirectoryAsync;
|
|
7
|
+
exports.withControlConnectionLockAsync = withControlConnectionLockAsync;
|
|
8
|
+
exports.borrowControlConnectionAsync = borrowControlConnectionAsync;
|
|
9
|
+
exports.inspectControlConnectionAsync = inspectControlConnectionAsync;
|
|
10
|
+
exports.openControlConnectionAsync = openControlConnectionAsync;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
13
|
+
const node_child_process_1 = require("node:child_process");
|
|
14
|
+
const node_crypto_1 = require("node:crypto");
|
|
15
|
+
const node_net_1 = require("node:net");
|
|
16
|
+
const node_os_1 = tslib_1.__importDefault(require("node:os"));
|
|
17
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
18
|
+
const proper_lockfile_1 = tslib_1.__importDefault(require("proper-lockfile"));
|
|
19
|
+
const zod_1 = require("zod");
|
|
20
|
+
const controlConnectionProtocol_1 = require("./controlConnectionProtocol");
|
|
21
|
+
const hostActions_1 = require("./hostActions");
|
|
22
|
+
const api_1 = require("../api");
|
|
23
|
+
const easCli_1 = require("../utils/easCli");
|
|
24
|
+
const paths_1 = require("../utils/paths");
|
|
25
|
+
function assertControlKeepAliveSupported() {
|
|
26
|
+
if (process.platform === 'win32') {
|
|
27
|
+
throw new Error('Control keep-alive is currently supported on macOS and Linux. Regular control commands still work on Windows.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function createControlConnectionIdentityAsync(sessionId, projectDir, authentication, root) {
|
|
31
|
+
const credential = authentication.accessToken ?? authentication.sessionSecret;
|
|
32
|
+
if (!credential) {
|
|
33
|
+
throw new Error('Sign in before using a simulator control connection.');
|
|
34
|
+
}
|
|
35
|
+
const scope = JSON.stringify([
|
|
36
|
+
controlConnectionProtocol_1.CONTROL_CONNECTION_VERSION,
|
|
37
|
+
easCli_1.easCliVersion,
|
|
38
|
+
node_path_1.default.resolve(__dirname),
|
|
39
|
+
(0, api_1.getExpoApiBaseUrl)(),
|
|
40
|
+
await fs.realpath(projectDir),
|
|
41
|
+
sessionId,
|
|
42
|
+
]);
|
|
43
|
+
const credentialHash = (0, node_crypto_1.createHmac)('sha256', credential)
|
|
44
|
+
.update('eas-control-connection:' + scope)
|
|
45
|
+
.digest('hex');
|
|
46
|
+
const name = credentialHash.slice(0, 32);
|
|
47
|
+
const runtimeName = (0, node_crypto_1.createHmac)('sha256', credential)
|
|
48
|
+
.update('eas-control-runtime:' + JSON.stringify([(0, api_1.getExpoApiBaseUrl)(), process.getuid?.()]))
|
|
49
|
+
.digest('hex')
|
|
50
|
+
.slice(0, 24);
|
|
51
|
+
root ??= node_path_1.default.join('/tmp', 'ectl-' + runtimeName);
|
|
52
|
+
return {
|
|
53
|
+
root,
|
|
54
|
+
socketPath: node_path_1.default.join(root, name + '.sock'),
|
|
55
|
+
credentialHash,
|
|
56
|
+
scope,
|
|
57
|
+
...(authentication.sessionSecret ? { sessionStatePath: (0, paths_1.getStateJsonPath)() } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function assertControlConnectionCredentialAsync(identity) {
|
|
61
|
+
if (!identity.sessionStatePath) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const stored = await fs.readJson(identity.sessionStatePath).catch(() => null);
|
|
65
|
+
const credential = stored?.auth?.sessionSecret;
|
|
66
|
+
if (typeof credential !== 'string') {
|
|
67
|
+
throw new Error('The EAS login used by this connection has ended.');
|
|
68
|
+
}
|
|
69
|
+
const credentialHash = (0, node_crypto_1.createHmac)('sha256', credential)
|
|
70
|
+
.update('eas-control-connection:' + identity.scope)
|
|
71
|
+
.digest('hex');
|
|
72
|
+
if (credentialHash !== identity.credentialHash) {
|
|
73
|
+
throw new Error('The EAS login used by this connection has changed.');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function ensureControlConnectionDirectoryAsync(root) {
|
|
77
|
+
assertControlKeepAliveSupported();
|
|
78
|
+
try {
|
|
79
|
+
await fs.mkdir(root, { mode: 0o700 });
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error.code !== 'EEXIST') {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
await assertControlConnectionDirectoryAsync(root);
|
|
87
|
+
}
|
|
88
|
+
async function assertControlConnectionDirectoryAsync(root) {
|
|
89
|
+
const stat = await fs.lstat(root);
|
|
90
|
+
if (!stat.isDirectory() ||
|
|
91
|
+
stat.isSymbolicLink() ||
|
|
92
|
+
stat.uid !== process.getuid?.() ||
|
|
93
|
+
(stat.mode & 0o777) !== 0o700) {
|
|
94
|
+
throw new Error('The local control directory must be owned by this user with permissions 0700.');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function hasControlSocketAsync(identity) {
|
|
98
|
+
try {
|
|
99
|
+
const stat = await fs.lstat(identity.socketPath);
|
|
100
|
+
await assertControlConnectionDirectoryAsync(identity.root);
|
|
101
|
+
if (!stat.isSocket() || stat.uid !== process.getuid?.()) {
|
|
102
|
+
throw new Error('The local control endpoint is not a private socket owned by this user.');
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (['ENOENT', 'ENOTDIR'].includes(error.code ?? '')) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function withControlConnectionLockAsync(identity, fn) {
|
|
114
|
+
await ensureControlConnectionDirectoryAsync(identity.root);
|
|
115
|
+
const release = await proper_lockfile_1.default.lock(identity.socketPath, {
|
|
116
|
+
realpath: false,
|
|
117
|
+
stale: 10_000,
|
|
118
|
+
update: 2_000,
|
|
119
|
+
retries: { retries: 1_200, minTimeout: 50, maxTimeout: 200 },
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
return await fn();
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
await release();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function connectChannelAsync(identity, operation) {
|
|
129
|
+
if (process.platform === 'win32') {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (!(await hasControlSocketAsync(identity))) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const socket = (0, node_net_1.createConnection)(identity.socketPath);
|
|
136
|
+
const channel = new controlConnectionProtocol_1.ControlConnectionChannel(socket);
|
|
137
|
+
try {
|
|
138
|
+
await new Promise((resolve, reject) => {
|
|
139
|
+
const timer = setTimeout(() => {
|
|
140
|
+
const error = new Error('Local control connection timed out.');
|
|
141
|
+
channel.destroy(error);
|
|
142
|
+
reject(error);
|
|
143
|
+
}, controlConnectionProtocol_1.CONTROL_SETUP_TIMEOUT_MS);
|
|
144
|
+
socket.once('connect', () => {
|
|
145
|
+
clearTimeout(timer);
|
|
146
|
+
resolve();
|
|
147
|
+
});
|
|
148
|
+
socket.once('error', error => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
reject(error);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
// Private filesystem ownership is the authority boundary; same-UID processes are trusted.
|
|
154
|
+
await channel.writeAsync(operation);
|
|
155
|
+
return channel;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
channel.destroy();
|
|
159
|
+
if (['ENOENT', 'ECONNREFUSED'].includes(error.code ?? '')) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const ReadySchema = zod_1.z.object({ info: controlConnectionProtocol_1.ConnectionInfoSchema, catalog: hostActions_1.HostActionCatalogSchema });
|
|
166
|
+
async function readControlReplyAsync(channel, timeoutMs, timeoutMessage) {
|
|
167
|
+
const reply = await channel.readAsync(timeoutMs, timeoutMessage);
|
|
168
|
+
const error = zod_1.z.strictObject({ error: zod_1.z.string() }).safeParse(reply);
|
|
169
|
+
if (error.success) {
|
|
170
|
+
throw new Error(error.data.error);
|
|
171
|
+
}
|
|
172
|
+
return reply;
|
|
173
|
+
}
|
|
174
|
+
async function borrowControlConnectionAsync(identity) {
|
|
175
|
+
const channel = await connectChannelAsync(identity, { operation: 'lease' });
|
|
176
|
+
if (!channel) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
const { info, catalog } = ReadySchema.parse(await readControlReplyAsync(channel, controlConnectionProtocol_1.CONTROL_LEASE_WAIT_TIMEOUT_MS, 'The control connection is busy; no action was sent. Try again after the current command finishes.'));
|
|
181
|
+
const controller = new AbortController();
|
|
182
|
+
channel.socket.once('close', () => {
|
|
183
|
+
controller.abort(new Error('The local control connection closed. An action already sent may still have run.'));
|
|
184
|
+
});
|
|
185
|
+
let nextId = 1;
|
|
186
|
+
return {
|
|
187
|
+
info,
|
|
188
|
+
catalog,
|
|
189
|
+
connection: {
|
|
190
|
+
signal: controller.signal,
|
|
191
|
+
udid: info.session.device.udid,
|
|
192
|
+
async requestAsync(action, params = {}) {
|
|
193
|
+
controller.signal.throwIfAborted();
|
|
194
|
+
if (action === 'actions.describe') {
|
|
195
|
+
return { stdout: JSON.stringify(catalog), stderr: '', exitCode: 0 };
|
|
196
|
+
}
|
|
197
|
+
const id = nextId++;
|
|
198
|
+
await channel.writeAsync({ id, action, params });
|
|
199
|
+
const result = hostActions_1.HostActionReplySchema.parse(await readControlReplyAsync(channel, controlConnectionProtocol_1.CONTROL_REQUEST_TIMEOUT_MS));
|
|
200
|
+
if (result.id !== id) {
|
|
201
|
+
channel.destroy();
|
|
202
|
+
throw new Error('The local control reply did not match the request.');
|
|
203
|
+
}
|
|
204
|
+
if ('error' in result) {
|
|
205
|
+
throw new Error(result.error);
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
},
|
|
209
|
+
close() {
|
|
210
|
+
channel.destroy();
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
channel.destroy();
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function inspectControlConnectionAsync(identity, operation = { operation: 'status' }) {
|
|
221
|
+
const channel = await connectChannelAsync(identity, operation);
|
|
222
|
+
if (!channel) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const info = controlConnectionProtocol_1.ConnectionInfoSchema.parse(await readControlReplyAsync(channel, operation.operation === 'close' ? controlConnectionProtocol_1.CONTROL_LEASE_WAIT_TIMEOUT_MS : undefined, operation.operation === 'close'
|
|
227
|
+
? 'Close could not be confirmed; no simulator action was sent.'
|
|
228
|
+
: undefined));
|
|
229
|
+
return info;
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
if (operation.operation === 'close' && channel.socket.destroyed) {
|
|
233
|
+
throw new Error('Close could not be confirmed; no simulator action was sent.', {
|
|
234
|
+
cause: error,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
channel.destroy();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async function openControlConnectionAsync(identity, load, idleTimeoutMs, workerPath = node_path_1.default.join(__dirname, 'controlConnectionWorker.js')) {
|
|
244
|
+
assertControlKeepAliveSupported();
|
|
245
|
+
return await withControlConnectionLockAsync(identity, async () => {
|
|
246
|
+
const existing = await inspectControlConnectionAsync(identity, {
|
|
247
|
+
operation: 'status',
|
|
248
|
+
...(idleTimeoutMs !== undefined ? { idleTimeoutMs } : {}),
|
|
249
|
+
});
|
|
250
|
+
if (existing) {
|
|
251
|
+
return existing;
|
|
252
|
+
}
|
|
253
|
+
if (await hasControlSocketAsync(identity)) {
|
|
254
|
+
await fs.unlink(identity.socketPath);
|
|
255
|
+
}
|
|
256
|
+
const bootstrap = await load();
|
|
257
|
+
const env = {};
|
|
258
|
+
for (const key of [
|
|
259
|
+
'PATH',
|
|
260
|
+
'HOME',
|
|
261
|
+
'USER',
|
|
262
|
+
'LOGNAME',
|
|
263
|
+
'TMPDIR',
|
|
264
|
+
'LANG',
|
|
265
|
+
'LC_ALL',
|
|
266
|
+
'EXPO_STAGING',
|
|
267
|
+
'EXPO_LOCAL',
|
|
268
|
+
'https_proxy',
|
|
269
|
+
'NODE_EXTRA_CA_CERTS',
|
|
270
|
+
]) {
|
|
271
|
+
if (process.env[key] !== undefined) {
|
|
272
|
+
env[key] = process.env[key];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const child = (0, node_child_process_1.fork)(workerPath, [], {
|
|
276
|
+
detached: true,
|
|
277
|
+
stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
278
|
+
execArgv: [],
|
|
279
|
+
env,
|
|
280
|
+
cwd: node_os_1.default.homedir(),
|
|
281
|
+
});
|
|
282
|
+
try {
|
|
283
|
+
return await new Promise((resolve, reject) => {
|
|
284
|
+
const timer = setTimeout(() => {
|
|
285
|
+
finish(new Error('The control helper did not become ready in time.'));
|
|
286
|
+
}, controlConnectionProtocol_1.CONTROL_BOOTSTRAP_TIMEOUT_MS);
|
|
287
|
+
const finish = (result) => {
|
|
288
|
+
clearTimeout(timer);
|
|
289
|
+
child.removeListener('error', onError);
|
|
290
|
+
child.removeListener('exit', onExit);
|
|
291
|
+
child.removeListener('message', onMessage);
|
|
292
|
+
result instanceof Error ? reject(result) : resolve(result);
|
|
293
|
+
};
|
|
294
|
+
const onError = () => {
|
|
295
|
+
finish(new Error('Could not start the local control helper.'));
|
|
296
|
+
};
|
|
297
|
+
const onExit = () => {
|
|
298
|
+
finish(new Error('The local control helper exited during setup.'));
|
|
299
|
+
};
|
|
300
|
+
const onMessage = (message) => {
|
|
301
|
+
const error = zod_1.z.object({ error: zod_1.z.string() }).safeParse(message);
|
|
302
|
+
if (error.success) {
|
|
303
|
+
finish(new Error(error.data.error));
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
const ready = zod_1.z
|
|
307
|
+
.object({ ready: zod_1.z.literal(true), info: controlConnectionProtocol_1.ConnectionInfoSchema })
|
|
308
|
+
.safeParse(message);
|
|
309
|
+
if (ready.success) {
|
|
310
|
+
finish(ready.data.info);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
child.once('error', onError);
|
|
315
|
+
child.once('exit', onExit);
|
|
316
|
+
child.on('message', onMessage);
|
|
317
|
+
child.send({
|
|
318
|
+
identity,
|
|
319
|
+
bootstrap,
|
|
320
|
+
idleTimeoutMs,
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
326
|
+
child.kill();
|
|
327
|
+
}
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
if (child.connected) {
|
|
332
|
+
child.disconnect();
|
|
333
|
+
}
|
|
334
|
+
child.unref();
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Socket } from 'node:net';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { DeviceRunSessionStatus } from '../graphql/generated';
|
|
4
|
+
export declare const CONTROL_CONNECTION_VERSION = 3;
|
|
5
|
+
export declare const DEFAULT_CONTROL_IDLE_TIMEOUT_MS = 120000;
|
|
6
|
+
export declare const CONTROL_SETUP_TIMEOUT_MS = 10000;
|
|
7
|
+
export declare const CONTROL_BOOTSTRAP_TIMEOUT_MS = 240000;
|
|
8
|
+
export declare const CONTROL_REQUEST_TIMEOUT_MS = 145000;
|
|
9
|
+
export declare const CONTROL_LEASE_WAIT_TIMEOUT_MS = 30000;
|
|
10
|
+
export declare const MAX_CONTROL_FRAME_BYTES: number;
|
|
11
|
+
export declare const ControlSessionSchema: z.ZodObject<{
|
|
12
|
+
id: z.ZodString;
|
|
13
|
+
name: z.ZodNullable<z.ZodString>;
|
|
14
|
+
project: z.ZodString;
|
|
15
|
+
status: z.ZodEnum<typeof DeviceRunSessionStatus>;
|
|
16
|
+
device: z.ZodObject<{
|
|
17
|
+
udid: z.ZodString;
|
|
18
|
+
name: z.ZodOptional<z.ZodString>;
|
|
19
|
+
runtime: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export type ControlSession = z.infer<typeof ControlSessionSchema>;
|
|
23
|
+
export declare const ConnectionInfoSchema: z.ZodObject<{
|
|
24
|
+
version: z.ZodLiteral<3>;
|
|
25
|
+
pid: z.ZodNumber;
|
|
26
|
+
session: z.ZodObject<{
|
|
27
|
+
id: z.ZodString;
|
|
28
|
+
name: z.ZodNullable<z.ZodString>;
|
|
29
|
+
project: z.ZodString;
|
|
30
|
+
status: z.ZodEnum<typeof DeviceRunSessionStatus>;
|
|
31
|
+
device: z.ZodObject<{
|
|
32
|
+
udid: z.ZodString;
|
|
33
|
+
name: z.ZodOptional<z.ZodString>;
|
|
34
|
+
runtime: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
idleTimeoutMs: z.ZodNumber;
|
|
38
|
+
idleDeadline: z.ZodNullable<z.ZodNumber>;
|
|
39
|
+
busy: z.ZodBoolean;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export type ControlConnectionInfo = z.infer<typeof ConnectionInfoSchema>;
|
|
42
|
+
export declare const ConnectionOperationSchema: z.ZodObject<{
|
|
43
|
+
operation: z.ZodEnum<{
|
|
44
|
+
status: "status";
|
|
45
|
+
close: "close";
|
|
46
|
+
lease: "lease";
|
|
47
|
+
}>;
|
|
48
|
+
idleTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
}, z.core.$strict>;
|
|
50
|
+
export type ConnectionOperation = z.infer<typeof ConnectionOperationSchema>;
|
|
51
|
+
export declare class ControlConnectionChannel {
|
|
52
|
+
readonly socket: Socket;
|
|
53
|
+
private readonly decoder;
|
|
54
|
+
private fragments;
|
|
55
|
+
private frameBytes;
|
|
56
|
+
private queued;
|
|
57
|
+
private failure;
|
|
58
|
+
private reader;
|
|
59
|
+
constructor(socket: Socket);
|
|
60
|
+
private fail;
|
|
61
|
+
destroy(error?: Error): void;
|
|
62
|
+
readAsync(timeoutMs?: number, timeoutMessage?: string): Promise<unknown>;
|
|
63
|
+
writeAsync(value: unknown): Promise<void>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ControlConnectionChannel = exports.ConnectionOperationSchema = exports.ConnectionInfoSchema = exports.ControlSessionSchema = exports.MAX_CONTROL_FRAME_BYTES = exports.CONTROL_LEASE_WAIT_TIMEOUT_MS = exports.CONTROL_REQUEST_TIMEOUT_MS = exports.CONTROL_BOOTSTRAP_TIMEOUT_MS = exports.CONTROL_SETUP_TIMEOUT_MS = exports.DEFAULT_CONTROL_IDLE_TIMEOUT_MS = exports.CONTROL_CONNECTION_VERSION = void 0;
|
|
4
|
+
const node_string_decoder_1 = require("node:string_decoder");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const generated_1 = require("../graphql/generated");
|
|
7
|
+
exports.CONTROL_CONNECTION_VERSION = 3;
|
|
8
|
+
exports.DEFAULT_CONTROL_IDLE_TIMEOUT_MS = 120_000;
|
|
9
|
+
exports.CONTROL_SETUP_TIMEOUT_MS = 10_000;
|
|
10
|
+
exports.CONTROL_BOOTSTRAP_TIMEOUT_MS = 240_000;
|
|
11
|
+
exports.CONTROL_REQUEST_TIMEOUT_MS = 145_000;
|
|
12
|
+
exports.CONTROL_LEASE_WAIT_TIMEOUT_MS = 30_000;
|
|
13
|
+
// Preserve replies supported by the remote WebSocket's 100 MiB payload limit.
|
|
14
|
+
exports.MAX_CONTROL_FRAME_BYTES = 128 * 1024 * 1024;
|
|
15
|
+
exports.ControlSessionSchema = zod_1.z.object({
|
|
16
|
+
id: zod_1.z.string().min(1),
|
|
17
|
+
name: zod_1.z.string().nullable(),
|
|
18
|
+
project: zod_1.z.string(),
|
|
19
|
+
status: zod_1.z.enum(generated_1.DeviceRunSessionStatus),
|
|
20
|
+
device: zod_1.z.object({
|
|
21
|
+
udid: zod_1.z.string().min(1),
|
|
22
|
+
name: zod_1.z.string().optional(),
|
|
23
|
+
runtime: zod_1.z.string().optional(),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
exports.ConnectionInfoSchema = zod_1.z.object({
|
|
27
|
+
version: zod_1.z.literal(exports.CONTROL_CONNECTION_VERSION),
|
|
28
|
+
pid: zod_1.z.number().int().positive(),
|
|
29
|
+
session: exports.ControlSessionSchema,
|
|
30
|
+
idleTimeoutMs: zod_1.z.number().int().positive(),
|
|
31
|
+
idleDeadline: zod_1.z.number().nullable(),
|
|
32
|
+
busy: zod_1.z.boolean(),
|
|
33
|
+
});
|
|
34
|
+
exports.ConnectionOperationSchema = zod_1.z.strictObject({
|
|
35
|
+
operation: zod_1.z.enum(['lease', 'status', 'close']),
|
|
36
|
+
idleTimeoutMs: zod_1.z.number().int().min(1_000).max(86_400_000).optional(),
|
|
37
|
+
});
|
|
38
|
+
// Pull one bounded JSON frame at a time. Closing a client discards queued input,
|
|
39
|
+
// so disconnected callers cannot leave another action waiting to execute.
|
|
40
|
+
class ControlConnectionChannel {
|
|
41
|
+
socket;
|
|
42
|
+
decoder = new node_string_decoder_1.StringDecoder('utf8');
|
|
43
|
+
fragments = [];
|
|
44
|
+
frameBytes = 0;
|
|
45
|
+
queued = [];
|
|
46
|
+
failure;
|
|
47
|
+
reader;
|
|
48
|
+
constructor(socket) {
|
|
49
|
+
this.socket = socket;
|
|
50
|
+
socket.on('data', chunk => {
|
|
51
|
+
try {
|
|
52
|
+
const text = this.decoder.write(chunk);
|
|
53
|
+
let start = 0;
|
|
54
|
+
while (start < text.length) {
|
|
55
|
+
const newline = text.indexOf('\n', start);
|
|
56
|
+
const fragment = text.slice(start, newline === -1 ? text.length : newline);
|
|
57
|
+
this.frameBytes += Buffer.byteLength(fragment);
|
|
58
|
+
if (this.frameBytes > exports.MAX_CONTROL_FRAME_BYTES) {
|
|
59
|
+
throw new Error('Local control message is too large.');
|
|
60
|
+
}
|
|
61
|
+
this.fragments.push(fragment);
|
|
62
|
+
if (newline === -1) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
const value = JSON.parse(this.fragments.join(''));
|
|
66
|
+
this.fragments = [];
|
|
67
|
+
this.frameBytes = 0;
|
|
68
|
+
start = newline + 1;
|
|
69
|
+
if (this.reader) {
|
|
70
|
+
const reader = this.reader;
|
|
71
|
+
this.reader = undefined;
|
|
72
|
+
reader.resolve(value);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (this.queued.length >= 8) {
|
|
76
|
+
throw new Error('Too many pending local control messages.');
|
|
77
|
+
}
|
|
78
|
+
this.queued.push(value);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
this.destroy(new Error('Invalid or oversized local control message.'));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
socket.on('error', error => {
|
|
87
|
+
this.fail(error);
|
|
88
|
+
});
|
|
89
|
+
socket.on('end', () => {
|
|
90
|
+
this.destroy(new Error('Local control caller disconnected.'));
|
|
91
|
+
});
|
|
92
|
+
socket.on('close', () => {
|
|
93
|
+
this.fail(new Error('Local control connection closed. An action already sent may still have run.'));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
fail(error) {
|
|
97
|
+
this.failure ??= error;
|
|
98
|
+
this.fragments = [];
|
|
99
|
+
this.frameBytes = 0;
|
|
100
|
+
this.queued = [];
|
|
101
|
+
this.reader?.reject(this.failure);
|
|
102
|
+
this.reader = undefined;
|
|
103
|
+
}
|
|
104
|
+
destroy(error = new Error('Local control connection closed.')) {
|
|
105
|
+
this.fail(error);
|
|
106
|
+
this.socket.destroy();
|
|
107
|
+
}
|
|
108
|
+
async readAsync(timeoutMs = exports.CONTROL_SETUP_TIMEOUT_MS, timeoutMessage = 'Local control connection timed out. An action already sent may still have run.') {
|
|
109
|
+
if (this.failure) {
|
|
110
|
+
throw this.failure;
|
|
111
|
+
}
|
|
112
|
+
if (this.queued.length) {
|
|
113
|
+
return this.queued.shift();
|
|
114
|
+
}
|
|
115
|
+
if (this.reader) {
|
|
116
|
+
throw new Error('A local control reply is already pending.');
|
|
117
|
+
}
|
|
118
|
+
return await new Promise((resolve, reject) => {
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
this.destroy(new Error(timeoutMessage));
|
|
121
|
+
}, timeoutMs);
|
|
122
|
+
this.reader = {
|
|
123
|
+
resolve: value => {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
resolve(value);
|
|
126
|
+
},
|
|
127
|
+
reject: error => {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
reject(error);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async writeAsync(value) {
|
|
135
|
+
if (this.failure) {
|
|
136
|
+
throw this.failure;
|
|
137
|
+
}
|
|
138
|
+
const text = JSON.stringify(value) + '\n';
|
|
139
|
+
if (Buffer.byteLength(text) > exports.MAX_CONTROL_FRAME_BYTES) {
|
|
140
|
+
throw new Error('Local control message is too large.');
|
|
141
|
+
}
|
|
142
|
+
await new Promise((resolve, reject) => {
|
|
143
|
+
const timer = setTimeout(() => {
|
|
144
|
+
const error = new Error('Local control write timed out. An action already sent may still have run.');
|
|
145
|
+
this.destroy(error);
|
|
146
|
+
reject(error);
|
|
147
|
+
}, exports.CONTROL_SETUP_TIMEOUT_MS);
|
|
148
|
+
this.socket.write(text, error => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
error ? reject(error) : resolve();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.ControlConnectionChannel = ControlConnectionChannel;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ControlConnectionIdentity } from './controlConnection';
|
|
2
|
+
import { ControlConnectionInfo } from './controlConnectionProtocol';
|
|
3
|
+
import { HostActionCatalog, HostActionConnection } from './hostActions';
|
|
4
|
+
export declare function serveControlConnectionAsync(identity: ControlConnectionIdentity, session: ControlConnectionInfo['session'], remote: HostActionConnection, catalog: HostActionCatalog, initialIdleTimeoutMs?: number): Promise<{
|
|
5
|
+
closeAsync(): Promise<void>;
|
|
6
|
+
info: ControlConnectionInfo;
|
|
7
|
+
}>;
|