import type { CatalogProvider, Product } from "@/lib/headless/types"; interface ShopifyGraphQLResponse { data?: T; errors?: Array<{ message: string }>; } async function shopifyFetch(query: string, variables: Record = {}): Promise { const url = process.env.SHOPIFY_STOREFRONT_URL; const token = process.env.SHOPIFY_STOREFRONT_TOKEN; if (!url || !token) throw new Error("Shopify Storefront API no está configurada."); const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", "X-Shopify-Storefront-Access-Token": token, }, body: JSON.stringify({ query, variables }), next: { revalidate: 300 }, }); if (!response.ok) throw new Error(`Shopify respondió HTTP ${response.status}`); const payload = (await response.json()) as ShopifyGraphQLResponse; if (payload.errors?.length) throw new Error(payload.errors.map((error) => error.message).join("; ")); if (!payload.data) throw new Error("Shopify no devolvió datos."); return payload.data; } function notImplemented(): never { throw new Error("Completa el mapeo Shopify → Product en lib/headless/providers/shopify.ts."); } export const shopifyCatalogProvider: CatalogProvider = { async getProducts() { await shopifyFetch<{ products: unknown }>(`query Products { products(first: 24) { nodes { id title handle } } }`); return notImplemented(); }, async getProductBySlug(): Promise { return notImplemented(); }, async searchProducts(): Promise { return notImplemented(); }, };