Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(config): ignore a negative SIMULATE_TYPING_MAX_MS
Yudhi Armyndharise7d5f9da866a
diff --git a/src/config/feature-flags.spec.ts b/src/config/feature-flags.spec.tsindex 0b9d69973..75d6aa421 100644--- a/src/config/feature-flags.spec.ts+++ b/src/config/feature-flags.spec.ts@@ -35,10 +35,14 @@ describe('feature-flags', () => {}});- it('parses simulateTypingMaxMs with Number()||5000 semantics (0/negative/non-numeric fall back)', () => {+ it('reads simulateTypingMaxMs as a positive integer (0, negative and non-numeric values fall back to 5000)', () => {expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: '3000' }).simulateTypingMaxMs).toBe(3000);- // Critical: "0" must fall back to 5000 (Number('0')||5000), NOT stay 0 as parseInt would.+ expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: '1' }).simulateTypingMaxMs).toBe(1);+ // Critical: "0" must fall back to 5000, NOT stay 0 as parseInt would.expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: '0' }).simulateTypingMaxMs).toBe(5000);+ // A negative cap would reach setTimeout and shrink the humanising pause to about 1 ms.+ expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: '-1' }).simulateTypingMaxMs).toBe(5000);+ expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: '-5' }).simulateTypingMaxMs).toBe(5000);expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: '' }).simulateTypingMaxMs).toBe(5000);expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: 'abc' }).simulateTypingMaxMs).toBe(5000);expect(computeFeatureFlags({ SIMULATE_TYPING_MAX_MS: undefined }).simulateTypingMaxMs).toBe(5000);diff --git a/src/config/feature-flags.ts b/src/config/feature-flags.tsindex 6f8fe465c..9e1fc1875 100644--- a/src/config/feature-flags.ts+++ b/src/config/feature-flags.ts@@ -1,4 +1,5 @@import { ConfigService } from '@nestjs/config';+import { positiveIntOrDefault } from '../common/utils/env-int';/*** Runtime feature flags, centralised so every flag's env-var name and default lives in one place@@ -25,7 +26,7 @@ export interface FeatureFlags {* unchanged:* - `=== 'true'` → opt-in flag (default false)* - `!== 'false'` → opt-out flag (default true)- * and the max-ms parse mirrors the original `Number(x) || 5000` — 0, negative, empty and non-numeric+ * The max-ms read keeps a positive number (a fraction is floored); 0, negative, empty and non-numeric* values all fall back to 5000 (note this differs from `parseInt`, which would keep a literal 0).*/export function computeFeatureFlags(env: NodeJS.ProcessEnv = process.env): FeatureFlags {@@ -34,7 +35,7 @@ export function computeFeatureFlags(env: NodeJS.ProcessEnv = process.env): FeatustoreEphemeralMessages: env.STORE_EPHEMERAL_MESSAGES !== 'false',resolveLidToPhone: env.RESOLVE_LID_TO_PHONE === 'true',simulateTyping: env.SIMULATE_TYPING !== 'false',- simulateTypingMaxMs: Number(env.SIMULATE_TYPING_MAX_MS) || 5000,+ simulateTypingMaxMs: positiveIntOrDefault(env.SIMULATE_TYPING_MAX_MS, 5000),};}