-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdoInvokeCommand.ts
More file actions
39 lines (36 loc) · 1.07 KB
/
Copy pathdoInvokeCommand.ts
File metadata and controls
39 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// @ts-ignore
import { fetchWithErrorHandling } from '@neos-project/neos-ui-backend-connector';
import { FeedbackEnvelope } from '../interfaces';
interface CommandInvocationResult {
success: boolean;
result: any;
uiFeedback: FeedbackEnvelope;
}
const doInvokeCommand = async (
endPoint: string,
commandName: string,
argument: string,
siteNode: string = null,
focusedNode: string = null,
documentNode: string = null
): Promise<CommandInvocationResult> => {
return fetchWithErrorHandling
.withCsrfToken((csrfToken) => ({
url: endPoint,
method: 'POST',
credentials: 'include',
headers: {
'X-Flow-Csrftoken': csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
commandName,
argument,
siteNode,
focusedNode,
documentNode,
}),
}))
.then((response) => response && response.json());
};
export default doInvokeCommand;