@friggframework/core 2.0.0--canary.397.fe6d7a2.0 → 2.0.0--canary.405.91dae19.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 (100) hide show
  1. package/README.md +50 -931
  2. package/core/create-handler.js +0 -1
  3. package/encrypt/encrypt.js +4 -27
  4. package/handlers/app-handler-helpers.js +3 -0
  5. package/handlers/backend-utils.js +44 -42
  6. package/handlers/routers/HEALTHCHECK.md +240 -0
  7. package/handlers/routers/auth.js +14 -3
  8. package/handlers/routers/health.js +451 -0
  9. package/handlers/routers/health.test.js +203 -0
  10. package/handlers/routers/integration-defined-routers.js +5 -8
  11. package/handlers/routers/middleware/loadUser.js +15 -0
  12. package/handlers/routers/middleware/requireLoggedInUser.js +12 -0
  13. package/handlers/routers/user.js +5 -25
  14. package/handlers/workers/integration-defined-workers.js +3 -6
  15. package/index.js +16 -1
  16. package/integrations/create-frigg-backend.js +31 -0
  17. package/integrations/index.js +5 -0
  18. package/integrations/integration-base.js +46 -142
  19. package/integrations/integration-factory.js +251 -0
  20. package/integrations/integration-router.js +181 -303
  21. package/integrations/integration-user.js +144 -0
  22. package/integrations/options.js +1 -1
  23. package/integrations/test/integration-base.test.js +144 -0
  24. package/module-plugin/auther.js +393 -0
  25. package/module-plugin/entity-manager.js +70 -0
  26. package/{modules → module-plugin}/entity.js +0 -1
  27. package/{modules → module-plugin}/index.js +8 -0
  28. package/module-plugin/manager.js +169 -0
  29. package/module-plugin/module-factory.js +61 -0
  30. package/{modules → module-plugin}/test/mock-api/api.js +3 -8
  31. package/{modules → module-plugin}/test/mock-api/definition.js +8 -12
  32. package/package.json +5 -5
  33. package/syncs/sync.js +1 -0
  34. package/types/integrations/index.d.ts +6 -2
  35. package/types/module-plugin/index.d.ts +56 -4
  36. package/types/syncs/index.d.ts +2 -0
  37. package/credential/credential-repository.js +0 -56
  38. package/credential/use-cases/get-credential-for-user.js +0 -21
  39. package/credential/use-cases/update-authentication-status.js +0 -15
  40. package/handlers/app-definition-loader.js +0 -38
  41. package/integrations/integration-repository.js +0 -80
  42. package/integrations/tests/doubles/dummy-integration-class.js +0 -90
  43. package/integrations/tests/doubles/test-integration-repository.js +0 -89
  44. package/integrations/tests/use-cases/create-integration.test.js +0 -124
  45. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -143
  46. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -143
  47. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -169
  48. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -169
  49. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
  50. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
  51. package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
  52. package/integrations/tests/use-cases/update-integration.test.js +0 -134
  53. package/integrations/use-cases/create-integration.js +0 -71
  54. package/integrations/use-cases/delete-integration-for-user.js +0 -72
  55. package/integrations/use-cases/get-integration-for-user.js +0 -78
  56. package/integrations/use-cases/get-integration-instance-by-definition.js +0 -67
  57. package/integrations/use-cases/get-integration-instance.js +0 -82
  58. package/integrations/use-cases/get-integrations-for-user.js +0 -76
  59. package/integrations/use-cases/get-possible-integrations.js +0 -27
  60. package/integrations/use-cases/index.js +0 -11
  61. package/integrations/use-cases/update-integration-messages.js +0 -31
  62. package/integrations/use-cases/update-integration-status.js +0 -28
  63. package/integrations/use-cases/update-integration.js +0 -91
  64. package/integrations/utils/map-integration-dto.js +0 -36
  65. package/modules/module-factory.js +0 -54
  66. package/modules/module-repository.js +0 -107
  67. package/modules/module.js +0 -218
  68. package/modules/tests/doubles/test-module-factory.js +0 -16
  69. package/modules/tests/doubles/test-module-repository.js +0 -19
  70. package/modules/use-cases/get-entities-for-user.js +0 -32
  71. package/modules/use-cases/get-entity-options-by-id.js +0 -58
  72. package/modules/use-cases/get-entity-options-by-type.js +0 -34
  73. package/modules/use-cases/get-module-instance-from-type.js +0 -31
  74. package/modules/use-cases/get-module.js +0 -56
  75. package/modules/use-cases/process-authorization-callback.js +0 -108
  76. package/modules/use-cases/refresh-entity-options.js +0 -58
  77. package/modules/use-cases/test-module-auth.js +0 -54
  78. package/modules/utils/map-module-dto.js +0 -18
  79. package/user/tests/doubles/test-user-repository.js +0 -72
  80. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  81. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  82. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  83. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  84. package/user/tests/use-cases/login-user.test.js +0 -140
  85. package/user/use-cases/create-individual-user.js +0 -61
  86. package/user/use-cases/create-organization-user.js +0 -47
  87. package/user/use-cases/create-token-for-user-id.js +0 -30
  88. package/user/use-cases/get-user-from-bearer-token.js +0 -77
  89. package/user/use-cases/login-user.js +0 -122
  90. package/user/user-repository.js +0 -62
  91. package/user/user.js +0 -77
  92. /package/{modules → module-plugin}/ModuleConstants.js +0 -0
  93. /package/{modules → module-plugin}/credential.js +0 -0
  94. /package/{modules → module-plugin}/requester/api-key.js +0 -0
  95. /package/{modules → module-plugin}/requester/basic.js +0 -0
  96. /package/{modules → module-plugin}/requester/oauth-2.js +0 -0
  97. /package/{modules → module-plugin}/requester/requester.js +0 -0
  98. /package/{modules → module-plugin}/requester/requester.test.js +0 -0
  99. /package/{modules → module-plugin}/test/auther.test.js +0 -0
  100. /package/{modules → module-plugin}/test/mock-api/mocks/hubspot.js +0 -0
@@ -34,7 +34,6 @@ const createHandler = (optionByName = {}) => {
34
34
  // Helps mongoose reuse the connection. Lowers response times.
35
35
  context.callbackWaitsForEmptyEventLoop = false;
36
36
 
37
- // todo: this should not be necessary anymore
38
37
  if (shouldUseDatabase) {
39
38
  await connectToDatabase();
40
39
  }
@@ -17,7 +17,6 @@ const findOneEvents = [
17
17
  const shouldBypassEncryption = (STAGE) => {
18
18
  const defaultBypassStages = ['dev', 'test', 'local'];
19
19
  const bypassStageEnv = process.env.BYPASS_ENCRYPTION_STAGE;
20
- // If the env is set to anything or an empty string, use the env. Otherwise, use the default array
21
20
  const useEnv = !String(bypassStageEnv) || !!bypassStageEnv;
22
21
  const bypassStages = useEnv
23
22
  ? bypassStageEnv.split(',').map((stage) => stage.trim())
@@ -25,19 +24,15 @@ const shouldBypassEncryption = (STAGE) => {
25
24
  return bypassStages.includes(STAGE);
26
25
  };
27
26
 
28
- // The Mongoose plug-in function
29
- function Encrypt(schema, options) {
27
+ function Encrypt(schema) {
30
28
  const { STAGE, KMS_KEY_ARN, AES_KEY_ID } = process.env;
31
29
 
32
30
  if (shouldBypassEncryption(STAGE)) {
33
31
  return;
34
32
  }
35
33
 
36
- if (KMS_KEY_ARN && AES_KEY_ID) {
37
- throw new Error(
38
- 'Local and AWS encryption keys are both set in the environment.'
39
- );
40
- }
34
+ const hasAES = AES_KEY_ID && AES_KEY_ID.trim() !== '';
35
+ const hasKMS = KMS_KEY_ARN && KMS_KEY_ARN.trim() !== '' && !hasAES;
41
36
 
42
37
  const fields = Object.values(schema.paths)
43
38
  .map(({ path, options }) => (options.lhEncrypt === true ? path : ''))
@@ -48,25 +43,17 @@ function Encrypt(schema, options) {
48
43
  }
49
44
 
50
45
  const cryptor = new Cryptor({
51
- // Use AWS if the CMK is present
52
- shouldUseAws: !!KMS_KEY_ARN,
53
- // Find all the fields in the schema with lhEncrypt === true
46
+ shouldUseAws: hasKMS,
54
47
  fields: fields,
55
48
  });
56
49
 
57
- // ---------------------------------------------
58
- // ### Encrypt fields before save/update/insert.
59
- // ---------------------------------------------
60
-
61
50
  schema.pre('save', async function encryptionPreSave() {
62
- // `this` will be a doc
63
51
  await cryptor.encryptFieldsInDocuments([this]);
64
52
  });
65
53
 
66
54
  schema.pre(
67
55
  'insertMany',
68
56
  async function encryptionPreInsertMany(_, docs, options) {
69
- // `this` will be the model
70
57
  if (options?.rawResult) {
71
58
  throw new Error(
72
59
  'Raw result not supported for insertMany with Encrypt plugin'
@@ -78,17 +65,14 @@ function Encrypt(schema, options) {
78
65
  );
79
66
 
80
67
  schema.pre(updateOneEvents, async function encryptionPreUpdateOne() {
81
- // `this` will be a query
82
68
  await cryptor.encryptFieldsInQuery(this);
83
69
  });
84
70
 
85
71
  schema.pre('updateMany', async function encryptionPreUpdateMany() {
86
- // `this` will be a query
87
72
  cryptor.expectNotToUpdateManyEncrypted(this.getUpdate());
88
73
  });
89
74
 
90
75
  schema.pre('update', async function encryptionPreUpdate() {
91
- // `this` will be a query
92
76
  const { multiple } = this.getOptions();
93
77
 
94
78
  if (multiple) {
@@ -99,16 +83,11 @@ function Encrypt(schema, options) {
99
83
  await cryptor.encryptFieldsInQuery(this);
100
84
  });
101
85
 
102
- // --------------------------------------------
103
- // ### Decrypt documents after they are loaded.
104
- // --------------------------------------------
105
86
  schema.post('save', async function encryptionPreSave() {
106
- // `this` will be a doc
107
87
  await cryptor.decryptFieldsInDocuments([this]);
108
88
  });
109
89
 
110
90
  schema.post(findOneEvents, async function encryptionPostFindOne(doc) {
111
- // `this` will be a query
112
91
  const { rawResult } = this.getOptions();
113
92
 
114
93
  if (rawResult) {
@@ -119,12 +98,10 @@ function Encrypt(schema, options) {
119
98
  });
120
99
 
121
100
  schema.post('find', async function encryptionPostFind(docs) {
122
- // `this` will be a query
123
101
  await cryptor.decryptFieldsInDocuments(docs);
124
102
  });
125
103
 
126
104
  schema.post('insertMany', async function encryptionPostInsertMany(docs) {
127
- // `this` will be the model
128
105
  await cryptor.decryptFieldsInDocuments(docs);
129
106
  });
130
107
  }
@@ -3,6 +3,7 @@ const express = require('express');
3
3
  const bodyParser = require('body-parser');
4
4
  const cors = require('cors');
5
5
  const Boom = require('@hapi/boom');
6
+ const loadUserManager = require('./routers/middleware/loadUser');
6
7
  const serverlessHttp = require('serverless-http');
7
8
 
8
9
  const createApp = (applyMiddleware) => {
@@ -19,6 +20,8 @@ const createApp = (applyMiddleware) => {
19
20
  })
20
21
  );
21
22
 
23
+ app.use(loadUserManager);
24
+
22
25
  if (applyMiddleware) applyMiddleware(app);
23
26
 
24
27
  // Handle sending error response and logging server errors to console
@@ -1,35 +1,36 @@
1
+ const { createFriggBackend, Worker } = require('@friggframework/core');
2
+ const { findNearestBackendPackageJson } = require('@friggframework/core/utils');
3
+ const path = require('node:path');
4
+ const fs = require('fs-extra');
5
+
6
+ const backendPath = findNearestBackendPackageJson();
7
+ if (!backendPath) {
8
+ throw new Error('Could not find backend package.json');
9
+ }
10
+
11
+ const backendDir = path.dirname(backendPath);
12
+ const backendFilePath = path.join(backendDir, 'index.js');
13
+ if (!fs.existsSync(backendFilePath)) {
14
+ throw new Error('Could not find index.js');
15
+ }
16
+
17
+ const backendJsFile = require(backendFilePath);
1
18
  const { Router } = require('express');
2
- const { Worker } = require('@friggframework/core');
3
- const { IntegrationRepository } = require('../integrations/integration-repository');
4
- const { ModuleFactory } = require('../modules/module-factory');
5
- const { getModulesDefinitionFromIntegrationClasses } = require('../integrations/utils/map-integration-dto');
6
- const { ModuleRepository } = require('../modules/module-repository');
7
- const { GetIntegrationInstanceByDefinition } = require('../integrations/use-cases/get-integration-instance-by-definition');
19
+ const appDefinition = backendJsFile.Definition;
8
20
 
21
+ const backend = createFriggBackend(appDefinition);
9
22
  const loadRouterFromObject = (IntegrationClass, routerObject) => {
10
-
11
- const integrationRepository = new IntegrationRepository();
12
- const moduleRepository = new ModuleRepository();
13
- const moduleFactory = new ModuleFactory({
14
- moduleRepository,
15
- moduleDefinitions: getModulesDefinitionFromIntegrationClasses([IntegrationClass]),
16
- });
17
23
  const router = Router();
18
24
  const { path, method, event } = routerObject;
19
-
20
25
  console.log(
21
26
  `Registering ${method} ${path} for ${IntegrationClass.Definition.name}`
22
27
  );
23
-
24
28
  router[method.toLowerCase()](path, async (req, res, next) => {
25
29
  try {
26
- const getIntegrationInstanceByDefinition = new GetIntegrationInstanceByDefinition({
27
- integrationRepository,
28
- moduleFactory,
29
- moduleRepository,
30
- });
31
- const integration = await getIntegrationInstanceByDefinition.execute(IntegrationClass);
32
- const result = await integration.send(event, { req, res, next });
30
+ const integration = new IntegrationClass({});
31
+ await integration.loadModules();
32
+ await integration.registerEventHandlers();
33
+ const result = await integration.send(event, {req, res, next});
33
34
  res.json(result);
34
35
  } catch (error) {
35
36
  next(error);
@@ -38,29 +39,29 @@ const loadRouterFromObject = (IntegrationClass, routerObject) => {
38
39
 
39
40
  return router;
40
41
  };
41
-
42
- //todo: this should be in a use case class
43
- const createQueueWorker = (integrationClass) => {
42
+ const createQueueWorker = (integrationClass, integrationFactory) => {
44
43
  class QueueWorker extends Worker {
45
-
46
- integrationRepository = new IntegrationRepository();
47
- moduleRepository = new ModuleRepository();
48
- moduleFactory = new ModuleFactory({
49
- moduleRepository: this.moduleRepository,
50
- moduleDefinitions: getModulesDefinitionFromIntegrationClasses([integrationClass]),
51
- });
52
-
53
44
  async _run(params, context) {
54
45
  try {
55
- const getIntegrationInstanceByDefinition = new GetIntegrationInstanceByDefinition({
56
- integrationRepository: this.integrationRepository,
57
- moduleFactory: this.moduleFactory,
58
- moduleRepository: this.moduleRepository,
59
- });
60
-
61
- const integration = await getIntegrationInstanceByDefinition.execute(integrationClass);
62
-
63
- const res = await integration.send(params.event, {
46
+ let instance;
47
+ if (!params.integrationId) {
48
+ instance = new integrationClass({});
49
+ await instance.loadModules();
50
+ // await instance.loadUserActions();
51
+ await instance.registerEventHandlers();
52
+ console.log(
53
+ `${params.event} for ${integrationClass.Definition.name} integration with no integrationId`
54
+ );
55
+ } else {
56
+ instance =
57
+ await integrationFactory.getInstanceFromIntegrationId({
58
+ integrationId: params.integrationId,
59
+ });
60
+ console.log(
61
+ `${params.event} for ${instance.record.config.type} of integrationId: ${params.integrationId}`
62
+ );
63
+ }
64
+ const res = await instance.send(params.event, {
64
65
  data: params.data,
65
66
  context,
66
67
  });
@@ -78,6 +79,7 @@ const createQueueWorker = (integrationClass) => {
78
79
  };
79
80
 
80
81
  module.exports = {
82
+ ...backend,
81
83
  loadRouterFromObject,
82
84
  createQueueWorker,
83
85
  };
@@ -0,0 +1,240 @@
1
+ # Frigg Healthcheck Endpoint Documentation
2
+
3
+ ## Overview
4
+
5
+ The Frigg service includes comprehensive healthcheck endpoints to monitor service health, connectivity, and readiness. These endpoints follow industry best practices and are designed for use with monitoring systems, load balancers, and container orchestration platforms.
6
+
7
+ ## Endpoints
8
+
9
+ ### 1. Basic Health Check
10
+ **GET** `/health`
11
+
12
+ Simple health check endpoint that returns basic service information. No authentication required. This endpoint is rate-limited at the API Gateway level.
13
+
14
+ **Response:**
15
+ ```json
16
+ {
17
+ "status": "ok",
18
+ "timestamp": "2024-01-10T12:00:00.000Z",
19
+ "service": "frigg-core-api"
20
+ }
21
+ ```
22
+
23
+ **Status Codes:**
24
+ - `200 OK` - Service is running
25
+
26
+ ### 2. Detailed Health Check
27
+ **GET** `/health/detailed`
28
+
29
+ Comprehensive health check that tests all service components and dependencies.
30
+
31
+ **Authentication Required:**
32
+ - Header: `x-api-key: YOUR_API_KEY`
33
+ - The API key must match the `HEALTH_API_KEY` environment variable
34
+
35
+ **Response:**
36
+ ```json
37
+ {
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
46
+ },
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
74
+ }
75
+ ```
76
+
77
+ **Status Codes:**
78
+ - `200 OK` - Service is healthy (all components operational)
79
+ - `503 Service Unavailable` - Service is unhealthy (any component failure)
80
+ - `401 Unauthorized` - Missing or invalid x-api-key header
81
+
82
+ ### 3. Liveness Probe
83
+ **GET** `/health/live`
84
+
85
+ Kubernetes-style liveness probe. Returns whether the service process is alive.
86
+
87
+ **Authentication Required:**
88
+ - Header: `x-api-key: YOUR_API_KEY`
89
+
90
+ **Response:**
91
+ ```json
92
+ {
93
+ "status": "alive",
94
+ "timestamp": "2024-01-10T12:00:00.000Z"
95
+ }
96
+ ```
97
+
98
+ **Status Codes:**
99
+ - `200 OK` - Service process is alive
100
+
101
+ ### 4. Readiness Probe
102
+ **GET** `/health/ready`
103
+
104
+ Kubernetes-style readiness probe. Returns whether the service is ready to receive traffic.
105
+
106
+ **Authentication Required:**
107
+ - Header: `x-api-key: YOUR_API_KEY`
108
+
109
+ **Response:**
110
+ ```json
111
+ {
112
+ "ready": true,
113
+ "timestamp": "2024-01-10T12:00:00.000Z",
114
+ "checks": {
115
+ "database": true,
116
+ "modules": true
117
+ }
118
+ }
119
+ ```
120
+
121
+ **Status Codes:**
122
+ - `200 OK` - Service is ready
123
+ - `503 Service Unavailable` - Service is not ready
124
+
125
+ ## Health Status Definitions
126
+
127
+ - **healthy**: All components are functioning normally
128
+ - **unhealthy**: Any component is failing, service may not function properly
129
+
130
+ ## Component Checks
131
+
132
+ ### Database Connectivity
133
+ - Checks database connection state
134
+ - Performs ping test with 2-second timeout if connected
135
+ - Reports connection state and response time
136
+ - Database type is not exposed for security reasons
137
+
138
+ ### External API Connectivity
139
+ - Tests connectivity to external services (GitHub, npm registry)
140
+ - Configurable timeout (default: 5 seconds)
141
+ - Reports reachability and response times
142
+ - Uses Promise.all for parallel checking
143
+
144
+ ### Integration Status
145
+ - Verifies available modules and integrations are loaded
146
+ - Reports counts and lists of available components
147
+
148
+ ## Usage Examples
149
+
150
+ ### Monitoring Systems
151
+ Configure your monitoring system to poll `/health/detailed` every 30-60 seconds:
152
+ ```bash
153
+ curl -H "x-api-key: YOUR_API_KEY" https://your-frigg-instance.com/health/detailed
154
+ ```
155
+
156
+ ### Load Balancer Health Checks
157
+ Configure load balancers to use the simple `/health` endpoint:
158
+ ```bash
159
+ curl https://your-frigg-instance.com/health
160
+ ```
161
+
162
+ ### Kubernetes Configuration
163
+ ```yaml
164
+ livenessProbe:
165
+ httpGet:
166
+ path: /health/live
167
+ port: 8080
168
+ httpHeaders:
169
+ - name: x-api-key
170
+ value: YOUR_API_KEY
171
+ periodSeconds: 10
172
+ timeoutSeconds: 5
173
+
174
+ readinessProbe:
175
+ httpGet:
176
+ path: /health/ready
177
+ port: 8080
178
+ httpHeaders:
179
+ - name: x-api-key
180
+ value: YOUR_API_KEY
181
+ initialDelaySeconds: 30
182
+ periodSeconds: 10
183
+ ```
184
+
185
+ ## Customization
186
+
187
+ ### Adding External API Checks
188
+ To add more external API checks, modify the `externalAPIs` array in the health router:
189
+ ```javascript
190
+ const externalAPIs = [
191
+ { name: 'github', url: 'https://api.github.com/status' },
192
+ { name: 'npm', url: 'https://registry.npmjs.org' },
193
+ { name: 'your-api', url: 'https://your-api.com/health' }
194
+ ];
195
+ ```
196
+
197
+ ### Adjusting Timeouts
198
+ The default timeout for external API checks is 5 seconds. Database ping timeout is set to 2 seconds:
199
+ ```javascript
200
+ const checkExternalAPI = (url, timeout = 5000) => {
201
+ // ...
202
+ };
203
+
204
+ await mongoose.connection.db.admin().ping({ maxTimeMS: 2000 });
205
+ ```
206
+
207
+ ## Best Practices
208
+
209
+ 1. **Authentication**: Basic `/health` endpoint requires no authentication, but detailed endpoints require `x-api-key` header
210
+ 2. **Rate Limiting**: Configure rate limiting at the API Gateway level to prevent abuse
211
+ 3. **Fast Response**: Health checks should respond quickly (< 1 second)
212
+ 4. **Strict Status Codes**: Return 503 for any non-healthy state to ensure proper alerting
213
+ 5. **Detailed Logging**: Failed health checks are logged for debugging
214
+ 6. **Security**: No sensitive information (DB types, versions) exposed in responses
215
+ 7. **Lambda Considerations**: Uptime and memory metrics not included as they're not relevant in serverless
216
+
217
+ ## Troubleshooting
218
+
219
+ ### Database Connection Issues
220
+ - Check `MONGO_URI` environment variable
221
+ - Verify network connectivity to MongoDB
222
+ - Check MongoDB server status
223
+
224
+ ### External API Failures
225
+ - May indicate network issues or external service downtime
226
+ - Service reports "unhealthy" status if any external API is unreachable
227
+
228
+ ## Security Considerations
229
+
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
237
+
238
+ ## Environment Variables
239
+
240
+ - `HEALTH_API_KEY`: Required API key for accessing detailed health endpoints
@@ -1,15 +1,26 @@
1
1
  const { createIntegrationRouter } = require('@friggframework/core');
2
2
  const { createAppHandler } = require('./../app-handler-helpers');
3
+ const { requireLoggedInUser } = require('./middleware/requireLoggedInUser');
4
+ const {
5
+ moduleFactory,
6
+ integrationFactory,
7
+ IntegrationHelper,
8
+ } = require('./../backend-utils');
3
9
 
4
- const router = createIntegrationRouter();
10
+ const router = createIntegrationRouter({
11
+ factory: { moduleFactory, integrationFactory, IntegrationHelper },
12
+ requireLoggedInUser,
13
+ getUserId: (req) => req.user.getUserId(),
14
+ });
5
15
 
6
16
  router.route('/redirect/:appId').get((req, res) => {
7
17
  res.redirect(
8
- `${process.env.FRONTEND_URI}/redirect/${req.params.appId
18
+ `${process.env.FRONTEND_URI}/redirect/${
19
+ req.params.appId
9
20
  }?${new URLSearchParams(req.query)}`
10
21
  );
11
22
  });
12
23
 
13
24
  const handler = createAppHandler('HTTP Event: Auth', router);
14
25
 
15
- module.exports = { handler };
26
+ module.exports = { handler, router };