@ebowwa/codespaces-types 0.1.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/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/index.d.ts +436 -0
- package/dist/index.js +96 -0
- package/dist/resources.d.ts +68 -0
- package/dist/resources.js +113 -0
- package/dist/schemas/resources.d.ts +165 -0
- package/dist/schemas/resources.js +123 -0
- package/dist/terminal-websocket.d.ts +108 -0
- package/dist/terminal-websocket.js +37 -0
- package/dist/time.d.ts +6 -0
- package/dist/time.js +27 -0
- package/dist/user/distributions.d.ts +14 -0
- package/dist/user/distributions.js +14 -0
- package/dist/validation.d.ts +43 -0
- package/dist/validation.js +80 -0
- package/package.json +68 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for environment names and other inputs
|
|
3
|
+
* Migrated to use Zod for runtime type safety and better error messages
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* Zod schema for environment name validation
|
|
8
|
+
* - Must start with a letter or number
|
|
9
|
+
* - Can contain letters, numbers, hyphens, and underscores
|
|
10
|
+
* - 1-64 characters long
|
|
11
|
+
* - Cannot be a reserved word
|
|
12
|
+
*/
|
|
13
|
+
export const EnvironmentNameSchema = z
|
|
14
|
+
.string()
|
|
15
|
+
.min(1, 'Environment name is required')
|
|
16
|
+
.max(64, 'Environment name must be 64 characters or less')
|
|
17
|
+
.regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/, 'Name must start with a letter or number and contain only letters, numbers, hyphens, and underscores')
|
|
18
|
+
.refine((name) => !['ssh', 'ssh-keys', 'docker', 'registry', 'volume', 'network'].includes(name.toLowerCase()), {
|
|
19
|
+
message: 'Name is a reserved word',
|
|
20
|
+
})
|
|
21
|
+
.transform((val) => val.trim());
|
|
22
|
+
/**
|
|
23
|
+
* Zod schema for SSH key name validation
|
|
24
|
+
*/
|
|
25
|
+
export const SSHKeyNameSchema = z
|
|
26
|
+
.string()
|
|
27
|
+
.min(1, 'SSH key name is required')
|
|
28
|
+
.max(64, 'Name must be 64 characters or less')
|
|
29
|
+
.transform((val) => val.trim());
|
|
30
|
+
/**
|
|
31
|
+
* Zod schema for Hetzner API token validation
|
|
32
|
+
*/
|
|
33
|
+
export const APITokenSchema = z
|
|
34
|
+
.string()
|
|
35
|
+
.min(1, 'API token is required')
|
|
36
|
+
.min(32, 'API token appears too short')
|
|
37
|
+
.startsWith('hetzner_', 'Hetzner API tokens typically start with "hetzner_"')
|
|
38
|
+
.transform((val) => val.trim());
|
|
39
|
+
/**
|
|
40
|
+
* Validates environment name according to Hetzner naming rules
|
|
41
|
+
* @deprecated Use EnvironmentNameSchema.safeParse() instead
|
|
42
|
+
*/
|
|
43
|
+
export function validateEnvironmentName(name) {
|
|
44
|
+
const result = EnvironmentNameSchema.safeParse(name);
|
|
45
|
+
if (result.success) {
|
|
46
|
+
return { isValid: true };
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
isValid: false,
|
|
50
|
+
error: result.error.issues.map((e) => e.message).join(', '),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates SSH key name
|
|
55
|
+
* @deprecated Use SSHKeyNameSchema.safeParse() instead
|
|
56
|
+
*/
|
|
57
|
+
export function validateSSHKeyName(name) {
|
|
58
|
+
const result = SSHKeyNameSchema.safeParse(name);
|
|
59
|
+
if (result.success) {
|
|
60
|
+
return { isValid: true };
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
isValid: false,
|
|
64
|
+
error: result.error.issues.map((e) => e.message).join(', '),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Validates Hetzner API token format
|
|
69
|
+
* @deprecated Use APITokenSchema.safeParse() instead
|
|
70
|
+
*/
|
|
71
|
+
export function validateAPIToken(token) {
|
|
72
|
+
const result = APITokenSchema.safeParse(token);
|
|
73
|
+
if (result.success) {
|
|
74
|
+
return { isValid: true };
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
isValid: false,
|
|
78
|
+
error: result.error.issues.map((e) => e.message).join(', '),
|
|
79
|
+
};
|
|
80
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ebowwa/codespaces-types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared TypeScript type definitions for Codespaces packages",
|
|
5
|
+
"author": "Ebowwa Labs <labs@ebowwa.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"homepage": "https://github.com/ebowwa/codespaces-types#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/ebowwa/codespaces-types.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ebowwa/codespaces-types/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"typescript",
|
|
18
|
+
"types",
|
|
19
|
+
"codespaces",
|
|
20
|
+
"shared"
|
|
21
|
+
],
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"typecheck": "tsc --noEmit"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"zod": "^3.24.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^22.10.2",
|
|
37
|
+
"typescript": "^5.7.2"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18.0.0"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"import": "./dist/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./resources": {
|
|
48
|
+
"types": "./dist/resources.d.ts",
|
|
49
|
+
"import": "./dist/resources.js"
|
|
50
|
+
},
|
|
51
|
+
"./terminal-websocket": {
|
|
52
|
+
"types": "./dist/terminal-websocket.d.ts",
|
|
53
|
+
"import": "./dist/terminal-websocket.js"
|
|
54
|
+
},
|
|
55
|
+
"./time": {
|
|
56
|
+
"types": "./dist/time.d.ts",
|
|
57
|
+
"import": "./dist/time.js"
|
|
58
|
+
},
|
|
59
|
+
"./validation": {
|
|
60
|
+
"types": "./dist/validation.d.ts",
|
|
61
|
+
"import": "./dist/validation.js"
|
|
62
|
+
},
|
|
63
|
+
"./schemas/resources": {
|
|
64
|
+
"types": "./dist/schemas/resources.d.ts",
|
|
65
|
+
"import": "./dist/schemas/resources.js"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|