1 | |
2 |
|
3 | async function apiBase(auth: RT.AdobeAcrobatSign): Promise<string> { |
4 | if (auth.base_uri) return auth.base_uri.replace(/\/+$/, "") |
5 | const r = await fetch("https://api.adobesign.com/api/rest/v6/baseUris", { |
6 | headers: { |
7 | Authorization: `Bearer ${auth.token}`, |
8 | Accept: "application/json", |
9 | }, |
10 | }) |
11 | if (!r.ok) throw new Error(`${r.status} ${await r.text()}`) |
12 | const { apiAccessPoint } = (await r.json()) as { apiAccessPoint: string } |
13 | return apiAccessPoint.replace(/\/+$/, "") |
14 | } |
15 |
|
16 | |
17 | * List Agreements |
18 | * List the agreements visible to the user, newest first. Use cursor + page_size for pagination (pass the response page.nextCursor back as cursor). |
19 | */ |
20 | export async function main( |
21 | auth: RT.AdobeAcrobatSign, |
22 | cursor: string | undefined, |
23 | page_size: number | undefined, |
24 | show_hidden_agreements: boolean | undefined |
25 | ) { |
26 | const base = await apiBase(auth) |
27 | const url = new URL(`${base}/api/rest/v6/agreements`) |
28 | for (const [k, v] of [ |
29 | ["cursor", cursor], |
30 | ["pageSize", page_size], |
31 | ["showHiddenAgreements", show_hidden_agreements], |
32 | ] as const) { |
33 | if (v !== undefined && v !== "") { |
34 | url.searchParams.append(k, String(v)) |
35 | } |
36 | } |
37 |
|
38 | const response = await fetch(url, { |
39 | method: "GET", |
40 | headers: { |
41 | Authorization: `Bearer ${auth.token}`, |
42 | Accept: "application/json", |
43 | }, |
44 | }) |
45 |
|
46 | if (!response.ok) { |
47 | throw new Error(`${response.status} ${await response.text()}`) |
48 | } |
49 |
|
50 | return await response.json() |
51 | } |
52 |
|