Skip to content

feat(import-export): improvements to export workspace, maintain file structure, include workflow variables - #1799

Merged
icecrasher321 merged 4 commits into
stagingfrom
feat/import-export-workspaces
Nov 3, 2025
Merged

feat(import-export): improvements to export workspace, maintain file structure, include workflow variables#1799
icecrasher321 merged 4 commits into
stagingfrom
feat/import-export-workspaces

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

  • Maintain file structure in import/export
  • Add way to export workspaces
  • Include workflow variables in exports / imports

Type of Change

  • New feature

Testing

Tested Manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Nov 3, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedNov 3, 2025 8:06pm

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

This PR adds comprehensive workspace import/export functionality with ZIP file support, folder structure preservation, and workflow variable handling.

Key Changes:

  • Added new import-export.ts module with functions to export workspaces as ZIP files and extract workflows from ZIP/JSON files
  • Extended WorkflowState interface to include metadata and variables fields for proper export/import
  • Updated export sanitization to include workflow metadata (name, description, exportedAt) and variables
  • Refactored import UI to support multiple file formats (ZIP and multiple JSON files) with folder structure recreation
  • Added workspace-level export button for admin users in workspace selector
  • Integrated jszip library (v3.10.1) for ZIP handling

Issues Found:

  • Critical: Variable IDs are regenerated during import using crypto.randomUUID(), which will break references to these variables in block configurations
  • Important: extractWorkflowName function checks incorrect metadata path (parsed.state?.metadata?.name instead of parsed.metadata?.name), causing workflow names to fall back to timestamps

Confidence Score: 2/5

  • This PR has critical logical issues that will cause runtime failures with variable references and incorrect workflow naming
  • The score reflects two significant logical bugs: (1) variable ID regeneration breaks references in block subblocks where variables are used, causing workflows to fail at runtime, and (2) incorrect metadata path lookup causes imported workflows to lose their names. While the architecture is sound and most of the implementation is clean, these issues need resolution before merge.
  • create-menu.tsx (variable ID regeneration issue) and import-export.ts (workflow name extraction bug) require immediate fixes

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/lib/workflows/import-export.ts3/5New file implementing workspace export/import with ZIP support. Contains logical issue with extractWorkflowName function that checks wrong metadata path.
apps/sim/lib/workflows/json-sanitizer.ts5/5Added metadata and variables fields to ExportWorkflowState interface and included them in sanitization logic. Clean implementation.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/create-menu/create-menu.tsx2/5Refactored import logic to support ZIP files, multiple JSON files, and folder structure preservation. Contains critical issue with variable ID regeneration that breaks references.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-selector/workspace-selector.tsx4/5Added workspace export functionality with Download button for admin users. Properly fetches workflows, folders, and variables before exporting.
apps/sim/stores/workflows/json/store.ts5/5Enhanced generateJson to include workflow metadata and variables from the variables store in the export.

Sequence Diagram

sequenceDiagram
participant User
participant WorkspaceSelector
participant CreateMenu
participant ImportExport as import-export.ts
participant Sanitizer as json-sanitizer.ts
participant JsonStore as json/store.ts
participant API
participant FolderStore
participant VariablesAPI
Note over User,VariablesAPI: Export Workflow
User->>WorkspaceSelector: Click Export button
WorkspaceSelector->>API: GET /api/workflows?workspaceId=X
API-->>WorkspaceSelector: Return workflows list
WorkspaceSelector->>API: GET /api/folders?workspaceId=X
API-->>WorkspaceSelector: Return folders list
loop For each workflow
WorkspaceSelector->>API: GET /api/workflows/{id}
API-->>WorkspaceSelector: Return workflow state
WorkspaceSelector->>VariablesAPI: GET /api/workflows/{id}/variables
VariablesAPI-->>WorkspaceSelector: Return workflow variables
end
WorkspaceSelector->>ImportExport: exportWorkspaceToZip(workflows, folders)
ImportExport->>Sanitizer: sanitizeForExport(workflowState)
Sanitizer-->>ImportExport: Sanitized workflow (metadata + variables)
ImportExport->>ImportExport: Build folder structure in ZIP
ImportExport-->>WorkspaceSelector: ZIP blob
WorkspaceSelector->>User: Download ZIP file
Note over User,VariablesAPI: Import Workflows
User->>CreateMenu: Select ZIP/JSON files
CreateMenu->>ImportExport: extractWorkflowsFromZip(zipFile)
ImportExport-->>CreateMenu: workflows[] + metadata
CreateMenu->>FolderStore: createFolder(workspaceName)
FolderStore-->>CreateMenu: importFolder
loop For each workflow
alt Has folder path
CreateMenu->>FolderStore: createFolder(subfolder, parentId)
FolderStore-->>CreateMenu: subfolder id
end
CreateMenu->>ImportExport: extractWorkflowName(content)
ImportExport-->>CreateMenu: workflow name
CreateMenu->>API: POST /api/workflows (create)
API-->>CreateMenu: newWorkflowId
CreateMenu->>API: PUT /api/workflows/{id}/state
API-->>CreateMenu: Success
alt Has variables
CreateMenu->>VariablesAPI: POST /api/workflows/{id}/variables
VariablesAPI-->>CreateMenu: Success
end
end
CreateMenu->>FolderStore: fetchFolders(workspaceId)
CreateMenu->>User: Import complete
Loading

8 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/lib/workflows/import-export.ts
@icecrasher321
icecrasher321 merged commit 2eea3ca into stagingNov 3, 2025
9 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/import-export-workspaces branch November 6, 2025 01:25
waleedlatif1 pushed a commit that referenced this pull request Nov 12, 2025
…structure, include workflow variables (#1799)
* feat(import-export): improvements to export workspace, maintain file structure
* fix type'
* import/export variables
* fix var ref id bug
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto 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

@icecrasher321