1 | |
2 | type Smartsheet = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Share Dashboard |
8 | * Shares a dashboard with the specified users and groups. |
9 | */ |
10 | export async function main( |
11 | auth: Smartsheet, |
12 | sightId: string, |
13 | accessApiLevel: string | undefined, |
14 | sendEmail: string | undefined, |
15 | body: { |
16 | id?: string; |
17 | groupId?: number; |
18 | userId?: number; |
19 | type?: string; |
20 | accessLevel?: |
21 | | "ADMIN" |
22 | | "COMMENTER" |
23 | | "EDITOR" |
24 | | "EDITOR_SHARE" |
25 | | "OWNER" |
26 | | "VIEWER"; |
27 | ccMe?: false | true; |
28 | createdAt?: string | number; |
29 | email?: string; |
30 | message?: string; |
31 | modifiedAt?: string | number; |
32 | name?: string; |
33 | scope?: string; |
34 | subject?: string; |
35 | }, |
36 | ) { |
37 | const url = new URL(`${auth.baseUrl}/sights/${sightId}/shares`); |
38 | for (const [k, v] of [ |
39 | ["accessApiLevel", accessApiLevel], |
40 | ["sendEmail", sendEmail], |
41 | ]) { |
42 | if (v !== undefined && v !== "" && k !== undefined) { |
43 | url.searchParams.append(k, v); |
44 | } |
45 | } |
46 | const response = await fetch(url, { |
47 | method: "POST", |
48 | headers: { |
49 | "Content-Type": "application/json", |
50 | Authorization: "Bearer " + auth.token, |
51 | }, |
52 | body: JSON.stringify(body), |
53 | }); |
54 | if (!response.ok) { |
55 | const text = await response.text(); |
56 | throw new Error(`${response.status} ${text}`); |
57 | } |
58 | return await response.json(); |
59 | } |
60 |
|