feat: real API integration + YouTube Data API v3 + progressive loading
- Replace mock useReport() with real Supabase API data pipeline - Add transformReport.ts to map API responses to MarketingReport type - Add useEnrichment() hook for background channel data enrichment - Replace Apify YouTube scraper with YouTube Data API v3 - Add mergeEnrichment() for progressive data loading - Add EmptyState component for graceful empty data handling - Add socialHandles to generate-report metadata - Graceful empty data in ClinicSnapshot, YouTube, Instagram, Facebook - Add Supabase Edge Functions and DB migrations - Add developer handoff documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c6e18b6a67
commit
60cd055042
30 files changed
+2905
-142
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
|
||||
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
|
||||
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
|
||||
|
||||
export const supabase = createClient(supabaseUrl, supabaseAnonKey);
|
||||
|
||||
export async function generateMarketingReport(url: string, clinicName?: string) {
|
||||
const response = await fetch(
|
||||
`${supabaseUrl}/functions/v1/generate-report`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ url, clinicName }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Report generation failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function fetchReportById(reportId: string) {
|
||||
const { data, error } = await supabase
|
||||
.from("marketing_reports")
|
||||
.select("*")
|
||||
.eq("id", reportId)
|
||||
.single();
|
||||
|
||||
if (error) throw new Error(`Failed to fetch report: ${error.message}`);
|
||||
return data;
|
||||
}
|
||||
|
||||
export interface EnrichChannelsRequest {
|
||||
reportId: string;
|
||||
clinicName: string;
|
||||
instagramHandle?: string;
|
||||
youtubeChannelId?: string;
|
||||
address?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire-and-forget: triggers background channel enrichment.
|
||||
* Returns enrichment result when the Edge Function completes (~27s).
|
||||
*/
|
||||
export async function enrichChannels(params: EnrichChannelsRequest) {
|
||||
const response = await fetch(
|
||||
`${supabaseUrl}/functions/v1/enrich-channels`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(params),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Channel enrichment failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function scrapeWebsite(url: string, clinicName?: string) {
|
||||
const response = await fetch(
|
||||
`${supabaseUrl}/functions/v1/scrape-website`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ url, clinicName }),
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Scraping failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
Reference in new issue
Block a user