/** * The oldest terminal app that may use the backoffice. Raise it with every app release that older versions must not * keep syncing past; MIN_APP_VERSION overrides it without a deploy. */ export const MIN_APP_VERSION = '1.4.0'; export const APP_VERSION_HEADER = 'x-app-version'; export function minAppVersion(): string { return process.env.MIN_APP_VERSION?.trim() || MIN_APP_VERSION; } /** `1.4.2+37` → [1, 4, 2]; the build number after `+` is ignored. Null for anything that isn't a version */ export function parseAppVersion(value: unknown): number[] | null { if (typeof value !== 'string') return null; const match = /^\s*v?(\d+(?:\.\d+)*)(?:[-+].*)?\s*$/.exec(value); return match ? match[1].split('.').map(Number) : null; } /** Whether [version] is at least [minimum]. Apps from before the version header send none and are outdated */ export function isAppVersionSupported(version: unknown, minimum = minAppVersion()): boolean { const current = parseAppVersion(version); const required = parseAppVersion(minimum); if (!required) return true; if (!current) return false; for (let i = 0; i < Math.max(current.length, required.length); i++) { const diff = (current[i] ?? 0) - (required[i] ?? 0); if (diff !== 0) return diff > 0; } return true; }