/**
* get_domain_pricing - Domain pricing tool
*
* Two-tier pricing system:
* 1. Static JSON (default) - Fast, no authentication required
* 2. Real-time DMAPI (optional) - Requires Joker.com credentials
*
* Results are cached for 6 hours (configurable) to reduce API load.
*/
import { fetchJokerPricing } from '../pricing-fetcher.js';
import { priceCache } from '../price-cache.js';
/**
* Get domain pricing with caching
*/
export async function getDomainPricing(args: {
domain: string;
force_refresh?: boolean;
use_api?: boolean;
}): Promise<{
content: Array<{
type: string;
text: string;
}>;
}> {
const { domain, force_refresh = false, use_api = false } = args;
// Validate input
if (!domain || typeof domain !== 'string' || domain.trim() === '') {
throw new Error('domain parameter is required and must be a non-empty string');
}
const normalizedDomain = domain.toLowerCase().trim();
try {
// Check cache (unless force_refresh)
if (!force_refresh) {
const cached = priceCache.get(normalizedDomain);
if (cached) {
return {
content: [{
type: 'text',
text: JSON.stringify({ ...cached, from_cache: true }, null, 2),
}],
};
}
}
// Fetch pricing (static by default, DMAPI if use_api=true)
const pricingResult = await fetchJokerPricing(normalizedDomain, { use_api });
// Update cache (only if no error)
if (!pricingResult.error) {
priceCache.set(normalizedDomain, pricingResult);
}
return {
content: [{
type: 'text',
text: JSON.stringify({ ...pricingResult, from_cache: false }, null, 2),
}],
};
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to fetch pricing for ${normalizedDomain}: ${message}`);
}
}