@geekmidas/cli 0.13.0 → 0.14.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 (79) hide show
  1. package/dist/{bundler-B1qy9b-j.cjs → bundler-BjholBlA.cjs} +26 -7
  2. package/dist/bundler-BjholBlA.cjs.map +1 -0
  3. package/dist/{bundler-DskIqW2t.mjs → bundler-DWctKN1z.mjs} +27 -8
  4. package/dist/bundler-DWctKN1z.mjs.map +1 -0
  5. package/dist/config.d.cts +1 -1
  6. package/dist/config.d.mts +1 -1
  7. package/dist/dokploy-api-B7KxOQr3.cjs +3 -0
  8. package/dist/dokploy-api-C7F9VykY.cjs +317 -0
  9. package/dist/dokploy-api-C7F9VykY.cjs.map +1 -0
  10. package/dist/dokploy-api-CaETb2L6.mjs +305 -0
  11. package/dist/dokploy-api-CaETb2L6.mjs.map +1 -0
  12. package/dist/dokploy-api-DHvfmWbi.mjs +3 -0
  13. package/dist/{encryption-Dyf_r1h-.cjs → encryption-D7Efcdi9.cjs} +1 -1
  14. package/dist/{encryption-Dyf_r1h-.cjs.map → encryption-D7Efcdi9.cjs.map} +1 -1
  15. package/dist/{encryption-C8H-38Yy.mjs → encryption-h4Nb6W-M.mjs} +1 -1
  16. package/dist/{encryption-C8H-38Yy.mjs.map → encryption-h4Nb6W-M.mjs.map} +1 -1
  17. package/dist/index.cjs +1513 -1136
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.mjs +1513 -1136
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/{openapi-Bt_1FDpT.cjs → openapi-C89hhkZC.cjs} +3 -3
  22. package/dist/{openapi-Bt_1FDpT.cjs.map → openapi-C89hhkZC.cjs.map} +1 -1
  23. package/dist/{openapi-BfFlOBCG.mjs → openapi-CZVcfxk-.mjs} +3 -3
  24. package/dist/{openapi-BfFlOBCG.mjs.map → openapi-CZVcfxk-.mjs.map} +1 -1
  25. package/dist/{openapi-react-query-B6XTeGqS.mjs → openapi-react-query-CM2_qlW9.mjs} +1 -1
  26. package/dist/{openapi-react-query-B6XTeGqS.mjs.map → openapi-react-query-CM2_qlW9.mjs.map} +1 -1
  27. package/dist/{openapi-react-query-B-sNWHFU.cjs → openapi-react-query-iKjfLzff.cjs} +1 -1
  28. package/dist/{openapi-react-query-B-sNWHFU.cjs.map → openapi-react-query-iKjfLzff.cjs.map} +1 -1
  29. package/dist/openapi-react-query.cjs +1 -1
  30. package/dist/openapi-react-query.mjs +1 -1
  31. package/dist/openapi.cjs +1 -1
  32. package/dist/openapi.d.cts +1 -1
  33. package/dist/openapi.d.mts +1 -1
  34. package/dist/openapi.mjs +1 -1
  35. package/dist/{storage-kSxTjkNb.mjs → storage-BaOP55oq.mjs} +16 -2
  36. package/dist/storage-BaOP55oq.mjs.map +1 -0
  37. package/dist/{storage-Bj1E26lU.cjs → storage-Bn3K9Ccu.cjs} +21 -1
  38. package/dist/storage-Bn3K9Ccu.cjs.map +1 -0
  39. package/dist/storage-UfyTn7Zm.cjs +7 -0
  40. package/dist/storage-nkGIjeXt.mjs +3 -0
  41. package/dist/{types-BhkZc-vm.d.cts → types-BgaMXsUa.d.cts} +3 -1
  42. package/dist/{types-BR0M2v_c.d.mts.map → types-BgaMXsUa.d.cts.map} +1 -1
  43. package/dist/{types-BR0M2v_c.d.mts → types-iFk5ms7y.d.mts} +3 -1
  44. package/dist/{types-BhkZc-vm.d.cts.map → types-iFk5ms7y.d.mts.map} +1 -1
  45. package/package.json +3 -3
  46. package/src/auth/__tests__/credentials.spec.ts +127 -0
  47. package/src/auth/__tests__/index.spec.ts +69 -0
  48. package/src/auth/credentials.ts +33 -0
  49. package/src/auth/index.ts +57 -50
  50. package/src/build/__tests__/bundler.spec.ts +1 -1
  51. package/src/build/__tests__/endpoint-analyzer.spec.ts +623 -0
  52. package/src/build/__tests__/handler-templates.spec.ts +272 -0
  53. package/src/build/bundler.ts +53 -4
  54. package/src/build/index.ts +21 -0
  55. package/src/build/types.ts +6 -0
  56. package/src/deploy/__tests__/dokploy-api.spec.ts +698 -0
  57. package/src/deploy/__tests__/dokploy.spec.ts +196 -6
  58. package/src/deploy/__tests__/index.spec.ts +339 -0
  59. package/src/deploy/__tests__/init.spec.ts +147 -16
  60. package/src/deploy/docker.ts +32 -3
  61. package/src/deploy/dokploy-api.ts +581 -0
  62. package/src/deploy/dokploy.ts +66 -93
  63. package/src/deploy/index.ts +587 -32
  64. package/src/deploy/init.ts +192 -249
  65. package/src/deploy/types.ts +19 -1
  66. package/src/dev/__tests__/index.spec.ts +95 -0
  67. package/src/docker/__tests__/templates.spec.ts +144 -0
  68. package/src/docker/index.ts +96 -6
  69. package/src/docker/templates.ts +114 -27
  70. package/src/generators/EndpointGenerator.ts +2 -2
  71. package/src/index.ts +34 -13
  72. package/src/secrets/storage.ts +15 -0
  73. package/src/types.ts +2 -0
  74. package/dist/bundler-B1qy9b-j.cjs.map +0 -1
  75. package/dist/bundler-DskIqW2t.mjs.map +0 -1
  76. package/dist/storage-BOOpAF8N.cjs +0 -5
  77. package/dist/storage-Bj1E26lU.cjs.map +0 -1
  78. package/dist/storage-kSxTjkNb.mjs.map +0 -1
  79. package/dist/storage-tgZSUnKl.mjs +0 -3
@@ -1,4 +1,5 @@
1
- import { getDokployToken } from '../auth';
1
+ import { getDokployRegistryId, getDokployToken } from '../auth';
2
+ import { DokployApi } from './dokploy-api';
2
3
  import type { DeployResult, DokployDeployConfig } from './types';
3
4
 
4
5
  const logger = console;
@@ -16,12 +17,6 @@ export interface DokployDeployOptions {
16
17
  config: DokployDeployConfig;
17
18
  }
18
19
 
19
- interface DokployErrorResponse {
20
- message: string;
21
- code?: string;
22
- issues?: Array<{ message: string }>;
23
- }
24
-
25
20
  /**
26
21
  * Get the Dokploy API token from stored credentials or environment
27
22
  */
@@ -37,85 +32,11 @@ async function getApiToken(): Promise<string> {
37
32
  }
38
33
 
39
34
  /**
40
- * Make a request to the Dokploy API
41
- */
42
- async function dokployRequest<T>(
43
- endpoint: string,
44
- baseUrl: string,
45
- token: string,
46
- body: Record<string, unknown>,
47
- ): Promise<T> {
48
- const url = `${baseUrl}/api/${endpoint}`;
49
-
50
- const response = await fetch(url, {
51
- method: 'POST',
52
- headers: {
53
- 'Content-Type': 'application/json',
54
- Authorization: `Bearer ${token}`,
55
- },
56
- body: JSON.stringify(body),
57
- });
58
-
59
- if (!response.ok) {
60
- let errorMessage = `Dokploy API error: ${response.status} ${response.statusText}`;
61
-
62
- try {
63
- const errorBody = (await response.json()) as DokployErrorResponse;
64
- if (errorBody.message) {
65
- errorMessage = `Dokploy API error: ${errorBody.message}`;
66
- }
67
- if (errorBody.issues?.length) {
68
- errorMessage += `\n Issues: ${errorBody.issues.map((i) => i.message).join(', ')}`;
69
- }
70
- } catch {
71
- // Ignore JSON parse errors
72
- }
73
-
74
- throw new Error(errorMessage);
75
- }
76
-
77
- return response.json() as Promise<T>;
78
- }
79
-
80
- /**
81
- * Update application environment variables
82
- */
83
- async function updateEnvironment(
84
- baseUrl: string,
85
- token: string,
86
- applicationId: string,
87
- envVars: Record<string, string>,
88
- ): Promise<void> {
89
- logger.log(' Updating environment variables...');
90
-
91
- // Convert env vars to the format Dokploy expects (KEY=VALUE per line)
92
- const envString = Object.entries(envVars)
93
- .map(([key, value]) => `${key}=${value}`)
94
- .join('\n');
95
-
96
- await dokployRequest('application.update', baseUrl, token, {
97
- applicationId,
98
- env: envString,
99
- });
100
-
101
- logger.log(' ✓ Environment variables updated');
102
- }
103
-
104
- /**
105
- * Trigger application deployment
35
+ * Create a Dokploy API client
106
36
  */
107
- async function triggerDeploy(
108
- baseUrl: string,
109
- token: string,
110
- applicationId: string,
111
- ): Promise<void> {
112
- logger.log(' Triggering deployment...');
113
-
114
- await dokployRequest('application.deploy', baseUrl, token, {
115
- applicationId,
116
- });
117
-
118
- logger.log(' ✓ Deployment triggered');
37
+ async function createApi(endpoint: string): Promise<DokployApi> {
38
+ const token = await getApiToken();
39
+ return new DokployApi({ baseUrl: endpoint, token });
119
40
  }
120
41
 
121
42
  /**
@@ -130,7 +51,54 @@ export async function deployDokploy(
130
51
  logger.log(` Endpoint: ${config.endpoint}`);
131
52
  logger.log(` Application: ${config.applicationId}`);
132
53
 
133
- const token = await getApiToken();
54
+ const api = await createApi(config.endpoint);
55
+
56
+ // Configure Docker provider with the image
57
+ logger.log(` Configuring Docker image: ${imageRef}`);
58
+
59
+ // Determine registry credentials
60
+ const registryOptions: {
61
+ registryId?: string;
62
+ username?: string;
63
+ password?: string;
64
+ registryUrl?: string;
65
+ } = {};
66
+
67
+ if (config.registryId) {
68
+ // Use registry ID from config
69
+ registryOptions.registryId = config.registryId;
70
+ logger.log(` Using Dokploy registry: ${config.registryId}`);
71
+ } else {
72
+ // Try stored registry ID from credentials
73
+ const storedRegistryId = await getDokployRegistryId();
74
+ if (storedRegistryId) {
75
+ registryOptions.registryId = storedRegistryId;
76
+ logger.log(` Using stored Dokploy registry: ${storedRegistryId}`);
77
+ } else if (config.registryCredentials) {
78
+ // Use explicit credentials from config
79
+ registryOptions.username = config.registryCredentials.username;
80
+ registryOptions.password = config.registryCredentials.password;
81
+ registryOptions.registryUrl = config.registryCredentials.registryUrl;
82
+ logger.log(
83
+ ` Using registry credentials for: ${config.registryCredentials.registryUrl}`,
84
+ );
85
+ } else {
86
+ // Try environment variables
87
+ const username = process.env.DOCKER_REGISTRY_USERNAME;
88
+ const password = process.env.DOCKER_REGISTRY_PASSWORD;
89
+ const registryUrl = process.env.DOCKER_REGISTRY_URL || config.registry;
90
+
91
+ if (username && password && registryUrl) {
92
+ registryOptions.username = username;
93
+ registryOptions.password = password;
94
+ registryOptions.registryUrl = registryUrl;
95
+ logger.log(` Using registry credentials from environment`);
96
+ }
97
+ }
98
+ }
99
+
100
+ await api.saveDockerProvider(config.applicationId, imageRef, registryOptions);
101
+ logger.log(' ✓ Docker provider configured');
134
102
 
135
103
  // Prepare environment variables
136
104
  const envVars: Record<string, string> = {};
@@ -141,16 +109,21 @@ export async function deployDokploy(
141
109
 
142
110
  // Update environment if we have variables to set
143
111
  if (Object.keys(envVars).length > 0) {
144
- await updateEnvironment(
145
- config.endpoint,
146
- token,
147
- config.applicationId,
148
- envVars,
149
- );
112
+ logger.log(' Updating environment variables...');
113
+
114
+ // Convert env vars to the format Dokploy expects (KEY=VALUE per line)
115
+ const envString = Object.entries(envVars)
116
+ .map(([key, value]) => `${key}=${value}`)
117
+ .join('\n');
118
+
119
+ await api.saveApplicationEnv(config.applicationId, envString);
120
+ logger.log(' ✓ Environment variables updated');
150
121
  }
151
122
 
152
123
  // Trigger deployment
153
- await triggerDeploy(config.endpoint, token, config.applicationId);
124
+ logger.log(' Triggering deployment...');
125
+ await api.deployApplication(config.applicationId);
126
+ logger.log(' ✓ Deployment triggered');
154
127
 
155
128
  logger.log('\n✅ Dokploy deployment initiated!');
156
129
  logger.log(`\n📋 Deployment details:`);