@highstate/library 0.14.2 → 0.16.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 (44) hide show
  1. package/dist/highstate.library.msgpack +0 -0
  2. package/dist/index.js +1721 -953
  3. package/dist/index.js.map +1 -1
  4. package/package.json +3 -3
  5. package/src/abbreviations.ts +1 -0
  6. package/src/common/access-point.ts +2 -2
  7. package/src/common/files.ts +10 -0
  8. package/src/common/server.ts +15 -57
  9. package/src/databases/etcd.ts +97 -0
  10. package/src/databases/index.ts +1 -0
  11. package/src/databases/mariadb.ts +48 -2
  12. package/src/databases/mongodb.ts +48 -2
  13. package/src/databases/postgresql.ts +51 -2
  14. package/src/databases/redis.ts +48 -2
  15. package/src/databases/s3.ts +65 -6
  16. package/src/databases/shared.ts +12 -6
  17. package/src/dns.ts +59 -49
  18. package/src/k8s/apps/etcd.ts +46 -0
  19. package/src/k8s/apps/index.ts +2 -0
  20. package/src/k8s/apps/mariadb.ts +0 -5
  21. package/src/k8s/apps/minio.ts +0 -5
  22. package/src/k8s/apps/mongodb.ts +0 -5
  23. package/src/k8s/apps/postgresql.ts +0 -5
  24. package/src/k8s/apps/shared.ts +10 -1
  25. package/src/k8s/apps/traefik.ts +16 -1
  26. package/src/k8s/apps/valkey.ts +0 -5
  27. package/src/k8s/apps/wg-feed-server.ts +34 -0
  28. package/src/k8s/reduced-access.ts +23 -53
  29. package/src/k8s/resources.ts +78 -35
  30. package/src/k8s/service.ts +21 -10
  31. package/src/k8s/shared.ts +60 -90
  32. package/src/k8s/workload.ts +87 -26
  33. package/src/network/address-space.ts +94 -0
  34. package/src/network/address.ts +33 -0
  35. package/src/network/dynamic-endpoint.ts +39 -0
  36. package/src/network/endpoint-schema.ts +116 -0
  37. package/src/network/endpoint.ts +347 -0
  38. package/src/network/index.ts +6 -0
  39. package/src/network/subnet.ts +31 -0
  40. package/src/ssh.ts +66 -10
  41. package/src/third-party/cloudflare.ts +1 -0
  42. package/src/utils.ts +41 -11
  43. package/src/wireguard.ts +340 -150
  44. package/src/network.ts +0 -391
package/src/network.ts DELETED
@@ -1,391 +0,0 @@
1
- import type { Simplify } from "type-fest"
2
- import { defineEntity, defineUnit, z } from "@highstate/contract"
3
-
4
- export const endpointVisibilitySchema = z.enum([
5
- "public", // reachable from the public internet
6
- "external", // reachable from outside the system boundary, but not public
7
- "internal", // reachable only from within the system or cluster
8
- ])
9
-
10
- export const endpointFilterSchema = endpointVisibilitySchema.array()
11
-
12
- /**
13
- * The L3 endpoint for some service.
14
- *
15
- * May be a domain name or an IP address.
16
- */
17
- export const l3EndpointEntity = defineEntity({
18
- type: "network.l3-endpoint.v1",
19
-
20
- schema: z.intersection(
21
- z.object({
22
- /**
23
- * The generic visibility of an endpoint.
24
- *
25
- * - `public`: reachable from the public internet;
26
- * - `external`: reachable from outside the system boundary (e.g., LAN, VPC), but not public;
27
- * - `internal`: reachable only from within the application or infrastructure boundary (e.g., within a cluster).
28
- */
29
- visibility: endpointVisibilitySchema,
30
-
31
- /**
32
- * The extra metadata for the endpoint.
33
- *
34
- * In most cases, this is provided by the endpoint origin (e.g., a Kubernetes service).
35
- */
36
- metadata: z.record(z.string(), z.unknown()).optional(),
37
- }),
38
- z.union([
39
- z.object({
40
- type: z.literal("hostname"),
41
-
42
- /**
43
- * The hostname of the endpoint in the format of a domain name.
44
- */
45
- hostname: z.string(),
46
- }),
47
- z.object({
48
- type: z.literal("ipv4"),
49
-
50
- /**
51
- * The IPv4 address of the endpoint.
52
- */
53
- address: z.string(),
54
- }),
55
- z.object({
56
- type: z.literal("ipv6"),
57
-
58
- /**
59
- * The IPv6 address of the endpoint.
60
- */
61
- address: z.string(),
62
- }),
63
- ]),
64
- ),
65
-
66
- meta: {
67
- color: "#4CAF50",
68
- },
69
- })
70
-
71
- export const l4ProtocolSchema = z.enum(["tcp", "udp"])
72
-
73
- /**
74
- * The schema for a TCP/UDP port.
75
- */
76
- export const portSchema = z.number().int().min(1).max(65535)
77
-
78
- /**
79
- * The schema for an IPv4 prefix length.
80
- */
81
- export const ipv4PrefixSchema = z.number().int().min(0).max(32)
82
-
83
- /**
84
- * The schema for address that can be either IPv4 or IPv6.
85
- */
86
- export const ipv46Schema = z.union([z.ipv4(), z.ipv6()])
87
-
88
- export const l4PortInfoSchema = z.object({
89
- port: portSchema,
90
- protocol: l4ProtocolSchema,
91
- })
92
-
93
- /**
94
- * The L4 endpoint for some service.
95
- *
96
- * Extends an L3 endpoint with a port and protocol.
97
- */
98
- export const l4EndpointEntity = defineEntity({
99
- type: "network.l4-endpoint.v1",
100
-
101
- schema: z.intersection(l3EndpointEntity.schema, l4PortInfoSchema),
102
-
103
- meta: {
104
- color: "#2196F3",
105
- },
106
- })
107
-
108
- export const l7AppInfoSchema = z.object({
109
- /**
110
- * The name of the application protocol used by the endpoint.
111
- */
112
- appProtocol: z.string(),
113
-
114
- /**
115
- * The resource path of the application endpoint, including query parameters.
116
- * Must not start with a slash (`/`).
117
- *
118
- * Example: `api/v1/resource?query=value`, `database?param=value`, `user/repo.git`.
119
- */
120
- resource: z.string().optional(),
121
- })
122
-
123
- /**
124
- * The L7 endpoint for some service.
125
- *
126
- * Extends an L4 endpoint with application protocol information.
127
- */
128
- export const l7EndpointEntity = defineEntity({
129
- type: "network.l7-endpoint.v1",
130
-
131
- schema: z.intersection(l4EndpointEntity.schema, l7AppInfoSchema),
132
-
133
- meta: {
134
- color: "#FF9800",
135
- },
136
- })
137
-
138
- /**
139
- * The component which creates an L3 endpoint.
140
- */
141
- export const l3Endpoint = defineUnit({
142
- type: "network.l3-endpoint.v1",
143
-
144
- args: {
145
- /**
146
- * The string representation of the endpoint.
147
- *
148
- * May be a domain name or an IP address.
149
- */
150
- endpoint: z.string(),
151
-
152
- /**
153
- * The visibility of the endpoint.
154
- *
155
- * The visibility levels are:
156
- * - `public`: reachable from the public internet;
157
- * - `external`: reachable from outside the system boundary (e.g., LAN, VPC), but not public;
158
- * - `internal`: reachable only from within the application or infrastructure boundary (e.g., within a cluster).
159
- *
160
- * If not specified, defaults to `public`.
161
- */
162
- visibility: endpointVisibilitySchema.default("public"),
163
- },
164
-
165
- outputs: {
166
- endpoint: l3EndpointEntity,
167
- },
168
-
169
- meta: {
170
- title: "L3 Endpoint",
171
- icon: "mdi:network-outline",
172
- iconColor: "#4CAF50",
173
- defaultNamePrefix: "endpoint",
174
- category: "Network",
175
- },
176
-
177
- source: {
178
- package: "@highstate/common",
179
- path: "units/network/l3-endpoint",
180
- },
181
- })
182
-
183
- /**
184
- * The component which creates an L4 endpoint.
185
- */
186
- export const l4Endpoint = defineUnit({
187
- type: "network.l4-endpoint.v1",
188
-
189
- args: {
190
- /**
191
- * The string representation of the endpoint.
192
- *
193
- * May be a domain name or an IP address + port/protocol.
194
- *
195
- * The possible formats are:
196
- *
197
- * - `endpoint:port` (TCP by default)
198
- * - `tcp://endpoint:port`
199
- * - `udp://endpoint:port`
200
- */
201
- endpoint: z.string(),
202
-
203
- /**
204
- * The visibility of the endpoint.
205
- *
206
- * The visibility levels are:
207
- * - `public`: reachable from the public internet;
208
- * - `external`: reachable from outside the system boundary (e.g., LAN, VPC), but not public;
209
- * - `internal`: reachable only from within the application or infrastructure boundary (e.g., within a cluster).
210
- *
211
- * If not specified, defaults to `public`.
212
- */
213
- visibility: endpointVisibilitySchema.default("public"),
214
- },
215
-
216
- outputs: {
217
- endpoint: l4EndpointEntity,
218
- },
219
-
220
- meta: {
221
- title: "L4 Endpoint",
222
- icon: "mdi:network-outline",
223
- iconColor: "#2196F3",
224
- defaultNamePrefix: "endpoint",
225
- category: "Network",
226
- },
227
-
228
- source: {
229
- package: "@highstate/common",
230
- path: "units/network/l4-endpoint",
231
- },
232
- })
233
-
234
- /**
235
- * The component which creates an L7 endpoint.
236
- */
237
- export const l7Endpoint = defineUnit({
238
- type: "network.l7-endpoint.v1",
239
-
240
- args: {
241
- /**
242
- * The string representation of the endpoint.
243
- *
244
- * The possible formats are:
245
- *
246
- * - `https://endpoint:port/resource`
247
- * - `ftp://endpoint:port/resource`
248
- * - `someotherprotocol://endpoint:port/resource`
249
- */
250
- endpoint: z.string(),
251
-
252
- /**
253
- * The visibility of the endpoint.
254
- *
255
- * The visibility levels are:
256
- * - `public`: reachable from the public internet;
257
- * - `external`: reachable from outside the system boundary (e.g., LAN, VPC), but not public;
258
- * - `internal`: reachable only from within the application or infrastructure boundary (e.g., within a cluster).
259
- *
260
- * If not specified, defaults to `public`.
261
- */
262
- visibility: endpointVisibilitySchema.default("public"),
263
- },
264
-
265
- outputs: {
266
- endpoint: l7EndpointEntity,
267
- },
268
-
269
- meta: {
270
- title: "L7 Endpoint",
271
- icon: "mdi:network-outline",
272
- iconColor: "#FF9800",
273
- defaultNamePrefix: "endpoint",
274
- category: "Network",
275
- },
276
-
277
- source: {
278
- package: "@highstate/common",
279
- path: "units/network/l7-endpoint",
280
- },
281
- })
282
-
283
- /**
284
- * Explicitly filter endpoints by their accessibility.
285
- */
286
- export const endpointFilter = defineUnit({
287
- type: "network.endpoint-filter.v1",
288
-
289
- args: {
290
- /**
291
- * The endpoint filter to filter the endpoints before creating the DNS records.
292
- *
293
- * Possible values:
294
- *
295
- * - `public`: only endpoints exposed to the public internet;
296
- * - `external`: reachable from outside the system but not public (e.g., LAN, VPC);
297
- * - `internal`: reachable only from within the system boundary (e.g., inside a cluster).
298
- *
299
- * You can select one or more values.
300
- *
301
- * If no value is provided, the endpoints will be filtered by the most accessible type:
302
- *
303
- * - if any public endpoints exist, all public endpoints are selected;
304
- * - otherwise, if any external endpoints exist, all external endpoints are selected;
305
- * - if neither exist, all internal endpoints are selected.
306
- */
307
- endpointFilter: endpointFilterSchema.default([]),
308
- },
309
-
310
- inputs: {
311
- l3Endpoints: {
312
- entity: l3EndpointEntity,
313
- multiple: true,
314
- required: false,
315
- },
316
- l4Endpoints: {
317
- entity: l4EndpointEntity,
318
- multiple: true,
319
- required: false,
320
- },
321
- },
322
-
323
- outputs: {
324
- l3Endpoints: {
325
- entity: l3EndpointEntity,
326
- multiple: true,
327
- },
328
- l4Endpoints: {
329
- entity: l4EndpointEntity,
330
- multiple: true,
331
- },
332
- },
333
-
334
- meta: {
335
- title: "Endpoint Filter",
336
- icon: "mdi:network-outline",
337
- iconColor: "#FF9800",
338
- secondaryIcon: "mdi:filter-outline",
339
- category: "Network",
340
- },
341
-
342
- source: {
343
- package: "@highstate/common",
344
- path: "units/network/endpoint-filter",
345
- },
346
- })
347
-
348
- /**
349
- * The generic visibility of an endpoint.
350
- *
351
- * - `public`: reachable from the public internet;
352
- * - `external`: reachable from outside the system boundary (e.g., LAN, VPC), but not public;
353
- * - `internal`: reachable only from within the application or infrastructure boundary (e.g., within a cluster).
354
- */
355
- export type EndpointVisibility = z.infer<typeof endpointVisibilitySchema>
356
-
357
- /**
358
- * The list of endpoint visibility levels used to filter endpoints.
359
- *
360
- * If empty, it will filter the most widely accessible endpoints, prefering visibility in the following order:
361
- * - If any public endpoints exist, all public endpoints are selected.
362
- * - Otherwise, if any external endpoints exist, all external endpoints are selected.
363
- * - If neither exist, all internal endpoints are selected.
364
- */
365
- export type EndpointFilter = z.infer<typeof endpointFilterSchema>
366
-
367
- export type L3Endpoint = Simplify<z.infer<typeof l3EndpointEntity.schema>>
368
- export type L4Endpoint = Simplify<z.infer<typeof l4EndpointEntity.schema>>
369
- export type L4Protocol = z.infer<typeof l4ProtocolSchema>
370
- export type L4PortInfo = z.infer<typeof l4PortInfoSchema>
371
- export type L7Endpoint = Simplify<z.infer<typeof l7EndpointEntity.schema>>
372
- export type L7AppInfo = z.infer<typeof l7AppInfoSchema>
373
-
374
- export const l34EndpointSchema = z.union([
375
- z.intersection(
376
- l3EndpointEntity.schema,
377
- z.object({
378
- port: z.undefined().optional(),
379
- protocol: z.undefined().optional(),
380
- }),
381
- ),
382
- l4EndpointEntity.schema,
383
- ])
384
-
385
- /**
386
- * The L3 or L4 endpoint for some service.
387
- *
388
- * For convenience, L3 case have `port` and `protocol` fields as `undefined`,
389
- * so you can check any of them to determine if it's an L3 or L4 endpoint.
390
- */
391
- export type L34Endpoint = Simplify<z.infer<typeof l34EndpointSchema>>