import yaml from 'js-yaml' import type { EnvironmentFile, EnvVariable } from '../types.js' export function parseEnvironment(yamlContent: string): EnvironmentFile { const raw = yaml.load(yamlContent) as Record if (!raw || typeof raw !== 'object') { throw new Error('Invalid environment file — expected an object') } const name = typeof raw.name === 'string' && raw.name.trim() !== '' ? raw.name : 'default' const variables: EnvVariable[] = Array.isArray(raw.variables) ? raw.variables.map((v: Record) => ({ name: String(v.name ?? ''), value: String(v.value ?? ''), enabled: v.enabled !== false, secret: Boolean(v.secret), type: typeof v.type === 'string' ? v.type : 'text', })) : [] return { name, variables } }