@friggframework/core 2.0.0--canary.396.340648d.0 → 2.0.0--canary.396.2b7bd44.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/integrations/index.js +1 -2
- package/integrations/integration-router.js +12 -19
- package/integrations/use-cases/get-integration-for-user.js +28 -4
- package/integrations/use-cases/{get-integration-instance.js → get-integration.js} +2 -3
- package/integrations/use-cases/get-integrations-for-user.js +35 -2
- package/integrations/use-cases/index.js +2 -2
- package/module-plugin/use-cases/get-entities-for-user.js +2 -6
- package/package.json +5 -5
package/integrations/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const { IntegrationBase } = require('./integration-base');
|
|
|
2
2
|
const { IntegrationModel } = require('./integration-model');
|
|
3
3
|
const { Options } = require('./options');
|
|
4
4
|
const { IntegrationMapping } = require('./integration-mapping');
|
|
5
|
-
const { IntegrationFactory
|
|
5
|
+
const { IntegrationFactory } = require('./integration-factory');
|
|
6
6
|
const { createIntegrationRouter, checkRequiredParams } = require('./integration-router');
|
|
7
7
|
|
|
8
8
|
module.exports = {
|
|
@@ -11,7 +11,6 @@ module.exports = {
|
|
|
11
11
|
Options,
|
|
12
12
|
IntegrationMapping,
|
|
13
13
|
IntegrationFactory,
|
|
14
|
-
IntegrationHelper,
|
|
15
14
|
createIntegrationRouter,
|
|
16
15
|
checkRequiredParams,
|
|
17
16
|
};
|
|
@@ -5,7 +5,6 @@ const catchAsyncError = require('express-async-handler');
|
|
|
5
5
|
const { debug } = require('../logs');
|
|
6
6
|
const { IntegrationRepository } = require('./integration-repository');
|
|
7
7
|
const { DeleteIntegrationForUser } = require('./use-cases/delete-integration-for-user');
|
|
8
|
-
const { GetIntegrationForUser } = require('./use-cases/get-integration-for-user');
|
|
9
8
|
const { GetIntegrationsForUser } = require('./use-cases/get-integrations-for-user');
|
|
10
9
|
const { CredentialRepository } = require('../credential/credential-repository');
|
|
11
10
|
const { GetCredentialForUser } = require('../credential/use-cases/get-credential-for-user');
|
|
@@ -56,9 +55,7 @@ function createIntegrationRouter(params) {
|
|
|
56
55
|
const deleteIntegrationForUser = new DeleteIntegrationForUser({
|
|
57
56
|
integrationRepository,
|
|
58
57
|
});
|
|
59
|
-
|
|
60
|
-
integrationRepository,
|
|
61
|
-
});
|
|
58
|
+
|
|
62
59
|
const getIntegrationsForUser = new GetIntegrationsForUser({
|
|
63
60
|
integrationRepository,
|
|
64
61
|
});
|
|
@@ -81,7 +78,7 @@ function createIntegrationRouter(params) {
|
|
|
81
78
|
const getUserFromBearerToken = get(params, 'getUserFromBearerToken');
|
|
82
79
|
|
|
83
80
|
// todo: moduleFactory in factory is not used here anymore, remove it
|
|
84
|
-
setIntegrationRoutes(router, factory, getUserFromBearerToken, {
|
|
81
|
+
setIntegrationRoutes(router, factory, getUserFromBearerToken, integrations, {
|
|
85
82
|
createIntegration,
|
|
86
83
|
deleteIntegrationForUser,
|
|
87
84
|
getIntegrationsForUser,
|
|
@@ -123,7 +120,7 @@ function checkRequiredParams(params, requiredKeys) {
|
|
|
123
120
|
* @param {Object} factory.integrationFactory - Factory for creating and managing integrations
|
|
124
121
|
* @param {import('../user/use-cases/get-user-from-bearer-token').GetUserFromBearerToken} getUserFromBearerToken - Use case for retrieving a user from a bearer token
|
|
125
122
|
*/
|
|
126
|
-
function setIntegrationRoutes(router, factory, getUserFromBearerToken, useCases) {
|
|
123
|
+
function setIntegrationRoutes(router, factory, getUserFromBearerToken, integrationClasses, useCases) {
|
|
127
124
|
const { integrationFactory } = factory;
|
|
128
125
|
const {
|
|
129
126
|
createIntegration,
|
|
@@ -131,26 +128,22 @@ function setIntegrationRoutes(router, factory, getUserFromBearerToken, useCases)
|
|
|
131
128
|
getIntegrationsForUser,
|
|
132
129
|
getEntitiesForUserUseCase,
|
|
133
130
|
} = useCases;
|
|
134
|
-
|
|
135
131
|
router.route('/api/integrations').get(
|
|
136
132
|
catchAsyncError(async (req, res) => {
|
|
137
133
|
const user = await getUserFromBearerToken.execute(
|
|
138
134
|
req.headers.authorization
|
|
139
135
|
);
|
|
140
136
|
const userId = user.getId();
|
|
141
|
-
const results =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
integrationId: integrationRecord.id,
|
|
150
|
-
userId,
|
|
151
|
-
});
|
|
152
|
-
integrationRecord.userActions = integration.userActions;
|
|
137
|
+
const results = {
|
|
138
|
+
entities: {
|
|
139
|
+
options: integrationClasses.map((IntegrationClass) =>
|
|
140
|
+
IntegrationClass.getOptionDetails()
|
|
141
|
+
),
|
|
142
|
+
authorized: await getEntitiesForUserUseCase.execute(userId),
|
|
143
|
+
},
|
|
144
|
+
integrations: await getIntegrationsForUser.execute(userId),
|
|
153
145
|
}
|
|
146
|
+
|
|
154
147
|
res.json(results);
|
|
155
148
|
})
|
|
156
149
|
);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
class GetIntegrationForUser {
|
|
2
|
-
constructor({ integrationRepository }) {
|
|
2
|
+
constructor({ integrationRepository, integrationClasses, moduleService }) {
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @type {import('../integration-repository').IntegrationRepository}
|
|
6
6
|
*/
|
|
7
7
|
this.integrationRepository = integrationRepository;
|
|
8
|
+
this.integrationClasses = integrationClasses;
|
|
9
|
+
this.moduleService = moduleService;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -13,16 +15,38 @@ class GetIntegrationForUser {
|
|
|
13
15
|
* @returns {Promise<Integration>}
|
|
14
16
|
*/
|
|
15
17
|
async execute(integrationId, userId) {
|
|
16
|
-
const
|
|
18
|
+
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
17
19
|
|
|
18
|
-
if (!
|
|
20
|
+
if (!integrationRecord) {
|
|
19
21
|
throw Boom.notFound(`Integration with id of ${integrationId} does not exist`);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
if (
|
|
24
|
+
if (integrationRecord.user.toString() !== userId.toString()) {
|
|
23
25
|
throw Boom.forbidden('User does not have access to this integration');
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
const modules = {};
|
|
29
|
+
for (const [entityId, key] of Object.entries(integrationRecord.entityReference)) {
|
|
30
|
+
const moduleInstance = await this.moduleService.getModuleInstance(
|
|
31
|
+
entityId,
|
|
32
|
+
integrationRecord.user
|
|
33
|
+
);
|
|
34
|
+
modules[key] = moduleInstance;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const integration = new Integration({
|
|
38
|
+
id: integrationRecord.id,
|
|
39
|
+
userId: integrationRecord.user,
|
|
40
|
+
entities: integrationRecord.entities,
|
|
41
|
+
config: integrationRecord.config,
|
|
42
|
+
status: integrationRecord.status,
|
|
43
|
+
version: integrationRecord.version,
|
|
44
|
+
messages: integrationRecord.messages,
|
|
45
|
+
entityReference: integrationRecord.entityReference,
|
|
46
|
+
integrationClass: IntegrationClass,
|
|
47
|
+
modules
|
|
48
|
+
});
|
|
49
|
+
|
|
26
50
|
return integration;
|
|
27
51
|
}
|
|
28
52
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
const { Integration } = require('../integration');
|
|
2
|
-
const { ModuleService } = require('../../module-plugin/module-service');
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
// todo: remove this use case
|
|
6
|
-
class
|
|
5
|
+
class GetIntegration {
|
|
7
6
|
constructor({
|
|
8
7
|
integrationRepository,
|
|
9
8
|
integrationClasses,
|
|
@@ -74,4 +73,4 @@ class GetIntegrationInstance {
|
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
module.exports = {
|
|
76
|
+
module.exports = { GetIntegration };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
class GetIntegrationsForUser {
|
|
2
|
-
constructor({ integrationRepository }) {
|
|
2
|
+
constructor({ integrationRepository, integrationClasses, moduleService }) {
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @type {import('../integration-repository').IntegrationRepository}
|
|
6
6
|
*/
|
|
7
7
|
this.integrationRepository = integrationRepository;
|
|
8
|
+
this.integrationClasses = integrationClasses;
|
|
9
|
+
this.moduleService = moduleService;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -12,7 +14,38 @@ class GetIntegrationsForUser {
|
|
|
12
14
|
* @returns {Promise<Integration[]>}
|
|
13
15
|
*/
|
|
14
16
|
async execute(userId) {
|
|
15
|
-
|
|
17
|
+
const integrationRecords = this.integrationRepository.findIntegrationsByUserId(userId);
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const integrations = []
|
|
21
|
+
|
|
22
|
+
for (const integrationRecord of integrationRecords) {
|
|
23
|
+
|
|
24
|
+
const modules = {};
|
|
25
|
+
for (const [entityId, key] of Object.entries(integrationRecord.entityReference)) {
|
|
26
|
+
const moduleInstance = await this.moduleService.getModuleInstance(
|
|
27
|
+
entityId,
|
|
28
|
+
integrationRecord.user
|
|
29
|
+
);
|
|
30
|
+
modules[key] = moduleInstance;
|
|
31
|
+
}
|
|
32
|
+
integrations.push(new Integration({
|
|
33
|
+
id: integrationRecord.id,
|
|
34
|
+
userId: integrationRecord.user,
|
|
35
|
+
entities: integrationRecord.entities,
|
|
36
|
+
config: integrationRecord.config,
|
|
37
|
+
status: integrationRecord.status,
|
|
38
|
+
version: integrationRecord.version,
|
|
39
|
+
messages: integrationRecord.messages,
|
|
40
|
+
entityReference: integrationRecord.entityReference,
|
|
41
|
+
integrationClass: IntegrationClass,
|
|
42
|
+
modules
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
return integrations;
|
|
16
49
|
}
|
|
17
50
|
}
|
|
18
51
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const { GetIntegrationsForUser } = require('./get-integrations-for-user');
|
|
2
2
|
const { DeleteIntegrationForUser } = require('./delete-integration-for-user');
|
|
3
3
|
const { CreateIntegration } = require('./create-integration');
|
|
4
|
-
const {
|
|
4
|
+
const { GetIntegration } = require('./get-integration');
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
GetIntegrationsForUser,
|
|
8
8
|
DeleteIntegrationForUser,
|
|
9
9
|
CreateIntegration,
|
|
10
|
-
|
|
10
|
+
GetIntegration,
|
|
11
11
|
};
|
|
@@ -6,9 +6,7 @@ class GetEntitiesForUser {
|
|
|
6
6
|
|
|
7
7
|
this.definitionMap = new Map();
|
|
8
8
|
for (const definition of moduleDefinitions) {
|
|
9
|
-
|
|
10
|
-
Module.getEntityModelFromDefinition(definition).modelName;
|
|
11
|
-
this.definitionMap.set(modelName, definition);
|
|
9
|
+
this.definitionMap.set(definition.modelName, definition);
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
12
|
|
|
@@ -18,9 +16,7 @@ class GetEntitiesForUser {
|
|
|
18
16
|
);
|
|
19
17
|
|
|
20
18
|
return entities.map((entity) => {
|
|
21
|
-
const definition = this.definitionMap.get(entity.
|
|
22
|
-
// todo: check if dont need to use this.
|
|
23
|
-
const type = definition ? definition.getName() : 'unknown';
|
|
19
|
+
const definition = this.definitionMap.get(entity.moduleName);
|
|
24
20
|
|
|
25
21
|
const moduleInstance = new Module({
|
|
26
22
|
userId,
|
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.396.
|
|
4
|
+
"version": "2.0.0--canary.396.2b7bd44.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.396.
|
|
26
|
-
"@friggframework/prettier-config": "2.0.0--canary.396.
|
|
27
|
-
"@friggframework/test": "2.0.0--canary.396.
|
|
25
|
+
"@friggframework/eslint-config": "2.0.0--canary.396.2b7bd44.0",
|
|
26
|
+
"@friggframework/prettier-config": "2.0.0--canary.396.2b7bd44.0",
|
|
27
|
+
"@friggframework/test": "2.0.0--canary.396.2b7bd44.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": "2b7bd440a6eba523892911e27082c1eff49fa8bb"
|
|
57
57
|
}
|