Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions apps/api/src/api/routes/deco-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Hono } from "hono";
import type { StudioContext } from "../../core/studio-context";
import { getSettings } from "../../settings";
import { supabaseGet } from "../../deco-legacy/supabase";

type Variables = { studioContext: StudioContext };

Expand All @@ -27,8 +28,6 @@ export interface DecoAppCatalogItem {
vendor: { alias: string; url: string };
}

const SUPABASE_FETCH_TIMEOUT_MS = 10_000;

export function mapSupabaseAppRows(
rows: SupabaseAppRow[],
): DecoAppCatalogItem[] {
Expand All @@ -47,31 +46,6 @@ export function mapSupabaseAppRows(
}));
}

async function supabaseGetApps(
supabaseUrl: string,
serviceKey: string,
): Promise<SupabaseAppRow[]> {
const res = await fetch(
`${supabaseUrl}/rest/v1/apps?select=name,title,description,logo,category,vendors(alias,url)`,
{
headers: {
apikey: serviceKey,
Authorization: `Bearer ${serviceKey}`,
Accept: "application/json",
},
signal: AbortSignal.timeout(SUPABASE_FETCH_TIMEOUT_MS),
},
);
if (!res.ok) {
const text = await res.text().catch(() => res.statusText);
console.error(
`[deco-apps] Supabase error (${res.status}): ${text.slice(0, 200)}`,
);
throw new Error(`External service error (${res.status})`);
}
return (await res.json()) as SupabaseAppRow[];
}

const requireAuth = async (
c: import("hono").Context<{ Variables: Variables }>,
next: () => Promise<void>,
Expand All @@ -98,7 +72,11 @@ export const createDecoAppsRoutes = () => {
}

try {
const rows = await supabaseGetApps(supabaseUrl, serviceKey);
const rows = await supabaseGet<SupabaseAppRow>(
supabaseUrl,
serviceKey,
"apps?select=name,title,description,logo,category,vendors(alias,url)",
);
return c.json({ apps: mapSupabaseAppRows(rows) });
} catch (err) {
console.error("[deco-apps] GET error:", err);
Expand Down
Loading