()
| 3 | import { updateSettings } from '@/persistence' |
| 4 | |
| 5 | export async function authAndSetupMachineIfNeeded(): Promise<{ |
| 6 | token: string |
| 7 | machineId: string |
| 8 | }> { |
| 9 | if (!configuration.cliApiToken) { |
| 10 | throw new Error('CLI_API_TOKEN is required') |
| 11 | } |
| 12 | |
| 13 | const settings = await updateSettings((current) => { |
| 14 | if (!current.machineId) { |
| 15 | return { |
| 16 | ...current, |
| 17 | machineId: randomUUID() |
| 18 | } |
| 19 | } |
| 20 | return current |
| 21 | }) |
| 22 | |
| 23 | if (!settings.machineId) { |
| 24 | throw new Error('Failed to initialize machineId') |
| 25 | } |
| 26 | |
| 27 | return { token: configuration.cliApiToken, machineId: settings.machineId } |
| 28 | } |
| 29 |
no test coverage detected