wbxcallprov/src/flows/stepRunner.js
jmcqueen 461caa8086 Consistency + cleanup pass
- Route Twilio Lookup v2 through the on-prem remote agent so all
  third-party calls (SIW, Google, Twilio) share the same network path
  and future IP allow-lists / corp proxies don't break it silently
- Delete unused GOOGLE_APPLICATION_CREDENTIALS / serviceAccountKeyPath
  wiring in config.js, .env.example, and README (never read by any code)
- Extract 150 lines of STORE_DEVICE_CUSTOMIZATIONS out of
  src/webex/devices.js into src/webex/deviceCustomizations.js so device
  config diffs are self-contained and devices.js stays focused on API
- runStep learns a {critical: true} option that re-throws on failure
  instead of the legacy always-swallow behavior; mark
  enableLocationForCalling critical in buildStore + stageStore so a
  failure there aborts the flow cleanly rather than cascading into
  dozens of downstream 404s

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 15:56:01 -04:00

36 lines
1.4 KiB
JavaScript

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', `<blockquote class='success'>${msg}</blockquote>`);
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', `<blockquote class='failure'>${msg}</blockquote>`);
if (critical) throw error;
return undefined;
}
}