* Reads the latest response submission time for change detection without * retaining responses. Scans every page — the Forms API does not guarantee * response order, so the newest submission may sit on any page. Returns the * greatest `lastSubmittedTime` (falling back to `createTime`), or undefin
( accessToken: string, formId: string )
| 290 | * `skippedOnError` → `listingCapped`. |
| 291 | */ |
| 292 | async function fetchLatestResponseTime( |
| 293 | accessToken: string, |
| 294 | formId: string |
| 295 | ): Promise<string | undefined> { |
| 296 | let latest = '' |
| 297 | let pageToken: string | undefined |
| 298 | |
| 299 | do { |
| 300 | const url = new URL(`${FORMS_API_BASE}/forms/${encodeURIComponent(formId)}/responses`) |
| 301 | url.searchParams.set('pageSize', String(RESPONSES_PAGE_SIZE)) |
| 302 | if (pageToken) url.searchParams.set('pageToken', pageToken) |
| 303 | |
| 304 | const response = await fetchWithRetry(url.toString(), { |
| 305 | method: 'GET', |
| 306 | headers: { |
| 307 | Authorization: `Bearer ${accessToken}`, |
| 308 | Accept: 'application/json', |
| 309 | }, |
| 310 | }) |
| 311 | |
| 312 | if (!response.ok) { |
| 313 | throw new Error( |
| 314 | `Failed to read responses for change detection on form ${formId}: ${response.status}` |
| 315 | ) |
| 316 | } |
| 317 | |
| 318 | const data = (await response.json()) as FormResponseList |
| 319 | const pageLatest = latestResponseTime(data.responses ?? []) |
| 320 | if (pageLatest && pageLatest > latest) latest = pageLatest |
| 321 | pageToken = data.nextPageToken |
| 322 | } while (pageToken) |
| 323 | |
| 324 | return latest || undefined |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Returns the greatest submission timestamp across the given responses, or |
no test coverage detected