#!/usr/bin/env tsx
/**
* Simple interactive test for add_user_consumed_item
* This will test the actual endpoint with real data
*/
import { Yazio } from 'yazio';
async function testRealEndpoint() {
console.log('π§ͺ Testing add_user_consumed_item with real Yazio API...\n');
// Get credentials from user
const username = process.env.YAZIO_USERNAME;
const password = process.env.YAZIO_PASSWORD;
if (!username || !password) {
console.log('β Please set your Yazio credentials:');
console.log('export YAZIO_USERNAME="your-username"');
console.log('export YAZIO_PASSWORD="your-password"');
console.log('\nThen run: npx tsx simple-test.ts');
return;
}
console.log('β
Credentials found');
console.log('π€ Username:', username);
console.log('');
try {
// Initialize Yazio client
console.log('1οΈβ£ Initializing Yazio client...');
const yazio = new Yazio({ credentials: { username, password } });
console.log('β
Client initialized');
// Test authentication
console.log('\n2οΈβ£ Testing authentication...');
const user = await yazio.user.get();
console.log('β
Authentication successful');
console.log('π€ User:', `${user.first_name} ${user.last_name}`);
// Search for a real product
console.log('\n3οΈβ£ Searching for products...');
const products = await yazio.products.search({ query: 'apple' });
console.log(products);
} catch (error) {
console.log('β Error occurred:');
console.error(error);
if (error instanceof Error) {
console.log('\nπ Error details:');
console.log('- Message:', error.message);
console.log('- Name:', error.name);
// Check for specific error types
if (error.message.includes('401') || error.message.includes('unauthorized')) {
console.log('π‘ This looks like an authentication error. Check your credentials.');
}
if (error.message.includes('product_id')) {
console.log('π‘ This looks like a product ID issue. The product might not exist or be accessible.');
}
if (error.message.includes('date')) {
console.log('π‘ This looks like a date format issue.');
}
}
}
}
// Run the test
testRealEndpoint().catch(console.error);