change cloud feature flags to be loaded dynamically at runtime rather than set in build (#6246)

## Summary

Implements server-side remote configuration to decouple runtime behavior
from build artifacts, enabling dynamic configuration updates without
redeployment.

## Technical Changes

- **Replaced** build-time constants (`__MIXPANEL_TOKEN__`,
`__BUILD_FLAGS__`) with runtime configuration loaded from
`/api/features`
- Configuration now sourced from `window.__CONFIG__` (hydrated from
`/api/features` endpoint)
- **Added** `src/platform/remoteConfig/` service that polls server
configuration every 30 seconds
- **Modified** application bootstrap sequence in `main.ts` to load
remote config before module initialization (required for cloud builds)
- **Removed** global constants: `__BUILD_FLAGS__`, `__MIXPANEL_TOKEN__`.
Runtime subscription enforcement toggle via `subscription_required` flag
- Server health alerts with variant-based severity rendering
(info/warning/error) via topbar badges

## Rationale

- **Build-once-deploy-anywhere**: Single immutable artifact promoted
through environments (staging → production)
- **Zero-downtime configuration**: Update behavior without rebuilding or
redeploying the application
- **Incident response**: Disable features or display alerts dynamically
in response to outages or degraded service
- **Instant rollback**: Revert configuration changes server-side without
artifact redeployment
- **Progressive delivery**: Enable A/B testing, canary releases, and
user/region-based configuration
- **Environment parity**: Eliminate configuration drift between staging
and production builds
- Decouples deployment cadence from configuration changes
- Enables GitOps workflows for configuration management separate from
code deployments
- Supports real-time operational control of client behavior
- Reduces build matrix complexity (no per-environment builds)

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-6246-change-cloud-feature-flags-to-be-loaded-dynamically-at-runtime-rather-than-set-in-build-2966d73d3650811cbb41c9093961037a)
by [Unito](https://www.unito.io)
This commit is contained in:
Christian Byrne
2025-10-23 20:16:18 -07:00
committed by GitHub
parent a3bfc2e91a
commit d7a58a7a9b
24 changed files with 354 additions and 107 deletions

View File

@@ -0,0 +1,45 @@
/**
* Remote configuration service
*
* Fetches configuration from the server at runtime, enabling:
* - Feature flags without rebuilding
* - Server-side feature discovery
* - Version compatibility management
* - Avoiding vendor lock-in for native apps
*
* This module is tree-shaken in OSS builds.
* Used for initial config load in main.ts and polling in the extension.
*/
import { ref } from 'vue'
import type { RemoteConfig } from './types'
/**
* Reactive remote configuration
* Updated whenever config is loaded from the server
*/
export const remoteConfig = ref<RemoteConfig>({})
/**
* Loads remote configuration from the backend /api/features endpoint
* and updates the reactive remoteConfig ref
*/
export async function loadRemoteConfig(): Promise<void> {
try {
const response = await fetch('/api/features', { cache: 'no-store' })
if (response.ok) {
const config = await response.json()
window.__CONFIG__ = config
remoteConfig.value = config
} else {
console.warn('Failed to load remote config:', response.statusText)
window.__CONFIG__ = {}
remoteConfig.value = {}
}
} catch (error) {
console.error('Failed to fetch remote config:', error)
window.__CONFIG__ = {}
remoteConfig.value = {}
}
}

View File

@@ -0,0 +1,19 @@
/**
* Server health alert configuration from the backend
*/
type ServerHealthAlert = {
message: string
tooltip?: string
severity?: 'info' | 'warning' | 'error'
badge?: string
}
/**
* Remote configuration type
* Configuration fetched from the server at runtime
*/
export type RemoteConfig = {
mixpanel_token?: string
subscription_required?: boolean
server_health_alert?: ServerHealthAlert
}