@friggframework/core 2.0.0--canary.397.1b51778.0 → 2.0.0--canary.397.155fecd.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 +933 -50
- package/core/create-handler.js +1 -0
- package/handlers/routers/auth.js +1 -15
- package/integrations/integration-router.js +11 -11
- package/integrations/tests/doubles/dummy-integration-class.js +90 -0
- package/integrations/tests/doubles/test-integration-repository.js +89 -0
- package/integrations/tests/use-cases/create-integration.test.js +124 -0
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +143 -0
- package/integrations/tests/use-cases/get-integration-for-user.test.js +143 -0
- package/integrations/tests/use-cases/get-integration-instance.test.js +169 -0
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +169 -0
- package/integrations/tests/use-cases/get-possible-integrations.test.js +188 -0
- package/integrations/tests/use-cases/update-integration-messages.test.js +142 -0
- package/integrations/tests/use-cases/update-integration-status.test.js +103 -0
- package/integrations/tests/use-cases/update-integration.test.js +134 -0
- package/integrations/use-cases/create-integration.js +19 -4
- package/integrations/use-cases/delete-integration-for-user.js +19 -0
- package/integrations/use-cases/get-integration-for-user.js +22 -6
- package/integrations/use-cases/get-integration-instance.js +14 -3
- package/integrations/use-cases/get-integrations-for-user.js +17 -3
- package/integrations/use-cases/get-possible-integrations.js +14 -0
- package/integrations/use-cases/update-integration-messages.js +17 -6
- package/integrations/use-cases/update-integration-status.js +16 -0
- package/integrations/use-cases/update-integration.js +17 -6
- package/modules/module-repository.js +2 -21
- package/modules/tests/doubles/test-module-factory.js +16 -0
- package/modules/tests/doubles/test-module-repository.js +19 -0
- package/package.json +5 -5
- package/integrations/test/integration-base.test.js +0 -144
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const { UpdateIntegrationStatus } = require('../../use-cases/update-integration-status');
|
|
2
|
+
const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
|
|
3
|
+
|
|
4
|
+
describe('UpdateIntegrationStatus Use-Case', () => {
|
|
5
|
+
let integrationRepository;
|
|
6
|
+
let useCase;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
integrationRepository = new TestIntegrationRepository();
|
|
10
|
+
useCase = new UpdateIntegrationStatus({
|
|
11
|
+
integrationRepository,
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('happy path', () => {
|
|
16
|
+
it('updates integration status', async () => {
|
|
17
|
+
const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
|
|
18
|
+
|
|
19
|
+
const result = await useCase.execute(record.id, 'ACTIVE');
|
|
20
|
+
|
|
21
|
+
expect(result).toBe(true);
|
|
22
|
+
|
|
23
|
+
const updatedRecord = await integrationRepository.findIntegrationById(record.id);
|
|
24
|
+
expect(updatedRecord.status).toBe('ACTIVE');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('tracks status update operation', async () => {
|
|
28
|
+
const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
|
|
29
|
+
integrationRepository.clearHistory();
|
|
30
|
+
|
|
31
|
+
await useCase.execute(record.id, 'PAUSED');
|
|
32
|
+
|
|
33
|
+
const history = integrationRepository.getOperationHistory();
|
|
34
|
+
const updateOperation = history.find(op => op.operation === 'updateStatus');
|
|
35
|
+
expect(updateOperation).toEqual({
|
|
36
|
+
operation: 'updateStatus',
|
|
37
|
+
id: record.id,
|
|
38
|
+
status: 'PAUSED',
|
|
39
|
+
success: true
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('handles different status values', async () => {
|
|
44
|
+
const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
|
|
45
|
+
|
|
46
|
+
const statuses = ['ACTIVE', 'PAUSED', 'ERROR', 'DISABLED'];
|
|
47
|
+
|
|
48
|
+
for (const status of statuses) {
|
|
49
|
+
await useCase.execute(record.id, status);
|
|
50
|
+
const updatedRecord = await integrationRepository.findIntegrationById(record.id);
|
|
51
|
+
expect(updatedRecord.status).toBe(status);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('error cases', () => {
|
|
57
|
+
it('returns false when integration not found', async () => {
|
|
58
|
+
const nonExistentId = 'non-existent-id';
|
|
59
|
+
|
|
60
|
+
const result = await useCase.execute(nonExistentId, 'ACTIVE');
|
|
61
|
+
|
|
62
|
+
expect(result).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('tracks failed update operation', async () => {
|
|
66
|
+
const nonExistentId = 'non-existent-id';
|
|
67
|
+
integrationRepository.clearHistory();
|
|
68
|
+
|
|
69
|
+
await useCase.execute(nonExistentId, 'ACTIVE');
|
|
70
|
+
|
|
71
|
+
const history = integrationRepository.getOperationHistory();
|
|
72
|
+
const updateOperation = history.find(op => op.operation === 'updateStatus');
|
|
73
|
+
expect(updateOperation).toEqual({
|
|
74
|
+
operation: 'updateStatus',
|
|
75
|
+
id: nonExistentId,
|
|
76
|
+
status: 'ACTIVE',
|
|
77
|
+
success: false
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('edge cases', () => {
|
|
83
|
+
it('handles null status value', async () => {
|
|
84
|
+
const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
|
|
85
|
+
|
|
86
|
+
const result = await useCase.execute(record.id, null);
|
|
87
|
+
|
|
88
|
+
expect(result).toBe(true);
|
|
89
|
+
const updatedRecord = await integrationRepository.findIntegrationById(record.id);
|
|
90
|
+
expect(updatedRecord.status).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('handles empty string status', async () => {
|
|
94
|
+
const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
|
|
95
|
+
|
|
96
|
+
const result = await useCase.execute(record.id, '');
|
|
97
|
+
|
|
98
|
+
expect(result).toBe(true);
|
|
99
|
+
const updatedRecord = await integrationRepository.findIntegrationById(record.id);
|
|
100
|
+
expect(updatedRecord.status).toBe('');
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
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 Use-Case', () => {
|
|
7
|
+
let integrationRepository;
|
|
8
|
+
let moduleFactory;
|
|
9
|
+
let useCase;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
integrationRepository = new TestIntegrationRepository();
|
|
13
|
+
moduleFactory = new TestModuleFactory();
|
|
14
|
+
useCase = new UpdateIntegration({
|
|
15
|
+
integrationRepository,
|
|
16
|
+
integrationClasses: [DummyIntegration],
|
|
17
|
+
moduleFactory,
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('happy path', () => {
|
|
22
|
+
it('calls on update and returns dto', async () => {
|
|
23
|
+
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
|
|
24
|
+
|
|
25
|
+
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
26
|
+
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
27
|
+
|
|
28
|
+
expect(dto.config.foo).toBe('baz');
|
|
29
|
+
expect(dto.id).toBe(record.id);
|
|
30
|
+
expect(dto.userId).toBe('user-1');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('triggers ON_UPDATE event with correct payload', async () => {
|
|
34
|
+
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
|
|
35
|
+
integrationRepository.clearHistory();
|
|
36
|
+
|
|
37
|
+
const newConfig = { type: 'dummy', foo: 'updated' };
|
|
38
|
+
await useCase.execute(record.id, 'user-1', newConfig);
|
|
39
|
+
|
|
40
|
+
const history = integrationRepository.getOperationHistory();
|
|
41
|
+
const findOperation = history.find(op => op.operation === 'findById');
|
|
42
|
+
expect(findOperation).toEqual({
|
|
43
|
+
operation: 'findById',
|
|
44
|
+
id: record.id,
|
|
45
|
+
found: true
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('updates integration with multiple entities', async () => {
|
|
50
|
+
const record = await integrationRepository.createIntegration(['e1', 'e2'], 'user-1', { type: 'dummy' });
|
|
51
|
+
|
|
52
|
+
const newConfig = { type: 'dummy', updated: true };
|
|
53
|
+
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
54
|
+
|
|
55
|
+
expect(dto.entities).toEqual(['e1', 'e2']);
|
|
56
|
+
expect(dto.config.updated).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('error cases', () => {
|
|
61
|
+
it('throws error when integration not found', async () => {
|
|
62
|
+
const nonExistentId = 'non-existent-id';
|
|
63
|
+
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
64
|
+
|
|
65
|
+
await expect(useCase.execute(nonExistentId, 'user-1', newConfig))
|
|
66
|
+
.rejects
|
|
67
|
+
.toThrow(`No integration found by the ID of ${nonExistentId}`);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('throws error when integration class not found', async () => {
|
|
71
|
+
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'unknown-type' });
|
|
72
|
+
|
|
73
|
+
const newConfig = { type: 'unknown-type', foo: 'baz' };
|
|
74
|
+
|
|
75
|
+
await expect(useCase.execute(record.id, 'user-1', newConfig))
|
|
76
|
+
.rejects
|
|
77
|
+
.toThrow('No integration class found for type: unknown-type');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('throws error when user does not own integration', async () => {
|
|
81
|
+
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
|
|
82
|
+
|
|
83
|
+
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
84
|
+
|
|
85
|
+
await expect(useCase.execute(record.id, 'different-user', newConfig))
|
|
86
|
+
.rejects
|
|
87
|
+
.toThrow(`Integration ${record.id} does not belong to User different-user`);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('throws error when no integration classes provided', async () => {
|
|
91
|
+
const useCaseWithoutClasses = new UpdateIntegration({
|
|
92
|
+
integrationRepository,
|
|
93
|
+
integrationClasses: [],
|
|
94
|
+
moduleFactory,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
|
|
98
|
+
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
99
|
+
|
|
100
|
+
await expect(useCaseWithoutClasses.execute(record.id, 'user-1', newConfig))
|
|
101
|
+
.rejects
|
|
102
|
+
.toThrow('No integration class found for type: dummy');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('edge cases', () => {
|
|
107
|
+
it('handles config with null values', async () => {
|
|
108
|
+
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
|
|
109
|
+
|
|
110
|
+
const newConfig = { type: 'dummy', foo: null, bar: undefined };
|
|
111
|
+
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
112
|
+
|
|
113
|
+
expect(dto.config.foo).toBeNull();
|
|
114
|
+
expect(dto.config.bar).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('handles deeply nested config updates', async () => {
|
|
118
|
+
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', nested: { old: 'value' } });
|
|
119
|
+
|
|
120
|
+
const newConfig = {
|
|
121
|
+
type: 'dummy',
|
|
122
|
+
nested: {
|
|
123
|
+
new: 'value',
|
|
124
|
+
deep: { level: 'test' }
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
128
|
+
|
|
129
|
+
expect(dto.config.nested.new).toBe('value');
|
|
130
|
+
expect(dto.config.nested.deep.level).toBe('test');
|
|
131
|
+
expect(dto.config.nested.old).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
const { Integration } = require('../integration');
|
|
2
2
|
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Use case for creating a new integration instance.
|
|
6
|
+
* @class CreateIntegration
|
|
7
|
+
*/
|
|
4
8
|
class CreateIntegration {
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {import('../integration-
|
|
9
|
-
* @param {import('
|
|
10
|
+
* Creates a new CreateIntegration instance.
|
|
11
|
+
* @param {Object} params - Configuration parameters.
|
|
12
|
+
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
|
|
13
|
+
* @param {import('../integration-classes').IntegrationClasses} params.integrationClasses - Array of available integration classes.
|
|
14
|
+
* @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management.
|
|
10
15
|
*/
|
|
11
16
|
constructor({ integrationRepository, integrationClasses, moduleFactory }) {
|
|
12
17
|
this.integrationRepository = integrationRepository;
|
|
@@ -14,6 +19,16 @@ class CreateIntegration {
|
|
|
14
19
|
this.moduleFactory = moduleFactory;
|
|
15
20
|
}
|
|
16
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Executes the integration creation process.
|
|
24
|
+
* @async
|
|
25
|
+
* @param {string[]} entities - Array of entity IDs to associate with the integration.
|
|
26
|
+
* @param {string} userId - ID of the user creating the integration.
|
|
27
|
+
* @param {Object} config - Configuration object for the integration.
|
|
28
|
+
* @param {string} config.type - Type of integration to create.
|
|
29
|
+
* @returns {Promise<Object>} The created integration DTO.
|
|
30
|
+
* @throws {Error} When integration class is not found for the specified type.
|
|
31
|
+
*/
|
|
17
32
|
async execute(entities, userId, config) {
|
|
18
33
|
const integrationRecord = await this.integrationRepository.createIntegration(entities, userId, config);
|
|
19
34
|
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
const Boom = require('@hapi/boom');
|
|
2
2
|
const { Integration } = require('../integration');
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Use case for deleting an integration for a specific user.
|
|
6
|
+
* @class DeleteIntegrationForUser
|
|
7
|
+
*/
|
|
4
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
|
+
*/
|
|
5
15
|
constructor({ integrationRepository, integrationClasses }) {
|
|
6
16
|
|
|
7
17
|
/**
|
|
@@ -11,6 +21,15 @@ class DeleteIntegrationForUser {
|
|
|
11
21
|
this.integrationClasses = integrationClasses;
|
|
12
22
|
}
|
|
13
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
|
+
*/
|
|
14
33
|
async execute(integrationId, userId) {
|
|
15
34
|
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
16
35
|
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
const { Integration } = require('../integration');
|
|
2
2
|
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Use case for retrieving a single integration for a specific user.
|
|
6
|
+
* @class GetIntegrationForUser
|
|
7
|
+
*/
|
|
4
8
|
class GetIntegrationForUser {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new GetIntegrationForUser 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
|
+
*/
|
|
5
17
|
constructor({ integrationRepository, integrationClasses, moduleFactory, moduleRepository }) {
|
|
6
18
|
|
|
7
19
|
/**
|
|
@@ -14,9 +26,13 @@ class GetIntegrationForUser {
|
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
29
|
+
* Executes the retrieval of a single integration for a user.
|
|
30
|
+
* @async
|
|
31
|
+
* @param {string} integrationId - ID of the integration to retrieve.
|
|
32
|
+
* @param {string} userId - ID of the user requesting the integration.
|
|
33
|
+
* @returns {Promise<Object>} The integration DTO for the specified user.
|
|
34
|
+
* @throws {Boom.notFound} When integration with the specified ID does not exist.
|
|
35
|
+
* @throws {Boom.forbidden} When user does not have access to the integration.
|
|
20
36
|
*/
|
|
21
37
|
async execute(integrationId, userId) {
|
|
22
38
|
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
@@ -26,7 +42,7 @@ class GetIntegrationForUser {
|
|
|
26
42
|
throw Boom.notFound(`Integration with id of ${integrationId} does not exist`);
|
|
27
43
|
}
|
|
28
44
|
|
|
29
|
-
if (integrationRecord.
|
|
45
|
+
if (integrationRecord.userId.toString() !== userId.toString()) {
|
|
30
46
|
throw Boom.forbidden('User does not have access to this integration');
|
|
31
47
|
}
|
|
32
48
|
|
|
@@ -38,14 +54,14 @@ class GetIntegrationForUser {
|
|
|
38
54
|
for (const entity of entities) {
|
|
39
55
|
const moduleInstance = await this.moduleFactory.getModuleInstance(
|
|
40
56
|
entity._id,
|
|
41
|
-
integrationRecord.
|
|
57
|
+
integrationRecord.userId
|
|
42
58
|
);
|
|
43
59
|
modules.push(moduleInstance);
|
|
44
60
|
}
|
|
45
61
|
|
|
46
62
|
const integrationInstance = new Integration({
|
|
47
63
|
id: integrationRecord._id,
|
|
48
|
-
userId: integrationRecord.
|
|
64
|
+
userId: integrationRecord.userId,
|
|
49
65
|
entities: entities,
|
|
50
66
|
config: integrationRecord.config,
|
|
51
67
|
status: integrationRecord.status,
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
const { Integration } = require('../integration');
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Use case for retrieving a single integration instance by ID and user.
|
|
5
|
+
* @class GetIntegrationInstance
|
|
6
|
+
*/
|
|
3
7
|
class GetIntegrationInstance {
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
* @param {Object} params
|
|
10
|
+
* Creates a new GetIntegrationInstance instance.
|
|
11
|
+
* @param {Object} params - Configuration parameters.
|
|
9
12
|
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data access
|
|
10
13
|
* @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes
|
|
11
14
|
* @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management
|
|
@@ -20,6 +23,14 @@ class GetIntegrationInstance {
|
|
|
20
23
|
this.moduleFactory = moduleFactory;
|
|
21
24
|
}
|
|
22
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
|
+
*/
|
|
23
34
|
async execute(integrationId, userId) {
|
|
24
35
|
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
25
36
|
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
const { Integration } = require('../integration');
|
|
2
2
|
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Use case for retrieving all integrations for a specific user.
|
|
6
|
+
* @class GetIntegrationsForUser
|
|
7
|
+
*/
|
|
4
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
|
+
*/
|
|
5
17
|
constructor({ integrationRepository, integrationClasses, moduleFactory, moduleRepository }) {
|
|
6
18
|
|
|
7
19
|
/**
|
|
@@ -14,8 +26,10 @@ class GetIntegrationsForUser {
|
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
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.
|
|
19
33
|
*/
|
|
20
34
|
async execute(userId) {
|
|
21
35
|
const integrationRecords = await this.integrationRepository.findIntegrationsByUserId(userId);
|
|
@@ -40,7 +54,7 @@ class GetIntegrationsForUser {
|
|
|
40
54
|
|
|
41
55
|
const integrationInstance = new Integration({
|
|
42
56
|
id: integrationRecord.id,
|
|
43
|
-
userId: integrationRecord.
|
|
57
|
+
userId: integrationRecord.userId,
|
|
44
58
|
entities: entities,
|
|
45
59
|
config: integrationRecord.config,
|
|
46
60
|
status: integrationRecord.status,
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use case for retrieving all possible integration types that can be created.
|
|
3
|
+
* @class GetPossibleIntegrations
|
|
4
|
+
*/
|
|
1
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
|
+
*/
|
|
2
11
|
constructor({ integrationClasses }) {
|
|
3
12
|
this.integrationClasses = integrationClasses;
|
|
4
13
|
}
|
|
5
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
|
+
*/
|
|
6
20
|
async execute() {
|
|
7
21
|
return this.integrationClasses.map((integrationClass) =>
|
|
8
22
|
integrationClass.getOptionDetails()
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use case for updating messages associated with an integration.
|
|
3
|
+
* @class UpdateIntegrationMessages
|
|
4
|
+
*/
|
|
1
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
|
+
*/
|
|
2
11
|
constructor({ integrationRepository }) {
|
|
3
12
|
this.integrationRepository = integrationRepository;
|
|
4
13
|
}
|
|
5
14
|
|
|
6
15
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
* @param {string}
|
|
10
|
-
* @param {string}
|
|
11
|
-
* @param {string}
|
|
12
|
-
* @
|
|
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.
|
|
13
24
|
*/
|
|
14
25
|
async execute(integrationId, messageType, messageTitle, messageBody, messageTimestamp) {
|
|
15
26
|
const integration = await this.integrationRepository.updateIntegrationMessages(integrationId, messageType, messageTitle, messageBody, messageTimestamp);
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use case for updating the status of an integration.
|
|
3
|
+
* @class UpdateIntegrationStatus
|
|
4
|
+
*/
|
|
1
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
|
+
*/
|
|
2
11
|
constructor({ integrationRepository }) {
|
|
3
12
|
this.integrationRepository = integrationRepository;
|
|
4
13
|
}
|
|
5
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
|
+
*/
|
|
6
22
|
async execute(integrationId, status) {
|
|
7
23
|
const integration = await this.integrationRepository.updateIntegrationStatus(integrationId, status);
|
|
8
24
|
return integration;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
const { Integration } = require('../integration');
|
|
2
2
|
const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Use case for updating a single integration by ID and user.
|
|
6
|
+
* @class UpdateIntegration
|
|
7
|
+
*/
|
|
5
8
|
class UpdateIntegration {
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* @param {Object} params
|
|
11
|
+
* Creates a new UpdateIntegration instance.
|
|
12
|
+
* @param {Object} params - Configuration parameters.
|
|
11
13
|
* @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data access
|
|
12
14
|
* @param {Array<import('../integration').Integration>} params.integrationClasses - Array of available integration classes
|
|
13
15
|
* @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management
|
|
@@ -22,6 +24,15 @@ class UpdateIntegration {
|
|
|
22
24
|
this.moduleFactory = moduleFactory;
|
|
23
25
|
}
|
|
24
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
|
+
*/
|
|
25
36
|
async execute(integrationId, userId, config) {
|
|
26
37
|
// 1. Get integration record from repository
|
|
27
38
|
const integrationRecord = await this.integrationRepository.findIntegrationById(integrationId);
|
|
@@ -56,12 +67,12 @@ class UpdateIntegration {
|
|
|
56
67
|
modules.push(moduleInstance);
|
|
57
68
|
}
|
|
58
69
|
|
|
59
|
-
// 4. Create the Integration domain entity with modules
|
|
70
|
+
// 4. Create the Integration domain entity with modules and updated config
|
|
60
71
|
const integrationInstance = new Integration({
|
|
61
72
|
id: integrationRecord.id,
|
|
62
73
|
userId: integrationRecord.userId,
|
|
63
74
|
entities: integrationRecord.entitiesIds,
|
|
64
|
-
config:
|
|
75
|
+
config: config,
|
|
65
76
|
status: integrationRecord.status,
|
|
66
77
|
version: integrationRecord.version,
|
|
67
78
|
messages: integrationRecord.messages,
|
|
@@ -19,26 +19,6 @@ class ModuleRepository {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
async findEntitiesByIds(entitiesIds) {
|
|
23
|
-
const entitiesRecords = await Entity.find({ _id: { $in: entitiesIds } }, '', { lean: true }).populate('credential');
|
|
24
|
-
|
|
25
|
-
// todo: this is a workaround needed while we create an integration with the same entity twice
|
|
26
|
-
if (entitiesRecords.length !== entitiesIds.length && entitiesIds[0] !== entitiesIds[1]) {
|
|
27
|
-
throw new Error(`Some entities not found`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return entitiesRecords.map(e => ({
|
|
31
|
-
id: e._id,
|
|
32
|
-
accountId: e.accountId,
|
|
33
|
-
credential: e.credential,
|
|
34
|
-
userId: e.user.toString(),
|
|
35
|
-
name: e.name,
|
|
36
|
-
externalId: e.externalId,
|
|
37
|
-
type: e.__t,
|
|
38
|
-
moduleName: e.moduleName,
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
22
|
async findEntitiesByUserId(userId) {
|
|
43
23
|
const entitiesRecords = await Entity.find(
|
|
44
24
|
{ user: userId },
|
|
@@ -84,7 +64,8 @@ class ModuleRepository {
|
|
|
84
64
|
* @returns {Promise<import('mongoose').UpdateWriteOpResult>}
|
|
85
65
|
*/
|
|
86
66
|
async unsetCredential(entityId) {
|
|
87
|
-
|
|
67
|
+
const result = await Entity.updateOne({ _id: entityId }, { $unset: { credential: "" } });
|
|
68
|
+
return result.acknowledged;
|
|
88
69
|
}
|
|
89
70
|
}
|
|
90
71
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class TestModuleFactory {
|
|
2
|
+
constructor() { }
|
|
3
|
+
|
|
4
|
+
async getModuleInstance(entityId, userId) {
|
|
5
|
+
// return minimal stub module with getName and api property
|
|
6
|
+
return {
|
|
7
|
+
getName() { return 'stubModule'; },
|
|
8
|
+
api: {},
|
|
9
|
+
entityId,
|
|
10
|
+
userId,
|
|
11
|
+
testAuth: async () => true,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = { TestModuleFactory };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class TestModuleRepository {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.entities = new Map();
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
addEntity(entity) {
|
|
7
|
+
this.entities.set(entity.id, entity);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async findEntityById(id) {
|
|
11
|
+
return this.entities.get(id);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async findEntitiesByIds(ids) {
|
|
15
|
+
return ids.map((id) => this.entities.get(id));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { TestModuleRepository };
|