@geekmidas/cli 0.54.0 → 1.0.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/CHANGELOG.md +17 -0
- package/README.md +26 -5
- package/dist/CachedStateProvider-D73dCqfH.cjs +60 -0
- package/dist/CachedStateProvider-D73dCqfH.cjs.map +1 -0
- package/dist/CachedStateProvider-DVyKfaMm.mjs +54 -0
- package/dist/CachedStateProvider-DVyKfaMm.mjs.map +1 -0
- package/dist/CachedStateProvider-D_uISMmJ.cjs +3 -0
- package/dist/CachedStateProvider-OiFUGr7p.mjs +3 -0
- package/dist/HostingerProvider-DUV9-Tzg.cjs +210 -0
- package/dist/HostingerProvider-DUV9-Tzg.cjs.map +1 -0
- package/dist/HostingerProvider-DqUq6e9i.mjs +210 -0
- package/dist/HostingerProvider-DqUq6e9i.mjs.map +1 -0
- package/dist/LocalStateProvider-CdspeSVL.cjs +43 -0
- package/dist/LocalStateProvider-CdspeSVL.cjs.map +1 -0
- package/dist/LocalStateProvider-DxoSaWUV.mjs +42 -0
- package/dist/LocalStateProvider-DxoSaWUV.mjs.map +1 -0
- package/dist/Route53Provider-CpRIqu69.cjs +157 -0
- package/dist/Route53Provider-CpRIqu69.cjs.map +1 -0
- package/dist/Route53Provider-KUAX3vz9.mjs +156 -0
- package/dist/Route53Provider-KUAX3vz9.mjs.map +1 -0
- package/dist/SSMStateProvider-BxAPU99a.cjs +53 -0
- package/dist/SSMStateProvider-BxAPU99a.cjs.map +1 -0
- package/dist/SSMStateProvider-C4wp4AZe.mjs +52 -0
- package/dist/SSMStateProvider-C4wp4AZe.mjs.map +1 -0
- package/dist/{bundler-DGry2vaR.mjs → bundler-BqTN5Dj5.mjs} +3 -3
- package/dist/{bundler-DGry2vaR.mjs.map → bundler-BqTN5Dj5.mjs.map} +1 -1
- package/dist/{bundler-BB-kETMd.cjs → bundler-tHLLwYuU.cjs} +3 -3
- package/dist/{bundler-BB-kETMd.cjs.map → bundler-tHLLwYuU.cjs.map} +1 -1
- package/dist/{config-HYiM3iQJ.cjs → config-BGeJsW1r.cjs} +2 -2
- package/dist/{config-HYiM3iQJ.cjs.map → config-BGeJsW1r.cjs.map} +1 -1
- package/dist/{config-C3LSBNSl.mjs → config-C6awcFBx.mjs} +2 -2
- package/dist/{config-C3LSBNSl.mjs.map → config-C6awcFBx.mjs.map} +1 -1
- package/dist/config.cjs +2 -2
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +2 -2
- package/dist/credentials-C8DWtnMY.cjs +174 -0
- package/dist/credentials-C8DWtnMY.cjs.map +1 -0
- package/dist/credentials-DT1dSxIx.mjs +126 -0
- package/dist/credentials-DT1dSxIx.mjs.map +1 -0
- package/dist/deploy/sniffer-envkit-patch.cjs.map +1 -1
- package/dist/deploy/sniffer-envkit-patch.mjs.map +1 -1
- package/dist/deploy/sniffer-loader.cjs +1 -1
- package/dist/{dokploy-api-94KzmTVf.mjs → dokploy-api-7k3t7_zd.mjs} +1 -1
- package/dist/{dokploy-api-94KzmTVf.mjs.map → dokploy-api-7k3t7_zd.mjs.map} +1 -1
- package/dist/dokploy-api-CHa8G51l.mjs +3 -0
- package/dist/{dokploy-api-YD8WCQfW.cjs → dokploy-api-CQvhV6Hd.cjs} +1 -1
- package/dist/{dokploy-api-YD8WCQfW.cjs.map → dokploy-api-CQvhV6Hd.cjs.map} +1 -1
- package/dist/dokploy-api-CWc02yyg.cjs +3 -0
- package/dist/{encryption-DaCB_NmS.cjs → encryption-BE0UOb8j.cjs} +1 -1
- package/dist/{encryption-DaCB_NmS.cjs.map → encryption-BE0UOb8j.cjs.map} +1 -1
- package/dist/{encryption-Biq0EZ4m.cjs → encryption-Cv3zips0.cjs} +1 -1
- package/dist/{encryption-BC4MAODn.mjs → encryption-JtMsiGNp.mjs} +1 -1
- package/dist/{encryption-BC4MAODn.mjs.map → encryption-JtMsiGNp.mjs.map} +1 -1
- package/dist/encryption-UUmaWAmz.mjs +3 -0
- package/dist/{index-pOA56MWT.d.cts → index-B5rGIc4g.d.cts} +553 -196
- package/dist/index-B5rGIc4g.d.cts.map +1 -0
- package/dist/{index-A70abJ1m.d.mts → index-KFEbMIRa.d.mts} +554 -197
- package/dist/index-KFEbMIRa.d.mts.map +1 -0
- package/dist/index.cjs +2223 -606
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2200 -583
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-C3C-BzIZ.mjs → openapi-BMFmLnX6.mjs} +51 -7
- package/dist/openapi-BMFmLnX6.mjs.map +1 -0
- package/dist/{openapi-D7WwlpPF.cjs → openapi-D1KXv2Ml.cjs} +51 -7
- package/dist/openapi-D1KXv2Ml.cjs.map +1 -0
- package/dist/{openapi-react-query-C_MxpBgF.cjs → openapi-react-query-BeXvk-wa.cjs} +1 -1
- package/dist/{openapi-react-query-C_MxpBgF.cjs.map → openapi-react-query-BeXvk-wa.cjs.map} +1 -1
- package/dist/{openapi-react-query-ZoP9DPbY.mjs → openapi-react-query-DGEkD39r.mjs} +1 -1
- package/dist/{openapi-react-query-ZoP9DPbY.mjs.map → openapi-react-query-DGEkD39r.mjs.map} +1 -1
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +3 -3
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +2 -2
- package/dist/openapi.mjs +3 -3
- package/dist/{storage-Dhst7BhI.mjs → storage-BMW6yLu3.mjs} +1 -1
- package/dist/{storage-Dhst7BhI.mjs.map → storage-BMW6yLu3.mjs.map} +1 -1
- package/dist/{storage-fOR8dMu5.cjs → storage-C7pmBq1u.cjs} +1 -1
- package/dist/{storage-BPRgh3DU.cjs → storage-CoCNe0Pt.cjs} +1 -1
- package/dist/{storage-BPRgh3DU.cjs.map → storage-CoCNe0Pt.cjs.map} +1 -1
- package/dist/{storage-DNj_I11J.mjs → storage-D8XzjVaO.mjs} +1 -1
- package/dist/{types-BtGL-8QS.d.mts → types-BldpmqQX.d.mts} +1 -1
- package/dist/{types-BtGL-8QS.d.mts.map → types-BldpmqQX.d.mts.map} +1 -1
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.d.cts +1 -1
- package/dist/workspace/index.d.mts +2 -2
- package/dist/workspace/index.mjs +1 -1
- package/dist/{workspace-CaVW6j2q.cjs → workspace-BFRUOOrh.cjs} +309 -25
- package/dist/workspace-BFRUOOrh.cjs.map +1 -0
- package/dist/{workspace-DLFRaDc-.mjs → workspace-DAxG3_H2.mjs} +309 -25
- package/dist/workspace-DAxG3_H2.mjs.map +1 -0
- package/package.json +12 -8
- package/src/build/__tests__/handler-templates.spec.ts +115 -47
- package/src/deploy/CachedStateProvider.ts +86 -0
- package/src/deploy/LocalStateProvider.ts +57 -0
- package/src/deploy/SSMStateProvider.ts +93 -0
- package/src/deploy/StateProvider.ts +171 -0
- package/src/deploy/__tests__/CachedStateProvider.spec.ts +228 -0
- package/src/deploy/__tests__/HostingerProvider.spec.ts +347 -0
- package/src/deploy/__tests__/LocalStateProvider.spec.ts +126 -0
- package/src/deploy/__tests__/Route53Provider.spec.ts +402 -0
- package/src/deploy/__tests__/SSMStateProvider.spec.ts +177 -0
- package/src/deploy/__tests__/__fixtures__/env-parsers/throwing-env-parser.ts +1 -3
- package/src/deploy/__tests__/__fixtures__/route-apps/services.ts +28 -19
- package/src/deploy/__tests__/createDnsProvider.spec.ts +172 -0
- package/src/deploy/__tests__/createStateProvider.spec.ts +116 -0
- package/src/deploy/__tests__/dns-orchestration.spec.ts +192 -0
- package/src/deploy/__tests__/dns-verification.spec.ts +2 -2
- package/src/deploy/__tests__/env-resolver.spec.ts +37 -15
- package/src/deploy/__tests__/sniffer.spec.ts +4 -20
- package/src/deploy/__tests__/state.spec.ts +13 -5
- package/src/deploy/dns/DnsProvider.ts +163 -0
- package/src/deploy/dns/HostingerProvider.ts +100 -0
- package/src/deploy/dns/Route53Provider.ts +256 -0
- package/src/deploy/dns/index.ts +257 -165
- package/src/deploy/env-resolver.ts +12 -5
- package/src/deploy/index.ts +16 -13
- package/src/deploy/sniffer-envkit-patch.ts +3 -1
- package/src/deploy/sniffer-routes-worker.ts +104 -0
- package/src/deploy/sniffer.ts +77 -55
- package/src/deploy/state-commands.ts +274 -0
- package/src/dev/__tests__/entry.spec.ts +8 -2
- package/src/dev/__tests__/index.spec.ts +1 -3
- package/src/dev/index.ts +9 -3
- package/src/docker/__tests__/templates.spec.ts +3 -1
- package/src/index.ts +88 -0
- package/src/init/__tests__/generators.spec.ts +273 -0
- package/src/init/__tests__/init.spec.ts +3 -3
- package/src/init/generators/auth.ts +1 -0
- package/src/init/generators/config.ts +2 -0
- package/src/init/generators/models.ts +6 -1
- package/src/init/generators/monorepo.ts +3 -0
- package/src/init/generators/ui.ts +1472 -0
- package/src/init/generators/web.ts +134 -87
- package/src/init/index.ts +22 -3
- package/src/init/templates/api.ts +109 -3
- package/src/openapi.ts +99 -13
- package/src/workspace/__tests__/schema.spec.ts +107 -0
- package/src/workspace/schema.ts +314 -4
- package/src/workspace/types.ts +22 -36
- package/dist/dokploy-api-CItuaWTq.mjs +0 -3
- package/dist/dokploy-api-DBNE8MDt.cjs +0 -3
- package/dist/encryption-CQXBZGkt.mjs +0 -3
- package/dist/index-A70abJ1m.d.mts.map +0 -1
- package/dist/index-pOA56MWT.d.cts.map +0 -1
- package/dist/openapi-C3C-BzIZ.mjs.map +0 -1
- package/dist/openapi-D7WwlpPF.cjs.map +0 -1
- package/dist/workspace-CaVW6j2q.cjs.map +0 -1
- package/dist/workspace-DLFRaDc-.mjs.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
createDnsProvider,
|
|
4
|
+
type DnsProvider,
|
|
5
|
+
type DnsRecord,
|
|
6
|
+
isDnsProvider,
|
|
7
|
+
type UpsertDnsRecord,
|
|
8
|
+
type UpsertResult,
|
|
9
|
+
} from '../dns/DnsProvider';
|
|
10
|
+
|
|
11
|
+
describe('isDnsProvider', () => {
|
|
12
|
+
it('should return true for valid provider', () => {
|
|
13
|
+
const provider: DnsProvider = {
|
|
14
|
+
name: 'test',
|
|
15
|
+
getRecords: async () => [],
|
|
16
|
+
upsertRecords: async () => [],
|
|
17
|
+
};
|
|
18
|
+
expect(isDnsProvider(provider)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should return false for null', () => {
|
|
22
|
+
expect(isDnsProvider(null)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return false for undefined', () => {
|
|
26
|
+
expect(isDnsProvider(undefined)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return false for empty object', () => {
|
|
30
|
+
expect(isDnsProvider({})).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should return false for object with only name', () => {
|
|
34
|
+
expect(isDnsProvider({ name: 'test' })).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should return false for object with only getRecords', () => {
|
|
38
|
+
expect(isDnsProvider({ getRecords: () => [] })).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return false for object with only upsertRecords', () => {
|
|
42
|
+
expect(isDnsProvider({ upsertRecords: () => [] })).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should return false for object with name and getRecords only', () => {
|
|
46
|
+
expect(isDnsProvider({ name: 'test', getRecords: () => [] })).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should return false for object with non-string name', () => {
|
|
50
|
+
expect(
|
|
51
|
+
isDnsProvider({
|
|
52
|
+
name: 123,
|
|
53
|
+
getRecords: () => [],
|
|
54
|
+
upsertRecords: () => [],
|
|
55
|
+
}),
|
|
56
|
+
).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('createDnsProvider', () => {
|
|
61
|
+
describe('manual provider', () => {
|
|
62
|
+
it('should return null for manual provider', async () => {
|
|
63
|
+
const provider = await createDnsProvider({
|
|
64
|
+
config: { provider: 'manual' },
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(provider).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('hostinger provider', () => {
|
|
72
|
+
it('should create HostingerProvider for hostinger config', async () => {
|
|
73
|
+
const provider = await createDnsProvider({
|
|
74
|
+
config: { provider: 'hostinger' },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(provider).not.toBeNull();
|
|
78
|
+
expect(provider?.name).toBe('hostinger');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('route53 provider', () => {
|
|
83
|
+
it('should create Route53Provider for route53 config', async () => {
|
|
84
|
+
const provider = await createDnsProvider({
|
|
85
|
+
config: {
|
|
86
|
+
provider: 'route53',
|
|
87
|
+
region: 'us-east-1',
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(provider).not.toBeNull();
|
|
92
|
+
expect(provider?.name).toBe('route53');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should create Route53Provider with hostedZoneId', async () => {
|
|
96
|
+
const provider = await createDnsProvider({
|
|
97
|
+
config: {
|
|
98
|
+
provider: 'route53',
|
|
99
|
+
region: 'us-west-2',
|
|
100
|
+
hostedZoneId: 'Z1234567890',
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(provider).not.toBeNull();
|
|
105
|
+
expect(provider?.name).toBe('route53');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('cloudflare provider', () => {
|
|
110
|
+
it('should throw for cloudflare provider (not yet implemented)', async () => {
|
|
111
|
+
await expect(
|
|
112
|
+
createDnsProvider({
|
|
113
|
+
config: { provider: 'cloudflare' },
|
|
114
|
+
}),
|
|
115
|
+
).rejects.toThrow('Cloudflare DNS provider not yet implemented');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('custom provider', () => {
|
|
120
|
+
it('should use custom provider implementation', async () => {
|
|
121
|
+
const customProvider: DnsProvider = {
|
|
122
|
+
name: 'custom-test',
|
|
123
|
+
async getRecords(): Promise<DnsRecord[]> {
|
|
124
|
+
return [];
|
|
125
|
+
},
|
|
126
|
+
async upsertRecords(): Promise<UpsertResult[]> {
|
|
127
|
+
return [];
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const provider = await createDnsProvider({
|
|
132
|
+
config: {
|
|
133
|
+
provider: customProvider,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(provider).toBe(customProvider);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should use custom provider with getRecords that returns data', async () => {
|
|
141
|
+
const mockRecords: DnsRecord[] = [
|
|
142
|
+
{ name: 'api', type: 'A', ttl: 300, values: ['1.2.3.4'] },
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const customProvider: DnsProvider = {
|
|
146
|
+
name: 'custom-test',
|
|
147
|
+
async getRecords(): Promise<DnsRecord[]> {
|
|
148
|
+
return mockRecords;
|
|
149
|
+
},
|
|
150
|
+
async upsertRecords(
|
|
151
|
+
_domain: string,
|
|
152
|
+
records: UpsertDnsRecord[],
|
|
153
|
+
): Promise<UpsertResult[]> {
|
|
154
|
+
return records.map((r) => ({
|
|
155
|
+
record: r,
|
|
156
|
+
created: true,
|
|
157
|
+
unchanged: false,
|
|
158
|
+
}));
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const provider = await createDnsProvider({
|
|
163
|
+
config: {
|
|
164
|
+
provider: customProvider,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const records = await provider!.getRecords('example.com');
|
|
169
|
+
expect(records).toEqual(mockRecords);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { mkdir, rm } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { CachedStateProvider } from '../CachedStateProvider';
|
|
6
|
+
import { LocalStateProvider } from '../LocalStateProvider';
|
|
7
|
+
import {
|
|
8
|
+
createStateProvider,
|
|
9
|
+
isStateProvider,
|
|
10
|
+
type StateProvider,
|
|
11
|
+
} from '../StateProvider';
|
|
12
|
+
|
|
13
|
+
describe('createStateProvider', () => {
|
|
14
|
+
let testDir: string;
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
testDir = join(tmpdir(), `gkm-state-factory-test-${Date.now()}`);
|
|
18
|
+
await mkdir(testDir, { recursive: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await rm(testDir, { recursive: true, force: true });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('isStateProvider', () => {
|
|
26
|
+
it('should return true for valid provider', () => {
|
|
27
|
+
const provider = {
|
|
28
|
+
read: async () => null,
|
|
29
|
+
write: async () => {},
|
|
30
|
+
};
|
|
31
|
+
expect(isStateProvider(provider)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should return false for null', () => {
|
|
35
|
+
expect(isStateProvider(null)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return false for undefined', () => {
|
|
39
|
+
expect(isStateProvider(undefined)).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return false for empty object', () => {
|
|
43
|
+
expect(isStateProvider({})).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should return false for object with only read', () => {
|
|
47
|
+
expect(isStateProvider({ read: () => {} })).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should return false for object with only write', () => {
|
|
51
|
+
expect(isStateProvider({ write: () => {} })).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('local provider', () => {
|
|
56
|
+
it('should create LocalStateProvider when no config', async () => {
|
|
57
|
+
const provider = await createStateProvider({
|
|
58
|
+
workspaceRoot: testDir,
|
|
59
|
+
workspaceName: 'test',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(provider).toBeInstanceOf(LocalStateProvider);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should create LocalStateProvider when provider is local', async () => {
|
|
66
|
+
const provider = await createStateProvider({
|
|
67
|
+
config: { provider: 'local' },
|
|
68
|
+
workspaceRoot: testDir,
|
|
69
|
+
workspaceName: 'test',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(provider).toBeInstanceOf(LocalStateProvider);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('ssm provider', () => {
|
|
77
|
+
it('should throw when workspace name is missing', async () => {
|
|
78
|
+
await expect(
|
|
79
|
+
createStateProvider({
|
|
80
|
+
config: { provider: 'ssm', region: 'us-east-1' },
|
|
81
|
+
workspaceRoot: testDir,
|
|
82
|
+
workspaceName: '',
|
|
83
|
+
}),
|
|
84
|
+
).rejects.toThrow('Workspace name is required');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should create CachedStateProvider for ssm config', async () => {
|
|
88
|
+
const provider = await createStateProvider({
|
|
89
|
+
config: { provider: 'ssm', region: 'us-east-1' },
|
|
90
|
+
workspaceRoot: testDir,
|
|
91
|
+
workspaceName: 'test-workspace',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(provider).toBeInstanceOf(CachedStateProvider);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('custom provider', () => {
|
|
99
|
+
it('should use custom provider implementation', async () => {
|
|
100
|
+
const customProvider: StateProvider = {
|
|
101
|
+
async read(): Promise<null> {
|
|
102
|
+
return null;
|
|
103
|
+
},
|
|
104
|
+
async write(): Promise<void> {},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const provider = await createStateProvider({
|
|
108
|
+
config: { provider: customProvider },
|
|
109
|
+
workspaceRoot: testDir,
|
|
110
|
+
workspaceName: 'test',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(provider).toBe(customProvider);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
extractSubdomain,
|
|
4
|
+
findRootDomain,
|
|
5
|
+
generateRequiredRecords,
|
|
6
|
+
groupHostnamesByDomain,
|
|
7
|
+
isLegacyDnsConfig,
|
|
8
|
+
normalizeDnsConfig,
|
|
9
|
+
} from '../dns/index';
|
|
10
|
+
|
|
11
|
+
describe('DNS orchestration helpers', () => {
|
|
12
|
+
describe('isLegacyDnsConfig', () => {
|
|
13
|
+
it('should return true for legacy config with domain property', () => {
|
|
14
|
+
const config = { provider: 'hostinger', domain: 'example.com' };
|
|
15
|
+
expect(isLegacyDnsConfig(config)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return false for new multi-domain config', () => {
|
|
19
|
+
const config = {
|
|
20
|
+
'example.com': { provider: 'hostinger' },
|
|
21
|
+
'example.dev': { provider: 'route53' },
|
|
22
|
+
};
|
|
23
|
+
expect(isLegacyDnsConfig(config)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return false for config without domain property', () => {
|
|
27
|
+
const config = { provider: 'hostinger' };
|
|
28
|
+
expect(isLegacyDnsConfig(config)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('normalizeDnsConfig', () => {
|
|
33
|
+
it('should convert legacy config to multi-domain format', () => {
|
|
34
|
+
const config = { provider: 'hostinger', domain: 'example.com', ttl: 300 };
|
|
35
|
+
const normalized = normalizeDnsConfig(config);
|
|
36
|
+
|
|
37
|
+
expect(normalized).toEqual({
|
|
38
|
+
'example.com': { provider: 'hostinger', ttl: 300 },
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should pass through multi-domain config unchanged', () => {
|
|
43
|
+
const config = {
|
|
44
|
+
'example.com': { provider: 'hostinger' },
|
|
45
|
+
'example.dev': { provider: 'route53' },
|
|
46
|
+
};
|
|
47
|
+
const normalized = normalizeDnsConfig(config);
|
|
48
|
+
|
|
49
|
+
expect(normalized).toBe(config);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('findRootDomain', () => {
|
|
54
|
+
const dnsConfig = {
|
|
55
|
+
'traflabs.io': { provider: 'hostinger' as const },
|
|
56
|
+
'geekmidas.com': { provider: 'route53' as const },
|
|
57
|
+
'sub.geekmidas.com': { provider: 'manual' as const },
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
it('should find exact domain match', () => {
|
|
61
|
+
expect(findRootDomain('traflabs.io', dnsConfig)).toBe('traflabs.io');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should find root domain for subdomain', () => {
|
|
65
|
+
expect(findRootDomain('api.traflabs.io', dnsConfig)).toBe('traflabs.io');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should find root domain for nested subdomain', () => {
|
|
69
|
+
expect(findRootDomain('staging.api.traflabs.io', dnsConfig)).toBe(
|
|
70
|
+
'traflabs.io',
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should prefer more specific domain', () => {
|
|
75
|
+
expect(findRootDomain('api.sub.geekmidas.com', dnsConfig)).toBe(
|
|
76
|
+
'sub.geekmidas.com',
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should return null for unknown domain', () => {
|
|
81
|
+
expect(findRootDomain('unknown.com', dnsConfig)).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should return null for domain that is prefix but not subdomain', () => {
|
|
85
|
+
// 'exampletraflabs.io' should not match 'traflabs.io'
|
|
86
|
+
expect(findRootDomain('exampletraflabs.io', dnsConfig)).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('groupHostnamesByDomain', () => {
|
|
91
|
+
const dnsConfig = {
|
|
92
|
+
'traflabs.io': { provider: 'hostinger' as const },
|
|
93
|
+
'geekmidas.com': { provider: 'route53' as const },
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
it('should group hostnames by their root domain', () => {
|
|
97
|
+
const appHostnames = new Map([
|
|
98
|
+
['api', 'api.traflabs.io'],
|
|
99
|
+
['web', 'web.traflabs.io'],
|
|
100
|
+
['docs', 'docs.geekmidas.com'],
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
const grouped = groupHostnamesByDomain(appHostnames, dnsConfig);
|
|
104
|
+
|
|
105
|
+
expect(grouped.size).toBe(2);
|
|
106
|
+
expect(grouped.get('traflabs.io')?.size).toBe(2);
|
|
107
|
+
expect(grouped.get('traflabs.io')?.get('api')).toBe('api.traflabs.io');
|
|
108
|
+
expect(grouped.get('traflabs.io')?.get('web')).toBe('web.traflabs.io');
|
|
109
|
+
expect(grouped.get('geekmidas.com')?.size).toBe(1);
|
|
110
|
+
expect(grouped.get('geekmidas.com')?.get('docs')).toBe(
|
|
111
|
+
'docs.geekmidas.com',
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should skip hostnames without matching domain', () => {
|
|
116
|
+
const appHostnames = new Map([
|
|
117
|
+
['api', 'api.traflabs.io'],
|
|
118
|
+
['unknown', 'api.unknown.com'],
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
const grouped = groupHostnamesByDomain(appHostnames, dnsConfig);
|
|
122
|
+
|
|
123
|
+
expect(grouped.size).toBe(1);
|
|
124
|
+
expect(grouped.get('traflabs.io')?.size).toBe(1);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('extractSubdomain', () => {
|
|
129
|
+
it('should extract single-level subdomain', () => {
|
|
130
|
+
expect(extractSubdomain('api.example.com', 'example.com')).toBe('api');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should extract multi-level subdomain', () => {
|
|
134
|
+
expect(extractSubdomain('staging.api.example.com', 'example.com')).toBe(
|
|
135
|
+
'staging.api',
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should return @ for root domain', () => {
|
|
140
|
+
expect(extractSubdomain('example.com', 'example.com')).toBe('@');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should throw for hostname not under root domain', () => {
|
|
144
|
+
expect(() => extractSubdomain('api.other.com', 'example.com')).toThrow(
|
|
145
|
+
'not under root domain',
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('generateRequiredRecords', () => {
|
|
151
|
+
it('should generate A records for all app hostnames', () => {
|
|
152
|
+
const appHostnames = new Map([
|
|
153
|
+
['api', 'api.example.com'],
|
|
154
|
+
['web', 'web.example.com'],
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
const records = generateRequiredRecords(
|
|
158
|
+
appHostnames,
|
|
159
|
+
'example.com',
|
|
160
|
+
'1.2.3.4',
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
expect(records).toHaveLength(2);
|
|
164
|
+
expect(records[0]).toMatchObject({
|
|
165
|
+
hostname: 'api.example.com',
|
|
166
|
+
subdomain: 'api',
|
|
167
|
+
type: 'A',
|
|
168
|
+
value: '1.2.3.4',
|
|
169
|
+
appName: 'api',
|
|
170
|
+
});
|
|
171
|
+
expect(records[1]).toMatchObject({
|
|
172
|
+
hostname: 'web.example.com',
|
|
173
|
+
subdomain: 'web',
|
|
174
|
+
type: 'A',
|
|
175
|
+
value: '1.2.3.4',
|
|
176
|
+
appName: 'web',
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should handle nested subdomains', () => {
|
|
181
|
+
const appHostnames = new Map([['api', 'staging.api.example.com']]);
|
|
182
|
+
|
|
183
|
+
const records = generateRequiredRecords(
|
|
184
|
+
appHostnames,
|
|
185
|
+
'example.com',
|
|
186
|
+
'1.2.3.4',
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
expect(records[0]?.subdomain).toBe('staging.api');
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it, vi
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { createEmptyState, type DokployStageState } from '../state';
|
|
3
3
|
|
|
4
4
|
// Mock dns/promises lookup
|
|
@@ -8,7 +8,7 @@ vi.mock('node:dns/promises', () => ({
|
|
|
8
8
|
|
|
9
9
|
// Import after mocking
|
|
10
10
|
import { lookup } from 'node:dns/promises';
|
|
11
|
-
import {
|
|
11
|
+
import { resolveHostnameToIp, verifyDnsRecords } from '../dns/index';
|
|
12
12
|
|
|
13
13
|
describe('resolveHostnameToIp', () => {
|
|
14
14
|
const mockLookup = vi.mocked(lookup);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import type { NormalizedAppConfig } from '../../workspace/types';
|
|
3
3
|
import {
|
|
4
4
|
AUTO_SUPPORTED_VARS,
|
|
@@ -151,7 +151,11 @@ describe('buildRedisUrl', () => {
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
it('should encode special characters in password', () => {
|
|
154
|
-
const redis = {
|
|
154
|
+
const redis = {
|
|
155
|
+
host: 'redis.example.com',
|
|
156
|
+
port: 6380,
|
|
157
|
+
password: 'p@ss:word',
|
|
158
|
+
};
|
|
155
159
|
|
|
156
160
|
const url = buildRedisUrl(redis);
|
|
157
161
|
|
|
@@ -194,15 +198,15 @@ describe('resolveEnvVar', () => {
|
|
|
194
198
|
it('should resolve NODE_ENV to production for all stages (deployed apps)', () => {
|
|
195
199
|
// NODE_ENV is always 'production' for deployed apps
|
|
196
200
|
// gkm dev handles development mode separately
|
|
197
|
-
expect(
|
|
198
|
-
'production',
|
|
199
|
-
);
|
|
201
|
+
expect(
|
|
202
|
+
resolveEnvVar('NODE_ENV', createContext({ stage: 'production' })),
|
|
203
|
+
).toBe('production');
|
|
200
204
|
expect(resolveEnvVar('NODE_ENV', createContext({ stage: 'staging' }))).toBe(
|
|
201
205
|
'production',
|
|
202
206
|
);
|
|
203
|
-
expect(
|
|
204
|
-
'
|
|
205
|
-
);
|
|
207
|
+
expect(
|
|
208
|
+
resolveEnvVar('NODE_ENV', createContext({ stage: 'development' })),
|
|
209
|
+
).toBe('production');
|
|
206
210
|
});
|
|
207
211
|
|
|
208
212
|
it('should resolve DATABASE_URL when credentials and postgres are provided', () => {
|
|
@@ -243,7 +247,9 @@ describe('resolveEnvVar', () => {
|
|
|
243
247
|
it('should resolve BETTER_AUTH_URL from app hostname', () => {
|
|
244
248
|
const context = createContext({ appHostname: 'auth.myapp.com' });
|
|
245
249
|
|
|
246
|
-
expect(resolveEnvVar('BETTER_AUTH_URL', context)).toBe(
|
|
250
|
+
expect(resolveEnvVar('BETTER_AUTH_URL', context)).toBe(
|
|
251
|
+
'https://auth.myapp.com',
|
|
252
|
+
);
|
|
247
253
|
});
|
|
248
254
|
|
|
249
255
|
it('should resolve BETTER_AUTH_SECRET by generating and storing secret', () => {
|
|
@@ -269,7 +275,9 @@ describe('resolveEnvVar', () => {
|
|
|
269
275
|
it('should return undefined for BETTER_AUTH_TRUSTED_ORIGINS when no frontend URLs', () => {
|
|
270
276
|
const context = createContext({ frontendUrls: [] });
|
|
271
277
|
|
|
272
|
-
expect(
|
|
278
|
+
expect(
|
|
279
|
+
resolveEnvVar('BETTER_AUTH_TRUSTED_ORIGINS', context),
|
|
280
|
+
).toBeUndefined();
|
|
273
281
|
});
|
|
274
282
|
|
|
275
283
|
it('should resolve GKM_MASTER_KEY from context', () => {
|
|
@@ -366,7 +374,10 @@ describe('resolveEnvVars', () => {
|
|
|
366
374
|
postgres: { host: 'postgres', port: 5432, database: 'mydb' },
|
|
367
375
|
});
|
|
368
376
|
|
|
369
|
-
const result = resolveEnvVars(
|
|
377
|
+
const result = resolveEnvVars(
|
|
378
|
+
['PORT', 'NODE_ENV', 'DATABASE_URL'],
|
|
379
|
+
context,
|
|
380
|
+
);
|
|
370
381
|
|
|
371
382
|
expect(result.resolved).toEqual({
|
|
372
383
|
PORT: '3000',
|
|
@@ -400,12 +411,20 @@ describe('resolveEnvVars', () => {
|
|
|
400
411
|
|
|
401
412
|
describe('formatMissingVarsError', () => {
|
|
402
413
|
it('should format error message with missing variables', () => {
|
|
403
|
-
const error = formatMissingVarsError(
|
|
414
|
+
const error = formatMissingVarsError(
|
|
415
|
+
'api',
|
|
416
|
+
['DATABASE_URL', 'REDIS_URL'],
|
|
417
|
+
'production',
|
|
418
|
+
);
|
|
404
419
|
|
|
405
|
-
expect(error).toContain(
|
|
420
|
+
expect(error).toContain(
|
|
421
|
+
'Deployment failed: api is missing required environment variables',
|
|
422
|
+
);
|
|
406
423
|
expect(error).toContain('- DATABASE_URL');
|
|
407
424
|
expect(error).toContain('- REDIS_URL');
|
|
408
|
-
expect(error).toContain(
|
|
425
|
+
expect(error).toContain(
|
|
426
|
+
'gkm secrets:set <VAR_NAME> <value> --stage production',
|
|
427
|
+
);
|
|
409
428
|
});
|
|
410
429
|
|
|
411
430
|
it('should handle single missing variable', () => {
|
|
@@ -452,7 +471,10 @@ describe('validateEnvVars', () => {
|
|
|
452
471
|
it('should return valid=false when vars are missing', () => {
|
|
453
472
|
const context = createContext();
|
|
454
473
|
|
|
455
|
-
const result = validateEnvVars(
|
|
474
|
+
const result = validateEnvVars(
|
|
475
|
+
['PORT', 'DATABASE_URL', 'CUSTOM_VAR'],
|
|
476
|
+
context,
|
|
477
|
+
);
|
|
456
478
|
|
|
457
479
|
expect(result.valid).toBe(false);
|
|
458
480
|
expect(result.missing).toEqual(['DATABASE_URL', 'CUSTOM_VAR']);
|
|
@@ -491,11 +491,7 @@ describe('sniffAppEnvironment with envParser apps', () => {
|
|
|
491
491
|
envParser: './valid-env-parser.ts#envParser',
|
|
492
492
|
};
|
|
493
493
|
|
|
494
|
-
const result = await sniffAppEnvironment(
|
|
495
|
-
app,
|
|
496
|
-
'api',
|
|
497
|
-
envParserFixturesPath,
|
|
498
|
-
);
|
|
494
|
+
const result = await sniffAppEnvironment(app, 'api', envParserFixturesPath);
|
|
499
495
|
|
|
500
496
|
expect(result.appName).toBe('api');
|
|
501
497
|
expect(result.requiredEnvVars).toContain('PORT');
|
|
@@ -514,11 +510,7 @@ describe('sniffAppEnvironment with envParser apps', () => {
|
|
|
514
510
|
requiredEnv: ['CUSTOM_VAR'], // Should use this instead
|
|
515
511
|
};
|
|
516
512
|
|
|
517
|
-
const result = await sniffAppEnvironment(
|
|
518
|
-
app,
|
|
519
|
-
'api',
|
|
520
|
-
envParserFixturesPath,
|
|
521
|
-
);
|
|
513
|
+
const result = await sniffAppEnvironment(app, 'api', envParserFixturesPath);
|
|
522
514
|
|
|
523
515
|
expect(result.requiredEnvVars).toEqual(['CUSTOM_VAR']);
|
|
524
516
|
// Should NOT contain the sniffed vars
|
|
@@ -663,11 +655,7 @@ describe('sniffAppEnvironment with route-based apps', () => {
|
|
|
663
655
|
envParser: './src/config/env#envParser', // Should be ignored when routes exist
|
|
664
656
|
};
|
|
665
657
|
|
|
666
|
-
const result = await sniffAppEnvironment(
|
|
667
|
-
app,
|
|
668
|
-
'api',
|
|
669
|
-
routeAppsFixturesPath,
|
|
670
|
-
);
|
|
658
|
+
const result = await sniffAppEnvironment(app, 'api', routeAppsFixturesPath);
|
|
671
659
|
|
|
672
660
|
expect(result.appName).toBe('api');
|
|
673
661
|
expect(result.requiredEnvVars).toContain('DATABASE_URL');
|
|
@@ -686,11 +674,7 @@ describe('sniffAppEnvironment with route-based apps', () => {
|
|
|
686
674
|
requiredEnv: ['CUSTOM_VAR'], // Should use this instead
|
|
687
675
|
};
|
|
688
676
|
|
|
689
|
-
const result = await sniffAppEnvironment(
|
|
690
|
-
app,
|
|
691
|
-
'api',
|
|
692
|
-
routeAppsFixturesPath,
|
|
693
|
-
);
|
|
677
|
+
const result = await sniffAppEnvironment(app, 'api', routeAppsFixturesPath);
|
|
694
678
|
|
|
695
679
|
expect(result.requiredEnvVars).toEqual(['CUSTOM_VAR']);
|
|
696
680
|
// Should NOT contain the sniffed vars
|