minimonolith 0.24.1 → 0.25.4

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 (153) hide show
  1. package/README.md +209 -208
  2. package/api/api.js +5 -0
  3. package/api/getModels/handler.js +5 -0
  4. package/api/getModels/out.js +3 -0
  5. package/api/getNewAPI/handler.js +53 -0
  6. package/api/getNewAPI/in.js +7 -0
  7. package/api/getNewAPI/out.js +3 -0
  8. package/api/getORM/handler.js +5 -0
  9. package/api/getORM/out.js +3 -0
  10. package/api/getSchemas/handler.js +5 -0
  11. package/api/getSchemas/out.js +3 -0
  12. package/api/getService/handler.js +8 -0
  13. package/api/getService/in.js +6 -0
  14. package/api/getService/out.js +3 -0
  15. package/api/getServices/handler.js +5 -0
  16. package/api/getServices/out.js +3 -0
  17. package/api/getSyncedHandler/handler.js +40 -0
  18. package/api/getSyncedHandler/in.js +3 -0
  19. package/api/getSyncedHandler/out.js +3 -0
  20. package/api/postModel/handler.js +8 -0
  21. package/api/postModel/in.js +6 -0
  22. package/api/postModule/handler.js +31 -0
  23. package/api/postModule/in.js +7 -0
  24. package/api/postORM/handler.js +7 -0
  25. package/api/postORM/in.js +5 -0
  26. package/api/postRawModule/handler.js +9 -0
  27. package/api/postRawModule/in.js +9 -0
  28. package/api/postRoute/handler.js +9 -0
  29. package/api/postRoute/in.js +7 -0
  30. package/api/postSchema/handler.js +8 -0
  31. package/api/postSchema/in.js +6 -0
  32. package/api/services.js +15 -0
  33. package/{src/autotest/getMethodTest/index.js → autotest/getMethodTest/handler.js} +14 -12
  34. package/autotest/getMethodTest/in.js +3 -0
  35. package/autotest/getMethodTest/out.js +3 -0
  36. package/{src/autotest → autotest}/getTestServerResponse/index.js +14 -14
  37. package/autotest/services.js +1 -0
  38. package/control/get/handler.js +8 -0
  39. package/control/get/in.js +6 -0
  40. package/control/get/out.js +3 -0
  41. package/control/services.js +1 -0
  42. package/database/post/handler.js +24 -0
  43. package/database/post/in.js +12 -0
  44. package/database/postConnection/handler.js +27 -0
  45. package/database/postConnection/in.js +5 -0
  46. package/database/postConnection/out.js +3 -0
  47. package/database/services.js +1 -0
  48. package/environment/getDBEnvVars/handler.js +6 -0
  49. package/environment/getDBEnvVars/in.js +3 -0
  50. package/environment/getDBEnvVars/out.js +3 -0
  51. package/environment/getENVEnvVars/handler.js +7 -0
  52. package/environment/getENVEnvVars/in.js +3 -0
  53. package/environment/getENVEnvVars/out.js +3 -0
  54. package/environment/postEnvFile/handler.js +20 -0
  55. package/environment/postEnvFile/in.js +6 -0
  56. package/{src/environment → environment}/postTestEnvironment/index.js +6 -6
  57. package/environment/services.js +5 -0
  58. package/{src/error → error}/index.js +4 -4
  59. package/{src/error → error}/postCompiletime/index.js +13 -13
  60. package/{src/error → error}/postRuntime/index.js +7 -7
  61. package/health/post/handler.js +14 -0
  62. package/health/services.js +1 -0
  63. package/index.js +23 -15
  64. package/{src/log → log}/index.js +5 -5
  65. package/{src/log → log}/post/index.js +3 -3
  66. package/{src/log → log}/postError/index.js +3 -3
  67. package/{src/log → log}/postQA/index.js +3 -3
  68. package/model/getSynced/handler.js +28 -0
  69. package/model/post/handler.js +17 -0
  70. package/model/post/in.js +6 -0
  71. package/model/services.js +1 -0
  72. package/modules.js +19 -0
  73. package/package.json +33 -32
  74. package/{src/server → server}/getNodejsServerHandler/index.js +70 -68
  75. package/server/getServerFactory/handler.js +17 -0
  76. package/server/getServerFactory/in.js +8 -0
  77. package/server/getServerFactory/out.js +3 -0
  78. package/server/services.js +1 -0
  79. package/service/getParsedCode/handler.js +22 -0
  80. package/service/getParsedCode/in.js +6 -0
  81. package/service/getParsedCode/out.js +6 -0
  82. package/service/getParsedEvent/handler.js +12 -0
  83. package/service/getParsedEvent/in.js +5 -0
  84. package/service/getParsedEvent/out.js +6 -0
  85. package/{src/method/getResponseCode/index.js → service/getResponseCode/handler.js} +11 -9
  86. package/service/getResponseCode/in.js +3 -0
  87. package/service/getResponseCode/out.js +3 -0
  88. package/service/getRouteCode/handler.js +15 -0
  89. package/service/getRouteCode/in.js +6 -0
  90. package/service/getRouteCode/out.js +3 -0
  91. package/service/getType/handler.js +11 -0
  92. package/service/getType/in.js +5 -0
  93. package/service/getType/out.js +3 -0
  94. package/{src/method → service}/postResponse/index.js +13 -13
  95. package/service/postRoute/handler.js +82 -0
  96. package/service/postRoute/in.js +6 -0
  97. package/service/services.js +9 -0
  98. package/validation/getParsedAsync/handler.js +38 -0
  99. package/validation/getParsedAsync/in.js +9 -0
  100. package/validation/getParsedAsync/out.js +6 -0
  101. package/validation/services.js +1 -0
  102. package/yarn-error.log +4104 -0
  103. package/zdb/components.js +1 -0
  104. package/zdb/getAssertExists/handler.js +16 -0
  105. package/zdb/getAssertExists/in.js +6 -0
  106. package/zdb/getAssertExists/out.js +3 -0
  107. package/zdb/getAssertNotExists/handler.js +16 -0
  108. package/zdb/getAssertNotExists/in.js +6 -0
  109. package/zdb/getAssertNotExists/out.js +3 -0
  110. package/zdb/getAssertSafeInt/handler.js +15 -0
  111. package/zdb/getAssertSafeInt/in.js +6 -0
  112. package/zdb/getAssertSafeInt/out.js +3 -0
  113. package/src/api/get/index.js +0 -19
  114. package/src/api/getNewAPI/index.js +0 -14
  115. package/src/api/getSyncedHandler/index.js +0 -24
  116. package/src/api/index.js +0 -4
  117. package/src/api/postService/index.js +0 -34
  118. package/src/autotest/getMethodTest/back.index.js +0 -29
  119. package/src/autotest/index.js +0 -3
  120. package/src/control/get/index.js +0 -3
  121. package/src/control/index.js +0 -3
  122. package/src/database/index.js +0 -4
  123. package/src/database/post/index.js +0 -28
  124. package/src/database/postConnection/index.js +0 -25
  125. package/src/environment/getDBEnvVars/index.js +0 -4
  126. package/src/environment/getENVEnvVars/index.js +0 -4
  127. package/src/environment/index.js +0 -4
  128. package/src/environment/postEnvFile/index.js +0 -13
  129. package/src/event/getParsedEvent/index.js +0 -9
  130. package/src/event/index.js +0 -3
  131. package/src/health/index.js +0 -3
  132. package/src/health/post/index.js +0 -10
  133. package/src/method/getParsedCode/index.js +0 -13
  134. package/src/method/getRouteCode/index.js +0 -12
  135. package/src/method/getType/index.js +0 -9
  136. package/src/method/index.js +0 -7
  137. package/src/method/post/index.js +0 -56
  138. package/src/middleware/index.js +0 -4
  139. package/src/middleware/postCors/index.js +0 -20
  140. package/src/middleware/postError/index.js +0 -10
  141. package/src/model/getSynced/index.js +0 -22
  142. package/src/model/index.js +0 -4
  143. package/src/model/post/index.js +0 -11
  144. package/src/path/getProjectRoot/index.js +0 -14
  145. package/src/path/index.js +0 -3
  146. package/src/server/getServerFactory/index.js +0 -14
  147. package/src/server/index.js +0 -3
  148. package/src/validation/dbValidation.js +0 -33
  149. package/src/validation/get/index.js +0 -16
  150. package/src/validation/getOptionalObject/index.js +0 -8
  151. package/src/validation/index.js +0 -8
  152. package/src/validation/postError/index.js +0 -29
  153. /package/{src/middleware/postCors → api}/corsHeaders.js +0 -0
package/README.md CHANGED
@@ -1,208 +1,209 @@
1
- # minimonolith
2
-
3
- [![codecov](https://codecov.io/gh/DeepHackDev/minimonolith-api/branch/master/graph/badge.svg?token=ORFNKKJRSE)](https://codecov.io/gh/DeepHackDev/minimonolith-lib)
4
-
5
- `minimonolith` is a lightweight library designed to help you build serverless APIs using AWS Lambda, with a focus on simplicity and ease of use. The library provides a straightforward structure to organize your API's services, methods, validation, and models while handling common tasks like database connection and request validation.
6
-
7
- In addition to its simplicity, `minimonolith` enables seamless inter-service communication within your API. This allows services to call one another's functionality without directly importing them, fostering a modular design. For example, you can call the get method of the todo service from the todoList service using SERVICES.todo.get({ id }). By registering services within the API, you can easily call their methods from other services, which not only promotes a clean architecture but also paves the way for future support of automated end-to-end testing.
8
-
9
- ## Example Project
10
-
11
- Here's an example project using `minimonolith`:
12
-
13
- ```go
14
- .
15
- ├── package.json
16
- ├── .gitignore
17
- ├── .env
18
- ├── server.js // For local development
19
- ├── index.js // Root of the code in a deployed AWS Lambda
20
- └── todo
21
- ├── index.js // Service 'todo' exported method handlers are declared here
22
- ├── model.js // Optional: Sequelize model for service 'todo' is declared here
23
- └── get
24
- ├── index.js // Service 'todo' method 'get' handler
25
- └── valid.js // Optional: Method 'get' handler validation, if body not empty
26
- ```
27
-
28
- ### server.js
29
-
30
- This file is used for local development. It runs a local server using `minimonolith`'s `getServer` function:
31
-
32
- ```js
33
- // server.js
34
- import { getServerFactory } from 'minimonolith';
35
-
36
- const getServer = await getServerFactory()(;
37
- const { lambdaHandler } = await import('./index.js');
38
-
39
- getServer(lambdaHandler).listen(8080);
40
- ```
41
-
42
- ### index.js
43
-
44
- This file serves as the root of the code in a deployed AWS Lambda:
45
-
46
- ```js
47
- // index.js
48
- 'use strict';
49
-
50
- import { getNewAPI } from 'minimonolith';
51
-
52
- const API = getNewAPI({
53
- PROD_ENV: process.env.PROD_ENV,
54
- DEV_ENV: process.env.DEV_ENV,
55
- });
56
-
57
- await API.postHealthService();
58
- await API.postService('todo');
59
- await API.postDatabaseService({
60
- DB_DIALECT: process.env.DB_DIALECT,
61
- DB_HOST: process.env.DB_HOST,
62
- DB_PORT: process.env.DB_PORT,
63
- DB_DB: process.env.DB_DB,
64
- DB_USER: process.env.DB_USER,
65
- DB_PASS: process.env.DB_PASS,
66
- });
67
-
68
- export const lambdaHandler = await API.getSyncedHandler();
69
- ```
70
-
71
- ### todo/index.js
72
-
73
- Here, we declare the method handlers for the `todo` service:
74
-
75
- ```js
76
- // todo/index.js
77
- export default ['getAll', 'get:id', 'post', 'patch:id', 'delete:id'];
78
- ```
79
-
80
- ### todo/model.js
81
-
82
- In this file, we define a Sequelize model for the `todo` service:
83
-
84
- ```js
85
- // todo/model.js
86
- export default serviceName => (orm, types) => {
87
- const schema = orm.define(serviceName, {
88
- name: {
89
- type: types.STRING,
90
- allowNull: false
91
- },
92
- });
93
-
94
- schema.associate = MODELS => {}; // e.g. MODELS.todo.belongsTo(MODELS.todoList, {...});
95
-
96
- return schema;
97
- };
98
- ```
99
-
100
- ### todo/get/index.js
101
-
102
- This file contains the `get:id` method handler for the `todo` service. It retrieves a todo item by its ID:
103
-
104
- ```js
105
- // todo/get/index.js
106
- export default async ({ body, MODELS }) => {
107
- return await MODELS.todo.findOne({ where: { id: body.id } });
108
- }
109
- ```
110
-
111
- ### todo/get/valid.js
112
-
113
- This file validates the `get:id` method's input, ensuring that the provided `id` is a string and exists in the `todo` model:
114
-
115
- ```js
116
- // todo/get/valid.js
117
- import { z, zdb } from 'minimonolith';
118
-
119
- export default ({ MODELS }) => ({
120
- id: z.string()
121
- .superRefine(zdb.isSafeInt('id'))
122
- .transform(id => parseInt(id))
123
- .superRefine(zdb.exists(MODELS.todo, 'id')),
124
- })
125
- ```
126
-
127
- ## Response Codes
128
-
129
- ### Success
130
-
131
- - POST -> 201
132
- - DELETE -> 204
133
- - Everything else -> 200
134
-
135
- ### Invalid Request
136
-
137
- - ANY -> 400
138
-
139
- ### Runtime Error
140
-
141
- - ANY -> 500
142
-
143
- ## App Environments
144
-
145
- There are 4 possible environments:
146
- 1. DEV=TRUE + PROD=FALSE: This is the standard DEV environment
147
- 2. DEV=FALSE + PROD=FALSE: This is the standard QA environment
148
- 3. DEV=FALSE + PROD=TRUE: This is the stnadard PROD environment
149
- 4. DEV=TRUE + PROD=TRUE: This allows to test the behavior of PROD within the "new concept" of DEV environment
150
-
151
- To better understand their relevance:
152
- 1. The "new concept" DEV environments (DEV=TRUE) aim to make the api crash if an "important" error happens
153
- - Its current only difference is it makes it crash on error at service registration phase
154
- - Some may think QA should also fail on "important" errors They can use DEV=TRUE there But some do training activities on QA that must be minimally disrupted
155
- 2. The "new concept" QA environments (PROD=FALSE) aim at logging data about the system which on production environments would be forbiden personal information
156
- - This is relevant because replication of QA activities (even security QA activities) depend heavily on this
157
-
158
- The current App environment is determined on the values of DEV ENV [TRUE/FALSE] and PROD_ENV [TRUE/FALSE]
159
- Assuming using same env variables as used at index.js above
160
-
161
- ```makefile
162
- # .env standard dev environment
163
- DEV_ENV=TRUE
164
- PROD_ENV=FALSE
165
- TEST_ENV=FALSE
166
- [...]
167
- ```
168
-
169
- *NOTICE*: Default environment it is assumed standard PROD environment (DEV=FLASE + PROD=TRUE)
170
- - This means that sequelize will not alter automatically tables having mismatches with defined model.js files
171
- - Database dialect/credentials detected will not be printed
172
- - Critical errors will not make the app crash
173
-
174
- ## Database Authentication
175
-
176
- To set up authentication for the database you need to pass necessary variables to postDatabaseService as at index.js above.
177
- Assuming using same env variable names as at index.js above
178
-
179
- For MySQL:
180
-
181
- ```makefile
182
- DEV_ENV=TRUE
183
- PROD_ENV=FALSE
184
- DB_DIALECT=mysql
185
- DB_HOST=<your_database_endpoint>
186
- DB_PORT=<your_database_port>
187
- DB_DB=<your_database_name>
188
- DB_USER=<your_database_username>
189
- DB_PASS=<your_database_password>
190
- ```
191
-
192
- For SQLite in memory:
193
-
194
- ```makefile
195
- DEV_ENV=TRUE
196
- PROD_ENV=FALSE
197
- DB_DIALECT=sqlite
198
- DB_DB=<your_database_name>
199
- DB_STORAGE=:memory: # Need to also pass to API.postDatabaseService()
200
- ```
201
-
202
- Make sure to replace the placeholders with your actual database credentials.
203
- - `DEV_ENV=TRUE` allows Sequelize to alter table structure automatically when working locally
204
- - `PROD_ENV=FALSE` allows logging of DB credentials for debugging purposes in non-production environments
205
- - We consider high quality logging important for app performance and evolution
206
- - However we recommend automatic DB credentials updates (daily) High quality logging does not mean
207
- giving away your infraestructure to hackers
208
- - At the risk of stating the obvious do not store personal information at the QA database
1
+ # minimonolith
2
+
3
+ [![codecov](https://codecov.io/gh/DeepHackDev/minimonolith-api/branch/master/graph/badge.svg?token=ORFNKKJRSE)](https://codecov.io/gh/DeepHackDev/minimonolith-lib)
4
+
5
+ `minimonolith` is a lightweight library designed to help you build serverless APIs using AWS Lambda, with a focus on simplicity and ease of use. The library provides a straightforward structure to organize your API's services, methods, validation, and models while handling common tasks like database connection and request validation.
6
+
7
+ In addition to its simplicity, `minimonolith` enables seamless inter-service communication within your API. This allows services to call one another's functionality without directly importing them, fostering a modular design. For example, you can call the get method of the todo service from the todoList service using SERVICES.todo.get({ id }). By registering services within the API, you can easily call their methods from other services, which not only promotes a clean architecture but also paves the way for future support of automated end-to-end testing.
8
+
9
+ ## Example Project
10
+
11
+ Here's an example project using `minimonolith`:
12
+
13
+ ```go
14
+ .
15
+ ├── package.json
16
+ ├── .gitignore
17
+ ├── .env
18
+ ├── server.js // For local development
19
+ ├── index.js // Root of the code in a deployed AWS Lambda
20
+ └── todo
21
+ ├── services.js // Module 'todo' exported services are declared here
22
+ ├── model.js // Optional: Sequelize model for module 'todo' is declared here
23
+ └── get
24
+ ├── handler.js // Module 'todo' service 'get' handler
25
+ └── in.js // Optional: Service 'get' input validation, if body not empty
26
+ └── in.js // Optional: Service 'get' output validation, if body not empty
27
+ ```
28
+
29
+ ### server.js
30
+
31
+ This file is used for local development. It runs a local server using `minimonolith`'s `getServer` function:
32
+
33
+ ```js
34
+ // server.js
35
+ import { getServerFactory } from 'minimonolith';
36
+
37
+ const getServer = await getServerFactory()(;
38
+ const { lambdaHandler } = await import('./index.js');
39
+
40
+ getServer(lambdaHandler).listen(8080);
41
+ ```
42
+
43
+ ### index.js
44
+
45
+ This file serves as the root of the code in a deployed AWS Lambda:
46
+
47
+ ```js
48
+ // index.js
49
+ 'use strict';
50
+
51
+ import { getNewAPI } from 'minimonolith';
52
+
53
+ const API = getNewAPI({
54
+ PROD_ENV: process.env.PROD_ENV,
55
+ DEV_ENV: process.env.DEV_ENV,
56
+ });
57
+
58
+ await API.postHealthService();
59
+ await API.postModule('todo');
60
+ await API.postDatabaseService({
61
+ DB_DIALECT: process.env.DB_DIALECT,
62
+ DB_HOST: process.env.DB_HOST,
63
+ DB_PORT: process.env.DB_PORT,
64
+ DB_DB: process.env.DB_DB,
65
+ DB_USER: process.env.DB_USER,
66
+ DB_PASS: process.env.DB_PASS,
67
+ });
68
+
69
+ export const lambdaHandler = await API.getSyncedHandler();
70
+ ```
71
+
72
+ ### todo/index.js
73
+
74
+ Here, we declare the service routes for the `todo` module:
75
+
76
+ ```js
77
+ // todo/services.js
78
+ export default ['getAll', 'get:id', 'post', 'patch:id', 'delete:id'];
79
+ ```
80
+
81
+ ### todo/model.js
82
+
83
+ In this file, we define a Sequelize model for the `todo` module:
84
+
85
+ ```js
86
+ // todo/model.js
87
+ export default moduleName => (orm, types) => {
88
+ const schema = orm.define(moduleName, {
89
+ name: {
90
+ type: types.STRING,
91
+ allowNull: false
92
+ },
93
+ });
94
+
95
+ schema.associate = MODELS => {}; // e.g. MODELS.todo.belongsTo(MODELS.todoList, {...});
96
+
97
+ return schema;
98
+ };
99
+ ```
100
+
101
+ ### todo/get/index.js
102
+
103
+ This file contains the `get:id` route for the `todo` module. It retrieves a todo item by its ID:
104
+
105
+ ```js
106
+ // todo/get/index.js
107
+ export default async ({ body, MODELS }) => {
108
+ return await MODELS.todo.findOne({ where: { id: body.id } });
109
+ }
110
+ ```
111
+
112
+ ### todo/get/valid.js
113
+
114
+ This file validates the `get:id` service's input, ensuring that the provided `id` is a string and exists in the `todo` model:
115
+
116
+ ```js
117
+ // todo/get/valid.js
118
+ import { z, zdb } from 'minimonolith';
119
+
120
+ export default ({ MODELS }) => ({
121
+ id: z.string()
122
+ .superRefine(zdb.getIsSafeInt('id'))
123
+ .transform(id => parseInt(id))
124
+ .superRefine(zdb.getExists(MODELS.todo, 'id')),
125
+ })
126
+ ```
127
+
128
+ ## Response Codes
129
+
130
+ ### Success
131
+
132
+ - POST -> 201
133
+ - DELETE -> 204
134
+ - Everything else -> 200
135
+
136
+ ### Invalid Request
137
+
138
+ - ANY -> 400
139
+
140
+ ### Runtime Error
141
+
142
+ - ANY -> 500
143
+
144
+ ## App Environments
145
+
146
+ There are 4 possible environments:
147
+ 1. DEV=TRUE + PROD=FALSE: This is the standard DEV environment
148
+ 2. DEV=FALSE + PROD=FALSE: This is the standard QA environment
149
+ 3. DEV=FALSE + PROD=TRUE: This is the stnadard PROD environment
150
+ 4. DEV=TRUE + PROD=TRUE: This allows to test the behavior of PROD within the "new concept" of DEV environment
151
+
152
+ To better understand their relevance:
153
+ 1. The "new concept" DEV environments (DEV=TRUE) aim to make the api crash if an "important" error happens
154
+ - Its current only difference is it makes it crash on error at service registration phase
155
+ - Some may think QA should also fail on "important" errors They can use DEV=TRUE there But some do training activities on QA that must be minimally disrupted
156
+ 2. The "new concept" QA environments (PROD=FALSE) aim at logging data about the system which on production environments would be forbiden personal information
157
+ - This is relevant because replication of QA activities (even security QA activities) depend heavily on this
158
+
159
+ The current App environment is determined on the values of DEV ENV [TRUE/FALSE] and PROD_ENV [TRUE/FALSE]
160
+ Assuming using same env variables as used at index.js above
161
+
162
+ ```makefile
163
+ # .env standard dev environment
164
+ DEV_ENV=TRUE
165
+ PROD_ENV=FALSE
166
+ TEST_ENV=FALSE
167
+ [...]
168
+ ```
169
+
170
+ *NOTICE*: Default environment it is assumed standard PROD environment (DEV=FLASE + PROD=TRUE)
171
+ - This means that sequelize will not alter automatically tables having mismatches with defined model.js files
172
+ - Database dialect/credentials detected will not be printed
173
+ - Critical errors will not make the app crash
174
+
175
+ ## Database Authentication
176
+
177
+ To set up authentication for the database you need to pass necessary variables to postDatabaseService as at index.js above.
178
+ Assuming using same env variable names as at index.js above
179
+
180
+ For MySQL:
181
+
182
+ ```makefile
183
+ DEV_ENV=TRUE
184
+ PROD_ENV=FALSE
185
+ DB_DIALECT=mysql
186
+ DB_HOST=<your_database_endpoint>
187
+ DB_PORT=<your_database_port>
188
+ DB_DB=<your_database_name>
189
+ DB_USER=<your_database_username>
190
+ DB_PASS=<your_database_password>
191
+ ```
192
+
193
+ For SQLite in memory:
194
+
195
+ ```makefile
196
+ DEV_ENV=TRUE
197
+ PROD_ENV=FALSE
198
+ DB_DIALECT=sqlite
199
+ DB_DB=<your_database_name>
200
+ DB_STORAGE=:memory: # Need to also pass to API.postDatabaseService()
201
+ ```
202
+
203
+ Make sure to replace the placeholders with your actual database credentials.
204
+ - `DEV_ENV=TRUE` allows Sequelize to alter table structure automatically when working locally
205
+ - `PROD_ENV=FALSE` allows logging of DB credentials for debugging purposes in non-production environments
206
+ - We consider high quality logging important for app performance and evolution
207
+ - However we recommend automatic DB credentials updates (daily) High quality logging does not mean
208
+ giving away your infraestructure to hackers
209
+ - At the risk of stating the obvious do not store personal information at the QA database
package/api/api.js ADDED
@@ -0,0 +1,5 @@
1
+ let API = undefined;
2
+
3
+ export const setAPI = api => { API = api; };
4
+
5
+ export default () => API;
@@ -0,0 +1,5 @@
1
+ import API from '../api.js';
2
+
3
+ export default () => {
4
+ return API().MODELS;
5
+ }
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,53 @@
1
+ import getLambdaAPI from 'lambda-api';
2
+
3
+ import { getNewLib, /*LOG_SERVICE*/ } from '@minimonolith/lib';
4
+
5
+ import { setAPI } from '../api.js';
6
+
7
+ import CORS_HEADERS from '../corsHeaders.js';
8
+
9
+ export default async ({ body, SERVICES }) => {
10
+ const DEV_ENV = body.DEV_ENV;
11
+ const PROD_ENV = body.PROD_ENV;
12
+ const TEST_ENV = body.TEST_ENV;
13
+
14
+ const API = {
15
+ ROUTES: getLambdaAPI(),
16
+ //LIB: await getNewLib({ DEBUG: 'TRUE' }),
17
+ LIB: await getNewLib(),
18
+ SCHEMAS: {},
19
+ MODELS: {},
20
+ ORM: undefined,
21
+ DEV_ENV: DEV_ENV,
22
+ PROD_ENV: PROD_ENV,
23
+ TEST_ENV: TEST_ENV,
24
+ };
25
+
26
+ API.ROUTES.use((req, res, next) => {
27
+ if (req.headers['x-trigger-error']) {
28
+ /*
29
+ LOG_SERVICE.post({
30
+ ROUTE_CODE: 'LAMBDA_API',
31
+ MESSAGE: 'X_TRIGGER_ERROR_HEADER'
32
+ });
33
+ */
34
+ throw new Error('X_TRIGGER_ERROR_HEADER');
35
+ }
36
+ //console.log('passes here');
37
+ res.cors(); next();
38
+ });
39
+
40
+ API.ROUTES.options('/*', (req, res) => {
41
+ for (let k in CORS_HEADERS) { res.header(k, CORS_HEADERS[k]); }
42
+ res.status(200).send({})
43
+ });
44
+
45
+ API.postHealthService = SERVICES.health.post.handler;
46
+ API.postModule = SERVICES.api.postModule.handler;
47
+ API.postDatabaseService = SERVICES.database.post.handler;
48
+ API.getSyncedHandler = SERVICES.api.getSyncedHandler.handler;
49
+
50
+ setAPI(API);
51
+
52
+ return API;
53
+ };
@@ -0,0 +1,7 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ DEV_ENV: z.string().default('FALSE'),
5
+ PROD_ENV: z.string().default('TRUE'),
6
+ TEST_ENV: z.string().default('FALSE'),
7
+ });
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,5 @@
1
+ import API from '../api.js';
2
+
3
+ export default () => {
4
+ return API().ORM;
5
+ }
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,5 @@
1
+ import API from '../api.js';
2
+
3
+ export default () => {
4
+ return API().SCHEMAS;
5
+ }
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,8 @@
1
+ import API from '../api.js';
2
+
3
+ export default ({ body }) => {
4
+ const moduleName = body.moduleName;
5
+ const serviceName = body.serviceName;
6
+
7
+ return API().LIB.SERVICES[moduleName][serviceName];
8
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ moduleName: z.string(),
5
+ serviceName: z.string(),
6
+ });
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,5 @@
1
+ import API from '../api.js';
2
+
3
+ export default ({ body }) => {
4
+ return API().LIB.SERVICES;
5
+ }
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,40 @@
1
+ import getLambdaAPI from 'lambda-api';
2
+ //import { LOG_SERVICE } from '@minimonolith/lib';
3
+
4
+ import API from '../api.js';
5
+
6
+ export default async ({ body, ROUTE_CODE, SERVICES }) => {
7
+
8
+ API().ROUTES.use((err, req, res, next) => {
9
+ //LOG_SERVICE.postError({ ROUTE_CODE: 'LAMBDA_API', ERROR: err });
10
+ console.log({ ROUTE_CODE: 'LAMBDA_API', ERROR: err });
11
+ res.cors(); //next();
12
+ res.status(500).send({ ROUTE_CODE: 'LAMBDA_API', ERROR: err.message });
13
+ });
14
+
15
+ if (API().ORM) await SERVICES.model.getSynced.handler();
16
+
17
+ API().LIB.postAdditionalKey('MODELS', API().MODELS);
18
+
19
+ //LOG_SERVICE.post({ ROUTE_CODE, INFO: 'LISTENING' });
20
+ console.log({ ROUTE_CODE, INFO: 'LISTENING' });
21
+
22
+ return async (event, context) => {
23
+ /*
24
+ LOG_SERVICE.post({
25
+ ROUTE_CODE: 'LAMBDA_EVENT',
26
+ PATH: event.requestContext?.http?.path,
27
+ METHOD: event.requestContext?.http?.method,
28
+ });
29
+ */
30
+ console.log({
31
+ ROUTE_CODE: 'LAMBDA_EVENT',
32
+ PATH: event.requestContext?.http?.path,
33
+ METHOD: event.requestContext?.http?.method,
34
+ });
35
+
36
+ //API().ROUTES.routes(true);
37
+ //return await api.run({ event, context });
38
+ return await API().ROUTES.run(event, context);
39
+ };
40
+ };
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.unknown();
@@ -0,0 +1,3 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => z.function();
@@ -0,0 +1,8 @@
1
+ import API from '../api.js';
2
+
3
+ export default ({ body }) => {
4
+ const moduleName = body.moduleName;
5
+ const model = body.model;
6
+
7
+ API().MODELS[moduleName] = model;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from '@minimonolith/lib';
2
+
3
+ export default () => ({
4
+ moduleName: z.string(),
5
+ model: z.unknown(),
6
+ });