@friggframework/core 2.0.0--canary.548.c8ae0ca.0 → 2.0.0--canary.545.c40eca4.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 (237) hide show
  1. package/CHANGELOG.md +66 -67
  2. package/CLAUDE.md +148 -124
  3. package/README.md +165 -130
  4. package/admin-scripts/index.js +52 -0
  5. package/admin-scripts/repositories/admin-api-key-repository-documentdb.js +21 -0
  6. package/admin-scripts/repositories/admin-api-key-repository-factory.js +51 -0
  7. package/admin-scripts/repositories/admin-api-key-repository-interface.js +121 -0
  8. package/admin-scripts/repositories/admin-api-key-repository-mongo.js +155 -0
  9. package/admin-scripts/repositories/admin-api-key-repository-postgres.js +189 -0
  10. package/admin-scripts/repositories/admin-process-repository-documentdb.js +21 -0
  11. package/admin-scripts/repositories/admin-process-repository-factory.js +49 -0
  12. package/admin-scripts/repositories/admin-process-repository-interface.js +150 -0
  13. package/admin-scripts/repositories/admin-process-repository-mongo.js +213 -0
  14. package/admin-scripts/repositories/admin-process-repository-postgres.js +251 -0
  15. package/admin-scripts/repositories/script-execution-repository-documentdb.js +21 -0
  16. package/admin-scripts/repositories/script-execution-repository-factory.js +51 -0
  17. package/admin-scripts/repositories/script-execution-repository-interface.js +193 -0
  18. package/admin-scripts/repositories/script-execution-repository-mongo.js +278 -0
  19. package/admin-scripts/repositories/script-execution-repository-postgres.js +320 -0
  20. package/admin-scripts/repositories/script-schedule-repository-documentdb.js +21 -0
  21. package/admin-scripts/repositories/script-schedule-repository-factory.js +49 -0
  22. package/admin-scripts/repositories/script-schedule-repository-interface.js +108 -0
  23. package/admin-scripts/repositories/script-schedule-repository-mongo.js +179 -0
  24. package/admin-scripts/repositories/script-schedule-repository-postgres.js +210 -0
  25. package/application/commands/admin-script-commands.js +348 -0
  26. package/application/commands/integration-commands.js +12 -6
  27. package/application/index.js +5 -3
  28. package/assertions/get.js +17 -7
  29. package/associations/association.js +59 -57
  30. package/core/CLAUDE.md +222 -156
  31. package/core/Worker.js +33 -12
  32. package/credential/credential-router.js +262 -0
  33. package/credential/repositories/credential-repository-documentdb.js +71 -1
  34. package/credential/repositories/credential-repository-factory.js +4 -6
  35. package/credential/repositories/credential-repository-interface.js +8 -2
  36. package/credential/repositories/credential-repository-mongo.js +45 -4
  37. package/credential/repositories/credential-repository-postgres.js +44 -3
  38. package/credential/repositories/credential-repository.js +3 -1
  39. package/credential/use-cases/delete-credential-for-user.js +50 -0
  40. package/credential/use-cases/get-credential-for-user.js +21 -3
  41. package/credential/use-cases/list-credentials-for-user.js +31 -0
  42. package/credential/use-cases/reauthorize-credential.js +103 -0
  43. package/credential/use-cases/update-authentication-status.js +5 -2
  44. package/database/MONGODB_TRANSACTION_FIX.md +72 -52
  45. package/database/config.js +13 -59
  46. package/database/documentdb-encryption-service.js +29 -13
  47. package/database/documentdb-utils.js +21 -12
  48. package/database/encryption/README.md +53 -36
  49. package/database/encryption/encryption-schema-registry.js +29 -23
  50. package/database/encryption/field-encryption-service.js +15 -4
  51. package/database/encryption/logger.js +3 -2
  52. package/database/encryption/prisma-encryption-extension.js +5 -8
  53. package/database/prisma.js +22 -14
  54. package/database/repositories/health-check-repository-factory.js +7 -5
  55. package/database/repositories/health-check-repository-interface.js +15 -5
  56. package/database/repositories/health-check-repository-postgres.js +1 -1
  57. package/database/use-cases/check-database-health-use-case.js +3 -2
  58. package/database/use-cases/check-database-state-use-case.js +8 -7
  59. package/database/use-cases/get-database-state-via-worker-use-case.js +15 -12
  60. package/database/use-cases/get-migration-status-use-case.js +4 -2
  61. package/database/use-cases/run-database-migration-use-case.js +41 -9
  62. package/database/use-cases/test-encryption-use-case.js +4 -5
  63. package/database/use-cases/trigger-database-migration-use-case.js +9 -8
  64. package/database/utils/mongodb-collection-utils.js +11 -3
  65. package/database/utils/mongodb-schema-init.js +10 -4
  66. package/database/utils/prisma-runner.js +144 -74
  67. package/database/utils/prisma-schema-parser.js +2 -2
  68. package/docs/PROCESS_MANAGEMENT_QUEUE_SPEC.md +135 -80
  69. package/encrypt/Cryptor.js +54 -49
  70. package/encrypt/aes-encryption-key-provider.js +82 -0
  71. package/encrypt/encryption-key-provider-interface.js +50 -0
  72. package/errors/fetch-error.js +1 -1
  73. package/generated/prisma-mongodb/edge.js +59 -4
  74. package/generated/prisma-mongodb/index-browser.js +49 -1
  75. package/generated/prisma-mongodb/index.d.ts +4023 -61
  76. package/generated/prisma-mongodb/index.js +59 -4
  77. package/generated/prisma-mongodb/package.json +1 -1
  78. package/generated/prisma-mongodb/schema.prisma +87 -0
  79. package/generated/prisma-mongodb/wasm.js +59 -4
  80. package/generated/prisma-postgresql/edge.js +58 -4
  81. package/generated/prisma-postgresql/index-browser.js +48 -1
  82. package/generated/prisma-postgresql/index.d.ts +4738 -54
  83. package/generated/prisma-postgresql/index.js +58 -4
  84. package/generated/prisma-postgresql/package.json +1 -1
  85. package/generated/prisma-postgresql/schema.prisma +85 -0
  86. package/generated/prisma-postgresql/wasm.js +58 -4
  87. package/handlers/WEBHOOKS.md +104 -81
  88. package/handlers/app-definition-loader.js +53 -10
  89. package/handlers/app-handler-helpers.js +14 -3
  90. package/handlers/backend-utils.js +0 -1
  91. package/handlers/database-migration-handler.js +64 -45
  92. package/handlers/middleware/admin-auth.js +53 -0
  93. package/handlers/routers/HEALTHCHECK.md +170 -135
  94. package/handlers/routers/admin.js +474 -0
  95. package/handlers/routers/auth.js +51 -9
  96. package/handlers/routers/db-migration.handler.js +2 -3
  97. package/handlers/routers/db-migration.js +102 -66
  98. package/handlers/routers/docs.js +180 -0
  99. package/handlers/routers/health.js +84 -283
  100. package/handlers/routers/integration-defined-routers.js +44 -33
  101. package/handlers/routers/integration-webhook-routers.js +73 -52
  102. package/handlers/routers/middleware/loadUser.js +39 -0
  103. package/handlers/routers/middleware/requireAdmin.js +43 -0
  104. package/handlers/routers/middleware/requireLoggedInUser.js +19 -0
  105. package/handlers/routers/user.js +30 -14
  106. package/handlers/routers/websocket.js +18 -4
  107. package/handlers/use-cases/check-integrations-health-use-case.js +13 -6
  108. package/handlers/workers/db-migration.js +74 -35
  109. package/handlers/workers/integration-defined-workers.js +31 -20
  110. package/index.js +50 -16
  111. package/infrastructure/scheduler/index.js +15 -11
  112. package/infrastructure/scheduler/netlify-scheduler-adapter.js +185 -0
  113. package/infrastructure/scheduler/scheduler-service-factory.js +38 -31
  114. package/integrations/WEBHOOK-QUICKSTART.md +21 -14
  115. package/integrations/index.js +4 -0
  116. package/integrations/integration-base.js +9 -6
  117. package/integrations/integration-router.js +1828 -157
  118. package/integrations/options.js +47 -20
  119. package/integrations/repositories/integration-mapping-repository-factory.js +4 -8
  120. package/integrations/repositories/integration-repository-documentdb.js +53 -24
  121. package/integrations/repositories/integration-repository-factory.js +6 -6
  122. package/integrations/repositories/integration-repository-interface.js +27 -9
  123. package/integrations/repositories/integration-repository-postgres.js +3 -3
  124. package/integrations/repositories/process-repository-factory.js +4 -7
  125. package/integrations/repositories/process-repository-interface.js +9 -5
  126. package/integrations/repositories/process-repository-mongo.js +7 -3
  127. package/integrations/repositories/process-repository-postgres.js +2 -2
  128. package/integrations/tests/doubles/config-capturing-integration.js +9 -8
  129. package/integrations/tests/doubles/dummy-integration-class.js +81 -8
  130. package/integrations/tests/doubles/test-integration-repository.js +51 -11
  131. package/integrations/use-cases/create-integration.js +36 -32
  132. package/integrations/use-cases/create-process.js +20 -9
  133. package/integrations/use-cases/delete-integration-for-user.js +5 -4
  134. package/integrations/use-cases/execute-proxy-request.js +564 -0
  135. package/integrations/use-cases/get-integration-for-user.js +25 -10
  136. package/integrations/use-cases/get-integration-instance-by-definition.js +13 -7
  137. package/integrations/use-cases/get-integrations-for-user.js +4 -1
  138. package/integrations/use-cases/get-possible-integrations.js +1 -1
  139. package/integrations/use-cases/get-process.js +5 -6
  140. package/integrations/use-cases/index.js +3 -1
  141. package/integrations/use-cases/load-integration-context.js +1 -5
  142. package/integrations/use-cases/update-process-state.js +10 -8
  143. package/integrations/utils/map-integration-dto.js +9 -3
  144. package/jest-setup.js +1 -1
  145. package/jest-teardown.js +1 -1
  146. package/lambda/TimeoutCatcher.js +32 -30
  147. package/lambda/index.js +1 -1
  148. package/logs/index.js +3 -3
  149. package/modules/domain/entities/AuthorizationSession.js +131 -0
  150. package/modules/domain/entities/index.js +10 -0
  151. package/modules/module.js +4 -9
  152. package/modules/repositories/authorization-session-repository-factory.js +53 -0
  153. package/modules/repositories/authorization-session-repository-interface.js +75 -0
  154. package/modules/repositories/authorization-session-repository-mongo.js +169 -0
  155. package/modules/repositories/authorization-session-repository-postgres.js +170 -0
  156. package/modules/repositories/module-repository-documentdb.js +89 -41
  157. package/modules/repositories/module-repository-factory.js +4 -6
  158. package/modules/repositories/module-repository-interface.js +13 -0
  159. package/modules/repositories/module-repository-mongo.js +40 -5
  160. package/modules/repositories/module-repository-postgres.js +42 -5
  161. package/modules/repositories/module-repository.js +28 -0
  162. package/modules/requester/api-key.js +0 -2
  163. package/modules/requester/basic.js +0 -1
  164. package/modules/requester/oauth-2.js +3 -14
  165. package/modules/test/mock-api/definition.js +15 -10
  166. package/modules/test/mock-api/mocks/hubspot.js +36 -36
  167. package/modules/tests/doubles/test-module-factory.js +10 -4
  168. package/modules/tests/doubles/test-module-repository.js +1 -1
  169. package/modules/use-cases/delete-module-entity.js +23 -0
  170. package/modules/use-cases/get-authorization-requirements.js +110 -0
  171. package/modules/use-cases/get-entities-for-user.js +1 -1
  172. package/modules/use-cases/get-entity-options-by-id.js +8 -6
  173. package/modules/use-cases/get-module-entity-by-id.js +16 -0
  174. package/modules/use-cases/get-module.js +12 -9
  175. package/modules/use-cases/process-authorization-callback.js +12 -6
  176. package/modules/use-cases/process-authorization-step.js +160 -0
  177. package/modules/use-cases/refresh-entity-options.js +8 -6
  178. package/modules/use-cases/start-authorization-session.js +86 -0
  179. package/modules/use-cases/test-module-auth.js +8 -6
  180. package/modules/use-cases/update-module-entity.js +27 -0
  181. package/modules/utils/map-module-dto.js +2 -2
  182. package/openapi/openapi-spec-generator.js +370 -0
  183. package/openapi/openapi-v1.yaml +1360 -0
  184. package/openapi/openapi-v2.yaml +1535 -0
  185. package/package.json +7 -9
  186. package/prisma-mongodb/schema.prisma +87 -0
  187. package/prisma-postgresql/migrations/20260222000000_add_admin_process_and_script_schedule/migration.sql +55 -0
  188. package/prisma-postgresql/schema.prisma +85 -0
  189. package/providers/index.js +13 -0
  190. package/providers/resolve-provider.js +93 -0
  191. package/queues/index.js +19 -0
  192. package/queues/providers/index.js +7 -0
  193. package/queues/providers/netlify-background-provider.js +76 -0
  194. package/queues/providers/qstash-queue-provider.js +122 -0
  195. package/queues/queue-client-interface.js +55 -0
  196. package/queues/queue-provider-factory.js +93 -0
  197. package/queues/queue-provider.js +46 -0
  198. package/queues/queuer-util.js +33 -25
  199. package/syncs/repositories/sync-repository-documentdb.js +39 -19
  200. package/syncs/repositories/sync-repository-factory.js +4 -4
  201. package/syncs/repositories/sync-repository-interface.js +6 -2
  202. package/syncs/repositories/sync-repository-postgres.js +19 -13
  203. package/syncs/sync.js +104 -100
  204. package/token/repositories/token-repository-factory.js +4 -6
  205. package/types/assertions/index.d.ts +72 -72
  206. package/types/core/index.d.ts +98 -53
  207. package/types/errors/index.d.ts +61 -54
  208. package/types/eslint-config/index.d.ts +40 -40
  209. package/types/lambda/index.d.ts +26 -26
  210. package/types/logs/index.d.ts +4 -4
  211. package/types/prettier-config/index.d.ts +5 -5
  212. package/types/test-environment/index.d.ts +14 -14
  213. package/types/tsconfig.json +95 -93
  214. package/user/repositories/user-repository-factory.js +4 -4
  215. package/user/tests/doubles/test-user-repository.js +5 -2
  216. package/user/use-cases/authenticate-user.js +2 -4
  217. package/user/use-cases/authenticate-with-shared-secret.js +1 -1
  218. package/user/use-cases/create-individual-user.js +8 -7
  219. package/user/use-cases/create-organization-user.js +1 -1
  220. package/user/use-cases/create-token-for-user-id.js +1 -1
  221. package/user/use-cases/delete-user.js +47 -0
  222. package/user/use-cases/get-user-from-adopter-jwt.js +0 -2
  223. package/user/use-cases/get-user-from-bearer-token.js +7 -3
  224. package/user/use-cases/get-user-from-x-frigg-headers.js +14 -11
  225. package/user/use-cases/login-user.js +8 -8
  226. package/user/user.js +18 -4
  227. package/utils/backend-path.js +2 -2
  228. package/utils/index.js +4 -1
  229. package/websocket/repositories/websocket-connection-repository-documentdb.js +46 -21
  230. package/websocket/repositories/websocket-connection-repository-factory.js +4 -8
  231. package/websocket/repositories/websocket-connection-repository-mongo.js +26 -16
  232. package/websocket/repositories/websocket-connection-repository-postgres.js +26 -15
  233. package/websocket/repositories/websocket-connection-repository.js +26 -20
  234. package/websocket/websocket-message-sender-interface.js +38 -0
  235. package/database/adapters/lambda-invoker.js +0 -97
  236. package/database/repositories/migration-status-repository-s3.js +0 -137
  237. package/infrastructure/scheduler/eventbridge-scheduler-adapter.js +0 -184
@@ -7,195 +7,222 @@ The Frigg service includes comprehensive healthcheck endpoints to monitor servic
7
7
  ## Endpoints
8
8
 
9
9
  ### 1. Basic Health Check
10
+
10
11
  **GET** `/health`
11
12
 
12
13
  Simple health check endpoint that returns basic service information. No authentication required. This endpoint is rate-limited at the API Gateway level.
13
14
 
14
15
  **Response:**
16
+
15
17
  ```json
16
18
  {
17
- "status": "ok",
18
- "timestamp": "2024-01-10T12:00:00.000Z",
19
- "service": "frigg-core-api"
19
+ "status": "ok",
20
+ "timestamp": "2024-01-10T12:00:00.000Z",
21
+ "service": "frigg-core-api"
20
22
  }
21
23
  ```
22
24
 
23
25
  **Status Codes:**
24
- - `200 OK` - Service is running
26
+
27
+ - `200 OK` - Service is running
25
28
 
26
29
  ### 2. Detailed Health Check
30
+
27
31
  **GET** `/health/detailed`
28
32
 
29
33
  Comprehensive health check that tests all service components and dependencies.
30
34
 
31
35
  **Authentication Required:**
32
- - Header: `x-api-key: YOUR_API_KEY`
33
- - The API key must match the `HEALTH_API_KEY` environment variable
36
+
37
+ - Header: `x-api-key: YOUR_API_KEY`
38
+ - The API key must match the `HEALTH_API_KEY` environment variable
34
39
 
35
40
  **Response:**
41
+
36
42
  ```json
37
43
  {
38
- "service": "frigg-core-api",
39
- "status": "healthy", // "healthy" or "unhealthy"
40
- "timestamp": "2024-01-10T12:00:00.000Z",
41
- "checks": {
42
- "database": {
43
- "status": "healthy",
44
- "state": "connected",
45
- "responseTime": 5 // milliseconds
44
+ "service": "frigg-core-api",
45
+ "status": "healthy", // "healthy" or "unhealthy"
46
+ "timestamp": "2024-01-10T12:00:00.000Z",
47
+ "checks": {
48
+ "database": {
49
+ "status": "healthy",
50
+ "state": "connected",
51
+ "responseTime": 5 // milliseconds
52
+ },
53
+ "externalApis": {
54
+ "github": {
55
+ "status": "healthy",
56
+ "statusCode": 200,
57
+ "responseTime": 150,
58
+ "reachable": true
59
+ },
60
+ "npm": {
61
+ "status": "healthy",
62
+ "statusCode": 200,
63
+ "responseTime": 200,
64
+ "reachable": true
65
+ }
66
+ },
67
+ "integrations": {
68
+ "status": "healthy",
69
+ "modules": {
70
+ "count": 10,
71
+ "available": ["module1", "module2", "..."]
72
+ },
73
+ "integrations": {
74
+ "count": 5,
75
+ "available": ["integration1", "integration2", "..."]
76
+ }
77
+ }
46
78
  },
47
- "externalApis": {
48
- "github": {
49
- "status": "healthy",
50
- "statusCode": 200,
51
- "responseTime": 150,
52
- "reachable": true
53
- },
54
- "npm": {
55
- "status": "healthy",
56
- "statusCode": 200,
57
- "responseTime": 200,
58
- "reachable": true
59
- }
60
- },
61
- "integrations": {
62
- "status": "healthy",
63
- "modules": {
64
- "count": 10,
65
- "available": ["module1", "module2", "..."]
66
- },
67
- "integrations": {
68
- "count": 5,
69
- "available": ["integration1", "integration2", "..."]
70
- }
71
- }
72
- },
73
- "responseTime": 250 // total endpoint response time in milliseconds
79
+ "responseTime": 250 // total endpoint response time in milliseconds
74
80
  }
75
81
  ```
76
82
 
77
83
  **Status Codes:**
78
- - `200 OK` - Service is healthy (all components operational)
79
- - `503 Service Unavailable` - Service is unhealthy (any component failure)
80
- - `401 Unauthorized` - Missing or invalid x-api-key header
84
+
85
+ - `200 OK` - Service is healthy (all components operational)
86
+ - `503 Service Unavailable` - Service is unhealthy (any component failure)
87
+ - `401 Unauthorized` - Missing or invalid x-api-key header
81
88
 
82
89
  ### 3. Liveness Probe
90
+
83
91
  **GET** `/health/live`
84
92
 
85
93
  Kubernetes-style liveness probe. Returns whether the service process is alive.
86
94
 
87
95
  **Authentication Required:**
88
- - Header: `x-api-key: YOUR_API_KEY`
96
+
97
+ - Header: `x-api-key: YOUR_API_KEY`
89
98
 
90
99
  **Response:**
100
+
91
101
  ```json
92
102
  {
93
- "status": "alive",
94
- "timestamp": "2024-01-10T12:00:00.000Z"
103
+ "status": "alive",
104
+ "timestamp": "2024-01-10T12:00:00.000Z"
95
105
  }
96
106
  ```
97
107
 
98
108
  **Status Codes:**
99
- - `200 OK` - Service process is alive
109
+
110
+ - `200 OK` - Service process is alive
100
111
 
101
112
  ### 4. Readiness Probe
113
+
102
114
  **GET** `/health/ready`
103
115
 
104
116
  Kubernetes-style readiness probe. Returns whether the service is ready to receive traffic.
105
117
 
106
118
  **Authentication Required:**
107
- - Header: `x-api-key: YOUR_API_KEY`
119
+
120
+ - Header: `x-api-key: YOUR_API_KEY`
108
121
 
109
122
  **Response:**
123
+
110
124
  ```json
111
125
  {
112
- "ready": true,
113
- "timestamp": "2024-01-10T12:00:00.000Z",
114
- "checks": {
115
- "database": true,
116
- "modules": true
117
- }
126
+ "ready": true,
127
+ "timestamp": "2024-01-10T12:00:00.000Z",
128
+ "checks": {
129
+ "database": true,
130
+ "modules": true
131
+ }
118
132
  }
119
133
  ```
120
134
 
121
135
  **Status Codes:**
122
- - `200 OK` - Service is ready
123
- - `503 Service Unavailable` - Service is not ready
136
+
137
+ - `200 OK` - Service is ready
138
+ - `503 Service Unavailable` - Service is not ready
124
139
 
125
140
  ## Health Status Definitions
126
141
 
127
- - **healthy**: All components are functioning normally
128
- - **unhealthy**: Any component is failing, service may not function properly
142
+ - **healthy**: All components are functioning normally
143
+ - **unhealthy**: Any component is failing, service may not function properly
129
144
 
130
145
  ## Component Checks
131
146
 
132
147
  ### Database Connectivity
133
- - Checks database connection state
134
- - Performs ping test with 2-second timeout if connected
135
- - Reports connection state and response time
136
- - Database type is not exposed for security reasons
148
+
149
+ - Checks database connection state
150
+ - Performs ping test with 2-second timeout if connected
151
+ - Reports connection state and response time
152
+ - Database type is not exposed for security reasons
137
153
 
138
154
  ### External API Connectivity
139
- - Tests connectivity to external services (GitHub, npm registry)
140
- - Configurable timeout (default: 5 seconds)
141
- - Reports reachability and response times
142
- - Uses Promise.all for parallel checking
155
+
156
+ - Tests connectivity to external services (GitHub, npm registry)
157
+ - Configurable timeout (default: 5 seconds)
158
+ - Reports reachability and response times
159
+ - Uses Promise.all for parallel checking
143
160
 
144
161
  ### Integration Status
145
- - Verifies available modules and integrations are loaded
146
- - Reports counts and lists of available components
162
+
163
+ - Verifies available modules and integrations are loaded
164
+ - Reports counts and lists of available components
147
165
 
148
166
  ## Usage Examples
149
167
 
150
168
  ### Monitoring Systems
169
+
151
170
  Configure your monitoring system to poll `/health/detailed` every 30-60 seconds:
171
+
152
172
  ```bash
153
173
  curl -H "x-api-key: YOUR_API_KEY" https://your-frigg-instance.com/health/detailed
154
174
  ```
155
175
 
156
176
  ### Load Balancer Health Checks
177
+
157
178
  Configure load balancers to use the simple `/health` endpoint:
179
+
158
180
  ```bash
159
181
  curl https://your-frigg-instance.com/health
160
182
  ```
161
183
 
162
184
  ### Kubernetes Configuration
185
+
163
186
  ```yaml
164
187
  livenessProbe:
165
- httpGet:
166
- path: /health/live
167
- port: 8080
168
- httpHeaders:
169
- - name: x-api-key
170
- value: YOUR_API_KEY
171
- periodSeconds: 10
172
- timeoutSeconds: 5
188
+ httpGet:
189
+ path: /health/live
190
+ port: 8080
191
+ httpHeaders:
192
+ - name: x-api-key
193
+ value: YOUR_API_KEY
194
+ periodSeconds: 10
195
+ timeoutSeconds: 5
173
196
 
174
197
  readinessProbe:
175
- httpGet:
176
- path: /health/ready
177
- port: 8080
178
- httpHeaders:
179
- - name: x-api-key
180
- value: YOUR_API_KEY
181
- initialDelaySeconds: 30
182
- periodSeconds: 10
198
+ httpGet:
199
+ path: /health/ready
200
+ port: 8080
201
+ httpHeaders:
202
+ - name: x-api-key
203
+ value: YOUR_API_KEY
204
+ initialDelaySeconds: 30
205
+ periodSeconds: 10
183
206
  ```
184
207
 
185
208
  ## Customization
186
209
 
187
210
  ### Adding External API Checks
211
+
188
212
  To add more external API checks, modify the `externalAPIs` array in the health router:
213
+
189
214
  ```javascript
190
215
  const externalAPIs = [
191
216
  { name: 'github', url: 'https://api.github.com/status' },
192
217
  { name: 'npm', url: 'https://registry.npmjs.org' },
193
- { name: 'your-api', url: 'https://your-api.com/health' }
218
+ { name: 'your-api', url: 'https://your-api.com/health' },
194
219
  ];
195
220
  ```
196
221
 
197
222
  ### Adjusting Timeouts
223
+
198
224
  The default timeout for external API checks is 5 seconds. Database ping timeout is set to 2 seconds:
225
+
199
226
  ```javascript
200
227
  const checkExternalAPI = (url, timeout = 5000) => {
201
228
  // ...
@@ -217,27 +244,29 @@ await mongoose.connection.db.admin().ping({ maxTimeMS: 2000 });
217
244
  ## Troubleshooting
218
245
 
219
246
  ### Database Connection Issues
220
- - Check `MONGO_URI` environment variable
221
- - Verify network connectivity to MongoDB
222
- - Check MongoDB server status
247
+
248
+ - Check `MONGO_URI` environment variable
249
+ - Verify network connectivity to MongoDB
250
+ - Check MongoDB server status
223
251
 
224
252
  ### External API Failures
225
- - May indicate network issues or external service downtime
226
- - Service reports "unhealthy" status if any external API is unreachable
253
+
254
+ - May indicate network issues or external service downtime
255
+ - Service reports "unhealthy" status if any external API is unreachable
227
256
 
228
257
  ## Security Considerations
229
258
 
230
- - Basic health endpoint requires no authentication for monitoring compatibility
231
- - Detailed endpoints require `x-api-key` header authentication
232
- - Health endpoints do not expose sensitive information
233
- - Database connection strings and credentials are never included in responses
234
- - External API checks use read-only endpoints
235
- - Rate limiting should be configured at the API Gateway level
236
- - Consider IP whitelisting for health endpoints in production
259
+ - Basic health endpoint requires no authentication for monitoring compatibility
260
+ - Detailed endpoints require `x-api-key` header authentication
261
+ - Health endpoints do not expose sensitive information
262
+ - Database connection strings and credentials are never included in responses
263
+ - External API checks use read-only endpoints
264
+ - Rate limiting should be configured at the API Gateway level
265
+ - Consider IP whitelisting for health endpoints in production
237
266
 
238
267
  ## Environment Variables
239
268
 
240
- - `HEALTH_API_KEY`: Required API key for accessing detailed health endpoints
269
+ - `HEALTH_API_KEY`: Required API key for accessing detailed health endpoints
241
270
 
242
271
  ## TODO: DDD/Hexagonal Architecture Refactoring
243
272
 
@@ -246,11 +275,13 @@ await mongoose.connection.db.admin().ping({ maxTimeMS: 2000 });
246
275
  The health router (health.js, 677 lines) currently violates DDD/Hexagonal Architecture principles:
247
276
 
248
277
  **✅ What's Good:**
249
- - Database access properly abstracted through `HealthCheckRepository`
250
- - `CheckDatabaseHealthUseCase` and `TestEncryptionUseCase` correctly implement use case pattern
251
- - All tests passing, no breaking changes
278
+
279
+ - Database access properly abstracted through `HealthCheckRepository`
280
+ - `CheckDatabaseHealthUseCase` and `TestEncryptionUseCase` correctly implement use case pattern
281
+ - All tests passing, no breaking changes
252
282
 
253
283
  **❌ Architecture Violations:**
284
+
254
285
  1. **Handler contains significant business logic** - Functions like `getEncryptionConfiguration()`, `checkEncryptionHealth()`, `checkKmsDecryptCapability()`, `detectVpcConfiguration()`, `checkExternalAPIs()`, and `checkIntegrations()` contain business logic that should be in use cases
255
286
  2. **Direct infrastructure dependencies** - Handler directly uses `https`, `http`, Node.js `dns`, and factory modules instead of accessing through repositories
256
287
  3. **Mixed concerns** - Single file handles HTTP routing, business logic, infrastructure detection, and response formatting
@@ -261,43 +292,46 @@ The health router (health.js, 677 lines) currently violates DDD/Hexagonal Archit
261
292
  #### Priority 1: Extract Core Health Check Use Cases (Immediate)
262
293
 
263
294
  **New Use Cases:**
295
+
264
296
  1. `CheckEncryptionHealthUseCase` - Orchestrate encryption testing with configuration checks (from health.js:122-181)
265
297
  2. `CheckKmsConnectivityUseCase` - Test KMS decrypt capability (from health.js:339-490)
266
298
  3. `DetectNetworkConfigurationUseCase` - VPC and network detection (from health.js:244-336)
267
299
 
268
300
  **New Repositories:**
301
+
269
302
  1. `EncryptionConfigRepository` - Get encryption mode, bypass rules (from health.js:98-120)
270
303
  2. `KmsRepository` - KMS connectivity testing, decrypt capability checks
271
304
  3. `NetworkRepository` - DNS resolution, VPC detection, TCP connectivity tests
272
305
 
273
306
  #### Priority 2: Extract External Service Checks
274
307
 
275
- **New Use Cases:**
276
- 4. `CheckExternalServicesUseCase` - Check external API availability (from health.js:183-209)
308
+ **New Use Cases:** 4. `CheckExternalServicesUseCase` - Check external API availability (from health.js:183-209)
277
309
 
278
- **New Repositories:**
279
- 4. `ExternalServiceRepository` - HTTP-based service health checking with timeout handling
310
+ **New Repositories:** 4. `ExternalServiceRepository` - HTTP-based service health checking with timeout handling
280
311
 
281
312
  #### Priority 3: Extract Integration Checks
282
313
 
283
- **New Use Cases:**
284
- 5. `CheckIntegrationAvailabilityUseCase` - Verify integrations and modules loaded (from health.js:211-231)
314
+ **New Use Cases:** 5. `CheckIntegrationAvailabilityUseCase` - Verify integrations and modules loaded (from health.js:211-231)
285
315
 
286
316
  **Extend Existing:**
287
- - Add `getAvailableIntegrations()` and `getAvailableModules()` methods to existing `IntegrationRepository`
317
+
318
+ - Add `getAvailableIntegrations()` and `getAvailableModules()` methods to existing `IntegrationRepository`
288
319
 
289
320
  ### Architectural Principles to Follow
290
321
 
291
322
  **The Handler Should Only:**
292
- - Define routes
293
- - Call use cases
294
- - Map use case results to HTTP responses
295
- - Handle HTTP-specific concerns (status codes, headers)
323
+
324
+ - Define routes
325
+ - Call use cases
326
+ - Map use case results to HTTP responses
327
+ - Handle HTTP-specific concerns (status codes, headers)
296
328
 
297
329
  **The Rule:**
330
+
298
331
  > "Handlers (adapters) should only call use cases, never repositories or business logic directly"
299
332
 
300
333
  **Dependency Direction:**
334
+
301
335
  ```
302
336
  Handler (Adapter Layer)
303
337
  ↓ calls
@@ -310,33 +344,34 @@ External Systems (Database, APIs, AWS Services)
310
344
 
311
345
  ### Expected Outcome
312
346
 
313
- - Reduce health.js from **677 lines to ~100-150 lines**
314
- - All business logic moved to use cases
315
- - All infrastructure access moved to repositories
316
- - Handler becomes thin HTTP adapter
317
- - Improved testability (use cases testable without HTTP context)
318
- - Better reusability (use cases usable in CLI tools, background jobs, etc.)
347
+ - Reduce health.js from **677 lines to ~100-150 lines**
348
+ - All business logic moved to use cases
349
+ - All infrastructure access moved to repositories
350
+ - Handler becomes thin HTTP adapter
351
+ - Improved testability (use cases testable without HTTP context)
352
+ - Better reusability (use cases usable in CLI tools, background jobs, etc.)
319
353
 
320
354
  ### Implementation Status
321
355
 
322
- - [ ] P1: Extract `CheckEncryptionHealthUseCase`
323
- - [ ] P1: Create `EncryptionConfigRepository`
324
- - [ ] P1: Extract `CheckKmsConnectivityUseCase`
325
- - [ ] P1: Create `KmsRepository`
326
- - [ ] P1: Extract `DetectNetworkConfigurationUseCase`
327
- - [ ] P1: Create `NetworkRepository`
328
- - [ ] P2: Extract `CheckExternalServicesUseCase`
329
- - [ ] P2: Create `ExternalServiceRepository`
330
- - [ ] P3: Extract `CheckIntegrationAvailabilityUseCase`
331
- - [ ] P3: Extend existing `IntegrationRepository`
356
+ - [ ] P1: Extract `CheckEncryptionHealthUseCase`
357
+ - [ ] P1: Create `EncryptionConfigRepository`
358
+ - [ ] P1: Extract `CheckKmsConnectivityUseCase`
359
+ - [ ] P1: Create `KmsRepository`
360
+ - [ ] P1: Extract `DetectNetworkConfigurationUseCase`
361
+ - [ ] P1: Create `NetworkRepository`
362
+ - [ ] P2: Extract `CheckExternalServicesUseCase`
363
+ - [ ] P2: Create `ExternalServiceRepository`
364
+ - [ ] P3: Extract `CheckIntegrationAvailabilityUseCase`
365
+ - [ ] P3: Extend existing `IntegrationRepository`
332
366
 
333
367
  ### Future Considerations (Optional)
334
368
 
335
369
  **Domain Models (Value Objects):**
336
- - `HealthCheckResult` - Overall health check result with status, checks, timestamp
337
- - `DatabaseHealth` - Database-specific health information
338
- - `EncryptionHealth` - Encryption-specific health information
339
- - `ServiceHealth` - Generic external service health
340
- - `NetworkConfiguration` - VPC and network detection results
341
370
 
342
- These would replace plain objects and provide type safety and business logic encapsulation.
371
+ - `HealthCheckResult` - Overall health check result with status, checks, timestamp
372
+ - `DatabaseHealth` - Database-specific health information
373
+ - `EncryptionHealth` - Encryption-specific health information
374
+ - `ServiceHealth` - Generic external service health
375
+ - `NetworkConfiguration` - VPC and network detection results
376
+
377
+ These would replace plain objects and provide type safety and business logic encapsulation.