@friggframework/core 2.0.0--canary.419.daed467.0 → 2.0.0--canary.419.f684df1.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/database/mongo.js +123 -79
- package/package.json +5 -5
package/database/mongo.js
CHANGED
|
@@ -14,24 +14,7 @@ mongoose.set('applyPluginsToDiscriminators', true); // Needed for LHEncrypt
|
|
|
14
14
|
|
|
15
15
|
// Load app definition to check for DocumentDB configuration
|
|
16
16
|
let appDefinition = {};
|
|
17
|
-
|
|
18
|
-
const backendPath = findNearestBackendPackageJson();
|
|
19
|
-
if (backendPath) {
|
|
20
|
-
const backendDir = path.dirname(backendPath);
|
|
21
|
-
const backendFilePath = path.join(backendDir, 'index.js');
|
|
22
|
-
if (fs.existsSync(backendFilePath)) {
|
|
23
|
-
const backendJsFile = require(backendFilePath);
|
|
24
|
-
appDefinition = backendJsFile.Definition || {};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
} catch (error) {
|
|
28
|
-
debug('Could not load app definition for DocumentDB configuration:', error.message);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Buffering means mongoose will queue up operations if it gets
|
|
32
|
-
// With serverless, better to fail fast if not connected.
|
|
33
|
-
// disconnected from MongoDB and send them when it reconnects.
|
|
34
|
-
const mongoConfig = {
|
|
17
|
+
let mongoConfig = {
|
|
35
18
|
useNewUrlParser: true,
|
|
36
19
|
bufferCommands: false, // Disable mongoose buffering
|
|
37
20
|
autoCreate: false, // Disable because auto creation does not work without buffering
|
|
@@ -39,65 +22,6 @@ const mongoConfig = {
|
|
|
39
22
|
serverSelectionTimeoutMS: 5000,
|
|
40
23
|
};
|
|
41
24
|
|
|
42
|
-
// Add DocumentDB TLS configuration if enabled
|
|
43
|
-
if (appDefinition.database?.documentDB?.enable === true) {
|
|
44
|
-
console.log('📄 DocumentDB configuration detected, enabling TLS');
|
|
45
|
-
console.log('📁 Current working directory:', process.cwd());
|
|
46
|
-
console.log('📋 App definition database config:', JSON.stringify(appDefinition.database, null, 2));
|
|
47
|
-
|
|
48
|
-
mongoConfig.tls = true;
|
|
49
|
-
|
|
50
|
-
// Set TLS CA file path if specified
|
|
51
|
-
if (appDefinition.database.documentDB.tlsCAFile) {
|
|
52
|
-
const tlsCAFile = appDefinition.database.documentDB.tlsCAFile;
|
|
53
|
-
|
|
54
|
-
// Basic safety: reject obviously dangerous paths
|
|
55
|
-
if (tlsCAFile.includes('..') || path.isAbsolute(tlsCAFile)) {
|
|
56
|
-
console.warn('⚠️ Rejecting potentially unsafe tlsCAFile path:', tlsCAFile);
|
|
57
|
-
} else {
|
|
58
|
-
const tlsCAFilePath = path.resolve(process.cwd(), tlsCAFile);
|
|
59
|
-
|
|
60
|
-
console.log('📄 DocumentDB TLS CA file configured:');
|
|
61
|
-
console.log(' 📎 Original path:', tlsCAFile);
|
|
62
|
-
console.log(' 📎 Resolved path:', tlsCAFilePath);
|
|
63
|
-
console.log(' 📄 File exists:', fs.existsSync(tlsCAFilePath));
|
|
64
|
-
|
|
65
|
-
// Only set tlsCAFile if the file actually exists
|
|
66
|
-
if (fs.existsSync(tlsCAFilePath)) {
|
|
67
|
-
mongoConfig.tlsCAFile = tlsCAFilePath;
|
|
68
|
-
console.log('✅ TLS CA file configured successfully');
|
|
69
|
-
} else {
|
|
70
|
-
console.error('❌ TLS CA file not found, continuing without certificate');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Debug directory listing (only in development)
|
|
74
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
75
|
-
try {
|
|
76
|
-
console.log('📁 Current directory contents:');
|
|
77
|
-
fs.readdirSync(process.cwd()).forEach(item => {
|
|
78
|
-
const stats = fs.statSync(path.join(process.cwd(), item));
|
|
79
|
-
console.log(` ${stats.isDirectory() ? '📁' : '📄'} ${item}`);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const securityDir = path.join(process.cwd(), 'security');
|
|
83
|
-
if (fs.existsSync(securityDir)) {
|
|
84
|
-
console.log('📁 Security directory contents:');
|
|
85
|
-
fs.readdirSync(securityDir).forEach(item => {
|
|
86
|
-
console.log(` 📄 ${item}`);
|
|
87
|
-
});
|
|
88
|
-
} else {
|
|
89
|
-
console.log('❌ Security directory does not exist at:', securityDir);
|
|
90
|
-
}
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.log('❌ Error listing directory contents:', error.message);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
console.log('📄 DocumentDB not enabled, using standard MongoDB configuration');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
25
|
const checkIsConnected = () => mongoose.connection?.readyState > 0;
|
|
102
26
|
|
|
103
27
|
const connectToDatabase = async () => {
|
|
@@ -107,12 +31,132 @@ const connectToDatabase = async () => {
|
|
|
107
31
|
}
|
|
108
32
|
|
|
109
33
|
console.log('🔗 Connecting to database...');
|
|
34
|
+
|
|
35
|
+
// Load appDefinition inside the function
|
|
36
|
+
try {
|
|
37
|
+
console.log(
|
|
38
|
+
'🔍 Loading app definition for DocumentDB configuration...'
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const backendPath = findNearestBackendPackageJson();
|
|
42
|
+
if (!backendPath) {
|
|
43
|
+
throw new Error('Could not find backend package.json');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const backendDir = path.dirname(backendPath);
|
|
47
|
+
const backendFilePath = path.join(backendDir, 'index.js');
|
|
48
|
+
if (!fs.existsSync(backendFilePath)) {
|
|
49
|
+
throw new Error('Could not find index.js');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const backend = require(backendFilePath);
|
|
53
|
+
appDefinition = backend.Definition;
|
|
54
|
+
|
|
55
|
+
console.log('📁 AppDefinition content:', JSON.stringify(appDefinition));
|
|
56
|
+
|
|
57
|
+
// Add DocumentDB TLS configuration if enabled
|
|
58
|
+
if (appDefinition.database?.documentDB?.enable === true) {
|
|
59
|
+
console.log('📄 DocumentDB configuration detected, enabling TLS');
|
|
60
|
+
console.log('📁 Current working directory:', process.cwd());
|
|
61
|
+
console.log(
|
|
62
|
+
'📋 App definition database config:',
|
|
63
|
+
JSON.stringify(appDefinition.database, null, 2)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
mongoConfig.tls = true;
|
|
67
|
+
|
|
68
|
+
// Set TLS CA file path if specified
|
|
69
|
+
if (appDefinition.database.documentDB.tlsCAFile) {
|
|
70
|
+
const tlsCAFile = appDefinition.database.documentDB.tlsCAFile;
|
|
71
|
+
|
|
72
|
+
// Basic safety: reject obviously dangerous paths
|
|
73
|
+
if (tlsCAFile.includes('..') || path.isAbsolute(tlsCAFile)) {
|
|
74
|
+
console.warn(
|
|
75
|
+
'⚠️ Rejecting potentially unsafe tlsCAFile path:',
|
|
76
|
+
tlsCAFile
|
|
77
|
+
);
|
|
78
|
+
} else {
|
|
79
|
+
const tlsCAFilePath = path.resolve(
|
|
80
|
+
process.cwd(),
|
|
81
|
+
tlsCAFile
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
console.log('📄 DocumentDB TLS CA file configured:');
|
|
85
|
+
console.log(' 📎 Original path:', tlsCAFile);
|
|
86
|
+
console.log(' 📎 Resolved path:', tlsCAFilePath);
|
|
87
|
+
console.log(
|
|
88
|
+
' 📄 File exists:',
|
|
89
|
+
fs.existsSync(tlsCAFilePath)
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Only set tlsCAFile if the file actually exists
|
|
93
|
+
if (fs.existsSync(tlsCAFilePath)) {
|
|
94
|
+
mongoConfig.tlsCAFile = tlsCAFilePath;
|
|
95
|
+
console.log('✅ TLS CA file configured successfully');
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`TLS CA file not found at ${tlsCAFilePath}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Debug directory listing (only in development)
|
|
103
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
104
|
+
try {
|
|
105
|
+
console.log('📁 Current directory contents:');
|
|
106
|
+
fs.readdirSync(process.cwd()).forEach((item) => {
|
|
107
|
+
const stats = fs.statSync(
|
|
108
|
+
path.join(process.cwd(), item)
|
|
109
|
+
);
|
|
110
|
+
console.log(
|
|
111
|
+
` ${
|
|
112
|
+
stats.isDirectory() ? '📁' : '📄'
|
|
113
|
+
} ${item}`
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const securityDir = path.join(
|
|
118
|
+
process.cwd(),
|
|
119
|
+
'security'
|
|
120
|
+
);
|
|
121
|
+
if (fs.existsSync(securityDir)) {
|
|
122
|
+
console.log('📁 Security directory contents:');
|
|
123
|
+
fs.readdirSync(securityDir).forEach((item) => {
|
|
124
|
+
console.log(` 📄 ${item}`);
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
console.log(
|
|
128
|
+
'❌ Security directory does not exist at:',
|
|
129
|
+
securityDir
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.log(
|
|
134
|
+
'❌ Error listing directory contents:',
|
|
135
|
+
error.message
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
console.log(
|
|
143
|
+
'📄 DocumentDB not enabled, using standard MongoDB configuration'
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error('❌ Error loading app definition:', error.message);
|
|
148
|
+
debug(
|
|
149
|
+
'Could not load app definition for DocumentDB configuration:',
|
|
150
|
+
error.message
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
110
154
|
console.log('🔗 MongoDB URI:', process.env.MONGO_URI ? 'SET' : 'NOT SET');
|
|
111
155
|
console.log('🔧 Final mongoConfig:', JSON.stringify(mongoConfig, null, 2));
|
|
112
|
-
|
|
156
|
+
|
|
113
157
|
debug('=> using new database connection');
|
|
114
158
|
await mongoose.connect(process.env.MONGO_URI, mongoConfig);
|
|
115
|
-
debug('Connection state:',
|
|
159
|
+
debug('Connection state:', mongoose.STATES[mongoose.connection.readyState]);
|
|
116
160
|
mongoose.connection.on('error', (error) => flushDebugLog(error));
|
|
117
161
|
};
|
|
118
162
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.419.
|
|
4
|
+
"version": "2.0.0--canary.419.f684df1.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@hapi/boom": "^10.0.1",
|
|
7
7
|
"aws-sdk": "^2.1200.0",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"uuid": "^9.0.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@friggframework/eslint-config": "2.0.0--canary.419.
|
|
26
|
-
"@friggframework/prettier-config": "2.0.0--canary.419.
|
|
27
|
-
"@friggframework/test": "2.0.0--canary.419.
|
|
25
|
+
"@friggframework/eslint-config": "2.0.0--canary.419.f684df1.0",
|
|
26
|
+
"@friggframework/prettier-config": "2.0.0--canary.419.f684df1.0",
|
|
27
|
+
"@friggframework/test": "2.0.0--canary.419.f684df1.0",
|
|
28
28
|
"@types/lodash": "4.17.15",
|
|
29
29
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
30
30
|
"chai": "^4.3.6",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f684df1e01022a10465fd21c39317f3105ab5ef2"
|
|
60
60
|
}
|