Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): show a failed API key read instead of an empty list
Yudhi Armyndharis2cd7ffa25bbc
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.jsonindex ec66805d3..0633aef39 100644--- a/dashboard/src/i18n/locales/ar.json+++ b/dashboard/src/i18n/locales/ar.json@@ -634,7 +634,10 @@},"empty": {"title": "لا توجد مفاتيح API",- "description": "أنشئ مفتاح API للمصادقة على طلباتك"+ "description": "أنشئ مفتاح API للمصادقة على طلباتك",+ "loadErrorTitle": "تعذر تحميل مفاتيح API",+ "forbiddenTitle": "لا يوجد وصول إلى مفاتيح API",+ "forbiddenDesc": "تتطلب إدارة مفاتيح API مفتاح مسؤول غير مقيد بجلسات محددة."},"confirm": {"deleteTitle": "حذف مفتاح API",diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.jsonindex 6f1dac381..07c0e4920 100644--- a/dashboard/src/i18n/locales/de.json+++ b/dashboard/src/i18n/locales/de.json@@ -617,7 +617,10 @@},"empty": {"title": "Keine API-Schlüssel erstellt",- "description": "Erstelle einen API-Schlüssel, um deine Anfragen zu authentifizieren"+ "description": "Erstelle einen API-Schlüssel, um deine Anfragen zu authentifizieren",+ "loadErrorTitle": "API-Schlüssel konnten nicht geladen werden",+ "forbiddenTitle": "Kein Zugriff auf API-Schlüssel",+ "forbiddenDesc": "Zum Verwalten von API-Schlüsseln ist ein Admin-Schlüssel erforderlich, der nicht auf bestimmte Sitzungen beschränkt ist."},"confirm": {"deleteTitle": "API-Schlüssel löschen",diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.jsonindex 12f822ace..e4a2dd4d4 100644--- a/dashboard/src/i18n/locales/en.json+++ b/dashboard/src/i18n/locales/en.json@@ -617,7 +617,10 @@},"empty": {"title": "No API keys created",- "description": "Create an API key to authenticate your requests"+ "description": "Create an API key to authenticate your requests",+ "loadErrorTitle": "Could not load API keys",+ "forbiddenTitle": "No access to API keys",+ "forbiddenDesc": "Managing API keys requires an admin key that is not restricted to specific sessions."},"confirm": {"deleteTitle": "Delete API Key",diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.jsonindex 0cf682864..62f11d88b 100644--- a/dashboard/src/i18n/locales/es.json+++ b/dashboard/src/i18n/locales/es.json@@ -572,7 +572,10 @@},"empty": {"title": "No hay claves API creadas",- "description": "Crea una clave API para autenticar tus peticiones"+ "description": "Crea una clave API para autenticar tus peticiones",+ "loadErrorTitle": "No se pudieron cargar las claves API",+ "forbiddenTitle": "Sin acceso a las claves API",+ "forbiddenDesc": "Para gestionar las claves API se necesita una clave de administrador que no esté restringida a sesiones específicas."},"confirm": {"deleteTitle": "Eliminar clave API",diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.jsonindex fc078602e..4c96fc184 100644--- a/dashboard/src/i18n/locales/fr.json+++ b/dashboard/src/i18n/locales/fr.json@@ -621,7 +621,10 @@},"empty": {"title": "Aucune clé API créée",- "description": "Créez une clé API pour authentifier vos requêtes"+ "description": "Créez une clé API pour authentifier vos requêtes",+ "loadErrorTitle": "Impossible de charger les clés API",+ "forbiddenTitle": "Aucun accès aux clés API",+ "forbiddenDesc": "La gestion des clés API nécessite une clé administrateur qui n'est pas limitée à des sessions précises."},"confirm": {"deleteTitle": "Supprimer la clé API",diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.jsonindex 67b46344b..4efba2a05 100644--- a/dashboard/src/i18n/locales/he.json+++ b/dashboard/src/i18n/locales/he.json@@ -626,7 +626,10 @@},"empty": {"title": "לא נוצרו מפתחות API",- "description": "יש ליצור מפתח API לאימות הבקשות"+ "description": "יש ליצור מפתח API לאימות הבקשות",+ "loadErrorTitle": "לא ניתן לטעון את מפתחות ה-API",+ "forbiddenTitle": "אין גישה למפתחות ה-API",+ "forbiddenDesc": "ניהול מפתחות API דורש מפתח מנהל שאינו מוגבל לסשנים מסוימים."},"confirm": {"deleteTitle": "מחיקת מפתח API",diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.jsonindex 2ffd12dab..322a2a12a 100644--- a/dashboard/src/i18n/locales/hi.json+++ b/dashboard/src/i18n/locales/hi.json@@ -617,7 +617,10 @@},"empty": {"title": "कोई API कुंजी नहीं बनाई गई",- "description": "अपने अनुरोधों को प्रमाणित करने के लिए एक API कुंजी बनाएँ"+ "description": "अपने अनुरोधों को प्रमाणित करने के लिए एक API कुंजी बनाएँ",+ "loadErrorTitle": "API कुंजियाँ लोड नहीं की जा सकीं",+ "forbiddenTitle": "API कुंजियों तक कोई पहुँच नहीं",+ "forbiddenDesc": "API कुंजियाँ प्रबंधित करने के लिए ऐसी व्यवस्थापक कुंजी चाहिए जो विशिष्ट सत्रों तक सीमित न हो।"},"confirm": {"deleteTitle": "API कुंजी हटाएँ",diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.jsonindex 57fccd624..994c0190b 100644--- a/dashboard/src/i18n/locales/it.json+++ b/dashboard/src/i18n/locales/it.json@@ -621,7 +621,10 @@},"empty": {"title": "Nessuna chiave API creata",- "description": "Crea una chiave API per autenticare le tue richieste"+ "description": "Crea una chiave API per autenticare le tue richieste",+ "loadErrorTitle": "Impossibile caricare le chiavi API",+ "forbiddenTitle": "Nessun accesso alle chiavi API",+ "forbiddenDesc": "Per gestire le chiavi API serve una chiave amministratore non limitata a sessioni specifiche."},"confirm": {"deleteTitle": "Elimina Chiave API",diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.jsonindex 363596020..dd2bb00e5 100644--- a/dashboard/src/i18n/locales/ko.json+++ b/dashboard/src/i18n/locales/ko.json@@ -617,7 +617,10 @@},"empty": {"title": "생성된 API 키가 없습니다",- "description": "요청을 인증하려면 API 키를 생성하세요"+ "description": "요청을 인증하려면 API 키를 생성하세요",+ "loadErrorTitle": "API 키를 불러올 수 없습니다",+ "forbiddenTitle": "API 키에 접근할 수 없습니다",+ "forbiddenDesc": "API 키를 관리하려면 특정 세션으로 제한되지 않은 관리자 키가 필요합니다."},"confirm": {"deleteTitle": "API 키 삭제",diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.jsonindex e68e90257..2caa3b14f 100644--- a/dashboard/src/i18n/locales/pt-BR.json+++ b/dashboard/src/i18n/locales/pt-BR.json@@ -572,7 +572,10 @@},"empty": {"title": "Nenhuma chave API criada",- "description": "Crie uma chave API para autenticar suas requisições"+ "description": "Crie uma chave API para autenticar suas requisições",+ "loadErrorTitle": "Não foi possível carregar as chaves API",+ "forbiddenTitle": "Sem acesso às chaves API",+ "forbiddenDesc": "Gerenciar chaves API exige uma chave de administrador que não esteja restrita a sessões específicas."},"confirm": {"deleteTitle": "Excluir chave API",diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.jsonindex fa8b723b6..04e3eff8e 100644--- a/dashboard/src/i18n/locales/te.json+++ b/dashboard/src/i18n/locales/te.json@@ -617,7 +617,10 @@},"empty": {"title": "ఎలాంటి API కీలు సృష్టించబడలేదు",- "description": "మీ రిక్వెస్ట్లను అథెంటికేట్ చేయడానికి ఒక API కీని సృష్టించండి"+ "description": "మీ రిక్వెస్ట్లను అథెంటికేట్ చేయడానికి ఒక API కీని సృష్టించండి",+ "loadErrorTitle": "API కీలను లోడ్ చేయడం సాధ్యం కాలేదు",+ "forbiddenTitle": "API కీలకు యాక్సెస్ లేదు",+ "forbiddenDesc": "API కీలను నిర్వహించడానికి నిర్దిష్ట సెషన్లకు పరిమితం కాని అడ్మిన్ కీ అవసరం."},"confirm": {"deleteTitle": "API కీని తొలగించండి",diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.jsonindex 19c37689a..413a21602 100644--- a/dashboard/src/i18n/locales/tr.json+++ b/dashboard/src/i18n/locales/tr.json@@ -617,7 +617,10 @@},"empty": {"title": "Oluşturulmuş API anahtarı yok",- "description": "İsteklerinizin kimliğini doğrulamak için bir API anahtarı oluşturun"+ "description": "İsteklerinizin kimliğini doğrulamak için bir API anahtarı oluşturun",+ "loadErrorTitle": "API anahtarları yüklenemedi",+ "forbiddenTitle": "API anahtarlarına erişim yok",+ "forbiddenDesc": "API anahtarlarını yönetmek, belirli oturumlarla sınırlı olmayan bir yönetici anahtarı gerektirir."},"confirm": {"deleteTitle": "API Anahtarını Sil",diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.jsonindex ff0a77314..9d2f72694 100644--- a/dashboard/src/i18n/locales/zh-CN.json+++ b/dashboard/src/i18n/locales/zh-CN.json@@ -617,7 +617,10 @@},"empty": {"title": "尚未创建 API 密钥",- "description": "创建 API 密钥以认证你的请求"+ "description": "创建 API 密钥以认证你的请求",+ "loadErrorTitle": "无法加载 API 密钥",+ "forbiddenTitle": "无权访问 API 密钥",+ "forbiddenDesc": "管理 API 密钥需要一个不受特定会话限制的管理员密钥。"},"confirm": {"deleteTitle": "删除 API 密钥",diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.jsonindex 86516db2c..49e29e5d5 100644--- a/dashboard/src/i18n/locales/zh-HK.json+++ b/dashboard/src/i18n/locales/zh-HK.json@@ -617,7 +617,10 @@},"empty": {"title": "尚未建立 API 金鑰",- "description": "建立 API 金鑰以認證你的請求"+ "description": "建立 API 金鑰以認證你的請求",+ "loadErrorTitle": "無法載入 API 金鑰",+ "forbiddenTitle": "無權存取 API 金鑰",+ "forbiddenDesc": "管理 API 金鑰需要一個不受特定工作階段限制的管理員金鑰。"},"confirm": {"deleteTitle": "刪除 API 金鑰",diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.tsindex ece08f8d9..d1c7a96e1 100644--- a/dashboard/src/pages/ApiKeys.test.ts+++ b/dashboard/src/pages/ApiKeys.test.ts@@ -11,12 +11,18 @@ function jsonResponse(data: unknown, status = 200): Response {return new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } });}+// The status GET /auth/api-keys answers with: 200 lists the key below.+let listStatus = 200;+function installFetchStub(): void {globalThis.fetch = ((input: RequestInfo | URL): Promise<Response> => {const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;const path = url.replace(/^https?:\/\/[^/]+/, '');if (path === '/api/sessions') return Promise.resolve(jsonResponse([]));if (path === '/api/auth/api-keys') {+ if (listStatus !== 200) {+ return Promise.resolve(jsonResponse({ message: 'This API key cannot access this resource' }, listStatus));+ }return Promise.resolve(jsonResponse([{@@ -55,8 +61,20 @@ afterEach(() => {rtl.cleanup();queryClient?.clear();queryClient = undefined;+ listStatus = 200;});+function renderApiKeys(): void {+ queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 1_000 } } });+ rtl.render(+ createElement(+ QueryClientProvider,+ { client: queryClient },+ createElement(ToastProvider, null, createElement(ApiKeys)),+ ),+ );+}+test('a key row shows its prefix masked and offers no show/hide toggle', async () => {queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 1_000 } } });rtl.render(@@ -72,3 +90,19 @@ test('a key row shows its prefix masked and offers no show/hide toggle', async ('the row offers to show a key it does not have',);});++// An admin key restricted to sessions is refused here (the route needs an unscoped key), and a+// failed read is not an empty list: "No API keys created" would read as a gateway with no keys.+test('a refused read says so instead of showing the empty state', async () => {+ listStatus = 403;+ renderApiKeys();+ await rtl.screen.findByText('No access to API keys');+ assert.ok(!rtl.screen.queryByText('No API keys created'), 'a refused read rendered as an empty list');+});++test('a failed read shows the error instead of the empty state', async () => {+ listStatus = 500;+ renderApiKeys();+ await rtl.screen.findByText('Could not load API keys');+ assert.ok(!rtl.screen.queryByText('No API keys created'), 'a failed read rendered as an empty list');+});diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsxindex e47679740..fb2d04404 100644--- a/dashboard/src/pages/ApiKeys.tsx+++ b/dashboard/src/pages/ApiKeys.tsx@@ -64,7 +64,7 @@ export function ApiKeys() {const { t } = useTranslation();const toast = useToast();useDocumentTitle(t('apiKeys.title'));- const { data: apiKeys = [], isLoading: loading, isError: apiKeysError } = useApiKeysQuery();+ const { data: apiKeys = [], isLoading: loading, error: apiKeysError } = useApiKeysQuery();const { data: sessions = [] } = useSessionsQuery();const createMutation = useCreateApiKeyMutation();const updateMutation = useUpdateApiKeyMutation();@@ -296,7 +296,7 @@ export function ApiKeys() {}/>- {apiKeysError && (+ {apiKeysError && apiKeys.length > 0 && (<div className="error-banner" role="alert"><AlertCircle size={20} /><span className="error-banner-text">{t('dashboard.loadError')}</span>@@ -422,7 +422,25 @@ export function ApiKeys() {<div className="api-keys-content"><div className="keys-table-container">- {apiKeys.length === 0 ? (+ {apiKeysError && apiKeys.length === 0 ? (+ // A failed read is not an empty list: an admin key restricted to sessions always gets 403+ // here (the route needs an unscoped key), and "No API keys created" would read as a gateway+ // with no keys at all.+ <div className="empty-table-state" role="alert">+ <AlertCircle size={48} strokeWidth={1} />+ {(apiKeysError as { status?: number }).status === 403 ? (+ <>+ <h3>{t('apiKeys.empty.forbiddenTitle')}</h3>+ <p>{t('apiKeys.empty.forbiddenDesc')}</p>+ </>+ ) : (+ <>+ <h3>{t('apiKeys.empty.loadErrorTitle')}</h3>+ <p>{apiKeysError.message}</p>+ </>+ )}+ </div>+ ) : apiKeys.length === 0 ? (<div className="empty-table-state"><KeyRound size={48} strokeWidth={1} /><h3>{t('apiKeys.empty.title')}</h3>