@friggframework/core 2.0.0--canary.397.3862908.0 → 2.0.0--canary.398.e2147f7.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 (91) hide show
  1. package/handlers/app-handler-helpers.js +3 -0
  2. package/handlers/backend-utils.js +34 -35
  3. package/handlers/routers/auth.js +11 -14
  4. package/handlers/routers/integration-defined-routers.js +5 -8
  5. package/handlers/routers/middleware/loadUser.js +15 -0
  6. package/handlers/routers/middleware/requireLoggedInUser.js +12 -0
  7. package/handlers/routers/user.js +5 -25
  8. package/handlers/workers/integration-defined-workers.js +3 -6
  9. package/index.js +14 -1
  10. package/integrations/create-frigg-backend.js +31 -0
  11. package/integrations/index.js +5 -0
  12. package/integrations/integration-base.js +44 -42
  13. package/integrations/integration-factory.js +251 -0
  14. package/integrations/integration-router.js +171 -289
  15. package/integrations/integration-user.js +144 -0
  16. package/integrations/options.js +1 -1
  17. package/integrations/test/integration-base.test.js +6 -6
  18. package/module-plugin/auther.js +393 -0
  19. package/module-plugin/entity-manager.js +70 -0
  20. package/{modules → module-plugin}/index.js +6 -0
  21. package/module-plugin/module-factory.js +61 -0
  22. package/{modules → module-plugin}/test/mock-api/api.js +3 -8
  23. package/{modules → module-plugin}/test/mock-api/definition.js +8 -12
  24. package/package.json +5 -5
  25. package/types/integrations/index.d.ts +6 -2
  26. package/types/module-plugin/index.d.ts +21 -4
  27. package/credential/credential-repository.js +0 -42
  28. package/credential/use-cases/get-credential-for-user.js +0 -21
  29. package/credential/use-cases/update-authentication-status.js +0 -15
  30. package/handlers/app-definition-loader.js +0 -38
  31. package/integrations/integration-repository.js +0 -67
  32. package/integrations/integration.js +0 -233
  33. package/integrations/tests/doubles/dummy-integration-class.js +0 -11
  34. package/integrations/tests/doubles/test-integration-repository.js +0 -52
  35. package/integrations/tests/use-cases/create-integration.test.js +0 -27
  36. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -20
  37. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -29
  38. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -26
  39. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -30
  40. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -12
  41. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -15
  42. package/integrations/tests/use-cases/update-integration-status.test.js +0 -0
  43. package/integrations/tests/use-cases/update-integration.test.js +0 -24
  44. package/integrations/use-cases/create-integration.js +0 -57
  45. package/integrations/use-cases/delete-integration-for-user.js +0 -54
  46. package/integrations/use-cases/get-integration-for-user.js +0 -63
  47. package/integrations/use-cases/get-integration-instance.js +0 -73
  48. package/integrations/use-cases/get-integrations-for-user.js +0 -63
  49. package/integrations/use-cases/get-possible-integrations.js +0 -13
  50. package/integrations/use-cases/index.js +0 -11
  51. package/integrations/use-cases/update-integration-messages.js +0 -20
  52. package/integrations/use-cases/update-integration-status.js +0 -12
  53. package/integrations/use-cases/update-integration.js +0 -81
  54. package/integrations/utils/map-integration-dto.js +0 -36
  55. package/modules/module-factory.js +0 -54
  56. package/modules/module-repository.js +0 -72
  57. package/modules/module.js +0 -251
  58. package/modules/tests/doubles/test-module-factory.js +0 -16
  59. package/modules/tests/doubles/test-module-repository.js +0 -19
  60. package/modules/use-cases/get-entities-for-user.js +0 -32
  61. package/modules/use-cases/get-entity-options-by-id.js +0 -58
  62. package/modules/use-cases/get-entity-options-by-type.js +0 -34
  63. package/modules/use-cases/get-module-instance-from-type.js +0 -31
  64. package/modules/use-cases/get-module.js +0 -56
  65. package/modules/use-cases/refresh-entity-options.js +0 -58
  66. package/modules/use-cases/test-module-auth.js +0 -54
  67. package/modules/utils/map-module-dto.js +0 -18
  68. package/user/tests/doubles/test-user-repository.js +0 -72
  69. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  70. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  71. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  72. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  73. package/user/tests/use-cases/login-user.test.js +0 -140
  74. package/user/use-cases/create-individual-user.js +0 -61
  75. package/user/use-cases/create-organization-user.js +0 -47
  76. package/user/use-cases/create-token-for-user-id.js +0 -30
  77. package/user/use-cases/get-user-from-bearer-token.js +0 -77
  78. package/user/use-cases/login-user.js +0 -122
  79. package/user/user-repository.js +0 -62
  80. package/user/user.js +0 -77
  81. /package/{modules → module-plugin}/ModuleConstants.js +0 -0
  82. /package/{modules → module-plugin}/credential.js +0 -0
  83. /package/{modules → module-plugin}/entity.js +0 -0
  84. /package/{modules → module-plugin}/manager.js +0 -0
  85. /package/{modules → module-plugin}/requester/api-key.js +0 -0
  86. /package/{modules → module-plugin}/requester/basic.js +0 -0
  87. /package/{modules → module-plugin}/requester/oauth-2.js +0 -0
  88. /package/{modules → module-plugin}/requester/requester.js +0 -0
  89. /package/{modules → module-plugin}/requester/requester.test.js +0 -0
  90. /package/{modules → module-plugin}/test/auther.test.js +0 -0
  91. /package/{modules → module-plugin}/test/mock-api/mocks/hubspot.js +0 -0
@@ -1,52 +0,0 @@
1
- const { v4: uuid } = require('uuid');
2
-
3
- class TestIntegrationRepository {
4
- constructor() {
5
- this.store = new Map();
6
- }
7
-
8
- async createIntegration(entities, userId, config) {
9
- const id = uuid();
10
- const record = {
11
- id,
12
- entitiesIds: entities,
13
- userId,
14
- config,
15
- version: '0.0.0',
16
- status: 'NEW',
17
- messages: {},
18
- };
19
- this.store.set(id, record);
20
- return record;
21
- }
22
-
23
- async findIntegrationById(id) {
24
- const rec = this.store.get(id);
25
- if (!rec) return null;
26
- return rec;
27
- }
28
-
29
- async findIntegrationsByUserId(userId) {
30
- return Array.from(this.store.values()).filter(r => r.userId === userId);
31
- }
32
-
33
- async updateIntegrationMessages(id, type, title, body, timestamp) {
34
- const rec = this.store.get(id);
35
- if (!rec) return false;
36
- if (!rec.messages[type]) rec.messages[type] = [];
37
- rec.messages[type].push({ title, message: body, timestamp });
38
- return true;
39
- }
40
-
41
- async deleteIntegrationById(id) {
42
- return this.store.delete(id);
43
- }
44
-
45
- async updateIntegrationStatus(id, status) {
46
- const rec = this.store.get(id);
47
- if (rec) rec.status = status;
48
- return true;
49
- }
50
- }
51
-
52
- module.exports = { TestIntegrationRepository };
@@ -1,27 +0,0 @@
1
- const { CreateIntegration } = require('../../use-cases/create-integration');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
4
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
5
-
6
- describe('CreateIntegration Use-Case', () => {
7
- it('creates an integration and returns DTO', async () => {
8
- const integrationRepository = new TestIntegrationRepository();
9
- const moduleFactory = new TestModuleFactory();
10
-
11
- const useCase = new CreateIntegration({
12
- integrationRepository,
13
- integrationClasses: [DummyIntegration],
14
- moduleFactory,
15
- });
16
-
17
- const entities = ['entity-1'];
18
- const userId = 'user-1';
19
- const config = { type: 'dummy', foo: 'bar' };
20
-
21
- const dto = await useCase.execute(entities, userId, config);
22
-
23
- expect(dto.id).toBeDefined();
24
- expect(dto.config).toEqual(config);
25
- expect(dto.userId).toBe(userId);
26
- });
27
- });
@@ -1,20 +0,0 @@
1
- const { DeleteIntegrationForUser } = require('../../use-cases/delete-integration-for-user');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
4
-
5
- describe('DeleteIntegrationForUser', () => {
6
- it('deletes integration', async () => {
7
- const repo = new TestIntegrationRepository();
8
- const record = await repo.createIntegration(['e1'], 'user-1', { type: 'dummy' });
9
-
10
- const useCase = new DeleteIntegrationForUser({
11
- integrationRepository: repo,
12
- integrationClasses: [DummyIntegration],
13
- });
14
-
15
- await useCase.execute(record.id, 'user-1');
16
-
17
- const found = await repo.findIntegrationById(record.id);
18
- expect(found).toBeNull();
19
- });
20
- });
@@ -1,29 +0,0 @@
1
- const { GetIntegrationForUser } = require('../../use-cases/get-integration-for-user');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
4
- const { TestModuleRepository } = require('../../../modules/tests/doubles/test-module-repository');
5
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
6
-
7
-
8
- describe('GetIntegrationForUser', () => {
9
- it('returns integration dto', async () => {
10
- const iRepo = new TestIntegrationRepository();
11
- const mRepo = new TestModuleRepository();
12
- const mFactory = new TestModuleFactory();
13
-
14
- const entity = { id: 'entity-1' };
15
- mRepo.addEntity(entity);
16
-
17
- const record = await iRepo.createIntegration([entity.id], 'user-1', { type: 'dummy' });
18
-
19
- const useCase = new GetIntegrationForUser({
20
- integrationRepository: iRepo,
21
- integrationClasses: [DummyIntegration],
22
- moduleFactory: mFactory,
23
- moduleRepository: mRepo,
24
- });
25
-
26
- const dto = await useCase.execute(record.id, 'user-1');
27
- expect(dto.id).toBe(record.id);
28
- });
29
- });
@@ -1,26 +0,0 @@
1
- const { GetIntegrationInstance } = require('../../use-cases/get-integration-instance');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
4
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
5
-
6
- describe('GetIntegrationInstance Use-Case', () => {
7
- it('returns hydrated integration instance', async () => {
8
- const integrationRepository = new TestIntegrationRepository();
9
- const moduleFactory = new TestModuleFactory();
10
-
11
- // first create record directly via repo
12
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
13
-
14
- const useCase = new GetIntegrationInstance({
15
- integrationRepository,
16
- integrationClasses: [DummyIntegration],
17
- moduleFactory,
18
- });
19
-
20
- const instance = await useCase.execute(record.id, 'user-1');
21
-
22
- expect(instance.id).toBe(record.id);
23
- expect(instance.getConfig().type).toBe('dummy');
24
- expect(instance.entities).toEqual(record.entitiesIds);
25
- });
26
- });
@@ -1,30 +0,0 @@
1
- const { GetIntegrationsForUser } = require('../../use-cases/get-integrations-for-user');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
4
- const { TestModuleRepository } = require('../../../modules/tests/doubles/test-module-repository');
5
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
6
-
7
- describe('GetIntegrationsForUser', () => {
8
- it('returns integrations dto list', async () => {
9
- const integrationRepo = new TestIntegrationRepository();
10
- const moduleRepo = new TestModuleRepository();
11
- const moduleFactory = new TestModuleFactory();
12
-
13
- // setup entity and module repo
14
- const entity = { id: 'entity-1' };
15
- moduleRepo.addEntity(entity);
16
-
17
- await integrationRepo.createIntegration([entity.id], 'user-1', { type: 'dummy' });
18
-
19
- const useCase = new GetIntegrationsForUser({
20
- integrationRepository: integrationRepo,
21
- integrationClasses: [DummyIntegration],
22
- moduleFactory,
23
- moduleRepository: moduleRepo,
24
- });
25
-
26
- const list = await useCase.execute('user-1');
27
- expect(list.length).toBe(1);
28
- expect(list[0].config.type).toBe('dummy');
29
- });
30
- });
@@ -1,12 +0,0 @@
1
- const { GetPossibleIntegrations } = require('../../use-cases/get-possible-integrations');
2
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
3
-
4
- describe('GetPossibleIntegrations', () => {
5
- it('returns option details array', async () => {
6
- const useCase = new GetPossibleIntegrations({ integrationClasses: [DummyIntegration] });
7
- const res = await useCase.execute();
8
- expect(Array.isArray(res)).toBe(true);
9
- expect(res.length).toBe(1);
10
- expect(res[0].display).toBeDefined();
11
- });
12
- });
@@ -1,15 +0,0 @@
1
- const { UpdateIntegrationMessages } = require('../../use-cases/update-integration-messages');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
-
4
- describe('UpdateIntegrationMessages', () => {
5
- it('adds message', async () => {
6
- const repo = new TestIntegrationRepository();
7
- const rec = await repo.createIntegration(['e1'], 'user-1', { type: 'dummy' });
8
-
9
- const useCase = new UpdateIntegrationMessages({ integrationRepository: repo });
10
- await useCase.execute(rec.id, 'errors', 'title', 'body', Date.now());
11
-
12
- const fetched = await repo.findIntegrationById(rec.id);
13
- expect(fetched.messages.errors.length).toBe(1);
14
- });
15
- });
@@ -1,24 +0,0 @@
1
- const { UpdateIntegration } = require('../../use-cases/update-integration');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
4
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
5
-
6
- describe('UpdateIntegration', () => {
7
- it('calls on update and returns dto', async () => {
8
- const repo = new TestIntegrationRepository();
9
- const mf = new TestModuleFactory();
10
-
11
- const record = await repo.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
12
-
13
- const useCase = new UpdateIntegration({
14
- integrationRepository: repo,
15
- integrationClasses: [DummyIntegration],
16
- moduleFactory: mf,
17
- });
18
-
19
- const newConfig = { type: 'dummy', foo: 'baz' };
20
- const dto = await useCase.execute(record.id, 'user-1', newConfig);
21
-
22
- expect(dto.config.foo).toBe('baz');
23
- });
24
- });
@@ -1,57 +0,0 @@
1
- const { Integration } = require('../integration');
2
- const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
3
-
4
- class CreateIntegration {
5
- /**
6
- * @param {Object} params
7
- * @param {import('../integration-repository').IntegrationRepository} params.integrationRepository
8
- * @param {import('../integration-classes').IntegrationClasses} params.integrationClasses
9
- * @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory
10
- */
11
- constructor({ integrationRepository, integrationClasses, moduleFactory }) {
12
- this.integrationRepository = integrationRepository;
13
- this.integrationClasses = integrationClasses;
14
- this.moduleFactory = moduleFactory;
15
- }
16
-
17
- async execute(entities, userId, config) {
18
- const integrationRecord = await this.integrationRepository.createIntegration(entities, userId, config);
19
-
20
-
21
- const integrationClass = this.integrationClasses.find(
22
- (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
23
- );
24
-
25
- if (!integrationClass) {
26
- throw new Error(`No integration class found for type: ${integrationRecord.config.type}`);
27
- }
28
-
29
- const modules = [];
30
- for (const entityId of integrationRecord.entitiesIds) {
31
- const moduleInstance = await this.moduleFactory.getModuleInstance(
32
- entityId,
33
- integrationRecord.userId
34
- );
35
- modules.push(moduleInstance);
36
- }
37
-
38
- const integrationInstance = new Integration({
39
- id: integrationRecord.id,
40
- userId: integrationRecord.userId,
41
- entities: integrationRecord.entitiesIds,
42
- config: integrationRecord.config,
43
- status: integrationRecord.status,
44
- version: integrationRecord.version,
45
- messages: integrationRecord.messages,
46
- integrationClass: integrationClass,
47
- modules
48
- });
49
-
50
- await integrationInstance.initialize();
51
- await integrationInstance.send('ON_CREATE', { integrationId: integrationRecord.id });
52
-
53
- return mapIntegrationClassToIntegrationDTO(integrationInstance);
54
- }
55
- }
56
-
57
- module.exports = { CreateIntegration };
@@ -1,54 +0,0 @@
1
- const Boom = require('@hapi/boom');
2
- const { Integration } = require('../integration');
3
-
4
- class DeleteIntegrationForUser {
5
- constructor({ integrationRepository, integrationClasses }) {
6
-
7
- /**
8
- * @type {import('../integration-repository').IntegrationRepository}
9
- */
10
- this.integrationRepository = integrationRepository;
11
- this.integrationClasses = integrationClasses;
12
- }
13
-
14
- async execute(integrationId, userId) {
15
- const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
16
-
17
- if (!integrationRecord) {
18
- throw Boom.notFound(
19
- `Integration with id of ${integrationId} does not exist`
20
- );
21
- }
22
-
23
- const integrationClass = this.integrationClasses.find(
24
- (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
25
- );
26
-
27
- if (integrationRecord.userId !== userId) {
28
- throw new Error(
29
- `Integration ${integrationId} does not belong to User ${userId}`
30
- );
31
- }
32
-
33
- const integrationInstance = new Integration({
34
- id: integrationRecord.id,
35
- userId: integrationRecord.userId,
36
- entities: integrationRecord.entitiesIds,
37
- config: integrationRecord.config,
38
- status: integrationRecord.status,
39
- version: integrationRecord.version,
40
- messages: integrationRecord.messages,
41
- integrationClass: integrationClass,
42
- modules: [],
43
- });
44
-
45
- // 6. Complete async initialization (load dynamic actions, register handlers)
46
- await integrationInstance.initialize();
47
- await integrationInstance.send('ON_DELETE');
48
-
49
- await this.integrationRepository.deleteIntegrationById(integrationId);
50
-
51
- }
52
- }
53
-
54
- module.exports = { DeleteIntegrationForUser };
@@ -1,63 +0,0 @@
1
- const { Integration } = require('../integration');
2
- const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
3
-
4
- class GetIntegrationForUser {
5
- constructor({ integrationRepository, integrationClasses, moduleFactory, moduleRepository }) {
6
-
7
- /**
8
- * @type {import('../integration-repository').IntegrationRepository}
9
- */
10
- this.integrationRepository = integrationRepository;
11
- this.integrationClasses = integrationClasses;
12
- this.moduleFactory = moduleFactory;
13
- this.moduleRepository = moduleRepository;
14
- }
15
-
16
- /**
17
- * @param {string} integrationId
18
- * @param {string} userId
19
- * @returns {Promise<Integration>}
20
- */
21
- async execute(integrationId, userId) {
22
- const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
23
- const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
24
-
25
- if (!integrationRecord) {
26
- throw Boom.notFound(`Integration with id of ${integrationId} does not exist`);
27
- }
28
-
29
- if (integrationRecord.user.toString() !== userId.toString()) {
30
- throw Boom.forbidden('User does not have access to this integration');
31
- }
32
-
33
- const integrationClass = this.integrationClasses.find(
34
- (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
35
- );
36
-
37
- const modules = [];
38
- for (const entity of entities) {
39
- const moduleInstance = await this.moduleFactory.getModuleInstance(
40
- entity._id,
41
- integrationRecord.user
42
- );
43
- modules.push(moduleInstance);
44
- }
45
-
46
- const integrationInstance = new Integration({
47
- id: integrationRecord._id,
48
- userId: integrationRecord.user,
49
- entities: entities,
50
- config: integrationRecord.config,
51
- status: integrationRecord.status,
52
- version: integrationRecord.version,
53
- messages: integrationRecord.messages,
54
- entityReference: integrationRecord.entityReference,
55
- integrationClass: integrationClass,
56
- modules
57
- });
58
-
59
- return mapIntegrationClassToIntegrationDTO(integrationInstance);
60
- }
61
- }
62
-
63
- module.exports = { GetIntegrationForUser };
@@ -1,73 +0,0 @@
1
- const { Integration } = require('../integration');
2
-
3
- class GetIntegrationInstance {
4
-
5
- /**
6
- * @class GetIntegrationInstance
7
- * @description Use case for retrieving a single integration instance by ID and user.
8
- * @param {Object} params
9
- * @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data access
10
- * @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes
11
- * @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management
12
- */
13
- constructor({
14
- integrationRepository,
15
- integrationClasses,
16
- moduleFactory,
17
- }) {
18
- this.integrationRepository = integrationRepository;
19
- this.integrationClasses = integrationClasses;
20
- this.moduleFactory = moduleFactory;
21
- }
22
-
23
- async execute(integrationId, userId) {
24
- const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
25
-
26
- if (!integrationRecord) {
27
- throw new Error(`No integration found by the ID of ${integrationId}`);
28
- }
29
-
30
- const integrationClass = this.integrationClasses.find(
31
- (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
32
- );
33
-
34
- if (!integrationClass) {
35
- throw new Error(`No integration class found for type: ${integrationRecord.config.type}`);
36
- }
37
-
38
- if (integrationRecord.userId !== userId) {
39
- throw new Error(
40
- `Integration ${integrationId} does not belong to User ${userId}`
41
- );
42
- }
43
-
44
-
45
- const modules = [];
46
- for (const entityId of integrationRecord.entitiesIds) {
47
- const moduleInstance = await this.moduleFactory.getModuleInstance(
48
- entityId,
49
- integrationRecord.userId
50
- );
51
- modules.push(moduleInstance);
52
- }
53
-
54
- const integrationInstance = new Integration({
55
- id: integrationRecord.id,
56
- userId: integrationRecord.userId,
57
- entities: integrationRecord.entitiesIds,
58
- config: integrationRecord.config,
59
- status: integrationRecord.status,
60
- version: integrationRecord.version,
61
- messages: integrationRecord.messages,
62
- integrationClass: integrationClass,
63
- modules
64
- });
65
-
66
-
67
- await integrationInstance.initialize();
68
-
69
- return integrationInstance;
70
- }
71
- }
72
-
73
- module.exports = { GetIntegrationInstance };
@@ -1,63 +0,0 @@
1
- const { Integration } = require('../integration');
2
- const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
3
-
4
- class GetIntegrationsForUser {
5
- constructor({ integrationRepository, integrationClasses, moduleFactory, moduleRepository }) {
6
-
7
- /**
8
- * @type {import('../integration-repository').IntegrationRepository}
9
- */
10
- this.integrationRepository = integrationRepository;
11
- this.integrationClasses = integrationClasses;
12
- this.moduleFactory = moduleFactory;
13
- this.moduleRepository = moduleRepository;
14
- }
15
-
16
- /**
17
- * @param {string} userId
18
- * @returns {Promise<Integration[]>}
19
- */
20
- async execute(userId) {
21
- const integrationRecords = await this.integrationRepository.findIntegrationsByUserId(userId);
22
-
23
- const integrations = []
24
-
25
- for (const integrationRecord of integrationRecords) {
26
- const entities = await this.moduleRepository.findEntitiesByIds(integrationRecord.entitiesIds);
27
-
28
- const integrationClass = this.integrationClasses.find(
29
- (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
30
- );
31
-
32
- const modules = [];
33
- for (const entity of entities) {
34
- const moduleInstance = await this.moduleFactory.getModuleInstance(
35
- entity.id,
36
- integrationRecord.userId
37
- );
38
- modules.push(moduleInstance);
39
- }
40
-
41
- const integrationInstance = new Integration({
42
- id: integrationRecord.id,
43
- userId: integrationRecord.user,
44
- entities: entities,
45
- config: integrationRecord.config,
46
- status: integrationRecord.status,
47
- version: integrationRecord.version,
48
- messages: integrationRecord.messages,
49
- integrationClass: integrationClass,
50
- modules
51
- });
52
-
53
- integrations.push(
54
- mapIntegrationClassToIntegrationDTO(integrationInstance)
55
- );
56
-
57
- }
58
-
59
- return integrations;
60
- }
61
- }
62
-
63
- module.exports = { GetIntegrationsForUser };
@@ -1,13 +0,0 @@
1
- class GetPossibleIntegrations {
2
- constructor({ integrationClasses }) {
3
- this.integrationClasses = integrationClasses;
4
- }
5
-
6
- async execute() {
7
- return this.integrationClasses.map((integrationClass) =>
8
- integrationClass.getOptionDetails()
9
- );
10
- }
11
- }
12
-
13
- 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,20 +0,0 @@
1
- class UpdateIntegrationMessages {
2
- constructor({ integrationRepository }) {
3
- this.integrationRepository = integrationRepository;
4
- }
5
-
6
- /**
7
- * @param {string} integrationId
8
- * @param {string} messageType - 'errors', 'warnings', 'info' or 'logs'
9
- * @param {string} messageTitle,
10
- * @param {string} messageBody,
11
- * @param {string} messageTimestamp,
12
- * @returns {Promise<Object>}
13
- */
14
- async execute(integrationId, messageType, messageTitle, messageBody, messageTimestamp) {
15
- const integration = await this.integrationRepository.updateIntegrationMessages(integrationId, messageType, messageTitle, messageBody, messageTimestamp);
16
- return integration;
17
- }
18
- }
19
-
20
- module.exports = { UpdateIntegrationMessages };
@@ -1,12 +0,0 @@
1
- class UpdateIntegrationStatus {
2
- constructor({ integrationRepository }) {
3
- this.integrationRepository = integrationRepository;
4
- }
5
-
6
- async execute(integrationId, status) {
7
- const integration = await this.integrationRepository.updateIntegrationStatus(integrationId, status);
8
- return integration;
9
- }
10
- }
11
-
12
- module.exports = { UpdateIntegrationStatus };