1 | |
2 | type Neondb = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Create a project |
7 | * Creates a Neon project. |
8 | A project is the top-level object in the Neon object hierarchy. |
9 | Plan limits define how many projects you can create. |
10 | For more information, see [Manage projects](https://neon.tech/docs/manage/projects/). |
11 |
|
12 | You can specify a region and Postgres version in the request body. |
13 | Neon currently supports PostgreSQL 14, 15, 16, and 17. |
14 | For supported regions and `region_id` values, see [Regions](https://neon.tech/docs/introduction/regions/). |
15 |
|
16 | */ |
17 | export async function main( |
18 | auth: Neondb, |
19 | body: { |
20 | project: { |
21 | settings?: { |
22 | quota?: { |
23 | active_time_seconds?: number |
24 | compute_time_seconds?: number |
25 | written_data_bytes?: number |
26 | data_transfer_bytes?: number |
27 | logical_size_bytes?: number |
28 | } |
29 | allowed_ips?: { |
30 | ips?: string[] |
31 | protected_branches_only?: false | true |
32 | } |
33 | enable_logical_replication?: false | true |
34 | maintenance_window?: { |
35 | weekdays: number[] |
36 | start_time: string |
37 | end_time: string |
38 | } |
39 | block_public_connections?: false | true |
40 | block_vpc_connections?: false | true |
41 | } |
42 | name?: string |
43 | branch?: { name?: string; role_name?: string; database_name?: string } |
44 | autoscaling_limit_min_cu?: number |
45 | autoscaling_limit_max_cu?: number |
46 | provisioner?: string |
47 | region_id?: string |
48 | default_endpoint_settings?: { |
49 | pg_settings?: {} |
50 | pgbouncer_settings?: {} |
51 | autoscaling_limit_min_cu?: number |
52 | autoscaling_limit_max_cu?: number |
53 | suspend_timeout_seconds?: number |
54 | } |
55 | pg_version?: number |
56 | store_passwords?: false | true |
57 | history_retention_seconds?: number |
58 | org_id?: string |
59 | } |
60 | } |
61 | ) { |
62 | const url = new URL(`https://console.neon.tech/api/v2/projects`) |
63 |
|
64 | const response = await fetch(url, { |
65 | method: 'POST', |
66 | headers: { |
67 | 'Content-Type': 'application/json', |
68 | Authorization: 'Bearer ' + auth.apiKey |
69 | }, |
70 | body: JSON.stringify(body) |
71 | }) |
72 | if (!response.ok) { |
73 | const text = await response.text() |
74 | throw new Error(`${response.status} ${text}`) |
75 | } |
76 | return await response.json() |
77 | } |
78 |
|