@friggframework/core 2.0.0--canary.395.65f5f64.0 → 2.0.0--canary.398.24926ac.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 +181 -303
- 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}/entity.js +0 -1
- 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 -56
- 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/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 -218
- 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 -108
- 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}/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,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 };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const { Entity } = require('./entity');
|
|
2
|
-
|
|
3
|
-
class ModuleRepository {
|
|
4
|
-
async findEntityById(entityId) {
|
|
5
|
-
const entity = await Entity.findById(entityId, undefined, { lean: true }).populate('credential');
|
|
6
|
-
if (!entity) {
|
|
7
|
-
throw new Error(`Entity ${entityId} not found`);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
id: entity._id,
|
|
12
|
-
accountId: entity.accountId,
|
|
13
|
-
credential: entity.credential,
|
|
14
|
-
userId: entity.user.toString(),
|
|
15
|
-
name: entity.name,
|
|
16
|
-
externalId: entity.externalId,
|
|
17
|
-
type: entity.__t,
|
|
18
|
-
moduleName: entity.moduleName,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async findEntitiesByUserId(userId) {
|
|
23
|
-
const entitiesRecords = await Entity.find(
|
|
24
|
-
{ user: userId },
|
|
25
|
-
'',
|
|
26
|
-
{ lean: true }
|
|
27
|
-
).populate('credential');
|
|
28
|
-
|
|
29
|
-
return entitiesRecords.map(e => ({
|
|
30
|
-
id: e._id.toString(),
|
|
31
|
-
accountId: e.accountId,
|
|
32
|
-
credential: e.credential,
|
|
33
|
-
userId: e.user.toString(),
|
|
34
|
-
name: e.name,
|
|
35
|
-
externalId: e.externalId,
|
|
36
|
-
type: e.__t,
|
|
37
|
-
moduleName: e.moduleName,
|
|
38
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async findEntitiesByIds(entitiesIds) {
|
|
42
|
-
const entitiesRecords = await Entity.find(
|
|
43
|
-
{ _id: { $in: entitiesIds } },
|
|
44
|
-
'',
|
|
45
|
-
{ lean: true }
|
|
46
|
-
).populate('credential');
|
|
47
|
-
|
|
48
|
-
return entitiesRecords.map(e => ({
|
|
49
|
-
id: e._id.toString(),
|
|
50
|
-
accountId: e.accountId,
|
|
51
|
-
credential: e.credential,
|
|
52
|
-
userId: e.user.toString(),
|
|
53
|
-
name: e.name,
|
|
54
|
-
externalId: e.externalId,
|
|
55
|
-
type: e.__t,
|
|
56
|
-
moduleName: e.moduleName,
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Remove the credential reference from an Entity document without loading a full Mongoose instance.
|
|
62
|
-
* Useful when a credential has been revoked/deleted (e.g. via Module.deauthorize).
|
|
63
|
-
* @param {string} entityId
|
|
64
|
-
* @returns {Promise<import('mongoose').UpdateWriteOpResult>}
|
|
65
|
-
*/
|
|
66
|
-
async unsetCredential(entityId) {
|
|
67
|
-
const result = await Entity.updateOne({ _id: entityId }, { $unset: { credential: "" } });
|
|
68
|
-
return result.acknowledged;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async findEntity(filter) {
|
|
72
|
-
const entity = await Entity.findOne(filter, undefined, { lean: true }).populate('credential');
|
|
73
|
-
if (!entity) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
id: entity._id.toString(),
|
|
79
|
-
accountId: entity.accountId,
|
|
80
|
-
credential: entity.credential,
|
|
81
|
-
userId: entity.user.toString(),
|
|
82
|
-
name: entity.name,
|
|
83
|
-
externalId: entity.externalId,
|
|
84
|
-
type: entity.__t,
|
|
85
|
-
moduleName: entity.moduleName,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async createEntity(entityData) {
|
|
90
|
-
const entity = await Entity.create(entityData);
|
|
91
|
-
await entity.populate('credential');
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
id: entity._id.toString(),
|
|
95
|
-
accountId: entity.accountId,
|
|
96
|
-
credential: entity.credential,
|
|
97
|
-
userId: entity.user.toString(),
|
|
98
|
-
name: entity.name,
|
|
99
|
-
externalId: entity.externalId,
|
|
100
|
-
type: entity.__t,
|
|
101
|
-
moduleName: entity.moduleName,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
module.exports = { ModuleRepository };
|