21 lines
749 B
TypeScript
21 lines
749 B
TypeScript
import type { N8nServiceWidget } from "@/lib/config/schema";
|
|||
|
|
import type { ServiceStat } from "@/lib/types/service-result";
|
||
|
|
import { serviceBaseUrl } from "./base-url";
|
||
|
|
|
||
|
|
interface N8nWorkflowsPage {
|
||
|
|
data: unknown[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function collectN8n(widget: N8nServiceWidget): Promise<{ stats: ServiceStat[] }> {
|
||
|
|
const base = serviceBaseUrl(widget);
|
||
|
|
const response = await fetch(`${base}/api/v1/workflows?limit=250`, {
|
||
|
|
headers: { "X-N8N-API-KEY": widget.apiKey },
|
||
|
|
signal: AbortSignal.timeout(5_000),
|
||
|
|
});
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`n8n API returned ${response.status}`);
|
||
|
|
}
|
||
|
|
const page = (await response.json()) as N8nWorkflowsPage;
|
||
|
|
return { stats: [{ label: "Workflows", value: String(page.data.length) }] };
|
||
|
|
}
|