import { existsSync, readFileSync } from 'node:fs'; import { backupEnvSchema, overlayEnv, parseEnv, parseSecretsFile, type BackupEnv, } from '@dorfteich/shared'; /** * Loads the sidecar configuration the same way the api does (issue #80): * the wizard-written secret store fills SMTP variables the container env * does not set, and empty strings count as unset — compose passes optional * variables as `""`. Without this, a wizard-configured relay would never * reach the failure mail. */ export function loadBackupEnv(env: Record = process.env): BackupEnv { const secretsFile = backupEnvSchema.shape.SECRETS_FILE.parse(env.SECRETS_FILE || undefined); const secrets = existsSync(secretsFile) ? parseSecretsFile(readFileSync(secretsFile, 'utf8')) : {}; return parseEnv(backupEnvSchema, overlayEnv(env, secrets)); }