@nilovonjs/hcloud-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -0
- package/package.json +70 -0
- package/src/apis/actions/index.ts +113 -0
- package/src/apis/actions/schemas.ts +59 -0
- package/src/apis/actions/types.ts +77 -0
- package/src/apis/certificates/index.ts +326 -0
- package/src/apis/certificates/schemas.ts +140 -0
- package/src/apis/certificates/types.ts +176 -0
- package/src/apis/common/schemas.ts +19 -0
- package/src/apis/dns/index.ts +961 -0
- package/src/apis/dns/schemas.ts +437 -0
- package/src/apis/dns/types.ts +397 -0
- package/src/apis/firewalls/index.ts +469 -0
- package/src/apis/firewalls/schemas.ts +274 -0
- package/src/apis/firewalls/types.ts +205 -0
- package/src/apis/floating-ips/index.ts +466 -0
- package/src/apis/floating-ips/schemas.ts +203 -0
- package/src/apis/floating-ips/types.ts +207 -0
- package/src/apis/images/index.ts +195 -0
- package/src/apis/images/schemas.ts +113 -0
- package/src/apis/images/types.ts +124 -0
- package/src/apis/isos/index.ts +91 -0
- package/src/apis/isos/schemas.ts +43 -0
- package/src/apis/isos/types.ts +60 -0
- package/src/apis/load-balancers/index.ts +892 -0
- package/src/apis/load-balancers/schemas.ts +561 -0
- package/src/apis/load-balancers/types.ts +361 -0
- package/src/apis/locations/index.ts +176 -0
- package/src/apis/locations/schemas.ts +83 -0
- package/src/apis/locations/types.ts +113 -0
- package/src/apis/networks/index.ts +544 -0
- package/src/apis/networks/schemas.ts +279 -0
- package/src/apis/networks/types.ts +243 -0
- package/src/apis/placement-groups/index.ts +212 -0
- package/src/apis/placement-groups/schemas.ts +90 -0
- package/src/apis/placement-groups/types.ts +99 -0
- package/src/apis/pricing/index.ts +42 -0
- package/src/apis/pricing/schemas.ts +93 -0
- package/src/apis/pricing/types.ts +71 -0
- package/src/apis/primary-ips/index.ts +467 -0
- package/src/apis/primary-ips/schemas.ts +221 -0
- package/src/apis/primary-ips/types.ts +221 -0
- package/src/apis/server-types/index.ts +93 -0
- package/src/apis/server-types/schemas.ts +29 -0
- package/src/apis/server-types/types.ts +43 -0
- package/src/apis/servers/index.ts +378 -0
- package/src/apis/servers/schemas.ts +771 -0
- package/src/apis/servers/types.ts +538 -0
- package/src/apis/ssh-keys/index.ts +204 -0
- package/src/apis/ssh-keys/schemas.ts +84 -0
- package/src/apis/ssh-keys/types.ts +106 -0
- package/src/apis/volumes/index.ts +452 -0
- package/src/apis/volumes/schemas.ts +195 -0
- package/src/apis/volumes/types.ts +197 -0
- package/src/auth/index.ts +26 -0
- package/src/base/index.ts +10 -0
- package/src/client/index.ts +388 -0
- package/src/config/index.ts +34 -0
- package/src/errors/index.ts +38 -0
- package/src/index.ts +799 -0
- package/src/types/index.ts +37 -0
- package/src/validation/index.ts +109 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hetzner Cloud Placement Groups API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HCloudClient } from "@/client/index";
|
|
7
|
+
import type {
|
|
8
|
+
ListPlacementGroupsParams,
|
|
9
|
+
ListPlacementGroupsResponse,
|
|
10
|
+
CreatePlacementGroupParams,
|
|
11
|
+
CreatePlacementGroupResponse,
|
|
12
|
+
GetPlacementGroupResponse,
|
|
13
|
+
UpdatePlacementGroupParams,
|
|
14
|
+
UpdatePlacementGroupResponse,
|
|
15
|
+
DeletePlacementGroupResponse,
|
|
16
|
+
} from "@/apis/placement-groups/types";
|
|
17
|
+
import { validate } from "@/validation/index";
|
|
18
|
+
import {
|
|
19
|
+
listPlacementGroupsResponseSchema,
|
|
20
|
+
createPlacementGroupRequestSchema,
|
|
21
|
+
createPlacementGroupResponseSchema,
|
|
22
|
+
getPlacementGroupResponseSchema,
|
|
23
|
+
updatePlacementGroupRequestSchema,
|
|
24
|
+
updatePlacementGroupResponseSchema,
|
|
25
|
+
deletePlacementGroupResponseSchema,
|
|
26
|
+
} from "@/apis/placement-groups/schemas";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Placement Groups API client
|
|
30
|
+
*/
|
|
31
|
+
export class PlacementGroupsClient {
|
|
32
|
+
constructor(private readonly client: HCloudClient) {}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns all Placement Group objects.
|
|
36
|
+
*
|
|
37
|
+
* @param params - Query parameters for filtering and pagination
|
|
38
|
+
* @returns Promise resolving to list of placement groups with pagination metadata
|
|
39
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-list-placement-groups
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
44
|
+
*
|
|
45
|
+
* // List all placement groups
|
|
46
|
+
* const result = await client.placementGroups.list();
|
|
47
|
+
*
|
|
48
|
+
* // List placement groups with filters
|
|
49
|
+
* const groups = await client.placementGroups.list({
|
|
50
|
+
* name: 'my-group',
|
|
51
|
+
* label_selector: 'environment=production',
|
|
52
|
+
* sort: ['name:asc'],
|
|
53
|
+
* page: 1,
|
|
54
|
+
* per_page: 50
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async list(params?: ListPlacementGroupsParams): Promise<ListPlacementGroupsResponse> {
|
|
59
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
60
|
+
|
|
61
|
+
if (params?.name) {
|
|
62
|
+
queryParams.name = params.name;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (params?.label_selector) {
|
|
66
|
+
queryParams.label_selector = params.label_selector;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (params?.sort) {
|
|
70
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (params?.page !== undefined) {
|
|
74
|
+
queryParams.page = params.page;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (params?.per_page !== undefined) {
|
|
78
|
+
queryParams.per_page = params.per_page;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const response = await this.client.get<unknown>("/placement_groups", queryParams);
|
|
82
|
+
|
|
83
|
+
return validate(listPlacementGroupsResponseSchema, response, {
|
|
84
|
+
context: "List placement groups response",
|
|
85
|
+
detailed: true,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new Placement Group.
|
|
91
|
+
*
|
|
92
|
+
* @param params - Parameters for creating the placement group
|
|
93
|
+
* @returns Promise resolving to the created placement group
|
|
94
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-create-a-placement-group
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
99
|
+
*
|
|
100
|
+
* // Create a placement group
|
|
101
|
+
* const group = await client.placementGroups.create({
|
|
102
|
+
* name: 'my-placement-group',
|
|
103
|
+
* type: 'spread',
|
|
104
|
+
* labels: { environment: 'production' }
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
async create(params: CreatePlacementGroupParams): Promise<CreatePlacementGroupResponse> {
|
|
109
|
+
const validatedParams = validate(createPlacementGroupRequestSchema, params, {
|
|
110
|
+
context: "Create placement group request",
|
|
111
|
+
detailed: true,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const response = await this.client.post<unknown>("/placement_groups", validatedParams);
|
|
115
|
+
|
|
116
|
+
return validate(createPlacementGroupResponseSchema, response, {
|
|
117
|
+
context: "Create placement group response",
|
|
118
|
+
detailed: true,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns a specific Placement Group object.
|
|
124
|
+
*
|
|
125
|
+
* @param id - ID of the Placement Group
|
|
126
|
+
* @returns Promise resolving to the placement group
|
|
127
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-get-a-placement-group
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
132
|
+
*
|
|
133
|
+
* // Get a placement group by ID
|
|
134
|
+
* const group = await client.placementGroups.get(12345);
|
|
135
|
+
* console.log(group.placement_group.name);
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async get(id: number): Promise<GetPlacementGroupResponse> {
|
|
139
|
+
const response = await this.client.get<unknown>(`/placement_groups/${id}`);
|
|
140
|
+
|
|
141
|
+
return validate(getPlacementGroupResponseSchema, response, {
|
|
142
|
+
context: "Get placement group response",
|
|
143
|
+
detailed: true,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Updates the Placement Group.
|
|
149
|
+
*
|
|
150
|
+
* You can update a Placement Group's name and labels.
|
|
151
|
+
*
|
|
152
|
+
* @param id - ID of the Placement Group
|
|
153
|
+
* @param params - Parameters to update (name and/or labels)
|
|
154
|
+
* @returns Promise resolving to the updated placement group
|
|
155
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-update-a-placement-group
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
160
|
+
*
|
|
161
|
+
* // Update placement group name
|
|
162
|
+
* const updated = await client.placementGroups.update(12345, {
|
|
163
|
+
* name: 'new-group-name'
|
|
164
|
+
* });
|
|
165
|
+
*
|
|
166
|
+
* // Update labels
|
|
167
|
+
* const updated = await client.placementGroups.update(12345, {
|
|
168
|
+
* labels: { environment: 'production', team: 'backend' }
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
async update(
|
|
173
|
+
id: number,
|
|
174
|
+
params: UpdatePlacementGroupParams,
|
|
175
|
+
): Promise<UpdatePlacementGroupResponse> {
|
|
176
|
+
const validatedParams = validate(updatePlacementGroupRequestSchema, params, {
|
|
177
|
+
context: "Update placement group request",
|
|
178
|
+
detailed: true,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const response = await this.client.put<unknown>(`/placement_groups/${id}`, validatedParams);
|
|
182
|
+
|
|
183
|
+
return validate(updatePlacementGroupResponseSchema, response, {
|
|
184
|
+
context: "Update placement group response",
|
|
185
|
+
detailed: true,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Deletes a Placement Group.
|
|
191
|
+
*
|
|
192
|
+
* @param id - ID of the Placement Group
|
|
193
|
+
* @returns Promise resolving to empty object
|
|
194
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-delete-a-placement-group
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
199
|
+
*
|
|
200
|
+
* // Delete a placement group
|
|
201
|
+
* await client.placementGroups.delete(12345);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
async delete(id: number): Promise<DeletePlacementGroupResponse> {
|
|
205
|
+
const response = await this.client.delete<unknown>(`/placement_groups/${id}`);
|
|
206
|
+
|
|
207
|
+
return validate(deletePlacementGroupResponseSchema, response, {
|
|
208
|
+
context: "Delete placement group response",
|
|
209
|
+
detailed: true,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for Hetzner Cloud Placement Groups API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { actionSchema } from "@/apis/actions/schemas";
|
|
8
|
+
import { paginationMetaSchema } from "@/apis/common/schemas";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Placement Group type schema
|
|
12
|
+
*/
|
|
13
|
+
export const placementGroupTypeSchema = z.enum(["spread"]);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Placement Group schema
|
|
17
|
+
*/
|
|
18
|
+
export const placementGroupSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
id: z.number(),
|
|
21
|
+
name: z.string(),
|
|
22
|
+
labels: z.record(z.string(), z.string()),
|
|
23
|
+
created: z.string(),
|
|
24
|
+
servers: z.array(z.number()),
|
|
25
|
+
type: placementGroupTypeSchema,
|
|
26
|
+
})
|
|
27
|
+
.passthrough();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* List Placement Groups response schema
|
|
31
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-list-placement-groups
|
|
32
|
+
*/
|
|
33
|
+
export const listPlacementGroupsResponseSchema = z.object({
|
|
34
|
+
placement_groups: z.array(placementGroupSchema),
|
|
35
|
+
meta: z
|
|
36
|
+
.object({
|
|
37
|
+
pagination: paginationMetaSchema,
|
|
38
|
+
})
|
|
39
|
+
.optional(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create Placement Group request schema
|
|
44
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-create-a-placement-group
|
|
45
|
+
*/
|
|
46
|
+
export const createPlacementGroupRequestSchema = z.object({
|
|
47
|
+
name: z.string(),
|
|
48
|
+
type: placementGroupTypeSchema,
|
|
49
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create Placement Group response schema
|
|
54
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-create-a-placement-group
|
|
55
|
+
*/
|
|
56
|
+
export const createPlacementGroupResponseSchema = z.object({
|
|
57
|
+
placement_group: placementGroupSchema,
|
|
58
|
+
action: actionSchema.optional(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get Placement Group response schema
|
|
63
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-get-a-placement-group
|
|
64
|
+
*/
|
|
65
|
+
export const getPlacementGroupResponseSchema = z.object({
|
|
66
|
+
placement_group: placementGroupSchema,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Update Placement Group request schema
|
|
71
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-update-a-placement-group
|
|
72
|
+
*/
|
|
73
|
+
export const updatePlacementGroupRequestSchema = z.object({
|
|
74
|
+
name: z.string().optional(),
|
|
75
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Update Placement Group response schema
|
|
80
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-update-a-placement-group
|
|
81
|
+
*/
|
|
82
|
+
export const updatePlacementGroupResponseSchema = z.object({
|
|
83
|
+
placement_group: placementGroupSchema,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Delete Placement Group response schema
|
|
88
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-delete-a-placement-group
|
|
89
|
+
*/
|
|
90
|
+
export const deletePlacementGroupResponseSchema = z.object({});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Hetzner Cloud Placement Groups API
|
|
3
|
+
* Types are inferred from Zod schemas
|
|
4
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// biome-ignore assist/source/organizeImports: we need to import the schemas first
|
|
8
|
+
import {
|
|
9
|
+
listPlacementGroupsResponseSchema,
|
|
10
|
+
createPlacementGroupRequestSchema,
|
|
11
|
+
createPlacementGroupResponseSchema,
|
|
12
|
+
getPlacementGroupResponseSchema,
|
|
13
|
+
updatePlacementGroupRequestSchema,
|
|
14
|
+
updatePlacementGroupResponseSchema,
|
|
15
|
+
deletePlacementGroupResponseSchema,
|
|
16
|
+
placementGroupSchema,
|
|
17
|
+
placementGroupTypeSchema,
|
|
18
|
+
} from "@/apis/placement-groups/schemas";
|
|
19
|
+
import type { z } from "zod";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Placement Group type
|
|
23
|
+
*/
|
|
24
|
+
export type PlacementGroupType = z.infer<typeof placementGroupTypeSchema>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Hetzner Cloud Placement Group
|
|
28
|
+
*/
|
|
29
|
+
export type PlacementGroup = z.infer<typeof placementGroupSchema>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* List Placement Groups query parameters
|
|
33
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-list-placement-groups
|
|
34
|
+
*/
|
|
35
|
+
export interface ListPlacementGroupsParams {
|
|
36
|
+
/**
|
|
37
|
+
* Can be used to filter resources by their name. The response will only contain the resources matching the specified name.
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc, created, created:asc, created:desc
|
|
42
|
+
* @see https://docs.hetzner.cloud/reference/cloud#sorting
|
|
43
|
+
*/
|
|
44
|
+
sort?: string | string[];
|
|
45
|
+
/**
|
|
46
|
+
* Can be used to filter resources by labels. The response will only contain resources matching the label selector.
|
|
47
|
+
*/
|
|
48
|
+
label_selector?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
51
|
+
*/
|
|
52
|
+
page?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
55
|
+
*/
|
|
56
|
+
per_page?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* List Placement Groups response
|
|
61
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-list-placement-groups
|
|
62
|
+
*/
|
|
63
|
+
export type ListPlacementGroupsResponse = z.infer<typeof listPlacementGroupsResponseSchema>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create Placement Group parameters
|
|
67
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-create-a-placement-group
|
|
68
|
+
*/
|
|
69
|
+
export type CreatePlacementGroupParams = z.infer<typeof createPlacementGroupRequestSchema>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create Placement Group response
|
|
73
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-create-a-placement-group
|
|
74
|
+
*/
|
|
75
|
+
export type CreatePlacementGroupResponse = z.infer<typeof createPlacementGroupResponseSchema>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get Placement Group response
|
|
79
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-get-a-placement-group
|
|
80
|
+
*/
|
|
81
|
+
export type GetPlacementGroupResponse = z.infer<typeof getPlacementGroupResponseSchema>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Update Placement Group parameters
|
|
85
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-update-a-placement-group
|
|
86
|
+
*/
|
|
87
|
+
export type UpdatePlacementGroupParams = z.infer<typeof updatePlacementGroupRequestSchema>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Update Placement Group response
|
|
91
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-update-a-placement-group
|
|
92
|
+
*/
|
|
93
|
+
export type UpdatePlacementGroupResponse = z.infer<typeof updatePlacementGroupResponseSchema>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Delete Placement Group response
|
|
97
|
+
* @see https://docs.hetzner.cloud/reference/cloud#placement-groups-delete-a-placement-group
|
|
98
|
+
*/
|
|
99
|
+
export type DeletePlacementGroupResponse = z.infer<typeof deletePlacementGroupResponseSchema>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hetzner Cloud Pricing API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#pricing
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HCloudClient } from "@/client/index";
|
|
7
|
+
import type { GetPricingResponse } from "@/apis/pricing/types";
|
|
8
|
+
import { validate } from "@/validation/index";
|
|
9
|
+
import { getPricingResponseSchema } from "@/apis/pricing/schemas";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Pricing API client
|
|
13
|
+
*/
|
|
14
|
+
export class PricingClient {
|
|
15
|
+
constructor(private readonly client: HCloudClient) {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns all prices for all resources.
|
|
19
|
+
*
|
|
20
|
+
* @returns Promise resolving to all pricing information
|
|
21
|
+
* @see https://docs.hetzner.cloud/reference/cloud#pricing-get-all-prices
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
26
|
+
*
|
|
27
|
+
* // Get all prices
|
|
28
|
+
* const pricing = await client.pricing.getAll();
|
|
29
|
+
* console.log(`Currency: ${pricing.currency}`);
|
|
30
|
+
* console.log(`VAT Rate: ${pricing.vat_rate}`);
|
|
31
|
+
* console.log(`Server Types: ${pricing.server_types.length}`);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
async getAll(): Promise<GetPricingResponse> {
|
|
35
|
+
const response = await this.client.get<unknown>("/pricing");
|
|
36
|
+
|
|
37
|
+
return validate(getPricingResponseSchema, response, {
|
|
38
|
+
context: "Get pricing response",
|
|
39
|
+
detailed: true,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for Hetzner Cloud Pricing API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#pricing
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Price schema
|
|
10
|
+
*/
|
|
11
|
+
export const priceSchema = z.object({
|
|
12
|
+
net: z.string(),
|
|
13
|
+
gross: z.string(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Pricing location schema
|
|
18
|
+
*/
|
|
19
|
+
export const pricingLocationSchema = z.object({
|
|
20
|
+
location: z.string(),
|
|
21
|
+
price_hourly: priceSchema,
|
|
22
|
+
price_monthly: priceSchema,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Server type pricing schema
|
|
27
|
+
*/
|
|
28
|
+
export const serverTypePricingSchema = z.object({
|
|
29
|
+
id: z.number(),
|
|
30
|
+
name: z.string(),
|
|
31
|
+
prices: z.array(pricingLocationSchema),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Load Balancer type pricing schema
|
|
36
|
+
*/
|
|
37
|
+
export const loadBalancerTypePricingSchema = z.object({
|
|
38
|
+
id: z.number(),
|
|
39
|
+
name: z.string(),
|
|
40
|
+
prices: z.array(pricingLocationSchema),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Volume pricing schema
|
|
45
|
+
*/
|
|
46
|
+
export const volumePricingSchema = z.object({
|
|
47
|
+
price_per_gb_month: priceSchema,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Floating IP pricing schema
|
|
52
|
+
*/
|
|
53
|
+
export const floatingIpPricingSchema = z.object({
|
|
54
|
+
price_monthly: priceSchema,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Primary IP pricing schema
|
|
59
|
+
*/
|
|
60
|
+
export const primaryIpPricingSchema = z.object({
|
|
61
|
+
price_monthly: priceSchema,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Traffic pricing schema
|
|
66
|
+
*/
|
|
67
|
+
export const trafficPricingSchema = z.object({
|
|
68
|
+
price_per_tb: priceSchema,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Image pricing schema
|
|
73
|
+
*/
|
|
74
|
+
export const imagePricingSchema = z.object({
|
|
75
|
+
price_per_gb_month: priceSchema,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get Pricing response schema
|
|
80
|
+
* @see https://docs.hetzner.cloud/reference/cloud#pricing-get-all-prices
|
|
81
|
+
*/
|
|
82
|
+
export const getPricingResponseSchema = z.object({
|
|
83
|
+
currency: z.string(),
|
|
84
|
+
vat_rate: z.string(),
|
|
85
|
+
image: imagePricingSchema,
|
|
86
|
+
floating_ip: floatingIpPricingSchema,
|
|
87
|
+
floating_ip_price_monthly: priceSchema,
|
|
88
|
+
primary_ips: z.array(primaryIpPricingSchema).optional(),
|
|
89
|
+
server_types: z.array(serverTypePricingSchema),
|
|
90
|
+
load_balancer_types: z.array(loadBalancerTypePricingSchema).optional(),
|
|
91
|
+
volume: volumePricingSchema,
|
|
92
|
+
traffic: trafficPricingSchema,
|
|
93
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Hetzner Cloud Pricing API
|
|
3
|
+
* Types are inferred from Zod schemas
|
|
4
|
+
* @see https://docs.hetzner.cloud/reference/cloud#pricing
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// biome-ignore assist/source/organizeImports: we need to import the schemas first
|
|
8
|
+
import {
|
|
9
|
+
getPricingResponseSchema,
|
|
10
|
+
priceSchema,
|
|
11
|
+
pricingLocationSchema,
|
|
12
|
+
serverTypePricingSchema,
|
|
13
|
+
loadBalancerTypePricingSchema,
|
|
14
|
+
volumePricingSchema,
|
|
15
|
+
floatingIpPricingSchema,
|
|
16
|
+
primaryIpPricingSchema,
|
|
17
|
+
trafficPricingSchema,
|
|
18
|
+
imagePricingSchema,
|
|
19
|
+
} from "@/apis/pricing/schemas";
|
|
20
|
+
import type { z } from "zod";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Price
|
|
24
|
+
*/
|
|
25
|
+
export type Price = z.infer<typeof priceSchema>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Pricing location
|
|
29
|
+
*/
|
|
30
|
+
export type PricingLocation = z.infer<typeof pricingLocationSchema>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Server type pricing
|
|
34
|
+
*/
|
|
35
|
+
export type ServerTypePricing = z.infer<typeof serverTypePricingSchema>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Load Balancer type pricing
|
|
39
|
+
*/
|
|
40
|
+
export type LoadBalancerTypePricing = z.infer<typeof loadBalancerTypePricingSchema>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Volume pricing
|
|
44
|
+
*/
|
|
45
|
+
export type VolumePricing = z.infer<typeof volumePricingSchema>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Floating IP pricing
|
|
49
|
+
*/
|
|
50
|
+
export type FloatingIpPricing = z.infer<typeof floatingIpPricingSchema>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Primary IP pricing
|
|
54
|
+
*/
|
|
55
|
+
export type PrimaryIpPricing = z.infer<typeof primaryIpPricingSchema>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Traffic pricing
|
|
59
|
+
*/
|
|
60
|
+
export type TrafficPricing = z.infer<typeof trafficPricingSchema>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Image pricing
|
|
64
|
+
*/
|
|
65
|
+
export type ImagePricing = z.infer<typeof imagePricingSchema>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get Pricing response
|
|
69
|
+
* @see https://docs.hetzner.cloud/reference/cloud#pricing-get-all-prices
|
|
70
|
+
*/
|
|
71
|
+
export type GetPricingResponse = z.infer<typeof getPricingResponseSchema>;
|