SPB Git

Repository Public

config.ts 6.2 KB 89 lines typescript

1import path from "node:path"23const env = process.env4function req(name: string, fallback?: string): string {5  const v = env[name] ?? fallback6  if (v === undefined || v === "") throw new Error(`Missing environment variable ${name}`)7  return v8}9const list = (v: string | undefined) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean)1011export const config = {12  port: Number(env.PORT ?? 8730),13  host: env.HOST ?? "127.0.0.1",14  databaseUrl: req("DATABASE_URL", "postgres://127.0.0.1/sp_mail_dev"),15  origin: req("SPMAIL_ORIGIN", "http://localhost:8730"),16  rpId: req("SPMAIL_RP_ID", "localhost"),17  rpName: "SP Mail",18  webDir: path.resolve(env.SPMAIL_WEB_DIR ?? "./dist/web"),19  trustProxy: list(env.SPMAIL_TRUST_PROXY ?? "127.0.0.1"),20  // Stalwart (JMAP + gestion), joint par le tunnel privé — jamais exposé au public.21  stalwartUrl: req("SPMAIL_STALWART_URL", "http://127.0.0.1:18080").replace(/\/$/, ""),22  stalwartAdminUser: req("SPMAIL_STALWART_ADMIN_USER", "spmail-admin@spboucher.ai"),23  stalwartAdminPassword: env.SPMAIL_STALWART_ADMIN_PASSWORD ?? "",24  // Clé maîtresse (32 octets, base64) : chiffre les secrets des comptes Stalwart en base.25  masterKey: env.SPMAIL_MASTER_KEY ?? "",26  appleAppIds: list(env.SPMAIL_APPLE_APP_IDS),27  mxHost: env.SPMAIL_MX_HOST ?? "mx1.spboucher.ai",28  mxIp: env.SPMAIL_MX_IP ?? "51.161.112.61",29  backupStatusFile: env.SPMAIL_BACKUP_STATUS ?? "",30  sessionIdleDays: 30,31  sessionMaxDays: 180,32  secureCookies: (env.SPMAIL_ORIGIN ?? "").startsWith("https://"),33  version: env.SPMAIL_VERSION ?? "dev",34  // ---- API /api/v1, travailleurs, webhooks35  workers: (env.SPMAIL_WORKERS ?? "on") !== "off",36  /** Adresses jamais supprimables ni modifiables de façon destructive par aucune API. */37  protectedAddresses: list(env.SPMAIL_PROTECTED_ADDRESSES ?? "info@spboucher.ai,contact@spboucher.ai,postmaster@spboucher.ai,abuse@spboucher.ai,dmarc@spboucher.ai").map((a) => a.toLowerCase()),38  watchIntervalMs: Math.max(250, Number(env.SPMAIL_WATCH_INTERVAL_MS ?? 5000)),39  expiryIntervalMs: Math.max(1000, Number(env.SPMAIL_EXPIRY_INTERVAL_MS ?? 3600_000)),40  workerTickMs: Math.max(100, Number(env.SPMAIL_WORKER_TICK_MS ?? 1000)),41  /** Délais de nouvelle tentative des webhooks, en secondes (1 min, 5 min, 30 min, 2 h, 6 h, 24 h). */42  webhookBackoff: list(env.SPMAIL_WEBHOOK_BACKOFF ?? "60,300,1800,7200,21600,86400").map(Number).filter((n) => n >= 0),43  /** Durée de vie d'un fichier téléversé (bornée par la conservation des blobs temporaires de Stalwart). */44  fileTtlMinutes: Math.max(1, Number(env.SPMAIL_FILE_TTL_MINUTES ?? 1440)),45  /** TEST SEULEMENT : domaines ou adresses hébergés traités comme « externes » (flux d'approbation). Refusé sur une origine https. */46  treatAsExternal: list(env.SPMAIL_TREAT_AS_EXTERNAL).map((a) => a.toLowerCase()),47  validateResponses: env.SPMAIL_VALIDATE_RESPONSES === "1",48  // ---- SP Mail Next : notifications push APNs (sans ces trois valeurs, le push est désactivé et le dit)49  apnsKeyFile: env.SPMAIL_APNS_KEY_FILE ?? "",50  apnsKeyId: env.SPMAIL_APNS_KEY_ID ?? "",51  apnsTeamId: env.SPMAIL_APNS_TEAM_ID ?? "",52  /** TEST SEULEMENT : origine d'un faux serveur APNs (http://127.0.0.1:port en HTTP/2 clair). Refusé sur une origine https. */53  apnsHostOverride: (env.SPMAIL_APNS_HOST_OVERRIDE ?? "").replace(/\/$/, ""),54  /** Délais de nouvelle tentative d'une notification, en secondes (5 s, 30 s, 2 min, 10 min, 1 h). */55  pushBackoff: list(env.SPMAIL_PUSH_BACKOFF ?? "5,30,120,600,3600").map(Number).filter((n) => n >= 0),56  // ---- SP Mail Next : intelligence (facultative, coupée par défaut), index sémantique, exploitation57  /** Fournisseur local : passerelle compatible OpenAI du cluster (ex. https://llm.spboucher.ai/v1). Vide = indisponible. */58  aiLocalUrl: (env.SPMAIL_AI_LOCAL_URL ?? "").replace(/\/$/, ""),59  aiLocalKey: env.SPMAIL_AI_LOCAL_KEY ?? "",60  aiLocalModel: env.SPMAIL_AI_LOCAL_MODEL ?? "maclustr-qwen3",61  /** Fournisseur externe (consentement exigé) : modèle rapide et peu coûteux par défaut ; la clé est celle de templates-ai (ANTHROPIC_API_KEY). */62  aiAnthropicModel: env.SPMAIL_AI_ANTHROPIC_MODEL ?? "claude-haiku-5-5",63  aiTimeoutMs: Math.max(1000, Number(env.SPMAIL_AI_TIMEOUT_MS ?? 60_000)),64  aiRatePerMinute: Math.max(1, Number(env.SPMAIL_AI_RATE_PER_MINUTE ?? 30)),65  aiRatePerDay: Math.max(1, Number(env.SPMAIL_AI_RATE_PER_DAY ?? 500)),66  /** Embeddings : auto (point /embeddings du fournisseur local s'il existe, sinon modèle en processus), endpoint, inprocess ou off. */67  aiEmbedBackend: (env.SPMAIL_AI_EMBED_BACKEND ?? "auto") as "auto" | "endpoint" | "inprocess" | "off",68  aiEmbedEndpointModel: env.SPMAIL_AI_EMBED_ENDPOINT_MODEL ?? "",69  aiEmbedModel: env.SPMAIL_AI_EMBED_MODEL ?? "Xenova/multilingual-e5-small",70  /** TEST SEULEMENT : embeddings déterministes sans modèle (sac de mots haché). Refusé sur une origine https. */71  aiEmbedFake: env.SPMAIL_AI_EMBED_FAKE === "1",72  /** Fuseau des règles « demain matin », « semaine prochaine ». */73  defaultTz: env.SPMAIL_DEFAULT_TZ ?? "America/Toronto",74  /** Moniteur d'alertes : "off" le coupe (les contrôles de /api/admin/health restent disponibles). */75  opsMonitor: (env.SPMAIL_OPS_MONITOR ?? "on") !== "off",76  opsMonitorIntervalMs: Math.max(500, Number(env.SPMAIL_OPS_MONITOR_INTERVAL_MS ?? 60_000)),77  opsDiskPath: env.SPMAIL_OPS_DISK_PATH ?? "",78  opsDiskWarnPct: Number(env.SPMAIL_OPS_DISK_WARN_PCT ?? 10),79  opsDiskFailPct: Number(env.SPMAIL_OPS_DISK_FAIL_PCT ?? 5),80  opsCertWarnDays: Number(env.SPMAIL_OPS_CERT_WARN_DAYS ?? 14),81  opsBackupMaxAgeHours: Number(env.SPMAIL_OPS_BACKUP_MAX_AGE_HOURS ?? 36),82  opsRenotifyHours: Math.max(1, Number(env.SPMAIL_OPS_RENOTIFY_HOURS ?? 12)),83  opsWebhookFailThreshold: Math.max(1, Number(env.SPMAIL_OPS_WEBHOOK_FAIL_THRESHOLD ?? 5)),84}85if (config.treatAsExternal.length && config.secureCookies) throw new Error("SPMAIL_TREAT_AS_EXTERNAL is a test-only hook and is refused on an https origin")86if (config.apnsHostOverride && config.secureCookies) throw new Error("SPMAIL_APNS_HOST_OVERRIDE is a test-only hook and is refused on an https origin")87if (config.aiEmbedFake && config.secureCookies) throw new Error("SPMAIL_AI_EMBED_FAKE is a test-only hook and is refused on an https origin")88export const cookieName = config.secureCookies ? "__Host-spmail_session" : "spmail_session"89
Files main
Menu

Theme