@friggframework/core 2.0.0--canary.490.10eff0a.0 → 2.0.0--canary.493.f8d621f.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.
@@ -29,21 +29,32 @@ class HealthCheckRepositoryMongoDB extends HealthCheckRepositoryInterface {
29
29
  }
30
30
 
31
31
  return {
32
+ readyState: isConnected ? 1 : 0,
32
33
  readyState: isConnected ? 1 : 0,
33
34
  stateName,
34
35
  isConnected,
35
36
  };
36
37
  }
37
38
 
38
- /**
39
- * @param {number} maxTimeMS
40
- * @returns {Promise<number>} Response time in milliseconds
41
- */
42
39
  async pingDatabase(maxTimeMS = 2000) {
43
40
  const pingStart = Date.now();
44
- await this.prisma.$queryRaw`SELECT 1`.catch(() => {
45
- return this.prisma.$runCommandRaw({ ping: 1 });
46
- });
41
+
42
+ // Create a timeout promise that rejects after maxTimeMS
43
+ const timeoutPromise = new Promise((_, reject) =>
44
+ setTimeout(() => reject(new Error('Database ping timeout')), maxTimeMS)
45
+ );
46
+
47
+ // Race between the database ping and the timeout
48
+ await Promise.race([
49
+ prisma.$queryRaw`SELECT 1`.catch(() => {
50
+ // For MongoDB, use runCommandRaw instead
51
+ return prisma.$runCommandRaw({ ping: 1 });
52
+ }),
53
+ timeoutPromise
54
+ ]);
55
+
56
+ return Date.now() - pingStart;
57
+ }
47
58
  return Date.now() - pingStart;
48
59
  }
49
60
 
@@ -113,6 +113,7 @@ function createIntegrationRouter() {
113
113
  const deleteIntegrationForUser = new DeleteIntegrationForUser({
114
114
  integrationRepository,
115
115
  integrationClasses,
116
+ moduleFactory,
116
117
  });
117
118
 
118
119
  const getIntegrationsForUser = new GetIntegrationsForUser({
@@ -11,13 +11,15 @@ class DeleteIntegrationForUser {
11
11
  * @param {Object} params - Configuration parameters.
12
12
  * @param {import('../repositories/integration-repository-interface').IntegrationRepositoryInterface} params.integrationRepository - Repository for integration data operations.
13
13
  * @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes.
14
+ * @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management.
14
15
  */
15
- constructor({ integrationRepository, integrationClasses }) {
16
+ constructor({ integrationRepository, integrationClasses, moduleFactory }) {
16
17
  /**
17
18
  * @type {import('../repositories/integration-repository-interface').IntegrationRepositoryInterface}
18
19
  */
19
20
  this.integrationRepository = integrationRepository;
20
21
  this.integrationClasses = integrationClasses;
22
+ this.moduleFactory = moduleFactory;
21
23
  }
22
24
 
23
25
  /**
@@ -51,6 +53,32 @@ class DeleteIntegrationForUser {
51
53
  );
52
54
  }
53
55
 
56
+ // Load modules with API clients for webhook deletion
57
+ const modules = [];
58
+ const failedModuleLoads = [];
59
+
60
+ for (const entityId of integrationRecord.entitiesIds) {
61
+ try {
62
+ const moduleInstance = await this.moduleFactory.getModuleInstance(
63
+ entityId,
64
+ integrationRecord.userId
65
+ );
66
+ modules.push(moduleInstance);
67
+ } catch (error) {
68
+ console.error(
69
+ `[Integration Deletion] Failed to load module for entity ${entityId}:`,
70
+ error.message
71
+ );
72
+ failedModuleLoads.push({ entityId, error: error.message });
73
+ }
74
+ }
75
+
76
+ if (failedModuleLoads.length > 0) {
77
+ console.warn(
78
+ `[Integration Deletion] ${failedModuleLoads.length}/${integrationRecord.entitiesIds.length} module(s) failed to load. Webhooks for these modules may require manual cleanup.`
79
+ );
80
+ }
81
+
54
82
  const integrationInstance = new integrationClass({
55
83
  id: integrationRecord.id,
56
84
  userId: integrationRecord.userId,
@@ -59,10 +87,10 @@ class DeleteIntegrationForUser {
59
87
  status: integrationRecord.status,
60
88
  version: integrationRecord.version,
61
89
  messages: integrationRecord.messages,
62
- modules: [],
90
+ modules,
63
91
  });
64
92
 
65
- // 6. Complete async initialization (load dynamic actions, register handlers)
93
+ // Complete async initialization (load dynamic actions, register handlers)
66
94
  await integrationInstance.initialize();
67
95
  await integrationInstance.send('ON_DELETE');
68
96
 
@@ -64,19 +64,20 @@ class GetIntegrationsForUser {
64
64
  modules.push(moduleInstance);
65
65
  }
66
66
 
67
- const integrationInstance = new integrationClass({
67
+ const integrationData = {
68
68
  id: integrationRecord.id,
69
69
  userId: integrationRecord.userId,
70
70
  entities: entities,
71
71
  config: integrationRecord.config,
72
72
  status: integrationRecord.status,
73
73
  version: integrationRecord.version,
74
- messages: integrationRecord.messages,
74
+ messages: integrationRecord.messages || { errors: [], warnings: [] },
75
75
  modules,
76
- });
76
+ options: integrationClass.getOptionDetails(),
77
+ };
77
78
 
78
79
  integrations.push(
79
- mapIntegrationClassToIntegrationDTO(integrationInstance)
80
+ mapIntegrationClassToIntegrationDTO(integrationData)
80
81
  );
81
82
  }
82
83
 
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @param {import('../integration').Integration} integration
3
3
  * Convert an Integration domain instance to a plain DTO suitable for JSON responses.
4
+ * Can also accept a plain object with an 'options' property to avoid unnecessary instantiation.
4
5
  */
5
6
  function mapIntegrationClassToIntegrationDTO(integration) {
6
7
  if (!integration) return null;
@@ -14,7 +15,7 @@ function mapIntegrationClassToIntegrationDTO(integration) {
14
15
  version: integration.version,
15
16
  messages: integration.messages,
16
17
  userActions: integration.userActions,
17
- options: integration.getOptionDetails(),
18
+ options: integration.options || (typeof integration.getOptionDetails === 'function' ? integration.getOptionDetails() : null),
18
19
  };
19
20
  }
20
21
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.490.10eff0a.0",
4
+ "version": "2.0.0--canary.493.f8d621f.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -38,9 +38,9 @@
38
38
  }
39
39
  },
40
40
  "devDependencies": {
41
- "@friggframework/eslint-config": "2.0.0--canary.490.10eff0a.0",
42
- "@friggframework/prettier-config": "2.0.0--canary.490.10eff0a.0",
43
- "@friggframework/test": "2.0.0--canary.490.10eff0a.0",
41
+ "@friggframework/eslint-config": "2.0.0--canary.493.f8d621f.0",
42
+ "@friggframework/prettier-config": "2.0.0--canary.493.f8d621f.0",
43
+ "@friggframework/test": "2.0.0--canary.493.f8d621f.0",
44
44
  "@prisma/client": "^6.17.0",
45
45
  "@types/lodash": "4.17.15",
46
46
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "10eff0ae7ff87794900048cb0cc357714232e4cf"
83
+ "gitHead": "f8d621f5fdc06756c1351e99a4686767a46f7064"
84
84
  }