@friggframework/core 2.0.0--canary.397.878fefa.0 → 2.0.0--canary.397.84ecb0e.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/handlers/backend-utils.js +15 -3
- package/integrations/integration-repository.js +13 -0
- package/integrations/use-cases/get-integration-for-user.js +1 -0
- package/integrations/use-cases/get-integration-instance-by-definition.js +67 -0
- package/modules/use-cases/process-authorization-callback.js +1 -1
- package/package.json +5 -5
|
@@ -6,8 +6,17 @@ const { ModuleFactory } = require('../modules/module-factory');
|
|
|
6
6
|
const { GetIntegrationInstance } = require('../integrations/use-cases/get-integration-instance');
|
|
7
7
|
const { getModulesDefinitionFromIntegrationClasses } = require('../integrations/utils/map-integration-dto');
|
|
8
8
|
const { ModuleRepository } = require('../modules/module-repository');
|
|
9
|
+
const { GetIntegrationInstanceByDefinition } = require('../integrations/use-cases/get-integration-instance-by-definition');
|
|
9
10
|
|
|
10
11
|
const loadRouterFromObject = (IntegrationClass, routerObject) => {
|
|
12
|
+
|
|
13
|
+
const integrationRepository = new IntegrationRepository();
|
|
14
|
+
const moduleRepository = new ModuleRepository();
|
|
15
|
+
const moduleFactory = new ModuleFactory({
|
|
16
|
+
moduleRepository,
|
|
17
|
+
moduleDefinitions: getModulesDefinitionFromIntegrationClasses(integrationClasses),
|
|
18
|
+
});
|
|
19
|
+
|
|
11
20
|
const router = Router();
|
|
12
21
|
const { path, method, event } = routerObject;
|
|
13
22
|
console.log(
|
|
@@ -15,9 +24,12 @@ const loadRouterFromObject = (IntegrationClass, routerObject) => {
|
|
|
15
24
|
);
|
|
16
25
|
router[method.toLowerCase()](path, async (req, res, next) => {
|
|
17
26
|
try {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
const getIntegrationInstanceByDefinition = new GetIntegrationInstanceByDefinition({
|
|
28
|
+
integrationRepository,
|
|
29
|
+
moduleFactory,
|
|
30
|
+
moduleRepository,
|
|
31
|
+
});
|
|
32
|
+
const integration = await getIntegrationInstanceByDefinition.execute(IntegrationClass.Definition);
|
|
21
33
|
const result = await integration.send(event, { req, res, next });
|
|
22
34
|
res.json(result);
|
|
23
35
|
} catch (error) {
|
|
@@ -18,6 +18,19 @@ class IntegrationRepository {
|
|
|
18
18
|
return IntegrationModel.deleteOne({ _id: integrationId });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
async findIntegrationByName(name) {
|
|
22
|
+
const integrationRecord = await IntegrationModel.findOne({ 'config.type': name }, '', { lean: true }).populate('entities');
|
|
23
|
+
return {
|
|
24
|
+
id: integrationRecord._id,
|
|
25
|
+
entitiesIds: integrationRecord.entities.map(e => e._id),
|
|
26
|
+
userId: integrationRecord.user.toString(),
|
|
27
|
+
config: integrationRecord.config,
|
|
28
|
+
version: integrationRecord.version,
|
|
29
|
+
status: integrationRecord.status,
|
|
30
|
+
messages: integrationRecord.messages,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
async findIntegrationById(id) {
|
|
22
35
|
const integrationRecord = await IntegrationModel.findById(id, '', { lean: true }).populate('entities');
|
|
23
36
|
return {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { Integration } = require('../integration');
|
|
2
|
+
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
|
+
const Boom = require('@hapi/boom');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use case for retrieving a single integration by definition.
|
|
7
|
+
* @class GetIntegrationByDefinition
|
|
8
|
+
*/
|
|
9
|
+
class GetIntegrationInstanceByDefinition {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new GetIntegrationByDefinition instance.
|
|
12
|
+
* @param {Object} params - Configuration parameters.
|
|
13
|
+
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
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, moduleFactory, moduleRepository }) {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @type {import('../integration-repository').IntegrationRepository}
|
|
21
|
+
*/
|
|
22
|
+
this.integrationRepository = integrationRepository;
|
|
23
|
+
this.moduleFactory = moduleFactory;
|
|
24
|
+
this.moduleRepository = moduleRepository;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Executes the retrieval of a single integration by definition.
|
|
29
|
+
* @async
|
|
30
|
+
* @returns {Promise<Object>} The integration DTO for the specified definition.
|
|
31
|
+
* @throws {Boom.notFound} When integration with the specified definition does not exist.
|
|
32
|
+
*/
|
|
33
|
+
async execute(definition) {
|
|
34
|
+
const integrationRecord = await this.integrationRepository.findIntegrationByName(definition.name);
|
|
35
|
+
const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
|
|
36
|
+
|
|
37
|
+
if (!integrationRecord) {
|
|
38
|
+
throw Boom.notFound(`Integration with name of ${definition.name} does not exist`);
|
|
39
|
+
}
|
|
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 Integration({
|
|
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
|
+
entityReference: integrationRecord.entityReference,
|
|
59
|
+
integrationClass: integrationClass,
|
|
60
|
+
modules
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return integrationInstance
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = { GetIntegrationInstanceByDefinition };
|
|
@@ -16,7 +16,7 @@ class ProcessAuthorizationCallback {
|
|
|
16
16
|
|
|
17
17
|
async execute(userId, entityType, params, credentialId = null) {
|
|
18
18
|
const moduleDefinition = this.moduleDefinitions.find((def) => {
|
|
19
|
-
return entityType === def.
|
|
19
|
+
return entityType === def.moduleName;
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
if (!moduleDefinition) {
|
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.397.
|
|
4
|
+
"version": "2.0.0--canary.397.84ecb0e.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@hapi/boom": "^10.0.1",
|
|
7
7
|
"aws-sdk": "^2.1200.0",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"uuid": "^9.0.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@friggframework/eslint-config": "2.0.0--canary.397.
|
|
26
|
-
"@friggframework/prettier-config": "2.0.0--canary.397.
|
|
27
|
-
"@friggframework/test": "2.0.0--canary.397.
|
|
25
|
+
"@friggframework/eslint-config": "2.0.0--canary.397.84ecb0e.0",
|
|
26
|
+
"@friggframework/prettier-config": "2.0.0--canary.397.84ecb0e.0",
|
|
27
|
+
"@friggframework/test": "2.0.0--canary.397.84ecb0e.0",
|
|
28
28
|
"@types/lodash": "4.17.15",
|
|
29
29
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
30
30
|
"chai": "^4.3.6",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
},
|
|
54
54
|
"homepage": "https://github.com/friggframework/frigg#readme",
|
|
55
55
|
"description": "",
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "84ecb0ef85262bbb8c2c063dd595684d63599649"
|
|
57
57
|
}
|