1 | |
2 | type Netlify = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create site in team |
7 | * **Note:** Environment variable keys and values have moved from `build_settings.env` and `repo.env` to a new endpoint. Please use [createEnvVars](#tag/environmentVariables/operation/createEnvVars) to create environment variables for a site. |
8 | */ |
9 | export async function main( |
10 | auth: Netlify, |
11 | account_slug: string, |
12 | configure_dns: string | undefined, |
13 | body: { |
14 | id?: string; |
15 | state?: string; |
16 | plan?: string; |
17 | name?: string; |
18 | custom_domain?: string; |
19 | domain_aliases?: string[]; |
20 | branch_deploy_custom_domain?: string; |
21 | deploy_preview_custom_domain?: string; |
22 | password?: string; |
23 | notification_email?: string; |
24 | url?: string; |
25 | ssl_url?: string; |
26 | admin_url?: string; |
27 | screenshot_url?: string; |
28 | created_at?: string; |
29 | updated_at?: string; |
30 | user_id?: string; |
31 | session_id?: string; |
32 | ssl?: false | true; |
33 | force_ssl?: false | true; |
34 | managed_dns?: false | true; |
35 | deploy_url?: string; |
36 | published_deploy?: { |
37 | id?: string; |
38 | site_id?: string; |
39 | user_id?: string; |
40 | build_id?: string; |
41 | state?: string; |
42 | name?: string; |
43 | url?: string; |
44 | ssl_url?: string; |
45 | admin_url?: string; |
46 | deploy_url?: string; |
47 | deploy_ssl_url?: string; |
48 | screenshot_url?: string; |
49 | review_id?: number; |
50 | draft?: false | true; |
51 | required?: string[]; |
52 | required_functions?: string[]; |
53 | error_message?: string; |
54 | branch?: string; |
55 | commit_ref?: string; |
56 | commit_url?: string; |
57 | skipped?: false | true; |
58 | created_at?: string; |
59 | updated_at?: string; |
60 | published_at?: string; |
61 | title?: string; |
62 | context?: string; |
63 | locked?: false | true; |
64 | review_url?: string; |
65 | framework?: string; |
66 | function_schedules?: { name?: string; cron?: string }[]; |
67 | }; |
68 | account_id?: string; |
69 | account_name?: string; |
70 | account_slug?: string; |
71 | git_provider?: string; |
72 | deploy_hook?: string; |
73 | capabilities?: {}; |
74 | processing_settings?: { html?: { pretty_urls?: false | true } }; |
75 | build_settings?: { |
76 | id?: number; |
77 | provider?: string; |
78 | deploy_key_id?: string; |
79 | repo_path?: string; |
80 | repo_branch?: string; |
81 | dir?: string; |
82 | functions_dir?: string; |
83 | cmd?: string; |
84 | allowed_branches?: string[]; |
85 | public_repo?: false | true; |
86 | private_logs?: false | true; |
87 | repo_url?: string; |
88 | env?: {}; |
89 | installation_id?: number; |
90 | stop_builds?: false | true; |
91 | }; |
92 | id_domain?: string; |
93 | default_hooks_data?: { access_token?: string }; |
94 | build_image?: string; |
95 | prerender?: string; |
96 | functions_region?: string; |
97 | } & { |
98 | repo?: { |
99 | id?: number; |
100 | provider?: string; |
101 | deploy_key_id?: string; |
102 | repo_path?: string; |
103 | repo_branch?: string; |
104 | dir?: string; |
105 | functions_dir?: string; |
106 | cmd?: string; |
107 | allowed_branches?: string[]; |
108 | public_repo?: false | true; |
109 | private_logs?: false | true; |
110 | repo_url?: string; |
111 | env?: {}; |
112 | installation_id?: number; |
113 | stop_builds?: false | true; |
114 | }; |
115 | }, |
116 | ) { |
117 | const url = new URL(`https://api.netlify.com/api/v1/${account_slug}/sites`); |
118 | for (const [k, v] of [["configure_dns", configure_dns]]) { |
119 | if (v !== undefined && v !== "" && k !== undefined) { |
120 | url.searchParams.append(k, v); |
121 | } |
122 | } |
123 | const response = await fetch(url, { |
124 | method: "POST", |
125 | headers: { |
126 | "Content-Type": "application/json", |
127 | Authorization: "Bearer " + auth.token, |
128 | }, |
129 | body: JSON.stringify(body), |
130 | }); |
131 | if (!response.ok) { |
132 | const text = await response.text(); |
133 | throw new Error(`${response.status} ${text}`); |
134 | } |
135 | return await response.json(); |
136 | } |
137 |
|