Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from '@/features/workflow-builder/hooks/useWorkflowGraphControllers';
import type { FrontendNodeData } from '@/schemas/node';
import type { Node as ReactFlowNode, Edge as ReactFlowEdge } from 'reactflow';
import { useSecretStore } from '@/store/secretStore';
import { useComponentStore } from '@/store/componentStore';
interface WorkflowMetadataShape {
id: string | null;
name: string;
Expand Down Expand Up @@ -98,6 +100,52 @@ export function useWorkflowImportExport({
const normalizedNodes = deserializeNodes(workflowGraph);
const normalizedEdges = deserializeEdges(workflowGraph);

// Validate secret references
try {
await useSecretStore.getState().fetchSecrets();
const secrets = useSecretStore.getState().secrets;
const secretIds = new Set(secrets.map((s) => s.id));

const componentStore = useComponentStore.getState();
if (Object.keys(componentStore.components).length === 0) {
await componentStore.fetchComponents();
}
const components = useComponentStore.getState().components;

normalizedNodes.forEach((node) => {
const data = node.data as FrontendNodeData;
const componentRef = data.componentId || data.componentSlug;
if (!componentRef) return;

const component =
componentStore.getComponent(componentRef) ||
Object.values(components).find((c) => c.slug === componentRef);

if (!component || !component.parameters) return;

// Find parameters that are secrets
const secretParams = component.parameters.filter((p) => p.type === 'secret');
const configParams = node.data.config.params || {};

secretParams.forEach((param) => {
const val = configParams[param.id];
// If value is a string (ID) and not in available secrets, remove it
if (typeof val === 'string' && val.trim().length > 0) {
if (!secretIds.has(val)) {
console.warn(
`[Import] Removing invalid secret reference for param "${param.id}" in node "${node.id}" (secret ID: ${val})`,
);
// Set to undefined to clear it
configParams[param.id] = undefined;
}
}
});
});
} catch (error) {
console.error('Failed to validate secrets during import:', error);
// Continue with import even if validation fails
}

resetWorkflow();
setDesignNodes(normalizedNodes);
setDesignEdges(normalizedEdges);
Expand Down