@oussema_mili/test-pkg-123 1.1.32

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 (49) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +220 -0
  3. package/auth-callback.html +97 -0
  4. package/auth.js +276 -0
  5. package/cli-commands.js +1921 -0
  6. package/containerManager.js +304 -0
  7. package/daemon/agentRunner.js +491 -0
  8. package/daemon/daemonEntry.js +64 -0
  9. package/daemon/daemonManager.js +266 -0
  10. package/daemon/logManager.js +227 -0
  11. package/dist/styles.css +504 -0
  12. package/docker-actions/apps.js +3913 -0
  13. package/docker-actions/config-transformer.js +380 -0
  14. package/docker-actions/containers.js +355 -0
  15. package/docker-actions/general.js +171 -0
  16. package/docker-actions/images.js +1128 -0
  17. package/docker-actions/logs.js +224 -0
  18. package/docker-actions/metrics.js +270 -0
  19. package/docker-actions/registry.js +1100 -0
  20. package/docker-actions/setup-tasks.js +859 -0
  21. package/docker-actions/terminal.js +247 -0
  22. package/docker-actions/volumes.js +713 -0
  23. package/helper-functions.js +193 -0
  24. package/index.html +83 -0
  25. package/index.js +341 -0
  26. package/package.json +82 -0
  27. package/postcss.config.mjs +5 -0
  28. package/scripts/release.sh +212 -0
  29. package/setup/setupWizard.js +403 -0
  30. package/store/agentSessionStore.js +51 -0
  31. package/store/agentStore.js +113 -0
  32. package/store/configStore.js +171 -0
  33. package/store/daemonStore.js +217 -0
  34. package/store/deviceCredentialStore.js +107 -0
  35. package/store/npmTokenStore.js +65 -0
  36. package/store/registryStore.js +329 -0
  37. package/store/setupState.js +147 -0
  38. package/styles.css +1 -0
  39. package/utils/appLogger.js +223 -0
  40. package/utils/deviceInfo.js +98 -0
  41. package/utils/ecrAuth.js +225 -0
  42. package/utils/encryption.js +112 -0
  43. package/utils/envSetup.js +41 -0
  44. package/utils/errorHandler.js +327 -0
  45. package/utils/portUtils.js +59 -0
  46. package/utils/prerequisites.js +323 -0
  47. package/utils/prompts.js +318 -0
  48. package/utils/ssl-certificates.js +256 -0
  49. package/websocket-server.js +415 -0
@@ -0,0 +1,380 @@
1
+ /**
2
+ * Configuration Transformer
3
+ *
4
+ * Transforms platform-agnostic deployment configuration into platform-specific formats.
5
+ * Supports Docker Compose and Helm transformations.
6
+ */
7
+
8
+ /**
9
+ * Transforms deployment config to Docker Compose format
10
+ * Splits environment variables by scope (container, host, secret)
11
+ *
12
+ * @param {Object} deploymentConfig - Universal deployment configuration
13
+ * @param {Array} deploymentConfig.environment - Environment variables with scopes
14
+ * @param {Object} deploymentConfig.resources - Resource limits (memory, cpu)
15
+ * @param {Object} deploymentConfig.scaling - Scaling config (replicas)
16
+ * @param {Object} deploymentConfig.volumes - Volume configurations
17
+ * @returns {Object} Docker Compose configuration with separated env vars
18
+ */
19
+ export function toDockerComposeConfig(deploymentConfig) {
20
+ if (!deploymentConfig) {
21
+ return {
22
+ containerEnv: {},
23
+ hostEnv: {},
24
+ secretRefs: {},
25
+ resources: null,
26
+ replicas: 1,
27
+ volumes: null,
28
+ };
29
+ }
30
+
31
+ const result = {
32
+ containerEnv: {},
33
+ hostEnv: {},
34
+ secretRefs: {},
35
+ resources: null,
36
+ replicas: 1,
37
+ volumes: null,
38
+ };
39
+
40
+ // Process environment variables by scope
41
+ if (
42
+ deploymentConfig.environment &&
43
+ Array.isArray(deploymentConfig.environment)
44
+ ) {
45
+ for (const envVar of deploymentConfig.environment) {
46
+ const { name, value, scope } = envVar;
47
+
48
+ // Skip invalid entries
49
+ if (!name || !value) continue;
50
+
51
+ switch (scope) {
52
+ case "container":
53
+ result.containerEnv[name] = value;
54
+ break;
55
+
56
+ case "host":
57
+ result.hostEnv[name] = value;
58
+ break;
59
+
60
+ case "secret":
61
+ // Store secret references (e.g., "${SECRET_NAME}")
62
+ // These will be resolved from host environment at runtime
63
+ result.secretRefs[name] = value;
64
+ // Also add to container env so docker-compose can interpolate
65
+ result.containerEnv[name] = value;
66
+ break;
67
+
68
+ default:
69
+ // Default to container scope
70
+ result.containerEnv[name] = value;
71
+ }
72
+ }
73
+ }
74
+
75
+ // Process resource limits
76
+ if (deploymentConfig.resources) {
77
+ result.resources = {
78
+ memory: deploymentConfig.resources.memory || null,
79
+ cpu: deploymentConfig.resources.cpu || null,
80
+ };
81
+ }
82
+
83
+ // Process scaling
84
+ if (deploymentConfig.scaling && deploymentConfig.scaling.replicas) {
85
+ result.replicas = deploymentConfig.scaling.replicas;
86
+ }
87
+
88
+ // Process volumes
89
+ if (deploymentConfig.volumes) {
90
+ result.volumes = deploymentConfig.volumes;
91
+ }
92
+
93
+ return result;
94
+ }
95
+
96
+ /**
97
+ * Generates a bash script to export host environment variables
98
+ *
99
+ * @param {Object} hostEnv - Key-value pairs of host environment variables
100
+ * @returns {string} Bash script content
101
+ */
102
+ export function generateHostEnvScript(hostEnv) {
103
+ if (!hostEnv || Object.keys(hostEnv).length === 0) {
104
+ return "#!/bin/bash\n# No host environment variables configured\n";
105
+ }
106
+
107
+ const lines = ["#!/bin/bash", "# Host environment variables", ""];
108
+
109
+ for (const [name, value] of Object.entries(hostEnv)) {
110
+ // Escape special characters in values
111
+ const escapedValue = value.replace(/"/g, '\\"').replace(/\$/g, "\\$");
112
+ lines.push(`export ${name}="${escapedValue}"`);
113
+ }
114
+
115
+ lines.push("");
116
+ return lines.join("\n");
117
+ }
118
+
119
+ /**
120
+ * Generates Docker Compose deploy section for resources and replicas
121
+ *
122
+ * @param {Object} resources - Resource limits {memory, cpu}
123
+ * @param {number} replicas - Number of replicas
124
+ * @returns {Object|null} Docker Compose deploy configuration
125
+ */
126
+ export function generateComposeDeploy(resources, replicas) {
127
+ const deploy = {};
128
+
129
+ // Add replicas
130
+ if (replicas && replicas > 1) {
131
+ deploy.replicas = replicas;
132
+ }
133
+
134
+ // Add resource limits
135
+ if (resources && (resources.memory || resources.cpu)) {
136
+ deploy.resources = {
137
+ limits: {},
138
+ reservations: {},
139
+ };
140
+
141
+ if (resources.memory) {
142
+ deploy.resources.limits.memory = resources.memory;
143
+ // Set reservations to 50% of limits
144
+ deploy.resources.reservations.memory = resources.memory;
145
+ }
146
+
147
+ if (resources.cpu) {
148
+ deploy.resources.limits.cpus = resources.cpu;
149
+ // Set reservations to 50% of limits
150
+ const cpuValue = parseFloat(resources.cpu);
151
+ if (!isNaN(cpuValue)) {
152
+ deploy.resources.reservations.cpus = (cpuValue * 0.5).toString();
153
+ }
154
+ }
155
+ }
156
+
157
+ return Object.keys(deploy).length > 0 ? deploy : null;
158
+ }
159
+
160
+ /**
161
+ * Generates .env file content for Docker Compose
162
+ * Includes both container and secret reference variables
163
+ *
164
+ * @param {Object} containerEnv - Container environment variables
165
+ * @param {Object} secretRefs - Secret reference variables
166
+ * @returns {string} .env file content
167
+ */
168
+ export function generateEnvFile(containerEnv, secretRefs) {
169
+ const lines = ["# Environment variables for Docker Compose", ""];
170
+
171
+ // Add container environment variables
172
+ if (containerEnv && Object.keys(containerEnv).length > 0) {
173
+ lines.push("# Container environment variables");
174
+ for (const [name, value] of Object.entries(containerEnv)) {
175
+ // Skip secret refs (they're added separately)
176
+ if (secretRefs && secretRefs[name]) continue;
177
+ lines.push(`${name}=${value}`);
178
+ }
179
+ lines.push("");
180
+ }
181
+
182
+ // Add secret references with comments
183
+ if (secretRefs && Object.keys(secretRefs).length > 0) {
184
+ lines.push("# Secret references (resolved from host environment)");
185
+ for (const [name, value] of Object.entries(secretRefs)) {
186
+ lines.push(`${name}=${value}`);
187
+ }
188
+ lines.push("");
189
+ }
190
+
191
+ return lines.join("\n");
192
+ }
193
+
194
+ /**
195
+ * Validates deployment configuration
196
+ *
197
+ * @param {Object} deploymentConfig - Universal deployment configuration
198
+ * @returns {Object} Validation result {valid: boolean, errors: string[]}
199
+ */
200
+ export function validateDeploymentConfig(deploymentConfig) {
201
+ const errors = [];
202
+
203
+ if (!deploymentConfig) {
204
+ return { valid: true, errors: [] }; // Config is optional
205
+ }
206
+
207
+ // Validate environment variables
208
+ if (deploymentConfig.environment) {
209
+ if (!Array.isArray(deploymentConfig.environment)) {
210
+ errors.push("environment must be an array");
211
+ } else {
212
+ deploymentConfig.environment.forEach((envVar, index) => {
213
+ if (!envVar.name) {
214
+ errors.push(`environment[${index}]: name is required`);
215
+ }
216
+ if (!envVar.value) {
217
+ errors.push(`environment[${index}]: value is required`);
218
+ }
219
+ if (
220
+ !envVar.scope ||
221
+ !["container", "host", "secret"].includes(envVar.scope)
222
+ ) {
223
+ errors.push(
224
+ `environment[${index}]: scope must be 'container', 'host', or 'secret'`
225
+ );
226
+ }
227
+ });
228
+ }
229
+ }
230
+
231
+ // Validate resources
232
+ if (deploymentConfig.resources) {
233
+ const { memory, cpu } = deploymentConfig.resources;
234
+
235
+ if (memory && typeof memory !== "string") {
236
+ errors.push('resources.memory must be a string (e.g., "512Mi", "1Gi")');
237
+ }
238
+
239
+ if (cpu && typeof cpu !== "string") {
240
+ errors.push('resources.cpu must be a string (e.g., "500m", "1")');
241
+ }
242
+ }
243
+
244
+ // Validate scaling
245
+ if (deploymentConfig.scaling) {
246
+ const { replicas } = deploymentConfig.scaling;
247
+
248
+ if (replicas !== undefined) {
249
+ if (typeof replicas !== "number" || replicas < 1) {
250
+ errors.push("scaling.replicas must be a number >= 1");
251
+ }
252
+ }
253
+ }
254
+
255
+ // Validate volumes
256
+ if (deploymentConfig.volumes) {
257
+ if (typeof deploymentConfig.volumes !== "object") {
258
+ errors.push("volumes must be an object");
259
+ }
260
+ }
261
+
262
+ return {
263
+ valid: errors.length === 0,
264
+ errors,
265
+ };
266
+ }
267
+
268
+ /**
269
+ * Transforms deployment config to Helm values format
270
+ * (For future Kubernetes deployments)
271
+ *
272
+ * @param {Object} deploymentConfig - Universal deployment configuration
273
+ * @returns {Object} Helm values object
274
+ */
275
+ export function toHelmValues(deploymentConfig) {
276
+ if (!deploymentConfig) {
277
+ return {};
278
+ }
279
+
280
+ const helmValues = {};
281
+
282
+ // Process environment variables
283
+ if (
284
+ deploymentConfig.environment &&
285
+ Array.isArray(deploymentConfig.environment)
286
+ ) {
287
+ helmValues.env = [];
288
+
289
+ for (const envVar of deploymentConfig.environment) {
290
+ const { name, value, scope } = envVar;
291
+
292
+ if (!name || !value) continue;
293
+
294
+ switch (scope) {
295
+ case "container":
296
+ // Direct environment variable
297
+ helmValues.env.push({
298
+ name,
299
+ value,
300
+ });
301
+ break;
302
+
303
+ case "secret":
304
+ // Secret reference - extract secret name and key
305
+ // Expected format: ${SECRET_NAME} or ${SECRET_NAME:KEY}
306
+ const secretMatch = value.match(/\$\{([^:}]+)(?::([^}]+))?\}/);
307
+ if (secretMatch) {
308
+ const secretName = secretMatch[1];
309
+ const secretKey = secretMatch[2] || name.toLowerCase();
310
+
311
+ helmValues.env.push({
312
+ name,
313
+ valueFrom: {
314
+ secretKeyRef: {
315
+ name: secretName,
316
+ key: secretKey,
317
+ },
318
+ },
319
+ });
320
+ } else {
321
+ // Invalid secret reference, treat as regular value
322
+ helmValues.env.push({ name, value });
323
+ }
324
+ break;
325
+
326
+ case "host":
327
+ // Host env vars don't apply to Kubernetes - skip or warn
328
+ console.warn(
329
+ `Host environment variable ${name} will not be included in Helm values`
330
+ );
331
+ break;
332
+
333
+ default:
334
+ helmValues.env.push({ name, value });
335
+ }
336
+ }
337
+ }
338
+
339
+ // Process resource limits
340
+ if (deploymentConfig.resources) {
341
+ helmValues.resources = {
342
+ limits: {},
343
+ requests: {},
344
+ };
345
+
346
+ if (deploymentConfig.resources.memory) {
347
+ helmValues.resources.limits.memory = deploymentConfig.resources.memory;
348
+ helmValues.resources.requests.memory = deploymentConfig.resources.memory;
349
+ }
350
+
351
+ if (deploymentConfig.resources.cpu) {
352
+ helmValues.resources.limits.cpu = deploymentConfig.resources.cpu;
353
+ // Request 50% of CPU limit
354
+ const cpuValue = parseFloat(deploymentConfig.resources.cpu);
355
+ if (!isNaN(cpuValue)) {
356
+ helmValues.resources.requests.cpu = (cpuValue * 0.5).toString();
357
+ }
358
+ }
359
+ }
360
+
361
+ // Process scaling
362
+ if (deploymentConfig.scaling && deploymentConfig.scaling.replicas) {
363
+ helmValues.replicaCount = deploymentConfig.scaling.replicas;
364
+ }
365
+
366
+ // Process volumes
367
+ if (deploymentConfig.volumes) {
368
+ helmValues.persistence = {};
369
+
370
+ for (const [name, size] of Object.entries(deploymentConfig.volumes)) {
371
+ helmValues.persistence[name] = {
372
+ enabled: true,
373
+ size,
374
+ accessMode: "ReadWriteOnce",
375
+ };
376
+ }
377
+ }
378
+
379
+ return helmValues;
380
+ }