@friggframework/devtools 2.0.0--canary.413.39a9576.0 → 2.0.0--canary.414.451bd3d.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.
@@ -1,11 +1,90 @@
1
1
  const { spawn, spawnSync } = require('child_process');
2
2
  const path = require('path');
3
+ const fs = require('fs');
3
4
 
4
5
  async function deployCommand(options) {
5
6
  console.log('Deploying the serverless application...');
6
7
 
8
+ // Collect validated environment variables
9
+ let integrationEnvironmentVariables = { ...process.env }; // Start with all, then filter
10
+
11
+ // Try to load and validate environment from appDefinition
12
+ const appDefPath = path.join(process.cwd(), 'index.js');
13
+ if (fs.existsSync(appDefPath)) {
14
+ try {
15
+ const { Definition } = require(appDefPath);
16
+
17
+ if (Definition.environment) {
18
+ console.log(
19
+ '🔧 Loading environment configuration from appDefinition...'
20
+ );
21
+ const envVars = Object.keys(Definition.environment).filter(
22
+ (key) => Definition.environment[key] === true
23
+ );
24
+ console.log(
25
+ ` Found ${
26
+ envVars.length
27
+ } environment variables: ${envVars.join(', ')}`
28
+ );
29
+
30
+ // Try to use the env-validator if available
31
+ try {
32
+ const {
33
+ validateEnvironmentVariables,
34
+ } = require('@friggframework/devtools/infrastructure/env-validator');
35
+ const validation = validateEnvironmentVariables(Definition);
36
+
37
+ if (
38
+ validation.missing.length > 0 &&
39
+ !options.skipEnvValidation
40
+ ) {
41
+ console.warn(
42
+ '⚠️ Warning: Missing environment variables detected'
43
+ );
44
+ console.warn(
45
+ ' Run with --skip-env-validation to bypass this check'
46
+ );
47
+ }
48
+
49
+ // Only pass the environment variables defined in app definition
50
+ integrationEnvironmentVariables = Object.fromEntries(
51
+ envVars
52
+ .map((key) => [key, process.env[key]])
53
+ .filter(([_, value]) => value !== undefined)
54
+ );
55
+ } catch (validatorError) {
56
+ // Validator not available in current version, just warn
57
+ const missing = envVars.filter((v) => !process.env[v]);
58
+ if (missing.length > 0) {
59
+ console.warn(
60
+ `⚠️ Warning: Missing environment variables: ${missing.join(
61
+ ', '
62
+ )}`
63
+ );
64
+ console.warn(
65
+ ' These should be set in your CI/CD environment or .env file'
66
+ );
67
+ }
68
+
69
+ // Only pass the environment variables defined in app definition
70
+ integrationEnvironmentVariables = Object.fromEntries(
71
+ envVars
72
+ .map((key) => [key, process.env[key]])
73
+ .filter(([_, value]) => value !== undefined)
74
+ );
75
+ }
76
+ }
77
+ } catch (error) {
78
+ console.warn(
79
+ 'Could not load appDefinition environment config:',
80
+ error.message
81
+ );
82
+ // Keep all env vars if we can't validate
83
+ }
84
+ }
85
+
7
86
  // AWS discovery is now handled directly in serverless-template.js
8
- console.log('🔥 Deploying serverless application...');
87
+ console.log('🚀 Deploying serverless application...');
9
88
  const backendPath = path.resolve(process.cwd());
10
89
  const infrastructurePath = 'infrastructure.js';
11
90
  const command = 'serverless';
@@ -17,12 +96,10 @@ async function deployCommand(options) {
17
96
  options.stage,
18
97
  ];
19
98
 
20
- console.log('>>> Env vars: ', JSON.stringify(process.env));
21
-
22
99
  const childProcess = spawn(command, serverlessArgs, {
23
100
  cwd: backendPath,
24
101
  stdio: 'inherit',
25
- env: { ...process.env },
102
+ env: integrationEnvironmentVariables, // Only pass validated environment variables
26
103
  });
27
104
 
28
105
  childProcess.on('error', (error) => {