minimonolith 0.18.1 → 0.20.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/.env.example CHANGED
@@ -1,4 +1,4 @@
1
1
  MM_API_DB_DIALECT=sqlite
2
2
  MM_API_DB_STORAGE=:memory:
3
- MM_API_PROD_ENV=false
4
- MM_API_LOCAL_ENV=true
3
+ MM_API_PROD_ENV=FALSE
4
+ MM_API_DEV_ENV=TRUE
package/README.md CHANGED
@@ -114,6 +114,34 @@ export default ({ MODELS }) => ({
114
114
  })
115
115
  ```
116
116
 
117
+ ## App Environments
118
+
119
+ There are 4 possible environments: DEV=TRUE & PROD=FALSE, DEV=TRUE & PROD=TRUE, DEV=FALSE & PROD=TRUE, DEV=FALSE & PROD=TRUE
120
+ 1. DEV=TRUE & PROD=FALSE: This is the standard DEV environment
121
+ 2. DEV=FALSE & PROD=FALSE: This is the standard QA environment
122
+ 3. DEV=FALSE & PROD=TRUE: This is the stnadard PROD environment
123
+ 4. DEV=TRUE & PROD=TRUE: This allows to test the behavior of PROD within the "new concept" of DEV environment
124
+
125
+ To better understand their relevance:
126
+ 1. The "new concept" DEV environments (DEV=TRUE) aim to make the api crash if an "important" error happens
127
+ 1. Its current only difference is it makes it crash on error at service registration phase
128
+ 2. The "new concept" QA environments (PROD=FALSE) aim at logging data about the system which on production environments would be forbiden personal information
129
+ 1. This is relevant because replication of QA activities (even security QA activities) depend heavily on this
130
+
131
+ The current App environment is determined on the values of MM_API_DEV ENV [TRUE/FALSE] and MM_API_PROD_ENV [TRUE/FALSE]:
132
+
133
+ ```makefile
134
+ # .env standard dev environment
135
+ MM_API_DEV_ENV=TRUE
136
+ MM_API_PROD_ENV=FALSE
137
+ [...]
138
+ ```
139
+
140
+ *NOTICE*: If this variables are not added to .env/Lambda environment it is assumed standard PROD environment (DEV=FLASE & PROD=TRUE)
141
+ - This means that sequelize will not alter automatically tables having mismatches with defined model.js files
142
+ - Database dialect/credentials detected will not be printed
143
+ - Critical errors will not make the app crash
144
+
117
145
  ## Database Authentication
118
146
 
119
147
  To set up authentication for the database, you need to provide the necessary environment variables in a `.env` file. Depending on the database dialect the required variables will differ.
@@ -121,27 +149,32 @@ To set up authentication for the database, you need to provide the necessary env
121
149
  For MySQL:
122
150
 
123
151
  ```makefile
152
+ MM_API_DEV_ENV=TRUE
153
+ MM_API_PROD_ENV=FALSE
124
154
  MM_API_DB_DIALECT=mysql
125
155
  MM_API_DB_HOST=<your_database_endpoint>
126
156
  MM_API_DB_PORT=<your_database_port>
127
157
  MM_API_DB_DATABASE=<your_database_name>
128
158
  MM_API_DB_USERNAME=<your_database_username>
129
159
  MM_API_DB_PASSWORD=<your_database_password>
130
- MM_API_LOCAL_ENV=true
131
- MM_API_PROD_ENV=false
132
160
  ```
133
161
 
134
162
  For SQLite:
135
163
 
136
164
  ```makefile
165
+ MM_API_DEV_ENV=TRUE
166
+ MM_API_PROD_ENV=FALSE
137
167
  MM_API_DB_DIALECT=sqlite
138
168
  MM_API_DB_STORAGE=:memory: # For in-memory SQLite database
139
169
  # Or
140
170
  MM_API_DB_STORAGE=path/to/your/sqlite/file.db # For file-based SQLite database
141
171
  MM_API_DB_DATABASE=<your_database_name>
142
- MM_API_LOCAL_ENV=true
143
- MM_API_PROD_ENV=false
144
172
  ```
145
173
 
146
- Make sure to replace the placeholders with your actual database credentials. The `MM_API_LOCAL_ENV` variable is used to allow Sequelize to alter table structure automatically when working locally, while the `MM_API_PROD_ENV` variable controls logging of secret credentials for debugging purposes in non-production environments.
147
-
174
+ Make sure to replace the placeholders with your actual database credentials.
175
+ - `MM_API_DEV_ENV=TRUE` allows Sequelize to alter table structure automatically when working locally
176
+ - `MM_API_PROD_ENV=FALSE` allows logging of DB credentials for debugging purposes in non-production environments
177
+ - We consider high quality logging important for app performance and evolution
178
+ - However we recommend automatic DB credentials updates (daily) High quality logging does not mean
179
+ giving away your infraestructure to hackers
180
+ - At the risk of stating the obvious do not store personal information at the QA database
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minimonolith",
3
3
  "type": "module",
4
- "version": "0.18.1",
4
+ "version": "0.20.0",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -1 +1 @@
1
- export default ERROR => { if (process.env.MM_API_LOCAL_ENV) throw ERROR; };
1
+ export default ERROR => { if (process.env.MM_API_DEV_ENV==='TRUE') throw ERROR; };
@@ -35,7 +35,7 @@ const registerDatabaseService = async API => {
35
35
  const SEQUELIZE_OPTIONS = { dialect: MM_API_DB_DIALECT, host: MM_API_DB_HOST,
36
36
  port: MM_API_DB_PORT, storage: MM_API_DB_STORAGE, logging: false };
37
37
 
38
- logger.dev({ ROUTE_CODE, MM_API_DB_VARS: { MM_API_DB_DIALECT,
38
+ logger.qa({ ROUTE_CODE, MM_API_DB_VARS: { MM_API_DB_DIALECT,
39
39
  MM_API_DB_USER, MM_API_DB_PASS, MM_API_DB_HOST, MM_API_DB_PORT, MM_API_DB_DB, MM_API_DB_STORAGE }});
40
40
  API.ORM = new Sequelize(MM_API_DB_DB, MM_API_DB_USER, MM_API_DB_PASS, SEQUELIZE_OPTIONS);
41
41
  establishConnection(API.ORM);
@@ -1,5 +1,5 @@
1
1
  export default {
2
2
  error: (...ERROR) => { console.error(...ERROR) },
3
3
  log: (...MESSAGE) => { console.log(...MESSAGE) },
4
- dev: (...MESSAGE) => { if (!process.env.MM_API_PROD_ENV) console.log(...MESSAGE) }
4
+ qa: (...MESSAGE) => { if (process.env.MM_API_PROD_ENV==='FALSE') console.log(...MESSAGE) }
5
5
  };
@@ -24,7 +24,7 @@ const loadAndSyncModels = async API => {
24
24
  });
25
25
 
26
26
  logger.log({ ROUTE_CODE, SYNCING_ORM: 'WAITING_FOR_ORM_SYNCING' });
27
- await API.ORM.sync({ alter: process.env.MM_API_LOCAL_ENV ? true : false });
27
+ await API.ORM.sync({ alter: process.env.MM_API_DEV_ENV==='TRUE' ? true : false });
28
28
  logger.log({ ROUTE_CODE, SYNCING_ORM: 'DONE_ORM_SYNCING' });
29
29
 
30
30
  return MODELS;