(wsBase: string, token: string)
| 48 | } else if (url.protocol === 'https:') { |
| 49 | url.protocol = 'wss:'; |
| 50 | } |
| 51 | const query = { ticket } satisfies ConnectTicketQuery; |
| 52 | url.searchParams.set('ticket', query.ticket); |
| 53 | return url.toString(); |
| 54 | } |
| 55 | |
| 56 | async function fetchConnectionTicket(wsBase: string, token: string): Promise<string> { |
| 57 | return withDeadline(CONTROL_PLANE_DEADLINE_MS, async signal => { |
| 58 | const response = await fetch(ticketEndpointFor(wsBase), { |
| 59 | method: 'POST', |
| 60 | headers: { authorization: `Bearer ${token}` }, |
| 61 | signal, |
| 62 | }); |
| 63 | if (response.status === 401 || response.status === 403) { |
| 64 | throw new WebSocketAuthError(); |
| 65 | } |
| 66 | if (!response.ok) { |
| 67 | throw new Error('Failed to mint WebSocket connection ticket'); |
no test coverage detected