Skip to content

Sync Model Library to Webflow CMS via Data API#21

Merged
williamw merged 21 commits intomasterfrom
billw/MKT-107-webflow-models-sync
Mar 23, 2026
Merged

Sync Model Library to Webflow CMS via Data API#21
williamw merged 21 commits intomasterfrom
billw/MKT-107-webflow-models-sync

Conversation

@williamw
Copy link
Contributor

  • Replaces models.json file output with direct Webflow CMS sync via the Data API
  • Renames workflow from "Fetch Model Garden" to "Sync Model Library"
  • Adds Webflow API client with auto-detection of live vs staged endpoints and batch chunking
  • Adds dry run mode and environment toggle (test/production) to the workflow
  • Adds unit tests for field mapping and diff logic (10 tests)
  • Removes data/models.json, data/images/, and the git commit step from the workflow

Notes

  • The script auto-detects whether /items/live endpoints are available (they 404 on sites that have never been published). Falls back to staged endpoints + publish, with graceful handling if publish also 404s.
  • Base64 logo uploads are skipped on subsequent runs if the model already has a logo in Webflow. URL-based logos always pass through for Webflow to re-evaluate.
  • Scheduled (cron) runs target production by default. Manual dispatch defaults to test.

Changes

Scripts

File Change
scripts/fetch-models.js Updated — rewritten as three-phase sync pipeline (fetch → diff → sync) using composed method pattern
scripts/webflow-api.js New — Webflow Data API v2 client with collections, items CRUD, asset upload, live/staged auto-detection

Tests

File Change
tests/fetch-models/transform.test.js New — 4 tests for buildWebflowFields (field mapping, defaults, fallbacks)
tests/fetch-models/diff.test.js New — 6 tests for diffModels (create, update, delete, unchanged, logo skip, empty/undefined equivalence)

Workflow

File Change
.github/workflows/fetch-models.yml Updated — renamed to Sync Model Library, added environment toggle and dry run, removed git commit step

Removed

File Change
data/models.json Removed — replaced by Webflow CMS as source of truth
data/images/flux2.svg Removed — logos now uploaded to Webflow Assets API or passed as URLs
data/images/smollm-135m-instruct-fp32.png Removed — same as above

williamw and others added 20 commits March 20, 2026 16:04
Design for modifying fetch-models.js to sync model data directly
to Webflow CMS instead of writing models.json. Covers batch diff
sync, logo upload via Assets API, and configurable site targeting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix MODULAR_CLOUD_ORG type (Var, not Secret)
- Expand Asset API upload to full two-step flow with request shapes
- Add batch size limits (100 items max) and chunking note
- Clarify publish scope (created + updated only, not deleted)
- Add collection slug discovery (models-categories, models)
- Define slug handling for models and categories
- Fix workflow config: use environment choice input instead of
  broken dynamic secret lookup
- Add image diff strategy (skip logo in comparison)
- Note undefined field handling
- Add MIME_TO_EXT to removal list

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7 tasks covering: schema migration, Webflow API client, transform/diff
logic with tests, main script rewrite, workflow update, cleanup, and
integration testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix createItems payload: wrap in {items: [{fieldData}, ...]}
- Fix deleteItems payload: use {itemIds: [...]} not {items: [{id}]}
- Add chunk() utility for >100 item batching
- Add defensive asset URL property check (hostedUrl/url/assetUrl)
- Add missing test cases: name fallback, unknown modalities
- Document cron runs target test site by default
- Add transitional state note for Task 2
- Note about test:unit vs Playwright tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove git commit/push step (no more models.json writes)
- Remove contents:write permission (not needed)
- Add WEBFLOW_API_TOKEN and WEBFLOW_SITE_ID env vars
- Use TEST_WEBFLOW_API_TOKEN secret and TEST_WEBFLOW_SITE_ID var
- Rename job from fetch to sync
- Rename workflow to Sync Model Library
- Add environment choice input (test/production) with
  TEST_ and PROD_ prefixed secrets/vars
- Add dry run checkbox that shows changes without pushing
- Scheduled runs default to test environment
- logo-image -> logo
- categories -> modalities
- models-categories -> models-category
- description: remove <p> wrapping (PlainText, not RichText)
All create/update/delete operations now use /items/live endpoints
which publish immediately, eliminating the separate publish step.
Sites that have never been published return 404 on /items/live.
The client now probes with a GET request and caches the result
per collection. If live isn't available, uses staged endpoints
and publishes after create/update.
fetch-models.js:
- main() reads as a story: fetch, discover, sync categories,
  build field data, diff, apply changes
- Dry-run gate in one place (main), not scattered across helpers
- Renamed: transformModel -> normalizeApiModel,
  toWebflowFields -> buildWebflowFields,
  SKIP_DIFF_FIELDS -> FIELDS_MANAGED_OUTSIDE_DIFF
- resolveLogo split into isUrl/isBase64DataUri/buildLogoField/
  uploadBase64Logo/parseBase64DataUri
- Extracted: fetchModels, discoverCollections, fetchExistingItems,
  buildModelFieldData, applyChanges, logDryRunSummary, logSyncSummary

webflow-api.js:
- Renamed live/suffix -> useLiveEndpoint/liveSuffix
- Documented asset URL fallback
@williamw williamw self-assigned this Mar 23, 2026
@williamw williamw marked this pull request as ready for review March 23, 2026 16:17
…ow-models-sync

# Conflicts:
#	data/models.json
@williamw williamw merged commit bbc7778 into master Mar 23, 2026
1 of 2 checks passed
@williamw williamw deleted the billw/MKT-107-webflow-models-sync branch March 24, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant