a222711ad9
- Migration: ModuleGrant.level (USE/MANAGE), Bestand bleibt USE - ModuleAccessService.getModuleAccessLevels als einzige Auflösung, MANAGE gewinnt - @ModuleManage(slug) am ModuleGuard, GET /modules/active liefert canManage - Kantinenabrechnung: Einstellungen für Benutzer mit Verwalten, Web-Hook useCanManageModule Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
/**
|
|
* API client utilities for the Tessera frontend.
|
|
*
|
|
* Provides typed fetch wrappers for common API endpoints.
|
|
* All functions accept a cookie string for server-side auth forwarding.
|
|
*/
|
|
|
|
const API_URL = process.env.API_INTERNAL_URL || process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';
|
|
|
|
/**
|
|
* Module data shape from the API.
|
|
*/
|
|
export interface ApiModule {
|
|
id: string;
|
|
name: string;
|
|
slug: string;
|
|
category: string;
|
|
description: Record<string, string> | string;
|
|
icon?: string;
|
|
version: string;
|
|
isSystem: boolean;
|
|
/** Freigabestufe Verwalten (261002-icv) — nur Anzeige, bindend bleibt die API. */
|
|
canManage?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Fetch all active modules for the current tenant.
|
|
*
|
|
* @param cookie - Cookie header value for auth forwarding
|
|
* @returns Array of active modules
|
|
*/
|
|
export async function getActiveModules(cookie: string): Promise<ApiModule[]> {
|
|
const response = await fetch(`${API_URL}/modules/active`, {
|
|
headers: { Cookie: cookie },
|
|
cache: 'no-store',
|
|
});
|
|
|
|
if (!response.ok) {
|
|
return [];
|
|
}
|
|
|
|
return response.json();
|
|
}
|
|
|
|
/**
|
|
* Find a specific module by its slug.
|
|
*
|
|
* Fetches all modules and filters by slug.
|
|
*
|
|
* @param slug - Module slug (e.g., 'domaincheck')
|
|
* @param cookie - Cookie header value for auth forwarding
|
|
* @returns The module if found, or null
|
|
*/
|
|
export async function getModuleBySlug(
|
|
slug: string,
|
|
cookie: string,
|
|
): Promise<ApiModule | null> {
|
|
const response = await fetch(`${API_URL}/modules`, {
|
|
headers: { Cookie: cookie },
|
|
cache: 'no-store',
|
|
});
|
|
|
|
if (!response.ok) {
|
|
return null;
|
|
}
|
|
|
|
const modules: ApiModule[] = await response.json();
|
|
return modules.find((m) => m.slug === slug) ?? null;
|
|
}
|