A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
fix(frontend): type the analysis-service API boundary
dextmorgn35632bde8195
diff --git a/flowsint-app/src/api/analysis-service.ts b/flowsint-app/src/api/analysis-service.tsindex 84e86c71..17403ca3 100644--- a/flowsint-app/src/api/analysis-service.ts+++ b/flowsint-app/src/api/analysis-service.ts@@ -1,34 +1,37 @@import { fetchWithAuth } from './api'+import type { Analysis } from '@/types/analysis'export const analysisService = {- get: async (): Promise<any> => {+ get: async (): Promise<Analysis[]> => {return fetchWithAuth('/api/analyses', {method: 'GET'})},- getByInvestigationId: async (investigationId: string): Promise<any> => {+ getByInvestigationId: async (investigationId: string): Promise<Analysis[]> => {return fetchWithAuth(`/api/analyses/investigation/${investigationId}`, {method: 'GET'})},- getById: async (analysisId: string): Promise<any> => {+ getById: async (analysisId: string): Promise<Analysis> => {return fetchWithAuth(`/api/analyses/${analysisId}`, {method: 'GET'})},- create: async (body: BodyInit): Promise<any> => {+ // Backend returns the created analysis on success, or an { error }+ // payload instead of a 4xx/5xx status on failure — callers branch on `id`.+ create: async (body: BodyInit): Promise<Analysis | { error: string }> => {return fetchWithAuth(`/api/analyses/create`, {method: 'POST',body: body})},- update: async (analysisId: string, body: BodyInit): Promise<any> => {+ update: async (analysisId: string, body: BodyInit): Promise<Analysis> => {return fetchWithAuth(`/api/analyses/${analysisId}`, {method: 'PUT',body: body})},- delete: async (analysisId: string): Promise<any> => {+ delete: async (analysisId: string): Promise<unknown> => {return fetchWithAuth(`/api/analyses/${analysisId}`, {method: 'DELETE'})diff --git a/flowsint-app/src/components/analyses/analyses-list.tsx b/flowsint-app/src/components/analyses/analyses-list.tsxindex 7ac0f6e9..38cfc0e0 100644--- a/flowsint-app/src/components/analyses/analyses-list.tsx+++ b/flowsint-app/src/components/analyses/analyses-list.tsx@@ -84,6 +84,10 @@ const AnalysisList = () => {return analysisService.create(JSON.stringify(newAnalysis))},onSuccess: async (data) => {+ if (!('id' in data)) {+ toast.error(data.error || 'Failed to create analysis')+ return+ }queryClient.invalidateQueries({queryKey: queryKeys.analyses.byInvestigation(investigationId || '')})diff --git a/flowsint-app/src/components/analyses/analysis-editor.tsx b/flowsint-app/src/components/analyses/analysis-editor.tsxindex 84e1f8d8..87fdf964 100644--- a/flowsint-app/src/components/analyses/analysis-editor.tsx+++ b/flowsint-app/src/components/analyses/analysis-editor.tsx@@ -109,6 +109,7 @@ export const AnalysisEditor = ({)},onSuccess: async (data) => {+ if (!data) return// Use more specific query invalidation with query key factoryqueryClient.setQueryData(queryKeys.analyses.byInvestigation(investigationId || ''),@@ -185,6 +186,7 @@ export const AnalysisEditor = ({)},onSuccess: async (data) => {+ if (!data) return// Use more specific query invalidationqueryClient.setQueryData(['analyses', investigationId], (oldData: Analysis[] | undefined) => {if (!oldData) return oldDatadiff --git a/flowsint-app/src/components/analyses/new-analysis.tsx b/flowsint-app/src/components/analyses/new-analysis.tsxindex fa9747fd..41fef211 100644--- a/flowsint-app/src/components/analyses/new-analysis.tsx+++ b/flowsint-app/src/components/analyses/new-analysis.tsx@@ -43,7 +43,7 @@ export default function NewAnalysis({ children }: NewAnalysisProps) {const createAnalysisMutation = useMutation({mutationFn: analysisService.create,onSuccess: (result) => {- if (result.id) {+ if ('id' in result && result.id) {toast.success('New analysis created.')router.navigate({to: `/dashboard/investigations/${investigationId}/analysis/${result.id}`@@ -60,7 +60,7 @@ export default function NewAnalysis({ children }: NewAnalysisProps) {}if (sketchId) setOpen(false)} else {- toast.error(result.error || 'Failed to create analysis.')+ toast.error(('error' in result && result.error) || 'Failed to create analysis.')}},onError: (error) => {diff --git a/flowsint-app/src/hooks/use-create-analysis.ts b/flowsint-app/src/hooks/use-create-analysis.tsindex cb3f2ee9..7bdff8b4 100644--- a/flowsint-app/src/hooks/use-create-analysis.ts+++ b/flowsint-app/src/hooks/use-create-analysis.ts@@ -5,7 +5,10 @@ import default_content from '@/components/analyses/default_content.json'import { queryKeys } from '@/api/query-keys'import { toast } from 'sonner'-export const useCreateAnalysis = (investigationId: string, onAnalysisCreate?: any) => {+export const useCreateAnalysis = (+ investigationId: string,+ onAnalysisCreate?: (investigationId: string) => void+) => {const queryClient = useQueryClient()return useMutation({