1 | |
2 | * create token to impersonate a user (require superadmin) |
3 | * |
4 | */ |
5 | export async function main(body: { |
6 | label?: string; |
7 | expiration?: string; |
8 | impersonate_email: string; |
9 | [k: string]: unknown; |
10 | }) { |
11 | const url = new URL(`${BASE_URL}/api/users/tokens/impersonate`); |
12 |
|
13 | const response = await fetch(url, { |
14 | method: "POST", |
15 | headers: { |
16 | "Content-Type": "application/json", |
17 | Authorization: "Bearer " + WM_TOKEN, |
18 | }, |
19 | body: JSON.stringify(body), |
20 | }); |
21 | if (!response.ok) { |
22 | const text = await response.text(); |
23 | throw new Error(`${response.status} ${text}`); |
24 | } |
25 | return await response.text(); |
26 | } |
27 |
|