4
4
*/
5
5
6
6
import { CoreStart , HttpFetchError } from '../../../src/core/public' ;
7
- import { FETCH_INDICES_PATH , SEARCH_INDICES_PATH } from '../common' ;
7
+ import {
8
+ CREATE_WORKFLOW_NODE_API_PATH ,
9
+ DELETE_WORKFLOW_NODE_API_PATH ,
10
+ CAT_INDICES_NODE_API_PATH ,
11
+ GET_WORKFLOW_NODE_API_PATH ,
12
+ GET_WORKFLOW_STATE_NODE_API_PATH ,
13
+ SEARCH_WORKFLOWS_NODE_API_PATH ,
14
+ } from '../common' ;
8
15
16
+ /**
17
+ * A simple client-side service interface containing all of the available node API functions.
18
+ * Exposed in services.ts.
19
+ * Example function call: getRouteService().getWorkflow(<workflow-id>)
20
+ *
21
+ * Used in redux by wrapping them in async thunk functions which mutate redux state when executed.
22
+ */
9
23
export interface RouteService {
10
- searchIndex : ( indexName : string , body : { } ) => Promise < any | HttpFetchError > ;
11
- fetchIndices : ( pattern : string ) => Promise < any | HttpFetchError > ;
24
+ getWorkflow : ( workflowId : string ) => Promise < any | HttpFetchError > ;
25
+ searchWorkflows : ( body : { } ) => Promise < any | HttpFetchError > ;
26
+ getWorkflowState : ( workflowId : string ) => Promise < any | HttpFetchError > ;
27
+ createWorkflow : ( body : { } ) => Promise < any | HttpFetchError > ;
28
+ deleteWorkflow : ( workflowId : string ) => Promise < any | HttpFetchError > ;
29
+ catIndices : ( pattern : string ) => Promise < any | HttpFetchError > ;
12
30
}
13
31
14
32
export function configureRoutes ( core : CoreStart ) : RouteService {
15
33
return {
16
- searchIndex : async ( indexName : string , body : { } ) => {
34
+ getWorkflow : async ( workflowId : string ) => {
35
+ try {
36
+ const response = await core . http . get < { respString : string } > (
37
+ `${ GET_WORKFLOW_NODE_API_PATH } /${ workflowId } `
38
+ ) ;
39
+ return response ;
40
+ } catch ( e : any ) {
41
+ return e as HttpFetchError ;
42
+ }
43
+ } ,
44
+ searchWorkflows : async ( body : { } ) => {
17
45
try {
18
46
const response = await core . http . post < { respString : string } > (
19
- ` ${ SEARCH_INDICES_PATH } / ${ indexName } ` ,
47
+ SEARCH_WORKFLOWS_NODE_API_PATH ,
20
48
{
21
49
body : JSON . stringify ( body ) ,
22
50
}
@@ -26,10 +54,43 @@ export function configureRoutes(core: CoreStart): RouteService {
26
54
return e as HttpFetchError ;
27
55
}
28
56
} ,
29
- fetchIndices : async ( pattern : string ) => {
57
+ getWorkflowState : async ( workflowId : string ) => {
58
+ try {
59
+ const response = await core . http . get < { respString : string } > (
60
+ `${ GET_WORKFLOW_STATE_NODE_API_PATH } /${ workflowId } `
61
+ ) ;
62
+ return response ;
63
+ } catch ( e : any ) {
64
+ return e as HttpFetchError ;
65
+ }
66
+ } ,
67
+ createWorkflow : async ( body : { } ) => {
30
68
try {
31
69
const response = await core . http . post < { respString : string } > (
32
- `${ FETCH_INDICES_PATH } /${ pattern } `
70
+ CREATE_WORKFLOW_NODE_API_PATH ,
71
+ {
72
+ body : JSON . stringify ( body ) ,
73
+ }
74
+ ) ;
75
+ return response ;
76
+ } catch ( e : any ) {
77
+ return e as HttpFetchError ;
78
+ }
79
+ } ,
80
+ deleteWorkflow : async ( workflowId : string ) => {
81
+ try {
82
+ const response = await core . http . delete < { respString : string } > (
83
+ `${ DELETE_WORKFLOW_NODE_API_PATH } /${ workflowId } `
84
+ ) ;
85
+ return response ;
86
+ } catch ( e : any ) {
87
+ return e as HttpFetchError ;
88
+ }
89
+ } ,
90
+ catIndices : async ( pattern : string ) => {
91
+ try {
92
+ const response = await core . http . get < { respString : string } > (
93
+ `${ CAT_INDICES_NODE_API_PATH } /${ pattern } `
33
94
) ;
34
95
return response ;
35
96
} catch ( e : any ) {
0 commit comments