@geekmidas/cli 0.10.0 → 0.13.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/README.md +525 -0
- package/dist/bundler-B1qy9b-j.cjs +112 -0
- package/dist/bundler-B1qy9b-j.cjs.map +1 -0
- package/dist/bundler-DskIqW2t.mjs +111 -0
- package/dist/bundler-DskIqW2t.mjs.map +1 -0
- package/dist/{config-C9aXOHBe.cjs → config-AmInkU7k.cjs} +8 -8
- package/dist/config-AmInkU7k.cjs.map +1 -0
- package/dist/{config-BrkUalUh.mjs → config-DYULeEv8.mjs} +3 -3
- package/dist/config-DYULeEv8.mjs.map +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/encryption-C8H-38Yy.mjs +42 -0
- package/dist/encryption-C8H-38Yy.mjs.map +1 -0
- package/dist/encryption-Dyf_r1h-.cjs +44 -0
- package/dist/encryption-Dyf_r1h-.cjs.map +1 -0
- package/dist/index.cjs +2123 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2141 -192
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-CZLI4QTr.mjs → openapi-BfFlOBCG.mjs} +801 -38
- package/dist/openapi-BfFlOBCG.mjs.map +1 -0
- package/dist/{openapi-BeHLKcwP.cjs → openapi-Bt_1FDpT.cjs} +794 -31
- package/dist/openapi-Bt_1FDpT.cjs.map +1 -0
- package/dist/{openapi-react-query-o5iMi8tz.cjs → openapi-react-query-B-sNWHFU.cjs} +5 -5
- package/dist/openapi-react-query-B-sNWHFU.cjs.map +1 -0
- package/dist/{openapi-react-query-CcciaVu5.mjs → openapi-react-query-B6XTeGqS.mjs} +5 -5
- package/dist/openapi-react-query-B6XTeGqS.mjs.map +1 -0
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.d.cts.map +1 -1
- package/dist/openapi-react-query.d.mts.map +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +2 -2
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +2 -2
- package/dist/storage-BOOpAF8N.cjs +5 -0
- package/dist/storage-Bj1E26lU.cjs +187 -0
- package/dist/storage-Bj1E26lU.cjs.map +1 -0
- package/dist/storage-kSxTjkNb.mjs +133 -0
- package/dist/storage-kSxTjkNb.mjs.map +1 -0
- package/dist/storage-tgZSUnKl.mjs +3 -0
- package/dist/{types-b-vwGpqc.d.cts → types-BR0M2v_c.d.mts} +100 -1
- package/dist/types-BR0M2v_c.d.mts.map +1 -0
- package/dist/{types-DXgiA1sF.d.mts → types-BhkZc-vm.d.cts} +100 -1
- package/dist/types-BhkZc-vm.d.cts.map +1 -0
- package/examples/cron-example.ts +27 -27
- package/examples/env.ts +27 -27
- package/examples/function-example.ts +31 -31
- package/examples/gkm.config.json +20 -20
- package/examples/gkm.config.ts +8 -8
- package/examples/gkm.minimal.config.json +5 -5
- package/examples/gkm.production.config.json +25 -25
- package/examples/logger.ts +2 -2
- package/package.json +6 -6
- package/src/__tests__/EndpointGenerator.hooks.spec.ts +191 -191
- package/src/__tests__/config.spec.ts +55 -55
- package/src/__tests__/loadEnvFiles.spec.ts +93 -93
- package/src/__tests__/normalizeHooksConfig.spec.ts +58 -58
- package/src/__tests__/openapi-react-query.spec.ts +497 -497
- package/src/__tests__/openapi.spec.ts +428 -428
- package/src/__tests__/test-helpers.ts +76 -76
- package/src/auth/__tests__/credentials.spec.ts +204 -0
- package/src/auth/__tests__/index.spec.ts +168 -0
- package/src/auth/credentials.ts +187 -0
- package/src/auth/index.ts +226 -0
- package/src/build/__tests__/bundler.spec.ts +444 -0
- package/src/build/__tests__/index-new.spec.ts +474 -474
- package/src/build/__tests__/manifests.spec.ts +333 -333
- package/src/build/bundler.ts +210 -0
- package/src/build/endpoint-analyzer.ts +236 -0
- package/src/build/handler-templates.ts +1253 -0
- package/src/build/index.ts +260 -179
- package/src/build/manifests.ts +52 -52
- package/src/build/providerResolver.ts +145 -145
- package/src/build/types.ts +64 -43
- package/src/config.ts +39 -39
- package/src/deploy/__tests__/docker.spec.ts +111 -0
- package/src/deploy/__tests__/dokploy.spec.ts +245 -0
- package/src/deploy/__tests__/init.spec.ts +662 -0
- package/src/deploy/docker.ts +128 -0
- package/src/deploy/dokploy.ts +204 -0
- package/src/deploy/index.ts +136 -0
- package/src/deploy/init.ts +484 -0
- package/src/deploy/types.ts +48 -0
- package/src/dev/__tests__/index.spec.ts +266 -266
- package/src/dev/index.ts +647 -601
- package/src/docker/__tests__/compose.spec.ts +531 -0
- package/src/docker/__tests__/templates.spec.ts +280 -0
- package/src/docker/compose.ts +273 -0
- package/src/docker/index.ts +230 -0
- package/src/docker/templates.ts +446 -0
- package/src/generators/CronGenerator.ts +72 -72
- package/src/generators/EndpointGenerator.ts +699 -398
- package/src/generators/FunctionGenerator.ts +84 -84
- package/src/generators/Generator.ts +72 -72
- package/src/generators/OpenApiTsGenerator.ts +577 -577
- package/src/generators/SubscriberGenerator.ts +124 -124
- package/src/generators/__tests__/CronGenerator.spec.ts +433 -433
- package/src/generators/__tests__/EndpointGenerator.spec.ts +532 -382
- package/src/generators/__tests__/FunctionGenerator.spec.ts +244 -244
- package/src/generators/__tests__/SubscriberGenerator.spec.ts +397 -382
- package/src/generators/index.ts +4 -4
- package/src/index.ts +623 -201
- package/src/init/__tests__/generators.spec.ts +334 -334
- package/src/init/__tests__/init.spec.ts +332 -332
- package/src/init/__tests__/utils.spec.ts +89 -89
- package/src/init/generators/config.ts +175 -175
- package/src/init/generators/docker.ts +41 -41
- package/src/init/generators/env.ts +72 -72
- package/src/init/generators/index.ts +1 -1
- package/src/init/generators/models.ts +64 -64
- package/src/init/generators/monorepo.ts +161 -161
- package/src/init/generators/package.ts +71 -71
- package/src/init/generators/source.ts +6 -6
- package/src/init/index.ts +203 -208
- package/src/init/templates/api.ts +115 -115
- package/src/init/templates/index.ts +75 -75
- package/src/init/templates/minimal.ts +98 -98
- package/src/init/templates/serverless.ts +89 -89
- package/src/init/templates/worker.ts +98 -98
- package/src/init/utils.ts +54 -56
- package/src/openapi-react-query.ts +194 -194
- package/src/openapi.ts +63 -63
- package/src/secrets/__tests__/encryption.spec.ts +226 -0
- package/src/secrets/__tests__/generator.spec.ts +319 -0
- package/src/secrets/__tests__/index.spec.ts +91 -0
- package/src/secrets/__tests__/storage.spec.ts +611 -0
- package/src/secrets/encryption.ts +91 -0
- package/src/secrets/generator.ts +164 -0
- package/src/secrets/index.ts +383 -0
- package/src/secrets/storage.ts +192 -0
- package/src/secrets/types.ts +53 -0
- package/src/types.ts +295 -176
- package/tsdown.config.ts +11 -8
- package/dist/config-BrkUalUh.mjs.map +0 -1
- package/dist/config-C9aXOHBe.cjs.map +0 -1
- package/dist/openapi-BeHLKcwP.cjs.map +0 -1
- package/dist/openapi-CZLI4QTr.mjs.map +0 -1
- package/dist/openapi-react-query-CcciaVu5.mjs.map +0 -1
- package/dist/openapi-react-query-o5iMi8tz.cjs.map +0 -1
- package/dist/types-DXgiA1sF.d.mts.map +0 -1
- package/dist/types-b-vwGpqc.d.cts.map +0 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { HttpResponse, http } from 'msw';
|
|
2
|
+
import { setupServer } from 'msw/node';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { deployDokploy, validateDokployConfig } from '../dokploy';
|
|
5
|
+
import type { DokployDeployConfig } from '../types';
|
|
6
|
+
|
|
7
|
+
// Mock getDokployToken to return a test token
|
|
8
|
+
vi.mock('../../auth', () => ({
|
|
9
|
+
getDokployToken: vi.fn().mockResolvedValue('test-api-token'),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
// MSW server for mocking Dokploy API
|
|
13
|
+
const server = setupServer();
|
|
14
|
+
|
|
15
|
+
describe('validateDokployConfig', () => {
|
|
16
|
+
it('should return true for valid complete config', () => {
|
|
17
|
+
const config: DokployDeployConfig = {
|
|
18
|
+
endpoint: 'https://dokploy.example.com',
|
|
19
|
+
projectId: 'proj_123',
|
|
20
|
+
applicationId: 'app_456',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const result = validateDokployConfig(config);
|
|
24
|
+
expect(result).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should return true with optional registry', () => {
|
|
28
|
+
const config: DokployDeployConfig = {
|
|
29
|
+
endpoint: 'https://dokploy.example.com',
|
|
30
|
+
projectId: 'proj_123',
|
|
31
|
+
applicationId: 'app_456',
|
|
32
|
+
registry: 'ghcr.io/myorg',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const result = validateDokployConfig(config);
|
|
36
|
+
expect(result).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should return false for undefined config', () => {
|
|
40
|
+
const result = validateDokployConfig(undefined);
|
|
41
|
+
expect(result).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should throw for missing endpoint', () => {
|
|
45
|
+
const config = {
|
|
46
|
+
projectId: 'proj_123',
|
|
47
|
+
applicationId: 'app_456',
|
|
48
|
+
} as Partial<DokployDeployConfig>;
|
|
49
|
+
|
|
50
|
+
expect(() => validateDokployConfig(config)).toThrow(
|
|
51
|
+
'Missing Dokploy configuration: endpoint',
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should throw for missing projectId', () => {
|
|
56
|
+
const config = {
|
|
57
|
+
endpoint: 'https://dokploy.example.com',
|
|
58
|
+
applicationId: 'app_456',
|
|
59
|
+
} as Partial<DokployDeployConfig>;
|
|
60
|
+
|
|
61
|
+
expect(() => validateDokployConfig(config)).toThrow(
|
|
62
|
+
'Missing Dokploy configuration: projectId',
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should throw for missing applicationId', () => {
|
|
67
|
+
const config = {
|
|
68
|
+
endpoint: 'https://dokploy.example.com',
|
|
69
|
+
projectId: 'proj_123',
|
|
70
|
+
} as Partial<DokployDeployConfig>;
|
|
71
|
+
|
|
72
|
+
expect(() => validateDokployConfig(config)).toThrow(
|
|
73
|
+
'Missing Dokploy configuration: applicationId',
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should list all missing fields', () => {
|
|
78
|
+
const config = {
|
|
79
|
+
endpoint: 'https://dokploy.example.com',
|
|
80
|
+
} as Partial<DokployDeployConfig>;
|
|
81
|
+
|
|
82
|
+
expect(() => validateDokployConfig(config)).toThrow(
|
|
83
|
+
'Missing Dokploy configuration: projectId, applicationId',
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should throw for empty config object', () => {
|
|
88
|
+
const config = {} as Partial<DokployDeployConfig>;
|
|
89
|
+
|
|
90
|
+
expect(() => validateDokployConfig(config)).toThrow(
|
|
91
|
+
'Missing Dokploy configuration: endpoint, projectId, applicationId',
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should include configuration example in error', () => {
|
|
96
|
+
const config = {} as Partial<DokployDeployConfig>;
|
|
97
|
+
|
|
98
|
+
expect(() => validateDokployConfig(config)).toThrow(
|
|
99
|
+
'Configure in gkm.config.ts:',
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('deployDokploy', () => {
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
server.listen({ onUnhandledRequest: 'bypass' });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
afterEach(() => {
|
|
110
|
+
server.resetHandlers();
|
|
111
|
+
server.close();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should deploy successfully without master key', async () => {
|
|
115
|
+
server.use(
|
|
116
|
+
http.post('https://dokploy.example.com/api/application.deploy', () => {
|
|
117
|
+
return HttpResponse.json({ success: true });
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const result = await deployDokploy({
|
|
122
|
+
stage: 'production',
|
|
123
|
+
tag: 'v1.0.0',
|
|
124
|
+
imageRef: 'ghcr.io/myorg/app:v1.0.0',
|
|
125
|
+
config: {
|
|
126
|
+
endpoint: 'https://dokploy.example.com',
|
|
127
|
+
projectId: 'proj_123',
|
|
128
|
+
applicationId: 'app_456',
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
expect(result.imageRef).toBe('ghcr.io/myorg/app:v1.0.0');
|
|
133
|
+
expect(result.masterKey).toBeUndefined();
|
|
134
|
+
expect(result.url).toBe('https://dokploy.example.com/project/proj_123');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should deploy with master key and update environment', async () => {
|
|
138
|
+
const updateCalls: unknown[] = [];
|
|
139
|
+
|
|
140
|
+
server.use(
|
|
141
|
+
http.post(
|
|
142
|
+
'https://dokploy.example.com/api/application.update',
|
|
143
|
+
async ({ request }) => {
|
|
144
|
+
const body = await request.json();
|
|
145
|
+
updateCalls.push(body);
|
|
146
|
+
return HttpResponse.json({ success: true });
|
|
147
|
+
},
|
|
148
|
+
),
|
|
149
|
+
http.post('https://dokploy.example.com/api/application.deploy', () => {
|
|
150
|
+
return HttpResponse.json({ success: true });
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const result = await deployDokploy({
|
|
155
|
+
stage: 'production',
|
|
156
|
+
tag: 'v1.0.0',
|
|
157
|
+
imageRef: 'ghcr.io/myorg/app:v1.0.0',
|
|
158
|
+
masterKey: 'secret-master-key',
|
|
159
|
+
config: {
|
|
160
|
+
endpoint: 'https://dokploy.example.com',
|
|
161
|
+
projectId: 'proj_123',
|
|
162
|
+
applicationId: 'app_456',
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
expect(result.masterKey).toBe('secret-master-key');
|
|
167
|
+
expect(updateCalls).toHaveLength(1);
|
|
168
|
+
expect(updateCalls[0]).toMatchObject({
|
|
169
|
+
applicationId: 'app_456',
|
|
170
|
+
env: 'GKM_MASTER_KEY=secret-master-key',
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('should handle API error with message', async () => {
|
|
175
|
+
server.use(
|
|
176
|
+
http.post('https://dokploy.example.com/api/application.deploy', () => {
|
|
177
|
+
return HttpResponse.json(
|
|
178
|
+
{ message: 'Application not found' },
|
|
179
|
+
{ status: 404 },
|
|
180
|
+
);
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
await expect(
|
|
185
|
+
deployDokploy({
|
|
186
|
+
stage: 'production',
|
|
187
|
+
tag: 'v1.0.0',
|
|
188
|
+
imageRef: 'ghcr.io/myorg/app:v1.0.0',
|
|
189
|
+
config: {
|
|
190
|
+
endpoint: 'https://dokploy.example.com',
|
|
191
|
+
projectId: 'proj_123',
|
|
192
|
+
applicationId: 'app_456',
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
).rejects.toThrow('Dokploy API error: Application not found');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should handle API error with issues', async () => {
|
|
199
|
+
server.use(
|
|
200
|
+
http.post('https://dokploy.example.com/api/application.deploy', () => {
|
|
201
|
+
return HttpResponse.json(
|
|
202
|
+
{
|
|
203
|
+
message: 'Validation failed',
|
|
204
|
+
issues: [{ message: 'Invalid field' }, { message: 'Missing data' }],
|
|
205
|
+
},
|
|
206
|
+
{ status: 400 },
|
|
207
|
+
);
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
await expect(
|
|
212
|
+
deployDokploy({
|
|
213
|
+
stage: 'production',
|
|
214
|
+
tag: 'v1.0.0',
|
|
215
|
+
imageRef: 'ghcr.io/myorg/app:v1.0.0',
|
|
216
|
+
config: {
|
|
217
|
+
endpoint: 'https://dokploy.example.com',
|
|
218
|
+
projectId: 'proj_123',
|
|
219
|
+
applicationId: 'app_456',
|
|
220
|
+
},
|
|
221
|
+
}),
|
|
222
|
+
).rejects.toThrow('Issues: Invalid field, Missing data');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should handle API error without JSON body', async () => {
|
|
226
|
+
server.use(
|
|
227
|
+
http.post('https://dokploy.example.com/api/application.deploy', () => {
|
|
228
|
+
return new HttpResponse('Internal Server Error', { status: 500 });
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
await expect(
|
|
233
|
+
deployDokploy({
|
|
234
|
+
stage: 'production',
|
|
235
|
+
tag: 'v1.0.0',
|
|
236
|
+
imageRef: 'ghcr.io/myorg/app:v1.0.0',
|
|
237
|
+
config: {
|
|
238
|
+
endpoint: 'https://dokploy.example.com',
|
|
239
|
+
projectId: 'proj_123',
|
|
240
|
+
applicationId: 'app_456',
|
|
241
|
+
},
|
|
242
|
+
}),
|
|
243
|
+
).rejects.toThrow('Dokploy API error: 500');
|
|
244
|
+
});
|
|
245
|
+
});
|