* Fetches the form structure via the Forms API. Returns null on 404 (form * deleted or inaccessible).
( accessToken: string, formId: string )
| 194 | * deleted or inaccessible). |
| 195 | */ |
| 196 | async function fetchFormStructure( |
| 197 | accessToken: string, |
| 198 | formId: string |
| 199 | ): Promise<FormStructure | null> { |
| 200 | const url = `${FORMS_API_BASE}/forms/${encodeURIComponent(formId)}` |
| 201 | const response = await fetchWithRetry(url, { |
| 202 | method: 'GET', |
| 203 | headers: { |
| 204 | Authorization: `Bearer ${accessToken}`, |
| 205 | Accept: 'application/json', |
| 206 | }, |
| 207 | }) |
| 208 | |
| 209 | if (!response.ok) { |
| 210 | if (response.status === 404) return null |
| 211 | throw new Error(`Failed to fetch form structure ${formId}: ${response.status}`) |
| 212 | } |
| 213 | |
| 214 | return (await response.json()) as FormStructure |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Result of fetching a form's responses: the collected responses (capped at |
no test coverage detected