1 | |
2 | type Pandadoc = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Pandadoc, |
8 | id: string, |
9 | watermark_color: string | undefined, |
10 | watermark_font_size: string | undefined, |
11 | watermark_opacity: string | undefined, |
12 | watermark_text: string | undefined, |
13 | separate_files: string | undefined |
14 | ) { |
15 | const url = new URL(`https://api.pandadoc.com/public/v1/documents/${id}/download`) |
16 |
|
17 | for (const [k, v] of [ |
18 | ['watermark_color', watermark_color], |
19 | ['watermark_font_size', watermark_font_size], |
20 | ['watermark_opacity', watermark_opacity], |
21 | ['watermark_text', watermark_text], |
22 | ['separate_files', separate_files] |
23 | ]) { |
24 | if (v !== undefined && v !== '' && k !== undefined) { |
25 | url.searchParams.append(k, v) |
26 | } |
27 | } |
28 |
|
29 | const response = await fetch(url, { |
30 | method: 'GET', |
31 | headers: { |
32 | Authorization: `API-Key ${auth.apiKey}` |
33 | }, |
34 | body: undefined |
35 | }) |
36 |
|
37 | if (!response.ok) { |
38 | const text = await response.text() |
39 | throw new Error(`${response.status} ${text}`) |
40 | } |
41 |
|
42 | return await response.text() |
43 | } |
44 |
|