/**
 * require-service-url.ts
 *
 * Thomas directive 2026-05-28: eliminate silent localhost fallbacks in production.
 *
 * RULE: In a deployed/production context (`NODE_ENV === 'production'`), a
 * missing service-URL env var must FAIL LOUDLY with a clear message naming the
 * missing variable. Localhost is acceptable ONLY as an explicit local-dev
 * convenience when NODE_ENV is not 'production'.
 *
 * Two exported functions:
 *   - requireServiceUrl(envName, devDefault)
 *       For server-to-server URLs (Category 2: governance-proxy, license-server).
 *       Call this once at startup (module-level or inside loadConfigFromEnv).
 *
 *   - resolveNextPublicUrl(envName, devDefault)
 *       For NEXT_PUBLIC_* browser-side URLs (Category 1: admin-dashboard, dashboard).
 *       Because Next.js inlines env vars at build time, this is used as a
 *       runtime guard — called at module load so a bad build fails loudly on first
 *       request rather than silently hitting localhost.
 *
 * Both functions are identical in behaviour. The two names are aliases that make
 * call-sites self-documenting (server vs browser context).
 *
 * @connexum/ai-governance | CXNI-005 | 2026-05-28
 */
/**
 * Resolve a service URL from an environment variable.
 *
 * - If the env var is set: return its value (even if that value is localhost —
 *   the operator explicitly configured it, which is their prerogative).
 * - If the env var is unset AND NODE_ENV === 'production': throw an informative
 *   ConfigurationError so the broken deployment is caught immediately.
 * - If the env var is unset AND NODE_ENV !== 'production': return devDefault.
 *
 * @param envName    Name of the environment variable (used in error message).
 * @param devDefault URL to return in local-dev/test mode when env var is absent.
 */
export function requireServiceUrl(envName, devDefault) {
    const value = process.env[envName];
    if (value !== undefined) {
        return value;
    }
    if (process.env['NODE_ENV'] === 'production') {
        throw new Error(`[connexum] Missing required environment variable: ${envName}. ` +
            `In production every service URL must be explicitly configured. ` +
            `Set ${envName} to the correct URL before deploying. ` +
            `Refusing to silently fall back to localhost in a production environment.`);
    }
    // Non-production: allow localhost dev default.
    return devDefault;
}
/**
 * Alias of requireServiceUrl for NEXT_PUBLIC_* browser-side URLs.
 * Semantics are identical; the separate name makes call-sites self-documenting.
 */
export const resolveNextPublicUrl = requireServiceUrl;
//# sourceMappingURL=require-service-url.js.map