1 | |
2 | type Base64 = string |
3 | |
4 | * Upload employee compliance document |
5 | * Upload compliance document for an EOR employee. |
6 | **Token scopes**: `worker:write` |
7 | */ |
8 | export async function main(auth: RT.Deel, document_id: string, body: Body) { |
9 | const url = new URL( |
10 | `https://api.letsdeel.com/rest/v2/eor/workers/compliance-documents/${document_id}` |
11 | ) |
12 |
|
13 | const formData = new FormData() |
14 | for (const [k, v] of Object.entries(body)) { |
15 | if (v !== undefined && v !== '') { |
16 | if (['file'].includes(k)) { |
17 | const { base64, type, name } = v as { |
18 | base64: Base64 |
19 | type: string |
20 | name: string |
21 | } |
22 | formData.append( |
23 | k, |
24 | new Blob([Uint8Array.from(atob(base64), (m) => m.codePointAt(0)!)], { type }), |
25 | name |
26 | ) |
27 | } else { |
28 | formData.append(k, String(v)) |
29 | } |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: 'POST', |
34 | headers: { |
35 | Authorization: 'Bearer ' + auth.apiKey |
36 | }, |
37 | body: formData |
38 | }) |
39 | if (!response.ok) { |
40 | const text = await response.text() |
41 | throw new Error(`${response.status} ${text}`) |
42 | } |
43 | return await response.json() |
44 | } |
45 |
|
46 | |
47 | |
48 | * This file was automatically generated by json-schema-to-typescript. |
49 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
50 | * and run json-schema-to-typescript to regenerate this file. |
51 | */ |
52 |
|
53 | |
54 | * This is the file you will upload in a multi-part form. |
55 | */ |
56 | export interface Body { |
57 | |
58 | * The employee compliance document to upload. |
59 | */ |
60 | file?: { |
61 | base64: Base64 |
62 | type: |
63 | | 'image/png' |
64 | | 'image/jpeg' |
65 | | 'image/gif' |
66 | | 'application/pdf' |
67 | | 'appication/json' |
68 | | 'text/csv' |
69 | | 'text/plain' |
70 | | 'audio/mpeg' |
71 | | 'audio/wav' |
72 | | 'video/mp4' |
73 | name: string |
74 | } |
75 | [k: string]: unknown |
76 | } |
77 |
|