mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-08 22:48:14 -05:00
fix(import): fix missing blocks in import if undefined keys exist (#2674)
This commit is contained in:
committed by
GitHub
parent
8d15219c12
commit
356b473dc3
@@ -161,6 +161,49 @@ function formatFieldName(fieldName: string): string {
|
|||||||
.join(' ')
|
.join(' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove malformed subBlocks from a block that may have been created by bugs.
|
||||||
|
* This includes subBlocks with:
|
||||||
|
* - Key "undefined" (caused by assigning to undefined key)
|
||||||
|
* - Missing required `id` field
|
||||||
|
* - Type "unknown" (indicates malformed data)
|
||||||
|
*/
|
||||||
|
function removeMalformedSubBlocks(block: any): void {
|
||||||
|
if (!block.subBlocks) return
|
||||||
|
|
||||||
|
const keysToRemove: string[] = []
|
||||||
|
|
||||||
|
Object.entries(block.subBlocks).forEach(([key, subBlock]: [string, any]) => {
|
||||||
|
// Flag subBlocks with invalid keys (literal "undefined" string)
|
||||||
|
if (key === 'undefined') {
|
||||||
|
keysToRemove.push(key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag subBlocks that are null or not objects
|
||||||
|
if (!subBlock || typeof subBlock !== 'object') {
|
||||||
|
keysToRemove.push(key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag subBlocks with type "unknown" (malformed data)
|
||||||
|
if (subBlock.type === 'unknown') {
|
||||||
|
keysToRemove.push(key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag subBlocks missing required id field
|
||||||
|
if (!subBlock.id) {
|
||||||
|
keysToRemove.push(key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Remove the flagged keys
|
||||||
|
keysToRemove.forEach((key) => {
|
||||||
|
delete block.subBlocks[key]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize workflow state by removing all credentials and workspace-specific data
|
* Sanitize workflow state by removing all credentials and workspace-specific data
|
||||||
* This is used for both template creation and workflow export to ensure consistency
|
* This is used for both template creation and workflow export to ensure consistency
|
||||||
@@ -183,6 +226,9 @@ export function sanitizeWorkflowForSharing(
|
|||||||
Object.values(sanitized.blocks).forEach((block: any) => {
|
Object.values(sanitized.blocks).forEach((block: any) => {
|
||||||
if (!block?.type) return
|
if (!block?.type) return
|
||||||
|
|
||||||
|
// First, remove any malformed subBlocks that may have been created by bugs
|
||||||
|
removeMalformedSubBlocks(block)
|
||||||
|
|
||||||
const blockConfig = getBlock(block.type)
|
const blockConfig = getBlock(block.type)
|
||||||
|
|
||||||
// Process subBlocks with config
|
// Process subBlocks with config
|
||||||
|
|||||||
@@ -5,9 +5,14 @@ import type { WorkflowState } from '../workflow/types'
|
|||||||
const logger = createLogger('WorkflowJsonImporter')
|
const logger = createLogger('WorkflowJsonImporter')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize subblock values by converting empty strings to null.
|
* Normalize subblock values by converting empty strings to null and filtering out invalid subblocks.
|
||||||
* This provides backwards compatibility for workflows exported before the null sanitization fix,
|
* This provides backwards compatibility for workflows exported before the null sanitization fix,
|
||||||
* preventing Zod validation errors like "Expected array, received string".
|
* preventing Zod validation errors like "Expected array, received string".
|
||||||
|
*
|
||||||
|
* Also filters out malformed subBlocks that may have been created by bugs in previous exports:
|
||||||
|
* - SubBlocks with key "undefined" (caused by assigning to undefined key)
|
||||||
|
* - SubBlocks missing required fields like `id`
|
||||||
|
* - SubBlocks with `type: "unknown"` (indicates malformed data)
|
||||||
*/
|
*/
|
||||||
function normalizeSubblockValues(blocks: Record<string, any>): Record<string, any> {
|
function normalizeSubblockValues(blocks: Record<string, any>): Record<string, any> {
|
||||||
const normalizedBlocks: Record<string, any> = {}
|
const normalizedBlocks: Record<string, any> = {}
|
||||||
@@ -19,6 +24,34 @@ function normalizeSubblockValues(blocks: Record<string, any>): Record<string, an
|
|||||||
const normalizedSubBlocks: Record<string, any> = {}
|
const normalizedSubBlocks: Record<string, any> = {}
|
||||||
|
|
||||||
Object.entries(block.subBlocks).forEach(([subBlockId, subBlock]: [string, any]) => {
|
Object.entries(block.subBlocks).forEach(([subBlockId, subBlock]: [string, any]) => {
|
||||||
|
// Skip subBlocks with invalid keys (literal "undefined" string)
|
||||||
|
if (subBlockId === 'undefined') {
|
||||||
|
logger.warn(`Skipping malformed subBlock with key "undefined" in block ${blockId}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip subBlocks that are null or not objects
|
||||||
|
if (!subBlock || typeof subBlock !== 'object') {
|
||||||
|
logger.warn(`Skipping invalid subBlock ${subBlockId} in block ${blockId}: not an object`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip subBlocks with type "unknown" (malformed data)
|
||||||
|
if (subBlock.type === 'unknown') {
|
||||||
|
logger.warn(
|
||||||
|
`Skipping malformed subBlock ${subBlockId} in block ${blockId}: type is "unknown"`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip subBlocks missing required id field
|
||||||
|
if (!subBlock.id) {
|
||||||
|
logger.warn(
|
||||||
|
`Skipping malformed subBlock ${subBlockId} in block ${blockId}: missing id field`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const normalizedSubBlock = { ...subBlock }
|
const normalizedSubBlock = { ...subBlock }
|
||||||
|
|
||||||
// Convert empty strings to null for consistency
|
// Convert empty strings to null for consistency
|
||||||
|
|||||||
Reference in New Issue
Block a user