@friggframework/core 2.0.0--canary.496.a94ee46.0 → 2.0.0--canary.490.feacde9.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 (51) hide show
  1. package/core/create-handler.js +63 -12
  2. package/database/PRISMA_BEST_PRACTICES.md +654 -0
  3. package/database/index.js +7 -29
  4. package/database/prisma.js +51 -19
  5. package/database/repositories/health-check-repository-mongodb.js +18 -22
  6. package/database/utils/mongodb-collection-utils.js +26 -18
  7. package/database/utils/mongodb-schema-init.js +7 -12
  8. package/generated/prisma-mongodb/edge.js +6 -6
  9. package/generated/prisma-mongodb/index-browser.js +4 -4
  10. package/generated/prisma-mongodb/index.d.ts +3 -2
  11. package/generated/prisma-mongodb/index.js +6 -6
  12. package/generated/prisma-mongodb/package.json +1 -1
  13. package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
  14. package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
  15. package/generated/prisma-mongodb/runtime/binary.js +2 -2
  16. package/generated/prisma-mongodb/runtime/edge-esm.js +3 -3
  17. package/generated/prisma-mongodb/runtime/edge.js +3 -3
  18. package/generated/prisma-mongodb/runtime/library.d.ts +5 -0
  19. package/generated/prisma-mongodb/runtime/react-native.js +14 -14
  20. package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +18 -18
  21. package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +11 -11
  22. package/generated/prisma-mongodb/wasm.js +6 -6
  23. package/generated/prisma-postgresql/edge.js +6 -6
  24. package/generated/prisma-postgresql/index-browser.js +4 -4
  25. package/generated/prisma-postgresql/index.d.ts +3 -2
  26. package/generated/prisma-postgresql/index.js +6 -6
  27. package/generated/prisma-postgresql/package.json +1 -1
  28. package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
  29. package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
  30. package/generated/prisma-postgresql/query_engine_bg.js +2 -2
  31. package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
  32. package/generated/prisma-postgresql/runtime/binary.js +2 -2
  33. package/generated/prisma-postgresql/runtime/edge-esm.js +3 -3
  34. package/generated/prisma-postgresql/runtime/edge.js +3 -3
  35. package/generated/prisma-postgresql/runtime/library.d.ts +5 -0
  36. package/generated/prisma-postgresql/runtime/react-native.js +14 -14
  37. package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +18 -18
  38. package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +11 -11
  39. package/generated/prisma-postgresql/wasm.js +6 -6
  40. package/integrations/integration-router.js +0 -1
  41. package/integrations/use-cases/delete-integration-for-user.js +3 -31
  42. package/integrations/use-cases/get-integrations-for-user.js +4 -5
  43. package/integrations/utils/map-integration-dto.js +1 -2
  44. package/modules/index.js +0 -2
  45. package/package.json +5 -5
  46. package/associations/model.js +0 -54
  47. package/database/models/UserModel.js +0 -7
  48. package/database/models/WebsocketConnection.js +0 -55
  49. package/database/repositories/health-check-repository.js +0 -108
  50. package/modules/entity.js +0 -46
  51. package/syncs/model.js +0 -62
@@ -35,12 +35,12 @@ exports.Prisma = Prisma
35
35
  exports.$Enums = {}
36
36
 
37
37
  /**
38
- * Prisma Client JS version: 6.17.0
39
- * Query Engine version: c0aafc03b8ef6cdced8654b9a817999e02457d6a
38
+ * Prisma Client JS version: 6.18.0
39
+ * Query Engine version: 34b5a692b7bd79939a9a2c3ef97d816e749cda2f
40
40
  */
41
41
  Prisma.prismaVersion = {
42
- client: "6.17.0",
43
- engine: "c0aafc03b8ef6cdced8654b9a817999e02457d6a"
42
+ client: "6.18.0",
43
+ engine: "34b5a692b7bd79939a9a2c3ef97d816e749cda2f"
44
44
  }
45
45
 
46
46
  Prisma.PrismaClientKnownRequestError = PrismaClientKnownRequestError;
@@ -313,8 +313,8 @@ const config = {
313
313
  "rootEnvPath": null
314
314
  },
315
315
  "relativePath": "../../prisma-postgresql",
316
- "clientVersion": "6.17.0",
317
- "engineVersion": "c0aafc03b8ef6cdced8654b9a817999e02457d6a",
316
+ "clientVersion": "6.18.0",
317
+ "engineVersion": "34b5a692b7bd79939a9a2c3ef97d816e749cda2f",
318
318
  "datasourceNames": [
319
319
  "db"
320
320
  ],
@@ -113,7 +113,6 @@ function createIntegrationRouter() {
113
113
  const deleteIntegrationForUser = new DeleteIntegrationForUser({
114
114
  integrationRepository,
115
115
  integrationClasses,
116
- moduleFactory,
117
116
  });
118
117
 
119
118
  const getIntegrationsForUser = new GetIntegrationsForUser({
@@ -11,15 +11,13 @@ 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.
15
14
  */
16
- constructor({ integrationRepository, integrationClasses, moduleFactory }) {
15
+ constructor({ integrationRepository, integrationClasses }) {
17
16
  /**
18
17
  * @type {import('../repositories/integration-repository-interface').IntegrationRepositoryInterface}
19
18
  */
20
19
  this.integrationRepository = integrationRepository;
21
20
  this.integrationClasses = integrationClasses;
22
- this.moduleFactory = moduleFactory;
23
21
  }
24
22
 
25
23
  /**
@@ -53,32 +51,6 @@ class DeleteIntegrationForUser {
53
51
  );
54
52
  }
55
53
 
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
-
82
54
  const integrationInstance = new integrationClass({
83
55
  id: integrationRecord.id,
84
56
  userId: integrationRecord.userId,
@@ -87,10 +59,10 @@ class DeleteIntegrationForUser {
87
59
  status: integrationRecord.status,
88
60
  version: integrationRecord.version,
89
61
  messages: integrationRecord.messages,
90
- modules,
62
+ modules: [],
91
63
  });
92
64
 
93
- // Complete async initialization (load dynamic actions, register handlers)
65
+ // 6. Complete async initialization (load dynamic actions, register handlers)
94
66
  await integrationInstance.initialize();
95
67
  await integrationInstance.send('ON_DELETE');
96
68
 
@@ -64,20 +64,19 @@ class GetIntegrationsForUser {
64
64
  modules.push(moduleInstance);
65
65
  }
66
66
 
67
- const integrationData = {
67
+ const integrationInstance = new integrationClass({
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 || { errors: [], warnings: [] },
74
+ messages: integrationRecord.messages,
75
75
  modules,
76
- options: integrationClass.getOptionDetails(),
77
- };
76
+ });
78
77
 
79
78
  integrations.push(
80
- mapIntegrationClassToIntegrationDTO(integrationData)
79
+ mapIntegrationClassToIntegrationDTO(integrationInstance)
81
80
  );
82
81
  }
83
82
 
@@ -1,7 +1,6 @@
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.
5
4
  */
6
5
  function mapIntegrationClassToIntegrationDTO(integration) {
7
6
  if (!integration) return null;
@@ -15,7 +14,7 @@ function mapIntegrationClassToIntegrationDTO(integration) {
15
14
  version: integration.version,
16
15
  messages: integration.messages,
17
16
  userActions: integration.userActions,
18
- options: integration.options || (typeof integration.getOptionDetails === 'function' ? integration.getOptionDetails() : null),
17
+ options: integration.getOptionDetails(),
19
18
  };
20
19
  }
21
20
 
package/modules/index.js CHANGED
@@ -1,4 +1,3 @@
1
- const { Entity } = require('./entity');
2
1
  const { ApiKeyRequester } = require('./requester/api-key');
3
2
  const { BasicAuthRequester } = require('./requester/basic');
4
3
  const { OAuth2Requester } = require('./requester/oauth-2');
@@ -7,7 +6,6 @@ const { ModuleConstants } = require('./ModuleConstants');
7
6
  const { ModuleFactory } = require('./module-factory');
8
7
 
9
8
  module.exports = {
10
- Entity,
11
9
  ApiKeyRequester,
12
10
  BasicAuthRequester,
13
11
  OAuth2Requester,
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.496.a94ee46.0",
4
+ "version": "2.0.0--canary.490.feacde9.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.496.a94ee46.0",
42
- "@friggframework/prettier-config": "2.0.0--canary.496.a94ee46.0",
43
- "@friggframework/test": "2.0.0--canary.496.a94ee46.0",
41
+ "@friggframework/eslint-config": "2.0.0--canary.490.feacde9.0",
42
+ "@friggframework/prettier-config": "2.0.0--canary.490.feacde9.0",
43
+ "@friggframework/test": "2.0.0--canary.490.feacde9.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": "a94ee46a47e2d717520fb54637da299ca612168d"
83
+ "gitHead": "feacde9231638532344b5d000724b994a53f3a65"
84
84
  }
@@ -1,54 +0,0 @@
1
- const mongoose = require("mongoose");
2
-
3
- const schema = new mongoose.Schema({
4
- integration: {
5
- type: mongoose.Schema.Types.ObjectId,
6
- ref: "Integration",
7
- required: true,
8
- },
9
- name: { type: String, required: true },
10
- type: {
11
- type: String,
12
- enum: ["ONE_TO_MANY", "ONE_TO_ONE", "MANY_TO_ONE"],
13
- required: true,
14
- },
15
- primaryObject: { type: String, required: true },
16
- objects: [
17
- {
18
- entity: {
19
- type: mongoose.Schema.Types.ObjectId,
20
- ref: "Entity",
21
- required: true,
22
- },
23
- objectType: { type: String, required: true },
24
- objId: { type: String, required: true },
25
- metadata: { type: Object, required: false },
26
- },
27
- ],
28
- });
29
-
30
- schema.statics({
31
- addAssociation: async function (id, object) {
32
- return this.update({ _id: id }, { $push: { objects: object } });
33
- },
34
- findAssociation: async function (name, dataIdentifierHash) {
35
- const syncList = await this.list({
36
- name: name,
37
- "dataIdentifiers.hash": dataIdentifierHash,
38
- });
39
-
40
- if (syncList.length === 1) {
41
- return syncList[0];
42
- } else if (syncList.length === 0) {
43
- return null;
44
- } else {
45
- throw new Error(
46
- `there are multiple sync objects with the name ${name}, for entities [${entities}]`
47
- );
48
- }
49
- },
50
- });
51
-
52
- const Association =
53
- mongoose.models.Association || mongoose.model("Association", schema);
54
- module.exports = { Association };
@@ -1,7 +0,0 @@
1
- const { mongoose } = require('../mongoose');
2
-
3
- const schema = new mongoose.Schema({}, {timestamps: true})
4
-
5
- const UserModel = mongoose.models.User || mongoose.model('User',schema)
6
-
7
- module.exports = { UserModel: UserModel };
@@ -1,55 +0,0 @@
1
- const { mongoose } = require('../mongoose');
2
- const {
3
- ApiGatewayManagementApiClient,
4
- PostToConnectionCommand,
5
- } = require('@aws-sdk/client-apigatewaymanagementapi');
6
-
7
- const schema = new mongoose.Schema({
8
- connectionId: { type: mongoose.Schema.Types.String },
9
- });
10
-
11
- // Add a static method to get active connections
12
- schema.statics.getActiveConnections = async function () {
13
- try {
14
- // Return empty array if websockets are not configured
15
- if (!process.env.WEBSOCKET_API_ENDPOINT) {
16
- return [];
17
- }
18
-
19
- const connections = await this.find({}, 'connectionId');
20
- return connections.map((conn) => ({
21
- connectionId: conn.connectionId,
22
- send: async (data) => {
23
- const apigwManagementApi = new ApiGatewayManagementApiClient({
24
- endpoint: process.env.WEBSOCKET_API_ENDPOINT,
25
- });
26
-
27
- try {
28
- const command = new PostToConnectionCommand({
29
- ConnectionId: conn.connectionId,
30
- Data: JSON.stringify(data),
31
- });
32
- await apigwManagementApi.send(command);
33
- } catch (error) {
34
- if (error.statusCode === 410 || error.$metadata?.httpStatusCode === 410) {
35
- console.log(`Stale connection ${conn.connectionId}`);
36
- await this.deleteOne({
37
- connectionId: conn.connectionId,
38
- });
39
- } else {
40
- throw error;
41
- }
42
- }
43
- },
44
- }));
45
- } catch (error) {
46
- console.error('Error getting active connections:', error);
47
- throw error;
48
- }
49
- };
50
-
51
- const WebsocketConnection =
52
- mongoose.models.WebsocketConnection ||
53
- mongoose.model('WebsocketConnection', schema);
54
-
55
- module.exports = { WebsocketConnection };
@@ -1,108 +0,0 @@
1
- const { prisma } = require('../prisma');
2
- const { mongoose } = require('../mongoose');
3
- const {
4
- HealthCheckRepositoryInterface,
5
- } = require('./health-check-repository-interface');
6
-
7
- /**
8
- * Repository for Health Check database operations.
9
- * Provides atomic database operations for health testing.
10
- *
11
- * Follows DDD/Hexagonal Architecture:
12
- * - Infrastructure Layer (this repository)
13
- * - Pure database operations only, no business logic
14
- * - Used by Application Layer (Use Cases)
15
- *
16
- * Works identically for both MongoDB and PostgreSQL:
17
- * - Uses Prisma for database operations
18
- * - Encryption happens transparently via Prisma extension
19
- * - Both MongoDB and PostgreSQL use same Prisma API
20
- *
21
- * Migration from Mongoose to Prisma:
22
- * - Replaced Mongoose models with Prisma client
23
- * - Uses Credential model for encryption testing
24
- * - Maintains same method signatures for compatibility
25
- */
26
- class HealthCheckRepository extends HealthCheckRepositoryInterface {
27
- constructor() {
28
- super();
29
- }
30
-
31
- /**
32
- * Get database connection state
33
- * @returns {Object} Object with readyState, stateName, and isConnected
34
- */
35
- getDatabaseConnectionState() {
36
- const stateMap = {
37
- 0: 'disconnected',
38
- 1: 'connected',
39
- 2: 'connecting',
40
- 3: 'disconnecting',
41
- };
42
- const readyState = mongoose.connection.readyState;
43
-
44
- return {
45
- readyState,
46
- stateName: stateMap[readyState],
47
- isConnected: readyState === 1,
48
- };
49
- }
50
-
51
- /**
52
- * Ping the database to verify connectivity
53
- * @param {number} maxTimeMS - Maximum time to wait for ping response
54
- * @returns {Promise<number>} Response time in milliseconds
55
- * @throws {Error} If database is not connected or ping fails
56
- */
57
- async pingDatabase(maxTimeMS = 2000) {
58
- const pingStart = Date.now();
59
- await mongoose.connection.db.admin().ping({ maxTimeMS });
60
- return Date.now() - pingStart;
61
- }
62
-
63
- /**
64
- * Create a test credential for encryption testing
65
- * @param {Object} credentialData - Credential data to create
66
- * @returns {Promise<Object>} Created credential
67
- */
68
- async createCredential(credentialData) {
69
- return await prisma.credential.create({
70
- data: credentialData,
71
- });
72
- }
73
-
74
- /**
75
- * Find a credential by ID
76
- * @param {string} id - Credential ID
77
- * @returns {Promise<Object|null>} Found credential or null
78
- */
79
- async findCredentialById(id) {
80
- return await prisma.credential.findUnique({
81
- where: { id },
82
- });
83
- }
84
-
85
- /**
86
- * Get raw credential from database bypassing Prisma encryption extension
87
- * @param {string} id - Credential ID
88
- * @returns {Promise<Object|null>} Raw credential from database
89
- */
90
- async getRawCredentialById(id) {
91
- return await mongoose.connection.db
92
- .collection('credentials')
93
- .findOne({ _id: id });
94
- }
95
-
96
- /**
97
- * Delete a credential by ID
98
- * @param {string} id - Credential ID
99
- * @returns {Promise<void>}
100
- */
101
- async deleteCredential(id) {
102
- await prisma.credential.delete({
103
- where: { id },
104
- });
105
- }
106
- }
107
-
108
- module.exports = { HealthCheckRepository };
package/modules/entity.js DELETED
@@ -1,46 +0,0 @@
1
- const { mongoose } = require('../database/mongoose');
2
- const schema = new mongoose.Schema(
3
- {
4
- credential: {
5
- type: mongoose.Schema.Types.ObjectId,
6
- ref: 'Credential',
7
- required: false,
8
- },
9
- user: {
10
- type: mongoose.Schema.Types.ObjectId,
11
- ref: 'User',
12
- required: false,
13
- },
14
- name: { type: String },
15
- moduleName: { type: String },
16
- externalId: { type: String },
17
- },
18
- { timestamps: true }
19
- );
20
-
21
- schema.static({
22
- findByUserId: async function (userId) {
23
- const entities = await this.find({ user: userId });
24
- if (entities.length === 0) {
25
- return null;
26
- } else if (entities.length === 1) {
27
- return entities[0];
28
- } else {
29
- throw new Error('multiple entities with same userId');
30
- }
31
- },
32
- findAllByUserId(userId) {
33
- return this.find({ user: userId });
34
- },
35
- upsert: async function (filter, obj) {
36
- return this.findOneAndUpdate(filter, obj, {
37
- new: true,
38
- upsert: true,
39
- setDefaultsOnInsert: true,
40
- });
41
- },
42
- });
43
-
44
- const Entity = mongoose.models.Entity || mongoose.model('Entity', schema);
45
-
46
- module.exports = { Entity };
package/syncs/model.js DELETED
@@ -1,62 +0,0 @@
1
- const mongoose = require("mongoose");
2
-
3
- const schema = new mongoose.Schema({
4
- entities: [
5
- { type: mongoose.Schema.Types.ObjectId, ref: "Entity", required: true },
6
- ],
7
- hash: { type: String, required: true },
8
- name: { type: String, required: true },
9
- dataIdentifiers: [
10
- {
11
- entity: {
12
- type: mongoose.Schema.Types.ObjectId,
13
- ref: "Entity",
14
- required: true,
15
- },
16
- id: { type: Object, required: true },
17
- hash: { type: String, required: true },
18
- },
19
- ],
20
- });
21
-
22
- schema.statics({
23
- getSyncObject: async function (name, dataIdentifier, entity) {
24
- // const syncList = await this.list({name:name,entities: {"$in": entities}, "entityIds.idHash":entityIdHash });
25
- const syncList = await this.find({
26
- name: name,
27
- dataIdentifiers: { $elemMatch: { id: dataIdentifier, entity } },
28
- });
29
-
30
- if (syncList.length === 1) {
31
- return syncList[0];
32
- } else if (syncList.length === 0) {
33
- return null;
34
- } else {
35
- throw new Error(
36
- `There are multiple sync objects with the name ${name}, for entities [${syncList[0].entities}] [${syncList[1].entities}]`
37
- );
38
- }
39
- },
40
-
41
- addDataIdentifier: async function (id, dataIdentifier) {
42
- return await this.update(
43
- { _id: id },
44
- {},
45
- { dataIdentifiers: dataIdentifier }
46
- );
47
- },
48
-
49
- getEntityObjIdForEntityIdFromObject: function (syncObj, entityId) {
50
- for (let dataIdentifier of syncObj.dataIdentifiers) {
51
- if (dataIdentifier.entity.toString() === entityId) {
52
- return dataIdentifier.id;
53
- }
54
- }
55
- throw new Error(
56
- `Sync object does not have DataIdentifier for entityId: ${entityId}`
57
- );
58
- },
59
- });
60
-
61
- const Sync = mongoose.models.Sync || mongoose.model("Sync", schema);
62
- module.exports = { Sync };