fix: add Authorization header to all Edge Function calls + fix Vision Analysis

- All fetch calls to Supabase Edge Functions now include
  Authorization: Bearer <anon_key> (was missing → 401 errors)
- Fix Firecrawl screenshot API: remove invalid screenshotOptions,
  use "screenshot@fullPage" format (v2 API compatibility)
- Fix screenshot response handling: v2 returns URL not base64,
  now downloads and converts to base64 for Gemini Vision
- Add about page to Vision Analysis capture targets
- Add retry utility, channel error tracking, pipeline resume,
  enrichment retry, EmptyState improvements (Sprint 2-3)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-05 10:08:03 +09:00
1 parent 2f2aa5a5b6
commit 79950925a1
12 files changed
+961 -214

No files matched your search

+44 -6
View File
@@ -5,12 +5,18 @@ const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseAnonKey);
/** Common headers for Edge Function calls (includes JWT auth) */
const fnHeaders = () => ({
"Content-Type": "application/json",
"Authorization": `Bearer ${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" },
headers: fnHeaders(),
body: JSON.stringify({ url, clinicName }),
}
);
@@ -33,6 +39,38 @@ export async function fetchReportById(reportId: string) {
return data;
}
/**
* Fetch pipeline status for a report.
* Used by AnalysisLoadingPage to resume interrupted pipelines.
*/
export interface PipelineStatus {
reportId: string;
clinicId?: string;
runId?: string;
status: string;
clinicName?: string;
hasChannelData: boolean;
hasReport: boolean;
}
export async function fetchPipelineStatus(reportId: string): Promise<PipelineStatus> {
const { data, error } = await supabase
.from("marketing_reports")
.select("id, status, clinic_name, channel_data, report")
.eq("id", reportId)
.single();
if (error || !data) throw new Error(`Report not found: ${error?.message}`);
return {
reportId: data.id,
status: data.status || "unknown",
clinicName: data.clinic_name,
hasChannelData: !!data.channel_data && Object.keys(data.channel_data).length > 0,
hasReport: !!data.report && Object.keys(data.report).length > 0,
};
}
export interface EnrichChannelsRequest {
reportId: string;
clinicName: string;
@@ -52,7 +90,7 @@ export async function enrichChannels(params: EnrichChannelsRequest) {
`${supabaseUrl}/functions/v1/enrich-channels`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
headers: fnHeaders(),
body: JSON.stringify(params),
}
);
@@ -69,7 +107,7 @@ export async function scrapeWebsite(url: string, clinicName?: string) {
`${supabaseUrl}/functions/v1/scrape-website`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
headers: fnHeaders(),
body: JSON.stringify({ url, clinicName }),
}
);
@@ -92,7 +130,7 @@ export async function discoverChannels(url: string, clinicName?: string) {
`${supabaseUrl}/functions/v1/discover-channels`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
headers: fnHeaders(),
body: JSON.stringify({ url, clinicName }),
}
);
@@ -113,7 +151,7 @@ export async function collectChannelData(reportId: string, clinicId?: string, ru
`${supabaseUrl}/functions/v1/collect-channel-data`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
headers: fnHeaders(),
body: JSON.stringify({ reportId, clinicId, runId }),
}
);
@@ -133,7 +171,7 @@ export async function generateReportV2(reportId: string, clinicId?: string, runI
`${supabaseUrl}/functions/v1/generate-report`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
headers: fnHeaders(),
body: JSON.stringify({ reportId, clinicId, runId }),
}
);