* Performs an authenticated GET against the X API v2 and returns the parsed JSON.
( path: string, accessToken: string, params?: Record<string, string>, retryOptions?: Parameters<typeof fetchWithRetry>[2] )
| 131 | * Performs an authenticated GET against the X API v2 and returns the parsed JSON. |
| 132 | */ |
| 133 | async function xApiGet( |
| 134 | path: string, |
| 135 | accessToken: string, |
| 136 | params?: Record<string, string>, |
| 137 | retryOptions?: Parameters<typeof fetchWithRetry>[2] |
| 138 | ): Promise<unknown> { |
| 139 | const queryParams = params ? `?${new URLSearchParams(params).toString()}` : '' |
| 140 | const url = `${X_API_BASE}${path}${queryParams}` |
| 141 | |
| 142 | const response = await fetchWithRetry( |
| 143 | url, |
| 144 | { |
| 145 | method: 'GET', |
| 146 | headers: { |
| 147 | Authorization: `Bearer ${accessToken}`, |
| 148 | 'Content-Type': 'application/json', |
| 149 | }, |
| 150 | }, |
| 151 | retryOptions |
| 152 | ) |
| 153 | |
| 154 | if (!response.ok) { |
| 155 | const body = await response.text().catch(() => '') |
| 156 | throw new Error(`X API HTTP error: ${response.status} ${response.statusText} ${body}`.trim()) |
| 157 | } |
| 158 | |
| 159 | return response.json() |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Resolves the authenticated user's numeric ID via GET /2/users/me. |
no test coverage detected