Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
chore(infra): post-#488 robustness follow-ups (review lows) (#490)
Yudhi Armyndharis4b5114354824
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 866b47bae..dc12ab12e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- The Infrastructure page now shows the actual **WhatsApp Web build** the whatsapp-web.js engine is using (e.g. `2.3000.1042251103-alpha`) and how it was chosen (pinned via `WWEBJS_WEB_VERSION`, auto-resolved, or native), surfaced via `/infra/status`. The engine card previously showed only the npm library version (`whatsapp-web.js 1.34.7`), which is unrelated to the WA Web build that actually governs connection stability. (#488)- Infrastructure data **backup & restore**: export all Data-DB tables to a JSON file and import them back, wired into the database-switch flow. When you change the database backend, the restart dialog now warns that the new database starts empty and offers a one-click backup before switching; a storage switch warns that existing media is not moved. (#488)- The Infrastructure page flags any database/redis/storage setting that is **pinned by an environment variable** (its running value differs from the saved config), so it's clear a dashboard change won't apply until that variable is unset, instead of the control silently having no effect. (#488)-- The storage card now warns when **S3 is selected but unreachable** (a dead/misconfigured bucket no longer shows a misleading green badge), via a new `s3Available` field on `/infra/status`. (#488)+- The storage card now warns when **S3 is selected but unreachable** (a dead/misconfigured bucket no longer shows a misleading green badge), via a new `s3Available` field on `/infra/status`; the check re-probes (throttled) rather than latching the boot-time result, so a bundled MinIO that comes up after the app self-corrects. A backup import that exceeds the request size limit now reports an actionable message (raise `BODY_SIZE_LIMIT`) instead of a bare "Payload Too Large". (#488)- Data-loss & availability hardening for the new infra flows: importing a backup now **refuses an empty/garbage file** (it no longer wipes the database and reports success) and asks for confirmation first; selecting the **built-in Postgres/MinIO no longer crash-loops a production boot** on the default-secret guard (the bundled containers run on the internal-only network); and a transient failure fetching the WhatsApp Web version is no longer cached, so it retries instead of permanently falling back. (#488)- Human-readable console logs: the `LoggerService` now renders a colorized, NestJS-style line (`[OpenWA] <pid> - <timestamp> <LEVEL> [Context] <message>` with dimmed `key=value` metadata and stack traces on their own line) instead of always emitting raw JSON, so application logs line up visually with NestJS's own framework logs. The format defaults to structured JSON in production (`NODE_ENV=production`, for containers and log aggregators) and human-readable pretty everywhere else, and can be pinned with `LOG_FORMAT=pretty|json`. `NO_COLOR` / `FORCE_COLOR` are honored. JSON output is byte-for-byte unchanged when selected. (#469)diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.jsonindex f21a1f572..0a94dfdb5 100644--- a/dashboard/src/i18n/locales/ar.json+++ b/dashboard/src/i18n/locales/ar.json@@ -663,7 +663,8 @@"importFailed": "تعذّر استيراد البيانات","importOk": "تمّ استيراد البيانات","importConfirm": "سيؤدّي الاستيراد إلى استبدال جميع البيانات الحالية بالنسخة الاحتياطية ({{rows}} صفًّا). لا يمكن التراجع عن هذا الإجراء. هل تريد المتابعة؟",- "invalidFile": "هذا الملفّ ليس نسخة احتياطية صالحة لبيانات OpenWA."+ "invalidFile": "هذا الملفّ ليس نسخة احتياطية صالحة لبيانات OpenWA.",+ "importTooLarge": "النسخة الاحتياطية أكبر من حدّ الطلب. زِد قيمة BODY_SIZE_LIMIT على الخادم ثم أعد المحاولة."}},"plugins": {diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.jsonindex e1fe1eb3f..da55d596a 100644--- a/dashboard/src/i18n/locales/en.json+++ b/dashboard/src/i18n/locales/en.json@@ -644,7 +644,8 @@"importFailed": "Couldn't import data","importOk": "Data imported","importConfirm": "Importing will REPLACE all current data with the backup ({{rows}} rows). This cannot be undone. Continue?",- "invalidFile": "That file isn't a valid OpenWA data backup."+ "invalidFile": "That file isn't a valid OpenWA data backup.",+ "importTooLarge": "Backup is too large for the request limit. Increase BODY_SIZE_LIMIT on the server and try again."},"restart": {"idleTitle": "Configuration saved",diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.jsonindex 32e626475..49e926046 100644--- a/dashboard/src/i18n/locales/es.json+++ b/dashboard/src/i18n/locales/es.json@@ -663,7 +663,8 @@"importFailed": "No se pudieron importar los datos","importOk": "Datos importados","importConfirm": "La importación REEMPLAZARÁ todos los datos actuales con la copia de seguridad ({{rows}} filas). Esto no se puede deshacer. ¿Continuar?",- "invalidFile": "Ese archivo no es una copia de seguridad de datos válida de OpenWA."+ "invalidFile": "Ese archivo no es una copia de seguridad de datos válida de OpenWA.",+ "importTooLarge": "La copia de seguridad supera el límite de la solicitud. Aumenta BODY_SIZE_LIMIT en el servidor e inténtalo de nuevo."}},"plugins": {diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.jsonindex 0a6ab7034..e12f794d8 100644--- a/dashboard/src/i18n/locales/fr.json+++ b/dashboard/src/i18n/locales/fr.json@@ -663,7 +663,8 @@"importFailed": "Impossible d'importer les données","importOk": "Données importées","importConfirm": "L'importation REMPLACERA toutes les données actuelles par la sauvegarde ({{rows}} lignes). Cette action est irréversible. Continuer ?",- "invalidFile": "Ce fichier n'est pas une sauvegarde de données OpenWA valide."+ "invalidFile": "Ce fichier n'est pas une sauvegarde de données OpenWA valide.",+ "importTooLarge": "La sauvegarde dépasse la limite de la requête. Augmentez BODY_SIZE_LIMIT sur le serveur, puis réessayez."}},"plugins": {diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.jsonindex 0f2dd27e1..c3fd83864 100644--- a/dashboard/src/i18n/locales/he.json+++ b/dashboard/src/i18n/locales/he.json@@ -663,7 +663,8 @@"importFailed": "לא ניתן לייבא את הנתונים","importOk": "הנתונים יובאו","importConfirm": "הייבוא יחליף את כל הנתונים הנוכחיים בגיבוי ({{rows}} שורות). לא ניתן לבטל פעולה זו. להמשיך?",- "invalidFile": "הקובץ הזה אינו גיבוי נתונים תקין של OpenWA."+ "invalidFile": "הקובץ הזה אינו גיבוי נתונים תקין של OpenWA.",+ "importTooLarge": "הגיבוי גדול מדי עבור מגבלת הבקשה. הגדילו את BODY_SIZE_LIMIT בשרת ונסו שוב."}},"plugins": {diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.jsonindex acbb6a899..baa2fc5b3 100644--- a/dashboard/src/i18n/locales/it.json+++ b/dashboard/src/i18n/locales/it.json@@ -663,7 +663,8 @@"importFailed": "Impossibile importare i dati","importOk": "Dati importati","importConfirm": "L'importazione SOSTITUIRÀ tutti i dati attuali con il backup ({{rows}} righe). Questa operazione non può essere annullata. Continuare?",- "invalidFile": "Questo file non è un backup dati valido di OpenWA."+ "invalidFile": "Questo file non è un backup dati valido di OpenWA.",+ "importTooLarge": "Il backup supera il limite della richiesta. Aumenta BODY_SIZE_LIMIT sul server e riprova."}},"plugins": {diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.jsonindex 0a9980dcc..96ab98b7d 100644--- a/dashboard/src/i18n/locales/te.json+++ b/dashboard/src/i18n/locales/te.json@@ -663,7 +663,8 @@"importFailed": "డేటాను ఇంపోర్ట్ చేయలేకపోయాం","importOk": "డేటా ఇంపోర్ట్ చేయబడింది","importConfirm": "ఇంపోర్ట్ చేయడం వల్ల ప్రస్తుత డేటా మొత్తం బ్యాకప్తో ({{rows}} వరుసలు) భర్తీ చేయబడుతుంది. దీన్ని వెనక్కి తీసుకోలేరు. కొనసాగించాలా?",- "invalidFile": "ఆ ఫైల్ చెల్లుబాటు అయ్యే OpenWA డేటా బ్యాకప్ కాదు."+ "invalidFile": "ఆ ఫైల్ చెల్లుబాటు అయ్యే OpenWA డేటా బ్యాకప్ కాదు.",+ "importTooLarge": "బ్యాకప్ అభ్యర్థన పరిమితి కంటే పెద్దది. సర్వర్లో BODY_SIZE_LIMIT పెంచి మళ్లీ ప్రయత్నించండి."}},"plugins": {diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.jsonindex 95424b902..d8556fb64 100644--- a/dashboard/src/i18n/locales/zh-CN.json+++ b/dashboard/src/i18n/locales/zh-CN.json@@ -663,7 +663,8 @@"importFailed": "无法导入数据","importOk": "数据已导入","importConfirm": "导入操作将用备份数据替换(REPLACE)当前所有数据({{rows}} 行)。此操作无法撤销。是否继续?",- "invalidFile": "该文件不是有效的 OpenWA 数据备份。"+ "invalidFile": "该文件不是有效的 OpenWA 数据备份。",+ "importTooLarge": "备份超出请求大小限制。请在服务器上调高 BODY_SIZE_LIMIT 后重试。"}},"plugins": {diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.jsonindex d9af4b5e7..250371a37 100644--- a/dashboard/src/i18n/locales/zh-HK.json+++ b/dashboard/src/i18n/locales/zh-HK.json@@ -663,7 +663,8 @@"importFailed": "無法匯入資料","importOk": "資料已匯入","importConfirm": "匯入將以備份({{rows}} 列)取代所有目前資料。此操作無法復原。是否繼續?",- "invalidFile": "該檔案並非有效的 OpenWA 資料備份。"+ "invalidFile": "該檔案並非有效的 OpenWA 資料備份。",+ "importTooLarge": "備份超出請求大小限制。請在伺服器上調高 BODY_SIZE_LIMIT 後重試。"}},"plugins": {diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsxindex df18219cd..518eec1db 100644--- a/dashboard/src/pages/Infrastructure.tsx+++ b/dashboard/src/pages/Infrastructure.tsx@@ -293,6 +293,9 @@ export function Infrastructure() {(dbConfig.type === 'postgres' && dbConfig.builtIn !== infraStatus.database.builtIn) ||dbExternalRetarget),);+ // Scope: this warns on a backend-TYPE change (local↔s3) and a built-in↔external flip — the cases+ // that point at a different store. It does NOT warn on same-backend repointing (e.g. a new S3+ // bucket/endpoint or a new local path); region/endpoint aren't on /status to compare reliably.setStorageSwitch(!!infraStatus &&(storageConfig.type !== infraStatus.storage.type ||@@ -351,7 +354,16 @@ export function Infrastructure() {if (res.imported) toast.success(t('infrastructure.migration.importOk'));else toast.error(t('infrastructure.migration.importFailed'), (res.warnings || []).slice(0, 3).join('; ') || res.message);} catch (err) {- toast.error(t('infrastructure.migration.importFailed'), err instanceof Error ? err.message : t('common.unknownError'));+ // A large backup can exceed the request body cap (default 25mb) — give an actionable message+ // instead of a bare "Payload Too Large". The status is carried on the Error by the api client.+ const status = (err as { status?: number } | null)?.status;+ const detail =+ status === 413+ ? t('infrastructure.migration.importTooLarge')+ : err instanceof Error+ ? err.message+ : t('common.unknownError');+ toast.error(t('infrastructure.migration.importFailed'), detail);} finally {setMigrating(false);}diff --git a/docker-compose.yml b/docker-compose.ymlindex 8fb8143c3..432750d41 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -83,6 +83,9 @@ services:# and the file wins. Set any of these in your .env/host to pin it (a real value keeps top precedence# and the dashboard control then shows "managed by environment"). First-run defaults (sqlite) are# written to data/.env.generated by the app, so a blank stack still boots SQLite.+ # NOTE: if you run the built-in Postgres MANUALLY (`docker compose --profile postgres up`) instead+ # of via the dashboard, set DATABASE_TYPE=postgres, DATABASE_HOST=postgres, DATABASE_PORT=5432,+ # DATABASE_USERNAME=openwa and DATABASE_PASSWORD in your .env/host — these are no longer defaulted here.- DATABASE_TYPE=${DATABASE_TYPE:-}- DATABASE_NAME=${DATABASE_NAME:-}- DATABASE_HOST=${DATABASE_HOST:-}diff --git a/src/common/storage/storage.service.ts b/src/common/storage/storage.service.tsindex 516bbff21..45a916816 100644--- a/src/common/storage/storage.service.ts+++ b/src/common/storage/storage.service.ts@@ -116,6 +116,39 @@ export class StorageService {return this.s3Available;}+ private lastS3Check = 0;+ private s3CheckInFlight: Promise<void> | null = null;++ /**+ * Re-probe S3/MinIO reachability when it's currently marked unavailable — e.g. a bundled MinIO that+ * came up AFTER the app booted (the init HeadBucket raced and latched false). Throttled (10s) and+ * in-flight-deduped so the status endpoint can call it on every poll cheaply. Once available it+ * stays available (no need to re-probe a healthy backend here).+ */+ async refreshS3Availability(): Promise<boolean> {+ if (this.storageType !== 's3' || !this.s3Client || this.s3Available) return this.s3Available;+ if (this.s3CheckInFlight) {+ await this.s3CheckInFlight;+ return this.s3Available;+ }+ const now = Date.now();+ if (now - this.lastS3Check < 10_000) return this.s3Available;+ this.lastS3Check = now;+ this.s3CheckInFlight = (async () => {+ try {+ await this.s3Client!.send(new HeadBucketCommand({ Bucket: this.s3Bucket }));+ this.s3Available = true;+ this.logger.log(`S3 bucket '${this.s3Bucket}' is now reachable`);+ } catch {+ // still unreachable — leave s3Available false; a later poll retries after the throttle window+ } finally {+ this.s3CheckInFlight = null;+ }+ })();+ await this.s3CheckInFlight;+ return this.s3Available;+ }+async listFiles(): Promise<string[]> {if (this.storageType === 's3' && this.s3Client && this.s3Available) {return this.listS3Files();diff --git a/src/modules/infra/infra.controller.spec.ts b/src/modules/infra/infra.controller.spec.tsindex a69a5d9bf..eb4e1a6d0 100644--- a/src/modules/infra/infra.controller.spec.ts+++ b/src/modules/infra/infra.controller.spec.ts@@ -655,7 +655,7 @@ describe('InfraController.getStatus engine (F7 — reads the real engine.puppete{} as never, // engineFactory{ isDockerAvailable: () => false } as never, // dockerService — no Docker in unit testscache as never,- { isS3Available: () => false } as never, // storageService+ { isS3Available: () => false, refreshS3Availability: () => Promise.resolve(false) } as never, // storageService{} as never, // shutdownService);@@ -678,7 +678,7 @@ describe('InfraController.getStatus storage (reads the real storage.localPath ke{} as never, // engineFactory{ isDockerAvailable: () => false } as never, // dockerService — no Docker in unit testscache as never,- { isS3Available: () => false } as never, // storageService+ { isS3Available: () => false, refreshS3Availability: () => Promise.resolve(false) } as never, // storageService{} as never, // shutdownService);};diff --git a/src/modules/infra/infra.controller.ts b/src/modules/infra/infra.controller.tsindex 50256ef60..56494c309 100644--- a/src/modules/infra/infra.controller.ts+++ b/src/modules/infra/infra.controller.ts@@ -301,7 +301,8 @@ export class InfraController {const dbBuiltIn = running ? running.database && dbHost === 'postgres' : savedBuiltin.database;const redisBuiltIn = running ? running.cache && redisHost === 'redis' : savedBuiltin.cache;const storageBuiltIn = running ? running.storage && s3Endpoint === 'http://minio:9000' : savedBuiltin.storage;- const s3Available = storageType === 's3' ? this.storageService.isS3Available() : undefined;+ // Re-probe (throttled) so a MinIO/S3 that came up after boot is reflected, not latched unreachable.+ const s3Available = storageType === 's3' ? await this.storageService.refreshS3Availability() : undefined;return {database: { connected: dbConnected, type: dbType, host: dbHost, builtIn: dbBuiltIn },