@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.
- package/CHANGELOG.md +67 -66
- package/CLAUDE.md +124 -148
- package/README.md +130 -165
- package/admin-scripts/index.js +16 -30
- package/admin-scripts/repositories/{admin-api-key-repository-documentdb.js → admin-process-repository-documentdb.js} +5 -5
- package/admin-scripts/repositories/{admin-api-key-repository-factory.js → admin-process-repository-factory.js} +15 -19
- 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-schedule-repository-factory.js +2 -6
- package/admin-scripts/repositories/script-schedule-repository-interface.js +14 -36
- package/admin-scripts/repositories/script-schedule-repository-mongo.js +13 -25
- package/admin-scripts/repositories/script-schedule-repository-postgres.js +13 -25
- package/application/commands/admin-script-commands.js +102 -266
- package/application/commands/integration-commands.js +6 -12
- package/application/index.js +3 -1
- package/assertions/get.js +4 -1
- package/associations/association.js +57 -59
- package/associations/model.js +41 -41
- package/core/CLAUDE.md +156 -222
- package/core/Worker.js +1 -5
- package/credential/repositories/credential-repository-documentdb.js +1 -71
- package/credential/repositories/credential-repository-interface.js +2 -8
- package/credential/repositories/credential-repository-mongo.js +4 -45
- package/credential/repositories/credential-repository-postgres.js +3 -44
- package/credential/repositories/credential-repository.js +4 -6
- package/credential/use-cases/get-credential-for-user.js +3 -21
- package/credential/use-cases/update-authentication-status.js +2 -5
- package/database/MONGODB_TRANSACTION_FIX.md +52 -72
- package/database/adapters/lambda-invoker.js +7 -8
- package/database/config.js +13 -15
- package/database/documentdb-encryption-service.js +13 -29
- package/database/documentdb-utils.js +12 -21
- package/database/encryption/README.md +36 -53
- package/database/encryption/encryption-schema-registry.js +9 -21
- package/database/encryption/field-encryption-service.js +4 -15
- package/database/encryption/logger.js +2 -3
- package/database/encryption/prisma-encryption-extension.js +8 -5
- package/database/index.js +2 -4
- package/database/models/IndividualUser.js +15 -15
- package/database/models/OrganizationUser.js +4 -6
- package/database/models/UserModel.js +2 -2
- package/database/models/WebsocketConnection.js +1 -4
- package/database/mongoose.js +2 -2
- package/database/prisma.js +14 -22
- package/database/repositories/health-check-repository-documentdb.js +7 -22
- package/database/repositories/health-check-repository-factory.js +3 -9
- package/database/repositories/health-check-repository-interface.js +5 -15
- package/database/repositories/health-check-repository-mongodb.js +6 -9
- package/database/repositories/health-check-repository-postgres.js +1 -1
- package/database/repositories/migration-status-repository-s3.js +5 -10
- package/database/use-cases/check-database-health-use-case.js +2 -3
- package/database/use-cases/check-database-state-use-case.js +7 -9
- package/database/use-cases/get-database-state-via-worker-use-case.js +12 -15
- package/database/use-cases/get-migration-status-use-case.js +2 -4
- package/database/use-cases/run-database-migration-use-case.js +9 -41
- package/database/use-cases/test-encryption-use-case.js +5 -4
- package/database/use-cases/trigger-database-migration-use-case.js +8 -9
- package/database/utils/mongodb-collection-utils.js +3 -11
- package/database/utils/mongodb-schema-init.js +4 -10
- package/database/utils/prisma-runner.js +74 -144
- package/database/utils/prisma-schema-parser.js +2 -2
- package/docs/PROCESS_MANAGEMENT_QUEUE_SPEC.md +80 -135
- package/encrypt/Cryptor.js +2 -8
- package/errors/fetch-error.js +1 -1
- package/generated/prisma-mongodb/edge.js +16 -59
- package/generated/prisma-mongodb/index-browser.js +12 -62
- package/generated/prisma-mongodb/index.d.ts +4850 -8136
- package/generated/prisma-mongodb/index.js +16 -59
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +33 -75
- package/generated/prisma-mongodb/wasm.js +16 -59
- package/generated/prisma-postgresql/edge.js +15 -59
- package/generated/prisma-postgresql/index-browser.js +11 -62
- package/generated/prisma-postgresql/index.d.ts +5963 -8930
- package/generated/prisma-postgresql/index.js +15 -59
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +33 -73
- package/generated/prisma-postgresql/wasm.js +15 -59
- package/handlers/WEBHOOKS.md +81 -104
- package/handlers/app-definition-loader.js +1 -1
- package/handlers/app-handler-helpers.js +2 -14
- package/handlers/backend-utils.js +1 -0
- package/handlers/database-migration-handler.js +45 -64
- package/handlers/middleware/admin-auth.js +53 -0
- package/handlers/routers/HEALTHCHECK.md +135 -170
- package/handlers/routers/auth.js +2 -23
- package/handlers/routers/db-migration.handler.js +3 -2
- package/handlers/routers/db-migration.js +33 -69
- package/handlers/routers/health.js +8 -23
- package/handlers/routers/integration-defined-routers.js +4 -4
- package/handlers/routers/integration-webhook-routers.js +7 -17
- package/handlers/routers/websocket.js +3 -9
- package/handlers/use-cases/check-integrations-health-use-case.js +6 -13
- package/handlers/workers/db-migration.js +26 -54
- package/index.js +9 -5
- package/integrations/WEBHOOK-QUICKSTART.md +14 -21
- package/integrations/index.js +0 -4
- package/integrations/integration-base.js +6 -9
- package/integrations/integration-router.js +146 -1817
- package/integrations/options.js +20 -47
- package/integrations/repositories/integration-repository-documentdb.js +24 -53
- package/integrations/repositories/integration-repository-factory.js +2 -6
- package/integrations/repositories/integration-repository-interface.js +9 -27
- package/integrations/repositories/integration-repository-postgres.js +3 -3
- package/integrations/repositories/process-repository-factory.js +1 -0
- package/integrations/repositories/process-repository-interface.js +5 -9
- package/integrations/repositories/process-repository-mongo.js +3 -7
- package/integrations/repositories/process-repository-postgres.js +2 -2
- package/integrations/tests/doubles/config-capturing-integration.js +8 -9
- package/integrations/tests/doubles/dummy-integration-class.js +8 -81
- package/integrations/tests/doubles/test-integration-repository.js +11 -51
- package/integrations/use-cases/create-integration.js +32 -36
- package/integrations/use-cases/create-process.js +9 -20
- package/integrations/use-cases/delete-integration-for-user.js +4 -5
- package/integrations/use-cases/get-integration-for-user.js +10 -25
- package/integrations/use-cases/get-integration-instance-by-definition.js +7 -13
- package/integrations/use-cases/get-integrations-for-user.js +1 -4
- package/integrations/use-cases/get-possible-integrations.js +1 -1
- package/integrations/use-cases/get-process.js +6 -5
- package/integrations/use-cases/index.js +1 -3
- package/integrations/use-cases/load-integration-context.js +5 -1
- package/integrations/use-cases/update-process-state.js +8 -10
- package/integrations/utils/map-integration-dto.js +3 -9
- package/jest-setup.js +1 -1
- package/jest-teardown.js +1 -1
- package/lambda/TimeoutCatcher.js +30 -32
- package/lambda/index.js +1 -1
- package/logs/index.js +3 -3
- package/modules/module.js +1 -3
- package/modules/repositories/module-repository-documentdb.js +48 -114
- package/modules/repositories/module-repository-interface.js +0 -13
- package/modules/repositories/module-repository-mongo.js +6 -46
- package/modules/repositories/module-repository-postgres.js +6 -48
- package/modules/repositories/module-repository.js +1 -34
- package/modules/requester/api-key.js +2 -0
- package/modules/requester/basic.js +1 -0
- package/modules/requester/oauth-2.js +2 -3
- package/modules/test/mock-api/definition.js +10 -15
- package/modules/test/mock-api/mocks/hubspot.js +36 -36
- package/modules/tests/doubles/test-module-factory.js +4 -10
- package/modules/tests/doubles/test-module-repository.js +1 -1
- package/modules/use-cases/get-entities-for-user.js +1 -1
- package/modules/use-cases/get-entity-options-by-id.js +6 -8
- package/modules/use-cases/get-module.js +9 -12
- package/modules/use-cases/process-authorization-callback.js +6 -12
- package/modules/use-cases/refresh-entity-options.js +6 -8
- package/modules/use-cases/test-module-auth.js +6 -8
- package/modules/utils/map-module-dto.js +2 -2
- package/package.json +5 -7
- package/prisma-mongodb/schema.prisma +33 -75
- package/prisma-postgresql/schema.prisma +33 -73
- package/queues/queuer-util.js +1 -5
- package/syncs/model.js +51 -51
- package/syncs/repositories/sync-repository-documentdb.js +19 -39
- package/syncs/repositories/sync-repository-interface.js +2 -6
- package/syncs/repositories/sync-repository-postgres.js +13 -19
- package/syncs/sync.js +100 -104
- package/token/repositories/token-repository-factory.js +3 -1
- package/types/assertions/index.d.ts +72 -72
- package/types/associations/index.d.ts +57 -57
- package/types/core/index.d.ts +53 -59
- package/types/database/index.d.ts +2 -2
- package/types/encrypt/index.d.ts +3 -3
- package/types/errors/index.d.ts +54 -61
- package/types/eslint-config/index.d.ts +40 -40
- package/types/integrations/index.d.ts +183 -185
- package/types/lambda/index.d.ts +26 -26
- package/types/logs/index.d.ts +4 -4
- package/types/module-plugin/index.d.ts +237 -239
- package/types/prettier-config/index.d.ts +5 -5
- package/types/syncs/index.d.ts +108 -102
- package/types/test-environment/index.d.ts +14 -14
- package/types/tsconfig.json +93 -95
- package/user/tests/doubles/test-user-repository.js +2 -5
- package/user/use-cases/authenticate-user.js +4 -2
- package/user/use-cases/authenticate-with-shared-secret.js +1 -1
- package/user/use-cases/create-individual-user.js +7 -8
- 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/get-user-from-adopter-jwt.js +2 -0
- package/user/use-cases/get-user-from-bearer-token.js +3 -7
- package/user/use-cases/get-user-from-x-frigg-headers.js +11 -14
- package/user/use-cases/login-user.js +8 -8
- package/user/user.js +4 -18
- package/utils/backend-path.js +2 -2
- package/utils/index.js +1 -4
- package/websocket/repositories/websocket-connection-repository-documentdb.js +8 -21
- package/websocket/repositories/websocket-connection-repository-mongo.js +4 -8
- package/websocket/repositories/websocket-connection-repository-postgres.js +4 -8
- package/websocket/repositories/websocket-connection-repository.js +4 -8
- package/admin-scripts/repositories/admin-api-key-repository-interface.js +0 -121
- package/admin-scripts/repositories/admin-api-key-repository-mongo.js +0 -155
- package/admin-scripts/repositories/admin-api-key-repository-postgres.js +0 -189
- package/admin-scripts/repositories/script-execution-repository-documentdb.js +0 -21
- package/admin-scripts/repositories/script-execution-repository-factory.js +0 -55
- package/admin-scripts/repositories/script-execution-repository-interface.js +0 -193
- package/admin-scripts/repositories/script-execution-repository-mongo.js +0 -278
- package/admin-scripts/repositories/script-execution-repository-postgres.js +0 -320
- package/credential/credential-router.js +0 -262
- package/credential/use-cases/delete-credential-for-user.js +0 -50
- package/credential/use-cases/list-credentials-for-user.js +0 -31
- package/credential/use-cases/reauthorize-credential.js +0 -103
- package/handlers/routers/admin.js +0 -450
- package/handlers/routers/docs.js +0 -180
- package/handlers/routers/middleware/loadUser.js +0 -39
- package/handlers/routers/middleware/requireAdmin.js +0 -41
- package/handlers/routers/middleware/requireLoggedInUser.js +0 -19
- package/integrations/use-cases/execute-proxy-request.js +0 -564
- package/modules/domain/entities/AuthorizationSession.js +0 -131
- package/modules/domain/entities/index.js +0 -10
- package/modules/repositories/authorization-session-repository-factory.js +0 -55
- package/modules/repositories/authorization-session-repository-interface.js +0 -75
- package/modules/repositories/authorization-session-repository-mongo.js +0 -169
- package/modules/repositories/authorization-session-repository-postgres.js +0 -170
- package/modules/use-cases/delete-module-entity.js +0 -23
- package/modules/use-cases/get-authorization-requirements.js +0 -110
- package/modules/use-cases/get-module-entity-by-id.js +0 -16
- package/modules/use-cases/process-authorization-step.js +0 -160
- package/modules/use-cases/start-authorization-session.js +0 -86
- package/modules/use-cases/update-module-entity.js +0 -27
- package/openapi/openapi-spec-generator.js +0 -370
- package/openapi/openapi-v1.yaml +0 -1360
- package/openapi/openapi-v2.yaml +0 -1535
- 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
"
|
|
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
|
-
-
|
|
86
|
-
-
|
|
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
|
-
|
|
104
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
-
|
|
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
|
-
-
|
|
143
|
-
-
|
|
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
|
-
-
|
|
150
|
-
-
|
|
151
|
-
-
|
|
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
|
-
-
|
|
157
|
-
-
|
|
158
|
-
-
|
|
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
|
-
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
-
|
|
249
|
-
-
|
|
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
|
-
-
|
|
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
|
-
-
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
-
|
|
263
|
-
-
|
|
264
|
-
-
|
|
265
|
-
-
|
|
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
|
-
-
|
|
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
|
-
-
|
|
280
|
-
-
|
|
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:**
|
|
275
|
+
**New Use Cases:**
|
|
276
|
+
4. `CheckExternalServicesUseCase` - Check external API availability (from health.js:183-209)
|
|
309
277
|
|
|
310
|
-
**New Repositories:**
|
|
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:**
|
|
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
|
-
-
|
|
325
|
-
-
|
|
326
|
-
-
|
|
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
|
-
-
|
|
348
|
-
-
|
|
349
|
-
-
|
|
350
|
-
-
|
|
351
|
-
-
|
|
352
|
-
-
|
|
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
|
-
-
|
|
357
|
-
-
|
|
358
|
-
-
|
|
359
|
-
-
|
|
360
|
-
-
|
|
361
|
-
-
|
|
362
|
-
-
|
|
363
|
-
-
|
|
364
|
-
-
|
|
365
|
-
-
|
|
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
|
-
|
|
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.
|
package/handlers/routers/auth.js
CHANGED
|
@@ -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
|
|
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
|
+
|