function parseEnvString(envString) { const result = {}; if (!envString) return result; for (const line of envString.split('\n')) { const trimmed = line.trim(); if (!trimmed || trimmed.startsWith('#')) continue; const eqIndex = trimmed.indexOf('='); if (eqIndex === -1) continue; const key = trimmed.slice(0, eqIndex).trim(); const value = trimmed .slice(eqIndex + 1) .trim() .replace(/^["']|["']$/g, ''); result[key] = value; } return result; } function extractPortalMeta(envString, fallbackLabel) { const vars = parseEnvString(envString); const appType = vars.PORTAL_APP_TYPE; if (appType !== 'web' && appType !== 'batch') { return null; } return { appType, label: vars.PORTAL_APP_LABEL || fallbackLabel, url: vars.PORTAL_APP_URL || null, triggerPath: vars.PORTAL_TRIGGER_PATH || null, }; } module.exports = { parseEnvString, extractPortalMeta };