1 | |
2 | type Linode = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a profile |
7 | * Update information in your profile. |
8 | */ |
9 | export async function main( |
10 | auth: Linode, |
11 | apiVersion: "v4" | "v4beta", |
12 | body: { |
13 | authentication_type?: "password" | "github"; |
14 | authorized_keys?: string[]; |
15 | email?: string; |
16 | email_notifications?: false | true; |
17 | ip_whitelist_enabled?: false | true; |
18 | lish_auth_method?: "password_keys" | "keys_only" | "disabled"; |
19 | referrals?: { |
20 | code?: string; |
21 | completed?: number; |
22 | credit?: number; |
23 | pending?: number; |
24 | total?: number; |
25 | url?: string; |
26 | }; |
27 | restricted?: false | true; |
28 | timezone?: string; |
29 | two_factor_auth?: false | true; |
30 | uid?: number; |
31 | username?: string; |
32 | verified_phone_number?: string; |
33 | }, |
34 | ) { |
35 | const url = new URL(`https://api.linode.com/${apiVersion}/profile`); |
36 |
|
37 | const response = await fetch(url, { |
38 | method: "PUT", |
39 | headers: { |
40 | "Content-Type": "application/json", |
41 | Authorization: "Bearer " + auth.token, |
42 | }, |
43 | body: JSON.stringify(body), |
44 | }); |
45 | if (!response.ok) { |
46 | const text = await response.text(); |
47 | throw new Error(`${response.status} ${text}`); |
48 | } |
49 | return await response.json(); |
50 | } |
51 |
|