From 32b436c35d9e1e9a5fcde92cb95da80938a7872f Mon Sep 17 00:00:00 2001 From: Bivekich Date: Mon, 28 Jul 2025 09:25:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BB=D0=BE=D0=B3=D0=B8=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D0=B8=20API=20?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=B9=20=D0=B2=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=D1=85=20Market?= =?UTF-8?q?placeApiStep=20=D0=B8=20MarketplaceService.=20=D0=A3=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA=20=D1=81=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=B4=D0=B5=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D0=B8.=20?= =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0=20API?= =?UTF-8?q?=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=20=D0=B4=D0=BB=D1=8F=20Wildbe?= =?UTF-8?q?rries.=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/auth/marketplace-api-step.tsx | 5 ++- src/graphql/resolvers.ts | 10 +++++ src/services/marketplace-service.ts | 44 +++++++++++++++++--- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/components/auth/marketplace-api-step.tsx b/src/components/auth/marketplace-api-step.tsx index d338762..5479fde 100644 --- a/src/components/auth/marketplace-api-step.tsx +++ b/src/components/auth/marketplace-api-step.tsx @@ -82,6 +82,8 @@ export function MarketplaceApiStep({ onNext, onBack }: MarketplaceApiStepProps) } }) + console.log(`🎯 Client received response for ${marketplace}:`, data) + setValidationStates(prev => ({ ...prev, [marketplace]: { @@ -110,7 +112,8 @@ export function MarketplaceApiStep({ onNext, onBack }: MarketplaceApiStepProps) }) } } - } catch { + } catch (error) { + console.log(`🔴 Client validation error for ${marketplace}:`, error) setValidationStates(prev => ({ ...prev, [marketplace]: { diff --git a/src/graphql/resolvers.ts b/src/graphql/resolvers.ts index 8aa0cf8..9ab0839 100644 --- a/src/graphql/resolvers.ts +++ b/src/graphql/resolvers.ts @@ -1634,6 +1634,12 @@ export const resolvers = { const { marketplace, apiKey, clientId, validateOnly } = args.input; + console.log(`🔍 Validating ${marketplace} API key:`, { + keyLength: apiKey.length, + keyPreview: apiKey.substring(0, 20) + '...', + validateOnly + }); + // Валидируем API ключ const validationResult = await marketplaceService.validateApiKey( marketplace, @@ -1641,7 +1647,10 @@ export const resolvers = { clientId ); + console.log(`✅ Validation result for ${marketplace}:`, validationResult); + if (!validationResult.isValid) { + console.log(`❌ Validation failed for ${marketplace}:`, validationResult.message); return { success: false, message: validationResult.message, @@ -1656,6 +1665,7 @@ export const resolvers = { apiKey: { id: "validate-only", marketplace, + apiKey: "***", // Скрываем реальный ключ при валидации isActive: true, validationData: validationResult, createdAt: new Date().toISOString(), diff --git a/src/services/marketplace-service.ts b/src/services/marketplace-service.ts index f657510..4245787 100644 --- a/src/services/marketplace-service.ts +++ b/src/services/marketplace-service.ts @@ -38,12 +38,38 @@ export class MarketplaceService { */ async validateWildberriesApiKey(apiKey: string): Promise { try { - // Пытаемся получить информацию о продавце + console.log('🔵 Starting Wildberries validation for key:', apiKey.substring(0, 20) + '...'); + + // Сначала проверяем валидность ключа через ping (быстрее) + console.log('📡 Making ping request to:', `${this.wbApiUrl}/ping`); + const pingResponse = await axios.get( + `${this.wbApiUrl}/ping`, + { + headers: { + 'Authorization': `Bearer ${apiKey}` + }, + timeout: 5000 + } + ) + + console.log('📡 Ping response:', { + status: pingResponse.status, + data: pingResponse.data + }); + + if (pingResponse.status !== 200 || pingResponse.data?.Status !== 'OK') { + return { + isValid: false, + message: 'API ключ Wildberries невалиден' + } + } + + // Если ping прошёл, получаем информацию о продавце const response = await axios.get( `${this.wbApiUrl}/api/v1/seller-info`, { headers: { - 'Authorization': apiKey, + 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }, timeout: 10000 @@ -70,9 +96,17 @@ export class MarketplaceService { } } catch (error) { - console.error('Wildberries API validation error:', error) + console.error('🔴 Wildberries API validation error:', error) if (axios.isAxiosError(error)) { + console.log('🔴 Axios error details:', { + status: error.response?.status, + statusText: error.response?.statusText, + data: error.response?.data, + message: error.message, + code: error.code + }); + if (error.response?.status === 401) { return { isValid: false, @@ -219,8 +253,8 @@ export class MarketplaceService { switch (marketplace) { case 'WILDBERRIES': - // Wildberries API ключи обычно содержат буквы, цифры и дефисы - return /^[a-zA-Z0-9\-_]{10,}$/.test(apiKey) + // Wildberries API ключи (JWT токены) содержат буквы, цифры, дефисы, подчёркивания и точки + return /^[a-zA-Z0-9\-_.]{10,}$/.test(apiKey) case 'OZON': // Ozon API ключи обычно содержат буквы, цифры и дефисы return /^[a-zA-Z0-9\-_]{10,}$/.test(apiKey)