| 81 | }; |
| 82 | |
| 83 | async function createCliSession(apiUrl: string, verifier: string): Promise<CreateSessionResponse> { |
| 84 | const res = await fetch(`${apiUrl}/cli-sessions`, { |
| 85 | method: "POST", |
| 86 | headers: { "Content-Type": "application/json" }, |
| 87 | body: JSON.stringify({ verifier }), |
| 88 | }); |
| 89 | if (!res.ok) { |
| 90 | throw new Error(`Failed to start CLI session (HTTP ${res.status})`); |
| 91 | } |
| 92 | return (await res.json()) as CreateSessionResponse; |
| 93 | } |
| 94 | |
| 95 | async function pollForApiKey(apiUrl: string, sessionId: string, verifier: string): Promise<string> { |
| 96 | const deadline = Date.now() + POLL_TIMEOUT_MS; |