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