A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
fix(frontend): type the flow-service API boundary
dextmorgn7493c37ee445
diff --git a/flowsint-app/src/api/flow-service.ts b/flowsint-app/src/api/flow-service.tsindex 0d4e403d..1014a303 100644--- a/flowsint-app/src/api/flow-service.ts+++ b/flowsint-app/src/api/flow-service.ts@@ -1,52 +1,58 @@import { fetchWithAuth } from './api'+import type { Flow, ComputeFlowResult } from '@/types/flow'+import type { Enricher, EnricherData } from '@/types/enricher'export const flowService = {- get: async (type?: string): Promise<any> => {+ get: async (type?: string): Promise<Flow[]> => {const url = type ? `/api/flows?category=${type}` : '/api/flows'return fetchWithAuth(url, {method: 'GET'})},- getById: async (flowId: string): Promise<any> => {+ getById: async (flowId: string): Promise<Flow> => {return fetchWithAuth(`/api/flows/${flowId}`, {method: 'GET'})},- create: async (body: BodyInit): Promise<any> => {+ create: async (body: BodyInit): Promise<Flow> => {return fetchWithAuth(`/api/flows/create`, {method: 'POST',body: body})},- update: async (flowId: string, body: BodyInit): Promise<any> => {+ update: async (flowId: string, body: BodyInit): Promise<Flow> => {return fetchWithAuth(`/api/flows/${flowId}`, {method: 'PUT',body: body})},- compute: async (flowId: string, body: BodyInit): Promise<any> => {+ compute: async (flowId: string, body: BodyInit): Promise<ComputeFlowResult> => {return fetchWithAuth(`/api/flows/${flowId}/compute`, {method: 'POST',body: body})},- delete: async (flowId: string): Promise<any> => {+ delete: async (flowId: string): Promise<unknown> => {return fetchWithAuth(`/api/flows/${flowId}`, {method: 'DELETE'})},- launch: async (flowId: string, body: BodyInit): Promise<any> => {+ launch: async (flowId: string, body: BodyInit): Promise<unknown> => {return fetchWithAuth(`/api/flows/${flowId}/launch`, {method: 'POST',body: body})},- getRawMaterial: async (): Promise<any> => {+ // Raw materials are enrichers grouped by input type — the pool a flow's+ // "type" nodes can be built from, not flows themselves.+ getRawMaterial: async (): Promise<EnricherData> => {return fetchWithAuth(`/api/flows/raw_materials`, {method: 'GET'})},- getRawMaterialForType: async (type: string): Promise<any> => {+ // Unlike getRawMaterial, this endpoint already filters to one input+ // type, so it returns a flat list instead of grouping by category.+ getRawMaterialForType: async (type: string): Promise<{ items: Enricher[] }> => {return fetchWithAuth(`/api/flows/input_type/${type}`, {method: 'GET'})diff --git a/flowsint-app/src/components/flows/controls.tsx b/flowsint-app/src/components/flows/controls.tsxindex 36a97b0c..d6a93825 100644--- a/flowsint-app/src/components/flows/controls.tsx+++ b/flowsint-app/src/components/flows/controls.tsx@@ -3,6 +3,7 @@ import { Panel } from '@xyflow/react'import { Save, Trash2, ZoomIn, ZoomOut, Maximize, LayoutGrid } from 'lucide-react'import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'import { FlowNamePanel } from './flow-name-panel'+import type { Flow } from '@/types/flow'interface FlowControlsProps {loading: boolean@@ -13,7 +14,7 @@ interface FlowControlsProps {zoomIn: () => voidzoomOut: () => voidisSaved: boolean- flow?: any+ flow?: Flow}export function FlowControls({diff --git a/flowsint-app/src/components/flows/editor.tsx b/flowsint-app/src/components/flows/editor.tsxindex ce5cb117..a49c2abf 100644--- a/flowsint-app/src/components/flows/editor.tsx+++ b/flowsint-app/src/components/flows/editor.tsx@@ -28,6 +28,7 @@ import { useConfirm } from '@/components/use-confirm-dialog'import { useParams, useRouter } from '@tanstack/react-router'import { flowService } from '@/api/flow-service'import { useFlowStore, type FlowNode, type FlowEdge } from '@/stores/flow-store'+import type { Flow, FlowBranch } from '@/types/flow'import type { CSSProperties } from 'react'import {Select,@@ -53,7 +54,7 @@ interface FlowEditorProps {theme?: ColorModeinitialEdges: FlowEdge[]initialNodes: FlowNode[]- flow?: any+ flow?: Flow}const defaultEdgeStyle: CSSProperties = { stroke: '#64748b' }@@ -80,7 +81,7 @@ const FlowEditor = memo(({ initialEdges, initialNodes, theme, flow }: FlowEditorconst [isSimulating, setIsSimulating] = useState(false)const [currentStepIndex, setCurrentStepIndex] = useState(0)const [simulationSpeed, setSimulationSpeed] = useState(1000) // ms per step- const [flowBranches, setFlowBranches] = useState<any[]>([])+ const [flowBranches, setFlowBranches] = useState<FlowBranch[]>([])// #### Enricher Store State ####const nodes = useFlowStore((state) => state.nodes)diff --git a/flowsint-app/src/components/flows/raw-material.tsx b/flowsint-app/src/components/flows/raw-material.tsxindex cb20339c..766aaafc 100644--- a/flowsint-app/src/components/flows/raw-material.tsx+++ b/flowsint-app/src/components/flows/raw-material.tsx@@ -27,13 +27,12 @@ export default function RawMaterial() {}const term = searchTerm.toLowerCase()- Object.entries(materials?.items).forEach(([category, items]) => {- // @ts-expect-error materials.items is typed unknown+ Object.entries(materials.items).forEach(([category, items]) => {const filtered = items.filter(- (item: any) =>+ (item) =>item.name.toLowerCase().includes(term) ||item.class_name.toLowerCase().includes(term) ||- (item.doc && item.doc.toLowerCase().includes(term))+ (item.documentation && item.documentation.toLowerCase().includes(term)))if (filtered.length > 0) {result[category] = filtered@@ -41,7 +40,7 @@ export default function RawMaterial() {})return result- }, [searchTerm, materials?.items])+ }, [searchTerm, materials])if (error) return <div>error</div>@@ -78,7 +77,6 @@ export default function RawMaterial() {<div key={category} className="space-y-2 w-full"><h3 className="text-sm font-medium capitalize mt-4">{category.replace('_', ' ')}</h3><div className="space-y-2">- {/* @ts-expect-error enrichers is typed unknown */}{enrichers.map((enricher: Enricher) => (<EnricherItemkey={enricher.name}diff --git a/flowsint-app/src/routes/_auth.dashboard.flows.$flowId.tsx b/flowsint-app/src/routes/_auth.dashboard.flows.$flowId.tsxindex a0b72a8b..897ddd2f 100644--- a/flowsint-app/src/routes/_auth.dashboard.flows.$flowId.tsx+++ b/flowsint-app/src/routes/_auth.dashboard.flows.$flowId.tsx@@ -34,8 +34,8 @@ function FlowPage() {<Editorkey={flow.id}flow={flow}- initialNodes={flow?.flow_schema?.nodes}- initialEdges={flow?.flow_schema?.edges}+ initialNodes={flow?.flow_schema?.nodes ?? []}+ initialEdges={flow?.flow_schema?.edges ?? []}/>)}diff --git a/flowsint-app/src/routes/_auth.dashboard.flows.index.tsx b/flowsint-app/src/routes/_auth.dashboard.flows.index.tsxindex 376fdb58..eaae3e3e 100644--- a/flowsint-app/src/routes/_auth.dashboard.flows.index.tsx+++ b/flowsint-app/src/routes/_auth.dashboard.flows.index.tsx@@ -12,16 +12,11 @@ import NewFlow from '@/components/flows/new-flow'import { flowService } from '@/api/flow-service'import ErrorState from '@/components/shared/error-state'import { PageLayout } from '@/components/layout/page-layout'+import type { Flow } from '@/types/flow'-interface Flow {- id: string- name: string- description?: string- category?: string[]- created_at: string- updated_at?: string- flow_schema?: any-}+// category comes back as either a string or a string[] — normalize once.+const categoriesOf = (flow: Flow): string[] =>+ Array.isArray(flow.category) ? flow.category : flow.category ? [flow.category] : []export const Route = createFileRoute('/_auth/dashboard/flows/')({component: FlowPage@@ -42,11 +37,9 @@ function FlowPage() {// Get all unique categoriesconst categories =flows?.reduce((acc: string[], flow) => {- if (flow.category) {- flow.category.forEach((cat) => {- if (!acc.includes(cat)) acc.push(cat)- })- }+ categoriesOf(flow).forEach((cat) => {+ if (!acc.includes(cat)) acc.push(cat)+ })return acc}, []) || []@@ -124,8 +117,8 @@ function FlowPage() {category === 'All'? true: category === 'Uncategorized'- ? !flow.category?.length- : flow.category?.includes(category)+ ? categoriesOf(flow).length === 0+ : categoriesOf(flow).includes(category)).map((flow) => (<Card@@ -148,12 +141,15 @@ function FlowPage() {<div className="flex items-center justify-between"><div className="flex items-center text-sm text-muted-foreground"><Clock className="w-4 h-4 mr-1" />- {formatDistanceToNow(new Date(flow.updated_at || flow.created_at), {- addSuffix: true- })}+ {formatDistanceToNow(+ new Date(flow.last_updated_at || flow.created_at),+ {+ addSuffix: true+ }+ )}</div><div className="flex flex-wrap gap-2 justify-end">- {flow.category?.map((cat) => (+ {categoriesOf(flow).map((cat) => (<Badge key={cat} variant="secondary">{cat}</Badge>diff --git a/flowsint-app/src/types/enricher.ts b/flowsint-app/src/types/enricher.tsindex 1297dcd3..e8985adf 100644--- a/flowsint-app/src/types/enricher.ts+++ b/flowsint-app/src/types/enricher.ts@@ -49,12 +49,12 @@ export interface EnricherNodeData extends Enricher, Record<string, unknown> {// DATA STRUCTURES// ================================-export interface ScansData {+export interface EnrichersData {[category: string]: Enricher[]}export interface EnricherData {- items: ScansData+ items: EnrichersData}// ================================@@ -71,24 +71,3 @@ export interface EnricherNodeProps {isConnectable?: booleanselected?: boolean}--// ================================-// ENRICHER DATA STRUCTURES-// ================================--export interface EnrichersData {- [category: string]: Enricher[]-}--export interface EnricherData {- items: EnrichersData-}--// ================================-// COMPONENT PROPS INTERFACES-// ================================--export interface EnricherItemProps {- enricher: Enricher- category: string-}diff --git a/flowsint-app/src/types/flow.ts b/flowsint-app/src/types/flow.tsindex e41be2b0..638d49ec 100644--- a/flowsint-app/src/types/flow.ts+++ b/flowsint-app/src/types/flow.ts@@ -1,3 +1,5 @@+import type { FlowNode, FlowEdge } from '@/stores/flow-store'+// ================================// FLOW TYPE DEFINITIONS// ================================@@ -9,10 +11,16 @@ export interface Flow {module: stringdescription: stringdocumentation: string- category: string+ // Backend has been observed sending both shapes — consumers (see+ // flow-list.tsx) already defend against either.+ category: string | string[]created_at: stringlast_updated_at: stringwobblyType?: boolean+ flow_schema?: {+ nodes: FlowNode[]+ edges: FlowEdge[]+ }}// ================================@@ -35,3 +43,21 @@ export interface FlowItemProps {flow: Flowcategory: string}++// ================================+// FLOW COMPUTATION / SIMULATION+// ================================++// Only nodeId is ever read off a step by the simulation playback — the+// backend result carries more, but nothing here reads it.+export interface FlowBranchStep {+ nodeId: string+}++export interface FlowBranch {+ steps: FlowBranchStep[]+}++export interface ComputeFlowResult {+ flowBranches: FlowBranch[]+}