@highstate/library 0.9.15 → 0.9.16

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/src/network.ts CHANGED
@@ -52,7 +52,7 @@ export const l3EndpointEntity = defineEntity({
52
52
 
53
53
  export const l4ProtocolSchema = Type.StringEnum(["tcp", "udp"])
54
54
 
55
- export const portInfoSchema = Type.Object({
55
+ export const l4PortInfoSchema = Type.Object({
56
56
  port: Type.Number(),
57
57
  protocol: l4ProtocolSchema,
58
58
  })
@@ -60,7 +60,7 @@ export const portInfoSchema = Type.Object({
60
60
  export const l4EndpointEntity = defineEntity({
61
61
  type: "network.l4-endpoint",
62
62
 
63
- schema: Type.Intersect([l3EndpointEntity.schema, portInfoSchema]),
63
+ schema: Type.Intersect([l3EndpointEntity.schema, l4PortInfoSchema]),
64
64
 
65
65
  meta: {
66
66
  color: "#2196F3",
@@ -68,6 +68,33 @@ export const l4EndpointEntity = defineEntity({
68
68
  },
69
69
  })
70
70
 
71
+ export const l7AppInfoSchema = Type.Object({
72
+ /**
73
+ * The name of the application protocol used by the endpoint.
74
+ */
75
+ appProtocol: Type.String(),
76
+
77
+ /**
78
+ * The resource path of the application endpoint, including query parameters.
79
+ * Must not start with a slash (`/`).
80
+ *
81
+ * Example: `api/v1/resource?query=value`, `database?param=value`, `user/repo.git`.
82
+ */
83
+ resource: Type.Optional(Type.String()),
84
+ })
85
+
86
+ export const l7EndpointEntity = defineEntity({
87
+ type: "network.l7-endpoint",
88
+
89
+ schema: Type.Intersect([l4EndpointEntity.schema, l7AppInfoSchema]),
90
+
91
+ meta: {
92
+ color: "#FF9800",
93
+ description:
94
+ "The L7 endpoint for some service. Extends an L4 endpoint with application protocol information.",
95
+ },
96
+ })
97
+
71
98
  export const l3Endpoint = defineUnit({
72
99
  type: "network.l3-endpoint",
73
100
 
@@ -156,13 +183,9 @@ export const l4Endpoint = defineUnit({
156
183
  export type EndpointVisibility = Static<typeof endpointVisibilitySchema>
157
184
 
158
185
  /**
159
- * Filter values used to select relevant endpoints based on visibility.
186
+ * The list of endpoint visibility levels used to filter endpoints.
160
187
  *
161
- * - `public`: Only endpoints exposed to the public internet.
162
- * - `private`: Endpoints not publicly accessible (external + internal).
163
- * - `external`: Reachable from outside the system but not public (e.g., LAN, VPC).
164
- * - `internal`: Reachable only from within the system boundary (e.g., inside a cluster).
165
- * - `most`: Select the most widely accessible endpoints, preferring visibility in the following order: `public` > `external` > `internal`.
188
+ * If empty, it will filter the most widely accessible endpoints, prefering visibility in the following order:
166
189
  * - If any public endpoints exist, all public endpoints are selected.
167
190
  * - Otherwise, if any external endpoints exist, all external endpoints are selected.
168
191
  * - If neither exist, all internal endpoints are selected.
@@ -172,7 +195,9 @@ export type EndpointFilter = Static<typeof endpointFilterSchema>
172
195
  export type L3Endpoint = Static<typeof l3EndpointEntity.schema>
173
196
  export type L4Endpoint = Static<typeof l4EndpointEntity.schema>
174
197
  export type L4Protocol = Static<typeof l4ProtocolSchema>
175
- export type L4PortInfo = Static<typeof portInfoSchema>
198
+ export type L4PortInfo = Static<typeof l4PortInfoSchema>
199
+ export type L7Endpoint = Static<typeof l7EndpointEntity.schema>
200
+ export type L7AppInfo = Static<typeof l7AppInfoSchema>
176
201
 
177
202
  /**
178
203
  * The L3 or L4 endpoint for some service.
package/src/nixos.ts CHANGED
@@ -1,24 +1,49 @@
1
- import { defineEntity, defineUnit, Type } from "@highstate/contract"
2
- import { fileEntity, serverEntity } from "./common"
3
-
4
- export const inlineModuleEntity = defineEntity({
5
- type: "nixos.inline-module",
6
-
7
- schema: Type.Object({
8
- code: Type.String(),
9
- }),
10
-
11
- meta: {
12
- displayName: "NixOS Inline Module",
13
- description: "The NixOS module reference.",
14
- color: "#5277c3",
15
- },
16
- })
1
+ import { defineUnit, Type } from "@highstate/contract"
2
+ import { fileEntity, folderEntity } from "./files"
3
+ import { serverEntity } from "./common"
4
+
5
+ // export const moduleEntity = defineEntity({
6
+ // type: "nixos.module",
7
+
8
+ // schema: Type.Object({
9
+ // /**
10
+ // * The folder containing the NixOS module files.
11
+ // *
12
+ // * @schema
13
+ // */
14
+ // folder: folderEntity.schema,
15
+
16
+ // /**
17
+ // * The name of the module file entrypoint to use when importing this module.
18
+ // *
19
+ // * @schema
20
+ // */
21
+ // entrypoint: Type.String(),
22
+ // }),
23
+
24
+ // meta: {
25
+ // displayName: "NixOS Module",
26
+ // description: "The NixOS module reference.",
27
+ // color: "#5277c3",
28
+ // },
29
+ // })
17
30
 
18
31
  export const inlineModule = defineUnit({
19
32
  type: "nixos.inline-module",
20
33
 
21
34
  args: {
35
+ /**
36
+ * The name of the module file.
37
+ *
38
+ * If not provided, the name will be the name of the unit.
39
+ */
40
+ moduleName: Type.Optional(Type.String()),
41
+
42
+ /**
43
+ * The code of the NixOS module.
44
+ *
45
+ * In this code you can reference other modules and files by their names.
46
+ */
22
47
  code: Type.String({ language: "nix" }),
23
48
  },
24
49
 
@@ -28,10 +53,15 @@ export const inlineModule = defineUnit({
28
53
  required: false,
29
54
  multiple: true,
30
55
  },
56
+ folders: {
57
+ entity: folderEntity,
58
+ required: false,
59
+ multiple: true,
60
+ },
31
61
  },
32
62
 
33
63
  outputs: {
34
- module: inlineModuleEntity,
64
+ folder: folderEntity,
35
65
  },
36
66
 
37
67
  meta: {
@@ -49,74 +79,68 @@ export const inlineModule = defineUnit({
49
79
  },
50
80
  })
51
81
 
52
- export const flakeEntity = defineEntity({
53
- type: "nixos.flake",
54
-
55
- schema: Type.Object({
56
- url: Type.String(),
57
- }),
58
-
59
- meta: {
60
- displayName: "NixOS Flake",
61
- description: "The NixOS flake reference.",
62
- color: "#5277c3",
63
- },
64
- })
65
-
66
- export const remoteFlake = defineUnit({
67
- type: "nixos.remote-flake",
68
-
69
- args: {
70
- url: Type.String(),
71
- },
72
-
73
- outputs: {
74
- flake: flakeEntity,
75
- },
76
-
77
- meta: {
78
- displayName: "NixOS Remote Flake",
79
- description: "References a remote NixOS flake.",
80
- primaryIcon: "simple-icons:nixos",
81
- primaryIconColor: "#7ebae4",
82
- secondaryIcon: "simple-icons:git",
83
- secondaryIconColor: "#f1502f",
84
- category: "NixOS",
85
- },
86
-
87
- source: {
88
- package: "@highstate/nixos",
89
- path: "flake",
90
- },
91
- })
82
+ // export const flakeEntity = defineEntity({
83
+ // type: "nixos.flake",
84
+
85
+ // schema: Type.Object({
86
+ // /**
87
+ // * The git repository where the flake is stored.
88
+ // *
89
+ // * @schema
90
+ // */
91
+ // repository: repositoryEntity.schema,
92
+
93
+ // /**
94
+ // * The relative path to the folder containing the flake.nix file.
95
+ // *
96
+ // * If not provided, the root of the repository will be used.
97
+ // *
98
+ // * @schema
99
+ // */
100
+ // flakePath: Type.Optional(Type.String()),
101
+ // }),
102
+
103
+ // meta: {
104
+ // displayName: "NixOS Flake",
105
+ // description: "The NixOS flake reference.",
106
+ // color: "#5277c3",
107
+ // },
108
+ // })
92
109
 
93
110
  export const inlineFlake = defineUnit({
94
111
  type: "nixos.inline-flake",
95
112
 
96
113
  args: {
114
+ /**
115
+ * The name of the flake folder.
116
+ *
117
+ * If not provided, the name will be the name of the unit.
118
+ */
119
+ flakeName: Type.Optional(Type.String()),
120
+
121
+ /**
122
+ * The code of the `flake.nix` file.
123
+ *
124
+ * In this code you can reference other flakes, modules, files, and folders by their names.
125
+ */
97
126
  code: Type.String({ language: "nix" }),
98
127
  },
99
128
 
100
129
  inputs: {
101
- flakes: {
102
- entity: flakeEntity,
130
+ files: {
131
+ entity: fileEntity,
103
132
  required: false,
104
133
  multiple: true,
105
134
  },
106
- modules: {
107
- entity: inlineModuleEntity,
108
- required: false,
109
- multiple: true,
110
- },
111
- files: {
112
- entity: fileEntity,
135
+ folders: {
136
+ entity: folderEntity,
113
137
  required: false,
114
138
  multiple: true,
115
139
  },
116
140
  },
117
141
 
118
142
  outputs: {
119
- flake: flakeEntity,
143
+ folder: folderEntity,
120
144
  },
121
145
 
122
146
  meta: {
@@ -142,13 +166,8 @@ export const system = defineUnit({
142
166
  },
143
167
 
144
168
  inputs: {
145
- flake: flakeEntity,
146
169
  server: serverEntity,
147
- modules: {
148
- entity: inlineModuleEntity,
149
- required: false,
150
- multiple: true,
151
- },
170
+ flake: folderEntity,
152
171
  },
153
172
 
154
173
  outputs: {
@@ -1,9 +1,9 @@
1
- import { Type, type Static, type TObject } from "@highstate/contract"
1
+ import { $args, $inputs, $outputs, Type, type Static, type TObject } from "@highstate/contract"
2
2
  import { clusterEntity } from "../k8s"
3
3
  import { l4EndpointEntity } from "../network"
4
4
 
5
5
  export const deobfuscatorSpec = {
6
- args: {
6
+ args: $args({
7
7
  /**
8
8
  * The name of the namespace and deployment to deploy the deobfuscator on.
9
9
  *
@@ -15,8 +15,6 @@ export const deobfuscatorSpec = {
15
15
  * The L4 endpoint to forward deobfuscated traffic to.
16
16
  *
17
17
  * Will take precedence over the `targetEndpoint` input.
18
- *
19
- * @schema
20
18
  */
21
19
  targetEndpoints: Type.Default(Type.Array(Type.String()), []),
22
20
 
@@ -24,17 +22,13 @@ export const deobfuscatorSpec = {
24
22
  * Whether to expose the deobfuscator service by "NodePort" or "LoadBalancer".
25
23
  *
26
24
  * By default, the service is not exposed and only accessible from within the cluster.
27
- *
28
- * @schema
29
25
  */
30
26
  external: Type.Default(Type.Boolean(), false),
31
- },
27
+ }),
32
28
 
33
- inputs: {
29
+ inputs: $inputs({
34
30
  /**
35
31
  * The Kubernetes cluster to deploy the deobfuscator on.
36
- *
37
- * @schema
38
32
  */
39
33
  k8sCluster: clusterEntity,
40
34
 
@@ -42,32 +36,28 @@ export const deobfuscatorSpec = {
42
36
  * The L4 endpoints to forward deobfuscated traffic to.
43
37
  *
44
38
  * Will select the most appropriate endpoint based on the environment.
45
- *
46
- * @schema
47
39
  */
48
40
  targetEndpoints: {
49
41
  entity: l4EndpointEntity,
50
42
  required: false,
51
43
  multiple: true,
52
44
  },
53
- },
45
+ }),
54
46
 
55
- outputs: {
47
+ outputs: $outputs({
56
48
  /**
57
49
  * The L4 endpoints of the deobfuscator accepting obfuscated traffic.
58
- *
59
- * @schema
60
50
  */
61
51
  endpoints: {
62
52
  entity: l4EndpointEntity,
63
53
  required: false,
64
54
  multiple: true,
65
55
  },
66
- },
67
- } as const
56
+ }),
57
+ }
68
58
 
69
59
  export const obfuscatorSpec = {
70
- args: {
60
+ args: $args({
71
61
  /**
72
62
  * The name of the namespace and deployment to deploy the obfuscator on.
73
63
  *
@@ -79,8 +69,6 @@ export const obfuscatorSpec = {
79
69
  * The endpoint of the deobfuscator to pass obfuscated traffic to.
80
70
  *
81
71
  * Will take precedence over the `endpoint` input.
82
- *
83
- * @schema
84
72
  */
85
73
  endpoints: Type.Default(Type.Array(Type.String()), []),
86
74
 
@@ -88,17 +76,13 @@ export const obfuscatorSpec = {
88
76
  * Whether to expose the obfuscator service by "NodePort" or "LoadBalancer".
89
77
  *
90
78
  * By default, the service is not exposed and only accessible from within the cluster.
91
- *
92
- * @schema
93
79
  */
94
80
  external: Type.Default(Type.Boolean(), false),
95
- },
81
+ }),
96
82
 
97
- inputs: {
83
+ inputs: $inputs({
98
84
  /**
99
85
  * The Kubernetes cluster to deploy the obfuscator on.
100
- *
101
- * @schema
102
86
  */
103
87
  k8sCluster: clusterEntity,
104
88
 
@@ -106,28 +90,24 @@ export const obfuscatorSpec = {
106
90
  * The L4 endpoints of the deobfuscator to pass obfuscated traffic to.
107
91
  *
108
92
  * Will select the most appropriate endpoint based on the environment.
109
- *
110
- * @schema
111
93
  */
112
94
  endpoints: {
113
95
  entity: l4EndpointEntity,
114
96
  required: false,
115
97
  multiple: true,
116
98
  },
117
- },
99
+ }),
118
100
 
119
- outputs: {
101
+ outputs: $outputs({
120
102
  /**
121
103
  * The L4 endpoints accepting unobfuscated traffic.
122
- *
123
- * @schema
124
104
  */
125
105
  entryEndpoints: {
126
106
  entity: l4EndpointEntity,
127
107
  multiple: true,
128
108
  },
129
- },
130
- } as const
109
+ }),
110
+ }
131
111
 
132
112
  export type DeobfuscatorArgs = Static<TObject<(typeof deobfuscatorSpec)["args"]>>
133
113
  export type ObfuscatorArgs = Static<TObject<(typeof obfuscatorSpec)["args"]>>
package/src/proxmox.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { defineEntity, defineUnit, Type } from "@highstate/contract"
2
- import { serverOutputs } from "./common"
3
- import { keyPairEntity } from "./ssh"
2
+ import { checksumSchema, fileEntity, serverOutputs } from "./common"
3
+ import { credentialsSchema, keyPairEntity } from "./ssh"
4
+ import { l7EndpointEntity } from "./network"
4
5
 
5
6
  export const clusterEntity = defineEntity({
6
7
  type: "proxmox.cluster",
7
8
 
8
9
  schema: Type.Object({
9
- endpoint: Type.String(),
10
+ endpoint: l7EndpointEntity.schema,
10
11
  insecure: Type.Optional(Type.Boolean()),
11
12
  username: Type.Optional(Type.String()),
12
13
 
@@ -16,7 +17,7 @@ export const clusterEntity = defineEntity({
16
17
  password: Type.Optional(Type.String()),
17
18
  apiToken: Type.Optional(Type.String()),
18
19
 
19
- sshKeyPair: Type.Optional(keyPairEntity.schema),
20
+ ssh: Type.Optional(credentialsSchema),
20
21
  }),
21
22
 
22
23
  meta: {
@@ -40,20 +41,85 @@ export const connection = defineUnit({
40
41
  type: "proxmox.connection",
41
42
 
42
43
  args: {
44
+ /**
45
+ * The endpoint of the Proxmox API.
46
+ */
43
47
  endpoint: Type.String(),
48
+
49
+ /**
50
+ * Whether to allow insecure connections to the Proxmox API.
51
+ */
44
52
  insecure: Type.Optional(Type.Boolean()),
53
+
54
+ /**
55
+ * The username to use for the Proxmox API.
56
+ *
57
+ * Only required for password token authentication.
58
+ */
45
59
  username: Type.Optional(Type.String()),
46
60
 
61
+ /**
62
+ * The name of the default Proxmox node to use for operations.
63
+ *
64
+ * If not specified, the first node in the cluster will be used.
65
+ */
47
66
  defaultNodeName: Type.Optional(Type.String()),
67
+
68
+ /**
69
+ * The ID of the default Proxmox datastore to use for operations.
70
+ *
71
+ * If not specified, the first datastore in the cluster will be used.
72
+ */
48
73
  defaultDatastoreId: Type.Optional(Type.String()),
74
+
75
+ /**
76
+ * The username to use for SSH connections to the Proxmox nodes.
77
+ *
78
+ * By default, this is set to "root".
79
+ */
80
+ sshUser: Type.Default(Type.String(), "root"),
81
+
82
+ /**
83
+ * The port to use for SSH connections to the Proxmox nodes.
84
+ *
85
+ * By default, this is set to 22.
86
+ */
87
+ sshPort: Type.Default(Type.Number(), 22),
49
88
  },
50
89
 
51
90
  secrets: {
52
- password: Type.Optional(Type.String()),
53
- apiToken: Type.Optional(Type.String()),
91
+ /**
92
+ * The password to use for the Proxmox API.
93
+ *
94
+ * Requires `username` to be set.
95
+ */
96
+ password: {
97
+ schema: Type.Optional(Type.String()),
98
+ meta: {
99
+ displayName: "Proxmox Password",
100
+ },
101
+ },
102
+
103
+ /**
104
+ * The Proxmox API token to use for authentication.
105
+ */
106
+ apiToken: {
107
+ schema: Type.Optional(Type.String()),
108
+ meta: {
109
+ displayName: "Proxmox API Token",
110
+ },
111
+ },
112
+
113
+ /**
114
+ * The SSH password to use for connecting to the Proxmox nodes.
115
+ */
116
+ sshPassword: Type.Optional(Type.String()),
54
117
  },
55
118
 
56
119
  inputs: {
120
+ /**
121
+ * The key pair to use for SSH connections to the Proxmox nodes.
122
+ */
57
123
  sshKeyPair: {
58
124
  entity: keyPairEntity,
59
125
  required: false,
@@ -82,14 +148,54 @@ export const image = defineUnit({
82
148
  type: "proxmox.image",
83
149
 
84
150
  args: {
85
- url: Type.String(),
151
+ /**
152
+ * The name of the image to upload.
153
+ *
154
+ * If not specified, the default name is `<unitName>-<sha256>.<extension>`
155
+ * or `<unitName>.<extension>` if `sha256` is not provided.
156
+ */
157
+ fileName: Type.Optional(Type.String()),
158
+
159
+ /**
160
+ * The URL of the image to upload.
161
+ */
162
+ url: Type.Optional(Type.String()),
163
+
164
+ /**
165
+ * The checksum of the image file to verify.
166
+ */
167
+ checksum: Type.Optional(checksumSchema),
168
+
169
+ /**
170
+ * The name of the Proxmox node to upload the image to.
171
+ *
172
+ * If not specified, the default node name from the cluster will be used.
173
+ */
86
174
  nodeName: Type.Optional(Type.String()),
87
- sha256: Type.Optional(Type.String()),
175
+
176
+ /**
177
+ * The ID of the Proxmox datastore to upload the image to.
178
+ *
179
+ * If not specified, the default datastore ID from the cluster will be used.
180
+ */
88
181
  datastoreId: Type.Optional(Type.String()),
89
182
  },
90
183
 
91
184
  inputs: {
185
+ /**
186
+ * The Proxmox cluster to upload the image to.
187
+ */
92
188
  proxmoxCluster: clusterEntity,
189
+
190
+ /**
191
+ * The file to upload as an image.
192
+ *
193
+ * If `url` is not specified, this file will be used.
194
+ */
195
+ file: {
196
+ entity: fileEntity,
197
+ required: false,
198
+ },
93
199
  },
94
200
 
95
201
  outputs: {
@@ -152,6 +258,11 @@ export const virtualMachine = defineUnit({
152
258
  sockets: Type.Default(Type.Number(), 1),
153
259
  memory: Type.Default(Type.Number(), 512),
154
260
 
261
+ /**
262
+ * The IPv4 address to assign to the virtual machine.
263
+ *
264
+ * If not specified, the virtual machine will not have an IPv4 address.
265
+ */
155
266
  ipv4: Type.Optional(Type.String()),
156
267
  ipv4Gateway: Type.Optional(Type.String()),
157
268
  dns: Type.Optional(Type.Array(Type.String())),
@@ -179,6 +290,16 @@ export const virtualMachine = defineUnit({
179
290
  entity: keyPairEntity,
180
291
  required: false,
181
292
  },
293
+
294
+ /**
295
+ * The cloud-init vendor data to use for the virtual machine.
296
+ *
297
+ * You can provide a cloud-config from the distribution component.
298
+ */
299
+ vendorData: {
300
+ entity: fileEntity,
301
+ required: false,
302
+ },
182
303
  },
183
304
 
184
305
  outputs: serverOutputs,
package/src/restic.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { defineEntity, defineUnit, Type, type Static } from "@highstate/contract"
2
2
  import { l3EndpointEntity, l4EndpointEntity } from "./network"
3
3
 
4
- export const repoEntity = defineEntity({
5
- type: "restic.repo",
4
+ export const repositoryEntity = defineEntity({
5
+ type: "restic.repository",
6
6
 
7
7
  schema: Type.Object({
8
8
  remoteEndpoints: Type.Array(Type.Union([l3EndpointEntity.schema, l4EndpointEntity.schema])),
@@ -34,8 +34,6 @@ export const repo = defineUnit({
34
34
  * - `$unitName`: The name of the unit, which deploys the application, provided by the user.
35
35
  *
36
36
  * By default, the path pattern is `backups/$clusterName/$appName`.
37
- *
38
- * @schema
39
37
  */
40
38
  pathPattern: Type.Default(Type.String(), "backups/$clusterName/$appName"),
41
39
  },
@@ -58,7 +56,7 @@ export const repo = defineUnit({
58
56
  },
59
57
 
60
58
  outputs: {
61
- repo: repoEntity,
59
+ repo: repositoryEntity,
62
60
  },
63
61
 
64
62
  meta: {
@@ -75,4 +73,4 @@ export const repo = defineUnit({
75
73
  },
76
74
  })
77
75
 
78
- export type Repo = Static<typeof repoEntity.schema>
76
+ export type Repository = Static<typeof repositoryEntity.schema>
package/src/sops.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { defineUnit, Type } from "@highstate/contract"
2
- import { fileEntity, serverEntity } from "./common"
2
+ import { fileEntity } from "./files"
3
+ import { serverEntity } from "./common"
3
4
 
4
5
  export const secrets = defineUnit({
5
6
  type: "sops.secrets",
6
7
 
7
- args: {
8
- secrets: Type.Record(Type.String(), Type.Any()),
8
+ secrets: {
9
+ data: Type.Record(Type.String(), Type.Any()),
9
10
  },
10
11
 
11
12
  inputs: {
package/src/ssh.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineEntity, defineUnit, Type, type Static } from "@highstate/contract"
2
2
  import { l4EndpointEntity } from "./network"
3
+ import { fileEntity } from "./files"
3
4
 
4
5
  export const keyTypeSchema = Type.StringEnum(["ed25519"])
5
6
 
@@ -35,6 +36,7 @@ export const keyPair = defineUnit({
35
36
 
36
37
  outputs: {
37
38
  keyPair: keyPairEntity,
39
+ publicKeyFile: fileEntity,
38
40
  },
39
41
 
40
42
  meta: {