feat: save variable and style references for Studio projects#3867
Conversation
- Extend ThemeObject with $themeGroupId and $themeOptionId for server-side UUID caching - Fix REST read: source figma_variable_references from theme group (not option) - Add PATCH helpers for variable refs (group) and style refs (option) - Add resolveChangeSetId helper for branch-aware writes - Wire tokenState middleware for TOKENS_STUDIO_OAUTH provider (refs-only actions) - Add unit tests for PATCH helpers and orchestrator (14 tests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 57cc01d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
|
Commit SHA:eb7e63bae81daadffb986da3064cce7d2371985c Test coverage results 🧪
|
|
Commit SHA:eb7e63bae81daadffb986da3064cce7d2371985c |
There was a problem hiding this comment.
Pull request overview
Adds REST/OAuth round-trip persistence for Figma variable/style reference maps when syncing against Studio-on-Rails projects, aligning REST behavior with the existing GQL sync path.
Changes:
- Fetches variable references from theme groups (REST model) and stores REST server IDs on
ThemeObjectfor targeted writes. - Introduces REST PATCH helpers plus middleware wiring to persist ref mutations back to the server.
- Adds unit tests for the new REST PATCH helpers and the ref-update orchestration.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/tokens-studio-for-figma/src/utils/tokensStudio/updateThemeRefsViaRestApi.ts | Diffs theme refs and PATCHes variable/style refs over REST for OAuth projects. |
| packages/tokens-studio-for-figma/src/utils/tokensStudio/updateThemeRefsViaRestApi.test.ts | Unit tests for the diff-and-patch orchestration. |
| packages/tokens-studio-for-figma/src/utils/tokensStudio/pushThemeRefsRest.ts | REST PATCH helpers for theme group/option ref persistence. |
| packages/tokens-studio-for-figma/src/utils/tokensStudio/pushThemeRefsRest.test.ts | Unit tests for the REST PATCH helpers. |
| packages/tokens-studio-for-figma/src/utils/tokensStudio/fetchProjectDataRest.ts | Fixes REST read path: variable refs come from theme groups; stores $themeGroupId/$themeOptionId. |
| packages/tokens-studio-for-figma/src/utils/tokensStudio/fetchBranchesListRest.ts | Adds resolveChangeSetId helper for re-resolving branch change set before writes. |
| packages/tokens-studio-for-figma/src/types/ThemeObject.ts | Adds optional REST server ID fields to ThemeObject. |
| packages/tokens-studio-for-figma/src/storage/schemas/themeObjectSchema.ts | Extends theme schema to allow the new REST server ID fields. |
| packages/tokens-studio-for-figma/src/app/store/middlewares/tokenState.ts | Triggers REST ref persistence for OAuth provider ref-mutation actions. |
| .changeset/theme-refs-round-trip.md | Changeset for releasing the feature. |
…cross theme options
…ite in-place mutations
|
🛡️ Hyma Compliance Check
Full finding details[ROPA] New REST API calls from Figma plugin to Studio-on-Rails backend
|
🛡️ Hyma Compliance Check — 2026-06-22Automated review against GDPR, SOC 2, and Hyma internal policy. 🟡 MEDIUM — ROPA: New data flow — Figma plugin sends variable/style references to Studio backendFiles: This PR establishes a new authenticated REST data flow: the Figma plugin now sends Data transferred:
Authentication: OAuth Bearer token from the Figma plugin's Studio connection. Risk:
Recommended action:
Taxonomy: ROPA | Severity: MEDIUM |
|
🛡️ Hyma Compliance Check
Full finding details[Subprocessor] New outbound PATCH write-path expands data sent to the Studio-on-Rails backend (previously read-only)
[Access Control] OAuth bearer token sent on new write endpoints with per-write change_set_id (branch) re-resolution
|
|
🛡️ Hyma Compliance Check
Full finding details[ROPA] New REST API calls sync Figma variable/style references to Studio-on-Rails
|
Why does this PR exist?
When using the REST/OAuth path to sync with Studio projects (Studio-on-Rails), variable references (
$figmaVariableReferences) and style references ($figmaStyleReferences) were read-only -- changes made in the plugin were never written back to the server. This PR adds round-trip support so these maps are persisted when users update them.Related backend PR: https://github.com/The-Phoenix-Will-Fly/studio-on-rails/pull/2396
What does this pull request do?
Adds write support for Figma variable/style references on the REST/OAuth path:
TOKENS_STUDIO_OAUTH, ref-mutation actions (assign/unassign variable refs, update style refs) now trigger a REST PATCH to persist changes.$themeGroupIdand$themeOptionIdare stored on eachThemeObjectafter the initial fetch so we can target the correct API endpoints on write.change_set_idis re-resolved before each write to handle branch switches between fetch and mutation.Key design decisions:
{}explicitly clears them;nullis never sent."S:key,"form) -- no stripping/re-adding prefixes.Testing this change
Unit tests added (14 new tests):
All existing tokensStudio tests (55) and middleware tests (36) continue to pass.
Manual testing against the preview API (
studio-on-rails-web-5s4z-pr-2396.onrender.com) has not been done yet -- this needs a live Studio project with OAuth configured.Additional Notes (if any)
This is scoped to refs-only sync (Option B). Full OAuth write parity (theme CRUD) is out of scope and can be a follow-up.