1 | |
2 | * cancel a job for a suspended flow |
3 | * |
4 | */ |
5 | export async function main( |
6 | workspace: string, |
7 | id: string, |
8 | resume_id: string, |
9 | signature: string, |
10 | approver: string | undefined, |
11 | body: { [k: string]: unknown } |
12 | ) { |
13 | const url = new URL( |
14 | `${BASE_URL}/api/w/${workspace}/jobs_u/cancel/${id}/${resume_id}/${signature}` |
15 | ); |
16 | for (const [k, v] of [["approver", approver]]) { |
17 | if (v !== undefined && v !== "") { |
18 | url.searchParams.append(k, v); |
19 | } |
20 | } |
21 | const response = await fetch(url, { |
22 | method: "POST", |
23 | headers: { |
24 | "Content-Type": "application/json", |
25 | Authorization: "Bearer " + WM_TOKEN, |
26 | }, |
27 | body: JSON.stringify(body), |
28 | }); |
29 | if (!response.ok) { |
30 | const text = await response.text(); |
31 | throw new Error(`${response.status} ${text}`); |
32 | } |
33 | return await response.text(); |
34 | } |
35 |
|