Repository navigation
Expand file tree
/
Copy pathplugin.ts
More file actions
58 lines (57 loc) · 2.08 KB
/
Copy pathplugin.ts
File metadata and controls
58 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { ProviderPluginHost } from 'agent-device/plugins';
import { verifyDoublespeedConnection } from './connection-verification.ts';
import type { CliFlags } from '@agent-device/contracts/command';
export default async function doublespeedPlugin(host: ProviderPluginHost) {
const { createDoublespeedRuntime } = await import('./runtime.ts');
const apiKey = host.env.DOUBLESPEED_API_KEY?.trim() ?? '';
const registration = createDoublespeedRuntime(
{
apiKey,
apiUrl: host.env.DOUBLESPEED_API_URL?.trim() || undefined,
device: host.env.DOUBLESPEED_DEVICE?.trim() || undefined,
},
{ clientVersion: host.clientVersion, host: host.apple, ios: host.apple },
{ includePlatformModule: true },
);
return {
...registration,
connection: {
resolve: ({ flags }: { flags: CliFlags }) => {
if (!apiKey)
throw host.createError(
'INVALID_ARGS',
'connect doublespeed requires DOUBLESPEED_API_KEY.',
);
if (flags.platform !== undefined && flags.platform !== 'ios')
throw host.createError(
'INVALID_ARGS',
'connect doublespeed supports --platform ios only.',
);
if (flags.device !== undefined)
throw host.createError(
'INVALID_ARGS',
'connect doublespeed does not accept --device; set DOUBLESPEED_DEVICE to pick the simulator model.',
);
if (flags.leaseBackend !== undefined && flags.leaseBackend !== 'ios-instance')
throw host.createError(
'INVALID_ARGS',
'connect doublespeed requires --lease-backend ios-instance.',
);
return {
profile: {
leaseProvider: 'doublespeed',
leaseBackend: 'ios-instance',
platform: 'ios',
daemonTransport: 'auto',
} as const,
};
},
verify: async () =>
await verifyDoublespeedConnection({
apiKey,
apiUrl: host.env.DOUBLESPEED_API_URL?.trim() || undefined,
clientVersion: host.clientVersion,
}),
},
};
}