@friggframework/core 2.0.0--canary.416.a2540c3.0 → 2.0.0--canary.419.e387a34.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.
Files changed (2) hide show
  1. package/database/mongo.js +67 -0
  2. package/package.json +5 -5
package/database/mongo.js CHANGED
@@ -5,10 +5,29 @@
5
5
  const { Encrypt } = require('../encrypt');
6
6
  const { mongoose } = require('./mongoose');
7
7
  const { debug, flushDebugLog } = require('../logs');
8
+ const { findNearestBackendPackageJson } = require('../utils');
9
+ const path = require('path');
10
+ const fs = require('fs');
8
11
 
9
12
  mongoose.plugin(Encrypt);
10
13
  mongoose.set('applyPluginsToDiscriminators', true); // Needed for LHEncrypt
11
14
 
15
+ // Load app definition to check for DocumentDB configuration
16
+ let appDefinition = {};
17
+ try {
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
+
12
31
  // Buffering means mongoose will queue up operations if it gets
13
32
  // With serverless, better to fail fast if not connected.
14
33
  // disconnected from MongoDB and send them when it reconnects.
@@ -20,6 +39,50 @@ const mongoConfig = {
20
39
  serverSelectionTimeoutMS: 5000,
21
40
  };
22
41
 
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 tlsCAFilePath = path.resolve(process.cwd(), appDefinition.database.documentDB.tlsCAFile);
53
+ mongoConfig.tlsCAFile = tlsCAFilePath;
54
+
55
+ console.log('📄 DocumentDB TLS CA file configured:');
56
+ console.log(' 📎 Original path:', appDefinition.database.documentDB.tlsCAFile);
57
+ console.log(' 📎 Resolved path:', tlsCAFilePath);
58
+ console.log(' 📄 File exists:', fs.existsSync(tlsCAFilePath));
59
+
60
+ // List current directory contents for debugging
61
+ try {
62
+ console.log('📁 Current directory contents:');
63
+ fs.readdirSync(process.cwd()).forEach(item => {
64
+ const stats = fs.statSync(path.join(process.cwd(), item));
65
+ console.log(` ${stats.isDirectory() ? '📁' : '📄'} ${item}`);
66
+ });
67
+
68
+ // Check if security directory exists
69
+ const securityDir = path.join(process.cwd(), 'security');
70
+ if (fs.existsSync(securityDir)) {
71
+ console.log('📁 Security directory contents:');
72
+ fs.readdirSync(securityDir).forEach(item => {
73
+ console.log(` 📄 ${item}`);
74
+ });
75
+ } else {
76
+ console.log('❌ Security directory does not exist at:', securityDir);
77
+ }
78
+ } catch (error) {
79
+ console.log('❌ Error listing directory contents:', error.message);
80
+ }
81
+ }
82
+ } else {
83
+ console.log('📄 DocumentDB not enabled, using standard MongoDB configuration');
84
+ }
85
+
23
86
  const checkIsConnected = () => mongoose.connection?.readyState > 0;
24
87
 
25
88
  const connectToDatabase = async () => {
@@ -28,6 +91,10 @@ const connectToDatabase = async () => {
28
91
  return;
29
92
  }
30
93
 
94
+ console.log('🔗 Connecting to database...');
95
+ console.log('🔗 MongoDB URI:', process.env.MONGO_URI ? 'SET' : 'NOT SET');
96
+ console.log('🔧 Final mongoConfig:', JSON.stringify(mongoConfig, null, 2));
97
+
31
98
  debug('=> using new database connection');
32
99
  await mongoose.connect(process.env.MONGO_URI, mongoConfig);
33
100
  debug('Connection state:', mongoose.STATES[mongoose.connection.readyState]);
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.416.a2540c3.0",
4
+ "version": "2.0.0--canary.419.e387a34.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.416.a2540c3.0",
26
- "@friggframework/prettier-config": "2.0.0--canary.416.a2540c3.0",
27
- "@friggframework/test": "2.0.0--canary.416.a2540c3.0",
25
+ "@friggframework/eslint-config": "2.0.0--canary.419.e387a34.0",
26
+ "@friggframework/prettier-config": "2.0.0--canary.419.e387a34.0",
27
+ "@friggframework/test": "2.0.0--canary.419.e387a34.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": "a2540c34c11afdb3dc06ae76d53811a2522ff36d"
59
+ "gitHead": "e387a348fdc21f44aacf0ead206444dfd07dec90"
60
60
  }