interface Shop {
id: string;
name: string | null;
sales: { lifetime: number | null; est_monthly_avg: number | null; est_trend_3m: number | null };
top_products: { id: string; title: string | null; sales: { est_monthly_avg: number | null } }[];
about: { ships_from: string | null; accepts_custom_requests: boolean | null } | null;
as_of: string;
}
const res = await fetch('https://api.alura.io/v1/research/shops/48911633?expand=top_products,about', {
headers: { Authorization: `Bearer ${process.env.ALURA_API_KEY}` },
});
if (!res.ok) throw new Error(`${res.status}: ${await res.text()}`);
const shop = (await res.json()) as Shop;
const trend = shop.sales.est_trend_3m === null ? 'unknown' : `${Math.round(shop.sales.est_trend_3m * 100)}%`;
console.log(`${shop.name}: ${shop.sales.lifetime ?? 'unknown'} sales on Etsy, about ${shop.sales.est_monthly_avg ?? 'unknown'} a month, trend ${trend}`);
console.log(`Ships from ${shop.about?.ships_from ?? 'unknown'} (data as of ${shop.as_of})`);
for (const p of shop.top_products) console.log(` ${p.id} ${p.title}: ${p.sales.est_monthly_avg ?? 'unknown'} a month`);