88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import { Product, AuctionLot, BiddingTender } from "../types";
|
|
import { supabase } from "./supabase";
|
|
|
|
// Removed API_KEY check for frontend as we now use Edge Functions
|
|
|
|
/**
|
|
* Helper: converte File em Part (inlineData) para o Gemini
|
|
* @deprecated Moved to Backend
|
|
*/
|
|
async function fileToPart(file: File) {
|
|
throw new Error("File processing must be moved to Backend Edge Functions.");
|
|
}
|
|
|
|
/**
|
|
* Sourcing Otimizado: Via Supabase Edge Function
|
|
*/
|
|
export async function searchProducts(
|
|
query: string,
|
|
currentExchangeRate?: number
|
|
): Promise<{ products: Product[]; sources: any[] }> {
|
|
try {
|
|
console.log("🚀 Calling Edge Function: search-products for:", query);
|
|
|
|
// Call Supabase Edge Function
|
|
const { data, error } = await supabase.functions.invoke('search-products', {
|
|
body: {
|
|
query,
|
|
kind: "products"
|
|
}
|
|
});
|
|
|
|
if (error) throw error;
|
|
|
|
console.log(`📦 Edge Function Result: ${data.cache}`);
|
|
|
|
let products = data.products || [];
|
|
const sources = data.sources || [];
|
|
|
|
// Recalculate BRL if exchange rate provided
|
|
if (currentExchangeRate && Array.isArray(products)) {
|
|
products = products.map((p: any) => ({
|
|
...p,
|
|
priceBRL: p.priceUSD * currentExchangeRate
|
|
}));
|
|
}
|
|
|
|
return { products, sources };
|
|
|
|
} catch (error) {
|
|
console.error("Erro na busca de produtos (Edge Function):", error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Busca Oportunidades (>25% Margem) por Categoria
|
|
* @todo Migrate to Edge Function
|
|
*/
|
|
export async function searchOpportunities(
|
|
category: string,
|
|
includeOverhead: boolean = true,
|
|
currentExchangeRate?: number
|
|
): Promise<{ products: Product[]; sources: any[] }> {
|
|
console.warn("searchOpportunities not yet migrated to Edge Function.");
|
|
return { products: [], sources: [] };
|
|
}
|
|
|
|
/**
|
|
* Leilões: Analisa texto, link ou ARQUIVO PDF
|
|
* @todo Migrate to Edge Function
|
|
*/
|
|
export async function analyzeAuctionData(
|
|
input: string | File
|
|
): Promise<{ lot: AuctionLot | null; sources: any[] }> {
|
|
console.warn("analyzeAuctionData not yet migrated to Edge Function.");
|
|
return { lot: null, sources: [] };
|
|
}
|
|
|
|
/**
|
|
* Licitações Otimizadas
|
|
* @todo Migrate to Edge Function
|
|
*/
|
|
export async function searchBiddings(
|
|
query: string
|
|
): Promise<{ tenders: BiddingTender[]; sources: any[] }> {
|
|
console.warn("searchBiddings not yet migrated to Edge Function.");
|
|
return { tenders: [], sources: [] };
|
|
}
|