@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.
Files changed (62) hide show
  1. package/README.md +90 -0
  2. package/package.json +70 -0
  3. package/src/apis/actions/index.ts +113 -0
  4. package/src/apis/actions/schemas.ts +59 -0
  5. package/src/apis/actions/types.ts +77 -0
  6. package/src/apis/certificates/index.ts +326 -0
  7. package/src/apis/certificates/schemas.ts +140 -0
  8. package/src/apis/certificates/types.ts +176 -0
  9. package/src/apis/common/schemas.ts +19 -0
  10. package/src/apis/dns/index.ts +961 -0
  11. package/src/apis/dns/schemas.ts +437 -0
  12. package/src/apis/dns/types.ts +397 -0
  13. package/src/apis/firewalls/index.ts +469 -0
  14. package/src/apis/firewalls/schemas.ts +274 -0
  15. package/src/apis/firewalls/types.ts +205 -0
  16. package/src/apis/floating-ips/index.ts +466 -0
  17. package/src/apis/floating-ips/schemas.ts +203 -0
  18. package/src/apis/floating-ips/types.ts +207 -0
  19. package/src/apis/images/index.ts +195 -0
  20. package/src/apis/images/schemas.ts +113 -0
  21. package/src/apis/images/types.ts +124 -0
  22. package/src/apis/isos/index.ts +91 -0
  23. package/src/apis/isos/schemas.ts +43 -0
  24. package/src/apis/isos/types.ts +60 -0
  25. package/src/apis/load-balancers/index.ts +892 -0
  26. package/src/apis/load-balancers/schemas.ts +561 -0
  27. package/src/apis/load-balancers/types.ts +361 -0
  28. package/src/apis/locations/index.ts +176 -0
  29. package/src/apis/locations/schemas.ts +83 -0
  30. package/src/apis/locations/types.ts +113 -0
  31. package/src/apis/networks/index.ts +544 -0
  32. package/src/apis/networks/schemas.ts +279 -0
  33. package/src/apis/networks/types.ts +243 -0
  34. package/src/apis/placement-groups/index.ts +212 -0
  35. package/src/apis/placement-groups/schemas.ts +90 -0
  36. package/src/apis/placement-groups/types.ts +99 -0
  37. package/src/apis/pricing/index.ts +42 -0
  38. package/src/apis/pricing/schemas.ts +93 -0
  39. package/src/apis/pricing/types.ts +71 -0
  40. package/src/apis/primary-ips/index.ts +467 -0
  41. package/src/apis/primary-ips/schemas.ts +221 -0
  42. package/src/apis/primary-ips/types.ts +221 -0
  43. package/src/apis/server-types/index.ts +93 -0
  44. package/src/apis/server-types/schemas.ts +29 -0
  45. package/src/apis/server-types/types.ts +43 -0
  46. package/src/apis/servers/index.ts +378 -0
  47. package/src/apis/servers/schemas.ts +771 -0
  48. package/src/apis/servers/types.ts +538 -0
  49. package/src/apis/ssh-keys/index.ts +204 -0
  50. package/src/apis/ssh-keys/schemas.ts +84 -0
  51. package/src/apis/ssh-keys/types.ts +106 -0
  52. package/src/apis/volumes/index.ts +452 -0
  53. package/src/apis/volumes/schemas.ts +195 -0
  54. package/src/apis/volumes/types.ts +197 -0
  55. package/src/auth/index.ts +26 -0
  56. package/src/base/index.ts +10 -0
  57. package/src/client/index.ts +388 -0
  58. package/src/config/index.ts +34 -0
  59. package/src/errors/index.ts +38 -0
  60. package/src/index.ts +799 -0
  61. package/src/types/index.ts +37 -0
  62. package/src/validation/index.ts +109 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Hetzner Cloud ISOs API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#isos
4
+ */
5
+
6
+ import type { HCloudClient } from "@/client/index";
7
+ import type { ListISOsParams, ListISOsResponse, GetISOResponse } from "@/apis/isos/types";
8
+ import { validate } from "@/validation/index";
9
+ import { listISOsResponseSchema, getISOResponseSchema } from "@/apis/isos/schemas";
10
+
11
+ /**
12
+ * ISOs API client
13
+ */
14
+ export class ISOsClient {
15
+ constructor(private readonly client: HCloudClient) {}
16
+
17
+ /**
18
+ * Returns all available ISO objects.
19
+ *
20
+ * @param params - Query parameters for filtering and pagination
21
+ * @returns Promise resolving to list of ISOs with pagination metadata
22
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-list-isos
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const client = new HCloudClient({ token: 'your-token' });
27
+ *
28
+ * // List all ISOs
29
+ * const result = await client.isos.list();
30
+ *
31
+ * // List ISOs with filters
32
+ * const isos = await client.isos.list({
33
+ * name: 'debian',
34
+ * sort: ['name:asc'],
35
+ * page: 1,
36
+ * per_page: 50
37
+ * });
38
+ * ```
39
+ */
40
+ async list(params?: ListISOsParams): Promise<ListISOsResponse> {
41
+ const queryParams: Record<string, string | number | string[] | undefined> = {};
42
+
43
+ if (params?.name) {
44
+ queryParams.name = params.name;
45
+ }
46
+
47
+ if (params?.sort) {
48
+ queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
49
+ }
50
+
51
+ if (params?.page !== undefined) {
52
+ queryParams.page = params.page;
53
+ }
54
+
55
+ if (params?.per_page !== undefined) {
56
+ queryParams.per_page = params.per_page;
57
+ }
58
+
59
+ const response = await this.client.get<unknown>("/isos", queryParams);
60
+
61
+ return validate(listISOsResponseSchema, response, {
62
+ context: "List ISOs response",
63
+ detailed: true,
64
+ });
65
+ }
66
+
67
+ /**
68
+ * Returns a specific ISO object.
69
+ *
70
+ * @param id - ID of the ISO
71
+ * @returns Promise resolving to the ISO
72
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-get-an-iso
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const client = new HCloudClient({ token: 'your-token' });
77
+ *
78
+ * // Get an ISO by ID
79
+ * const iso = await client.isos.get(12345);
80
+ * console.log(iso.iso.name);
81
+ * ```
82
+ */
83
+ async get(id: number): Promise<GetISOResponse> {
84
+ const response = await this.client.get<unknown>(`/isos/${id}`);
85
+
86
+ return validate(getISOResponseSchema, response, {
87
+ context: "Get ISO response",
88
+ detailed: true,
89
+ });
90
+ }
91
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Zod schemas for Hetzner Cloud ISOs API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-list-isos
4
+ */
5
+
6
+ import { z } from "zod";
7
+ import { paginationMetaSchema } from "@/apis/common/schemas";
8
+
9
+ /**
10
+ * ISO type schema
11
+ */
12
+ export const isoTypeSchema = z.enum(["public", "private"]);
13
+
14
+ /**
15
+ * ISO schema
16
+ */
17
+ export const isoSchema = z.object({
18
+ id: z.number(),
19
+ name: z.string(),
20
+ description: z.string(),
21
+ type: isoTypeSchema,
22
+ });
23
+
24
+ /**
25
+ * List ISOs response schema
26
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-list-isos
27
+ */
28
+ export const listISOsResponseSchema = z.object({
29
+ isos: z.array(isoSchema),
30
+ meta: z
31
+ .object({
32
+ pagination: paginationMetaSchema,
33
+ })
34
+ .optional(),
35
+ });
36
+
37
+ /**
38
+ * Get ISO response schema
39
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-get-an-iso
40
+ */
41
+ export const getISOResponseSchema = z.object({
42
+ iso: isoSchema,
43
+ });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Types for Hetzner Cloud ISOs API
3
+ * Types are inferred from Zod schemas
4
+ * @see https://docs.hetzner.cloud/reference/cloud#isos
5
+ */
6
+
7
+ // biome-ignore assist/source/organizeImports: we need to import the schemas first
8
+ import {
9
+ listISOsResponseSchema,
10
+ getISOResponseSchema,
11
+ isoSchema,
12
+ isoTypeSchema,
13
+ } from "@/apis/isos/schemas";
14
+ import type { z } from "zod";
15
+
16
+ /**
17
+ * ISO type
18
+ */
19
+ export type ISOType = z.infer<typeof isoTypeSchema>;
20
+
21
+ /**
22
+ * Hetzner Cloud ISO
23
+ */
24
+ export type ISO = z.infer<typeof isoSchema>;
25
+
26
+ /**
27
+ * List ISOs query parameters
28
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-list-isos
29
+ */
30
+ export interface ListISOsParams {
31
+ /**
32
+ * Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc
33
+ * @see https://docs.hetzner.cloud/reference/cloud#sorting
34
+ */
35
+ sort?: string | string[];
36
+ /**
37
+ * Can be used to filter ISOs by their name. The response will only contain the ISO matching the specified name.
38
+ */
39
+ name?: string;
40
+ /**
41
+ * Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
42
+ */
43
+ page?: number;
44
+ /**
45
+ * Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
46
+ */
47
+ per_page?: number;
48
+ }
49
+
50
+ /**
51
+ * List ISOs response
52
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-list-isos
53
+ */
54
+ export type ListISOsResponse = z.infer<typeof listISOsResponseSchema>;
55
+
56
+ /**
57
+ * Get ISO response
58
+ * @see https://docs.hetzner.cloud/reference/cloud#isos-get-an-iso
59
+ */
60
+ export type GetISOResponse = z.infer<typeof getISOResponseSchema>;