Files
govoplan-policy/webui/src/api/adminTargets.ts
T
2026-07-11 02:34:58 +02:00

57 lines
1.7 KiB
TypeScript

import { apiFetch, type ApiSettings, type DeltaDeletedItem } from "@govoplan/core-webui";
export type RoleSummary = {
id: string;
slug: string;
name: string;
permissions: string[];
};
export type GroupSummary = {
id: string;
slug: string;
name: string;
description?: string | null;
is_active: boolean;
member_count: number;
member_ids: string[];
roles: RoleSummary[];
};
export type UserAdminItem = {
id: string;
account_id: string;
tenant_id: string;
email: string;
display_name?: string | null;
is_active: boolean;
groups: GroupSummary[];
roles: RoleSummary[];
};
type DeltaResponseFields = {
deleted: DeltaDeletedItem[];
watermark?: string | null;
has_more: boolean;
full: boolean;
};
export type UserListDeltaResponse = { users: UserAdminItem[] } & DeltaResponseFields;
export type GroupListDeltaResponse = { groups: GroupSummary[] } & DeltaResponseFields;
function deltaSuffix(options: { since?: string | null; limit?: number } = {}): string {
const params = new URLSearchParams();
if (options.since) params.set("since", options.since);
if (options.limit) params.set("limit", String(options.limit));
const suffix = params.toString();
return suffix ? `?${suffix}` : "";
}
export function fetchUsersDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<UserListDeltaResponse> {
return apiFetch(settings, `/api/v1/admin/users/delta${deltaSuffix(options)}`);
}
export function fetchGroupsDelta(settings: ApiSettings, options: { since?: string | null; limit?: number } = {}): Promise<GroupListDeltaResponse> {
return apiFetch(settings, `/api/v1/admin/groups/delta${deltaSuffix(options)}`);
}