refactor: introduce dedicated identifier types for improved clarity and type safety

This commit is contained in:
2025-11-24 23:47:36 +01:00
parent 22f0c040a2
commit 70e7bda87e
79 changed files with 1567 additions and 1572 deletions
+11 -10
View File
@@ -6,6 +6,7 @@ import {
regenerateApiToken,
type ApiTokenRecord,
} from '../lib/apiClient';
import type { ApiTokenId, CapabilitySetId } from '../types/identifiers';
interface ApiTokensResponse {
token_info?: ApiTokenRecord;
@@ -15,7 +16,7 @@ interface ApiTokensResponse {
interface CreateTokenArgs {
label?: string;
expires_at?: string;
capability_set_id?: string | number;
capability_set_id?: CapabilitySetId;
}
interface UseApiTokensArgs {
@@ -28,13 +29,13 @@ interface UseApiTokensResult {
tokens: ApiTokenRecord[];
loading: boolean;
creating: boolean;
deletingId: string | number | null;
regeneratingId: string | number | null;
deletingId: ApiTokenId | null;
regeneratingId: ApiTokenId | null;
createdSecret: string | null;
refresh: () => Promise<void>;
create: (args?: CreateTokenArgs) => Promise<ApiTokensResponse | false>;
revoke: (tokenId?: string | number | null) => Promise<boolean>;
regenerate: (tokenId?: string | number | null) => Promise<boolean>;
revoke: (tokenId?: ApiTokenId | null) => Promise<boolean>;
regenerate: (tokenId?: ApiTokenId | null) => Promise<boolean>;
dismissSecret: () => void;
}
@@ -42,8 +43,8 @@ const useApiTokens = ({ notifyApiError, setStatusMessage, token }: UseApiTokensA
const [tokens, setTokens] = useState<ApiTokenRecord[]>([]);
const [loading] = useState(false);
const [creating, setCreating] = useState(false);
const [deletingId, setDeletingId] = useState<string | number | null>(null);
const [regeneratingId, setRegeneratingId] = useState<string | number | null>(null);
const [deletingId, setDeletingId] = useState<ApiTokenId | null>(null);
const [regeneratingId, setRegeneratingId] = useState<ApiTokenId | null>(null);
const [createdSecret, setCreatedSecret] = useState<string | null>(null);
const refresh = useCallback(async () => {
@@ -65,7 +66,7 @@ const useApiTokens = ({ notifyApiError, setStatusMessage, token }: UseApiTokensA
}
setCreating(true);
try {
const payload: { capability_set_id: string | number; label?: string; expires_at?: string } = { capability_set_id };
const payload: { capability_set_id: CapabilitySetId; label?: string; expires_at?: string } = { capability_set_id };
if (label) {
payload.label = label;
}
@@ -100,7 +101,7 @@ const useApiTokens = ({ notifyApiError, setStatusMessage, token }: UseApiTokensA
);
const revoke = useCallback(
async (tokenId?: string | number | null) => {
async (tokenId?: string | null) => {
if (!tokenId) {
return false;
}
@@ -121,7 +122,7 @@ const useApiTokens = ({ notifyApiError, setStatusMessage, token }: UseApiTokensA
);
const regenerate = useCallback(
async (tokenId?: string | number | null) => {
async (tokenId?: string | null) => {
if (!tokenId) {
return false;
}