@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.
- package/CHANGELOG.md +66 -67
- package/CLAUDE.md +148 -124
- package/README.md +165 -130
- package/admin-scripts/index.js +52 -0
- package/admin-scripts/repositories/admin-api-key-repository-documentdb.js +21 -0
- package/admin-scripts/repositories/admin-api-key-repository-factory.js +51 -0
- package/admin-scripts/repositories/admin-api-key-repository-interface.js +121 -0
- package/admin-scripts/repositories/admin-api-key-repository-mongo.js +155 -0
- package/admin-scripts/repositories/admin-api-key-repository-postgres.js +189 -0
- package/admin-scripts/repositories/admin-process-repository-documentdb.js +21 -0
- package/admin-scripts/repositories/admin-process-repository-factory.js +49 -0
- package/admin-scripts/repositories/admin-process-repository-interface.js +150 -0
- package/admin-scripts/repositories/admin-process-repository-mongo.js +213 -0
- package/admin-scripts/repositories/admin-process-repository-postgres.js +251 -0
- package/admin-scripts/repositories/script-execution-repository-documentdb.js +21 -0
- package/admin-scripts/repositories/script-execution-repository-factory.js +51 -0
- package/admin-scripts/repositories/script-execution-repository-interface.js +193 -0
- package/admin-scripts/repositories/script-execution-repository-mongo.js +278 -0
- package/admin-scripts/repositories/script-execution-repository-postgres.js +320 -0
- package/admin-scripts/repositories/script-schedule-repository-documentdb.js +21 -0
- package/admin-scripts/repositories/script-schedule-repository-factory.js +49 -0
- package/admin-scripts/repositories/script-schedule-repository-interface.js +108 -0
- package/admin-scripts/repositories/script-schedule-repository-mongo.js +179 -0
- package/admin-scripts/repositories/script-schedule-repository-postgres.js +210 -0
- package/application/commands/admin-script-commands.js +348 -0
- package/application/commands/integration-commands.js +12 -6
- package/application/index.js +5 -3
- package/assertions/get.js +17 -7
- package/associations/association.js +59 -57
- package/core/CLAUDE.md +222 -156
- package/core/Worker.js +33 -12
- package/credential/credential-router.js +262 -0
- package/credential/repositories/credential-repository-documentdb.js +71 -1
- package/credential/repositories/credential-repository-factory.js +4 -6
- package/credential/repositories/credential-repository-interface.js +8 -2
- package/credential/repositories/credential-repository-mongo.js +45 -4
- package/credential/repositories/credential-repository-postgres.js +44 -3
- package/credential/repositories/credential-repository.js +3 -1
- package/credential/use-cases/delete-credential-for-user.js +50 -0
- package/credential/use-cases/get-credential-for-user.js +21 -3
- package/credential/use-cases/list-credentials-for-user.js +31 -0
- package/credential/use-cases/reauthorize-credential.js +103 -0
- package/credential/use-cases/update-authentication-status.js +5 -2
- package/database/MONGODB_TRANSACTION_FIX.md +72 -52
- package/database/config.js +13 -59
- package/database/documentdb-encryption-service.js +29 -13
- package/database/documentdb-utils.js +21 -12
- package/database/encryption/README.md +53 -36
- package/database/encryption/encryption-schema-registry.js +29 -23
- package/database/encryption/field-encryption-service.js +15 -4
- package/database/encryption/logger.js +3 -2
- package/database/encryption/prisma-encryption-extension.js +5 -8
- package/database/prisma.js +22 -14
- package/database/repositories/health-check-repository-factory.js +7 -5
- package/database/repositories/health-check-repository-interface.js +15 -5
- package/database/repositories/health-check-repository-postgres.js +1 -1
- package/database/use-cases/check-database-health-use-case.js +3 -2
- package/database/use-cases/check-database-state-use-case.js +8 -7
- package/database/use-cases/get-database-state-via-worker-use-case.js +15 -12
- package/database/use-cases/get-migration-status-use-case.js +4 -2
- package/database/use-cases/run-database-migration-use-case.js +41 -9
- package/database/use-cases/test-encryption-use-case.js +4 -5
- package/database/use-cases/trigger-database-migration-use-case.js +9 -8
- package/database/utils/mongodb-collection-utils.js +11 -3
- package/database/utils/mongodb-schema-init.js +10 -4
- package/database/utils/prisma-runner.js +144 -74
- package/database/utils/prisma-schema-parser.js +2 -2
- package/docs/PROCESS_MANAGEMENT_QUEUE_SPEC.md +135 -80
- package/encrypt/Cryptor.js +54 -49
- package/encrypt/aes-encryption-key-provider.js +82 -0
- package/encrypt/encryption-key-provider-interface.js +50 -0
- package/errors/fetch-error.js +1 -1
- package/generated/prisma-mongodb/edge.js +59 -4
- package/generated/prisma-mongodb/index-browser.js +49 -1
- package/generated/prisma-mongodb/index.d.ts +4023 -61
- package/generated/prisma-mongodb/index.js +59 -4
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +87 -0
- package/generated/prisma-mongodb/wasm.js +59 -4
- package/generated/prisma-postgresql/edge.js +58 -4
- package/generated/prisma-postgresql/index-browser.js +48 -1
- package/generated/prisma-postgresql/index.d.ts +4738 -54
- package/generated/prisma-postgresql/index.js +58 -4
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +85 -0
- package/generated/prisma-postgresql/wasm.js +58 -4
- package/handlers/WEBHOOKS.md +104 -81
- package/handlers/app-definition-loader.js +53 -10
- package/handlers/app-handler-helpers.js +14 -3
- package/handlers/backend-utils.js +0 -1
- package/handlers/database-migration-handler.js +64 -45
- package/handlers/middleware/admin-auth.js +53 -0
- package/handlers/routers/HEALTHCHECK.md +170 -135
- package/handlers/routers/admin.js +474 -0
- package/handlers/routers/auth.js +51 -9
- package/handlers/routers/db-migration.handler.js +2 -3
- package/handlers/routers/db-migration.js +102 -66
- package/handlers/routers/docs.js +180 -0
- package/handlers/routers/health.js +84 -283
- package/handlers/routers/integration-defined-routers.js +44 -33
- package/handlers/routers/integration-webhook-routers.js +73 -52
- package/handlers/routers/middleware/loadUser.js +39 -0
- package/handlers/routers/middleware/requireAdmin.js +43 -0
- package/handlers/routers/middleware/requireLoggedInUser.js +19 -0
- package/handlers/routers/user.js +30 -14
- package/handlers/routers/websocket.js +18 -4
- package/handlers/use-cases/check-integrations-health-use-case.js +13 -6
- package/handlers/workers/db-migration.js +74 -35
- package/handlers/workers/integration-defined-workers.js +31 -20
- package/index.js +50 -16
- package/infrastructure/scheduler/index.js +15 -11
- package/infrastructure/scheduler/netlify-scheduler-adapter.js +185 -0
- package/infrastructure/scheduler/scheduler-service-factory.js +38 -31
- package/integrations/WEBHOOK-QUICKSTART.md +21 -14
- package/integrations/index.js +4 -0
- package/integrations/integration-base.js +9 -6
- package/integrations/integration-router.js +1828 -157
- package/integrations/options.js +47 -20
- package/integrations/repositories/integration-mapping-repository-factory.js +4 -8
- package/integrations/repositories/integration-repository-documentdb.js +53 -24
- package/integrations/repositories/integration-repository-factory.js +6 -6
- package/integrations/repositories/integration-repository-interface.js +27 -9
- package/integrations/repositories/integration-repository-postgres.js +3 -3
- package/integrations/repositories/process-repository-factory.js +4 -7
- package/integrations/repositories/process-repository-interface.js +9 -5
- package/integrations/repositories/process-repository-mongo.js +7 -3
- package/integrations/repositories/process-repository-postgres.js +2 -2
- package/integrations/tests/doubles/config-capturing-integration.js +9 -8
- package/integrations/tests/doubles/dummy-integration-class.js +81 -8
- package/integrations/tests/doubles/test-integration-repository.js +51 -11
- package/integrations/use-cases/create-integration.js +36 -32
- package/integrations/use-cases/create-process.js +20 -9
- package/integrations/use-cases/delete-integration-for-user.js +5 -4
- package/integrations/use-cases/execute-proxy-request.js +564 -0
- package/integrations/use-cases/get-integration-for-user.js +25 -10
- package/integrations/use-cases/get-integration-instance-by-definition.js +13 -7
- package/integrations/use-cases/get-integrations-for-user.js +4 -1
- package/integrations/use-cases/get-possible-integrations.js +1 -1
- package/integrations/use-cases/get-process.js +5 -6
- package/integrations/use-cases/index.js +3 -1
- package/integrations/use-cases/load-integration-context.js +1 -5
- package/integrations/use-cases/update-process-state.js +10 -8
- package/integrations/utils/map-integration-dto.js +9 -3
- package/jest-setup.js +1 -1
- package/jest-teardown.js +1 -1
- package/lambda/TimeoutCatcher.js +32 -30
- package/lambda/index.js +1 -1
- package/logs/index.js +3 -3
- package/modules/domain/entities/AuthorizationSession.js +131 -0
- package/modules/domain/entities/index.js +10 -0
- package/modules/module.js +4 -9
- package/modules/repositories/authorization-session-repository-factory.js +53 -0
- package/modules/repositories/authorization-session-repository-interface.js +75 -0
- package/modules/repositories/authorization-session-repository-mongo.js +169 -0
- package/modules/repositories/authorization-session-repository-postgres.js +170 -0
- package/modules/repositories/module-repository-documentdb.js +89 -41
- package/modules/repositories/module-repository-factory.js +4 -6
- package/modules/repositories/module-repository-interface.js +13 -0
- package/modules/repositories/module-repository-mongo.js +40 -5
- package/modules/repositories/module-repository-postgres.js +42 -5
- package/modules/repositories/module-repository.js +28 -0
- package/modules/requester/api-key.js +0 -2
- package/modules/requester/basic.js +0 -1
- package/modules/requester/oauth-2.js +3 -14
- package/modules/test/mock-api/definition.js +15 -10
- package/modules/test/mock-api/mocks/hubspot.js +36 -36
- package/modules/tests/doubles/test-module-factory.js +10 -4
- package/modules/tests/doubles/test-module-repository.js +1 -1
- package/modules/use-cases/delete-module-entity.js +23 -0
- package/modules/use-cases/get-authorization-requirements.js +110 -0
- package/modules/use-cases/get-entities-for-user.js +1 -1
- package/modules/use-cases/get-entity-options-by-id.js +8 -6
- package/modules/use-cases/get-module-entity-by-id.js +16 -0
- package/modules/use-cases/get-module.js +12 -9
- package/modules/use-cases/process-authorization-callback.js +12 -6
- package/modules/use-cases/process-authorization-step.js +160 -0
- package/modules/use-cases/refresh-entity-options.js +8 -6
- package/modules/use-cases/start-authorization-session.js +86 -0
- package/modules/use-cases/test-module-auth.js +8 -6
- package/modules/use-cases/update-module-entity.js +27 -0
- package/modules/utils/map-module-dto.js +2 -2
- package/openapi/openapi-spec-generator.js +370 -0
- package/openapi/openapi-v1.yaml +1360 -0
- package/openapi/openapi-v2.yaml +1535 -0
- package/package.json +7 -9
- package/prisma-mongodb/schema.prisma +87 -0
- package/prisma-postgresql/migrations/20260222000000_add_admin_process_and_script_schedule/migration.sql +55 -0
- package/prisma-postgresql/schema.prisma +85 -0
- package/providers/index.js +13 -0
- package/providers/resolve-provider.js +93 -0
- package/queues/index.js +19 -0
- package/queues/providers/index.js +7 -0
- package/queues/providers/netlify-background-provider.js +76 -0
- package/queues/providers/qstash-queue-provider.js +122 -0
- package/queues/queue-client-interface.js +55 -0
- package/queues/queue-provider-factory.js +93 -0
- package/queues/queue-provider.js +46 -0
- package/queues/queuer-util.js +33 -25
- package/syncs/repositories/sync-repository-documentdb.js +39 -19
- package/syncs/repositories/sync-repository-factory.js +4 -4
- package/syncs/repositories/sync-repository-interface.js +6 -2
- package/syncs/repositories/sync-repository-postgres.js +19 -13
- package/syncs/sync.js +104 -100
- package/token/repositories/token-repository-factory.js +4 -6
- package/types/assertions/index.d.ts +72 -72
- package/types/core/index.d.ts +98 -53
- package/types/errors/index.d.ts +61 -54
- package/types/eslint-config/index.d.ts +40 -40
- package/types/lambda/index.d.ts +26 -26
- package/types/logs/index.d.ts +4 -4
- package/types/prettier-config/index.d.ts +5 -5
- package/types/test-environment/index.d.ts +14 -14
- package/types/tsconfig.json +95 -93
- package/user/repositories/user-repository-factory.js +4 -4
- package/user/tests/doubles/test-user-repository.js +5 -2
- package/user/use-cases/authenticate-user.js +2 -4
- package/user/use-cases/authenticate-with-shared-secret.js +1 -1
- package/user/use-cases/create-individual-user.js +8 -7
- package/user/use-cases/create-organization-user.js +1 -1
- package/user/use-cases/create-token-for-user-id.js +1 -1
- package/user/use-cases/delete-user.js +47 -0
- package/user/use-cases/get-user-from-adopter-jwt.js +0 -2
- package/user/use-cases/get-user-from-bearer-token.js +7 -3
- package/user/use-cases/get-user-from-x-frigg-headers.js +14 -11
- package/user/use-cases/login-user.js +8 -8
- package/user/user.js +18 -4
- package/utils/backend-path.js +2 -2
- package/utils/index.js +4 -1
- package/websocket/repositories/websocket-connection-repository-documentdb.js +46 -21
- package/websocket/repositories/websocket-connection-repository-factory.js +4 -8
- package/websocket/repositories/websocket-connection-repository-mongo.js +26 -16
- package/websocket/repositories/websocket-connection-repository-postgres.js +26 -15
- package/websocket/repositories/websocket-connection-repository.js +26 -20
- package/websocket/websocket-message-sender-interface.js +38 -0
- package/database/adapters/lambda-invoker.js +0 -97
- package/database/repositories/migration-status-repository-s3.js +0 -137
- 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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
"
|
|
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
|
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
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
|
-
|
|
96
|
+
|
|
97
|
+
- Header: `x-api-key: YOUR_API_KEY`
|
|
89
98
|
|
|
90
99
|
**Response:**
|
|
100
|
+
|
|
91
101
|
```json
|
|
92
102
|
{
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
"status": "alive",
|
|
104
|
+
"timestamp": "2024-01-10T12:00:00.000Z"
|
|
95
105
|
}
|
|
96
106
|
```
|
|
97
107
|
|
|
98
108
|
**Status Codes:**
|
|
99
|
-
|
|
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
|
-
|
|
119
|
+
|
|
120
|
+
- Header: `x-api-key: YOUR_API_KEY`
|
|
108
121
|
|
|
109
122
|
**Response:**
|
|
123
|
+
|
|
110
124
|
```json
|
|
111
125
|
{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
123
|
-
-
|
|
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
|
-
-
|
|
128
|
-
-
|
|
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
|
-
|
|
134
|
-
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
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
|
-
|
|
140
|
-
-
|
|
141
|
-
-
|
|
142
|
-
-
|
|
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
|
-
|
|
146
|
-
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
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
|
-
|
|
226
|
-
-
|
|
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
|
-
-
|
|
231
|
-
-
|
|
232
|
-
-
|
|
233
|
-
-
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
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
|
-
-
|
|
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
|
-
|
|
250
|
-
-
|
|
251
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
293
|
-
-
|
|
294
|
-
-
|
|
295
|
-
-
|
|
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
|
-
-
|
|
314
|
-
-
|
|
315
|
-
-
|
|
316
|
-
-
|
|
317
|
-
-
|
|
318
|
-
-
|
|
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
|
-
-
|
|
323
|
-
-
|
|
324
|
-
-
|
|
325
|
-
-
|
|
326
|
-
-
|
|
327
|
-
-
|
|
328
|
-
-
|
|
329
|
-
-
|
|
330
|
-
-
|
|
331
|
-
-
|
|
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
|
-
|
|
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.
|