/** * Choosing the destination number for the manual scripts. * * 555-01xx numbers are reserved as fictional and do not exist, so they are a * fine placeholder for the console adapter and a guaranteed failure against the * real API: Twilio validates the destination even under test credentials and * answers "The 'To' number ... is not a valid phone number." */ import { missingTwilioConfig } from "../src/services/smsService.js"; import { normalizePhoneNumber } from "../src/util/smsPhoneNumber.js"; export const FICTIONAL_PLACEHOLDER = "+15555550123"; export function twilioIsConfigured(): boolean { return missingTwilioConfig().length === 0; } /** * Resolves the destination, or explains why the placeholder cannot be used. * Exits rather than spending a round trip discovering it at the provider. */ export function resolveTarget(explicit: string | undefined, envVar: string): string { const raw = explicit ?? process.env[envVar]; const normalized = normalizePhoneNumber(raw ?? FICTIONAL_PLACEHOLDER); if (normalized === undefined) { console.error(`Not a phone number: ${raw}`); process.exit(1); } if (twilioIsConfigured() && normalized === FICTIONAL_PLACEHOLDER) { console.error( `Twilio is configured, so the destination has to be a number Twilio can\n` + `validate. ${FICTIONAL_PLACEHOLDER} is a reserved fictional number and is\n` + `rejected with error 21211, even under test credentials.\n\n` + `Pass a real number instead — your own is the obvious choice:\n\n` + ` ${envVar}=+15551234567 pnpm run