From 2432c0ddfc3e42d02729411b6427ed286c75de95 Mon Sep 17 00:00:00 2001 From: Rene Fichtmueller Date: Sat, 6 Jun 2026 17:06:22 +0000 Subject: [PATCH] fix(flexoptix-sync): empty FLEXOPTIX_API_TOKEN string short-circuited bearer login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause of the persistent sync:flexoptix-catalog HTTP 401: line 397 used '?? null' which only coerces null/undefined. With FLEXOPTIX_API_TOKEN='' (empty string set in .env), token stayed '' and line 485's 'token ?? getBearerToken()' returned '' instead of performing the username/password login — sending an empty 'Bearer ' header that the products endpoint rejected with 401. Fix: '|| null' coerces empty string to null so the bearer-login fallback fires. Verified: sync now completes (username/password -> customer token -> products 200, 3 products/price/stock writes on limit=50). Credentials were correct all along. --- packages/scraper/src/robots/flexoptix-api-sync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scraper/src/robots/flexoptix-api-sync.ts b/packages/scraper/src/robots/flexoptix-api-sync.ts index c1d034d..d341bd3 100644 --- a/packages/scraper/src/robots/flexoptix-api-sync.ts +++ b/packages/scraper/src/robots/flexoptix-api-sync.ts @@ -394,7 +394,7 @@ function validateEnv(): { baseUrl: string; username: string | null; password: st if (!baseUrl) { throw new Error("FLEXOPTIX_API_BASE_URL is required for Flexoptix API sync"); } - const token = process.env["FLEXOPTIX_API_TOKEN"]?.trim() ?? null; + const token = process.env["FLEXOPTIX_API_TOKEN"]?.trim() || null; // empty string -> null so bearer-login fallback fires const username = process.env["FLEXOPTIX_API_USERNAME"]?.trim() ?? null; const password = process.env["FLEXOPTIX_API_PASSWORD"]?.trim() ?? null; if (!token && (!username || !password)) {