11import { createApi , fetchBaseQuery } from '@reduxjs/toolkit/query/react' ;
22import environment from '../../../../environment' ;
33
4- // Type for Node-RED flows response/request
4+ // Base type for common properties
5+ export interface NodeRedBase {
6+ id : string ;
7+ type : string ;
8+ info : string ;
9+ env : { name : string ; type : string ; value : string } [ ] ;
10+ }
11+
12+ // Type for regular Node-RED flows
13+ export interface NodeRedFlow extends NodeRedBase {
14+ type : 'tab' ;
15+ label : string ;
16+ disabled : boolean ;
17+ }
18+
19+ // Type for Node-RED subflows
20+ export interface NodeRedSubflow extends NodeRedBase {
21+ type : 'subflow' ;
22+ name : string ;
23+ category : string ;
24+ color : string ;
25+ icon : string ;
26+ in : NodeRedEndpoint [ ] ;
27+ out : NodeRedEndpoint [ ] ;
28+ }
29+
30+ // Type for nodes within flows or subflows
31+ export interface NodeRedNode extends NodeRedBase {
32+ name : string ;
33+ x : number ;
34+ y : number ;
35+ z : string ;
36+ wires : string [ ] [ ] ;
37+ inputs ?: number ;
38+ outputs ?: number ;
39+ inputLabels ?: string [ ] ;
40+ outputLabels ?: string [ ] ;
41+ icon ?: string ;
42+ }
43+
44+ // Type for endpoints used in subflows (inputs and outputs)
45+ export interface NodeRedEndpoint {
46+ x : number ;
47+ y : number ;
48+ wires : { id : string ; port ?: number } [ ] ;
49+ }
50+
51+ // Composite type for all Node-RED objects
552export interface NodeRedFlows {
6- flows : unknown [ ] ;
53+ rev ?: string ;
54+ flows : NodeRedBase [ ] ;
755}
856
957// Define a service using a base URL and expected endpoints for flows
@@ -12,6 +60,11 @@ export const flowApi = createApi({
1260 baseQuery : fetchBaseQuery ( {
1361 baseUrl : environment . NODE_RED_API_ROOT ,
1462 responseHandler : 'content-type' ,
63+ prepareHeaders : headers => {
64+ headers . set ( 'Node-RED-API-Version' , 'v2' ) ;
65+ headers . set ( 'Node-RED-Deployment-Type' , 'nodes' ) ;
66+ return headers ;
67+ } ,
1568 } ) ,
1669 tagTypes : [ 'Flow' ] , // For automatic cache invalidation and refetching
1770 endpoints : builder => ( {
@@ -27,7 +80,7 @@ export const flowApi = createApi({
2780 } ) ,
2881 // Endpoint to update all flows
2982 updateFlows : builder . mutation < NodeRedFlows , NodeRedFlows > ( {
30- query : ( flows ) => ( {
83+ query : flows => ( {
3184 url : 'flows' ,
3285 method : 'POST' ,
3386 headers : {
0 commit comments