Skip to content

Environment Variable Brand Neutralization Plan

Overview

This document outlines the migration strategy for PREGO_* environment variables to brand-neutral alternatives. Due to the high risk of breaking deployed systems, this migration requires careful planning and backward compatibility support.

Current State

High-Usage Variables (> 20 occurrences)

Current NameProposed NameCategoryRisk
PREGO_TRACE_ID_HEADERTRACE_ID_HEADERObservabilityHigh
PREGO_CONTROL_PLANE_URLCONTROL_PLANE_URLInfrastructureHigh
PREGO_JWTAUTH_JWTAuth CookieHigh
PREGO_LOCALELOCALEi18nMedium
PREGO_CONSENT_*CONSENT_*PrivacyMedium
PREGO_AUTH_URLAUTH_URLInfrastructureHigh

Medium-Usage Variables (10-20 occurrences)

Current NameProposed NameCategory
PREGO_COOKIE_*COOKIE_*Cookie Names
PREGO_EIDEIDEvent ID
PREGO_DEVICE_IDDEVICE_IDTracking
PREGO_PENDING_EIDPENDING_EIDEvent ID
PREGO_CONTROL_PLANE_INTERNAL_API_KEYCP_INTERNAL_API_KEYAuth

Low-Usage Variables (< 10 occurrences)

Current NameProposed NameCategory
PREGO_ONBOARDING_*ONBOARDING_*Onboarding
PREGO_DEMO_*DEMO_*Demo Mode
PREGO_SESSIONSESSIONAuth
PREGO_WWW_BASE_URLWWW_BASE_URLInfrastructure
PREGO_JWT_COOKIE_DOMAINJWT_COOKIE_DOMAINAuth
PREGO_ZUPLO_INTERNAL_API_KEYZUPLO_INTERNAL_API_KEYAuth
PREGO_THEMETHEMEUI
PREGO_BILLING_PROXY_URLBILLING_PROXY_URLInfrastructure

Migration Strategy

Phase 1: Add Fallback Support (Low Risk)

For each environment variable, implement a fallback pattern:

// Before
const controlPlaneUrl = process.env.PREGO_CONTROL_PLANE_URL
// After
const controlPlaneUrl = process.env.CONTROL_PLANE_URL
?? process.env.PREGO_CONTROL_PLANE_URL

Implemented in @platform/env-utils (packages/env-utils):

import { getEnvWithFallback, COMMON_ENV_MAPPINGS } from '@platform/env-utils';
// Single variable
const controlPlaneUrl = getEnvWithFallback(
process.env,
'CONTROL_PLANE_URL',
'PREGO_CONTROL_PLANE_URL'
);
// With deprecation warning
import { getEnvWithFallbackAndWarn } from '@platform/env-utils';
const url = getEnvWithFallbackAndWarn(env, 'CONTROL_PLANE_URL', 'PREGO_CONTROL_PLANE_URL');
// Batch resolution using pre-defined mappings
import { resolveEnvMappings, ADMIN_WEB_ENV_MAPPINGS } from '@platform/env-utils';
const resolved = resolveEnvMappings(process.env, ADMIN_WEB_ENV_MAPPINGS);

Phase 2: Update Infrastructure Variables

Order:

  1. CONTROL_PLANE_URL (NEXT_PUBLIC_PREGO_CONTROL_PLANE_URL)
  2. AUTH_URL (NEXT_PUBLIC_PREGO_AUTH_URL)
  3. WWW_BASE_URL (PREGO_WWW_BASE_URL)

Procedure:

  1. Deploy code with fallback support
  2. Update Cloudflare Worker variables to new names
  3. Monitor for errors
  4. Remove legacy variable after 2 weeks

Special consideration: Cookie names affect browser storage. Changing cookie names requires:

  1. Migration script to copy old cookie → new cookie
  2. Extended fallback period (reading both cookies)
  3. Clear old cookies after migration window

Order:

  1. JWT cookie (PREGO_JWT → AUTH_JWT)
  2. LOCALE cookie (PREGO_LOCALE → LOCALE)
  3. CONSENT cookie (PREGO_CONSENT → CONSENT)
  4. THEME cookie (PREGO_THEME → THEME)

Phase 4: Update Client-Side Constants

Browser code changes require:

  1. Version-coordinated deployment (www + client-web + admin-web simultaneously)
  2. Cache invalidation for static assets

Phase 5: Remove Legacy Support

After migration window (recommended: 30 days minimum):

  1. Remove fallback code
  2. Delete legacy environment variables from Cloudflare
  3. Update documentation

Implementation Checklist

  • Create getEnvWithFallback utility — implemented in @platform/env-utils (packages/env-utils/src/index.ts)
  • Add deprecation warnings when legacy names are used — warnLegacyEnvUsage() and getEnvWithFallbackAndWarn() in same package
  • Define environment variable mappings — COMMON_ENV_MAPPINGS, app-specific mappings in packages/env-utils/src/mappings.ts
  • Update @platform/cookies with fallback cookie reading (AUTH_JWT / PREGO_JWT — partial: see apps/admin-web/lib/cookie-header-for-zuplo-upstream.ts)
  • Document new variable names in deployment guides
  • Coordinate deployment timeline with operations team
  • Monitor error rates during migration
  • Adopt @platform/env-utils in apps (admin-web, client-web, www) and workers (control-plane)

Not Changing (HTTP Headers)

The following HTTP header constants will NOT change as they are part of the public API contract:

  • X-Prego-Api-Key (client API key header)
  • X-Prego-Agent-Key (agent API key header)
  • X-Prego-Demo (demo mode header)
  • X-Prego-M-Admin-Login (admin login gate)

These require API versioning and client update coordination, which is out of scope for this phase.

Risk Mitigation

  1. Feature flags: Use feature flags to toggle new vs legacy names
  2. Monitoring: Set up alerts for missing environment variables
  3. Rollback plan: Document steps to revert to legacy names
  4. Communication: Notify operations team 1 week before each phase

Timeline Estimate

PhaseDurationDependencies
Phase 11 weekNone
Phase 22 weeksPhase 1 complete
Phase 32 weeksPhase 2 complete
Phase 41 weekPhase 3 complete
Phase 51 day30 days after Phase 4

Total: ~6-8 weeks (excluding migration window)

Help