( baseUrl: string, path: string, body: unknown, token?: string, timeoutMs = 40_000, signal?: AbortSignal, )
| 34 | } |
| 35 | |
| 36 | async function post<T>( |
| 37 | baseUrl: string, |
| 38 | path: string, |
| 39 | body: unknown, |
| 40 | token?: string, |
| 41 | timeoutMs = 40_000, |
| 42 | signal?: AbortSignal, |
| 43 | ): Promise<T> { |
| 44 | const controller = new AbortController() |
| 45 | const timeout = setTimeout(() => controller.abort(), timeoutMs) |
| 46 | |
| 47 | if (signal) { |
| 48 | signal.addEventListener('abort', () => controller.abort(), { once: true }) |
| 49 | } |
| 50 | |
| 51 | try { |
| 52 | const response = await fetch(`${baseUrl}${path}`, { |
| 53 | method: 'POST', |
| 54 | headers: buildHeaders(token), |
| 55 | body: JSON.stringify(body), |
| 56 | signal: controller.signal, |
| 57 | }) |
| 58 | |
| 59 | if (!response.ok) { |
| 60 | throw new Error(`HTTP ${response.status}: ${response.statusText}`) |
| 61 | } |
| 62 | |
| 63 | return (await response.json()) as T |
| 64 | } finally { |
| 65 | clearTimeout(timeout) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | export async function getUpdates( |
| 70 | baseUrl: string, |
no test coverage detected