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