@codapult/cli 0.21.1 → 0.23.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.
@@ -1,344 +1,161 @@
1
- /**
2
- * Shared, read-only mirror of `src/config/env.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/config/env.ts` and `codapult/src/config/env-schema.ts`.
7
- * The CLI cannot import from the host project, so this module centralises
8
- * the provider/feature shape that several commands share regardless of whether
9
- * env values come from `.env.local` or `process.env`.
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
- aiCore: 'ENABLE_AI_CORE',
20
- aiChat: 'ENABLE_AI_CHAT',
21
- aiRag: 'ENABLE_AI_RAG',
22
- aiAgents: 'ENABLE_AI_AGENTS',
23
- aiBatch: 'ENABLE_AI_BATCH',
24
- aiPlayground: 'ENABLE_AI_PLAYGROUND',
25
- teams: 'ENABLE_TEAMS',
26
- referrals: 'ENABLE_REFERRALS',
27
- promotions: 'ENABLE_PROMOTIONS',
28
- analytics: 'ENABLE_ANALYTICS',
29
- workflows: 'ENABLE_WORKFLOWS',
30
- webhooks: 'ENABLE_WEBHOOKS',
31
- auditLog: 'ENABLE_AUDIT_LOG',
32
- reports: 'ENABLE_REPORTS',
33
- onboarding: 'ENABLE_ONBOARDING',
34
- branding: 'ENABLE_BRANDING',
35
- experiments: 'ENABLE_EXPERIMENTS',
36
- dripCampaigns: 'ENABLE_DRIP_CAMPAIGNS',
37
- plugins: 'ENABLE_PLUGINS',
38
- compare: 'ENABLE_COMPARE',
39
- };
40
- /**
41
- * Snapshot of the host env-schema contract. The compatibility check compares
42
- * this explicit contract with `src/config/env-schema.ts`; adding a variable to
43
- * the template therefore produces an actionable doctor warning until the CLI
44
- * mirror is reviewed.
45
- */
46
- export const ENV_SCHEMA_KEYS = [
47
- 'NEXT_PUBLIC_APP_URL',
48
- 'NEXT_PUBLIC_APP_NAME',
49
- 'APP_MODE',
50
- 'DEMO_URL',
51
- 'LOG_LEVEL',
52
- 'DB_PROVIDER',
53
- 'AUTH_PROVIDER',
54
- 'PAYMENT_PROVIDER',
55
- 'STORAGE_PROVIDER',
56
- 'JOB_PROVIDER',
57
- 'SSO_PROVIDER',
58
- 'NOTIFICATION_TRANSPORT',
59
- 'EMBEDDING_PROVIDER',
60
- 'VECTOR_STORE_PROVIDER',
61
- 'SUPPORT_PROVIDER',
62
- 'TURSO_DATABASE_URL',
63
- 'TURSO_AUTH_TOKEN',
64
- 'DATABASE_URL',
65
- 'ENABLE_TWO_FACTOR',
66
- 'AUTH_MAGIC_LINK',
67
- 'AUTH_PASSKEYS',
68
- 'BETTER_AUTH_SECRET',
69
- 'BETTER_AUTH_URL',
70
- 'KINDE_CLIENT_ID',
71
- 'KINDE_CLIENT_SECRET',
72
- 'KINDE_ISSUER_URL',
73
- 'GOOGLE_CLIENT_ID',
74
- 'GOOGLE_CLIENT_SECRET',
75
- 'GITHUB_CLIENT_ID',
76
- 'GITHUB_CLIENT_SECRET',
77
- 'APPLE_CLIENT_ID',
78
- 'APPLE_CLIENT_SECRET',
79
- 'DISCORD_CLIENT_ID',
80
- 'DISCORD_CLIENT_SECRET',
81
- 'TWITTER_CLIENT_ID',
82
- 'TWITTER_CLIENT_SECRET',
83
- 'MICROSOFT_CLIENT_ID',
84
- 'MICROSOFT_CLIENT_SECRET',
85
- 'STRIPE_SECRET_KEY',
86
- 'STRIPE_WEBHOOK_SECRET',
87
- 'STRIPE_CONNECT_FEE_PERCENT',
88
- 'STRIPE_CONNECT_ONBOARDING_RETURN_URL',
89
- 'STRIPE_CONNECT_ONBOARDING_REFRESH_URL',
90
- 'LEMONSQUEEZY_API_KEY',
91
- 'LEMONSQUEEZY_STORE_ID',
92
- 'LEMONSQUEEZY_WEBHOOK_SECRET',
93
- 'POLAR_ACCESS_TOKEN',
94
- 'POLAR_WEBHOOK_SECRET',
95
- 'S3_BUCKET',
96
- 'S3_REGION',
97
- 'S3_ENDPOINT',
98
- 'S3_ACCESS_KEY_ID',
99
- 'S3_SECRET_ACCESS_KEY',
100
- 'S3_PUBLIC_URL',
101
- 'JOB_QUEUE_NAME',
102
- 'REDIS_URL',
103
- 'CODAPULT_WORKER_MODE',
104
- 'CODAPULT_DISABLE_IN_PROCESS_JOBS',
105
- 'CUSTOM_DOMAIN_CNAME_TARGET',
106
- 'REFERRAL_REWARD_AMOUNT',
107
- 'REFERRAL_REWARD_TYPE',
108
- 'SSO_PRODUCT',
109
- 'SSO_DB_ENGINE',
110
- 'SSO_DB_TYPE',
111
- 'SSO_DB_URL',
112
- 'NOTIFICATION_WS_URL',
113
- 'NOTIFICATION_WS_PORT',
114
- 'OPENAI_API_KEY',
115
- 'ANTHROPIC_API_KEY',
116
- 'GOOGLE_GENERATIVE_AI_API_KEY',
117
- 'GROQ_API_KEY',
118
- 'TOGETHER_AI_API_KEY',
119
- 'CUSTOM_AI_BASE_URL',
120
- 'CUSTOM_AI_API_KEY',
121
- 'SERPER_API_KEY',
122
- 'TAVILY_API_KEY',
123
- 'AI_DEFAULT_MODEL',
124
- 'AI_ALLOWED_MODELS',
125
- 'AI_FALLBACK_CHAIN',
126
- 'AI_MAX_RETRIES',
127
- 'AI_DEFAULT_TEMPERATURE',
128
- 'AI_DEFAULT_MAX_TOKENS',
129
- 'AI_DEFAULT_TOP_P',
130
- 'AI_DAILY_BUDGET_USD',
131
- 'AI_MONTHLY_BUDGET_USD',
132
- 'AI_HTTP_ALLOWLIST',
133
- 'AI_RAG_MAX_DOCUMENT_SIZE',
134
- 'AI_RAG_MAX_BATCH_DOCUMENTS',
135
- 'AI_RAG_MAX_CHUNKS_PER_QUERY',
136
- 'AI_RAG_MIN_SCORE',
137
- 'OLLAMA_BASE_URL',
138
- 'OLLAMA_EMBEDDING_MODEL',
139
- 'RESEND_API_KEY',
140
- 'EMAIL_FROM',
141
- 'CRISP_WEBSITE_ID',
142
- 'INTERCOM_APP_ID',
143
- 'DEFAULT_MONTHLY_CREDITS',
144
- 'OTEL_EXPORTER_OTLP_ENDPOINT',
145
- 'OTEL_SERVICE_NAME',
146
- 'OTEL_TRACES_SAMPLE_RATE',
147
- 'OTEL_EXPORTER_OTLP_HEADERS',
148
- 'POSTHOG_TOKEN',
149
- 'POSTHOG_HOST',
150
- 'POSTHOG_UI_HOST',
151
- ...Object.values(FEATURE_ENV),
152
- ];
153
- /** Auth-gated features: when AUTH_PROVIDER=none, these are forced off. */
154
- export const AUTH_GATED_FEATURES = new Set([
1
+ /** CLI projections of the environment schema and values owned by the project. */
2
+ import { getProjectEnvSchema, getProjectEnvSchemaKeys, loadProjectAppConfig, loadProjectEnvSchema, loadProjectOAuthProviders, parseProjectEnv, } from './project-env-schema.js';
3
+ function getSchemaFieldValue(schema, source, key) {
4
+ const field = schema.shape[key];
5
+ if (field === undefined)
6
+ throw new Error(`Environment schema does not define ${key}`);
7
+ try {
8
+ return String(field.parse(source[key]));
9
+ }
10
+ catch {
11
+ return source[key] ?? '';
12
+ }
13
+ }
14
+ /** Stable CLI presentation order; env variable names still come from the app schema. */
15
+ const FEATURE_DISPLAY_ORDER = [
155
16
  'apiDocs',
17
+ 'docs',
18
+ 'blog',
19
+ 'waitlist',
156
20
  'featureRequests',
157
21
  'changelog',
22
+ 'ai',
158
23
  'aiChat',
159
- 'aiCore',
160
24
  'aiRag',
161
25
  'aiAgents',
162
26
  'aiBatch',
163
27
  'aiPlayground',
164
28
  'teams',
165
29
  'referrals',
166
- ]);
167
- /** OAuth provider → [client id env, client secret env]. Mirrors oauth-providers.ts. */
168
- export const OAUTH_CREDENTIAL_KEYS = {
169
- google: ['GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET'],
170
- github: ['GITHUB_CLIENT_ID', 'GITHUB_CLIENT_SECRET'],
171
- apple: ['APPLE_CLIENT_ID', 'APPLE_CLIENT_SECRET'],
172
- discord: ['DISCORD_CLIENT_ID', 'DISCORD_CLIENT_SECRET'],
173
- twitter: ['TWITTER_CLIENT_ID', 'TWITTER_CLIENT_SECRET'],
174
- microsoft: ['MICROSOFT_CLIENT_ID', 'MICROSOFT_CLIENT_SECRET'],
175
- };
30
+ 'promotions',
31
+ 'analytics',
32
+ 'workflows',
33
+ 'webhooks',
34
+ 'auditLog',
35
+ 'reports',
36
+ 'onboarding',
37
+ 'branding',
38
+ 'experiments',
39
+ 'dripCampaigns',
40
+ 'plugins',
41
+ 'compare',
42
+ 'seo',
43
+ 'graphql',
44
+ 'connect',
45
+ 'eventStore',
46
+ 'otel',
47
+ ];
48
+ export function getFeatureEnv(root, options = {}) {
49
+ const discovered = getProjectEnvSchemaKeys(root)
50
+ .filter((key) => key.startsWith('ENABLE_'))
51
+ .map((envKey) => [
52
+ envKey
53
+ .slice('ENABLE_'.length)
54
+ .toLowerCase()
55
+ .replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()),
56
+ envKey,
57
+ ]);
58
+ const features = options.includeAuthMethods
59
+ ? discovered
60
+ : discovered.filter(([feature]) => feature !== 'twoFactor');
61
+ const order = new Map(FEATURE_DISPLAY_ORDER.map((feature, index) => [feature, index]));
62
+ return Object.fromEntries(features.sort(([a], [b]) => (order.get(a) ?? Number.MAX_SAFE_INTEGER) - (order.get(b) ?? Number.MAX_SAFE_INTEGER)));
63
+ }
176
64
  /** Read a single var from raw .env content. Returns undefined if missing or empty. */
177
65
  export function readEnvVar(envContent, key) {
178
- const match = new RegExp(`^${key}\\s*=\\s*"?([^"\\n\\r]*)"?\\s*$`, 'm').exec(envContent);
179
- const value = match?.[1]?.trim();
66
+ const value = parseProjectEnv(envContent)[key]?.trim();
180
67
  return value && value.length > 0 ? value : undefined;
181
68
  }
182
- /** Same as `readEnvVar` but with a typed fallback. */
183
- export function readEnv(envContent, key, fallback) {
184
- return readEnvVar(envContent, key) ?? fallback;
69
+ /** Read a value after applying the project schema's transforms and defaults. */
70
+ export function getProjectEnvValue(envContent, root, key) {
71
+ const source = parseProjectEnv(envContent);
72
+ return getSchemaFieldValue(getProjectEnvSchema(root, source), source, key);
185
73
  }
186
- /** Resolve all adapters from .env content, applying the same defaults as `env.*`. */
187
- export function getAdapters(envContent) {
188
- const landingMode = readEnv(envContent, 'APP_MODE', 'app') === 'landing';
189
- const authProvider = readEnv(envContent, 'AUTH_PROVIDER', 'better-auth');
74
+ /** Resolve provider values and defaults through the project's own schema. */
75
+ function getAdaptersFromSchema(schema, source) {
76
+ const value = (key) => getSchemaFieldValue(schema, source, key);
190
77
  return {
191
- database: readEnv(envContent, 'DB_PROVIDER', 'turso'),
192
- auth: landingMode ? 'none' : authProvider,
193
- sso: readEnv(envContent, 'SSO_PROVIDER', 'none'),
194
- payments: readEnv(envContent, 'PAYMENT_PROVIDER', 'stripe'),
195
- storage: readEnv(envContent, 'STORAGE_PROVIDER', 'local'),
196
- jobs: readEnv(envContent, 'JOB_PROVIDER', 'memory'),
197
- notifications: readEnv(envContent, 'NOTIFICATION_TRANSPORT', 'poll'),
198
- embedding: readEnv(envContent, 'EMBEDDING_PROVIDER', 'openai'),
199
- vectorStore: readEnv(envContent, 'VECTOR_STORE_PROVIDER', 'sqlite'),
200
- support: readEnv(envContent, 'SUPPORT_PROVIDER', 'none'),
78
+ database: value('DB_PROVIDER'),
79
+ auth: value('AUTH_PROVIDER'),
80
+ sso: value('SSO_PROVIDER'),
81
+ payments: value('PAYMENT_PROVIDER'),
82
+ storage: value('STORAGE_PROVIDER'),
83
+ jobs: value('JOB_PROVIDER'),
84
+ notifications: value('NOTIFICATION_TRANSPORT'),
85
+ embedding: value('EMBEDDING_PROVIDER'),
86
+ vectorStore: value('VECTOR_STORE_PROVIDER'),
87
+ support: value('SUPPORT_PROVIDER'),
201
88
  };
202
89
  }
203
- /**
204
- * Compute the effective set of feature toggles from .env content.
205
- * Mirrors `env.features` in `codapult/src/config/env.ts`:
206
- * - default `true` for every ENABLE_* (unset → enabled);
207
- * - explicit "false" disables;
208
- * - `auth` derived from AUTH_PROVIDER !== 'none';
209
- * - auth-gated features forced off when AUTH_PROVIDER=none.
210
- */
211
- export function getFeatures(envContent) {
212
- const appMode = readEnv(envContent, 'APP_MODE', 'app');
213
- const authProvider = getAdapters(envContent).auth;
214
- const authEnabled = authProvider !== 'none';
215
- const features = { auth: authEnabled };
216
- for (const [key, envVar] of Object.entries(FEATURE_ENV)) {
217
- const raw = readEnvVar(envContent, envVar);
218
- const defaultEnabled = key === 'compare' ? appMode === 'landing' : key === 'aiRag' ? false : true;
219
- const enabled = raw == null ? defaultEnabled : raw !== 'false';
220
- features[key] = enabled && (!AUTH_GATED_FEATURES.has(key) || authEnabled);
90
+ export function getAdapters(envContent, root) {
91
+ const source = parseProjectEnv(envContent);
92
+ const schema = getProjectEnvSchema(root, source);
93
+ return getAdaptersFromSchema(schema, source);
94
+ }
95
+ /** Resolve feature toggles with schema defaults and CLI-specific dependencies. */
96
+ export function getFeatures(envContent, root) {
97
+ const source = parseProjectEnv(envContent);
98
+ const schema = getProjectEnvSchema(root, source);
99
+ const featureEnv = getFeatureEnv(root);
100
+ const features = {};
101
+ for (const [feature, envKey] of Object.entries(featureEnv)) {
102
+ const value = getSchemaFieldValue(schema, source, envKey);
103
+ features[feature] = value !== 'false';
221
104
  }
222
- if (!features.aiCore) {
223
- features.aiChat = false;
224
- features.aiRag = false;
225
- features.aiAgents = false;
226
- features.aiBatch = false;
227
- features.aiPlayground = false;
105
+ const adapters = getAdaptersFromSchema(schema, source);
106
+ features.auth = adapters.auth !== 'none';
107
+ features.sso = adapters.sso !== 'none';
108
+ features.jobs = adapters.jobs !== 'none';
109
+ const parentFeature = {
110
+ aiChat: 'ai',
111
+ aiRag: 'ai',
112
+ aiAgents: 'ai',
113
+ aiBatch: 'ai',
114
+ aiPlayground: 'ai',
115
+ branding: 'teams',
116
+ };
117
+ for (const [feature, parent] of Object.entries(parentFeature)) {
118
+ if (!features[parent])
119
+ features[feature] = false;
228
120
  }
229
121
  return features;
230
122
  }
231
- export function getAuthMethods(envContent) {
232
- const authEnabled = getAdapters(envContent).auth !== 'none';
123
+ export function getAuthMethods(envContent, root) {
124
+ const source = parseProjectEnv(envContent);
125
+ const schema = getProjectEnvSchema(root, source);
126
+ const value = (key) => getSchemaFieldValue(schema, source, key) === 'true';
233
127
  return {
234
- twoFactor: authEnabled && readEnvVar(envContent, 'ENABLE_TWO_FACTOR') !== 'false',
235
- magicLink: (readEnvVar(envContent, 'AUTH_MAGIC_LINK') ?? 'true') === 'true',
236
- passkeys: (readEnvVar(envContent, 'AUTH_PASSKEYS') ?? 'true') === 'true',
128
+ twoFactor: value('ENABLE_TWO_FACTOR'),
129
+ magicLink: value('AUTH_MAGIC_LINK'),
130
+ passkeys: value('AUTH_PASSKEYS'),
237
131
  };
238
132
  }
239
- /** OAuth providers that have both client id + secret configured in .env. */
240
- export function getOauthProviders(envContent) {
241
- return Object.entries(OAUTH_CREDENTIAL_KEYS)
242
- .filter(([, [id, secret]]) => !!readEnvVar(envContent, id) && !!readEnvVar(envContent, secret))
133
+ /** OAuth providers are derived from matching credential keys in the schema. */
134
+ export function getOauthProviders(envContent, root) {
135
+ const source = parseProjectEnv(envContent);
136
+ const { oauthCredentialKeys: credentials } = loadProjectOAuthProviders(root);
137
+ return Object.entries(credentials)
138
+ .filter(([, [idKey, secretKey]]) => !!source[idKey] && !!source[secretKey])
243
139
  .map(([provider]) => provider);
244
140
  }
245
- export function findProviderIssues(envContent) {
246
- const issues = [];
247
- const adapters = getAdapters(envContent);
248
- const has = (k) => readEnvVar(envContent, k) != null;
249
- if (adapters.database === 'turso' && !has('TURSO_DATABASE_URL')) {
250
- issues.push({
251
- key: 'TURSO_DATABASE_URL',
252
- message: 'Required when DB_PROVIDER="turso"',
253
- severity: 'error',
254
- });
255
- }
256
- if (adapters.database === 'postgres' && !has('DATABASE_URL')) {
257
- issues.push({
258
- key: 'DATABASE_URL',
259
- message: 'Required when DB_PROVIDER="postgres"',
260
- severity: 'error',
261
- });
262
- }
263
- if (adapters.auth === 'better-auth') {
264
- const secret = readEnvVar(envContent, 'BETTER_AUTH_SECRET');
265
- if (!secret) {
266
- issues.push({
267
- key: 'BETTER_AUTH_SECRET',
268
- message: 'Required when AUTH_PROVIDER="better-auth" (openssl rand -base64 32)',
269
- severity: 'error',
270
- });
271
- }
272
- else if (secret.length < 32) {
273
- issues.push({
274
- key: 'BETTER_AUTH_SECRET',
275
- message: 'Must be at least 32 characters',
276
- severity: 'error',
277
- });
278
- }
279
- }
280
- if (adapters.auth === 'kinde') {
281
- for (const k of ['KINDE_CLIENT_ID', 'KINDE_CLIENT_SECRET', 'KINDE_ISSUER_URL']) {
282
- if (!has(k)) {
283
- issues.push({ key: k, message: 'Required when AUTH_PROVIDER="kinde"', severity: 'error' });
284
- }
285
- }
286
- }
287
- if (adapters.payments === 'stripe' && !has('STRIPE_SECRET_KEY')) {
288
- issues.push({
289
- key: 'STRIPE_SECRET_KEY',
290
- message: 'Required when PAYMENT_PROVIDER="stripe"',
291
- severity: 'error',
292
- });
293
- }
294
- if (adapters.payments === 'lemonsqueezy') {
295
- const label = `Required when PAYMENT_PROVIDER="${adapters.payments}"`;
296
- for (const k of ['LEMONSQUEEZY_API_KEY', 'LEMONSQUEEZY_STORE_ID']) {
297
- if (!has(k))
298
- issues.push({ key: k, message: label, severity: 'error' });
299
- }
300
- }
301
- if (adapters.payments === 'polar' && !has('POLAR_ACCESS_TOKEN')) {
302
- issues.push({
303
- key: 'POLAR_ACCESS_TOKEN',
304
- message: 'Required when PAYMENT_PROVIDER="polar"',
305
- severity: 'error',
306
- });
307
- }
308
- if (adapters.storage === 's3' || adapters.storage === 'r2') {
309
- const label = `Required when STORAGE_PROVIDER="${adapters.storage}"`;
310
- for (const k of ['S3_BUCKET', 'S3_ACCESS_KEY_ID', 'S3_SECRET_ACCESS_KEY']) {
311
- if (!has(k))
312
- issues.push({ key: k, message: label, severity: 'error' });
313
- }
314
- }
315
- if (adapters.jobs === 'bullmq' && !has('REDIS_URL')) {
316
- issues.push({
317
- key: 'REDIS_URL',
318
- message: 'Required when JOB_PROVIDER="bullmq"',
319
- severity: 'error',
320
- });
321
- }
322
- if (adapters.notifications === 'ws' && !has('NOTIFICATION_WS_URL')) {
323
- issues.push({
324
- key: 'NOTIFICATION_WS_URL',
325
- message: 'Required when NOTIFICATION_TRANSPORT="ws"',
326
- severity: 'error',
141
+ export function findEnvIssues(envContent, projectRoot) {
142
+ try {
143
+ const source = parseProjectEnv(envContent);
144
+ const defaults = loadProjectAppConfig(projectRoot).createAppConfig(source);
145
+ const schema = loadProjectEnvSchema(projectRoot).createEnvSchema(source, {
146
+ skipRuntimeChecks: false,
147
+ defaults,
327
148
  });
328
- }
329
- if (adapters.support === 'crisp' && !has('CRISP_WEBSITE_ID')) {
330
- issues.push({
331
- key: 'CRISP_WEBSITE_ID',
332
- message: 'Required when SUPPORT_PROVIDER="crisp"',
149
+ const result = schema.safeParse(source);
150
+ if (result.success)
151
+ return [];
152
+ return result.error.issues.map((issue) => ({
153
+ key: typeof issue.path[0] === 'string' ? issue.path[0] : 'ENV',
154
+ message: issue.message,
333
155
  severity: 'error',
334
- });
156
+ }));
335
157
  }
336
- if (adapters.support === 'intercom' && !has('INTERCOM_APP_ID')) {
337
- issues.push({
338
- key: 'INTERCOM_APP_ID',
339
- message: 'Required when SUPPORT_PROVIDER="intercom"',
340
- severity: 'error',
341
- });
158
+ catch (error) {
159
+ return [{ key: 'ENV_SCHEMA', message: String(error), severity: 'error' }];
342
160
  }
343
- return issues;
344
161
  }
@@ -4,7 +4,7 @@ import { findPageBackups, findPageConflicts } from './patchers.js';
4
4
  import { resolveManifest } from './manifest.js';
5
5
  import { findProjectRoot, readJsonFile } from './project.js';
6
6
  import { getProjectEnvOptions, loadProjectEnv } from './project-env.js';
7
- import { findProviderIssues, getAdapters, readEnvVar } from './env-config.js';
7
+ import { findEnvIssues, getAdapters, getProjectEnvValue, readEnvVar } from './env-config.js';
8
8
  import { runProjectCommand } from './command.js';
9
9
  import { checkEnvSchemaCompatibility } from './env-compatibility.js';
10
10
  import { compareSchemaFiles } from './schema-parity.js';
@@ -65,14 +65,14 @@ export function collectProjectHealth(root = findProjectRoot() ?? process.cwd(),
65
65
  : '.env.local is missing',
66
66
  path: env.filePath,
67
67
  });
68
- const adapters = getAdapters(env.content);
68
+ const adapters = getAdapters(env.content, root);
69
69
  add({
70
70
  id: 'effective-config',
71
71
  status: 'ok',
72
72
  message: 'Effective providers and feature configuration resolved',
73
73
  details: {
74
74
  adapters,
75
- appMode: readEnvVar(env.content, 'APP_MODE') ?? 'app',
75
+ appMode: getProjectEnvValue(env.content, root, 'APP_MODE'),
76
76
  },
77
77
  });
78
78
  const schemaPath = adapters.database === 'postgres' ? 'src/lib/db/schema-pg.ts' : 'src/lib/db/schema.ts';
@@ -112,7 +112,7 @@ export function collectProjectHealth(root = findProjectRoot() ?? process.cwd(),
112
112
  file('auth-module', 'src/lib/auth/index.ts', 'Auth module', adapters.auth !== 'none');
113
113
  file('payments-module', 'src/lib/payments/index.ts', 'Payments module');
114
114
  file('plugin-registry', 'codapult.plugins.ts', 'Plugin registry', false);
115
- for (const issue of findProviderIssues(env.content)) {
115
+ for (const issue of findEnvIssues(env.content, root)) {
116
116
  add({
117
117
  id: `env-${issue.key.toLowerCase()}`,
118
118
  status: issue.severity === 'error' ? 'fail' : 'warn',
@@ -53,8 +53,8 @@ if (provider === 'turso') {
53
53
  output([...map.values()]);
54
54
  }
55
55
  `;
56
- function databaseEnv(envContent) {
57
- const adapters = getAdapters(envContent);
56
+ function databaseEnv(envContent, root) {
57
+ const adapters = getAdapters(envContent, root);
58
58
  return {
59
59
  CODAPULT_DB_PROVIDER: adapters.database,
60
60
  TURSO_DATABASE_URL: readEnvVar(envContent, 'TURSO_DATABASE_URL'),
@@ -63,7 +63,7 @@ function databaseEnv(envContent) {
63
63
  };
64
64
  }
65
65
  export function inspectLiveDatabase(root, envContent) {
66
- const env = databaseEnv(envContent);
66
+ const env = databaseEnv(envContent, root);
67
67
  const requiredKey = env.CODAPULT_DB_PROVIDER === 'postgres' ? 'DATABASE_URL' : 'TURSO_DATABASE_URL';
68
68
  if (!env[requiredKey])
69
69
  throw new Error(`${requiredKey} is required to inspect the live database`);
@@ -0,0 +1,31 @@
1
+ import type { z } from 'zod';
2
+ interface ProjectEnvSchemaModule {
3
+ createEnvSchema(environment?: NodeJS.ProcessEnv, options?: {
4
+ skipRuntimeChecks?: boolean;
5
+ defaults?: ProjectAppConfig;
6
+ }): z.ZodObject<z.ZodRawShape>;
7
+ }
8
+ interface ProjectAppConfig {
9
+ appName: string;
10
+ appUrl: string;
11
+ currency: string;
12
+ reverseProxyUrl?: string;
13
+ }
14
+ interface ProjectAppConfigModule {
15
+ createAppConfig(environment?: NodeJS.ProcessEnv): ProjectAppConfig;
16
+ }
17
+ /**
18
+ * Load the env schema from the Codapult project, transpiling its TypeScript
19
+ * source in memory so the CLI can validate the exact source used by the app.
20
+ */
21
+ export declare function loadProjectEnvSchema(root: string): ProjectEnvSchemaModule;
22
+ export declare function loadProjectAppConfig(root: string): ProjectAppConfigModule;
23
+ interface ProjectOAuthProvidersModule {
24
+ oauthCredentialKeys: Record<string, [string, string]>;
25
+ }
26
+ export declare function loadProjectOAuthProviders(root: string): ProjectOAuthProvidersModule;
27
+ export declare function getProjectEnvSchema(root: string, environment?: NodeJS.ProcessEnv): z.ZodObject<z.ZodRawShape>;
28
+ export declare function getProjectEnvSchemaKeys(root: string): string[];
29
+ /** Parse the simple KEY=value format used by the project's env files. */
30
+ export declare function parseProjectEnv(content: string): NodeJS.ProcessEnv;
31
+ export {};