1 | |
2 | type Grist = { |
3 | apiKey: string; |
4 | host: string; |
5 | }; |
6 | |
7 | * Change who has access to workspace |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Grist, |
12 | workspaceId: string, |
13 | body: { |
14 | delta: { maxInheritedRole?: "owners" | "editors" | "viewers"; users?: {} }; |
15 | }, |
16 | ) { |
17 | const url = new URL( |
18 | `https://${auth.host}/api/workspaces/${workspaceId}/access`, |
19 | ); |
20 |
|
21 | const response = await fetch(url, { |
22 | method: "PATCH", |
23 | headers: { |
24 | "Content-Type": "application/json", |
25 | Authorization: "Bearer " + auth.apiKey, |
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 |
|