MCPcopy
hub / github.com/simstudioai/sim / exportWorkspaceToZip

Function exportWorkspaceToZip

apps/sim/lib/workflows/operations/import-export.ts:224–275  ·  view source on GitHub ↗
(
  workspaceName: string,
  workflows: WorkflowExportData[],
  folders: FolderExportData[]
)

Source from the content-addressed store, hash-verified

222}
223
224export async function exportWorkspaceToZip(
225 workspaceName: string,
226 workflows: WorkflowExportData[],
227 folders: FolderExportData[]
228): Promise<Blob> {
229 const JSZip = await getJSZip()
230 const zip = new JSZip()
231 const foldersMap = new Map(folders.map((f) => [f.id, f]))
232
233 const metadata = {
234 workspace: {
235 name: workspaceName,
236 exportedAt: new Date().toISOString(),
237 },
238 folders: folders.map((f) => ({
239 id: f.id,
240 name: f.name,
241 parentId: f.parentId,
242 sortOrder: f.sortOrder,
243 })),
244 }
245
246 zip.file('_workspace.json', JSON.stringify(metadata, null, 2))
247
248 for (const workflow of workflows) {
249 try {
250 const workflowState = {
251 ...workflow.state,
252 metadata: {
253 name: workflow.workflow.name,
254 description: workflow.workflow.description,
255 sortOrder: workflow.workflow.sortOrder,
256 exportedAt: new Date().toISOString(),
257 },
258 variables: workflow.variables,
259 }
260
261 const exportState = sanitizeForExport(workflowState)
262 const sanitizedName = sanitizePathSegment(workflow.workflow.name)
263 const filename = `${sanitizedName}-${workflow.workflow.id}.json`
264
265 const folderPath = buildFolderPath(workflow.workflow.folderId, foldersMap)
266 const fullPath = folderPath ? `${folderPath}/${filename}` : filename
267
268 zip.file(fullPath, JSON.stringify(exportState, null, 2))
269 } catch (error) {
270 logger.error(`Failed to export workflow ${workflow.workflow.id}:`, error)
271 }
272 }
273
274 return await zip.generateAsync({ type: 'blob' })
275}
276
277/**
278 * Export a folder and its contents to a ZIP file.

Callers 1

route.tsFile · 0.90

Calls 5

sanitizeForExportFunction · 0.90
getJSZipFunction · 0.85
sanitizePathSegmentFunction · 0.85
buildFolderPathFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected