* Fetches collection IDs for a site. If a specific collectionId is provided, * returns only that ID. Otherwise fetches all collections from the site.
( accessToken: string, siteId: string, collectionIds: string[] )
| 372 | * returns only that ID. Otherwise fetches all collections from the site. |
| 373 | */ |
| 374 | async function fetchCollectionIds( |
| 375 | accessToken: string, |
| 376 | siteId: string, |
| 377 | collectionIds: string[] |
| 378 | ): Promise<string[]> { |
| 379 | if (collectionIds.length > 0) { |
| 380 | return collectionIds |
| 381 | } |
| 382 | |
| 383 | const url = `${WEBFLOW_API}/sites/${siteId}/collections` |
| 384 | const response = await fetchWithRetry(url, { |
| 385 | method: 'GET', |
| 386 | headers: { |
| 387 | Authorization: `Bearer ${accessToken}`, |
| 388 | 'accept-version': '2.0.0', |
| 389 | }, |
| 390 | }) |
| 391 | |
| 392 | if (!response.ok) { |
| 393 | throw new Error(`Failed to list Webflow collections: ${response.status}`) |
| 394 | } |
| 395 | |
| 396 | const data = (await response.json()) as { collections: WebflowCollection[] } |
| 397 | return (data.collections || []).map((c) => c.id) |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Fetches a collection's display name, caching in syncContext. |
no test coverage detected