SPB Git

Repository Public

config.ts 3.5 KB 79 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr SMS Gateway8 * File             : backend/src/config.ts9 * Module           : backend10 * Repository       : https://git.spboucher.ai/maclustr-sms11 * Project Website  : https://sms.spboucher.ai12 * Created          : 2026-11-3013 * Last Modified    : 2026-11-3014 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { readFileSync } from "node:fs"4344const env = (k: string, d?: string) => process.env[k] ?? d45const must = (k: string) => { const v = process.env[k]; if (!v) throw new Error(`variable d'environnement manquante : ${k}`); return v }4647function loadKey(): Buffer {48  const file = env("SMS_DATA_KEY_FILE")49  const raw = file ? readFileSync(file, "utf8").trim() : must("SMS_DATA_KEY")50  const key = Buffer.from(raw, "base64")51  if (key.length !== 32) throw new Error("la clé de données doit faire 32 octets (base64)")52  return key53}5455export const config = {56  port: Number(env("PORT", "8751")),57  host: env("HOST", "127.0.0.1")!,58  origin: env("SMS_ORIGIN", "http://localhost:8751")!,59  rpId: env("SMS_RP_ID", "localhost")!,60  databaseUrl: env("DATABASE_URL", "postgres://127.0.0.1/maclustr_sms_dev")!,61  webDir: env("SMS_WEB_DIR", "dist/web")!,62  releasesDir: env("SMS_RELEASES_DIR", "releases")!,63  migrationsDir: env("SMS_MIGRATIONS_DIR", "backend/migrations")!,64  trustProxy: (env("SMS_TRUST_PROXY", "127.0.0.1")!).split(",").map(s => s.trim()).filter(Boolean),65  // Hôtes privés explicitement autorisés comme cibles de webhook (ex. services du LAN). Vide = aucune adresse privée.66  webhookAllowHosts: (env("SMS_WEBHOOK_ALLOW_HOSTS", "")!).split(",").map(s => s.trim().toLowerCase()).filter(Boolean),67  // Applications Apple autorisées à utiliser les clés d'accès du domaine (fichier apple-app-site-association) : « <équipe>.<bundle id> ».68  appleAppIds: (env("SMS_APPLE_APP_IDS", "3YM54G49SN.ai.spboucher.maclustr.sms")!).split(",").map(s => s.trim()).filter(Boolean),69  defaultRegion: env("SMS_DEFAULT_REGION", "CA")!,70  logLevel: env("SMS_LOG_LEVEL", "info")!,71  heartbeatIntervalS: Number(env("SMS_HEARTBEAT_S", "30")),72  inFlightWindow: Number(env("SMS_IN_FLIGHT_WINDOW", "4")),73  dataKey: null as unknown as Buffer,74  secure: false,75}76config.secure = config.origin.startsWith("https://")7778export function initConfig() { config.dataKey = loadKey(); return config }79
Files main
Menu

Theme