import { logger } from '../logger.js'; /** * Run a provisioning step, log its outcome to console + bot chat, and return * the step's resolved value. * * Options: * - successMessage: text to show on success (defaults to description) * - failureMessage: text to show on failure (defaults to "Error: {description}") * - critical: when true, a failure re-throws so the caller aborts the flow. * Use for steps that everything downstream depends on (e.g. enabling a * new location for Webex Calling — every subsequent Calling API call will * 404 otherwise). Non-critical steps swallow the error and return undefined, * matching legacy behavior so a single flaky API call doesn't abort the * entire provision. */ export async function runStep( bot, description, fn, { successMessage, failureMessage, critical = false } = {}, ) { try { const result = await fn(); const msg = successMessage ?? description; bot?.say('markdown', `
${msg}
`); return result; } catch (error) { logger.error(`${description} failed:`, error); const baseMsg = failureMessage ?? `Error: ${description}`; const msg = critical ? `${baseMsg} — aborting (critical step).` : baseMsg; bot?.say('markdown', `
${msg}
`); if (critical) throw error; return undefined; } }