@friggframework/core 2.0.0--canary.397.e634da9.0 → 2.0.0--canary.398.ad248a6.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/README.md +50 -931
- package/core/create-handler.js +0 -1
- package/database/models/WebsocketConnection.js +5 -0
- package/handlers/app-handler-helpers.js +3 -0
- package/handlers/backend-utils.js +44 -42
- package/handlers/routers/auth.js +14 -3
- package/handlers/routers/integration-defined-routers.js +5 -8
- package/handlers/routers/middleware/loadUser.js +15 -0
- package/handlers/routers/middleware/requireLoggedInUser.js +12 -0
- package/handlers/routers/user.js +5 -25
- package/handlers/workers/integration-defined-workers.js +3 -6
- package/index.js +16 -1
- package/integrations/create-frigg-backend.js +31 -0
- package/integrations/index.js +5 -0
- package/integrations/integration-base.js +46 -142
- package/integrations/integration-factory.js +251 -0
- package/integrations/integration-router.js +178 -301
- package/integrations/integration-user.js +144 -0
- package/integrations/options.js +1 -1
- package/integrations/test/integration-base.test.js +144 -0
- package/module-plugin/auther.js +393 -0
- package/module-plugin/entity-manager.js +70 -0
- package/{modules → module-plugin}/index.js +8 -0
- package/module-plugin/manager.js +169 -0
- package/module-plugin/module-factory.js +61 -0
- package/{modules → module-plugin}/test/mock-api/api.js +3 -8
- package/{modules → module-plugin}/test/mock-api/definition.js +8 -12
- package/package.json +5 -5
- package/syncs/sync.js +1 -0
- package/types/integrations/index.d.ts +6 -2
- package/types/module-plugin/index.d.ts +56 -4
- package/types/syncs/index.d.ts +2 -0
- package/credential/credential-repository.js +0 -42
- package/credential/use-cases/get-credential-for-user.js +0 -21
- package/credential/use-cases/update-authentication-status.js +0 -15
- package/handlers/app-definition-loader.js +0 -38
- package/integrations/integration-repository.js +0 -80
- package/integrations/integration.js +0 -246
- package/integrations/tests/doubles/dummy-integration-class.js +0 -90
- package/integrations/tests/doubles/test-integration-repository.js +0 -89
- package/integrations/tests/use-cases/create-integration.test.js +0 -124
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -143
- package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -143
- package/integrations/tests/use-cases/get-integration-instance.test.js +0 -169
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -169
- package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
- package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
- package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
- package/integrations/tests/use-cases/update-integration.test.js +0 -134
- package/integrations/use-cases/create-integration.js +0 -71
- package/integrations/use-cases/delete-integration-for-user.js +0 -72
- package/integrations/use-cases/get-integration-for-user.js +0 -78
- package/integrations/use-cases/get-integration-instance-by-definition.js +0 -67
- package/integrations/use-cases/get-integration-instance.js +0 -82
- package/integrations/use-cases/get-integrations-for-user.js +0 -76
- package/integrations/use-cases/get-possible-integrations.js +0 -27
- package/integrations/use-cases/index.js +0 -11
- package/integrations/use-cases/update-integration-messages.js +0 -31
- package/integrations/use-cases/update-integration-status.js +0 -28
- package/integrations/use-cases/update-integration.js +0 -91
- package/integrations/utils/map-integration-dto.js +0 -36
- package/modules/module-factory.js +0 -54
- package/modules/module-repository.js +0 -107
- package/modules/module.js +0 -221
- package/modules/tests/doubles/test-module-factory.js +0 -16
- package/modules/tests/doubles/test-module-repository.js +0 -19
- package/modules/use-cases/get-entities-for-user.js +0 -32
- package/modules/use-cases/get-entity-options-by-id.js +0 -58
- package/modules/use-cases/get-entity-options-by-type.js +0 -34
- package/modules/use-cases/get-module-instance-from-type.js +0 -31
- package/modules/use-cases/get-module.js +0 -56
- package/modules/use-cases/process-authorization-callback.js +0 -114
- package/modules/use-cases/refresh-entity-options.js +0 -58
- package/modules/use-cases/test-module-auth.js +0 -54
- package/modules/utils/map-module-dto.js +0 -18
- package/user/tests/doubles/test-user-repository.js +0 -72
- package/user/tests/use-cases/create-individual-user.test.js +0 -24
- package/user/tests/use-cases/create-organization-user.test.js +0 -28
- package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
- package/user/tests/use-cases/login-user.test.js +0 -140
- package/user/use-cases/create-individual-user.js +0 -61
- package/user/use-cases/create-organization-user.js +0 -47
- package/user/use-cases/create-token-for-user-id.js +0 -30
- package/user/use-cases/get-user-from-bearer-token.js +0 -77
- package/user/use-cases/login-user.js +0 -122
- package/user/user-repository.js +0 -62
- package/user/user.js +0 -77
- /package/{modules → module-plugin}/ModuleConstants.js +0 -0
- /package/{modules → module-plugin}/credential.js +0 -0
- /package/{modules → module-plugin}/entity.js +0 -0
- /package/{modules → module-plugin}/requester/api-key.js +0 -0
- /package/{modules → module-plugin}/requester/basic.js +0 -0
- /package/{modules → module-plugin}/requester/oauth-2.js +0 -0
- /package/{modules → module-plugin}/requester/requester.js +0 -0
- /package/{modules → module-plugin}/requester/requester.test.js +0 -0
- /package/{modules → module-plugin}/test/auther.test.js +0 -0
- /package/{modules → module-plugin}/test/mock-api/mocks/hubspot.js +0 -0
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const Boom = require('@hapi/boom');
|
|
2
|
-
// Removed Integration wrapper - using IntegrationBase directly
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use case for deleting an integration for a specific user.
|
|
6
|
-
* @class DeleteIntegrationForUser
|
|
7
|
-
*/
|
|
8
|
-
class DeleteIntegrationForUser {
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new DeleteIntegrationForUser instance.
|
|
11
|
-
* @param {Object} params - Configuration parameters.
|
|
12
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
13
|
-
* @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes.
|
|
14
|
-
*/
|
|
15
|
-
constructor({ integrationRepository, integrationClasses }) {
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @type {import('../integration-repository').IntegrationRepository}
|
|
19
|
-
*/
|
|
20
|
-
this.integrationRepository = integrationRepository;
|
|
21
|
-
this.integrationClasses = integrationClasses;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Executes the deletion of an integration for a user.
|
|
26
|
-
* @async
|
|
27
|
-
* @param {string} integrationId - ID of the integration to delete.
|
|
28
|
-
* @param {string} userId - ID of the user requesting the deletion.
|
|
29
|
-
* @returns {Promise<void>} Resolves when the integration is successfully deleted.
|
|
30
|
-
* @throws {Boom.notFound} When integration with the specified ID does not exist.
|
|
31
|
-
* @throws {Error} When the integration doesn't belong to the specified user.
|
|
32
|
-
*/
|
|
33
|
-
async execute(integrationId, userId) {
|
|
34
|
-
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
35
|
-
|
|
36
|
-
if (!integrationRecord) {
|
|
37
|
-
throw Boom.notFound(
|
|
38
|
-
`Integration with id of ${integrationId} does not exist`
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const integrationClass = this.integrationClasses.find(
|
|
43
|
-
(integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (integrationRecord.userId !== userId) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
`Integration ${integrationId} does not belong to User ${userId}`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const integrationInstance = new integrationClass({
|
|
53
|
-
id: integrationRecord.id,
|
|
54
|
-
userId: integrationRecord.userId,
|
|
55
|
-
entities: integrationRecord.entitiesIds,
|
|
56
|
-
config: integrationRecord.config,
|
|
57
|
-
status: integrationRecord.status,
|
|
58
|
-
version: integrationRecord.version,
|
|
59
|
-
messages: integrationRecord.messages,
|
|
60
|
-
modules: [],
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// 6. Complete async initialization (load dynamic actions, register handlers)
|
|
64
|
-
await integrationInstance.initialize();
|
|
65
|
-
await integrationInstance.send('ON_DELETE');
|
|
66
|
-
|
|
67
|
-
await this.integrationRepository.deleteIntegrationById(integrationId);
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = { DeleteIntegrationForUser };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// Removed Integration wrapper - using IntegrationBase directly
|
|
2
|
-
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
|
-
const Boom = require('@hapi/boom');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Use case for retrieving a single integration for a specific user.
|
|
7
|
-
* @class GetIntegrationForUser
|
|
8
|
-
*/
|
|
9
|
-
class GetIntegrationForUser {
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new GetIntegrationForUser instance.
|
|
12
|
-
* @param {Object} params - Configuration parameters.
|
|
13
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
14
|
-
* @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes.
|
|
15
|
-
* @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management.
|
|
16
|
-
* @param {import('../../modules/module-repository').ModuleRepository} params.moduleRepository - Repository for module and entity data operations.
|
|
17
|
-
*/
|
|
18
|
-
constructor({ integrationRepository, integrationClasses, moduleFactory, moduleRepository }) {
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @type {import('../integration-repository').IntegrationRepository}
|
|
22
|
-
*/
|
|
23
|
-
this.integrationRepository = integrationRepository;
|
|
24
|
-
this.integrationClasses = integrationClasses;
|
|
25
|
-
this.moduleFactory = moduleFactory;
|
|
26
|
-
this.moduleRepository = moduleRepository;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Executes the retrieval of a single integration for a user.
|
|
31
|
-
* @async
|
|
32
|
-
* @param {string} integrationId - ID of the integration to retrieve.
|
|
33
|
-
* @param {string} userId - ID of the user requesting the integration.
|
|
34
|
-
* @returns {Promise<Object>} The integration DTO for the specified user.
|
|
35
|
-
* @throws {Boom.notFound} When integration with the specified ID does not exist.
|
|
36
|
-
* @throws {Boom.forbidden} When user does not have access to the integration.
|
|
37
|
-
*/
|
|
38
|
-
async execute(integrationId, userId) {
|
|
39
|
-
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
40
|
-
const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
|
|
41
|
-
|
|
42
|
-
if (!integrationRecord) {
|
|
43
|
-
throw Boom.notFound(`Integration with id of ${integrationId} does not exist`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (integrationRecord.userId.toString() !== userId.toString()) {
|
|
47
|
-
throw Boom.forbidden('User does not have access to this integration');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const integrationClass = this.integrationClasses.find(
|
|
51
|
-
(integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const modules = [];
|
|
55
|
-
for (const entity of entities) {
|
|
56
|
-
const moduleInstance = await this.moduleFactory.getModuleInstance(
|
|
57
|
-
entity._id,
|
|
58
|
-
integrationRecord.userId
|
|
59
|
-
);
|
|
60
|
-
modules.push(moduleInstance);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const integrationInstance = new integrationClass({
|
|
64
|
-
id: integrationRecord._id,
|
|
65
|
-
userId: integrationRecord.userId,
|
|
66
|
-
entities: entities,
|
|
67
|
-
config: integrationRecord.config,
|
|
68
|
-
status: integrationRecord.status,
|
|
69
|
-
version: integrationRecord.version,
|
|
70
|
-
messages: integrationRecord.messages,
|
|
71
|
-
modules
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return mapIntegrationClassToIntegrationDTO(integrationInstance);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
module.exports = { GetIntegrationForUser };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// Removed Integration wrapper - using IntegrationBase directly
|
|
2
|
-
const Boom = require('@hapi/boom');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use case for retrieving a single integration by definition.
|
|
6
|
-
* @class GetIntegrationByDefinition
|
|
7
|
-
*/
|
|
8
|
-
class GetIntegrationInstanceByDefinition {
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new GetIntegrationByDefinition instance.
|
|
11
|
-
* @param {Object} params - Configuration parameters.
|
|
12
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
13
|
-
* @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management.
|
|
14
|
-
* @param {import('../../modules/module-repository').ModuleRepository} params.moduleRepository - Repository for module and entity data operations.
|
|
15
|
-
*/
|
|
16
|
-
constructor({ integrationRepository, moduleFactory, moduleRepository }) {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @type {import('../integration-repository').IntegrationRepository}
|
|
20
|
-
*/
|
|
21
|
-
this.integrationRepository = integrationRepository;
|
|
22
|
-
this.moduleFactory = moduleFactory;
|
|
23
|
-
this.moduleRepository = moduleRepository;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Executes the retrieval of a single integration by definition.
|
|
28
|
-
* @async
|
|
29
|
-
* @returns {Promise<Object>} The integration DTO for the specified definition.
|
|
30
|
-
* @throws {Boom.notFound} When integration with the specified definition does not exist.
|
|
31
|
-
*/
|
|
32
|
-
async execute(integrationClass) {
|
|
33
|
-
const integrationRecord = await this.integrationRepository.findIntegrationByName(integrationClass.Definition.name);
|
|
34
|
-
|
|
35
|
-
if (!integrationRecord) {
|
|
36
|
-
throw Boom.notFound(`Integration with name of ${integrationClass.Definition.name} does not exist`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
|
|
40
|
-
|
|
41
|
-
const modules = [];
|
|
42
|
-
for (const entity of entities) {
|
|
43
|
-
const moduleInstance = await this.moduleFactory.getModuleInstance(
|
|
44
|
-
entity.id,
|
|
45
|
-
integrationRecord.userId
|
|
46
|
-
);
|
|
47
|
-
modules.push(moduleInstance);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const integrationInstance = new integrationClass({
|
|
51
|
-
id: integrationRecord.id,
|
|
52
|
-
userId: integrationRecord.userId,
|
|
53
|
-
entities: entities,
|
|
54
|
-
config: integrationRecord.config,
|
|
55
|
-
status: integrationRecord.status,
|
|
56
|
-
version: integrationRecord.version,
|
|
57
|
-
messages: integrationRecord.messages,
|
|
58
|
-
modules
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
await integrationInstance.initialize();
|
|
62
|
-
|
|
63
|
-
return integrationInstance
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = { GetIntegrationInstanceByDefinition };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Removed Integration wrapper - using IntegrationBase directly
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Use case for retrieving a single integration instance by ID and user.
|
|
5
|
-
* @class GetIntegrationInstance
|
|
6
|
-
*/
|
|
7
|
-
class GetIntegrationInstance {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new GetIntegrationInstance instance.
|
|
11
|
-
* @param {Object} params - Configuration parameters.
|
|
12
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data access
|
|
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
|
-
*/
|
|
16
|
-
constructor({
|
|
17
|
-
integrationRepository,
|
|
18
|
-
integrationClasses,
|
|
19
|
-
moduleFactory,
|
|
20
|
-
}) {
|
|
21
|
-
this.integrationRepository = integrationRepository;
|
|
22
|
-
this.integrationClasses = integrationClasses;
|
|
23
|
-
this.moduleFactory = moduleFactory;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Executes the retrieval of a single integration instance.
|
|
28
|
-
* @async
|
|
29
|
-
* @param {string} integrationId - ID of the integration to retrieve.
|
|
30
|
-
* @param {string} userId - ID of the user requesting the integration.
|
|
31
|
-
* @returns {Promise<Integration>} The fully initialized integration instance.
|
|
32
|
-
* @throws {Error} When integration is not found, doesn't belong to user, or integration class is not found.
|
|
33
|
-
*/
|
|
34
|
-
async execute(integrationId, userId) {
|
|
35
|
-
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
36
|
-
|
|
37
|
-
if (!integrationRecord) {
|
|
38
|
-
throw new Error(`No integration found by the ID of ${integrationId}`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const integrationClass = this.integrationClasses.find(
|
|
42
|
-
(integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (!integrationClass) {
|
|
46
|
-
throw new Error(`No integration class found for type: ${integrationRecord.config.type}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (integrationRecord.userId !== userId) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Integration ${integrationId} does not belong to User ${userId}`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const modules = [];
|
|
57
|
-
for (const entityId of integrationRecord.entitiesIds) {
|
|
58
|
-
const moduleInstance = await this.moduleFactory.getModuleInstance(
|
|
59
|
-
entityId,
|
|
60
|
-
integrationRecord.userId
|
|
61
|
-
);
|
|
62
|
-
modules.push(moduleInstance);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const integrationInstance = new integrationClass({
|
|
66
|
-
id: integrationRecord.id,
|
|
67
|
-
userId: integrationRecord.userId,
|
|
68
|
-
entities: integrationRecord.entitiesIds,
|
|
69
|
-
config: integrationRecord.config,
|
|
70
|
-
status: integrationRecord.status,
|
|
71
|
-
version: integrationRecord.version,
|
|
72
|
-
messages: integrationRecord.messages,
|
|
73
|
-
modules
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
await integrationInstance.initialize();
|
|
77
|
-
|
|
78
|
-
return integrationInstance;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
module.exports = { GetIntegrationInstance };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// Removed Integration wrapper - using IntegrationBase directly
|
|
2
|
-
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use case for retrieving all integrations for a specific user.
|
|
6
|
-
* @class GetIntegrationsForUser
|
|
7
|
-
*/
|
|
8
|
-
class GetIntegrationsForUser {
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new GetIntegrationsForUser instance.
|
|
11
|
-
* @param {Object} params - Configuration parameters.
|
|
12
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
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
|
-
* @param {import('../../modules/module-repository').ModuleRepository} params.moduleRepository - Repository for module and entity data operations.
|
|
16
|
-
*/
|
|
17
|
-
constructor({ integrationRepository, integrationClasses, moduleFactory, moduleRepository }) {
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @type {import('../integration-repository').IntegrationRepository}
|
|
21
|
-
*/
|
|
22
|
-
this.integrationRepository = integrationRepository;
|
|
23
|
-
this.integrationClasses = integrationClasses;
|
|
24
|
-
this.moduleFactory = moduleFactory;
|
|
25
|
-
this.moduleRepository = moduleRepository;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Executes the retrieval of all integrations for a user.
|
|
30
|
-
* @async
|
|
31
|
-
* @param {string} userId - ID of the user whose integrations to retrieve.
|
|
32
|
-
* @returns {Promise<Object[]>} Array of integration DTOs for the specified user.
|
|
33
|
-
*/
|
|
34
|
-
async execute(userId) {
|
|
35
|
-
const integrationRecords = await this.integrationRepository.findIntegrationsByUserId(userId);
|
|
36
|
-
|
|
37
|
-
const integrations = []
|
|
38
|
-
|
|
39
|
-
for (const integrationRecord of integrationRecords) {
|
|
40
|
-
const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
|
|
41
|
-
|
|
42
|
-
const integrationClass = this.integrationClasses.find(
|
|
43
|
-
(integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const modules = [];
|
|
47
|
-
for (const entity of entities) {
|
|
48
|
-
const moduleInstance = await this.moduleFactory.getModuleInstance(
|
|
49
|
-
entity.id,
|
|
50
|
-
integrationRecord.userId
|
|
51
|
-
);
|
|
52
|
-
modules.push(moduleInstance);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const integrationInstance = new integrationClass({
|
|
56
|
-
id: integrationRecord.id,
|
|
57
|
-
userId: integrationRecord.userId,
|
|
58
|
-
entities: entities,
|
|
59
|
-
config: integrationRecord.config,
|
|
60
|
-
status: integrationRecord.status,
|
|
61
|
-
version: integrationRecord.version,
|
|
62
|
-
messages: integrationRecord.messages,
|
|
63
|
-
modules
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
integrations.push(
|
|
67
|
-
mapIntegrationClassToIntegrationDTO(integrationInstance)
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return integrations;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
module.exports = { GetIntegrationsForUser };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Use case for retrieving all possible integration types that can be created.
|
|
3
|
-
* @class GetPossibleIntegrations
|
|
4
|
-
*/
|
|
5
|
-
class GetPossibleIntegrations {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new GetPossibleIntegrations instance.
|
|
8
|
-
* @param {Object} params - Configuration parameters.
|
|
9
|
-
* @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes.
|
|
10
|
-
*/
|
|
11
|
-
constructor({ integrationClasses }) {
|
|
12
|
-
this.integrationClasses = integrationClasses;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Executes the retrieval of all possible integration types.
|
|
17
|
-
* @async
|
|
18
|
-
* @returns {Promise<Object[]>} Array of integration option details for all available integration types.
|
|
19
|
-
*/
|
|
20
|
-
async execute() {
|
|
21
|
-
return this.integrationClasses.map((integrationClass) =>
|
|
22
|
-
integrationClass.getOptionDetails()
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = { GetPossibleIntegrations };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const { GetIntegrationsForUser } = require('./get-integrations-for-user');
|
|
2
|
-
const { DeleteIntegrationForUser } = require('./delete-integration-for-user');
|
|
3
|
-
const { CreateIntegration } = require('./create-integration');
|
|
4
|
-
const { GetIntegration } = require('./get-integration');
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
GetIntegrationsForUser,
|
|
8
|
-
DeleteIntegrationForUser,
|
|
9
|
-
CreateIntegration,
|
|
10
|
-
GetIntegration,
|
|
11
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Use case for updating messages associated with an integration.
|
|
3
|
-
* @class UpdateIntegrationMessages
|
|
4
|
-
*/
|
|
5
|
-
class UpdateIntegrationMessages {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new UpdateIntegrationMessages instance.
|
|
8
|
-
* @param {Object} params - Configuration parameters.
|
|
9
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
10
|
-
*/
|
|
11
|
-
constructor({ integrationRepository }) {
|
|
12
|
-
this.integrationRepository = integrationRepository;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Executes the integration messages update.
|
|
17
|
-
* @async
|
|
18
|
-
* @param {string} integrationId - ID of the integration to update.
|
|
19
|
-
* @param {string} messageType - Type of message: 'errors', 'warnings', 'info', or 'logs'.
|
|
20
|
-
* @param {string} messageTitle - Title of the message.
|
|
21
|
-
* @param {string} messageBody - Body content of the message.
|
|
22
|
-
* @param {string} messageTimestamp - Timestamp when the message was created.
|
|
23
|
-
* @returns {Promise<Object>} The updated integration record.
|
|
24
|
-
*/
|
|
25
|
-
async execute(integrationId, messageType, messageTitle, messageBody, messageTimestamp) {
|
|
26
|
-
const integration = await this.integrationRepository.updateIntegrationMessages(integrationId, messageType, messageTitle, messageBody, messageTimestamp);
|
|
27
|
-
return integration;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = { UpdateIntegrationMessages };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Use case for updating the status of an integration.
|
|
3
|
-
* @class UpdateIntegrationStatus
|
|
4
|
-
*/
|
|
5
|
-
class UpdateIntegrationStatus {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new UpdateIntegrationStatus instance.
|
|
8
|
-
* @param {Object} params - Configuration parameters.
|
|
9
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
10
|
-
*/
|
|
11
|
-
constructor({ integrationRepository }) {
|
|
12
|
-
this.integrationRepository = integrationRepository;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Executes the integration status update.
|
|
17
|
-
* @async
|
|
18
|
-
* @param {string} integrationId - ID of the integration to update.
|
|
19
|
-
* @param {string} status - New status for the integration (e.g., 'ENABLED', 'DISABLED', 'ERROR').
|
|
20
|
-
* @returns {Promise<Object>} The updated integration record.
|
|
21
|
-
*/
|
|
22
|
-
async execute(integrationId, status) {
|
|
23
|
-
const integration = await this.integrationRepository.updateIntegrationStatus(integrationId, status);
|
|
24
|
-
return integration;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = { UpdateIntegrationStatus };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// Removed Integration wrapper - using IntegrationBase directly
|
|
2
|
-
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Use case for updating a single integration by ID and user.
|
|
6
|
-
* @class UpdateIntegration
|
|
7
|
-
*/
|
|
8
|
-
class UpdateIntegration {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new UpdateIntegration instance.
|
|
12
|
-
* @param {Object} params - Configuration parameters.
|
|
13
|
-
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data access
|
|
14
|
-
* @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes
|
|
15
|
-
* @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management
|
|
16
|
-
*/
|
|
17
|
-
constructor({
|
|
18
|
-
integrationRepository,
|
|
19
|
-
integrationClasses,
|
|
20
|
-
moduleFactory,
|
|
21
|
-
}) {
|
|
22
|
-
this.integrationRepository = integrationRepository;
|
|
23
|
-
this.integrationClasses = integrationClasses;
|
|
24
|
-
this.moduleFactory = moduleFactory;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Executes the integration update process.
|
|
29
|
-
* @async
|
|
30
|
-
* @param {string} integrationId - ID of the integration to update.
|
|
31
|
-
* @param {string} userId - ID of the user requesting the update.
|
|
32
|
-
* @param {Object} config - New configuration object for the integration.
|
|
33
|
-
* @returns {Promise<Object>} The updated integration DTO.
|
|
34
|
-
* @throws {Error} When integration is not found, doesn't belong to user, or integration class is not found.
|
|
35
|
-
*/
|
|
36
|
-
async execute(integrationId, userId, config) {
|
|
37
|
-
// 1. Get integration record from repository
|
|
38
|
-
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
39
|
-
|
|
40
|
-
if (!integrationRecord) {
|
|
41
|
-
throw new Error(`No integration found by the ID of ${integrationId}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 2. Get the correct Integration class by type
|
|
45
|
-
const integrationClass = this.integrationClasses.find(
|
|
46
|
-
(integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
if (!integrationClass) {
|
|
50
|
-
throw new Error(`No integration class found for type: ${integrationRecord.config.type}`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (integrationRecord.userId !== userId) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Integration ${integrationId} does not belong to User ${userId}`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// 3. Load modules based on entity references
|
|
61
|
-
const modules = [];
|
|
62
|
-
for (const entityId of integrationRecord.entitiesIds) {
|
|
63
|
-
const moduleInstance = await this.moduleFactory.getModuleInstance(
|
|
64
|
-
entityId,
|
|
65
|
-
integrationRecord.userId
|
|
66
|
-
);
|
|
67
|
-
modules.push(moduleInstance);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 4. Create the Integration domain entity with modules and updated config
|
|
71
|
-
const integrationInstance = new integrationClass({
|
|
72
|
-
id: integrationRecord.id,
|
|
73
|
-
userId: integrationRecord.userId,
|
|
74
|
-
entities: integrationRecord.entitiesIds,
|
|
75
|
-
config: config,
|
|
76
|
-
status: integrationRecord.status,
|
|
77
|
-
version: integrationRecord.version,
|
|
78
|
-
messages: integrationRecord.messages,
|
|
79
|
-
modules
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// 6. Complete async initialization (load dynamic actions, register handlers)
|
|
84
|
-
await integrationInstance.initialize();
|
|
85
|
-
await integrationInstance.send('ON_UPDATE', { config });
|
|
86
|
-
|
|
87
|
-
return mapIntegrationClassToIntegrationDTO(integrationInstance);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = { UpdateIntegration };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {import('../integration').Integration} integration
|
|
3
|
-
* Convert an Integration domain instance to a plain DTO suitable for JSON responses.
|
|
4
|
-
*/
|
|
5
|
-
function mapIntegrationClassToIntegrationDTO(integration) {
|
|
6
|
-
if (!integration) return null;
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
id: integration.id,
|
|
10
|
-
userId: integration.userId,
|
|
11
|
-
entities: integration.entities,
|
|
12
|
-
config: integration.config,
|
|
13
|
-
status: integration.status,
|
|
14
|
-
version: integration.version,
|
|
15
|
-
messages: integration.messages,
|
|
16
|
-
userActions: integration.userActions,
|
|
17
|
-
options: integration.getOptionDetails(),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const getModulesDefinitionFromIntegrationClasses = (integrationClasses) => {
|
|
23
|
-
return [
|
|
24
|
-
...new Set(
|
|
25
|
-
integrationClasses
|
|
26
|
-
.map((integration) =>
|
|
27
|
-
Object.values(integration.Definition.modules).map(
|
|
28
|
-
(module) => module.definition
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
.flat()
|
|
32
|
-
),
|
|
33
|
-
];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
module.exports = { mapIntegrationClassToIntegrationDTO, getModulesDefinitionFromIntegrationClasses };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const { Module } = require('./module');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Acts as a factory for fully-hydrated domain Module instances.
|
|
5
|
-
* Provides methods to retrieve and construct Module objects with their associated
|
|
6
|
-
* entity and definition.
|
|
7
|
-
*/
|
|
8
|
-
class ModuleFactory {
|
|
9
|
-
/**
|
|
10
|
-
* @param {Object} params - Configuration parameters.
|
|
11
|
-
* @param {import('./module-repository').ModuleRepository} params.moduleRepository - Repository for module data operations.
|
|
12
|
-
* @param {Array<Object>} params.moduleDefinitions - Array of module definitions.
|
|
13
|
-
*/
|
|
14
|
-
constructor({ moduleRepository, moduleDefinitions }) {
|
|
15
|
-
this.moduleRepository = moduleRepository;
|
|
16
|
-
this.moduleDefinitions = moduleDefinitions;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async getModuleInstance(entityId, userId) {
|
|
20
|
-
const entity = await this.moduleRepository.findEntityById(
|
|
21
|
-
entityId,
|
|
22
|
-
userId
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (!entity) {
|
|
26
|
-
throw new Error(`Entity ${entityId} not found`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (entity.userId !== userId) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
`Entity ${entityId} does not belong to user ${userId}`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const moduleName = entity.moduleName;
|
|
36
|
-
const moduleDefinition = this.moduleDefinitions.find((def) => {
|
|
37
|
-
return moduleName === def.moduleName;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (!moduleDefinition) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Module definition not found for entity type: ${entityType}`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return new Module({
|
|
47
|
-
userId,
|
|
48
|
-
entity,
|
|
49
|
-
definition: moduleDefinition,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
module.exports = { ModuleFactory };
|