@codapult/cli 0.3.0 → 0.4.1
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/commands/config-show.js +76 -69
- package/dist/commands/doctor.js +27 -18
- package/dist/commands/setup.js +164 -21
- package/dist/mcp/resources.js +1 -1
- package/dist/mcp/tools/project.js +9 -18
- package/dist/mcp/tools/project.test.js +15 -6
- package/dist/utils/env-config.d.ts +65 -0
- package/dist/utils/env-config.js +211 -0
- package/dist/utils/patchers.js +1 -1
- package/package.json +1 -1
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { findProjectRoot, readJsonFile } from '../utils/project.js';
|
|
4
|
+
import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, FEATURE_ENV, } from '../utils/env-config.js';
|
|
4
5
|
import { heading, success, fail, info, dim, label } from '../utils/ui.js';
|
|
6
|
+
/** Extracts a quoted string from a TS object literal: `field: 'value'` or `field: "value"`. */
|
|
5
7
|
function extractTsObjectField(content, field) {
|
|
6
|
-
const regex = new RegExp(
|
|
8
|
+
const regex = new RegExp(`\\b${field}\\s*:\\s*['"\`]([^'"\`]+)['"\`]`);
|
|
7
9
|
const match = regex.exec(content);
|
|
8
10
|
return match?.[1] ?? null;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const regex =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
result[match[1]] = match[2] === 'true';
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
12
|
+
/** Extracts a numeric literal: `field: 123` or `field: 0.5`. */
|
|
13
|
+
function extractTsNumericField(content, field) {
|
|
14
|
+
const regex = new RegExp(`\\b${field}\\s*:\\s*([\\d.]+)`);
|
|
15
|
+
const match = regex.exec(content);
|
|
16
|
+
return match?.[1] ?? null;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
18
|
+
/** Extracts a boolean literal: `field: true|false`. */
|
|
19
|
+
function extractTsBoolField(content, field) {
|
|
20
|
+
const regex = new RegExp(`\\b${field}\\s*:\\s*(true|false)`);
|
|
21
|
+
const match = regex.exec(content);
|
|
22
|
+
return match ? match[1] === 'true' : null;
|
|
23
23
|
}
|
|
24
24
|
export function configShowCommand() {
|
|
25
25
|
const root = findProjectRoot();
|
|
@@ -36,6 +36,8 @@ export function configShowCommand() {
|
|
|
36
36
|
label('Version', typeof pkg.version === 'string' ? pkg.version : 'unknown');
|
|
37
37
|
}
|
|
38
38
|
console.log();
|
|
39
|
+
const envPath = resolve(root, '.env.local');
|
|
40
|
+
const envContent = existsSync(envPath) ? readFileSync(envPath, 'utf-8') : '';
|
|
39
41
|
// --- App config (src/config/app.ts) ---
|
|
40
42
|
const appConfigPath = resolve(root, 'src/config/app.ts');
|
|
41
43
|
if (existsSync(appConfigPath)) {
|
|
@@ -43,73 +45,78 @@ export function configShowCommand() {
|
|
|
43
45
|
info('Brand');
|
|
44
46
|
const name = extractTsObjectField(content, 'name');
|
|
45
47
|
const description = extractTsObjectField(content, 'description');
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
+
const logo = extractTsObjectField(content, 'logo');
|
|
49
|
+
const favicon = extractTsObjectField(content, 'favicon');
|
|
48
50
|
if (name)
|
|
49
51
|
label(' Name', name);
|
|
50
52
|
if (description)
|
|
51
53
|
label(' Description', description);
|
|
52
|
-
if (
|
|
53
|
-
label('
|
|
54
|
-
if (
|
|
55
|
-
label('
|
|
54
|
+
if (logo)
|
|
55
|
+
label(' Logo', logo);
|
|
56
|
+
if (favicon)
|
|
57
|
+
label(' Favicon', favicon);
|
|
56
58
|
console.log();
|
|
57
|
-
info('
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
success(f);
|
|
65
|
-
}
|
|
66
|
-
if (disabled.length > 0) {
|
|
67
|
-
for (const f of disabled)
|
|
68
|
-
dim(` ○ ${f}`);
|
|
69
|
-
}
|
|
59
|
+
info('Company');
|
|
60
|
+
const contactEmail = extractTsObjectField(content, 'contactEmail');
|
|
61
|
+
const githubUrl = extractTsObjectField(content, 'githubUrl');
|
|
62
|
+
if (contactEmail)
|
|
63
|
+
label(' Contact email', contactEmail);
|
|
64
|
+
if (githubUrl)
|
|
65
|
+
label(' GitHub', githubUrl);
|
|
70
66
|
console.log();
|
|
71
|
-
info('
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
.split(',')
|
|
85
|
-
.map((s) => s.trim().replace(/['"]/g, ''))
|
|
86
|
-
.filter(Boolean);
|
|
87
|
-
label(' OAuth providers', providers.join(', ') || 'none');
|
|
88
|
-
}
|
|
67
|
+
info('AI');
|
|
68
|
+
const defaultModel = extractTsObjectField(content, 'defaultModel');
|
|
69
|
+
const ragEnabled = extractTsBoolField(content, 'ragEnabled');
|
|
70
|
+
const ragMaxChunks = extractTsNumericField(content, 'ragMaxChunks');
|
|
71
|
+
const ragMinScore = extractTsNumericField(content, 'ragMinScore');
|
|
72
|
+
if (defaultModel)
|
|
73
|
+
label(' Default model', defaultModel);
|
|
74
|
+
if (ragEnabled !== null)
|
|
75
|
+
label(' RAG', ragEnabled ? 'enabled' : 'disabled');
|
|
76
|
+
if (ragMaxChunks)
|
|
77
|
+
label(' RAG max chunks', ragMaxChunks);
|
|
78
|
+
if (ragMinScore)
|
|
79
|
+
label(' RAG min score', ragMinScore);
|
|
89
80
|
}
|
|
90
81
|
else {
|
|
91
82
|
dim('src/config/app.ts not found — run `codapult setup`');
|
|
92
83
|
}
|
|
93
84
|
console.log();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const envContent = readFileSync(envPath, 'utf-8');
|
|
99
|
-
const adapters = [
|
|
100
|
-
['AUTH_PROVIDER', 'Auth'],
|
|
101
|
-
['PAYMENT_PROVIDER', 'Payments'],
|
|
102
|
-
['STORAGE_PROVIDER', 'Storage'],
|
|
103
|
-
['NOTIFICATION_TRANSPORT', 'Notifications'],
|
|
104
|
-
['JOB_PROVIDER', 'Background jobs'],
|
|
105
|
-
];
|
|
106
|
-
for (const [key, name] of adapters) {
|
|
107
|
-
const value = extractEnvValue(envContent, key);
|
|
108
|
-
label(` ${name}`, value ?? 'not set');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
dim('.env.local not found');
|
|
85
|
+
if (!existsSync(envPath)) {
|
|
86
|
+
dim('.env.local not found — adapters / features / auth methods unavailable');
|
|
87
|
+
console.log();
|
|
88
|
+
return;
|
|
113
89
|
}
|
|
90
|
+
// --- Adapters (from .env.local) ---
|
|
91
|
+
info('Adapters');
|
|
92
|
+
const adapters = getAdapters(envContent);
|
|
93
|
+
label(' Database', adapters.database);
|
|
94
|
+
label(' Auth', adapters.auth);
|
|
95
|
+
label(' Payments', adapters.payments);
|
|
96
|
+
label(' Storage', adapters.storage);
|
|
97
|
+
label(' Background jobs', adapters.jobs);
|
|
98
|
+
label(' Notifications', adapters.notifications);
|
|
99
|
+
label(' Embedding', adapters.embedding);
|
|
100
|
+
label(' Vector store', adapters.vectorStore);
|
|
101
|
+
console.log();
|
|
102
|
+
// --- Auth methods (from .env.local) ---
|
|
103
|
+
info('Auth methods');
|
|
104
|
+
const authMethods = getAuthMethods(envContent);
|
|
105
|
+
label(' Magic Link', authMethods.magicLink ? 'enabled' : 'disabled');
|
|
106
|
+
label(' Passkeys', authMethods.passkeys ? 'enabled' : 'disabled');
|
|
107
|
+
label(' 2FA (TOTP)', authMethods.twoFactor ? 'enabled' : 'disabled');
|
|
108
|
+
const oauth = getOauthProviders(envContent);
|
|
109
|
+
label(' OAuth providers', oauth.length > 0 ? oauth.join(', ') : 'none');
|
|
110
|
+
console.log();
|
|
111
|
+
// --- Feature toggles (from .env.local + ENABLE_* defaults) ---
|
|
112
|
+
info('Features');
|
|
113
|
+
const features = getFeatures(envContent);
|
|
114
|
+
const featureKeys = Object.keys(FEATURE_ENV);
|
|
115
|
+
const enabled = featureKeys.filter((k) => features[k]);
|
|
116
|
+
const disabled = featureKeys.filter((k) => !features[k]);
|
|
117
|
+
for (const f of enabled)
|
|
118
|
+
success(f);
|
|
119
|
+
for (const f of disabled)
|
|
120
|
+
dim(` ○ ${f}`);
|
|
114
121
|
console.log();
|
|
115
122
|
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -4,6 +4,7 @@ import { execSync } from 'node:child_process';
|
|
|
4
4
|
import { findProjectRoot, readJsonFile } from '../utils/project.js';
|
|
5
5
|
import { resolveManifest } from '../utils/manifest.js';
|
|
6
6
|
import { findPageConflicts, findPageBackups } from '../utils/patchers.js';
|
|
7
|
+
import { findProviderIssues, getAdapters, readEnvVar } from '../utils/env-config.js';
|
|
7
8
|
import { heading, success, fail, warn, info, dim, label } from '../utils/ui.js';
|
|
8
9
|
function checkExists(root, path, description) {
|
|
9
10
|
const exists = existsSync(resolve(root, path));
|
|
@@ -15,17 +16,6 @@ function checkExists(root, path, description) {
|
|
|
15
16
|
}
|
|
16
17
|
return exists;
|
|
17
18
|
}
|
|
18
|
-
function checkEnvVar(envContent, key, description) {
|
|
19
|
-
const regex = new RegExp(`^${key}=.+`, 'm');
|
|
20
|
-
const found = regex.test(envContent);
|
|
21
|
-
if (found) {
|
|
22
|
-
success(description);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
warn(`${description} — not set: ${key}`);
|
|
26
|
-
}
|
|
27
|
-
return found;
|
|
28
|
-
}
|
|
29
19
|
function tryExec(cmd, cwd) {
|
|
30
20
|
try {
|
|
31
21
|
return execSync(cmd, { cwd, encoding: 'utf-8', stdio: 'pipe' }).trim();
|
|
@@ -72,14 +62,33 @@ export function doctorCommand() {
|
|
|
72
62
|
else {
|
|
73
63
|
success('.env.local exists');
|
|
74
64
|
const envContent = readFileSync(envPath, 'utf-8');
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
const adapters = getAdapters(envContent);
|
|
66
|
+
label(' DB_PROVIDER', adapters.database);
|
|
67
|
+
label(' AUTH_PROVIDER', adapters.auth);
|
|
68
|
+
label(' PAYMENT_PROVIDER', adapters.payments);
|
|
69
|
+
label(' STORAGE_PROVIDER', adapters.storage);
|
|
70
|
+
label(' JOB_PROVIDER', adapters.jobs);
|
|
71
|
+
label(' NOTIFICATION_TRANSPORT', adapters.notifications);
|
|
72
|
+
const providerIssues = findProviderIssues(envContent);
|
|
73
|
+
if (providerIssues.length === 0) {
|
|
74
|
+
success('All provider-conditional env vars are set');
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
for (const i of providerIssues) {
|
|
78
|
+
if (i.severity === 'error') {
|
|
79
|
+
fail(`${i.key}: ${i.message}`);
|
|
80
|
+
issues += 1;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
warn(`${i.key}: ${i.message}`);
|
|
84
|
+
warnings += 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!readEnvVar(envContent, 'NEXT_PUBLIC_APP_URL')) {
|
|
89
|
+
warn('NEXT_PUBLIC_APP_URL not set — defaults to http://localhost:3000');
|
|
82
90
|
warnings += 1;
|
|
91
|
+
}
|
|
83
92
|
}
|
|
84
93
|
console.log();
|
|
85
94
|
// --- Dependencies ---
|
package/dist/commands/setup.js
CHANGED
|
@@ -30,6 +30,8 @@ async function selectPrompt(iface, question, options) {
|
|
|
30
30
|
// Built-in presets for non-interactive (CI/CD) setup via --preset flag.
|
|
31
31
|
// ---------------------------------------------------------------------------
|
|
32
32
|
const BUILT_IN_PRESETS = {
|
|
33
|
+
// Showcase / marketing-only site: navbar shows only Pricing, Plugins, Docs.
|
|
34
|
+
// `enableHelpCenter` stays true (powers /docs).
|
|
33
35
|
marketing: {
|
|
34
36
|
authProvider: 'none',
|
|
35
37
|
enableAuth: false,
|
|
@@ -48,6 +50,16 @@ const BUILT_IN_PRESETS = {
|
|
|
48
50
|
enableDripCampaigns: false,
|
|
49
51
|
enableApiDocs: false,
|
|
50
52
|
enableChangelog: false,
|
|
53
|
+
enableBlog: false,
|
|
54
|
+
enableWaitlist: false,
|
|
55
|
+
enableFeatureRequests: false,
|
|
56
|
+
enableWebhooks: false,
|
|
57
|
+
enableAuditLog: false,
|
|
58
|
+
enableReports: false,
|
|
59
|
+
enableBranding: false,
|
|
60
|
+
enableTwoFactor: false,
|
|
61
|
+
// Plugins page stays in marketing navbar by default — preset keeps the
|
|
62
|
+
// feature on. Override with `marketing;enablePlugins=false` to drop it.
|
|
51
63
|
},
|
|
52
64
|
demo: {
|
|
53
65
|
authProvider: 'better-auth',
|
|
@@ -81,6 +93,12 @@ const DEFAULT_CONFIG = {
|
|
|
81
93
|
enableAnalytics: true,
|
|
82
94
|
enableChangelog: true,
|
|
83
95
|
enableRAG: true,
|
|
96
|
+
enableWebhooks: true,
|
|
97
|
+
enableAuditLog: true,
|
|
98
|
+
enableReports: true,
|
|
99
|
+
enableBranding: true,
|
|
100
|
+
enableTwoFactor: true,
|
|
101
|
+
enablePlugins: true,
|
|
84
102
|
};
|
|
85
103
|
function parsePresetValue(raw) {
|
|
86
104
|
const parts = raw
|
|
@@ -121,15 +139,19 @@ function resolvePreset(raw) {
|
|
|
121
139
|
}
|
|
122
140
|
return config;
|
|
123
141
|
}
|
|
142
|
+
// All app-router paths are under `src/app/[locale]/...` (next-intl).
|
|
143
|
+
// API routes (`src/app/api/...`) and `src/lib`/`src/components` paths
|
|
144
|
+
// are NOT under [locale].
|
|
145
|
+
const APP = 'src/app/[locale]';
|
|
124
146
|
const MODULE_REMOVALS = [
|
|
125
147
|
{
|
|
126
148
|
key: 'enableAuth',
|
|
127
149
|
paths: [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
150
|
+
`${APP}/(auth)`,
|
|
151
|
+
`${APP}/(dashboard)`,
|
|
152
|
+
`${APP}/admin`,
|
|
153
|
+
`${APP}/invite`,
|
|
131
154
|
'src/app/api/auth',
|
|
132
|
-
'src/app/invite',
|
|
133
155
|
'src/lib/auth/better-auth.ts',
|
|
134
156
|
'src/lib/auth/kinde.ts',
|
|
135
157
|
'src/components/auth',
|
|
@@ -141,13 +163,13 @@ const MODULE_REMOVALS = [
|
|
|
141
163
|
},
|
|
142
164
|
{
|
|
143
165
|
key: 'enableAI',
|
|
144
|
-
paths: [
|
|
166
|
+
paths: [`${APP}/(dashboard)/dashboard/ai-chat`, 'src/app/api/chat', 'src/components/ai'],
|
|
145
167
|
label: 'AI Chat',
|
|
146
168
|
},
|
|
147
169
|
{
|
|
148
170
|
key: 'enableBlog',
|
|
149
171
|
paths: [
|
|
150
|
-
|
|
172
|
+
`${APP}/(marketing)/blog`,
|
|
151
173
|
'src/components/blog',
|
|
152
174
|
'src/lib/blog',
|
|
153
175
|
'content/blog',
|
|
@@ -158,8 +180,8 @@ const MODULE_REMOVALS = [
|
|
|
158
180
|
{
|
|
159
181
|
key: 'enableTeams',
|
|
160
182
|
paths: [
|
|
161
|
-
|
|
162
|
-
|
|
183
|
+
`${APP}/(dashboard)/dashboard/teams`,
|
|
184
|
+
`${APP}/invite`,
|
|
163
185
|
'src/components/dashboard/TeamSwitcher.tsx',
|
|
164
186
|
'src/components/dashboard/TeamSettings.tsx',
|
|
165
187
|
'src/components/dashboard/AcceptInvitationButton.tsx',
|
|
@@ -171,10 +193,10 @@ const MODULE_REMOVALS = [
|
|
|
171
193
|
{
|
|
172
194
|
key: 'enableWaitlist',
|
|
173
195
|
paths: [
|
|
174
|
-
|
|
196
|
+
`${APP}/(marketing)/waitlist`,
|
|
197
|
+
`${APP}/admin/waitlist`,
|
|
175
198
|
'src/components/marketing/WaitlistForm.tsx',
|
|
176
199
|
'src/lib/actions/waitlist.ts',
|
|
177
|
-
'src/app/admin/waitlist',
|
|
178
200
|
],
|
|
179
201
|
label: 'Waitlist',
|
|
180
202
|
},
|
|
@@ -186,10 +208,10 @@ const MODULE_REMOVALS = [
|
|
|
186
208
|
{
|
|
187
209
|
key: 'enableSSO',
|
|
188
210
|
paths: [
|
|
211
|
+
`${APP}/admin/sso`,
|
|
189
212
|
'src/lib/sso',
|
|
190
213
|
'src/app/api/auth/sso',
|
|
191
214
|
'src/app/api/admin/sso',
|
|
192
|
-
'src/app/admin/sso',
|
|
193
215
|
'src/components/admin/SSOManager.tsx',
|
|
194
216
|
],
|
|
195
217
|
label: 'Enterprise SSO',
|
|
@@ -197,8 +219,8 @@ const MODULE_REMOVALS = [
|
|
|
197
219
|
{
|
|
198
220
|
key: 'enableApiDocs',
|
|
199
221
|
paths: [
|
|
222
|
+
`${APP}/(marketing)/docs/api`,
|
|
200
223
|
'src/lib/api-docs.ts',
|
|
201
|
-
'src/app/(marketing)/docs/api',
|
|
202
224
|
'src/components/docs/ApiReference.tsx',
|
|
203
225
|
],
|
|
204
226
|
label: 'API Docs',
|
|
@@ -206,19 +228,28 @@ const MODULE_REMOVALS = [
|
|
|
206
228
|
{
|
|
207
229
|
key: 'enableHelpCenter',
|
|
208
230
|
paths: [
|
|
231
|
+
`${APP}/(marketing)/docs`,
|
|
209
232
|
'src/lib/docs',
|
|
210
|
-
'src/app/(marketing)/docs',
|
|
211
233
|
'src/components/docs/HelpDocSearch.tsx',
|
|
212
234
|
'content/docs',
|
|
213
235
|
],
|
|
214
236
|
label: 'Documentation',
|
|
215
237
|
},
|
|
238
|
+
{
|
|
239
|
+
key: 'enableChangelog',
|
|
240
|
+
paths: [
|
|
241
|
+
`${APP}/(marketing)/changelog`,
|
|
242
|
+
'src/app/api/changelog',
|
|
243
|
+
'src/components/dashboard/ChangelogWidget.tsx',
|
|
244
|
+
],
|
|
245
|
+
label: 'Changelog',
|
|
246
|
+
},
|
|
216
247
|
{
|
|
217
248
|
key: 'enableExperiments',
|
|
218
249
|
paths: [
|
|
250
|
+
`${APP}/admin/experiments`,
|
|
219
251
|
'src/lib/experiments',
|
|
220
252
|
'src/app/api/admin/experiments',
|
|
221
|
-
'src/app/admin/experiments',
|
|
222
253
|
'src/components/admin/ExperimentManager.tsx',
|
|
223
254
|
],
|
|
224
255
|
label: 'A/B Testing',
|
|
@@ -226,19 +257,19 @@ const MODULE_REMOVALS = [
|
|
|
226
257
|
{
|
|
227
258
|
key: 'enableFeatureRequests',
|
|
228
259
|
paths: [
|
|
260
|
+
`${APP}/(marketing)/feature-requests`,
|
|
229
261
|
'src/lib/feature-requests',
|
|
230
262
|
'src/app/api/feature-requests',
|
|
231
|
-
'src/
|
|
232
|
-
'src/components/feature-requests/FeatureBoard.tsx',
|
|
263
|
+
'src/components/feature-requests',
|
|
233
264
|
],
|
|
234
265
|
label: 'Feature Requests',
|
|
235
266
|
},
|
|
236
267
|
{
|
|
237
268
|
key: 'enableConnect',
|
|
238
269
|
paths: [
|
|
270
|
+
`${APP}/(dashboard)/dashboard/connect`,
|
|
239
271
|
'src/lib/payments/connect.ts',
|
|
240
272
|
'src/app/api/connect',
|
|
241
|
-
'src/app/(dashboard)/dashboard/connect',
|
|
242
273
|
'src/components/dashboard/ConnectDashboard.tsx',
|
|
243
274
|
],
|
|
244
275
|
label: 'Stripe Connect',
|
|
@@ -252,9 +283,9 @@ const MODULE_REMOVALS = [
|
|
|
252
283
|
{
|
|
253
284
|
key: 'enableDripCampaigns',
|
|
254
285
|
paths: [
|
|
286
|
+
`${APP}/admin/drip-campaigns`,
|
|
255
287
|
'src/lib/drip-campaigns',
|
|
256
288
|
'src/app/api/admin/drip-campaigns',
|
|
257
|
-
'src/app/admin/drip-campaigns',
|
|
258
289
|
'src/components/admin/DripCampaignManager.tsx',
|
|
259
290
|
],
|
|
260
291
|
label: 'Drip Campaigns',
|
|
@@ -262,18 +293,20 @@ const MODULE_REMOVALS = [
|
|
|
262
293
|
{
|
|
263
294
|
key: 'enableOnboarding',
|
|
264
295
|
paths: [
|
|
296
|
+
`${APP}/(dashboard)/dashboard/onboarding`,
|
|
265
297
|
'src/lib/onboarding',
|
|
266
298
|
'src/app/api/onboarding',
|
|
267
299
|
'src/components/dashboard/OnboardingTour.tsx',
|
|
300
|
+
'src/components/dashboard/OnboardingForm.tsx',
|
|
268
301
|
],
|
|
269
302
|
label: 'Onboarding Tours',
|
|
270
303
|
},
|
|
271
304
|
{
|
|
272
305
|
key: 'enableWorkflows',
|
|
273
306
|
paths: [
|
|
307
|
+
`${APP}/(dashboard)/dashboard/workflows`,
|
|
274
308
|
'src/lib/workflows',
|
|
275
309
|
'src/app/api/workflows',
|
|
276
|
-
'src/app/(dashboard)/dashboard/workflows',
|
|
277
310
|
'src/components/dashboard/WorkflowBuilder.tsx',
|
|
278
311
|
],
|
|
279
312
|
label: 'Workflow Automation',
|
|
@@ -281,9 +314,9 @@ const MODULE_REMOVALS = [
|
|
|
281
314
|
{
|
|
282
315
|
key: 'enableReferrals',
|
|
283
316
|
paths: [
|
|
317
|
+
`${APP}/(dashboard)/dashboard/referrals`,
|
|
284
318
|
'src/lib/referrals',
|
|
285
319
|
'src/app/api/referrals',
|
|
286
|
-
'src/app/(dashboard)/dashboard/referrals',
|
|
287
320
|
'src/components/dashboard/ReferralDashboard.tsx',
|
|
288
321
|
],
|
|
289
322
|
label: 'Referral Program',
|
|
@@ -291,9 +324,9 @@ const MODULE_REMOVALS = [
|
|
|
291
324
|
{
|
|
292
325
|
key: 'enableAnalytics',
|
|
293
326
|
paths: [
|
|
327
|
+
`${APP}/(dashboard)/dashboard/analytics`,
|
|
294
328
|
'src/lib/analytics',
|
|
295
329
|
'src/app/api/analytics',
|
|
296
|
-
'src/app/(dashboard)/dashboard/analytics',
|
|
297
330
|
'src/components/dashboard/AnalyticsDashboard.tsx',
|
|
298
331
|
],
|
|
299
332
|
label: 'Built-in Analytics',
|
|
@@ -309,12 +342,103 @@ const MODULE_REMOVALS = [
|
|
|
309
342
|
],
|
|
310
343
|
label: 'RAG Pipeline',
|
|
311
344
|
},
|
|
345
|
+
{
|
|
346
|
+
key: 'enableWebhooks',
|
|
347
|
+
paths: [
|
|
348
|
+
`${APP}/(dashboard)/dashboard/webhooks`,
|
|
349
|
+
`${APP}/admin/webhooks`,
|
|
350
|
+
'src/app/api/webhooks',
|
|
351
|
+
'src/lib/outgoing-webhooks',
|
|
352
|
+
'src/lib/webhook-log.ts',
|
|
353
|
+
'src/lib/webhook-log.test.ts',
|
|
354
|
+
'src/components/dashboard/OutgoingWebhooks.tsx',
|
|
355
|
+
],
|
|
356
|
+
label: 'Outgoing Webhooks',
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
key: 'enableAuditLog',
|
|
360
|
+
paths: [
|
|
361
|
+
`${APP}/(dashboard)/dashboard/audit-log`,
|
|
362
|
+
`${APP}/admin/activity`,
|
|
363
|
+
'src/app/api/audit-log',
|
|
364
|
+
'src/lib/activity-log.ts',
|
|
365
|
+
'src/components/dashboard/AuditLog.tsx',
|
|
366
|
+
],
|
|
367
|
+
label: 'Audit Log',
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
key: 'enableReports',
|
|
371
|
+
paths: [
|
|
372
|
+
`${APP}/(dashboard)/dashboard/reports`,
|
|
373
|
+
'src/app/api/reports',
|
|
374
|
+
'src/lib/scheduled-reports',
|
|
375
|
+
'src/components/dashboard/ReportSchedules.tsx',
|
|
376
|
+
],
|
|
377
|
+
label: 'Scheduled Reports',
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
key: 'enableBranding',
|
|
381
|
+
paths: [
|
|
382
|
+
`${APP}/(dashboard)/dashboard/branding`,
|
|
383
|
+
'src/app/api/branding',
|
|
384
|
+
'src/lib/white-label',
|
|
385
|
+
'src/components/dashboard/BrandingSettings.tsx',
|
|
386
|
+
'src/components/dashboard/BrandingProvider.tsx',
|
|
387
|
+
],
|
|
388
|
+
label: 'White-label Branding',
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
key: 'enableTwoFactor',
|
|
392
|
+
// 2FA is implemented as a Better Auth plugin — only the UI control needs
|
|
393
|
+
// to be removed; auth route handlers stay since the plugin is loaded at
|
|
394
|
+
// runtime when ENABLE_TWO_FACTOR is set.
|
|
395
|
+
paths: ['src/components/dashboard/TwoFactorSettings.tsx'],
|
|
396
|
+
label: 'Two-factor Authentication (UI)',
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
key: 'enablePlugins',
|
|
400
|
+
paths: [
|
|
401
|
+
`${APP}/(marketing)/plugins`,
|
|
402
|
+
`${APP}/(dashboard)/dashboard/plugins`,
|
|
403
|
+
'src/app/api/plugins',
|
|
404
|
+
'src/lib/plugins',
|
|
405
|
+
'src/components/marketing/PluginsShowcase.tsx',
|
|
406
|
+
'src/components/marketing/PluginDetail.tsx',
|
|
407
|
+
'src/components/dashboard/PluginMarketplace.tsx',
|
|
408
|
+
],
|
|
409
|
+
label: 'Plugin Marketplace',
|
|
410
|
+
},
|
|
312
411
|
];
|
|
313
412
|
// Maps CLI enable* flags → server-side ENABLE_* env var names.
|
|
413
|
+
// Only flags that actually toggle runtime behavior via env.features belong here;
|
|
414
|
+
// everything else is removed from disk by `removeModules`.
|
|
415
|
+
//
|
|
416
|
+
// Install-time-only features (no runtime ENABLE_* — file removal only):
|
|
417
|
+
// enableGraphQL, enableEventStore, enableOtel, enableRAG, enableConnect.
|
|
418
|
+
// These are infrastructure-flavoured and either always-on or only meaningful
|
|
419
|
+
// at build-time, so they don't expose a user-facing env toggle.
|
|
314
420
|
const FEATURE_ENV_VARS = {
|
|
315
421
|
enableApiDocs: 'ENABLE_API_DOCS',
|
|
316
422
|
enableHelpCenter: 'ENABLE_HELP_CENTER',
|
|
317
423
|
enableChangelog: 'ENABLE_CHANGELOG',
|
|
424
|
+
enableBlog: 'ENABLE_BLOG',
|
|
425
|
+
enableWaitlist: 'ENABLE_WAITLIST',
|
|
426
|
+
enableFeatureRequests: 'ENABLE_FEATURE_REQUESTS',
|
|
427
|
+
enableAI: 'ENABLE_AI_CHAT',
|
|
428
|
+
enableTeams: 'ENABLE_TEAMS',
|
|
429
|
+
enableReferrals: 'ENABLE_REFERRALS',
|
|
430
|
+
enableAnalytics: 'ENABLE_ANALYTICS',
|
|
431
|
+
enableWorkflows: 'ENABLE_WORKFLOWS',
|
|
432
|
+
enableSSO: 'ENABLE_SSO',
|
|
433
|
+
enableExperiments: 'ENABLE_EXPERIMENTS',
|
|
434
|
+
enableDripCampaigns: 'ENABLE_DRIP_CAMPAIGNS',
|
|
435
|
+
enableOnboarding: 'ENABLE_ONBOARDING',
|
|
436
|
+
enableWebhooks: 'ENABLE_WEBHOOKS',
|
|
437
|
+
enableAuditLog: 'ENABLE_AUDIT_LOG',
|
|
438
|
+
enableReports: 'ENABLE_REPORTS',
|
|
439
|
+
enableBranding: 'ENABLE_BRANDING',
|
|
440
|
+
enableTwoFactor: 'ENABLE_TWO_FACTOR',
|
|
441
|
+
enablePlugins: 'ENABLE_PLUGINS',
|
|
318
442
|
};
|
|
319
443
|
function generateEnvFile(root, config) {
|
|
320
444
|
const envExamplePath = join(root, '.env.example');
|
|
@@ -377,13 +501,24 @@ function removeModules(root, config) {
|
|
|
377
501
|
if (config[removal.key])
|
|
378
502
|
continue;
|
|
379
503
|
dim(`Removing ${removal.label}...`);
|
|
504
|
+
let removed = 0;
|
|
505
|
+
const missing = [];
|
|
380
506
|
for (const p of removal.paths) {
|
|
381
507
|
const fullPath = resolve(root, p);
|
|
382
508
|
if (existsSync(fullPath)) {
|
|
383
509
|
rmSync(fullPath, { recursive: true });
|
|
384
510
|
dim(` deleted ${p}`);
|
|
511
|
+
removed += 1;
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
missing.push(p);
|
|
385
515
|
}
|
|
386
516
|
}
|
|
517
|
+
// Surface stale paths so removals don't silently no-op when the host
|
|
518
|
+
// project's file layout changes (e.g. moving routes under [locale]).
|
|
519
|
+
if (removed === 0 && missing.length > 0) {
|
|
520
|
+
dim(` no matching files found (expected ${missing.length} path(s))`);
|
|
521
|
+
}
|
|
387
522
|
}
|
|
388
523
|
}
|
|
389
524
|
async function interactiveSetup() {
|
|
@@ -433,6 +568,14 @@ async function interactiveSetup() {
|
|
|
433
568
|
enableAnalytics: await confirmPrompt(iface, 'Enable built-in analytics?'),
|
|
434
569
|
enableChangelog: await confirmPrompt(iface, 'Enable Changelog page?'),
|
|
435
570
|
enableRAG: await confirmPrompt(iface, 'Enable RAG pipeline (vector search)?'),
|
|
571
|
+
enableWebhooks: authProvider !== 'none' && (await confirmPrompt(iface, 'Enable outgoing webhooks?')),
|
|
572
|
+
enableAuditLog: authProvider !== 'none' && (await confirmPrompt(iface, 'Enable audit log / activity feed?')),
|
|
573
|
+
enableReports: authProvider !== 'none' && (await confirmPrompt(iface, 'Enable scheduled email reports?')),
|
|
574
|
+
enableBranding: authProvider !== 'none' &&
|
|
575
|
+
(await confirmPrompt(iface, 'Enable per-org branding (white-label)?')),
|
|
576
|
+
enableTwoFactor: authProvider !== 'none' &&
|
|
577
|
+
(await confirmPrompt(iface, 'Enable two-factor authentication (TOTP)?')),
|
|
578
|
+
enablePlugins: await confirmPrompt(iface, 'Enable plugin marketplace (/plugins)?'),
|
|
436
579
|
};
|
|
437
580
|
if (await confirmPrompt(iface, 'Remove unused module code?', false)) {
|
|
438
581
|
return config;
|
package/dist/mcp/resources.js
CHANGED
|
@@ -16,7 +16,7 @@ export function registerResources(server) {
|
|
|
16
16
|
});
|
|
17
17
|
server.registerResource('codapult_app_config', 'codapult://config/app', {
|
|
18
18
|
title: 'App Configuration',
|
|
19
|
-
description: 'Application config (src/config/app.ts) — brand,
|
|
19
|
+
description: 'Application config (src/config/app.ts) — brand, AI, payments, company. Feature toggles and auth methods live in .env.local (read via codapult://env-example or codapult_project_status).',
|
|
20
20
|
mimeType: 'text/plain',
|
|
21
21
|
}, () => {
|
|
22
22
|
const content = readProjectFile(getRoot(), 'src/config/app.ts') ?? 'Config file not found';
|
|
@@ -3,6 +3,7 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { findProjectRoot, readProjectFile } from '../../utils/project.js';
|
|
6
|
+
import { getAdapters, getAuthMethods, getFeatures, getOauthProviders, } from '../../utils/env-config.js';
|
|
6
7
|
function getRoot() {
|
|
7
8
|
const root = findProjectRoot();
|
|
8
9
|
if (!root)
|
|
@@ -18,10 +19,6 @@ export function registerProjectTools(server) {
|
|
|
18
19
|
const root = getRoot();
|
|
19
20
|
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf-8'));
|
|
20
21
|
const envContent = readProjectFile(root, '.env.local') ?? '';
|
|
21
|
-
const getEnv = (key, fallback) => {
|
|
22
|
-
const m = new RegExp(`^${key}\\s*=\\s*"?(.+?)"?\\s*$`, 'm').exec(envContent);
|
|
23
|
-
return m?.[1] ?? fallback;
|
|
24
|
-
};
|
|
25
22
|
const pluginsDir = resolve(root, 'src/plugins');
|
|
26
23
|
const plugins = existsSync(pluginsDir)
|
|
27
24
|
? readdirSync(pluginsDir)
|
|
@@ -42,24 +39,18 @@ export function registerProjectTools(server) {
|
|
|
42
39
|
catch {
|
|
43
40
|
/* not a git repo */
|
|
44
41
|
}
|
|
45
|
-
const
|
|
46
|
-
const features = [];
|
|
47
|
-
for (const m of configContent.matchAll(/(\w+):\s*true/g)) {
|
|
48
|
-
features.push(m[1]);
|
|
49
|
-
}
|
|
42
|
+
const features = getFeatures(envContent);
|
|
50
43
|
const result = {
|
|
51
44
|
name: pkg.name,
|
|
52
45
|
version: pkg.version,
|
|
53
|
-
adapters:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
storage: getEnv('STORAGE_PROVIDER', 'local'),
|
|
57
|
-
database: getEnv('DB_PROVIDER', 'turso'),
|
|
58
|
-
notifications: getEnv('NOTIFICATION_TRANSPORT', 'poll'),
|
|
59
|
-
jobs: getEnv('JOB_PROVIDER', 'memory'),
|
|
60
|
-
},
|
|
46
|
+
adapters: getAdapters(envContent),
|
|
47
|
+
authMethods: getAuthMethods(envContent),
|
|
48
|
+
oauthProviders: getOauthProviders(envContent),
|
|
61
49
|
plugins,
|
|
62
|
-
features
|
|
50
|
+
features: {
|
|
51
|
+
enabled: Object.keys(features).filter((k) => features[k]),
|
|
52
|
+
disabled: Object.keys(features).filter((k) => !features[k]),
|
|
53
|
+
},
|
|
63
54
|
git: { branch: gitBranch, dirty: gitDirty },
|
|
64
55
|
};
|
|
65
56
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
@@ -44,9 +44,14 @@ describe('registerProjectTools', () => {
|
|
|
44
44
|
mockedRead.mockReturnValue(JSON.stringify({ name: 'codapult', version: '1.0.0' }));
|
|
45
45
|
mockedReadProject.mockImplementation((_root, path) => {
|
|
46
46
|
if (path === '.env.local')
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return [
|
|
48
|
+
'AUTH_PROVIDER=kinde',
|
|
49
|
+
'PAYMENT_PROVIDER=lemonsqueezy',
|
|
50
|
+
'STORAGE_PROVIDER=s3',
|
|
51
|
+
'ENABLE_TEAMS=false',
|
|
52
|
+
'GOOGLE_CLIENT_ID=abc',
|
|
53
|
+
'GOOGLE_CLIENT_SECRET=def',
|
|
54
|
+
].join('\n');
|
|
50
55
|
return null;
|
|
51
56
|
});
|
|
52
57
|
mockedExists.mockReturnValue(true);
|
|
@@ -65,10 +70,14 @@ describe('registerProjectTools', () => {
|
|
|
65
70
|
expect(parsed.adapters.auth).toBe('kinde');
|
|
66
71
|
expect(parsed.adapters.payments).toBe('lemonsqueezy');
|
|
67
72
|
expect(parsed.adapters.storage).toBe('s3');
|
|
73
|
+
expect(parsed.adapters.database).toBe('turso');
|
|
74
|
+
expect(parsed.adapters.embedding).toBe('openai');
|
|
75
|
+
expect(parsed.adapters.vectorStore).toBe('sqlite');
|
|
76
|
+
expect(parsed.oauthProviders).toEqual(['google']);
|
|
68
77
|
expect(parsed.plugins).toEqual(['ai-kit', 'crm']);
|
|
69
|
-
expect(parsed.features).toContain('
|
|
70
|
-
expect(parsed.features).toContain('blog');
|
|
71
|
-
expect(parsed.features).
|
|
78
|
+
expect(parsed.features.enabled).toContain('aiChat');
|
|
79
|
+
expect(parsed.features.enabled).toContain('blog');
|
|
80
|
+
expect(parsed.features.disabled).toContain('teams');
|
|
72
81
|
expect(parsed.git.branch).toBe('main');
|
|
73
82
|
expect(parsed.git.dirty).toBe(false);
|
|
74
83
|
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared, read-only mirror of `src/lib/config.ts` from the host project.
|
|
3
|
+
*
|
|
4
|
+
* Keep this file in sync with the host's `env.features`, `env.auth`,
|
|
5
|
+
* provider enums, and the `superRefine` validation in
|
|
6
|
+
* `codapult/src/lib/config.ts`. The CLI parses `.env.local` directly (it
|
|
7
|
+
* cannot import from the host project), so this module centralises the
|
|
8
|
+
* provider/feature shape that several commands share (config-show, doctor,
|
|
9
|
+
* MCP project status).
|
|
10
|
+
*/
|
|
11
|
+
export type DbProvider = 'turso' | 'postgres';
|
|
12
|
+
export type AuthProvider = 'better-auth' | 'kinde' | 'none';
|
|
13
|
+
export type PaymentProvider = 'stripe' | 'lemonsqueezy' | 'polar';
|
|
14
|
+
export type StorageProvider = 'local' | 's3' | 'r2';
|
|
15
|
+
export type JobProvider = 'memory' | 'bullmq';
|
|
16
|
+
export type NotificationTransport = 'poll' | 'sse' | 'ws';
|
|
17
|
+
export type EmbeddingProvider = 'openai' | 'ollama';
|
|
18
|
+
export type VectorStoreProvider = 'sqlite' | 'memory';
|
|
19
|
+
/** Feature toggle key → ENABLE_* env var. Order = display order. */
|
|
20
|
+
export declare const FEATURE_ENV: Readonly<Record<string, string>>;
|
|
21
|
+
/** Auth-gated features: when AUTH_PROVIDER=none, these are forced off. */
|
|
22
|
+
export declare const AUTH_GATED_FEATURES: ReadonlySet<string>;
|
|
23
|
+
/** OAuth provider → [client id env, client secret env]. Mirrors oauth-providers.ts. */
|
|
24
|
+
export declare const OAUTH_CREDENTIAL_KEYS: Readonly<Record<string, [string, string]>>;
|
|
25
|
+
/** Read a single var from raw .env content. Returns undefined if missing or empty. */
|
|
26
|
+
export declare function readEnvVar(envContent: string, key: string): string | undefined;
|
|
27
|
+
/** Same as `readEnvVar` but with a typed fallback. */
|
|
28
|
+
export declare function readEnv<T extends string>(envContent: string, key: string, fallback: T): T;
|
|
29
|
+
export interface Adapters {
|
|
30
|
+
database: DbProvider;
|
|
31
|
+
auth: AuthProvider;
|
|
32
|
+
payments: PaymentProvider;
|
|
33
|
+
storage: StorageProvider;
|
|
34
|
+
jobs: JobProvider;
|
|
35
|
+
notifications: NotificationTransport;
|
|
36
|
+
embedding: EmbeddingProvider;
|
|
37
|
+
vectorStore: VectorStoreProvider;
|
|
38
|
+
}
|
|
39
|
+
/** Resolve all adapters from .env content, applying the same defaults as `env.*`. */
|
|
40
|
+
export declare function getAdapters(envContent: string): Adapters;
|
|
41
|
+
/**
|
|
42
|
+
* Compute the effective set of feature toggles from .env content.
|
|
43
|
+
* Mirrors `env.features` in `codapult/src/lib/config.ts`:
|
|
44
|
+
* - default `true` for every ENABLE_* (unset → enabled);
|
|
45
|
+
* - explicit "false" disables;
|
|
46
|
+
* - `auth` derived from AUTH_PROVIDER !== 'none';
|
|
47
|
+
* - auth-gated features forced off when AUTH_PROVIDER=none.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getFeatures(envContent: string): Record<string, boolean>;
|
|
50
|
+
/** Auth-method toggles that live in env (not in app.ts). */
|
|
51
|
+
export interface AuthMethods {
|
|
52
|
+
twoFactor: boolean;
|
|
53
|
+
magicLink: boolean;
|
|
54
|
+
passkeys: boolean;
|
|
55
|
+
}
|
|
56
|
+
export declare function getAuthMethods(envContent: string): AuthMethods;
|
|
57
|
+
/** OAuth providers that have both client id + secret configured in .env. */
|
|
58
|
+
export declare function getOauthProviders(envContent: string): string[];
|
|
59
|
+
/** Provider-conditional env var requirements (mirrors `superRefine`). */
|
|
60
|
+
export interface EnvIssue {
|
|
61
|
+
key: string;
|
|
62
|
+
message: string;
|
|
63
|
+
severity: 'error' | 'warn';
|
|
64
|
+
}
|
|
65
|
+
export declare function findProviderIssues(envContent: string): EnvIssue[];
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared, read-only mirror of `src/lib/config.ts` from the host project.
|
|
3
|
+
*
|
|
4
|
+
* Keep this file in sync with the host's `env.features`, `env.auth`,
|
|
5
|
+
* provider enums, and the `superRefine` validation in
|
|
6
|
+
* `codapult/src/lib/config.ts`. The CLI parses `.env.local` directly (it
|
|
7
|
+
* cannot import from the host project), so this module centralises the
|
|
8
|
+
* provider/feature shape that several commands share (config-show, doctor,
|
|
9
|
+
* MCP project status).
|
|
10
|
+
*/
|
|
11
|
+
/** Feature toggle key → ENABLE_* env var. Order = display order. */
|
|
12
|
+
export const FEATURE_ENV = {
|
|
13
|
+
apiDocs: 'ENABLE_API_DOCS',
|
|
14
|
+
helpCenter: 'ENABLE_HELP_CENTER',
|
|
15
|
+
blog: 'ENABLE_BLOG',
|
|
16
|
+
waitlist: 'ENABLE_WAITLIST',
|
|
17
|
+
featureRequests: 'ENABLE_FEATURE_REQUESTS',
|
|
18
|
+
changelog: 'ENABLE_CHANGELOG',
|
|
19
|
+
aiChat: 'ENABLE_AI_CHAT',
|
|
20
|
+
teams: 'ENABLE_TEAMS',
|
|
21
|
+
referrals: 'ENABLE_REFERRALS',
|
|
22
|
+
analytics: 'ENABLE_ANALYTICS',
|
|
23
|
+
workflows: 'ENABLE_WORKFLOWS',
|
|
24
|
+
webhooks: 'ENABLE_WEBHOOKS',
|
|
25
|
+
auditLog: 'ENABLE_AUDIT_LOG',
|
|
26
|
+
reports: 'ENABLE_REPORTS',
|
|
27
|
+
onboarding: 'ENABLE_ONBOARDING',
|
|
28
|
+
branding: 'ENABLE_BRANDING',
|
|
29
|
+
sso: 'ENABLE_SSO',
|
|
30
|
+
experiments: 'ENABLE_EXPERIMENTS',
|
|
31
|
+
dripCampaigns: 'ENABLE_DRIP_CAMPAIGNS',
|
|
32
|
+
plugins: 'ENABLE_PLUGINS',
|
|
33
|
+
};
|
|
34
|
+
/** Auth-gated features: when AUTH_PROVIDER=none, these are forced off. */
|
|
35
|
+
export const AUTH_GATED_FEATURES = new Set([
|
|
36
|
+
'apiDocs',
|
|
37
|
+
'featureRequests',
|
|
38
|
+
'changelog',
|
|
39
|
+
'aiChat',
|
|
40
|
+
'teams',
|
|
41
|
+
'referrals',
|
|
42
|
+
]);
|
|
43
|
+
/** OAuth provider → [client id env, client secret env]. Mirrors oauth-providers.ts. */
|
|
44
|
+
export const OAUTH_CREDENTIAL_KEYS = {
|
|
45
|
+
google: ['GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET'],
|
|
46
|
+
github: ['GITHUB_CLIENT_ID', 'GITHUB_CLIENT_SECRET'],
|
|
47
|
+
apple: ['APPLE_CLIENT_ID', 'APPLE_CLIENT_SECRET'],
|
|
48
|
+
discord: ['DISCORD_CLIENT_ID', 'DISCORD_CLIENT_SECRET'],
|
|
49
|
+
twitter: ['TWITTER_CLIENT_ID', 'TWITTER_CLIENT_SECRET'],
|
|
50
|
+
microsoft: ['MICROSOFT_CLIENT_ID', 'MICROSOFT_CLIENT_SECRET'],
|
|
51
|
+
};
|
|
52
|
+
/** Read a single var from raw .env content. Returns undefined if missing or empty. */
|
|
53
|
+
export function readEnvVar(envContent, key) {
|
|
54
|
+
const match = new RegExp(`^${key}\\s*=\\s*"?([^"\\n\\r]*)"?\\s*$`, 'm').exec(envContent);
|
|
55
|
+
const value = match?.[1]?.trim();
|
|
56
|
+
return value && value.length > 0 ? value : undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Same as `readEnvVar` but with a typed fallback. */
|
|
59
|
+
export function readEnv(envContent, key, fallback) {
|
|
60
|
+
return readEnvVar(envContent, key) ?? fallback;
|
|
61
|
+
}
|
|
62
|
+
/** Resolve all adapters from .env content, applying the same defaults as `env.*`. */
|
|
63
|
+
export function getAdapters(envContent) {
|
|
64
|
+
return {
|
|
65
|
+
database: readEnv(envContent, 'DB_PROVIDER', 'turso'),
|
|
66
|
+
auth: readEnv(envContent, 'AUTH_PROVIDER', 'better-auth'),
|
|
67
|
+
payments: readEnv(envContent, 'PAYMENT_PROVIDER', 'stripe'),
|
|
68
|
+
storage: readEnv(envContent, 'STORAGE_PROVIDER', 'local'),
|
|
69
|
+
jobs: readEnv(envContent, 'JOB_PROVIDER', 'memory'),
|
|
70
|
+
notifications: readEnv(envContent, 'NOTIFICATION_TRANSPORT', 'poll'),
|
|
71
|
+
embedding: readEnv(envContent, 'EMBEDDING_PROVIDER', 'openai'),
|
|
72
|
+
vectorStore: readEnv(envContent, 'VECTOR_STORE_PROVIDER', 'sqlite'),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Compute the effective set of feature toggles from .env content.
|
|
77
|
+
* Mirrors `env.features` in `codapult/src/lib/config.ts`:
|
|
78
|
+
* - default `true` for every ENABLE_* (unset → enabled);
|
|
79
|
+
* - explicit "false" disables;
|
|
80
|
+
* - `auth` derived from AUTH_PROVIDER !== 'none';
|
|
81
|
+
* - auth-gated features forced off when AUTH_PROVIDER=none.
|
|
82
|
+
*/
|
|
83
|
+
export function getFeatures(envContent) {
|
|
84
|
+
const authProvider = readEnv(envContent, 'AUTH_PROVIDER', 'better-auth');
|
|
85
|
+
const authEnabled = authProvider !== 'none';
|
|
86
|
+
const features = { auth: authEnabled };
|
|
87
|
+
for (const [key, envVar] of Object.entries(FEATURE_ENV)) {
|
|
88
|
+
const raw = readEnvVar(envContent, envVar);
|
|
89
|
+
const enabled = raw !== 'false';
|
|
90
|
+
features[key] = enabled && (!AUTH_GATED_FEATURES.has(key) || authEnabled);
|
|
91
|
+
}
|
|
92
|
+
return features;
|
|
93
|
+
}
|
|
94
|
+
export function getAuthMethods(envContent) {
|
|
95
|
+
const authEnabled = readEnv(envContent, 'AUTH_PROVIDER', 'better-auth') !== 'none';
|
|
96
|
+
return {
|
|
97
|
+
twoFactor: authEnabled && readEnvVar(envContent, 'ENABLE_TWO_FACTOR') !== 'false',
|
|
98
|
+
magicLink: (readEnvVar(envContent, 'AUTH_MAGIC_LINK') ?? 'true') === 'true',
|
|
99
|
+
passkeys: (readEnvVar(envContent, 'AUTH_PASSKEYS') ?? 'true') === 'true',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** OAuth providers that have both client id + secret configured in .env. */
|
|
103
|
+
export function getOauthProviders(envContent) {
|
|
104
|
+
return Object.entries(OAUTH_CREDENTIAL_KEYS)
|
|
105
|
+
.filter(([, [id, secret]]) => !!readEnvVar(envContent, id) && !!readEnvVar(envContent, secret))
|
|
106
|
+
.map(([provider]) => provider);
|
|
107
|
+
}
|
|
108
|
+
export function findProviderIssues(envContent) {
|
|
109
|
+
const issues = [];
|
|
110
|
+
const adapters = getAdapters(envContent);
|
|
111
|
+
const has = (k) => readEnvVar(envContent, k) !== undefined;
|
|
112
|
+
if (adapters.database === 'turso') {
|
|
113
|
+
if (!has('TURSO_DATABASE_URL')) {
|
|
114
|
+
issues.push({
|
|
115
|
+
key: 'TURSO_DATABASE_URL',
|
|
116
|
+
message: 'Required when DB_PROVIDER="turso"',
|
|
117
|
+
severity: 'error',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (!has('TURSO_AUTH_TOKEN')) {
|
|
121
|
+
issues.push({
|
|
122
|
+
key: 'TURSO_AUTH_TOKEN',
|
|
123
|
+
message: 'Required when DB_PROVIDER="turso"',
|
|
124
|
+
severity: 'warn',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (adapters.database === 'postgres' && !has('DATABASE_URL')) {
|
|
129
|
+
issues.push({
|
|
130
|
+
key: 'DATABASE_URL',
|
|
131
|
+
message: 'Required when DB_PROVIDER="postgres"',
|
|
132
|
+
severity: 'error',
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (adapters.auth === 'better-auth') {
|
|
136
|
+
const secret = readEnvVar(envContent, 'BETTER_AUTH_SECRET');
|
|
137
|
+
if (!secret) {
|
|
138
|
+
issues.push({
|
|
139
|
+
key: 'BETTER_AUTH_SECRET',
|
|
140
|
+
message: 'Required when AUTH_PROVIDER="better-auth" (openssl rand -base64 32)',
|
|
141
|
+
severity: 'error',
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else if (secret.length < 32) {
|
|
145
|
+
issues.push({
|
|
146
|
+
key: 'BETTER_AUTH_SECRET',
|
|
147
|
+
message: 'Must be at least 32 characters',
|
|
148
|
+
severity: 'error',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (adapters.auth === 'kinde') {
|
|
153
|
+
for (const k of ['KINDE_CLIENT_ID', 'KINDE_CLIENT_SECRET', 'KINDE_ISSUER_URL']) {
|
|
154
|
+
if (!has(k)) {
|
|
155
|
+
issues.push({ key: k, message: 'Required when AUTH_PROVIDER="kinde"', severity: 'error' });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (adapters.payments === 'stripe' && !has('STRIPE_SECRET_KEY')) {
|
|
160
|
+
issues.push({
|
|
161
|
+
key: 'STRIPE_SECRET_KEY',
|
|
162
|
+
message: 'Required when PAYMENT_PROVIDER="stripe"',
|
|
163
|
+
severity: 'error',
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (adapters.payments === 'lemonsqueezy') {
|
|
167
|
+
if (!has('LEMONSQUEEZY_API_KEY')) {
|
|
168
|
+
issues.push({
|
|
169
|
+
key: 'LEMONSQUEEZY_API_KEY',
|
|
170
|
+
message: 'Required when PAYMENT_PROVIDER="lemonsqueezy"',
|
|
171
|
+
severity: 'error',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (!has('LEMONSQUEEZY_STORE_ID')) {
|
|
175
|
+
issues.push({
|
|
176
|
+
key: 'LEMONSQUEEZY_STORE_ID',
|
|
177
|
+
message: 'Required when PAYMENT_PROVIDER="lemonsqueezy"',
|
|
178
|
+
severity: 'error',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (adapters.payments === 'polar' && !has('POLAR_ACCESS_TOKEN')) {
|
|
183
|
+
issues.push({
|
|
184
|
+
key: 'POLAR_ACCESS_TOKEN',
|
|
185
|
+
message: 'Required when PAYMENT_PROVIDER="polar"',
|
|
186
|
+
severity: 'error',
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (adapters.storage === 's3' || adapters.storage === 'r2') {
|
|
190
|
+
const label = `Required when STORAGE_PROVIDER="${adapters.storage}"`;
|
|
191
|
+
for (const k of ['S3_BUCKET', 'S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY']) {
|
|
192
|
+
if (!has(k))
|
|
193
|
+
issues.push({ key: k, message: label, severity: 'error' });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (adapters.jobs === 'bullmq' && !has('REDIS_URL')) {
|
|
197
|
+
issues.push({
|
|
198
|
+
key: 'REDIS_URL',
|
|
199
|
+
message: 'Required when JOB_PROVIDER="bullmq"',
|
|
200
|
+
severity: 'error',
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (adapters.notifications === 'ws' && !has('NEXT_PUBLIC_WS_URL')) {
|
|
204
|
+
issues.push({
|
|
205
|
+
key: 'NEXT_PUBLIC_WS_URL',
|
|
206
|
+
message: 'Required when NOTIFICATION_TRANSPORT="ws"',
|
|
207
|
+
severity: 'error',
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return issues;
|
|
211
|
+
}
|
package/dist/utils/patchers.js
CHANGED
|
@@ -219,7 +219,7 @@ export function regenerateBarrel(projectRoot) {
|
|
|
219
219
|
.filter((f) => typeof f === 'string' && f.endsWith('.ts') && f !== 'index.ts')
|
|
220
220
|
.sort();
|
|
221
221
|
const imports = files.map((f) => `import './${f.replace('.ts', '')}';`).join('\n');
|
|
222
|
-
const barrel = `// Auto-generated by @codapult/cli — do not edit manually\n${imports}\n`;
|
|
222
|
+
const barrel = `// Auto-generated by @codapult/cli — do not edit manually\n${imports}${imports.length > 0 ? '\n' : ''}`;
|
|
223
223
|
writeFileSync(resolve(pluginsDir, 'index.ts'), barrel, 'utf-8');
|
|
224
224
|
}
|
|
225
225
|
export function createPluginRegistration(projectRoot, pluginName, packageName, action) {
|