KI-AGENT: Zentralen Push-Server Stack ergänzen

This commit is contained in:
2026-05-22 16:53:27 +02:00
parent 19bab852de
commit 5a4de421ce
43 changed files with 17731 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json* ./
COPY apps/admin/package.json apps/admin/package.json
RUN npm install
FROM deps AS build
COPY . .
RUN npm run build --workspace @fedeo/push-admin
FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/apps/admin/.output ./.output
EXPOSE 3000
CMD ["node", ".output/server/index.mjs"]

View File

@@ -0,0 +1,5 @@
<template>
<UApp>
<NuxtPage />
</UApp>
</template>

View File

@@ -0,0 +1,12 @@
html,
body,
#__nuxt {
min-height: 100%;
}
body {
margin: 0;
background: #f8fafc;
color: #111827;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

View File

@@ -0,0 +1,31 @@
<script setup lang="ts">
const route = useRoute();
const items = [
{ label: "Übersicht", icon: "i-lucide-layout-dashboard", to: "/" },
{ label: "Instanzen", icon: "i-lucide-server-cog", to: "/instances" },
{ label: "Zustellungen", icon: "i-lucide-send", to: "/jobs" },
];
</script>
<template>
<div class="min-h-screen">
<header class="border-b border-gray-200 bg-white">
<div class="mx-auto flex max-w-7xl items-center justify-between px-4 py-4 sm:px-6 lg:px-8">
<div>
<p class="text-xs font-semibold uppercase tracking-wide text-green-700">FEDEO Push</p>
<h1 class="text-xl font-bold text-gray-950">Zentraler Push-Server</h1>
</div>
<UBadge color="success" variant="soft">Admin</UBadge>
</div>
</header>
<div class="mx-auto grid max-w-7xl gap-6 px-4 py-6 sm:px-6 lg:grid-cols-[220px_1fr] lg:px-8">
<aside class="lg:sticky lg:top-6 lg:self-start">
<UNavigationMenu orientation="vertical" :items="items" />
</aside>
<main>
<slot />
</main>
</div>
</div>
</template>

View File

@@ -0,0 +1,25 @@
<script setup lang="ts">
const pushApi = usePushApi();
const draft = ref("");
onMounted(() => {
pushApi.hydrateToken();
draft.value = pushApi.token.value;
});
</script>
<template>
<UCard v-if="!pushApi.token.value" class="mx-auto mt-16 max-w-lg">
<template #header>
<div>
<h2 class="text-lg font-bold">Admin-Zugang</h2>
<p class="text-sm text-gray-500">Gib den Admin-Token aus der Push-Server-Umgebung ein.</p>
</div>
</template>
<form class="space-y-4" @submit.prevent="pushApi.setToken(draft)">
<UInput v-model="draft" type="password" placeholder="ADMIN_TOKEN" icon="i-lucide-key-round" autofocus />
<UButton type="submit" block icon="i-lucide-log-in">Verbinden</UButton>
</form>
</UCard>
<slot v-else />
</template>

View File

@@ -0,0 +1,40 @@
type FetchOptions = {
method?: "GET" | "POST" | "PATCH" | "DELETE";
body?: unknown;
};
export function usePushApi() {
const config = useRuntimeConfig();
const token = useState<string>("push-admin-token", () => "");
const setToken = (nextToken: string) => {
token.value = nextToken.trim();
if (process.client) {
localStorage.setItem("fedeo-push-admin-token", token.value);
}
};
const hydrateToken = () => {
if (process.client && !token.value) {
token.value = localStorage.getItem("fedeo-push-admin-token") || "";
}
};
const request = async <T>(path: string, options: FetchOptions = {}) => {
hydrateToken();
return await $fetch<T>(`${config.public.apiBase}${path}`, {
method: options.method || "GET",
body: options.body as Record<string, any> | BodyInit | null | undefined,
headers: {
Authorization: `Bearer ${token.value}`,
},
});
};
return {
token,
setToken,
hydrateToken,
request,
};
}

View File

@@ -0,0 +1,11 @@
export default defineNuxtConfig({
modules: ["@nuxt/ui"],
css: ["~/assets/css/main.css"],
compatibilityDate: "2026-05-22",
devtools: { enabled: true },
runtimeConfig: {
public: {
apiBase: process.env.NUXT_PUBLIC_API_BASE || "http://localhost:4020",
},
},
});

View File

@@ -0,0 +1,24 @@
{
"name": "@fedeo/push-admin",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "nuxt dev --host 0.0.0.0",
"build": "nuxt build",
"preview": "nuxt preview",
"typecheck": "nuxt typecheck"
},
"dependencies": {
"@nuxt/ui": "^3.3.7",
"nuxt": "^3.14.1592",
"vue": "^3.5.13",
"vue-router": "^4.2.5",
"zod": "^4.1.12"
},
"devDependencies": {
"@types/node": "^24.3.0",
"typescript": "^5.9.2",
"vue-tsc": "^3.1.5"
}
}

View File

@@ -0,0 +1,55 @@
<script setup lang="ts">
const pushApi = usePushApi();
const toast = useToast();
const { data, pending, refresh, error } = await useAsyncData("summary", () => pushApi.request<{
instances: number;
devices: number;
jobs: number;
failedJobs: number;
}>("/admin/summary"), { immediate: false });
onMounted(async () => {
pushApi.hydrateToken();
if (pushApi.token.value) await refresh();
});
watch(error, (nextError) => {
if (nextError) toast.add({ title: "Dashboard konnte nicht geladen werden", color: "error" });
});
</script>
<template>
<AdminShell>
<TokenGate>
<div class="space-y-6">
<div class="flex items-center justify-between">
<div>
<h2 class="text-2xl font-bold text-gray-950">Übersicht</h2>
<p class="text-sm text-gray-500">Technischer Zustand des zentralen Push-Gateways.</p>
</div>
<UButton icon="i-lucide-refresh-cw" variant="soft" :loading="pending" @click="refresh()">Aktualisieren</UButton>
</div>
<div class="grid gap-4 md:grid-cols-4">
<UCard>
<p class="text-sm text-gray-500">Instanzen</p>
<p class="mt-2 text-3xl font-bold">{{ data?.instances ?? 0 }}</p>
</UCard>
<UCard>
<p class="text-sm text-gray-500">Geräte</p>
<p class="mt-2 text-3xl font-bold">{{ data?.devices ?? 0 }}</p>
</UCard>
<UCard>
<p class="text-sm text-gray-500">Jobs</p>
<p class="mt-2 text-3xl font-bold">{{ data?.jobs ?? 0 }}</p>
</UCard>
<UCard>
<p class="text-sm text-gray-500">Fehler</p>
<p class="mt-2 text-3xl font-bold text-red-600">{{ data?.failedJobs ?? 0 }}</p>
</UCard>
</div>
</div>
</TokenGate>
</AdminShell>
</template>

View File

@@ -0,0 +1,162 @@
<script setup lang="ts">
type Instance = {
id: string;
instanceId: string;
name: string;
baseUrl: string;
status: "active" | "blocked" | "disabled";
mode: "minimal" | "rich";
capabilities: string[];
currentSecretPreview: string;
nextSecretPreview?: string | null;
lastHeartbeatAt?: string | null;
};
const pushApi = usePushApi();
const toast = useToast();
const createOpen = ref(false);
const createdSecret = ref("");
const form = reactive({
name: "",
baseUrl: "",
mode: "minimal",
capabilities: "ios_push,minimal_payload",
});
const { data: instances, pending, refresh } = await useAsyncData("instances", () => pushApi.request<Instance[]>("/admin/instances"), {
default: () => [],
immediate: false,
});
onMounted(async () => {
pushApi.hydrateToken();
if (pushApi.token.value) await refresh();
});
async function createInstance() {
const created = await pushApi.request<Instance & { clientSecret: string }>("/admin/instances", {
method: "POST",
body: {
name: form.name,
baseUrl: form.baseUrl,
mode: form.mode,
capabilities: form.capabilities.split(",").map((item) => item.trim()).filter(Boolean),
},
});
createdSecret.value = created.clientSecret;
createOpen.value = false;
form.name = "";
form.baseUrl = "";
await refresh();
toast.add({ title: "Instanz angelegt", color: "success" });
}
async function patchInstance(instance: Instance, status: Instance["status"]) {
await pushApi.request(`/admin/instances/${instance.id}`, {
method: "PATCH",
body: { status },
});
await refresh();
}
async function rotateSecret(instance: Instance) {
const result = await pushApi.request<Instance & { nextClientSecret: string }>(`/admin/instances/${instance.id}/rotate-secret`, {
method: "POST",
body: {},
});
createdSecret.value = result.nextClientSecret;
await refresh();
}
</script>
<template>
<AdminShell>
<TokenGate>
<div class="space-y-6">
<div class="flex flex-wrap items-center justify-between gap-3">
<div>
<h2 class="text-2xl font-bold text-gray-950">Instanzen</h2>
<p class="text-sm text-gray-500">Selfhosted FEDEO-Instanzen und ihre Gateway-Schlüssel.</p>
</div>
<div class="flex gap-2">
<UButton icon="i-lucide-refresh-cw" variant="soft" :loading="pending" @click="refresh()">Aktualisieren</UButton>
<UButton icon="i-lucide-plus" @click="createOpen = true">Instanz</UButton>
</div>
</div>
<UAlert
v-if="createdSecret"
color="warning"
icon="i-lucide-key-round"
title="Schlüssel nur jetzt kopieren"
:description="createdSecret"
/>
<div class="grid gap-4">
<UCard v-for="instance in instances" :key="instance.id">
<div class="flex flex-wrap items-start justify-between gap-4">
<div class="min-w-0">
<div class="flex items-center gap-2">
<h3 class="truncate text-lg font-bold">{{ instance.name }}</h3>
<UBadge :color="instance.status === 'active' ? 'success' : instance.status === 'blocked' ? 'error' : 'neutral'" variant="soft">
{{ instance.status }}
</UBadge>
</div>
<p class="mt-1 text-sm text-gray-500">{{ instance.instanceId }}</p>
<p class="mt-1 text-sm text-gray-700">{{ instance.baseUrl }}</p>
<div class="mt-3 flex flex-wrap gap-2">
<UBadge v-for="capability in instance.capabilities" :key="capability" color="success" variant="subtle">
{{ capability }}
</UBadge>
</div>
</div>
<div class="flex flex-wrap gap-2">
<UButton icon="i-lucide-key-round" variant="soft" @click="rotateSecret(instance)">Rotieren</UButton>
<UButton v-if="instance.status !== 'active'" color="success" variant="soft" @click="patchInstance(instance, 'active')">Aktivieren</UButton>
<UButton v-else color="error" variant="soft" @click="patchInstance(instance, 'blocked')">Sperren</UButton>
<UButton icon="i-lucide-arrow-right" variant="ghost" :to="`/instances/${instance.id}`" />
</div>
</div>
<div class="mt-4 grid gap-3 text-sm md:grid-cols-3">
<div>
<p class="text-gray-500">Aktueller Schlüssel</p>
<p class="font-mono">{{ instance.currentSecretPreview }}</p>
</div>
<div>
<p class="text-gray-500">Nächster Schlüssel</p>
<p class="font-mono">{{ instance.nextSecretPreview || "nicht gesetzt" }}</p>
</div>
<div>
<p class="text-gray-500">Heartbeat</p>
<p>{{ instance.lastHeartbeatAt ? new Date(instance.lastHeartbeatAt).toLocaleString() : "noch keiner" }}</p>
</div>
</div>
</UCard>
</div>
</div>
<UModal v-model:open="createOpen" title="Instanz anlegen">
<template #body>
<form class="space-y-4" @submit.prevent="createInstance">
<UFormField label="Name">
<UInput v-model="form.name" placeholder="Kunde / Selfhost-Instanz" />
</UFormField>
<UFormField label="Basis-URL">
<UInput v-model="form.baseUrl" placeholder="https://app.example.com" />
</UFormField>
<UFormField label="Payload-Modus">
<USelect v-model="form.mode" :items="['minimal', 'rich']" />
</UFormField>
<UFormField label="Fähigkeiten">
<UInput v-model="form.capabilities" />
</UFormField>
<div class="flex justify-end gap-2">
<UButton variant="soft" @click="createOpen = false">Abbrechen</UButton>
<UButton type="submit">Anlegen</UButton>
</div>
</form>
</template>
</UModal>
</TokenGate>
</AdminShell>
</template>

View File

@@ -0,0 +1,108 @@
<script setup lang="ts">
const route = useRoute();
const pushApi = usePushApi();
const id = route.params.id as string;
const { data: instance, refresh: refreshInstance } = await useAsyncData(`instance-${id}`, () => pushApi.request<Record<string, any>>(`/admin/instances/${id}`), { immediate: false });
const { data: devices, refresh: refreshDevices } = await useAsyncData(`devices-${id}`, () => pushApi.request<Record<string, any>[]>(`/admin/instances/${id}/devices`), { default: () => [], immediate: false });
const { data: jobs, refresh: refreshJobs } = await useAsyncData(`jobs-${id}`, () => pushApi.request<Record<string, any>[]>(`/admin/instances/${id}/jobs`), { default: () => [], immediate: false });
onMounted(async () => {
pushApi.hydrateToken();
if (pushApi.token.value) {
await refreshAll();
}
});
async function refreshAll() {
await Promise.all([refreshInstance(), refreshDevices(), refreshJobs()]);
}
</script>
<template>
<AdminShell>
<TokenGate>
<div class="space-y-6">
<div class="flex items-center justify-between">
<div>
<UButton to="/instances" icon="i-lucide-arrow-left" variant="ghost" size="sm">Zurück</UButton>
<h2 class="mt-2 text-2xl font-bold">{{ instance?.name || "Instanz" }}</h2>
<p class="text-sm text-gray-500">{{ instance?.instanceId }}</p>
</div>
<UButton icon="i-lucide-refresh-cw" variant="soft" @click="refreshAll">Aktualisieren</UButton>
</div>
<div class="grid gap-4 md:grid-cols-3">
<UCard>
<p class="text-sm text-gray-500">Geräte</p>
<p class="mt-2 text-3xl font-bold">{{ instance?.deviceCount ?? 0 }}</p>
</UCard>
<UCard>
<p class="text-sm text-gray-500">Zustelljobs</p>
<p class="mt-2 text-3xl font-bold">{{ instance?.jobCount ?? 0 }}</p>
</UCard>
<UCard>
<p class="text-sm text-gray-500">Status</p>
<p class="mt-2 text-xl font-bold">{{ instance?.status }}</p>
</UCard>
</div>
<UCard>
<template #header>
<h3 class="font-bold">Geräte</h3>
</template>
<div class="overflow-x-auto">
<table class="w-full text-left text-sm">
<thead class="text-gray-500">
<tr>
<th class="py-2">Central ID</th>
<th>Plattform</th>
<th>Status</th>
<th>Zuletzt gesehen</th>
</tr>
</thead>
<tbody>
<tr v-for="device in devices" :key="device.id" class="border-t border-gray-100">
<td class="py-2 font-mono">{{ device.centralDeviceId }}</td>
<td>{{ device.platform }}</td>
<td>{{ device.status }}</td>
<td>{{ new Date(device.lastSeenAt).toLocaleString() }}</td>
</tr>
</tbody>
</table>
</div>
</UCard>
<UCard>
<template #header>
<h3 class="font-bold">Letzte Zustelljobs</h3>
</template>
<div class="overflow-x-auto">
<table class="w-full text-left text-sm">
<thead class="text-gray-500">
<tr>
<th class="py-2">Job</th>
<th>Status</th>
<th>Angenommen</th>
<th>Gesendet</th>
<th>Fehler</th>
<th>Erstellt</th>
</tr>
</thead>
<tbody>
<tr v-for="job in jobs" :key="job.id" class="border-t border-gray-100">
<td class="py-2 font-mono">{{ job.deliveryJobId }}</td>
<td>{{ job.status }}</td>
<td>{{ job.acceptedCount }}</td>
<td>{{ job.sentCount }}</td>
<td>{{ job.failedCount }}</td>
<td>{{ new Date(job.createdAt).toLocaleString() }}</td>
</tr>
</tbody>
</table>
</div>
</UCard>
</div>
</TokenGate>
</AdminShell>
</template>

View File

@@ -0,0 +1,56 @@
<script setup lang="ts">
const pushApi = usePushApi();
const { data: jobs, pending, refresh } = await useAsyncData("jobs", () => pushApi.request<Record<string, any>[]>("/admin/jobs"), {
default: () => [],
immediate: false,
});
onMounted(async () => {
pushApi.hydrateToken();
if (pushApi.token.value) await refresh();
});
</script>
<template>
<AdminShell>
<TokenGate>
<div class="space-y-6">
<div class="flex items-center justify-between">
<div>
<h2 class="text-2xl font-bold text-gray-950">Zustellungen</h2>
<p class="text-sm text-gray-500">Letzte technische Push-Aufträge aller Instanzen.</p>
</div>
<UButton icon="i-lucide-refresh-cw" variant="soft" :loading="pending" @click="refresh()">Aktualisieren</UButton>
</div>
<UCard>
<div class="overflow-x-auto">
<table class="w-full text-left text-sm">
<thead class="text-gray-500">
<tr>
<th class="py-2">Job</th>
<th>Status</th>
<th>Angenommen</th>
<th>Gesendet</th>
<th>Fehler</th>
<th>Letzter Fehler</th>
<th>Erstellt</th>
</tr>
</thead>
<tbody>
<tr v-for="job in jobs" :key="job.id" class="border-t border-gray-100">
<td class="py-2 font-mono">{{ job.deliveryJobId }}</td>
<td>{{ job.status }}</td>
<td>{{ job.acceptedCount }}</td>
<td>{{ job.sentCount }}</td>
<td>{{ job.failedCount }}</td>
<td>{{ job.lastErrorCode || "-" }}</td>
<td>{{ new Date(job.createdAt).toLocaleString() }}</td>
</tr>
</tbody>
</table>
</div>
</UCard>
</div>
</TokenGate>
</AdminShell>
</template>

View File

@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}