Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

fix(frontend): type the investigation-service API boundary

dextmorgne0aef871fb41
diff --git a/flowsint-app/src/api/investigation-service.ts b/flowsint-app/src/api/investigation-service.ts
index 0e68f91f..a51903b8 100644
--- a/flowsint-app/src/api/investigation-service.ts
+++ b/flowsint-app/src/api/investigation-service.ts
@@ -1,30 +1,33 @@
import { fetchWithAuth } from './api'
+import type { Investigation, Collaborator } from '@/types/investigation'
export const investigationService = {
- get: async (): Promise<any> => {
+ get: async (): Promise<Investigation[]> => {
return fetchWithAuth('/api/investigations', {
method: 'GET'
})
},
- getById: async (investigationId: string): Promise<any> => {
+ getById: async (investigationId: string): Promise<Investigation> => {
return fetchWithAuth(`/api/investigations/${investigationId}`, {
method: 'GET'
})
},
- create: async (body: BodyInit): Promise<any> => {
+ // Backend returns the created investigation on success, or an { error }
+ // payload instead of a 4xx/5xx status on failure — callers branch on `id`.
+ create: async (body: BodyInit): Promise<Investigation | { error: string }> => {
return fetchWithAuth(`/api/investigations/create`, {
method: 'POST',
body: body
})
},
- delete: async (investigationId: string): Promise<any> => {
+ delete: async (investigationId: string): Promise<unknown> => {
return fetchWithAuth(`/api/investigations/${investigationId}`, {
method: 'DELETE'
})
},
// Collaborator management
- getCollaborators: async (investigationId: string): Promise<any> => {
+ getCollaborators: async (investigationId: string): Promise<Collaborator[]> => {
return fetchWithAuth(`/api/investigations/${investigationId}/collaborators`, {
method: 'GET'
})
@@ -32,7 +35,7 @@ export const investigationService = {
addCollaborator: async (
investigationId: string,
body: { email: string; role: string }
- ): Promise<any> => {
+ ): Promise<unknown> => {
return fetchWithAuth(`/api/investigations/${investigationId}/collaborators`, {
method: 'POST',
body: JSON.stringify(body)
@@ -42,13 +45,13 @@ export const investigationService = {
investigationId: string,
userId: string,
body: { role: string }
- ): Promise<any> => {
+ ): Promise<unknown> => {
return fetchWithAuth(`/api/investigations/${investigationId}/collaborators/${userId}`, {
method: 'PUT',
body: JSON.stringify(body)
})
},
- removeCollaborator: async (investigationId: string, userId: string): Promise<any> => {
+ removeCollaborator: async (investigationId: string, userId: string): Promise<unknown> => {
return fetchWithAuth(`/api/investigations/${investigationId}/collaborators/${userId}`, {
method: 'DELETE'
})
diff --git a/flowsint-app/src/components/dashboard/overview/dashboard-page.tsx b/flowsint-app/src/components/dashboard/overview/dashboard-page.tsx
index 09735e0d..16cbe710 100644
--- a/flowsint-app/src/components/dashboard/overview/dashboard-page.tsx
+++ b/flowsint-app/src/components/dashboard/overview/dashboard-page.tsx
@@ -15,7 +15,7 @@ export function DashboardPage() {
const [search, setSearch] = useState<string>('')
const {
- data: investigations,
+ data: investigations = [],
isLoading
// error,
// refetch
@@ -28,9 +28,8 @@ export function DashboardPage() {
return <InvestigationSkeleton />
}
- const casesCount = investigations.length ?? (0 as number)
- const activeCasesCount =
- investigations.filter((i: Investigation) => i.status === 'active').length ?? (0 as number)
+ const casesCount = investigations.length
+ const activeCasesCount = investigations.filter((i: Investigation) => i.status === 'active').length
return (
<main className="flex-1 h-full overflow-auto">
diff --git a/flowsint-app/src/components/investigations/investigation-list.tsx b/flowsint-app/src/components/investigations/investigation-list.tsx
index 5aa27cd0..8f7d987d 100644
--- a/flowsint-app/src/components/investigations/investigation-list.tsx
+++ b/flowsint-app/src/components/investigations/investigation-list.tsx
@@ -10,7 +10,12 @@ import { queryKeys } from '@/api/query-keys'
import ErrorState from '../shared/error-state'
const InvestigationList = () => {
- const { data, isLoading, error, refetch } = useQuery({
+ const {
+ data = [],
+ isLoading,
+ error,
+ refetch
+ } = useQuery({
queryKey: queryKeys.investigations.list,
queryFn: investigationService.get
})
diff --git a/flowsint-app/src/components/investigations/new-investigation.tsx b/flowsint-app/src/components/investigations/new-investigation.tsx
index 45b84e66..d5fc528c 100644
--- a/flowsint-app/src/components/investigations/new-investigation.tsx
+++ b/flowsint-app/src/components/investigations/new-investigation.tsx
@@ -142,7 +142,7 @@ export default function NewInvestigation({ children, noDropDown = false }: NewIn
const createInvestigationMutation = useMutation({
mutationFn: investigationService.create,
onSuccess: (result) => {
- if (result.id) {
+ if ('id' in result && result.id) {
toast.success('New investigation created.')
router.navigate({ to: `/dashboard/investigations/${result.id}` })
// Invalidate investigations list
@@ -150,7 +150,7 @@ export default function NewInvestigation({ children, noDropDown = false }: NewIn
queryKey: queryKeys.investigations.list
})
} else {
- toast.error(result.error || 'Failed to create investigation')
+ toast.error(('error' in result && result.error) || 'Failed to create investigation')
}
},
onError: (error) => {