1 |
|
2 | type Actimo = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Actimo, |
8 | body: { |
9 | decision_graph?: { |
10 | edges?: { |
11 | end?: string |
12 | predicate?: { key_name?: string; type?: string } |
13 | start?: string |
14 | }[] |
15 | id?: string |
16 | nodes?: { id?: number }[][] |
17 | } |
18 | description?: string |
19 | name?: string |
20 | start_node?: number[] |
21 | } |
22 | ) { |
23 | const url = new URL(`https://actimo.com/api/v1/decisiongraphs/`) |
24 |
|
25 | const response = await fetch(url, { |
26 | method: 'POST', |
27 | headers: { |
28 | 'api-key': auth.apiKey, |
29 | 'Content-Type': 'application/json' |
30 | }, |
31 | body: JSON.stringify(body) |
32 | }) |
33 |
|
34 | if (!response.ok) { |
35 | const text = await response.text() |
36 | throw new Error(`${response.status} ${text}`) |
37 | } |
38 |
|
39 | return await response.json() |
40 | } |
41 |
|