/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see .
*/
/** @jsxRuntime automatic */
/** @jsxImportSource hono/jsx */
import {hasPermission} from '@fluxer/admin/src/AccessControlList';
import {ALL_ACLS} from '@fluxer/admin/src/AdminPackageConstants';
import {listApiKeys} from '@fluxer/admin/src/api/AdminApiKeys';
import {Layout} from '@fluxer/admin/src/components/Layout';
import {Badge} from '@fluxer/admin/src/components/ui/Badge';
import {FormFieldGroup} from '@fluxer/admin/src/components/ui/Form/FormFieldGroup';
import {Input} from '@fluxer/admin/src/components/ui/Input';
import {HStack} from '@fluxer/admin/src/components/ui/Layout/HStack';
import {PageLayout} from '@fluxer/admin/src/components/ui/Layout/PageLayout';
import {VStack} from '@fluxer/admin/src/components/ui/Layout/VStack';
import {Caption, Heading, Label, Text} from '@fluxer/admin/src/components/ui/Typography';
import type {Session} from '@fluxer/admin/src/types/App';
import type {AdminConfig as Config} from '@fluxer/admin/src/types/Config';
import {AdminACLs} from '@fluxer/constants/src/AdminACLs';
import type {Flash} from '@fluxer/hono/src/Flash';
import type {CreateAdminApiKeyResponse, ListAdminApiKeyResponse} from '@fluxer/schema/src/domains/admin/AdminSchemas';
import type {UserAdminResponse} from '@fluxer/schema/src/domains/admin/AdminUserSchemas';
import {Alert} from '@fluxer/ui/src/components/Alert';
import {Button} from '@fluxer/ui/src/components/Button';
import {Card} from '@fluxer/ui/src/components/Card';
import {CsrfInput} from '@fluxer/ui/src/components/CsrfInput';
import {EmptyState} from '@fluxer/ui/src/components/EmptyState';
import {FlashMessage} from '@fluxer/ui/src/components/Flash';
import {Checkbox} from '@fluxer/ui/src/components/Form';
import type {FC} from 'hono/jsx';
export interface AdminApiKeysPageProps {
config: Config;
session: Session;
currentAdmin: UserAdminResponse | undefined;
flash: Flash | undefined;
assetVersion: string;
createdKey: CreateAdminApiKeyResponse | undefined;
flashAfterAction: Flash | undefined;
csrfToken: string;
}
export async function AdminApiKeysPage({
config,
session,
currentAdmin,
flash,
assetVersion,
createdKey,
flashAfterAction,
csrfToken,
}: AdminApiKeysPageProps) {
const adminAcls = currentAdmin?.acls ?? [];
const hasPermissionToManage = hasPermission(adminAcls, AdminACLs.ADMIN_API_KEY_MANAGE);
if (!hasPermissionToManage) {
return (
);
}
const apiKeysResult = await listApiKeys(config, session);
const apiKeys = apiKeysResult.ok ? apiKeysResult.data : undefined;
return (
);
}
const RenderKeyManagement: FC<{
config: Config;
createdKey: CreateAdminApiKeyResponse | undefined;
flashAfterAction: Flash | undefined;
apiKeys: Array | undefined;
adminAcls: Array;
csrfToken: string;
}> = ({config, createdKey, flashAfterAction, apiKeys, adminAcls, csrfToken}) => {
return (
);
};
const RenderCreateForm: FC<{
config: Config;
createdKey: CreateAdminApiKeyResponse | undefined;
adminAcls: Array;
csrfToken: string;
}> = ({config, createdKey, adminAcls, csrfToken}) => {
const createdKeyView = createdKey ? : null;
const availableAcls = ALL_ACLS.filter((acl) => hasPermission(adminAcls, acl));
return (
Create Admin API Key
{createdKeyView}
);
};
const RenderCreatedKey: FC<{createdKey: CreateAdminApiKeyResponse}> = ({createdKey}) => {
return (
API Key Created Successfully
Save this key now. You won't be able to see it again.
{createdKey.key}