Добавлены логи для валидации API ключей в компонентах MarketplaceApiStep и MarketplaceService. Улучшена обработка ошибок с выводом детальной информации. Оптимизирована проверка формата API ключа для Wildberries. Обновлены сообщения для улучшения отладки.
This commit is contained in:
@ -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]: {
|
||||
|
@ -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(),
|
||||
|
@ -38,12 +38,38 @@ export class MarketplaceService {
|
||||
*/
|
||||
async validateWildberriesApiKey(apiKey: string): Promise<MarketplaceValidationResult> {
|
||||
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)
|
||||
|
Reference in New Issue
Block a user