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