@simplens/onboard 1.0.9 → 1.0.10
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/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/templates.d.ts +2 -2
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +4 -4
- package/package.json +5 -1
- package/src/__tests__/env-config.test.ts +0 -28
- package/src/__tests__/errors.test.ts +0 -188
- package/src/__tests__/infra-prompts.test.ts +0 -56
- package/src/__tests__/infra.test.ts +0 -30
- package/src/__tests__/utils.test.ts +0 -142
- package/src/__tests__/validators.test.ts +0 -221
- package/src/config/constants.ts +0 -87
- package/src/config/index.ts +0 -1
- package/src/env-config.ts +0 -503
- package/src/index.ts +0 -704
- package/src/infra.ts +0 -515
- package/src/plugins.ts +0 -221
- package/src/services.ts +0 -401
- package/src/templates.ts +0 -282
- package/src/types/domain.ts +0 -135
- package/src/types/errors.ts +0 -173
- package/src/types/index.ts +0 -2
- package/src/ui.ts +0 -91
- package/src/utils/index.ts +0 -1
- package/src/utils/logger.ts +0 -144
- package/src/utils.ts +0 -183
- package/src/validators.ts +0 -196
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -22
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
checkDockerInstalled,
|
|
4
|
-
checkDockerRunning,
|
|
5
|
-
detectOS,
|
|
6
|
-
validatePrerequisites,
|
|
7
|
-
validateEnvValue,
|
|
8
|
-
validatePublicDomain,
|
|
9
|
-
validateEmailAddress
|
|
10
|
-
} from '../validators.js';
|
|
11
|
-
import {
|
|
12
|
-
DockerNotInstalledError,
|
|
13
|
-
DockerNotRunningError,
|
|
14
|
-
DockerPermissionError
|
|
15
|
-
} from '../types/errors.js';
|
|
16
|
-
|
|
17
|
-
// Mock execa
|
|
18
|
-
vi.mock('execa', () => ({
|
|
19
|
-
execa: vi.fn(),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
// Mock utils
|
|
23
|
-
vi.mock('../utils.js', () => ({
|
|
24
|
-
logError: vi.fn(),
|
|
25
|
-
logSuccess: vi.fn(),
|
|
26
|
-
logWarning: vi.fn(),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
import { execa } from 'execa';
|
|
30
|
-
|
|
31
|
-
describe('validators', () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
vi.clearAllMocks();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('checkDockerInstalled', () => {
|
|
37
|
-
it('should not throw when docker is installed', async () => {
|
|
38
|
-
vi.mocked(execa).mockResolvedValueOnce({
|
|
39
|
-
stdout: 'Docker version 24.0.0',
|
|
40
|
-
stderr: '',
|
|
41
|
-
} as any);
|
|
42
|
-
|
|
43
|
-
await expect(checkDockerInstalled()).resolves.not.toThrow();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should throw DockerNotInstalledError when docker is not installed', async () => {
|
|
47
|
-
vi.mocked(execa).mockRejectedValueOnce(new Error('Command not found'));
|
|
48
|
-
|
|
49
|
-
await expect(checkDockerInstalled()).rejects.toThrow(DockerNotInstalledError);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('checkDockerRunning', () => {
|
|
54
|
-
it('should not throw when docker daemon is running', async () => {
|
|
55
|
-
vi.mocked(execa).mockResolvedValueOnce({
|
|
56
|
-
stdout: 'CONTAINER ID IMAGE',
|
|
57
|
-
stderr: '',
|
|
58
|
-
} as any);
|
|
59
|
-
|
|
60
|
-
await expect(checkDockerRunning()).resolves.not.toThrow();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should throw DockerPermissionError on permission denied', async () => {
|
|
64
|
-
const error = new Error('permission denied while trying to connect');
|
|
65
|
-
vi.mocked(execa).mockRejectedValueOnce(error);
|
|
66
|
-
|
|
67
|
-
await expect(checkDockerRunning()).rejects.toThrow(DockerPermissionError);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should throw DockerNotRunningError when daemon is not running', async () => {
|
|
71
|
-
const error = new Error('Cannot connect to the Docker daemon');
|
|
72
|
-
vi.mocked(execa).mockRejectedValueOnce(error);
|
|
73
|
-
|
|
74
|
-
await expect(checkDockerRunning()).rejects.toThrow(DockerNotRunningError);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should throw DockerNotRunningError on generic docker error', async () => {
|
|
78
|
-
const error = new Error('Some other docker error');
|
|
79
|
-
vi.mocked(execa).mockRejectedValueOnce(error);
|
|
80
|
-
|
|
81
|
-
await expect(checkDockerRunning()).rejects.toThrow(DockerNotRunningError);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('detectOS', () => {
|
|
86
|
-
const originalPlatform = process.platform;
|
|
87
|
-
|
|
88
|
-
afterEach(() => {
|
|
89
|
-
Object.defineProperty(process, 'platform', {
|
|
90
|
-
value: originalPlatform
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should detect Windows', () => {
|
|
95
|
-
Object.defineProperty(process, 'platform', {
|
|
96
|
-
value: 'win32'
|
|
97
|
-
});
|
|
98
|
-
expect(detectOS()).toBe('windows');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should detect macOS', () => {
|
|
102
|
-
Object.defineProperty(process, 'platform', {
|
|
103
|
-
value: 'darwin'
|
|
104
|
-
});
|
|
105
|
-
expect(detectOS()).toBe('darwin');
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should detect Linux', () => {
|
|
109
|
-
Object.defineProperty(process, 'platform', {
|
|
110
|
-
value: 'linux'
|
|
111
|
-
});
|
|
112
|
-
expect(detectOS()).toBe('linux');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should default to Linux for unknown platforms', () => {
|
|
116
|
-
Object.defineProperty(process, 'platform', {
|
|
117
|
-
value: 'freebsd'
|
|
118
|
-
});
|
|
119
|
-
expect(detectOS()).toBe('linux');
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('validateEnvValue', () => {
|
|
124
|
-
describe('URL validation', () => {
|
|
125
|
-
it('should reject empty MongoDB URI', () => {
|
|
126
|
-
expect(validateEnvValue('MONGO_URI', '')).toBe(false);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should reject MongoDB URI without proper format', () => {
|
|
130
|
-
expect(validateEnvValue('MONGO_URI', 'localhost:27017')).toBe(false);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should accept valid MongoDB URI', () => {
|
|
134
|
-
expect(validateEnvValue('MONGO_URI', 'mongodb://localhost:27017')).toBe(true);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('should reject Redis URL without proper format', () => {
|
|
138
|
-
expect(validateEnvValue('REDIS_URL', 'localhost:6379')).toBe(false);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should accept valid Redis URL', () => {
|
|
142
|
-
expect(validateEnvValue('REDIS_URL', 'redis://localhost:6379')).toBe(true);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('Port validation', () => {
|
|
147
|
-
it('should reject negative ports', () => {
|
|
148
|
-
expect(validateEnvValue('PORT', '-1')).toBe(false);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('should reject zero port', () => {
|
|
152
|
-
expect(validateEnvValue('PORT', '0')).toBe(false);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should reject ports > 65535', () => {
|
|
156
|
-
expect(validateEnvValue('PORT', '65536')).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should accept valid ports', () => {
|
|
160
|
-
expect(validateEnvValue('PORT', '3000')).toBe(true);
|
|
161
|
-
expect(validateEnvValue('API_PORT', '8080')).toBe(true);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should reject non-numeric ports', () => {
|
|
165
|
-
expect(validateEnvValue('PORT', 'abc')).toBe(false);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('Security fields validation', () => {
|
|
170
|
-
it('should reject short API keys', () => {
|
|
171
|
-
expect(validateEnvValue('API_KEY', 'short')).toBe(false);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should reject short passwords', () => {
|
|
175
|
-
expect(validateEnvValue('PASSWORD', '1234567')).toBe(false);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('should reject short secrets', () => {
|
|
179
|
-
expect(validateEnvValue('AUTH_SECRET', 'abc')).toBe(false);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('should accept API keys with 8+ characters', () => {
|
|
183
|
-
expect(validateEnvValue('API_KEY', 'verylongapikey123')).toBe(true);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should accept passwords with 8+ characters', () => {
|
|
187
|
-
expect(validateEnvValue('PASSWORD', 'password123')).toBe(true);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe('General validation', () => {
|
|
192
|
-
it('should accept valid non-special values', () => {
|
|
193
|
-
expect(validateEnvValue('SOME_VAR', 'some-value')).toBe(true);
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('validatePublicDomain', () => {
|
|
199
|
-
it('accepts valid public domains', () => {
|
|
200
|
-
expect(validatePublicDomain('example.com')).toBe(true);
|
|
201
|
-
expect(validatePublicDomain('app.example.com')).toBe(true);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('rejects urls or malformed values', () => {
|
|
205
|
-
expect(validatePublicDomain('https://example.com')).not.toBe(true);
|
|
206
|
-
expect(validatePublicDomain('example')).not.toBe(true);
|
|
207
|
-
expect(validatePublicDomain('example.com/path')).not.toBe(true);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
describe('validateEmailAddress', () => {
|
|
212
|
-
it('accepts valid email addresses', () => {
|
|
213
|
-
expect(validateEmailAddress('admin@example.com')).toBe(true);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('rejects invalid email values', () => {
|
|
217
|
-
expect(validateEmailAddress('admin@')).not.toBe(true);
|
|
218
|
-
expect(validateEmailAddress('not-an-email')).not.toBe(true);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|
package/src/config/constants.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Application configuration constants
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Service port mappings
|
|
7
|
-
*/
|
|
8
|
-
export const SERVICE_PORTS = {
|
|
9
|
-
API: 3000,
|
|
10
|
-
DASHBOARD: 3002,
|
|
11
|
-
GRAFANA: 3001,
|
|
12
|
-
KAFKA_UI: 8080,
|
|
13
|
-
MONGO: 27017,
|
|
14
|
-
KAFKA: 9092,
|
|
15
|
-
REDIS: 6379,
|
|
16
|
-
LOKI: 3100,
|
|
17
|
-
} as const;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Health check configuration
|
|
21
|
-
*/
|
|
22
|
-
export const HEALTH_CHECK = {
|
|
23
|
-
MAX_RETRIES: 30,
|
|
24
|
-
RETRY_DELAY_MS: 2000,
|
|
25
|
-
TIMEOUT_MS: 60000,
|
|
26
|
-
} as const;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Docker command timeouts
|
|
30
|
-
*/
|
|
31
|
-
export const DOCKER_TIMEOUTS = {
|
|
32
|
-
START_MS: 30000,
|
|
33
|
-
STOP_MS: 15000,
|
|
34
|
-
BUILD_MS: 300000,
|
|
35
|
-
} as const;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Critical environment variables that always need user input
|
|
39
|
-
*/
|
|
40
|
-
export const CRITICAL_ENV_KEYS = [
|
|
41
|
-
'NS_API_KEY',
|
|
42
|
-
'MONGO_URI',
|
|
43
|
-
'BROKERS',
|
|
44
|
-
'REDIS_URL',
|
|
45
|
-
'AUTH_SECRET',
|
|
46
|
-
'ADMIN_PASSWORD',
|
|
47
|
-
'CORE_VERSION',
|
|
48
|
-
'DASHBOARD_VERSION',
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Validation constraints
|
|
53
|
-
*/
|
|
54
|
-
export const VALIDATION = {
|
|
55
|
-
MIN_PASSWORD_LENGTH: 8,
|
|
56
|
-
MIN_API_KEY_LENGTH: 8,
|
|
57
|
-
PORT_MIN: 1,
|
|
58
|
-
PORT_MAX: 65535,
|
|
59
|
-
} as const;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* File paths
|
|
63
|
-
*/
|
|
64
|
-
export const FILES = {
|
|
65
|
-
DOCKER_COMPOSE_INFRA: 'docker-compose.infra.yaml',
|
|
66
|
-
DOCKER_COMPOSE_APP: 'docker-compose.yaml',
|
|
67
|
-
ENV_FILE: '.env',
|
|
68
|
-
CONFIG_FILE: 'simplens.config.yaml',
|
|
69
|
-
ERROR_LOG: 'onboard-error.log',
|
|
70
|
-
} as const;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* URL templates for service access
|
|
74
|
-
*/
|
|
75
|
-
export function getServiceURL(service: keyof typeof SERVICE_PORTS, host: string = 'localhost'): string {
|
|
76
|
-
return `http://${host}:${SERVICE_PORTS[service]}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Docker compose file paths
|
|
81
|
-
*/
|
|
82
|
-
export const DOCKER_COMPOSE_COMMANDS = {
|
|
83
|
-
UP: ['up', '-d'],
|
|
84
|
-
DOWN: ['down'],
|
|
85
|
-
LOGS: ['logs', '-f'],
|
|
86
|
-
PS: ['ps'],
|
|
87
|
-
} as const;
|
package/src/config/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './constants.js';
|